]>
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
)
85 SInt16 key
= entry
->GetKeyCode() ;
88 bool explicitCommandKey
= (entry
->GetFlags() & wxACCEL_CTRL
);
90 if (entry
->GetFlags() & wxACCEL_ALT
)
91 modifiers
|= kMenuOptionModifier
;
93 if (entry
->GetFlags() & wxACCEL_SHIFT
)
94 modifiers
|= kMenuShiftModifier
;
98 if ( key
>= WXK_F1
&& key
<= WXK_F15
)
100 if ( !explicitCommandKey
)
101 modifiers
|= kMenuNoCommandModifier
;
103 // for some reasons this must be 0 right now
104 // everything else leads to just the first function key item
105 // to be selected. Thanks to Ryan Wilcox for finding out.
107 glyph
= kMenuF1Glyph
+ ( key
- WXK_F1
) ;
108 if ( key
>= WXK_F13
)
116 macKey
= kBackspaceCharCode
;
117 glyph
= kMenuDeleteLeftGlyph
;
121 macKey
= kTabCharCode
;
122 glyph
= kMenuTabRightGlyph
;
125 case kEnterCharCode
:
126 macKey
= kEnterCharCode
;
127 glyph
= kMenuEnterGlyph
;
131 macKey
= kReturnCharCode
;
132 glyph
= kMenuReturnGlyph
;
136 macKey
= kEscapeCharCode
;
137 glyph
= kMenuEscapeGlyph
;
142 glyph
= kMenuSpaceGlyph
;
146 macKey
= kDeleteCharCode
;
147 glyph
= kMenuDeleteRightGlyph
;
151 macKey
= kClearCharCode
;
152 glyph
= kMenuClearGlyph
;
156 macKey
= kPageUpCharCode
;
157 glyph
= kMenuPageUpGlyph
;
161 macKey
= kPageDownCharCode
;
162 glyph
= kMenuPageDownGlyph
;
166 macKey
= kLeftArrowCharCode
;
167 glyph
= kMenuLeftArrowGlyph
;
171 macKey
= kUpArrowCharCode
;
172 glyph
= kMenuUpArrowGlyph
;
176 macKey
= kRightArrowCharCode
;
177 glyph
= kMenuRightArrowGlyph
;
181 macKey
= kDownArrowCharCode
;
182 glyph
= kMenuDownArrowGlyph
;
186 macKey
= kHomeCharCode
;
187 glyph
= kMenuNorthwestArrowGlyph
;
191 macKey
= kEndCharCode
;
192 glyph
= kMenuSoutheastArrowGlyph
;
195 macKey
= toupper( key
) ;
199 // we now allow non command key shortcuts
200 // remove in case this gives problems
201 if ( !explicitCommandKey
)
202 modifiers
|= kMenuNoCommandModifier
;
205 // 1d and 1e have special meaning to SetItemCmd, so
206 // do not use for these character codes.
207 if (key
!= WXK_UP
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_LEFT
)
208 SetItemCmd( menu
, item
, macKey
);
210 SetMenuItemModifiers( menu
, item
, modifiers
) ;
213 SetMenuItemKeyGlyph( menu
, item
, glyph
) ;
217 void UMAAppendMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, wxAcceleratorEntry
*entry
)
219 AppendMenuItemTextWithCFString( menu
,
220 CFSTR("A"), 0, 0,NULL
);
221 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
222 ChangeMenuItemAttributes( menu
, ::CountMenuItems(menu
), kMenuItemAttrIgnoreMeta
, 0 ) ;
223 UMASetMenuItemText(menu
, (SInt16
) ::CountMenuItems(menu
), title
, encoding
);
224 UMASetMenuItemShortcut( menu
, (SInt16
) ::CountMenuItems(menu
), entry
) ;
227 void UMAInsertMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, MenuItemIndex item
, wxAcceleratorEntry
*entry
)
229 InsertMenuItemTextWithCFString( menu
,
230 CFSTR("A"), item
, 0, 0);
232 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
233 ChangeMenuItemAttributes( menu
, item
+1, kMenuItemAttrIgnoreMeta
, 0 ) ;
234 UMASetMenuItemText(menu
, item
+1 , title
, encoding
);
235 UMASetMenuItemShortcut( menu
, item
+1 , entry
) ;
238 static OSStatus
UMAGetHelpMenu(
239 MenuRef
* outHelpMenu
,
240 MenuItemIndex
* outFirstCustomItemIndex
,
241 bool allowHelpMenuCreation
);
243 static OSStatus
UMAGetHelpMenu(
244 MenuRef
* outHelpMenu
,
245 MenuItemIndex
* outFirstCustomItemIndex
,
246 bool allowHelpMenuCreation
)
248 static bool s_createdHelpMenu
= false ;
250 if ( !s_createdHelpMenu
&& !allowHelpMenuCreation
)
255 OSStatus status
= HMGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
) ;
256 s_createdHelpMenu
= ( status
== noErr
) ;
260 OSStatus
UMAGetHelpMenu(
261 MenuRef
* outHelpMenu
,
262 MenuItemIndex
* outFirstCustomItemIndex
)
264 return UMAGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
, true );
267 OSStatus
UMAGetHelpMenuDontCreate(
268 MenuRef
* outHelpMenu
,
269 MenuItemIndex
* outFirstCustomItemIndex
)
271 return UMAGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
, false );