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 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
);
187 @class wxRichTextParagraphStyleDefinition
189 This class represents a paragraph style definition, usually added to a
190 wxRichTextStyleSheet.
195 class wxRichTextParagraphStyleDefinition
: public wxRichTextStyleDefinition
201 wxRichTextParagraphStyleDefinition(const wxString
& name
= wxEmptyString
);
206 virtual ~wxRichTextParagraphStyleDefinition();
209 Returns the style that should normally follow this style.
211 const wxString
& GetNextStyle() const;
214 Sets the style that should normally follow this style.
216 void SetNextStyle(const wxString
& name
);
222 @class wxRichTextStyleListBox
224 This is a listbox that can display the styles in a wxRichTextStyleSheet,
225 and apply the selection to an associated wxRichTextCtrl.
227 See @c samples/richtext for an example of how to use it.
232 @see wxRichTextStyleComboCtrl, @ref overview_richtextctrl
234 class wxRichTextStyleListBox
: public wxHtmlListBox
240 wxRichTextStyleListBox(wxWindow
* parent
,
241 wxWindowID id
= wxID_ANY
,
242 const wxPoint
& pos
= wxDefaultPosition
,
243 const wxSize
& size
= wxDefaultSize
,
249 virtual ~wxRichTextStyleListBox();
252 Applies the @e ith style to the associated rich text control.
254 void ApplyStyle(int i
);
257 Converts units in tenths of a millimetre to device units.
259 int ConvertTenthsMMToPixels(wxDC
& dc
, int units
) const;
262 Creates a suitable HTML fragment for a definition.
264 wxString
CreateHTML(wxRichTextStyleDefinition
* def
) const;
267 If the return value is @true, clicking on a style name in the list will
268 immediately apply the style to the associated rich text control.
270 bool GetApplyOnSelection() const;
273 Returns the wxRichTextCtrl associated with this listbox.
275 wxRichTextCtrl
* GetRichTextCtrl() const;
278 Gets a style for a listbox index.
280 wxRichTextStyleDefinition
* GetStyle(size_t i
) const;
283 Returns the style sheet associated with this listbox.
285 wxRichTextStyleSheet
* GetStyleSheet() const;
288 Returns the type of style to show in the list box.
290 wxRichTextStyleListBox::wxRichTextStyleType
GetStyleType() const;
293 Implements left click behaviour, applying the clicked style to the
296 void OnLeftDown(wxMouseEvent
& event
);
301 void OnSelect(wxCommandEvent
& event
);
304 If @a applyOnSelection is @true, clicking on a style name in the list will
305 immediately apply the style to the associated rich text control.
307 void SetApplyOnSelection(bool applyOnSelection
);
310 Associates the listbox with a wxRichTextCtrl.
312 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
);
315 Associates the control with a style sheet.
317 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
);
320 Sets the style type to display. One of
321 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL,
322 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH,
323 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER
324 - wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST.
326 void SetStyleType(wxRichTextStyleListBox::wxRichTextStyleType styleType
);
329 Updates the list from the associated style sheet.
336 Returns the HTML for this item.
338 virtual wxString
OnGetItem(size_t n
) const;
344 @class wxRichTextStyleComboCtrl
346 This is a combo control that can display the styles in a wxRichTextStyleSheet,
347 and apply the selection to an associated wxRichTextCtrl.
349 See @c samples/richtext for an example of how to use it.
354 @see wxRichTextStyleListBox, @ref overview_richtextctrl
356 class wxRichTextStyleComboCtrl
: public wxComboCtrl
362 wxRichTextStyleComboCtrl(wxWindow
* parent
,
363 wxWindowID id
= wxID_ANY
,
364 const wxPoint
& pos
= wxDefaultPosition
,
365 const wxSize
& size
= wxDefaultSize
,
371 virtual ~wxRichTextStyleComboCtrl();
374 Returns the wxRichTextCtrl associated with this control.
376 wxRichTextCtrl
* GetRichTextCtrl() const;
379 Returns the style sheet associated with this control.
381 wxRichTextStyleSheet
* GetStyleSheet() const;
384 Associates the control with a wxRichTextCtrl.
386 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
);
389 Associates the control with a style sheet.
391 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
);
394 Updates the combo control from the associated style sheet.
402 @class wxRichTextCharacterStyleDefinition
404 This class represents a character style definition, usually added to a
405 wxRichTextStyleSheet.
410 class wxRichTextCharacterStyleDefinition
: public wxRichTextStyleDefinition
416 wxRichTextCharacterStyleDefinition(const wxString
& name
= wxEmptyString
);
421 virtual ~wxRichTextCharacterStyleDefinition();
427 @class wxRichTextListStyleDefinition
429 This class represents a list style definition, usually added to a
430 wxRichTextStyleSheet.
432 The class inherits paragraph attributes from wxRichTextStyleParagraphDefinition,
433 and adds 10 further attribute objects, one for each level of a list.
434 When applying a list style to a paragraph, the list style's base and
435 appropriate level attributes are merged with the paragraph's existing attributes.
437 You can apply a list style to one or more paragraphs using wxRichTextCtrl::SetListStyle.
438 You can also use the functions wxRichTextCtrl::NumberList, wxRichTextCtrl::PromoteList and
439 wxRichTextCtrl::ClearListStyle.
441 As usual, there are wxRichTextBuffer versions of these functions
442 so that you can apply them directly to a buffer without requiring a control.
447 class wxRichTextListStyleDefinition
: public wxRichTextParagraphStyleDefinition
453 wxRichTextListStyleDefinition(const wxString
& name
= wxEmptyString
);
458 virtual ~wxRichTextListStyleDefinition();
461 This function combines the given paragraph style with the list style's base
462 attributes and level style matching the given indent, returning the combined attributes.
464 If @a 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 @a indent (expressed in tenths of a millimetre).
475 int FindLevelForIndent(int indent
) const;
478 This function combines the list style's base attributes and the level style
479 matching the given indent, returning the combined attributes.
481 If @a styleSheet is specified, the base style for this definition will also be
482 included in the result.
484 wxTextAttr
GetCombinedStyle(int indent
,
485 wxRichTextStyleSheet
* styleSheet
= NULL
);
488 This function combines the list style's base attributes and the style for the
489 specified level, 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
GetCombinedStyleLevel(int level
,
495 wxRichTextStyleSheet
* styleSheet
= NULL
) const;
498 Returns the style for the given level. @a level is a number between 0 and 9.
500 const wxTextAttr
* GetLevelAttributes(int level
) const;
503 Returns the number of levels. This is hard-wired to 10.
504 Returns the style for the given level. @e level is a number between 0 and 9.
506 int GetLevelCount() const;
509 Returns @true if the given level has numbered list attributes.
511 bool IsNumbered(int level
) const;
515 Sets the style for the given level. @a 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
);
530 @class wxRichTextStyleSheet
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 user interface to show available
536 styles to the user, and allow application of styles to the control.
541 class wxRichTextStyleSheet
: public wxObject
547 wxRichTextStyleSheet();
552 virtual ~wxRichTextStyleSheet();
555 Adds a definition to the character style list.
557 bool AddCharacterStyle(wxRichTextCharacterStyleDefinition
* def
);
560 Adds a definition to the list style list.
562 bool AddListStyle(wxRichTextListStyleDefinition
* def
);
565 Adds a definition to the paragraph style list.
567 bool AddParagraphStyle(wxRichTextParagraphStyleDefinition
* def
);
570 Adds a definition to the appropriate style list.
572 bool AddStyle(wxRichTextStyleDefinition
* def
);
580 Finds a character definition by name.
582 wxRichTextCharacterStyleDefinition
* FindCharacterStyle(const wxString
& name
,
583 bool recurse
= true) const;
586 Finds a list definition by name.
588 wxRichTextListStyleDefinition
* FindListStyle(const wxString
& name
,
589 bool recurse
= true) const;
592 Finds a paragraph definition by name.
594 wxRichTextParagraphStyleDefinition
* FindParagraphStyle(const wxString
& name
,
595 bool recurse
= true) const;
598 Finds a style definition by name.
600 wxRichTextStyleDefinition
* FindStyle(const wxString
& name
) const;
603 Returns the @e nth character style.
605 wxRichTextCharacterStyleDefinition
* GetCharacterStyle(size_t n
) const;
608 Returns the number of character styles.
610 size_t GetCharacterStyleCount() const;
613 Returns the style sheet's description.
615 const wxString
& GetDescription() const;
618 Returns the @e nth list style.
620 wxRichTextListStyleDefinition
* GetListStyle(size_t n
) const;
623 Returns the number of list styles.
625 size_t GetListStyleCount() const;
628 Returns the style sheet's name.
630 const wxString
& GetName() const;
633 Returns the @e nth paragraph style.
635 wxRichTextParagraphStyleDefinition
* GetParagraphStyle(size_t n
) const;
638 Returns the number of paragraph styles.
640 size_t GetParagraphStyleCount() const;
643 Removes a character style.
645 bool RemoveCharacterStyle(wxRichTextStyleDefinition
* def
,
646 bool deleteStyle
= false);
649 Removes a list style.
651 bool RemoveListStyle(wxRichTextStyleDefinition
* def
,
652 bool deleteStyle
= false);
655 Removes a paragraph style.
657 bool RemoveParagraphStyle(wxRichTextStyleDefinition
* def
,
658 bool deleteStyle
= false);
663 bool RemoveStyle(wxRichTextStyleDefinition
* def
,
664 bool deleteStyle
= false);
667 Sets the style sheet's description.
669 void SetDescription(const wxString
& descr
);
672 Sets the style sheet's name.
674 void SetName(const wxString
& name
);