LibreOffice Module extensions (master) 1
groupboxwiz.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 "groupboxwiz.hxx"
21#include "commonpagesdbp.hxx"
22#include <tools/debug.hxx>
25#include <helpids.h>
26#include <o3tl/safeint.hxx>
27
28#define GBW_STATE_OPTIONLIST 0
29#define GBW_STATE_DEFAULTOPTION 1
30#define GBW_STATE_OPTIONVALUES 2
31#define GBW_STATE_DBFIELD 3
32#define GBW_STATE_FINALIZE 4
33
34namespace dbp
35{
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::lang;
38 using namespace ::com::sun::star::beans;
39 using namespace ::com::sun::star::form;
40
42 const Reference< XPropertySet >& _rxObjectModel, const Reference< XComponentContext >& _rxContext )
43 : OControlWizard(_pParent, _rxObjectModel, _rxContext)
44 , m_bVisitedDefault(false)
45 , m_bVisitedDB(false)
46 {
48
53 setTitleBase(compmodule::ModuleRes(RID_STR_GROUPWIZARD_TITLE));
54 }
55
56 bool OGroupBoxWizard::approveControl(sal_Int16 _nClassId)
57 {
58 return FormComponentType::GROUPBOX == _nClassId;
59 }
60
62 {
63 OUString sIdent(OUString::number(_nState));
64 weld::Container* pPageContainer = m_xAssistant->append_page(sIdent);
65
66 switch (_nState)
67 {
69 return std::make_unique<ORadioSelectionPage>(pPageContainer, this);
70
72 return std::make_unique<ODefaultFieldSelectionPage>(pPageContainer, this);
73
75 return std::make_unique<OOptionValuesPage>(pPageContainer, this);
76
78 return std::make_unique<OOptionDBFieldPage>(pPageContainer, this);
79
81 return std::make_unique<OFinalizeGBWPage>(pPageContainer, this);
82 }
83
84 return nullptr;
85 }
86
88 {
89 switch (_nCurrentState)
90 {
93
96
98 if (getContext().aFieldNames.hasElements())
99 return GBW_STATE_DBFIELD;
100 else
101 return GBW_STATE_FINALIZE;
102
104 return GBW_STATE_FINALIZE;
105 }
106
107 return WZS_INVALID_STATE;
108 }
109
111 {
112 // some stuff to do before calling the base class (modifying our settings)
113 switch (_nState)
114 {
117 { // assume that the first of the radio buttons should be selected
118 DBG_ASSERT(m_aSettings.aLabels.size(), "OGroupBoxWizard::enterState: should never have reached this state!");
120 }
121 m_bVisitedDefault = true;
122 break;
123
125 if (!m_bVisitedDB)
126 { // try to generate a default for the DB field
127 // (simply use the first field in the DB names collection)
128 if (getContext().aFieldNames.hasElements())
130 }
131 m_bVisitedDB = true;
132 break;
133 }
134
135 // setting the def button... to be done before the base class is called, too, 'cause the base class
136 // calls the pages, which are allowed to override our def button behaviour
137 defaultButton(GBW_STATE_FINALIZE == _nState ? WizardButtonFlags::FINISH : WizardButtonFlags::NEXT);
138
139 // allow "finish" on the last page only
140 enableButtons(WizardButtonFlags::FINISH, GBW_STATE_FINALIZE == _nState);
141 // allow previous on all pages but the first one
142 enableButtons(WizardButtonFlags::PREVIOUS, GBW_STATE_OPTIONLIST != _nState);
143 // allow next on all pages but the last one
144 enableButtons(WizardButtonFlags::NEXT, GBW_STATE_FINALIZE != _nState);
145
147 }
148
150 {
151 // commit the basic control settings
153
154 // create the radio buttons
155 try
156 {
158 aLayouter.doLayout(getContext(), getSettings());
159 }
160 catch(const Exception&)
161 {
162 TOOLS_WARN_EXCEPTION("extensions.dbpilots",
163 "caught an exception while creating the radio shapes!");
164 }
165
167 }
168
170 : OGBWPage(pPage, pWizard, "modules/sabpilot/ui/groupradioselectionpage.ui", "GroupRadioSelectionPage")
171 , m_xRadioName(m_xBuilder->weld_entry("radiolabels"))
172 , m_xMoveRight(m_xBuilder->weld_button("toright"))
173 , m_xMoveLeft(m_xBuilder->weld_button("toleft"))
174 , m_xExistingRadios(m_xBuilder->weld_tree_view("radiobuttons"))
175 {
176 if (getContext().aFieldNames.hasElements())
177 {
179 }
180
181 m_xMoveLeft->connect_clicked(LINK(this, ORadioSelectionPage, OnMoveEntry));
182 m_xMoveRight->connect_clicked(LINK(this, ORadioSelectionPage, OnMoveEntry));
183 m_xRadioName->connect_changed(LINK(this, ORadioSelectionPage, OnNameModified));
184 m_xExistingRadios->connect_changed(LINK(this, ORadioSelectionPage, OnEntrySelected));
185
187 m_xExistingRadios->set_selection_mode(SelectionMode::Multiple);
188
190 }
191
193 {
194 }
195
197 {
199 m_xRadioName->grab_focus();
200 }
201
203 {
205
206 m_xRadioName->set_text("");
207
208 // no need to initialize the list of radios here
209 // (we're the only one affecting this special setting, so it will be in the same state as last time this
210 // page was committed)
211
213 }
214
216 {
217 if (!OGBWPage::commitPage(_eReason))
218 return false;
219
220 // copy the names of the radio buttons to be inserted
221 // and initialize the values
222 OOptionGroupSettings& rSettings = getSettings();
223 rSettings.aLabels.clear();
224 rSettings.aValues.clear();
225 rSettings.aLabels.reserve(m_xExistingRadios->n_children());
226 rSettings.aValues.reserve(m_xExistingRadios->n_children());
227 for (sal_Int32 i=0; i<m_xExistingRadios->n_children(); ++i)
228 {
229 rSettings.aLabels.push_back(m_xExistingRadios->get_text(i));
230 rSettings.aValues.push_back(OUString::number(i + 1));
231 }
232
233 return true;
234 }
235
236 IMPL_LINK( ORadioSelectionPage, OnMoveEntry, weld::Button&, rButton, void )
237 {
238 bool bMoveLeft = (m_xMoveLeft.get() == &rButton);
239 if (bMoveLeft)
240 {
241 while (m_xExistingRadios->count_selected_rows())
242 m_xExistingRadios->remove(m_xExistingRadios->get_selected_index());
243 }
244 else
245 {
246 m_xExistingRadios->append_text(m_xRadioName->get_text());
247 m_xRadioName->set_text("");
248 }
249
250 implCheckMoveButtons();
251
252 //adjust the focus
253 if (bMoveLeft)
254 m_xExistingRadios->grab_focus();
255 else
256 m_xRadioName->grab_focus();
257 }
258
260 {
261 implCheckMoveButtons();
262 }
263
265 {
266 implCheckMoveButtons();
267 }
268
270 {
271 return 0 != m_xExistingRadios->n_children();
272 }
273
275 {
276 bool bHaveSome = (0 != m_xExistingRadios->n_children());
277 bool bSelectedSome = (0 != m_xExistingRadios->count_selected_rows());
278 bool bUnfinishedInput = !m_xRadioName->get_text().isEmpty();
279
280 m_xMoveLeft->set_sensitive(bSelectedSome);
281 m_xMoveRight->set_sensitive(bUnfinishedInput);
282
283 OControlWizard* pDialogController = getDialog();
284
285 pDialogController->enableButtons(WizardButtonFlags::NEXT, bHaveSome);
286
287 weld::Dialog* pDialog = pDialogController->getDialog();
288
289 if (bUnfinishedInput)
290 {
291 if (!pDialog->is_default_widget(m_xMoveRight.get()))
292 pDialogController->defaultButton(m_xMoveRight.get());
293 }
294 else
295 {
296 if (pDialog->is_default_widget(m_xMoveRight.get()))
297 pDialogController->defaultButton(WizardButtonFlags::NEXT);
298 }
299 }
300
302 : OMaybeListSelectionPage(pPage, pWizard, "modules/sabpilot/ui/defaultfieldselectionpage.ui", "DefaultFieldSelectionPage")
303 , m_xDefSelYes(m_xBuilder->weld_radio_button("defaultselectionyes"))
304 , m_xDefSelNo(m_xBuilder->weld_radio_button("defaultselectionno"))
305 , m_xDefSelection(m_xBuilder->weld_combo_box("defselectionfield"))
306 {
308 }
309
311 {
312 }
313
315 {
317
318 const OOptionGroupSettings& rSettings = getSettings();
319
320 // fill the listbox
321 m_xDefSelection->clear();
322 for (auto const& label : rSettings.aLabels)
323 m_xDefSelection->append_text(label);
324
325 implInitialize(rSettings.sDefaultField);
326 }
327
329 {
331 return false;
332
333 OOptionGroupSettings& rSettings = getSettings();
334 implCommit(rSettings.sDefaultField);
335
336 return true;
337 }
338
340 : OGBWPage(pPage, pWizard, "modules/sabpilot/ui/optionvaluespage.ui", "OptionValuesPage")
341 , m_xValue(m_xBuilder->weld_entry("optionvalue"))
342 , m_xOptions(m_xBuilder->weld_tree_view("radiobuttons"))
343 , m_nLastSelection(::vcl::WizardTypes::WizardState(-1))
344 {
345 m_xOptions->connect_changed(LINK(this, OOptionValuesPage, OnOptionSelected));
346 }
347
349 {
350 }
351
353 {
354 implTraveledOptions();
355 }
356
358 {
360 m_xValue->grab_focus();
361 }
362
364 {
366 {
367 // save the value for the last option
368 DBG_ASSERT(o3tl::make_unsigned(m_nLastSelection) < m_aUncommittedValues.size(), "OOptionValuesPage::implTraveledOptions: invalid previous selection index!");
370 }
371
372 m_nLastSelection = m_xOptions->get_selected_index();
373 DBG_ASSERT(o3tl::make_unsigned(m_nLastSelection) < m_aUncommittedValues.size(), "OOptionValuesPage::implTraveledOptions: invalid new selection index!");
375 }
376
378 {
380
381 const OOptionGroupSettings& rSettings = getSettings();
382 DBG_ASSERT(rSettings.aLabels.size(), "OOptionValuesPage::initializePage: no options!!");
383 DBG_ASSERT(rSettings.aLabels.size() == rSettings.aValues.size(), "OOptionValuesPage::initializePage: inconsistent data!");
384
385 // fill the list with all available options
386 m_xOptions->clear();
387 m_nLastSelection = -1;
388 for (auto const& label : rSettings.aLabels)
389 m_xOptions->append_text(label);
390
391 // remember the values ... can't set them directly in the settings without the explicit commit call
392 // so we need have a copy of the values
393 m_aUncommittedValues = rSettings.aValues;
394
395 // select the first entry
396 m_xOptions->select(0);
398 }
399
401 {
402 if (!OGBWPage::commitPage(_eReason))
403 return false;
404
405 OOptionGroupSettings& rSettings = getSettings();
406
407 // commit the current value
409 // copy the uncommitted values
410 rSettings.aValues = m_aUncommittedValues;
411
412 return true;
413 }
414
416 : ODBFieldPage(pPage, pWizard)
417 {
418 setDescriptionText(compmodule::ModuleRes(RID_STR_GROUPWIZ_DBFIELD));
419 }
420
422 {
423 return static_cast<OGroupBoxWizard*>(getDialog())->getSettings().sDBField;
424 }
425
427 : OGBWPage(pPage, pWizard, "modules/sabpilot/ui/optionsfinalpage.ui", "OptionsFinalPage")
428 , m_xName(m_xBuilder->weld_entry("nameit"))
429 {
430 }
431
433 {
434 }
435
437 {
439 m_xName->grab_focus();
440 }
441
443 {
444 return false;
445 }
446
448 {
450
451 const OOptionGroupSettings& rSettings = getSettings();
452 m_xName->set_text(rSettings.sControlLabel);
453 }
454
456 {
457 if (!OGBWPage::commitPage(_eReason))
458 return false;
459
460 getSettings().sControlLabel = m_xName->get_text();
461
462 return true;
463 }
464
465} // namespace dbp
466
467
468/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const char *const aFieldNames[]
OControlWizard * getDialog()
virtual void initializePage() override
const OControlWizardContext & getContext() const
void initControlSettings(OControlWizardSettings *_pSettings)
void commitControlSettings(OControlWizardSettings const *_pSettings)
const css::uno::Reference< css::uno::XComponentContext > & getComponentContext() const
const OControlWizardContext & getContext() const
void setDescriptionText(const OUString &rDesc)
std::unique_ptr< weld::RadioButton > m_xDefSelNo
virtual void initializePage() override
ODefaultFieldSelectionPage(weld::Container *pPage, OControlWizard *pWizard)
std::unique_ptr< weld::RadioButton > m_xDefSelYes
virtual ~ODefaultFieldSelectionPage() override
OOptionGroupSettings & getSettings()
virtual bool commitPage(::vcl::WizardTypes::CommitPageReason _eReason) override
std::unique_ptr< weld::ComboBox > m_xDefSelection
virtual bool commitPage(::vcl::WizardTypes::CommitPageReason _eReason) override
OFinalizeGBWPage(weld::Container *pPage, OControlWizard *pWizard)
virtual bool canAdvance() const override
virtual void initializePage() override
virtual ~OFinalizeGBWPage() override
std::unique_ptr< weld::Entry > m_xName
void Activate() override
OOptionGroupSettings & getSettings()
Definition: groupboxwiz.hxx:74
OGroupBoxWizard(weld::Window *_pParent, const css::uno::Reference< css::beans::XPropertySet > &_rxObjectModel, const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
Definition: groupboxwiz.cxx:41
OOptionGroupSettings m_aSettings
Definition: groupboxwiz.hxx:41
virtual std::unique_ptr< BuilderPage > createPage(WizardState _nState) override
Definition: groupboxwiz.cxx:61
virtual WizardState determineNextState(WizardState _nCurrentState) const override
Definition: groupboxwiz.cxx:87
virtual bool approveControl(sal_Int16 _nClassId) override
Definition: groupboxwiz.cxx:56
virtual void enterState(WizardState _nState) override
virtual bool onFinish() override
OOptionGroupSettings & getSettings()
Definition: groupboxwiz.hxx:53
void implCommit(OUString &_rSelection)
void announceControls(weld::RadioButton &_rYesButton, weld::RadioButton &_rNoButton, weld::ComboBox &_rSelection)
void implInitialize(const OUString &_rSelection)
OOptionDBFieldPage(weld::Container *pPage, OControlWizard *pWizard)
virtual OUString & getDBFieldSetting() override
void doLayout(const OControlWizardContext &_rContext, const OOptionGroupSettings &_rSettings)
void Activate() override
std::unique_ptr< weld::TreeView > m_xOptions
virtual void initializePage() override
OOptionValuesPage(weld::Container *pPage, OControlWizard *pWizard)
virtual ~OOptionValuesPage() override
std::unique_ptr< weld::Entry > m_xValue
std::vector< OUString > m_aUncommittedValues
virtual bool commitPage(::vcl::WizardTypes::CommitPageReason _eReason) override
::vcl::WizardTypes::WizardState m_nLastSelection
void Activate() override
std::unique_ptr< weld::Entry > m_xRadioName
Definition: groupboxwiz.hxx:79
std::unique_ptr< weld::Button > m_xMoveRight
Definition: groupboxwiz.hxx:80
virtual ~ORadioSelectionPage() override
virtual bool canAdvance() const override
std::unique_ptr< weld::TreeView > m_xExistingRadios
Definition: groupboxwiz.hxx:82
virtual bool commitPage(::vcl::WizardTypes::CommitPageReason _eReason) override
std::unique_ptr< weld::Button > m_xMoveLeft
Definition: groupboxwiz.hxx:81
virtual void initializePage() override
ORadioSelectionPage(weld::Container *pPage, OControlWizard *pWizard)
virtual bool commitPage(WizardTypes::CommitPageReason _eReason) override
virtual void Activate() override
std::unique_ptr< weld::Button > m_xNextPage
std::unique_ptr< weld::Button > m_xCancel
virtual bool onFinish()
void defaultButton(WizardButtonFlags _nWizardButtonFlags)
std::unique_ptr< weld::Button > m_xPrevPage
void enableButtons(WizardButtonFlags _nWizardButtonFlags, bool _bEnable)
std::unique_ptr< weld::Button > m_xFinish
virtual void enterState(WizardTypes::WizardState _nState)
void setTitleBase(const OUString &_rTitleBase)
virtual Dialog * getDialog() override
std::unique_ptr< weld::Assistant > m_xAssistant
virtual bool is_default_widget(const weld::Widget *pCandidate) const=0
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define GBW_STATE_DBFIELD
Definition: groupboxwiz.cxx:31
#define GBW_STATE_DEFAULTOPTION
Definition: groupboxwiz.cxx:29
#define GBW_STATE_OPTIONLIST
Definition: groupboxwiz.cxx:28
#define GBW_STATE_FINALIZE
Definition: groupboxwiz.cxx:32
#define GBW_STATE_OPTIONVALUES
Definition: groupboxwiz.cxx:30
constexpr OUStringLiteral HID_GROUPWIZARD_PREVIOUS
Definition: helpids.h:66
constexpr OUStringLiteral HID_GROUPWIZARD_FINISH
Definition: helpids.h:69
constexpr OUStringLiteral HID_GROUPWIZARD_NEXT
Definition: helpids.h:67
constexpr OUStringLiteral HID_GROUPWIZARD_CANCEL
Definition: helpids.h:68
def label(st)
@ Exception
OUString ModuleRes(TranslateId pId)
IMPL_LINK_NOARG(OTableSelectionPage, OnSearchClicked, weld::Button &, void)
IMPL_LINK(OTableSelectionPage, OnListboxDoubleClicked, weld::TreeView &, _rBox, bool)
int i
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
sal_Int16 WizardState
css::uno::Sequence< OUString > aFieldNames
std::vector< OUString > aLabels
Definition: groupboxwiz.hxx:33
std::vector< OUString > aValues
Definition: groupboxwiz.hxx:34
#define WZS_INVALID_STATE