1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/osx/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 virtual void SendSizeEvent(int flags
= 0);
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 );
68 virtual bool ShowWithEffect(wxShowEffect effect
,
71 return OSXShowWithEffect(true, effect
, timeout
);
73 virtual bool HideWithEffect(wxShowEffect effect
,
76 return OSXShowWithEffect(false, effect
, timeout
);
79 virtual bool IsShownOnScreen() const;
81 virtual void SetFocus();
83 virtual void WarpPointer( int x
, int y
);
85 virtual void Refresh( bool eraseBackground
= true,
86 const wxRect
*rect
= NULL
);
88 virtual void Update() ;
89 virtual void ClearBackground();
91 virtual bool SetCursor( const wxCursor
&cursor
);
92 virtual bool SetFont( const wxFont
&font
);
93 virtual bool SetBackgroundColour( const wxColour
&colour
);
94 virtual bool SetForegroundColour( const wxColour
&colour
);
96 virtual bool SetBackgroundStyle(wxBackgroundStyle style
);
98 virtual int GetCharHeight() const;
99 virtual int GetCharWidth() const;
101 virtual double GetMagnificationFactor() const;
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_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
122 // hot keys (system wide accelerators)
123 // -----------------------------------
125 virtual bool RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
);
126 virtual bool UnregisterHotKey(int hotkeyId
);
127 #endif // wxUSE_HOTKEY
129 #if wxUSE_DRAG_AND_DROP
130 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
133 // Accept files for dragging
134 virtual void DragAcceptFiles( bool accept
);
136 // implementation from now on
137 // --------------------------
139 void MacClientToRootWindow( int *x
, int *y
) const;
141 void MacWindowToRootWindow( int *x
, int *y
) const;
143 void MacRootWindowToWindow( int *x
, int *y
) const;
145 virtual wxString
MacGetToolTipString( wxPoint
&where
);
150 virtual WXWidget
GetHandle() const;
152 virtual bool SetTransparent(wxByte alpha
);
153 virtual bool CanSetTransparent();
154 virtual wxByte
GetTransparent() const ;
159 void OnMouseEvent( wxMouseEvent
&event
);
161 void MacOnScroll( wxScrollEvent
&event
);
163 virtual bool AcceptsFocus() const;
165 virtual bool IsDoubleBuffered() const { return true; }
168 static long MacRemoveBordersFromStyle( long style
) ;
171 // For implementation purposes:
172 // sometimes decorations make the client area smaller
173 virtual wxPoint
GetClientAreaOrigin() const;
175 wxWindowMac
*FindItem(long id
) const;
176 wxWindowMac
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= false) const;
178 virtual void TriggerScrollEvent( wxEventType scrollEvent
) ;
179 // this should not be overridden in classes above wxWindowMac
180 // because it is called from its destructor via DeleteChildren
181 virtual void RemoveChild( wxWindowBase
*child
);
183 virtual bool MacDoRedraw( long time
) ;
184 virtual void MacPaintChildrenBorders();
185 virtual void MacPaintBorders( int left
, int top
) ;
186 void MacPaintGrowBox();
188 // invalidates the borders and focus area around the control;
189 // must not be virtual as it will be called during destruction
190 void MacInvalidateBorders() ;
192 WXWindow
MacGetTopLevelWindowRef() const ;
193 wxNonOwnedWindow
* MacGetTopLevelWindow() const ;
195 virtual long MacGetWXBorderSize() const;
196 virtual long MacGetLeftBorderSize() const ;
197 virtual long MacGetRightBorderSize() const ;
198 virtual long MacGetTopBorderSize() const ;
199 virtual long MacGetBottomBorderSize() const ;
201 virtual void MacSuperChangedPosition() ;
203 // absolute coordinates of this window's root have changed
204 virtual void MacTopLevelWindowChangedPosition() ;
206 virtual void MacChildAdded() ;
207 virtual void MacVisibilityChanged() ;
208 virtual void MacEnabledStateChanged() ;
209 virtual void MacHiliteChanged() ;
210 virtual wxInt32
MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF event
) ;
212 bool MacIsReallyEnabled() ;
213 bool MacIsReallyHilited() ;
215 #if WXWIN_COMPATIBILITY_2_8
216 bool MacIsUserPane();
218 bool MacIsUserPane() const;
220 virtual bool MacSetupCursor( const wxPoint
& pt
) ;
222 // return the rectangle that would be visible of this control,
223 // regardless whether controls are hidden
224 // only taking into account clipping by parent windows
225 const wxRect
& MacGetClippedClientRect() const ;
226 const wxRect
& MacGetClippedRect() const ;
227 const wxRect
& MacGetClippedRectWithOuterStructure() const ;
229 // returns the visible region of this control in window ie non-client coordinates
230 const wxRegion
& MacGetVisibleRegion( bool includeOuterStructures
= false ) ;
232 // returns true if children have to clipped to the content area
233 // (e.g., scrolled windows)
234 bool MacClipChildren() const { return m_clipChildren
; }
235 void MacSetClipChildren( bool clip
) { m_clipChildren
= clip
; }
237 // returns true if the grandchildren need to be clipped to the children's content area
238 // (e.g., splitter windows)
239 virtual bool MacClipGrandChildren() const { return false ; }
240 bool MacIsWindowScrollbar( const wxWindow
* sb
) const
241 { return ((wxWindow
*)m_hScrollBar
== sb
|| (wxWindow
*)m_vScrollBar
== sb
) ; }
242 virtual bool IsClientAreaChild(const wxWindow
*child
) const
244 return !MacIsWindowScrollbar(child
) && !((wxWindow
*)m_growBox
==child
) &&
245 wxWindowBase::IsClientAreaChild(child
);
248 void MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
) ;
249 wxList
& GetSubcontrols() { return m_subControls
; }
251 // translate wxWidgets coords into ones suitable
252 // to be passed to CreateControl calls
254 // returns true if non-default coords are returned, false otherwise
255 bool MacGetBoundsForControl(const wxPoint
& pos
,
258 int& w
, int& h
, bool adjustForOrigin
) const ;
260 // the 'true' OS level control for this wxWindow
261 wxOSXWidgetImpl
* GetPeer() const;
263 // optimization to avoid creating a user pane in wxWindow::Create if we already know
264 // we will replace it with our own peer
265 void DontCreatePeer();
267 // return true unless DontCreatePeer() had been called
268 bool ShouldCreatePeer() const;
270 // sets the native implementation wrapper, can replace an existing peer, use peer = NULL to
271 // release existing peer
272 void SetPeer(wxOSXWidgetImpl
* peer
);
274 // wraps the already existing peer with the wrapper
275 void SetWrappingPeer(wxOSXWidgetImpl
* wrapper
);
277 #if wxOSX_USE_COCOA_OR_IPHONE
278 // the NSView or NSWindow of this window: can be used for both child and
281 // this is useful for a few Cocoa function which can work with either views
282 // or windows indiscriminately, e.g. for setting NSViewAnimationTargetKey
283 virtual void *OSXGetViewOrWindow() const { return GetHandle(); }
286 void * MacGetCGContextRef() { return m_cgContextRef
; }
287 void MacSetCGContextRef(void * cg
) { m_cgContextRef
= cg
; }
289 // osx specific event handling common for all osx-ports
291 virtual bool OSXHandleClicked( double timestampsec
);
292 virtual bool OSXHandleKeyEvent( wxKeyEvent
& event
);
293 virtual void OSXSimulateFocusEvents();
295 bool IsNativeWindowWrapper() const { return m_isNativeWindowWrapper
; }
297 float GetContentScaleFactor() const ;
299 // internal response to size events
300 virtual void MacOnInternalSize() {}
303 // For controls like radio buttons which are genuinely composite
304 wxList m_subControls
;
306 // the peer object, allowing for cleaner API support
308 void * m_cgContextRef
;
310 // cache the clipped rectangles within the window hierarchy
311 void MacUpdateClippedRects() const ;
313 mutable bool m_cachedClippedRectValid
;
314 mutable wxRect m_cachedClippedRectWithOuterStructure
;
315 mutable wxRect m_cachedClippedRect
;
316 mutable wxRect m_cachedClippedClientRect
;
317 mutable wxRegion m_cachedClippedRegionWithOuterStructure
;
318 mutable wxRegion m_cachedClippedRegion
;
319 mutable wxRegion m_cachedClippedClientRegion
;
321 // insets of the mac control from the wx top left corner
322 wxPoint m_macTopLeftInset
;
323 wxPoint m_macBottomRightInset
;
326 wxScrollBar
* m_hScrollBar
;
327 wxScrollBar
* m_vScrollBar
;
328 bool m_hScrollBarAlwaysShown
;
329 bool m_vScrollBarAlwaysShown
;
330 wxWindow
* m_growBox
;
333 bool m_isNativeWindowWrapper
;
335 // set to true if we do a sharp clip at the content area of this window
336 // must be dynamic as eg a panel normally is not clipping precisely, but if
337 // it becomes the target window of a scrolled window it has to...
338 bool m_clipChildren
;
340 virtual bool MacIsChildOfClientArea( const wxWindow
* child
) const ;
342 bool MacHasScrollBarCorner() const;
343 void MacCreateScrollBars( long style
) ;
344 void MacRepositionScrollBars() ;
345 void MacUpdateControlFont() ;
347 // implement the base class pure virtuals
348 virtual void DoGetTextExtent(const wxString
& string
,
351 int *externalLeading
= NULL
,
352 const wxFont
*theFont
= NULL
) const;
354 virtual void DoEnable( bool enable
);
356 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
359 virtual void DoFreeze();
360 virtual void DoThaw();
362 virtual wxSize
DoGetBestSize() const;
363 virtual wxSize
DoGetSizeFromClientSize( const wxSize
& size
) const;
364 virtual void DoClientToScreen( int *x
, int *y
) const;
365 virtual void DoScreenToClient( int *x
, int *y
) const;
366 virtual void DoGetPosition( int *x
, int *y
) const;
367 virtual void DoGetSize( int *width
, int *height
) const;
368 virtual void DoGetClientSize( int *width
, int *height
) const;
369 virtual void DoSetSize(int x
, int y
,
370 int width
, int height
,
371 int sizeFlags
= wxSIZE_AUTO
);
372 virtual void DoSetClientSize(int width
, int height
);
374 virtual void DoCaptureMouse();
375 virtual void DoReleaseMouse();
377 // move the window to the specified location and resize it: this is called
378 // from both DoSetSize() and DoSetClientSize() and would usually just call
379 // ::MoveWindow() except for composite controls which will want to arrange
380 // themselves inside the given rectangle
381 virtual void DoMoveWindow( int x
, int y
, int width
, int height
);
382 virtual void DoSetWindowVariant( wxWindowVariant variant
);
385 virtual void DoSetToolTip( wxToolTip
*tip
);
388 // common part of Show/HideWithEffect()
389 virtual bool OSXShowWithEffect(bool show
,
394 wxOSXWidgetImpl
* m_peer
;
395 // common part of all ctors
398 // show/hide scrollbars as needed, common part of SetScrollbar() and
399 // AlwaysShowScrollbars()
400 void DoUpdateScrollbarVisibility();
402 wxDECLARE_NO_COPY_CLASS(wxWindowMac
);
403 DECLARE_EVENT_TABLE()
406 #endif // _WX_WINDOW_H_