LibreOffice Module sw (master) 1
mailmergetoolbarcontrols.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
25#include <vcl/svapp.hxx>
26#include <vcl/toolbox.hxx>
27
28#include <com/sun/star/lang/XServiceInfo.hpp>
29
30#include <strings.hrc>
31#include <mmconfigitem.hxx>
32#include <swmodule.hxx>
33#include <view.hxx>
34
35using namespace css;
36
37namespace {
38
39class CurrentEdit final : public InterimItemWindow
40{
41private:
42 std::unique_ptr<weld::Entry> m_xWidget;
43
44 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
45public:
46 CurrentEdit(vcl::Window* pParent)
47 : InterimItemWindow(pParent, "modules/swriter/ui/editbox.ui", "EditBox")
48 , m_xWidget(m_xBuilder->weld_entry("entry"))
49 {
51
52 m_xWidget->connect_key_press(LINK(this, CurrentEdit, KeyInputHdl));
53 SetSizePixel(m_xWidget->get_preferred_size());
54 }
55
56 virtual void dispose() override
57 {
58 m_xWidget.reset();
60 }
61
62 void set_sensitive(bool bSensitive)
63 {
64 Enable(bSensitive);
65 m_xWidget->set_sensitive(bSensitive);
66 }
67
68 bool get_sensitive() const
69 {
70 return m_xWidget->get_sensitive();
71 }
72
73 void set_text(const OUString& rText)
74 {
75 m_xWidget->set_text(rText);
76 }
77
78 OUString get_text() const
79 {
80 return m_xWidget->get_text();
81 }
82
83 void connect_activate(const Link<weld::Entry&, bool>& rLink)
84 {
85 m_xWidget->connect_activate(rLink);
86 }
87
88 virtual ~CurrentEdit() override
89 {
91 }
92};
93
94IMPL_LINK(CurrentEdit, KeyInputHdl, const KeyEvent&, rKEvt, bool)
95{
96 return ChildKeyInput(rKEvt);
97}
98
100typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo> MMCurrentEntryController_Base;
101class MMCurrentEntryController : public MMCurrentEntryController_Base
102{
103 VclPtr<CurrentEdit> m_xCurrentEdit;
104
105 DECL_LINK(CurrentEditUpdatedHdl, weld::Entry&, bool);
106
107public:
108 explicit MMCurrentEntryController(const uno::Reference<uno::XComponentContext>& rContext)
109 : MMCurrentEntryController_Base(rContext, uno::Reference<frame::XFrame>(), ".uno:MailMergeCurrentEntry")
110 , m_xCurrentEdit(nullptr)
111 {
112 }
113
114 // XServiceInfo
115 virtual OUString SAL_CALL getImplementationName() override
116 {
117 return "lo.writer.MMCurrentEntryController";
118 }
119
120 virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override
121 {
122 return cppu::supportsService(this, rServiceName);
123 }
124
125 virtual uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
126 {
127 return { "com.sun.star.frame.ToolbarController" };
128 }
129
130 // XComponent
131 virtual void SAL_CALL dispose() override;
132
133 // XToolbarController
134 virtual uno::Reference<awt::XWindow> SAL_CALL createItemWindow(const uno::Reference<awt::XWindow>& rParent) override;
135
136 // XStatusListener
137 virtual void SAL_CALL statusChanged(const frame::FeatureStateEvent& rEvent) override;
138};
139
140class ExcludeCheckBox final : public InterimItemWindow
141{
142private:
143 std::unique_ptr<weld::CheckButton> m_xWidget;
144
145 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
146public:
147 ExcludeCheckBox(vcl::Window* pParent)
148 : InterimItemWindow(pParent, "modules/swriter/ui/checkbox.ui", "CheckBox")
149 , m_xWidget(m_xBuilder->weld_check_button("checkbutton"))
150 {
152
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());
156 }
157
158 virtual void dispose() override
159 {
160 m_xWidget.reset();
162 }
163
164 void set_sensitive(bool bSensitive)
165 {
166 Enable(bSensitive);
167 m_xWidget->set_sensitive(bSensitive);
168 }
169
170 void set_active(bool bActive)
171 {
172 m_xWidget->set_active(bActive);
173 }
174
175 void connect_toggled(const Link<weld::Toggleable&, void>& rLink)
176 {
177 m_xWidget->connect_toggled(rLink);
178 }
179
180 virtual ~ExcludeCheckBox() override
181 {
182 disposeOnce();
183 }
184};
185
186IMPL_LINK(ExcludeCheckBox, KeyInputHdl, const KeyEvent&, rKEvt, bool)
187{
188 return ChildKeyInput(rKEvt);
189}
190
192typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo> MMExcludeEntryController_Base;
193class MMExcludeEntryController : public MMExcludeEntryController_Base
194{
195 VclPtr<ExcludeCheckBox> m_xExcludeCheckbox;
196
197 DECL_STATIC_LINK(MMExcludeEntryController, ExcludeHdl, weld::Toggleable&, void);
198
199public:
200 explicit MMExcludeEntryController(const uno::Reference<uno::XComponentContext>& rContext)
201 : MMExcludeEntryController_Base(rContext, uno::Reference<frame::XFrame>(), ".uno:MailMergeExcludeEntry")
202 , m_xExcludeCheckbox(nullptr)
203 {
204 }
205
206 // XServiceInfo
207 virtual OUString SAL_CALL getImplementationName() override
208 {
209 return "lo.writer.MMExcludeEntryController";
210 }
211
212 virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override
213 {
214 return cppu::supportsService(this, rServiceName);
215 }
216
217 virtual uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
218 {
219 return { "com.sun.star.frame.ToolbarController" };
220 }
221
222 // XComponent
223 virtual void SAL_CALL dispose() override;
224
225 // XToolbarController
226 virtual uno::Reference<awt::XWindow> SAL_CALL createItemWindow(const uno::Reference<awt::XWindow>& rParent) override;
227
228 // XStatusListener
229 virtual void SAL_CALL statusChanged(const frame::FeatureStateEvent& rEvent) override;
230};
231
233{
234 SolarMutexGuard aSolarMutexGuard;
235
237 m_xCurrentEdit.disposeAndClear();
238}
239
240uno::Reference<awt::XWindow> MMCurrentEntryController::createItemWindow(const uno::Reference<awt::XWindow>& rParent)
241{
243 ToolBox* pToolbar = dynamic_cast<ToolBox*>(pParent.get());
244 if (pToolbar)
245 {
246 // make it visible
247 m_xCurrentEdit = VclPtr<CurrentEdit>::Create(pToolbar);
248 m_xCurrentEdit->connect_activate(LINK(this, MMCurrentEntryController, CurrentEditUpdatedHdl));
249 }
250
251 return VCLUnoHelper::GetInterface(m_xCurrentEdit);
252}
253
254IMPL_LINK(MMCurrentEntryController, CurrentEditUpdatedHdl, weld::Entry&, rEdit, bool)
255{
256 std::shared_ptr<SwMailMergeConfigItem> xConfigItem;
257 if (SwView* pView = GetActiveView())
258 xConfigItem = pView->GetMailMergeConfigItem();
259
260 if (!xConfigItem)
261 return true;
262
263 OUString aText(rEdit.get_text());
264 sal_Int32 nEntry = aText.toInt32();
265 if (!aText.isEmpty() && nEntry != xConfigItem->GetResultSetPosition())
266 {
267 xConfigItem->MoveResultSet(nEntry);
268 // notify about the change
269 dispatchCommand(".uno:MailMergeCurrentEntry", uno::Sequence<beans::PropertyValue>());
270 }
271 return true;
272};
273
274void MMCurrentEntryController::statusChanged(const frame::FeatureStateEvent& rEvent)
275{
276 if (!m_xCurrentEdit)
277 return;
278
279 std::shared_ptr<SwMailMergeConfigItem> xConfigItem;
280 if (SwView* pView = GetActiveView())
281 xConfigItem = pView->GetMailMergeConfigItem();
282
283 if (!xConfigItem || !rEvent.IsEnabled)
284 {
285 m_xCurrentEdit->set_sensitive(false);
286 m_xCurrentEdit->set_text("");
287 }
288 else
289 {
290 sal_Int32 nEntry = m_xCurrentEdit->get_text().toInt32();
291 if (!m_xCurrentEdit->get_sensitive() || nEntry != xConfigItem->GetResultSetPosition())
292 {
293 m_xCurrentEdit->set_sensitive(true);
294 m_xCurrentEdit->set_text(OUString::number(xConfigItem->GetResultSetPosition()));
295 }
296 }
297}
298
300{
301 SolarMutexGuard aSolarMutexGuard;
302
304 m_xExcludeCheckbox.disposeAndClear();
305}
306
307uno::Reference<awt::XWindow> MMExcludeEntryController::createItemWindow(const uno::Reference<awt::XWindow>& rParent)
308{
310 ToolBox* pToolbar = dynamic_cast<ToolBox*>(pParent.get());
311 if (pToolbar)
312 {
313 // make it visible
314 m_xExcludeCheckbox = VclPtr<ExcludeCheckBox>::Create(pToolbar);
315 m_xExcludeCheckbox->connect_toggled(LINK(this, MMExcludeEntryController, ExcludeHdl));
316 }
317
318 return VCLUnoHelper::GetInterface(m_xExcludeCheckbox);
319}
320
321IMPL_STATIC_LINK(MMExcludeEntryController, ExcludeHdl, weld::Toggleable&, rCheckbox, void)
322{
323 std::shared_ptr<SwMailMergeConfigItem> xConfigItem;
324 if (SwView* pView = GetActiveView())
325 xConfigItem = pView->GetMailMergeConfigItem();
326
327 if (xConfigItem)
328 xConfigItem->ExcludeRecord(xConfigItem->GetResultSetPosition(), rCheckbox.get_active());
329};
330
331void MMExcludeEntryController::statusChanged(const frame::FeatureStateEvent& rEvent)
332{
333 if (!m_xExcludeCheckbox)
334 return;
335
336 std::shared_ptr<SwMailMergeConfigItem> xConfigItem;
337 if (SwView* pView = GetActiveView())
338 xConfigItem = pView->GetMailMergeConfigItem();
339
340 if (!xConfigItem || !rEvent.IsEnabled)
341 {
342 m_xExcludeCheckbox->set_sensitive(false);
343 m_xExcludeCheckbox->set_active(false);
344 }
345 else
346 {
347 m_xExcludeCheckbox->set_sensitive(true);
348 m_xExcludeCheckbox->set_active(xConfigItem->IsRecordExcluded(xConfigItem->GetResultSetPosition()));
349 }
350}
351
352}
353
354extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface *
356 uno::XComponentContext *context,
357 uno::Sequence<uno::Any> const &)
358{
359 return cppu::acquire(new MMCurrentEntryController(context));
360}
361
362extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface *
364 uno::XComponentContext *context,
365 uno::Sequence<uno::Any> const &)
366{
367 return cppu::acquire(new MMExcludeEntryController(context));
368}
369
370/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Image > m_xWidget
IMPL_LINK(SwAccessibleDocument, WindowChildEventListener, VclWindowEvent &, rEvent, void)
Definition: accdoc.cxx:386
virtual void dispose() override
void InitControlBase(weld::Widget *pWidget)
Definition: view.hxx:146
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
reference_type * get() const
static VclPtr< reference_type > Create(Arg &&... arg)
virtual void SAL_CALL dispose() override
virtual void SetSizePixel(const Size &rNewSize)
void Enable(bool bEnable=true, bool bChild=true)
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
SAL_DLLPUBLIC_EXPORT uno::XInterface * lo_writer_MMCurrentEntryController_get_implementation(uno::XComponentContext *context, uno::Sequence< uno::Any > const &)
SAL_DLLPUBLIC_EXPORT uno::XInterface * lo_writer_MMExcludeEntryController_get_implementation(uno::XComponentContext *context, uno::Sequence< uno::Any > const &)
rEdit set_text(aStr)
bool dispatchCommand(const OUString &rCommand, const uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const uno::Reference< css::frame::XDispatchResultListener > &rListener)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Reference
IMPL_STATIC_LINK(SwRetrievedInputStreamDataManager, LinkedInputStreamReady, void *, p, void)
callback function, which is triggered by input stream data manager on filling of the data container t...
SwView * GetActiveView()
Definition: swmodul1.cxx:115
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168
unsigned char sal_Bool