[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sfx2/inc sfx2/source
sfx2/inc/autoredactdialog.hxx| 14 sfx2/source/doc/autoredactdialog.cxx | 120 ++- 2 files changed, 52 insertions(+), 82 deletions(-) New commits: commit 16772ff18d04af5b91d00075841b967597fae595 Author: Muhammet Kara AuthorDate: Fri Aug 23 20:29:37 2019 +0300 Commit: Muhammet Kara CommitDate: Fri Aug 23 21:35:27 2019 +0200 AutoRedaction: Adapt EditHdl And do some clean-up [NO-FORWARD-PORT] Change-Id: I8fec2acd38e0f160b22db20f6d9adc585b67c13c Reviewed-on: https://gerrit.libreoffice.org/78039 Reviewed-by: Muhammet Kara Tested-by: Muhammet Kara diff --git a/sfx2/inc/autoredactdialog.hxx b/sfx2/inc/autoredactdialog.hxx index 5af176a6f7ce..90e5ec6ad3d5 100644 --- a/sfx2/inc/autoredactdialog.hxx +++ b/sfx2/inc/autoredactdialog.hxx @@ -48,7 +48,7 @@ class TargetsTable : public SvSimpleTable public: TargetsTable(SvSimpleTableContainer& rParent); void InsertTarget(RedactionTarget* pTarget); -void SelectByName(const OUString& sName); +void InsertTargetAtPos(RedactionTarget* pTarget, const sal_uLong& nPos); RedactionTarget* GetTargetByName(const OUString& sName); OUString GetNameProposal(); }; @@ -67,7 +67,6 @@ enum class StartFileDialogType class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxModalDialog { SfxObjectShellLock m_xDocShell; -//std::vector> m_aTableTargets; std::unique_ptr m_pFileDlg; bool m_bIsValidState; bool m_bTargetsCopied; @@ -84,16 +83,14 @@ class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxModalDialog DECL_LINK(Load, Button*, void); DECL_LINK(Save, Button*, void); DECL_LINK(AddHdl, Button*, void); -//DECL_LINK(EditHdl, Button*, void); +DECL_LINK(EditHdl, Button*, void); DECL_LINK(DeleteHdl, Button*, void); DECL_LINK(LoadHdl, sfx2::FileDialogHelper*, void); DECL_LINK(SaveHdl, sfx2::FileDialogHelper*, void); void StartFileDialog(StartFileDialogType nType, const OUString& rTitle); -/// Carry out proper addition both to the targets box, and to the tabletargets vector. -/*void addTarget(RedactionTarget* pTarget);*/ -/// Clear all targets both visually and from the targets vector +/// Clear all targets both visually and from the memory void clearTargets(); public: @@ -101,11 +98,6 @@ public: virtual ~SfxAutoRedactDialog() override; virtual void dispose() override; -/// Check if the dialog has any valid redaction targets. -//bool hasTargets() const; -/// Check if the dialog is in a valid state. -//bool isValidState() const { return m_bIsValidState; } - /** Copies targets vector * Does a shallow copy. * Returns true if successful. diff --git a/sfx2/source/doc/autoredactdialog.cxx b/sfx2/source/doc/autoredactdialog.cxx index 040fb3a9dacc..cbeb8a8705a1 100644 --- a/sfx2/source/doc/autoredactdialog.cxx +++ b/sfx2/source/doc/autoredactdialog.cxx @@ -150,13 +150,34 @@ void TargetsTable::InsertTarget(RedactionTarget* pTarget) InsertEntryToColumn(sColumnData, TREELIST_APPEND, 0x, pTarget); } -void TargetsTable::SelectByName(const OUString& sName) +void TargetsTable::InsertTargetAtPos(RedactionTarget* pTarget, const sal_uLong& nPos) { -SvTreeListEntry* pEntry = GetRowByTargetName(sName); -if (!pEntry) +if (!pTarget) +{ +SAL_WARN("sfx.doc", "pTarget is null in TargetsTable::InsertTarget()"); return; +} + +// Check if the name is empty or invalid (clashing with another entry's name) +if (pTarget->sName.isEmpty() || GetRowByTargetName(pTarget->sName) != nullptr) +{ +SAL_WARN("sfx.doc", "Repetitive or empty target name in TargetsTable::InsertTarget()"); +pTarget->sName = GetNameProposal(); +} + +OUString sContent = pTarget->sContent; + +if (pTarget->sType == RedactionTargetType::REDACTION_TARGET_PREDEFINED) +{ +//selection_num;selection_name +sContent = sContent.getToken(1, ';'); +} -Select(pEntry); +OUString sColumnData = pTarget->sName + "\t" + getTypeName(pTarget->sType) + "\t" + sContent + + "\t" + (pTarget->bCaseSensitive ? OUString("Yes") : OUString("No")) + + "\t" + (pTarget->bWholeWords ? OUString("Yes") : OUString("No")); + +InsertEntryToColumn(sColumnData, nPos, 0x, pTarget); } RedactionTarget* TargetsTable::GetTargetByName(const OUString& sName) @@ -191,23 +212,6 @@ OUString TargetsTable::GetNameProposal() return sDefaultTargetName + " " + OUString::number(nHighestTargetId + 1); } -/*void TargetsTable::setRowData(const int& nRowIndex, const RedactionTarget* pTarget) -{ -OUString sContent = pTarget->sContent; - -if (pTarget->sType == RedactionTargetType::REDACTION_TARGET_PREDEFINED) -{ -//selection_num;selection_name -sContent = sContent.getToken(1, ';'); -} - -
[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sfx2/inc sfx2/source
sfx2/inc/autoredactdialog.hxx| 41 +++--- sfx2/source/doc/autoredactdialog.cxx | 228 ++- 2 files changed, 138 insertions(+), 131 deletions(-) New commits: commit 0cb4b06798975735ee812ad6ca20e3d8c5cc4ca8 Author: Muhammet Kara AuthorDate: Fri Aug 23 13:56:47 2019 +0300 Commit: Muhammet Kara CommitDate: Fri Aug 23 21:34:54 2019 +0200 AutoRedaction: Adapt AddHdl [NO-FORWARD-PORT] Change-Id: Id33ee13d8342c862bd063e2345cb14805b950e37 Reviewed-on: https://gerrit.libreoffice.org/78038 Reviewed-by: Muhammet Kara Tested-by: Muhammet Kara diff --git a/sfx2/inc/autoredactdialog.hxx b/sfx2/inc/autoredactdialog.hxx index 9399ba530a80..5af176a6f7ce 100644 --- a/sfx2/inc/autoredactdialog.hxx +++ b/sfx2/inc/autoredactdialog.hxx @@ -83,8 +83,8 @@ class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxModalDialog DECL_LINK(Load, Button*, void); DECL_LINK(Save, Button*, void); -/*DECL_LINK(AddHdl, Button*, void); -DECL_LINK(EditHdl, Button*, void);*/ +DECL_LINK(AddHdl, Button*, void); +//DECL_LINK(EditHdl, Button*, void); DECL_LINK(DeleteHdl, Button*, void); DECL_LINK(LoadHdl, sfx2::FileDialogHelper*, void); @@ -113,35 +113,34 @@ public: bool getTargets(std::vector>& r_aTargets); }; -/*class SfxAddTargetDialog : public weld::GenericDialogController +class SfxAddTargetDialog : public SfxModalDialog { private: -std::unique_ptr m_xName; -std::unique_ptr m_xType; -std::unique_ptr m_xLabelContent; -std::unique_ptr m_xContent; -std::unique_ptr m_xLabelPredefContent; -std::unique_ptr m_xPredefContent; -std::unique_ptr m_xCaseSensitive; -std::unique_ptr m_xWholeWords; +VclPtr m_pName; +VclPtr m_pType; +VclPtr m_pLabelContent; +VclPtr m_pContent; +VclPtr m_pLabelPredefContent; +VclPtr m_pPredefContent; +VclPtr m_pCaseSensitive; +VclPtr m_pWholeWords; -DECL_LINK(SelectTypeHdl, weld::ComboBox&, void); +DECL_LINK(SelectTypeHdl, ListBox&, void); public: -SfxAddTargetDialog(weld::Window* pWindow, const OUString& rName); -SfxAddTargetDialog(weld::Window* pWindow, const OUString& sName, +SfxAddTargetDialog(vcl::Window* pWindow, const OUString& rName); +SfxAddTargetDialog(vcl::Window* pWindow, const OUString& sName, const RedactionTargetType& eTargetType, const OUString& sContent, const bool& bCaseSensitive, const bool& bWholeWords); +virtual ~SfxAddTargetDialog() override; +virtual void dispose() override; -OUString getName() const { return m_xName->get_text(); } +OUString getName() const { return m_pName->GetText(); } RedactionTargetType getType() const; OUString getContent() const; -bool isCaseSensitive() const -{ -return m_xCaseSensitive->get_state() == TriState::TRISTATE_TRUE; -} -bool isWholeWords() const { return m_xWholeWords->get_state() == TriState::TRISTATE_TRUE; } -};*/ +bool isCaseSensitive() const { return m_pCaseSensitive->GetState() == TriState::TRISTATE_TRUE; } +bool isWholeWords() const { return m_pWholeWords->GetState() == TriState::TRISTATE_TRUE; } +}; #endif diff --git a/sfx2/source/doc/autoredactdialog.cxx b/sfx2/source/doc/autoredactdialog.cxx index 0bfe244e760f..040fb3a9dacc 100644 --- a/sfx2/source/doc/autoredactdialog.cxx +++ b/sfx2/source/doc/autoredactdialog.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -95,28 +96,28 @@ OUString getTypeName(RedactionTargetType nType) } /// Returns TypeID to be used in the add/edit target dialog -/*OUString getTypeID(RedactionTargetType nType) +sal_Int32 getTypeID(RedactionTargetType nType) { -OUString sTypeID("unknown"); +sal_Int32 nTypeID(-1); switch (nType) { case RedactionTargetType::REDACTION_TARGET_TEXT: -sTypeID = "text"; +nTypeID = 0; break; case RedactionTargetType::REDACTION_TARGET_REGEX: -sTypeID = "regex"; +nTypeID = 1; break; case RedactionTargetType::REDACTION_TARGET_PREDEFINED: -sTypeID = "predefined"; +nTypeID = 2; break; case RedactionTargetType::REDACTION_TARGET_UNKNOWN: -sTypeID = "unknown"; +nTypeID = -1; break; } -return sTypeID; -}*/ +return nTypeID; +} } void TargetsTable::InsertTarget(RedactionTarget* pTarget) @@ -220,17 +221,17 @@ IMPL_LINK_NOARG(SfxAutoRedactDialog, Save, Button*, void) StartFileDialog(StartFileDialogType::SaveAs, "Save Targets"); } -/*IMPL_LINK_NOARG(SfxAutoRedactDialog, AddHdl, Button*, void) +IMPL_LINK_NOARG(SfxAutoRedactDialog, AddHdl, Button*, void) { // Open the Add Target dialog, craete a new target and insert into the targets vector and the listbox -SfxAddTargetDialog aAddTargetDialog(getDialog(),
[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sfx2/inc sfx2/source
sfx2/inc/autoredactdialog.hxx|8 ++-- sfx2/source/doc/autoredactdialog.cxx | 66 ++- 2 files changed, 46 insertions(+), 28 deletions(-) New commits: commit 9fc2afbb2a10e29617791005168b64a881ebfb3f Author: Muhammet Kara AuthorDate: Fri Aug 23 10:31:34 2019 +0300 Commit: Muhammet Kara CommitDate: Fri Aug 23 21:34:23 2019 +0200 AutoRedaction: Adapt Save & DeleteHdl [NO-FORWARD-PORT] Change-Id: I0feeed87cc69f364980657f5b6a2dfdee05ce2f3 Reviewed-on: https://gerrit.libreoffice.org/78037 Reviewed-by: Muhammet Kara Tested-by: Muhammet Kara diff --git a/sfx2/inc/autoredactdialog.hxx b/sfx2/inc/autoredactdialog.hxx index b128e9d67634..9399ba530a80 100644 --- a/sfx2/inc/autoredactdialog.hxx +++ b/sfx2/inc/autoredactdialog.hxx @@ -82,10 +82,10 @@ class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxModalDialog VclPtr m_pDeleteBtn; DECL_LINK(Load, Button*, void); -/*DECL_LINK(Save, Button*, void); -DECL_LINK(AddHdl, Button*, void); -DECL_LINK(EditHdl, Button*, void); -DECL_LINK(DeleteHdl, Button*, void);*/ +DECL_LINK(Save, Button*, void); +/*DECL_LINK(AddHdl, Button*, void); +DECL_LINK(EditHdl, Button*, void);*/ +DECL_LINK(DeleteHdl, Button*, void); DECL_LINK(LoadHdl, sfx2::FileDialogHelper*, void); DECL_LINK(SaveHdl, sfx2::FileDialogHelper*, void); diff --git a/sfx2/source/doc/autoredactdialog.cxx b/sfx2/source/doc/autoredactdialog.cxx index b62cb249b426..0bfe244e760f 100644 --- a/sfx2/source/doc/autoredactdialog.cxx +++ b/sfx2/source/doc/autoredactdialog.cxx @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -213,13 +214,13 @@ IMPL_LINK_NOARG(SfxAutoRedactDialog, Load, Button*, void) StartFileDialog(StartFileDialogType::Open, "Load Targets"); } -/*IMPL_LINK_NOARG(SfxAutoRedactDialog, Save, Button*, void) +IMPL_LINK_NOARG(SfxAutoRedactDialog, Save, Button*, void) { //Allow saving the targets into a file StartFileDialog(StartFileDialogType::SaveAs, "Save Targets"); } -IMPL_LINK_NOARG(SfxAutoRedactDialog, AddHdl, Button*, void) +/*IMPL_LINK_NOARG(SfxAutoRedactDialog, AddHdl, Button*, void) { // Open the Add Target dialog, craete a new target and insert into the targets vector and the listbox SfxAddTargetDialog aAddTargetDialog(getDialog(), m_xTargetsBox->GetNameProposal()); @@ -342,39 +343,47 @@ IMPL_LINK_NOARG(SfxAutoRedactDialog, EditHdl, Button*, void) // And sync the targets box row with the actual target data m_xTargetsBox->setRowData(nSelectedRow, pTarget); -} +}*/ IMPL_LINK_NOARG(SfxAutoRedactDialog, DeleteHdl, Button*, void) { -std::vector aSelectedRows = m_xTargetsBox->get_selected_rows(); +sal_uLong nSelectionCount = m_pTargetsBox->GetSelectionCount(); //No selection, so nothing to delete -if (aSelectedRows.empty()) +if (nSelectionCount < 1) return; -if (aSelectedRows.size() > 1) +if (nSelectionCount > 1) { -OUString sMsg("Are you sure you would like to delete " - + OUString::number(aSelectedRows.size()) + " targets at once?"); +OUString sMsg("Are you sure you would like to delete " + OUString::number(nSelectionCount) + + " targets at once?"); + //Warn the user about multiple deletions -std::unique_ptr xBox(Application::CreateMessageDialog( -getDialog(), VclMessageType::Question, VclButtonsType::OkCancel, sMsg)); -if (xBox->run() == RET_CANCEL) +if (ScopedVclPtrInstance(this, MessBoxStyle::OkCancel, sMsg)->Execute() +== RET_CANCEL) return; } -// After each delete, the indexes of the following items decrease by one. -int delta = 0; -for (const auto& i : aSelectedRows) +SvTreeListEntry* pSelected = m_pTargetsBox->FirstSelected(); + +for (sal_uLong i = nSelectionCount; i > 0; i--) { -m_aTableTargets.erase(m_aTableTargets.begin() + (i - delta)); -m_xTargetsBox->remove(i - delta++); +// remove the target +RedactionTarget* pTarget = static_cast(pSelected->GetUserData()); +delete pTarget; + +// remove from the table +SvTreeListEntry* nextSelected = m_pTargetsBox->NextSelected(pSelected); +m_pTargetsBox->RemoveEntry(pSelected); +pSelected = nextSelected; } -}*/ + +m_pTargetsBox->SelectAll(false); +} namespace { -/*boost::property_tree::ptree redactionTargetToJSON(RedactionTarget* pTarget) +boost::property_tree::ptree redactionTargetToJSON(RedactionTarget* pTarget) { boost::property_tree::ptree aNode; aNode.put("sName", pTarget->sName.toUtf8().getStr()); @@ -385,7 +394,7 @@ namespace aNode.put("nID", pTarget->nID); return aNode; -}*/ +} RedactionTarget* JSONtoRedactionTarget(const boost::property_tree::ptree::value_type& rValue) { @@ -456,7 +465,7 @@
[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sfx2/inc sfx2/source
sfx2/inc/autoredactdialog.hxx| 14 +++--- sfx2/source/doc/autoredactdialog.cxx | 78 ++- sfx2/source/doc/objserv.cxx |2 3 files changed, 58 insertions(+), 36 deletions(-) New commits: commit 9b63b1a51e7cd11a7450f2dc4f70aa561a46b4da Author: Muhammet Kara AuthorDate: Wed Aug 21 22:22:15 2019 +0300 Commit: Muhammet Kara CommitDate: Fri Aug 23 21:33:20 2019 +0200 AutoRedaction: Adapt Load And enable getTargets() [NO-FORWARD-PORT] Change-Id: I6f6fb690183e54bef8f4cb5b21c625ff757fd16e Reviewed-on: https://gerrit.libreoffice.org/77935 Reviewed-by: Muhammet Kara Tested-by: Muhammet Kara diff --git a/sfx2/inc/autoredactdialog.hxx b/sfx2/inc/autoredactdialog.hxx index 0011166e631a..b128e9d67634 100644 --- a/sfx2/inc/autoredactdialog.hxx +++ b/sfx2/inc/autoredactdialog.hxx @@ -67,7 +67,7 @@ enum class StartFileDialogType class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxModalDialog { SfxObjectShellLock m_xDocShell; -std::vector> m_aTableTargets; +//std::vector> m_aTableTargets; std::unique_ptr m_pFileDlg; bool m_bIsValidState; bool m_bTargetsCopied; @@ -81,20 +81,20 @@ class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxModalDialog VclPtr m_pEditBtn; VclPtr m_pDeleteBtn; -/*DECL_LINK(Load, Button*, void); -DECL_LINK(Save, Button*, void); +DECL_LINK(Load, Button*, void); +/*DECL_LINK(Save, Button*, void); DECL_LINK(AddHdl, Button*, void); DECL_LINK(EditHdl, Button*, void); -DECL_LINK(DeleteHdl, Button*, void); +DECL_LINK(DeleteHdl, Button*, void);*/ DECL_LINK(LoadHdl, sfx2::FileDialogHelper*, void); DECL_LINK(SaveHdl, sfx2::FileDialogHelper*, void); void StartFileDialog(StartFileDialogType nType, const OUString& rTitle); /// Carry out proper addition both to the targets box, and to the tabletargets vector. -void addTarget(RedactionTarget* pTarget); +/*void addTarget(RedactionTarget* pTarget);*/ /// Clear all targets both visually and from the targets vector -void clearTargets();*/ +void clearTargets(); public: SfxAutoRedactDialog(vcl::Window* pParent); @@ -110,7 +110,7 @@ public: * Does a shallow copy. * Returns true if successful. */ -//bool getTargets(std::vector>& r_aTargets); +bool getTargets(std::vector>& r_aTargets); }; /*class SfxAddTargetDialog : public weld::GenericDialogController diff --git a/sfx2/source/doc/autoredactdialog.cxx b/sfx2/source/doc/autoredactdialog.cxx index bd8c4dfcd646..b62cb249b426 100644 --- a/sfx2/source/doc/autoredactdialog.cxx +++ b/sfx2/source/doc/autoredactdialog.cxx @@ -204,7 +204,7 @@ OUString TargetsTable::GetNameProposal() m_xControl->set_text(nRowIndex, sContent, 2); m_xControl->set_text(nRowIndex, pTarget->bCaseSensitive ? OUString("Yes") : OUString("No"), 3); m_xControl->set_text(nRowIndex, pTarget->bWholeWords ? OUString("Yes") : OUString("No"), 4); -} +}*/ IMPL_LINK_NOARG(SfxAutoRedactDialog, Load, Button*, void) { @@ -213,7 +213,7 @@ IMPL_LINK_NOARG(SfxAutoRedactDialog, Load, Button*, void) StartFileDialog(StartFileDialogType::Open, "Load Targets"); } -IMPL_LINK_NOARG(SfxAutoRedactDialog, Save, Button*, void) +/*IMPL_LINK_NOARG(SfxAutoRedactDialog, Save, Button*, void) { //Allow saving the targets into a file StartFileDialog(StartFileDialogType::SaveAs, "Save Targets"); @@ -370,11 +370,11 @@ IMPL_LINK_NOARG(SfxAutoRedactDialog, DeleteHdl, Button*, void) m_aTableTargets.erase(m_aTableTargets.begin() + (i - delta)); m_xTargetsBox->remove(i - delta++); } -} +}*/ namespace { -boost::property_tree::ptree redactionTargetToJSON(RedactionTarget* pTarget) +/*boost::property_tree::ptree redactionTargetToJSON(RedactionTarget* pTarget) { boost::property_tree::ptree aNode; aNode.put("sName", pTarget->sName.toUtf8().getStr()); @@ -385,7 +385,7 @@ boost::property_tree::ptree redactionTargetToJSON(RedactionTarget* pTarget) aNode.put("nID", pTarget->nID); return aNode; -} +}*/ RedactionTarget* JSONtoRedactionTarget(const boost::property_tree::ptree::value_type& rValue) { @@ -421,7 +421,7 @@ IMPL_LINK_NOARG(SfxAutoRedactDialog, LoadHdl, sfx2::FileDialogHelper*, void) osl::File::getSystemPathFromFileURL(sTargetsFile, sSysPath); sTargetsFile = sSysPath; -weld::WaitObject aWaitObject(getDialog()); +EnterWait(); try { @@ -440,7 +440,7 @@ IMPL_LINK_NOARG(SfxAutoRedactDialog, LoadHdl, sfx2::FileDialogHelper*, void) aTargetsJSON.get_child("RedactionTargets")) { RedactionTarget* pTarget = JSONtoRedactionTarget(rValue); -addTarget(pTarget); +m_pTargetsBox->InsertTarget(pTarget); } } catch (css::uno::Exception& e) @@ -450,11 +450,13 @@ IMPL_LINK_NOARG(SfxAutoRedactDialog, LoadHdl, sfx2::FileDialogHelper*, void)
[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sfx2/inc sfx2/source sfx2/uiconfig
sfx2/inc/autoredactdialog.hxx| 14 - sfx2/source/doc/autoredactdialog.cxx | 92 + sfx2/uiconfig/ui/autoredactdialog.ui | 325 +-- 3 files changed, 184 insertions(+), 247 deletions(-) New commits: commit b4e0f730e274d634f6548a16ca1573a5b1f7f7a3 Author: Muhammet Kara AuthorDate: Wed Aug 21 09:59:03 2019 +0300 Commit: Muhammet Kara CommitDate: Thu Aug 22 12:24:55 2019 +0200 AutoRedaction: Adapt Targets Box [NO-FORWARD-PORT] Change-Id: I574e3a332efe1af50bc590fd6f805cacc7667069 Reviewed-on: https://gerrit.libreoffice.org/77890 Tested-by: Jenkins CollaboraOffice Reviewed-by: Muhammet Kara diff --git a/sfx2/inc/autoredactdialog.hxx b/sfx2/inc/autoredactdialog.hxx index 7c9f35c11cf1..0011166e631a 100644 --- a/sfx2/inc/autoredactdialog.hxx +++ b/sfx2/inc/autoredactdialog.hxx @@ -41,7 +41,7 @@ struct RedactionTarget }; /// Used to display the targets list -/*class TargetsTable : public SvSimpleTable +class TargetsTable : public SvSimpleTable { SvTreeListEntry* GetRowByTargetName(const OUString& sName); @@ -51,13 +51,7 @@ public: void SelectByName(const OUString& sName); RedactionTarget* GetTargetByName(const OUString& sName); OUString GetNameProposal(); - -// Sync data on the targets box with the data on the target -void setRowData(SvTreeListEntry* pRow, const RedactionTarget* pTarget); - -//void connect_changed(const Link& rLink) { m_xControl->connect_changed(rLink); } -//void connect_row_activated(const Link& rLink) { m_xControl->connect_row_activated(rLink); } -};*/ +}; namespace sfx2 { @@ -78,8 +72,8 @@ class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxModalDialog bool m_bIsValidState; bool m_bTargetsCopied; -//VclPtr m_pTargetsContainer; -//VclPtrm_pTargetsBox; +VclPtr m_pTargetsContainer; +VclPtr m_pTargetsBox; VclPtr m_pRedactionTargetsLabel; VclPtr m_pLoadBtn; VclPtr m_pSaveBtn; diff --git a/sfx2/source/doc/autoredactdialog.cxx b/sfx2/source/doc/autoredactdialog.cxx index fdf7ee673c1d..bd8c4dfcd646 100644 --- a/sfx2/source/doc/autoredactdialog.cxx +++ b/sfx2/source/doc/autoredactdialog.cxx @@ -31,36 +31,41 @@ #include #include +#include + #include #include -/*int TargetsTable::GetRowByTargetName(const OUString& sName) +SvTreeListEntry* TargetsTable::GetRowByTargetName(const OUString& sName) { -for (int i = 0, nCount = m_xControl->n_children(); i < nCount; ++i) +SvTreeListEntry* pEntry = First(); +while (pEntry) { -RedactionTarget* pTarget -= reinterpret_cast(m_xControl->get_id(i).toInt64()); +RedactionTarget* pTarget = static_cast(pEntry->GetUserData()); if (pTarget->sName == sName) { -return i; +return pEntry; } +pEntry = Next(pEntry); } -return -1; +return nullptr; } -TargetsTable::TargetsTable(std::unique_ptr xControl) -: m_xControl(std::move(xControl)) -{ -m_xControl->set_size_request(555, 250); -std::vector aWidths; -aWidths.push_back(100); -aWidths.push_back(50); -aWidths.push_back(200); -aWidths.push_back(105); -aWidths.push_back(105); -m_xControl->set_column_fixed_widths(aWidths); -m_xControl->set_selection_mode(SelectionMode::Multiple); +TargetsTable::TargetsTable(SvSimpleTableContainer& rParent) +: SvSimpleTable(rParent, 0) +{ +static long nTabs[] = { 5, 0, 100, 150, 350, 455 }; + +SetTabs(nTabs, MapUnit::MapPixel); +SetSelectionMode(SelectionMode::Multiple); +InsertHeaderEntry("Target Name"); +InsertHeaderEntry("Type"); +InsertHeaderEntry("Content"); +InsertHeaderEntry("Case Sensitive"); +InsertHeaderEntry("Whole Words"); + +rParent.SetTable(this); } namespace @@ -89,7 +94,7 @@ OUString getTypeName(RedactionTargetType nType) } /// Returns TypeID to be used in the add/edit target dialog -OUString getTypeID(RedactionTargetType nType) +/*OUString getTypeID(RedactionTargetType nType) { OUString sTypeID("unknown"); @@ -110,7 +115,7 @@ OUString getTypeID(RedactionTargetType nType) } return sTypeID; -} +}*/ } void TargetsTable::InsertTarget(RedactionTarget* pTarget) @@ -122,8 +127,9 @@ void TargetsTable::InsertTarget(RedactionTarget* pTarget) } // Check if the name is empty or invalid (clashing with another entry's name) -if (pTarget->sName.isEmpty() || GetRowByTargetName(pTarget->sName) != -1) +if (pTarget->sName.isEmpty() || GetRowByTargetName(pTarget->sName) != nullptr) { +SAL_WARN("sfx.doc", "Repetitive or empty target name in TargetsTable::InsertTarget()"); pTarget->sName = GetNameProposal(); } @@ -135,30 +141,29 @@ void TargetsTable::InsertTarget(RedactionTarget* pTarget) sContent = sContent.getToken(1, ';'); } -// Add to the end -int nRow =
[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sfx2/inc sfx2/source
sfx2/inc/SfxRedactionHelper.hxx| 12 sfx2/inc/autoredactdialog.hxx | 86 +++-- sfx2/source/doc/SfxRedactionHelper.cxx | 15 + sfx2/source/doc/autoredactdialog.cxx | 60 +-- sfx2/source/doc/objserv.cxx| 16 -- 5 files changed, 90 insertions(+), 99 deletions(-) New commits: commit c02978727b3827547dde9b4d7d5c1d08341f4034 Author: Muhammet Kara AuthorDate: Thu Aug 8 19:15:13 2019 +0300 Commit: Muhammet Kara CommitDate: Sat Aug 17 18:08:28 2019 +0200 Make AutoRedactDialog buildable again Change-Id: I3161df87dc35fb6677d9886f45b50ae98d6994a0 Reviewed-on: https://gerrit.libreoffice.org/77171 Tested-by: Jenkins CollaboraOffice Reviewed-by: Muhammet Kara diff --git a/sfx2/inc/SfxRedactionHelper.hxx b/sfx2/inc/SfxRedactionHelper.hxx index ae72c39f4886..61578438ae35 100644 --- a/sfx2/inc/SfxRedactionHelper.hxx +++ b/sfx2/inc/SfxRedactionHelper.hxx @@ -122,18 +122,6 @@ public: const RedactionTarget* pTarget); private: -static constexpr OUStringLiteral m_aPredefinedTargets[6] = { -"\\b(?:\\d[ -]*?){13,16}\\b", //Credit card numbers -"\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}\\b", //Email addresses - "\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" - "\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" -"\\b", //IP addresses -"([12]\\d{3}[./-](0[1-9]|1[0-2])[./" - "-](0[1-9]|[12]\\d|3[01]))|((0[1-9]|[12]\\d|3[01])[./-](0[1-9]|1[0-2])[./" -"-][12]\\d{3})", //Dates (numerical) -"\\s*[a-zA-Z]{2}(?:\\s*\\d\\s*){6}[a-zA-Z]?\\s*", //National Insurance Number (UK) -"([1-9])(?!\\1{2}-\\1{2}-\\1{4})[1-9]{2}-[1-9]{2}-[1-9]{4}" //Social Security Number (US) -}; }; #endif // INCLUDED_CUI_SOURCE_INC_SFXREDACTIONHELPER_HXX diff --git a/sfx2/inc/autoredactdialog.hxx b/sfx2/inc/autoredactdialog.hxx index 92010071b185..7c9f35c11cf1 100644 --- a/sfx2/inc/autoredactdialog.hxx +++ b/sfx2/inc/autoredactdialog.hxx @@ -19,26 +19,7 @@ #include #include -namespace weld -{ -class Button; -} -namespace weld -{ -class ComboBox; -} -namespace weld -{ -class Label; -} -namespace weld -{ -class Window; -} -namespace weld -{ -class TreeView; -} +#include enum RedactionTargetType { @@ -60,34 +41,23 @@ struct RedactionTarget }; /// Used to display the targets list -class TargetsTable +/*class TargetsTable : public SvSimpleTable { -std::unique_ptr m_xControl; -int GetRowByTargetName(const OUString& sName); +SvTreeListEntry* GetRowByTargetName(const OUString& sName); public: -TargetsTable(std::unique_ptr xControl); +TargetsTable(SvSimpleTableContainer& rParent); void InsertTarget(RedactionTarget* pTarget); void SelectByName(const OUString& sName); RedactionTarget* GetTargetByName(const OUString& sName); OUString GetNameProposal(); -void unselect_all() { m_xControl->unselect_all(); } -bool has_focus() const { return m_xControl->has_focus(); } -int n_children() const { return m_xControl->n_children(); } -int get_selected_index() const { return m_xControl->get_selected_index(); } -std::vector get_selected_rows() const { return m_xControl->get_selected_rows(); } -void clear() { m_xControl->clear(); } -void remove(int nRow) { m_xControl->remove(nRow); } -void select(int nRow) { m_xControl->select(nRow); } -OUString get_id(int nRow) const { return m_xControl->get_id(nRow); } - // Sync data on the targets box with the data on the target -void setRowData(const int& nRowIndex, const RedactionTarget* pTarget); +void setRowData(SvTreeListEntry* pRow, const RedactionTarget* pTarget); //void connect_changed(const Link& rLink) { m_xControl->connect_changed(rLink); } //void connect_row_activated(const Link& rLink) { m_xControl->connect_row_activated(rLink); } -}; +};*/ namespace sfx2 { @@ -100,7 +70,7 @@ enum class StartFileDialogType SaveAs }; -class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxDialogController +class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxModalDialog { SfxObjectShellLock m_xDocShell; std::vector> m_aTableTargets; @@ -108,19 +78,20 @@ class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxDialogController bool m_bIsValidState; bool m_bTargetsCopied; -std::unique_ptr m_xRedactionTargetsLabel; -std::unique_ptr m_xTargetsBox; -std::unique_ptr m_xLoadBtn; -std::unique_ptr m_xSaveBtn; -std::unique_ptr m_xAddBtn; -std::unique_ptr m_xEditBtn; -std::unique_ptr m_xDeleteBtn; - -DECL_LINK(Load, weld::Button&, void); -DECL_LINK(Save, weld::Button&, void); -DECL_LINK(AddHdl, weld::Button&, void); -DECL_LINK(EditHdl, weld::Button&, void); -DECL_LINK(DeleteHdl, weld::Button&, void); +//VclPtr
[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sfx2/inc sfx2/source sfx2/uiconfig
sfx2/inc/SfxRedactionHelper.hxx| 14 + sfx2/inc/autoredactdialog.hxx |7 ++ sfx2/source/doc/SfxRedactionHelper.cxx | 17 +- sfx2/source/doc/autoredactdialog.cxx | 89 +++-- sfx2/uiconfig/ui/addtargetdialog.ui| 52 +-- 5 files changed, 167 insertions(+), 12 deletions(-) New commits: commit 9ef2b684647472f6774243df79493fee59f78095 Author: Muhammet Kara AuthorDate: Sat Jun 15 12:08:35 2019 +0300 Commit: Muhammet Kara CommitDate: Sat Aug 17 16:40:38 2019 +0200 Add predefined targets to auto redaction Change-Id: Ib8cf8b50944667d6a87a5cafb6995ad195699358 Reviewed-on: https://gerrit.libreoffice.org/74092 Tested-by: Jenkins Reviewed-by: Muhammet Kara Reviewed-on: https://gerrit.libreoffice.org/77165 Tested-by: Muhammet Kara diff --git a/sfx2/inc/SfxRedactionHelper.hxx b/sfx2/inc/SfxRedactionHelper.hxx index 2f470386d2dc..ae72c39f4886 100644 --- a/sfx2/inc/SfxRedactionHelper.hxx +++ b/sfx2/inc/SfxRedactionHelper.hxx @@ -120,6 +120,20 @@ public: /// Fill the search options based on the given redaction target static void fillSearchOptions(i18nutil::SearchOptions2& rSearchOpt, const RedactionTarget* pTarget); + +private: +static constexpr OUStringLiteral m_aPredefinedTargets[6] = { +"\\b(?:\\d[ -]*?){13,16}\\b", //Credit card numbers +"\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}\\b", //Email addresses + "\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" + "\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" +"\\b", //IP addresses +"([12]\\d{3}[./-](0[1-9]|1[0-2])[./" + "-](0[1-9]|[12]\\d|3[01]))|((0[1-9]|[12]\\d|3[01])[./-](0[1-9]|1[0-2])[./" +"-][12]\\d{3})", //Dates (numerical) +"\\s*[a-zA-Z]{2}(?:\\s*\\d\\s*){6}[a-zA-Z]?\\s*", //National Insurance Number (UK) +"([1-9])(?!\\1{2}-\\1{2}-\\1{4})[1-9]{2}-[1-9]{2}-[1-9]{4}" //Social Security Number (US) +}; }; #endif // INCLUDED_CUI_SOURCE_INC_SFXREDACTIONHELPER_HXX diff --git a/sfx2/inc/autoredactdialog.hxx b/sfx2/inc/autoredactdialog.hxx index bab00cf536a3..2cec20cc64c8 100644 --- a/sfx2/inc/autoredactdialog.hxx +++ b/sfx2/inc/autoredactdialog.hxx @@ -155,10 +155,15 @@ class SfxAddTargetDialog : public weld::GenericDialogController private: std::unique_ptr m_xName; std::unique_ptr m_xType; +std::unique_ptr m_xLabelContent; std::unique_ptr m_xContent; +std::unique_ptr m_xLabelPredefContent; +std::unique_ptr m_xPredefContent; std::unique_ptr m_xCaseSensitive; std::unique_ptr m_xWholeWords; +DECL_LINK(SelectTypeHdl, weld::ComboBox&, void); + public: SfxAddTargetDialog(weld::Window* pWindow, const OUString& rName); SfxAddTargetDialog(weld::Window* pWindow, const OUString& sName, @@ -167,7 +172,7 @@ public: OUString getName() const { return m_xName->get_text(); } RedactionTargetType getType() const; -OUString getContent() const { return m_xContent->get_text(); } +OUString getContent() const; bool isCaseSensitive() const { return m_xCaseSensitive->get_state() == TriState::TRISTATE_TRUE; diff --git a/sfx2/source/doc/SfxRedactionHelper.cxx b/sfx2/source/doc/SfxRedactionHelper.cxx index 1ce83b25e295..6fff84c6b5da 100644 --- a/sfx2/source/doc/SfxRedactionHelper.cxx +++ b/sfx2/source/doc/SfxRedactionHelper.cxx @@ -531,7 +531,8 @@ void SfxRedactionHelper::fillSearchOptions(i18nutil::SearchOptions2& rSearchOpt, return; } -if (pTarget->sType == RedactionTargetType::REDACTION_TARGET_REGEX) +if (pTarget->sType == RedactionTargetType::REDACTION_TARGET_REGEX +|| pTarget->sType == RedactionTargetType::REDACTION_TARGET_PREDEFINED) { rSearchOpt.algorithmType = util::SearchAlgorithms_REGEXP; rSearchOpt.AlgorithmType2 = util::SearchAlgorithms2::REGEXP; @@ -543,10 +544,20 @@ void SfxRedactionHelper::fillSearchOptions(i18nutil::SearchOptions2& rSearchOpt, } rSearchOpt.Locale = GetAppLanguageTag().getLocale(); -rSearchOpt.searchString = pTarget->sContent; +if (pTarget->sType == RedactionTargetType::REDACTION_TARGET_PREDEFINED) +{ +sal_Int32 nPredefIndex = pTarget->sContent.getToken(0, ';').toInt32(); +//sal_Int32 nPredefIndex = sContent.toInt32(); + +rSearchOpt.searchString = m_aPredefinedTargets[nPredefIndex]; +} +else +rSearchOpt.searchString = pTarget->sContent; + rSearchOpt.replaceString.clear(); -if (!pTarget->bCaseSensitive && pTarget->sType != RedactionTargetType::REDACTION_TARGET_REGEX) +if (!pTarget->bCaseSensitive && pTarget->sType != RedactionTargetType::REDACTION_TARGET_REGEX +&& pTarget->sType != RedactionTargetType::REDACTION_TARGET_PREDEFINED) rSearchOpt.transliterateFlags |=
[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sfx2/inc sfx2/source
sfx2/inc/SfxRedactionHelper.hxx| 11 +++ sfx2/source/doc/SfxRedactionHelper.cxx | 92 ++--- 2 files changed, 85 insertions(+), 18 deletions(-) New commits: commit 122ee5952f80816817d9485f3b8f6b07ca189cc3 Author: Muhammet Kara AuthorDate: Thu Jun 13 18:32:27 2019 +0300 Commit: Muhammet Kara CommitDate: Sat Aug 17 16:40:11 2019 +0200 Use utl::TextSearch in the auto redaction process * Add support for: * Case sensitive and insensitive text search * Regex search (always case sensitive) regarless of the choice * Multiple occurences of the same target on a single TEXTARRAY Change-Id: I580059f77286e8c4226cafdd1eb9472f8e1a9a9d Reviewed-on: https://gerrit.libreoffice.org/74049 Tested-by: Jenkins Reviewed-by: Muhammet Kara Reviewed-on: https://gerrit.libreoffice.org/77164 Tested-by: Muhammet Kara diff --git a/sfx2/inc/SfxRedactionHelper.hxx b/sfx2/inc/SfxRedactionHelper.hxx index 9be54ca8ac22..2f470386d2dc 100644 --- a/sfx2/inc/SfxRedactionHelper.hxx +++ b/sfx2/inc/SfxRedactionHelper.hxx @@ -33,6 +33,11 @@ class DocumentToGraphicRenderer; class SfxViewFrame; struct RedactionTarget; +namespace i18nutil +{ +struct SearchOptions2; +} + struct PageMargins { // Page margins in mm100th @@ -92,7 +97,7 @@ public: * */ static PageMargins getPageMarginsForCalc(css::uno::Reference& xModel); -static void searchInMetaFile(const OUString& sSearchTerm, const GDIMetaFile& rMtf, +static void searchInMetaFile(const RedactionTarget* pRedactionTarget, const GDIMetaFile& rMtf, std::vector& aRedactionRectangles, uno::Reference& xComponent); @@ -111,6 +116,10 @@ public: const GDIMetaFile& rGDIMetaFile, uno::Reference& xPage, uno::Reference& xComponent); + +/// Fill the search options based on the given redaction target +static void fillSearchOptions(i18nutil::SearchOptions2& rSearchOpt, + const RedactionTarget* pTarget); }; #endif // INCLUDED_CUI_SOURCE_INC_SFXREDACTIONHELPER_HXX diff --git a/sfx2/source/doc/SfxRedactionHelper.cxx b/sfx2/source/doc/SfxRedactionHelper.cxx index b9049c2b6d7b..1ce83b25e295 100644 --- a/sfx2/source/doc/SfxRedactionHelper.cxx +++ b/sfx2/source/doc/SfxRedactionHelper.cxx @@ -24,6 +24,18 @@ #include #include +// Search util +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include #include #include @@ -114,7 +126,7 @@ void setPageMargins(uno::Reference& xPageProperySet, // #i10613# Extracted from ImplCheckRect::ImplCreate tools::Rectangle ImplCalcActionBounds(const MetaAction& rAct, const OutputDevice& rOut, - const OUString& sSubString, const sal_Int32& nStrPos) + const sal_Int32& nStrStartPos, const sal_Int32& nStrEndPos) { tools::Rectangle aActionBounds; @@ -129,17 +141,16 @@ tools::Rectangle ImplCalcActionBounds(const MetaAction& rAct, const OutputDevice { // #105987# ImplLayout takes everything in logical coordinates std::unique_ptr pSalLayout1 = rOut.ImplLayout( -aString, 0, nStrPos, rTextAct.GetPoint(), 0, rTextAct.GetDXArray()); -std::unique_ptr pSalLayout2 -= rOut.ImplLayout(aString, 0, nStrPos + sSubString.getLength(), - rTextAct.GetPoint(), 0, rTextAct.GetDXArray()); +aString, 0, nStrStartPos, rTextAct.GetPoint(), 0, rTextAct.GetDXArray()); +std::unique_ptr pSalLayout2 = rOut.ImplLayout( +aString, 0, nStrEndPos, rTextAct.GetPoint(), 0, rTextAct.GetDXArray()); if (pSalLayout2) { tools::Rectangle aBoundRect2( const_cast(rOut).ImplGetTextBoundRect(*pSalLayout2)); aActionBounds = rOut.PixelToLogic(aBoundRect2); } -if (pSalLayout1 && nStrPos > 0) +if (pSalLayout1 && nStrStartPos > 0) { tools::Rectangle aBoundRect1( const_cast(rOut).ImplGetTextBoundRect(*pSalLayout1)); @@ -407,10 +418,17 @@ SfxRedactionHelper::getPageMarginsForCalc(css::uno::Reference& aRedactionRectangles, uno::Reference& xComponent) { +// Initialize search +i18nutil::SearchOptions2 aSearchOptions; +fillSearchOptions(aSearchOptions, pRedactionTarget); + +utl::TextSearch textSearch(aSearchOptions); + MetaAction* pCurrAct; // Watch for TEXTARRAY actions. @@ -422,22 +440,28 @@ void SfxRedactionHelper::searchInMetaFile(const rtl::OUString&
[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sfx2/inc sfx2/source
sfx2/inc/autoredactdialog.hxx| 21 - sfx2/source/doc/autoredactdialog.cxx | 142 +-- 2 files changed, 138 insertions(+), 25 deletions(-) New commits: commit 53bfc6452528e87a68c0ca1bfda601053cdfec03 Author: Muhammet Kara AuthorDate: Sat Jun 8 23:27:56 2019 +0300 Commit: Muhammet Kara CommitDate: Sat Aug 17 16:38:53 2019 +0200 Auto redaction dialog 4th iteration * Add the Save & SaveHdl handlers * Add stubs for Load & LoadHdl handlers Change-Id: I5f58213c86e99f8bfc9075e04eedbb5cb546d9ad Reviewed-on: https://gerrit.libreoffice.org/73724 Tested-by: Jenkins Reviewed-by: Muhammet Kara Reviewed-on: https://gerrit.libreoffice.org/77161 Tested-by: Muhammet Kara diff --git a/sfx2/inc/autoredactdialog.hxx b/sfx2/inc/autoredactdialog.hxx index 267427c90b21..99c956246d69 100644 --- a/sfx2/inc/autoredactdialog.hxx +++ b/sfx2/inc/autoredactdialog.hxx @@ -89,10 +89,22 @@ public: //void connect_row_activated(const Link& rLink) { m_xControl->connect_row_activated(rLink); } }; +namespace sfx2 +{ +class FileDialogHelper; +} + +enum class StartFileDialogType +{ +Open, +SaveAs +}; + class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxDialogController { SfxObjectShellLock m_xDocShell; std::vector> m_aTableTargets; +std::unique_ptr m_pFileDlg; std::unique_ptr m_xRedactionTargetsLabel; std::unique_ptr m_xTargetsBox; @@ -102,12 +114,17 @@ class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxDialogController std::unique_ptr m_xEditBtn; std::unique_ptr m_xDeleteBtn; -/*DECL_LINK(LoadHdl, weld::Button&, void); -DECL_LINK(SaveHdl, weld::Button&, void);*/ +DECL_LINK(Load, weld::Button&, void); +DECL_LINK(Save, weld::Button&, void); DECL_LINK(AddHdl, weld::Button&, void); DECL_LINK(EditHdl, weld::Button&, void); DECL_LINK(DeleteHdl, weld::Button&, void); +DECL_LINK(LoadHdl, sfx2::FileDialogHelper*, void); +DECL_LINK(SaveHdl, sfx2::FileDialogHelper*, void); + +void StartFileDialog(StartFileDialogType nType, const OUString& rTitle); + public: SfxAutoRedactDialog(weld::Window* pParent); virtual ~SfxAutoRedactDialog() override; diff --git a/sfx2/source/doc/autoredactdialog.cxx b/sfx2/source/doc/autoredactdialog.cxx index 266859a129ec..7c414cfc3189 100644 --- a/sfx2/source/doc/autoredactdialog.cxx +++ b/sfx2/source/doc/autoredactdialog.cxx @@ -7,31 +7,34 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include +#include +#include #include #include -#include -#include -#include -#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include #include #include +#include +#include +#include -#include +#include + +#include int TargetsTable::GetRowByTargetName(const OUString& sName) { @@ -180,17 +183,20 @@ void TargetsTable::setRowData(const int& nRowIndex, const RedactionTarget* pTarg m_xControl->set_text(nRowIndex, pTarget->bWholeWords ? OUString("Yes") : OUString("No"), 4); } -/*IMPL_LINK_NOARG(SfxAutoRedactDialog, LoadHdl, weld::Button&, void) +IMPL_LINK_NOARG(SfxAutoRedactDialog, Load, weld::Button&, void) { //TODO: Implement -//Load a targets list from a previously saved file (a json file in the user profile dir?) +//Load a targets list from a previously saved file (a json file?) +// ask for filename, where we should load the new config data from +StartFileDialog(StartFileDialogType::Open, "Load Targets"); } -IMPL_LINK_NOARG(SfxAutoRedactDialog, SaveHdl, weld::Button&, void) +IMPL_LINK_NOARG(SfxAutoRedactDialog, Save, weld::Button&, void) { //TODO: Implement //Allow saving the targets into a file -}*/ +StartFileDialog(StartFileDialogType::SaveAs, "Save Targets"); +} IMPL_LINK_NOARG(SfxAutoRedactDialog, AddHdl, weld::Button&, void) { @@ -345,6 +351,96 @@ IMPL_LINK_NOARG(SfxAutoRedactDialog, DeleteHdl, weld::Button&, void) } } +namespace +{ +boost::property_tree::ptree redactionTargetToJSON(RedactionTarget* pTarget) +{ +boost::property_tree::ptree aNode; +aNode.put("sName", pTarget->sName.toUtf8().getStr()); +aNode.put("eType", pTarget->sType); +aNode.put("sContent", pTarget->sContent.toUtf8().getStr()); +aNode.put("bWholeWords", pTarget->bWholeWords); +aNode.put("bCaseSensitive", pTarget->bCaseSensitive); +aNode.put("nID", pTarget->nID); + +return aNode; +} +} + +IMPL_LINK_NOARG(SfxAutoRedactDialog, LoadHdl, sfx2::FileDialogHelper*, void) +{ +//TODO: Implement +bool bDummy = hasTargets(); + +if (bDummy) +void(); +} + +IMPL_LINK_NOARG(SfxAutoRedactDialog, SaveHdl, sfx2::FileDialogHelper*, void) +{ +assert(m_pFileDlg); + +OUString
[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sfx2/inc sfx2/source
sfx2/inc/SfxRedactionHelper.hxx| 14 +- sfx2/inc/autoredactdialog.hxx | 13 ++--- sfx2/source/doc/SfxRedactionHelper.cxx | 29 + sfx2/source/doc/autoredactdialog.cxx | 22 ++ sfx2/source/doc/objserv.cxx| 12 5 files changed, 70 insertions(+), 20 deletions(-) New commits: commit ad06753daebbfb69fded5ae3e5631502d16581bb Author: Muhammet Kara AuthorDate: Wed Jun 12 21:21:26 2019 +0300 Commit: Muhammet Kara CommitDate: Sat Aug 17 16:39:49 2019 +0200 Auto redaction dialog 6th iteration * Binds everything together. * The auto redaction process works end to end now. * Only for case sensitive text content (no regex support yet) Change-Id: I6edd67472d376e2c0d91ac4b1ff90d98c49b13ac Reviewed-on: https://gerrit.libreoffice.org/73908 Tested-by: Jenkins Reviewed-by: Muhammet Kara Reviewed-on: https://gerrit.libreoffice.org/77163 Tested-by: Muhammet Kara diff --git a/sfx2/inc/SfxRedactionHelper.hxx b/sfx2/inc/SfxRedactionHelper.hxx index 44a78ab9b877..9be54ca8ac22 100644 --- a/sfx2/inc/SfxRedactionHelper.hxx +++ b/sfx2/inc/SfxRedactionHelper.hxx @@ -31,6 +31,7 @@ class SfxStringItem; class GDIMetaFile; class DocumentToGraphicRenderer; class SfxViewFrame; +struct RedactionTarget; struct PageMargins { @@ -66,10 +67,12 @@ public: * Creates one shape and one draw page for each gdimetafile, * and inserts the shapes into the newly created draw pages. * */ -static void addPagesToDraw(uno::Reference& xComponent, const sal_Int32& nPages, - const std::vector& aMetaFiles, - const std::vector<::Size>& aPageSizes, - const PageMargins& aPageMargins); +static void +addPagesToDraw(uno::Reference& xComponent, const sal_Int32& nPages, + const std::vector& aMetaFiles, + const std::vector<::Size>& aPageSizes, const PageMargins& aPageMargins, + const std::vector>& r_aTableTargets, + const bool& bIsAutoRedact); /* * Makes the Redaction toolbar visible to the user. * Meant to be called after converting a document to a Draw doc @@ -104,7 +107,8 @@ public: * Search for the given term through the gdimetafile, which has the whole content of a draw page, * and draw redaction rectangles to the appropriate positions with suitable sizes. * */ -static void autoRedactPage(const OUString& sRedactionTerm, const GDIMetaFile& rGDIMetaFile, +static void autoRedactPage(const RedactionTarget* pRedactionTarget, + const GDIMetaFile& rGDIMetaFile, uno::Reference& xPage, uno::Reference& xComponent); }; diff --git a/sfx2/inc/autoredactdialog.hxx b/sfx2/inc/autoredactdialog.hxx index 2336d66c4063..bab00cf536a3 100644 --- a/sfx2/inc/autoredactdialog.hxx +++ b/sfx2/inc/autoredactdialog.hxx @@ -105,6 +105,7 @@ class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxDialogController SfxObjectShellLock m_xDocShell; std::vector> m_aTableTargets; std::unique_ptr m_pFileDlg; +bool m_bIsValidState; std::unique_ptr m_xRedactionTargetsLabel; std::unique_ptr m_xTargetsBox; @@ -133,10 +134,16 @@ public: SfxAutoRedactDialog(weld::Window* pParent); virtual ~SfxAutoRedactDialog() override; -/* - * Check if the dialog has any valid redaction targets. - */ +/// Check if the dialog has any valid redaction targets. bool hasTargets() const; +/// Check if the dialog is in a valid state. +bool isValidState() const { return m_bIsValidState; } +/** Literally moves targets into the given vector. + * At the end of the operation, m_aTableTargets vector becomes empty. + * The contents of the given vector will be erased before being filled in. + * Returns true if successfull. + */ +bool moveTargets(std::vector>& r_aTargets); // TODO: Some method(s) to check emptiness/validity // TODO: Some method(s) to get the search params/objects diff --git a/sfx2/source/doc/SfxRedactionHelper.cxx b/sfx2/source/doc/SfxRedactionHelper.cxx index a5ee9ae588d9..b9049c2b6d7b 100644 --- a/sfx2/source/doc/SfxRedactionHelper.cxx +++ b/sfx2/source/doc/SfxRedactionHelper.cxx @@ -8,6 +8,7 @@ */ #include +#include #include #include @@ -204,11 +205,12 @@ void SfxRedactionHelper::getPageMetaFilesFromDoc(std::vector& aMeta } } -void SfxRedactionHelper::addPagesToDraw(uno::Reference& xComponent, -const sal_Int32& nPages, -const std::vector& aMetaFiles, -const std::vector<::Size>& aPageSizes, -const PageMargins&
[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sfx2/inc sfx2/source
sfx2/inc/autoredactdialog.hxx|4 + sfx2/source/doc/autoredactdialog.cxx | 97 --- 2 files changed, 95 insertions(+), 6 deletions(-) New commits: commit 4722f7c87f8a20409876f753c0e680b1eeb815e3 Author: Muhammet Kara AuthorDate: Tue Jun 11 15:20:55 2019 +0300 Commit: Muhammet Kara CommitDate: Sat Aug 17 16:39:19 2019 +0200 Auto redaction dialog 5th iteration * Add the Load handler, and the related bits * The dialog can be considered fully functional now, as all buttons are working. * Next is to handle its output in the redaction phase. Change-Id: Idd558e13b50f82a95f5f6e226bc855257837b351 Reviewed-on: https://gerrit.libreoffice.org/73822 Tested-by: Jenkins Reviewed-by: Muhammet Kara Reviewed-on: https://gerrit.libreoffice.org/77162 Tested-by: Muhammet Kara diff --git a/sfx2/inc/autoredactdialog.hxx b/sfx2/inc/autoredactdialog.hxx index 99c956246d69..2336d66c4063 100644 --- a/sfx2/inc/autoredactdialog.hxx +++ b/sfx2/inc/autoredactdialog.hxx @@ -124,6 +124,10 @@ class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxDialogController DECL_LINK(SaveHdl, sfx2::FileDialogHelper*, void); void StartFileDialog(StartFileDialogType nType, const OUString& rTitle); +/// Carry out proper addition both to the targets box, and to the tabletargets vector. +void addTarget(RedactionTarget* pTarget); +/// Clear all targets both visually and from the targets vector +void clearTargets(); public: SfxAutoRedactDialog(weld::Window* pParent); diff --git a/sfx2/source/doc/autoredactdialog.cxx b/sfx2/source/doc/autoredactdialog.cxx index 7c414cfc3189..7025baa81576 100644 --- a/sfx2/source/doc/autoredactdialog.cxx +++ b/sfx2/source/doc/autoredactdialog.cxx @@ -185,7 +185,6 @@ void TargetsTable::setRowData(const int& nRowIndex, const RedactionTarget* pTarg IMPL_LINK_NOARG(SfxAutoRedactDialog, Load, weld::Button&, void) { -//TODO: Implement //Load a targets list from a previously saved file (a json file?) // ask for filename, where we should load the new config data from StartFileDialog(StartFileDialogType::Open, "Load Targets"); @@ -193,7 +192,6 @@ IMPL_LINK_NOARG(SfxAutoRedactDialog, Load, weld::Button&, void) IMPL_LINK_NOARG(SfxAutoRedactDialog, Save, weld::Button&, void) { -//TODO: Implement //Allow saving the targets into a file StartFileDialog(StartFileDialogType::SaveAs, "Save Targets"); } @@ -365,15 +363,70 @@ boost::property_tree::ptree redactionTargetToJSON(RedactionTarget* pTarget) return aNode; } + +RedactionTarget* JSONtoRedactionTarget(const boost::property_tree::ptree::value_type& rValue) +{ +OUString sName = OUString::fromUtf8(rValue.second.get("sName").c_str()); +RedactionTargetType eType += static_cast(atoi(rValue.second.get("sName").c_str())); +OUString sContent = OUString::fromUtf8(rValue.second.get("sContent").c_str()); +bool bCaseSensitive += OUString::fromUtf8(rValue.second.get("bCaseSensitive").c_str()).toBoolean(); +bool bWholeWords += OUString::fromUtf8(rValue.second.get("bWholeWords").c_str()).toBoolean(); +sal_uInt32 nID = atoi(rValue.second.get("nID").c_str()); + +RedactionTarget* pTarget += new RedactionTarget({ sName, eType, sContent, bCaseSensitive, bWholeWords, nID }); + +return pTarget; +} } IMPL_LINK_NOARG(SfxAutoRedactDialog, LoadHdl, sfx2::FileDialogHelper*, void) { -//TODO: Implement -bool bDummy = hasTargets(); +assert(m_pFileDlg); + +OUString sTargetsFile; +if (ERRCODE_NONE == m_pFileDlg->GetError()) +sTargetsFile = m_pFileDlg->GetPath(); + +if (sTargetsFile.isEmpty()) +return; + +OUString sSysPath; +osl::File::getSystemPathFromFileURL(sTargetsFile, sSysPath); +sTargetsFile = sSysPath; + +weld::WaitObject aWaitObject(getDialog()); + +try +{ +// Create path string, and read JSON from file +std::string sPathStr(OUStringToOString(sTargetsFile, RTL_TEXTENCODING_UTF8).getStr()); + +boost::property_tree::ptree aTargetsJSON; + +boost::property_tree::read_json(sPathStr, aTargetsJSON); + +// Clear the dialog +clearTargets(); -if (bDummy) -void(); +// Recreate & add the targets to the dialog +for (const boost::property_tree::ptree::value_type& rValue : + aTargetsJSON.get_child("RedactionTargets")) +{ +RedactionTarget* pTarget = JSONtoRedactionTarget(rValue); +addTarget(pTarget); +} +} +catch (css::uno::Exception& e) +{ +SAL_WARN("sfx.doc", + "Exception caught while trying to load the targets JSON from file: " << e.Message); +return; +//TODO: Warn the user with a message box +} } IMPL_LINK_NOARG(SfxAutoRedactDialog, SaveHdl, sfx2::FileDialogHelper*, void) @@ -441,6
[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sfx2/inc sfx2/source
sfx2/inc/autoredactdialog.hxx|8 +- sfx2/source/doc/autoredactdialog.cxx | 131 +-- 2 files changed, 133 insertions(+), 6 deletions(-) New commits: commit ec442c00bc1236bbd27010bdcf7b114c796712d8 Author: Muhammet Kara AuthorDate: Sat Jun 8 16:37:04 2019 +0300 Commit: Muhammet Kara CommitDate: Sat Aug 17 16:38:26 2019 +0200 Auto redaction dialog 3rd iteration * Add the Edit handler Change-Id: Id900d2aab6fa6795455012aaf2bcaf755ccca139 Reviewed-on: https://gerrit.libreoffice.org/73705 Tested-by: Jenkins Reviewed-by: Muhammet Kara Reviewed-on: https://gerrit.libreoffice.org/77160 Tested-by: Muhammet Kara diff --git a/sfx2/inc/autoredactdialog.hxx b/sfx2/inc/autoredactdialog.hxx index 26b29bf10cf5..267427c90b21 100644 --- a/sfx2/inc/autoredactdialog.hxx +++ b/sfx2/inc/autoredactdialog.hxx @@ -82,6 +82,9 @@ public: void select(int nRow) { m_xControl->select(nRow); } OUString get_id(int nRow) const { return m_xControl->get_id(nRow); } +// Sync data on the targets box with the data on the target +void setRowData(const int& nRowIndex, const RedactionTarget* pTarget); + //void connect_changed(const Link& rLink) { m_xControl->connect_changed(rLink); } //void connect_row_activated(const Link& rLink) { m_xControl->connect_row_activated(rLink); } }; @@ -102,7 +105,7 @@ class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxDialogController /*DECL_LINK(LoadHdl, weld::Button&, void); DECL_LINK(SaveHdl, weld::Button&, void);*/ DECL_LINK(AddHdl, weld::Button&, void); -//DECL_LINK(EditHdl, weld::Button&, void); +DECL_LINK(EditHdl, weld::Button&, void); DECL_LINK(DeleteHdl, weld::Button&, void); public: @@ -130,6 +133,9 @@ private: public: SfxAddTargetDialog(weld::Window* pWindow, const OUString& rName); +SfxAddTargetDialog(weld::Window* pWindow, const OUString& sName, + const RedactionTargetType& eTargetType, const OUString& sContent, + const bool& bCaseSensitive, const bool& bWholeWords); OUString getName() const { return m_xName->get_text(); } RedactionTargetType getType() const; diff --git a/sfx2/source/doc/autoredactdialog.cxx b/sfx2/source/doc/autoredactdialog.cxx index 5d94906e9ba8..266859a129ec 100644 --- a/sfx2/source/doc/autoredactdialog.cxx +++ b/sfx2/source/doc/autoredactdialog.cxx @@ -85,6 +85,30 @@ OUString getTypeName(RedactionTargetType nType) return sTypeName; } + +/// Returns TypeID to be used in the add/edit target dialog +OUString getTypeID(RedactionTargetType nType) +{ +OUString sTypeID("unknown"); + +switch (nType) +{ +case RedactionTargetType::REDACTION_TARGET_TEXT: +sTypeID = "text"; +break; +case RedactionTargetType::REDACTION_TARGET_REGEX: +sTypeID = "regex"; +break; +case RedactionTargetType::REDACTION_TARGET_PREDEFINED: +sTypeID = "predefined"; +break; +case RedactionTargetType::REDACTION_TARGET_UNKNOWN: +sTypeID = "unknown"; +break; +} + +return sTypeID; +} } void TargetsTable::InsertTarget(RedactionTarget* pTarget) @@ -147,6 +171,15 @@ OUString TargetsTable::GetNameProposal() return sDefaultTargetName + " " + OUString::number(nHighestTargetId + 1); } +void TargetsTable::setRowData(const int& nRowIndex, const RedactionTarget* pTarget) +{ +m_xControl->set_text(nRowIndex, pTarget->sName, 0); +m_xControl->set_text(nRowIndex, getTypeName(pTarget->sType), 1); +m_xControl->set_text(nRowIndex, pTarget->sContent, 2); +m_xControl->set_text(nRowIndex, pTarget->bCaseSensitive ? OUString("Yes") : OUString("No"), 3); +m_xControl->set_text(nRowIndex, pTarget->bWholeWords ? OUString("Yes") : OUString("No"), 4); +} + /*IMPL_LINK_NOARG(SfxAutoRedactDialog, LoadHdl, weld::Button&, void) { //TODO: Implement @@ -214,11 +247,75 @@ IMPL_LINK_NOARG(SfxAutoRedactDialog, AddHdl, weld::Button&, void) } } -/*IMPL_LINK_NOARG(SfxAutoRedactDialog, EditHdl, weld::Button&, void) +IMPL_LINK_NOARG(SfxAutoRedactDialog, EditHdl, weld::Button&, void) { -//TODO: Implement -//Reuse the Add Target dialog -}*/ +sal_Int32 nSelectedRow = m_xTargetsBox->get_selected_index(); + +// No selection, nothing to edit +if (nSelectedRow < 0) +return; + +// Only one entry should be selected for editing +if (m_xTargetsBox->get_selected_rows().size() > 1) +{ +OUString sMsg( +"You have selected multiple targets, but only one target can be edited at once."); +//Warn the user about multiple selections +std::unique_ptr xBox(Application::CreateMessageDialog( +getDialog(), VclMessageType::Error, VclButtonsType::Ok, sMsg)); +xBox->run(); +return; +} + +// Get the redaction target to be edited +
[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sfx2/inc sfx2/source
sfx2/inc/SfxRedactionHelper.hxx| 20 sfx2/source/doc/SfxRedactionHelper.cxx | 148 + 2 files changed, 168 insertions(+) New commits: commit a8c06f3e6498da3e16bdcbf6f7d505a2019a8514 Author: Muhammet Kara AuthorDate: Fri Mar 1 21:56:31 2019 +0300 Commit: Muhammet Kara CommitDate: Wed Aug 7 00:23:18 2019 +0200 Auto-redact - First stab Add a SfxRedactionHelper::autoRedactPage method which searches for the given term through the gdimetafile which has the whole content of an xPage (a Draw page), and draws redaction rectangles at proper positions with proper sizes. The search is case sensitive, and finds only the first occurences on a line. Will switch to a proper search provider via a follow-up patch. Change-Id: If3db62e50994670143785b6727fdcf1ccd4c6f8e Reviewed-on: https://gerrit.libreoffice.org/68597 Tested-by: Jenkins Reviewed-by: Muhammet Kara Reviewed-on: https://gerrit.libreoffice.org/77015 Tested-by: Jenkins CollaboraOffice diff --git a/sfx2/inc/SfxRedactionHelper.hxx b/sfx2/inc/SfxRedactionHelper.hxx index ac15bb790fe9..44a78ab9b877 100644 --- a/sfx2/inc/SfxRedactionHelper.hxx +++ b/sfx2/inc/SfxRedactionHelper.hxx @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -87,6 +88,25 @@ public: * pages inserted into Draw for redaction. * */ static PageMargins getPageMarginsForCalc(css::uno::Reference& xModel); + +static void searchInMetaFile(const OUString& sSearchTerm, const GDIMetaFile& rMtf, + std::vector& aRedactionRectangles, + uno::Reference& xComponent); + +/* + * Draws a redaction rectangle on the draw page referenced with its page number (0-based) + * */ +static void addRedactionRectToPage(uno::Reference& xComponent, + uno::Reference& xPage, + const std::vector& aNewRectangles); + +/* + * Search for the given term through the gdimetafile, which has the whole content of a draw page, + * and draw redaction rectangles to the appropriate positions with suitable sizes. + * */ +static void autoRedactPage(const OUString& sRedactionTerm, const GDIMetaFile& rGDIMetaFile, + uno::Reference& xPage, + uno::Reference& xComponent); }; #endif // INCLUDED_CUI_SOURCE_INC_SFXREDACTIONHELPER_HXX diff --git a/sfx2/source/doc/SfxRedactionHelper.cxx b/sfx2/source/doc/SfxRedactionHelper.cxx index 3680323a7cf0..a5ee9ae588d9 100644 --- a/sfx2/source/doc/SfxRedactionHelper.cxx +++ b/sfx2/source/doc/SfxRedactionHelper.cxx @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -31,11 +32,16 @@ #include +#include + #include #include #include #include +#include +#include +#include using namespace ::com::sun::star; using namespace ::com::sun::star::lang; @@ -104,8 +110,66 @@ void setPageMargins(uno::Reference& xPageProperySet, xPageProperySet->setPropertyValue("BorderLeft", css::uno::makeAny(aPageMargins.nLeft)); xPageProperySet->setPropertyValue("BorderRight", css::uno::makeAny(aPageMargins.nRight)); } + +// #i10613# Extracted from ImplCheckRect::ImplCreate +tools::Rectangle ImplCalcActionBounds(const MetaAction& rAct, const OutputDevice& rOut, + const OUString& sSubString, const sal_Int32& nStrPos) +{ +tools::Rectangle aActionBounds; + +switch (rAct.GetType()) +{ +case MetaActionType::TEXTARRAY: +{ +const MetaTextArrayAction& rTextAct = static_cast(rAct); +const OUString aString(rTextAct.GetText().copy(rTextAct.GetIndex(), rTextAct.GetLen())); + +if (!aString.isEmpty()) +{ +// #105987# ImplLayout takes everything in logical coordinates +std::unique_ptr pSalLayout1 = rOut.ImplLayout( +aString, 0, nStrPos, rTextAct.GetPoint(), 0, rTextAct.GetDXArray()); +std::unique_ptr pSalLayout2 += rOut.ImplLayout(aString, 0, nStrPos + sSubString.getLength(), + rTextAct.GetPoint(), 0, rTextAct.GetDXArray()); +if (pSalLayout2) +{ +tools::Rectangle aBoundRect2( + const_cast(rOut).ImplGetTextBoundRect(*pSalLayout2)); +aActionBounds = rOut.PixelToLogic(aBoundRect2); +} +if (pSalLayout1 && nStrPos > 0) +{ +tools::Rectangle aBoundRect1( + const_cast(rOut).ImplGetTextBoundRect(*pSalLayout1)); +aActionBounds.SetLeft(rOut.PixelToLogic(aBoundRect1).getX() + +
[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sfx2/inc sfx2/source
sfx2/inc/SfxRedactionHelper.hxx| 26 + sfx2/source/doc/SfxRedactionHelper.cxx | 152 - sfx2/source/doc/objserv.cxx|9 + 3 files changed, 182 insertions(+), 5 deletions(-) New commits: commit 83e6a2cf6916aa8ee7dd3e4d58ccc0fc5b049712 Author: Muhammet Kara AuthorDate: Tue May 7 22:03:25 2019 +0300 Commit: Muhammet Kara CommitDate: Wed May 8 13:28:04 2019 +0200 Respect page margins of the source doc during redaction Change-Id: Ieaa50a2eba17145180ddd5d2bfc77add4801c43a Reviewed-on: https://gerrit.libreoffice.org/71929 Tested-by: Jenkins Reviewed-by: Muhammet Kara (cherry picked from commit 141e33bc1d56f7b7af5037988eeb5ca36864a511) Reviewed-on: https://gerrit.libreoffice.org/71960 Tested-by: Muhammet Kara diff --git a/sfx2/inc/SfxRedactionHelper.hxx b/sfx2/inc/SfxRedactionHelper.hxx index 8b1bdd57e247..ac15bb790fe9 100644 --- a/sfx2/inc/SfxRedactionHelper.hxx +++ b/sfx2/inc/SfxRedactionHelper.hxx @@ -12,6 +12,8 @@ #include #include +#include +#include #include #include @@ -29,6 +31,15 @@ class GDIMetaFile; class DocumentToGraphicRenderer; class SfxViewFrame; +struct PageMargins +{ +// Page margins in mm100th +sal_Int32 nTop; +sal_Int32 nBottom; +sal_Int32 nLeft; +sal_Int32 nRight; +}; + /* * Mostly a bunch of static methods to handle the redaction functionality at * different points of the process. @@ -56,13 +67,26 @@ public: * */ static void addPagesToDraw(uno::Reference& xComponent, const sal_Int32& nPages, const std::vector& aMetaFiles, - const std::vector<::Size>& aPageSizes); + const std::vector<::Size>& aPageSizes, + const PageMargins& aPageMargins); /* * Makes the Redaction toolbar visible to the user. * Meant to be called after converting a document to a Draw doc * for redaction purposes. * */ static void showRedactionToolbar(SfxViewFrame* pViewFrame); + +/* + * Used to get the page margins from the original/source Writer document. Then we apply these values to the + * pages inserted into Draw for redaction. + * */ +static PageMargins getPageMarginsForWriter(css::uno::Reference& xModel); + +/* + * Used to get the page margins from the original/source Calc document. Then we apply these values to the + * pages inserted into Draw for redaction. + * */ +static PageMargins getPageMarginsForCalc(css::uno::Reference& xModel); }; #endif // INCLUDED_CUI_SOURCE_INC_SFXREDACTIONHELPER_HXX diff --git a/sfx2/source/doc/SfxRedactionHelper.cxx b/sfx2/source/doc/SfxRedactionHelper.cxx index f31e6eb2d73b..3680323a7cf0 100644 --- a/sfx2/source/doc/SfxRedactionHelper.cxx +++ b/sfx2/source/doc/SfxRedactionHelper.cxx @@ -11,10 +11,17 @@ #include #include -#include #include #include +// For page margin related methods +#include +#include +#include +#include +#include +#include + #include #include #include @@ -65,6 +72,12 @@ OUString SfxRedactionHelper::getStringParam(const SfxRequest& rReq, const sal_uI namespace { +/* + * Roundtrip the gdimetafile to and from WMF + * to get rid of the position and size irregularities + * We better check the conversion method to see what it + * actually does to correct these issues, and do it ourselves. + * */ void fixMetaFile(GDIMetaFile& tmpMtf) { SvMemoryStream aDestStrm(65535, 65535); @@ -75,6 +88,22 @@ void fixMetaFile(GDIMetaFile& tmpMtf) ReadWindowMetafile(aDestStrm, tmpMtf); } + +/* + * Sets page margins for a Draw page. Negative values are considered erronous. + * */ +void setPageMargins(uno::Reference& xPageProperySet, +const PageMargins& aPageMargins) +{ +if (aPageMargins.nTop < 0 || aPageMargins.nBottom < 0 || aPageMargins.nLeft < 0 +|| aPageMargins.nRight < 0) +return; + +xPageProperySet->setPropertyValue("BorderTop", css::uno::makeAny(aPageMargins.nTop)); +xPageProperySet->setPropertyValue("BorderBottom", css::uno::makeAny(aPageMargins.nBottom)); +xPageProperySet->setPropertyValue("BorderLeft", css::uno::makeAny(aPageMargins.nLeft)); +xPageProperySet->setPropertyValue("BorderRight", css::uno::makeAny(aPageMargins.nRight)); +} } void SfxRedactionHelper::getPageMetaFilesFromDoc(std::vector& aMetaFiles, @@ -114,7 +143,8 @@ void SfxRedactionHelper::getPageMetaFilesFromDoc(std::vector& aMeta void SfxRedactionHelper::addPagesToDraw(uno::Reference& xComponent, const sal_Int32& nPages, const std::vector& aMetaFiles, -const std::vector<::Size>& aPageSizes) +const std::vector<::Size>& aPageSizes, +const
[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sfx2/inc sfx2/source
sfx2/inc/SfxRedactionHelper.hxx|5 +-- sfx2/source/doc/SfxRedactionHelper.cxx | 52 +++-- sfx2/source/doc/objserv.cxx|7 +--- 3 files changed, 28 insertions(+), 36 deletions(-) New commits: commit dd3f2fee98a77739d2036119303520e6cf3e5934 Author: Muhammet Kara AuthorDate: Fri May 3 22:07:59 2019 +0300 Commit: Muhammet Kara CommitDate: Wed May 8 13:26:53 2019 +0200 tdf#125135: Standardize content placement for redaction Correct the position & size by roundtrip conversion from/to wmf as a temporary solution. Simplify a bit. Change-Id: I6515571bb85134a4c48f00397c7554d190633575 Reviewed-on: https://gerrit.libreoffice.org/71860 Tested-by: Jenkins Reviewed-by: Muhammet Kara Reviewed-on: https://gerrit.libreoffice.org/71932 Tested-by: Muhammet Kara diff --git a/sfx2/inc/SfxRedactionHelper.hxx b/sfx2/inc/SfxRedactionHelper.hxx index 1cd653650557..8b1bdd57e247 100644 --- a/sfx2/inc/SfxRedactionHelper.hxx +++ b/sfx2/inc/SfxRedactionHelper.hxx @@ -49,15 +49,14 @@ public: * */ static void getPageMetaFilesFromDoc(std::vector& aMetaFiles, std::vector<::Size>& aPageSizes, const sal_Int32& nPages, -DocumentToGraphicRenderer& aRenderer, bool bIsWriter, -bool bIsCalc); +DocumentToGraphicRenderer& aRenderer); /* * Creates one shape and one draw page for each gdimetafile, * and inserts the shapes into the newly created draw pages. * */ static void addPagesToDraw(uno::Reference& xComponent, const sal_Int32& nPages, const std::vector& aMetaFiles, - const std::vector<::Size>& aPageSizes, bool bIsCalc); + const std::vector<::Size>& aPageSizes); /* * Makes the Redaction toolbar visible to the user. * Meant to be called after converting a document to a Draw doc diff --git a/sfx2/source/doc/SfxRedactionHelper.cxx b/sfx2/source/doc/SfxRedactionHelper.cxx index 5edc4123cbb7..f31e6eb2d73b 100644 --- a/sfx2/source/doc/SfxRedactionHelper.cxx +++ b/sfx2/source/doc/SfxRedactionHelper.cxx @@ -27,6 +27,9 @@ #include #include +#include +#include + using namespace ::com::sun::star; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::uno; @@ -60,11 +63,24 @@ OUString SfxRedactionHelper::getStringParam(const SfxRequest& rReq, const sal_uI return sStringParam; } +namespace +{ +void fixMetaFile(GDIMetaFile& tmpMtf) +{ +SvMemoryStream aDestStrm(65535, 65535); +ConvertGDIMetaFileToWMF(tmpMtf, aDestStrm, nullptr, false); +aDestStrm.Seek(0); + +tmpMtf.Clear(); + +ReadWindowMetafile(aDestStrm, tmpMtf); +} +} + void SfxRedactionHelper::getPageMetaFilesFromDoc(std::vector& aMetaFiles, std::vector<::Size>& aPageSizes, const sal_Int32& nPages, - DocumentToGraphicRenderer& aRenderer, - bool bIsWriter, bool bIsCalc) + DocumentToGraphicRenderer& aRenderer) { for (sal_Int32 nPage = 1; nPage <= nPages; ++nPage) { @@ -74,37 +90,22 @@ void SfxRedactionHelper::getPageMetaFilesFromDoc(std::vector& aMeta ::Size aCalcPageContentSize; ::Size aLogic = aRenderer.getDocumentSizeIn100mm(nPage, , , ); -// FIXME: This is a temporary hack. Need to figure out a proper way to derive this scale factor. -::Size aTargetSize(aDocumentSizePixel.Width() * 1.23, aDocumentSizePixel.Height() * 1.23); aPageSizes.push_back(aLogic); -Graphic aGraphic -= aRenderer.renderToGraphic(nPage, aDocumentSizePixel, aTargetSize, COL_TRANSPARENT); +Graphic aGraphic = aRenderer.renderToGraphic(nPage, aDocumentSizePixel, aDocumentSizePixel, + COL_TRANSPARENT); auto& rGDIMetaFile = const_cast(aGraphic.GetGDIMetaFile()); // Set preferred map unit and size on the metafile, so the Shape size // will be correct in MM. MapMode aMapMode; aMapMode.SetMapUnit(MapUnit::Map100thMM); -// FIXME: This is a temporary hack. Need to figure out a proper way to derive these magic numbers. -if (bIsWriter) -aMapMode.SetOrigin(::Point(-(aLogicPos.getX() - 512) * 1.53, - -((aLogicPos.getY() - 501) * 1.53 + (nPage - 1) * 740))); -else if (bIsCalc) -rGDIMetaFile.Scale(0.566, 0.566); rGDIMetaFile.SetPrefMapMode(aMapMode); +
[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sfx2/inc sfx2/source
sfx2/inc/SfxRedactionHelper.hxx|6 -- sfx2/source/doc/SfxRedactionHelper.cxx | 10 +++--- sfx2/source/doc/objserv.cxx|5 +++-- 3 files changed, 14 insertions(+), 7 deletions(-) New commits: commit 41ece101171123bd6eb9e59b88c2719ab83020b3 Author: Muhammet Kara AuthorDate: Wed May 1 18:46:47 2019 +0300 Commit: Andras Timar CommitDate: Thu May 2 13:43:31 2019 +0200 tdf#125063: Don't depend on content size for Page sizing During redaction of Calc sheets Change-Id: If2a4f71c77a687a74b8f823152b76d2a7e2e21da Reviewed-on: https://gerrit.libreoffice.org/71658 Reviewed-by: Muhammet Kara Reviewed-by: Andras Timar Tested-by: Andras Timar diff --git a/sfx2/inc/SfxRedactionHelper.hxx b/sfx2/inc/SfxRedactionHelper.hxx index d338143c608e..1cd653650557 100644 --- a/sfx2/inc/SfxRedactionHelper.hxx +++ b/sfx2/inc/SfxRedactionHelper.hxx @@ -15,6 +15,7 @@ #include #include +#include #include @@ -47,7 +48,7 @@ public: * and pushes into the given vector. * */ static void getPageMetaFilesFromDoc(std::vector& aMetaFiles, -const sal_Int32& nPages, +std::vector<::Size>& aPageSizes, const sal_Int32& nPages, DocumentToGraphicRenderer& aRenderer, bool bIsWriter, bool bIsCalc); /* @@ -55,7 +56,8 @@ public: * and inserts the shapes into the newly created draw pages. * */ static void addPagesToDraw(uno::Reference& xComponent, const sal_Int32& nPages, - const std::vector& aMetaFiles, bool bIsCalc); + const std::vector& aMetaFiles, + const std::vector<::Size>& aPageSizes, bool bIsCalc); /* * Makes the Redaction toolbar visible to the user. * Meant to be called after converting a document to a Draw doc diff --git a/sfx2/source/doc/SfxRedactionHelper.cxx b/sfx2/source/doc/SfxRedactionHelper.cxx index 9db938f3c79f..5edc4123cbb7 100644 --- a/sfx2/source/doc/SfxRedactionHelper.cxx +++ b/sfx2/source/doc/SfxRedactionHelper.cxx @@ -61,6 +61,7 @@ OUString SfxRedactionHelper::getStringParam(const SfxRequest& rReq, const sal_uI } void SfxRedactionHelper::getPageMetaFilesFromDoc(std::vector& aMetaFiles, + std::vector<::Size>& aPageSizes, const sal_Int32& nPages, DocumentToGraphicRenderer& aRenderer, bool bIsWriter, bool bIsCalc) @@ -76,6 +77,8 @@ void SfxRedactionHelper::getPageMetaFilesFromDoc(std::vector& aMeta // FIXME: This is a temporary hack. Need to figure out a proper way to derive this scale factor. ::Size aTargetSize(aDocumentSizePixel.Width() * 1.23, aDocumentSizePixel.Height() * 1.23); +aPageSizes.push_back(aLogic); + Graphic aGraphic = aRenderer.renderToGraphic(nPage, aDocumentSizePixel, aTargetSize, COL_TRANSPARENT); auto& rGDIMetaFile = const_cast(aGraphic.GetGDIMetaFile()); @@ -109,7 +112,8 @@ void SfxRedactionHelper::getPageMetaFilesFromDoc(std::vector& aMeta void SfxRedactionHelper::addPagesToDraw(uno::Reference& xComponent, const sal_Int32& nPages, -const std::vector& aMetaFiles, bool bIsCalc) +const std::vector& aMetaFiles, +const std::vector<::Size>& aPageSizes, bool bIsCalc) { // Access the draw pages uno::Reference xDrawPagesSupplier(xComponent, uno::UNO_QUERY); @@ -122,8 +126,8 @@ void SfxRedactionHelper::addPagesToDraw(uno::Reference& xComponent, GDIMetaFile rGDIMetaFile = aMetaFiles[nPage]; Graphic aGraphic(rGDIMetaFile); -sal_Int32 nPageHeight(rGDIMetaFile.GetPrefSize().Height()); -sal_Int32 nPageWidth(rGDIMetaFile.GetPrefSize().Width()); +sal_Int32 nPageHeight(aPageSizes[nPage].Height()); +sal_Int32 nPageWidth(aPageSizes[nPage].Width()); uno::Reference xGraph = aGraphic.GetXGraphic(); uno::Reference xPage = xDrawPages->insertNewByIndex(nPage); diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index f6fd9ed3e553..8d1dc78c0ff8 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -546,9 +546,10 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest ) sal_Int32 nPages = aRenderer.getPageCount(); std::vector< GDIMetaFile > aMetaFiles; +std::vector< ::Size > aPageSizes; // Convert the pages of the document to gdimetafiles -SfxRedactionHelper::getPageMetaFilesFromDoc(aMetaFiles, nPages, aRenderer,