]>
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$ | |
10 | // Copyright: (c) 2000 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
11 | // Licence: wxWindows license | |
12 | /////////////////////////////////////////////////////////////////////////////// | |
13 | ||
14 | #ifndef _WX_UNIV_WINDOW_H_ | |
15 | #define _WX_UNIV_WINDOW_H_ | |
16 | ||
17 | #ifdef __GNUG__ | |
18 | #pragma interface "univwindow.h" | |
19 | #endif | |
20 | ||
21 | #include "wx/bitmap.h" // for m_bitmapBg | |
22 | ||
23 | class WXDLLEXPORT wxControlRenderer; | |
24 | class WXDLLEXPORT wxEventLoop; | |
25 | class WXDLLEXPORT wxMenu; | |
26 | class WXDLLEXPORT wxMenuBar; | |
27 | class WXDLLEXPORT wxRenderer; | |
28 | class WXDLLEXPORT wxScrollBar; | |
29 | ||
30 | // ---------------------------------------------------------------------------- | |
31 | // constants | |
32 | // ---------------------------------------------------------------------------- | |
33 | ||
34 | // control state flags used in wxRenderer and wxColourScheme | |
35 | enum | |
36 | { | |
37 | wxCONTROL_DISABLED = 0x00000001, // control is disabled | |
38 | wxCONTROL_FOCUSED = 0x00000002, // currently has keyboard focus | |
39 | wxCONTROL_PRESSED = 0x00000004, // (button) is pressed | |
40 | wxCONTROL_ISDEFAULT = 0x00000008, // only applies to the buttons | |
41 | wxCONTROL_ISSUBMENU = wxCONTROL_ISDEFAULT, // only for menu items | |
42 | wxCONTROL_CURRENT = 0x00000010, // mouse is currently over the control | |
43 | wxCONTROL_SELECTED = 0x00000020, // selected item in e.g. listbox | |
44 | wxCONTROL_CHECKED = 0x00000040, // (check/radio button) is checked | |
45 | wxCONTROL_CHECKABLE = 0x00000080, // (menu) item can be checked | |
46 | ||
47 | wxCONTROL_FLAGS_MASK = 0x000000ff, | |
48 | ||
49 | // this is a pseudo flag not used directly by wxRenderer but rather by some | |
50 | // controls internally | |
51 | wxCONTROL_DIRTY = 0x80000000 | |
52 | }; | |
53 | ||
54 | // ---------------------------------------------------------------------------- | |
55 | // wxWindow | |
56 | // ---------------------------------------------------------------------------- | |
57 | ||
58 | class WXDLLEXPORT wxWindow : public wxWindowNative | |
59 | { | |
60 | public: | |
61 | // ctors and creatie functions | |
62 | // --------------------------- | |
63 | ||
64 | wxWindow() { Init(); } | |
65 | ||
66 | wxWindow(wxWindow *parent, | |
67 | wxWindowID id, | |
68 | const wxPoint& pos = wxDefaultPosition, | |
69 | const wxSize& size = wxDefaultSize, | |
70 | long style = 0, | |
71 | const wxString& name = wxPanelNameStr) | |
72 | : wxWindowNative(parent, id, pos, size, style | wxCLIP_CHILDREN, name) | |
73 | { Init(); } | |
74 | ||
75 | bool Create(wxWindow *parent, | |
76 | wxWindowID id, | |
77 | const wxPoint& pos = wxDefaultPosition, | |
78 | const wxSize& size = wxDefaultSize, | |
79 | long style = 0, | |
80 | const wxString& name = wxPanelNameStr); | |
81 | ||
82 | // background pixmap support | |
83 | // ------------------------- | |
84 | ||
85 | virtual void SetBackground(const wxBitmap& bitmap, | |
86 | int alignment = wxALIGN_CENTRE, | |
87 | wxStretch stretch = wxSTRETCH_NOT); | |
88 | ||
89 | const wxBitmap& GetBackgroundBitmap(int *alignment = NULL, | |
90 | wxStretch *stretch = NULL) const; | |
91 | ||
92 | // scrollbars: we (re)implement it ourselves using our own scrollbars | |
93 | // instead of the native ones | |
94 | // ------------------------------------------------------------------ | |
95 | ||
96 | virtual void SetScrollbar(int orient, | |
97 | int pos, | |
98 | int page, | |
99 | int range, | |
100 | bool refresh = TRUE ); | |
101 | virtual void SetScrollPos(int orient, int pos, bool refresh = TRUE); | |
102 | virtual int GetScrollPos(int orient) const; | |
103 | virtual int GetScrollThumb(int orient) const; | |
104 | virtual int GetScrollRange(int orient) const; | |
105 | virtual void ScrollWindow(int dx, int dy, | |
106 | const wxRect* rect = (wxRect *) NULL); | |
107 | ||
108 | // take into account the borders here | |
109 | virtual wxPoint GetClientAreaOrigin() const; | |
110 | ||
111 | // popup menu support | |
112 | // ------------------ | |
113 | ||
114 | // NB: all menu related functions are implemented in menu.cpp | |
115 | ||
116 | #if wxUSE_MENUS | |
117 | virtual bool DoPopupMenu(wxMenu *menu, int x, int y); | |
118 | ||
119 | // this is wxUniv-specific private method to be used only by wxMenu | |
120 | void DismissPopupMenu(); | |
121 | #endif // wxUSE_MENUS | |
122 | ||
123 | // miscellaneous other methods | |
124 | // --------------------------- | |
125 | ||
126 | // get the state information | |
127 | virtual bool IsFocused() const; | |
128 | virtual bool IsCurrent() const; | |
129 | virtual bool IsPressed() const; | |
130 | virtual bool IsDefault() const; | |
131 | ||
132 | // return all state flags at once (combination of wxCONTROL_XXX values) | |
133 | int GetStateFlags() const; | |
134 | ||
135 | // set the "highlighted" flag and return TRUE if it changed | |
136 | virtual bool SetCurrent(bool doit = TRUE); | |
137 | ||
138 | // get the scrollbar (may be NULL) for the given orientation | |
139 | wxScrollBar *GetScrollbar(int orient) const | |
140 | { | |
141 | return orient & wxVERTICAL ? m_scrollbarVert : m_scrollbarHorz; | |
142 | } | |
143 | ||
144 | // methods used by wxColourScheme to choose the colours for this window | |
145 | // -------------------------------------------------------------------- | |
146 | ||
147 | // return TRUE if this is a panel/canvas window which contains other | |
148 | // controls only | |
149 | virtual bool IsCanvasWindow() const { return FALSE; } | |
150 | ||
151 | // return TRUE if this a container window which contains the other items: | |
152 | // e.g, a listbox, listctrl, treectrl, ... and FALSE if it is a monolithic | |
153 | // control (e.g. a button, checkbox, ...) | |
154 | virtual bool IsContainerWindow() const { return FALSE; } | |
155 | ||
156 | // return TRUE if this control can be highlighted when the mouse is over | |
157 | // it (the theme decides itself whether it is really highlighted or not) | |
158 | virtual bool CanBeHighlighted() const { return FALSE; } | |
159 | ||
160 | // return TRUE if we should use the colours/fonts returned by the | |
161 | // corresponding GetXXX() methods instead of the default ones | |
162 | bool UseBgCol() const { return m_hasBgCol; } | |
163 | bool UseFgCol() const { return m_hasFgCol; } | |
164 | bool UseFont() const { return m_hasFont; } | |
165 | ||
166 | // returns the (low level) renderer to use for drawing the control by | |
167 | // querying the current theme | |
168 | wxRenderer *GetRenderer() const { return m_renderer; } | |
169 | ||
170 | // scrolling helper: like ScrollWindow() except that it doesn't refresh the | |
171 | // uncovered window areas but returns the rectangle to update (don't call | |
172 | // this with both dx and dy non zero) | |
173 | wxRect ScrollNoRefresh(int dx, int dy, const wxRect *rect = NULL); | |
174 | ||
175 | // after scrollbars are added or removed they must be refreshed by calling | |
176 | // this function | |
177 | void RefreshScrollbars(); | |
178 | ||
179 | // erase part of the control | |
180 | virtual void EraseBackground(wxDC& dc, const wxRect& rect); | |
181 | ||
182 | // overridden base class methods | |
183 | // ----------------------------- | |
184 | ||
185 | // the rect coordinates are, for us, in client coords, but if no rect is | |
186 | // specified, the entire window is refreshed | |
187 | virtual void Refresh(bool eraseBackground = TRUE, | |
188 | const wxRect *rect = (const wxRect *) NULL); | |
189 | ||
190 | // we refresh the window when it is dis/enabled | |
191 | virtual bool Enable(bool enable = TRUE); | |
192 | ||
193 | // remember that the font/colour was changed | |
194 | virtual bool SetBackgroundColour(const wxColour& colour); | |
195 | virtual bool SetForegroundColour(const wxColour& colour); | |
196 | virtual bool SetFont(const wxFont& font); | |
197 | ||
198 | // our Capture/ReleaseMouse() maintains the stack of windows which had | |
199 | // captured the mouse and when ReleaseMouse() is called, the mouse freed | |
200 | // only if the stack is empty, otherwise it is captured back by the window | |
201 | // on top of the stack | |
202 | virtual void CaptureMouse(); | |
203 | virtual void ReleaseMouse(); | |
204 | ||
205 | protected: | |
206 | // common part of all ctors | |
207 | void Init(); | |
208 | ||
209 | // overridden base class virtuals | |
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); | |
218 | void OnNcPaint(wxPaintEvent& event); | |
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 | ||
231 | // draw the control background, return TRUE if done | |
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 | ||
246 | // adjust the size of the window to take into account its borders | |
247 | wxSize AdjustSize(const wxSize& size) const; | |
248 | ||
249 | // put the scrollbars along the edges of the window | |
250 | void PositionScrollbars(); | |
251 | ||
252 | #if wxUSE_MENUS | |
253 | // return the menubar of the parent frame or NULL | |
254 | wxMenuBar *GetParentFrameMenuBar() const; | |
255 | #endif // wxUSE_MENUS | |
256 | ||
257 | // the renderer we use | |
258 | wxRenderer *m_renderer; | |
259 | ||
260 | // background bitmap info | |
261 | wxBitmap m_bitmapBg; | |
262 | int m_alignBgBitmap; | |
263 | wxStretch m_stretchBgBitmap; | |
264 | ||
265 | // more flags | |
266 | bool m_isCurrent:1; // is the mouse currently inside the window? | |
267 | bool m_hasBgCol:1; // was the bg colour explicitly changed by user? | |
268 | bool m_hasFgCol:1; // fg | |
269 | bool m_hasFont:1; // font | |
270 | ||
271 | private: | |
272 | // the window scrollbars | |
273 | wxScrollBar *m_scrollbarHorz, | |
274 | *m_scrollbarVert; | |
275 | ||
276 | // the stack of windows which have captured the mouse | |
277 | static struct WXDLLEXPORT wxWindowNext *ms_winCaptureNext; | |
278 | ||
279 | #if wxUSE_MENUS | |
280 | // the current modal event loop for the popup menu we show or NULL | |
281 | static wxEventLoop *ms_evtLoopPopup; | |
282 | ||
283 | // the last window over which Alt was pressed (used by OnKeyUp) | |
284 | static wxWindow *ms_winLastAltPress; | |
285 | #endif // wxUSE_MENUS | |
286 | ||
287 | DECLARE_DYNAMIC_CLASS(wxWindow) | |
288 | DECLARE_EVENT_TABLE() | |
289 | }; | |
290 | ||
291 | #endif // _WX_UNIV_WINDOW_H_ | |
292 |