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