Fixed bugs in, and added operators and copy constructors to, style

sheet classes.
Now merges base, paragraph and content styles dynamically on
display or layout so that we can distinguish between them. This
means appling a paragraph style that has character formatting
doesn't wipe out the original content formatting. The old-style
static method can be enabled by setting wxRICHTEXT_USE_DYNAMIC_STYLES
to 0 in richtextbuffer.h.
The default style is initially empty, so that adding text
reflects the base and paragraph styles. Setting the default style
doesn't merge with the previous setting, but BeginStyle does.
Adding new paragraphs is now sensitive to the previous paragraph's
style and also whether its style has a next-paragraph style indication.
Added wxRichTextCtrl::ApplyStyleSheet which reapplies styles to
paragraphs with named styles.
Added style application command to sample to demonstrate how
styles can be changed and reapplied without affecting content
character formatting.
Fixed some range bugs in UI feedback and clipboard copying and pasting.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41501 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2006-09-29 08:53:23 +00:00
parent 81c330c6f0
commit fe5aa22c17
7 changed files with 765 additions and 129 deletions

View File

@@ -102,6 +102,10 @@
#include "wx/cmdproc.h"
#include "wx/txtstrm.h"
// Experimental dynamic styles to avoid user-specific character styles from being
// overwritten by paragraph styles.
#define wxRICHTEXT_USE_DYNAMIC_STYLES 1
/*!
* File types
*/
@@ -161,6 +165,13 @@ class WXDLLIMPEXP_RICHTEXT wxTextAttrEx;
#define wxRICHTEXT_FORMATTED 0x01
#define wxRICHTEXT_UNFORMATTED 0x02
/*!
* Flags for text insertion
*/
#define wxRICHTEXT_INSERT_NONE 0x00
#define wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE 0x01
/*!
* Extra formatting flags not in wxTextAttr
*/
@@ -378,6 +389,9 @@ public:
// Assignment from a wxTextAttrEx object.
void operator= (const wxTextAttrEx& attr);
// Equality test
bool operator== (const wxRichTextAttr& attr) const;
// Making a wxTextAttrEx object.
operator wxTextAttrEx () const ;
@@ -853,13 +867,13 @@ public:
virtual void Reset();
/// Convenience function to add a paragraph of text
virtual wxRichTextRange AddParagraph(const wxString& text);
virtual wxRichTextRange AddParagraph(const wxString& text, wxTextAttrEx* paraStyle = NULL);
/// Convenience function to add an image
virtual wxRichTextRange AddImage(const wxImage& image);
virtual wxRichTextRange AddImage(const wxImage& image, wxTextAttrEx* paraStyle = NULL);
/// Adds multiple paragraphs, based on newlines.
virtual wxRichTextRange AddParagraphs(const wxString& text);
virtual wxRichTextRange AddParagraphs(const wxString& text, wxTextAttrEx* paraStyle = NULL);
/// Get the line at the given position. If caretPosition is true, the position is
/// a caret position, which is normally a smaller number.
@@ -916,10 +930,18 @@ public:
virtual bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style, bool withUndo = true);
virtual bool SetStyle(const wxRichTextRange& range, const wxTextAttrEx& style, bool withUndo = true);
/// Get the text attributes for this position.
/// Get the conbined text attributes for this position.
virtual bool GetStyle(long position, wxTextAttrEx& style);
virtual bool GetStyle(long position, wxRichTextAttr& style);
/// Get the content (uncombined) attributes for this position.
virtual bool GetUncombinedStyle(long position, wxTextAttrEx& style);
virtual bool GetUncombinedStyle(long position, wxRichTextAttr& style);
/// Implementation helper for GetStyle. If combineStyles is true, combine base, paragraph and
/// context attributes.
virtual bool DoGetStyle(long position, wxTextAttrEx& style, bool combineStyles = true);
/// 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
@@ -945,6 +967,9 @@ public:
/// Make a copy of the fragment corresponding to the given range, putting it in 'fragment'.
virtual bool CopyFragment(const wxRichTextRange& range, wxRichTextFragment& fragment);
/// Apply the style sheet to the buffer, for example if the styles have changed.
virtual bool ApplyStyleSheet(wxRichTextStyleSheet* styleSheet);
/// Copy
void Copy(const wxRichTextParagraphLayoutBox& obj);
@@ -1161,7 +1186,7 @@ public:
// Implementation
/// Apply paragraph styles such as centering to the wrapped lines
virtual void ApplyParagraphStyle(const wxRect& rect);
virtual void ApplyParagraphStyle(const wxTextAttrEx& attr, const wxRect& rect);
/// Insert text at the given position
virtual bool InsertText(long pos, const wxString& text);
@@ -1196,6 +1221,13 @@ public:
/// Clear remaining unused line objects, if any
bool ClearUnusedLines(int lineCount);
/// Get combined attributes of the base style, paragraph style and character style. We use this to dynamically
/// retrieve the actual style.
wxTextAttrEx GetCombinedAttributes(const wxTextAttr& contentStyle) const;
/// Get combined attributes of the base style and paragraph style.
wxTextAttrEx GetCombinedAttributes() const;
protected:
/// The lines that make up the wrapped paragraph
wxRichTextLineList m_cachedLines;
@@ -1269,7 +1301,7 @@ public:
/// Clone
virtual wxRichTextObject* Clone() const { return new wxRichTextPlainText(*this); }
private:
bool DrawTabbedString(wxDC& dc,const wxRect& rect,wxString& str, wxCoord& x, wxCoord& y, bool selected);
bool DrawTabbedString(wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect, wxString& str, wxCoord& x, wxCoord& y, bool selected);
protected:
wxString m_text;
@@ -1623,13 +1655,13 @@ public:
virtual wxRichTextObject* Clone() const { return new wxRichTextBuffer(*this); }
/// Submit command to insert the given text
bool InsertTextWithUndo(long pos, const wxString& text, wxRichTextCtrl* ctrl);
bool InsertTextWithUndo(long pos, const wxString& text, wxRichTextCtrl* ctrl, int flags = 0);
/// Submit command to insert a newline
bool InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl);
bool InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int flags = 0);
/// Submit command to insert the given image
bool InsertImageWithUndo(long pos, const wxRichTextImageBlock& imageBlock, wxRichTextCtrl* ctrl);
bool InsertImageWithUndo(long pos, const wxRichTextImageBlock& imageBlock, wxRichTextCtrl* ctrl, int flags = 0);
/// Submit command to delete this range
bool DeleteRangeWithUndo(const wxRichTextRange& range, long initialCaretPosition, long newCaretPositon, wxRichTextCtrl* ctrl);
@@ -1638,6 +1670,11 @@ public:
void Modify(bool modify = true) { m_modified = modify; }
bool IsModified() const { return m_modified; }
/// Get the style that is appropriate for a new paragraph at this position.
/// If the previous paragraph has a paragraph style name, look up the next-paragraph
/// style.
wxRichTextAttr GetStyleForNewParagraph(long pos, bool caretPosition = false) const;
/// Dumps contents of buffer for debugging purposes
virtual void Dump();
virtual void Dump(wxTextOutputStream& stream) { wxRichTextParagraphLayoutBox::Dump(stream); }