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