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++; }
S32 PopupMenu::insertSubMenu(S32 pos, const char *title, PopupMenu *submenu) { for(S32 i = 0;i < mSubmenus->size();i++) { if(submenu == (*mSubmenus)[i]) { Con::errorf("PopupMenu::insertSubMenu - Attempting to add submenu twice"); return -1; } } CFStringRef cftitle = CFStringCreateWithCString(NULL,title,kCFStringEncodingUTF8); InsertMenuItemTextWithCFString(mData->mMenu, cftitle, pos, 0, kHICommandTorque + 1); CFRelease( cftitle ); // ensure that we have the correct index for the new menu item MenuRef outref; MenuItemIndex item; GetIndMenuItemWithCommandID(mData->mMenu, kHICommandTorque+1, 1, &outref, &item); SetMenuItemCommandID(mData->mMenu, item, 0); S32 tag = PlatformPopupMenuData::getTag(); SetMenuItemRefCon( mData->mMenu, item, tag); // store a pointer to the PopupMenu this item represents. See PopupMenu::removeItem() SetMenuItemProperty(mData->mMenu, item, 'GG2d', 'subm', sizeof(PopupMenu*), submenu); SetMenuItemHierarchicalMenu( mData->mMenu, item, submenu->mData->mMenu); mSubmenus->addObject(submenu); return tag; }
void UMAInsertSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , SInt16 id ) { InsertMenuItemTextWithCFString( menu, CFSTR("A"), item, 0, 0); UMASetMenuItemText( menu, item+1, title , encoding ); SetMenuItemHierarchicalID( menu , item+1 , id ) ; }
void UMAInsertMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , wxAcceleratorEntry *entry ) { InsertMenuItemTextWithCFString( menu, CFSTR("A"), item, 0, 0); // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise) ChangeMenuItemAttributes( menu , item+1, kMenuItemAttrIgnoreMeta , 0 ) ; UMASetMenuItemText(menu, item+1 , title , encoding ); UMASetMenuItemShortcut( menu , item+1 , entry ) ; }
virtual void InsertOrAppend(wxMenuItem *pItem, size_t pos) { // MacOS counts menu items from 1 and inserts after, therefore having the // same effect as wx 0 based and inserting before, we must correct pos // after however for updates to be correct MenuItemIndex index = pos; if ( pos == (size_t) -1 ) index = CountMenuItems(m_osxMenu); if ( pItem->IsSeparator() ) { InsertMenuItemTextWithCFString( m_osxMenu, CFSTR(""), index, kMenuItemAttrSeparator, 0); // now switch to the Carbon 1 based counting index += 1 ; } else { InsertMenuItemTextWithCFString( m_osxMenu, CFSTR("placeholder"), index, 0, 0 ); // now switch to the Carbon 1 based counting index += 1 ; if ( pItem->IsSubMenu() ) { MenuRef submenu = pItem->GetSubMenu()->GetHMenu(); SetMenuItemHierarchicalMenu(m_osxMenu, index, submenu); // carbon is using the title of the submenu, eg in the menubar SetMenuTitleWithCFString(submenu, wxCFStringRef(pItem->GetItemLabelText())); } else { SetMenuItemCommandID( m_osxMenu, index , wxIdToMacCommand(pItem->GetId()) ) ; } } wxMenuItemCarbonImpl* impl = (wxMenuItemCarbonImpl*) pItem->GetPeer(); impl->AttachToParent( m_osxMenu, index ); // only now can all settings be updated correctly pItem->UpdateItemText(); pItem->UpdateItemStatus(); pItem->UpdateItemBitmap(); }
bool AquaGui::createMenu() { MenuRef rApplicationMenu; MenuItemIndex outIndex[1]; /* Enable 'Prefereces...' */ EnableMenuCommand(NULL, kHICommandPreferences); GetIndMenuItemWithCommandID(NULL, kHICommandPreferences, 1, &rApplicationMenu, outIndex); /* Enable 'About' */ InsertMenuItemTextWithCFString(rApplicationMenu, CFSTR("About gnash"), (short) 0, 0, kHICommandAbout); return true; }
void wxInsertMenuItemsInMenu(wxMenu* menu, MenuRef wm, MenuItemIndex insertAfter) { wxMenuItemList::compatibility_iterator node; wxMenuItem *item; wxMenu *subMenu = NULL ; bool newItems = false; for (node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext()) { item = (wxMenuItem *)node->GetData(); subMenu = item->GetSubMenu() ; if (subMenu) { wxInsertMenuItemsInMenu(subMenu, (MenuRef)subMenu->GetHMenu(), 0); } if ( item->IsSeparator() ) { if ( wm && newItems) InsertMenuItemTextWithCFString( wm, CFSTR(""), insertAfter, kMenuItemAttrSeparator, 0); newItems = false; } else { wxAcceleratorEntry* entry = wxAcceleratorEntry::Create( item->GetItemLabel() ) ; MenuItemIndex winListPos = (MenuItemIndex)-1; OSStatus err = GetIndMenuItemWithCommandID(wm, wxIdToMacCommand ( item->GetId() ), 1, NULL, &winListPos); if ( wm && err == menuItemNotFoundErr ) { // NB: the only way to determine whether or not we should add // a separator is to know if we've added menu items to the menu // before the separator. newItems = true; UMAInsertMenuItem(wm, wxStripMenuCodes(item->GetItemLabel()) , wxFont::GetDefaultEncoding(), insertAfter, entry); SetMenuItemCommandID( wm , insertAfter+1 , wxIdToMacCommand ( item->GetId() ) ) ; SetMenuItemRefCon( wm , insertAfter+1 , (URefCon) item ) ; } delete entry ; } } }
S32 PopupMenu::insertItem(S32 pos, const char *title, const char* accel) { MenuItemIndex item; CFStringRef cftitle; MenuItemAttributes attr = 0; bool needRelease = false; if(title && *title) { cftitle = CFStringCreateWithCString(NULL,title,kCFStringEncodingUTF8); needRelease = true; } else { cftitle = CFSTR("-"); attr = kMenuItemAttrSeparator; } InsertMenuItemTextWithCFString(mData->mMenu, cftitle, pos, attr, kHICommandTorque + 1); if( needRelease ) CFRelease( cftitle ); // ensure that we have the correct index for the new menu item MenuRef outref; GetIndMenuItemWithCommandID(mData->mMenu, kHICommandTorque+1, 1, &outref, &item); SetMenuItemCommandID(mData->mMenu, item, kHICommandTorque); // save a ref to the PopupMenu that owns this item. PopupMenu* thisMenu = this; SetMenuItemProperty(mData->mMenu, item, 'GG2d', 'ownr', sizeof(PopupMenu*), &thisMenu); // construct the accelerator keys _assignCommandKeys(accel, mData->mMenu, item); S32 tag = PlatformPopupMenuData::getTag(); SetMenuItemRefCon(mData->mMenu, item, tag); return tag; }
void wxMenuBar::MacInstallMenuBar() { if ( s_macInstalledMenuBar == this ) return ; m_rootMenu->GetPeer()->MakeRoot(); // hide items in the apple menu that don't exist in the wx menubar int menuid = 0; wxMenuItem* appleItem = NULL; wxMenuItem* wxItem = NULL; menuid = wxApp::s_macAboutMenuItemId; appleItem = m_appleMenu->FindItem(menuid); wxItem = FindItem(menuid); if ( appleItem != NULL ) { if ( wxItem == NULL ) appleItem->GetPeer()->Hide(); else appleItem->SetItemLabel(wxItem->GetItemLabel()); } menuid = wxApp::s_macPreferencesMenuItemId; appleItem = m_appleMenu->FindItem(menuid); wxItem = FindItem(menuid); if ( appleItem != NULL ) { if ( wxItem == NULL ) appleItem->GetPeer()->Hide(); else appleItem->SetItemLabel(wxItem->GetItemLabel()); } #if 0 // if we have a mac help menu, clean it up before adding new items MenuHandle helpMenuHandle ; MenuItemIndex firstUserHelpMenuItem ; if ( UMAGetHelpMenuDontCreate( &helpMenuHandle , &firstUserHelpMenuItem) == noErr ) { for ( int i = CountMenuItems( helpMenuHandle ) ; i >= firstUserHelpMenuItem ; --i ) DeleteMenuItem( helpMenuHandle , i ) ; } else { helpMenuHandle = NULL ; } if ( wxApp::s_macPreferencesMenuItemId) { wxMenuItem *item = FindItem( wxApp::s_macPreferencesMenuItemId , NULL ) ; if ( item == NULL || !(item->IsEnabled()) ) DisableMenuCommand( NULL , kHICommandPreferences ) ; else EnableMenuCommand( NULL , kHICommandPreferences ) ; } // Unlike preferences which may or may not exist, the Quit item should be always // enabled unless it is added by the application and then disabled, otherwise // a program would be required to add an item with wxID_EXIT in order to get the // Quit menu item to be enabled, which seems a bit burdensome. if ( wxApp::s_macExitMenuItemId) { wxMenuItem *item = FindItem( wxApp::s_macExitMenuItemId , NULL ) ; if ( item != NULL && !(item->IsEnabled()) ) DisableMenuCommand( NULL , kHICommandQuit ) ; else EnableMenuCommand( NULL , kHICommandQuit ) ; } wxString strippedHelpMenuTitle = wxStripMenuCodes( wxApp::s_macHelpMenuTitleName ) ; wxString strippedTranslatedHelpMenuTitle = wxStripMenuCodes( wxString( _("&Help") ) ) ; wxMenuList::compatibility_iterator menuIter = m_menus.GetFirst(); for (size_t i = 0; i < m_menus.GetCount(); i++, menuIter = menuIter->GetNext()) { wxMenuItemList::compatibility_iterator node; wxMenuItem *item; wxMenu* menu = menuIter->GetData() , *subMenu = NULL ; wxString strippedMenuTitle = wxStripMenuCodes(m_titles[i]); if ( strippedMenuTitle == wxT("?") || strippedMenuTitle == strippedHelpMenuTitle || strippedMenuTitle == strippedTranslatedHelpMenuTitle ) { for (node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext()) { item = (wxMenuItem *)node->GetData(); subMenu = item->GetSubMenu() ; if (subMenu) { UMAAppendMenuItem(mh, wxStripMenuCodes(item->GetText()) , wxFont::GetDefaultEncoding() ); MenuItemIndex position = CountMenuItems(mh); ::SetMenuItemHierarchicalMenu(mh, position, MAC_WXHMENU(subMenu->GetHMenu())); } else { if ( item->GetId() != wxApp::s_macAboutMenuItemId ) { // we have found a user help menu and an item other than the about item, // so we can create the mac help menu now, if we haven't created it yet if ( helpMenuHandle == NULL ) { if ( UMAGetHelpMenu( &helpMenuHandle , &firstUserHelpMenuItem) != noErr ) { helpMenuHandle = NULL ; break ; } } } if ( item->IsSeparator() ) { if ( helpMenuHandle ) AppendMenuItemTextWithCFString( helpMenuHandle, CFSTR(""), kMenuItemAttrSeparator, 0,NULL); } else { wxAcceleratorEntry* entry = wxAcceleratorEntry::Create( item->GetItemLabel() ) ; if ( item->GetId() == wxApp::s_macAboutMenuItemId ) { // this will be taken care of below } else { if ( helpMenuHandle ) { UMAAppendMenuItem(helpMenuHandle, wxStripMenuCodes(item->GetItemLabel()) , wxFont::GetDefaultEncoding(), entry); SetMenuItemCommandID( helpMenuHandle , CountMenuItems(helpMenuHandle) , wxIdToMacCommand ( item->GetId() ) ) ; SetMenuItemRefCon( helpMenuHandle , CountMenuItems(helpMenuHandle) , (URefCon) item ) ; } } delete entry ; } } } } else if ( ( m_titles[i] == wxT("Window") || m_titles[i] == wxT("&Window") ) && GetAutoWindowMenu() ) { if ( MacGetWindowMenuHMenu() == NULL ) { CreateStandardWindowMenu( 0 , (MenuHandle*) &s_macWindowMenuHandle ) ; } MenuRef wm = (MenuRef)MacGetWindowMenuHMenu(); if ( wm == NULL ) break; // get the insertion point in the standard menu MenuItemIndex winListStart; GetIndMenuItemWithCommandID(wm, kHICommandWindowListSeparator, 1, NULL, &winListStart); // add a separator so that the standard items and the custom items // aren't mixed together, but only if this is the first run OSStatus err = GetIndMenuItemWithCommandID(wm, 'WXWM', 1, NULL, NULL); if ( err == menuItemNotFoundErr ) { InsertMenuItemTextWithCFString( wm, CFSTR(""), winListStart-1, kMenuItemAttrSeparator, 'WXWM'); } wxInsertMenuItemsInMenu(menu, wm, winListStart); } else { UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , m_titles[i], GetFont().GetEncoding() ) ; menu->MacBeforeDisplay(false) ; ::InsertMenu(MAC_WXHMENU(GetMenu(i)->GetHMenu()), 0); } } // take care of the about menu item wherever it is { wxMenu* aboutMenu ; wxMenuItem *aboutMenuItem = FindItem(wxApp::s_macAboutMenuItemId , &aboutMenu) ; if ( aboutMenuItem ) { wxAcceleratorEntry* entry = wxAcceleratorEntry::Create( aboutMenuItem->GetItemLabel() ) ; UMASetMenuItemText( GetMenuHandle( kwxMacAppleMenuId ) , 1 , wxStripMenuCodes ( aboutMenuItem->GetItemLabel() ) , wxFont::GetDefaultEncoding() ); UMAEnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 , true ); SetMenuItemCommandID( GetMenuHandle( kwxMacAppleMenuId ) , 1 , kHICommandAbout ) ; SetMenuItemRefCon(GetMenuHandle( kwxMacAppleMenuId ) , 1 , (URefCon)aboutMenuItem ) ; UMASetMenuItemShortcut( GetMenuHandle( kwxMacAppleMenuId ) , 1 , entry ) ; delete entry; } } if ( GetAutoWindowMenu() ) { if ( MacGetWindowMenuHMenu() == NULL ) CreateStandardWindowMenu( 0 , (MenuHandle*) &s_macWindowMenuHandle ) ; InsertMenu( (MenuHandle) MacGetWindowMenuHMenu() , 0 ) ; } ::DrawMenuBar() ; #endif s_macInstalledMenuBar = this; }
void ige_mac_menu_add_app_menu_item (IgeMacMenuGroup *group, GtkMenuItem *menu_item, const gchar *label) { MenuRef appmenu; GList *list; gint index = 0; g_return_if_fail (group != NULL); g_return_if_fail (GTK_IS_MENU_ITEM (menu_item)); setup_menu_event_handler (); if (GetIndMenuItemWithCommandID (NULL, kHICommandHide, 1, &appmenu, NULL) != noErr) { g_warning ("%s: retrieving app menu failed", G_STRFUNC); return; } for (list = app_menu_groups; list; list = g_list_next (list)) { IgeMacMenuGroup *list_group = list->data; index += g_list_length (list_group->items); /* adjust index for the separator between groups, but not * before the first group */ if (list_group->items && list->prev) index++; if (group == list_group) { CFStringRef cfstr; /* add a separator before adding the first item, but not * for the first group */ if (!group->items && list->prev) { InsertMenuItemTextWithCFString (appmenu, NULL, index, kMenuItemAttrSeparator, 0); index++; } if (!label) label = get_menu_label_text (GTK_WIDGET (menu_item), NULL); cfstr = CFStringCreateWithCString (NULL, label, kCFStringEncodingUTF8); InsertMenuItemTextWithCFString (appmenu, cfstr, index, 0, 0); SetMenuItemProperty (appmenu, index + 1, IGE_QUARTZ_MENU_CREATOR, IGE_QUARTZ_ITEM_WIDGET, sizeof (menu_item), &menu_item); CFRelease (cfstr); gtk_widget_hide (GTK_WIDGET (menu_item)); group->items = g_list_append (group->items, menu_item); return; } } if (!list) g_warning ("%s: app menu group %p does not exist", G_STRFUNC, group); }
static void sync_menu_shell (GtkMenuShell *menu_shell, MenuRef carbon_menu, gboolean toplevel, gboolean debug) { GList *children; GList *l; MenuItemIndex carbon_index = 1; if (debug) g_printerr ("%s: syncing shell %p\n", G_STRFUNC, menu_shell); carbon_menu_connect (GTK_WIDGET (menu_shell), carbon_menu, toplevel); children = gtk_container_get_children (GTK_CONTAINER (menu_shell)); for (l = children; l; l = l->next) { GtkWidget *menu_item = l->data; CarbonMenuItem *carbon_item; if (GTK_IS_TEAROFF_MENU_ITEM (menu_item)) continue; if (toplevel && g_object_get_data (G_OBJECT (menu_item), "gtk-empty-menu-item")) continue; carbon_item = carbon_menu_item_get (menu_item); if (debug) g_printerr ("%s: carbon_item %d for menu_item %d (%s, %s)\n", G_STRFUNC, carbon_item ? carbon_item->index : -1, carbon_index, get_menu_label_text (menu_item, NULL), g_type_name (G_TYPE_FROM_INSTANCE (menu_item))); if (carbon_item && carbon_item->index != carbon_index) { if (debug) g_printerr ("%s: -> not matching, deleting\n", G_STRFUNC); DeleteMenuItem (carbon_item->menu, carbon_index); carbon_item = NULL; } if (!carbon_item) { GtkWidget *label = NULL; const gchar *label_text; CFStringRef cfstr = NULL; MenuItemAttributes attributes = 0; if (debug) g_printerr ("%s: -> creating new\n", G_STRFUNC); label_text = get_menu_label_text (menu_item, &label); if (label_text) cfstr = CFStringCreateWithCString (NULL, label_text, kCFStringEncodingUTF8); if (GTK_IS_SEPARATOR_MENU_ITEM (menu_item)) attributes |= kMenuItemAttrSeparator; if (!gtk_widget_is_sensitive (menu_item)) attributes |= kMenuItemAttrDisabled; if (!gtk_widget_get_visible (menu_item)) attributes |= kMenuItemAttrHidden; InsertMenuItemTextWithCFString (carbon_menu, cfstr, carbon_index - 1, attributes, 0); SetMenuItemProperty (carbon_menu, carbon_index, IGE_QUARTZ_MENU_CREATOR, IGE_QUARTZ_ITEM_WIDGET, sizeof (menu_item), &menu_item); if (cfstr) CFRelease (cfstr); carbon_item = carbon_menu_item_connect (menu_item, label, carbon_menu, carbon_index); if (GTK_IS_CHECK_MENU_ITEM (menu_item)) carbon_menu_item_update_active (carbon_item, menu_item); carbon_menu_item_update_accel_closure (carbon_item, menu_item); if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (menu_item))) carbon_menu_item_update_submenu (carbon_item, menu_item); } carbon_index++; } g_list_free (children); }
static void sync_menu_shell (GtkMenuShell *menu_shell, MenuRef carbon_menu, gboolean toplevel) { GList *children; GList *l; MenuItemIndex carbon_index = 1; carbon_menu_connect (GTK_WIDGET (menu_shell), carbon_menu); children = gtk_container_get_children (GTK_CONTAINER (menu_shell)); UInt16 carbon_item_count = CountMenuItems(carbon_menu); for (l = children; l; l = l->next) { GtkWidget *menu_item = l->data; CarbonMenuItem *carbon_item; if (GTK_IS_TEAROFF_MENU_ITEM (menu_item)) continue; if (toplevel && g_object_get_data (G_OBJECT (menu_item), "gtk-empty-menu-item")) continue; GtkWidget *label = NULL; const gchar *label_text = NULL; label_text = get_menu_label_text (menu_item, &label); if (label_text && strcmp(label_text, "_SKIP_") == 0) { carbon_index++; continue; } else if (!label_text) label_text = ""; MenuItemAttributes attributes = 0; if (GTK_IS_SEPARATOR_MENU_ITEM (menu_item)) attributes |= kMenuItemAttrSeparator; if (!GTK_WIDGET_IS_SENSITIVE (menu_item)) attributes |= kMenuItemAttrDisabled; if (!GTK_WIDGET_VISIBLE (menu_item)) attributes |= kMenuItemAttrHidden; CFStringRef cfstr = CFStringCreateWithCString (NULL, label_text, kCFStringEncodingUTF8); if (carbon_index > carbon_item_count) AppendMenuItemTextWithCFString(carbon_menu, cfstr, attributes, 0, NULL); else if (!toplevel && (carbon_index > carbon_item_count)) InsertMenuItemTextWithCFString (carbon_menu, cfstr, carbon_index, attributes, 0); else SetMenuItemTextWithCFString(carbon_menu, carbon_index, cfstr); CFRelease (cfstr); MenuItemAttributes c_attributes = kMenuItemAttrSectionHeader | kMenuItemAttrAutoDisable; if (!(attributes & kMenuItemAttrDisabled)) c_attributes |= kMenuItemAttrDisabled; if (!(attributes & kMenuItemAttrSeparator)) c_attributes |= kMenuItemAttrSeparator; if (!(attributes & kMenuItemAttrHidden)) c_attributes |= kMenuItemAttrHidden; ChangeMenuItemAttributes(carbon_menu, carbon_index, attributes, c_attributes); SetMenuItemProperty (carbon_menu, carbon_index, GTK_QUARTZ_MENU_CREATOR, GTK_QUARTZ_ITEM_WIDGET, sizeof (menu_item), &menu_item); carbon_item = carbon_menu_item_connect (menu_item, label, carbon_menu, carbon_index); if (GTK_IS_CHECK_MENU_ITEM (menu_item)) carbon_menu_item_update_active (carbon_item, menu_item); carbon_menu_item_update_accel_closure (carbon_item, menu_item); if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (menu_item))) carbon_menu_item_update_submenu (carbon_item, menu_item); carbon_index++; } while (carbon_index <= carbon_item_count) { DeleteMenuItem (carbon_menu, carbon_index); carbon_index++; } g_list_free (children); }
int main(int argc, char *argv[]) { WindowRef window; HIViewRef content; HIViewRef combo; HIViewRef group; HIViewRef check; HIViewRef text; HIViewRef slider; HIViewRef quit; MenuRef menu; HIRect rect; // Window bounds Rect bounds = {0, 0, 436, 590}; // Create window CreateNewWindow(kDocumentWindowClass, kWindowStandardFloatingAttributes | kWindowStandardHandlerAttribute | kWindowInWindowMenuAttribute | kWindowCompositingAttribute, &bounds, &window); // Set the title SetWindowTitleWithCFString(window, CFSTR("Accordion")); // Create an application menu CreateNewMenu(0, 0, &menu); // Set menu title SetMenuTitleWithCFString(menu, CFStringCreateWithPascalString(kCFAllocatorDefault, "\p\024", kCFStringEncodingMacRoman)); // Create an about item InsertMenuItemTextWithCFString(menu, CFSTR("About Accordion"), 0, 0, kHICommandAbout); // Insert the menu InsertMenu(menu, 0); // Create a standard window menu CreateStandardWindowMenu(0, &menu); // Insert the menu InsertMenu(menu, 0); // Show and position the window ShowWindow(window); RepositionWindow(window, NULL, kWindowCascadeOnMainScreen); // Find the window content HIViewFindByID(HIViewGetRoot(window), kHIViewWindowContentID, &content); // Set bounds for group box bounds.bottom = 92; bounds.right = 550; // Create group box CreateGroupBoxControl(window, &bounds, NULL, true, &group); // Place in the window HIViewAddSubview(content, group); HIViewPlaceInSuperviewAt(group, 20, 20); // Bounds of text bounds.bottom = 16; bounds.right = 74; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Instrument:"), NULL, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 16, 18); // Bounds of combo box rect.size.height = 20; rect.size.width = 168; // Create combo box HIComboBoxCreate(&rect, CFSTR(" Accordion"), NULL, NULL, kHIComboBoxStandardAttributes, &combo); // Set visible and set command ID HIViewSetVisible(combo, true); HIViewSetCommandID(combo, kCommandInst); // Add the instruments for (int i = 0; i < Length(instruments); i++) { HIComboBoxAppendTextItem(combo, CFStringCreateWithCString(kCFAllocatorDefault, instruments[i], kCFStringEncodingMacRoman), NULL); // Set the current instrument if (strcmp(instruments[i], " Accordion") == 0) instrument = i; } // Place in the group box HIViewAddSubview(group, combo); HIViewPlaceInSuperviewAt(combo, 102, 16); // Bounds of check box bounds.bottom = 18; bounds.right = 121; // Create check box CreateCheckBoxControl(window, &bounds, CFSTR("Reverse"), false, true, &check); // Set the control ID and the command ID HIViewSetID(check, kHIViewIDReverse); HIViewSetCommandID(check, kCommandReverse); // Place in the group box HIViewAddSubview(group, check); HIViewPlaceInSuperviewAt(check, 286, 17); // Bounds of text bounds.bottom = 16; bounds.right = 32; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Key:"), NULL, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 400, 18); // Bounds of combo box rect.size.width = 90; // Create combo box HIComboBoxCreate(&rect, CFSTR(" A/D/G"), NULL, NULL, kHIComboBoxStandardAttributes, &combo); // Set visible and set command ID HIViewSetVisible(combo, true); HIViewSetID(combo, kHIViewIDKey); HIViewSetCommandID(combo, kCommandKey); // Add keys for (int i = 0; i < Length(keys); i++) { HIComboBoxAppendTextItem(combo, CFStringCreateWithCString(kCFAllocatorDefault, keys[i], kCFStringEncodingMacRoman), NULL); // Set current key if (strcmp(keys[i], " A/D/G") == 0) key = i; } // Place in the group box HIViewAddSubview(group, combo); HIViewPlaceInSuperviewAt(combo, 440, 16); // Bounds of text bounds.bottom = 16; bounds.right = 54; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Volume:"), NULL, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 16, 56); // Bounds of slider bounds.bottom = 16; bounds.right = 168; // Create slider CreateSliderControl(window, &bounds, MAXVOL, 0, MAXVOL, kControlSliderDoesNotPoint, 0, false, NULL, &slider); // Set command ID HIViewSetCommandID(slider, kCommandVolume); // Place in the group box HIViewAddSubview(group, slider); HIViewPlaceInSuperviewAt(slider, 100, 58); // Bounds of check box bounds.bottom = 18; bounds.right = 121; // Create check box CreateCheckBoxControl(window, &bounds, CFSTR("Notes"), false, true, &check); // Set the control ID and the command ID HIViewSetID(check, kHIViewIDNote); HIViewSetCommandID(check, kCommandNote); // Place in the group box HIViewAddSubview(group, check); HIViewPlaceInSuperviewAt(check, 286, 56); // Bounds of push button bounds.bottom = 20; bounds.right = 90; // Create push button CreatePushButtonControl(window, &bounds, CFSTR("Quit"), &quit); // Set command ID HIViewSetCommandID(quit, kHICommandQuit); // Place in the group box HIViewAddSubview(group, quit); HIViewPlaceInSuperviewAt(quit, 440, 54); // Group box bounds bounds.bottom = 48; bounds.right = 550; // Create group box CreateGroupBoxControl(window, &bounds, NULL, true, &group); // Place in the window HIViewAddSubview(content, group); HIViewPlaceInSuperviewAt(group, 20, 132); // Font style ControlFontStyleRec style; style.flags = kControlUseFontMask|kControlUseJustMask; style.font = kControlFontBigSystemFont; style.just = teCenter; // Bounds of text bounds.bottom = 16; bounds.right = 550; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Accordion"), &style, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 0, 8); // Bounds of text bounds.bottom = 16; bounds.right = 550; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Play accordion on your keyboard"), &style, &text); // Place in the group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 0, 24); // Group box bounds bounds.bottom = 196; bounds.right = 550; // Create group box CreateGroupBoxControl(window, &bounds, NULL, true, &group); // Place in the window HIViewAddSubview(content, group); HIViewPlaceInSuperviewAt(group, 20, 200); // Button bounds bounds.bottom = SIZE; bounds.right = SIZE; // Create row of bass buttons for (int i = 0; i < Length(bassdisplay); i++) { int x = 15 + 44 * i; int y = 15; // Create button CreateBevelButtonControl(window, &bounds, NULL, kControlBevelButtonNormalBevel, kControlBehaviorPushbutton, NULL, 0, 0, 0, &bassdisplay[i]); // Place in the group box HIViewAddSubview(group, bassdisplay[i]); HIViewPlaceInSuperviewAt(bassdisplay[i], x, y); } // Create three rows of buttons for (int i = 0; i < Length(display); i++) { for (int j = 0; j < ((i == 1)? Length(display[i]): Length(display[i]) - 1); j++) { int x = (i == 1)? 37 + 44 * j: 59 + 44 * j; int y = 59 + 44 * i; // Create button CreateBevelButtonControl(window, &bounds, NULL, kControlBevelButtonNormalBevel, kControlBehaviorPushbutton, NULL, 0, 0, 0, &display[i][j]); // Place in the group box HIViewAddSubview(group, display[i][j]); HIViewPlaceInSuperviewAt(display[i][j], x, y); } } // Create spacebar button CreateBevelButtonControl(window, &bounds, NULL, kControlBevelButtonNormalBevel, kControlBehaviorPushbutton, NULL, 0, 0, 0, &spacebar); // Place in the group box HIViewAddSubview(group, spacebar); HIViewPlaceInSuperviewAt(spacebar, 16, 147); // Group box bounds, wider than the window to hide rounded corners bounds.bottom = 20; bounds.right = 598; // Create group box for fake status bar CreateGroupBoxControl(window, &bounds, NULL, false, &group); // Place in window at negative offset to hide rounded corners HIViewAddSubview(content, group); HIViewPlaceInSuperviewAt(group, -4, 416); // Text bounds bounds.bottom = 16; bounds.right = 590; // Font style style.flags = kControlUseFontMask|kControlUseJustMask; style.font = kControlFontSmallSystemFont; style.just = teCenter; // Create static text CreateStaticTextControl(window, &bounds, CFSTR("Press the keyboard keys as accordion buttons " "and the space bar as the bellows. 3rd button start."), &style, &text); // Place in group box HIViewAddSubview(group, text); HIViewPlaceInSuperviewAt(text, 0, 2); // Application events type spec EventTypeSpec applicationEvents[] = {{kEventClassApplication, kEventAppFrontSwitched}}; // Install event handler InstallApplicationEventHandler(NewEventHandlerUPP(ApplicationHandler), Length(applicationEvents), applicationEvents, NULL, NULL); // Mouse events type spec EventTypeSpec mouseEvents[] = {{kEventClassMouse, kEventMouseDown}}; // Install event handler on the event dispatcher, so that we can // see mouse events before the default handler gets them InstallEventHandler(GetEventDispatcherTarget(), NewEventHandlerUPP(MouseHandler), Length(mouseEvents), mouseEvents, NULL, NULL); // Window events type spec EventTypeSpec windowEvents[] = {{kEventClassWindow, kEventWindowClose}}; // Install event handler InstallWindowEventHandler(window, NewEventHandlerUPP(WindowHandler), Length(windowEvents), windowEvents, NULL, NULL); // Combo box events type spec EventTypeSpec comboBoxEvents[] = {{kEventClassHIComboBox, kEventComboBoxListItemSelected}}; // Install event handler InstallApplicationEventHandler(NewEventHandlerUPP(ComboBoxHandler), Length(comboBoxEvents), comboBoxEvents, NULL, NULL); // Command events type spec EventTypeSpec commandEvents[] = {{kEventClassCommand, kEventCommandProcess}}; // Install event handler InstallApplicationEventHandler(NewEventHandlerUPP(CommandHandler), Length(commandEvents), commandEvents, NULL, NULL); // Keyboard events type spec EventTypeSpec keyboardEvents[] = {{kEventClassKeyboard, kEventRawKeyDown}, {kEventClassKeyboard, kEventRawKeyUp}, {kEventClassKeyboard, kEventRawKeyModifiersChanged}}; // Install event handler on the event dispatcher InstallEventHandler(GetEventDispatcherTarget(), NewEventHandlerUPP(KeyboardHandler), Length(keyboardEvents), keyboardEvents, NULL, NULL); // Audio Unit graph AUGraph graph; // Audio Unit synthesizer and output node AUNode synthNode; AUNode outNode; // Component description ComponentDescription cd; cd.componentManufacturer = kAudioUnitManufacturer_Apple; cd.componentFlags = 0; cd.componentFlagsMask = 0; do { // New AU graph OSStatus status = NewAUGraph(&graph); if (status != noErr) { DisplayAlert(CFSTR("NewAUGraph"), CFSTR("Can't create a new AUGraph"), status); break; } // Synthesizer cd.componentType = kAudioUnitType_MusicDevice; cd.componentSubType = kAudioUnitSubType_DLSSynth; // New synthesizer node status = AUGraphNewNode(graph, &cd, 0, NULL, &synthNode); if (status != noErr) { DisplayAlert(CFSTR("AUGraphNewNode"), CFSTR("Can't create a new AUGraph node"), status); break; } // Output cd.componentType = kAudioUnitType_Output; cd.componentSubType = kAudioUnitSubType_DefaultOutput; // New output node status = AUGraphNewNode(graph, &cd, 0, NULL, &outNode); if (status != noErr) { DisplayAlert(CFSTR("AUGraphNewNode"), CFSTR("Can't create a new AUGraph node"), status); break; } // Open graph status = AUGraphOpen(graph); if (status != noErr) { DisplayAlert(CFSTR("AUGraphOpen"), CFSTR("Can't open AUGraph"), status); break; } // Connect synthesizer node to output node status = AUGraphConnectNodeInput(graph, synthNode, 0, outNode, 0); if (status != noErr) { DisplayAlert(CFSTR("AUGraphConnectNodeInput"), CFSTR("Can't connect AUGraph input node"), status); break; } // Get a synthesizer unit status = AUGraphGetNodeInfo(graph, synthNode, NULL, 0, NULL, &synthUnit); if (status != noErr) { DisplayAlert(CFSTR("AUGraphGetNodeInfo"), CFSTR("Can't get AUGraph node info"), status); break; } // Initialise status = AUGraphInitialize(graph); if (status != noErr) { DisplayAlert(CFSTR("AUGraphInitialize"), CFSTR("Can't initialize AUGraph"), status); break; } // Start status = AUGraphStart(graph); if (status != noErr) { DisplayAlert(CFSTR("AUGraphStart"), CFSTR("Can't start AUGraph"), status); break; } // Show the graph // CAShow(graph); } while (false); // Change instrument ChangeInstrument(instrument); // Run the application event loop RunApplicationEventLoop(); // Stop the graph AUGraphStop(graph); // Dispose of the graph DisposeAUGraph(graph); // Exit return 0; }
MenuRef IGraphicsCarbon::CreateMenu(IPopupMenu* pMenu) { MenuRef menuRef = 0; ResID menuID = UniqueID ('MENU'); int numItems = pMenu->GetNItems(); if (numItems && CreateNewMenu(menuID, kMenuAttrCondenseSeparators, &menuRef) == noErr) { for (int i = 0; i < numItems; ++i) { IPopupMenuItem* menuItem = pMenu->GetItem(i); if (menuItem->GetIsSeparator()) { AppendMenuItemTextWithCFString(menuRef, CFSTR(""), kMenuItemAttrSeparator, 0, NULL); } else { CFStringRef itemString = CFStringCreateWithCString(NULL, menuItem->GetText(), kCFStringEncodingUTF8); if (pMenu->GetPrefix()) { CFStringRef prefixString = 0; switch (pMenu->GetPrefix()) { case 0: prefixString = CFStringCreateWithFormat(NULL, 0, CFSTR(""),i+1); break; case 1: prefixString = CFStringCreateWithFormat(NULL, 0, CFSTR("%1d: "),i+1); break; case 2: prefixString = CFStringCreateWithFormat(NULL, 0, CFSTR("%02d: "),i+1); break; case 3: prefixString = CFStringCreateWithFormat(NULL, 0, CFSTR("%03d: "),i+1); break; } CFMutableStringRef newItemString = CFStringCreateMutable(0, 0); CFStringAppend (newItemString, prefixString); CFStringAppend (newItemString, itemString); CFRelease (itemString); CFRelease (prefixString); itemString = newItemString; } if (itemString == 0) continue; MenuItemAttributes itemAttribs = kMenuItemAttrIgnoreMeta; if (!menuItem->GetEnabled()) { itemAttribs |= kMenuItemAttrDisabled; } if (menuItem->GetIsTitle()) { itemAttribs |= kMenuItemAttrSectionHeader; } InsertMenuItemTextWithCFString(menuRef, itemString, i, itemAttribs, 0); if (menuItem->GetChecked()) { CheckMenuItem(menuRef, i+1, true); } if (menuItem->GetSubmenu()) { MenuRef submenu = CreateMenu(menuItem->GetSubmenu()); if (submenu) { SetMenuItemHierarchicalMenu(menuRef, i+1, submenu); CFRelease (submenu); } } CFRelease (itemString); } } // if (pMenu->getStyle() & kCheckStyle && !multipleCheck) // CheckMenuItem (menuRef, pMenu->getCurrentIndex (true) + 1, true); SetMenuItemRefCon(menuRef, 0, (int32_t)pMenu); //swell collision #undef InsertMenu InsertMenu(menuRef, kInsertHierarchicalMenu); #define InsertMenu SWELL_InsertMenu } return menuRef; }
void wxMenuBar::MacInstallMenuBar() { if ( s_macInstalledMenuBar == this ) return ; MenuBarHandle menubar = NULL ; #if TARGET_API_MAC_OSX menubar = NewHandleClear( 6 /* sizeof( MenuBarHeader ) */ ) ; #else menubar = NewHandleClear( 12 ) ; (*menubar)[3] = 0x0a ; #endif ::SetMenuBar( menubar ) ; DisposeMenuBar( menubar ) ; MenuHandle appleMenu = NULL ; verify_noerr( CreateNewMenu( kwxMacAppleMenuId , 0 , &appleMenu ) ) ; verify_noerr( SetMenuTitleWithCFString( appleMenu , CFSTR( "\x14" ) ) ); // Add About/Preferences separator only on OS X // KH/RN: Separator is always present on 10.3 but not on 10.2 // However, the change from 10.2 to 10.3 suggests it is preferred #if TARGET_API_MAC_OSX InsertMenuItemTextWithCFString( appleMenu, CFSTR(""), 0, kMenuItemAttrSeparator, 0); #endif InsertMenuItemTextWithCFString( appleMenu, CFSTR("About..."), 0, 0, 0); MacInsertMenu( appleMenu , 0 ) ; // clean-up the help menu before adding new items static MenuHandle mh = NULL ; if ( mh != NULL ) { MenuItemIndex firstUserHelpMenuItem ; if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) == noErr ) { for ( int i = CountMenuItems( mh ) ; i >= firstUserHelpMenuItem ; --i ) DeleteMenuItem( mh , i ) ; } else { mh = NULL ; } } #if TARGET_CARBON if ( UMAGetSystemVersion() >= 0x1000 && wxApp::s_macPreferencesMenuItemId) { wxMenuItem *item = FindItem( wxApp::s_macPreferencesMenuItemId , NULL ) ; if ( item == NULL || !(item->IsEnabled()) ) DisableMenuCommand( NULL , kHICommandPreferences ) ; else EnableMenuCommand( NULL , kHICommandPreferences ) ; } // Unlike preferences which may or may not exist, the Quit item should be always // enabled unless it is added by the application and then disabled, otherwise // a program would be required to add an item with wxID_EXIT in order to get the // Quit menu item to be enabled, which seems a bit burdensome. if ( UMAGetSystemVersion() >= 0x1000 && wxApp::s_macExitMenuItemId) { wxMenuItem *item = FindItem( wxApp::s_macExitMenuItemId , NULL ) ; if ( item != NULL && !(item->IsEnabled()) ) DisableMenuCommand( NULL , kHICommandQuit ) ; else EnableMenuCommand( NULL , kHICommandQuit ) ; } #endif wxMenuList::compatibility_iterator menuIter = m_menus.GetFirst(); for (size_t i = 0; i < m_menus.GetCount(); i++, menuIter = menuIter->GetNext()) { wxMenuItemList::compatibility_iterator node; wxMenuItem *item; wxMenu* menu = menuIter->GetData() , *subMenu = NULL ; if ( m_titles[i] == wxT("?") || m_titles[i] == wxT("&?") || m_titles[i] == wxApp::s_macHelpMenuTitleName ) { for (node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext()) { item = (wxMenuItem *)node->GetData(); subMenu = item->GetSubMenu() ; if (subMenu) { // we don't support hierarchical menus in the help menu yet } else { if ( item->GetId() != wxApp::s_macAboutMenuItemId ) { if ( mh == NULL ) { MenuItemIndex firstUserHelpMenuItem ; if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) != noErr ) { mh = NULL ; break ; } } } if ( item->IsSeparator() ) { if ( mh ) AppendMenuItemTextWithCFString( mh, CFSTR(""), kMenuItemAttrSeparator, 0,NULL); } else { wxAcceleratorEntry* entry = wxAcceleratorEntry::Create( item->GetText() ) ; if ( item->GetId() == wxApp::s_macAboutMenuItemId ) { // this will be taken care of below } else { if ( mh ) { UMAAppendMenuItem(mh, wxStripMenuCodes(item->GetText()) , wxFont::GetDefaultEncoding(), entry); SetMenuItemCommandID( mh , CountMenuItems(mh) , wxIdToMacCommand ( item->GetId() ) ) ; SetMenuItemRefCon( mh , CountMenuItems(mh) , (URefCon) item ) ; } } delete entry ; } } } } else { UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , m_titles[i], m_font.GetEncoding() ) ; menu->MacBeforeDisplay(false) ; ::InsertMenu(MAC_WXHMENU(_wxMenuAt(m_menus, i)->GetHMenu()), 0); } } // take care of the about menu item wherever it is { wxMenu* aboutMenu ; wxMenuItem *aboutMenuItem = FindItem(wxApp::s_macAboutMenuItemId , &aboutMenu) ; if ( aboutMenuItem ) { wxAcceleratorEntry* entry = wxAcceleratorEntry::Create( aboutMenuItem->GetText() ) ; UMASetMenuItemText( GetMenuHandle( kwxMacAppleMenuId ) , 1 , wxStripMenuCodes ( aboutMenuItem->GetText() ) , wxFont::GetDefaultEncoding() ); UMAEnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 , true ); SetMenuItemCommandID( GetMenuHandle( kwxMacAppleMenuId ) , 1 , kHICommandAbout ) ; SetMenuItemRefCon(GetMenuHandle( kwxMacAppleMenuId ) , 1 , (URefCon)aboutMenuItem ) ; UMASetMenuItemShortcut( GetMenuHandle( kwxMacAppleMenuId ) , 1 , entry ) ; } } if ( GetAutoWindowMenu() ) { if ( MacGetWindowMenuHMenu() == NULL ) CreateStandardWindowMenu( 0 , (MenuHandle*) &s_macWindowMenuHandle ) ; InsertMenu( (MenuHandle) MacGetWindowMenuHMenu() , 0 ) ; } ::DrawMenuBar() ; s_macInstalledMenuBar = this; }
// function appends a new item or submenu to the menu // append a new item or submenu to the menu bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) { wxASSERT_MSG( pItem != NULL, wxT("can't append NULL item to the menu") ); if ( pItem->IsSeparator() ) { if ( pos == (size_t)-1 ) AppendMenuItemTextWithCFString( MAC_WXHMENU(m_hMenu), CFSTR(""), kMenuItemAttrSeparator, 0,NULL); else InsertMenuItemTextWithCFString( MAC_WXHMENU(m_hMenu), CFSTR(""), pos, kMenuItemAttrSeparator, 0); } else { wxMenu *pSubMenu = pItem->GetSubMenu() ; if ( pSubMenu != NULL ) { wxASSERT_MSG( pSubMenu->m_hMenu != NULL , wxT("invalid submenu added")); pSubMenu->m_menuParent = this ; if (wxMenuBar::MacGetInstalledMenuBar() == GetMenuBar()) pSubMenu->MacBeforeDisplay( true ) ; if ( pos == (size_t)-1 ) UMAAppendSubMenuItem(MAC_WXHMENU(m_hMenu), wxStripMenuCodes(pItem->GetText()), wxFont::GetDefaultEncoding(), pSubMenu->m_macMenuId); else UMAInsertSubMenuItem(MAC_WXHMENU(m_hMenu), wxStripMenuCodes(pItem->GetText()), wxFont::GetDefaultEncoding(), pos, pSubMenu->m_macMenuId); pItem->UpdateItemBitmap() ; pItem->UpdateItemStatus() ; } else { if ( pos == (size_t)-1 ) { UMAAppendMenuItem(MAC_WXHMENU(m_hMenu), wxT("a") , wxFont::GetDefaultEncoding() ); pos = CountMenuItems(MAC_WXHMENU(m_hMenu)) ; } else { // MacOS counts menu items from 1 and inserts after, therefore having the // same effect as wx 0 based and inserting before, we must correct pos // after however for updates to be correct UMAInsertMenuItem(MAC_WXHMENU(m_hMenu), wxT("a"), wxFont::GetDefaultEncoding(), pos); pos += 1 ; } SetMenuItemCommandID( MAC_WXHMENU(m_hMenu) , pos , wxIdToMacCommand ( pItem->GetId() ) ) ; SetMenuItemRefCon( MAC_WXHMENU(m_hMenu) , pos , (URefCon) pItem ) ; pItem->UpdateItemText() ; pItem->UpdateItemBitmap() ; pItem->UpdateItemStatus() ; if ( pItem->GetId() == idMenuTitle ) UMAEnableMenuItem(MAC_WXHMENU(m_hMenu) , pos , false ) ; } } // if we're already attached to the menubar, we must update it if ( IsAttached() && GetMenuBar()->IsAttached() ) GetMenuBar()->Refresh(); return true ; }