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 <com/sun/star/frame/Frame.hpp>
23 
24 using namespace ::com::sun::star;
25 using namespace ::com::sun::star::uno;
26 using namespace ::com::sun::star::frame;
27 using namespace ::com::sun::star::beans;
28 using namespace ::com::sun::star::lang;
29 using namespace ::com::sun::star::util;
30 
31 SwDBTablePreviewDialog::SwDBTablePreviewDialog(weld::Window* pParent, uno::Sequence< beans::PropertyValue> const & rValues)
32  : SfxDialogController(pParent, "modules/swriter/ui/tablepreviewdialog.ui", "TablePreviewDialog")
33  , m_xDescriptionFI(m_xBuilder->weld_label("description"))
34  , m_xBeamerWIN(m_xBuilder->weld_container("beamer"))
35 {
36  Size aSize(m_xBeamerWIN->get_approximate_digit_width() * 80,
37  m_xBeamerWIN->get_text_height() * 18);
38  m_xBeamerWIN->set_size_request(aSize.Width(), aSize.Height());
39 
40  auto pValue = std::find_if(rValues.begin(), rValues.end(),
41  [](const beans::PropertyValue& rValue) { return rValue.Name == "Command"; });
42  if (pValue != rValues.end())
43  {
44  OUString sDescription = m_xDescriptionFI->get_label();
45  OUString sTemp;
46  pValue->Value >>= sTemp;
47  m_xDescriptionFI->set_label(sDescription.replaceFirst("%1", sTemp));
48  }
49 
50  try
51  {
52  // create a frame wrapper for myself
53  m_xFrame = frame::Frame::create( comphelper::getProcessComponentContext() );
54  m_xFrame->initialize(m_xBeamerWIN->CreateChildFrame());
55  }
56  catch (uno::Exception const &)
57  {
58  m_xFrame.clear();
59  }
60  if (m_xFrame.is())
61  {
62  util::URL aURL;
63  aURL.Complete = ".component:DB/DataSourceBrowser";
64  uno::Reference<frame::XDispatch> xD = m_xFrame->queryDispatch(aURL, "", 0x0C);
65  if(xD.is())
66  {
67  xD->dispatch(aURL, rValues);
68  m_xBeamerWIN->show();
69  }
70  }
71 }
72 
74 {
75  if(m_xFrame.is())
76  {
77  m_xFrame->setComponent(nullptr, nullptr);
78  m_xFrame->dispose();
79  m_xFrame.clear();
80  }
81 }
82 
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
URL aURL
css::uno::Reference< css::frame::XFrame2 > m_xFrame
SwDBTablePreviewDialog(weld::Window *pParent, css::uno::Sequence< css::beans::PropertyValue > const &rValues)
virtual ~SwDBTablePreviewDialog() override
std::unique_ptr< weld::Container > m_xBeamerWIN
css::uno::Any const & rValue
std::unique_ptr< weld::Label > m_xDescriptionFI
Reference< XComponentContext > getProcessComponentContext()