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