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;
102 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
103 int range
, bool refresh
= true );
104 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= true );
105 virtual int GetScrollPos( int orient
) const;
106 virtual int GetScrollThumb( int orient
) const;
107 virtual int GetScrollRange( int orient
) const;
108 virtual void ScrollWindow( int dx
, int dy
,
109 const wxRect
* rect
= NULL
);
110 virtual void AlwaysShowScrollbars(bool horz
= true, bool vert
= true);
111 virtual bool IsScrollbarAlwaysShown(int orient
) const
113 return orient
== wxHORIZONTAL
? m_hScrollBarAlwaysShown
114 : m_vScrollBarAlwaysShown
;
117 virtual bool Reparent( wxWindowBase
*newParent
);
119 #if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
120 // hot keys (system wide accelerators)
121 // -----------------------------------
123 virtual bool RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
);
124 virtual bool UnregisterHotKey(int hotkeyId
);
125 #endif // wxUSE_HOTKEY
127 #if wxUSE_DRAG_AND_DROP
128 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
131 // Accept files for dragging
132 virtual void DragAcceptFiles( bool accept
);
134 // implementation from now on
135 // --------------------------
137 void MacClientToRootWindow( int *x
, int *y
) const;
139 void MacWindowToRootWindow( int *x
, int *y
) const;
141 void MacRootWindowToWindow( int *x
, int *y
) const;
143 virtual wxString
MacGetToolTipString( wxPoint
&where
);
148 virtual WXWidget
GetHandle() const;
150 virtual bool SetTransparent(wxByte alpha
);
151 virtual bool CanSetTransparent();
152 virtual wxByte
GetTransparent() const ;
157 void OnMouseEvent( wxMouseEvent
&event
);
159 void MacOnScroll( wxScrollEvent
&event
);
161 virtual bool AcceptsFocus() const;
163 virtual bool IsDoubleBuffered() const { return true; }
166 static long MacRemoveBordersFromStyle( long style
) ;
169 // For implementation purposes:
170 // sometimes decorations make the client area smaller
171 virtual wxPoint
GetClientAreaOrigin() const;
173 wxWindowMac
*FindItem(long id
) const;
174 wxWindowMac
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= false) const;
176 virtual void TriggerScrollEvent( wxEventType scrollEvent
) ;
177 // this should not be overridden in classes above wxWindowMac
178 // because it is called from its destructor via DeleteChildren
179 virtual void RemoveChild( wxWindowBase
*child
);
181 virtual bool MacDoRedraw( long time
) ;
182 virtual void MacPaintChildrenBorders();
183 virtual void MacPaintBorders( int left
, int top
) ;
184 void MacPaintGrowBox();
186 // invalidates the borders and focus area around the control;
187 // must not be virtual as it will be called during destruction
188 void MacInvalidateBorders() ;
190 WXWindow
MacGetTopLevelWindowRef() const ;
191 wxNonOwnedWindow
* MacGetTopLevelWindow() const ;
193 virtual long MacGetWXBorderSize() const;
194 virtual long MacGetLeftBorderSize() const ;
195 virtual long MacGetRightBorderSize() const ;
196 virtual long MacGetTopBorderSize() const ;
197 virtual long MacGetBottomBorderSize() const ;
199 virtual void MacSuperChangedPosition() ;
201 // absolute coordinates of this window's root have changed
202 virtual void MacTopLevelWindowChangedPosition() ;
204 virtual void MacChildAdded() ;
205 virtual void MacVisibilityChanged() ;
206 virtual void MacEnabledStateChanged() ;
207 virtual void MacHiliteChanged() ;
208 virtual wxInt32
MacControlHit( WXEVENTHANDLERREF handler
, WXEVENTREF event
) ;
210 bool MacIsReallyEnabled() ;
211 bool MacIsReallyHilited() ;
213 #if WXWIN_COMPATIBILITY_2_8
214 bool MacIsUserPane();
216 bool MacIsUserPane() const;
218 virtual bool MacSetupCursor( const wxPoint
& pt
) ;
220 // return the rectangle that would be visible of this control,
221 // regardless whether controls are hidden
222 // only taking into account clipping by parent windows
223 const wxRect
& MacGetClippedClientRect() const ;
224 const wxRect
& MacGetClippedRect() const ;
225 const wxRect
& MacGetClippedRectWithOuterStructure() const ;
227 // returns the visible region of this control in window ie non-client coordinates
228 const wxRegion
& MacGetVisibleRegion( bool includeOuterStructures
= false ) ;
230 // returns true if children have to clipped to the content area
231 // (e.g., scrolled windows)
232 bool MacClipChildren() const { return m_clipChildren
; }
233 void MacSetClipChildren( bool clip
) { m_clipChildren
= clip
; }
235 // returns true if the grandchildren need to be clipped to the children's content area
236 // (e.g., splitter windows)
237 virtual bool MacClipGrandChildren() const { return false ; }
238 bool MacIsWindowScrollbar( const wxWindow
* sb
) const
239 { return ((wxWindow
*)m_hScrollBar
== sb
|| (wxWindow
*)m_vScrollBar
== sb
) ; }
240 virtual bool IsClientAreaChild(const wxWindow
*child
) const
242 return !MacIsWindowScrollbar(child
) && !((wxWindow
*)m_growBox
==child
) &&
243 wxWindowBase::IsClientAreaChild(child
);
246 void MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
) ;
247 wxList
& GetSubcontrols() { return m_subControls
; }
249 // translate wxWidgets coords into ones suitable
250 // to be passed to CreateControl calls
252 // returns true if non-default coords are returned, false otherwise
253 bool MacGetBoundsForControl(const wxPoint
& pos
,
256 int& w
, int& h
, bool adjustForOrigin
) const ;
258 // the 'true' OS level control for this wxWindow
259 wxOSXWidgetImpl
* GetPeer() const;
261 // optimization to avoid creating a user pane in wxWindow::Create if we already know
262 // we will replace it with our own peer
263 void DontCreatePeer();
265 // return true unless DontCreatePeer() had been called
266 bool ShouldCreatePeer() const;
268 // sets the native implementation wrapper, can replace an existing peer, use peer = NULL to
269 // release existing peer
270 void SetPeer(wxOSXWidgetImpl
* peer
);
272 // wraps the already existing peer with the wrapper
273 void SetWrappingPeer(wxOSXWidgetImpl
* wrapper
);
275 #if wxOSX_USE_COCOA_OR_IPHONE
276 // the NSView or NSWindow of this window: can be used for both child and
279 // this is useful for a few Cocoa function which can work with either views
280 // or windows indiscriminately, e.g. for setting NSViewAnimationTargetKey
281 virtual void *OSXGetViewOrWindow() const { return GetHandle(); }
284 void * MacGetCGContextRef() { return m_cgContextRef
; }
285 void MacSetCGContextRef(void * cg
) { m_cgContextRef
= cg
; }
287 // osx specific event handling common for all osx-ports
289 virtual bool OSXHandleClicked( double timestampsec
);
290 virtual bool OSXHandleKeyEvent( wxKeyEvent
& event
);
291 virtual void OSXSimulateFocusEvents();
293 bool IsNativeWindowWrapper() const { return m_isNativeWindowWrapper
; }
295 float GetContentScaleFactor() const ;
297 // internal response to size events
298 virtual void MacOnInternalSize() {}
301 // For controls like radio buttons which are genuinely composite
302 wxList m_subControls
;
304 // the peer object, allowing for cleaner API support
306 void * m_cgContextRef
;
308 // cache the clipped rectangles within the window hierarchy
309 void MacUpdateClippedRects() const ;
311 mutable bool m_cachedClippedRectValid
;
312 mutable wxRect m_cachedClippedRectWithOuterStructure
;
313 mutable wxRect m_cachedClippedRect
;
314 mutable wxRect m_cachedClippedClientRect
;
315 mutable wxRegion m_cachedClippedRegionWithOuterStructure
;
316 mutable wxRegion m_cachedClippedRegion
;
317 mutable wxRegion m_cachedClippedClientRegion
;
319 // insets of the mac control from the wx top left corner
320 wxPoint m_macTopLeftInset
;
321 wxPoint m_macBottomRightInset
;
324 wxScrollBar
* m_hScrollBar
;
325 wxScrollBar
* m_vScrollBar
;
326 bool m_hScrollBarAlwaysShown
;
327 bool m_vScrollBarAlwaysShown
;
328 wxWindow
* m_growBox
;
331 bool m_isNativeWindowWrapper
;
333 // set to true if we do a sharp clip at the content area of this window
334 // must be dynamic as eg a panel normally is not clipping precisely, but if
335 // it becomes the target window of a scrolled window it has to...
336 bool m_clipChildren
;
338 virtual bool MacIsChildOfClientArea( const wxWindow
* child
) const ;
340 bool MacHasScrollBarCorner() const;
341 void MacCreateScrollBars( long style
) ;
342 void MacRepositionScrollBars() ;
343 void MacUpdateControlFont() ;
345 // implement the base class pure virtuals
346 virtual void DoGetTextExtent(const wxString
& string
,
349 int *externalLeading
= NULL
,
350 const wxFont
*theFont
= NULL
) const;
352 virtual void DoEnable( bool enable
);
354 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
357 virtual void DoFreeze();
358 virtual void DoThaw();
360 virtual wxSize
DoGetBestSize() const;
361 virtual wxSize
DoGetSizeFromClientSize( const wxSize
& size
) const;
362 virtual void DoClientToScreen( int *x
, int *y
) const;
363 virtual void DoScreenToClient( int *x
, int *y
) const;
364 virtual void DoGetPosition( int *x
, int *y
) const;
365 virtual void DoGetSize( int *width
, int *height
) const;
366 virtual void DoGetClientSize( int *width
, int *height
) const;
367 virtual void DoSetSize(int x
, int y
,
368 int width
, int height
,
369 int sizeFlags
= wxSIZE_AUTO
);
370 virtual void DoSetClientSize(int width
, int height
);
372 virtual void DoCaptureMouse();
373 virtual void DoReleaseMouse();
375 // move the window to the specified location and resize it: this is called
376 // from both DoSetSize() and DoSetClientSize() and would usually just call
377 // ::MoveWindow() except for composite controls which will want to arrange
378 // themselves inside the given rectangle
379 virtual void DoMoveWindow( int x
, int y
, int width
, int height
);
380 virtual void DoSetWindowVariant( wxWindowVariant variant
);
383 virtual void DoSetToolTip( wxToolTip
*tip
);
386 // common part of Show/HideWithEffect()
387 virtual bool OSXShowWithEffect(bool show
,
392 wxOSXWidgetImpl
* m_peer
;
393 // common part of all ctors
396 // show/hide scrollbars as needed, common part of SetScrollbar() and
397 // AlwaysShowScrollbars()
398 void DoUpdateScrollbarVisibility();
400 wxDECLARE_NO_COPY_CLASS(wxWindowMac
);
401 DECLARE_EVENT_TABLE()
404 #endif // _WX_WINDOW_H_