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