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