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
;
26 class WXDLLIMPEXP_FWD_CORE wxWidgetCocoaImpl
;
27 typedef wxWidgetCocoaImpl wxOSXWidgetImpl
;
28 #elif wxOSX_USE_IPHONE
29 class WXDLLIMPEXP_FWD_CORE wxWidgetIPhoneImpl
;
30 typedef wxWidgetIPhoneImpl wxOSXWidgetImpl
;
34 class WXDLLIMPEXP_CORE wxWindowMac
: public wxWindowBase
36 DECLARE_DYNAMIC_CLASS(wxWindowMac
)
39 friend class wxPaintDC
;
44 wxWindowMac( wxWindowMac
*parent
,
46 const wxPoint
& pos
= wxDefaultPosition
,
47 const wxSize
& size
= wxDefaultSize
,
49 const wxString
& name
= wxPanelNameStr
);
51 virtual ~wxWindowMac();
53 bool Create( wxWindowMac
*parent
,
55 const wxPoint
& pos
= wxDefaultPosition
,
56 const wxSize
& size
= wxDefaultSize
,
58 const wxString
& name
= wxPanelNameStr
);
60 // implement base class pure virtuals
61 virtual void SetLabel( const wxString
& label
);
62 virtual wxString
GetLabel() const;
67 virtual bool Show( bool show
= true );
69 virtual bool IsShownOnScreen() const;
71 virtual void SetFocus();
73 virtual void WarpPointer( int x
, int y
);
75 virtual void Refresh( bool eraseBackground
= true,
76 const wxRect
*rect
= NULL
);
78 virtual void Update() ;
79 virtual void ClearBackground();
81 virtual bool SetCursor( const wxCursor
&cursor
);
82 virtual bool SetFont( const wxFont
&font
);
83 virtual bool SetBackgroundColour( const wxColour
&colour
);
84 virtual bool SetForegroundColour( const wxColour
&colour
);
86 virtual int GetCharHeight() const;
87 virtual int GetCharWidth() const;
88 virtual void GetTextExtent( const wxString
& string
,
91 int *externalLeading
= NULL
,
92 const wxFont
*theFont
= NULL
)
95 virtual void DoEnable( bool enable
);
97 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
100 virtual void DoFreeze();
101 virtual void DoThaw();
104 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
105 int range
, bool refresh
= true );
106 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= true );
107 virtual int GetScrollPos( int orient
) const;
108 virtual int GetScrollThumb( int orient
) const;
109 virtual int GetScrollRange( int orient
) const;
110 virtual void ScrollWindow( int dx
, int dy
,
111 const wxRect
* rect
= NULL
);
112 virtual void AlwaysShowScrollbars(bool horz
= true, bool vert
= true);
113 virtual bool IsScrollbarAlwaysShown(int orient
) const
115 return orient
== wxHORIZONTAL
? m_hScrollBarAlwaysShown
116 : m_vScrollBarAlwaysShown
;
119 virtual bool Reparent( wxWindowBase
*newParent
);
121 #if wxUSE_DRAG_AND_DROP
122 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
125 // Accept files for dragging
126 virtual void DragAcceptFiles( bool accept
);
128 // implementation from now on
129 // --------------------------
131 void MacClientToRootWindow( int *x
, int *y
) const;
133 void MacWindowToRootWindow( int *x
, int *y
) const;
135 void MacRootWindowToWindow( int *x
, int *y
) const;
137 virtual wxString
MacGetToolTipString( wxPoint
&where
);
142 virtual WXWidget
GetHandle() const;
144 virtual bool SetTransparent(wxByte alpha
);
145 virtual bool CanSetTransparent();
146 virtual wxByte
GetTransparent() const ;
151 void OnNcPaint( wxNcPaintEvent
& event
);
152 void OnEraseBackground(wxEraseEvent
& event
);
153 void OnMouseEvent( wxMouseEvent
&event
);
155 void MacOnScroll( wxScrollEvent
&event
);
157 virtual bool AcceptsFocus() const;
159 virtual bool IsDoubleBuffered() const { return true; }
162 static long MacRemoveBordersFromStyle( long style
) ;
165 void OnInternalIdle();
167 // For implementation purposes:
168 // sometimes decorations make the client area smaller
169 virtual wxPoint
GetClientAreaOrigin() const;
171 wxWindowMac
*FindItem(long id
) const;
172 wxWindowMac
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= false) const;
174 virtual void TriggerScrollEvent( wxEventType scrollEvent
) ;
175 // this should not be overriden in classes above wxWindowMac
176 // because it is called from its destructor via DeleteChildren
177 virtual void RemoveChild( wxWindowBase
*child
);
179 virtual bool MacDoRedraw( long time
) ;
180 virtual void MacPaintChildrenBorders();
181 virtual void MacPaintBorders( int left
, int top
) ;
182 void MacPaintGrowBox();
184 // invalidates the borders and focus area around the control;
185 // must not be virtual as it will be called during destruction
186 void MacInvalidateBorders() ;
188 WXWindow
MacGetTopLevelWindowRef() const ;
189 wxNonOwnedWindow
* MacGetTopLevelWindow() const ;
191 virtual long MacGetLeftBorderSize() const ;
192 virtual long MacGetRightBorderSize() const ;
193 virtual long MacGetTopBorderSize() const ;
194 virtual long MacGetBottomBorderSize() const ;
196 virtual void MacSuperChangedPosition() ;
198 // absolute coordinates of this window's root have changed
199 virtual void MacTopLevelWindowChangedPosition() ;
201 virtual void MacChildAdded() ;
202 virtual void MacVisibilityChanged() ;
203 virtual void MacEnabledStateChanged() ;
204 virtual void MacHiliteChanged() ;
205 virtual wxInt32
MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF event
) ;
207 bool MacIsReallyEnabled() ;
208 bool MacIsReallyHilited() ;
210 #if WXWIN_COMPATIBILITY_2_8
211 bool MacIsUserPane() { return m_macIsUserPane
; }
213 bool MacIsUserPane() const { return m_macIsUserPane
; }
215 virtual bool MacSetupCursor( const wxPoint
& pt
) ;
217 // return the rectangle that would be visible of this control,
218 // regardless whether controls are hidden
219 // only taking into account clipping by parent windows
220 const wxRect
& MacGetClippedClientRect() const ;
221 const wxRect
& MacGetClippedRect() const ;
222 const wxRect
& MacGetClippedRectWithOuterStructure() const ;
224 // returns the visible region of this control in window ie non-client coordinates
225 const wxRegion
& MacGetVisibleRegion( bool includeOuterStructures
= false ) ;
227 // returns true if children have to clipped to the content area
228 // (e.g., scrolled windows)
229 bool MacClipChildren() const { return m_clipChildren
; }
230 void MacSetClipChildren( bool clip
) { m_clipChildren
= clip
; }
232 // returns true if the grandchildren need to be clipped to the children's content area
233 // (e.g., splitter windows)
234 virtual bool MacClipGrandChildren() const { return false ; }
235 bool MacIsWindowScrollbar( const wxWindow
* sb
) const
236 { return ((wxWindow
*)m_hScrollBar
== sb
|| (wxWindow
*)m_vScrollBar
== sb
) ; }
237 virtual bool IsClientAreaChild(const wxWindow
*child
) const
239 return !MacIsWindowScrollbar(child
) &&
240 wxWindowBase::IsClientAreaChild(child
);
243 void MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
) ;
244 wxList
& GetSubcontrols() { return m_subControls
; }
246 // translate wxWidgets coords into ones suitable
247 // to be passed to CreateControl calls
249 // returns true if non-default coords are returned, false otherwise
250 bool MacGetBoundsForControl(const wxPoint
& pos
,
253 int& w
, int& h
, bool adjustForOrigin
) const ;
255 // the 'true' OS level control for this wxWindow
256 wxOSXWidgetImpl
* GetPeer() const { return m_peer
; }
258 void * MacGetCGContextRef() { return m_cgContextRef
; }
259 void MacSetCGContextRef(void * cg
) { m_cgContextRef
= cg
; }
261 // osx specific event handling common for all osx-ports
263 virtual bool OSXHandleClicked( double timestampsec
);
264 virtual bool OSXHandleKeyEvent( wxKeyEvent
& event
);
266 // For controls like radio buttons which are genuinely composite
267 wxList m_subControls
;
269 // the peer object, allowing for cleaner API support
270 wxOSXWidgetImpl
* m_peer
;
272 void * m_cgContextRef
;
274 // cache the clipped rectangles within the window hierarchy
275 void MacUpdateClippedRects() const ;
277 mutable bool m_cachedClippedRectValid
;
278 mutable wxRect m_cachedClippedRectWithOuterStructure
;
279 mutable wxRect m_cachedClippedRect
;
280 mutable wxRect m_cachedClippedClientRect
;
281 mutable wxRegion m_cachedClippedRegionWithOuterStructure
;
282 mutable wxRegion m_cachedClippedRegion
;
283 mutable wxRegion m_cachedClippedClientRegion
;
285 // true if is is not a native control but a wxWindow control
286 bool m_macIsUserPane
;
288 // insets of the mac control from the wx top left corner
289 wxPoint m_macTopLeftInset
;
290 wxPoint m_macBottomRightInset
;
293 wxScrollBar
* m_hScrollBar
;
294 wxScrollBar
* m_vScrollBar
;
295 bool m_hScrollBarAlwaysShown
;
296 bool m_vScrollBarAlwaysShown
;
299 // set to true if we do a sharp clip at the content area of this window
300 // must be dynamic as eg a panel normally is not clipping precisely, but if
301 // it becomes the target window of a scrolled window it has to...
302 bool m_clipChildren
;
304 virtual bool MacIsChildOfClientArea( const wxWindow
* child
) const ;
306 bool MacHasScrollBarCorner() const;
307 void MacCreateScrollBars( long style
) ;
308 void MacRepositionScrollBars() ;
309 void MacUpdateControlFont() ;
311 // implement the base class pure virtuals
312 virtual wxSize
DoGetBestSize() const;
313 virtual wxSize
DoGetSizeFromClientSize( const wxSize
& size
) const;
314 virtual void DoClientToScreen( int *x
, int *y
) const;
315 virtual void DoScreenToClient( int *x
, int *y
) const;
316 virtual void DoGetPosition( int *x
, int *y
) const;
317 virtual void DoGetSize( int *width
, int *height
) const;
318 virtual void DoGetClientSize( int *width
, int *height
) const;
319 virtual void DoSetSize(int x
, int y
,
320 int width
, int height
,
321 int sizeFlags
= wxSIZE_AUTO
);
322 virtual void DoSetClientSize(int width
, int height
);
324 virtual void DoCaptureMouse();
325 virtual void DoReleaseMouse();
327 // move the window to the specified location and resize it: this is called
328 // from both DoSetSize() and DoSetClientSize() and would usually just call
329 // ::MoveWindow() except for composite controls which will want to arrange
330 // themselves inside the given rectangle
331 virtual void DoMoveWindow( int x
, int y
, int width
, int height
);
332 virtual void DoSetWindowVariant( wxWindowVariant variant
);
335 virtual void DoSetToolTip( wxToolTip
*tip
);
339 // common part of all ctors
342 // show/hide scrollbars as needed, common part of SetScrollbar() and
343 // AlwaysShowScrollbars()
344 void DoUpdateScrollbarVisibility();
347 wxDECLARE_NO_COPY_CLASS(wxWindowMac
);
348 DECLARE_EVENT_TABLE()
351 #endif // _WX_WINDOW_H_