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 wxPanel
;
21 class WXDLLIMPEXP_FWD_CORE wxNonOwnedWindow
;
24 class WXDLLIMPEXP_FWD_CORE wxMacControl
;
25 typedef wxMacControl wxOSXWidgetImpl
;
26 #elif wxOSX_USE_COCOA_OR_IPHONE
27 class WXDLLIMPEXP_FWD_CORE wxWidgetImpl
;
28 typedef wxWidgetImpl wxOSXWidgetImpl
;
32 class WXDLLIMPEXP_CORE wxWindowMac
: public wxWindowBase
34 DECLARE_DYNAMIC_CLASS(wxWindowMac
)
37 friend class wxPaintDC
;
42 wxWindowMac( wxWindowMac
*parent
,
44 const wxPoint
& pos
= wxDefaultPosition
,
45 const wxSize
& size
= wxDefaultSize
,
47 const wxString
& name
= wxPanelNameStr
);
49 virtual ~wxWindowMac();
51 bool Create( wxWindowMac
*parent
,
53 const wxPoint
& pos
= wxDefaultPosition
,
54 const wxSize
& size
= wxDefaultSize
,
56 const wxString
& name
= wxPanelNameStr
);
58 // implement base class pure virtuals
59 virtual void SetLabel( const wxString
& label
);
60 virtual wxString
GetLabel() const;
65 virtual bool Show( bool show
= true );
67 virtual bool IsShownOnScreen() const;
69 virtual void SetFocus();
71 virtual void WarpPointer( int x
, int y
);
73 virtual void Refresh( bool eraseBackground
= true,
74 const wxRect
*rect
= NULL
);
76 virtual void Update() ;
77 virtual void ClearBackground();
79 virtual bool SetCursor( const wxCursor
&cursor
);
80 virtual bool SetFont( const wxFont
&font
);
81 virtual bool SetBackgroundColour( const wxColour
&colour
);
82 virtual bool SetForegroundColour( const wxColour
&colour
);
84 virtual int GetCharHeight() const;
85 virtual int GetCharWidth() const;
88 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
89 int range
, bool refresh
= true );
90 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= true );
91 virtual int GetScrollPos( int orient
) const;
92 virtual int GetScrollThumb( int orient
) const;
93 virtual int GetScrollRange( int orient
) const;
94 virtual void ScrollWindow( int dx
, int dy
,
95 const wxRect
* rect
= NULL
);
96 virtual void AlwaysShowScrollbars(bool horz
= true, bool vert
= true);
97 virtual bool IsScrollbarAlwaysShown(int orient
) const
99 return orient
== wxHORIZONTAL
? m_hScrollBarAlwaysShown
100 : m_vScrollBarAlwaysShown
;
103 virtual bool Reparent( wxWindowBase
*newParent
);
105 #if wxUSE_DRAG_AND_DROP
106 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
109 // Accept files for dragging
110 virtual void DragAcceptFiles( bool accept
);
112 // implementation from now on
113 // --------------------------
115 void MacClientToRootWindow( int *x
, int *y
) const;
117 void MacWindowToRootWindow( int *x
, int *y
) const;
119 void MacRootWindowToWindow( int *x
, int *y
) const;
121 virtual wxString
MacGetToolTipString( wxPoint
&where
);
126 virtual WXWidget
GetHandle() const;
128 virtual bool SetTransparent(wxByte alpha
);
129 virtual bool CanSetTransparent();
130 virtual wxByte
GetTransparent() const ;
135 void OnMouseEvent( wxMouseEvent
&event
);
137 void MacOnScroll( wxScrollEvent
&event
);
139 virtual bool AcceptsFocus() const;
141 virtual bool IsDoubleBuffered() const { return true; }
144 static long MacRemoveBordersFromStyle( long style
) ;
147 void OnInternalIdle();
149 // For implementation purposes:
150 // sometimes decorations make the client area smaller
151 virtual wxPoint
GetClientAreaOrigin() const;
153 wxWindowMac
*FindItem(long id
) const;
154 wxWindowMac
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= false) const;
156 virtual void TriggerScrollEvent( wxEventType scrollEvent
) ;
157 // this should not be overriden in classes above wxWindowMac
158 // because it is called from its destructor via DeleteChildren
159 virtual void RemoveChild( wxWindowBase
*child
);
161 virtual bool MacDoRedraw( long time
) ;
162 virtual void MacPaintChildrenBorders();
163 virtual void MacPaintBorders( int left
, int top
) ;
164 void MacPaintGrowBox();
166 // invalidates the borders and focus area around the control;
167 // must not be virtual as it will be called during destruction
168 void MacInvalidateBorders() ;
170 WXWindow
MacGetTopLevelWindowRef() const ;
171 wxNonOwnedWindow
* MacGetTopLevelWindow() const ;
173 virtual long MacGetLeftBorderSize() const ;
174 virtual long MacGetRightBorderSize() const ;
175 virtual long MacGetTopBorderSize() const ;
176 virtual long MacGetBottomBorderSize() const ;
178 virtual void MacSuperChangedPosition() ;
180 // absolute coordinates of this window's root have changed
181 virtual void MacTopLevelWindowChangedPosition() ;
183 virtual void MacChildAdded() ;
184 virtual void MacVisibilityChanged() ;
185 virtual void MacEnabledStateChanged() ;
186 virtual void MacHiliteChanged() ;
187 virtual wxInt32
MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF event
) ;
189 bool MacIsReallyEnabled() ;
190 bool MacIsReallyHilited() ;
192 #if WXWIN_COMPATIBILITY_2_8
193 bool MacIsUserPane() { return m_macIsUserPane
; }
195 bool MacIsUserPane() const { return m_macIsUserPane
; }
197 virtual bool MacSetupCursor( const wxPoint
& pt
) ;
199 // return the rectangle that would be visible of this control,
200 // regardless whether controls are hidden
201 // only taking into account clipping by parent windows
202 const wxRect
& MacGetClippedClientRect() const ;
203 const wxRect
& MacGetClippedRect() const ;
204 const wxRect
& MacGetClippedRectWithOuterStructure() const ;
206 // returns the visible region of this control in window ie non-client coordinates
207 const wxRegion
& MacGetVisibleRegion( bool includeOuterStructures
= false ) ;
209 // returns true if children have to clipped to the content area
210 // (e.g., scrolled windows)
211 bool MacClipChildren() const { return m_clipChildren
; }
212 void MacSetClipChildren( bool clip
) { m_clipChildren
= clip
; }
214 // returns true if the grandchildren need to be clipped to the children's content area
215 // (e.g., splitter windows)
216 virtual bool MacClipGrandChildren() const { return false ; }
217 bool MacIsWindowScrollbar( const wxWindow
* sb
) const
218 { return ((wxWindow
*)m_hScrollBar
== sb
|| (wxWindow
*)m_vScrollBar
== sb
) ; }
219 virtual bool IsClientAreaChild(const wxWindow
*child
) const
221 return !MacIsWindowScrollbar(child
) &&
222 wxWindowBase::IsClientAreaChild(child
);
225 void MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
) ;
226 wxList
& GetSubcontrols() { return m_subControls
; }
228 // translate wxWidgets coords into ones suitable
229 // to be passed to CreateControl calls
231 // returns true if non-default coords are returned, false otherwise
232 bool MacGetBoundsForControl(const wxPoint
& pos
,
235 int& w
, int& h
, bool adjustForOrigin
) const ;
237 // the 'true' OS level control for this wxWindow
238 wxOSXWidgetImpl
* GetPeer() const { return m_peer
; }
240 void * MacGetCGContextRef() { return m_cgContextRef
; }
241 void MacSetCGContextRef(void * cg
) { m_cgContextRef
= cg
; }
243 // osx specific event handling common for all osx-ports
245 virtual bool OSXHandleClicked( double timestampsec
);
246 virtual bool OSXHandleKeyEvent( wxKeyEvent
& event
);
248 // For controls like radio buttons which are genuinely composite
249 wxList m_subControls
;
251 // the peer object, allowing for cleaner API support
252 wxOSXWidgetImpl
* m_peer
;
254 void * m_cgContextRef
;
256 // cache the clipped rectangles within the window hierarchy
257 void MacUpdateClippedRects() const ;
259 mutable bool m_cachedClippedRectValid
;
260 mutable wxRect m_cachedClippedRectWithOuterStructure
;
261 mutable wxRect m_cachedClippedRect
;
262 mutable wxRect m_cachedClippedClientRect
;
263 mutable wxRegion m_cachedClippedRegionWithOuterStructure
;
264 mutable wxRegion m_cachedClippedRegion
;
265 mutable wxRegion m_cachedClippedClientRegion
;
267 // true if is is not a native control but a wxWindow control
268 bool m_macIsUserPane
;
270 // insets of the mac control from the wx top left corner
271 wxPoint m_macTopLeftInset
;
272 wxPoint m_macBottomRightInset
;
275 wxScrollBar
* m_hScrollBar
;
276 wxScrollBar
* m_vScrollBar
;
277 bool m_hScrollBarAlwaysShown
;
278 bool m_vScrollBarAlwaysShown
;
282 // set to true if we do a sharp clip at the content area of this window
283 // must be dynamic as eg a panel normally is not clipping precisely, but if
284 // it becomes the target window of a scrolled window it has to...
285 bool m_clipChildren
;
287 virtual bool MacIsChildOfClientArea( const wxWindow
* child
) const ;
289 bool MacHasScrollBarCorner() const;
290 void MacCreateScrollBars( long style
) ;
291 void MacRepositionScrollBars() ;
292 void MacUpdateControlFont() ;
294 // implement the base class pure virtuals
295 virtual void DoGetTextExtent(const wxString
& string
,
298 int *externalLeading
= NULL
,
299 const wxFont
*theFont
= NULL
) const;
301 virtual void DoEnable( bool enable
);
303 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
306 virtual void DoFreeze();
307 virtual void DoThaw();
309 virtual wxSize
DoGetBestSize() const;
310 virtual wxSize
DoGetSizeFromClientSize( const wxSize
& size
) const;
311 virtual void DoClientToScreen( int *x
, int *y
) const;
312 virtual void DoScreenToClient( int *x
, int *y
) const;
313 virtual void DoGetPosition( int *x
, int *y
) const;
314 virtual void DoGetSize( int *width
, int *height
) const;
315 virtual void DoGetClientSize( int *width
, int *height
) const;
316 virtual void DoSetSize(int x
, int y
,
317 int width
, int height
,
318 int sizeFlags
= wxSIZE_AUTO
);
319 virtual void DoSetClientSize(int width
, int height
);
321 virtual void DoCaptureMouse();
322 virtual void DoReleaseMouse();
324 // move the window to the specified location and resize it: this is called
325 // from both DoSetSize() and DoSetClientSize() and would usually just call
326 // ::MoveWindow() except for composite controls which will want to arrange
327 // themselves inside the given rectangle
328 virtual void DoMoveWindow( int x
, int y
, int width
, int height
);
329 virtual void DoSetWindowVariant( wxWindowVariant variant
);
332 virtual void DoSetToolTip( wxToolTip
*tip
);
336 // common part of all ctors
339 // show/hide scrollbars as needed, common part of SetScrollbar() and
340 // AlwaysShowScrollbars()
341 void DoUpdateScrollbarVisibility();
344 wxDECLARE_NO_COPY_CLASS(wxWindowMac
);
345 DECLARE_EVENT_TABLE()
348 #endif // _WX_WINDOW_H_