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
27 static bool sUMAHasAppearance
= false ;
28 static long sUMAAppearanceVersion
= 0 ;
29 static bool sUMAHasAquaLayout
= false ;
30 static bool sUMASystemInitialized
= false ;
32 extern int gAGABackgroundColor
;
33 bool UMAHasAppearance() { return sUMAHasAppearance
; }
34 long UMAGetAppearanceVersion() { return sUMAAppearanceVersion
; }
36 static bool sUMAHasWindowManager
= false ;
37 static long sUMAWindowManagerAttr
= 0 ;
39 bool UMAHasWindowManager() { return sUMAHasWindowManager
; }
40 long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr
; }
41 bool UMAHasAquaLayout() { return sUMAHasAquaLayout
; }
42 bool UMASystemIsInitialized() { return sUMASystemInitialized
; }
44 void UMACleanupToolbox()
46 if ( sUMAHasAppearance
)
48 UnregisterAppearanceClient() ;
50 if ( NavServicesAvailable() )
55 TXNTerminateTextension( ) ;
58 void UMAInitToolbox( UInt16 inMoreMastersCalls
)
62 for (long i
= 1; i
<= inMoreMastersCalls
; i
++)
65 ::InitGraf(&qd
.thePort
);
70 ::FlushEvents(everyEvent
, 0);
73 PurgeSpace(&total
, &contig
);
79 if ( Gestalt( gestaltAppearanceAttr
, &theAppearance
) == noErr
)
81 sUMAHasAppearance
= true ;
82 RegisterAppearanceClient();
83 if ( Gestalt( gestaltAppearanceVersion
, &theAppearance
) == noErr
)
85 sUMAAppearanceVersion
= theAppearance
;
89 sUMAAppearanceVersion
= 0x0100 ;
92 if ( Gestalt( gestaltWindowMgrAttr
, &sUMAWindowManagerAttr
) == noErr
)
94 sUMAHasWindowManager
= sUMAWindowManagerAttr
& gestaltWindowMgrPresent
;
98 // Call currently implicitely done : InitFloatingWindows() ;
100 if ( sUMAHasWindowManager
)
101 InitFloatingWindows() ;
106 if ( NavServicesAvailable() )
112 TXNMacOSPreferredFontDescription defaults
;
113 defaults
.fontID
= kFontIDGeneva
;
114 defaults
.pointSize
= (10 << 16) ;
115 defaults
.fontStyle
= kTXNDefaultFontStyle
;
116 defaults
.encoding
= kTXNSystemDefaultEncoding
;
117 TXNInitTextension(&defaults
, 1, (kTXNAlwaysUseQuickDrawTextMask
| kTXNWantMoviesMask
| kTXNWantSoundMask
| kTXNWantGraphicsMask
));
120 Gestalt( gestaltMenuMgrAttr
, &menuMgrAttr
) ;
121 if ( menuMgrAttr
& gestaltMenuMgrAquaLayoutMask
)
122 sUMAHasAquaLayout
= true ;
123 sUMASystemInitialized
= true ;
128 Boolean CanUseATSUI()
131 OSErr err = Gestalt(gestaltATSUVersion, &result);
132 return (err == noErr);
136 long UMAGetProcessMode()
139 ProcessInfoRec processinfo
;
140 ProcessSerialNumber procno
;
142 procno
.highLongOfPSN
= NULL
;
143 procno
.lowLongOfPSN
= kCurrentProcess
;
144 processinfo
.processInfoLength
= sizeof(ProcessInfoRec
);
145 processinfo
.processName
= NULL
;
146 processinfo
.processAppSpec
= NULL
;
148 err
= ::GetProcessInformation( &procno
, &processinfo
) ;
149 wxASSERT( err
== noErr
) ;
150 return processinfo
.processMode
;
153 bool UMAGetProcessModeDoesActivateOnFGSwitch()
155 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch
;
160 void UMASetMenuTitle( MenuRef menu
, StringPtr title
)
164 long size = GetHandleSize( (Handle) menu ) ;
165 const long headersize = 14 ;
166 int oldlen = (**menu).menuData[0] + 1;
167 int newlen = title[0] + 1 ;
169 if ( oldlen < newlen )
171 // enlarge before adjusting
172 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) );
175 if ( oldlen != newlen )
176 memmove( (char*) (**menu).menuData + newlen , (char*) (**menu).menuData + oldlen , size - headersize - oldlen ) ;
178 memcpy( (char*) (**menu).menuData , title , newlen ) ;
179 if ( oldlen > newlen )
182 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) ) ;
186 SetMenuTitle( menu
, title
) ;
190 UInt32
UMAMenuEvent( EventRecord
*inEvent
)
192 return MenuEvent( inEvent
) ;
195 void UMAEnableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
197 EnableMenuItem( inMenu
, inItem
) ;
200 void UMADisableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
202 DisableMenuItem( inMenu
, inItem
) ;
205 void UMAAppendSubMenuItem( MenuRef menu
, StringPtr l
, SInt16 id
)
208 memcpy( label
, l
, l
[0]+1 ) ;
209 // hardcoded adding of the submenu combination for mac
211 int theEnd
= label
[0] + 1;
213 theEnd
= 251; // mac allows only 255 characters
214 label
[theEnd
++] = '/';
215 label
[theEnd
++] = hMenuCmd
;
216 label
[theEnd
++] = '!';
217 label
[theEnd
++] = id
;
218 label
[theEnd
] = 0x00;
220 MacAppendMenu(menu
, label
);
223 void UMAInsertSubMenuItem( MenuRef menu
, StringPtr l
, MenuItemIndex item
, SInt16 id
)
226 memcpy( label
, l
, l
[0]+1 ) ;
227 // hardcoded adding of the submenu combination for mac
229 int theEnd
= label
[0] + 1;
231 theEnd
= 251; // mac allows only 255 characters
232 label
[theEnd
++] = '/';
233 label
[theEnd
++] = hMenuCmd
;
234 label
[theEnd
++] = '!';
235 label
[theEnd
++] = id
;
236 label
[theEnd
] = 0x00;
238 MacInsertMenuItem(menu
, label
, item
);
241 void UMAAppendMenuItem( MenuRef menu
, StringPtr l
, SInt16 key
, UInt8 modifiers
)
244 memcpy( label
, l
, l
[0]+1 ) ;
249 label
[++pos
] = toupper( key
);
252 MacAppendMenu( menu
, label
) ;
255 void UMAInsertMenuItem( MenuRef menu
, StringPtr l
, MenuItemIndex item
, SInt16 key
, UInt8 modifiers
)
258 memcpy( label
, l
, l
[0]+1 ) ;
263 label
[++pos
] = toupper( key
);
266 MacInsertMenuItem( menu
, label
, item
) ;
271 int gPrOpenCounter
= 0 ;
273 OSStatus
UMAPrOpen(void *macPrintSession
)
278 if ( gPrOpenCounter
== 1 )
282 wxASSERT( err
== noErr
) ;
286 OSStatus err
= noErr
;
288 if ( gPrOpenCounter
== 1 )
290 #if PM_USE_SESSION_APIS
291 err
= PMCreateSession((PMPrintSession
*)macPrintSession
) ;
295 wxASSERT( err
== noErr
) ;
301 OSStatus
UMAPrClose(void *macPrintSession
)
305 wxASSERT( gPrOpenCounter
>= 1 ) ;
306 if ( gPrOpenCounter
== 1 )
310 wxASSERT( err
== noErr
) ;
315 OSStatus err
= noErr
;
316 wxASSERT( gPrOpenCounter
>= 1 ) ;
317 if ( gPrOpenCounter
== 1 )
319 #if PM_USE_SESSION_APIS
320 err
= PMRelease(*(PMPrintSession
*)macPrintSession
) ;
321 *(PMPrintSession
*)macPrintSession
= kPMNoReference
;
333 pascal QDGlobalsPtr
GetQDGlobalsPtr (void) ;
334 pascal QDGlobalsPtr
GetQDGlobalsPtr (void)
336 return QDGlobalsPtr (* (Ptr
*) LMGetCurrentA5 ( ) - 0xCA);
341 void UMAShowWatchCursor()
345 CursHandle watchFob
= GetCursor (watchCursor
);
352 // Cursor preservedArrow;
353 // GetQDGlobalsArrow (&preservedArrow);
354 // SetQDGlobalsArrow (*watchFob);
356 // SetQDGlobalsArrow (&preservedArrow);
357 SetCursor (*watchFob
);
359 SetCursor (*watchFob
);
364 void UMAShowArrowCursor()
368 SetCursor (GetQDGlobalsArrow (&arrow
));
370 SetCursor (&(qd
.arrow
));
376 GrafPtr
UMAGetWindowPort( WindowRef inWindowRef
)
378 wxASSERT( inWindowRef
!= NULL
) ;
380 return (GrafPtr
) GetWindowPort( inWindowRef
) ;
382 return (GrafPtr
) inWindowRef
;
386 void UMADisposeWindow( WindowRef inWindowRef
)
388 wxASSERT( inWindowRef
!= NULL
) ;
389 DisposeWindow( inWindowRef
) ;
392 void UMASetWTitleC( WindowRef inWindowRef
, const char *title
)
395 strncpy( (char*)ptitle
, title
, 96 ) ;
398 c2pstrcpy( ptitle
, (char *)ptitle
) ;
400 c2pstr( (char*)ptitle
) ;
402 SetWTitle( inWindowRef
, ptitle
) ;
405 void UMAGetWTitleC( WindowRef inWindowRef
, char *title
)
407 GetWTitle( inWindowRef
, (unsigned char*)title
) ;
409 p2cstrcpy( title
, (unsigned char *)title
) ;
411 p2cstr( (unsigned char*)title
) ;
415 // appearance additions
417 void UMAActivateControl( ControlHandle inControl
)
419 // we have to add the control after again to the update rgn
420 // otherwise updates get lost
421 if ( !IsControlActive( inControl
) )
423 bool visible
= IsControlVisible( inControl
) ;
425 SetControlVisibility( inControl
, false , false ) ;
426 ::ActivateControl( inControl
) ;
428 SetControlVisibility( inControl
, true , false ) ;
430 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
435 void UMADrawControl( ControlHandle inControl
)
437 WindowRef theWindow
= GetControlOwner(inControl
) ;
438 RgnHandle updateRgn
= NewRgn() ;
439 GetWindowUpdateRgn( theWindow
, updateRgn
) ;
440 Point zero
= { 0 , 0 } ;
441 LocalToGlobal( &zero
) ;
442 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
443 ::DrawControlInCurrentPort( inControl
) ;
444 InvalWindowRgn( theWindow
, updateRgn
) ;
445 DisposeRgn( updateRgn
) ;
448 void UMAMoveControl( ControlHandle inControl
, short x
, short y
)
450 bool visible
= IsControlVisible( inControl
) ;
452 SetControlVisibility( inControl
, false , false ) ;
454 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
456 ::MoveControl( inControl
, x
, y
) ;
458 SetControlVisibility( inControl
, true , false ) ;
460 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
464 void UMASizeControl( ControlHandle inControl
, short x
, short y
)
466 bool visible
= IsControlVisible( inControl
) ;
468 SetControlVisibility( inControl
, false , false ) ;
470 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
472 ::SizeControl( inControl
, x
, y
) ;
474 SetControlVisibility( inControl
, true , false ) ;
476 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
480 void UMADeactivateControl( ControlHandle inControl
)
482 // we have to add the control after again to the update rgn
483 // otherwise updates get lost
484 bool visible
= IsControlVisible( inControl
) ;
486 SetControlVisibility( inControl
, false , false ) ;
487 ::DeactivateControl( inControl
) ;
489 SetControlVisibility( inControl
, true , false ) ;
491 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
494 // shows the control and adds the region to the update region
495 void UMAShowControl (ControlHandle inControl
)
497 SetControlVisibility( inControl
, true , false ) ;
499 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
502 // shows the control and adds the region to the update region
503 void UMAHideControl (ControlHandle inControl
)
505 SetControlVisibility( inControl
, false , false ) ;
507 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
510 OSErr
UMASetKeyboardFocus (WindowPtr inWindow
,
511 ControlHandle inControl
,
512 ControlFocusPart inPart
)
518 SetPortWindowPort( inWindow
) ;
520 err
= SetKeyboardFocus( inWindow
, inControl
, inPart
) ;
529 void UMAUpdateControls( WindowPtr inWindow
, RgnHandle inRgn
)
531 RgnHandle updateRgn
= NewRgn() ;
532 GetWindowUpdateRgn( inWindow
, updateRgn
) ;
534 Point zero
= { 0 , 0 } ;
535 LocalToGlobal( &zero
) ;
536 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
538 UpdateControls( inWindow
, inRgn
) ;
539 InvalWindowRgn( inWindow
, updateRgn
) ;
540 DisposeRgn( updateRgn
) ;
544 bool UMAIsWindowFloating( WindowRef inWindow
)
548 GetWindowClass( inWindow
, &cl
) ;
549 return cl
== kFloatingWindowClass
;
552 bool UMAIsWindowModal( WindowRef inWindow
)
556 GetWindowClass( inWindow
, &cl
) ;
557 return cl
< kFloatingWindowClass
;
562 void UMAHighlightAndActivateWindow( WindowRef inWindowRef
, bool inActivate
)
566 // bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
567 // if ( inActivate != isHightlited )
570 SetPortWindowPort( inWindowRef
) ;
571 HiliteWindow( inWindowRef
, inActivate
) ;
572 ControlHandle control
= NULL
;
573 ::GetRootControl( inWindowRef
, & control
) ;
577 UMAActivateControl( control
) ;
579 UMADeactivateControl( control
) ;
584 OSStatus
UMADrawThemePlacard( const Rect
*inRect
, ThemeDrawState inState
)
586 return ::DrawThemePlacard( inRect
, inState
) ;
590 static OSStatus helpMenuStatus
= noErr
;
591 static MenuItemIndex firstCustomItemIndex
= 0 ;
594 OSStatus
UMAGetHelpMenu(
595 MenuRef
* outHelpMenu
,
596 MenuItemIndex
* outFirstCustomItemIndex
)
599 return HMGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
) ;
601 MenuRef helpMenuHandle
;
602 helpMenuStatus
= HMGetHelpMenuHandle( &helpMenuHandle
) ;
603 if ( firstCustomItemIndex
== 0 && helpMenuStatus
== noErr
)
605 firstCustomItemIndex
= CountMenuItems( helpMenuHandle
) + 1 ;
607 if ( outFirstCustomItemIndex
)
609 *outFirstCustomItemIndex
= firstCustomItemIndex
;
611 *outHelpMenu
= helpMenuHandle
;
612 return helpMenuStatus
;
616 wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport
)
622 wxMacPortStateHelper::wxMacPortStateHelper()
627 void wxMacPortStateHelper::Setup( GrafPtr newport
)
629 GetPort( &m_oldPort
) ;
631 wxASSERT_MSG( m_clip
== NULL
, "Cannot call setup twice" ) ;
634 m_textFont
= GetPortTextFont( (CGrafPtr
) newport
);
635 m_textSize
= GetPortTextSize( (CGrafPtr
) newport
);
636 m_textStyle
= GetPortTextFace( (CGrafPtr
) newport
);
637 m_textMode
= GetPortTextMode( (CGrafPtr
) newport
);
638 GetThemeDrawingState( &m_drawingState
) ;
639 m_currentPort
= newport
;
641 void wxMacPortStateHelper::Clear()
645 DisposeRgn( m_clip
) ;
646 DisposeThemeDrawingState( m_drawingState
) ;
651 wxMacPortStateHelper::~wxMacPortStateHelper()
655 SetPort( m_currentPort
) ;
657 DisposeRgn( m_clip
) ;
658 TextFont( m_textFont
);
659 TextSize( m_textSize
);
660 TextFace( m_textStyle
);
661 TextMode( m_textMode
);
662 SetThemeDrawingState( m_drawingState
, true ) ;
663 SetPort( m_oldPort
) ;