X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cdaed652d7d2b20bc9f508d45f77a280f88279d9..65034d07ed264018024570904f6ad18312339a3f:/include/wx/richtext/richtextctrl.h diff --git a/include/wx/richtext/richtextctrl.h b/include/wx/richtext/richtextctrl.h index abf7f449a9..6456ef94af 100644 --- a/include/wx/richtext/richtextctrl.h +++ b/include/wx/richtext/richtextctrl.h @@ -48,6 +48,13 @@ class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextStyleDefinition; #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 */ @@ -66,14 +73,17 @@ class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextStyleDefinition; // 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 @@ -81,12 +91,74 @@ class WXDLLIMPEXP_FWD_RICHTEXT wxRichTextStyleDefinition; #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 */ -class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl : public wxTextCtrlBase, +class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl : public wxControl, + public wxTextCtrlIface, public wxScrollHelper { DECLARE_CLASS( wxRichTextCtrl ) @@ -131,6 +203,11 @@ public: virtual void GetSelection(long* from, long* to) const; 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; } @@ -184,12 +261,21 @@ public: 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); @@ -223,27 +309,35 @@ public: // methods allow to apply the given text style to the given selection or to // set/get the style which will be used for all appended text virtual bool SetStyle(long start, long end, const wxTextAttr& style); + virtual bool SetStyle(long start, long end, const wxRichTextAttr& style); virtual bool SetStyle(const wxRichTextRange& range, const wxTextAttr& style); + 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 wxRichTextAnchoredObjectAttr& style); + // 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. - virtual bool SetStyleEx(const wxRichTextRange& range, const wxTextAttr& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); + virtual bool SetStyleEx(const wxRichTextRange& range, const wxRichTextAttr& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); /// Get the content (uncombined) attributes for this position. - virtual bool GetUncombinedStyle(long position, wxTextAttr& style); + 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 const wxTextAttr& GetDefaultStyleEx() const { return GetDefaultStyle(); } + virtual const wxRichTextAttr& GetDefaultStyleEx() const; - virtual const wxTextAttr& GetDefaultStyle() const; + //virtual const wxTextAttr& GetDefaultStyle() const; /// Set list style virtual bool SetListStyle(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); @@ -310,23 +404,41 @@ public: 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 /// for internal and file storage of the raw data. - virtual bool WriteImage(const wxImage& image, wxBitmapType bitmapType = wxBITMAP_TYPE_PNG, const wxRichTextAnchoredObjectAttr& attr = wxRichTextAnchoredObjectAttr()); + virtual bool WriteImage(const wxImage& image, wxBitmapType bitmapType = wxBITMAP_TYPE_PNG, + const wxRichTextAttr& textAttr = wxRichTextAttr()); /// Write a bitmap at the current insertion point. Supply optional type to use /// for internal and file storage of the raw data. - virtual bool WriteImage(const wxBitmap& bitmap, wxBitmapType bitmapType = wxBITMAP_TYPE_PNG, const wxRichTextAnchoredObjectAttr& attr = wxRichTextAnchoredObjectAttr()); + virtual bool WriteImage(const wxBitmap& bitmap, wxBitmapType bitmapType = wxBITMAP_TYPE_PNG, + const wxRichTextAttr& textAttr = wxRichTextAttr()); /// Load an image from file and write at the current insertion point. - virtual bool WriteImage(const wxString& filename, wxBitmapType bitmapType, const wxRichTextAnchoredObjectAttr& attr = wxRichTextAnchoredObjectAttr()); + virtual bool WriteImage(const wxString& filename, wxBitmapType bitmapType, + const wxRichTextAttr& textAttr = wxRichTextAttr()); /// Write an image block at the current insertion point. - virtual bool WriteImage(const wxRichTextImageBlock& imageBlock, const wxRichTextAnchoredObjectAttr& attr = wxRichTextAnchoredObjectAttr()); + 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(); @@ -335,12 +447,12 @@ public: virtual bool LineBreak(); /// Set basic (overall) style - virtual void SetBasicStyle(const wxTextAttr& style) { GetBuffer().SetBasicStyle(style); } + virtual void SetBasicStyle(const wxRichTextAttr& style) { GetBuffer().SetBasicStyle(style); } /// Get basic (overall) style - virtual const wxTextAttr& GetBasicStyle() const { return GetBuffer().GetBasicStyle(); } + virtual const wxRichTextAttr& GetBasicStyle() const { return GetBuffer().GetBasicStyle(); } - virtual bool BeginStyle(const wxTextAttr& style) { return GetBuffer().BeginStyle(style); } + virtual bool BeginStyle(const wxRichTextAttr& style) { return GetBuffer().BeginStyle(style); } /// End the style virtual bool EndStyle() { return GetBuffer().EndStyle(); } @@ -474,11 +586,12 @@ public: 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); @@ -491,7 +604,7 @@ public: 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); @@ -561,7 +674,7 @@ public: /// 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 wxTextAttr& style) const + virtual bool HasCharacterAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const { return GetBuffer().HasCharacterAttributes(range.ToInternal(), style); } @@ -570,7 +683,7 @@ public: /// 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 wxTextAttr& style) const + virtual bool HasParagraphAttributes(const wxRichTextRange& range, const wxRichTextAttr& style) const { return GetBuffer().HasParagraphAttributes(range.ToInternal(), style); } @@ -628,7 +741,7 @@ public: 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); @@ -637,7 +750,7 @@ public: 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 @@ -711,7 +824,7 @@ public: 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. @@ -721,7 +834,7 @@ public: 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. @@ -743,8 +856,9 @@ public: /// 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 @@ -791,7 +905,7 @@ public: /// Convenience function that tells the control to start reflecting the default /// style, since the user is changing it. - void SetAndShowDefaultStyle(const wxTextAttr& attr) + void SetAndShowDefaultStyle(const wxRichTextAttr& attr) { SetDefaultStyle(attr); SetCaretPositionForDefaultStyle(GetCaretPosition()); @@ -802,16 +916,32 @@ public: // 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); + + /// 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); - WX_FORWARD_TO_SCROLL_HELPER() + /// Font names take a long time to retrieve, so cache them (on demand) + static const wxArrayString& GetAvailableFontNames(); + static void ClearAvailableFontNames(); - // implement wxTextEntry methods - virtual wxString DoGetValue() const; + 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__ @@ -822,7 +952,6 @@ protected: virtual WXWidget GetTextWidget() const { return NULL; } #endif #ifdef __WXGTK20__ - virtual wxWindow *GetEditableWindow() { return this; } virtual GtkEditable *GetEditable() const { return NULL; } virtual GtkEntry *GetEntry() const { return NULL; } #endif @@ -860,12 +989,17 @@ private: 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; @@ -892,9 +1026,11 @@ private: 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; }; /*! @@ -907,14 +1043,14 @@ public: 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; } @@ -935,15 +1071,23 @@ public: 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) @@ -970,6 +1114,7 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_CONTENT_D 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&);