1 /////////////////////////////////////////////////////////////////////////////
2 // Name: richtext/richtextstyles.h
3 // Purpose: interface of wxRichTextStyleListCtrl
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
9 @class wxRichTextStyleListCtrl
11 This class incorporates a wxRichTextStyleListBox and a choice control that
12 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 one of
18 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.
23 Associate the control with a style sheet and rich text control with
24 SetStyleSheet and SetRichTextCtrl, so that when a style is double-clicked,
25 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() const;
64 Returns the wxChoice control used for selecting the style category.
66 wxChoice
* GetStyleChoice() const;
69 Returns the wxListBox control used to view the style list.
71 wxRichTextStyleListBox
* GetStyleListBox() const;
74 Returns the associated style sheet, if any.
76 wxRichTextStyleSheet
* GetStyleSheet() const;
79 Returns the type of style to show in the list box.
81 wxRichTextStyleListBox::wxRichTextStyleType
GetStyleType() const;
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.
97 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL,
98 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH,
99 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER
100 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST.
102 void SetStyleType(wxRichTextStyleListBox::wxRichTextStyleType styleType
);
105 Updates the style list box.
113 @class wxRichTextStyleDefinition
115 This is a base class for paragraph and character styles.
120 class wxRichTextStyleDefinition
: public wxObject
126 wxRichTextStyleDefinition(const wxString
& name
= wxEmptyString
);
131 virtual ~wxRichTextStyleDefinition();
134 Returns the style on which this style is based.
136 const wxString
& GetBaseStyle() const;
139 Returns the style's description.
141 const wxString
& GetDescription() const;
144 Returns the style name.
146 const wxString
& GetName() const;
150 Returns the attributes associated with this style.
152 wxRichTextAttr
GetStyle() const;
153 const wxRichTextAttr
GetStyle() const;
157 Returns the style attributes combined with the attributes of the specified base
158 style, if any. This function works recursively.
160 virtual wxRichTextAttr
GetStyleMergedWithBase(const wxRichTextStyleSheet
* sheet
) const;
163 Sets the name of the style that this style is based on.
165 void SetBaseStyle(const wxString
& name
);
168 Sets the style description.
170 void SetDescription(const wxString
& descr
);
173 Sets the name of the style.
175 void SetName(const wxString
& name
);
178 Sets the attributes for this style.
180 void SetStyle(const wxRichTextAttr
& style
);
183 Returns the definition's properties.
185 wxRichTextProperties
& GetProperties();
188 Returns the definition's properties.
190 const wxRichTextProperties
& GetProperties() const;
193 Sets the definition's properties.
195 void SetProperties(const wxRichTextProperties
& props
);
201 @class wxRichTextParagraphStyleDefinition
203 This class represents a paragraph style definition, usually added to a
204 wxRichTextStyleSheet.
209 class wxRichTextParagraphStyleDefinition
: public wxRichTextStyleDefinition
215 wxRichTextParagraphStyleDefinition(const wxString
& name
= wxEmptyString
);
220 virtual ~wxRichTextParagraphStyleDefinition();
223 Returns the style that should normally follow this style.
225 const wxString
& GetNextStyle() const;
228 Sets the style that should normally follow this style.
230 void SetNextStyle(const wxString
& name
);
236 @class wxRichTextStyleListBox
238 This is a listbox that can display the styles in a wxRichTextStyleSheet,
239 and apply the selection to an associated wxRichTextCtrl.
241 See @c samples/richtext for an example of how to use it.
246 @see wxRichTextStyleComboCtrl, @ref overview_richtextctrl
248 class wxRichTextStyleListBox
: public wxHtmlListBox
252 /// Which type of style definition is currently showing?
253 enum wxRichTextStyleType
255 wxRICHTEXT_STYLE_ALL
,
256 wxRICHTEXT_STYLE_PARAGRAPH
,
257 wxRICHTEXT_STYLE_CHARACTER
,
258 wxRICHTEXT_STYLE_LIST
,
265 wxRichTextStyleListBox(wxWindow
* parent
,
266 wxWindowID id
= wxID_ANY
,
267 const wxPoint
& pos
= wxDefaultPosition
,
268 const wxSize
& size
= wxDefaultSize
,
274 virtual ~wxRichTextStyleListBox();
277 Applies the @e ith style to the associated rich text control.
279 void ApplyStyle(int i
);
282 Converts units in tenths of a millimetre to device units.
284 int ConvertTenthsMMToPixels(wxDC
& dc
, int units
) const;
287 Creates a suitable HTML fragment for a definition.
289 wxString
CreateHTML(wxRichTextStyleDefinition
* def
) const;
292 If the return value is @true, clicking on a style name in the list will
293 immediately apply the style to the associated rich text control.
295 bool GetApplyOnSelection() const;
298 Returns the wxRichTextCtrl associated with this listbox.
300 wxRichTextCtrl
* GetRichTextCtrl() const;
303 Gets a style for a listbox index.
305 wxRichTextStyleDefinition
* GetStyle(size_t i
) const;
308 Returns the style sheet associated with this listbox.
310 wxRichTextStyleSheet
* GetStyleSheet() const;
313 Returns the type of style to show in the list box.
315 wxRichTextStyleListBox::wxRichTextStyleType
GetStyleType() const;
318 Implements left click behaviour, applying the clicked style to the
321 void OnLeftDown(wxMouseEvent
& event
);
324 If @a applyOnSelection is @true, clicking on a style name in the list will
325 immediately apply the style to the associated rich text control.
327 void SetApplyOnSelection(bool applyOnSelection
);
330 Associates the listbox with a wxRichTextCtrl.
332 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
);
335 Associates the control with a style sheet.
337 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
);
340 Sets the style type to display. One of
341 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL,
342 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH,
343 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER
344 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST.
346 void SetStyleType(wxRichTextStyleListBox::wxRichTextStyleType styleType
);
349 Updates the list from the associated style sheet.
356 Returns the HTML for this item.
358 virtual wxString
OnGetItem(size_t n
) const;
364 @class wxRichTextStyleComboCtrl
366 This is a combo control that can display the styles in a wxRichTextStyleSheet,
367 and apply the selection to an associated wxRichTextCtrl.
369 See @c samples/richtext for an example of how to use it.
374 @see wxRichTextStyleListBox, @ref overview_richtextctrl
376 class wxRichTextStyleComboCtrl
: public wxComboCtrl
382 wxRichTextStyleComboCtrl(wxWindow
* parent
,
383 wxWindowID id
= wxID_ANY
,
384 const wxPoint
& pos
= wxDefaultPosition
,
385 const wxSize
& size
= wxDefaultSize
,
391 virtual ~wxRichTextStyleComboCtrl();
394 Returns the wxRichTextCtrl associated with this control.
396 wxRichTextCtrl
* GetRichTextCtrl() const;
399 Returns the style sheet associated with this control.
401 wxRichTextStyleSheet
* GetStyleSheet() const;
404 Associates the control with a wxRichTextCtrl.
406 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
);
409 Associates the control with a style sheet.
411 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
);
414 Updates the combo control from the associated style sheet.
422 @class wxRichTextCharacterStyleDefinition
424 This class represents a character style definition, usually added to a
425 wxRichTextStyleSheet.
430 class wxRichTextCharacterStyleDefinition
: public wxRichTextStyleDefinition
436 wxRichTextCharacterStyleDefinition(const wxString
& name
= wxEmptyString
);
441 virtual ~wxRichTextCharacterStyleDefinition();
447 @class wxRichTextListStyleDefinition
449 This class represents a list style definition, usually added to a
450 wxRichTextStyleSheet.
452 The class inherits paragraph attributes from wxRichTextStyleParagraphDefinition,
453 and adds 10 further attribute objects, one for each level of a list.
454 When applying a list style to a paragraph, the list style's base and
455 appropriate level attributes are merged with the paragraph's existing attributes.
457 You can apply a list style to one or more paragraphs using wxRichTextCtrl::SetListStyle.
458 You can also use the functions wxRichTextCtrl::NumberList, wxRichTextCtrl::PromoteList and
459 wxRichTextCtrl::ClearListStyle.
461 As usual, there are wxRichTextBuffer versions of these functions
462 so that you can apply them directly to a buffer without requiring a control.
467 class wxRichTextListStyleDefinition
: public wxRichTextParagraphStyleDefinition
473 wxRichTextListStyleDefinition(const wxString
& name
= wxEmptyString
);
478 virtual ~wxRichTextListStyleDefinition();
481 This function combines the given paragraph style with the list style's base
482 attributes and level style matching the given indent, returning the combined attributes.
484 If @a styleSheet is specified, the base style for this definition will also be
485 included in the result.
487 wxRichTextAttr
CombineWithParagraphStyle(int indent
,
488 const wxRichTextAttr
& paraStyle
,
489 wxRichTextStyleSheet
* styleSheet
= NULL
);
492 This function finds the level (from 0 to 9) whose indentation attribute mostly
493 closely matches @a indent (expressed in tenths of a millimetre).
495 int FindLevelForIndent(int indent
) const;
498 This function combines the list style's base attributes and the level style
499 matching the given indent, returning the combined attributes.
501 If @a styleSheet is specified, the base style for this definition will also be
502 included in the result.
504 wxRichTextAttr
GetCombinedStyle(int indent
,
505 wxRichTextStyleSheet
* styleSheet
= NULL
);
508 This function combines the list style's base attributes and the style for the
509 specified level, returning the combined attributes.
511 If @a styleSheet is specified, the base style for this definition will also be
512 included in the result.
515 wxRichTextAttr
GetCombinedStyleForLevel(int level
,
516 wxRichTextStyleSheet
* styleSheet
= NULL
);
519 Returns the style for the given level. @a level is a number between 0 and 9.
521 const wxRichTextAttr
* GetLevelAttributes(int level
) const;
524 Returns the number of levels. This is hard-wired to 10.
525 Returns the style for the given level. @e level is a number between 0 and 9.
527 int GetLevelCount() const;
530 Returns @true if the given level has numbered list attributes.
532 bool IsNumbered(int level
) const;
535 Sets the style for the given level. @a level is a number between 0 and 9.
536 The first and most flexible form uses a wxTextAttr object, while the second
537 form is for convenient setting of the most commonly-used attributes.
539 void SetLevelAttributes(int level
, const wxRichTextAttr
& attr
);
545 @class wxRichTextStyleSheet
547 A style sheet contains named paragraph and character styles that make it
548 easy for a user to apply combinations of attributes to a wxRichTextCtrl.
550 You can use a wxRichTextStyleListBox in your user interface to show available
551 styles to the user, and allow application of styles to the control.
556 class wxRichTextStyleSheet
: public wxObject
562 wxRichTextStyleSheet();
567 virtual ~wxRichTextStyleSheet();
570 Adds a definition to the character style list.
572 bool AddCharacterStyle(wxRichTextCharacterStyleDefinition
* def
);
575 Adds a definition to the list style list.
577 bool AddListStyle(wxRichTextListStyleDefinition
* def
);
580 Adds a definition to the paragraph style list.
582 bool AddParagraphStyle(wxRichTextParagraphStyleDefinition
* def
);
585 Adds a definition to the appropriate style list.
587 bool AddStyle(wxRichTextStyleDefinition
* def
);
595 Finds a character definition by name.
597 wxRichTextCharacterStyleDefinition
* FindCharacterStyle(const wxString
& name
,
598 bool recurse
= true) const;
601 Finds a list definition by name.
603 wxRichTextListStyleDefinition
* FindListStyle(const wxString
& name
,
604 bool recurse
= true) const;
607 Finds a paragraph definition by name.
609 wxRichTextParagraphStyleDefinition
* FindParagraphStyle(const wxString
& name
,
610 bool recurse
= true) const;
613 Finds a style definition by name.
615 wxRichTextStyleDefinition
* FindStyle(const wxString
& name
) const;
618 Returns the @e nth character style.
620 wxRichTextCharacterStyleDefinition
* GetCharacterStyle(size_t n
) const;
623 Returns the number of character styles.
625 size_t GetCharacterStyleCount() const;
628 Returns the style sheet's description.
630 const wxString
& GetDescription() const;
633 Returns the @e nth list style.
635 wxRichTextListStyleDefinition
* GetListStyle(size_t n
) const;
638 Returns the number of list styles.
640 size_t GetListStyleCount() const;
643 Returns the style sheet's name.
645 const wxString
& GetName() const;
648 Returns the @e nth paragraph style.
650 wxRichTextParagraphStyleDefinition
* GetParagraphStyle(size_t n
) const;
653 Returns the number of paragraph styles.
655 size_t GetParagraphStyleCount() const;
658 Removes a character style.
660 bool RemoveCharacterStyle(wxRichTextStyleDefinition
* def
,
661 bool deleteStyle
= false);
664 Removes a list style.
666 bool RemoveListStyle(wxRichTextStyleDefinition
* def
,
667 bool deleteStyle
= false);
670 Removes a paragraph style.
672 bool RemoveParagraphStyle(wxRichTextStyleDefinition
* def
,
673 bool deleteStyle
= false);
678 bool RemoveStyle(wxRichTextStyleDefinition
* def
,
679 bool deleteStyle
= false);
682 Sets the style sheet's description.
684 void SetDescription(const wxString
& descr
);
687 Sets the style sheet's name.
689 void SetName(const wxString
& name
);
692 Returns the sheet's properties.
694 wxRichTextProperties
& GetProperties();
697 Returns the sheet's properties.
699 const wxRichTextProperties
& GetProperties() const;
702 Sets the sheet's properties.
704 void SetProperties(const wxRichTextProperties
& props
);