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