Removed obsolete code

Added some more event types
Added back GetStyleForRange


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43469 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2006-11-17 14:28:47 +00:00
parent a95dd1d8ff
commit 5912d19ef7
4 changed files with 139 additions and 133 deletions

View File

@@ -70,10 +70,6 @@
#include "wx/dataobj.h"
#endif
// Experimental dynamic styles to avoid user-specific character styles from being
// overwritten by paragraph styles.
#define wxRICHTEXT_USE_DYNAMIC_STYLES 1
/*!
* File types
*/

View File

@@ -184,11 +184,10 @@ public:
virtual bool GetStyle(long position, wxTextAttrEx& style);
virtual bool GetStyle(long position, wxRichTextAttr& style);
/*
// get the common set of styles for the range
bool GetStyleForRange(const wxRichTextRange& range, wxRichTextAttr& style);
bool GetStyleForRange(const wxRichTextRange& range, wxTextAttrEx& style);
*/
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.
@@ -854,17 +853,19 @@ class WXDLLIMPEXP_RICHTEXT wxRichTextEvent : public wxNotifyEvent
public:
wxRichTextEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
: wxNotifyEvent(commandType, winid),
m_itemIndex(-1), m_flags(0), m_oldStyleSheet(NULL), m_newStyleSheet(NULL)
m_flags(0), m_position(-1), m_oldStyleSheet(NULL), m_newStyleSheet(NULL),
m_char((wxChar) 0)
{ }
wxRichTextEvent(const wxRichTextEvent& event)
: wxNotifyEvent(event),
m_itemIndex(event.m_itemIndex), m_flags(event.m_flags),
m_oldStyleSheet(event.m_oldStyleSheet), m_newStyleSheet(event.m_newStyleSheet)
m_flags(event.m_flags), m_position(-1),
m_oldStyleSheet(event.m_oldStyleSheet), m_newStyleSheet(event.m_newStyleSheet),
m_char((wxChar) 0)
{ }
int GetIndex() const { return m_itemIndex; }
void SetIndex(int n) { m_itemIndex = n; }
long GetPosition() const { return m_position; }
void SetPosition(long pos) { m_position = pos; }
int GetFlags() const { return m_flags; }
void SetFlags(int flags) { m_flags = flags; }
@@ -875,13 +876,21 @@ public:
wxRichTextStyleSheet* GetNewStyleSheet() const { return m_newStyleSheet; }
void SetNewStyleSheet(wxRichTextStyleSheet* sheet) { m_newStyleSheet = sheet; }
const wxRichTextRange& GetRange() const { return m_range; }
void SetRange(const wxRichTextRange& range) { m_range = range; }
wxChar GetCharacter() const { return m_char; }
void SetCharacter(wxChar ch) { m_char = ch; }
virtual wxEvent *Clone() const { return new wxRichTextEvent(*this); }
protected:
int m_itemIndex;
int m_flags;
long m_position;
wxRichTextStyleSheet* m_oldStyleSheet;
wxRichTextStyleSheet* m_newStyleSheet;
wxRichTextRange m_range;
wxChar m_char;
private:
DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRichTextEvent)
@@ -892,35 +901,45 @@ private:
*/
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED, 2600)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED, 2601)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, 2602)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, 2603)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, 2604)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, 2605)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_RETURN, 2606)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_CHARACTER, 2607)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_DELETE, 2608)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING, 2607)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED, 2608)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING, 2609)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED, 2610)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING, 2609)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED, 2610)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING, 2611)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED, 2612)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED, 2613)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED, 2614)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED, 2615)
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_RICHTEXT, wxEVT_COMMAND_RICHTEXT_SELECTION_CHANGED, 2616)
END_DECLARE_EVENT_TYPES()
typedef void (wxEvtHandler::*wxRichTextEventFunction)(wxRichTextEvent&);
#define EVT_RICHTEXT_ITEM_SELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
#define EVT_RICHTEXT_ITEM_DESELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
#define EVT_RICHTEXT_LEFT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
#define EVT_RICHTEXT_RIGHT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
#define EVT_RICHTEXT_MIDDLE_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
#define EVT_RICHTEXT_LEFT_DCLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
#define EVT_RICHTEXT_RETURN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_RETURN, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
#define EVT_RICHTEXT_CHARACTER(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_CHARACTER, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
#define EVT_RICHTEXT_DELETE(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_DELETE, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
#define EVT_RICHTEXT_STYLESHEET_CHANGING(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
#define EVT_RICHTEXT_STYLESHEET_CHANGED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
#define EVT_RICHTEXT_STYLESHEET_REPLACING(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
#define EVT_RICHTEXT_STYLESHEET_REPLACED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
#define EVT_RICHTEXT_CONTENT_INSERTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
#define EVT_RICHTEXT_CONTENT_DELETED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
#define EVT_RICHTEXT_STYLE_CHANGED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
#define EVT_RICHTEXT_SELECTION_CHANGED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_SELECTION_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
#endif
// wxUSE_RICHTEXT

View File

@@ -85,12 +85,6 @@ void wxRichTextObject::Copy(const wxRichTextObject& obj)
m_range = obj.m_range;
m_attributes = obj.m_attributes;
m_descent = obj.m_descent;
/*
if (!m_attributes.GetFont().Ok())
wxLogDebug(wxT("No font!"));
if (!obj.m_attributes.GetFont().Ok())
wxLogDebug(wxT("Parent has no font!"));
*/
}
void wxRichTextObject::SetMargins(int margin)
@@ -907,25 +901,14 @@ wxSize wxRichTextParagraphLayoutBox::GetLineSizeAtPosition(long pos, bool caretP
/// Convenience function to add a paragraph of text
wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraph(const wxString& text, wxTextAttrEx* paraStyle)
{
#if wxRICHTEXT_USE_DYNAMIC_STYLES
// Don't use the base style, just the default style, and the base style will
// be combined at display time.
// Divide into paragraph and character styles.
wxTextAttrEx defaultCharStyle;
wxTextAttrEx defaultParaStyle;
wxRichTextSplitParaCharStyles(GetDefaultStyle(), defaultParaStyle, defaultCharStyle);
#else
wxTextAttrEx style(GetAttributes());
// Apply default style. If the style has no attributes set,
// then the attributes will remain the 'basic style' (i.e. the
// layout box's style).
wxRichTextApplyStyle(style, GetDefaultStyle());
wxTextAttrEx defaultCharStyle = style;
wxTextAttrEx defaultParaStyle = style;
#endif
wxTextAttrEx* pStyle = paraStyle ? paraStyle : (wxTextAttrEx*) & defaultParaStyle;
wxTextAttrEx* cStyle = & defaultCharStyle;
@@ -942,7 +925,6 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraph(const wxString& text,
/// Adds multiple paragraphs, based on newlines.
wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraphs(const wxString& text, wxTextAttrEx* paraStyle)
{
#if wxRICHTEXT_USE_DYNAMIC_STYLES
// Don't use the base style, just the default style, and the base style will
// be combined at display time.
// Divide into paragraph and character styles.
@@ -950,17 +932,6 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraphs(const wxString& text
wxTextAttrEx defaultCharStyle;
wxTextAttrEx defaultParaStyle;
wxRichTextSplitParaCharStyles(GetDefaultStyle(), defaultParaStyle, defaultCharStyle);
#else
wxTextAttrEx style(GetAttributes());
// Apply default style. If the style has no attributes set,
// then the attributes will remain the 'basic style' (i.e. the
// layout box's style).
wxRichTextApplyStyle(style, GetDefaultStyle());
wxTextAttrEx defaultCharStyle = style;
wxTextAttrEx defaultParaStyle = style;
#endif
wxTextAttrEx* pStyle = paraStyle ? paraStyle : (wxTextAttrEx*) & defaultParaStyle;
wxTextAttrEx* cStyle = & defaultCharStyle;
@@ -1017,7 +988,6 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraphs(const wxString& text
/// Convenience function to add an image
wxRichTextRange wxRichTextParagraphLayoutBox::AddImage(const wxImage& image, wxTextAttrEx* paraStyle)
{
#if wxRICHTEXT_USE_DYNAMIC_STYLES
// Don't use the base style, just the default style, and the base style will
// be combined at display time.
// Divide into paragraph and character styles.
@@ -1025,17 +995,6 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddImage(const wxImage& image, wxT
wxTextAttrEx defaultCharStyle;
wxTextAttrEx defaultParaStyle;
wxRichTextSplitParaCharStyles(GetDefaultStyle(), defaultParaStyle, defaultCharStyle);
#else
wxTextAttrEx style(GetAttributes());
// Apply default style. If the style has no attributes set,
// then the attributes will remain the 'basic style' (i.e. the
// layout box's style).
wxRichTextApplyStyle(style, GetDefaultStyle());
wxTextAttrEx defaultCharStyle = style;
wxTextAttrEx defaultParaStyle = style;
#endif
wxTextAttrEx* pStyle = paraStyle ? paraStyle : (wxTextAttrEx*) & defaultParaStyle;
wxTextAttrEx* cStyle = & defaultCharStyle;
@@ -1685,8 +1644,7 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const
}
}
#if wxRICHTEXT_USE_DYNAMIC_STYLES
// If applying paragraph styles dynamically, don't change the text objects' attributes
// When applying paragraph styles dynamically, don't change the text objects' attributes
// since they will computed as needed. Only apply the character styling if it's _only_
// character styling. This policy is subject to change and might be put under user control.
@@ -1698,9 +1656,6 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const
// if (!paragraphStyle && characterStyle && range.GetStart() != newPara->GetRange().GetEnd())
if (!parasOnly && characterStyle && range.GetStart() != newPara->GetRange().GetEnd())
#else
if (characterStyle && range.GetStart() != newPara->GetRange().GetEnd())
#endif
{
wxRichTextRange childRange(range);
childRange.LimitTo(newPara->GetRange());
@@ -1837,7 +1792,6 @@ bool wxRichTextParagraphLayoutBox::DoGetStyle(long position, wxTextAttrEx& style
obj = GetParagraphAtPosition(position);
if (obj)
{
#if wxRICHTEXT_USE_DYNAMIC_STYLES
if (combineStyles)
{
// Start with the base style
@@ -1848,9 +1802,7 @@ bool wxRichTextParagraphLayoutBox::DoGetStyle(long position, wxTextAttrEx& style
}
else
style = obj->GetAttributes();
#else
style = obj->GetAttributes();
#endif
return true;
}
}
@@ -1859,7 +1811,6 @@ bool wxRichTextParagraphLayoutBox::DoGetStyle(long position, wxTextAttrEx& style
obj = GetLeafObjectAtPosition(position);
if (obj)
{
#if wxRICHTEXT_USE_DYNAMIC_STYLES
if (combineStyles)
{
wxRichTextParagraph* para = wxDynamicCast(obj->GetParent(), wxRichTextParagraph);
@@ -1867,9 +1818,7 @@ bool wxRichTextParagraphLayoutBox::DoGetStyle(long position, wxTextAttrEx& style
}
else
style = obj->GetAttributes();
#else
style = obj->GetAttributes();
#endif
return true;
}
}
@@ -2405,11 +2354,8 @@ bool wxRichTextParagraphLayoutBox::HasCharacterAttributes(const wxRichTextRange&
if (!child->GetRange().IsOutside(range) && child->IsKindOf(CLASSINFO(wxRichTextPlainText)))
{
foundCount ++;
#if wxRICHTEXT_USE_DYNAMIC_STYLES
wxTextAttrEx textAttr = para->GetCombinedAttributes(child->GetAttributes());
#else
const wxTextAttrEx& textAttr = child->GetAttributes();
#endif
if (wxTextAttrEqPartial(textAttr, style, style.GetFlags()))
matchingCount ++;
}
@@ -2454,14 +2400,10 @@ bool wxRichTextParagraphLayoutBox::HasParagraphAttributes(const wxRichTextRange&
if (!para->GetRange().IsOutside(range))
{
#if wxRICHTEXT_USE_DYNAMIC_STYLES
wxTextAttrEx textAttr = GetAttributes();
// Apply the paragraph style
wxRichTextApplyStyle(textAttr, para->GetAttributes());
#else
const wxTextAttrEx& textAttr = para->GetAttributes();
#endif
foundCount ++;
if (wxTextAttrEqPartial(textAttr, style, style.GetFlags()))
matchingCount ++;
@@ -3060,11 +3002,7 @@ wxRichTextParagraph::~wxRichTextParagraph()
/// Draw the item
bool wxRichTextParagraph::Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& WXUNUSED(rect), int WXUNUSED(descent), int style)
{
#if wxRICHTEXT_USE_DYNAMIC_STYLES
wxTextAttrEx attr = GetCombinedAttributes();
#else
const wxTextAttrEx& attr = GetAttributes();
#endif
// Draw the bullet, if any
if (attr.GetBulletStyle() != wxTEXT_ATTR_BULLET_STYLE_NONE)
@@ -3176,11 +3114,7 @@ bool wxRichTextParagraph::Draw(wxDC& dc, const wxRichTextRange& range, const wxR
/// Lay the item out
bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style)
{
#if wxRICHTEXT_USE_DYNAMIC_STYLES
wxTextAttrEx attr = GetCombinedAttributes();
#else
const wxTextAttrEx& attr = GetAttributes();
#endif
// ClearLines();
@@ -4166,14 +4100,10 @@ wxRichTextPlainText::wxRichTextPlainText(const wxString& text, wxRichTextObject*
/// Draw the item
bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int WXUNUSED(style))
{
#if wxRICHTEXT_USE_DYNAMIC_STYLES
wxRichTextParagraph* para = wxDynamicCast(GetParent(), wxRichTextParagraph);
wxASSERT (para != NULL);
wxTextAttrEx textAttr(para ? para->GetCombinedAttributes(GetAttributes()) : GetAttributes());
#else
wxTextAttrEx textAttr(GetAttributes());
#endif
int offset = GetRange().GetStart();
@@ -4395,14 +4325,10 @@ bool wxRichTextPlainText::DrawTabbedString(wxDC& dc, const wxTextAttrEx& attr, c
/// Lay the item out
bool wxRichTextPlainText::Layout(wxDC& dc, const wxRect& WXUNUSED(rect), int WXUNUSED(style))
{
#if wxRICHTEXT_USE_DYNAMIC_STYLES
wxRichTextParagraph* para = wxDynamicCast(GetParent(), wxRichTextParagraph);
wxASSERT (para != NULL);
wxTextAttrEx textAttr(para ? para->GetCombinedAttributes(GetAttributes()) : GetAttributes());
#else
wxTextAttrEx textAttr(GetAttributes());
#endif
if (textAttr.GetFont().Ok())
dc.SetFont(textAttr.GetFont());
@@ -4433,14 +4359,10 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz
if (!range.IsWithin(GetRange()))
return false;
#if wxRICHTEXT_USE_DYNAMIC_STYLES
wxRichTextParagraph* para = wxDynamicCast(GetParent(), wxRichTextParagraph);
wxASSERT (para != NULL);
wxTextAttrEx textAttr(para ? para->GetCombinedAttributes(GetAttributes()) : GetAttributes());
#else
wxTextAttrEx textAttr(GetAttributes());
#endif
// Always assume unformatted text, since at this level we have no knowledge
// of line breaks - and we don't need it, since we'll calculate size within
@@ -4685,12 +4607,7 @@ bool wxRichTextBuffer::InsertParagraphsWithUndo(long pos, const wxRichTextParagr
{
wxRichTextAction* action = new wxRichTextAction(NULL, _("Insert Text"), wxRICHTEXT_INSERT, this, ctrl, false);
#if wxRICHTEXT_USE_DYNAMIC_STYLES
wxTextAttrEx attr(GetDefaultStyle());
#else
wxTextAttrEx attr(GetBasicStyle());
wxRichTextApplyStyle(attr, GetDefaultStyle());
#endif
wxTextAttrEx* p = NULL;
wxTextAttrEx paraAttr;
@@ -4775,12 +4692,7 @@ bool wxRichTextBuffer::InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int
p = & paraAttr;
}
#if wxRICHTEXT_USE_DYNAMIC_STYLES
wxTextAttrEx attr(GetDefaultStyle());
#else
wxTextAttrEx attr(GetBasicStyle());
wxRichTextApplyStyle(attr, GetDefaultStyle());
#endif
wxRichTextParagraph* newPara = new wxRichTextParagraph(wxEmptyString, this, & attr);
action->GetNewParagraphs().AppendChild(newPara);
@@ -4813,12 +4725,7 @@ bool wxRichTextBuffer::InsertImageWithUndo(long pos, const wxRichTextImageBlock&
p = & paraAttr;
}
#if wxRICHTEXT_USE_DYNAMIC_STYLES
wxTextAttrEx attr(GetDefaultStyle());
#else
wxTextAttrEx attr(GetBasicStyle());
wxRichTextApplyStyle(attr, GetDefaultStyle());
#endif
wxRichTextParagraph* newPara = new wxRichTextParagraph(this, & attr);
if (p)
@@ -6054,13 +5961,21 @@ bool wxRichTextAction::Do()
if (m_newParagraphs.GetPartialParagraph())
newCaretPosition --;
newCaretPosition = wxMin(newCaretPosition, (m_buffer->GetRange().GetEnd()-1));
newCaretPosition = wxMin(newCaretPosition, (m_buffer->GetRange().GetEnd()-1));
if (optimizationLineCharPositions.GetCount() > 0)
UpdateAppearance(newCaretPosition, true /* send update event */, & optimizationLineCharPositions, & optimizationLineYPositions);
else
UpdateAppearance(newCaretPosition, true /* send update event */);
wxRichTextEvent cmdEvent(
wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED,
m_ctrl ? m_ctrl->GetId() : -1);
cmdEvent.SetEventObject(m_ctrl ? (wxObject*) m_ctrl : (wxObject*) m_buffer);
cmdEvent.SetRange(GetRange());
cmdEvent.SetPosition(GetRange().GetStart());
m_buffer->SendEvent(cmdEvent);
break;
}
@@ -6072,6 +5987,15 @@ bool wxRichTextAction::Do()
UpdateAppearance(GetRange().GetStart()-1, true /* send update event */);
wxRichTextEvent cmdEvent(
wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED,
m_ctrl ? m_ctrl->GetId() : -1);
cmdEvent.SetEventObject(m_ctrl ? (wxObject*) m_ctrl : (wxObject*) m_buffer);
cmdEvent.SetRange(GetRange());
cmdEvent.SetPosition(GetRange().GetStart());
m_buffer->SendEvent(cmdEvent);
break;
}
case wxRICHTEXT_CHANGE_STYLE:
@@ -6081,6 +6005,15 @@ bool wxRichTextAction::Do()
UpdateAppearance(GetPosition());
wxRichTextEvent cmdEvent(
wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED,
m_ctrl ? m_ctrl->GetId() : -1);
cmdEvent.SetEventObject(m_ctrl ? (wxObject*) m_ctrl : (wxObject*) m_buffer);
cmdEvent.SetRange(GetRange());
cmdEvent.SetPosition(GetRange().GetStart());
m_buffer->SendEvent(cmdEvent);
break;
}
default:
@@ -6103,11 +6036,18 @@ bool wxRichTextAction::Undo()
m_buffer->Invalidate(wxRichTextRange(GetRange().GetStart(), GetRange().GetStart()));
long newCaretPosition = GetPosition() - 1;
// if (m_newParagraphs.GetPartialParagraph())
// newCaretPosition --;
UpdateAppearance(newCaretPosition, true /* send update event */);
wxRichTextEvent cmdEvent(
wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED,
m_ctrl ? m_ctrl->GetId() : -1);
cmdEvent.SetEventObject(m_ctrl ? (wxObject*) m_ctrl : (wxObject*) m_buffer);
cmdEvent.SetRange(GetRange());
cmdEvent.SetPosition(GetRange().GetStart());
m_buffer->SendEvent(cmdEvent);
break;
}
case wxRICHTEXT_DELETE:
@@ -6118,6 +6058,15 @@ bool wxRichTextAction::Undo()
UpdateAppearance(GetPosition(), true /* send update event */);
wxRichTextEvent cmdEvent(
wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED,
m_ctrl ? m_ctrl->GetId() : -1);
cmdEvent.SetEventObject(m_ctrl ? (wxObject*) m_ctrl : (wxObject*) m_buffer);
cmdEvent.SetRange(GetRange());
cmdEvent.SetPosition(GetRange().GetStart());
m_buffer->SendEvent(cmdEvent);
break;
}
case wxRICHTEXT_CHANGE_STYLE:
@@ -6127,6 +6076,15 @@ bool wxRichTextAction::Undo()
UpdateAppearance(GetPosition());
wxRichTextEvent cmdEvent(
wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED,
m_ctrl ? m_ctrl->GetId() : -1);
cmdEvent.SetEventObject(m_ctrl ? (wxObject*) m_ctrl : (wxObject*) m_buffer);
cmdEvent.SetRange(GetRange());
cmdEvent.SetPosition(GetRange().GetStart());
m_buffer->SendEvent(cmdEvent);
break;
}
default:

View File

@@ -37,18 +37,24 @@
#include "wx/app.h"
WX_CHECK_BUILD_OPTIONS("wxRichTextCtrl")
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_ITEM_SELECTED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_LEFT_CLICK)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_MIDDLE_CLICK)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_RETURN)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_CHARACTER)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_DELETE)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGING)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_STYLESHEET_CHANGED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_SELECTION_CHANGED)
IMPLEMENT_CLASS( wxRichTextCtrl, wxControl )
IMPLEMENT_CLASS( wxRichTextEvent, wxNotifyEvent )
@@ -561,6 +567,8 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event)
GetId());
cmdEvent.SetEventObject(this);
cmdEvent.SetFlags(flags);
cmdEvent.SetPosition(newPos+1);
if (!GetEventHandler()->ProcessEvent(cmdEvent))
{
// Generate conventional event
@@ -574,7 +582,7 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event)
else if (event.GetKeyCode() == WXK_BACK)
{
BeginBatchUndo(_("Delete Text"));
// Submit range in character positions, which are greater than caret positions,
// so subtract 1 for deleted character and add 1 for conversion to character position.
if (m_caretPosition > -1 && !HasSelection())
@@ -599,6 +607,15 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event)
}
ScrollIntoView(m_caretPosition, WXK_LEFT);
wxRichTextEvent cmdEvent(
wxEVT_COMMAND_RICHTEXT_DELETE,
GetId());
cmdEvent.SetEventObject(this);
cmdEvent.SetFlags(flags);
cmdEvent.SetPosition(m_caretPosition+1);
GetEventHandler()->ProcessEvent(cmdEvent);
Update();
}
else if (event.GetKeyCode() == WXK_DELETE)
@@ -626,6 +643,15 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event)
PositionCaret();
SetDefaultStyleToCursorStyle();
}
wxRichTextEvent cmdEvent(
wxEVT_COMMAND_RICHTEXT_DELETE,
GetId());
cmdEvent.SetEventObject(this);
cmdEvent.SetFlags(flags);
cmdEvent.SetPosition(m_caretPosition+1);
GetEventHandler()->ProcessEvent(cmdEvent);
Update();
}
else
@@ -741,6 +767,14 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event)
return;
}
wxRichTextEvent cmdEvent(
wxEVT_COMMAND_RICHTEXT_CHARACTER,
GetId());
cmdEvent.SetEventObject(this);
cmdEvent.SetFlags(flags);
cmdEvent.SetCharacter((wxChar) keycode);
cmdEvent.SetPosition(m_caretPosition+1);
if (keycode == wxT('\t'))
{
// See if we need to promote or demote the selection or paragraph at the cursor
@@ -759,6 +793,8 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event)
PromoteList(promoteBy, range, NULL);
GetEventHandler()->ProcessEvent(cmdEvent);
return;
}
}
@@ -775,6 +811,9 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event)
SetDefaultStyleToCursorStyle();
ScrollIntoView(m_caretPosition, WXK_RIGHT);
GetEventHandler()->ProcessEvent(cmdEvent);
Update();
}
}
@@ -2525,7 +2564,6 @@ bool wxRichTextCtrl::GetStyle(long position, wxRichTextAttr& style)
return GetBuffer().GetStyle(position, style);
}
/*
// get the common set of styles for the range
bool wxRichTextCtrl::GetStyleForRange(const wxRichTextRange& range, wxRichTextAttr& style)
{
@@ -2543,7 +2581,6 @@ bool wxRichTextCtrl::GetStyleForRange(const wxRichTextRange& range, wxTextAttrEx
{
return GetBuffer().GetStyleForRange(range.ToInternal(), style);
}
*/
/// Get the content (uncombined) attributes for this position.
@@ -2957,11 +2994,7 @@ bool wxRichTextCtrl::SetDefaultStyleToCursorStyle()
// If at the start of a paragraph, use the next position.
long pos = GetAdjustedCaretPosition(GetCaretPosition());
#if wxRICHTEXT_USE_DYNAMIC_STYLES
if (GetUncombinedStyle(pos, attr))
#else
if (GetStyle(pos, attr))
#endif
{
SetDefaultStyle(attr);
return true;