3 #include "wx/mac/uma.h"
4 #include <MacTextEditor.h>
7 #include <Navigation.h>
10 // since we have decided that we only support 8.6 upwards we are
11 // checking for these minimum requirements in the startup code of
12 // the application so all wxWindows code can safely assume that appearance 1.1
13 // windows manager, control manager, navigation services etc. are
19 static bool sUMAHasAppearance
= false ;
20 static long sUMAAppearanceVersion
= 0 ;
21 static bool sUMAHasAquaLayout
= false ;
22 extern int gAGABackgroundColor
;
23 bool UMAHasAppearance() { return sUMAHasAppearance
; }
24 long UMAGetAppearanceVersion() { return sUMAAppearanceVersion
; }
26 static bool sUMAHasWindowManager
= false ;
27 static long sUMAWindowManagerAttr
= 0 ;
29 bool UMAHasWindowManager() { return sUMAHasWindowManager
; }
30 long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr
; }
31 bool UMAHasAquaLayout() { return sUMAHasAquaLayout
; }
34 void UMACleanupToolbox()
36 if ( sUMAHasAppearance
)
38 UnregisterAppearanceClient() ;
40 if ( NavServicesAvailable() )
45 TXNTerminateTextension( ) ;
48 void UMAInitToolbox( UInt16 inMoreMastersCalls
)
52 for (long i
= 1; i
<= inMoreMastersCalls
; i
++)
55 ::InitGraf(&qd
.thePort
);
60 ::FlushEvents(everyEvent
, 0);
63 PurgeSpace(&total
, &contig
);
69 if ( Gestalt( gestaltAppearanceAttr
, &theAppearance
) == noErr
)
71 sUMAHasAppearance
= true ;
72 RegisterAppearanceClient();
73 if ( Gestalt( gestaltAppearanceVersion
, &theAppearance
) == noErr
)
75 sUMAAppearanceVersion
= theAppearance
;
79 sUMAAppearanceVersion
= 0x0100 ;
82 if ( Gestalt( gestaltWindowMgrAttr
, &sUMAWindowManagerAttr
) == noErr
)
84 sUMAHasWindowManager
= sUMAWindowManagerAttr
& gestaltWindowMgrPresent
;
89 // Call currently implicitely done : InitFloatingWindows() ;
91 if ( sUMAHasWindowManager
)
92 InitFloatingWindows() ;
98 if ( NavServicesAvailable() )
104 TXNMacOSPreferredFontDescription defaults
;
105 defaults
.fontID
= kFontIDGeneva
;
106 defaults
.pointSize
= (10 << 16) ;
107 defaults
.fontStyle
= kTXNDefaultFontStyle
;
108 defaults
.encoding
= kTXNSystemDefaultEncoding
;
109 TXNInitTextension(&defaults
, 1, (kTXNAlwaysUseQuickDrawTextMask
| kTXNWantMoviesMask
| kTXNWantSoundMask
| kTXNWantGraphicsMask
));
112 Gestalt( gestaltMenuMgrAttr
, &menuMgrAttr
) ;
113 if ( menuMgrAttr
& gestaltMenuMgrAquaLayoutMask
)
114 sUMAHasAquaLayout
= true ;
119 long UMAGetProcessMode()
122 ProcessInfoRec processinfo
;
123 ProcessSerialNumber procno
;
125 procno
.highLongOfPSN
= NULL
;
126 procno
.lowLongOfPSN
= kCurrentProcess
;
127 processinfo
.processInfoLength
= sizeof(ProcessInfoRec
);
128 processinfo
.processName
= NULL
;
129 processinfo
.processAppSpec
= NULL
;
131 err
= ::GetProcessInformation( &procno
, &processinfo
) ;
132 wxASSERT( err
== noErr
) ;
133 return processinfo
.processMode
;
136 bool UMAGetProcessModeDoesActivateOnFGSwitch()
138 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch
;
143 void UMASetMenuTitle( MenuRef menu
, StringPtr title
)
147 long size = GetHandleSize( (Handle) menu ) ;
148 const long headersize = 14 ;
149 int oldlen = (**menu).menuData[0] + 1;
150 int newlen = title[0] + 1 ;
152 if ( oldlen < newlen )
154 // enlarge before adjusting
155 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) );
158 if ( oldlen != newlen )
159 memmove( (char*) (**menu).menuData + newlen , (char*) (**menu).menuData + oldlen , size - headersize - oldlen ) ;
161 memcpy( (char*) (**menu).menuData , title , newlen ) ;
162 if ( oldlen > newlen )
165 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) ) ;
169 SetMenuTitle( menu
, title
) ;
173 UInt32
UMAMenuEvent( EventRecord
*inEvent
)
175 return MenuEvent( inEvent
) ;
178 void UMAEnableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
180 EnableMenuItem( inMenu
, inItem
) ;
183 void UMADisableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
185 DisableMenuItem( inMenu
, inItem
) ;
188 void UMAAppendSubMenuItem( MenuRef menu
, StringPtr l
, SInt16 id
)
191 memcpy( label
, l
, l
[0]+1 ) ;
192 // hardcoded adding of the submenu combination for mac
194 int theEnd
= label
[0] + 1;
196 theEnd
= 251; // mac allows only 255 characters
197 label
[theEnd
++] = '/';
198 label
[theEnd
++] = hMenuCmd
;
199 label
[theEnd
++] = '!';
200 label
[theEnd
++] = id
;
201 label
[theEnd
] = 0x00;
203 MacAppendMenu(menu
, label
);
206 void UMAInsertSubMenuItem( MenuRef menu
, StringPtr l
, MenuItemIndex item
, SInt16 id
)
209 memcpy( label
, l
, l
[0]+1 ) ;
210 // hardcoded adding of the submenu combination for mac
212 int theEnd
= label
[0] + 1;
214 theEnd
= 251; // mac allows only 255 characters
215 label
[theEnd
++] = '/';
216 label
[theEnd
++] = hMenuCmd
;
217 label
[theEnd
++] = '!';
218 label
[theEnd
++] = id
;
219 label
[theEnd
] = 0x00;
221 MacInsertMenuItem(menu
, label
, item
);
224 void UMAAppendMenuItem( MenuRef menu
, StringPtr l
, SInt16 key
, UInt8 modifiers
)
227 memcpy( label
, l
, l
[0]+1 ) ;
232 label
[++pos
] = toupper( key
);
235 MacAppendMenu( menu
, label
) ;
238 void UMAInsertMenuItem( MenuRef menu
, StringPtr l
, MenuItemIndex item
, SInt16 key
, UInt8 modifiers
)
241 memcpy( label
, l
, l
[0]+1 ) ;
246 label
[++pos
] = toupper( key
);
249 MacInsertMenuItem( menu
, label
, item
) ;
254 int gPrOpenCounter
= 0 ;
256 #if TARGET_CARBON && PM_USE_SESSION_APIS
257 OSStatus
UMAPrOpen(PMPrintSession
*macPrintSession
)
265 if ( gPrOpenCounter
== 1 )
269 wxASSERT( err
== noErr
) ;
273 OSStatus err
= noErr
;
275 if ( gPrOpenCounter
== 1 )
277 #if PM_USE_SESSION_APIS
278 err
= PMCreateSession(macPrintSession
) ;
282 wxASSERT( err
== noErr
) ;
288 #if TARGET_CARBON && PM_USE_SESSION_APIS
289 OSStatus
UMAPrClose(PMPrintSession
*macPrintSession
)
291 OSStatus
UMAPrClose()
296 wxASSERT( gPrOpenCounter
>= 1 ) ;
297 if ( gPrOpenCounter
== 1 )
301 wxASSERT( err
== noErr
) ;
306 OSStatus err
= noErr
;
307 wxASSERT( gPrOpenCounter
>= 1 ) ;
308 if ( gPrOpenCounter
== 1 )
310 #if PM_USE_SESSION_APIS
311 err
= PMRelease(*macPrintSession
) ;
312 *macPrintSession
= kPMNoReference
;
324 pascal QDGlobalsPtr
GetQDGlobalsPtr (void) ;
325 pascal QDGlobalsPtr
GetQDGlobalsPtr (void)
327 return QDGlobalsPtr (* (Ptr
*) LMGetCurrentA5 ( ) - 0xCA);
332 void UMAShowWatchCursor()
336 CursHandle watchFob
= GetCursor (watchCursor
);
343 // Cursor preservedArrow;
344 // GetQDGlobalsArrow (&preservedArrow);
345 // SetQDGlobalsArrow (*watchFob);
347 // SetQDGlobalsArrow (&preservedArrow);
348 SetCursor (*watchFob
);
350 SetCursor (*watchFob
);
355 void UMAShowArrowCursor()
359 SetCursor (GetQDGlobalsArrow (&arrow
));
361 SetCursor (&(qd
.arrow
));
367 GrafPtr
UMAGetWindowPort( WindowRef inWindowRef
)
369 wxASSERT( inWindowRef
!= NULL
) ;
371 return GetWindowPort( inWindowRef
) ;
373 return (GrafPtr
) inWindowRef
;
377 void UMADisposeWindow( WindowRef inWindowRef
)
379 wxASSERT( inWindowRef
!= NULL
) ;
380 DisposeWindow( inWindowRef
) ;
383 void UMASetWTitleC( WindowRef inWindowRef
, const char *title
)
386 strncpy( (char*)ptitle
, title
, 96 ) ;
389 c2pstrcpy( ptitle
, (char *)ptitle
) ;
391 c2pstr( (char*)ptitle
) ;
393 SetWTitle( inWindowRef
, ptitle
) ;
396 void UMAGetWTitleC( WindowRef inWindowRef
, char *title
)
398 GetWTitle( inWindowRef
, (unsigned char*)title
) ;
400 p2cstrcpy( title
, (unsigned char *)title
) ;
402 p2cstr( (unsigned char*)title
) ;
406 // appearance additions
408 void UMAActivateControl( ControlHandle inControl
)
410 // we have to add the control after again to the update rgn
411 // otherwise updates get lost
412 if ( !IsControlActive( inControl
) )
414 bool visible
= IsControlVisible( inControl
) ;
416 SetControlVisibility( inControl
, false , false ) ;
417 ::ActivateControl( inControl
) ;
419 SetControlVisibility( inControl
, true , false ) ;
421 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
426 void UMADrawControl( ControlHandle inControl
)
428 WindowRef theWindow
= GetControlOwner(inControl
) ;
429 RgnHandle updateRgn
= NewRgn() ;
430 GetWindowUpdateRgn( theWindow
, updateRgn
) ;
431 Point zero
= { 0 , 0 } ;
432 LocalToGlobal( &zero
) ;
433 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
434 ::DrawControlInCurrentPort( inControl
) ;
435 InvalWindowRgn( theWindow
, updateRgn
) ;
436 DisposeRgn( updateRgn
) ;
439 void UMAMoveControl( ControlHandle inControl
, short x
, short y
)
441 bool visible
= IsControlVisible( inControl
) ;
443 SetControlVisibility( inControl
, false , false ) ;
445 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
447 ::MoveControl( inControl
, x
, y
) ;
449 SetControlVisibility( inControl
, true , false ) ;
451 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
455 void UMASizeControl( ControlHandle inControl
, short x
, short y
)
457 bool visible
= IsControlVisible( inControl
) ;
459 SetControlVisibility( inControl
, false , false ) ;
461 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
463 ::SizeControl( inControl
, x
, y
) ;
465 SetControlVisibility( inControl
, true , false ) ;
467 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
471 void UMADeactivateControl( ControlHandle inControl
)
473 // we have to add the control after again to the update rgn
474 // otherwise updates get lost
475 bool visible
= IsControlVisible( inControl
) ;
477 SetControlVisibility( inControl
, false , false ) ;
478 ::DeactivateControl( inControl
) ;
480 SetControlVisibility( inControl
, true , false ) ;
482 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
485 // shows the control and adds the region to the update region
486 void UMAShowControl (ControlHandle inControl
)
488 SetControlVisibility( inControl
, true , false ) ;
490 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
493 // shows the control and adds the region to the update region
494 void UMAHideControl (ControlHandle inControl
)
496 SetControlVisibility( inControl
, false , false ) ;
498 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
501 OSErr
UMASetKeyboardFocus (WindowPtr inWindow
,
502 ControlHandle inControl
,
503 ControlFocusPart inPart
)
509 SetPortWindowPort( inWindow
) ;
511 err
= SetKeyboardFocus( inWindow
, inControl
, inPart
) ;
520 void UMAUpdateControls( WindowPtr inWindow
, RgnHandle inRgn
)
522 RgnHandle updateRgn
= NewRgn() ;
523 GetWindowUpdateRgn( inWindow
, updateRgn
) ;
525 Point zero
= { 0 , 0 } ;
526 LocalToGlobal( &zero
) ;
527 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
529 UpdateControls( inWindow
, inRgn
) ;
530 InvalWindowRgn( inWindow
, updateRgn
) ;
531 DisposeRgn( updateRgn
) ;
535 bool UMAIsWindowFloating( WindowRef inWindow
)
539 GetWindowClass( inWindow
, &cl
) ;
540 return cl
== kFloatingWindowClass
;
543 bool UMAIsWindowModal( WindowRef inWindow
)
547 GetWindowClass( inWindow
, &cl
) ;
548 return cl
< kFloatingWindowClass
;
553 void UMAHighlightAndActivateWindow( WindowRef inWindowRef
, bool inActivate
)
557 // bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
558 // if ( inActivate != isHightlited )
561 SetPortWindowPort( inWindowRef
) ;
562 HiliteWindow( inWindowRef
, inActivate
) ;
563 ControlHandle control
= NULL
;
564 ::GetRootControl( inWindowRef
, & control
) ;
568 UMAActivateControl( control
) ;
570 UMADeactivateControl( control
) ;
575 OSStatus
UMADrawThemePlacard( const Rect
*inRect
, ThemeDrawState inState
)
577 return ::DrawThemePlacard( inRect
, inState
) ;
580 static OSStatus helpMenuStatus
= noErr
;
581 static MenuRef helpMenuHandle
= NULL
;
582 static MenuItemIndex firstCustomItemIndex
= 0 ;
584 OSStatus
UMAGetHelpMenu(
585 MenuRef
* outHelpMenu
,
586 MenuItemIndex
* outFirstCustomItemIndex
)
589 return HMGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
) ;
591 if ( helpMenuHandle
== NULL
)
593 helpMenuStatus
= HMGetHelpMenuHandle( &helpMenuHandle
) ;
594 if ( helpMenuStatus
== noErr
)
596 firstCustomItemIndex
= CountMenuItems( helpMenuHandle
) + 1 ;
599 if ( outFirstCustomItemIndex
)
601 *outFirstCustomItemIndex
= firstCustomItemIndex
;
603 *outHelpMenu
= helpMenuHandle
;
604 return helpMenuStatus
;
608 wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport
)
614 wxMacPortStateHelper::wxMacPortStateHelper()
619 void wxMacPortStateHelper::Setup( GrafPtr newport
)
621 GetPort( &m_oldPort
) ;
623 wxASSERT_MSG( m_clip
== NULL
, "Cannot call setup twice" ) ;
626 m_textFont
= GetPortTextFont( (CGrafPtr
) newport
);
627 m_textSize
= GetPortTextSize( (CGrafPtr
) newport
);
628 m_textStyle
= GetPortTextFace( (CGrafPtr
) newport
);
629 m_textMode
= GetPortTextMode( (CGrafPtr
) newport
);
630 GetThemeDrawingState( &m_drawingState
) ;
631 m_currentPort
= newport
;
633 void wxMacPortStateHelper::Clear()
637 DisposeRgn( m_clip
) ;
638 DisposeThemeDrawingState( m_drawingState
) ;
643 wxMacPortStateHelper::~wxMacPortStateHelper()
647 SetPort( m_currentPort
) ;
649 DisposeRgn( m_clip
) ;
650 TextFont( m_textFont
);
651 TextSize( m_textSize
);
652 TextFace( m_textStyle
);
653 TextMode( m_textMode
);
654 SetThemeDrawingState( m_drawingState
, true ) ;
655 SetPort( m_oldPort
) ;