Example #1
0
/*	SetPopMatch(theDialog, popupItemNumber, selStr)

 	Sets currently selected item to that which matches string (case insensitive).
	Returns item number or zero if there is no match.

	Thread Safety: SetPopMatch is not thread-safe.
*/
int
SetPopMatch(DialogPtr theDialog, int popupItemNumber, const char *selStr)
{
	ControlHandle controlH;
	MenuHandle mH;
	int numMenuItems;
	int i;
	unsigned char temp[256];
	char itemText[256];
	int result;
	int err;

	if (err = XOPGetDialogItemAsControl(theDialog, popupItemNumber, &controlH))
		return 0;
	
	mH = GetPopMenuHandle(theDialog, popupItemNumber);
	if (mH == NULL)
		return 0;
	
	result = 0;
	numMenuItems = CountMenuItems(mH);
	for (i=1; i<=numMenuItems; i++) {
		GetMenuItemText(mH, i, temp);
		CopyPascalStringToC(temp, itemText);
		if (CmpStr(itemText,selStr) == 0) {
			result = i;
			SetControlValue(controlH, result);
			InvalDBox(theDialog, popupItemNumber);		// This can move heap.
			break;
		}
	}
	return result;
}
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();	
}
EXPORT(sqInt) primitiveCountMenuItems(void) {
	sqInt returnValue;
	MenuHandle menuHandle;
	sqInt menuHandleOop;
	sqInt _return_value;

	menuHandleOop = interpreterProxy->stackValue(0);
	if (interpreterProxy->failed()) {
		return null;
	}
	menuHandle = ((MenuHandle) (interpreterProxy->positive64BitValueOf(menuHandleOop)));
	if (!(ioCheckMenuHandle(menuHandle))) {
		_return_value = interpreterProxy->success(0);
		if (interpreterProxy->failed()) {
			return null;
		}
		interpreterProxy->popthenPush(2, _return_value);
		return null;
	}
	returnValue = CountMenuItems(menuHandle);
	_return_value = interpreterProxy->integerObjectOf(returnValue);
	if (interpreterProxy->failed()) {
		return null;
	}
	interpreterProxy->popthenPush(2, _return_value);
	return null;
}
Example #4
0
File: uma.cpp Project: beanhome/dev
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) );
}
Example #5
0
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);
                }
            }
        }
    }
}
Example #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;
}
Example #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));
}
Example #8
0
static void uncheckallmenuitems (MenuHandle hmenu) {
	
	short i;
	short ct;
	//Code change by Timothy Paustian Sunday, June 25, 2000 10:50:50 PM
	//updated to modern functions.
	ct = CountMenuItems (hmenu);
	
	for (i = 1; i <= ct; i++)
		CheckMenuItem (hmenu, i, false);
	} /*uncheckallmenuitems*/
