LibreOffice Module sfx2 (master) 1
basedlgs.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 <vcl/help.hxx>
21#include <svl/eitem.hxx>
23#include <vcl/idle.hxx>
24
25#include <sfx2/basedlgs.hxx>
26#include <sfx2/tabdlg.hxx>
27#include <sfx2/bindings.hxx>
28#include <sfx2/dispatch.hxx>
29#include <sfx2/childwin.hxx>
30#include <sfx2/viewsh.hxx>
31#include <workwin.hxx>
32#include <comphelper/lok.hxx>
33
34using namespace ::com::sun::star::uno;
35
36constexpr OUStringLiteral USERITEM_NAME = u"UserItem";
37
39{
40public:
41 OUString aWinState;
44 void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
45
46 Idle aMoveIdle { "SfxModelessDialog_Impl aMoveIdle" };
47};
48
50{
51 if (pMgr && rHint.GetId() == SfxHintId::Dying) {
52 pMgr->Destroy();
53 }
54}
55
57
58/* [Description]
59
60 Initialization of the class SfxModelessDialog via a SfxChildWinInfo.
61 The initialization is done only in a 2nd step after the constructor, this
62 constructor should be called from the derived class or from the
63 SfxChildWindows.
64*/
65
66{
67 if (!pInfo)
68 return;
69 m_xImpl->aWinState = pInfo->aWinState;
70 if (m_xImpl->aWinState.isEmpty())
71 return;
72 m_xDialog->set_window_state(m_xImpl->aWinState);
73}
74
76 SfxChildWindow *pCW, weld::Window *pParent, const OUString& rUIXMLDescription,
77 const OUString& rID)
78 : SfxDialogController(pParent, rUIXMLDescription, rID)
79{
80 Init(pBindinx, pCW);
81}
82
83/* [Description]
84
85 Fills a SfxChildWinInfo with specific data from SfxModelessDialog,
86 so that it can be written in the INI file. It is assumed that rinfo
87 receives all other possible relevant data in the ChildWindow class.
88 ModelessDialogs have no specific information, so that the base
89 implementation does nothing and therefore must not be called.
90*/
92{
93 rInfo.aSize = m_xDialog->get_size();
94}
95
97{
98 m_pBindings = pBindinx;
100 m_xImpl->pMgr = pCW;
101 m_xImpl->bClosing = false;
102 if (pBindinx)
103 m_xImpl->StartListening( *pBindinx );
104}
105
106/* [Description]
107
108 If a ModelessDialog is enabled its ViewFrame will be activated.
109 This is necessary by PluginInFrames.
110*/
112{
113 if (m_xDialog->has_toplevel_focus())
114 Activate();
115 else
116 Deactivate();
117}
118
120{
121 if (!m_xImpl || !m_xImpl->pMgr)
122 return;
123 m_pBindings->SetActiveFrame(m_xImpl->pMgr->GetFrame());
124 m_xImpl->pMgr->Activate_Impl();
125}
126
128{
129 if (!m_xImpl)
130 return;
131 m_pBindings->SetActiveFrame(css::uno::Reference< css::frame::XFrame>());
132}
133
135{
136 if (!m_xImpl->pMgr)
137 return;
138 auto xFrame = m_xImpl->pMgr->GetFrame();
139 if (!xFrame)
140 return;
142 m_pBindings->SetActiveFrame(nullptr);
143}
144
146{
147 if (!m_xDialog->get_visible())
148 return;
149 response(nResponse);
150}
151
153{
154 return m_xImpl->bClosing;
155}
156
158{
159 if (m_xImpl->bClosing)
160 return;
161 // In the case of async dialogs, the call to SfxDialogController::EndDialog
162 // may delete this object, so keep myself alive for the duration of this
163 // stack frame.
164 auto aHoldSelf = shared_from_this();
165 m_xImpl->bClosing = true;
167 if (!m_xImpl)
168 return;
169 m_xImpl->bClosing = false;
170}
171
173{
174 if (m_xImpl->pMgr)
175 {
177 if (m_xDialog->get_resizable())
179 m_xImpl->aWinState = m_xDialog->get_window_state(nMask);
181 }
182
183 m_xImpl->pMgr = nullptr;
184}
185
186/* [Description]
187
188 The window is closed when the ChildWindow is destroyed by running the
189 ChildWindow-slots.
190*/
192{
193 if (m_xImpl->bClosing)
194 return;
195 // Execute with Parameters, since Toggle is ignored by some ChildWindows.
196 SfxBoolItem aValue(m_xImpl->pMgr->GetType(), false);
198 m_xImpl->pMgr->GetType(),
201}
202
204 const OUString& rDialogId)
205 : GenericDialogController(pParent, rUIFile, rDialogId,
206 comphelper::LibreOfficeKit::isActive()
207 && SfxViewShell::Current()
208 && SfxViewShell::Current()->isLOKMobilePhone())
209{
210 m_xDialog->SetInstallLOKNotifierHdl(LINK(this, SfxDialogController, InstallLOKNotifierHdl));
211 m_xDialog->connect_container_focus_changed(LINK(this, SfxDialogController, FocusChangeHdl));
212}
213
215{
216 // tdf3146571 ignore focus changes after we've closed
217 m_xDialog->connect_container_focus_changed(Link<weld::Container&, void>());
218}
219
221{
222 return SfxViewShell::Current();
223}
224
226 const OUString& rUIXMLDescription, const OUString& rID)
227 : SfxOkDialogController(pParent, rUIXMLDescription, rID)
228 , m_pInputSet(pSet)
229 , m_xContainer(m_xDialog->weld_content_area())
230 , m_xOKBtn(m_xBuilder->weld_button("ok"))
231 , m_xHelpBtn(m_xBuilder->weld_button("help"))
232{
233 m_xOKBtn->connect_clicked(LINK(this, SfxSingleTabDialogController, OKHdl_Impl));
234}
235
237 const OUString& rContainerId, const OUString& rUIXMLDescription, const OUString& rID)
238 : SfxOkDialogController(pParent, rUIXMLDescription, rID)
239 , m_pInputSet(pSet)
240 , m_xContainer(m_xBuilder->weld_container(rContainerId))
241 , m_xOKBtn(m_xBuilder->weld_button("ok"))
242 , m_xHelpBtn(m_xBuilder->weld_button("help"))
243{
244 m_xOKBtn->connect_clicked(LINK(this, SfxSingleTabDialogController, OKHdl_Impl));
245}
246
248{
249}
250
251/* [Description]
252
253 Insert a (new) TabPage; an existing page is deleted.
254 The passed on page is initialized with the initially given Itemset
255 through calling Reset().
256*/
257void SfxSingleTabDialogController::SetTabPage(std::unique_ptr<SfxTabPage> xTabPage)
258{
259 m_xSfxPage = std::move(xTabPage);
260 if (!m_xSfxPage)
261 return;
262
263 // First obtain the user data, only then Reset()
264 OUString sConfigId = m_xSfxPage->GetConfigId();
265 SvtViewOptions aPageOpt(EViewType::TabPage, sConfigId);
266 Any aUserItem = aPageOpt.GetUserItem( USERITEM_NAME );
267 OUString sUserData;
268 aUserItem >>= sUserData;
269 m_xSfxPage->SetUserData(sUserData);
270 m_xSfxPage->Reset(GetInputItemSet());
271
273
274 // Set TabPage text in the Dialog if there is any
275 OUString sTitle(m_xSfxPage->GetPageTitle());
276 if (!sTitle.isEmpty())
277 m_xDialog->set_title(sTitle);
278
279 // Dialog receives the HelpId of TabPage if there is any
280 OUString sHelpId(m_xSfxPage->GetHelpId());
281 if (!sHelpId.isEmpty())
282 m_xDialog->set_help_id(sHelpId);
283}
284
285/* [Description]
286
287 Ok_Handler; FillItemSet() is called for setting of Page.
288*/
290{
291 const SfxItemSet* pInputSet = GetInputItemSet();
292 if (!pInputSet)
293 {
294 // TabPage without ItemSet
295 m_xDialog->response(RET_OK);
296 return;
297 }
298
299 if (!GetOutputItemSet())
300 {
301 CreateOutputItemSet(*pInputSet);
302 }
303
304 bool bModified = false;
305
306 if (m_xSfxPage->HasExchangeSupport())
307 {
308 DeactivateRC nRet = m_xSfxPage->DeactivatePage(m_xOutputSet.get());
309 if (nRet != DeactivateRC::LeavePage)
310 return;
311 else
312 bModified = m_xOutputSet->Count() > 0;
313 }
314 else
315 bModified = m_xSfxPage->FillItemSet(m_xOutputSet.get());
316
317 if (bModified)
318 {
319 // Save user data in IniManager.
320 m_xSfxPage->FillUserData();
321 OUString sData(m_xSfxPage->GetUserData());
322
323 OUString sConfigId = m_xSfxPage->GetConfigId();
324 SvtViewOptions aPageOpt(EViewType::TabPage, sConfigId);
325 aPageOpt.SetUserItem( USERITEM_NAME, Any( sData ) );
326 m_xDialog->response(RET_OK);
327 }
328 else
329 m_xDialog->response(RET_CANCEL);
330}
331
333{
334 assert(!m_xOutputSet && "Double creation of OutputSet!");
335 m_xOutputSet.reset(new SfxItemSet(rSet));
336 m_xOutputSet->ClearItem();
337}
338
339/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
IMPL_STATIC_LINK_NOARG(SfxDialogController, InstallLOKNotifierHdl, void *, vcl::ILibreOfficeKitNotifier *)
Definition: basedlgs.cxx:220
IMPL_LINK_NOARG(SfxDialogController, FocusChangeHdl, weld::Container &, void)
Definition: basedlgs.cxx:111
constexpr OUStringLiteral USERITEM_NAME
Definition: basedlgs.cxx:36
static bool IsContextHelpEnabled()
SAL_DLLPRIVATE SfxWorkWindow * GetWorkWindow_Impl() const
Definition: bindings.cxx:1683
SAL_DLLPRIVATE SfxDispatcher * GetDispatcher_Impl()
Definition: bindings.hxx:180
css::uno::Reference< css::frame::XFrame > GetActiveFrame() const
Definition: bindings.cxx:1712
void SetActiveFrame(const css::uno::Reference< css::frame::XFrame > &rFrame)
Definition: bindings.cxx:1703
void Destroy()
Definition: childwin.cxx:158
virtual void Close()
Definition: basedlgs.cxx:214
virtual void EndDialog(int nResponse)
Definition: basedlgs.cxx:145
SfxDialogController(weld::Widget *pParent, const OUString &rUIFile, const OUString &rDialogId)
Definition: basedlgs.cxx:203
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
Method to execute a <SfxSlot>s over the Slot-Id.
Definition: dispatch.cxx:931
SfxHintId GetId() const
virtual void Deactivate() override
Definition: basedlgs.cxx:127
virtual void EndDialog(int nResponse) override
Definition: basedlgs.cxx:157
virtual void Close() override
Definition: basedlgs.cxx:191
void Init(SfxBindings *pBindinx, SfxChildWindow *pCW)
Definition: basedlgs.cxx:96
virtual void FillInfo(SfxChildWinInfo &) const
Definition: basedlgs.cxx:91
SfxBindings * m_pBindings
Definition: basedlgs.hxx:59
virtual ~SfxModelessDialogController() override
Definition: basedlgs.cxx:134
SfxBindings & GetBindings() const
Definition: basedlgs.hxx:82
void Initialize(SfxChildWinInfo const *pInfo)
Definition: basedlgs.cxx:56
SfxModelessDialogController(SfxModelessDialogController &)=delete
std::unique_ptr< SfxModelessDialog_Impl > m_xImpl
Definition: basedlgs.hxx:60
virtual void ChildWinDispose() override
Definition: basedlgs.cxx:172
virtual void Activate() override
Definition: basedlgs.cxx:119
SfxChildWindow * pMgr
Definition: basedlgs.cxx:42
void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: basedlgs.cxx:49
std::unique_ptr< weld::Button > m_xHelpBtn
Definition: basedlgs.hxx:132
void SetTabPage(std::unique_ptr< SfxTabPage > xTabPage)
Definition: basedlgs.cxx:257
virtual ~SfxSingleTabDialogController() override
Definition: basedlgs.cxx:247
std::unique_ptr< SfxTabPage > m_xSfxPage
Definition: basedlgs.hxx:129
void CreateOutputItemSet(const SfxItemSet &rInput)
Definition: basedlgs.cxx:332
SfxSingleTabDialogController(weld::Widget *pParent, const SfxItemSet *pOptionsSet, const OUString &rUIXMLDescription=OUString("sfx/ui/singletabdialog.ui"), const OUString &rID=OUString("SingleTabDialog"))
Definition: basedlgs.cxx:225
std::unique_ptr< weld::Button > m_xOKBtn
Definition: basedlgs.hxx:131
std::unique_ptr< SfxItemSet > m_xOutputSet
Definition: basedlgs.hxx:103
const SfxItemSet * GetInputItemSet() const
Definition: basedlgs.hxx:126
One SfxViewShell more or less represents one edit window for a document, there can be multiple ones f...
Definition: viewsh.hxx:165
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
Definition: viewsh.cxx:1848
void ConfigChild_Impl(SfxChildIdentifier, SfxDockingConfig, sal_uInt16)
Definition: workwin.cxx:1533
css::uno::Any GetUserItem(const OUString &sName) const
void SetUserItem(const OUString &sName, const css::uno::Any &aValue)
void response(int nResponse)
std::shared_ptr< weld::Dialog > m_xDialog
virtual const SfxItemSet * GetOutputItemSet() const override
float u
bool isActive()
WindowDataMask
Reference< XNameAccess > m_xContainer
static SfxItemSet & rSet
Definition: shell.cxx:534
OUString aWinState
Definition: childwin.hxx:65
Reference< XFrame > xFrame
DeactivateRC
Definition: tabdlg.hxx:173
RET_OK
RET_CANCEL