]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/uma.cpp
added new notifications to be added, corrected DoGetBestSize
[wxWidgets.git] / src / mac / carbon / 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
4a6a2972 168 OptionBits options = 0 ;
4a6a2972 169
facd6764 170 if ( UMAGetSystemVersion() < 0x1000 )
54ddeb7e
SC
171 {
172 options |= kTXNAlwaysUseQuickDrawTextMask ;
173 }
facd6764 174 TXNInitTextension(fontDescriptions, noOfFontDescriptions, options );
54ddeb7e 175 }
f8eebb95 176
ded4fa5b 177
2dbc444a 178 UMASetSystemIsInitialized(true);
66a09d47 179
72e7876b
SC
180}
181
66a09d47
SC
182/*
183Boolean CanUseATSUI()
e40298d5
JS
184 {
185 long result;
186 OSErr err = Gestalt(gestaltATSUVersion, &result);
187 return (err == noErr);
188 }
66a09d47 189*/
72e7876b 190// process manager
58751a86 191long UMAGetProcessMode()
72e7876b 192{
58751a86 193 OSErr err ;
e40298d5
JS
194 ProcessInfoRec processinfo;
195 ProcessSerialNumber procno ;
58751a86 196
e40298d5
JS
197 procno.highLongOfPSN = NULL ;
198 procno.lowLongOfPSN = kCurrentProcess ;
199 processinfo.processInfoLength = sizeof(ProcessInfoRec);
200 processinfo.processName = NULL;
201 processinfo.processAppSpec = NULL;
72e7876b 202
e40298d5
JS
203 err = ::GetProcessInformation( &procno , &processinfo ) ;
204 wxASSERT( err == noErr ) ;
205 return processinfo.processMode ;
72e7876b
SC
206}
207
58751a86 208bool UMAGetProcessModeDoesActivateOnFGSwitch()
72e7876b 209{
e40298d5 210 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch ;
72e7876b
SC
211}
212
213// menu manager
214
908d407c 215MenuRef UMANewMenu( SInt16 id , const wxString& title , wxFontEncoding encoding )
72e7876b 216{
e40298d5
JS
217 wxString str = wxStripMenuCodes( title ) ;
218 MenuRef menu ;
bf918b97 219#if TARGET_CARBON
e40298d5 220 CreateNewMenu( id , 0 , &menu ) ;
908d407c 221 SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding ) ) ;
bf918b97 222#else
e40298d5
JS
223 Str255 ptitle ;
224 wxMacStringToPascal( str , ptitle ) ;
225 menu = ::NewMenu( id , ptitle ) ;
bf918b97 226#endif
e40298d5 227 return menu ;
bf918b97 228}
72e7876b 229
908d407c 230void UMASetMenuTitle( MenuRef menu , const wxString& title , wxFontEncoding encoding)
bf918b97 231{
e40298d5 232 wxString str = wxStripMenuCodes( title ) ;
bf918b97 233#if TARGET_CARBON
908d407c 234 SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding) ) ;
72e7876b 235#else
e40298d5
JS
236 Str255 ptitle ;
237 wxMacStringToPascal( str , ptitle ) ;
238 SetMenuTitle( menu , ptitle ) ;
bf918b97 239#endif
72e7876b
SC
240}
241
908d407c 242void UMASetMenuItemText( MenuRef menu, MenuItemIndex item, const wxString& title , wxFontEncoding encoding)
72e7876b 243{
e40298d5 244 wxString str = wxStripMenuCodes( title ) ;
bf918b97 245#if TARGET_CARBON
908d407c 246 SetMenuItemTextWithCFString( menu , item , wxMacCFStringHolder(str , encoding) ) ;
bf918b97 247#else
e40298d5
JS
248 Str255 ptitle ;
249 wxMacStringToPascal( str , ptitle ) ;
250 SetMenuItemText( menu , item , ptitle ) ;
bf918b97 251#endif
72e7876b
SC
252}
253
bf918b97
SC
254
255UInt32 UMAMenuEvent( EventRecord *inEvent )
72e7876b 256{
e40298d5 257 return MenuEvent( inEvent ) ;
72e7876b
SC
258}
259
58751a86 260void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem , bool enable)
72e7876b 261{
e40298d5
JS
262 if ( enable )
263 EnableMenuItem( inMenu , inItem ) ;
264 else
265 DisableMenuItem( inMenu , inItem ) ;
72e7876b 266}
2f1ae414 267
908d407c 268void UMAAppendSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , SInt16 id )
2f1ae414 269{
e40298d5 270 MacAppendMenu(menu, "\pA");
908d407c 271 UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title , encoding );
e40298d5 272 SetMenuItemHierarchicalID( menu , CountMenuItems( menu ) , id ) ;
2f1ae414
SC
273}
274
908d407c 275void UMAInsertSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , SInt16 id )
2f1ae414 276{
e40298d5 277 MacInsertMenuItem(menu, "\pA" , item);
908d407c 278 UMASetMenuItemText(menu, item , title , encoding);
e40298d5 279 SetMenuItemHierarchicalID( menu , item , id ) ;
2f1ae414
SC
280}
281
bf918b97 282void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEntry *entry )
2f1ae414 283{
e40298d5
JS
284 if ( !entry )
285 return ;
58751a86 286
e40298d5
JS
287 UInt8 modifiers = 0 ;
288 SInt16 key = entry->GetKeyCode() ;
289 if ( key )
290 {
291 bool explicitCommandKey = false ;
292
58751a86 293 if ( entry->GetFlags() & wxACCEL_CTRL )
e40298d5
JS
294 {
295 explicitCommandKey = true ;
296 }
297
58751a86 298 if (entry->GetFlags() & wxACCEL_ALT )
e40298d5
JS
299 {
300 modifiers |= kMenuOptionModifier ;
301 }
302
58751a86 303 if (entry->GetFlags() & wxACCEL_SHIFT)
e40298d5
JS
304 {
305 modifiers |= kMenuShiftModifier ;
306 }
307
308 SInt16 glyph = 0 ;
309 SInt16 macKey = key ;
310 if ( key >= WXK_F1 && key <= WXK_F15 )
311 {
a5c1f8ca
SC
312 // for some reasons this must be 0 right now
313 // everything else leads to just the first function key item
314 // to be selected. Thanks to Ryan Wilcox for finding out.
2dbc444a 315 macKey = 0 ;
e40298d5
JS
316 glyph = kMenuF1Glyph + ( key - WXK_F1 ) ;
317 if ( key >= WXK_F13 )
318 glyph += 13 ;
bf918b97 319 if ( !explicitCommandKey )
e40298d5 320 modifiers |= kMenuNoCommandModifier ;
e40298d5
JS
321 }
322 else
323 {
324 switch( key )
325 {
326 case WXK_BACK :
327 macKey = kBackspaceCharCode ;
328 glyph = kMenuDeleteLeftGlyph ;
329 break ;
330 case WXK_TAB :
331 macKey = kTabCharCode ;
332 glyph = kMenuTabRightGlyph ;
333 break ;
334 case kEnterCharCode :
335 macKey = kEnterCharCode ;
336 glyph = kMenuEnterGlyph ;
337 break ;
338 case WXK_RETURN :
339 macKey = kReturnCharCode ;
340 glyph = kMenuReturnGlyph ;
341 break ;
342 case WXK_ESCAPE :
343 macKey = kEscapeCharCode ;
344 glyph = kMenuEscapeGlyph ;
345 break ;
346 case WXK_SPACE :
347 macKey = ' ' ;
348 glyph = kMenuSpaceGlyph ;
349 break ;
350 case WXK_DELETE :
351 macKey = kDeleteCharCode ;
352 glyph = kMenuDeleteRightGlyph ;
353 break ;
354 case WXK_CLEAR :
355 macKey = kClearCharCode ;
356 glyph = kMenuClearGlyph ;
357 break ;
358 case WXK_PRIOR : // PAGE UP
359 macKey = kPageUpCharCode ;
360 glyph = kMenuPageUpGlyph ;
361 break ;
362 case WXK_NEXT :
363 macKey = kPageDownCharCode ;
364 glyph = kMenuPageDownGlyph ;
365 break ;
366 case WXK_LEFT :
367 macKey = kLeftArrowCharCode ;
368 glyph = kMenuLeftArrowGlyph ;
369 break ;
370 case WXK_UP :
371 macKey = kUpArrowCharCode ;
372 glyph = kMenuUpArrowGlyph ;
373 break ;
374 case WXK_RIGHT :
375 macKey = kRightArrowCharCode ;
376 glyph = kMenuRightArrowGlyph ;
377 break ;
378 case WXK_DOWN :
379 macKey = kDownArrowCharCode ;
380 glyph = kMenuDownArrowGlyph ;
381 break ;
2b5f62a0
VZ
382 }
383 }
bf918b97 384
e40298d5
JS
385 SetItemCmd( menu, item , macKey );
386 SetMenuItemModifiers(menu, item , modifiers ) ;
2b5f62a0
VZ
387
388 if ( glyph )
389 SetMenuItemKeyGlyph(menu, item , glyph ) ;
e40298d5 390 }
2b5f62a0
VZ
391}
392
908d407c 393void UMAAppendMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , wxAcceleratorEntry *entry )
2b5f62a0 394{
e40298d5 395 MacAppendMenu(menu, "\pA");
908d407c 396 UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title , encoding );
e40298d5 397 UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), entry ) ;
2f1ae414
SC
398}
399
908d407c 400void UMAInsertMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , wxAcceleratorEntry *entry )
2f1ae414 401{
58751a86 402 MacInsertMenuItem( menu , "\pA" , item) ;
908d407c 403 UMASetMenuItemText(menu, item+1 , title , encoding );
58751a86 404 UMASetMenuItemShortcut( menu , item+1 , entry ) ;
2f1ae414
SC
405}
406
72e7876b
SC
407// quickdraw
408
7052b16d
SC
409#if !TARGET_CARBON
410
2f1ae414
SC
411int gPrOpenCounter = 0 ;
412
7052b16d 413OSStatus UMAPrOpen()
2f1ae414 414{
e40298d5
JS
415 OSErr err = noErr ;
416 ++gPrOpenCounter ;
417 if ( gPrOpenCounter == 1 )
418 {
419 PrOpen() ;
420 err = PrError() ;
421 wxASSERT( err == noErr ) ;
422 }
423 return err ;
2f1ae414
SC
424}
425
7052b16d 426OSStatus UMAPrClose()
2f1ae414 427{
e40298d5
JS
428 OSErr err = noErr ;
429 wxASSERT( gPrOpenCounter >= 1 ) ;
430 if ( gPrOpenCounter == 1 )
431 {
432 PrClose() ;
433 err = PrError() ;
434 wxASSERT( err == noErr ) ;
435 }
436 --gPrOpenCounter ;
437 return err ;
2f1ae414
SC
438}
439
72055702 440pascal QDGlobalsPtr GetQDGlobalsPtr (void) ;
72e7876b
SC
441pascal QDGlobalsPtr GetQDGlobalsPtr (void)
442{
e40298d5 443 return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA);
72e7876b
SC
444}
445
446#endif
447
58751a86 448void UMAShowWatchCursor()
72e7876b 449{
e40298d5 450 OSErr err = noErr;
72e7876b 451
e40298d5 452 CursHandle watchFob = GetCursor (watchCursor);
72e7876b 453
e40298d5
JS
454 if (!watchFob)
455 err = nilHandleErr;
456 else
457 {
458 #if TARGET_CARBON
459// Cursor preservedArrow;
460// GetQDGlobalsArrow (&preservedArrow);
461// SetQDGlobalsArrow (*watchFob);
462// InitCursor ( );
463// SetQDGlobalsArrow (&preservedArrow);
58751a86 464 SetCursor (*watchFob);
e40298d5 465 #else
58751a86 466 SetCursor (*watchFob);
e40298d5
JS
467 #endif
468 }
72e7876b
SC
469}
470
58751a86 471void UMAShowArrowCursor()
72e7876b
SC
472{
473#if TARGET_CARBON
e40298d5
JS
474 Cursor arrow;
475 SetCursor (GetQDGlobalsArrow (&arrow));
72e7876b 476#else
e40298d5 477 SetCursor (&(qd.arrow));
72e7876b
SC
478#endif
479}
480
481// window manager
482
58751a86 483GrafPtr UMAGetWindowPort( WindowRef inWindowRef )
72e7876b 484{
e40298d5 485 wxASSERT( inWindowRef != NULL ) ;
58751a86
RD
486#if TARGET_CARBON
487 return (GrafPtr) GetWindowPort( inWindowRef ) ;
72e7876b 488#else
e40298d5 489 return (GrafPtr) inWindowRef ;
72e7876b
SC
490#endif
491}
492
58751a86 493void UMADisposeWindow( WindowRef inWindowRef )
72e7876b 494{
e40298d5
JS
495 wxASSERT( inWindowRef != NULL ) ;
496 DisposeWindow( inWindowRef ) ;
72e7876b
SC
497}
498
908d407c 499void UMASetWTitle( WindowRef inWindowRef , const wxString& title , wxFontEncoding encoding)
72e7876b 500{
03e11df5 501#if TARGET_CARBON
908d407c 502 SetWindowTitleWithCFString( inWindowRef , wxMacCFStringHolder(title , encoding) ) ;
03e11df5 503#else
427ff662
SC
504 Str255 ptitle ;
505 wxMacStringToPascal( title , ptitle ) ;
e40298d5 506 SetWTitle( inWindowRef , ptitle ) ;
427ff662 507#endif
72e7876b 508}
03e11df5 509
72e7876b
SC
510// appearance additions
511
facd6764 512void UMASetControlTitle( ControlRef inControl , const wxString& title , wxFontEncoding encoding)
427ff662
SC
513{
514#if TARGET_CARBON
908d407c 515 SetControlTitleWithCFString( inControl , wxMacCFStringHolder(title , encoding) ) ;
427ff662
SC
516#else
517 Str255 ptitle ;
518 wxMacStringToPascal( title , ptitle ) ;
519 SetControlTitle( inControl , ptitle ) ;
520#endif
521}
522
facd6764 523void UMAActivateControl( ControlRef inControl )
72e7876b 524{
facd6764 525#if !TARGET_API_MAC_OSX
22e751a5
SC
526 // we have to add the control after again to the update rgn
527 // otherwise updates get lost
e40298d5
JS
528 if ( !IsControlActive( inControl ) )
529 {
fdaf613a
SC
530 bool visible = IsControlVisible( inControl ) ;
531 if ( visible )
e40298d5 532 SetControlVisibility( inControl , false , false ) ;
facd6764 533#endif
3f4902f5 534 ::ActivateControl( inControl ) ;
facd6764 535#if !TARGET_API_MAC_OSX
fdaf613a 536 if ( visible ) {
e40298d5 537 SetControlVisibility( inControl , true , false ) ;
facd6764 538
e40298d5 539 Rect ctrlBounds ;
facd6764 540 InvalWindowRect(GetControlOwner(inControl),UMAGetControlBoundsInWindowCoords(inControl,&ctrlBounds) ) ;
fdaf613a 541 }
e40298d5 542 }
facd6764 543#endif
72e7876b
SC
544}
545
facd6764 546void UMADrawControl( ControlRef inControl )
72e7876b 547{
facd6764
SC
548#if TARGET_API_MAC_CARBON
549 ::Draw1Control( inControl );
550#else
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 ) ;
facd6764 561#endif
72e7876b
SC
562}
563
facd6764 564void UMAMoveControl( ControlRef inControl , short x , short y )
72e7876b 565{
facd6764 566#if !TARGET_API_MAC_OSX
e40298d5
JS
567 bool visible = IsControlVisible( inControl ) ;
568 if ( visible ) {
569 SetControlVisibility( inControl , false , false ) ;
570 Rect ctrlBounds ;
571 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
572 }
facd6764 573#endif
e40298d5 574 ::MoveControl( inControl , x , y ) ;
facd6764 575#if !TARGET_API_MAC_OSX
e40298d5
JS
576 if ( visible ) {
577 SetControlVisibility( inControl , true , false ) ;
578 Rect ctrlBounds ;
579 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
580 }
facd6764 581#endif
72e7876b
SC
582}
583
facd6764 584void UMASizeControl( ControlRef inControl , short x , short y )
72e7876b 585{
facd6764 586#if !TARGET_API_MAC_OSX
e40298d5
JS
587 bool visible = IsControlVisible( inControl ) ;
588 if ( visible ) {
589 SetControlVisibility( inControl , false , false ) ;
590 Rect ctrlBounds ;
591 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
58751a86 592 }
facd6764 593#endif
e40298d5 594 ::SizeControl( inControl , x , y ) ;
facd6764 595#if !TARGET_API_MAC_OSX
e40298d5
JS
596 if ( visible ) {
597 SetControlVisibility( inControl , true , false ) ;
598 Rect ctrlBounds ;
599 InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ;
600 }
facd6764 601#endif
72e7876b
SC
602}
603
facd6764 604void UMADeactivateControl( ControlRef inControl )
72e7876b 605{
facd6764 606#if !TARGET_API_MAC_OSX
22e751a5
SC
607 // we have to add the control after again to the update rgn
608 // otherwise updates get lost
e40298d5
JS
609 bool visible = IsControlVisible( inControl ) ;
610 if ( visible )
611 SetControlVisibility( inControl , false , false ) ;
facd6764 612#endif
e40298d5 613 ::DeactivateControl( inControl ) ;
facd6764 614#if !TARGET_API_MAC_OSX
e40298d5 615 if ( visible ) {
fdaf613a 616 SetControlVisibility( inControl , true , false ) ;
c36f0244 617 Rect ctrlBounds ;
facd6764 618 InvalWindowRect(GetControlOwner(inControl),UMAGetControlBoundsInWindowCoords(inControl,&ctrlBounds) ) ;
e40298d5 619 }
facd6764 620#endif
e40298d5
JS
621}
622// shows the control and adds the region to the update region
facd6764 623void UMAShowControl (ControlRef inControl)
e40298d5
JS
624{
625 SetControlVisibility( inControl , true , false ) ;
626 Rect ctrlBounds ;
facd6764 627 InvalWindowRect(GetControlOwner(inControl),UMAGetControlBoundsInWindowCoords(inControl,&ctrlBounds) ) ;
72e7876b
SC
628}
629
facd6764
SC
630// hides the control and adds the region to the update region
631void UMAHideControl (ControlRef inControl)
22e751a5 632{
e40298d5
JS
633 SetControlVisibility( inControl , false , false ) ;
634 Rect ctrlBounds ;
facd6764 635 InvalWindowRect(GetControlOwner(inControl),UMAGetControlBoundsInWindowCoords(inControl,&ctrlBounds) ) ;
22e751a5 636}
72e7876b 637// keyboard focus
e40298d5 638OSErr UMASetKeyboardFocus (WindowPtr inWindow,
facd6764 639 ControlRef inControl,
e40298d5 640 ControlFocusPart inPart)
72e7876b 641{
e40298d5
JS
642 OSErr err = noErr;
643 GrafPtr port ;
644 GetPort( &port ) ;
72055702 645
e40298d5 646 SetPortWindowPort( inWindow ) ;
72055702 647
e40298d5
JS
648 err = SetKeyboardFocus( inWindow , inControl , inPart ) ;
649 SetPort( port ) ;
650 return err ;
72e7876b
SC
651}
652
72e7876b 653// events
58751a86 654void UMAUpdateControls( WindowPtr inWindow , RgnHandle inRgn )
72e7876b 655{
f17e0be4 656 wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) inWindow) ) ;
e40298d5
JS
657 RgnHandle updateRgn = NewRgn() ;
658 GetWindowUpdateRgn( inWindow , updateRgn ) ;
58751a86 659
e40298d5
JS
660 Point zero = { 0 , 0 } ;
661 LocalToGlobal( &zero ) ;
662 OffsetRgn( updateRgn , -zero.h , -zero.v ) ;
58751a86 663
e40298d5
JS
664 UpdateControls( inWindow , inRgn ) ;
665 InvalWindowRgn( inWindow, updateRgn) ;
666 DisposeRgn( updateRgn ) ;
72e7876b
SC
667}
668
58751a86 669bool UMAIsWindowFloating( WindowRef inWindow )
72e7876b 670{
e40298d5 671 WindowClass cl ;
58751a86 672
e40298d5
JS
673 GetWindowClass( inWindow , &cl ) ;
674 return cl == kFloatingWindowClass ;
72e7876b
SC
675}
676
58751a86 677bool UMAIsWindowModal( WindowRef inWindow )
72e7876b 678{
e40298d5 679 WindowClass cl ;
58751a86 680
e40298d5
JS
681 GetWindowClass( inWindow , &cl ) ;
682 return cl < kFloatingWindowClass ;
72e7876b
SC
683}
684
685// others
686
687void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
688{
e40298d5
JS
689 if ( inWindowRef )
690 {
691// bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
692// if ( inActivate != isHightlited )
693 GrafPtr port ;
694 GetPort( &port ) ;
695 SetPortWindowPort( inWindowRef ) ;
696 HiliteWindow( inWindowRef , inActivate ) ;
facd6764 697 ControlRef control = NULL ;
e40298d5
JS
698 ::GetRootControl( inWindowRef , & control ) ;
699 if ( control )
700 {
701 if ( inActivate )
702 UMAActivateControl( control ) ;
703 else
704 UMADeactivateControl( control ) ;
58751a86 705 }
e40298d5
JS
706 SetPort( port ) ;
707 }
72e7876b 708}
e40298d5 709
58751a86 710OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState )
2f1ae414 711{
e40298d5 712 return ::DrawThemePlacard( inRect , inState ) ;
2f1ae414 713}
72e7876b 714
2f056c85 715#if !TARGET_CARBON
b03e4fcd 716static OSStatus helpMenuStatus = noErr ;
b03e4fcd 717static MenuItemIndex firstCustomItemIndex = 0 ;
2f056c85 718#endif
b03e4fcd
SC
719
720OSStatus UMAGetHelpMenu(
721 MenuRef * outHelpMenu,
722 MenuItemIndex * outFirstCustomItemIndex)
723{
724#if TARGET_CARBON
e40298d5 725 return HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ;
b03e4fcd 726#else
e40298d5
JS
727 MenuRef helpMenuHandle ;
728 helpMenuStatus = HMGetHelpMenuHandle( &helpMenuHandle ) ;
729 if ( firstCustomItemIndex == 0 && helpMenuStatus == noErr )
730 {
731 firstCustomItemIndex = CountMenuItems( helpMenuHandle ) + 1 ;
732 }
733 if ( outFirstCustomItemIndex )
734 {
735 *outFirstCustomItemIndex = firstCustomItemIndex ;
736 }
737 *outHelpMenu = helpMenuHandle ;
738 return helpMenuStatus ;
b03e4fcd
SC
739#endif
740}
76a5e5d2 741
58751a86 742wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport)
76a5e5d2 743{
e40298d5
JS
744 m_clip = NULL ;
745 Setup( newport ) ;
76a5e5d2
SC
746}
747
748wxMacPortStateHelper::wxMacPortStateHelper()
749{
e40298d5 750 m_clip = NULL ;
76a5e5d2
SC
751}
752
753void wxMacPortStateHelper::Setup( GrafPtr newport )
754{
e40298d5
JS
755 GetPort( &m_oldPort ) ;
756 SetPort( newport ) ;
f17e0be4 757 SetOrigin(0,0);
427ff662 758 wxASSERT_MSG( m_clip == NULL , wxT("Cannot call setup twice") ) ;
e40298d5
JS
759 m_clip = NewRgn() ;
760 GetClip( m_clip );
761 m_textFont = GetPortTextFont( (CGrafPtr) newport);
762 m_textSize = GetPortTextSize( (CGrafPtr) newport);
763 m_textStyle = GetPortTextFace( (CGrafPtr) newport);
58751a86 764 m_textMode = GetPortTextMode( (CGrafPtr) newport);
e40298d5
JS
765 GetThemeDrawingState( &m_drawingState ) ;
766 m_currentPort = newport ;
76a5e5d2
SC
767}
768void wxMacPortStateHelper::Clear()
769{
e40298d5
JS
770 if ( m_clip )
771 {
772 DisposeRgn( m_clip ) ;
773 DisposeThemeDrawingState( m_drawingState ) ;
774 m_clip = NULL ;
775 }
76a5e5d2
SC
776}
777
778wxMacPortStateHelper::~wxMacPortStateHelper()
779{
e40298d5
JS
780 if ( m_clip )
781 {
782 SetPort( m_currentPort ) ;
783 SetClip( m_clip ) ;
784 DisposeRgn( m_clip ) ;
785 TextFont( m_textFont );
786 TextSize( m_textSize );
787 TextFace( m_textStyle );
788 TextMode( m_textMode );
789 SetThemeDrawingState( m_drawingState , true ) ;
790 SetPort( m_oldPort ) ;
791 }
76a5e5d2
SC
792}
793
9c3c5849
SC
794OSStatus UMAPutScrap( Size size , OSType type , void *data )
795{
e40298d5 796 OSStatus err = noErr ;
9c3c5849
SC
797#if !TARGET_CARBON
798 err = PutScrap( size , type , data ) ;
799#else
800 ScrapRef scrap;
58751a86 801 err = GetCurrentScrap (&scrap);
9c3c5849
SC
802 if ( !err )
803 {
804 err = PutScrapFlavor (scrap, type , 0, size, data);
805 }
806#endif
e40298d5 807 return err ;
9c3c5849
SC
808}
809
facd6764
SC
810Rect* UMAGetControlBoundsInWindowCoords(ControlRef theControl, Rect *bounds)
811{
812 wxWindow* win = wxFindControlFromMacControl( theControl ) ;
813
814 GetControlBounds( theControl , bounds ) ;
815#if TARGET_API_MAC_OSX
816 if ( win != NULL && win->MacGetTopLevelWindow() != NULL )
817 {
818 int x , y ;
819 x = 0 ;
820 y = 0 ;
821
822 win->GetParent()->MacWindowToRootWindow( &x , & y ) ;
823 bounds->left += x ;
824 bounds->right += x ;
825 bounds->top += y ;
826 bounds->bottom += y ;
827 }
828#endif
829 return bounds ;
830}
831
832
2dbc444a
RD
833#endif // wxUSE_GUI
834
835#if wxUSE_BASE
836
837static bool sUMASystemInitialized = false ;
838
839bool UMASystemIsInitialized()
840{
841 return sUMASystemInitialized ;
842}
843
844void UMASetSystemIsInitialized(bool val)
845{
846 sUMASystemInitialized = val;
847}
848
849
850#endif // wxUSE_BASE