update dev300-m58
[ooovba.git] / extensions / source / dbpilots / groupboxwiz.cxx
blob1e9968a83a624fd01b8285e58dc22e0618f20e26
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: groupboxwiz.cxx,v $
10 * $Revision: 1.20 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "groupboxwiz.hxx"
34 #include "commonpagesdbp.hxx"
35 #include <tools/debug.hxx>
36 #include <vcl/svapp.hxx>
37 #include <vcl/msgbox.hxx>
38 #include "optiongrouplayouter.hxx"
39 #ifndef EXTENSIONS_INC_EXTENSIO_HRC
40 #include "extensio.hrc"
41 #endif
44 //#define GBW_STATE_DATASELECTION 0
45 #define GBW_STATE_OPTIONLIST 0
46 #define GBW_STATE_DEFAULTOPTION 1
47 #define GBW_STATE_OPTIONVALUES 2
48 #define GBW_STATE_DBFIELD 3
49 #define GBW_STATE_FINALIZE 4
51 //.........................................................................
52 namespace dbp
54 //.........................................................................
56 using namespace ::com::sun::star::uno;
57 using namespace ::com::sun::star::lang;
58 using namespace ::com::sun::star::beans;
59 using namespace ::com::sun::star::form;
60 using namespace ::svt;
62 //=====================================================================
63 //= OGroupBoxWizard
64 //=====================================================================
65 //---------------------------------------------------------------------
66 OGroupBoxWizard::OGroupBoxWizard( Window* _pParent,
67 const Reference< XPropertySet >& _rxObjectModel, const Reference< XMultiServiceFactory >& _rxORB )
68 :OControlWizard(_pParent, ModuleRes(RID_DLG_GROUPBOXWIZARD), _rxObjectModel, _rxORB)
69 ,m_bVisitedDefault(sal_False)
70 ,m_bVisitedDB(sal_False)
72 initControlSettings(&m_aSettings);
74 m_pPrevPage->SetHelpId(HID_GROUPWIZARD_PREVIOUS);
75 m_pNextPage->SetHelpId(HID_GROUPWIZARD_NEXT);
76 m_pCancel->SetHelpId(HID_GROUPWIZARD_CANCEL);
77 m_pFinish->SetHelpId(HID_GROUPWIZARD_FINISH);
80 //---------------------------------------------------------------------
81 sal_Bool OGroupBoxWizard::approveControl(sal_Int16 _nClassId)
83 return FormComponentType::GROUPBOX == _nClassId;
86 //---------------------------------------------------------------------
87 OWizardPage* OGroupBoxWizard::createPage(WizardState _nState)
89 switch (_nState)
91 // case GBW_STATE_DATASELECTION:
92 // return new OTableSelectionPage(this);
94 case GBW_STATE_OPTIONLIST:
95 return new ORadioSelectionPage(this);
97 case GBW_STATE_DEFAULTOPTION:
98 return new ODefaultFieldSelectionPage(this);
100 case GBW_STATE_OPTIONVALUES:
101 return new OOptionValuesPage(this);
103 case GBW_STATE_DBFIELD:
104 return new OOptionDBFieldPage(this);
106 case GBW_STATE_FINALIZE:
107 return new OFinalizeGBWPage(this);
110 return NULL;
113 //---------------------------------------------------------------------
114 WizardTypes::WizardState OGroupBoxWizard::determineNextState( WizardState _nCurrentState ) const
116 switch (_nCurrentState)
118 // case GBW_STATE_DATASELECTION:
119 // return GBW_STATE_OPTIONLIST;
121 case GBW_STATE_OPTIONLIST:
122 return GBW_STATE_DEFAULTOPTION;
124 case GBW_STATE_DEFAULTOPTION:
125 return GBW_STATE_OPTIONVALUES;
127 case GBW_STATE_OPTIONVALUES:
128 if (getContext().aFieldNames.getLength())
129 return GBW_STATE_DBFIELD;
130 else
131 return GBW_STATE_FINALIZE;
133 case GBW_STATE_DBFIELD:
134 return GBW_STATE_FINALIZE;
137 return WZS_INVALID_STATE;
140 //---------------------------------------------------------------------
141 void OGroupBoxWizard::enterState(WizardState _nState)
143 // some stuff to do before calling the base class (modifying our settings)
144 switch (_nState)
146 case GBW_STATE_DEFAULTOPTION:
147 if (!m_bVisitedDefault)
148 { // assume that the first of the radio buttons should be selected
149 DBG_ASSERT(m_aSettings.aLabels.size(), "OGroupBoxWizard::enterState: should never have reached this state!");
150 m_aSettings.sDefaultField = m_aSettings.aLabels[0];
152 m_bVisitedDefault = sal_True;
153 break;
155 case GBW_STATE_DBFIELD:
156 if (!m_bVisitedDB)
157 { // try to generate a default for the DB field
158 // (simply use the first field in the DB names collection)
159 if (getContext().aFieldNames.getLength())
160 m_aSettings.sDBField = getContext().aFieldNames[0];
162 m_bVisitedDB = sal_True;
163 break;
166 // setting the def button .... to be done before the base class is called, too, 'cause the base class
167 // calls the pages, which are allowed to override our def button behaviour
168 defaultButton(GBW_STATE_FINALIZE == _nState ? WZB_FINISH : WZB_NEXT);
170 // allow "finish" on the last page only
171 enableButtons(WZB_FINISH, GBW_STATE_FINALIZE == _nState);
172 // allow previous on all pages but the first one
173 enableButtons(WZB_PREVIOUS, GBW_STATE_OPTIONLIST != _nState);
174 // allow next on all pages but the last one
175 enableButtons(WZB_NEXT, GBW_STATE_FINALIZE != _nState);
177 OControlWizard::enterState(_nState);
180 //---------------------------------------------------------------------
181 void OGroupBoxWizard::createRadios()
185 OOptionGroupLayouter aLayouter(getServiceFactory());
186 aLayouter.doLayout(getContext(), getSettings());
188 catch(Exception&)
190 DBG_ERROR("OGroupBoxWizard::createRadios: caught an exception while creating the radio shapes!");
194 //---------------------------------------------------------------------
195 sal_Bool OGroupBoxWizard::onFinish(sal_Int32 _nResult)
197 if (RET_OK != _nResult)
198 return OControlWizard::onFinish(_nResult);
200 // commit the basic control setttings
201 commitControlSettings(&m_aSettings);
203 // create the radio buttons
204 createRadios();
206 return OControlWizard::onFinish(_nResult);
209 //=====================================================================
210 //= ORadioSelectionPage
211 //=====================================================================
212 //---------------------------------------------------------------------
213 ORadioSelectionPage::ORadioSelectionPage( OControlWizard* _pParent )
214 :OGBWPage(_pParent, ModuleRes(RID_PAGE_GROUPRADIOSELECTION))
215 ,m_aFrame (this, ModuleRes(FL_DATA))
216 ,m_aRadioNameLabel (this, ModuleRes(FT_RADIOLABELS))
217 ,m_aRadioName (this, ModuleRes(ET_RADIOLABELS))
218 ,m_aMoveRight (this, ModuleRes(PB_MOVETORIGHT))
219 ,m_aMoveLeft (this, ModuleRes(PB_MOVETOLEFT))
220 ,m_aExistingRadiosLabel (this, ModuleRes(FT_RADIOBUTTONS))
221 ,m_aExistingRadios (this, ModuleRes(LB_RADIOBUTTONS))
223 FreeResource();
225 if (getContext().aFieldNames.getLength())
227 enableFormDatasourceDisplay();
229 else
231 adjustControlForNoDSDisplay(&m_aFrame);
232 adjustControlForNoDSDisplay(&m_aRadioNameLabel);
233 adjustControlForNoDSDisplay(&m_aRadioName);
234 adjustControlForNoDSDisplay(&m_aMoveRight);
235 adjustControlForNoDSDisplay(&m_aMoveLeft);
236 adjustControlForNoDSDisplay(&m_aExistingRadiosLabel);
237 adjustControlForNoDSDisplay(&m_aExistingRadios, sal_True);
240 m_aMoveLeft.SetClickHdl(LINK(this, ORadioSelectionPage, OnMoveEntry));
241 m_aMoveRight.SetClickHdl(LINK(this, ORadioSelectionPage, OnMoveEntry));
242 m_aRadioName.SetModifyHdl(LINK(this, ORadioSelectionPage, OnNameModified));
243 m_aExistingRadios.SetSelectHdl(LINK(this, ORadioSelectionPage, OnEntrySelected));
245 implCheckMoveButtons();
246 m_aExistingRadios.EnableMultiSelection(sal_True);
248 getDialog()->defaultButton(&m_aMoveRight);
251 //---------------------------------------------------------------------
252 void ORadioSelectionPage::ActivatePage()
254 OGBWPage::ActivatePage();
255 m_aRadioName.GrabFocus();
258 //---------------------------------------------------------------------
259 void ORadioSelectionPage::initializePage()
261 OGBWPage::initializePage();
263 m_aRadioName.SetText(String());
265 // no need to initialize the list of radios here
266 // (we're the only one affecting this special setting, so it will be in the same state as last time this
267 // page was commited)
269 implCheckMoveButtons();
272 //---------------------------------------------------------------------
273 sal_Bool ORadioSelectionPage::commitPage( CommitPageReason _eReason )
275 if (!OGBWPage::commitPage(_eReason))
276 return sal_False;
278 // copy the names of the radio buttons to be inserted
279 // and initialize the values
280 OOptionGroupSettings& rSettings = getSettings();
281 rSettings.aLabels.clear();
282 rSettings.aValues.clear();
283 rSettings.aLabels.reserve(m_aExistingRadios.GetEntryCount());
284 rSettings.aValues.reserve(m_aExistingRadios.GetEntryCount());
285 for (WizardState i=0; i<m_aExistingRadios.GetEntryCount(); ++i)
287 rSettings.aLabels.push_back(m_aExistingRadios.GetEntry(i));
288 rSettings.aValues.push_back(String::CreateFromInt32((sal_Int32)(i + 1)));
291 return sal_True;
294 //---------------------------------------------------------------------
295 IMPL_LINK( ORadioSelectionPage, OnMoveEntry, PushButton*, _pButton )
297 sal_Bool bMoveLeft = (&m_aMoveLeft == _pButton);
298 if (bMoveLeft)
300 while (m_aExistingRadios.GetSelectEntryCount())
301 m_aExistingRadios.RemoveEntry(m_aExistingRadios.GetSelectEntryPos(0));
303 else
305 m_aExistingRadios.InsertEntry(m_aRadioName.GetText());
306 m_aRadioName.SetText(String());
309 implCheckMoveButtons();
311 //adjust the focus
312 if (bMoveLeft)
313 m_aExistingRadios.GrabFocus();
314 else
315 m_aRadioName.GrabFocus();
316 return 0L;
319 //---------------------------------------------------------------------
320 IMPL_LINK( ORadioSelectionPage, OnEntrySelected, ListBox*, /*_pList*/ )
322 implCheckMoveButtons();
323 return 0L;
326 //---------------------------------------------------------------------
327 IMPL_LINK( ORadioSelectionPage, OnNameModified, Edit*, /*_pList*/ )
329 implCheckMoveButtons();
330 return 0L;
333 //---------------------------------------------------------------------
334 bool ORadioSelectionPage::canAdvance() const
336 return 0 != m_aExistingRadios.GetEntryCount();
339 //---------------------------------------------------------------------
340 void ORadioSelectionPage::implCheckMoveButtons()
342 sal_Bool bHaveSome = (0 != m_aExistingRadios.GetEntryCount());
343 sal_Bool bSelectedSome = (0 != m_aExistingRadios.GetSelectEntryCount());
344 sal_Bool bUnfinishedInput = (0 != m_aRadioName.GetText().Len());
346 m_aMoveLeft.Enable(bSelectedSome);
347 m_aMoveRight.Enable(bUnfinishedInput);
349 getDialog()->enableButtons(WZB_NEXT, bHaveSome);
351 if (bUnfinishedInput)
353 if (0 == (m_aMoveRight.GetStyle() & WB_DEFBUTTON))
354 getDialog()->defaultButton(&m_aMoveRight);
356 else
358 if (WB_DEFBUTTON == (m_aMoveRight.GetStyle() & WB_DEFBUTTON))
359 getDialog()->defaultButton(WZB_NEXT);
363 //=====================================================================
364 //= ODefaultFieldSelectionPage
365 //=====================================================================
366 //---------------------------------------------------------------------
367 ODefaultFieldSelectionPage::ODefaultFieldSelectionPage( OControlWizard* _pParent )
368 :OMaybeListSelectionPage(_pParent, ModuleRes(RID_PAGE_DEFAULTFIELDSELECTION))
369 ,m_aFrame (this, ModuleRes(FL_DEFAULTSELECTION))
370 ,m_aDefaultSelectionLabel (this, ModuleRes(FT_DEFAULTSELECTION))
371 ,m_aDefSelYes (this, ModuleRes(RB_DEFSELECTION_YES))
372 ,m_aDefSelNo (this, ModuleRes(RB_DEFSELECTION_NO))
373 ,m_aDefSelection (this, ModuleRes(LB_DEFSELECTIONFIELD))
375 FreeResource();
377 announceControls(m_aDefSelYes, m_aDefSelNo, m_aDefSelection);
378 m_aDefSelection.SetDropDownLineCount(10);
381 //---------------------------------------------------------------------
382 void ODefaultFieldSelectionPage::initializePage()
384 OMaybeListSelectionPage::initializePage();
386 const OOptionGroupSettings& rSettings = getSettings();
388 // fill the listbox
389 m_aDefSelection.Clear();
390 for ( ConstStringArrayIterator aLoop = rSettings.aLabels.begin();
391 aLoop != rSettings.aLabels.end();
392 ++aLoop
394 m_aDefSelection.InsertEntry(*aLoop);
397 implInitialize(rSettings.sDefaultField);
400 //---------------------------------------------------------------------
401 sal_Bool ODefaultFieldSelectionPage::commitPage( CommitPageReason _eReason )
403 if (!OMaybeListSelectionPage::commitPage(_eReason))
404 return sal_False;
406 OOptionGroupSettings& rSettings = getSettings();
407 implCommit(rSettings.sDefaultField);
409 return sal_True;
412 //=====================================================================
413 //= OOptionValuesPage
414 //=====================================================================
415 //---------------------------------------------------------------------
416 OOptionValuesPage::OOptionValuesPage( OControlWizard* _pParent )
417 :OGBWPage(_pParent, ModuleRes(RID_PAGE_OPTIONVALUES))
418 ,m_aFrame (this, ModuleRes(FL_OPTIONVALUES))
419 ,m_aDescription (this, ModuleRes(FT_OPTIONVALUES_EXPL))
420 ,m_aValueLabel (this, ModuleRes(FT_OPTIONVALUES))
421 ,m_aValue (this, ModuleRes(ET_OPTIONVALUE))
422 ,m_aOptionsLabel (this, ModuleRes(FT_RADIOBUTTONS))
423 ,m_aOptions (this, ModuleRes(LB_RADIOBUTTONS))
424 ,m_nLastSelection((WizardState)-1)
426 FreeResource();
428 m_aOptions.SetSelectHdl(LINK(this, OOptionValuesPage, OnOptionSelected));
431 //---------------------------------------------------------------------
432 IMPL_LINK( OOptionValuesPage, OnOptionSelected, ListBox*, /*NOTINTERESTEDIN*/ )
434 implTraveledOptions();
435 return 0L;
438 //---------------------------------------------------------------------
439 void OOptionValuesPage::ActivatePage()
441 OGBWPage::ActivatePage();
442 m_aValue.GrabFocus();
445 //---------------------------------------------------------------------
446 void OOptionValuesPage::implTraveledOptions()
448 if ((WizardState)-1 != m_nLastSelection)
450 // save the value for the last option
451 DBG_ASSERT((size_t)m_nLastSelection < m_aUncommittedValues.size(), "OOptionValuesPage::implTraveledOptions: invalid previous selection index!");
452 m_aUncommittedValues[m_nLastSelection] = m_aValue.GetText();
455 m_nLastSelection = m_aOptions.GetSelectEntryPos();
456 DBG_ASSERT((size_t)m_nLastSelection < m_aUncommittedValues.size(), "OOptionValuesPage::implTraveledOptions: invalid new selection index!");
457 m_aValue.SetText(m_aUncommittedValues[m_nLastSelection]);
460 //---------------------------------------------------------------------
461 void OOptionValuesPage::initializePage()
463 OGBWPage::initializePage();
465 const OOptionGroupSettings& rSettings = getSettings();
466 DBG_ASSERT(rSettings.aLabels.size(), "OOptionValuesPage::initializePage: no options!!");
467 DBG_ASSERT(rSettings.aLabels.size() == rSettings.aValues.size(), "OOptionValuesPage::initializePage: inconsistent data!");
469 // fill the list with all available options
470 m_aOptions.Clear();
471 m_nLastSelection = -1;
472 for ( ConstStringArrayIterator aLoop = rSettings.aLabels.begin();
473 aLoop != rSettings.aLabels.end();
474 ++aLoop
476 m_aOptions.InsertEntry(*aLoop);
478 // remember the values ... can't set them directly in the settings without the explicit commit call
479 // so we need have a copy of the values
480 m_aUncommittedValues = rSettings.aValues;
482 // select the first entry
483 m_aOptions.SelectEntryPos(0);
484 implTraveledOptions();
487 //---------------------------------------------------------------------
488 sal_Bool OOptionValuesPage::commitPage( CommitPageReason _eReason )
490 if (!OGBWPage::commitPage(_eReason))
491 return sal_False;
493 OOptionGroupSettings& rSettings = getSettings();
495 // commit the current value
496 implTraveledOptions();
497 // copy the uncommitted values
498 rSettings.aValues = m_aUncommittedValues;
500 return sal_True;
503 //=====================================================================
504 //= OOptionDBFieldPage
505 //=====================================================================
506 //---------------------------------------------------------------------
507 OOptionDBFieldPage::OOptionDBFieldPage( OControlWizard* _pParent )
508 :ODBFieldPage(_pParent)
510 setDescriptionText(String(ModuleRes(RID_STR_GROUPWIZ_DBFIELD)));
513 //---------------------------------------------------------------------
514 String& OOptionDBFieldPage::getDBFieldSetting()
516 return getSettings().sDBField;
519 //=====================================================================
520 //= OFinalizeGBWPage
521 //=====================================================================
522 //---------------------------------------------------------------------
523 OFinalizeGBWPage::OFinalizeGBWPage( OControlWizard* _pParent )
524 :OGBWPage(_pParent, ModuleRes(RID_PAGE_OPTIONS_FINAL))
525 ,m_aFrame (this, ModuleRes(FL_NAMEIT))
526 ,m_aNameLabel (this, ModuleRes(FT_NAMEIT))
527 ,m_aName (this, ModuleRes(ET_NAMEIT))
528 ,m_aThatsAll (this, ModuleRes(FT_THATSALL))
530 FreeResource();
533 //---------------------------------------------------------------------
534 void OFinalizeGBWPage::ActivatePage()
536 OGBWPage::ActivatePage();
537 m_aName.GrabFocus();
540 //---------------------------------------------------------------------
541 bool OFinalizeGBWPage::canAdvance() const
543 return false;
546 //---------------------------------------------------------------------
547 void OFinalizeGBWPage::initializePage()
549 OGBWPage::initializePage();
551 const OOptionGroupSettings& rSettings = getSettings();
552 m_aName.SetText(rSettings.sControlLabel);
555 //---------------------------------------------------------------------
556 sal_Bool OFinalizeGBWPage::commitPage( CommitPageReason _eReason )
558 if (!OGBWPage::commitPage(_eReason))
559 return sal_False;
561 getSettings().sControlLabel = m_aName.GetText();
563 return sal_True;
566 //.........................................................................
567 } // namespace dbp
568 //.........................................................................