]>
Commit | Line | Data |
---|---|---|
8cf73271 | 1 | ///////////////////////////////////////////////////////////////////////////// |
fb5246be | 2 | // Name: wx/mac/carbon/private.h |
8cf73271 | 3 | // Purpose: Private declarations: as this header is only included by |
77ffb593 | 4 | // wxWidgets itself, it may contain identifiers which don't start |
8cf73271 SC |
5 | // with "wx". |
6 | // Author: Stefan Csomor | |
7 | // Modified by: | |
8 | // Created: 1998-01-01 | |
9 | // RCS-ID: $Id$ | |
10 | // Copyright: (c) Stefan Csomor | |
65571936 | 11 | // Licence: wxWindows licence |
8cf73271 SC |
12 | ///////////////////////////////////////////////////////////////////////////// |
13 | ||
14 | #ifndef _WX_PRIVATE_H_ | |
15 | #define _WX_PRIVATE_H_ | |
16 | ||
17 | #include "wx/defs.h" | |
18 | #include "wx/app.h" | |
19 | ||
20 | #ifdef __DARWIN__ | |
21 | # include <Carbon/Carbon.h> | |
22 | #else | |
4f305456 | 23 | # include <Debugging.h> |
8cf73271 SC |
24 | # include <Quickdraw.h> |
25 | # include <Appearance.h> | |
26 | # include <Folders.h> | |
27 | # include <Controls.h> | |
28 | # include <ControlDefinitions.h> | |
29 | # include <LowMem.h> | |
30 | # include <Gestalt.h> | |
d9af087c | 31 | # include <FixMath.h> |
a6140a4c | 32 | # include <CoreServices.h> |
8cf73271 SC |
33 | #endif |
34 | ||
a6140a4c | 35 | #if UNIVERSAL_INTERFACES_VERSION < 0x0342 |
8cf73271 SC |
36 | #error "please update to Apple's lastest universal headers from http://developer.apple.com/sdk/" |
37 | #endif | |
38 | ||
c3a404b0 SC |
39 | #ifndef MAC_OS_X_VERSION_10_3 |
40 | #define MAC_OS_X_VERSION_10_3 1030 | |
41 | #endif | |
42 | ||
ddb08e02 SC |
43 | #ifndef MAC_OS_X_VERSION_10_4 |
44 | #define MAC_OS_X_VERSION_10_4 1040 | |
45 | #endif | |
46 | ||
5185263f DE |
47 | #ifdef __WXMAC_CARBON__ |
48 | #include "wx/mac/corefoundation/cfstring.h" | |
49 | #endif | |
50 | ||
3d639707 SC |
51 | #ifndef FixedToInt |
52 | // as macro in FixMath.h for 10.3 | |
53 | inline Fixed IntToFixed( int inInt ) | |
54 | { | |
55 | return (((SInt32) inInt) << 16); | |
56 | } | |
57 | ||
58 | inline int FixedToInt( Fixed inFixed ) | |
59 | { | |
60 | return (((SInt32) inFixed) >> 16); | |
61 | } | |
62 | #endif | |
63 | ||
8cf73271 SC |
64 | #if wxUSE_GUI |
65 | ||
20b69855 | 66 | #include "wx/dc.h" |
8cf73271 | 67 | #include "wx/window.h" |
285b5ce0 | 68 | #include "wx/toplevel.h" |
8cf73271 | 69 | |
fb5246be | 70 | class wxMacPortStateHelper |
8cf73271 SC |
71 | { |
72 | DECLARE_NO_COPY_CLASS(wxMacPortStateHelper) | |
fb5246be | 73 | |
8cf73271 | 74 | public: |
fb5246be | 75 | wxMacPortStateHelper( GrafPtr newport) ; |
8cf73271 SC |
76 | wxMacPortStateHelper() ; |
77 | ~wxMacPortStateHelper() ; | |
78 | ||
79 | void Setup( GrafPtr newport ) ; | |
80 | void Clear() ; | |
81 | bool IsCleared() { return m_clip == NULL ; } | |
82 | GrafPtr GetCurrentPort() { return m_currentPort ; } | |
83 | ||
84 | private: | |
85 | GrafPtr m_currentPort ; | |
86 | GrafPtr m_oldPort ; | |
87 | RgnHandle m_clip ; | |
88 | ThemeDrawingState m_drawingState ; | |
89 | short m_textFont ; | |
90 | short m_textSize ; | |
91 | short m_textStyle ; | |
92 | short m_textMode ; | |
93 | } ; | |
94 | ||
4f305456 SC |
95 | class WXDLLEXPORT wxMacPortSaver |
96 | { | |
97 | DECLARE_NO_COPY_CLASS(wxMacPortSaver) | |
fb5246be | 98 | |
4f305456 | 99 | public: |
54ce9ebb JS |
100 | wxMacPortSaver( GrafPtr port ); |
101 | ~wxMacPortSaver(); | |
4f305456 SC |
102 | private : |
103 | GrafPtr m_port ; | |
104 | } ; | |
105 | ||
8cf73271 SC |
106 | class WXDLLEXPORT wxMacPortSetter |
107 | { | |
108 | DECLARE_NO_COPY_CLASS(wxMacPortSetter) | |
fb5246be | 109 | |
8cf73271 SC |
110 | public: |
111 | wxMacPortSetter( const wxDC* dc ) ; | |
112 | ~wxMacPortSetter() ; | |
113 | private: | |
114 | wxMacPortStateHelper m_ph ; | |
115 | const wxDC* m_dc ; | |
116 | } ; | |
117 | ||
4f305456 SC |
118 | /* |
119 | Clips to the visible region of a control within the current port | |
120 | */ | |
fb5246be | 121 | |
4f305456 | 122 | class WXDLLEXPORT wxMacWindowClipper : public wxMacPortSaver |
8cf73271 SC |
123 | { |
124 | DECLARE_NO_COPY_CLASS(wxMacWindowClipper) | |
fb5246be | 125 | |
8cf73271 SC |
126 | public: |
127 | wxMacWindowClipper( const wxWindow* win ) ; | |
128 | ~wxMacWindowClipper() ; | |
129 | private: | |
01299d56 | 130 | GrafPtr m_newPort ; |
8cf73271 SC |
131 | RgnHandle m_formerClip ; |
132 | RgnHandle m_newClip ; | |
133 | } ; | |
134 | ||
01299d56 SC |
135 | class WXDLLEXPORT wxMacWindowStateSaver : public wxMacWindowClipper |
136 | { | |
137 | DECLARE_NO_COPY_CLASS(wxMacWindowStateSaver) | |
fb5246be | 138 | |
01299d56 SC |
139 | public: |
140 | wxMacWindowStateSaver( const wxWindow* win ) ; | |
141 | ~wxMacWindowStateSaver() ; | |
142 | private: | |
143 | GrafPtr m_newPort ; | |
144 | ThemeDrawingState m_themeDrawingState ; | |
145 | } ; | |
146 | ||
ddb08e02 | 147 | #if wxMAC_USE_CORE_GRAPHICS |
fb5246be | 148 | class WXDLLEXPORT wxMacCGContextStateSaver |
ddb08e02 SC |
149 | { |
150 | DECLARE_NO_COPY_CLASS(wxMacCGContextStateSaver) | |
fb5246be | 151 | |
ddb08e02 | 152 | public: |
fb5246be | 153 | wxMacCGContextStateSaver( CGContextRef cg ) |
ddb08e02 SC |
154 | { |
155 | m_cg = cg ; | |
156 | CGContextSaveGState( cg ) ; | |
157 | } | |
fb5246be | 158 | ~wxMacCGContextStateSaver() |
ddb08e02 SC |
159 | { |
160 | CGContextRestoreGState( m_cg ) ; | |
161 | } | |
162 | private: | |
163 | CGContextRef m_cg ; | |
164 | } ; | |
165 | ||
166 | #endif | |
4f305456 | 167 | /* |
8cf73271 SC |
168 | class wxMacDrawingHelper |
169 | { | |
170 | DECLARE_NO_COPY_CLASS(wxMacDrawingHelper) | |
fb5246be | 171 | |
8cf73271 SC |
172 | public: |
173 | wxMacDrawingHelper( wxWindowMac * theWindow , bool clientArea = false ) ; | |
174 | ~wxMacDrawingHelper() ; | |
175 | bool Ok() { return m_ok ; } | |
176 | void LocalToWindow( Rect *rect) { OffsetRect( rect , m_origin.h , m_origin.v ) ; } | |
177 | void LocalToWindow( Point *pt ) { AddPt( m_origin , pt ) ; } | |
178 | void LocalToWindow( RgnHandle rgn ) { OffsetRgn( rgn , m_origin.h , m_origin.v ) ; } | |
179 | const Point& GetOrigin() { return m_origin ; } | |
180 | private: | |
181 | Point m_origin ; | |
182 | GrafPtr m_formerPort ; | |
183 | GrafPtr m_currentPort ; | |
184 | PenState m_savedPenState ; | |
185 | bool m_ok ; | |
186 | } ; | |
4f305456 | 187 | */ |
8cf73271 SC |
188 | |
189 | // app.h | |
190 | bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec) ; | |
191 | ||
192 | #endif // wxUSE_GUI | |
193 | ||
194 | // filefn.h | |
195 | WXDLLEXPORT wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) ; | |
a2b77260 | 196 | WXDLLEXPORT void wxMacFilename2FSSpec( const wxString &path , FSSpec *spec ) ; |
8cf73271 SC |
197 | |
198 | // utils.h | |
199 | WXDLLEXPORT wxString wxMacFindFolder(short vRefNum, | |
200 | OSType folderType, | |
201 | Boolean createFolder); | |
202 | ||
4f305456 SC |
203 | template<typename T> EventParamType wxMacGetEventParamType() { wxFAIL_MSG( wxT("Unknown Param Type") ) ; return 0 ; } |
204 | template<> inline EventParamType wxMacGetEventParamType<RgnHandle>() { return typeQDRgnHandle ; } | |
205 | template<> inline EventParamType wxMacGetEventParamType<ControlRef>() { return typeControlRef ; } | |
206 | template<> inline EventParamType wxMacGetEventParamType<WindowRef>() { return typeWindowRef ; } | |
207 | template<> inline EventParamType wxMacGetEventParamType<MenuRef>() { return typeMenuRef ; } | |
208 | template<> inline EventParamType wxMacGetEventParamType<EventRef>() { return typeEventRef ; } | |
209 | template<> inline EventParamType wxMacGetEventParamType<Point>() { return typeQDPoint ; } | |
210 | template<> inline EventParamType wxMacGetEventParamType<Rect>() { return typeQDRectangle ; } | |
211 | template<> inline EventParamType wxMacGetEventParamType<Boolean>() { return typeBoolean ; } | |
c06bbbff SC |
212 | template<> inline EventParamType wxMacGetEventParamType<SInt16>() { return typeSInt16 ; } |
213 | template<> inline EventParamType wxMacGetEventParamType<SInt32>() { return typeSInt32 ; } | |
214 | template<> inline EventParamType wxMacGetEventParamType<UInt32>() { return typeUInt32 ; } | |
215 | template<> inline EventParamType wxMacGetEventParamType<RGBColor>() { return typeRGBColor ; } | |
4f305456 | 216 | #if TARGET_API_MAC_OSX |
6d4c54a7 | 217 | template<> inline EventParamType wxMacGetEventParamType<HICommand>() { return typeHICommand ; } |
4f305456 SC |
218 | template<> inline EventParamType wxMacGetEventParamType<HIPoint>() { return typeHIPoint ; } |
219 | template<> inline EventParamType wxMacGetEventParamType<HISize>() { return typeHISize ; } | |
220 | template<> inline EventParamType wxMacGetEventParamType<HIRect>() { return typeHIRect ; } | |
221 | template<> inline EventParamType wxMacGetEventParamType<void*>() { return typeVoidPtr ; } | |
222 | #endif | |
c06bbbff | 223 | template<> inline EventParamType wxMacGetEventParamType<CFDictionaryRef>() { return typeCFDictionaryRef ; } |
4f305456 SC |
224 | template<> inline EventParamType wxMacGetEventParamType<Collection>() { return typeCollection ; } |
225 | template<> inline EventParamType wxMacGetEventParamType<CGContextRef>() { return typeCGContextRef ; } | |
226 | /* | |
885fb02f SC |
227 | These are ambiguous |
228 | template<> EventParamType wxMacGetEventParamType<GrafPtr>() { return typeGrafPtr ; } | |
229 | template<> EventParamType wxMacGetEventParamType<OSStatus>() { return typeOSStatus ; } | |
230 | template<> EventParamType wxMacGetEventParamType<CFIndex>() { return typeCFIndex ; } | |
231 | template<> EventParamType wxMacGetEventParamType<GWorldPtr>() { return typeGWorldPtr ; } | |
232 | */ | |
4f305456 SC |
233 | |
234 | class wxMacCarbonEvent | |
235 | { | |
fb5246be | 236 | |
4f305456 | 237 | public : |
a4848597 SC |
238 | wxMacCarbonEvent() |
239 | { | |
240 | m_eventRef = 0 ; | |
241 | m_release = false ; | |
242 | } | |
fb5246be WS |
243 | |
244 | wxMacCarbonEvent( EventRef event , bool release = false ) | |
4f305456 SC |
245 | { |
246 | m_eventRef = event ; | |
6d4c54a7 SC |
247 | m_release = release ; |
248 | } | |
fb5246be WS |
249 | |
250 | wxMacCarbonEvent(UInt32 inClassID,UInt32 inKind,EventTime inWhen = 0 /*now*/,EventAttributes inAttributes=kEventAttributeNone) | |
6d4c54a7 SC |
251 | { |
252 | m_eventRef = NULL ; | |
253 | verify_noerr( MacCreateEvent( NULL , inClassID, inKind,inWhen,inAttributes,&m_eventRef) ) ; | |
254 | m_release = true ; | |
255 | } | |
fb5246be | 256 | |
6d4c54a7 SC |
257 | ~wxMacCarbonEvent() |
258 | { | |
259 | if ( m_release ) | |
260 | ReleaseEvent( m_eventRef ) ; | |
4f305456 | 261 | } |
fb5246be WS |
262 | |
263 | OSStatus Create(UInt32 inClassID,UInt32 inKind,EventTime inWhen = 0 /*now*/,EventAttributes inAttributes=kEventAttributeNone) | |
a4848597 SC |
264 | { |
265 | verify( (m_eventRef == NULL) || m_release ) ; | |
266 | if ( m_eventRef && m_release ) | |
267 | { | |
268 | ReleaseEvent( m_eventRef ) ; | |
269 | m_release = false ; | |
270 | m_eventRef = NULL ; | |
a4848597 SC |
271 | } |
272 | OSStatus err = MacCreateEvent( NULL , inClassID, inKind,inWhen,inAttributes,&m_eventRef) ; | |
273 | if ( err == noErr ) | |
274 | m_release = true ; | |
275 | return err ; | |
276 | } | |
fb5246be | 277 | |
4f305456 | 278 | OSStatus GetParameter( EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData) ; |
fb5246be | 279 | |
4f305456 SC |
280 | template <typename T> OSStatus GetParameter( EventParamName inName, EventParamType type , T *data ) |
281 | { | |
282 | return GetParameter( inName, type , sizeof( T ) , data ) ; | |
283 | } | |
284 | template <typename T> OSStatus GetParameter( EventParamName inName, T *data ) | |
285 | { | |
286 | return GetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ; | |
287 | } | |
fb5246be | 288 | |
4f305456 SC |
289 | template <typename T> T GetParameter( EventParamName inName ) |
290 | { | |
291 | T value ; | |
292 | verify_noerr( GetParameter<T>( inName, &value ) ) ; | |
293 | return value ; | |
294 | } | |
295 | template <typename T> T GetParameter( EventParamName inName, EventParamType inDesiredType ) | |
296 | { | |
297 | T value ; | |
298 | verify_noerr( GetParameter<T>( inName, inDesiredType , &value ) ) ; | |
299 | return value ; | |
300 | } | |
fb5246be | 301 | |
6d4c54a7 SC |
302 | OSStatus SetParameter( EventParamName inName, EventParamType inType, UInt32 inSize, const void * inData) ; |
303 | template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , const T *data ) | |
4f305456 | 304 | { |
2aefa0ef SC |
305 | return SetParameter( inName, inDesiredType , sizeof( T ) , data ) ; |
306 | } | |
6d4c54a7 | 307 | template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , const T& data ) |
2aefa0ef SC |
308 | { |
309 | return SetParameter<T>( inName, inDesiredType , &data ) ; | |
4f305456 | 310 | } |
6d4c54a7 | 311 | template <typename T> OSStatus SetParameter( EventParamName inName, const T *data ) |
4f305456 SC |
312 | { |
313 | return SetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ; | |
314 | } | |
6d4c54a7 | 315 | template <typename T> OSStatus SetParameter( EventParamName inName, const T& data ) |
2aefa0ef SC |
316 | { |
317 | return SetParameter<T>( inName, wxMacGetEventParamType<T>() , &data ) ; | |
318 | } | |
86d8b744 SC |
319 | UInt32 GetClass() |
320 | { | |
321 | return ::GetEventClass( m_eventRef ) ; | |
322 | } | |
41b53169 | 323 | UInt32 GetKind() |
4f305456 SC |
324 | { |
325 | return ::GetEventKind( m_eventRef ) ; | |
326 | } | |
327 | EventTime GetTime() | |
328 | { | |
329 | return ::GetEventTime( m_eventRef ) ; | |
330 | } | |
331 | UInt32 GetTicks() | |
332 | { | |
333 | return EventTimeToTicks( GetTime() ) ; | |
334 | } | |
2c01d335 | 335 | OSStatus SetCurrentTime( ) |
a4848597 | 336 | { |
2c01d335 VZ |
337 | return ::SetEventTime( m_eventRef , GetCurrentEventTime() ) ; |
338 | } | |
fb5246be | 339 | OSStatus SetTime( EventTime when ) |
2c01d335 VZ |
340 | { |
341 | return ::SetEventTime( m_eventRef , when ) ; | |
a4848597 SC |
342 | } |
343 | operator EventRef () { return m_eventRef; } | |
fb5246be WS |
344 | |
345 | bool IsValid() { return m_eventRef != 0 ; } | |
4f305456 SC |
346 | protected : |
347 | EventRef m_eventRef ; | |
6d4c54a7 | 348 | bool m_release ; |
4f305456 SC |
349 | } ; |
350 | ||
3feeb1e1 SC |
351 | // |
352 | // helper class for allocating and deallocating Universal Proc Ptrs | |
353 | // | |
354 | ||
355 | template <typename procType, typename uppType , uppType (*newUPP)(procType) , void (*disposeUPP)(uppType) > class wxMacUPP | |
356 | { | |
357 | public : | |
358 | wxMacUPP( procType proc ) | |
359 | { | |
360 | m_upp = NULL ; | |
361 | m_upp = (*newUPP)( NULL ) ; | |
362 | } | |
363 | ~wxMacUPP() | |
364 | { | |
365 | if ( m_upp ) | |
366 | disposeUPP( m_upp ) ; | |
367 | } | |
368 | operator uppType() { return m_upp ; } | |
369 | private : | |
370 | uppType m_upp ; | |
371 | } ; | |
372 | ||
373 | typedef wxMacUPP<NMProcPtr,NMUPP,NewNMUPP,DisposeNMUPP> wxMacNMUPP ; | |
374 | ||
18b94824 SC |
375 | template <typename refType> class wxMacCFRefHolder |
376 | { | |
377 | public : | |
378 | wxMacCFRefHolder() | |
fb5246be | 379 | : m_ref(NULL) , m_release(false) |
18b94824 SC |
380 | { |
381 | } | |
fb5246be WS |
382 | |
383 | wxMacCFRefHolder( refType ref , bool release = true ) | |
18b94824 SC |
384 | : m_ref(ref) , m_release(release) |
385 | { | |
386 | } | |
fb5246be | 387 | |
18b94824 SC |
388 | ~wxMacCFRefHolder() |
389 | { | |
390 | CFRelease( m_ref ) ; | |
391 | } | |
fb5246be | 392 | |
18b94824 SC |
393 | void Release() |
394 | { | |
395 | if ( m_release && m_ref != NULL ) | |
396 | CFRelease( m_ref ) ; | |
397 | m_ref = NULL ; | |
398 | } | |
fb5246be | 399 | |
18b94824 SC |
400 | refType Detach() |
401 | { | |
402 | refType val = m_ref ; | |
403 | m_release = false ; | |
404 | m_ref = NULL ; | |
405 | return val ; | |
406 | } | |
fb5246be | 407 | |
18b94824 SC |
408 | void Set( refType ref , bool release = true ) |
409 | { | |
410 | Release() ; | |
411 | m_release = release ; | |
412 | m_ref = ref ; | |
413 | } | |
fb5246be | 414 | |
18b94824 | 415 | operator refType () const { return m_ref; } |
fb5246be | 416 | |
18b94824 SC |
417 | private : |
418 | refType m_ref ; | |
fb5246be WS |
419 | bool m_release ; |
420 | ||
18b94824 SC |
421 | DECLARE_NO_COPY_CLASS( wxMacCFRefHolder ) |
422 | } ; | |
423 | ||
885fb02f | 424 | #if wxUSE_GUI |
20b69855 | 425 | /* |
885fb02f SC |
426 | GWorldPtr wxMacCreateGWorld( int width , int height , int depth ) ; |
427 | void wxMacDestroyGWorld( GWorldPtr gw ) ; | |
428 | PicHandle wxMacCreatePict( GWorldPtr gw , GWorldPtr mask = NULL ) ; | |
429 | CIconHandle wxMacCreateCIcon(GWorldPtr image , GWorldPtr mask , short dstDepth , short iconSize ) ; | |
430 | void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue ) ; | |
431 | CTabHandle wxMacCreateColorTable( int numColors ) ; | |
20b69855 | 432 | */ |
885fb02f | 433 | void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType = 0 ) ; |
20b69855 | 434 | void wxMacReleaseBitmapButton( ControlButtonContentInfo*info ) ; |
885fb02f SC |
435 | |
436 | #define MAC_WXCOLORREF(a) (*((RGBColor*)&(a))) | |
437 | #define MAC_WXHBITMAP(a) (GWorldPtr(a)) | |
438 | #define MAC_WXHMETAFILE(a) (PicHandle(a)) | |
20b69855 | 439 | #define MAC_WXHICON(a) (IconRef(a)) |
885fb02f SC |
440 | #define MAC_WXHCURSOR(a) (CursHandle(a)) |
441 | #define MAC_WXHRGN(a) (RgnHandle(a)) | |
442 | #define MAC_WXHWND(a) (WindowPtr(a)) | |
443 | #define MAC_WXRECPTR(a) ((Rect*)a) | |
444 | #define MAC_WXPOINTPTR(a) ((Point*)a) | |
445 | #define MAC_WXHMENU(a) ((MenuHandle)a) | |
446 | ||
447 | struct wxOpaqueWindowRef | |
448 | { | |
449 | wxOpaqueWindowRef( WindowRef ref ) { m_data = ref ; } | |
fb5246be | 450 | operator WindowRef() { return m_data ; } |
885fb02f SC |
451 | private : |
452 | WindowRef m_data ; | |
453 | } ; | |
454 | ||
285b5ce0 SC |
455 | void wxMacRectToNative( const wxRect *wx , Rect *n ) ; |
456 | void wxMacNativeToRect( const Rect *n , wxRect* wx ) ; | |
457 | void wxMacPointToNative( const wxPoint* wx , Point *n ) ; | |
458 | void wxMacNativeToPoint( const Point *n , wxPoint* wx ) ; | |
459 | ||
885fb02f SC |
460 | wxWindow * wxFindControlFromMacControl(ControlRef inControl ) ; |
461 | wxTopLevelWindowMac* wxFindWinFromMacWindow( WindowRef inWindow ) ; | |
462 | wxMenu* wxFindMenuFromMacMenu(MenuRef inMenuRef) ; | |
463 | ||
1628261e SC |
464 | int wxMacCommandToId( UInt32 macCommandId ) ; |
465 | UInt32 wxIdToMacCommand( int wxId ) ; | |
466 | wxMenu* wxFindMenuFromMacCommand( const HICommand &macCommandId , wxMenuItem* &item ) ; | |
467 | ||
885fb02f SC |
468 | extern wxWindow* g_MacLastWindow ; |
469 | pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ; | |
470 | Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin = true ) ; | |
471 | ||
285b5ce0 SC |
472 | ControlActionUPP GetwxMacLiveScrollbarActionProc() ; |
473 | ||
86d8b744 SC |
474 | class wxMacControl |
475 | { | |
476 | public : | |
fb5246be | 477 | wxMacControl( wxWindow* peer , bool isRootControl = false ) ; |
9b89f11a SC |
478 | wxMacControl( wxWindow* peer , ControlRef control ) ; |
479 | wxMacControl( wxWindow* peer , WXWidget control ) ; | |
480 | virtual ~wxMacControl() ; | |
fb5246be | 481 | |
9b89f11a | 482 | void Init() ; |
fb5246be | 483 | |
5ca0d812 SC |
484 | virtual void Dispose() ; |
485 | ||
486 | bool Ok() const { return GetControlRef() != NULL ; } | |
5ca0d812 | 487 | |
fb5246be WS |
488 | virtual ControlRef * GetControlRefAddr() { return &m_controlRef; } |
489 | virtual ControlRef GetControlRef() const { return m_controlRef ; } | |
490 | ||
491 | virtual void SetReference( SInt32 data ) ; | |
5ca0d812 | 492 | /* |
2837271a | 493 | void operator= (ControlRef c) { m_controlRef = c ; } |
fb5246be WS |
494 | operator ControlRef () { return m_controlRef; } |
495 | operator ControlRef * () { return &m_controlRef; } | |
5ca0d812 | 496 | */ |
2837271a SC |
497 | // accessing data and values |
498 | ||
499 | virtual OSStatus SetData( ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData ) ; | |
0fc3bc3b SC |
500 | virtual OSStatus GetData( ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const ; |
501 | virtual OSStatus GetDataSize( ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const ; | |
2837271a SC |
502 | virtual OSStatus SendEvent( EventRef ref , OptionBits inOptions = 0 ) ; |
503 | virtual OSStatus SendHICommand( HICommand &command , OptionBits inOptions = 0 ) ; | |
504 | ||
0fc3bc3b | 505 | virtual OSStatus SendHICommand( UInt32 commandID , OptionBits inOptions = 0 ) ; |
2837271a | 506 | |
0fc3bc3b SC |
507 | virtual SInt32 GetValue() const ; |
508 | virtual SInt32 GetMaximum() const ; | |
509 | virtual SInt32 GetMinimum() const ; | |
fb5246be | 510 | |
0fc3bc3b SC |
511 | virtual void SetValue( SInt32 v ) ; |
512 | virtual void SetMinimum( SInt32 v ) ; | |
513 | virtual void SetMaximum( SInt32 v ) ; | |
2837271a | 514 | |
0fc3bc3b SC |
515 | virtual void SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum ) ; |
516 | virtual void SetRange( SInt32 minimum , SInt32 maximum ) ; | |
fb5246be | 517 | |
5ca0d812 SC |
518 | virtual OSStatus SetFocus( ControlFocusPart focusPart ) ; |
519 | virtual bool HasFocus() const ; | |
520 | virtual bool NeedsFocusRect() const ; | |
9b89f11a | 521 | virtual void SetNeedsFocusRect( bool needs ) ; |
fb5246be | 522 | |
2837271a SC |
523 | // templated helpers |
524 | ||
0fc3bc3b | 525 | Size GetDataSize( ControlPartCode inPartCode , ResType inTag ) const |
86d8b744 SC |
526 | { |
527 | Size sz ; | |
528 | verify_noerr( GetDataSize( inPartCode , inTag , &sz ) ) ; | |
529 | return sz ; | |
530 | } | |
6d4c54a7 | 531 | template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , const T *data ) |
86d8b744 SC |
532 | { |
533 | return SetData( inPartCode , inTag , sizeof( T ) , data ) ; | |
534 | } | |
6d4c54a7 | 535 | template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , const T& data ) |
86d8b744 SC |
536 | { |
537 | return SetData( inPartCode , inTag , sizeof( T ) , &data ) ; | |
538 | } | |
fbb7ee81 SC |
539 | template <typename T> OSStatus SetData( ResType inTag , const T *data ) |
540 | { | |
541 | return SetData( kControlEntireControl , inTag , sizeof( T ) , data ) ; | |
542 | } | |
543 | template <typename T> OSStatus SetData( ResType inTag , const T& data ) | |
544 | { | |
545 | return SetData( kControlEntireControl , inTag , sizeof( T ) , &data ) ; | |
546 | } | |
0fc3bc3b | 547 | template <typename T> OSStatus GetData( ControlPartCode inPartCode , ResType inTag , T *data ) const |
86d8b744 SC |
548 | { |
549 | Size dummy ; | |
550 | return GetData( inPartCode , inTag , sizeof( T ) , data , &dummy ) ; | |
551 | } | |
0fc3bc3b | 552 | template <typename T> T GetData( ControlPartCode inPartCode , ResType inTag ) const |
86d8b744 SC |
553 | { |
554 | T value ; | |
555 | verify_noerr( GetData<T>( inPartCode , inTag , &value ) ) ; | |
556 | return value ; | |
557 | } | |
fbb7ee81 SC |
558 | template <typename T> OSStatus GetData( ResType inTag , T *data ) const |
559 | { | |
560 | Size dummy ; | |
561 | return GetData( kControlEntireControl , inTag , sizeof( T ) , data , &dummy ) ; | |
562 | } | |
563 | template <typename T> T GetData( ResType inTag ) const | |
564 | { | |
565 | T value ; | |
566 | verify_noerr( GetData<T>( kControlEntireControl , inTag , &value ) ) ; | |
567 | return value ; | |
568 | } | |
569 | ||
6d4c54a7 | 570 | // Flash the control for the specified amount of time |
0fc3bc3b | 571 | virtual void Flash( ControlPartCode part , UInt32 ticks = 8 ) ; |
89a66f11 | 572 | |
0fc3bc3b | 573 | virtual void VisibilityChanged( bool shown ) ; |
89a66f11 SC |
574 | virtual void SuperChangedPosition() ; |
575 | ||
576 | ||
0fc3bc3b | 577 | virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) ; |
7ea087b7 | 578 | virtual void SetBackground( const wxBrush &brush ) ; |
5ca0d812 SC |
579 | virtual ControlPartCode HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers ) ; |
580 | void SetActionProc( ControlActionUPP actionProc ) ; | |
581 | void SetViewSize( SInt32 viewSize ) ; | |
582 | SInt32 GetViewSize() const ; | |
fb5246be | 583 | |
5ca0d812 SC |
584 | virtual bool IsVisible() const ; |
585 | virtual void SetVisibility( bool visible , bool redraw ) ; | |
586 | virtual bool IsEnabled() const ; | |
587 | virtual bool IsActive() const ; | |
588 | virtual void Enable( bool enable ) ; | |
fb5246be | 589 | |
5ca0d812 SC |
590 | // invalidates this control and all children |
591 | virtual void InvalidateWithChildren() ; | |
592 | virtual void SetDrawingEnabled( bool enable ) ; | |
b905d6cc | 593 | #ifdef __WXMAC_OSX__ |
5ca0d812 | 594 | virtual bool GetNeedsDisplay() const ; |
b905d6cc | 595 | #endif |
285b5ce0 SC |
596 | // where is in native window relative coordinates |
597 | virtual void SetNeedsDisplay( RgnHandle where ) ; | |
598 | // where is in native window relative coordinates | |
599 | virtual void SetNeedsDisplay( Rect* where = NULL ) ; | |
600 | ||
fb5246be | 601 | // if rect = NULL, entire view |
92346151 | 602 | virtual void ScrollRect( wxRect *rect , int dx , int dy ) ; |
5ca0d812 | 603 | |
285b5ce0 | 604 | // in native parent window relative coordinates |
5ca0d812 | 605 | virtual void GetRect( Rect *r ) ; |
285b5ce0 SC |
606 | |
607 | // in native parent window relative coordinates | |
5ca0d812 | 608 | virtual void SetRect( Rect *r ) ; |
285b5ce0 | 609 | |
5ca0d812 SC |
610 | virtual void GetRectInWindowCoords( Rect *r ) ; |
611 | virtual void GetBestRect( Rect *r ) ; | |
fb5246be | 612 | virtual void SetLabel( const wxString &title ) ; |
5ca0d812 SC |
613 | // converts from Toplevel-Content relative to local |
614 | static void Convert( wxPoint *pt , wxMacControl *convert , wxMacControl *to ) ; | |
fb5246be | 615 | |
5ca0d812 SC |
616 | virtual void GetFeatures( UInt32 *features ) ; |
617 | virtual OSStatus GetRegion( ControlPartCode partCode , RgnHandle region ) ; | |
618 | virtual OSStatus SetZOrder( bool above , wxMacControl* other ) ; | |
619 | // to be moved into a databrowser subclass | |
fb5246be | 620 | |
5ca0d812 SC |
621 | virtual OSStatus SetSelectionFlags( DataBrowserSelectionFlags ) ; |
622 | virtual OSStatus AddListViewColumn( DataBrowserListViewColumnDesc *columnDesc, | |
623 | DataBrowserTableViewColumnIndex position ) ; | |
624 | virtual OSStatus AutoSizeListViewColumns() ; | |
625 | virtual OSStatus SetHasScrollBars( bool horiz , bool vert ) ; | |
626 | virtual OSStatus SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle ) ; | |
627 | virtual OSStatus SetListViewHeaderBtnHeight(UInt16 height) ; | |
628 | virtual OSStatus SetCallbacks(const DataBrowserCallbacks * callbacks) ; | |
629 | virtual OSStatus UpdateItems( DataBrowserItemID container, UInt32 numItems, | |
fb5246be | 630 | const DataBrowserItemID* items, |
5ca0d812 SC |
631 | DataBrowserPropertyID preSortProperty, |
632 | DataBrowserPropertyID propertyID ) ; | |
633 | virtual OSStatus AddItems( DataBrowserItemID container, UInt32 numItems, | |
fb5246be | 634 | const DataBrowserItemID* items, |
5ca0d812 SC |
635 | DataBrowserPropertyID preSortProperty ) ; |
636 | virtual OSStatus RemoveItems( DataBrowserItemID container, UInt32 numItems, | |
fb5246be | 637 | const DataBrowserItemID* items, |
5ca0d812 SC |
638 | DataBrowserPropertyID preSortProperty ) ; |
639 | virtual OSStatus RevealItem( DataBrowserItemID item, | |
640 | DataBrowserPropertyID propertyID, | |
641 | DataBrowserRevealOptions options ) ; | |
fe3dc505 | 642 | virtual OSStatus GetSelectionAnchor( DataBrowserItemID * first, DataBrowserItemID * last ) ; |
5ca0d812 SC |
643 | virtual bool IsItemSelected( DataBrowserItemID item ) ; |
644 | virtual OSStatus SetSelectedItems(UInt32 numItems, | |
645 | const DataBrowserItemID * items, | |
646 | DataBrowserSetOption operation ) ; | |
fb5246be | 647 | |
5ca0d812 | 648 | // to be moved into a tab control class |
fb5246be | 649 | |
5ca0d812 | 650 | virtual OSStatus SetTabEnabled( SInt16 tabNo , bool enable ) ; |
9b89f11a | 651 | bool IsCompositing() { return m_isCompositing ; } |
285b5ce0 | 652 | bool IsRootControl() { return m_isRootControl ; } |
86d8b744 | 653 | protected : |
0fc3bc3b SC |
654 | ControlRef m_controlRef ; |
655 | wxFont m_font ; | |
fb5246be | 656 | long m_windowStyle ; |
b905d6cc | 657 | wxWindow* m_peer ; |
9b89f11a SC |
658 | bool m_needsFocusRect ; |
659 | bool m_isCompositing ; | |
285b5ce0 | 660 | bool m_isRootControl ; |
86d8b744 SC |
661 | } ; |
662 | ||
20b69855 SC |
663 | #if wxMAC_USE_CORE_GRAPHICS |
664 | ||
fb5246be | 665 | class WXDLLEXPORT wxMacCGPath : public wxGraphicPath |
20b69855 SC |
666 | { |
667 | DECLARE_NO_COPY_CLASS(wxMacCGPath) | |
668 | public : | |
669 | wxMacCGPath() ; | |
670 | ~wxMacCGPath() ; | |
fb5246be | 671 | |
20b69855 SC |
672 | // Starts a new subpath at |
673 | void MoveToPoint( wxCoord x1 , wxCoord y1 ) ; | |
674 | void AddLineToPoint( wxCoord x1 , wxCoord y1 ) ; | |
fea3713c | 675 | void AddQuadCurveToPoint( wxCoord cx1, wxCoord cy1, wxCoord x1, wxCoord y1 ) ; |
20b69855 SC |
676 | void AddRectangle( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) ; |
677 | void AddCircle( wxCoord x, wxCoord y , wxCoord r ) ; | |
fb5246be | 678 | |
20b69855 SC |
679 | // closes the current subpath |
680 | void CloseSubpath() ; | |
fb5246be | 681 | |
20b69855 SC |
682 | CGPathRef GetPath() const ; |
683 | private : | |
684 | CGMutablePathRef m_path ; | |
685 | } ; | |
686 | ||
687 | class WXDLLEXPORT wxMacCGContext : public wxGraphicContext | |
688 | { | |
689 | DECLARE_NO_COPY_CLASS(wxMacCGContext) | |
fb5246be | 690 | |
20b69855 SC |
691 | public: |
692 | wxMacCGContext( CGrafPtr port ) ; | |
693 | wxMacCGContext( CGContextRef cgcontext ) ; | |
694 | wxMacCGContext() ; | |
695 | ~wxMacCGContext() ; | |
696 | ||
697 | virtual void Clip( const wxRegion ®ion ) ; | |
698 | virtual void StrokePath( const wxGraphicPath *p ) ; | |
699 | virtual void DrawPath( const wxGraphicPath *p , int fillStyle = wxWINDING_RULE ) ; | |
700 | virtual void FillPath( const wxGraphicPath *p , const wxColor &fillColor , int fillStyle = wxWINDING_RULE ) ; | |
fb5246be | 701 | |
20b69855 | 702 | virtual wxGraphicPath* CreatePath() ; |
fb5246be | 703 | virtual void SetPen( const wxPen &pen ) ; |
20b69855 SC |
704 | virtual void SetBrush( const wxBrush &brush ) ; |
705 | CGContextRef GetNativeContext() ; | |
706 | void SetNativeContext( CGContextRef cg ) ; | |
707 | CGPathDrawingMode GetDrawingMode() const { return m_mode ; } | |
708 | private: | |
709 | CGContextRef m_cgContext ; | |
710 | CGrafPtr m_qdPort ; | |
711 | CGPathDrawingMode m_mode ; | |
712 | wxPen m_pen ; | |
713 | wxBrush m_brush ; | |
714 | } ; | |
715 | ||
30e77b5c SC |
716 | #endif // wxMAC_USE_CORE_GRAPHICS |
717 | ||
718 | #ifdef __WXMAC_OSX__ | |
719 | ||
20b69855 | 720 | CGColorSpaceRef wxMacGetGenericRGBColorSpace(void) ; |
71cc158e | 721 | void wxMacMemoryBufferReleaseProc(void *info, const void *data, size_t size) ; |
20b69855 | 722 | |
30e77b5c | 723 | #endif |
20b69855 SC |
724 | |
725 | class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData | |
726 | { | |
727 | DECLARE_NO_COPY_CLASS(wxBitmapRefData) | |
fb5246be | 728 | |
20b69855 SC |
729 | friend class WXDLLEXPORT wxIcon; |
730 | friend class WXDLLEXPORT wxCursor; | |
731 | public: | |
732 | wxBitmapRefData(int width , int height , int depth); | |
733 | wxBitmapRefData(); | |
734 | ~wxBitmapRefData(); | |
735 | ||
736 | void Free() ; | |
737 | bool Ok() const { return m_ok ; } | |
738 | void SetOk( bool isOk) { m_ok = isOk ; } | |
fb5246be | 739 | |
20b69855 SC |
740 | void SetWidth( int width ) { m_width = width ; } |
741 | void SetHeight( int height ) { m_height = height ; } | |
742 | void SetDepth( int depth ) { m_depth = depth ; } | |
743 | ||
744 | int GetWidth() const { return m_width ; } | |
745 | int GetHeight() const { return m_height ; } | |
746 | int GetDepth() const { return m_depth ; } | |
fb5246be | 747 | |
20b69855 SC |
748 | void *GetRawAccess() const ; |
749 | void *BeginRawAccess() ; | |
750 | void EndRawAccess() ; | |
751 | ||
752 | bool HasAlpha() const { return m_hasAlpha ; } | |
753 | void UseAlpha( bool useAlpha ) ; | |
754 | ||
755 | public: | |
756 | #if wxUSE_PALETTE | |
757 | wxPalette m_bitmapPalette; | |
758 | #endif // wxUSE_PALETTE | |
fb5246be | 759 | |
20b69855 | 760 | wxMask * m_bitmapMask; // Optional mask |
30e77b5c | 761 | #ifdef __WXMAC_OSX__ |
20b69855 | 762 | CGImageRef CGImageCreate() const ; |
71cc158e | 763 | #endif |
fb5246be | 764 | |
6d2c830a SC |
765 | // returns true if the bitmap has a size that |
766 | // can be natively transferred into a true icon | |
767 | // if no is returned GetIconRef will still produce | |
768 | // an icon but it will be generated via a PICT and | |
fb5246be | 769 | // rescaled to 16 x 16 |
6d2c830a | 770 | bool HasNativeSize() ; |
fb5246be | 771 | |
6d2c830a SC |
772 | // caller should increase ref count if needed longer |
773 | // than the bitmap exists | |
774 | IconRef GetIconRef() ; | |
fb5246be | 775 | |
6d2c830a SC |
776 | // returns a Pict from the bitmap content |
777 | PicHandle GetPictHandle() ; | |
20b69855 SC |
778 | GWorldPtr GetHBITMAP(GWorldPtr * mask = NULL ) const ; |
779 | void UpdateAlphaMask() const ; | |
71cc158e | 780 | |
20b69855 SC |
781 | private : |
782 | bool Create(int width , int height , int depth) ; | |
783 | void Init() ; | |
784 | ||
785 | int m_width; | |
786 | int m_height; | |
787 | int m_bytesPerRow ; | |
788 | int m_depth; | |
789 | bool m_hasAlpha; | |
790 | wxMemoryBuffer m_memBuf ; | |
791 | int m_rawAccessCount ; | |
792 | bool m_ok; | |
30e77b5c | 793 | #ifdef __WXMAC_OSX__ |
20b69855 | 794 | mutable CGImageRef m_cgImageRef ; |
71cc158e | 795 | #endif |
6d2c830a SC |
796 | IconRef m_iconRef ; |
797 | PicHandle m_pictHandle ; | |
20b69855 SC |
798 | GWorldPtr m_hBitmap; |
799 | GWorldPtr m_hMaskBitmap ; | |
800 | wxMemoryBuffer m_maskMemBuf ; | |
801 | int m_maskBytesPerRow ; | |
20b69855 SC |
802 | }; |
803 | ||
20b69855 SC |
804 | class WXDLLEXPORT wxIconRefData : public wxGDIRefData |
805 | { | |
806 | public: | |
807 | wxIconRefData() ; | |
808 | wxIconRefData( WXHICON ) ; | |
809 | virtual ~wxIconRefData() { Free(); } | |
810 | ||
811 | void Init() ; | |
812 | virtual void Free(); | |
ddb08e02 SC |
813 | |
814 | void SetWidth( int width ) { m_width = width ; } | |
815 | void SetHeight( int height ) { m_height = height ; } | |
816 | ||
817 | int GetWidth() const { return m_width ; } | |
818 | int GetHeight() const { return m_height ; } | |
819 | ||
20b69855 SC |
820 | WXHICON GetHICON() const { return (WXHICON) m_iconRef ; } |
821 | private : | |
822 | IconRef m_iconRef ; | |
ddb08e02 SC |
823 | int m_width ; |
824 | int m_height ; | |
20b69855 SC |
825 | }; |
826 | ||
285b5ce0 SC |
827 | // toplevel.cpp |
828 | ||
fbfb8bcc | 829 | ControlRef wxMacFindControlUnderMouse( wxTopLevelWindowMac* toplevelWindow, const Point& location , WindowRef window , ControlPartCode *outPart ) ; |
285b5ce0 | 830 | |
7358f907 SC |
831 | #if WORDS_BIGENDIAN |
832 | inline Rect* wxMacGetPictureBounds( PicHandle pict , Rect* rect ) | |
833 | { | |
834 | *rect = (**pict).picFrame ; | |
835 | return rect ; | |
836 | } | |
837 | #else | |
838 | inline Rect* wxMacGetPictureBounds( PicHandle pict , Rect* rect ) | |
839 | { | |
840 | return QDGetPictureBounds( pict , rect ) ; | |
841 | } | |
842 | #endif | |
843 | ||
8cf73271 SC |
844 | #endif // wxUSE_GUI |
845 | ||
285b5ce0 SC |
846 | #define wxMAC_DEFINE_PROC_GETTER( UPP , x ) \ |
847 | UPP Get##x() \ | |
848 | { \ | |
849 | static UPP sHandler = NULL; \ | |
850 | if ( sHandler == NULL ) \ | |
851 | sHandler = New##UPP( x ); \ | |
852 | return sHandler; \ | |
853 | } | |
854 | ||
8cf73271 SC |
855 | //--------------------------------------------------------------------------- |
856 | // wxMac string conversions | |
857 | //--------------------------------------------------------------------------- | |
858 | ||
859 | void wxMacSetupConverters() ; | |
860 | void wxMacCleanupConverters() ; | |
861 | ||
862 | void wxMacStringToPascal( const wxString&from , StringPtr to ) ; | |
863 | wxString wxMacMakeStringFromPascal( ConstStringPtr from ) ; | |
864 | ||
a2b77260 SC |
865 | // filefn.cpp |
866 | ||
867 | wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL ) ; | |
868 | OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef ) ; | |
869 | wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname ) ; | |
aa0cc8a1 | 870 | |
8cf73271 SC |
871 | #endif |
872 | // _WX_PRIVATE_H_ |