3 #include "wx/mac/uma.h"
4 #include <MacTextEditor.h>
7 # include <Navigation.h>
8 # if defined(TARGET_CARBON)
9 # if PM_USE_SESSION_APIS
12 # include <PMApplication.h>
14 # include <Printing.h>
18 // since we have decided that we only support 8.6 upwards we are
19 // checking for these minimum requirements in the startup code of
20 // the application so all wxWindows code can safely assume that appearance 1.1
21 // windows manager, control manager, navigation services etc. are
24 static bool sUMAHasAppearance
= false ;
25 static long sUMAAppearanceVersion
= 0 ;
26 static bool sUMAHasAquaLayout
= false ;
27 static bool sUMASystemInitialized
= false ;
29 extern int gAGABackgroundColor
;
30 bool UMAHasAppearance() { return sUMAHasAppearance
; }
31 long UMAGetAppearanceVersion() { return sUMAAppearanceVersion
; }
33 static bool sUMAHasWindowManager
= false ;
34 static long sUMAWindowManagerAttr
= 0 ;
36 bool UMAHasWindowManager() { return sUMAHasWindowManager
; }
37 long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr
; }
38 bool UMAHasAquaLayout() { return sUMAHasAquaLayout
; }
39 bool UMASystemIsInitialized() { return sUMASystemInitialized
; }
41 void UMACleanupToolbox()
43 if ( sUMAHasAppearance
)
45 UnregisterAppearanceClient() ;
47 if ( NavServicesAvailable() )
51 if ( TXNTerminateTextension
!= (void*) kUnresolvedCFragSymbolAddress
)
52 TXNTerminateTextension( ) ;
54 void UMAInitToolbox( UInt16 inMoreMastersCalls
)
58 for (long i
= 1; i
<= inMoreMastersCalls
; i
++)
61 ::InitGraf(&qd
.thePort
);
66 ::FlushEvents(everyEvent
, 0);
69 PurgeSpace(&total
, &contig
);
75 if ( Gestalt( gestaltAppearanceAttr
, &theAppearance
) == noErr
)
77 sUMAHasAppearance
= true ;
78 RegisterAppearanceClient();
79 if ( Gestalt( gestaltAppearanceVersion
, &theAppearance
) == noErr
)
81 sUMAAppearanceVersion
= theAppearance
;
85 sUMAAppearanceVersion
= 0x0100 ;
88 if ( Gestalt( gestaltWindowMgrAttr
, &sUMAWindowManagerAttr
) == noErr
)
90 sUMAHasWindowManager
= sUMAWindowManagerAttr
& gestaltWindowMgrPresent
;
94 // Call currently implicitely done : InitFloatingWindows() ;
96 if ( sUMAHasWindowManager
)
97 InitFloatingWindows() ;
102 if ( NavServicesAvailable() )
107 if ( TXNInitTextension
!= (void*) kUnresolvedCFragSymbolAddress
)
109 TXNMacOSPreferredFontDescription defaults
;
110 defaults
.fontID
= kFontIDGeneva
;
111 defaults
.pointSize
= (10 << 16) ;
112 defaults
.fontStyle
= kTXNDefaultFontStyle
;
113 defaults
.encoding
= kTXNSystemDefaultEncoding
;
114 TXNInitTextension(&defaults
, 1, (kTXNAlwaysUseQuickDrawTextMask
| kTXNWantMoviesMask
| kTXNWantSoundMask
| kTXNWantGraphicsMask
));
118 Gestalt( gestaltMenuMgrAttr
, &menuMgrAttr
) ;
119 if ( menuMgrAttr
& gestaltMenuMgrAquaLayoutMask
)
120 sUMAHasAquaLayout
= true ;
121 sUMASystemInitialized
= true ;
126 Boolean CanUseATSUI()
129 OSErr err = Gestalt(gestaltATSUVersion, &result);
130 return (err == noErr);
134 long UMAGetProcessMode()
137 ProcessInfoRec processinfo
;
138 ProcessSerialNumber procno
;
140 procno
.highLongOfPSN
= NULL
;
141 procno
.lowLongOfPSN
= kCurrentProcess
;
142 processinfo
.processInfoLength
= sizeof(ProcessInfoRec
);
143 processinfo
.processName
= NULL
;
144 processinfo
.processAppSpec
= NULL
;
146 err
= ::GetProcessInformation( &procno
, &processinfo
) ;
147 wxASSERT( err
== noErr
) ;
148 return processinfo
.processMode
;
151 bool UMAGetProcessModeDoesActivateOnFGSwitch()
153 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch
;
158 void UMASetMenuTitle( MenuRef menu
, StringPtr title
)
162 long size = GetHandleSize( (Handle) menu ) ;
163 const long headersize = 14 ;
164 int oldlen = (**menu).menuData[0] + 1;
165 int newlen = title[0] + 1 ;
167 if ( oldlen < newlen )
169 // enlarge before adjusting
170 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) );
173 if ( oldlen != newlen )
174 memmove( (char*) (**menu).menuData + newlen , (char*) (**menu).menuData + oldlen , size - headersize - oldlen ) ;
176 memcpy( (char*) (**menu).menuData , title , newlen ) ;
177 if ( oldlen > newlen )
180 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) ) ;
184 SetMenuTitle( menu
, title
) ;
188 UInt32
UMAMenuEvent( EventRecord
*inEvent
)
190 return MenuEvent( inEvent
) ;
193 void UMAEnableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
195 EnableMenuItem( inMenu
, inItem
) ;
198 void UMADisableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
200 DisableMenuItem( inMenu
, inItem
) ;
203 void UMAAppendSubMenuItem( MenuRef menu
, StringPtr l
, SInt16 id
)
206 memcpy( label
, l
, l
[0]+1 ) ;
207 // hardcoded adding of the submenu combination for mac
209 int theEnd
= label
[0] + 1;
211 theEnd
= 251; // mac allows only 255 characters
212 label
[theEnd
++] = '/';
213 label
[theEnd
++] = hMenuCmd
;
214 label
[theEnd
++] = '!';
215 label
[theEnd
++] = id
;
216 label
[theEnd
] = 0x00;
218 MacAppendMenu(menu
, label
);
221 void UMAInsertSubMenuItem( MenuRef menu
, StringPtr l
, MenuItemIndex item
, SInt16 id
)
224 memcpy( label
, l
, l
[0]+1 ) ;
225 // hardcoded adding of the submenu combination for mac
227 int theEnd
= label
[0] + 1;
229 theEnd
= 251; // mac allows only 255 characters
230 label
[theEnd
++] = '/';
231 label
[theEnd
++] = hMenuCmd
;
232 label
[theEnd
++] = '!';
233 label
[theEnd
++] = id
;
234 label
[theEnd
] = 0x00;
236 MacInsertMenuItem(menu
, label
, item
);
239 void UMAAppendMenuItem( MenuRef menu
, StringPtr l
, SInt16 key
, UInt8 modifiers
)
242 memcpy( label
, l
, l
[0]+1 ) ;
247 label
[++pos
] = toupper( key
);
250 MacAppendMenu( menu
, label
) ;
253 void UMAInsertMenuItem( MenuRef menu
, StringPtr l
, MenuItemIndex item
, SInt16 key
, UInt8 modifiers
)
256 memcpy( label
, l
, l
[0]+1 ) ;
261 label
[++pos
] = toupper( key
);
264 MacInsertMenuItem( menu
, label
, item
) ;
269 int gPrOpenCounter
= 0 ;
271 OSStatus
UMAPrOpen(void *macPrintSession
)
276 if ( gPrOpenCounter
== 1 )
280 wxASSERT( err
== noErr
) ;
284 OSStatus err
= noErr
;
286 if ( gPrOpenCounter
== 1 )
288 #if PM_USE_SESSION_APIS
289 err
= PMCreateSession((PMPrintSession
*)macPrintSession
) ;
293 wxASSERT( err
== noErr
) ;
299 OSStatus
UMAPrClose(void *macPrintSession
)
303 wxASSERT( gPrOpenCounter
>= 1 ) ;
304 if ( gPrOpenCounter
== 1 )
308 wxASSERT( err
== noErr
) ;
313 OSStatus err
= noErr
;
314 wxASSERT( gPrOpenCounter
>= 1 ) ;
315 if ( gPrOpenCounter
== 1 )
317 #if PM_USE_SESSION_APIS
318 err
= PMRelease(*(PMPrintSession
*)macPrintSession
) ;
319 *(PMPrintSession
*)macPrintSession
= kPMNoReference
;
331 pascal QDGlobalsPtr
GetQDGlobalsPtr (void) ;
332 pascal QDGlobalsPtr
GetQDGlobalsPtr (void)
334 return QDGlobalsPtr (* (Ptr
*) LMGetCurrentA5 ( ) - 0xCA);
339 void UMAShowWatchCursor()
343 CursHandle watchFob
= GetCursor (watchCursor
);
350 // Cursor preservedArrow;
351 // GetQDGlobalsArrow (&preservedArrow);
352 // SetQDGlobalsArrow (*watchFob);
354 // SetQDGlobalsArrow (&preservedArrow);
355 SetCursor (*watchFob
);
357 SetCursor (*watchFob
);
362 void UMAShowArrowCursor()
366 SetCursor (GetQDGlobalsArrow (&arrow
));
368 SetCursor (&(qd
.arrow
));
374 GrafPtr
UMAGetWindowPort( WindowRef inWindowRef
)
376 wxASSERT( inWindowRef
!= NULL
) ;
378 return (GrafPtr
) GetWindowPort( inWindowRef
) ;
380 return (GrafPtr
) inWindowRef
;
384 void UMADisposeWindow( WindowRef inWindowRef
)
386 wxASSERT( inWindowRef
!= NULL
) ;
387 DisposeWindow( inWindowRef
) ;
390 void UMASetWTitleC( WindowRef inWindowRef
, const char *title
)
393 strncpy( (char*)ptitle
, title
, 96 ) ;
396 c2pstrcpy( ptitle
, (char *)ptitle
) ;
398 c2pstr( (char*)ptitle
) ;
400 SetWTitle( inWindowRef
, ptitle
) ;
403 void UMAGetWTitleC( WindowRef inWindowRef
, char *title
)
405 GetWTitle( inWindowRef
, (unsigned char*)title
) ;
407 p2cstrcpy( title
, (unsigned char *)title
) ;
409 p2cstr( (unsigned char*)title
) ;
413 // appearance additions
415 void UMAActivateControl( ControlHandle inControl
)
417 // we have to add the control after again to the update rgn
418 // otherwise updates get lost
419 if ( !IsControlActive( inControl
) )
421 bool visible
= IsControlVisible( inControl
) ;
423 SetControlVisibility( inControl
, false , false ) ;
424 ::ActivateControl( inControl
) ;
426 SetControlVisibility( inControl
, true , false ) ;
428 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
433 void UMADrawControl( ControlHandle inControl
)
435 WindowRef theWindow
= GetControlOwner(inControl
) ;
436 RgnHandle updateRgn
= NewRgn() ;
437 GetWindowUpdateRgn( theWindow
, updateRgn
) ;
438 Point zero
= { 0 , 0 } ;
439 LocalToGlobal( &zero
) ;
440 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
441 ::DrawControlInCurrentPort( inControl
) ;
442 InvalWindowRgn( theWindow
, updateRgn
) ;
443 DisposeRgn( updateRgn
) ;
446 void UMAMoveControl( ControlHandle inControl
, short x
, short y
)
448 bool visible
= IsControlVisible( inControl
) ;
450 SetControlVisibility( inControl
, false , false ) ;
452 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
454 ::MoveControl( inControl
, x
, y
) ;
456 SetControlVisibility( inControl
, true , false ) ;
458 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
462 void UMASizeControl( ControlHandle inControl
, short x
, short y
)
464 bool visible
= IsControlVisible( inControl
) ;
466 SetControlVisibility( inControl
, false , false ) ;
468 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
470 ::SizeControl( inControl
, x
, y
) ;
472 SetControlVisibility( inControl
, true , false ) ;
474 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
478 void UMADeactivateControl( ControlHandle inControl
)
480 // we have to add the control after again to the update rgn
481 // otherwise updates get lost
482 bool visible
= IsControlVisible( inControl
) ;
484 SetControlVisibility( inControl
, false , false ) ;
485 ::DeactivateControl( inControl
) ;
487 SetControlVisibility( inControl
, true , false ) ;
489 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
492 // shows the control and adds the region to the update region
493 void UMAShowControl (ControlHandle inControl
)
495 SetControlVisibility( inControl
, true , false ) ;
497 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
500 // shows the control and adds the region to the update region
501 void UMAHideControl (ControlHandle inControl
)
503 SetControlVisibility( inControl
, false , false ) ;
505 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
508 OSErr
UMASetKeyboardFocus (WindowPtr inWindow
,
509 ControlHandle inControl
,
510 ControlFocusPart inPart
)
516 SetPortWindowPort( inWindow
) ;
518 err
= SetKeyboardFocus( inWindow
, inControl
, inPart
) ;
527 void UMAUpdateControls( WindowPtr inWindow
, RgnHandle inRgn
)
529 RgnHandle updateRgn
= NewRgn() ;
530 GetWindowUpdateRgn( inWindow
, updateRgn
) ;
532 Point zero
= { 0 , 0 } ;
533 LocalToGlobal( &zero
) ;
534 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
536 UpdateControls( inWindow
, inRgn
) ;
537 InvalWindowRgn( inWindow
, updateRgn
) ;
538 DisposeRgn( updateRgn
) ;
542 bool UMAIsWindowFloating( WindowRef inWindow
)
546 GetWindowClass( inWindow
, &cl
) ;
547 return cl
== kFloatingWindowClass
;
550 bool UMAIsWindowModal( WindowRef inWindow
)
554 GetWindowClass( inWindow
, &cl
) ;
555 return cl
< kFloatingWindowClass
;
560 void UMAHighlightAndActivateWindow( WindowRef inWindowRef
, bool inActivate
)
564 // bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
565 // if ( inActivate != isHightlited )
568 SetPortWindowPort( inWindowRef
) ;
569 HiliteWindow( inWindowRef
, inActivate
) ;
570 ControlHandle control
= NULL
;
571 ::GetRootControl( inWindowRef
, & control
) ;
575 UMAActivateControl( control
) ;
577 UMADeactivateControl( control
) ;
582 OSStatus
UMADrawThemePlacard( const Rect
*inRect
, ThemeDrawState inState
)
584 return ::DrawThemePlacard( inRect
, inState
) ;
588 static OSStatus helpMenuStatus
= noErr
;
589 static MenuItemIndex firstCustomItemIndex
= 0 ;
592 OSStatus
UMAGetHelpMenu(
593 MenuRef
* outHelpMenu
,
594 MenuItemIndex
* outFirstCustomItemIndex
)
597 return HMGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
) ;
599 MenuRef helpMenuHandle
;
600 helpMenuStatus
= HMGetHelpMenuHandle( &helpMenuHandle
) ;
601 if ( firstCustomItemIndex
== 0 && helpMenuStatus
== noErr
)
603 firstCustomItemIndex
= CountMenuItems( helpMenuHandle
) + 1 ;
605 if ( outFirstCustomItemIndex
)
607 *outFirstCustomItemIndex
= firstCustomItemIndex
;
609 *outHelpMenu
= helpMenuHandle
;
610 return helpMenuStatus
;
614 wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport
)
620 wxMacPortStateHelper::wxMacPortStateHelper()
625 void wxMacPortStateHelper::Setup( GrafPtr newport
)
627 GetPort( &m_oldPort
) ;
629 wxASSERT_MSG( m_clip
== NULL
, "Cannot call setup twice" ) ;
632 m_textFont
= GetPortTextFont( (CGrafPtr
) newport
);
633 m_textSize
= GetPortTextSize( (CGrafPtr
) newport
);
634 m_textStyle
= GetPortTextFace( (CGrafPtr
) newport
);
635 m_textMode
= GetPortTextMode( (CGrafPtr
) newport
);
636 GetThemeDrawingState( &m_drawingState
) ;
637 m_currentPort
= newport
;
639 void wxMacPortStateHelper::Clear()
643 DisposeRgn( m_clip
) ;
644 DisposeThemeDrawingState( m_drawingState
) ;
649 wxMacPortStateHelper::~wxMacPortStateHelper()
653 SetPort( m_currentPort
) ;
655 DisposeRgn( m_clip
) ;
656 TextFont( m_textFont
);
657 TextSize( m_textSize
);
658 TextFace( m_textStyle
);
659 TextMode( m_textMode
);
660 SetThemeDrawingState( m_drawingState
, true ) ;
661 SetPort( m_oldPort
) ;