]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/uma.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/uma.cpp
3 // Purpose: UMA support
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: The wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/osx/uma.h"
18 #include "wx/toplevel.h"
21 #include "wx/osx/uma.h"
23 static SInt32 sUMASystemVersion
= 0 ;
25 long UMAGetSystemVersion()
27 if ( sUMASystemVersion
== 0 )
29 verify_noerr(Gestalt(gestaltSystemVersion
, &sUMASystemVersion
));
31 return sUMASystemVersion
;
38 MenuRef
UMANewMenu( SInt16 id
, const wxString
& title
, wxFontEncoding encoding
)
40 wxString str
= wxStripMenuCodes( title
) ;
43 CreateNewMenu( id
, 0 , &menu
) ;
44 SetMenuTitleWithCFString( menu
, wxCFStringRef(str
, encoding
) ) ;
49 void UMASetMenuTitle( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
)
51 wxString str
= wxStripMenuCodes( title
) ;
53 SetMenuTitleWithCFString( menu
, wxCFStringRef(str
, encoding
) ) ;
56 void UMASetMenuItemText( MenuRef menu
, MenuItemIndex item
, const wxString
& title
, wxFontEncoding encoding
)
58 // we don't strip the accels here anymore, must be done before
59 wxString str
= title
;
61 SetMenuItemTextWithCFString( menu
, item
, wxCFStringRef(str
, encoding
) ) ;
64 void UMAEnableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
, bool enable
)
67 EnableMenuItem( inMenu
, inItem
) ;
69 DisableMenuItem( inMenu
, inItem
) ;
72 void UMAAppendSubMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, SInt16 id
)
74 AppendMenuItemTextWithCFString( menu
,
75 CFSTR("A"), 0, 0,NULL
);
76 UMASetMenuItemText( menu
, (SInt16
) ::CountMenuItems(menu
), title
, encoding
);
77 SetMenuItemHierarchicalID( menu
, CountMenuItems( menu
) , id
) ;
80 void UMAInsertSubMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, MenuItemIndex item
, SInt16 id
)
82 InsertMenuItemTextWithCFString( menu
,
83 CFSTR("A"), item
, 0, 0);
85 UMASetMenuItemText( menu
, item
+1, title
, encoding
);
86 SetMenuItemHierarchicalID( menu
, item
+1 , id
) ;
89 void UMASetMenuItemShortcut( MenuRef menu
, MenuItemIndex item
, wxAcceleratorEntry
*entry
)
95 SInt16 key
= entry
->GetKeyCode() ;
98 bool explicitCommandKey
= (entry
->GetFlags() & wxACCEL_CTRL
);
100 if (entry
->GetFlags() & wxACCEL_ALT
)
101 modifiers
|= kMenuOptionModifier
;
103 if (entry
->GetFlags() & wxACCEL_SHIFT
)
104 modifiers
|= kMenuShiftModifier
;
107 SInt16 macKey
= key
;
108 if ( key
>= WXK_F1
&& key
<= WXK_F15
)
110 if ( !explicitCommandKey
)
111 modifiers
|= kMenuNoCommandModifier
;
113 // for some reasons this must be 0 right now
114 // everything else leads to just the first function key item
115 // to be selected. Thanks to Ryan Wilcox for finding out.
117 glyph
= kMenuF1Glyph
+ ( key
- WXK_F1
) ;
118 if ( key
>= WXK_F13
)
126 macKey
= kBackspaceCharCode
;
127 glyph
= kMenuDeleteLeftGlyph
;
131 macKey
= kTabCharCode
;
132 glyph
= kMenuTabRightGlyph
;
135 case kEnterCharCode
:
136 macKey
= kEnterCharCode
;
137 glyph
= kMenuEnterGlyph
;
141 macKey
= kReturnCharCode
;
142 glyph
= kMenuReturnGlyph
;
146 macKey
= kEscapeCharCode
;
147 glyph
= kMenuEscapeGlyph
;
152 glyph
= kMenuSpaceGlyph
;
156 macKey
= kDeleteCharCode
;
157 glyph
= kMenuDeleteRightGlyph
;
161 macKey
= kClearCharCode
;
162 glyph
= kMenuClearGlyph
;
166 macKey
= kPageUpCharCode
;
167 glyph
= kMenuPageUpGlyph
;
171 macKey
= kPageDownCharCode
;
172 glyph
= kMenuPageDownGlyph
;
176 macKey
= kLeftArrowCharCode
;
177 glyph
= kMenuLeftArrowGlyph
;
181 macKey
= kUpArrowCharCode
;
182 glyph
= kMenuUpArrowGlyph
;
186 macKey
= kRightArrowCharCode
;
187 glyph
= kMenuRightArrowGlyph
;
191 macKey
= kDownArrowCharCode
;
192 glyph
= kMenuDownArrowGlyph
;
196 macKey
= kHomeCharCode
;
197 glyph
= kMenuNorthwestArrowGlyph
;
201 macKey
= kEndCharCode
;
202 glyph
= kMenuSoutheastArrowGlyph
;
205 macKey
= toupper( key
) ;
209 // we now allow non command key shortcuts
210 // remove in case this gives problems
211 if ( !explicitCommandKey
)
212 modifiers
|= kMenuNoCommandModifier
;
215 // 1d and 1e have special meaning to SetItemCmd, so
216 // do not use for these character codes.
217 if (key
!= WXK_UP
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_LEFT
)
218 SetItemCmd( menu
, item
, macKey
);
220 SetMenuItemModifiers( menu
, item
, modifiers
) ;
223 SetMenuItemKeyGlyph( menu
, item
, glyph
) ;
227 void UMAAppendMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, wxAcceleratorEntry
*entry
)
229 AppendMenuItemTextWithCFString( menu
,
230 CFSTR("A"), 0, 0,NULL
);
231 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
232 ChangeMenuItemAttributes( menu
, ::CountMenuItems(menu
), kMenuItemAttrIgnoreMeta
, 0 ) ;
233 UMASetMenuItemText(menu
, (SInt16
) ::CountMenuItems(menu
), title
, encoding
);
234 UMASetMenuItemShortcut( menu
, (SInt16
) ::CountMenuItems(menu
), entry
) ;
237 void UMAInsertMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, MenuItemIndex item
, wxAcceleratorEntry
*entry
)
239 InsertMenuItemTextWithCFString( menu
,
240 CFSTR("A"), item
, 0, 0);
242 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
243 ChangeMenuItemAttributes( menu
, item
+1, kMenuItemAttrIgnoreMeta
, 0 ) ;
244 UMASetMenuItemText(menu
, item
+1 , title
, encoding
);
245 UMASetMenuItemShortcut( menu
, item
+1 , entry
) ;
248 static OSStatus
UMAGetHelpMenu(
249 MenuRef
* outHelpMenu
,
250 MenuItemIndex
* outFirstCustomItemIndex
,
251 bool allowHelpMenuCreation
);
253 static OSStatus
UMAGetHelpMenu(
254 MenuRef
* outHelpMenu
,
255 MenuItemIndex
* outFirstCustomItemIndex
,
256 bool allowHelpMenuCreation
)
258 static bool s_createdHelpMenu
= false ;
260 if ( !s_createdHelpMenu
&& !allowHelpMenuCreation
)
265 OSStatus status
= HMGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
) ;
266 s_createdHelpMenu
= ( status
== noErr
) ;
270 OSStatus
UMAGetHelpMenu(
271 MenuRef
* outHelpMenu
,
272 MenuItemIndex
* outFirstCustomItemIndex
)
274 return UMAGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
, true );
277 OSStatus
UMAGetHelpMenuDontCreate(
278 MenuRef
* outHelpMenu
,
279 MenuItemIndex
* outFirstCustomItemIndex
)
281 return UMAGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
, false );