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