window.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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
  7. // Modified by:
  8. // Created: 06.08.00
  9. // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
  10. // Licence: wxWindows licence
  11. ///////////////////////////////////////////////////////////////////////////////
  12. #ifndef _WX_UNIV_WINDOW_H_
  13. #define _WX_UNIV_WINDOW_H_
  14. #include "wx/bitmap.h" // for m_bitmapBg
  15. class WXDLLIMPEXP_FWD_CORE wxControlRenderer;
  16. class WXDLLIMPEXP_FWD_CORE wxEventLoop;
  17. #if wxUSE_MENUS
  18. class WXDLLIMPEXP_FWD_CORE wxMenu;
  19. class WXDLLIMPEXP_FWD_CORE wxMenuBar;
  20. #endif // wxUSE_MENUS
  21. class WXDLLIMPEXP_FWD_CORE wxRenderer;
  22. #if wxUSE_SCROLLBAR
  23. class WXDLLIMPEXP_FWD_CORE wxScrollBar;
  24. #endif // wxUSE_SCROLLBAR
  25. #ifdef __WXX11__
  26. #define wxUSE_TWO_WINDOWS 1
  27. #else
  28. #define wxUSE_TWO_WINDOWS 0
  29. #endif
  30. // ----------------------------------------------------------------------------
  31. // wxWindow
  32. // ----------------------------------------------------------------------------
  33. #if defined(__WXMSW__)
  34. #define wxWindowNative wxWindowMSW
  35. #elif defined(__WXGTK__)
  36. #define wxWindowNative wxWindowGTK
  37. #elif defined(__WXX11__)
  38. #define wxWindowNative wxWindowX11
  39. #elif defined(__WXMAC__)
  40. #define wxWindowNative wxWindowMac
  41. #endif
  42. class WXDLLIMPEXP_CORE wxWindow : public wxWindowNative
  43. {
  44. public:
  45. // ctors and create functions
  46. // ---------------------------
  47. wxWindow() { Init(); }
  48. wxWindow(wxWindow *parent,
  49. wxWindowID id,
  50. const wxPoint& pos = wxDefaultPosition,
  51. const wxSize& size = wxDefaultSize,
  52. long style = 0,
  53. const wxString& name = wxPanelNameStr)
  54. : wxWindowNative(parent, id, pos, size, style | wxCLIP_CHILDREN, name)
  55. { Init(); }
  56. bool Create(wxWindow *parent,
  57. wxWindowID id,
  58. const wxPoint& pos = wxDefaultPosition,
  59. const wxSize& size = wxDefaultSize,
  60. long style = 0,
  61. const wxString& name = wxPanelNameStr);
  62. virtual ~wxWindow();
  63. // background pixmap support
  64. // -------------------------
  65. virtual void SetBackground(const wxBitmap& bitmap,
  66. int alignment = wxALIGN_CENTRE,
  67. wxStretch stretch = wxSTRETCH_NOT);
  68. const wxBitmap& GetBackgroundBitmap(int *alignment = NULL,
  69. wxStretch *stretch = NULL) const;
  70. // scrollbars: we (re)implement it ourselves using our own scrollbars
  71. // instead of the native ones
  72. // ------------------------------------------------------------------
  73. virtual void SetScrollbar(int orient,
  74. int pos,
  75. int page,
  76. int range,
  77. bool refresh = true );
  78. virtual void SetScrollPos(int orient, int pos, bool refresh = true);
  79. virtual int GetScrollPos(int orient) const;
  80. virtual int GetScrollThumb(int orient) const;
  81. virtual int GetScrollRange(int orient) const;
  82. virtual void ScrollWindow(int dx, int dy,
  83. const wxRect* rect = NULL);
  84. // take into account the borders here
  85. virtual wxPoint GetClientAreaOrigin() const;
  86. // popup menu support
  87. // ------------------
  88. // NB: all menu related functions are implemented in menu.cpp
  89. #if wxUSE_MENUS
  90. // this is wxUniv-specific private method to be used only by wxMenu
  91. void DismissPopupMenu();
  92. #endif // wxUSE_MENUS
  93. // miscellaneous other methods
  94. // ---------------------------
  95. // get the state information
  96. virtual bool IsFocused() const;
  97. virtual bool IsCurrent() const;
  98. virtual bool IsPressed() const;
  99. virtual bool IsDefault() const;
  100. // return all state flags at once (combination of wxCONTROL_XXX values)
  101. int GetStateFlags() const;
  102. // set the "highlighted" flag and return true if it changed
  103. virtual bool SetCurrent(bool doit = true);
  104. #if wxUSE_SCROLLBAR
  105. // get the scrollbar (may be NULL) for the given orientation
  106. wxScrollBar *GetScrollbar(int orient) const
  107. {
  108. return orient & wxVERTICAL ? m_scrollbarVert : m_scrollbarHorz;
  109. }
  110. #endif // wxUSE_SCROLLBAR
  111. // methods used by wxColourScheme to choose the colours for this window
  112. // --------------------------------------------------------------------
  113. // return true if this is a panel/canvas window which contains other
  114. // controls only
  115. virtual bool IsCanvasWindow() const { return false; }
  116. // return true if this control can be highlighted when the mouse is over
  117. // it (the theme decides itself whether it is really highlighted or not)
  118. virtual bool CanBeHighlighted() const { return false; }
  119. // return true if we should use the colours/fonts returned by the
  120. // corresponding GetXXX() methods instead of the default ones
  121. bool UseFgCol() const { return m_hasFgCol; }
  122. bool UseFont() const { return m_hasFont; }
  123. // return true if this window serves as a container for the other windows
  124. // only and doesn't get any input itself
  125. virtual bool IsStaticBox() const { return false; }
  126. // returns the (low level) renderer to use for drawing the control by
  127. // querying the current theme
  128. wxRenderer *GetRenderer() const { return m_renderer; }
  129. // scrolling helper: like ScrollWindow() except that it doesn't refresh the
  130. // uncovered window areas but returns the rectangle to update (don't call
  131. // this with both dx and dy non zero)
  132. wxRect ScrollNoRefresh(int dx, int dy, const wxRect *rect = NULL);
  133. // after scrollbars are added or removed they must be refreshed by calling
  134. // this function
  135. void RefreshScrollbars();
  136. // erase part of the control
  137. virtual void EraseBackground(wxDC& dc, const wxRect& rect);
  138. // overridden base class methods
  139. // -----------------------------
  140. // the rect coordinates are, for us, in client coords, but if no rect is
  141. // specified, the entire window is refreshed
  142. virtual void Refresh(bool eraseBackground = true,
  143. const wxRect *rect = (const wxRect *) NULL);
  144. // we refresh the window when it is dis/enabled
  145. virtual bool Enable(bool enable = true);
  146. // should we use the standard control colours or not?
  147. virtual bool ShouldInheritColours() const { return false; }
  148. virtual bool IsClientAreaChild(const wxWindow *child) const
  149. {
  150. #if wxUSE_SCROLLBAR
  151. if ( child == (wxWindow*)m_scrollbarHorz ||
  152. child == (wxWindow*)m_scrollbarVert )
  153. return false;
  154. #endif
  155. return wxWindowNative::IsClientAreaChild(child);
  156. }
  157. protected:
  158. // common part of all ctors
  159. void Init();
  160. #if wxUSE_MENUS
  161. virtual bool DoPopupMenu(wxMenu *menu, int x, int y);
  162. #endif // wxUSE_MENUS
  163. // we deal with the scrollbars in these functions
  164. virtual void DoSetClientSize(int width, int height);
  165. virtual void DoGetClientSize(int *width, int *height) const;
  166. virtual wxHitTest DoHitTest(wxCoord x, wxCoord y) const;
  167. // event handlers
  168. void OnSize(wxSizeEvent& event);
  169. void OnNcPaint(wxNcPaintEvent& event);
  170. void OnPaint(wxPaintEvent& event);
  171. void OnErase(wxEraseEvent& event);
  172. #if wxUSE_ACCEL || wxUSE_MENUS
  173. void OnKeyDown(wxKeyEvent& event);
  174. #endif // wxUSE_ACCEL
  175. #if wxUSE_MENUS
  176. void OnChar(wxKeyEvent& event);
  177. void OnKeyUp(wxKeyEvent& event);
  178. #endif // wxUSE_MENUS
  179. // draw the control background, return true if done
  180. virtual bool DoDrawBackground(wxDC& dc);
  181. // draw the controls border
  182. virtual void DoDrawBorder(wxDC& dc, const wxRect& rect);
  183. // draw the controls contents
  184. virtual void DoDraw(wxControlRenderer *renderer);
  185. // override the base class method to return the size of the window borders
  186. virtual wxSize DoGetBorderSize() const;
  187. // adjust the size of the window to take into account its borders
  188. wxSize AdjustSize(const wxSize& size) const;
  189. // put the scrollbars along the edges of the window
  190. void PositionScrollbars();
  191. #if wxUSE_MENUS
  192. // return the menubar of the parent frame or NULL
  193. wxMenuBar *GetParentFrameMenuBar() const;
  194. #endif // wxUSE_MENUS
  195. // the renderer we use
  196. wxRenderer *m_renderer;
  197. // background bitmap info
  198. wxBitmap m_bitmapBg;
  199. int m_alignBgBitmap;
  200. wxStretch m_stretchBgBitmap;
  201. // old size
  202. wxSize m_oldSize;
  203. // is the mouse currently inside the window?
  204. bool m_isCurrent:1;
  205. #ifdef __WXMSW__
  206. public:
  207. // override MSWWindowProc() to process WM_NCHITTEST
  208. WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
  209. #endif // __WXMSW__
  210. private:
  211. #if wxUSE_SCROLLBAR
  212. // the window scrollbars
  213. wxScrollBar *m_scrollbarHorz,
  214. *m_scrollbarVert;
  215. #endif // wxUSE_SCROLLBAR
  216. #if wxUSE_MENUS
  217. // the current modal event loop for the popup menu we show or NULL
  218. static wxEventLoop *ms_evtLoopPopup;
  219. // the last window over which Alt was pressed (used by OnKeyUp)
  220. static wxWindow *ms_winLastAltPress;
  221. #endif // wxUSE_MENUS
  222. DECLARE_DYNAMIC_CLASS(wxWindow)
  223. DECLARE_EVENT_TABLE()
  224. };
  225. #endif // _WX_UNIV_WINDOW_H_