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