⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 richtextctrl.h

📁 Wxpython Implemented on Windows CE, Source code
💻 H
📖 第 1 页 / 共 2 页
字号:
/////////////////////////////////////////////////////////////////////////////
// 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.15 2006/07/03 21:13:14 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"

#if wxCHECK_VERSION(2,7,0)
#define wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE 0
#else
#define wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE 0
#endif

#if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
#include "wx/textctrl.h"
#endif

/*!
 * 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:
#if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
 public wxTextCtrlBase, wxScrollHelper
#else
 public wxScrolledWindow
#endif
{
    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 );
    ~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 );

    /// Member initialisation
    void Init();

///// wxTextCtrl compatibility

// Accessors

    virtual wxString GetValue() const;
    virtual void SetValue(const wxString& value);

    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 LoadFile(const wxString& file, int type = wxRICHTEXT_TYPE_ANY);
    virtual bool SaveFile(const wxString& file = wxEmptyString, int type = wxRICHTEXT_TYPE_ANY);

    // 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) const;
    virtual bool GetStyle(long position, wxTextAttrEx& style) const;
    virtual bool GetStyle(long position, wxRichTextAttr& style) const;
    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;

    // 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();

    /// 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
    virtual bool EndStyle() { return GetBuffer().EndStyle(); }

    /// End all styles
    virtual bool EndAllStyles() { return GetBuffer().EndAllStyles(); }

    /// Begin using bold
    bool BeginBold() { return GetBuffer().BeginBold(); }

    /// End using bold
    bool EndBold()  { return GetBuffer().EndBold(); }

    /// Begin using italic
    bool BeginItalic() { return GetBuffer().BeginItalic(); }

    /// End using italic
    bool EndItalic() { return GetBuffer().EndItalic(); }

    /// Begin using underline
    bool BeginUnderline() { return GetBuffer().BeginUnderline(); }

    /// End using underline
    bool EndUnderline() { return GetBuffer().EndUnderline(); }

    /// Begin using point size
    bool BeginFontSize(int pointSize) { return GetBuffer().BeginFontSize(pointSize); }

    /// End using point size
    bool EndFontSize() { return GetBuffer().EndFontSize(); }

    /// Begin using this font
    bool BeginFont(const wxFont& font) { return GetBuffer().BeginFont(font); }

    /// End using a font
    bool EndFont() { return GetBuffer().EndFont(); }

    /// Begin using this colour
    bool BeginTextColour(const wxColour& colour) { return GetBuffer().BeginTextColour(colour); }

    /// End using a colour
    bool EndTextColour() { return GetBuffer().EndTextColour(); }

    /// Begin using alignment
    bool BeginAlignment(wxTextAttrAlignment alignment) { return GetBuffer().BeginAlignment(alignment); }

    /// End alignment
    bool EndAlignment() { return GetBuffer().EndAlignment(); }

    /// Begin left indent
    bool BeginLeftIndent(int leftIndent, int leftSubIndent = 0) { return GetBuffer().BeginLeftIndent(leftIndent, leftSubIndent); }

    /// End left indent
    bool EndLeftIndent() { return GetBuffer().EndLeftIndent(); }

    /// Begin right indent
    bool BeginRightIndent(int rightIndent) { return GetBuffer().BeginRightIndent(rightIndent); }

    /// End right indent
    bool EndRightIndent() { return GetBuffer().EndRightIndent(); }

    /// Begin paragraph spacing
    bool BeginParagraphSpacing(int before, int after) { return GetBuffer().BeginParagraphSpacing(before, after); }

    /// End paragraph spacing
    bool EndParagraphSpacing() { return GetBuffer().EndParagraphSpacing(); }

    /// Begin line spacing
    bool BeginLineSpacing(int lineSpacing) { return GetBuffer().BeginLineSpacing(lineSpacing); }

    /// End line spacing
    bool EndLineSpacing() { return GetBuffer().EndLineSpacing(); }

    /// Begin numbered bullet
    bool BeginNumberedBullet(int bulletNumber, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_ARABIC|wxTEXT_ATTR_BULLET_STYLE_PERIOD)
    { return GetBuffer().BeginNumberedBullet(bulletNumber, leftIndent, leftSubIndent, bulletStyle); }

    /// End numbered bullet
    bool EndNumberedBullet() { return GetBuffer().EndNumberedBullet(); }

    /// Begin symbol bullet
    bool BeginSymbolBullet(wxChar symbol, int leftIndent, int leftSubIndent, int bulletStyle = wxTEXT_ATTR_BULLET_STYLE_SYMBOL)
    { return GetBuffer().BeginSymbolBullet(symbol, leftIndent, leftSubIndent, bulletStyle); }

    /// End symbol bullet
    bool EndSymbolBullet() { return GetBuffer().EndSymbolBullet(); }

    /// Begin named character style
    bool BeginCharacterStyle(const wxString& characterStyle) { return GetBuffer().BeginCharacterStyle(characterStyle); }

    /// End named character style
    bool EndCharacterStyle() { return GetBuffer().EndCharacterStyle(); }

    /// Begin named paragraph style
    bool BeginParagraphStyle(const wxString& paragraphStyle) { return GetBuffer().BeginParagraphStyle(paragraphStyle); }

    /// End named character style
    bool EndParagraphStyle() { return GetBuffer().EndParagraphStyle(); }

    /// Sets the default style to the style under the cursor
    bool SetDefaultStyleToCursorStyle();

    /// Clear the selection
    virtual void SelectNone();

    /// Get/set the selection range in character positions. -1, -1 means no selection.
    const wxRichTextRange& GetSelectionRange() const { return m_selectionRange; }
    void SetSelectionRange(const wxRichTextRange& range) { m_selectionRange = range; }

    /// Add a new paragraph of text to the end of the buffer
    virtual wxRichTextRange AddParagraph(const wxString& text);

    /// Add an image
    virtual wxRichTextRange AddImage(const wxImage& image);

    /// Layout the buffer: which we must do before certain operations, such as
    /// setting the caret position.
    virtual bool LayoutContent(bool onlyVisibleRect = false);

    /// Move the caret to the given character position
    virtual bool MoveCaret(long pos, bool showAtLineStart = false);

    /// Move right
    virtual bool MoveRight(int noPositions = 1, int flags = 0);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -