]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/carbon/private.h
fixed #includes
[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
5185263f
DE
41#ifdef __WXMAC_CARBON__
42#include "wx/mac/corefoundation/cfstring.h"
43#endif
44
8cf73271
SC
45#if wxUSE_GUI
46
47#include "wx/window.h"
48
49class wxMacPortStateHelper
50{
51 DECLARE_NO_COPY_CLASS(wxMacPortStateHelper)
52
53public:
54 wxMacPortStateHelper( GrafPtr newport) ;
55 wxMacPortStateHelper() ;
56 ~wxMacPortStateHelper() ;
57
58 void Setup( GrafPtr newport ) ;
59 void Clear() ;
60 bool IsCleared() { return m_clip == NULL ; }
61 GrafPtr GetCurrentPort() { return m_currentPort ; }
62
63private:
64 GrafPtr m_currentPort ;
65 GrafPtr m_oldPort ;
66 RgnHandle m_clip ;
67 ThemeDrawingState m_drawingState ;
68 short m_textFont ;
69 short m_textSize ;
70 short m_textStyle ;
71 short m_textMode ;
72} ;
73
4f305456
SC
74class WXDLLEXPORT wxMacPortSaver
75{
76 DECLARE_NO_COPY_CLASS(wxMacPortSaver)
77
78public:
79 wxMacPortSaver( GrafPtr port )
80 {
81 ::GetPort( &m_port ) ;
82 ::SetPort( port ) ;
83 }
84 ~wxMacPortSaver()
85 {
86 ::SetPort( m_port ) ;
87 }
88private :
89 GrafPtr m_port ;
90} ;
91
8cf73271
SC
92class WXDLLEXPORT wxMacPortSetter
93{
94 DECLARE_NO_COPY_CLASS(wxMacPortSetter)
95
96public:
97 wxMacPortSetter( const wxDC* dc ) ;
98 ~wxMacPortSetter() ;
99private:
100 wxMacPortStateHelper m_ph ;
101 const wxDC* m_dc ;
102} ;
103
4f305456
SC
104/*
105 Clips to the visible region of a control within the current port
106 */
107
108class WXDLLEXPORT wxMacWindowClipper : public wxMacPortSaver
8cf73271
SC
109{
110 DECLARE_NO_COPY_CLASS(wxMacWindowClipper)
111
112public:
113 wxMacWindowClipper( const wxWindow* win ) ;
114 ~wxMacWindowClipper() ;
115private:
01299d56 116 GrafPtr m_newPort ;
8cf73271
SC
117 RgnHandle m_formerClip ;
118 RgnHandle m_newClip ;
119} ;
120
01299d56
SC
121class WXDLLEXPORT wxMacWindowStateSaver : public wxMacWindowClipper
122{
123 DECLARE_NO_COPY_CLASS(wxMacWindowStateSaver)
124
125public:
126 wxMacWindowStateSaver( const wxWindow* win ) ;
127 ~wxMacWindowStateSaver() ;
128private:
129 GrafPtr m_newPort ;
130 ThemeDrawingState m_themeDrawingState ;
131} ;
132
4f305456 133/*
8cf73271
SC
134class wxMacDrawingHelper
135{
136 DECLARE_NO_COPY_CLASS(wxMacDrawingHelper)
137
138public:
139 wxMacDrawingHelper( wxWindowMac * theWindow , bool clientArea = false ) ;
140 ~wxMacDrawingHelper() ;
141 bool Ok() { return m_ok ; }
142 void LocalToWindow( Rect *rect) { OffsetRect( rect , m_origin.h , m_origin.v ) ; }
143 void LocalToWindow( Point *pt ) { AddPt( m_origin , pt ) ; }
144 void LocalToWindow( RgnHandle rgn ) { OffsetRgn( rgn , m_origin.h , m_origin.v ) ; }
145 const Point& GetOrigin() { return m_origin ; }
146private:
147 Point m_origin ;
148 GrafPtr m_formerPort ;
149 GrafPtr m_currentPort ;
150 PenState m_savedPenState ;
151 bool m_ok ;
152} ;
4f305456 153*/
8cf73271
SC
154
155// app.h
156bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec) ;
157
158#endif // wxUSE_GUI
159
160// filefn.h
161WXDLLEXPORT wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) ;
a2b77260 162WXDLLEXPORT void wxMacFilename2FSSpec( const wxString &path , FSSpec *spec ) ;
8cf73271
SC
163
164// utils.h
165WXDLLEXPORT wxString wxMacFindFolder(short vRefNum,
166 OSType folderType,
167 Boolean createFolder);
168
169#if wxUSE_GUI
170
171GWorldPtr wxMacCreateGWorld( int width , int height , int depth ) ;
172void wxMacDestroyGWorld( GWorldPtr gw ) ;
173PicHandle wxMacCreatePict( GWorldPtr gw , GWorldPtr mask = NULL ) ;
174CIconHandle wxMacCreateCIcon(GWorldPtr image , GWorldPtr mask , short dstDepth , short iconSize ) ;
175void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue ) ;
176CTabHandle wxMacCreateColorTable( int numColors ) ;
177void 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
4f305456
SC
190struct wxOpaqueWindowRef
191{
192 wxOpaqueWindowRef( WindowRef ref ) { m_data = ref ; }
193 operator WindowRef() { return m_data ; }
194private :
195 WindowRef m_data ;
196} ;
197
41b53169
SC
198wxWindow * wxFindControlFromMacControl(ControlRef inControl ) ;
199wxTopLevelWindowMac* wxFindWinFromMacWindow( WindowRef inWindow ) ;
200wxMenu* wxFindMenuFromMacMenu(MenuRef inMenuRef) ;
201
4f305456
SC
202extern wxWindow* g_MacLastWindow ;
203pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ;
271cad4c 204Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin = true ) ;
4f305456
SC
205
206template<typename T> EventParamType wxMacGetEventParamType() { wxFAIL_MSG( wxT("Unknown Param Type") ) ; return 0 ; }
207template<> inline EventParamType wxMacGetEventParamType<RgnHandle>() { return typeQDRgnHandle ; }
208template<> inline EventParamType wxMacGetEventParamType<ControlRef>() { return typeControlRef ; }
209template<> inline EventParamType wxMacGetEventParamType<WindowRef>() { return typeWindowRef ; }
210template<> inline EventParamType wxMacGetEventParamType<MenuRef>() { return typeMenuRef ; }
211template<> inline EventParamType wxMacGetEventParamType<EventRef>() { return typeEventRef ; }
212template<> inline EventParamType wxMacGetEventParamType<Point>() { return typeQDPoint ; }
213template<> inline EventParamType wxMacGetEventParamType<Rect>() { return typeQDRectangle ; }
214template<> inline EventParamType wxMacGetEventParamType<Boolean>() { return typeBoolean ; }
215#if TARGET_API_MAC_OSX
6d4c54a7 216template<> inline EventParamType wxMacGetEventParamType<HICommand>() { return typeHICommand ; }
4f305456
SC
217template<> inline EventParamType wxMacGetEventParamType<HIPoint>() { return typeHIPoint ; }
218template<> inline EventParamType wxMacGetEventParamType<HISize>() { return typeHISize ; }
219template<> inline EventParamType wxMacGetEventParamType<HIRect>() { return typeHIRect ; }
220template<> inline EventParamType wxMacGetEventParamType<void*>() { return typeVoidPtr ; }
221#endif
222template<> inline EventParamType wxMacGetEventParamType<Collection>() { return typeCollection ; }
223template<> inline EventParamType wxMacGetEventParamType<CGContextRef>() { return typeCGContextRef ; }
224/*
225These are ambiguous
226template<> EventParamType wxMacGetEventParamType<GrafPtr>() { return typeGrafPtr ; }
227template<> EventParamType wxMacGetEventParamType<OSStatus>() { return typeOSStatus ; }
228template<> EventParamType wxMacGetEventParamType<CFIndex>() { return typeCFIndex ; }
229template<> EventParamType wxMacGetEventParamType<GWorldPtr>() { return typeGWorldPtr ; }
230*/
231
232class wxMacCarbonEvent
233{
234
235public :
6d4c54a7 236 wxMacCarbonEvent( EventRef event , bool release = false )
4f305456
SC
237 {
238 m_eventRef = event ;
6d4c54a7
SC
239 m_release = release ;
240 }
241 wxMacCarbonEvent(UInt32 inClassID,UInt32 inKind,EventTime inWhen = 0 /*now*/,EventAttributes inAttributes=kEventAttributeNone)
242 {
243 m_eventRef = NULL ;
244 verify_noerr( MacCreateEvent( NULL , inClassID, inKind,inWhen,inAttributes,&m_eventRef) ) ;
245 m_release = true ;
246 }
247 ~wxMacCarbonEvent()
248 {
249 if ( m_release )
250 ReleaseEvent( m_eventRef ) ;
4f305456
SC
251 }
252
253 OSStatus GetParameter( EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData) ;
254
255 template <typename T> OSStatus GetParameter( EventParamName inName, EventParamType type , T *data )
256 {
257 return GetParameter( inName, type , sizeof( T ) , data ) ;
258 }
259 template <typename T> OSStatus GetParameter( EventParamName inName, T *data )
260 {
261 return GetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ;
262 }
263
264 template <typename T> T GetParameter( EventParamName inName )
265 {
266 T value ;
267 verify_noerr( GetParameter<T>( inName, &value ) ) ;
268 return value ;
269 }
270 template <typename T> T GetParameter( EventParamName inName, EventParamType inDesiredType )
271 {
272 T value ;
273 verify_noerr( GetParameter<T>( inName, inDesiredType , &value ) ) ;
274 return value ;
275 }
276
6d4c54a7
SC
277 OSStatus SetParameter( EventParamName inName, EventParamType inType, UInt32 inSize, const void * inData) ;
278 template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , const T *data )
4f305456 279 {
2aefa0ef
SC
280 return SetParameter( inName, inDesiredType , sizeof( T ) , data ) ;
281 }
6d4c54a7 282 template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , const T& data )
2aefa0ef
SC
283 {
284 return SetParameter<T>( inName, inDesiredType , &data ) ;
4f305456 285 }
6d4c54a7 286 template <typename T> OSStatus SetParameter( EventParamName inName, const T *data )
4f305456
SC
287 {
288 return SetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ;
289 }
6d4c54a7 290 template <typename T> OSStatus SetParameter( EventParamName inName, const T& data )
2aefa0ef
SC
291 {
292 return SetParameter<T>( inName, wxMacGetEventParamType<T>() , &data ) ;
293 }
86d8b744
SC
294 UInt32 GetClass()
295 {
296 return ::GetEventClass( m_eventRef ) ;
297 }
41b53169 298 UInt32 GetKind()
4f305456
SC
299 {
300 return ::GetEventKind( m_eventRef ) ;
301 }
302 EventTime GetTime()
303 {
304 return ::GetEventTime( m_eventRef ) ;
305 }
306 UInt32 GetTicks()
307 {
308 return EventTimeToTicks( GetTime() ) ;
309 }
6d4c54a7 310 operator EventRef () { return m_eventRef; }
4f305456
SC
311protected :
312 EventRef m_eventRef ;
6d4c54a7 313 bool m_release ;
4f305456
SC
314} ;
315
86d8b744
SC
316class wxMacControl
317{
318public :
6d4c54a7
SC
319 wxMacControl()
320 {
321 m_controlRef = NULL ;
322 }
323
86d8b744
SC
324 wxMacControl( ControlRef control )
325 {
326 m_controlRef = control ;
327 }
328 wxMacControl( WXWidget control )
329 {
330 m_controlRef = (ControlRef) control ;
331 }
0fc3bc3b
SC
332 virtual ~wxMacControl()
333 {
334 }
6d4c54a7 335
5ca0d812
SC
336 virtual void Dispose() ;
337
338 bool Ok() const { return GetControlRef() != NULL ; }
339
340 virtual ControlRef * GetControlRefAddr() { return &m_controlRef; }
341 virtual ControlRef GetControlRef() const { return m_controlRef ; }
342
343 virtual void SetReference( SInt32 data ) ;
344 /*
2837271a
SC
345 void operator= (ControlRef c) { m_controlRef = c ; }
346 operator ControlRef () { return m_controlRef; }
347 operator ControlRef * () { return &m_controlRef; }
5ca0d812 348 */
2837271a
SC
349 // accessing data and values
350
351 virtual OSStatus SetData( ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData ) ;
0fc3bc3b
SC
352 virtual OSStatus GetData( ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const ;
353 virtual OSStatus GetDataSize( ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const ;
2837271a
SC
354 virtual OSStatus SendEvent( EventRef ref , OptionBits inOptions = 0 ) ;
355 virtual OSStatus SendHICommand( HICommand &command , OptionBits inOptions = 0 ) ;
356
0fc3bc3b 357 virtual OSStatus SendHICommand( UInt32 commandID , OptionBits inOptions = 0 ) ;
2837271a 358
0fc3bc3b
SC
359 virtual SInt32 GetValue() const ;
360 virtual SInt32 GetMaximum() const ;
361 virtual SInt32 GetMinimum() const ;
2837271a 362
0fc3bc3b
SC
363 virtual void SetValue( SInt32 v ) ;
364 virtual void SetMinimum( SInt32 v ) ;
365 virtual void SetMaximum( SInt32 v ) ;
2837271a 366
0fc3bc3b
SC
367 virtual void SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum ) ;
368 virtual void SetRange( SInt32 minimum , SInt32 maximum ) ;
2837271a 369
5ca0d812
SC
370 virtual OSStatus SetFocus( ControlFocusPart focusPart ) ;
371 virtual bool HasFocus() const ;
372 virtual bool NeedsFocusRect() const ;
373
2837271a
SC
374 // templated helpers
375
0fc3bc3b 376 Size GetDataSize( ControlPartCode inPartCode , ResType inTag ) const
86d8b744
SC
377 {
378 Size sz ;
379 verify_noerr( GetDataSize( inPartCode , inTag , &sz ) ) ;
380 return sz ;
381 }
6d4c54a7 382 template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , const T *data )
86d8b744
SC
383 {
384 return SetData( inPartCode , inTag , sizeof( T ) , data ) ;
385 }
6d4c54a7 386 template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , const T& data )
86d8b744
SC
387 {
388 return SetData( inPartCode , inTag , sizeof( T ) , &data ) ;
389 }
0fc3bc3b 390 template <typename T> OSStatus GetData( ControlPartCode inPartCode , ResType inTag , T *data ) const
86d8b744
SC
391 {
392 Size dummy ;
393 return GetData( inPartCode , inTag , sizeof( T ) , data , &dummy ) ;
394 }
0fc3bc3b 395 template <typename T> T GetData( ControlPartCode inPartCode , ResType inTag ) const
86d8b744
SC
396 {
397 T value ;
398 verify_noerr( GetData<T>( inPartCode , inTag , &value ) ) ;
399 return value ;
400 }
2837271a 401
6d4c54a7 402 // Flash the control for the specified amount of time
0fc3bc3b
SC
403 virtual void Flash( ControlPartCode part , UInt32 ticks = 8 ) ;
404 virtual void VisibilityChanged( bool shown ) ;
405 virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) ;
7ea087b7 406 virtual void SetBackground( const wxBrush &brush ) ;
5ca0d812
SC
407 virtual ControlPartCode HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers ) ;
408 void SetActionProc( ControlActionUPP actionProc ) ;
409 void SetViewSize( SInt32 viewSize ) ;
410 SInt32 GetViewSize() const ;
411
412 virtual bool IsVisible() const ;
413 virtual void SetVisibility( bool visible , bool redraw ) ;
414 virtual bool IsEnabled() const ;
415 virtual bool IsActive() const ;
416 virtual void Enable( bool enable ) ;
417
418 // invalidates this control and all children
419 virtual void InvalidateWithChildren() ;
420 virtual void SetDrawingEnabled( bool enable ) ;
421 virtual bool GetNeedsDisplay() const ;
422 virtual void SetNeedsDisplay( bool needsDisplay , RgnHandle where = NULL ) ;
423
424 virtual void ScrollRect( const wxRect &rect , int dx , int dy ) ;
425
426 virtual void GetRect( Rect *r ) ;
427 virtual void SetRect( Rect *r ) ;
428 virtual void GetRectInWindowCoords( Rect *r ) ;
429 virtual void GetBestRect( Rect *r ) ;
430 virtual void SetTitle( const wxString &title ) ;
431 // converts from Toplevel-Content relative to local
432 static void Convert( wxPoint *pt , wxMacControl *convert , wxMacControl *to ) ;
433
434 virtual void GetFeatures( UInt32 *features ) ;
435 virtual OSStatus GetRegion( ControlPartCode partCode , RgnHandle region ) ;
436 virtual OSStatus SetZOrder( bool above , wxMacControl* other ) ;
437 // to be moved into a databrowser subclass
438
439 virtual OSStatus SetSelectionFlags( DataBrowserSelectionFlags ) ;
440 virtual OSStatus AddListViewColumn( DataBrowserListViewColumnDesc *columnDesc,
441 DataBrowserTableViewColumnIndex position ) ;
442 virtual OSStatus AutoSizeListViewColumns() ;
443 virtual OSStatus SetHasScrollBars( bool horiz , bool vert ) ;
444 virtual OSStatus SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle ) ;
445 virtual OSStatus SetListViewHeaderBtnHeight(UInt16 height) ;
446 virtual OSStatus SetCallbacks(const DataBrowserCallbacks * callbacks) ;
447 virtual OSStatus UpdateItems( DataBrowserItemID container, UInt32 numItems,
448 const DataBrowserItemID* items,
449 DataBrowserPropertyID preSortProperty,
450 DataBrowserPropertyID propertyID ) ;
451 virtual OSStatus AddItems( DataBrowserItemID container, UInt32 numItems,
452 const DataBrowserItemID* items,
453 DataBrowserPropertyID preSortProperty ) ;
454 virtual OSStatus RemoveItems( DataBrowserItemID container, UInt32 numItems,
455 const DataBrowserItemID* items,
456 DataBrowserPropertyID preSortProperty ) ;
457 virtual OSStatus RevealItem( DataBrowserItemID item,
458 DataBrowserPropertyID propertyID,
459 DataBrowserRevealOptions options ) ;
fe3dc505 460 virtual OSStatus GetSelectionAnchor( DataBrowserItemID * first, DataBrowserItemID * last ) ;
5ca0d812
SC
461 virtual bool IsItemSelected( DataBrowserItemID item ) ;
462 virtual OSStatus SetSelectedItems(UInt32 numItems,
463 const DataBrowserItemID * items,
464 DataBrowserSetOption operation ) ;
465
466 // to be moved into a tab control class
467
468 virtual OSStatus SetTabEnabled( SInt16 tabNo , bool enable ) ;
86d8b744 469protected :
0fc3bc3b
SC
470 ControlRef m_controlRef ;
471 wxFont m_font ;
472 long m_windowStyle ;
86d8b744
SC
473} ;
474
8cf73271
SC
475#endif // wxUSE_GUI
476
477//---------------------------------------------------------------------------
478// wxMac string conversions
479//---------------------------------------------------------------------------
480
481void wxMacSetupConverters() ;
482void wxMacCleanupConverters() ;
483
484void wxMacStringToPascal( const wxString&from , StringPtr to ) ;
485wxString wxMacMakeStringFromPascal( ConstStringPtr from ) ;
486
1a42f89c
SC
487// toplevel.cpp
488
489ControlRef wxMacFindControlUnderMouse( Point location , WindowRef window , ControlPartCode *outPart ) ;
8cf73271 490
a2b77260
SC
491// filefn.cpp
492
493wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL ) ;
494OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef ) ;
495wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname ) ;
aa0cc8a1 496
8cf73271
SC
497#endif
498 // _WX_PRIVATE_H_