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
10 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
11 // Licence: wxWindows licence
12 ///////////////////////////////////////////////////////////////////////////////
14 #ifndef _WX_UNIV_WINDOW_H_
15 #define _WX_UNIV_WINDOW_H_
17 #include "wx/bitmap.h" // for m_bitmapBg
19 class WXDLLEXPORT wxControlRenderer
;
20 class WXDLLEXPORT wxEventLoop
;
23 class WXDLLEXPORT wxMenu
;
24 class WXDLLEXPORT wxMenuBar
;
27 class WXDLLEXPORT wxRenderer
;
30 class WXDLLEXPORT wxScrollBar
;
31 #endif // wxUSE_SCROLLBAR
34 #define wxUSE_TWO_WINDOWS 1
36 #define wxUSE_TWO_WINDOWS 0
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 #if defined(__WXMSW__)
44 #define wxWindowNative wxWindowMSW
45 #elif defined(__WXGTK__)
46 #define wxWindowNative wxWindowGTK
47 #elif defined(__WXMGL__)
48 #define wxWindowNative wxWindowMGL
49 #elif defined(__WXX11__)
50 #define wxWindowNative wxWindowX11
51 #elif defined(__WXMAC__)
52 #define wxWindowNative wxWindowMac
55 class WXDLLEXPORT wxWindow
: public wxWindowNative
58 // ctors and create functions
59 // ---------------------------
61 wxWindow() { Init(); }
63 wxWindow(wxWindow
*parent
,
65 const wxPoint
& pos
= wxDefaultPosition
,
66 const wxSize
& size
= wxDefaultSize
,
68 const wxString
& name
= wxPanelNameStr
)
69 : wxWindowNative(parent
, id
, pos
, size
, style
| wxCLIP_CHILDREN
, name
)
72 bool Create(wxWindow
*parent
,
74 const wxPoint
& pos
= wxDefaultPosition
,
75 const wxSize
& size
= wxDefaultSize
,
77 const wxString
& name
= wxPanelNameStr
);
81 // background pixmap support
82 // -------------------------
84 virtual void SetBackground(const wxBitmap
& bitmap
,
85 int alignment
= wxALIGN_CENTRE
,
86 wxStretch stretch
= wxSTRETCH_NOT
);
88 const wxBitmap
& GetBackgroundBitmap(int *alignment
= NULL
,
89 wxStretch
*stretch
= NULL
) const;
91 // scrollbars: we (re)implement it ourselves using our own scrollbars
92 // instead of the native ones
93 // ------------------------------------------------------------------
95 virtual void SetScrollbar(int orient
,
99 bool refresh
= true );
100 virtual void SetScrollPos(int orient
, int pos
, bool refresh
= true);
101 virtual int GetScrollPos(int orient
) const;
102 virtual int GetScrollThumb(int orient
) const;
103 virtual int GetScrollRange(int orient
) const;
104 virtual void ScrollWindow(int dx
, int dy
,
105 const wxRect
* rect
= (wxRect
*) NULL
);
107 // take into account the borders here
108 virtual wxPoint
GetClientAreaOrigin() const;
110 // popup menu support
111 // ------------------
113 // NB: all menu related functions are implemented in menu.cpp
116 // this is wxUniv-specific private method to be used only by wxMenu
117 void DismissPopupMenu();
118 #endif // wxUSE_MENUS
120 // miscellaneous other methods
121 // ---------------------------
123 // get the state information
124 virtual bool IsFocused() const;
125 virtual bool IsCurrent() const;
126 virtual bool IsPressed() const;
127 virtual bool IsDefault() const;
129 // return all state flags at once (combination of wxCONTROL_XXX values)
130 int GetStateFlags() const;
132 // set the "highlighted" flag and return true if it changed
133 virtual bool SetCurrent(bool doit
= true);
136 // get the scrollbar (may be NULL) for the given orientation
137 wxScrollBar
*GetScrollbar(int orient
) const
139 return orient
& wxVERTICAL
? m_scrollbarVert
: m_scrollbarHorz
;
141 #endif // wxUSE_SCROLLBAR
143 // methods used by wxColourScheme to choose the colours for this window
144 // --------------------------------------------------------------------
146 // return true if this is a panel/canvas window which contains other
148 virtual bool IsCanvasWindow() const { return false; }
150 // return true if this control can be highlighted when the mouse is over
151 // it (the theme decides itself whether it is really highlighted or not)
152 virtual bool CanBeHighlighted() const { return false; }
154 // return true if we should use the colours/fonts returned by the
155 // corresponding GetXXX() methods instead of the default ones
156 bool UseFgCol() const { return m_hasFgCol
; }
157 bool UseFont() const { return m_hasFont
; }
159 // return true if this window serves as a container for the other windows
160 // only and doesn't get any input itself
161 virtual bool IsStaticBox() const { return false; }
163 // returns the (low level) renderer to use for drawing the control by
164 // querying the current theme
165 wxRenderer
*GetRenderer() const { return m_renderer
; }
167 // scrolling helper: like ScrollWindow() except that it doesn't refresh the
168 // uncovered window areas but returns the rectangle to update (don't call
169 // this with both dx and dy non zero)
170 wxRect
ScrollNoRefresh(int dx
, int dy
, const wxRect
*rect
= NULL
);
172 // after scrollbars are added or removed they must be refreshed by calling
174 void RefreshScrollbars();
176 // erase part of the control
177 virtual void EraseBackground(wxDC
& dc
, const wxRect
& rect
);
179 // overridden base class methods
180 // -----------------------------
182 // the rect coordinates are, for us, in client coords, but if no rect is
183 // specified, the entire window is refreshed
184 virtual void Refresh(bool eraseBackground
= true,
185 const wxRect
*rect
= (const wxRect
*) NULL
);
187 // we refresh the window when it is dis/enabled
188 virtual bool Enable(bool enable
= true);
190 // should we use the standard control colours or not?
191 virtual bool ShouldInheritColours() const { return false; }
194 // common part of all ctors
198 virtual bool DoPopupMenu(wxMenu
*menu
, int x
, int y
);
199 #endif // wxUSE_MENUS
201 // we deal with the scrollbars in these functions
202 virtual void DoSetClientSize(int width
, int height
);
203 virtual void DoGetClientSize(int *width
, int *height
) const;
204 virtual wxHitTest
DoHitTest(wxCoord x
, wxCoord y
) const;
207 void OnSize(wxSizeEvent
& event
);
208 void OnNcPaint(wxNcPaintEvent
& event
);
209 void OnPaint(wxPaintEvent
& event
);
210 void OnErase(wxEraseEvent
& event
);
212 #if wxUSE_ACCEL || wxUSE_MENUS
213 void OnKeyDown(wxKeyEvent
& event
);
214 #endif // wxUSE_ACCEL
217 void OnChar(wxKeyEvent
& event
);
218 void OnKeyUp(wxKeyEvent
& event
);
219 #endif // wxUSE_MENUS
221 // draw the control background, return true if done
222 virtual bool DoDrawBackground(wxDC
& dc
);
224 // draw the controls border
225 virtual void DoDrawBorder(wxDC
& dc
, const wxRect
& rect
);
227 // draw the controls contents
228 virtual void DoDraw(wxControlRenderer
*renderer
);
230 // calculate the best size for the client area of the window: default
231 // implementation of DoGetBestSize() uses this method and adds the border
232 // width to the result
233 virtual wxSize
DoGetBestClientSize() const;
234 virtual wxSize
DoGetBestSize() const;
236 // adjust the size of the window to take into account its borders
237 wxSize
AdjustSize(const wxSize
& size
) const;
239 // put the scrollbars along the edges of the window
240 void PositionScrollbars();
243 // return the menubar of the parent frame or NULL
244 wxMenuBar
*GetParentFrameMenuBar() const;
245 #endif // wxUSE_MENUS
247 // the renderer we use
248 wxRenderer
*m_renderer
;
250 // background bitmap info
253 wxStretch m_stretchBgBitmap
;
258 // is the mouse currently inside the window?
263 // override MSWWindowProc() to process WM_NCHITTEST
264 WXLRESULT
MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
);
270 // the window scrollbars
271 wxScrollBar
*m_scrollbarHorz
,
273 #endif // wxUSE_SCROLLBAR
276 // the current modal event loop for the popup menu we show or NULL
277 static wxEventLoop
*ms_evtLoopPopup
;
279 // the last window over which Alt was pressed (used by OnKeyUp)
280 static wxWindow
*ms_winLastAltPress
;
281 #endif // wxUSE_MENUS
283 DECLARE_DYNAMIC_CLASS(wxWindow
)
284 DECLARE_EVENT_TABLE()
287 #endif // _WX_UNIV_WINDOW_H_