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 
10 #include <vcl/builderpage.hxx>
12 #include <vcl/settings.hxx>
13 #include <vcl/svapp.hxx>
14 #include <vcl/weldutils.hxx>
15 
17  const OUString& rUIXMLDescription, const OString& rID, bool bIsMobile)
18  : m_pDialogController(pController)
19  , m_xBuilder(Application::CreateBuilder(pParent, rUIXMLDescription, bIsMobile))
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, bool bMobile)
44  : m_xBuilder(Application::CreateBuilder(pParent, rUIFile, bMobile))
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 {
111  if (rTreeView.iter_has_child(rParent))
112  {
113  std::unique_ptr<weld::TreeIter> xNewParent(rTreeView.make_iterator(&rParent));
114  if (!rTreeView.iter_parent(*xNewParent))
115  xNewParent.reset();
116 
117  while (true)
118  {
119  std::unique_ptr<weld::TreeIter> xChild(rTreeView.make_iterator(&rParent));
120  if (!rTreeView.iter_children(*xChild))
121  break;
122  rTreeView.move_subtree(*xChild, xNewParent.get(), -1);
123  }
124  }
125  rTreeView.remove(rParent);
126 }
127 
129  : m_rEntry(rEntry)
130  , m_eOptions(Application::GetSettings().GetStyleSettings().GetSelectionOptions())
131 {
132  m_rEntry.connect_changed(LINK(this, EntryFormatter, ModifyHdl));
133  m_rEntry.connect_focus_out(LINK(this, EntryFormatter, FocusOutHdl));
134 }
135 
137 {
138  int nStartPos, nEndPos;
139  m_rEntry.get_selection_bounds(nStartPos, nEndPos);
140  return Selection(nStartPos, nEndPos);
141 }
142 
143 OUString EntryFormatter::GetEntryText() const { return m_rEntry.get_text(); }
144 
145 void EntryFormatter::SetEntryText(const OUString& rText, const Selection& rSel)
146 {
147  m_rEntry.set_text(rText);
148  auto nMin = rSel.Min();
149  auto nMax = rSel.Max();
150  m_rEntry.select_region(nMin < 0 ? 0 : nMin, nMax == SELECTION_MAX ? -1 : nMax);
151 }
152 
154 {
155  m_rEntry.set_font_color(pColor ? *pColor : COL_AUTO);
156 }
157 
159 
161 
163 
164 IMPL_LINK_NOARG(EntryFormatter, FocusOutHdl, weld::Widget&, void) { EntryLostFocus(); }
165 }
166 
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< weld::Dialog > m_xDialog
Definition: weld.hxx:2365
virtual void connect_focus_out(const Link< Widget &, void > &rLink)
Definition: weld.hxx:184
virtual bool iter_parent(TreeIter &rIter) const =0
virtual Dialog * getDialog() override
Definition: weldutils.cxx:85
virtual void SetEntryText(const OUString &rText, const Selection &rSel) override
Definition: weldutils.cxx:145
virtual SelectionOptions GetEntrySelectionOptions() const override
Definition: weldutils.cxx:158
SelectionOptions
Definition: settings.hxx:181
Link< weld::Entry &, void > m_aModifyHdl
Definition: weldutils.hxx:178
std::unique_ptr< weld::Builder > m_xBuilder
Definition: weld.hxx:2377
std::unique_ptr< weld::Widget > m_xRelocate
Definition: weld.hxx:2380
void RemoveParentKeepChildren(weld::TreeView &rTreeView, weld::TreeIter &rParent)
Definition: weldutils.cxx:109
virtual ~MessageDialogController() override
Definition: weldutils.cxx:70
virtual Dialog * getDialog() override
Definition: weldutils.cxx:40
virtual void set_text(const OUString &rText)=0
TRISTATE_TRUE
void connect_changed(const Link< Entry &, void > &rLink)
Definition: weld.hxx:1509
virtual ~BuilderPage() COVERITY_NOEXCEPT_FALSE
Definition: weldutils.cxx:28
virtual std::unique_ptr< TreeIter > make_iterator(const TreeIter *pOrig=nullptr) const =0
std::unique_ptr< weld::Container > m_xOrigParent
Definition: weld.hxx:2381
constexpr::Color COL_AUTO(0xFF, 0xFF, 0xFF, 0xFF)
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
Definition: weldutils.cxx:32
Reference< XNameAccess > m_xContainer
virtual void Deactivate()
Definition: weldutils.cxx:26
TRISTATE_INDET
weld::Entry & m_rEntry
Definition: weldutils.hxx:177
AssistantController(weld::Widget *pParent, const OUString &rUIFile, const OString &rDialogId)
Definition: weldutils.cxx:78
long Min() const
virtual bool get_selection_bounds(int &rStartPos, int &rEndPos)=0
virtual ~DialogController() COVERITY_NOEXCEPT_FALSE
Definition: weldutils.cxx:38
virtual ~GenericDialogController() COVERITY_NOEXCEPT_FALSE override
Definition: weldutils.cxx:49
virtual OUString GetEntryText() const override
Definition: weldutils.cxx:143
TRISTATE_FALSE
virtual bool iter_has_child(const TreeIter &rIter) const =0
std::unique_ptr< weld::Container > m_xContentArea
Definition: weld.hxx:2379
virtual void select_region(int nStartPos, int nEndPos)=0
virtual Selection GetEntrySelection() const override
Definition: weldutils.cxx:136
Base class used mainly for the LibreOffice Desktop class.
Definition: svapp.hxx:237
void ButtonToggled(ToggleButton &rToggle)
Definition: weldutils.cxx:89
virtual OUString get_text() const =0
virtual void Activate()
Definition: weldutils.cxx:24
virtual bool iter_children(TreeIter &rIter) const =0
virtual void remove(int pos)=0
EntryFormatter(weld::Entry &rEntry)
Definition: weldutils.cxx:128
virtual Dialog * getDialog() override
Definition: weldutils.cxx:51
IMPL_LINK_NOARG(HexColorControl, OnAsyncModifyHdl, void *, void)
TriState get_state() const
Definition: weld.hxx:1308
virtual ~AssistantController() override
Definition: weldutils.cxx:87
virtual void FieldModified() override
Definition: weldutils.cxx:160
Reference< XExecutableDialog > m_xDialog
virtual void SetEntryTextColor(const Color *pColor) override
Definition: weldutils.cxx:153
#define SELECTION_MAX
void set_state(TriState eState)
Definition: weld.hxx:1317
long Max() const
SelectionOptions m_eOptions
Definition: weldutils.hxx:179
std::unique_ptr< weld::Assistant > m_xAssistant
Definition: weld.hxx:2407
std::unique_ptr< weld::MessageDialog > m_xDialog
Definition: weld.hxx:2378
virtual void move_subtree(TreeIter &rNode, const TreeIter *pNewParent, int nIndexInNewParent)=0
virtual void set_font_color(const Color &rColor)=0
GenericDialogController(weld::Widget *pParent, const OUString &rUIFile, const OString &rDialogId, bool bMobile=false)
Definition: weldutils.cxx:42
MessageDialogController(weld::Widget *pParent, const OUString &rUIFile, const OString &rDialogId, const OString &rRelocateId=OString())
Definition: weldutils.cxx:53
BuilderPage(weld::Widget *pParent, weld::DialogController *pController, const OUString &rUIXMLDescription, const OString &rID, bool bIsMobile=false)
Definition: weldutils.cxx:16