Esempio n. 1
0
int
TkMacOSXProcessCommandEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr)
{
    HICommand	    command;
    int 	    menuContext;
    OSStatus	    status;

    switch (eventPtr->eKind) {
	case kEventCommandProcess:
	case kEventCommandUpdateStatus:
	    break;
	default:
	    return 0;
	    break;
    }
    status = GetEventParameter(eventPtr->eventRef, 
	    kEventParamDirectObject,
	    typeHICommand, NULL, 
	    sizeof(command), NULL,
	    &command);
    if (status == noErr && (command.attributes & kHICommandFromMenu)) {
	if (eventPtr->eKind == kEventCommandProcess) {
	    status = GetEventParameter(eventPtr->eventRef, 
		    kEventParamMenuContext,
		    typeUInt32, NULL, 
		    sizeof(menuContext), NULL,
		    &menuContext);
	    if (status == noErr && (menuContext & kMenuContextMenuBar) &&
		    (menuContext & kMenuContextMenuBarTracking)) {
		TkMacOSXHandleMenuSelect(GetMenuID(command.menu.menuRef),
			command.menu.menuItemIndex,
			GetCurrentEventKeyModifiers() & optionKey);
		return 1;
	    }
	} else {
	    Tcl_CmdInfo dummy;
	    if (command.commandID == kHICommandPreferences && eventPtr->interp) {
		if (Tcl_GetCommandInfo(eventPtr->interp, 
			"::tk::mac::ShowPreferences", &dummy)) {
		    if (!IsMenuItemEnabled(command.menu.menuRef, 
			    command.menu.menuItemIndex)) {
			EnableMenuItem(command.menu.menuRef,
				command.menu.menuItemIndex);
		    }
		} else {
		    if (IsMenuItemEnabled(command.menu.menuRef, 
			    command.menu.menuItemIndex)) {
			DisableMenuItem(command.menu.menuRef,
				command.menu.menuItemIndex);
		    }
		}
		return 1;
	    }
	}
    }
    return 0;
}
Esempio n. 2
0
Boolean MenuItemEnabled(MenuHandle menu, short item)
{
#if TARGET_API_MAC_CARBON
	// first check the entire  menu
	if(!IsMenuItemEnabled(menu,0)) return false;
	return IsMenuItemEnabled(menu,item);
	
#else
	return ((**menu).enableFlags & 1) && // low bit means menu itself is enabled
		   (BitTst((Ptr)&((**menu).enableFlags),
						 31 - (item <= 31 ? item : 0)));
#endif
}
EXPORT(sqInt) primitiveIsMenuItemEnabled(void) {
	MenuHandle menuHandle;
	sqInt result;
	sqInt menuHandleOop;
	sqInt anInteger;
	sqInt _return_value;

	menuHandleOop = interpreterProxy->stackValue(1);
	anInteger = interpreterProxy->stackIntegerValue(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(3, _return_value);
		return null;
	}
	result = IsMenuItemEnabled(menuHandle,anInteger);
	_return_value = (result? interpreterProxy->trueObject(): interpreterProxy->falseObject());
	if (interpreterProxy->failed()) {
		return null;
	}
	interpreterProxy->popthenPush(3, _return_value);
	return null;
}
Esempio n. 4
0
void wxMenuItem::Enable(bool bDoEnable)
{
    if (( m_isEnabled != bDoEnable
#if TARGET_CARBON
      // avoid changing menuitem state when menu is disabled
      // eg. BeginAppModalStateForWindow() will disable menus and ignore this change
      // which in turn causes m_isEnabled to become out of sync with real menuitem state
         && !(m_parentMenu && !IsMenuItemEnabled(MAC_WXHMENU(m_parentMenu->GetHMenu()), 0)) )
      // always update builtin menuitems
         || (   GetId() == wxApp::s_macPreferencesMenuItemId
             || GetId() == wxApp::s_macExitMenuItemId
             || GetId() == wxApp::s_macAboutMenuItemId
#endif
         ))
    {
        wxMenuItemBase::Enable( bDoEnable ) ;
        UpdateItemStatus() ;
    }
}
Esempio n. 5
0
/****************************************************************
   PopDraw() is the function associated with the user item that
   invokes the popup menu.  We draw the box to look like a menu
   cell, and then call the appropriate drawProc to fill in the
   cell with the actual contents.  If the drawProc is nil, we
   draw the menu item as text.  We gray the cell if the menu
   is disabled.  Finally, we draw a down arrow to indicate that
   the button is a popup menu.

   If the popup item is static, we only draw the cell contents.
 ****************************************************************/
