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