]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/carbon/window.h
Cast for argument to delete[] - VC6 doesn't want to delete a const pointer
[wxWidgets.git] / include / wx / mac / carbon / window.h
CommitLineData
8cf73271 1/////////////////////////////////////////////////////////////////////////////
b156929d 2// Name: include/wx/mac/carbon/window.h
8cf73271
SC
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
65571936 9// Licence: wxWindows licence
8cf73271
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_WINDOW_H_
13#define _WX_WINDOW_H_
14
8cf73271 15#include "wx/brush.h"
20b69855 16#include "wx/dc.h"
8cf73271 17
b5dbe15d
VS
18class WXDLLIMPEXP_FWD_CORE wxButton;
19class WXDLLIMPEXP_FWD_CORE wxScrollBar;
074ec0b5 20class WXDLLIMPEXP_FWD_CORE wxNonOwnedWindow;
8cf73271 21
6954e0f6 22class WXDLLIMPEXP_FWD_CORE wxMacControl ;
6d4c54a7 23
53a2db12 24class WXDLLIMPEXP_CORE wxWindowMac: public wxWindowBase
8cf73271
SC
25{
26 DECLARE_DYNAMIC_CLASS(wxWindowMac)
fb5246be 27
8cf73271
SC
28 friend class wxDC;
29 friend class wxPaintDC;
fb5246be 30
8cf73271 31public:
b156929d 32 wxWindowMac();
fb5246be 33
b156929d 34 wxWindowMac( wxWindowMac *parent,
8cf73271
SC
35 wxWindowID id,
36 const wxPoint& pos = wxDefaultPosition,
37 const wxSize& size = wxDefaultSize,
38 long style = 0,
b156929d 39 const wxString& name = wxPanelNameStr );
8cf73271
SC
40
41 virtual ~wxWindowMac();
42
b156929d 43 bool Create( wxWindowMac *parent,
8cf73271
SC
44 wxWindowID id,
45 const wxPoint& pos = wxDefaultPosition,
46 const wxSize& size = wxDefaultSize,
47 long style = 0,
b156929d 48 const wxString& name = wxPanelNameStr );
8cf73271
SC
49
50 // implement base class pure virtuals
b156929d 51 virtual void SetLabel( const wxString& label );
fb5246be 52 virtual wxString GetLabel() const;
8cf73271
SC
53
54 virtual void Raise();
55 virtual void Lower();
56
fb5246be 57 virtual bool Show( bool show = true );
8cf73271 58
b41f2bbc
JS
59 virtual bool IsShownOnScreen() const;
60
8cf73271
SC
61 virtual void SetFocus();
62
b156929d 63 virtual void WarpPointer( int x, int y );
8cf73271 64
fb5246be 65 virtual void Refresh( bool eraseBackground = true,
b156929d 66 const wxRect *rect = NULL );
c1142003 67
cb4b0966 68 virtual void Update() ;
b156929d 69 virtual void ClearBackground();
cb4b0966 70
8cf73271 71 virtual bool SetCursor( const wxCursor &cursor );
b156929d 72 virtual bool SetFont( const wxFont &font );
4f305456
SC
73 virtual bool SetBackgroundColour( const wxColour &colour );
74 virtual bool SetForegroundColour( const wxColour &colour );
75
8cf73271
SC
76 virtual int GetCharHeight() const;
77 virtual int GetCharWidth() const;
b156929d 78 virtual void GetTextExtent( const wxString& string,
8cf73271 79 int *x, int *y,
b156929d
DS
80 int *descent = NULL,
81 int *externalLeading = NULL,
82 const wxFont *theFont = NULL )
8cf73271 83 const;
6f02a879 84protected:
4e7b25f0 85 virtual void DoEnable( bool enable );
8cf73271 86 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
c1142003 87
17808a75
VZ
88 virtual void DoFreeze();
89 virtual void DoThaw();
90
6f02a879 91public:
8cf73271 92 virtual void SetScrollbar( int orient, int pos, int thumbVisible,
fb5246be
WS
93 int range, bool refresh = true );
94 virtual void SetScrollPos( int orient, int pos, bool refresh = true );
8cf73271
SC
95 virtual int GetScrollPos( int orient ) const;
96 virtual int GetScrollThumb( int orient ) const;
97 virtual int GetScrollRange( int orient ) const;
98 virtual void ScrollWindow( int dx, int dy,
99 const wxRect* rect = (wxRect *) NULL );
c1142003
VZ
100 virtual void AlwaysShowScrollbars(bool horz = true, bool vert = true);
101 virtual bool IsScrollbarAlwaysShown(int orient) const
102 {
103 return orient == wxHORIZONTAL ? m_hScrollBarAlwaysShown
104 : m_vScrollBarAlwaysShown;
105 }
106
50779e06 107 virtual bool Reparent( wxWindowBase *newParent );
8cf73271
SC
108
109#if wxUSE_DRAG_AND_DROP
110 virtual void SetDropTarget( wxDropTarget *dropTarget );
b156929d 111#endif
8cf73271
SC
112
113 // Accept files for dragging
b156929d 114 virtual void DragAcceptFiles( bool accept );
8cf73271 115
8cf73271
SC
116 // implementation from now on
117 // --------------------------
118
b156929d
DS
119 void MacClientToRootWindow( int *x , int *y ) const;
120 void MacRootWindowToClient( int *x , int *y ) const;
4f305456 121
b156929d
DS
122 void MacWindowToRootWindow( int *x , int *y ) const;
123 void MacWindowToRootWindow( short *x , short *y ) const;
4f305456 124
b156929d
DS
125 void MacRootWindowToWindow( int *x , int *y ) const;
126 void MacRootWindowToWindow( short *x , short *y ) const;
fb5246be 127
b156929d 128 virtual wxString MacGetToolTipString( wxPoint &where );
8cf73271
SC
129
130 // simple accessors
131 // ----------------
132
b156929d 133 virtual WXWidget GetHandle() const;
8cf73271 134
29a7b4d0
SC
135 virtual bool SetTransparent(wxByte alpha);
136 virtual bool CanSetTransparent();
137 virtual wxByte GetTransparent() const ;
c1142003 138
8cf73271
SC
139 // event handlers
140 // --------------
b156929d
DS
141 void OnPaint( wxPaintEvent& event );
142 void OnNcPaint( wxNcPaintEvent& event );
143 void OnEraseBackground(wxEraseEvent& event );
144 void OnMouseEvent( wxMouseEvent &event );
8cf73271 145
b156929d 146 void MacOnScroll( wxScrollEvent&event );
fb5246be 147
ebf2a1ec 148 virtual bool AcceptsFocus() const;
b156929d 149
2e992e06
VZ
150 virtual bool IsDoubleBuffered() const { return true; }
151
b156929d
DS
152public:
153 static long MacRemoveBordersFromStyle( long style ) ;
8cf73271
SC
154
155public:
156 void OnInternalIdle();
157
b156929d
DS
158 // For implementation purposes:
159 // sometimes decorations make the client area smaller
8cf73271
SC
160 virtual wxPoint GetClientAreaOrigin() const;
161
162 wxWindowMac *FindItem(long id) const;
fb5246be 163 wxWindowMac *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const;
8cf73271 164
4f305456 165 virtual void MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) ;
7f801f85 166 virtual bool MacDoRedraw( void* updatergn , long time ) ;
4f305456 167 virtual bool MacCanFocus() const ;
fb5246be 168
b156929d
DS
169 // this should not be overriden in classes above wxWindowMac
170 // because it is called from its destructor via DeleteChildren
4f305456
SC
171 virtual void RemoveChild( wxWindowBase *child );
172 virtual void MacPaintBorders( int left , int top ) ;
ebf2a1ec 173 void MacPaintGrowBox();
b156929d
DS
174
175 // invalidates the borders and focus area around the control;
e2f865d8
SC
176 // must not be virtual as it will be called during destruction
177 void MacInvalidateBorders() ;
b156929d
DS
178
179 WXWindow MacGetTopLevelWindowRef() const ;
074ec0b5 180 wxNonOwnedWindow* MacGetTopLevelWindow() const ;
fb5246be 181
4f305456
SC
182 virtual long MacGetLeftBorderSize() const ;
183 virtual long MacGetRightBorderSize() const ;
184 virtual long MacGetTopBorderSize() const ;
185 virtual long MacGetBottomBorderSize() const ;
fb5246be 186
4f305456 187 virtual void MacSuperChangedPosition() ;
b156929d
DS
188
189 // absolute coordinates of this window's root have changed
4f305456 190 virtual void MacTopLevelWindowChangedPosition() ;
fb5246be 191
08422003 192 virtual void MacChildAdded() ;
4f305456
SC
193 virtual void MacVisibilityChanged() ;
194 virtual void MacEnabledStateChanged() ;
8ab50549 195 virtual void MacHiliteChanged() ;
336a6aba 196 virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ;
fb5246be 197
4f305456 198 bool MacIsReallyEnabled() ;
8ab50549 199 bool MacIsReallyHilited() ;
fb5246be
WS
200
201 bool MacIsUserPane() { return m_macIsUserPane; }
4f305456 202
4f305456 203 virtual bool MacSetupCursor( const wxPoint& pt ) ;
fb5246be 204
b156929d
DS
205 // return the rectangle that would be visible of this control,
206 // regardless whether controls are hidden
a45ff297 207 // only taking into account clipping by parent windows
78df41df 208 const wxRect& MacGetClippedClientRect() const ;
a45ff297
SC
209 const wxRect& MacGetClippedRect() const ;
210 const wxRect& MacGetClippedRectWithOuterStructure() const ;
b156929d 211
4f305456 212 // returns the visible region of this control in window ie non-client coordinates
a45ff297 213 const wxRegion& MacGetVisibleRegion( bool includeOuterStructures = false ) ;
b156929d
DS
214
215 // returns true if children have to clipped to the content area
216 // (e.g., scrolled windows)
fb5246be 217 bool MacClipChildren() const { return m_clipChildren ; }
8adc196b 218 void MacSetClipChildren( bool clip ) { m_clipChildren = clip ; }
b156929d
DS
219
220 // returns true if the grandchildren need to be clipped to the children's content area
221 // (e.g., splitter windows)
fb5246be 222 virtual bool MacClipGrandChildren() const { return false ; }
049908c5 223 bool MacIsWindowScrollbar( const wxWindow* sb ) const
31e1bd37 224 { return ((wxWindow*)m_hScrollBar == sb || (wxWindow*)m_vScrollBar == sb) ; }
049908c5
VS
225 virtual bool IsClientAreaChild(const wxWindow *child) const
226 {
227 return !MacIsWindowScrollbar(child) &&
228 wxWindowBase::IsClientAreaChild(child);
229 }
4f305456 230
fb5246be 231 virtual void MacInstallEventHandler(WXWidget native) ;
4f305456 232 void MacPostControlCreate(const wxPoint& pos, const wxSize& size) ;
b156929d
DS
233 wxList& GetSubcontrols() { return m_subControls; }
234 WXEVENTHANDLERREF MacGetControlEventHandler() { return m_macControlEventHandler ; }
235
b156929d
DS
236 // translate wxWidgets coords into ones suitable
237 // to be passed to CreateControl calls
4f305456 238 //
b156929d 239 // returns true if non-default coords are returned, false otherwise
4f305456
SC
240 bool MacGetBoundsForControl(const wxPoint& pos,
241 const wxSize& size,
242 int& x, int& y,
79392158 243 int& w, int& h , bool adjustForOrigin ) const ;
b156929d 244
4f305456
SC
245 // calculates the real window position and size from the native control
246 void MacGetPositionAndSizeFromControl(int& x, int& y,
247 int& w, int& h) const ;
b156929d 248
f5ea731f
SC
249 // gets the inset from every part
250 virtual void MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) ;
251
b156929d
DS
252 // visibly flash the current invalid area:
253 // useful for debugging in OSX composited (double-buffered) situation
8d4c4868 254 void MacFlashInvalidAreas() ;
e2f865d8
SC
255
256 // the 'true' OS level control for this wxWindow
257 wxMacControl* GetPeer() const { return m_peer ; }
b156929d 258
20b69855
SC
259 void * MacGetCGContextRef() { return m_cgContextRef ; }
260 void MacSetCGContextRef(void * cg) { m_cgContextRef = cg ; }
b156929d 261
8cf73271 262protected:
b156929d 263 // For controls like radio buttons which are genuinely composite
4f305456 264 wxList m_subControls;
b156929d 265
6d4c54a7 266 // the peer object, allowing for cleaner API support
b156929d
DS
267 wxMacControl * m_peer ;
268
20b69855 269 void * m_cgContextRef ;
b156929d 270
a45ff297
SC
271 // cache the clipped rectangles within the window hierarchy
272 void MacUpdateClippedRects() const ;
b156929d 273
a45ff297
SC
274 mutable bool m_cachedClippedRectValid ;
275 mutable wxRect m_cachedClippedRectWithOuterStructure ;
276 mutable wxRect m_cachedClippedRect ;
78df41df 277 mutable wxRect m_cachedClippedClientRect ;
a45ff297
SC
278 mutable wxRegion m_cachedClippedRegionWithOuterStructure ;
279 mutable wxRegion m_cachedClippedRegion ;
78df41df 280 mutable wxRegion m_cachedClippedClientRegion ;
b156929d 281
ed8a0852 282 // true if is is not a native control but a wxWindow control
fb5246be 283 bool m_macIsUserPane ;
b156929d
DS
284
285 // insets of the mac control from the wx top left corner
ed8a0852 286 wxPoint m_macTopLeftInset ;
ed8a0852 287 wxPoint m_macBottomRightInset ;
29a7b4d0 288 wxByte m_macAlpha ;
fb5246be 289
4f305456
SC
290 wxScrollBar* m_hScrollBar ;
291 wxScrollBar* m_vScrollBar ;
c1142003
VZ
292 bool m_hScrollBarAlwaysShown;
293 bool m_vScrollBarAlwaysShown;
4f305456 294 wxString m_label ;
b156929d
DS
295
296 // set to true if we do a sharp clip at the content area of this window
8adc196b
SC
297 // must be dynamic as eg a panel normally is not clipping precisely, but if
298 // it becomes the target window of a scrolled window it has to...
299 bool m_clipChildren ;
fb5246be 300
78df41df 301 virtual bool MacIsChildOfClientArea( const wxWindow* child ) const ;
fb5246be 302
ebf2a1ec 303 bool MacHasScrollBarCorner() const;
4f305456
SC
304 void MacCreateScrollBars( long style ) ;
305 void MacRepositionScrollBars() ;
306 void MacUpdateControlFont() ;
8ab50549 307
8cf73271 308 // implement the base class pure virtuals
fb5246be
WS
309 virtual wxSize DoGetBestSize() const;
310 virtual wxSize DoGetSizeFromClientSize( const wxSize & size ) const;
8cf73271
SC
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
b156929d
DS
328 virtual void DoMoveWindow( int x, int y, int width, int height );
329 virtual void DoSetWindowVariant( wxWindowVariant variant );
8cf73271
SC
330
331#if wxUSE_TOOLTIPS
332 virtual void DoSetToolTip( wxToolTip *tip );
b156929d 333#endif
4f305456 334
8cf73271
SC
335private:
336 // common part of all ctors
337 void Init();
338
c1142003
VZ
339 // show/hide scrollbars as needed, common part of SetScrollbar() and
340 // AlwaysShowScrollbars()
341 void DoUpdateScrollbarVisibility();
342
343
4f305456
SC
344 WXEVENTHANDLERREF m_macControlEventHandler ;
345
8cf73271
SC
346 DECLARE_NO_COPY_CLASS(wxWindowMac)
347 DECLARE_EVENT_TABLE()
348};
349
b156929d 350#endif // _WX_WINDOW_H_