diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-01-16 00:22:27 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-01-16 13:58:41 +0100 |
commit | 0ffebfb691ae6fcc8df4df4a0611276bb4f33b59 (patch) | |
tree | a04e39614e7d869910848e4721887107e55fa7f2 /svx/source | |
parent | c9f7a8c73d28dc26a9939dfcd082fb72a7e59e30 (diff) |
devtools: Add more elements to the document model tree view
This change adds more elements to the document model tree view.
for all: style families and styles
for Writer: shapes, graphic objects, OLE objects, frames, tables
for Impress: master slides
for Calc: shapes, charts, pivot tables
Change-Id: Ic6d2c6c8f45fe7881e17aee3727864aeb4d701c0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109376
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx/source')
-rw-r--r-- | svx/source/devtools/DevelopmentToolDockingWindow.cxx | 340 |
1 files changed, 310 insertions, 30 deletions
diff --git a/svx/source/devtools/DevelopmentToolDockingWindow.cxx b/svx/source/devtools/DevelopmentToolDockingWindow.cxx index f62d3b6eab25..4bfd6df94463 100644 --- a/svx/source/devtools/DevelopmentToolDockingWindow.cxx +++ b/svx/source/devtools/DevelopmentToolDockingWindow.cxx @@ -46,11 +46,24 @@ #include <com/sun/star/drawing/XDrawPage.hpp> #include <com/sun/star/drawing/XDrawPages.hpp> #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <com/sun/star/drawing/XMasterPagesSupplier.hpp> + #include <com/sun/star/container/XNamed.hpp> #include <com/sun/star/sheet/XSpreadsheetDocument.hpp> #include <com/sun/star/sheet/XSpreadsheet.hpp> #include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/table/XTableChartsSupplier.hpp> +#include <com/sun/star/table/XTableCharts.hpp> + +#include <com/sun/star/text/XTextTablesSupplier.hpp> +#include <com/sun/star/text/XTextFramesSupplier.hpp> +#include <com/sun/star/text/XTextGraphicObjectsSupplier.hpp> +#include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> using namespace css; @@ -95,11 +108,32 @@ private: SelectionChangeHandler& operator=(const SelectionChangeHandler&) = delete; }; +void lclAppendToParent(std::unique_ptr<weld::TreeView>& rTree, weld::TreeIter const& rParent, + OUString const& rString, bool bChildrenOnDemand = false) +{ + rTree->insert(&rParent, -1, &rString, nullptr, nullptr, nullptr, bChildrenOnDemand, nullptr); +} + +void lclAppendToParentWithIter(std::unique_ptr<weld::TreeView>& rTree, + weld::TreeIter const& rParent, weld::TreeIter& rCurrent, + OUString const& rString, bool bChildrenOnDemand = false) +{ + rTree->insert(&rParent, -1, &rString, nullptr, nullptr, nullptr, bChildrenOnDemand, &rCurrent); +} + void lclAppend(std::unique_ptr<weld::TreeView>& rTree, OUString const& rString) { rTree->insert(nullptr, -1, &rString, nullptr, nullptr, nullptr, true, nullptr); } +OUString lclGetNamed(uno::Reference<uno::XInterface> const& xObject) +{ + uno::Reference<container::XNamed> xNamed(xObject, uno::UNO_QUERY); + if (!xNamed.is()) + return OUString(); + return xNamed->getName(); +} + } // end anonymous namespace DevelopmentToolDockingWindow::DevelopmentToolDockingWindow(SfxBindings* pInputBindings, @@ -160,6 +194,39 @@ IMPL_LINK(DevelopmentToolDockingWindow, ModelTreeViewExpanding, weld::TreeIter c clearChildren(rParent); fillParagraphs(rParent); } + else if (aText == "Shapes") + { + if (msDocumentType == "Text Document") + { + clearChildren(rParent); + fillShapes(rParent); + } + } + else if (aText == "Tables") + { + clearChildren(rParent); + fillTables(rParent); + } + else if (aText == "Frames") + { + clearChildren(rParent); + fillFrames(rParent); + } + else if (aText == "Graphic Objects") + { + clearChildren(rParent); + fillGraphicObjects(rParent); + } + else if (aText == "Embedded Objects") + { + clearChildren(rParent); + fillOLEObjects(rParent); + } + else if (aText == "Styles") + { + clearChildren(rParent); + fillStyleFamilies(rParent); + } else if (aText == "Pages") { clearChildren(rParent); @@ -170,11 +237,17 @@ IMPL_LINK(DevelopmentToolDockingWindow, ModelTreeViewExpanding, weld::TreeIter c clearChildren(rParent); fillSlides(rParent); } + else if (aText == "Master Slides") + { + clearChildren(rParent); + fillMasterSlides(rParent); + } else if (aText == "Sheets") { clearChildren(rParent); fillSheets(rParent); } + return true; } @@ -188,6 +261,89 @@ IMPL_LINK_NOARG(DevelopmentToolDockingWindow, LeftSideSelected, weld::TreeView&, introspect(rObject); } +void DevelopmentToolDockingWindow::fillGraphicObjects(weld::TreeIter const& rParent) +{ + uno::Reference<text::XTextGraphicObjectsSupplier> xSupplier(mxRoot, uno::UNO_QUERY); + if (!xSupplier.is()) + return; + uno::Reference<container::XNameAccess> xGraphicObjects = xSupplier->getGraphicObjects(); + const uno::Sequence<OUString> aNames = xGraphicObjects->getElementNames(); + for (auto const& rName : aNames) + { + maUnoObjectMap.emplace(rName, xGraphicObjects); + lclAppendToParent(mpLeftSideTreeView, rParent, rName); + } +} + +void DevelopmentToolDockingWindow::fillOLEObjects(weld::TreeIter const& rParent) +{ + uno::Reference<text::XTextEmbeddedObjectsSupplier> xSupplier(mxRoot, uno::UNO_QUERY); + if (!xSupplier.is()) + return; + uno::Reference<container::XNameAccess> xOleObjects = xSupplier->getEmbeddedObjects(); + const uno::Sequence<OUString> aNames = xOleObjects->getElementNames(); + for (auto const& rName : aNames) + { + maUnoObjectMap.emplace(rName, xOleObjects); + lclAppendToParent(mpLeftSideTreeView, rParent, rName); + } +} + +void DevelopmentToolDockingWindow::fillStyleFamilies(weld::TreeIter const& rParent) +{ + uno::Reference<style::XStyleFamiliesSupplier> xSupplier(mxRoot, uno::UNO_QUERY); + if (!xSupplier.is()) + return; + uno::Reference<container::XNameAccess> xStyleFamilies = xSupplier->getStyleFamilies(); + const uno::Sequence<OUString> aNames = xStyleFamilies->getElementNames(); + for (auto const& rFamilyName : aNames) + { + uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName(rFamilyName), + uno::UNO_QUERY); + maUnoObjectMap.emplace(rFamilyName, xStyleFamily); + + std::unique_ptr<weld::TreeIter> pCurrentStyleFamily = mpLeftSideTreeView->make_iterator(); + lclAppendToParentWithIter(mpLeftSideTreeView, rParent, *pCurrentStyleFamily, rFamilyName); + + const uno::Sequence<OUString> aStyleNames = xStyleFamily->getElementNames(); + for (auto const& rStyleName : aStyleNames) + { + uno::Reference<uno::XInterface> xStyle(xStyleFamily->getByName(rStyleName), + uno::UNO_QUERY); + maUnoObjectMap.emplace(rStyleName, xStyle); + lclAppendToParent(mpLeftSideTreeView, *pCurrentStyleFamily, rStyleName); + } + } +} + +void DevelopmentToolDockingWindow::fillFrames(weld::TreeIter const& rParent) +{ + uno::Reference<text::XTextFramesSupplier> xSupplier(mxRoot, uno::UNO_QUERY); + if (!xSupplier.is()) + return; + uno::Reference<container::XNameAccess> xFrames = xSupplier->getTextFrames(); + const uno::Sequence<OUString> aNames = xFrames->getElementNames(); + for (auto const& rName : aNames) + { + maUnoObjectMap.emplace(rName, xFrames); + lclAppendToParent(mpLeftSideTreeView, rParent, rName); + } +} + +void DevelopmentToolDockingWindow::fillTables(weld::TreeIter const& rParent) +{ + uno::Reference<text::XTextTablesSupplier> xSupplier(mxRoot, uno::UNO_QUERY); + if (!xSupplier.is()) + return; + uno::Reference<container::XNameAccess> xTables = xSupplier->getTextTables(); + const uno::Sequence<OUString> aNames = xTables->getElementNames(); + for (auto const& rName : aNames) + { + maUnoObjectMap.emplace(rName, xTables); + lclAppendToParent(mpLeftSideTreeView, rParent, rName); + } +} + void DevelopmentToolDockingWindow::fillSheets(weld::TreeIter const& rParent) { uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxRoot, uno::UNO_QUERY); @@ -199,11 +355,72 @@ void DevelopmentToolDockingWindow::fillSheets(weld::TreeIter const& rParent) { uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(i), uno::UNO_QUERY); + OUString aSlideString = lclGetNamed(xSheet); + if (aSlideString.isEmpty()) + aSlideString = "Sheet " + OUString::number(i + 1); + std::unique_ptr<weld::TreeIter> pCurrentSheet = mpLeftSideTreeView->make_iterator(); - OUString aSlideString = "Sheet " + OUString::number(i + 1); + lclAppendToParentWithIter(mpLeftSideTreeView, rParent, *pCurrentSheet, aSlideString); maUnoObjectMap.emplace(aSlideString, xSheet); - mpLeftSideTreeView->insert(&rParent, -1, &aSlideString, nullptr, nullptr, nullptr, false, - pCurrentSheet.get()); + + { + uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xSheet, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xDraws = xDrawPageSupplier->getDrawPage(); + + std::unique_ptr<weld::TreeIter> pCurrentShapes = mpLeftSideTreeView->make_iterator(); + + lclAppendToParentWithIter(mpLeftSideTreeView, *pCurrentSheet, *pCurrentShapes, + "Shapes"); + maUnoObjectMap.emplace("Shapes", xDraws); + + for (sal_Int32 nIndexShapes = 0; nIndexShapes < xDraws->getCount(); ++nIndexShapes) + { + uno::Reference<uno::XInterface> xShape(xDraws->getByIndex(nIndexShapes), + uno::UNO_QUERY); + OUString aShapeName = lclGetNamed(xShape); + if (aShapeName.isEmpty()) + aShapeName = "Shape " + OUString::number(nIndexShapes + 1); + + lclAppendToParent(mpLeftSideTreeView, *pCurrentShapes, aShapeName); + maUnoObjectMap.emplace(aShapeName, xShape); + } + } + + { + uno::Reference<table::XTableChartsSupplier> xSupplier(xSheet, uno::UNO_QUERY); + uno::Reference<table::XTableCharts> xCharts = xSupplier->getCharts(); + std::unique_ptr<weld::TreeIter> pCurrentCharts = mpLeftSideTreeView->make_iterator(); + lclAppendToParentWithIter(mpLeftSideTreeView, *pCurrentSheet, *pCurrentCharts, + "Charts"); + maUnoObjectMap.emplace("Charts", xCharts); + + const uno::Sequence<OUString> aNames = xCharts->getElementNames(); + for (auto const& rName : aNames) + { + uno::Reference<uno::XInterface> xChart(xCharts->getByName(rName), uno::UNO_QUERY); + maUnoObjectMap.emplace(rName, xChart); + lclAppendToParent(mpLeftSideTreeView, *pCurrentCharts, rName); + } + } + + { + uno::Reference<sheet::XDataPilotTablesSupplier> xSupplier(xSheet, uno::UNO_QUERY); + uno::Reference<sheet::XDataPilotTables> xPivotTables = xSupplier->getDataPilotTables(); + std::unique_ptr<weld::TreeIter> pCurrentPivotTables + = mpLeftSideTreeView->make_iterator(); + lclAppendToParentWithIter(mpLeftSideTreeView, *pCurrentSheet, *pCurrentPivotTables, + "Pivot Tables"); + maUnoObjectMap.emplace("Pivot Tables", xPivotTables); + + const uno::Sequence<OUString> aNames = xPivotTables->getElementNames(); + for (auto const& rName : aNames) + { + uno::Reference<uno::XInterface> xPivotTable(xPivotTables->getByName(rName), + uno::UNO_QUERY); + maUnoObjectMap.emplace(rName, xPivotTable); + lclAppendToParent(mpLeftSideTreeView, *pCurrentPivotTables, rName); + } + } } } @@ -219,23 +436,23 @@ void DevelopmentToolDockingWindow::fillPages(weld::TreeIter const& rParent) if (!xPage.is()) continue; + OUString aPageString = lclGetNamed(xPage); + if (aPageString.isEmpty()) + aPageString = "Page " + OUString::number(i + 1); + std::unique_ptr<weld::TreeIter> pCurrentPage = mpLeftSideTreeView->make_iterator(); - OUString aPageString = "Page " + OUString::number(i + 1); + lclAppendToParentWithIter(mpLeftSideTreeView, rParent, *pCurrentPage, aPageString); maUnoObjectMap.emplace(aPageString, xPage); - mpLeftSideTreeView->insert(&rParent, -1, &aPageString, nullptr, nullptr, nullptr, false, - pCurrentPage.get()); - for (sal_Int32 j = 0; j < xPage->getCount(); ++j) + for (sal_Int32 nPageIndex = 0; nPageIndex < xPage->getCount(); ++nPageIndex) { - uno::Reference<container::XNamed> xShape(xPage->getByIndex(j), uno::UNO_QUERY); + uno::Reference<uno::XInterface> xShape(xPage->getByIndex(nPageIndex), uno::UNO_QUERY); - OUString aShapeName = xShape->getName(); + OUString aShapeName = lclGetNamed(xShape); if (aShapeName.isEmpty()) - aShapeName = "Shape " + OUString::number(j + 1); + aShapeName = "Shape " + OUString::number(nPageIndex + 1); - std::unique_ptr<weld::TreeIter> pCurrentShape = mpLeftSideTreeView->make_iterator(); - mpLeftSideTreeView->insert(pCurrentPage.get(), -1, &aShapeName, nullptr, nullptr, - nullptr, false, pCurrentShape.get()); + lclAppendToParent(mpLeftSideTreeView, *pCurrentPage, aShapeName); maUnoObjectMap.emplace(aShapeName, xShape); } } @@ -253,23 +470,57 @@ void DevelopmentToolDockingWindow::fillSlides(weld::TreeIter const& rParent) if (!xPage.is()) continue; + OUString aSlideName = lclGetNamed(xPage); + if (aSlideName.isEmpty()) + aSlideName = "Slide " + OUString::number(i + 1); + std::unique_ptr<weld::TreeIter> pCurrentPage = mpLeftSideTreeView->make_iterator(); - OUString aSlideString = "Slide " + OUString::number(i + 1); - maUnoObjectMap.emplace(aSlideString, xPage); - mpLeftSideTreeView->insert(&rParent, -1, &aSlideString, nullptr, nullptr, nullptr, false, - pCurrentPage.get()); + lclAppendToParentWithIter(mpLeftSideTreeView, rParent, *pCurrentPage, aSlideName); + maUnoObjectMap.emplace(aSlideName, xPage); - for (sal_Int32 j = 0; j < xPage->getCount(); ++j) + for (sal_Int32 nPageIndex = 0; nPageIndex < xPage->getCount(); ++nPageIndex) { - uno::Reference<container::XNamed> xShape(xPage->getByIndex(j), uno::UNO_QUERY); + uno::Reference<uno::XInterface> xShape(xPage->getByIndex(nPageIndex), uno::UNO_QUERY); + + OUString aShapeName = lclGetNamed(xShape); + if (aShapeName.isEmpty()) + aShapeName = "Shape " + OUString::number(nPageIndex + 1); + + lclAppendToParent(mpLeftSideTreeView, *pCurrentPage, aShapeName); + maUnoObjectMap.emplace(aShapeName, xShape); + } + } +} + +void DevelopmentToolDockingWindow::fillMasterSlides(weld::TreeIter const& rParent) +{ + uno::Reference<drawing::XMasterPagesSupplier> xSupplier(mxRoot, uno::UNO_QUERY); + if (!xSupplier.is()) + return; + uno::Reference<drawing::XDrawPages> xDrawPages = xSupplier->getMasterPages(); + for (sal_Int32 i = 0; i < xDrawPages->getCount(); ++i) + { + uno::Reference<drawing::XDrawPage> xPage(xDrawPages->getByIndex(i), uno::UNO_QUERY); + if (!xPage.is()) + continue; + + OUString aSlideName = lclGetNamed(xPage); + if (aSlideName.isEmpty()) + aSlideName = "Master " + OUString::number(i + 1); + + std::unique_ptr<weld::TreeIter> pCurrentPage = mpLeftSideTreeView->make_iterator(); + lclAppendToParentWithIter(mpLeftSideTreeView, rParent, *pCurrentPage, aSlideName); + maUnoObjectMap.emplace(aSlideName, xPage); + + for (sal_Int32 nPageIndex = 0; nPageIndex < xPage->getCount(); ++nPageIndex) + { + uno::Reference<container::XNamed> xShape(xPage->getByIndex(nPageIndex), uno::UNO_QUERY); OUString aShapeName = xShape->getName(); if (aShapeName.isEmpty()) - aShapeName = "Shape " + OUString::number(j + 1); + aShapeName = "Shape " + OUString::number(nPageIndex + 1); - std::unique_ptr<weld::TreeIter> pCurrentShape = mpLeftSideTreeView->make_iterator(); - mpLeftSideTreeView->insert(pCurrentPage.get(), -1, &aShapeName, nullptr, nullptr, - nullptr, false, pCurrentShape.get()); + lclAppendToParent(mpLeftSideTreeView, *pCurrentPage, aShapeName); maUnoObjectMap.emplace(aShapeName, xShape); } } @@ -292,22 +543,41 @@ void DevelopmentToolDockingWindow::fillParagraphs(weld::TreeIter const& rParent) if (xParagraphEnum.is()) { sal_Int32 i = 0; - std::unique_ptr<weld::TreeIter> pCurrent = mpLeftSideTreeView->make_iterator(); while (xParagraphEnum->hasMoreElements()) { - OUString aString = "Paragraph " + OUString::number(i + 1); - mpLeftSideTreeView->insert(&rParent, -1, &aString, nullptr, nullptr, nullptr, false, - pCurrent.get()); + uno::Reference<text::XTextContent> const xParagraph(xParagraphEnum->nextElement(), + uno::UNO_QUERY); + OUString aString = lclGetNamed(xParagraph); + if (aString.isEmpty()) + aString = "Paragraph " + OUString::number(i + 1); + lclAppendToParent(mpLeftSideTreeView, rParent, aString); - uno::Reference<text::XTextContent> const xElem(xParagraphEnum->nextElement(), - uno::UNO_QUERY); - maUnoObjectMap.emplace(aString, xElem); + maUnoObjectMap.emplace(aString, xParagraph); i++; } } } +void DevelopmentToolDockingWindow::fillShapes(weld::TreeIter const& rParent) +{ + uno::Reference<text::XTextDocument> xDocument(mxRoot, uno::UNO_QUERY); + if (!xDocument.is()) + return; + uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xDocument, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xDraws = xDrawPageSupplier->getDrawPage(); + for (sal_Int32 nIndexShapes = 0; nIndexShapes < xDraws->getCount(); ++nIndexShapes) + { + uno::Reference<uno::XInterface> xShape(xDraws->getByIndex(nIndexShapes), uno::UNO_QUERY); + OUString aShapeName = lclGetNamed(xShape); + if (aShapeName.isEmpty()) + aShapeName = "Shape " + OUString::number(nIndexShapes + 1); + + lclAppendToParent(mpLeftSideTreeView, rParent, aShapeName); + maUnoObjectMap.emplace(aShapeName, xShape); + } +} + void DevelopmentToolDockingWindow::inspectDocument() { uno::Reference<lang::XServiceInfo> xDocument(mxRoot, uno::UNO_QUERY_THROW); @@ -320,6 +590,7 @@ void DevelopmentToolDockingWindow::inspectDocument() maUnoObjectMap.emplace(msDocumentType, mxRoot); lclAppend(mpLeftSideTreeView, "Sheets"); + lclAppend(mpLeftSideTreeView, "Styles"); } else if (xDocument->supportsService("com.sun.star.presentation.PresentationDocument")) { @@ -329,6 +600,8 @@ void DevelopmentToolDockingWindow::inspectDocument() maUnoObjectMap.emplace(msDocumentType, mxRoot); lclAppend(mpLeftSideTreeView, "Slides"); + lclAppend(mpLeftSideTreeView, "Styles"); + lclAppend(mpLeftSideTreeView, "Master Slides"); } else if (xDocument->supportsService("com.sun.star.drawing.DrawingDocument")) { @@ -338,6 +611,7 @@ void DevelopmentToolDockingWindow::inspectDocument() maUnoObjectMap.emplace(msDocumentType, mxRoot); lclAppend(mpLeftSideTreeView, "Pages"); + lclAppend(mpLeftSideTreeView, "Styles"); } else if (xDocument->supportsService("com.sun.star.text.TextDocument") || xDocument->supportsService("com.sun.star.text.WebDocument")) @@ -348,6 +622,12 @@ void DevelopmentToolDockingWindow::inspectDocument() maUnoObjectMap.emplace(msDocumentType, mxRoot); lclAppend(mpLeftSideTreeView, "Paragraphs"); + lclAppend(mpLeftSideTreeView, "Shapes"); + lclAppend(mpLeftSideTreeView, "Tables"); + lclAppend(mpLeftSideTreeView, "Frames"); + lclAppend(mpLeftSideTreeView, "Graphic Objects"); + lclAppend(mpLeftSideTreeView, "Embedded Objects"); + lclAppend(mpLeftSideTreeView, "Styles"); } } |