TweetFollow Us on Twitter

Jun 98 Getting Started

Volume Number: 14 (1998)
Issue Number: 6
Column Tag: Getting Started

Modal Dialog Filter

by Dave Mark

Filtering Events in a Modal Dialog

DLOGFilter shows you how to write a filter procedure for a modal dialog. As usual, we'll create and run the project here. You can type it all in, start with last month's column and make changes, or just get the project files from ftp://ftp.mactech.com/src/mactech/volume14_1998/14.06.sit.

Creating the DLOGFilter Resources

Create a folder named DLOGFilter in your Development folder. Next, jump into ResEdit and create a new file named DLOGFilter.rsrc inside the DLOGFilter folder.

Create an MBAR resource using the specifications in Figure 1. Be sure that the MBAR's resource ID is set to 128.

Figure 1. Specifications for the MBAR resource.

Next, create three MENU resources using the specifications in Figure 2 as a guide. Be sure to include a separator line as the second item in all three MENUs. Remember to type in the appropriate command key equivalents (two for the File menu and four for the Edit menu).

Figure 2. Specifications for the three MENU resources.

Next, create a DLOG resource according to the specifications in Figure 3. Be sure that the modal dialog window icon (8th from the left) is selected, that the DITL ID is set to 128 and the "Initially visible" and "Close box" check boxes are unchecked, and that the Top, Left, Height, and Width fields are filled in as noted. Remember, if your DLOG editor uses Bottom and Right instead of Height and Width, select Show Height & Width from the DLOG menu.

Figure 3. Specifications for the DLOG resource.

Next, select Auto Position from the DLOG menu. When the Auto Position dialog appears, use the pop-up menus to direct Mac OS to automatically center our dialog on the main screen.

Figure 4. Proper settings for our DLOG's auto-position dialog.

Next, double-click the blank dialog box in the middle of the DLOG editing window to create a new DITL resource with an id of 128. The DITL contains six items. Create an OK button (Figure 5) and then a Cancel button (Figure 6).

Figure 5. Specifications for the OK button.

Figure 6. Specifications for the Cancel button.

Next, create a static text label (Figure 7) and its corresponding edit text field (Figure 8). Our dialog filter procedure will limit the number of characters entered in this field to 10.

Figure 7. Specifications for the first static text item.

Figure 8. Specifications for the first edit text field.

Now create a second static text label (Figure 9) and its corresponding edit text field (Figure 10). Our dialog filter procedure will only allow the digits 0 through 9 to be typed in this field. When the OK button is clicked, our main program will check to be sure the number typed was between 1 and 100.

Figure 9. Specifications for the second static text item.

Figure 10. Specifications for the second edit text field.

Figure 11 shows the DITL resource with all six items in place. Notice that the OK button is in the lower right corner with the Cancel button immediately to its left. This attention to detail is what makes the Mac so easy to use.

Figure 11. A look at the completed DITL resource.

Now create an ALRT resource using the specifications shown in Figure 12. This alert will be used to display various messages of interest to the user. Make sure that the DITL ID is set to 129. Then, change the ALRT's resource ID to 129. (Select Get Resource Info from the Resource menu.) See Figure 12.


Figure 12. Specifications for the ALRT resource.

Next, double-click the ALRT box in the middle of the ALRT editing window to create a new DITL resource. The ALRT DITL should have a resource id of 129 and will consist of 2 items. The OK button, used to dismiss the alert, is detailed in Figure 13.


Figure 13. Specifications for the alert's OK button.

The second DITL item is a static text item (Figure 14). Notice that the text provided reads: ^0. The Dialog Manager allows you to provide up to four strings (^0, ^1, ^2, and ^3) which may appear in any item in any DITL in your program. The function ParamText() allows you to substitute values for any of these strings. We'll use ParamText() to specify the message displayed by this alert.


Figure 14. Specifications for the static text item.

Figure 15 shows the message alert's DITL once we're done creating the two DITL items.


Figure 15. The message alert's DITL in final form.

Creating the DLOGFilter Project

Quit ResEdit, being sure to save your changes. Launch CodeWarrior and create a new project based on the Mac OS:C/C++:Basic Toolbox 68k stationary. Turn off the Create Folder check box. Name the project DLOGFilter.mcp and place it in your DLOGFilter folder. Remove SillyBalls.c and SillyBalls.rsrc from the project; we will not be using these files. From the Finder, drag and drop your DLOGFilter.rsrc file into the project window. You also can remove the ANSI Libraries group from the project, because we won't need them, either.

