]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: private.h | |
3 | // Purpose: Private declarations: as this header is only included by | |
4 | // wxWindows itself, it may contain identifiers which don't start | |
5 | // with "wx". | |
6 | // Author: Stefan Csomor | |
7 | // Modified by: | |
8 | // Created: 1998-01-01 | |
9 | // RCS-ID: $Id$ | |
10 | // Copyright: (c) Stefan Csomor | |
11 | // Licence: wxWindows licence | |
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 | |
23 | # include <Debugging.h> | |
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> | |
31 | #endif | |
32 | ||
33 | #if UNIVERSAL_INTERFACES_VERSION < 0x0340 | |
34 | #error "please update to Apple's lastest universal headers from http://developer.apple.com/sdk/" | |
35 | #endif | |
36 | ||
37 | #if wxUSE_GUI | |
38 | ||
39 | #include "wx/window.h" | |
40 | ||
41 | class wxMacPortStateHelper | |
42 | { | |
43 | DECLARE_NO_COPY_CLASS(wxMacPortStateHelper) | |
44 | ||
45 | public: | |
46 | wxMacPortStateHelper( GrafPtr newport) ; | |
47 | wxMacPortStateHelper() ; | |
48 | ~wxMacPortStateHelper() ; | |
49 | ||
50 | void Setup( GrafPtr newport ) ; | |
51 | void Clear() ; | |
52 | bool IsCleared() { return m_clip == NULL ; } | |
53 | GrafPtr GetCurrentPort() { return m_currentPort ; } | |
54 | ||
55 | private: | |
56 | GrafPtr m_currentPort ; | |
57 | GrafPtr m_oldPort ; | |
58 | RgnHandle m_clip ; | |
59 | ThemeDrawingState m_drawingState ; | |
60 | short m_textFont ; | |
61 | short m_textSize ; | |
62 | short m_textStyle ; | |
63 | short m_textMode ; | |
64 | } ; | |
65 | ||
66 | class WXDLLEXPORT wxMacPortSaver | |
67 | { | |
68 | DECLARE_NO_COPY_CLASS(wxMacPortSaver) | |
69 | ||
70 | public: | |
71 | wxMacPortSaver( GrafPtr port ) | |
72 | { | |
73 | ::GetPort( &m_port ) ; | |
74 | ::SetPort( port ) ; | |
75 | } | |
76 | ~wxMacPortSaver() | |
77 | { | |
78 | ::SetPort( m_port ) ; | |
79 | } | |
80 | private : | |
81 | GrafPtr m_port ; | |
82 | } ; | |
83 | ||
84 | class WXDLLEXPORT wxMacPortSetter | |
85 | { | |
86 | DECLARE_NO_COPY_CLASS(wxMacPortSetter) | |
87 | ||
88 | public: | |
89 | wxMacPortSetter( const wxDC* dc ) ; | |
90 | ~wxMacPortSetter() ; | |
91 | private: | |
92 | wxMacPortStateHelper m_ph ; | |
93 | const wxDC* m_dc ; | |
94 | } ; | |
95 | ||
96 | /* | |
97 | Clips to the visible region of a control within the current port | |
98 | */ | |
99 | ||
100 | class WXDLLEXPORT wxMacWindowClipper : public wxMacPortSaver | |
101 | { | |
102 | DECLARE_NO_COPY_CLASS(wxMacWindowClipper) | |
103 | ||
104 | public: | |
105 | wxMacWindowClipper( const wxWindow* win ) ; | |
106 | ~wxMacWindowClipper() ; | |
107 | private: | |
108 | GrafPtr m_newPort ; | |
109 | RgnHandle m_formerClip ; | |
110 | RgnHandle m_newClip ; | |
111 | } ; | |
112 | ||
113 | class WXDLLEXPORT wxMacWindowStateSaver : public wxMacWindowClipper | |
114 | { | |
115 | DECLARE_NO_COPY_CLASS(wxMacWindowStateSaver) | |
116 | ||
117 | public: | |
118 | wxMacWindowStateSaver( const wxWindow* win ) ; | |
119 | ~wxMacWindowStateSaver() ; | |
120 | private: | |
121 | GrafPtr m_newPort ; | |
122 | ThemeDrawingState m_themeDrawingState ; | |
123 | } ; | |
124 | ||
125 | /* | |
126 | class wxMacDrawingHelper | |
127 | { | |
128 | DECLARE_NO_COPY_CLASS(wxMacDrawingHelper) | |
129 | ||
130 | public: | |
131 | wxMacDrawingHelper( wxWindowMac * theWindow , bool clientArea = false ) ; | |
132 | ~wxMacDrawingHelper() ; | |
133 | bool Ok() { return m_ok ; } | |
134 | void LocalToWindow( Rect *rect) { OffsetRect( rect , m_origin.h , m_origin.v ) ; } | |
135 | void LocalToWindow( Point *pt ) { AddPt( m_origin , pt ) ; } | |
136 | void LocalToWindow( RgnHandle rgn ) { OffsetRgn( rgn , m_origin.h , m_origin.v ) ; } | |
137 | const Point& GetOrigin() { return m_origin ; } | |
138 | private: | |
139 | Point m_origin ; | |
140 | GrafPtr m_formerPort ; | |
141 | GrafPtr m_currentPort ; | |
142 | PenState m_savedPenState ; | |
143 | bool m_ok ; | |
144 | } ; | |
145 | */ | |
146 | ||
147 | // app.h | |
148 | bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec) ; | |
149 | ||
150 | #endif // wxUSE_GUI | |
151 | ||
152 | // filefn.h | |
153 | WXDLLEXPORT wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) ; | |
154 | WXDLLEXPORT void wxMacFilename2FSSpec( const char *path , FSSpec *spec ) ; | |
155 | WXDLLEXPORT void wxMacFilename2FSSpec( const wxChar *path , FSSpec *spec ) ; | |
156 | # ifndef __DARWIN__ | |
157 | // Mac file names are POSIX (Unix style) under Darwin, so these are not needed | |
158 | WXDLLEXPORT wxString wxMacFSSpec2UnixFilename( const FSSpec *spec ) ; | |
159 | WXDLLEXPORT void wxUnixFilename2FSSpec( const char *path , FSSpec *spec ) ; | |
160 | WXDLLEXPORT wxString wxMac2UnixFilename( const char *s) ; | |
161 | WXDLLEXPORT wxString wxUnix2MacFilename( const char *s); | |
162 | # endif | |
163 | ||
164 | // utils.h | |
165 | WXDLLEXPORT wxString wxMacFindFolder(short vRefNum, | |
166 | OSType folderType, | |
167 | Boolean createFolder); | |
168 | ||
169 | #if wxUSE_GUI | |
170 | ||
171 | GWorldPtr wxMacCreateGWorld( int width , int height , int depth ) ; | |
172 | void wxMacDestroyGWorld( GWorldPtr gw ) ; | |
173 | PicHandle wxMacCreatePict( GWorldPtr gw , GWorldPtr mask = NULL ) ; | |
174 | CIconHandle wxMacCreateCIcon(GWorldPtr image , GWorldPtr mask , short dstDepth , short iconSize ) ; | |
175 | void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue ) ; | |
176 | CTabHandle wxMacCreateColorTable( int numColors ) ; | |
177 | void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType = 0 ) ; | |
178 | ||
179 | #define MAC_WXCOLORREF(a) (*((RGBColor*)&(a))) | |
180 | #define MAC_WXHBITMAP(a) (GWorldPtr(a)) | |
181 | #define MAC_WXHMETAFILE(a) (PicHandle(a)) | |
182 | #define MAC_WXHICON(a) (CIconHandle(a)) | |
183 | #define MAC_WXHCURSOR(a) (CursHandle(a)) | |
184 | #define MAC_WXHRGN(a) (RgnHandle(a)) | |
185 | #define MAC_WXHWND(a) (WindowPtr(a)) | |
186 | #define MAC_WXRECPTR(a) ((Rect*)a) | |
187 | #define MAC_WXPOINTPTR(a) ((Point*)a) | |
188 | #define MAC_WXHMENU(a) ((MenuHandle)a) | |
189 | ||
190 | struct wxOpaqueWindowRef | |
191 | { | |
192 | wxOpaqueWindowRef( WindowRef ref ) { m_data = ref ; } | |
193 | operator WindowRef() { return m_data ; } | |
194 | private : | |
195 | WindowRef m_data ; | |
196 | } ; | |
197 | ||
198 | wxWindow *wxFindControlFromMacControl(ControlRef inControl ) ; | |
199 | wxTopLevelWindowMac* wxFindWinFromMacWindow( WindowRef inWindow ) ; | |
200 | extern wxWindow* g_MacLastWindow ; | |
201 | pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ; | |
202 | Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin = true ) ; | |
203 | ||
204 | template<typename T> EventParamType wxMacGetEventParamType() { wxFAIL_MSG( wxT("Unknown Param Type") ) ; return 0 ; } | |
205 | template<> inline EventParamType wxMacGetEventParamType<RgnHandle>() { return typeQDRgnHandle ; } | |
206 | template<> inline EventParamType wxMacGetEventParamType<ControlRef>() { return typeControlRef ; } | |
207 | template<> inline EventParamType wxMacGetEventParamType<WindowRef>() { return typeWindowRef ; } | |
208 | template<> inline EventParamType wxMacGetEventParamType<MenuRef>() { return typeMenuRef ; } | |
209 | template<> inline EventParamType wxMacGetEventParamType<EventRef>() { return typeEventRef ; } | |
210 | template<> inline EventParamType wxMacGetEventParamType<Point>() { return typeQDPoint ; } | |
211 | template<> inline EventParamType wxMacGetEventParamType<Rect>() { return typeQDRectangle ; } | |
212 | template<> inline EventParamType wxMacGetEventParamType<Boolean>() { return typeBoolean ; } | |
213 | #if TARGET_API_MAC_OSX | |
214 | template<> inline EventParamType wxMacGetEventParamType<HIPoint>() { return typeHIPoint ; } | |
215 | template<> inline EventParamType wxMacGetEventParamType<HISize>() { return typeHISize ; } | |
216 | template<> inline EventParamType wxMacGetEventParamType<HIRect>() { return typeHIRect ; } | |
217 | template<> inline EventParamType wxMacGetEventParamType<void*>() { return typeVoidPtr ; } | |
218 | #endif | |
219 | template<> inline EventParamType wxMacGetEventParamType<Collection>() { return typeCollection ; } | |
220 | template<> inline EventParamType wxMacGetEventParamType<CGContextRef>() { return typeCGContextRef ; } | |
221 | /* | |
222 | These are ambiguous | |
223 | template<> EventParamType wxMacGetEventParamType<GrafPtr>() { return typeGrafPtr ; } | |
224 | template<> EventParamType wxMacGetEventParamType<OSStatus>() { return typeOSStatus ; } | |
225 | template<> EventParamType wxMacGetEventParamType<CFIndex>() { return typeCFIndex ; } | |
226 | template<> EventParamType wxMacGetEventParamType<GWorldPtr>() { return typeGWorldPtr ; } | |
227 | */ | |
228 | ||
229 | class wxMacCarbonEvent | |
230 | { | |
231 | ||
232 | public : | |
233 | wxMacCarbonEvent( EventRef event ) | |
234 | { | |
235 | m_eventRef = event ; | |
236 | } | |
237 | ||
238 | OSStatus GetParameter( EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData) ; | |
239 | ||
240 | template <typename T> OSStatus GetParameter( EventParamName inName, EventParamType type , T *data ) | |
241 | { | |
242 | return GetParameter( inName, type , sizeof( T ) , data ) ; | |
243 | } | |
244 | template <typename T> OSStatus GetParameter( EventParamName inName, T *data ) | |
245 | { | |
246 | return GetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ; | |
247 | } | |
248 | ||
249 | template <typename T> T GetParameter( EventParamName inName ) | |
250 | { | |
251 | T value ; | |
252 | verify_noerr( GetParameter<T>( inName, &value ) ) ; | |
253 | return value ; | |
254 | } | |
255 | template <typename T> T GetParameter( EventParamName inName, EventParamType inDesiredType ) | |
256 | { | |
257 | T value ; | |
258 | verify_noerr( GetParameter<T>( inName, inDesiredType , &value ) ) ; | |
259 | return value ; | |
260 | } | |
261 | ||
262 | ||
263 | OSStatus SetParameter( EventParamName inName, EventParamType inType, UInt32 inSize, void * inData) ; | |
264 | template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , T *data ) | |
265 | { | |
266 | return SetParameter( inName, inDesiredType , sizeof( T ) , data ) ; | |
267 | } | |
268 | template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , T data ) | |
269 | { | |
270 | return SetParameter<T>( inName, inDesiredType , &data ) ; | |
271 | } | |
272 | template <typename T> OSStatus SetParameter( EventParamName inName, T *data ) | |
273 | { | |
274 | return SetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ; | |
275 | } | |
276 | template <typename T> OSStatus SetParameter( EventParamName inName, T data ) | |
277 | { | |
278 | return SetParameter<T>( inName, wxMacGetEventParamType<T>() , &data ) ; | |
279 | } | |
280 | ||
281 | EventKind GetKind() | |
282 | { | |
283 | return ::GetEventKind( m_eventRef ) ; | |
284 | } | |
285 | EventTime GetTime() | |
286 | { | |
287 | return ::GetEventTime( m_eventRef ) ; | |
288 | } | |
289 | UInt32 GetTicks() | |
290 | { | |
291 | return EventTimeToTicks( GetTime() ) ; | |
292 | } | |
293 | protected : | |
294 | EventRef m_eventRef ; | |
295 | } ; | |
296 | ||
297 | #endif // wxUSE_GUI | |
298 | ||
299 | //--------------------------------------------------------------------------- | |
300 | // wxMac string conversions | |
301 | //--------------------------------------------------------------------------- | |
302 | ||
303 | void wxMacSetupConverters() ; | |
304 | void wxMacCleanupConverters() ; | |
305 | ||
306 | void wxMacStringToPascal( const wxString&from , StringPtr to ) ; | |
307 | wxString wxMacMakeStringFromPascal( ConstStringPtr from ) ; | |
308 | ||
309 | void wxMacConvertNewlines13To10( char * data ) ; | |
310 | void wxMacConvertNewlines10To13( char * data ) ; | |
311 | void wxMacConvertNewlines13To10( wxString *data ) ; | |
312 | void wxMacConvertNewlines10To13( wxString *data ) ; | |
313 | ||
314 | #if wxUSE_UNICODE | |
315 | void wxMacConvertNewlines13To10( wxChar * data ) ; | |
316 | void wxMacConvertNewlines10To13( wxChar * data ) ; | |
317 | #endif | |
318 | ||
319 | #if TARGET_CARBON | |
320 | ||
321 | class wxMacCFStringHolder | |
322 | { | |
323 | public: | |
324 | wxMacCFStringHolder() | |
325 | { | |
326 | m_cfs = NULL ; | |
327 | m_release = false ; | |
328 | } | |
329 | ||
330 | wxMacCFStringHolder(const wxString &str , wxFontEncoding encoding ) | |
331 | { | |
332 | m_cfs = NULL ; | |
333 | m_release = false ; | |
334 | Assign( str , encoding ) ; | |
335 | } | |
336 | ||
337 | wxMacCFStringHolder(CFStringRef ref , bool release = true ) | |
338 | { | |
339 | m_cfs = ref ; | |
340 | m_release = release ; | |
341 | } | |
342 | ||
343 | ~wxMacCFStringHolder() | |
344 | { | |
345 | Release() ; | |
346 | } | |
347 | ||
348 | CFStringRef Detach() | |
349 | { | |
350 | CFStringRef retval = m_cfs ; | |
351 | m_release = false ; | |
352 | m_cfs = NULL ; | |
353 | return retval ; | |
354 | } | |
355 | ||
356 | void Release() | |
357 | { | |
358 | if ( m_release && m_cfs) | |
359 | CFRelease( m_cfs ) ; | |
360 | m_cfs = NULL ; | |
361 | } | |
362 | ||
363 | void Assign( const wxString &str , wxFontEncoding encoding ) ; | |
364 | ||
365 | operator CFStringRef () { return m_cfs; } | |
366 | wxString AsString( wxFontEncoding encoding = wxFONTENCODING_DEFAULT ) ; | |
367 | ||
368 | private: | |
369 | ||
370 | CFStringRef m_cfs; | |
371 | bool m_release ; | |
372 | } ; | |
373 | ||
374 | #endif | |
375 | ||
376 | // utils.cpp | |
377 | ||
378 | wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding) ; | |
379 | wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding) ; | |
380 | ||
381 | // toplevel.cpp | |
382 | ||
383 | ControlRef wxMacFindControlUnderMouse( Point location , WindowRef window , ControlPartCode *outPart ) ; | |
384 | ||
385 | #endif | |
386 | // _WX_PRIVATE_H_ |