TweetFollow Us on Twitter

May 98 - Getting Started

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

Handling Modeless Dialogs

by Dave Mark

Looking deeper into the Dialog Manager

Over the last few columns, we've explored the mysteries of the Dialog Manager via a program called Dialogger. As promised, the next few columns will go deeper into the Dialog Manager, presenting a program called Modeless. Modeless implements a modeless dialog, a dialog that looks and acts like a regular window, but retains the benefits of being managed by the Dialog Manager.

Modeless dialogs require a change in the usual modal programming strategy. Modal dialog handling code is usually pretty self-contained. Modeless code tends to be larger and more spread out, as you'll see when we get to the code.

Creating the Modeless Resources

Most of the resources we'll need for this month's column can be copied from last month's resource file, Dialogger.rsrc. Start by creating a new folder in your Development folder named Modeless. Next, duplicate the file Dialogger.rsrc and drag the copy into the Modeless folder. Change the name of this file to Modeless.rsrc.

Next, launch ResEdit by double-clicking the file Modeless.rsrc. The Modeless.rsrc window should look similar to the one shown in Figure 1.

Figure 1. Modeless.n.rsrc, before surgery.

Your first mission is to edit the ALRT, replacing any references to Dialogger with the appropriate reference to Modeless. Double-click on the ALRT icon. When the ALRT-picker window appears, double-click the only ALRT listed, the one with a resource ID of 129. When the ALRT editor appears, double-click the ALRT window so the DITL editor appears. Finally, double-click the static text item and, when the static text editor appears, make your changes. Mine are shown in Figure 2.

Figure 2. A new version of the About... ALRT.

When you're happy with your About message, close all the windows until you are back at the main window. Next, you'll change the About Dialogger item in the Apple menu to read About Modeless.

Double-click the MENU icon to bring up the MENU picker window. Next, double-click the Apple MENU, bringing up the MENU editing window. Click the About Dialogge. item and change it so it says About Modeless, as shown in Figure 3.

Figure 3. A new version of the MENU resource.

Close the Apple MENU editing window, then double-click the File menu, bringing up the File MENU editing window. Click the Settings item and then click in the Cmd-key: field. Type the letter S in the Cmd-key: field. This ties the command-key equivalent S to the Settings item in the File menu. My File MENU editing window is shown in Figure 4.

Figure 4. A new version of the File MENU resource.

Once you are done, close all the windows leaving just the main window open. Our final chore is to edit the DLOG and DITL resources that made up Dialogger's modal dialog, changing them to reflect the look of a modeless dialog.

Double-click the DLOG icon to bring up the DLOG-picker window. Next, double-click the only DLOG listed, the one with the resource id of 128. The Settings DLOG editing window should appear. First, click the Initially visible check box, making sure it is unchecked.

Next, click the second window icon from the left, at the top of the editing window. The DLOG window should change to reflect your new selection. Modeless dialogs don't have the traditional double-border of their modal cousins. Instead, they look like regular windows. In this case, we want to give our dialog window a close box, so make sure the Close box check box is checked.

We also want to give our dialog window a title. Select Set 'DLOG' Characteristics from the DLOG menu. When the 'DLOG' Characteristics dialog appears, type the text Fred Settings in the Window title: field and click OK. Your new title should be reflected in the DLOG editing window. Figure 5 shows my DLOG editing window at this point in the process.

Figure 5. The DLOG editing window, at the half-way point.

Next, we'll edit the DITL associated with this DLOG. Double click the DLOG window (within the editing window) so the DITL editing window appears. You are now going to delete all the items in the DITL except the Pick one: static text item and the three radio buttons.

Click the OK button and press the delete key. Click the Cancel button and press the delete key. Click the Show preview check box and press the delete key. Finally, click the user item (the grey rectangle) and press delete.

Next, you'll change the positioning of the remaining four items. Double-click the Pick one: static text item and change its coordinates to the ones shown in Figure 6. Close the window when you are done.

Figure 6. New coordinates for the Pick one: static text item.

Double-click the Afghan radio button and change its coordinates to the ones shown in Figure 7. Close the window when you are done.

Figure 7. New coordinates for the Afghan radio button.

Double-click the Elephant radio button and change its coordinates to the ones shown in Figure 8. Close the window when you are done.

Figure 8. New coordinates for the Elephant radio button.

Double-click the Squirrel radio button and change its coordinates to the ones shown in Figure 9. Close the window when you are done.

Figure 9. New coordinates for the Squirrel radio button.

Now we're almost done. Close the DITL editing window, leaving you back in the DLOG editing window. The last thing left to do is to resize the DLOG to reflect its slimmed down and rearranged DITL. Change the Bottom: to 123 and the Right: to 234. The final version of our DLOG is shown in Figure 10.

Figure 10. The final version of our DLOG.

Quit ResEdit, being sure to save your changes. Now we're ready to enter our source code.

Creating the Modeless Project

Launch CodeWarrior and create a new project based on the MacOS:C/C++:Basic Toolbox 68k stationary. Turn off the Create Folder check box. Name the project Modeless.mcp and place it in your Modeless folder. Remove SillyBalls.c and SillyBalls.rsrc from the project; we will not be using these files. From the Finder, drag and drop your Modeless.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 Dialogger.c in your Modeless folder. Select Add Window from the Project menu to add Dialogger.c to the project. Your project window should look something like Figure 11.

Figure 11. Dialogger project window.

Rather than print the code here twice, we'll go straight to the walk-through. You can type in the code as we discuss it below and you will end up with the complete program, or you can save your fingers some effort and get the complete project from MacTech's ftp site ftp://ftp.mactech.com/src/mactech/volume14_1998/14.05.sit.

Walking Through the Source Code

Much of the Modeless source code will look familiar to you from earlier programs. As usual, Modeless starts off #including necessary header files, then it begins a series of #defines. The first three define the base resource ID, and the resource IDs for the ALRT and DLOG resources.

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

#define kBaseResID        128
#define kAboutALRTid      129
#define kDialogResID      128

kVisible, kMoveToBack, kMoveToFront, and kNoGoAway are used in the calls to NewWindow() and GetNewDialog(). kSleep, as usual, is passed to WaitNextEvent().

#define kVisible          true
#define kMoveToBack       NULL
#define kMoveToFront      (WindowPtr)-1L
#define kNoGoAway         false
#define kSleep            7L

kOn and kOff are passed to SetControlValue() to turn a radio button on and off.

#define kOn                 1
#define kOff                0

These three #defines define the item IDs for the three radio buttons that appear in the modeless dialog.

#define iAfghan             1
#define iElephant           2
#define iSquirrel           3

kLeftMargin and kTopMargin determine the position of the My Pet Fred window on the screen.

#define kLeftMargin         5
#define kTopMargin         40

kFirstRadio defines the ID of the first radio button in the modeless dialog. kLastRadio defines the ID of the last radio button in the set.

#define kFirstRadio        1
#define kLastRadio         3

The remainder of the #defines represent the Modeless menus and menu items.

#define mApple             kBaseResID
#define iAbout             1

#define mFile              kBaseResID+1
#define iSettings          1
#define iQuit              3

Modeless makes use of four global variables. gDone is set to true until the program is ready to exit. gCurrentPICT contains the ID of the current My Pet Fred PICT. gSettingsDLOG is a pointer to the modeless dialog. We made this a global so we could keep the modeless dialog settings around, even if we close the dialog. gFredWindow points to the My Pet Fred window. We'll take advantage of this pointer when we delete the My Pet Fred window and create a new one.

Boolean     gDone;
short       gCurrentPICT = kBaseResID;
DialogPtr   gSettingsDLOG = NULL;
WindowPtr   gFredWindow = NULL;

As always, we created a function prototype for each of the Modeless functions.

void         ToolBoxInit( void );
PicHandle    LoadPICT( short picID );
void         CreateWindow( void );
void         MenuBarInit( void );
void         EventLoop( void );
void         DoEvent( EventRecord *eventPtr );
void         DoDialogEvent( EventRecord *eventPtr );
void         HandleMouseDown( EventRecord *eventPtr );
void         HandleMenuChoice( long menuChoice );
void         HandleAppleChoice( short item );
void         HandleFileChoice( short item );
void         DoUpdate( EventRecord *eventPtr );
void         CreateDialog( void );
void         FlipControl( ControlHandle control );
void         SwitchPICT( void );

main() starts off by initializing the Toolbox. Next, the menu bar is set up and the My Pet Fred window is created. Finally, we begin the main event loop.

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

void   main( void )
{
   ToolBoxInit();
   MenuBarInit();
   
   CreateWindow();
   
   EventLoop();
}

Nothing new about ToolBoxInit().

/********** ToolBoxInit **********/

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

Just like its Dialogger counterpart, LoadPICT() takes a resource ID as an input parameter, loads the specified PICT resource, then returns a handle to the PICT.

/********** LoadPICT **********/

PicHandle   LoadPICT( short picID )
{
   PicHandle   pic;
   
   pic = GetPicture( picID );

If the PICT could not be loaded for some reason, the program beeps once, then exits.

   if ( pic == NULL )
   {
      SysBeep( 10 );   /* Couldn't load the PICT resource!!! */
      ExitToShell();
   }

   return( pic );
}

CreateWindow() creates a new My Pet Fred window.

/********** CreateWindow **********/

void   CreateWindow( void )
{
   PicHandle   pic;
   Rect            r;

First, LoadPICT() is called to load the PICT specified by gCurrentPICT.

   pic = LoadPICT( gCurrentPICT );

Next, the PICT's bounding rectangle is stored in the local variable r.

   r = (**pic).picFrame;

OffsetRect() is called to normalize the Rect, keeping it the same size as the PICT, but moving its upper left corner to the position specified by kLeftMargin and kTopMargin. Basically, we're setting up the bounding rectangle for the new My Pet Fred window.

   OffsetRect( &r, kLeftMargin - r.left,
               kTopMargin - r.top );

This rectangle is passed to NewWindow(). The new window is made visible. Notice that kMoveToBack is passed instead of our normal kMoveToFront. Why? We want the window to appear behind the modeless dialog window, if the dialog is currently visible.

   gFredWindow = NewWindow( NULL, &r, "\pMy Pet Fred", 
         kVisible, noGrowDocProc, kMoveToBack, kNoGoAway, 0L );

If the window couldn't be created for some reason, beep once, then exit.

   if ( gFredWindow == NULL )
   {
      SysBeep( 10 );   /* Couldn't load the WIND resource!!! */
      ExitToShell();
   }

Finally, make the window visible (this line is unnecessary because we created the window with kVisible, but it's a good habit to get into) and make it the current port. We'll draw the current Fred by responding to an update event.

   ShowWindow( gFredWindow );
   SetPort( gFredWindow );
}

MenuBarInit() loads the MBAR resource, and makes it the current menu bar.

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

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

Next, a handle to the Apple menu is retrieved and the desk accessories added to the menu.

   menu = GetMenuHandle( mApple );
   AppendReMenu( menu, 'DRVR' );

Finally, the menu bar is redrawn.

   DrawMenuBar();
}

EventLoop() looks much the same. As you'd expect, the program exits when gDone is set to true.

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

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

DoEvent() is slightly different than previous incarnations.

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

void   DoEvent( EventRecord *eventPtr )
{
   char      theChar;

The first difference lies in our call of IsDialogEvent(). IsDialogEvent() takes a pointer to an EventRecord as a parameter and returns true if the event is associated with a modeless dialog. Note that our code calls IsDialogEvent() whether or not a modeless dialog is currently open. Since we aren't that concerned with efficiency here, this is just fine. In a more complex program, you might want to check to see if any of your modeless dialogs are open before you call IsDialogEvent(). Obviously, if your program contains no modeless dialogs, you shouldn't call IsDialogEvent().

   if ( IsDialogEvent( eventPtr ) )
   {

If IsDialogEvent() returns true, the event is associated with our modeless dialog box and we'll pass it along to DoDialogEvent() for processing.

      DoDialogEvent( eventPtr );
   }

If the event is not associated with a modeless dialog, we'll process the event as we always did, using a switch statement.

   else
   {
      switch ( eventPtr->what )
      {

A mouseDown is handled by HandleMouseDown().

         case mouseDown: 
            HandleMouseDown( eventPtr );
            break;

keyDown and autoKey events are turned into characters and turned from command-key equivalences (if appropriate) into menu selections by MenuKey(). The menu selections are handled by HandleMenuChoice().

         case keyDown:
         case autoKey:
            theChar = eventPtr->message & charCodeMask;
            if ( (eventPtr->modifiers & cmdKey) != 0 ) 
               HandleMenuChoice( MenuKey( theChar ) );
            break;

updateEvts are handled by DoUpdate(). Since the update events for our modeless dialog will have been diverted to DoDialogEvent(), any updateEvts passed to DoUpdate() will be for the My Pet Fred window.

         case updateEvt:
            DoUpdate( eventPtr );
            break;
      }
   }
}

All events for the modeless dialog are passed to DoDialogEvent().

/********** DoDialogEvent **********/

void   DoDialogEvent( EventRecord *eventPtr )
{
   short         itemHit;
   short         itemType;
   Handle        itemHandle;
   Rect          itemRect;
   short         curRadioButton, i;
   char          theChar;
   Boolean       becomingActive;
   MenuHandle    menu;
   DialogPtr     dialog;

We'll start off by fetching a handle to the File menu. Why? We're going to dim the Settings item if the modeless dialog is up front. Remember, we're doing this just to demonstrate how it's done, not because it's needed.

   menu = GetMenuHandle( mFile );

Notice that we process keyDown and autoKey events in two different places. If the modeless dialog is up front, DoDialogEvent() will get all keyDowns and autoKeys. If the modeless dialog is not up front or is not open, the normal event handling mechanism will get the keyDowns and autoKeys.

   switch ( eventPtr->what )
   {
      case keyDown:
      case autoKey:
         theChar = eventPtr->message & charCodeMask;
         if ( (eventPtr->modifiers & cmdKey) != 0 ) 
            HandleMenuChoice( MenuKey( theChar ) );
         break;

If the modeless dialog window is either being activated or deactivated, DoDialogEvent() will get an activateEvt. In that case, we'll use the activeFlag to determine whether becomingActive should be set to true or false.

      case activateEvt:
         becomingActive = ( (eventPtr->modifiers & activeFlag)
                              == activeFlag );

If the modeless dialog window is becoming active, we'll use HiliteControl() to enable all the radio buttons, from kFirstRadio to kLastRadio, then we'll disable the File menu's Settings item.

         if ( becomingActive )
         {
            for ( i=kFirstRadio; i<=kLastRadio; i++ )
            {
               GetDialogItem( gSettingsDLOG, i, &itemType,
                     &itemHandle, &itemRect );
               HiliteControl( (ControlHandle)itemHandle, 0 );
            }
            DisableItem( menu, iSettings );
         }

If the modeless dialog window is being deactivated, we'll dim all the radio buttons and enable the Settings item. When the user goes to the File menu and sees that Settings is dimmed, they'll have a clue that the modeless dialog is already up front and ready to use.

         else
         {
            for ( i=kFirstRadio; i<=kLastRadio; i++ )
            {
               GetDialogItem( gSettingsDLOG, i, &itemType,
                     &itemHandle, &itemRect );
               HiliteControl( (ControlHandle)itemHandle, 255 );
            }
            EnableItem( menu, iSettings );
         }
         break;
   }

The previous chunk of code accomplished two things. First, it made sure that command-key equivalents were supported. Second, it made any user interface adjustments that were not normally handled by the Dialog Manager. We decided to dim the radio buttons when the modeless window is deactivated and dim the Settings item when the modeless window is activated. These user interface adjustments are window trimmings that we decided to add. The program would still work without them.

Next, we're going to the things that absolutely must be done. DialogSelect() is the modeless version of ModalDialog(). DialogSelect() takes the event pointer and maps it to a specific dialog and a specific item in the dialog. DialogSelect() returns true if we need to do some processing (if an item was actually hit).

   if ( DialogSelect( eventPtr, &dialog, &itemHit ) )
   {

Since our dialog was relatively simple, we know that itemHit is going to be one of iAfghan, iElephant, or iSquirrel.

      switch ( itemHit )
      {
         case iAfghan:
         case iElephant:
         case iSquirrel:

Before we process the radio button click, we'll first calculate which radio button should be currently lit.

            curRadioButton = gCurrentPICT - 
                     kBaseResID + kFirstRadio;

If the button that was clicked in is not the current radio button, we've got some work to do.

            if ( curRadioButton != itemHit )
            {

First, we'll turn off the current radio button.

               GetDialogItem( dialog, curRadioButton, &itemType,
                     &itemHandle, &itemRect );
               FlipControl( (ControlHandle)itemHandle );

Next, we'll turn on the radio button that was just clicked. Remember, always turn off a radio button before you turn on a new one.

               GetDialogItem( dialog, itemHit, &itemType,
                     &itemHandle, &itemRect );
               FlipControl( (ControlHandle)itemHandle );

Next, update curRadioButton to reflect the newly clicked radio button.

               curRadioButton = itemHit;

Next we check to see if the current PICT is still up to date.

               if ( gCurrentPICT != curRadioButton +
                     kBaseResID - kFirstRadio )
               {

If not, we'll set it to its new value, then call SwitchPICT() to update the My Pet Fred window.

                  gCurrentPICT = curRadioButton +
                        kBaseResID - kFirstRadio;
                  SwitchPICT();
               }
            }
            break;
      }
   }
}

HandleMouseDown() works much the same as always.

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

void   HandleMouseDown( EventRecord *eventPtr )
{
   WindowPtr      window;
   short          thePart;
   long           menuChoice;
   MenuHandle     menu;

First, we call FindWindow() to find out what window the mouseDown was in and where in the window the mouseDown occurred.

   thePart = FindWindow( eventPtr->where, &window );

If the mouseDown was in the menu bar, pass the menu selection on to HandleMenuChoice(). A mouseDown in inSysWindow gets passed on to SystemClick().

   switch ( thePart )
   {
      case inMenuBar:
         menuChoice = MenuSelect( eventPtr->where );
         HandleMenuChoice( menuChoice );
         break;
      case inSysWindow : 
         SystemClick( eventPtr, window );
         break;

A mouseDown inContent causes a call to SelectWindow() to bring the clicked-in window to the front.

      case inContent:
         SelectWindow( window );
         break;

Note that this line will get executed even if the mouse click was in the modeless dialog, but only if the modeless dialog was in the back when it was clicked in. Want to prove this? Try adding this line after the call of SelectWindow() but before the break:

if ( window == gSettingsDLOG ) SysBeep( 20 );

If the mouseDown was inDrag, call DragWindow() to drag the window around on the screen.

      case inDrag : 
         DragWindow( window, eventPtr->where, 
               &qd.screenBits.bounds );
         break;

This next case is interesting. If the mouseDown was inGoAway, call TrackGoAway() to ensure that the mouse button was released inside the close box.

      case inGoAway:
         if ( TrackGoAway( window, eventPtr->where ) )

If so, verify that the click was in the modeless dialog's close box (the only window with a close box, by the way).

            if ( window == gSettingsDLOG )
            {

If so, make the modeless dialog window invisible. Why not close the window? We want to keep the dialog around so if the user brings it back up, it will have the same settings and will be in the same position, without us having to keep track of all that stuff.

               HideWindow( window );

Once the window is hidden, we'll enable the File menu's Settings item.

               menu = GetMenuHandle( mFile );
               EnableItem( menu, iSettings );
            }
         break;
   }
}

HandleMenuChoice() does what it always has, dispatching menu selections to the Apple and File menus.

/********** 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() puts up an alert if the first item on the Apple menu was selected. An alert is like a dialog, but is not interactive (other than dismissing it). The alert comes up and is then dismissed, usually by a button click. Read the section on alerts in Inside Macintosh: Macintosh Toolbox Essentials. Alerts are not complicated.

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

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

HandleFileChoice() handles the two items in the File menu.

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

void   HandleFileChoice( short item )
{

If Settings was selected, we first check to see if the modeless dialog was created yet. If not, we create it by calling CreateDialog().

   switch ( item )
   {
      case iSettings:
         if ( gSettingsDLOG == NULL )
            CreateDialog();

If the dialog does exist, we make it visible and bring it to the front. How does the Settings... item get dimmed, you might ask. When the dialog is brought to the front, an activateEvt gets posted. The activateEvt handling code takes care of that.

         else
         {
            ShowWindow( gSettingsDLOG );
            SelectWindow( gSettingsDLOG );
         }
         break;

As always, when Quit is selected, we set gDone to true and drop out of the program.

      case iQuit:
         gDone = true;
         break;
   }
}

Since events for the modeless dialog are handled elsewhere, the only update event this code will see is for the My Pet Fred window.

/********** DoUpdate **********/

void   DoUpdate( EventRecord *eventPtr )
{
   PicHandle   pic;
   WindowPtr   window;
   Rect            r;

We'll retrieve the WindowPtr from eventPtr->message and load the current Fred PICT using LoadPICT.

   window = (WindowPtr)eventPtr->message;
   
   pic = LoadPICT( gCurrentPICT );

Next, we make the window the current port, call BeginUpdate(), then draw the newest version of Fred and call EndUpdate().

   SetPort( window );
   
   BeginUpdate( window );
   
   r = window->portRect;
   DrawPicture( pic, &r );
   
   EndUpdate( window );
}

Just as we'd do with a modal dialog, we load the modeless DLOG resource by calling GetNewDialog().

/********** CreateDialog **********/

void   CreateDialog( void )
{
   short      itemType;
   Handle      itemHandle;
   Rect         itemRect;
   short      curRadioButton;

   gSettingsDLOG = GetNewDialog( kDialogResID, 
         NULL, kMoveToFront );

If the DLOG couldn't be loaded, beep once then exit.

   if ( gSettingsDLOG == NULL )
   {
      SysBeep( 10 );   /* Couldn't load the DLOG resource!!! */
      ExitToShell();
   }

Once the DLOG is loaded, make the dialog window visible and the current port.

   ShowWindow( gSettingsDLOG );
   SetPort( gSettingsDLOG );

Next, turn the current radio button on.

   curRadioButton = gCurrentPICT - kBaseResID + kFirstRadio;
   GetDialogItem( gSettingsDLOG, curRadioButton, &itemType,
            &itemHandle, &itemRect );
   SetControlValue( (ControlHandle)itemHandle, kOn );
}

FlipControl() turns a radio button or check box that's on, off and one that's off, on.

/********** FlipControl **********/

void   FlipControl( ControlHandle control )
{
   SetControlValue( control, ! GetControlValue( control ) );
}

SwitchPICT() calls DisposeWindow() to free up the memory used by the specified window (this closes the window as well) and then calls CreateWindow() to create a My Pet Fred window that reflects or most current choice of pet.

/********** SwitchPICT **********/

void   SwitchPICT( void )
{
   DisposeWindow( gFredWindow );
   
   CreateWindow();
}

Running Modeless

Save your source code and you're ready to run. Select Run from the Project menu to compile and run your program. When the program runs, the My Pet Fred window will appear, showing PICT 128. Pull down the Apple menu and verify that the first item reads About Modeless. Select About Modeless. from the Apple menu and check out your About box. Are your changes all there? Click the OK button to dismiss the About box.

Hold down the mouse in the File menu and verify that the S command-key equivalent was added to the Settings item. Select Settings. The Settings dialog box should appear (Figure 12).

Figure 12. The Settings... modal dialog box.

Click the My Pet Fred window, bringing it to the front and sending the modeless dialog to the back. Notice that the radio buttons are dimmed when the dialog is no longer the front-most window (Figure 13).

Figure 13. The radio buttons are dimmed when the dialog box is not in front.

Now type the command-key equivalent S to bring the Settings dialog to the front again; the radio buttons should be enabled. Click the Elephant radio button. Notice that the My Pet Fred window changes appropriately, leaving the Settings window in front. Click a few more radio buttons. While you are at it, click the File menu. Notice that the Settings item has been dimmed. Though this doesn't help us much in this program, it's important to be able to disable and enable certain menu items when a modeless dialog is in front.

When you are satisfied with your pet selection, drag the Settings window to another part of your screen. Now click the close box. The Settings window disappears. Select Settings from the File menu. The Settings window reappears at the position it was in when it disappeared and with the same radio button settings.

Finally, type the command-key equivalent Q to exit the program.

Till Next Time...

Well, that's about it for modeless dialogs. Be sure to read the Inside Macintosh: Macintosh Toolbox Essentials chapters that pertain to dialogs and alerts. In a future column we'll spend some time with a filterProc, a procedure that you provide to the Toolbo, and that the Toolbox calls for you. The filterProc allows you to control how the user interact with a dialog box, including what text the user can type. You can read about filterProc in Inside Macintosh: Macintosh Toolbox Essentials in the description of the Dialog Manager routine ModalDialog().

 
AAPL
$104.83
Apple Inc.
+0.00
MSFT
$45.02
Microsoft Corpora
+0.00
GOOG
$543.98
Google Inc.
+0.00

MacTech Search:
Community Search:

Software Updates via MacUpdate

Skitch 2.7.3 - Take screenshots, annotat...
With Skitch, taking, annotating, and sharing screenshots or images is as fun as it is simple.Communicate and collaborate with images using Skitch and its intuitive, engaging drawing and annotating... Read more
Delicious Library 3.3.2 - Import, browse...
Delicious Library allows you to import, browse, and share all your books, movies, music, and video games with Delicious Library. Run your very own library from your home or office using our... Read more
Art Text 2.4.8 - Create high quality hea...
Art Text is an OS X application for creating high quality textual graphics, headings, logos, icons, Web site elements, and buttons. Thanks to multi-layer support, creating complex graphics is no... Read more
Live Interior 3D Pro 2.9.6 - Powerful an...
Live Interior 3D Pro is a powerful yet very intuitive interior designing application. View Video Tutorials It has every feature of Live Interior 3D Standard, plus some exclusive ones: Create multi... Read more
The Hit List 1.1.7 - Advanced reminder a...
The Hit List manages the daily chaos of your modern life. It's easy to learn - it's as easy as making lists. And it's powerful enough to let you plan, then forget, then act when the time is right.... Read more
jAlbum Pro 12.2.4 - Organize your digita...
jAlbum Pro has all the features you love in jAlbum, but comes with a commercial license. With jAlbum, you can create gorgeous custom photo galleries for the Web without writing a line of code!... Read more
jAlbum 12.2.4 - Create custom photo gall...
With jAlbum, you can create gorgeous custom photo galleries for the Web without writing a line of code! Beginner-friendly, with pro results Simply drag and drop photos into groups, choose a design... Read more
ExpanDrive 4.1.7 - Access remote files o...
ExpanDrive builds cloud storage in every application, acts just like a USB drive plugged into your Mac. With ExpanDrive, you can securely access any remote file server directly from the Finder or... Read more
OmniOutliner Pro 4.1.3 - Pro version of...
OmniOutliner Pro is a flexible program for creating, collecting, and organizing information. Give your creativity a kick start by using an application that's actually designed to help you think. It'... Read more
Evernote 5.6.2 - Create searchable notes...
Evernote allows you to easily capture information in any environment using whatever device or platform you find most convenient, and makes this information accessible and searchable at anytime, from... Read more

Latest Forum Discussions

See All

A Few Days Left (Games)
A Few Days Left 1.01 Device: iOS Universal Category: Games Price: $3.99, Version: 1.01 (iTunes) Description: Screenshots are in compliance to App Store's 4+ age rating! Please see App Preview for real game play! **Important: Make... | Read more »
Toca Boo (Education)
Toca Boo 1.0.2 Device: iOS Universal Category: Education Price: $2.99, Version: 1.0.2 (iTunes) Description: BOO! Did I scare you!? My name is Bonnie and my family loves to spook! Do you want to scare them back? Follow me and I'll... | Read more »
Intuon (Games)
Intuon 1.1 Device: iOS Universal Category: Games Price: $.99, Version: 1.1 (iTunes) Description: Join the battle with your intuition in a new hardcore game Intuon! How well do you trust your intuition? Can you find a needle in a... | Read more »
Ravenous Rampage (Games)
Ravenous Rampage 1.0 Device: iOS Universal Category: Games Price: $.99, Version: 1.0 (iTunes) Description: | Read more »
Partia 2 (Games)
Partia 2 1.0.1 Device: iOS Universal Category: Games Price: $5.99, Version: 1.0.1 (iTunes) Description: Partia 2 is a SRPG (Strategy Role-playing) video game inspired by Fire Emblem and Tear Ring Saga series. In a high fantasy... | Read more »
Puzzle to the Center of the Earth Review
Puzzle to the Center of the Earth Review By Campbell Bird on October 23rd, 2014 Our Rating: :: SPELUNKING PUZZLESUniversal App - Designed for iPhone and iPad Do some puzzles to make some platforms in this smart and fun free-to-play... | Read more »
Sleep Attack TD Review
Sleep Attack TD Review By Jennifer Allen on October 23rd, 2014 Our Rating: :: A TRUE TWISTUniversal App - Designed for iPhone and iPad Sleep Attack TD is a tower defense game with a difference – you can rotate the layout – and it’s... | Read more »
Mecanic (Education)
Mecanic 1.0 Device: iOS Universal Category: Education Price: $1.99, Version: 1.0 (iTunes) Description: Plates, screws, wheels ... Everything you need to achieve whatever you want... MECHANICWith 'MECANIC' kids will have fun... | Read more »
Earn Your Master Camper Badge in Camp Po...
Earn Your Master Camper Badge in Camp Pokemon Posted by Jessica Fisher on October 23rd, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Garruk Gets His Revenge in a New Magic 2...
Garruk Gets His Revenge in a New Magic 2015 Expansion, Coming This November Posted by Jessica Fisher on October 23rd, 2014 [ permalink ] | Read more »

Price Scanner via MacPrices.net

13-inch 2.5GHz MacBook Pro on sale for $949,...
Best Buy has the 13″ 2.5GHz MacBook Pro available for $949.99 on their online store. Choose free shipping or free instant local store pickup (if available). Their price is $150 off MSRP. Price is... Read more
Save up to $125 on Retina MacBook Pros
B&H Photo has the new 2014 13″ and 15″ Retina MacBook Pros on sale for up to $125 off MSRP. Shipping is free, and B&H charges NY sales tax only. They’ll also include free copies of Parallels... Read more
Apple refurbished Time Capsules available sta...
The Apple Store has certified refurbished Time Capsules available for up to $60 off MSRP. Apple’s one-year warranty is included with each Time Capsule, and shipping is free: - 2TB Time Capsule: $255... Read more
Textilus New Word, Notes and PDF Processor fo...
Textilus is new word-crunching, notes, and PDF processor designed exclusively for the iPad. I haven’t had time to thoroughly check it out yet, but it looks great and early reviews are positive.... Read more
WD My Passport Pro Bus-Powered Thunderbolt RA...
WD’s My Passport Pro RAID solution is powered by an integrated Thunderbolt cable for true portability and speeds as high as 233 MB/s. HighlightsOverviewSpecifications Transfer, Back Up And Edit In... Read more
Save with Best Buy’s College Student Deals
Take an additional $50 off all MacBooks and iMacs at Best Buy Online with their College Students Deals Savings, valid through November 1st. Anyone with a valid .EDU email address can take advantage... Read more
iPad Air 2 & iPad mini 3 Best Tablets Yet...
The new iPads turned out to be pretty much everything I’d been hoping for and more than I’d expected.”More” particularly in terms of a drinking-from-a-firehose choice of models and configurations,... Read more
Drafts 4 Reinvents iOS Productivity App
N Richland Hills, Texas based Agile Tortoise has announced the release of Drafts 4 for iPhone and iPad. Drafts is a quick capture note taking app with flexible output actions. Drafts 4 scales from... Read more
AT&T accepting preorders for new iPads fo...
AT&T Wireless is accepting preorders for the new iPad Air 2 and iPad mini 3, cellular models, for $100 off MSRP with a 2-year service agreement: - 16GB iPad Air 2 WiFi + Cellular: $529.99 - 64GB... Read more
Apple offering refurbished Mac Pros for up to...
The Apple Store is offering Apple Certified Refurbished 2013 Mac Pros for up to $600 off the cost of new models. An Apple one-year warranty is included with each Mac Pro, and shipping is free. The... Read more

Jobs Board

*Apple* Solutions Consultant - Apple Inc. (U...
…important role that the ASC serves is that of providing an excellent Apple Customer Experience. Responsibilities include: * Promoting Apple products and solutions 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* 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
Project Manager / Business Analyst, WW *Appl...
…a senior project manager / business analyst to work within our Worldwide Apple Fulfillment Operations and the Business Process Re-engineering team. This role will work Read more
*Apple* Retail - Multiple Positions (US) - A...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.