1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/mac/carbon/window.h
3 // Purpose: wxWindowMac class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
18 class WXDLLIMPEXP_FWD_CORE wxButton
;
19 class WXDLLIMPEXP_FWD_CORE wxScrollBar
;
20 class WXDLLIMPEXP_FWD_CORE wxNonOwnedWindow
;
23 class WXDLLIMPEXP_FWD_CORE wxMacControl
;
24 typedef wxMacControl wxOSXWidgetImpl
;
25 #elif wxOSX_USE_COCOA_OR_IPHONE
26 class WXDLLIMPEXP_FWD_CORE wxWidgetImpl
;
27 typedef wxWidgetImpl wxOSXWidgetImpl
;
31 class WXDLLIMPEXP_CORE wxWindowMac
: public wxWindowBase
33 DECLARE_DYNAMIC_CLASS(wxWindowMac
)
36 friend class wxPaintDC
;
41 wxWindowMac( wxWindowMac
*parent
,
43 const wxPoint
& pos
= wxDefaultPosition
,
44 const wxSize
& size
= wxDefaultSize
,
46 const wxString
& name
= wxPanelNameStr
);
48 virtual ~wxWindowMac();
50 bool Create( wxWindowMac
*parent
,
52 const wxPoint
& pos
= wxDefaultPosition
,
53 const wxSize
& size
= wxDefaultSize
,
55 const wxString
& name
= wxPanelNameStr
);
57 // implement base class pure virtuals
58 virtual void SetLabel( const wxString
& label
);
59 virtual wxString
GetLabel() const;
64 virtual bool Show( bool show
= true );
66 virtual bool IsShownOnScreen() const;
68 virtual void SetFocus();
70 virtual void WarpPointer( int x
, int y
);
72 virtual void Refresh( bool eraseBackground
= true,
73 const wxRect
*rect
= NULL
);
75 virtual void Update() ;
76 virtual void ClearBackground();
78 virtual bool SetCursor( const wxCursor
&cursor
);
79 virtual bool SetFont( const wxFont
&font
);
80 virtual bool SetBackgroundColour( const wxColour
&colour
);
81 virtual bool SetForegroundColour( const wxColour
&colour
);
83 virtual int GetCharHeight() const;
84 virtual int GetCharWidth() const;
87 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
88 int range
, bool refresh
= true );
89 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= true );
90 virtual int GetScrollPos( int orient
) const;
91 virtual int GetScrollThumb( int orient
) const;
92 virtual int GetScrollRange( int orient
) const;
93 virtual void ScrollWindow( int dx
, int dy
,
94 const wxRect
* rect
= NULL
);
95 virtual void AlwaysShowScrollbars(bool horz
= true, bool vert
= true);
96 virtual bool IsScrollbarAlwaysShown(int orient
) const
98 return orient
== wxHORIZONTAL
? m_hScrollBarAlwaysShown
99 : m_vScrollBarAlwaysShown
;
102 virtual bool Reparent( wxWindowBase
*newParent
);
104 #if wxUSE_DRAG_AND_DROP
105 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
108 // Accept files for dragging
109 virtual void DragAcceptFiles( bool accept
);
111 // implementation from now on
112 // --------------------------
114 void MacClientToRootWindow( int *x
, int *y
) const;
116 void MacWindowToRootWindow( int *x
, int *y
) const;
118 void MacRootWindowToWindow( int *x
, int *y
) const;
120 virtual wxString
MacGetToolTipString( wxPoint
&where
);
125 virtual WXWidget
GetHandle() const;
127 virtual bool SetTransparent(wxByte alpha
);
128 virtual bool CanSetTransparent();
129 virtual wxByte
GetTransparent() const ;
134 void OnMouseEvent( wxMouseEvent
&event
);
136 void MacOnScroll( wxScrollEvent
&event
);
138 virtual bool AcceptsFocus() const;
140 virtual bool IsDoubleBuffered() const { return true; }
143 static long MacRemoveBordersFromStyle( long style
) ;
146 void OnInternalIdle();
148 // For implementation purposes:
149 // sometimes decorations make the client area smaller
150 virtual wxPoint
GetClientAreaOrigin() const;
152 wxWindowMac
*FindItem(long id
) const;
153 wxWindowMac
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= false) const;
155 virtual void TriggerScrollEvent( wxEventType scrollEvent
) ;
156 // this should not be overriden in classes above wxWindowMac
157 // because it is called from its destructor via DeleteChildren
158 virtual void RemoveChild( wxWindowBase
*child
);
160 virtual bool MacDoRedraw( long time
) ;
161 virtual void MacPaintChildrenBorders();
162 virtual void MacPaintBorders( int left
, int top
) ;
163 void MacPaintGrowBox();
165 // invalidates the borders and focus area around the control;
166 // must not be virtual as it will be called during destruction
167 void MacInvalidateBorders() ;
169 WXWindow
MacGetTopLevelWindowRef() const ;
170 wxNonOwnedWindow
* MacGetTopLevelWindow() const ;
172 virtual long MacGetLeftBorderSize() const ;
173 virtual long MacGetRightBorderSize() const ;
174 virtual long MacGetTopBorderSize() const ;
175 virtual long MacGetBottomBorderSize() const ;
177 virtual void MacSuperChangedPosition() ;
179 // absolute coordinates of this window's root have changed
180 virtual void MacTopLevelWindowChangedPosition() ;
182 virtual void MacChildAdded() ;
183 virtual void MacVisibilityChanged() ;
184 virtual void MacEnabledStateChanged() ;
185 virtual void MacHiliteChanged() ;
186 virtual wxInt32
MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF event
) ;
188 bool MacIsReallyEnabled() ;
189 bool MacIsReallyHilited() ;
191 #if WXWIN_COMPATIBILITY_2_8
192 bool MacIsUserPane() { return m_macIsUserPane
; }
194 bool MacIsUserPane() const { return m_macIsUserPane
; }
196 virtual bool MacSetupCursor( const wxPoint
& pt
) ;
198 // return the rectangle that would be visible of this control,
199 // regardless whether controls are hidden
200 // only taking into account clipping by parent windows
201 const wxRect
& MacGetClippedClientRect() const ;
202 const wxRect
& MacGetClippedRect() const ;
203 const wxRect
& MacGetClippedRectWithOuterStructure() const ;
205 // returns the visible region of this control in window ie non-client coordinates
206 const wxRegion
& MacGetVisibleRegion( bool includeOuterStructures
= false ) ;
208 // returns true if children have to clipped to the content area
209 // (e.g., scrolled windows)
210 bool MacClipChildren() const { return m_clipChildren
; }
211 void MacSetClipChildren( bool clip
) { m_clipChildren
= clip
; }
213 // returns true if the grandchildren need to be clipped to the children's content area
214 // (e.g., splitter windows)
215 virtual bool MacClipGrandChildren() const { return false ; }
216 bool MacIsWindowScrollbar( const wxWindow
* sb
) const
217 { return ((wxWindow
*)m_hScrollBar
== sb
|| (wxWindow
*)m_vScrollBar
== sb
) ; }
218 virtual bool IsClientAreaChild(const wxWindow
*child
) const
220 return !MacIsWindowScrollbar(child
) &&
221 wxWindowBase::IsClientAreaChild(child
);
224 void MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
) ;
225 wxList
& GetSubcontrols() { return m_subControls
; }
227 // translate wxWidgets coords into ones suitable
228 // to be passed to CreateControl calls
230 // returns true if non-default coords are returned, false otherwise
231 bool MacGetBoundsForControl(const wxPoint
& pos
,
234 int& w
, int& h
, bool adjustForOrigin
) const ;
236 // the 'true' OS level control for this wxWindow
237 wxOSXWidgetImpl
* GetPeer() const { return m_peer
; }
239 void * MacGetCGContextRef() { return m_cgContextRef
; }
240 void MacSetCGContextRef(void * cg
) { m_cgContextRef
= cg
; }
242 // osx specific event handling common for all osx-ports
244 virtual bool OSXHandleClicked( double timestampsec
);
245 virtual bool OSXHandleKeyEvent( wxKeyEvent
& event
);
247 // For controls like radio buttons which are genuinely composite
248 wxList m_subControls
;
250 // the peer object, allowing for cleaner API support
251 wxOSXWidgetImpl
* m_peer
;
253 void * m_cgContextRef
;
255 // cache the clipped rectangles within the window hierarchy
256 void MacUpdateClippedRects() const ;
258 mutable bool m_cachedClippedRectValid
;
259 mutable wxRect m_cachedClippedRectWithOuterStructure
;
260 mutable wxRect m_cachedClippedRect
;
261 mutable wxRect m_cachedClippedClientRect
;
262 mutable wxRegion m_cachedClippedRegionWithOuterStructure
;
263 mutable wxRegion m_cachedClippedRegion
;
264 mutable wxRegion m_cachedClippedClientRegion
;
266 // true if is is not a native control but a wxWindow control
267 bool m_macIsUserPane
;
269 // insets of the mac control from the wx top left corner
270 wxPoint m_macTopLeftInset
;
271 wxPoint m_macBottomRightInset
;
274 wxScrollBar
* m_hScrollBar
;
275 wxScrollBar
* m_vScrollBar
;
276 bool m_hScrollBarAlwaysShown
;
277 bool m_vScrollBarAlwaysShown
;
280 // set to true if we do a sharp clip at the content area of this window
281 // must be dynamic as eg a panel normally is not clipping precisely, but if
282 // it becomes the target window of a scrolled window it has to...
283 bool m_clipChildren
;
285 virtual bool MacIsChildOfClientArea( const wxWindow
* child
) const ;
287 bool MacHasScrollBarCorner() const;
288 void MacCreateScrollBars( long style
) ;
289 void MacRepositionScrollBars() ;
290 void MacUpdateControlFont() ;
292 // implement the base class pure virtuals
293 virtual void DoGetTextExtent(const wxString
& string
,
296 int *externalLeading
= NULL
,
297 const wxFont
*theFont
= NULL
) const;
299 virtual void DoEnable( bool enable
);
301 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
304 virtual void DoFreeze();
305 virtual void DoThaw();
307 virtual wxSize
DoGetBestSize() const;
308 virtual wxSize
DoGetSizeFromClientSize( const wxSize
& size
) const;
309 virtual void DoClientToScreen( int *x
, int *y
) const;
310 virtual void DoScreenToClient( int *x
, int *y
) const;
311 virtual void DoGetPosition( int *x
, int *y
) const;
312 virtual void DoGetSize( int *width
, int *height
) const;
313 virtual void DoGetClientSize( int *width
, int *height
) const;
314 virtual void DoSetSize(int x
, int y
,
315 int width
, int height
,
316 int sizeFlags
= wxSIZE_AUTO
);
317 virtual void DoSetClientSize(int width
, int height
);
319 virtual void DoCaptureMouse();
320 virtual void DoReleaseMouse();
322 // move the window to the specified location and resize it: this is called
323 // from both DoSetSize() and DoSetClientSize() and would usually just call
324 // ::MoveWindow() except for composite controls which will want to arrange
325 // themselves inside the given rectangle
326 virtual void DoMoveWindow( int x
, int y
, int width
, int height
);
327 virtual void DoSetWindowVariant( wxWindowVariant variant
);
330 virtual void DoSetToolTip( wxToolTip
*tip
);
334 // common part of all ctors
337 // show/hide scrollbars as needed, common part of SetScrollbar() and
338 // AlwaysShowScrollbars()
339 void DoUpdateScrollbarVisibility();
342 wxDECLARE_NO_COPY_CLASS(wxWindowMac
);
343 DECLARE_EVENT_TABLE()
346 #endif // _WX_WINDOW_H_