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 !wxUSE_GUI || wxOSX_USE_COCOA_OR_CARBON
37 // Carbon functions are currently still used in wxOSX/Cocoa too (including
38 // wxBase part of it).
39 #include <Carbon/Carbon.h>
41 WXDLLIMPEXP_BASE
long UMAGetSystemVersion() ;
43 void WXDLLIMPEXP_CORE
wxMacStringToPascal( const wxString
&from
, unsigned char * to
);
44 wxString WXDLLIMPEXP_CORE
wxMacMakeStringFromPascal( const unsigned char * from
);
46 WXDLLIMPEXP_BASE wxString
wxMacFSRefToPath( const FSRef
*fsRef
, CFStringRef additionalPathComponent
= NULL
);
47 WXDLLIMPEXP_BASE OSStatus
wxMacPathToFSRef( const wxString
&path
, FSRef
*fsRef
);
48 WXDLLIMPEXP_BASE wxString
wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname
);
55 #include <CoreGraphics/CoreGraphics.h>
57 #include <ApplicationServices/ApplicationServices.h>
60 #include "wx/bitmap.h"
61 #include "wx/window.h"
63 class WXDLLIMPEXP_CORE wxMacCGContextStateSaver
65 wxDECLARE_NO_COPY_CLASS(wxMacCGContextStateSaver
);
68 wxMacCGContextStateSaver( CGContextRef cg
)
71 CGContextSaveGState( cg
);
73 ~wxMacCGContextStateSaver()
75 CGContextRestoreGState( m_cg
);
81 class WXDLLIMPEXP_CORE wxDeferredObjectDeleter
: public wxObject
84 wxDeferredObjectDeleter( wxObject
* obj
) : m_obj(obj
)
87 virtual ~wxDeferredObjectDeleter()
97 WXDLLIMPEXP_CORE CGImageRef
wxMacCreateCGImageFromBitmap( const wxBitmap
& bitmap
);
99 WXDLLIMPEXP_CORE CGDataProviderRef
wxMacCGDataProviderCreateWithCFData( CFDataRef data
);
100 WXDLLIMPEXP_CORE CGDataConsumerRef
wxMacCGDataConsumerCreateWithCFData( CFMutableDataRef data
);
101 WXDLLIMPEXP_CORE CGDataProviderRef
wxMacCGDataProviderCreateWithMemoryBuffer( const wxMemoryBuffer
& buf
);
103 CGColorSpaceRef WXDLLIMPEXP_CORE
wxMacGetGenericRGBColorSpace(void);
107 extern wxWindow
* g_MacLastWindow
;
108 class wxNonOwnedWindow
;
110 // temporary typedef so that no additional casts are necessary within carbon code at the moment
119 WXDLLIMPEXP_CORE wxWindowMac
* wxFindWindowFromWXWidget(WXWidget inControl
);
122 typedef wxMacControl wxWidgetImplType
;
124 typedef wxWidgetImpl wxWidgetImplType
;
128 class wxMenuItemImpl
: public wxObject
131 wxMenuItemImpl( wxMenuItem
* peer
) : m_peer(peer
)
135 virtual ~wxMenuItemImpl() ;
136 virtual void SetBitmap( const wxBitmap
& bitmap
) = 0;
137 virtual void Enable( bool enable
) = 0;
138 virtual void Check( bool check
) = 0;
139 virtual void SetLabel( const wxString
& text
, wxAcceleratorEntry
*entry
) = 0;
140 virtual void Hide( bool hide
= true ) = 0;
142 virtual void * GetHMenuItem() = 0;
144 wxMenuItem
* GetWXPeer() { return m_peer
; }
146 static wxMenuItemImpl
* Create( wxMenuItem
* peer
, wxMenu
*pParentMenu
,
148 const wxString
& text
,
149 wxAcceleratorEntry
*entry
,
150 const wxString
& strHelp
,
154 // handle OS specific menu items if they weren't handled during normal processing
155 virtual bool DoDefault() { return false; }
159 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl
)
162 class wxMenuImpl
: public wxObject
165 wxMenuImpl( wxMenu
* peer
) : m_peer(peer
)
169 virtual ~wxMenuImpl() ;
170 virtual void InsertOrAppend(wxMenuItem
*pItem
, size_t pos
) = 0;
171 virtual void Remove( wxMenuItem
*pItem
) = 0;
173 virtual void MakeRoot() = 0;
175 virtual void SetTitle( const wxString
& text
) = 0;
177 virtual WXHMENU
GetHMenu() = 0;
179 wxMenu
* GetWXPeer() { return m_peer
; }
181 virtual void PopUp( wxWindow
*win
, int x
, int y
) = 0;
183 static wxMenuImpl
* Create( wxMenu
* peer
, const wxString
& title
);
184 static wxMenuImpl
* CreateRootMenu( wxMenu
* peer
);
188 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl
)
193 class WXDLLIMPEXP_CORE wxWidgetImpl
: public wxObject
196 wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
= false );
198 virtual ~wxWidgetImpl();
202 bool IsRootControl() const { return m_isRootControl
; }
204 wxWindowMac
* GetWXPeer() const { return m_wxPeer
; }
206 bool IsOk() const { return GetWXWidget() != NULL
; }
208 // not only the control itself, but also all its parents must be visible
209 // in order for this function to return true
210 virtual bool IsVisible() const = 0;
211 // set the visibility of this widget (maybe latent)
212 virtual void SetVisibility( bool visible
) = 0;
214 virtual bool ShowWithEffect(bool WXUNUSED(show
),
215 wxShowEffect
WXUNUSED(effect
),
216 unsigned WXUNUSED(timeout
))
221 virtual void Raise() = 0;
223 virtual void Lower() = 0;
225 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
) = 0;
227 virtual WXWidget
GetWXWidget() const = 0;
229 virtual void SetBackgroundColour( const wxColour
& col
) = 0;
230 virtual bool SetBackgroundStyle(wxBackgroundStyle style
) = 0;
232 // all coordinates in native parent widget relative coordinates
233 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
234 virtual void Move(int x
, int y
, int width
, int height
) = 0;
235 virtual void GetPosition( int &x
, int &y
) const = 0;
236 virtual void GetSize( int &width
, int &height
) const = 0;
237 virtual void SetControlSize( wxWindowVariant variant
) = 0;
238 virtual float GetContentScaleFactor() const
243 // the native coordinates may have an 'aura' for shadows etc, if this is the case the layout
244 // inset indicates on which insets the real control is drawn
245 virtual void GetLayoutInset(int &left
, int &top
, int &right
, int &bottom
) const
247 left
= top
= right
= bottom
= 0;
250 // native view coordinates are topleft to bottom right (flipped regarding CoreGraphics origin)
251 virtual bool IsFlipped() const { return true; }
253 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
) = 0;
254 virtual bool GetNeedsDisplay() const = 0;
256 virtual bool NeedsFocusRect() const;
257 virtual void SetNeedsFocusRect( bool needs
);
259 virtual bool NeedsFrame() const;
260 virtual void SetNeedsFrame( bool needs
);
262 virtual bool CanFocus() const = 0;
263 // return true if successful
264 virtual bool SetFocus() = 0;
265 virtual bool HasFocus() const = 0;
267 virtual void RemoveFromParent() = 0;
268 virtual void Embed( wxWidgetImpl
*parent
) = 0;
270 virtual void SetDefaultButton( bool isDefault
) = 0;
271 virtual void PerformClick() = 0;
272 virtual void SetLabel( const wxString
& title
, wxFontEncoding encoding
) = 0;
274 virtual void SetCursor( const wxCursor
& cursor
) = 0;
275 virtual void CaptureMouse() = 0;
276 virtual void ReleaseMouse() = 0;
278 virtual wxInt32
GetValue() const = 0;
279 virtual void SetValue( wxInt32 v
) = 0;
280 virtual wxBitmap
GetBitmap() const = 0;
281 virtual void SetBitmap( const wxBitmap
& bitmap
) = 0;
282 virtual void SetBitmapPosition( wxDirection dir
) = 0;
283 virtual void SetupTabs( const wxNotebook
¬ebook
) =0;
284 virtual void GetBestRect( wxRect
*r
) const = 0;
285 virtual bool IsEnabled() const = 0;
286 virtual void Enable( bool enable
) = 0;
287 virtual void SetMinimum( wxInt32 v
) = 0;
288 virtual void SetMaximum( wxInt32 v
) = 0;
289 virtual wxInt32
GetMinimum() const = 0;
290 virtual wxInt32
GetMaximum() const = 0;
291 virtual void PulseGauge() = 0;
292 virtual void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
) = 0;
294 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true ) = 0;
296 virtual void SetToolTip(wxToolTip
* WXUNUSED(tooltip
)) { }
298 // is the clicked event sent AFTER the state already changed, so no additional
299 // state changing logic is required from the outside
300 virtual bool ButtonClickDidStateChange() = 0;
302 virtual void InstallEventHandler( WXWidget control
= NULL
) = 0;
304 // Mechanism used to keep track of whether a change should send an event
305 // Do SendEvents(false) when starting actions that would trigger programmatic events
306 // and SendEvents(true) at the end of the block.
307 virtual void SendEvents(bool shouldSendEvents
) { m_shouldSendEvents
= shouldSendEvents
; }
308 virtual bool ShouldSendEvents() { return m_shouldSendEvents
; }
310 // static methods for associating native controls and their implementations
313 FindFromWXWidget(WXWidget control
);
315 static void RemoveAssociations( wxWidgetImpl
* impl
);
317 static void Associate( WXWidget control
, wxWidgetImpl
*impl
);
319 static WXWidget
FindFocus();
321 // static creation methods, must be implemented by all toolkits
323 static wxWidgetImplType
* CreateUserPane( wxWindowMac
* wxpeer
,
330 static wxWidgetImplType
* CreateContentView( wxNonOwnedWindow
* now
) ;
332 static wxWidgetImplType
* CreateButton( wxWindowMac
* wxpeer
,
335 const wxString
& label
,
341 static wxWidgetImplType
* CreateDisclosureTriangle( wxWindowMac
* wxpeer
,
344 const wxString
& label
,
350 static wxWidgetImplType
* CreateStaticLine( wxWindowMac
* wxpeer
,
358 static wxWidgetImplType
* CreateGroupBox( wxWindowMac
* wxpeer
,
361 const wxString
& label
,
367 static wxWidgetImplType
* CreateStaticText( wxWindowMac
* wxpeer
,
370 const wxString
& label
,
376 static wxWidgetImplType
* CreateTextControl( wxTextCtrl
* wxpeer
,
379 const wxString
& content
,
385 static wxWidgetImplType
* CreateSearchControl( wxSearchCtrl
* wxpeer
,
388 const wxString
& content
,
394 static wxWidgetImplType
* CreateCheckBox( wxWindowMac
* wxpeer
,
397 const wxString
& label
,
403 static wxWidgetImplType
* CreateRadioButton( wxWindowMac
* wxpeer
,
406 const wxString
& label
,
412 static wxWidgetImplType
* CreateToggleButton( wxWindowMac
* wxpeer
,
415 const wxString
& label
,
421 static wxWidgetImplType
* CreateBitmapToggleButton( wxWindowMac
* wxpeer
,
424 const wxBitmap
& bitmap
,
430 static wxWidgetImplType
* CreateBitmapButton( wxWindowMac
* wxpeer
,
433 const wxBitmap
& bitmap
,
439 static wxWidgetImplType
* CreateTabView( wxWindowMac
* wxpeer
,
447 static wxWidgetImplType
* CreateGauge( wxWindowMac
* wxpeer
,
458 static wxWidgetImplType
* CreateSlider( wxWindowMac
* wxpeer
,
469 static wxWidgetImplType
* CreateSpinButton( wxWindowMac
* wxpeer
,
480 static wxWidgetImplType
* CreateScrollBar( wxWindowMac
* wxpeer
,
488 static wxWidgetImplType
* CreateChoice( wxWindowMac
* wxpeer
,
497 static wxWidgetImplType
* CreateListBox( wxWindowMac
* wxpeer
,
506 static wxWidgetImplType
* CreateComboBox( wxComboBox
* wxpeer
,
516 // converts from Toplevel-Content relative to local
517 static void Convert( wxPoint
*pt
, wxWidgetImpl
*from
, wxWidgetImpl
*to
);
519 bool m_isRootControl
;
520 wxWindowMac
* m_wxPeer
;
521 bool m_needsFocusRect
;
523 bool m_shouldSendEvents
;
525 DECLARE_ABSTRACT_CLASS(wxWidgetImpl
)
529 // the interface to be implemented eg by a listbox
532 class WXDLLIMPEXP_CORE wxListWidgetColumn
535 virtual ~wxListWidgetColumn() {}
538 class WXDLLIMPEXP_CORE wxListWidgetCellValue
541 wxListWidgetCellValue() {}
542 virtual ~wxListWidgetCellValue() {}
544 virtual void Set( CFStringRef value
) = 0;
545 virtual void Set( const wxString
& value
) = 0;
546 virtual void Set( int value
) = 0;
547 virtual void Check( bool check
);
549 virtual bool IsChecked() const;
550 virtual int GetIntValue() const = 0;
551 virtual wxString
GetStringValue() const = 0;
554 class WXDLLIMPEXP_CORE wxListWidgetImpl
557 wxListWidgetImpl() {}
558 virtual ~wxListWidgetImpl() { }
560 virtual wxListWidgetColumn
* InsertTextColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
561 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
562 virtual wxListWidgetColumn
* InsertCheckColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
563 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
567 // TODO will be replaced
568 virtual void ListDelete( unsigned int n
) = 0;
569 virtual void ListInsert( unsigned int n
) = 0;
570 virtual void ListClear() = 0;
574 virtual void ListDeselectAll() = 0;
575 virtual void ListSetSelection( unsigned int n
, bool select
, bool multi
) = 0;
576 virtual int ListGetSelection() const = 0;
577 virtual int ListGetSelections( wxArrayInt
& aSelections
) const = 0;
578 virtual bool ListIsSelected( unsigned int n
) const = 0;
582 virtual void ListScrollTo( unsigned int n
) = 0;
583 virtual void UpdateLine( unsigned int n
, wxListWidgetColumn
* col
= NULL
) = 0;
584 virtual void UpdateLineToEnd( unsigned int n
) = 0;
588 virtual unsigned int ListGetCount() const = 0;
590 virtual int DoListHitTest( const wxPoint
& inpoint
) const = 0;
594 // interface to be implemented by a textcontrol
597 class WXDLLIMPEXP_FWD_CORE wxTextAttr
;
598 class WXDLLIMPEXP_FWD_CORE wxTextEntry
;
600 // common interface for all implementations
601 class WXDLLIMPEXP_CORE wxTextWidgetImpl
605 // Any widgets implementing this interface must be associated with a
606 // wxTextEntry so instead of requiring the derived classes to implement
607 // another (pure) virtual function, just take the pointer to this entry in
608 // our ctor and implement GetTextEntry() ourselves.
609 wxTextWidgetImpl(wxTextEntry
*entry
) : m_entry(entry
) {}
611 virtual ~wxTextWidgetImpl() {}
613 wxTextEntry
*GetTextEntry() const { return m_entry
; }
615 virtual bool CanFocus() const { return true; }
617 virtual wxString
GetStringValue() const = 0 ;
618 virtual void SetStringValue( const wxString
&val
) = 0 ;
619 virtual void SetSelection( long from
, long to
) = 0 ;
620 virtual void GetSelection( long* from
, long* to
) const = 0 ;
621 virtual void WriteText( const wxString
& str
) = 0 ;
623 virtual bool GetStyle( long position
, wxTextAttr
& style
);
624 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
625 virtual void Copy() ;
627 virtual void Paste() ;
628 virtual bool CanPaste() const ;
629 virtual void SetEditable( bool editable
) ;
630 virtual long GetLastPosition() const ;
631 virtual void Replace( long from
, long to
, const wxString
&str
) ;
632 virtual void Remove( long from
, long to
) ;
635 virtual bool HasOwnContextMenu() const
638 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
641 virtual void Clear() ;
642 virtual bool CanUndo() const;
643 virtual void Undo() ;
644 virtual bool CanRedo() const;
645 virtual void Redo() ;
646 virtual int GetNumberOfLines() const ;
647 virtual long XYToPosition(long x
, long y
) const;
648 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
649 virtual void ShowPosition(long WXUNUSED(pos
)) ;
650 virtual int GetLineLength(long lineNo
) const ;
651 virtual wxString
GetLineText(long lineNo
) const ;
652 virtual void CheckSpelling(bool WXUNUSED(check
)) { }
654 virtual wxSize
GetBestSize() const { return wxDefaultSize
; }
656 virtual bool SetHint(const wxString
& WXUNUSED(hint
)) { return false; }
658 wxTextEntry
* const m_entry
;
660 wxDECLARE_NO_COPY_CLASS(wxTextWidgetImpl
);
663 // common interface for all implementations
664 class WXDLLIMPEXP_CORE wxComboWidgetImpl
668 wxComboWidgetImpl() {}
670 virtual ~wxComboWidgetImpl() {}
672 virtual int GetSelectedItem() const { return -1; };
673 virtual void SetSelectedItem(int WXUNUSED(item
)) {};
675 virtual int GetNumberOfItems() const { return -1; };
677 virtual void InsertItem(int WXUNUSED(pos
), const wxString
& WXUNUSED(item
)) {}
679 virtual void RemoveItem(int WXUNUSED(pos
)) {}
681 virtual void Clear() {}
683 virtual wxString
GetStringAtIndex(int WXUNUSED(pos
)) const { return wxEmptyString
; }
685 virtual int FindString(const wxString
& WXUNUSED(text
)) const { return -1; }
689 // common interface for buttons
696 virtual ~wxButtonImpl(){}
698 virtual void SetPressedBitmap( const wxBitmap
& bitmap
) = 0;
702 // common interface for search controls
705 class wxSearchWidgetImpl
708 wxSearchWidgetImpl(){}
709 virtual ~wxSearchWidgetImpl(){}
711 // search field options
712 virtual void ShowSearchButton( bool show
) = 0;
713 virtual bool IsSearchButtonVisible() const = 0;
715 virtual void ShowCancelButton( bool show
) = 0;
716 virtual bool IsCancelButtonVisible() const = 0;
718 virtual void SetSearchMenu( wxMenu
* menu
) = 0;
720 virtual void SetDescriptiveText(const wxString
& text
) = 0;
724 // toplevel window implementation class
727 class wxNonOwnedWindowImpl
: public wxObject
730 wxNonOwnedWindowImpl( wxNonOwnedWindow
* nonownedwnd
) : m_wxPeer(nonownedwnd
)
733 wxNonOwnedWindowImpl()
736 virtual ~wxNonOwnedWindowImpl()
740 virtual void WillBeDestroyed()
744 virtual void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
745 long style
, long extraStyle
, const wxString
& name
) = 0;
748 virtual WXWindow
GetWXWindow() const = 0;
758 virtual bool Show(bool WXUNUSED(show
))
763 virtual bool ShowWithEffect(bool show
, wxShowEffect
WXUNUSED(effect
), unsigned WXUNUSED(timeout
))
768 virtual void Update()
772 virtual bool SetTransparent(wxByte
WXUNUSED(alpha
))
777 virtual bool SetBackgroundColour(const wxColour
& WXUNUSED(col
) )
782 virtual void SetExtraStyle( long WXUNUSED(exStyle
) )
786 virtual void SetWindowStyleFlag( long WXUNUSED(style
) )
790 virtual bool SetBackgroundStyle(wxBackgroundStyle
WXUNUSED(style
))
795 virtual bool CanSetTransparent()
800 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
801 virtual void MoveWindow(int x
, int y
, int width
, int height
) = 0;
802 virtual void GetPosition( int &x
, int &y
) const = 0;
803 virtual void GetSize( int &width
, int &height
) const = 0;
805 virtual bool SetShape(const wxRegion
& WXUNUSED(region
))
810 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) = 0;
812 virtual bool IsMaximized() const = 0;
814 virtual bool IsIconized() const= 0;
816 virtual void Iconize( bool iconize
)= 0;
818 virtual void Maximize(bool maximize
) = 0;
820 virtual bool IsFullScreen() const= 0;
822 virtual void ShowWithoutActivating() { Show(true); }
824 virtual bool ShowFullScreen(bool show
, long style
)= 0;
826 virtual void RequestUserAttention(int flags
) = 0;
828 virtual void ScreenToWindow( int *x
, int *y
) = 0;
830 virtual void WindowToScreen( int *x
, int *y
) = 0;
832 virtual bool IsActive() = 0;
834 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
836 static wxNonOwnedWindowImpl
*
837 FindFromWXWindow(WXWindow window
);
839 static void RemoveAssociations( wxNonOwnedWindowImpl
* impl
);
841 static void Associate( WXWindow window
, wxNonOwnedWindowImpl
*impl
);
843 // static creation methods, must be implemented by all toolkits
845 static wxNonOwnedWindowImpl
* CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, WXWindow native
) ;
847 static wxNonOwnedWindowImpl
* CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
848 long style
, long extraStyle
, const wxString
& name
) ;
850 virtual void SetModified(bool WXUNUSED(modified
)) { }
851 virtual bool IsModified() const { return false; }
854 wxNonOwnedWindow
* m_wxPeer
;
855 DECLARE_ABSTRACT_CLASS(wxNonOwnedWindowImpl
)
860 //---------------------------------------------------------------------------
861 // cocoa bridging utilities
862 //---------------------------------------------------------------------------
864 bool wxMacInitCocoa();
866 class WXDLLIMPEXP_CORE wxMacAutoreleasePool
869 wxMacAutoreleasePool();
870 ~wxMacAutoreleasePool();
877 void wxMacCocoaRelease( void* obj
);
878 void wxMacCocoaAutorelease( void* obj
);
879 void* wxMacCocoaRetain( void* obj
);
883 // _WX_PRIVATE_CORE_H_