Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / vcl / source / app / weldutils.cxx
blob9e20d7f69a0d1dbdd0c12bba13e4b6ef17cf2ca3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <comphelper/dispatchcommand.hxx>
11 #include <vcl/builderpage.hxx>
12 #include <vcl/commandinfoprovider.hxx>
13 #include <vcl/svapp.hxx>
14 #include <vcl/weldutils.hxx>
16 BuilderPage::BuilderPage(weld::Widget* pParent, weld::DialogController* pController,
17 const OUString& rUIXMLDescription, const OString& rID)
18 : m_pDialogController(pController)
19 , m_xBuilder(Application::CreateBuilder(pParent, rUIXMLDescription))
20 , m_xContainer(m_xBuilder->weld_container(rID))
24 void BuilderPage::Activate() {}
26 void BuilderPage::Deactivate() {}
28 BuilderPage::~BuilderPage() COVERITY_NOEXCEPT_FALSE {}
30 namespace weld
32 bool DialogController::runAsync(const std::shared_ptr<DialogController>& rController,
33 const std::function<void(sal_Int32)>& func)
35 return rController->getDialog()->runAsync(rController, func);
38 DialogController::~DialogController() COVERITY_NOEXCEPT_FALSE {}
40 Dialog* GenericDialogController::getDialog() { return m_xDialog.get(); }
42 GenericDialogController::GenericDialogController(weld::Widget* pParent, const OUString& rUIFile,
43 const OString& rDialogId)
44 : m_xBuilder(Application::CreateBuilder(pParent, rUIFile))
45 , m_xDialog(m_xBuilder->weld_dialog(rDialogId))
49 GenericDialogController::~GenericDialogController() COVERITY_NOEXCEPT_FALSE {}
51 Dialog* MessageDialogController::getDialog() { return m_xDialog.get(); }
53 MessageDialogController::MessageDialogController(weld::Widget* pParent, const OUString& rUIFile,
54 const OString& rDialogId,
55 const OString& rRelocateId)
56 : m_xBuilder(Application::CreateBuilder(pParent, rUIFile))
57 , m_xDialog(m_xBuilder->weld_message_dialog(rDialogId))
58 , m_xContentArea(m_xDialog->weld_message_area())
60 if (!rRelocateId.isEmpty())
62 m_xRelocate = m_xBuilder->weld_container(rRelocateId);
63 m_xOrigParent = m_xRelocate->weld_parent();
64 //fdo#75121, a bit tricky because the widgets we want to align with
65 //don't actually exist in the ui description, they're implied
66 m_xOrigParent->move(m_xRelocate.get(), m_xContentArea.get());
70 MessageDialogController::~MessageDialogController()
72 if (m_xRelocate)
74 m_xContentArea->move(m_xRelocate.get(), m_xOrigParent.get());
78 AssistantController::AssistantController(weld::Widget* pParent, const OUString& rUIFile,
79 const OString& rDialogId)
80 : m_xBuilder(Application::CreateBuilder(pParent, rUIFile))
81 , m_xAssistant(m_xBuilder->weld_assistant(rDialogId))
85 Dialog* AssistantController::getDialog() { return m_xAssistant.get(); }
87 AssistantController::~AssistantController() {}
89 void TriStateEnabled::ButtonToggled(weld::ToggleButton& rToggle)
91 if (bTriStateEnabled)
93 switch (eState)
95 case TRISTATE_INDET:
96 rToggle.set_state(TRISTATE_FALSE);
97 break;
98 case TRISTATE_TRUE:
99 rToggle.set_state(TRISTATE_INDET);
100 break;
101 case TRISTATE_FALSE:
102 rToggle.set_state(TRISTATE_TRUE);
103 break;
106 eState = rToggle.get_state();
109 ToolbarUnoDispatcher::ToolbarUnoDispatcher(Toolbar& rToolbar,
110 const css::uno::Reference<css::frame::XFrame>& rFrame)
111 : m_xFrame(rFrame)
113 OUString aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(rFrame));
114 vcl::ImageType eSize = rToolbar.get_icon_size();
116 for (int i = 0, nItems = rToolbar.get_n_items(); i < nItems; ++i)
118 OUString sCommand = OUString::fromUtf8(rToolbar.get_item_ident(i));
120 OUString aLabel(vcl::CommandInfoProvider::GetLabelForCommand(sCommand, aModuleName));
121 rToolbar.set_item_label(i, aLabel);
122 OUString aTooltip(vcl::CommandInfoProvider::GetTooltipForCommand(sCommand, rFrame));
123 rToolbar.set_item_tooltip_text(i, aTooltip);
124 auto xImage(vcl::CommandInfoProvider::GetXGraphicForCommand(sCommand, rFrame, eSize));
125 rToolbar.set_item_icon(i, xImage);
128 rToolbar.connect_clicked(LINK(this, ToolbarUnoDispatcher, SelectHdl));
131 IMPL_LINK(ToolbarUnoDispatcher, SelectHdl, const OString&, rCommand, void)
133 comphelper::dispatchCommand(OUString::fromUtf8(rCommand), m_xFrame,
134 css::uno::Sequence<css::beans::PropertyValue>());
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */