[Libreoffice-commits] core.git: Branch 'feature/ods-edit-cell-import' - sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Mon Feb 11 08:28:55 PST 2013


 sc/source/filter/xml/celltextparacontext.cxx |  105 +++++++++++++++++++++++++--
 sc/source/filter/xml/celltextparacontext.hxx |   56 ++++++++++++++
 sc/source/filter/xml/xmlcelli.cxx            |   13 ++-
 sc/source/filter/xml/xmlcelli.hxx            |    2 
 sc/source/filter/xml/xmlimprt.cxx            |    3 
 sc/source/filter/xml/xmlimprt.hxx            |    5 +
 6 files changed, 177 insertions(+), 7 deletions(-)

New commits:
commit 89a3618aea7f12b814a492d017b99803c6ddd9ef
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Mon Feb 11 11:28:54 2013 -0500

    Prepare for the import of cell field items.
    
    And some code to import sheet name fields. But for some reason they
    are not being imported.  I need to debug this...
    
    Change-Id: I5d10ae27f2f45de2454660884924fd1e0c0dcef0

diff --git a/sc/source/filter/xml/celltextparacontext.cxx b/sc/source/filter/xml/celltextparacontext.cxx
index d15b715..84249b4 100644
--- a/sc/source/filter/xml/celltextparacontext.cxx
+++ b/sc/source/filter/xml/celltextparacontext.cxx
@@ -24,7 +24,7 @@ ScXMLCellTextParaContext::ScXMLCellTextParaContext(
 {
 }
 
-void ScXMLCellTextParaContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& xAttrList)
+void ScXMLCellTextParaContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
 {
 }
 
