1 #include <wx/mac/uma.h>
2 #include <wx/mac/aga.h>
6 static bool sUMAHasAppearance
= false ;
7 static long sUMAAppearanceVersion
= 0 ;
8 extern int gAGABackgroundColor
;
9 bool UMAHasAppearance() { return sUMAHasAppearance
; }
10 long UMAGetAppearanceVersion() { return sUMAAppearanceVersion
; }
12 static bool sUMAHasWindowManager
= false ;
13 static long sUMAWindowManagerAttr
= 0 ;
15 bool UMAHasWindowManager() { return sUMAHasWindowManager
; }
16 long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr
; }
18 void UMAInitToolbox( UInt16 inMoreMastersCalls
)
22 for (long i
= 1; i
<= inMoreMastersCalls
; i
++)
25 ::InitGraf(&qd
.thePort
);
31 ::FlushEvents(everyEvent
, 0);
34 PurgeSpace(&total
, &contig
);
39 #if UMA_USE_APPEARANCE
41 if ( Gestalt( gestaltAppearanceAttr
, &theAppearance
) == noErr
)
43 sUMAHasAppearance
= true ;
44 RegisterAppearanceClient();
45 if ( Gestalt( gestaltAppearanceVersion
, &theAppearance
) == noErr
)
47 sUMAAppearanceVersion
= theAppearance
;
51 sUMAAppearanceVersion
= 0x0100 ;
54 #endif // UMA_USE_APPEARANCE
57 if ( Gestalt( gestaltWindowMgrAttr
, &sUMAWindowManagerAttr
) == noErr
)
59 sUMAHasWindowManager
= sUMAWindowManagerAttr
& gestaltWindowMgrPresent
;
61 #endif // UMA_USE_WINDOWMGR
66 long UMAGetProcessMode()
69 ProcessInfoRec processinfo
;
70 ProcessSerialNumber procno
;
72 procno
.highLongOfPSN
= NULL
;
73 procno
.lowLongOfPSN
= kCurrentProcess
;
74 processinfo
.processInfoLength
= sizeof(ProcessInfoRec
);
75 processinfo
.processName
= NULL
;
76 processinfo
.processAppSpec
= NULL
;
78 err
= ::GetProcessInformation( &procno
, &processinfo
) ;
79 wxASSERT( err
== noErr
) ;
80 return processinfo
.processMode
;
83 bool UMAGetProcessModeDoesActivateOnFGSwitch()
85 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch
;
90 void UMASetMenuTitle( MenuRef menu
, ConstStr255Param title
)
93 long size
= GetHandleSize( (Handle
) menu
) ;
94 const long headersize
= 14 ;
95 int oldlen
= (**menu
).menuData
[0] + 1;
96 int newlen
= title
[0] + 1 ;
98 if ( oldlen
< newlen
)
100 // enlarge before adjusting
101 SetHandleSize( (Handle
) menu
, size
+ (newlen
- oldlen
) );
104 if ( oldlen
!= newlen
)
105 memmove( (char*) (**menu
).menuData
+ newlen
, (char*) (**menu
).menuData
+ oldlen
, size
- headersize
- oldlen
) ;
107 memcpy( (char*) (**menu
).menuData
, title
, newlen
) ;
108 if ( oldlen
> newlen
)
111 SetHandleSize( (Handle
) menu
, size
+ (newlen
- oldlen
) ) ;
114 SetMenuTitle( menu
, title
) ;
118 UInt32
UMAMenuEvent( EventRecord
*inEvent
)
120 if ( UMAHasAppearance() )
122 return MenuEvent( inEvent
) ;
126 if ( inEvent
->what
== keyDown
&& inEvent
->modifiers
& cmdKey
)
128 return MenuKey( inEvent
->message
& charCodeMask
) ;
134 void UMAEnableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
137 EnableMenuItem( inMenu
, inItem
) ;
139 EnableItem( inMenu
, inItem
) ;
143 void UMADisableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
146 DisableMenuItem( inMenu
, inItem
) ;
148 DisableItem( inMenu
, inItem
) ;
155 pascal QDGlobalsPtr
GetQDGlobalsPtr (void)
157 return QDGlobalsPtr (* (Ptr
*) LMGetCurrentA5 ( ) - 0xCA);
162 void UMAShowWatchCursor()
166 CursHandle watchFob
= GetCursor (watchCursor
);
173 Cursor preservedArrow
;
174 GetQDGlobalsArrow (&preservedArrow
);
175 SetQDGlobalsArrow (*watchFob
);
177 SetQDGlobalsArrow (&preservedArrow
);
179 SetCursor (*watchFob
);
184 void UMAShowArrowCursor()
188 SetCursor (GetQDGlobalsArrow (&arrow
));
190 SetCursor (&(qd
.arrow
));
196 GrafPtr
UMAGetWindowPort( WindowRef inWindowRef
)
198 wxASSERT( inWindowRef
!= NULL
) ;
200 return GetWindowPort( inWindowRef
) ;
202 return (GrafPtr
) inWindowRef
;
206 void UMADisposeWindow( WindowRef inWindowRef
)
208 wxASSERT( inWindowRef
!= NULL
) ;
209 DisposeWindow( inWindowRef
) ;
212 void UMASetWTitleC( WindowRef inWindowRef
, const char *title
)
215 strncpy( (char*)ptitle
, title
, 96 ) ;
217 c2pstr( (char*)ptitle
) ;
218 SetWTitle( inWindowRef
, ptitle
) ;
220 void UMAGetWTitleC( WindowRef inWindowRef
, char *title
)
222 GetWTitle( inWindowRef
, (unsigned char*)title
) ;
223 p2cstr( (unsigned char*)title
) ;
226 void UMAShowWindow( WindowRef inWindowRef
)
228 ShowWindow( inWindowRef
) ;
231 void UMAHideWindow( WindowRef inWindowRef
)
233 HideWindow( inWindowRef
) ;
236 void UMASelectWindow( WindowRef inWindowRef
)
238 SelectWindow( inWindowRef
) ;
241 void UMABringToFront( WindowRef inWindowRef
)
243 BringToFront( inWindowRef
) ;
246 void UMASendBehind( WindowRef inWindowRef
, WindowRef behindWindow
)
248 SendBehind( inWindowRef
, behindWindow
) ;
251 void UMACloseWindow(WindowRef inWindowRef
)
255 CloseWindow( inWindowRef
) ;
259 // appearance additions
261 void UMAActivateControl( ControlHandle inControl
)
263 if ( UMAHasAppearance() )
265 ::ActivateControl( inControl
) ;
269 AGAActivateControl( inControl
) ;
273 void UMADrawControl( ControlHandle inControl
)
275 if ( UMAHasAppearance() )
277 ::DrawControlInCurrentPort( inControl
) ;
281 AGADrawControl( inControl
) ;
285 void UMAMoveControl( ControlHandle inControl
, short x
, short y
)
287 if ( UMAHasAppearance() )
289 ::MoveControl( inControl
, x
, y
) ;
293 AGAMoveControl( inControl
, x
,y
) ;
297 void UMASizeControl( ControlHandle inControl
, short x
, short y
)
299 if ( UMAHasAppearance() )
301 ::SizeControl( inControl
, x
, y
) ;
305 AGASizeControl( inControl
, x
,y
) ;
309 void UMADeactivateControl( ControlHandle inControl
)
311 if ( UMAHasAppearance() )
313 ::DeactivateControl( inControl
) ;
317 AGADeactivateControl( inControl
) ;
321 void UMASetThemeWindowBackground (WindowRef inWindow
,
324 if ( UMAHasAppearance() )
326 ::SetThemeWindowBackground( inWindow
,inBrush
, inUpdate
) ;
330 AGASetThemeWindowBackground( inWindow
, inBrush
, inUpdate
) ;
335 ControlHandle
UMANewControl(WindowPtr owningWindow
,
336 const Rect
* boundsRect
,
337 ConstStr255Param controlTitle
,
338 Boolean initiallyVisible
,
343 SInt32 controlReference
)
345 ControlHandle theControl
= NULL
;
346 if ( UMAHasAppearance() )
348 theControl
= NewControl( owningWindow
, boundsRect
, controlTitle
, initiallyVisible
,
349 initialValue
, minimumValue
, maximumValue
, procID
, controlReference
) ;
353 theControl
= AGANewControl( owningWindow
, boundsRect
, controlTitle
, initiallyVisible
,
354 initialValue
, minimumValue
, maximumValue
, procID
, controlReference
) ;
359 void UMADisposeControl (ControlHandle theControl
)
361 if ( UMAHasAppearance() )
363 ::DisposeControl( theControl
) ;
367 ::DisposeControl( theControl
) ;
372 void UMAHiliteControl (ControlHandle theControl
,
373 ControlPartCode hiliteState
)
375 if ( UMAHasAppearance() )
377 ::HiliteControl( theControl
, hiliteState
) ;
381 ::HiliteControl( theControl
, hiliteState
) ;
386 void UMAShowControl (ControlHandle theControl
)
388 if ( UMAHasAppearance() )
390 ::ShowControl( theControl
) ;
394 ::ShowControl( theControl
) ;
399 void UMAHideControl (ControlHandle theControl
)
401 if ( UMAHasAppearance() )
403 ::HideControl( theControl
) ;
407 ::HideControl( theControl
) ;
412 void UMASetControlVisibility (ControlHandle inControl
,
416 if ( UMAHasAppearance() )
418 ::SetControlVisibility( inControl
, inIsVisible
, inDoDraw
) ;
424 bool UMAIsControlActive (ControlHandle inControl
)
426 if ( UMAHasAppearance() )
428 return IsControlActive( inControl
) ;
431 return (**inControl
).contrlHilite
== 0 ;
435 bool UMAIsControlVisible (ControlHandle inControl
)
437 if ( UMAHasAppearance() )
439 return IsControlVisible( inControl
) ;
444 OSErr
UMAGetBestControlRect (ControlHandle inControl
,
446 SInt16
* outBaseLineOffset
)
448 if ( UMAHasAppearance() )
450 return GetBestControlRect( inControl
, outRect
, outBaseLineOffset
) ;
454 return AGAGetBestControlRect( inControl
, outRect
, outBaseLineOffset
) ;
459 OSErr
UMASetControlFontStyle (ControlHandle inControl
,
460 const ControlFontStyleRec
* inStyle
)
462 if ( UMAHasAppearance() )
464 return ::SetControlFontStyle( inControl
, inStyle
) ;
467 return AGASetControlFontStyle( inControl
, inStyle
) ;
474 OSErr
UMACreateRootControl (WindowPtr inWindow
,
475 ControlHandle
* outControl
)
477 if ( UMAHasAppearance() )
479 return CreateRootControl( inWindow
, outControl
) ;
482 return AGACreateRootControl( inWindow
, outControl
) ;
487 OSErr
UMAEmbedControl (ControlHandle inControl
,
488 ControlHandle inContainer
)
490 if ( UMAHasAppearance() )
492 return EmbedControl( inControl
, inContainer
) ;
495 return AGAEmbedControl( inControl
, inContainer
) ; ;
501 OSErr
UMASetKeyboardFocus (WindowPtr inWindow
,
502 ControlHandle inControl
,
503 ControlFocusPart inPart
)
505 if ( UMAHasAppearance() )
507 return SetKeyboardFocus( inWindow
, inControl
, inPart
) ;
510 return AGASetKeyboardFocus( inWindow
, inControl
, inPart
) ;
518 ControlPartCode
UMAHandleControlClick (ControlHandle inControl
,
521 ControlActionUPP inAction
)
523 if ( UMAHasAppearance() )
525 return HandleControlClick( inControl
, inWhere
, inModifiers
, inAction
) ;
529 return AGAHandleControlClick( inControl
, inWhere
, inModifiers
, inAction
) ;
534 SInt16
UMAHandleControlKey (ControlHandle inControl
,
539 if ( UMAHasAppearance() )
541 return HandleControlKey( inControl
, inKeyCode
, inCharCode
, inModifiers
) ;
545 return AGAHandleControlKey(inControl
, inKeyCode
, inCharCode
, inModifiers
) ;
551 void UMAIdleControls (WindowPtr inWindow
)
553 if ( UMAHasAppearance() )
555 IdleControls( inWindow
) ;
559 AGAIdleControls( inWindow
) ;
563 void UMAUpdateControls( WindowPtr inWindow
, RgnHandle inRgn
)
565 if ( UMAHasAppearance() )
567 UpdateControls( inWindow
, inRgn
) ;
571 AGAUpdateControls( inWindow
, inRgn
) ;
575 OSErr
UMAGetRootControl( WindowPtr inWindow
, ControlHandle
*outControl
)
577 if ( UMAHasAppearance() )
579 return GetRootControl( inWindow
, outControl
) ;
583 return AGAGetRootControl( inWindow
, outControl
) ;
588 // handling control data
590 OSErr
UMASetControlData (ControlHandle inControl
,
591 ControlPartCode inPart
,
596 if ( UMAHasAppearance() )
598 return SetControlData( inControl
, inPart
, inTagName
, inSize
, inData
) ;
601 return AGASetControlData( inControl
, inPart
, inTagName
, inSize
, inData
) ;
606 OSErr
UMAGetControlData (ControlHandle inControl
,
607 ControlPartCode inPart
,
611 Size
* outActualSize
)
613 if ( UMAHasAppearance() )
615 return ::GetControlData( inControl
, inPart
, inTagName
, inBufferSize
, outBuffer
, outActualSize
) ;
619 return AGAGetControlData( inControl
, inPart
, inTagName
, inBufferSize
, outBuffer
, outActualSize
) ;
625 OSErr
UMAGetControlDataSize (ControlHandle inControl
,
626 ControlPartCode inPart
,
630 if ( UMAHasAppearance() )
632 return GetControlDataSize( inControl
, inPart
, inTagName
, outMaxSize
) ;
636 return AGAGetControlDataSize( inControl
, inPart
, inTagName
, outMaxSize
) ;
644 // system 8.0 changes
646 short UMAFindWindow( Point inPoint
, WindowRef
*outWindow
)
648 // todo add the additional area codes
649 return FindWindow( inPoint
, outWindow
) ;
652 OSStatus
UMAGetWindowFeatures( WindowRef inWindowRef
, UInt32
*outFeatures
)
654 #if UMA_USE_WINDOWMGR
655 return GetWindowFeatures( inWindowRef
, outFeatures
) ;
661 OSStatus
UMAGetWindowRegion( WindowRef inWindowRef
, WindowRegionCode inRegionCode
, RgnHandle ioWinRgn
)
663 #if UMA_USE_WINDOWMGR
664 return GetWindowRegion( inWindowRef
, inRegionCode
, ioWinRgn
) ;
670 void UMADrawGrowIcon( WindowRef inWindowRef
)
672 DrawGrowIcon( inWindowRef
) ;
675 OSStatus
UMACollapseWindow( WindowRef inWindowRef
, Boolean inCollapseIt
)
677 return CollapseWindow( inWindowRef
, inCollapseIt
) ;
680 OSStatus
UMACollapseAllWindows( Boolean inCollapseEm
)
682 return CollapseAllWindows( inCollapseEm
) ;
685 Boolean
UMAIsWindowCollapsed( WindowRef inWindowRef
)
687 return IsWindowCollapsed( inWindowRef
) ;
690 Boolean
UMAIsWindowCollapsable( WindowRef inWindowRef
)
692 return IsWindowCollapsable( inWindowRef
) ;
695 // system 8.5 changes<MacWindows.h>
696 OSStatus
UMACreateNewWindow( WindowClass windowClass
, WindowAttributes attributes
, const Rect
*bounds
, WindowRef
*outWindow
)
698 #if UMA_USE_WINDOWMGR
699 if ( UMAHasWindowManager() )
701 return CreateNewWindow( windowClass
, attributes
, bounds
, outWindow
) ;
707 if ( UMAHasAppearance() )
709 switch( windowClass
)
711 case kMovableModalWindowClass
:
712 procID
= kWindowMovableModalDialogProc
;
714 case kDocumentWindowClass
:
715 procID
= kWindowFullZoomGrowDocumentProc
;
718 procID
= kWindowMovableModalDialogProc
;
724 switch( windowClass
)
726 case kMovableModalWindowClass
:
727 procID
= movableDBoxProc
;
728 // procID += kMovableModalDialogVariantCode;
730 case kDocumentWindowClass
:
731 procID
= zoomDocProc
;
734 procID
= documentProc
;
738 *outWindow
= NewCWindow(nil
, bounds
, "\p", false, procID
, (WindowRef
) -1 /*behind*/,
739 attributes
& kWindowCloseBoxAttribute
, (long)NULL
);
744 OSStatus
UMAGetWindowClass( WindowRef inWindowRef
, WindowClass
*outWindowClass
)
746 #if UMA_USE_WINDOWMGR
747 if ( UMAHasWindowManager() )
749 return GetWindowClass( inWindowRef
, outWindowClass
) ;
753 return kDocumentWindowClass
;
756 OSStatus
UMAGetWindowAttributes( WindowRef inWindowRef
, WindowAttributes
*outAttributes
)
758 #if UMA_USE_WINDOWMGR
759 if ( UMAHasWindowManager() )
761 return GetWindowAttributes( inWindowRef
, outAttributes
) ;
764 return kWindowNoAttributes
;
767 void UMAShowFloatingWindows()
769 #if UMA_USE_WINDOWMGR
770 if ( UMAHasWindowManager() )
772 ShowFloatingWindows() ;
777 void UMAHideFloatingWindows()
779 #if UMA_USE_WINDOWMGR
780 if ( UMAHasWindowManager() )
782 HideFloatingWindows() ;
787 Boolean
UMAAreFloatingWindowsVisible()
789 #if UMA_USE_WINDOWMGR
790 if ( UMAHasWindowManager() )
792 return AreFloatingWindowsVisible() ;
798 WindowRef
UMAFrontNonFloatingWindow()
800 #if UMA_USE_WINDOWMGR
801 if ( UMAHasWindowManager() )
803 return FrontNonFloatingWindow() ;
808 return FrontWindow() ;
812 WindowRef
UMAFrontWindow()
814 #if UMA_USE_WINDOWMGR
815 if ( UMAHasWindowManager() )
817 return FrontWindow() ;
822 return FrontWindow() ;
826 WindowRef
UMAGetActiveNonFloatingWindow()
831 bool UMAIsWindowFloating( WindowRef inWindow
)
835 UMAGetWindowClass( inWindow
, &cl
) ;
836 return cl
== kFloatingWindowClass
;
839 bool UMAIsWindowModal( WindowRef inWindow
)
843 UMAGetWindowClass( inWindow
, &cl
) ;
844 return cl
< kFloatingWindowClass
;
849 void UMAHighlightAndActivateWindow( WindowRef inWindowRef
, bool inActivate
)
853 // bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
854 // if ( inActivate != isHightlited )
855 HiliteWindow( inWindowRef
, inActivate
) ;