1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
39 class CurrentEdit final
: public InterimItemWindow
42 std::unique_ptr
<weld::Entry
> m_xWidget
;
44 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
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
59 InterimItemWindow::dispose();
62 void set_sensitive(bool 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
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 typedef cppu::ImplInheritanceHelper
< ::svt::ToolboxController
, css::lang::XServiceInfo
> MMCurrentEntryController_Base
;
101 class MMCurrentEntryController
: public MMCurrentEntryController_Base
103 VclPtr
<CurrentEdit
> m_xCurrentEdit
;
105 DECL_LINK(CurrentEditUpdatedHdl
, weld::Entry
&, bool);
108 explicit MMCurrentEntryController(const uno::Reference
<uno::XComponentContext
>& rContext
)
109 : MMCurrentEntryController_Base(rContext
, uno::Reference
<frame::XFrame
>(), ".uno:MailMergeCurrentEntry")
110 , m_xCurrentEdit(nullptr)
115 virtual OUString SAL_CALL
getImplementationName() override
117 return "lo.writer.MMCurrentEntryController";
120 virtual sal_Bool SAL_CALL
supportsService(const OUString
& rServiceName
) override
122 return cppu::supportsService(this, rServiceName
);
125 virtual uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
127 return { "com.sun.star.frame.ToolbarController" };
131 virtual void SAL_CALL
dispose() override
;
133 // XToolbarController
134 virtual uno::Reference
<awt::XWindow
> SAL_CALL
createItemWindow(const uno::Reference
<awt::XWindow
>& rParent
) override
;
137 virtual void SAL_CALL
statusChanged(const frame::FeatureStateEvent
& rEvent
) override
;
140 class ExcludeCheckBox final
: public InterimItemWindow
143 std::unique_ptr
<weld::CheckButton
> m_xWidget
;
145 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
147 ExcludeCheckBox(vcl::Window
* pParent
)
148 : InterimItemWindow(pParent
, "modules/swriter/ui/checkbox.ui", "CheckBox")
149 , m_xWidget(m_xBuilder
->weld_check_button("checkbutton"))
151 InitControlBase(m_xWidget
.get());
153 m_xWidget
->set_label(SwResId(ST_EXCLUDE
));
154 m_xWidget
->connect_key_press(LINK(this, ExcludeCheckBox
, KeyInputHdl
));
155 SetSizePixel(m_xWidget
->get_preferred_size());
158 virtual void dispose() override
161 InterimItemWindow::dispose();
164 void set_sensitive(bool bSensitive
)
167 m_xWidget
->set_sensitive(bSensitive
);
170 void set_active(bool bActive
)
172 m_xWidget
->set_active(bActive
);
175 void connect_toggled(const Link
<weld::Toggleable
&, void>& rLink
)
177 m_xWidget
->connect_toggled(rLink
);
180 virtual ~ExcludeCheckBox() override
186 IMPL_LINK(ExcludeCheckBox
, KeyInputHdl
, const KeyEvent
&, rKEvt
, bool)
188 return ChildKeyInput(rKEvt
);
191 /// Controller for .uno:MailMergeExcludeEntry toolbar checkbox: creates the checkbox & handles the value.
192 typedef cppu::ImplInheritanceHelper
< ::svt::ToolboxController
, css::lang::XServiceInfo
> MMExcludeEntryController_Base
;
193 class MMExcludeEntryController
: public MMExcludeEntryController_Base
195 VclPtr
<ExcludeCheckBox
> m_xExcludeCheckbox
;
197 DECL_STATIC_LINK(MMExcludeEntryController
, ExcludeHdl
, weld::Toggleable
&, void);
200 explicit MMExcludeEntryController(const uno::Reference
<uno::XComponentContext
>& rContext
)
201 : MMExcludeEntryController_Base(rContext
, uno::Reference
<frame::XFrame
>(), ".uno:MailMergeExcludeEntry")
202 , m_xExcludeCheckbox(nullptr)
207 virtual OUString SAL_CALL
getImplementationName() override
209 return "lo.writer.MMExcludeEntryController";
212 virtual sal_Bool SAL_CALL
supportsService(const OUString
& rServiceName
) override
214 return cppu::supportsService(this, rServiceName
);
217 virtual uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
219 return { "com.sun.star.frame.ToolbarController" };
223 virtual void SAL_CALL
dispose() override
;
225 // XToolbarController
226 virtual uno::Reference
<awt::XWindow
> SAL_CALL
createItemWindow(const uno::Reference
<awt::XWindow
>& rParent
) override
;
229 virtual void SAL_CALL
statusChanged(const frame::FeatureStateEvent
& rEvent
) override
;
232 void MMCurrentEntryController::dispose()
234 SolarMutexGuard aSolarMutexGuard
;
236 svt::ToolboxController::dispose();
237 m_xCurrentEdit
.disposeAndClear();
240 uno::Reference
<awt::XWindow
> MMCurrentEntryController::createItemWindow(const uno::Reference
<awt::XWindow
>& rParent
)
242 VclPtr
<vcl::Window
> pParent
= VCLUnoHelper::GetWindow(rParent
);
243 ToolBox
* pToolbar
= dynamic_cast<ToolBox
*>(pParent
.get());
247 m_xCurrentEdit
= VclPtr
<CurrentEdit
>::Create(pToolbar
);
248 m_xCurrentEdit
->connect_activate(LINK(this, MMCurrentEntryController
, CurrentEditUpdatedHdl
));
251 return VCLUnoHelper::GetInterface(m_xCurrentEdit
);
254 IMPL_LINK(MMCurrentEntryController
, CurrentEditUpdatedHdl
, weld::Entry
&, rEdit
, bool)
256 std::shared_ptr
<SwMailMergeConfigItem
> xConfigItem
;
257 if (SwView
* pView
= GetActiveView())
258 xConfigItem
= pView
->GetMailMergeConfigItem();
263 OUString
aText(rEdit
.get_text());
264 sal_Int32 nEntry
= aText
.toInt32();
265 if (!aText
.isEmpty() && nEntry
!= xConfigItem
->GetResultSetPosition())
267 xConfigItem
->MoveResultSet(nEntry
);
268 // notify about the change
269 dispatchCommand(".uno:MailMergeCurrentEntry", uno::Sequence
<beans::PropertyValue
>());
274 void MMCurrentEntryController::statusChanged(const frame::FeatureStateEvent
& rEvent
)
279 std::shared_ptr
<SwMailMergeConfigItem
> xConfigItem
;
280 if (SwView
* pView
= GetActiveView())
281 xConfigItem
= pView
->GetMailMergeConfigItem();
283 if (!xConfigItem
|| !rEvent
.IsEnabled
)
285 m_xCurrentEdit
->set_sensitive(false);
286 m_xCurrentEdit
->set_text("");
290 sal_Int32 nEntry
= m_xCurrentEdit
->get_text().toInt32();
291 if (!m_xCurrentEdit
->get_sensitive() || nEntry
!= xConfigItem
->GetResultSetPosition())
293 m_xCurrentEdit
->set_sensitive(true);
294 m_xCurrentEdit
->set_text(OUString::number(xConfigItem
->GetResultSetPosition()));
299 void MMExcludeEntryController::dispose()
301 SolarMutexGuard aSolarMutexGuard
;
303 svt::ToolboxController::dispose();
304 m_xExcludeCheckbox
.disposeAndClear();
307 uno::Reference
<awt::XWindow
> MMExcludeEntryController::createItemWindow(const uno::Reference
<awt::XWindow
>& rParent
)
309 VclPtr
<vcl::Window
> pParent
= VCLUnoHelper::GetWindow(rParent
);
310 ToolBox
* pToolbar
= dynamic_cast<ToolBox
*>(pParent
.get());
314 m_xExcludeCheckbox
= VclPtr
<ExcludeCheckBox
>::Create(pToolbar
);
315 m_xExcludeCheckbox
->connect_toggled(LINK(this, MMExcludeEntryController
, ExcludeHdl
));
318 return VCLUnoHelper::GetInterface(m_xExcludeCheckbox
);
321 IMPL_STATIC_LINK(MMExcludeEntryController
, ExcludeHdl
, weld::Toggleable
&, rCheckbox
, void)
323 std::shared_ptr
<SwMailMergeConfigItem
> xConfigItem
;
324 if (SwView
* pView
= GetActiveView())
325 xConfigItem
= pView
->GetMailMergeConfigItem();
328 xConfigItem
->ExcludeRecord(xConfigItem
->GetResultSetPosition(), rCheckbox
.get_active());
331 void MMExcludeEntryController::statusChanged(const frame::FeatureStateEvent
& rEvent
)
333 if (!m_xExcludeCheckbox
)
336 std::shared_ptr
<SwMailMergeConfigItem
> xConfigItem
;
337 if (SwView
* pView
= GetActiveView())
338 xConfigItem
= pView
->GetMailMergeConfigItem();
340 if (!xConfigItem
|| !rEvent
.IsEnabled
)
342 m_xExcludeCheckbox
->set_sensitive(false);
343 m_xExcludeCheckbox
->set_active(false);
347 m_xExcludeCheckbox
->set_sensitive(true);
348 m_xExcludeCheckbox
->set_active(xConfigItem
->IsRecordExcluded(xConfigItem
->GetResultSetPosition()));
354 extern "C" SAL_DLLPUBLIC_EXPORT
uno::XInterface
*
355 lo_writer_MMCurrentEntryController_get_implementation(
356 uno::XComponentContext
*context
,
357 uno::Sequence
<uno::Any
> const &)
359 return cppu::acquire(new MMCurrentEntryController(context
));
362 extern "C" SAL_DLLPUBLIC_EXPORT
uno::XInterface
*
363 lo_writer_MMExcludeEntryController_get_implementation(
364 uno::XComponentContext
*context
,
365 uno::Sequence
<uno::Any
> const &)
367 return cppu::acquire(new MMExcludeEntryController(context
));
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */