+ /**
+ Given a line number, returns the corresponding wxRichTextLine object.
+ */
+ virtual wxRichTextLine* GetLineForVisibleLineNumber(long lineNumber) const;
+
+ /**
+ Returns the leaf object in a paragraph at this position.
+ */
+ virtual wxRichTextObject* GetLeafObjectAtPosition(long position) const;
+
+ /**
+ Returns the paragraph by number.
+ */
+ virtual wxRichTextParagraph* GetParagraphAtLine(long paragraphNumber) const;
+
+ /**
+ Returns the paragraph for a given line.
+ */
+ virtual wxRichTextParagraph* GetParagraphForLine(wxRichTextLine* line) const;
+
+ /**
+ Returns the length of the paragraph.
+ */
+ virtual int GetParagraphLength(long paragraphNumber) const;
+
+ /**
+ Returns the number of paragraphs.
+ */
+ virtual int GetParagraphCount() const { return static_cast<int>(GetChildCount()); }
+
+ /**
+ Returns the number of visible lines.
+ */
+ virtual int GetLineCount() const;
+
+ /**
+ Returns the text of the paragraph.
+ */
+ virtual wxString GetParagraphText(long paragraphNumber) const;
+
+ /**
+ Converts zero-based line column and paragraph number to a position.
+ */
+ virtual long XYToPosition(long x, long y) const;
+
+ /**
+ Converts a zero-based position to line column and paragraph number.
+ */
+ virtual bool PositionToXY(long pos, long* x, long* y) const;
+
+ /**
+ Sets the attributes for the given range. Pass flags to determine how the
+ attributes are set.
+
+ The end point of range is specified as the last character position of the span
+ of text. So, for example, to set the style for a character at position 5,
+ use the range (5,5).
+ This differs from the wxRichTextCtrl API, where you would specify (5,6).
+
+ @a flags may contain a bit list of the following values:
+ - wxRICHTEXT_SETSTYLE_NONE: no style flag.
+ - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this operation should be
+ undoable.
+ - wxRICHTEXT_SETSTYLE_OPTIMIZE: specifies that the style should not be applied
+ if the combined style at this point is already the style in question.
+ - wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY: specifies that the style should only be
+ applied to paragraphs, and not the content.
+ This allows content styling to be preserved independently from that
+ of e.g. a named paragraph style.
+ - wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY: specifies that the style should only be
+ applied to characters, and not the paragraph.
+ This allows content styling to be preserved independently from that
+ of e.g. a named paragraph style.
+ - wxRICHTEXT_SETSTYLE_RESET: resets (clears) the existing style before applying
+ the new style.
+ - wxRICHTEXT_SETSTYLE_REMOVE: removes the specified style.
+ Only the style flags are used in this operation.
+ */
+ virtual bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
+
+ /**
+ Sets the attributes for the given object only, for example the box attributes for a text box.
+ */
+ virtual void SetStyle(wxRichTextObject *obj, const wxRichTextAttr& textAttr, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
+
+ /**
+ Returns the combined text attributes for this position.
+
+ This function gets the @e uncombined style - that is, the attributes associated
+ with the paragraph or character content, and not necessarily the combined
+ attributes you see on the screen. To get the combined attributes, use GetStyle().
+ If you specify (any) paragraph attribute in @e style's flags, this function
+ will fetch the paragraph attributes.
+ Otherwise, it will return the character attributes.
+ */
+ virtual bool GetStyle(long position, wxRichTextAttr& style);
+
+ /**
+ Returns the content (uncombined) attributes for this position.
+ */
+ 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, wxRichTextAttr& style, bool combineStyles = true);
+
+ /**
+ This function gets a style representing the common, combined attributes in the
+ given range.
+ Attributes which have different values within the specified range will not be
+ included the style flags.
+
+ The function is used to get the attributes to display in the formatting dialog:
+ the user can edit the attributes common to the selection, and optionally specify the
+ values of further attributes to be applied uniformly.
+
+ To apply the edited attributes, you can use SetStyle() specifying
+ the wxRICHTEXT_SETSTYLE_OPTIMIZE flag, which will only apply attributes that
+ are different from the @e combined attributes within the range.
+ So, the user edits the effective, displayed attributes for the range,
+ but his choice won't be applied unnecessarily to content. As an example,
+ say the style for a paragraph specifies bold, but the paragraph text doesn't
+ specify a weight.
+ The combined style is bold, and this is what the user will see on-screen and
+ in the formatting dialog. The user now specifies red text, in addition to bold.
+ When applying with SetStyle(), the content font weight attributes won't be
+ changed to bold because this is already specified by the paragraph.
+ However the text colour attributes @e will be changed to show red.
+ */
+ virtual bool GetStyleForRange(const wxRichTextRange& range, wxRichTextAttr& style);
+
+ /**
+ Combines @a style with @a currentStyle for the purpose of summarising the attributes of a range of
+ content.
+ */
+ bool CollectStyle(wxRichTextAttr& currentStyle, const wxRichTextAttr& style, wxRichTextAttr& clashingAttr, wxRichTextAttr& absentAttr);
+
+ //@{
+ /**
+ Sets the list attributes for the given range, passing flags to determine how
+ the attributes are set.
+ Either the style definition or the name of the style definition (in the current
+ sheet) can be passed.
+
+ @a flags is a bit list of the following:
+ - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
+ - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
+ @a startFrom, otherwise existing attributes are used.
+ - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
+ as the level for all paragraphs, otherwise the current indentation will be used.
+
+ @see NumberList(), PromoteList(), ClearListStyle().
+ */
+ 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);
+ //@}
+
+ /**
+ Clears the list style from the given range, clearing list-related attributes
+ and applying any named paragraph style associated with each paragraph.
+
+ @a flags is a bit list of the following:
+ - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
+
+ @see SetListStyle(), PromoteList(), NumberList()
+ */
+ virtual bool ClearListStyle(const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO);
+
+ //@{
+ /**
+ Numbers the paragraphs in the given range.
+
+ Pass flags to determine how the attributes are set.
+ Either the style definition or the name of the style definition (in the current
+ sheet) can be passed.
+
+ @a flags is a bit list of the following:
+ - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
+ - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
+ @a startFrom, otherwise existing attributes are used.
+ - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
+ as the level for all paragraphs, otherwise the current indentation will be used.
+
+ @a def can be NULL to indicate that the existing list style should be used.
+
+ @see SetListStyle(), PromoteList(), ClearListStyle()
+ */
+ virtual bool NumberList(const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, 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);
+ //@}
+
+ //@{
+ /**
+ Promotes the list items within the given range.
+ A positive @a promoteBy produces a smaller indent, and a negative number
+ produces a larger indent. Pass flags to determine how the attributes are set.
+ Either the style definition or the name of the style definition (in the current
+ sheet) can be passed.
+
+ @a flags is a bit list of the following:
+ - wxRICHTEXT_SETSTYLE_WITH_UNDO: specifies that this command will be undoable.
+ - wxRICHTEXT_SETSTYLE_RENUMBER: specifies that numbering should start from
+ @a startFrom, otherwise existing attributes are used.
+ - wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL: specifies that @a listLevel should be used
+ as the level for all paragraphs, otherwise the current indentation will be used.
+
+ @see SetListStyle(), SetListStyle(), ClearListStyle()
+ */
+ virtual bool PromoteList(int promoteBy, const wxRichTextRange& range, wxRichTextListStyleDefinition* def = NULL, 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
+ @a def 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);
+
+ /**
+ Fills in the attributes for numbering a paragraph after previousParagraph.
+ */
+ virtual bool FindNextParagraphNumber(wxRichTextParagraph* previousParagraph, wxRichTextAttr& attr) const;
+
+ /**
+ Sets the properties for the given range, passing flags to determine how the
+ attributes are set. You can merge properties or replace them.
+
+ The end point of range is specified as the last character position of the span
+ of text, plus one. So, for example, to set the properties for a character at
+ position 5, use the range (5,6).
+
+ @a flags may contain a bit list of the following values:
+ - wxRICHTEXT_SETPROPERTIES_NONE: no flag.
+ - wxRICHTEXT_SETPROPERTIES_WITH_UNDO: specifies that this operation should be
+ undoable.
+ - wxRICHTEXT_SETPROPERTIES_PARAGRAPHS_ONLY: specifies that the properties should only be
+ applied to paragraphs, and not the content.
+ - wxRICHTEXT_SETPROPERTIES_CHARACTERS_ONLY: specifies that the properties should only be
+ applied to characters, and not the paragraph.
+ - wxRICHTEXT_SETPROPERTIES_RESET: resets (clears) the existing properties before applying
+ the new properties.
+ - wxRICHTEXT_SETPROPERTIES_REMOVE: removes the specified properties.
+ */
+ virtual bool SetProperties(const wxRichTextRange& range, const wxRichTextProperties& properties, int flags = wxRICHTEXT_SETPROPERTIES_WITH_UNDO);
+
+ /**
+ 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
+ flags indicating which attributes are of interest.
+ */
+ virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const;
+
+ /**
+ Test if this whole range has paragraph 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, centering button updating. style must have
+ flags indicating which attributes are of interest.
+ */
+ virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const;
+
+ virtual wxRichTextObject* Clone() const { return new wxRichTextParagraphLayoutBox(*this); }
+
+ /**
+ Prepares the content just before insertion (or after buffer reset).
+ Currently is only called if undo mode is on.
+ */
+ virtual void PrepareContent(wxRichTextParagraphLayoutBox& container);
+
+ /**
+ Insert fragment into this box at the given position. If partialParagraph is true,
+ it is assumed that the last (or only) paragraph is just a piece of data with no paragraph
+ marker.
+ */
+ virtual bool InsertFragment(long position, wxRichTextParagraphLayoutBox& fragment);
+
+ /**
+ Make a copy of the fragment corresponding to the given range, putting it in @a fragment.
+ */
+ virtual bool CopyFragment(const wxRichTextRange& range, wxRichTextParagraphLayoutBox& fragment);
+
+ /**
+ Apply the style sheet to the buffer, for example if the styles have changed.
+ */
+ virtual bool ApplyStyleSheet(wxRichTextStyleSheet* styleSheet);
+
+ void Copy(const wxRichTextParagraphLayoutBox& obj);
+
+ void operator= (const wxRichTextParagraphLayoutBox& obj) { Copy(obj); }
+
+ /**
+ Calculate ranges.
+ */
+ virtual void UpdateRanges();
+
+ /**
+ Get all the text.
+ */
+ virtual wxString GetText() const;
+
+ /**
+ Sets the default style, affecting the style currently being applied
+ (for example, setting the default style to bold will cause subsequently
+ inserted text to be bold).
+
+ This is not cumulative - setting the default style will replace the previous
+ default style.
+
+ Setting it to a default attribute object makes new content take on the 'basic' style.
+ */
+ virtual bool SetDefaultStyle(const wxRichTextAttr& style);
+
+ /**
+ Returns the current default style, affecting the style currently being applied
+ (for example, setting the default style to bold will cause subsequently
+ inserted text to be bold).
+ */
+ virtual const wxRichTextAttr& GetDefaultStyle() const { return m_defaultAttributes; }
+
+ /**
+ Sets the basic (overall) style. This is the style of the whole
+ buffer before further styles are applied, unlike the default style, which
+ only affects the style currently being applied (for example, setting the default
+ style to bold will cause subsequently inserted text to be bold).
+ */
+ virtual void SetBasicStyle(const wxRichTextAttr& style) { m_attributes = style; }
+
+ /**
+ Returns the basic (overall) style.
+
+ This is the style of the whole buffer before further styles are applied,
+ unlike the default style, which only affects the style currently being
+ applied (for example, setting the default style to bold will cause
+ subsequently inserted text to be bold).
+ */
+ virtual const wxRichTextAttr& GetBasicStyle() const { return m_attributes; }
+
+ /**
+ Invalidates the buffer. With no argument, invalidates whole buffer.
+ */
+ virtual void Invalidate(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL);
+
+ /**
+ Do the (in)validation for this object only.
+ */
+ virtual void DoInvalidate(const wxRichTextRange& invalidRange);
+
+ /**
+ Do the (in)validation both up and down the hierarchy.
+ */
+ virtual void InvalidateHierarchy(const wxRichTextRange& invalidRange = wxRICHTEXT_ALL);
+
+ /**
+ Gather information about floating objects. If untilObj is non-NULL,
+ will stop getting information if the current object is this, since we
+ will collect the rest later.
+ */
+ virtual bool UpdateFloatingObjects(const wxRect& availableRect, wxRichTextObject* untilObj = NULL);
+
+ /**
+ Get invalid range, rounding to entire paragraphs if argument is true.
+ */
+ wxRichTextRange GetInvalidRange(bool wholeParagraphs = false) const;
+
+ /**
+ Returns @true if this object needs layout.
+ */
+ bool IsDirty() const { return m_invalidRange != wxRICHTEXT_NONE; }
+
+ /**
+ Returns the wxRichTextFloatCollector of this object.
+ */
+ wxRichTextFloatCollector* GetFloatCollector() { return m_floatCollector; }
+
+ /**
+ Returns the number of floating objects at this level.
+ */
+ int GetFloatingObjectCount() const;
+
+ /**
+ Returns a list of floating objects.
+ */
+ bool GetFloatingObjects(wxRichTextObjectList& objects) const;
+
+protected:
+ wxRichTextCtrl* m_ctrl;
+ wxRichTextAttr m_defaultAttributes;
+
+ // The invalidated range that will need full layout
+ wxRichTextRange m_invalidRange;
+
+ // Is the last paragraph partial or complete?
+ bool m_partialParagraph;
+
+ // The floating layout state
+ wxRichTextFloatCollector* m_floatCollector;
+};
+
+/**
+ @class wxRichTextBox
+
+ This class implements a floating or inline text box, containing paragraphs.
+
+ @library{wxrichtext}
+ @category{richtext}
+
+ @see wxRichTextParagraphLayoutBox, wxRichTextObject, wxRichTextBuffer, wxRichTextCtrl
+*/
+
+class WXDLLIMPEXP_RICHTEXT wxRichTextBox: public wxRichTextParagraphLayoutBox
+{
+ DECLARE_DYNAMIC_CLASS(wxRichTextBox)
+public:
+// Constructors
+
+ /**
+ Default constructor; optionally pass the parent object.
+ */
+
+ wxRichTextBox(wxRichTextObject* parent = NULL);
+
+ /**
+ Copy constructor.
+ */
+
+ wxRichTextBox(const wxRichTextBox& obj): wxRichTextParagraphLayoutBox() { Copy(obj); }
+
+// Overridables
+
+ virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style);
+
+ virtual wxString GetXMLNodeName() const { return wxT("textbox"); }
+
+ virtual bool CanEditProperties() const { return true; }
+
+ virtual bool EditProperties(wxWindow* parent, wxRichTextBuffer* buffer);
+
+ virtual wxString GetPropertiesMenuLabel() const { return _("&Box"); }
+
+// Accessors
+
+// Operations
+
+ virtual wxRichTextObject* Clone() const { return new wxRichTextBox(*this); }
+
+ void Copy(const wxRichTextBox& obj);
+
+protected:
+};
+
+/**
+ @class wxRichTextField
+
+ This class implements the general concept of a field, an object that represents
+ additional functionality such as a footnote, a bookmark, a page number, a table
+ of contents, and so on. Extra information (such as a bookmark name) can be stored
+ in the object properties.
+
+ Drawing, layout, and property editing is delegated to classes derived
+ from wxRichTextFieldType, such as instances of wxRichTextFieldTypeStandard; this makes
+ the use of fields an efficient method of introducing extra functionality, since
+ most of the information required to draw a field (such as a bitmap) is kept centrally
+ in a single field type definition.
+
+ The FieldType property, accessed by SetFieldType/GetFieldType, is used to retrieve
+ the field type definition. So be careful not to overwrite this property.
+
+ wxRichTextField is derived from wxRichTextParagraphLayoutBox, which means that it
+ can contain its own read-only content, refreshed when the application calls the UpdateField
+ function. Whether a field is treated as a composite or a single graphic is determined
+ by the field type definition. If using wxRichTextFieldTypeStandard, passing the display
+ type wxRICHTEXT_FIELD_STYLE_COMPOSITE to the field type definition causes the field
+ to behave like a composite; the other display styles display a simple graphic.
+ When implementing a composite field, you will still need to derive from wxRichTextFieldTypeStandard
+ or wxRichTextFieldType, if only to implement UpdateField to refresh the field content
+ appropriately. wxRichTextFieldTypeStandard is only one possible implementation, but
+ covers common needs especially for simple, static fields using text or a bitmap.
+
+ Register field types on application initialisation with the static function
+ wxRichTextBuffer::AddFieldType. They will be deleted automatically on
+ application exit.
+
+ An application can write a field to a control with wxRichTextCtrl::WriteField,
+ taking a field type, the properties for the field, and optional attributes.
+
+ @library{wxrichtext}
+ @category{richtext}
+
+ @see wxRichTextFieldTypeStandard, wxRichTextFieldType, wxRichTextParagraphLayoutBox, wxRichTextProperties, wxRichTextCtrl
+*/
+
+class WXDLLIMPEXP_RICHTEXT wxRichTextField: public wxRichTextParagraphLayoutBox
+{
+ DECLARE_DYNAMIC_CLASS(wxRichTextField)
+public:
+// Constructors
+
+ /**
+ Default constructor; optionally pass the parent object.
+ */
+
+ wxRichTextField(const wxString& fieldType = wxEmptyString, wxRichTextObject* parent = NULL);
+
+ /**
+ Copy constructor.
+ */
+
+ wxRichTextField(const wxRichTextField& obj): wxRichTextParagraphLayoutBox() { Copy(obj); }
+
+// Overridables
+
+ virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style);
+
+ virtual bool Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style);
+
+ virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position = wxPoint(0,0), const wxSize& parentSize = wxDefaultSize, wxArrayInt* partialExtents = NULL) const;
+
+ virtual wxString GetXMLNodeName() const { return wxT("field"); }
+
+ virtual bool CanEditProperties() const;
+
+ virtual bool EditProperties(wxWindow* parent, wxRichTextBuffer* buffer);
+
+ virtual wxString GetPropertiesMenuLabel() const;
+
+ virtual bool AcceptsFocus() const { return false; }
+
+ virtual void CalculateRange(long start, long& end);
+
+ /**
+ If a field has children, we don't want the user to be able to edit it.
+ */
+ virtual bool IsAtomic() const { return true; }
+
+ virtual bool IsEmpty() const { return false; }
+
+ virtual bool IsTopLevel() const;
+
+// Accessors
+
+ void SetFieldType(const wxString& fieldType) { GetProperties().SetProperty(wxT("FieldType"), fieldType); }
+ wxString GetFieldType() const { return GetProperties().GetPropertyString(wxT("FieldType")); }
+
+// Operations
+
+ /**
+ Update the field; delegated to the associated field type. This would typically expand the field to its value,
+ if this is a dynamically changing and/or composite field.
+ */
+ virtual bool UpdateField(wxRichTextBuffer* buffer);
+
+ virtual wxRichTextObject* Clone() const { return new wxRichTextField(*this); }
+
+ void Copy(const wxRichTextField& obj);
+
+protected:
+};