]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/uma.cpp
compilation fix
[wxWidgets.git] / src / mac / uma.cpp
... / ...
CommitLineData
1#include "wx/defs.h"
2#include "wx/dc.h"
3#include "wx/mac/uma.h"
4#include <MacTextEditor.h>
5
6#ifndef __DARWIN__
7# include <Navigation.h>
8# if defined(TARGET_CARBON)
9# if PM_USE_SESSION_APIS
10# include <PMCore.h>
11# endif
12# include <PMApplication.h>
13# else
14# include <Printing.h>
15# endif
16#endif
17
18// since we have decided that we only support 8.6 upwards we are
19// checking for these minimum requirements in the startup code of
20// the application so all wxWindows code can safely assume that appearance 1.1
21// windows manager, control manager, navigation services etc. are
22// present
23
24static bool sUMAHasAppearance = false ;
25static long sUMAAppearanceVersion = 0 ;
26static long sUMASystemVersion = 0 ;
27static bool sUMAHasAquaLayout = false ;
28static bool sUMASystemInitialized = false ;
29
30extern int gAGABackgroundColor ;
31bool UMAHasAppearance() { return sUMAHasAppearance ; }
32long UMAGetAppearanceVersion() { return sUMAAppearanceVersion ; }
33long UMAGetSystemVersion() { return sUMASystemVersion ; }
34
35static bool sUMAHasWindowManager = false ;
36static long sUMAWindowManagerAttr = 0 ;
37
38bool UMAHasWindowManager() { return sUMAHasWindowManager ; }
39long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr ; }
40bool UMAHasAquaLayout() { return sUMAHasAquaLayout ; }
41bool UMASystemIsInitialized() { return sUMASystemInitialized ; }
42
43void UMACleanupToolbox()
44{
45 if ( sUMAHasAppearance )
46 {
47 UnregisterAppearanceClient() ;
48 }
49 if ( NavServicesAvailable() )
50 {
51 NavUnload() ;
52 }
53 if ( TXNTerminateTextension != (void*) kUnresolvedCFragSymbolAddress )
54 TXNTerminateTextension( ) ;
55}
56void UMAInitToolbox( UInt16 inMoreMastersCalls )
57{
58#if !TARGET_CARBON
59 ::MaxApplZone();
60 for (long i = 1; i <= inMoreMastersCalls; i++)
61 ::MoreMasters();
62
63 ::InitGraf(&qd.thePort);
64 ::InitFonts();
65 ::InitMenus();
66 ::TEInit();
67 ::InitDialogs(0L);
68 ::FlushEvents(everyEvent, 0);
69 ::InitCursor();
70 long total,contig;
71 PurgeSpace(&total, &contig);
72#else
73 InitCursor();
74#endif
75
76 if ( Gestalt(gestaltSystemVersion, &sUMASystemVersion) != noErr)
77 sUMASystemVersion = 0x0000 ;
78
79 long theAppearance ;
80 if ( Gestalt( gestaltAppearanceAttr, &theAppearance ) == noErr )
81 {
82 sUMAHasAppearance = true ;
83 RegisterAppearanceClient();
84 if ( Gestalt( gestaltAppearanceVersion, &theAppearance ) == noErr )
85 {
86 sUMAAppearanceVersion = theAppearance ;
87 }
88 else
89 {
90 sUMAAppearanceVersion = 0x0100 ;
91 }
92 }
93 if ( Gestalt( gestaltWindowMgrAttr, &sUMAWindowManagerAttr ) == noErr )
94 {
95 sUMAHasWindowManager = sUMAWindowManagerAttr & gestaltWindowMgrPresent ;
96 }
97
98#if TARGET_CARBON
99// Call currently implicitely done : InitFloatingWindows() ;
100#else
101 if ( sUMAHasWindowManager )
102 InitFloatingWindows() ;
103 else
104 InitWindows();
105#endif
106
107 if ( NavServicesAvailable() )
108 {
109 NavLoad() ;
110 }
111
112 long menuMgrAttr ;
113 Gestalt( gestaltMenuMgrAttr , &menuMgrAttr ) ;
114 if ( menuMgrAttr & gestaltMenuMgrAquaLayoutMask )
115 sUMAHasAquaLayout = true ;
116
117 if ( TXNInitTextension != (void*) kUnresolvedCFragSymbolAddress )
118 {
119 FontFamilyID fontId ;
120 Str255 fontName ;
121 SInt16 fontSize ;
122 Style fontStyle ;
123 GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
124 GetFNum( fontName, &fontId );
125
126 TXNMacOSPreferredFontDescription fontDescriptions[] =
127 {
128 { fontId , (fontSize << 16) ,kTXNDefaultFontStyle, kTXNSystemDefaultEncoding } ,
129 } ;
130 int noOfFontDescriptions = sizeof( fontDescriptions ) / sizeof(TXNMacOSPreferredFontDescription) ;
131#if 0 // TARGET_CARBON
132 --noOfFontDescriptions ;
133#endif
134 // kTXNAlwaysUseQuickDrawTextMask might be desirable because of speed increases but it crashes the app under OS X upon key stroke
135 OptionBits options = kTXNWantMoviesMask | kTXNWantSoundMask | kTXNWantGraphicsMask ;
136#if TARGET_CARBON
137 if ( !UMAHasAquaLayout() )
138#endif
139 {
140 options |= kTXNAlwaysUseQuickDrawTextMask ;
141 }
142 TXNInitTextension(fontDescriptions, noOfFontDescriptions, options );
143 }
144
145
146 sUMASystemInitialized = true ;
147
148}
149
150/*
151Boolean CanUseATSUI()
152 {
153 long result;
154 OSErr err = Gestalt(gestaltATSUVersion, &result);
155 return (err == noErr);
156 }
157*/
158// process manager
159long UMAGetProcessMode()
160{
161 OSErr err ;
162 ProcessInfoRec processinfo;
163 ProcessSerialNumber procno ;
164
165 procno.highLongOfPSN = NULL ;
166 procno.lowLongOfPSN = kCurrentProcess ;
167 processinfo.processInfoLength = sizeof(ProcessInfoRec);
168 processinfo.processName = NULL;
169 processinfo.processAppSpec = NULL;
170
171 err = ::GetProcessInformation( &procno , &processinfo ) ;
172 wxASSERT( err == noErr ) ;
173 return processinfo.processMode ;
174}
175
176bool UMAGetProcessModeDoesActivateOnFGSwitch()
177{
178 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch ;
179}
180
181// menu manager
182
183void UMASetMenuTitle( MenuRef menu , StringPtr title )
184{
185/*
186#if !TARGET_CARBON
187 long size = GetHandleSize( (Handle) menu ) ;
188 const long headersize = 14 ;
189 int oldlen = (**menu).menuData[0] + 1;
190 int newlen = title[0] + 1 ;
191
192 if ( oldlen < newlen )
193 {
194 // enlarge before adjusting
195 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) );
196 }
197
198 if ( oldlen != newlen )
199 memmove( (char*) (**menu).menuData + newlen , (char*) (**menu).menuData + oldlen , size - headersize - oldlen ) ;
200
201 memcpy( (char*) (**menu).menuData , title , newlen ) ;
202 if ( oldlen > newlen )
203 {
204 // shrink after
205 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) ) ;
206 }
207#else
208*/
209 SetMenuTitle( menu , title ) ;
210//#endif
211}
212
213UInt32 UMAMenuEvent( EventRecord *inEvent )
214{
215 return MenuEvent( inEvent ) ;
216}
217
218void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem )
219{
220 EnableMenuItem( inMenu , inItem ) ;
221}
222
223void UMADisableMenuItem( MenuRef inMenu , MenuItemIndex inItem )
224{
225 DisableMenuItem( inMenu , inItem ) ;
226}
227
228void UMAAppendSubMenuItem( MenuRef menu , StringPtr l , SInt16 id )
229{
230 MacAppendMenu(menu, l);
231 SetMenuItemHierarchicalID( menu , CountMenuItems( menu ) , id ) ;
232}
233
234void UMAInsertSubMenuItem( MenuRef menu , StringPtr l , MenuItemIndex item , SInt16 id )
235{
236 MacInsertMenuItem(menu, l , item);
237 SetMenuItemHierarchicalID( menu , item , id ) ;
238}
239
240void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , SInt16 key , UInt8 modifiers )
241{
242 if ( key )
243 {
244 SInt16 glyph = 0 ;
245 SInt16 macKey = key ;
246 if ( key >= WXK_F1 && key <= WXK_F15 )
247 {
248 macKey = kFunctionKeyCharCode ;
249 glyph = kMenuF1Glyph + ( key - WXK_F1 ) ;
250 if ( key >= WXK_F13 )
251 glyph += 13 ;
252 switch( key )
253 {
254 case WXK_F1 :
255 macKey += ( 0x7a << 8 ) ;
256 break ;
257 case WXK_F2 :
258 macKey += ( 0x78 << 8 ) ;
259 break ;
260 case WXK_F3 :
261 macKey += ( 0x63 << 8 ) ;
262 break ;
263 case WXK_F4 :
264 macKey += ( 0x76 << 8 ) ;
265 break ;
266 case WXK_F5 :
267 macKey += ( 0x60 << 8 ) ;
268 break ;
269 case WXK_F6 :
270 macKey += ( 0x61 << 8 ) ;
271 break ;
272 case WXK_F7 :
273 macKey += ( 0x62 << 8 ) ;
274 break ;
275 case WXK_F8 :
276 macKey += ( 0x64 << 8 ) ;
277 break ;
278 case WXK_F9 :
279 macKey += ( 0x65 << 8 ) ;
280 break ;
281 case WXK_F10 :
282 macKey += ( 0x6D << 8 ) ;
283 break ;
284 case WXK_F11 :
285 macKey += ( 0x67 << 8 ) ;
286 break ;
287 case WXK_F12 :
288 macKey += ( 0x6F << 8 ) ;
289 break ;
290 case WXK_F13 :
291 macKey += ( 0x69 << 8 ) ;
292 break ;
293 case WXK_F14 :
294 macKey += ( 0x6B << 8 ) ;
295 break ;
296 case WXK_F15 :
297 macKey += ( 0x71 << 8 ) ;
298 break ;
299 default :
300 break ;
301 } ;
302 // unfortunately this does not yet trigger the right key ,
303 // for some reason mac justs picks the first function key menu
304 // defined, so we turn this off
305 macKey = 0 ;
306 glyph = 0 ;
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
379void UMAAppendMenuItem( MenuRef menu , StringPtr l , SInt16 key, UInt8 modifiers )
380{
381 MacAppendMenu(menu, "\pA");
382 SetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), l);
383 UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), key , modifiers ) ;
384}
385
386void UMAInsertMenuItem( MenuRef menu , StringPtr l , MenuItemIndex item , SInt16 key, UInt8 modifiers )
387{
388 MacInsertMenuItem( menu , "\p" , item) ;
389 SetMenuItemText(menu, item , l);
390 UMASetMenuItemShortcut( menu , item , key , modifiers ) ;
391}
392
393// quickdraw
394
395int gPrOpenCounter = 0 ;
396
397OSStatus UMAPrOpen(void *macPrintSession)
398{
399#if !TARGET_CARBON
400 OSErr err = noErr ;
401 ++gPrOpenCounter ;
402 if ( gPrOpenCounter == 1 )
403 {
404 PrOpen() ;
405 err = PrError() ;
406 wxASSERT( err == noErr ) ;
407 }
408 return err ;
409#else
410 OSStatus err = noErr ;
411 ++gPrOpenCounter ;
412 if ( gPrOpenCounter == 1 )
413 {
414 #if PM_USE_SESSION_APIS
415 err = PMCreateSession((PMPrintSession *)macPrintSession) ;
416 #else
417 err = PMBegin() ;
418 #endif
419 wxASSERT( err == noErr ) ;
420 }
421 return err ;
422#endif
423}
424
425OSStatus UMAPrClose(void *macPrintSession)
426{
427#if !TARGET_CARBON
428 OSErr err = noErr ;
429 wxASSERT( gPrOpenCounter >= 1 ) ;
430 if ( gPrOpenCounter == 1 )
431 {
432 PrClose() ;
433 err = PrError() ;
434 wxASSERT( err == noErr ) ;
435 }
436 --gPrOpenCounter ;
437 return err ;
438#else
439 OSStatus err = noErr ;
440 wxASSERT( gPrOpenCounter >= 1 ) ;
441 if ( gPrOpenCounter == 1 )
442 {
443 #if PM_USE_SESSION_APIS
444 err = PMRelease(*(PMPrintSession *)macPrintSession) ;
445 *(PMPrintSession *)macPrintSession = kPMNoReference;
446 #else
447 err = PMEnd() ;
448 #endif
449 }
450 --gPrOpenCounter ;
451 return err ;
452#endif
453}
454
455#if !TARGET_CARBON
456
457pascal QDGlobalsPtr GetQDGlobalsPtr (void) ;
458pascal QDGlobalsPtr GetQDGlobalsPtr (void)
459{
460 return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA);
461}
462
463#endif
464
465void UMAShowWatchCursor()
466{
467 OSErr err = noErr;
468
469 CursHandle watchFob = GetCursor (watchCursor);
470
471 if (!watchFob)
472 err = nilHandleErr;
473 else
474 {
475 #if TARGET_CARBON
476// Cursor preservedArrow;
477// GetQDGlobalsArrow (&preservedArrow);
478// SetQDGlobalsArrow (*watchFob);
479// InitCursor ( );
480// SetQDGlobalsArrow (&preservedArrow);
481 SetCursor (*watchFob);
482 #else
483 SetCursor (*watchFob);
484 #endif
485 }
486}
487
488void UMAShowArrowCursor()
489{
490#if TARGET_CARBON
491 Cursor arrow;
492 SetCursor (GetQDGlobalsArrow (&arrow));
493#else
494 SetCursor (&(qd.arrow));
495#endif
496}
497
498// window manager
499
500GrafPtr UMAGetWindowPort( WindowRef inWindowRef )
501{
502 wxASSERT( inWindowRef != NULL ) ;
503#if TARGET_CARBON
504 return (GrafPtr) GetWindowPort( inWindowRef ) ;
505#else
506 return (GrafPtr) inWindowRef ;
507#endif
508}
509
510void UMADisposeWindow( WindowRef inWindowRef )
511{
512 wxASSERT( inWindowRef != NULL ) ;
513 DisposeWindow( inWindowRef ) ;
514}
515
516void UMASetWTitleC( WindowRef inWindowRef , const char *title )
517{
518 Str255 ptitle ;
519 strncpy( (char*)ptitle , title , 96 ) ;
520 ptitle[96] = 0 ;
521#if TARGET_CARBON
522 c2pstrcpy( ptitle, (char *)ptitle ) ;
523#else
524 c2pstr( (char*)ptitle ) ;
525#endif
526 SetWTitle( inWindowRef , ptitle ) ;
527}
528
529void UMAGetWTitleC( WindowRef inWindowRef , char *title )
530{
531 GetWTitle( inWindowRef , (unsigned char*)title ) ;
532#if TARGET_CARBON
533 p2cstrcpy( title, (unsigned char *)title ) ;
534#else
535 p2cstr( (unsigned char*)title ) ;
536#endif
537}
538
539// appearance additions
540
541void UMAActivateControl( ControlHandle inControl )
542{
543 // we have to add the control after again to the update rgn
544 // otherwise updates get lost
545 if ( !IsControlActive( inControl ) )
546 {
547 bool visible = IsControlVisible( inControl ) ;
548 if ( visible )
549 SetControlVisibility( inControl , false , false ) ;
550 ::ActivateControl( inControl ) ;
551 if ( visible ) {
552 SetControlVisibility( inControl , true , false ) ;
553 Rect ctrlBounds ;
554 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
555 }
556 }
557}
558
559void UMADrawControl( ControlHandle inControl )
560{
561 WindowRef theWindow = GetControlOwner(inControl) ;
562 RgnHandle updateRgn = NewRgn() ;
563 GetWindowUpdateRgn( theWindow , updateRgn ) ;
564 Point zero = { 0 , 0 } ;
565 LocalToGlobal( &zero ) ;
566 OffsetRgn( updateRgn , -zero.h , -zero.v ) ;
567 ::DrawControlInCurrentPort( inControl ) ;
568 InvalWindowRgn( theWindow, updateRgn) ;
569 DisposeRgn( updateRgn ) ;
570}
571
572void UMAMoveControl( ControlHandle inControl , short x , short y )
573{
574 bool visible = IsControlVisible( inControl ) ;
575 if ( visible ) {
576 SetControlVisibility( inControl , false , false ) ;
577 Rect ctrlBounds ;
578 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
579 }
580 ::MoveControl( inControl , x , y ) ;
581 if ( visible ) {
582 SetControlVisibility( inControl , true , false ) ;
583 Rect ctrlBounds ;
584 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
585 }
586}
587
588void UMASizeControl( ControlHandle inControl , short x , short y )
589{
590 bool visible = IsControlVisible( inControl ) ;
591 if ( visible ) {
592 SetControlVisibility( inControl , false , false ) ;
593 Rect ctrlBounds ;
594 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
595 }
596 ::SizeControl( inControl , x , y ) ;
597 if ( visible ) {
598 SetControlVisibility( inControl , true , false ) ;
599 Rect ctrlBounds ;
600 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
601 }
602}
603
604void UMADeactivateControl( ControlHandle inControl )
605{
606 // we have to add the control after again to the update rgn
607 // otherwise updates get lost
608 bool visible = IsControlVisible( inControl ) ;
609 if ( visible )
610 SetControlVisibility( inControl , false , false ) ;
611 ::DeactivateControl( inControl ) ;
612 if ( visible ) {
613 SetControlVisibility( inControl , true , false ) ;
614 Rect ctrlBounds ;
615 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
616 }
617}
618// shows the control and adds the region to the update region
619void UMAShowControl (ControlHandle inControl)
620{
621 SetControlVisibility( inControl , true , false ) ;
622 Rect ctrlBounds ;
623 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
624}
625
626// shows the control and adds the region to the update region
627void UMAHideControl (ControlHandle inControl)
628{
629 SetControlVisibility( inControl , false , false ) ;
630 Rect ctrlBounds ;
631 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
632}
633// keyboard focus
634OSErr UMASetKeyboardFocus (WindowPtr inWindow,
635 ControlHandle inControl,
636 ControlFocusPart inPart)
637{
638 OSErr err = noErr;
639 GrafPtr port ;
640 GetPort( &port ) ;
641
642 SetPortWindowPort( inWindow ) ;
643
644 err = SetKeyboardFocus( inWindow , inControl , inPart ) ;
645 SetPort( port ) ;
646 return err ;
647}
648
649
650
651
652// events
653void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn )
654{
655 RgnHandle updateRgn = NewRgn() ;
656 GetWindowUpdateRgn( inWindow , updateRgn ) ;
657
658 Point zero = { 0 , 0 } ;
659 LocalToGlobal( &zero ) ;
660 OffsetRgn( updateRgn , -zero.h , -zero.v ) ;
661
662 UpdateControls( inWindow , inRgn ) ;
663 InvalWindowRgn( inWindow, updateRgn) ;
664 DisposeRgn( updateRgn ) ;
665
666}
667
668bool UMAIsWindowFloating( WindowRef inWindow )
669{
670 WindowClass cl ;
671
672 GetWindowClass( inWindow , &cl ) ;
673 return cl == kFloatingWindowClass ;
674}
675
676bool UMAIsWindowModal( WindowRef inWindow )
677{
678 WindowClass cl ;
679
680 GetWindowClass( inWindow , &cl ) ;
681 return cl < kFloatingWindowClass ;
682}
683
684// others
685
686void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
687{
688 if ( inWindowRef )
689 {
690// bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
691// if ( inActivate != isHightlited )
692 GrafPtr port ;
693 GetPort( &port ) ;
694 SetPortWindowPort( inWindowRef ) ;
695 HiliteWindow( inWindowRef , inActivate ) ;
696 ControlHandle control = NULL ;
697 ::GetRootControl( inWindowRef , & control ) ;
698 if ( control )
699 {
700 if ( inActivate )
701 UMAActivateControl( control ) ;
702 else
703 UMADeactivateControl( control ) ;
704 }
705 SetPort( port ) ;
706 }
707}
708OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState )
709{
710 return ::DrawThemePlacard( inRect , inState ) ;
711}
712
713#if !TARGET_CARBON
714static OSStatus helpMenuStatus = noErr ;
715static MenuItemIndex firstCustomItemIndex = 0 ;
716#endif
717
718OSStatus UMAGetHelpMenu(
719 MenuRef * outHelpMenu,
720 MenuItemIndex * outFirstCustomItemIndex)
721{
722#if TARGET_CARBON
723 return HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ;
724#else
725 MenuRef helpMenuHandle ;
726 helpMenuStatus = HMGetHelpMenuHandle( &helpMenuHandle ) ;
727 if ( firstCustomItemIndex == 0 && helpMenuStatus == noErr )
728 {
729 firstCustomItemIndex = CountMenuItems( helpMenuHandle ) + 1 ;
730 }
731 if ( outFirstCustomItemIndex )
732 {
733 *outFirstCustomItemIndex = firstCustomItemIndex ;
734 }
735 *outHelpMenu = helpMenuHandle ;
736 return helpMenuStatus ;
737#endif
738}
739
740wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport)
741{
742 m_clip = NULL ;
743 Setup( newport ) ;
744}
745
746wxMacPortStateHelper::wxMacPortStateHelper()
747{
748 m_clip = NULL ;
749}
750
751void wxMacPortStateHelper::Setup( GrafPtr newport )
752{
753 GetPort( &m_oldPort ) ;
754 SetPort( newport ) ;
755 wxASSERT_MSG( m_clip == NULL , "Cannot call setup twice" ) ;
756 m_clip = NewRgn() ;
757 GetClip( m_clip );
758 m_textFont = GetPortTextFont( (CGrafPtr) newport);
759 m_textSize = GetPortTextSize( (CGrafPtr) newport);
760 m_textStyle = GetPortTextFace( (CGrafPtr) newport);
761 m_textMode = GetPortTextMode( (CGrafPtr) newport);
762 GetThemeDrawingState( &m_drawingState ) ;
763 m_currentPort = newport ;
764}
765void wxMacPortStateHelper::Clear()
766{
767 if ( m_clip )
768 {
769 DisposeRgn( m_clip ) ;
770 DisposeThemeDrawingState( m_drawingState ) ;
771 m_clip = NULL ;
772 }
773}
774
775wxMacPortStateHelper::~wxMacPortStateHelper()
776{
777 if ( m_clip )
778 {
779 SetPort( m_currentPort ) ;
780 SetClip( m_clip ) ;
781 DisposeRgn( m_clip ) ;
782 TextFont( m_textFont );
783 TextSize( m_textSize );
784 TextFace( m_textStyle );
785 TextMode( m_textMode );
786 SetThemeDrawingState( m_drawingState , true ) ;
787 SetPort( m_oldPort ) ;
788 }
789}
790