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
)
146 long size
= GetHandleSize( (Handle
) menu
) ;
147 const long headersize
= 14 ;
148 int oldlen
= (**menu
).menuData
[0] + 1;
149 int newlen
= title
[0] + 1 ;
151 if ( oldlen
< newlen
)
153 // enlarge before adjusting
154 SetHandleSize( (Handle
) menu
, size
+ (newlen
- oldlen
) );
157 if ( oldlen
!= newlen
)
158 memmove( (char*) (**menu
).menuData
+ newlen
, (char*) (**menu
).menuData
+ oldlen
, size
- headersize
- oldlen
) ;
160 memcpy( (char*) (**menu
).menuData
, title
, newlen
) ;
161 if ( oldlen
> newlen
)
164 SetHandleSize( (Handle
) menu
, size
+ (newlen
- oldlen
) ) ;
167 SetMenuTitle( menu
, title
) ;
171 UInt32
UMAMenuEvent( EventRecord
*inEvent
)
173 return MenuEvent( inEvent
) ;
176 void UMAEnableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
178 EnableMenuItem( inMenu
, inItem
) ;
181 void UMADisableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
183 DisableMenuItem( inMenu
, inItem
) ;
186 void UMAAppendSubMenuItem( MenuRef menu
, StringPtr l
, SInt16 id
)
189 memcpy( label
, l
, l
[0]+1 ) ;
190 // hardcoded adding of the submenu combination for mac
192 int theEnd
= label
[0] + 1;
194 theEnd
= 251; // mac allows only 255 characters
195 label
[theEnd
++] = '/';
196 label
[theEnd
++] = hMenuCmd
;
197 label
[theEnd
++] = '!';
198 label
[theEnd
++] = id
;
199 label
[theEnd
] = 0x00;
201 MacAppendMenu(menu
, label
);
204 void UMAInsertSubMenuItem( MenuRef menu
, StringPtr l
, MenuItemIndex item
, SInt16 id
)
207 memcpy( label
, l
, l
[0]+1 ) ;
208 // hardcoded adding of the submenu combination for mac
210 int theEnd
= label
[0] + 1;
212 theEnd
= 251; // mac allows only 255 characters
213 label
[theEnd
++] = '/';
214 label
[theEnd
++] = hMenuCmd
;
215 label
[theEnd
++] = '!';
216 label
[theEnd
++] = id
;
217 label
[theEnd
] = 0x00;
219 MacInsertMenuItem(menu
, label
, item
);
222 void UMAAppendMenuItem( MenuRef menu
, StringPtr l
, SInt16 key
, UInt8 modifiers
)
225 memcpy( label
, l
, l
[0]+1 ) ;
230 label
[++pos
] = toupper( key
);
233 MacAppendMenu( menu
, label
) ;
236 void UMAInsertMenuItem( MenuRef menu
, StringPtr l
, MenuItemIndex item
, SInt16 key
, UInt8 modifiers
)
239 memcpy( label
, l
, l
[0]+1 ) ;
244 label
[++pos
] = toupper( key
);
247 MacInsertMenuItem( menu
, label
, item
) ;
252 int gPrOpenCounter
= 0 ;
254 #if TARGET_CARBON && PM_USE_SESSION_APIS
255 OSStatus
UMAPrOpen(PMPrintSession
*macPrintSession
)
263 if ( gPrOpenCounter
== 1 )
267 wxASSERT( err
== noErr
) ;
271 OSStatus err
= noErr
;
273 if ( gPrOpenCounter
== 1 )
275 #if PM_USE_SESSION_APIS
276 err
= PMCreateSession(macPrintSession
) ;
280 wxASSERT( err
== noErr
) ;
286 #if TARGET_CARBON && PM_USE_SESSION_APIS
287 OSStatus
UMAPrClose(PMPrintSession
*macPrintSession
)
289 OSStatus
UMAPrClose()
294 wxASSERT( gPrOpenCounter
>= 1 ) ;
295 if ( gPrOpenCounter
== 1 )
299 wxASSERT( err
== noErr
) ;
304 OSStatus err
= noErr
;
305 wxASSERT( gPrOpenCounter
>= 1 ) ;
306 if ( gPrOpenCounter
== 1 )
308 #if PM_USE_SESSION_APIS
309 err
= PMRelease(*macPrintSession
) ;
310 *macPrintSession
= kPMNoReference
;
322 pascal QDGlobalsPtr
GetQDGlobalsPtr (void) ;
323 pascal QDGlobalsPtr
GetQDGlobalsPtr (void)
325 return QDGlobalsPtr (* (Ptr
*) LMGetCurrentA5 ( ) - 0xCA);
330 void UMAShowWatchCursor()
334 CursHandle watchFob
= GetCursor (watchCursor
);
341 // Cursor preservedArrow;
342 // GetQDGlobalsArrow (&preservedArrow);
343 // SetQDGlobalsArrow (*watchFob);
345 // SetQDGlobalsArrow (&preservedArrow);
346 SetCursor (*watchFob
);
348 SetCursor (*watchFob
);
353 void UMAShowArrowCursor()
357 SetCursor (GetQDGlobalsArrow (&arrow
));
359 SetCursor (&(qd
.arrow
));
365 GrafPtr
UMAGetWindowPort( WindowRef inWindowRef
)
367 wxASSERT( inWindowRef
!= NULL
) ;
369 return GetWindowPort( inWindowRef
) ;
371 return (GrafPtr
) inWindowRef
;
375 void UMADisposeWindow( WindowRef inWindowRef
)
377 wxASSERT( inWindowRef
!= NULL
) ;
378 DisposeWindow( inWindowRef
) ;
381 void UMASetWTitleC( WindowRef inWindowRef
, const char *title
)
384 strncpy( (char*)ptitle
, title
, 96 ) ;
387 c2pstrcpy( ptitle
, (char *)ptitle
) ;
389 c2pstr( (char*)ptitle
) ;
391 SetWTitle( inWindowRef
, ptitle
) ;
394 void UMAGetWTitleC( WindowRef inWindowRef
, char *title
)
396 GetWTitle( inWindowRef
, (unsigned char*)title
) ;
398 p2cstrcpy( title
, (unsigned char *)title
) ;
400 p2cstr( (unsigned char*)title
) ;
404 // appearance additions
406 void UMAActivateControl( ControlHandle inControl
)
408 // we have to add the control after again to the update rgn
409 // otherwise updates get lost
410 if ( !IsControlActive( inControl
) )
412 bool visible
= IsControlVisible( inControl
) ;
414 SetControlVisibility( inControl
, false , false ) ;
415 ::ActivateControl( inControl
) ;
417 SetControlVisibility( inControl
, true , false ) ;
419 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
424 void UMADrawControl( ControlHandle inControl
)
426 WindowRef theWindow
= GetControlOwner(inControl
) ;
427 RgnHandle updateRgn
= NewRgn() ;
428 GetWindowUpdateRgn( theWindow
, updateRgn
) ;
429 Point zero
= { 0 , 0 } ;
430 LocalToGlobal( &zero
) ;
431 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
432 ::DrawControlInCurrentPort( inControl
) ;
433 InvalWindowRgn( theWindow
, updateRgn
) ;
434 DisposeRgn( updateRgn
) ;
437 void UMAMoveControl( ControlHandle inControl
, short x
, short y
)
439 bool visible
= IsControlVisible( inControl
) ;
441 SetControlVisibility( inControl
, false , false ) ;
443 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
445 ::MoveControl( inControl
, x
, y
) ;
447 SetControlVisibility( inControl
, true , false ) ;
449 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
453 void UMASizeControl( ControlHandle inControl
, short x
, short y
)
455 bool visible
= IsControlVisible( inControl
) ;
457 SetControlVisibility( inControl
, false , false ) ;
459 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
461 ::SizeControl( inControl
, x
, y
) ;
463 SetControlVisibility( inControl
, true , false ) ;
465 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
469 void UMADeactivateControl( ControlHandle inControl
)
471 // we have to add the control after again to the update rgn
472 // otherwise updates get lost
473 bool visible
= IsControlVisible( inControl
) ;
475 SetControlVisibility( inControl
, false , false ) ;
476 ::DeactivateControl( inControl
) ;
478 SetControlVisibility( inControl
, true , false ) ;
480 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
483 // shows the control and adds the region to the update region
484 void UMAShowControl (ControlHandle inControl
)
486 SetControlVisibility( inControl
, true , false ) ;
488 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
491 // shows the control and adds the region to the update region
492 void UMAHideControl (ControlHandle inControl
)
494 SetControlVisibility( inControl
, false , false ) ;
496 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
499 OSErr
UMASetKeyboardFocus (WindowPtr inWindow
,
500 ControlHandle inControl
,
501 ControlFocusPart inPart
)
507 SetPortWindowPort( inWindow
) ;
509 err
= SetKeyboardFocus( inWindow
, inControl
, inPart
) ;
518 void UMAUpdateControls( WindowPtr inWindow
, RgnHandle inRgn
)
520 RgnHandle updateRgn
= NewRgn() ;
521 GetWindowUpdateRgn( inWindow
, updateRgn
) ;
523 Point zero
= { 0 , 0 } ;
524 LocalToGlobal( &zero
) ;
525 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
527 UpdateControls( inWindow
, inRgn
) ;
528 InvalWindowRgn( inWindow
, updateRgn
) ;
529 DisposeRgn( updateRgn
) ;
533 bool UMAIsWindowFloating( WindowRef inWindow
)
537 GetWindowClass( inWindow
, &cl
) ;
538 return cl
== kFloatingWindowClass
;
541 bool UMAIsWindowModal( WindowRef inWindow
)
545 GetWindowClass( inWindow
, &cl
) ;
546 return cl
< kFloatingWindowClass
;
551 void UMAHighlightAndActivateWindow( WindowRef inWindowRef
, bool inActivate
)
555 // bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
556 // if ( inActivate != isHightlited )
559 SetPortWindowPort( inWindowRef
) ;
560 HiliteWindow( inWindowRef
, inActivate
) ;
561 ControlHandle control
= NULL
;
562 ::GetRootControl( inWindowRef
, & control
) ;
566 UMAActivateControl( control
) ;
568 UMADeactivateControl( control
) ;
573 OSStatus
UMADrawThemePlacard( const Rect
*inRect
, ThemeDrawState inState
)
575 return ::DrawThemePlacard( inRect
, inState
) ;
578 static OSStatus helpMenuStatus
= noErr
;
579 static MenuRef helpMenuHandle
= NULL
;
580 static MenuItemIndex firstCustomItemIndex
= 0 ;
582 OSStatus
UMAGetHelpMenu(
583 MenuRef
* outHelpMenu
,
584 MenuItemIndex
* outFirstCustomItemIndex
)
587 return HMGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
) ;
589 if ( helpMenuHandle
== NULL
)
591 helpMenuStatus
= HMGetHelpMenuHandle( &helpMenuHandle
) ;
592 if ( helpMenuStatus
== noErr
)
594 firstCustomItemIndex
= CountMenuItems( helpMenuHandle
) + 1 ;
597 if ( outFirstCustomItemIndex
)
599 *outFirstCustomItemIndex
= firstCustomItemIndex
;
601 *outHelpMenu
= helpMenuHandle
;
602 return helpMenuStatus
;