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
This commit is contained in:
Julian Smart
2006-07-03 21:13:18 +00:00
parent 27b12131a6
commit 27e20452c4
5 changed files with 60 additions and 7 deletions

View File

@@ -263,6 +263,7 @@ class WXDLLIMPEXP_RICHTEXT wxTextAttrEx: public wxTextAttr
public: public:
// ctors // ctors
wxTextAttrEx(const wxTextAttrEx& attr); wxTextAttrEx(const wxTextAttrEx& attr);
wxTextAttrEx(const wxTextAttr& attr) { Init(); (*this) = attr; }
wxTextAttrEx() { Init(); } wxTextAttrEx() { Init(); }
// Initialise this object. // Initialise this object.

View File

@@ -98,14 +98,14 @@ public:
// Constructors // Constructors
wxRichTextCtrl( ); 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 ); long style = wxRE_MULTILINE );
~wxRichTextCtrl( ); ~wxRichTextCtrl( );
// Operations // Operations
/// Creation /// 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 ); long style = wxRE_MULTILINE );
/// Member initialisation /// Member initialisation
@@ -175,14 +175,18 @@ public:
// text control under some platforms supports the text styles: these // text control under some platforms supports the text styles: these
// methods allow to apply the given text style to the given selection or to // 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 // 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(long start, long end, const wxTextAttrEx& style);
virtual bool SetStyle(const wxRichTextRange& range, const wxRichTextAttr& 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, wxTextAttrEx& style) const;
virtual bool GetStyle(long position, wxRichTextAttr& style) const; virtual bool GetStyle(long position, wxRichTextAttr& style) const;
virtual bool SetDefaultStyle(const wxTextAttrEx& style); virtual bool SetDefaultStyle(const wxTextAttrEx& style);
virtual bool SetDefaultStyle(const wxTextAttr& style);
// TODO: change to GetDefaultStyle if we merge wxTextAttr and wxTextAttrEx // TODO: change to GetDefaultStyle if we merge wxTextAttr and wxTextAttrEx
virtual const wxTextAttrEx& GetDefaultStyleEx() const; virtual const wxTextAttrEx& GetDefaultStyleEx() const;
virtual const wxTextAttr& GetDefaultStyle() const;
// translate between the position (which is just an index in the text ctrl // 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 // considering all its contents as a single strings) and (x, y) coordinates

View File

@@ -312,6 +312,20 @@ void MyApp::CreateStyles()
m_styleSheet->AddParagraphStyle(indentedPara); 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")); wxRichTextParagraphStyleDefinition* flIndentedPara = new wxRichTextParagraphStyleDefinition(wxT("First Line Indented"));
wxRichTextAttr flIndentedAttr; wxRichTextAttr flIndentedAttr;
flIndentedAttr.SetFontFaceName(swissFont.GetFaceName()); 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 boldFont = wxFont(12, wxROMAN, wxNORMAL, wxBOLD);
wxFont italicFont = wxFont(12, wxROMAN, wxITALIC, wxNORMAL); 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); wxFont font(12, wxROMAN, wxNORMAL, wxNORMAL);
m_richTextCtrl->SetFont(font); m_richTextCtrl->SetFont(font);

View File

@@ -1411,7 +1411,7 @@ wxString wxRichTextParagraphLayoutBox::GetText() const
/// Get the paragraph by number /// Get the paragraph by number
wxRichTextParagraph* wxRichTextParagraphLayoutBox::GetParagraphAtLine(long paragraphNumber) const wxRichTextParagraph* wxRichTextParagraphLayoutBox::GetParagraphAtLine(long paragraphNumber) const
{ {
if ((size_t) paragraphNumber <= GetChildCount()) if ((size_t) paragraphNumber >= GetChildCount())
return NULL; return NULL;
return (wxRichTextParagraph*) GetChild((size_t) paragraphNumber); return (wxRichTextParagraph*) GetChild((size_t) paragraphNumber);

View File

@@ -31,6 +31,10 @@
#include "wx/dcbuffer.h" #include "wx/dcbuffer.h"
#include "wx/arrimpl.cpp" #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_SELECTED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED) DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_ITEM_DESELECTED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_LEFT_CLICK) DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_LEFT_CLICK)
@@ -102,17 +106,17 @@ wxRichTextCtrl::wxRichTextCtrl()
Init(); 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 #if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
: wxScrollHelper(this) : wxScrollHelper(this)
#endif #endif
{ {
Init(); Init();
Create(parent, id, pos, size, style); Create(parent, id, value, pos, size, style);
} }
/// Creation /// 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 wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
if (!wxTextCtrlBase::Create(parent, id, pos, size, style|wxFULL_REPAINT_ON_RESIZE 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); RecreateBuffer(size);
SetCursor(wxCursor(wxCURSOR_IBEAM)); SetCursor(wxCursor(wxCURSOR_IBEAM));
if (!value.IsEmpty())
SetValue(value);
return true; return true;
} }
@@ -2177,6 +2184,11 @@ bool wxRichTextCtrl::SetStyle(long start, long end, const wxTextAttrEx& style)
return GetBuffer().SetStyle(wxRichTextRange(start, end), 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) bool wxRichTextCtrl::SetStyle(const wxRichTextRange& range, const wxRichTextAttr& style)
{ {
return GetBuffer().SetStyle(range, style); return GetBuffer().SetStyle(range, style);
@@ -2187,11 +2199,33 @@ bool wxRichTextCtrl::SetDefaultStyle(const wxTextAttrEx& style)
return GetBuffer().SetDefaultStyle(style); return GetBuffer().SetDefaultStyle(style);
} }
bool wxRichTextCtrl::SetDefaultStyle(const wxTextAttr& style)
{
return GetBuffer().SetDefaultStyle(wxTextAttrEx(style));
}
const wxTextAttrEx& wxRichTextCtrl::GetDefaultStyleEx() const const wxTextAttrEx& wxRichTextCtrl::GetDefaultStyleEx() const
{ {
return GetBuffer().GetDefaultStyle(); 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 bool wxRichTextCtrl::GetStyle(long position, wxTextAttrEx& style) const
{ {
return GetBuffer().GetStyle(position, style); return GetBuffer().GetStyle(position, style);