]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/window.h
adding CoreText implementation
[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 WXDLLIMPEXP_FWD_CORE wxButton;
19 class WXDLLIMPEXP_FWD_CORE wxScrollBar;
20 class WXDLLIMPEXP_FWD_CORE 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
59 virtual void SetFocus();
60
61 virtual void WarpPointer( int x, int y );
62
63 virtual void Refresh( bool eraseBackground = true,
64 const wxRect *rect = NULL );
65 virtual void Freeze();
66 virtual void Thaw();
67 virtual bool IsFrozen() const;
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 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 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
105 virtual bool Reparent( wxWindowBase *newParent );
106
107 #if wxUSE_DRAG_AND_DROP
108 virtual void SetDropTarget( wxDropTarget *dropTarget );
109 #endif
110
111 // Accept files for dragging
112 virtual void DragAcceptFiles( bool accept );
113
114 // implementation from now on
115 // --------------------------
116
117 void MacClientToRootWindow( int *x , int *y ) const;
118 void MacRootWindowToClient( int *x , int *y ) const;
119
120 void MacWindowToRootWindow( int *x , int *y ) const;
121 void MacWindowToRootWindow( short *x , short *y ) const;
122
123 void MacRootWindowToWindow( int *x , int *y ) const;
124 void MacRootWindowToWindow( short *x , short *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 virtual bool MacCanFocus() const ;
166
167 // this should not be overriden in classes above wxWindowMac
168 // because it is called from its destructor via DeleteChildren
169 virtual void RemoveChild( wxWindowBase *child );
170 virtual void MacPaintBorders( int left , int top ) ;
171 void MacPaintGrowBox();
172
173 // invalidates the borders and focus area around the control;
174 // must not be virtual as it will be called during destruction
175 void MacInvalidateBorders() ;
176
177 WXWindow MacGetTopLevelWindowRef() const ;
178 wxTopLevelWindowMac* MacGetTopLevelWindow() const ;
179
180 virtual long MacGetLeftBorderSize() const ;
181 virtual long MacGetRightBorderSize() const ;
182 virtual long MacGetTopBorderSize() const ;
183 virtual long MacGetBottomBorderSize() const ;
184
185 virtual void MacSuperChangedPosition() ;
186
187 // absolute coordinates of this window's root have changed
188 virtual void MacTopLevelWindowChangedPosition() ;
189
190 virtual void MacChildAdded() ;
191 virtual void MacVisibilityChanged() ;
192 virtual void MacEnabledStateChanged() ;
193 virtual void MacHiliteChanged() ;
194 virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ;
195
196 bool MacIsReallyShown() ;
197 bool MacIsReallyEnabled() ;
198 bool MacIsReallyHilited() ;
199
200 bool MacIsUserPane() { return m_macIsUserPane; }
201
202 virtual bool MacSetupCursor( const wxPoint& pt ) ;
203
204 // return the rectangle that would be visible of this control,
205 // regardless whether controls are hidden
206 // only taking into account clipping by parent windows
207 const wxRect& MacGetClippedClientRect() const ;
208 const wxRect& MacGetClippedRect() const ;
209 const wxRect& MacGetClippedRectWithOuterStructure() const ;
210
211 // returns the visible region of this control in window ie non-client coordinates
212 const wxRegion& MacGetVisibleRegion( bool includeOuterStructures = false ) ;
213
214 // returns true if children have to clipped to the content area
215 // (e.g., scrolled windows)
216 bool MacClipChildren() const { return m_clipChildren ; }
217 void MacSetClipChildren( bool clip ) { m_clipChildren = clip ; }
218
219 // returns true if the grandchildren need to be clipped to the children's content area
220 // (e.g., splitter windows)
221 virtual bool MacClipGrandChildren() const { return false ; }
222 bool MacIsWindowScrollbar( const wxWindow* sb ) const
223 { return ((wxWindow*)m_hScrollBar == sb || (wxWindow*)m_vScrollBar == sb) ; }
224 virtual bool IsClientAreaChild(const wxWindow *child) const
225 {
226 return !MacIsWindowScrollbar(child) &&
227 wxWindowBase::IsClientAreaChild(child);
228 }
229
230 virtual void MacInstallEventHandler(WXWidget native) ;
231 void MacPostControlCreate(const wxPoint& pos, const wxSize& size) ;
232 wxList& GetSubcontrols() { return m_subControls; }
233 WXEVENTHANDLERREF MacGetControlEventHandler() { return m_macControlEventHandler ; }
234
235 // translate wxWidgets coords into ones suitable
236 // to be passed to CreateControl calls
237 //
238 // returns true if non-default coords are returned, false otherwise
239 bool MacGetBoundsForControl(const wxPoint& pos,
240 const wxSize& size,
241 int& x, int& y,
242 int& w, int& h , bool adjustForOrigin ) const ;
243
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 ;
247
248 // gets the inset from every part
249 virtual void MacGetContentAreaInset( int &left , int &top , int &right , int &bottom ) ;
250
251 // visibly flash the current invalid area:
252 // useful for debugging in OSX composited (double-buffered) situation
253 void MacFlashInvalidAreas() ;
254
255 // the 'true' OS level control for this wxWindow
256 wxMacControl* GetPeer() const { return m_peer ; }
257
258 void * MacGetCGContextRef() { return m_cgContextRef ; }
259 void MacSetCGContextRef(void * cg) { m_cgContextRef = cg ; }
260
261 protected:
262 // For controls like radio buttons which are genuinely composite
263 wxList m_subControls;
264
265 // number of calls to Freeze() minus number of calls to Thaw()
266 unsigned int m_frozenness;
267
268 // the peer object, allowing for cleaner API support
269 wxMacControl * m_peer ;
270
271 void * m_cgContextRef ;
272
273 // cache the clipped rectangles within the window hierarchy
274 void MacUpdateClippedRects() const ;
275
276 mutable bool m_cachedClippedRectValid ;
277 mutable wxRect m_cachedClippedRectWithOuterStructure ;
278 mutable wxRect m_cachedClippedRect ;
279 mutable wxRect m_cachedClippedClientRect ;
280 mutable wxRegion m_cachedClippedRegionWithOuterStructure ;
281 mutable wxRegion m_cachedClippedRegion ;
282 mutable wxRegion m_cachedClippedClientRegion ;
283
284 // true if is is not a native control but a wxWindow control
285 bool m_macIsUserPane ;
286
287 // insets of the mac control from the wx top left corner
288 wxPoint m_macTopLeftInset ;
289 wxPoint m_macBottomRightInset ;
290 wxByte m_macAlpha ;
291
292 wxScrollBar* m_hScrollBar ;
293 wxScrollBar* m_vScrollBar ;
294 bool m_hScrollBarAlwaysShown;
295 bool m_vScrollBarAlwaysShown;
296 wxString m_label ;
297
298 // set to true if we do a sharp clip at the content area of this window
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 ;
302
303 virtual bool MacIsChildOfClientArea( const wxWindow* child ) const ;
304
305 bool MacHasScrollBarCorner() const;
306 void MacCreateScrollBars( long style ) ;
307 void MacRepositionScrollBars() ;
308 void MacUpdateControlFont() ;
309
310 // implement the base class pure virtuals
311 virtual wxSize DoGetBestSize() const;
312 virtual wxSize DoGetSizeFromClientSize( const wxSize & size ) const;
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
330 virtual void DoMoveWindow( int x, int y, int width, int height );
331 virtual void DoSetWindowVariant( wxWindowVariant variant );
332
333 #if wxUSE_TOOLTIPS
334 virtual void DoSetToolTip( wxToolTip *tip );
335 #endif
336
337 private:
338 // common part of all ctors
339 void Init();
340
341 // show/hide scrollbars as needed, common part of SetScrollbar() and
342 // AlwaysShowScrollbars()
343 void DoUpdateScrollbarVisibility();
344
345
346 WXEVENTHANDLERREF m_macControlEventHandler ;
347
348 DECLARE_NO_COPY_CLASS(wxWindowMac)
349 DECLARE_EVENT_TABLE()
350 };
351
352 #endif // _WX_WINDOW_H_