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