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
;
99 // Call currently implicitely done : InitFloatingWindows() ;
101 if ( sUMAHasWindowManager
)
102 InitFloatingWindows() ;
108 if ( NavServicesAvailable() )
114 TXNMacOSPreferredFontDescription defaults
;
115 defaults
.fontID
= kFontIDGeneva
;
116 defaults
.pointSize
= (10 << 16) ;
117 defaults
.fontStyle
= kTXNDefaultFontStyle
;
118 defaults
.encoding
= kTXNSystemDefaultEncoding
;
119 TXNInitTextension(&defaults
, 1, (kTXNAlwaysUseQuickDrawTextMask
| kTXNWantMoviesMask
| kTXNWantSoundMask
| kTXNWantGraphicsMask
));
122 Gestalt( gestaltMenuMgrAttr
, &menuMgrAttr
) ;
123 if ( menuMgrAttr
& gestaltMenuMgrAquaLayoutMask
)
124 sUMAHasAquaLayout
= true ;
125 sUMASystemInitialized
= true ;
130 Boolean CanUseATSUI()
133 OSErr err = Gestalt(gestaltATSUVersion, &result);
134 return (err == noErr);
138 long UMAGetProcessMode()
141 ProcessInfoRec processinfo
;
142 ProcessSerialNumber procno
;
144 procno
.highLongOfPSN
= NULL
;
145 procno
.lowLongOfPSN
= kCurrentProcess
;
146 processinfo
.processInfoLength
= sizeof(ProcessInfoRec
);
147 processinfo
.processName
= NULL
;
148 processinfo
.processAppSpec
= NULL
;
150 err
= ::GetProcessInformation( &procno
, &processinfo
) ;
151 wxASSERT( err
== noErr
) ;
152 return processinfo
.processMode
;
155 bool UMAGetProcessModeDoesActivateOnFGSwitch()
157 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch
;
162 void UMASetMenuTitle( MenuRef menu
, StringPtr title
)
166 long size = GetHandleSize( (Handle) menu ) ;
167 const long headersize = 14 ;
168 int oldlen = (**menu).menuData[0] + 1;
169 int newlen = title[0] + 1 ;
171 if ( oldlen < newlen )
173 // enlarge before adjusting
174 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) );
177 if ( oldlen != newlen )
178 memmove( (char*) (**menu).menuData + newlen , (char*) (**menu).menuData + oldlen , size - headersize - oldlen ) ;
180 memcpy( (char*) (**menu).menuData , title , newlen ) ;
181 if ( oldlen > newlen )
184 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) ) ;
188 SetMenuTitle( menu
, title
) ;
192 UInt32
UMAMenuEvent( EventRecord
*inEvent
)
194 return MenuEvent( inEvent
) ;
197 void UMAEnableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
199 EnableMenuItem( inMenu
, inItem
) ;
202 void UMADisableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
204 DisableMenuItem( inMenu
, inItem
) ;
207 void UMAAppendSubMenuItem( MenuRef menu
, StringPtr l
, SInt16 id
)
210 memcpy( label
, l
, l
[0]+1 ) ;
211 // hardcoded adding of the submenu combination for mac
213 int theEnd
= label
[0] + 1;
215 theEnd
= 251; // mac allows only 255 characters
216 label
[theEnd
++] = '/';
217 label
[theEnd
++] = hMenuCmd
;
218 label
[theEnd
++] = '!';
219 label
[theEnd
++] = id
;
220 label
[theEnd
] = 0x00;
222 MacAppendMenu(menu
, label
);
225 void UMAInsertSubMenuItem( MenuRef menu
, StringPtr l
, MenuItemIndex item
, SInt16 id
)
228 memcpy( label
, l
, l
[0]+1 ) ;
229 // hardcoded adding of the submenu combination for mac
231 int theEnd
= label
[0] + 1;
233 theEnd
= 251; // mac allows only 255 characters
234 label
[theEnd
++] = '/';
235 label
[theEnd
++] = hMenuCmd
;
236 label
[theEnd
++] = '!';
237 label
[theEnd
++] = id
;
238 label
[theEnd
] = 0x00;
240 MacInsertMenuItem(menu
, label
, item
);
243 void UMAAppendMenuItem( MenuRef menu
, StringPtr l
, SInt16 key
, UInt8 modifiers
)
246 memcpy( label
, l
, l
[0]+1 ) ;
251 label
[++pos
] = toupper( key
);
254 MacAppendMenu( menu
, label
) ;
257 void UMAInsertMenuItem( MenuRef menu
, StringPtr l
, MenuItemIndex item
, SInt16 key
, UInt8 modifiers
)
260 memcpy( label
, l
, l
[0]+1 ) ;
265 label
[++pos
] = toupper( key
);
268 MacInsertMenuItem( menu
, label
, item
) ;
273 int gPrOpenCounter
= 0 ;
275 OSStatus
UMAPrOpen(void *macPrintSession
)
280 if ( gPrOpenCounter
== 1 )
284 wxASSERT( err
== noErr
) ;
288 OSStatus err
= noErr
;
290 if ( gPrOpenCounter
== 1 )
292 #if PM_USE_SESSION_APIS
293 err
= PMCreateSession((PMPrintSession
*)macPrintSession
) ;
297 wxASSERT( err
== noErr
) ;
303 OSStatus
UMAPrClose(void *macPrintSession
)
307 wxASSERT( gPrOpenCounter
>= 1 ) ;
308 if ( gPrOpenCounter
== 1 )
312 wxASSERT( err
== noErr
) ;
317 OSStatus err
= noErr
;
318 wxASSERT( gPrOpenCounter
>= 1 ) ;
319 if ( gPrOpenCounter
== 1 )
321 #if PM_USE_SESSION_APIS
322 err
= PMRelease(*(PMPrintSession
*)macPrintSession
) ;
323 *(PMPrintSession
*)macPrintSession
= kPMNoReference
;
335 pascal QDGlobalsPtr
GetQDGlobalsPtr (void) ;
336 pascal QDGlobalsPtr
GetQDGlobalsPtr (void)
338 return QDGlobalsPtr (* (Ptr
*) LMGetCurrentA5 ( ) - 0xCA);
343 void UMAShowWatchCursor()
347 CursHandle watchFob
= GetCursor (watchCursor
);
354 // Cursor preservedArrow;
355 // GetQDGlobalsArrow (&preservedArrow);
356 // SetQDGlobalsArrow (*watchFob);
358 // SetQDGlobalsArrow (&preservedArrow);
359 SetCursor (*watchFob
);
361 SetCursor (*watchFob
);
366 void UMAShowArrowCursor()
370 SetCursor (GetQDGlobalsArrow (&arrow
));
372 SetCursor (&(qd
.arrow
));
378 GrafPtr
UMAGetWindowPort( WindowRef inWindowRef
)
380 wxASSERT( inWindowRef
!= NULL
) ;
382 return GetWindowPort( inWindowRef
) ;
384 return (GrafPtr
) inWindowRef
;
388 void UMADisposeWindow( WindowRef inWindowRef
)
390 wxASSERT( inWindowRef
!= NULL
) ;
391 DisposeWindow( inWindowRef
) ;
394 void UMASetWTitleC( WindowRef inWindowRef
, const char *title
)
397 strncpy( (char*)ptitle
, title
, 96 ) ;
400 c2pstrcpy( ptitle
, (char *)ptitle
) ;
402 c2pstr( (char*)ptitle
) ;
404 SetWTitle( inWindowRef
, ptitle
) ;
407 void UMAGetWTitleC( WindowRef inWindowRef
, char *title
)
409 GetWTitle( inWindowRef
, (unsigned char*)title
) ;
411 p2cstrcpy( title
, (unsigned char *)title
) ;
413 p2cstr( (unsigned char*)title
) ;
417 // appearance additions
419 void UMAActivateControl( ControlHandle inControl
)
421 // we have to add the control after again to the update rgn
422 // otherwise updates get lost
423 if ( !IsControlActive( inControl
) )
425 bool visible
= IsControlVisible( inControl
) ;
427 SetControlVisibility( inControl
, false , false ) ;
428 ::ActivateControl( inControl
) ;
430 SetControlVisibility( inControl
, true , false ) ;
432 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
437 void UMADrawControl( ControlHandle inControl
)
439 WindowRef theWindow
= GetControlOwner(inControl
) ;
440 RgnHandle updateRgn
= NewRgn() ;
441 GetWindowUpdateRgn( theWindow
, updateRgn
) ;
442 Point zero
= { 0 , 0 } ;
443 LocalToGlobal( &zero
) ;
444 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
445 ::DrawControlInCurrentPort( inControl
) ;
446 InvalWindowRgn( theWindow
, updateRgn
) ;
447 DisposeRgn( updateRgn
) ;
450 void UMAMoveControl( ControlHandle inControl
, short x
, short y
)
452 bool visible
= IsControlVisible( inControl
) ;
454 SetControlVisibility( inControl
, false , false ) ;
456 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
458 ::MoveControl( inControl
, x
, y
) ;
460 SetControlVisibility( inControl
, true , false ) ;
462 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
466 void UMASizeControl( ControlHandle inControl
, short x
, short y
)
468 bool visible
= IsControlVisible( inControl
) ;
470 SetControlVisibility( inControl
, false , false ) ;
472 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
474 ::SizeControl( inControl
, x
, y
) ;
476 SetControlVisibility( inControl
, true , false ) ;
478 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
482 void UMADeactivateControl( ControlHandle inControl
)
484 // we have to add the control after again to the update rgn
485 // otherwise updates get lost
486 bool visible
= IsControlVisible( inControl
) ;
488 SetControlVisibility( inControl
, false , false ) ;
489 ::DeactivateControl( inControl
) ;
491 SetControlVisibility( inControl
, true , false ) ;
493 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
496 // shows the control and adds the region to the update region
497 void UMAShowControl (ControlHandle inControl
)
499 SetControlVisibility( inControl
, true , false ) ;
501 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
504 // shows the control and adds the region to the update region
505 void UMAHideControl (ControlHandle inControl
)
507 SetControlVisibility( inControl
, false , false ) ;
509 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
512 OSErr
UMASetKeyboardFocus (WindowPtr inWindow
,
513 ControlHandle inControl
,
514 ControlFocusPart inPart
)
520 SetPortWindowPort( inWindow
) ;
522 err
= SetKeyboardFocus( inWindow
, inControl
, inPart
) ;
531 void UMAUpdateControls( WindowPtr inWindow
, RgnHandle inRgn
)
533 RgnHandle updateRgn
= NewRgn() ;
534 GetWindowUpdateRgn( inWindow
, updateRgn
) ;
536 Point zero
= { 0 , 0 } ;
537 LocalToGlobal( &zero
) ;
538 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
540 UpdateControls( inWindow
, inRgn
) ;
541 InvalWindowRgn( inWindow
, updateRgn
) ;
542 DisposeRgn( updateRgn
) ;
546 bool UMAIsWindowFloating( WindowRef inWindow
)
550 GetWindowClass( inWindow
, &cl
) ;
551 return cl
== kFloatingWindowClass
;
554 bool UMAIsWindowModal( WindowRef inWindow
)
558 GetWindowClass( inWindow
, &cl
) ;
559 return cl
< kFloatingWindowClass
;
564 void UMAHighlightAndActivateWindow( WindowRef inWindowRef
, bool inActivate
)
568 // bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
569 // if ( inActivate != isHightlited )
572 SetPortWindowPort( inWindowRef
) ;
573 HiliteWindow( inWindowRef
, inActivate
) ;
574 ControlHandle control
= NULL
;
575 ::GetRootControl( inWindowRef
, & control
) ;
579 UMAActivateControl( control
) ;
581 UMADeactivateControl( control
) ;
586 OSStatus
UMADrawThemePlacard( const Rect
*inRect
, ThemeDrawState inState
)
588 return ::DrawThemePlacard( inRect
, inState
) ;
591 static OSStatus helpMenuStatus
= noErr
;
592 static MenuRef helpMenuHandle
= NULL
;
593 static MenuItemIndex firstCustomItemIndex
= 0 ;
595 OSStatus
UMAGetHelpMenu(
596 MenuRef
* outHelpMenu
,
597 MenuItemIndex
* outFirstCustomItemIndex
)
600 return HMGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
) ;
602 if ( helpMenuHandle
== NULL
)
604 helpMenuStatus
= HMGetHelpMenuHandle( &helpMenuHandle
) ;
605 if ( helpMenuStatus
== noErr
)
607 firstCustomItemIndex
= CountMenuItems( helpMenuHandle
) + 1 ;
610 if ( outFirstCustomItemIndex
)
612 *outFirstCustomItemIndex
= firstCustomItemIndex
;
614 *outHelpMenu
= helpMenuHandle
;
615 return helpMenuStatus
;
619 wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport
)
625 wxMacPortStateHelper::wxMacPortStateHelper()
630 void wxMacPortStateHelper::Setup( GrafPtr newport
)
632 GetPort( &m_oldPort
) ;
634 wxASSERT_MSG( m_clip
== NULL
, "Cannot call setup twice" ) ;
637 m_textFont
= GetPortTextFont( (CGrafPtr
) newport
);
638 m_textSize
= GetPortTextSize( (CGrafPtr
) newport
);
639 m_textStyle
= GetPortTextFace( (CGrafPtr
) newport
);
640 m_textMode
= GetPortTextMode( (CGrafPtr
) newport
);
641 GetThemeDrawingState( &m_drawingState
) ;
642 m_currentPort
= newport
;
644 void wxMacPortStateHelper::Clear()
648 DisposeRgn( m_clip
) ;
649 DisposeThemeDrawingState( m_drawingState
) ;
654 wxMacPortStateHelper::~wxMacPortStateHelper()
658 SetPort( m_currentPort
) ;
660 DisposeRgn( m_clip
) ;
661 TextFont( m_textFont
);
662 TextSize( m_textSize
);
663 TextFace( m_textStyle
);
664 TextMode( m_textMode
);
665 SetThemeDrawingState( m_drawingState
, true ) ;
666 SetPort( m_oldPort
) ;