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_ 
  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
); 
  76     // background pixmap support 
  77     // ------------------------- 
  79     virtual void SetBackground(const wxBitmap
& bitmap
, 
  80                                int alignment 
= wxALIGN_CENTRE
, 
  81                                wxStretch stretch 
= wxSTRETCH_NOT
); 
  83     const wxBitmap
& GetBackgroundBitmap(int *alignment 
= NULL
, 
  84                                         wxStretch 
*stretch 
= NULL
) const; 
  86     // scrollbars: we (re)implement it ourselves using our own scrollbars 
  87     // instead of the native ones 
  88     // ------------------------------------------------------------------ 
  90     virtual void SetScrollbar(int orient
, 
  94                               bool refresh 
= TRUE 
); 
  95     virtual void SetScrollPos(int orient
, int pos
, bool refresh 
= TRUE
); 
  96     virtual int GetScrollPos(int orient
) const; 
  97     virtual int GetScrollThumb(int orient
) const; 
  98     virtual int GetScrollRange(int orient
) const; 
  99     virtual void ScrollWindow(int dx
, int dy
, 
 100                               const wxRect
* rect 
= (wxRect 
*) NULL
); 
 102     // take into account the borders here 
 103     virtual wxPoint 
GetClientAreaOrigin() const; 
 105     // popup menu support 
 106     // ------------------ 
 108     // NB: all menu related functions are implemented in menu.cpp 
 111     virtual bool DoPopupMenu(wxMenu 
*menu
, int x
, int y
); 
 113     // this is wxUniv-specific private method to be used only by wxMenu 
 114     void DismissPopupMenu(); 
 115 #endif // wxUSE_MENUS 
 117     // miscellaneous other methods 
 118     // --------------------------- 
 120     // get the state information 
 121     virtual bool IsFocused() const; 
 122     virtual bool IsCurrent() const; 
 123     virtual bool IsPressed() const; 
 124     virtual bool IsDefault() const; 
 126     // return all state flags at once (combination of wxCONTROL_XXX values) 
 127     int GetStateFlags() const; 
 129     // set the "highlighted" flag and return TRUE if it changed 
 130     virtual bool SetCurrent(bool doit 
= TRUE
); 
 132     // get the scrollbar (may be NULL) for the given orientation 
 133     wxScrollBar 
*GetScrollbar(int orient
) const 
 135         return orient 
& wxVERTICAL 
? m_scrollbarVert 
: m_scrollbarHorz
; 
 138     // methods used by wxColourScheme to choose the colours for this window 
 139     // -------------------------------------------------------------------- 
 141     // return TRUE if this is a panel/canvas window which contains other 
 143     virtual bool IsCanvasWindow() const { return FALSE
; } 
 145     // return TRUE if this a container window which contains the other items: 
 146     // e.g, a listbox, listctrl, treectrl, ... and FALSE if it is a monolithic 
 147     // control (e.g. a button, checkbox, ...) 
 148     virtual bool IsContainerWindow() const { return FALSE
; } 
 150     // returns TRUE if the control has "transparent" areas such 
 151     // as a wxStaticText and wxCheckBox and the background should 
 152     // be adapted from a parent window 
 153     virtual bool HasTransparentBackground() { return FALSE
; } 
 155     // to be used with function above: transparent windows get 
 156     // their background from parents that return TRUE here, 
 157     // so this is mostly for wxPanel, wxTopLevelWindow etc. 
 158     virtual bool ProvidesBackground() const { return FALSE
; } 
 160     // return TRUE if this control can be highlighted when the mouse is over 
 161     // it (the theme decides itself whether it is really highlighted or not) 
 162     virtual bool CanBeHighlighted() const { return FALSE
; } 
 164     // return TRUE if we should use the colours/fonts returned by the 
 165     // corresponding GetXXX() methods instead of the default ones 
 166     bool UseBgCol() const { return m_hasBgCol
; } 
 167     bool UseFgCol() const { return m_hasFgCol
; } 
 168     bool UseFont() const { return m_hasFont
; } 
 170     // return TRUE if this window serves as a container for the other windows 
 171     // only and doesn't get any input itself 
 172     virtual bool IsStaticBox() const { return FALSE
; } 
 174     // returns the (low level) renderer to use for drawing the control by 
 175     // querying the current theme 
 176     wxRenderer 
