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