1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/uma.cpp
3 // Purpose: UMA support
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: The wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/mac/uma.h"
18 #include "wx/toplevel.h"
21 #include "wx/mac/uma.h"
23 static SInt32 sUMASystemVersion
= 0 ;
25 long UMAGetSystemVersion()
27 if ( sUMASystemVersion
== 0 )
29 verify_noerr(Gestalt(gestaltSystemVersion
, &sUMASystemVersion
));
31 return sUMASystemVersion
;
34 void UMAInitToolbox( UInt16
WXUNUSED(inMoreMastersCalls
),
35 bool WXUNUSED(isEmbedded
) )
37 #if 0 // ndef __LP64__
44 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
45 GetFNum( fontName
, &fontId
);
47 TXNMacOSPreferredFontDescription fontDescriptions
[] =
49 { fontId
, (fontSize
<< 16) , kTXNDefaultFontStyle
, kTXNSystemDefaultEncoding
}
51 int noOfFontDescriptions
= sizeof( fontDescriptions
) / sizeof(TXNMacOSPreferredFontDescription
) ;
53 OptionBits options
= 0 ;
55 TXNInitTextension( fontDescriptions
, noOfFontDescriptions
, options
);
61 long UMAGetProcessMode()
64 ProcessInfoRec processinfo
;
65 ProcessSerialNumber procno
;
67 procno
.highLongOfPSN
= 0 ;
68 procno
.lowLongOfPSN
= kCurrentProcess
;
69 processinfo
.processInfoLength
= sizeof(ProcessInfoRec
);
70 processinfo
.processName
= NULL
;
72 processinfo
.processAppSpec
= NULL
;
75 err
= ::GetProcessInformation( &procno
, &processinfo
) ;
76 wxASSERT( err
== noErr
) ;
78 return processinfo
.processMode
;
81 bool UMAGetProcessModeDoesActivateOnFGSwitch()
83 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch
;
88 #if wxMAC_USE_COCOA == 0
90 MenuRef
UMANewMenu( SInt16 id
, const wxString
& title
, wxFontEncoding encoding
)
92 wxString str
= wxStripMenuCodes( title
) ;
95 CreateNewMenu( id
, 0 , &menu
) ;
96 SetMenuTitleWithCFString( menu
, wxMacCFStringHolder(str
, encoding
) ) ;
101 void UMASetMenuTitle( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
)
103 wxString str
= wxStripMenuCodes( title
) ;
105 SetMenuTitleWithCFString( menu
, wxMacCFStringHolder(str
, encoding
) ) ;
108 void UMASetMenuItemText( MenuRef menu
, MenuItemIndex item
, const wxString
& title
, wxFontEncoding encoding
)
110 // we don't strip the accels here anymore, must be done before
111 wxString str
= title
;
113 SetMenuItemTextWithCFString( menu
, item
, wxMacCFStringHolder(str
, encoding
) ) ;
116 void UMAEnableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
, bool enable
)
119 EnableMenuItem( inMenu
, inItem
) ;
121 DisableMenuItem( inMenu
, inItem
) ;
124 void UMAAppendSubMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, SInt16 id
)
126 AppendMenuItemTextWithCFString( menu
,
127 CFSTR("A"), 0, 0,NULL
);
128 UMASetMenuItemText( menu
, (SInt16
) ::CountMenuItems(menu
), title
, encoding
);
129 SetMenuItemHierarchicalID( menu
, CountMenuItems( menu
) , id
) ;
132 void UMAInsertSubMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, MenuItemIndex item
, SInt16 id
)
134 InsertMenuItemTextWithCFString( menu
,
135 CFSTR("A"), item
, 0, 0);
137 UMASetMenuItemText( menu
, item
+1, title
, encoding
);
138 SetMenuItemHierarchicalID( menu
, item
+1 , id
) ;
141 void UMASetMenuItemShortcut( MenuRef menu
, MenuItemIndex item
, wxAcceleratorEntry
*entry
)
146 UInt8 modifiers
= 0 ;
147 SInt16 key
= entry
->GetKeyCode() ;
150 bool explicitCommandKey
= (entry
->GetFlags() & wxACCEL_CTRL
);
152 if (entry
->GetFlags() & wxACCEL_ALT
)
153 modifiers
|= kMenuOptionModifier
;
155 if (entry
->GetFlags() & wxACCEL_SHIFT
)
156 modifiers
|= kMenuShiftModifier
;
159 SInt16 macKey
= key
;
160 if ( key
>= WXK_F1
&& key
<= WXK_F15
)
162 if ( !explicitCommandKey
)
163 modifiers
|= kMenuNoCommandModifier
;
165 // for some reasons this must be 0 right now
166 // everything else leads to just the first function key item
167 // to be selected. Thanks to Ryan Wilcox for finding out.
169 glyph
= kMenuF1Glyph
+ ( key
- WXK_F1
) ;
170 if ( key
>= WXK_F13
)
178 macKey
= kBackspaceCharCode
;
179 glyph
= kMenuDeleteLeftGlyph
;
183 macKey
= kTabCharCode
;
184 glyph
= kMenuTabRightGlyph
;
187 case kEnterCharCode
:
188 macKey
= kEnterCharCode
;
189 glyph
= kMenuEnterGlyph
;
193 macKey
= kReturnCharCode
;
194 glyph
= kMenuReturnGlyph
;
198 macKey
= kEscapeCharCode
;
199 glyph
= kMenuEscapeGlyph
;
204 glyph
= kMenuSpaceGlyph
;
208 macKey
= kDeleteCharCode
;
209 glyph
= kMenuDeleteRightGlyph
;
213 macKey
= kClearCharCode
;
214 glyph
= kMenuClearGlyph
;
218 macKey
= kPageUpCharCode
;
219 glyph
= kMenuPageUpGlyph
;
223 macKey
= kPageDownCharCode
;
224 glyph
= kMenuPageDownGlyph
;
228 macKey
= kLeftArrowCharCode
;
229 glyph
= kMenuLeftArrowGlyph
;
233 macKey
= kUpArrowCharCode
;
234 glyph
= kMenuUpArrowGlyph
;
238 macKey
= kRightArrowCharCode
;
239 glyph
= kMenuRightArrowGlyph
;
243 macKey
= kDownArrowCharCode
;
244 glyph
= kMenuDownArrowGlyph
;
248 macKey
= kHomeCharCode
;
249 glyph
= kMenuNorthwestArrowGlyph
;
253 macKey
= kEndCharCode
;
254 glyph
= kMenuSoutheastArrowGlyph
;
257 macKey
= toupper( key
) ;
261 // we now allow non command key shortcuts
262 // remove in case this gives problems
263 if ( !explicitCommandKey
)
264 modifiers
|= kMenuNoCommandModifier
;
267 // 1d and 1e have special meaning to SetItemCmd, so
268 // do not use for these character codes.
269 if (key
!= WXK_UP
&& key
!= WXK_RIGHT
&& key
!= WXK_DOWN
&& key
!= WXK_LEFT
)
270 SetItemCmd( menu
, item
, macKey
);
272 SetMenuItemModifiers( menu
, item
, modifiers
) ;
275 SetMenuItemKeyGlyph( menu
, item
, glyph
) ;
279 void UMAAppendMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, wxAcceleratorEntry
*entry
)
281 AppendMenuItemTextWithCFString( menu
,
282 CFSTR("A"), 0, 0,NULL
);
283 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
284 ChangeMenuItemAttributes( menu
, ::CountMenuItems(menu
), kMenuItemAttrIgnoreMeta
, 0 ) ;
285 UMASetMenuItemText(menu
, (SInt16
) ::CountMenuItems(menu
), title
, encoding
);
286 UMASetMenuItemShortcut( menu
, (SInt16
) ::CountMenuItems(menu
), entry
) ;
289 void UMAInsertMenuItem( MenuRef menu
, const wxString
& title
, wxFontEncoding encoding
, MenuItemIndex item
, wxAcceleratorEntry
*entry
)
291 InsertMenuItemTextWithCFString( menu
,
292 CFSTR("A"), item
, 0, 0);
294 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
295 ChangeMenuItemAttributes( menu
, item
+1, kMenuItemAttrIgnoreMeta
, 0 ) ;
296 UMASetMenuItemText(menu
, item
+1 , title
, encoding
);
297 UMASetMenuItemShortcut( menu
, item
+1 , entry
) ;
302 #if wxMAC_USE_COCOA == 0
304 static OSStatus
UMAGetHelpMenu(
305 MenuRef
* outHelpMenu
,
306 MenuItemIndex
* outFirstCustomItemIndex
,
307 bool allowHelpMenuCreation
);
309 static OSStatus
UMAGetHelpMenu(
310 MenuRef
* outHelpMenu
,
311 MenuItemIndex
* outFirstCustomItemIndex
,
312 bool allowHelpMenuCreation
)
314 static bool s_createdHelpMenu
= false ;
316 if ( !s_createdHelpMenu
&& !allowHelpMenuCreation
)
321 OSStatus status
= HMGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
) ;
322 s_createdHelpMenu
= ( status
== noErr
) ;
326 OSStatus
UMAGetHelpMenu(
327 MenuRef
* outHelpMenu
,
328 MenuItemIndex
* outFirstCustomItemIndex
)
330 return UMAGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
, true );
333 OSStatus
UMAGetHelpMenuDontCreate(
334 MenuRef
* outHelpMenu
,
335 MenuItemIndex
* outFirstCustomItemIndex
)
337 return UMAGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
, false );
344 #if wxMAC_USE_QUICKDRAW
346 void UMAActivateControl( ControlRef inControl
)
348 ::ActivateControl( inControl
) ;
351 void UMADeactivateControl( ControlRef inControl
)
353 ::DeactivateControl( inControl
) ;
358 void UMAHighlightAndActivateWindow( WindowRef inWindowRef
, bool inActivate
)
363 // bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
364 // if ( inActivate != isHighlighted )
368 SetPortWindowPort( inWindowRef
) ;
370 HiliteWindow( inWindowRef
, inActivate
) ;
371 ControlRef control
= NULL
;
372 ::GetRootControl( inWindowRef
, &control
) ;
376 UMAActivateControl( control
) ;
378 UMADeactivateControl( control
) ;
387 Rect
* UMAGetControlBoundsInWindowCoords( ControlRef theControl
, Rect
*bounds
)
389 GetControlBounds( theControl
, bounds
) ;
391 WindowRef tlwref
= GetControlOwner( theControl
) ;
393 wxTopLevelWindowMac
* tlwwx
= wxFindWinFromMacWindow( tlwref
) ;
396 ControlRef rootControl
= tlwwx
->GetPeer()->GetControlRef() ;
397 HIPoint hiPoint
= CGPointMake( 0 , 0 ) ;
398 HIViewConvertPoint( &hiPoint
, HIViewGetSuperview(theControl
) , rootControl
) ;
399 OffsetRect( bounds
, (short) hiPoint
.x
, (short) hiPoint
.y
) ;
407 size_t UMAPutBytesCFRefCallback( void *info
, const void *bytes
, size_t count
)
409 CFMutableDataRef data
= (CFMutableDataRef
) info
;
412 CFDataAppendBytes( data
, (const UInt8
*) bytes
, count
);
417 void UMAReleaseCFDataProviderCallback(void *info
,
418 const void *WXUNUSED(data
),
419 size_t WXUNUSED(count
))
422 CFRelease( (CFDataRef
) info
);
425 void UMAReleaseCFDataConsumerCallback( void *info
)
428 CFRelease( (CFDataRef
) info
);
431 CGDataProviderRef
UMACGDataProviderCreateWithCFData( CFDataRef data
)
436 return CGDataProviderCreateWithCFData( data
);
439 CGDataConsumerRef
UMACGDataConsumerCreateWithCFData( CFMutableDataRef data
)
444 return CGDataConsumerCreateWithCFData( data
);