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