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 DECLARE_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 static wxMenuImpl
* Create( wxMenu
* peer
, const wxString
& title
);
156 static wxMenuImpl
* CreateRootMenu( wxMenu
* peer
);
160 DECLARE_ABSTRACT_CLASS(wxMenuItemImpl
);
165 class WXDLLIMPEXP_CORE wxWidgetImpl
: public wxObject
168 wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
= false );
170 virtual ~wxWidgetImpl();
174 bool IsRootControl() const { return m_isRootControl
; }
176 wxWindowMac
* GetWXPeer() const { return m_wxPeer
; }
178 bool IsOk() const { return GetWXWidget() != NULL
; }
180 // not only the control itself, but also all its parents must be visible
181 // in order for this function to return true
182 virtual bool IsVisible() const = 0;
183 // set the visibility of this widget (maybe latent)
184 virtual void SetVisibility( bool visible
) = 0;
186 virtual void Raise() = 0;
188 virtual void Lower() = 0;
190 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
) = 0;
192 virtual WXWidget
GetWXWidget() const = 0;
194 virtual void SetBackgroundColour( const wxColour
& col
) = 0;
196 // all coordinates in native parent widget relative coordinates
197 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
198 virtual void Move(int x
, int y
, int width
, int height
) = 0;
199 virtual void GetPosition( int &x
, int &y
) const = 0;
200 virtual void GetSize( int &width
, int &height
) const = 0;
201 virtual void SetControlSize( wxWindowVariant variant
) = 0;
203 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
) = 0;
204 virtual bool GetNeedsDisplay() const = 0;
206 virtual bool NeedsFocusRect() const;
207 virtual void SetNeedsFocusRect( bool needs
);
209 virtual bool CanFocus() const = 0;
210 // return true if successful
211 virtual bool SetFocus() = 0;
212 virtual bool HasFocus() const = 0;
214 virtual void RemoveFromParent() = 0;
215 virtual void Embed( wxWidgetImpl
*parent
) = 0;
217 virtual void SetDefaultButton( bool isDefault
) = 0;
218 virtual void PerformClick() = 0;
219 virtual void SetLabel( const wxString
& title
, wxFontEncoding encoding
) = 0;
221 virtual wxInt32
GetValue() const = 0;
222 virtual void SetValue( wxInt32 v
) = 0;
223 virtual void SetBitmap( const wxBitmap
& bitmap
) = 0;
224 virtual void SetupTabs( const wxNotebook
¬ebook
) =0;
225 virtual void GetBestRect( wxRect
*r
) const = 0;
226 virtual bool IsEnabled() const = 0;
227 virtual void Enable( bool enable
) = 0;
228 virtual void SetMinimum( wxInt32 v
) = 0;
229 virtual void SetMaximum( wxInt32 v
) = 0;
230 virtual void PulseGauge() = 0;
231 virtual void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
) = 0;
233 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true ) = 0;
235 // is the clicked event sent AFTER the state already changed, so no additional
236 // state changing logic is required from the outside
237 virtual bool ButtonClickDidStateChange() = 0;
239 // static creation methods, must be implemented by all toolkits
241 static wxWidgetImplType
* CreateUserPane( wxWindowMac
* wxpeer
,
248 static wxWidgetImplType
* CreateContentView( wxNonOwnedWindow
* now
) ;
250 static wxWidgetImplType
* CreateButton( wxWindowMac
* wxpeer
,
253 const wxString
& label
,
259 static wxWidgetImplType
* CreateDisclosureTriangle( wxWindowMac
* wxpeer
,
262 const wxString
& label
,
268 static wxWidgetImplType
* CreateStaticLine( wxWindowMac
* wxpeer
,
276 static wxWidgetImplType
* CreateGroupBox( wxWindowMac
* wxpeer
,
279 const wxString
& label
,
285 static wxWidgetImplType
* CreateStaticText( wxWindowMac
* wxpeer
,
288 const wxString
& label
,
294 static wxWidgetImplType
* CreateTextControl( wxTextCtrl
* wxpeer
,
297 const wxString
& content
,
303 static wxWidgetImplType
* CreateSearchControl( wxTextCtrl
* wxpeer
,
306 const wxString
& content
,
312 static wxWidgetImplType
* CreateCheckBox( wxWindowMac
* wxpeer
,
315 const wxString
& label
,
321 static wxWidgetImplType
* CreateRadioButton( wxWindowMac
* wxpeer
,
324 const wxString
& label
,
330 static wxWidgetImplType
* CreateToggleButton( wxWindowMac
* wxpeer
,
333 const wxString
& label
,
339 static wxWidgetImplType
* CreateBitmapToggleButton( wxWindowMac
* wxpeer
,
342 const wxBitmap
& bitmap
,
348 static wxWidgetImplType
* CreateBitmapButton( wxWindowMac
* wxpeer
,
351 const wxBitmap
& bitmap
,
357 static wxWidgetImplType
* CreateTabView( wxWindowMac
* wxpeer
,
365 static wxWidgetImplType
* CreateGauge( wxWindowMac
* wxpeer
,
376 static wxWidgetImplType
* CreateSlider( wxWindowMac
* wxpeer
,
387 static wxWidgetImplType
* CreateSpinButton( wxWindowMac
* wxpeer
,
398 static wxWidgetImplType
* CreateScrollBar( wxWindowMac
* wxpeer
,
406 static wxWidgetImplType
* CreateChoice( wxWindowMac
* wxpeer
,
415 static wxWidgetImplType
* CreateListBox( wxWindowMac
* wxpeer
,
423 // converts from Toplevel-Content relative to local
424 static void Convert( wxPoint
*pt
, wxWidgetImpl
*from
, wxWidgetImpl
*to
);
426 bool m_isRootControl
;
427 wxWindowMac
* m_wxPeer
;
428 bool m_needsFocusRect
;
430 DECLARE_ABSTRACT_CLASS(wxWidgetImpl
)
434 // the interface to be implemented eg by a listbox
437 class WXDLLIMPEXP_CORE wxListWidgetColumn
440 virtual ~wxListWidgetColumn() {}
443 class WXDLLIMPEXP_CORE wxListWidgetCellValue
446 wxListWidgetCellValue() {}
447 virtual ~wxListWidgetCellValue() {}
449 virtual void Set( CFStringRef value
) = 0;
450 virtual void Set( const wxString
& value
) = 0;
451 virtual void Set( int value
) = 0;
453 virtual int GetIntValue() const = 0;
454 virtual wxString
GetStringValue() const = 0;
457 class WXDLLIMPEXP_CORE wxListWidgetImpl
460 wxListWidgetImpl() {}
461 virtual ~wxListWidgetImpl() { }
463 virtual wxListWidgetColumn
* InsertTextColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
464 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
465 virtual wxListWidgetColumn
* InsertCheckColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
466 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
470 // TODO will be replaced
471 virtual void ListDelete( unsigned int n
) = 0;
472 virtual void ListInsert( unsigned int n
) = 0;
473 virtual void ListClear() = 0;
477 virtual void ListDeselectAll() = 0;
478 virtual void ListSetSelection( unsigned int n
, bool select
, bool multi
) = 0;
479 virtual int ListGetSelection() const = 0;
480 virtual int ListGetSelections( wxArrayInt
& aSelections
) const = 0;
481 virtual bool ListIsSelected( unsigned int n
) const = 0;
485 virtual void ListScrollTo( unsigned int n
) = 0;
486 virtual void UpdateLine( unsigned int n
, wxListWidgetColumn
* col
= NULL
) = 0;
487 virtual void UpdateLineToEnd( unsigned int n
) = 0;
491 virtual unsigned int ListGetCount() const = 0;
495 // interface to be implemented by a textcontrol
498 class WXDLLIMPEXP_FWD_CORE wxTextAttr
;
500 // common interface for all implementations
501 class WXDLLIMPEXP_CORE wxTextWidgetImpl
505 wxTextWidgetImpl() {}
507 virtual ~wxTextWidgetImpl() {}
509 virtual bool CanFocus() const { return true; }
511 virtual wxString
GetStringValue() const = 0 ;
512 virtual void SetStringValue( const wxString
&val
) = 0 ;
513 virtual void SetSelection( long from
, long to
) = 0 ;
514 virtual void GetSelection( long* from
, long* to
) const = 0 ;
515 virtual void WriteText( const wxString
& str
) = 0 ;
517 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
518 virtual void Copy() ;
520 virtual void Paste() ;
521 virtual bool CanPaste() const ;
522 virtual void SetEditable( bool editable
) ;
523 virtual long GetLastPosition() const ;
524 virtual void Replace( long from
, long to
, const wxString
&str
) ;
525 virtual void Remove( long from
, long to
) ;
528 virtual bool HasOwnContextMenu() const
531 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
534 virtual void Clear() ;
535 virtual bool CanUndo() const;
536 virtual void Undo() ;
537 virtual bool CanRedo() const;
538 virtual void Redo() ;
539 virtual int GetNumberOfLines() const ;
540 virtual long XYToPosition(long x
, long y
) const;
541 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
542 virtual void ShowPosition(long WXUNUSED(pos
)) ;
543 virtual int GetLineLength(long lineNo
) const ;
544 virtual wxString
GetLineText(long lineNo
) const ;
545 virtual void CheckSpelling(bool WXUNUSED(check
)) { }
549 // common interface for search controls
552 class wxSearchWidgetImpl
555 wxSearchWidgetImpl(){}
556 virtual ~wxSearchWidgetImpl(){}
558 // search field options
559 virtual void ShowSearchButton( bool show
) = 0;
560 virtual bool IsSearchButtonVisible() const = 0;
562 virtual void ShowCancelButton( bool show
) = 0;
563 virtual bool IsCancelButtonVisible() const = 0;
565 virtual void SetSearchMenu( wxMenu
* menu
) = 0;
567 virtual void SetDescriptiveText(const wxString
& text
) = 0;
571 // toplevel window implementation class
574 class wxNonOwnedWindowImpl
: public wxObject
577 wxNonOwnedWindowImpl( wxNonOwnedWindow
* nonownedwnd
) : m_wxPeer(nonownedwnd
)
580 wxNonOwnedWindowImpl()
583 virtual ~wxNonOwnedWindowImpl()
587 virtual void Destroy()
591 virtual void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
592 long style
, long extraStyle
, const wxString
& name
) = 0;
595 virtual WXWindow
GetWXWindow() const = 0;
605 virtual bool Show(bool WXUNUSED(show
))
610 virtual bool ShowWithEffect(bool show
, wxShowEffect
WXUNUSED(effect
), unsigned WXUNUSED(timeout
))
615 virtual void Update()
619 virtual bool SetTransparent(wxByte
WXUNUSED(alpha
))
624 virtual bool SetBackgroundColour(const wxColour
& WXUNUSED(col
) )
629 virtual void SetExtraStyle( long WXUNUSED(exStyle
) )
633 virtual bool SetBackgroundStyle(wxBackgroundStyle
WXUNUSED(style
))
638 bool CanSetTransparent()
643 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
644 virtual void MoveWindow(int x
, int y
, int width
, int height
) = 0;
645 virtual void GetPosition( int &x
, int &y
) const = 0;
646 virtual void GetSize( int &width
, int &height
) const = 0;
648 virtual bool SetShape(const wxRegion
& WXUNUSED(region
))
653 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) = 0;
655 virtual bool IsMaximized() const = 0;
657 virtual bool IsIconized() const= 0;
659 virtual void Iconize( bool iconize
)= 0;
661 virtual void Maximize(bool maximize
) = 0;
663 virtual bool IsFullScreen() const= 0;
665 virtual bool ShowFullScreen(bool show
, long style
)= 0;
667 virtual void RequestUserAttention(int flags
) = 0;
669 virtual void ScreenToWindow( int *x
, int *y
) = 0;
671 virtual void WindowToScreen( int *x
, int *y
) = 0;
673 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
675 // static creation methods, must be implemented by all toolkits
677 static wxNonOwnedWindowImpl
* CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
678 long style
, long extraStyle
, const wxString
& name
) ;
681 wxNonOwnedWindow
* m_wxPeer
;
682 DECLARE_ABSTRACT_CLASS(wxNonOwnedWindowImpl
)
687 //---------------------------------------------------------------------------
688 // cocoa bridging utilities
689 //---------------------------------------------------------------------------
691 bool wxMacInitCocoa();
693 class WXDLLIMPEXP_CORE wxMacAutoreleasePool
696 wxMacAutoreleasePool();
697 ~wxMacAutoreleasePool();
704 void wxMacCocoaRelease( void* obj
);
705 void wxMacCocoaAutorelease( void* obj
);
706 void wxMacCocoaRetain( void* obj
);
710 // _WX_PRIVATE_CORE_H_