X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7afd2b58c565ec9d9148c54745bb94613dbea4bf..50d4763f1710f6e45ac6af7112d1ce9effe93bc4:/interface/wx/richtext/richtextbuffer.h?ds=sidebyside diff --git a/interface/wx/richtext/richtextbuffer.h b/interface/wx/richtext/richtextbuffer.h index ba5b53a7db..0e4c5b2d3a 100644 --- a/interface/wx/richtext/richtextbuffer.h +++ b/interface/wx/richtext/richtextbuffer.h @@ -9,96 +9,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef _WX_RICHTEXTBUFFER_H_ -#define _WX_RICHTEXTBUFFER_H_ - -/* - - Data structures - =============== - - Data is represented by a hierarchy of objects, all derived from - wxRichTextObject. - - The top of the hierarchy is the buffer, a kind of wxRichTextParagraphLayoutBox. - These boxes will allow flexible placement of text boxes on a page, but - for now there is a single box representing the document, and this box is - a wxRichTextParagraphLayoutBox which contains further wxRichTextParagraph - objects, each of which can include text and images. - - Each object maintains a range (start and end position) measured - from the start of the main parent box. - A paragraph object knows its range, and a text fragment knows its range - too. So, a character or image in a page has a position relative to the - start of the document, and a character in an embedded text box has - a position relative to that text box. For now, we will not be dealing with - embedded objects but it's something to bear in mind for later. - - Note that internally, a range (5,5) represents a range of one character. - In the public wx[Rich]TextCtrl API, this would be passed to e.g. SetSelection - as (5,6). A paragraph with one character might have an internal range of (0, 1) - since the end of the paragraph takes up one position. - - Layout - ====== - - When Layout is called on an object, it is given a size which the object - must limit itself to, or one or more flexible directions (vertical - or horizontal). So for example a centered paragraph is given the page - width to play with (minus any margins), but can extend indefinitely - in the vertical direction. The implementation of Layout can then - cache the calculated size and position within the parent. - - */ - -/*! - * Includes - */ - -#include "wx/defs.h" - -#if wxUSE_RICHTEXT - -#include "wx/list.h" -#include "wx/textctrl.h" -#include "wx/bitmap.h" -#include "wx/image.h" -#include "wx/cmdproc.h" -#include "wx/txtstrm.h" -#include "wx/variant.h" - -#if wxUSE_DATAOBJ -#include "wx/dataobj.h" -#endif - -// Compatibility -//#define wxRichTextAttr wxTextAttr -#define wxTextAttrEx wxTextAttr - -// Setting wxRICHTEXT_USE_OWN_CARET to 1 implements a -// caret reliably without using wxClientDC in case there -// are platform-specific problems with the generic caret. -#if defined(__WXGTK__) || defined(__WXMAC__) -#define wxRICHTEXT_USE_OWN_CARET 1 -#else -#define wxRICHTEXT_USE_OWN_CARET 0 -#endif - -// Switch off for binary compatibility, on for faster drawing -// Note: this seems to be buggy (overzealous use of extents) so -// don't use for now -#define wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING 0 - -// The following two symbols determine whether an output implementation -// is present. To switch the relevant one on, set wxRICHTEXT_USE_XMLDOCUMENT_OUTPUT in -// richtextxml.cpp. By default, the faster direct output implementation is used. - -// Include the wxXmlDocument implementation for output -#define wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT 1 - -// Include the faster, direct implementation for output -#define wxRICHTEXT_HAVE_DIRECT_OUTPUT 1 - /** The line break character that can be embedded in content. */ @@ -118,31 +28,6 @@ enum wxRichTextFileType wxRICHTEXT_TYPE_PDF }; -/* - * Forward declarations - */ - -class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCtrl; -class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextObject; -class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextImage; -class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextCacheObject; -class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextObjectList; -class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextLine; -class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextParagraph; -class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextFileHandler; -class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextStyleSheet; -class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextListStyleDefinition; -class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextEvent; -class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextRenderer; -class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextBuffer; -class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextXMLHandler; -class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextParagraphLayoutBox; -class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextImageBlock; -class WXDLLIMPEXP_FWD_XML wxXmlNode; -class wxRichTextFloatCollector; -class WXDLLIMPEXP_FWD_BASE wxDataInputStream; -class WXDLLIMPEXP_FWD_BASE wxDataOutputStream; - /** Flags determining the available space, passed to Layout. */ @@ -241,6 +126,29 @@ enum wxRichTextHitTestFlags // Removes the given style instead of applying it #define wxRICHTEXT_SETSTYLE_REMOVE 0x80 +/** + Flags for SetProperties. + */ + +#define wxRICHTEXT_SETPROPERTIES_NONE 0x00 + +// Specifies that this operation should be undoable +#define wxRICHTEXT_SETPROPERTIES_WITH_UNDO 0x01 + +// Specifies that the properties should only be applied to paragraphs, +// and not the content. +#define wxRICHTEXT_SETPROPERTIES_PARAGRAPHS_ONLY 0x02 + +// Specifies that the properties should only be applied to characters, +// and not the paragraph. +#define wxRICHTEXT_SETPROPERTIES_CHARACTERS_ONLY 0x04 + +// Resets the existing properties before applying the new properties. +#define wxRICHTEXT_SETPROPERTIES_RESET 0x08 + +// Removes the given properties instead of applying them. +#define wxRICHTEXT_SETPROPERTIES_REMOVE 0x10 + /** Flags for object insertion. */ @@ -516,6 +424,12 @@ public: const wxTextAttrDimension& GetBottom() const { return m_bottom; } wxTextAttrDimension& GetBottom() { return m_bottom; } + /** + Are all dimensions valid? + + */ + bool IsValid() const { return m_left.IsValid() && m_top.IsValid() && m_right.IsValid() && m_bottom.IsValid(); } + wxTextAttrDimension m_left; wxTextAttrDimension m_top; wxTextAttrDimension m_right; @@ -581,10 +495,12 @@ public: Sets the width. */ void SetWidth(int value, wxTextAttrDimensionFlags flags) { m_width.SetValue(value, flags); } + /** Sets the width. */ void SetWidth(int value, wxTextAttrUnits units) { m_width.SetValue(value, units); } + /** Sets the width. */ @@ -600,15 +516,22 @@ public: Sets the height. */ void SetHeight(int value, wxTextAttrDimensionFlags flags) { m_height.SetValue(value, flags); } + /** Sets the height. */ void SetHeight(int value, wxTextAttrUnits units) { m_height.SetValue(value, units); } + /** Sets the height. */ void SetHeight(const wxTextAttrDimension& dim) { m_height.SetValue(dim); } + /** + Is the size valid? + */ + bool IsValid() const { return m_width.IsValid() && m_height.IsValid(); } + wxTextAttrDimension m_width; wxTextAttrDimension m_height; }; @@ -1315,11 +1238,35 @@ public: wxTextAttrSize& GetSize() { return m_size; } const wxTextAttrSize& GetSize() const { return m_size; } + /** + Returns the object minimum size. + */ + + wxTextAttrSize& GetMinSize() { return m_minSize; } + const wxTextAttrSize& GetMinSize() const { return m_minSize; } + + /** + Returns the object maximum size. + */ + + wxTextAttrSize& GetMaxSize() { return m_maxSize; } + const wxTextAttrSize& GetMaxSize() const { return m_maxSize; } + /** Sets the object size. */ void SetSize(const wxTextAttrSize& sz) { m_size = sz; } + /** + Sets the object minimum size. + */ + void SetMinSize(const wxTextAttrSize& sz) { m_minSize = sz; } + + /** + Sets the object maximum size. + */ + void SetMaxSize(const wxTextAttrSize& sz) { m_maxSize = sz; } + /** Returns the object width. */ @@ -1332,6 +1279,21 @@ public: wxTextAttrDimension& GetHeight() { return m_size.m_height; } const wxTextAttrDimension& GetHeight() const { return m_size.m_height; } + /** + Returns the box style name. + */ + const wxString& GetBoxStyleName() const { return m_boxStyleName; } + + /** + Sets the box style name. + */ + void SetBoxStyleName(const wxString& name) { m_boxStyleName = name; AddFlag(wxTEXT_BOX_ATTR_BOX_STYLE_NAME); } + + /** + Returns @true if the box style name is present. + */ + bool HasBoxStyleName() const { return HasFlag(wxTEXT_BOX_ATTR_BOX_STYLE_NAME); } + public: int m_flags; @@ -1341,6 +1303,8 @@ public: wxTextAttrDimensions m_position; wxTextAttrSize m_size; + wxTextAttrSize m_minSize; + wxTextAttrSize m_maxSize; wxTextAttrBorders m_border; wxTextAttrBorders m_outline; @@ -1349,6 +1313,7 @@ public: wxTextBoxAttrClearStyle m_clearMode; wxTextBoxAttrCollapseMode m_collapseMode; wxTextBoxAttrVerticalAlignment m_verticalAlignment; + wxString m_boxStyleName; }; /** @@ -1530,6 +1495,11 @@ public: */ int Find(const wxString& name) const; + /** + Removes the given property. + */ + bool Remove(const wxString& name); + /** Gets the property variant by name. */ @@ -1590,6 +1560,16 @@ public: */ void SetProperty(const wxString& name, bool value); + /** + Removes the given properties from these properties. + */ + void RemoveProperties(const wxRichTextProperties& properties); + + /** + Merges the given properties with these properties. + */ + void MergeProperties(const wxRichTextProperties& properties); + protected: wxRichTextVariantArray m_properties; }; @@ -1955,6 +1935,52 @@ public: wxRichTextParagraphLayoutBox* m_container; }; +/** + @class wxRichTextDrawingContext + + A class for passing information to drawing and measuring functions. + + @library{wxrichtext} + @category{richtext} + + @see wxRichTextBuffer, wxRichTextCtrl +*/ + +class WXDLLIMPEXP_RICHTEXT wxRichTextDrawingContext: public wxObject +{ + DECLARE_CLASS(wxRichTextDrawingContext) +public: + + /** + Pass the buffer to the context so the context can retrieve information + such as virtual attributes. + */ + wxRichTextDrawingContext(wxRichTextBuffer* buffer) { Init(); m_buffer = buffer; } + + void Init() { m_buffer = NULL; } + + /** + Does this object have virtual attributes? + Virtual attributes can be provided for visual cues without + affecting the actual styling. + */ + bool HasVirtualAttributes(wxRichTextObject* obj) const; + + /** + Returns the virtual attributes for this object. + Virtual attributes can be provided for visual cues without + affecting the actual styling. + */ + wxRichTextAttr GetVirtualAttributes(wxRichTextObject* obj) const; + + /** + Applies any virtual attributes relevant to this object. + */ + bool ApplyVirtualAttributes(wxRichTextAttr& attr, wxRichTextObject* obj) const; + + wxRichTextBuffer* m_buffer; +}; + /** @class wxRichTextObject @@ -1983,13 +2009,15 @@ public: Draw the item, within the given range. Some objects may ignore the range (for example paragraphs) while others must obey it (lines, to implement wrapping) */ - virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style) = 0; + virtual bool Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style) = 0; /** Lay the item out at the specified position with the given size constraint. - Layout must set the cached size. + Layout must set the cached size. @rect is the available space for the object, + and @a parentRect is the container that is used to determine a relative size + or position (for example if a text box must be 50% of the parent text box). */ - virtual bool Layout(wxDC& dc, const wxRect& rect, int style) = 0; + virtual bool Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style) = 0; /** Hit-testing: returns a flag indicating hit test details, plus @@ -2004,12 +2032,12 @@ public: @return One of the ::wxRichTextHitTestFlags values. */ - virtual int HitTest(wxDC& dc, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); + virtual int HitTest(wxDC& dc, wxRichTextDrawingContext& context, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); /** Finds the absolute position and row height for the given character position. */ - virtual bool FindPosition(wxDC& WXUNUSED(dc), long WXUNUSED(index), wxPoint& WXUNUSED(pt), int* WXUNUSED(height), bool WXUNUSED(forceLineStart)) { return false; } + virtual bool FindPosition(wxDC& WXUNUSED(dc), wxRichTextDrawingContext& WXUNUSED(context), long WXUNUSED(index), wxPoint& WXUNUSED(pt), int* WXUNUSED(height), bool WXUNUSED(forceLineStart)) { return false; } /** Returns the best size, i.e. the ideal starting size for this object irrespective @@ -2023,7 +2051,7 @@ public: is invalid for this object. */ - virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const = 0; + virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const = 0; /** Do a split from @a pos, returning an object containing the second part, and setting @@ -2319,14 +2347,19 @@ public: Calculates the available content space in the given rectangle, given the margins, border and padding specified in the object's attributes. */ - virtual wxRect GetAvailableContentArea(wxDC& dc, const wxRect& outerRect) const; + virtual wxRect GetAvailableContentArea(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& outerRect) const; /** Lays out the object first with a given amount of space, and then if no width was specified in attr, - lays out the object again using the minimum size + lays out the object again using the minimum size. @a availableParentSpace is the maximum space + for the object, whereas @a availableContainerSpace is the container with which relative positions and + sizes should be computed. For example, a text box whose space has already been constrained + in a previous layout pass to @a availableParentSpace, but should have a width of 50% of @a availableContainerSpace. + (If these two rects were the same, a 2nd pass could see the object getting too small.) */ - virtual bool LayoutToBestSize(wxDC& dc, wxRichTextBuffer* buffer, - const wxRichTextAttr& parentAttr, const wxRichTextAttr& attr, const wxRect& availableParentSpace, int style); + virtual bool LayoutToBestSize(wxDC& dc, wxRichTextDrawingContext& context, wxRichTextBuffer* buffer, + const wxRichTextAttr& parentAttr, const wxRichTextAttr& attr, + const wxRect& availableParentSpace, const wxRect& availableContainerSpace, int style); /** Sets the object's attributes. @@ -2477,8 +2510,11 @@ public: /** Returns the rectangle which the child has available to it given restrictions specified in the child attribute, e.g. 50% width of the parent, 400 pixels, x position 20% of the parent, etc. + availableContainerSpace might be a parent that the cell has to compute its width relative to. + E.g. a cell that's 50% of its parent. */ - static wxRect AdjustAvailableSpace(wxDC& dc, wxRichTextBuffer* buffer, const wxRichTextAttr& parentAttr, const wxRichTextAttr& childAttr, const wxRect& availableParentSpace); + static wxRect AdjustAvailableSpace(wxDC& dc, wxRichTextBuffer* buffer, const wxRichTextAttr& parentAttr, const wxRichTextAttr& childAttr, + const wxRect& availableParentSpace, const wxRect& availableContainerSpace); protected: wxSize m_size; @@ -2527,9 +2563,9 @@ public: // Overridables - virtual int HitTest(wxDC& dc, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); + virtual int HitTest(wxDC& dc, wxRichTextDrawingContext& context, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); - virtual bool FindPosition(wxDC& dc, long index, wxPoint& pt, int* height, bool forceLineStart); + virtual bool FindPosition(wxDC& dc, wxRichTextDrawingContext& context, long index, wxPoint& pt, int* height, bool forceLineStart); virtual void CalculateRange(long start, long& end); @@ -2537,7 +2573,7 @@ public: virtual wxString GetTextForRange(const wxRichTextRange& range) const; - virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; + virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; virtual void Dump(wxTextOutputStream& stream); @@ -2642,13 +2678,13 @@ public: // Overridables - virtual int HitTest(wxDC& dc, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); + virtual int HitTest(wxDC& dc, wxRichTextDrawingContext& context, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); - virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); + 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, const wxRect& rect, 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, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; + virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; virtual bool DeleteRange(const wxRichTextRange& range); @@ -2704,23 +2740,23 @@ public: /** Submits a command to insert paragraphs. */ - bool InsertParagraphsWithUndo(long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, wxRichTextBuffer* buffer, int flags = 0); + bool InsertParagraphsWithUndo(wxRichTextBuffer* buffer, long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, int flags = 0); /** Submits a command to insert the given text. */ - bool InsertTextWithUndo(long pos, const wxString& text, wxRichTextCtrl* ctrl, wxRichTextBuffer* buffer, int flags = 0); + bool InsertTextWithUndo(wxRichTextBuffer* buffer, long pos, const wxString& text, wxRichTextCtrl* ctrl, int flags = 0); /** Submits a command to insert the given text. */ - bool InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, wxRichTextBuffer* buffer, int flags = 0); + bool InsertNewlineWithUndo(wxRichTextBuffer* buffer, long pos, wxRichTextCtrl* ctrl, int flags = 0); /** Submits a command to insert the given image. */ - bool InsertImageWithUndo(long pos, const wxRichTextImageBlock& imageBlock, - wxRichTextCtrl* ctrl, wxRichTextBuffer* buffer, int flags, + bool InsertImageWithUndo(wxRichTextBuffer* buffer, long pos, const wxRichTextImageBlock& imageBlock, + wxRichTextCtrl* ctrl, int flags, const wxRichTextAttr& textAttr); /** @@ -2733,7 +2769,7 @@ public: /** Inserts an object. */ - wxRichTextObject* InsertObjectWithUndo(long pos, wxRichTextObject *object, wxRichTextCtrl* ctrl, wxRichTextBuffer* buffer, int flags = 0); + wxRichTextObject* InsertObjectWithUndo(wxRichTextBuffer* buffer, long pos, wxRichTextObject *object, wxRichTextCtrl* ctrl, int flags = 0); /** Submits a command to delete this range. @@ -2743,7 +2779,7 @@ public: /** Draws the floating objects in this buffer. */ - void DrawFloats(wxDC& dc, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); + void DrawFloats(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); /** Moves an anchored object to another paragraph. @@ -3035,6 +3071,28 @@ public: */ 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 @@ -3053,6 +3111,12 @@ public: 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 @@ -3213,7 +3277,7 @@ public: // Overridables - virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); + 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"); } @@ -3400,15 +3464,15 @@ public: // Overridables - virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); + 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, const wxRect& rect, 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, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; + virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; - virtual bool FindPosition(wxDC& dc, long index, wxPoint& pt, int* height, bool forceLineStart); + virtual bool FindPosition(wxDC& dc, wxRichTextDrawingContext& context, long index, wxPoint& pt, int* height, bool forceLineStart); - virtual int HitTest(wxDC& dc, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); + virtual int HitTest(wxDC& dc, wxRichTextDrawingContext& context, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); virtual void CalculateRange(long start, long& end); @@ -3473,7 +3537,7 @@ public: Finds a suitable wrap position. @a wrapPosition is the last position in the line to the left of the split. */ - bool FindWrapPosition(const wxRichTextRange& range, wxDC& dc, int availableSpace, long& wrapPosition, wxArrayInt* partialExtents); + bool FindWrapPosition(const wxRichTextRange& range, wxDC& dc, wxRichTextDrawingContext& context, int availableSpace, long& wrapPosition, wxArrayInt* partialExtents); /** Finds the object at the given position. @@ -3529,7 +3593,7 @@ public: /** Lays out the floating objects. */ - void LayoutFloat(wxDC& dc, const wxRect& rect, int style, wxRichTextFloatCollector* floatCollector); + void LayoutFloat(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, int style, wxRichTextFloatCollector* floatCollector); protected: @@ -3571,11 +3635,11 @@ public: // Overridables - virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); + 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, const wxRect& rect, 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, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; + virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; virtual wxString GetTextForRange(const wxRichTextRange& range) const; @@ -3847,11 +3911,11 @@ public: // Overridables - virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); + 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, const wxRect& rect, 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, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; + virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; /** Returns the 'natural' size for this object - the image size. @@ -4395,7 +4459,7 @@ public: // Implementation - virtual int HitTest(wxDC& dc, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); + virtual int HitTest(wxDC& dc, wxRichTextDrawingContext& context, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags = 0); /** Copies the buffer. @@ -4520,6 +4584,36 @@ public: */ static void InitStandardHandlers(); + /** + Returns the drawing handlers. + */ + static wxList& GetDrawingHandlers() { return sm_drawingHandlers; } + + /** + Adds a drawing handler to the end. + */ + static void AddDrawingHandler(wxRichTextDrawingHandler *handler); + + /** + Inserts a drawing handler at the front. + */ + static void InsertDrawingHandler(wxRichTextDrawingHandler *handler); + + /** + Removes a drawing handler. + */ + static bool RemoveDrawingHandler(const wxString& name); + + /** + Finds a drawing handler by name. + */ + static wxRichTextDrawingHandler *FindDrawingHandler(const wxString& name); + + /** + Clean up drawing handlers. + */ + static void CleanUpDrawingHandlers(); + /** Returns the renderer object. */ @@ -4603,6 +4697,9 @@ protected: /// File handlers static wxList sm_handlers; + /// Drawing handlers + static wxList sm_drawingHandlers; + /// Renderer static wxRichTextRenderer* sm_renderer; @@ -4642,7 +4739,7 @@ public: // Overridables - virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); + 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("cell"); } @@ -4693,13 +4790,13 @@ public: // Overridables - virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style); + 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("table"); } - virtual bool Layout(wxDC& dc, const wxRect& rect, 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, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; + virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, wxPoint position = wxPoint(0,0), wxArrayInt* partialExtents = NULL) const; virtual bool DeleteRange(const wxRichTextRange& range); @@ -4717,7 +4814,7 @@ public: virtual bool ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler); #endif - virtual bool FindPosition(wxDC& dc, long index, wxPoint& pt, int* height, bool forceLineStart); + virtual bool FindPosition(wxDC& dc, wxRichTextDrawingContext& context, long index, wxPoint& pt, int* height, bool forceLineStart); virtual void CalculateRange(long start, long& end); @@ -5381,6 +5478,54 @@ protected: }; +/** + @class wxRichTextDrawingHandler + + The base class for custom drawing handlers. + Currently, drawing handlers can provide virtual handlers. + + @library{wxrichtext} + @category{richtext} + + @see wxRichTextBuffer, wxRichTextCtrl +*/ + +class WXDLLIMPEXP_RICHTEXT wxRichTextDrawingHandler: public wxObject +{ + DECLARE_CLASS(wxRichTextDrawingHandler) +public: + /** + Creates a drawing handler object. + */ + wxRichTextDrawingHandler(const wxString& name = wxEmptyString) + : m_name(name) + { } + + /** + Returns @true if this object has virtual attributes that we can provide. + */ + virtual bool HasVirtualAttributes(wxRichTextObject* obj) const = 0; + + /** + Provides virtual attributes that we can provide. + */ + virtual bool GetVirtualAttributes(wxRichTextAttr& attr, wxRichTextObject* obj) const = 0; + + /** + Sets the name of the nandler. + */ + void SetName(const wxString& name) { m_name = name; } + + /** + Returns the name of the nandler. + */ + wxString GetName() const { return m_name; } + +protected: + + wxString m_name; +}; + #if wxUSE_DATAOBJ /** @@ -5553,10 +5698,3 @@ WXDLLIMPEXP_RICHTEXT wxString wxRichTextDecimalToRoman(long n); WXDLLIMPEXP_RICHTEXT void wxTextAttrCollectCommonAttributes(wxTextAttr& currentStyle, const wxTextAttr& attr, wxTextAttr& clashingAttr, wxTextAttr& absentAttr); WXDLLIMPEXP_RICHTEXT void wxRichTextModuleInit(); - -#endif - // wxUSE_RICHTEXT - -#endif - // _WX_RICHTEXTBUFFER_H_ -