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