📄 richtextctrl.h
字号:
/////////////////////////////////////////////////////////////////////////////// Name: wx/richtext/richtextctrl.h// Purpose: A rich edit control// Author: Julian Smart// Modified by:// Created: 2005-09-30// RCS-ID: $Id: richtextctrl.h,v 1.39 2006/11/20 11:33:37 JS Exp $// Copyright: (c) Julian Smart// Licence: wxWindows licence/////////////////////////////////////////////////////////////////////////////#ifndef _WX_RICHTEXTCTRL_H_#define _WX_RICHTEXTCTRL_H_#include "wx/richtext/richtextbuffer.h"#if wxUSE_RICHTEXT#include "wx/scrolwin.h"#include "wx/caret.h"#include "wx/textctrl.h"#if !defined(__WXGTK__) && !defined(__WXMAC__)#define wxRICHTEXT_BUFFERED_PAINTING 1#else#define wxRICHTEXT_BUFFERED_PAINTING 0#endifclass WXDLLIMPEXP_RICHTEXT wxRichTextStyleDefinition;/*! * Styles and flags *//* Styles */#define wxRE_READONLY 0x0010#define wxRE_MULTILINE 0x0020/* Flags */#define wxRICHTEXT_SHIFT_DOWN 0x01#define wxRICHTEXT_CTRL_DOWN 0x02#define wxRICHTEXT_ALT_DOWN 0x04/* Defaults */#define wxRICHTEXT_DEFAULT_OVERALL_SIZE wxSize(-1, -1)#define wxRICHTEXT_DEFAULT_IMAGE_SIZE wxSize(80, 80)#define wxRICHTEXT_DEFAULT_SPACING 3#define wxRICHTEXT_DEFAULT_MARGIN 3#define wxRICHTEXT_DEFAULT_UNFOCUSSED_BACKGROUND wxColour(175, 175, 175)#define wxRICHTEXT_DEFAULT_FOCUSSED_BACKGROUND wxColour(140, 140, 140)#define wxRICHTEXT_DEFAULT_UNSELECTED_BACKGROUND wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)#define wxRICHTEXT_DEFAULT_TYPE_COLOUR wxColour(0, 0, 200)#define wxRICHTEXT_DEFAULT_FOCUS_RECT_COLOUR wxColour(100, 80, 80)#define wxRICHTEXT_DEFAULT_CARET_WIDTH 2// Minimum buffer size before delayed layout kicks in#define wxRICHTEXT_DEFAULT_DELAYED_LAYOUT_THRESHOLD 20000// Milliseconds before layout occurs after resize#define wxRICHTEXT_DEFAULT_LAYOUT_INTERVAL 50/*! * Forward declarations *//*! * wxRichTextItem class declaration */// Drawing styles/states#define wxRICHTEXT_SELECTED 0x01#define wxRICHTEXT_TAGGED 0x02// The control is focussed#define wxRICHTEXT_FOCUSSED 0x04// The item itself has the focus#define wxRICHTEXT_IS_FOCUS 0x08/*! * wxRichTextCtrl class declaration */class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl : public wxTextCtrlBase, public wxScrollHelper{ DECLARE_CLASS( wxRichTextCtrl ) DECLARE_EVENT_TABLE()public:// Constructors wxRichTextCtrl( ); wxRichTextCtrl( wxWindow* parent, wxWindowID id = -1, const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxRE_MULTILINE, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr); virtual ~wxRichTextCtrl( );// Operations /// Creation bool Create( wxWindow* parent, wxWindowID id = -1, const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxRE_MULTILINE, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr ); /// Member initialisation void Init();///// wxTextCtrl compatibility// Accessors virtual wxString GetValue() const; virtual wxString GetRange(long from, long to) const; virtual int GetLineLength(long lineNo) const ; virtual wxString GetLineText(long lineNo) const ; virtual int GetNumberOfLines() const ; virtual bool IsModified() const ; virtual bool IsEditable() const ; // more readable flag testing methods bool IsSingleLine() const { return !HasFlag(wxRE_MULTILINE); } bool IsMultiLine() const { return !IsSingleLine(); } // If the return values from and to are the same, there is no selection. virtual void GetSelection(long* from, long* to) const; virtual wxString GetStringSelection() const; /// Get filename wxString GetFilename() const { return m_filename; } /// Set filename void SetFilename(const wxString& filename) { m_filename = filename; } /// Set the threshold in character positions for doing layout optimization during sizing void SetDelayedLayoutThreshold(long threshold) { m_delayedLayoutThreshold = threshold; } /// Get the threshold in character positions for doing layout optimization during sizing long GetDelayedLayoutThreshold() const { return m_delayedLayoutThreshold; }// Operations // editing virtual void Clear(); virtual void Replace(long from, long to, const wxString& value); virtual void Remove(long from, long to); // load/save the controls contents from/to the file virtual bool DoLoadFile(const wxString& file, int fileType); virtual bool DoSaveFile(const wxString& file = wxEmptyString, int fileType = wxRICHTEXT_TYPE_ANY); /// Set the handler flags, controlling loading and saving void SetHandlerFlags(int flags) { GetBuffer().SetHandlerFlags(flags); } /// Get the handler flags, controlling loading and saving int GetHandlerFlags() const { return GetBuffer().GetHandlerFlags(); } // sets/clears the dirty flag virtual void MarkDirty(); virtual void DiscardEdits(); // set the max number of characters which may be entered in a single line // text control virtual void SetMaxLength(unsigned long WXUNUSED(len)) { } // writing text inserts it at the current position, appending always // inserts it at the end virtual void WriteText(const wxString& text); virtual void AppendText(const wxString& text); // text control under some platforms supports the text styles: these // 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 wxTextAttrEx& style); virtual bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style); virtual bool GetStyle(long position, wxTextAttr& style); virtual bool GetStyle(long position, wxTextAttrEx& style); virtual bool GetStyle(long position, wxRichTextAttr& style); // get the common set of styles for the range virtual bool GetStyleForRange(const wxRichTextRange& range, wxRichTextAttr& style); virtual bool GetStyleForRange(const wxRichTextRange& range, wxTextAttrEx& style); // 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(long start, long end, const wxTextAttrEx& style, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); virtual bool SetStyleEx(const wxRichTextRange& range, const wxTextAttrEx& 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, wxTextAttrEx& style); virtual bool GetUncombinedStyle(long position, wxRichTextAttr& style); virtual bool SetDefaultStyle(const wxTextAttrEx& style); virtual bool SetDefaultStyle(const wxTextAttr& style); // TODO: change to GetDefaultStyle if we merge wxTextAttr and wxTextAttrEx virtual const wxTextAttrEx& GetDefaultStyleEx() 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); virtual bool SetListStyle(const wxRichTextRange& range, const wxString& defName, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO, int startFrom = 1, int specifiedLevel = -1); /// Clear list for given range virtual bool ClearListStyle(const wxRichTextRange& range, int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO); /// Number/renumber any list elements in the given range /// def/defName can be NULL/empty to indicate that the existing list style should be used. 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); /// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1 /// def/defName can be NULL/empty to indicate that the existing list style should be used. 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); /// Deletes the content in the given range virtual bool Delete(const wxRichTextRange& range); // translate between the position (which is just an index in the text ctrl // considering all its contents as a single strings) and (x, y) coordinates // which represent column and line. virtual long XYToPosition(long x, long y) const; virtual bool PositionToXY(long pos, long *x, long *y) const; virtual void ShowPosition(long pos); // find the character at position given in pixels // // NB: pt is in device coords (not adjusted for the client area origin nor // scrolling) virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, long *pos) const; virtual wxTextCtrlHitTestResult HitTest(const wxPoint& pt, wxTextCoord *col, wxTextCoord *row) const; // Clipboard operations virtual void Copy(); virtual void Cut(); virtual void Paste(); virtual void DeleteSelection(); virtual bool CanCopy() const; virtual bool CanCut() const; virtual bool CanPaste() const; virtual bool CanDeleteSelection() const; // Undo/redo virtual void Undo(); virtual void Redo(); virtual bool CanUndo() const; virtual bool CanRedo() const; // Insertion point virtual void SetInsertionPoint(long pos); virtual void SetInsertionPointEnd(); virtual long GetInsertionPoint() const; virtual wxTextPos GetLastPosition() const; virtual void SetSelection(long from, long to); virtual void SelectAll(); virtual void SetEditable(bool editable); /// Call Freeze to prevent refresh virtual void Freeze(); /// Call Thaw to refresh virtual void Thaw(); /// Call Thaw to refresh virtual bool IsFrozen() const { return m_freezeCount > 0; } virtual bool HasSelection() 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, int bitmapType = wxBITMAP_TYPE_PNG); /// 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, int bitmapType = wxBITMAP_TYPE_PNG); /// Load an image from file and write at the current insertion point. virtual bool WriteImage(const wxString& filename, int bitmapType); /// Write an image block at the current insertion point. virtual bool WriteImage(const wxRichTextImageBlock& imageBlock); /// Insert a newline (actually paragraph) at the current insertion point. virtual bool Newline(); /// Insert a line break at the current insertion point. virtual bool LineBreak(); /// Set basic (overall) style virtual void SetBasicStyle(const wxTextAttrEx& style) { GetBuffer().SetBasicStyle(style); } virtual void SetBasicStyle(const wxRichTextAttr& style) { GetBuffer().SetBasicStyle(style); } /// Get basic (overall) style virtual const wxTextAttrEx& GetBasicStyle() const { return GetBuffer().GetBasicStyle(); } /// Begin using a style virtual bool BeginStyle(const wxTextAttrEx& style) { return GetBuffer().BeginStyle(style); } /// End the style
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -