LibreOffice Module sw (master) 1
dbtablepreviewdialog.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
23#include <com/sun/star/lang/XEventListener.hpp>
24#include <com/sun/star/frame/Frame.hpp>
25#include <com/sun/star/frame/FrameSearchFlag.hpp>
26#include <utility>
27
28using namespace ::com::sun::star;
29using namespace ::com::sun::star::uno;
30using namespace ::com::sun::star::frame;
31using namespace ::com::sun::star::beans;
32using namespace ::com::sun::star::lang;
33using namespace ::com::sun::star::util;
34
36 : public cppu::WeakImplHelper<lang::XEventListener>
37{
38private:
39 css::uno::Reference<css::frame::XFrame2> m_xFrame;
40
41 virtual void SAL_CALL disposing(const lang::EventObject& /*Source*/) override
42 {
43 m_xFrame.clear();
44 }
45
46public:
47 DBTablePreviewFrame(css::uno::Reference<css::frame::XFrame2> xFrame)
48 : m_xFrame(std::move(xFrame))
49 {
50 }
51
52 void cleanup()
53 {
54 if (m_xFrame.is())
55 {
56 m_xFrame->setComponent(nullptr, nullptr);
57 m_xFrame->dispose();
58 m_xFrame.clear();
59 }
60 }
61};
62
63SwDBTablePreviewDialog::SwDBTablePreviewDialog(weld::Window* pParent, uno::Sequence< beans::PropertyValue> const & rValues)
64 : SfxDialogController(pParent, "modules/swriter/ui/tablepreviewdialog.ui", "TablePreviewDialog")
65 , m_xDescriptionFI(m_xBuilder->weld_label("description"))
66 , m_xBeamerWIN(m_xBuilder->weld_container("beamer"))
67{
68 Size aSize(m_xBeamerWIN->get_approximate_digit_width() * 80,
69 m_xBeamerWIN->get_text_height() * 18);
70 m_xBeamerWIN->set_size_request(aSize.Width(), aSize.Height());
71
72 auto pValue = std::find_if(rValues.begin(), rValues.end(),
73 [](const beans::PropertyValue& rValue) { return rValue.Name == "Command"; });
74 if (pValue != rValues.end())
75 {
76 OUString sDescription = m_xDescriptionFI->get_label();
77 OUString sTemp;
78 pValue->Value >>= sTemp;
79 m_xDescriptionFI->set_label(sDescription.replaceFirst("%1", sTemp));
80 }
81
82 css::uno::Reference<css::frame::XFrame2> xFrame;
83 try
84 {
85 // create a frame wrapper for myself
86 xFrame = frame::Frame::create( comphelper::getProcessComponentContext() );
87 xFrame->initialize(m_xBeamerWIN->CreateChildFrame());
88 }
89 catch (uno::Exception const &)
90 {
91 xFrame.clear();
92 }
93 if (!xFrame.is())
94 return;
95
97 xFrame->addEventListener(m_xFrameListener);
98
99 util::URL aURL;
100 aURL.Complete = ".component:DB/DataSourceBrowser";
101 uno::Reference<frame::XDispatch> xD = xFrame->queryDispatch(aURL, "",
102 css::frame::FrameSearchFlag::CHILDREN | css::frame::FrameSearchFlag::CREATE);
103 if (xD.is())
104 {
105 xD->dispatch(aURL, rValues);
106 m_xBeamerWIN->show();
107 }
108}
109
111{
113 {
114 m_xFrameListener->cleanup();
115 m_xFrameListener.clear();
116 }
117}
118
119/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::frame::XFrame2 > m_xFrame
DBTablePreviewFrame(css::uno::Reference< css::frame::XFrame2 > xFrame)
virtual void SAL_CALL disposing(const lang::EventObject &) override
constexpr tools::Long Height() const
constexpr tools::Long Width() const
SwDBTablePreviewDialog(weld::Window *pParent, css::uno::Sequence< css::beans::PropertyValue > const &rValues)
std::unique_ptr< weld::Container > m_xBeamerWIN
std::unique_ptr< weld::Label > m_xDescriptionFI
virtual ~SwDBTablePreviewDialog() override
rtl::Reference< DBTablePreviewFrame > m_xFrameListener
URL aURL
Reference< XComponentContext > getProcessComponentContext()
Reference< XFrame > xFrame