Important: The information in this document is obsolete and should not be used for new development.
Implementing the Cyberdog Preferences Command
The Cyberdog Preferences command responds to its corresponding menu item to display the Cyberdog Preferences dialog box. When your part is activated, itsAdjustMenus
method is called to set up its menus. You can modify this method to enable the Cyberdog Preferences menu item. To enable the Cyberdog preferences menu item, you must take these actions:
Listing 3-15 shows the button part's
- Set the menu item string and enable a command for the preferences.
- Call the Cyberdog service menu's
Adjust
method
AdjustMenus
method.Listing 3-15 The button part's
AdjustMenus
method
void CybTxtBtn::AdjustMenus( Environment* ev, ODFrame* frame ) { if (frame->IsRoot(ev)) { // A root part must validate the menu bar before displaying it // because a part can swap the base menu bar at any time. CheckMenus(ev, kODNULL); } // After copying the base menu bar, install your part's menus. ... TRY ... ODArbitrator* arbitrator = ODGetSession(ev,fSelf)->GetArbitrator(ev); TempODFrame menuOwner = arbitrator->AcquireFocusOwner(ev, gGlobals->fMenuFocus); if ( ODObjectsAreEqual(ev, frame, menuOwner) ) { Str63 text; ... ODGetIndString(text, kMenuStringResID, kDefaultContent2ID); // Create an IText object to pass into the menu bar. TempODIText prefItem(CreateIText(gGlobals->fEditorsScript, gGlobals->fEditorsLanguage, (StringPtr)&text)); // Change the text of the "Preferences" menu item. fMenuBar->SetItemString(ev, kODCommandPreferences, prefItem); fMenuBar->EnableCommand(ev, kODCommandPreferences, kODTrue); } // Allow Cyberdog services to enable or disable their menu items. if(fCyberServiceMenu) fCyberServiceMenu->Adjust(ev, frame); CATCH_ALL ENDTRY }When a menu event occurs, you should call the Cyberdog service menu's DoCommand method to allow a Cyberdog service to handle the event. If the Cyberdog Preferences menu item is selected, you must call the Cyberdog session's ShowPreferencesDialog method to display the Cyberdog Preferences dialog box. Listing 3-16 shows the button part's HandleMenuEvent method.
- Note
- In this example, the part's standard Preferences menu item, specified by kODCommandPreferences, is replaced by the Cyberdog Preferences menu item. u
Listing 3-16 The button part's
HandleMenuEvent
method
ODBoolean CybTxtBtn::HandleMenuEvent(Environment* ev, ODEventData* event, ODFrame* frame ) { ODULong menuResult = event->message; ODUShort menu = HiWord(menuResult); ODUShort item = LoWord(menuResult); ODBoolean handled = kODTrue; ODULong commandID; commandID = fMenuBar->GetCommand(ev, menu, item); // Give Cyberdog the first chance at the command. if (fCyberServiceMenu) handled = fCyberServiceMenu->DoCommand(ev, commandID, frame); if (handled == kODFalse) { switch (commandID) { ... // The Cyberdog Preferences command was sent. // Show the Cyberdog Preferences dialog box. case kODCommandPreferences: CyberSession* cyberSession = GetCyberSession(ev); cyberSession->ShowPreferencesDialog(ev); handled = kODTrue; break; ... default: handled = kODFalse; } } return handled; }