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