]> git.saurik.com Git - wxWidgets.git/blame - include/wx/osx/window.h
Instead of just deleting m_popupInterface, call Destroy() of its wxWindow-based popup...
[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
58 // implement base class pure virtuals
59 virtual void SetLabel( const wxString& label );
60 virtual wxString GetLabel() const;
61
62 virtual void Raise();
63 virtual void Lower();
64
65 virtual bool Show( bool show = true );
ab9a0b84
VZ
66 virtual bool ShowWithEffect(wxShowEffect effect,
67 unsigned timeout = 0)
68 {
69 return OSXShowWithEffect(true, effect, timeout);
70 }
71 virtual bool HideWithEffect(wxShowEffect effect,
72 unsigned timeout = 0)
73 {
74 return OSXShowWithEffect(false, effect, timeout);
75 }
6762286d
SC
76
77 virtual bool IsShownOnScreen() const;
78
79 virtual void SetFocus();
80
81 virtual void WarpPointer( int x, int y );
82
83 virtual void Refresh( bool eraseBackground = true,
84 const wxRect *rect = NULL );
85
86 virtual void Update() ;
87 virtual void ClearBackground();
88
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 );
93
bc5c09a3
SC
94 virtual bool SetBackgroundStyle(wxBackgroundStyle style);
95
6762286d
SC
96 virtual int GetCharHeight() const;
97 virtual int GetCharWidth() const;
6762286d
SC
98
99public:
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,
d3b9f782 107 const wxRect* rect = NULL );
6762286d
SC
108 virtual void AlwaysShowScrollbars(bool horz = true, bool vert = true);
109 virtual bool IsScrollbarAlwaysShown(int orient) const
110 {
111 return orient == wxHORIZONTAL ? m_hScrollBarAlwaysShown
112 : m_vScrollBarAlwaysShown;
113 }
114
115 virtual bool Reparent( wxWindowBase *newParent );
116
117#if wxUSE_DRAG_AND_DROP
118 virtual void SetDropTarget( wxDropTarget *dropTarget );
119#endif
120
121 // Accept files for dragging
122 virtual void DragAcceptFiles( bool accept );
123
124 // implementation from now on
125 // --------------------------
126
127 void MacClientToRootWindow( int *x , int *y ) const;
128
129 void MacWindowToRootWindow( int *x , int *y ) const;
130
131 void MacRootWindowToWindow( int *x , int *y ) const;
132
133 virtual wxString MacGetToolTipString( wxPoint &where );
134
135 // simple accessors
136 // ----------------
137
138 virtual WXWidget GetHandle() const;
139
140 virtual bool SetTransparent(wxByte alpha);
141 virtual bool CanSetTransparent();
142 virtual wxByte GetTransparent() const ;
143
144 // event handlers
145 // --------------
4dd9fdf8 146
6762286d
SC
147 void OnMouseEvent( wxMouseEvent &event );
148
149 void MacOnScroll( wxScrollEvent&event );
150
151 virtual bool AcceptsFocus() const;
152
153 virtual bool IsDoubleBuffered() const { return true; }
154
155public:
156 static long MacRemoveBordersFromStyle( long style ) ;
157
158public:
6762286d
SC
159 // For implementation purposes:
160 // sometimes decorations make the client area smaller
161 virtual wxPoint GetClientAreaOrigin() const;
162
163 wxWindowMac *FindItem(long id) const;
164 wxWindowMac *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const;
165
19c7ac3d 166 virtual void TriggerScrollEvent( wxEventType scrollEvent ) ;
4c51a665 167 // this should not be overridden in classes above wxWindowMac
6762286d
SC
168 // because it is called from its destructor via DeleteChildren
169 virtual void RemoveChild( wxWindowBase *child );
03647350 170
5398a2e0
SC
171 virtual bool MacDoRedraw( long time ) ;
172 virtual void MacPaintChildrenBorders();
6762286d
SC
173 virtual void MacPaintBorders( int left , int top ) ;
174 void MacPaintGrowBox();
175
176 // invalidates the borders and focus area around the control;
177 // must not be virtual as it will be called during destruction
178 void MacInvalidateBorders() ;
179
180 WXWindow MacGetTopLevelWindowRef() const ;
181 wxNonOwnedWindow* MacGetTopLevelWindow() const ;
182
54ea2834 183 virtual long MacGetWXBorderSize() const;
6762286d
SC
184 virtual long MacGetLeftBorderSize() const ;
185 virtual long MacGetRightBorderSize() const ;
186 virtual long MacGetTopBorderSize() const ;
187 virtual long MacGetBottomBorderSize() const ;
188
189 virtual void MacSuperChangedPosition() ;
190
191 // absolute coordinates of this window's root have changed
192 virtual void MacTopLevelWindowChangedPosition() ;
193
194 virtual void MacChildAdded() ;
195 virtual void MacVisibilityChanged() ;
196 virtual void MacEnabledStateChanged() ;
197 virtual void MacHiliteChanged() ;
198 virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ;
199
200 bool MacIsReallyEnabled() ;
201 bool MacIsReallyHilited() ;
202
938fbc8f 203#if WXWIN_COMPATIBILITY_2_8
d15694e8 204 bool MacIsUserPane();
938fbc8f 205#endif
d15694e8 206 bool MacIsUserPane() const;
6762286d
SC
207
208 virtual bool MacSetupCursor( const wxPoint& pt ) ;
209
210 // return the rectangle that would be visible of this control,
211 // regardless whether controls are hidden
212 // only taking into account clipping by parent windows
213 const wxRect& MacGetClippedClientRect() const ;
214 const wxRect& MacGetClippedRect() const ;
215 const wxRect& MacGetClippedRectWithOuterStructure() const ;
216
217 // returns the visible region of this control in window ie non-client coordinates
218 const wxRegion& MacGetVisibleRegion( bool includeOuterStructures = false ) ;
219
220 // returns true if children have to clipped to the content area
221 // (e.g., scrolled windows)
222 bool MacClipChildren() const { return m_clipChildren ; }
223 void MacSetClipChildren( bool clip ) { m_clipChildren = clip ; }
224
225 // returns true if the grandchildren need to be clipped to the children's content area
226 // (e.g., splitter windows)
227 virtual bool MacClipGrandChildren() const { return false ; }
228 bool MacIsWindowScrollbar( const wxWindow* sb ) const
229 { return ((wxWindow*)m_hScrollBar == sb || (wxWindow*)m_vScrollBar == sb) ; }
230 virtual bool IsClientAreaChild(const wxWindow *child) const
231 {
82f8ea85 232 return !MacIsWindowScrollbar(child) && !((wxWindow*)m_growBox==child) &&
6762286d
SC
233 wxWindowBase::IsClientAreaChild(child);
234 }
235
236 void MacPostControlCreate(const wxPoint& pos, const wxSize& size) ;
237 wxList& GetSubcontrols() { return m_subControls; }
238
239 // translate wxWidgets coords into ones suitable
240 // to be passed to CreateControl calls
241 //
242 // returns true if non-default coords are returned, false otherwise
243 bool MacGetBoundsForControl(const wxPoint& pos,
244 const wxSize& size,
245 int& x, int& y,
246 int& w, int& h , bool adjustForOrigin ) const ;
247
248 // the 'true' OS level control for this wxWindow
d15694e8
SC
249 wxOSXWidgetImpl* GetPeer() const;
250
251 // optimization to avoid creating a user pane in wxWindow::Create if we already know
252 // we will replace it with our own peer
253 void DontCreatePeer();
254
255 // sets the native implementation wrapper, can replace an existing peer, use peer = NULL to
256 // release existing peer
22756322 257 void SetPeer(wxOSXWidgetImpl* peer);
d15694e8
SC
258
259 // wraps the already existing peer with the wrapper
260 void SetWrappingPeer(wxOSXWidgetImpl* wrapper);
03647350 261
ff6893d2
VZ
262#if wxOSX_USE_COCOA_OR_IPHONE
263 // the NSView or NSWindow of this window: can be used for both child and
264 // non-owned windows
265 //
266 // this is useful for a few Cocoa function which can work with either views
267 // or windows indiscriminately, e.g. for setting NSViewAnimationTargetKey
268 virtual void *OSXGetViewOrWindow() const { return GetHandle(); }
269#endif // Cocoa
270
6762286d
SC
271 void * MacGetCGContextRef() { return m_cgContextRef ; }
272 void MacSetCGContextRef(void * cg) { m_cgContextRef = cg ; }
273
274 // osx specific event handling common for all osx-ports
03647350 275
4eb5a0ec
RR
276 virtual bool OSXHandleClicked( double timestampsec );
277 virtual bool OSXHandleKeyEvent( wxKeyEvent& event );
ce00f59b 278
17e2694c 279 bool IsNativeWindowWrapper() const { return m_isNativeWindowWrapper; }
f18b5ee7
SC
280
281 float GetContentScaleFactor() const ;
282
6762286d
SC
283protected:
284 // For controls like radio buttons which are genuinely composite
285 wxList m_subControls;
286
6762286d 287 // the peer object, allowing for cleaner API support
c099b533 288
6762286d
SC
289 void * m_cgContextRef ;
290
291 // cache the clipped rectangles within the window hierarchy
292 void MacUpdateClippedRects() const ;
293
294 mutable bool m_cachedClippedRectValid ;
295 mutable wxRect m_cachedClippedRectWithOuterStructure ;
296 mutable wxRect m_cachedClippedRect ;
297 mutable wxRect m_cachedClippedClientRect ;
298 mutable wxRegion m_cachedClippedRegionWithOuterStructure ;
299 mutable wxRegion m_cachedClippedRegion ;
300 mutable wxRegion m_cachedClippedClientRegion ;
301
6762286d
SC
302 // insets of the mac control from the wx top left corner
303 wxPoint m_macTopLeftInset ;
304 wxPoint m_macBottomRightInset ;
305 wxByte m_macAlpha ;
306
307 wxScrollBar* m_hScrollBar ;
308 wxScrollBar* m_vScrollBar ;
309 bool m_hScrollBarAlwaysShown;
310 bool m_vScrollBarAlwaysShown;
82f8ea85 311 wxWindow* m_growBox ;
6762286d 312 wxString m_label ;
ce00f59b 313
17e2694c 314 bool m_isNativeWindowWrapper;
6762286d
SC
315
316 // set to true if we do a sharp clip at the content area of this window
317 // must be dynamic as eg a panel normally is not clipping precisely, but if
318 // it becomes the target window of a scrolled window it has to...
319 bool m_clipChildren ;
320
321 virtual bool MacIsChildOfClientArea( const wxWindow* child ) const ;
322
323 bool MacHasScrollBarCorner() const;
324 void MacCreateScrollBars( long style ) ;
325 void MacRepositionScrollBars() ;
326 void MacUpdateControlFont() ;
327
328 // implement the base class pure virtuals
6de70470
VZ
329 virtual void DoGetTextExtent(const wxString& string,
330 int *x, int *y,
331 int *descent = NULL,
332 int *externalLeading = NULL,
333 const wxFont *theFont = NULL ) const;
334
335 virtual void DoEnable( bool enable );
336#if wxUSE_MENUS
337 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
338#endif
339
340 virtual void DoFreeze();
341 virtual void DoThaw();
342
6762286d
SC
343 virtual wxSize DoGetBestSize() const;
344 virtual wxSize DoGetSizeFromClientSize( const wxSize & size ) const;
345 virtual void DoClientToScreen( int *x, int *y ) const;
346 virtual void DoScreenToClient( int *x, int *y ) const;
347 virtual void DoGetPosition( int *x, int *y ) const;
348 virtual void DoGetSize( int *width, int *height ) const;
349 virtual void DoGetClientSize( int *width, int *height ) const;
350 virtual void DoSetSize(int x, int y,
351 int width, int height,
352 int sizeFlags = wxSIZE_AUTO);
353 virtual void DoSetClientSize(int width, int height);
354
355 virtual void DoCaptureMouse();
356 virtual void DoReleaseMouse();
357
358 // move the window to the specified location and resize it: this is called
359 // from both DoSetSize() and DoSetClientSize() and would usually just call
360 // ::MoveWindow() except for composite controls which will want to arrange
361 // themselves inside the given rectangle
362 virtual void DoMoveWindow( int x, int y, int width, int height );
363 virtual void DoSetWindowVariant( wxWindowVariant variant );
364
365#if wxUSE_TOOLTIPS
366 virtual void DoSetToolTip( wxToolTip *tip );
5c6eb3a8 367#endif
6762286d 368
ab9a0b84
VZ
369 // common part of Show/HideWithEffect()
370 virtual bool OSXShowWithEffect(bool show,
371 wxShowEffect effect,
372 unsigned timeout);
373
6762286d 374private:
22756322 375 wxOSXWidgetImpl * m_peer ;
6762286d
SC
376 // common part of all ctors
377 void Init();
378
379 // show/hide scrollbars as needed, common part of SetScrollbar() and
380 // AlwaysShowScrollbars()
381 void DoUpdateScrollbarVisibility();
382
c0c133e1 383 wxDECLARE_NO_COPY_CLASS(wxWindowMac);
6762286d
SC
384 DECLARE_EVENT_TABLE()
385};
386
387#endif // _WX_WINDOW_H_