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
118 WXDLLIMPEXP_CORE wxWindowMac
* wxFindWindowFromWXWidget(WXWidget inControl
);
121 typedef wxMacControl wxWidgetImplType
;
123 typedef wxWidgetImpl wxWidgetImplType
;
127 class wxMenuItemImpl
: public wxObject
130 wxMenuItemImpl( wxMenuItem
* peer
) : m_peer(peer
)
134 virtual ~wxMenuItemImpl() ;
135 virtual void SetBitmap( const wxBitmap
& bitmap
) = 0;
136 virtual void Enable( bool enable
) = 0;
137 virtual void Check( bool check
) = 0;
138 virtual void SetLabel( const wxString
& text
, wxAcceleratorEntry
*entry
) = 0;
139 virtual void Hide( bool hide
= true ) = 0;
141 virtual void * GetHMenuItem() = 0;
143 wxMenuItem
* GetWXPeer() { return m_peer
; }
145 static wxMenuItemImpl
* Create( wxMenuItem
* peer
, wxMenu
*pParentMenu
,
147 const wxString
& text
,
148 wxAcceleratorEntry
*entry
,
149 const wxString
& strHelp
,
153 // handle OS specific menu items if they weren't handled during normal processing
154 virtual bool DoDefault() { return false; }
158 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl
)
161 class wxMenuImpl
: public wxObject
164 wxMenuImpl( wxMenu
* peer
) : m_peer(peer
)
168 virtual ~wxMenuImpl() ;
169 virtual void InsertOrAppend(wxMenuItem
*pItem
, size_t pos
) = 0;
170 virtual void Remove( wxMenuItem
*pItem
) = 0;
172 virtual void MakeRoot() = 0;
174 virtual void SetTitle( const wxString
& text
) = 0;
176 virtual WXHMENU
GetHMenu() = 0;
178 wxMenu
* GetWXPeer() { return m_peer
; }
180 virtual void PopUp( wxWindow
*win
, int x
, int y
) = 0;
182 static wxMenuImpl
* Create( wxMenu
* peer
, const wxString
& title
);
183 static wxMenuImpl
* CreateRootMenu( wxMenu
* peer
);
187 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl
)
192 class WXDLLIMPEXP_CORE wxWidgetImpl
: public wxObject
195 wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
= false );
197 virtual ~wxWidgetImpl();
201 bool IsRootControl() const { return m_isRootControl
; }
203 wxWindowMac
* GetWXPeer() const { return m_wxPeer
; }
205 bool IsOk() const { return GetWXWidget() != NULL
; }
207 // not only the control itself, but also all its parents must be visible
208 // in order for this function to return true
209 virtual bool IsVisible() const = 0;
210 // set the visibility of this widget (maybe latent)
211 virtual void SetVisibility( bool visible
) = 0;
213 virtual bool ShowWithEffect(bool WXUNUSED(show
),
214 wxShowEffect
WXUNUSED(effect
),
215 unsigned WXUNUSED(timeout
))
220 virtual void Raise() = 0;
222 virtual void Lower() = 0;
224 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
) = 0;
226 virtual WXWidget
GetWXWidget() const = 0;
228 virtual void SetBackgroundColour( const wxColour
& col
) = 0;
229 virtual bool SetBackgroundStyle(wxBackgroundStyle style
) = 0;
231 // all coordinates in native parent widget relative coordinates
232 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
233 virtual void Move(int x
, int y
, int width
, int height
) = 0;
234 virtual void GetPosition( int &x
, int &y
) const = 0;
235 virtual void GetSize( int &width
, int &height
) const = 0;
236 virtual void SetControlSize( wxWindowVariant variant
) = 0;
238 // native view coordinates are topleft to bottom right (flipped regarding CoreGraphics origin)
239 virtual bool IsFlipped() const { return true; }
241 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
) = 0;
242 virtual bool GetNeedsDisplay() const = 0;
244 virtual bool NeedsFocusRect() const;
245 virtual void SetNeedsFocusRect( bool needs
);
247 virtual bool NeedsFrame() const;
248 virtual void SetNeedsFrame( bool needs
);
250 virtual bool CanFocus() const = 0;
251 // return true if successful
252 virtual bool SetFocus() = 0;
253 virtual bool HasFocus() const = 0;
255 virtual void RemoveFromParent() = 0;
256 virtual void Embed( wxWidgetImpl
*parent
) = 0;
258 virtual void SetDefaultButton( bool isDefault
) = 0;
259 virtual void PerformClick() = 0;
260 virtual void SetLabel( const wxString
& title
, wxFontEncoding encoding
) = 0;
262 virtual void SetCursor( const wxCursor
& cursor
) = 0;
263 virtual void CaptureMouse() = 0;
264 virtual void ReleaseMouse() = 0;
266 virtual wxInt32
GetValue() const = 0;
267 virtual void SetValue( wxInt32 v
) = 0;
268 virtual wxBitmap
GetBitmap() const = 0;
269 virtual void SetBitmap( const wxBitmap
& bitmap
) = 0;
270 virtual void SetBitmapPosition( wxDirection dir
) = 0;
271 virtual void SetupTabs( const wxNotebook
¬ebook
) =0;
272 virtual void GetBestRect( wxRect
*r
) const = 0;
273 virtual bool IsEnabled() const = 0;
274 virtual void Enable( bool enable
) = 0;
275 virtual void SetMinimum( wxInt32 v
) = 0;
276 virtual void SetMaximum( wxInt32 v
) = 0;
277 virtual wxInt32
GetMinimum() const = 0;
278 virtual wxInt32
GetMaximum() const = 0;
279 virtual void PulseGauge() = 0;
280 virtual void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
) = 0;
282 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true ) = 0;
284 virtual void SetToolTip(wxToolTip
* WXUNUSED(tooltip
)) { }
286 // is the clicked event sent AFTER the state already changed, so no additional
287 // state changing logic is required from the outside
288 virtual bool ButtonClickDidStateChange() = 0;
290 virtual void InstallEventHandler( WXWidget control
= NULL
) = 0;
292 // Mechanism used to keep track of whether a change should send an event
293 // Do SendEvents(false) when starting actions that would trigger programmatic events
294 // and SendEvents(true) at the end of the block.
295 virtual void SendEvents(bool shouldSendEvents
) { m_shouldSendEvents
= shouldSendEvents
; }
296 virtual bool ShouldSendEvents() { return m_shouldSendEvents
; }
298 // static methods for associating native controls and their implementations
301 FindFromWXWidget(WXWidget control
);
303 static void RemoveAssociations( wxWidgetImpl
* impl
);
305 static void Associate( WXWidget control
, wxWidgetImpl
*impl
);
307 static WXWidget
FindFocus();
309 // static creation methods, must be implemented by all toolkits
311 static wxWidgetImplType
* CreateUserPane( wxWindowMac
* wxpeer
,
318 static wxWidgetImplType
* CreateContentView( wxNonOwnedWindow
* now
) ;
320 static wxWidgetImplType
* CreateButton( wxWindowMac
* wxpeer
,
323 const wxString
& label
,
329 static wxWidgetImplType
* CreateDisclosureTriangle( wxWindowMac
* wxpeer
,
332 const wxString
& label
,
338 static wxWidgetImplType
* CreateStaticLine( wxWindowMac
* wxpeer
,
346 static wxWidgetImplType
* CreateGroupBox( wxWindowMac
* wxpeer
,
349 const wxString
& label
,
355 static wxWidgetImplType
* CreateStaticText( wxWindowMac
* wxpeer
,
358 const wxString
& label
,
364 static wxWidgetImplType
* CreateTextControl( wxTextCtrl
* wxpeer
,
367 const wxString
& content
,
373 static wxWidgetImplType
* CreateSearchControl( wxTextCtrl
* wxpeer
,
376 const wxString
& content
,
382 static wxWidgetImplType
* CreateCheckBox( wxWindowMac
* wxpeer
,
385 const wxString
& label
,
391 static wxWidgetImplType
* CreateRadioButton( wxWindowMac
* wxpeer
,
394 const wxString
& label
,
400 static wxWidgetImplType
* CreateToggleButton( wxWindowMac
* wxpeer
,
403 const wxString
& label
,
409 static wxWidgetImplType
* CreateBitmapToggleButton( wxWindowMac
* wxpeer
,
412 const wxBitmap
& bitmap
,
418 static wxWidgetImplType
* CreateBitmapButton( wxWindowMac
* wxpeer
,
421 const wxBitmap
& bitmap
,
427 static wxWidgetImplType
* CreateTabView( wxWindowMac
* wxpeer
,
435 static wxWidgetImplType
* CreateGauge( wxWindowMac
* wxpeer
,
446 static wxWidgetImplType
* CreateSlider( wxWindowMac
* wxpeer
,
457 static wxWidgetImplType
* CreateSpinButton( wxWindowMac
* wxpeer
,
468 static wxWidgetImplType
* CreateScrollBar( wxWindowMac
* wxpeer
,
476 static wxWidgetImplType
* CreateChoice( wxWindowMac
* wxpeer
,
485 static wxWidgetImplType
* CreateListBox( wxWindowMac
* wxpeer
,
494 static wxWidgetImplType
* CreateComboBox( wxComboBox
* wxpeer
,
504 // converts from Toplevel-Content relative to local
505 static void Convert( wxPoint
*pt
, wxWidgetImpl
*from
, wxWidgetImpl
*to
);
507 bool m_isRootControl
;
508 wxWindowMac
* m_wxPeer
;
509 bool m_needsFocusRect
;
511 bool m_shouldSendEvents
;
513 DECLARE_ABSTRACT_CLASS(wxWidgetImpl
)
517 // the interface to be implemented eg by a listbox
520 class WXDLLIMPEXP_CORE wxListWidgetColumn
523 virtual ~wxListWidgetColumn() {}
526 class WXDLLIMPEXP_CORE wxListWidgetCellValue
529 wxListWidgetCellValue() {}
530 virtual ~wxListWidgetCellValue() {}
532 virtual void Set( CFStringRef value
) = 0;
533 virtual void Set( const wxString
& value
) = 0;
534 virtual void Set( int value
) = 0;
535 virtual void Check( bool check
);
537 virtual bool IsChecked() const;
538 virtual int GetIntValue() const = 0;
539 virtual wxString
GetStringValue() const = 0;
542 class WXDLLIMPEXP_CORE wxListWidgetImpl
545 wxListWidgetImpl() {}
546 virtual ~wxListWidgetImpl() { }
548 virtual wxListWidgetColumn
* InsertTextColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
549 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
550 virtual wxListWidgetColumn
* InsertCheckColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
551 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
555 // TODO will be replaced
556 virtual void ListDelete( unsigned int n
) = 0;
557 virtual void ListInsert( unsigned int n
) = 0;
558 virtual void ListClear() = 0;
562 virtual void ListDeselectAll() = 0;
563 virtual void ListSetSelection( unsigned int n
, bool select
, bool multi
) = 0;
564 virtual int ListGetSelection() const = 0;
565 virtual int ListGetSelections( wxArrayInt
& aSelections
) const = 0;
566 virtual bool ListIsSelected( unsigned int n
) const = 0;
570 virtual void ListScrollTo( unsigned int n
) = 0;
571 virtual void UpdateLine( unsigned int n
, wxListWidgetColumn
* col
= NULL
) = 0;
572 virtual void UpdateLineToEnd( unsigned int n
) = 0;
576 virtual unsigned int ListGetCount() const = 0;
578 virtual int DoListHitTest( const wxPoint
& inpoint
) const = 0;
582 // interface to be implemented by a textcontrol
585 class WXDLLIMPEXP_FWD_CORE wxTextAttr
;
586 class WXDLLIMPEXP_FWD_CORE wxTextEntry
;
588 // common interface for all implementations
589 class WXDLLIMPEXP_CORE wxTextWidgetImpl
593 // Any widgets implementing this interface must be associated with a
594 // wxTextEntry so instead of requiring the derived classes to implement
595 // another (pure) virtual function, just take the pointer to this entry in
596 // our ctor and implement GetTextEntry() ourselves.
597 wxTextWidgetImpl(wxTextEntry
*entry
) : m_entry(entry
) {}
599 virtual ~wxTextWidgetImpl() {}
601 wxTextEntry
*GetTextEntry() const { return m_entry
; }
603 virtual bool CanFocus() const { return true; }
605 virtual wxString
GetStringValue() const = 0 ;
606 virtual void SetStringValue( const wxString
&val
) = 0 ;
607 virtual void SetSelection( long from
, long to
) = 0 ;
608 virtual void GetSelection( long* from
, long* to
) const = 0 ;
609 virtual void WriteText( const wxString
& str
) = 0 ;
611 virtual bool GetStyle( long position
, wxTextAttr
& style
);
612 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
613 virtual void Copy() ;
615 virtual void Paste() ;
616 virtual bool CanPaste() const ;
617 virtual void SetEditable( bool editable
) ;
618 virtual long GetLastPosition() const ;
619 virtual void Replace( long from
, long to
, const wxString
&str
) ;
620 virtual void Remove( long from
, long to
) ;
623 virtual bool HasOwnContextMenu() const
626 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
629 virtual void Clear() ;
630 virtual bool CanUndo() const;
631 virtual void Undo() ;
632 virtual bool CanRedo() const;
633 virtual void Redo() ;
634 virtual int GetNumberOfLines() const ;
635 virtual long XYToPosition(long x
, long y
) const;
636 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
637 virtual void ShowPosition(long WXUNUSED(pos
)) ;
638 virtual int GetLineLength(long lineNo
) const ;
639 virtual wxString
GetLineText(long lineNo
) const ;
640 virtual void CheckSpelling(bool WXUNUSED(check
)) { }
642 virtual wxSize
GetBestSize() const { return wxDefaultSize
; }
645 wxTextEntry
* const m_entry
;
647 wxDECLARE_NO_COPY_CLASS(wxTextWidgetImpl
);
650 // common interface for all implementations
651 class WXDLLIMPEXP_CORE wxComboWidgetImpl
655 wxComboWidgetImpl() {}
657 virtual ~wxComboWidgetImpl() {}
659 virtual int GetSelectedItem() const { return -1; };
660 virtual void SetSelectedItem(int WXUNUSED(item
)) {};
662 virtual int GetNumberOfItems() const { return -1; };
664 virtual void InsertItem(int WXUNUSED(pos
), const wxString
& WXUNUSED(item
)) {}
666 virtual void RemoveItem(int WXUNUSED(pos
)) {}
668 virtual void Clear() {}
670 virtual wxString
GetStringAtIndex(int WXUNUSED(pos
)) const { return wxEmptyString
; }
672 virtual int FindString(const wxString
& WXUNUSED(text
)) const { return -1; }
676 // common interface for buttons
683 virtual ~wxButtonImpl(){}
685 virtual void SetPressedBitmap( const wxBitmap
& bitmap
) = 0;
689 // common interface for search controls
692 class wxSearchWidgetImpl
695 wxSearchWidgetImpl(){}
696 virtual ~wxSearchWidgetImpl(){}
698 // search field options
699 virtual void ShowSearchButton( bool show
) = 0;
700 virtual bool IsSearchButtonVisible() const = 0;
702 virtual void ShowCancelButton( bool show
) = 0;
703 virtual bool IsCancelButtonVisible() const = 0;
705 virtual void SetSearchMenu( wxMenu
* menu
) = 0;
707 virtual void SetDescriptiveText(const wxString
& text
) = 0;
711 // toplevel window implementation class
714 class wxNonOwnedWindowImpl
: public wxObject
717 wxNonOwnedWindowImpl( wxNonOwnedWindow
* nonownedwnd
) : m_wxPeer(nonownedwnd
)
720 wxNonOwnedWindowImpl()
723 virtual ~wxNonOwnedWindowImpl()
727 virtual void WillBeDestroyed()
731 virtual void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
732 long style
, long extraStyle
, const wxString
& name
) = 0;
735 virtual WXWindow
GetWXWindow() const = 0;
745 virtual bool Show(bool WXUNUSED(show
))
750 virtual bool ShowWithEffect(bool show
, wxShowEffect
WXUNUSED(effect
), unsigned WXUNUSED(timeout
))
755 virtual void Update()
759 virtual bool SetTransparent(wxByte
WXUNUSED(alpha
))
764 virtual bool SetBackgroundColour(const wxColour
& WXUNUSED(col
) )
769 virtual void SetExtraStyle( long WXUNUSED(exStyle
) )
773 virtual void SetWindowStyleFlag( long WXUNUSED(style
) )
777 virtual bool SetBackgroundStyle(wxBackgroundStyle
WXUNUSED(style
))
782 virtual bool CanSetTransparent()
787 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
788 virtual void MoveWindow(int x
, int y
, int width
, int height
) = 0;
789 virtual void GetPosition( int &x
, int &y
) const = 0;
790 virtual void GetSize( int &width
, int &height
) const = 0;
792 virtual bool SetShape(const wxRegion
& WXUNUSED(region
))
797 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) = 0;
799 virtual bool IsMaximized() const = 0;
801 virtual bool IsIconized() const= 0;
803 virtual void Iconize( bool iconize
)= 0;
805 virtual void Maximize(bool maximize
) = 0;
807 virtual bool IsFullScreen() const= 0;
809 virtual void ShowWithoutActivating() { Show(true); }
811 virtual bool ShowFullScreen(bool show
, long style
)= 0;
813 virtual void RequestUserAttention(int flags
) = 0;
815 virtual void ScreenToWindow( int *x
, int *y
) = 0;
817 virtual void WindowToScreen( int *x
, int *y
) = 0;
819 virtual bool IsActive() = 0;
821 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
823 static wxNonOwnedWindowImpl
*
824 FindFromWXWindow(WXWindow window
);
826 static void RemoveAssociations( wxNonOwnedWindowImpl
* impl
);
828 static void Associate( WXWindow window
, wxNonOwnedWindowImpl
*impl
);
830 // static creation methods, must be implemented by all toolkits
832 static wxNonOwnedWindowImpl
* CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, WXWindow native
) ;
834 static wxNonOwnedWindowImpl
* CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
835 long style
, long extraStyle
, const wxString
& name
) ;
837 virtual void SetModified(bool WXUNUSED(modified
)) { }
838 virtual bool IsModified() const { return false; }
841 wxNonOwnedWindow
* m_wxPeer
;
842 DECLARE_ABSTRACT_CLASS(wxNonOwnedWindowImpl
)
847 //---------------------------------------------------------------------------
848 // cocoa bridging utilities
849 //---------------------------------------------------------------------------
851 bool wxMacInitCocoa();
853 class WXDLLIMPEXP_CORE wxMacAutoreleasePool
856 wxMacAutoreleasePool();
857 ~wxMacAutoreleasePool();
864 void wxMacCocoaRelease( void* obj
);
865 void wxMacCocoaAutorelease( void* obj
);
866 void* wxMacCocoaRetain( void* obj
);
870 // _WX_PRIVATE_CORE_H_