Added list style to text attributes, independent from paragraph style
Added list style definition Added SetListStyle, ClearListStyle, NumberList, PromoteList to buffer and control classes Changed style listbox so double-click applies style instead of single click. This allows for multiple items to be applicable, and also in future to edit styles from this listbox without accidentally applying the style to content. Added wxRichTextStyleListCtrl which also shows a wxChoice for selecting the type of style to display. Style sheets can form a chain to allow inheritance from current style sheet (not yet supported by style list controls). Added PushStyleSheet/PopStyleSheet. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42075 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -98,6 +98,7 @@ class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph;
|
||||
class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler;
|
||||
class WXDLLIMPEXP_RICHTEXT wxRichTextStyleSheet;
|
||||
class WXDLLIMPEXP_RICHTEXT wxTextAttrEx;
|
||||
class WXDLLIMPEXP_RICHTEXT wxRichTextListStyleDefinition;
|
||||
|
||||
/*!
|
||||
* Flags determining the available space, passed to Layout
|
||||
@@ -133,7 +134,7 @@ class WXDLLIMPEXP_RICHTEXT wxTextAttrEx;
|
||||
#define wxRICHTEXT_UNFORMATTED 0x02
|
||||
|
||||
/*!
|
||||
* Flags for SetStyle
|
||||
* Flags for SetStyle/SetListStyle
|
||||
*/
|
||||
|
||||
#define wxRICHTEXT_SETSTYLE_NONE 0x00
|
||||
@@ -155,6 +156,14 @@ class WXDLLIMPEXP_RICHTEXT wxTextAttrEx;
|
||||
// preserved independently from that of e.g. a named paragraph style.
|
||||
#define wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY 0x08
|
||||
|
||||
// For SetListStyle only: specifies starting from the given number, otherwise
|
||||
// deduces number from existing attributes
|
||||
#define wxRICHTEXT_SETSTYLE_RENUMBER 0x10
|
||||
|
||||
// For SetListStyle only: specifies the list level for all paragraphs, otherwise
|
||||
// the current indentation will be used
|
||||
#define wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL 0x20
|
||||
|
||||
/*!
|
||||
* Flags for text insertion
|
||||
*/
|
||||
@@ -174,6 +183,7 @@ class WXDLLIMPEXP_RICHTEXT wxTextAttrEx;
|
||||
#define wxTEXT_ATTR_BULLET_STYLE 0x00010000
|
||||
#define wxTEXT_ATTR_BULLET_NUMBER 0x00020000
|
||||
#define wxTEXT_ATTR_BULLET_SYMBOL 0x00040000
|
||||
#define wxTEXT_ATTR_LIST_STYLE_NAME 0x00080000
|
||||
|
||||
/*!
|
||||
* Styles for wxTextAttrEx::SetBulletStyle
|
||||
@@ -274,18 +284,22 @@ public:
|
||||
wxTextAttrEx(const wxTextAttr& attr) { Init(); (*this) = attr; }
|
||||
wxTextAttrEx() { Init(); }
|
||||
|
||||
// Initialise this object.
|
||||
// Initialise this object
|
||||
void Init();
|
||||
|
||||
// Assignment from a wxTextAttrEx object
|
||||
void operator= (const wxTextAttrEx& attr);
|
||||
|
||||
// Assignment from a wxTextAttr object.
|
||||
// Assignment from a wxTextAttr object
|
||||
void operator= (const wxTextAttr& attr);
|
||||
|
||||
// Equality test
|
||||
bool operator== (const wxTextAttrEx& attr) const;
|
||||
|
||||
// setters
|
||||
void SetCharacterStyleName(const wxString& name) { m_characterStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_CHARACTER_STYLE_NAME); }
|
||||
void SetParagraphStyleName(const wxString& name) { m_paragraphStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_PARAGRAPH_STYLE_NAME); }
|
||||
void SetListStyleName(const wxString& name) { m_listStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_LIST_STYLE_NAME); }
|
||||
void SetParagraphSpacingAfter(int spacing) { m_paragraphSpacingAfter = spacing; SetFlags(GetFlags() | wxTEXT_ATTR_PARA_SPACING_AFTER); }
|
||||
void SetParagraphSpacingBefore(int spacing) { m_paragraphSpacingBefore = spacing; SetFlags(GetFlags() | wxTEXT_ATTR_PARA_SPACING_BEFORE); }
|
||||
void SetLineSpacing(int spacing) { m_lineSpacing = spacing; SetFlags(GetFlags() | wxTEXT_ATTR_LINE_SPACING); }
|
||||
@@ -296,6 +310,7 @@ public:
|
||||
|
||||
const wxString& GetCharacterStyleName() const { return m_characterStyleName; }
|
||||
const wxString& GetParagraphStyleName() const { return m_paragraphStyleName; }
|
||||
const wxString& GetListStyleName() const { return m_listStyleName; }
|
||||
int GetParagraphSpacingAfter() const { return m_paragraphSpacingAfter; }
|
||||
int GetParagraphSpacingBefore() const { return m_paragraphSpacingBefore; }
|
||||
int GetLineSpacing() const { return m_lineSpacing; }
|
||||
@@ -315,6 +330,7 @@ public:
|
||||
bool HasLineSpacing() const { return HasFlag(wxTEXT_ATTR_LINE_SPACING); }
|
||||
bool HasCharacterStyleName() const { return HasFlag(wxTEXT_ATTR_CHARACTER_STYLE_NAME) || !m_characterStyleName.IsEmpty(); }
|
||||
bool HasParagraphStyleName() const { return HasFlag(wxTEXT_ATTR_PARAGRAPH_STYLE_NAME) || !m_paragraphStyleName.IsEmpty(); }
|
||||
bool HasListStyleName() const { return HasFlag(wxTEXT_ATTR_LIST_STYLE_NAME) || !m_listStyleName.IsEmpty(); }
|
||||
bool HasBulletStyle() const { return HasFlag(wxTEXT_ATTR_BULLET_STYLE); }
|
||||
bool HasBulletNumber() const { return HasFlag(wxTEXT_ATTR_BULLET_NUMBER); }
|
||||
bool HasBulletSymbol() const { return HasFlag(wxTEXT_ATTR_BULLET_SYMBOL); }
|
||||
@@ -331,7 +347,8 @@ public:
|
||||
return !HasTextColour() && !HasBackgroundColour() && !HasFont() && !HasAlignment() &&
|
||||
!HasTabs() && !HasLeftIndent() && !HasRightIndent() &&
|
||||
!HasParagraphSpacingAfter() && !HasParagraphSpacingBefore() && !HasLineSpacing() &&
|
||||
!HasCharacterStyleName() && !HasParagraphStyleName() && !HasBulletNumber() && !HasBulletStyle() && !HasBulletSymbol();
|
||||
!HasCharacterStyleName() && !HasParagraphStyleName() && !HasListStyleName() &&
|
||||
!HasBulletNumber() && !HasBulletStyle() && !HasBulletSymbol();
|
||||
}
|
||||
|
||||
// return the attribute having the valid font and colours: it uses the
|
||||
@@ -356,6 +373,9 @@ private:
|
||||
|
||||
// Paragraph style
|
||||
wxString m_paragraphStyleName;
|
||||
|
||||
// List style
|
||||
wxString m_listStyleName;
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -415,6 +435,7 @@ public:
|
||||
|
||||
void SetCharacterStyleName(const wxString& name) { m_characterStyleName = name; m_flags |= wxTEXT_ATTR_CHARACTER_STYLE_NAME; }
|
||||
void SetParagraphStyleName(const wxString& name) { m_paragraphStyleName = name; m_flags |= wxTEXT_ATTR_PARAGRAPH_STYLE_NAME; }
|
||||
void SetListStyleName(const wxString& name) { m_listStyleName = name; SetFlags(GetFlags() | wxTEXT_ATTR_LIST_STYLE_NAME); }
|
||||
void SetParagraphSpacingAfter(int spacing) { m_paragraphSpacingAfter = spacing; m_flags |= wxTEXT_ATTR_PARA_SPACING_AFTER; }
|
||||
void SetParagraphSpacingBefore(int spacing) { m_paragraphSpacingBefore = spacing; m_flags |= wxTEXT_ATTR_PARA_SPACING_BEFORE; }
|
||||
void SetLineSpacing(int spacing) { m_lineSpacing = spacing; m_flags |= wxTEXT_ATTR_LINE_SPACING; }
|
||||
@@ -440,6 +461,7 @@ public:
|
||||
|
||||
const wxString& GetCharacterStyleName() const { return m_characterStyleName; }
|
||||
const wxString& GetParagraphStyleName() const { return m_paragraphStyleName; }
|
||||
const wxString& GetListStyleName() const { return m_listStyleName; }
|
||||
int GetParagraphSpacingAfter() const { return m_paragraphSpacingAfter; }
|
||||
int GetParagraphSpacingBefore() const { return m_paragraphSpacingBefore; }
|
||||
int GetLineSpacing() const { return m_lineSpacing; }
|
||||
@@ -467,6 +489,7 @@ public:
|
||||
bool HasLineSpacing() const { return (m_flags & wxTEXT_ATTR_LINE_SPACING) != 0; }
|
||||
bool HasCharacterStyleName() const { return (m_flags & wxTEXT_ATTR_CHARACTER_STYLE_NAME) != 0 || !m_characterStyleName.IsEmpty(); }
|
||||
bool HasParagraphStyleName() const { return (m_flags & wxTEXT_ATTR_PARAGRAPH_STYLE_NAME) != 0 || !m_paragraphStyleName.IsEmpty(); }
|
||||
bool HasListStyleName() const { return HasFlag(wxTEXT_ATTR_LIST_STYLE_NAME) || !m_listStyleName.IsEmpty(); }
|
||||
bool HasBulletStyle() const { return (m_flags & wxTEXT_ATTR_BULLET_STYLE) != 0; }
|
||||
bool HasBulletNumber() const { return (m_flags & wxTEXT_ATTR_BULLET_NUMBER) != 0; }
|
||||
bool HasBulletSymbol() const { return (m_flags & wxTEXT_ATTR_BULLET_SYMBOL) != 0; }
|
||||
@@ -485,7 +508,8 @@ public:
|
||||
return !HasTextColour() && !HasBackgroundColour() && !HasFont() && !HasAlignment() &&
|
||||
!HasTabs() && !HasLeftIndent() && !HasRightIndent() &&
|
||||
!HasParagraphSpacingAfter() && !HasParagraphSpacingBefore() && !HasLineSpacing() &&
|
||||
!HasCharacterStyleName() && !HasParagraphStyleName() && !HasBulletNumber() && !HasBulletStyle() && !HasBulletSymbol();
|
||||
!HasCharacterStyleName() && !HasParagraphStyleName() && !HasListStyleName() &&
|
||||
!HasBulletNumber() && !HasBulletStyle() && !HasBulletSymbol();
|
||||
}
|
||||
|
||||
// return the attribute having the valid font and colours: it uses the
|
||||
@@ -528,13 +552,16 @@ private:
|
||||
|
||||
// Paragraph style
|
||||
wxString m_paragraphStyleName;
|
||||
|
||||
// List style
|
||||
wxString m_listStyleName;
|
||||
};
|
||||
|
||||
#define wxTEXT_ATTR_CHARACTER (wxTEXT_ATTR_FONT | wxTEXT_ATTR_BACKGROUND_COLOUR | wxTEXT_ATTR_TEXT_COLOUR | wxTEXT_ATTR_CHARACTER_STYLE_NAME)
|
||||
|
||||
#define wxTEXT_ATTR_PARAGRAPH (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|\
|
||||
wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|wxTEXT_ATTR_LINE_SPACING|\
|
||||
wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER|wxTEXT_ATTR_BULLET_SYMBOL|wxTEXT_ATTR_PARAGRAPH_STYLE_NAME)
|
||||
wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER|wxTEXT_ATTR_BULLET_SYMBOL|wxTEXT_ATTR_PARAGRAPH_STYLE_NAME|wxTEXT_ATTR_LIST_STYLE_NAME)
|
||||
|
||||
#define wxTEXT_ATTR_ALL (wxTEXT_ATTR_CHARACTER|wxTEXT_ATTR_PARAGRAPH)
|
||||
|
||||
@@ -858,6 +885,10 @@ public:
|
||||
void SetPartialParagraph(bool partialPara) { m_partialParagraph = partialPara; }
|
||||
bool GetPartialParagraph() const { return m_partialParagraph; }
|
||||
|
||||
/// If this is a buffer, returns the current style sheet. The base layout box
|
||||
/// class doesn't have an associated style sheet.
|
||||
virtual wxRichTextStyleSheet* GetStyleSheet() const { return NULL; }
|
||||
|
||||
// Operations
|
||||
|
||||
/// Initialize the object.
|
||||
@@ -953,6 +984,27 @@ public:
|
||||
/// content.
|
||||
bool CollectStyle(wxTextAttrEx& currentStyle, const wxTextAttrEx& style, long& multipleStyleAttributes);
|
||||
|
||||
/// Set list style
|
||||
virtual bool SetListStyle(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
|
||||
virtual bool SetListStyle(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
|
||||
|
||||
/// Clear list for given range
|
||||
virtual bool ClearListStyle(const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
|
||||
|
||||
/// Number/renumber any list elements in the given range.
|
||||
/// def/defName can be NULL/empty to indicate that the existing list style should be used.
|
||||
virtual bool NumberList(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
|
||||
virtual bool NumberList(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
|
||||
|
||||
/// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1
|
||||
/// def/defName can be NULL/empty to indicate that the existing list style should be used.
|
||||
virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1);
|
||||
virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1);
|
||||
|
||||
/// Helper for NumberList and PromoteList, that does renumbering and promotion simultaneously
|
||||
/// def/defName can be NULL/empty to indicate that the existing list style should be used.
|
||||
virtual bool DoNumberList(const wxRichTextRange& range, const wxRichTextRange& promotionRange, int promoteBy, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
|
||||
|
||||
/// Test if this whole range has character attributes of the specified kind. If any
|
||||
/// of the attributes are different within the range, the test fails. You
|
||||
/// can use this to implement, for example, bold button updating. style must have
|
||||
@@ -1465,7 +1517,13 @@ public:
|
||||
|
||||
/// Set style sheet, if any.
|
||||
void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_styleSheet = styleSheet; }
|
||||
wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; }
|
||||
virtual wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; }
|
||||
|
||||
/// Push style sheet to top of stack
|
||||
bool PushStyleSheet(wxRichTextStyleSheet* styleSheet);
|
||||
|
||||
/// Pop style sheet from top of stack
|
||||
wxRichTextStyleSheet* PopStyleSheet();
|
||||
|
||||
// Operations
|
||||
|
||||
|
@@ -196,6 +196,23 @@ public:
|
||||
virtual const wxTextAttrEx& GetDefaultStyleEx() const;
|
||||
virtual const wxTextAttr& GetDefaultStyle() const;
|
||||
|
||||
/// Set list style
|
||||
virtual bool SetListStyle(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
|
||||
virtual bool SetListStyle(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
|
||||
|
||||
/// Clear list for given range
|
||||
virtual bool ClearListStyle(const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
|
||||
|
||||
/// Number/renumber any list elements in the given range
|
||||
/// def/defName can be NULL/empty to indicate that the existing list style should be used.
|
||||
virtual bool NumberList(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
|
||||
virtual bool NumberList(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1);
|
||||
|
||||
/// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1
|
||||
/// def/defName can be NULL/empty to indicate that the existing list style should be used.
|
||||
virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1);
|
||||
virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int specifiedLevel = -1);
|
||||
|
||||
// translate between the position (which is just an index in the text ctrl
|
||||
// considering all its contents as a single strings) and (x, y) coordinates
|
||||
// which represent column and line.
|
||||
@@ -530,10 +547,16 @@ public:
|
||||
/// Apply a named style to the selection
|
||||
virtual bool ApplyStyle(wxRichTextStyleDefinition* def);
|
||||
|
||||
/// Set style sheet, if any.
|
||||
/// Set style sheet, if any
|
||||
void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { GetBuffer().SetStyleSheet(styleSheet); }
|
||||
wxRichTextStyleSheet* GetStyleSheet() const { return GetBuffer().GetStyleSheet(); }
|
||||
|
||||
/// Push style sheet to top of stack
|
||||
bool PushStyleSheet(wxRichTextStyleSheet* styleSheet) { return GetBuffer().PushStyleSheet(styleSheet); }
|
||||
|
||||
/// Pop style sheet from top of stack
|
||||
wxRichTextStyleSheet* PopStyleSheet() { return GetBuffer().PopStyleSheet(); }
|
||||
|
||||
/// Apply the style sheet to the buffer, for example if the styles have changed.
|
||||
bool ApplyStyleSheet(wxRichTextStyleSheet* styleSheet = NULL);
|
||||
|
||||
|
@@ -30,6 +30,8 @@
|
||||
#include "wx/combo.h"
|
||||
#endif
|
||||
|
||||
#include "wx/choice.h"
|
||||
|
||||
/*!
|
||||
* Forward declarations
|
||||
*/
|
||||
@@ -47,32 +49,47 @@ class WXDLLIMPEXP_RICHTEXT wxRichTextStyleDefinition: public wxObject
|
||||
DECLARE_CLASS(wxRichTextStyleDefinition)
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
/// Copy constructors
|
||||
wxRichTextStyleDefinition(const wxRichTextStyleDefinition& def)
|
||||
: wxObject()
|
||||
{
|
||||
Init();
|
||||
Copy(def);
|
||||
}
|
||||
|
||||
/// Default constructor
|
||||
wxRichTextStyleDefinition(const wxString& name = wxEmptyString) { Init(); m_name = name; }
|
||||
|
||||
/// Destructor
|
||||
virtual ~wxRichTextStyleDefinition() {}
|
||||
|
||||
/// Initialises members
|
||||
void Init() {}
|
||||
|
||||
/// Copies from def
|
||||
void Copy(const wxRichTextStyleDefinition& def);
|
||||
|
||||
/// Equality test
|
||||
bool Eq(const wxRichTextStyleDefinition& def) const;
|
||||
|
||||
/// Assignment operator
|
||||
void operator =(const wxRichTextStyleDefinition& def) { Copy(def); }
|
||||
|
||||
/// Equality operator
|
||||
bool operator ==(const wxRichTextStyleDefinition& def) const { return Eq(def); }
|
||||
|
||||
/// Override to clone the object
|
||||
virtual wxRichTextStyleDefinition* Clone() const = 0;
|
||||
|
||||
/// The name of the style.
|
||||
/// Sets and gets the name of the style
|
||||
void SetName(const wxString& name) { m_name = name; }
|
||||
const wxString& GetName() const { return m_name; }
|
||||
|
||||
/// The name of the style that this style is based on.
|
||||
/// Sets and gets the name of the style that this style is based on
|
||||
void SetBaseStyle(const wxString& name) { m_baseStyle = name; }
|
||||
const wxString& GetBaseStyle() const { return m_baseStyle; }
|
||||
|
||||
/// The style.
|
||||
/// Sets the style
|
||||
void SetStyle(const wxRichTextAttr& style) { m_style = style; }
|
||||
const wxRichTextAttr& GetStyle() const { return m_style; }
|
||||
wxRichTextAttr& GetStyle() { return m_style; }
|
||||
@@ -92,13 +109,17 @@ class WXDLLIMPEXP_RICHTEXT wxRichTextCharacterStyleDefinition: public wxRichText
|
||||
DECLARE_DYNAMIC_CLASS(wxRichTextCharacterStyleDefinition)
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
/// Copy constructor
|
||||
wxRichTextCharacterStyleDefinition(const wxRichTextCharacterStyleDefinition& def): wxRichTextStyleDefinition(def) {}
|
||||
|
||||
/// Default constructor
|
||||
wxRichTextCharacterStyleDefinition(const wxString& name = wxEmptyString):
|
||||
wxRichTextStyleDefinition(name) {}
|
||||
|
||||
/// Destructor
|
||||
virtual ~wxRichTextCharacterStyleDefinition() {}
|
||||
|
||||
/// Clones the object
|
||||
virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextCharacterStyleDefinition(*this); }
|
||||
|
||||
protected:
|
||||
@@ -113,21 +134,30 @@ class WXDLLIMPEXP_RICHTEXT wxRichTextParagraphStyleDefinition: public wxRichText
|
||||
DECLARE_DYNAMIC_CLASS(wxRichTextParagraphStyleDefinition)
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
/// Copy constructor
|
||||
wxRichTextParagraphStyleDefinition(const wxRichTextParagraphStyleDefinition& def): wxRichTextStyleDefinition(def) { m_nextStyle = def.m_nextStyle; }
|
||||
|
||||
/// Default constructor
|
||||
wxRichTextParagraphStyleDefinition(const wxString& name = wxEmptyString):
|
||||
wxRichTextStyleDefinition(name) {}
|
||||
|
||||
// Destructor
|
||||
virtual ~wxRichTextParagraphStyleDefinition() {}
|
||||
|
||||
/// The next style.
|
||||
/// Sets and gets the next style
|
||||
void SetNextStyle(const wxString& name) { m_nextStyle = name; }
|
||||
const wxString& GetNextStyle() const { return m_nextStyle; }
|
||||
|
||||
/// Copies from def
|
||||
void Copy(const wxRichTextParagraphStyleDefinition& def);
|
||||
|
||||
/// Assignment operator
|
||||
void operator =(const wxRichTextParagraphStyleDefinition& def) { Copy(def); }
|
||||
|
||||
/// Equality operator
|
||||
bool operator ==(const wxRichTextParagraphStyleDefinition& def) const;
|
||||
|
||||
/// Clones the object
|
||||
virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextParagraphStyleDefinition(*this); }
|
||||
|
||||
protected:
|
||||
@@ -136,6 +166,72 @@ protected:
|
||||
wxString m_nextStyle;
|
||||
};
|
||||
|
||||
/*!
|
||||
* wxRichTextListStyleDefinition class declaration
|
||||
*/
|
||||
|
||||
class WXDLLIMPEXP_RICHTEXT wxRichTextListStyleDefinition: public wxRichTextParagraphStyleDefinition
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxRichTextListStyleDefinition)
|
||||
public:
|
||||
|
||||
/// Copy constructor
|
||||
wxRichTextListStyleDefinition(const wxRichTextListStyleDefinition& def): wxRichTextParagraphStyleDefinition(def) { Init(); Copy(def); }
|
||||
|
||||
/// Default constructor
|
||||
wxRichTextListStyleDefinition(const wxString& name = wxEmptyString):
|
||||
wxRichTextParagraphStyleDefinition(name) { Init(); }
|
||||
|
||||
/// Destructor
|
||||
virtual ~wxRichTextListStyleDefinition() {}
|
||||
|
||||
/// Copies from def
|
||||
void Copy(const wxRichTextListStyleDefinition& def);
|
||||
|
||||
/// Assignment operator
|
||||
void operator =(const wxRichTextListStyleDefinition& def) { Copy(def); }
|
||||
|
||||
/// Equality operator
|
||||
bool operator ==(const wxRichTextListStyleDefinition& def) const;
|
||||
|
||||
/// Clones the object
|
||||
virtual wxRichTextStyleDefinition* Clone() const { return new wxRichTextListStyleDefinition(*this); }
|
||||
|
||||
/// Sets/gets the attributes for the given level
|
||||
void SetLevelAttributes(int i, const wxTextAttrEx& attr);
|
||||
wxTextAttrEx* GetLevelAttributes(int i);
|
||||
const wxTextAttrEx* GetLevelAttributes(int i) const;
|
||||
|
||||
/// Convenience function for setting the major attributes for a list level specification
|
||||
void SetAttributes(int i, int leftIndent, int leftSubIndent, int bulletStyle, const wxString& bulletSymbol = wxEmptyString);
|
||||
|
||||
/// Finds the level corresponding to the given indentation
|
||||
int FindLevelForIndent(int indent) const;
|
||||
|
||||
/// Combine the base and list style with a paragraph style, using the given indent (from which
|
||||
/// an appropriate level is found)
|
||||
wxTextAttrEx CombineWithParagraphStyle(int indent, const wxTextAttrEx& paraStyle);
|
||||
|
||||
/// Combine the base and list style, using the given indent (from which
|
||||
/// an appropriate level is found)
|
||||
wxTextAttrEx GetCombinedStyle(int indent);
|
||||
|
||||
/// Combine the base and list style, using the given level from which
|
||||
/// an appropriate level is found)
|
||||
wxTextAttrEx GetCombinedStyleForLevel(int level);
|
||||
|
||||
/// Gets the number of available levels
|
||||
int GetLevelCount() const { return 10; }
|
||||
|
||||
/// Is this a numbered list?
|
||||
bool IsNumbered(int i) const;
|
||||
|
||||
protected:
|
||||
|
||||
/// The styles for each level (up to 10)
|
||||
wxTextAttrEx m_levelStyles[10];
|
||||
};
|
||||
|
||||
/*!
|
||||
* The style sheet
|
||||
*/
|
||||
@@ -152,7 +248,7 @@ public:
|
||||
Copy(sheet);
|
||||
}
|
||||
wxRichTextStyleSheet() { Init(); }
|
||||
virtual ~wxRichTextStyleSheet() { DeleteStyles(); }
|
||||
virtual ~wxRichTextStyleSheet();
|
||||
|
||||
/// Initialisation
|
||||
void Init();
|
||||
@@ -172,33 +268,65 @@ public:
|
||||
/// Add a definition to the paragraph style list
|
||||
bool AddParagraphStyle(wxRichTextParagraphStyleDefinition* def);
|
||||
|
||||
/// Add a definition to the list style list
|
||||
bool AddListStyle(wxRichTextListStyleDefinition* def);
|
||||
|
||||
/// Remove a character style
|
||||
bool RemoveCharacterStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_characterStyleDefinitions, def, deleteStyle); }
|
||||
|
||||
/// Remove a paragraph style
|
||||
bool RemoveParagraphStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_paragraphStyleDefinitions, def, deleteStyle); }
|
||||
|
||||
/// Remove a list style
|
||||
bool RemoveListStyle(wxRichTextStyleDefinition* def, bool deleteStyle = false) { return RemoveStyle(m_listStyleDefinitions, def, deleteStyle); }
|
||||
|
||||
/// Find a character definition by name
|
||||
wxRichTextCharacterStyleDefinition* FindCharacterStyle(const wxString& name) const { return (wxRichTextCharacterStyleDefinition*) FindStyle(m_characterStyleDefinitions, name); }
|
||||
wxRichTextCharacterStyleDefinition* FindCharacterStyle(const wxString& name, bool recurse = true) const { return (wxRichTextCharacterStyleDefinition*) FindStyle(m_characterStyleDefinitions, name, recurse); }
|
||||
|
||||
/// Find a paragraph definition by name
|
||||
wxRichTextParagraphStyleDefinition* FindParagraphStyle(const wxString& name) const { return (wxRichTextParagraphStyleDefinition*) FindStyle(m_paragraphStyleDefinitions, name); }
|
||||
wxRichTextParagraphStyleDefinition* FindParagraphStyle(const wxString& name, bool recurse = true) const { return (wxRichTextParagraphStyleDefinition*) FindStyle(m_paragraphStyleDefinitions, name, recurse); }
|
||||
|
||||
/// Return the number of character styes.
|
||||
/// Find a list definition by name
|
||||
wxRichTextListStyleDefinition* FindListStyle(const wxString& name, bool recurse = true) const { return (wxRichTextListStyleDefinition*) FindStyle(m_listStyleDefinitions, name, recurse); }
|
||||
|
||||
/// Return the number of character styles
|
||||
size_t GetCharacterStyleCount() const { return m_characterStyleDefinitions.GetCount(); }
|
||||
|
||||
/// Return the number of paragraph styes.
|
||||
/// Return the number of paragraph styles
|
||||
size_t GetParagraphStyleCount() const { return m_paragraphStyleDefinitions.GetCount(); }
|
||||
|
||||
/// Return the number of list styles
|
||||
size_t GetListStyleCount() const { return m_listStyleDefinitions.GetCount(); }
|
||||
|
||||
/// Return the nth character style
|
||||
wxRichTextCharacterStyleDefinition* GetCharacterStyle(size_t n) const { return (wxRichTextCharacterStyleDefinition*) m_characterStyleDefinitions.Item(n)->GetData(); }
|
||||
|
||||
/// Return the nth paragraph style
|
||||
wxRichTextParagraphStyleDefinition* GetParagraphStyle(size_t n) const { return (wxRichTextParagraphStyleDefinition*) m_paragraphStyleDefinitions.Item(n)->GetData(); }
|
||||
|
||||
/// Return the nth list style
|
||||
wxRichTextListStyleDefinition* GetListStyle(size_t n) const { return (wxRichTextListStyleDefinition*) m_listStyleDefinitions.Item(n)->GetData(); }
|
||||
|
||||
/// Delete all styles
|
||||
void DeleteStyles();
|
||||
|
||||
/// Insert into list of style sheets
|
||||
bool InsertSheet(wxRichTextStyleSheet* before);
|
||||
|
||||
/// Append to list of style sheets
|
||||
bool AppendSheet(wxRichTextStyleSheet* after);
|
||||
|
||||
/// Unlink from the list of style sheets
|
||||
void Unlink();
|
||||
|
||||
/// Get/set next sheet
|
||||
wxRichTextStyleSheet* GetNextSheet() const { return m_nextSheet; }
|
||||
void SetNextSheet(wxRichTextStyleSheet* sheet) { m_nextSheet = sheet; }
|
||||
|
||||
/// Get/set previous sheet
|
||||
wxRichTextStyleSheet* GetPreviousSheet() const { return m_previousSheet; }
|
||||
void SetPreviousSheet(wxRichTextStyleSheet* sheet) { m_previousSheet = sheet; }
|
||||
|
||||
/// Implementation
|
||||
|
||||
/// Add a definition to one of the style lists
|
||||
@@ -208,12 +336,16 @@ public:
|
||||
bool RemoveStyle(wxList& list, wxRichTextStyleDefinition* def, bool deleteStyle);
|
||||
|
||||
/// Find a definition by name
|
||||
wxRichTextStyleDefinition* FindStyle(const wxList& list, const wxString& name) const;
|
||||
wxRichTextStyleDefinition* FindStyle(const wxList& list, const wxString& name, bool recurse = true) const;
|
||||
|
||||
protected:
|
||||
|
||||
wxList m_characterStyleDefinitions;
|
||||
wxList m_paragraphStyleDefinitions;
|
||||
wxList m_listStyleDefinitions;
|
||||
|
||||
wxRichTextStyleSheet* m_previousSheet;
|
||||
wxRichTextStyleSheet* m_nextSheet;
|
||||
};
|
||||
|
||||
#if wxUSE_HTML
|
||||
@@ -228,6 +360,15 @@ class WXDLLIMPEXP_RICHTEXT wxRichTextStyleListBox: public wxHtmlListBox
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
||||
public:
|
||||
/// Which type of style definition is currently showing?
|
||||
enum wxRichTextStyleType
|
||||
{
|
||||
wxRICHTEXT_STYLE_ALL,
|
||||
wxRICHTEXT_STYLE_PARAGRAPH,
|
||||
wxRICHTEXT_STYLE_CHARACTER,
|
||||
wxRICHTEXT_STYLE_LIST
|
||||
};
|
||||
|
||||
wxRichTextStyleListBox()
|
||||
{
|
||||
Init();
|
||||
@@ -240,7 +381,8 @@ public:
|
||||
{
|
||||
m_styleSheet = NULL;
|
||||
m_richTextCtrl = NULL;
|
||||
m_applyOnSelection = true;
|
||||
m_applyOnSelection = false;
|
||||
m_styleType = wxRICHTEXT_STYLE_PARAGRAPH;
|
||||
}
|
||||
|
||||
bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
|
||||
@@ -278,14 +420,12 @@ public:
|
||||
/// Left click
|
||||
void OnLeftDown(wxMouseEvent& event);
|
||||
|
||||
/// Left double-click
|
||||
void OnLeftDoubleClick(wxMouseEvent& event);
|
||||
|
||||
/// Auto-select from style under caret in idle time
|
||||
void OnIdle(wxIdleEvent& event);
|
||||
|
||||
#if 0
|
||||
virtual wxColour GetSelectedTextColour(const wxColour& colFg) const;
|
||||
virtual wxColour GetSelectedTextBgColour(const wxColour& colBg) const;
|
||||
#endif
|
||||
|
||||
/// Convert units in tends of a millimetre to device units
|
||||
int ConvertTenthsMMToPixels(wxDC& dc, int units) const;
|
||||
|
||||
@@ -297,6 +437,13 @@ public:
|
||||
void SetApplyOnSelection(bool applyOnSel) { m_applyOnSelection = applyOnSel; }
|
||||
bool GetApplyOnSelection() const { return m_applyOnSelection; }
|
||||
|
||||
/// Set the style type to display
|
||||
void SetStyleType(wxRichTextStyleType styleType) { m_styleType = styleType; UpdateStyles(); }
|
||||
wxRichTextStyleType GetStyleType() const { return m_styleType; }
|
||||
|
||||
/// Helper for listbox and combo control
|
||||
static wxString GetStyleToShowInIdleTime(wxRichTextCtrl* ctrl, wxRichTextStyleType styleType);
|
||||
|
||||
protected:
|
||||
/// Returns the HTML for this item
|
||||
virtual wxString OnGetItem(size_t n) const;
|
||||
@@ -306,6 +453,84 @@ private:
|
||||
wxRichTextStyleSheet* m_styleSheet;
|
||||
wxRichTextCtrl* m_richTextCtrl;
|
||||
bool m_applyOnSelection; // if true, applies style on selection
|
||||
wxRichTextStyleType m_styleType; // style type to display
|
||||
};
|
||||
|
||||
/*!
|
||||
* wxRichTextStyleListCtrl class declaration
|
||||
* This is a container for the list control plus a combobox to switch between
|
||||
* style types.
|
||||
*/
|
||||
|
||||
class WXDLLIMPEXP_RICHTEXT wxRichTextStyleListCtrl: public wxControl
|
||||
{
|
||||
DECLARE_CLASS(wxRichTextStyleListCtrl)
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
||||
public:
|
||||
|
||||
/// Constructors
|
||||
wxRichTextStyleListCtrl()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
wxRichTextStyleListCtrl(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize, long style = 0);
|
||||
|
||||
/// Constructors
|
||||
virtual ~wxRichTextStyleListCtrl();
|
||||
|
||||
/// Member initialisation
|
||||
void Init()
|
||||
{
|
||||
m_styleListBox = NULL;
|
||||
m_styleChoice = NULL;
|
||||
m_dontUpdate = false;
|
||||
}
|
||||
|
||||
/// Creates the windows
|
||||
bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize, long style = 0);
|
||||
|
||||
/// Associates the control with a style manager
|
||||
void SetStyleSheet(wxRichTextStyleSheet* styleSheet);
|
||||
wxRichTextStyleSheet* GetStyleSheet() const;
|
||||
|
||||
/// Associates the control with a wxRichTextCtrl
|
||||
void SetRichTextCtrl(wxRichTextCtrl* ctrl);
|
||||
wxRichTextCtrl* GetRichTextCtrl() const;
|
||||
|
||||
/// Updates the style list box
|
||||
void UpdateStyles();
|
||||
|
||||
/// Set/get the style type to display
|
||||
void SetStyleType(wxRichTextStyleListBox::wxRichTextStyleType styleType);
|
||||
wxRichTextStyleListBox::wxRichTextStyleType GetStyleType() const;
|
||||
|
||||
/// Get the choice index for style type
|
||||
int StyleTypeToIndex(wxRichTextStyleListBox::wxRichTextStyleType styleType);
|
||||
|
||||
/// Get the style type for choice index
|
||||
wxRichTextStyleListBox::wxRichTextStyleType StyleIndexToType(int i);
|
||||
|
||||
/// Get the listbox
|
||||
wxRichTextStyleListBox* GetStyleListBox() const { return m_styleListBox; }
|
||||
|
||||
/// Get the choice
|
||||
wxChoice* GetStyleChoice() const { return m_styleChoice; }
|
||||
|
||||
/// React to style type choice
|
||||
void OnChooseType(wxCommandEvent& event);
|
||||
|
||||
/// Lay out the controls
|
||||
void OnSize(wxSizeEvent& event);
|
||||
|
||||
private:
|
||||
|
||||
wxRichTextStyleListBox* m_styleListBox;
|
||||
wxChoice* m_styleChoice;
|
||||
bool m_dontUpdate;
|
||||
};
|
||||
|
||||
#if wxUSE_COMBOCTRL
|
||||
|
Reference in New Issue
Block a user