]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/uma.cpp
Missing header.
[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
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
faa94f3e 361 case WXK_PAGEUP :
e40298d5
JS
362 macKey = kPageUpCharCode ;
363 glyph = kMenuPageUpGlyph ;
364 break ;
98af9c73 365
faa94f3e 366 case WXK_PAGEDOWN :
e40298d5
JS
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
4952771d
JS
391 case WXK_HOME :
392 macKey = kHomeCharCode ;
393 glyph = kMenuNorthwestArrowGlyph ;
394 break ;
395
396 case WXK_END :
397 macKey = kEndCharCode ;
398 glyph = kMenuSoutheastArrowGlyph ;
399 break ;
1bec2ee4
SC
400 default :
401 macKey = toupper( key ) ;
402 break ;
2b5f62a0 403 }
98af9c73 404
1bec2ee4
SC
405 // we now allow non command key shortcuts
406 // remove in case this gives problems
407 if ( !explicitCommandKey )
408 modifiers |= kMenuNoCommandModifier ;
2b5f62a0 409 }
bf918b97 410
1a03b3e2
JS
411 // 1d and 1e have special meaning to SetItemCmd, so
412 // do not use for these character codes.
40cc34ec 413 if (key != WXK_UP && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_LEFT)
1a03b3e2
JS
414 SetItemCmd( menu, item , macKey );
415
98af9c73 416 SetMenuItemModifiers( menu, item , modifiers ) ;
2b5f62a0
VZ
417
418 if ( glyph )
98af9c73 419 SetMenuItemKeyGlyph( menu, item , glyph ) ;
e40298d5 420 }
2b5f62a0
VZ
421}
422
908d407c 423void UMAAppendMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , wxAcceleratorEntry *entry )
2b5f62a0 424{
e40298d5 425 MacAppendMenu(menu, "\pA");
98af9c73 426
faa94f3e 427 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
a76342da 428 ChangeMenuItemAttributes( menu , ::CountMenuItems(menu), kMenuItemAttrIgnoreMeta , 0 ) ;
908d407c 429 UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title , encoding );
98af9c73 430 UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), entry ) ;
2f1ae414
SC
431}
432
908d407c 433void UMAInsertMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , wxAcceleratorEntry *entry )
2f1ae414 434{
58751a86 435 MacInsertMenuItem( menu , "\pA" , item) ;
98af9c73 436
faa94f3e 437 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
a76342da 438 ChangeMenuItemAttributes( menu , item+1, kMenuItemAttrIgnoreMeta , 0 ) ;
908d407c 439 UMASetMenuItemText(menu, item+1 , title , encoding );
58751a86 440 UMASetMenuItemShortcut( menu , item+1 , entry ) ;
2f1ae414
SC
441}
442
72e7876b
SC
443// quickdraw
444
7052b16d
SC
445#if !TARGET_CARBON
446
2f1ae414
SC
447int gPrOpenCounter = 0 ;
448
7052b16d 449OSStatus UMAPrOpen()
2f1ae414 450{
e40298d5 451 OSErr err = noErr ;
98af9c73 452
e40298d5 453 ++gPrOpenCounter ;
98af9c73 454
e40298d5
JS
455 if ( gPrOpenCounter == 1 )
456 {
457 PrOpen() ;
458 err = PrError() ;
459 wxASSERT( err == noErr ) ;
460 }
98af9c73 461
e40298d5 462 return err ;
2f1ae414
SC
463}
464
7052b16d 465OSStatus UMAPrClose()
2f1ae414 466{
e40298d5 467 OSErr err = noErr ;
98af9c73 468
e40298d5 469 wxASSERT( gPrOpenCounter >= 1 ) ;
98af9c73 470
e40298d5
JS
471 if ( gPrOpenCounter == 1 )
472 {
473 PrClose() ;
474 err = PrError() ;
475 wxASSERT( err == noErr ) ;
476 }
98af9c73 477
e40298d5 478 --gPrOpenCounter ;
98af9c73 479
e40298d5 480 return err ;
2f1ae414
SC
481}
482
98af9c73
DS
483pascal QDGlobalsPtr GetQDGlobalsPtr() ;
484pascal QDGlobalsPtr GetQDGlobalsPtr()
72e7876b 485{
e40298d5 486 return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA);
72e7876b
SC
487}
488
489#endif
490
58751a86 491void UMAShowWatchCursor()
72e7876b 492{
e40298d5 493 OSErr err = noErr;
72e7876b 494
98af9c73 495 CursHandle watchFob = GetCursor(watchCursor);
72e7876b 496
98af9c73
DS
497 if (watchFob == NULL)
498 {
e40298d5 499 err = nilHandleErr;
98af9c73 500 }
e40298d5
JS
501 else
502 {
98af9c73 503#if TARGET_CARBON
e40298d5 504// Cursor preservedArrow;
98af9c73
DS
505// GetQDGlobalsArrow(&preservedArrow);
506// SetQDGlobalsArrow(*watchFob);
507// InitCursor();
508// SetQDGlobalsArrow(&preservedArrow);
509 SetCursor(*watchFob);
510#else
511 SetCursor(*watchFob);
512#endif
e40298d5 513 }
72e7876b
SC
514}
515
98af9c73 516void UMAShowArrowCursor()
72e7876b
SC
517{
518#if TARGET_CARBON
e40298d5 519 Cursor arrow;
98af9c73 520 SetCursor( GetQDGlobalsArrow(&arrow) );
72e7876b 521#else
e40298d5 522 SetCursor (&(qd.arrow));
72e7876b
SC
523#endif
524}
525
526// window manager
527
98af9c73 528GrafPtr UMAGetWindowPort( WindowRef inWindowRef )
72e7876b 529{
e40298d5 530 wxASSERT( inWindowRef != NULL ) ;
98af9c73 531
58751a86
RD
532#if TARGET_CARBON
533 return (GrafPtr) GetWindowPort( inWindowRef ) ;
72e7876b 534#else
e40298d5 535 return (GrafPtr) inWindowRef ;
72e7876b
SC
536#endif
537}
538
98af9c73 539void UMADisposeWindow( WindowRef inWindowRef )
72e7876b 540{
e40298d5 541 wxASSERT( inWindowRef != NULL ) ;
98af9c73 542
e40298d5 543 DisposeWindow( inWindowRef ) ;
72e7876b
SC
544}
545
98af9c73 546void UMASetWTitle( WindowRef inWindowRef , const wxString& title , wxFontEncoding encoding )
72e7876b 547{
03e11df5 548#if TARGET_CARBON
908d407c 549 SetWindowTitleWithCFString( inWindowRef , wxMacCFStringHolder(title , encoding) ) ;
98af9c73 550
03e11df5 551#else
427ff662
SC
552 Str255 ptitle ;
553 wxMacStringToPascal( title , ptitle ) ;
e40298d5 554 SetWTitle( inWindowRef , ptitle ) ;
427ff662 555#endif
72e7876b 556}
03e11df5 557
72e7876b
SC
558// appearance additions
559
98af9c73 560void UMASetControlTitle( ControlRef inControl , const wxString& title , wxFontEncoding encoding )
427ff662
SC
561{
562#if TARGET_CARBON
908d407c 563 SetControlTitleWithCFString( inControl , wxMacCFStringHolder(title , encoding) ) ;
98af9c73 564
427ff662
SC
565#else
566 Str255 ptitle ;
567 wxMacStringToPascal( title , ptitle ) ;
568 SetControlTitle( inControl , ptitle ) ;
569#endif
570}
571
facd6764 572void UMAActivateControl( ControlRef inControl )
72e7876b 573{
98af9c73
DS
574#if TARGET_API_MAC_OSX
575 ::ActivateControl( inControl ) ;
576
577#else
22e751a5
SC
578 // we have to add the control after again to the update rgn
579 // otherwise updates get lost
e40298d5
JS
580 if ( !IsControlActive( inControl ) )
581 {
fdaf613a
SC
582 bool visible = IsControlVisible( inControl ) ;
583 if ( visible )
e40298d5 584 SetControlVisibility( inControl , false , false ) ;
98af9c73 585
3f4902f5 586 ::ActivateControl( inControl ) ;
98af9c73
DS
587
588 if ( visible )
589 {
e40298d5 590 SetControlVisibility( inControl , true , false ) ;
98af9c73 591
e40298d5 592 Rect ctrlBounds ;
98af9c73 593 InvalWindowRect( GetControlOwner(inControl), UMAGetControlBoundsInWindowCoords(inControl, &ctrlBounds) ) ;
fdaf613a 594 }
e40298d5 595 }
faa94f3e 596#endif
72e7876b
SC
597}
598
facd6764 599void UMAMoveControl( ControlRef inControl , short x , short y )
72e7876b 600{
98af9c73
DS
601#if TARGET_API_MAC_OSX
602 ::MoveControl( inControl , x , y ) ;
603
604#else
e40298d5 605 bool visible = IsControlVisible( inControl ) ;
98af9c73
DS
606 if ( visible )
607 {
e40298d5
JS
608 SetControlVisibility( inControl , false , false ) ;
609 Rect ctrlBounds ;
98af9c73 610 InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ;
e40298d5 611 }
98af9c73 612
e40298d5 613 ::MoveControl( inControl , x , y ) ;
98af9c73
DS
614
615 if ( visible )
616 {
e40298d5
JS
617 SetControlVisibility( inControl , true , false ) ;
618 Rect ctrlBounds ;
98af9c73 619 InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ;
e40298d5 620 }
facd6764 621#endif
72e7876b
SC
622}
623
facd6764 624void UMASizeControl( ControlRef inControl , short x , short y )
72e7876b 625{
98af9c73
DS
626#if TARGET_API_MAC_OSX
627 ::SizeControl( inControl , x , y ) ;
628
629#else
e40298d5 630 bool visible = IsControlVisible( inControl ) ;
98af9c73
DS
631 if ( visible )
632 {
e40298d5
JS
633 SetControlVisibility( inControl , false , false ) ;
634 Rect ctrlBounds ;
98af9c73 635 InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ;
58751a86 636 }
98af9c73 637
e40298d5 638 ::SizeControl( inControl , x , y ) ;
98af9c73
DS
639
640 if ( visible )
641 {
e40298d5
JS
642 SetControlVisibility( inControl , true , false ) ;
643 Rect ctrlBounds ;
98af9c73 644 InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ;
e40298d5 645 }
facd6764 646#endif
72e7876b
SC
647}
648
facd6764 649void UMADeactivateControl( ControlRef inControl )
72e7876b 650{
98af9c73
DS
651#if TARGET_API_MAC_OSX
652 ::DeactivateControl( inControl ) ;
653
654#else
22e751a5
SC
655 // we have to add the control after again to the update rgn
656 // otherwise updates get lost
e40298d5
JS
657 bool visible = IsControlVisible( inControl ) ;
658 if ( visible )
659 SetControlVisibility( inControl , false , false ) ;
98af9c73 660
e40298d5 661 ::DeactivateControl( inControl ) ;
98af9c73
DS
662
663 if ( visible )
664 {
fdaf613a 665 SetControlVisibility( inControl , true , false ) ;
c36f0244 666 Rect ctrlBounds ;
98af9c73 667 InvalWindowRect( GetControlOwner(inControl), UMAGetControlBoundsInWindowCoords(inControl, &ctrlBounds) ) ;
e40298d5 668 }
facd6764 669#endif
e40298d5 670}
98af9c73 671
e40298d5 672// shows the control and adds the region to the update region
98af9c73 673void UMAShowControl( ControlRef inControl )
e40298d5
JS
674{
675 SetControlVisibility( inControl , true , false ) ;
676 Rect ctrlBounds ;
98af9c73 677 InvalWindowRect( GetControlOwner(inControl), UMAGetControlBoundsInWindowCoords(inControl, &ctrlBounds) ) ;
72e7876b
SC
678}
679
facd6764 680// hides the control and adds the region to the update region
98af9c73 681void UMAHideControl( ControlRef inControl )
22e751a5 682{
e40298d5
JS
683 SetControlVisibility( inControl , false , false ) ;
684 Rect ctrlBounds ;
98af9c73 685 InvalWindowRect( GetControlOwner(inControl), UMAGetControlBoundsInWindowCoords(inControl, &ctrlBounds) ) ;
22e751a5 686}
98af9c73 687
72e7876b 688// keyboard focus
98af9c73
DS
689OSErr UMASetKeyboardFocus( WindowPtr inWindow,
690 ControlRef inControl,
691 ControlFocusPart inPart )
72e7876b 692{
e40298d5
JS
693 OSErr err = noErr;
694 GrafPtr port ;
72055702 695
98af9c73 696 GetPort( &port ) ;
e40298d5 697 SetPortWindowPort( inWindow ) ;
72055702 698
e40298d5
JS
699 err = SetKeyboardFocus( inWindow , inControl , inPart ) ;
700 SetPort( port ) ;
98af9c73 701
e40298d5 702 return err ;
72e7876b
SC
703}
704
58751a86 705bool UMAIsWindowFloating( WindowRef inWindow )
72e7876b 706{
e40298d5 707 WindowClass cl ;
58751a86 708
e40298d5
JS
709 GetWindowClass( inWindow , &cl ) ;
710 return cl == kFloatingWindowClass ;
72e7876b
SC
711}
712
58751a86 713bool UMAIsWindowModal( WindowRef inWindow )
72e7876b 714{
e40298d5 715 WindowClass cl ;
58751a86 716
e40298d5
JS
717 GetWindowClass( inWindow , &cl ) ;
718 return cl < kFloatingWindowClass ;
72e7876b
SC
719}
720
721// others
722
723void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
724{
e40298d5
JS
725 if ( inWindowRef )
726 {
727// bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
3103e8a9 728// if ( inActivate != isHighlighted )
98af9c73 729
e40298d5
JS
730 GrafPtr port ;
731 GetPort( &port ) ;
732 SetPortWindowPort( inWindowRef ) ;
733 HiliteWindow( inWindowRef , inActivate ) ;
facd6764 734 ControlRef control = NULL ;
98af9c73 735 ::GetRootControl( inWindowRef , &control ) ;
e40298d5
JS
736 if ( control )
737 {
738 if ( inActivate )
739 UMAActivateControl( control ) ;
740 else
741 UMADeactivateControl( control ) ;
58751a86 742 }
98af9c73 743
e40298d5
JS
744 SetPort( port ) ;
745 }
72e7876b 746}
e40298d5 747
58751a86 748OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState )
2f1ae414 749{
e40298d5 750 return ::DrawThemePlacard( inRect , inState ) ;
2f1ae414 751}
72e7876b 752
2f056c85 753#if !TARGET_CARBON
b03e4fcd 754static OSStatus helpMenuStatus = noErr ;
b03e4fcd 755static MenuItemIndex firstCustomItemIndex = 0 ;
2f056c85 756#endif
b03e4fcd
SC
757
758OSStatus UMAGetHelpMenu(
98af9c73
DS
759 MenuRef * outHelpMenu,
760 MenuItemIndex * outFirstCustomItemIndex)
b03e4fcd
SC
761{
762#if TARGET_CARBON
e40298d5 763 return HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ;
98af9c73 764
b03e4fcd 765#else
e40298d5 766 MenuRef helpMenuHandle ;
98af9c73 767
e40298d5
JS
768 helpMenuStatus = HMGetHelpMenuHandle( &helpMenuHandle ) ;
769 if ( firstCustomItemIndex == 0 && helpMenuStatus == noErr )
e40298d5 770 firstCustomItemIndex = CountMenuItems( helpMenuHandle ) + 1 ;
98af9c73 771
e40298d5 772 if ( outFirstCustomItemIndex )
e40298d5 773 *outFirstCustomItemIndex = firstCustomItemIndex ;
98af9c73 774
e40298d5 775 *outHelpMenu = helpMenuHandle ;
98af9c73 776
e40298d5 777 return helpMenuStatus ;
b03e4fcd
SC
778#endif
779}
76a5e5d2 780
98af9c73 781wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport )
76a5e5d2 782{
e40298d5
JS
783 m_clip = NULL ;
784 Setup( newport ) ;
76a5e5d2
SC
785}
786
787wxMacPortStateHelper::wxMacPortStateHelper()
788{
e40298d5 789 m_clip = NULL ;
76a5e5d2
SC
790}
791
792void wxMacPortStateHelper::Setup( GrafPtr newport )
793{
e40298d5
JS
794 GetPort( &m_oldPort ) ;
795 SetPort( newport ) ;
98af9c73
DS
796 SetOrigin(0, 0);
797
427ff662 798 wxASSERT_MSG( m_clip == NULL , wxT("Cannot call setup twice") ) ;
e40298d5
JS
799 m_clip = NewRgn() ;
800 GetClip( m_clip );
98af9c73
DS
801 m_textFont = GetPortTextFont( (CGrafPtr) newport );
802 m_textSize = GetPortTextSize( (CGrafPtr) newport );
803 m_textStyle = GetPortTextFace( (CGrafPtr) newport );
804 m_textMode = GetPortTextMode( (CGrafPtr) newport );
e40298d5
JS
805 GetThemeDrawingState( &m_drawingState ) ;
806 m_currentPort = newport ;
76a5e5d2 807}
98af9c73 808
76a5e5d2
SC
809void wxMacPortStateHelper::Clear()
810{
e40298d5
JS
811 if ( m_clip )
812 {
813 DisposeRgn( m_clip ) ;
814 DisposeThemeDrawingState( m_drawingState ) ;
815 m_clip = NULL ;
816 }
76a5e5d2
SC
817}
818
819wxMacPortStateHelper::~wxMacPortStateHelper()
820{
e40298d5
JS
821 if ( m_clip )
822 {
823 SetPort( m_currentPort ) ;
824 SetClip( m_clip ) ;
825 DisposeRgn( m_clip ) ;
826 TextFont( m_textFont );
827 TextSize( m_textSize );
828 TextFace( m_textStyle );
829 TextMode( m_textMode );
830 SetThemeDrawingState( m_drawingState , true ) ;
831 SetPort( m_oldPort ) ;
832 }
76a5e5d2
SC
833}
834
9c3c5849
SC
835OSStatus UMAPutScrap( Size size , OSType type , void *data )
836{
e40298d5 837 OSStatus err = noErr ;
98af9c73 838
9c3c5849
SC
839#if !TARGET_CARBON
840 err = PutScrap( size , type , data ) ;
841#else
842 ScrapRef scrap;
98af9c73
DS
843 err = GetCurrentScrap( &scrap );
844 if ( err == noErr )
845 err = PutScrapFlavor( scrap, type , 0, size, data );
9c3c5849 846#endif
98af9c73 847
e40298d5 848 return err ;
9c3c5849
SC
849}
850
98af9c73 851Rect * UMAGetControlBoundsInWindowCoords( ControlRef theControl, Rect *bounds )
facd6764 852{
facd6764 853 GetControlBounds( theControl , bounds ) ;
98af9c73 854
facd6764 855#if TARGET_API_MAC_OSX
37d0bfa8 856 WindowRef tlwref = GetControlOwner( theControl ) ;
37d0bfa8 857
789ae0cf 858 wxTopLevelWindowMac* tlwwx = wxFindWinFromMacWindow( tlwref ) ;
9942b0b5 859 if ( tlwwx != NULL && tlwwx->MacUsesCompositing() )
789ae0cf
SC
860 {
861 ControlRef rootControl = tlwwx->GetPeer()->GetControlRef() ;
98af9c73
DS
862 HIPoint hiPoint = CGPointMake( 0 , 0 ) ;
863 HIViewConvertPoint( &hiPoint , HIViewGetSuperview(theControl) , rootControl ) ;
789ae0cf
SC
864 OffsetRect( bounds , (short) hiPoint.x , (short) hiPoint.y ) ;
865 }
facd6764 866#endif
98af9c73 867
facd6764
SC
868 return bounds ;
869}
870
2dbc444a
RD
871#endif // wxUSE_GUI
872
873#if wxUSE_BASE
874
875static bool sUMASystemInitialized = false ;
876
877bool UMASystemIsInitialized()
878{
879 return sUMASystemInitialized ;
880}
881
882void UMASetSystemIsInitialized(bool val)
883{
884 sUMASystemInitialized = val;
885}
886
2dbc444a 887#endif // wxUSE_BASE