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