Select New from the File menu to create a new window. Save it with the name DLOGFilter.c in your DLOGFilter folder. Select Add Window from the Project menu to add DLOGFilter.c to the project. Your project window should look something like Figure 16.

Figure 16. DLOGFilter project window.

You may have noticed that our aapplication every month has been named "Mac OS Toolbox DEBUG 68K." This is name automatically provided by the project stationary. You can change this name in the Project Settings Target panel. Open your project settings by clicking the settings button in the Project window (Figure 16) just to the right of the of the target popup. (The popup says "68K Debug Mac OS Toolbox.") In the project settings window, select the 68K Target panel as shown in Figure 17. Enter "DLOGFilter app" in the File Name field. Close the window, clicking Save when you are asked to save and clicking OK if you are warned about relinking the project. Now your project wil build the application using this name.

Figure 17. DLOGFilter project window.

Walking Through the Source Code

DLOGFilter starts off #including necessary header files, then it begins a series of #defines. You'll see these again as they are used throughout the code.

I know this is obvious, but here's a word or two about the naming convention I use in my code. Start all constants with a lower-case k, with two exceptions. Menu and dialog items start with a lower-case i and menu resource id's start with a lower case m. Notice that the remainder of the constant name is spelled according to Pascal rules, as opposed to C rules. Pascal starts each word with an upper-case letter, while C traditionally uses all upper-case letters, separating each word by an underscore (_). I think the Pascal method is much easier to read. As it happens, most of Apple's C code uses the Pascal conventions as well.

#include <Dialogs.h>
#include <Menus.h>
#include <Quickdraw.h>
#include <Sound.h>

#define kDialogResID        128
#define kMBARid             128
#define kMessageAlertID     129

#define kSleep              60L
#define kMoveToFront        (WindowPtr)-1L
#define kNULLFilterProc     NULL

#define kOn          1
#define kOff         0

#define kEditItemExists       true
#define kEventNotHandledYet   false
#define kEventHandled         true

#define kMaxFieldLength     10

#define kEnterKey          3
#define kBackSpaceKey      8
#define kTabKey            9
#define kReturnKey         13
#define kEscapeKey         27
#define kLeftArrow         28
#define kRightArrow        29
#define kUpArrow           30
#define kDownArrow         31
#define kPeriodKey         46
#define kDeleteKey         127

#define iTenCharMaxText    4
#define iNumberText        6

#define mApple             128
#define iAbout             1

#define mFile              129
#define iDialog            1
#define iQuit              3

As usual, we've declared the global gDone as a Boolean to tell us when to drop out of the main event loop. As always, we start global variables with the letter g. There are lots of other naming conventions for variables. For example, some folks start their variables with a letter indicating the type of the variable. This can come in handy if you are writing code that gets shared among a group of people.

/************************************* Globals */

Boolean      gDone;

Here's the function prototypes for every single routine in the program. Get in the habit of providing function prototypes for all your routines. Since C++ requires function prototypes, this is a good habit to get into.

/************************************* Functions */

void         ToolboxInit( void );
void         MenuBarInit( void );
void         EventLoop( void );
void         DoEvent( EventRecord *eventPtr );
void         HandleMouseDown( EventRecord *eventPtr );
void         HandleMenuChoice( long menuChoice );
void         HandleAppleChoice( short item );
void         HandleFileChoice( short item );
void         DoDialog( void );

Here's an unusual prototype. Look at the return type for the function DLOGFilter().

pascal Boolean   DLOGFilter( DialogPtr dialog, EventRecord
    *eventPtr, short *itemHitPtr );

The pascal keyword tells the compiler that this routine should be called using Pascal, as opposed to C, calling conventions. Here's why this is important. When your code calls a regular C function, the compiler has no trouble using the C function-calling conventions. When you call a Toolbox function, the rules change a bit. Since the Toolbox was originally written in Pascal, all calls to it are made using the Pascal calling conventions. When you call a Toolbox function from your code, the compiler is smart enough to use the Pascal convention to pass parameters and return the return value to your code. The compiler knows to do this because the Toolbox function prototypes use the pascal keyword.

Where things get tricky is when you write a function in C that you'd like to be called by a Toolbox function. For example, in this program, we're creating a function that will be called, periodically by ModalDialog(). Which conventions do we use, C or Pascal? As it turns out, we yield to the Toolbox and declare our function using the pascal keyword. It's not important to understand the difference between C and Pascal calling conventions just as long as you remember this rule: If your routine is designed to be called by the Toolbox, be sure to declare it using the pascal keyword. Here's the rest of the function prototypes.

