editeng/source/accessibility/AccessibleEditableTextPara.cxx |    3 
 editeng/source/items/CustomPropertyField.cxx                |   19 +++--
 editeng/source/items/flditem.cxx                            |   11 +++
 editeng/source/uno/unofield.cxx                             |   41 ++++++++++++
 include/editeng/CustomPropertyField.hxx                     |   18 +++--
 include/editeng/unonames.hxx                                |    6 +
 offapi/com/sun/star/text/textfield/Type.idl                 |    4 -
 sd/source/ui/app/sdmod2.cxx                                 |   16 ++++
 sd/source/ui/unoidl/unomodel.cxx                            |    6 +
 sd/source/ui/view/drviews2.cxx                              |   14 ++--
 10 files changed, 114 insertions(+), 24 deletions(-)

New commits:
commit 2884d57d4717afc3c31baee0ebc4a3e8b1c1d2f2
Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
Date:   Mon Oct 30 12:21:49 2017 +0900

    TSCP: Support DocInfo.Custom field for ODP file format
    
    Impress has a limited support for fields - this includes support
    for DocInfo.Custom field, which shows the user defined custom
    fields that are used in TSCP. This commit adds minimal support
    (only what is needed for TSCP) for DocInfo.Custom field but only
    supports string fields for now. It is not possible to add the field
    manually, at least not until the full support is added.
    
    Change-Id: Ib3b73ab22fd4fe65ab6fb5173fe035a3359deea5
    Reviewed-on: https://gerrit.libreoffice.org/44041
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/editeng/source/accessibility/AccessibleEditableTextPara.cxx 
b/editeng/source/accessibility/AccessibleEditableTextPara.cxx
index a8e7a90017ed..b7931eef21c4 100644
--- a/editeng/source/accessibility/AccessibleEditableTextPara.cxx
+++ b/editeng/source/accessibility/AccessibleEditableTextPara.cxx
@@ -901,6 +901,9 @@ namespace
             case text::textfield::Type::DOCINFO_TITLE:
                 strFldType = "file name";
                 break;
+            case text::textfield::Type::DOCINFO_CUSTOM:
+                strFldType = "custom document property";
+                break;
             default:
                 break;
         }
diff --git a/editeng/source/items/CustomPropertyField.cxx 
b/editeng/source/items/CustomPropertyField.cxx
index 7145bc72c650..70a6a40197b2 100644
--- a/editeng/source/items/CustomPropertyField.cxx
+++ b/editeng/source/items/CustomPropertyField.cxx
@@ -22,9 +22,10 @@ CustomPropertyField::CustomPropertyField()
     : SvxFieldData()
 {}
 
-CustomPropertyField::CustomPropertyField(OUString const & rKey)
+CustomPropertyField::CustomPropertyField(OUString const & rName, OUString 
const & rCurrentPresentation)
     : SvxFieldData()
-    , msKey(rKey)
+    , msName(rName)
+    , msCurrentPresentation(rCurrentPresentation)
 {}
 
 CustomPropertyField::~CustomPropertyField()
@@ -34,7 +35,7 @@ SV_IMPL_PERSIST1(CustomPropertyField);
 
 SvxFieldData* CustomPropertyField::Clone() const
 {
-    return new CustomPropertyField(msKey);
+    return new CustomPropertyField(msName, msCurrentPresentation);
 }
 
 bool CustomPropertyField::operator==(const SvxFieldData& rOther) const
@@ -43,7 +44,8 @@ bool CustomPropertyField::operator==(const SvxFieldData& 
rOther) const
         return false;
 
     const CustomPropertyField& rOtherField = static_cast<const 
CustomPropertyField&>(rOther);
-    return (msKey == rOtherField.msKey);
+    return (msName               == rOtherField.msName &&
+            msCurrentPresentation == rOtherField.msCurrentPresentation);
 }
 
 MetaAction* CustomPropertyField::createBeginComment() const
@@ -51,8 +53,10 @@ MetaAction* CustomPropertyField::createBeginComment() const
     return new MetaCommentAction("FIELD_SEQ_BEGIN");
 }
 
