]>
Commit | Line | Data |
---|---|---|
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 | |
f5c6eb5c | 21 | #ifndef __DARWIN__ |
768c6e8b | 22 | # include <MacTextEditor.h> |
a3d3d3bf GD |
23 | # include <Navigation.h> |
24 | # if defined(TARGET_CARBON) | |
25 | # if PM_USE_SESSION_APIS | |
26 | # include <PMCore.h> | |
27 | # endif | |
28 | # include <PMApplication.h> | |
66a09d47 SC |
29 | # else |
30 | # include <Printing.h> | |
a3d3d3bf | 31 | # endif |
03e11df5 | 32 | #endif |
5b781a67 | 33 | |
9c3c5849 | 34 | #ifndef __DARWIN__ |
1832043f | 35 | # include <Scrap.h> |
9c3c5849 | 36 | #endif |
9c3c5849 | 37 | |
72055702 SC |
38 | // since we have decided that we only support 8.6 upwards we are |
39 | // checking for these minimum requirements in the startup code of | |
77ffb593 | 40 | // the application so all wxWidgets code can safely assume that appearance 1.1 |
58751a86 | 41 | // windows manager, control manager, navigation services etc. are |
72055702 | 42 | // present |
e7b596fb | 43 | |
e6c3d3e6 | 44 | static SInt32 sUMASystemVersion = 0 ; |
0e5a4d20 | 45 | |
2b5f62a0 | 46 | long UMAGetSystemVersion() { return sUMASystemVersion ; } |
72e7876b | 47 | |
5b781a67 SC |
48 | void UMACleanupToolbox() |
49 | { | |
5b781a67 | 50 | } |
98af9c73 | 51 | |
89954433 VZ |
52 | void UMAInitToolbox( UInt16 WXUNUSED(inMoreMastersCalls), |
53 | bool WXUNUSED(isEmbedded) ) | |
72e7876b | 54 | { |
e128397f DS |
55 | ::InitCursor(); |
56 | ||
2b5f62a0 | 57 | if ( Gestalt(gestaltSystemVersion, &sUMASystemVersion) != noErr) |
e40298d5 | 58 | sUMASystemVersion = 0x0000 ; |
58751a86 | 59 | |
e6c3d3e6 | 60 | #ifndef __LP64__ |
564bf1ea | 61 | { |
98af9c73 DS |
62 | FontFamilyID fontId ; |
63 | Str255 fontName ; | |
64 | SInt16 fontSize ; | |
65 | Style fontStyle ; | |
4a6a2972 | 66 | |
98af9c73 DS |
67 | GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; |
68 | GetFNum( fontName, &fontId ); | |
4a6a2972 | 69 | |
98af9c73 DS |
70 | TXNMacOSPreferredFontDescription fontDescriptions[] = |
71 | { | |
72 | { fontId , (fontSize << 16) , kTXNDefaultFontStyle, kTXNSystemDefaultEncoding } | |
73 | } ; | |
74 | int noOfFontDescriptions = sizeof( fontDescriptions ) / sizeof(TXNMacOSPreferredFontDescription) ; | |
75 | ||
76 | OptionBits options = 0 ; | |
f8eebb95 | 77 | |
98af9c73 DS |
78 | if ( UMAGetSystemVersion() < 0x1000 ) |
79 | options |= kTXNAlwaysUseQuickDrawTextMask ; | |
ded4fa5b | 80 | |
98af9c73 DS |
81 | TXNInitTextension( fontDescriptions, noOfFontDescriptions, options ); |
82 | } | |
e6c3d3e6 | 83 | #endif |
66a09d47 | 84 | |
98af9c73 | 85 | UMASetSystemIsInitialized( true ); |
72e7876b SC |
86 | } |
87 | ||
88 | // process manager | |
58751a86 | 89 | long UMAGetProcessMode() |
72e7876b | 90 | { |
58751a86 | 91 | OSErr err ; |
e40298d5 JS |
92 | ProcessInfoRec processinfo; |
93 | ProcessSerialNumber procno ; | |
58751a86 | 94 | |
77eddfb7 | 95 | procno.highLongOfPSN = 0 ; |
e40298d5 JS |
96 | procno.lowLongOfPSN = kCurrentProcess ; |
97 | processinfo.processInfoLength = sizeof(ProcessInfoRec); | |
98 | processinfo.processName = NULL; | |
e6c3d3e6 | 99 | #ifndef __LP64__ |
e40298d5 | 100 | processinfo.processAppSpec = NULL; |
e6c3d3e6 | 101 | #endif |
72e7876b | 102 | |
e40298d5 JS |
103 | err = ::GetProcessInformation( &procno , &processinfo ) ; |
104 | wxASSERT( err == noErr ) ; | |
98af9c73 | 105 | |
e40298d5 | 106 | return processinfo.processMode ; |
72e7876b SC |
107 | } |
108 | ||
58751a86 | 109 | bool UMAGetProcessModeDoesActivateOnFGSwitch() |
72e7876b | 110 | { |
e40298d5 | 111 | return UMAGetProcessMode() & modeDoesActivateOnFGSwitch ; |
72e7876b SC |
112 | } |
113 | ||
114 | // menu manager | |
115 | ||
908d407c | 116 | MenuRef UMANewMenu( SInt16 id , const wxString& title , wxFontEncoding encoding ) |
72e7876b | 117 | { |
e40298d5 JS |
118 | wxString str = wxStripMenuCodes( title ) ; |
119 | MenuRef menu ; | |
98af9c73 | 120 | |
bf918b97 | 121 | #if TARGET_CARBON |
e40298d5 | 122 | CreateNewMenu( id , 0 , &menu ) ; |
908d407c | 123 | SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding ) ) ; |
bf918b97 | 124 | #else |
e40298d5 JS |
125 | Str255 ptitle ; |
126 | wxMacStringToPascal( str , ptitle ) ; | |
127 | menu = ::NewMenu( id , ptitle ) ; | |
bf918b97 | 128 | #endif |
98af9c73 | 129 | |
e40298d5 | 130 | return menu ; |
bf918b97 | 131 | } |
72e7876b | 132 | |
98af9c73 | 133 | void UMASetMenuTitle( MenuRef menu , const wxString& title , wxFontEncoding encoding ) |
bf918b97 | 134 | { |
e40298d5 | 135 | wxString str = wxStripMenuCodes( title ) ; |
98af9c73 | 136 | |
bf918b97 | 137 | #if TARGET_CARBON |
908d407c | 138 | SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding) ) ; |
98af9c73 | 139 | |
72e7876b | 140 | #else |
e40298d5 JS |
141 | Str255 ptitle ; |
142 | wxMacStringToPascal( str , ptitle ) ; | |
143 | SetMenuTitle( menu , ptitle ) ; | |
bf918b97 | 144 | #endif |
72e7876b SC |
145 | } |
146 | ||
98af9c73 | 147 | void UMASetMenuItemText( MenuRef menu, MenuItemIndex item, const wxString& title, wxFontEncoding encoding ) |
72e7876b | 148 | { |
43524b15 DS |
149 | // we don't strip the accels here anymore, must be done before |
150 | wxString str = title ; | |
98af9c73 | 151 | |
bf918b97 | 152 | #if TARGET_CARBON |
908d407c | 153 | SetMenuItemTextWithCFString( menu , item , wxMacCFStringHolder(str , encoding) ) ; |
98af9c73 | 154 | |
bf918b97 | 155 | #else |
e40298d5 JS |
156 | Str255 ptitle ; |
157 | wxMacStringToPascal( str , ptitle ) ; | |
158 | SetMenuItemText( menu , item , ptitle ) ; | |
bf918b97 | 159 | #endif |
72e7876b SC |
160 | } |
161 | ||
bf918b97 | 162 | UInt32 UMAMenuEvent( EventRecord *inEvent ) |
72e7876b | 163 | { |
98af9c73 | 164 | return MenuEvent( inEvent ) ; |
72e7876b SC |
165 | } |
166 | ||
58751a86 | 167 | void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem , bool enable) |
72e7876b | 168 | { |
e40298d5 JS |
169 | if ( enable ) |
170 | EnableMenuItem( inMenu , inItem ) ; | |
171 | else | |
172 | DisableMenuItem( inMenu , inItem ) ; | |
72e7876b | 173 | } |
2f1ae414 | 174 | |
908d407c | 175 | void UMAAppendSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , SInt16 id ) |
2f1ae414 | 176 | { |
e6c3d3e6 SC |
177 | AppendMenuItemTextWithCFString( menu, |
178 | CFSTR("A"), 0, 0,NULL); | |
98af9c73 | 179 | UMASetMenuItemText( menu, (SInt16) ::CountMenuItems(menu), title , encoding ); |
e40298d5 | 180 | SetMenuItemHierarchicalID( menu , CountMenuItems( menu ) , id ) ; |
2f1ae414 SC |
181 | } |
182 | ||
908d407c | 183 | void UMAInsertSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , SInt16 id ) |
2f1ae414 | 184 | { |
e6c3d3e6 SC |
185 | InsertMenuItemTextWithCFString( menu, |
186 | CFSTR("A"), item, 0, 0); | |
187 | ||
98af9c73 | 188 | UMASetMenuItemText( menu, item+1, title , encoding ); |
4da39c96 | 189 | SetMenuItemHierarchicalID( menu , item+1 , id ) ; |
2f1ae414 SC |
190 | } |
191 | ||
bf918b97 | 192 | void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEntry *entry ) |
2f1ae414 | 193 | { |
e40298d5 JS |
194 | if ( !entry ) |
195 | return ; | |
58751a86 | 196 | |
e40298d5 JS |
197 | UInt8 modifiers = 0 ; |
198 | SInt16 key = entry->GetKeyCode() ; | |
199 | if ( key ) | |
200 | { | |
98af9c73 | 201 | bool explicitCommandKey = (entry->GetFlags() & wxACCEL_CTRL); |
e40298d5 | 202 | |
98af9c73 | 203 | if (entry->GetFlags() & wxACCEL_ALT) |
e40298d5 | 204 | modifiers |= kMenuOptionModifier ; |
e40298d5 | 205 | |
58751a86 | 206 | if (entry->GetFlags() & wxACCEL_SHIFT) |
e40298d5 | 207 | modifiers |= kMenuShiftModifier ; |
e40298d5 JS |
208 | |
209 | SInt16 glyph = 0 ; | |
210 | SInt16 macKey = key ; | |
211 | if ( key >= WXK_F1 && key <= WXK_F15 ) | |
212 | { | |
98af9c73 DS |
213 | if ( !explicitCommandKey ) |
214 | modifiers |= kMenuNoCommandModifier ; | |
215 | ||
a5c1f8ca SC |
216 | // for some reasons this must be 0 right now |
217 | // everything else leads to just the first function key item | |
218 | // to be selected. Thanks to Ryan Wilcox for finding out. | |
2dbc444a | 219 | macKey = 0 ; |
e40298d5 JS |
220 | glyph = kMenuF1Glyph + ( key - WXK_F1 ) ; |
221 | if ( key >= WXK_F13 ) | |
222 | glyph += 13 ; | |
1bec2ee4 | 223 | } |
e40298d5 JS |
224 | else |
225 | { | |
98af9c73 | 226 | switch ( key ) |
e40298d5 JS |
227 | { |
228 | case WXK_BACK : | |
229 | macKey = kBackspaceCharCode ; | |
230 | glyph = kMenuDeleteLeftGlyph ; | |
231 | break ; | |
98af9c73 | 232 | |
e40298d5 JS |
233 | case WXK_TAB : |
234 | macKey = kTabCharCode ; | |
235 | glyph = kMenuTabRightGlyph ; | |
236 | break ; | |
98af9c73 | 237 | |
e40298d5 JS |
238 | case kEnterCharCode : |
239 | macKey = kEnterCharCode ; | |
240 | glyph = kMenuEnterGlyph ; | |
241 | break ; | |
98af9c73 | 242 | |
e40298d5 JS |
243 | case WXK_RETURN : |
244 | macKey = kReturnCharCode ; | |
245 | glyph = kMenuReturnGlyph ; | |
246 | break ; | |
98af9c73 | 247 | |
e40298d5 JS |
248 | case WXK_ESCAPE : |
249 | macKey = kEscapeCharCode ; | |
250 | glyph = kMenuEscapeGlyph ; | |
251 | break ; | |
98af9c73 | 252 | |
e40298d5 JS |
253 | case WXK_SPACE : |
254 | macKey = ' ' ; | |
255 | glyph = kMenuSpaceGlyph ; | |
256 | break ; | |
98af9c73 | 257 | |
e40298d5 JS |
258 | case WXK_DELETE : |
259 | macKey = kDeleteCharCode ; | |
260 | glyph = kMenuDeleteRightGlyph ; | |
261 | break ; | |
98af9c73 | 262 | |
e40298d5 JS |
263 | case WXK_CLEAR : |
264 | macKey = kClearCharCode ; | |
265 | glyph = kMenuClearGlyph ; | |
266 | break ; | |
98af9c73 | 267 | |
faa94f3e | 268 | case WXK_PAGEUP : |
e40298d5 JS |
269 | macKey = kPageUpCharCode ; |
270 | glyph = kMenuPageUpGlyph ; | |
271 | break ; | |
98af9c73 | 272 | |
faa94f3e | 273 | case WXK_PAGEDOWN : |
e40298d5 JS |
274 | macKey = kPageDownCharCode ; |
275 | glyph = kMenuPageDownGlyph ; | |
276 | break ; | |
98af9c73 | 277 | |
e40298d5 JS |
278 | case WXK_LEFT : |
279 | macKey = kLeftArrowCharCode ; | |
280 | glyph = kMenuLeftArrowGlyph ; | |
281 | break ; | |
98af9c73 | 282 | |
e40298d5 JS |
283 | case WXK_UP : |
284 | macKey = kUpArrowCharCode ; | |
285 | glyph = kMenuUpArrowGlyph ; | |
286 | break ; | |
98af9c73 | 287 | |
e40298d5 JS |
288 | case WXK_RIGHT : |
289 | macKey = kRightArrowCharCode ; | |
290 | glyph = kMenuRightArrowGlyph ; | |
291 | break ; | |
98af9c73 | 292 | |
e40298d5 JS |
293 | case WXK_DOWN : |
294 | macKey = kDownArrowCharCode ; | |
295 | glyph = kMenuDownArrowGlyph ; | |
296 | break ; | |
98af9c73 | 297 | |
4952771d JS |
298 | case WXK_HOME : |
299 | macKey = kHomeCharCode ; | |
300 | glyph = kMenuNorthwestArrowGlyph ; | |
301 | break ; | |
302 | ||
303 | case WXK_END : | |
304 | macKey = kEndCharCode ; | |
305 | glyph = kMenuSoutheastArrowGlyph ; | |
306 | break ; | |
1bec2ee4 SC |
307 | default : |
308 | macKey = toupper( key ) ; | |
309 | break ; | |
2b5f62a0 | 310 | } |
98af9c73 | 311 | |
1bec2ee4 SC |
312 | // we now allow non command key shortcuts |
313 | // remove in case this gives problems | |
314 | if ( !explicitCommandKey ) | |
315 | modifiers |= kMenuNoCommandModifier ; | |
2b5f62a0 | 316 | } |
bf918b97 | 317 | |
1a03b3e2 JS |
318 | // 1d and 1e have special meaning to SetItemCmd, so |
319 | // do not use for these character codes. | |
40cc34ec | 320 | if (key != WXK_UP && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_LEFT) |
1a03b3e2 JS |
321 | SetItemCmd( menu, item , macKey ); |
322 | ||
98af9c73 | 323 | SetMenuItemModifiers( menu, item , modifiers ) ; |
2b5f62a0 VZ |
324 | |
325 | if ( glyph ) | |
98af9c73 | 326 | SetMenuItemKeyGlyph( menu, item , glyph ) ; |
e40298d5 | 327 | } |
2b5f62a0 VZ |
328 | } |
329 | ||
908d407c | 330 | void UMAAppendMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , wxAcceleratorEntry *entry ) |
2b5f62a0 | 331 | { |
e6c3d3e6 SC |
332 | AppendMenuItemTextWithCFString( menu, |
333 | CFSTR("A"), 0, 0,NULL); | |
faa94f3e | 334 | // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise) |
a76342da | 335 | ChangeMenuItemAttributes( menu , ::CountMenuItems(menu), kMenuItemAttrIgnoreMeta , 0 ) ; |
908d407c | 336 | UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title , encoding ); |
98af9c73 | 337 | UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), entry ) ; |
2f1ae414 SC |
338 | } |
339 | ||
908d407c | 340 | void UMAInsertMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , wxAcceleratorEntry *entry ) |
2f1ae414 | 341 | { |
e6c3d3e6 SC |
342 | InsertMenuItemTextWithCFString( menu, |
343 | CFSTR("A"), item, 0, 0); | |
98af9c73 | 344 | |
faa94f3e | 345 | // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise) |
a76342da | 346 | ChangeMenuItemAttributes( menu , item+1, kMenuItemAttrIgnoreMeta , 0 ) ; |
908d407c | 347 | UMASetMenuItemText(menu, item+1 , title , encoding ); |
58751a86 | 348 | UMASetMenuItemShortcut( menu , item+1 , entry ) ; |
2f1ae414 SC |
349 | } |
350 | ||
72e7876b SC |
351 | // quickdraw |
352 | ||
7052b16d SC |
353 | #if !TARGET_CARBON |
354 | ||
2f1ae414 SC |
355 | int gPrOpenCounter = 0 ; |
356 | ||
7052b16d | 357 | OSStatus UMAPrOpen() |
2f1ae414 | 358 | { |
e40298d5 | 359 | OSErr err = noErr ; |
98af9c73 | 360 | |
e40298d5 | 361 | ++gPrOpenCounter ; |
98af9c73 | 362 | |
e40298d5 JS |
363 | if ( gPrOpenCounter == 1 ) |
364 | { | |
365 | PrOpen() ; | |
366 | err = PrError() ; | |
367 | wxASSERT( err == noErr ) ; | |
368 | } | |
98af9c73 | 369 | |
e40298d5 | 370 | return err ; |
2f1ae414 SC |
371 | } |
372 | ||
7052b16d | 373 | OSStatus UMAPrClose() |
2f1ae414 | 374 | { |
e40298d5 | 375 | OSErr err = noErr ; |
98af9c73 | 376 | |
e40298d5 | 377 | wxASSERT( gPrOpenCounter >= 1 ) ; |
98af9c73 | 378 | |
e40298d5 JS |
379 | if ( gPrOpenCounter == 1 ) |
380 | { | |
381 | PrClose() ; | |
382 | err = PrError() ; | |
383 | wxASSERT( err == noErr ) ; | |
384 | } | |
98af9c73 | 385 | |
e40298d5 | 386 | --gPrOpenCounter ; |
98af9c73 | 387 | |
e40298d5 | 388 | return err ; |
2f1ae414 SC |
389 | } |
390 | ||
98af9c73 DS |
391 | pascal QDGlobalsPtr GetQDGlobalsPtr() ; |
392 | pascal QDGlobalsPtr GetQDGlobalsPtr() | |
72e7876b | 393 | { |
e40298d5 | 394 | return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA); |
72e7876b SC |
395 | } |
396 | ||
397 | #endif | |
398 | ||
58751a86 | 399 | void UMAShowWatchCursor() |
72e7876b | 400 | { |
e6c3d3e6 | 401 | SetThemeCursor(kThemeWatchCursor); |
72e7876b SC |
402 | } |
403 | ||
98af9c73 | 404 | void UMAShowArrowCursor() |
72e7876b | 405 | { |
e6c3d3e6 | 406 | SetThemeCursor(kThemeArrowCursor); |
72e7876b SC |
407 | } |
408 | ||
409 | // window manager | |
410 | ||
98af9c73 | 411 | GrafPtr UMAGetWindowPort( WindowRef inWindowRef ) |
72e7876b | 412 | { |
e40298d5 | 413 | wxASSERT( inWindowRef != NULL ) ; |
98af9c73 | 414 | |
58751a86 RD |
415 | #if TARGET_CARBON |
416 | return (GrafPtr) GetWindowPort( inWindowRef ) ; | |
72e7876b | 417 | #else |
e40298d5 | 418 | return (GrafPtr) inWindowRef ; |
72e7876b SC |
419 | #endif |
420 | } | |
421 | ||
98af9c73 | 422 | void UMADisposeWindow( WindowRef inWindowRef ) |
72e7876b | 423 | { |
e40298d5 | 424 | wxASSERT( inWindowRef != NULL ) ; |
98af9c73 | 425 | |
e40298d5 | 426 | DisposeWindow( inWindowRef ) ; |
72e7876b SC |
427 | } |
428 | ||
98af9c73 | 429 | void UMASetWTitle( WindowRef inWindowRef , const wxString& title , wxFontEncoding encoding ) |
72e7876b | 430 | { |
03e11df5 | 431 | #if TARGET_CARBON |
908d407c | 432 | SetWindowTitleWithCFString( inWindowRef , wxMacCFStringHolder(title , encoding) ) ; |
98af9c73 | 433 | |
03e11df5 | 434 | #else |
427ff662 SC |
435 | Str255 ptitle ; |
436 | wxMacStringToPascal( title , ptitle ) ; | |
e40298d5 | 437 | SetWTitle( inWindowRef , ptitle ) ; |
427ff662 | 438 | #endif |
72e7876b | 439 | } |
03e11df5 | 440 | |
72e7876b SC |
441 | // appearance additions |
442 | ||
98af9c73 | 443 | void UMASetControlTitle( ControlRef inControl , const wxString& title , wxFontEncoding encoding ) |
427ff662 SC |
444 | { |
445 | #if TARGET_CARBON | |
908d407c | 446 | SetControlTitleWithCFString( inControl , wxMacCFStringHolder(title , encoding) ) ; |
98af9c73 | 447 | |
427ff662 SC |
448 | #else |
449 | Str255 ptitle ; | |
450 | wxMacStringToPascal( title , ptitle ) ; | |
451 | SetControlTitle( inControl , ptitle ) ; | |
452 | #endif | |
453 | } | |
454 | ||
facd6764 | 455 | void UMAActivateControl( ControlRef inControl ) |
72e7876b | 456 | { |
98af9c73 DS |
457 | #if TARGET_API_MAC_OSX |
458 | ::ActivateControl( inControl ) ; | |
459 | ||
460 | #else | |
22e751a5 SC |
461 | // we have to add the control after again to the update rgn |
462 | // otherwise updates get lost | |
e40298d5 JS |
463 | if ( !IsControlActive( inControl ) ) |
464 | { | |
fdaf613a SC |
465 | bool visible = IsControlVisible( inControl ) ; |
466 | if ( visible ) | |
e40298d5 | 467 | SetControlVisibility( inControl , false , false ) ; |
98af9c73 | 468 | |
3f4902f5 | 469 | ::ActivateControl( inControl ) ; |
98af9c73 DS |
470 | |
471 | if ( visible ) | |
472 | { | |
e40298d5 | 473 | SetControlVisibility( inControl , true , false ) ; |
98af9c73 | 474 | |
e40298d5 | 475 | Rect ctrlBounds ; |
98af9c73 | 476 | InvalWindowRect( GetControlOwner(inControl), UMAGetControlBoundsInWindowCoords(inControl, &ctrlBounds) ) ; |
fdaf613a | 477 | } |
e40298d5 | 478 | } |
faa94f3e | 479 | #endif |
72e7876b SC |
480 | } |
481 | ||
facd6764 | 482 | void UMAMoveControl( ControlRef inControl , short x , short y ) |
72e7876b | 483 | { |
98af9c73 DS |
484 | #if TARGET_API_MAC_OSX |
485 | ::MoveControl( inControl , x , y ) ; | |
486 | ||
487 | #else | |
e40298d5 | 488 | bool visible = IsControlVisible( inControl ) ; |
98af9c73 DS |
489 | if ( visible ) |
490 | { | |
e40298d5 JS |
491 | SetControlVisibility( inControl , false , false ) ; |
492 | Rect ctrlBounds ; | |
98af9c73 | 493 | InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ; |
e40298d5 | 494 | } |
98af9c73 | 495 | |
e40298d5 | 496 | ::MoveControl( inControl , x , y ) ; |
98af9c73 DS |
497 | |
498 | if ( visible ) | |
499 | { | |
e40298d5 JS |
500 | SetControlVisibility( inControl , true , false ) ; |
501 | Rect ctrlBounds ; | |
98af9c73 | 502 | InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ; |
e40298d5 | 503 | } |
facd6764 | 504 | #endif |
72e7876b SC |
505 | } |
506 | ||
facd6764 | 507 | void UMASizeControl( ControlRef inControl , short x , short y ) |
72e7876b | 508 | { |
98af9c73 DS |
509 | #if TARGET_API_MAC_OSX |
510 | ::SizeControl( inControl , x , y ) ; | |
511 | ||
512 | #else | |
e40298d5 | 513 | bool visible = IsControlVisible( inControl ) ; |
98af9c73 DS |
514 | if ( visible ) |
515 | { | |
e40298d5 JS |
516 | SetControlVisibility( inControl , false , false ) ; |
517 | Rect ctrlBounds ; | |
98af9c73 | 518 | InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ; |
58751a86 | 519 | } |
98af9c73 | 520 | |
e40298d5 | 521 | ::SizeControl( inControl , x , y ) ; |
98af9c73 DS |
522 | |
523 | if ( visible ) | |
524 | { | |
e40298d5 JS |
525 | SetControlVisibility( inControl , true , false ) ; |
526 | Rect ctrlBounds ; | |
98af9c73 | 527 | InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ; |
e40298d5 | 528 | } |
facd6764 | 529 | #endif |
72e7876b SC |
530 | } |
531 | ||
facd6764 | 532 | void UMADeactivateControl( ControlRef inControl ) |
72e7876b | 533 | { |
98af9c73 DS |
534 | #if TARGET_API_MAC_OSX |
535 | ::DeactivateControl( inControl ) ; | |
536 | ||
537 | #else | |
22e751a5 SC |
538 | // we have to add the control after again to the update rgn |
539 | // otherwise updates get lost | |
e40298d5 JS |
540 | bool visible = IsControlVisible( inControl ) ; |
541 | if ( visible ) | |
542 | SetControlVisibility( inControl , false , false ) ; | |
98af9c73 | 543 | |
e40298d5 | 544 | ::DeactivateControl( inControl ) ; |
98af9c73 DS |
545 | |
546 | if ( visible ) | |
547 | { | |
fdaf613a | 548 | SetControlVisibility( inControl , true , false ) ; |
c36f0244 | 549 | Rect ctrlBounds ; |
98af9c73 | 550 | InvalWindowRect( GetControlOwner(inControl), UMAGetControlBoundsInWindowCoords(inControl, &ctrlBounds) ) ; |
e40298d5 | 551 | } |
facd6764 | 552 | #endif |
e40298d5 | 553 | } |
98af9c73 | 554 | |
e40298d5 | 555 | // shows the control and adds the region to the update region |
98af9c73 | 556 | void UMAShowControl( ControlRef inControl ) |
e40298d5 JS |
557 | { |
558 | SetControlVisibility( inControl , true , false ) ; | |
e6c3d3e6 | 559 | HIViewSetNeedsDisplay( inControl, true ); |
72e7876b SC |
560 | } |
561 | ||
facd6764 | 562 | // hides the control and adds the region to the update region |
98af9c73 | 563 | void UMAHideControl( ControlRef inControl ) |
22e751a5 | 564 | { |
e40298d5 | 565 | SetControlVisibility( inControl , false , false ) ; |
e6c3d3e6 | 566 | HIViewSetNeedsDisplay( inControl, true ); |
22e751a5 | 567 | } |
98af9c73 | 568 | |
72e7876b | 569 | // keyboard focus |
98af9c73 DS |
570 | OSErr UMASetKeyboardFocus( WindowPtr inWindow, |
571 | ControlRef inControl, | |
572 | ControlFocusPart inPart ) | |
72e7876b | 573 | { |
e40298d5 | 574 | OSErr err = noErr; |
e6c3d3e6 | 575 | #ifndef __LP64__ |
e40298d5 | 576 | GrafPtr port ; |
72055702 | 577 | |
98af9c73 | 578 | GetPort( &port ) ; |
e40298d5 | 579 | SetPortWindowPort( inWindow ) ; |
e6c3d3e6 | 580 | #endif |
72055702 | 581 | |
e40298d5 | 582 | err = SetKeyboardFocus( inWindow , inControl , inPart ) ; |
e6c3d3e6 | 583 | #ifndef __LP64__ |
e40298d5 | 584 | SetPort( port ) ; |
e6c3d3e6 | 585 | #endif |
98af9c73 | 586 | |
e40298d5 | 587 | return err ; |
72e7876b SC |
588 | } |
589 | ||
58751a86 | 590 | bool UMAIsWindowFloating( WindowRef inWindow ) |
72e7876b | 591 | { |
e40298d5 | 592 | WindowClass cl ; |
58751a86 | 593 | |
e40298d5 JS |
594 | GetWindowClass( inWindow , &cl ) ; |
595 | return cl == kFloatingWindowClass ; | |
72e7876b SC |
596 | } |
597 | ||
58751a86 | 598 | bool UMAIsWindowModal( WindowRef inWindow ) |
72e7876b | 599 | { |
e40298d5 | 600 | WindowClass cl ; |
58751a86 | 601 | |
e40298d5 JS |
602 | GetWindowClass( inWindow , &cl ) ; |
603 | return cl < kFloatingWindowClass ; | |
72e7876b SC |
604 | } |
605 | ||
606 | // others | |
607 | ||
608 | void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate ) | |
609 | { | |
e40298d5 JS |
610 | if ( inWindowRef ) |
611 | { | |
612 | // bool isHighlighted = IsWindowHighlited( inWindowRef ) ; | |
3103e8a9 | 613 | // if ( inActivate != isHighlighted ) |
e6c3d3e6 | 614 | #ifndef __LP64__ |
e40298d5 JS |
615 | GrafPtr port ; |
616 | GetPort( &port ) ; | |
617 | SetPortWindowPort( inWindowRef ) ; | |
e6c3d3e6 | 618 | #endif |
e40298d5 | 619 | HiliteWindow( inWindowRef , inActivate ) ; |
facd6764 | 620 | ControlRef control = NULL ; |
98af9c73 | 621 | ::GetRootControl( inWindowRef , &control ) ; |
e40298d5 JS |
622 | if ( control ) |
623 | { | |
624 | if ( inActivate ) | |
625 | UMAActivateControl( control ) ; | |
626 | else | |
627 | UMADeactivateControl( control ) ; | |
58751a86 | 628 | } |
e6c3d3e6 | 629 | #ifndef __LP64__ |
e40298d5 | 630 | SetPort( port ) ; |
e6c3d3e6 | 631 | #endif |
e40298d5 | 632 | } |
72e7876b | 633 | } |
e40298d5 | 634 | |
58751a86 | 635 | OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState ) |
2f1ae414 | 636 | { |
e6c3d3e6 | 637 | #ifndef __LP64__ |
e40298d5 | 638 | return ::DrawThemePlacard( inRect , inState ) ; |
e6c3d3e6 SC |
639 | #else |
640 | return noErr; | |
641 | #endif | |
2f1ae414 | 642 | } |
72e7876b | 643 | |
2f056c85 | 644 | #if !TARGET_CARBON |
b03e4fcd | 645 | static OSStatus helpMenuStatus = noErr ; |
b03e4fcd | 646 | static MenuItemIndex firstCustomItemIndex = 0 ; |
2f056c85 | 647 | #endif |
b03e4fcd | 648 | |
4dd25308 | 649 | static OSStatus UMAGetHelpMenu( |
98af9c73 | 650 | MenuRef * outHelpMenu, |
4dd25308 VZ |
651 | MenuItemIndex * outFirstCustomItemIndex, |
652 | bool allowHelpMenuCreation); | |
653 | ||
654 | static OSStatus UMAGetHelpMenu( | |
655 | MenuRef * outHelpMenu, | |
656 | MenuItemIndex * outFirstCustomItemIndex, | |
657 | bool allowHelpMenuCreation) | |
b03e4fcd SC |
658 | { |
659 | #if TARGET_CARBON | |
4dd25308 | 660 | static bool s_createdHelpMenu = false ; |
98af9c73 | 661 | |
4dd25308 VZ |
662 | if ( !s_createdHelpMenu && !allowHelpMenuCreation ) |
663 | { | |
664 | return paramErr ; | |
665 | } | |
666 | ||
667 | OSStatus status = HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ; | |
668 | s_createdHelpMenu = ( status == noErr ) ; | |
669 | return status ; | |
b03e4fcd | 670 | #else |
4dd25308 | 671 | wxUnusedVar( allowHelpMenuCreation ) ; |
e40298d5 | 672 | MenuRef helpMenuHandle ; |
98af9c73 | 673 | |
e40298d5 JS |
674 | helpMenuStatus = HMGetHelpMenuHandle( &helpMenuHandle ) ; |
675 | if ( firstCustomItemIndex == 0 && helpMenuStatus == noErr ) | |
e40298d5 | 676 | firstCustomItemIndex = CountMenuItems( helpMenuHandle ) + 1 ; |
98af9c73 | 677 | |
e40298d5 | 678 | if ( outFirstCustomItemIndex ) |
e40298d5 | 679 | *outFirstCustomItemIndex = firstCustomItemIndex ; |
98af9c73 | 680 | |
e40298d5 | 681 | *outHelpMenu = helpMenuHandle ; |
98af9c73 | 682 | |
e40298d5 | 683 | return helpMenuStatus ; |
b03e4fcd SC |
684 | #endif |
685 | } | |
76a5e5d2 | 686 | |
4dd25308 VZ |
687 | OSStatus UMAGetHelpMenu( |
688 | MenuRef * outHelpMenu, | |
689 | MenuItemIndex * outFirstCustomItemIndex) | |
690 | { | |
691 | return UMAGetHelpMenu( outHelpMenu , outFirstCustomItemIndex , true ); | |
692 | } | |
693 | ||
694 | OSStatus UMAGetHelpMenuDontCreate( | |
695 | MenuRef * outHelpMenu, | |
696 | MenuItemIndex * outFirstCustomItemIndex) | |
697 | { | |
698 | return UMAGetHelpMenu( outHelpMenu , outFirstCustomItemIndex , false ); | |
699 | } | |
700 | ||
e6c3d3e6 SC |
701 | #ifndef __LP64__ |
702 | ||
98af9c73 | 703 | wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport ) |
76a5e5d2 | 704 | { |
e40298d5 JS |
705 | m_clip = NULL ; |
706 | Setup( newport ) ; | |
76a5e5d2 SC |
707 | } |
708 | ||
709 | wxMacPortStateHelper::wxMacPortStateHelper() | |
710 | { | |
e40298d5 | 711 | m_clip = NULL ; |
76a5e5d2 SC |
712 | } |
713 | ||
714 | void wxMacPortStateHelper::Setup( GrafPtr newport ) | |
715 | { | |
e40298d5 JS |
716 | GetPort( &m_oldPort ) ; |
717 | SetPort( newport ) ; | |
98af9c73 DS |
718 | SetOrigin(0, 0); |
719 | ||
427ff662 | 720 | wxASSERT_MSG( m_clip == NULL , wxT("Cannot call setup twice") ) ; |
e40298d5 JS |
721 | m_clip = NewRgn() ; |
722 | GetClip( m_clip ); | |
98af9c73 DS |
723 | m_textFont = GetPortTextFont( (CGrafPtr) newport ); |
724 | m_textSize = GetPortTextSize( (CGrafPtr) newport ); | |
725 | m_textStyle = GetPortTextFace( (CGrafPtr) newport ); | |
726 | m_textMode = GetPortTextMode( (CGrafPtr) newport ); | |
e40298d5 JS |
727 | GetThemeDrawingState( &m_drawingState ) ; |
728 | m_currentPort = newport ; | |
76a5e5d2 | 729 | } |
98af9c73 | 730 | |
76a5e5d2 SC |
731 | void wxMacPortStateHelper::Clear() |
732 | { | |
e40298d5 JS |
733 | if ( m_clip ) |
734 | { | |
735 | DisposeRgn( m_clip ) ; | |
736 | DisposeThemeDrawingState( m_drawingState ) ; | |
737 | m_clip = NULL ; | |
738 | } | |
76a5e5d2 SC |
739 | } |
740 | ||
741 | wxMacPortStateHelper::~wxMacPortStateHelper() | |
742 | { | |
e40298d5 JS |
743 | if ( m_clip ) |
744 | { | |
745 | SetPort( m_currentPort ) ; | |
746 | SetClip( m_clip ) ; | |
747 | DisposeRgn( m_clip ) ; | |
748 | TextFont( m_textFont ); | |
749 | TextSize( m_textSize ); | |
750 | TextFace( m_textStyle ); | |
751 | TextMode( m_textMode ); | |
752 | SetThemeDrawingState( m_drawingState , true ) ; | |
753 | SetPort( m_oldPort ) ; | |
754 | } | |
76a5e5d2 SC |
755 | } |
756 | ||
e6c3d3e6 SC |
757 | #endif |
758 | ||
9c3c5849 SC |
759 | OSStatus UMAPutScrap( Size size , OSType type , void *data ) |
760 | { | |
e40298d5 | 761 | OSStatus err = noErr ; |
98af9c73 | 762 | |
9c3c5849 SC |
763 | #if !TARGET_CARBON |
764 | err = PutScrap( size , type , data ) ; | |
765 | #else | |
766 | ScrapRef scrap; | |
98af9c73 DS |
767 | err = GetCurrentScrap( &scrap ); |
768 | if ( err == noErr ) | |
769 | err = PutScrapFlavor( scrap, type , 0, size, data ); | |
9c3c5849 | 770 | #endif |
98af9c73 | 771 | |
e40298d5 | 772 | return err ; |
9c3c5849 SC |
773 | } |
774 | ||
98af9c73 | 775 | Rect * UMAGetControlBoundsInWindowCoords( ControlRef theControl, Rect *bounds ) |
facd6764 | 776 | { |
facd6764 | 777 | GetControlBounds( theControl , bounds ) ; |
98af9c73 | 778 | |
facd6764 | 779 | #if TARGET_API_MAC_OSX |
37d0bfa8 | 780 | WindowRef tlwref = GetControlOwner( theControl ) ; |
37d0bfa8 | 781 | |
789ae0cf | 782 | wxTopLevelWindowMac* tlwwx = wxFindWinFromMacWindow( tlwref ) ; |
e779b609 | 783 | if ( tlwwx != NULL ) |
789ae0cf SC |
784 | { |
785 | ControlRef rootControl = tlwwx->GetPeer()->GetControlRef() ; | |
98af9c73 DS |
786 | HIPoint hiPoint = CGPointMake( 0 , 0 ) ; |
787 | HIViewConvertPoint( &hiPoint , HIViewGetSuperview(theControl) , rootControl ) ; | |
789ae0cf SC |
788 | OffsetRect( bounds , (short) hiPoint.x , (short) hiPoint.y ) ; |
789 | } | |
facd6764 | 790 | #endif |
98af9c73 | 791 | |
facd6764 SC |
792 | return bounds ; |
793 | } | |
794 | ||
2dbc444a RD |
795 | #endif // wxUSE_GUI |
796 | ||
797 | #if wxUSE_BASE | |
798 | ||
799 | static bool sUMASystemInitialized = false ; | |
800 | ||
801 | bool UMASystemIsInitialized() | |
802 | { | |
803 | return sUMASystemInitialized ; | |
804 | } | |
805 | ||
806 | void UMASetSystemIsInitialized(bool val) | |
807 | { | |
808 | sUMASystemInitialized = val; | |
809 | } | |
810 | ||
2dbc444a | 811 | #endif // wxUSE_BASE |