1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/osx/window.h
3 // Purpose: wxWindowMac class
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
17 class WXDLLIMPEXP_FWD_CORE wxButton
;
18 class WXDLLIMPEXP_FWD_CORE wxScrollBar
;
19 class WXDLLIMPEXP_FWD_CORE wxPanel
;
20 class WXDLLIMPEXP_FWD_CORE wxNonOwnedWindow
;
23 class WXDLLIMPEXP_FWD_CORE wxMacControl
;
24 typedef wxMacControl wxOSXWidgetImpl
;
25 #elif wxOSX_USE_COCOA_OR_IPHONE
26 class WXDLLIMPEXP_FWD_CORE wxWidgetImpl
;
27 typedef wxWidgetImpl wxOSXWidgetImpl
;
31 class WXDLLIMPEXP_CORE wxWindowMac
: public wxWindowBase
33 DECLARE_DYNAMIC_CLASS(wxWindowMac
)
36 friend class wxPaintDC
;
41 wxWindowMac( wxWindowMac
*parent
,
43 const wxPoint
& pos
= wxDefaultPosition
,
44 const wxSize
& size
= wxDefaultSize
,
46 const wxString
& name
= wxPanelNameStr
);
48 virtual ~wxWindowMac();
50 bool Create( wxWindowMac
*parent
,
52 const wxPoint
& pos
= wxDefaultPosition
,
53 const wxSize
& size
= wxDefaultSize
,
55 const wxString
& name
= wxPanelNameStr
);
57 virtual void SendSizeEvent(int flags
= 0);
59 // implement base class pure virtuals
60 virtual void SetLabel( const wxString
& label
);
61 virtual wxString
GetLabel() const;
66 virtual bool Show( bool show
= true );
67 virtual bool ShowWithEffect(wxShowEffect effect
,
70 return OSXShowWithEffect(true, effect
, timeout
);
72 virtual bool HideWithEffect(wxShowEffect effect
,
75 return OSXShowWithEffect(false, effect
, timeout
);
78 virtual bool IsShownOnScreen() const;
80 virtual void SetFocus();
82 virtual void WarpPointer( int x
, int y
);
84 virtual void Refresh( bool eraseBackground
= true,
85 const wxRect
*rect
= NULL
);
87 virtual void Update() ;
88 virtual void ClearBackground();
90 virtual bool SetCursor( const wxCursor
&cursor
);
91 virtual bool SetFont( const wxFont
&font
);
92 virtual bool SetBackgroundColour( const wxColour
&colour
);
93 virtual bool SetForegroundColour( const wxColour
&colour
);
95 virtual bool SetBackgroundStyle(wxBackgroundStyle style
);
97 virtual int GetCharHeight() const;
98 virtual int GetCharWidth() const;
101 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
102 int range
, bool refresh
= true );
103 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= true );
104 virtual int GetScrollPos( int orient
) const;
105 virtual int GetScrollThumb( int orient
) const;
106 virtual int GetScrollRange( int orient
) const;
107 virtual void ScrollWindow( int dx
, int dy
,
108 const wxRect
* rect
= NULL
);
109 virtual void AlwaysShowScrollbars(bool horz
= true, bool vert
= true);
110 virtual bool IsScrollbarAlwaysShown(int orient
) const
112 return orient
== wxHORIZONTAL
? m_hScrollBarAlwaysShown
113 : m_vScrollBarAlwaysShown
;
116 virtual bool Reparent( wxWindowBase
*newParent
);
118 #if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
119 // hot keys (system wide accelerators)
120 // -----------------------------------
122 virtual bool RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
);
123 virtual bool UnregisterHotKey(int hotkeyId
);
124 #endif // wxUSE_HOTKEY
126 #if wxUSE_DRAG_AND_DROP
127 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
130 // Accept files for dragging
131 virtual void DragAcceptFiles( bool accept
);
133 // implementation from now on
134 // --------------------------
136 void MacClientToRootWindow( int *x
, int *y
) const;
138 void MacWindowToRootWindow( int *x
, int *y
) const;
140 void MacRootWindowToWindow( int *x
, int *y
) const;
142 virtual wxString
MacGetToolTipString( wxPoint
&where
);
147 virtual WXWidget
GetHandle() const;
149 virtual bool SetTransparent(wxByte alpha
);
150 virtual bool CanSetTransparent();
151 virtual wxByte
GetTransparent() const ;
156 void OnMouseEvent( wxMouseEvent
&event
);
158 void MacOnScroll( wxScrollEvent
&event
);
160 virtual bool AcceptsFocus() const;
162 virtual bool IsDoubleBuffered() const { return true; }
165 static long MacRemoveBordersFromStyle( long style
) ;
168 // For implementation purposes:
169 // sometimes decorations make the client area smaller
170 virtual wxPoint
GetClientAreaOrigin() const;
172 wxWindowMac
*FindItem(long id
) const;
173 wxWindowMac
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= false) const;
175 virtual void TriggerScrollEvent( wxEventType scrollEvent
) ;
176 // this should not be overridden in classes above wxWindowMac
177 // because it is called from its destructor via DeleteChildren
178 virtual void RemoveChild( wxWindowBase
*child
);
180 virtual bool MacDoRedraw( long time
) ;
181 virtual void MacPaintChildrenBorders();
182 virtual void MacPaintBorders( int left
, int top
) ;
183 void MacPaintGrowBox();
185 // invalidates the borders and focus area around the control;
186 // must not be virtual as it will be called during destruction
187 void MacInvalidateBorders() ;
189 WXWindow
MacGetTopLevelWindowRef() const ;
190 wxNonOwnedWindow
* MacGetTopLevelWindow() const ;
192 virtual long MacGetWXBorderSize() const;
193 virtual long MacGetLeftBorderSize() const ;
194 virtual long MacGetRightBorderSize() const ;
195 virtual long MacGetTopBorderSize() const ;
196 virtual long MacGetBottomBorderSize() const ;
198 virtual void MacSuperChangedPosition() ;
200 // absolute coordinates of this window's root have changed
201 virtual void MacTopLevelWindowChangedPosition() ;
203 virtual void MacChildAdded() ;
204 virtual void MacVisibilityChanged() ;
205 virtual void MacEnabledStateChanged() ;
206 virtual void MacHiliteChanged() ;
207 virtual wxInt32
MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF event
) ;
209 bool MacIsReallyEnabled() ;
210 bool MacIsReallyHilited() ;
212 #if WXWIN_COMPATIBILITY_2_8
213 bool MacIsUserPane();
215 bool MacIsUserPane() const;
217 virtual bool MacSetupCursor( const wxPoint
& pt
) ;
219 // return the rectangle that would be visible of this control,
220 // regardless whether controls are hidden
221 // only taking into account clipping by parent windows
222 const wxRect
& MacGetClippedClientRect() const ;
223 const wxRect
& MacGetClippedRect() const ;
224 const wxRect
& MacGetClippedRectWithOuterStructure() const ;
226 // returns the visible region of this control in window ie non-client coordinates
227 const wxRegion
& MacGetVisibleRegion( bool includeOuterStructures
= false ) ;
229 // returns true if children have to clipped to the content area
230 // (e.g., scrolled windows)
231 bool MacClipChildren() const { return m_clipChildren
; }
232 void MacSetClipChildren( bool clip
) { m_clipChildren
= clip
; }
234 // returns true if the grandchildren need to be clipped to the children's content area
235 // (e.g., splitter windows)
236 virtual bool MacClipGrandChildren() const { return false ; }
237 bool MacIsWindowScrollbar( const wxWindow
* sb
) const
238 { return ((wxWindow
*)m_hScrollBar
== sb
|| (wxWindow
*)m_vScrollBar
== sb
) ; }
239 virtual bool IsClientAreaChild(const wxWindow
*child
) const
241 return !MacIsWindowScrollbar(child
) && !((wxWindow
*)m_growBox
==child
) &&
242 wxWindowBase::IsClientAreaChild(child
);
245 void MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
) ;
246 wxList
& GetSubcontrols() { return m_subControls
; }
248 // translate wxWidgets coords into ones suitable
249 // to be passed to CreateControl calls
251 // returns true if non-default coords are returned, false otherwise
252 bool MacGetBoundsForControl(const wxPoint
& pos
,
255 int& w
, int& h
, bool adjustForOrigin
) const ;
257 // the 'true' OS level control for this wxWindow
258 wxOSXWidgetImpl
* GetPeer() const;
260 // optimization to avoid creating a user pane in wxWindow::Create if we already know
261 // we will replace it with our own peer
262 void DontCreatePeer();
264 // return true unless DontCreatePeer() had been called
265 bool ShouldCreatePeer() const;
267 // sets the native implementation wrapper, can replace an existing peer, use peer = NULL to
268 // release existing peer
269 void SetPeer(wxOSXWidgetImpl
* peer
);
271 // wraps the already existing peer with the wrapper
272 void SetWrappingPeer(wxOSXWidgetImpl
* wrapper
);
274 #if wxOSX_USE_COCOA_OR_IPHONE
275 // the NSView or NSWindow of this window: can be used for both child and
278 // this is useful for a few Cocoa function which can work with either views
279 // or windows indiscriminately, e.g. for setting NSViewAnimationTargetKey
280 virtual void *OSXGetViewOrWindow() const;
283 void * MacGetCGContextRef() { return m_cgContextRef
; }
284 void MacSetCGContextRef(void * cg
) { m_cgContextRef
= cg
; }
286 // osx specific event handling common for all osx-ports
288 virtual bool OSXHandleClicked( double timestampsec
);
289 virtual bool OSXHandleKeyEvent( wxKeyEvent
& event
);
290 virtual void OSXSimulateFocusEvents();
292 bool IsNativeWindowWrapper() const { return m_isNativeWindowWrapper
; }
294 double GetContentScaleFactor() const ;
296 // internal response to size events
297 virtual void MacOnInternalSize() {}
300 // For controls like radio buttons which are genuinely composite
301 wxList m_subControls
;
303 // the peer object, allowing for cleaner API support
305 void * m_cgContextRef
;
307 // cache the clipped rectangles within the window hierarchy
308 void MacUpdateClippedRects() const ;
310 mutable bool m_cachedClippedRectValid
;
311 mutable wxRect m_cachedClippedRectWithOuterStructure
;
312 mutable wxRect m_cachedClippedRect
;
313 mutable wxRect m_cachedClippedClientRect
;
314 mutable wxRegion m_cachedClippedRegionWithOuterStructure
;
315 mutable wxRegion m_cachedClippedRegion
;
316 mutable wxRegion m_cachedClippedClientRegion
;
318 // insets of the mac control from the wx top left corner
319 wxPoint m_macTopLeftInset
;
320 wxPoint m_macBottomRightInset
;
323 wxScrollBar
* m_hScrollBar
;
324 wxScrollBar
* m_vScrollBar
;
325 bool m_hScrollBarAlwaysShown
;
326 bool m_vScrollBarAlwaysShown
;
327 wxWindow
* m_growBox
;
330 bool m_isNativeWindowWrapper
;
332 // set to true if we do a sharp clip at the content area of this window
333 // must be dynamic as eg a panel normally is not clipping precisely, but if
334 // it becomes the target window of a scrolled window it has to...
335 bool m_clipChildren
;
337 virtual bool MacIsChildOfClientArea( const wxWindow
* child
) const ;
339 bool MacHasScrollBarCorner() const;
340 void MacCreateScrollBars( long style
) ;
341 void MacRepositionScrollBars() ;
342 void MacUpdateControlFont() ;
344 // implement the base class pure virtuals
345 virtual void DoGetTextExtent(const wxString
& string
,
348 int *externalLeading
= NULL
,
349 const wxFont
*theFont
= NULL
) const;
351 virtual void DoEnable( bool enable
);
353 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
356 virtual void DoFreeze();
357 virtual void DoThaw();
359 virtual wxSize
DoGetBestSize() const;
360 virtual wxSize
DoGetSizeFromClientSize( const wxSize
& size
) const;
361 virtual void DoClientToScreen( int *x
, int *y
) const;
362 virtual void DoScreenToClient( int *x
, int *y
) const;
363 virtual void DoGetPosition( int *x
, int *y
) const;
364 virtual void DoGetSize( int *width
, int *height
) const;
365 virtual void DoGetClientSize( int *width
, int *height
) const;
366 virtual void DoSetSize(int x
, int y
,
367 int width
, int height
,
368 int sizeFlags
= wxSIZE_AUTO
);
369 virtual void DoSetClientSize(int width
, int height
);
371 virtual void DoCaptureMouse();
372 virtual void DoReleaseMouse();
374 // move the window to the specified location and resize it: this is called
375 // from both DoSetSize() and DoSetClientSize() and would usually just call
376 // ::MoveWindow() except for composite controls which will want to arrange
377 // themselves inside the given rectangle
378 virtual void DoMoveWindow( int x
, int y
, int width
, int height
);
379 virtual void DoSetWindowVariant( wxWindowVariant variant
);
382 virtual void DoSetToolTip( wxToolTip
*tip
);
385 // common part of Show/HideWithEffect()
386 virtual bool OSXShowWithEffect(bool show
,
391 wxOSXWidgetImpl
* m_peer
;
392 // common part of all ctors
395 // show/hide scrollbars as needed, common part of SetScrollbar() and
396 // AlwaysShowScrollbars()
397 void DoUpdateScrollbarVisibility();
399 wxDECLARE_NO_COPY_CLASS(wxWindowMac
);
400 DECLARE_EVENT_TABLE()
403 #endif // _WX_WINDOW_H_