bump product version to 4.1.6.2
[LibreOffice.git] / extensions / source / dbpilots / groupboxwiz.cxx
blob597e73943c6ffa5dbfb745234c122f0b5376ce18
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 <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
35 //.........................................................................
36 namespace dbp
38 //.........................................................................
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 //=====================================================================
47 //= OGroupBoxWizard
48 //=====================================================================
49 //---------------------------------------------------------------------
50 OGroupBoxWizard::OGroupBoxWizard( Window* _pParent,
51 const Reference< XPropertySet >& _rxObjectModel, const Reference< XComponentContext >& _rxContext )
52 :OControlWizard(_pParent, ModuleRes(RID_DLG_GROUPBOXWIZARD), _rxObjectModel, _rxContext)
53 ,m_bVisitedDefault(sal_False)
54 ,m_bVisitedDB(sal_False)
56 initControlSettings(&m_aSettings);
58 m_pPrevPage->SetHelpId(HID_GROUPWIZARD_PREVIOUS);
59 m_pNextPage->SetHelpId(HID_GROUPWIZARD_NEXT);
60 m_pCancel->SetHelpId(HID_GROUPWIZARD_CANCEL);
61 m_pFinish->SetHelpId(HID_GROUPWIZARD_FINISH);
64 //---------------------------------------------------------------------
65 sal_Bool OGroupBoxWizard::approveControl(sal_Int16 _nClassId)
67 return FormComponentType::GROUPBOX == _nClassId;
70 //---------------------------------------------------------------------
71 OWizardPage* OGroupBoxWizard::createPage(::svt::WizardTypes::WizardState _nState)
73 switch (_nState)
75 case GBW_STATE_OPTIONLIST:
76 return new ORadioSelectionPage(this);
78 case GBW_STATE_DEFAULTOPTION:
79 return new ODefaultFieldSelectionPage(this);
81 case GBW_STATE_OPTIONVALUES:
82 return new OOptionValuesPage(this);
84 case GBW_STATE_DBFIELD:
85 return new OOptionDBFieldPage(this);
87 case GBW_STATE_FINALIZE:
88 return new OFinalizeGBWPage(this);
91 return NULL;
94 //---------------------------------------------------------------------
95 WizardTypes::WizardState OGroupBoxWizard::determineNextState( ::svt::WizardTypes::WizardState _nCurrentState ) const
97 switch (_nCurrentState)
99 case GBW_STATE_OPTIONLIST:
100 return GBW_STATE_DEFAULTOPTION;
102 case GBW_STATE_DEFAULTOPTION:
103 return GBW_STATE_OPTIONVALUES;
105 case GBW_STATE_OPTIONVALUES:
106 if (getContext().aFieldNames.getLength())
107 return GBW_STATE_DBFIELD;
108 else
109 return GBW_STATE_FINALIZE;
111 case GBW_STATE_DBFIELD:
112 return GBW_STATE_FINALIZE;
115 return WZS_INVALID_STATE;
118 //---------------------------------------------------------------------
119 void OGroupBoxWizard::enterState(::svt::WizardTypes::WizardState _nState)
121 // some stuff to do before calling the base class (modifying our settings)
122 switch (_nState)
124 case GBW_STATE_DEFAULTOPTION:
125 if (!m_bVisitedDefault)
126 { // assume that the first of the radio buttons should be selected
127 DBG_ASSERT(m_aSettings.aLabels.size(), "OGroupBoxWizard::enterState: should never have reached this state!");
128 m_aSettings.sDefaultField = m_aSettings.aLabels[0];
130 m_bVisitedDefault = sal_True;
131 break;
133 case GBW_STATE_DBFIELD:
134 if (!m_bVisitedDB)
135 { // try to generate a default for the DB field
136 // (simply use the first field in the DB names collection)
137 if (getContext().aFieldNames.getLength())
138 m_aSettings.sDBField = getContext().aFieldNames[0];
140 m_bVisitedDB = sal_True;
141 break;
144 // setting the def button .... to be done before the base class is called, too, 'cause the base class
145 // calls the pages, which are allowed to override our def button behaviour
146 defaultButton(GBW_STATE_FINALIZE == _nState ? WZB_FINISH : WZB_NEXT);
148 // allow "finish" on the last page only
149 enableButtons(WZB_FINISH, GBW_STATE_FINALIZE == _nState);
150 // allow previous on all pages but the first one
151 enableButtons(WZB_PREVIOUS, GBW_STATE_OPTIONLIST != _nState);
152 // allow next on all pages but the last one
153 enableButtons(WZB_NEXT, GBW_STATE_FINALIZE != _nState);
155 OControlWizard::enterState(_nState);
158 //---------------------------------------------------------------------
159 void OGroupBoxWizard::createRadios()
163 OOptionGroupLayouter aLayouter( getComponentContext() );
164 aLayouter.doLayout(getContext(), getSettings());
166 catch(const Exception&)
168 OSL_FAIL("OGroupBoxWizard::createRadios: caught an exception while creating the radio shapes!");
172 //---------------------------------------------------------------------
173 sal_Bool OGroupBoxWizard::onFinish()
175 // commit the basic control setttings
176 commitControlSettings(&m_aSettings);
178 // create the radio buttons
179 createRadios();
181 return OControlWizard::onFinish();
184 //=====================================================================
185 //= ORadioSelectionPage
186 //=====================================================================
187 //---------------------------------------------------------------------
188 ORadioSelectionPage::ORadioSelectionPage( OControlWizard* _pParent )
189 :OGBWPage(_pParent, ModuleRes(RID_PAGE_GROUPRADIOSELECTION))
190 ,m_aFrame (this, ModuleRes(FL_DATA))
191 ,m_aRadioNameLabel (this, ModuleRes(FT_RADIOLABELS))
192 ,m_aRadioName (this, ModuleRes(ET_RADIOLABELS))
193 ,m_aMoveRight (this, ModuleRes(PB_MOVETORIGHT))
194 ,m_aMoveLeft (this, ModuleRes(PB_MOVETOLEFT))
195 ,m_aExistingRadiosLabel (this, ModuleRes(FT_RADIOBUTTONS))
196 ,m_aExistingRadios (this, ModuleRes(LB_RADIOBUTTONS))
198 FreeResource();
200 if (getContext().aFieldNames.getLength())
202 enableFormDatasourceDisplay();
204 else
206 adjustControlForNoDSDisplay(&m_aFrame);
207 adjustControlForNoDSDisplay(&m_aRadioNameLabel);
208 adjustControlForNoDSDisplay(&m_aRadioName);
209 adjustControlForNoDSDisplay(&m_aMoveRight);
210 adjustControlForNoDSDisplay(&m_aMoveLeft);
211 adjustControlForNoDSDisplay(&m_aExistingRadiosLabel);
212 adjustControlForNoDSDisplay(&m_aExistingRadios, sal_True);
215 m_aMoveLeft.SetClickHdl(LINK(this, ORadioSelectionPage, OnMoveEntry));
216 m_aMoveRight.SetClickHdl(LINK(this, ORadioSelectionPage, OnMoveEntry));
217 m_aRadioName.SetModifyHdl(LINK(this, ORadioSelectionPage, OnNameModified));
218 m_aExistingRadios.SetSelectHdl(LINK(this, ORadioSelectionPage, OnEntrySelected));
220 implCheckMoveButtons();
221 m_aExistingRadios.EnableMultiSelection(sal_True);
223 getDialog()->defaultButton(&m_aMoveRight);
225 m_aExistingRadios.SetAccessibleRelationMemberOf(&m_aExistingRadios);
226 m_aExistingRadios.SetAccessibleRelationLabeledBy(&m_aExistingRadiosLabel);
229 //---------------------------------------------------------------------
230 void ORadioSelectionPage::ActivatePage()
232 OGBWPage::ActivatePage();
233 m_aRadioName.GrabFocus();
236 //---------------------------------------------------------------------
237 void ORadioSelectionPage::initializePage()
239 OGBWPage::initializePage();
241 m_aRadioName.SetText(String());
243 // no need to initialize the list of radios here
244 // (we're the only one affecting this special setting, so it will be in the same state as last time this
245 // page was commited)
247 implCheckMoveButtons();
250 //---------------------------------------------------------------------
251 sal_Bool ORadioSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
253 if (!OGBWPage::commitPage(_eReason))
254 return sal_False;
256 // copy the names of the radio buttons to be inserted
257 // and initialize the values
258 OOptionGroupSettings& rSettings = getSettings();
259 rSettings.aLabels.clear();
260 rSettings.aValues.clear();
261 rSettings.aLabels.reserve(m_aExistingRadios.GetEntryCount());
262 rSettings.aValues.reserve(m_aExistingRadios.GetEntryCount());
263 for (::svt::WizardTypes::WizardState i=0; i<m_aExistingRadios.GetEntryCount(); ++i)
265 rSettings.aLabels.push_back(m_aExistingRadios.GetEntry(i));
266 rSettings.aValues.push_back(OUString::valueOf((sal_Int32)(i + 1)));
269 return sal_True;
272 //---------------------------------------------------------------------
273 IMPL_LINK( ORadioSelectionPage, OnMoveEntry, PushButton*, _pButton )
275 sal_Bool bMoveLeft = (&m_aMoveLeft == _pButton);
276 if (bMoveLeft)
278 while (m_aExistingRadios.GetSelectEntryCount())
279 m_aExistingRadios.RemoveEntry(m_aExistingRadios.GetSelectEntryPos(0));
281 else
283 m_aExistingRadios.InsertEntry(m_aRadioName.GetText());
284 m_aRadioName.SetText(String());
287 implCheckMoveButtons();
289 //adjust the focus
290 if (bMoveLeft)
291 m_aExistingRadios.GrabFocus();
292 else
293 m_aRadioName.GrabFocus();
294 return 0L;
297 //---------------------------------------------------------------------
298 IMPL_LINK( ORadioSelectionPage, OnEntrySelected, ListBox*, /*_pList*/ )
300 implCheckMoveButtons();
301 return 0L;
304 //---------------------------------------------------------------------
305 IMPL_LINK( ORadioSelectionPage, OnNameModified, Edit*, /*_pList*/ )
307 implCheckMoveButtons();
308 return 0L;
311 //---------------------------------------------------------------------
312 bool ORadioSelectionPage::canAdvance() const
314 return 0 != m_aExistingRadios.GetEntryCount();
317 //---------------------------------------------------------------------
318 void ORadioSelectionPage::implCheckMoveButtons()
320 sal_Bool bHaveSome = (0 != m_aExistingRadios.GetEntryCount());
321 sal_Bool bSelectedSome = (0 != m_aExistingRadios.GetSelectEntryCount());
322 sal_Bool bUnfinishedInput = (!m_aRadioName.GetText().isEmpty());
324 m_aMoveLeft.Enable(bSelectedSome);
325 m_aMoveRight.Enable(bUnfinishedInput);
327 getDialog()->enableButtons(WZB_NEXT, bHaveSome);
329 if (bUnfinishedInput)
331 if (0 == (m_aMoveRight.GetStyle() & WB_DEFBUTTON))
332 getDialog()->defaultButton(&m_aMoveRight);
334 else
336 if (WB_DEFBUTTON == (m_aMoveRight.GetStyle() & WB_DEFBUTTON))
337 getDialog()->defaultButton(WZB_NEXT);
341 //=====================================================================
342 //= ODefaultFieldSelectionPage
343 //=====================================================================
344 //---------------------------------------------------------------------
345 ODefaultFieldSelectionPage::ODefaultFieldSelectionPage( OControlWizard* _pParent )
346 :OMaybeListSelectionPage(_pParent, ModuleRes(RID_PAGE_DEFAULTFIELDSELECTION))
347 ,m_aFrame (this, ModuleRes(FL_DEFAULTSELECTION))
348 ,m_aDefaultSelectionLabel (this, ModuleRes(FT_DEFAULTSELECTION))
349 ,m_aDefSelYes (this, ModuleRes(RB_DEFSELECTION_YES))
350 ,m_aDefSelNo (this, ModuleRes(RB_DEFSELECTION_NO))
351 ,m_aDefSelection (this, ModuleRes(LB_DEFSELECTIONFIELD))
353 FreeResource();
355 announceControls(m_aDefSelYes, m_aDefSelNo, m_aDefSelection);
356 m_aDefSelection.SetDropDownLineCount(10);
357 m_aDefSelection.SetAccessibleRelationLabeledBy( &m_aDefSelYes );
358 m_aDefSelection.SetAccessibleRelationMemberOf(&m_aDefaultSelectionLabel);
361 //---------------------------------------------------------------------
362 void ODefaultFieldSelectionPage::initializePage()
364 OMaybeListSelectionPage::initializePage();
366 const OOptionGroupSettings& rSettings = getSettings();
368 // fill the listbox
369 m_aDefSelection.Clear();
370 for ( ConstStringArrayIterator aLoop = rSettings.aLabels.begin();
371 aLoop != rSettings.aLabels.end();
372 ++aLoop
374 m_aDefSelection.InsertEntry(*aLoop);
377 implInitialize(rSettings.sDefaultField);
380 //---------------------------------------------------------------------
381 sal_Bool ODefaultFieldSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
383 if (!OMaybeListSelectionPage::commitPage(_eReason))
384 return sal_False;
386 OOptionGroupSettings& rSettings = getSettings();
387 implCommit(rSettings.sDefaultField);
389 return sal_True;
392 //=====================================================================
393 //= OOptionValuesPage
394 //=====================================================================
395 //---------------------------------------------------------------------
396 OOptionValuesPage::OOptionValuesPage( OControlWizard* _pParent )
397 :OGBWPage(_pParent, ModuleRes(RID_PAGE_OPTIONVALUES))
398 ,m_aFrame (this, ModuleRes(FL_OPTIONVALUES))
399 ,m_aDescription (this, ModuleRes(FT_OPTIONVALUES_EXPL))
400 ,m_aValueLabel (this, ModuleRes(FT_OPTIONVALUES))
401 ,m_aValue (this, ModuleRes(ET_OPTIONVALUE))
402 ,m_aOptionsLabel (this, ModuleRes(FT_RADIOBUTTONS))
403 ,m_aOptions (this, ModuleRes(LB_RADIOBUTTONS))
404 ,m_nLastSelection((::svt::WizardTypes::WizardState)-1)
406 FreeResource();
408 m_aOptions.SetSelectHdl(LINK(this, OOptionValuesPage, OnOptionSelected));
410 m_aOptions.SetAccessibleRelationMemberOf(&m_aOptions);
411 m_aOptions.SetAccessibleRelationLabeledBy(&m_aOptionsLabel);
414 //---------------------------------------------------------------------
415 IMPL_LINK( OOptionValuesPage, OnOptionSelected, ListBox*, /*NOTINTERESTEDIN*/ )
417 implTraveledOptions();
418 return 0L;
421 //---------------------------------------------------------------------
422 void OOptionValuesPage::ActivatePage()
424 OGBWPage::ActivatePage();
425 m_aValue.GrabFocus();
428 //---------------------------------------------------------------------
429 void OOptionValuesPage::implTraveledOptions()
431 if ((::svt::WizardTypes::WizardState)-1 != m_nLastSelection)
433 // save the value for the last option
434 DBG_ASSERT((size_t)m_nLastSelection < m_aUncommittedValues.size(), "OOptionValuesPage::implTraveledOptions: invalid previous selection index!");
435 m_aUncommittedValues[m_nLastSelection] = m_aValue.GetText();
438 m_nLastSelection = m_aOptions.GetSelectEntryPos();
439 DBG_ASSERT((size_t)m_nLastSelection < m_aUncommittedValues.size(), "OOptionValuesPage::implTraveledOptions: invalid new selection index!");
440 m_aValue.SetText(m_aUncommittedValues[m_nLastSelection]);
443 //---------------------------------------------------------------------
444 void OOptionValuesPage::initializePage()
446 OGBWPage::initializePage();
448 const OOptionGroupSettings& rSettings = getSettings();
449 DBG_ASSERT(rSettings.aLabels.size(), "OOptionValuesPage::initializePage: no options!!");
450 DBG_ASSERT(rSettings.aLabels.size() == rSettings.aValues.size(), "OOptionValuesPage::initializePage: inconsistent data!");
452 // fill the list with all available options
453 m_aOptions.Clear();
454 m_nLastSelection = -1;
455 for ( ConstStringArrayIterator aLoop = rSettings.aLabels.begin();
456 aLoop != rSettings.aLabels.end();
457 ++aLoop
459 m_aOptions.InsertEntry(*aLoop);
461 // remember the values ... can't set them directly in the settings without the explicit commit call
462 // so we need have a copy of the values
463 m_aUncommittedValues = rSettings.aValues;
465 // select the first entry
466 m_aOptions.SelectEntryPos(0);
467 implTraveledOptions();
470 //---------------------------------------------------------------------
471 sal_Bool OOptionValuesPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
473 if (!OGBWPage::commitPage(_eReason))
474 return sal_False;
476 OOptionGroupSettings& rSettings = getSettings();
478 // commit the current value
479 implTraveledOptions();
480 // copy the uncommitted values
481 rSettings.aValues = m_aUncommittedValues;
483 return sal_True;
486 //=====================================================================
487 //= OOptionDBFieldPage
488 //=====================================================================
489 //---------------------------------------------------------------------
490 OOptionDBFieldPage::OOptionDBFieldPage( OControlWizard* _pParent )
491 :ODBFieldPage(_pParent)
493 setDescriptionText(String(ModuleRes(RID_STR_GROUPWIZ_DBFIELD)));
496 //---------------------------------------------------------------------
497 String& OOptionDBFieldPage::getDBFieldSetting()
499 return getSettings().sDBField;
502 //=====================================================================
503 //= OFinalizeGBWPage
504 //=====================================================================
505 //---------------------------------------------------------------------
506 OFinalizeGBWPage::OFinalizeGBWPage( OControlWizard* _pParent )
507 :OGBWPage(_pParent, ModuleRes(RID_PAGE_OPTIONS_FINAL))
508 ,m_aFrame (this, ModuleRes(FL_NAMEIT))
509 ,m_aNameLabel (this, ModuleRes(FT_NAMEIT))
510 ,m_aName (this, ModuleRes(ET_NAMEIT))
511 ,m_aThatsAll (this, ModuleRes(FT_THATSALL))
513 FreeResource();
516 //---------------------------------------------------------------------
517 void OFinalizeGBWPage::ActivatePage()
519 OGBWPage::ActivatePage();
520 m_aName.GrabFocus();
523 //---------------------------------------------------------------------
524 bool OFinalizeGBWPage::canAdvance() const
526 return false;
529 //---------------------------------------------------------------------
530 void OFinalizeGBWPage::initializePage()
532 OGBWPage::initializePage();
534 const OOptionGroupSettings& rSettings = getSettings();
535 m_aName.SetText(rSettings.sControlLabel);
538 //---------------------------------------------------------------------
539 sal_Bool OFinalizeGBWPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
541 if (!OGBWPage::commitPage(_eReason))
542 return sal_False;
544 getSettings().sControlLabel = m_aName.GetText();
546 return sal_True;
549 //.........................................................................
550 } // namespace dbp
551 //.........................................................................
553 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */