summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2017-09-19 15:37:04 +0200
committerTomaž Vajngerl <quikee@gmail.com>2017-09-21 09:49:12 +0200
commit71ee09947d5a71105d64fd225bb3672dfa7ce834 (patch)
tree81103520450ac1742f100dcc21526a1543cf74dc /sw
parentf22ad61038d5bf10dbe9f2ce0bdf0ef996be72f6 (diff)
TSCP: add advanced classification dialog
This adds a advanced classification dialog, which enables the user to manually construct a header/footer message from classification properties in cases where the user needs more control. All the text is inserted as fields into the end document and can be changed by changing the document properties. The simple classification still functions as it did before, which is what most users will want to use in this case. The BAF policy has been extended with new xml extension elements: - loext:Marking - loext:IntellectualPropertyPart - loext:IntellectualPropertyPartNumber They are used to fill the values in the advanced classification dialog. Change-Id: Ie2d638d69b8a9b0799cff9c2b785eb789f8af1d5 Reviewed-on: https://gerrit.libreoffice.org/42474 Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/editsh.hxx3
-rw-r--r--sw/sdi/_basesh.sdi7
-rw-r--r--sw/source/core/edit/edfcol.cxx267
-rw-r--r--sw/source/uibase/app/docsh2.cxx15
-rw-r--r--sw/source/uibase/app/docst.cxx3
-rw-r--r--sw/source/uibase/shells/basesh.cxx5
-rw-r--r--sw/uiconfig/swriter/toolbar/classificationbar.xml1
7 files changed, 292 insertions, 9 deletions
diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx
index f8d40ddcd0ba..bda5d3216a48 100644
--- a/sw/inc/editsh.hxx
+++ b/sw/inc/editsh.hxx
@@ -34,6 +34,7 @@
#include <svtools/embedhlp.hxx>
#include <editeng/swafopt.hxx>
+#include <svx/ClassificationField.hxx>
#include <vcl/font.hxx>
@@ -367,6 +368,8 @@ public:
{ return static_cast<SwCharFormat*>(SwEditShell::GetFormatFromPool( nId )); }
void SetClassification(const OUString& rName, SfxClassificationPolicyType eType);
+ void ApplyAdvancedClassification(std::vector<svx::ClassificationResult> const & rResult);
+ std::vector<svx::ClassificationResult> CollectAdvancedClassification();
SfxWatermarkItem GetWatermark();
void SetWatermark(const SfxWatermarkItem& rText);
diff --git a/sw/sdi/_basesh.sdi b/sw/sdi/_basesh.sdi
index 3d3a92080705..c3275e247d75 100644
--- a/sw/sdi/_basesh.sdi
+++ b/sw/sdi/_basesh.sdi
@@ -377,6 +377,12 @@ interface BaseTextSelection
StateMethod = StateStyle ;
]
+ SID_CLASSIFICATION_DIALOG
+ [
+ ExecMethod = Execute ;
+ StateMethod = StateStyle ;
+ ]
+
SID_WATERMARK
[
ExecMethod = Execute ;
@@ -546,4 +552,3 @@ interface BaseTextSelection
StateMethod = GetState;
]
}
-
diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx
index d23828d35fa5..b413b0e290ed 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -78,25 +78,28 @@
#include <strings.hrc>
#include <undobj.hxx>
+#include <officecfg/Office/Common.hxx>
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+
#define WATERMARK_NAME "PowerPlusWaterMarkObject"
namespace
{
/// Find all page styles which are currently used in the document.
-std::set<OUString> lcl_getUsedPageStyles(SwViewShell const * pShell)
+std::vector<OUString> lcl_getUsedPageStyles(SwViewShell const * pShell)
{
- std::set<OUString> aRet;
+ std::vector<OUString> aReturn;
SwRootFrame* pLayout = pShell->GetLayout();
for (SwFrame* pFrame = pLayout->GetLower(); pFrame; pFrame = pFrame->GetNext())
{
SwPageFrame* pPage = static_cast<SwPageFrame*>(pFrame);
if (const SwPageDesc *pDesc = pPage->FindPageDesc())
- aRet.insert(pDesc->GetName());
+ aReturn.push_back(pDesc->GetName());
}
- return aRet;
+ return aReturn;
}
/// Search for a field named rFieldName of type rServiceName in xText.
@@ -290,11 +293,259 @@ sal_uInt16 SwEditShell::GetTextFormatCollCount() const
return GetDoc()->GetTextFormatColls()->size();
}
-SwTextFormatColl& SwEditShell::GetTextFormatColl( sal_uInt16 nFormatColl) const
+SwTextFormatColl& SwEditShell::GetTextFormatColl(sal_uInt16 nFormatColl) const
{
return *((*(GetDoc()->GetTextFormatColls()))[nFormatColl]);
}
+OUString lcl_getProperty(uno::Reference<beans::XPropertyContainer> const & rxPropertyContainer, const OUString& rName)
+{
+ uno::Reference<beans::XPropertySet> xPropertySet(rxPropertyContainer, uno::UNO_QUERY);
+ return xPropertySet->getPropertyValue(rName).get<OUString>();
+}
+
+bool lcl_containsProperty(const uno::Sequence<beans::Property> & rProperties, const OUString& rName)
+{
+ return std::find_if(rProperties.begin(), rProperties.end(), [&](const beans::Property& rProperty)
+ {
+ return rProperty.Name == rName;
+ }) != rProperties.end();
+}
+
+void lcl_removeAllProperties(uno::Reference<beans::XPropertyContainer> const & rxPropertyContainer)
+{
+ uno::Reference<beans::XPropertySet> xPropertySet(rxPropertyContainer, uno::UNO_QUERY);
+ uno::Sequence<beans::Property> aProperties = xPropertySet->getPropertySetInfo()->getProperties();
+
+ for (const beans::Property& rProperty : aProperties)
+ {
+ rxPropertyContainer->removeProperty(rProperty.Name);
+ }
+}
+
+// from classification helper
+SfxClassificationPolicyType getPolicyType()
+{
+ sal_Int32 nPolicyTypeNumber = officecfg::Office::Common::Classification::Policy::get();
+ auto eType = static_cast<SfxClassificationPolicyType>(nPolicyTypeNumber);
+ return eType;
+}
+
+bool addOrInsertDocumentProperty(uno::Reference<beans::XPropertyContainer> const & rxPropertyContainer, OUString const & rsKey, OUString const & rsValue)
+{
+ uno::Reference<beans::XPropertySet> xPropertySet(rxPropertyContainer, uno::UNO_QUERY);
+
+ try
+ {
+ if (lcl_containsProperty(xPropertySet->getPropertySetInfo()->getProperties(), rsKey))
+ xPropertySet->setPropertyValue(rsKey, uno::makeAny(rsValue));
+ else
+ rxPropertyContainer->addProperty(rsKey, beans::PropertyAttribute::REMOVABLE, uno::makeAny(rsValue));
+ }
+ catch (const uno::Exception& /*rException*/)
+ {
+ return false;
+ }
+ return true;
+}
+
+void insertFieldToDocument(uno::Reference<lang::XMultiServiceFactory> const & rxMultiServiceFactory, uno::Reference<text::XText> const & rxText, OUString const & rsKey)
+{
+ const OUString aServiceName = "com.sun.star.text.TextField.DocInfo.Custom";
+ if (!lcl_hasField(rxText, aServiceName, rsKey))
+ {
+ uno::Reference<beans::XPropertySet> xField(rxMultiServiceFactory->createInstance(aServiceName), uno::UNO_QUERY);
+ xField->setPropertyValue(UNO_NAME_NAME, uno::makeAny(rsKey));
+ uno::Reference<text::XTextContent> xTextContent(xField, uno::UNO_QUERY);
+ rxText->insertTextContent(rxText->getEnd(), xTextContent, false);
+ }
+}
+
+void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationResult> const & rResults)
+{
+ SwDocShell* pDocShell = GetDoc()->GetDocShell();
+ if (!pDocShell)
+ return;
+
+ uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
+ uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
+ uno::Reference<container::XNameAccess> xStyleFamilies(xStyleFamiliesSupplier->getStyleFamilies(), uno::UNO_QUERY);
+ uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"), uno::UNO_QUERY);
+
+ uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, uno::UNO_QUERY);
+
+ uno::Reference<document::XDocumentProperties> xDocumentProperties = SfxObjectShell::Current()->getDocProperties();
+
+ // Clear properties
+ uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
+ lcl_removeAllProperties(xPropertyContainer);
+
+ SfxClassificationHelper aHelper(xDocumentProperties);
+
+ // Apply properties from the BA policy
+ for (svx::ClassificationResult const & rResult : rResults)
+ {
+ if (rResult.meType == svx::ClassificationType::CATEGORY)
+ {
+ aHelper.SetBACName(rResult.msString, getPolicyType());
+ }
+ }
+
+ OUString sPolicy = SfxClassificationHelper::policyTypeToString(getPolicyType());
+
+ std::vector<OUString> aUsedPageStyles = lcl_getUsedPageStyles(this);
+ for (const OUString& rPageStyleName : aUsedPageStyles)
+ {
+ uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(rPageStyleName), uno::UNO_QUERY);
+
+ // HEADER
+ bool bHeaderIsOn = false;
+ xPageStyle->getPropertyValue(UNO_NAME_HEADER_IS_ON) >>= bHeaderIsOn;
+ if (!bHeaderIsOn)
+ xPageStyle->setPropertyValue(UNO_NAME_HEADER_IS_ON, uno::makeAny(true));
+ uno::Reference<text::XText> xHeaderText;
+ xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT) >>= xHeaderText;
+
+ // FOOTER
+ bool bFooterIsOn = false;
+ xPageStyle->getPropertyValue(UNO_NAME_FOOTER_IS_ON) >>= bFooterIsOn;
+ if (!bFooterIsOn)
+ xPageStyle->setPropertyValue(UNO_NAME_FOOTER_IS_ON, uno::makeAny(true));
+ uno::Reference<text::XText> xFooterText;
+ xPageStyle->getPropertyValue(UNO_NAME_FOOTER_TEXT) >>= xFooterText;
+
+ sal_Int32 nTextNumber = 1;
+
+ for (svx::ClassificationResult const & rResult : rResults)
+ {
+ switch(rResult.meType)
+ {
+ case svx::ClassificationType::TEXT:
+ {
+ OUString sKey = sPolicy + "Marking:Text:" + OUString::number(nTextNumber);
+ nTextNumber++;
+
+ addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msString);
+ insertFieldToDocument(xMultiServiceFactory, xHeaderText, sKey);
+ insertFieldToDocument(xMultiServiceFactory, xFooterText, sKey);
+ }
+ break;
+
+ case svx::ClassificationType::CATEGORY:
+ {
+ OUString sKey = sPolicy + "BusinessAuthorizationCategory:Name";
+ insertFieldToDocument(xMultiServiceFactory, xHeaderText, sKey);
+ insertFieldToDocument(xMultiServiceFactory, xFooterText, sKey);
+ }
+ break;
+
+ case svx::ClassificationType::MARKING:
+ {
+ OUString sKey = sPolicy + "Extension:Marking";
+ addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msString);
+ insertFieldToDocument(xMultiServiceFactory, xHeaderText, sKey);
+ insertFieldToDocument(xMultiServiceFactory, xFooterText, sKey);
+ }
+ break;
+
+ case svx::ClassificationType::INTELLECTUAL_PROPERTY_PART:
+ {
+ OUString sKey = sPolicy + "Extension:IntellectualPropertyPart";
+ addOrInsertDocumentProperty(xPropertyContainer, sKey, rResult.msString);
+ insertFieldToDocument(xMultiServiceFactory, xHeaderText, sKey);
+ insertFieldToDocument(xMultiServiceFactory, xFooterText, sKey);
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+}
+
+std::vector<svx::ClassificationResult> SwEditShell::CollectAdvancedClassification()
+{
+ std::vector<svx::ClassificationResult> aResult;
+
+ SwDocShell* pDocShell = GetDoc()->GetDocShell();
+
+ if (!pDocShell)
+ return aResult;
+
+ uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
+ uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
+ uno::Reference<container::XNameAccess> xStyleFamilies(xStyleFamiliesSupplier->getStyleFamilies(), uno::UNO_QUERY);
+ uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"), uno::UNO_QUERY);
+
+ std::vector<OUString> aPageStyles = lcl_getUsedPageStyles(this);
+ OUString aPageStyleString = aPageStyles.back();
+ uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(aPageStyleString), uno::UNO_QUERY);
+
+ bool bHeaderIsOn = false;
+ xPageStyle->getPropertyValue(UNO_NAME_HEADER_IS_ON) >>= bHeaderIsOn;
+ if (!bHeaderIsOn)
+ return aResult;
+
+ uno::Reference<text::XText> xHeaderText;
+ xPageStyle->getPropertyValue(UNO_NAME_HEADER_TEXT) >>= xHeaderText;
+
+ uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(xHeaderText, uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xParagraphs = xParagraphEnumerationAccess->createEnumeration();
+
+ uno::Reference<document::XDocumentProperties> xDocumentProperties = SfxObjectShell::Current()->getDocProperties();
+ uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
+
+ OUString sPolicy = SfxClassificationHelper::policyTypeToString(getPolicyType());
+ sal_Int32 nParagraph = 1;
+
+ while (xParagraphs->hasMoreElements())
+ {
+ uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraphs->nextElement(), uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
+ while (xTextPortions->hasMoreElements())
+ {
+ uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY);
+ OUString aTextPortionType;
+ xTextPortion->getPropertyValue(UNO_NAME_TEXT_PORTION_TYPE) >>= aTextPortionType;
+ if (aTextPortionType != UNO_NAME_TEXT_FIELD)
+ continue;
+
+ uno::Reference<lang::XServiceInfo> xTextField;
+ xTextPortion->getPropertyValue(UNO_NAME_TEXT_FIELD) >>= xTextField;
+ if (!xTextField->supportsService("com.sun.star.text.TextField.DocInfo.Custom"))
+ continue;
+
+ OUString aName;
+ uno::Reference<beans::XPropertySet> xPropertySet(xTextField, uno::UNO_QUERY);
+ xPropertySet->getPropertyValue(UNO_NAME_NAME) >>= aName;
+ if (aName.startsWith(sPolicy + "Marking:Text:"))
+ {
+ OUString aValue = lcl_getProperty(xPropertyContainer, aName);
+ aResult.push_back({ svx::ClassificationType::TEXT, aValue, nParagraph });
+ }
+ else if (aName.startsWith(sPolicy + "BusinessAuthorizationCategory:Name"))
+ {
+ OUString aValue = lcl_getProperty(xPropertyContainer, aName);
+ aResult.push_back({ svx::ClassificationType::CATEGORY, aValue, nParagraph });
+ }
+ else if (aName.startsWith(sPolicy + "Extension:Marking"))
+ {
+ OUString aValue = lcl_getProperty(xPropertyContainer, aName);
+ aResult.push_back({ svx::ClassificationType::MARKING, aValue, nParagraph });
+ }
+ else if (aName.startsWith(sPolicy + "Extension:IntellectualPropertyPart"))
+ {
+ OUString aValue = lcl_getProperty(xPropertyContainer, aName);
+ aResult.push_back({ svx::ClassificationType::INTELLECTUAL_PROPERTY_PART, aValue, nParagraph });
+ }
+ }
+ nParagraph++;
+ }
+
+ return aResult;
+}
+
void SwEditShell::SetClassification(const OUString& rName, SfxClassificationPolicyType eType)
{
SwDocShell* pDocShell = GetDoc()->GetDocShell();
@@ -321,7 +572,7 @@ void SwEditShell::SetClassification(const OUString& rName, SfxClassificationPoli
uno::Reference<container::XNameAccess> xStyleFamilies(xStyleFamiliesSupplier->getStyleFamilies(), uno::UNO_QUERY);
uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"), uno::UNO_QUERY);
- std::set<OUString> aUsedPageStyles = lcl_getUsedPageStyles(this);
+ std::vector<OUString> aUsedPageStyles = lcl_getUsedPageStyles(this);
for (const OUString& rPageStyleName : aUsedPageStyles)
{
uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(rPageStyleName), uno::UNO_QUERY);
@@ -414,7 +665,7 @@ SfxWatermarkItem SwEditShell::GetWatermark()
uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xModel, uno::UNO_QUERY);
uno::Reference<container::XNameAccess> xStyleFamilies(xStyleFamiliesSupplier->getStyleFamilies(), uno::UNO_QUERY);
uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"), uno::UNO_QUERY);
- std::set<OUString> aUsedPageStyles = lcl_getUsedPageStyles(this);
+ std::vector<OUString> aUsedPageStyles = lcl_getUsedPageStyles(this);
for (const OUString& rPageStyleName : aUsedPageStyles)
{
uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(rPageStyleName), uno::UNO_QUERY);
@@ -629,7 +880,7 @@ void SwEditShell::SetWatermark(const SfxWatermarkItem& rWatermark)
uno::Reference<container::XNameAccess> xStyleFamilies(xStyleFamiliesSupplier->getStyleFamilies(), uno::UNO_QUERY);
uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"), uno::UNO_QUERY);
- std::set<OUString> aUsedPageStyles = lcl_getUsedPageStyles(this);
+ std::vector<OUString> aUsedPageStyles = lcl_getUsedPageStyles(this);
for (const OUString& rPageStyleName : aUsedPageStyles)
{
uno::Reference<beans::XPropertySet> xPageStyle(xStyleFamily->getByName(rPageStyleName), uno::UNO_QUERY);
diff --git a/sw/source/uibase/app/docsh2.cxx b/sw/source/uibase/app/docsh2.cxx
index dbcb99cb4bfc..eae9c158ff91 100644
--- a/sw/source/uibase/app/docsh2.cxx
+++ b/sw/source/uibase/app/docsh2.cxx
@@ -122,6 +122,7 @@
#include <officecfg/Office/Security.hxx>
#include <sfx2/fcontnr.hxx>
+#include <svx/ClassificationDialog.hxx>
#include "swabstdlg.hxx"
#include "watermarkdialog.hxx"
@@ -1163,6 +1164,20 @@ void SwDocShell::Execute(SfxRequest& rReq)
SAL_WARN("sw.ui", "missing parameter for SID_CLASSIFICATION_APPLY");
}
break;
+ case SID_CLASSIFICATION_DIALOG:
+ {
+ ScopedVclPtr<svx::ClassificationDialog> pDialog(VclPtr<svx::ClassificationDialog>::Create(nullptr));
+
+ SwWrtShell* pShell = GetWrtShell();
+ std::vector<svx::ClassificationResult> aInput = pShell->CollectAdvancedClassification();
+ pDialog->setupValues(aInput);
+
+ if (RET_OK == pDialog->Execute())
+ pShell->ApplyAdvancedClassification(pDialog->getResult());
+
+ pDialog.disposeAndClear();
+ }
+ break;
case SID_WATERMARK:
{
SwWrtShell* pSh = GetWrtShell();
diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx
index f78d7126faeb..a93bb5ab9ab0 100644
--- a/sw/source/uibase/app/docst.cxx
+++ b/sw/source/uibase/app/docst.cxx
@@ -272,6 +272,9 @@ void SwDocShell::StateStyleSheet(SfxItemSet& rSet, SwWrtShell* pSh)
// Just trigger ClassificationCategoriesController::statusChanged().
rSet.InvalidateItem(nWhich);
break;
+ case SID_CLASSIFICATION_DIALOG:
+ rSet.InvalidateItem(nWhich);
+ break;
case SID_STYLE_EDIT:
break;
case SID_WATERMARK:
diff --git a/sw/source/uibase/shells/basesh.cxx b/sw/source/uibase/shells/basesh.cxx
index 483ee0a003a8..e2c87f6bb156 100644
--- a/sw/source/uibase/shells/basesh.cxx
+++ b/sw/source/uibase/shells/basesh.cxx
@@ -952,6 +952,11 @@ void SwBaseShell::Execute(SfxRequest &rReq)
GetView().GetDocShell()->Execute(rReq);
}
break;
+ case SID_CLASSIFICATION_DIALOG:
+ {
+ GetView().GetDocShell()->Execute(rReq);
+ }
+ break;
case SID_WATERMARK:
{
GetView().GetDocShell()->Execute(rReq);
diff --git a/sw/uiconfig/swriter/toolbar/classificationbar.xml b/sw/uiconfig/swriter/toolbar/classificationbar.xml
index 3ee34071e040..f176c094273a 100644
--- a/sw/uiconfig/swriter/toolbar/classificationbar.xml
+++ b/sw/uiconfig/swriter/toolbar/classificationbar.xml
@@ -9,4 +9,5 @@
-->
<toolbar:toolbar xmlns:toolbar="http://openoffice.org/2001/toolbar" xmlns:xlink="http://www.w3.org/1999/xlink" toolbar:id="toolbar">
<toolbar:toolbaritem xlink:href=".uno:ClassificationApply"/>
+ <toolbar:toolbaritem xlink:href=".uno:ClassificationDialog"/>
</toolbar:toolbar>