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
99 typedef wxMacControl wxWidgetImplType
;
101 typedef wxWidgetImpl wxWidgetImplType
;
104 class wxMenuItemImpl
: public wxObject
107 wxMenuItemImpl( wxMenuItem
* peer
) : m_peer(peer
)
111 virtual ~wxMenuItemImpl() ;
112 virtual void SetBitmap( const wxBitmap
& bitmap
) = 0;
113 virtual void Enable( bool enable
) = 0;
114 virtual void Check( bool check
) = 0;
115 virtual void SetLabel( const wxString
& text
, wxAcceleratorEntry
*entry
) = 0;
116 virtual void Hide( bool hide
= true ) = 0;
118 virtual void * GetHMenuItem() = 0;
120 wxMenuItem
* GetWXPeer() { return m_peer
; }
122 static wxMenuItemImpl
* Create( wxMenuItem
* peer
, wxMenu
*pParentMenu
,
124 const wxString
& text
,
125 wxAcceleratorEntry
*entry
,
126 const wxString
& strHelp
,
133 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl
)
136 class wxMenuImpl
: public wxObject
139 wxMenuImpl( wxMenu
* peer
) : m_peer(peer
)
143 virtual ~wxMenuImpl() ;
144 virtual void InsertOrAppend(wxMenuItem
*pItem
, size_t pos
) = 0;
145 virtual void Remove( wxMenuItem
*pItem
) = 0;
147 virtual void MakeRoot() = 0;
149 virtual void SetTitle( const wxString
& text
) = 0;
151 virtual WXHMENU
GetHMenu() = 0;
153 wxMenu
* GetWXPeer() { return m_peer
; }
155 virtual void PopUp( wxWindow
*win
, int x
, int y
) = 0;
157 static wxMenuImpl
* Create( wxMenu
* peer
, const wxString
& title
);
158 static wxMenuImpl
* CreateRootMenu( wxMenu
* peer
);
162 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl
)
167 class WXDLLIMPEXP_CORE wxWidgetImpl
: public wxObject
170 wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
= false );
172 virtual ~wxWidgetImpl();
176 bool IsRootControl() const { return m_isRootControl
; }
178 wxWindowMac
* GetWXPeer() const { return m_wxPeer
; }
180 bool IsOk() const { return GetWXWidget() != NULL
; }
182 // not only the control itself, but also all its parents must be visible
183 // in order for this function to return true
184 virtual bool IsVisible() const = 0;
185 // set the visibility of this widget (maybe latent)
186 virtual void SetVisibility( bool visible
) = 0;
188 virtual void Raise() = 0;
190 virtual void Lower() = 0;
192 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
) = 0;
194 virtual WXWidget
GetWXWidget() const = 0;
196 virtual void SetBackgroundColour( const wxColour
& col
) = 0;
198 // all coordinates in native parent widget relative coordinates
199 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
200 virtual void Move(int x
, int y
, int width
, int height
) = 0;
201 virtual void GetPosition( int &x
, int &y
) const = 0;
202 virtual void GetSize( int &width
, int &height
) const = 0;
203 virtual void SetControlSize( wxWindowVariant variant
) = 0;
205 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
) = 0;
206 virtual bool GetNeedsDisplay() const = 0;
208 virtual bool NeedsFocusRect() const;
209 virtual void SetNeedsFocusRect( bool needs
);
211 virtual bool NeedsFrame() const;
212 virtual void SetNeedsFrame( bool needs
);
214 virtual bool CanFocus() const = 0;
215 // return true if successful
216 virtual bool SetFocus() = 0;
217 virtual bool HasFocus() const = 0;
219 virtual void RemoveFromParent() = 0;
220 virtual void Embed( wxWidgetImpl
*parent
) = 0;
222 virtual void SetDefaultButton( bool isDefault
) = 0;
223 virtual void PerformClick() = 0;
224 virtual void SetLabel( const wxString
& title
, wxFontEncoding encoding
) = 0;
226 virtual void SetCursor( const wxCursor
& cursor
) = 0;
227 virtual void CaptureMouse() = 0;
228 virtual void ReleaseMouse() = 0;
230 virtual wxInt32
GetValue() const = 0;
231 virtual void SetValue( wxInt32 v
) = 0;
232 virtual void SetBitmap( const wxBitmap
& bitmap
) = 0;
233 virtual void SetupTabs( const wxNotebook
¬ebook
) =0;
234 virtual void GetBestRect( wxRect
*r
) const = 0;
235 virtual bool IsEnabled() const = 0;
236 virtual void Enable( bool enable
) = 0;
237 virtual void SetMinimum( wxInt32 v
) = 0;
238 virtual void SetMaximum( wxInt32 v
) = 0;
239 virtual wxInt32
GetMinimum() const = 0;
240 virtual wxInt32
GetMaximum() const = 0;
241 virtual void PulseGauge() = 0;
242 virtual void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
) = 0;
244 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true ) = 0;
246 // is the clicked event sent AFTER the state already changed, so no additional
247 // state changing logic is required from the outside
248 virtual bool ButtonClickDidStateChange() = 0;
250 virtual void InstallEventHandler( WXWidget control
= NULL
) = 0;
252 // static methods for associating native controls and their implementations
255 FindFromWXWidget(WXWidget control
);
257 static void RemoveAssociations( wxWidgetImpl
* impl
);
259 static void Associate( WXWidget control
, wxWidgetImpl
*impl
);
261 // static creation methods, must be implemented by all toolkits
263 static wxWidgetImplType
* CreateUserPane( wxWindowMac
* wxpeer
,
270 static wxWidgetImplType
* CreateContentView( wxNonOwnedWindow
* now
) ;
272 static wxWidgetImplType
* CreateButton( wxWindowMac
* wxpeer
,
275 const wxString
& label
,
281 static wxWidgetImplType
* CreateDisclosureTriangle( wxWindowMac
* wxpeer
,
284 const wxString
& label
,
290 static wxWidgetImplType
* CreateStaticLine( wxWindowMac
* wxpeer
,
298 static wxWidgetImplType
* CreateGroupBox( wxWindowMac
* wxpeer
,
301 const wxString
& label
,
307 static wxWidgetImplType
* CreateStaticText( wxWindowMac
* wxpeer
,
310 const wxString
& label
,
316 static wxWidgetImplType
* CreateTextControl( wxTextCtrl
* wxpeer
,
319 const wxString
& content
,
325 static wxWidgetImplType
* CreateSearchControl( wxTextCtrl
* wxpeer
,
328 const wxString
& content
,
334 static wxWidgetImplType
* CreateCheckBox( wxWindowMac
* wxpeer
,
337 const wxString
& label
,
343 static wxWidgetImplType
* CreateRadioButton( wxWindowMac
* wxpeer
,
346 const wxString
& label
,
352 static wxWidgetImplType
* CreateToggleButton( wxWindowMac
* wxpeer
,
355 const wxString
& label
,
361 static wxWidgetImplType
* CreateBitmapToggleButton( wxWindowMac
* wxpeer
,
364 const wxBitmap
& bitmap
,
370 static wxWidgetImplType
* CreateBitmapButton( wxWindowMac
* wxpeer
,
373 const wxBitmap
& bitmap
,
379 static wxWidgetImplType
* CreateTabView( wxWindowMac
* wxpeer
,
387 static wxWidgetImplType
* CreateGauge( wxWindowMac
* wxpeer
,
398 static wxWidgetImplType
* CreateSlider( wxWindowMac
* wxpeer
,
409 static wxWidgetImplType
* CreateSpinButton( wxWindowMac
* wxpeer
,
420 static wxWidgetImplType
* CreateScrollBar( wxWindowMac
* wxpeer
,
428 static wxWidgetImplType
* CreateChoice( wxWindowMac
* wxpeer
,
437 static wxWidgetImplType
* CreateListBox( wxWindowMac
* wxpeer
,
445 // converts from Toplevel-Content relative to local
446 static void Convert( wxPoint
*pt
, wxWidgetImpl
*from
, wxWidgetImpl
*to
);
448 bool m_isRootControl
;
449 wxWindowMac
* m_wxPeer
;
450 bool m_needsFocusRect
;
453 DECLARE_ABSTRACT_CLASS(wxWidgetImpl
)
457 // the interface to be implemented eg by a listbox
460 class WXDLLIMPEXP_CORE wxListWidgetColumn
463 virtual ~wxListWidgetColumn() {}
466 class WXDLLIMPEXP_CORE wxListWidgetCellValue
469 wxListWidgetCellValue() {}
470 virtual ~wxListWidgetCellValue() {}
472 virtual void Set( CFStringRef value
) = 0;
473 virtual void Set( const wxString
& value
) = 0;
474 virtual void Set( int value
) = 0;
476 virtual int GetIntValue() const = 0;
477 virtual wxString
GetStringValue() const = 0;
480 class WXDLLIMPEXP_CORE wxListWidgetImpl
483 wxListWidgetImpl() {}
484 virtual ~wxListWidgetImpl() { }
486 virtual wxListWidgetColumn
* InsertTextColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
487 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
488 virtual wxListWidgetColumn
* InsertCheckColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
489 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
493 // TODO will be replaced
494 virtual void ListDelete( unsigned int n
) = 0;
495 virtual void ListInsert( unsigned int n
) = 0;
496 virtual void ListClear() = 0;
500 virtual void ListDeselectAll() = 0;
501 virtual void ListSetSelection( unsigned int n
, bool select
, bool multi
) = 0;
502 virtual int ListGetSelection() const = 0;
503 virtual int ListGetSelections( wxArrayInt
& aSelections
) const = 0;
504 virtual bool ListIsSelected( unsigned int n
) const = 0;
508 virtual void ListScrollTo( unsigned int n
) = 0;
509 virtual void UpdateLine( unsigned int n
, wxListWidgetColumn
* col
= NULL
) = 0;
510 virtual void UpdateLineToEnd( unsigned int n
) = 0;
514 virtual unsigned int ListGetCount() const = 0;
518 // interface to be implemented by a textcontrol
521 class WXDLLIMPEXP_FWD_CORE wxTextAttr
;
523 // common interface for all implementations
524 class WXDLLIMPEXP_CORE wxTextWidgetImpl
528 wxTextWidgetImpl() {}
530 virtual ~wxTextWidgetImpl() {}
532 virtual bool CanFocus() const { return true; }
534 virtual wxString
GetStringValue() const = 0 ;
535 virtual void SetStringValue( const wxString
&val
) = 0 ;
536 virtual void SetSelection( long from
, long to
) = 0 ;
537 virtual void GetSelection( long* from
, long* to
) const = 0 ;
538 virtual void WriteText( const wxString
& str
) = 0 ;
540 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
541 virtual void Copy() ;
543 virtual void Paste() ;
544 virtual bool CanPaste() const ;
545 virtual void SetEditable( bool editable
) ;
546 virtual long GetLastPosition() const ;
547 virtual void Replace( long from
, long to
, const wxString
&str
) ;
548 virtual void Remove( long from
, long to
) ;
551 virtual bool HasOwnContextMenu() const
554 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
557 virtual void Clear() ;
558 virtual bool CanUndo() const;
559 virtual void Undo() ;
560 virtual bool CanRedo() const;
561 virtual void Redo() ;
562 virtual int GetNumberOfLines() const ;
563 virtual long XYToPosition(long x
, long y
) const;
564 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
565 virtual void ShowPosition(long WXUNUSED(pos
)) ;
566 virtual int GetLineLength(long lineNo
) const ;
567 virtual wxString
GetLineText(long lineNo
) const ;
568 virtual void CheckSpelling(bool WXUNUSED(check
)) { }
572 // common interface for search controls
575 class wxSearchWidgetImpl
578 wxSearchWidgetImpl(){}
579 virtual ~wxSearchWidgetImpl(){}
581 // search field options
582 virtual void ShowSearchButton( bool show
) = 0;
583 virtual bool IsSearchButtonVisible() const = 0;
585 virtual void ShowCancelButton( bool show
) = 0;
586 virtual bool IsCancelButtonVisible() const = 0;
588 virtual void SetSearchMenu( wxMenu
* menu
) = 0;
590 virtual void SetDescriptiveText(const wxString
& text
) = 0;
594 // toplevel window implementation class
597 class wxNonOwnedWindowImpl
: public wxObject
600 wxNonOwnedWindowImpl( wxNonOwnedWindow
* nonownedwnd
) : m_wxPeer(nonownedwnd
)
603 wxNonOwnedWindowImpl()
606 virtual ~wxNonOwnedWindowImpl()
610 virtual void Destroy()
614 virtual void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
615 long style
, long extraStyle
, const wxString
& name
) = 0;
618 virtual WXWindow
GetWXWindow() const = 0;
628 virtual bool Show(bool WXUNUSED(show
))
633 virtual bool ShowWithEffect(bool show
, wxShowEffect
WXUNUSED(effect
), unsigned WXUNUSED(timeout
))
638 virtual void Update()
642 virtual bool SetTransparent(wxByte
WXUNUSED(alpha
))
647 virtual bool SetBackgroundColour(const wxColour
& WXUNUSED(col
) )
652 virtual void SetExtraStyle( long WXUNUSED(exStyle
) )
656 virtual bool SetBackgroundStyle(wxBackgroundStyle
WXUNUSED(style
))
661 bool CanSetTransparent()
666 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
667 virtual void MoveWindow(int x
, int y
, int width
, int height
) = 0;
668 virtual void GetPosition( int &x
, int &y
) const = 0;
669 virtual void GetSize( int &width
, int &height
) const = 0;
671 virtual bool SetShape(const wxRegion
& WXUNUSED(region
))
676 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) = 0;
678 virtual bool IsMaximized() const = 0;
680 virtual bool IsIconized() const= 0;
682 virtual void Iconize( bool iconize
)= 0;
684 virtual void Maximize(bool maximize
) = 0;
686 virtual bool IsFullScreen() const= 0;
688 virtual bool ShowFullScreen(bool show
, long style
)= 0;
690 virtual void RequestUserAttention(int flags
) = 0;
692 virtual void ScreenToWindow( int *x
, int *y
) = 0;
694 virtual void WindowToScreen( int *x
, int *y
) = 0;
696 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
698 // static creation methods, must be implemented by all toolkits
700 static wxNonOwnedWindowImpl
* CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
701 long style
, long extraStyle
, const wxString
& name
) ;
704 wxNonOwnedWindow
* m_wxPeer
;
705 DECLARE_ABSTRACT_CLASS(wxNonOwnedWindowImpl
)
710 //---------------------------------------------------------------------------
711 // cocoa bridging utilities
712 //---------------------------------------------------------------------------
714 bool wxMacInitCocoa();
716 class WXDLLIMPEXP_CORE wxMacAutoreleasePool
719 wxMacAutoreleasePool();
720 ~wxMacAutoreleasePool();
727 void wxMacCocoaRelease( void* obj
);
728 void wxMacCocoaAutorelease( void* obj
);
729 void* wxMacCocoaRetain( void* obj
);
733 // _WX_PRIVATE_CORE_H_