]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/uma.cpp
fix wxBrush for the mac build
[wxWidgets.git] / src / mac / carbon / uma.cpp
CommitLineData
84969af7 1/////////////////////////////////////////////////////////////////////////////
faa94f3e 2// Name: src/mac/carbon/uma.cpp
84969af7
JS
3// Purpose: UMA support
4// Author: Stefan Csomor
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
65571936 9// Licence: The wxWindows licence
84969af7
JS
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878 12#include "wx/wxprec.h"
2dbc444a 13
e17206f7
VS
14#include "wx/mac/uma.h"
15
2dbc444a
RD
16#if wxUSE_GUI
17
0db43f1a 18#include "wx/toplevel.h"
5fde6fcc 19#include "wx/dc.h"
72e7876b 20
6239ee05 21#include "wx/mac/uma.h"
9c3c5849 22
e6c3d3e6 23static SInt32 sUMASystemVersion = 0 ;
0e5a4d20 24
7fc641af
SC
25long UMAGetSystemVersion()
26{
27 if ( sUMASystemVersion == 0 )
28 {
29 verify_noerr(Gestalt(gestaltSystemVersion, &sUMASystemVersion));
30 }
31 return sUMASystemVersion ;
5b781a67 32}
98af9c73 33
89954433
VZ
34void UMAInitToolbox( UInt16 WXUNUSED(inMoreMastersCalls),
35 bool WXUNUSED(isEmbedded) )
72e7876b 36{
7fc641af 37#if 0 // ndef __LP64__
564bf1ea 38 {
98af9c73
DS
39 FontFamilyID fontId ;
40 Str255 fontName ;
41 SInt16 fontSize ;
42 Style fontStyle ;
4a6a2972 43
98af9c73
DS
44 GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
45 GetFNum( fontName, &fontId );
4a6a2972 46
98af9c73
DS
47 TXNMacOSPreferredFontDescription fontDescriptions[] =
48 {
49 { fontId , (fontSize << 16) , kTXNDefaultFontStyle, kTXNSystemDefaultEncoding }
50 } ;
51 int noOfFontDescriptions = sizeof( fontDescriptions ) / sizeof(TXNMacOSPreferredFontDescription) ;
52
53 OptionBits options = 0 ;
f8eebb95 54
98af9c73
DS
55 TXNInitTextension( fontDescriptions, noOfFontDescriptions, options );
56 }
e6c3d3e6 57#endif
72e7876b
SC
58}
59
72e7876b
SC
60// menu manager
61
cd66beb3
SC
62#if wxMAC_USE_COCOA == 0
63
908d407c 64MenuRef UMANewMenu( SInt16 id , const wxString& title , wxFontEncoding encoding )
72e7876b 65{
e40298d5
JS
66 wxString str = wxStripMenuCodes( title ) ;
67 MenuRef menu ;
98af9c73 68
e40298d5 69 CreateNewMenu( id , 0 , &menu ) ;
dbe4a80c 70 SetMenuTitleWithCFString( menu , wxCFStringRef(str , encoding ) ) ;
98af9c73 71
e40298d5 72 return menu ;
bf918b97 73}
72e7876b 74
98af9c73 75void UMASetMenuTitle( MenuRef menu , const wxString& title , wxFontEncoding encoding )
bf918b97 76{
e40298d5 77 wxString str = wxStripMenuCodes( title ) ;
98af9c73 78
dbe4a80c 79 SetMenuTitleWithCFString( menu , wxCFStringRef(str , encoding) ) ;
72e7876b
SC
80}
81
98af9c73 82void UMASetMenuItemText( MenuRef menu, MenuItemIndex item, const wxString& title, wxFontEncoding encoding )
72e7876b 83{
43524b15
DS
84 // we don't strip the accels here anymore, must be done before
85 wxString str = title ;
98af9c73 86
dbe4a80c 87 SetMenuItemTextWithCFString( menu , item , wxCFStringRef(str , encoding) ) ;
72e7876b
SC
88}
89
58751a86 90void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem , bool enable)
72e7876b 91{
e40298d5
JS
92 if ( enable )
93 EnableMenuItem( inMenu , inItem ) ;
94 else
95 DisableMenuItem( inMenu , inItem ) ;
72e7876b 96}
2f1ae414 97
908d407c 98void UMAAppendSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , SInt16 id )
2f1ae414 99{
e6c3d3e6 100 AppendMenuItemTextWithCFString( menu,
31c1cbc7 101 CFSTR("A"), 0, 0,NULL);
98af9c73 102 UMASetMenuItemText( menu, (SInt16) ::CountMenuItems(menu), title , encoding );
e40298d5 103 SetMenuItemHierarchicalID( menu , CountMenuItems( menu ) , id ) ;
2f1ae414
SC
104}
105
908d407c 106void UMAInsertSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , SInt16 id )
2f1ae414 107{
e6c3d3e6 108 InsertMenuItemTextWithCFString( menu,
31c1cbc7
VZ
109 CFSTR("A"), item, 0, 0);
110
98af9c73 111 UMASetMenuItemText( menu, item+1, title , encoding );
4da39c96 112 SetMenuItemHierarchicalID( menu , item+1 , id ) ;
2f1ae414
SC
113}
114
bf918b97 115void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEntry *entry )
2f1ae414 116{
e40298d5
JS
117 if ( !entry )
118 return ;
58751a86 119
e40298d5
JS
120 UInt8 modifiers = 0 ;
121 SInt16 key = entry->GetKeyCode() ;
122 if ( key )
123 {
98af9c73 124 bool explicitCommandKey = (entry->GetFlags() & wxACCEL_CTRL);
e40298d5 125
98af9c73 126 if (entry->GetFlags() & wxACCEL_ALT)
e40298d5 127 modifiers |= kMenuOptionModifier ;
e40298d5 128
58751a86 129 if (entry->GetFlags() & wxACCEL_SHIFT)
e40298d5 130 modifiers |= kMenuShiftModifier ;
e40298d5
JS
131
132 SInt16 glyph = 0 ;
133 SInt16 macKey = key ;
134 if ( key >= WXK_F1 && key <= WXK_F15 )
135 {
98af9c73
DS
136 if ( !explicitCommandKey )
137 modifiers |= kMenuNoCommandModifier ;
138
a5c1f8ca
SC
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.
2dbc444a 142 macKey = 0 ;
e40298d5
JS
143 glyph = kMenuF1Glyph + ( key - WXK_F1 ) ;
144 if ( key >= WXK_F13 )
6239ee05 145 glyph += 12 ;
1bec2ee4 146 }
e40298d5
JS
147 else
148 {
98af9c73 149 switch ( key )
e40298d5
JS
150 {
151 case WXK_BACK :
152 macKey = kBackspaceCharCode ;
153 glyph = kMenuDeleteLeftGlyph ;
154 break ;
98af9c73 155
e40298d5
JS
156 case WXK_TAB :
157 macKey = kTabCharCode ;
158 glyph = kMenuTabRightGlyph ;
159 break ;
98af9c73 160
e40298d5
JS
161 case kEnterCharCode :
162 macKey = kEnterCharCode ;
163 glyph = kMenuEnterGlyph ;
164 break ;
98af9c73 165
e40298d5
JS
166 case WXK_RETURN :
167 macKey = kReturnCharCode ;
168 glyph = kMenuReturnGlyph ;
169 break ;
98af9c73 170
e40298d5
JS
171 case WXK_ESCAPE :
172 macKey = kEscapeCharCode ;
173 glyph = kMenuEscapeGlyph ;
174 break ;
98af9c73 175
e40298d5
JS
176 case WXK_SPACE :
177 macKey = ' ' ;
178 glyph = kMenuSpaceGlyph ;
179 break ;
98af9c73 180
e40298d5
JS
181 case WXK_DELETE :
182 macKey = kDeleteCharCode ;
183 glyph = kMenuDeleteRightGlyph ;
184 break ;
98af9c73 185
e40298d5
JS
186 case WXK_CLEAR :
187 macKey = kClearCharCode ;
188 glyph = kMenuClearGlyph ;
189 break ;
98af9c73 190
faa94f3e 191 case WXK_PAGEUP :
e40298d5
JS
192 macKey = kPageUpCharCode ;
193 glyph = kMenuPageUpGlyph ;
194 break ;
98af9c73 195
faa94f3e 196 case WXK_PAGEDOWN :
e40298d5
JS
197 macKey = kPageDownCharCode ;
198 glyph = kMenuPageDownGlyph ;
199 break ;
98af9c73 200
e40298d5
JS
201 case WXK_LEFT :
202 macKey = kLeftArrowCharCode ;
203 glyph = kMenuLeftArrowGlyph ;
204 break ;
98af9c73 205
e40298d5
JS
206 case WXK_UP :
207 macKey = kUpArrowCharCode ;
208 glyph = kMenuUpArrowGlyph ;
209 break ;
98af9c73 210
e40298d5
JS
211 case WXK_RIGHT :
212 macKey = kRightArrowCharCode ;
213 glyph = kMenuRightArrowGlyph ;
214 break ;
98af9c73 215
e40298d5
JS
216 case WXK_DOWN :
217 macKey = kDownArrowCharCode ;
218 glyph = kMenuDownArrowGlyph ;
219 break ;
98af9c73 220
4952771d
JS
221 case WXK_HOME :
222 macKey = kHomeCharCode ;
223 glyph = kMenuNorthwestArrowGlyph ;
224 break ;
225
226 case WXK_END :
227 macKey = kEndCharCode ;
228 glyph = kMenuSoutheastArrowGlyph ;
229 break ;
1bec2ee4
SC
230 default :
231 macKey = toupper( key ) ;
232 break ;
2b5f62a0 233 }
98af9c73 234
1bec2ee4
SC
235 // we now allow non command key shortcuts
236 // remove in case this gives problems
237 if ( !explicitCommandKey )
238 modifiers |= kMenuNoCommandModifier ;
2b5f62a0 239 }
bf918b97 240
1a03b3e2
JS
241 // 1d and 1e have special meaning to SetItemCmd, so
242 // do not use for these character codes.
40cc34ec 243 if (key != WXK_UP && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_LEFT)
1a03b3e2
JS
244 SetItemCmd( menu, item , macKey );
245
98af9c73 246 SetMenuItemModifiers( menu, item , modifiers ) ;
2b5f62a0
VZ
247
248 if ( glyph )
98af9c73 249 SetMenuItemKeyGlyph( menu, item , glyph ) ;
e40298d5 250 }
2b5f62a0
VZ
251}
252
908d407c 253void UMAAppendMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , wxAcceleratorEntry *entry )
2b5f62a0 254{
e6c3d3e6 255 AppendMenuItemTextWithCFString( menu,
31c1cbc7 256 CFSTR("A"), 0, 0,NULL);
faa94f3e 257 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
a76342da 258 ChangeMenuItemAttributes( menu , ::CountMenuItems(menu), kMenuItemAttrIgnoreMeta , 0 ) ;
908d407c 259 UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title , encoding );
98af9c73 260 UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), entry ) ;
2f1ae414
SC
261}
262
908d407c 263void UMAInsertMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , wxAcceleratorEntry *entry )
2f1ae414 264{
e6c3d3e6 265 InsertMenuItemTextWithCFString( menu,
31c1cbc7 266 CFSTR("A"), item, 0, 0);
98af9c73 267
faa94f3e 268 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
a76342da 269 ChangeMenuItemAttributes( menu , item+1, kMenuItemAttrIgnoreMeta , 0 ) ;
908d407c 270 UMASetMenuItemText(menu, item+1 , title , encoding );
58751a86 271 UMASetMenuItemShortcut( menu , item+1 , entry ) ;
2f1ae414
SC
272}
273
cd66beb3
SC
274#endif
275
276#if wxMAC_USE_COCOA == 0
277
cd66beb3
SC
278static OSStatus UMAGetHelpMenu(
279 MenuRef * outHelpMenu,
280 MenuItemIndex * outFirstCustomItemIndex,
281 bool allowHelpMenuCreation);
282
283static OSStatus UMAGetHelpMenu(
284 MenuRef * outHelpMenu,
285 MenuItemIndex * outFirstCustomItemIndex,
286 bool allowHelpMenuCreation)
287{
288 static bool s_createdHelpMenu = false ;
289
290 if ( !s_createdHelpMenu && !allowHelpMenuCreation )
291 {
292 return paramErr ;
293 }
294
295 OSStatus status = HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ;
296 s_createdHelpMenu = ( status == noErr ) ;
297 return status ;
298}
299
300OSStatus UMAGetHelpMenu(
301 MenuRef * outHelpMenu,
302 MenuItemIndex * outFirstCustomItemIndex)
303{
304 return UMAGetHelpMenu( outHelpMenu , outFirstCustomItemIndex , true );
305}
306
307OSStatus UMAGetHelpMenuDontCreate(
308 MenuRef * outHelpMenu,
309 MenuItemIndex * outFirstCustomItemIndex)
310{
311 return UMAGetHelpMenu( outHelpMenu , outFirstCustomItemIndex , false );
312}
313
314#endif
315
2dbc444a 316#endif // wxUSE_GUI