]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/window.h
fix SetUserData() to delete the correct pointer
[wxWidgets.git] / include / wx / mac / carbon / window.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 // ---------------------------------------------------------------------------
19 // forward declarations
20 // ---------------------------------------------------------------------------
21
22 class WXDLLEXPORT wxButton;
23 class WXDLLEXPORT wxScrollBar;
24 class WXDLLEXPORT wxTopLevelWindowMac;
25
26 // internal implementation classes
27
28 class wxMacControl ;
29
30 // ---------------------------------------------------------------------------
31 // constants
32 // ---------------------------------------------------------------------------
33
34 class WXDLLEXPORT wxWindowMac: public wxWindowBase
35 {
36 DECLARE_DYNAMIC_CLASS(wxWindowMac)
37
38 friend class wxDC;
39 friend class wxPaintDC;
40
41 public:
42
43 wxWindowMac() ;
44
45 wxWindowMac(wxWindowMac *parent,
46 wxWindowID id,
47 const wxPoint& pos = wxDefaultPosition,
48 const wxSize& size = wxDefaultSize,
49 long style = 0,
50 const wxString& name = wxPanelNameStr) ;
51
52 virtual ~wxWindowMac();
53
54 bool Create(wxWindowMac *parent,
55 wxWindowID id,
56 const wxPoint& pos = wxDefaultPosition,
57 const wxSize& size = wxDefaultSize,
58 long style = 0,
59 const wxString& name = wxPanelNameStr);
60
61
62 // implement base class pure virtuals
63 virtual void SetLabel( const wxString& label);
64 virtual wxString GetLabel() const;
65
66 virtual void Raise();
67 virtual void Lower();
68
69 virtual bool Show( bool show = true );
70 virtual bool Enable( bool enable = true );
71
72 virtual void SetFocus();
73
74 virtual void WarpPointer(int x, int y);
75
76 virtual void Refresh( bool eraseBackground = true,
77 const wxRect *rect = (const wxRect *) NULL );
78 virtual void Freeze() ;
79 virtual void Thaw() ;
80
81 virtual void Update() ;
82 virtual void ClearBackground() ;
83
84 virtual bool SetCursor( const wxCursor &cursor );
85 virtual bool SetFont( const wxFont &font ) ;
86 virtual bool SetBackgroundColour( const wxColour &colour );
87 virtual bool SetForegroundColour( const wxColour &colour );
88
89 virtual int GetCharHeight() const;
90 virtual int GetCharWidth() const;
91 virtual void GetTextExtent(const wxString& string,
92 int *x, int *y,
93 int *descent = (int *) NULL,
94 int *externalLeading = (int *) NULL,
95 const wxFont *theFont = (const wxFont *) NULL)
96 const;
97
98 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
99
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 = (wxRect *) NULL );
108 virtual bool Reparent( wxWindowBase *newParent );
109
110 #if wxUSE_DRAG_AND_DROP
111 virtual void SetDropTarget( wxDropTarget *dropTarget );
112 #endif // wxUSE_DRAG_AND_DROP
113
114 // Accept files for dragging
115 virtual void DragAcceptFiles(bool accept);
116
117 // implementation from now on
118 // --------------------------
119
120 void MacClientToRootWindow( int *x , int *y ) const ;
121 void MacRootWindowToClient( int *x , int *y ) const ;
122
123 void MacWindowToRootWindow( int *x , int *y ) const ;
124 void MacWindowToRootWindow( short *x , short *y ) const ;
125
126 void MacRootWindowToWindow( int *x , int *y ) const ;
127 void MacRootWindowToWindow( short *x , short *y ) const ;
128
129 virtual wxString MacGetToolTipString( wxPoint &where ) ;
130
131 // simple accessors
132 // ----------------
133
134 virtual WXWidget GetHandle() const ;
135
136 #if WXWIN_COMPATIBILITY_2_4
137 bool GetTransparentBackground() const { return m_backgroundTransparent; }
138 void SetTransparent(bool t = true) { m_backgroundTransparent = t; }
139 #endif
140
141 // event handlers
142 // --------------
143 void OnSetFocus(wxFocusEvent& event) ;
144 void OnPaint(wxPaintEvent& event);
145 void OnNcPaint(wxNcPaintEvent& event);
146 void OnEraseBackground(wxEraseEvent& event);
147 void OnMouseEvent( wxMouseEvent &event ) ;
148
149 void MacOnScroll(wxScrollEvent&event ) ;
150
151 bool AcceptsFocus() const ;
152
153 public:
154 void OnInternalIdle();
155
156 // For implementation purposes - sometimes decorations make the client area
157 // smaller
158 virtual wxPoint GetClientAreaOrigin() const;
159
160 wxWindowMac *FindItem(long id) const;
161 wxWindowMac *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const;
162
163 public:
164 virtual void MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) ;
165 virtual bool MacDoRedraw( WXHRGN updatergn , long time ) ;
166 virtual bool MacCanFocus() const ;
167
168 // this should not be overriden in classes above wxWindowMac because it is called from its destructor via DeleteChildren
169 virtual void RemoveChild( wxWindowBase *child );
170 virtual void MacPaintBorders( int left , int top ) ;
171 // invalidates the borders and focus area around the control
172 // must not be virtual as it will be called during destruction
173 void MacInvalidateBorders() ;
174 WXWindow MacGetTopLevelWindowRef() const ;
175 wxTopLevelWindowMac* MacGetTopLevelWindow() const ;
176
177 virtual long MacGetLeftBorderSize() const ;
178 virtual long MacGetRightBorderSize() const ;
179 virtual long MacGetTopBorderSize() const ;
180 virtual long MacGetBottomBorderSize() const ;
181
182 static long MacRemoveBordersFromStyle( long style ) ;
183
184 virtual void MacSuperChangedPosition() ;
185 // the absolute coortinates of this window's root have changed
186 virtual void MacTopLevelWindowChangedPosition() ;
187
188 virtual void MacChildAdded() ;
189 virtual void MacVisibilityChanged() ;
190 virtual void MacEnabledStateChanged() ;
191 virtual void MacHiliteChanged() ;
192 virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ;
193
194 bool MacIsReallyShown() ;
195 bool MacIsReallyEnabled() ;
196 bool MacIsReallyHilited() ;
197
198 bool MacIsUserPane() { return m_macIsUserPane; }
199
200 virtual bool MacSetupCursor( const wxPoint& pt ) ;
201
202 virtual void MacSetBackgroundBrush( const wxBrush &brush ) ;
203 const wxBrush& MacGetBackgroundBrush() const { return m_macBackgroundBrush ; }
204
205 // return the rectangle that would be visible of this control, regardless whether controls are hidden
206 // only taking into account clipping by parent windows
207 const wxRect& MacGetClippedClientRect() const ;
208 const wxRect& MacGetClippedRect() const ;
209 const wxRect& MacGetClippedRectWithOuterStructure() const ;
210 // returns the visible region of this control in window ie non-client coordinates
211 const wxRegion& MacGetVisibleRegion( bool includeOuterStructures = false ) ;
212 // returns true if children have to clipped to the content area (eg scrolled window)
213 bool MacClipChildren() const { return m_clipChildren ; }
214 void MacSetClipChildren( bool clip ) { m_clipChildren = clip ; }
215 // returns true if the grandchildren have to be clipped to the children's content area (eg
216 // splitter window)
217 virtual bool MacClipGrandChildren() const { return false ; }
218 bool MacIsWindowScrollbar( const wxScrollBar* sb )
219 { return (m_hScrollBar == sb || m_vScrollBar == sb) ; }
220
221 wxList& GetSubcontrols() { return m_subControls; }
222 virtual void MacInstallEventHandler(WXWidget native) ;
223 WXEVENTHANDLERREF MacGetControlEventHandler() { return m_macControlEventHandler ; }
224 void MacPostControlCreate(const wxPoint& pos, const wxSize& size) ;
225 #ifndef __WXMAC_OSX__
226 virtual void MacControlUserPaneDrawProc(wxInt16 part) ;
227 virtual wxInt16 MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) ;
228 virtual wxInt16 MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) ;
229 virtual void MacControlUserPaneIdleProc() ;
230 virtual wxInt16 MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) ;
231 virtual void MacControlUserPaneActivateProc(bool activating) ;
232 virtual wxInt16 MacControlUserPaneFocusProc(wxInt16 action) ;
233 virtual void MacControlUserPaneBackgroundProc(void* info) ;
234 #endif
235 // translate wxWidgets coords into ones suitable to be passed to
236 // the CreateControl calls
237 //
238 // returns true if non default coords are returned, false otherwise
239 bool MacGetBoundsForControl(const wxPoint& pos,
240 const wxSize& size,
241 int& x, int& y,
242 int& w, int& h , bool adjustForOrigin ) const ;
243 // calculates the real window position and size from the native control
244 void MacGetPositionAndSizeFromControl(int& x, int& y,
245 int& w, int& h) const ;
246 // gets the inset from every part
247 virtual void MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) ;
248
249 // flash the current invalid area, useful for debugging in OSX double buffered situation
250 void MacFlashInvalidAreas() ;
251
252 // the 'true' OS level control for this wxWindow
253 wxMacControl* GetPeer() const { return m_peer ; }
254 #if wxMAC_USE_CORE_GRAPHICS
255 void * MacGetCGContextRef() { return m_cgContextRef ; }
256 void MacSetCGContextRef(void * cg) { m_cgContextRef = cg ; }
257 #endif
258 protected:
259 // For controls like radiobuttons which are really composite
260 wxList m_subControls;
261 // number of calls to Freeze() minus number of calls to Thaw()
262 unsigned int m_frozenness;
263 // the peer object, allowing for cleaner API support
264 wxMacControl* m_peer ;
265 #if wxMAC_USE_CORE_GRAPHICS
266 void * m_cgContextRef ;
267 #endif
268 // cache the clipped rectangles within the window hierarchy
269 void MacUpdateClippedRects() const ;
270 mutable bool m_cachedClippedRectValid ;
271 mutable wxRect m_cachedClippedRectWithOuterStructure ;
272 mutable wxRect m_cachedClippedRect ;
273 mutable wxRect m_cachedClippedClientRect ;
274 mutable wxRegion m_cachedClippedRegionWithOuterStructure ;
275 mutable wxRegion m_cachedClippedRegion ;
276 mutable wxRegion m_cachedClippedClientRegion ;
277 // true if is is not a native control but a wxWindow control
278 bool m_macIsUserPane ;
279 wxBrush m_macBackgroundBrush ;
280 // topleft inset of the mac control from the wx top left corner
281 wxPoint m_macTopLeftInset ;
282 // bottom right inset of the mac control from the wx bottom right corner
283 wxPoint m_macBottomRightInset ;
284
285 wxScrollBar* m_hScrollBar ;
286 wxScrollBar* m_vScrollBar ;
287 wxString m_label ;
288 // returns true if we do a sharp clip at the content area of this window
289 // must be dynamic as eg a panel normally is not clipping precisely, but if
290 // it becomes the target window of a scrolled window it has to...
291 bool m_clipChildren ;
292
293 virtual bool MacIsChildOfClientArea( const wxWindow* child ) const ;
294
295 void MacCreateScrollBars( long style ) ;
296 void MacRepositionScrollBars() ;
297 void MacUpdateControlFont() ;
298
299 void MacPropagateVisibilityChanged() ;
300 void MacPropagateEnabledStateChanged() ;
301 void MacPropagateHiliteChanged() ;
302
303
304 #if WXWIN_COMPATIBILITY_2_4
305 bool m_backgroundTransparent ;
306 #endif
307
308 // implement the base class pure virtuals
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
332 #if wxUSE_TOOLTIPS
333 virtual void DoSetToolTip( wxToolTip *tip );
334 #endif // wxUSE_TOOLTIPS
335
336 private :
337
338 private:
339 // common part of all ctors
340 void Init();
341
342 WXEVENTHANDLERREF m_macControlEventHandler ;
343
344
345 DECLARE_NO_COPY_CLASS(wxWindowMac)
346 DECLARE_EVENT_TABLE()
347 };
348
349 #endif
350 // _WX_WINDOW_H_