1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "dbtablepreviewdialog.hxx"
21 #include <comphelper/processfactory.hxx>
22 #include <cppuhelper/implbase.hxx>
23 #include <com/sun/star/lang/XEventListener.hpp>
24 #include <com/sun/star/frame/Frame.hpp>
25 #include <com/sun/star/frame/FrameSearchFlag.hpp>
28 using namespace ::com::sun::star
;
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::frame
;
31 using namespace ::com::sun::star::beans
;
32 using namespace ::com::sun::star::lang
;
33 using namespace ::com::sun::star::util
;
35 class DBTablePreviewFrame
36 : public cppu::WeakImplHelper
<lang::XEventListener
>
39 css::uno::Reference
<css::frame::XFrame2
> m_xFrame
;
41 virtual void SAL_CALL
disposing(const lang::EventObject
& /*Source*/) override
47 DBTablePreviewFrame(css::uno::Reference
<css::frame::XFrame2
> xFrame
)
48 : m_xFrame(std::move(xFrame
))
56 m_xFrame
->setComponent(nullptr, nullptr);
63 SwDBTablePreviewDialog::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"))
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());
72 auto pValue
= std::find_if(rValues
.begin(), rValues
.end(),
73 [](const beans::PropertyValue
& rValue
) { return rValue
.Name
== "Command"; });
74 if (pValue
!= rValues
.end())
76 OUString sDescription
= m_xDescriptionFI
->get_label();
78 pValue
->Value
>>= sTemp
;
79 m_xDescriptionFI
->set_label(sDescription
.replaceFirst("%1", sTemp
));
82 css::uno::Reference
<css::frame::XFrame2
> xFrame
;
85 // create a frame wrapper for myself
86 xFrame
= frame::Frame::create( comphelper::getProcessComponentContext() );
87 xFrame
->initialize(m_xBeamerWIN
->CreateChildFrame());
89 catch (uno::Exception
const &)
96 m_xFrameListener
.set(new DBTablePreviewFrame(xFrame
));
97 xFrame
->addEventListener(m_xFrameListener
);
100 aURL
.Complete
= ".component:DB/DataSourceBrowser";
101 uno::Reference
<frame::XDispatch
> xD
= xFrame
->queryDispatch(aURL
, "",
102 css::frame::FrameSearchFlag::CHILDREN
| css::frame::FrameSearchFlag::CREATE
);
105 xD
->dispatch(aURL
, rValues
);
106 m_xBeamerWIN
->show();
110 SwDBTablePreviewDialog::~SwDBTablePreviewDialog()
112 if (m_xFrameListener
)
114 m_xFrameListener
->cleanup();
115 m_xFrameListener
.clear();
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */