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 // Define helper macros allowing to insert small snippets of code to be
25 // compiled for high enough OS X version only: this shouldn't be abused for
26 // anything big but it's handy for e.g. specifying OS X 10.6-only protocols in
27 // the Objective C classes declarations when they're not supported under the
29 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
30 #define wxOSX_10_6_AND_LATER(x) x
32 #define wxOSX_10_6_AND_LATER(x)
35 #if wxOSX_USE_COCOA_OR_CARBON
37 WXDLLIMPEXP_BASE
long UMAGetSystemVersion() ;
39 void WXDLLIMPEXP_CORE
wxMacStringToPascal( const wxString
&from
, unsigned char * to
);
40 wxString WXDLLIMPEXP_CORE
wxMacMakeStringFromPascal( const unsigned char * from
);
47 #include <CoreGraphics/CoreGraphics.h>
49 #include <ApplicationServices/ApplicationServices.h>
52 #include "wx/bitmap.h"
53 #include "wx/window.h"
55 class WXDLLIMPEXP_CORE wxMacCGContextStateSaver
57 wxDECLARE_NO_COPY_CLASS(wxMacCGContextStateSaver
);
60 wxMacCGContextStateSaver( CGContextRef cg
)
63 CGContextSaveGState( cg
);
65 ~wxMacCGContextStateSaver()
67 CGContextRestoreGState( m_cg
);
73 class WXDLLIMPEXP_CORE wxDeferredObjectDeleter
: public wxObject
76 wxDeferredObjectDeleter( wxObject
* obj
) : m_obj(obj
)
79 virtual ~wxDeferredObjectDeleter()
89 WXDLLIMPEXP_CORE CGImageRef
wxMacCreateCGImageFromBitmap( const wxBitmap
& bitmap
);
91 WXDLLIMPEXP_CORE CGDataProviderRef
wxMacCGDataProviderCreateWithCFData( CFDataRef data
);
92 WXDLLIMPEXP_CORE CGDataConsumerRef
wxMacCGDataConsumerCreateWithCFData( CFMutableDataRef data
);
93 WXDLLIMPEXP_CORE CGDataProviderRef
wxMacCGDataProviderCreateWithMemoryBuffer( const wxMemoryBuffer
& buf
);
95 CGColorSpaceRef WXDLLIMPEXP_CORE
wxMacGetGenericRGBColorSpace(void);
99 extern wxWindow
* g_MacLastWindow
;
100 class wxNonOwnedWindow
;
102 // temporary typedef so that no additional casts are necessary within carbon code at the moment
109 WXDLLIMPEXP_CORE wxWindowMac
* wxFindWindowFromWXWidget(WXWidget inControl
);
112 typedef wxMacControl wxWidgetImplType
;
114 typedef wxWidgetImpl wxWidgetImplType
;
118 class wxMenuItemImpl
: public wxObject
121 wxMenuItemImpl( wxMenuItem
* peer
) : m_peer(peer
)
125 virtual ~wxMenuItemImpl() ;
126 virtual void SetBitmap( const wxBitmap
& bitmap
) = 0;
127 virtual void Enable( bool enable
) = 0;
128 virtual void Check( bool check
) = 0;
129 virtual void SetLabel( const wxString
& text
, wxAcceleratorEntry
*entry
) = 0;
130 virtual void Hide( bool hide
= true ) = 0;
132 virtual void * GetHMenuItem() = 0;
134 wxMenuItem
* GetWXPeer() { return m_peer
; }
136 static wxMenuItemImpl
* Create( wxMenuItem
* peer
, wxMenu
*pParentMenu
,
138 const wxString
& text
,
139 wxAcceleratorEntry
*entry
,
140 const wxString
& strHelp
,
147 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl
)
150 class wxMenuImpl
: public wxObject
153 wxMenuImpl( wxMenu
* peer
) : m_peer(peer
)
157 virtual ~wxMenuImpl() ;
158 virtual void InsertOrAppend(wxMenuItem
*pItem
, size_t pos
) = 0;
159 virtual void Remove( wxMenuItem
*pItem
) = 0;
161 virtual void MakeRoot() = 0;
163 virtual void SetTitle( const wxString
& text
) = 0;
165 virtual WXHMENU
GetHMenu() = 0;
167 wxMenu
* GetWXPeer() { return m_peer
; }
169 virtual void PopUp( wxWindow
*win
, int x
, int y
) = 0;
171 static wxMenuImpl
* Create( wxMenu
* peer
, const wxString
& title
);
172 static wxMenuImpl
* CreateRootMenu( wxMenu
* peer
);
176 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl
)
181 class WXDLLIMPEXP_CORE wxWidgetImpl
: public wxObject
184 wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
= false );
186 virtual ~wxWidgetImpl();
190 bool IsRootControl() const { return m_isRootControl
; }
192 wxWindowMac
* GetWXPeer() const { return m_wxPeer
; }
194 bool IsOk() const { return GetWXWidget() != NULL
; }
196 // not only the control itself, but also all its parents must be visible
197 // in order for this function to return true
198 virtual bool IsVisible() const = 0;
199 // set the visibility of this widget (maybe latent)
200 virtual void SetVisibility( bool visible
) = 0;
202 virtual bool ShowWithEffect(bool WXUNUSED(show
),
203 wxShowEffect
WXUNUSED(effect
),
204 unsigned WXUNUSED(timeout
))
209 virtual void Raise() = 0;
211 virtual void Lower() = 0;
213 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
) = 0;
215 virtual WXWidget
GetWXWidget() const = 0;
217 virtual void SetBackgroundColour( const wxColour
& col
) = 0;
219 // all coordinates in native parent widget relative coordinates
220 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
221 virtual void Move(int x
, int y
, int width
, int height
) = 0;
222 virtual void GetPosition( int &x
, int &y
) const = 0;
223 virtual void GetSize( int &width
, int &height
) const = 0;
224 virtual void SetControlSize( wxWindowVariant variant
) = 0;
226 // native view coordinates are topleft to bottom right (flipped regarding CoreGraphics origin)
227 virtual bool IsFlipped() const { return true; }
229 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
) = 0;
230 virtual bool GetNeedsDisplay() const = 0;
232 virtual bool NeedsFocusRect() const;
233 virtual void SetNeedsFocusRect( bool needs
);
235 virtual bool NeedsFrame() const;
236 virtual void SetNeedsFrame( bool needs
);
238 virtual bool CanFocus() const = 0;
239 // return true if successful
240 virtual bool SetFocus() = 0;
241 virtual bool HasFocus() const = 0;
243 virtual void RemoveFromParent() = 0;
244 virtual void Embed( wxWidgetImpl
*parent
) = 0;
246 virtual void SetDefaultButton( bool isDefault
) = 0;
247 virtual void PerformClick() = 0;
248 virtual void SetLabel( const wxString
& title
, wxFontEncoding encoding
) = 0;
250 virtual void SetCursor( const wxCursor
& cursor
) = 0;
251 virtual void CaptureMouse() = 0;
252 virtual void ReleaseMouse() = 0;
254 virtual wxInt32
GetValue() const = 0;
255 virtual void SetValue( wxInt32 v
) = 0;
256 virtual wxBitmap
GetBitmap() const = 0;
257 virtual void SetBitmap( const wxBitmap
& bitmap
) = 0;
258 virtual void SetBitmapPosition( wxDirection dir
) = 0;
259 virtual void SetupTabs( const wxNotebook
¬ebook
) =0;
260 virtual void GetBestRect( wxRect
*r
) const = 0;
261 virtual bool IsEnabled() const = 0;
262 virtual void Enable( bool enable
) = 0;
263 virtual void SetMinimum( wxInt32 v
) = 0;
264 virtual void SetMaximum( wxInt32 v
) = 0;
265 virtual wxInt32
GetMinimum() const = 0;
266 virtual wxInt32
GetMaximum() const = 0;
267 virtual void PulseGauge() = 0;
268 virtual void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
) = 0;
270 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true ) = 0;
272 virtual void SetToolTip(wxToolTip
* WXUNUSED(tooltip
)) { }
274 // is the clicked event sent AFTER the state already changed, so no additional
275 // state changing logic is required from the outside
276 virtual bool ButtonClickDidStateChange() = 0;
278 virtual void InstallEventHandler( WXWidget control
= NULL
) = 0;
280 // static methods for associating native controls and their implementations
283 FindFromWXWidget(WXWidget control
);
285 static void RemoveAssociations( wxWidgetImpl
* impl
);
287 static void Associate( WXWidget control
, wxWidgetImpl
*impl
);
289 static WXWidget
FindFocus();
291 // static creation methods, must be implemented by all toolkits
293 static wxWidgetImplType
* CreateUserPane( wxWindowMac
* wxpeer
,
300 static wxWidgetImplType
* CreateContentView( wxNonOwnedWindow
* now
) ;
302 static wxWidgetImplType
* CreateButton( wxWindowMac
* wxpeer
,
305 const wxString
& label
,
311 static wxWidgetImplType
* CreateDisclosureTriangle( wxWindowMac
* wxpeer
,
314 const wxString
& label
,
320 static wxWidgetImplType
* CreateStaticLine( wxWindowMac
* wxpeer
,
328 static wxWidgetImplType
* CreateGroupBox( wxWindowMac
* wxpeer
,
331 const wxString
& label
,
337 static wxWidgetImplType
* CreateStaticText( wxWindowMac
* wxpeer
,
340 const wxString
& label
,
346 static wxWidgetImplType
* CreateTextControl( wxTextCtrl
* wxpeer
,
349 const wxString
& content
,
355 static wxWidgetImplType
* CreateSearchControl( wxTextCtrl
* wxpeer
,
358 const wxString
& content
,
364 static wxWidgetImplType
* CreateCheckBox( wxWindowMac
* wxpeer
,
367 const wxString
& label
,
373 static wxWidgetImplType
* CreateRadioButton( wxWindowMac
* wxpeer
,
376 const wxString
& label
,
382 static wxWidgetImplType
* CreateToggleButton( wxWindowMac
* wxpeer
,
385 const wxString
& label
,
391 static wxWidgetImplType
* CreateBitmapToggleButton( wxWindowMac
* wxpeer
,
394 const wxBitmap
& bitmap
,
400 static wxWidgetImplType
* CreateBitmapButton( wxWindowMac
* wxpeer
,
403 const wxBitmap
& bitmap
,
409 static wxWidgetImplType
* CreateTabView( wxWindowMac
* wxpeer
,
417 static wxWidgetImplType
* CreateGauge( wxWindowMac
* wxpeer
,
428 static wxWidgetImplType
* CreateSlider( wxWindowMac
* wxpeer
,
439 static wxWidgetImplType
* CreateSpinButton( wxWindowMac
* wxpeer
,
450 static wxWidgetImplType
* CreateScrollBar( wxWindowMac
* wxpeer
,
458 static wxWidgetImplType
* CreateChoice( wxWindowMac
* wxpeer
,
467 static wxWidgetImplType
* CreateListBox( wxWindowMac
* wxpeer
,
476 static wxWidgetImplType
* CreateComboBox( wxWindowMac
* wxpeer
,
486 // converts from Toplevel-Content relative to local
487 static void Convert( wxPoint
*pt
, wxWidgetImpl
*from
, wxWidgetImpl
*to
);
489 bool m_isRootControl
;
490 wxWindowMac
* m_wxPeer
;
491 bool m_needsFocusRect
;
494 DECLARE_ABSTRACT_CLASS(wxWidgetImpl
)
498 // the interface to be implemented eg by a listbox
501 class WXDLLIMPEXP_CORE wxListWidgetColumn
504 virtual ~wxListWidgetColumn() {}
507 class WXDLLIMPEXP_CORE wxListWidgetCellValue
510 wxListWidgetCellValue() {}
511 virtual ~wxListWidgetCellValue() {}
513 virtual void Set( CFStringRef value
) = 0;
514 virtual void Set( const wxString
& value
) = 0;
515 virtual void Set( int value
) = 0;
516 virtual void Check( bool check
);
518 virtual bool IsChecked() const;
519 virtual int GetIntValue() const = 0;
520 virtual wxString
GetStringValue() const = 0;
523 class WXDLLIMPEXP_CORE wxListWidgetImpl
526 wxListWidgetImpl() {}
527 virtual ~wxListWidgetImpl() { }
529 virtual wxListWidgetColumn
* InsertTextColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
530 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
531 virtual wxListWidgetColumn
* InsertCheckColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
532 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
536 // TODO will be replaced
537 virtual void ListDelete( unsigned int n
) = 0;
538 virtual void ListInsert( unsigned int n
) = 0;
539 virtual void ListClear() = 0;
543 virtual void ListDeselectAll() = 0;
544 virtual void ListSetSelection( unsigned int n
, bool select
, bool multi
) = 0;
545 virtual int ListGetSelection() const = 0;
546 virtual int ListGetSelections( wxArrayInt
& aSelections
) const = 0;
547 virtual bool ListIsSelected( unsigned int n
) const = 0;
551 virtual void ListScrollTo( unsigned int n
) = 0;
552 virtual void UpdateLine( unsigned int n
, wxListWidgetColumn
* col
= NULL
) = 0;
553 virtual void UpdateLineToEnd( unsigned int n
) = 0;
557 virtual unsigned int ListGetCount() const = 0;
561 // interface to be implemented by a textcontrol
564 class WXDLLIMPEXP_FWD_CORE wxTextAttr
;
566 // common interface for all implementations
567 class WXDLLIMPEXP_CORE wxTextWidgetImpl
571 wxTextWidgetImpl() {}
573 virtual ~wxTextWidgetImpl() {}
575 virtual bool CanFocus() const { return true; }
577 virtual wxString
GetStringValue() const = 0 ;
578 virtual void SetStringValue( const wxString
&val
) = 0 ;
579 virtual void SetSelection( long from
, long to
) = 0 ;
580 virtual void GetSelection( long* from
, long* to
) const = 0 ;
581 virtual void WriteText( const wxString
& str
) = 0 ;
583 virtual bool GetStyle( long position
, wxTextAttr
& style
);
584 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
585 virtual void Copy() ;
587 virtual void Paste() ;
588 virtual bool CanPaste() const ;
589 virtual void SetEditable( bool editable
) ;
590 virtual long GetLastPosition() const ;
591 virtual void Replace( long from
, long to
, const wxString
&str
) ;
592 virtual void Remove( long from
, long to
) ;
595 virtual bool HasOwnContextMenu() const
598 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
601 virtual void Clear() ;
602 virtual bool CanUndo() const;
603 virtual void Undo() ;
604 virtual bool CanRedo() const;
605 virtual void Redo() ;
606 virtual int GetNumberOfLines() const ;
607 virtual long XYToPosition(long x
, long y
) const;
608 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
609 virtual void ShowPosition(long WXUNUSED(pos
)) ;
610 virtual int GetLineLength(long lineNo
) const ;
611 virtual wxString
GetLineText(long lineNo
) const ;
612 virtual void CheckSpelling(bool WXUNUSED(check
)) { }
614 virtual wxSize
GetBestSize() const { return wxDefaultSize
; }
617 // common interface for all implementations
618 class WXDLLIMPEXP_CORE wxComboWidgetImpl
622 wxComboWidgetImpl() {}
624 virtual ~wxComboWidgetImpl() {}
626 virtual int GetSelectedItem() const { return -1; };
627 virtual void SetSelectedItem(int WXUNUSED(item
)) {};
629 virtual int GetNumberOfItems() const { return -1; };
631 virtual void InsertItem(int WXUNUSED(pos
), const wxString
& WXUNUSED(item
)) {}
633 virtual void RemoveItem(int WXUNUSED(pos
)) {}
635 virtual void Clear() {}
637 virtual wxString
GetStringAtIndex(int WXUNUSED(pos
)) const { return wxEmptyString
; }
639 virtual int FindString(const wxString
& WXUNUSED(text
)) const { return -1; }
643 // common interface for buttons
650 virtual ~wxButtonImpl(){}
652 virtual void SetPressedBitmap( const wxBitmap
& bitmap
) = 0;
656 // common interface for search controls
659 class wxSearchWidgetImpl
662 wxSearchWidgetImpl(){}
663 virtual ~wxSearchWidgetImpl(){}
665 // search field options
666 virtual void ShowSearchButton( bool show
) = 0;
667 virtual bool IsSearchButtonVisible() const = 0;
669 virtual void ShowCancelButton( bool show
) = 0;
670 virtual bool IsCancelButtonVisible() const = 0;
672 virtual void SetSearchMenu( wxMenu
* menu
) = 0;
674 virtual void SetDescriptiveText(const wxString
& text
) = 0;
678 // toplevel window implementation class
681 class wxNonOwnedWindowImpl
: public wxObject
684 wxNonOwnedWindowImpl( wxNonOwnedWindow
* nonownedwnd
) : m_wxPeer(nonownedwnd
)
687 wxNonOwnedWindowImpl()
690 virtual ~wxNonOwnedWindowImpl()
694 virtual void WillBeDestroyed()
698 virtual void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
699 long style
, long extraStyle
, const wxString
& name
) = 0;
702 virtual WXWindow
GetWXWindow() const = 0;
712 virtual bool Show(bool WXUNUSED(show
))
717 virtual bool ShowWithEffect(bool show
, wxShowEffect
WXUNUSED(effect
), unsigned WXUNUSED(timeout
))
722 virtual void Update()
726 virtual bool SetTransparent(wxByte
WXUNUSED(alpha
))
731 virtual bool SetBackgroundColour(const wxColour
& WXUNUSED(col
) )
736 virtual void SetExtraStyle( long WXUNUSED(exStyle
) )
740 virtual void SetWindowStyleFlag( long WXUNUSED(style
) )
744 virtual bool SetBackgroundStyle(wxBackgroundStyle
WXUNUSED(style
))
749 bool CanSetTransparent()
754 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
755 virtual void MoveWindow(int x
, int y
, int width
, int height
) = 0;
756 virtual void GetPosition( int &x
, int &y
) const = 0;
757 virtual void GetSize( int &width
, int &height
) const = 0;
759 virtual bool SetShape(const wxRegion
& WXUNUSED(region
))
764 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) = 0;
766 virtual bool IsMaximized() const = 0;
768 virtual bool IsIconized() const= 0;
770 virtual void Iconize( bool iconize
)= 0;
772 virtual void Maximize(bool maximize
) = 0;
774 virtual bool IsFullScreen() const= 0;
776 virtual void ShowWithoutActivating() { Show(true); }
778 virtual bool ShowFullScreen(bool show
, long style
)= 0;
780 virtual void RequestUserAttention(int flags
) = 0;
782 virtual void ScreenToWindow( int *x
, int *y
) = 0;
784 virtual void WindowToScreen( int *x
, int *y
) = 0;
786 virtual bool IsActive() = 0;
788 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
790 // static creation methods, must be implemented by all toolkits
792 static wxNonOwnedWindowImpl
* CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
793 long style
, long extraStyle
, const wxString
& name
) ;
795 virtual void SetModified(bool WXUNUSED(modified
)) { }
796 virtual bool IsModified() const { return false; }
799 wxNonOwnedWindow
* m_wxPeer
;
800 DECLARE_ABSTRACT_CLASS(wxNonOwnedWindowImpl
)
805 //---------------------------------------------------------------------------
806 // cocoa bridging utilities
807 //---------------------------------------------------------------------------
809 bool wxMacInitCocoa();
811 class WXDLLIMPEXP_CORE wxMacAutoreleasePool
814 wxMacAutoreleasePool();
815 ~wxMacAutoreleasePool();
822 void wxMacCocoaRelease( void* obj
);
823 void wxMacCocoaAutorelease( void* obj
);
824 void* wxMacCocoaRetain( void* obj
);
828 // _WX_PRIVATE_CORE_H_