Boolean    ScrapIsOnlyDigits( void );
Boolean    CallFilterProc( DialogPtr dialog, 
              EventRecord *eventPtr, short *itemHitPtr );
short      CurEditField( DialogPtr dialog );
short      SelectionLength( DialogPtr dialog );
void       Message( Str255 messageStr );

main() initializes the Toolbox and menu bar, then enters the main event loop.

/************************************* main */

void   main( void )
{
   ToolboxInit();
   MenuBarInit();
   
   EventLoop();
}

Notice the new spelling of ToolboxInit(). (I used to spell it ToolBoxInit() -- Aack!)

/************************************* ToolboxInit */

void   ToolboxInit( void )
{
   InitGraf( &qd.thePort );
   InitFonts();
   InitWindows();
   InitMenus();
   TEInit();
   InitDialogs( NULL );
   InitCursor();
}

Not too much new here. This time I added a constant for the MBAR resource id.

/************************************* MenuBarInit */

void   MenuBarInit( void )
{
   Handle            menuBar;
   MenuHandle      menu;
   
   menuBar = GetNewMBar( kMBARid );
   SetMenuBar( menuBar );

   menu = GetMenuHandle( mApple );
   AppendResMenu( menu, 'DRVR' );
   
   DrawMenuBar();
}

Same old, same old...

/************************************* EventLoop */

void   EventLoop( void )
{      
   EventRecord      event;
   
   gDone = false;
   while ( gDone == false )
   {
      if ( WaitNextEvent( everyEvent, &event, kSleep, NULL ) )
         DoEvent( &event );
   }
}

Because our program supports only menus and a single dialog, we'll handle only a few events. The dialog window events are handled by the Dialog Manager.

/************************************* DoEvent */

void   DoEvent( EventRecord *eventPtr )
{
   char      theChar;
   
   switch ( eventPtr->what )
   {
      case mouseDown: 
         HandleMouseDown( eventPtr );
         break;
      case keyDown:
      case autoKey:
         theChar = eventPtr->message & charCodeMask;
         if ( (eventPtr->modifiers & cmdKey) != 0 ) 
            HandleMenuChoice( MenuKey( theChar ) );
         break;
   }
}

Last month's version of HandleMouseDown() included code for dragging a window around the screen. Because we don't have any windows, I took the liberty of deleting the unnecessary lines. Sorry about the extra typing.

/************************************* HandleMouseDown */

void   HandleMouseDown( EventRecord *eventPtr )
{
   WindowPtr   window;
   short         thePart;
   long            menuChoice;
   
   thePart = FindWindow( eventPtr->where, &window );
   
   switch ( thePart )
   {
      case inMenuBar:
         menuChoice = MenuSelect( eventPtr->where );
         HandleMenuChoice( menuChoice );
         break;
      case inSysWindow : 
         SystemClick( eventPtr, window );
         break;
   }
}

Pretty standard menu handling code. HandleMenuChoice() dispatches the menu selection...

/************************************* HandleMenuChoice */

void   HandleMenuChoice( long menuChoice )
{
   short   menu;
   short   item;
   if ( menuChoice != 0 )
   {
      menu = HiWord( menuChoice );
      item = LoWord( menuChoice );
      
      switch ( menu )
      {
         case mApple:
            HandleAppleChoice( item );
            break;
         case mFile:
            HandleFileChoice( item );
            break;
      }
      HiliteMenu( 0 );
   }
}

HandleAppleChoice() handles selections from the Apple menu. Feel free to add an about alert of your own design.

/************************************* HandleAppleChoice */

void   HandleAppleChoice( short item )
{
   MenuHandle   appleMenu;
   Str255         accName;
   short         accNumber;
   
   switch ( item )
   {
      case iAbout:
         SysBeep( 20 );
         break;
      default:
         appleMenu = GetMenuHandle( mApple );
         GetMenuItemText( appleMenu, item, accName );
         accNumber = OpenDeskAcc( accName );
         break;
   }
}

HandleFileChoice() handles the File menu selections. The first item in the File menu is the Dialog item, which displays our filtered dialog. The dialog is handled by the routine DoDialog().

/************************************* HandleFileChoice */

void   HandleFileChoice( short item )
{
   switch ( item )
   {
      case iDialog:
         DoDialog();
         break;
      case iQuit:
         gDone = true;
         break;
   }
}

DoDialog() starts by loading the DLOG resource using GetNewDialog().

/************************************* DoDialog */

void   DoDialog( void )
{
   DialogPtr    dialog;
   Boolean         dialogDone = false;
   short           itemHit, iType;
   Handle          iHandle;
   Rect            iRect;
   Str255          numberStr;
   long            number;

Strictly speaking, you should check the value returned by GetNewDialog(). This will keep you from an embarassing crash if the DLOG resource couldn't be loaded for some reason (like there's no more memory left, or the darn thing just wasn't there).

   dialog = GetNewDialog( kDialogResID, NULL, kMoveToFront );

As usual, we make the dialog visible, make it the current port, then configure it with three Toolbox routines.

   ShowWindow( dialog );
   SetPort( dialog );

   SetDialogDefaultItem( dialog, ok );
   SetDialogCancelItem( dialog, cancel );
   SetDialogTracksCursor( dialog, kEditItemExists );

Check out the tech note that describes these routines. (TB 37 in the new numbers, Tech Note 304 in the really old numbers.) You can find them on the developer CDs and, I'll bet, on-line at http://devworld.apple.com/. With the dialog window visible, we can enter the main dialog loop. We'll drop out of the loop once dialogDone is set to true.

   while ( ! dialogDone )
   {

The loop consists of a call to ModalDialog() and a switch to interpret the result returned in itemHit. The first parameter is a pointer to a filter function. Our filter function is named DLOGFilter. Note the lack of parentheses in the function name. If we included the parens, the function would be called in place and the return value would be passed as the first parameter to ModalDialog(). We'll get to DLOGFilter() in a minute.

      ModalDialog( DLOGFilter, &itemHit );

      switch( itemHit )
      {

If the OK button was clicked, we'll call GetDialogItem() and GetDialogItemText() to retrieve the text in the Number (1-100): text-edit field.

case ok:
   GetDialogItem(dialog, iNumberText, &iType, &iHandle, &iRect );
   GetDialogItemText( iHandle, numberStr);

If the field is empty, we'll print a message asking the user to enter a number in the field.

   if ( numberStr[ 0 ] == 0 )
   {
    Message("\pYou must enter a number in the number field!");
   }

Otherwise, we'll convert the text in the field into a number, then test to see if the number is between 1 and 100. If so, we can drop out of the loop.

   else
   {
      StringToNum( numberStr, &number );
               
      if ( (number >= 1) && (number <= 100) )
         dialogDone = true;

If the number is not in the required range, we'll print the appropriate message, then highlight all the text in the field.

      else
      {
      Message("\pPlease enter a number between 1 and 100..." );
      SelectDialogItemText( dialog, iNumberText, 0, 32767 );
      }
   }
   break;

How can we be sure that the text in the field is a number? As you'll see, that's part of the job of the filter procedure. DLOGFilter() makes sure that only numeric characters are entered in the number field.

If the Cancel button was pressed, we'll drop out of the dialog loop.

      case cancel:
         dialogDone = true;
         break;
      }
   }

Once out of the loop, we'll free up the memory occupied by the dialog, then print an appropriate message.

   DisposeDialog( dialog );
   
   if ( itemHit == ok )
      Message( "\pYour number was valid!!!" );
   else
      Message( "\pDialog cancelled..." );
}

DLOGFilter() gets called every time ModalDialog() encounters an event. Pointers to the dialog and event are passed as the first two parameters. The third parameter allows DLOGFilter() to set the value of itemHit.

If the event is handled by DLOGFilter() (and we want ModalDialog() to ignore it) we'll return a value of true, being sure to set the value of itemHit first (via itemHitPtr). If we didn't handle the event, we'll return false, asking ModalDialog() to process the event.

/************************************* DLOGFilter */

