nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / uibase / dbui / mailmergetoolbarcontrols.cxx
blob827b2aef1b0c352db8235a03016b0f8ee520893a
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 <cppuhelper/queryinterface.hxx>
21 #include <cppuhelper/supportsservice.hxx>
22 #include <svtools/toolboxcontroller.hxx>
23 #include <toolkit/helper/vclunohelper.hxx>
24 #include <vcl/InterimItemWindow.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/toolbox.hxx>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <strings.hrc>
31 #include <mmconfigitem.hxx>
32 #include <swmodule.hxx>
33 #include <view.hxx>
35 using namespace css;
37 namespace {
39 class CurrentEdit final : public InterimItemWindow
41 private:
42 std::unique_ptr<weld::Entry> m_xWidget;
44 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
45 public:
46 CurrentEdit(vcl::Window* pParent)
47 : InterimItemWindow(pParent, "modules/swriter/ui/editbox.ui", "EditBox")
48 , m_xWidget(m_xBuilder->weld_entry("entry"))
50 InitControlBase(m_xWidget.get());
52 m_xWidget->connect_key_press(LINK(this, CurrentEdit, KeyInputHdl));
53 SetSizePixel(m_xWidget->get_preferred_size());
56 virtual void dispose() override
58 m_xWidget.reset();
59 InterimItemWindow::dispose();
62 void set_sensitive(bool bSensitive)
64 Enable(bSensitive);
65 m_xWidget->set_sensitive(bSensitive);
68 bool get_sensitive() const
70 return m_xWidget->get_sensitive();
73 void set_text(const OUString& rText)
75 m_xWidget->set_text(rText);
78 OUString get_text() const
80 return m_xWidget->get_text();
83 void connect_activate(const Link<weld::Entry&, bool>& rLink)
85 m_xWidget->connect_activate(rLink);
88 virtual ~CurrentEdit() override
90 disposeOnce();
94 IMPL_LINK(CurrentEdit, KeyInputHdl, const KeyEvent&, rKEvt, bool)
96 return ChildKeyInput(rKEvt);
99 /// Controller for .uno:MailMergeCurrentEntry toolbar checkbox: creates the checkbox & handles the value.
100 class MMCurrentEntryController : public svt::ToolboxController, public lang::XServiceInfo
102 VclPtr<CurrentEdit> m_xCurrentEdit;
104 DECL_LINK(CurrentEditUpdatedHdl, weld::Entry&, bool);
106 public:
107 explicit MMCurrentEntryController(const uno::Reference<uno::XComponentContext>& rContext)
108 : svt::ToolboxController(rContext, uno::Reference<frame::XFrame>(), ".uno:MailMergeCurrentEntry")
109 , m_xCurrentEdit(nullptr)
113 // XInterface
114 virtual uno::Any SAL_CALL queryInterface(const uno::Type& aType) override
116 uno::Any a(ToolboxController::queryInterface(aType));
117 if (a.hasValue())
118 return a;
120 return ::cppu::queryInterface(aType, static_cast<lang::XServiceInfo*>(this));
123 void SAL_CALL acquire() throw () override
125 ToolboxController::acquire();
128 void SAL_CALL release() throw () override
130 ToolboxController::release();
133 // XServiceInfo
134 virtual OUString SAL_CALL getImplementationName() override
136 return "lo.writer.MMCurrentEntryController";
139 virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override
141 return cppu::supportsService(this, rServiceName);
144 virtual uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
146 return { "com.sun.star.frame.ToolbarController" };
149 // XComponent
150 virtual void SAL_CALL dispose() override;
152 // XToolbarController
153 virtual uno::Reference<awt::XWindow> SAL_CALL createItemWindow(const uno::Reference<awt::XWindow>& rParent) override;
155 // XStatusListener
156 virtual void SAL_CALL statusChanged(const frame::FeatureStateEvent& rEvent) override;
159 class ExcludeCheckBox final : public InterimItemWindow
161 private:
162 std::unique_ptr<weld::CheckButton> m_xWidget;
164 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
165 public:
166 ExcludeCheckBox(vcl::Window* pParent)
167 : InterimItemWindow(pParent, "modules/swriter/ui/checkbox.ui", "CheckBox")
168 , m_xWidget(m_xBuilder->weld_check_button("checkbutton"))
170 InitControlBase(m_xWidget.get());
172 m_xWidget->set_label(SwResId(ST_EXCLUDE));
173 m_xWidget->connect_key_press(LINK(this, ExcludeCheckBox, KeyInputHdl));
174 SetSizePixel(m_xWidget->get_preferred_size());
177 virtual void dispose() override
179 m_xWidget.reset();
180 InterimItemWindow::dispose();
183 void set_sensitive(bool bSensitive)
185 Enable(bSensitive);
186 m_xWidget->set_sensitive(bSensitive);
189 void set_active(bool bActive)
191 m_xWidget->set_active(bActive);
194 void connect_toggled(const Link<weld::ToggleButton&, void>& rLink)
196 m_xWidget->connect_toggled(rLink);
199 virtual ~ExcludeCheckBox() override
201 disposeOnce();
205 IMPL_LINK(ExcludeCheckBox, KeyInputHdl, const KeyEvent&, rKEvt, bool)
207 return ChildKeyInput(rKEvt);
210 /// Controller for .uno:MailMergeExcludeEntry toolbar checkbox: creates the checkbox & handles the value.
211 class MMExcludeEntryController : public svt::ToolboxController, public lang::XServiceInfo
213 VclPtr<ExcludeCheckBox> m_xExcludeCheckbox;
215 DECL_STATIC_LINK(MMExcludeEntryController, ExcludeHdl, weld::ToggleButton&, void);
217 public:
218 explicit MMExcludeEntryController(const uno::Reference<uno::XComponentContext>& rContext)
219 : svt::ToolboxController(rContext, uno::Reference<frame::XFrame>(), ".uno:MailMergeExcludeEntry")
220 , m_xExcludeCheckbox(nullptr)
224 // XInterface
225 virtual uno::Any SAL_CALL queryInterface(const uno::Type& aType) override
227 uno::Any a(ToolboxController::queryInterface(aType));
228 if (a.hasValue())
229 return a;
231 return ::cppu::queryInterface(aType, static_cast<lang::XServiceInfo*>(this));
234 void SAL_CALL acquire() throw () override
236 ToolboxController::acquire();
239 void SAL_CALL release() throw () override
241 ToolboxController::release();
244 // XServiceInfo
245 virtual OUString SAL_CALL getImplementationName() override
247 return "lo.writer.MMExcludeEntryController";
250 virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override
252 return cppu::supportsService(this, rServiceName);
255 virtual uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
257 return { "com.sun.star.frame.ToolbarController" };
260 // XComponent
261 virtual void SAL_CALL dispose() override;
263 // XToolbarController
264 virtual uno::Reference<awt::XWindow> SAL_CALL createItemWindow(const uno::Reference<awt::XWindow>& rParent) override;
266 // XStatusListener
267 virtual void SAL_CALL statusChanged(const frame::FeatureStateEvent& rEvent) override;
270 void MMCurrentEntryController::dispose()
272 SolarMutexGuard aSolarMutexGuard;
274 svt::ToolboxController::dispose();
275 m_xCurrentEdit.disposeAndClear();
278 uno::Reference<awt::XWindow> MMCurrentEntryController::createItemWindow(const uno::Reference<awt::XWindow>& rParent)
280 VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow(rParent);
281 ToolBox* pToolbar = dynamic_cast<ToolBox*>(pParent.get());
282 if (pToolbar)
284 // make it visible
285 m_xCurrentEdit = VclPtr<CurrentEdit>::Create(pToolbar);
286 m_xCurrentEdit->connect_activate(LINK(this, MMCurrentEntryController, CurrentEditUpdatedHdl));
289 return VCLUnoHelper::GetInterface(m_xCurrentEdit);
292 IMPL_LINK(MMCurrentEntryController, CurrentEditUpdatedHdl, weld::Entry&, rEdit, bool)
294 SwView* pView = ::GetActiveView();
295 std::shared_ptr<SwMailMergeConfigItem> xConfigItem;
296 if (pView)
297 xConfigItem = pView->GetMailMergeConfigItem();
299 if (!xConfigItem)
300 return true;
302 OUString aText(rEdit.get_text());
303 sal_Int32 nEntry = aText.toInt32();
304 if (!aText.isEmpty() && nEntry != xConfigItem->GetResultSetPosition())
306 xConfigItem->MoveResultSet(nEntry);
307 // notify about the change
308 dispatchCommand(".uno:MailMergeCurrentEntry", uno::Sequence<beans::PropertyValue>());
310 return true;
313 void MMCurrentEntryController::statusChanged(const frame::FeatureStateEvent& rEvent)
315 if (!m_xCurrentEdit)
316 return;
318 SwView* pView = ::GetActiveView();
319 std::shared_ptr<SwMailMergeConfigItem> xConfigItem;
320 if (pView)
321 xConfigItem = pView->GetMailMergeConfigItem();
323 if (!xConfigItem || !rEvent.IsEnabled)
325 m_xCurrentEdit->set_sensitive(false);
326 m_xCurrentEdit->set_text("");
328 else
330 sal_Int32 nEntry = m_xCurrentEdit->get_text().toInt32();
331 if (!m_xCurrentEdit->get_sensitive() || nEntry != xConfigItem->GetResultSetPosition())
333 m_xCurrentEdit->set_sensitive(true);
334 m_xCurrentEdit->set_text(OUString::number(xConfigItem->GetResultSetPosition()));
339 void MMExcludeEntryController::dispose()
341 SolarMutexGuard aSolarMutexGuard;
343 svt::ToolboxController::dispose();
344 m_xExcludeCheckbox.disposeAndClear();
347 uno::Reference<awt::XWindow> MMExcludeEntryController::createItemWindow(const uno::Reference<awt::XWindow>& rParent)
349 VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow(rParent);
350 ToolBox* pToolbar = dynamic_cast<ToolBox*>(pParent.get());
351 if (pToolbar)
353 // make it visible
354 m_xExcludeCheckbox = VclPtr<ExcludeCheckBox>::Create(pToolbar);
355 m_xExcludeCheckbox->connect_toggled(LINK(this, MMExcludeEntryController, ExcludeHdl));
358 return VCLUnoHelper::GetInterface(m_xExcludeCheckbox);
361 IMPL_STATIC_LINK(MMExcludeEntryController, ExcludeHdl, weld::ToggleButton&, rCheckbox, void)
363 SwView* pView = ::GetActiveView();
364 std::shared_ptr<SwMailMergeConfigItem> xConfigItem;
365 if (pView)
366 xConfigItem = pView->GetMailMergeConfigItem();
368 if (xConfigItem)
369 xConfigItem->ExcludeRecord(xConfigItem->GetResultSetPosition(), rCheckbox.get_active());
372 void MMExcludeEntryController::statusChanged(const frame::FeatureStateEvent& rEvent)
374 if (!m_xExcludeCheckbox)
375 return;
377 SwView* pView = ::GetActiveView();
378 std::shared_ptr<SwMailMergeConfigItem> xConfigItem;
379 if (pView)
380 xConfigItem = pView->GetMailMergeConfigItem();
382 if (!xConfigItem || !rEvent.IsEnabled)
384 m_xExcludeCheckbox->set_sensitive(false);
385 m_xExcludeCheckbox->set_active(false);
387 else
389 m_xExcludeCheckbox->set_sensitive(true);
390 m_xExcludeCheckbox->set_active(xConfigItem->IsRecordExcluded(xConfigItem->GetResultSetPosition()));
396 extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface *
397 lo_writer_MMCurrentEntryController_get_implementation(
398 uno::XComponentContext *context,
399 uno::Sequence<uno::Any> const &)
401 return cppu::acquire(new MMCurrentEntryController(context));
404 extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface *
405 lo_writer_MMExcludeEntryController_get_implementation(
406 uno::XComponentContext *context,
407 uno::Sequence<uno::Any> const &)
409 return cppu::acquire(new MMExcludeEntryController(context));
412 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */