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