]>
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) |
1e6feb95 VZ |
11 | // Licence: wxWindows license |
12 | /////////////////////////////////////////////////////////////////////////////// | |
13 | ||
14 | #ifndef _WX_UNIV_WINDOW_H_ | |
15 | #define _WX_UNIV_WINDOW_H_ | |
16 | ||
17 | #ifdef __GNUG__ | |
196cc38b | 18 | #pragma interface "univwindow.h" |
1e6feb95 VZ |
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 | ||
ab6b6b15 RR |
54 | #ifdef __WXX11__ |
55 | #define wxUSE_TWO_WINDOWS 1 | |
56 | #else | |
57 | #define wxUSE_TWO_WINDOWS 0 | |
58 | #endif | |
59 | ||
1e6feb95 VZ |
60 | // ---------------------------------------------------------------------------- |
61 | // wxWindow | |
62 | // ---------------------------------------------------------------------------- | |
63 | ||
24ce4c18 JS |
64 | #if defined(__WXMSW__) |
65 | #define wxWindowNative wxWindowMSW | |
66 | #elif defined(__WXGTK__) | |
67 | #define wxWindowNative wxWindowGTK | |
68 | #elif defined(__WXMGL__) | |
69 | #define wxWindowNative wxWindowMGL | |
1b0b798d RR |
70 | #elif defined(__WXX11__) |
71 | #define wxWindowNative wxWindowX11 | |
e766c8a9 SC |
72 | #elif defined(__WXMAC__) |
73 | #define wxWindowNative wxWindowMac | |
24ce4c18 JS |
74 | #endif |
75 | ||
1e6feb95 VZ |
76 | class WXDLLEXPORT wxWindow : public wxWindowNative |
77 | { | |
78 | public: | |
1a77875b | 79 | // ctors and create functions |
1e6feb95 VZ |
80 | // --------------------------- |
81 | ||
82 | wxWindow() { Init(); } | |
83 | ||
84 | wxWindow(wxWindow *parent, | |
85 | wxWindowID id, | |
86 | const wxPoint& pos = wxDefaultPosition, | |
87 | const wxSize& size = wxDefaultSize, | |
88 | long style = 0, | |
89 | const wxString& name = wxPanelNameStr) | |
90 | : wxWindowNative(parent, id, pos, size, style | wxCLIP_CHILDREN, name) | |
91 | { Init(); } | |
92 | ||
93 | bool Create(wxWindow *parent, | |
94 | wxWindowID id, | |
95 | const wxPoint& pos = wxDefaultPosition, | |
96 | const wxSize& size = wxDefaultSize, | |
97 | long style = 0, | |
98 | const wxString& name = wxPanelNameStr); | |
99 | ||
100 | // background pixmap support | |
101 | // ------------------------- | |
102 | ||
103 | virtual void SetBackground(const wxBitmap& bitmap, | |
104 | int alignment = wxALIGN_CENTRE, | |
105 | wxStretch stretch = wxSTRETCH_NOT); | |
106 | ||
107 | const wxBitmap& GetBackgroundBitmap(int *alignment = NULL, | |
108 | wxStretch *stretch = NULL) const; | |
109 | ||
110 | // scrollbars: we (re)implement it ourselves using our own scrollbars | |
111 | // instead of the native ones | |
112 | // ------------------------------------------------------------------ | |
113 | ||
114 | virtual void SetScrollbar(int orient, | |
115 | int pos, | |
116 | int page, | |
117 | int range, | |
118 | bool refresh = TRUE ); | |
119 | virtual void SetScrollPos(int orient, int pos, bool refresh = TRUE); | |
120 | virtual int GetScrollPos(int orient) const; | |
121 | virtual int GetScrollThumb(int orient) const; | |
122 | virtual int GetScrollRange(int orient) const; | |
123 | virtual void ScrollWindow(int dx, int dy, | |
124 | const wxRect* rect = (wxRect *) NULL); | |
125 | ||
126 | // take into account the borders here | |
127 | virtual wxPoint GetClientAreaOrigin() const; | |
128 | ||
129 | // popup menu support | |
130 | // ------------------ | |
131 | ||
132 | // NB: all menu related functions are implemented in menu.cpp | |
133 | ||
134 | #if wxUSE_MENUS | |
135 | virtual bool DoPopupMenu(wxMenu *menu, int x, int y); | |
136 | ||
137 | // this is wxUniv-specific private method to be used only by wxMenu | |
138 | void DismissPopupMenu(); | |
139 | #endif // wxUSE_MENUS | |
140 | ||
141 | // miscellaneous other methods | |
142 | // --------------------------- | |
143 | ||
144 | // get the state information | |
145 | virtual bool IsFocused() const; | |
146 | virtual bool IsCurrent() const; | |
147 | virtual bool IsPressed() const; | |
148 | virtual bool IsDefault() const; | |
149 | ||
150 | // return all state flags at once (combination of wxCONTROL_XXX values) | |
151 | int GetStateFlags() const; | |
152 | ||
153 | // set the "highlighted" flag and return TRUE if it changed | |
154 | virtual bool SetCurrent(bool doit = TRUE); | |
155 | ||
156 | // get the scrollbar (may be NULL) for the given orientation | |
157 | wxScrollBar *GetScrollbar(int orient) const | |
158 | { | |
159 | return orient & wxVERTICAL ? m_scrollbarVert : m_scrollbarHorz; | |
160 | } | |
161 | ||
162 | // methods used by wxColourScheme to choose the colours for this window | |
163 | // -------------------------------------------------------------------- | |
164 | ||
165 | // return TRUE if this is a panel/canvas window which contains other | |
166 | // controls only | |
167 | virtual bool IsCanvasWindow() const { return FALSE; } | |
168 | ||
169 | // return TRUE if this a container window which contains the other items: | |
170 | // e.g, a listbox, listctrl, treectrl, ... and FALSE if it is a monolithic | |
171 | // control (e.g. a button, checkbox, ...) | |
172 | virtual bool IsContainerWindow() const { return FALSE; } | |
173 | ||
193e19cf RR |
174 | // returns TRUE if the control has "transparent" areas such |
175 | // as a wxStaticText and wxCheckBox and the background should | |
176 | // be adapted from a parent window | |
177 | virtual bool HasTransparentBackground() { return FALSE; } | |
178 | ||
179 | // to be used with function above: transparent windows get | |
180 | // their background from parents that return TRUE here, | |
181 | // so this is mostly for wxPanel, wxTopLevelWindow etc. | |
2b5f62a0 | 182 | virtual bool ProvidesBackground() const { return FALSE; } |
193e19cf | 183 | |
1e6feb95 VZ |
184 | // return TRUE if this control can be highlighted when the mouse is over |
185 | // it (the theme decides itself whether it is really highlighted or not) | |
186 | virtual bool CanBeHighlighted() const { return FALSE; } | |
187 | ||
188 | // return TRUE if we should use the colours/fonts returned by the | |
189 | // corresponding GetXXX() methods instead of the default ones | |
190 | bool UseBgCol() const { return m_hasBgCol; } | |
191 | bool UseFgCol() const { return m_hasFgCol; } | |
192 | bool UseFont() const { return m_hasFont; } | |
193 | ||
30827629 VZ |
194 | // return TRUE if this window serves as a container for the other windows |
195 | // only and doesn't get any input itself | |
196 | virtual bool IsStaticBox() const { return FALSE; } | |
197 | ||
1e6feb95 VZ |
198 | // returns the (low level) renderer to use for drawing the control by |
199 | // querying the current theme | |
200 | wxRenderer *GetRenderer() const { return m_renderer; } | |
201 | ||
202 | // scrolling helper: like ScrollWindow() except that it doesn't refresh the | |
203 | // uncovered window areas but returns the rectangle to update (don't call | |
204 | // this with both dx and dy non zero) | |
205 | wxRect ScrollNoRefresh(int dx, int dy, const wxRect *rect = NULL); | |
206 | ||
207 | // after scrollbars are added or removed they must be refreshed by calling | |
208 | // this function | |
209 | void RefreshScrollbars(); | |
210 | ||
211 | // erase part of the control | |
212 | virtual void EraseBackground(wxDC& dc, const wxRect& rect); | |
67d947ba | 213 | |
1e6feb95 VZ |
214 | // overridden base class methods |
215 | // ----------------------------- | |
216 | ||
217 | // the rect coordinates are, for us, in client coords, but if no rect is | |
218 | // specified, the entire window is refreshed | |
219 | virtual void Refresh(bool eraseBackground = TRUE, | |
220 | const wxRect *rect = (const wxRect *) NULL); | |
221 | ||
222 | // we refresh the window when it is dis/enabled | |
223 | virtual bool Enable(bool enable = TRUE); | |
224 | ||
1e6feb95 VZ |
225 | protected: |
226 | // common part of all ctors | |
227 | void Init(); | |
228 | ||
229 | // overridden base class virtuals | |
230 | ||
231 | // we deal with the scrollbars in these functions | |
232 | virtual void DoSetClientSize(int width, int height); | |
233 | virtual void DoGetClientSize(int *width, int *height) const; | |
234 | virtual wxHitTest DoHitTest(wxCoord x, wxCoord y) const; | |
235 | ||
236 | // event handlers | |
237 | void OnSize(wxSizeEvent& event); | |
238 | void OnNcPaint(wxPaintEvent& event); | |
239 | void OnPaint(wxPaintEvent& event); | |
240 | void OnErase(wxEraseEvent& event); | |
241 | ||
242 | #if wxUSE_ACCEL || wxUSE_MENUS | |
243 | void OnKeyDown(wxKeyEvent& event); | |
244 | #endif // wxUSE_ACCEL | |
245 | ||
246 | #if wxUSE_MENUS | |
247 | void OnChar(wxKeyEvent& event); | |
248 | void OnKeyUp(wxKeyEvent& event); | |
249 | #endif // wxUSE_MENUS | |
250 | ||
251 | // draw the control background, return TRUE if done | |
252 | virtual bool DoDrawBackground(wxDC& dc); | |
253 | ||
254 | // draw the controls border | |
255 | virtual void DoDrawBorder(wxDC& dc, const wxRect& rect); | |
256 | ||
257 | // draw the controls contents | |
258 | virtual void DoDraw(wxControlRenderer *renderer); | |
259 | ||
260 | // calculate the best size for the client area of the window: default | |
261 | // implementation of DoGetBestSize() uses this method and adds the border | |
262 | // width to the result | |
263 | virtual wxSize DoGetBestClientSize() const; | |
264 | virtual wxSize DoGetBestSize() const; | |
265 | ||
266 | // adjust the size of the window to take into account its borders | |
267 | wxSize AdjustSize(const wxSize& size) const; | |
268 | ||
269 | // put the scrollbars along the edges of the window | |
270 | void PositionScrollbars(); | |
271 | ||
272 | #if wxUSE_MENUS | |
273 | // return the menubar of the parent frame or NULL | |
274 | wxMenuBar *GetParentFrameMenuBar() const; | |
275 | #endif // wxUSE_MENUS | |
276 | ||
277 | // the renderer we use | |
278 | wxRenderer *m_renderer; | |
67d947ba | 279 | |
1e6feb95 VZ |
280 | // background bitmap info |
281 | wxBitmap m_bitmapBg; | |
282 | int m_alignBgBitmap; | |
283 | wxStretch m_stretchBgBitmap; | |
aae73669 RR |
284 | |
285 | // old size | |
286 | wxSize m_oldSize; | |
1e6feb95 | 287 | |
23895080 VZ |
288 | // is the mouse currently inside the window? |
289 | bool m_isCurrent:1; | |
1e6feb95 | 290 | |
30827629 VZ |
291 | #ifdef __WXMSW__ |
292 | // override MSWWindowProc() to process WM_NCHITTEST | |
293 | long MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam); | |
294 | #endif // __WXMSW__ | |
295 | ||
1e6feb95 VZ |
296 | private: |
297 | // the window scrollbars | |
298 | wxScrollBar *m_scrollbarHorz, | |
299 | *m_scrollbarVert; | |
300 | ||
1e6feb95 VZ |
301 | #if wxUSE_MENUS |
302 | // the current modal event loop for the popup menu we show or NULL | |
303 | static wxEventLoop *ms_evtLoopPopup; | |
304 | ||
305 | // the last window over which Alt was pressed (used by OnKeyUp) | |
306 | static wxWindow *ms_winLastAltPress; | |
307 | #endif // wxUSE_MENUS | |
308 | ||
309 | DECLARE_DYNAMIC_CLASS(wxWindow) | |
310 | DECLARE_EVENT_TABLE() | |
311 | }; | |
312 | ||
313 | #endif // _WX_UNIV_WINDOW_H_ | |
314 |