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
;
21 class WXDLLEXPORT wxMenu
;
22 class WXDLLEXPORT wxMenuBar
;
23 class WXDLLEXPORT wxRenderer
;
24 class WXDLLEXPORT wxScrollBar
;
27 #define wxUSE_TWO_WINDOWS 1
29 #define wxUSE_TWO_WINDOWS 0
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 #if defined(__WXMSW__)
37 #define wxWindowNative wxWindowMSW
38 #elif defined(__WXGTK__)
39 #define wxWindowNative wxWindowGTK
40 #elif defined(__WXMGL__)
41 #define wxWindowNative wxWindowMGL
42 #elif defined(__WXX11__)
43 #define wxWindowNative wxWindowX11
44 #elif defined(__WXMAC__)
45 #define wxWindowNative wxWindowMac
48 class WXDLLEXPORT wxWindow
: public wxWindowNative
51 // ctors and create functions
52 // ---------------------------
54 wxWindow() { Init(); }
56 wxWindow(wxWindow
*parent
,
58 const wxPoint
& pos
= wxDefaultPosition
,
59 const wxSize
& size
= wxDefaultSize
,
61 const wxString
& name
= wxPanelNameStr
)
62 : wxWindowNative(parent
, id
, pos
, size
, style
| wxCLIP_CHILDREN
, name
)
65 bool Create(wxWindow
*parent
,
67 const wxPoint
& pos
= wxDefaultPosition
,
68 const wxSize
& size
= wxDefaultSize
,
70 const wxString
& name
= wxPanelNameStr
);
74 // background pixmap support
75 // -------------------------
77 virtual void SetBackground(const wxBitmap
& bitmap
,
78 int alignment
= wxALIGN_CENTRE
,
79 wxStretch stretch
= wxSTRETCH_NOT
);
81 const wxBitmap
& GetBackgroundBitmap(int *alignment
= NULL
,
82 wxStretch
*stretch
= NULL
) const;
84 // scrollbars: we (re)implement it ourselves using our own scrollbars
85 // instead of the native ones
86 // ------------------------------------------------------------------
88 virtual void SetScrollbar(int orient
,
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
);
100 // take into account the borders here
101 virtual wxPoint
GetClientAreaOrigin() const;
103 // popup menu support
104 // ------------------
106 // NB: all menu related functions are implemented in menu.cpp
109 // this is wxUniv-specific private method to be used only by wxMenu
110 void DismissPopupMenu();
111 #endif // wxUSE_MENUS
113 // miscellaneous other methods
114 // ---------------------------
116 // get the state information
117 virtual bool IsFocused() const;
118 virtual bool IsCurrent() const;
119 virtual bool IsPressed() const;
120 virtual bool IsDefault() const;
122 // return all state flags at once (combination of wxCONTROL_XXX values)
123 int GetStateFlags() const;
125 // set the "highlighted" flag and return true if it changed
126 virtual bool SetCurrent(bool doit
= true);
128 // get the scrollbar (may be NULL) for the given orientation
129 wxScrollBar
*GetScrollbar(int orient
) const
131 return orient
& wxVERTICAL
? m_scrollbarVert
: m_scrollbarHorz
;
134 // methods used by wxColourScheme to choose the colours for this window
135 // --------------------------------------------------------------------
137 // return true if this is a panel/canvas window which contains other
139 virtual bool IsCanvasWindow() const { return false; }
141 // return true if this control can be highlighted when the mouse is over
142 // it (the theme decides itself whether it is really highlighted or not)
143 virtual bool CanBeHighlighted() const { return false; }
145 // return true if we should use the colours/fonts returned by the
146 // corresponding GetXXX() methods instead of the default ones
147 bool UseFgCol() const { return m_hasFgCol
; }
148 bool UseFont() const { return m_hasFont
; }
150 // return true if this window serves as a container for the other windows
151 // only and doesn't get any input itself
152 virtual bool IsStaticBox() const { return false; }
154 // returns the (low level) renderer to use for drawing the control by
155 // querying the current theme
156 wxRenderer
*GetRenderer() const { return m_renderer
; }
158 // scrolling helper: like ScrollWindow() except that it doesn't refresh the
159 // uncovered window areas but returns the rectangle to update (don't call
160 // this with both dx and dy non zero)
161 wxRect
ScrollNoRefresh(int dx
, int dy
, const wxRect
*rect
= NULL
);
163 // after scrollbars are added or removed they must be refreshed by calling
165 void RefreshScrollbars();
167 // erase part of the control
168 virtual void EraseBackground(wxDC
& dc
, const wxRect
& rect
);
170 // overridden base class methods
171 // -----------------------------
173 // the rect coordinates are, for us, in client coords, but if no rect is
174 // specified, the entire window is refreshed
175 virtual void Refresh(bool eraseBackground
= true,
176 const wxRect
*rect
= (const wxRect
*) NULL
);
178 // we refresh the window when it is dis/enabled
179 virtual bool Enable(bool enable
= true);
181 // should we use the standard control colours or not?
182 virtual bool ShouldInheritColours() const { return false; }
185 // common part of all ctors
189 virtual bool DoPopupMenu(wxMenu
*menu
, int x
, int y
);
190 #endif // wxUSE_MENUS
192 // we deal with the scrollbars in these functions
193 virtual void DoSetClientSize(int width
, int height
);
194 virtual void DoGetClientSize(int *width
, int *height
) const;
195 virtual wxHitTest
DoHitTest(wxCoord x
, wxCoord y
) const;
198 void OnSize(wxSizeEvent
& event
);
199 void OnNcPaint(wxNcPaintEvent
& event
);
200 void OnPaint(wxPaintEvent
& event
);
201 void OnErase(wxEraseEvent
& event
);
203 #if wxUSE_ACCEL || wxUSE_MENUS
204 void OnKeyDown(wxKeyEvent
& event
);
205 #endif // wxUSE_ACCEL
208 void OnChar(wxKeyEvent
& event
);
209 void OnKeyUp(wxKeyEvent
& event
);
210 #endif // wxUSE_MENUS
212 // draw the control background, return true if done
213 virtual bool DoDrawBackground(wxDC
& dc
);
215 // draw the controls border
216 virtual void DoDrawBorder(wxDC
& dc
, const wxRect
& rect
);
218 // draw the controls contents
219 virtual void DoDraw(wxControlRenderer
*renderer
);
221 // calculate the best size for the client area of the window: default
222 // implementation of DoGetBestSize() uses this method and adds the border
223 // width to the result
224 virtual wxSize
DoGetBestClientSize() const;
225 virtual wxSize
DoGetBestSize() const;
227 // adjust the size of the window to take into account its borders
228 wxSize
AdjustSize(const wxSize
& size
) const;
230 // put the scrollbars along the edges of the window
231 void PositionScrollbars();
234 // return the menubar of the parent frame or NULL
235 wxMenuBar
*GetParentFrameMenuBar() const;
236 #endif // wxUSE_MENUS
238 // the renderer we use
239 wxRenderer
*m_renderer
;
241 // background bitmap info
244 wxStretch m_stretchBgBitmap
;
249 // is the mouse currently inside the window?
254 // override MSWWindowProc() to process WM_NCHITTEST
255 WXLRESULT
MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
);
259 // the window scrollbars
260 wxScrollBar
*m_scrollbarHorz
,
264 // the current modal event loop for the popup menu we show or NULL
265 static wxEventLoop
*ms_evtLoopPopup
;
267 // the last window over which Alt was pressed (used by OnKeyUp)
268 static wxWindow
*ms_winLastAltPress
;
269 #endif // wxUSE_MENUS
271 DECLARE_DYNAMIC_CLASS(wxWindow
)
272 DECLARE_EVENT_TABLE()
275 #endif // _WX_UNIV_WINDOW_H_