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 // we have to add the control after again to the update rgn
400 // otherwise updates get lost
401 if ( !IsControlActive( inControl
) )
403 bool visible
= IsControlVisible( inControl
) ;
405 SetControlVisibility( inControl
, false , false ) ;
406 ::ActivateControl( inControl
) ;
408 SetControlVisibility( inControl
, true , false ) ;
410 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
415 void UMADrawControl( ControlHandle inControl
)
417 WindowRef theWindow
= GetControlOwner(inControl
) ;
418 RgnHandle updateRgn
= NewRgn() ;
419 GetWindowUpdateRgn( theWindow
, updateRgn
) ;
420 Point zero
= { 0 , 0 } ;
421 LocalToGlobal( &zero
) ;
422 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
423 ::DrawControlInCurrentPort( inControl
) ;
424 InvalWindowRgn( theWindow
, updateRgn
) ;
425 DisposeRgn( updateRgn
) ;
428 void UMAMoveControl( ControlHandle inControl
, short x
, short y
)
430 bool visible
= IsControlVisible( inControl
) ;
432 SetControlVisibility( inControl
, false , false ) ;
434 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
436 ::MoveControl( inControl
, x
, y
) ;
438 SetControlVisibility( inControl
, true , false ) ;
440 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
444 void UMASizeControl( ControlHandle inControl
, short x
, short y
)
446 bool visible
= IsControlVisible( inControl
) ;
448 SetControlVisibility( inControl
, false , false ) ;
450 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
452 ::SizeControl( inControl
, x
, y
) ;
454 SetControlVisibility( inControl
, true , false ) ;
456 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
460 void UMADeactivateControl( ControlHandle inControl
)
462 // we have to add the control after again to the update rgn
463 // otherwise updates get lost
464 bool visible
= IsControlVisible( inControl
) ;
466 SetControlVisibility( inControl
, false , false ) ;
467 ::DeactivateControl( inControl
) ;
469 SetControlVisibility( inControl
, true , false ) ;
471 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
) ) ;
482 // shows the control and adds the region to the update region
483 void UMAHideControl (ControlHandle inControl
)
485 SetControlVisibility( inControl
, false , false ) ;
487 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
490 OSErr
UMASetKeyboardFocus (WindowPtr inWindow
,
491 ControlHandle inControl
,
492 ControlFocusPart inPart
)
498 SetPortWindowPort( inWindow
) ;
501 err
= SetKeyboardFocus( inWindow
, inControl
, inPart
) ;
510 void UMAUpdateControls( WindowPtr inWindow
, RgnHandle inRgn
)
512 RgnHandle updateRgn
= NewRgn() ;
513 GetWindowUpdateRgn( inWindow
, updateRgn
) ;
515 Point zero
= { 0 , 0 } ;
516 LocalToGlobal( &zero
) ;
517 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
519 UpdateControls( inWindow
, inRgn
) ;
520 InvalWindowRgn( inWindow
, updateRgn
) ;
521 DisposeRgn( updateRgn
) ;
525 bool UMAIsWindowFloating( WindowRef inWindow
)
529 GetWindowClass( inWindow
, &cl
) ;
530 return cl
== kFloatingWindowClass
;
533 bool UMAIsWindowModal( WindowRef inWindow
)
537 GetWindowClass( inWindow
, &cl
) ;
538 return cl
< kFloatingWindowClass
;
543 void UMAHighlightAndActivateWindow( WindowRef inWindowRef
, bool inActivate
)
547 // bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
548 // if ( inActivate != isHightlited )
551 SetPortWindowPort( inWindowRef
) ;
553 HiliteWindow( inWindowRef
, inActivate
) ;
554 ControlHandle control
= NULL
;
555 ::GetRootControl( inWindowRef
, & control
) ;
559 UMAActivateControl( control
) ;
561 UMADeactivateControl( control
) ;
566 OSStatus
UMADrawThemePlacard( const Rect
*inRect
, ThemeDrawState inState
)
568 return ::DrawThemePlacard( inRect
, inState
) ;
571 static OSStatus helpMenuStatus
= noErr
;
572 static MenuRef helpMenuHandle
= NULL
;
573 static MenuItemIndex firstCustomItemIndex
= 0 ;
575 OSStatus
UMAGetHelpMenu(
576 MenuRef
* outHelpMenu
,
577 MenuItemIndex
* outFirstCustomItemIndex
)
580 return HMGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
) ;
582 if ( helpMenuHandle
== NULL
)
584 helpMenuStatus
= HMGetHelpMenuHandle( &helpMenuHandle
) ;
585 if ( helpMenuStatus
== noErr
)
587 firstCustomItemIndex
= CountMenuItems( helpMenuHandle
) + 1 ;
590 if ( outFirstCustomItemIndex
)
592 *outFirstCustomItemIndex
= firstCustomItemIndex
;
594 *outHelpMenu
= helpMenuHandle
;
595 return helpMenuStatus
;