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 
20 #include "dbtablepreviewdialog.hxx"
22 #include <cppuhelper/implbase.hxx>
23 #include <com/sun/star/document/XEventListener.hpp>
24 #include <com/sun/star/frame/Frame.hpp>
25 
26 using namespace ::com::sun::star;
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star::frame;
29 using namespace ::com::sun::star::beans;
30 using namespace ::com::sun::star::lang;
31 using namespace ::com::sun::star::util;
32 
34  : public cppu::WeakImplHelper<lang::XEventListener>
35 {
36 private:
37  css::uno::Reference<css::frame::XFrame2> m_xFrame;
38 
39  virtual void SAL_CALL disposing(const lang::EventObject& /*Source*/) override
40  {
41  m_xFrame.clear();
42  }
43 
44 public:
45  DBTablePreviewFrame(css::uno::Reference<css::frame::XFrame2>& rFrame)
46  : m_xFrame(rFrame)
47  {
48  }
49 
50  void cleanup()
51  {
52  if (m_xFrame.is())
53  {
54  m_xFrame->setComponent(nullptr, nullptr);
55  m_xFrame->dispose();
56  m_xFrame.clear();
57  }
58  }
59 };
60 
61 SwDBTablePreviewDialog::SwDBTablePreviewDialog(weld::Window* pParent, uno::Sequence< beans::PropertyValue> const & rValues)
62  : SfxDialogController(pParent, "modules/swriter/ui/tablepreviewdialog.ui", "TablePreviewDialog")
63  , m_xDescriptionFI(m_xBuilder->weld_label("description"))
64  , m_xBeamerWIN(m_xBuilder->weld_container("beamer"))
65 {
66  Size aSize(m_xBeamerWIN->get_approximate_digit_width() * 80,
67  m_xBeamerWIN->get_text_height() * 18);
68  m_xBeamerWIN->set_size_request(aSize.Width(), aSize.Height());
69 
70  auto pValue = std::find_if(rValues.begin(), rValues.end(),
71  [](const beans::PropertyValue& rValue) { return rValue.Name == "Command"; });
72  if (pValue != rValues.end())
73  {
74  OUString sDescription = m_xDescriptionFI->get_label();
75  OUString sTemp;
76  pValue->Value >>= sTemp;
77  m_xDescriptionFI->set_label(sDescription.replaceFirst("%1", sTemp));
78  }
79 
80  css::uno::Reference<css::frame::XFrame2> xFrame;
81  try
82  {
83  // create a frame wrapper for myself
84  xFrame = frame::Frame::create( comphelper::getProcessComponentContext() );
85  xFrame->initialize(m_xBeamerWIN->CreateChildFrame());
86  }
87  catch (uno::Exception const &)
88  {
89  xFrame.clear();
90  }
91  if (xFrame.is())
92  {
93  m_xFrameListener.set(new DBTablePreviewFrame(xFrame));
94  xFrame->addEventListener(m_xFrameListener.get());
95 
96  util::URL aURL;
97  aURL.Complete = ".component:DB/DataSourceBrowser";
98  uno::Reference<frame::XDispatch> xD = xFrame->queryDispatch(aURL, "", 0x0C);
99  if (xD.is())
100  {
101  xD->dispatch(aURL, rValues);
102  m_xBeamerWIN->show();
103  }
104  }
105 }
106 
108 {
109  if (m_xFrameListener)
110  {
111  m_xFrameListener->cleanup();
112  m_xFrameListener.clear();
113  }
114 }
115 
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
URL aURL
SwDBTablePreviewDialog(weld::Window *pParent, css::uno::Sequence< css::beans::PropertyValue > const &rValues)
rtl::Reference< DBTablePreviewFrame > m_xFrameListener
Reference< XFrame > xFrame
css::uno::Reference< css::frame::XFrame2 > m_xFrame
virtual ~SwDBTablePreviewDialog() override
std::unique_ptr< weld::Container > m_xBeamerWIN
css::uno::Any const & rValue
DBTablePreviewFrame(css::uno::Reference< css::frame::XFrame2 > &rFrame)
std::unique_ptr< weld::Label > m_xDescriptionFI
virtual void SAL_CALL disposing(const lang::EventObject &) override
Reference< XComponentContext > getProcessComponentContext()