Example #9
0
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 ) ;
}
Example #10
0
OSStatus
SyncPopupButtonToMenu( ControlRef popupButton )
{
	OSStatus	err;
	MenuRef		menu;
	
	err = GetPopupButtonMenuRef( popupButton, &menu );
	if ( err == noErr )
	{
		if ( CountMenuItems( menu ) >= 1 )
		{
			SetControlMaximum( popupButton, CountMenuItems( menu ) );
			SetControlMinimum( popupButton, 1 );
		}
		else
		{
			SetControlMinimum( popupButton, 0 );
			SetControlMaximum( popupButton, 0 );
		}
	}

	return err;
}
Example #11
0
void XGPopControl::ReloadItems (void)
{
	MenuHandle menu;
	int ix, len;
	char buf[256];

	if (!fControl)
		return;

	XGDraw draw(this,false);

	menu = GetMenuHandle();
	if (!menu)
		return;

#if TARGET_CARBON
	for (ix = CountMenuItems(menu); ix > 0; ix--) DeleteMenuItem(menu, ix);
#else
	for (ix = CountMItems(menu); ix > 0; ix--) DeleteMenuItem(menu, ix);
#endif

	for (ix = 0; ix < fList.GetNumStrings(); ix++) {
		fList.GetString(ix, buf);
		len = strlen(buf);
		memmove(&buf[1], buf, len);
		buf[0] = len;
		AppendMenu(menu, "\px");
		SetMenuItemText(menu, ix + 1, (unsigned char *)buf);
	}

#if TARGET_CARBON
	SetControlMaximum(fControl, CountMenuItems(menu));
#else
	SetControlMaximum(fControl, CountMItems(menu));
#endif
	SetControlValue(fControl, fValue + 1);
}
Example #12
0
short GetWindowMenuItemID( StringPtr title )
{
	short i;
	Str255 menuItemTitle;

	i = CountMenuItems( windowMenu );
	while( i )
	{
		GetMenuItemText( windowMenu, i, menuItemTitle );		// if you open more than one file with the same name (or edit the other fork)É
		if( EqualPStrings( title, menuItemTitle ) )
			break;
		i--;
	}
	return( i );
}
Example #13
0
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 : ""));
}
Example #14
0
 MenuItemIndex FindMenuItemIndex()
 {
     MenuItemIndex hit = 0 ;
     if ( m_parentMenuRef )
     {
         for ( MenuItemIndex i = 1 ; i <= CountMenuItems(m_parentMenuRef) ; ++i )
         {
             URefCon storedRef = 0;
             GetMenuItemRefCon(m_parentMenuRef, i, &storedRef );
             if ( storedRef == (URefCon) m_peer )
             {
                 hit = i;
                 break;
             }
         }
     }
     return hit;
 }
Example #15
0
void wxFontEnumeratorHelper::DoEnumerate()
{
    MenuHandle    menu ;
    Str255        p_name ;

    short         lines ;

    menu = NewMenu( 32000 , "\pFont" )  ;
    AppendResMenu( menu , 'FONT' ) ;
    lines = CountMenuItems( menu ) ;

    for ( int i = 1 ; i < lines+1  ; i ++ )
    {
        GetMenuItemText( menu , i , p_name ) ;
        wxString c_name = wxMacMakeStringFromPascal(p_name) ;

        /*

          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 ) ;
}
Example #16
0
/*	SetPopMenuMax(theDialog, popupItemNumber)

	The Mac OS Control Manager needs to be told how many items are in the menu each time we change it.

	Thread Safety: SetPopMenuMax is not thread-safe.
*/
static int
SetPopMenuMax(DialogPtr theDialog, int popupItemNumber)
{
	ControlHandle controlH;
	MenuHandle mH;
	int numMenuItems;
	int err;

	if (err = XOPGetDialogItemAsControl(theDialog, popupItemNumber, &controlH))
		return err;
	
	if (err = GetDialogPopupMenuMenuHandle(theDialog, popupItemNumber, &mH))
		return err;

	numMenuItems = CountMenuItems(mH);				// Number of items in the menu.
	SetControlMaximum(controlH, numMenuItems);		// Tell the control manager.
	
	return 0;
}
Example #17
0
    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();
    }
Example #18
0
/*	SetPopItem(theDialog, popupItemNumber, theItem)

 	Makes theItem the currently selected item.

	Thread Safety: SetPopItem is not thread-safe.
*/
void
SetPopItem(DialogPtr theDialog, int popupItemNumber, int theItem)
{
	ControlHandle controlH;
	MenuHandle mH;
	int numMenuItems;
	int err;

	if (err = XOPGetDialogItemAsControl(theDialog, popupItemNumber, &controlH))
		return;
	
	mH = GetPopMenuHandle(theDialog, popupItemNumber);
	if (mH == NULL)
		return;
	
	numMenuItems = CountMenuItems(mH);
	if (theItem<=0 || theItem>numMenuItems)
		return;
	
	SetControlValue(controlH, theItem);
	InvalDBox(theDialog, popupItemNumber);			// This can move heap.
}
//----------------------------------------------------------------------------//
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;
}
Example #20
0
/****************************************************************
   SetPopSelection() sets the lastItemSelected for the given
   popup.
 ****************************************************************/