pascal   Boolean   DLOGFilter( DialogPtr dialog, EventRecord
     *eventPtr, short *itemHitPtr )
{
   char             c;
   short            iType;
   Handle           iHandle;
   Rect             iRect;
   Str255           textStr;
   long             scrapLength, scrapOffset;
   short            selecLength;

In this program, we're only interested in keyDown and autoKey events. Feel free to add whatever events you like to the switch.

   switch ( eventPtr->what )
   {
      case keyDown:
      case autoKey:

If the key pressed was one of those in the if clause, we'll call the default filter procedure (the one ModalDialog() calls if we don't provide one), returning the result returned by the default filterproc.

         c = (eventPtr->message & charCodeMask);

         if ( (c == kReturnKey) || (c == kEnterKey) ||
            (c == kTabKey) || (c == kBackSpaceKey) ||
            (c == kEscapeKey) || (c == kLeftArrow) ||
            (c == kRightArrow) || (c == kUpArrow) ||
            (c == kDownArrow) || (c == kDeleteKey) )
         {
         return(CallFilterProc( dialog, eventPtr, itemHitPtr ));
         }

Otherwise, we'll check to see if the edit cursor is inside the Ten chars max field.

         else if ( CurEditField( dialog ) == iTenCharMaxText )
         {

If so, we'll retrieve the text from that field.

            GetDialogItem(dialog, iTenCharMaxText, &iType, 
               &iHandle, &iRect);
            GetDialogItemText( iHandle, textStr);

Next, we'll find out how many characters in that field are currently selected.

            selecLength = SelectionLength( dialog );

If the current event represents the key sequence cmd-V, we'll check to make sure the text in the clipboard won't push us over our ten character limit.

            if ( ( (eventPtr->modifiers & cmdKey) != 0) 
               && (c == 'v') )
            {

First, we'll call GetScrap() to find out how many characters are in the clipboard. To programmers, the clipboard is known as the scrap, thus the name GetScrap(). Since the scrap can contain many types of data, we must specify that we are interested in 'TEXT' data (as opposed to 'PICT' data, for example).

            scrapLength = GetScrap( NULL, 'TEXT', &scrapOffset );

If the text that's in the current field, plus the length of the scrap, minus the selection length (remember, the selection will be replaced by whatever is pasted) exceeds the 10 char limit, we'll beep and return true.

   if (textStr[0]+ scrapLength - selecLength 
      > kMaxFieldLength)
      {
         SysBeep( 20 );
         *itemHitPtr = iTenCharMaxText;
         return( kEventHandled );
      }

Otherwise, we'll let the default filterproc handle the paste.

      else
         return(CallFilterProc( dialog, eventPtr, itemHitPtr) );
   }

If the field is full and no characters are selected (and thus replaced by the typed character), we'll beep and return false.

   if ((textStr[ 0 ] == kMaxFieldLength) 
      && (selecLength == 0))
      {
         SysBeep( 20 );
         return( kEventHandled );
      }

Otherwise, we'll let the default filterproc handle the event normally.

   else
      return( CallFilterProc( dialog, eventPtr, itemHitPtr ) );
}

So much for the Ten chars max field. Now we'll handle an event that occurs when the current field is the Number (1-100) field.

      else if ( CurEditField( dialog ) == iNumberText )
      {

This next line is superfluous. Feel free to delete it.

            GetDialogItem( dialog, iNumberText, &iType, 
               &iHandle, &iRect );

Once again, we'll retrieve the length of the current selection.

            selecLength = SelectionLength( dialog );

Next, we'll check to see if a cmd-V was typed. By the way, the Dialog Manager will convert a selection of Paste from the Edit menu to a cmd-V for us. Try it. This code should still work.

            if ( ( (eventPtr->modifiers & cmdKey) != 0) && 
               (c == 'v') )
            {

If cmd-V was typed, we'll check to be sure the scrap contains only digits. If so, we'll let the default filterproc handle the paste.

               if ( ScrapIsOnlyDigits() )
               {
                  return( CallFilterProc( dialog, eventPtr, 
                     itemHitPtr ) );
               }

Otherwise, we'll beep and return.

               else
               {
                  SysBeep( 20 );
                  *itemHitPtr = iNumberText;
                  return( kEventHandled );
               }
            }

If the character typed was not a digit, and the command key was not held down, we'll beep and return.

            else if ( ((c < '0') || (c > '9')) && 
               ( (eventPtr->modifiers & cmdKey) == 0) )
            {
               SysBeep( 20 );
               *itemHitPtr = iNumberText;
               return( kEventHandled );
            }

If the character typed was a digit, or if a command-key sequence of any type was entered, we'll let the default filterproc handle it.

   else
      {
      return( CallFilterProc( dialog, eventPtr, itemHitPtr ) );
      }
   }
   break;
}

If anything else slips through, we'll let the default filterproc handle it.

   return( CallFilterProc( dialog, eventPtr, itemHitPtr ) );
}

You may have noticed that we started the filter off by checking for characters like return, enter, tab, delete, and the arrow keys. These are context-free keys. In other words, their importance is not related to the current field. We try to get those out of the way first, before we start checking for input related to a specific field.

ScrapIsOnlyDigits() checks the contents of the scrap to make sure each character is a digit, between '0' and '9'.

/************************************* ScrapIsOnlyDigits */

