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
18 static bool sUMAHasAppearance
= false ;
19 static long sUMAAppearanceVersion
= 0 ;
20 extern int gAGABackgroundColor
;
21 bool UMAHasAppearance() { return sUMAHasAppearance
; }
22 long UMAGetAppearanceVersion() { return sUMAAppearanceVersion
; }
24 static bool sUMAHasWindowManager
= false ;
25 static long sUMAWindowManagerAttr
= 0 ;
27 bool UMAHasWindowManager() { return sUMAHasWindowManager
; }
28 long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr
; }
30 void UMACleanupToolbox()
32 if ( sUMAHasAppearance
)
34 UnregisterAppearanceClient() ;
36 if ( NavServicesAvailable() )
41 TXNTerminateTextension( ) ;
44 void UMAInitToolbox( UInt16 inMoreMastersCalls
)
48 for (long i
= 1; i
<= inMoreMastersCalls
; i
++)
51 ::InitGraf(&qd
.thePort
);
56 ::FlushEvents(everyEvent
, 0);
59 PurgeSpace(&total
, &contig
);
65 if ( Gestalt( gestaltAppearanceAttr
, &theAppearance
) == noErr
)
67 sUMAHasAppearance
= true ;
68 RegisterAppearanceClient();
69 if ( Gestalt( gestaltAppearanceVersion
, &theAppearance
) == noErr
)
71 sUMAAppearanceVersion
= theAppearance
;
75 sUMAAppearanceVersion
= 0x0100 ;
78 if ( Gestalt( gestaltWindowMgrAttr
, &sUMAWindowManagerAttr
) == noErr
)
80 sUMAHasWindowManager
= sUMAWindowManagerAttr
& gestaltWindowMgrPresent
;
85 // Call currently implicitely done : InitFloatingWindows() ;
87 if ( sUMAHasWindowManager
)
88 InitFloatingWindows() ;
94 if ( NavServicesAvailable() )
100 TXNMacOSPreferredFontDescription defaults
;
101 defaults
.fontID
= kFontIDGeneva
;
102 defaults
.pointSize
= (10 << 16) ;
103 defaults
.fontStyle
= kTXNDefaultFontStyle
;
104 defaults
.encoding
= kTXNSystemDefaultEncoding
;
105 TXNInitTextension(&defaults
, 1, (kTXNAlwaysUseQuickDrawTextMask
| kTXNWantMoviesMask
| kTXNWantSoundMask
| kTXNWantGraphicsMask
));
110 long UMAGetProcessMode()
113 ProcessInfoRec processinfo
;
114 ProcessSerialNumber procno
;
116 procno
.highLongOfPSN
= NULL
;
117 procno
.lowLongOfPSN
= kCurrentProcess
;
118 processinfo
.processInfoLength
= sizeof(ProcessInfoRec
);
119 processinfo
.processName
= NULL
;
120 processinfo
.processAppSpec
= NULL
;
122 err
= ::GetProcessInformation( &procno
, &processinfo
) ;
123 wxASSERT( err
== noErr
) ;
124 return processinfo
.processMode
;
127 bool UMAGetProcessModeDoesActivateOnFGSwitch()
129 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch
;
134 void UMASetMenuTitle( MenuRef menu
, StringPtr title
)
137 long size
= GetHandleSize( (Handle
) menu
) ;
138 const long headersize
= 14 ;
139 int oldlen
= (**menu
).menuData
[0] + 1;
140 int newlen
= title
[0] + 1 ;
142 if ( oldlen
< newlen
)
144 // enlarge before adjusting
145 SetHandleSize( (Handle
) menu
, size
+ (newlen
- oldlen
) );
148 if ( oldlen
!= newlen
)
149 memmove( (char*) (**menu
).menuData
+ newlen
, (char*) (**menu
).menuData
+ oldlen
, size
- headersize
- oldlen
) ;
151 memcpy( (char*) (**menu
).menuData
, title
, newlen
) ;
152 if ( oldlen
> newlen
)
155 SetHandleSize( (Handle
) menu
, size
+ (newlen
- oldlen
) ) ;
158 SetMenuTitle( menu
, title
) ;
162 UInt32
UMAMenuEvent( EventRecord
*inEvent
)
164 return MenuEvent( inEvent
) ;
167 void UMAEnableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
169 EnableMenuItem( inMenu
, inItem
) ;
172 void UMADisableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
174 DisableMenuItem( inMenu
, inItem
) ;
177 void UMAAppendSubMenuItem( MenuRef menu
, StringPtr l
, SInt16 id
)
180 memcpy( label
, l
, l
[0]+1 ) ;
181 // hardcoded adding of the submenu combination for mac
183 int theEnd
= label
[0] + 1;
185 theEnd
= 251; // mac allows only 255 characters
186 label
[theEnd
++] = '/';
187 label
[theEnd
++] = hMenuCmd
;
188 label
[theEnd
++] = '!';
189 label
[theEnd
++] = id
;
190 label
[theEnd
] = 0x00;
192 MacAppendMenu(menu
, label
);
195 void UMAInsertSubMenuItem( MenuRef menu
, StringPtr l
, MenuItemIndex item
, SInt16 id
)
198 memcpy( label
, l
, l
[0]+1 ) ;
199 // hardcoded adding of the submenu combination for mac
201 int theEnd
= label
[0] + 1;
203 theEnd
= 251; // mac allows only 255 characters
204 label
[theEnd
++] = '/';
205 label
[theEnd
++] = hMenuCmd
;
206 label
[theEnd
++] = '!';
207 label
[theEnd
++] = id
;
208 label
[theEnd
] = 0x00;
210 MacInsertMenuItem(menu
, label
, item
);
213 void UMAAppendMenuItem( MenuRef menu
, StringPtr l
, SInt16 key
, UInt8 modifiers
)
216 memcpy( label
, l
, l
[0]+1 ) ;
221 label
[++pos
] = toupper( key
);
224 MacAppendMenu( menu
, label
) ;
227 void UMAInsertMenuItem( MenuRef menu
, StringPtr l
, MenuItemIndex item
, SInt16 key
, UInt8 modifiers
)
230 memcpy( label
, l
, l
[0]+1 ) ;
235 label
[++pos
] = toupper( key
);
238 MacInsertMenuItem( menu
, label
, item
) ;
243 int gPrOpenCounter
= 0 ;
245 #if TARGET_CARBON && PM_USE_SESSION_APIS
246 OSStatus
UMAPrOpen(PMPrintSession
*macPrintSession
)
254 if ( gPrOpenCounter
== 1 )
258 wxASSERT( err
== noErr
) ;
262 OSStatus err
= noErr
;
264 if ( gPrOpenCounter
== 1 )
266 #if PM_USE_SESSION_APIS
267 err
= PMCreateSession(macPrintSession
) ;
271 wxASSERT( err
== noErr
) ;
277 #if TARGET_CARBON && PM_USE_SESSION_APIS
278 OSStatus
UMAPrClose(PMPrintSession
*macPrintSession
)
280 OSStatus
UMAPrClose()
285 wxASSERT( gPrOpenCounter
>= 1 ) ;
286 if ( gPrOpenCounter
== 1 )
290 wxASSERT( err
== noErr
) ;
295 OSStatus err
= noErr
;
296 wxASSERT( gPrOpenCounter
>= 1 ) ;
297 if ( gPrOpenCounter
== 1 )
299 #if PM_USE_SESSION_APIS
300 err
= PMRelease(*macPrintSession
) ;
301 *macPrintSession
= kPMNoReference
;
313 pascal QDGlobalsPtr
GetQDGlobalsPtr (void) ;
314 pascal QDGlobalsPtr
GetQDGlobalsPtr (void)
316 return QDGlobalsPtr (* (Ptr
*) LMGetCurrentA5 ( ) - 0xCA);
321 void UMAShowWatchCursor()
325 CursHandle watchFob
= GetCursor (watchCursor
);
332 // Cursor preservedArrow;
333 // GetQDGlobalsArrow (&preservedArrow);
334 // SetQDGlobalsArrow (*watchFob);
336 // SetQDGlobalsArrow (&preservedArrow);
337 SetCursor (*watchFob
);
339 SetCursor (*watchFob
);
344 void UMAShowArrowCursor()
348 SetCursor (GetQDGlobalsArrow (&arrow
));
350 SetCursor (&(qd
.arrow
));
356 GrafPtr
UMAGetWindowPort( WindowRef inWindowRef
)
358 wxASSERT( inWindowRef
!= NULL
) ;
360 return GetWindowPort( inWindowRef
) ;
362 return (GrafPtr
) inWindowRef
;
366 void UMADisposeWindow( WindowRef inWindowRef
)
368 wxASSERT( inWindowRef
!= NULL
) ;
369 DisposeWindow( inWindowRef
) ;
372 void UMASetWTitleC( WindowRef inWindowRef
, const char *title
)
375 strncpy( (char*)ptitle
, title
, 96 ) ;
378 c2pstrcpy( ptitle
, (char *)ptitle
) ;
380 c2pstr( (char*)ptitle
) ;
382 SetWTitle( inWindowRef
, ptitle
) ;
385 void UMAGetWTitleC( WindowRef inWindowRef
, char *title
)
387 GetWTitle( inWindowRef
, (unsigned char*)title
) ;
389 p2cstrcpy( title
, (unsigned char *)title
) ;
391 p2cstr( (unsigned char*)title
) ;
395 // appearance additions
397 void UMAActivateControl( ControlHandle inControl
)
399 if ( !IsControlActive( inControl
) )
401 bool visible
= IsControlVisible( inControl
) ;
403 SetControlVisibility( inControl
, false , false ) ;
404 ::ActivateControl( inControl
) ;
406 SetControlVisibility( inControl
, true , false ) ;
408 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
413 void UMADrawControl( ControlHandle inControl
)
415 WindowRef theWindow
= GetControlOwner(inControl
) ;
416 RgnHandle updateRgn
= NewRgn() ;
417 GetWindowUpdateRgn( theWindow
, updateRgn
) ;
418 Point zero
= { 0 , 0 } ;
419 LocalToGlobal( &zero
) ;
420 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
421 ::DrawControlInCurrentPort( inControl
) ;
422 InvalWindowRgn( theWindow
, updateRgn
) ;
423 DisposeRgn( updateRgn
) ;
427 void UMAMoveControl( ControlHandle inControl
, short x
, short y
)
429 bool visible
= IsControlVisible( inControl
) ;
431 SetControlVisibility( inControl
, false , false ) ;
433 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
435 ::MoveControl( inControl
, x
, y
) ;
437 SetControlVisibility( inControl
, true , false ) ;
439 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
443 void UMASizeControl( ControlHandle inControl
, short x
, short y
)
445 bool visible
= IsControlVisible( inControl
) ;
447 SetControlVisibility( inControl
, false , false ) ;
449 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
451 ::SizeControl( inControl
, x
, y
) ;
453 SetControlVisibility( inControl
, true , false ) ;
455 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
459 void UMADeactivateControl( ControlHandle inControl
)
461 if ( IsControlActive( inControl
) )
463 bool visible
= IsControlVisible( inControl
) ;
465 SetControlVisibility( inControl
, false , false ) ;
466 ::DeactivateControl( inControl
) ;
468 SetControlVisibility( inControl
, true , false ) ;
470 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
474 // shows the control and adds the region to the update region
475 void UMAShowControl (ControlHandle inControl
)
477 SetControlVisibility( inControl
, true , false ) ;
479 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
483 OSErr
UMASetKeyboardFocus (WindowPtr inWindow
,
484 ControlHandle inControl
,
485 ControlFocusPart inPart
)
491 SetPortWindowPort( inWindow
) ;
494 err
= SetKeyboardFocus( inWindow
, inControl
, inPart
) ;
503 void UMAUpdateControls( WindowPtr inWindow
, RgnHandle inRgn
)
505 RgnHandle updateRgn
= NewRgn() ;
506 GetWindowUpdateRgn( inWindow
, updateRgn
) ;
508 Point zero
= { 0 , 0 } ;
509 LocalToGlobal( &zero
) ;
510 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
512 UpdateControls( inWindow
, inRgn
) ;
513 InvalWindowRgn( inWindow
, updateRgn
) ;
514 DisposeRgn( updateRgn
) ;
518 bool UMAIsWindowFloating( WindowRef inWindow
)
522 GetWindowClass( inWindow
, &cl
) ;
523 return cl
== kFloatingWindowClass
;
526 bool UMAIsWindowModal( WindowRef inWindow
)
530 GetWindowClass( inWindow
, &cl
) ;
531 return cl
< kFloatingWindowClass
;
536 void UMAHighlightAndActivateWindow( WindowRef inWindowRef
, bool inActivate
)
540 // bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
541 // if ( inActivate != isHightlited )
544 SetPortWindowPort( inWindowRef
) ;
546 HiliteWindow( inWindowRef
, inActivate
) ;
547 ControlHandle control
= NULL
;
548 ::GetRootControl( inWindowRef
, & control
) ;
552 UMAActivateControl( control
) ;
554 UMADeactivateControl( control
) ;
559 OSStatus
UMADrawThemePlacard( const Rect
*inRect
, ThemeDrawState inState
)
561 return ::DrawThemePlacard( inRect
, inState
) ;
564 static OSStatus helpMenuStatus
= noErr
;
565 static MenuRef helpMenuHandle
= NULL
;
566 static MenuItemIndex firstCustomItemIndex
= 0 ;
568 OSStatus
UMAGetHelpMenu(
569 MenuRef
* outHelpMenu
,
570 MenuItemIndex
* outFirstCustomItemIndex
)
573 return HMGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
) ;
575 if ( helpMenuHandle
== NULL
)
577 helpMenuStatus
= HMGetHelpMenuHandle( &helpMenuHandle
) ;
578 if ( helpMenuStatus
== noErr
)
580 firstCustomItemIndex
= CountMenuItems( helpMenuHandle
) + 1 ;
583 if ( outFirstCustomItemIndex
)
585 *outFirstCustomItemIndex
= firstCustomItemIndex
;
587 *outHelpMenu
= helpMenuHandle
;
588 return helpMenuStatus
;