]>
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; | |
2ae3afa0 | 20 | class WXDLLIMPEXP_FWD_CORE wxPanel; |
6762286d SC |
21 | class WXDLLIMPEXP_FWD_CORE wxNonOwnedWindow; |
22 | ||
c099b533 SC |
23 | #if wxOSX_USE_CARBON |
24 | class WXDLLIMPEXP_FWD_CORE wxMacControl ; | |
25 | typedef wxMacControl wxOSXWidgetImpl; | |
ee032c59 SC |
26 | #elif wxOSX_USE_COCOA_OR_IPHONE |
27 | class WXDLLIMPEXP_FWD_CORE wxWidgetImpl ; | |
28 | typedef wxWidgetImpl wxOSXWidgetImpl; | |
c099b533 SC |
29 | #endif |
30 | ||
6762286d SC |
31 | |
32 | class WXDLLIMPEXP_CORE wxWindowMac: public wxWindowBase | |
33 | { | |
34 | DECLARE_DYNAMIC_CLASS(wxWindowMac) | |
35 | ||
36 | friend class wxDC; | |
37 | friend class wxPaintDC; | |
38 | ||
39 | public: | |
40 | wxWindowMac(); | |
41 | ||
42 | wxWindowMac( wxWindowMac *parent, | |
43 | wxWindowID id, | |
44 | const wxPoint& pos = wxDefaultPosition, | |
45 | const wxSize& size = wxDefaultSize, | |
46 | long style = 0, | |
47 | const wxString& name = wxPanelNameStr ); | |
48 | ||
49 | virtual ~wxWindowMac(); | |
50 | ||
51 | bool Create( wxWindowMac *parent, | |
52 | wxWindowID id, | |
53 | const wxPoint& pos = wxDefaultPosition, | |
54 | const wxSize& size = wxDefaultSize, | |
55 | long style = 0, | |
56 | const wxString& name = wxPanelNameStr ); | |
57 | ||
58 | // implement base class pure virtuals | |
59 | virtual void SetLabel( const wxString& label ); | |
60 | virtual wxString GetLabel() const; | |
61 | ||
62 | virtual void Raise(); | |
63 | virtual void Lower(); | |
64 | ||
65 | virtual bool Show( bool show = true ); | |
66 | ||
67 | virtual bool IsShownOnScreen() const; | |
68 | ||
69 | virtual void SetFocus(); | |
70 | ||
71 | virtual void WarpPointer( int x, int y ); | |
72 | ||
73 | virtual void Refresh( bool eraseBackground = true, | |
74 | const wxRect *rect = NULL ); | |
75 | ||
76 | virtual void Update() ; | |
77 | virtual void ClearBackground(); | |
78 | ||
79 | virtual bool SetCursor( const wxCursor &cursor ); | |
80 | virtual bool SetFont( const wxFont &font ); | |
81 | virtual bool SetBackgroundColour( const wxColour &colour ); | |
82 | virtual bool SetForegroundColour( const wxColour &colour ); | |
83 | ||
84 | virtual int GetCharHeight() const; | |
85 | virtual int GetCharWidth() const; | |
6762286d SC |
86 | |
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, | |
d3b9f782 | 95 | const wxRect* rect = NULL ); |
6762286d SC |
96 | virtual void AlwaysShowScrollbars(bool horz = true, bool vert = true); |
97 | virtual bool IsScrollbarAlwaysShown(int orient) const | |
98 | { | |
99 | return orient == wxHORIZONTAL ? m_hScrollBarAlwaysShown | |
100 | : m_vScrollBarAlwaysShown; | |
101 | } | |
102 | ||
103 | virtual bool Reparent( wxWindowBase *newParent ); | |
104 | ||
105 | #if wxUSE_DRAG_AND_DROP | |
106 | virtual void SetDropTarget( wxDropTarget *dropTarget ); | |
107 | #endif | |
108 | ||
109 | // Accept files for dragging | |
110 | virtual void DragAcceptFiles( bool accept ); | |
111 | ||
112 | // implementation from now on | |
113 | // -------------------------- | |
114 | ||
115 | void MacClientToRootWindow( int *x , int *y ) const; | |
116 | ||
117 | void MacWindowToRootWindow( int *x , int *y ) const; | |
118 | ||
119 | void MacRootWindowToWindow( int *x , int *y ) const; | |
120 | ||
121 | virtual wxString MacGetToolTipString( wxPoint &where ); | |
122 | ||
123 | // simple accessors | |
124 | // ---------------- | |
125 | ||
126 | virtual WXWidget GetHandle() const; | |
127 | ||
128 | virtual bool SetTransparent(wxByte alpha); | |
129 | virtual bool CanSetTransparent(); | |
130 | virtual wxByte GetTransparent() const ; | |
131 | ||
132 | // event handlers | |
133 | // -------------- | |
4dd9fdf8 | 134 | |
6762286d SC |
135 | void OnMouseEvent( wxMouseEvent &event ); |
136 | ||
137 | void MacOnScroll( wxScrollEvent&event ); | |
138 | ||
139 | virtual bool AcceptsFocus() const; | |
140 | ||
141 | virtual bool IsDoubleBuffered() const { return true; } | |
142 | ||
143 | public: | |
144 | static long MacRemoveBordersFromStyle( long style ) ; | |
145 | ||
146 | public: | |
147 | void OnInternalIdle(); | |
148 | ||
149 | // For implementation purposes: | |
150 | // sometimes decorations make the client area smaller | |
151 | virtual wxPoint GetClientAreaOrigin() const; | |
152 | ||
153 | wxWindowMac *FindItem(long id) const; | |
154 | wxWindowMac *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const; | |
155 | ||
19c7ac3d | 156 | virtual void TriggerScrollEvent( wxEventType scrollEvent ) ; |
6762286d SC |
157 | // this should not be overriden in classes above wxWindowMac |
158 | // because it is called from its destructor via DeleteChildren | |
159 | virtual void RemoveChild( wxWindowBase *child ); | |
03647350 | 160 | |
5398a2e0 SC |
161 | virtual bool MacDoRedraw( long time ) ; |
162 | virtual void MacPaintChildrenBorders(); | |
6762286d SC |
163 | virtual void MacPaintBorders( int left , int top ) ; |
164 | void MacPaintGrowBox(); | |
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 | wxNonOwnedWindow* 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 MacIsReallyEnabled() ; | |
190 | bool MacIsReallyHilited() ; | |
191 | ||
938fbc8f | 192 | #if WXWIN_COMPATIBILITY_2_8 |
6762286d | 193 | bool MacIsUserPane() { return m_macIsUserPane; } |
938fbc8f SC |
194 | #endif |
195 | bool MacIsUserPane() const { return m_macIsUserPane; } | |
6762286d SC |
196 | |
197 | virtual bool MacSetupCursor( const wxPoint& pt ) ; | |
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 ) const | |
218 | { return ((wxWindow*)m_hScrollBar == sb || (wxWindow*)m_vScrollBar == sb) ; } | |
219 | virtual bool IsClientAreaChild(const wxWindow *child) const | |
220 | { | |
221 | return !MacIsWindowScrollbar(child) && | |
222 | wxWindowBase::IsClientAreaChild(child); | |
223 | } | |
224 | ||
225 | void MacPostControlCreate(const wxPoint& pos, const wxSize& size) ; | |
226 | wxList& GetSubcontrols() { return m_subControls; } | |
227 | ||
228 | // translate wxWidgets coords into ones suitable | |
229 | // to be passed to CreateControl calls | |
230 | // | |
231 | // returns true if non-default coords are returned, false otherwise | |
232 | bool MacGetBoundsForControl(const wxPoint& pos, | |
233 | const wxSize& size, | |
234 | int& x, int& y, | |
235 | int& w, int& h , bool adjustForOrigin ) const ; | |
236 | ||
237 | // the 'true' OS level control for this wxWindow | |
c099b533 | 238 | wxOSXWidgetImpl* GetPeer() const { return m_peer ; } |
03647350 | 239 | |
6762286d SC |
240 | void * MacGetCGContextRef() { return m_cgContextRef ; } |
241 | void MacSetCGContextRef(void * cg) { m_cgContextRef = cg ; } | |
242 | ||
243 | // osx specific event handling common for all osx-ports | |
03647350 | 244 | |
4eb5a0ec RR |
245 | virtual bool OSXHandleClicked( double timestampsec ); |
246 | virtual bool OSXHandleKeyEvent( wxKeyEvent& event ); | |
6762286d SC |
247 | protected: |
248 | // For controls like radio buttons which are genuinely composite | |
249 | wxList m_subControls; | |
250 | ||
6762286d | 251 | // the peer object, allowing for cleaner API support |
c099b533 SC |
252 | wxOSXWidgetImpl * m_peer ; |
253 | ||
6762286d SC |
254 | void * m_cgContextRef ; |
255 | ||
256 | // cache the clipped rectangles within the window hierarchy | |
257 | void MacUpdateClippedRects() const ; | |
258 | ||
259 | mutable bool m_cachedClippedRectValid ; | |
260 | mutable wxRect m_cachedClippedRectWithOuterStructure ; | |
261 | mutable wxRect m_cachedClippedRect ; | |
262 | mutable wxRect m_cachedClippedClientRect ; | |
263 | mutable wxRegion m_cachedClippedRegionWithOuterStructure ; | |
264 | mutable wxRegion m_cachedClippedRegion ; | |
265 | mutable wxRegion m_cachedClippedClientRegion ; | |
266 | ||
267 | // true if is is not a native control but a wxWindow control | |
268 | bool m_macIsUserPane ; | |
269 | ||
270 | // insets of the mac control from the wx top left corner | |
271 | wxPoint m_macTopLeftInset ; | |
272 | wxPoint m_macBottomRightInset ; | |
273 | wxByte m_macAlpha ; | |
274 | ||
275 | wxScrollBar* m_hScrollBar ; | |
276 | wxScrollBar* m_vScrollBar ; | |
277 | bool m_hScrollBarAlwaysShown; | |
278 | bool m_vScrollBarAlwaysShown; | |
2ae3afa0 | 279 | wxPanel* m_growBox ; |
6762286d SC |
280 | wxString m_label ; |
281 | ||
282 | // set to true if we do a sharp clip at the content area of this window | |
283 | // must be dynamic as eg a panel normally is not clipping precisely, but if | |
284 | // it becomes the target window of a scrolled window it has to... | |
285 | bool m_clipChildren ; | |
286 | ||
287 | virtual bool MacIsChildOfClientArea( const wxWindow* child ) const ; | |
288 | ||
289 | bool MacHasScrollBarCorner() const; | |
290 | void MacCreateScrollBars( long style ) ; | |
291 | void MacRepositionScrollBars() ; | |
292 | void MacUpdateControlFont() ; | |
293 | ||
294 | // implement the base class pure virtuals | |
6de70470 VZ |
295 | virtual void DoGetTextExtent(const wxString& string, |
296 | int *x, int *y, | |
297 | int *descent = NULL, | |
298 | int *externalLeading = NULL, | |
299 | const wxFont *theFont = NULL ) const; | |
300 | ||
301 | virtual void DoEnable( bool enable ); | |
302 | #if wxUSE_MENUS | |
303 | virtual bool DoPopupMenu( wxMenu *menu, int x, int y ); | |
304 | #endif | |
305 | ||
306 | virtual void DoFreeze(); | |
307 | virtual void DoThaw(); | |
308 | ||
6762286d SC |
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_ |