16#include "DevToolsStrings.hrc"
18#include <com/sun/star/lang/XServiceInfo.hpp>
19#include <com/sun/star/container/XNamed.hpp>
20#include <com/sun/star/container/XEnumerationAccess.hpp>
22#include <com/sun/star/drawing/XDrawPage.hpp>
23#include <com/sun/star/drawing/XDrawPages.hpp>
24#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
25#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
26#include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
27#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
28#include <com/sun/star/sheet/XSpreadsheet.hpp>
29#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
30#include <com/sun/star/sheet/XDataPilotTables.hpp>
31#include <com/sun/star/table/XTableChartsSupplier.hpp>
32#include <com/sun/star/table/XTableCharts.hpp>
33#include <com/sun/star/text/XTextDocument.hpp>
34#include <com/sun/star/text/XTextTablesSupplier.hpp>
35#include <com/sun/star/text/XTextFramesSupplier.hpp>
36#include <com/sun/star/text/XTextGraphicObjectsSupplier.hpp>
37#include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp>
38#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
46OUString lclGetNamed(uno::Reference<uno::XInterface>
const& xObject)
48 uno::Reference<container::XNamed> xNamed(xObject, uno::UNO_QUERY);
51 return xNamed->getName();
60class DocumentModelTreeEntry
64 css::uno::Reference<css::uno::XInterface> mxObject;
67 DocumentModelTreeEntry(OUString aString, css::uno::Reference<css::uno::XInterface> xObject)
69 , mxObject(
std::move(xObject))
73 virtual ~DocumentModelTreeEntry() {}
79 virtual bool shouldShowExpander() {
return false; }
82 virtual css::uno::Reference<css::uno::XInterface> getMainObject() {
return mxObject; }
85 virtual void fill(std::unique_ptr<weld::TreeView>& ,
92void lclAppendToParentEntry(
const std::unique_ptr<weld::TreeView>& rTree,
96 OUString
const& rString = pEntry->getString();
97 rTree->insert(&rParent, -1, &rString, &sId,
nullptr,
nullptr, pEntry->shouldShowExpander(),
102OUString lclAppend(
const std::unique_ptr<weld::TreeView>& rTree, DocumentModelTreeEntry* pEntry)
105 OUString
const& rString = pEntry->getString();
106 rTree->insert(
nullptr, -1, &rString, &sId,
nullptr,
nullptr, pEntry->shouldShowExpander(),
112class NameAccessTreeEntry :
public DocumentModelTreeEntry
115 NameAccessTreeEntry(OUString
const& rString, uno::Reference<uno::XInterface>
const& xObject)
116 : DocumentModelTreeEntry(rString, xObject)
120 bool shouldShowExpander()
override
122 uno::Reference<container::XNameAccess> xNameAccess(getMainObject(), uno::UNO_QUERY);
123 return xNameAccess.is() && xNameAccess->getElementNames().getLength() > 0;
127 void fill(std::unique_ptr<weld::TreeView>& pDocumentModelTree,
130 uno::Reference<container::XNameAccess> xNameAccess(getMainObject(), uno::UNO_QUERY);
131 xNameAccess.set(getMainObject(), uno::UNO_QUERY);
132 if (!xNameAccess.is())
135 const uno::Sequence<OUString> aNames = xNameAccess->getElementNames();
136 for (
auto const& rName : aNames)
138 uno::Reference<uno::XInterface> xObject(xNameAccess->getByName(rName), uno::UNO_QUERY);
139 auto pEntry = std::make_unique<DocumentModelTreeEntry>(rName, xObject);
140 lclAppendToParentEntry(pDocumentModelTree, rParent, pEntry.release());
146class DocumentRootEntry :
public DocumentModelTreeEntry
149 DocumentRootEntry(OUString
const& rString, uno::Reference<uno::XInterface>
const& xObject)
150 : DocumentModelTreeEntry(rString, xObject)
154 bool shouldShowExpander()
override {
return false; }
158class ParagraphEntry :
public DocumentModelTreeEntry
161 ParagraphEntry(OUString
const& rString,
162 css::uno::Reference<css::uno::XInterface>
const& xObject)
163 : DocumentModelTreeEntry(rString, xObject)
167 bool shouldShowExpander()
override
169 uno::Reference<container::XEnumerationAccess> xEnumAccess(getMainObject(), uno::UNO_QUERY);
170 if (!xEnumAccess.is())
172 auto xTextPortions = xEnumAccess->createEnumeration();
173 if (!xTextPortions.is())
175 return xTextPortions->hasMoreElements();
178 void fill(std::unique_ptr<weld::TreeView>& pDocumentModelTree,
181 uno::Reference<container::XEnumerationAccess> xEnumAccess(getMainObject(), uno::UNO_QUERY);
182 if (!xEnumAccess.is())
185 uno::Reference<container::XEnumeration> xTextPortions = xEnumAccess->createEnumeration();
186 if (!xTextPortions.is())
189 for (sal_Int32 i = 0; xTextPortions->hasMoreElements();
i++)
191 uno::Reference<text::XTextRange>
const xTextPortion(xTextPortions->nextElement(),
193 OUString aString = lclGetNamed(xTextPortion);
194 if (aString.isEmpty())
196 OUString aNumber = OUString::number(i + 1);
197 aString =
SfxResId(STR_TEXT_PORTION).replaceFirst(
"%1", aNumber);
200 auto pEntry = std::make_unique<DocumentModelTreeEntry>(aString, xTextPortion);
201 lclAppendToParentEntry(pDocumentModelTree, rParent, pEntry.release());
207class ParagraphsEntry :
public DocumentModelTreeEntry
210 ParagraphsEntry(OUString
const& rString,
211 css::uno::Reference<css::uno::XInterface>
const& xObject)
212 : DocumentModelTreeEntry(rString, xObject)
216 css::uno::Reference<css::uno::XInterface> getMainObject()
override
218 uno::Reference<text::XTextDocument> xDocument(mxObject, uno::UNO_QUERY);
222 return xDocument->getText()->getText();
225 bool shouldShowExpander()
override
227 uno::Reference<container::XEnumerationAccess> xEnumAccess(getMainObject(), uno::UNO_QUERY);
228 if (!xEnumAccess.is())
230 auto xParagraphEnum = xEnumAccess->createEnumeration();
231 if (!xParagraphEnum.is())
233 return xParagraphEnum->hasMoreElements();
236 void fill(std::unique_ptr<weld::TreeView>& pDocumentModelTree,
239 uno::Reference<container::XEnumerationAccess> xEnumAccess(getMainObject(), uno::UNO_QUERY);
240 if (!xEnumAccess.is())
243 uno::Reference<container::XEnumeration> xParagraphEnum = xEnumAccess->createEnumeration();
245 if (!xParagraphEnum.is())
248 for (sal_Int32 i = 0; xParagraphEnum->hasMoreElements();
i++)
250 uno::Reference<text::XTextContent>
const xParagraph(xParagraphEnum->nextElement(),
252 OUString aString = lclGetNamed(xParagraph);
253 if (aString.isEmpty())
255 aString =
SfxResId(STR_PARAGRAPH).replaceFirst(
"%1", OUString::number(i + 1));
258 auto pEntry = std::make_unique<ParagraphEntry>(aString, xParagraph);
259 lclAppendToParentEntry(pDocumentModelTree, rParent, pEntry.release());
265class ShapesEntry :
public DocumentModelTreeEntry
268 ShapesEntry(OUString
const& rString, css::uno::Reference<css::uno::XInterface>
const& xObject)
269 : DocumentModelTreeEntry(rString, xObject)
273 css::uno::Reference<css::uno::XInterface> getMainObject()
override
275 uno::Reference<drawing::XDrawPageSupplier> xSupplier(mxObject, uno::UNO_QUERY);
278 return xSupplier->getDrawPage();
281 bool shouldShowExpander()
override
283 uno::Reference<container::XIndexAccess> xShapes(getMainObject(), uno::UNO_QUERY);
284 return xShapes.is() && xShapes->getCount() > 0;
287 void fill(std::unique_ptr<weld::TreeView>& pDocumentModelTree,
290 uno::Reference<container::XIndexAccess> xShapes(getMainObject(), uno::UNO_QUERY);
293 for (sal_Int32 nIndexShapes = 0; nIndexShapes < xShapes->getCount(); ++nIndexShapes)
295 uno::Reference<uno::XInterface> xShape(xShapes->getByIndex(nIndexShapes),
297 OUString aShapeName = lclGetNamed(xShape);
298 if (aShapeName.isEmpty())
301 =
SfxResId(STR_SHAPE).replaceFirst(
"%1", OUString::number(nIndexShapes + 1));
304 auto pEntry = std::make_unique<DocumentModelTreeEntry>(aShapeName, xShape);
305 lclAppendToParentEntry(pDocumentModelTree, rParent, pEntry.release());
311class TablesEntry :
public NameAccessTreeEntry
314 TablesEntry(OUString
const& rString, css::uno::Reference<css::uno::XInterface>
const& xObject)
315 : NameAccessTreeEntry(rString, xObject)
319 css::uno::Reference<css::uno::XInterface> getMainObject()
override
321 uno::Reference<text::XTextTablesSupplier> xSupplier(mxObject, uno::UNO_QUERY);
324 return xSupplier->getTextTables();
329class FramesEntry :
public NameAccessTreeEntry
332 FramesEntry(OUString
const& rString, css::uno::Reference<css::uno::XInterface>
const& xObject)
333 : NameAccessTreeEntry(rString, xObject)
337 css::uno::Reference<css::uno::XInterface> getMainObject()
override
339 uno::Reference<text::XTextFramesSupplier> xSupplier(mxObject, uno::UNO_QUERY);
342 return xSupplier->getTextFrames();
347class WriterGraphicObjectsEntry :
public NameAccessTreeEntry
350 WriterGraphicObjectsEntry(OUString
const& rString,
351 css::uno::Reference<css::uno::XInterface>
const& xObject)
352 : NameAccessTreeEntry(rString, xObject)
356 css::uno::Reference<css::uno::XInterface> getMainObject()
override
358 uno::Reference<text::XTextGraphicObjectsSupplier> xSupplier(mxObject, uno::UNO_QUERY);
361 return xSupplier->getGraphicObjects();
366class EmbeddedObjectsEntry :
public NameAccessTreeEntry
369 EmbeddedObjectsEntry(OUString
const& rString,
370 css::uno::Reference<css::uno::XInterface>
const& xObject)
371 : NameAccessTreeEntry(rString, xObject)
375 css::uno::Reference<css::uno::XInterface> getMainObject()
override
377 uno::Reference<text::XTextEmbeddedObjectsSupplier> xSupplier(mxObject, uno::UNO_QUERY);
380 return xSupplier->getEmbeddedObjects();
385class StylesFamilyEntry :
public NameAccessTreeEntry
388 StylesFamilyEntry(OUString
const& rString,
389 css::uno::Reference<css::uno::XInterface>
const& xObject)
390 : NameAccessTreeEntry(rString, xObject)
396class StylesFamiliesEntry :
public DocumentModelTreeEntry
399 StylesFamiliesEntry(OUString
const& rString,
400 css::uno::Reference<css::uno::XInterface>
const& xObject)
401 : DocumentModelTreeEntry(rString, xObject)
405 css::uno::Reference<css::uno::XInterface> getMainObject()
override
407 uno::Reference<style::XStyleFamiliesSupplier> xSupplier(mxObject, uno::UNO_QUERY);
410 return xSupplier->getStyleFamilies();
413 bool shouldShowExpander()
override
415 uno::Reference<container::XNameAccess> xStyleFamilies(getMainObject(), uno::UNO_QUERY);
416 return xStyleFamilies.is() && xStyleFamilies->getElementNames().getLength() > 0;
419 void fill(std::unique_ptr<weld::TreeView>& pDocumentModelTree,
422 uno::Reference<container::XNameAccess> xStyleFamilies(getMainObject(), uno::UNO_QUERY);
423 if (!xStyleFamilies.is())
426 const uno::Sequence<OUString> aNames = xStyleFamilies->getElementNames();
427 for (
auto const& rFamilyName : aNames)
429 uno::Reference<uno::XInterface> xStyleFamily(xStyleFamilies->getByName(rFamilyName),
432 auto pStylesFamilyEntry
433 = std::make_unique<StylesFamilyEntry>(rFamilyName, xStyleFamily);
434 lclAppendToParentEntry(pDocumentModelTree, rParent, pStylesFamilyEntry.release());
440class PagesEntry :
public DocumentModelTreeEntry
443 PagesEntry(OUString
const& rString, css::uno::Reference<css::uno::XInterface>
const& xObject)
444 : DocumentModelTreeEntry(rString, xObject)
448 css::uno::Reference<css::uno::XInterface> getMainObject()
override
450 uno::Reference<drawing::XDrawPagesSupplier> xSupplier(mxObject, uno::UNO_QUERY);
453 return xSupplier->getDrawPages();
456 bool shouldShowExpander()
override
458 uno::Reference<drawing::XDrawPages> xDrawPages(getMainObject(), uno::UNO_QUERY);
459 return xDrawPages.is() && xDrawPages->getCount() > 0;
462 void fill(std::unique_ptr<weld::TreeView>& pDocumentModelTree,
465 uno::Reference<drawing::XDrawPages> xDrawPages(getMainObject(), uno::UNO_QUERY);
466 for (sal_Int32 i = 0;
i < xDrawPages->getCount(); ++
i)
468 uno::Reference<drawing::XDrawPage> xPage(xDrawPages->getByIndex(i), uno::UNO_QUERY);
472 OUString aPageString = lclGetNamed(xPage);
473 if (aPageString.isEmpty())
474 aPageString =
SfxResId(STR_PAGE).replaceFirst(
"%1", OUString::number(i + 1));
476 auto pShapesEntry = std::make_unique<ShapesEntry>(aPageString, xPage);
477 lclAppendToParentEntry(pDocumentModelTree, rParent, pShapesEntry.release());
483class SlidesEntry :
public DocumentModelTreeEntry
486 SlidesEntry(OUString
const& rString, css::uno::Reference<css::uno::XInterface>
const& xObject)
487 : DocumentModelTreeEntry(rString, xObject)
491 css::uno::Reference<css::uno::XInterface> getMainObject()
override
493 uno::Reference<drawing::XDrawPagesSupplier> xSupplier(mxObject, uno::UNO_QUERY);
496 return xSupplier->getDrawPages();
499 bool shouldShowExpander()
override
501 uno::Reference<drawing::XDrawPages> xDrawPages(getMainObject(), uno::UNO_QUERY);
502 return xDrawPages.is() && xDrawPages->getCount() > 0;
505 void fill(std::unique_ptr<weld::TreeView>& pDocumentModelTree,
508 uno::Reference<drawing::XDrawPages> xDrawPages(getMainObject(), uno::UNO_QUERY);
509 for (sal_Int32 i = 0;
i < xDrawPages->getCount(); ++
i)
511 uno::Reference<drawing::XDrawPage> xPage(xDrawPages->getByIndex(i), uno::UNO_QUERY);
515 OUString aPageString = lclGetNamed(xPage);
516 if (aPageString.isEmpty())
517 aPageString =
SfxResId(STR_SLIDE).replaceFirst(
"%1", OUString::number(i + 1));
519 auto pShapesEntry = std::make_unique<ShapesEntry>(aPageString, xPage);
520 lclAppendToParentEntry(pDocumentModelTree, rParent, pShapesEntry.release());
526class MasterSlidesEntry :
public DocumentModelTreeEntry
529 MasterSlidesEntry(OUString
const& rString,
530 css::uno::Reference<css::uno::XInterface>
const& xObject)
531 : DocumentModelTreeEntry(rString, xObject)
535 css::uno::Reference<css::uno::XInterface> getMainObject()
override
537 uno::Reference<drawing::XMasterPagesSupplier> xSupplier(mxObject, uno::UNO_QUERY);
540 return xSupplier->getMasterPages();
543 bool shouldShowExpander()
override
545 uno::Reference<drawing::XDrawPages> xDrawPages(getMainObject(), uno::UNO_QUERY);
546 return xDrawPages.is() && xDrawPages->getCount() > 0;
549 void fill(std::unique_ptr<weld::TreeView>& pDocumentModelTree,
552 uno::Reference<drawing::XDrawPages> xDrawPages(getMainObject(), uno::UNO_QUERY);
553 for (sal_Int32 i = 0;
i < xDrawPages->getCount(); ++
i)
555 uno::Reference<drawing::XDrawPage> xPage(xDrawPages->getByIndex(i), uno::UNO_QUERY);
559 OUString aPageString = lclGetNamed(xPage);
560 if (aPageString.isEmpty())
563 =
SfxResId(STR_MASTER_SLIDE).replaceFirst(
"%1", OUString::number(i + 1));
566 auto pShapesEntry = std::make_unique<ShapesEntry>(aPageString, xPage);
567 lclAppendToParentEntry(pDocumentModelTree, rParent, pShapesEntry.release());
573class ChartsEntry :
public NameAccessTreeEntry
576 ChartsEntry(OUString
const& rString, css::uno::Reference<css::uno::XInterface>
const& xObject)
577 : NameAccessTreeEntry(rString, xObject)
581 css::uno::Reference<css::uno::XInterface> getMainObject()
override
583 uno::Reference<table::XTableChartsSupplier> xSupplier(mxObject, uno::UNO_QUERY);
586 return xSupplier->getCharts();
589 void fill(std::unique_ptr<weld::TreeView>& pDocumentModelTree,
592 uno::Reference<table::XTableCharts> xCharts(getMainObject(), uno::UNO_QUERY);
595 NameAccessTreeEntry::fill(pDocumentModelTree, rParent);
600class PivotTablesEntry :
public NameAccessTreeEntry
603 PivotTablesEntry(OUString
const& rString,
604 css::uno::Reference<css::uno::XInterface>
const& xObject)
605 : NameAccessTreeEntry(rString, xObject)
609 bool shouldShowExpander()
override {
return true; }
611 css::uno::Reference<css::uno::XInterface> getMainObject()
override
613 uno::Reference<sheet::XDataPilotTablesSupplier> xSupplier(mxObject, uno::UNO_QUERY);
616 return xSupplier->getDataPilotTables();
619 void fill(std::unique_ptr<weld::TreeView>& pDocumentModelTree,
622 uno::Reference<sheet::XDataPilotTables> xPivotTables(getMainObject(), uno::UNO_QUERY);
623 if (!xPivotTables.is())
625 NameAccessTreeEntry::fill(pDocumentModelTree, rParent);
630class SheetEntry :
public DocumentModelTreeEntry
633 SheetEntry(OUString
const& rString, css::uno::Reference<css::uno::XInterface>
const& xObject)
634 : DocumentModelTreeEntry(rString, xObject)
638 bool shouldShowExpander()
override {
return true; }
640 void fill(std::unique_ptr<weld::TreeView>& pDocumentModelTree,
644 = std::make_unique<ShapesEntry>(
SfxResId(STR_SHAPES_ENTRY), getMainObject());
645 lclAppendToParentEntry(pDocumentModelTree, rParent, pShapesEntry.release());
648 = std::make_unique<ChartsEntry>(
SfxResId(STR_CHARTS_ENTRY), getMainObject());
649 lclAppendToParentEntry(pDocumentModelTree, rParent, pChartsEntry.release());
651 auto pPivotTablesEntry
652 = std::make_unique<PivotTablesEntry>(
SfxResId(STR_PIVOT_TABLES_ENTRY), getMainObject());
653 lclAppendToParentEntry(pDocumentModelTree, rParent, pPivotTablesEntry.release());
658class SheetsEntry :
public DocumentModelTreeEntry
661 SheetsEntry(OUString
const& rString, css::uno::Reference<css::uno::XInterface>
const& xObject)
662 : DocumentModelTreeEntry(rString, xObject)
666 css::uno::Reference<css::uno::XInterface> getMainObject()
override
668 uno::Reference<sheet::XSpreadsheetDocument> xSheetDocument(mxObject, uno::UNO_QUERY);
669 if (!xSheetDocument.is())
671 return xSheetDocument->getSheets();
674 bool shouldShowExpander()
override
676 uno::Reference<container::XIndexAccess> xIndexAccess(getMainObject(), uno::UNO_QUERY);
677 return xIndexAccess.is() && xIndexAccess->getCount() > 0;
680 void fill(std::unique_ptr<weld::TreeView>& pDocumentModelTree,
683 uno::Reference<container::XIndexAccess> xIndexAccesss(getMainObject(), uno::UNO_QUERY);
684 if (!xIndexAccesss.is())
687 for (sal_Int32 i = 0;
i < xIndexAccesss->getCount(); ++
i)
689 uno::Reference<sheet::XSpreadsheet> xSheet(xIndexAccesss->getByIndex(i),
691 OUString aString = lclGetNamed(xSheet);
692 if (aString.isEmpty())
693 aString =
SfxResId(STR_SHEET).replaceFirst(
"%1", OUString::number(i + 1));
694 auto pEntry = std::make_unique<SheetEntry>(aString, xSheet);
695 lclAppendToParentEntry(pDocumentModelTree, rParent, pEntry.release());
703 std::unique_ptr<weld::TreeView>& pDocumentModelTree,
704 css::uno::Reference<css::uno::XInterface> xDocument)
705 : mpDocumentModelTree(pDocumentModelTree)
706 , mxDocument(
std::move(xDocument))
713 uno::Reference<uno::XInterface> xObject;
716 auto* pEntry = weld::fromId<DocumentModelTreeEntry*>(rID);
717 return pEntry->getMainObject();
725 auto* pEntry = weld::fromId<DocumentModelTreeEntry*>(sID);
746 auto* pEntry = weld::fromId<DocumentModelTreeEntry*>(sID);
758 auto* pEntry = weld::fromId<DocumentModelTreeEntry*>(sID);
766 OUString sID = mpDocumentModelTree->get_id(rParent);
770 clearChildren(rParent);
771 auto* pEntry = weld::fromId<DocumentModelTreeEntry*>(sID);
772 pEntry->fill(mpDocumentModelTree, rParent);
778 css::uno::Reference<css::uno::XInterface>
const& xInterface)
784 auto* pEntry = weld::fromId<DocumentModelTreeEntry*>(sID);
785 if (xInterface == pEntry->getMainObject())
798 uno::Reference<lang::XServiceInfo> xDocumentServiceInfo(
mxDocument, uno::UNO_QUERY_THROW);
802 if (xDocumentServiceInfo->supportsService(
"com.sun.star.sheet.SpreadsheetDocument"))
808 else if (xDocumentServiceInfo->supportsService(
809 "com.sun.star.presentation.PresentationDocument"))
817 else if (xDocumentServiceInfo->supportsService(
"com.sun.star.drawing.DrawingDocument"))
823 else if (xDocumentServiceInfo->supportsService(
"com.sun.star.text.TextDocument")
824 || xDocumentServiceInfo->supportsService(
"com.sun.star.text.WebDocument"))
IMPL_LINK(DocumentModelTreeHandler, ExpandingHandler, weld::TreeIter const &, rParent, bool)
Document model tree handler.
std::unique_ptr< weld::TreeView > & mpDocumentModelTree
static css::uno::Reference< css::uno::XInterface > getObjectByID(OUString const &rID)
void selectObject(css::uno::Reference< css::uno::XInterface > const &xInterface)
void clearChildren(weld::TreeIter const &rParent)
css::uno::Reference< css::uno::XInterface > mxDocument
DocumentModelTreeHandler(std::unique_ptr< weld::TreeView > &pDocumentModelTree, css::uno::Reference< css::uno::XInterface > xDocument)
#define LINK(Instance, Class, Member)
OUString getString(const Any &_rAny)
OUString toId(const void *pValue)
OUString SfxResId(TranslateId aId)