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