]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/uma.cpp
a89ca35d15d6a925c982f14d19959a1cf2dbf56b
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
;
99 if (entry
->GetFlags() & wxACCEL_RAW_CTRL
)
100 modifiers
|= kMenuControlModifier
;
103 SInt16 macKey
= key
;
104 if ( key
>= WXK_F1
&& key
<= WXK_F15
)
106 if ( !explicitCommandKey
)
107 modifiers
|= kMenuNoCommandModifier
;
109 // for some reasons this must be 0 right now
110 // everything else leads to just the first function key item
111 // to be selected. Thanks to Ryan Wilcox for finding out.
113 glyph
= kMenuF1Glyph
+ ( key
- WXK_F1
) ;
114 if ( key
>= WXK_F13
)
122 macKey
= kBackspaceCharCode
;
123 glyph
= kMenuDeleteLeftGlyph
;
127 macKey
= kTabCharCode
;
128 glyph
= kMenuTabRightGlyph
;
131 case kEnterCharCode
:
132 macKey
= kEnterCharCode
;
133 glyph
= kMenuEnterGlyph
;
137 macKey
= kReturnCharCode
;
138 glyph
= kMenuReturnGlyph
;
142 macKey
= kEscapeCharCode
;
143 glyph
= kMenuEscapeGlyph
;
148 glyph
= kMenuSpaceGlyph
;
152 macKey
= kDeleteCharCode
;
153 glyph
= kMenuDeleteRightGlyph
;
157 macKey
= kClearCharCode
;
158 glyph
= kMenuClearGlyph
;
162 macKey
= kPageUpCharCode
;
163 glyph
= kMenuPageUpGlyph
;
167 macKey
= kPageDownCharCode
;
168 glyph
= kMenuPageDownGlyph
;
172 macKey
= kLeftArrowCharCode
;
173 glyph
= kMenuLeftArrowGlyph
;
177 macKey
= kUpArrowCharCode
;
178 glyph
= kMenuUpArrowGlyph
;
182 macKey
= kRightArrowCharCode
;
183 glyph
= kMenuRightArrowGlyph
;
187 macKey
= kDownArrowCharCode
;
188 glyph
= kMenuDownArrowGlyph
;
192 macKey
= kHomeCharCode
;
193 glyph
= kMenuNorthwestArrowGlyph
;
197 macKey
= kEndCharCode
;
198 glyph
= kMenuSoutheastArrowGlyph
;
201 macKey
= toupper( key
) ;
205 // we now allow non command key shortcuts
206 // remove in case this gives problems
207 if ( !explicitCommandKey
)
208 modifiers
|= kMenuNoCommandModifier
;
211 // 1d and 1e have special meaning to SetItemCmd, so
212 // do not use for these character codes.
213 if (key
!= WXK_UP
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_LEFT
)
214 SetItemCmd( menu
, item
, macKey
);
216 SetMenuItemModifiers( menu
, item
, modifiers
) ;
219 SetMenuItemKeyGlyph( menu
, item
, glyph
) ;
223 void UMAAppendMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, wxAcceleratorEntry
*entry
)
225 AppendMenuItemTextWithCFString( menu
,
226 CFSTR("A"), 0, 0,NULL
);
227 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
228 ChangeMenuItemAttributes( menu
, ::CountMenuItems(menu
), kMenuItemAttrIgnoreMeta
, 0 ) ;
229 UMASetMenuItemText(menu
, (SInt16
) ::CountMenuItems(menu
), title
, encoding
);
230 UMASetMenuItemShortcut( menu
, (SInt16
) ::CountMenuItems(menu
), entry
) ;
233 void UMAInsertMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, MenuItemIndex item
, wxAcceleratorEntry
*entry
)
235 InsertMenuItemTextWithCFString( menu
,
236 CFSTR("A"), item
, 0, 0);
238 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
239 ChangeMenuItemAttributes( menu
, item
+1, kMenuItemAttrIgnoreMeta
, 0 ) ;
240 UMASetMenuItemText(menu
, item
+1 , title
, encoding
);
241 UMASetMenuItemShortcut( menu
, item
+1 , entry
) ;
244 static OSStatus
UMAGetHelpMenu(
245 MenuRef
* outHelpMenu
,
246 MenuItemIndex
* outFirstCustomItemIndex
,
247 bool allowHelpMenuCreation
);
249 static OSStatus
UMAGetHelpMenu(
250 MenuRef
* outHelpMenu
,
251 MenuItemIndex
* outFirstCustomItemIndex
,
252 bool allowHelpMenuCreation
)
254 static bool s_createdHelpMenu
= false ;
256 if ( !s_createdHelpMenu
&& !allowHelpMenuCreation
)
261 OSStatus status
= HMGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
) ;
262 s_createdHelpMenu
= ( status
== noErr
) ;
266 OSStatus
UMAGetHelpMenu(
267 MenuRef
* outHelpMenu
,
268 MenuItemIndex
* outFirstCustomItemIndex
)
270 return UMAGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
, true );
273 OSStatus
UMAGetHelpMenuDontCreate(
274 MenuRef
* outHelpMenu
,
275 MenuItemIndex
* outFirstCustomItemIndex
)
277 return UMAGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
, false );