]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/uma.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/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"
27 MenuRef
UMANewMenu( SInt16 id
, const wxString
& title
, wxFontEncoding encoding
)
29 wxString str
= wxStripMenuCodes( title
) ;
32 CreateNewMenu( id
, 0 , &menu
) ;
33 SetMenuTitleWithCFString( menu
, wxCFStringRef(str
, encoding
) ) ;
38 void UMASetMenuTitle( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
)
40 wxString str
= wxStripMenuCodes( title
) ;
42 SetMenuTitleWithCFString( menu
, wxCFStringRef(str
, encoding
) ) ;
45 void UMASetMenuItemText( MenuRef menu
, MenuItemIndex item
, const wxString
& title
, wxFontEncoding encoding
)
47 // we don't strip the accels here anymore, must be done before
48 wxString str
= title
;
50 SetMenuItemTextWithCFString( menu
, item
, wxCFStringRef(str
, encoding
) ) ;
53 void UMAEnableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
, bool enable
)
56 EnableMenuItem( inMenu
, inItem
) ;
58 DisableMenuItem( inMenu
, inItem
) ;
61 void UMAAppendSubMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, MenuRef submenu
)
63 AppendMenuItemTextWithCFString( menu
,
64 CFSTR("A"), 0, 0,NULL
);
65 UMASetMenuItemText( menu
, (SInt16
) ::CountMenuItems(menu
), title
, encoding
);
66 SetMenuItemHierarchicalMenu( menu
, CountMenuItems( menu
) , submenu
) ;
67 SetMenuTitleWithCFString(submenu
, wxCFStringRef(title
, encoding
) );
70 void UMAInsertSubMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, MenuItemIndex item
, SInt16 id
)
72 InsertMenuItemTextWithCFString( menu
,
73 CFSTR("A"), item
, 0, 0);
75 UMASetMenuItemText( menu
, item
+1, title
, encoding
);
76 SetMenuItemHierarchicalID( menu
, item
+1 , id
) ;
79 void UMASetMenuItemShortcut( MenuRef menu
, MenuItemIndex item
, wxAcceleratorEntry
*entry
)
83 SetMenuItemCommandKey(menu
, item
, false, 0);
88 SInt16 key
= entry
->GetKeyCode() ;
91 bool explicitCommandKey
= (entry
->GetFlags() & wxACCEL_CTRL
);
93 if (entry
->GetFlags() & wxACCEL_ALT
)
94 modifiers
|= kMenuOptionModifier
;
96 if (entry
->GetFlags() & wxACCEL_SHIFT
)
97 modifiers
|= kMenuShiftModifier
;
100 SInt16 macKey
= key
;
101 if ( key
>= WXK_F1
&& key
<= WXK_F15
)
103 if ( !explicitCommandKey
)
104 modifiers
|= kMenuNoCommandModifier
;
106 // for some reasons this must be 0 right now
107 // everything else leads to just the first function key item
108 // to be selected. Thanks to Ryan Wilcox for finding out.
110 glyph
= kMenuF1Glyph
+ ( key
- WXK_F1
) ;
111 if ( key
>= WXK_F13
)
119 macKey
= kBackspaceCharCode
;
120 glyph
= kMenuDeleteLeftGlyph
;
124 macKey
= kTabCharCode
;
125 glyph
= kMenuTabRightGlyph
;
128 case kEnterCharCode
:
129 macKey
= kEnterCharCode
;
130 glyph
= kMenuEnterGlyph
;
134 macKey
= kReturnCharCode
;
135 glyph
= kMenuReturnGlyph
;
139 macKey
= kEscapeCharCode
;
140 glyph
= kMenuEscapeGlyph
;
145 glyph
= kMenuSpaceGlyph
;
149 macKey
= kDeleteCharCode
;
150 glyph
= kMenuDeleteRightGlyph
;
154 macKey
= kClearCharCode
;
155 glyph
= kMenuClearGlyph
;
159 macKey
= kPageUpCharCode
;
160 glyph
= kMenuPageUpGlyph
;
164 macKey
= kPageDownCharCode
;
165 glyph
= kMenuPageDownGlyph
;
169 macKey
= kLeftArrowCharCode
;
170 glyph
= kMenuLeftArrowGlyph
;
174 macKey
= kUpArrowCharCode
;
175 glyph
= kMenuUpArrowGlyph
;
179 macKey
= kRightArrowCharCode
;
180 glyph
= kMenuRightArrowGlyph
;
184 macKey
= kDownArrowCharCode
;
185 glyph
= kMenuDownArrowGlyph
;
189 macKey
= kHomeCharCode
;
190 glyph
= kMenuNorthwestArrowGlyph
;
194 macKey
= kEndCharCode
;
195 glyph
= kMenuSoutheastArrowGlyph
;
198 macKey
= toupper( key
) ;
202 // we now allow non command key shortcuts
203 // remove in case this gives problems
204 if ( !explicitCommandKey
)
205 modifiers
|= kMenuNoCommandModifier
;
208 // 1d and 1e have special meaning to SetItemCmd, so
209 // do not use for these character codes.
210 if (key
!= WXK_UP
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_LEFT
)
211 SetItemCmd( menu
, item
, macKey
);
213 SetMenuItemModifiers( menu
, item
, modifiers
) ;
216 SetMenuItemKeyGlyph( menu
, item
, glyph
) ;
220 void UMAAppendMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, wxAcceleratorEntry
*entry
)
222 AppendMenuItemTextWithCFString( menu
,
223 CFSTR("A"), 0, 0,NULL
);
224 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
225 ChangeMenuItemAttributes( menu
, ::CountMenuItems(menu
), kMenuItemAttrIgnoreMeta
, 0 ) ;
226 UMASetMenuItemText(menu
, (SInt16
) ::CountMenuItems(menu
), title
, encoding
);
227 UMASetMenuItemShortcut( menu
, (SInt16
) ::CountMenuItems(menu
), entry
) ;
230 void UMAInsertMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, MenuItemIndex item
, wxAcceleratorEntry
*entry
)
232 InsertMenuItemTextWithCFString( menu
,
233 CFSTR("A"), item
, 0, 0);
235 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
236 ChangeMenuItemAttributes( menu
, item
+1, kMenuItemAttrIgnoreMeta
, 0 ) ;
237 UMASetMenuItemText(menu
, item
+1 , title
, encoding
);
238 UMASetMenuItemShortcut( menu
, item
+1 , entry
) ;
241 static OSStatus
UMAGetHelpMenu(
242 MenuRef
* outHelpMenu
,
243 MenuItemIndex
* outFirstCustomItemIndex
,
244 bool allowHelpMenuCreation
);
246 static OSStatus
UMAGetHelpMenu(
247 MenuRef
* outHelpMenu
,
248 MenuItemIndex
* outFirstCustomItemIndex
,
249 bool allowHelpMenuCreation
)
251 static bool s_createdHelpMenu
= false ;
253 if ( !s_createdHelpMenu
&& !allowHelpMenuCreation
)
258 OSStatus status
= HMGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
) ;
259 s_createdHelpMenu
= ( status
== noErr
) ;
263 OSStatus
UMAGetHelpMenu(
264 MenuRef
* outHelpMenu
,
265 MenuItemIndex
* outFirstCustomItemIndex
)
267 return UMAGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
, true );
270 OSStatus
UMAGetHelpMenuDontCreate(
271 MenuRef
* outHelpMenu
,
272 MenuItemIndex
* outFirstCustomItemIndex
)
274 return UMAGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
, false );