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