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 void SetBitmap( const wxBitmap
& bitmap
) = 0;
239 virtual void SetupTabs( const wxNotebook
¬ebook
) =0;
240 virtual void GetBestRect( wxRect
*r
) const = 0;
241 virtual bool IsEnabled() const = 0;
242 virtual void Enable( bool enable
) = 0;
243 virtual void SetMinimum( wxInt32 v
) = 0;
244 virtual void SetMaximum( wxInt32 v
) = 0;
245 virtual wxInt32
GetMinimum() const = 0;
246 virtual wxInt32
GetMaximum() const = 0;
247 virtual void PulseGauge() = 0;
248 virtual void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
) = 0;
250 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true ) = 0;
252 // is the clicked event sent AFTER the state already changed, so no additional
253 // state changing logic is required from the outside
254 virtual bool ButtonClickDidStateChange() = 0;
256 virtual void InstallEventHandler( WXWidget control
= NULL
) = 0;
258 // static methods for associating native controls and their implementations
261 FindFromWXWidget(WXWidget control
);
263 static void RemoveAssociations( wxWidgetImpl
* impl
);
265 static void Associate( WXWidget control
, wxWidgetImpl
*impl
);
267 static WXWidget
FindFocus();
269 // static creation methods, must be implemented by all toolkits
271 static wxWidgetImplType
* CreateUserPane( wxWindowMac
* wxpeer
,
278 static wxWidgetImplType
* CreateContentView( wxNonOwnedWindow
* now
) ;
280 static wxWidgetImplType
* CreateButton( wxWindowMac
* wxpeer
,
283 const wxString
& label
,
289 static wxWidgetImplType
* CreateDisclosureTriangle( wxWindowMac
* wxpeer
,
292 const wxString
& label
,
298 static wxWidgetImplType
* CreateStaticLine( wxWindowMac
* wxpeer
,
306 static wxWidgetImplType
* CreateGroupBox( wxWindowMac
* wxpeer
,
309 const wxString
& label
,
315 static wxWidgetImplType
* CreateStaticText( wxWindowMac
* wxpeer
,
318 const wxString
& label
,
324 static wxWidgetImplType
* CreateTextControl( wxTextCtrl
* wxpeer
,
327 const wxString
& content
,
333 static wxWidgetImplType
* CreateSearchControl( wxTextCtrl
* wxpeer
,
336 const wxString
& content
,
342 static wxWidgetImplType
* CreateCheckBox( wxWindowMac
* wxpeer
,
345 const wxString
& label
,
351 static wxWidgetImplType
* CreateRadioButton( wxWindowMac
* wxpeer
,
354 const wxString
& label
,
360 static wxWidgetImplType
* CreateToggleButton( wxWindowMac
* wxpeer
,
363 const wxString
& label
,
369 static wxWidgetImplType
* CreateBitmapToggleButton( wxWindowMac
* wxpeer
,
372 const wxBitmap
& bitmap
,
378 static wxWidgetImplType
* CreateBitmapButton( wxWindowMac
* wxpeer
,
381 const wxBitmap
& bitmap
,
387 static wxWidgetImplType
* CreateTabView( wxWindowMac
* wxpeer
,
395 static wxWidgetImplType
* CreateGauge( wxWindowMac
* wxpeer
,
406 static wxWidgetImplType
* CreateSlider( wxWindowMac
* wxpeer
,
417 static wxWidgetImplType
* CreateSpinButton( wxWindowMac
* wxpeer
,
428 static wxWidgetImplType
* CreateScrollBar( wxWindowMac
* wxpeer
,
436 static wxWidgetImplType
* CreateChoice( wxWindowMac
* wxpeer
,
445 static wxWidgetImplType
* CreateListBox( wxWindowMac
* wxpeer
,
453 // converts from Toplevel-Content relative to local
454 static void Convert( wxPoint
*pt
, wxWidgetImpl
*from
, wxWidgetImpl
*to
);
456 bool m_isRootControl
;
457 wxWindowMac
* m_wxPeer
;
458 bool m_needsFocusRect
;
461 DECLARE_ABSTRACT_CLASS(wxWidgetImpl
)
465 // the interface to be implemented eg by a listbox
468 class WXDLLIMPEXP_CORE wxListWidgetColumn
471 virtual ~wxListWidgetColumn() {}
474 class WXDLLIMPEXP_CORE wxListWidgetCellValue
477 wxListWidgetCellValue() {}
478 virtual ~wxListWidgetCellValue() {}
480 virtual void Set( CFStringRef value
) = 0;
481 virtual void Set( const wxString
& value
) = 0;
482 virtual void Set( int value
) = 0;
484 virtual int GetIntValue() const = 0;
485 virtual wxString
GetStringValue() const = 0;
488 class WXDLLIMPEXP_CORE wxListWidgetImpl
491 wxListWidgetImpl() {}
492 virtual ~wxListWidgetImpl() { }
494 virtual wxListWidgetColumn
* InsertTextColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
495 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
496 virtual wxListWidgetColumn
* InsertCheckColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
497 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
501 // TODO will be replaced
502 virtual void ListDelete( unsigned int n
) = 0;
503 virtual void ListInsert( unsigned int n
) = 0;
504 virtual void ListClear() = 0;
508 virtual void ListDeselectAll() = 0;
509 virtual void ListSetSelection( unsigned int n
, bool select
, bool multi
) = 0;
510 virtual int ListGetSelection() const = 0;
511 virtual int ListGetSelections( wxArrayInt
& aSelections
) const = 0;
512 virtual bool ListIsSelected( unsigned int n
) const = 0;
516 virtual void ListScrollTo( unsigned int n
) = 0;
517 virtual void UpdateLine( unsigned int n
, wxListWidgetColumn
* col
= NULL
) = 0;
518 virtual void UpdateLineToEnd( unsigned int n
) = 0;
522 virtual unsigned int ListGetCount() const = 0;
526 // interface to be implemented by a textcontrol
529 class WXDLLIMPEXP_FWD_CORE wxTextAttr
;
531 // common interface for all implementations
532 class WXDLLIMPEXP_CORE wxTextWidgetImpl
536 wxTextWidgetImpl() {}
538 virtual ~wxTextWidgetImpl() {}
540 virtual bool CanFocus() const { return true; }
542 virtual wxString
GetStringValue() const = 0 ;
543 virtual void SetStringValue( const wxString
&val
) = 0 ;
544 virtual void SetSelection( long from
, long to
) = 0 ;
545 virtual void GetSelection( long* from
, long* to
) const = 0 ;
546 virtual void WriteText( const wxString
& str
) = 0 ;
548 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
549 virtual void Copy() ;
551 virtual void Paste() ;
552 virtual bool CanPaste() const ;
553 virtual void SetEditable( bool editable
) ;
554 virtual long GetLastPosition() const ;
555 virtual void Replace( long from
, long to
, const wxString
&str
) ;
556 virtual void Remove( long from
, long to
) ;
559 virtual bool HasOwnContextMenu() const
562 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
565 virtual void Clear() ;
566 virtual bool CanUndo() const;
567 virtual void Undo() ;
568 virtual bool CanRedo() const;
569 virtual void Redo() ;
570 virtual int GetNumberOfLines() const ;
571 virtual long XYToPosition(long x
, long y
) const;
572 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
573 virtual void ShowPosition(long WXUNUSED(pos
)) ;
574 virtual int GetLineLength(long lineNo
) const ;
575 virtual wxString
GetLineText(long lineNo
) const ;
576 virtual void CheckSpelling(bool WXUNUSED(check
)) { }
580 // common interface for search controls
583 class wxSearchWidgetImpl
586 wxSearchWidgetImpl(){}
587 virtual ~wxSearchWidgetImpl(){}
589 // search field options
590 virtual void ShowSearchButton( bool show
) = 0;
591 virtual bool IsSearchButtonVisible() const = 0;
593 virtual void ShowCancelButton( bool show
) = 0;
594 virtual bool IsCancelButtonVisible() const = 0;
596 virtual void SetSearchMenu( wxMenu
* menu
) = 0;
598 virtual void SetDescriptiveText(const wxString
& text
) = 0;
602 // toplevel window implementation class
605 class wxNonOwnedWindowImpl
: public wxObject
608 wxNonOwnedWindowImpl( wxNonOwnedWindow
* nonownedwnd
) : m_wxPeer(nonownedwnd
)
611 wxNonOwnedWindowImpl()
614 virtual ~wxNonOwnedWindowImpl()
618 virtual void Destroy()
622 virtual void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
623 long style
, long extraStyle
, const wxString
& name
) = 0;
626 virtual WXWindow
GetWXWindow() const = 0;
636 virtual bool Show(bool WXUNUSED(show
))
641 virtual bool ShowWithEffect(bool show
, wxShowEffect
WXUNUSED(effect
), unsigned WXUNUSED(timeout
))
646 virtual void Update()
650 virtual bool SetTransparent(wxByte
WXUNUSED(alpha
))
655 virtual bool SetBackgroundColour(const wxColour
& WXUNUSED(col
) )
660 virtual void SetExtraStyle( long WXUNUSED(exStyle
) )
664 virtual bool SetBackgroundStyle(wxBackgroundStyle
WXUNUSED(style
))
669 bool CanSetTransparent()
674 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
675 virtual void MoveWindow(int x
, int y
, int width
, int height
) = 0;
676 virtual void GetPosition( int &x
, int &y
) const = 0;
677 virtual void GetSize( int &width
, int &height
) const = 0;
679 virtual bool SetShape(const wxRegion
& WXUNUSED(region
))
684 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) = 0;
686 virtual bool IsMaximized() const = 0;
688 virtual bool IsIconized() const= 0;
690 virtual void Iconize( bool iconize
)= 0;
692 virtual void Maximize(bool maximize
) = 0;
694 virtual bool IsFullScreen() const= 0;
696 virtual bool ShowFullScreen(bool show
, long style
)= 0;
698 virtual void RequestUserAttention(int flags
) = 0;
700 virtual void ScreenToWindow( int *x
, int *y
) = 0;
702 virtual void WindowToScreen( int *x
, int *y
) = 0;
704 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
706 // static creation methods, must be implemented by all toolkits
708 static wxNonOwnedWindowImpl
* CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
709 long style
, long extraStyle
, const wxString
& name
) ;
712 wxNonOwnedWindow
* m_wxPeer
;
713 DECLARE_ABSTRACT_CLASS(wxNonOwnedWindowImpl
)
718 //---------------------------------------------------------------------------
719 // cocoa bridging utilities
720 //---------------------------------------------------------------------------
722 bool wxMacInitCocoa();
724 class WXDLLIMPEXP_CORE wxMacAutoreleasePool
727 wxMacAutoreleasePool();
728 ~wxMacAutoreleasePool();
735 void wxMacCocoaRelease( void* obj
);
736 void wxMacCocoaAutorelease( void* obj
);
737 void* wxMacCocoaRetain( void* obj
);
741 // _WX_PRIVATE_CORE_H_