]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: richtext/richtextstyles.h | |
3 | // Purpose: interface of wxRichTextStyleListCtrl | |
4 | // Author: wxWidgets team | |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows licence | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxRichTextStyleListCtrl | |
11 | ||
12 | This class incorporates a wxRichTextStyleListBox and a choice control that | |
13 | allows the user to select the category of style to view. | |
14 | ||
15 | It is demonstrated in the wxRichTextCtrl sample in @c samples/richtext. | |
16 | ||
17 | To use wxRichTextStyleListCtrl, add the control to your window hierarchy and | |
18 | call wxRichTextStyleListCtrl::SetStyleType with one of | |
19 | wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL, | |
20 | wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH, | |
21 | wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER and | |
22 | wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST to set the current view. | |
23 | ||
24 | Associate the control with a style sheet and rich text control with | |
25 | SetStyleSheet and SetRichTextCtrl, so that when a style is double-clicked, | |
26 | it is applied to the selection. | |
27 | ||
28 | @beginStyleTable | |
29 | @style{wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR} | |
30 | This style hides the category selection control. | |
31 | @endStyleTable | |
32 | ||
33 | @library{wxrichtext} | |
34 | @category{richtext} | |
35 | */ | |
36 | class wxRichTextStyleListCtrl : public wxControl | |
37 | { | |
38 | public: | |
39 | //@{ | |
40 | /** | |
41 | Constructors. | |
42 | */ | |
43 | wxRichTextStyleListCtrl(wxWindow* parent, | |
44 | wxWindowID id = wxID_ANY, | |
45 | const wxPoint& pos = wxDefaultPosition, | |
46 | const wxSize& size = wxDefaultSize, | |
47 | long style = 0); | |
48 | wxRichTextStyleListCtrl(); | |
49 | //@} | |
50 | ||
51 | /** | |
52 | Creates the windows. | |
53 | */ | |
54 | bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, | |
55 | const wxPoint& pos = wxDefaultPosition, | |
56 | const wxSize& size = wxDefaultSize, | |
57 | long style = 0); | |
58 | ||
59 | /** | |
60 | Returns the associated rich text control, if any. | |
61 | */ | |
62 | wxRichTextCtrl* GetRichTextCtrl() const; | |
63 | ||
64 | /** | |
65 | Returns the wxChoice control used for selecting the style category. | |
66 | */ | |
67 | wxChoice* GetStyleChoice() const; | |
68 | ||
69 | /** | |
70 | Returns the wxListBox control used to view the style list. | |
71 | */ | |
72 | wxRichTextStyleListBox* GetStyleListBox() const; | |
73 | ||
74 | /** | |
75 | Returns the associated style sheet, if any. | |
76 | */ | |
77 | wxRichTextStyleSheet* GetStyleSheet() const; | |
78 | ||
79 | /** | |
80 | Returns the type of style to show in the list box. | |
81 | */ | |
82 | wxRichTextStyleListBox::wxRichTextStyleType GetStyleType() const; | |
83 | ||
84 | /** | |
85 | Associates the control with a wxRichTextCtrl. | |
86 | */ | |
87 | void SetRichTextCtrl(wxRichTextCtrl* ctrl); | |
88 | ||
89 | /** | |
90 | Associates the control with a style sheet. | |
91 | */ | |
92 | void SetStyleSheet(wxRichTextStyleSheet* styleSheet); | |
93 | ||
94 | /** | |
95 | Sets the style type to display. | |
96 | ||
97 | One of | |
98 | - wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL, | |
99 | - wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH, | |
100 | - wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER | |
101 | - wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST. | |
102 | */ | |
103 | void SetStyleType(wxRichTextStyleListBox::wxRichTextStyleType styleType); | |
104 | ||
105 | /** | |
106 | Updates the style list box. | |
107 | */ | |
108 | void UpdateStyles(); | |
109 | }; | |
110 | ||
111 | ||
112 | ||
113 | /** | |
114 | @class wxRichTextStyleDefinition | |
115 | ||
116 | This is a base class for paragraph and character styles. | |
117 | ||
118 | @library{wxrichtext} | |
119 | @category{richtext} | |
120 | */ | |
121 | class wxRichTextStyleDefinition : public wxObject | |
122 | { | |
123 | public: | |
124 | /** | |
125 | Constructor. | |
126 | */ | |
127 | wxRichTextStyleDefinition(const wxString& name = wxEmptyString); | |
128 | ||
129 | /** | |
130 | Destructor. | |
131 | */ | |
132 | virtual ~wxRichTextStyleDefinition(); | |
133 | ||
134 | /** | |
135 | Returns the style on which this style is based. | |
136 | */ | |
137 | const wxString& GetBaseStyle() const; | |
138 | ||
139 | /** | |
140 | Returns the style's description. | |
141 | */ | |
142 | const wxString& GetDescription() const; | |
143 | ||
144 | /** | |
145 | Returns the style name. | |
146 | */ | |
147 | const wxString& GetName() const; | |
148 | ||
149 | //@{ | |
150 | /** | |
151 | Returns the attributes associated with this style. | |
152 | */ | |
153 | wxTextAttr GetStyle() const; | |
154 | const wxTextAttr GetStyle() const; | |
155 | //@} | |
156 | ||
157 | /** | |
158 | Returns the style attributes combined with the attributes of the specified base | |
159 | style, if any. This function works recursively. | |
160 | */ | |
161 | virtual wxTextAttr GetStyleMergedWithBase(const wxRichTextStyleSheet* sheet) const; | |
162 | ||
163 | /** | |
164 | Sets the name of the style that this style is based on. | |
165 | */ | |
166 | void SetBaseStyle(const wxString& name); | |
167 | ||
168 | /** | |
169 | Sets the style description. | |
170 | */ | |
171 | void SetDescription(const wxString& descr); | |
172 | ||
173 | /** | |
174 | Sets the name of the style. | |
175 | */ | |
176 | void SetName(const wxString& name); | |
177 | ||
178 | /** | |
179 | Sets the attributes for this style. | |
180 | */ | |
181 | void SetStyle(const wxTextAttr& style); | |
182 | }; | |
183 | ||
184 | ||
185 | ||
186 | /** | |
187 | @class wxRichTextParagraphStyleDefinition | |
188 | ||
189 | This class represents a paragraph style definition, usually added to a | |
190 | wxRichTextStyleSheet. | |
191 | ||
192 | @library{wxrichtext} | |
193 | @category{richtext} | |
194 | */ | |
195 | class wxRichTextParagraphStyleDefinition : public wxRichTextStyleDefinition | |
196 | { | |
197 | public: | |
198 | /** | |
199 | Constructor. | |
200 | */ | |
201 | wxRichTextParagraphStyleDefinition(const wxString& name = wxEmptyString); | |
202 | ||
203 | /** | |
204 | Destructor. | |
205 | */ | |
206 | virtual ~wxRichTextParagraphStyleDefinition(); | |
207 | ||
208 | /** | |
209 | Returns the style that should normally follow this style. | |
210 | */ | |
211 | const wxString& GetNextStyle() const; | |
212 | ||
213 | /** | |
214 | Sets the style that should normally follow this style. | |
215 | */ | |
216 | void SetNextStyle(const wxString& name); | |
217 | }; | |
218 | ||
219 | ||
220 | ||
221 | /** | |
222 | @class wxRichTextStyleListBox | |
223 | ||
224 | This is a listbox that can display the styles in a wxRichTextStyleSheet, | |
225 | and apply the selection to an associated wxRichTextCtrl. | |
226 | ||
227 | See @c samples/richtext for an example of how to use it. | |
228 | ||
229 | @library{wxrichtext} | |
230 | @category{richtext} | |
231 | ||
232 | @see wxRichTextStyleComboCtrl, @ref overview_richtextctrl | |
233 | */ | |
234 | class wxRichTextStyleListBox : public wxHtmlListBox | |
235 | { | |
236 | public: | |
237 | /** | |
238 | Constructor. | |
239 | */ | |
240 | wxRichTextStyleListBox(wxWindow* parent, | |
241 | wxWindowID id = wxID_ANY, | |
242 | const wxPoint& pos = wxDefaultPosition, | |
243 | const wxSize& size = wxDefaultSize, | |
244 | long style = 0); | |
245 | ||
246 | /** | |
247 | Destructor. | |
248 | */ | |
249 | virtual ~wxRichTextStyleListBox(); | |
250 | ||
251 | /** | |
252 | Applies the @e ith style to the associated rich text control. | |
253 | */ | |
254 | void ApplyStyle(int i); | |
255 | ||
256 | /** | |
257 | Converts units in tenths of a millimetre to device units. | |
258 | */ | |
259 | int ConvertTenthsMMToPixels(wxDC& dc, int units) const; | |
260 | ||
261 | /** | |
262 | Creates a suitable HTML fragment for a definition. | |
263 | */ | |
264 | wxString CreateHTML(wxRichTextStyleDefinition* def) const; | |
265 | ||
266 | /** | |
267 | If the return value is @true, clicking on a style name in the list will | |
268 | immediately apply the style to the associated rich text control. | |
269 | */ | |
270 | bool GetApplyOnSelection() const; | |
271 | ||
272 | /** | |
273 | Returns the wxRichTextCtrl associated with this listbox. | |
274 | */ | |
275 | wxRichTextCtrl* GetRichTextCtrl() const; | |
276 | ||
277 | /** | |
278 | Gets a style for a listbox index. | |
279 | */ | |
280 | wxRichTextStyleDefinition* GetStyle(size_t i) const; | |
281 | ||
282 | /** | |
283 | Returns the style sheet associated with this listbox. | |
284 | */ | |
285 | wxRichTextStyleSheet* GetStyleSheet() const; | |
286 | ||
287 | /** | |
288 | Returns the type of style to show in the list box. | |
289 | */ | |
290 | wxRichTextStyleListBox::wxRichTextStyleType GetStyleType() const; | |
291 | ||
292 | /** | |
293 | Implements left click behaviour, applying the clicked style to the | |
294 | wxRichTextCtrl. | |
295 | */ | |
296 | void OnLeftDown(wxMouseEvent& event); | |
297 | ||
298 | /** | |
299 | If @a applyOnSelection is @true, clicking on a style name in the list will | |
300 | immediately apply the style to the associated rich text control. | |
301 | */ | |
302 | void SetApplyOnSelection(bool applyOnSelection); | |
303 | ||
304 | /** | |
305 | Associates the listbox with a wxRichTextCtrl. | |
306 | */ | |
307 | void SetRichTextCtrl(wxRichTextCtrl* ctrl); | |
308 | ||
309 | /** | |
310 | Associates the control with a style sheet. | |
311 | */ | |
312 | void SetStyleSheet(wxRichTextStyleSheet* styleSheet); | |
313 | ||
314 | /** | |
315 | Sets the style type to display. One of | |
316 | - wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL, | |
317 | - wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH, | |
318 | - wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER | |
319 | - wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST. | |
320 | */ | |
321 | void SetStyleType(wxRichTextStyleListBox::wxRichTextStyleType styleType); | |
322 | ||
323 | /** | |
324 | Updates the list from the associated style sheet. | |
325 | */ | |
326 | void UpdateStyles(); | |
327 | ||
328 | protected: | |
329 | ||
330 | /** | |
331 | Returns the HTML for this item. | |
332 | */ | |
333 | virtual wxString OnGetItem(size_t n) const; | |
334 | }; | |
335 | ||
336 | ||
337 | ||
338 | /** | |
339 | @class wxRichTextStyleComboCtrl | |
340 | ||
341 | This is a combo control that can display the styles in a wxRichTextStyleSheet, | |
342 | and apply the selection to an associated wxRichTextCtrl. | |
343 | ||
344 | See @c samples/richtext for an example of how to use it. | |
345 | ||
346 | @library{wxrichtext} | |
347 | @category{richtext} | |
348 | ||
349 | @see wxRichTextStyleListBox, @ref overview_richtextctrl | |
350 | */ | |
351 | class wxRichTextStyleComboCtrl : public wxComboCtrl | |
352 | { | |
353 | public: | |
354 | /** | |
355 | Constructor. | |
356 | */ | |
357 | wxRichTextStyleComboCtrl(wxWindow* parent, | |
358 | wxWindowID id = wxID_ANY, | |
359 | const wxPoint& pos = wxDefaultPosition, | |
360 | const wxSize& size = wxDefaultSize, | |
361 | long style = 0); | |
362 | ||
363 | /** | |
364 | Destructor. | |
365 | */ | |
366 | virtual ~wxRichTextStyleComboCtrl(); | |
367 | ||
368 | /** | |
369 | Returns the wxRichTextCtrl associated with this control. | |
370 | */ | |
371 | wxRichTextCtrl* GetRichTextCtrl() const; | |
372 | ||
373 | /** | |
374 | Returns the style sheet associated with this control. | |
375 | */ | |
376 | wxRichTextStyleSheet* GetStyleSheet() const; | |
377 | ||
378 | /** | |
379 | Associates the control with a wxRichTextCtrl. | |
380 | */ | |
381 | void SetRichTextCtrl(wxRichTextCtrl* ctrl); | |
382 | ||
383 | /** | |
384 | Associates the control with a style sheet. | |
385 | */ | |
386 | void SetStyleSheet(wxRichTextStyleSheet* styleSheet); | |
387 | ||
388 | /** | |
389 | Updates the combo control from the associated style sheet. | |
390 | */ | |
391 | void UpdateStyles(); | |
392 | }; | |
393 | ||
394 | ||
395 | ||
396 | /** | |
397 | @class wxRichTextCharacterStyleDefinition | |
398 | ||
399 | This class represents a character style definition, usually added to a | |
400 | wxRichTextStyleSheet. | |
401 | ||
402 | @library{wxrichtext} | |
403 | @category{richtext} | |
404 | */ | |
405 | class wxRichTextCharacterStyleDefinition : public wxRichTextStyleDefinition | |
406 | { | |
407 | public: | |
408 | /** | |
409 | Constructor. | |
410 | */ | |
411 | wxRichTextCharacterStyleDefinition(const wxString& name = wxEmptyString); | |
412 | ||
413 | /** | |
414 | Destructor. | |
415 | */ | |
416 | virtual ~wxRichTextCharacterStyleDefinition(); | |
417 | }; | |
418 | ||
419 | ||
420 | ||
421 | /** | |
422 | @class wxRichTextListStyleDefinition | |
423 | ||
424 | This class represents a list style definition, usually added to a | |
425 | wxRichTextStyleSheet. | |
426 | ||
427 | The class inherits paragraph attributes from wxRichTextStyleParagraphDefinition, | |
428 | and adds 10 further attribute objects, one for each level of a list. | |
429 | When applying a list style to a paragraph, the list style's base and | |
430 | appropriate level attributes are merged with the paragraph's existing attributes. | |
431 | ||
432 | You can apply a list style to one or more paragraphs using wxRichTextCtrl::SetListStyle. | |
433 | You can also use the functions wxRichTextCtrl::NumberList, wxRichTextCtrl::PromoteList and | |
434 | wxRichTextCtrl::ClearListStyle. | |
435 | ||
436 | As usual, there are wxRichTextBuffer versions of these functions | |
437 | so that you can apply them directly to a buffer without requiring a control. | |
438 | ||
439 | @library{wxrichtext} | |
440 | @category{richtext} | |
441 | */ | |
442 | class wxRichTextListStyleDefinition : public wxRichTextParagraphStyleDefinition | |
443 | { | |
444 | public: | |
445 | /** | |
446 | Constructor. | |
447 | */ | |
448 | wxRichTextListStyleDefinition(const wxString& name = wxEmptyString); | |
449 | ||
450 | /** | |
451 | Destructor. | |
452 | */ | |
453 | virtual ~wxRichTextListStyleDefinition(); | |
454 | ||
455 | /** | |
456 | This function combines the given paragraph style with the list style's base | |
457 | attributes and level style matching the given indent, returning the combined attributes. | |
458 | ||
459 | If @a styleSheet is specified, the base style for this definition will also be | |
460 | included in the result. | |
461 | */ | |
462 | wxTextAttr CombineWithParagraphStyle(int indent, | |
463 | const wxTextAttr& paraStyle, | |
464 | wxRichTextStyleSheet* styleSheet = NULL); | |
465 | ||
466 | /** | |
467 | This function finds the level (from 0 to 9) whose indentation attribute mostly | |
468 | closely matches @a indent (expressed in tenths of a millimetre). | |
469 | */ | |
470 | int FindLevelForIndent(int indent) const; | |
471 | ||
472 | /** | |
473 | This function combines the list style's base attributes and the level style | |
474 | matching the given indent, returning the combined attributes. | |
475 | ||
476 | If @a styleSheet is specified, the base style for this definition will also be | |
477 | included in the result. | |
478 | */ | |
479 | wxTextAttr GetCombinedStyle(int indent, | |
480 | wxRichTextStyleSheet* styleSheet = NULL); | |
481 | ||
482 | /** | |
483 | This function combines the list style's base attributes and the style for the | |
484 | specified level, returning the combined attributes. | |
485 | ||
486 | If @a styleSheet is specified, the base style for this definition will also be | |
487 | included in the result. | |
488 | */ | |
489 | ||
490 | wxTextAttr GetCombinedStyleForLevel(int level, | |
491 | wxRichTextStyleSheet* styleSheet = NULL) const; | |
492 | ||
493 | /** | |
494 | Returns the style for the given level. @a level is a number between 0 and 9. | |
495 | */ | |
496 | const wxTextAttr* GetLevelAttributes(int level) const; | |
497 | ||
498 | /** | |
499 | Returns the number of levels. This is hard-wired to 10. | |
500 | Returns the style for the given level. @e level is a number between 0 and 9. | |
501 | */ | |
502 | int GetLevelCount() const; | |
503 | ||
504 | /** | |
505 | Returns @true if the given level has numbered list attributes. | |
506 | */ | |
507 | bool IsNumbered(int level) const; | |
508 | ||
509 | /** | |
510 | Sets the style for the given level. @a level is a number between 0 and 9. | |
511 | The first and most flexible form uses a wxTextAttr object, while the second | |
512 | form is for convenient setting of the most commonly-used attributes. | |
513 | */ | |
514 | void SetLevelAttributes(int level, const wxTextAttr& attr); | |
515 | }; | |
516 | ||
517 | ||
518 | ||
519 | /** | |
520 | @class wxRichTextStyleSheet | |
521 | ||
522 | A style sheet contains named paragraph and character styles that make it | |
523 | easy for a user to apply combinations of attributes to a wxRichTextCtrl. | |
524 | ||
525 | You can use a wxRichTextStyleListBox in your user interface to show available | |
526 | styles to the user, and allow application of styles to the control. | |
527 | ||
528 | @library{wxrichtext} | |
529 | @category{richtext} | |
530 | */ | |
531 | class wxRichTextStyleSheet : public wxObject | |
532 | { | |
533 | public: | |
534 | /** | |
535 | Constructor. | |
536 | */ | |
537 | wxRichTextStyleSheet(); | |
538 | ||
539 | /** | |
540 | Destructor. | |
541 | */ | |
542 | virtual ~wxRichTextStyleSheet(); | |
543 | ||
544 | /** | |
545 | Adds a definition to the character style list. | |
546 | */ | |
547 | bool AddCharacterStyle(wxRichTextCharacterStyleDefinition* def); | |
548 | ||
549 | /** | |
550 | Adds a definition to the list style list. | |
551 | */ | |
552 | bool AddListStyle(wxRichTextListStyleDefinition* def); | |
553 | ||
554 | /** | |
555 | Adds a definition to the paragraph style list. | |
556 | */ | |
557 | bool AddParagraphStyle(wxRichTextParagraphStyleDefinition* def); | |
558 | ||
559 | /** | |
560 | Adds a definition to the appropriate style list. | |
561 | */ | |
562 | bool AddStyle(wxRichTextStyleDefinition* def); | |
563 | ||
564 | /** | |
565 | Deletes all styles. | |
566 | */ | |
567 | void DeleteStyles(); | |
568 | ||
569 | /** | |
570 | Finds a character definition by name. | |
571 | */ | |
572 | wxRichTextCharacterStyleDefinition* FindCharacterStyle(const wxString& name, | |
573 | bool recurse = true) const; | |
574 | ||
575 | /** | |
576 | Finds a list definition by name. | |
577 | */ | |
578 | wxRichTextListStyleDefinition* FindListStyle(const wxString& name, | |
579 | bool recurse = true) const; | |
580 | ||
581 | /** | |
582 | Finds a paragraph definition by name. | |
583 | */ | |
584 | wxRichTextParagraphStyleDefinition* FindParagraphStyle(const wxString& name, | |
585 | bool recurse = true) const; | |
586 | ||
587 | /** | |
588 | Finds a style definition by name. | |
589 | */ | |
590 | wxRichTextStyleDefinition* FindStyle(const wxString& name) const; | |
591 | ||
592 | /** | |
593 | Returns the @e nth character style. | |
594 | */ | |
595 | wxRichTextCharacterStyleDefinition* GetCharacterStyle(size_t n) const; | |
596 | ||
597 | /** | |
598 | Returns the number of character styles. | |
599 | */ | |
600 | size_t GetCharacterStyleCount() const; | |
601 | ||
602 | /** | |
603 | Returns the style sheet's description. | |
604 | */ | |
605 | const wxString& GetDescription() const; | |
606 | ||
607 | /** | |
608 | Returns the @e nth list style. | |
609 | */ | |
610 | wxRichTextListStyleDefinition* GetListStyle(size_t n) const; | |
611 | ||
612 | /** | |
613 | Returns the number of list styles. | |
614 | */ | |
615 | size_t GetListStyleCount() const; | |
616 | ||
617 | /** | |
618 | Returns the style sheet's name. | |
619 | */ | |
620 | const wxString& GetName() const; | |
621 | ||
622 | /** | |
623 | Returns the @e nth paragraph style. | |
624 | */ | |
625 | wxRichTextParagraphStyleDefinition* GetParagraphStyle(size_t n) const; | |
626 | ||
627 | /** | |
628 | Returns the number of paragraph styles. | |
629 | */ | |
630 | size_t GetParagraphStyleCount() const; | |
631 | ||
632 | /** | |
633 | Removes a character style. | |
634 | */ | |
635 | bool RemoveCharacterStyle(wxRichTextStyleDefinition* def, | |
636 | bool deleteStyle = false); | |
637 | ||
638 | /** | |
639 | Removes a list style. | |
640 | */ | |
641 | bool RemoveListStyle(wxRichTextStyleDefinition* def, | |
642 | bool deleteStyle = false); | |
643 | ||
644 | /** | |
645 | Removes a paragraph style. | |
646 | */ | |
647 | bool RemoveParagraphStyle(wxRichTextStyleDefinition* def, | |
648 | bool deleteStyle = false); | |
649 | ||
650 | /** | |
651 | Removes a style. | |
652 | */ | |
653 | bool RemoveStyle(wxRichTextStyleDefinition* def, | |
654 | bool deleteStyle = false); | |
655 | ||
656 | /** | |
657 | Sets the style sheet's description. | |
658 | */ | |
659 | void SetDescription(const wxString& descr); | |
660 | ||
661 | /** | |
662 | Sets the style sheet's name. | |
663 | */ | |
664 | void SetName(const wxString& name); | |
665 | }; | |
666 |