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