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 bool SetBackgroundStyle(wxBackgroundStyle style
);
96 virtual int GetCharHeight() const;
97 virtual int GetCharWidth() const;
100 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
101 int range
, bool refresh
= true );
102 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= true );
103 virtual int GetScrollPos( int orient
) const;
104 virtual int GetScrollThumb( int orient
) const;
105 virtual int GetScrollRange( int orient
) const;
106 virtual void ScrollWindow( int dx
, int dy
,
107 const wxRect
* rect
= NULL
);
108 virtual void AlwaysShowScrollbars(bool horz
= true, bool vert
= true);
109 virtual bool IsScrollbarAlwaysShown(int orient
) const
111 return orient
== wxHORIZONTAL
? m_hScrollBarAlwaysShown
112 : m_vScrollBarAlwaysShown
;
115 virtual bool Reparent( wxWindowBase
*newParent
);
117 #if wxUSE_DRAG_AND_DROP
118 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
121 // Accept files for dragging
122 virtual void DragAcceptFiles( bool accept
);
124 // implementation from now on
125 // --------------------------
127 void MacClientToRootWindow( int *x
, int *y
) const;
129 void MacWindowToRootWindow( int *x
, int *y
) const;
131 void MacRootWindowToWindow( int *x
, int *y
) const;
133 virtual wxString
MacGetToolTipString( wxPoint
&where
);
138 virtual WXWidget
GetHandle() const;
140 virtual bool SetTransparent(wxByte alpha
);
141 virtual bool CanSetTransparent();
142 virtual wxByte
GetTransparent() const ;
147 void OnMouseEvent( wxMouseEvent
&event
);
149 void MacOnScroll( wxScrollEvent
&event
);
151 virtual bool AcceptsFocus() const;
153 virtual bool IsDoubleBuffered() const { return true; }
156 static long MacRemoveBordersFromStyle( long style
) ;
159 void OnInternalIdle();
161 // For implementation purposes:
162 // sometimes decorations make the client area smaller
163 virtual wxPoint
GetClientAreaOrigin() const;
165 wxWindowMac
*FindItem(long id
) const;
166 wxWindowMac
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= false) const;
168 virtual void TriggerScrollEvent( wxEventType scrollEvent
) ;
169 // this should not be overriden in classes above wxWindowMac
170 // because it is called from its destructor via DeleteChildren
171 virtual void RemoveChild( wxWindowBase
*child
);
173 virtual bool MacDoRedraw( long time
) ;
174 virtual void MacPaintChildrenBorders();
175 virtual void MacPaintBorders( int left
, int top
) ;
176 void MacPaintGrowBox();
178 // invalidates the borders and focus area around the control;
179 // must not be virtual as it will be called during destruction
180 void MacInvalidateBorders() ;
182 WXWindow
MacGetTopLevelWindowRef() const ;
183 wxNonOwnedWindow
* MacGetTopLevelWindow() const ;
185 virtual long MacGetLeftBorderSize() const ;
186 virtual long MacGetRightBorderSize() const ;
187 virtual long MacGetTopBorderSize() const ;
188 virtual long MacGetBottomBorderSize() const ;
190 virtual void MacSuperChangedPosition() ;
192 // absolute coordinates of this window's root have changed
193 virtual void MacTopLevelWindowChangedPosition() ;
195 virtual void MacChildAdded() ;
196 virtual void MacVisibilityChanged() ;
197 virtual void MacEnabledStateChanged() ;
198 virtual void MacHiliteChanged() ;
199 virtual wxInt32
MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF event
) ;
201 bool MacIsReallyEnabled() ;
202 bool MacIsReallyHilited() ;
204 #if WXWIN_COMPATIBILITY_2_8
205 bool MacIsUserPane() { return m_macIsUserPane
; }
207 bool MacIsUserPane() const { return m_macIsUserPane
; }
209 virtual bool MacSetupCursor( const wxPoint
& pt
) ;
211 // return the rectangle that would be visible of this control,
212 // regardless whether controls are hidden
213 // only taking into account clipping by parent windows
214 const wxRect
& MacGetClippedClientRect() const ;
215 const wxRect
& MacGetClippedRect() const ;
216 const wxRect
& MacGetClippedRectWithOuterStructure() const ;
218 // returns the visible region of this control in window ie non-client coordinates
219 const wxRegion
& MacGetVisibleRegion( bool includeOuterStructures
= false ) ;
221 // returns true if children have to clipped to the content area
222 // (e.g., scrolled windows)
223 bool MacClipChildren() const { return m_clipChildren
; }
224 void MacSetClipChildren( bool clip
) { m_clipChildren
= clip
; }
226 // returns true if the grandchildren need to be clipped to the children's content area
227 // (e.g., splitter windows)
228 virtual bool MacClipGrandChildren() const { return false ; }
229 bool MacIsWindowScrollbar( const wxWindow
* sb
) const
230 { return ((wxWindow
*)m_hScrollBar
== sb
|| (wxWindow
*)m_vScrollBar
== sb
) ; }
231 virtual bool IsClientAreaChild(const wxWindow
*child
) const
233 return !MacIsWindowScrollbar(child
) && !((wxWindow
*)m_growBox
==child
) &&
234 wxWindowBase::IsClientAreaChild(child
);
237 void MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
) ;
238 wxList
& GetSubcontrols() { return m_subControls
; }
240 // translate wxWidgets coords into ones suitable
241 // to be passed to CreateControl calls
243 // returns true if non-default coords are returned, false otherwise
244 bool MacGetBoundsForControl(const wxPoint
& pos
,
247 int& w
, int& h
, bool adjustForOrigin
) const ;
249 // the 'true' OS level control for this wxWindow
250 wxOSXWidgetImpl
* GetPeer() const { return m_peer
; }
252 #if wxOSX_USE_COCOA_OR_IPHONE
253 // the NSView or NSWindow of this window: can be used for both child and
256 // this is useful for a few Cocoa function which can work with either views
257 // or windows indiscriminately, e.g. for setting NSViewAnimationTargetKey
258 virtual void *OSXGetViewOrWindow() const { return GetHandle(); }
261 void * MacGetCGContextRef() { return m_cgContextRef
; }
262 void MacSetCGContextRef(void * cg
) { m_cgContextRef
= cg
; }
264 // osx specific event handling common for all osx-ports
266 virtual bool OSXHandleClicked( double timestampsec
);
267 virtual bool OSXHandleKeyEvent( wxKeyEvent
& event
);
269 bool IsNativeWindowWrapper() const { return m_isNativeWindowWrapper
; }
271 // For controls like radio buttons which are genuinely composite
272 wxList m_subControls
;
274 // the peer object, allowing for cleaner API support
275 wxOSXWidgetImpl
* m_peer
;
277 void * m_cgContextRef
;
279 // cache the clipped rectangles within the window hierarchy
280 void MacUpdateClippedRects() const ;
282 mutable bool m_cachedClippedRectValid
;
283 mutable wxRect m_cachedClippedRectWithOuterStructure
;
284 mutable wxRect m_cachedClippedRect
;
285 mutable wxRect m_cachedClippedClientRect
;
286 mutable wxRegion m_cachedClippedRegionWithOuterStructure
;
287 mutable wxRegion m_cachedClippedRegion
;
288 mutable wxRegion m_cachedClippedClientRegion
;
290 // true if is is not a native control but a wxWindow control
291 bool m_macIsUserPane
;
293 // insets of the mac control from the wx top left corner
294 wxPoint m_macTopLeftInset
;
295 wxPoint m_macBottomRightInset
;
298 wxScrollBar
* m_hScrollBar
;
299 wxScrollBar
* m_vScrollBar
;
300 bool m_hScrollBarAlwaysShown
;
301 bool m_vScrollBarAlwaysShown
;
302 wxWindow
* m_growBox
;
305 bool m_isNativeWindowWrapper
;
307 // set to true if we do a sharp clip at the content area of this window
308 // must be dynamic as eg a panel normally is not clipping precisely, but if
309 // it becomes the target window of a scrolled window it has to...
310 bool m_clipChildren
;
312 virtual bool MacIsChildOfClientArea( const wxWindow
* child
) const ;
314 bool MacHasScrollBarCorner() const;
315 void MacCreateScrollBars( long style
) ;
316 void MacRepositionScrollBars() ;
317 void MacUpdateControlFont() ;
319 // implement the base class pure virtuals
320 virtual void DoGetTextExtent(const wxString
& string
,
323 int *externalLeading
= NULL
,
324 const wxFont
*theFont
= NULL
) const;
326 virtual void DoEnable( bool enable
);
328 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
331 virtual void DoFreeze();
332 virtual void DoThaw();
334 virtual wxSize
DoGetBestSize() const;
335 virtual wxSize
DoGetSizeFromClientSize( const wxSize
& size
) const;
336 virtual void DoClientToScreen( int *x
, int *y
) const;
337 virtual void DoScreenToClient( int *x
, int *y
) const;
338 virtual void DoGetPosition( int *x
, int *y
) const;
339 virtual void DoGetSize( int *width
, int *height
) const;
340 virtual void DoGetClientSize( int *width
, int *height
) const;
341 virtual void DoSetSize(int x
, int y
,
342 int width
, int height
,
343 int sizeFlags
= wxSIZE_AUTO
);
344 virtual void DoSetClientSize(int width
, int height
);
346 virtual void DoCaptureMouse();
347 virtual void DoReleaseMouse();
349 // move the window to the specified location and resize it: this is called
350 // from both DoSetSize() and DoSetClientSize() and would usually just call
351 // ::MoveWindow() except for composite controls which will want to arrange
352 // themselves inside the given rectangle
353 virtual void DoMoveWindow( int x
, int y
, int width
, int height
);
354 virtual void DoSetWindowVariant( wxWindowVariant variant
);
357 virtual void DoSetToolTip( wxToolTip
*tip
);
360 // common part of Show/HideWithEffect()
361 virtual bool OSXShowWithEffect(bool show
,
366 // common part of all ctors
369 // show/hide scrollbars as needed, common part of SetScrollbar() and
370 // AlwaysShowScrollbars()
371 void DoUpdateScrollbarVisibility();
373 wxDECLARE_NO_COPY_CLASS(wxWindowMac
);
374 DECLARE_EVENT_TABLE()
377 #endif // _WX_WINDOW_H_