]> git.saurik.com Git - wxWidgets.git/blame - src/mac/uma.cpp
Watcom 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
58751a86 36// windows manager, control manager, navigation services etc. are
72055702 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 92 sUMASystemVersion = 0x0000 ;
58751a86 93
e40298d5
JS
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 }
58751a86 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 132 if ( TXNInitTextension != (void*) kUnresolvedCFragSymbolAddress )
58751a86 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) ;
58751a86 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 173// process manager
58751a86 174long UMAGetProcessMode()
72e7876b 175{
58751a86 176 OSErr err ;
e40298d5
JS
177 ProcessInfoRec processinfo;
178 ProcessSerialNumber procno ;
58751a86 179
e40298d5
JS
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
58751a86 191bool UMAGetProcessModeDoesActivateOnFGSwitch()
72e7876b 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
58751a86 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
58751a86 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
58751a86 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
58751a86 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 ;
58751a86 269
e40298d5
JS
270 UInt8 modifiers = 0 ;
271 SInt16 key = entry->GetKeyCode() ;
272 if ( key )
273 {
274 bool explicitCommandKey = false ;
275
58751a86 276 if ( entry->GetFlags() & wxACCEL_CTRL )
e40298d5
JS
277 {
278 explicitCommandKey = true ;
279 }
280
58751a86 281 if (entry->GetFlags() & wxACCEL_ALT )
e40298d5
JS
282 {
283 modifiers |= kMenuOptionModifier ;
284 }
285
58751a86 286 if (entry->GetFlags() & wxACCEL_SHIFT)
e40298d5
JS
287 {
288 modifiers |= kMenuShiftModifier ;
289 }
290
291 SInt16 glyph = 0 ;
292 SInt16 macKey = key ;
293 if ( key >= WXK_F1 && key <= WXK_F15 )
294 {
a5c1f8ca
SC
295 // for some reasons this must be 0 right now
296 // everything else leads to just the first function key item
297 // to be selected. Thanks to Ryan Wilcox for finding out.
298 macKey = 0 ;
e40298d5
JS
299 glyph = kMenuF1Glyph + ( key - WXK_F1 ) ;
300 if ( key >= WXK_F13 )
301 glyph += 13 ;
bf918b97 302 if ( !explicitCommandKey )
e40298d5 303 modifiers |= kMenuNoCommandModifier ;
e40298d5
JS
304 }
305 else
306 {
307 switch( key )
308 {
309 case WXK_BACK :
310 macKey = kBackspaceCharCode ;
311 glyph = kMenuDeleteLeftGlyph ;
312 break ;
313 case WXK_TAB :
314 macKey = kTabCharCode ;
315 glyph = kMenuTabRightGlyph ;
316 break ;
317 case kEnterCharCode :
318 macKey = kEnterCharCode ;
319 glyph = kMenuEnterGlyph ;
320 break ;
321 case WXK_RETURN :
322 macKey = kReturnCharCode ;
323 glyph = kMenuReturnGlyph ;
324 break ;
325 case WXK_ESCAPE :
326 macKey = kEscapeCharCode ;
327 glyph = kMenuEscapeGlyph ;
328 break ;
329 case WXK_SPACE :
330 macKey = ' ' ;
331 glyph = kMenuSpaceGlyph ;
332 break ;
333 case WXK_DELETE :
334 macKey = kDeleteCharCode ;
335 glyph = kMenuDeleteRightGlyph ;
336 break ;
337 case WXK_CLEAR :
338 macKey = kClearCharCode ;
339 glyph = kMenuClearGlyph ;
340 break ;
341 case WXK_PRIOR : // PAGE UP
342 macKey = kPageUpCharCode ;
343 glyph = kMenuPageUpGlyph ;
344 break ;
345 case WXK_NEXT :
346 macKey = kPageDownCharCode ;
347 glyph = kMenuPageDownGlyph ;
348 break ;
349 case WXK_LEFT :
350 macKey = kLeftArrowCharCode ;
351 glyph = kMenuLeftArrowGlyph ;
352 break ;
353 case WXK_UP :
354 macKey = kUpArrowCharCode ;
355 glyph = kMenuUpArrowGlyph ;
356 break ;
357 case WXK_RIGHT :
358 macKey = kRightArrowCharCode ;
359 glyph = kMenuRightArrowGlyph ;
360 break ;
361 case WXK_DOWN :
362 macKey = kDownArrowCharCode ;
363 glyph = kMenuDownArrowGlyph ;
364 break ;
2b5f62a0
VZ
365 }
366 }
bf918b97 367
e40298d5
JS
368 SetItemCmd( menu, item , macKey );
369 SetMenuItemModifiers(menu, item , modifiers ) ;
2b5f62a0
VZ
370
371 if ( glyph )
372 SetMenuItemKeyGlyph(menu, item , glyph ) ;
e40298d5 373 }
2b5f62a0
VZ
374}
375
58751a86 376void UMAAppendMenuItem( MenuRef menu , const wxString& title , wxAcceleratorEntry *entry )
2b5f62a0 377{
e40298d5
JS
378 MacAppendMenu(menu, "\pA");
379 UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title );
380 UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), entry ) ;
2f1ae414
SC
381}
382
58751a86 383void UMAInsertMenuItem( MenuRef menu , const wxString& title , MenuItemIndex item , wxAcceleratorEntry *entry )
2f1ae414 384{
58751a86
RD
385 MacInsertMenuItem( menu , "\pA" , item) ;
386 UMASetMenuItemText(menu, item+1 , title );
387 UMASetMenuItemShortcut( menu , item+1 , entry ) ;
2f1ae414
SC
388}
389
72e7876b
SC
390// quickdraw
391
7052b16d
SC
392#if !TARGET_CARBON
393
2f1ae414
SC
394int gPrOpenCounter = 0 ;
395
7052b16d 396OSStatus UMAPrOpen()
2f1ae414 397{
e40298d5
JS
398 OSErr err = noErr ;
399 ++gPrOpenCounter ;
400 if ( gPrOpenCounter == 1 )
401 {
402 PrOpen() ;
403 err = PrError() ;
404 wxASSERT( err == noErr ) ;
405 }
406 return err ;
2f1ae414
SC
407}
408
7052b16d 409OSStatus UMAPrClose()
2f1ae414 410{
e40298d5
JS
411 OSErr err = noErr ;
412 wxASSERT( gPrOpenCounter >= 1 ) ;
413 if ( gPrOpenCounter == 1 )
414 {
415 PrClose() ;
416 err = PrError() ;
417 wxASSERT( err == noErr ) ;
418 }
419 --gPrOpenCounter ;
420 return err ;
2f1ae414
SC
421}
422
72055702 423pascal QDGlobalsPtr GetQDGlobalsPtr (void) ;
72e7876b
SC
424pascal QDGlobalsPtr GetQDGlobalsPtr (void)
425{
e40298d5 426 return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA);
72e7876b
SC
427}
428
429#endif
430
58751a86 431void UMAShowWatchCursor()
72e7876b 432{
e40298d5 433 OSErr err = noErr;
72e7876b 434
e40298d5 435 CursHandle watchFob = GetCursor (watchCursor);
72e7876b 436
e40298d5
JS
437 if (!watchFob)
438 err = nilHandleErr;
439 else
440 {
441 #if TARGET_CARBON
442// Cursor preservedArrow;
443// GetQDGlobalsArrow (&preservedArrow);
444// SetQDGlobalsArrow (*watchFob);
445// InitCursor ( );
446// SetQDGlobalsArrow (&preservedArrow);
58751a86 447 SetCursor (*watchFob);
e40298d5 448 #else
58751a86 449 SetCursor (*watchFob);
e40298d5
JS
450 #endif
451 }
72e7876b
SC
452}
453
58751a86 454void UMAShowArrowCursor()
72e7876b
SC
455{
456#if TARGET_CARBON
e40298d5
JS
457 Cursor arrow;
458 SetCursor (GetQDGlobalsArrow (&arrow));
72e7876b 459#else
e40298d5 460 SetCursor (&(qd.arrow));
72e7876b
SC
461#endif
462}
463
464// window manager
465
58751a86 466GrafPtr UMAGetWindowPort( WindowRef inWindowRef )
72e7876b 467{
e40298d5 468 wxASSERT( inWindowRef != NULL ) ;
58751a86
RD
469#if TARGET_CARBON
470 return (GrafPtr) GetWindowPort( inWindowRef ) ;
72e7876b 471#else
e40298d5 472 return (GrafPtr) inWindowRef ;
72e7876b
SC
473#endif
474}
475
58751a86 476void UMADisposeWindow( WindowRef inWindowRef )
72e7876b 477{
e40298d5
JS
478 wxASSERT( inWindowRef != NULL ) ;
479 DisposeWindow( inWindowRef ) ;
72e7876b
SC
480}
481
58751a86 482void UMASetWTitle( WindowRef inWindowRef , const wxString& title )
72e7876b 483{
03e11df5 484#if TARGET_CARBON
427ff662 485 SetWindowTitleWithCFString( inWindowRef , wxMacCFStringHolder(title) ) ;
03e11df5 486#else
427ff662
SC
487 Str255 ptitle ;
488 wxMacStringToPascal( title , ptitle ) ;
e40298d5 489 SetWTitle( inWindowRef , ptitle ) ;
427ff662 490#endif
72e7876b 491}
03e11df5 492
58751a86 493void UMAGetWTitleC( WindowRef inWindowRef , char *title )
72e7876b 494{
e40298d5 495 GetWTitle( inWindowRef , (unsigned char*)title ) ;
03e11df5 496#if TARGET_CARBON
e40298d5 497 p2cstrcpy( title, (unsigned char *)title ) ;
03e11df5 498#else
e40298d5 499 p2cstr( (unsigned char*)title ) ;
03e11df5 500#endif
72e7876b
SC
501}
502
72e7876b
SC
503// appearance additions
504
58751a86 505void UMASetControlTitle( ControlHandle inControl , const wxString& title )
427ff662
SC
506{
507#if TARGET_CARBON
508 SetControlTitleWithCFString( inControl , wxMacCFStringHolder(title) ) ;
509#else
510 Str255 ptitle ;
511 wxMacStringToPascal( title , ptitle ) ;
512 SetControlTitle( inControl , ptitle ) ;
513#endif
514}
515
58751a86 516void UMAActivateControl( ControlHandle inControl )
72e7876b 517{
22e751a5
SC
518 // we have to add the control after again to the update rgn
519 // otherwise updates get lost
e40298d5
JS
520 if ( !IsControlActive( inControl ) )
521 {
fdaf613a
SC
522 bool visible = IsControlVisible( inControl ) ;
523 if ( visible )
e40298d5 524 SetControlVisibility( inControl , false , false ) ;
3f4902f5 525 ::ActivateControl( inControl ) ;
fdaf613a 526 if ( visible ) {
e40298d5
JS
527 SetControlVisibility( inControl , true , false ) ;
528 Rect ctrlBounds ;
529 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
fdaf613a 530 }
e40298d5 531 }
72e7876b
SC
532}
533
58751a86 534void UMADrawControl( ControlHandle inControl )
72e7876b 535{
3f4902f5
GD
536 WindowRef theWindow = GetControlOwner(inControl) ;
537 RgnHandle updateRgn = NewRgn() ;
3f4902f5 538 GetWindowUpdateRgn( theWindow , updateRgn ) ;
e40298d5
JS
539 Point zero = { 0 , 0 } ;
540 LocalToGlobal( &zero ) ;
541 OffsetRgn( updateRgn , -zero.h , -zero.v ) ;
22e751a5
SC
542 ::DrawControlInCurrentPort( inControl ) ;
543 InvalWindowRgn( theWindow, updateRgn) ;
e40298d5 544 DisposeRgn( updateRgn ) ;
72e7876b
SC
545}
546
58751a86 547void UMAMoveControl( ControlHandle inControl , short x , short y )
72e7876b 548{
e40298d5
JS
549 bool visible = IsControlVisible( inControl ) ;
550 if ( visible ) {
551 SetControlVisibility( inControl , false , false ) ;
552 Rect ctrlBounds ;
553 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
554 }
555 ::MoveControl( inControl , x , y ) ;
556 if ( visible ) {
557 SetControlVisibility( inControl , true , false ) ;
558 Rect ctrlBounds ;
559 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
560 }
72e7876b
SC
561}
562
58751a86 563void UMASizeControl( ControlHandle inControl , short x , short y )
72e7876b 564{
e40298d5
JS
565 bool visible = IsControlVisible( inControl ) ;
566 if ( visible ) {
567 SetControlVisibility( inControl , false , false ) ;
568 Rect ctrlBounds ;
569 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
58751a86 570 }
e40298d5
JS
571 ::SizeControl( inControl , x , y ) ;
572 if ( visible ) {
573 SetControlVisibility( inControl , true , false ) ;
574 Rect ctrlBounds ;
575 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
576 }
72e7876b
SC
577}
578
58751a86 579void UMADeactivateControl( ControlHandle inControl )
72e7876b 580{
22e751a5
SC
581 // we have to add the control after again to the update rgn
582 // otherwise updates get lost
e40298d5
JS
583 bool visible = IsControlVisible( inControl ) ;
584 if ( visible )
585 SetControlVisibility( inControl , false , false ) ;
586 ::DeactivateControl( inControl ) ;
587 if ( visible ) {
fdaf613a 588 SetControlVisibility( inControl , true , false ) ;
c36f0244
SC
589 Rect ctrlBounds ;
590 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
e40298d5
JS
591 }
592}
593// shows the control and adds the region to the update region
594void UMAShowControl (ControlHandle inControl)
595{
596 SetControlVisibility( inControl , true , false ) ;
597 Rect ctrlBounds ;
598 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
72e7876b
SC
599}
600
22e751a5 601// shows the control and adds the region to the update region
e40298d5 602void UMAHideControl (ControlHandle inControl)
22e751a5 603{
e40298d5
JS
604 SetControlVisibility( inControl , false , false ) ;
605 Rect ctrlBounds ;
606 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
22e751a5 607}
72e7876b 608// keyboard focus
e40298d5
JS
609OSErr UMASetKeyboardFocus (WindowPtr inWindow,
610 ControlHandle inControl,
611 ControlFocusPart inPart)
72e7876b 612{
e40298d5
JS
613 OSErr err = noErr;
614 GrafPtr port ;
615 GetPort( &port ) ;
72055702 616
e40298d5 617 SetPortWindowPort( inWindow ) ;
72055702 618
e40298d5
JS
619 err = SetKeyboardFocus( inWindow , inControl , inPart ) ;
620 SetPort( port ) ;
621 return err ;
72e7876b
SC
622}
623
624
72e7876b 625// events
58751a86 626void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn )
72e7876b 627{
e40298d5
JS
628 RgnHandle updateRgn = NewRgn() ;
629 GetWindowUpdateRgn( inWindow , updateRgn ) ;
58751a86 630
e40298d5
JS
631 Point zero = { 0 , 0 } ;
632 LocalToGlobal( &zero ) ;
633 OffsetRgn( updateRgn , -zero.h , -zero.v ) ;
58751a86 634
e40298d5
JS
635 UpdateControls( inWindow , inRgn ) ;
636 InvalWindowRgn( inWindow, updateRgn) ;
637 DisposeRgn( updateRgn ) ;
72e7876b
SC
638}
639
58751a86 640bool UMAIsWindowFloating( WindowRef inWindow )
72e7876b 641{
e40298d5 642 WindowClass cl ;
58751a86 643
e40298d5
JS
644 GetWindowClass( inWindow , &cl ) ;
645 return cl == kFloatingWindowClass ;
72e7876b
SC
646}
647
58751a86 648bool UMAIsWindowModal( WindowRef inWindow )
72e7876b 649{
e40298d5 650 WindowClass cl ;
58751a86 651
e40298d5
JS
652 GetWindowClass( inWindow , &cl ) ;
653 return cl < kFloatingWindowClass ;
72e7876b
SC
654}
655
656// others
657
658void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
659{
e40298d5
JS
660 if ( inWindowRef )
661 {
662// bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
663// if ( inActivate != isHightlited )
664 GrafPtr port ;
665 GetPort( &port ) ;
666 SetPortWindowPort( inWindowRef ) ;
667 HiliteWindow( inWindowRef , inActivate ) ;
668 ControlHandle control = NULL ;
669 ::GetRootControl( inWindowRef , & control ) ;
670 if ( control )
671 {
672 if ( inActivate )
673 UMAActivateControl( control ) ;
674 else
675 UMADeactivateControl( control ) ;
58751a86 676 }
e40298d5
JS
677 SetPort( port ) ;
678 }
72e7876b 679}
e40298d5 680
58751a86 681OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState )
2f1ae414 682{
e40298d5 683 return ::DrawThemePlacard( inRect , inState ) ;
2f1ae414 684}
72e7876b 685
2f056c85 686#if !TARGET_CARBON
b03e4fcd 687static OSStatus helpMenuStatus = noErr ;
b03e4fcd 688static MenuItemIndex firstCustomItemIndex = 0 ;
2f056c85 689#endif
b03e4fcd
SC
690
691OSStatus UMAGetHelpMenu(
692 MenuRef * outHelpMenu,
693 MenuItemIndex * outFirstCustomItemIndex)
694{
695#if TARGET_CARBON
e40298d5 696 return HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ;
b03e4fcd 697#else
e40298d5
JS
698 MenuRef helpMenuHandle ;
699 helpMenuStatus = HMGetHelpMenuHandle( &helpMenuHandle ) ;
700 if ( firstCustomItemIndex == 0 && helpMenuStatus == noErr )
701 {
702 firstCustomItemIndex = CountMenuItems( helpMenuHandle ) + 1 ;
703 }
704 if ( outFirstCustomItemIndex )
705 {
706 *outFirstCustomItemIndex = firstCustomItemIndex ;
707 }
708 *outHelpMenu = helpMenuHandle ;
709 return helpMenuStatus ;
b03e4fcd
SC
710#endif
711}
76a5e5d2 712
58751a86 713wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport)
76a5e5d2 714{
e40298d5
JS
715 m_clip = NULL ;
716 Setup( newport ) ;
76a5e5d2
SC
717}
718
719wxMacPortStateHelper::wxMacPortStateHelper()
720{
e40298d5 721 m_clip = NULL ;
76a5e5d2
SC
722}
723
724void wxMacPortStateHelper::Setup( GrafPtr newport )
725{
e40298d5
JS
726 GetPort( &m_oldPort ) ;
727 SetPort( newport ) ;
427ff662 728 wxASSERT_MSG( m_clip == NULL , wxT("Cannot call setup twice") ) ;
e40298d5
JS
729 m_clip = NewRgn() ;
730 GetClip( m_clip );
731 m_textFont = GetPortTextFont( (CGrafPtr) newport);
732 m_textSize = GetPortTextSize( (CGrafPtr) newport);
733 m_textStyle = GetPortTextFace( (CGrafPtr) newport);
58751a86 734 m_textMode = GetPortTextMode( (CGrafPtr) newport);
e40298d5
JS
735 GetThemeDrawingState( &m_drawingState ) ;
736 m_currentPort = newport ;
76a5e5d2
SC
737}
738void wxMacPortStateHelper::Clear()
739{
e40298d5
JS
740 if ( m_clip )
741 {
742 DisposeRgn( m_clip ) ;
743 DisposeThemeDrawingState( m_drawingState ) ;
744 m_clip = NULL ;
745 }
76a5e5d2
SC
746}
747
748wxMacPortStateHelper::~wxMacPortStateHelper()
749{
e40298d5
JS
750 if ( m_clip )
751 {
752 SetPort( m_currentPort ) ;
753 SetClip( m_clip ) ;
754 DisposeRgn( m_clip ) ;
755 TextFont( m_textFont );
756 TextSize( m_textSize );
757 TextFace( m_textStyle );
758 TextMode( m_textMode );
759 SetThemeDrawingState( m_drawingState , true ) ;
760 SetPort( m_oldPort ) ;
761 }
76a5e5d2
SC
762}
763
9c3c5849
SC
764OSStatus UMAPutScrap( Size size , OSType type , void *data )
765{
e40298d5 766 OSStatus err = noErr ;
9c3c5849
SC
767#if !TARGET_CARBON
768 err = PutScrap( size , type , data ) ;
769#else
770 ScrapRef scrap;
58751a86 771 err = GetCurrentScrap (&scrap);
9c3c5849
SC
772 if ( !err )
773 {
774 err = PutScrapFlavor (scrap, type , 0, size, data);
775 }
776#endif
e40298d5 777 return err ;
9c3c5849
SC
778}
779