renderer.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/renderer.h
  3. // Purpose: wxRendererNative class declaration
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 20.07.2003
  7. // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. /*
  11. Renderers are used in wxWidgets for two similar but different things:
  12. (a) wxUniversal uses them to draw everything, i.e. all the control
  13. (b) all the native ports use them to draw generic controls only
  14. wxUniversal needs more functionality than what is included in the base class
  15. as it needs to draw stuff like scrollbars which are never going to be
  16. generic. So we put the bare minimum needed by the native ports here and the
  17. full wxRenderer class is declared in wx/univ/renderer.h and is only used by
  18. wxUniveral (although note that native ports can load wxRenderer objects from
  19. theme DLLs and use them as wxRendererNative ones, of course).
  20. */
  21. #ifndef _WX_RENDERER_H_
  22. #define _WX_RENDERER_H_
  23. class WXDLLIMPEXP_FWD_CORE wxDC;
  24. class WXDLLIMPEXP_FWD_CORE wxWindow;
  25. #include "wx/gdicmn.h" // for wxPoint, wxSize
  26. #include "wx/colour.h"
  27. #include "wx/font.h"
  28. #include "wx/bitmap.h"
  29. #include "wx/string.h"
  30. // some platforms have their own renderers, others use the generic one
  31. #if defined(__WXMSW__) || ( defined(__WXMAC__) && wxOSX_USE_COCOA_OR_CARBON ) || defined(__WXGTK__)
  32. #define wxHAS_NATIVE_RENDERER
  33. #else
  34. #undef wxHAS_NATIVE_RENDERER
  35. #endif
  36. // only MSW and OS X currently provides DrawTitleBarBitmap() method
  37. #if defined(__WXMSW__) || (defined(__WXMAC__) && wxUSE_LIBPNG && wxUSE_IMAGE)
  38. #define wxHAS_DRAW_TITLE_BAR_BITMAP
  39. #endif
  40. // ----------------------------------------------------------------------------
  41. // constants
  42. // ----------------------------------------------------------------------------
  43. // control state flags used in wxRenderer and wxColourScheme
  44. enum
  45. {
  46. wxCONTROL_DISABLED = 0x00000001, // control is disabled
  47. wxCONTROL_FOCUSED = 0x00000002, // currently has keyboard focus
  48. wxCONTROL_PRESSED = 0x00000004, // (button) is pressed
  49. wxCONTROL_SPECIAL = 0x00000008, // control-specific bit:
  50. wxCONTROL_ISDEFAULT = wxCONTROL_SPECIAL, // only for the buttons
  51. wxCONTROL_ISSUBMENU = wxCONTROL_SPECIAL, // only for the menu items
  52. wxCONTROL_EXPANDED = wxCONTROL_SPECIAL, // only for the tree items
  53. wxCONTROL_SIZEGRIP = wxCONTROL_SPECIAL, // only for the status bar panes
  54. wxCONTROL_FLAT = wxCONTROL_SPECIAL, // checkboxes only: flat border
  55. wxCONTROL_CURRENT = 0x00000010, // mouse is currently over the control
  56. wxCONTROL_SELECTED = 0x00000020, // selected item in e.g. listbox
  57. wxCONTROL_CHECKED = 0x00000040, // (check/radio button) is checked
  58. wxCONTROL_CHECKABLE = 0x00000080, // (menu) item can be checked
  59. wxCONTROL_UNDETERMINED = wxCONTROL_CHECKABLE, // (check) undetermined state
  60. wxCONTROL_FLAGS_MASK = 0x000000ff,
  61. // this is a pseudo flag not used directly by wxRenderer but rather by some
  62. // controls internally
  63. wxCONTROL_DIRTY = 0x80000000
  64. };
  65. // title bar buttons supported by DrawTitleBarBitmap()
  66. //
  67. // NB: they have the same values as wxTOPLEVEL_BUTTON_XXX constants in
  68. // wx/univ/toplevel.h as they really represent the same things
  69. enum wxTitleBarButton
  70. {
  71. wxTITLEBAR_BUTTON_CLOSE = 0x01000000,
  72. wxTITLEBAR_BUTTON_MAXIMIZE = 0x02000000,
  73. wxTITLEBAR_BUTTON_ICONIZE = 0x04000000,
  74. wxTITLEBAR_BUTTON_RESTORE = 0x08000000,
  75. wxTITLEBAR_BUTTON_HELP = 0x10000000
  76. };
  77. // ----------------------------------------------------------------------------
  78. // helper structs
  79. // ----------------------------------------------------------------------------
  80. // wxSplitterWindow parameters
  81. struct WXDLLIMPEXP_CORE wxSplitterRenderParams
  82. {
  83. // the only way to initialize this struct is by using this ctor
  84. wxSplitterRenderParams(wxCoord widthSash_, wxCoord border_, bool isSens_)
  85. : widthSash(widthSash_), border(border_), isHotSensitive(isSens_)
  86. {
  87. }
  88. // the width of the splitter sash
  89. const wxCoord widthSash;
  90. // the width of the border of the splitter window
  91. const wxCoord border;
  92. // true if the splitter changes its appearance when the mouse is over it
  93. const bool isHotSensitive;
  94. };
  95. // extra optional parameters for DrawHeaderButton
  96. struct WXDLLIMPEXP_CORE wxHeaderButtonParams
  97. {
  98. wxHeaderButtonParams()
  99. : m_labelAlignment(wxALIGN_LEFT)
  100. { }
  101. wxColour m_arrowColour;
  102. wxColour m_selectionColour;
  103. wxString m_labelText;
  104. wxFont m_labelFont;
  105. wxColour m_labelColour;
  106. wxBitmap m_labelBitmap;
  107. int m_labelAlignment;
  108. };
  109. enum wxHeaderSortIconType
  110. {
  111. wxHDR_SORT_ICON_NONE, // Header button has no sort arrow
  112. wxHDR_SORT_ICON_UP, // Header button an up sort arrow icon
  113. wxHDR_SORT_ICON_DOWN // Header button a down sort arrow icon
  114. };
  115. // wxRendererNative interface version
  116. struct WXDLLIMPEXP_CORE wxRendererVersion
  117. {
  118. wxRendererVersion(int version_, int age_) : version(version_), age(age_) { }
  119. // default copy ctor, assignment operator and dtor are ok
  120. // the current version and age of wxRendererNative interface: different
  121. // versions are incompatible (in both ways) while the ages inside the same
  122. // version are upwards compatible, i.e. the version of the renderer must
  123. // match the version of the main program exactly while the age may be
  124. // highergreater or equal to it
  125. //
  126. // NB: don't forget to increment age after adding any new virtual function!
  127. enum
  128. {
  129. Current_Version = 1,
  130. Current_Age = 5
  131. };
  132. // check if the given version is compatible with the current one
  133. static bool IsCompatible(const wxRendererVersion& ver)
  134. {
  135. return ver.version == Current_Version && ver.age >= Current_Age;
  136. }
  137. const int version;
  138. const int age;
  139. };
  140. // ----------------------------------------------------------------------------
  141. // wxRendererNative: abstracts drawing methods needed by the native controls
  142. // ----------------------------------------------------------------------------
  143. class WXDLLIMPEXP_CORE wxRendererNative
  144. {
  145. public:
  146. // drawing functions
  147. // -----------------
  148. // draw the header control button (used by wxListCtrl) Returns optimal
  149. // width for the label contents.
  150. virtual int DrawHeaderButton(wxWindow *win,
  151. wxDC& dc,
  152. const wxRect& rect,
  153. int flags = 0,
  154. wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
  155. wxHeaderButtonParams* params=NULL) = 0;
  156. // Draw the contents of a header control button (label, sort arrows, etc.)
  157. // Normally only called by DrawHeaderButton.
  158. virtual int DrawHeaderButtonContents(wxWindow *win,
  159. wxDC& dc,
  160. const wxRect& rect,
  161. int flags = 0,
  162. wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
  163. wxHeaderButtonParams* params=NULL) = 0;
  164. // Returns the default height of a header button, either a fixed platform
  165. // height if available, or a generic height based on the window's font.
  166. virtual int GetHeaderButtonHeight(wxWindow *win) = 0;
  167. // Returns the margin on left and right sides of header button's label
  168. virtual int GetHeaderButtonMargin(wxWindow *win) = 0;
  169. // draw the expanded/collapsed icon for a tree control item
  170. virtual void DrawTreeItemButton(wxWindow *win,
  171. wxDC& dc,
  172. const wxRect& rect,
  173. int flags = 0) = 0;
  174. // draw the border for sash window: this border must be such that the sash
  175. // drawn by DrawSash() blends into it well
  176. virtual void DrawSplitterBorder(wxWindow *win,
  177. wxDC& dc,
  178. const wxRect& rect,
  179. int flags = 0) = 0;
  180. // draw a (vertical) sash
  181. virtual void DrawSplitterSash(wxWindow *win,
  182. wxDC& dc,
  183. const wxSize& size,
  184. wxCoord position,
  185. wxOrientation orient,
  186. int flags = 0) = 0;
  187. // draw a combobox dropdown button
  188. //
  189. // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
  190. virtual void DrawComboBoxDropButton(wxWindow *win,
  191. wxDC& dc,
  192. const wxRect& rect,
  193. int flags = 0) = 0;
  194. // draw a dropdown arrow
  195. //
  196. // flags may use wxCONTROL_PRESSED and wxCONTROL_CURRENT
  197. virtual void DrawDropArrow(wxWindow *win,
  198. wxDC& dc,
  199. const wxRect& rect,
  200. int flags = 0) = 0;
  201. // draw check button
  202. //
  203. // flags may use wxCONTROL_CHECKED, wxCONTROL_UNDETERMINED and wxCONTROL_CURRENT
  204. virtual void DrawCheckBox(wxWindow *win,
  205. wxDC& dc,
  206. const wxRect& rect,
  207. int flags = 0) = 0;
  208. // Returns the default size of a check box.
  209. virtual wxSize GetCheckBoxSize(wxWindow *win) = 0;
  210. // draw blank button
  211. //
  212. // flags may use wxCONTROL_PRESSED, wxCONTROL_CURRENT and wxCONTROL_ISDEFAULT
  213. virtual void DrawPushButton(wxWindow *win,
  214. wxDC& dc,
  215. const wxRect& rect,
  216. int flags = 0) = 0;
  217. // draw rectangle indicating that an item in e.g. a list control
  218. // has been selected or focused
  219. //
  220. // flags may use
  221. // wxCONTROL_SELECTED (item is selected, e.g. draw background)
  222. // wxCONTROL_CURRENT (item is the current item, e.g. dotted border)
  223. // wxCONTROL_FOCUSED (the whole control has focus, e.g. blue background vs. grey otherwise)
  224. virtual void DrawItemSelectionRect(wxWindow *win,
  225. wxDC& dc,
  226. const wxRect& rect,
  227. int flags = 0) = 0;
  228. // draw the focus rectangle around the label contained in the given rect
  229. //
  230. // only wxCONTROL_SELECTED makes sense in flags here
  231. virtual void DrawFocusRect(wxWindow* win,
  232. wxDC& dc,
  233. const wxRect& rect,
  234. int flags = 0) = 0;
  235. // Draw a native wxChoice
  236. virtual void DrawChoice(wxWindow* win,
  237. wxDC& dc,
  238. const wxRect& rect,
  239. int flags = 0) = 0;
  240. // Draw a native wxComboBox
  241. virtual void DrawComboBox(wxWindow* win,
  242. wxDC& dc,
  243. const wxRect& rect,
  244. int flags = 0) = 0;
  245. // Draw a native wxTextCtrl frame
  246. virtual void DrawTextCtrl(wxWindow* win,
  247. wxDC& dc,
  248. const wxRect& rect,
  249. int flags = 0) = 0;
  250. // Draw a native wxRadioButton bitmap
  251. virtual void DrawRadioBitmap(wxWindow* win,
  252. wxDC& dc,
  253. const wxRect& rect,
  254. int flags = 0) = 0;
  255. #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
  256. // Draw one of the standard title bar buttons
  257. //
  258. // This is currently implemented only for MSW and OS X (for the close
  259. // button only) because there is no way to render standard title bar
  260. // buttons under the other platforms, the best can be done is to use normal
  261. // (only) images which wxArtProvider provides for wxART_HELP and
  262. // wxART_CLOSE (but not any other title bar buttons)
  263. //
  264. // NB: make sure PNG handler is enabled if using this function under OS X
  265. virtual void DrawTitleBarBitmap(wxWindow *win,
  266. wxDC& dc,
  267. const wxRect& rect,
  268. wxTitleBarButton button,
  269. int flags = 0) = 0;
  270. #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
  271. // geometry functions
  272. // ------------------
  273. // get the splitter parameters: the x field of the returned point is the
  274. // sash width and the y field is the border width
  275. virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) = 0;
  276. // pseudo constructors
  277. // -------------------
  278. // return the currently used renderer
  279. static wxRendererNative& Get();
  280. // return the generic implementation of the renderer
  281. static wxRendererNative& GetGeneric();
  282. // return the default (native) implementation for this platform
  283. static wxRendererNative& GetDefault();
  284. // changing the global renderer
  285. // ----------------------------
  286. #if wxUSE_DYNLIB_CLASS
  287. // load the renderer from the specified DLL, the returned pointer must be
  288. // deleted by caller if not NULL when it is not used any more
  289. static wxRendererNative *Load(const wxString& name);
  290. #endif // wxUSE_DYNLIB_CLASS
  291. // set the renderer to use, passing NULL reverts to using the default
  292. // renderer
  293. //
  294. // return the previous renderer used with Set() or NULL if none
  295. static wxRendererNative *Set(wxRendererNative *renderer);
  296. // miscellaneous stuff
  297. // -------------------
  298. // this function is used for version checking: Load() refuses to load any
  299. // DLLs implementing an older or incompatible version; it should be
  300. // implemented simply by returning wxRendererVersion::Current_XXX values
  301. virtual wxRendererVersion GetVersion() const = 0;
  302. // virtual dtor for any base class
  303. virtual ~wxRendererNative();
  304. };
  305. // ----------------------------------------------------------------------------
  306. // wxDelegateRendererNative: allows reuse of renderers code
  307. // ----------------------------------------------------------------------------
  308. class WXDLLIMPEXP_CORE wxDelegateRendererNative : public wxRendererNative
  309. {
  310. public:
  311. wxDelegateRendererNative()
  312. : m_rendererNative(GetGeneric()) { }
  313. wxDelegateRendererNative(wxRendererNative& rendererNative)
  314. : m_rendererNative(rendererNative) { }
  315. virtual int DrawHeaderButton(wxWindow *win,
  316. wxDC& dc,
  317. const wxRect& rect,
  318. int flags = 0,
  319. wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
  320. wxHeaderButtonParams* params = NULL)
  321. { return m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params); }
  322. virtual int DrawHeaderButtonContents(wxWindow *win,
  323. wxDC& dc,
  324. const wxRect& rect,
  325. int flags = 0,
  326. wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
  327. wxHeaderButtonParams* params = NULL)
  328. { return m_rendererNative.DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params); }
  329. virtual int GetHeaderButtonHeight(wxWindow *win)
  330. { return m_rendererNative.GetHeaderButtonHeight(win); }
  331. virtual int GetHeaderButtonMargin(wxWindow *win)
  332. { return m_rendererNative.GetHeaderButtonMargin(win); }
  333. virtual void DrawTreeItemButton(wxWindow *win,
  334. wxDC& dc,
  335. const wxRect& rect,
  336. int flags = 0)
  337. { m_rendererNative.DrawTreeItemButton(win, dc, rect, flags); }
  338. virtual void DrawSplitterBorder(wxWindow *win,
  339. wxDC& dc,
  340. const wxRect& rect,
  341. int flags = 0)
  342. { m_rendererNative.DrawSplitterBorder(win, dc, rect, flags); }
  343. virtual void DrawSplitterSash(wxWindow *win,
  344. wxDC& dc,
  345. const wxSize& size,
  346. wxCoord position,
  347. wxOrientation orient,
  348. int flags = 0)
  349. { m_rendererNative.DrawSplitterSash(win, dc, size,
  350. position, orient, flags); }
  351. virtual void DrawComboBoxDropButton(wxWindow *win,
  352. wxDC& dc,
  353. const wxRect& rect,
  354. int flags = 0)
  355. { m_rendererNative.DrawComboBoxDropButton(win, dc, rect, flags); }
  356. virtual void DrawDropArrow(wxWindow *win,
  357. wxDC& dc,
  358. const wxRect& rect,
  359. int flags = 0)
  360. { m_rendererNative.DrawDropArrow(win, dc, rect, flags); }
  361. virtual void DrawCheckBox(wxWindow *win,
  362. wxDC& dc,
  363. const wxRect& rect,
  364. int flags = 0)
  365. { m_rendererNative.DrawCheckBox( win, dc, rect, flags ); }
  366. virtual wxSize GetCheckBoxSize(wxWindow *win)
  367. { return m_rendererNative.GetCheckBoxSize(win); }
  368. virtual void DrawPushButton(wxWindow *win,
  369. wxDC& dc,
  370. const wxRect& rect,
  371. int flags = 0)
  372. { m_rendererNative.DrawPushButton( win, dc, rect, flags ); }
  373. virtual void DrawItemSelectionRect(wxWindow *win,
  374. wxDC& dc,
  375. const wxRect& rect,
  376. int flags = 0)
  377. { m_rendererNative.DrawItemSelectionRect( win, dc, rect, flags ); }
  378. virtual void DrawFocusRect(wxWindow* win,
  379. wxDC& dc,
  380. const wxRect& rect,
  381. int flags = 0)
  382. { m_rendererNative.DrawFocusRect( win, dc, rect, flags ); }
  383. virtual void DrawChoice(wxWindow* win,
  384. wxDC& dc,
  385. const wxRect& rect,
  386. int flags = 0)
  387. { m_rendererNative.DrawChoice( win, dc, rect, flags); }
  388. virtual void DrawComboBox(wxWindow* win,
  389. wxDC& dc,
  390. const wxRect& rect,
  391. int flags = 0)
  392. { m_rendererNative.DrawComboBox( win, dc, rect, flags); }
  393. virtual void DrawTextCtrl(wxWindow* win,
  394. wxDC& dc,
  395. const wxRect& rect,
  396. int flags = 0)
  397. { m_rendererNative.DrawTextCtrl( win, dc, rect, flags); }
  398. virtual void DrawRadioBitmap(wxWindow* win,
  399. wxDC& dc,
  400. const wxRect& rect,
  401. int flags = 0)
  402. { m_rendererNative.DrawRadioBitmap(win, dc, rect, flags); }
  403. #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
  404. virtual void DrawTitleBarBitmap(wxWindow *win,
  405. wxDC& dc,
  406. const wxRect& rect,
  407. wxTitleBarButton button,
  408. int flags = 0)
  409. { m_rendererNative.DrawTitleBarBitmap(win, dc, rect, button, flags); }
  410. #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
  411. virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win)
  412. { return m_rendererNative.GetSplitterParams(win); }
  413. virtual wxRendererVersion GetVersion() const
  414. { return m_rendererNative.GetVersion(); }
  415. protected:
  416. wxRendererNative& m_rendererNative;
  417. wxDECLARE_NO_COPY_CLASS(wxDelegateRendererNative);
  418. };
  419. // ----------------------------------------------------------------------------
  420. // inline functions implementation
  421. // ----------------------------------------------------------------------------
  422. #ifndef wxHAS_NATIVE_RENDERER
  423. // default native renderer is the generic one then
  424. /* static */ inline
  425. wxRendererNative& wxRendererNative::GetDefault()
  426. {
  427. return GetGeneric();
  428. }
  429. #endif // !wxHAS_NATIVE_RENDERER
  430. #endif // _WX_RENDERER_H_