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