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