-OUString 
CustomPropertyField::GetFormatted(uno::Reference<document::XDocumentProperties> 
const & xDocumentProperties) const
+OUString 
CustomPropertyField::GetFormatted(uno::Reference<document::XDocumentProperties> 
const & xDocumentProperties)
 {
+    if (msName.isEmpty())
+        return OUString();
     if (!xDocumentProperties.is())
         return OUString();
     uno::Reference<beans::XPropertyContainer> xPropertyContainer = 
xDocumentProperties->getUserDefinedProperties();
@@ -61,10 +65,11 @@ OUString 
CustomPropertyField::GetFormatted(uno::Reference<document::XDocumentPro
     uno::Reference<beans::XPropertySet> xPropertySet(xPropertyContainer, 
uno::UNO_QUERY);
     if (!xPropertySet.is())
         return OUString();
-    uno::Any aAny = xPropertySet->getPropertyValue(msKey);
+    uno::Any aAny = xPropertySet->getPropertyValue(msName);
     if (!aAny.has<OUString>())
         return OUString();
-    return aAny.get<OUString>();
+    msCurrentPresentation = aAny.get<OUString>();
+    return msCurrentPresentation;
 }
 
 } // end editeng namespace
diff --git a/editeng/source/items/flditem.cxx b/editeng/source/items/flditem.cxx
index bbdd2b7036d0..4435fcf490b9 100644
--- a/editeng/source/items/flditem.cxx
+++ b/editeng/source/items/flditem.cxx
@@ -24,6 +24,7 @@
 #include <tools/urlobj.hxx>
 
 #include <editeng/flditem.hxx>
+#include <editeng/CustomPropertyField.hxx>
 #include <editeng/measfld.hxx>
 #include <editeng/unonames.hxx>
 
@@ -216,6 +217,16 @@ SvxFieldData* SvxFieldData::Create(const 
uno::Reference<text::XTextContent>& xTe
                 return new SvxFooterField();
             case text::textfield::Type::PRESENTATION_DATE_TIME:
                 return new SvxDateTimeField();
+            case text::textfield::Type::DOCINFO_CUSTOM:
+                {
+                    OUString sName;
+                    xPropSet->getPropertyValue(UNO_TC_PROP_NAME) >>= sName;
+
+                    OUString sCurrentPresentation;
+                    
xPropSet->getPropertyValue(UNO_TC_PROP_CURRENT_PRESENTATION) >>= 
sCurrentPresentation;
+
+                    return new editeng::CustomPropertyField(sName, 
sCurrentPresentation);
+                }
             default:
                 ;
         };
diff --git a/editeng/source/uno/unofield.cxx b/editeng/source/uno/unofield.cxx
index 55fb74bcc999..b2f416c7c78e 100644
--- a/editeng/source/uno/unofield.cxx
+++ b/editeng/source/uno/unofield.cxx
@@ -25,6 +25,7 @@
 
 #include <editeng/eeitem.hxx>
 #include <editeng/flditem.hxx>
+#include <editeng/CustomPropertyField.hxx>
 #include <editeng/measfld.hxx>
 #include <editeng/unofield.hxx>
 #include <editeng/unotext.hxx>
@@ -128,6 +129,17 @@ const SfxItemPropertySet* ImplGetFieldItemPropertySet( 
sal_Int32 mnId )
     };
     static const SfxItemPropertySet 
aMeasureFieldPropertySet_Impl(aMeasureFieldPropertyMap_Impl);
 
+    static const SfxItemPropertyMapEntry aDocInfoCustomFieldPropertyMap_Impl[] 
=
+    {
+        { OUString(UNO_TC_PROP_NAME),                 WID_STRING1, 
cppu::UnoType<OUString>::get(),   0, 0 },
+        { OUString(UNO_TC_PROP_CURRENT_PRESENTATION), WID_STRING2, 
cppu::UnoType<OUString>::get(),   0, 0 },
+        { OUString(UNO_TC_PROP_IS_FIXED),             WID_BOOL1,   
cppu::UnoType<bool>::get(),       0, 0 },
+        { OUString(UNO_TC_PROP_NUMFORMAT),            WID_INT32,   
cppu::UnoType<sal_Int32>::get(),  0, 0 },
+        { OUString(UNO_TC_PROP_IS_FIXED_LANGUAGE),    WID_BOOL2,   
cppu::UnoType<bool>::get(),       0, 0 },
+        { OUString(), 0, css::uno::Type(), 0, 0 }
+    };
+    static const SfxItemPropertySet 
aDocInfoCustomFieldPropertySet_Impl(aDocInfoCustomFieldPropertyMap_Impl);
+
     switch( mnId )
     {
     case text::textfield::Type::EXTENDED_TIME:
@@ -143,6 +155,8 @@ const SfxItemPropertySet* ImplGetFieldItemPropertySet( 
sal_Int32 mnId )
         return &aAuthorFieldPropertySet_Impl;
     case text::textfield::Type::MEASURE:
         return &aMeasureFieldPropertySet_Impl;
+    case text::textfield::Type::DOCINFO_CUSTOM:
+        return &aDocInfoCustomFieldPropertySet_Impl;
     default:
         return &aEmptyPropertySet_Impl;
     }
@@ -281,6 +295,12 @@ SvxUnoTextField::SvxUnoTextField( sal_Int32 nServiceId ) 
throw()
         mpImpl->mnInt16 = static_cast<sal_uInt16>(SdrMeasureFieldKind::Value);
         break;
 
+    case text::textfield::Type::DOCINFO_CUSTOM:
+        mpImpl->mbBoolean1 = true;
+        mpImpl->mbBoolean2 = true;
+        mpImpl->mnInt32 = 0;
+        break;
+
     default:
         mpImpl->mbBoolean1 = false;
         mpImpl->mbBoolean2 = false;
@@ -364,6 +384,14 @@ SvxUnoTextField::SvxUnoTextField( uno::Reference< 
text::XTextRange > const & xAn
                 mpImpl->mnInt16     = sal::static_int_cast< sal_Int16 
>(static_cast<const SdrMeasureField*>(pData)->GetMeasureFieldKind());
                 break;
 
+            case text::textfield::Type::DOCINFO_CUSTOM:
+                mpImpl->msString1 = static_cast<const 
editeng::CustomPropertyField*>(pData)->GetName();
+                mpImpl->msString2 = static_cast<const 
editeng::CustomPropertyField*>(pData)->GetCurrentPresentation();
+                mpImpl->mbBoolean1 = false;
+                mpImpl->mbBoolean2 = false;
+                mpImpl->mnInt32 = 0;
+                break;
+
             default:
                 SAL_WARN("editeng", "Id service unknown: " << mnServiceId);
                 break;
@@ -512,6 +540,9 @@ SvxFieldData* SvxUnoTextField::CreateFieldData() const 
throw()
     case text::textfield::Type::PAGE_NAME:
         pData = new SvxPageTitleField();
         break;
+    case text::textfield::Type::DOCINFO_CUSTOM:
+        pData = new editeng::CustomPropertyField(mpImpl->msString1, 
mpImpl->msString2);
+        break;
     };
 
     return pData;
@@ -611,6 +642,8 @@ OUString SAL_CALL SvxUnoTextField::getPresentation( 
sal_Bool bShowCommand )
                 return OUString("DateTime");
             case text::textfield::Type::PAGE_NAME:
                 return OUString("PageName");
+            case text::textfield::Type::DOCINFO_CUSTOM:
+                return OUString("Custom");
             default:
                 return OUString("Unknown");
         }
@@ -853,6 +886,10 @@ uno::Sequence< OUString > SAL_CALL 
SvxUnoTextField::getSupportedServiceNames()
             pServices[2] = "com.sun.star.text.TextField.PageName";
             pServices[3] = "com.sun.star.text.textfield.PageName";
         break;
+        case text::textfield::Type::DOCINFO_CUSTOM:
+            pServices[2] = "com.sun.star.text.TextField.DocInfo.Custom";
+            pServices[3] = "com.sun.star.text.textfield.DocInfo.Custom";
+        break;
         default:
             aSeq.realloc(0);
     }
@@ -918,6 +955,10 @@ uno::Reference< uno::XInterface > SAL_CALL 
SvxUnoTextCreateTextField( const OUSt
         {
             nId = text::textfield::Type::MEASURE;
         }
+        else if (aFieldType == "DocInfo.Custom")
+        {
+            nId = text::textfield::Type::DOCINFO_CUSTOM;
+        }
 
         if (nId != text::textfield::Type::UNSPECIFIED)
             xRet = static_cast<cppu::OWeakObject *>(new SvxUnoTextField( nId 
));
diff --git a/include/editeng/CustomPropertyField.hxx 
b/include/editeng/CustomPropertyField.hxx
index 3d862007c1f6..687b4a171375 100644
--- a/include/editeng/CustomPropertyField.hxx
+++ b/include/editeng/CustomPropertyField.hxx
@@ -26,26 +26,32 @@ namespace editeng
 class EDITENG_DLLPUBLIC CustomPropertyField : public SvxFieldData
 {
 private:
-    OUString msKey;
+    OUString msName;
+    OUString msCurrentPresentation;
 
 public:
     CustomPropertyField();
-    explicit CustomPropertyField(OUString const & rKey);
+    explicit CustomPropertyField(OUString const & rName, OUString const & 
rCurrentPresentation);
 
     virtual ~CustomPropertyField() override;
 
-    SV_DECL_PERSIST1(CustomPropertyField, 
css::text::textfield::Type::CUSTOM_PROPERTY)
+    SV_DECL_PERSIST1(CustomPropertyField, 
css::text::textfield::Type::DOCINFO_CUSTOM)
 
     virtual SvxFieldData* Clone() const override;
     virtual bool operator==(const SvxFieldData&) const override;
 
     virtual MetaAction* createBeginComment() const override;
 
-    OUString 
GetFormatted(css::uno::Reference<css::document::XDocumentProperties> const & 
xDocumentProperties) const;
+    OUString 
GetFormatted(css::uno::Reference<css::document::XDocumentProperties> const & 
xDocumentProperties);
 
-    OUString GetKey() const
+    OUString GetName() const
     {
-        return msKey;
+        return msName;
+    }
+
+    OUString GetCurrentPresentation() const
+    {
+        return msCurrentPresentation;
     }
 };
 
diff --git a/include/editeng/unonames.hxx b/include/editeng/unonames.hxx
index f3e3a8047e67..de2e1fcf6c47 100644
--- a/include/editeng/unonames.hxx
+++ b/include/editeng/unonames.hxx
@@ -15,11 +15,15 @@
 #define UNO_TC_PROP_TEXTFIELD_TYPE       "TextFieldType"
 #define UNO_TC_PROP_IS_FIXED             "IsFixed"
 #define UNO_TC_PROP_CURRENT_PRESENTATION "CurrentPresentation"
+#define UNO_TC_PROP_NAME                 "Name"
+#define UNO_TC_PROP_IS_FIXED_LANGUAGE    "IsFixedLanguage"
+#define UNO_TC_PROP_NUMFORMAT            "NumberFormat"
+#define UNO_TC_PROP_USED                 "IsFieldUsed"
+#define UNO_TC_PROP_DISPLAYED            "IsFieldDisplayed"
 
 // Date & Time
 #define UNO_TC_PROP_IS_DATE   "IsDate"
 #define UNO_TC_PROP_DATE_TIME "DateTime"
-#define UNO_TC_PROP_NUMFORMAT "NumberFormat"
 
 // URL
 #define UNO_TC_PROP_URL_FORMAT         "Format"
diff --git a/offapi/com/sun/star/text/textfield/Type.idl 
b/offapi/com/sun/star/text/textfield/Type.idl
index 454b1c765a8a..648400a224ba 100644
--- a/offapi/com/sun/star/text/textfield/Type.idl
+++ b/offapi/com/sun/star/text/textfield/Type.idl
@@ -42,8 +42,8 @@ constants Type
     const long PRESENTATION_HEADER    = 11;
     const long PRESENTATION_FOOTER    = 12;
     const long PRESENTATION_DATE_TIME = 13;
-    const long PAGE_NAME       = 14;
-    const long CUSTOM_PROPERTY = 15;
+    const long PAGE_NAME      = 14;
+    const long DOCINFO_CUSTOM = 15;
 };
 
 }; }; }; }; };
diff --git a/sd/source/ui/app/sdmod2.cxx b/sd/source/ui/app/sdmod2.cxx
index 29b8b9798228..b7b51f41917c 100644
--- a/sd/source/ui/app/sdmod2.cxx
+++ b/sd/source/ui/app/sdmod2.cxx
@@ -349,7 +349,21 @@ IMPL_LINK(SdModule, CalcFieldValueHdl, EditFieldInfo*, 
pInfo, void)
     }
     else if ((pCustomPropertyField = dynamic_cast<const 
editeng::CustomPropertyField*>(pField)) != nullptr)
     {
-        
pInfo->SetRepresentation(pCustomPropertyField->GetFormatted(SfxObjectShell::Current()->getDocProperties()));
+        try
+        {
+            if (SfxObjectShell::Current() && 
SfxObjectShell::Current()->IsLoadingFinished())
+            {
+                auto pNonConstCustomPropertyField = 
const_cast<editeng::CustomPropertyField*>(pCustomPropertyField);
+                OUString sCurrent = 
pNonConstCustomPropertyField->GetFormatted(SfxObjectShell::Current()->getDocProperties());
+                pInfo->SetRepresentation(sCurrent);
+            }
+            else
+                
pInfo->SetRepresentation(pCustomPropertyField->GetCurrentPresentation());
+        }
+        catch (...)
+        {
+            
pInfo->SetRepresentation(pCustomPropertyField->GetCurrentPresentation());
+        }
     }
     else
     {
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index 63964904173b..4cd01e61acff 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -926,6 +926,12 @@ css::uno::Reference<css::uno::XInterface> 
SdXImpressDocument::create(
         return static_cast<cppu::OWeakObject *>(new SvxUnoTextField( 
text::textfield::Type::PAGE_NAME ));
     }
 
+    if (aServiceSpecifier == "com.sun.star.text.TextField.DocInfo.Custom" ||
+        aServiceSpecifier == "com.sun.star.text.textfield.DocInfo.Custom")
+    {
+        return static_cast<cppu::OWeakObject *>(new 
SvxUnoTextField(text::textfield::Type::DOCINFO_CUSTOM));
+    }
+
     if( aServiceSpecifier == "com.sun.star.xml.NamespaceMap" )
     {
         static sal_uInt16 aWhichIds[] = { SDRATTR_XMLATTRIBUTES, 
EE_CHAR_XMLATTRIBS, EE_PARA_XMLATTRIBS, 0 };
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
index 4d1eca41992b..6959bd726536 100644
--- a/sd/source/ui/view/drviews2.cxx
+++ b/sd/source/ui/view/drviews2.cxx
@@ -244,7 +244,7 @@ const SvxFieldItem* findField(editeng::Section const & 
rSection)
     return nullptr;
 }
 
-bool hasCustomPropertyField(std::vector<editeng::Section> const & aSections, 
OUString const & rKey)
+bool hasCustomPropertyField(std::vector<editeng::Section> const & aSections, 
OUString const & rName)
 {
     for (editeng::Section const & rSection : aSections)
     {
@@ -252,7 +252,7 @@ bool hasCustomPropertyField(std::vector<editeng::Section> 
const & aSections, OUS
         if (pFieldItem)
         {
             const editeng::CustomPropertyField* pCustomPropertyField = 
dynamic_cast<const editeng::CustomPropertyField*>(pFieldItem->GetField());
-            if (pCustomPropertyField && pCustomPropertyField->GetKey() == rKey)
+            if (pCustomPropertyField && pCustomPropertyField->GetName() == 
rName)
                 return true;
         }
     }
@@ -315,7 +315,7 @@ private:
             if (pFieldItem)
             {
                 const auto* pCustomPropertyField = dynamic_cast<const 
editeng::CustomPropertyField*>(pFieldItem->GetField());
-                OUString aKey = pCustomPropertyField->GetKey();
+                OUString aKey = pCustomPropertyField->GetName();
                 if (aKeyCreator.isMarkingTextKey(aKey))
                 {
                     OUString aValue = lcl_getProperty(xPropertyContainer, 
aKey);
@@ -490,14 +490,14 @@ public:
                 {
                     OUString sKey = aKeyCreator.makeNumberedMarkingTextKey();
                     addOrInsertDocumentProperty(xPropertyContainer, sKey, 
rResult.msString);
-                    
pOutliner->QuickInsertField(SvxFieldItem(editeng::CustomPropertyField(sKey), 
EE_FEATURE_FIELD), aPosition);
+                    
pOutliner->QuickInsertField(SvxFieldItem(editeng::CustomPropertyField(sKey, 
rResult.msString), EE_FEATURE_FIELD), aPosition);
                 }
                 break;
 
                 case svx::ClassificationType::CATEGORY:
                 {
                     OUString sKey = aKeyCreator.makeCategoryKey();
-                    
pOutliner->QuickInsertField(SvxFieldItem(editeng::CustomPropertyField(sKey), 
EE_FEATURE_FIELD), aPosition);
+                    
pOutliner->QuickInsertField(SvxFieldItem(editeng::CustomPropertyField(sKey, 
rResult.msString), EE_FEATURE_FIELD), aPosition);
                 }
                 break;
 
@@ -505,7 +505,7 @@ public:
                 {
                     OUString sKey = aKeyCreator.makeMarkingKey();
                     addOrInsertDocumentProperty(xPropertyContainer, sKey, 
rResult.msString);
-                    
pOutliner->QuickInsertField(SvxFieldItem(editeng::CustomPropertyField(sKey), 
EE_FEATURE_FIELD), aPosition);
+                    
pOutliner->QuickInsertField(SvxFieldItem(editeng::CustomPropertyField(sKey, 
rResult.msString), EE_FEATURE_FIELD), aPosition);
                 }
                 break;
 
@@ -513,7 +513,7 @@ public:
                 {
                     OUString sKey = 
aKeyCreator.makeIntellectualPropertyPartKey();
                     addOrInsertDocumentProperty(xPropertyContainer, sKey, 
rResult.msString);
-                    
pOutliner->QuickInsertField(SvxFieldItem(editeng::CustomPropertyField(sKey), 
EE_FEATURE_FIELD), aPosition);
+                    
pOutliner->QuickInsertField(SvxFieldItem(editeng::CustomPropertyField(sKey, 
rResult.msString), EE_FEATURE_FIELD), aPosition);
                 }
                 break;
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to