void GetServiceTypeToLookup(CFMutableStringRef * serviceString, UInt16 * serviceMenuItem) { ControlID controlID = { kNSLSample, kServicesTypePopup }; ControlRef control; CFStringRef outString; MenuRef menu; SInt16 value; OSStatus err; err = GetControlByID(gMainWindow, &controlID, &control); if (err == noErr) { value = GetControlValue(control); if (serviceString) { menu = GetControlPopupMenuHandle(control); if (menu) { CopyMenuItemTextAsCFString(menu, value, &outString); if (serviceString) { *serviceString = CFStringCreateMutableCopy(NULL, CFStringGetLength(outString), outString); CFStringLowercase(*serviceString, NULL); } if (outString) CFRelease(outString); } } if (serviceMenuItem) *serviceMenuItem = value; } }
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); } } } } }
void wxFontEnumeratorHelper::DoEnumerate() { MenuHandle menu ; short lines ; menu = NewMenu( 32000 , "\pFont" ) ; AppendResMenu( menu , 'FONT' ) ; lines = CountMenuItems( menu ) ; for ( int i = 1 ; i < lines+1 ; i ++ ) { wxString c_name ; #if TARGET_API_MAC_CARBON CFStringRef menutext ; c_name = wxEmptyString ; if ( CopyMenuItemTextAsCFString (menu, i, &menutext) == noErr ) { c_name = wxMacCFStringHolder(menutext).AsString(wxLocale::GetSystemEncoding()); } #else Str255 p_name; GetMenuItemText( menu , i , p_name ) ; c_name = wxMacMakeStringFromPascal( p_name ); #endif /* if ( m_fixedOnly ) { // check that it's a fixed pitch font (there is *no* error here, the // flag name is misleading!) if ( tm->tmPitchAndFamily & TMPF_FIXED_PITCH ) { // not a fixed pitch font return TRUE; } } if ( m_charset != -1 ) { // check that we have the right encoding if ( lf->lfCharSet != m_charset ) { return TRUE; } } */ m_fontEnum->OnFacename( c_name ) ; } DisposeMenu( menu ) ; }
bool PopupMenu::handleSelect(U32 command, const char *text /* = NULL */) { // [tom, 8/20/2006] Pass off to a sub menu if it's for them for(S32 i = 0;i < mSubmenus->size();i++) { PopupMenu *subM = dynamic_cast<PopupMenu *>((*mSubmenus)[i]); if(subM == NULL) continue; if(subM->canHandleID(command)) { return subM->handleSelect(command, text); } } // ensure that this menu actually has an item with the specificed command / refcon. // this is not strictly necessary, we're just doing it here to keep the behavior // in line with the windows implementation. UInt32 refcon; U32 nItems = CountMenuItems(mData->mMenu); S32 pos = -1; for(int i = 1; i <= nItems; i++) { GetMenuItemRefCon(mData->mMenu, i, &refcon); if(refcon == command) pos = i; } if(pos == -1) { Con::errorf("PopupMenu::handleSelect - Could not find menu item position for ID %d ... this shouldn't happen!", command); return false; } char textbuf[1024]; if(!text) { CFStringRef cfstr; CopyMenuItemTextAsCFString(mData->mMenu, pos, &cfstr); CFStringGetCString(cfstr,textbuf,sizeof(textbuf) - 1,kCFStringEncodingUTF8); CFRelease( cfstr ); text = textbuf; } // [tom, 8/20/2006] Wasn't handled by a submenu, pass off to script return dAtob(Con::executef(this, "onSelectItem", Con::getIntArg(pos - 1), text ? text : "")); }
OSStatus OPL_LoginDialog::handleCommandEvent(UInt32 commandID) { UInt32 idx; CFStringRef str; char *dsn; char tmp_path[1024]; switch (commandID) { case 'SDIR': ControlRef f_select; CFStringRef menuText; MenuRef menu; getControl(kLoginDIR, &f_select); menu = GetControlPopupMenuHandle(f_select); idx = GetControlValue (f_select); CopyMenuItemTextAsCFString(menu, idx, &menuText); CFStringGetCString(menuText, tmp_path, sizeof(tmp_path), kCFStringEncodingUTF8); CFRelease(menuText); loadFDSNList(tmp_path); return noErr; case 'SFDS': idx = fdsnlist->getSelectedItem(); if (idx && !fdsnlist->getItemType(idx)) { // set DSN dsn = OPL_CFString_to_char(fdsnlist->getItem(idx)); str = OPL_CFString_asprintf("%s/%s", cur_dir, dsn); setEditText(kLoginDSN, str); free(dsn); } return noErr; case 'SDS ': idx = dsnlist->getSelectedItem(); if (idx) setEditText(kLoginDSN, CFStringCreateCopy(NULL, dsnlist->getItem(idx))); return noErr; default: return OPL_Dialog::handleCommandEvent(commandID); } }