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 );
66 virtual bool ShowWithEffect(wxShowEffect effect
,
69 return OSXShowWithEffect(true, effect
, timeout
);
71 virtual bool HideWithEffect(wxShowEffect effect
,
74 return OSXShowWithEffect(false, effect
, timeout
);
77 virtual bool IsShownOnScreen() const;
79 virtual void SetFocus();
81 virtual void WarpPointer( int x
, int y
);
83 virtual void Refresh( bool eraseBackground
= true,
84 const wxRect
*rect
= NULL
);
86 virtual void Update() ;
87 virtual void ClearBackground();
89 virtual bool SetCursor( const wxCursor
&cursor
);
90 virtual bool SetFont( const wxFont
&font
);
91 virtual bool SetBackgroundColour( const wxColour
&colour
);
92 virtual bool SetForegroundColour( const wxColour
&colour
);
94 virtual int GetCharHeight() const;
95 virtual int GetCharWidth() const;
98 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
99 int range
, bool refresh
= true );
100 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= true );
101 virtual int GetScrollPos( int orient
) const;
102 virtual int GetScrollThumb( int orient
) const;
103 virtual int GetScrollRange( int orient
) const;
104 virtual void ScrollWindow( int dx
, int dy
,
105 const wxRect
* rect
= NULL
);
106 virtual void AlwaysShowScrollbars(bool horz
= true, bool vert
= true);
107 virtual bool IsScrollbarAlwaysShown(int orient
) const
109 return orient
== wxHORIZONTAL
? m_hScrollBarAlwaysShown
110 : m_vScrollBarAlwaysShown
;
113 virtual bool Reparent( wxWindowBase
*newParent
);
115 #if wxUSE_DRAG_AND_DROP
116 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
119 // Accept files for dragging
120 virtual void DragAcceptFiles( bool accept
);
122 // implementation from now on
123 // --------------------------
125 void MacClientToRootWindow( int *x
, int *y
) const;
127 void MacWindowToRootWindow( int *x
, int *y
) const;
129 void MacRootWindowToWindow( int *x
, int *y
) const;
131 virtual wxString
MacGetToolTipString( wxPoint
&where
);
136 virtual WXWidget
GetHandle() const;
138 virtual bool SetTransparent(wxByte alpha
);
139 virtual bool CanSetTransparent();
140 virtual wxByte
GetTransparent() const ;
145 void OnMouseEvent( wxMouseEvent
&event
);
147 void MacOnScroll( wxScrollEvent
&event
);
149 virtual bool AcceptsFocus() const;
151 virtual bool IsDoubleBuffered() const { return true; }
154 static long MacRemoveBordersFromStyle( long style
) ;
157 void OnInternalIdle();
159 // For implementation purposes:
160 // sometimes decorations make the client area smaller
161 virtual wxPoint
GetClientAreaOrigin() const;
163 wxWindowMac
*FindItem(long id
) const;
164 wxWindowMac
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= false) const;
166 virtual void TriggerScrollEvent( wxEventType scrollEvent
) ;
167 // this should not be overriden in classes above wxWindowMac
168 // because it is called from its destructor via DeleteChildren
169 virtual void RemoveChild( wxWindowBase
*child
);
171 virtual bool MacDoRedraw( long time
) ;
172 virtual void MacPaintChildrenBorders();
173 virtual void MacPaintBorders( int left
, int top
) ;
174 void MacPaintGrowBox();
176 // invalidates the borders and focus area around the control;
177 // must not be virtual as it will be called during destruction
178 void MacInvalidateBorders() ;
180 WXWindow
MacGetTopLevelWindowRef() const ;
181 wxNonOwnedWindow
* MacGetTopLevelWindow() const ;
183 virtual long MacGetLeftBorderSize() const ;
184 virtual long MacGetRightBorderSize() const ;
185 virtual long MacGetTopBorderSize() const ;
186 virtual long MacGetBottomBorderSize() const ;
188 virtual void MacSuperChangedPosition() ;
190 // absolute coordinates of this window's root have changed
191 virtual void MacTopLevelWindowChangedPosition() ;
193 virtual void MacChildAdded() ;
194 virtual void MacVisibilityChanged() ;
195 virtual void MacEnabledStateChanged() ;
196 virtual void MacHiliteChanged() ;
197 virtual wxInt32
MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF event
) ;
199 bool MacIsReallyEnabled() ;
200 bool MacIsReallyHilited() ;
202 #if WXWIN_COMPATIBILITY_2_8
203 bool MacIsUserPane() { return m_macIsUserPane
; }
205 bool MacIsUserPane() const { return m_macIsUserPane
; }
207 virtual bool MacSetupCursor( const wxPoint
& pt
) ;
209 // return the rectangle that would be visible of this control,
210 // regardless whether controls are hidden
211 // only taking into account clipping by parent windows
212 const wxRect
& MacGetClippedClientRect() const ;
213 const wxRect
& MacGetClippedRect() const ;
214 const wxRect
& MacGetClippedRectWithOuterStructure() const ;
216 // returns the visible region of this control in window ie non-client coordinates
217 const wxRegion
& MacGetVisibleRegion( bool includeOuterStructures
= false ) ;
219 // returns true if children have to clipped to the content area
220 // (e.g., scrolled windows)
221 bool MacClipChildren() const { return m_clipChildren
; }
222 void MacSetClipChildren( bool clip
) { m_clipChildren
= clip
; }
224 // returns true if the grandchildren need to be clipped to the children's content area
225 // (e.g., splitter windows)
226 virtual bool MacClipGrandChildren() const { return false ; }
227 bool MacIsWindowScrollbar( const wxWindow
* sb
) const
228 { return ((wxWindow
*)m_hScrollBar
== sb
|| (wxWindow
*)m_vScrollBar
== sb
) ; }
229 virtual bool IsClientAreaChild(const wxWindow
*child
) const
231 return !MacIsWindowScrollbar(child
) &&
232 wxWindowBase::IsClientAreaChild(child
);
235 void MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
) ;
236 wxList
& GetSubcontrols() { return m_subControls
; }
238 // translate wxWidgets coords into ones suitable
239 // to be passed to CreateControl calls
241 // returns true if non-default coords are returned, false otherwise
242 bool MacGetBoundsForControl(const wxPoint
& pos
,
245 int& w
, int& h
, bool adjustForOrigin
) const ;
247 // the 'true' OS level control for this wxWindow
248 wxOSXWidgetImpl
* GetPeer() const { return m_peer
; }
250 #if wxOSX_USE_COCOA_OR_IPHONE
251 // the NSView or NSWindow of this window: can be used for both child and
254 // this is useful for a few Cocoa function which can work with either views
255 // or windows indiscriminately, e.g. for setting NSViewAnimationTargetKey
256 virtual void *OSXGetViewOrWindow() const { return GetHandle(); }
259 void * MacGetCGContextRef() { return m_cgContextRef
; }
260 void MacSetCGContextRef(void * cg
) { m_cgContextRef
= cg
; }
262 // osx specific event handling common for all osx-ports
264 virtual bool OSXHandleClicked( double timestampsec
);
265 virtual bool OSXHandleKeyEvent( wxKeyEvent
& event
);
267 // For controls like radio buttons which are genuinely composite
268 wxList m_subControls
;
270 // the peer object, allowing for cleaner API support
271 wxOSXWidgetImpl
* m_peer
;
273 void * m_cgContextRef
;
275 // cache the clipped rectangles within the window hierarchy
276 void MacUpdateClippedRects() const ;
278 mutable bool m_cachedClippedRectValid
;
279 mutable wxRect m_cachedClippedRectWithOuterStructure
;
280 mutable wxRect m_cachedClippedRect
;
281 mutable wxRect m_cachedClippedClientRect
;
282 mutable wxRegion m_cachedClippedRegionWithOuterStructure
;
283 mutable wxRegion m_cachedClippedRegion
;
284 mutable wxRegion m_cachedClippedClientRegion
;
286 // true if is is not a native control but a wxWindow control
287 bool m_macIsUserPane
;
289 // insets of the mac control from the wx top left corner
290 wxPoint m_macTopLeftInset
;
291 wxPoint m_macBottomRightInset
;
294 wxScrollBar
* m_hScrollBar
;
295 wxScrollBar
* m_vScrollBar
;
296 bool m_hScrollBarAlwaysShown
;
297 bool m_vScrollBarAlwaysShown
;
301 // set to true if we do a sharp clip at the content area of this window
302 // must be dynamic as eg a panel normally is not clipping precisely, but if
303 // it becomes the target window of a scrolled window it has to...
304 bool m_clipChildren
;
306 virtual bool MacIsChildOfClientArea( const wxWindow
* child
) const ;
308 bool MacHasScrollBarCorner() const;
309 void MacCreateScrollBars( long style
) ;
310 void MacRepositionScrollBars() ;
311 void MacUpdateControlFont() ;
313 // implement the base class pure virtuals
314 virtual void DoGetTextExtent(const wxString
& string
,
317 int *externalLeading
= NULL
,
318 const wxFont
*theFont
= NULL
) const;
320 virtual void DoEnable( bool enable
);
322 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
325 virtual void DoFreeze();
326 virtual void DoThaw();
328 virtual wxSize
DoGetBestSize() const;
329 virtual wxSize
DoGetSizeFromClientSize( const wxSize
& size
) const;
330 virtual void DoClientToScreen( int *x
, int *y
) const;
331 virtual void DoScreenToClient( int *x
, int *y
) const;
332 virtual void DoGetPosition( int *x
, int *y
) const;
333 virtual void DoGetSize( int *width
, int *height
) const;
334 virtual void DoGetClientSize( int *width
, int *height
) const;
335 virtual void DoSetSize(int x
, int y
,
336 int width
, int height
,
337 int sizeFlags
= wxSIZE_AUTO
);
338 virtual void DoSetClientSize(int width
, int height
);
340 virtual void DoCaptureMouse();
341 virtual void DoReleaseMouse();
343 // move the window to the specified location and resize it: this is called
344 // from both DoSetSize() and DoSetClientSize() and would usually just call
345 // ::MoveWindow() except for composite controls which will want to arrange
346 // themselves inside the given rectangle
347 virtual void DoMoveWindow( int x
, int y
, int width
, int height
);
348 virtual void DoSetWindowVariant( wxWindowVariant variant
);
351 virtual void DoSetToolTip( wxToolTip
*tip
);
354 // common part of Show/HideWithEffect()
355 virtual bool OSXShowWithEffect(bool show
,
360 // common part of all ctors
363 // show/hide scrollbars as needed, common part of SetScrollbar() and
364 // AlwaysShowScrollbars()
365 void DoUpdateScrollbarVisibility();
367 wxDECLARE_NO_COPY_CLASS(wxWindowMac
);
368 DECLARE_EVENT_TABLE()
371 #endif // _WX_WINDOW_H_