Beispiel #1
0
void tool_wind_fill_group_combo(void)
{
	int					n,group_idx;
	char				str[256];
	CFStringRef			cf_str;
	HMHelpContentRec	tag;
	
		// old settings
		
	group_idx=GetControl32BitValue(group_combo);
	
		// delete old control and menu
		
	DisposeControl(group_combo);
	
	DeleteMenu(160);
	DisposeMenu(group_menu);
	
		// recreate the menu
		
	CreateNewMenu(group_combo_menu_id,0,&group_menu);
	
	cf_str=CFStringCreateWithCString(kCFAllocatorDefault,"No Group",kCFStringEncodingMacRoman);
	AppendMenuItemTextWithCFString(group_menu,cf_str,0,FOUR_CHAR_CODE('gp01'),NULL);
	CFRelease(cf_str);
	
	AppendMenuItemTextWithCFString(group_menu,NULL,kMenuItemAttrSeparator,0,NULL);
	
	for (n=0;n<map.ngroup;n++) {
		sprintf(str,"%s (%d)",map.groups[n].name,group_count(n));
		cf_str=CFStringCreateWithCString(kCFAllocatorDefault,str,kCFStringEncodingMacRoman);
		AppendMenuItemTextWithCFString(group_menu,cf_str,0,FOUR_CHAR_CODE('gp03'),NULL);
		CFRelease(cf_str);
	}
	
	InsertMenu(group_menu,kInsertHierarchicalMenu);
	
		// recreate the contorl
		
	CreatePopupButtonControl(toolwind,&group_box,NULL,group_combo_menu_id,FALSE,0,0,0,&group_combo);
	Draw1Control(group_combo);
	
		// build the help
	
	tag.version=kMacHelpVersion;
	tag.tagSide=kHMDefaultSide;
	SetRect(&tag.absHotRect,0,0,0,0);
	tag.content[kHMMinimumContentIndex].contentType=kHMCFStringContent;
	tag.content[kHMMinimumContentIndex].u.tagCFString=CFStringCreateWithCString(NULL,"Segment Groups",kCFStringEncodingMacRoman);
	tag.content[kHMMaximumContentIndex].contentType=kHMNoContent;
		
	HMSetControlHelpContent(group_combo,&tag);
	
		// reset the control
		
	SetControl32BitValue(group_combo,group_idx);
}
void PreferencesDialog::initDialog()
{
	ControlHandle popupButtonControl;
	ControlID popupButtonControlID = {kAppSignature, 130};
	MenuRef menu;
	
	GetControlByID(preferencesWindow, &popupButtonControlID, &popupButtonControl);
	GetControlData(popupButtonControl, kControlEntireControl, kControlPopupButtonMenuRefTag, sizeof(menu), &menu, NULL);

	unsigned int nPorts = midiin ? midiin->getPortCount() : 0;

	if (nPorts)
	{
		UInt32 numItems = CountMenuItems(menu);
		DeleteMenuItems(menu, 1, numItems); 
		
		// Check inputs.
		std::string portName;
		unsigned int nSelectedDevice = 0;
		for (unsigned int i = 0; i < nPorts; i++ ) 
		{
			try 
			{
				portName = midiin->getPortName(i);
			}
			catch (RtMidiError &error) 
			{
				error.printMessage();
			}
			
			if (strcmp(portName.c_str(), m_dataBase->restore(KEY_MIDIDEVICE)->getStringValue()) == 0)
				nSelectedDevice = i;
			
			CFStringRef CFStrPortName = CFStringCreateWithCString(NULL, portName.c_str(), kCFStringEncodingASCII);
			AppendMenuItemTextWithCFString(menu, CFStrPortName, 0, kMIDIDeviceBaseCommand + i, 0);
			CFRelease(CFStrPortName);
			
		}

		/*AppendMenuItemTextWithCFString(menu, CFSTR("Temp1"), 0, kMIDIDeviceBaseCommand + 1, 0);
		AppendMenuItemTextWithCFString(menu, CFSTR("Temp2"), 0, kMIDIDeviceBaseCommand + 2, 0);
		nPorts+=2;*/
		
		SetControlMaximum(popupButtonControl, nPorts);
		
		SetControlValue(popupButtonControl, nSelectedDevice + 1);
		
		storeMidiDeviceName(nSelectedDevice);

		EnableControl(popupButtonControl);			
	}
	else
	{
		DisableControl(popupButtonControl);	
	}
	
	updateControls();

	updateSliderVelocityAmplify();	
}
Beispiel #3
0
void UMAAppendSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuRef submenu )
{
    AppendMenuItemTextWithCFString( menu,
                                CFSTR("A"), 0, 0,NULL);
    UMASetMenuItemText( menu, (SInt16) ::CountMenuItems(menu), title , encoding );
    SetMenuItemHierarchicalMenu( menu , CountMenuItems( menu ) , submenu ) ;
    SetMenuTitleWithCFString(submenu , wxCFStringRef(title , encoding) );
}
Beispiel #4
0
void UMAAppendMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , wxAcceleratorEntry *entry )
{
    AppendMenuItemTextWithCFString( menu,
                                CFSTR("A"), 0, 0,NULL);
    // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
    ChangeMenuItemAttributes( menu , ::CountMenuItems(menu), kMenuItemAttrIgnoreMeta , 0 ) ;
    UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title , encoding );
    UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), entry ) ;
}
void
AddServiceToPopupMenu(char * serviceType, UInt16 serviceLen, UInt16 * serviceMenuItem)
{
    ControlID 		controlID = { kNSLSample, kServicesTypePopup };
    ControlRef		control;
    CFStringRef		tempService = NULL;
    CFStringRef    	menuText = NULL;
    char		tempServiceString[kMaxTypeNameLength];
    CFComparisonResult	result = -1;
    MenuRef		menu;
    OSStatus		err = noErr;
    short		itemCount, i;
    
    if (serviceType)
    {
        err = GetControlByID(gMainWindow, &controlID, &control);
        if (err == noErr)
        {
            strncpy(tempServiceString, serviceType, serviceLen);
            tempServiceString[serviceLen] = '\0';
            
            for (i = 0; i < serviceLen; i++) tempServiceString[i] = toupper(tempServiceString[i]);
            
            tempService = CFStringCreateWithCString(NULL, tempServiceString, CFStringGetSystemEncoding());
            if (tempService)
            {
                menu = GetControlPopupMenuHandle(control);
                itemCount = CountMenuItems(menu);
                
                for (i = 1; i <= itemCount; i ++)
                {
                    CopyMenuItemTextAsCFString(menu, i , &menuText);
                    if (menuText)
                    {                        
                        result = CFStringCompare(menuText, tempService, kCFCompareCaseInsensitive);
                        if (result == kCFCompareEqualTo)
                        {
                            if (serviceMenuItem) *serviceMenuItem = i;
                            break;
                        }
                    }
                }
                
                if (result != kCFCompareEqualTo)
                {
                    err = AppendMenuItemTextWithCFString(menu, tempService, 0, 0, serviceMenuItem);
                    if (err == noErr)
                    {
                        SetControlMaximum(control, itemCount + 1);
                        if (serviceMenuItem) *serviceMenuItem = itemCount + 1;
                    }
                    CFRelease(tempService);
                }
            }
        }
    }
}
Beispiel #6
0
void
OPL_LoginDialog::fill_dir_menu(char *path)
{
    char *tmp_dir, *prov, *dir;
    MenuRef items_m;
    int i = -1;
    ControlRef f_select;

    getControl(kLoginDIR, &f_select);

    if (!path || !(prov = strdup (path)))
        return;

    if (prov[strlen(prov) - 1] == '/' && strlen(prov) > 1)
        prov[strlen(prov) - 1] = 0;

    items_m = GetControlPopupMenuHandle (f_select);
    DeleteMenuItems (items_m, 1, CountMenuItems (items_m));

    /* Add the root directory */
    AppendMenuItemTextWithCFString(items_m, CFSTR("/"), 0, 0, NULL);

    for (tmp_dir = prov, dir = NULL; tmp_dir;
            tmp_dir = strchr (tmp_dir + 1, '/'))
    {
        if (strchr (tmp_dir + 1, '/'))
        {
            dir = strchr (tmp_dir + 1, '/');
            *dir = 0;
        }

        AppendMenuItemTextWithCFString(items_m, OPL_char_to_CFString(prov), 0, 0, NULL);

        if (dir)
            *dir = '/';
    }
    i = CountMenuItems (items_m);
    SetControlMaximum (f_select, i);
    SetControlValue (f_select, i);
    if (cur_dir)
        free(cur_dir);
    cur_dir = prov;
}
Beispiel #7
0
static void fill_dir_menu(TDSNCHOOSER *dsnchoose_t, char *path)
{
  char *curr_dir, *prov, *dir;
  MenuRef items_m;
  int i = -1;
  CFStringRef str;
  ControlRef f_select = dsnchoose_t->fdir;

  if (!path || !(prov = strdup (path)))
    return;

  if (prov[strlen(prov) - 1] == '/' && strlen(prov) > 1)
    prov[strlen(prov) - 1] = 0;

  items_m = GetControlPopupMenuHandle (f_select);
  DeleteMenuItems (items_m, 1, CountMenuItems (items_m));

  /* Add the root directory */
  AppendMenuItemTextWithCFString(items_m, CFSTR("/"), 0, 0, NULL);

  if (strlen(prov) > 1)
    for (curr_dir = prov, dir = NULL; curr_dir;
          curr_dir = strchr (curr_dir + 1, '/'))
      {
        if (strchr (curr_dir + 1, '/'))
	  {
	    dir = strchr (curr_dir + 1, '/');
	    *dir = 0;
	  }

        str = CFStringCreateWithCString(NULL, prov, kCFStringEncodingUTF8);
        AppendMenuItemTextWithCFString(items_m, str, 0, 0, NULL);

        if (dir)
	  *dir = '/';
      }

  i = CountMenuItems (items_m);
  SetControlMaximum (f_select, i);
  SetControlValue (f_select, i);
  strncpy(dsnchoose_t->curr_dir, prov, sizeof(dsnchoose_t->curr_dir));
}
Beispiel #8
0
int Sys_AppendMenuSeparator(int menuId) {
    menu_t *menu;

    menu = &menus[menuId];
    if (menu->cbIndex >= MAX_MENU_ITEM_CALLBACKS)
        return -1;

    ++menu->cbIndex; /* separators have their own ids so they must be skipped */
    AppendMenuItemTextWithCFString(menu->mr, CFSTR(""), kMenuItemAttrSeparator, 0, 0);
    return 0;
}
Beispiel #9
0
void
MyContextualMenuCallback( MenuRef iContextualMenu, TXNObject object, void *inUserData)
{
	OSStatus status = noErr;
	MenuItemAttributes inAttributes = 0;
	MenuCommand commandID = kHICommandAbout; // we'll insert a menu that shows the "About box"
	MenuItemIndex appendIndex = 0;
	
	status = AppendMenuItemTextWithCFString( iContextualMenu, CFSTR("About MLTEShowcase"),
												inAttributes, /*MenuItemAttributes*/
												commandID, /*MenuCommand*/
												&appendIndex );
}
//----------------------------------------------------------------------------//
int MacCEGuiRendererSelector::populateRendererMenu()
{
	// get the menu from the popup
	MenuRef menu;
	GetControlData(d_rendererPopup, 0, kControlPopupButtonMenuRefTag,
                   sizeof(menu), &menu, 0);

    int idx = 0;
    // Put items in the combobox for enabled renderers.
    if (d_rendererAvailability[OpenGLGuiRendererType])
    {
        d_rendererTypes[idx++] = OpenGLGuiRendererType;
        AppendMenuItemTextWithCFString(menu, CFSTR("OpenGL Renderer"),
                                       0, 0, 0);
    }
    if (d_rendererAvailability[IrrlichtGuiRendererType])
    {
        d_rendererTypes[idx++] = IrrlichtGuiRendererType;
        AppendMenuItemTextWithCFString(menu, CFSTR("Irrlicht Renderer"),
                                       0, 0, 0);
    }
    if (d_rendererAvailability[OgreGuiRendererType])
    {
        d_rendererTypes[idx++] = OgreGuiRendererType;
        AppendMenuItemTextWithCFString(menu, CFSTR("Ogre Renderer"),
                                       0, 0, 0);
    }
    if (d_rendererAvailability[DirectFBGuiRendererType])
    {
        d_rendererTypes[idx++] = DirectFBGuiRendererType;
        AppendMenuItemTextWithCFString(menu, CFSTR("DirectFB Renderer"),
                                       0, 0, 0);
    }

	HIViewSetMaximum(d_rendererPopup, CountMenuItems(menu));
    HIViewSetValue(d_rendererPopup, 1);
    return idx;
}
Beispiel #11
0
int Sys_AppendMenuItem(int menuId, const char *title, void (*callback)(void)) {
    /* TODO: error handling */
    menu_t *menu;
    CFStringRef cfs;

    cfs = CFStringCreateWithCString(0, title, CFStringGetSystemEncoding());

    menu = &menus[menuId];
    if (menu->cbIndex >= MAX_MENU_ITEM_CALLBACKS)
        return -1;

    AppendMenuItemTextWithCFString(menu->mr, cfs, 0, 0, 0);
    menu->callbacks[menu->cbIndex++] = callback;
    return 0;
}
Beispiel #12
0
// add some interesting sample items
static void
AddSampleItems( MenuRef menu )
{
	MenuItemIndex	item;
	
	AppendMenuItemTextWithCFString( menu, CFSTR("Checkmark"), 0, 0, &item );
	CheckMenuItem( menu, item, true );
	AppendMenuItemTextWithCFString( menu, CFSTR("Dash"), 0, 0, &item );
	SetItemMark( menu, item, '-' );
	AppendMenuItemTextWithCFString( menu, CFSTR("Diamond"), 0, 0, &item );
	SetItemMark( menu, item, kDiamondCharCode );
	AppendMenuItemTextWithCFString( menu, CFSTR("Bullet"), 0, 0, &item );
	SetItemMark( menu, item, kBulletCharCode );
	AppendMenuItemTextWithCFString( menu, NULL, kMenuItemAttrSeparator, 0, NULL );
	AppendMenuItemTextWithCFString( menu, CFSTR("Section Header"), kMenuItemAttrSectionHeader, 0, NULL );
	AppendMenuItemTextWithCFString( menu, CFSTR("Indented item 1"), 0, 0, &item );
	SetMenuItemIndent( menu, item, 1 );
	AppendMenuItemTextWithCFString( menu, CFSTR("Indented item 2"), 0, 0, &item );
	SetMenuItemIndent( menu, item, 1 );
}
Beispiel #13
0
void	AUControlGroup::CreatePopupMenu (AUCarbonViewBase *			auView,
										const CAAUParameter &		auvp,
										const Rect &				area,
										const ControlFontStyleRec &	inFontStyle,
										const bool					inSizeToFit)
{
#if !__LP64__
	ControlRef thePopUp;

	verify_noerr(CreatePopupButtonControl (auView->GetCarbonWindow(), &area, NULL,
												-12345,	// DON'T GET MENU FROM RESOURCE mMenuID
												FALSE,	// variableWidth,
												0,		// titleWidth,
												0,		// titleJustification,
												0,		// titleStyle,
												&thePopUp));

	ControlSize small = kControlSizeSmall;
	SetControlData(thePopUp, kControlEntireControl, kControlSizeTag, sizeof(ControlSize), &small);

	MenuRef menuRef;
	verify_noerr(CreateNewMenu( 1, 0, &menuRef));

	for (int i = 0; i < auvp.GetNumIndexedParams(); ++i) {
		verify_noerr(AppendMenuItemTextWithCFString (menuRef, auvp.GetParamName(i), kMenuItemAttrIgnoreMeta, 0, 0));
	}

	verify_noerr(SetControlData(thePopUp, 0, kControlPopupButtonMenuRefTag, sizeof(menuRef), &menuRef));
	SetControl32BitMaximum(thePopUp, auvp.GetNumIndexedParams());

	verify_noerr (SetControlFontStyle (thePopUp, &inFontStyle));

	if (inSizeToFit) {
		AUCarbonViewControl::SizeControlToFit(thePopUp);
	}

	auView->AddCarbonControl(AUCarbonViewControl::kTypeDiscrete, auvp, thePopUp);
#endif
}
Beispiel #14
0
// create the Shell menu in Terminal
static void
AddShellItems( MenuRef menu )
{
	MenuItemIndex	item;
	
	AppendMenuItemTextWithCFString( menu, CFSTR("New"), 0, 0, &item );
	SetItemCmd( menu, item, 'N' );
	AppendMenuItemTextWithCFString( menu, CFSTR("Open..."), 0, 0, &item );
	SetItemCmd( menu, item, 'O' );
	AppendMenuItemTextWithCFString( menu, CFSTR("Library"), kMenuItemAttrDisabled, 0, &item );
	SetMenuItemHierarchicalID( menu, item, 201 );
	AppendMenuItemTextWithCFString( menu, NULL, kMenuItemAttrSeparator, 0, NULL );
	AppendMenuItemTextWithCFString( menu, CFSTR("Save"), 0, 0, &item );
	SetItemCmd( menu, item, 'S' );
	AppendMenuItemTextWithCFString( menu, CFSTR("Save As..."), 0, 0, &item );
	SetItemCmd( menu, item, 'S' );
	SetMenuItemModifiers( menu, item, kMenuShiftModifier );
	AppendMenuItemTextWithCFString( menu, CFSTR("Save Text As..."), 0, 0, &item );
	SetItemCmd( menu, item, 'S' );
	SetMenuItemModifiers( menu, item, kMenuOptionModifier );
	AppendMenuItemTextWithCFString( menu, CFSTR("Save Selected Text As..."), 0, 0, &item );
	SetItemCmd( menu, item, 'S' );
	SetMenuItemModifiers( menu, item, kMenuShiftModifier | kMenuOptionModifier );
	AppendMenuItemTextWithCFString( menu, NULL, kMenuItemAttrSeparator, 0, NULL );
	AppendMenuItemTextWithCFString( menu, CFSTR("Run Command..."), 0, 0, &item );
	SetItemCmd( menu, item, 'N' );
	SetMenuItemModifiers( menu, item, kMenuShiftModifier );
	AppendMenuItemTextWithCFString( menu, CFSTR("Set Title..."), 0, 0, &item );
	SetItemCmd( menu, item, 'T' );
	SetMenuItemModifiers( menu, item, kMenuShiftModifier );
	AppendMenuItemTextWithCFString( menu, CFSTR("Inspector..."), 0, 0, &item );
	SetItemCmd( menu, item, 'I' );
	AppendMenuItemTextWithCFString( menu, NULL, kMenuItemAttrSeparator, 0, NULL );
	AppendMenuItemTextWithCFString( menu, CFSTR("Page Setup..."), 0, 0, &item );
	SetItemCmd( menu, item, 'P' );
	SetMenuItemModifiers( menu, item, kMenuShiftModifier );
	AppendMenuItemTextWithCFString( menu, CFSTR("Print..."), 0, 0, &item );
	SetItemCmd( menu, item, 'P' );
}
Beispiel #15
0
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);
}
Beispiel #16
0
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;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	AURenderQualityPopup::AURenderQualityPopup
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AURenderQualityPopup::AURenderQualityPopup (AUCarbonViewBase *inBase, 
				Point 					inLocation, 
				int 					inRightEdge, 
				ControlFontStyleRec & 	inFontStyle)
	: AUPropertyControl (inBase)
{
	Rect r;
	r.top = inLocation.v;		r.bottom = r.top + 17;
	r.left = inLocation.h;		r.right = r.left + inRightEdge;
	
	ControlFontStyleRec fontStyle = inFontStyle;
	inFontStyle.just = teFlushRight;

	ControlRef			ref;
		
	CFBundleRef mainBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.audio.units.Components"));
	if (mainBundle != NULL) {
		CFMutableStringRef renderTitle = CFStringCreateMutable(NULL, 0);
		CFStringAppend(renderTitle, CFCopyLocalizedStringFromTableInBundle(
			CFSTR("Render Quality"), CFSTR("CustomUI"), mainBundle,
			CFSTR("The Render Quality Popup menu title")));
		CFStringAppend(renderTitle, CFSTR(":"));
	
		OSErr theErr =  CreateStaticTextControl (GetCarbonWindow(), &r, renderTitle, &inFontStyle, &ref);
		if (theErr == noErr)
			EmbedControl(ref);
		
		r.left = r.right + 8;
		r.right = r.left + 100;

		short bundleRef = CFBundleOpenBundleResourceMap (mainBundle);
		
		theErr = CreatePopupButtonControl (mView->GetCarbonWindow(), &r, NULL,
			/*kQualityMenuID*/ -12345, false, -1, 0, 0, &mControl);	
			
		MenuRef menuRef;
		verify_noerr(CreateNewMenu(kQualityMenuID, 0, &menuRef));
		
		verify_noerr(AppendMenuItemTextWithCFString (menuRef, CFCopyLocalizedStringFromTableInBundle(CFSTR("Maximum"), CFSTR("CustomUI"), mainBundle, CFSTR("")), 0, kChangeRenderQualityCmd, 0));
		verify_noerr(AppendMenuItemTextWithCFString (menuRef, CFCopyLocalizedStringFromTableInBundle(CFSTR("High"), CFSTR("CustomUI"), mainBundle, CFSTR("")), 0, kChangeRenderQualityCmd, 0));
		verify_noerr(AppendMenuItemTextWithCFString (menuRef, CFCopyLocalizedStringFromTableInBundle(CFSTR("Medium"), CFSTR("CustomUI"), mainBundle, CFSTR("")), 0, kChangeRenderQualityCmd, 0));
		verify_noerr(AppendMenuItemTextWithCFString (menuRef, CFCopyLocalizedStringFromTableInBundle(CFSTR("Low"), CFSTR("CustomUI"), mainBundle, CFSTR("")), 0, kChangeRenderQualityCmd, 0));
		verify_noerr(AppendMenuItemTextWithCFString (menuRef, CFCopyLocalizedStringFromTableInBundle(CFSTR("Minimum"), CFSTR("CustomUI"), mainBundle, CFSTR("")), 0, kChangeRenderQualityCmd, 0));
																
		verify_noerr(SetControlData(mControl, 0, kControlPopupButtonMenuRefTag, sizeof(menuRef), &menuRef));
					
		verify_noerr(SetControlFontStyle (mControl, &inFontStyle));
			
		SetControl32BitMaximum(mControl, 5);
		UInt32 renderQuality;
		UInt32 size = sizeof(UInt32);
		AudioUnitGetProperty (mView->GetEditAudioUnit(), 
							kAudioUnitProperty_RenderQuality,
							kAudioUnitScope_Global, 
							0, 
							&renderQuality, 
							&size);
							
		HandlePropertyChange(renderQuality);

		EmbedControl(mControl);
		theErr = AudioUnitAddPropertyListener(mView->GetEditAudioUnit(), kAudioUnitProperty_RenderQuality, RenderQualityListener, this);
		CFBundleCloseBundleResourceMap (mainBundle, bundleRef);
		CFRelease(renderTitle);
	}
	RegisterEvents();
}
Beispiel #18
0
static void
winproc(void *a)
{
	MenuItemIndex index;

	winRect.left = 30;
	winRect.top = 60;
	winRect.bottom = (devRect.size.height * 0.75) + winRect.top;
	winRect.right = (devRect.size.width * 0.75) + winRect.left;

	ClearMenuBar();
	InitCursor();

	CreateStandardWindowMenu(0, &windMenu);
	InsertMenu(windMenu, 0);

	CreateNewMenu(1004, 0, &viewMenu);
	SetMenuTitleWithCFString(viewMenu, CFSTR("View"));
	AppendMenuItemTextWithCFString(viewMenu, CFSTR("Toggle Full Screen"), 0,
								kFullScreenCmd, &index);
	SetMenuItemCommandKey(viewMenu, index, FALSE, 'F');
	InsertMenu(viewMenu, GetMenuID(windMenu));

	DrawMenuBar();
	uint32_t windowAttrs = 0
				| kWindowCloseBoxAttribute
				| kWindowCollapseBoxAttribute
				| kWindowResizableAttribute
				| kWindowStandardHandlerAttribute
				| kWindowFullZoomAttribute
		;

	CreateNewWindow(kDocumentWindowClass, windowAttrs, &winRect, &theWindow);
	SetWindowTitleWithCFString(theWindow, CFSTR("Acme SAC"));

	if(PasteboardCreate(kPasteboardClipboard, &appleclip) != noErr)
		sysfatal("pasteboard create failed");

	const EventTypeSpec app_events[] = {
		{ kEventClassApplication, kEventAppQuit }
	};
	const EventTypeSpec commands[] = {
		{ kEventClassWindow, kEventWindowClosed },
		{ kEventClassWindow, kEventWindowBoundsChanged },
		{ kEventClassCommand, kEventCommandProcess }
	};
	const EventTypeSpec events[] = {
		{ kEventClassTextInput, kEventTextInputUpdateActiveInputArea },
		{ kEventClassTextInput, kEventTextInputUnicodeForKeyEvent },
		{ kEventClassTextInput, kEventTextInputOffsetToPos },
		{ kEventClassTextInput, kEventTextInputPosToOffset },
		{ kEventClassTextInput, kEventTextInputShowHideBottomWindow },
		{ kEventClassTextInput, kEventTextInputGetSelectedText },
		{ kEventClassTextInput, kEventTextInputUnicodeText },
		{ kEventClassTextInput, kEventTextInputFilterText },
		{ kEventClassKeyboard, kEventRawKeyDown },
		{ kEventClassKeyboard, kEventRawKeyModifiersChanged },
		{ kEventClassKeyboard, kEventRawKeyRepeat },
		{ kEventClassMouse, kEventMouseDown },
		{ kEventClassMouse, kEventMouseUp },
		{ kEventClassMouse, kEventMouseMoved },
		{ kEventClassMouse, kEventMouseDragged },
		{ kEventClassMouse, kEventMouseWheelMoved },
	};

	InstallApplicationEventHandler (
								NewEventHandlerUPP (ApplicationQuitEventHandler),
								GetEventTypeCount(app_events),
								app_events,
								NULL,
								NULL);

	InstallApplicationEventHandler (
								NewEventHandlerUPP (MainWindowEventHandler),
								GetEventTypeCount(events),
								events,
								NULL,
								NULL);
						
	InstallWindowEventHandler (
								theWindow,
								NewEventHandlerUPP (MainWindowCommandHandler),
								GetEventTypeCount(commands),
								commands,
								theWindow,
								NULL);

	ShowWindow(theWindow);
	ShowMenuBar();
	window_resized();
	Rectangle rect =  { { 0, 0 }, { bounds.size.width, bounds.size.height } };		
	wmtrack(0, rect.max.x, rect.max.y, 0);
	SelectWindow(theWindow);
	// Run the event loop
	readybit = 1;
	Wakeup(&rend);
	RunApplicationEventLoop();
}
Beispiel #19
0
AUVPresets::AUVPresets (AUCarbonViewBase* 		inParentView, 
						CFArrayRef& 			inPresets,
						Point 					inLocation, 
						int 					nameWidth, 
						int 					controlWidth, 
						ControlFontStyleRec & 	inFontStyle)
	: AUPropertyControl (inParentView),
	  mPresets (inPresets),
	  mView (inParentView)
{
#if !__LP64__
	Rect r;
	
	// ok we now have an array of factory presets
	// get their strings and display them

	r.top = inLocation.v;		r.bottom = r.top;
	r.left = inLocation.h;		r.right = r.left;
	
    // localize as necessary
    if (!sAUVPresetLocalized) {
        CFBundleRef mainBundle = CFBundleGetBundleWithIdentifier(kLocalizedStringBundle_AUView);
        if (mainBundle) {
            kStringFactoryPreset =	CFCopyLocalizedStringFromTableInBundle(
                                        kAUViewLocalizedStringKey_FactoryPreset, kLocalizedStringTable_AUView,
                                        mainBundle, CFSTR("FactoryPreset title string"));
            sAUVPresetLocalized = true;
        }
    }
    
    // create localized title string
    CFMutableStringRef factoryPresetsTitle = CFStringCreateMutable(NULL, 0);
    CFStringAppend(factoryPresetsTitle, kStringFactoryPreset);
    CFStringAppend(factoryPresetsTitle, kAUViewUnlocalizedString_TitleSeparator);
    
	ControlRef theControl;
    verify_noerr(CreateStaticTextControl(mView->GetCarbonWindow(), &r, factoryPresetsTitle, &inFontStyle, &theControl));
	SInt16 width = 0;
	AUCarbonViewControl::SizeControlToFit(theControl, &width, &mHeight);
    CFRelease(factoryPresetsTitle);
	EmbedControl(theControl);
	
	r.top -= 2;
	r.left += width + 10;
	r.right = r.left;
	r.bottom = r.top;
	
	verify_noerr(CreatePopupButtonControl (	mView->GetCarbonWindow(), &r, NULL, 
											-12345,	// DON'T GET MENU FROM RESOURCE mMenuID,!!!
											FALSE,	// variableWidth, 
											0,		// titleWidth, 
											0,		// titleJustification, 
											0,		// titleStyle, 
											&mControl));
	
	MenuRef menuRef;
	verify_noerr(CreateNewMenu(1, 0, &menuRef));
	
	int numPresets = CFArrayGetCount(mPresets);
	
	for (int i = 0; i < numPresets; ++i)
	{
		AUPreset* preset = (AUPreset*) CFArrayGetValueAtIndex (mPresets, i);
		verify_noerr(AppendMenuItemTextWithCFString (menuRef, preset->presetName, 0, 0, 0));
	}
	
	verify_noerr(SetControlData(mControl, 0, kControlPopupButtonMenuRefTag, sizeof(menuRef), &menuRef));
	verify_noerr (SetControlFontStyle (mControl, &inFontStyle));
	
	SetControl32BitMaximum (mControl, numPresets);
	
	// size popup
	SInt16 height = 0;
	
	AUCarbonViewControl::SizeControlToFit(mControl, &width, &height);
	
	if (height > mHeight) mHeight = height;
	if (mHeight < 0) mHeight = 0;
	
	// find which menu item is the Default preset
	UInt32 propertySize = sizeof(AUPreset);
	AUPreset defaultPreset;
	OSStatus result = AudioUnitGetProperty (mView->GetEditAudioUnit(), 
									kAudioUnitProperty_PresentPreset,
									kAudioUnitScope_Global, 
									0, 
									&defaultPreset, 
									&propertySize);
	
	mPropertyID = kAudioUnitProperty_PresentPreset;
#endif	
#ifndef __LP64__
	if (result != noErr) {	// if the PresentPreset property is not implemented, fall back to the CurrentPreset property
		OSStatus result = AudioUnitGetProperty (mView->GetEditAudioUnit(), 
									kAudioUnitProperty_CurrentPreset,
									kAudioUnitScope_Global, 
									0, 
									&defaultPreset, 
									&propertySize);
		mPropertyID = kAudioUnitProperty_CurrentPreset;
		if (result == noErr)
			CFRetain (defaultPreset.presetName);
	} 
#endif
#if !__LP64__		
	EmbedControl (mControl);
	
	HandlePropertyChange(defaultPreset);
	
	RegisterEvents();
#endif
}
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;
}
Beispiel #21
0
// 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 ;
}
Beispiel #22
0
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;
}
Beispiel #23
0
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;
}