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