@@ -42,7 +42,7 @@ void ScXMLCellTextParaContext::Characters(const OUString& rChars)
 }
 
 SvXMLImportContext* ScXMLCellTextParaContext::CreateChildContext(
-    sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& xAttrList)
+    sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
 {
     if (!maContent.isEmpty())
     {
@@ -55,7 +55,12 @@ SvXMLImportContext* ScXMLCellTextParaContext::CreateChildContext(
     {
         case XML_TOK_CELL_TEXT_SPAN:
             return new ScXMLCellTextSpanContext(GetScImport(), nPrefix, rLocalName, *this);
-        break;
+        case XML_TOK_CELL_TEXT_SHEET_NAME:
+            return new ScXMLCellFieldSheetNameContext(GetScImport(), nPrefix, rLocalName, *this);
+        case XML_TOK_CELL_TEXT_DATE:
+            return new ScXMLCellFieldDateContext(GetScImport(), nPrefix, rLocalName, *this);
+        case XML_TOK_CELL_TEXT_TITLE:
+            return new ScXMLCellFieldTitleContext(GetScImport(), nPrefix, rLocalName, *this);
         default:
             ;
     }
@@ -68,6 +73,19 @@ void ScXMLCellTextParaContext::PushSpan(const OUString& rSpan, const OUString& r
     mrParentCxt.PushParagraphSpan(rSpan, rStyleName);
 }
 
+void ScXMLCellTextParaContext::PushFieldSheetName()
+{
+    mrParentCxt.PushParagraphFieldSheetName();
+}
+
+void ScXMLCellTextParaContext::PushFieldDate(const OUString& rOutput)
+{
+}
+
+void ScXMLCellTextParaContext::PushFieldTitle(const OUString& rTitle)
+{
+}
+
 ScXMLCellTextSpanContext::ScXMLCellTextSpanContext(
     ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) :
     ScXMLImportContext(rImport, nPrefix, rLName),
@@ -116,7 +134,86 @@ void ScXMLCellTextSpanContext::Characters(const OUString& rChars)
 }
 
 SvXMLImportContext* ScXMLCellTextSpanContext::CreateChildContext(
-    sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& xAttrList)
+    sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
+{
+    return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
+}
+
+ScXMLCellFieldSheetNameContext::ScXMLCellFieldSheetNameContext(
+    ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) :
+    ScXMLImportContext(rImport, nPrefix, rLName),
+    mrParentCxt(rParent)
+{
+}
+
+void ScXMLCellFieldSheetNameContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
+{
+    // <text:sheet-name> has no attributes (that I'm aware of).
+}
+
+void ScXMLCellFieldSheetNameContext::EndElement()
+{
+    mrParentCxt.PushFieldSheetName();
+}
+
+void ScXMLCellFieldSheetNameContext::Characters(const OUString& /*rChars*/)
+{
+}
+
+SvXMLImportContext* ScXMLCellFieldSheetNameContext::CreateChildContext(
+    sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
+{
+    return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
+}
+
+ScXMLCellFieldDateContext::ScXMLCellFieldDateContext(
+    ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) :
+    ScXMLImportContext(rImport, nPrefix, rLName),
+    mrParentCxt(rParent)
+{
+}
+
+void ScXMLCellFieldDateContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
+{
+}
+
+void ScXMLCellFieldDateContext::EndElement()
+{
+}
+
+void ScXMLCellFieldDateContext::Characters(const OUString& rChars)
+{
+    maDate = rChars;
+}
+
+SvXMLImportContext* ScXMLCellFieldDateContext::CreateChildContext(
+    sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
+{
+    return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
+}
+
+ScXMLCellFieldTitleContext::ScXMLCellFieldTitleContext(
+    ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent) :
+    ScXMLImportContext(rImport, nPrefix, rLName),
+    mrParentCxt(rParent)
+{
+}
+
+void ScXMLCellFieldTitleContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
+{
+}
+
+void ScXMLCellFieldTitleContext::EndElement()
+{
+}
+
+void ScXMLCellFieldTitleContext::Characters(const OUString& rChars)
+{
+    maTitle = rChars;
+}
+
+SvXMLImportContext* ScXMLCellFieldTitleContext::CreateChildContext(
+    sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
 {
     return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
 }
diff --git a/sc/source/filter/xml/celltextparacontext.hxx b/sc/source/filter/xml/celltextparacontext.hxx
index 8401c0d..7840cd6 100644
--- a/sc/source/filter/xml/celltextparacontext.hxx
+++ b/sc/source/filter/xml/celltextparacontext.hxx
@@ -32,6 +32,9 @@ public:
         sal_uInt16 nPrefix, const OUString& rLocalName, const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
 
     void PushSpan(const OUString& rSpan, const OUString& rStyleName);
+    void PushFieldSheetName();
+    void PushFieldDate(const OUString& rOutput);
+    void PushFieldTitle(const OUString& rTitle);
 };
 
 /**
@@ -52,6 +55,59 @@ public:
         sal_uInt16 nPrefix, const OUString& rLocalName, const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
 };
 
+/**
+ * This context handles <text:sheet-name> element inside <text:p>.
+ *
+ */
+class ScXMLCellFieldSheetNameContext : public ScXMLImportContext
+{
+    ScXMLCellTextParaContext& mrParentCxt;
+public:
+    ScXMLCellFieldSheetNameContext(ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent);
+
+    virtual void StartElement(const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
+    virtual void EndElement();
+    virtual void Characters(const OUString& rChars);
+    virtual SvXMLImportContext* CreateChildContext(
+        sal_uInt16 nPrefix, const OUString& rLocalName, const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
+};
+
+/**
+ * This context handles <text:date> element inside <text:p>.
+ *
+ */
+class ScXMLCellFieldDateContext : public ScXMLImportContext
+{
+    ScXMLCellTextParaContext& mrParentCxt;
+    OUString maDate;
+public:
+    ScXMLCellFieldDateContext(ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent);
+
+    virtual void StartElement(const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
+    virtual void EndElement();
+    virtual void Characters(const OUString& rChars);
+    virtual SvXMLImportContext* CreateChildContext(
+        sal_uInt16 nPrefix, const OUString& rLocalName, const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
+};
+
+/**
+ * This context handles <text:title> element inside <text:p>.
+ *
+ */
+class ScXMLCellFieldTitleContext : public ScXMLImportContext
+{
+    ScXMLCellTextParaContext& mrParentCxt;
+    OUString maTitle;
+public:
+    ScXMLCellFieldTitleContext(ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent);
+
+    virtual void StartElement(const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
+    virtual void EndElement();
+    virtual void Characters(const OUString& rChars);
+    virtual SvXMLImportContext* CreateChildContext(
+        sal_uInt16 nPrefix, const OUString& rLocalName, const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
+};
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 72de86c..47aa7ee 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -78,6 +78,7 @@
 #include "editeng/escpitem.hxx"
 #include "editeng/emphitem.hxx"
 #include "editeng/langitem.hxx"
+#include "editeng/flditem.hxx"
 #include <svx/unoapi.hxx>
 #include <svl/languageoptions.hxx>
 #include <sax/tools/converter.hxx>
@@ -145,7 +146,8 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
     bFormulaTextResult(false),
     mbPossibleErrorCell(false),
     mbCheckWithCompilerForError(false),
-    mbEditEngineHasText(false)
+    mbEditEngineHasText(false),
+    mbEditEngineHasField(false)
 {
     rtl::math::setNan(&fValue); // NaN by default
     mpEditEngine->Clear();
@@ -550,6 +552,13 @@ void ScXMLTableRowCellContext::PushParagraphSpan(const OUString& rSpan, const OU
         rFmt.maItemSet.Put(*pPoolItem);
 }
 
+void ScXMLTableRowCellContext::PushParagraphFieldSheetName()
+{
+    SvxTableField aField(0);
+    mpEditEngine->QuickInsertField(SvxFieldItem(aField, EE_FEATURE_FIELD), ESelection(EE_PARA_APPEND, EE_PARA_APPEND));
+    mbEditEngineHasField = true;
+}
+
 void ScXMLTableRowCellContext::PushParagraphEnd()
 {
     // EditEngine always has at least one paragraph even when its content is empty.
@@ -989,7 +998,7 @@ void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos,
             pNewCell = ScBaseCell::CreateTextCell( *maStringValue, pDoc );
         else if (mbEditEngineHasText)
         {
-            if (maFormats.empty() && mpEditEngine->GetParagraphCount() == 1)
+            if (!mbEditEngineHasField && maFormats.empty() && mpEditEngine->GetParagraphCount() == 1)
             {
                 // This is a normal text without format runs.
                 pNewCell = new ScStringCell(mpEditEngine->GetText());
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index e9d7e23..bdb817c 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -76,6 +76,7 @@ class ScXMLTableRowCellContext : public ScXMLImportContext
     bool mbPossibleErrorCell;
     bool mbCheckWithCompilerForError;
     bool mbEditEngineHasText;
+    bool mbEditEngineHasField;
 
     sal_Int16 GetCellType(const rtl::OUString& sOUValue) const;
 
@@ -120,6 +121,7 @@ public:
                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
 
     void PushParagraphSpan(const OUString& rSpan, const OUString& rStyleName);
+    void PushParagraphFieldSheetName();
     void PushParagraphEnd();
 
     void SetAnnotation( const ScAddress& rPosition );
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index 0781667..fb5516f 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -1850,6 +1850,9 @@ const SvXMLTokenMap& ScXMLImport::GetCellTextParaElemTokenMap()
         static SvXMLTokenMapEntry aMap[] =
         {
             { XML_NAMESPACE_TEXT, XML_SPAN, XML_TOK_CELL_TEXT_SPAN },
+            { XML_NAMESPACE_TEXT, XML_SHEET_NAME, XML_TOK_CELL_TEXT_SHEET_NAME },
+            { XML_NAMESPACE_TEXT, XML_DATE, XML_TOK_CELL_TEXT_DATE },
+            { XML_NAMESPACE_TEXT, XML_TITLE, XML_TOK_CELL_TEXT_TITLE },
             XML_TOKEN_MAP_END
         };
 
diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx
index 1aae0b1..da35d640 100644
--- a/sc/source/filter/xml/xmlimprt.hxx
+++ b/sc/source/filter/xml/xmlimprt.hxx
@@ -687,7 +687,10 @@ enum ScXMLConsolidationAttrTokens
  */
 enum ScXMLCellTextParaElemTokens
 {
-    XML_TOK_CELL_TEXT_SPAN
+    XML_TOK_CELL_TEXT_SPAN,
+    XML_TOK_CELL_TEXT_SHEET_NAME,
+    XML_TOK_CELL_TEXT_DATE,
+    XML_TOK_CELL_TEXT_TITLE
 };
 
 /**


More information about the Libreoffice-commits mailing list