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