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