]> git.saurik.com Git - wxWidgets.git/blob - include/wx/osx/carbon/window.h
osx regrouping
[wxWidgets.git] / include / wx / osx / 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 WXDLLIMPEXP_FWD_CORE wxButton;
19 class WXDLLIMPEXP_FWD_CORE wxScrollBar;
20 class WXDLLIMPEXP_FWD_CORE wxNonOwnedWindow;
21
22 class WXDLLIMPEXP_FWD_CORE wxMacControl ;
23 class WXDLLIMPEXP_FWD_CORE wxWidgetImpl ;
24
25 class WXDLLIMPEXP_CORE wxWindowMac: public wxWindowBase
26 {
27 DECLARE_DYNAMIC_CLASS(wxWindowMac)
28
29 friend class wxDC;
30 friend class wxPaintDC;
31
32 public:
33 wxWindowMac();
34
35 wxWindowMac( wxWindowMac *parent,
36 wxWindowID id,
37 const wxPoint& pos = wxDefaultPosition,
38 const wxSize& size = wxDefaultSize,
39 long style = 0,
40 const wxString& name = wxPanelNameStr );
41
42 virtual ~wxWindowMac();
43
44 bool Create( wxWindowMac *parent,
45 wxWindowID id,
46 const wxPoint& pos = wxDefaultPosition,
47 const wxSize& size = wxDefaultSize,
48 long style = 0,
49 const wxString& name = wxPanelNameStr );
50
51 // implement base class pure virtuals
52 virtual void SetLabel( const wxString& label );
53 virtual wxString GetLabel() const;
54
55 virtual void Raise();
56 virtual void Lower();
57
58 virtual bool Show( bool show = true );
59
60 virtual bool IsShownOnScreen() const;
61
62 virtual void SetFocus();
63
64 virtual void WarpPointer( int x, int y );
65
66 virtual void Refresh( bool eraseBackground = true,
67 const wxRect *rect = NULL );
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 void DoEnable( bool enable );
87 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
88
89 virtual void DoFreeze();
90 virtual void DoThaw();
91
92 public:
93 virtual void SetScrollbar( int orient, int pos, int thumbVisible,
94 int range, bool refresh = true );
95 virtual void SetScrollPos( int orient, int pos, bool refresh = true );
96 virtual int GetScrollPos( int orient ) const;
97 virtual int GetScrollThumb( int orient ) const;
98 virtual int GetScrollRange( int orient ) const;
99 virtual void ScrollWindow( int dx, int dy,
100 const wxRect* rect = (wxRect *) NULL );
101 virtual void AlwaysShowScrollbars(bool horz = true, bool vert = true);
102 virtual bool IsScrollbarAlwaysShown(int orient) const
103 {
104 return orient == wxHORIZONTAL ? m_hScrollBarAlwaysShown
105 : m_vScrollBarAlwaysShown;
106 }
107
108 virtual bool Reparent( wxWindowBase *newParent );
109
110 #if wxUSE_DRAG_AND_DROP
111 virtual void SetDropTarget( wxDropTarget *dropTarget );
112 #endif
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
122 void MacWindowToRootWindow( int *x , int *y ) const;
123
124 void MacRootWindowToWindow( int *x , int *y ) const;
125
126 virtual wxString MacGetToolTipString( wxPoint &where );
127
128 // simple accessors
129 // ----------------
130
131 virtual WXWidget GetHandle() const;
132
133 virtual bool SetTransparent(wxByte alpha);
134 virtual bool CanSetTransparent();
135 virtual wxByte GetTransparent() const ;
136
137 // event handlers
138 // --------------
139 void OnPaint( wxPaintEvent& event );
140 void OnNcPaint( wxNcPaintEvent& event );
141 void OnEraseBackground(wxEraseEvent& event );
142 void OnMouseEvent( wxMouseEvent &event );
143
144 void MacOnScroll( wxScrollEvent&event );
145
146 virtual bool AcceptsFocus() const;
147
148 virtual bool IsDoubleBuffered() const { return true; }
149
150 public:
151 static long MacRemoveBordersFromStyle( long style ) ;
152
153 public:
154 void OnInternalIdle();
155
156 // For implementation purposes:
157 // sometimes decorations make the client area smaller
158 virtual wxPoint GetClientAreaOrigin() const;
159
160 wxWindowMac *FindItem(long id) const;
161 wxWindowMac *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const;
162
163 virtual void MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) ;
164 virtual bool MacDoRedraw( void* updatergn , long time ) ;
165
166 // this should not be overriden in classes above wxWindowMac
167 // because it is called from its destructor via DeleteChildren
168 virtual void RemoveChild( wxWindowBase *child );
169 virtual void MacPaintBorders( int left , int top ) ;
170 void MacPaintGrowBox();
171
172 // invalidates the borders and focus area around the control;
173 // must not be virtual as it will be called during destruction
174 void MacInvalidateBorders() ;
175
176 WXWindow MacGetTopLevelWindowRef() const ;
177 wxNonOwnedWindow* MacGetTopLevelWindow() const ;
178
179 virtual long MacGetLeftBorderSize() const ;
180 virtual long MacGetRightBorderSize() const ;
181 virtual long MacGetTopBorderSize() const ;
182 virtual long MacGetBottomBorderSize() const ;
183
184 virtual void MacSuperChangedPosition() ;
185
186 // absolute coordinates of this window's root have changed
187 virtual void MacTopLevelWindowChangedPosition() ;
188
189 virtual void MacChildAdded() ;
190 virtual void MacVisibilityChanged() ;
191 virtual void MacEnabledStateChanged() ;
192 virtual void MacHiliteChanged() ;
193 virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ;
194
195 bool MacIsReallyEnabled() ;
196 bool MacIsReallyHilited() ;
197
198 bool MacIsUserPane() { return m_macIsUserPane; }
199
200 virtual bool MacSetupCursor( const wxPoint& pt ) ;
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 ) const
221 { return ((wxWindow*)m_hScrollBar == sb || (wxWindow*)m_vScrollBar == sb) ; }
222 virtual bool IsClientAreaChild(const wxWindow *child) const
223 {
224 return !MacIsWindowScrollbar(child) &&
225 wxWindowBase::IsClientAreaChild(child);
226 }
227
228 void MacPostControlCreate(const wxPoint& pos, const wxSize& size) ;
229 wxList& GetSubcontrols() { return m_subControls; }
230
231 // translate wxWidgets coords into ones suitable
232 // to be passed to CreateControl calls
233 //
234 // returns true if non-default coords are returned, false otherwise
235 bool MacGetBoundsForControl(const wxPoint& pos,
236 const wxSize& size,
237 int& x, int& y,
238 int& w, int& h , bool adjustForOrigin ) const ;
239
240 // the 'true' OS level control for this wxWindow
241 #if wxOSX_USE_CARBON
242 wxMacControl* GetPeer() const { return m_peer ; }
243 #else
244 wxWidgetImpl* GetPeer() const { return m_peer ; }
245 #endif
246
247 void * MacGetCGContextRef() { return m_cgContextRef ; }
248 void MacSetCGContextRef(void * cg) { m_cgContextRef = cg ; }
249
250 protected:
251 // For controls like radio buttons which are genuinely composite
252 wxList m_subControls;
253
254 #if wxOSX_USE_CARBON
255 // the peer object, allowing for cleaner API support
256 wxMacControl * m_peer ;
257 #else
258 wxWidgetImpl * m_peer ;
259 #endif
260 void * m_cgContextRef ;
261
262 // cache the clipped rectangles within the window hierarchy
263 void MacUpdateClippedRects() const ;
264
265 mutable bool m_cachedClippedRectValid ;
266 mutable wxRect m_cachedClippedRectWithOuterStructure ;
267 mutable wxRect m_cachedClippedRect ;
268 mutable wxRect m_cachedClippedClientRect ;
269 mutable wxRegion m_cachedClippedRegionWithOuterStructure ;
270 mutable wxRegion m_cachedClippedRegion ;
271 mutable wxRegion m_cachedClippedClientRegion ;
272
273 // true if is is not a native control but a wxWindow control
274 bool m_macIsUserPane ;
275
276 // insets of the mac control from the wx top left corner
277 wxPoint m_macTopLeftInset ;
278 wxPoint m_macBottomRightInset ;
279 wxByte m_macAlpha ;
280
281 wxScrollBar* m_hScrollBar ;
282 wxScrollBar* m_vScrollBar ;
283 bool m_hScrollBarAlwaysShown;
284 bool m_vScrollBarAlwaysShown;
285 wxString m_label ;
286
287 // set to true if we do a sharp clip at the content area of this window
288 // must be dynamic as eg a panel normally is not clipping precisely, but if
289 // it becomes the target window of a scrolled window it has to...
290 bool m_clipChildren ;
291
292 virtual bool MacIsChildOfClientArea( const wxWindow* child ) const ;
293
294 bool MacHasScrollBarCorner() const;
295 void MacCreateScrollBars( long style ) ;
296 void MacRepositionScrollBars() ;
297 void MacUpdateControlFont() ;
298
299 // implement the base class pure virtuals
300 virtual wxSize DoGetBestSize() const;
301 virtual wxSize DoGetSizeFromClientSize( const wxSize & size ) const;
302 virtual void DoClientToScreen( int *x, int *y ) const;
303 virtual void DoScreenToClient( int *x, int *y ) const;
304 virtual void DoGetPosition( int *x, int *y ) const;
305 virtual void DoGetSize( int *width, int *height ) const;
306 virtual void DoGetClientSize( int *width, int *height ) const;
307 virtual void DoSetSize(int x, int y,
308 int width, int height,
309 int sizeFlags = wxSIZE_AUTO);
310 virtual void DoSetClientSize(int width, int height);
311
312 virtual void DoCaptureMouse();
313 virtual void DoReleaseMouse();
314
315 // move the window to the specified location and resize it: this is called
316 // from both DoSetSize() and DoSetClientSize() and would usually just call
317 // ::MoveWindow() except for composite controls which will want to arrange
318 // themselves inside the given rectangle
319 virtual void DoMoveWindow( int x, int y, int width, int height );
320 virtual void DoSetWindowVariant( wxWindowVariant variant );
321
322 #if wxUSE_TOOLTIPS
323 virtual void DoSetToolTip( wxToolTip *tip );
324 #endif
325
326 private:
327 // common part of all ctors
328 void Init();
329
330 // show/hide scrollbars as needed, common part of SetScrollbar() and
331 // AlwaysShowScrollbars()
332 void DoUpdateScrollbarVisibility();
333
334
335 DECLARE_NO_COPY_CLASS(wxWindowMac)
336 DECLARE_EVENT_TABLE()
337 };
338
339 #endif // _WX_WINDOW_H_