#define wxRICHTEXT_CTRL_DOWN 0x02
#define wxRICHTEXT_ALT_DOWN 0x04
+/* Extra flags
+ */
+
+// Don't draw guide lines around boxes and tables
+#define wxRICHTEXT_EX_NO_GUIDELINES 0x00000100
+
+
/* Defaults
*/
// Milliseconds before layout occurs after resize
#define wxRICHTEXT_DEFAULT_LAYOUT_INTERVAL 50
-/*!
- * Forward declarations
+/* Identifiers
*/
+#define wxID_RICHTEXT_PROPERTIES1 (wxID_HIGHEST + 1)
+#define wxID_RICHTEXT_PROPERTIES2 (wxID_HIGHEST + 2)
+#define wxID_RICHTEXT_PROPERTIES3 (wxID_HIGHEST + 3)
/*!
- * wxRichTextItem class declaration
+ * Forward declarations
*/
+#if 0
// Drawing styles/states
#define wxRICHTEXT_SELECTED 0x01
#define wxRICHTEXT_TAGGED 0x02
#define wxRICHTEXT_FOCUSSED 0x04
// The item itself has the focus
#define wxRICHTEXT_IS_FOCUS 0x08
+#endif
+
+// Normal selection occurs initially and as user drags within one container.
+// Common ancestor selection occurs when the user starts dragging across containers
+// that have a common ancestor, for example the cells in a table.
+enum wxRichTextCtrlSelectionState
+{
+ wxRichTextCtrlSelectionState_Normal,
+ wxRichTextCtrlSelectionState_CommonAncestor
+};
+
+/*!
+ * wxRichTextContextMenuPropertiesInfo keeps track of objects that appear in the context menu,
+ * whose properties are available to be edited.
+ */
+
+class WXDLLIMPEXP_RICHTEXT wxRichTextContextMenuPropertiesInfo
+{
+public:
+ wxRichTextContextMenuPropertiesInfo() { Init(); }
+
+// Operations
+
+ /// Initialisation
+ void Init() {}
+
+ /// Add an item
+ bool AddItem(const wxString& label, wxRichTextObject* obj);
+
+ /// Returns number of menu items were added.
+ int AddMenuItems(wxMenu* menu, int startCmd = wxID_RICHTEXT_PROPERTIES1) const;
+
+ /// Add appropriate menu items for the current container and clicked on object
+ /// (and container's parent, if appropriate).
+ int AddItems(wxRichTextObject* container, wxRichTextObject* obj);
+
+ /// Clear the items
+ void Clear() { m_objects.Clear(); m_labels.Clear(); }
+
+// Accessors
+ /// Gets the nth label
+ wxString GetLabel(int n) const { return m_labels[n]; }
+
+ /// Gets the nth object
+ wxRichTextObject* GetObject(int n) const { return m_objects[n]; }
+
+ /// Get objects
+ wxRichTextObjectPtrArray& GetObjects() { return m_objects; }
+ const wxRichTextObjectPtrArray& GetObjects() const { return m_objects; }
+
+ /// Get labels
+ wxArrayString& GetLabels() { return m_labels; }
+ const wxArrayString& GetLabels() const { return m_labels; }
+
+ /// Get number of items
+ int GetCount() const { return m_objects.GetCount(); }
+
+ //wxArrayInt m_ids;
+ wxRichTextObjectPtrArray m_objects;
+ wxArrayString m_labels;
+};
/*!
* wxRichTextCtrl class declaration
virtual wxString GetStringSelection() const;
+ const wxRichTextSelection& GetSelection() const { return m_selection; }
+ wxRichTextSelection& GetSelection() { return m_selection; }
+ void SetSelection(const wxRichTextSelection& sel) { m_selection = sel; }
+
+
/// Get filename
wxString GetFilename() const { return m_filename; }
/// Get the threshold in character positions for doing layout optimization during sizing
long GetDelayedLayoutThreshold() const { return m_delayedLayoutThreshold; }
+ bool GetFullLayoutRequired() const { return m_fullLayoutRequired; }
+ void SetFullLayoutRequired(bool b) { m_fullLayoutRequired = b; }
+
+ wxLongLong GetFullLayoutTime() const { return m_fullLayoutTime; }
+ void SetFullLayoutTime(wxLongLong t) { m_fullLayoutTime = t; }
+
+ long GetFullLayoutSavedPosition() const { return m_fullLayoutSavedPosition; }
+ void SetFullLayoutSavedPosition(long p) { m_fullLayoutSavedPosition = p; }
+
+ // Force any pending layout due to large buffer
+ void ForceDelayedLayout();
+
/// Set text cursor
void SetTextCursor(const wxCursor& cursor ) { m_textCursor = cursor; }
long GetSelectionAnchor() const { return m_selectionAnchor; }
void SetSelectionAnchor(long anchor) { m_selectionAnchor = anchor; }
- /// The wxRichTextObject object under mouse if any
- wxRichTextObject* GetCurrentObject() const { return m_currentObject; }
- void SetCurrentObject(wxRichTextObject* obj) { m_currentObject = obj; }
+ /// Anchor object if selecting multiple containers.
+ wxRichTextObject* GetSelectionAnchorObject() const { return m_selectionAnchorObject; }
+ void SetSelectionAnchorObject(wxRichTextObject* anchor) { m_selectionAnchorObject = anchor; }
+
+ wxRichTextContextMenuPropertiesInfo& GetContextMenuPropertiesInfo() { return m_contextMenuPropertiesInfo; }
+ const wxRichTextContextMenuPropertiesInfo& GetContextMenuPropertiesInfo() const { return m_contextMenuPropertiesInfo; }
+
+ /// The wxRichTextObject object that currently has the editing focus
+ wxRichTextParagraphLayoutBox* GetFocusObject() const { return m_focusObject; }
+ bool SetFocusObject(wxRichTextParagraphLayoutBox* obj, bool setCaretPosition = true);
// Operations
+ void Invalidate() { GetBuffer().Invalidate(wxRICHTEXT_ALL); }
+
// editing
virtual void Clear();
virtual void Replace(long from, long to, const wxString& value);
virtual bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style);
virtual bool GetStyle(long position, wxTextAttr& style);
virtual bool GetStyle(long position, wxRichTextAttr& style);
+ virtual bool GetStyle(long position, wxRichTextAttr& style, wxRichTextParagraphLayoutBox* container);
- // Set an image style
- void SetImageStyle(wxRichTextImage *image, const wxRichTextAttr& textAttr);
+ // Set the style for a single object
+ virtual void SetStyle(wxRichTextObject *obj, const wxRichTextAttr& textAttr);
// get the common set of styles for the range
virtual bool GetStyleForRange(const wxRichTextRange& range, wxTextAttr& style);
virtual bool GetStyleForRange(const wxRichTextRange& range, wxRichTextAttr& style);
+ virtual bool GetStyleForRange(const wxRichTextRange& range, wxRichTextAttr& style, wxRichTextParagraphLayoutBox* container);
// extended style setting operation with flags including:
// wxRICHTEXT_SETSTYLE_WITH_UNDO, wxRICHTEXT_SETSTYLE_OPTIMIZE, wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY, wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY
// see richtextbuffer.h for more details.
/// Get the content (uncombined) attributes for this position.
virtual bool GetUncombinedStyle(long position, wxRichTextAttr& style);
+ virtual bool GetUncombinedStyle(long position, wxRichTextAttr& style, wxRichTextParagraphLayoutBox* container);
virtual bool SetDefaultStyle(const wxTextAttr& style);
virtual bool SetDefaultStyle(const wxRichTextAttr& style);
virtual void SelectAll();
virtual void SetEditable(bool editable);
+ /// Returns true if there was a selection and the object containing the selection
+ /// was the same as the current focus object.
virtual bool HasSelection() const;
+ /// Returns true if there was a selection, whether or not the current focus object
+ /// is the same as the selection's container object.
+ virtual bool HasUnfocusedSelection() const;
+
///// Functionality specific to wxRichTextCtrl
/// Write an image at the current insertion point. Supply optional type to use
virtual bool WriteImage(const wxRichTextImageBlock& imageBlock,
const wxRichTextAttr& textAttr = wxRichTextAttr());
+ /// Write a text box at the current insertion point, returning the text box.
+ /// You can then call SetFocusObject() to set the focus to the new object.
+ virtual wxRichTextBox* WriteTextBox(const wxRichTextAttr& textAttr = wxRichTextAttr());
+
+ /// Write a table at the current insertion point, returning the table.
+ /// You can then call SetFocusObject() to set the focus to the new object.
+ virtual wxRichTextTable* WriteTable(int rows, int cols, const wxRichTextAttr& tableAttr = wxRichTextAttr(), const wxRichTextAttr& cellAttr = wxRichTextAttr());
+
/// Insert a newline (actually paragraph) at the current insertion point.
virtual bool Newline();
wxRichTextRange GetSelectionRange() const;
void SetSelectionRange(const wxRichTextRange& range);
- /// Get/set the selection range in character positions. -1, -1 means no selection.
+ /// Get/set the selection range in character positions. -2, -2 means no selection
+ /// -1, -1 means select everything.
/// The range is in internal format, i.e. a single character selection is denoted
/// by (n, n)
- const wxRichTextRange& GetInternalSelectionRange() const { return m_selectionRange; }
- void SetInternalSelectionRange(const wxRichTextRange& range) { m_selectionRange = range; }
+ wxRichTextRange GetInternalSelectionRange() const { return m_selection.GetRange(); }
+ void SetInternalSelectionRange(const wxRichTextRange& range) { m_selection.Set(range, GetFocusObject()); }
/// Add a new paragraph of text to the end of the buffer
virtual wxRichTextRange AddParagraph(const wxString& text);
virtual bool LayoutContent(bool onlyVisibleRect = false);
/// Move the caret to the given character position
- virtual bool MoveCaret(long pos, bool showAtLineStart = false);
+ virtual bool MoveCaret(long pos, bool showAtLineStart = false, wxRichTextParagraphLayoutBox* container = NULL);
/// Move right
virtual bool MoveRight(int noPositions = 1, int flags = 0);
void OnUndo(wxCommandEvent& event);
void OnRedo(wxCommandEvent& event);
void OnSelectAll(wxCommandEvent& event);
- void OnImage(wxCommandEvent& event);
+ void OnProperties(wxCommandEvent& event);
void OnClear(wxCommandEvent& event);
void OnUpdateCut(wxUpdateUIEvent& event);
void OnUpdateUndo(wxUpdateUIEvent& event);
void OnUpdateRedo(wxUpdateUIEvent& event);
void OnUpdateSelectAll(wxUpdateUIEvent& event);
- void OnUpdateImage(wxUpdateUIEvent& event);
+ void OnUpdateProperties(wxUpdateUIEvent& event);
void OnUpdateClear(wxUpdateUIEvent& event);
// Show a context menu for Rich Edit controls (the standard
virtual bool ShouldInheritColours() const { return false; }
/// Position the caret
- virtual void PositionCaret();
+ virtual void PositionCaret(wxRichTextParagraphLayoutBox* container = NULL);
/// Extend the selection, returning true if the selection was
/// changed. Selections are in caret positions.
virtual bool ScrollIntoView(long position, int keyCode);
/// Refresh the area affected by a selection change
- bool RefreshForSelectionChange(const wxRichTextRange& oldSelection, const wxRichTextRange& newSelection);
+ bool RefreshForSelectionChange(const wxRichTextSelection& oldSelection, const wxRichTextSelection& newSelection);
/// The caret position is the character position just before the caret.
/// A value of -1 means the caret is at the start of the buffer.
/// to the start of the next, which may be the exact same caret position.
void MoveCaretBack(long oldPosition) ;
- /// Get the caret height and position for the given character position
- bool GetCaretPositionForIndex(long position, wxRect& rect);
+ /// Get the caret height and position for the given character position. If container is null,
+ /// the current focus object will be used.
+ bool GetCaretPositionForIndex(long position, wxRect& rect, wxRichTextParagraphLayoutBox* container = NULL);
/// Gets the line for the visible caret position. If the caret is
/// shown at the very end of the line, it means the next character is actually
// Implementation
- /// Font names take a long time to retrieve, so cache them (on demand)
- static const wxArrayString& GetAvailableFontNames();
- static void ClearAvailableFontNames();
+ /// Set up the caret for the given position and container, after a mouse click
+ bool SetCaretPositionAfterClick(wxRichTextParagraphLayoutBox* container, long position, int hitTestFlags, bool extendSelection = false);
- WX_FORWARD_TO_SCROLL_HELPER()
+ /// Find the caret position for the combination of hit-test flags and character position.
+ /// Returns the caret position and also an indication of where to place the caret (caretLineStart)
+ /// since this is ambiguous (same position used for end of line and start of next).
+ long FindCaretPositionForCharacterPosition(long position, int hitTestFlags, wxRichTextParagraphLayoutBox* container,
+ bool& caretLineStart);
- // implement wxTextEntry methods
- virtual wxString DoGetValue() const;
+ /// Font names take a long time to retrieve, so cache them (on demand)
+ static const wxArrayString& GetAvailableFontNames();
+ static void ClearAvailableFontNames();
+
+ WX_FORWARD_TO_SCROLL_HELPER()
+
+ // implement wxTextEntry methods
+ virtual wxString DoGetValue() const;
protected:
// implement the wxTextEntry pure virtual method
virtual wxWindow *GetEditableWindow() { return this; }
+ // margins functions
+ virtual bool DoSetMargins(const wxPoint& pt);
+ virtual wxPoint DoGetMargins() const;
+
// FIXME: this does not work, it allows this code to compile but will fail
// during run-time
#ifndef __WXUNIVERSAL__
long m_caretPositionForDefaultStyle;
/// Selection range in character positions. -2, -2 means no selection.
- wxRichTextRange m_selectionRange;
+ wxRichTextSelection m_selection;
+
+ wxRichTextCtrlSelectionState m_selectionState;
/// Anchor so we know how to extend the selection
/// It's a caret position since it's between two characters.
long m_selectionAnchor;
+ /// Anchor object if selecting multiple container objects, such as grid cells.
+ wxRichTextObject* m_selectionAnchorObject;
+
/// Are we editable?
bool m_editable;
wxCursor m_urlCursor;
static wxArrayString sm_availableFontNames;
- /// The wxRichTextObject object under mouse if any
- wxRichTextObject* m_currentObject;
- long m_imagePropertyId;
+
+ wxRichTextContextMenuPropertiesInfo m_contextMenuPropertiesInfo;
+
+ /// The object that currently has the editing focus
+ wxRichTextParagraphLayoutBox* m_focusObject;
};
/*!
wxRichTextEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
: wxNotifyEvent(commandType, winid),
m_flags(0), m_position(-1), m_oldStyleSheet(NULL), m_newStyleSheet(NULL),
- m_char((wxChar) 0)
+ m_char((wxChar) 0), m_container(NULL), m_oldContainer(NULL)
{ }
wxRichTextEvent(const wxRichTextEvent& event)
: wxNotifyEvent(event),
m_flags(event.m_flags), m_position(-1),
m_oldStyleSheet(event.m_oldStyleSheet), m_newStyleSheet(event.m_newStyleSheet),
- m_char((wxChar) 0)
+ m_char((wxChar) 0), m_container(event.m_container), m_oldContainer(event.m_oldContainer)
{ }
long GetPosition() const { return m_position; }
wxChar GetCharacter() const { return m_char; }
void SetCharacter(wxChar ch) { m_char = ch; }
+ wxRichTextParagraphLayoutBox* GetContainer() const { return m_container; }
+ void SetContainer(wxRichTextParagraphLayoutBox* container) { m_container = container; }
+
+ wxRichTextParagraphLayoutBox* GetOldContainer() const { return m_oldContainer; }
+ void SetOldContainer(wxRichTextParagraphLayoutBox* container) { m_oldContainer = container; }
+
virtual wxEvent *Clone() const { return new wxRichTextEvent(*this); }
protected:
- int m_flags;
- long m_position;
- wxRichTextStyleSheet* m_oldStyleSheet;
- wxRichTextStyleSheet* m_newStyleSheet;
- wxRichTextRange m_range;
- wxChar m_char;
+ int m_flags;
+ long m_position;
+ wxRichTextStyleSheet* m_oldStyleSheet;
+ wxRichTextStyleSheet* m_newStyleSheet;
+ wxRichTextRange m_range;
+ wxChar m_char;
+ wxRichTextParagraphLayoutBox* m_container;
+ wxRichTextParagraphLayoutBox* m_oldContainer;
private:
DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRichTextEvent)
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED, wxRichTextEvent );
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_SELECTION_CHANGED, wxRichTextEvent );
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_BUFFER_RESET, wxRichTextEvent );
+wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_FOCUS_OBJECT_CHANGED, wxRichTextEvent );
typedef void (wxEvtHandler::*wxRichTextEventFunction)(wxRichTextEvent&);