Added a reset-buffer event to give an opportunity to set the default initial style

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51494 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart 2008-02-01 14:14:44 +00:00
parent 144ae5bbbf
commit cd8ba0d9e4
4 changed files with 19 additions and 6 deletions

View File

@ -24,6 +24,7 @@ function that takes a wxRichTextEvent argument.
\twocolitem{{\bf EVT\_RICHTEXT\_STYLESHEET\_REPLACED(id, func)}}{Process a wxEVT\_COMMAND\_RICHTEXT\_STYLESHEET\_REPLACED event, generated when the control's stylesheet has been replaced, for example when a file is loaded into the control. Valid event functions: GetOldStyleSheet, GetNewStyleSheet.}
\twocolitem{{\bf EVT\_RICHTEXT\_CONTENT\_INSERTED(id, func)}}{Process a wxEVT\_COMMAND\_RICHTEXT\_CONTENT\_INSERTED event, generated when content has been inserted into the control. Valid event functions: GetPosition, GetRange.}
\twocolitem{{\bf EVT\_RICHTEXT\_CONTENT\_DELETED(id, func)}}{Process a wxEVT\_COMMAND\_RICHTEXT\_CONTENT\_DELETED event, generated when content has been deleted from the control. Valid event functions: GetPosition, GetRange.}
\twocolitem{{\bf EVT\_RICHTEXT\_BUFFER\_RESET(id, func)}}{Process a wxEVT\_COMMAND\_RICHTEXT\_BUFFER\_RESET event, generated when the buffer has been reset by deleting all content. You can use this to set a default style for the first new paragraph.}
\end{twocollist}%
\wxheading{Derived from}

View File

@ -894,6 +894,7 @@ extern WXDLLIMPEXP_RICHTEXT const wxEventType wxEVT_COMMAND_RICHTEXT_CONTENT_INS
extern WXDLLIMPEXP_RICHTEXT const wxEventType wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED;
extern WXDLLIMPEXP_RICHTEXT const wxEventType wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED;
extern WXDLLIMPEXP_RICHTEXT const wxEventType wxEVT_COMMAND_RICHTEXT_SELECTION_CHANGED;
extern WXDLLIMPEXP_RICHTEXT const wxEventType wxEVT_COMMAND_RICHTEXT_BUFFER_RESET;
typedef void (wxEvtHandler::*wxRichTextEventFunction)(wxRichTextEvent&);
@ -917,6 +918,7 @@ typedef void (wxEvtHandler::*wxRichTextEventFunction)(wxRichTextEvent&);
#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 ),
#define EVT_RICHTEXT_BUFFER_RESET(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_RICHTEXT_BUFFER_RESET, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxRichTextEventFunction, & fn ), NULL ),
#endif
// wxUSE_RICHTEXT

View File

@ -2419,6 +2419,15 @@ void wxRichTextParagraphLayoutBox::Reset()
{
Clear();
wxRichTextBuffer* buffer = wxDynamicCast(this, wxRichTextBuffer);
if (buffer && GetRichTextCtrl())
{
wxRichTextEvent event(wxEVT_COMMAND_RICHTEXT_BUFFER_RESET, GetRichTextCtrl()->GetId());
event.SetEventObject(GetRichTextCtrl());
buffer->SendEvent(event, true);
}
AddParagraph(wxEmptyString);
Invalidate(wxRICHTEXT_ALL);

View File

@ -54,6 +54,7 @@ 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)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_BUFFER_RESET)
IMPLEMENT_CLASS( wxRichTextCtrl, wxControl )
@ -140,12 +141,6 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& va
SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
}
GetBuffer().Reset();
GetBuffer().SetRichTextCtrl(this);
SetCaret(new wxCaret(this, wxRICHTEXT_DEFAULT_CARET_WIDTH, 16));
GetCaret()->Show();
if (style & wxTE_READONLY)
SetEditable(false);
@ -170,6 +165,12 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& va
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
SetBackgroundStyle(wxBG_STYLE_CUSTOM);
GetBuffer().Reset();
GetBuffer().SetRichTextCtrl(this);
SetCaret(new wxCaret(this, wxRICHTEXT_DEFAULT_CARET_WIDTH, 16));
GetCaret()->Show();
// Tell the sizers to use the given or best size
SetInitialSize(size);