stdrend.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/univ/stdrend.h
  3. // Purpose: wxStdRenderer class declaration
  4. // Author: Vadim Zeitlin
  5. // Created: 2006-09-18
  6. // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_UNIV_STDREND_H_
  10. #define _WX_UNIV_STDREND_H_
  11. #include "wx/univ/renderer.h"
  12. #include "wx/pen.h"
  13. class WXDLLIMPEXP_FWD_CORE wxColourScheme;
  14. // ----------------------------------------------------------------------------
  15. // wxStdRenderer: implements as much of wxRenderer API as possible generically
  16. // ----------------------------------------------------------------------------
  17. class wxStdRenderer : public wxRenderer
  18. {
  19. public:
  20. // the renderer will use the given scheme, whose lifetime must be at least
  21. // as long as of this object itself, to choose the colours for drawing
  22. wxStdRenderer(const wxColourScheme *scheme);
  23. virtual void DrawBackground(wxDC& dc,
  24. const wxColour& col,
  25. const wxRect& rect,
  26. int flags = 0,
  27. wxWindow *window = NULL);
  28. virtual void DrawButtonSurface(wxDC& dc,
  29. const wxColour& col,
  30. const wxRect& rect,
  31. int flags);
  32. virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0);
  33. virtual void DrawLabel(wxDC& dc,
  34. const wxString& label,
  35. const wxRect& rect,
  36. int flags = 0,
  37. int alignment = wxALIGN_LEFT | wxALIGN_TOP,
  38. int indexAccel = -1,
  39. wxRect *rectBounds = NULL);
  40. virtual void DrawButtonLabel(wxDC& dc,
  41. const wxString& label,
  42. const wxBitmap& image,
  43. const wxRect& rect,
  44. int flags = 0,
  45. int alignment = wxALIGN_LEFT | wxALIGN_TOP,
  46. int indexAccel = -1,
  47. wxRect *rectBounds = NULL);
  48. virtual void DrawBorder(wxDC& dc,
  49. wxBorder border,
  50. const wxRect& rect,
  51. int flags = 0,
  52. wxRect *rectIn = NULL);
  53. virtual void DrawTextBorder(wxDC& dc,
  54. wxBorder border,
  55. const wxRect& rect,
  56. int flags = 0,
  57. wxRect *rectIn = NULL);
  58. virtual void DrawHorizontalLine(wxDC& dc,
  59. wxCoord y, wxCoord x1, wxCoord x2);
  60. virtual void DrawVerticalLine(wxDC& dc,
  61. wxCoord x, wxCoord y1, wxCoord y2);
  62. virtual void DrawFrame(wxDC& dc,
  63. const wxString& label,
  64. const wxRect& rect,
  65. int flags = 0,
  66. int alignment = wxALIGN_LEFT,
  67. int indexAccel = -1);
  68. virtual void DrawItem(wxDC& dc,
  69. const wxString& label,
  70. const wxRect& rect,
  71. int flags = 0);
  72. virtual void DrawCheckItem(wxDC& dc,
  73. const wxString& label,
  74. const wxBitmap& bitmap,
  75. const wxRect& rect,
  76. int flags = 0);
  77. virtual void DrawCheckButton(wxDC& dc,
  78. const wxString& label,
  79. const wxBitmap& bitmap,
  80. const wxRect& rect,
  81. int flags = 0,
  82. wxAlignment align = wxALIGN_LEFT,
  83. int indexAccel = -1);
  84. virtual void DrawRadioButton(wxDC& dc,
  85. const wxString& label,
  86. const wxBitmap& bitmap,
  87. const wxRect& rect,
  88. int flags = 0,
  89. wxAlignment align = wxALIGN_LEFT,
  90. int indexAccel = -1);
  91. virtual void DrawScrollbarArrow(wxDC& dc,
  92. wxDirection dir,
  93. const wxRect& rect,
  94. int flags = 0);
  95. virtual void DrawScrollCorner(wxDC& dc,
  96. const wxRect& rect);
  97. #if wxUSE_TEXTCTRL
  98. virtual void DrawTextLine(wxDC& dc,
  99. const wxString& text,
  100. const wxRect& rect,
  101. int selStart = -1,
  102. int selEnd = -1,
  103. int flags = 0);
  104. virtual void DrawLineWrapMark(wxDC& dc, const wxRect& rect);
  105. virtual wxRect GetTextTotalArea(const wxTextCtrl *text,
  106. const wxRect& rect) const;
  107. virtual wxRect GetTextClientArea(const wxTextCtrl *text,
  108. const wxRect& rect,
  109. wxCoord *extraSpaceBeyond) const;
  110. #endif // wxUSE_TEXTCTRL
  111. virtual wxRect GetBorderDimensions(wxBorder border) const;
  112. virtual bool AreScrollbarsInsideBorder() const;
  113. virtual void AdjustSize(wxSize *size, const wxWindow *window);
  114. virtual wxCoord GetListboxItemHeight(wxCoord fontHeight);
  115. #if wxUSE_STATUSBAR
  116. virtual void DrawStatusField(wxDC& dc,
  117. const wxRect& rect,
  118. const wxString& label,
  119. int flags = 0, int style = 0);
  120. virtual wxSize GetStatusBarBorders() const;
  121. virtual wxCoord GetStatusBarBorderBetweenFields() const;
  122. virtual wxSize GetStatusBarFieldMargins() const;
  123. #endif // wxUSE_STATUSBAR
  124. virtual wxCoord GetCheckItemMargin() const { return 0; }
  125. virtual void DrawFrameTitleBar(wxDC& dc,
  126. const wxRect& rect,
  127. const wxString& title,
  128. const wxIcon& icon,
  129. int flags,
  130. int specialButton = 0,
  131. int specialButtonFlag = 0);
  132. virtual void DrawFrameBorder(wxDC& dc,
  133. const wxRect& rect,
  134. int flags);
  135. virtual void DrawFrameBackground(wxDC& dc,
  136. const wxRect& rect,
  137. int flags);
  138. virtual void DrawFrameTitle(wxDC& dc,
  139. const wxRect& rect,
  140. const wxString& title,
  141. int flags);
  142. virtual void DrawFrameIcon(wxDC& dc,
  143. const wxRect& rect,
  144. const wxIcon& icon,
  145. int flags);
  146. virtual void DrawFrameButton(wxDC& dc,
  147. wxCoord x, wxCoord y,
  148. int button,
  149. int flags = 0);
  150. virtual wxRect GetFrameClientArea(const wxRect& rect, int flags) const;
  151. virtual wxSize GetFrameTotalSize(const wxSize& clientSize, int flags) const;
  152. virtual wxSize GetFrameMinSize(int flags) const;
  153. virtual wxSize GetFrameIconSize() const;
  154. virtual int HitTestFrame(const wxRect& rect,
  155. const wxPoint& pt,
  156. int flags = 0) const;
  157. protected:
  158. // various constants
  159. enum ArrowDirection
  160. {
  161. Arrow_Left,
  162. Arrow_Right,
  163. Arrow_Up,
  164. Arrow_Down,
  165. Arrow_Max
  166. };
  167. enum ArrowStyle
  168. {
  169. Arrow_Normal,
  170. Arrow_Disabled,
  171. Arrow_Pressed,
  172. Arrow_Inverted,
  173. Arrow_InvertedDisabled,
  174. Arrow_StateMax
  175. };
  176. enum FrameButtonType
  177. {
  178. FrameButton_Close,
  179. FrameButton_Minimize,
  180. FrameButton_Maximize,
  181. FrameButton_Restore,
  182. FrameButton_Help,
  183. FrameButton_Max
  184. };
  185. enum IndicatorType
  186. {
  187. IndicatorType_Check,
  188. IndicatorType_Radio,
  189. IndicatorType_MaxCtrl,
  190. IndicatorType_Menu = IndicatorType_MaxCtrl,
  191. IndicatorType_Max
  192. };
  193. enum IndicatorState
  194. {
  195. IndicatorState_Normal,
  196. IndicatorState_Pressed, // this one is for check/radioboxes
  197. IndicatorState_Disabled,
  198. IndicatorState_MaxCtrl,
  199. // the rest of the states are valid for menu items only
  200. IndicatorState_Selected = IndicatorState_Pressed,
  201. IndicatorState_SelectedDisabled = IndicatorState_MaxCtrl,
  202. IndicatorState_MaxMenu
  203. };
  204. enum IndicatorStatus
  205. {
  206. IndicatorStatus_Checked,
  207. IndicatorStatus_Unchecked,
  208. IndicatorStatus_Undetermined,
  209. IndicatorStatus_Max
  210. };
  211. // translate the appropriate bits in flags to the above enum elements
  212. static void GetIndicatorsFromFlags(int flags,
  213. IndicatorState& state,
  214. IndicatorStatus& status);
  215. // translate wxDirection to ArrowDirection
  216. static ArrowDirection GetArrowDirection(wxDirection dir);
  217. // fill the rectangle with a brush of given colour (must be valid)
  218. void DrawSolidRect(wxDC& dc, const wxColour& col, const wxRect& rect);
  219. // all the functions in this section adjust the rect parameter to
  220. // correspond to the interiour of the drawn area
  221. // draw complete rectangle
  222. void DrawRect(wxDC& dc, wxRect *rect, const wxPen& pen);
  223. // draw the rectange using the first pen for the left and top sides
  224. // and the second one for the bottom and right ones
  225. void DrawShadedRect(wxDC& dc, wxRect *rect,
  226. const wxPen& pen1, const wxPen& pen2);
  227. // border drawing routines, may be overridden in the derived class
  228. virtual void DrawRaisedBorder(wxDC& dc, wxRect *rect);
  229. virtual void DrawSunkenBorder(wxDC& dc, wxRect *rect);
  230. virtual void DrawAntiSunkenBorder(wxDC& dc, wxRect *rect);
  231. virtual void DrawBoxBorder(wxDC& dc, wxRect *rect);
  232. virtual void DrawStaticBorder(wxDC& dc, wxRect *rect);
  233. virtual void DrawExtraBorder(wxDC& dc, wxRect *rect);
  234. // draw the frame with non-empty label inside the given rectText
  235. virtual void DrawFrameWithLabel(wxDC& dc,
  236. const wxString& label,
  237. const wxRect& rectFrame,
  238. const wxRect& rectText,
  239. int flags,
  240. int alignment,
  241. int indexAccel);
  242. // draw the (static box) frame without the part corresponding to rectLabel
  243. void DrawFrameWithoutLabel(wxDC& dc,
  244. const wxRect& rectFrame,
  245. const wxRect& rectLabel);
  246. // draw the bitmap for a check item (which is by default the same as check
  247. // box one but may be different)
  248. virtual void DrawCheckItemBitmap(wxDC& dc,
  249. const wxBitmap& bitmap,
  250. const wxRect& rect,
  251. int flags);
  252. // common routine for drawing check and radio buttons
  253. void DrawCheckOrRadioButton(wxDC& dc,
  254. const wxString& label,
  255. const wxBitmap& bitmap,
  256. const wxRect& rect,
  257. int flags,
  258. wxAlignment align,
  259. int indexAccel);
  260. // return the check/radio bitmap for the given flags
  261. virtual wxBitmap GetRadioBitmap(int flags) = 0;
  262. virtual wxBitmap GetCheckBitmap(int flags) = 0;
  263. // return the frame icon bitmap
  264. virtual wxBitmap GetFrameButtonBitmap(FrameButtonType type) = 0;
  265. // get the width of either normal or resizable frame border depending on
  266. // whether flags contains wxTOPLEVEL_RESIZEABLE bit
  267. //
  268. // notice that these methods only make sense with standard border drawing
  269. // code which uses the borders of the same width on all sides, this is why
  270. // they are only present here and not in wxRenderer itself
  271. virtual int GetFrameBorderWidth(int flags) const;
  272. #if wxUSE_TEXTCTRL
  273. // return the width of the border around the text area in the text control
  274. virtual int GetTextBorderWidth(const wxTextCtrl *text) const;
  275. #endif // wxUSE_TEXTCTRL
  276. // GDI objects we often use
  277. wxPen m_penBlack,
  278. m_penDarkGrey,
  279. m_penLightGrey,
  280. m_penHighlight;
  281. wxFont m_titlebarFont;
  282. // the colours we use, they never change currently so we don't have to ever
  283. // update m_penXXX objects above
  284. const wxColourScheme * const m_scheme;
  285. wxDECLARE_NO_COPY_CLASS(wxStdRenderer);
  286. };
  287. #endif // _WX_UNIV_STDREND_H_