1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/osx/core/private.h
3 // Purpose: Private declarations: as this header is only included by
4 // wxWidgets itself, it may contain identifiers which don't start
6 // Author: Stefan Csomor
9 // RCS-ID: $Id: private.h 53819 2008-05-29 14:11:45Z SC $
10 // Copyright: (c) Stefan Csomor
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
14 #ifndef _WX_PRIVATE_CORE_H_
15 #define _WX_PRIVATE_CORE_H_
19 #include <CoreFoundation/CoreFoundation.h>
21 #include "wx/osx/core/cfstring.h"
22 #include "wx/osx/core/cfdataref.h"
24 #if wxOSX_USE_COCOA_OR_CARBON
26 WXDLLIMPEXP_BASE
long UMAGetSystemVersion() ;
28 void WXDLLIMPEXP_CORE
wxMacStringToPascal( const wxString
&from
, unsigned char * to
);
29 wxString WXDLLIMPEXP_CORE
wxMacMakeStringFromPascal( const unsigned char * from
);
35 WXDLLIMPEXP_CORE wxWindowMac
* wxFindWindowFromWXWidget(WXWidget inControl
);
38 #include <CoreGraphics/CoreGraphics.h>
40 #include <ApplicationServices/ApplicationServices.h>
43 #include "wx/bitmap.h"
44 #include "wx/window.h"
46 class WXDLLIMPEXP_CORE wxMacCGContextStateSaver
48 wxDECLARE_NO_COPY_CLASS(wxMacCGContextStateSaver
);
51 wxMacCGContextStateSaver( CGContextRef cg
)
54 CGContextSaveGState( cg
);
56 ~wxMacCGContextStateSaver()
58 CGContextRestoreGState( m_cg
);
64 class WXDLLIMPEXP_CORE wxDeferredObjectDeleter
: public wxObject
67 wxDeferredObjectDeleter( wxObject
* obj
) : m_obj(obj
)
70 virtual ~wxDeferredObjectDeleter()
80 WXDLLIMPEXP_CORE CGImageRef
wxMacCreateCGImageFromBitmap( const wxBitmap
& bitmap
);
82 WXDLLIMPEXP_CORE CGDataProviderRef
wxMacCGDataProviderCreateWithCFData( CFDataRef data
);
83 WXDLLIMPEXP_CORE CGDataConsumerRef
wxMacCGDataConsumerCreateWithCFData( CFMutableDataRef data
);
84 WXDLLIMPEXP_CORE CGDataProviderRef
wxMacCGDataProviderCreateWithMemoryBuffer( const wxMemoryBuffer
& buf
);
86 CGColorSpaceRef WXDLLIMPEXP_CORE
wxMacGetGenericRGBColorSpace(void);
90 extern wxWindow
* g_MacLastWindow
;
91 class wxNonOwnedWindow
;
93 // temporary typedef so that no additional casts are necessary within carbon code at the moment
101 typedef wxMacControl wxWidgetImplType
;
103 typedef wxWidgetImpl wxWidgetImplType
;
106 class wxMenuItemImpl
: public wxObject
109 wxMenuItemImpl( wxMenuItem
* peer
) : m_peer(peer
)
113 virtual ~wxMenuItemImpl() ;
114 virtual void SetBitmap( const wxBitmap
& bitmap
) = 0;
115 virtual void Enable( bool enable
) = 0;
116 virtual void Check( bool check
) = 0;
117 virtual void SetLabel( const wxString
& text
, wxAcceleratorEntry
*entry
) = 0;
118 virtual void Hide( bool hide
= true ) = 0;
120 virtual void * GetHMenuItem() = 0;
122 wxMenuItem
* GetWXPeer() { return m_peer
; }
124 static wxMenuItemImpl
* Create( wxMenuItem
* peer
, wxMenu
*pParentMenu
,
126 const wxString
& text
,
127 wxAcceleratorEntry
*entry
,
128 const wxString
& strHelp
,
135 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl
)
138 class wxMenuImpl
: public wxObject
141 wxMenuImpl( wxMenu
* peer
) : m_peer(peer
)
145 virtual ~wxMenuImpl() ;
146 virtual void InsertOrAppend(wxMenuItem
*pItem
, size_t pos
) = 0;
147 virtual void Remove( wxMenuItem
*pItem
) = 0;
149 virtual void MakeRoot() = 0;
151 virtual void SetTitle( const wxString
& text
) = 0;
153 virtual WXHMENU
GetHMenu() = 0;
155 wxMenu
* GetWXPeer() { return m_peer
; }
157 virtual void PopUp( wxWindow
*win
, int x
, int y
) = 0;
159 static wxMenuImpl
* Create( wxMenu
* peer
, const wxString
& title
);
160 static wxMenuImpl
* CreateRootMenu( wxMenu
* peer
);
164 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl
)
169 class WXDLLIMPEXP_CORE wxWidgetImpl
: public wxObject
172 wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
= false );
174 virtual ~wxWidgetImpl();
178 bool IsRootControl() const { return m_isRootControl
; }
180 wxWindowMac
* GetWXPeer() const { return m_wxPeer
; }
182 bool IsOk() const { return GetWXWidget() != NULL
; }
184 // not only the control itself, but also all its parents must be visible
185 // in order for this function to return true
186 virtual bool IsVisible() const = 0;
187 // set the visibility of this widget (maybe latent)
188 virtual void SetVisibility( bool visible
) = 0;
190 virtual void Raise() = 0;
192 virtual void Lower() = 0;
194 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
) = 0;
196 virtual WXWidget
GetWXWidget() const = 0;
198 virtual void SetBackgroundColour( const wxColour
& col
) = 0;
200 // all coordinates in native parent widget relative coordinates
201 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
202 virtual void Move(int x
, int y
, int width
, int height
) = 0;
203 virtual void GetPosition( int &x
, int &y
) const = 0;
204 virtual void GetSize( int &width
, int &height
) const = 0;
205 virtual void SetControlSize( wxWindowVariant variant
) = 0;
207 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
) = 0;
208 virtual bool GetNeedsDisplay() const = 0;
210 virtual bool NeedsFocusRect() const;
211 virtual void SetNeedsFocusRect( bool needs
);
213 virtual bool NeedsFrame() const;
214 virtual void SetNeedsFrame( bool needs
);
216 virtual bool CanFocus() const = 0;
217 // return true if successful
218 virtual bool SetFocus() = 0;
219 virtual bool HasFocus() const = 0;
221 virtual void RemoveFromParent() = 0;
222 virtual void Embed( wxWidgetImpl
*parent
) = 0;
224 virtual void SetDefaultButton( bool isDefault
) = 0;
225 virtual void PerformClick() = 0;
226 virtual void SetLabel( const wxString
& title
, wxFontEncoding encoding
) = 0;
228 virtual void SetCursor( const wxCursor
& cursor
) = 0;
229 virtual void CaptureMouse() = 0;
230 virtual void ReleaseMouse() = 0;
232 virtual wxInt32
GetValue() const = 0;
233 virtual void SetValue( wxInt32 v
) = 0;
234 virtual void SetBitmap( const wxBitmap
& bitmap
) = 0;
235 virtual void SetupTabs( const wxNotebook
¬ebook
) =0;
236 virtual void GetBestRect( wxRect
*r
) const = 0;
237 virtual bool IsEnabled() const = 0;
238 virtual void Enable( bool enable
) = 0;
239 virtual void SetMinimum( wxInt32 v
) = 0;
240 virtual void SetMaximum( wxInt32 v
) = 0;
241 virtual wxInt32
GetMinimum() const = 0;
242 virtual wxInt32
GetMaximum() const = 0;
243 virtual void PulseGauge() = 0;
244 virtual void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
) = 0;
246 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true ) = 0;
248 // is the clicked event sent AFTER the state already changed, so no additional
249 // state changing logic is required from the outside
250 virtual bool ButtonClickDidStateChange() = 0;
252 virtual void InstallEventHandler( WXWidget control
= NULL
) = 0;
254 // static methods for associating native controls and their implementations
257 FindFromWXWidget(WXWidget control
);
259 static void RemoveAssociations( wxWidgetImpl
* impl
);
261 static void Associate( WXWidget control
, wxWidgetImpl
*impl
);
263 static WXWidget
FindFocus();
265 // static creation methods, must be implemented by all toolkits
267 static wxWidgetImplType
* CreateUserPane( wxWindowMac
* wxpeer
,
274 static wxWidgetImplType
* CreateContentView( wxNonOwnedWindow
* now
) ;
276 static wxWidgetImplType
* CreateButton( wxWindowMac
* wxpeer
,
279 const wxString
& label
,
285 static wxWidgetImplType
* CreateDisclosureTriangle( wxWindowMac
* wxpeer
,
288 const wxString
& label
,
294 static wxWidgetImplType
* CreateStaticLine( wxWindowMac
* wxpeer
,
302 static wxWidgetImplType
* CreateGroupBox( wxWindowMac
* wxpeer
,
305 const wxString
& label
,
311 static wxWidgetImplType
* CreateStaticText( wxWindowMac
* wxpeer
,
314 const wxString
& label
,
320 static wxWidgetImplType
* CreateTextControl( wxTextCtrl
* wxpeer
,
323 const wxString
& content
,
329 static wxWidgetImplType
* CreateSearchControl( wxTextCtrl
* wxpeer
,
332 const wxString
& content
,
338 static wxWidgetImplType
* CreateCheckBox( wxWindowMac
* wxpeer
,
341 const wxString
& label
,
347 static wxWidgetImplType
* CreateRadioButton( wxWindowMac
* wxpeer
,
350 const wxString
& label
,
356 static wxWidgetImplType
* CreateToggleButton( wxWindowMac
* wxpeer
,
359 const wxString
& label
,
365 static wxWidgetImplType
* CreateBitmapToggleButton( wxWindowMac
* wxpeer
,
368 const wxBitmap
& bitmap
,
374 static wxWidgetImplType
* CreateBitmapButton( wxWindowMac
* wxpeer
,
377 const wxBitmap
& bitmap
,
383 static wxWidgetImplType
* CreateTabView( wxWindowMac
* wxpeer
,
391 static wxWidgetImplType
* CreateGauge( wxWindowMac
* wxpeer
,
402 static wxWidgetImplType
* CreateSlider( wxWindowMac
* wxpeer
,
413 static wxWidgetImplType
* CreateSpinButton( wxWindowMac
* wxpeer
,
424 static wxWidgetImplType
* CreateScrollBar( wxWindowMac
* wxpeer
,
432 static wxWidgetImplType
* CreateChoice( wxWindowMac
* wxpeer
,
441 static wxWidgetImplType
* CreateListBox( wxWindowMac
* wxpeer
,
449 // converts from Toplevel-Content relative to local
450 static void Convert( wxPoint
*pt
, wxWidgetImpl
*from
, wxWidgetImpl
*to
);
452 bool m_isRootControl
;
453 wxWindowMac
* m_wxPeer
;
454 bool m_needsFocusRect
;
457 DECLARE_ABSTRACT_CLASS(wxWidgetImpl
)
461 // the interface to be implemented eg by a listbox
464 class WXDLLIMPEXP_CORE wxListWidgetColumn
467 virtual ~wxListWidgetColumn() {}
470 class WXDLLIMPEXP_CORE wxListWidgetCellValue
473 wxListWidgetCellValue() {}
474 virtual ~wxListWidgetCellValue() {}
476 virtual void Set( CFStringRef value
) = 0;
477 virtual void Set( const wxString
& value
) = 0;
478 virtual void Set( int value
) = 0;
480 virtual int GetIntValue() const = 0;
481 virtual wxString
GetStringValue() const = 0;
484 class WXDLLIMPEXP_CORE wxListWidgetImpl
487 wxListWidgetImpl() {}
488 virtual ~wxListWidgetImpl() { }
490 virtual wxListWidgetColumn
* InsertTextColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
491 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
492 virtual wxListWidgetColumn
* InsertCheckColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
493 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
497 // TODO will be replaced
498 virtual void ListDelete( unsigned int n
) = 0;
499 virtual void ListInsert( unsigned int n
) = 0;
500 virtual void ListClear() = 0;
504 virtual void ListDeselectAll() = 0;
505 virtual void ListSetSelection( unsigned int n
, bool select
, bool multi
) = 0;
506 virtual int ListGetSelection() const = 0;
507 virtual int ListGetSelections( wxArrayInt
& aSelections
) const = 0;
508 virtual bool ListIsSelected( unsigned int n
) const = 0;
512 virtual void ListScrollTo( unsigned int n
) = 0;
513 virtual void UpdateLine( unsigned int n
, wxListWidgetColumn
* col
= NULL
) = 0;
514 virtual void UpdateLineToEnd( unsigned int n
) = 0;
518 virtual unsigned int ListGetCount() const = 0;
522 // interface to be implemented by a textcontrol
525 class WXDLLIMPEXP_FWD_CORE wxTextAttr
;
527 // common interface for all implementations
528 class WXDLLIMPEXP_CORE wxTextWidgetImpl
532 wxTextWidgetImpl() {}
534 virtual ~wxTextWidgetImpl() {}
536 virtual bool CanFocus() const { return true; }
538 virtual wxString
GetStringValue() const = 0 ;
539 virtual void SetStringValue( const wxString
&val
) = 0 ;
540 virtual void SetSelection( long from
, long to
) = 0 ;
541 virtual void GetSelection( long* from
, long* to
) const = 0 ;
542 virtual void WriteText( const wxString
& str
) = 0 ;
544 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
545 virtual void Copy() ;
547 virtual void Paste() ;
548 virtual bool CanPaste() const ;
549 virtual void SetEditable( bool editable
) ;
550 virtual long GetLastPosition() const ;
551 virtual void Replace( long from
, long to
, const wxString
&str
) ;
552 virtual void Remove( long from
, long to
) ;
555 virtual bool HasOwnContextMenu() const
558 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
561 virtual void Clear() ;
562 virtual bool CanUndo() const;
563 virtual void Undo() ;
564 virtual bool CanRedo() const;
565 virtual void Redo() ;
566 virtual int GetNumberOfLines() const ;
567 virtual long XYToPosition(long x
, long y
) const;
568 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
569 virtual void ShowPosition(long WXUNUSED(pos
)) ;
570 virtual int GetLineLength(long lineNo
) const ;
571 virtual wxString
GetLineText(long lineNo
) const ;
572 virtual void CheckSpelling(bool WXUNUSED(check
)) { }
576 // common interface for search controls
579 class wxSearchWidgetImpl
582 wxSearchWidgetImpl(){}
583 virtual ~wxSearchWidgetImpl(){}
585 // search field options
586 virtual void ShowSearchButton( bool show
) = 0;
587 virtual bool IsSearchButtonVisible() const = 0;
589 virtual void ShowCancelButton( bool show
) = 0;
590 virtual bool IsCancelButtonVisible() const = 0;
592 virtual void SetSearchMenu( wxMenu
* menu
) = 0;
594 virtual void SetDescriptiveText(const wxString
& text
) = 0;
598 // toplevel window implementation class
601 class wxNonOwnedWindowImpl
: public wxObject
604 wxNonOwnedWindowImpl( wxNonOwnedWindow
* nonownedwnd
) : m_wxPeer(nonownedwnd
)
607 wxNonOwnedWindowImpl()
610 virtual ~wxNonOwnedWindowImpl()
614 virtual void Destroy()
618 virtual void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
619 long style
, long extraStyle
, const wxString
& name
) = 0;
622 virtual WXWindow
GetWXWindow() const = 0;
632 virtual bool Show(bool WXUNUSED(show
))
637 virtual bool ShowWithEffect(bool show
, wxShowEffect
WXUNUSED(effect
), unsigned WXUNUSED(timeout
))
642 virtual void Update()
646 virtual bool SetTransparent(wxByte
WXUNUSED(alpha
))
651 virtual bool SetBackgroundColour(const wxColour
& WXUNUSED(col
) )
656 virtual void SetExtraStyle( long WXUNUSED(exStyle
) )
660 virtual bool SetBackgroundStyle(wxBackgroundStyle
WXUNUSED(style
))
665 bool CanSetTransparent()
670 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
671 virtual void MoveWindow(int x
, int y
, int width
, int height
) = 0;
672 virtual void GetPosition( int &x
, int &y
) const = 0;
673 virtual void GetSize( int &width
, int &height
) const = 0;
675 virtual bool SetShape(const wxRegion
& WXUNUSED(region
))
680 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) = 0;
682 virtual bool IsMaximized() const = 0;
684 virtual bool IsIconized() const= 0;
686 virtual void Iconize( bool iconize
)= 0;
688 virtual void Maximize(bool maximize
) = 0;
690 virtual bool IsFullScreen() const= 0;
692 virtual bool ShowFullScreen(bool show
, long style
)= 0;
694 virtual void RequestUserAttention(int flags
) = 0;
696 virtual void ScreenToWindow( int *x
, int *y
) = 0;
698 virtual void WindowToScreen( int *x
, int *y
) = 0;
700 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
702 // static creation methods, must be implemented by all toolkits
704 static wxNonOwnedWindowImpl
* CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
705 long style
, long extraStyle
, const wxString
& name
) ;
708 wxNonOwnedWindow
* m_wxPeer
;
709 DECLARE_ABSTRACT_CLASS(wxNonOwnedWindowImpl
)
714 //---------------------------------------------------------------------------
715 // cocoa bridging utilities
716 //---------------------------------------------------------------------------
718 bool wxMacInitCocoa();
720 class WXDLLIMPEXP_CORE wxMacAutoreleasePool
723 wxMacAutoreleasePool();
724 ~wxMacAutoreleasePool();
731 void wxMacCocoaRelease( void* obj
);
732 void wxMacCocoaAutorelease( void* obj
);
733 void* wxMacCocoaRetain( void* obj
);
737 // _WX_PRIVATE_CORE_H_