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/mac/uma.h"
18 #include "wx/toplevel.h"
21 #include "wx/mac/uma.h"
23 static SInt32 sUMASystemVersion
= 0 ;
25 long UMAGetSystemVersion()
27 if ( sUMASystemVersion
== 0 )
29 verify_noerr(Gestalt(gestaltSystemVersion
, &sUMASystemVersion
));
31 return sUMASystemVersion
;
34 void UMAInitToolbox( UInt16
WXUNUSED(inMoreMastersCalls
),
35 bool WXUNUSED(isEmbedded
) )
37 #if 0 // ndef __LP64__
44 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
45 GetFNum( fontName
, &fontId
);
47 TXNMacOSPreferredFontDescription fontDescriptions
[] =
49 { fontId
, (fontSize
<< 16) , kTXNDefaultFontStyle
, kTXNSystemDefaultEncoding
}
51 int noOfFontDescriptions
= sizeof( fontDescriptions
) / sizeof(TXNMacOSPreferredFontDescription
) ;
53 OptionBits options
= 0 ;
55 TXNInitTextension( fontDescriptions
, noOfFontDescriptions
, options
);
62 #if wxMAC_USE_COCOA == 0
64 MenuRef
UMANewMenu( SInt16 id
, const wxString
& title
, wxFontEncoding encoding
)
66 wxString str
= wxStripMenuCodes( title
) ;
69 CreateNewMenu( id
, 0 , &menu
) ;
70 SetMenuTitleWithCFString( menu
, wxCFStringRef(str
, encoding
) ) ;
75 void UMASetMenuTitle( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
)
77 wxString str
= wxStripMenuCodes( title
) ;
79 SetMenuTitleWithCFString( menu
, wxCFStringRef(str
, encoding
) ) ;
82 void UMASetMenuItemText( MenuRef menu
, MenuItemIndex item
, const wxString
& title
, wxFontEncoding encoding
)
84 // we don't strip the accels here anymore, must be done before
85 wxString str
= title
;
87 SetMenuItemTextWithCFString( menu
, item
, wxCFStringRef(str
, encoding
) ) ;
90 void UMAEnableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
, bool enable
)
93 EnableMenuItem( inMenu
, inItem
) ;
95 DisableMenuItem( inMenu
, inItem
) ;
98 void UMAAppendSubMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, SInt16 id
)
100 AppendMenuItemTextWithCFString( menu
,
101 CFSTR("A"), 0, 0,NULL
);
102 UMASetMenuItemText( menu
, (SInt16
) ::CountMenuItems(menu
), title
, encoding
);
103 SetMenuItemHierarchicalID( menu
, CountMenuItems( menu
) , id
) ;
106 void UMAInsertSubMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, MenuItemIndex item
, SInt16 id
)
108 InsertMenuItemTextWithCFString( menu
,
109 CFSTR("A"), item
, 0, 0);
111 UMASetMenuItemText( menu
, item
+1, title
, encoding
);
112 SetMenuItemHierarchicalID( menu
, item
+1 , id
) ;
115 void UMASetMenuItemShortcut( MenuRef menu
, MenuItemIndex item
, wxAcceleratorEntry
*entry
)
120 UInt8 modifiers
= 0 ;
121 SInt16 key
= entry
->GetKeyCode() ;
124 bool explicitCommandKey
= (entry
->GetFlags() & wxACCEL_CTRL
);
126 if (entry
->GetFlags() & wxACCEL_ALT
)
127 modifiers
|= kMenuOptionModifier
;
129 if (entry
->GetFlags() & wxACCEL_SHIFT
)
130 modifiers
|= kMenuShiftModifier
;
133 SInt16 macKey
= key
;
134 if ( key
>= WXK_F1
&& key
<= WXK_F15
)
136 if ( !explicitCommandKey
)
137 modifiers
|= kMenuNoCommandModifier
;
139 // for some reasons this must be 0 right now
140 // everything else leads to just the first function key item
141 // to be selected. Thanks to Ryan Wilcox for finding out.
143 glyph
= kMenuF1Glyph
+ ( key
- WXK_F1
) ;
144 if ( key
>= WXK_F13
)
152 macKey
= kBackspaceCharCode
;
153 glyph
= kMenuDeleteLeftGlyph
;
157 macKey
= kTabCharCode
;
158 glyph
= kMenuTabRightGlyph
;
161 case kEnterCharCode
:
162 macKey
= kEnterCharCode
;
163 glyph
= kMenuEnterGlyph
;
167 macKey
= kReturnCharCode
;
168 glyph
= kMenuReturnGlyph
;
172 macKey
= kEscapeCharCode
;
173 glyph
= kMenuEscapeGlyph
;
178 glyph
= kMenuSpaceGlyph
;
182 macKey
= kDeleteCharCode
;
183 glyph
= kMenuDeleteRightGlyph
;
187 macKey
= kClearCharCode
;
188 glyph
= kMenuClearGlyph
;
192 macKey
= kPageUpCharCode
;
193 glyph
= kMenuPageUpGlyph
;
197 macKey
= kPageDownCharCode
;
198 glyph
= kMenuPageDownGlyph
;
202 macKey
= kLeftArrowCharCode
;
203 glyph
= kMenuLeftArrowGlyph
;
207 macKey
= kUpArrowCharCode
;
208 glyph
= kMenuUpArrowGlyph
;
212 macKey
= kRightArrowCharCode
;
213 glyph
= kMenuRightArrowGlyph
;
217 macKey
= kDownArrowCharCode
;
218 glyph
= kMenuDownArrowGlyph
;
222 macKey
= kHomeCharCode
;
223 glyph
= kMenuNorthwestArrowGlyph
;
227 macKey
= kEndCharCode
;
228 glyph
= kMenuSoutheastArrowGlyph
;
231 macKey
= toupper( key
) ;
235 // we now allow non command key shortcuts
236 // remove in case this gives problems
237 if ( !explicitCommandKey
)
238 modifiers
|= kMenuNoCommandModifier
;
241 // 1d and 1e have special meaning to SetItemCmd, so
242 // do not use for these character codes.
243 if (key
!= WXK_UP
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_LEFT
)
244 SetItemCmd( menu
, item
, macKey
);
246 SetMenuItemModifiers( menu
, item
, modifiers
) ;
249 SetMenuItemKeyGlyph( menu
, item
, glyph
) ;
253 void UMAAppendMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, wxAcceleratorEntry
*entry
)
255 AppendMenuItemTextWithCFString( menu
,
256 CFSTR("A"), 0, 0,NULL
);
257 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
258 ChangeMenuItemAttributes( menu
, ::CountMenuItems(menu
), kMenuItemAttrIgnoreMeta
, 0 ) ;
259 UMASetMenuItemText(menu
, (SInt16
) ::CountMenuItems(menu
), title
, encoding
);
260 UMASetMenuItemShortcut( menu
, (SInt16
) ::CountMenuItems(menu
), entry
) ;
263 void UMAInsertMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, MenuItemIndex item
, wxAcceleratorEntry
*entry
)
265 InsertMenuItemTextWithCFString( menu
,
266 CFSTR("A"), item
, 0, 0);
268 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
269 ChangeMenuItemAttributes( menu
, item
+1, kMenuItemAttrIgnoreMeta
, 0 ) ;
270 UMASetMenuItemText(menu
, item
+1 , title
, encoding
);
271 UMASetMenuItemShortcut( menu
, item
+1 , entry
) ;
276 #if wxMAC_USE_COCOA == 0
278 static OSStatus
UMAGetHelpMenu(
279 MenuRef
* outHelpMenu
,
280 MenuItemIndex
* outFirstCustomItemIndex
,
281 bool allowHelpMenuCreation
);
283 static OSStatus
UMAGetHelpMenu(
284 MenuRef
* outHelpMenu
,
285 MenuItemIndex
* outFirstCustomItemIndex
,
286 bool allowHelpMenuCreation
)
288 static bool s_createdHelpMenu
= false ;
290 if ( !s_createdHelpMenu
&& !allowHelpMenuCreation
)
295 OSStatus status
= HMGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
) ;
296 s_createdHelpMenu
= ( status
== noErr
) ;
300 OSStatus
UMAGetHelpMenu(
301 MenuRef
* outHelpMenu
,
302 MenuItemIndex
* outFirstCustomItemIndex
)
304 return UMAGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
, true );
307 OSStatus
UMAGetHelpMenuDontCreate(
308 MenuRef
* outHelpMenu
,
309 MenuItemIndex
* outFirstCustomItemIndex
)
311 return UMAGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
, false );