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