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