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