1 /////////////////////////////////////////////////////////////////////////////
2 // Name: richtext/richtextstyles.h
3 // Purpose: documentation for wxRichTextStyleListCtrl class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxRichTextStyleListCtrl
11 @headerfile richtextstyles.h wx/richtext/richtextstyles.h
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.
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.
28 @style{wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR}:
29 This style hides the category selection control.
35 class wxRichTextStyleListCtrl
: public wxControl
42 wxRichTextStyleListCtrl(wxWindow
* parent
,
43 wxWindowID id
= wxID_ANY
,
44 const wxPoint
& pos
= wxDefaultPosition
,
45 const wxSize
& size
= wxDefaultSize
,
47 wxRichTextStyleListCtrl();
53 bool Create(wxWindow
* parent
, wxWindowID id
= wxID_ANY
,
54 const wxPoint
& pos
= wxDefaultPosition
,
55 const wxSize
& size
= wxDefaultSize
,
59 Returns the associated rich text control, if any.
61 wxRichTextCtrl
* GetRichTextCtrl();
64 Returns the wxChoice control used for selecting the style category.
66 wxChoice
* GetStyleChoice();
69 Returns the wxListBox control used to view the style list.
71 wxRichTextStyleListBox
* GetStyleListBox();
74 Returns the associated style sheet, if any.
76 wxRichTextStyleSheet
* GetStyleSheet();
79 Returns the type of style to show in the list box.
81 wxRichTextStyleListBox::wxRichTextStyleType
GetStyleType();
84 Associates the control with a wxRichTextCtrl.
86 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
);
89 Associates the control with a style sheet.
91 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
);
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.
99 void SetStyleType(wxRichTextStyleListBox::wxRichTextStyleType styleType
);
102 Updates the style list box.
109 @class wxRichTextStyleDefinition
110 @headerfile richtextstyles.h wx/richtext/richtextstyles.h
112 This is a base class for paragraph and character styles.
117 class wxRichTextStyleDefinition
: public wxObject
123 wxRichTextStyleDefinition(const wxString
& name
= wxEmptyString
);
128 ~wxRichTextStyleDefinition();
131 Returns the style on which this style is based.
133 const wxString
GetBaseStyle();
136 Returns the style's description.
138 const wxString
GetDescription();
141 Returns the style name.
143 const wxString
GetName();
147 Returns the attributes associated with this style.
149 wxTextAttr
GetStyle();
150 const wxTextAttr
GetStyle();
154 Returns the style attributes combined with the attributes of the specified base
155 style, if any. This function works recursively.
157 wxTextAttr
GetStyleMergedWithBase(wxRichTextStyleSheet
* sheet
);
160 Sets the name of the style that this style is based on.
162 void SetBaseStyle(const wxString
& name
);
165 Sets the style description.
167 void SetDescription(const wxString
& descr
);
170 Sets the name of the style.
172 void SetName(const wxString
& name
);
175 Sets the attributes for this style.
177 void SetStyle(const wxTextAttr
& style
);
182 @class wxRichTextParagraphStyleDefinition
183 @headerfile richtextstyles.h wx/richtext/richtextstyles.h
185 This class represents a paragraph style definition, usually added to a
186 wxRichTextStyleSheet.
191 class wxRichTextParagraphStyleDefinition
: public wxRichTextStyleDefinition
197 wxRichTextParagraphStyleDefinition(const wxString
& name
= wxEmptyString
);
202 ~wxRichTextParagraphStyleDefinition();
205 Returns the style that should normally follow this style.
207 const wxString
GetNextStyle();
210 Sets the style that should normally follow this style.
212 void SetNextStyle(const wxString
& name
);
217 @class wxRichTextStyleListBox
218 @headerfile richtextstyles.h wx/richtext/richtextstyles.h
220 This is a listbox that can display the styles in a wxRichTextStyleSheet,
221 and apply the selection to an associated wxRichTextCtrl.
223 See @c samples/richtext for an example of how to use it.
229 wxRichTextStyleComboCtrl, @ref overview_wxrichtextctrloverview "wxRichTextCtrl
232 class wxRichTextStyleListBox
: public wxHtmlListBox
238 wxRichTextStyleListBox(wxWindow
* parent
,
239 wxWindowID id
= wxID_ANY
,
240 const wxPoint
& pos
= wxDefaultPosition
,
241 const wxSize
& size
= wxDefaultSize
,
247 ~wxRichTextStyleListBox();
250 Applies the @e ith style to the associated rich text control.
252 void ApplyStyle(int i
);
255 Converts units in tenths of a millimetre to device units.
257 int ConvertTenthsMMToPixels(wxDC
& dc
, int units
);
260 Creates a suitable HTML fragment for a definition.
262 wxString
CreateHTML(wxRichTextStyleDefinition
* def
);
265 If the return value is @true, clicking on a style name in the list will
267 apply the style to the associated rich text control.
269 bool GetApplyOnSelection();
272 Returns the wxRichTextCtrl associated with this listbox.
274 wxRichTextCtrl
* GetRichTextCtrl();
277 Gets a style for a listbox index.
279 wxRichTextStyleDefinition
* GetStyle(size_t i
);
282 Returns the style sheet associated with this listbox.
284 wxRichTextStyleSheet
* GetStyleSheet();
287 Returns the type of style to show in the list box.
289 wxRichTextStyleListBox::wxRichTextStyleType
GetStyleType();
292 Returns the HTML for this item.
294 wxString
OnGetItem(size_t n
);
297 Implements left click behaviour, applying the clicked style to the
300 void OnLeftDown(wxMouseEvent
& event
);
305 void OnSelect(wxCommandEvent
& event
);
308 If @e applyOnSelection is @true, clicking on a style name in the list will
310 apply the style to the associated rich text control.
312 void SetApplyOnSelection(bool applyOnSelection
);
315 Associates the listbox with a wxRichTextCtrl.
317 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
);
320 Associates the control with a style sheet.
322 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
);
325 Sets the style type to display. One of
326 wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL, wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH,
327 wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER and
328 wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST.
330 void SetStyleType(wxRichTextStyleListBox::wxRichTextStyleType styleType
);
333 Updates the list from the associated style sheet.
340 @class wxRichTextStyleComboCtrl
341 @headerfile richtextstyles.h wx/richtext/richtextstyles.h
343 This is a combo control that can display the styles in a wxRichTextStyleSheet,
344 and apply the selection to an associated wxRichTextCtrl.
346 See @c samples/richtext for an example of how to use it.
352 wxRichTextStyleListBox, @ref overview_wxrichtextctrloverview "wxRichTextCtrl
355 class wxRichTextStyleComboCtrl
: public wxComboCtrl
361 wxRichTextStyleComboCtrl(wxWindow
* parent
,
362 wxWindowID id
= wxID_ANY
,
363 const wxPoint
& pos
= wxDefaultPosition
,
364 const wxSize
& size
= wxDefaultSize
,
370 ~wxRichTextStyleComboCtrl();
373 Returns the wxRichTextCtrl associated with this control.
375 wxRichTextCtrl
* GetRichTextCtrl();
378 Returns the style sheet associated with this control.
380 wxRichTextStyleSheet
* GetStyleSheet();
383 Associates the control with a wxRichTextCtrl.
385 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
);
388 Associates the control with a style sheet.
390 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
);
393 Updates the combo control from the associated style sheet.
400 @class wxRichTextCharacterStyleDefinition
401 @headerfile richtextstyles.h wx/richtext/richtextstyles.h
403 This class represents a character style definition, usually added to a
404 wxRichTextStyleSheet.
409 class wxRichTextCharacterStyleDefinition
: public wxRichTextStyleDefinition
415 wxRichTextCharacterStyleDefinition(const wxString
& name
= wxEmptyString
);
420 ~wxRichTextCharacterStyleDefinition();
425 @class wxRichTextListStyleDefinition
426 @headerfile richtextstyles.h wx/richtext/richtextstyles.h
428 This class represents a list style definition, usually added to a
429 wxRichTextStyleSheet.
431 The class inherits paragraph attributes from
432 wxRichTextStyleParagraphDefinition, and adds 10 further attribute objects, one for each level of a list.
433 When applying a list style to a paragraph, the list style's base and
434 appropriate level attributes are merged with the
435 paragraph's existing attributes.
437 You can apply a list style to one or more paragraphs using
438 wxRichTextCtrl::SetListStyle. You
439 can also use the functions wxRichTextCtrl::NumberList,
440 wxRichTextCtrl::PromoteList and
441 wxRichTextCtrl::ClearListStyle. As usual, there are wxRichTextBuffer versions
443 so that you can apply them directly to a buffer without requiring a control.
448 class wxRichTextListStyleDefinition
: public wxRichTextParagraphStyleDefinition
454 wxRichTextListStyleDefinition(const wxString
& name
= wxEmptyString
);
459 ~wxRichTextListStyleDefinition();
462 This function combines the given paragraph style with the list style's base
463 attributes and level style matching the given indent, returning the combined attributes.
464 If @e styleSheet is specified, the base style for this definition will also be
465 included in the result.
467 wxTextAttr
CombineWithParagraphStyle(int indent
,
468 const wxTextAttr
& paraStyle
,
469 wxRichTextStyleSheet
* styleSheet
= @NULL
);
472 This function finds the level (from 0 to 9) whose indentation attribute mostly
473 closely matches @e indent (expressed in tenths of a millimetre).
475 int FindLevelForIndent(int indent
);
478 This function combines the list style's base attributes and the level style
479 matching the given indent, returning the combined attributes.
480 If @e styleSheet is specified, the base style for this definition will also be
481 included in the result.
483 wxTextAttr
GetCombinedStyle(int indent
,
484 wxRichTextStyleSheet
* styleSheet
= @NULL
);
487 This function combines the list style's base attributes and the style for the
488 specified level, returning the combined attributes.
489 If @e styleSheet is specified, the base style for this definition will also be
490 included in the result.
492 wxTextAttr
GetCombinedStyleLevel(int level
,
493 wxRichTextStyleSheet
* styleSheet
= @NULL
);
496 Returns the style for the given level. @e level is a number between 0 and 9.
498 const wxTextAttr
* GetLevelAttributes(int level
);
501 Returns the number of levels. This is hard-wired to 10.
503 Returns the style for the given level. @e level is a number between 0 and 9.
508 Returns @true if the given level has numbered list attributes.
510 int IsNumbered(int level
);
514 Sets the style for the given level. @e level is a number between 0 and 9.
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.
519 void SetLevelAttributes(int level
, const wxTextAttr
& attr
);
520 void SetLevelAttributes(int level
, int leftIndent
,
523 const wxString
& bulletSymbol
= wxEmptyString
);
529 @class wxRichTextStyleSheet
530 @headerfile richtextstyles.h wx/richtext/richtextstyles.h
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.
535 You can use a wxRichTextStyleListBox in your
536 user interface to show available styles to the user, and allow application
537 of styles to the control.
542 class wxRichTextStyleSheet
: public wxObject
548 wxRichTextStyleSheet();
553 ~wxRichTextStyleSheet();
556 Adds a definition to the character style list.
558 bool AddCharacterStyle(wxRichTextCharacterStyleDefinition
* def
);
561 Adds a definition to the list style list.
563 bool AddListStyle(wxRichTextListStyleDefinition
* def
);
566 Adds a definition to the paragraph style list.
568 bool AddParagraphStyle(wxRichTextParagraphStyleDefinition
* def
);
571 Adds a definition to the appropriate style list.
573 bool AddStyle(wxRichTextStyleDefinition
* def
);
581 Finds a character definition by name.
583 wxRichTextCharacterStyleDefinition
* FindCharacterStyle(const wxString
& name
);
586 Finds a list definition by name.
588 wxRichTextListStyleDefinition
* FindListStyle(const wxString
& name
);
591 Finds a paragraph definition by name.
593 wxRichTextParagraphStyleDefinition
* FindParagraphStyle(const wxString
& name
);
596 Finds a style definition by name.
598 wxRichTextStyleDefinition
* FindStyle(const wxString
& name
);
601 Returns the @e nth character style.
603 wxRichTextCharacterStyleDefinition
* GetCharacterStyle(size_t n
);
606 Returns the number of character styles.
608 size_t GetCharacterStyleCount();
611 Returns the style sheet's description.
613 const wxString
GetDescription();
616 Returns the @e nth list style.
618 wxRichTextListStyleDefinition
* GetListStyle(size_t n
);
621 Returns the number of list styles.
623 size_t GetListStyleCount();
626 Returns the style sheet's name.
628 const wxString
GetName();
631 Returns the @e nth paragraph style.
633 wxRichTextParagraphStyleDefinition
* GetParagraphStyle(size_t n
);
636 Returns the number of paragraph styles.
638 size_t GetParagraphStyleCount();
641 Removes a character style.
643 bool RemoveCharacterStyle(wxRichTextStyleDefinition
* def
,
644 bool deleteStyle
= @
false);
647 Removes a list style.
649 bool RemoveListStyle(wxRichTextStyleDefinition
* def
,
650 bool deleteStyle
= @
false);
653 Removes a paragraph style.
655 bool RemoveParagraphStyle(wxRichTextStyleDefinition
* def
,
656 bool deleteStyle
= @
false);
661 bool RemoveStyle(wxRichTextStyleDefinition
* def
,
662 bool deleteStyle
= @
false);
665 Sets the style sheet's description.
667 void SetDescription(const wxString
& descr
);
670 Sets the style sheet's name.
672 void SetName(const wxString
& name
);