📄 richtextbuffer.h
字号:
int m_paragraphSpacingBefore;
int m_lineSpacing;
int m_bulletStyle;
int m_bulletNumber;
wxChar m_bulletSymbol;
// Character style
wxString m_characterStyleName;
// Paragraph style
wxString m_paragraphStyleName;
};
/*!
* wxRichTextAttr stores attributes without a wxFont object, so is a much more
* efficient way to query styles.
*/
class WXDLLIMPEXP_RICHTEXT wxRichTextAttr
{
public:
// ctors
wxRichTextAttr(const wxTextAttrEx& attr);
wxRichTextAttr() { Init(); }
wxRichTextAttr(const wxColour& colText,
const wxColour& colBack = wxNullColour,
wxTextAttrAlignment alignment = wxTEXT_ALIGNMENT_DEFAULT);
// Initialise this object.
void Init();
// Assignment from a wxRichTextAttr object.
void operator= (const wxRichTextAttr& attr);
// Assignment from a wxTextAttrEx object.
void operator= (const wxTextAttrEx& attr);
// Making a wxTextAttrEx object.
operator wxTextAttrEx () const ;
// Copy to a wxTextAttr
void CopyTo(wxTextAttrEx& attr) const;
// Create font from font attributes.
wxFont CreateFont() const;
// Get attributes from font.
bool GetFontAttributes(const wxFont& font);
// setters
void SetTextColour(const wxColour& colText) { m_colText = colText; m_flags |= wxTEXT_ATTR_TEXT_COLOUR; }
void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; m_flags |= wxTEXT_ATTR_BACKGROUND_COLOUR; }
void SetAlignment(wxTextAttrAlignment alignment) { m_textAlignment = alignment; m_flags |= wxTEXT_ATTR_ALIGNMENT; }
void SetTabs(const wxArrayInt& tabs) { m_tabs = tabs; m_flags |= wxTEXT_ATTR_TABS; }
void SetLeftIndent(int indent, int subIndent = 0) { m_leftIndent = indent; m_leftSubIndent = subIndent; m_flags |= wxTEXT_ATTR_LEFT_INDENT; }
void SetRightIndent(int indent) { m_rightIndent = indent; m_flags |= wxTEXT_ATTR_RIGHT_INDENT; }
void SetFontSize(int pointSize) { m_fontSize = pointSize; m_flags |= wxTEXT_ATTR_FONT_SIZE; }
void SetFontStyle(int fontStyle) { m_fontStyle = fontStyle; m_flags |= wxTEXT_ATTR_FONT_ITALIC; }
void SetFontWeight(int fontWeight) { m_fontWeight = fontWeight; m_flags |= wxTEXT_ATTR_FONT_WEIGHT; }
void SetFontFaceName(const wxString& faceName) { m_fontFaceName = faceName; m_flags |= wxTEXT_ATTR_FONT_FACE; }
void SetFontUnderlined(bool underlined) { m_fontUnderlined = underlined; m_flags |= wxTEXT_ATTR_FONT_UNDERLINE; }
void SetFlags(long flags) { m_flags = flags; }
void SetCharacterStyleName(const wxString& name) { m_characterStyleName = name; }
void SetParagraphStyleName(const wxString& name) { m_paragraphStyleName = name; }
void SetParagraphSpacingAfter(int spacing) { m_paragraphSpacingAfter = spacing; }
void SetParagraphSpacingBefore(int spacing) { m_paragraphSpacingBefore = spacing; }
void SetLineSpacing(int spacing) { m_lineSpacing = spacing; }
void SetBulletStyle(int style) { m_bulletStyle = style; }
void SetBulletNumber(int n) { m_bulletNumber = n; }
void SetBulletSymbol(wxChar symbol) { m_bulletSymbol = symbol; }
const wxColour& GetTextColour() const { return m_colText; }
const wxColour& GetBackgroundColour() const { return m_colBack; }
wxTextAttrAlignment GetAlignment() const { return m_textAlignment; }
const wxArrayInt& GetTabs() const { return m_tabs; }
long GetLeftIndent() const { return m_leftIndent; }
long GetLeftSubIndent() const { return m_leftSubIndent; }
long GetRightIndent() const { return m_rightIndent; }
long GetFlags() const { return m_flags; }
int GetFontSize() const { return m_fontSize; }
int GetFontStyle() const { return m_fontStyle; }
int GetFontWeight() const { return m_fontWeight; }
bool GetFontUnderlined() const { return m_fontUnderlined; }
const wxString& GetFontFaceName() const { return m_fontFaceName; }
const wxString& GetCharacterStyleName() const { return m_characterStyleName; }
const wxString& GetParagraphStyleName() const { return m_paragraphStyleName; }
int GetParagraphSpacingAfter() const { return m_paragraphSpacingAfter; }
int GetParagraphSpacingBefore() const { return m_paragraphSpacingBefore; }
int GetLineSpacing() const { return m_lineSpacing; }
int GetBulletStyle() const { return m_bulletStyle; }
int GetBulletNumber() const { return m_bulletNumber; }
wxChar GetBulletSymbol() const { return m_bulletSymbol; }
// accessors
bool HasTextColour() const { return m_colText.Ok() && HasFlag(wxTEXT_ATTR_TEXT_COLOUR) ; }
bool HasBackgroundColour() const { return m_colBack.Ok() && HasFlag(wxTEXT_ATTR_BACKGROUND_COLOUR) ; }
bool HasAlignment() const { return (m_textAlignment != wxTEXT_ALIGNMENT_DEFAULT) || ((m_flags & wxTEXT_ATTR_ALIGNMENT) != 0) ; }
bool HasTabs() const { return (m_flags & wxTEXT_ATTR_TABS) != 0 ; }
bool HasLeftIndent() const { return (m_flags & wxTEXT_ATTR_LEFT_INDENT) != 0 ; }
bool HasRightIndent() const { return (m_flags & wxTEXT_ATTR_RIGHT_INDENT) != 0 ; }
bool HasWeight() const { return (m_flags & wxTEXT_ATTR_FONT_WEIGHT) != 0; }
bool HasSize() const { return (m_flags & wxTEXT_ATTR_FONT_SIZE) != 0; }
bool HasItalic() const { return (m_flags & wxTEXT_ATTR_FONT_ITALIC) != 0; }
bool HasUnderlined() const { return (m_flags & wxTEXT_ATTR_FONT_UNDERLINE) != 0; }
bool HasFaceName() const { return (m_flags & wxTEXT_ATTR_FONT_FACE) != 0; }
bool HasFont() const { return (m_flags & (wxTEXT_ATTR_FONT)) != 0; }
bool HasParagraphSpacingAfter() const { return (m_flags & wxTEXT_ATTR_PARA_SPACING_AFTER) != 0; }
bool HasParagraphSpacingBefore() const { return (m_flags & wxTEXT_ATTR_PARA_SPACING_BEFORE) != 0; }
bool HasLineSpacing() const { return (m_flags & wxTEXT_ATTR_LINE_SPACING) != 0; }
bool HasCharacterStyleName() const { return (m_flags & wxTEXT_ATTR_CHARACTER_STYLE_NAME) != 0; }
bool HasParagraphStyleName() const { return (m_flags & wxTEXT_ATTR_PARAGRAPH_STYLE_NAME) != 0; }
bool HasBulletStyle() const { return (m_flags & wxTEXT_ATTR_BULLET_STYLE) != 0; }
bool HasBulletNumber() const { return (m_flags & wxTEXT_ATTR_BULLET_NUMBER) != 0; }
bool HasBulletSymbol() const { return (m_flags & wxTEXT_ATTR_BULLET_SYMBOL) != 0; }
bool HasFlag(long flag) const { return (m_flags & flag) != 0; }
// Is this a character style?
bool IsCharacterStyle() const { return (0 != (GetFlags() & (wxTEXT_ATTR_FONT | wxTEXT_ATTR_BACKGROUND_COLOUR | wxTEXT_ATTR_TEXT_COLOUR))); }
bool IsParagraphStyle() const { return (0 != (GetFlags() & (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|
wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|wxTEXT_ATTR_LINE_SPACING|
wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER))); }
// returns false if we have any attributes set, true otherwise
bool IsDefault() const
{
return !HasTextColour() && !HasBackgroundColour() && !HasFont() && !HasAlignment() &&
!HasTabs() && !HasLeftIndent() && !HasRightIndent() &&
!HasParagraphSpacingAfter() && !HasParagraphSpacingBefore() && !HasLineSpacing() &&
!HasCharacterStyleName() && !HasParagraphStyleName() && !HasBulletNumber() && !HasBulletStyle() && !HasBulletSymbol();
}
// return the attribute having the valid font and colours: it uses the
// attributes set in attr and falls back first to attrDefault and then to
// the text control font/colours for those attributes which are not set
static wxRichTextAttr Combine(const wxRichTextAttr& attr,
const wxRichTextAttr& attrDef,
const wxTextCtrlBase *text);
private:
long m_flags;
// Paragraph styles
wxArrayInt m_tabs; // array of int: tab stops in 1/10 mm
int m_leftIndent; // left indent in 1/10 mm
int m_leftSubIndent; // left indent for all but the first
// line in a paragraph relative to the
// first line, in 1/10 mm
int m_rightIndent; // right indent in 1/10 mm
wxTextAttrAlignment m_textAlignment;
int m_paragraphSpacingAfter;
int m_paragraphSpacingBefore;
int m_lineSpacing;
int m_bulletStyle;
int m_bulletNumber;
wxChar m_bulletSymbol;
// Character styles
wxColour m_colText,
m_colBack;
int m_fontSize;
int m_fontStyle;
int m_fontWeight;
bool m_fontUnderlined;
wxString m_fontFaceName;
// Character style
wxString m_characterStyleName;
// Paragraph style
wxString m_paragraphStyleName;
};
#define wxTEXT_ATTR_CHARACTER (wxTEXT_ATTR_FONT | wxTEXT_ATTR_BACKGROUND_COLOUR | wxTEXT_ATTR_TEXT_COLOUR)
#define wxTEXT_ATTR_PARAGRAPH (wxTEXT_ATTR_ALIGNMENT|wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_TABS|\
wxTEXT_ATTR_PARA_SPACING_BEFORE|wxTEXT_ATTR_PARA_SPACING_AFTER|wxTEXT_ATTR_LINE_SPACING|\
wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_BULLET_NUMBER|wxTEXT_ATTR_BULLET_SYMBOL)
#define wxTEXT_ATTR_ALL (wxTEXT_ATTR_CHARACTER|wxTEXT_ATTR_PARAGRAPH)
/*!
* wxRichTextObject class declaration
* This is the base for drawable objects.
*/
class WXDLLIMPEXP_RICHTEXT wxRichTextObject: public wxObject
{
DECLARE_CLASS(wxRichTextObject)
public:
// Constructors
wxRichTextObject(wxRichTextObject* parent = NULL);
~wxRichTextObject();
// Overrideables
/// Draw the item, within the given range. Some objects may ignore the range (for
/// example paragraphs) while others must obey it (lines, to implement wrapping)
virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style) = 0;
/// Lay the item out at the specified position with the given size constraint.
/// Layout must set the cached size.
virtual bool Layout(wxDC& dc, const wxRect& rect, int style) = 0;
/// Hit-testing: returns a flag indicating hit test details, plus
/// information about position
virtual int HitTest(wxDC& WXUNUSED(dc), const wxPoint& WXUNUSED(pt), long& WXUNUSED(textPosition)) { return false; }
/// Finds the absolute position and row height for the given character position
virtual bool FindPosition(wxDC& WXUNUSED(dc), long WXUNUSED(index), wxPoint& WXUNUSED(pt), int* WXUNUSED(height), bool WXUNUSED(forceLineStart)) { return false; }
/// Get the best size, i.e. the ideal starting size for this object irrespective
/// of available space. For a short text string, it will be the size that exactly encloses
/// the text. For a longer string, it might use the parent width for example.
virtual wxSize GetBestSize() const { return m_size; }
/// 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 = 0;
/// Do a split, returning an object containing the second part, and setting
/// the first part in 'this'.
virtual wxRichTextObject* DoSplit(long WXUNUSED(pos)) { return NULL; }
/// Calculate range. By default, guess that the object is 1 unit long.
virtual void CalculateRange(long start, long& end) { end = start ; m_range.SetRange(start, end); }
/// Delete range
virtual bool DeleteRange(const wxRichTextRange& WXUNUSED(range)) { return false; }
/// Returns true if the object is empty
virtual bool IsEmpty() const { return false; }
/// Get any text in this object for the given range
virtual wxString GetTextForRange(const wxRichTextRange& WXUNUSED(range)) const { return wxEmptyString; }
/// Returns true if this object can merge itself with the given one.
virtual bool CanMerge(wxRichTextObject* WXUNUSED(object)) const { return false; }
/// Returns true if this object merged itself with the given one.
/// The calling code will then delete the given object.
virtual bool Merge(wxRichTextObject* WXUNUSED(object)) { return false; }
/// Dump to output stream for debugging
virtual void Dump(wxTextOutputStream& stream);
// Accessors
/// Get/set the cached object size as calculated by Layout.
virtual wxSize GetCachedSize() const { return m_size; }
virtual void SetCachedSize(const wxSize& sz) { m_size = sz; }
/// Get/set the object position
virtual wxPoint GetPosition() const { return m_pos; }
virtual void SetPosition(const wxPoint& pos) { m_pos = pos; }
/// Get the rectangle enclosing the object
virtual wxRect GetRect() const { return wxRect(GetPosition(), GetCachedSize()); }
/// Set the range
void SetRange(const wxRichTextRange& range) { m_range = range; }
/// Get the range
const wxRichTextRange& GetRange() const { return m_range; }
wxRichTextRange& GetRange() { return m_range; }
/// Get/set dirty flag (whether the object needs Layout to be called)
virtual bool GetDirty() const { return m_dirty; }
virtual void SetDirty(bool dirty) { m_dirty = dirty; }
/// Is this composite?
virtual bool IsComposite() const { return false; }
/// Get/set the parent.
virtual wxRichTextObject* GetParent() const { return m_parent; }
virtual void SetParent(wxRichTextObject* parent) { m_parent = parent; }
/// Set the margin around the object
virtual void SetMargins(int margin);
virtual void SetMargins(int leftMargin, int rightMargin, int topMargin, int bottomMargin);
virtual int GetLeftMargin() const { return m_leftMargin; }
virtual int GetRightMargin() const { return m_rightMargin; }
virtual int GetTopMargin() const { return m_topMargin; }
virtual int GetBottomMargin() const { return m_bottomMargin; }
/// Set attributes object
void SetAttributes(const wxTextAttrEx& attr) { m_attributes = attr; }
const wxTextAttrEx& GetAttributes() const { return m_attributes; }
wxTextAttrEx& GetAttributes() { return m_attributes; }
/// Set/get stored descent
void SetDescent(int descent) { m_descent = descent; }
int GetDescent() const { return m_descent; }
// Operations
/// Clone the object
virtual wxRichTextObject* Clone() const { return NULL; }
/// Copy
void Copy(const wxRichTextObject& obj);
/// Reference-counting allows us to use the same object in multiple
/// lists (not yet used)
void Reference() { m_refCount ++; }
void Dereference();
/// Convert units in tends of a millimetre to device units
int ConvertTenthsMMToPixels(wxDC& dc, int units);
protected:
wxSize m_size;
wxPoint m_pos;
int m_descent; // Descent for this object (if any)
bool m_dirty;
int m_refCount;
wxRichTextObject* m_parent;
/// The range of this object (start position to end position)
wxRichTextRange m_range;
/// Margins
int m_leftMargin;
int m_rightMargin;
int m_topMargin;
int m_bottomMargin;
/// Attributes
wxTextAttrEx m_attributes;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -