Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Cyberdog Programmer's Kit / Part 2 - Programming in Cyberdog
Chapter 5 - Embedding a Cyberdog Display Part in a Navigator


Enabling Menu Items From an Embedded Display Part

A navigator allows an embedded display part to specify whether it wishes to enable several Document menu items. These commands are Save a Copy, Page Setup, and Print. The navigator calls the part extension's HandleCommand method for each command. Your part extension's HandleCommand method should return kODTrue if your embedded display part handles the command or kODFalse if it does not. If your part does not handle the command, you must call the part extension's inherited HandleCommand method.

The last parameter to the HandleCommand method for these commands specifies whether or not the menu item should be enabled. If your HandleCommand method returns kODTrue, you can set this parameter to kODTrue if you want the menu item enabled or kODFalse if you want the menu item to be disabled.

Listing 5-11 shows the embedded text-viewer part extension's HandleCommand method. It calls its part's HandleCommand method to specify whether it handles commands.

Listing 5-11 The HandleCommand method of the embedded text-viewer's part extension

SOM_Scope ODBoolean  SOMLINK som_CybTxtNavViewerCyberExt__HandleCommand
                     (Apple_som_CybTxtNavViewerCyberExt *somSelf,
                      Environment *ev,
                      long commandCreator,
                      long commandID,
                      ODFrame* frame,
                      void* commandData)
{
   ...
   ODBoolean handled = kODFalse;
   
   SOM_TRY
      
      CybTxtNavViewer* realPart 
                        = (CybTxtNavViewer*) somThis->fBasePart;
      if (realPart)
         handled = realPart->HandleCommand(ev, 
                                 commandCreator, 
                                 commandID, 
                                 frame, 
                                 commandData);
      
      if(handled == kODFalse)
         handled = Apple_som_CybTxtNavViewerCyberExt_parent
                              _CyberPartExtension_HandleCommand
                              (somSelf,ev,
                               commandCreator,
                               commandID,
                               frame,
                               commandData);
         
   SOM_CATCH_ALL
      handled = kODFalse;
   SOM_ENDTRY
   
   return handled;
}
Listing 5-12 shows the embedded text-viewer part's HandleCommand method. The commandCreator parameter is used to qualify the commands to only those issued by the navigator, as specified by kNavigatorCreator. The embedded text-viewer part indicates that each of the commands are handled; however, they appear disabled in the menu.

Listing 5-12 The HandleCommand method of the embedded text-viewer's part

ODBoolean CybTxtNavViewer::HandleCommand(Environment*, 
                               long commandCreator, 
                               long commandID, 
                               ODFrame* , 
                               void* cmdData)
{
   ODBoolean handled = kODFalse;
   
   switch(commandCreator)
   {
      case kNavigatorCreator:
         {
            // This sample handles all of these commands but
            // leaves them disabled.
            ODBoolean* enableTheMenuCommand = (ODBoolean*)cmdData;
            switch(commandID)
            {
               case kODCommandPrint:
               case kODCommandPageSetup:
               case kODCommandSaveACopy:
                  *enableTheMenuCommand = kODFalse;
                  handled = kODTrue;
                  break;
            }
         }
         break;
   }
      
   return handled;
}


Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996