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