// 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.
*/
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.
*/
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;
};
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.
*/
wxTextAttrDimensions m_position;
wxTextAttrSize m_size;
+ wxTextAttrSize m_minSize;
+ wxTextAttrSize m_maxSize;
wxTextAttrBorders m_border;
wxTextAttrBorders m_outline;
*/
int Find(const wxString& name) const;
+ /**
+ Removes the given property.
+ */
+ bool Remove(const wxString& name);
+
/**
Gets the property variant by name.
*/
*/
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;
};
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
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.
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, const wxRect& parentRect, 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
@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
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
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,
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,
+ virtual bool LayoutToBestSize(wxDC& dc, wxRichTextDrawingContext& context, wxRichTextBuffer* buffer,
const wxRichTextAttr& parentAttr, const wxRichTextAttr& attr,
const wxRect& availableParentSpace, const wxRect& availableContainerSpace, int style);
// 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);
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);
// 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, const wxRect& parentRect, 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);
/**
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.
*/
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
// 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"); }
// 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, const wxRect& parentRect, 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);
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.
/**
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:
// 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, const wxRect& parentRect, 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;
// 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, const wxRect& parentRect, 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.
// 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.
*/
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.
*/
/// File handlers
static wxList sm_handlers;
+ /// Drawing handlers
+ static wxList sm_drawingHandlers;
+
/// Renderer
static wxRichTextRenderer* sm_renderer;
// 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"); }
// 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, const wxRect& parentRect, 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);
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);
};
+/**
+ @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
/**