Boolean   ScrapIsOnlyDigits( void )
{
   Handle           textHandle;
   long             scrapLength, scrapOffset;
   Boolean          onlyDigits = true;
   unsigned short   i;

First, we'll allocate a new, minimum-sized handle. The Mac's Memory Manager will allocate the minimum size block of memory, then return a pointer to a pointer to the block. We'll get into handles in a later column. For the moment, just bear with me.

   textHandle = NewHandle( 0 );

We pass that handle to GetScrap(), asking it to retrieve data of type 'TEXT' from the scrap, resizing the handled block to a size appropriate to hold the retrieved text.

   scrapLength = GetScrap( textHandle, 'TEXT', &scrapOffset );

If the scrap was empty, or if text couldn't be retireved (scrapLength was negative), we'll return false.

   if ( scrapLength <= 0 )
      return( false );

Since we are about to singly dereference the handle, we have to lock it. Once again, we'll talk more about this in a future column.

   HLock( textHandle );

Next, we'll walk through the text, checking for non-digits.

   for ( i=0; i<scrapLength; i++ )
   {
      if (((*textHandle)[i] < '0') || ((*textHandle)[i] > '9'))
         onlyDigits = false;
   }

Next, unlock the handle, release the memory, and return the result.

   HUnlock( textHandle );
   
   DisposeHandle( textHandle );
   
   return( onlyDigits );
}

CallFilterProc() is our next step.

/************************************* CallFilterProc */

Boolean   CallFilterProc( DialogPtr dialog, EventRecord
     *eventPtr, short *itemHitPtr )
{
   ModalFilterProcPtr   theModalProc;
   OSErr                myErr;

GetStdFilterProc() retrieves the default filterproc. The default filterproc takes care of things like drawing the outline around the default button, checking for the cancel key-equivalents, and changing the cursor to the i-beam when the cursor is over a text-edit field.

   myErr = GetStdFilterProc(&theModalProc);

   if (myErr == noErr)
      return( theModalProc( dialog, eventPtr, itemHitPtr ) );
   else
      return( kEventNotHandledYet );
}

CurEditField() peeks into the dialog's data structure and returns the adjusted value hidden in the editField field.

/************************************* CurEditField */

short   CurEditField( DialogPtr dialog )
{
   return( ((DialogPeek)dialog)->editField + 1 );
}

SelectionLength() starts by retrieving the current TEHandle from the specified dialog. The TEHandle is a handle to the struct describing the current text-edit field. The selEnd and selStart fields describe the position of the end and beginning of the text selection.

/************************************* SelectionLength */

short   SelectionLength( DialogPtr dialog )
{
   TEHandle   teH;
   
   teH = ((DialogPeek)dialog)->textH;
   
   return( (**teH).selEnd - (**teH).selStart );
}

Message() puts up an alert containing the specified text string.

/************************************* Message */

void   Message( Str255 messageStr )
{
   short unused;

   ParamText( messageStr, "\p", "\p", "\p" );
   
   unused = NoteAlert( kMessageAlertID, kNULLFilterProc );
}

Running DLOGFilter

Save your source code and then choose Run from the Project menu. When DLOGFilter starts running, a menu bar with three menus (Apple, File, and Edit) will appear. If you select About DLOGFilter from the Apple menu, the program will beep at you. Since you already know how to implement an about alert from past columns, I didn't want to take up space in this column with a real about box.

Next, click your mouse in the File menu. The first item, Dialog, has a command key equivalent of cmd-D. Type cmd-D or select Dialog from the File menu. Either way, a dialog box will appear, just like the one in Figure 18. Notice that the text edit cursor is in the first of the two text edit fields.

Figure 18. The DLOGFilter dialog.

To start things off, press the Cancel button. The alert shown in Figure 19 will appear. Click the OK button and type cmd-D to bring up the dialog again and this time, type cmd-. (command-period). Once again, the "Dialog cancelled" alert appears. Once more, click the OK button and type cmd-D to bring up the dialog and this time hit the escape key. As before, the "Dialog cancelled" alert appears. Click the OK button to dismiss the alert.

Figure 19. This alert appears when you Cancel the DLOGFilter dialog.

Type cmd-D to bring up the dialog again. This time, type the characters 1234567890 in the first field. Now type another character. The dialog will beep at you and your character will not appear. As you can see, this field limits you to 10 characters. Try copying some text to the clipboard, then pasting it to the field. You will succeed only if the number of characters in the clipboard plus the number of characters that are not selected in the field does not exceed 10.

Without typing anything in the second field, click the OK button. The alert shown in Figure 20 appears, telling you to enter a number in the second field.

Figure 20. Another message alert.

Click the mouse in the second field and type a non-numeric character (like the letter x). Your Mac will beep at you, telling you that you can only type numeric characters in this field. Now type the number 355 in the second field and click OK. The message alert shown in Figure 21 appears, telling you to enter a number between 1 and 100.

Figure 21. Yet another message alert.

Click OK to get back to the dialog and type a number between 1 and 100 in the second field and click OK. The message alert in Figure 22 tells you that your input was valid.

Figure 22. A final message alert.

Till Next Month...

At the heart of this program was a filter procedure that the Dialog Manager called repeatedly to preprocess all the events associated with the main dialog box. The filter procedure was responsible for limiting the characters that appeared in the two text edit fields. As an exercise, try changing the program so the OK button is dimmed until a valid number is entered. You'll need to check and adjust the OK button inside the filterproc.

 
AAPL
$118.93
Apple Inc.
-0.07
MSFT
$47.81
Microsoft Corpora
+0.06
GOOG
$541.83
Google Inc.
+1.46

MacTech Search:
Community Search:

Software Updates via MacUpdate

Adobe Photoshop Elements 13.0 - Consumer...
Adobe Photoshop Elements 12--the #1 selling consumer photo editing software--helps you edit pictures with powerful, easy-to-use options and share them via print, the web, Facebook, and more.Version... Read more
Skype 7.2.0.412 - Voice-over-internet ph...
Skype allows you to talk to friends, family and co-workers across the Internet without the inconvenience of long distance telephone charges. Using peer-to-peer data transmission technology, Skype... Read more
HoudahSpot 3.9.6 - Advanced file search...
HoudahSpot is a powerful file search tool built upon MacOS X Spotlight. Spotlight unleashed Create detailed queries to locate the exact file you need Narrow down searches. Zero in on files Save... Read more
RapidWeaver 6.0.3 - Create template-base...
RapidWeaver is a next-generation Web design application to help you easily create professional-looking Web sites in minutes. No knowledge of complex code is required, RapidWeaver will take care of... Read more
iPhoto Library Manager 4.1.10 - Manage m...
iPhoto Library Manager lets you organize your photos into multiple iPhoto libraries. Separate your high school and college photos from your latest summer vacation pictures. Or keep some photo... Read more
iExplorer 3.5.1.9 - View and transfer al...
iExplorer is an iPhone browser for Mac lets you view the files on your iOS device. By using a drag and drop interface, you can quickly copy files and folders between your Mac and your iPhone or... Read more
MacUpdate Desktop 6.0.3 - Discover and i...
MacUpdate Desktop 6 brings seamless 1-click installs and version updates to your Mac. With a free MacUpdate account and MacUpdate Desktop 6, Mac users can now install almost any Mac app on macupdate.... Read more
SteerMouse 4.2.2 - Powerful third-party...
SteerMouse is an advanced driver for USB and Bluetooth mice. It also supports Apple Mighty Mouse very well. SteerMouse can assign various functions to buttons that Apple's software does not allow,... Read more
iMazing 1.1 - Complete iOS device manage...
iMazing (was DiskAid) is the ultimate iOS device manager with capabilities far beyond what iTunes offers. With iMazing and your iOS device (iPhone, iPad, or iPod), you can: Copy music to and from... Read more
PopChar X 7.0 - Floating window shows av...
PopChar X helps you get the most out of your font collection. With its crystal-clear interface, PopChar X provides a frustration-free way to access any font's special characters. Expanded... Read more

Latest Forum Discussions

See All

Mystery Case Files: Dire Grove, Sacred G...
Mystery Case Files: Dire Grove, Sacred Grove HD Review By Jennifer Allen on November 28th, 2014 Our Rating: iPad Only App - Designed for the iPad A decent new installment for the popular Mystery Case Files series.   | Read more »
Castaway Paradise – Tips, Tricks, and St...
Ahoy there, castaways: Were you curious about our own thoughts regarding this pristine shipwreck? Check out our Castaway Paradise review! Castaway Paradise is out for iOS, finally giving mobile gamers the opportunity to enjoy the idyllic lifestyle... | Read more »
Castaway Paradise VIP Subs are on Sale f...
Castaway Paradise VIP Subs are on Sale for a Limited Time, and a Special Holiday Update is Coming Soon Posted by Rob Rich on November 28th, 2014 [ | Read more »
Primitive Review
Primitive Review By Jordan Minor on November 28th, 2014 Our Rating: :: FOLK ARTUniversal App - Designed for iPhone and iPad True to its name, Primitive is about as straightforward as runners get.   | Read more »
7 tips to get ahead of the competition i...
7 tips to get ahead of the competition in Dynasty of Dungeons Posted by Simon Reed on November 28th, 2014 [ permalink ] Playcrab has launched their action-packed new dungeon crawler, Dynasty of Dungeons, today. | Read more »
Master of Tea Kung Fu Review
Master of Tea Kung Fu Review By Jordan Minor on November 28th, 2014 Our Rating: :: ONE DROP RULESUniversal App - Designed for iPhone and iPad Master of Tea Kung Fu is a creative and complex caffeinated brawler.   | Read more »
Monster Strike Review
Monster Strike Review By Campbell Bird on November 28th, 2014 Our Rating: :: BILLIARD STRATEGYUniversal App - Designed for iPhone and iPad Collect monsters and battle by flinging them across the battlefield in this strangely... | Read more »
Proun+ Review
Proun+ Review By Jennifer Allen on November 28th, 2014 Our Rating: :: TWITCHY RACINGUniversal App - Designed for iPhone and iPad Twitchy racing aplenty in Proun+, an enjoyably tricky title.   | Read more »
Lucha Amigos (Games)
Lucha Amigos 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Forget Ninja Turtles, and meet Wrestlers Turtles! Crazier, Spicier and…Bouncier! Sling carapaces of 7 Luchadores to knock all... | Read more »
Record of Agarest War Zero (Games)
Record of Agarest War Zero 1.0 Device: iOS Universal Category: Games Price: $7.99, Version: 1.0 (iTunes) Description: HyperDevbox Holiday Turkey Black Friday Special Pricing! To celebrate the opening of the holiday season HyperDevbox... | Read more »

Price Scanner via MacPrices.net

Best Black Friday Deal: 15-inch Retina MacBoo...
 B&H Photo has the new 2014 15″ Retina MacBook Pros on sale for $300 off MSRP as part of their Black Friday sale. Shipping is free, and B&H charges NY sales tax only: - 15″ 2.2GHz Retina... Read more
Up To 75% Off Infovole Text Apps Over Black F...
Infovole’s entire range of apps, including the Textkraft family of word processors for iPads and iPhones, is being offered at 50-75% off over the Black Friday and Cyber Monday weekend. The five-day... Read more
Black Friday: Up to $60 off Mac minis, NY tax...
 B&H Photo has new 2014 Mac minis on sale for up to $60 off MSRP as part of their Black Friday sale. Shipping is free, and B&H charges NY sales tax only: - 1.4GHz Mac mini: $449.99 $50 off... Read more
Black Friday: 27-inch 5K iMac for $2299, save...
 B&H Photo continues to offer Black Friday sale prices on the 27″ 3.5GHz 5K iMac, in stock today and on sale for $2299 including free shipping plus NY sales tax only. Their price is $200 off MSRP... Read more
Karalux Announces 24K Gold-Plated iPhone 6
Karalux, a Vietnam-based jewellery firm, has launched a unique 24 karat gold-plated iPhone 6 version with gold-cast monolithic dragon on its back panel. The real 24 karat gold plated enclosure doesn’... Read more
Black Friday: 13-inch 2.6GHz Retina MacBook P...
 B&H Photo has lowered their price for the 13″ 2.6GHz/128GB Retina MacBook Pro to $1159 for Black Friday. That’s $140 off MSRP, and it’s the lowest price for this model (except for Apple’s $1099... Read more
View all the Black Friday sales on our Mac Pr...
We’ve updated our Mac Price Trackers with the latest information on prices, bundles, and availability on systems from Apple’s authorized internet/catalog resellers. View Black Friday sale prices at a... Read more
Black Friday: 11-inch MacBook Air for $779, s...
 Best Buy has lowered their price for the 2014 11″ 1.4GHz/128GB MacBook Air to $779.99 for Black Friday. That’s $120 off MSRP. Choose free shipping or free local store pickup (if available). Sale... Read more
Apple Store Black Friday sale for 2014: $100...
BLACK FRIDAY The Apple Store has posted their Black Friday deals for 2014. Receive a $100 PRODUCT(RED) branded iTunes gift card with the purchase of select Macs, $50 with iPads, and $25 with iPods,... Read more
Black Friday: 15% off iTunes Gift Cards
Staples is offering 15% off $50 and $100 iTunes Gift Cards on their online store as part of their Black Friday sale. Click here for more information. Shipping is free. Best Buy is offering $100... Read more

Jobs Board

*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.