pascal_ifMac void PopDraw(DialogPtr theDialog, short itemNum)
{
   GrafPtr        savePort;
   short          theType;
   Handle         itemHandle;
   Rect           itemBox;
   Rect           cellBox;
   MenuHandle     theMenu;
   //SysEnvRec      theWorld;
   RGBColor       SaveBack, SaveFore, DefaultBack, DefaultFore;
   char           name[256];
   short          i;
   short          drawStringFlag;

   // Added by Glen to code for support of Type-in Pop-Up menus
   // if drawStringFlag  = 1 then we don't draw text string ...
	
   drawStringFlag = 0;

   for ( i = 0 ; i < sa_numPopUps ; i++ )
      if ( (sa_popTable[i].dialogPtr == theDialog) && (sa_popTable[i].popupItemNum == itemNum) )
         break;
                              if (i == sa_numPopUps)
      { SysBeep(1); return; }    // should not happen since the dialog must have been registered
                                             // for PopDraw to have been called

   GetPortGrafPtr(&savePort);
   SetPortDialogPort(theDialog);
  // SysEnvirons(curSysEnvVers,&theWorld);

  // if (theWorld.hasColorQD) {
  if (ColorQDAvailable()) {
      GetForeColor(&SaveFore);
      GetBackColor(&SaveBack);
      DefaultMenuColors(&DefaultFore, &DefaultBack);
      if (sa_popTable[i].bStatic) {
         DefaultFore = SaveFore;
         DefaultBack = SaveBack;
      }
   }

   theMenu = GetMenuHandle(sa_popTable[i].menuID);
   if (!theMenu) { SysBeep(1); return; }
   
   /* change item's width to match the menu */
   GetDialogItem(theDialog,itemNum,&theType,&itemHandle,&itemBox);
   CalcMenuSize(theMenu);
   if (sa_popTable[i].itemWidth == 0) {
      if (sa_popTable[i].drawProc == nil)
        // itemBox.right = itemBox.left + (**theMenu).menuWidth + 20 + 2;
         itemBox.right = itemBox.left + GetMenuWidth(theMenu) + 20 + 2;
      else
         //itemBox.right = itemBox.left + (**theMenu).menuWidth + 2;
         itemBox.right = itemBox.left + GetMenuWidth(theMenu) + 2;
   }
   else if (sa_popTable[i].itemWidth == -1) {  // Type-in Pop-Up Menu
      itemBox.right = itemBox.left + 20 + 2;
      drawStringFlag = 1;
   }
   else
      itemBox.right = itemBox.left + sa_popTable[i].itemWidth + 2;
   SetDialogItem(theDialog,itemNum,theType,itemHandle,&itemBox);

   /* draw the box */
   if (TRUE) { // !sa_popTable[i].bStatic
     // if (theWorld.hasColorQD) RGBBackColor(&DefaultBack);
     if (ColorQDAvailable()) RGBBackColor(&DefaultBack);
      EraseRect( &itemBox );
     // if (theWorld.hasColorQD) RGBForeColor(&SaveFore);
     if (ColorQDAvailable())  RGBForeColor(&SaveFore);
      PenNormal();
	 // if (sa_popTable[i].bStatic) PenPat((ConstPatternParam)&qd.gray);
	  //if (sa_popTable[i].bStatic) PenPat((ConstPatternParam)&GRAY_BRUSH());
	  //if (sa_popTable[i].bStatic) PenPat((ConstPatternParam)&GRAY_BRUSH);
	  if (sa_popTable[i].bStatic) PenPatQDGlobalsGray();
      FrameRect(&itemBox);
      /* draw the shadow */
      MoveTo(itemBox.left + 3, itemBox.bottom);
      Line((itemBox.right - itemBox.left) - 3, 0);
      Line(0, -((itemBox.bottom - itemBox.top) - 2));
      PenNormal();
   }
   else
      EraseRect( &itemBox );

   /* draw the current item in the box */

  // if (theWorld.hasColorQD) RGBForeColor(&DefaultFore);
    if (ColorQDAvailable()) RGBForeColor(&DefaultFore);

   // Draw text if no Type-in Pop-Up
   if(drawStringFlag == 0){
      if (sa_popTable[i].drawProc != nil) {
         cellBox = itemBox;
         InsetRect(&cellBox, 1, 1);
         (* sa_popTable[i].drawProc) (theMenu,
                                                sa_popTable[i].lastItemSelected,
                                                &cellBox,         // so the drawProc gets the same-size rect,
                                                                      // whether it's drawing in the menu or in the pop-box
                                                true,           // since we are indeed drawing a pop box item
                                                //&theWorld,
                                                &DefaultFore,
                                                &DefaultBack);
      }
      else {
         MoveTo(itemBox.left + 15, itemBox.top + 4 + (itemBox.bottom - itemBox.top)/2);
         GetMenuItemText(theMenu, sa_popTable[i].lastItemSelected, (unsigned char *)name);
         DrawString((unsigned char *)name);
      }
   }

   if (TRUE) { // !sa_popTable[i].bStatic
      /* cover the item in gray if the menu is disabled */
     // if (!((**theMenu).enableFlags & ENABLE_BIT)) {
	  #if TARGET_API_MAC_CARBON
	 	 Boolean menuIsEnabled = IsMenuItemEnabled(theMenu,0);
	 #else
	 	 Boolean menuIsEnabled = (**theMenu).enableFlags & ENABLE_BIT;
	 #endif
      if (!menuIsEnabled) {
         //PenPat((ConstPatternParam)&qd.gray);
         //PenPat((ConstPatternParam)&GRAY_BRUSH);
		 PenPatQDGlobalsGray();
         PenMode(patOr);
         //if (theWorld.hasColorQD) RGBForeColor(&DefaultBack);
         if (ColorQDAvailable()) RGBForeColor(&DefaultBack); 
         else ForeColor(whiteColor);
         PaintRect(&itemBox);
         PenNormal();
        // if (theWorld.hasColorQD) RGBForeColor(&DefaultFore);
         if (ColorQDAvailable()) RGBForeColor(&DefaultFore);
         else ForeColor(blackColor);
      }

      /* draw the down arrow */
      itemBox.left = itemBox.right - 20;
      DrawArrow(&itemBox, kDown, sa_popTable[i].bStatic);
   }

   //if (theWorld.hasColorQD) {
   if (ColorQDAvailable()) {
     RGBForeColor(&SaveFore);
     RGBBackColor(&SaveBack);
   }

   SetPortGrafPort(savePort);
}