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