LibreOffice Module vcl (master)  1
weldutils.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 
11 #include <vcl/builderpage.hxx>
13 #include <vcl/svapp.hxx>
14 #include <vcl/weldutils.hxx>
15 
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))
21 {
22 }
23 
25 
27 
28 BuilderPage::~BuilderPage() COVERITY_NOEXCEPT_FALSE {}
29 
30 namespace weld
31 {
32 bool DialogController::runAsync(const std::shared_ptr<DialogController>& rController,
33  const std::function<void(sal_Int32)>& func)
34 {
35  return rController->getDialog()->runAsync(rController, func);
36 }
37 
38 DialogController::~DialogController() COVERITY_NOEXCEPT_FALSE {}
39 
41 
43  const OString& rDialogId)
44  : m_xBuilder(Application::CreateBuilder(pParent, rUIFile))
45  , m_xDialog(m_xBuilder->weld_dialog(rDialogId))
46 {
47 }
48 
50 
52 
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())
59 {
60  if (!rRelocateId.isEmpty())
61  {
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());
67  }
68 }
69 
71 {
72  if (m_xRelocate)
73  {
74  m_xContentArea->move(m_xRelocate.get(), m_xOrigParent.get());
75  }
76 }
77 
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))
82 {
83 }
84 
86 
88 
90 {
91  if (bTriStateEnabled)
92  {
93  switch (eState)
94  {
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;
104  }
105  }
106  eState = rToggle.get_state();
107 }
108 
110  const css::uno::Reference<css::frame::XFrame>& rFrame)
111  : m_xFrame(rFrame)
112 {
113  OUString aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(rFrame));
114  vcl::ImageType eSize = rToolbar.get_icon_size();
115 
116  for (int i = 0, nItems = rToolbar.get_n_items(); i < nItems; ++i)
117  {
118  OUString sCommand = OUString::fromUtf8(rToolbar.get_item_ident(i));
119 
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);
126  }
127 
128  rToolbar.connect_clicked(LINK(this, ToolbarUnoDispatcher, SelectHdl));
129 }
130 
131 IMPL_LINK(ToolbarUnoDispatcher, SelectHdl, const OString&, rCommand, void)
132 {
133  comphelper::dispatchCommand(OUString::fromUtf8(rCommand), m_xFrame,
134  css::uno::Sequence<css::beans::PropertyValue>());
135 }
136 }
137 
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< weld::Dialog > m_xDialog
Definition: weld.hxx:2071
BuilderPage(weld::Widget *pParent, weld::DialogController *pController, const OUString &rUIXMLDescription, const OString &rID)
Definition: weldutils.cxx:16
virtual Dialog * getDialog() override
Definition: weldutils.cxx:85
std::unique_ptr< weld::Builder > m_xBuilder
Definition: weld.hxx:2083
std::unique_ptr< weld::Widget > m_xRelocate
Definition: weld.hxx:2086
virtual ~MessageDialogController() override
Definition: weldutils.cxx:70
virtual void set_item_label(int nIndex, const OUString &rLabel)=0
virtual Dialog * getDialog() override
Definition: weldutils.cxx:40
TRISTATE_TRUE
virtual ~BuilderPage() COVERITY_NOEXCEPT_FALSE
Definition: weldutils.cxx:28
std::unique_ptr< weld::Container > m_xOrigParent
Definition: weld.hxx:2087
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
Definition: weldutils.cxx:32
bool dispatchCommand(const OUString &rCommand, const uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const uno::Reference< css::frame::XDispatchResultListener > &rListener)
IMPL_LINK(CustomWeld, DoResize, const Size &, rSize, void)
Definition: customweld.cxx:38
virtual void Deactivate()
Definition: weldutils.cxx:26
TRISTATE_INDET
virtual int get_n_items() const =0
AssistantController(weld::Widget *pParent, const OUString &rUIFile, const OString &rDialogId)
Definition: weldutils.cxx:78
virtual void set_item_tooltip_text(int nIndex, const OUString &rTip)=0
virtual ~DialogController() COVERITY_NOEXCEPT_FALSE
Definition: weldutils.cxx:38
OUString GetModuleIdentifier(const Reference< frame::XFrame > &rxFrame)
virtual ~GenericDialogController() COVERITY_NOEXCEPT_FALSE override
Definition: weldutils.cxx:49
ImageType
Definition: vclenum.hxx:319
virtual OString get_item_ident(int nIndex) const =0
Reference< graphic::XGraphic > GetXGraphicForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)
int i
virtual void set_item_icon(int nIndex, const css::uno::Reference< css::graphic::XGraphic > &rIcon)=0
TRISTATE_FALSE
std::unique_ptr< weld::Container > m_xContentArea
Definition: weld.hxx:2085
Base class used mainly for the LibreOffice Desktop class.
Definition: svapp.hxx:238
void ButtonToggled(ToggleButton &rToggle)
Definition: weldutils.cxx:89
GenericDialogController(weld::Widget *pParent, const OUString &rUIFile, const OString &rDialogId)
Definition: weldutils.cxx:42
virtual void Activate()
Definition: weldutils.cxx:24
ToolbarUnoDispatcher(Toolbar &rToolbar, const css::uno::Reference< css::frame::XFrame > &rFrame)
Definition: weldutils.cxx:109
virtual Dialog * getDialog() override
Definition: weldutils.cxx:51
TriState get_state() const
Definition: weld.hxx:1101
virtual ~AssistantController() override
Definition: weldutils.cxx:87
OUString GetTooltipForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame)
virtual vcl::ImageType get_icon_size() const =0
OUString GetLabelForCommand(const OUString &rsCommandName, const OUString &rsModuleName)
Return a label for the given command.
void connect_clicked(const Link< const OString &, void > &rLink)
Definition: weld.hxx:1931
void set_state(TriState eState)
Definition: weld.hxx:1110
std::unique_ptr< weld::Assistant > m_xAssistant
Definition: weld.hxx:2113
std::unique_ptr< weld::MessageDialog > m_xDialog
Definition: weld.hxx:2084
MessageDialogController(weld::Widget *pParent, const OUString &rUIFile, const OString &rDialogId, const OString &rRelocateId=OString())
Definition: weldutils.cxx:53