]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/uma.cpp
cleanup - reformat
[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{
e40298d5 245 wxString str = wxStripMenuCodes( title ) ;
98af9c73 246
bf918b97 247#if TARGET_CARBON
908d407c 248 SetMenuItemTextWithCFString( menu , item , wxMacCFStringHolder(str , encoding) ) ;
98af9c73 249
bf918b97 250#else
e40298d5
JS
251 Str255 ptitle ;
252 wxMacStringToPascal( str , ptitle ) ;
253 SetMenuItemText( menu , item , ptitle ) ;
bf918b97 254#endif
72e7876b
SC
255}
256
bf918b97 257UInt32 UMAMenuEvent( EventRecord *inEvent )
72e7876b 258{
98af9c73 259 return MenuEvent( inEvent ) ;
72e7876b
SC
260}
261
58751a86 262void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem , bool enable)
72e7876b 263{
e40298d5
JS
264 if ( enable )
265 EnableMenuItem( inMenu , inItem ) ;
266 else
267 DisableMenuItem( inMenu , inItem ) ;
72e7876b 268}
2f1ae414 269
908d407c 270void UMAAppendSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , SInt16 id )
2f1ae414 271{
98af9c73
DS
272 MacAppendMenu( menu, "\pA" );
273 UMASetMenuItemText( menu, (SInt16) ::CountMenuItems(menu), title , encoding );
e40298d5 274 SetMenuItemHierarchicalID( menu , CountMenuItems( menu ) , id ) ;
2f1ae414
SC
275}
276
908d407c 277void UMAInsertSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , SInt16 id )
2f1ae414 278{
98af9c73
DS
279 MacInsertMenuItem( menu, "\pA" , item );
280 UMASetMenuItemText( menu, item+1, title , encoding );
4da39c96 281 SetMenuItemHierarchicalID( menu , item+1 , id ) ;
2f1ae414
SC
282}
283
bf918b97 284void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEntry *entry )
2f1ae414 285{
e40298d5
JS
286 if ( !entry )
287 return ;
58751a86 288
e40298d5
JS
289 UInt8 modifiers = 0 ;
290 SInt16 key = entry->GetKeyCode() ;
291 if ( key )
292 {
98af9c73 293 bool explicitCommandKey = (entry->GetFlags() & wxACCEL_CTRL);
e40298d5 294
98af9c73 295 if (entry->GetFlags() & wxACCEL_ALT)
e40298d5 296 modifiers |= kMenuOptionModifier ;
e40298d5 297
58751a86 298 if (entry->GetFlags() & wxACCEL_SHIFT)
e40298d5 299 modifiers |= kMenuShiftModifier ;
e40298d5
JS
300
301 SInt16 glyph = 0 ;
302 SInt16 macKey = key ;
303 if ( key >= WXK_F1 && key <= WXK_F15 )
304 {
98af9c73
DS
305 if ( !explicitCommandKey )
306 modifiers |= kMenuNoCommandModifier ;
307
a5c1f8ca
SC
308 // for some reasons this must be 0 right now
309 // everything else leads to just the first function key item
310 // to be selected. Thanks to Ryan Wilcox for finding out.
2dbc444a 311 macKey = 0 ;
e40298d5
JS
312 glyph = kMenuF1Glyph + ( key - WXK_F1 ) ;
313 if ( key >= WXK_F13 )
314 glyph += 13 ;
1bec2ee4 315 }
e40298d5
JS
316 else
317 {
98af9c73 318 switch ( key )
e40298d5
JS
319 {
320 case WXK_BACK :
321 macKey = kBackspaceCharCode ;
322 glyph = kMenuDeleteLeftGlyph ;
323 break ;
98af9c73 324
e40298d5
JS
325 case WXK_TAB :
326 macKey = kTabCharCode ;
327 glyph = kMenuTabRightGlyph ;
328 break ;
98af9c73 329
e40298d5
JS
330 case kEnterCharCode :
331 macKey = kEnterCharCode ;
332 glyph = kMenuEnterGlyph ;
333 break ;
98af9c73 334
e40298d5
JS
335 case WXK_RETURN :
336 macKey = kReturnCharCode ;
337 glyph = kMenuReturnGlyph ;
338 break ;
98af9c73 339
e40298d5
JS
340 case WXK_ESCAPE :
341 macKey = kEscapeCharCode ;
342 glyph = kMenuEscapeGlyph ;
343 break ;
98af9c73 344
e40298d5
JS
345 case WXK_SPACE :
346 macKey = ' ' ;
347 glyph = kMenuSpaceGlyph ;
348 break ;
98af9c73 349
e40298d5
JS
350 case WXK_DELETE :
351 macKey = kDeleteCharCode ;
352 glyph = kMenuDeleteRightGlyph ;
353 break ;
98af9c73 354
e40298d5
JS
355 case WXK_CLEAR :
356 macKey = kClearCharCode ;
357 glyph = kMenuClearGlyph ;
358 break ;
98af9c73 359
e40298d5
JS
360 case WXK_PRIOR : // PAGE UP
361 macKey = kPageUpCharCode ;
362 glyph = kMenuPageUpGlyph ;
363 break ;
98af9c73 364
e40298d5
JS
365 case WXK_NEXT :
366 macKey = kPageDownCharCode ;
367 glyph = kMenuPageDownGlyph ;
368 break ;
98af9c73 369
e40298d5
JS
370 case WXK_LEFT :
371 macKey = kLeftArrowCharCode ;
372 glyph = kMenuLeftArrowGlyph ;
373 break ;
98af9c73 374
e40298d5
JS
375 case WXK_UP :
376 macKey = kUpArrowCharCode ;
377 glyph = kMenuUpArrowGlyph ;
378 break ;
98af9c73 379
e40298d5
JS
380 case WXK_RIGHT :
381 macKey = kRightArrowCharCode ;
382 glyph = kMenuRightArrowGlyph ;
383 break ;
98af9c73 384
e40298d5
JS
385 case WXK_DOWN :
386 macKey = kDownArrowCharCode ;
387 glyph = kMenuDownArrowGlyph ;
388 break ;
98af9c73 389
1bec2ee4
SC
390 default :
391 macKey = toupper( key ) ;
392 break ;
2b5f62a0 393 }
98af9c73 394
1bec2ee4
SC
395 // we now allow non command key shortcuts
396 // remove in case this gives problems
397 if ( !explicitCommandKey )
398 modifiers |= kMenuNoCommandModifier ;
2b5f62a0 399 }
bf918b97 400
1a03b3e2
JS
401 // 1d and 1e have special meaning to SetItemCmd, so
402 // do not use for these character codes.
403 if (key != WXK_UP && key != WXK_RIGHT)
404 SetItemCmd( menu, item , macKey );
405
98af9c73 406 SetMenuItemModifiers( menu, item , modifiers ) ;
2b5f62a0
VZ
407
408 if ( glyph )
98af9c73 409 SetMenuItemKeyGlyph( menu, item , glyph ) ;
e40298d5 410 }
2b5f62a0
VZ
411}
412
908d407c 413void UMAAppendMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , wxAcceleratorEntry *entry )
2b5f62a0 414{
e40298d5 415 MacAppendMenu(menu, "\pA");
98af9c73 416
a76342da
SC
417 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
418 ChangeMenuItemAttributes( menu , ::CountMenuItems(menu), kMenuItemAttrIgnoreMeta , 0 ) ;
908d407c 419 UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title , encoding );
98af9c73 420 UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), entry ) ;
2f1ae414
SC
421}
422
908d407c 423void UMAInsertMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , wxAcceleratorEntry *entry )
2f1ae414 424{
58751a86 425 MacInsertMenuItem( menu , "\pA" , item) ;
98af9c73 426
a76342da
SC
427 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
428 ChangeMenuItemAttributes( menu , item+1, kMenuItemAttrIgnoreMeta , 0 ) ;
908d407c 429 UMASetMenuItemText(menu, item+1 , title , encoding );
58751a86 430 UMASetMenuItemShortcut( menu , item+1 , entry ) ;
2f1ae414
SC
431}
432
72e7876b
SC
433// quickdraw
434
7052b16d
SC
435#if !TARGET_CARBON
436
2f1ae414
SC
437int gPrOpenCounter = 0 ;
438
7052b16d 439OSStatus UMAPrOpen()
2f1ae414 440{
e40298d5 441 OSErr err = noErr ;
98af9c73 442
e40298d5 443 ++gPrOpenCounter ;
98af9c73 444
e40298d5
JS
445 if ( gPrOpenCounter == 1 )
446 {
447 PrOpen() ;
448 err = PrError() ;
449 wxASSERT( err == noErr ) ;
450 }
98af9c73 451
e40298d5 452 return err ;
2f1ae414
SC
453}
454
7052b16d 455OSStatus UMAPrClose()
2f1ae414 456{
e40298d5 457 OSErr err = noErr ;
98af9c73 458
e40298d5 459 wxASSERT( gPrOpenCounter >= 1 ) ;
98af9c73 460
e40298d5
JS
461 if ( gPrOpenCounter == 1 )
462 {
463 PrClose() ;
464 err = PrError() ;
465 wxASSERT( err == noErr ) ;
466 }
98af9c73 467
e40298d5 468 --gPrOpenCounter ;
98af9c73 469
e40298d5 470 return err ;
2f1ae414
SC
471}
472
98af9c73
DS
473pascal QDGlobalsPtr GetQDGlobalsPtr() ;
474pascal QDGlobalsPtr GetQDGlobalsPtr()
72e7876b 475{
e40298d5 476 return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA);
72e7876b
SC
477}
478
479#endif
480
58751a86 481void UMAShowWatchCursor()
72e7876b 482{
e40298d5 483 OSErr err = noErr;
72e7876b 484
98af9c73 485 CursHandle watchFob = GetCursor(watchCursor);
72e7876b 486
98af9c73
DS
487 if (watchFob == NULL)
488 {
e40298d5 489 err = nilHandleErr;
98af9c73 490 }
e40298d5
JS
491 else
492 {
98af9c73 493#if TARGET_CARBON
e40298d5 494// Cursor preservedArrow;
98af9c73
DS
495// GetQDGlobalsArrow(&preservedArrow);
496// SetQDGlobalsArrow(*watchFob);
497// InitCursor();
498// SetQDGlobalsArrow(&preservedArrow);
499 SetCursor(*watchFob);
500#else
501 SetCursor(*watchFob);
502#endif
e40298d5 503 }
72e7876b
SC
504}
505
98af9c73 506void UMAShowArrowCursor()
72e7876b
SC
507{
508#if TARGET_CARBON
e40298d5 509 Cursor arrow;
98af9c73 510 SetCursor( GetQDGlobalsArrow(&arrow) );
72e7876b 511#else
e40298d5 512 SetCursor (&(qd.arrow));
72e7876b
SC
513#endif
514}
515
516// window manager
517
98af9c73 518GrafPtr UMAGetWindowPort( WindowRef inWindowRef )
72e7876b 519{
e40298d5 520 wxASSERT( inWindowRef != NULL ) ;
98af9c73 521
58751a86
RD
522#if TARGET_CARBON
523 return (GrafPtr) GetWindowPort( inWindowRef ) ;
72e7876b 524#else
e40298d5 525 return (GrafPtr) inWindowRef ;
72e7876b
SC
526#endif
527}
528
98af9c73 529void UMADisposeWindow( WindowRef inWindowRef )
72e7876b 530{
e40298d5 531 wxASSERT( inWindowRef != NULL ) ;
98af9c73 532
e40298d5 533 DisposeWindow( inWindowRef ) ;
72e7876b
SC
534}
535
98af9c73 536void UMASetWTitle( WindowRef inWindowRef , const wxString& title , wxFontEncoding encoding )
72e7876b 537{
03e11df5 538#if TARGET_CARBON
908d407c 539 SetWindowTitleWithCFString( inWindowRef , wxMacCFStringHolder(title , encoding) ) ;
98af9c73 540
03e11df5 541#else
427ff662
SC
542 Str255 ptitle ;
543 wxMacStringToPascal( title , ptitle ) ;
e40298d5 544 SetWTitle( inWindowRef , ptitle ) ;
427ff662 545#endif
72e7876b 546}
03e11df5 547
72e7876b
SC
548// appearance additions
549
98af9c73 550void UMASetControlTitle( ControlRef inControl , const wxString& title , wxFontEncoding encoding )
427ff662
SC
551{
552#if TARGET_CARBON
908d407c 553 SetControlTitleWithCFString( inControl , wxMacCFStringHolder(title , encoding) ) ;
98af9c73 554
427ff662
SC
555#else
556 Str255 ptitle ;
557 wxMacStringToPascal( title , ptitle ) ;
558 SetControlTitle( inControl , ptitle ) ;
559#endif
560}
561
facd6764 562void UMAActivateControl( ControlRef inControl )
72e7876b 563{
98af9c73
DS
564#if TARGET_API_MAC_OSX
565 ::ActivateControl( inControl ) ;
566
567#else
22e751a5
SC
568 // we have to add the control after again to the update rgn
569 // otherwise updates get lost
e40298d5
JS
570 if ( !IsControlActive( inControl ) )
571 {
fdaf613a
SC
572 bool visible = IsControlVisible( inControl ) ;
573 if ( visible )
e40298d5 574 SetControlVisibility( inControl , false , false ) ;
98af9c73 575
3f4902f5 576 ::ActivateControl( inControl ) ;
98af9c73
DS
577
578 if ( visible )
579 {
e40298d5 580 SetControlVisibility( inControl , true , false ) ;
98af9c73 581
e40298d5 582 Rect ctrlBounds ;
98af9c73 583 InvalWindowRect( GetControlOwner(inControl), UMAGetControlBoundsInWindowCoords(inControl, &ctrlBounds) ) ;
fdaf613a 584 }
e40298d5 585 }
facd6764 586#endif
72e7876b
SC
587}
588
facd6764 589void UMAMoveControl( ControlRef inControl , short x , short y )
72e7876b 590{
98af9c73
DS
591#if TARGET_API_MAC_OSX
592 ::MoveControl( inControl , x , y ) ;
593
594#else
e40298d5 595 bool visible = IsControlVisible( inControl ) ;
98af9c73
DS
596 if ( visible )
597 {
e40298d5
JS
598 SetControlVisibility( inControl , false , false ) ;
599 Rect ctrlBounds ;
98af9c73 600 InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ;
e40298d5 601 }
98af9c73 602
e40298d5 603 ::MoveControl( inControl , x , y ) ;
98af9c73
DS
604
605 if ( visible )
606 {
e40298d5
JS
607 SetControlVisibility( inControl , true , false ) ;
608 Rect ctrlBounds ;
98af9c73 609 InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ;
e40298d5 610 }
facd6764 611#endif
72e7876b
SC
612}
613
facd6764 614void UMASizeControl( ControlRef inControl , short x , short y )
72e7876b 615{
98af9c73
DS
616#if TARGET_API_MAC_OSX
617 ::SizeControl( inControl , x , y ) ;
618
619#else
e40298d5 620 bool visible = IsControlVisible( inControl ) ;
98af9c73
DS
621 if ( visible )
622 {
e40298d5
JS
623 SetControlVisibility( inControl , false , false ) ;
624 Rect ctrlBounds ;
98af9c73 625 InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ;
58751a86 626 }
98af9c73 627
e40298d5 628 ::SizeControl( inControl , x , y ) ;
98af9c73
DS
629
630 if ( visible )
631 {
e40298d5
JS
632 SetControlVisibility( inControl , true , false ) ;
633 Rect ctrlBounds ;
98af9c73 634 InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ;
e40298d5 635 }
facd6764 636#endif
72e7876b
SC
637}
638
facd6764 639void UMADeactivateControl( ControlRef inControl )
72e7876b 640{
98af9c73
DS
641#if TARGET_API_MAC_OSX
642 ::DeactivateControl( inControl ) ;
643
644#else
22e751a5
SC
645 // we have to add the control after again to the update rgn
646 // otherwise updates get lost
e40298d5
JS
647 bool visible = IsControlVisible( inControl ) ;
648 if ( visible )
649 SetControlVisibility( inControl , false , false ) ;
98af9c73 650
e40298d5 651 ::DeactivateControl( inControl ) ;
98af9c73
DS
652
653 if ( visible )
654 {
fdaf613a 655 SetControlVisibility( inControl , true , false ) ;
c36f0244 656 Rect ctrlBounds ;
98af9c73 657 InvalWindowRect( GetControlOwner(inControl), UMAGetControlBoundsInWindowCoords(inControl, &ctrlBounds) ) ;
e40298d5 658 }
facd6764 659#endif
e40298d5 660}
98af9c73 661
e40298d5 662// shows the control and adds the region to the update region
98af9c73 663void UMAShowControl( ControlRef inControl )
e40298d5
JS
664{
665 SetControlVisibility( inControl , true , false ) ;
666 Rect ctrlBounds ;
98af9c73 667 InvalWindowRect( GetControlOwner(inControl), UMAGetControlBoundsInWindowCoords(inControl, &ctrlBounds) ) ;
72e7876b
SC
668}
669
facd6764 670// hides the control and adds the region to the update region
98af9c73 671void UMAHideControl( ControlRef inControl )
22e751a5 672{
e40298d5
JS
673 SetControlVisibility( inControl , false , false ) ;
674 Rect ctrlBounds ;
98af9c73 675 InvalWindowRect( GetControlOwner(inControl), UMAGetControlBoundsInWindowCoords(inControl, &ctrlBounds) ) ;
22e751a5 676}
98af9c73 677
72e7876b 678// keyboard focus
98af9c73
DS
679OSErr UMASetKeyboardFocus( WindowPtr inWindow,
680 ControlRef inControl,
681 ControlFocusPart inPart )
72e7876b 682{
e40298d5
JS
683 OSErr err = noErr;
684 GrafPtr port ;
72055702 685
98af9c73 686 GetPort( &port ) ;
e40298d5 687 SetPortWindowPort( inWindow ) ;
72055702 688
e40298d5
JS
689 err = SetKeyboardFocus( inWindow , inControl , inPart ) ;
690 SetPort( port ) ;
98af9c73 691
e40298d5 692 return err ;
72e7876b
SC
693}
694
58751a86 695bool UMAIsWindowFloating( WindowRef inWindow )
72e7876b 696{
e40298d5 697 WindowClass cl ;
58751a86 698
e40298d5
JS
699 GetWindowClass( inWindow , &cl ) ;
700 return cl == kFloatingWindowClass ;
72e7876b
SC
701}
702
58751a86 703bool UMAIsWindowModal( WindowRef inWindow )
72e7876b 704{
e40298d5 705 WindowClass cl ;
58751a86 706
e40298d5
JS
707 GetWindowClass( inWindow , &cl ) ;
708 return cl < kFloatingWindowClass ;
72e7876b
SC
709}
710
711// others
712
713void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
714{
e40298d5
JS
715 if ( inWindowRef )
716 {
717// bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
3103e8a9 718// if ( inActivate != isHighlighted )
98af9c73 719
e40298d5
JS
720 GrafPtr port ;
721 GetPort( &port ) ;
722 SetPortWindowPort( inWindowRef ) ;
723 HiliteWindow( inWindowRef , inActivate ) ;
facd6764 724 ControlRef control = NULL ;
98af9c73 725 ::GetRootControl( inWindowRef , &control ) ;
e40298d5
JS
726 if ( control )
727 {
728 if ( inActivate )
729 UMAActivateControl( control ) ;
730 else
731 UMADeactivateControl( control ) ;
58751a86 732 }
98af9c73 733
e40298d5
JS
734 SetPort( port ) ;
735 }
72e7876b 736}
e40298d5 737
58751a86 738OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState )
2f1ae414 739{
e40298d5 740 return ::DrawThemePlacard( inRect , inState ) ;
2f1ae414 741}
72e7876b 742
2f056c85 743#if !TARGET_CARBON
b03e4fcd 744static OSStatus helpMenuStatus = noErr ;
b03e4fcd 745static MenuItemIndex firstCustomItemIndex = 0 ;
2f056c85 746#endif
b03e4fcd
SC
747
748OSStatus UMAGetHelpMenu(
98af9c73
DS
749 MenuRef * outHelpMenu,
750 MenuItemIndex * outFirstCustomItemIndex)
b03e4fcd
SC
751{
752#if TARGET_CARBON
e40298d5 753 return HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ;
98af9c73 754
b03e4fcd 755#else
e40298d5 756 MenuRef helpMenuHandle ;
98af9c73 757
e40298d5
JS
758 helpMenuStatus = HMGetHelpMenuHandle( &helpMenuHandle ) ;
759 if ( firstCustomItemIndex == 0 && helpMenuStatus == noErr )
e40298d5 760 firstCustomItemIndex = CountMenuItems( helpMenuHandle ) + 1 ;
98af9c73 761
e40298d5 762 if ( outFirstCustomItemIndex )
e40298d5 763 *outFirstCustomItemIndex = firstCustomItemIndex ;
98af9c73 764
e40298d5 765 *outHelpMenu = helpMenuHandle ;
98af9c73 766
e40298d5 767 return helpMenuStatus ;
b03e4fcd
SC
768#endif
769}
76a5e5d2 770
98af9c73 771wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport )
76a5e5d2 772{
e40298d5
JS
773 m_clip = NULL ;
774 Setup( newport ) ;
76a5e5d2
SC
775}
776
777wxMacPortStateHelper::wxMacPortStateHelper()
778{
e40298d5 779 m_clip = NULL ;
76a5e5d2
SC
780}
781
782void wxMacPortStateHelper::Setup( GrafPtr newport )
783{
e40298d5
JS
784 GetPort( &m_oldPort ) ;
785 SetPort( newport ) ;
98af9c73
DS
786 SetOrigin(0, 0);
787
427ff662 788 wxASSERT_MSG( m_clip == NULL , wxT("Cannot call setup twice") ) ;
e40298d5
JS
789 m_clip = NewRgn() ;
790 GetClip( m_clip );
98af9c73
DS
791 m_textFont = GetPortTextFont( (CGrafPtr) newport );
792 m_textSize = GetPortTextSize( (CGrafPtr) newport );
793 m_textStyle = GetPortTextFace( (CGrafPtr) newport );
794 m_textMode = GetPortTextMode( (CGrafPtr) newport );
e40298d5
JS
795 GetThemeDrawingState( &m_drawingState ) ;
796 m_currentPort = newport ;
76a5e5d2 797}
98af9c73 798
76a5e5d2
SC
799void wxMacPortStateHelper::Clear()
800{
e40298d5
JS
801 if ( m_clip )
802 {
803 DisposeRgn( m_clip ) ;
804 DisposeThemeDrawingState( m_drawingState ) ;
805 m_clip = NULL ;
806 }
76a5e5d2
SC
807}
808
809wxMacPortStateHelper::~wxMacPortStateHelper()
810{
e40298d5
JS
811 if ( m_clip )
812 {
813 SetPort( m_currentPort ) ;
814 SetClip( m_clip ) ;
815 DisposeRgn( m_clip ) ;
816 TextFont( m_textFont );
817 TextSize( m_textSize );
818 TextFace( m_textStyle );
819 TextMode( m_textMode );
820 SetThemeDrawingState( m_drawingState , true ) ;
821 SetPort( m_oldPort ) ;
822 }
76a5e5d2
SC
823}
824
9c3c5849
SC
825OSStatus UMAPutScrap( Size size , OSType type , void *data )
826{
e40298d5 827 OSStatus err = noErr ;
98af9c73 828
9c3c5849
SC
829#if !TARGET_CARBON
830 err = PutScrap( size , type , data ) ;
831#else
832 ScrapRef scrap;
98af9c73
DS
833 err = GetCurrentScrap( &scrap );
834 if ( err == noErr )
835 err = PutScrapFlavor( scrap, type , 0, size, data );
9c3c5849 836#endif
98af9c73 837
e40298d5 838 return err ;
9c3c5849
SC
839}
840
98af9c73 841Rect * UMAGetControlBoundsInWindowCoords( ControlRef theControl, Rect *bounds )
facd6764 842{
facd6764 843 GetControlBounds( theControl , bounds ) ;
98af9c73 844
facd6764 845#if TARGET_API_MAC_OSX
37d0bfa8 846 WindowRef tlwref = GetControlOwner( theControl ) ;
37d0bfa8 847
789ae0cf 848 wxTopLevelWindowMac* tlwwx = wxFindWinFromMacWindow( tlwref ) ;
9942b0b5 849 if ( tlwwx != NULL && tlwwx->MacUsesCompositing() )
789ae0cf
SC
850 {
851 ControlRef rootControl = tlwwx->GetPeer()->GetControlRef() ;
98af9c73
DS
852 HIPoint hiPoint = CGPointMake( 0 , 0 ) ;
853 HIViewConvertPoint( &hiPoint , HIViewGetSuperview(theControl) , rootControl ) ;
789ae0cf
SC
854 OffsetRect( bounds , (short) hiPoint.x , (short) hiPoint.y ) ;
855 }
facd6764 856#endif
98af9c73 857
facd6764
SC
858 return bounds ;
859}
860
2dbc444a
RD
861#endif // wxUSE_GUI
862
863#if wxUSE_BASE
864
865static bool sUMASystemInitialized = false ;
866
867bool UMASystemIsInitialized()
868{
869 return sUMASystemInitialized ;
870}
871
872void UMASetSystemIsInitialized(bool val)
873{
874 sUMASystemInitialized = val;
875}
876
2dbc444a 877#endif // wxUSE_BASE
98af9c73 878