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