]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/window.h
Don't use deprecated NSTableView selectRow:byExtendingSelection: method.
[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 // 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 bool SetBackgroundStyle(wxBackgroundStyle style);
95
96 virtual int GetCharHeight() const;
97 virtual int GetCharWidth() const;
98
99 public:
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,
107 const wxRect* rect = NULL );
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 // --------------
146
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
155 public:
156 static long MacRemoveBordersFromStyle( long style ) ;
157
158 public:
159 void OnInternalIdle();
160
161 // For implementation purposes:
162 // sometimes decorations make the client area smaller
163 virtual wxPoint GetClientAreaOrigin() const;
164
165 wxWindowMac *FindItem(long id) const;
166 wxWindowMac *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const;
167
168 virtual void TriggerScrollEvent( wxEventType scrollEvent ) ;
169 // this should not be overriden in classes above wxWindowMac
170 // because it is called from its destructor via DeleteChildren
171 virtual void RemoveChild( wxWindowBase *child );
172
173 virtual bool MacDoRedraw( long time ) ;
174 virtual void MacPaintChildrenBorders();
175 virtual void MacPaintBorders( int left , int top ) ;
176 void MacPaintGrowBox();
177
178 // invalidates the borders and focus area around the control;
179 // must not be virtual as it will be called during destruction
180 void MacInvalidateBorders() ;
181
182 WXWindow MacGetTopLevelWindowRef() const ;
183 wxNonOwnedWindow* MacGetTopLevelWindow() const ;
184
185 virtual long MacGetWXBorderSize() const;
186 virtual long MacGetLeftBorderSize() const ;
187 virtual long MacGetRightBorderSize() const ;
188 virtual long MacGetTopBorderSize() const ;
189 virtual long MacGetBottomBorderSize() const ;
190
191 virtual void MacSuperChangedPosition() ;
192
193 // absolute coordinates of this window's root have changed
194 virtual void MacTopLevelWindowChangedPosition() ;
195
196 virtual void MacChildAdded() ;
197 virtual void MacVisibilityChanged() ;
198 virtual void MacEnabledStateChanged() ;
199 virtual void MacHiliteChanged() ;
200 virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ;
201
202 bool MacIsReallyEnabled() ;
203 bool MacIsReallyHilited() ;
204
205 #if WXWIN_COMPATIBILITY_2_8
206 bool MacIsUserPane() { return m_macIsUserPane; }
207 #endif
208 bool MacIsUserPane() const { return m_macIsUserPane; }
209
210 virtual bool MacSetupCursor( const wxPoint& pt ) ;
211
212 // return the rectangle that would be visible of this control,
213 // regardless whether controls are hidden
214 // only taking into account clipping by parent windows
215 const wxRect& MacGetClippedClientRect() const ;
216 const wxRect& MacGetClippedRect() const ;
217 const wxRect& MacGetClippedRectWithOuterStructure() const ;
218
219 // returns the visible region of this control in window ie non-client coordinates
220 const wxRegion& MacGetVisibleRegion( bool includeOuterStructures = false ) ;
221
222 // returns true if children have to clipped to the content area
223 // (e.g., scrolled windows)
224 bool MacClipChildren() const { return m_clipChildren ; }
225 void MacSetClipChildren( bool clip ) { m_clipChildren = clip ; }
226
227 // returns true if the grandchildren need to be clipped to the children's content area
228 // (e.g., splitter windows)
229 virtual bool MacClipGrandChildren() const { return false ; }
230 bool MacIsWindowScrollbar( const wxWindow* sb ) const
231 { return ((wxWindow*)m_hScrollBar == sb || (wxWindow*)m_vScrollBar == sb) ; }
232 virtual bool IsClientAreaChild(const wxWindow *child) const
233 {
234 return !MacIsWindowScrollbar(child) && !((wxWindow*)m_growBox==child) &&
235 wxWindowBase::IsClientAreaChild(child);
236 }
237
238 void MacPostControlCreate(const wxPoint& pos, const wxSize& size) ;
239 wxList& GetSubcontrols() { return m_subControls; }
240
241 // translate wxWidgets coords into ones suitable
242 // to be passed to CreateControl calls
243 //
244 // returns true if non-default coords are returned, false otherwise
245 bool MacGetBoundsForControl(const wxPoint& pos,
246 const wxSize& size,
247 int& x, int& y,
248 int& w, int& h , bool adjustForOrigin ) const ;
249
250 // the 'true' OS level control for this wxWindow
251 wxOSXWidgetImpl* GetPeer() const { return m_peer ; }
252
253 #if wxOSX_USE_COCOA_OR_IPHONE
254 // the NSView or NSWindow of this window: can be used for both child and
255 // non-owned windows
256 //
257 // this is useful for a few Cocoa function which can work with either views
258 // or windows indiscriminately, e.g. for setting NSViewAnimationTargetKey
259 virtual void *OSXGetViewOrWindow() const { return GetHandle(); }
260 #endif // Cocoa
261
262 void * MacGetCGContextRef() { return m_cgContextRef ; }
263 void MacSetCGContextRef(void * cg) { m_cgContextRef = cg ; }
264
265 // osx specific event handling common for all osx-ports
266
267 virtual bool OSXHandleClicked( double timestampsec );
268 virtual bool OSXHandleKeyEvent( wxKeyEvent& event );
269
270 bool IsNativeWindowWrapper() const { return m_isNativeWindowWrapper; }
271 protected:
272 // For controls like radio buttons which are genuinely composite
273 wxList m_subControls;
274
275 // the peer object, allowing for cleaner API support
276 wxOSXWidgetImpl * m_peer ;
277
278 void * m_cgContextRef ;
279
280 // cache the clipped rectangles within the window hierarchy
281 void MacUpdateClippedRects() const ;
282
283 mutable bool m_cachedClippedRectValid ;
284 mutable wxRect m_cachedClippedRectWithOuterStructure ;
285 mutable wxRect m_cachedClippedRect ;
286 mutable wxRect m_cachedClippedClientRect ;
287 mutable wxRegion m_cachedClippedRegionWithOuterStructure ;
288 mutable wxRegion m_cachedClippedRegion ;
289 mutable wxRegion m_cachedClippedClientRegion ;
290
291 // true if is is not a native control but a wxWindow control
292 bool m_macIsUserPane ;
293
294 // insets of the mac control from the wx top left corner
295 wxPoint m_macTopLeftInset ;
296 wxPoint m_macBottomRightInset ;
297 wxByte m_macAlpha ;
298
299 wxScrollBar* m_hScrollBar ;
300 wxScrollBar* m_vScrollBar ;
301 bool m_hScrollBarAlwaysShown;
302 bool m_vScrollBarAlwaysShown;
303 wxWindow* m_growBox ;
304 wxString m_label ;
305
306 bool m_isNativeWindowWrapper;
307
308 // set to true if we do a sharp clip at the content area of this window
309 // must be dynamic as eg a panel normally is not clipping precisely, but if
310 // it becomes the target window of a scrolled window it has to...
311 bool m_clipChildren ;
312
313 virtual bool MacIsChildOfClientArea( const wxWindow* child ) const ;
314
315 bool MacHasScrollBarCorner() const;
316 void MacCreateScrollBars( long style ) ;
317 void MacRepositionScrollBars() ;
318 void MacUpdateControlFont() ;
319
320 // implement the base class pure virtuals
321 virtual void DoGetTextExtent(const wxString& string,
322 int *x, int *y,
323 int *descent = NULL,
324 int *externalLeading = NULL,
325 const wxFont *theFont = NULL ) const;
326
327 virtual void DoEnable( bool enable );
328 #if wxUSE_MENUS
329 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
330 #endif
331
332 virtual void DoFreeze();
333 virtual void DoThaw();
334
335 virtual wxSize DoGetBestSize() const;
336 virtual wxSize DoGetSizeFromClientSize( const wxSize & size ) const;
337 virtual void DoClientToScreen( int *x, int *y ) const;
338 virtual void DoScreenToClient( int *x, int *y ) const;
339 virtual void DoGetPosition( int *x, int *y ) const;
340 virtual void DoGetSize( int *width, int *height ) const;
341 virtual void DoGetClientSize( int *width, int *height ) const;
342 virtual void DoSetSize(int x, int y,
343 int width, int height,
344 int sizeFlags = wxSIZE_AUTO);
345 virtual void DoSetClientSize(int width, int height);
346
347 virtual void DoCaptureMouse();
348 virtual void DoReleaseMouse();
349
350 // move the window to the specified location and resize it: this is called
351 // from both DoSetSize() and DoSetClientSize() and would usually just call
352 // ::MoveWindow() except for composite controls which will want to arrange
353 // themselves inside the given rectangle
354 virtual void DoMoveWindow( int x, int y, int width, int height );
355 virtual void DoSetWindowVariant( wxWindowVariant variant );
356
357 #if wxUSE_TOOLTIPS
358 virtual void DoSetToolTip( wxToolTip *tip );
359 #endif
360
361 // common part of Show/HideWithEffect()
362 virtual bool OSXShowWithEffect(bool show,
363 wxShowEffect effect,
364 unsigned timeout);
365
366 private:
367 // common part of all ctors
368 void Init();
369
370 // show/hide scrollbars as needed, common part of SetScrollbar() and
371 // AlwaysShowScrollbars()
372 void DoUpdateScrollbarVisibility();
373
374 wxDECLARE_NO_COPY_CLASS(wxWindowMac);
375 DECLARE_EVENT_TABLE()
376 };
377
378 #endif // _WX_WINDOW_H_