📄 richtextbuffer.h
字号:
/////////////////////////////////////////////////////////////////////////////// Name: wx/richtext/richtextbuffer.h// Purpose: Buffer for wxRichTextCtrl// Author: Julian Smart// Modified by:// Created: 2005-09-30// RCS-ID: $Id: richtextbuffer.h,v 1.46 2006/12/01 23:52:54 RD Exp $// Copyright: (c) Julian Smart// Licence: wxWindows licence/////////////////////////////////////////////////////////////////////////////#ifndef _WX_RICHTEXTBUFFER_H_#define _WX_RICHTEXTBUFFER_H_/* Data structures =============== Data is represented by a hierarchy of objects, all derived from wxRichTextObject. The top of the hierarchy is the buffer, a kind of wxRichTextParagraphLayoutBox. These boxes will allow flexible placement of text boxes on a page, but for now there is a single box representing the document, and this box is a wxRichTextParagraphLayoutBox which contains further wxRichTextParagraph objects, each of which can include text and images. Each object maintains a range (start and end position) measured from the start of the main parent box. A paragraph object knows its range, and a text fragment knows its range too. So, a character or image in a page has a position relative to the start of the document, and a character in an embedded text box has a position relative to that text box. For now, we will not be dealing with embedded objects but it's something to bear in mind for later. Note that internally, a range (5,5) represents a range of one character. In the public wx[Rich]TextCtrl API, this would be passed to e.g. SetSelection as (5,6). A paragraph with one character might have an internal range of (0, 1) since the end of the paragraph takes up one position. Layout ====== When Layout is called on an object, it is given a size which the object must limit itself to, or one or more flexible directions (vertical or horizontal). So for example a centered paragraph is given the page width to play with (minus any margins), but can extend indefinitely in the vertical direction. The implementation of Layout can then cache the calculated size and position within the parent. *//*! * Includes */#include "wx/defs.h"#if wxUSE_RICHTEXT#include "wx/list.h"#include "wx/textctrl.h"#include "wx/bitmap.h"#include "wx/image.h"#include "wx/cmdproc.h"#include "wx/txtstrm.h"#if wxUSE_DATAOBJ#include "wx/dataobj.h"#endif/*! * Special characters */extern WXDLLIMPEXP_RICHTEXT const wxChar wxRichTextLineBreakChar;/*! * File types */#define wxRICHTEXT_TYPE_ANY 0#define wxRICHTEXT_TYPE_TEXT 1#define wxRICHTEXT_TYPE_XML 2#define wxRICHTEXT_TYPE_HTML 3#define wxRICHTEXT_TYPE_RTF 4#define wxRICHTEXT_TYPE_PDF 5/*! * Forward declarations */class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl;class WXDLLIMPEXP_RICHTEXT wxRichTextObject;class WXDLLIMPEXP_RICHTEXT wxRichTextCacheObject;class WXDLLIMPEXP_RICHTEXT wxRichTextObjectList;class WXDLLIMPEXP_RICHTEXT wxRichTextLine;class WXDLLIMPEXP_RICHTEXT wxRichTextParagraph;class WXDLLIMPEXP_RICHTEXT wxRichTextFileHandler;class WXDLLIMPEXP_RICHTEXT wxRichTextStyleSheet;class WXDLLIMPEXP_RICHTEXT wxTextAttrEx;class WXDLLIMPEXP_RICHTEXT wxRichTextListStyleDefinition;class WXDLLIMPEXP_RICHTEXT wxRichTextEvent;class WXDLLIMPEXP_RICHTEXT wxRichTextRenderer;class WXDLLIMPEXP_RICHTEXT wxRichTextBuffer;/*! * Flags determining the available space, passed to Layout */#define wxRICHTEXT_FIXED_WIDTH 0x01#define wxRICHTEXT_FIXED_HEIGHT 0x02#define wxRICHTEXT_VARIABLE_WIDTH 0x04#define wxRICHTEXT_VARIABLE_HEIGHT 0x08// Only lay out the part of the buffer that lies within// the rect passed to Layout.#define wxRICHTEXT_LAYOUT_SPECIFIED_RECT 0x10/*! * Flags to pass to Draw */// Ignore paragraph cache optimization, e.g. for printing purposes// where one line may be drawn higher (on the next page) compared// with the previous line#define wxRICHTEXT_DRAW_IGNORE_CACHE 0x01/*! * Flags returned from hit-testing */// The point was not on this object#define wxRICHTEXT_HITTEST_NONE 0x01// The point was before the position returned from HitTest#define wxRICHTEXT_HITTEST_BEFORE 0x02// The point was after the position returned from HitTest#define wxRICHTEXT_HITTEST_AFTER 0x04// The point was on the position returned from HitTest#define wxRICHTEXT_HITTEST_ON 0x08/*! * Flags for GetRangeSize */#define wxRICHTEXT_FORMATTED 0x01#define wxRICHTEXT_UNFORMATTED 0x02/*! * Flags for SetStyle/SetListStyle */#define wxRICHTEXT_SETSTYLE_NONE 0x00// Specifies that this operation should be undoable#define wxRICHTEXT_SETSTYLE_WITH_UNDO 0x01// Specifies that the style should not be applied if the// combined style at this point is already the style in question.#define wxRICHTEXT_SETSTYLE_OPTIMIZE 0x02// Specifies that the style should only be applied to paragraphs,// and not the content. This allows content styling to be// preserved independently from that of e.g. a named paragraph style.#define wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY 0x04// Specifies that the style should only be applied to characters,// and not the paragraph. This allows content styling to be// preserved independently from that of e.g. a named paragraph style.#define wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY 0x08// For SetListStyle only: specifies starting from the given number, otherwise// deduces number from existing attributes#define wxRICHTEXT_SETSTYLE_RENUMBER 0x10// For SetListStyle only: specifies the list level for all paragraphs, otherwise// the current indentation will be used#define wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL 0x20// Resets the existing style before applying the new style#define wxRICHTEXT_SETSTYLE_RESET 0x40/*! * Flags for text insertion */#define wxRICHTEXT_INSERT_NONE 0x00#define wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE 0x01/*! * Extra formatting flags not in wxTextAttr */#define wxTEXT_ATTR_PARA_SPACING_AFTER 0x00000800#define wxTEXT_ATTR_PARA_SPACING_BEFORE 0x00001000#define wxTEXT_ATTR_LINE_SPACING 0x00002000#define wxTEXT_ATTR_CHARACTER_STYLE_NAME 0x00004000#define wxTEXT_ATTR_PARAGRAPH_STYLE_NAME 0x00008000#define wxTEXT_ATTR_LIST_STYLE_NAME 0x00010000#define wxTEXT_ATTR_BULLET_STYLE 0x00020000#define wxTEXT_ATTR_BULLET_NUMBER 0x00040000#define wxTEXT_ATTR_BULLET_TEXT 0x00080000#define wxTEXT_ATTR_BULLET_NAME 0x00100000#define wxTEXT_ATTR_URL 0x00200000#define wxTEXT_ATTR_PAGE_BREAK 0x00400000#define wxTEXT_ATTR_EFFECTS 0x00800000#define wxTEXT_ATTR_OUTLINE_LEVEL 0x01000000/*! * Styles for wxTextAttrEx::SetBulletStyle */#define wxTEXT_ATTR_BULLET_STYLE_NONE 0x00000000#define wxTEXT_ATTR_BULLET_STYLE_ARABIC 0x00000001#define wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER 0x00000002#define wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER 0x00000004#define wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER 0x00000008#define wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER 0x00000010#define wxTEXT_ATTR_BULLET_STYLE_SYMBOL 0x00000020#define wxTEXT_ATTR_BULLET_STYLE_BITMAP 0x00000040#define wxTEXT_ATTR_BULLET_STYLE_PARENTHESES 0x00000080#define wxTEXT_ATTR_BULLET_STYLE_PERIOD 0x00000100#define wxTEXT_ATTR_BULLET_STYLE_STANDARD 0x00000200#define wxTEXT_ATTR_BULLET_STYLE_RIGHT_PARENTHESIS 0x00000400#define wxTEXT_ATTR_BULLET_STYLE_OUTLINE 0x00000800#define wxTEXT_ATTR_BULLET_STYLE_ALIGN_LEFT 0x00000000#define wxTEXT_ATTR_BULLET_STYLE_ALIGN_RIGHT 0x00001000#define wxTEXT_ATTR_BULLET_STYLE_ALIGN_CENTRE 0x00002000/*! * Styles for wxTextAttrEx::SetTextEffects */#define wxTEXT_ATTR_EFFECT_NONE 0x00000000#define wxTEXT_ATTR_EFFECT_CAPITALS 0x00000001#define wxTEXT_ATTR_EFFECT_SMALL_CAPITALS 0x00000002#define wxTEXT_ATTR_EFFECT_STRIKETHROUGH 0x00000004#define wxTEXT_ATTR_EFFECT_DOUBLE_STRIKETHROUGH 0x00000008#define wxTEXT_ATTR_EFFECT_SHADOW 0x00000010#define wxTEXT_ATTR_EFFECT_EMBOSS 0x00000020#define wxTEXT_ATTR_EFFECT_OUTLINE 0x00000040#define wxTEXT_ATTR_EFFECT_ENGRAVE 0x00000080#define wxTEXT_ATTR_EFFECT_SUPERSCRIPT 0x00000100#define wxTEXT_ATTR_EFFECT_SUBSCRIPT 0x00000200/*! * Line spacing values */#define wxTEXT_ATTR_LINE_SPACING_NORMAL 10#define wxTEXT_ATTR_LINE_SPACING_HALF 15#define wxTEXT_ATTR_LINE_SPACING_TWICE 20/*! * Character and paragraph combined styles */#define wxTEXT_ATTR_CHARACTER (wxTEXT_ATTR_FONT|wxTEXT_ATTR_EFFECTS|wxTEXT_ATTR_BACKGROUND_COLOUR|wxTEXT_ATTR_TEXT_COLOUR|wxTEXT_ATTR_CHARACTER_STYLE_NAME|wxTEXT_ATTR_URL)#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_TEXT|wxTEXT_ATTR_BULLET_NAME|\ wxTEXT_ATTR_PARAGRAPH_STYLE_NAME|wxTEXT_ATTR_LIST_STYLE_NAME|wxTEXT_ATTR_OUTLINE_LEVEL)#define wxTEXT_ATTR_ALL (wxTEXT_ATTR_CHARACTER|wxTEXT_ATTR_PARAGRAPH)/*! * wxRichTextRange class declaration * This stores beginning and end positions for a range of data. */class WXDLLIMPEXP_RICHTEXT wxRichTextRange{public:// Constructors wxRichTextRange() { m_start = 0; m_end = 0; } wxRichTextRange(long start, long end) { m_start = start; m_end = end; } wxRichTextRange(const wxRichTextRange& range) { m_start = range.m_start; m_end = range.m_end; } ~wxRichTextRange() {} void operator =(const wxRichTextRange& range) { m_start = range.m_start; m_end = range.m_end; } bool operator ==(const wxRichTextRange& range) const { return (m_start == range.m_start && m_end == range.m_end); } bool operator !=(const wxRichTextRange& range) const { return (m_start != range.m_start && m_end != range.m_end); } wxRichTextRange operator -(const wxRichTextRange& range) const { return wxRichTextRange(m_start - range.m_start, m_end - range.m_end); } wxRichTextRange operator +(const wxRichTextRange& range) const { return wxRichTextRange(m_start + range.m_start, m_end + range.m_end); } void SetRange(long start, long end) { m_start = start; m_end = end; } void SetStart(long start) { m_start = start; } long GetStart() const { return m_start; } void SetEnd(long end) { m_end = end; } long GetEnd() const { return m_end; } /// Returns true if this range is completely outside 'range' bool IsOutside(const wxRichTextRange& range) const { return range.m_start > m_end || range.m_end < m_start; } /// Returns true if this range is completely within 'range' bool IsWithin(const wxRichTextRange& range) const { return m_start >= range.m_start && m_end <= range.m_end; } /// Returns true if the given position is within this range. Allow /// for the possibility of an empty range - assume the position /// is within this empty range. NO, I think we should not match with an empty range. // bool Contains(long pos) const { return pos >= m_start && (pos <= m_end || GetLength() == 0); } bool Contains(long pos) const { return pos >= m_start && pos <= m_end ; } /// Limit this range to be within 'range' bool LimitTo(const wxRichTextRange& range) ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -