]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/uma.cpp
recursive tab processing
[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
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
168 OptionBits options = 0 ;
169
170 if ( UMAGetSystemVersion() < 0x1000 )
171 {
172 options |= kTXNAlwaysUseQuickDrawTextMask ;
173 }
174 TXNInitTextension(fontDescriptions, noOfFontDescriptions, options );
175 }
176
177
178 UMASetSystemIsInitialized(true);
179
180 }
181
182 /*
183 Boolean CanUseATSUI()
184 {
185 long result;
186 OSErr err = Gestalt(gestaltATSUVersion, &result);
187 return (err == noErr);
188 }
189 */
190 // process manager
191 long UMAGetProcessMode()
192 {
193 OSErr err ;
194 ProcessInfoRec processinfo;
195 ProcessSerialNumber procno ;
196
197 procno.highLongOfPSN = NULL ;
198 procno.lowLongOfPSN = kCurrentProcess ;
199 processinfo.processInfoLength = sizeof(ProcessInfoRec);
200 processinfo.processName = NULL;
201 processinfo.processAppSpec = NULL;
202
203 err = ::GetProcessInformation( &procno , &processinfo ) ;
204 wxASSERT( err == noErr ) ;
205 return processinfo.processMode ;
206 }
207
208 bool UMAGetProcessModeDoesActivateOnFGSwitch()
209 {
210 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch ;
211 }
212
213 // menu manager
214
215 MenuRef UMANewMenu( SInt16 id , const wxString& title , wxFontEncoding encoding )
216 {
217 wxString str = wxStripMenuCodes( title ) ;
218 MenuRef menu ;
219 #if TARGET_CARBON
220 CreateNewMenu( id , 0 , &menu ) ;
221 SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding ) ) ;
222 #else
223 Str255 ptitle ;
224 wxMacStringToPascal( str , ptitle ) ;
225 menu = ::NewMenu( id , ptitle ) ;
226 #endif
227 return menu ;
228 }
229
230 void UMASetMenuTitle( MenuRef menu , const wxString& title , wxFontEncoding encoding)
231 {
232 wxString str = wxStripMenuCodes( title ) ;
233 #if TARGET_CARBON
234 SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding) ) ;
235 #else
236 Str255 ptitle ;
237 wxMacStringToPascal( str , ptitle ) ;
238 SetMenuTitle( menu , ptitle ) ;
239 #endif
240 }
241
242 void UMASetMenuItemText( MenuRef menu, MenuItemIndex item, const wxString& title , wxFontEncoding encoding)
243 {
244 wxString str = wxStripMenuCodes( title ) ;
245 #if TARGET_CARBON
246 SetMenuItemTextWithCFString( menu , item , wxMacCFStringHolder(str , encoding) ) ;
247 #else
248 Str255 ptitle ;
249 wxMacStringToPascal( str , ptitle ) ;
250 SetMenuItemText( menu , item , ptitle ) ;
251 #endif
252 }
253
254
255 UInt32 UMAMenuEvent( EventRecord *inEvent )
256 {
257 return MenuEvent( inEvent ) ;
258 }
259
260 void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem , bool enable)
261 {
262 if ( enable )
263 EnableMenuItem( inMenu , inItem ) ;
264 else
265 DisableMenuItem( inMenu , inItem ) ;
266 }
267
268 void UMAAppendSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , SInt16 id )
269 {
270 MacAppendMenu(menu, "\pA");
271 UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title , encoding );
272 SetMenuItemHierarchicalID( menu , CountMenuItems( menu ) , id ) ;
273 }
274
275 void UMAInsertSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , SInt16 id )
276 {
277 MacInsertMenuItem(menu, "\pA" , item);
278 UMASetMenuItemText(menu, item , title , encoding);
279 SetMenuItemHierarchicalID( menu , item , id ) ;
280 }
281
282 void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEntry *entry )
283 {
284 if ( !entry )
285 return ;
286
287 UInt8 modifiers = 0 ;
288 SInt16 key = entry->GetKeyCode() ;
289 if ( key )
290 {
291 bool explicitCommandKey = false ;
292
293 if ( entry->GetFlags() & wxACCEL_CTRL )
294 {
295 explicitCommandKey = true ;
296 }
297
298 if (entry->GetFlags() & wxACCEL_ALT )
299 {
300 modifiers |= kMenuOptionModifier ;
301 }
302
303 if (entry->GetFlags() & wxACCEL_SHIFT)
304 {
305 modifiers |= kMenuShiftModifier ;
306 }
307
308 SInt16 glyph = 0 ;
309 SInt16 macKey = key ;
310 if ( key >= WXK_F1 && key <= WXK_F15 )
311 {
312 // for some reasons this must be 0 right now
313 // everything else leads to just the first function key item
314 // to be selected. Thanks to Ryan Wilcox for finding out.
315 macKey = 0 ;
316 glyph = kMenuF1Glyph + ( key - WXK_F1 ) ;
317 if ( key >= WXK_F13 )
318 glyph += 13 ;
319 if ( !explicitCommandKey )
320 modifiers |= kMenuNoCommandModifier ;
321 }
322 else
323 {
324 switch( key )
325 {
326 case WXK_BACK :
327 macKey = kBackspaceCharCode ;
328 glyph = kMenuDeleteLeftGlyph ;
329 break ;
330 case WXK_TAB :
331 macKey = kTabCharCode ;
332 glyph = kMenuTabRightGlyph ;
333 break ;
334 case kEnterCharCode :
335 macKey = kEnterCharCode ;
336 glyph = kMenuEnterGlyph ;
337 break ;
338 case WXK_RETURN :
339 macKey = kReturnCharCode ;
340 glyph = kMenuReturnGlyph ;
341 break ;
342 case WXK_ESCAPE :
343 macKey = kEscapeCharCode ;
344 glyph = kMenuEscapeGlyph ;
345 break ;
346 case WXK_SPACE :
347 macKey = ' ' ;
348 glyph = kMenuSpaceGlyph ;
349 break ;
350 case WXK_DELETE :
351 macKey = kDeleteCharCode ;
352 glyph = kMenuDeleteRightGlyph ;
353 break ;
354 case WXK_CLEAR :
355 macKey = kClearCharCode ;
356 glyph = kMenuClearGlyph ;
357 break ;
358 case WXK_PRIOR : // PAGE UP
359 macKey = kPageUpCharCode ;
360 glyph = kMenuPageUpGlyph ;
361 break ;
362 case WXK_NEXT :
363 macKey = kPageDownCharCode ;
364 glyph = kMenuPageDownGlyph ;
365 break ;
366 case WXK_LEFT :
367 macKey = kLeftArrowCharCode ;
368 glyph = kMenuLeftArrowGlyph ;
369 break ;
370 case WXK_UP :
371 macKey = kUpArrowCharCode ;
372 glyph = kMenuUpArrowGlyph ;
373 break ;
374 case WXK_RIGHT :
375 macKey = kRightArrowCharCode ;
376 glyph = kMenuRightArrowGlyph ;
377 break ;
378 case WXK_DOWN :
379 macKey = kDownArrowCharCode ;
380 glyph = kMenuDownArrowGlyph ;
381 break ;
382 }
383 }
384
385 SetItemCmd( menu, item , macKey );
386 SetMenuItemModifiers(menu, item , modifiers ) ;
387
388 if ( glyph )
389 SetMenuItemKeyGlyph(menu, item , glyph ) ;
390 }
391 }
392
393 void UMAAppendMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , wxAcceleratorEntry *entry )
394 {
395 MacAppendMenu(menu, "\pA");
396 UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title , encoding );
397 UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), entry ) ;
398 }
399
400 void UMAInsertMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , wxAcceleratorEntry *entry )
401 {
402 MacInsertMenuItem( menu , "\pA" , item) ;
403 UMASetMenuItemText(menu, item+1 , title , encoding );
404 UMASetMenuItemShortcut( menu , item+1 , entry ) ;
405 }
406
407 // quickdraw
408
409 #if !TARGET_CARBON
410
411 int gPrOpenCounter = 0 ;
412
413 OSStatus UMAPrOpen()
414 {
415 OSErr err = noErr ;
416 ++gPrOpenCounter ;
417 if ( gPrOpenCounter == 1 )
418 {
419 PrOpen() ;
420 err = PrError() ;
421 wxASSERT( err == noErr ) ;
422 }
423 return err ;
424 }
425
426 OSStatus UMAPrClose()
427 {
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 }
439
440 pascal QDGlobalsPtr GetQDGlobalsPtr (void) ;
441 pascal QDGlobalsPtr GetQDGlobalsPtr (void)
442 {
443 return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA);
444 }
445
446 #endif
447
448 void UMAShowWatchCursor()
449 {
450 OSErr err = noErr;
451
452 CursHandle watchFob = GetCursor (watchCursor);
453
454 if (!watchFob)
455 err = nilHandleErr;
456 else
457 {
458 #if TARGET_CARBON
459 // Cursor preservedArrow;
460 // GetQDGlobalsArrow (&preservedArrow);
461 // SetQDGlobalsArrow (*watchFob);
462 // InitCursor ( );
463 // SetQDGlobalsArrow (&preservedArrow);
464 SetCursor (*watchFob);
465 #else
466 SetCursor (*watchFob);
467 #endif
468 }
469 }
470
471 void UMAShowArrowCursor()
472 {
473 #if TARGET_CARBON
474 Cursor arrow;
475 SetCursor (GetQDGlobalsArrow (&arrow));
476 #else
477 SetCursor (&(qd.arrow));
478 #endif
479 }
480
481 // window manager
482
483 GrafPtr UMAGetWindowPort( WindowRef inWindowRef )
484 {
485 wxASSERT( inWindowRef != NULL ) ;
486 #if TARGET_CARBON
487 return (GrafPtr) GetWindowPort( inWindowRef ) ;
488 #else
489 return (GrafPtr) inWindowRef ;
490 #endif
491 }
492
493 void UMADisposeWindow( WindowRef inWindowRef )
494 {
495 wxASSERT( inWindowRef != NULL ) ;
496 DisposeWindow( inWindowRef ) ;
497 }
498
499 void UMASetWTitle( WindowRef inWindowRef , const wxString& title , wxFontEncoding encoding)
500 {
501 #if TARGET_CARBON
502 SetWindowTitleWithCFString( inWindowRef , wxMacCFStringHolder(title , encoding) ) ;
503 #else
504 Str255 ptitle ;
505 wxMacStringToPascal( title , ptitle ) ;
506 SetWTitle( inWindowRef , ptitle ) ;
507 #endif
508 }
509
510 // appearance additions
511
512 void UMASetControlTitle( ControlRef inControl , const wxString& title , wxFontEncoding encoding)
513 {
514 #if TARGET_CARBON
515 SetControlTitleWithCFString( inControl , wxMacCFStringHolder(title , encoding) ) ;
516 #else
517 Str255 ptitle ;
518 wxMacStringToPascal( title , ptitle ) ;
519 SetControlTitle( inControl , ptitle ) ;
520 #endif
521 }
522
523 void UMAActivateControl( ControlRef inControl )
524 {
525 #if !TARGET_API_MAC_OSX
526 // we have to add the control after again to the update rgn
527 // otherwise updates get lost
528 if ( !IsControlActive( inControl ) )
529 {
530 bool visible = IsControlVisible( inControl ) ;
531 if ( visible )
532 SetControlVisibility( inControl , false , false ) ;
533 #endif
534 ::ActivateControl( inControl ) ;
535 #if !TARGET_API_MAC_OSX
536 if ( visible ) {
537 SetControlVisibility( inControl , true , false ) ;
538
539 Rect ctrlBounds ;
540 InvalWindowRect(GetControlOwner(inControl),UMAGetControlBoundsInWindowCoords(inControl,&ctrlBounds) ) ;
541 }
542 }
543 #endif
544 }
545
546 void UMAMoveControl( ControlRef inControl , short x , short y )
547 {
548 #if !TARGET_API_MAC_OSX
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 #endif
556 ::MoveControl( inControl , x , y ) ;
557 #if !TARGET_API_MAC_OSX
558 if ( visible ) {
559 SetControlVisibility( inControl , true , false ) ;
560 Rect ctrlBounds ;
561 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
562 }
563 #endif
564 }
565
566 void UMASizeControl( ControlRef inControl , short x , short y )
567 {
568 #if !TARGET_API_MAC_OSX
569 bool visible = IsControlVisible( inControl ) ;
570 if ( visible ) {
571 SetControlVisibility( inControl , false , false ) ;
572 Rect ctrlBounds ;
573 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
574 }
575 #endif
576 ::SizeControl( inControl , x , y ) ;
577 #if !TARGET_API_MAC_OSX
578 if ( visible ) {
579 SetControlVisibility( inControl , true , false ) ;
580 Rect ctrlBounds ;
581 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
582 }
583 #endif
584 }
585
586 void UMADeactivateControl( ControlRef inControl )
587 {
588 #if !TARGET_API_MAC_OSX
589 // we have to add the control after again to the update rgn
590 // otherwise updates get lost
591 bool visible = IsControlVisible( inControl ) ;
592 if ( visible )
593 SetControlVisibility( inControl , false , false ) ;
594 #endif
595 ::DeactivateControl( inControl ) ;
596 #if !TARGET_API_MAC_OSX
597 if ( visible ) {
598 SetControlVisibility( inControl , true , false ) ;
599 Rect ctrlBounds ;
600 InvalWindowRect(GetControlOwner(inControl),UMAGetControlBoundsInWindowCoords(inControl,&ctrlBounds) ) ;
601 }
602 #endif
603 }
604 // shows the control and adds the region to the update region
605 void UMAShowControl (ControlRef inControl)
606 {
607 SetControlVisibility( inControl , true , false ) ;
608 Rect ctrlBounds ;
609 InvalWindowRect(GetControlOwner(inControl),UMAGetControlBoundsInWindowCoords(inControl,&ctrlBounds) ) ;
610 }
611
612 // hides the control and adds the region to the update region
613 void UMAHideControl (ControlRef inControl)
614 {
615 SetControlVisibility( inControl , false , false ) ;
616 Rect ctrlBounds ;
617 InvalWindowRect(GetControlOwner(inControl),UMAGetControlBoundsInWindowCoords(inControl,&ctrlBounds) ) ;
618 }
619 // keyboard focus
620 OSErr UMASetKeyboardFocus (WindowPtr inWindow,
621 ControlRef inControl,
622 ControlFocusPart inPart)
623 {
624 OSErr err = noErr;
625 GrafPtr port ;
626 GetPort( &port ) ;
627
628 SetPortWindowPort( inWindow ) ;
629
630 err = SetKeyboardFocus( inWindow , inControl , inPart ) ;
631 SetPort( port ) ;
632 return err ;
633 }
634
635 // events
636 void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn )
637 {
638 wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) inWindow) ) ;
639 RgnHandle updateRgn = NewRgn() ;
640 GetWindowUpdateRgn( inWindow , updateRgn ) ;
641
642 Point zero = { 0 , 0 } ;
643 LocalToGlobal( &zero ) ;
644 OffsetRgn( updateRgn , -zero.h , -zero.v ) ;
645
646 UpdateControls( inWindow , inRgn ) ;
647 InvalWindowRgn( inWindow, updateRgn) ;
648 DisposeRgn( updateRgn ) ;
649 }
650
651 bool UMAIsWindowFloating( WindowRef inWindow )
652 {
653 WindowClass cl ;
654
655 GetWindowClass( inWindow , &cl ) ;
656 return cl == kFloatingWindowClass ;
657 }
658
659 bool UMAIsWindowModal( WindowRef inWindow )
660 {
661 WindowClass cl ;
662
663 GetWindowClass( inWindow , &cl ) ;
664 return cl < kFloatingWindowClass ;
665 }
666
667 // others
668
669 void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
670 {
671 if ( inWindowRef )
672 {
673 // bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
674 // if ( inActivate != isHightlited )
675 GrafPtr port ;
676 GetPort( &port ) ;
677 SetPortWindowPort( inWindowRef ) ;
678 HiliteWindow( inWindowRef , inActivate ) ;
679 ControlRef control = NULL ;
680 ::GetRootControl( inWindowRef , & control ) ;
681 if ( control )
682 {
683 if ( inActivate )
684 UMAActivateControl( control ) ;
685 else
686 UMADeactivateControl( control ) ;
687 }
688 SetPort( port ) ;
689 }
690 }
691
692 OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState )
693 {
694 return ::DrawThemePlacard( inRect , inState ) ;
695 }
696
697 #if !TARGET_CARBON
698 static OSStatus helpMenuStatus = noErr ;
699 static MenuItemIndex firstCustomItemIndex = 0 ;
700 #endif
701
702 OSStatus UMAGetHelpMenu(
703 MenuRef * outHelpMenu,
704 MenuItemIndex * outFirstCustomItemIndex)
705 {
706 #if TARGET_CARBON
707 return HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ;
708 #else
709 MenuRef helpMenuHandle ;
710 helpMenuStatus = HMGetHelpMenuHandle( &helpMenuHandle ) ;
711 if ( firstCustomItemIndex == 0 && helpMenuStatus == noErr )
712 {
713 firstCustomItemIndex = CountMenuItems( helpMenuHandle ) + 1 ;
714 }
715 if ( outFirstCustomItemIndex )
716 {
717 *outFirstCustomItemIndex = firstCustomItemIndex ;
718 }
719 *outHelpMenu = helpMenuHandle ;
720 return helpMenuStatus ;
721 #endif
722 }
723
724 wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport)
725 {
726 m_clip = NULL ;
727 Setup( newport ) ;
728 }
729
730 wxMacPortStateHelper::wxMacPortStateHelper()
731 {
732 m_clip = NULL ;
733 }
734
735 void wxMacPortStateHelper::Setup( GrafPtr newport )
736 {
737 GetPort( &m_oldPort ) ;
738 SetPort( newport ) ;
739 SetOrigin(0,0);
740 wxASSERT_MSG( m_clip == NULL , wxT("Cannot call setup twice") ) ;
741 m_clip = NewRgn() ;
742 GetClip( m_clip );
743 m_textFont = GetPortTextFont( (CGrafPtr) newport);
744 m_textSize = GetPortTextSize( (CGrafPtr) newport);
745 m_textStyle = GetPortTextFace( (CGrafPtr) newport);
746 m_textMode = GetPortTextMode( (CGrafPtr) newport);
747 GetThemeDrawingState( &m_drawingState ) ;
748 m_currentPort = newport ;
749 }
750 void wxMacPortStateHelper::Clear()
751 {
752 if ( m_clip )
753 {
754 DisposeRgn( m_clip ) ;
755 DisposeThemeDrawingState( m_drawingState ) ;
756 m_clip = NULL ;
757 }
758 }
759
760 wxMacPortStateHelper::~wxMacPortStateHelper()
761 {
762 if ( m_clip )
763 {
764 SetPort( m_currentPort ) ;
765 SetClip( m_clip ) ;
766 DisposeRgn( m_clip ) ;
767 TextFont( m_textFont );
768 TextSize( m_textSize );
769 TextFace( m_textStyle );
770 TextMode( m_textMode );
771 SetThemeDrawingState( m_drawingState , true ) ;
772 SetPort( m_oldPort ) ;
773 }
774 }
775
776 OSStatus UMAPutScrap( Size size , OSType type , void *data )
777 {
778 OSStatus err = noErr ;
779 #if !TARGET_CARBON
780 err = PutScrap( size , type , data ) ;
781 #else
782 ScrapRef scrap;
783 err = GetCurrentScrap (&scrap);
784 if ( !err )
785 {
786 err = PutScrapFlavor (scrap, type , 0, size, data);
787 }
788 #endif
789 return err ;
790 }
791
792 Rect* UMAGetControlBoundsInWindowCoords(ControlRef theControl, Rect *bounds)
793 {
794 wxWindow* win = wxFindControlFromMacControl( theControl ) ;
795
796 GetControlBounds( theControl , bounds ) ;
797 #if TARGET_API_MAC_OSX
798 if ( win != NULL && win->MacGetTopLevelWindow() != NULL )
799 {
800 int x , y ;
801 x = 0 ;
802 y = 0 ;
803
804 win->GetParent()->MacWindowToRootWindow( &x , & y ) ;
805 bounds->left += x ;
806 bounds->right += x ;
807 bounds->top += y ;
808 bounds->bottom += y ;
809 }
810 #endif
811 return bounds ;
812 }
813
814
815 #endif // wxUSE_GUI
816
817 #if wxUSE_BASE
818
819 static bool sUMASystemInitialized = false ;
820
821 bool UMASystemIsInitialized()
822 {
823 return sUMASystemInitialized ;
824 }
825
826 void UMASetSystemIsInitialized(bool val)
827 {
828 sUMASystemInitialized = val;
829 }
830
831
832 #endif // wxUSE_BASE