Beispiel #1
0
static void
carbon_menu_item_update_accelerator (CarbonMenuItem *carbon_item,
				     GtkWidget      *widget)
{
  GtkWidget *label;

  get_menu_label_text (widget, &label);

  if (GTK_IS_ACCEL_LABEL (label))
    {
      GClosure      *closure;

      g_object_get (label, "accel-closure", &closure, NULL);

      if (closure)
	{
	  GtkAccelGroup *group;
	  GtkAccelKey   *key;

	  group = gtk_accel_group_from_accel_closure (closure);
	  key = gtk_accel_group_find (group, accel_find_func, closure);

	  g_closure_unref (closure);

	  if (key            &&
	      key->accel_key &&
	      key->accel_flags & GTK_ACCEL_VISIBLE)
	    {
	      GdkDisplay      *display = gtk_widget_get_display (widget);
	      GdkKeymap       *keymap  = gdk_keymap_get_for_display (display);
	      GdkKeymapKey    *keys;
	      gint             n_keys;

	      if (gdk_keymap_get_entries_for_keyval (keymap, key->accel_key,
						     &keys, &n_keys))
		{
		  UInt8 modifiers = 0;

		  SetMenuItemCommandKey (carbon_item->menu, carbon_item->index,
					 true, keys[0].keycode);

		  g_free (keys);

		  if (key->accel_mods)
		    {
		      if (key->accel_mods & GDK_SHIFT_MASK)
			modifiers |= kMenuShiftModifier;

		      if (key->accel_mods & GDK_MOD1_MASK)
			modifiers |= kMenuOptionModifier;
		    }

		  if (!(key->accel_mods & GDK_META_MASK))
		    {
		      modifiers |= kMenuNoCommandModifier;
		    }

		  SetMenuItemModifiers (carbon_item->menu, carbon_item->index,
					modifiers);

		  return;
		}
	    }
	}
    }

  /*  otherwise, clear the menu shortcut  */
  SetMenuItemModifiers (carbon_item->menu, carbon_item->index,
			kMenuNoModifiers | kMenuNoCommandModifier);
  ChangeMenuItemAttributes (carbon_item->menu, carbon_item->index,
			    0, kMenuItemAttrUseVirtualKey);
  SetMenuItemCommandKey (carbon_item->menu, carbon_item->index,
			 false, 0);
}
Beispiel #2
0
static void _assignCommandKeys(const char* accel, MenuRef menu, MenuItemIndex item)
{
   if(!(accel && *accel))
      return;
   
   // get the modifier keys
   String _accel = String::ToLower( accel );
   int mods = _getModifierMask(_accel);

   // accel is space or dash delimted.
   // the modifier key is either the last token in accel, or the first char in accel.
   const char* key = dStrrchr(_accel, ' ');
   if(!key)
      key = dStrrchr(_accel, '-');
   if(!key)
      key = _accel;
   else
      key++;
      
   if(dStrlen(key) <= 1)
   {
      char k = dToupper( key[0] );
      SetMenuItemCommandKey( menu, item, false, k );
   }
   else
   {
      SInt16 glyph = kMenuNullGlyph;

      //*** A lot of these mappings came from a listing at http://developer.apple.com/releasenotes/Carbon/HIToolboxOlderNotes.html
      if(!dStricmp(key, "DELETE"))
         glyph = kMenuDeleteRightGlyph;
         
      else if(!dStricmp(key, "HOME"))
         glyph = kMenuNorthwestArrowGlyph;
         
      else if(!dStricmp(key, "END"))
         glyph = kMenuSoutheastArrowGlyph;
         
      else if(!dStricmp(key, "BACKSPACE"))
         glyph =  kMenuDeleteLeftGlyph;
         
      else if(!dStricmp(key, "TAB"))
         glyph =  kMenuTabRightGlyph;
         
      else if(!dStricmp(key, "RETURN"))
         glyph =  kMenuReturnGlyph;
         
      else if(!dStricmp(key, "ENTER"))
         glyph =  kMenuEnterGlyph;
         
      else if(!dStricmp(key, "PG UP"))
         glyph =  kMenuPageUpGlyph;
         
      else if(!dStricmp(key, "PG DOWN"))
         glyph =  kMenuPageDownGlyph;
         
      else if(!dStricmp(key, "ESC"))
         glyph =  kMenuEscapeGlyph;
         
      else if(!dStricmp(key, "LEFT"))
         glyph =  kMenuLeftArrowGlyph;
         
      else if(!dStricmp(key, "RIGHT"))
         glyph =  kMenuRightArrowGlyph;
         
      else if(!dStricmp(key, "UP"))
         glyph =  kMenuUpArrowGlyph;

      else if(!dStricmp(key, "DOWN"))
         glyph =  kMenuDownArrowGlyph;

      else if(!dStricmp(key, "SPACE"))
         glyph =  kMenuSpaceGlyph;

      else if(!dStricmp(key, "F1"))
         glyph =  kMenuF1Glyph;

      else if(!dStricmp(key, "F2"))
         glyph =  kMenuF2Glyph;

      else if(!dStricmp(key, "F3"))
         glyph =  kMenuF3Glyph;

      else if(!dStricmp(key, "F4"))
         glyph =  kMenuF4Glyph;

      else if(!dStricmp(key, "F5"))
         glyph =  kMenuF5Glyph;

      else if(!dStricmp(key, "F6"))
         glyph =  kMenuF6Glyph;

      else if(!dStricmp(key, "F7"))
         glyph =  kMenuF7Glyph;

      else if(!dStricmp(key, "F8"))
         glyph =  kMenuF8Glyph;

      else if(!dStricmp(key, "F9"))
         glyph =  kMenuF9Glyph;

      else if(!dStricmp(key, "F10"))
         glyph =  kMenuF10Glyph;

      else if(!dStricmp(key, "F11"))
         glyph =  kMenuF11Glyph;

      else if(!dStricmp(key, "F12"))
         glyph =  kMenuF12Glyph;

      else if(!dStricmp(key, "F13"))
         glyph =  kMenuF13Glyph;

      else if(!dStricmp(key, "F14"))
         glyph =  kMenuF14Glyph;

      else if(!dStricmp(key, "F15"))
         glyph =  kMenuF15Glyph;

      SetMenuItemKeyGlyph(menu, item, glyph);
   }

   SetMenuItemModifiers(menu, item, mods);
}
Beispiel #3
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;
}
Beispiel #4
0
void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEntry *entry )
{
    if ( !entry )
    {
        SetMenuItemCommandKey(menu, item, false, 0); 
        return ;
    }

    UInt8 modifiers = 0 ;
    SInt16 key = entry->GetKeyCode() ;
    if ( key )
    {
        bool explicitCommandKey = (entry->GetFlags() & wxACCEL_CTRL);

        if (entry->GetFlags() & wxACCEL_ALT)
            modifiers |= kMenuOptionModifier ;

        if (entry->GetFlags() & wxACCEL_SHIFT)
            modifiers |= kMenuShiftModifier ;

        SInt16 glyph = 0 ;
        SInt16 macKey = key ;
        if ( key >= WXK_F1 && key <= WXK_F15 )
        {
            if ( !explicitCommandKey )
                modifiers |= kMenuNoCommandModifier ;

            // for some reasons this must be 0 right now
            // everything else leads to just the first function key item
            // to be selected. Thanks to Ryan Wilcox for finding out.
            macKey = 0 ;
            glyph = kMenuF1Glyph + ( key - WXK_F1 ) ;
            if ( key >= WXK_F13 )
                glyph += 12 ;
        }
        else
        {
            switch ( key )
            {
                case WXK_BACK :
                    macKey = kBackspaceCharCode ;
                    glyph = kMenuDeleteLeftGlyph ;
                    break ;

                case WXK_TAB :
                    macKey = kTabCharCode ;
                    glyph = kMenuTabRightGlyph ;
                    break ;

                case kEnterCharCode :
                    macKey = kEnterCharCode ;
                    glyph = kMenuEnterGlyph ;
                    break ;

                case WXK_RETURN :
                    macKey = kReturnCharCode ;
                    glyph = kMenuReturnGlyph ;
                    break ;

                case WXK_ESCAPE :
                    macKey = kEscapeCharCode ;
                    glyph = kMenuEscapeGlyph ;
                    break ;

                case WXK_SPACE :
                    macKey = ' ' ;
                    glyph = kMenuSpaceGlyph ;
                    break ;

                case WXK_DELETE :
                    macKey = kDeleteCharCode ;
                    glyph = kMenuDeleteRightGlyph ;
                    break ;

                case WXK_CLEAR :
                    macKey = kClearCharCode ;
                    glyph = kMenuClearGlyph ;
                    break ;

                case WXK_PAGEUP :
                    macKey = kPageUpCharCode ;
                    glyph = kMenuPageUpGlyph ;
                    break ;

                case WXK_PAGEDOWN :
                    macKey = kPageDownCharCode ;
                    glyph = kMenuPageDownGlyph ;
                    break ;

                case WXK_LEFT :
                    macKey = kLeftArrowCharCode ;
                    glyph = kMenuLeftArrowGlyph ;
                    break ;

                case WXK_UP :
                    macKey = kUpArrowCharCode ;
                    glyph = kMenuUpArrowGlyph ;
                    break ;

                case WXK_RIGHT :
                    macKey = kRightArrowCharCode ;
                    glyph = kMenuRightArrowGlyph ;
                    break ;

                case WXK_DOWN :
                    macKey = kDownArrowCharCode ;
                    glyph = kMenuDownArrowGlyph ;
                    break ;

                case WXK_HOME :
                    macKey = kHomeCharCode ;
                    glyph = kMenuNorthwestArrowGlyph ;
                    break ;

                case WXK_END :
                    macKey = kEndCharCode ;
                    glyph = kMenuSoutheastArrowGlyph ;
                    break ;
                default :
                    macKey = toupper( key ) ;
                    break ;
            }

            // we now allow non command key shortcuts
            // remove in case this gives problems
            if ( !explicitCommandKey )
                modifiers |= kMenuNoCommandModifier ;
        }

        // 1d and 1e have special meaning to SetItemCmd, so
        // do not use for these character codes.
        if (key != WXK_UP && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_LEFT)
            SetItemCmd( menu, item , macKey );

        SetMenuItemModifiers( menu, item , modifiers ) ;

        if ( glyph )
            SetMenuItemKeyGlyph( menu, item , glyph ) ;
    }
}
Beispiel #5
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();
}