*GetRenderer() const { return m_renderer
; } 
 178     // scrolling helper: like ScrollWindow() except that it doesn't refresh the 
 179     // uncovered window areas but returns the rectangle to update (don't call 
 180     // this with both dx and dy non zero) 
 181     wxRect 
ScrollNoRefresh(int dx
, int dy
, const wxRect 
*rect 
= NULL
); 
 183     // after scrollbars are added or removed they must be refreshed by calling 
 185     void RefreshScrollbars(); 
 187     // erase part of the control 
 188     virtual void EraseBackground(wxDC
& dc
, const wxRect
& rect
); 
 190     // overridden base class methods 
 191     // ----------------------------- 
 193     // the rect coordinates are, for us, in client coords, but if no rect is 
 194     // specified, the entire window is refreshed 
 195     virtual void Refresh(bool eraseBackground 
= TRUE
, 
 196                          const wxRect 
*rect 
= (const wxRect 
*) NULL
); 
 198     // we refresh the window when it is dis/enabled 
 199     virtual bool Enable(bool enable 
= TRUE
); 
 202     // common part of all ctors 
 205     // overridden base class virtuals 
 207     // we deal with the scrollbars in these functions 
 208     virtual void DoSetClientSize(int width
, int height
); 
 209     virtual void DoGetClientSize(int *width
, int *height
) const; 
 210     virtual wxHitTest 
DoHitTest(wxCoord x
, wxCoord y
) const; 
 213     void OnSize(wxSizeEvent
& event
); 
 214     void OnNcPaint(wxPaintEvent
& event
); 
 215     void OnPaint(wxPaintEvent
& event
); 
 216     void OnErase(wxEraseEvent
& event
); 
 218 #if wxUSE_ACCEL || wxUSE_MENUS 
 219     void OnKeyDown(wxKeyEvent
& event
); 
 220 #endif // wxUSE_ACCEL 
 223     void OnChar(wxKeyEvent
& event
); 
 224     void OnKeyUp(wxKeyEvent
& event
); 
 225 #endif // wxUSE_MENUS 
 227     // draw the control background, return TRUE if done 
 228     virtual bool DoDrawBackground(wxDC
& dc
); 
 230     // draw the controls border 
 231     virtual void DoDrawBorder(wxDC
& dc
, const wxRect
& rect
); 
 233     // draw the controls contents 
 234     virtual void DoDraw(wxControlRenderer 
*renderer
); 
 236     // calculate the best size for the client area of the window: default 
 237     // implementation of DoGetBestSize() uses this method and adds the border 
 238     // width to the result 
 239     virtual wxSize 
DoGetBestClientSize() const; 
 240     virtual wxSize 
DoGetBestSize() const; 
 242     // adjust the size of the window to take into account its borders 
 243     wxSize 
AdjustSize(const wxSize
& size
) const; 
 245     // put the scrollbars along the edges of the window 
 246     void PositionScrollbars(); 
 249     // return the menubar of the parent frame or NULL 
 250     wxMenuBar 
*GetParentFrameMenuBar() const; 
 251 #endif // wxUSE_MENUS 
 253     // the renderer we use 
 254     wxRenderer 
*m_renderer
; 
 256     // background bitmap info 
 259     wxStretch m_stretchBgBitmap
; 
 264     // is the mouse currently inside the window? 
 268     // override MSWWindowProc() to process WM_NCHITTEST 
 269     long MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
); 
 273     // the window scrollbars 
 274     wxScrollBar 
*m_scrollbarHorz
, 
 278     // the current modal event loop for the popup menu we show or NULL 
 279     static wxEventLoop 
*ms_evtLoopPopup
; 
 281     // the last window over which Alt was pressed (used by OnKeyUp) 
 282     static wxWindow 
*ms_winLastAltPress
; 
 283 #endif // wxUSE_MENUS 
 285     DECLARE_DYNAMIC_CLASS(wxWindow
) 
 286     DECLARE_EVENT_TABLE() 
 289 #endif // _WX_UNIV_WINDOW_H_