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 #if wxOSX_USE_COCOA_OR_IPHONE
241 // the NSView or NSWindow of this window: can be used for both child and
244 // this is useful for a few Cocoa function which can work with either views
245 // or windows indiscriminately, e.g. for setting NSViewAnimationTargetKey
246 virtual void *OSXGetViewOrWindow() const { return GetHandle(); }
249 void * MacGetCGContextRef() { return m_cgContextRef
; }
250 void MacSetCGContextRef(void * cg
) { m_cgContextRef
= cg
; }
252 // osx specific event handling common for all osx-ports
254 virtual bool OSXHandleClicked( double timestampsec
);
255 virtual bool OSXHandleKeyEvent( wxKeyEvent
& event
);
257 // For controls like radio buttons which are genuinely composite
258 wxList m_subControls
;
260 // the peer object, allowing for cleaner API support
261 wxOSXWidgetImpl
* m_peer
;
263 void * m_cgContextRef
;
265 // cache the clipped rectangles within the window hierarchy
266 void MacUpdateClippedRects() const ;
268 mutable bool m_cachedClippedRectValid
;
269 mutable wxRect m_cachedClippedRectWithOuterStructure
;
270 mutable wxRect m_cachedClippedRect
;
271 mutable wxRect m_cachedClippedClientRect
;
272 mutable wxRegion m_cachedClippedRegionWithOuterStructure
;
273 mutable wxRegion m_cachedClippedRegion
;
274 mutable wxRegion m_cachedClippedClientRegion
;
276 // true if is is not a native control but a wxWindow control
277 bool m_macIsUserPane
;
279 // insets of the mac control from the wx top left corner
280 wxPoint m_macTopLeftInset
;
281 wxPoint m_macBottomRightInset
;
284 wxScrollBar
* m_hScrollBar
;
285 wxScrollBar
* m_vScrollBar
;
286 bool m_hScrollBarAlwaysShown
;
287 bool m_vScrollBarAlwaysShown
;
291 // set to true if we do a sharp clip at the content area of this window
292 // must be dynamic as eg a panel normally is not clipping precisely, but if
293 // it becomes the target window of a scrolled window it has to...
294 bool m_clipChildren
;
296 virtual bool MacIsChildOfClientArea( const wxWindow
* child
) const ;
298 bool MacHasScrollBarCorner() const;
299 void MacCreateScrollBars( long style
) ;
300 void MacRepositionScrollBars() ;
301 void MacUpdateControlFont() ;
303 // implement the base class pure virtuals
304 virtual void DoGetTextExtent(const wxString
& string
,
307 int *externalLeading
= NULL
,
308 const wxFont
*theFont
= NULL
) const;
310 virtual void DoEnable( bool enable
);
312 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
315 virtual void DoFreeze();
316 virtual void DoThaw();
318 virtual wxSize
DoGetBestSize() const;
319 virtual wxSize
DoGetSizeFromClientSize( const wxSize
& size
) const;
320 virtual void DoClientToScreen( int *x
, int *y
) const;
321 virtual void DoScreenToClient( int *x
, int *y
) const;
322 virtual void DoGetPosition( int *x
, int *y
) const;
323 virtual void DoGetSize( int *width
, int *height
) const;
324 virtual void DoGetClientSize( int *width
, int *height
) const;
325 virtual void DoSetSize(int x
, int y
,
326 int width
, int height
,
327 int sizeFlags
= wxSIZE_AUTO
);
328 virtual void DoSetClientSize(int width
, int height
);
330 virtual void DoCaptureMouse();
331 virtual void DoReleaseMouse();
333 // move the window to the specified location and resize it: this is called
334 // from both DoSetSize() and DoSetClientSize() and would usually just call
335 // ::MoveWindow() except for composite controls which will want to arrange
336 // themselves inside the given rectangle
337 virtual void DoMoveWindow( int x
, int y
, int width
, int height
);
338 virtual void DoSetWindowVariant( wxWindowVariant variant
);
341 virtual void DoSetToolTip( wxToolTip
*tip
);
345 // common part of all ctors
348 // show/hide scrollbars as needed, common part of SetScrollbar() and
349 // AlwaysShowScrollbars()
350 void DoUpdateScrollbarVisibility();
353 wxDECLARE_NO_COPY_CLASS(wxWindowMac
);
354 DECLARE_EVENT_TABLE()
357 #endif // _WX_WINDOW_H_