3 #include "wx/mac/uma.h"
4 #include <MacTextEditor.h>
7 # include <Navigation.h>
8 # if defined(TARGET_CARBON)
9 # if PM_USE_SESSION_APIS
12 # include <PMApplication.h>
16 // since we have decided that we only support 8.6 upwards we are
17 // checking for these minimum requirements in the startup code of
18 // the application so all wxWindows code can safely assume that appearance 1.1
19 // windows manager, control manager, navigation services etc. are
25 static bool sUMAHasAppearance
= false ;
26 static long sUMAAppearanceVersion
= 0 ;
27 static bool sUMAHasAquaLayout
= false ;
28 static bool sUMASystemInitialized
= false ;
30 extern int gAGABackgroundColor
;
31 bool UMAHasAppearance() { return sUMAHasAppearance
; }
32 long UMAGetAppearanceVersion() { return sUMAAppearanceVersion
; }
34 static bool sUMAHasWindowManager
= false ;
35 static long sUMAWindowManagerAttr
= 0 ;
37 bool UMAHasWindowManager() { return sUMAHasWindowManager
; }
38 long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr
; }
39 bool UMAHasAquaLayout() { return sUMAHasAquaLayout
; }
40 bool UMASystemIsInitialized() { return sUMASystemInitialized
; }
42 void UMACleanupToolbox()
44 if ( sUMAHasAppearance
)
46 UnregisterAppearanceClient() ;
48 if ( NavServicesAvailable() )
53 TXNTerminateTextension( ) ;
56 void UMAInitToolbox( UInt16 inMoreMastersCalls
)
60 for (long i
= 1; i
<= inMoreMastersCalls
; i
++)
63 ::InitGraf(&qd
.thePort
);
68 ::FlushEvents(everyEvent
, 0);
71 PurgeSpace(&total
, &contig
);
77 if ( Gestalt( gestaltAppearanceAttr
, &theAppearance
) == noErr
)
79 sUMAHasAppearance
= true ;
80 RegisterAppearanceClient();
81 if ( Gestalt( gestaltAppearanceVersion
, &theAppearance
) == noErr
)
83 sUMAAppearanceVersion
= theAppearance
;
87 sUMAAppearanceVersion
= 0x0100 ;
90 if ( Gestalt( gestaltWindowMgrAttr
, &sUMAWindowManagerAttr
) == noErr
)
92 sUMAHasWindowManager
= sUMAWindowManagerAttr
& gestaltWindowMgrPresent
;
97 // Call currently implicitely done : InitFloatingWindows() ;
99 if ( sUMAHasWindowManager
)
100 InitFloatingWindows() ;
106 if ( NavServicesAvailable() )
112 TXNMacOSPreferredFontDescription defaults
;
113 defaults
.fontID
= kFontIDGeneva
;
114 defaults
.pointSize
= (10 << 16) ;
115 defaults
.fontStyle
= kTXNDefaultFontStyle
;
116 defaults
.encoding
= kTXNSystemDefaultEncoding
;
117 TXNInitTextension(&defaults
, 1, (kTXNAlwaysUseQuickDrawTextMask
| kTXNWantMoviesMask
| kTXNWantSoundMask
| kTXNWantGraphicsMask
));
120 Gestalt( gestaltMenuMgrAttr
, &menuMgrAttr
) ;
121 if ( menuMgrAttr
& gestaltMenuMgrAquaLayoutMask
)
122 sUMAHasAquaLayout
= true ;
123 sUMASystemInitialized
= true ;
127 long UMAGetProcessMode()
130 ProcessInfoRec processinfo
;
131 ProcessSerialNumber procno
;
133 procno
.highLongOfPSN
= NULL
;
134 procno
.lowLongOfPSN
= kCurrentProcess
;
135 processinfo
.processInfoLength
= sizeof(ProcessInfoRec
);
136 processinfo
.processName
= NULL
;
137 processinfo
.processAppSpec
= NULL
;
139 err
= ::GetProcessInformation( &procno
, &processinfo
) ;
140 wxASSERT( err
== noErr
) ;
141 return processinfo
.processMode
;
144 bool UMAGetProcessModeDoesActivateOnFGSwitch()
146 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch
;
151 void UMASetMenuTitle( MenuRef menu
, StringPtr title
)
155 long size = GetHandleSize( (Handle) menu ) ;
156 const long headersize = 14 ;
157 int oldlen = (**menu).menuData[0] + 1;
158 int newlen = title[0] + 1 ;
160 if ( oldlen < newlen )
162 // enlarge before adjusting
163 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) );
166 if ( oldlen != newlen )
167 memmove( (char*) (**menu).menuData + newlen , (char*) (**menu).menuData + oldlen , size - headersize - oldlen ) ;
169 memcpy( (char*) (**menu).menuData , title , newlen ) ;
170 if ( oldlen > newlen )
173 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) ) ;
177 SetMenuTitle( menu
, title
) ;
181 UInt32
UMAMenuEvent( EventRecord
*inEvent
)
183 return MenuEvent( inEvent
) ;
186 void UMAEnableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
188 EnableMenuItem( inMenu
, inItem
) ;
191 void UMADisableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
193 DisableMenuItem( inMenu
, inItem
) ;
196 void UMAAppendSubMenuItem( MenuRef menu
, StringPtr l
, SInt16 id
)
199 memcpy( label
, l
, l
[0]+1 ) ;
200 // hardcoded adding of the submenu combination for mac
202 int theEnd
= label
[0] + 1;
204 theEnd
= 251; // mac allows only 255 characters
205 label
[theEnd
++] = '/';
206 label
[theEnd
++] = hMenuCmd
;
207 label
[theEnd
++] = '!';
208 label
[theEnd
++] = id
;
209 label
[theEnd
] = 0x00;
211 MacAppendMenu(menu
, label
);
214 void UMAInsertSubMenuItem( MenuRef menu
, StringPtr l
, MenuItemIndex item
, SInt16 id
)
217 memcpy( label
, l
, l
[0]+1 ) ;
218 // hardcoded adding of the submenu combination for mac
220 int theEnd
= label
[0] + 1;
222 theEnd
= 251; // mac allows only 255 characters
223 label
[theEnd
++] = '/';
224 label
[theEnd
++] = hMenuCmd
;
225 label
[theEnd
++] = '!';
226 label
[theEnd
++] = id
;
227 label
[theEnd
] = 0x00;
229 MacInsertMenuItem(menu
, label
, item
);
232 void UMAAppendMenuItem( MenuRef menu
, StringPtr l
, SInt16 key
, UInt8 modifiers
)
235 memcpy( label
, l
, l
[0]+1 ) ;
240 label
[++pos
] = toupper( key
);
243 MacAppendMenu( menu
, label
) ;
246 void UMAInsertMenuItem( MenuRef menu
, StringPtr l
, MenuItemIndex item
, SInt16 key
, UInt8 modifiers
)
249 memcpy( label
, l
, l
[0]+1 ) ;
254 label
[++pos
] = toupper( key
);
257 MacInsertMenuItem( menu
, label
, item
) ;
262 int gPrOpenCounter
= 0 ;
264 OSStatus
UMAPrOpen(void *macPrintSession
)
269 if ( gPrOpenCounter
== 1 )
273 wxASSERT( err
== noErr
) ;
277 OSStatus err
= noErr
;
279 if ( gPrOpenCounter
== 1 )
281 #if PM_USE_SESSION_APIS
282 err
= PMCreateSession((PMPrintSession
*)macPrintSession
) ;
286 wxASSERT( err
== noErr
) ;
292 OSStatus
UMAPrClose(void *macPrintSession
)
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(*(PMPrintSession
*)macPrintSession
) ;
312 *(PMPrintSession
*)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
) ;