nss: upgrade to release 3.73
[LibreOffice.git] / sfx2 / source / dialog / basedlgs.cxx
blobd0cafa6926e2f872fb87037238f867bfac6444ef
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/help.hxx>
21 #include <svl/eitem.hxx>
22 #include <unotools/viewoptions.hxx>
23 #include <vcl/idle.hxx>
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 <sfx2/lokhelper.hxx>
33 #include <comphelper/lok.hxx>
35 using namespace ::com::sun::star::uno;
37 #define USERITEM_NAME "UserItem"
39 class SfxModelessDialog_Impl : public SfxListener
41 public:
42 OString aWinState;
43 SfxChildWindow* pMgr;
44 bool bClosing;
45 void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
47 Idle aMoveIdle;
50 void SfxModelessDialog_Impl::Notify( SfxBroadcaster&, const SfxHint& rHint )
52 if (pMgr && rHint.GetId() == SfxHintId::Dying) {
53 pMgr->Destroy();
57 void SfxModelessDialogController::Initialize(SfxChildWinInfo const *pInfo)
59 /* [Description]
61 Initialization of the class SfxModelessDialog via a SfxChildWinInfo.
62 The initialization is done only in a 2nd step after the constructor, this
63 constructor should be called from the derived class or from the
64 SfxChildWindows.
68 if (!pInfo)
69 return;
70 m_xImpl->aWinState = pInfo->aWinState;
71 if (m_xImpl->aWinState.isEmpty())
72 return;
73 m_xDialog->set_window_state(m_xImpl->aWinState);
76 SfxModelessDialogController::SfxModelessDialogController(SfxBindings* pBindinx,
77 SfxChildWindow *pCW, weld::Window *pParent, const OUString& rUIXMLDescription,
78 const OString& rID)
79 : SfxDialogController(pParent, rUIXMLDescription, rID)
81 Init(pBindinx, pCW);
84 /* [Description]
86 Fills a SfxChildWinInfo with specific data from SfxModelessDialog,
87 so that it can be written in the INI file. It is assumed that rinfo
88 receives all other possible relevant data in the ChildWindow class.
89 ModelessDialogs have no specific information, so that the base
90 implementation does nothing and therefore must not be called.
92 void SfxModelessDialogController::FillInfo(SfxChildWinInfo& rInfo) const
94 rInfo.aSize = m_xDialog->get_size();
97 void SfxModelessDialogController::Init(SfxBindings *pBindinx, SfxChildWindow *pCW)
99 m_pBindings = pBindinx;
100 m_xImpl.reset(new SfxModelessDialog_Impl);
101 m_xImpl->pMgr = pCW;
102 m_xImpl->bClosing = false;
103 if (pBindinx)
104 m_xImpl->StartListening( *pBindinx );
107 /* [Description]
109 If a ModelessDialog is enabled its ViewFrame will be activated.
110 This is necessary by PluginInFrames.
112 IMPL_LINK_NOARG(SfxDialogController, FocusChangeHdl, weld::Widget&, void)
114 if (m_xDialog->has_toplevel_focus())
115 Activate();
116 else
117 Deactivate();
120 void SfxModelessDialogController::Activate()
122 if (!m_xImpl)
123 return;
124 m_pBindings->SetActiveFrame(m_xImpl->pMgr->GetFrame());
125 m_xImpl->pMgr->Activate_Impl();
128 void SfxModelessDialogController::Deactivate()
130 if (!m_xImpl)
131 return;
132 m_pBindings->SetActiveFrame(css::uno::Reference< css::frame::XFrame>());
135 SfxModelessDialogController::~SfxModelessDialogController()
137 if (!m_xImpl->pMgr)
138 return;
139 auto xFrame = m_xImpl->pMgr->GetFrame();
140 if (!xFrame)
141 return;
142 if (xFrame == m_pBindings->GetActiveFrame())
143 m_pBindings->SetActiveFrame(nullptr);
146 void SfxDialogController::EndDialog()
148 if (!m_xDialog->get_visible())
149 return;
150 response(RET_CLOSE);
153 bool SfxModelessDialogController::IsClosing() const
155 return m_xImpl->bClosing;
158 void SfxModelessDialogController::EndDialog()
160 if (m_xImpl->bClosing)
161 return;
162 // In the case of async dialogs, the call to SfxDialogController::EndDialog
163 // may delete this object, so keep myself alive for the duration of this
164 // stack frame.
165 auto aHoldSelf = shared_from_this();
166 m_xImpl->bClosing = true;
167 SfxDialogController::EndDialog();
168 if (!m_xImpl)
169 return;
170 m_xImpl->bClosing = false;
173 void SfxModelessDialogController::ChildWinDispose()
175 if (m_xImpl->pMgr)
177 WindowStateMask nMask = WindowStateMask::Pos | WindowStateMask::State;
178 if (m_xDialog->get_resizable())
179 nMask |= WindowStateMask::Width | WindowStateMask::Height;
180 m_xImpl->aWinState = m_xDialog->get_window_state(nMask);
181 GetBindings().GetWorkWindow_Impl()->ConfigChild_Impl( SfxChildIdentifier::DOCKINGWINDOW, SfxDockingConfig::ALIGNDOCKINGWINDOW, m_xImpl->pMgr->GetType() );
184 m_xImpl->pMgr = nullptr;
187 /* [Description]
189 The window is closed when the ChildWindow is destroyed by running the
190 ChildWindow-slots.
192 void SfxModelessDialogController::Close()
194 if (m_xImpl->bClosing)
195 return;
196 // Execute with Parameters, since Toggle is ignored by some ChildWindows.
197 SfxBoolItem aValue(m_xImpl->pMgr->GetType(), false);
198 m_pBindings->GetDispatcher_Impl()->ExecuteList(
199 m_xImpl->pMgr->GetType(),
200 SfxCallMode::RECORD|SfxCallMode::SYNCHRON, { &aValue } );
203 SfxDialogController::SfxDialogController(weld::Widget* pParent, const OUString& rUIFile,
204 const OString& rDialogId)
205 : GenericDialogController(pParent, rUIFile, rDialogId,
206 comphelper::LibreOfficeKit::isActive()
207 && SfxViewShell::Current()
208 && SfxViewShell::Current()->isLOKMobilePhone())
210 m_xDialog->SetInstallLOKNotifierHdl(LINK(this, SfxDialogController, InstallLOKNotifierHdl));
211 m_xDialog->connect_toplevel_focus_changed(LINK(this, SfxDialogController, FocusChangeHdl));
214 IMPL_STATIC_LINK_NOARG(SfxDialogController, InstallLOKNotifierHdl, void*, vcl::ILibreOfficeKitNotifier*)
216 return SfxViewShell::Current();
219 SfxSingleTabDialogController::SfxSingleTabDialogController(weld::Widget *pParent, const SfxItemSet* pSet,
220 const OUString& rUIXMLDescription, const OString& rID)
221 : SfxOkDialogController(pParent, rUIXMLDescription, rID)
222 , m_pInputSet(pSet)
223 , m_xContainer(m_xDialog->weld_content_area())
224 , m_xOKBtn(m_xBuilder->weld_button("ok"))
225 , m_xHelpBtn(m_xBuilder->weld_button("help"))
227 m_xOKBtn->connect_clicked(LINK(this, SfxSingleTabDialogController, OKHdl_Impl));
230 SfxSingleTabDialogController::~SfxSingleTabDialogController()
234 /* [Description]
236 Insert a (new) TabPage; an existing page is deleted.
237 The passed on page is initialized with the initially given Itemset
238 through calling Reset().
240 void SfxSingleTabDialogController::SetTabPage(std::unique_ptr<SfxTabPage> xTabPage)
242 m_xSfxPage = std::move(xTabPage);
243 if (!m_xSfxPage)
244 return;
246 // First obtain the user data, only then Reset()
247 OUString sConfigId = OStringToOUString(m_xSfxPage->GetConfigId(), RTL_TEXTENCODING_UTF8);
248 SvtViewOptions aPageOpt(EViewType::TabPage, sConfigId);
249 Any aUserItem = aPageOpt.GetUserItem( USERITEM_NAME );
250 OUString sUserData;
251 aUserItem >>= sUserData;
252 m_xSfxPage->SetUserData(sUserData);
253 m_xSfxPage->Reset(GetInputItemSet());
255 m_xHelpBtn->set_visible(Help::IsContextHelpEnabled());
257 // Set TabPage text in the Dialog if there is any
258 OUString sTitle(m_xSfxPage->GetPageTitle());
259 if (!sTitle.isEmpty())
260 m_xDialog->set_title(sTitle);
262 // Dialog receives the HelpId of TabPage if there is any
263 OString sHelpId(m_xSfxPage->GetHelpId());
264 if (!sHelpId.isEmpty())
265 m_xDialog->set_help_id(sHelpId);
268 /* [Description]
270 Ok_Handler; FillItemSet() is called for setting of Page.
272 IMPL_LINK_NOARG(SfxSingleTabDialogController, OKHdl_Impl, weld::Button&, void)
274 const SfxItemSet* pInputSet = GetInputItemSet();
275 if (!pInputSet)
277 // TabPage without ItemSet
278 m_xDialog->response(RET_OK);
279 return;
282 if (!GetOutputItemSet())
284 CreateOutputItemSet(*pInputSet);
287 bool bModified = false;
289 if (m_xSfxPage->HasExchangeSupport())
291 DeactivateRC nRet = m_xSfxPage->DeactivatePage(m_xOutputSet.get());
292 if (nRet != DeactivateRC::LeavePage)
293 return;
294 else
295 bModified = m_xOutputSet->Count() > 0;
297 else
298 bModified = m_xSfxPage->FillItemSet(m_xOutputSet.get());
300 if (bModified)
302 // Save user data in IniManager.
303 m_xSfxPage->FillUserData();
304 OUString sData(m_xSfxPage->GetUserData());
306 OUString sConfigId = OStringToOUString(m_xSfxPage->GetConfigId(),
307 RTL_TEXTENCODING_UTF8);
308 SvtViewOptions aPageOpt(EViewType::TabPage, sConfigId);
309 aPageOpt.SetUserItem( USERITEM_NAME, makeAny( sData ) );
310 m_xDialog->response(RET_OK);
312 else
313 m_xDialog->response(RET_CANCEL);
316 void SfxSingleTabDialogController::CreateOutputItemSet(const SfxItemSet& rSet)
318 assert(!m_xOutputSet && "Double creation of OutputSet!");
319 m_xOutputSet.reset(new SfxItemSet(rSet));
320 m_xOutputSet->ClearItem();
323 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */