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
110 WXDLLIMPEXP_CORE wxWindowMac
* wxFindWindowFromWXWidget(WXWidget inControl
);
113 typedef wxMacControl wxWidgetImplType
;
115 typedef wxWidgetImpl wxWidgetImplType
;
119 class wxMenuItemImpl
: public wxObject
122 wxMenuItemImpl( wxMenuItem
* peer
) : m_peer(peer
)
126 virtual ~wxMenuItemImpl() ;
127 virtual void SetBitmap( const wxBitmap
& bitmap
) = 0;
128 virtual void Enable( bool enable
) = 0;
129 virtual void Check( bool check
) = 0;
130 virtual void SetLabel( const wxString
& text
, wxAcceleratorEntry
*entry
) = 0;
131 virtual void Hide( bool hide
= true ) = 0;
133 virtual void * GetHMenuItem() = 0;
135 wxMenuItem
* GetWXPeer() { return m_peer
; }
137 static wxMenuItemImpl
* Create( wxMenuItem
* peer
, wxMenu
*pParentMenu
,
139 const wxString
& text
,
140 wxAcceleratorEntry
*entry
,
141 const wxString
& strHelp
,
148 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl
)
151 class wxMenuImpl
: public wxObject
154 wxMenuImpl( wxMenu
* peer
) : m_peer(peer
)
158 virtual ~wxMenuImpl() ;
159 virtual void InsertOrAppend(wxMenuItem
*pItem
, size_t pos
) = 0;
160 virtual void Remove( wxMenuItem
*pItem
) = 0;
162 virtual void MakeRoot() = 0;
164 virtual void SetTitle( const wxString
& text
) = 0;
166 virtual WXHMENU
GetHMenu() = 0;
168 wxMenu
* GetWXPeer() { return m_peer
; }
170 virtual void PopUp( wxWindow
*win
, int x
, int y
) = 0;
172 static wxMenuImpl
* Create( wxMenu
* peer
, const wxString
& title
);
173 static wxMenuImpl
* CreateRootMenu( wxMenu
* peer
);
177 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl
)
182 class WXDLLIMPEXP_CORE wxWidgetImpl
: public wxObject
185 wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
= false );
187 virtual ~wxWidgetImpl();
191 bool IsRootControl() const { return m_isRootControl
; }
193 wxWindowMac
* GetWXPeer() const { return m_wxPeer
; }
195 bool IsOk() const { return GetWXWidget() != NULL
; }
197 // not only the control itself, but also all its parents must be visible
198 // in order for this function to return true
199 virtual bool IsVisible() const = 0;
200 // set the visibility of this widget (maybe latent)
201 virtual void SetVisibility( bool visible
) = 0;
203 virtual bool ShowWithEffect(bool WXUNUSED(show
),
204 wxShowEffect
WXUNUSED(effect
),
205 unsigned WXUNUSED(timeout
))
210 virtual void Raise() = 0;
212 virtual void Lower() = 0;
214 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
) = 0;
216 virtual WXWidget
GetWXWidget() const = 0;
218 virtual void SetBackgroundColour( const wxColour
& col
) = 0;
219 virtual bool SetBackgroundStyle(wxBackgroundStyle style
) = 0;
221 // all coordinates in native parent widget relative coordinates
222 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
223 virtual void Move(int x
, int y
, int width
, int height
) = 0;
224 virtual void GetPosition( int &x
, int &y
) const = 0;
225 virtual void GetSize( int &width
, int &height
) const = 0;
226 virtual void SetControlSize( wxWindowVariant variant
) = 0;
228 // native view coordinates are topleft to bottom right (flipped regarding CoreGraphics origin)
229 virtual bool IsFlipped() const { return true; }
231 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
) = 0;
232 virtual bool GetNeedsDisplay() const = 0;
234 virtual bool NeedsFocusRect() const;
235 virtual void SetNeedsFocusRect( bool needs
);
237 virtual bool NeedsFrame() const;
238 virtual void SetNeedsFrame( bool needs
);
240 virtual bool CanFocus() const = 0;
241 // return true if successful
242 virtual bool SetFocus() = 0;
243 virtual bool HasFocus() const = 0;
245 virtual void RemoveFromParent() = 0;
246 virtual void Embed( wxWidgetImpl
*parent
) = 0;
248 virtual void SetDefaultButton( bool isDefault
) = 0;
249 virtual void PerformClick() = 0;
250 virtual void SetLabel( const wxString
& title
, wxFontEncoding encoding
) = 0;
252 virtual void SetCursor( const wxCursor
& cursor
) = 0;
253 virtual void CaptureMouse() = 0;
254 virtual void ReleaseMouse() = 0;
256 virtual wxInt32
GetValue() const = 0;
257 virtual void SetValue( wxInt32 v
) = 0;
258 virtual wxBitmap
GetBitmap() const = 0;
259 virtual void SetBitmap( const wxBitmap
& bitmap
) = 0;
260 virtual void SetBitmapPosition( wxDirection dir
) = 0;
261 virtual void SetupTabs( const wxNotebook
¬ebook
) =0;
262 virtual void GetBestRect( wxRect
*r
) const = 0;
263 virtual bool IsEnabled() const = 0;
264 virtual void Enable( bool enable
) = 0;
265 virtual void SetMinimum( wxInt32 v
) = 0;
266 virtual void SetMaximum( wxInt32 v
) = 0;
267 virtual wxInt32
GetMinimum() const = 0;
268 virtual wxInt32
GetMaximum() const = 0;
269 virtual void PulseGauge() = 0;
270 virtual void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
) = 0;
272 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true ) = 0;
274 virtual void SetToolTip(wxToolTip
* WXUNUSED(tooltip
)) { }
276 // is the clicked event sent AFTER the state already changed, so no additional
277 // state changing logic is required from the outside
278 virtual bool ButtonClickDidStateChange() = 0;
280 virtual void InstallEventHandler( WXWidget control
= NULL
) = 0;
282 // Mechanism used to keep track of whether a change should send an event
283 // Do SendEvents(false) when starting actions that would trigger programmatic events
284 // and SendEvents(true) at the end of the block.
285 virtual void SendEvents(bool shouldSendEvents
) { m_shouldSendEvents
= shouldSendEvents
; }
286 virtual bool ShouldSendEvents() { return m_shouldSendEvents
; }
288 // static methods for associating native controls and their implementations
291 FindFromWXWidget(WXWidget control
);
293 static void RemoveAssociations( wxWidgetImpl
* impl
);
295 static void Associate( WXWidget control
, wxWidgetImpl
*impl
);
297 static WXWidget
FindFocus();
299 // static creation methods, must be implemented by all toolkits
301 static wxWidgetImplType
* CreateUserPane( wxWindowMac
* wxpeer
,
308 static wxWidgetImplType
* CreateContentView( wxNonOwnedWindow
* now
) ;
310 static wxWidgetImplType
* CreateButton( wxWindowMac
* wxpeer
,
313 const wxString
& label
,
319 static wxWidgetImplType
* CreateDisclosureTriangle( wxWindowMac
* wxpeer
,
322 const wxString
& label
,
328 static wxWidgetImplType
* CreateStaticLine( wxWindowMac
* wxpeer
,
336 static wxWidgetImplType
* CreateGroupBox( wxWindowMac
* wxpeer
,
339 const wxString
& label
,
345 static wxWidgetImplType
* CreateStaticText( wxWindowMac
* wxpeer
,
348 const wxString
& label
,
354 static wxWidgetImplType
* CreateTextControl( wxTextCtrl
* wxpeer
,
357 const wxString
& content
,
363 static wxWidgetImplType
* CreateSearchControl( wxTextCtrl
* wxpeer
,
366 const wxString
& content
,
372 static wxWidgetImplType
* CreateCheckBox( wxWindowMac
* wxpeer
,
375 const wxString
& label
,
381 static wxWidgetImplType
* CreateRadioButton( wxWindowMac
* wxpeer
,
384 const wxString
& label
,
390 static wxWidgetImplType
* CreateToggleButton( wxWindowMac
* wxpeer
,
393 const wxString
& label
,
399 static wxWidgetImplType
* CreateBitmapToggleButton( wxWindowMac
* wxpeer
,
402 const wxBitmap
& bitmap
,
408 static wxWidgetImplType
* CreateBitmapButton( wxWindowMac
* wxpeer
,
411 const wxBitmap
& bitmap
,
417 static wxWidgetImplType
* CreateTabView( wxWindowMac
* wxpeer
,
425 static wxWidgetImplType
* CreateGauge( wxWindowMac
* wxpeer
,
436 static wxWidgetImplType
* CreateSlider( wxWindowMac
* wxpeer
,
447 static wxWidgetImplType
* CreateSpinButton( wxWindowMac
* wxpeer
,
458 static wxWidgetImplType
* CreateScrollBar( wxWindowMac
* wxpeer
,
466 static wxWidgetImplType
* CreateChoice( wxWindowMac
* wxpeer
,
475 static wxWidgetImplType
* CreateListBox( wxWindowMac
* wxpeer
,
484 static wxWidgetImplType
* CreateComboBox( wxComboBox
* wxpeer
,
494 // converts from Toplevel-Content relative to local
495 static void Convert( wxPoint
*pt
, wxWidgetImpl
*from
, wxWidgetImpl
*to
);
497 bool m_isRootControl
;
498 wxWindowMac
* m_wxPeer
;
499 bool m_needsFocusRect
;
501 bool m_shouldSendEvents
;
503 DECLARE_ABSTRACT_CLASS(wxWidgetImpl
)
507 // the interface to be implemented eg by a listbox
510 class WXDLLIMPEXP_CORE wxListWidgetColumn
513 virtual ~wxListWidgetColumn() {}
516 class WXDLLIMPEXP_CORE wxListWidgetCellValue
519 wxListWidgetCellValue() {}
520 virtual ~wxListWidgetCellValue() {}
522 virtual void Set( CFStringRef value
) = 0;
523 virtual void Set( const wxString
& value
) = 0;
524 virtual void Set( int value
) = 0;
525 virtual void Check( bool check
);
527 virtual bool IsChecked() const;
528 virtual int GetIntValue() const = 0;
529 virtual wxString
GetStringValue() const = 0;
532 class WXDLLIMPEXP_CORE wxListWidgetImpl
535 wxListWidgetImpl() {}
536 virtual ~wxListWidgetImpl() { }
538 virtual wxListWidgetColumn
* InsertTextColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
539 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
540 virtual wxListWidgetColumn
* InsertCheckColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
541 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
545 // TODO will be replaced
546 virtual void ListDelete( unsigned int n
) = 0;
547 virtual void ListInsert( unsigned int n
) = 0;
548 virtual void ListClear() = 0;
552 virtual void ListDeselectAll() = 0;
553 virtual void ListSetSelection( unsigned int n
, bool select
, bool multi
) = 0;
554 virtual int ListGetSelection() const = 0;
555 virtual int ListGetSelections( wxArrayInt
& aSelections
) const = 0;
556 virtual bool ListIsSelected( unsigned int n
) const = 0;
560 virtual void ListScrollTo( unsigned int n
) = 0;
561 virtual void UpdateLine( unsigned int n
, wxListWidgetColumn
* col
= NULL
) = 0;
562 virtual void UpdateLineToEnd( unsigned int n
) = 0;
566 virtual unsigned int ListGetCount() const = 0;
568 virtual int DoListHitTest( const wxPoint
& inpoint
) const = 0;
572 // interface to be implemented by a textcontrol
575 class WXDLLIMPEXP_FWD_CORE wxTextAttr
;
576 class WXDLLIMPEXP_FWD_CORE wxTextEntry
;
578 // common interface for all implementations
579 class WXDLLIMPEXP_CORE wxTextWidgetImpl
583 // Any widgets implementing this interface must be associated with a
584 // wxTextEntry so instead of requiring the derived classes to implement
585 // another (pure) virtual function, just take the pointer to this entry in
586 // our ctor and implement GetTextEntry() ourselves.
587 wxTextWidgetImpl(wxTextEntry
*entry
) : m_entry(entry
) {}
589 virtual ~wxTextWidgetImpl() {}
591 wxTextEntry
*GetTextEntry() const { return m_entry
; }
593 virtual bool CanFocus() const { return true; }
595 virtual wxString
GetStringValue() const = 0 ;
596 virtual void SetStringValue( const wxString
&val
) = 0 ;
597 virtual void SetSelection( long from
, long to
) = 0 ;
598 virtual void GetSelection( long* from
, long* to
) const = 0 ;
599 virtual void WriteText( const wxString
& str
) = 0 ;
601 virtual bool GetStyle( long position
, wxTextAttr
& style
);
602 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
603 virtual void Copy() ;
605 virtual void Paste() ;
606 virtual bool CanPaste() const ;
607 virtual void SetEditable( bool editable
) ;
608 virtual long GetLastPosition() const ;
609 virtual void Replace( long from
, long to
, const wxString
&str
) ;
610 virtual void Remove( long from
, long to
) ;
613 virtual bool HasOwnContextMenu() const
616 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
619 virtual void Clear() ;
620 virtual bool CanUndo() const;
621 virtual void Undo() ;
622 virtual bool CanRedo() const;
623 virtual void Redo() ;
624 virtual int GetNumberOfLines() const ;
625 virtual long XYToPosition(long x
, long y
) const;
626 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
627 virtual void ShowPosition(long WXUNUSED(pos
)) ;
628 virtual int GetLineLength(long lineNo
) const ;
629 virtual wxString
GetLineText(long lineNo
) const ;
630 virtual void CheckSpelling(bool WXUNUSED(check
)) { }
632 virtual wxSize
GetBestSize() const { return wxDefaultSize
; }
635 wxTextEntry
* const m_entry
;
637 wxDECLARE_NO_COPY_CLASS(wxTextWidgetImpl
);
640 // common interface for all implementations
641 class WXDLLIMPEXP_CORE wxComboWidgetImpl
645 wxComboWidgetImpl() {}
647 virtual ~wxComboWidgetImpl() {}
649 virtual int GetSelectedItem() const { return -1; };
650 virtual void SetSelectedItem(int WXUNUSED(item
)) {};
652 virtual int GetNumberOfItems() const { return -1; };
654 virtual void InsertItem(int WXUNUSED(pos
), const wxString
& WXUNUSED(item
)) {}
656 virtual void RemoveItem(int WXUNUSED(pos
)) {}
658 virtual void Clear() {}
660 virtual wxString
GetStringAtIndex(int WXUNUSED(pos
)) const { return wxEmptyString
; }
662 virtual int FindString(const wxString
& WXUNUSED(text
)) const { return -1; }
666 // common interface for buttons
673 virtual ~wxButtonImpl(){}
675 virtual void SetPressedBitmap( const wxBitmap
& bitmap
) = 0;
679 // common interface for search controls
682 class wxSearchWidgetImpl
685 wxSearchWidgetImpl(){}
686 virtual ~wxSearchWidgetImpl(){}
688 // search field options
689 virtual void ShowSearchButton( bool show
) = 0;
690 virtual bool IsSearchButtonVisible() const = 0;
692 virtual void ShowCancelButton( bool show
) = 0;
693 virtual bool IsCancelButtonVisible() const = 0;
695 virtual void SetSearchMenu( wxMenu
* menu
) = 0;
697 virtual void SetDescriptiveText(const wxString
& text
) = 0;
701 // toplevel window implementation class
704 class wxNonOwnedWindowImpl
: public wxObject
707 wxNonOwnedWindowImpl( wxNonOwnedWindow
* nonownedwnd
) : m_wxPeer(nonownedwnd
)
710 wxNonOwnedWindowImpl()
713 virtual ~wxNonOwnedWindowImpl()
717 virtual void WillBeDestroyed()
721 virtual void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
722 long style
, long extraStyle
, const wxString
& name
) = 0;
725 virtual WXWindow
GetWXWindow() const = 0;
735 virtual bool Show(bool WXUNUSED(show
))
740 virtual bool ShowWithEffect(bool show
, wxShowEffect
WXUNUSED(effect
), unsigned WXUNUSED(timeout
))
745 virtual void Update()
749 virtual bool SetTransparent(wxByte
WXUNUSED(alpha
))
754 virtual bool SetBackgroundColour(const wxColour
& WXUNUSED(col
) )
759 virtual void SetExtraStyle( long WXUNUSED(exStyle
) )
763 virtual void SetWindowStyleFlag( long WXUNUSED(style
) )
767 virtual bool SetBackgroundStyle(wxBackgroundStyle
WXUNUSED(style
))
772 virtual bool CanSetTransparent()
777 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
778 virtual void MoveWindow(int x
, int y
, int width
, int height
) = 0;
779 virtual void GetPosition( int &x
, int &y
) const = 0;
780 virtual void GetSize( int &width
, int &height
) const = 0;
782 virtual bool SetShape(const wxRegion
& WXUNUSED(region
))
787 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) = 0;
789 virtual bool IsMaximized() const = 0;
791 virtual bool IsIconized() const= 0;
793 virtual void Iconize( bool iconize
)= 0;
795 virtual void Maximize(bool maximize
) = 0;
797 virtual bool IsFullScreen() const= 0;
799 virtual void ShowWithoutActivating() { Show(true); }
801 virtual bool ShowFullScreen(bool show
, long style
)= 0;
803 virtual void RequestUserAttention(int flags
) = 0;
805 virtual void ScreenToWindow( int *x
, int *y
) = 0;
807 virtual void WindowToScreen( int *x
, int *y
) = 0;
809 virtual bool IsActive() = 0;
811 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
813 static wxNonOwnedWindowImpl
*
814 FindFromWXWindow(WXWindow window
);
816 static void RemoveAssociations( wxNonOwnedWindowImpl
* impl
);
818 static void Associate( WXWindow window
, wxNonOwnedWindowImpl
*impl
);
820 // static creation methods, must be implemented by all toolkits
822 static wxNonOwnedWindowImpl
* CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, WXWindow native
) ;
824 static wxNonOwnedWindowImpl
* CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
825 long style
, long extraStyle
, const wxString
& name
) ;
827 virtual void SetModified(bool WXUNUSED(modified
)) { }
828 virtual bool IsModified() const { return false; }
831 wxNonOwnedWindow
* m_wxPeer
;
832 DECLARE_ABSTRACT_CLASS(wxNonOwnedWindowImpl
)
837 //---------------------------------------------------------------------------
838 // cocoa bridging utilities
839 //---------------------------------------------------------------------------
841 bool wxMacInitCocoa();
843 class WXDLLIMPEXP_CORE wxMacAutoreleasePool
846 wxMacAutoreleasePool();
847 ~wxMacAutoreleasePool();
854 void wxMacCocoaRelease( void* obj
);
855 void wxMacCocoaAutorelease( void* obj
);
856 void* wxMacCocoaRetain( void* obj
);
860 // _WX_PRIVATE_CORE_H_