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