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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
18 #pragma interface "univwindow.h"
21 #include "wx/bitmap.h" // for m_bitmapBg
23 class WXDLLEXPORT wxControlRenderer
;
24 class WXDLLEXPORT wxEventLoop
;
25 class WXDLLEXPORT wxMenu
;
26 class WXDLLEXPORT wxMenuBar
;
27 class WXDLLEXPORT wxRenderer
;
28 class WXDLLEXPORT wxScrollBar
;
31 #define wxUSE_TWO_WINDOWS 1
33 #define wxUSE_TWO_WINDOWS 0
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
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
52 class WXDLLEXPORT wxWindow
: public wxWindowNative
55 // ctors and create functions
56 // ---------------------------
58 wxWindow() { Init(); }
60 wxWindow(wxWindow
*parent
,
62 const wxPoint
& pos
= wxDefaultPosition
,
63 const wxSize
& size
= wxDefaultSize
,
65 const wxString
& name
= wxPanelNameStr
)
66 : wxWindowNative(parent
, id
, pos
, size
, style
| wxCLIP_CHILDREN
, name
)
69 bool Create(wxWindow
*parent
,
71 const wxPoint
& pos
= wxDefaultPosition
,
72 const wxSize
& size
= wxDefaultSize
,
74 const wxString
& name
= wxPanelNameStr
);
78 // background pixmap support
79 // -------------------------
81 virtual void SetBackground(const wxBitmap
& bitmap
,
82 int alignment
= wxALIGN_CENTRE
,
83 wxStretch stretch
= wxSTRETCH_NOT
);
85 const wxBitmap
& GetBackgroundBitmap(int *alignment
= NULL
,
86 wxStretch
*stretch
= NULL
) const;
88 // scrollbars: we (re)implement it ourselves using our own scrollbars
89 // instead of the native ones
90 // ------------------------------------------------------------------
92 virtual void SetScrollbar(int orient
,
96 bool refresh
= true );
97 virtual void SetScrollPos(int orient
, int pos
, bool refresh
= true);
98 virtual int GetScrollPos(int orient
) const;
99 virtual int GetScrollThumb(int orient
) const;
100 virtual int GetScrollRange(int orient
) const;
101 virtual void ScrollWindow(int dx
, int dy
,
102 const wxRect
* rect
= (wxRect
*) NULL
);
104 // take into account the borders here
105 virtual wxPoint
GetClientAreaOrigin() const;
107 // popup menu support
108 // ------------------
110 // NB: all menu related functions are implemented in menu.cpp
113 virtual bool DoPopupMenu(wxMenu
*menu
, int x
, int y
);
115 // this is wxUniv-specific private method to be used only by wxMenu
116 void DismissPopupMenu();
117 #endif // wxUSE_MENUS
119 // miscellaneous other methods
120 // ---------------------------
122 // get the state information
123 virtual bool IsFocused() const;
124 virtual bool IsCurrent() const;
125 virtual bool IsPressed() const;
126 virtual bool IsDefault() const;
128 // return all state flags at once (combination of wxCONTROL_XXX values)
129 int GetStateFlags() const;
131 // set the "highlighted" flag and return true if it changed
132 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
;
140 // methods used by wxColourScheme to choose the colours for this window
141 // --------------------------------------------------------------------
143 // return true if this is a panel/canvas window which contains other
145 virtual bool IsCanvasWindow() const { return false; }
147 // return true if this control can be highlighted when the mouse is over
148 // it (the theme decides itself whether it is really highlighted or not)
149 virtual bool CanBeHighlighted() const { return false; }
151 // return true if we should use the colours/fonts returned by the
152 // corresponding GetXXX() methods instead of the default ones
153 bool UseBgCol() const { return m_hasBgCol
; }
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; }
192 // common part of all ctors
195 // overridden base class virtuals
197 // we deal with the scrollbars in these functions
198 virtual void DoSetClientSize(int width
, int height
);
199 virtual void DoGetClientSize(int *width
, int *height
) const;
200 virtual wxHitTest
DoHitTest(wxCoord x
, wxCoord y
) const;
203 void OnSize(wxSizeEvent
& event
);
204 void OnNcPaint(wxNcPaintEvent
& event
);
205 void OnPaint(wxPaintEvent
& event
);
206 void OnErase(wxEraseEvent
& event
);
208 #if wxUSE_ACCEL || wxUSE_MENUS
209 void OnKeyDown(wxKeyEvent
& event
);
210 #endif // wxUSE_ACCEL
213 void OnChar(wxKeyEvent
& event
);
214 void OnKeyUp(wxKeyEvent
& event
);
215 #endif // wxUSE_MENUS
217 // draw the control background, return true if done
218 virtual bool DoDrawBackground(wxDC
& dc
);
220 // draw the controls border
221 virtual void DoDrawBorder(wxDC
& dc
, const wxRect
& rect
);
223 // draw the controls contents
224 virtual void DoDraw(wxControlRenderer
*renderer
);
226 // calculate the best size for the client area of the window: default
227 // implementation of DoGetBestSize() uses this method and adds the border
228 // width to the result
229 virtual wxSize
DoGetBestClientSize() const;
230 virtual wxSize
DoGetBestSize() const;
232 // adjust the size of the window to take into account its borders
233 wxSize
AdjustSize(const wxSize
& size
) const;
235 // put the scrollbars along the edges of the window
236 void PositionScrollbars();
239 // return the menubar of the parent frame or NULL
240 wxMenuBar
*GetParentFrameMenuBar() const;
241 #endif // wxUSE_MENUS
243 // the renderer we use
244 wxRenderer
*m_renderer
;
246 // background bitmap info
249 wxStretch m_stretchBgBitmap
;
254 // is the mouse currently inside the window?
258 // override MSWWindowProc() to process WM_NCHITTEST
259 WXLRESULT
MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
);
263 // the window scrollbars
264 wxScrollBar
*m_scrollbarHorz
,
268 // the current modal event loop for the popup menu we show or NULL
269 static wxEventLoop
*ms_evtLoopPopup
;
271 // the last window over which Alt was pressed (used by OnKeyUp)
272 static wxWindow
*ms_winLastAltPress
;
273 #endif // wxUSE_MENUS
275 DECLARE_DYNAMIC_CLASS(wxWindow
)
276 DECLARE_EVENT_TABLE()
279 #endif // _WX_UNIV_WINDOW_H_