]>
Commit | Line | Data |
---|---|---|
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 bool Enable( bool enable = true ); | |
59 | ||
60 | virtual void SetFocus(); | |
61 | ||
62 | virtual void WarpPointer( int x, int y ); | |
63 | ||
64 | virtual void Refresh( bool eraseBackground = true, | |
65 | const wxRect *rect = NULL ); | |
66 | virtual void Freeze(); | |
67 | virtual void Thaw(); | |
68 | virtual bool IsFrozen() const; | |
69 | ||
70 | virtual void Update() ; | |
71 | virtual void ClearBackground(); | |
72 | ||
73 | virtual bool SetCursor( const wxCursor &cursor ); | |
74 | virtual bool SetFont( const wxFont &font ); | |
75 | virtual bool SetBackgroundColour( const wxColour &colour ); | |
76 | virtual bool SetForegroundColour( const wxColour &colour ); | |
77 | ||
78 | virtual int GetCharHeight() const; | |
79 | virtual int GetCharWidth() const; | |
80 | virtual void GetTextExtent( const wxString& string, | |
81 | int *x, int *y, | |
82 | int *descent = NULL, | |
83 | int *externalLeading = NULL, | |
84 | const wxFont *theFont = NULL ) | |
85 | const; | |
86 | protected: | |
87 | virtual bool DoPopupMenu( wxMenu *menu, int x, int y ); | |
88 | public: | |
89 | virtual void SetScrollbar( int orient, int pos, int thumbVisible, | |
90 | int range, bool refresh = true ); | |
91 | virtual void SetScrollPos( int orient, int pos, bool refresh = true ); | |
92 | virtual int GetScrollPos( int orient ) const; | |
93 | virtual int GetScrollThumb( int orient ) const; | |
94 | virtual int GetScrollRange( int orient ) const; | |
95 | virtual void ScrollWindow( int dx, int dy, | |
96 | const wxRect* rect = (wxRect *) NULL ); | |
97 | virtual bool Reparent( wxWindowBase *newParent ); | |
98 | ||
99 | #if wxUSE_DRAG_AND_DROP | |
100 | virtual void SetDropTarget( wxDropTarget *dropTarget ); | |
101 | #endif | |
102 | ||
103 | // Accept files for dragging | |
104 | virtual void DragAcceptFiles( bool accept ); | |
105 | ||
106 | // implementation from now on | |
107 | // -------------------------- | |
108 | ||
109 | void MacClientToRootWindow( int *x , int *y ) const; | |
110 | void MacRootWindowToClient( int *x , int *y ) const; | |
111 | ||
112 | void MacWindowToRootWindow( int *x , int *y ) const; | |
113 | void MacWindowToRootWindow( short *x , short *y ) const; | |
114 | ||
115 | void MacRootWindowToWindow( int *x , int *y ) const; | |
116 | void MacRootWindowToWindow( short *x , short *y ) const; | |
117 | ||
118 | virtual wxString MacGetToolTipString( wxPoint &where ); | |
119 | ||
120 | // simple accessors | |
121 | // ---------------- | |
122 | ||
123 | virtual WXWidget GetHandle() const; | |
124 | ||
125 | virtual bool SetTransparent(wxByte alpha); | |
126 | virtual bool CanSetTransparent(); | |
127 | virtual wxByte GetTransparent() const ; | |
128 | ||
129 | // event handlers | |
130 | // -------------- | |
131 | void OnSetFocus( wxFocusEvent& event ); | |
132 | void OnPaint( wxPaintEvent& event ); | |
133 | void OnNcPaint( wxNcPaintEvent& event ); | |
134 | void OnEraseBackground(wxEraseEvent& event ); | |
135 | void OnMouseEvent( wxMouseEvent &event ); | |
136 | ||
137 | void MacOnScroll( wxScrollEvent&event ); | |
138 | ||
139 | 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 | ||
156 | virtual void MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) ; | |
157 | virtual bool MacDoRedraw( WXHRGN updatergn , long time ) ; | |
158 | virtual bool MacCanFocus() const ; | |
159 | ||
160 | // this should not be overriden in classes above wxWindowMac | |
161 | // because it is called from its destructor via DeleteChildren | |
162 | virtual void RemoveChild( wxWindowBase *child ); | |
163 | virtual void MacPaintBorders( int left , int top ) ; | |
164 | ||
165 | // invalidates the borders and focus area around the control; | |
166 | // must not be virtual as it will be called during destruction | |
167 | void MacInvalidateBorders() ; | |
168 | ||
169 | WXWindow MacGetTopLevelWindowRef() const ; | |
170 | wxTopLevelWindowMac* MacGetTopLevelWindow() const ; | |
171 | ||
172 | virtual long MacGetLeftBorderSize() const ; | |
173 | virtual long MacGetRightBorderSize() const ; | |
174 | virtual long MacGetTopBorderSize() const ; | |
175 | virtual long MacGetBottomBorderSize() const ; | |
176 | ||
177 | virtual void MacSuperChangedPosition() ; | |
178 | ||
179 | // absolute coordinates of this window's root have changed | |
180 | virtual void MacTopLevelWindowChangedPosition() ; | |
181 | ||
182 | virtual void MacChildAdded() ; | |
183 | virtual void MacVisibilityChanged() ; | |
184 | virtual void MacEnabledStateChanged() ; | |
185 | virtual void MacHiliteChanged() ; | |
186 | virtual wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ; | |
187 | ||
188 | bool MacIsReallyShown() ; | |
189 | bool MacIsReallyEnabled() ; | |
190 | bool MacIsReallyHilited() ; | |
191 | ||
192 | bool MacIsUserPane() { return m_macIsUserPane; } | |
193 | ||
194 | virtual bool MacSetupCursor( const wxPoint& pt ) ; | |
195 | virtual void MacSetBackgroundBrush( const wxBrush &brush ) ; | |
196 | const wxBrush& MacGetBackgroundBrush() const { return m_macBackgroundBrush ; } | |
197 | ||
198 | // return the rectangle that would be visible of this control, | |
199 | // regardless whether controls are hidden | |
200 | // only taking into account clipping by parent windows | |
201 | const wxRect& MacGetClippedClientRect() const ; | |
202 | const wxRect& MacGetClippedRect() const ; | |
203 | const wxRect& MacGetClippedRectWithOuterStructure() const ; | |
204 | ||
205 | // returns the visible region of this control in window ie non-client coordinates | |
206 | const wxRegion& MacGetVisibleRegion( bool includeOuterStructures = false ) ; | |
207 | ||
208 | // returns true if children have to clipped to the content area | |
209 | // (e.g., scrolled windows) | |
210 | bool MacClipChildren() const { return m_clipChildren ; } | |
211 | void MacSetClipChildren( bool clip ) { m_clipChildren = clip ; } | |
212 | ||
213 | // returns true if the grandchildren need to be clipped to the children's content area | |
214 | // (e.g., splitter windows) | |
215 | virtual bool MacClipGrandChildren() const { return false ; } | |
216 | bool MacIsWindowScrollbar( const wxWindow* sb ) | |
217 | { return ((wxWindow*)m_hScrollBar == sb || (wxWindow*)m_vScrollBar == sb) ; } | |
218 | ||
219 | virtual void MacInstallEventHandler(WXWidget native) ; | |
220 | void MacPostControlCreate(const wxPoint& pos, const wxSize& size) ; | |
221 | wxList& GetSubcontrols() { return m_subControls; } | |
222 | WXEVENTHANDLERREF MacGetControlEventHandler() { return m_macControlEventHandler ; } | |
223 | ||
224 | #ifndef __WXMAC_OSX__ | |
225 | virtual void MacControlUserPaneDrawProc(wxInt16 part) ; | |
226 | virtual wxInt16 MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) ; | |
227 | virtual wxInt16 MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) ; | |
228 | virtual void MacControlUserPaneIdleProc() ; | |
229 | virtual wxInt16 MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) ; | |
230 | virtual void MacControlUserPaneActivateProc(bool activating) ; | |
231 | virtual wxInt16 MacControlUserPaneFocusProc(wxInt16 action) ; | |
232 | virtual void MacControlUserPaneBackgroundProc(void* info) ; | |
233 | #endif | |
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 | #if wxMAC_USE_CORE_GRAPHICS | |
259 | void * MacGetCGContextRef() { return m_cgContextRef ; } | |
260 | void MacSetCGContextRef(void * cg) { m_cgContextRef = cg ; } | |
261 | #endif | |
262 | ||
263 | protected: | |
264 | // For controls like radio buttons which are genuinely composite | |
265 | wxList m_subControls; | |
266 | ||
267 | // number of calls to Freeze() minus number of calls to Thaw() | |
268 | unsigned int m_frozenness; | |
269 | ||
270 | // the peer object, allowing for cleaner API support | |
271 | wxMacControl * m_peer ; | |
272 | ||
273 | #if wxMAC_USE_CORE_GRAPHICS | |
274 | void * m_cgContextRef ; | |
275 | #endif | |
276 | ||
277 | // cache the clipped rectangles within the window hierarchy | |
278 | void MacUpdateClippedRects() const ; | |
279 | ||
280 | mutable bool m_cachedClippedRectValid ; | |
281 | mutable wxRect m_cachedClippedRectWithOuterStructure ; | |
282 | mutable wxRect m_cachedClippedRect ; | |
283 | mutable wxRect m_cachedClippedClientRect ; | |
284 | mutable wxRegion m_cachedClippedRegionWithOuterStructure ; | |
285 | mutable wxRegion m_cachedClippedRegion ; | |
286 | mutable wxRegion m_cachedClippedClientRegion ; | |
287 | ||
288 | // true if is is not a native control but a wxWindow control | |
289 | bool m_macIsUserPane ; | |
290 | wxBrush m_macBackgroundBrush ; | |
291 | ||
292 | // insets of the mac control from the wx top left corner | |
293 | wxPoint m_macTopLeftInset ; | |
294 | wxPoint m_macBottomRightInset ; | |
295 | wxByte m_macAlpha ; | |
296 | ||
297 | wxScrollBar* m_hScrollBar ; | |
298 | wxScrollBar* m_vScrollBar ; | |
299 | wxString m_label ; | |
300 | ||
301 | // set to true if we do a sharp clip at the content area of this window | |
302 | // must be dynamic as eg a panel normally is not clipping precisely, but if | |
303 | // it becomes the target window of a scrolled window it has to... | |
304 | bool m_clipChildren ; | |
305 | ||
306 | virtual bool MacIsChildOfClientArea( const wxWindow* child ) const ; | |
307 | ||
308 | void MacCreateScrollBars( long style ) ; | |
309 | void MacRepositionScrollBars() ; | |
310 | void MacUpdateControlFont() ; | |
311 | ||
312 | void MacPropagateVisibilityChanged() ; | |
313 | void MacPropagateEnabledStateChanged() ; | |
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_ |