]> git.saurik.com Git - wxWidgets.git/blame - src/mac/uma.cpp
try to create smaller executables
[wxWidgets.git] / src / mac / 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
bf918b97 183MenuRef UMANewMenu( SInt16 id , const wxString& title )
72e7876b 184{
bf918b97
SC
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}
72e7876b 199
bf918b97
SC
200void 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 ) ;
72e7876b 207#else
bf918b97
SC
208 Str255 ptitle ;
209 wxMacStringToPascal( str , ptitle ) ;
210 SetMenuTitle( menu , ptitle ) ;
211#endif
72e7876b
SC
212}
213
bf918b97 214void UMASetMenuItemText( MenuRef menu, MenuItemIndex item, const wxString& title )
72e7876b 215{
bf918b97
SC
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
72e7876b
SC
226}
227
bf918b97
SC
228
229UInt32 UMAMenuEvent( EventRecord *inEvent )
72e7876b 230{
bf918b97 231 return MenuEvent( inEvent ) ;
72e7876b
SC
232}
233
bf918b97 234void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem , bool enable)
72e7876b 235{
bf918b97
SC
236 if ( enable )
237 EnableMenuItem( inMenu , inItem ) ;
238 else
239 DisableMenuItem( inMenu , inItem ) ;
72e7876b 240}
2f1ae414 241
bf918b97 242void UMAAppendSubMenuItem( MenuRef menu , const wxString& title , SInt16 id )
2f1ae414 243{
bf918b97
SC
244 MacAppendMenu(menu, "\pA");
245 UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title );
867e99f5 246 SetMenuItemHierarchicalID( menu , CountMenuItems( menu ) , id ) ;
2f1ae414
SC
247}
248
bf918b97 249void UMAInsertSubMenuItem( MenuRef menu , const wxString& title , MenuItemIndex item , SInt16 id )
2f1ae414 250{
bf918b97
SC
251 MacInsertMenuItem(menu, "\pA" , item);
252 UMASetMenuItemText(menu, item , title );
867e99f5 253 SetMenuItemHierarchicalID( menu , item , id ) ;
2f1ae414
SC
254}
255
bf918b97 256void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEntry *entry )
2f1ae414 257{
bf918b97
SC
258 if ( !entry )
259 return ;
260
261 UInt8 modifiers = 0 ;
262 SInt16 key = entry->GetKeyCode() ;
2f1ae414
SC
263 if ( key )
264 {
bf918b97
SC
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
2b5f62a0
VZ
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 ;
bf918b97
SC
290 if ( !explicitCommandKey )
291 modifiers |= kMenuNoCommandModifier ;
292
293 switch( key )
2b5f62a0
VZ
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 }
bf918b97 411
2b5f62a0
VZ
412 SetItemCmd( menu, item , macKey );
413 SetMenuItemModifiers(menu, item , modifiers ) ;
414
415 if ( glyph )
416 SetMenuItemKeyGlyph(menu, item , glyph ) ;
2f1ae414 417 }
2b5f62a0
VZ
418}
419
bf918b97 420void UMAAppendMenuItem( MenuRef menu , const wxString& title , wxAcceleratorEntry *entry )
2b5f62a0
VZ
421{
422 MacAppendMenu(menu, "\pA");
bf918b97
SC
423 UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title );
424 UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), entry ) ;
2f1ae414
SC
425}
426
bf918b97 427void UMAInsertMenuItem( MenuRef menu , const wxString& title , MenuItemIndex item , wxAcceleratorEntry *entry )
2f1ae414 428{
2b5f62a0 429 MacInsertMenuItem( menu , "\p" , item) ;
bf918b97
SC
430 UMASetMenuItemText(menu, item , title );
431 UMASetMenuItemShortcut( menu , item , entry ) ;
2f1ae414
SC
432}
433
72e7876b
SC
434// quickdraw
435
2f1ae414
SC
436int gPrOpenCounter = 0 ;
437
a3d3d3bf 438OSStatus UMAPrOpen(void *macPrintSession)
2f1ae414
SC
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 }
5b781a67 449 return err ;
2f1ae414 450#else
5b781a67
SC
451 OSStatus err = noErr ;
452 ++gPrOpenCounter ;
453 if ( gPrOpenCounter == 1 )
454 {
a689a4d0 455 #if PM_USE_SESSION_APIS
a3d3d3bf 456 err = PMCreateSession((PMPrintSession *)macPrintSession) ;
a689a4d0
GD
457 #else
458 err = PMBegin() ;
459 #endif
5b781a67
SC
460 wxASSERT( err == noErr ) ;
461 }
462 return err ;
2f1ae414
SC
463#endif
464}
465
a3d3d3bf 466OSStatus UMAPrClose(void *macPrintSession)
2f1ae414
SC
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 ;
5b781a67 478 return err ;
2f1ae414 479#else
5b781a67
SC
480 OSStatus err = noErr ;
481 wxASSERT( gPrOpenCounter >= 1 ) ;
482 if ( gPrOpenCounter == 1 )
483 {
a689a4d0 484 #if PM_USE_SESSION_APIS
a3d3d3bf
GD
485 err = PMRelease(*(PMPrintSession *)macPrintSession) ;
486 *(PMPrintSession *)macPrintSession = kPMNoReference;
a689a4d0
GD
487 #else
488 err = PMEnd() ;
489 #endif
5b781a67
SC
490 }
491 --gPrOpenCounter ;
492 return err ;
2f1ae414
SC
493#endif
494}
495
72e7876b
SC
496#if !TARGET_CARBON
497
72055702 498pascal QDGlobalsPtr GetQDGlobalsPtr (void) ;
72e7876b
SC
499pascal QDGlobalsPtr GetQDGlobalsPtr (void)
500{
501 return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA);
502}
503
504#endif
505
506void 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
72055702
SC
517// Cursor preservedArrow;
518// GetQDGlobalsArrow (&preservedArrow);
519// SetQDGlobalsArrow (*watchFob);
520// InitCursor ( );
521// SetQDGlobalsArrow (&preservedArrow);
522 SetCursor (*watchFob);
72e7876b
SC
523 #else
524 SetCursor (*watchFob);
525 #endif
526 }
527}
528
529void 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
541GrafPtr UMAGetWindowPort( WindowRef inWindowRef )
542{
543 wxASSERT( inWindowRef != NULL ) ;
544#if TARGET_CARBON
cf6674a4 545 return (GrafPtr) GetWindowPort( inWindowRef ) ;
72e7876b
SC
546#else
547 return (GrafPtr) inWindowRef ;
548#endif
549}
550
551void UMADisposeWindow( WindowRef inWindowRef )
552{
553 wxASSERT( inWindowRef != NULL ) ;
554 DisposeWindow( inWindowRef ) ;
555}
556
557void UMASetWTitleC( WindowRef inWindowRef , const char *title )
558{
559 Str255 ptitle ;
560 strncpy( (char*)ptitle , title , 96 ) ;
561 ptitle[96] = 0 ;
03e11df5
GD
562#if TARGET_CARBON
563 c2pstrcpy( ptitle, (char *)ptitle ) ;
564#else
72e7876b 565 c2pstr( (char*)ptitle ) ;
03e11df5 566#endif
72e7876b
SC
567 SetWTitle( inWindowRef , ptitle ) ;
568}
03e11df5 569
72e7876b
SC
570void UMAGetWTitleC( WindowRef inWindowRef , char *title )
571{
572 GetWTitle( inWindowRef , (unsigned char*)title ) ;
03e11df5
GD
573#if TARGET_CARBON
574 p2cstrcpy( title, (unsigned char *)title ) ;
575#else
72e7876b 576 p2cstr( (unsigned char*)title ) ;
03e11df5 577#endif
72e7876b
SC
578}
579
72e7876b
SC
580// appearance additions
581
582void UMAActivateControl( ControlHandle inControl )
583{
22e751a5
SC
584 // we have to add the control after again to the update rgn
585 // otherwise updates get lost
586 if ( !IsControlActive( inControl ) )
587 {
fdaf613a
SC
588 bool visible = IsControlVisible( inControl ) ;
589 if ( visible )
590 SetControlVisibility( inControl , false , false ) ;
3f4902f5 591 ::ActivateControl( inControl ) ;
fdaf613a
SC
592 if ( visible ) {
593 SetControlVisibility( inControl , true , false ) ;
c36f0244
SC
594 Rect ctrlBounds ;
595 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
fdaf613a 596 }
22e751a5 597 }
72e7876b
SC
598}
599
600void UMADrawControl( ControlHandle inControl )
601{
3f4902f5
GD
602 WindowRef theWindow = GetControlOwner(inControl) ;
603 RgnHandle updateRgn = NewRgn() ;
3f4902f5 604 GetWindowUpdateRgn( theWindow , updateRgn ) ;
22e751a5
SC
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 ) ;
72e7876b
SC
611}
612
613void UMAMoveControl( ControlHandle inControl , short x , short y )
614{
72055702
SC
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 }
72e7876b
SC
627}
628
629void UMASizeControl( ControlHandle inControl , short x , short y )
630{
72055702
SC
631 bool visible = IsControlVisible( inControl ) ;
632 if ( visible ) {
633 SetControlVisibility( inControl , false , false ) ;
634 Rect ctrlBounds ;
635 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
b03e4fcd 636 }
72055702
SC
637 ::SizeControl( inControl , x , y ) ;
638 if ( visible ) {
639 SetControlVisibility( inControl , true , false ) ;
640 Rect ctrlBounds ;
641 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
642 }
72e7876b
SC
643}
644
645void UMADeactivateControl( ControlHandle inControl )
646{
22e751a5
SC
647 // we have to add the control after again to the update rgn
648 // otherwise updates get lost
72055702
SC
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 }
72e7876b 658}
fdaf613a 659// shows the control and adds the region to the update region
3f4902f5 660void UMAShowControl (ControlHandle inControl)
72e7876b 661{
fdaf613a 662 SetControlVisibility( inControl , true , false ) ;
c36f0244
SC
663 Rect ctrlBounds ;
664 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
72e7876b
SC
665}
666
22e751a5
SC
667// shows the control and adds the region to the update region
668void UMAHideControl (ControlHandle inControl)
669{
670 SetControlVisibility( inControl , false , false ) ;
671 Rect ctrlBounds ;
672 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
673}
72e7876b
SC
674// keyboard focus
675OSErr UMASetKeyboardFocus (WindowPtr inWindow,
676 ControlHandle inControl,
677 ControlFocusPart inPart)
678{
2f1ae414
SC
679 OSErr err = noErr;
680 GrafPtr port ;
681 GetPort( &port ) ;
72055702
SC
682
683 SetPortWindowPort( inWindow ) ;
684
72055702 685 err = SetKeyboardFocus( inWindow , inControl , inPart ) ;
2f1ae414
SC
686 SetPort( port ) ;
687 return err ;
72e7876b
SC
688}
689
690
691
692
693// events
72e7876b
SC
694void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn )
695{
72055702
SC
696 RgnHandle updateRgn = NewRgn() ;
697 GetWindowUpdateRgn( inWindow , updateRgn ) ;
698
be57fda6
SC
699 Point zero = { 0 , 0 } ;
700 LocalToGlobal( &zero ) ;
701 OffsetRgn( updateRgn , -zero.h , -zero.v ) ;
72e7876b 702
72055702
SC
703 UpdateControls( inWindow , inRgn ) ;
704 InvalWindowRgn( inWindow, updateRgn) ;
705 DisposeRgn( updateRgn ) ;
72e7876b 706
72e7876b
SC
707}
708
709bool UMAIsWindowFloating( WindowRef inWindow )
710{
711 WindowClass cl ;
712
72055702 713 GetWindowClass( inWindow , &cl ) ;
72e7876b
SC
714 return cl == kFloatingWindowClass ;
715}
716
717bool UMAIsWindowModal( WindowRef inWindow )
718{
719 WindowClass cl ;
720
72055702 721 GetWindowClass( inWindow , &cl ) ;
72e7876b
SC
722 return cl < kFloatingWindowClass ;
723}
724
725// others
726
727void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
728{
729 if ( inWindowRef )
730 {
731// bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
732// if ( inActivate != isHightlited )
c809f3be
SC
733 GrafPtr port ;
734 GetPort( &port ) ;
72055702 735 SetPortWindowPort( inWindowRef ) ;
c809f3be
SC
736 HiliteWindow( inWindowRef , inActivate ) ;
737 ControlHandle control = NULL ;
72055702 738 ::GetRootControl( inWindowRef , & control ) ;
c809f3be
SC
739 if ( control )
740 {
741 if ( inActivate )
742 UMAActivateControl( control ) ;
743 else
744 UMADeactivateControl( control ) ;
745 }
746 SetPort( port ) ;
72e7876b
SC
747 }
748}
2f1ae414
SC
749OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState )
750{
72055702 751 return ::DrawThemePlacard( inRect , inState ) ;
2f1ae414 752}
72e7876b 753
2f056c85 754#if !TARGET_CARBON
b03e4fcd 755static OSStatus helpMenuStatus = noErr ;
b03e4fcd 756static MenuItemIndex firstCustomItemIndex = 0 ;
2f056c85 757#endif
b03e4fcd
SC
758
759OSStatus UMAGetHelpMenu(
760 MenuRef * outHelpMenu,
761 MenuItemIndex * outFirstCustomItemIndex)
762{
763#if TARGET_CARBON
764 return HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ;
765#else
ca5e5bad
SC
766 MenuRef helpMenuHandle ;
767 helpMenuStatus = HMGetHelpMenuHandle( &helpMenuHandle ) ;
768 if ( firstCustomItemIndex == 0 && helpMenuStatus == noErr )
b03e4fcd 769 {
ca5e5bad 770 firstCustomItemIndex = CountMenuItems( helpMenuHandle ) + 1 ;
b03e4fcd
SC
771 }
772 if ( outFirstCustomItemIndex )
773 {
774 *outFirstCustomItemIndex = firstCustomItemIndex ;
775 }
776 *outHelpMenu = helpMenuHandle ;
777 return helpMenuStatus ;
778#endif
779}
76a5e5d2
SC
780
781wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport)
782{
783 m_clip = NULL ;
784 Setup( newport ) ;
785}
786
787wxMacPortStateHelper::wxMacPortStateHelper()
788{
789 m_clip = NULL ;
790}
791
792void 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}
806void wxMacPortStateHelper::Clear()
807{
808 if ( m_clip )
809 {
810 DisposeRgn( m_clip ) ;
811 DisposeThemeDrawingState( m_drawingState ) ;
812 m_clip = NULL ;
813 }
814}
815
816wxMacPortStateHelper::~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