]> git.saurik.com Git - wxWidgets.git/blob - src/mac/uma.cpp
corrections for buffers
[wxWidgets.git] / src / mac / 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/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 wxWindows code can safely assume that appearance 1.1
40 // windows manager, control manager, navigation services etc. are
41 // present
42
43 static bool sUMAHasAppearance = false ;
44 static long sUMAAppearanceVersion = 0 ;
45 static long sUMASystemVersion = 0 ;
46 static bool sUMAHasAquaLayout = false ;
47
48 static bool sUMAHasInittedAppearance = false;
49
50 extern int gAGABackgroundColor ;
51 bool UMAHasAppearance() { return sUMAHasAppearance ; }
52 long UMAGetAppearanceVersion() { return sUMAAppearanceVersion ; }
53 long UMAGetSystemVersion() { return sUMASystemVersion ; }
54
55 static bool sUMAHasWindowManager = false ;
56 static long sUMAWindowManagerAttr = 0 ;
57
58 bool UMAHasWindowManager() { return sUMAHasWindowManager ; }
59 long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr ; }
60 bool UMAHasAquaLayout() { return sUMAHasAquaLayout ; }
61
62
63 void UMACleanupToolbox()
64 {
65 if (sUMAHasInittedAppearance)
66 {
67 UnregisterAppearanceClient() ;
68 }
69 if ( NavServicesAvailable() )
70 {
71 NavUnload() ;
72 }
73 if ( TXNTerminateTextension != (void*) kUnresolvedCFragSymbolAddress )
74 TXNTerminateTextension( ) ;
75 }
76 void 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 #if 0 // TARGET_CARBON
168 --noOfFontDescriptions ;
169 #endif
170 // kTXNAlwaysUseQuickDrawTextMask might be desirable because of speed increases but it crashes the app under OS X upon key stroke
171 OptionBits options = kTXNWantMoviesMask | kTXNWantSoundMask | kTXNWantGraphicsMask ;
172 #if TARGET_CARBON
173 if ( !UMAHasAquaLayout() )
174 #endif
175 {
176 options |= kTXNAlwaysUseQuickDrawTextMask ;
177 }
178 TXNInitTextension(fontDescriptions, noOfFontDescriptions, options );
179 }
180
181
182 UMASetSystemIsInitialized(true);
183
184 }
185
186 /*
187 Boolean CanUseATSUI()
188 {
189 long result;
190 OSErr err = Gestalt(gestaltATSUVersion, &result);
191 return (err == noErr);
192 }
193 */
194 // process manager
195 long UMAGetProcessMode()
196 {
197 OSErr err ;
198 ProcessInfoRec processinfo;
199 ProcessSerialNumber procno ;
200
201 procno.highLongOfPSN = NULL ;
202 procno.lowLongOfPSN = kCurrentProcess ;
203 processinfo.processInfoLength = sizeof(ProcessInfoRec);
204 processinfo.processName = NULL;
205 processinfo.processAppSpec = NULL;
206
207 err = ::GetProcessInformation( &procno , &processinfo ) ;
208 wxASSERT( err == noErr ) ;
209 return processinfo.processMode ;
210 }
211
212 bool UMAGetProcessModeDoesActivateOnFGSwitch()
213 {
214 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch ;
215 }
216
217 // menu manager
218
219 MenuRef UMANewMenu( SInt16 id , const wxString& title , wxFontEncoding encoding )
220 {
221 wxString str = wxStripMenuCodes( title ) ;
222 MenuRef menu ;
223 #if TARGET_CARBON
224 CreateNewMenu( id , 0 , &menu ) ;
225 SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding ) ) ;
226 #else
227 Str255 ptitle ;
228 wxMacStringToPascal( str , ptitle ) ;
229 menu = ::NewMenu( id , ptitle ) ;
230 #endif
231 return menu ;
232 }
233
234 void UMASetMenuTitle( MenuRef menu , const wxString& title , wxFontEncoding encoding)
235 {
236 wxString str = wxStripMenuCodes( title ) ;
237 #if TARGET_CARBON
238 SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding) ) ;
239 #else
240 Str255 ptitle ;
241 wxMacStringToPascal( str , ptitle ) ;
242 SetMenuTitle( menu , ptitle ) ;
243 #endif
244 }
245
246 void UMASetMenuItemText( MenuRef menu, MenuItemIndex item, const wxString& title , wxFontEncoding encoding)
247 {
248 wxString str = wxStripMenuCodes( title ) ;
249 #if TARGET_CARBON
250 SetMenuItemTextWithCFString( menu , item , wxMacCFStringHolder(str , encoding) ) ;
251 #else
252 Str255 ptitle ;
253 wxMacStringToPascal( str , ptitle ) ;
254 SetMenuItemText( menu , item , ptitle ) ;
255 #endif
256 }
257
258
259 UInt32 UMAMenuEvent( EventRecord *inEvent )
260 {
261 return MenuEvent( inEvent ) ;
262 }
263
264 void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem , bool enable)
265 {
266 if ( enable )
267 EnableMenuItem( inMenu , inItem ) ;
268 else
269 DisableMenuItem( inMenu , inItem ) ;
270 }
271
272 void UMAAppendSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , SInt16 id )
273 {
274 MacAppendMenu(menu, "\pA");
275 UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title , encoding );
276 SetMenuItemHierarchicalID( menu , CountMenuItems( menu ) , id ) ;
277 }
278
279 void UMAInsertSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , SInt16 id )
280 {
281 MacInsertMenuItem(menu, "\pA" , item);
282 UMASetMenuItemText(menu, item , title , encoding);
283 SetMenuItemHierarchicalID( menu , item , id ) ;
284 }
285
286 void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEntry *entry )
287 {
288 if ( !entry )
289 return ;
290
291 UInt8 modifiers = 0 ;
292 SInt16 key = entry->GetKeyCode() ;
293 if ( key )
294 {
295 bool explicitCommandKey = false ;
296
297 if ( entry->GetFlags() & wxACCEL_CTRL )
298 {
299 explicitCommandKey = true ;
300 }
301
302 if (entry->GetFlags() & wxACCEL_ALT )
303 {
304 modifiers |= kMenuOptionModifier ;
305 }
306
307 if (entry->GetFlags() & wxACCEL_SHIFT)
308 {
309 modifiers |= kMenuShiftModifier ;
310 }
311
312 SInt16 glyph = 0 ;
313 SInt16 macKey = key ;
314 if ( key >= WXK_F1 && key <= WXK_F15 )
315 {
316 // for some reasons this must be 0 right now
317 // everything else leads to just the first function key item
318 // to be selected. Thanks to Ryan Wilcox for finding out.
319 macKey = 0 ;
320 glyph = kMenuF1Glyph + ( key - WXK_F1 ) ;
321 if ( key >= WXK_F13 )
322 glyph += 13 ;
323 if ( !explicitCommandKey )
324 modifiers |= kMenuNoCommandModifier ;
325 }
326 else
327 {
328 switch( key )
329 {
330 case WXK_BACK :
331 macKey = kBackspaceCharCode ;
332 glyph = kMenuDeleteLeftGlyph ;
333 break ;
334 case WXK_TAB :
335 macKey = kTabCharCode ;
336 glyph = kMenuTabRightGlyph ;
337 break ;
338 case kEnterCharCode :
339 macKey = kEnterCharCode ;
340 glyph = kMenuEnterGlyph ;
341 break ;
342 case WXK_RETURN :
343 macKey = kReturnCharCode ;
344 glyph = kMenuReturnGlyph ;
345 break ;
346 case WXK_ESCAPE :
347 macKey = kEscapeCharCode ;
348 glyph = kMenuEscapeGlyph ;
349 break ;
350 case WXK_SPACE :
351 macKey = ' ' ;
352 glyph = kMenuSpaceGlyph ;
353 break ;
354 case WXK_DELETE :
355 macKey = kDeleteCharCode ;
356 glyph = kMenuDeleteRightGlyph ;
357 break ;
358 case WXK_CLEAR :
359 macKey = kClearCharCode ;
360 glyph = kMenuClearGlyph ;
361 break ;
362 case WXK_PRIOR : // PAGE UP
363 macKey = kPageUpCharCode ;
364 glyph = kMenuPageUpGlyph ;
365 break ;
366 case WXK_NEXT :
367 macKey = kPageDownCharCode ;
368 glyph = kMenuPageDownGlyph ;
369 break ;
370 case WXK_LEFT :
371 macKey = kLeftArrowCharCode ;
372 glyph = kMenuLeftArrowGlyph ;
373 break ;
374 case WXK_UP :
375 macKey = kUpArrowCharCode ;
376 glyph = kMenuUpArrowGlyph ;
377 break ;
378 case WXK_RIGHT :
379 macKey = kRightArrowCharCode ;
380 glyph = kMenuRightArrowGlyph ;
381 break ;
382 case WXK_DOWN :
383 macKey = kDownArrowCharCode ;
384 glyph = kMenuDownArrowGlyph ;
385 break ;
386 }
387 }
388
389 SetItemCmd( menu, item , macKey );
390 SetMenuItemModifiers(menu, item , modifiers ) ;
391
392 if ( glyph )
393 SetMenuItemKeyGlyph(menu, item , glyph ) ;
394 }
395 }
396
397 void UMAAppendMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , wxAcceleratorEntry *entry )
398 {
399 MacAppendMenu(menu, "\pA");
400 UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title , encoding );
401 UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), entry ) ;
402 }
403
404 void UMAInsertMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , wxAcceleratorEntry *entry )
405 {
406 MacInsertMenuItem( menu , "\pA" , item) ;
407 UMASetMenuItemText(menu, item+1 , title , encoding );
408 UMASetMenuItemShortcut( menu , item+1 , entry ) ;
409 }
410
411 // quickdraw
412
413 #if !TARGET_CARBON
414
415 int gPrOpenCounter = 0 ;
416
417 OSStatus UMAPrOpen()
418 {
419 OSErr err = noErr ;
420 ++gPrOpenCounter ;
421 if ( gPrOpenCounter == 1 )
422 {
423 PrOpen() ;
424 err = PrError() ;
425 wxASSERT( err == noErr ) ;
426 }
427 return err ;
428 }
429
430 OSStatus UMAPrClose()
431 {
432 OSErr err = noErr ;
433 wxASSERT( gPrOpenCounter >= 1 ) ;
434 if ( gPrOpenCounter == 1 )
435 {
436 PrClose() ;
437 err = PrError() ;
438 wxASSERT( err == noErr ) ;
439 }
440 --gPrOpenCounter ;
441 return err ;
442 }
443
444 pascal QDGlobalsPtr GetQDGlobalsPtr (void) ;
445 pascal QDGlobalsPtr GetQDGlobalsPtr (void)
446 {
447 return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA);
448 }
449
450 #endif
451
452 void UMAShowWatchCursor()
453 {
454 OSErr err = noErr;
455
456 CursHandle watchFob = GetCursor (watchCursor);
457
458 if (!watchFob)
459 err = nilHandleErr;
460 else
461 {
462 #if TARGET_CARBON
463 // Cursor preservedArrow;
464 // GetQDGlobalsArrow (&preservedArrow);
465 // SetQDGlobalsArrow (*watchFob);
466 // InitCursor ( );
467 // SetQDGlobalsArrow (&preservedArrow);
468 SetCursor (*watchFob);
469 #else
470 SetCursor (*watchFob);
471 #endif
472 }
473 }
474
475 void UMAShowArrowCursor()
476 {
477 #if TARGET_CARBON
478 Cursor arrow;
479 SetCursor (GetQDGlobalsArrow (&arrow));
480 #else
481 SetCursor (&(qd.arrow));
482 #endif
483 }
484
485 // window manager
486
487 GrafPtr UMAGetWindowPort( WindowRef inWindowRef )
488 {
489 wxASSERT( inWindowRef != NULL ) ;
490 #if TARGET_CARBON
491 return (GrafPtr) GetWindowPort( inWindowRef ) ;
492 #else
493 return (GrafPtr) inWindowRef ;
494 #endif
495 }
496
497 void UMADisposeWindow( WindowRef inWindowRef )
498 {
499 wxASSERT( inWindowRef != NULL ) ;
500 DisposeWindow( inWindowRef ) ;
501 }
502
503 void UMASetWTitle( WindowRef inWindowRef , const wxString& title , wxFontEncoding encoding)
504 {
505 #if TARGET_CARBON
506 SetWindowTitleWithCFString( inWindowRef , wxMacCFStringHolder(title , encoding) ) ;
507 #else
508 Str255 ptitle ;
509 wxMacStringToPascal( title , ptitle ) ;
510 SetWTitle( inWindowRef , ptitle ) ;
511 #endif
512 }
513
514 // appearance additions
515
516 void UMASetControlTitle( ControlHandle inControl , const wxString& title , wxFontEncoding encoding)
517 {
518 #if TARGET_CARBON
519 SetControlTitleWithCFString( inControl , wxMacCFStringHolder(title , encoding) ) ;
520 #else
521 Str255 ptitle ;
522 wxMacStringToPascal( title , ptitle ) ;
523 SetControlTitle( inControl , ptitle ) ;
524 #endif
525 }
526
527 void UMAActivateControl( ControlHandle inControl )
528 {
529 // we have to add the control after again to the update rgn
530 // otherwise updates get lost
531 if ( !IsControlActive( inControl ) )
532 {
533 bool visible = IsControlVisible( inControl ) ;
534 if ( visible )
535 SetControlVisibility( inControl , false , false ) ;
536 ::ActivateControl( inControl ) ;
537 if ( visible ) {
538 SetControlVisibility( inControl , true , false ) ;
539 Rect ctrlBounds ;
540 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
541 }
542 }
543 }
544
545 void UMADrawControl( ControlHandle inControl )
546 {
547 WindowRef theWindow = GetControlOwner(inControl) ;
548 wxMacPortStateHelper help( (GrafPtr) GetWindowPort(theWindow) ) ;
549 RgnHandle updateRgn = NewRgn() ;
550 GetWindowUpdateRgn( theWindow , updateRgn ) ;
551 Point zero = { 0 , 0 } ;
552 LocalToGlobal( &zero ) ;
553 OffsetRgn( updateRgn , -zero.h , -zero.v ) ;
554 ::DrawControlInCurrentPort( inControl ) ;
555 InvalWindowRgn( theWindow, updateRgn) ;
556 DisposeRgn( updateRgn ) ;
557 }
558
559 void UMAMoveControl( ControlHandle inControl , short x , short y )
560 {
561 bool visible = IsControlVisible( inControl ) ;
562 if ( visible ) {
563 SetControlVisibility( inControl , false , false ) ;
564 Rect ctrlBounds ;
565 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
566 }
567 ::MoveControl( inControl , x , y ) ;
568 if ( visible ) {
569 SetControlVisibility( inControl , true , false ) ;
570 Rect ctrlBounds ;
571 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
572 }
573 }
574
575 void UMASizeControl( ControlHandle inControl , short x , short y )
576 {
577 bool visible = IsControlVisible( inControl ) ;
578 if ( visible ) {
579 SetControlVisibility( inControl , false , false ) ;
580 Rect ctrlBounds ;
581 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
582 }
583 ::SizeControl( inControl , x , y ) ;
584 if ( visible ) {
585 SetControlVisibility( inControl , true , false ) ;
586 Rect ctrlBounds ;
587 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
588 }
589 }
590
591 void UMADeactivateControl( ControlHandle inControl )
592 {
593 // we have to add the control after again to the update rgn
594 // otherwise updates get lost
595 bool visible = IsControlVisible( inControl ) ;
596 if ( visible )
597 SetControlVisibility( inControl , false , false ) ;
598 ::DeactivateControl( inControl ) ;
599 if ( visible ) {
600 SetControlVisibility( inControl , true , false ) ;
601 Rect ctrlBounds ;
602 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
603 }
604 }
605 // shows the control and adds the region to the update region
606 void UMAShowControl (ControlHandle inControl)
607 {
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
614 void UMAHideControl (ControlHandle inControl)
615 {
616 SetControlVisibility( inControl , false , false ) ;
617 Rect ctrlBounds ;
618 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
619 }
620 // keyboard focus
621 OSErr UMASetKeyboardFocus (WindowPtr inWindow,
622 ControlHandle inControl,
623 ControlFocusPart inPart)
624 {
625 OSErr err = noErr;
626 GrafPtr port ;
627 GetPort( &port ) ;
628
629 SetPortWindowPort( inWindow ) ;
630
631 err = SetKeyboardFocus( inWindow , inControl , inPart ) ;
632 SetPort( port ) ;
633 return err ;
634 }
635
636
637 // events
638 void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn )
639 {
640 wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) inWindow) ) ;
641 RgnHandle updateRgn = NewRgn() ;
642 GetWindowUpdateRgn( inWindow , updateRgn ) ;
643
644 Point zero = { 0 , 0 } ;
645 LocalToGlobal( &zero ) ;
646 OffsetRgn( updateRgn , -zero.h , -zero.v ) ;
647
648 UpdateControls( inWindow , inRgn ) ;
649 InvalWindowRgn( inWindow, updateRgn) ;
650 DisposeRgn( updateRgn ) ;
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 != isHightlited )
677 GrafPtr port ;
678 GetPort( &port ) ;
679 SetPortWindowPort( inWindowRef ) ;
680 HiliteWindow( inWindowRef , inActivate ) ;
681 ControlHandle 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 #endif // wxUSE_GUI
795
796 #if wxUSE_BASE
797
798 static bool sUMASystemInitialized = false ;
799
800 bool UMASystemIsInitialized()
801 {
802 return sUMASystemInitialized ;
803 }
804
805 void UMASetSystemIsInitialized(bool val)
806 {
807 sUMASystemInitialized = val;
808 }
809
810
811 #endif // wxUSE_BASE