markuptext.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/generic/private/markuptext.h
  3. // Purpose: Generic wxMarkupText class for managing text with markup.
  4. // Author: Vadim Zeitlin
  5. // Created: 2011-02-21
  6. // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_GENERIC_PRIVATE_MARKUPTEXT_H_
  10. #define _WX_GENERIC_PRIVATE_MARKUPTEXT_H_
  11. #include "wx/defs.h"
  12. class WXDLLIMPEXP_FWD_CORE wxDC;
  13. class WXDLLIMPEXP_FWD_CORE wxRect;
  14. // ----------------------------------------------------------------------------
  15. // wxMarkupText: allows to measure and draw the text containing markup.
  16. // ----------------------------------------------------------------------------
  17. class WXDLLIMPEXP_CORE wxMarkupText
  18. {
  19. public:
  20. // Constants for Render() flags.
  21. enum
  22. {
  23. Render_Default = 0, // Don't show mnemonics visually.
  24. Render_ShowAccels = 1 // Underline mnemonics.
  25. };
  26. // Initialize with the given string containing markup (which is supposed to
  27. // be valid, the caller must check for it before constructing this object).
  28. //
  29. // Notice that the usual rules for mnemonics apply to the markup text: if
  30. // it contains any '&' characters they must be escaped by doubling them,
  31. // otherwise they indicate that the next character is the mnemonic for this
  32. // field.
  33. //
  34. // TODO-MULTILINE-MARKUP: Currently only single line labels are supported,
  35. // search for other occurrences of this comment to find the places which
  36. // need to be updated to support multiline labels with markup.
  37. wxMarkupText(const wxString& markup)
  38. : m_markup(markup)
  39. {
  40. }
  41. // Default copy ctor, assignment operator and dtor are ok.
  42. // Update the markup string.
  43. //
  44. // The same rules for mnemonics as in the ctor apply to this string.
  45. void SetMarkup(const wxString& markup) { m_markup = markup; }
  46. // Return the width and height required by the given string and optionally
  47. // the height of the visible part above the baseline (i.e. ascent minus
  48. // internal leading).
  49. //
  50. // The font currently selected into the DC is used for measuring (notice
  51. // that it is changed by this function but normally -- i.e. if markup is
  52. // valid -- restored to its original value when it returns).
  53. wxSize Measure(wxDC& dc, int *visibleHeight = NULL) const;
  54. // Render the markup string into the given DC in the specified rectangle.
  55. //
  56. // Notice that while the function uses the provided rectangle for alignment
  57. // (it centers the text in it), no clipping is done by it so use Measure()
  58. // and set the clipping region before rendering if necessary.
  59. void Render(wxDC& dc, const wxRect& rect, int flags);
  60. private:
  61. wxString m_markup;
  62. };
  63. #endif // _WX_GENERIC_PRIVATE_MARKUPTEXT_H_