]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/uma.cpp
Mac compilation fix after const patch
[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 bool UMAHasAppearance() { return sUMAHasAppearance ; }
55 long UMAGetAppearanceVersion() { return sUMAAppearanceVersion ; }
56 long UMAGetSystemVersion() { return sUMASystemVersion ; }
57
58 static bool sUMAHasWindowManager = false ;
59 static long sUMAWindowManagerAttr = 0 ;
60
61 bool UMAHasWindowManager() { return sUMAHasWindowManager ; }
62 long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr ; }
63 bool UMAHasAquaLayout() { return sUMAHasAquaLayout ; }
64
65
66 void UMACleanupToolbox()
67 {
68 if (sUMAHasInittedAppearance)
69 {
70 UnregisterAppearanceClient() ;
71 }
72 if ( NavServicesAvailable() )
73 {
74 NavUnload() ;
75 }
76 if ( TXNTerminateTextension != (void*) kUnresolvedCFragSymbolAddress )
77 TXNTerminateTextension( ) ;
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 sUMAHasAppearance = true ;
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
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 }
133
134 #if TARGET_CARBON
135 // Call currently implicitely done : InitFloatingWindows() ;
136 #else
137 if (!isEmbedded)
138 {
139 if ( sUMAHasWindowManager )
140 InitFloatingWindows() ;
141 else
142 InitWindows();
143 }
144 #endif
145
146 if ( NavServicesAvailable() )
147 {
148 NavLoad() ;
149 }
150
151 long menuMgrAttr ;
152 Gestalt( gestaltMenuMgrAttr , &menuMgrAttr ) ;
153 if ( menuMgrAttr & gestaltMenuMgrAquaLayoutMask )
154 sUMAHasAquaLayout = true ;
155
156 if ( TXNInitTextension != (void*) kUnresolvedCFragSymbolAddress )
157 {
158 FontFamilyID fontId ;
159 Str255 fontName ;
160 SInt16 fontSize ;
161 Style fontStyle ;
162 GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
163 GetFNum( fontName, &fontId );
164
165 TXNMacOSPreferredFontDescription fontDescriptions[] =
166 {
167 { fontId , (fontSize << 16) ,kTXNDefaultFontStyle, kTXNSystemDefaultEncoding }
168 } ;
169 int noOfFontDescriptions = sizeof( fontDescriptions ) / sizeof(TXNMacOSPreferredFontDescription) ;
170
171 OptionBits options = 0 ;
172
173 if ( UMAGetSystemVersion() < 0x1000 )
174 {
175 options |= kTXNAlwaysUseQuickDrawTextMask ;
176 }
177 TXNInitTextension(fontDescriptions, noOfFontDescriptions, options );
178 }
179
180
181 UMASetSystemIsInitialized(true);
182
183 }
184
185 /*
186 Boolean CanUseATSUI()
187 {
188 long result;
189 OSErr err = Gestalt(gestaltATSUVersion, &result);
190 return (err == noErr);
191 }
192 */
193 // process manager
194 long UMAGetProcessMode()
195 {
196 OSErr err ;
197 ProcessInfoRec processinfo;
198 ProcessSerialNumber procno ;
199
200 procno.highLongOfPSN = 0 ;
201 procno.lowLongOfPSN = kCurrentProcess ;
202 processinfo.processInfoLength = sizeof(ProcessInfoRec);
203 processinfo.processName = NULL;
204 processinfo.processAppSpec = NULL;
205
206 err = ::GetProcessInformation( &procno , &processinfo ) ;
207 wxASSERT( err == noErr ) ;
208 return processinfo.processMode ;
209 }
210
211 bool UMAGetProcessModeDoesActivateOnFGSwitch()
212 {
213 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch ;
214 }
215
216 // menu manager
217
218 MenuRef UMANewMenu( SInt16 id , const wxString& title , wxFontEncoding encoding )
219 {
220 wxString str = wxStripMenuCodes( title ) ;
221 MenuRef menu ;
222 #if TARGET_CARBON
223 CreateNewMenu( id , 0 , &menu ) ;
224 SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding ) ) ;
225 #else
226 Str255 ptitle ;
227 wxMacStringToPascal( str , ptitle ) ;
228 menu = ::NewMenu( id , ptitle ) ;
229 #endif
230 return menu ;
231 }
232
233 void UMASetMenuTitle( MenuRef menu , const wxString& title , wxFontEncoding encoding)
234 {
235 wxString str = wxStripMenuCodes( title ) ;
236 #if TARGET_CARBON
237 SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding) ) ;
238 #else
239 Str255 ptitle ;
240 wxMacStringToPascal( str , ptitle ) ;
241 SetMenuTitle( menu , ptitle ) ;
242 #endif
243 }
244
245 void UMASetMenuItemText( MenuRef menu, MenuItemIndex item, const wxString& title , wxFontEncoding encoding)
246 {
247 wxString str = wxStripMenuCodes( title ) ;
248 #if TARGET_CARBON
249 SetMenuItemTextWithCFString( menu , item , wxMacCFStringHolder(str , encoding) ) ;
250 #else
251 Str255 ptitle ;
252 wxMacStringToPascal( str , ptitle ) ;
253 SetMenuItemText( menu , item , ptitle ) ;
254 #endif
255 }
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 = false ;
295
296 if ( entry->GetFlags() & wxACCEL_CTRL )
297 {
298 explicitCommandKey = true ;
299 }
300
301 if (entry->GetFlags() & wxACCEL_ALT )
302 {
303 modifiers |= kMenuOptionModifier ;
304 }
305
306 if (entry->GetFlags() & wxACCEL_SHIFT)
307 {
308 modifiers |= kMenuShiftModifier ;
309 }
310
311 SInt16 glyph = 0 ;
312 SInt16 macKey = key ;
313 if ( key >= WXK_F1 && key <= WXK_F15 )
314 {
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.
318 macKey = 0 ;
319 glyph = kMenuF1Glyph + ( key - WXK_F1 ) ;
320 if ( key >= WXK_F13 )
321 glyph += 13 ;
322 if ( !explicitCommandKey )
323 modifiers |= kMenuNoCommandModifier ;
324 }
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 ;
385 default :
386 macKey = toupper( key ) ;
387 break ;
388 }
389 // we now allow non command key shortcuts
390 // remove in case this gives problems
391 if ( !explicitCommandKey )
392 modifiers |= kMenuNoCommandModifier ;
393 }
394
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
400 SetMenuItemModifiers(menu, item , modifiers ) ;
401
402 if ( glyph )
403 SetMenuItemKeyGlyph(menu, item , glyph ) ;
404 }
405 }
406
407 void UMAAppendMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , wxAcceleratorEntry *entry )
408 {
409 MacAppendMenu(menu, "\pA");
410 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
411 ChangeMenuItemAttributes( menu , ::CountMenuItems(menu), kMenuItemAttrIgnoreMeta , 0 ) ;
412 UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title , encoding );
413 UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), entry ) ;
414 }
415
416 void UMAInsertMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , wxAcceleratorEntry *entry )
417 {
418 MacInsertMenuItem( menu , "\pA" , item) ;
419 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
420 ChangeMenuItemAttributes( menu , item+1, kMenuItemAttrIgnoreMeta , 0 ) ;
421 UMASetMenuItemText(menu, item+1 , title , encoding );
422 UMASetMenuItemShortcut( menu , item+1 , entry ) ;
423 }
424
425 // quickdraw
426
427 #if !TARGET_CARBON
428
429 int gPrOpenCounter = 0 ;
430
431 OSStatus UMAPrOpen()
432 {
433 OSErr err = noErr ;
434 ++gPrOpenCounter ;
435 if ( gPrOpenCounter == 1 )
436 {
437 PrOpen() ;
438 err = PrError() ;
439 wxASSERT( err == noErr ) ;
440 }
441 return err ;
442 }
443
444 OSStatus UMAPrClose()
445 {
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 ;
456 }
457
458 pascal QDGlobalsPtr GetQDGlobalsPtr (void) ;
459 pascal QDGlobalsPtr GetQDGlobalsPtr (void)
460 {
461 return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA);
462 }
463
464 #endif
465
466 void UMAShowWatchCursor()
467 {
468 OSErr err = noErr;
469
470 CursHandle watchFob = GetCursor (watchCursor);
471
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);
482 SetCursor (*watchFob);
483 #else
484 SetCursor (*watchFob);
485 #endif
486 }
487 }
488
489 void UMAShowArrowCursor()
490 {
491 #if TARGET_CARBON
492 Cursor arrow;
493 SetCursor (GetQDGlobalsArrow (&arrow));
494 #else
495 SetCursor (&(qd.arrow));
496 #endif
497 }
498
499 // window manager
500
501 GrafPtr UMAGetWindowPort( WindowRef inWindowRef )
502 {
503 wxASSERT( inWindowRef != NULL ) ;
504 #if TARGET_CARBON
505 return (GrafPtr) GetWindowPort( inWindowRef ) ;
506 #else
507 return (GrafPtr) inWindowRef ;
508 #endif
509 }
510
511 void UMADisposeWindow( WindowRef inWindowRef )
512 {
513 wxASSERT( inWindowRef != NULL ) ;
514 DisposeWindow( inWindowRef ) ;
515 }
516
517 void UMASetWTitle( WindowRef inWindowRef , const wxString& title , wxFontEncoding encoding)
518 {
519 #if TARGET_CARBON
520 SetWindowTitleWithCFString( inWindowRef , wxMacCFStringHolder(title , encoding) ) ;
521 #else
522 Str255 ptitle ;
523 wxMacStringToPascal( title , ptitle ) ;
524 SetWTitle( inWindowRef , ptitle ) ;
525 #endif
526 }
527
528 // appearance additions
529
530 void UMASetControlTitle( ControlRef inControl , const wxString& title , wxFontEncoding encoding)
531 {
532 #if TARGET_CARBON
533 SetControlTitleWithCFString( inControl , wxMacCFStringHolder(title , encoding) ) ;
534 #else
535 Str255 ptitle ;
536 wxMacStringToPascal( title , ptitle ) ;
537 SetControlTitle( inControl , ptitle ) ;
538 #endif
539 }
540
541 void UMAActivateControl( ControlRef inControl )
542 {
543 #if !TARGET_API_MAC_OSX
544 // we have to add the control after again to the update rgn
545 // otherwise updates get lost
546 if ( !IsControlActive( inControl ) )
547 {
548 bool visible = IsControlVisible( inControl ) ;
549 if ( visible )
550 SetControlVisibility( inControl , false , false ) ;
551 #endif
552 ::ActivateControl( inControl ) ;
553 #if !TARGET_API_MAC_OSX
554 if ( visible ) {
555 SetControlVisibility( inControl , true , false ) ;
556
557 Rect ctrlBounds ;
558 InvalWindowRect(GetControlOwner(inControl),UMAGetControlBoundsInWindowCoords(inControl,&ctrlBounds) ) ;
559 }
560 }
561 #endif
562 }
563
564 void UMAMoveControl( ControlRef inControl , short x , short y )
565 {
566 #if !TARGET_API_MAC_OSX
567 bool visible = IsControlVisible( inControl ) ;
568 if ( visible ) {
569 SetControlVisibility( inControl , false , false ) ;
570 Rect ctrlBounds ;
571 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
572 }
573 #endif
574 ::MoveControl( inControl , x , y ) ;
575 #if !TARGET_API_MAC_OSX
576 if ( visible ) {
577 SetControlVisibility( inControl , true , false ) ;
578 Rect ctrlBounds ;
579 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
580 }
581 #endif
582 }
583
584 void UMASizeControl( ControlRef inControl , short x , short y )
585 {
586 #if !TARGET_API_MAC_OSX
587 bool visible = IsControlVisible( inControl ) ;
588 if ( visible ) {
589 SetControlVisibility( inControl , false , false ) ;
590 Rect ctrlBounds ;
591 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
592 }
593 #endif
594 ::SizeControl( inControl , x , y ) ;
595 #if !TARGET_API_MAC_OSX
596 if ( visible ) {
597 SetControlVisibility( inControl , true , false ) ;
598 Rect ctrlBounds ;
599 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
600 }
601 #endif
602 }
603
604 void UMADeactivateControl( ControlRef inControl )
605 {
606 #if !TARGET_API_MAC_OSX
607 // we have to add the control after again to the update rgn
608 // otherwise updates get lost
609 bool visible = IsControlVisible( inControl ) ;
610 if ( visible )
611 SetControlVisibility( inControl , false , false ) ;
612 #endif
613 ::DeactivateControl( inControl ) ;
614 #if !TARGET_API_MAC_OSX
615 if ( visible ) {
616 SetControlVisibility( inControl , true , false ) ;
617 Rect ctrlBounds ;
618 InvalWindowRect(GetControlOwner(inControl),UMAGetControlBoundsInWindowCoords(inControl,&ctrlBounds) ) ;
619 }
620 #endif
621 }
622 // shows the control and adds the region to the update region
623 void UMAShowControl (ControlRef inControl)
624 {
625 SetControlVisibility( inControl , true , false ) ;
626 Rect ctrlBounds ;
627 InvalWindowRect(GetControlOwner(inControl),UMAGetControlBoundsInWindowCoords(inControl,&ctrlBounds) ) ;
628 }
629
630 // hides the control and adds the region to the update region
631 void UMAHideControl (ControlRef inControl)
632 {
633 SetControlVisibility( inControl , false , false ) ;
634 Rect ctrlBounds ;
635 InvalWindowRect(GetControlOwner(inControl),UMAGetControlBoundsInWindowCoords(inControl,&ctrlBounds) ) ;
636 }
637 // keyboard focus
638 OSErr UMASetKeyboardFocus (WindowPtr inWindow,
639 ControlRef inControl,
640 ControlFocusPart inPart)
641 {
642 OSErr err = noErr;
643 GrafPtr port ;
644 GetPort( &port ) ;
645
646 SetPortWindowPort( inWindow ) ;
647
648 err = SetKeyboardFocus( inWindow , inControl , inPart ) ;
649 SetPort( port ) ;
650 return err ;
651 }
652
653 bool UMAIsWindowFloating( WindowRef inWindow )
654 {
655 WindowClass cl ;
656
657 GetWindowClass( inWindow , &cl ) ;
658 return cl == kFloatingWindowClass ;
659 }
660
661 bool UMAIsWindowModal( WindowRef inWindow )
662 {
663 WindowClass cl ;
664
665 GetWindowClass( inWindow , &cl ) ;
666 return cl < kFloatingWindowClass ;
667 }
668
669 // others
670
671 void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
672 {
673 if ( inWindowRef )
674 {
675 // bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
676 // if ( inActivate != isHighlighted )
677 GrafPtr port ;
678 GetPort( &port ) ;
679 SetPortWindowPort( inWindowRef ) ;
680 HiliteWindow( inWindowRef , inActivate ) ;
681 ControlRef control = NULL ;
682 ::GetRootControl( inWindowRef , & control ) ;
683 if ( control )
684 {
685 if ( inActivate )
686 UMAActivateControl( control ) ;
687 else
688 UMADeactivateControl( control ) ;
689 }
690 SetPort( port ) ;
691 }
692 }
693
694 OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState )
695 {
696 return ::DrawThemePlacard( inRect , inState ) ;
697 }
698
699 #if !TARGET_CARBON
700 static OSStatus helpMenuStatus = noErr ;
701 static MenuItemIndex firstCustomItemIndex = 0 ;
702 #endif
703
704 OSStatus UMAGetHelpMenu(
705 MenuRef * outHelpMenu,
706 MenuItemIndex * outFirstCustomItemIndex)
707 {
708 #if TARGET_CARBON
709 return HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ;
710 #else
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 ;
723 #endif
724 }
725
726 wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport)
727 {
728 m_clip = NULL ;
729 Setup( newport ) ;
730 }
731
732 wxMacPortStateHelper::wxMacPortStateHelper()
733 {
734 m_clip = NULL ;
735 }
736
737 void wxMacPortStateHelper::Setup( GrafPtr newport )
738 {
739 GetPort( &m_oldPort ) ;
740 SetPort( newport ) ;
741 SetOrigin(0,0);
742 wxASSERT_MSG( m_clip == NULL , wxT("Cannot call setup twice") ) ;
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);
748 m_textMode = GetPortTextMode( (CGrafPtr) newport);
749 GetThemeDrawingState( &m_drawingState ) ;
750 m_currentPort = newport ;
751 }
752 void wxMacPortStateHelper::Clear()
753 {
754 if ( m_clip )
755 {
756 DisposeRgn( m_clip ) ;
757 DisposeThemeDrawingState( m_drawingState ) ;
758 m_clip = NULL ;
759 }
760 }
761
762 wxMacPortStateHelper::~wxMacPortStateHelper()
763 {
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 }
776 }
777
778 OSStatus UMAPutScrap( Size size , OSType type , void *data )
779 {
780 OSStatus err = noErr ;
781 #if !TARGET_CARBON
782 err = PutScrap( size , type , data ) ;
783 #else
784 ScrapRef scrap;
785 err = GetCurrentScrap (&scrap);
786 if ( !err )
787 {
788 err = PutScrapFlavor (scrap, type , 0, size, data);
789 }
790 #endif
791 return err ;
792 }
793
794 Rect* UMAGetControlBoundsInWindowCoords(ControlRef theControl, Rect *bounds)
795 {
796 GetControlBounds( theControl , bounds ) ;
797 #if TARGET_API_MAC_OSX
798 WindowRef tlwref = GetControlOwner( theControl ) ;
799
800 wxTopLevelWindowMac* tlwwx = wxFindWinFromMacWindow( tlwref ) ;
801 if ( tlwwx != NULL && tlwwx->MacUsesCompositing() )
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 }
808 #endif
809 return bounds ;
810 }
811
812
813 #endif // wxUSE_GUI
814
815 #if wxUSE_BASE
816
817 static bool sUMASystemInitialized = false ;
818
819 bool UMASystemIsInitialized()
820 {
821 return sUMASystemInitialized ;
822 }
823
824 void UMASetSystemIsInitialized(bool val)
825 {
826 sUMASystemInitialized = val;
827 }
828
829
830 #endif // wxUSE_BASE