2021-01-08 22:41:56 +09:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include <svx/devtools/DevelopmentToolDockingWindow.hxx>
|
|
|
|
|
2020-12-24 17:12:48 +09:00
|
|
|
#include <com/sun/star/uno/XComponentContext.hpp>
|
|
|
|
|
|
|
|
#include <com/sun/star/beans/theIntrospection.hpp>
|
|
|
|
#include <com/sun/star/beans/XIntrospection.hpp>
|
|
|
|
#include <com/sun/star/beans/XIntrospectionAccess.hpp>
|
|
|
|
#include <com/sun/star/beans/Property.hpp>
|
|
|
|
#include <com/sun/star/beans/PropertyConcept.hpp>
|
|
|
|
#include <com/sun/star/beans/MethodConcept.hpp>
|
|
|
|
#include <com/sun/star/reflection/XIdlMethod.hpp>
|
|
|
|
#include <com/sun/star/lang/XServiceInfo.hpp>
|
2021-01-08 20:09:01 +09:00
|
|
|
#include <com/sun/star/text/XTextDocument.hpp>
|
|
|
|
#include <com/sun/star/container/XEnumerationAccess.hpp>
|
2020-12-24 17:12:48 +09:00
|
|
|
|
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
|
2021-01-08 22:41:56 +09:00
|
|
|
#include <sfx2/dispatch.hxx>
|
|
|
|
#include <sfx2/sfxmodelfactory.hxx>
|
|
|
|
#include <svx/svxids.hrc>
|
|
|
|
|
2020-12-24 17:12:48 +09:00
|
|
|
#include <sfx2/objsh.hxx>
|
|
|
|
|
|
|
|
#include <sfx2/viewfrm.hxx>
|
|
|
|
|
|
|
|
#include <com/sun/star/frame/XController.hpp>
|
|
|
|
#include <com/sun/star/view/XSelectionChangeListener.hpp>
|
|
|
|
|
|
|
|
#include <cppuhelper/compbase.hxx>
|
|
|
|
#include <cppuhelper/basemutex.hxx>
|
|
|
|
|
|
|
|
#include <com/sun/star/view/XSelectionSupplier.hpp>
|
|
|
|
|
2021-01-08 20:09:01 +09:00
|
|
|
#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
|
|
|
|
|
2020-12-24 17:12:48 +09:00
|
|
|
using namespace css;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
typedef cppu::WeakComponentImplHelper<css::view::XSelectionChangeListener>
|
|
|
|
SelectionChangeHandlerInterfaceBase;
|
|
|
|
|
|
|
|
class SelectionChangeHandler final : private ::cppu::BaseMutex,
|
|
|
|
public SelectionChangeHandlerInterfaceBase
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
css::uno::Reference<css::frame::XController> mxController;
|
2021-01-06 15:58:13 +09:00
|
|
|
VclPtr<DevelopmentToolDockingWindow> mpDockingWindow;
|
2020-12-24 17:12:48 +09:00
|
|
|
|
|
|
|
public:
|
2021-01-06 15:58:13 +09:00
|
|
|
SelectionChangeHandler(const css::uno::Reference<css::frame::XController>& rxController,
|
|
|
|
DevelopmentToolDockingWindow* pDockingWindow)
|
2020-12-24 17:12:48 +09:00
|
|
|
: SelectionChangeHandlerInterfaceBase(m_aMutex)
|
|
|
|
, mxController(rxController)
|
2021-01-06 15:58:13 +09:00
|
|
|
, mpDockingWindow(pDockingWindow)
|
2020-12-24 17:12:48 +09:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-01-06 15:58:13 +09:00
|
|
|
~SelectionChangeHandler() { mpDockingWindow.disposeAndClear(); }
|
|
|
|
|
2020-12-24 17:12:48 +09:00
|
|
|
virtual void SAL_CALL selectionChanged(const css::lang::EventObject& /*rEvent*/) override
|
|
|
|
{
|
|
|
|
uno::Reference<view::XSelectionSupplier> xSupplier(mxController, uno::UNO_QUERY);
|
|
|
|
if (xSupplier.is())
|
|
|
|
{
|
|
|
|
uno::Any aAny = xSupplier->getSelection();
|
|
|
|
auto aRef = aAny.get<uno::Reference<uno::XInterface>>();
|
2021-01-06 15:58:13 +09:00
|
|
|
mpDockingWindow->introspect(aRef);
|
2020-12-24 17:12:48 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
virtual void SAL_CALL disposing(const css::lang::EventObject& /*rEvent*/) override {}
|
|
|
|
virtual void SAL_CALL disposing() override {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SelectionChangeHandler(const SelectionChangeHandler&) = delete;
|
|
|
|
SelectionChangeHandler& operator=(const SelectionChangeHandler&) = delete;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2021-01-08 22:41:56 +09:00
|
|
|
DevelopmentToolDockingWindow::DevelopmentToolDockingWindow(SfxBindings* pInputBindings,
|
|
|
|
SfxChildWindow* pChildWindow,
|
|
|
|
vcl::Window* pParent)
|
|
|
|
: SfxDockingWindow(pInputBindings, pChildWindow, pParent, "DevelopmentTool",
|
|
|
|
"svx/ui/developmenttool.ui")
|
2021-01-06 15:58:13 +09:00
|
|
|
, mpClassNameLabel(m_xBuilder->weld_label("class_name_value_id"))
|
|
|
|
, mpClassListBox(m_xBuilder->weld_tree_view("class_listbox_id"))
|
2021-01-08 20:09:01 +09:00
|
|
|
, mpLeftSideTreeView(m_xBuilder->weld_tree_view("leftside_treeview_id"))
|
2021-01-08 22:41:56 +09:00
|
|
|
{
|
2021-01-08 20:09:01 +09:00
|
|
|
mpLeftSideTreeView->connect_changed(LINK(this, DevelopmentToolDockingWindow, LeftSideSelected));
|
|
|
|
|
2020-12-24 17:12:48 +09:00
|
|
|
auto* pViewFrame = pInputBindings->GetDispatcher()->GetFrame();
|
|
|
|
|
2021-01-06 15:58:13 +09:00
|
|
|
uno::Reference<frame::XController> xController = pViewFrame->GetFrame().GetController();
|
2020-12-24 17:12:48 +09:00
|
|
|
|
2021-01-08 20:09:01 +09:00
|
|
|
mxRoot = pInputBindings->GetDispatcher()->GetFrame()->GetObjectShell()->GetBaseModel();
|
|
|
|
|
|
|
|
introspect(mxRoot);
|
|
|
|
inspectDocument();
|
|
|
|
|
2021-01-06 15:58:13 +09:00
|
|
|
uno::Reference<view::XSelectionSupplier> xSupplier(xController, uno::UNO_QUERY);
|
2020-12-24 17:12:48 +09:00
|
|
|
if (xSupplier.is())
|
|
|
|
{
|
|
|
|
uno::Reference<view::XSelectionChangeListener> xChangeListener(
|
2021-01-06 15:58:13 +09:00
|
|
|
new SelectionChangeHandler(xController, this));
|
2020-12-24 17:12:48 +09:00
|
|
|
xSupplier->addSelectionChangeListener(xChangeListener);
|
2021-01-08 20:09:01 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_LINK_NOARG(DevelopmentToolDockingWindow, LeftSideSelected, weld::TreeView&, void)
|
|
|
|
{
|
|
|
|
OUString sID = mpLeftSideTreeView->get_selected_text();
|
|
|
|
auto& rObject = maUnoObjectMap.at(sID);
|
|
|
|
if (rObject.is())
|
|
|
|
introspect(rObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DevelopmentToolDockingWindow::inspectDocument()
|
|
|
|
{
|
|
|
|
uno::Reference<lang::XServiceInfo> xDocument(mxRoot, uno::UNO_QUERY_THROW);
|
|
|
|
|
|
|
|
if (xDocument->supportsService("com.sun.star.sheet.SpreadsheetDocument"))
|
|
|
|
{
|
|
|
|
msDocumentType = "Spreadsheet Document";
|
|
|
|
}
|
|
|
|
else if (xDocument->supportsService("com.sun.star.presentation.PresentationDocument"))
|
|
|
|
{
|
|
|
|
msDocumentType = "Presentation Document";
|
|
|
|
}
|
|
|
|
else if (xDocument->supportsService("com.sun.star.drawing.DrawingDocument"))
|
|
|
|
{
|
|
|
|
msDocumentType = "Drawing Document";
|
|
|
|
}
|
|
|
|
else if (xDocument->supportsService("com.sun.star.text.TextDocument")
|
|
|
|
|| xDocument->supportsService("com.sun.star.text.WebDocument"))
|
|
|
|
{
|
|
|
|
msDocumentType = "Text Document";
|
|
|
|
|
|
|
|
std::unique_ptr<weld::TreeIter> pParent = mpLeftSideTreeView->make_iterator();
|
|
|
|
mpLeftSideTreeView->insert(nullptr, -1, &msDocumentType, nullptr, nullptr, nullptr, false,
|
|
|
|
pParent.get());
|
|
|
|
maUnoObjectMap.emplace(msDocumentType, xDocument);
|
|
|
|
|
|
|
|
uno::Reference<text::XTextDocument> xTextDocument(xDocument, uno::UNO_QUERY);
|
|
|
|
if (xTextDocument.is())
|
|
|
|
{
|
|
|
|
uno::Reference<container::XEnumerationAccess> xParagraphEnumAccess(
|
|
|
|
xTextDocument->getText()->getText(), uno::UNO_QUERY);
|
|
|
|
if (xParagraphEnumAccess.is())
|
|
|
|
{
|
|
|
|
uno::Reference<container::XEnumeration> xParagraphEnum
|
|
|
|
= xParagraphEnumAccess->createEnumeration();
|
|
|
|
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(pParent.get(), -1, &aString, nullptr, nullptr,
|
|
|
|
nullptr, false, pCurrent.get());
|
|
|
|
|
|
|
|
uno::Reference<text::XTextContent> const xElem(
|
|
|
|
xParagraphEnum->nextElement(), uno::UNO_QUERY);
|
|
|
|
maUnoObjectMap.emplace(aString, xElem);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-24 17:12:48 +09:00
|
|
|
}
|
2021-01-08 22:41:56 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
DevelopmentToolDockingWindow::~DevelopmentToolDockingWindow() { disposeOnce(); }
|
|
|
|
|
2021-01-08 20:09:01 +09:00
|
|
|
void DevelopmentToolDockingWindow::dispose()
|
|
|
|
{
|
|
|
|
mpClassNameLabel.reset();
|
|
|
|
mpClassListBox.reset();
|
|
|
|
mpLeftSideTreeView.reset();
|
|
|
|
|
|
|
|
SfxDockingWindow::dispose();
|
|
|
|
}
|
|
|
|
|
2021-01-08 22:41:56 +09:00
|
|
|
void DevelopmentToolDockingWindow::ToggleFloatingMode()
|
|
|
|
{
|
|
|
|
SfxDockingWindow::ToggleFloatingMode();
|
|
|
|
|
|
|
|
if (GetFloatingWindow())
|
|
|
|
GetFloatingWindow()->SetMinOutputSizePixel(Size(300, 300));
|
|
|
|
|
|
|
|
Invalidate();
|
|
|
|
}
|
|
|
|
|
2021-01-06 15:58:13 +09:00
|
|
|
void DevelopmentToolDockingWindow::introspect(uno::Reference<uno::XInterface> const& xInterface)
|
|
|
|
{
|
|
|
|
if (!xInterface.is())
|
|
|
|
return;
|
|
|
|
|
|
|
|
uno::Reference<uno::XComponentContext> xContext = comphelper::getProcessComponentContext();
|
|
|
|
if (!xContext.is())
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto xServiceInfo = uno::Reference<lang::XServiceInfo>(xInterface, uno::UNO_QUERY);
|
|
|
|
OUString aImplementationName = xServiceInfo->getImplementationName();
|
|
|
|
|
|
|
|
mpClassNameLabel->set_label(aImplementationName);
|
|
|
|
|
|
|
|
mpClassListBox->freeze();
|
|
|
|
mpClassListBox->clear();
|
|
|
|
|
|
|
|
std::unique_ptr<weld::TreeIter> pParent = mpClassListBox->make_iterator();
|
|
|
|
OUString aServicesString("Services");
|
|
|
|
mpClassListBox->insert(nullptr, -1, &aServicesString, nullptr, nullptr, nullptr, false,
|
|
|
|
pParent.get());
|
|
|
|
mpClassListBox->set_text_emphasis(*pParent, true, 0);
|
|
|
|
|
|
|
|
std::unique_ptr<weld::TreeIter> pResult = mpClassListBox->make_iterator();
|
|
|
|
const uno::Sequence<OUString> aServiceNames(xServiceInfo->getSupportedServiceNames());
|
|
|
|
for (auto const& aServiceName : aServiceNames)
|
|
|
|
{
|
|
|
|
mpClassListBox->insert(pParent.get(), -1, &aServiceName, nullptr, nullptr, nullptr, false,
|
|
|
|
pResult.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
uno::Reference<beans::XIntrospection> xIntrospection;
|
|
|
|
xIntrospection = beans::theIntrospection::get(xContext);
|
|
|
|
|
|
|
|
uno::Reference<beans::XIntrospectionAccess> xIntrospectionAccess;
|
|
|
|
xIntrospectionAccess = xIntrospection->inspect(uno::makeAny(xInterface));
|
|
|
|
|
|
|
|
OUString aPropertiesString("Properties");
|
|
|
|
mpClassListBox->insert(nullptr, -1, &aPropertiesString, nullptr, nullptr, nullptr, false,
|
|
|
|
pParent.get());
|
|
|
|
mpClassListBox->set_text_emphasis(*pParent, true, 0);
|
|
|
|
|
|
|
|
const auto xProperties = xIntrospectionAccess->getProperties(
|
|
|
|
beans::PropertyConcept::ALL - beans::PropertyConcept::DANGEROUS);
|
|
|
|
for (auto const& xProperty : xProperties)
|
|
|
|
{
|
|
|
|
mpClassListBox->insert(pParent.get(), -1, &xProperty.Name, nullptr, nullptr, nullptr, false,
|
|
|
|
pResult.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString aMethodsString("Methods");
|
|
|
|
mpClassListBox->insert(nullptr, -1, &aMethodsString, nullptr, nullptr, nullptr, false,
|
|
|
|
pParent.get());
|
|
|
|
mpClassListBox->set_text_emphasis(*pParent, true, 0);
|
|
|
|
|
|
|
|
const auto xMethods = xIntrospectionAccess->getMethods(beans::MethodConcept::ALL);
|
|
|
|
for (auto const& xMethod : xMethods)
|
|
|
|
{
|
|
|
|
OUString aMethodName = xMethod->getName();
|
|
|
|
mpClassListBox->insert(pParent.get(), -1, &aMethodName, nullptr, nullptr, nullptr, false,
|
|
|
|
pResult.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
mpClassListBox->thaw();
|
|
|
|
}
|
2021-01-08 22:41:56 +09:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|