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
);
36 #include <CoreGraphics/CoreGraphics.h>
38 #include <ApplicationServices/ApplicationServices.h>
41 #include "wx/bitmap.h"
42 #include "wx/window.h"
44 class WXDLLIMPEXP_CORE wxMacCGContextStateSaver
46 wxDECLARE_NO_COPY_CLASS(wxMacCGContextStateSaver
);
49 wxMacCGContextStateSaver( CGContextRef cg
)
52 CGContextSaveGState( cg
);
54 ~wxMacCGContextStateSaver()
56 CGContextRestoreGState( m_cg
);
62 class WXDLLIMPEXP_CORE wxDeferredObjectDeleter
: public wxObject
65 wxDeferredObjectDeleter( wxObject
* obj
) : m_obj(obj
)
68 virtual ~wxDeferredObjectDeleter()
78 WXDLLIMPEXP_CORE CGImageRef
wxMacCreateCGImageFromBitmap( const wxBitmap
& bitmap
);
80 WXDLLIMPEXP_CORE CGDataProviderRef
wxMacCGDataProviderCreateWithCFData( CFDataRef data
);
81 WXDLLIMPEXP_CORE CGDataConsumerRef
wxMacCGDataConsumerCreateWithCFData( CFMutableDataRef data
);
82 WXDLLIMPEXP_CORE CGDataProviderRef
wxMacCGDataProviderCreateWithMemoryBuffer( const wxMemoryBuffer
& buf
);
84 CGColorSpaceRef WXDLLIMPEXP_CORE
wxMacGetGenericRGBColorSpace(void);
88 extern wxWindow
* g_MacLastWindow
;
89 class wxNonOwnedWindow
;
91 // temporary typedef so that no additional casts are necessary within carbon code at the moment
98 WXDLLIMPEXP_CORE wxWindowMac
* wxFindWindowFromWXWidget(WXWidget inControl
);
101 typedef wxMacControl wxWidgetImplType
;
103 typedef wxWidgetImpl wxWidgetImplType
;
107 class wxMenuItemImpl
: public wxObject
110 wxMenuItemImpl( wxMenuItem
* peer
) : m_peer(peer
)
114 virtual ~wxMenuItemImpl() ;
115 virtual void SetBitmap( const wxBitmap
& bitmap
) = 0;
116 virtual void Enable( bool enable
) = 0;
117 virtual void Check( bool check
) = 0;
118 virtual void SetLabel( const wxString
& text
, wxAcceleratorEntry
*entry
) = 0;
119 virtual void Hide( bool hide
= true ) = 0;
121 virtual void * GetHMenuItem() = 0;
123 wxMenuItem
* GetWXPeer() { return m_peer
; }
125 static wxMenuItemImpl
* Create( wxMenuItem
* peer
, wxMenu
*pParentMenu
,
127 const wxString
& text
,
128 wxAcceleratorEntry
*entry
,
129 const wxString
& strHelp
,
136 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl
)
139 class wxMenuImpl
: public wxObject
142 wxMenuImpl( wxMenu
* peer
) : m_peer(peer
)
146 virtual ~wxMenuImpl() ;
147 virtual void InsertOrAppend(wxMenuItem
*pItem
, size_t pos
) = 0;
148 virtual void Remove( wxMenuItem
*pItem
) = 0;
150 virtual void MakeRoot() = 0;
152 virtual void SetTitle( const wxString
& text
) = 0;
154 virtual WXHMENU
GetHMenu() = 0;
156 wxMenu
* GetWXPeer() { return m_peer
; }
158 virtual void PopUp( wxWindow
*win
, int x
, int y
) = 0;
160 static wxMenuImpl
* Create( wxMenu
* peer
, const wxString
& title
);
161 static wxMenuImpl
* CreateRootMenu( wxMenu
* peer
);
165 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl
)
170 class WXDLLIMPEXP_CORE wxWidgetImpl
: public wxObject
173 wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
= false );
175 virtual ~wxWidgetImpl();
179 bool IsRootControl() const { return m_isRootControl
; }
181 wxWindowMac
* GetWXPeer() const { return m_wxPeer
; }
183 bool IsOk() const { return GetWXWidget() != NULL
; }
185 // not only the control itself, but also all its parents must be visible
186 // in order for this function to return true
187 virtual bool IsVisible() const = 0;
188 // set the visibility of this widget (maybe latent)
189 virtual void SetVisibility( bool visible
) = 0;
191 virtual void Raise() = 0;
193 virtual void Lower() = 0;
195 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
) = 0;
197 virtual WXWidget
GetWXWidget() const = 0;
199 virtual void SetBackgroundColour( const wxColour
& col
) = 0;
201 // all coordinates in native parent widget relative coordinates
202 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
203 virtual void Move(int x
, int y
, int width
, int height
) = 0;
204 virtual void GetPosition( int &x
, int &y
) const = 0;
205 virtual void GetSize( int &width
, int &height
) const = 0;
206 virtual void SetControlSize( wxWindowVariant variant
) = 0;
208 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
) = 0;
209 virtual bool GetNeedsDisplay() const = 0;
211 virtual bool NeedsFocusRect() const;
212 virtual void SetNeedsFocusRect( bool needs
);
214 virtual bool NeedsFrame() const;
215 virtual void SetNeedsFrame( bool needs
);
217 virtual bool CanFocus() const = 0;
218 // return true if successful
219 virtual bool SetFocus() = 0;
220 virtual bool HasFocus() const = 0;
222 virtual void RemoveFromParent() = 0;
223 virtual void Embed( wxWidgetImpl
*parent
) = 0;
225 virtual void SetDefaultButton( bool isDefault
) = 0;
226 virtual void PerformClick() = 0;
227 virtual void SetLabel( const wxString
& title
, wxFontEncoding encoding
) = 0;
229 virtual void SetCursor( const wxCursor
& cursor
) = 0;
230 virtual void CaptureMouse() = 0;
231 virtual void ReleaseMouse() = 0;
233 virtual wxInt32
GetValue() const = 0;
234 virtual void SetValue( wxInt32 v
) = 0;
235 virtual void SetBitmap( const wxBitmap
& bitmap
) = 0;
236 virtual void SetupTabs( const wxNotebook
¬ebook
) =0;
237 virtual void GetBestRect( wxRect
*r
) const = 0;
238 virtual bool IsEnabled() const = 0;
239 virtual void Enable( bool enable
) = 0;
240 virtual void SetMinimum( wxInt32 v
) = 0;
241 virtual void SetMaximum( wxInt32 v
) = 0;
242 virtual wxInt32
GetMinimum() const = 0;
243 virtual wxInt32
GetMaximum() const = 0;
244 virtual void PulseGauge() = 0;
245 virtual void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
) = 0;
247 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true ) = 0;
249 // is the clicked event sent AFTER the state already changed, so no additional
250 // state changing logic is required from the outside
251 virtual bool ButtonClickDidStateChange() = 0;
253 virtual void InstallEventHandler( WXWidget control
= NULL
) = 0;
255 // static methods for associating native controls and their implementations
258 FindFromWXWidget(WXWidget control
);
260 static void RemoveAssociations( wxWidgetImpl
* impl
);
262 static void Associate( WXWidget control
, wxWidgetImpl
*impl
);
264 static WXWidget
FindFocus();
266 // static creation methods, must be implemented by all toolkits
268 static wxWidgetImplType
* CreateUserPane( wxWindowMac
* wxpeer
,
275 static wxWidgetImplType
* CreateContentView( wxNonOwnedWindow
* now
) ;
277 static wxWidgetImplType
* CreateButton( wxWindowMac
* wxpeer
,
280 const wxString
& label
,
286 static wxWidgetImplType
* CreateDisclosureTriangle( wxWindowMac
* wxpeer
,
289 const wxString
& label
,
295 static wxWidgetImplType
* CreateStaticLine( wxWindowMac
* wxpeer
,
303 static wxWidgetImplType
* CreateGroupBox( wxWindowMac
* wxpeer
,
306 const wxString
& label
,
312 static wxWidgetImplType
* CreateStaticText( wxWindowMac
* wxpeer
,
315 const wxString
& label
,
321 static wxWidgetImplType
* CreateTextControl( wxTextCtrl
* wxpeer
,
324 const wxString
& content
,
330 static wxWidgetImplType
* CreateSearchControl( wxTextCtrl
* wxpeer
,
333 const wxString
& content
,
339 static wxWidgetImplType
* CreateCheckBox( wxWindowMac
* wxpeer
,
342 const wxString
& label
,
348 static wxWidgetImplType
* CreateRadioButton( wxWindowMac
* wxpeer
,
351 const wxString
& label
,
357 static wxWidgetImplType
* CreateToggleButton( wxWindowMac
* wxpeer
,
360 const wxString
& label
,
366 static wxWidgetImplType
* CreateBitmapToggleButton( wxWindowMac
* wxpeer
,
369 const wxBitmap
& bitmap
,
375 static wxWidgetImplType
* CreateBitmapButton( wxWindowMac
* wxpeer
,
378 const wxBitmap
& bitmap
,
384 static wxWidgetImplType
* CreateTabView( wxWindowMac
* wxpeer
,
392 static wxWidgetImplType
* CreateGauge( wxWindowMac
* wxpeer
,
403 static wxWidgetImplType
* CreateSlider( wxWindowMac
* wxpeer
,
414 static wxWidgetImplType
* CreateSpinButton( wxWindowMac
* wxpeer
,
425 static wxWidgetImplType
* CreateScrollBar( wxWindowMac
* wxpeer
,
433 static wxWidgetImplType
* CreateChoice( wxWindowMac
* wxpeer
,
442 static wxWidgetImplType
* CreateListBox( wxWindowMac
* wxpeer
,
450 // converts from Toplevel-Content relative to local
451 static void Convert( wxPoint
*pt
, wxWidgetImpl
*from
, wxWidgetImpl
*to
);
453 bool m_isRootControl
;
454 wxWindowMac
* m_wxPeer
;
455 bool m_needsFocusRect
;
458 DECLARE_ABSTRACT_CLASS(wxWidgetImpl
)
462 // the interface to be implemented eg by a listbox
465 class WXDLLIMPEXP_CORE wxListWidgetColumn
468 virtual ~wxListWidgetColumn() {}
471 class WXDLLIMPEXP_CORE wxListWidgetCellValue
474 wxListWidgetCellValue() {}
475 virtual ~wxListWidgetCellValue() {}
477 virtual void Set( CFStringRef value
) = 0;
478 virtual void Set( const wxString
& value
) = 0;
479 virtual void Set( int value
) = 0;
481 virtual int GetIntValue() const = 0;
482 virtual wxString
GetStringValue() const = 0;
485 class WXDLLIMPEXP_CORE wxListWidgetImpl
488 wxListWidgetImpl() {}
489 virtual ~wxListWidgetImpl() { }
491 virtual wxListWidgetColumn
* InsertTextColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
492 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
493 virtual wxListWidgetColumn
* InsertCheckColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
494 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
498 // TODO will be replaced
499 virtual void ListDelete( unsigned int n
) = 0;
500 virtual void ListInsert( unsigned int n
) = 0;
501 virtual void ListClear() = 0;
505 virtual void ListDeselectAll() = 0;
506 virtual void ListSetSelection( unsigned int n
, bool select
, bool multi
) = 0;
507 virtual int ListGetSelection() const = 0;
508 virtual int ListGetSelections( wxArrayInt
& aSelections
) const = 0;
509 virtual bool ListIsSelected( unsigned int n
) const = 0;
513 virtual void ListScrollTo( unsigned int n
) = 0;
514 virtual void UpdateLine( unsigned int n
, wxListWidgetColumn
* col
= NULL
) = 0;
515 virtual void UpdateLineToEnd( unsigned int n
) = 0;
519 virtual unsigned int ListGetCount() const = 0;
523 // interface to be implemented by a textcontrol
526 class WXDLLIMPEXP_FWD_CORE wxTextAttr
;
528 // common interface for all implementations
529 class WXDLLIMPEXP_CORE wxTextWidgetImpl
533 wxTextWidgetImpl() {}
535 virtual ~wxTextWidgetImpl() {}
537 virtual bool CanFocus() const { return true; }
539 virtual wxString
GetStringValue() const = 0 ;
540 virtual void SetStringValue( const wxString
&val
) = 0 ;
541 virtual void SetSelection( long from
, long to
) = 0 ;
542 virtual void GetSelection( long* from
, long* to
) const = 0 ;
543 virtual void WriteText( const wxString
& str
) = 0 ;
545 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
546 virtual void Copy() ;
548 virtual void Paste() ;
549 virtual bool CanPaste() const ;
550 virtual void SetEditable( bool editable
) ;
551 virtual long GetLastPosition() const ;
552 virtual void Replace( long from
, long to
, const wxString
&str
) ;
553 virtual void Remove( long from
, long to
) ;
556 virtual bool HasOwnContextMenu() const
559 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
562 virtual void Clear() ;
563 virtual bool CanUndo() const;
564 virtual void Undo() ;
565 virtual bool CanRedo() const;
566 virtual void Redo() ;
567 virtual int GetNumberOfLines() const ;
568 virtual long XYToPosition(long x
, long y
) const;
569 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
570 virtual void ShowPosition(long WXUNUSED(pos
)) ;
571 virtual int GetLineLength(long lineNo
) const ;
572 virtual wxString
GetLineText(long lineNo
) const ;
573 virtual void CheckSpelling(bool WXUNUSED(check
)) { }
577 // common interface for search controls
580 class wxSearchWidgetImpl
583 wxSearchWidgetImpl(){}
584 virtual ~wxSearchWidgetImpl(){}
586 // search field options
587 virtual void ShowSearchButton( bool show
) = 0;
588 virtual bool IsSearchButtonVisible() const = 0;
590 virtual void ShowCancelButton( bool show
) = 0;
591 virtual bool IsCancelButtonVisible() const = 0;
593 virtual void SetSearchMenu( wxMenu
* menu
) = 0;
595 virtual void SetDescriptiveText(const wxString
& text
) = 0;
599 // toplevel window implementation class
602 class wxNonOwnedWindowImpl
: public wxObject
605 wxNonOwnedWindowImpl( wxNonOwnedWindow
* nonownedwnd
) : m_wxPeer(nonownedwnd
)
608 wxNonOwnedWindowImpl()
611 virtual ~wxNonOwnedWindowImpl()
615 virtual void Destroy()
619 virtual void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
620 long style
, long extraStyle
, const wxString
& name
) = 0;
623 virtual WXWindow
GetWXWindow() const = 0;
633 virtual bool Show(bool WXUNUSED(show
))
638 virtual bool ShowWithEffect(bool show
, wxShowEffect
WXUNUSED(effect
), unsigned WXUNUSED(timeout
))
643 virtual void Update()
647 virtual bool SetTransparent(wxByte
WXUNUSED(alpha
))
652 virtual bool SetBackgroundColour(const wxColour
& WXUNUSED(col
) )
657 virtual void SetExtraStyle( long WXUNUSED(exStyle
) )
661 virtual bool SetBackgroundStyle(wxBackgroundStyle
WXUNUSED(style
))
666 bool CanSetTransparent()
671 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
672 virtual void MoveWindow(int x
, int y
, int width
, int height
) = 0;
673 virtual void GetPosition( int &x
, int &y
) const = 0;
674 virtual void GetSize( int &width
, int &height
) const = 0;
676 virtual bool SetShape(const wxRegion
& WXUNUSED(region
))
681 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) = 0;
683 virtual bool IsMaximized() const = 0;
685 virtual bool IsIconized() const= 0;
687 virtual void Iconize( bool iconize
)= 0;
689 virtual void Maximize(bool maximize
) = 0;
691 virtual bool IsFullScreen() const= 0;
693 virtual bool ShowFullScreen(bool show
, long style
)= 0;
695 virtual void RequestUserAttention(int flags
) = 0;
697 virtual void ScreenToWindow( int *x
, int *y
) = 0;
699 virtual void WindowToScreen( int *x
, int *y
) = 0;
701 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
703 // static creation methods, must be implemented by all toolkits
705 static wxNonOwnedWindowImpl
* CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
706 long style
, long extraStyle
, const wxString
& name
) ;
709 wxNonOwnedWindow
* m_wxPeer
;
710 DECLARE_ABSTRACT_CLASS(wxNonOwnedWindowImpl
)
715 //---------------------------------------------------------------------------
716 // cocoa bridging utilities
717 //---------------------------------------------------------------------------
719 bool wxMacInitCocoa();
721 class WXDLLIMPEXP_CORE wxMacAutoreleasePool
724 wxMacAutoreleasePool();
725 ~wxMacAutoreleasePool();
732 void wxMacCocoaRelease( void* obj
);
733 void wxMacCocoaAutorelease( void* obj
);
734 void* wxMacCocoaRetain( void* obj
);
738 // _WX_PRIVATE_CORE_H_