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