1 /////////////////////////////////////////////////////////////////////////////
2 // Name: richtext/richtextstyles.h
3 // Purpose: interface of wxRichTextStyleListCtrl
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxRichTextStyleListCtrl
12 This class incorporates a wxRichTextStyleListBox and
13 a choice control that allows the user to select the category of style to view.
14 It is demonstrated in the wxRichTextCtrl sample in @c samples/richtext.
16 To use wxRichTextStyleListCtrl, add the control to your window hierarchy and
17 call wxRichTextStyleListCtrl::SetStyleType with
18 one of wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL,
19 wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH,
20 wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER and
21 wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST to set the current view.
22 Associate the control with a style sheet and rich text control with
23 SetStyleSheet and SetRichTextCtrl,
24 so that when a style is double-clicked, it is applied to the selection.
27 @style{wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR}
28 This style hides the category selection control.
34 class wxRichTextStyleListCtrl
: public wxControl
41 wxRichTextStyleListCtrl(wxWindow
* parent
,
42 wxWindowID id
= wxID_ANY
,
43 const wxPoint
& pos
= wxDefaultPosition
,
44 const wxSize
& size
= wxDefaultSize
,
46 wxRichTextStyleListCtrl();
52 bool Create(wxWindow
* parent
, wxWindowID id
= wxID_ANY
,
53 const wxPoint
& pos
= wxDefaultPosition
,
54 const wxSize
& size
= wxDefaultSize
,
58 Returns the associated rich text control, if any.
60 wxRichTextCtrl
* GetRichTextCtrl() const;
63 Returns the wxChoice control used for selecting the style category.
65 wxChoice
* GetStyleChoice() const;
68 Returns the wxListBox control used to view the style list.
70 wxRichTextStyleListBox
* GetStyleListBox() const;
73 Returns the associated style sheet, if any.
75 wxRichTextStyleSheet
* GetStyleSheet() const;
78 Returns the type of style to show in the list box.
80 wxRichTextStyleListBox::wxRichTextStyleType
GetStyleType() const;
83 Associates the control with a wxRichTextCtrl.
85 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
);
88 Associates the control with a style sheet.
90 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
);
93 Sets the style type to display. One of
94 wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL, wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH,
95 wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER and
96 wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST.
98 void SetStyleType(wxRichTextStyleListBox::wxRichTextStyleType styleType
);
101 Updates the style list box.
109 @class wxRichTextStyleDefinition
111 This is a base class for paragraph and character styles.
116 class wxRichTextStyleDefinition
: public wxObject
122 wxRichTextStyleDefinition(const wxString
& name
= wxEmptyString
);
127 ~wxRichTextStyleDefinition();
130 Returns the style on which this style is based.
132 const wxString
GetBaseStyle() const;
135 Returns the style's description.
137 const wxString
GetDescription() const;
140 Returns the style name.
142 const wxString
GetName() const;
146 Returns the attributes associated with this style.
148 wxTextAttr
GetStyle() const;
149 const wxTextAttr
GetStyle() const;
153 Returns the style attributes combined with the attributes of the specified base
154 style, if any. This function works recursively.
156 wxTextAttr
GetStyleMergedWithBase(wxRichTextStyleSheet
* sheet
) const;
159 Sets the name of the style that this style is based on.
161 void SetBaseStyle(const wxString
& name
);
164 Sets the style description.
166 void SetDescription(const wxString
& descr
);
169 Sets the name of the style.
171 void SetName(const wxString
& name
);
174 Sets the attributes for this style.
176 void SetStyle(const wxTextAttr
& style
);
182 @class wxRichTextParagraphStyleDefinition
184 This class represents a paragraph style definition, usually added to a
185 wxRichTextStyleSheet.
190 class wxRichTextParagraphStyleDefinition
: public wxRichTextStyleDefinition
196 wxRichTextParagraphStyleDefinition(const wxString
& name
= wxEmptyString
);
201 ~wxRichTextParagraphStyleDefinition();
204 Returns the style that should normally follow this style.
206 const wxString
GetNextStyle() const;
209 Sets the style that should normally follow this style.
211 void SetNextStyle(const wxString
& name
);
217 @class wxRichTextStyleListBox
219 This is a listbox that can display the styles in a wxRichTextStyleSheet,
220 and apply the selection to an associated wxRichTextCtrl.
222 See @c samples/richtext for an example of how to use it.
227 @see wxRichTextStyleComboCtrl, @ref overview_wxrichtextctrloverview
228 "wxRichTextCtrl overview"
230 class wxRichTextStyleListBox
: public wxHtmlListBox
236 wxRichTextStyleListBox(wxWindow
* parent
,
237 wxWindowID id
= wxID_ANY
,
238 const wxPoint
& pos
= wxDefaultPosition
,
239 const wxSize
& size
= wxDefaultSize
,
245 ~wxRichTextStyleListBox();
248 Applies the @e ith style to the associated rich text control.
250 void ApplyStyle(int i
);
253 Converts units in tenths of a millimetre to device units.
255 int ConvertTenthsMMToPixels(wxDC
& dc
, int units
) const;
258 Creates a suitable HTML fragment for a definition.
260 wxString
CreateHTML(wxRichTextStyleDefinition
* def
) const;
263 If the return value is @true, clicking on a style name in the list will
265 apply the style to the associated rich text control.
267 bool GetApplyOnSelection() const;
270 Returns the wxRichTextCtrl associated with this listbox.
272 wxRichTextCtrl
* GetRichTextCtrl() const;
275 Gets a style for a listbox index.
277 wxRichTextStyleDefinition
* GetStyle(size_t i
) const;
280 Returns the style sheet associated with this listbox.
282 wxRichTextStyleSheet
* GetStyleSheet() const;
285 Returns the type of style to show in the list box.
287 wxRichTextStyleListBox::wxRichTextStyleType
GetStyleType() const;
290 Returns the HTML for this item.
292 wxString
OnGetItem(size_t n
) const;
295 Implements left click behaviour, applying the clicked style to the
298 void OnLeftDown(wxMouseEvent
& event
);
303 void OnSelect(wxCommandEvent
& event
);
306 If @a applyOnSelection is @true, clicking on a style name in the list will
308 apply the style to the associated rich text control.
310 void SetApplyOnSelection(bool applyOnSelection
);
313 Associates the listbox with a wxRichTextCtrl.
315 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
);
318 Associates the control with a style sheet.
320 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
);
323 Sets the style type to display. One of
324 wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL, wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH,
325 wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER and
326 wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST.
328 void SetStyleType(wxRichTextStyleListBox::wxRichTextStyleType styleType
);
331 Updates the list from the associated style sheet.
339 @class wxRichTextStyleComboCtrl
341 This is a combo control that can display the styles in a wxRichTextStyleSheet,
342 and apply the selection to an associated wxRichTextCtrl.
344 See @c samples/richtext for an example of how to use it.
349 @see wxRichTextStyleListBox, @ref overview_wxrichtextctrloverview
350 "wxRichTextCtrl overview"
352 class wxRichTextStyleComboCtrl
: public wxComboCtrl
358 wxRichTextStyleComboCtrl(wxWindow
* parent
,
359 wxWindowID id
= wxID_ANY
,
360 const wxPoint
& pos
= wxDefaultPosition
,
361 const wxSize
& size
= wxDefaultSize
,
367 ~wxRichTextStyleComboCtrl();
370 Returns the wxRichTextCtrl associated with this control.
372 wxRichTextCtrl
* GetRichTextCtrl() const;
375 Returns the style sheet associated with this control.
377 wxRichTextStyleSheet
* GetStyleSheet() const;
380 Associates the control with a wxRichTextCtrl.
382 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
);
385 Associates the control with a style sheet.
387 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
);
390 Updates the combo control from the associated style sheet.
398 @class wxRichTextCharacterStyleDefinition
400 This class represents a character style definition, usually added to a
401 wxRichTextStyleSheet.
406 class wxRichTextCharacterStyleDefinition
: public wxRichTextStyleDefinition
412 wxRichTextCharacterStyleDefinition(const wxString
& name
= wxEmptyString
);
417 ~wxRichTextCharacterStyleDefinition();
423 @class wxRichTextListStyleDefinition
425 This class represents a list style definition, usually added to a
426 wxRichTextStyleSheet.
428 The class inherits paragraph attributes from
429 wxRichTextStyleParagraphDefinition, and adds 10 further attribute objects, one for each level of a list.
430 When applying a list style to a paragraph, the list style's base and
431 appropriate level attributes are merged with the
432 paragraph's existing attributes.
434 You can apply a list style to one or more paragraphs using
435 wxRichTextCtrl::SetListStyle. You
436 can also use the functions wxRichTextCtrl::NumberList,
437 wxRichTextCtrl::PromoteList and
438 wxRichTextCtrl::ClearListStyle. As usual, there are wxRichTextBuffer versions
440 so that you can apply them directly to a buffer without requiring a control.
445 class wxRichTextListStyleDefinition
: public wxRichTextParagraphStyleDefinition
451 wxRichTextListStyleDefinition(const wxString
& name
= wxEmptyString
);
456 ~wxRichTextListStyleDefinition();
459 This function combines the given paragraph style with the list style's base
460 attributes and level style matching the given indent, returning the combined attributes.
461 If @a styleSheet is specified, the base style for this definition will also be
462 included in the result.
464 wxTextAttr
CombineWithParagraphStyle(int indent
,
465 const wxTextAttr
& paraStyle
,
466 wxRichTextStyleSheet
* styleSheet
= NULL
);
469 This function finds the level (from 0 to 9) whose indentation attribute mostly
470 closely matches @a indent (expressed in tenths of a millimetre).
472 int FindLevelForIndent(int indent
) const;
475 This function combines the list style's base attributes and the level style
476 matching the given indent, returning the combined attributes.
477 If @a styleSheet is specified, the base style for this definition will also be
478 included in the result.
480 wxTextAttr
GetCombinedStyle(int indent
,
481 wxRichTextStyleSheet
* styleSheet
= NULL
) const;
484 This function combines the list style's base attributes and the style for the
485 specified level, returning the combined attributes.
486 If @a styleSheet is specified, the base style for this definition will also be
487 included in the result.
489 wxTextAttr
GetCombinedStyleLevel(int level
,
490 wxRichTextStyleSheet
* styleSheet
= NULL
) const;
493 Returns the style for the given level. @a level is a number between 0 and 9.
495 const wxTextAttr
* GetLevelAttributes(int level
) const;
498 Returns the number of levels. This is hard-wired to 10.
499 Returns the style for the given level. @e level is a number between 0 and 9.
501 int GetLevelCount() const;
504 Returns @true if the given level has numbered list attributes.
506 int IsNumbered(int level
) const;
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.
514 void SetLevelAttributes(int level
, const wxTextAttr
& attr
);
515 void SetLevelAttributes(int level
, int leftIndent
,
518 const wxString
& bulletSymbol
= wxEmptyString
);
525 @class wxRichTextStyleSheet
527 A style sheet contains named paragraph and character styles that make it
528 easy for a user to apply combinations of attributes to a wxRichTextCtrl.
530 You can use a wxRichTextStyleListBox in your
531 user interface to show available styles to the user, and allow application
532 of styles to the control.
537 class wxRichTextStyleSheet
: public wxObject
543 wxRichTextStyleSheet();
548 ~wxRichTextStyleSheet();
551 Adds a definition to the character style list.
553 bool AddCharacterStyle(wxRichTextCharacterStyleDefinition
* def
);
556 Adds a definition to the list style list.
558 bool AddListStyle(wxRichTextListStyleDefinition
* def
);
561 Adds a definition to the paragraph style list.
563 bool AddParagraphStyle(wxRichTextParagraphStyleDefinition
* def
);
566 Adds a definition to the appropriate style list.
568 bool AddStyle(wxRichTextStyleDefinition
* def
);
576 Finds a character definition by name.
578 wxRichTextCharacterStyleDefinition
* FindCharacterStyle(const wxString
& name
) const;
581 Finds a list definition by name.
583 wxRichTextListStyleDefinition
* FindListStyle(const wxString
& name
) const;
586 Finds a paragraph definition by name.
588 wxRichTextParagraphStyleDefinition
* FindParagraphStyle(const wxString
& name
) const;
591 Finds a style definition by name.
593 wxRichTextStyleDefinition
* FindStyle(const wxString
& name
) const;
596 Returns the @e nth character style.
598 wxRichTextCharacterStyleDefinition
* GetCharacterStyle(size_t n
) const;
601 Returns the number of character styles.
603 size_t GetCharacterStyleCount() const;
606 Returns the style sheet's description.
608 const wxString
GetDescription() const;
611 Returns the @e nth list style.
613 wxRichTextListStyleDefinition
* GetListStyle(size_t n
) const;
616 Returns the number of list styles.
618 size_t GetListStyleCount() const;
621 Returns the style sheet's name.
623 const wxString
GetName() const;
626 Returns the @e nth paragraph style.
628 wxRichTextParagraphStyleDefinition
* GetParagraphStyle(size_t n
) const;
631 Returns the number of paragraph styles.
633 size_t GetParagraphStyleCount() const;
636 Removes a character style.
638 bool RemoveCharacterStyle(wxRichTextStyleDefinition
* def
,
639 bool deleteStyle
= false);
642 Removes a list style.
644 bool RemoveListStyle(wxRichTextStyleDefinition
* def
,
645 bool deleteStyle
= false);
648 Removes a paragraph style.
650 bool RemoveParagraphStyle(wxRichTextStyleDefinition
* def
,
651 bool deleteStyle
= false);
656 bool RemoveStyle(wxRichTextStyleDefinition
* def
,
657 bool deleteStyle
= false);
660 Sets the style sheet's description.
662 void SetDescription(const wxString
& descr
);
665 Sets the style sheet's name.
667 void SetName(const wxString
& name
);