Made column and row spans members so they don't interfere with app-defined properties.

Added identifier to wxRichTextObject so objects can be addressed by name.
Generalised wxRICHTEXT_CHANGE_OBJECT command so it can now apply to a paragraph as well as an object within a paragraph.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75124 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2013-11-04 15:13:41 +00:00
parent 3ee8ea054e
commit 254eb6841a
5 changed files with 112 additions and 44 deletions

View File

@@ -2746,6 +2746,16 @@ public:
*/ */
bool IsShown() const { return m_show; } bool IsShown() const { return m_show; }
/**
Returns the object's unique identifier, if any.
*/
const wxString& GetId() const { return m_id; }
/**
Sets the object's unique identifier.
*/
void SetId(const wxString& id) { m_id = id; }
// Operations // Operations
/** /**
@@ -2844,6 +2854,7 @@ protected:
int m_descent; // Descent for this object (if any) int m_descent; // Descent for this object (if any)
int m_refCount; int m_refCount;
bool m_show; bool m_show;
wxString m_id;
wxRichTextObject* m_parent; wxRichTextObject* m_parent;
// The range of this object (start position to end position) // The range of this object (start position to end position)
@@ -5690,13 +5701,25 @@ public:
// Accessors // Accessors
int GetColSpan() const; /**
Returns the column span. The default is 1.
*/
int GetColSpan() const { return m_colSpan; }
void SetColSpan(long span) { GetProperties().SetProperty(wxT("colspan"), span); } /**
Sets the column span.
*/
void SetColSpan(int span);
int GetRowSpan() const; /**
Returns the row span. The default is 1.
*/
int GetRowSpan() const { return m_rowSpan; }
void SetRowSpan(long span) { GetProperties().SetProperty(wxT("rowspan"), span); } /**
Sets the row span.
*/
void SetRowSpan(int span);
// Operations // Operations
@@ -5705,6 +5728,8 @@ public:
void Copy(const wxRichTextCell& obj); void Copy(const wxRichTextCell& obj);
protected: protected:
int m_colSpan;
int m_rowSpan;
}; };
/** /**

View File

@@ -2588,6 +2588,16 @@ public:
*/ */
bool IsShown() const; bool IsShown() const;
/**
Returns the object's unique identifier, if any.
*/
const wxString& GetId() const;
/**
Sets the object's unique identifier.
*/
void SetId(const wxString& id);
// Operations // Operations
/** /**

View File

@@ -531,6 +531,7 @@ void wxRichTextObject::Copy(const wxRichTextObject& obj)
m_properties = obj.m_properties; m_properties = obj.m_properties;
m_descent = obj.m_descent; m_descent = obj.m_descent;
m_show = obj.m_show; m_show = obj.m_show;
m_id = obj.m_id;
} }
// Get/set the top-level container of this object. // Get/set the top-level container of this object.
@@ -9389,6 +9390,8 @@ IMPLEMENT_DYNAMIC_CLASS(wxRichTextCell, wxRichTextBox)
wxRichTextCell::wxRichTextCell(wxRichTextObject* parent): wxRichTextCell::wxRichTextCell(wxRichTextObject* parent):
wxRichTextBox(parent) wxRichTextBox(parent)
{ {
m_colSpan = 1;
m_rowSpan = 1;
} }
/// Draw the item /// Draw the item
@@ -9561,6 +9564,23 @@ bool wxRichTextCell::AdjustAttributes(wxRichTextAttr& attr, wxRichTextDrawingCon
void wxRichTextCell::Copy(const wxRichTextCell& obj) void wxRichTextCell::Copy(const wxRichTextCell& obj)
{ {
wxRichTextBox::Copy(obj); wxRichTextBox::Copy(obj);
m_colSpan = obj.m_colSpan;
m_rowSpan = obj.m_rowSpan;
}
void wxRichTextCell::SetColSpan(int span)
{
wxASSERT(span >= 1);
if (span >= 1)
m_colSpan = span;
}
void wxRichTextCell::SetRowSpan(int span)
{
wxASSERT(span >= 1);
if (span >= 1)
m_rowSpan = span;
} }
// Edit properties via a GUI // Edit properties via a GUI
@@ -9643,29 +9663,6 @@ bool wxRichTextCell::EditProperties(wxWindow* parent, wxRichTextBuffer* buffer)
return false; return false;
} }
// The next 2 methods return span values. Note that the default is 1, not 0
int wxRichTextCell::GetColSpan() const
{
int span = 1;
if (GetProperties().HasProperty(wxT("colspan")))
{
span = GetProperties().GetPropertyLong(wxT("colspan"));
}
return span;
}
int wxRichTextCell::GetRowSpan() const
{
int span = 1;
if (GetProperties().HasProperty(wxT("rowspan")))
{
span = GetProperties().GetPropertyLong(wxT("rowspan"));
}
return span;
}
WX_DEFINE_OBJARRAY(wxRichTextObjectPtrArrayArray) WX_DEFINE_OBJARRAY(wxRichTextObjectPtrArrayArray)
IMPLEMENT_DYNAMIC_CLASS(wxRichTextTable, wxRichTextBox) IMPLEMENT_DYNAMIC_CLASS(wxRichTextTable, wxRichTextBox)
@@ -11574,21 +11571,29 @@ bool wxRichTextAction::Do()
// The plan is to swap the current object with the stored, previous-state, clone // The plan is to swap the current object with the stored, previous-state, clone
// We can't get 'node' from the containing buffer (as it doesn't directly store objects) // We can't get 'node' from the containing buffer (as it doesn't directly store objects)
// so use the parent paragraph // so use the parent paragraph
wxRichTextParagraph* para = wxDynamicCast(obj->GetParent(), wxRichTextParagraph); wxRichTextCompositeObject* parent = wxDynamicCast(obj->GetParent(), wxRichTextCompositeObject);
wxCHECK_MSG(para, false, "Invalid parent paragraph"); wxCHECK_MSG(parent, false, wxT("Invalid parent"));
// The stored object, m_object, may have a stale parent paragraph. This would cause // Check that at least one is a paragraph, but not both.
// a crash during layout, so use obj's parent para, which should be the correct one. wxCHECK_MSG((!obj->IsKindOf(CLASSINFO(wxRichTextParagraph)) && parent->IsKindOf(CLASSINFO(wxRichTextParagraph))) ||
(obj->IsKindOf(CLASSINFO(wxRichTextParagraph)) && !parent->IsKindOf(CLASSINFO(wxRichTextParagraph)))
, false, wxT("Either the object or the parent must be a paragraph"));
// The stored object, m_object, may have a stale parent. This would cause
// a crash during layout, so use obj's parent, which should be the correct one.
// (An alternative would be to return the parent too from m_objectAddress.GetObject(), // (An alternative would be to return the parent too from m_objectAddress.GetObject(),
// or to set obj's parent there before returning) // or to set obj's parent there before returning)
m_object->SetParent(para); m_object->SetParent(parent);
if (parent)
wxRichTextObjectList::compatibility_iterator node = para->GetChildren().Find(obj); {
wxRichTextObjectList::compatibility_iterator node = parent->GetChildren().Find(obj);
if (node) if (node)
{ {
wxRichTextObject* obj = node->GetData(); wxRichTextObject* obj = node->GetData();
node->SetData(m_object); node->SetData(m_object);
m_object = obj; m_object = obj;
m_object->SetParent(NULL);
}
} }
} }

View File

@@ -474,7 +474,7 @@
<long name="locked">0</long> <long name="locked">0</long>
<string name="created">"2/10/2006"</string> <string name="created">"2/10/2006"</string>
<string name="proxy-type">"wbTextCtrlProxy"</string> <string name="proxy-type">"wbTextCtrlProxy"</string>
<string name="event-handler-0">"wxEVT_COMMAND_TEXT_UPDATED|OnFaceTextCtrlUpdated"</string> <string name="event-handler-0">"wxEVT_COMMAND_TEXT_UPDATED|OnFaceTextCtrlUpdated|||wxRichTextFontPage"</string>
<string name="proxy-Id name">"ID_RICHTEXTFONTPAGE_FACETEXTCTRL"</string> <string name="proxy-Id name">"ID_RICHTEXTFONTPAGE_FACETEXTCTRL"</string>
<long name="proxy-Id value">10001</long> <long name="proxy-Id value">10001</long>
<string name="proxy-Name">""</string> <string name="proxy-Name">""</string>
@@ -7306,11 +7306,11 @@
<long name="locked">0</long> <long name="locked">0</long>
<string name="created">"25/10/2006"</string> <string name="created">"25/10/2006"</string>
<string name="proxy-type">"wbSpinCtrlProxy"</string> <string name="proxy-type">"wbSpinCtrlProxy"</string>
<string name="event-handler-0">"wxEVT_COMMAND_SPINCTRL_UPDATED|OnNumberctrlUpdated"</string> <string name="event-handler-0">"wxEVT_COMMAND_SPINCTRL_UPDATED|OnNumberctrlUpdated|||wxRichTextBulletsPage"</string>
<string name="event-handler-1">"wxEVT_SCROLL_LINEUP|OnNumberctrlUp"</string> <string name="event-handler-1">"wxEVT_SCROLL_LINEUP|OnNumberctrlUp|||"</string>
<string name="event-handler-2">"wxEVT_SCROLL_LINEDOWN|OnNumberctrlDown"</string> <string name="event-handler-2">"wxEVT_SCROLL_LINEDOWN|OnNumberctrlDown|||"</string>
<string name="event-handler-3">"wxEVT_COMMAND_TEXT_UPDATED|OnNumberctrlTextUpdated"</string> <string name="event-handler-3">"wxEVT_COMMAND_TEXT_UPDATED|OnNumberctrlTextUpdated|||"</string>
<string name="event-handler-4">"wxEVT_UPDATE_UI|OnNumberctrlUpdate"</string> <string name="event-handler-4">"wxEVT_UPDATE_UI|OnNumberctrlUpdate|||"</string>
<string name="proxy-Id name">"ID_RICHTEXTBULLETSPAGE_NUMBERCTRL"</string> <string name="proxy-Id name">"ID_RICHTEXTBULLETSPAGE_NUMBERCTRL"</string>
<long name="proxy-Id value">10310</long> <long name="proxy-Id value">10310</long>
<string name="proxy-Name">""</string> <string name="proxy-Name">""</string>

View File

@@ -352,6 +352,7 @@ bool wxRichTextObject::ImportFromXML(wxRichTextBuffer* WXUNUSED(buffer), wxXmlNo
wxString value = node->GetAttribute(wxT("show"), wxEmptyString); wxString value = node->GetAttribute(wxT("show"), wxEmptyString);
if (!value.IsEmpty()) if (!value.IsEmpty())
Show(value == wxT("1")); Show(value == wxT("1"));
SetId(node->GetAttribute(wxT("id"), wxEmptyString));
*recurse = true; *recurse = true;
@@ -368,6 +369,8 @@ bool wxRichTextObject::ExportXML(wxOutputStream& stream, int indent, wxRichTextX
wxString style = handler->GetHelper().AddAttributes(GetAttributes(), true); wxString style = handler->GetHelper().AddAttributes(GetAttributes(), true);
if (!IsShown()) if (!IsShown())
style << wxT(" show=\"0\""); style << wxT(" show=\"0\"");
if (!GetId().IsEmpty())
style << wxT(" id=\"") << handler->GetHelper().AttributeToXML(GetId()) << wxT("\"");
handler->GetHelper().OutputString(stream, style + wxT(">")); handler->GetHelper().OutputString(stream, style + wxT(">"));
@@ -403,6 +406,8 @@ bool wxRichTextObject::ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handle
handler->GetHelper().WriteProperties(elementNode, GetProperties()); handler->GetHelper().WriteProperties(elementNode, GetProperties());
if (!IsShown()) if (!IsShown())
elementNode->AddAttribute(wxT("show"), wxT("0")); elementNode->AddAttribute(wxT("show"), wxT("0"));
if (!GetId().IsEmpty())
elementNode->AddAttribute(wxT("id"), GetId());
wxRichTextCompositeObject* composite = wxDynamicCast(this, wxRichTextCompositeObject); wxRichTextCompositeObject* composite = wxDynamicCast(this, wxRichTextCompositeObject);
if (composite) if (composite)
@@ -840,6 +845,15 @@ bool wxRichTextParagraphLayoutBox::ImportFromXML(wxRichTextBuffer* buffer, wxXml
if (partial == wxT("true")) if (partial == wxT("true"))
SetPartialParagraph(true); SetPartialParagraph(true);
wxRichTextCell* cell = wxDynamicCast(this, wxRichTextCell);
if (cell)
{
if (node->HasAttribute(wxT("colspan")))
cell->SetColSpan(wxAtoi(node->GetAttribute(wxT("colspan"), wxEmptyString)));
if (node->HasAttribute(wxT("rowspan")))
cell->SetRowSpan(wxAtoi(node->GetAttribute(wxT("rowspan"), wxEmptyString)));
}
wxXmlNode* child = handler->GetHelper().FindNode(node, wxT("stylesheet")); wxXmlNode* child = handler->GetHelper().FindNode(node, wxT("stylesheet"));
if (child && (handler->GetFlags() & wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET)) if (child && (handler->GetFlags() & wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET))
{ {
@@ -880,6 +894,13 @@ bool wxRichTextParagraphLayoutBox::ExportXML(wxOutputStream& stream, int indent,
if (GetPartialParagraph()) if (GetPartialParagraph())
style << wxT(" partialparagraph=\"true\""); style << wxT(" partialparagraph=\"true\"");
wxRichTextCell* cell = wxDynamicCast(this, wxRichTextCell);
if (cell)
{
style << wxT(" colspan=\"") << wxString::Format(wxT("%d"), cell->GetColSpan()) << wxT("\"");
style << wxT(" rowspan=\"") << wxString::Format(wxT("%d"), cell->GetRowSpan()) << wxT("\"");
}
handler->GetHelper().OutputString(stream, style + wxT(">")); handler->GetHelper().OutputString(stream, style + wxT(">"));
if (GetProperties().GetCount() > 0) if (GetProperties().GetCount() > 0)
@@ -912,6 +933,13 @@ bool wxRichTextParagraphLayoutBox::ExportXML(wxXmlNode* parent, wxRichTextXMLHan
if (GetPartialParagraph()) if (GetPartialParagraph())
elementNode->AddAttribute(wxT("partialparagraph"), wxT("true")); elementNode->AddAttribute(wxT("partialparagraph"), wxT("true"));
wxRichTextCell* cell = wxDynamicCast(this, wxRichTextCell);
if (cell)
{
elementNode->AddAttribute(wxT("colspan"), wxString::Format(wxT("%d"), cell->GetColSpan()));
elementNode->AddAttribute(wxT("rowspan"), wxString::Format(wxT("%d"), cell->GetRowSpan()));
}
size_t i; size_t i;
for (i = 0; i < GetChildCount(); i++) for (i = 0; i < GetChildCount(); i++)
{ {