📄 richtextbuffer.h
字号:
size_t m_dataSize;
int m_imageType; // wxWin type id
};
/*!
* wxRichTextImage class declaration
* This object represents an image.
*/
class WXDLLIMPEXP_RICHTEXT wxRichTextImage: public wxRichTextObject
{
DECLARE_DYNAMIC_CLASS(wxRichTextImage)
public:
// Constructors
wxRichTextImage(wxRichTextObject* parent = NULL):wxRichTextObject(parent) { }
wxRichTextImage(const wxImage& image, wxRichTextObject* parent = NULL);
wxRichTextImage(const wxRichTextImageBlock& imageBlock, wxRichTextObject* parent = NULL);
wxRichTextImage(const wxRichTextImage& obj):wxRichTextObject() { Copy(obj); }
// Overrideables
/// Draw the item
virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
/// Lay the item out
virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
/// Get the object size for the given range. Returns false if the range
/// is invalid for this object.
virtual bool GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position = wxPoint(0,0)) const;
/// Returns true if the object is empty
virtual bool IsEmpty() const { return !m_image.Ok(); }
// Accessors
/// Get the image
const wxImage& GetImage() const { return m_image; }
/// Set the image
void SetImage(const wxImage& image) { m_image = image; }
/// Get the image block containing the raw data
wxRichTextImageBlock& GetImageBlock() { return m_imageBlock; }
// Operations
/// Copy
void Copy(const wxRichTextImage& obj);
/// Clone
virtual wxRichTextObject* Clone() const { return new wxRichTextImage(*this); }
/// Load wxImage from the block
virtual bool LoadFromBlock();
/// Make block from the wxImage
virtual bool MakeBlock();
protected:
// TODO: reduce the multiple representations of data
wxImage m_image;
wxBitmap m_bitmap;
wxRichTextImageBlock m_imageBlock;
};
/*!
* wxRichTextBuffer class declaration
* This is a kind of box, used to represent the whole buffer
*/
class WXDLLIMPEXP_RICHTEXT wxRichTextCommand;
class WXDLLIMPEXP_RICHTEXT wxRichTextAction;
class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer: public wxRichTextParagraphLayoutBox
{
DECLARE_DYNAMIC_CLASS(wxRichTextBuffer)
public:
// Constructors
wxRichTextBuffer() { Init(); }
wxRichTextBuffer(const wxRichTextBuffer& obj):wxRichTextParagraphLayoutBox() { Init(); Copy(obj); }
~wxRichTextBuffer() ;
// Accessors
/// Gets the command processor
wxCommandProcessor* GetCommandProcessor() const { return m_commandProcessor; }
/// Set style sheet, if any.
void SetStyleSheet(wxRichTextStyleSheet* styleSheet) { m_styleSheet = styleSheet; }
wxRichTextStyleSheet* GetStyleSheet() const { return m_styleSheet; }
// Operations
/// Initialisation
void Init();
/// Clears the buffer and resets the command processor
virtual void Clear();
/// The same as Clear, and adds an empty paragraph.
virtual void Reset();
/// Load a file
virtual bool LoadFile(const wxString& filename, int type = wxRICHTEXT_TYPE_ANY);
/// Save a file
virtual bool SaveFile(const wxString& filename, int type = wxRICHTEXT_TYPE_ANY);
/// Load from a stream
virtual bool LoadFile(wxInputStream& stream, int type = wxRICHTEXT_TYPE_ANY);
/// Save to a stream
virtual bool SaveFile(wxOutputStream& stream, int type = wxRICHTEXT_TYPE_ANY);
/// Convenience function to add a paragraph of text
virtual wxRichTextRange AddParagraph(const wxString& text) { Modify(); return wxRichTextParagraphLayoutBox::AddParagraph(text); }
/// Begin collapsing undo/redo commands. Note that this may not work properly
/// if combining commands that delete or insert content, changing ranges for
/// subsequent actions.
virtual bool BeginBatchUndo(const wxString& cmdName);
/// End collapsing undo/redo commands
virtual bool EndBatchUndo();
/// Collapsing commands?
virtual bool BatchingUndo() const { return m_batchedCommandDepth > 0; }
/// Submit immediately, or delay according to whether collapsing is on
virtual bool SubmitAction(wxRichTextAction* action);
/// Get collapsed command
virtual wxRichTextCommand* GetBatchedCommand() const { return m_batchedCommand; }
/// Begin suppressing undo/redo commands. The way undo is suppressed may be implemented
/// differently by each command. If not dealt with by a command implementation, then
/// it will be implemented automatically by not storing the command in the undo history
/// when the action is submitted to the command processor.
virtual bool BeginSuppressUndo();
/// End suppressing undo/redo commands.
virtual bool EndSuppressUndo();
/// Collapsing commands?
virtual bool SuppressingUndo() const { return m_suppressUndo > 0; }
/// Copy the range to the clipboard
virtual bool CopyToClipboard(const wxRichTextRange& range);
/// Paste the clipboard content to the buffer
virtual bool PasteFromClipboard(long position);
/// Can we paste from the clipboard?
virtual bool CanPasteFromClipboard() const;
/// Begin using a style
virtual bool BeginStyle(const wxTextAttrEx& style);
/// End the style
virtual bool EndStyle();
/// End all styles
virtual bool EndAllStyles();
/// Clear the style stack
virtual void ClearStyleStack();
/// Get the size of the style stack, for example to check correct nesting
virtual size_t GetStyleStackSize() const { return m_attributeStack.GetCount(); }
/// Begin using bold
bool BeginBold();
/// End using bold
bool EndBold() { return EndStyle(); }
/// Begin using italic
bool BeginItalic();
/// End using italic
bool EndItalic() { return EndStyle(); }
/// Begin using underline
bool BeginUnderline();
/// End using underline
bool EndUnderline() { return EndStyle(); }
/// Begin using point size
bool BeginFontSize(int pointSize);
/// End using point size
bool EndFontSize() { return EndStyle(); }
/// Begin using this font
bool BeginFont(const wxFont& font);
/// End using a font
bool EndFont() { return EndStyle(); }
/// Begin using this colour
bool BeginTextColour(const wxColour& colour);
/// End using a colour
bool EndTextColour() { return EndStyle(); }
/// Begin using alignment
bool BeginAlignment(wxTextAttrAlignment alignment);
/// End alignment
bool EndAlignment() { return EndStyle(); }
/// Begin left indent
bool BeginLeftIndent(int leftIndent, int leftSubIndent = 0);
/// End left indent
bool EndLeftIndent() { return EndStyle(); }
/// Begin right indent
bool BeginRightIndent(int rightIndent);
/// End right indent
bool EndRightIndent() { return EndStyle(); }
/// Begin paragraph spacing
bool BeginParagraphSpacing(int before, int after);
/// End paragraph spacing
bool EndParagraphSpacing() { return EndStyle(); }
/// Begin line spacing
bool BeginLineSpacing(int lineSpacing);
/// End line spacing
bool EndLineSpacing() { return EndStyle(); }
/// Begin numbered bullet
bool BeginNumberedBullet(int bulletNumber, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD);
/// End numbered bullet
bool EndNumberedBullet() { return EndStyle(); }
/// Begin symbol bullet
bool BeginSymbolBullet(wxChar symbol, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL);
/// End symbol bullet
bool EndSymbolBullet() { return EndStyle(); }
/// Begin named character style
bool BeginCharacterStyle(const wxString& characterStyle);
/// End named character style
bool EndCharacterStyle() { return EndStyle(); }
/// Begin named paragraph style
bool BeginParagraphStyle(const wxString& paragraphStyle);
/// End named character style
bool EndParagraphStyle() { return EndStyle(); }
// Implementation
/// Copy
void Copy(const wxRichTextBuffer& obj) { wxRichTextBox::Copy(obj); }
/// Clone
virtual wxRichTextObject* Clone() const { return new wxRichTextBuffer(*this); }
/// Submit command to insert the given text
bool InsertTextWithUndo(long pos, const wxString& text, wxRichTextCtrl* ctrl);
/// Submit command to insert a newline
bool InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl);
/// Submit command to insert the given image
bool InsertImageWithUndo(long pos, const wxRichTextImageBlock& imageBlock, wxRichTextCtrl* ctrl);
/// Submit command to delete this range
bool DeleteRangeWithUndo(const wxRichTextRange& range, long initialCaretPosition, long newCaretPositon, wxRichTextCtrl* ctrl);
/// Mark modified
void Modify(bool modify = true) { m_modified = modify; }
bool IsModified() const { return m_modified; }
/// Dumps contents of buffer for debugging purposes
virtual void Dump();
virtual void Dump(wxTextOutputStream& stream) { wxRichTextParagraphLayoutBox::Dump(stream); }
/// Returns the file handlers
static wxList& GetHandlers() { return sm_handlers; }
/// Adds a handler to the end
static void AddHandler(wxRichTextFileHandler *handler);
/// Inserts a handler at the front
static void InsertHandler(wxRichTextFileHandler *handler);
/// Removes a handler
static bool RemoveHandler(const wxString& name);
/// Finds a handler by name
static wxRichTextFileHandler *FindHandler(const wxString& name);
/// Finds a handler by extension and type
static wxRichTextFileHandler *FindHandler(const wxString& extension, int imageType);
/// Finds a handler by filename or, if supplied, type
static wxRichTextFileHandler *FindHandlerFilenameOrType(const wxString& filename, int imageType);
/// Finds a handler by type
static wxRichTextFileHandler *FindHandler(int imageType);
/// Gets a wildcard incorporating all visible handlers. If 'types' is present,
/// will be filled with the file type corresponding to each filter. This can be
/// used to determine the type to pass to LoadFile given a selected filter.
static wxString GetExtWildcard(bool combine = false, bool save = false, wxArrayInt* types = NULL);
/// Clean up handlers
static void CleanUpHandlers();
/// Initialise the standard handlers
static void InitStandardHandlers();
protected:
/// Command processor
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -