1 /////////////////////////////////////////////////////////////////////////////
2 // Name: richtext/richtextstyles.h
3 // Purpose: interface of wxRichTextStyleListCtrl
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxRichTextStyleListCtrl
12 This class incorporates a wxRichTextStyleListBox and a choice control that
13 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 one of
19 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.
24 Associate the control with a style sheet and rich text control with
25 SetStyleSheet and SetRichTextCtrl, so that when a style is double-clicked,
26 it is applied to the selection.
29 @style{wxRICHTEXTSTYLELIST_HIDE_TYPE_SELECTOR}
30 This style hides the category selection control.
36 class wxRichTextStyleListCtrl
: public wxControl
43 wxRichTextStyleListCtrl(wxWindow
* parent
,
44 wxWindowID id
= wxID_ANY
,
45 const wxPoint
& pos
= wxDefaultPosition
,
46 const wxSize
& size
= wxDefaultSize
,
48 wxRichTextStyleListCtrl();
54 bool Create(wxWindow
* parent
, wxWindowID id
= wxID_ANY
,
55 const wxPoint
& pos
= wxDefaultPosition
,
56 const wxSize
& size
= wxDefaultSize
,
60 Returns the associated rich text control, if any.
62 wxRichTextCtrl
* GetRichTextCtrl() const;
65 Returns the wxChoice control used for selecting the style category.
67 wxChoice
* GetStyleChoice() const;
70 Returns the wxListBox control used to view the style list.
72 wxRichTextStyleListBox
* GetStyleListBox() const;
75 Returns the associated style sheet, if any.
77 wxRichTextStyleSheet
* GetStyleSheet() const;
80 Returns the type of style to show in the list box.
82 wxRichTextStyleListBox::wxRichTextStyleType
GetStyleType() const;
85 Associates the control with a wxRichTextCtrl.
87 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
);
90 Associates the control with a style sheet.
92 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
);
95 Sets the style type to display.
98 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL,
99 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH,
100 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER
101 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST.
103 void SetStyleType(wxRichTextStyleListBox::wxRichTextStyleType styleType
);
106 Updates the style list box.
114 @class wxRichTextStyleDefinition
116 This is a base class for paragraph and character styles.
121 class wxRichTextStyleDefinition
: public wxObject
127 wxRichTextStyleDefinition(const wxString
& name
= wxEmptyString
);
132 virtual ~wxRichTextStyleDefinition();
135 Returns the style on which this style is based.
137 const wxString
& GetBaseStyle() const;
140 Returns the style's description.
142 const wxString
& GetDescription() const;
145 Returns the style name.
147 const wxString
& GetName() const;
151 Returns the attributes associated with this style.
153 wxTextAttr
GetStyle() const;
154 const wxTextAttr
GetStyle() const;
158 Returns the style attributes combined with the attributes of the specified base
159 style, if any. This function works recursively.
161 virtual wxTextAttr
GetStyleMergedWithBase(const wxRichTextStyleSheet
* sheet
) const;
164 Sets the name of the style that this style is based on.
166 void SetBaseStyle(const wxString
& name
);
169 Sets the style description.
171 void SetDescription(const wxString
& descr
);
174 Sets the name of the style.
176 void SetName(const wxString
& name
);
179 Sets the attributes for this style.
181 void SetStyle(const wxTextAttr
& style
);
184 Returns the definition's properties.
186 wxRichTextProperties
& GetProperties();
189 Returns the definition's properties.
191 const wxRichTextProperties
& GetProperties() const;
194 Sets the definition's properties.
196 void SetProperties(const wxRichTextProperties
& props
);
202 @class wxRichTextParagraphStyleDefinition
204 This class represents a paragraph style definition, usually added to a
205 wxRichTextStyleSheet.
210 class wxRichTextParagraphStyleDefinition
: public wxRichTextStyleDefinition
216 wxRichTextParagraphStyleDefinition(const wxString
& name
= wxEmptyString
);
221 virtual ~wxRichTextParagraphStyleDefinition();
224 Returns the style that should normally follow this style.
226 const wxString
& GetNextStyle() const;
229 Sets the style that should normally follow this style.
231 void SetNextStyle(const wxString
& name
);
237 @class wxRichTextStyleListBox
239 This is a listbox that can display the styles in a wxRichTextStyleSheet,
240 and apply the selection to an associated wxRichTextCtrl.
242 See @c samples/richtext for an example of how to use it.
247 @see wxRichTextStyleComboCtrl, @ref overview_richtextctrl
249 class wxRichTextStyleListBox
: public wxHtmlListBox
255 wxRichTextStyleListBox(wxWindow
* parent
,
256 wxWindowID id
= wxID_ANY
,
257 const wxPoint
& pos
= wxDefaultPosition
,
258 const wxSize
& size
= wxDefaultSize
,
264 virtual ~wxRichTextStyleListBox();
267 Applies the @e ith style to the associated rich text control.
269 void ApplyStyle(int i
);
272 Converts units in tenths of a millimetre to device units.
274 int ConvertTenthsMMToPixels(wxDC
& dc
, int units
) const;
277 Creates a suitable HTML fragment for a definition.
279 wxString
CreateHTML(wxRichTextStyleDefinition
* def
) const;
282 If the return value is @true, clicking on a style name in the list will
283 immediately apply the style to the associated rich text control.
285 bool GetApplyOnSelection() const;
288 Returns the wxRichTextCtrl associated with this listbox.
290 wxRichTextCtrl
* GetRichTextCtrl() const;
293 Gets a style for a listbox index.
295 wxRichTextStyleDefinition
* GetStyle(size_t i
) const;
298 Returns the style sheet associated with this listbox.
300 wxRichTextStyleSheet
* GetStyleSheet() const;
303 Returns the type of style to show in the list box.
305 wxRichTextStyleListBox::wxRichTextStyleType
GetStyleType() const;
308 Implements left click behaviour, applying the clicked style to the
311 void OnLeftDown(wxMouseEvent
& event
);
314 If @a applyOnSelection is @true, clicking on a style name in the list will
315 immediately apply the style to the associated rich text control.
317 void SetApplyOnSelection(bool applyOnSelection
);
320 Associates the listbox with a wxRichTextCtrl.
322 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
);
325 Associates the control with a style sheet.
327 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
);
330 Sets the style type to display. One of
331 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL,
332 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH,
333 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER
334 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST.
336 void SetStyleType(wxRichTextStyleListBox::wxRichTextStyleType styleType
);
339 Updates the list from the associated style sheet.
346 Returns the HTML for this item.
348 virtual wxString
OnGetItem(size_t n
) const;
354 @class wxRichTextStyleComboCtrl
356 This is a combo control that can display the styles in a wxRichTextStyleSheet,
357 and apply the selection to an associated wxRichTextCtrl.
359 See @c samples/richtext for an example of how to use it.
364 @see wxRichTextStyleListBox, @ref overview_richtextctrl
366 class wxRichTextStyleComboCtrl
: public wxComboCtrl
372 wxRichTextStyleComboCtrl(wxWindow
* parent
,
373 wxWindowID id
= wxID_ANY
,
374 const wxPoint
& pos
= wxDefaultPosition
,
375 const wxSize
& size
= wxDefaultSize
,
381 virtual ~wxRichTextStyleComboCtrl();
384 Returns the wxRichTextCtrl associated with this control.
386 wxRichTextCtrl
* GetRichTextCtrl() const;
389 Returns the style sheet associated with this control.
391 wxRichTextStyleSheet
* GetStyleSheet() const;
394 Associates the control with a wxRichTextCtrl.
396 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
);
399 Associates the control with a style sheet.
401 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
);
404 Updates the combo control from the associated style sheet.
412 @class wxRichTextCharacterStyleDefinition
414 This class represents a character style definition, usually added to a
415 wxRichTextStyleSheet.
420 class wxRichTextCharacterStyleDefinition
: public wxRichTextStyleDefinition
426 wxRichTextCharacterStyleDefinition(const wxString
& name
= wxEmptyString
);
431 virtual ~wxRichTextCharacterStyleDefinition();
437 @class wxRichTextListStyleDefinition
439 This class represents a list style definition, usually added to a
440 wxRichTextStyleSheet.
442 The class inherits paragraph attributes from wxRichTextStyleParagraphDefinition,
443 and adds 10 further attribute objects, one for each level of a list.
444 When applying a list style to a paragraph, the list style's base and
445 appropriate level attributes are merged with the paragraph's existing attributes.
447 You can apply a list style to one or more paragraphs using wxRichTextCtrl::SetListStyle.
448 You can also use the functions wxRichTextCtrl::NumberList, wxRichTextCtrl::PromoteList and
449 wxRichTextCtrl::ClearListStyle.
451 As usual, there are wxRichTextBuffer versions of these functions
452 so that you can apply them directly to a buffer without requiring a control.
457 class wxRichTextListStyleDefinition
: public wxRichTextParagraphStyleDefinition
463 wxRichTextListStyleDefinition(const wxString
& name
= wxEmptyString
);
468 virtual ~wxRichTextListStyleDefinition();
471 This function combines the given paragraph style with the list style's base
472 attributes and level style matching the given indent, returning the combined attributes.
474 If @a styleSheet is specified, the base style for this definition will also be
475 included in the result.
477 wxTextAttr
CombineWithParagraphStyle(int indent
,
478 const wxTextAttr
& paraStyle
,
479 wxRichTextStyleSheet
* styleSheet
= NULL
);
482 This function finds the level (from 0 to 9) whose indentation attribute mostly
483 closely matches @a indent (expressed in tenths of a millimetre).
485 int FindLevelForIndent(int indent
) const;
488 This function combines the list style's base attributes and the level style
489 matching the given indent, returning the combined attributes.
491 If @a styleSheet is specified, the base style for this definition will also be
492 included in the result.
494 wxTextAttr
GetCombinedStyle(int indent
,
495 wxRichTextStyleSheet
* styleSheet
= NULL
);
498 This function combines the list style's base attributes and the style for the
499 specified level, returning the combined attributes.
501 If @a styleSheet is specified, the base style for this definition will also be
502 included in the result.
505 wxTextAttr
GetCombinedStyleForLevel(int level
,
506 wxRichTextStyleSheet
* styleSheet
= NULL
) const;
509 Returns the style for the given level. @a level is a number between 0 and 9.
511 const wxTextAttr
* GetLevelAttributes(int level
) const;
514 Returns the number of levels. This is hard-wired to 10.
515 Returns the style for the given level. @e level is a number between 0 and 9.
517 int GetLevelCount() const;
520 Returns @true if the given level has numbered list attributes.
522 bool IsNumbered(int level
) const;
525 Sets the style for the given level. @a level is a number between 0 and 9.
526 The first and most flexible form uses a wxTextAttr object, while the second
527 form is for convenient setting of the most commonly-used attributes.
529 void SetLevelAttributes(int level
, const wxTextAttr
& attr
);
535 @class wxRichTextStyleSheet
537 A style sheet contains named paragraph and character styles that make it
538 easy for a user to apply combinations of attributes to a wxRichTextCtrl.
540 You can use a wxRichTextStyleListBox in your user interface to show available
541 styles to the user, and allow application of styles to the control.
546 class wxRichTextStyleSheet
: public wxObject
552 wxRichTextStyleSheet();
557 virtual ~wxRichTextStyleSheet();
560 Adds a definition to the character style list.
562 bool AddCharacterStyle(wxRichTextCharacterStyleDefinition
* def
);
565 Adds a definition to the list style list.
567 bool AddListStyle(wxRichTextListStyleDefinition
* def
);
570 Adds a definition to the paragraph style list.
572 bool AddParagraphStyle(wxRichTextParagraphStyleDefinition
* def
);
575 Adds a definition to the appropriate style list.
577 bool AddStyle(wxRichTextStyleDefinition
* def
);
585 Finds a character definition by name.
587 wxRichTextCharacterStyleDefinition
* FindCharacterStyle(const wxString
& name
,
588 bool recurse
= true) const;
591 Finds a list definition by name.
593 wxRichTextListStyleDefinition
* FindListStyle(const wxString
& name
,
594 bool recurse
= true) const;
597 Finds a paragraph definition by name.
599 wxRichTextParagraphStyleDefinition
* FindParagraphStyle(const wxString
& name
,
600 bool recurse
= true) const;
603 Finds a style definition by name.
605 wxRichTextStyleDefinition
* FindStyle(const wxString
& name
) const;
608 Returns the @e nth character style.
610 wxRichTextCharacterStyleDefinition
* GetCharacterStyle(size_t n
) const;
613 Returns the number of character styles.
615 size_t GetCharacterStyleCount() const;
618 Returns the style sheet's description.
620 const wxString
& GetDescription() const;
623 Returns the @e nth list style.
625 wxRichTextListStyleDefinition
* GetListStyle(size_t n
) const;
628 Returns the number of list styles.
630 size_t GetListStyleCount() const;
633 Returns the style sheet's name.
635 const wxString
& GetName() const;
638 Returns the @e nth paragraph style.
640 wxRichTextParagraphStyleDefinition
* GetParagraphStyle(size_t n
) const;
643 Returns the number of paragraph styles.
645 size_t GetParagraphStyleCount() const;
648 Removes a character style.
650 bool RemoveCharacterStyle(wxRichTextStyleDefinition
* def
,
651 bool deleteStyle
= false);
654 Removes a list style.
656 bool RemoveListStyle(wxRichTextStyleDefinition
* def
,
657 bool deleteStyle
= false);
660 Removes a paragraph style.
662 bool RemoveParagraphStyle(wxRichTextStyleDefinition
* def
,
663 bool deleteStyle
= false);
668 bool RemoveStyle(wxRichTextStyleDefinition
* def
,
669 bool deleteStyle
= false);
672 Sets the style sheet's description.
674 void SetDescription(const wxString
& descr
);
677 Sets the style sheet's name.
679 void SetName(const wxString
& name
);
682 Returns the sheet's properties.
684 wxRichTextProperties
& GetProperties();
687 Returns the sheet's properties.
689 const wxRichTextProperties
& GetProperties() const;
692 Sets the sheet's properties.
694 void SetProperties(const wxRichTextProperties
& props
);