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