1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "groupboxwiz.hxx"
31 #include "commonpagesdbp.hxx"
32 #include <tools/debug.hxx>
33 #include <vcl/svapp.hxx>
34 #include <vcl/msgbox.hxx>
35 #include "optiongrouplayouter.hxx"
36 #include "dbpilots.hrc"
39 //#define GBW_STATE_DATASELECTION 0
40 #define GBW_STATE_OPTIONLIST 0
41 #define GBW_STATE_DEFAULTOPTION 1
42 #define GBW_STATE_OPTIONVALUES 2
43 #define GBW_STATE_DBFIELD 3
44 #define GBW_STATE_FINALIZE 4
46 //.........................................................................
49 //.........................................................................
51 using namespace ::com::sun::star::uno
;
52 using namespace ::com::sun::star::lang
;
53 using namespace ::com::sun::star::beans
;
54 using namespace ::com::sun::star::form
;
55 using namespace ::svt
;
57 //=====================================================================
59 //=====================================================================
60 //---------------------------------------------------------------------
61 OGroupBoxWizard::OGroupBoxWizard( Window
* _pParent
,
62 const Reference
< XPropertySet
>& _rxObjectModel
, const Reference
< XMultiServiceFactory
>& _rxORB
)
63 :OControlWizard(_pParent
, ModuleRes(RID_DLG_GROUPBOXWIZARD
), _rxObjectModel
, _rxORB
)
64 ,m_bVisitedDefault(sal_False
)
65 ,m_bVisitedDB(sal_False
)
67 initControlSettings(&m_aSettings
);
69 m_pPrevPage
->SetHelpId(HID_GROUPWIZARD_PREVIOUS
);
70 m_pNextPage
->SetHelpId(HID_GROUPWIZARD_NEXT
);
71 m_pCancel
->SetHelpId(HID_GROUPWIZARD_CANCEL
);
72 m_pFinish
->SetHelpId(HID_GROUPWIZARD_FINISH
);
75 //---------------------------------------------------------------------
76 sal_Bool
OGroupBoxWizard::approveControl(sal_Int16 _nClassId
)
78 return FormComponentType::GROUPBOX
== _nClassId
;
81 //---------------------------------------------------------------------
82 OWizardPage
* OGroupBoxWizard::createPage(::svt::WizardTypes::WizardState _nState
)
86 // case GBW_STATE_DATASELECTION:
87 // return new OTableSelectionPage(this);
89 case GBW_STATE_OPTIONLIST
:
90 return new ORadioSelectionPage(this);
92 case GBW_STATE_DEFAULTOPTION
:
93 return new ODefaultFieldSelectionPage(this);
95 case GBW_STATE_OPTIONVALUES
:
96 return new OOptionValuesPage(this);
98 case GBW_STATE_DBFIELD
:
99 return new OOptionDBFieldPage(this);
101 case GBW_STATE_FINALIZE
:
102 return new OFinalizeGBWPage(this);
108 //---------------------------------------------------------------------
109 WizardTypes::WizardState
OGroupBoxWizard::determineNextState( ::svt::WizardTypes::WizardState _nCurrentState
) const
111 switch (_nCurrentState
)
113 // case GBW_STATE_DATASELECTION:
114 // return GBW_STATE_OPTIONLIST;
116 case GBW_STATE_OPTIONLIST
:
117 return GBW_STATE_DEFAULTOPTION
;
119 case GBW_STATE_DEFAULTOPTION
:
120 return GBW_STATE_OPTIONVALUES
;
122 case GBW_STATE_OPTIONVALUES
:
123 if (getContext().aFieldNames
.getLength())
124 return GBW_STATE_DBFIELD
;
126 return GBW_STATE_FINALIZE
;
128 case GBW_STATE_DBFIELD
:
129 return GBW_STATE_FINALIZE
;
132 return WZS_INVALID_STATE
;
135 //---------------------------------------------------------------------
136 void OGroupBoxWizard::enterState(::svt::WizardTypes::WizardState _nState
)
138 // some stuff to do before calling the base class (modifying our settings)
141 case GBW_STATE_DEFAULTOPTION
:
142 if (!m_bVisitedDefault
)
143 { // assume that the first of the radio buttons should be selected
144 DBG_ASSERT(m_aSettings
.aLabels
.size(), "OGroupBoxWizard::enterState: should never have reached this state!");
145 m_aSettings
.sDefaultField
= m_aSettings
.aLabels
[0];
147 m_bVisitedDefault
= sal_True
;
150 case GBW_STATE_DBFIELD
:
152 { // try to generate a default for the DB field
153 // (simply use the first field in the DB names collection)
154 if (getContext().aFieldNames
.getLength())
155 m_aSettings
.sDBField
= getContext().aFieldNames
[0];
157 m_bVisitedDB
= sal_True
;
161 // setting the def button .... to be done before the base class is called, too, 'cause the base class
162 // calls the pages, which are allowed to override our def button behaviour
163 defaultButton(GBW_STATE_FINALIZE
== _nState
? WZB_FINISH
: WZB_NEXT
);
165 // allow "finish" on the last page only
166 enableButtons(WZB_FINISH
, GBW_STATE_FINALIZE
== _nState
);
167 // allow previous on all pages but the first one
168 enableButtons(WZB_PREVIOUS
, GBW_STATE_OPTIONLIST
!= _nState
);
169 // allow next on all pages but the last one
170 enableButtons(WZB_NEXT
, GBW_STATE_FINALIZE
!= _nState
);
172 OControlWizard::enterState(_nState
);
175 //---------------------------------------------------------------------
176 void OGroupBoxWizard::createRadios()
180 OOptionGroupLayouter
aLayouter(getServiceFactory());
181 aLayouter
.doLayout(getContext(), getSettings());
185 DBG_ERROR("OGroupBoxWizard::createRadios: caught an exception while creating the radio shapes!");
189 //---------------------------------------------------------------------
190 sal_Bool
OGroupBoxWizard::onFinish()
192 // commit the basic control setttings
193 commitControlSettings(&m_aSettings
);
195 // create the radio buttons
198 return OControlWizard::onFinish();
201 //=====================================================================
202 //= ORadioSelectionPage
203 //=====================================================================
204 //---------------------------------------------------------------------
205 ORadioSelectionPage::ORadioSelectionPage( OControlWizard
* _pParent
)
206 :OGBWPage(_pParent
, ModuleRes(RID_PAGE_GROUPRADIOSELECTION
))
207 ,m_aFrame (this, ModuleRes(FL_DATA
))
208 ,m_aRadioNameLabel (this, ModuleRes(FT_RADIOLABELS
))
209 ,m_aRadioName (this, ModuleRes(ET_RADIOLABELS
))
210 ,m_aMoveRight (this, ModuleRes(PB_MOVETORIGHT
))
211 ,m_aMoveLeft (this, ModuleRes(PB_MOVETOLEFT
))
212 ,m_aExistingRadiosLabel (this, ModuleRes(FT_RADIOBUTTONS
))
213 ,m_aExistingRadios (this, ModuleRes(LB_RADIOBUTTONS
))
217 if (getContext().aFieldNames
.getLength())
219 enableFormDatasourceDisplay();
223 adjustControlForNoDSDisplay(&m_aFrame
);
224 adjustControlForNoDSDisplay(&m_aRadioNameLabel
);
225 adjustControlForNoDSDisplay(&m_aRadioName
);
226 adjustControlForNoDSDisplay(&m_aMoveRight
);
227 adjustControlForNoDSDisplay(&m_aMoveLeft
);
228 adjustControlForNoDSDisplay(&m_aExistingRadiosLabel
);
229 adjustControlForNoDSDisplay(&m_aExistingRadios
, sal_True
);
232 m_aMoveLeft
.SetClickHdl(LINK(this, ORadioSelectionPage
, OnMoveEntry
));
233 m_aMoveRight
.SetClickHdl(LINK(this, ORadioSelectionPage
, OnMoveEntry
));
234 m_aRadioName
.SetModifyHdl(LINK(this, ORadioSelectionPage
, OnNameModified
));
235 m_aExistingRadios
.SetSelectHdl(LINK(this, ORadioSelectionPage
, OnEntrySelected
));
237 implCheckMoveButtons();
238 m_aExistingRadios
.EnableMultiSelection(sal_True
);
240 getDialog()->defaultButton(&m_aMoveRight
);
243 //---------------------------------------------------------------------
244 void ORadioSelectionPage::ActivatePage()
246 OGBWPage::ActivatePage();
247 m_aRadioName
.GrabFocus();
250 //---------------------------------------------------------------------
251 void ORadioSelectionPage::initializePage()
253 OGBWPage::initializePage();
255 m_aRadioName
.SetText(String());
257 // no need to initialize the list of radios here
258 // (we're the only one affecting this special setting, so it will be in the same state as last time this
259 // page was commited)
261 implCheckMoveButtons();
264 //---------------------------------------------------------------------
265 sal_Bool
ORadioSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason
)
267 if (!OGBWPage::commitPage(_eReason
))
270 // copy the names of the radio buttons to be inserted
271 // and initialize the values
272 OOptionGroupSettings
& rSettings
= getSettings();
273 rSettings
.aLabels
.clear();
274 rSettings
.aValues
.clear();
275 rSettings
.aLabels
.reserve(m_aExistingRadios
.GetEntryCount());
276 rSettings
.aValues
.reserve(m_aExistingRadios
.GetEntryCount());
277 for (::svt::WizardTypes::WizardState i
=0; i
<m_aExistingRadios
.GetEntryCount(); ++i
)
279 rSettings
.aLabels
.push_back(m_aExistingRadios
.GetEntry(i
));
280 rSettings
.aValues
.push_back(String::CreateFromInt32((sal_Int32
)(i
+ 1)));
286 //---------------------------------------------------------------------
287 IMPL_LINK( ORadioSelectionPage
, OnMoveEntry
, PushButton
*, _pButton
)
289 sal_Bool bMoveLeft
= (&m_aMoveLeft
== _pButton
);
292 while (m_aExistingRadios
.GetSelectEntryCount())
293 m_aExistingRadios
.RemoveEntry(m_aExistingRadios
.GetSelectEntryPos(0));
297 m_aExistingRadios
.InsertEntry(m_aRadioName
.GetText());
298 m_aRadioName
.SetText(String());
301 implCheckMoveButtons();
305 m_aExistingRadios
.GrabFocus();
307 m_aRadioName
.GrabFocus();
311 //---------------------------------------------------------------------
312 IMPL_LINK( ORadioSelectionPage
, OnEntrySelected
, ListBox
*, /*_pList*/ )
314 implCheckMoveButtons();
318 //---------------------------------------------------------------------
319 IMPL_LINK( ORadioSelectionPage
, OnNameModified
, Edit
*, /*_pList*/ )
321 implCheckMoveButtons();
325 //---------------------------------------------------------------------
326 bool ORadioSelectionPage::canAdvance() const
328 return 0 != m_aExistingRadios
.GetEntryCount();
331 //---------------------------------------------------------------------
332 void ORadioSelectionPage::implCheckMoveButtons()
334 sal_Bool bHaveSome
= (0 != m_aExistingRadios
.GetEntryCount());
335 sal_Bool bSelectedSome
= (0 != m_aExistingRadios
.GetSelectEntryCount());
336 sal_Bool bUnfinishedInput
= (0 != m_aRadioName
.GetText().Len());
338 m_aMoveLeft
.Enable(bSelectedSome
);
339 m_aMoveRight
.Enable(bUnfinishedInput
);
341 getDialog()->enableButtons(WZB_NEXT
, bHaveSome
);
343 if (bUnfinishedInput
)
345 if (0 == (m_aMoveRight
.GetStyle() & WB_DEFBUTTON
))
346 getDialog()->defaultButton(&m_aMoveRight
);
350 if (WB_DEFBUTTON
== (m_aMoveRight
.GetStyle() & WB_DEFBUTTON
))
351 getDialog()->defaultButton(WZB_NEXT
);
355 //=====================================================================
356 //= ODefaultFieldSelectionPage
357 //=====================================================================
358 //---------------------------------------------------------------------
359 ODefaultFieldSelectionPage::ODefaultFieldSelectionPage( OControlWizard
* _pParent
)
360 :OMaybeListSelectionPage(_pParent
, ModuleRes(RID_PAGE_DEFAULTFIELDSELECTION
))
361 ,m_aFrame (this, ModuleRes(FL_DEFAULTSELECTION
))
362 ,m_aDefaultSelectionLabel (this, ModuleRes(FT_DEFAULTSELECTION
))
363 ,m_aDefSelYes (this, ModuleRes(RB_DEFSELECTION_YES
))
364 ,m_aDefSelNo (this, ModuleRes(RB_DEFSELECTION_NO
))
365 ,m_aDefSelection (this, ModuleRes(LB_DEFSELECTIONFIELD
))
369 announceControls(m_aDefSelYes
, m_aDefSelNo
, m_aDefSelection
);
370 m_aDefSelection
.SetDropDownLineCount(10);
373 //---------------------------------------------------------------------
374 void ODefaultFieldSelectionPage::initializePage()
376 OMaybeListSelectionPage::initializePage();
378 const OOptionGroupSettings
& rSettings
= getSettings();
381 m_aDefSelection
.Clear();
382 for ( ConstStringArrayIterator aLoop
= rSettings
.aLabels
.begin();
383 aLoop
!= rSettings
.aLabels
.end();
386 m_aDefSelection
.InsertEntry(*aLoop
);
389 implInitialize(rSettings
.sDefaultField
);
392 //---------------------------------------------------------------------
393 sal_Bool
ODefaultFieldSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason
)
395 if (!OMaybeListSelectionPage::commitPage(_eReason
))
398 OOptionGroupSettings
& rSettings
= getSettings();
399 implCommit(rSettings
.sDefaultField
);
404 //=====================================================================
405 //= OOptionValuesPage
406 //=====================================================================
407 //---------------------------------------------------------------------
408 OOptionValuesPage::OOptionValuesPage( OControlWizard
* _pParent
)
409 :OGBWPage(_pParent
, ModuleRes(RID_PAGE_OPTIONVALUES
))
410 ,m_aFrame (this, ModuleRes(FL_OPTIONVALUES
))
411 ,m_aDescription (this, ModuleRes(FT_OPTIONVALUES_EXPL
))
412 ,m_aValueLabel (this, ModuleRes(FT_OPTIONVALUES
))
413 ,m_aValue (this, ModuleRes(ET_OPTIONVALUE
))
414 ,m_aOptionsLabel (this, ModuleRes(FT_RADIOBUTTONS
))
415 ,m_aOptions (this, ModuleRes(LB_RADIOBUTTONS
))
416 ,m_nLastSelection((::svt::WizardTypes::WizardState
)-1)
420 m_aOptions
.SetSelectHdl(LINK(this, OOptionValuesPage
, OnOptionSelected
));
423 //---------------------------------------------------------------------
424 IMPL_LINK( OOptionValuesPage
, OnOptionSelected
, ListBox
*, /*NOTINTERESTEDIN*/ )
426 implTraveledOptions();
430 //---------------------------------------------------------------------
431 void OOptionValuesPage::ActivatePage()
433 OGBWPage::ActivatePage();
434 m_aValue
.GrabFocus();
437 //---------------------------------------------------------------------
438 void OOptionValuesPage::implTraveledOptions()
440 if ((::svt::WizardTypes::WizardState
)-1 != m_nLastSelection
)
442 // save the value for the last option
443 DBG_ASSERT((size_t)m_nLastSelection
< m_aUncommittedValues
.size(), "OOptionValuesPage::implTraveledOptions: invalid previous selection index!");
444 m_aUncommittedValues
[m_nLastSelection
] = m_aValue
.GetText();
447 m_nLastSelection
= m_aOptions
.GetSelectEntryPos();
448 DBG_ASSERT((size_t)m_nLastSelection
< m_aUncommittedValues
.size(), "OOptionValuesPage::implTraveledOptions: invalid new selection index!");
449 m_aValue
.SetText(m_aUncommittedValues
[m_nLastSelection
]);
452 //---------------------------------------------------------------------
453 void OOptionValuesPage::initializePage()
455 OGBWPage::initializePage();
457 const OOptionGroupSettings
& rSettings
= getSettings();
458 DBG_ASSERT(rSettings
.aLabels
.size(), "OOptionValuesPage::initializePage: no options!!");
459 DBG_ASSERT(rSettings
.aLabels
.size() == rSettings
.aValues
.size(), "OOptionValuesPage::initializePage: inconsistent data!");
461 // fill the list with all available options
463 m_nLastSelection
= -1;
464 for ( ConstStringArrayIterator aLoop
= rSettings
.aLabels
.begin();
465 aLoop
!= rSettings
.aLabels
.end();
468 m_aOptions
.InsertEntry(*aLoop
);
470 // remember the values ... can't set them directly in the settings without the explicit commit call
471 // so we need have a copy of the values
472 m_aUncommittedValues
= rSettings
.aValues
;
474 // select the first entry
475 m_aOptions
.SelectEntryPos(0);
476 implTraveledOptions();
479 //---------------------------------------------------------------------
480 sal_Bool
OOptionValuesPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason
)
482 if (!OGBWPage::commitPage(_eReason
))
485 OOptionGroupSettings
& rSettings
= getSettings();
487 // commit the current value
488 implTraveledOptions();
489 // copy the uncommitted values
490 rSettings
.aValues
= m_aUncommittedValues
;
495 //=====================================================================
496 //= OOptionDBFieldPage
497 //=====================================================================
498 //---------------------------------------------------------------------
499 OOptionDBFieldPage::OOptionDBFieldPage( OControlWizard
* _pParent
)
500 :ODBFieldPage(_pParent
)
502 setDescriptionText(String(ModuleRes(RID_STR_GROUPWIZ_DBFIELD
)));
505 //---------------------------------------------------------------------
506 String
& OOptionDBFieldPage::getDBFieldSetting()
508 return getSettings().sDBField
;
511 //=====================================================================
513 //=====================================================================
514 //---------------------------------------------------------------------
515 OFinalizeGBWPage::OFinalizeGBWPage( OControlWizard
* _pParent
)
516 :OGBWPage(_pParent
, ModuleRes(RID_PAGE_OPTIONS_FINAL
))
517 ,m_aFrame (this, ModuleRes(FL_NAMEIT
))
518 ,m_aNameLabel (this, ModuleRes(FT_NAMEIT
))
519 ,m_aName (this, ModuleRes(ET_NAMEIT
))
520 ,m_aThatsAll (this, ModuleRes(FT_THATSALL
))
525 //---------------------------------------------------------------------
526 void OFinalizeGBWPage::ActivatePage()
528 OGBWPage::ActivatePage();
532 //---------------------------------------------------------------------
533 bool OFinalizeGBWPage::canAdvance() const
538 //---------------------------------------------------------------------
539 void OFinalizeGBWPage::initializePage()
541 OGBWPage::initializePage();
543 const OOptionGroupSettings
& rSettings
= getSettings();
544 m_aName
.SetText(rSettings
.sControlLabel
);
547 //---------------------------------------------------------------------
548 sal_Bool
OFinalizeGBWPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason
)
550 if (!OGBWPage::commitPage(_eReason
))
553 getSettings().sControlLabel
= m_aName
.GetText();
558 //.........................................................................
560 //.........................................................................