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 WXDLLIMPEXP_FWD_CORE wxControlRenderer
;
20 class WXDLLIMPEXP_FWD_CORE wxEventLoop
;
23 class WXDLLIMPEXP_FWD_CORE wxMenu
;
24 class WXDLLIMPEXP_FWD_CORE wxMenuBar
;
27 class WXDLLIMPEXP_FWD_CORE wxRenderer
;
30 class WXDLLIMPEXP_FWD_CORE 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(__WXX11__)
48 #define wxWindowNative wxWindowX11
49 #elif defined(__WXMAC__)
50 #define wxWindowNative wxWindowMac
53 class WXDLLIMPEXP_CORE wxWindow
: public wxWindowNative
56 // ctors and create functions
57 // ---------------------------
59 wxWindow() { Init(); }
61 wxWindow(wxWindow
*parent
,
63 const wxPoint
& pos
= wxDefaultPosition
,
64 const wxSize
& size
= wxDefaultSize
,
66 const wxString
& name
= wxPanelNameStr
)
67 : wxWindowNative(parent
, id
, pos
, size
, style
| wxCLIP_CHILDREN
, name
)
70 bool Create(wxWindow
*parent
,
72 const wxPoint
& pos
= wxDefaultPosition
,
73 const wxSize
& size
= wxDefaultSize
,
75 const wxString
& name
= wxPanelNameStr
);
79 // background pixmap support
80 // -------------------------
82 virtual void SetBackground(const wxBitmap
& bitmap
,
83 int alignment
= wxALIGN_CENTRE
,
84 wxStretch stretch
= wxSTRETCH_NOT
);
86 const wxBitmap
& GetBackgroundBitmap(int *alignment
= NULL
,
87 wxStretch
*stretch
= NULL
) const;
89 // scrollbars: we (re)implement it ourselves using our own scrollbars
90 // instead of the native ones
91 // ------------------------------------------------------------------
93 virtual void SetScrollbar(int orient
,
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
);
105 // take into account the borders here
106 virtual wxPoint
GetClientAreaOrigin() const;
108 // popup menu support
109 // ------------------
111 // NB: all menu related functions are implemented in menu.cpp
114 // this is wxUniv-specific private method to be used only by wxMenu
115 void DismissPopupMenu();
116 #endif // wxUSE_MENUS
118 // miscellaneous other methods
119 // ---------------------------
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;
127 // return all state flags at once (combination of wxCONTROL_XXX values)
128 int GetStateFlags() const;
130 // set the "highlighted" flag and return true if it changed
131 virtual bool SetCurrent(bool doit
= true);
134 // get the scrollbar (may be NULL) for the given orientation
135 wxScrollBar
*GetScrollbar(int orient
) const
137 return orient
& wxVERTICAL
? m_scrollbarVert
: m_scrollbarHorz
;
139 #endif // wxUSE_SCROLLBAR
141 // methods used by wxColourScheme to choose the colours for this window
142 // --------------------------------------------------------------------
144 // return true if this is a panel/canvas window which contains other
146 virtual bool IsCanvasWindow() const { return false; }
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; }
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
; }
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; }
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
; }
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
);
170 // after scrollbars are added or removed they must be refreshed by calling
172 void RefreshScrollbars();
174 // erase part of the control
175 virtual void EraseBackground(wxDC
& dc
, const wxRect
& rect
);
177 // overridden base class methods
178 // -----------------------------
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
);
185 // we refresh the window when it is dis/enabled
186 virtual bool Enable(bool enable
= true);
188 // should we use the standard control colours or not?
189 virtual bool ShouldInheritColours() const { return false; }
191 virtual bool IsClientAreaChild(const wxWindow
*child
) const
194 if ( child
== (wxWindow
*)m_scrollbarHorz
||
195 child
== (wxWindow
*)m_scrollbarVert
)
198 return wxWindowNative::IsClientAreaChild(child
);
202 // common part of all ctors
206 virtual bool DoPopupMenu(wxMenu
*menu
, int x
, int y
);
207 #endif // wxUSE_MENUS
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;
215 void OnSize(wxSizeEvent
& event
);
216 void OnNcPaint(wxNcPaintEvent
& event
);
217 void OnPaint(wxPaintEvent
& event
);
218 void OnErase(wxEraseEvent
& event
);
220 #if wxUSE_ACCEL || wxUSE_MENUS
221 void OnKeyDown(wxKeyEvent
& event
);
222 #endif // wxUSE_ACCEL
225 void OnChar(wxKeyEvent
& event
);
226 void OnKeyUp(wxKeyEvent
& event
);
227 #endif // wxUSE_MENUS
229 // draw the control background, return true if done
230 virtual bool DoDrawBackground(wxDC
& dc
);
232 // draw the controls border
233 virtual void DoDrawBorder(wxDC
& dc
, const wxRect
& rect
);
235 // draw the controls contents
236 virtual void DoDraw(wxControlRenderer
*renderer
);
238 // override the base class method to return the size of the window borders
239 virtual wxSize
DoGetBorderSize() const;
241 // adjust the size of the window to take into account its borders
242 wxSize
AdjustSize(const wxSize
& size
) const;
244 // put the scrollbars along the edges of the window
245 void PositionScrollbars();
248 // return the menubar of the parent frame or NULL
249 wxMenuBar
*GetParentFrameMenuBar() const;
250 #endif // wxUSE_MENUS
252 // the renderer we use
253 wxRenderer
*m_renderer
;
255 // background bitmap info
258 wxStretch m_stretchBgBitmap
;
263 // is the mouse currently inside the window?
268 // override MSWWindowProc() to process WM_NCHITTEST
269 WXLRESULT
MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
);
275 // the window scrollbars
276 wxScrollBar
*m_scrollbarHorz
,
278 #endif // wxUSE_SCROLLBAR
281 // the current modal event loop for the popup menu we show or NULL
282 static wxEventLoop
*ms_evtLoopPopup
;
284 // the last window over which Alt was pressed (used by OnKeyUp)
285 static wxWindow
*ms_winLastAltPress
;
286 #endif // wxUSE_MENUS
288 DECLARE_DYNAMIC_CLASS(wxWindow
)
289 DECLARE_EVENT_TABLE()
292 #endif // _WX_UNIV_WINDOW_H_