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