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 "groupboxwiz.hxx"
21 #include "commonpagesdbp.hxx"
22 #include <tools/debug.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/msgbox.hxx>
25 #include "optiongrouplayouter.hxx"
26 #include "dbpilots.hrc"
27 #include <comphelper/processfactory.hxx>
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
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)
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(ModuleRes(RID_STR_GROUPWIZARD_TITLE
).toString());
62 bool OGroupBoxWizard::approveControl(sal_Int16 _nClassId
)
64 return FormComponentType::GROUPBOX
== _nClassId
;
68 VclPtr
<TabPage
> OGroupBoxWizard::createPage(::svt::WizardTypes::WizardState _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);
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
.getLength())
104 return GBW_STATE_DBFIELD
;
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)
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;
130 case GBW_STATE_DBFIELD
:
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
.getLength())
135 m_aSettings
.sDBField
= getContext().aFieldNames
[0];
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 void OGroupBoxWizard::createRadios()
160 OOptionGroupLayouter
aLayouter( getComponentContext() );
161 aLayouter
.doLayout(getContext(), getSettings());
163 catch(const Exception
&)
165 OSL_FAIL("OGroupBoxWizard::createRadios: caught an exception while creating the radio shapes!");
170 bool OGroupBoxWizard::onFinish()
172 // commit the basic control setttings
173 commitControlSettings(&m_aSettings
);
175 // create the radio buttons
178 return OControlWizard::onFinish();
181 ORadioSelectionPage::ORadioSelectionPage( OControlWizard
* _pParent
)
182 :OGBWPage(_pParent
, "GroupRadioSelectionPage", "modules/sabpilot/ui/groupradioselectionpage.ui")
184 get(m_pRadioName
, "radiolabels");
185 get(m_pMoveRight
, "toright");
186 get(m_pMoveLeft
, "toleft");
187 get(m_pExistingRadios
, "radiobuttons");
189 if (getContext().aFieldNames
.getLength())
191 enableFormDatasourceDisplay();
194 m_pMoveLeft
->SetClickHdl(LINK(this, ORadioSelectionPage
, OnMoveEntry
));
195 m_pMoveRight
->SetClickHdl(LINK(this, ORadioSelectionPage
, OnMoveEntry
));
196 m_pRadioName
->SetModifyHdl(LINK(this, ORadioSelectionPage
, OnNameModified
));
197 m_pExistingRadios
->SetSelectHdl(LINK(this, ORadioSelectionPage
, OnEntrySelected
));
199 implCheckMoveButtons();
200 m_pExistingRadios
->EnableMultiSelection(true);
202 getDialog()->defaultButton(m_pMoveRight
.get());
204 m_pExistingRadios
->SetAccessibleRelationMemberOf(m_pExistingRadios
);
207 ORadioSelectionPage::~ORadioSelectionPage()
212 void ORadioSelectionPage::dispose()
214 m_pRadioName
.clear();
215 m_pMoveRight
.clear();
217 m_pExistingRadios
.clear();
221 void ORadioSelectionPage::ActivatePage()
223 OGBWPage::ActivatePage();
224 m_pRadioName
->GrabFocus();
228 void ORadioSelectionPage::initializePage()
230 OGBWPage::initializePage();
232 m_pRadioName
->SetText("");
234 // no need to initialize the list of radios here
235 // (we're the only one affecting this special setting, so it will be in the same state as last time this
236 // page was committed)
238 implCheckMoveButtons();
242 bool ORadioSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason
)
244 if (!OGBWPage::commitPage(_eReason
))
247 // copy the names of the radio buttons to be inserted
248 // and initialize the values
249 OOptionGroupSettings
& rSettings
= getSettings();
250 rSettings
.aLabels
.clear();
251 rSettings
.aValues
.clear();
252 rSettings
.aLabels
.reserve(m_pExistingRadios
->GetEntryCount());
253 rSettings
.aValues
.reserve(m_pExistingRadios
->GetEntryCount());
254 for (::svt::WizardTypes::WizardState i
=0; i
<m_pExistingRadios
->GetEntryCount(); ++i
)
256 rSettings
.aLabels
.push_back(m_pExistingRadios
->GetEntry(i
));
257 rSettings
.aValues
.push_back(OUString::number((i
+ 1)));
264 IMPL_LINK( ORadioSelectionPage
, OnMoveEntry
, PushButton
*, _pButton
)
266 bool bMoveLeft
= (m_pMoveLeft
== _pButton
);
269 while (m_pExistingRadios
->GetSelectEntryCount())
270 m_pExistingRadios
->RemoveEntry(m_pExistingRadios
->GetSelectEntryPos(0));
274 m_pExistingRadios
->InsertEntry(m_pRadioName
->GetText());
275 m_pRadioName
->SetText("");
278 implCheckMoveButtons();
282 m_pExistingRadios
->GrabFocus();
284 m_pRadioName
->GrabFocus();
289 IMPL_LINK( ORadioSelectionPage
, OnEntrySelected
, ListBox
*, /*_pList*/ )
291 implCheckMoveButtons();
296 IMPL_LINK( ORadioSelectionPage
, OnNameModified
, Edit
*, /*_pList*/ )
298 implCheckMoveButtons();
303 bool ORadioSelectionPage::canAdvance() const
305 return 0 != m_pExistingRadios
->GetEntryCount();
309 void ORadioSelectionPage::implCheckMoveButtons()
311 bool bHaveSome
= (0 != m_pExistingRadios
->GetEntryCount());
312 bool bSelectedSome
= (0 != m_pExistingRadios
->GetSelectEntryCount());
313 bool bUnfinishedInput
= (!m_pRadioName
->GetText().isEmpty());
315 m_pMoveLeft
->Enable(bSelectedSome
);
316 m_pMoveRight
->Enable(bUnfinishedInput
);
318 getDialog()->enableButtons(WizardButtonFlags::NEXT
, bHaveSome
);
320 if (bUnfinishedInput
)
322 if (0 == (m_pMoveRight
->GetStyle() & WB_DEFBUTTON
))
323 getDialog()->defaultButton(m_pMoveRight
.get());
327 if (WB_DEFBUTTON
== (m_pMoveRight
->GetStyle() & WB_DEFBUTTON
))
328 getDialog()->defaultButton(WizardButtonFlags::NEXT
);
332 ODefaultFieldSelectionPage::ODefaultFieldSelectionPage( OControlWizard
* _pParent
)
333 :OMaybeListSelectionPage(_pParent
, "DefaultFieldSelectionPage", "modules/sabpilot/ui/defaultfieldselectionpage.ui")
335 get(m_pDefSelYes
, "defaultselectionyes");
336 get(m_pDefSelNo
, "defaultselectionno");
337 get(m_pDefSelection
, "defselectionfield");
339 announceControls(*m_pDefSelYes
, *m_pDefSelNo
, *m_pDefSelection
);
340 m_pDefSelection
->SetDropDownLineCount(10);
341 m_pDefSelection
->SetAccessibleRelationLabeledBy( m_pDefSelYes
);
342 m_pDefSelection
->SetStyle(WB_DROPDOWN
);
345 ODefaultFieldSelectionPage::~ODefaultFieldSelectionPage()
350 void ODefaultFieldSelectionPage::dispose()
352 m_pDefSelYes
.clear();
354 m_pDefSelection
.clear();
355 OMaybeListSelectionPage::dispose();
358 void ODefaultFieldSelectionPage::initializePage()
360 OMaybeListSelectionPage::initializePage();
362 const OOptionGroupSettings
& rSettings
= getSettings();
365 m_pDefSelection
->Clear();
366 for ( StringArray::const_iterator aLoop
= rSettings
.aLabels
.begin();
367 aLoop
!= rSettings
.aLabels
.end();
370 m_pDefSelection
->InsertEntry(*aLoop
);
373 implInitialize(rSettings
.sDefaultField
);
377 bool ODefaultFieldSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason
)
379 if (!OMaybeListSelectionPage::commitPage(_eReason
))
382 OOptionGroupSettings
& rSettings
= getSettings();
383 implCommit(rSettings
.sDefaultField
);
388 OOptionValuesPage::OOptionValuesPage( OControlWizard
* _pParent
)
389 :OGBWPage(_pParent
, "OptionValuesPage", "modules/sabpilot/ui/optionvaluespage.ui")
390 ,m_nLastSelection((::svt::WizardTypes::WizardState
)-1)
392 get(m_pValue
, "optionvalue");
393 get(m_pOptions
, "radiobuttons");
395 m_pOptions
->SetSelectHdl(LINK(this, OOptionValuesPage
, OnOptionSelected
));
397 m_pOptions
->SetAccessibleRelationMemberOf(m_pOptions
);
400 OOptionValuesPage::~OOptionValuesPage()
405 void OOptionValuesPage::dispose()
412 IMPL_LINK( OOptionValuesPage
, OnOptionSelected
, ListBox
*, /*NOTINTERESTEDIN*/ )
414 implTraveledOptions();
419 void OOptionValuesPage::ActivatePage()
421 OGBWPage::ActivatePage();
422 m_pValue
->GrabFocus();
426 void OOptionValuesPage::implTraveledOptions()
428 if ((::svt::WizardTypes::WizardState
)-1 != m_nLastSelection
)
430 // save the value for the last option
431 DBG_ASSERT((size_t)m_nLastSelection
< m_aUncommittedValues
.size(), "OOptionValuesPage::implTraveledOptions: invalid previous selection index!");
432 m_aUncommittedValues
[m_nLastSelection
] = m_pValue
->GetText();
435 m_nLastSelection
= m_pOptions
->GetSelectEntryPos();
436 DBG_ASSERT((size_t)m_nLastSelection
< m_aUncommittedValues
.size(), "OOptionValuesPage::implTraveledOptions: invalid new selection index!");
437 m_pValue
->SetText(m_aUncommittedValues
[m_nLastSelection
]);
441 void OOptionValuesPage::initializePage()
443 OGBWPage::initializePage();
445 const OOptionGroupSettings
& rSettings
= getSettings();
446 DBG_ASSERT(rSettings
.aLabels
.size(), "OOptionValuesPage::initializePage: no options!!");
447 DBG_ASSERT(rSettings
.aLabels
.size() == rSettings
.aValues
.size(), "OOptionValuesPage::initializePage: inconsistent data!");
449 // fill the list with all available options
451 m_nLastSelection
= -1;
452 for ( StringArray::const_iterator aLoop
= rSettings
.aLabels
.begin();
453 aLoop
!= rSettings
.aLabels
.end();
456 m_pOptions
->InsertEntry(*aLoop
);
458 // remember the values ... can't set them directly in the settings without the explicit commit call
459 // so we need have a copy of the values
460 m_aUncommittedValues
= rSettings
.aValues
;
462 // select the first entry
463 m_pOptions
->SelectEntryPos(0);
464 implTraveledOptions();
468 bool OOptionValuesPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason
)
470 if (!OGBWPage::commitPage(_eReason
))
473 OOptionGroupSettings
& rSettings
= getSettings();
475 // commit the current value
476 implTraveledOptions();
477 // copy the uncommitted values
478 rSettings
.aValues
= m_aUncommittedValues
;
483 OOptionDBFieldPage::OOptionDBFieldPage( OControlWizard
* _pParent
)
484 :ODBFieldPage(_pParent
)
486 setDescriptionText(ModuleRes(RID_STR_GROUPWIZ_DBFIELD
).toString());
490 OUString
& OOptionDBFieldPage::getDBFieldSetting()
492 return getSettings().sDBField
;
495 OFinalizeGBWPage::OFinalizeGBWPage( OControlWizard
* _pParent
)
496 :OGBWPage(_pParent
, "OptionsFinalPage", "modules/sabpilot/ui/optionsfinalpage.ui")
498 get(m_pName
, "nameit");
501 OFinalizeGBWPage::~OFinalizeGBWPage()
506 void OFinalizeGBWPage::dispose()
512 void OFinalizeGBWPage::ActivatePage()
514 OGBWPage::ActivatePage();
515 m_pName
->GrabFocus();
519 bool OFinalizeGBWPage::canAdvance() const
525 void OFinalizeGBWPage::initializePage()
527 OGBWPage::initializePage();
529 const OOptionGroupSettings
& rSettings
= getSettings();
530 m_pName
->SetText(rSettings
.sControlLabel
);
534 bool OFinalizeGBWPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason
)
536 if (!OGBWPage::commitPage(_eReason
))
539 getSettings().sControlLabel
= m_pName
->GetText();
548 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */