]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/uma.cpp
(hopefully) workaround for a carbon bug not always setting the modifiers event record...
[wxWidgets.git] / src / mac / carbon / uma.cpp
CommitLineData
03e11df5 1#include "wx/defs.h"
5fde6fcc 2#include "wx/dc.h"
03e11df5 3#include "wx/mac/uma.h"
b03e4fcd 4#include <MacTextEditor.h>
72e7876b 5
f5c6eb5c 6#ifndef __DARWIN__
a3d3d3bf
GD
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>
66a09d47
SC
13# else
14# include <Printing.h>
a3d3d3bf 15# endif
03e11df5 16#endif
5b781a67 17
72055702
SC
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
e7b596fb 23
72e7876b
SC
24static bool sUMAHasAppearance = false ;
25static long sUMAAppearanceVersion = 0 ;
0888ccc7 26static bool sUMAHasAquaLayout = false ;
0e5a4d20
SC
27static bool sUMASystemInitialized = false ;
28
72e7876b
SC
29extern int gAGABackgroundColor ;
30bool UMAHasAppearance() { return sUMAHasAppearance ; }
31long UMAGetAppearanceVersion() { return sUMAAppearanceVersion ; }
32
33static bool sUMAHasWindowManager = false ;
34static long sUMAWindowManagerAttr = 0 ;
35
36bool UMAHasWindowManager() { return sUMAHasWindowManager ; }
37long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr ; }
0888ccc7 38bool UMAHasAquaLayout() { return sUMAHasAquaLayout ; }
0e5a4d20 39bool UMASystemIsInitialized() { return sUMASystemInitialized ; }
72055702 40
5b781a67
SC
41void UMACleanupToolbox()
42{
5b781a67
SC
43 if ( sUMAHasAppearance )
44 {
45 UnregisterAppearanceClient() ;
46 }
5b781a67
SC
47 if ( NavServicesAvailable() )
48 {
49 NavUnload() ;
50 }
f8eebb95
SC
51 if ( TXNTerminateTextension != (void*) kUnresolvedCFragSymbolAddress )
52 TXNTerminateTextension( ) ;
5b781a67 53}
72e7876b
SC
54void UMAInitToolbox( UInt16 inMoreMastersCalls )
55{
56#if !TARGET_CARBON
57 ::MaxApplZone();
58 for (long i = 1; i <= inMoreMastersCalls; i++)
59 ::MoreMasters();
60
61 ::InitGraf(&qd.thePort);
62 ::InitFonts();
72e7876b
SC
63 ::InitMenus();
64 ::TEInit();
65 ::InitDialogs(0L);
66 ::FlushEvents(everyEvent, 0);
67 ::InitCursor();
68 long total,contig;
69 PurgeSpace(&total, &contig);
70#else
2f1ae414 71 InitCursor();
72e7876b
SC
72#endif
73
72e7876b
SC
74 long theAppearance ;
75 if ( Gestalt( gestaltAppearanceAttr, &theAppearance ) == noErr )
76 {
77 sUMAHasAppearance = true ;
78 RegisterAppearanceClient();
79 if ( Gestalt( gestaltAppearanceVersion, &theAppearance ) == noErr )
80 {
81 sUMAAppearanceVersion = theAppearance ;
82 }
83 else
84 {
85 sUMAAppearanceVersion = 0x0100 ;
86 }
87 }
72e7876b
SC
88 if ( Gestalt( gestaltWindowMgrAttr, &sUMAWindowManagerAttr ) == noErr )
89 {
90 sUMAHasWindowManager = sUMAWindowManagerAttr & gestaltWindowMgrPresent ;
91 }
5b781a67 92
8e8d3ba8
SC
93#if TARGET_CARBON
94// Call currently implicitely done : InitFloatingWindows() ;
95#else
5b781a67
SC
96 if ( sUMAHasWindowManager )
97 InitFloatingWindows() ;
98 else
99 InitWindows();
03e11df5 100#endif
5b781a67
SC
101
102 if ( NavServicesAvailable() )
103 {
104 NavLoad() ;
105 }
b03e4fcd 106
ded4fa5b
SC
107 long menuMgrAttr ;
108 Gestalt( gestaltMenuMgrAttr , &menuMgrAttr ) ;
109 if ( menuMgrAttr & gestaltMenuMgrAquaLayoutMask )
110 sUMAHasAquaLayout = true ;
111
f8eebb95
SC
112 if ( TXNInitTextension != (void*) kUnresolvedCFragSymbolAddress )
113 {
564bf1ea
SC
114 FontFamilyID fontId ;
115 Str255 fontName ;
116 SInt16 fontSize ;
117 Style fontStyle ;
118 GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
119 GetFNum( fontName, &fontId );
120
121 TXNMacOSPreferredFontDescription fontDescriptions[] =
122 {
123 { fontId , (fontSize << 16) ,kTXNDefaultFontStyle, kTXNSystemDefaultEncoding } ,
124 } ;
125 int noOfFontDescriptions = sizeof( fontDescriptions ) / sizeof(TXNMacOSPreferredFontDescription) ;
54ddeb7e 126#if 0 // TARGET_CARBON
564bf1ea
SC
127 --noOfFontDescriptions ;
128#endif
129 // kTXNAlwaysUseQuickDrawTextMask might be desirable because of speed increases but it crashes the app under OS X upon key stroke
54ddeb7e
SC
130 OptionBits options = kTXNWantMoviesMask | kTXNWantSoundMask | kTXNWantGraphicsMask ;
131#if TARGET_CARBON
132 if ( !UMAHasAquaLayout() )
133#endif
134 {
135 options |= kTXNAlwaysUseQuickDrawTextMask ;
136 }
137 TXNInitTextension(fontDescriptions, noOfFontDescriptions, options );
138 }
f8eebb95 139
ded4fa5b 140
0e5a4d20 141 sUMASystemInitialized = true ;
66a09d47 142
72e7876b
SC
143}
144
66a09d47
SC
145/*
146Boolean CanUseATSUI()
147 {
148 long result;
149 OSErr err = Gestalt(gestaltATSUVersion, &result);
150 return (err == noErr);
151 }
152*/
72e7876b
SC
153// process manager
154long UMAGetProcessMode()
155{
156 OSErr err ;
157 ProcessInfoRec processinfo;
158 ProcessSerialNumber procno ;
159
160 procno.highLongOfPSN = NULL ;
161 procno.lowLongOfPSN = kCurrentProcess ;
162 processinfo.processInfoLength = sizeof(ProcessInfoRec);
163 processinfo.processName = NULL;
164 processinfo.processAppSpec = NULL;
165
166 err = ::GetProcessInformation( &procno , &processinfo ) ;
167 wxASSERT( err == noErr ) ;
168 return processinfo.processMode ;
169}
170
171bool UMAGetProcessModeDoesActivateOnFGSwitch()
172{
173 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch ;
174}
175
176// menu manager
177
2f1ae414 178void UMASetMenuTitle( MenuRef menu , StringPtr title )
72e7876b 179{
76a5e5d2 180/*
72e7876b
SC
181#if !TARGET_CARBON
182 long size = GetHandleSize( (Handle) menu ) ;
183 const long headersize = 14 ;
184 int oldlen = (**menu).menuData[0] + 1;
185 int newlen = title[0] + 1 ;
186
187 if ( oldlen < newlen )
188 {
189 // enlarge before adjusting
190 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) );
191 }
192
193 if ( oldlen != newlen )
194 memmove( (char*) (**menu).menuData + newlen , (char*) (**menu).menuData + oldlen , size - headersize - oldlen ) ;
195
196 memcpy( (char*) (**menu).menuData , title , newlen ) ;
197 if ( oldlen > newlen )
198 {
199 // shrink after
200 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) ) ;
201 }
202#else
76a5e5d2 203*/
72e7876b 204 SetMenuTitle( menu , title ) ;
76a5e5d2 205//#endif
72e7876b
SC
206}
207
208UInt32 UMAMenuEvent( EventRecord *inEvent )
209{
72e7876b 210 return MenuEvent( inEvent ) ;
72e7876b
SC
211}
212
213void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem )
214{
72e7876b 215 EnableMenuItem( inMenu , inItem ) ;
72e7876b
SC
216}
217
218void UMADisableMenuItem( MenuRef inMenu , MenuItemIndex inItem )
219{
72e7876b 220 DisableMenuItem( inMenu , inItem ) ;
72e7876b 221}
2f1ae414
SC
222
223void UMAAppendSubMenuItem( MenuRef menu , StringPtr l , SInt16 id )
224{
225 Str255 label ;
226 memcpy( label , l , l[0]+1 ) ;
227 // hardcoded adding of the submenu combination for mac
228
229 int theEnd = label[0] + 1;
230 if (theEnd > 251)
231 theEnd = 251; // mac allows only 255 characters
232 label[theEnd++] = '/';
233 label[theEnd++] = hMenuCmd;
234 label[theEnd++] = '!';
235 label[theEnd++] = id ;
236 label[theEnd] = 0x00;
237 label[0] = theEnd;
238 MacAppendMenu(menu, label);
239}
240
241void UMAInsertSubMenuItem( MenuRef menu , StringPtr l , MenuItemIndex item , SInt16 id )
242{
243 Str255 label ;
244 memcpy( label , l , l[0]+1 ) ;
245 // hardcoded adding of the submenu combination for mac
246
247 int theEnd = label[0] + 1;
248 if (theEnd > 251)
249 theEnd = 251; // mac allows only 255 characters
250 label[theEnd++] = '/';
251 label[theEnd++] = hMenuCmd;
252 label[theEnd++] = '!';
253 label[theEnd++] = id;
254 label[theEnd] = 0x00;
255 label[0] = theEnd;
256 MacInsertMenuItem(menu, label , item);
257}
258
259void UMAAppendMenuItem( MenuRef menu , StringPtr l , SInt16 key, UInt8 modifiers )
260{
261 Str255 label ;
262 memcpy( label , l , l[0]+1 ) ;
263 if ( key )
264 {
265 int pos = label[0] ;
266 label[++pos] = '/';
267 label[++pos] = toupper( key );
268 label[0] = pos ;
269 }
270 MacAppendMenu( menu , label ) ;
271}
272
273void UMAInsertMenuItem( MenuRef menu , StringPtr l , MenuItemIndex item , SInt16 key, UInt8 modifiers )
274{
275 Str255 label ;
276 memcpy( label , l , l[0]+1 ) ;
277 if ( key )
278 {
279 int pos = label[0] ;
280 label[++pos] = '/';
281 label[++pos] = toupper( key );
282 label[0] = pos ;
283 }
284 MacInsertMenuItem( menu , label , item) ;
285}
286
72e7876b
SC
287// quickdraw
288
2f1ae414
SC
289int gPrOpenCounter = 0 ;
290
a3d3d3bf 291OSStatus UMAPrOpen(void *macPrintSession)
2f1ae414
SC
292{
293#if !TARGET_CARBON
294 OSErr err = noErr ;
295 ++gPrOpenCounter ;
296 if ( gPrOpenCounter == 1 )
297 {
298 PrOpen() ;
299 err = PrError() ;
300 wxASSERT( err == noErr ) ;
301 }
5b781a67 302 return err ;
2f1ae414 303#else
5b781a67
SC
304 OSStatus err = noErr ;
305 ++gPrOpenCounter ;
306 if ( gPrOpenCounter == 1 )
307 {
a689a4d0 308 #if PM_USE_SESSION_APIS
a3d3d3bf 309 err = PMCreateSession((PMPrintSession *)macPrintSession) ;
a689a4d0
GD
310 #else
311 err = PMBegin() ;
312 #endif
5b781a67
SC
313 wxASSERT( err == noErr ) ;
314 }
315 return err ;
2f1ae414
SC
316#endif
317}
318
a3d3d3bf 319OSStatus UMAPrClose(void *macPrintSession)
2f1ae414
SC
320{
321#if !TARGET_CARBON
322 OSErr err = noErr ;
323 wxASSERT( gPrOpenCounter >= 1 ) ;
324 if ( gPrOpenCounter == 1 )
325 {
326 PrClose() ;
327 err = PrError() ;
328 wxASSERT( err == noErr ) ;
329 }
330 --gPrOpenCounter ;
5b781a67 331 return err ;
2f1ae414 332#else
5b781a67
SC
333 OSStatus err = noErr ;
334 wxASSERT( gPrOpenCounter >= 1 ) ;
335 if ( gPrOpenCounter == 1 )
336 {
a689a4d0 337 #if PM_USE_SESSION_APIS
a3d3d3bf
GD
338 err = PMRelease(*(PMPrintSession *)macPrintSession) ;
339 *(PMPrintSession *)macPrintSession = kPMNoReference;
a689a4d0
GD
340 #else
341 err = PMEnd() ;
342 #endif
5b781a67
SC
343 }
344 --gPrOpenCounter ;
345 return err ;
2f1ae414
SC
346#endif
347}
348
72e7876b
SC
349#if !TARGET_CARBON
350
72055702 351pascal QDGlobalsPtr GetQDGlobalsPtr (void) ;
72e7876b
SC
352pascal QDGlobalsPtr GetQDGlobalsPtr (void)
353{
354 return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA);
355}
356
357#endif
358
359void UMAShowWatchCursor()
360{
361 OSErr err = noErr;
362
363 CursHandle watchFob = GetCursor (watchCursor);
364
365 if (!watchFob)
366 err = nilHandleErr;
367 else
368 {
369 #if TARGET_CARBON
72055702
SC
370// Cursor preservedArrow;
371// GetQDGlobalsArrow (&preservedArrow);
372// SetQDGlobalsArrow (*watchFob);
373// InitCursor ( );
374// SetQDGlobalsArrow (&preservedArrow);
375 SetCursor (*watchFob);
72e7876b
SC
376 #else
377 SetCursor (*watchFob);
378 #endif
379 }
380}
381
382void UMAShowArrowCursor()
383{
384#if TARGET_CARBON
385 Cursor arrow;
386 SetCursor (GetQDGlobalsArrow (&arrow));
387#else
388 SetCursor (&(qd.arrow));
389#endif
390}
391
392// window manager
393
394GrafPtr UMAGetWindowPort( WindowRef inWindowRef )
395{
396 wxASSERT( inWindowRef != NULL ) ;
397#if TARGET_CARBON
cf6674a4 398 return (GrafPtr) GetWindowPort( inWindowRef ) ;
72e7876b
SC
399#else
400 return (GrafPtr) inWindowRef ;
401#endif
402}
403
404void UMADisposeWindow( WindowRef inWindowRef )
405{
406 wxASSERT( inWindowRef != NULL ) ;
407 DisposeWindow( inWindowRef ) ;
408}
409
410void UMASetWTitleC( WindowRef inWindowRef , const char *title )
411{
412 Str255 ptitle ;
413 strncpy( (char*)ptitle , title , 96 ) ;
414 ptitle[96] = 0 ;
03e11df5
GD
415#if TARGET_CARBON
416 c2pstrcpy( ptitle, (char *)ptitle ) ;
417#else
72e7876b 418 c2pstr( (char*)ptitle ) ;
03e11df5 419#endif
72e7876b
SC
420 SetWTitle( inWindowRef , ptitle ) ;
421}
03e11df5 422
72e7876b
SC
423void UMAGetWTitleC( WindowRef inWindowRef , char *title )
424{
425 GetWTitle( inWindowRef , (unsigned char*)title ) ;
03e11df5
GD
426#if TARGET_CARBON
427 p2cstrcpy( title, (unsigned char *)title ) ;
428#else
72e7876b 429 p2cstr( (unsigned char*)title ) ;
03e11df5 430#endif
72e7876b
SC
431}
432
72e7876b
SC
433// appearance additions
434
435void UMAActivateControl( ControlHandle inControl )
436{
22e751a5
SC
437 // we have to add the control after again to the update rgn
438 // otherwise updates get lost
439 if ( !IsControlActive( inControl ) )
440 {
fdaf613a
SC
441 bool visible = IsControlVisible( inControl ) ;
442 if ( visible )
443 SetControlVisibility( inControl , false , false ) ;
3f4902f5 444 ::ActivateControl( inControl ) ;
fdaf613a
SC
445 if ( visible ) {
446 SetControlVisibility( inControl , true , false ) ;
c36f0244
SC
447 Rect ctrlBounds ;
448 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
fdaf613a 449 }
22e751a5 450 }
72e7876b
SC
451}
452
453void UMADrawControl( ControlHandle inControl )
454{
3f4902f5
GD
455 WindowRef theWindow = GetControlOwner(inControl) ;
456 RgnHandle updateRgn = NewRgn() ;
3f4902f5 457 GetWindowUpdateRgn( theWindow , updateRgn ) ;
22e751a5
SC
458 Point zero = { 0 , 0 } ;
459 LocalToGlobal( &zero ) ;
460 OffsetRgn( updateRgn , -zero.h , -zero.v ) ;
461 ::DrawControlInCurrentPort( inControl ) ;
462 InvalWindowRgn( theWindow, updateRgn) ;
463 DisposeRgn( updateRgn ) ;
72e7876b
SC
464}
465
466void UMAMoveControl( ControlHandle inControl , short x , short y )
467{
72055702
SC
468 bool visible = IsControlVisible( inControl ) ;
469 if ( visible ) {
470 SetControlVisibility( inControl , false , false ) ;
471 Rect ctrlBounds ;
472 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
473 }
474 ::MoveControl( inControl , x , y ) ;
475 if ( visible ) {
476 SetControlVisibility( inControl , true , false ) ;
477 Rect ctrlBounds ;
478 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
479 }
72e7876b
SC
480}
481
482void UMASizeControl( ControlHandle inControl , short x , short y )
483{
72055702
SC
484 bool visible = IsControlVisible( inControl ) ;
485 if ( visible ) {
486 SetControlVisibility( inControl , false , false ) ;
487 Rect ctrlBounds ;
488 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
b03e4fcd 489 }
72055702
SC
490 ::SizeControl( inControl , x , y ) ;
491 if ( visible ) {
492 SetControlVisibility( inControl , true , false ) ;
493 Rect ctrlBounds ;
494 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
495 }
72e7876b
SC
496}
497
498void UMADeactivateControl( ControlHandle inControl )
499{
22e751a5
SC
500 // we have to add the control after again to the update rgn
501 // otherwise updates get lost
72055702
SC
502 bool visible = IsControlVisible( inControl ) ;
503 if ( visible )
504 SetControlVisibility( inControl , false , false ) ;
505 ::DeactivateControl( inControl ) ;
506 if ( visible ) {
507 SetControlVisibility( inControl , true , false ) ;
508 Rect ctrlBounds ;
509 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
510 }
72e7876b 511}
fdaf613a 512// shows the control and adds the region to the update region
3f4902f5 513void UMAShowControl (ControlHandle inControl)
72e7876b 514{
fdaf613a 515 SetControlVisibility( inControl , true , false ) ;
c36f0244
SC
516 Rect ctrlBounds ;
517 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
72e7876b
SC
518}
519
22e751a5
SC
520// shows the control and adds the region to the update region
521void UMAHideControl (ControlHandle inControl)
522{
523 SetControlVisibility( inControl , false , false ) ;
524 Rect ctrlBounds ;
525 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
526}
72e7876b
SC
527// keyboard focus
528OSErr UMASetKeyboardFocus (WindowPtr inWindow,
529 ControlHandle inControl,
530 ControlFocusPart inPart)
531{
2f1ae414
SC
532 OSErr err = noErr;
533 GrafPtr port ;
534 GetPort( &port ) ;
72055702
SC
535
536 SetPortWindowPort( inWindow ) ;
537
72055702 538 err = SetKeyboardFocus( inWindow , inControl , inPart ) ;
2f1ae414
SC
539 SetPort( port ) ;
540 return err ;
72e7876b
SC
541}
542
543
544
545
546// events
72e7876b
SC
547void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn )
548{
72055702
SC
549 RgnHandle updateRgn = NewRgn() ;
550 GetWindowUpdateRgn( inWindow , updateRgn ) ;
551
be57fda6
SC
552 Point zero = { 0 , 0 } ;
553 LocalToGlobal( &zero ) ;
554 OffsetRgn( updateRgn , -zero.h , -zero.v ) ;
72e7876b 555
72055702
SC
556 UpdateControls( inWindow , inRgn ) ;
557 InvalWindowRgn( inWindow, updateRgn) ;
558 DisposeRgn( updateRgn ) ;
72e7876b 559
72e7876b
SC
560}
561
562bool UMAIsWindowFloating( WindowRef inWindow )
563{
564 WindowClass cl ;
565
72055702 566 GetWindowClass( inWindow , &cl ) ;
72e7876b
SC
567 return cl == kFloatingWindowClass ;
568}
569
570bool UMAIsWindowModal( WindowRef inWindow )
571{
572 WindowClass cl ;
573
72055702 574 GetWindowClass( inWindow , &cl ) ;
72e7876b
SC
575 return cl < kFloatingWindowClass ;
576}
577
578// others
579
580void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
581{
582 if ( inWindowRef )
583 {
584// bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
585// if ( inActivate != isHightlited )
c809f3be
SC
586 GrafPtr port ;
587 GetPort( &port ) ;
72055702 588 SetPortWindowPort( inWindowRef ) ;
c809f3be
SC
589 HiliteWindow( inWindowRef , inActivate ) ;
590 ControlHandle control = NULL ;
72055702 591 ::GetRootControl( inWindowRef , & control ) ;
c809f3be
SC
592 if ( control )
593 {
594 if ( inActivate )
595 UMAActivateControl( control ) ;
596 else
597 UMADeactivateControl( control ) ;
598 }
599 SetPort( port ) ;
72e7876b
SC
600 }
601}
2f1ae414
SC
602OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState )
603{
72055702 604 return ::DrawThemePlacard( inRect , inState ) ;
2f1ae414 605}
72e7876b 606
2f056c85 607#if !TARGET_CARBON
b03e4fcd 608static OSStatus helpMenuStatus = noErr ;
b03e4fcd 609static MenuItemIndex firstCustomItemIndex = 0 ;
2f056c85 610#endif
b03e4fcd
SC
611
612OSStatus UMAGetHelpMenu(
613 MenuRef * outHelpMenu,
614 MenuItemIndex * outFirstCustomItemIndex)
615{
616#if TARGET_CARBON
617 return HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ;
618#else
ca5e5bad
SC
619 MenuRef helpMenuHandle ;
620 helpMenuStatus = HMGetHelpMenuHandle( &helpMenuHandle ) ;
621 if ( firstCustomItemIndex == 0 && helpMenuStatus == noErr )
b03e4fcd 622 {
ca5e5bad 623 firstCustomItemIndex = CountMenuItems( helpMenuHandle ) + 1 ;
b03e4fcd
SC
624 }
625 if ( outFirstCustomItemIndex )
626 {
627 *outFirstCustomItemIndex = firstCustomItemIndex ;
628 }
629 *outHelpMenu = helpMenuHandle ;
630 return helpMenuStatus ;
631#endif
632}
76a5e5d2
SC
633
634wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport)
635{
636 m_clip = NULL ;
637 Setup( newport ) ;
638}
639
640wxMacPortStateHelper::wxMacPortStateHelper()
641{
642 m_clip = NULL ;
643}
644
645void wxMacPortStateHelper::Setup( GrafPtr newport )
646{
647 GetPort( &m_oldPort ) ;
648 SetPort( newport ) ;
649 wxASSERT_MSG( m_clip == NULL , "Cannot call setup twice" ) ;
650 m_clip = NewRgn() ;
651 GetClip( m_clip );
652 m_textFont = GetPortTextFont( (CGrafPtr) newport);
653 m_textSize = GetPortTextSize( (CGrafPtr) newport);
654 m_textStyle = GetPortTextFace( (CGrafPtr) newport);
655 m_textMode = GetPortTextMode( (CGrafPtr) newport);
656 GetThemeDrawingState( &m_drawingState ) ;
657 m_currentPort = newport ;
658}
659void wxMacPortStateHelper::Clear()
660{
661 if ( m_clip )
662 {
663 DisposeRgn( m_clip ) ;
664 DisposeThemeDrawingState( m_drawingState ) ;
665 m_clip = NULL ;
666 }
667}
668
669wxMacPortStateHelper::~wxMacPortStateHelper()
670{
671 if ( m_clip )
672 {
673 SetPort( m_currentPort ) ;
674 SetClip( m_clip ) ;
675 DisposeRgn( m_clip ) ;
676 TextFont( m_textFont );
677 TextSize( m_textSize );
678 TextFace( m_textStyle );
679 TextMode( m_textMode );
680 SetThemeDrawingState( m_drawingState , true ) ;
681 SetPort( m_oldPort ) ;
682 }
683}
684