3 #include "wx/mac/uma.h"
6 #include <Navigation.h>
9 // since we have decided that we only support 8.6 upwards we are
10 // checking for these minimum requirements in the startup code of
11 // the application so all wxWindows code can safely assume that appearance 1.1
12 // windows manager, control manager, navigation services etc. are
15 static bool sUMAHasAppearance
= false ;
16 static long sUMAAppearanceVersion
= 0 ;
17 extern int gAGABackgroundColor
;
18 bool UMAHasAppearance() { return sUMAHasAppearance
; }
19 long UMAGetAppearanceVersion() { return sUMAAppearanceVersion
; }
21 static bool sUMAHasWindowManager
= false ;
22 static long sUMAWindowManagerAttr
= 0 ;
24 bool UMAHasWindowManager() { return sUMAHasWindowManager
; }
25 long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr
; }
27 void UMACleanupToolbox()
29 if ( sUMAHasAppearance
)
31 UnregisterAppearanceClient() ;
33 if ( NavServicesAvailable() )
38 void UMAInitToolbox( UInt16 inMoreMastersCalls
)
42 for (long i
= 1; i
<= inMoreMastersCalls
; i
++)
45 ::InitGraf(&qd
.thePort
);
50 ::FlushEvents(everyEvent
, 0);
53 PurgeSpace(&total
, &contig
);
59 if ( Gestalt( gestaltAppearanceAttr
, &theAppearance
) == noErr
)
61 sUMAHasAppearance
= true ;
62 RegisterAppearanceClient();
63 if ( Gestalt( gestaltAppearanceVersion
, &theAppearance
) == noErr
)
65 sUMAAppearanceVersion
= theAppearance
;
69 sUMAAppearanceVersion
= 0x0100 ;
72 if ( Gestalt( gestaltWindowMgrAttr
, &sUMAWindowManagerAttr
) == noErr
)
74 sUMAHasWindowManager
= sUMAWindowManagerAttr
& gestaltWindowMgrPresent
;
79 // Call currently implicitely done : InitFloatingWindows() ;
81 if ( sUMAHasWindowManager
)
82 InitFloatingWindows() ;
88 if ( NavServicesAvailable() )
95 long UMAGetProcessMode()
98 ProcessInfoRec processinfo
;
99 ProcessSerialNumber procno
;
101 procno
.highLongOfPSN
= NULL
;
102 procno
.lowLongOfPSN
= kCurrentProcess
;
103 processinfo
.processInfoLength
= sizeof(ProcessInfoRec
);
104 processinfo
.processName
= NULL
;
105 processinfo
.processAppSpec
= NULL
;
107 err
= ::GetProcessInformation( &procno
, &processinfo
) ;
108 wxASSERT( err
== noErr
) ;
109 return processinfo
.processMode
;
112 bool UMAGetProcessModeDoesActivateOnFGSwitch()
114 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch
;
119 void UMASetMenuTitle( MenuRef menu
, StringPtr title
)
122 long size
= GetHandleSize( (Handle
) menu
) ;
123 const long headersize
= 14 ;
124 int oldlen
= (**menu
).menuData
[0] + 1;
125 int newlen
= title
[0] + 1 ;
127 if ( oldlen
< newlen
)
129 // enlarge before adjusting
130 SetHandleSize( (Handle
) menu
, size
+ (newlen
- oldlen
) );
133 if ( oldlen
!= newlen
)
134 memmove( (char*) (**menu
).menuData
+ newlen
, (char*) (**menu
).menuData
+ oldlen
, size
- headersize
- oldlen
) ;
136 memcpy( (char*) (**menu
).menuData
, title
, newlen
) ;
137 if ( oldlen
> newlen
)
140 SetHandleSize( (Handle
) menu
, size
+ (newlen
- oldlen
) ) ;
143 SetMenuTitle( menu
, title
) ;
147 UInt32
UMAMenuEvent( EventRecord
*inEvent
)
149 return MenuEvent( inEvent
) ;
152 void UMAEnableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
154 EnableMenuItem( inMenu
, inItem
) ;
157 void UMADisableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
159 DisableMenuItem( inMenu
, inItem
) ;
162 void UMAAppendSubMenuItem( MenuRef menu
, StringPtr l
, SInt16 id
)
165 memcpy( label
, l
, l
[0]+1 ) ;
166 // hardcoded adding of the submenu combination for mac
168 int theEnd
= label
[0] + 1;
170 theEnd
= 251; // mac allows only 255 characters
171 label
[theEnd
++] = '/';
172 label
[theEnd
++] = hMenuCmd
;
173 label
[theEnd
++] = '!';
174 label
[theEnd
++] = id
;
175 label
[theEnd
] = 0x00;
177 MacAppendMenu(menu
, label
);
180 void UMAInsertSubMenuItem( MenuRef menu
, StringPtr l
, MenuItemIndex item
, SInt16 id
)
183 memcpy( label
, l
, l
[0]+1 ) ;
184 // hardcoded adding of the submenu combination for mac
186 int theEnd
= label
[0] + 1;
188 theEnd
= 251; // mac allows only 255 characters
189 label
[theEnd
++] = '/';
190 label
[theEnd
++] = hMenuCmd
;
191 label
[theEnd
++] = '!';
192 label
[theEnd
++] = id
;
193 label
[theEnd
] = 0x00;
195 MacInsertMenuItem(menu
, label
, item
);
198 void UMAAppendMenuItem( MenuRef menu
, StringPtr l
, SInt16 key
, UInt8 modifiers
)
201 memcpy( label
, l
, l
[0]+1 ) ;
206 label
[++pos
] = toupper( key
);
209 MacAppendMenu( menu
, label
) ;
212 void UMAInsertMenuItem( MenuRef menu
, StringPtr l
, MenuItemIndex item
, SInt16 key
, UInt8 modifiers
)
215 memcpy( label
, l
, l
[0]+1 ) ;
220 label
[++pos
] = toupper( key
);
223 MacInsertMenuItem( menu
, label
, item
) ;
228 int gPrOpenCounter
= 0 ;
230 #if TARGET_CARBON && PM_USE_SESSION_APIS
231 OSStatus
UMAPrOpen(PMPrintSession
*macPrintSession
)
239 if ( gPrOpenCounter
== 1 )
243 wxASSERT( err
== noErr
) ;
247 OSStatus err
= noErr
;
249 if ( gPrOpenCounter
== 1 )
251 #if PM_USE_SESSION_APIS
252 err
= PMCreateSession(macPrintSession
) ;
256 wxASSERT( err
== noErr
) ;
262 #if TARGET_CARBON && PM_USE_SESSION_APIS
263 OSStatus
UMAPrClose(PMPrintSession
*macPrintSession
)
265 OSStatus
UMAPrClose()
270 wxASSERT( gPrOpenCounter
>= 1 ) ;
271 if ( gPrOpenCounter
== 1 )
275 wxASSERT( err
== noErr
) ;
280 OSStatus err
= noErr
;
281 wxASSERT( gPrOpenCounter
>= 1 ) ;
282 if ( gPrOpenCounter
== 1 )
284 #if PM_USE_SESSION_APIS
285 err
= PMRelease(*macPrintSession
) ;
286 *macPrintSession
= kPMNoReference
;
298 pascal QDGlobalsPtr
GetQDGlobalsPtr (void) ;
299 pascal QDGlobalsPtr
GetQDGlobalsPtr (void)
301 return QDGlobalsPtr (* (Ptr
*) LMGetCurrentA5 ( ) - 0xCA);
306 void UMAShowWatchCursor()
310 CursHandle watchFob
= GetCursor (watchCursor
);
317 // Cursor preservedArrow;
318 // GetQDGlobalsArrow (&preservedArrow);
319 // SetQDGlobalsArrow (*watchFob);
321 // SetQDGlobalsArrow (&preservedArrow);
322 SetCursor (*watchFob
);
324 SetCursor (*watchFob
);
329 void UMAShowArrowCursor()
333 SetCursor (GetQDGlobalsArrow (&arrow
));
335 SetCursor (&(qd
.arrow
));
341 GrafPtr
UMAGetWindowPort( WindowRef inWindowRef
)
343 wxASSERT( inWindowRef
!= NULL
) ;
345 return GetWindowPort( inWindowRef
) ;
347 return (GrafPtr
) inWindowRef
;
351 void UMADisposeWindow( WindowRef inWindowRef
)
353 wxASSERT( inWindowRef
!= NULL
) ;
354 DisposeWindow( inWindowRef
) ;
357 void UMASetWTitleC( WindowRef inWindowRef
, const char *title
)
360 strncpy( (char*)ptitle
, title
, 96 ) ;
363 c2pstrcpy( ptitle
, (char *)ptitle
) ;
365 c2pstr( (char*)ptitle
) ;
367 SetWTitle( inWindowRef
, ptitle
) ;
370 void UMAGetWTitleC( WindowRef inWindowRef
, char *title
)
372 GetWTitle( inWindowRef
, (unsigned char*)title
) ;
374 p2cstrcpy( title
, (unsigned char *)title
) ;
376 p2cstr( (unsigned char*)title
) ;
380 // appearance additions
382 void UMAActivateControl( ControlHandle inControl
)
384 if ( !IsControlActive( inControl
) )
386 bool visible
= IsControlVisible( inControl
) ;
388 SetControlVisibility( inControl
, false , false ) ;
389 ::ActivateControl( inControl
) ;
391 SetControlVisibility( inControl
, true , false ) ;
393 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
398 void UMADrawControl( ControlHandle inControl
)
400 WindowRef theWindow
= GetControlOwner(inControl
) ;
401 RgnHandle updateRgn
= NewRgn() ;
402 GetWindowUpdateRgn( theWindow
, updateRgn
) ;
403 Point zero
= { 0 , 0 } ;
404 LocalToGlobal( &zero
) ;
405 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
406 ::DrawControlInCurrentPort( inControl
) ;
407 InvalWindowRgn( theWindow
, updateRgn
) ;
408 DisposeRgn( updateRgn
) ;
412 void UMAMoveControl( ControlHandle inControl
, short x
, short y
)
414 bool visible
= IsControlVisible( inControl
) ;
416 SetControlVisibility( inControl
, false , false ) ;
418 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
420 ::MoveControl( inControl
, x
, y
) ;
422 SetControlVisibility( inControl
, true , false ) ;
424 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
428 void UMASizeControl( ControlHandle inControl
, short x
, short y
)
430 bool visible
= IsControlVisible( inControl
) ;
432 SetControlVisibility( inControl
, false , false ) ;
434 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
436 ::SizeControl( inControl
, x
, y
) ;
438 SetControlVisibility( inControl
, true , false ) ;
440 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
444 void UMADeactivateControl( ControlHandle inControl
)
446 if ( IsControlActive( inControl
) )
448 bool visible
= IsControlVisible( inControl
) ;
450 SetControlVisibility( inControl
, false , false ) ;
451 ::DeactivateControl( inControl
) ;
453 SetControlVisibility( inControl
, true , false ) ;
455 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
459 // shows the control and adds the region to the update region
460 void UMAShowControl (ControlHandle inControl
)
462 SetControlVisibility( inControl
, true , false ) ;
464 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
468 OSErr
UMASetKeyboardFocus (WindowPtr inWindow
,
469 ControlHandle inControl
,
470 ControlFocusPart inPart
)
476 SetPortWindowPort( inWindow
) ;
479 err
= SetKeyboardFocus( inWindow
, inControl
, inPart
) ;
488 void UMAUpdateControls( WindowPtr inWindow
, RgnHandle inRgn
)
490 RgnHandle updateRgn
= NewRgn() ;
491 GetWindowUpdateRgn( inWindow
, updateRgn
) ;
493 Point zero
= { 0 , 0 } ;
494 LocalToGlobal( &zero
) ;
495 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
497 UpdateControls( inWindow
, inRgn
) ;
498 InvalWindowRgn( inWindow
, updateRgn
) ;
499 DisposeRgn( updateRgn
) ;
503 bool UMAIsWindowFloating( WindowRef inWindow
)
507 GetWindowClass( inWindow
, &cl
) ;
508 return cl
== kFloatingWindowClass
;
511 bool UMAIsWindowModal( WindowRef inWindow
)
515 GetWindowClass( inWindow
, &cl
) ;
516 return cl
< kFloatingWindowClass
;
521 void UMAHighlightAndActivateWindow( WindowRef inWindowRef
, bool inActivate
)
525 // bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
526 // if ( inActivate != isHightlited )
529 SetPortWindowPort( inWindowRef
) ;
531 HiliteWindow( inWindowRef
, inActivate
) ;
532 ControlHandle control
= NULL
;
533 ::GetRootControl( inWindowRef
, & control
) ;
537 UMAActivateControl( control
) ;
539 UMADeactivateControl( control
) ;
544 OSStatus
UMADrawThemePlacard( const Rect
*inRect
, ThemeDrawState inState
)
546 return ::DrawThemePlacard( inRect
, inState
) ;