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