for_each(BumpTopCommand* option, ordered_context_menu_items) { err = InsertMenuItemTextWithCFString(carbon_context_menu, CFStringFromQString(option->name()), menu_size, // MenuItemIndex inAfterItem option->isSeparator() ? kMenuItemAttrSeparator : 0, // MenuItemAttributes inAttributes 0); // MenuCommand inCommandID if (option->has_subcommands()) { QStringList subcommand_names = option->subcommand_names(actors); err = CreateNibReference(CFSTR("ContextMenu"), &nib_ref); MenuRef carbon_context_sub_menu; err = CreateMenuFromNib(nib_ref, CFSTR("ItemContextMenu"), &carbon_context_sub_menu); err = ChangeMenuAttributes(carbon_context_sub_menu, kMenuAttrCondenseSeparators, NULL); DisposeNibReference(nib_ref); int sub_menu_size = 0; for_each(QString subcommand, subcommand_names) { err = InsertMenuItemTextWithCFString(carbon_context_sub_menu, CFStringFromQString(subcommand), sub_menu_size, // MenuItemIndex inAfterItem subcommand == "" ? kMenuItemAttrSeparator : 0, // MenuItemAttributes inAttributes 0); // MenuCommand inCommandID CGImageRef icon = option->iconForSubcommand(actors, sub_menu_size); if (icon) { err = SetMenuItemIconHandle (carbon_context_sub_menu, sub_menu_size+1, kMenuCGImageRefType, (Handle) icon); CGImageRelease(icon); } sub_menu_size++; }
// -------------------------------------------------------------------------------------- static pascal OSErr openApplicationAEHandler(const AppleEvent *appleEvent, AppleEvent *reply, long refcon) { OSErr error; DescType returnedType; Size actualSize; error = AEGetAttributePtr(appleEvent, keyMissedKeywordAttr, typeWildCard, &returnedType, NULL, 0, &actualSize); if (error == noErr) error = errAEParamMissed; else if (error == errAEDescNotFound) { MenuRef menu; CFStringRef aboutString; EventTypeSpec applicationEvents[] = { {kEventClassCommand, kEventCommandProcess} }; /* For our program running in Carbon, a Quit Application Apple Event handler is unnecessary because RunApplicationEventLoop installs one for us that calls QuitApplicationEventLoop. However we will leave ours here in case we ever need it to do something different so that we know where it belongs. */ gQuitAppAEHandler = NewAEEventHandlerUPP(quitApplicationAEHandler); error = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, gQuitAppAEHandler, 0, false); if (error != noErr) // if we can't allow the user a mechanism to quit { // we'd better just quit right now DisposeAEEventHandlerUPP(gOpenAppAEHandler); DisposeAEEventHandlerUPP(gQuitAppAEHandler); ExitToShell(); } gViewsFontChangedAEHandler = NewAEEventHandlerUPP(viewsFontChangedAEHandler); error = AEInstallEventHandler(kAppearanceEventClass, kAEViewsFontChanged, gViewsFontChangedAEHandler, 0, false); #if TARGET_API_MAC_OSX #pragma unused (reply, refcon) menu = GetMenuRef(mAppleApplication); aboutString = CFCopyLocalizedString(CFSTR("About Item"), NULL); SetMenuItemTextWithCFString(menu, iAbout, aboutString); // get rid of the "..." CFRelease(aboutString); // if we're running in OS X menu = GetMenuRef(mFile); ChangeMenuAttributes(menu, kMenuAttrAutoDisable, 0); DeleteMenuItem(menu, iQuit); // remove the Quit item and separator DeleteMenuItem(menu, iQuitSeparator); // if we're running in OS X #else #pragma unused (reply, refcon, menu, aboutString) #endif gAppEventHandler = NewEventHandlerUPP(appEventHandler); InstallApplicationEventHandler(gAppEventHandler, GetEventTypeCount(applicationEvents), applicationEvents, NULL, NULL); InitIconDataBrowser(); error = noErr; } return error; }
AEPutDesc(&file_list, 0, &file_list_element); } } UInt32 user_selection_type; MenuID menu_id; MenuItemIndex menu_item_index; IBNibRef nib_ref; err = CreateNibReference(CFSTR("ContextMenu"), &nib_ref); MenuRef carbon_context_menu; err = CreateMenuFromNib(nib_ref, CFSTR("ItemContextMenu"), &carbon_context_menu); // change double separators to just one separator: err = ChangeMenuAttributes(carbon_context_menu, kMenuAttrCondenseSeparators, NULL); DisposeNibReference(nib_ref); int num_submenu_items = 0; int menu_size = 0; for_each(BumpTopCommand* option, ordered_context_menu_items) { err = InsertMenuItemTextWithCFString(carbon_context_menu, CFStringFromQString(option->name()), menu_size, // MenuItemIndex inAfterItem option->isSeparator() ? kMenuItemAttrSeparator : 0, // MenuItemAttributes inAttributes 0); // MenuCommand inCommandID if (option->has_subcommands()) { QStringList subcommand_names = option->subcommand_names(actors); err = CreateNibReference(CFSTR("ContextMenu"), &nib_ref); MenuRef carbon_context_sub_menu;