void sync_menu_takeover_menu (GtkMenuShell *menu_shell) { static MenuRef carbon_menubar = NULL; g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell)); if (carbon_menu_quark == 0) carbon_menu_quark = g_quark_from_static_string ("CarbonMenu"); if (carbon_menu_item_quark == 0) carbon_menu_item_quark = g_quark_from_static_string ("CarbonMenuItem"); if (!carbon_menubar) { carbon_menubar = AcquireRootMenu(); setup_menu_event_handler (); } sync_menu_shell (menu_shell, carbon_menubar, TRUE); }
int main() { IBNibRef nibRef; WindowRef window; OSStatus err; MenuDefSpec defSpec; MenuRef menu; SInt32 gestaltResult; // Create a Nib reference passing the name of the nib file (without the .nib extension) // CreateNibReference only searches into the application bundle. err = CreateNibReference(CFSTR("main"), &nibRef); require_noerr( err, CantGetNibRef ); // Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar // object. This name is set in InterfaceBuilder when the nib is created. err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar")); require_noerr( err, CantSetMenuBar ); // Add a Quit item if we're not running on X Gestalt( gestaltMenuMgrAttr, &gestaltResult ); if ( ( gestaltResult & gestaltMenuMgrAquaLayoutMask ) == 0 ) { MenuRef rootMenu = AcquireRootMenu(); MenuItemIndex item; GetMenuItemHierarchicalMenu( rootMenu, 2, &menu ); AppendMenuItemTextWithCFString( menu, CFSTR("Quit"), 0, kHICommandQuit, &item ); SetMenuItemCommandKey( menu, item, false, 'Q' ); ReleaseMenu( rootMenu ); } defSpec.defType = kMenuDefProcPtr; defSpec.u.defProc = NewMenuDefUPP( SampleMDEF ); // Create a standard menu CreateNewMenu( 200, 0, &menu ); SetMenuTitleWithCFString( menu, CFSTR("Sample") ); InsertMenu( menu, 0 ); AddSampleItems( menu ); // Create a custom menu CreateCustomMenu( &defSpec, 201, 0, &menu ); SetMenuTitleWithCFString( menu, CFSTR("Sample [Custom]") ); InsertMenu( menu, 0 ); AddSampleItems( menu ); // Create a standard menu CreateNewMenu( 202, 0, &menu ); SetMenuTitleWithCFString( menu, CFSTR("Shell") ); InsertMenu( menu, 0 ); AddShellItems( menu ); // Create a custom menu CreateCustomMenu( &defSpec, 203, 0, &menu ); SetMenuTitleWithCFString( menu, CFSTR("Shell [Custom]") ); InsertMenu( menu, 0 ); AddShellItems( menu ); // Create a standard menu CreateNewMenu( 204, 0, &menu ); SetMenuTitleWithCFString( menu, CFSTR("Fonts") ); InsertMenu( menu, 0 ); CreateStandardFontMenu( menu, 0, 0, 0, NULL ); // Create a custom menu CreateCustomMenu( &defSpec, 205, 0, &menu ); SetMenuTitleWithCFString( menu, CFSTR("Fonts [Custom]") ); InsertMenu( menu, 0 ); CreateStandardFontMenu( menu, 0, 0, 0, NULL ); // Then create a window. "MainWindow" is the name of the window object. This name is set in // InterfaceBuilder when the nib is created. err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window); require_noerr( err, CantCreateWindow ); // We don't need the nib reference anymore. DisposeNibReference(nibRef); // The window was created hidden so show it. ShowWindow( window ); // Call the event loop RunApplicationEventLoop(); CantCreateWindow: CantSetMenuBar: CantGetNibRef: return err; }