]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: richtext/richtextformatdlg.h | |
3 | // Purpose: interface of wxRichTextFormattingDialog* | |
4 | // Author: wxWidgets team | |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxRichTextFormattingDialogFactory | |
11 | ||
12 | This class provides pages for wxRichTextFormattingDialog, and allows other | |
13 | customization of the dialog. | |
14 | ||
15 | A default instance of this class is provided automatically. | |
16 | If you wish to change the behaviour of the formatting dialog (for example add | |
17 | or replace a page), you may derive from this class, override one or more | |
18 | functions, and call the static function | |
19 | wxRichTextFormattingDialog::SetFormattingDialogFactory. | |
20 | ||
21 | @library{wxrichtext} | |
22 | @category{richtext} | |
23 | */ | |
24 | class wxRichTextFormattingDialogFactory : public wxObject | |
25 | { | |
26 | public: | |
27 | /** | |
28 | Constructor. | |
29 | */ | |
30 | wxRichTextFormattingDialogFactory(); | |
31 | ||
32 | /** | |
33 | Destructor. | |
34 | */ | |
35 | virtual ~wxRichTextFormattingDialogFactory(); | |
36 | ||
37 | /** | |
38 | Creates the main dialog buttons. | |
39 | */ | |
40 | virtual bool CreateButtons(wxRichTextFormattingDialog* dialog); | |
41 | ||
42 | /** | |
43 | Creates a page, given a page identifier. | |
44 | */ | |
45 | virtual wxPanel* CreatePage(int page, wxString& title, | |
46 | wxRichTextFormattingDialog* dialog); | |
47 | ||
48 | /** | |
49 | Creates all pages under the dialog's book control, also calling AddPage(). | |
50 | */ | |
51 | virtual bool CreatePages(long pages, | |
52 | wxRichTextFormattingDialog* dialog); | |
53 | ||
54 | /** | |
55 | Enumerate all available page identifiers. | |
56 | */ | |
57 | virtual int GetPageId(int i) const; | |
58 | ||
59 | /** | |
60 | Gets the number of available page identifiers. | |
61 | */ | |
62 | virtual int GetPageIdCount() const; | |
63 | ||
64 | /** | |
65 | Gets the image index for the given page identifier. | |
66 | */ | |
67 | virtual int GetPageImage(int id) const; | |
68 | ||
69 | /** | |
70 | Set the property sheet style, called at the start of | |
71 | wxRichTextFormattingDialog::Create. | |
72 | */ | |
73 | virtual bool SetSheetStyle(wxRichTextFormattingDialog* dialog); | |
74 | ||
75 | /** | |
76 | Invokes help for the dialog. | |
77 | */ | |
78 | virtual bool ShowHelp(int page, | |
79 | wxRichTextFormattingDialog* dialog); | |
80 | }; | |
81 | ||
82 | ||
83 | ||
84 | #define wxRICHTEXT_FORMAT_STYLE_EDITOR 0x0001 | |
85 | #define wxRICHTEXT_FORMAT_FONT 0x0002 | |
86 | #define wxRICHTEXT_FORMAT_TABS 0x0004 | |
87 | #define wxRICHTEXT_FORMAT_BULLETS 0x0008 | |
88 | #define wxRICHTEXT_FORMAT_INDENTS_SPACING 0x0010 | |
89 | ||
90 | /** | |
91 | @class wxRichTextFormattingDialog | |
92 | ||
93 | This dialog allows the user to edit a character and/or paragraph style. | |
94 | ||
95 | In the constructor, specify the pages that will be created. | |
96 | Use wxRichTextFormattingDialog::GetStyle() to retrieve the common style | |
97 | for a given range, and then use wxRichTextFormattingDialog::ApplyStyle() | |
98 | to apply the user-selected formatting to a control. | |
99 | ||
100 | For example: | |
101 | @code | |
102 | wxRichTextRange range; | |
103 | if (m_richTextCtrl-HasSelection()) | |
104 | range = m_richTextCtrl-GetSelectionRange(); | |
105 | else | |
106 | range = wxRichTextRange(0, m_richTextCtrl-GetLastPosition()+1); | |
107 | ||
108 | int pages = wxRICHTEXT_FORMAT_FONT|wxRICHTEXT_FORMAT_INDENTS_SPACING| \ | |
109 | wxRICHTEXT_FORMAT_TABS|wxRICHTEXT_FORMAT_BULLETS; | |
110 | ||
111 | wxRichTextFormattingDialog formatDlg(pages, this); | |
112 | formatDlg.GetStyle(m_richTextCtrl, range); | |
113 | ||
114 | if (formatDlg.ShowModal() == wxID_OK) | |
115 | { | |
116 | formatDlg.ApplyStyle(m_richTextCtrl, range); | |
117 | } | |
118 | @endcode | |
119 | ||
120 | @library{wxrichtext} | |
121 | @category{richtext} | |
122 | */ | |
123 | class wxRichTextFormattingDialog : public wxPropertySheetDialog | |
124 | { | |
125 | public: | |
126 | /** | |
127 | Default ctor. | |
128 | */ | |
129 | wxRichTextFormattingDialog(); | |
130 | ||
131 | /** | |
132 | Constructors. | |
133 | ||
134 | @param flags | |
135 | The pages to show. | |
136 | @param parent | |
137 | The dialog's parent. | |
138 | @param pos | |
139 | The dialog's position. | |
140 | @param sz | |
141 | The dialog's size. | |
142 | @param style | |
143 | The dialog's window style. | |
144 | */ | |
145 | wxRichTextFormattingDialog(long flags, wxWindow* parent, | |
146 | const wxPoint& pos = wxDefaultPosition, | |
147 | const wxSize& sz = wxDefaultSize, | |
148 | long style = wxDEFAULT_DIALOG_STYLE); | |
149 | ||
150 | /** | |
151 | Destructor. | |
152 | */ | |
153 | virtual ~wxRichTextFormattingDialog(); | |
154 | ||
155 | /** | |
156 | Apply attributes to the given range, only changing attributes that | |
157 | need to be changed. | |
158 | */ | |
159 | virtual bool ApplyStyle(wxRichTextCtrl* ctrl, const wxRichTextRange& range, | |
160 | int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE); | |
161 | ||
162 | /** | |
163 | Creation: see wxRichTextFormattingDialog() "the constructor" for | |
164 | details about the parameters. | |
165 | */ | |
166 | bool Create(long flags, wxWindow* parent, const wxString& title, | |
167 | wxWindowID id, const wxPoint& pos = wxDefaultPosition, | |
168 | const wxSize& sz = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE); | |
169 | ||
170 | //@{ | |
171 | /** | |
172 | Gets the attributes being edited. | |
173 | */ | |
174 | const wxTextAttr& GetAttributes() const; | |
175 | wxTextAttr& GetAttributes(); | |
176 | //@} | |
177 | ||
178 | /** | |
179 | Helper for pages to get the top-level dialog. | |
180 | */ | |
181 | static wxRichTextFormattingDialog* GetDialog(wxWindow* win); | |
182 | ||
183 | /** | |
184 | Helper for pages to get the attributes. | |
185 | */ | |
186 | static wxTextAttr* GetDialogAttributes(wxWindow* win); | |
187 | ||
188 | /** | |
189 | Helper for pages to get the style. | |
190 | */ | |
191 | static wxRichTextStyleDefinition* GetDialogStyleDefinition(wxWindow* win); | |
192 | ||
193 | /** | |
194 | Returns the object to be used to customize the dialog and provide pages. | |
195 | */ | |
196 | static wxRichTextFormattingDialogFactory* GetFormattingDialogFactory(); | |
197 | ||
198 | /** | |
199 | Returns the image list associated with the dialog, used for example if showing | |
200 | the dialog as a toolbook. | |
201 | */ | |
202 | wxImageList* GetImageList() const; | |
203 | ||
204 | /** | |
205 | Gets common attributes from the given range and calls SetAttributes(). | |
206 | Attributes that do not have common values in the given range | |
207 | will be omitted from the style's flags. | |
208 | */ | |
209 | virtual bool GetStyle(wxRichTextCtrl* ctrl, const wxRichTextRange& range); | |
210 | ||
211 | /** | |
212 | Gets the associated style definition, if any. | |
213 | */ | |
214 | virtual wxRichTextStyleDefinition* GetStyleDefinition() const; | |
215 | ||
216 | /** | |
217 | Gets the associated style sheet, if any. | |
218 | */ | |
219 | virtual wxRichTextStyleSheet* GetStyleSheet() const; | |
220 | ||
221 | /** | |
222 | Sets the attributes to be edited. | |
223 | */ | |
224 | void SetAttributes(const wxTextAttr& attr); | |
225 | ||
226 | /** | |
227 | Sets the formatting factory object to be used for customization and page | |
228 | creation. | |
229 | ||
230 | It deletes the existing factory object. | |
231 | */ | |
232 | static void SetFormattingDialogFactory(wxRichTextFormattingDialogFactory* factory); | |
233 | ||
234 | /** | |
235 | Sets the image list associated with the dialog's property sheet. | |
236 | */ | |
237 | void SetImageList(wxImageList* imageList); | |
238 | ||
239 | /** | |
240 | Sets the attributes and optionally updates the display, if @a update is @true. | |
241 | */ | |
242 | virtual bool SetStyle(const wxTextAttr& style, bool update = true); | |
243 | ||
244 | /** | |
245 | Sets the style definition and optionally update the display, | |
246 | if @a update is @true. | |
247 | */ | |
248 | virtual bool SetStyleDefinition(const wxRichTextStyleDefinition& styleDef, | |
249 | wxRichTextStyleSheet* sheet, | |
250 | bool update = true); | |
251 | ||
252 | /** | |
253 | Updates the display. | |
254 | */ | |
255 | virtual bool UpdateDisplay(); | |
256 | }; | |
257 |