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
19 static bool sUMAHasAppearance
= false ;
20 static long sUMAAppearanceVersion
= 0 ;
21 static bool sUMAHasAquaLayout
= false ;
22 static bool sUMASystemInitialized
= false ;
24 extern int gAGABackgroundColor
;
25 bool UMAHasAppearance() { return sUMAHasAppearance
; }
26 long UMAGetAppearanceVersion() { return sUMAAppearanceVersion
; }
28 static bool sUMAHasWindowManager
= false ;
29 static long sUMAWindowManagerAttr
= 0 ;
31 bool UMAHasWindowManager() { return sUMAHasWindowManager
; }
32 long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr
; }
33 bool UMAHasAquaLayout() { return sUMAHasAquaLayout
; }
34 bool UMASystemIsInitialized() { return sUMASystemInitialized
; }
36 void UMACleanupToolbox()
38 if ( sUMAHasAppearance
)
40 UnregisterAppearanceClient() ;
42 if ( NavServicesAvailable() )
47 TXNTerminateTextension( ) ;
50 void UMAInitToolbox( UInt16 inMoreMastersCalls
)
54 for (long i
= 1; i
<= inMoreMastersCalls
; i
++)
57 ::InitGraf(&qd
.thePort
);
62 ::FlushEvents(everyEvent
, 0);
65 PurgeSpace(&total
, &contig
);
71 if ( Gestalt( gestaltAppearanceAttr
, &theAppearance
) == noErr
)
73 sUMAHasAppearance
= true ;
74 RegisterAppearanceClient();
75 if ( Gestalt( gestaltAppearanceVersion
, &theAppearance
) == noErr
)
77 sUMAAppearanceVersion
= theAppearance
;
81 sUMAAppearanceVersion
= 0x0100 ;
84 if ( Gestalt( gestaltWindowMgrAttr
, &sUMAWindowManagerAttr
) == noErr
)
86 sUMAHasWindowManager
= sUMAWindowManagerAttr
& gestaltWindowMgrPresent
;
91 // Call currently implicitely done : InitFloatingWindows() ;
93 if ( sUMAHasWindowManager
)
94 InitFloatingWindows() ;
100 if ( NavServicesAvailable() )
106 TXNMacOSPreferredFontDescription defaults
;
107 defaults
.fontID
= kFontIDGeneva
;
108 defaults
.pointSize
= (10 << 16) ;
109 defaults
.fontStyle
= kTXNDefaultFontStyle
;
110 defaults
.encoding
= kTXNSystemDefaultEncoding
;
111 TXNInitTextension(&defaults
, 1, (kTXNAlwaysUseQuickDrawTextMask
| kTXNWantMoviesMask
| kTXNWantSoundMask
| kTXNWantGraphicsMask
));
114 Gestalt( gestaltMenuMgrAttr
, &menuMgrAttr
) ;
115 if ( menuMgrAttr
& gestaltMenuMgrAquaLayoutMask
)
116 sUMAHasAquaLayout
= true ;
117 sUMASystemInitialized
= true ;
121 long UMAGetProcessMode()
124 ProcessInfoRec processinfo
;
125 ProcessSerialNumber procno
;
127 procno
.highLongOfPSN
= NULL
;
128 procno
.lowLongOfPSN
= kCurrentProcess
;
129 processinfo
.processInfoLength
= sizeof(ProcessInfoRec
);
130 processinfo
.processName
= NULL
;
131 processinfo
.processAppSpec
= NULL
;
133 err
= ::GetProcessInformation( &procno
, &processinfo
) ;
134 wxASSERT( err
== noErr
) ;
135 return processinfo
.processMode
;
138 bool UMAGetProcessModeDoesActivateOnFGSwitch()
140 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch
;
145 void UMASetMenuTitle( MenuRef menu
, StringPtr title
)
149 long size = GetHandleSize( (Handle) menu ) ;
150 const long headersize = 14 ;
151 int oldlen = (**menu).menuData[0] + 1;
152 int newlen = title[0] + 1 ;
154 if ( oldlen < newlen )
156 // enlarge before adjusting
157 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) );
160 if ( oldlen != newlen )
161 memmove( (char*) (**menu).menuData + newlen , (char*) (**menu).menuData + oldlen , size - headersize - oldlen ) ;
163 memcpy( (char*) (**menu).menuData , title , newlen ) ;
164 if ( oldlen > newlen )
167 SetHandleSize( (Handle) menu , size + (newlen - oldlen ) ) ;
171 SetMenuTitle( menu
, title
) ;
175 UInt32
UMAMenuEvent( EventRecord
*inEvent
)
177 return MenuEvent( inEvent
) ;
180 void UMAEnableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
182 EnableMenuItem( inMenu
, inItem
) ;
185 void UMADisableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
)
187 DisableMenuItem( inMenu
, inItem
) ;
190 void UMAAppendSubMenuItem( MenuRef menu
, StringPtr l
, SInt16 id
)
193 memcpy( label
, l
, l
[0]+1 ) ;
194 // hardcoded adding of the submenu combination for mac
196 int theEnd
= label
[0] + 1;
198 theEnd
= 251; // mac allows only 255 characters
199 label
[theEnd
++] = '/';
200 label
[theEnd
++] = hMenuCmd
;
201 label
[theEnd
++] = '!';
202 label
[theEnd
++] = id
;
203 label
[theEnd
] = 0x00;
205 MacAppendMenu(menu
, label
);
208 void UMAInsertSubMenuItem( MenuRef menu
, StringPtr l
, MenuItemIndex item
, SInt16 id
)
211 memcpy( label
, l
, l
[0]+1 ) ;
212 // hardcoded adding of the submenu combination for mac
214 int theEnd
= label
[0] + 1;
216 theEnd
= 251; // mac allows only 255 characters
217 label
[theEnd
++] = '/';
218 label
[theEnd
++] = hMenuCmd
;
219 label
[theEnd
++] = '!';
220 label
[theEnd
++] = id
;
221 label
[theEnd
] = 0x00;
223 MacInsertMenuItem(menu
, label
, item
);
226 void UMAAppendMenuItem( MenuRef menu
, StringPtr l
, SInt16 key
, UInt8 modifiers
)
229 memcpy( label
, l
, l
[0]+1 ) ;
234 label
[++pos
] = toupper( key
);
237 MacAppendMenu( menu
, label
) ;
240 void UMAInsertMenuItem( MenuRef menu
, StringPtr l
, MenuItemIndex item
, SInt16 key
, UInt8 modifiers
)
243 memcpy( label
, l
, l
[0]+1 ) ;
248 label
[++pos
] = toupper( key
);
251 MacInsertMenuItem( menu
, label
, item
) ;
256 int gPrOpenCounter
= 0 ;
258 #if TARGET_CARBON && PM_USE_SESSION_APIS
259 OSStatus
UMAPrOpen(PMPrintSession
*macPrintSession
)
267 if ( gPrOpenCounter
== 1 )
271 wxASSERT( err
== noErr
) ;
275 OSStatus err
= noErr
;
277 if ( gPrOpenCounter
== 1 )
279 #if PM_USE_SESSION_APIS
280 err
= PMCreateSession(macPrintSession
) ;
284 wxASSERT( err
== noErr
) ;
290 #if TARGET_CARBON && PM_USE_SESSION_APIS
291 OSStatus
UMAPrClose(PMPrintSession
*macPrintSession
)
293 OSStatus
UMAPrClose()
298 wxASSERT( gPrOpenCounter
>= 1 ) ;
299 if ( gPrOpenCounter
== 1 )
303 wxASSERT( err
== noErr
) ;
308 OSStatus err
= noErr
;
309 wxASSERT( gPrOpenCounter
>= 1 ) ;
310 if ( gPrOpenCounter
== 1 )
312 #if PM_USE_SESSION_APIS
313 err
= PMRelease(*macPrintSession
) ;
314 *macPrintSession
= kPMNoReference
;
326 pascal QDGlobalsPtr
GetQDGlobalsPtr (void) ;
327 pascal QDGlobalsPtr
GetQDGlobalsPtr (void)
329 return QDGlobalsPtr (* (Ptr
*) LMGetCurrentA5 ( ) - 0xCA);
334 void UMAShowWatchCursor()
338 CursHandle watchFob
= GetCursor (watchCursor
);
345 // Cursor preservedArrow;
346 // GetQDGlobalsArrow (&preservedArrow);
347 // SetQDGlobalsArrow (*watchFob);
349 // SetQDGlobalsArrow (&preservedArrow);
350 SetCursor (*watchFob
);
352 SetCursor (*watchFob
);
357 void UMAShowArrowCursor()
361 SetCursor (GetQDGlobalsArrow (&arrow
));
363 SetCursor (&(qd
.arrow
));
369 GrafPtr
UMAGetWindowPort( WindowRef inWindowRef
)
371 wxASSERT( inWindowRef
!= NULL
) ;
373 return GetWindowPort( inWindowRef
) ;
375 return (GrafPtr
) inWindowRef
;
379 void UMADisposeWindow( WindowRef inWindowRef
)
381 wxASSERT( inWindowRef
!= NULL
) ;
382 DisposeWindow( inWindowRef
) ;
385 void UMASetWTitleC( WindowRef inWindowRef
, const char *title
)
388 strncpy( (char*)ptitle
, title
, 96 ) ;
391 c2pstrcpy( ptitle
, (char *)ptitle
) ;
393 c2pstr( (char*)ptitle
) ;
395 SetWTitle( inWindowRef
, ptitle
) ;
398 void UMAGetWTitleC( WindowRef inWindowRef
, char *title
)
400 GetWTitle( inWindowRef
, (unsigned char*)title
) ;
402 p2cstrcpy( title
, (unsigned char *)title
) ;
404 p2cstr( (unsigned char*)title
) ;
408 // appearance additions
410 void UMAActivateControl( ControlHandle inControl
)
412 // we have to add the control after again to the update rgn
413 // otherwise updates get lost
414 if ( !IsControlActive( inControl
) )
416 bool visible
= IsControlVisible( inControl
) ;
418 SetControlVisibility( inControl
, false , false ) ;
419 ::ActivateControl( inControl
) ;
421 SetControlVisibility( inControl
, true , false ) ;
423 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
428 void UMADrawControl( ControlHandle inControl
)
430 WindowRef theWindow
= GetControlOwner(inControl
) ;
431 RgnHandle updateRgn
= NewRgn() ;
432 GetWindowUpdateRgn( theWindow
, updateRgn
) ;
433 Point zero
= { 0 , 0 } ;
434 LocalToGlobal( &zero
) ;
435 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
436 ::DrawControlInCurrentPort( inControl
) ;
437 InvalWindowRgn( theWindow
, updateRgn
) ;
438 DisposeRgn( updateRgn
) ;
441 void UMAMoveControl( ControlHandle inControl
, short x
, short y
)
443 bool visible
= IsControlVisible( inControl
) ;
445 SetControlVisibility( inControl
, false , false ) ;
447 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
449 ::MoveControl( inControl
, x
, y
) ;
451 SetControlVisibility( inControl
, true , false ) ;
453 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
457 void UMASizeControl( ControlHandle inControl
, short x
, short y
)
459 bool visible
= IsControlVisible( inControl
) ;
461 SetControlVisibility( inControl
, false , false ) ;
463 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
465 ::SizeControl( inControl
, x
, y
) ;
467 SetControlVisibility( inControl
, true , false ) ;
469 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
473 void UMADeactivateControl( ControlHandle inControl
)
475 // we have to add the control after again to the update rgn
476 // otherwise updates get lost
477 bool visible
= IsControlVisible( inControl
) ;
479 SetControlVisibility( inControl
, false , false ) ;
480 ::DeactivateControl( inControl
) ;
482 SetControlVisibility( inControl
, true , false ) ;
484 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
487 // shows the control and adds the region to the update region
488 void UMAShowControl (ControlHandle inControl
)
490 SetControlVisibility( inControl
, true , false ) ;
492 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
495 // shows the control and adds the region to the update region
496 void UMAHideControl (ControlHandle inControl
)
498 SetControlVisibility( inControl
, false , false ) ;
500 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
503 OSErr
UMASetKeyboardFocus (WindowPtr inWindow
,
504 ControlHandle inControl
,
505 ControlFocusPart inPart
)
511 SetPortWindowPort( inWindow
) ;
513 err
= SetKeyboardFocus( inWindow
, inControl
, inPart
) ;
522 void UMAUpdateControls( WindowPtr inWindow
, RgnHandle inRgn
)
524 RgnHandle updateRgn
= NewRgn() ;
525 GetWindowUpdateRgn( inWindow
, updateRgn
) ;
527 Point zero
= { 0 , 0 } ;
528 LocalToGlobal( &zero
) ;
529 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
531 UpdateControls( inWindow
, inRgn
) ;
532 InvalWindowRgn( inWindow
, updateRgn
) ;
533 DisposeRgn( updateRgn
) ;
537 bool UMAIsWindowFloating( WindowRef inWindow
)
541 GetWindowClass( inWindow
, &cl
) ;
542 return cl
== kFloatingWindowClass
;
545 bool UMAIsWindowModal( WindowRef inWindow
)
549 GetWindowClass( inWindow
, &cl
) ;
550 return cl
< kFloatingWindowClass
;
555 void UMAHighlightAndActivateWindow( WindowRef inWindowRef
, bool inActivate
)
559 // bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
560 // if ( inActivate != isHightlited )
563 SetPortWindowPort( inWindowRef
) ;
564 HiliteWindow( inWindowRef
, inActivate
) ;
565 ControlHandle control
= NULL
;
566 ::GetRootControl( inWindowRef
, & control
) ;
570 UMAActivateControl( control
) ;
572 UMADeactivateControl( control
) ;
577 OSStatus
UMADrawThemePlacard( const Rect
*inRect
, ThemeDrawState inState
)
579 return ::DrawThemePlacard( inRect
, inState
) ;
582 static OSStatus helpMenuStatus
= noErr
;
583 static MenuRef helpMenuHandle
= NULL
;
584 static MenuItemIndex firstCustomItemIndex
= 0 ;
586 OSStatus
UMAGetHelpMenu(
587 MenuRef
* outHelpMenu
,
588 MenuItemIndex
* outFirstCustomItemIndex
)
591 return HMGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
) ;
593 if ( helpMenuHandle
== NULL
)
595 helpMenuStatus
= HMGetHelpMenuHandle( &helpMenuHandle
) ;
596 if ( helpMenuStatus
== noErr
)
598 firstCustomItemIndex
= CountMenuItems( helpMenuHandle
) + 1 ;
601 if ( outFirstCustomItemIndex
)
603 *outFirstCustomItemIndex
= firstCustomItemIndex
;
605 *outHelpMenu
= helpMenuHandle
;
606 return helpMenuStatus
;
610 wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport
)
616 wxMacPortStateHelper::wxMacPortStateHelper()
621 void wxMacPortStateHelper::Setup( GrafPtr newport
)
623 GetPort( &m_oldPort
) ;
625 wxASSERT_MSG( m_clip
== NULL
, "Cannot call setup twice" ) ;
628 m_textFont
= GetPortTextFont( (CGrafPtr
) newport
);
629 m_textSize
= GetPortTextSize( (CGrafPtr
) newport
);
630 m_textStyle
= GetPortTextFace( (CGrafPtr
) newport
);
631 m_textMode
= GetPortTextMode( (CGrafPtr
) newport
);
632 GetThemeDrawingState( &m_drawingState
) ;
633 m_currentPort
= newport
;
635 void wxMacPortStateHelper::Clear()
639 DisposeRgn( m_clip
) ;
640 DisposeThemeDrawingState( m_drawingState
) ;
645 wxMacPortStateHelper::~wxMacPortStateHelper()
649 SetPort( m_currentPort
) ;
651 DisposeRgn( m_clip
) ;
652 TextFont( m_textFont
);
653 TextSize( m_textSize
);
654 TextFace( m_textStyle
);
655 TextMode( m_textMode
);
656 SetThemeDrawingState( m_drawingState
, true ) ;
657 SetPort( m_oldPort
) ;