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 bool ShowWithEffect(bool WXUNUSED(show
),
192 wxShowEffect
WXUNUSED(effect
),
193 unsigned WXUNUSED(timeout
))
198 virtual void Raise() = 0;
200 virtual void Lower() = 0;
202 virtual void ScrollRect( const wxRect
*rect
, int dx
, int dy
) = 0;
204 virtual WXWidget
GetWXWidget() const = 0;
206 virtual void SetBackgroundColour( const wxColour
& col
) = 0;
208 // all coordinates in native parent widget relative coordinates
209 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
210 virtual void Move(int x
, int y
, int width
, int height
) = 0;
211 virtual void GetPosition( int &x
, int &y
) const = 0;
212 virtual void GetSize( int &width
, int &height
) const = 0;
213 virtual void SetControlSize( wxWindowVariant variant
) = 0;
215 // native view coordinates are topleft to bottom right (flipped regarding CoreGraphics origin)
216 virtual bool IsFlipped() const { return true; }
218 virtual void SetNeedsDisplay( const wxRect
* where
= NULL
) = 0;
219 virtual bool GetNeedsDisplay() const = 0;
221 virtual bool NeedsFocusRect() const;
222 virtual void SetNeedsFocusRect( bool needs
);
224 virtual bool NeedsFrame() const;
225 virtual void SetNeedsFrame( bool needs
);
227 virtual bool CanFocus() const = 0;
228 // return true if successful
229 virtual bool SetFocus() = 0;
230 virtual bool HasFocus() const = 0;
232 virtual void RemoveFromParent() = 0;
233 virtual void Embed( wxWidgetImpl
*parent
) = 0;
235 virtual void SetDefaultButton( bool isDefault
) = 0;
236 virtual void PerformClick() = 0;
237 virtual void SetLabel( const wxString
& title
, wxFontEncoding encoding
) = 0;
239 virtual void SetCursor( const wxCursor
& cursor
) = 0;
240 virtual void CaptureMouse() = 0;
241 virtual void ReleaseMouse() = 0;
243 virtual wxInt32
GetValue() const = 0;
244 virtual void SetValue( wxInt32 v
) = 0;
245 virtual wxBitmap
GetBitmap() const = 0;
246 virtual void SetBitmap( const wxBitmap
& bitmap
) = 0;
247 virtual void SetBitmapPosition( wxDirection dir
) = 0;
248 virtual void SetupTabs( const wxNotebook
¬ebook
) =0;
249 virtual void GetBestRect( wxRect
*r
) const = 0;
250 virtual bool IsEnabled() const = 0;
251 virtual void Enable( bool enable
) = 0;
252 virtual void SetMinimum( wxInt32 v
) = 0;
253 virtual void SetMaximum( wxInt32 v
) = 0;
254 virtual wxInt32
GetMinimum() const = 0;
255 virtual wxInt32
GetMaximum() const = 0;
256 virtual void PulseGauge() = 0;
257 virtual void SetScrollThumb( wxInt32 value
, wxInt32 thumbSize
) = 0;
259 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
, bool ignoreBlack
= true ) = 0;
261 // is the clicked event sent AFTER the state already changed, so no additional
262 // state changing logic is required from the outside
263 virtual bool ButtonClickDidStateChange() = 0;
265 virtual void InstallEventHandler( WXWidget control
= NULL
) = 0;
267 // static methods for associating native controls and their implementations
270 FindFromWXWidget(WXWidget control
);
272 static void RemoveAssociations( wxWidgetImpl
* impl
);
274 static void Associate( WXWidget control
, wxWidgetImpl
*impl
);
276 static WXWidget
FindFocus();
278 // static creation methods, must be implemented by all toolkits
280 static wxWidgetImplType
* CreateUserPane( wxWindowMac
* wxpeer
,
287 static wxWidgetImplType
* CreateContentView( wxNonOwnedWindow
* now
) ;
289 static wxWidgetImplType
* CreateButton( wxWindowMac
* wxpeer
,
292 const wxString
& label
,
298 static wxWidgetImplType
* CreateDisclosureTriangle( wxWindowMac
* wxpeer
,
301 const wxString
& label
,
307 static wxWidgetImplType
* CreateStaticLine( wxWindowMac
* wxpeer
,
315 static wxWidgetImplType
* CreateGroupBox( wxWindowMac
* wxpeer
,
318 const wxString
& label
,
324 static wxWidgetImplType
* CreateStaticText( wxWindowMac
* wxpeer
,
327 const wxString
& label
,
333 static wxWidgetImplType
* CreateTextControl( wxTextCtrl
* wxpeer
,
336 const wxString
& content
,
342 static wxWidgetImplType
* CreateSearchControl( wxTextCtrl
* wxpeer
,
345 const wxString
& content
,
351 static wxWidgetImplType
* CreateCheckBox( wxWindowMac
* wxpeer
,
354 const wxString
& label
,
360 static wxWidgetImplType
* CreateRadioButton( wxWindowMac
* wxpeer
,
363 const wxString
& label
,
369 static wxWidgetImplType
* CreateToggleButton( wxWindowMac
* wxpeer
,
372 const wxString
& label
,
378 static wxWidgetImplType
* CreateBitmapToggleButton( wxWindowMac
* wxpeer
,
381 const wxBitmap
& bitmap
,
387 static wxWidgetImplType
* CreateBitmapButton( wxWindowMac
* wxpeer
,
390 const wxBitmap
& bitmap
,
396 static wxWidgetImplType
* CreateTabView( wxWindowMac
* wxpeer
,
404 static wxWidgetImplType
* CreateGauge( wxWindowMac
* wxpeer
,
415 static wxWidgetImplType
* CreateSlider( wxWindowMac
* wxpeer
,
426 static wxWidgetImplType
* CreateSpinButton( wxWindowMac
* wxpeer
,
437 static wxWidgetImplType
* CreateScrollBar( wxWindowMac
* wxpeer
,
445 static wxWidgetImplType
* CreateChoice( wxWindowMac
* wxpeer
,
454 static wxWidgetImplType
* CreateListBox( wxWindowMac
* wxpeer
,
462 // converts from Toplevel-Content relative to local
463 static void Convert( wxPoint
*pt
, wxWidgetImpl
*from
, wxWidgetImpl
*to
);
465 bool m_isRootControl
;
466 wxWindowMac
* m_wxPeer
;
467 bool m_needsFocusRect
;
470 DECLARE_ABSTRACT_CLASS(wxWidgetImpl
)
474 // the interface to be implemented eg by a listbox
477 class WXDLLIMPEXP_CORE wxListWidgetColumn
480 virtual ~wxListWidgetColumn() {}
483 class WXDLLIMPEXP_CORE wxListWidgetCellValue
486 wxListWidgetCellValue() {}
487 virtual ~wxListWidgetCellValue() {}
489 virtual void Set( CFStringRef value
) = 0;
490 virtual void Set( const wxString
& value
) = 0;
491 virtual void Set( int value
) = 0;
492 virtual void Check( bool check
);
494 virtual bool IsChecked() const;
495 virtual int GetIntValue() const = 0;
496 virtual wxString
GetStringValue() const = 0;
499 class WXDLLIMPEXP_CORE wxListWidgetImpl
502 wxListWidgetImpl() {}
503 virtual ~wxListWidgetImpl() { }
505 virtual wxListWidgetColumn
* InsertTextColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
506 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
507 virtual wxListWidgetColumn
* InsertCheckColumn( unsigned pos
, const wxString
& title
, bool editable
= false,
508 wxAlignment just
= wxALIGN_LEFT
, int defaultWidth
= -1) = 0 ;
512 // TODO will be replaced
513 virtual void ListDelete( unsigned int n
) = 0;
514 virtual void ListInsert( unsigned int n
) = 0;
515 virtual void ListClear() = 0;
519 virtual void ListDeselectAll() = 0;
520 virtual void ListSetSelection( unsigned int n
, bool select
, bool multi
) = 0;
521 virtual int ListGetSelection() const = 0;
522 virtual int ListGetSelections( wxArrayInt
& aSelections
) const = 0;
523 virtual bool ListIsSelected( unsigned int n
) const = 0;
527 virtual void ListScrollTo( unsigned int n
) = 0;
528 virtual void UpdateLine( unsigned int n
, wxListWidgetColumn
* col
= NULL
) = 0;
529 virtual void UpdateLineToEnd( unsigned int n
) = 0;
533 virtual unsigned int ListGetCount() const = 0;
537 // interface to be implemented by a textcontrol
540 class WXDLLIMPEXP_FWD_CORE wxTextAttr
;
542 // common interface for all implementations
543 class WXDLLIMPEXP_CORE wxTextWidgetImpl
547 wxTextWidgetImpl() {}
549 virtual ~wxTextWidgetImpl() {}
551 virtual bool CanFocus() const { return true; }
553 virtual wxString
GetStringValue() const = 0 ;
554 virtual void SetStringValue( const wxString
&val
) = 0 ;
555 virtual void SetSelection( long from
, long to
) = 0 ;
556 virtual void GetSelection( long* from
, long* to
) const = 0 ;
557 virtual void WriteText( const wxString
& str
) = 0 ;
559 virtual bool GetStyle( long position
, wxTextAttr
& style
);
560 virtual void SetStyle( long start
, long end
, const wxTextAttr
& style
) ;
561 virtual void Copy() ;
563 virtual void Paste() ;
564 virtual bool CanPaste() const ;
565 virtual void SetEditable( bool editable
) ;
566 virtual long GetLastPosition() const ;
567 virtual void Replace( long from
, long to
, const wxString
&str
) ;
568 virtual void Remove( long from
, long to
) ;
571 virtual bool HasOwnContextMenu() const
574 virtual bool SetupCursor( const wxPoint
& WXUNUSED(pt
) )
577 virtual void Clear() ;
578 virtual bool CanUndo() const;
579 virtual void Undo() ;
580 virtual bool CanRedo() const;
581 virtual void Redo() ;
582 virtual int GetNumberOfLines() const ;
583 virtual long XYToPosition(long x
, long y
) const;
584 virtual bool PositionToXY(long pos
, long *x
, long *y
) const ;
585 virtual void ShowPosition(long WXUNUSED(pos
)) ;
586 virtual int GetLineLength(long lineNo
) const ;
587 virtual wxString
GetLineText(long lineNo
) const ;
588 virtual void CheckSpelling(bool WXUNUSED(check
)) { }
592 // common interface for buttons
599 virtual ~wxButtonImpl(){}
601 virtual void SetPressedBitmap( const wxBitmap
& bitmap
) = 0;
605 // common interface for search controls
608 class wxSearchWidgetImpl
611 wxSearchWidgetImpl(){}
612 virtual ~wxSearchWidgetImpl(){}
614 // search field options
615 virtual void ShowSearchButton( bool show
) = 0;
616 virtual bool IsSearchButtonVisible() const = 0;
618 virtual void ShowCancelButton( bool show
) = 0;
619 virtual bool IsCancelButtonVisible() const = 0;
621 virtual void SetSearchMenu( wxMenu
* menu
) = 0;
623 virtual void SetDescriptiveText(const wxString
& text
) = 0;
627 // toplevel window implementation class
630 class wxNonOwnedWindowImpl
: public wxObject
633 wxNonOwnedWindowImpl( wxNonOwnedWindow
* nonownedwnd
) : m_wxPeer(nonownedwnd
)
636 wxNonOwnedWindowImpl()
639 virtual ~wxNonOwnedWindowImpl()
643 virtual void Destroy()
647 virtual void Create( wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
648 long style
, long extraStyle
, const wxString
& name
) = 0;
651 virtual WXWindow
GetWXWindow() const = 0;
661 virtual bool Show(bool WXUNUSED(show
))
666 virtual bool ShowWithEffect(bool show
, wxShowEffect
WXUNUSED(effect
), unsigned WXUNUSED(timeout
))
671 virtual void Update()
675 virtual bool SetTransparent(wxByte
WXUNUSED(alpha
))
680 virtual bool SetBackgroundColour(const wxColour
& WXUNUSED(col
) )
685 virtual void SetExtraStyle( long WXUNUSED(exStyle
) )
689 virtual void SetWindowStyleFlag( long WXUNUSED(style
) )
693 virtual bool SetBackgroundStyle(wxBackgroundStyle
WXUNUSED(style
))
698 bool CanSetTransparent()
703 virtual void GetContentArea( int &left
, int &top
, int &width
, int &height
) const = 0;
704 virtual void MoveWindow(int x
, int y
, int width
, int height
) = 0;
705 virtual void GetPosition( int &x
, int &y
) const = 0;
706 virtual void GetSize( int &width
, int &height
) const = 0;
708 virtual bool SetShape(const wxRegion
& WXUNUSED(region
))
713 virtual void SetTitle( const wxString
& title
, wxFontEncoding encoding
) = 0;
715 virtual bool IsMaximized() const = 0;
717 virtual bool IsIconized() const= 0;
719 virtual void Iconize( bool iconize
)= 0;
721 virtual void Maximize(bool maximize
) = 0;
723 virtual bool IsFullScreen() const= 0;
725 virtual void ShowWithoutActivating() { Show(true); }
727 virtual bool ShowFullScreen(bool show
, long style
)= 0;
729 virtual void RequestUserAttention(int flags
) = 0;
731 virtual void ScreenToWindow( int *x
, int *y
) = 0;
733 virtual void WindowToScreen( int *x
, int *y
) = 0;
735 virtual bool IsActive() = 0;
737 wxNonOwnedWindow
* GetWXPeer() { return m_wxPeer
; }
739 // static creation methods, must be implemented by all toolkits
741 static wxNonOwnedWindowImpl
* CreateNonOwnedWindow( wxNonOwnedWindow
* wxpeer
, wxWindow
* parent
, const wxPoint
& pos
, const wxSize
& size
,
742 long style
, long extraStyle
, const wxString
& name
) ;
745 wxNonOwnedWindow
* m_wxPeer
;
746 DECLARE_ABSTRACT_CLASS(wxNonOwnedWindowImpl
)
751 //---------------------------------------------------------------------------
752 // cocoa bridging utilities
753 //---------------------------------------------------------------------------
755 bool wxMacInitCocoa();
757 class WXDLLIMPEXP_CORE wxMacAutoreleasePool
760 wxMacAutoreleasePool();
761 ~wxMacAutoreleasePool();
768 void wxMacCocoaRelease( void* obj
);
769 void wxMacCocoaAutorelease( void* obj
);
770 void* wxMacCocoaRetain( void* obj
);
774 // _WX_PRIVATE_CORE_H_