From: Julian Smart Date: Mon, 3 Jul 2006 21:13:18 +0000 (+0000) Subject: SetStyle/GetStyle corrections X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/27e20452c4931a0af2fc61e649476e03aecb54f9?ds=inline SetStyle/GetStyle corrections Added compatibility ctor to wxTextAttrEx wxRichTextCtrl should take a string value for wxTextCtrl compatibility git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39961 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/richtext/richtextbuffer.h b/include/wx/richtext/richtextbuffer.h index 2524265d7d..38c3b901c0 100644 --- a/include/wx/richtext/richtextbuffer.h +++ b/include/wx/richtext/richtextbuffer.h @@ -263,6 +263,7 @@ class WXDLLIMPEXP_RICHTEXT wxTextAttrEx: public wxTextAttr public: // ctors wxTextAttrEx(const wxTextAttrEx& attr); + wxTextAttrEx(const wxTextAttr& attr) { Init(); (*this) = attr; } wxTextAttrEx() { Init(); } // Initialise this object. diff --git a/include/wx/richtext/richtextctrl.h b/include/wx/richtext/richtextctrl.h index e4c9aeef51..5e6f37cb9c 100644 --- a/include/wx/richtext/richtextctrl.h +++ b/include/wx/richtext/richtextctrl.h @@ -98,14 +98,14 @@ public: // Constructors wxRichTextCtrl( ); - wxRichTextCtrl( wxWindow* parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, + 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 wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, + 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 @@ -175,14 +175,18 @@ public: // 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 diff --git a/samples/richtext/richtext.cpp b/samples/richtext/richtext.cpp index 20f0fa7576..bf3bb2ae97 100644 --- a/samples/richtext/richtext.cpp +++ b/samples/richtext/richtext.cpp @@ -312,6 +312,20 @@ void MyApp::CreateStyles() m_styleSheet->AddParagraphStyle(indentedPara); + wxRichTextParagraphStyleDefinition* indentedPara2 = new wxRichTextParagraphStyleDefinition(wxT("Red Bold Indented")); + wxRichTextAttr indentedAttr2; + indentedAttr2.SetFontFaceName(romanFont.GetFaceName()); + indentedAttr2.SetFontSize(12); + indentedAttr2.SetFontWeight(wxBOLD); + indentedAttr2.SetTextColour(*wxRED); + indentedAttr2.SetFontSize(12); + indentedAttr2.SetLeftIndent(100, 0); + // We want to affect indentation, font and text colour + indentedAttr2.SetFlags(wxTEXT_ATTR_LEFT_INDENT|wxTEXT_ATTR_RIGHT_INDENT|wxTEXT_ATTR_FONT|wxTEXT_ATTR_TEXT_COLOUR); + indentedPara2->SetStyle(indentedAttr2); + + m_styleSheet->AddParagraphStyle(indentedPara2); + wxRichTextParagraphStyleDefinition* flIndentedPara = new wxRichTextParagraphStyleDefinition(wxT("First Line Indented")); wxRichTextAttr flIndentedAttr; flIndentedAttr.SetFontFaceName(swissFont.GetFaceName()); @@ -475,7 +489,7 @@ MyFrame::MyFrame(const wxString& title, wxWindowID id, const wxPoint& pos, wxFont boldFont = wxFont(12, wxROMAN, wxNORMAL, wxBOLD); wxFont italicFont = wxFont(12, wxROMAN, wxITALIC, wxNORMAL); - m_richTextCtrl = new wxRichTextCtrl(splitter, wxID_ANY, wxDefaultPosition, wxSize(200, 200), wxVSCROLL|wxHSCROLL|wxNO_BORDER|wxWANTS_CHARS); + m_richTextCtrl = new wxRichTextCtrl(splitter, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200, 200), wxVSCROLL|wxHSCROLL|wxNO_BORDER|wxWANTS_CHARS); wxFont font(12, wxROMAN, wxNORMAL, wxNORMAL); m_richTextCtrl->SetFont(font); diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index 40b51cc5df..13a67f7c69 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -1411,7 +1411,7 @@ wxString wxRichTextParagraphLayoutBox::GetText() const /// Get the paragraph by number wxRichTextParagraph* wxRichTextParagraphLayoutBox::GetParagraphAtLine(long paragraphNumber) const { - if ((size_t) paragraphNumber <= GetChildCount()) + if ((size_t) paragraphNumber >= GetChildCount()) return NULL; return (wxRichTextParagraph*) GetChild((size_t) paragraphNumber); diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index 7503b9ece1..0bb40c3e34 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -31,6 +31,10 @@ #include "wx/dcbuffer.h" #include "wx/arrimpl.cpp" +// DLL options compatibility check: +#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) @@ -102,17 +106,17 @@ wxRichTextCtrl::wxRichTextCtrl() Init(); } -wxRichTextCtrl::wxRichTextCtrl( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) +wxRichTextCtrl::wxRichTextCtrl( wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style) #if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE : wxScrollHelper(this) #endif { Init(); - Create(parent, id, pos, size, style); + Create(parent, id, value, pos, size, style); } /// Creation -bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) +bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style) { #if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE if (!wxTextCtrlBase::Create(parent, id, pos, size, style|wxFULL_REPAINT_ON_RESIZE @@ -151,6 +155,9 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos RecreateBuffer(size); SetCursor(wxCursor(wxCURSOR_IBEAM)); + + if (!value.IsEmpty()) + SetValue(value); return true; } @@ -2177,6 +2184,11 @@ bool wxRichTextCtrl::SetStyle(long start, long end, const wxTextAttrEx& style) return GetBuffer().SetStyle(wxRichTextRange(start, end), style); } +bool wxRichTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) +{ + return GetBuffer().SetStyle(wxRichTextRange(start, end), wxTextAttrEx(style)); +} + bool wxRichTextCtrl::SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style) { return GetBuffer().SetStyle(range, style); @@ -2187,11 +2199,33 @@ bool wxRichTextCtrl::SetDefaultStyle(const wxTextAttrEx& style) return GetBuffer().SetDefaultStyle(style); } +bool wxRichTextCtrl::SetDefaultStyle(const wxTextAttr& style) +{ + return GetBuffer().SetDefaultStyle(wxTextAttrEx(style)); +} + const wxTextAttrEx& wxRichTextCtrl::GetDefaultStyleEx() const { return GetBuffer().GetDefaultStyle(); } +const wxTextAttr& wxRichTextCtrl::GetDefaultStyle() const +{ + return GetBuffer().GetDefaultStyle(); +} + +bool wxRichTextCtrl::GetStyle(long position, wxTextAttr& style) const +{ + wxTextAttrEx attr; + if (GetBuffer().GetStyle(position, attr)) + { + style = attr; + return true; + } + else + return false; +} + bool wxRichTextCtrl::GetStyle(long position, wxTextAttrEx& style) const { return GetBuffer().GetStyle(position, style);