]> git.saurik.com Git - wxWidgets.git/blame - include/wx/osx/window.h
Add functor-taking overload of CallAfter().
[wxWidgets.git] / include / wx / osx / window.h
CommitLineData
6762286d 1/////////////////////////////////////////////////////////////////////////////
233f5738 2// Name: wx/osx/window.h
6762286d
SC
3// Purpose: wxWindowMac class
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_WINDOW_H_
13#define _WX_WINDOW_H_
14
15#include "wx/brush.h"
16#include "wx/dc.h"
17
18class WXDLLIMPEXP_FWD_CORE wxButton;
19class WXDLLIMPEXP_FWD_CORE wxScrollBar;
2ae3afa0 20class WXDLLIMPEXP_FWD_CORE wxPanel;
6762286d
SC
21class WXDLLIMPEXP_FWD_CORE wxNonOwnedWindow;
22
c099b533
SC
23#if wxOSX_USE_CARBON
24 class WXDLLIMPEXP_FWD_CORE wxMacControl ;
25 typedef wxMacControl wxOSXWidgetImpl;
ee032c59
SC
26#elif wxOSX_USE_COCOA_OR_IPHONE
27 class WXDLLIMPEXP_FWD_CORE wxWidgetImpl ;
28 typedef wxWidgetImpl wxOSXWidgetImpl;
c099b533
SC
29#endif
30
6762286d
SC
31
32class WXDLLIMPEXP_CORE wxWindowMac: public wxWindowBase
33{
34 DECLARE_DYNAMIC_CLASS(wxWindowMac)
35
36 friend class wxDC;
37 friend class wxPaintDC;
38
39public:
40 wxWindowMac();
41
42 wxWindowMac( wxWindowMac *parent,
43 wxWindowID id,
44 const wxPoint& pos = wxDefaultPosition,
45 const wxSize& size = wxDefaultSize,
46 long style = 0,
47 const wxString& name = wxPanelNameStr );
48
49 virtual ~wxWindowMac();
50
51 bool Create( wxWindowMac *parent,
52 wxWindowID id,
53 const wxPoint& pos = wxDefaultPosition,
54 const wxSize& size = wxDefaultSize,
55 long style = 0,
56 const wxString& name = wxPanelNameStr );
57
cf83b0cf
SC
58 virtual void SendSizeEvent(int flags = 0);
59
6762286d
SC
60 // implement base class pure virtuals
61 virtual void SetLabel( const wxString& label );
62 virtual wxString GetLabel() const;
63
64 virtual void Raise();
65 virtual void Lower();
66
67 virtual bool Show( bool show = true );
ab9a0b84
VZ
68 virtual bool ShowWithEffect(wxShowEffect effect,
69 unsigned timeout = 0)
70 {
71 return OSXShowWithEffect(true, effect, timeout);
72 }
73 virtual bool HideWithEffect(wxShowEffect effect,
74 unsigned timeout = 0)
75 {
76 return OSXShowWithEffect(false, effect, timeout);
77 }
6762286d
SC
78
79 virtual bool IsShownOnScreen() const;
80
81 virtual void SetFocus();
82
83 virtual void WarpPointer( int x, int y );
84
85 virtual void Refresh( bool eraseBackground = true,
86 const wxRect *rect = NULL );
87
88 virtual void Update() ;
89 virtual void ClearBackground();
90
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 );
95
bc5c09a3
SC
96 virtual bool SetBackgroundStyle(wxBackgroundStyle style);
97
6762286d
SC
98 virtual int GetCharHeight() const;
99 virtual int GetCharWidth() const;
f8619070 100
6762286d
SC
101public:
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,
d3b9f782 109 const wxRect* rect = NULL );
6762286d
SC
110 virtual void AlwaysShowScrollbars(bool horz = true, bool vert = true);
111 virtual bool IsScrollbarAlwaysShown(int orient) const
112 {
113 return orient == wxHORIZONTAL ? m_hScrollBarAlwaysShown
114 : m_vScrollBarAlwaysShown;
115 }
116
117 virtual bool Reparent( wxWindowBase *newParent );
118
c1313b54
SC
119#if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
120 // hot keys (system wide accelerators)
121 // -----------------------------------
122
123 virtual bool RegisterHotKey(int hotkeyId, int modifiers, int keycode);
124 virtual bool UnregisterHotKey(int hotkeyId);
125#endif // wxUSE_HOTKEY
126
6762286d
SC
127#if wxUSE_DRAG_AND_DROP
128 virtual void SetDropTarget( wxDropTarget *dropTarget );
129#endif
130
131 // Accept files for dragging
132 virtual void DragAcceptFiles( bool accept );
133
134 // implementation from now on
135 // --------------------------
136
137 void MacClientToRootWindow( int *x , int *y ) const;
138
139 void MacWindowToRootWindow( int *x , int *y ) const;
140
141 void MacRootWindowToWindow( int *x , int *y ) const;
142
143 virtual wxString MacGetToolTipString( wxPoint &where );
144
145 // simple accessors
146 // ----------------
147
148 virtual WXWidget GetHandle() const;
149
150 virtual bool SetTransparent(wxByte alpha);
151 virtual bool CanSetTransparent();
152 virtual wxByte GetTransparent() const ;
153
154 // event handlers
155 // --------------
4dd9fdf8 156
6762286d
SC
157 void OnMouseEvent( wxMouseEvent &event );
158
159 void MacOnScroll( wxScrollEvent&event );
160
161 virtual bool AcceptsFocus() const;
162
163 virtual bool IsDoubleBuffered() const { return true; }
164
165public:
166 static long MacRemoveBordersFromStyle( long style ) ;
167
168public:
6762286d
SC
169 // For implementation purposes:
170 // sometimes decorations make the client area smaller
171 virtual wxPoint GetClientAreaOrigin() const;
172
173 wxWindowMac *FindItem(long id) const;
174 wxWindowMac *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const;
175
19c7ac3d 176 virtual void TriggerScrollEvent( wxEventType scrollEvent ) ;
4c51a665 177 // this should not be overridden in classes above wxWindowMac
6762286d
SC
178 // because it is called from its destructor via DeleteChildren
179 virtual void RemoveChild( wxWindowBase *child );
03647350 180
5398a2e0
SC
181 virtual bool MacDoRedraw( long time ) ;
182 virtual void MacPaintChildrenBorders();
6762286d
SC
183 virtual void MacPaintBorders( int left , int top ) ;
184 void MacPaintGrowBox();
185
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() ;
189
190 WXWindow MacGetTopLevelWindowRef() const ;
191 wxNonOwnedWindow* MacGetTopLevelWindow() const ;
192
54ea2834 193 virtual long MacGetWXBorderSize() const;
6762286d
SC
194 virtual long MacGetLeftBorderSize() const ;
195 virtual long MacGetRightBorderSize() const ;
196 virtual long MacGetTopBorderSize() const ;
197 virtual long MacGetBottomBorderSize() const ;
198
199 virtual void MacSuperChangedPosition() ;
200
201 // absolute coordinates of this window's root have changed
202 virtual void MacTopLevelWindowChangedPosition() ;
203
204 virtual void MacChildAdded() ;
205 virtual void MacVisibilityChanged() ;
206 virtual void MacEnabledStateChanged() ;
207 virtual void MacHiliteChanged() ;
208 virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ;
209
210 bool MacIsReallyEnabled() ;
211 bool MacIsReallyHilited() ;
212
938fbc8f 213#if WXWIN_COMPATIBILITY_2_8
d15694e8 214 bool MacIsUserPane();
938fbc8f 215#endif
d15694e8 216 bool MacIsUserPane() const;
6762286d
SC
217
218 virtual bool MacSetupCursor( const wxPoint& pt ) ;
219
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 ;
226
227 // returns the visible region of this control in window ie non-client coordinates
228 const wxRegion& MacGetVisibleRegion( bool includeOuterStructures = false ) ;
229
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 ; }
234
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
241 {
82f8ea85 242 return !MacIsWindowScrollbar(child) && !((wxWindow*)m_growBox==child) &&
6762286d
SC
243 wxWindowBase::IsClientAreaChild(child);
244 }
245
246 void MacPostControlCreate(const wxPoint& pos, const wxSize& size) ;
247 wxList& GetSubcontrols() { return m_subControls; }
248
249 // translate wxWidgets coords into ones suitable
250 // to be passed to CreateControl calls
251 //
252 // returns true if non-default coords are returned, false otherwise
253 bool MacGetBoundsForControl(const wxPoint& pos,
254 const wxSize& size,
255 int& x, int& y,
256 int& w, int& h , bool adjustForOrigin ) const ;
257
258 // the 'true' OS level control for this wxWindow
d15694e8
SC
259 wxOSXWidgetImpl* GetPeer() const;
260
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();
ce63f2e9
VZ
264
265 // return true unless DontCreatePeer() had been called
266 bool ShouldCreatePeer() const;
267
d15694e8
SC
268 // sets the native implementation wrapper, can replace an existing peer, use peer = NULL to
269 // release existing peer
22756322 270 void SetPeer(wxOSXWidgetImpl* peer);
d15694e8
SC
271
272 // wraps the already existing peer with the wrapper
273 void SetWrappingPeer(wxOSXWidgetImpl* wrapper);
03647350 274
ff6893d2
VZ
275#if wxOSX_USE_COCOA_OR_IPHONE
276 // the NSView or NSWindow of this window: can be used for both child and
277 // non-owned windows
278 //
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(); }
282#endif // Cocoa
283
6762286d
SC
284 void * MacGetCGContextRef() { return m_cgContextRef ; }
285 void MacSetCGContextRef(void * cg) { m_cgContextRef = cg ; }
286
287 // osx specific event handling common for all osx-ports
03647350 288
4eb5a0ec
RR
289 virtual bool OSXHandleClicked( double timestampsec );
290 virtual bool OSXHandleKeyEvent( wxKeyEvent& event );
3af58289 291 virtual void OSXSimulateFocusEvents();
ce00f59b 292
17e2694c 293 bool IsNativeWindowWrapper() const { return m_isNativeWindowWrapper; }
f18b5ee7 294
f082dcd5 295 double GetContentScaleFactor() const ;
f18b5ee7 296
6062fe5c
JS
297 // internal response to size events
298 virtual void MacOnInternalSize() {}
299
6762286d
SC
300protected:
301 // For controls like radio buttons which are genuinely composite
302 wxList m_subControls;
303
6762286d 304 // the peer object, allowing for cleaner API support
c099b533 305
6762286d
SC
306 void * m_cgContextRef ;
307
308 // cache the clipped rectangles within the window hierarchy
309 void MacUpdateClippedRects() const ;
310
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 ;
318
6762286d
SC
319 // insets of the mac control from the wx top left corner
320 wxPoint m_macTopLeftInset ;
321 wxPoint m_macBottomRightInset ;
322 wxByte m_macAlpha ;
323
324 wxScrollBar* m_hScrollBar ;
325 wxScrollBar* m_vScrollBar ;
326 bool m_hScrollBarAlwaysShown;
327 bool m_vScrollBarAlwaysShown;
82f8ea85 328 wxWindow* m_growBox ;
6762286d 329 wxString m_label ;
ce00f59b 330
17e2694c 331 bool m_isNativeWindowWrapper;
6762286d
SC
332
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 ;
337
338 virtual bool MacIsChildOfClientArea( const wxWindow* child ) const ;
339
340 bool MacHasScrollBarCorner() const;
341 void MacCreateScrollBars( long style ) ;
342 void MacRepositionScrollBars() ;
343 void MacUpdateControlFont() ;
344
345 // implement the base class pure virtuals
6de70470
VZ
346 virtual void DoGetTextExtent(const wxString& string,
347 int *x, int *y,
348 int *descent = NULL,
349 int *externalLeading = NULL,
350 const wxFont *theFont = NULL ) const;
351
352 virtual void DoEnable( bool enable );
353#if wxUSE_MENUS
354 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
355#endif
356
357 virtual void DoFreeze();
358 virtual void DoThaw();
359
6762286d
SC
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);
371
372 virtual void DoCaptureMouse();
373 virtual void DoReleaseMouse();
374
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 );
381
382#if wxUSE_TOOLTIPS
383 virtual void DoSetToolTip( wxToolTip *tip );
5c6eb3a8 384#endif
6762286d 385
ab9a0b84
VZ
386 // common part of Show/HideWithEffect()
387 virtual bool OSXShowWithEffect(bool show,
388 wxShowEffect effect,
389 unsigned timeout);
390
6762286d 391private:
22756322 392 wxOSXWidgetImpl * m_peer ;
6762286d
SC
393 // common part of all ctors
394 void Init();
395
396 // show/hide scrollbars as needed, common part of SetScrollbar() and
397 // AlwaysShowScrollbars()
398 void DoUpdateScrollbarVisibility();
399
c0c133e1 400 wxDECLARE_NO_COPY_CLASS(wxWindowMac);
6762286d
SC
401 DECLARE_EVENT_TABLE()
402};
403
404#endif // _WX_WINDOW_H_