bump product version to 6.3.0.0.beta1
[LibreOffice.git] / extensions / source / dbpilots / groupboxwiz.cxx
blobf8ee3b2129b5f04c204c1b1c433bcfba7be7f430
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 "groupboxwiz.hxx"
21 #include "commonpagesdbp.hxx"
22 #include <tools/debug.hxx>
23 #include <vcl/svapp.hxx>
24 #include "optiongrouplayouter.hxx"
25 #include <helpids.h>
26 #include <comphelper/processfactory.hxx>
27 #include <osl/diagnose.h>
29 #define GBW_STATE_OPTIONLIST 0
30 #define GBW_STATE_DEFAULTOPTION 1
31 #define GBW_STATE_OPTIONVALUES 2
32 #define GBW_STATE_DBFIELD 3
33 #define GBW_STATE_FINALIZE 4
36 namespace dbp
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::lang;
42 using namespace ::com::sun::star::beans;
43 using namespace ::com::sun::star::form;
44 using namespace ::svt;
46 OGroupBoxWizard::OGroupBoxWizard( vcl::Window* _pParent,
47 const Reference< XPropertySet >& _rxObjectModel, const Reference< XComponentContext >& _rxContext )
48 :OControlWizard(_pParent, _rxObjectModel, _rxContext)
49 ,m_bVisitedDefault(false)
50 ,m_bVisitedDB(false)
52 initControlSettings(&m_aSettings);
54 m_pPrevPage->SetHelpId(HID_GROUPWIZARD_PREVIOUS);
55 m_pNextPage->SetHelpId(HID_GROUPWIZARD_NEXT);
56 m_pCancel->SetHelpId(HID_GROUPWIZARD_CANCEL);
57 m_pFinish->SetHelpId(HID_GROUPWIZARD_FINISH);
58 setTitleBase(compmodule::ModuleRes(RID_STR_GROUPWIZARD_TITLE));
62 bool OGroupBoxWizard::approveControl(sal_Int16 _nClassId)
64 return FormComponentType::GROUPBOX == _nClassId;
68 VclPtr<TabPage> OGroupBoxWizard::createPage(::svt::WizardTypes::WizardState _nState)
70 switch (_nState)
72 case GBW_STATE_OPTIONLIST:
73 return VclPtr<ORadioSelectionPage>::Create(this);
75 case GBW_STATE_DEFAULTOPTION:
76 return VclPtr<ODefaultFieldSelectionPage>::Create(this);
78 case GBW_STATE_OPTIONVALUES:
79 return VclPtr<OOptionValuesPage>::Create(this);
81 case GBW_STATE_DBFIELD:
82 return VclPtr<OOptionDBFieldPage>::Create(this);
84 case GBW_STATE_FINALIZE:
85 return VclPtr<OFinalizeGBWPage>::Create(this);
88 return nullptr;
92 WizardTypes::WizardState OGroupBoxWizard::determineNextState( ::svt::WizardTypes::WizardState _nCurrentState ) const
94 switch (_nCurrentState)
96 case GBW_STATE_OPTIONLIST:
97 return GBW_STATE_DEFAULTOPTION;
99 case GBW_STATE_DEFAULTOPTION:
100 return GBW_STATE_OPTIONVALUES;
102 case GBW_STATE_OPTIONVALUES:
103 if (getContext().aFieldNames.hasElements())
104 return GBW_STATE_DBFIELD;
105 else
106 return GBW_STATE_FINALIZE;
108 case GBW_STATE_DBFIELD:
109 return GBW_STATE_FINALIZE;
112 return WZS_INVALID_STATE;
116 void OGroupBoxWizard::enterState(::svt::WizardTypes::WizardState _nState)
118 // some stuff to do before calling the base class (modifying our settings)
119 switch (_nState)
121 case GBW_STATE_DEFAULTOPTION:
122 if (!m_bVisitedDefault)
123 { // assume that the first of the radio buttons should be selected
124 DBG_ASSERT(m_aSettings.aLabels.size(), "OGroupBoxWizard::enterState: should never have reached this state!");
125 m_aSettings.sDefaultField = m_aSettings.aLabels[0];
127 m_bVisitedDefault = true;
128 break;
130 case GBW_STATE_DBFIELD:
131 if (!m_bVisitedDB)
132 { // try to generate a default for the DB field
133 // (simply use the first field in the DB names collection)
134 if (getContext().aFieldNames.hasElements())
135 m_aSettings.sDBField = getContext().aFieldNames[0];
137 m_bVisitedDB = true;
138 break;
141 // setting the def button .... to be done before the base class is called, too, 'cause the base class
142 // calls the pages, which are allowed to override our def button behaviour
143 defaultButton(GBW_STATE_FINALIZE == _nState ? WizardButtonFlags::FINISH : WizardButtonFlags::NEXT);
145 // allow "finish" on the last page only
146 enableButtons(WizardButtonFlags::FINISH, GBW_STATE_FINALIZE == _nState);
147 // allow previous on all pages but the first one
148 enableButtons(WizardButtonFlags::PREVIOUS, GBW_STATE_OPTIONLIST != _nState);
149 // allow next on all pages but the last one
150 enableButtons(WizardButtonFlags::NEXT, GBW_STATE_FINALIZE != _nState);
152 OControlWizard::enterState(_nState);
156 bool OGroupBoxWizard::onFinish()
158 // commit the basic control settings
159 commitControlSettings(&m_aSettings);
161 // create the radio buttons
164 OOptionGroupLayouter aLayouter( getComponentContext() );
165 aLayouter.doLayout(getContext(), getSettings());
167 catch(const Exception&)
169 OSL_FAIL("OGroupBoxWizard::createRadios: caught an exception while creating the radio shapes!");
172 return OControlWizard::onFinish();
175 ORadioSelectionPage::ORadioSelectionPage( OControlWizard* _pParent )
176 :OGBWPage(_pParent, "GroupRadioSelectionPage", "modules/sabpilot/ui/groupradioselectionpage.ui")
178 get(m_pRadioName, "radiolabels");
179 get(m_pMoveRight, "toright");
180 get(m_pMoveLeft, "toleft");
181 get(m_pExistingRadios, "radiobuttons");
183 if (getContext().aFieldNames.hasElements())
185 enableFormDatasourceDisplay();
188 m_pMoveLeft->SetClickHdl(LINK(this, ORadioSelectionPage, OnMoveEntry));
189 m_pMoveRight->SetClickHdl(LINK(this, ORadioSelectionPage, OnMoveEntry));
190 m_pRadioName->SetModifyHdl(LINK(this, ORadioSelectionPage, OnNameModified));
191 m_pExistingRadios->SetSelectHdl(LINK(this, ORadioSelectionPage, OnEntrySelected));
193 implCheckMoveButtons();
194 m_pExistingRadios->EnableMultiSelection(true);
196 getDialog()->defaultButton(m_pMoveRight.get());
199 ORadioSelectionPage::~ORadioSelectionPage()
201 disposeOnce();
204 void ORadioSelectionPage::dispose()
206 m_pRadioName.clear();
207 m_pMoveRight.clear();
208 m_pMoveLeft.clear();
209 m_pExistingRadios.clear();
210 OGBWPage::dispose();
213 void ORadioSelectionPage::ActivatePage()
215 OGBWPage::ActivatePage();
216 m_pRadioName->GrabFocus();
220 void ORadioSelectionPage::initializePage()
222 OGBWPage::initializePage();
224 m_pRadioName->SetText("");
226 // no need to initialize the list of radios here
227 // (we're the only one affecting this special setting, so it will be in the same state as last time this
228 // page was committed)
230 implCheckMoveButtons();
234 bool ORadioSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
236 if (!OGBWPage::commitPage(_eReason))
237 return false;
239 // copy the names of the radio buttons to be inserted
240 // and initialize the values
241 OOptionGroupSettings& rSettings = getSettings();
242 rSettings.aLabels.clear();
243 rSettings.aValues.clear();
244 rSettings.aLabels.reserve(m_pExistingRadios->GetEntryCount());
245 rSettings.aValues.reserve(m_pExistingRadios->GetEntryCount());
246 for (sal_Int32 i=0; i<m_pExistingRadios->GetEntryCount(); ++i)
248 rSettings.aLabels.push_back(m_pExistingRadios->GetEntry(i));
249 rSettings.aValues.push_back(OUString::number((i + 1)));
252 return true;
256 IMPL_LINK( ORadioSelectionPage, OnMoveEntry, Button*, _pButton, void )
258 bool bMoveLeft = (m_pMoveLeft == _pButton);
259 if (bMoveLeft)
261 while (m_pExistingRadios->GetSelectedEntryCount())
262 m_pExistingRadios->RemoveEntry(m_pExistingRadios->GetSelectedEntryPos());
264 else
266 m_pExistingRadios->InsertEntry(m_pRadioName->GetText());
267 m_pRadioName->SetText("");
270 implCheckMoveButtons();
272 //adjust the focus
273 if (bMoveLeft)
274 m_pExistingRadios->GrabFocus();
275 else
276 m_pRadioName->GrabFocus();
280 IMPL_LINK_NOARG( ORadioSelectionPage, OnEntrySelected, ListBox&, void )
282 implCheckMoveButtons();
286 IMPL_LINK_NOARG( ORadioSelectionPage, OnNameModified, Edit&, void )
288 implCheckMoveButtons();
292 bool ORadioSelectionPage::canAdvance() const
294 return 0 != m_pExistingRadios->GetEntryCount();
298 void ORadioSelectionPage::implCheckMoveButtons()
300 bool bHaveSome = (0 != m_pExistingRadios->GetEntryCount());
301 bool bSelectedSome = (0 != m_pExistingRadios->GetSelectedEntryCount());
302 bool bUnfinishedInput = !m_pRadioName->GetText().isEmpty();
304 m_pMoveLeft->Enable(bSelectedSome);
305 m_pMoveRight->Enable(bUnfinishedInput);
307 getDialog()->enableButtons(WizardButtonFlags::NEXT, bHaveSome);
309 if (bUnfinishedInput)
311 if (0 == (m_pMoveRight->GetStyle() & WB_DEFBUTTON))
312 getDialog()->defaultButton(m_pMoveRight.get());
314 else
316 if (WB_DEFBUTTON == (m_pMoveRight->GetStyle() & WB_DEFBUTTON))
317 getDialog()->defaultButton(WizardButtonFlags::NEXT);
321 ODefaultFieldSelectionPage::ODefaultFieldSelectionPage( OControlWizard* _pParent )
322 :OMaybeListSelectionPage(_pParent, "DefaultFieldSelectionPage", "modules/sabpilot/ui/defaultfieldselectionpage.ui")
324 get(m_pDefSelYes, "defaultselectionyes");
325 get(m_pDefSelNo, "defaultselectionno");
326 get(m_pDefSelection, "defselectionfield");
328 announceControls(*m_pDefSelYes, *m_pDefSelNo, *m_pDefSelection);
329 m_pDefSelection->SetDropDownLineCount(10);
330 m_pDefSelection->SetStyle(WB_DROPDOWN);
333 ODefaultFieldSelectionPage::~ODefaultFieldSelectionPage()
335 disposeOnce();
338 void ODefaultFieldSelectionPage::dispose()
340 m_pDefSelYes.clear();
341 m_pDefSelNo.clear();
342 m_pDefSelection.clear();
343 OMaybeListSelectionPage::dispose();
346 void ODefaultFieldSelectionPage::initializePage()
348 OMaybeListSelectionPage::initializePage();
350 const OOptionGroupSettings& rSettings = getSettings();
352 // fill the listbox
353 m_pDefSelection->Clear();
354 for (auto const& label : rSettings.aLabels)
355 m_pDefSelection->InsertEntry(label);
358 implInitialize(rSettings.sDefaultField);
362 bool ODefaultFieldSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
364 if (!OMaybeListSelectionPage::commitPage(_eReason))
365 return false;
367 OOptionGroupSettings& rSettings = getSettings();
368 implCommit(rSettings.sDefaultField);
370 return true;
373 OOptionValuesPage::OOptionValuesPage( OControlWizard* _pParent )
374 :OGBWPage(_pParent, "OptionValuesPage", "modules/sabpilot/ui/optionvaluespage.ui")
375 ,m_nLastSelection(::svt::WizardTypes::WizardState(-1))
377 get(m_pValue, "optionvalue");
378 get(m_pOptions, "radiobuttons");
380 m_pOptions->SetSelectHdl(LINK(this, OOptionValuesPage, OnOptionSelected));
383 OOptionValuesPage::~OOptionValuesPage()
385 disposeOnce();
388 void OOptionValuesPage::dispose()
390 m_pValue.clear();
391 m_pOptions.clear();
392 OGBWPage::dispose();
395 IMPL_LINK_NOARG( OOptionValuesPage, OnOptionSelected, ListBox&, void )
397 implTraveledOptions();
401 void OOptionValuesPage::ActivatePage()
403 OGBWPage::ActivatePage();
404 m_pValue->GrabFocus();
408 void OOptionValuesPage::implTraveledOptions()
410 if (::svt::WizardTypes::WizardState(-1) != m_nLastSelection)
412 // save the value for the last option
413 DBG_ASSERT(static_cast<size_t>(m_nLastSelection) < m_aUncommittedValues.size(), "OOptionValuesPage::implTraveledOptions: invalid previous selection index!");
414 m_aUncommittedValues[m_nLastSelection] = m_pValue->GetText();
417 m_nLastSelection = m_pOptions->GetSelectedEntryPos();
418 DBG_ASSERT(static_cast<size_t>(m_nLastSelection) < m_aUncommittedValues.size(), "OOptionValuesPage::implTraveledOptions: invalid new selection index!");
419 m_pValue->SetText(m_aUncommittedValues[m_nLastSelection]);
423 void OOptionValuesPage::initializePage()
425 OGBWPage::initializePage();
427 const OOptionGroupSettings& rSettings = getSettings();
428 DBG_ASSERT(rSettings.aLabels.size(), "OOptionValuesPage::initializePage: no options!!");
429 DBG_ASSERT(rSettings.aLabels.size() == rSettings.aValues.size(), "OOptionValuesPage::initializePage: inconsistent data!");
431 // fill the list with all available options
432 m_pOptions->Clear();
433 m_nLastSelection = -1;
434 for (auto const& label : rSettings.aLabels)
435 m_pOptions->InsertEntry(label);
437 // remember the values ... can't set them directly in the settings without the explicit commit call
438 // so we need have a copy of the values
439 m_aUncommittedValues = rSettings.aValues;
441 // select the first entry
442 m_pOptions->SelectEntryPos(0);
443 implTraveledOptions();
447 bool OOptionValuesPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
449 if (!OGBWPage::commitPage(_eReason))
450 return false;
452 OOptionGroupSettings& rSettings = getSettings();
454 // commit the current value
455 implTraveledOptions();
456 // copy the uncommitted values
457 rSettings.aValues = m_aUncommittedValues;
459 return true;
462 OOptionDBFieldPage::OOptionDBFieldPage( OControlWizard* _pParent )
463 :ODBFieldPage(_pParent)
465 setDescriptionText(compmodule::ModuleRes(RID_STR_GROUPWIZ_DBFIELD));
469 OUString& OOptionDBFieldPage::getDBFieldSetting()
471 return static_cast<OGroupBoxWizard*>(getDialog())->getSettings().sDBField;
474 OFinalizeGBWPage::OFinalizeGBWPage( OControlWizard* _pParent )
475 :OGBWPage(_pParent, "OptionsFinalPage", "modules/sabpilot/ui/optionsfinalpage.ui")
477 get(m_pName, "nameit");
480 OFinalizeGBWPage::~OFinalizeGBWPage()
482 disposeOnce();
485 void OFinalizeGBWPage::dispose()
487 m_pName.clear();
488 OGBWPage::dispose();
491 void OFinalizeGBWPage::ActivatePage()
493 OGBWPage::ActivatePage();
494 m_pName->GrabFocus();
498 bool OFinalizeGBWPage::canAdvance() const
500 return false;
504 void OFinalizeGBWPage::initializePage()
506 OGBWPage::initializePage();
508 const OOptionGroupSettings& rSettings = getSettings();
509 m_pName->SetText(rSettings.sControlLabel);
513 bool OFinalizeGBWPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
515 if (!OGBWPage::commitPage(_eReason))
516 return false;
518 getSettings().sControlLabel = m_pName->GetText();
520 return true;
524 } // namespace dbp
527 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */