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