]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/window.h
Added a virtual wxWindow::OSXGetViewOrWindow() method.
[wxWidgets.git] / include / wx / osx / window.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/mac/carbon/window.h
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
18 class WXDLLIMPEXP_FWD_CORE wxButton;
19 class WXDLLIMPEXP_FWD_CORE wxScrollBar;
20 class WXDLLIMPEXP_FWD_CORE wxPanel;
21 class WXDLLIMPEXP_FWD_CORE wxNonOwnedWindow;
22
23 #if wxOSX_USE_CARBON
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;
29 #endif
30
31
32 class WXDLLIMPEXP_CORE wxWindowMac: public wxWindowBase
33 {
34 DECLARE_DYNAMIC_CLASS(wxWindowMac)
35
36 friend class wxDC;
37 friend class wxPaintDC;
38
39 public:
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 );
66
67 virtual bool IsShownOnScreen() const;
68
69 virtual void SetFocus();
70
71 virtual void WarpPointer( int x, int y );
72
73 virtual void Refresh( bool eraseBackground = true,
74 const wxRect *rect = NULL );
75
76 virtual void Update() ;
77 virtual void ClearBackground();
78
79 virtual bool SetCursor( const wxCursor &cursor );
80 virtual bool SetFont( const wxFont &font );
81 virtual bool SetBackgroundColour( const wxColour &colour );
82 virtual bool SetForegroundColour( const wxColour &colour );
83
84 virtual int GetCharHeight() const;
85 virtual int GetCharWidth() const;
86
87 public:
88 virtual void SetScrollbar( int orient, int pos, int thumbVisible,
89 int range, bool refresh = true );
90 virtual void SetScrollPos( int orient, int pos, bool refresh = true );
91 virtual int GetScrollPos( int orient ) const;
92 virtual int GetScrollThumb( int orient ) const;
93 virtual int GetScrollRange( int orient ) const;
94 virtual void ScrollWindow( int dx, int dy,
95 const wxRect* rect = NULL );
96 virtual void AlwaysShowScrollbars(bool horz = true, bool vert = true);
97 virtual bool IsScrollbarAlwaysShown(int orient) const
98 {
99 return orient == wxHORIZONTAL ? m_hScrollBarAlwaysShown
100 : m_vScrollBarAlwaysShown;
101 }
102
103 virtual bool Reparent( wxWindowBase *newParent );
104
105 #if wxUSE_DRAG_AND_DROP
106 virtual void SetDropTarget( wxDropTarget *dropTarget );
107 #endif
108
109 // Accept files for dragging
110 virtual void DragAcceptFiles( bool accept );
111
112 // implementation from now on
113 // --------------------------
114
115 void MacClientToRootWindow( int *x , int *y ) const;
116
117 void MacWindowToRootWindow( int *x , int *y ) const;
118
119 void MacRootWindowToWindow( int *x , int *y ) const;
120
121 virtual wxString MacGetToolTipString( wxPoint &where );
122
123 // simple accessors
124 // ----------------
125
126 virtual WXWidget GetHandle() const;
127
128 virtual bool SetTransparent(wxByte alpha);
129 virtual bool CanSetTransparent();
130 virtual wxByte GetTransparent() const ;
131
132 // event handlers
133 // --------------
134
135 void OnMouseEvent( wxMouseEvent &event );
136
137 void MacOnScroll( wxScrollEvent&event );
138
139 virtual bool AcceptsFocus() const;
140
141 virtual bool IsDoubleBuffered() const { return true; }
142
143 public:
144 static long MacRemoveBordersFromStyle( long style ) ;
145
146 public:
147 void OnInternalIdle();
148
149 // For implementation purposes:
150 // sometimes decorations make the client area smaller
151 virtual wxPoint GetClientAreaOrigin() const;
152
153 wxWindowMac *FindItem(long id) const;
154 wxWindowMac *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const;
155
156 virtual void TriggerScrollEvent( wxEventType scrollEvent ) ;
157 // this should not be overriden in classes above wxWindowMac
158 // because it is called from its destructor via DeleteChildren
159 virtual void RemoveChild( wxWindowBase *child );
160
161 virtual bool MacDoRedraw( long time ) ;
162 virtual void MacPaintChildrenBorders();
163 virtual void MacPaintBorders( int left , int top ) ;
164 void MacPaintGrowBox();
165
166 // invalidates the borders and focus area around the control;
167 // must not be virtual as it will be called during destruction
168 void MacInvalidateBorders() ;
169
170 WXWindow MacGetTopLevelWindowRef() const ;
171 wxNonOwnedWindow* MacGetTopLevelWindow() const ;
172
173 virtual long MacGetLeftBorderSize() const ;
174 virtual long MacGetRightBorderSize() const ;
175 virtual long MacGetTopBorderSize() const ;
176 virtual long MacGetBottomBorderSize() const ;
177
178 virtual void MacSuperChangedPosition() ;
179
180 // absolute coordinates of this window's root have changed
181 virtual void MacTopLevelWindowChangedPosition() ;
182
183 virtual void MacChildAdded() ;
184 virtual void MacVisibilityChanged() ;
185 virtual void MacEnabledStateChanged() ;
186 virtual void MacHiliteChanged() ;
187 virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ;
188
189 bool MacIsReallyEnabled() ;
190 bool MacIsReallyHilited() ;
191
192 #if WXWIN_COMPATIBILITY_2_8
193 bool MacIsUserPane() { return m_macIsUserPane; }
194 #endif
195 bool MacIsUserPane() const { return m_macIsUserPane; }
196
197 virtual bool MacSetupCursor( const wxPoint& pt ) ;
198
199 // return the rectangle that would be visible of this control,
200 // regardless whether controls are hidden
201 // only taking into account clipping by parent windows
202 const wxRect& MacGetClippedClientRect() const ;
203 const wxRect& MacGetClippedRect() const ;
204 const wxRect& MacGetClippedRectWithOuterStructure() const ;
205
206 // returns the visible region of this control in window ie non-client coordinates
207 const wxRegion& MacGetVisibleRegion( bool includeOuterStructures = false ) ;
208
209 // returns true if children have to clipped to the content area
210 // (e.g., scrolled windows)
211 bool MacClipChildren() const { return m_clipChildren ; }
212 void MacSetClipChildren( bool clip ) { m_clipChildren = clip ; }
213
214 // returns true if the grandchildren need to be clipped to the children's content area
215 // (e.g., splitter windows)
216 virtual bool MacClipGrandChildren() const { return false ; }
217 bool MacIsWindowScrollbar( const wxWindow* sb ) const
218 { return ((wxWindow*)m_hScrollBar == sb || (wxWindow*)m_vScrollBar == sb) ; }
219 virtual bool IsClientAreaChild(const wxWindow *child) const
220 {
221 return !MacIsWindowScrollbar(child) &&
222 wxWindowBase::IsClientAreaChild(child);
223 }
224
225 void MacPostControlCreate(const wxPoint& pos, const wxSize& size) ;
226 wxList& GetSubcontrols() { return m_subControls; }
227
228 // translate wxWidgets coords into ones suitable
229 // to be passed to CreateControl calls
230 //
231 // returns true if non-default coords are returned, false otherwise
232 bool MacGetBoundsForControl(const wxPoint& pos,
233 const wxSize& size,
234 int& x, int& y,
235 int& w, int& h , bool adjustForOrigin ) const ;
236
237 // the 'true' OS level control for this wxWindow
238 wxOSXWidgetImpl* GetPeer() const { return m_peer ; }
239
240 #if wxOSX_USE_COCOA_OR_IPHONE
241 // the NSView or NSWindow of this window: can be used for both child and
242 // non-owned windows
243 //
244 // this is useful for a few Cocoa function which can work with either views
245 // or windows indiscriminately, e.g. for setting NSViewAnimationTargetKey
246 virtual void *OSXGetViewOrWindow() const { return GetHandle(); }
247 #endif // Cocoa
248
249 void * MacGetCGContextRef() { return m_cgContextRef ; }
250 void MacSetCGContextRef(void * cg) { m_cgContextRef = cg ; }
251
252 // osx specific event handling common for all osx-ports
253
254 virtual bool OSXHandleClicked( double timestampsec );
255 virtual bool OSXHandleKeyEvent( wxKeyEvent& event );
256 protected:
257 // For controls like radio buttons which are genuinely composite
258 wxList m_subControls;
259
260 // the peer object, allowing for cleaner API support
261 wxOSXWidgetImpl * m_peer ;
262
263 void * m_cgContextRef ;
264
265 // cache the clipped rectangles within the window hierarchy
266 void MacUpdateClippedRects() const ;
267
268 mutable bool m_cachedClippedRectValid ;
269 mutable wxRect m_cachedClippedRectWithOuterStructure ;
270 mutable wxRect m_cachedClippedRect ;
271 mutable wxRect m_cachedClippedClientRect ;
272 mutable wxRegion m_cachedClippedRegionWithOuterStructure ;
273 mutable wxRegion m_cachedClippedRegion ;
274 mutable wxRegion m_cachedClippedClientRegion ;
275
276 // true if is is not a native control but a wxWindow control
277 bool m_macIsUserPane ;
278
279 // insets of the mac control from the wx top left corner
280 wxPoint m_macTopLeftInset ;
281 wxPoint m_macBottomRightInset ;
282 wxByte m_macAlpha ;
283
284 wxScrollBar* m_hScrollBar ;
285 wxScrollBar* m_vScrollBar ;
286 bool m_hScrollBarAlwaysShown;
287 bool m_vScrollBarAlwaysShown;
288 wxPanel* m_growBox ;
289 wxString m_label ;
290
291 // set to true if we do a sharp clip at the content area of this window
292 // must be dynamic as eg a panel normally is not clipping precisely, but if
293 // it becomes the target window of a scrolled window it has to...
294 bool m_clipChildren ;
295
296 virtual bool MacIsChildOfClientArea( const wxWindow* child ) const ;
297
298 bool MacHasScrollBarCorner() const;
299 void MacCreateScrollBars( long style ) ;
300 void MacRepositionScrollBars() ;
301 void MacUpdateControlFont() ;
302
303 // implement the base class pure virtuals
304 virtual void DoGetTextExtent(const wxString& string,
305 int *x, int *y,
306 int *descent = NULL,
307 int *externalLeading = NULL,
308 const wxFont *theFont = NULL ) const;
309
310 virtual void DoEnable( bool enable );
311 #if wxUSE_MENUS
312 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
313 #endif
314
315 virtual void DoFreeze();
316 virtual void DoThaw();
317
318 virtual wxSize DoGetBestSize() const;
319 virtual wxSize DoGetSizeFromClientSize( const wxSize & size ) const;
320 virtual void DoClientToScreen( int *x, int *y ) const;
321 virtual void DoScreenToClient( int *x, int *y ) const;
322 virtual void DoGetPosition( int *x, int *y ) const;
323 virtual void DoGetSize( int *width, int *height ) const;
324 virtual void DoGetClientSize( int *width, int *height ) const;
325 virtual void DoSetSize(int x, int y,
326 int width, int height,
327 int sizeFlags = wxSIZE_AUTO);
328 virtual void DoSetClientSize(int width, int height);
329
330 virtual void DoCaptureMouse();
331 virtual void DoReleaseMouse();
332
333 // move the window to the specified location and resize it: this is called
334 // from both DoSetSize() and DoSetClientSize() and would usually just call
335 // ::MoveWindow() except for composite controls which will want to arrange
336 // themselves inside the given rectangle
337 virtual void DoMoveWindow( int x, int y, int width, int height );
338 virtual void DoSetWindowVariant( wxWindowVariant variant );
339
340 #if wxUSE_TOOLTIPS
341 virtual void DoSetToolTip( wxToolTip *tip );
342 #endif
343
344 private:
345 // common part of all ctors
346 void Init();
347
348 // show/hide scrollbars as needed, common part of SetScrollbar() and
349 // AlwaysShowScrollbars()
350 void DoUpdateScrollbarVisibility();
351
352
353 wxDECLARE_NO_COPY_CLASS(wxWindowMac);
354 DECLARE_EVENT_TABLE()
355 };
356
357 #endif // _WX_WINDOW_H_