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