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 #if wxOSX_USE_COCOA_OR_CARBON
26 WXDLLIMPEXP_BASE
long UMAGetSystemVersion() ;
28 void WXDLLIMPEXP_CORE
wxMacStringToPascal( const wxString
&from
, unsigned char * to
);
29 wxString WXDLLIMPEXP_CORE
wxMacMakeStringFromPascal( const unsigned char * from
);
36 #include <CoreGraphics/CoreGraphics.h>
38 #include <ApplicationServices/ApplicationServices.h>
41 #include "wx/bitmap.h"
42 #include "wx/window.h"
44 class WXDLLIMPEXP_CORE wxMacCGContextStateSaver
46 wxDECLARE_NO_COPY_CLASS(wxMacCGContextStateSaver
);
49 wxMacCGContextStateSaver( CGContextRef cg
)
52 CGContextSaveGState( cg
);
54 ~wxMacCGContextStateSaver()
56 CGContextRestoreGState( m_cg
);
62 class WXDLLIMPEXP_CORE wxDeferredObjectDeleter
: public wxObject
65 wxDeferredObjectDeleter( wxObject
* obj
) : m_obj(obj
)
68 virtual ~wxDeferredObjectDeleter()
78 WXDLLIMPEXP_CORE CGImageRef
wxMacCreateCGImageFromBitmap( const wxBitmap
& bitmap
);
80 WXDLLIMPEXP_CORE CGDataProviderRef
wxMacCGDataProviderCreateWithCFData( CFDataRef data
);
81 WXDLLIMPEXP_CORE CGDataConsumerRef
wxMacCGDataConsumerCreateWithCFData( CFMutableDataRef data
);
82 WXDLLIMPEXP_CORE CGDataProviderRef
wxMacCGDataProviderCreateWithMemoryBuffer( const wxMemoryBuffer
& buf
);
84 CGColorSpaceRef WXDLLIMPEXP_CORE
wxMacGetGenericRGBColorSpace(void);
88 extern wxWindow
* g_MacLastWindow
;
89 class wxNonOwnedWindow
;
91 // temporary typedef so that no additional casts are necessary within carbon code at the moment
98 WXDLLIMPEXP_CORE wxWindowMac
* wxFindWindowFromWXWidget(WXWidget inControl
);
101 typedef wxMacControl wxWidgetImplType
;
103 typedef wxWidgetImpl wxWidgetImplType
;
107 class wxMenuItemImpl
: public wxObject
110 wxMenuItemImpl( wxMenuItem
* peer
) : m_peer(peer
)
114 virtual ~wxMenuItemImpl() ;
115 virtual void SetBitmap( const wxBitmap
& bitmap
) = 0;
116 virtual void Enable( bool enable
) = 0;
117 virtual void Check( bool check
) = 0;
118 virtual void SetLabel( const wxString
& text
, wxAcceleratorEntry
*entry
) = 0;
119 virtual void Hide( bool hide
= true ) = 0;
121 virtual void * GetHMenuItem() = 0;
123 wxMenuItem
* GetWXPeer() { return m_peer
; }
125 static wxMenuItemImpl
* Create( wxMenuItem
* peer
, wxMenu
*pParentMenu
,
127 const wxString
& text
,
128 wxAcceleratorEntry
*entry
,
129 const wxString
& strHelp
,
136 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl
)
139 class wxMenuImpl
: public wxObject
142 wxMenuImpl( wxMenu
* peer
) : m_peer(peer
)
146 virtual ~wxMenuImpl() ;
147 virtual void InsertOrAppend(wxMenuItem
*pItem
, size_t pos
) = 0;
148 virtual void Remove( wxMenuItem
*pItem
) = 0;
150 virtual void MakeRoot() = 0;
152 virtual void SetTitle( const wxString
& text
) = 0;
154 virtual WXHMENU
GetHMenu() = 0;
156 wxMenu
* GetWXPeer() { return m_peer
; }
158 virtual void PopUp( wxWindow
*win
, int x
, int y
) = 0;
160 static wxMenuImpl
* Create( wxMenu
* peer
, const wxString
& title
);
161 static wxMenuImpl
* CreateRootMenu( wxMenu
* peer
);
165 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl
)
170 class WXDLLIMPEXP_CORE wxWidgetImpl
: public wxObject
173 wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
= false );
175 virtual ~wxWidgetImpl();
179 bool IsRootControl() const { return m_isRootControl
; }
181 wxWindowMac
* GetWXPeer() const { return m_wxPeer
; }
183 bool IsOk() const { return GetWXWidget() != NULL
; }
185 // not only the control itself, but also all its parents must be visible
186 // in order for this function to return true
187 virtual bool IsVisible() const = 0;
188 // set the visibility of this widget (maybe latent)
189 virtual void SetVisibility( bool visible
) = 0;
191 virtual void Raise() = 0;
193 virtual void Lower() = 0;
195 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
) = 0;
197 virtual WXWidget
GetWXWidget() const = 0;
199 virtual void SetBackgroundColour( const wxColour
& col
) = 0;
201 // all coordinates in native parent widget relative coordinates
202 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
203 virtual void Move(int x
, int y
, int width
, int height
) = 0;
204 virtual void GetPosition( int &x
, int &y
) const = 0;
205 virtual void GetSize( int &width
, int &height
) const = 0;
206 virtual void SetControlSize( wxWindowVariant variant
) = 0;
208 // native view coordinates are topleft to bottom right (flipped regarding CoreGraphics origin)
209 virtual bool IsFlipped() const { return true; }
211 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
) = 0;
212 virtual bool GetNeedsDisplay() const = 0;
214 virtual bool NeedsFocusRect() const;
215 virtual void SetNeedsFocusRect( bool needs
);
217 virtual bool NeedsFrame() const;
218 virtual void SetNeedsFrame( bool needs
);
220 virtual bool CanFocus() const = 0;
221 // return true if successful
222 virtual bool SetFocus() = 0;
223 virtual bool HasFocus() const = 0;
225 virtual void RemoveFromParent() = 0;
226 virtual void Embed( wxWidgetImpl
*parent
) = 0;
228 virtual void SetDefaultButton( bool isDefault
) = 0;
229 virtual void PerformClick() = 0;
230 virtual void SetLabel( const wxString
& title
, wxFontEncoding encoding
) = 0;
232 virtual void SetCursor( const wxCursor
& cursor
) = 0;
233 virtual void CaptureMouse() = 0;
234 virtual void ReleaseMouse() = 0;
236 virtual wxInt32
GetValue() const = 0;
237 virtual void SetValue( wxInt32 v
) = 0;
238 virtual wxBitmap
GetBitmap() const = 0;
239 virtual void SetBitmap( const wxBitmap
& bitmap
) = 0;
240 virtual void SetBitmapPosition( wxDirection dir
) = 0;
241 virtual void SetupTabs( const wxNotebook
¬ebook
) =0;
242 virtual void GetBestRect( wxRect
*r
) const = 0;
243 virtual bool IsEnabled() const = 0;
244 virtual void Enable( bool enable
) = 0;
245 virtual void SetMinimum( wxInt32 v
) = 0;
246 virtual void SetMaximum( wxInt32 v
) = 0;
247 virtual wxInt32
GetMinimum() const = 0;
248 virtual wxInt32
GetMaximum() const = 0;
249 virtual void PulseGauge() = 0;
250 virtual void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
) = 0;
252 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true ) = 0;
254 // is the clicked event sent AFTER the state already changed, so no additional
255 // state changing logic is required from the outside
256 virtual bool ButtonClickDidStateChange() = 0;
258 virtual void InstallEventHandler( WXWidget control
= NULL
) = 0;
260 // static methods for associating native controls and their implementations
263 FindFromWXWidget(WXWidget control
);
265 static void RemoveAssociations( wxWidgetImpl
* impl
);
267 static void Associate( WXWidget control
, wxWidgetImpl
*impl
);
269 static WXWidget
FindFocus();
271 // static creation methods, must be implemented by all toolkits
273 static wxWidgetImplType
* CreateUserPane( wxWindowMac
* wxpeer
,
280 static wxWidgetImplType
* CreateContentView( wxNonOwnedWindow
* now
) ;
282 static wxWidgetImplType
* CreateButton( wxWindowMac
* wxpeer
,
285 const wxString
& label
,
291 static wxWidgetImplType
* CreateDisclosureTriangle( wxWindowMac
* wxpeer
,
294 const wxString
& label
,
300 static wxWidgetImplType
* CreateStaticLine( wxWindowMac
* wxpeer
,
308 static wxWidgetImplType
* CreateGroupBox( wxWindowMac
* wxpeer
,
311 const wxString
& label
,
317 static wxWidgetImplType
* CreateStaticText( wxWindowMac
* wxpeer
,
320 const wxString
& label
,
326 static wxWidgetImplType
* CreateTextControl( wxTextCtrl
* wxpeer
,
329 const wxString
& content
,
335 static wxWidgetImplType
* CreateSearchControl( wxTextCtrl
* wxpeer
,
338 const wxString
& content
,
344 static wxWidgetImplType
* CreateCheckBox( wxWindowMac
* wxpeer
,
347 const wxString
& label
,
353 static wxWidgetImplType
* CreateRadioButton( wxWindowMac
* wxpeer
,
356 const wxString
& label
,
362 static wxWidgetImplType
* CreateToggleButton( wxWindowMac
* wxpeer
,
365 const wxString
& label
,
371 static wxWidgetImplType
* CreateBitmapToggleButton( wxWindowMac
* wxpeer
,
374 const wxBitmap
& bitmap
,
380 static wxWidgetImplType
* CreateBitmapButton( wxWindowMac
* wxpeer
,
383 const wxBitmap
& bitmap
,
389 static wxWidgetImplType
* CreateTabView( wxWindowMac
* wxpeer
,
397 static wxWidgetImplType
* CreateGauge( wxWindowMac
* wxpeer
,
408 static wxWidgetImplType
* CreateSlider( wxWindowMac
* wxpeer
,
419 static wxWidgetImplType
* CreateSpinButton( wxWindowMac
* wxpeer
,
430 static wxWidgetImplType
* CreateScrollBar( wxWindowMac
* wxpeer
,
438 static wxWidgetImplType
* CreateChoice( wxWindowMac
* wxpeer
,
447 static wxWidgetImplType
* CreateListBox( wxWindowMac
* wxpeer
,
455 // converts from Toplevel-Content relative to local
456 static void Convert( wxPoint
*pt
, wxWidgetImpl
*from
, wxWidgetImpl
*to
);
458 bool m_isRootControl
;
459 wxWindowMac
* m_wxPeer
;
460 bool m_needsFocusRect
;
463 DECLARE_ABSTRACT_CLASS(wxWidgetImpl
)
467 // the interface to be implemented eg by a listbox
470 class WXDLLIMPEXP_CORE wxListWidgetColumn
473 virtual ~wxListWidgetColumn() {}
476 class WXDLLIMPEXP_CORE wxListWidgetCellValue
479 wxListWidgetCellValue() {}
480 virtual ~wxListWidgetCellValue() {}
482 virtual void Set( CFStringRef value
) = 0;
483 virtual void Set( const wxString
& value
) = 0;
484 virtual void Set( int value
) = 0;
485 virtual void Check( bool check
);
487 virtual bool IsChecked() const;
488 virtual int GetIntValue() const = 0;
489 virtual wxString
GetStringValue() const = 0;
492 class WXDLLIMPEXP_CORE wxListWidgetImpl
495 wxListWidgetImpl() {}
496 virtual ~wxListWidgetImpl() { }
498 virtual wxListWidgetColumn
* InsertTextColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
499 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
500 virtual wxListWidgetColumn
* InsertCheckColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
501 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
505 // TODO will be replaced
506 virtual void ListDelete( unsigned int n
) = 0;
507 virtual void ListInsert( unsigned int n
) = 0;
508 virtual void ListClear() = 0;
512 virtual void ListDeselectAll() = 0;
513 virtual void ListSetSelection( unsigned int n
, bool select
, bool multi
) = 0;
514 virtual int ListGetSelection() const = 0;
515 virtual int ListGetSelections( wxArrayInt
& aSelections
) const = 0;
516 virtual bool ListIsSelected( unsigned int n
) const = 0;
520 virtual void ListScrollTo( unsigned int n
) = 0;
521 virtual void UpdateLine( unsigned int n
, wxListWidgetColumn
* col
= NULL
) = 0;
522 virtual void UpdateLineToEnd( unsigned int n
) = 0;
526 virtual unsigned int ListGetCount() const = 0;
530 // interface to be implemented by a textcontrol
533 class WXDLLIMPEXP_FWD_CORE wxTextAttr
;
535 // common interface for all implementations
536 class WXDLLIMPEXP_CORE wxTextWidgetImpl
540 wxTextWidgetImpl() {}
542 virtual ~wxTextWidgetImpl() {}
544 virtual bool CanFocus() const { return true; }
546 virtual wxString
GetStringValue() const = 0 ;
547 virtual void SetStringValue( const wxString
&val
) = 0 ;
548 virtual void SetSelection( long from
, long to
) = 0 ;
549 virtual void GetSelection( long* from
, long* to
) const = 0 ;
550 virtual void WriteText( const wxString
& str
) = 0 ;
552 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
553 virtual void Copy() ;
555 virtual void Paste() ;
556 virtual bool CanPaste() const ;
557 virtual void SetEditable( bool editable
) ;
558 virtual long GetLastPosition() const ;
559 virtual void Replace( long from
, long to
, const wxString
&str
) ;
560 virtual void Remove( long from
, long to
) ;
563 virtual bool HasOwnContextMenu() const
566 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
569 virtual void Clear() ;
570 virtual bool CanUndo() const;
571 virtual void Undo() ;
572 virtual bool CanRedo() const;
573 virtual void Redo() ;
574 virtual int GetNumberOfLines() const ;
575 virtual long XYToPosition(long x
, long y
) const;
576 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
577 virtual void ShowPosition(long WXUNUSED(pos
)) ;
578 virtual int GetLineLength(long lineNo
) const ;
579 virtual wxString
GetLineText(long lineNo
) const ;
580 virtual void CheckSpelling(bool WXUNUSED(check
)) { }
584 // common interface for search controls
587 class wxSearchWidgetImpl
590 wxSearchWidgetImpl(){}
591 virtual ~wxSearchWidgetImpl(){}
593 // search field options
594 virtual void ShowSearchButton( bool show
) = 0;
595 virtual bool IsSearchButtonVisible() const = 0;
597 virtual void ShowCancelButton( bool show
) = 0;
598 virtual bool IsCancelButtonVisible() const = 0;
600 virtual void SetSearchMenu( wxMenu
* menu
) = 0;
602 virtual void SetDescriptiveText(const wxString
& text
) = 0;
606 // toplevel window implementation class
609 class wxNonOwnedWindowImpl
: public wxObject
612 wxNonOwnedWindowImpl( wxNonOwnedWindow
* nonownedwnd
) : m_wxPeer(nonownedwnd
)
615 wxNonOwnedWindowImpl()
618 virtual ~wxNonOwnedWindowImpl()
622 virtual void Destroy()
626 virtual void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
627 long style
, long extraStyle
, const wxString
& name
) = 0;
630 virtual WXWindow
GetWXWindow() const = 0;
640 virtual bool Show(bool WXUNUSED(show
))
645 virtual bool ShowWithEffect(bool show
, wxShowEffect
WXUNUSED(effect
), unsigned WXUNUSED(timeout
))
650 virtual void Update()
654 virtual bool SetTransparent(wxByte
WXUNUSED(alpha
))
659 virtual bool SetBackgroundColour(const wxColour
& WXUNUSED(col
) )
664 virtual void SetExtraStyle( long WXUNUSED(exStyle
) )
668 virtual bool SetBackgroundStyle(wxBackgroundStyle
WXUNUSED(style
))
673 bool CanSetTransparent()
678 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
679 virtual void MoveWindow(int x
, int y
, int width
, int height
) = 0;
680 virtual void GetPosition( int &x
, int &y
) const = 0;
681 virtual void GetSize( int &width
, int &height
) const = 0;
683 virtual bool SetShape(const wxRegion
& WXUNUSED(region
))
688 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) = 0;
690 virtual bool IsMaximized() const = 0;
692 virtual bool IsIconized() const= 0;
694 virtual void Iconize( bool iconize
)= 0;
696 virtual void Maximize(bool maximize
) = 0;
698 virtual bool IsFullScreen() const= 0;
700 virtual bool ShowFullScreen(bool show
, long style
)= 0;
702 virtual void RequestUserAttention(int flags
) = 0;
704 virtual void ScreenToWindow( int *x
, int *y
) = 0;
706 virtual void WindowToScreen( int *x
, int *y
) = 0;
708 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
710 // static creation methods, must be implemented by all toolkits
712 static wxNonOwnedWindowImpl
* CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
713 long style
, long extraStyle
, const wxString
& name
) ;
716 wxNonOwnedWindow
* m_wxPeer
;
717 DECLARE_ABSTRACT_CLASS(wxNonOwnedWindowImpl
)
722 //---------------------------------------------------------------------------
723 // cocoa bridging utilities
724 //---------------------------------------------------------------------------
726 bool wxMacInitCocoa();
728 class WXDLLIMPEXP_CORE wxMacAutoreleasePool
731 wxMacAutoreleasePool();
732 ~wxMacAutoreleasePool();
739 void wxMacCocoaRelease( void* obj
);
740 void wxMacCocoaAutorelease( void* obj
);
741 void* wxMacCocoaRetain( void* obj
);
745 // _WX_PRIVATE_CORE_H_