1 /////////////////////////////////////////////////////////////////////////////
2 // Name: richtext/richtextstyles.h
3 // Purpose: interface of wxRichTextStyleListCtrl
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() 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. 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.
110 @class wxRichTextStyleDefinition
111 @headerfile richtextstyles.h wx/richtext/richtextstyles.h
113 This is a base class for paragraph and character styles.
118 class wxRichTextStyleDefinition
: public wxObject
124 wxRichTextStyleDefinition(const wxString
& name
= wxEmptyString
);
129 ~wxRichTextStyleDefinition();
132 Returns the style on which this style is based.
134 const wxString
GetBaseStyle() const;
137 Returns the style's description.
139 const wxString
GetDescription() const;
142 Returns the style name.
144 const wxString
GetName() const;
148 Returns the attributes associated with this style.
150 wxTextAttr
GetStyle() const;
151 const wxTextAttr
GetStyle() const;
155 Returns the style attributes combined with the attributes of the specified base
156 style, if any. This function works recursively.
158 wxTextAttr
GetStyleMergedWithBase(wxRichTextStyleSheet
* sheet
) const;
161 Sets the name of the style that this style is based on.
163 void SetBaseStyle(const wxString
& name
);
166 Sets the style description.
168 void SetDescription(const wxString
& descr
);
171 Sets the name of the style.
173 void SetName(const wxString
& name
);
176 Sets the attributes for this style.
178 void SetStyle(const wxTextAttr
& style
);
184 @class wxRichTextParagraphStyleDefinition
185 @headerfile richtextstyles.h wx/richtext/richtextstyles.h
187 This class represents a paragraph style definition, usually added to a
188 wxRichTextStyleSheet.
193 class wxRichTextParagraphStyleDefinition
: public wxRichTextStyleDefinition
199 wxRichTextParagraphStyleDefinition(const wxString
& name
= wxEmptyString
);
204 ~wxRichTextParagraphStyleDefinition();
207 Returns the style that should normally follow this style.
209 const wxString
GetNextStyle() const;
212 Sets the style that should normally follow this style.
214 void SetNextStyle(const wxString
& name
);
220 @class wxRichTextStyleListBox
221 @headerfile richtextstyles.h wx/richtext/richtextstyles.h
223 This is a listbox that can display the styles in a wxRichTextStyleSheet,
224 and apply the selection to an associated wxRichTextCtrl.
226 See @c samples/richtext for an example of how to use it.
231 @see wxRichTextStyleComboCtrl, @ref overview_wxrichtextctrloverview
232 "wxRichTextCtrl overview"
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 ~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
269 apply the style to the associated rich text control.
271 bool GetApplyOnSelection() const;
274 Returns the wxRichTextCtrl associated with this listbox.
276 wxRichTextCtrl
* GetRichTextCtrl() const;
279 Gets a style for a listbox index.
281 wxRichTextStyleDefinition
* GetStyle(size_t i
) const;
284 Returns the style sheet associated with this listbox.
286 wxRichTextStyleSheet
* GetStyleSheet() const;
289 Returns the type of style to show in the list box.
291 wxRichTextStyleListBox::wxRichTextStyleType
GetStyleType() const;
294 Returns the HTML for this item.
296 wxString
OnGetItem(size_t n
) const;
299 Implements left click behaviour, applying the clicked style to the
302 void OnLeftDown(wxMouseEvent
& event
);
307 void OnSelect(wxCommandEvent
& event
);
310 If @a applyOnSelection is @true, clicking on a style name in the list will
312 apply the style to the associated rich text control.
314 void SetApplyOnSelection(bool applyOnSelection
);
317 Associates the listbox with a wxRichTextCtrl.
319 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
);
322 Associates the control with a style sheet.
324 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
);
327 Sets the style type to display. One of
328 wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL, wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH,
329 wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER and
330 wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST.
332 void SetStyleType(wxRichTextStyleListBox::wxRichTextStyleType styleType
);
335 Updates the list from the associated style sheet.
343 @class wxRichTextStyleComboCtrl
344 @headerfile richtextstyles.h wx/richtext/richtextstyles.h
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_wxrichtextctrloverview
355 "wxRichTextCtrl overview"
357 class wxRichTextStyleComboCtrl
: public wxComboCtrl
363 wxRichTextStyleComboCtrl(wxWindow
* parent
,
364 wxWindowID id
= wxID_ANY
,
365 const wxPoint
& pos
= wxDefaultPosition
,
366 const wxSize
& size
= wxDefaultSize
,
372 ~wxRichTextStyleComboCtrl();
375 Returns the wxRichTextCtrl associated with this control.
377 wxRichTextCtrl
* GetRichTextCtrl() const;
380 Returns the style sheet associated with this control.
382 wxRichTextStyleSheet
* GetStyleSheet() const;
385 Associates the control with a wxRichTextCtrl.
387 void SetRichTextCtrl(wxRichTextCtrl
* ctrl
);
390 Associates the control with a style sheet.
392 void SetStyleSheet(wxRichTextStyleSheet
* styleSheet
);
395 Updates the combo control from the associated style sheet.
403 @class wxRichTextCharacterStyleDefinition
404 @headerfile richtextstyles.h wx/richtext/richtextstyles.h
406 This class represents a character style definition, usually added to a
407 wxRichTextStyleSheet.
412 class wxRichTextCharacterStyleDefinition
: public wxRichTextStyleDefinition
418 wxRichTextCharacterStyleDefinition(const wxString
& name
= wxEmptyString
);
423 ~wxRichTextCharacterStyleDefinition();
429 @class wxRichTextListStyleDefinition
430 @headerfile richtextstyles.h wx/richtext/richtextstyles.h
432 This class represents a list style definition, usually added to a
433 wxRichTextStyleSheet.
435 The class inherits paragraph attributes from
436 wxRichTextStyleParagraphDefinition, and adds 10 further attribute objects, one for each level of a list.
437 When applying a list style to a paragraph, the list style's base and
438 appropriate level attributes are merged with the
439 paragraph's existing attributes.
441 You can apply a list style to one or more paragraphs using
442 wxRichTextCtrl::SetListStyle. You
443 can also use the functions wxRichTextCtrl::NumberList,
444 wxRichTextCtrl::PromoteList and
445 wxRichTextCtrl::ClearListStyle. As usual, there are wxRichTextBuffer versions
447 so that you can apply them directly to a buffer without requiring a control.
452 class wxRichTextListStyleDefinition
: public wxRichTextParagraphStyleDefinition
458 wxRichTextListStyleDefinition(const wxString
& name
= wxEmptyString
);
463 ~wxRichTextListStyleDefinition();
466 This function combines the given paragraph style with the list style's base
467 attributes and level style matching the given indent, returning the combined attributes.
468 If @a styleSheet is specified, the base style for this definition will also be
469 included in the result.
471 wxTextAttr
CombineWithParagraphStyle(int indent
,
472 const wxTextAttr
& paraStyle
,
473 wxRichTextStyleSheet
* styleSheet
= NULL
);
476 This function finds the level (from 0 to 9) whose indentation attribute mostly
477 closely matches @a indent (expressed in tenths of a millimetre).
479 int FindLevelForIndent(int indent
) const;
482 This function combines the list style's base attributes and the level style
483 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 wxTextAttr
GetCombinedStyle(int indent
,
488 wxRichTextStyleSheet
* styleSheet
= NULL
) const;
491 This function combines the list style's base attributes and the style for the
492 specified level, returning the combined attributes.
493 If @a styleSheet is specified, the base style for this definition will also be
494 included in the result.
496 wxTextAttr
GetCombinedStyleLevel(int level
,
497 wxRichTextStyleSheet
* styleSheet
= NULL
) const;
500 Returns the style for the given level. @a level is a number between 0 and 9.
502 const wxTextAttr
* GetLevelAttributes(int level
) const;
505 Returns the number of levels. This is hard-wired to 10.
506 Returns the style for the given level. @e level is a number between 0 and 9.
508 int GetLevelCount() const;
511 Returns @true if the given level has numbered list attributes.
513 int IsNumbered(int level
) const;
517 Sets the style for the given level. @a level is a number between 0 and 9.
518 The first and most flexible form uses a wxTextAttr object, while the second
519 form is for convenient setting of the most commonly-used attributes.
521 void SetLevelAttributes(int level
, const wxTextAttr
& attr
);
522 void SetLevelAttributes(int level
, int leftIndent
,
525 const wxString
& bulletSymbol
= wxEmptyString
);
532 @class wxRichTextStyleSheet
533 @headerfile richtextstyles.h wx/richtext/richtextstyles.h
535 A style sheet contains named paragraph and character styles that make it
536 easy for a user to apply combinations of attributes to a wxRichTextCtrl.
538 You can use a wxRichTextStyleListBox in your
539 user interface to show available styles to the user, and allow application
540 of styles to the control.
545 class wxRichTextStyleSheet
: public wxObject
551 wxRichTextStyleSheet();
556 ~wxRichTextStyleSheet();
559 Adds a definition to the character style list.
561 bool AddCharacterStyle(wxRichTextCharacterStyleDefinition
* def
);
564 Adds a definition to the list style list.
566 bool AddListStyle(wxRichTextListStyleDefinition
* def
);
569 Adds a definition to the paragraph style list.
571 bool AddParagraphStyle(wxRichTextParagraphStyleDefinition
* def
);
574 Adds a definition to the appropriate style list.
576 bool AddStyle(wxRichTextStyleDefinition
* def
);
584 Finds a character definition by name.
586 wxRichTextCharacterStyleDefinition
* FindCharacterStyle(const wxString
& name
) const;
589 Finds a list definition by name.
591 wxRichTextListStyleDefinition
* FindListStyle(const wxString
& name
) const;
594 Finds a paragraph definition by name.
596 wxRichTextParagraphStyleDefinition
* FindParagraphStyle(const wxString
& name
) const;
599 Finds a style definition by name.
601 wxRichTextStyleDefinition
* FindStyle(const wxString
& name
) const;
604 Returns the @e nth character style.
606 wxRichTextCharacterStyleDefinition
* GetCharacterStyle(size_t n
) const;
609 Returns the number of character styles.
611 size_t GetCharacterStyleCount() const;
614 Returns the style sheet's description.
616 const wxString
GetDescription() const;
619 Returns the @e nth list style.
621 wxRichTextListStyleDefinition
* GetListStyle(size_t n
) const;
624 Returns the number of list styles.
626 size_t GetListStyleCount() const;
629 Returns the style sheet's name.
631 const wxString
GetName() const;
634 Returns the @e nth paragraph style.
636 wxRichTextParagraphStyleDefinition
* GetParagraphStyle(size_t n
) const;
639 Returns the number of paragraph styles.
641 size_t GetParagraphStyleCount() const;
644 Removes a character style.
646 bool RemoveCharacterStyle(wxRichTextStyleDefinition
* def
,
647 bool deleteStyle
= false);
650 Removes a list style.
652 bool RemoveListStyle(wxRichTextStyleDefinition
* def
,
653 bool deleteStyle
= false);
656 Removes a paragraph style.
658 bool RemoveParagraphStyle(wxRichTextStyleDefinition
* def
,
659 bool deleteStyle
= false);
664 bool RemoveStyle(wxRichTextStyleDefinition
* def
,
665 bool deleteStyle
= false);
668 Sets the style sheet's description.
670 void SetDescription(const wxString
& descr
);
673 Sets the style sheet's name.
675 void SetName(const wxString
& name
);