]>
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
7 // Copyright: (c) Stefan Csomor
8 // Licence: The wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
13 #include "wx/osx/uma.h"
17 #include "wx/toplevel.h"
20 #include "wx/osx/uma.h"
26 MenuRef
UMANewMenu( SInt16 id
, const wxString
& title
, wxFontEncoding encoding
)
28 wxString str
= wxStripMenuCodes( title
) ;
31 CreateNewMenu( id
, 0 , &menu
) ;
32 SetMenuTitleWithCFString( menu
, wxCFStringRef(str
, encoding
) ) ;
37 void UMASetMenuTitle( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
)
39 wxString str
= wxStripMenuCodes( title
) ;
41 SetMenuTitleWithCFString( menu
, wxCFStringRef(str
, encoding
) ) ;
44 void UMASetMenuItemText( MenuRef menu
, MenuItemIndex item
, const wxString
& title
, wxFontEncoding encoding
)
46 // we don't strip the accels here anymore, must be done before
47 wxString str
= title
;
49 SetMenuItemTextWithCFString( menu
, item
, wxCFStringRef(str
, encoding
) ) ;
52 void UMAEnableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
, bool enable
)
55 EnableMenuItem( inMenu
, inItem
) ;
57 DisableMenuItem( inMenu
, inItem
) ;
60 void UMAAppendSubMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, MenuRef submenu
)
62 AppendMenuItemTextWithCFString( menu
,
63 CFSTR("A"), 0, 0,NULL
);
64 UMASetMenuItemText( menu
, (SInt16
) ::CountMenuItems(menu
), title
, encoding
);
65 SetMenuItemHierarchicalMenu( menu
, CountMenuItems( menu
) , submenu
) ;
66 SetMenuTitleWithCFString(submenu
, wxCFStringRef(title
, encoding
) );
69 void UMAInsertSubMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, MenuItemIndex item
, SInt16 id
)
71 InsertMenuItemTextWithCFString( menu
,
72 CFSTR("A"), item
, 0, 0);
74 UMASetMenuItemText( menu
, item
+1, title
, encoding
);
75 SetMenuItemHierarchicalID( menu
, item
+1 , id
) ;
78 void UMASetMenuItemShortcut( MenuRef menu
, MenuItemIndex item
, wxAcceleratorEntry
*entry
)
82 SetMenuItemCommandKey(menu
, item
, false, 0);
87 SInt16 key
= entry
->GetKeyCode() ;
90 bool explicitCommandKey
= (entry
->GetFlags() & wxACCEL_CTRL
);
92 if (entry
->GetFlags() & wxACCEL_ALT
)
93 modifiers
|= kMenuOptionModifier
;
95 if (entry
->GetFlags() & wxACCEL_SHIFT
)
96 modifiers
|= kMenuShiftModifier
;
98 if (entry
->GetFlags() & wxACCEL_RAW_CTRL
)
99 modifiers
|= kMenuControlModifier
;
102 SInt16 macKey
= key
;
103 if ( key
>= WXK_F1
&& key
<= WXK_F15
)
105 if ( !explicitCommandKey
)
106 modifiers
|= kMenuNoCommandModifier
;
108 // for some reasons this must be 0 right now
109 // everything else leads to just the first function key item
110 // to be selected. Thanks to Ryan Wilcox for finding out.
112 glyph
= kMenuF1Glyph
+ ( key
- WXK_F1
) ;
113 if ( key
>= WXK_F13
)
121 macKey
= kBackspaceCharCode
;
122 glyph
= kMenuDeleteLeftGlyph
;
126 macKey
= kTabCharCode
;
127 glyph
= kMenuTabRightGlyph
;
130 case kEnterCharCode
:
131 macKey
= kEnterCharCode
;
132 glyph
= kMenuEnterGlyph
;
136 macKey
= kReturnCharCode
;
137 glyph
= kMenuReturnGlyph
;
141 macKey
= kEscapeCharCode
;
142 glyph
= kMenuEscapeGlyph
;
147 glyph
= kMenuSpaceGlyph
;
151 macKey
= kDeleteCharCode
;
152 glyph
= kMenuDeleteRightGlyph
;
156 macKey
= kClearCharCode
;
157 glyph
= kMenuClearGlyph
;
161 macKey
= kPageUpCharCode
;
162 glyph
= kMenuPageUpGlyph
;
166 macKey
= kPageDownCharCode
;
167 glyph
= kMenuPageDownGlyph
;
171 macKey
= kLeftArrowCharCode
;
172 glyph
= kMenuLeftArrowGlyph
;
176 macKey
= kUpArrowCharCode
;
177 glyph
= kMenuUpArrowGlyph
;
181 macKey
= kRightArrowCharCode
;
182 glyph
= kMenuRightArrowGlyph
;
186 macKey
= kDownArrowCharCode
;
187 glyph
= kMenuDownArrowGlyph
;
191 macKey
= kHomeCharCode
;
192 glyph
= kMenuNorthwestArrowGlyph
;
196 macKey
= kEndCharCode
;
197 glyph
= kMenuSoutheastArrowGlyph
;
200 macKey
= toupper( key
) ;
204 // we now allow non command key shortcuts
205 // remove in case this gives problems
206 if ( !explicitCommandKey
)
207 modifiers
|= kMenuNoCommandModifier
;
210 // 1d and 1e have special meaning to SetItemCmd, so
211 // do not use for these character codes.
212 if (key
!= WXK_UP
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_LEFT
)
213 SetItemCmd( menu
, item
, macKey
);
215 SetMenuItemModifiers( menu
, item
, modifiers
) ;
218 SetMenuItemKeyGlyph( menu
, item
, glyph
) ;
222 void UMAAppendMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, wxAcceleratorEntry
*entry
)
224 AppendMenuItemTextWithCFString( menu
,
225 CFSTR("A"), 0, 0,NULL
);
226 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
227 ChangeMenuItemAttributes( menu
, ::CountMenuItems(menu
), kMenuItemAttrIgnoreMeta
, 0 ) ;
228 UMASetMenuItemText(menu
, (SInt16
) ::CountMenuItems(menu
), title
, encoding
);
229 UMASetMenuItemShortcut( menu
, (SInt16
) ::CountMenuItems(menu
), entry
) ;
232 void UMAInsertMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, MenuItemIndex item
, wxAcceleratorEntry
*entry
)
234 InsertMenuItemTextWithCFString( menu
,
235 CFSTR("A"), item
, 0, 0);
237 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
238 ChangeMenuItemAttributes( menu
, item
+1, kMenuItemAttrIgnoreMeta
, 0 ) ;
239 UMASetMenuItemText(menu
, item
+1 , title
, encoding
);
240 UMASetMenuItemShortcut( menu
, item
+1 , entry
) ;
243 static OSStatus
UMAGetHelpMenu(
244 MenuRef
* outHelpMenu
,
245 MenuItemIndex
* outFirstCustomItemIndex
,
246 bool allowHelpMenuCreation
);
248 static OSStatus
UMAGetHelpMenu(
249 MenuRef
* outHelpMenu
,
250 MenuItemIndex
* outFirstCustomItemIndex
,
251 bool allowHelpMenuCreation
)
253 static bool s_createdHelpMenu
= false ;
255 if ( !s_createdHelpMenu
&& !allowHelpMenuCreation
)
260 OSStatus status
= HMGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
) ;
261 s_createdHelpMenu
= ( status
== noErr
) ;
265 OSStatus
UMAGetHelpMenu(
266 MenuRef
* outHelpMenu
,
267 MenuItemIndex
* outFirstCustomItemIndex
)
269 return UMAGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
, true );
272 OSStatus
UMAGetHelpMenuDontCreate(
273 MenuRef
* outHelpMenu
,
274 MenuItemIndex
* outFirstCustomItemIndex
)
276 return UMAGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
, false );