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