ownerdrw.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/ownerdrw.h
  3. // Purpose: interface for owner-drawn GUI elements
  4. // Author: Vadim Zeitlin
  5. // Modified by: Marcin Malich
  6. // Created: 11.11.97
  7. // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_OWNERDRW_H_BASE
  11. #define _WX_OWNERDRW_H_BASE
  12. #include "wx/defs.h"
  13. #if wxUSE_OWNER_DRAWN
  14. #include "wx/font.h"
  15. #include "wx/colour.h"
  16. class WXDLLIMPEXP_FWD_CORE wxDC;
  17. // ----------------------------------------------------------------------------
  18. // wxOwnerDrawn - a mix-in base class, derive from it to implement owner-drawn
  19. // behaviour
  20. //
  21. // wxOwnerDrawn supports drawing of an item with non standard font, color and
  22. // also supports 3 bitmaps: either a checked/unchecked bitmap for a checkable
  23. // element or one unchangeable bitmap otherwise.
  24. // ----------------------------------------------------------------------------
  25. class WXDLLIMPEXP_CORE wxOwnerDrawnBase
  26. {
  27. public:
  28. wxOwnerDrawnBase()
  29. {
  30. m_ownerDrawn = false;
  31. m_margin = ms_defaultMargin;
  32. }
  33. virtual ~wxOwnerDrawnBase() {}
  34. void SetFont(const wxFont& font)
  35. { m_font = font; m_ownerDrawn = true; }
  36. wxFont& GetFont() const
  37. { return (wxFont&) m_font; }
  38. void SetTextColour(const wxColour& colText)
  39. { m_colText = colText; m_ownerDrawn = true; }
  40. wxColour& GetTextColour() const
  41. { return (wxColour&) m_colText; }
  42. void SetBackgroundColour(const wxColour& colBack)
  43. { m_colBack = colBack; m_ownerDrawn = true; }
  44. wxColour& GetBackgroundColour() const
  45. { return (wxColour&) m_colBack ; }
  46. void SetMarginWidth(int width)
  47. { m_margin = width; }
  48. int GetMarginWidth() const
  49. { return m_margin; }
  50. static int GetDefaultMarginWidth()
  51. { return ms_defaultMargin; }
  52. // get item name (with mnemonics if exist)
  53. virtual wxString GetName() const = 0;
  54. // this function might seem strange, but if it returns false it means that
  55. // no non-standard attribute are set, so there is no need for this control
  56. // to be owner-drawn. Moreover, you can force owner-drawn to false if you
  57. // want to change, say, the color for the item but only if it is owner-drawn
  58. // (see wxMenuItem::wxMenuItem for example)
  59. bool IsOwnerDrawn() const
  60. { return m_ownerDrawn; }
  61. // switch on/off owner-drawing the item
  62. void SetOwnerDrawn(bool ownerDrawn = true)
  63. { m_ownerDrawn = ownerDrawn; }
  64. // constants used in OnDrawItem
  65. // (they have the same values as corresponding Win32 constants)
  66. enum wxODAction
  67. {
  68. wxODDrawAll = 0x0001, // redraw entire control
  69. wxODSelectChanged = 0x0002, // selection changed (see Status.Select)
  70. wxODFocusChanged = 0x0004 // keyboard focus changed (see Status.Focus)
  71. };
  72. enum wxODStatus
  73. {
  74. wxODSelected = 0x0001, // control is currently selected
  75. wxODGrayed = 0x0002, // item is to be grayed
  76. wxODDisabled = 0x0004, // item is to be drawn as disabled
  77. wxODChecked = 0x0008, // item is to be checked
  78. wxODHasFocus = 0x0010, // item has the keyboard focus
  79. wxODDefault = 0x0020, // item is the default item
  80. wxODHidePrefix= 0x0100 // hide keyboard cues (w2k and xp only)
  81. };
  82. // virtual functions to implement drawing (return true if processed)
  83. virtual bool OnMeasureItem(size_t *width, size_t *height);
  84. virtual bool OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction act, wxODStatus stat) = 0;
  85. protected:
  86. // get the font and colour to use, whether it is set or not
  87. virtual void GetFontToUse(wxFont& font) const;
  88. virtual void GetColourToUse(wxODStatus stat, wxColour& colText, wxColour& colBack) const;
  89. private:
  90. bool m_ownerDrawn; // true if something is non standard
  91. wxFont m_font; // font to use for drawing
  92. wxColour m_colText, // color ----"---"---"----
  93. m_colBack; // background color
  94. int m_margin; // space occupied by bitmap to the left of the item
  95. static int ms_defaultMargin;
  96. };
  97. // ----------------------------------------------------------------------------
  98. // include the platform-specific class declaration
  99. // ----------------------------------------------------------------------------
  100. #if defined(__WXMSW__)
  101. #include "wx/msw/ownerdrw.h"
  102. #elif defined(__WXPM__)
  103. #include "wx/os2/ownerdrw.h"
  104. #endif
  105. #endif // wxUSE_OWNER_DRAWN
  106. #endif // _WX_OWNERDRW_H_BASE