]>
Commit | Line | Data |
---|---|---|
1e6feb95 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/univ/window.h | |
3 | // Purpose: wxWindow class which is the base class for all | |
4 | // wxUniv port controls, it supports the customization of the | |
5 | // window drawing and input processing. | |
6 | // Author: Vadim Zeitlin | |
7 | // Modified by: | |
8 | // Created: 06.08.00 | |
9 | // RCS-ID: $Id$ | |
442b35b5 | 10 | // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com) |
65571936 | 11 | // Licence: wxWindows licence |
1e6feb95 VZ |
12 | /////////////////////////////////////////////////////////////////////////////// |
13 | ||
14 | #ifndef _WX_UNIV_WINDOW_H_ | |
15 | #define _WX_UNIV_WINDOW_H_ | |
16 | ||
1e6feb95 VZ |
17 | #include "wx/bitmap.h" // for m_bitmapBg |
18 | ||
b5dbe15d VS |
19 | class WXDLLIMPEXP_FWD_CORE wxControlRenderer; |
20 | class WXDLLIMPEXP_FWD_CORE wxEventLoop; | |
9a6384ca WS |
21 | |
22 | #if wxUSE_MENUS | |
b5dbe15d VS |
23 | class WXDLLIMPEXP_FWD_CORE wxMenu; |
24 | class WXDLLIMPEXP_FWD_CORE wxMenuBar; | |
9a6384ca WS |
25 | #endif // wxUSE_MENUS |
26 | ||
b5dbe15d | 27 | class WXDLLIMPEXP_FWD_CORE wxRenderer; |
9a6384ca WS |
28 | |
29 | #if wxUSE_SCROLLBAR | |
b5dbe15d | 30 | class WXDLLIMPEXP_FWD_CORE wxScrollBar; |
9a6384ca | 31 | #endif // wxUSE_SCROLLBAR |
1e6feb95 | 32 | |
ab6b6b15 RR |
33 | #ifdef __WXX11__ |
34 | #define wxUSE_TWO_WINDOWS 1 | |
35 | #else | |
36 | #define wxUSE_TWO_WINDOWS 0 | |
37 | #endif | |
38 | ||
1e6feb95 VZ |
39 | // ---------------------------------------------------------------------------- |
40 | // wxWindow | |
41 | // ---------------------------------------------------------------------------- | |
42 | ||
24ce4c18 JS |
43 | #if defined(__WXMSW__) |
44 | #define wxWindowNative wxWindowMSW | |
45 | #elif defined(__WXGTK__) | |
46 | #define wxWindowNative wxWindowGTK | |
47 | #elif defined(__WXMGL__) | |
48 | #define wxWindowNative wxWindowMGL | |
1b0b798d RR |
49 | #elif defined(__WXX11__) |
50 | #define wxWindowNative wxWindowX11 | |
e766c8a9 SC |
51 | #elif defined(__WXMAC__) |
52 | #define wxWindowNative wxWindowMac | |
24ce4c18 JS |
53 | #endif |
54 | ||
53a2db12 | 55 | class WXDLLIMPEXP_CORE wxWindow : public wxWindowNative |
1e6feb95 VZ |
56 | { |
57 | public: | |
1a77875b | 58 | // ctors and create functions |
1e6feb95 VZ |
59 | // --------------------------- |
60 | ||
6463b9f5 | 61 | wxWindow() { Init(); } |
1e6feb95 VZ |
62 | |
63 | wxWindow(wxWindow *parent, | |
64 | wxWindowID id, | |
65 | const wxPoint& pos = wxDefaultPosition, | |
66 | const wxSize& size = wxDefaultSize, | |
67 | long style = 0, | |
6463b9f5 JS |
68 | const wxString& name = wxPanelNameStr) |
69 | : wxWindowNative(parent, id, pos, size, style | wxCLIP_CHILDREN, name) | |
70 | { Init(); } | |
1e6feb95 VZ |
71 | |
72 | bool Create(wxWindow *parent, | |
73 | wxWindowID id, | |
74 | const wxPoint& pos = wxDefaultPosition, | |
75 | const wxSize& size = wxDefaultSize, | |
76 | long style = 0, | |
77 | const wxString& name = wxPanelNameStr); | |
78 | ||
8da1f9a9 VZ |
79 | virtual ~wxWindow(); |
80 | ||
1e6feb95 VZ |
81 | // background pixmap support |
82 | // ------------------------- | |
83 | ||
84 | virtual void SetBackground(const wxBitmap& bitmap, | |
85 | int alignment = wxALIGN_CENTRE, | |
86 | wxStretch stretch = wxSTRETCH_NOT); | |
87 | ||
88 | const wxBitmap& GetBackgroundBitmap(int *alignment = NULL, | |
89 | wxStretch *stretch = NULL) const; | |
90 | ||
91 | // scrollbars: we (re)implement it ourselves using our own scrollbars | |
92 | // instead of the native ones | |
93 | // ------------------------------------------------------------------ | |
94 | ||
95 | virtual void SetScrollbar(int orient, | |
96 | int pos, | |
97 | int page, | |
98 | int range, | |
a290fa5a WS |
99 | bool refresh = true ); |
100 | virtual void SetScrollPos(int orient, int pos, bool refresh = true); | |
1e6feb95 VZ |
101 | virtual int GetScrollPos(int orient) const; |
102 | virtual int GetScrollThumb(int orient) const; | |
103 | virtual int GetScrollRange(int orient) const; | |
104 | virtual void ScrollWindow(int dx, int dy, | |
d3b9f782 | 105 | const wxRect* rect = NULL); |
1e6feb95 VZ |
106 | |
107 | // take into account the borders here | |
108 | virtual wxPoint GetClientAreaOrigin() const; | |
109 | ||
110 | // popup menu support | |
111 | // ------------------ | |
112 | ||
113 | // NB: all menu related functions are implemented in menu.cpp | |
114 | ||
115 | #if wxUSE_MENUS | |
1e6feb95 VZ |
116 | // this is wxUniv-specific private method to be used only by wxMenu |
117 | void DismissPopupMenu(); | |
118 | #endif // wxUSE_MENUS | |
119 | ||
120 | // miscellaneous other methods | |
121 | // --------------------------- | |
122 | ||
123 | // get the state information | |
124 | virtual bool IsFocused() const; | |
125 | virtual bool IsCurrent() const; | |
126 | virtual bool IsPressed() const; | |
127 | virtual bool IsDefault() const; | |
128 | ||
129 | // return all state flags at once (combination of wxCONTROL_XXX values) | |
130 | int GetStateFlags() const; | |
131 | ||
a290fa5a WS |
132 | // set the "highlighted" flag and return true if it changed |
133 | virtual bool SetCurrent(bool doit = true); | |
1e6feb95 | 134 | |
9a6384ca | 135 | #if wxUSE_SCROLLBAR |
1e6feb95 VZ |
136 | // get the scrollbar (may be NULL) for the given orientation |
137 | wxScrollBar *GetScrollbar(int orient) const | |
138 | { | |
139 | return orient & wxVERTICAL ? m_scrollbarVert : m_scrollbarHorz; | |
140 | } | |
9a6384ca | 141 | #endif // wxUSE_SCROLLBAR |
1e6feb95 VZ |
142 | |
143 | // methods used by wxColourScheme to choose the colours for this window | |
144 | // -------------------------------------------------------------------- | |
145 | ||
a290fa5a | 146 | // return true if this is a panel/canvas window which contains other |
1e6feb95 | 147 | // controls only |
a290fa5a | 148 | virtual bool IsCanvasWindow() const { return false; } |
1e6feb95 | 149 | |
a290fa5a | 150 | // return true if this control can be highlighted when the mouse is over |
1e6feb95 | 151 | // it (the theme decides itself whether it is really highlighted or not) |
a290fa5a | 152 | virtual bool CanBeHighlighted() const { return false; } |
1e6feb95 | 153 | |
a290fa5a | 154 | // return true if we should use the colours/fonts returned by the |
1e6feb95 | 155 | // corresponding GetXXX() methods instead of the default ones |
1e6feb95 VZ |
156 | bool UseFgCol() const { return m_hasFgCol; } |
157 | bool UseFont() const { return m_hasFont; } | |
158 | ||
a290fa5a | 159 | // return true if this window serves as a container for the other windows |
30827629 | 160 | // only and doesn't get any input itself |
a290fa5a | 161 | virtual bool IsStaticBox() const { return false; } |
30827629 | 162 | |
1e6feb95 VZ |
163 | // returns the (low level) renderer to use for drawing the control by |
164 | // querying the current theme | |
165 | wxRenderer *GetRenderer() const { return m_renderer; } | |
166 | ||
167 | // scrolling helper: like ScrollWindow() except that it doesn't refresh the | |
168 | // uncovered window areas but returns the rectangle to update (don't call | |
169 | // this with both dx and dy non zero) | |
170 | wxRect ScrollNoRefresh(int dx, int dy, const wxRect *rect = NULL); | |
171 | ||
172 | // after scrollbars are added or removed they must be refreshed by calling | |
173 | // this function | |
174 | void RefreshScrollbars(); | |
175 | ||
176 | // erase part of the control | |
177 | virtual void EraseBackground(wxDC& dc, const wxRect& rect); | |
4cc4e7b6 | 178 | |
1e6feb95 VZ |
179 | // overridden base class methods |
180 | // ----------------------------- | |
181 | ||
182 | // the rect coordinates are, for us, in client coords, but if no rect is | |
183 | // specified, the entire window is refreshed | |
a290fa5a | 184 | virtual void Refresh(bool eraseBackground = true, |
1e6feb95 VZ |
185 | const wxRect *rect = (const wxRect *) NULL); |
186 | ||
187 | // we refresh the window when it is dis/enabled | |
a290fa5a | 188 | virtual bool Enable(bool enable = true); |
1e6feb95 | 189 | |
b2d22a3f VZ |
190 | // should we use the standard control colours or not? |
191 | virtual bool ShouldInheritColours() const { return false; } | |
192 | ||
049908c5 VS |
193 | virtual bool IsClientAreaChild(const wxWindow *child) const |
194 | { | |
195 | #if wxUSE_SCROLLBAR | |
196 | if ( child == (wxWindow*)m_scrollbarHorz || | |
197 | child == (wxWindow*)m_scrollbarVert ) | |
198 | return false; | |
199 | #endif | |
200 | return wxWindowNative::IsClientAreaChild(child); | |
201 | } | |
202 | ||
1e6feb95 VZ |
203 | protected: |
204 | // common part of all ctors | |
205 | void Init(); | |
206 | ||
6f02a879 VZ |
207 | #if wxUSE_MENUS |
208 | virtual bool DoPopupMenu(wxMenu *menu, int x, int y); | |
209 | #endif // wxUSE_MENUS | |
1e6feb95 VZ |
210 | |
211 | // we deal with the scrollbars in these functions | |
212 | virtual void DoSetClientSize(int width, int height); | |
213 | virtual void DoGetClientSize(int *width, int *height) const; | |
214 | virtual wxHitTest DoHitTest(wxCoord x, wxCoord y) const; | |
215 | ||
216 | // event handlers | |
217 | void OnSize(wxSizeEvent& event); | |
3795cdba | 218 | void OnNcPaint(wxNcPaintEvent& event); |
1e6feb95 VZ |
219 | void OnPaint(wxPaintEvent& event); |
220 | void OnErase(wxEraseEvent& event); | |
221 | ||
222 | #if wxUSE_ACCEL || wxUSE_MENUS | |
223 | void OnKeyDown(wxKeyEvent& event); | |
224 | #endif // wxUSE_ACCEL | |
225 | ||
226 | #if wxUSE_MENUS | |
227 | void OnChar(wxKeyEvent& event); | |
228 | void OnKeyUp(wxKeyEvent& event); | |
229 | #endif // wxUSE_MENUS | |
230 | ||
a290fa5a | 231 | // draw the control background, return true if done |
1e6feb95 VZ |
232 | virtual bool DoDrawBackground(wxDC& dc); |
233 | ||
234 | // draw the controls border | |
235 | virtual void DoDrawBorder(wxDC& dc, const wxRect& rect); | |
236 | ||
237 | // draw the controls contents | |
238 | virtual void DoDraw(wxControlRenderer *renderer); | |
239 | ||
240 | // calculate the best size for the client area of the window: default | |
241 | // implementation of DoGetBestSize() uses this method and adds the border | |
242 | // width to the result | |
243 | virtual wxSize DoGetBestClientSize() const; | |
244 | virtual wxSize DoGetBestSize() const; | |
245 | ||
2c1a1ed1 VZ |
246 | // override the base class method to return the size of the window borders |
247 | virtual wxSize DoGetBorderSize() const; | |
248 | ||
1e6feb95 VZ |
249 | // adjust the size of the window to take into account its borders |
250 | wxSize AdjustSize(const wxSize& size) const; | |
251 | ||
252 | // put the scrollbars along the edges of the window | |
253 | void PositionScrollbars(); | |
254 | ||
255 | #if wxUSE_MENUS | |
256 | // return the menubar of the parent frame or NULL | |
257 | wxMenuBar *GetParentFrameMenuBar() const; | |
258 | #endif // wxUSE_MENUS | |
259 | ||
260 | // the renderer we use | |
261 | wxRenderer *m_renderer; | |
4cc4e7b6 | 262 | |
1e6feb95 VZ |
263 | // background bitmap info |
264 | wxBitmap m_bitmapBg; | |
265 | int m_alignBgBitmap; | |
266 | wxStretch m_stretchBgBitmap; | |
4cc4e7b6 | 267 | |
aae73669 RR |
268 | // old size |
269 | wxSize m_oldSize; | |
1e6feb95 | 270 | |
23895080 VZ |
271 | // is the mouse currently inside the window? |
272 | bool m_isCurrent:1; | |
1e6feb95 | 273 | |
30827629 | 274 | #ifdef __WXMSW__ |
e9efd3f5 | 275 | public: |
30827629 | 276 | // override MSWWindowProc() to process WM_NCHITTEST |
c140b7e7 | 277 | WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam); |
30827629 VZ |
278 | #endif // __WXMSW__ |
279 | ||
1e6feb95 | 280 | private: |
9a6384ca WS |
281 | |
282 | #if wxUSE_SCROLLBAR | |
1e6feb95 VZ |
283 | // the window scrollbars |
284 | wxScrollBar *m_scrollbarHorz, | |
285 | *m_scrollbarVert; | |
9a6384ca | 286 | #endif // wxUSE_SCROLLBAR |
1e6feb95 | 287 | |
1e6feb95 VZ |
288 | #if wxUSE_MENUS |
289 | // the current modal event loop for the popup menu we show or NULL | |
290 | static wxEventLoop *ms_evtLoopPopup; | |
291 | ||
292 | // the last window over which Alt was pressed (used by OnKeyUp) | |
293 | static wxWindow *ms_winLastAltPress; | |
294 | #endif // wxUSE_MENUS | |
295 | ||
296 | DECLARE_DYNAMIC_CLASS(wxWindow) | |
297 | DECLARE_EVENT_TABLE() | |
298 | }; | |
299 | ||
300 | #endif // _WX_UNIV_WINDOW_H_ |