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 // 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_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
118 // hot keys (system wide accelerators)
119 // -----------------------------------
121 virtual bool RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
);
122 virtual bool UnregisterHotKey(int hotkeyId
);
123 #endif // wxUSE_HOTKEY
125 #if wxUSE_DRAG_AND_DROP
126 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
129 // Accept files for dragging
130 virtual void DragAcceptFiles( bool accept
);
132 // implementation from now on
133 // --------------------------
135 void MacClientToRootWindow( int *x
, int *y
) const;
137 void MacWindowToRootWindow( int *x
, int *y
) const;
139 void MacRootWindowToWindow( int *x
, int *y
) const;
141 virtual wxString
MacGetToolTipString( wxPoint
&where
);
146 virtual WXWidget
GetHandle() const;
148 virtual bool SetTransparent(wxByte alpha
);
149 virtual bool CanSetTransparent();
150 virtual wxByte
GetTransparent() const ;
155 void OnMouseEvent( wxMouseEvent
&event
);
157 void MacOnScroll( wxScrollEvent
&event
);
159 virtual bool AcceptsFocus() const;
161 virtual bool IsDoubleBuffered() const { return true; }
164 static long MacRemoveBordersFromStyle( long style
) ;
167 // For implementation purposes:
168 // sometimes decorations make the client area smaller
169 virtual wxPoint
GetClientAreaOrigin() const;
171 wxWindowMac
*FindItem(long id
) const;
172 wxWindowMac
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= false) const;
174 virtual void TriggerScrollEvent( wxEventType scrollEvent
) ;
175 // this should not be overridden in classes above wxWindowMac
176 // because it is called from its destructor via DeleteChildren
177 virtual void RemoveChild( wxWindowBase
*child
);
179 virtual bool MacDoRedraw( long time
) ;
180 virtual void MacPaintChildrenBorders();
181 virtual void MacPaintBorders( int left
, int top
) ;
182 void MacPaintGrowBox();
184 // invalidates the borders and focus area around the control;
185 // must not be virtual as it will be called during destruction
186 void MacInvalidateBorders() ;
188 WXWindow
MacGetTopLevelWindowRef() const ;
189 wxNonOwnedWindow
* MacGetTopLevelWindow() const ;
191 virtual long MacGetWXBorderSize() const;
192 virtual long MacGetLeftBorderSize() const ;
193 virtual long MacGetRightBorderSize() const ;
194 virtual long MacGetTopBorderSize() const ;
195 virtual long MacGetBottomBorderSize() const ;
197 virtual void MacSuperChangedPosition() ;
199 // absolute coordinates of this window's root have changed
200 virtual void MacTopLevelWindowChangedPosition() ;
202 virtual void MacChildAdded() ;
203 virtual void MacVisibilityChanged() ;
204 virtual void MacEnabledStateChanged() ;
205 virtual void MacHiliteChanged() ;
206 virtual wxInt32
MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF event
) ;
208 bool MacIsReallyEnabled() ;
209 bool MacIsReallyHilited() ;
211 #if WXWIN_COMPATIBILITY_2_8
212 bool MacIsUserPane();
214 bool MacIsUserPane() const;
216 virtual bool MacSetupCursor( const wxPoint
& pt
) ;
218 // return the rectangle that would be visible of this control,
219 // regardless whether controls are hidden
220 // only taking into account clipping by parent windows
221 const wxRect
& MacGetClippedClientRect() const ;
222 const wxRect
& MacGetClippedRect() const ;
223 const wxRect
& MacGetClippedRectWithOuterStructure() const ;
225 // returns the visible region of this control in window ie non-client coordinates
226 const wxRegion
& MacGetVisibleRegion( bool includeOuterStructures
= false ) ;
228 // returns true if children have to clipped to the content area
229 // (e.g., scrolled windows)
230 bool MacClipChildren() const { return m_clipChildren
; }
231 void MacSetClipChildren( bool clip
) { m_clipChildren
= clip
; }
233 // returns true if the grandchildren need to be clipped to the children's content area
234 // (e.g., splitter windows)
235 virtual bool MacClipGrandChildren() const { return false ; }
236 bool MacIsWindowScrollbar( const wxWindow
* sb
) const
237 { return ((wxWindow
*)m_hScrollBar
== sb
|| (wxWindow
*)m_vScrollBar
== sb
) ; }
238 virtual bool IsClientAreaChild(const wxWindow
*child
) const
240 return !MacIsWindowScrollbar(child
) && !((wxWindow
*)m_growBox
==child
) &&
241 wxWindowBase::IsClientAreaChild(child
);
244 void MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
) ;
245 wxList
& GetSubcontrols() { return m_subControls
; }
247 // translate wxWidgets coords into ones suitable
248 // to be passed to CreateControl calls
250 // returns true if non-default coords are returned, false otherwise
251 bool MacGetBoundsForControl(const wxPoint
& pos
,
254 int& w
, int& h
, bool adjustForOrigin
) const ;
256 // the 'true' OS level control for this wxWindow
257 wxOSXWidgetImpl
* GetPeer() const;
259 // optimization to avoid creating a user pane in wxWindow::Create if we already know
260 // we will replace it with our own peer
261 void DontCreatePeer();
263 // return true unless DontCreatePeer() had been called
264 bool ShouldCreatePeer() const;
266 // sets the native implementation wrapper, can replace an existing peer, use peer = NULL to
267 // release existing peer
268 void SetPeer(wxOSXWidgetImpl
* peer
);
270 // wraps the already existing peer with the wrapper
271 void SetWrappingPeer(wxOSXWidgetImpl
* wrapper
);
273 #if wxOSX_USE_COCOA_OR_IPHONE
274 // the NSView or NSWindow of this window: can be used for both child and
277 // this is useful for a few Cocoa function which can work with either views
278 // or windows indiscriminately, e.g. for setting NSViewAnimationTargetKey
279 virtual void *OSXGetViewOrWindow() const { return GetHandle(); }
282 void * MacGetCGContextRef() { return m_cgContextRef
; }
283 void MacSetCGContextRef(void * cg
) { m_cgContextRef
= cg
; }
285 // osx specific event handling common for all osx-ports
287 virtual bool OSXHandleClicked( double timestampsec
);
288 virtual bool OSXHandleKeyEvent( wxKeyEvent
& event
);
289 virtual void OSXSimulateFocusEvents();
291 bool IsNativeWindowWrapper() const { return m_isNativeWindowWrapper
; }
293 float GetContentScaleFactor() const ;
295 // internal response to size events
296 virtual void MacOnInternalSize() {}
299 // For controls like radio buttons which are genuinely composite
300 wxList m_subControls
;
302 // the peer object, allowing for cleaner API support
304 void * m_cgContextRef
;
306 // cache the clipped rectangles within the window hierarchy
307 void MacUpdateClippedRects() const ;
309 mutable bool m_cachedClippedRectValid
;
310 mutable wxRect m_cachedClippedRectWithOuterStructure
;
311 mutable wxRect m_cachedClippedRect
;
312 mutable wxRect m_cachedClippedClientRect
;
313 mutable wxRegion m_cachedClippedRegionWithOuterStructure
;
314 mutable wxRegion m_cachedClippedRegion
;
315 mutable wxRegion m_cachedClippedClientRegion
;
317 // insets of the mac control from the wx top left corner
318 wxPoint m_macTopLeftInset
;
319 wxPoint m_macBottomRightInset
;
322 wxScrollBar
* m_hScrollBar
;
323 wxScrollBar
* m_vScrollBar
;
324 bool m_hScrollBarAlwaysShown
;
325 bool m_vScrollBarAlwaysShown
;
326 wxWindow
* m_growBox
;
329 bool m_isNativeWindowWrapper
;
331 // set to true if we do a sharp clip at the content area of this window
332 // must be dynamic as eg a panel normally is not clipping precisely, but if
333 // it becomes the target window of a scrolled window it has to...
334 bool m_clipChildren
;
336 virtual bool MacIsChildOfClientArea( const wxWindow
* child
) const ;
338 bool MacHasScrollBarCorner() const;
339 void MacCreateScrollBars( long style
) ;
340 void MacRepositionScrollBars() ;
341 void MacUpdateControlFont() ;
343 // implement the base class pure virtuals
344 virtual void DoGetTextExtent(const wxString
& string
,
347 int *externalLeading
= NULL
,
348 const wxFont
*theFont
= NULL
) const;
350 virtual void DoEnable( bool enable
);
352 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
355 virtual void DoFreeze();
356 virtual void DoThaw();
358 virtual wxSize
DoGetBestSize() const;
359 virtual wxSize
DoGetSizeFromClientSize( const wxSize
& size
) const;
360 virtual void DoClientToScreen( int *x
, int *y
) const;
361 virtual void DoScreenToClient( int *x
, int *y
) const;
362 virtual void DoGetPosition( int *x
, int *y
) const;
363 virtual void DoGetSize( int *width
, int *height
) const;
364 virtual void DoGetClientSize( int *width
, int *height
) const;
365 virtual void DoSetSize(int x
, int y
,
366 int width
, int height
,
367 int sizeFlags
= wxSIZE_AUTO
);
368 virtual void DoSetClientSize(int width
, int height
);
370 virtual void DoCaptureMouse();
371 virtual void DoReleaseMouse();
373 // move the window to the specified location and resize it: this is called
374 // from both DoSetSize() and DoSetClientSize() and would usually just call
375 // ::MoveWindow() except for composite controls which will want to arrange
376 // themselves inside the given rectangle
377 virtual void DoMoveWindow( int x
, int y
, int width
, int height
);
378 virtual void DoSetWindowVariant( wxWindowVariant variant
);
381 virtual void DoSetToolTip( wxToolTip
*tip
);
384 // common part of Show/HideWithEffect()
385 virtual bool OSXShowWithEffect(bool show
,
390 wxOSXWidgetImpl
* m_peer
;
391 // common part of all ctors
394 // show/hide scrollbars as needed, common part of SetScrollbar() and
395 // AlwaysShowScrollbars()
396 void DoUpdateScrollbarVisibility();
398 wxDECLARE_NO_COPY_CLASS(wxWindowMac
);
399 DECLARE_EVENT_TABLE()
402 #endif // _WX_WINDOW_H_