From 0ffebfb691ae6fcc8df4df4a0611276bb4f33b59 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Sat, 16 Jan 2021 00:22:27 +0900 Subject: devtools: Add more elements to the document model tree view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../devtools/DevelopmentToolDockingWindow.cxx | 340 +++++++++++++++++++-- 1 file changed, 310 insertions(+), 30 deletions(-) (limited to 'svx/source') 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 #include #include +#include +#include + #include #include #include #include +#include +#include +#include +#include + +#include +#include +#include +#include +#include using namespace css; @@ -95,11 +108,32 @@ private: SelectionChangeHandler& operator=(const SelectionChangeHandler&) = delete; }; +void lclAppendToParent(std::unique_ptr& 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& 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& rTree, OUString const& rString) { rTree->insert(nullptr, -1, &rString, nullptr, nullptr, nullptr, true, nullptr); } +OUString lclGetNamed(uno::Reference const& xObject) +{ + uno::Reference 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 xSupplier(mxRoot, uno::UNO_QUERY); + if (!xSupplier.is()) + return; + uno::Reference xGraphicObjects = xSupplier->getGraphicObjects(); + const uno::Sequence 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 xSupplier(mxRoot, uno::UNO_QUERY); + if (!xSupplier.is()) + return; + uno::Reference xOleObjects = xSupplier->getEmbeddedObjects(); + const uno::Sequence 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 xSupplier(mxRoot, uno::UNO_QUERY); + if (!xSupplier.is()) + return; + uno::Reference xStyleFamilies = xSupplier->getStyleFamilies(); + const uno::Sequence aNames = xStyleFamilies->getElementNames(); + for (auto const& rFamilyName : aNames) + { + uno::Reference xStyleFamily(xStyleFamilies->getByName(rFamilyName), + uno::UNO_QUERY); + maUnoObjectMap.emplace(rFamilyName, xStyleFamily); + + std::unique_ptr pCurrentStyleFamily = mpLeftSideTreeView->make_iterator(); + lclAppendToParentWithIter(mpLeftSideTreeView, rParent, *pCurrentStyleFamily, rFamilyName); + + const uno::Sequence aStyleNames = xStyleFamily->getElementNames(); + for (auto const& rStyleName : aStyleNames) + { + uno::Reference xStyle(xStyleFamily->getByName(rStyleName), + uno::UNO_QUERY); + maUnoObjectMap.emplace(rStyleName, xStyle); + lclAppendToParent(mpLeftSideTreeView, *pCurrentStyleFamily, rStyleName); + } + } +} + +void DevelopmentToolDockingWindow::fillFrames(weld::TreeIter const& rParent) +{ + uno::Reference xSupplier(mxRoot, uno::UNO_QUERY); + if (!xSupplier.is()) + return; + uno::Reference xFrames = xSupplier->getTextFrames(); + const uno::Sequence 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 xSupplier(mxRoot, uno::UNO_QUERY); + if (!xSupplier.is()) + return; + uno::Reference xTables = xSupplier->getTextTables(); + const uno::Sequence 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 xSheetDoc(mxRoot, uno::UNO_QUERY); @@ -199,11 +355,72 @@ void DevelopmentToolDockingWindow::fillSheets(weld::TreeIter const& rParent) { uno::Reference xSheet(xIndex->getByIndex(i), uno::UNO_QUERY); + OUString aSlideString = lclGetNamed(xSheet); + if (aSlideString.isEmpty()) + aSlideString = "Sheet " + OUString::number(i + 1); + std::unique_ptr 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 xDrawPageSupplier(xSheet, uno::UNO_QUERY); + uno::Reference xDraws = xDrawPageSupplier->getDrawPage(); + + std::unique_ptr pCurrentShapes = mpLeftSideTreeView->make_iterator(); + + lclAppendToParentWithIter(mpLeftSideTreeView, *pCurrentSheet, *pCurrentShapes, + "Shapes"); + maUnoObjectMap.emplace("Shapes", xDraws); + + for (sal_Int32 nIndexShapes = 0; nIndexShapes < xDraws->getCount(); ++nIndexShapes) + { + uno::Reference 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 xSupplier(xSheet, uno::UNO_QUERY); + uno::Reference xCharts = xSupplier->getCharts(); + std::unique_ptr pCurrentCharts = mpLeftSideTreeView->make_iterator(); + lclAppendToParentWithIter(mpLeftSideTreeView, *pCurrentSheet, *pCurrentCharts, + "Charts"); + maUnoObjectMap.emplace("Charts", xCharts); + + const uno::Sequence aNames = xCharts->getElementNames(); + for (auto const& rName : aNames) + { + uno::Reference xChart(xCharts->getByName(rName), uno::UNO_QUERY); + maUnoObjectMap.emplace(rName, xChart); + lclAppendToParent(mpLeftSideTreeView, *pCurrentCharts, rName); + } + } + + { + uno::Reference xSupplier(xSheet, uno::UNO_QUERY); + uno::Reference xPivotTables = xSupplier->getDataPilotTables(); + std::unique_ptr pCurrentPivotTables + = mpLeftSideTreeView->make_iterator(); + lclAppendToParentWithIter(mpLeftSideTreeView, *pCurrentSheet, *pCurrentPivotTables, + "Pivot Tables"); + maUnoObjectMap.emplace("Pivot Tables", xPivotTables); + + const uno::Sequence aNames = xPivotTables->getElementNames(); + for (auto const& rName : aNames) + { + uno::Reference 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 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 xShape(xPage->getByIndex(j), uno::UNO_QUERY); + uno::Reference 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 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 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 xShape(xPage->getByIndex(j), uno::UNO_QUERY); + uno::Reference 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 xSupplier(mxRoot, uno::UNO_QUERY); + if (!xSupplier.is()) + return; + uno::Reference xDrawPages = xSupplier->getMasterPages(); + for (sal_Int32 i = 0; i < xDrawPages->getCount(); ++i) + { + uno::Reference 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 pCurrentPage = mpLeftSideTreeView->make_iterator(); + lclAppendToParentWithIter(mpLeftSideTreeView, rParent, *pCurrentPage, aSlideName); + maUnoObjectMap.emplace(aSlideName, xPage); + + for (sal_Int32 nPageIndex = 0; nPageIndex < xPage->getCount(); ++nPageIndex) + { + uno::Reference 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 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 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 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 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 xDocument(mxRoot, uno::UNO_QUERY); + if (!xDocument.is()) + return; + uno::Reference xDrawPageSupplier(xDocument, uno::UNO_QUERY); + uno::Reference xDraws = xDrawPageSupplier->getDrawPage(); + for (sal_Int32 nIndexShapes = 0; nIndexShapes < xDraws->getCount(); ++nIndexShapes) + { + uno::Reference 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 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"); } } -- cgit