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;
218 virtual bool SetBackgroundStyle(wxBackgroundStyle style
) = 0;
220 // all coordinates in native parent widget relative coordinates
221 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
222 virtual void Move(int x
, int y
, int width
, int height
) = 0;
223 virtual void GetPosition( int &x
, int &y
) const = 0;
224 virtual void GetSize( int &width
, int &height
) const = 0;
225 virtual void SetControlSize( wxWindowVariant variant
) = 0;
227 // native view coordinates are topleft to bottom right (flipped regarding CoreGraphics origin)
228 virtual bool IsFlipped() const { return true; }
230 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
) = 0;
231 virtual bool GetNeedsDisplay() const = 0;
233 virtual bool NeedsFocusRect() const;
234 virtual void SetNeedsFocusRect( bool needs
);
236 virtual bool NeedsFrame() const;
237 virtual void SetNeedsFrame( bool needs
);
239 virtual bool CanFocus() const = 0;
240 // return true if successful
241 virtual bool SetFocus() = 0;
242 virtual bool HasFocus() const = 0;
244 virtual void RemoveFromParent() = 0;
245 virtual void Embed( wxWidgetImpl
*parent
) = 0;
247 virtual void SetDefaultButton( bool isDefault
) = 0;
248 virtual void PerformClick() = 0;
249 virtual void SetLabel( const wxString
& title
, wxFontEncoding encoding
) = 0;
251 virtual void SetCursor( const wxCursor
& cursor
) = 0;
252 virtual void CaptureMouse() = 0;
253 virtual void ReleaseMouse() = 0;
255 virtual wxInt32
GetValue() const = 0;
256 virtual void SetValue( wxInt32 v
) = 0;
257 virtual wxBitmap
GetBitmap() const = 0;
258 virtual void SetBitmap( const wxBitmap
& bitmap
) = 0;
259 virtual void SetBitmapPosition( wxDirection dir
) = 0;
260 virtual void SetupTabs( const wxNotebook
¬ebook
) =0;
261 virtual void GetBestRect( wxRect
*r
) const = 0;
262 virtual bool IsEnabled() const = 0;
263 virtual void Enable( bool enable
) = 0;
264 virtual void SetMinimum( wxInt32 v
) = 0;
265 virtual void SetMaximum( wxInt32 v
) = 0;
266 virtual wxInt32
GetMinimum() const = 0;
267 virtual wxInt32
GetMaximum() const = 0;
268 virtual void PulseGauge() = 0;
269 virtual void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
) = 0;
271 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true ) = 0;
273 virtual void SetToolTip(wxToolTip
* WXUNUSED(tooltip
)) { }
275 // is the clicked event sent AFTER the state already changed, so no additional
276 // state changing logic is required from the outside
277 virtual bool ButtonClickDidStateChange() = 0;
279 virtual void InstallEventHandler( WXWidget control
= NULL
) = 0;
281 // Mechanism used to keep track of whether a change should send an event
282 // Do SendEvents(false) when starting actions that would trigger programmatic events
283 // and SendEvents(true) at the end of the block.
284 virtual void SendEvents(bool shouldSendEvents
) { m_shouldSendEvents
= shouldSendEvents
; }
285 virtual bool ShouldSendEvents() { return m_shouldSendEvents
; }
287 // static methods for associating native controls and their implementations
290 FindFromWXWidget(WXWidget control
);
292 static void RemoveAssociations( wxWidgetImpl
* impl
);
294 static void Associate( WXWidget control
, wxWidgetImpl
*impl
);
296 static WXWidget
FindFocus();
298 // static creation methods, must be implemented by all toolkits
300 static wxWidgetImplType
* CreateUserPane( wxWindowMac
* wxpeer
,
307 static wxWidgetImplType
* CreateContentView( wxNonOwnedWindow
* now
) ;
309 static wxWidgetImplType
* CreateButton( wxWindowMac
* wxpeer
,
312 const wxString
& label
,
318 static wxWidgetImplType
* CreateDisclosureTriangle( wxWindowMac
* wxpeer
,
321 const wxString
& label
,
327 static wxWidgetImplType
* CreateStaticLine( wxWindowMac
* wxpeer
,
335 static wxWidgetImplType
* CreateGroupBox( wxWindowMac
* wxpeer
,
338 const wxString
& label
,
344 static wxWidgetImplType
* CreateStaticText( wxWindowMac
* wxpeer
,
347 const wxString
& label
,
353 static wxWidgetImplType
* CreateTextControl( wxTextCtrl
* wxpeer
,
356 const wxString
& content
,
362 static wxWidgetImplType
* CreateSearchControl( wxTextCtrl
* wxpeer
,
365 const wxString
& content
,
371 static wxWidgetImplType
* CreateCheckBox( wxWindowMac
* wxpeer
,
374 const wxString
& label
,
380 static wxWidgetImplType
* CreateRadioButton( wxWindowMac
* wxpeer
,
383 const wxString
& label
,
389 static wxWidgetImplType
* CreateToggleButton( wxWindowMac
* wxpeer
,
392 const wxString
& label
,
398 static wxWidgetImplType
* CreateBitmapToggleButton( wxWindowMac
* wxpeer
,
401 const wxBitmap
& bitmap
,
407 static wxWidgetImplType
* CreateBitmapButton( wxWindowMac
* wxpeer
,
410 const wxBitmap
& bitmap
,
416 static wxWidgetImplType
* CreateTabView( wxWindowMac
* wxpeer
,
424 static wxWidgetImplType
* CreateGauge( wxWindowMac
* wxpeer
,
435 static wxWidgetImplType
* CreateSlider( wxWindowMac
* wxpeer
,
446 static wxWidgetImplType
* CreateSpinButton( wxWindowMac
* wxpeer
,
457 static wxWidgetImplType
* CreateScrollBar( wxWindowMac
* wxpeer
,
465 static wxWidgetImplType
* CreateChoice( wxWindowMac
* wxpeer
,
474 static wxWidgetImplType
* CreateListBox( wxWindowMac
* wxpeer
,
483 static wxWidgetImplType
* CreateComboBox( wxWindowMac
* wxpeer
,
493 // converts from Toplevel-Content relative to local
494 static void Convert( wxPoint
*pt
, wxWidgetImpl
*from
, wxWidgetImpl
*to
);
496 bool m_isRootControl
;
497 wxWindowMac
* m_wxPeer
;
498 bool m_needsFocusRect
;
500 bool m_shouldSendEvents
;
502 DECLARE_ABSTRACT_CLASS(wxWidgetImpl
)
506 // the interface to be implemented eg by a listbox
509 class WXDLLIMPEXP_CORE wxListWidgetColumn
512 virtual ~wxListWidgetColumn() {}
515 class WXDLLIMPEXP_CORE wxListWidgetCellValue
518 wxListWidgetCellValue() {}
519 virtual ~wxListWidgetCellValue() {}
521 virtual void Set( CFStringRef value
) = 0;
522 virtual void Set( const wxString
& value
) = 0;
523 virtual void Set( int value
) = 0;
524 virtual void Check( bool check
);
526 virtual bool IsChecked() const;
527 virtual int GetIntValue() const = 0;
528 virtual wxString
GetStringValue() const = 0;
531 class WXDLLIMPEXP_CORE wxListWidgetImpl
534 wxListWidgetImpl() {}
535 virtual ~wxListWidgetImpl() { }
537 virtual wxListWidgetColumn
* InsertTextColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
538 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
539 virtual wxListWidgetColumn
* InsertCheckColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
540 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
544 // TODO will be replaced
545 virtual void ListDelete( unsigned int n
) = 0;
546 virtual void ListInsert( unsigned int n
) = 0;
547 virtual void ListClear() = 0;
551 virtual void ListDeselectAll() = 0;
552 virtual void ListSetSelection( unsigned int n
, bool select
, bool multi
) = 0;
553 virtual int ListGetSelection() const = 0;
554 virtual int ListGetSelections( wxArrayInt
& aSelections
) const = 0;
555 virtual bool ListIsSelected( unsigned int n
) const = 0;
559 virtual void ListScrollTo( unsigned int n
) = 0;
560 virtual void UpdateLine( unsigned int n
, wxListWidgetColumn
* col
= NULL
) = 0;
561 virtual void UpdateLineToEnd( unsigned int n
) = 0;
565 virtual unsigned int ListGetCount() const = 0;
569 // interface to be implemented by a textcontrol
572 class WXDLLIMPEXP_FWD_CORE wxTextAttr
;
574 // common interface for all implementations
575 class WXDLLIMPEXP_CORE wxTextWidgetImpl
579 wxTextWidgetImpl() {}
581 virtual ~wxTextWidgetImpl() {}
583 virtual bool CanFocus() const { return true; }
585 virtual wxString
GetStringValue() const = 0 ;
586 virtual void SetStringValue( const wxString
&val
) = 0 ;
587 virtual void SetSelection( long from
, long to
) = 0 ;
588 virtual void GetSelection( long* from
, long* to
) const = 0 ;
589 virtual void WriteText( const wxString
& str
) = 0 ;
591 virtual bool GetStyle( long position
, wxTextAttr
& style
);
592 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
593 virtual void Copy() ;
595 virtual void Paste() ;
596 virtual bool CanPaste() const ;
597 virtual void SetEditable( bool editable
) ;
598 virtual long GetLastPosition() const ;
599 virtual void Replace( long from
, long to
, const wxString
&str
) ;
600 virtual void Remove( long from
, long to
) ;
603 virtual bool HasOwnContextMenu() const
606 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
609 virtual void Clear() ;
610 virtual bool CanUndo() const;
611 virtual void Undo() ;
612 virtual bool CanRedo() const;
613 virtual void Redo() ;
614 virtual int GetNumberOfLines() const ;
615 virtual long XYToPosition(long x
, long y
) const;
616 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
617 virtual void ShowPosition(long WXUNUSED(pos
)) ;
618 virtual int GetLineLength(long lineNo
) const ;
619 virtual wxString
GetLineText(long lineNo
) const ;
620 virtual void CheckSpelling(bool WXUNUSED(check
)) { }
622 virtual wxSize
GetBestSize() const { return wxDefaultSize
; }
625 // common interface for all implementations
626 class WXDLLIMPEXP_CORE wxComboWidgetImpl
630 wxComboWidgetImpl() {}
632 virtual ~wxComboWidgetImpl() {}
634 virtual int GetSelectedItem() const { return -1; };
635 virtual void SetSelectedItem(int WXUNUSED(item
)) {};
637 virtual int GetNumberOfItems() const { return -1; };
639 virtual void InsertItem(int WXUNUSED(pos
), const wxString
& WXUNUSED(item
)) {}
641 virtual void RemoveItem(int WXUNUSED(pos
)) {}
643 virtual void Clear() {}
645 virtual wxString
GetStringAtIndex(int WXUNUSED(pos
)) const { return wxEmptyString
; }
647 virtual int FindString(const wxString
& WXUNUSED(text
)) const { return -1; }
651 // common interface for buttons
658 virtual ~wxButtonImpl(){}
660 virtual void SetPressedBitmap( const wxBitmap
& bitmap
) = 0;
664 // common interface for search controls
667 class wxSearchWidgetImpl
670 wxSearchWidgetImpl(){}
671 virtual ~wxSearchWidgetImpl(){}
673 // search field options
674 virtual void ShowSearchButton( bool show
) = 0;
675 virtual bool IsSearchButtonVisible() const = 0;
677 virtual void ShowCancelButton( bool show
) = 0;
678 virtual bool IsCancelButtonVisible() const = 0;
680 virtual void SetSearchMenu( wxMenu
* menu
) = 0;
682 virtual void SetDescriptiveText(const wxString
& text
) = 0;
686 // toplevel window implementation class
689 class wxNonOwnedWindowImpl
: public wxObject
692 wxNonOwnedWindowImpl( wxNonOwnedWindow
* nonownedwnd
) : m_wxPeer(nonownedwnd
)
695 wxNonOwnedWindowImpl()
698 virtual ~wxNonOwnedWindowImpl()
702 virtual void WillBeDestroyed()
706 virtual void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
707 long style
, long extraStyle
, const wxString
& name
) = 0;
710 virtual WXWindow
GetWXWindow() const = 0;
720 virtual bool Show(bool WXUNUSED(show
))
725 virtual bool ShowWithEffect(bool show
, wxShowEffect
WXUNUSED(effect
), unsigned WXUNUSED(timeout
))
730 virtual void Update()
734 virtual bool SetTransparent(wxByte
WXUNUSED(alpha
))
739 virtual bool SetBackgroundColour(const wxColour
& WXUNUSED(col
) )
744 virtual void SetExtraStyle( long WXUNUSED(exStyle
) )
748 virtual void SetWindowStyleFlag( long WXUNUSED(style
) )
752 virtual bool SetBackgroundStyle(wxBackgroundStyle
WXUNUSED(style
))
757 bool CanSetTransparent()
762 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
763 virtual void MoveWindow(int x
, int y
, int width
, int height
) = 0;
764 virtual void GetPosition( int &x
, int &y
) const = 0;
765 virtual void GetSize( int &width
, int &height
) const = 0;
767 virtual bool SetShape(const wxRegion
& WXUNUSED(region
))
772 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) = 0;
774 virtual bool IsMaximized() const = 0;
776 virtual bool IsIconized() const= 0;
778 virtual void Iconize( bool iconize
)= 0;
780 virtual void Maximize(bool maximize
) = 0;
782 virtual bool IsFullScreen() const= 0;
784 virtual void ShowWithoutActivating() { Show(true); }
786 virtual bool ShowFullScreen(bool show
, long style
)= 0;
788 virtual void RequestUserAttention(int flags
) = 0;
790 virtual void ScreenToWindow( int *x
, int *y
) = 0;
792 virtual void WindowToScreen( int *x
, int *y
) = 0;
794 virtual bool IsActive() = 0;
796 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
798 static wxNonOwnedWindowImpl
*
799 FindFromWXWindow(WXWindow window
);
801 static void RemoveAssociations( wxNonOwnedWindowImpl
* impl
);
803 static void Associate( WXWindow window
, wxNonOwnedWindowImpl
*impl
);
805 // static creation methods, must be implemented by all toolkits
807 static wxNonOwnedWindowImpl
* CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, WXWindow native
) ;
809 static wxNonOwnedWindowImpl
* CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
810 long style
, long extraStyle
, const wxString
& name
) ;
812 virtual void SetModified(bool WXUNUSED(modified
)) { }
813 virtual bool IsModified() const { return false; }
816 wxNonOwnedWindow
* m_wxPeer
;
817 DECLARE_ABSTRACT_CLASS(wxNonOwnedWindowImpl
)
822 //---------------------------------------------------------------------------
823 // cocoa bridging utilities
824 //---------------------------------------------------------------------------
826 bool wxMacInitCocoa();
828 class WXDLLIMPEXP_CORE wxMacAutoreleasePool
831 wxMacAutoreleasePool();
832 ~wxMacAutoreleasePool();
839 void wxMacCocoaRelease( void* obj
);
840 void wxMacCocoaAutorelease( void* obj
);
841 void* wxMacCocoaRetain( void* obj
);
845 // _WX_PRIVATE_CORE_H_