void SetPopSelection(DialogPtr theDialog, short item, short selection)
{
      short          i;
   
   #ifndef IBM   
      short          j, c;
   #endif
   
      for ( i = 0 ; i < sa_numPopUps ; i++ )
         if ( (sa_popTable[i].dialogPtr == theDialog) && (sa_popTable[i].popupItemNum == item) )
            break;

      if (i < sa_numPopUps)
      {
      #ifndef IBM
	  
         MenuHandle  theMenu;

         theMenu = GetMenuHandle(sa_popTable[i].menuID);
         for (j = 1, c = CountMenuItems(theMenu); j <= c ; j++)
            SetItemMark(theMenu, j, noMark);
         SetItemMark(theMenu, selection, kCheckMark);
		 
      #endif //IBM
	  
         sa_popTable[i].lastItemSelected = selection;
     
     #ifdef IBM //{/////////
       
		 // This forces an update of the 'combo box' so that it displays the 
	     //   currently selected menu item.
		 PopDraw( theDialog, item );
       
     #endif // IBM //}/////////
	 
      }

}
Example #21
0
// this method really isn't necessary for the mac implementation
bool PopupMenu::canHandleID(U32 iD)
{
   for(S32 i = 0;i < mSubmenus->size();i++)
   {
      PopupMenu *subM = dynamic_cast<PopupMenu *>((*mSubmenus)[i]);
      if(subM == NULL)
         continue;

      if(subM->canHandleID(iD))
         return true;
   }

   UInt32 refcon;
   U32 nItems = CountMenuItems(mData->mMenu);
   for(int i = 1; i <= nItems; i++)
   {
      GetMenuItemRefCon(mData->mMenu, i, &refcon);
      if(refcon == iD)
         return true;
   }

   return false;
}
Example #22
0
/*
	Event handler for the content view that gets attached to the menu frame.

	The content view will (eventually) contain the menu view.
*/
OSStatus ContentViewEventHandler(
	EventHandlerCallRef inCallRef,
	EventRef inEvent,
	void *refcon)
{
	OSStatus retVal = eventNotHandledErr;
	if(GetEventClass(inEvent) == kEventClassMenu) {
		return noErr;
	} else
	if(GetEventClass(inEvent) == kEventClassControl) {
		HIViewRef hiSelf = NULL;
		verify_noerr(GetEventParameter(inEvent, kEventParamDirectObject, typeControlRef, NULL, sizeof(hiSelf), NULL, &hiSelf));

		if(hiSelf) {
			HIRect frame;
			HIViewGetFrame(hiSelf, &frame);

			switch(GetEventKind(inEvent)) {
				case kEventControlAddedSubControl : {
					HIViewRef subControl;
					ControlID subControlID;

					GetEventParameter(inEvent, kEventParamControlSubControl, typeControlRef, NULL, sizeof(subControl), NULL, &subControl );
					GetControlID(subControl, &subControlID);

					// This should be comparing against kHIViewMenuContentID as shown inside the
					// #if 0. At the time of this writing, however, using that constant causes a
					// linker error (and a crash if you use ZeroLink).  I extracted the signature
					// and id by determining the value at run-time the value I compare against.
#if 0
					if( kHIViewMenuContentID.signature == subControlID.signature && kHIViewMenuContentID.id == subControlID.id ) {
#else
					if( 'menu' == subControlID.signature && 0 == subControlID.id ) {
#endif
						// If we have the menu content view then set up some view bindings for it.
						HIRect bounds;
						HIViewGetBounds(hiSelf, &bounds);
						HIViewSetFrame(subControl, &bounds);

						HILayoutInfo contentLayout = {
							kHILayoutInfoVersionZero,
							{
								{ NULL, kHILayoutBindTop },
								{ NULL, kHILayoutBindLeft },
								{ NULL, kHILayoutBindBottom },
								{ NULL, kHILayoutBindRight }
							},
							{
								{ NULL, kHILayoutScaleAbsolute, 0 },
								{ NULL, kHILayoutScaleAbsolute, 0 }
							},
							{
								{ NULL, kHILayoutPositionTop, 0 },
								{ NULL, kHILayoutPositionLeft, 0 }
							}
						};

						verify_noerr(HIViewSetLayoutInfo(subControl, &contentLayout));
					}

					retVal = noErr;
				} break;

				case kEventControlGetFrameMetrics :
					HIViewFrameMetrics metrics;

					// The offset from the frame view to the content view is 
					// given by the kFrameOffset constant
					metrics.top = kFrameOffset;
					metrics.left = kFrameOffset;
					metrics.right = kFrameOffset;
					metrics.bottom = kFrameOffset;

					verify_noerr(SetEventParameter(inEvent, kEventParamControlFrameMetrics, typeControlFrameMetrics, sizeof(metrics), &metrics));

					retVal = noErr;
				break;

				case kEventControlBoundsChanged :
				case kEventControlOwningWindowChanged : {
					// Maintain the QuickDraw port by changing its position to
					// match that of the content view.
					CGrafPtr windowPort = NULL;
					WindowRef window = GetControlOwner(hiSelf);

					if(window && (windowPort = GetWindowPort(window))) {
						CGrafPtr savePort;
						bool swapped = QDSwapPort(windowPort, &savePort);

						MovePortTo((short) frame.origin.x, (short) frame.origin.y);
						PortSize((short) frame.size.width, (short) frame.size.height);

						if(swapped) {
							QDSwapPort(savePort, NULL);
						}
					}

					retVal = noErr;
				} break;
			} // switch
		} // if (hiSelf)
	}

	return retVal;
}


/* ------------------------------------------ CreatePathForEntireStarMenu */
/*
	Create a path shape for the star frame.
	
	This looks an awful lot like CreatePathForEntireStarMenu in
	StarMenu.cpp but takes the radius to use as a parameter and
	then takes into account the kFrameOffest when creating the path.

	In true Core Foundation style, this is a CreateXXX routine and the
	caller is responsible for freeing the path that is returned.
*/
CGPathRef CreatePathForStarFrame(StarFrameData *menuData, float radius)
{
   CGMutablePathRef retVal = CGPathCreateMutable();
   MenuItemIndex numItems = CountMenuItems(menuData->menu);

   if(numItems > 0) {
	  const CGPoint fullRadiusPoint = { radius, 0 };
	  const CGPoint halfRadiusPoint = { ((radius - kFrameOffset) / 2.0) + kFrameOffset , 0 };

	  float   anglePerItem = 2 * pi / (float)numItems;   // in radians naturally
	  float   halfAngle = anglePerItem / 2.0;

	  CGPoint startPoint = halfRadiusPoint;
	  CGAffineTransform midRotate = CGAffineTransformMakeRotation(halfAngle);
	  CGPoint midPoint = CGPointApplyAffineTransform(fullRadiusPoint, midRotate);

	  CGAffineTransform rotateToNext = CGAffineTransformMakeRotation(anglePerItem);

	  CGPathMoveToPoint(retVal, NULL, startPoint.x, startPoint.y);
	  CGPathAddLineToPoint(retVal, NULL, midPoint.x, midPoint.y);

	  for(short ctr = 0; ctr < numItems; ctr++) {
		 startPoint = CGPointApplyAffineTransform(startPoint, rotateToNext);
		 midPoint = CGPointApplyAffineTransform(midPoint, rotateToNext);

		 CGPathAddLineToPoint(retVal, NULL, startPoint.x, startPoint.y);
		 CGPathAddLineToPoint(retVal, NULL, midPoint.x, midPoint.y);
	  }

	  CGPathCloseSubpath(retVal);
   }

   return retVal;
}
Example #23
0
U32 PopupMenu::getItemCount()
{
   return CountMenuItems( mData->mMenu );
}
Example #24
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);
}
Example #25
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;
}
Example #26
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;
}
Example #27
0
Boolean OverridePopClick(DialogPtr theDialog, short itemHit, long *result)
{
	GrafPtr				savePort;
	MenuHandle			theMenu;
	short				count;
	char				name[256],str[256];
	short				i;
	
	if(gVUTrick == gVUTrick2) return false; // we will not override PopClick
	
	for ( i = 0 ; i < sa_numPopUps ; i++ )
		if ( sa_popTable[i].dialogPtr == theDialog && sa_popTable[i].popupItemNum == itemHit )
			break;
	
	if (i == sa_numPopUps || sa_popTable[i].bStatic) {
		*result = 0;
		return false; // we will not override PopClick
	}
	
	// else we have found the i value
	
	theMenu = GetMenuHandle(sa_popTable[i].menuID);
	GetMenuItemText(theMenu, sa_popTable[i].lastItemSelected, (StringPtr)str); 
	my_p2cstr((StringPtr)str); 
	GetPortGrafPtr(&savePort);
	if(REQUEST("enter value to select",str,str) == ok)
	{
		short numItems = CountMenuItems(theMenu);
		UpperText(str,strlen(str));
		//UppercaseText(str,strlen(str),smSystemScript);	//smCurrentScript
		// find the string	
		for ( count = numItems ; count >= 1 ; count-- ) 
		{
			GetMenuItemText(theMenu, count, (StringPtr)name);
			my_p2cstr((StringPtr)name); 
			UpperText(name,strlen(name));
			//UppercaseText(name,strlen(name),smSystemScript);	//smCurrentScript
			if (strcmp(str,name) == 0) {
				if (!MenuItemEnabled(theMenu, count)) {
					REQUEST("Item found but disabled",str,str);
					*result = 0;
					SetPortGrafPort(savePort);
					return false;
				}
				else
					break; // we found it
			}
		}
		if(count == 0) 
		{
			// we did not find the string
			REQUEST("Could not find string in Menu",str,str);
			*result = 0;
			SetPortGrafPort(savePort);
			return false;
		}
		else
		{
			// count holds the menuItem Num we want
			SetItemMark(theMenu, sa_popTable[i].lastItemSelected, noMark);
			sa_popTable[i].lastItemSelected = count;
			SetItemMark(theMenu, sa_popTable[i].lastItemSelected, kCheckMark);
			*result = sa_popTable[i].menuID*0x10000 + sa_popTable[i].lastItemSelected;
		}
	
	}
	SetPortGrafPort(savePort);
	PopDraw(sa_popTable[i].dialogPtr, sa_popTable[i].popupItemNum);
	return(true); //we have overriden PopClick
}
Example #28
0
void	XControl::SetMenuHandle(MenuHandle menu)
{
    SetControlData(mControl, 0, kControlPopupButtonMenuHandleTag, sizeof(MenuHandle), &menu);
    SetControl32BitMaximum(mControl, CountMenuItems(menu));
}
Example #29
0
/****************************************************************
   PopClick() gets called when there is a click in a dialog item
   that might be a popup item.  It determines if the click is
   in a popup and if so handles the click.  It brings up the
   popup on the item that was last selected for this menu.  It
   returns true if the item was a popup item and the mouse was
   released on a valid item.
   In that case, it also stores the value returned
   by PopUpMenuSelect in *result (a long containing the menu and
   item ID selected).  If the item selected was in this menu (as
   opposed to one of its submenus), that item is stored in the
   lastItemSelected field for this popup in the popTable.  In
   that case, the item is also checked, and the previously
   selected item is unchecked.

   For a click on a static popup item, PopClick returns false,
   returns 0 in *result and doesn't call PopUpMenuSelect.

   -- On the IBM, this simply gets the index value of the selected item.

****************************************************************/
Boolean PopClick(DialogPtr theDialog, short itemHit, LONGPTR result)
{
#ifndef IBM
   GrafPtr        savePort;
   short          theType;
   Rect           popBox;
   Rect           titleBox;
   MenuHandle     theMenu;
   long           res;
   short          count;
   char           name[256];
   Handle         itemHandle;
#else
	HANDLE itemHandle;
#endif
   short          i;
   
   #ifndef IBM
   if (OverridePopClick(theDialog, itemHit, result)) return true;
   #endif
   
   for ( i = 0 ; i < sa_numPopUps ; i++ )
      if ( (sa_popTable[i].dialogPtr == theDialog) && (sa_popTable[i].popupItemNum == itemHit) )
         break;

   if (i == sa_numPopUps || sa_popTable[i].bStatic) {
      *result = 0;
      return false;
   }

 #ifdef IBM
   itemHandle = GetDlgItem (theDialog, itemHit);
   sa_popTable[i].lastItemSelected =
    // (SendMessage (itemHandle, CB_GETCURSEL, 0, 0L)+1);  //Combo box item ID's begin at 0
     (SendMessage ((HWND)itemHandle, CB_GETCURSEL, 0, 0L)+1);  //Combo box item ID's begin at 0
	
	return FALSE;
 #else
   GetPortGrafPtr(&savePort);
   SetPortDialogPort(theDialog);
   theMenu = GetMenuHandle(sa_popTable[i].menuID);

   if (sa_popTable[i].drawProc == nil)       // grow items to match size of pop-box
      for ( count = CountMenuItems(theMenu) ; count >= 1 ; count-- ) {
         GetMenuItemText(theMenu, count, (StringPtr)name);
         my_p2cstr((StringPtr)name);
         strcat(name, "     ");
         my_c2pstr(name);
         SetMenuItemText(theMenu, count, (StringPtr)name);
         my_p2cstr((StringPtr)name);
      }

   if (sa_popTable[i].titleItemNum) {
      GetDialogItem(theDialog,sa_popTable[i].titleItemNum,&theType,&itemHandle,&titleBox);
      InvertRect(&titleBox);
   }
   GetDialogItem(theDialog,sa_popTable[i].popupItemNum,&theType,&itemHandle,&popBox);
   LocalToGlobal((Point *)(&popBox.top));
   LocalToGlobal((Point *)(&popBox.bottom));
   res = PopUpMenuSelect( theMenu, popBox.top + 1, popBox.left + 1, sa_popTable[i].lastItemSelected );
   if (sa_popTable[i].titleItemNum)
      InvertRect(&titleBox);
   if (LoWord(res) && (HiWord(res) == sa_popTable[i].menuID)) {
      SetItemMark(theMenu, sa_popTable[i].lastItemSelected, noMark);
      sa_popTable[i].lastItemSelected = LoWord(res);
      SetItemMark(theMenu, sa_popTable[i].lastItemSelected, kCheckMark);
   }

   if (sa_popTable[i].drawProc == nil)       // shrink items back to normal
      for ( count = CountMenuItems(theMenu) ; count >= 1 ; count-- ) {
         GetMenuItemText(theMenu, count, (StringPtr)name);
         my_p2cstr((StringPtr)name);
         name[strlen(name) - 5] = 0;
         my_c2pstr(name);
         SetMenuItemText(theMenu, count, (StringPtr)name);
         my_p2cstr((StringPtr)name);
      }

   *result = res;

   SetPortGrafPort(savePort);

   if (LoWord(res)) {
      PopDraw(sa_popTable[i].dialogPtr, sa_popTable[i].popupItemNum);
      return true;
   }

   return false;
 #endif //IBM
}
Example #30
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 ;
}