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
;
22 class WXDLLIMPEXP_FWD_CORE wxMacControl
;
23 class WXDLLIMPEXP_FWD_CORE wxWidgetImpl
;
25 class WXDLLIMPEXP_CORE wxWindowMac
: public wxWindowBase
27 DECLARE_DYNAMIC_CLASS(wxWindowMac
)
30 friend class wxPaintDC
;
35 wxWindowMac( wxWindowMac
*parent
,
37 const wxPoint
& pos
= wxDefaultPosition
,
38 const wxSize
& size
= wxDefaultSize
,
40 const wxString
& name
= wxPanelNameStr
);
42 virtual ~wxWindowMac();
44 bool Create( wxWindowMac
*parent
,
46 const wxPoint
& pos
= wxDefaultPosition
,
47 const wxSize
& size
= wxDefaultSize
,
49 const wxString
& name
= wxPanelNameStr
);
51 // implement base class pure virtuals
52 virtual void SetLabel( const wxString
& label
);
53 virtual wxString
GetLabel() const;
58 virtual bool Show( bool show
= true );
60 virtual bool IsShownOnScreen() const;
62 virtual void SetFocus();
64 virtual void WarpPointer( int x
, int y
);
66 virtual void Refresh( bool eraseBackground
= true,
67 const wxRect
*rect
= NULL
);
69 virtual void Update() ;
70 virtual void ClearBackground();
72 virtual bool SetCursor( const wxCursor
&cursor
);
73 virtual bool SetFont( const wxFont
&font
);
74 virtual bool SetBackgroundColour( const wxColour
&colour
);
75 virtual bool SetForegroundColour( const wxColour
&colour
);
77 virtual int GetCharHeight() const;
78 virtual int GetCharWidth() const;
79 virtual void GetTextExtent( const wxString
& string
,
82 int *externalLeading
= NULL
,
83 const wxFont
*theFont
= NULL
)
86 virtual void DoEnable( bool enable
);
88 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
91 virtual void DoFreeze();
92 virtual void DoThaw();
95 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
96 int range
, bool refresh
= true );
97 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= true );
98 virtual int GetScrollPos( int orient
) const;
99 virtual int GetScrollThumb( int orient
) const;
100 virtual int GetScrollRange( int orient
) const;
101 virtual void ScrollWindow( int dx
, int dy
,
102 const wxRect
* rect
= NULL
);
103 virtual void AlwaysShowScrollbars(bool horz
= true, bool vert
= true);
104 virtual bool IsScrollbarAlwaysShown(int orient
) const
106 return orient
== wxHORIZONTAL
? m_hScrollBarAlwaysShown
107 : m_vScrollBarAlwaysShown
;
110 virtual bool Reparent( wxWindowBase
*newParent
);
112 #if wxUSE_DRAG_AND_DROP
113 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
116 // Accept files for dragging
117 virtual void DragAcceptFiles( bool accept
);
119 // implementation from now on
120 // --------------------------
122 void MacClientToRootWindow( int *x
, int *y
) const;
124 void MacWindowToRootWindow( int *x
, int *y
) const;
126 void MacRootWindowToWindow( int *x
, int *y
) const;
128 virtual wxString
MacGetToolTipString( wxPoint
&where
);
133 virtual WXWidget
GetHandle() const;
135 virtual bool SetTransparent(wxByte alpha
);
136 virtual bool CanSetTransparent();
137 virtual wxByte
GetTransparent() const ;
142 void OnNcPaint( wxNcPaintEvent
& event
);
143 void OnEraseBackground(wxEraseEvent
& event
);
144 void OnMouseEvent( wxMouseEvent
&event
);
146 void MacOnScroll( wxScrollEvent
&event
);
148 virtual bool AcceptsFocus() const;
150 virtual bool IsDoubleBuffered() const { return true; }
153 static long MacRemoveBordersFromStyle( long style
) ;
156 void OnInternalIdle();
158 // For implementation purposes:
159 // sometimes decorations make the client area smaller
160 virtual wxPoint
GetClientAreaOrigin() const;
162 wxWindowMac
*FindItem(long id
) const;
163 wxWindowMac
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= false) const;
165 virtual void TriggerScrollEvent( wxEventType scrollEvent
) ;
166 // this should not be overriden in classes above wxWindowMac
167 // because it is called from its destructor via DeleteChildren
168 virtual void RemoveChild( wxWindowBase
*child
);
170 virtual bool MacDoRedraw( long time
) ;
171 virtual void MacPaintChildrenBorders();
172 virtual void MacPaintBorders( int left
, int top
) ;
173 void MacPaintGrowBox();
175 // invalidates the borders and focus area around the control;
176 // must not be virtual as it will be called during destruction
177 void MacInvalidateBorders() ;
179 WXWindow
MacGetTopLevelWindowRef() const ;
180 wxNonOwnedWindow
* MacGetTopLevelWindow() const ;
182 virtual long MacGetLeftBorderSize() const ;
183 virtual long MacGetRightBorderSize() const ;
184 virtual long MacGetTopBorderSize() const ;
185 virtual long MacGetBottomBorderSize() const ;
187 virtual void MacSuperChangedPosition() ;
189 // absolute coordinates of this window's root have changed
190 virtual void MacTopLevelWindowChangedPosition() ;
192 virtual void MacChildAdded() ;
193 virtual void MacVisibilityChanged() ;
194 virtual void MacEnabledStateChanged() ;
195 virtual void MacHiliteChanged() ;
196 virtual wxInt32
MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF event
) ;
198 bool MacIsReallyEnabled() ;
199 bool MacIsReallyHilited() ;
201 bool MacIsUserPane() { return m_macIsUserPane
; }
203 virtual bool MacSetupCursor( const wxPoint
& pt
) ;
205 // return the rectangle that would be visible of this control,
206 // regardless whether controls are hidden
207 // only taking into account clipping by parent windows
208 const wxRect
& MacGetClippedClientRect() const ;
209 const wxRect
& MacGetClippedRect() const ;
210 const wxRect
& MacGetClippedRectWithOuterStructure() const ;
212 // returns the visible region of this control in window ie non-client coordinates
213 const wxRegion
& MacGetVisibleRegion( bool includeOuterStructures
= false ) ;
215 // returns true if children have to clipped to the content area
216 // (e.g., scrolled windows)
217 bool MacClipChildren() const { return m_clipChildren
; }
218 void MacSetClipChildren( bool clip
) { m_clipChildren
= clip
; }
220 // returns true if the grandchildren need to be clipped to the children's content area
221 // (e.g., splitter windows)
222 virtual bool MacClipGrandChildren() const { return false ; }
223 bool MacIsWindowScrollbar( const wxWindow
* sb
) const
224 { return ((wxWindow
*)m_hScrollBar
== sb
|| (wxWindow
*)m_vScrollBar
== sb
) ; }
225 virtual bool IsClientAreaChild(const wxWindow
*child
) const
227 return !MacIsWindowScrollbar(child
) &&
228 wxWindowBase::IsClientAreaChild(child
);
231 void MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
) ;
232 wxList
& GetSubcontrols() { return m_subControls
; }
234 // translate wxWidgets coords into ones suitable
235 // to be passed to CreateControl calls
237 // returns true if non-default coords are returned, false otherwise
238 bool MacGetBoundsForControl(const wxPoint
& pos
,
241 int& w
, int& h
, bool adjustForOrigin
) const ;
243 // the 'true' OS level control for this wxWindow
245 wxMacControl
* GetPeer() const { return m_peer
; }
247 wxWidgetImpl
* GetPeer() const { return m_peer
; }
250 void * MacGetCGContextRef() { return m_cgContextRef
; }
251 void MacSetCGContextRef(void * cg
) { m_cgContextRef
= cg
; }
253 // osx specific event handling common for all osx-ports
255 virtual bool OSXHandleClicked( double timestampsec
);
256 virtual bool OSXHandleKeyEvent( wxKeyEvent
& event
);
258 // For controls like radio buttons which are genuinely composite
259 wxList m_subControls
;
262 // the peer object, allowing for cleaner API support
263 wxMacControl
* m_peer
;
265 wxWidgetImpl
* m_peer
;
267 void * m_cgContextRef
;
269 // cache the clipped rectangles within the window hierarchy
270 void MacUpdateClippedRects() const ;
272 mutable bool m_cachedClippedRectValid
;
273 mutable wxRect m_cachedClippedRectWithOuterStructure
;
274 mutable wxRect m_cachedClippedRect
;
275 mutable wxRect m_cachedClippedClientRect
;
276 mutable wxRegion m_cachedClippedRegionWithOuterStructure
;
277 mutable wxRegion m_cachedClippedRegion
;
278 mutable wxRegion m_cachedClippedClientRegion
;
280 // true if is is not a native control but a wxWindow control
281 bool m_macIsUserPane
;
283 // insets of the mac control from the wx top left corner
284 wxPoint m_macTopLeftInset
;
285 wxPoint m_macBottomRightInset
;
288 wxScrollBar
* m_hScrollBar
;
289 wxScrollBar
* m_vScrollBar
;
290 bool m_hScrollBarAlwaysShown
;
291 bool m_vScrollBarAlwaysShown
;
294 // set to true if we do a sharp clip at the content area of this window
295 // must be dynamic as eg a panel normally is not clipping precisely, but if
296 // it becomes the target window of a scrolled window it has to...
297 bool m_clipChildren
;
299 virtual bool MacIsChildOfClientArea( const wxWindow
* child
) const ;
301 bool MacHasScrollBarCorner() const;
302 void MacCreateScrollBars( long style
) ;
303 void MacRepositionScrollBars() ;
304 void MacUpdateControlFont() ;
306 // implement the base class pure virtuals
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_