1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_extensions.hxx" 26 #include "groupboxwiz.hxx" 27 #include "commonpagesdbp.hxx" 28 #include <tools/debug.hxx> 29 #include <vcl/svapp.hxx> 30 #include <vcl/msgbox.hxx> 31 #include "optiongrouplayouter.hxx" 32 #include "dbpilots.hrc" 33 34 35 //#define GBW_STATE_DATASELECTION 0 36 #define GBW_STATE_OPTIONLIST 0 37 #define GBW_STATE_DEFAULTOPTION 1 38 #define GBW_STATE_OPTIONVALUES 2 39 #define GBW_STATE_DBFIELD 3 40 #define GBW_STATE_FINALIZE 4 41 42 //......................................................................... 43 namespace dbp 44 { 45 //......................................................................... 46 47 using namespace ::com::sun::star::uno; 48 using namespace ::com::sun::star::lang; 49 using namespace ::com::sun::star::beans; 50 using namespace ::com::sun::star::form; 51 using namespace ::svt; 52 53 //===================================================================== 54 //= OGroupBoxWizard 55 //===================================================================== 56 //--------------------------------------------------------------------- OGroupBoxWizard(Window * _pParent,const Reference<XPropertySet> & _rxObjectModel,const Reference<XMultiServiceFactory> & _rxORB)57 OGroupBoxWizard::OGroupBoxWizard( Window* _pParent, 58 const Reference< XPropertySet >& _rxObjectModel, const Reference< XMultiServiceFactory >& _rxORB ) 59 :OControlWizard(_pParent, ModuleRes(RID_DLG_GROUPBOXWIZARD), _rxObjectModel, _rxORB) 60 ,m_bVisitedDefault(sal_False) 61 ,m_bVisitedDB(sal_False) 62 { 63 initControlSettings(&m_aSettings); 64 65 m_pPrevPage->SetHelpId(HID_GROUPWIZARD_PREVIOUS); 66 m_pNextPage->SetHelpId(HID_GROUPWIZARD_NEXT); 67 m_pCancel->SetHelpId(HID_GROUPWIZARD_CANCEL); 68 m_pFinish->SetHelpId(HID_GROUPWIZARD_FINISH); 69 } 70 71 //--------------------------------------------------------------------- approveControl(sal_Int16 _nClassId)72 sal_Bool OGroupBoxWizard::approveControl(sal_Int16 _nClassId) 73 { 74 return FormComponentType::GROUPBOX == _nClassId; 75 } 76 77 //--------------------------------------------------------------------- createPage(::svt::WizardTypes::WizardState _nState)78 OWizardPage* OGroupBoxWizard::createPage(::svt::WizardTypes::WizardState _nState) 79 { 80 switch (_nState) 81 { 82 // case GBW_STATE_DATASELECTION: 83 // return new OTableSelectionPage(this); 84 // 85 case GBW_STATE_OPTIONLIST: 86 return new ORadioSelectionPage(this); 87 88 case GBW_STATE_DEFAULTOPTION: 89 return new ODefaultFieldSelectionPage(this); 90 91 case GBW_STATE_OPTIONVALUES: 92 return new OOptionValuesPage(this); 93 94 case GBW_STATE_DBFIELD: 95 return new OOptionDBFieldPage(this); 96 97 case GBW_STATE_FINALIZE: 98 return new OFinalizeGBWPage(this); 99 } 100 101 return NULL; 102 } 103 104 //--------------------------------------------------------------------- determineNextState(::svt::WizardTypes::WizardState _nCurrentState) const105 WizardTypes::WizardState OGroupBoxWizard::determineNextState( ::svt::WizardTypes::WizardState _nCurrentState ) const 106 { 107 switch (_nCurrentState) 108 { 109 // case GBW_STATE_DATASELECTION: 110 // return GBW_STATE_OPTIONLIST; 111 // 112 case GBW_STATE_OPTIONLIST: 113 return GBW_STATE_DEFAULTOPTION; 114 115 case GBW_STATE_DEFAULTOPTION: 116 return GBW_STATE_OPTIONVALUES; 117 118 case GBW_STATE_OPTIONVALUES: 119 if (getContext().aFieldNames.getLength()) 120 return GBW_STATE_DBFIELD; 121 else 122 return GBW_STATE_FINALIZE; 123 124 case GBW_STATE_DBFIELD: 125 return GBW_STATE_FINALIZE; 126 } 127 128 return WZS_INVALID_STATE; 129 } 130 131 //--------------------------------------------------------------------- enterState(::svt::WizardTypes::WizardState _nState)132 void OGroupBoxWizard::enterState(::svt::WizardTypes::WizardState _nState) 133 { 134 // some stuff to do before calling the base class (modifying our settings) 135 switch (_nState) 136 { 137 case GBW_STATE_DEFAULTOPTION: 138 if (!m_bVisitedDefault) 139 { // assume that the first of the radio buttons should be selected 140 DBG_ASSERT(m_aSettings.aLabels.size(), "OGroupBoxWizard::enterState: should never have reached this state!"); 141 m_aSettings.sDefaultField = m_aSettings.aLabels[0]; 142 } 143 m_bVisitedDefault = sal_True; 144 break; 145 146 case GBW_STATE_DBFIELD: 147 if (!m_bVisitedDB) 148 { // try to generate a default for the DB field 149 // (simply use the first field in the DB names collection) 150 if (getContext().aFieldNames.getLength()) 151 m_aSettings.sDBField = getContext().aFieldNames[0]; 152 } 153 m_bVisitedDB = sal_True; 154 break; 155 } 156 157 // setting the def button .... to be done before the base class is called, too, 'cause the base class 158 // calls the pages, which are allowed to override our def button behaviour 159 defaultButton(GBW_STATE_FINALIZE == _nState ? WZB_FINISH : WZB_NEXT); 160 161 // allow "finish" on the last page only 162 enableButtons(WZB_FINISH, GBW_STATE_FINALIZE == _nState); 163 // allow previous on all pages but the first one 164 enableButtons(WZB_PREVIOUS, GBW_STATE_OPTIONLIST != _nState); 165 // allow next on all pages but the last one 166 enableButtons(WZB_NEXT, GBW_STATE_FINALIZE != _nState); 167 168 OControlWizard::enterState(_nState); 169 } 170 171 //--------------------------------------------------------------------- createRadios()172 void OGroupBoxWizard::createRadios() 173 { 174 try 175 { 176 OOptionGroupLayouter aLayouter(getServiceFactory()); 177 aLayouter.doLayout(getContext(), getSettings()); 178 } 179 catch(Exception&) 180 { 181 DBG_ERROR("OGroupBoxWizard::createRadios: caught an exception while creating the radio shapes!"); 182 } 183 } 184 185 //--------------------------------------------------------------------- onFinish()186 sal_Bool OGroupBoxWizard::onFinish() 187 { 188 // commit the basic control setttings 189 commitControlSettings(&m_aSettings); 190 191 // create the radio buttons 192 createRadios(); 193 194 return OControlWizard::onFinish(); 195 } 196 197 //===================================================================== 198 //= ORadioSelectionPage 199 //===================================================================== 200 //--------------------------------------------------------------------- ORadioSelectionPage(OControlWizard * _pParent)201 ORadioSelectionPage::ORadioSelectionPage( OControlWizard* _pParent ) 202 :OGBWPage(_pParent, ModuleRes(RID_PAGE_GROUPRADIOSELECTION)) 203 ,m_aFrame (this, ModuleRes(FL_DATA)) 204 ,m_aRadioNameLabel (this, ModuleRes(FT_RADIOLABELS)) 205 ,m_aRadioName (this, ModuleRes(ET_RADIOLABELS)) 206 ,m_aMoveRight (this, ModuleRes(PB_MOVETORIGHT)) 207 ,m_aMoveLeft (this, ModuleRes(PB_MOVETOLEFT)) 208 ,m_aExistingRadiosLabel (this, ModuleRes(FT_RADIOBUTTONS)) 209 ,m_aExistingRadios (this, ModuleRes(LB_RADIOBUTTONS)) 210 { 211 FreeResource(); 212 213 if (getContext().aFieldNames.getLength()) 214 { 215 enableFormDatasourceDisplay(); 216 } 217 else 218 { 219 adjustControlForNoDSDisplay(&m_aFrame); 220 adjustControlForNoDSDisplay(&m_aRadioNameLabel); 221 adjustControlForNoDSDisplay(&m_aRadioName); 222 adjustControlForNoDSDisplay(&m_aMoveRight); 223 adjustControlForNoDSDisplay(&m_aMoveLeft); 224 adjustControlForNoDSDisplay(&m_aExistingRadiosLabel); 225 adjustControlForNoDSDisplay(&m_aExistingRadios, sal_True); 226 } 227 228 m_aMoveLeft.SetClickHdl(LINK(this, ORadioSelectionPage, OnMoveEntry)); 229 m_aMoveRight.SetClickHdl(LINK(this, ORadioSelectionPage, OnMoveEntry)); 230 m_aRadioName.SetModifyHdl(LINK(this, ORadioSelectionPage, OnNameModified)); 231 m_aExistingRadios.SetSelectHdl(LINK(this, ORadioSelectionPage, OnEntrySelected)); 232 233 implCheckMoveButtons(); 234 m_aExistingRadios.EnableMultiSelection(sal_True); 235 236 getDialog()->defaultButton(&m_aMoveRight); 237 238 m_aExistingRadios.SetAccessibleRelationMemberOf(&m_aExistingRadios); 239 m_aExistingRadios.SetAccessibleRelationLabeledBy(&m_aExistingRadiosLabel); 240 } 241 242 //--------------------------------------------------------------------- ActivatePage()243 void ORadioSelectionPage::ActivatePage() 244 { 245 OGBWPage::ActivatePage(); 246 m_aRadioName.GrabFocus(); 247 } 248 249 //--------------------------------------------------------------------- initializePage()250 void ORadioSelectionPage::initializePage() 251 { 252 OGBWPage::initializePage(); 253 254 m_aRadioName.SetText(String()); 255 256 // no need to initialize the list of radios here 257 // (we're the only one affecting this special setting, so it will be in the same state as last time this 258 // page was committed) 259 260 implCheckMoveButtons(); 261 } 262 263 //--------------------------------------------------------------------- commitPage(::svt::WizardTypes::CommitPageReason _eReason)264 sal_Bool ORadioSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason ) 265 { 266 if (!OGBWPage::commitPage(_eReason)) 267 return sal_False; 268 269 // copy the names of the radio buttons to be inserted 270 // and initialize the values 271 OOptionGroupSettings& rSettings = getSettings(); 272 rSettings.aLabels.clear(); 273 rSettings.aValues.clear(); 274 rSettings.aLabels.reserve(m_aExistingRadios.GetEntryCount()); 275 rSettings.aValues.reserve(m_aExistingRadios.GetEntryCount()); 276 for (::svt::WizardTypes::WizardState i=0; i<m_aExistingRadios.GetEntryCount(); ++i) 277 { 278 rSettings.aLabels.push_back(m_aExistingRadios.GetEntry(i)); 279 rSettings.aValues.push_back(String::CreateFromInt32((sal_Int32)(i + 1))); 280 } 281 282 return sal_True; 283 } 284 285 //--------------------------------------------------------------------- IMPL_LINK(ORadioSelectionPage,OnMoveEntry,PushButton *,_pButton)286 IMPL_LINK( ORadioSelectionPage, OnMoveEntry, PushButton*, _pButton ) 287 { 288 sal_Bool bMoveLeft = (&m_aMoveLeft == _pButton); 289 if (bMoveLeft) 290 { 291 while (m_aExistingRadios.GetSelectEntryCount()) 292 m_aExistingRadios.RemoveEntry(m_aExistingRadios.GetSelectEntryPos(0)); 293 } 294 else 295 { 296 m_aExistingRadios.InsertEntry(m_aRadioName.GetText()); 297 m_aRadioName.SetText(String()); 298 } 299 300 implCheckMoveButtons(); 301 302 //adjust the focus 303 if (bMoveLeft) 304 m_aExistingRadios.GrabFocus(); 305 else 306 m_aRadioName.GrabFocus(); 307 return 0L; 308 } 309 310 //--------------------------------------------------------------------- 311 IMPL_LINK( ORadioSelectionPage, OnEntrySelected, ListBox*, /*_pList*/ ) 312 { 313 implCheckMoveButtons(); 314 return 0L; 315 } 316 317 //--------------------------------------------------------------------- 318 IMPL_LINK( ORadioSelectionPage, OnNameModified, Edit*, /*_pList*/ ) 319 { 320 implCheckMoveButtons(); 321 return 0L; 322 } 323 324 //--------------------------------------------------------------------- canAdvance() const325 bool ORadioSelectionPage::canAdvance() const 326 { 327 return 0 != m_aExistingRadios.GetEntryCount(); 328 } 329 330 //--------------------------------------------------------------------- implCheckMoveButtons()331 void ORadioSelectionPage::implCheckMoveButtons() 332 { 333 sal_Bool bHaveSome = (0 != m_aExistingRadios.GetEntryCount()); 334 sal_Bool bSelectedSome = (0 != m_aExistingRadios.GetSelectEntryCount()); 335 sal_Bool bUnfinishedInput = (0 != m_aRadioName.GetText().Len()); 336 337 m_aMoveLeft.Enable(bSelectedSome); 338 m_aMoveRight.Enable(bUnfinishedInput); 339 340 getDialog()->enableButtons(WZB_NEXT, bHaveSome); 341 342 if (bUnfinishedInput) 343 { 344 if (0 == (m_aMoveRight.GetStyle() & WB_DEFBUTTON)) 345 getDialog()->defaultButton(&m_aMoveRight); 346 } 347 else 348 { 349 if (WB_DEFBUTTON == (m_aMoveRight.GetStyle() & WB_DEFBUTTON)) 350 getDialog()->defaultButton(WZB_NEXT); 351 } 352 } 353 354 //===================================================================== 355 //= ODefaultFieldSelectionPage 356 //===================================================================== 357 //--------------------------------------------------------------------- ODefaultFieldSelectionPage(OControlWizard * _pParent)358 ODefaultFieldSelectionPage::ODefaultFieldSelectionPage( OControlWizard* _pParent ) 359 :OMaybeListSelectionPage(_pParent, ModuleRes(RID_PAGE_DEFAULTFIELDSELECTION)) 360 ,m_aFrame (this, ModuleRes(FL_DEFAULTSELECTION)) 361 ,m_aDefaultSelectionLabel (this, ModuleRes(FT_DEFAULTSELECTION)) 362 ,m_aDefSelYes (this, ModuleRes(RB_DEFSELECTION_YES)) 363 ,m_aDefSelNo (this, ModuleRes(RB_DEFSELECTION_NO)) 364 ,m_aDefSelection (this, ModuleRes(LB_DEFSELECTIONFIELD)) 365 { 366 FreeResource(); 367 368 announceControls(m_aDefSelYes, m_aDefSelNo, m_aDefSelection); 369 m_aDefSelection.SetDropDownLineCount(10); 370 m_aDefSelection.SetAccessibleRelationLabeledBy( &m_aDefSelYes ); 371 m_aDefSelection.SetAccessibleRelationMemberOf(&m_aDefaultSelectionLabel); 372 } 373 374 //--------------------------------------------------------------------- initializePage()375 void ODefaultFieldSelectionPage::initializePage() 376 { 377 OMaybeListSelectionPage::initializePage(); 378 379 const OOptionGroupSettings& rSettings = getSettings(); 380 381 // fill the listbox 382 m_aDefSelection.Clear(); 383 for ( ConstStringArrayIterator aLoop = rSettings.aLabels.begin(); 384 aLoop != rSettings.aLabels.end(); 385 ++aLoop 386 ) 387 m_aDefSelection.InsertEntry(*aLoop); 388 389 390 implInitialize(rSettings.sDefaultField); 391 } 392 393 //--------------------------------------------------------------------- commitPage(::svt::WizardTypes::CommitPageReason _eReason)394 sal_Bool ODefaultFieldSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason ) 395 { 396 if (!OMaybeListSelectionPage::commitPage(_eReason)) 397 return sal_False; 398 399 OOptionGroupSettings& rSettings = getSettings(); 400 implCommit(rSettings.sDefaultField); 401 402 return sal_True; 403 } 404 405 //===================================================================== 406 //= OOptionValuesPage 407 //===================================================================== 408 //--------------------------------------------------------------------- OOptionValuesPage(OControlWizard * _pParent)409 OOptionValuesPage::OOptionValuesPage( OControlWizard* _pParent ) 410 :OGBWPage(_pParent, ModuleRes(RID_PAGE_OPTIONVALUES)) 411 ,m_aFrame (this, ModuleRes(FL_OPTIONVALUES)) 412 ,m_aDescription (this, ModuleRes(FT_OPTIONVALUES_EXPL)) 413 ,m_aValueLabel (this, ModuleRes(FT_OPTIONVALUES)) 414 ,m_aValue (this, ModuleRes(ET_OPTIONVALUE)) 415 ,m_aOptionsLabel (this, ModuleRes(FT_RADIOBUTTONS)) 416 ,m_aOptions (this, ModuleRes(LB_RADIOBUTTONS)) 417 ,m_nLastSelection((::svt::WizardTypes::WizardState)-1) 418 { 419 FreeResource(); 420 421 m_aOptions.SetSelectHdl(LINK(this, OOptionValuesPage, OnOptionSelected)); 422 423 m_aOptions.SetAccessibleRelationMemberOf(&m_aOptions); 424 m_aOptions.SetAccessibleRelationLabeledBy(&m_aOptionsLabel); 425 } 426 427 //--------------------------------------------------------------------- 428 IMPL_LINK( OOptionValuesPage, OnOptionSelected, ListBox*, /*NOTINTERESTEDIN*/ ) 429 { 430 implTraveledOptions(); 431 return 0L; 432 } 433 434 //--------------------------------------------------------------------- ActivatePage()435 void OOptionValuesPage::ActivatePage() 436 { 437 OGBWPage::ActivatePage(); 438 m_aValue.GrabFocus(); 439 } 440 441 //--------------------------------------------------------------------- implTraveledOptions()442 void OOptionValuesPage::implTraveledOptions() 443 { 444 if ((::svt::WizardTypes::WizardState)-1 != m_nLastSelection) 445 { 446 // save the value for the last option 447 DBG_ASSERT((size_t)m_nLastSelection < m_aUncommittedValues.size(), "OOptionValuesPage::implTraveledOptions: invalid previous selection index!"); 448 m_aUncommittedValues[m_nLastSelection] = m_aValue.GetText(); 449 } 450 451 m_nLastSelection = m_aOptions.GetSelectEntryPos(); 452 DBG_ASSERT((size_t)m_nLastSelection < m_aUncommittedValues.size(), "OOptionValuesPage::implTraveledOptions: invalid new selection index!"); 453 m_aValue.SetText(m_aUncommittedValues[m_nLastSelection]); 454 } 455 456 //--------------------------------------------------------------------- initializePage()457 void OOptionValuesPage::initializePage() 458 { 459 OGBWPage::initializePage(); 460 461 const OOptionGroupSettings& rSettings = getSettings(); 462 DBG_ASSERT(rSettings.aLabels.size(), "OOptionValuesPage::initializePage: no options!!"); 463 DBG_ASSERT(rSettings.aLabels.size() == rSettings.aValues.size(), "OOptionValuesPage::initializePage: inconsistent data!"); 464 465 // fill the list with all available options 466 m_aOptions.Clear(); 467 m_nLastSelection = -1; 468 for ( ConstStringArrayIterator aLoop = rSettings.aLabels.begin(); 469 aLoop != rSettings.aLabels.end(); 470 ++aLoop 471 ) 472 m_aOptions.InsertEntry(*aLoop); 473 474 // remember the values ... can't set them directly in the settings without the explicit commit call 475 // so we need have a copy of the values 476 m_aUncommittedValues = rSettings.aValues; 477 478 // select the first entry 479 m_aOptions.SelectEntryPos(0); 480 implTraveledOptions(); 481 } 482 483 //--------------------------------------------------------------------- commitPage(::svt::WizardTypes::CommitPageReason _eReason)484 sal_Bool OOptionValuesPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason ) 485 { 486 if (!OGBWPage::commitPage(_eReason)) 487 return sal_False; 488 489 OOptionGroupSettings& rSettings = getSettings(); 490 491 // commit the current value 492 implTraveledOptions(); 493 // copy the uncommitted values 494 rSettings.aValues = m_aUncommittedValues; 495 496 return sal_True; 497 } 498 499 //===================================================================== 500 //= OOptionDBFieldPage 501 //===================================================================== 502 //--------------------------------------------------------------------- OOptionDBFieldPage(OControlWizard * _pParent)503 OOptionDBFieldPage::OOptionDBFieldPage( OControlWizard* _pParent ) 504 :ODBFieldPage(_pParent) 505 { 506 setDescriptionText(String(ModuleRes(RID_STR_GROUPWIZ_DBFIELD))); 507 } 508 509 //--------------------------------------------------------------------- getDBFieldSetting()510 String& OOptionDBFieldPage::getDBFieldSetting() 511 { 512 return getSettings().sDBField; 513 } 514 515 //===================================================================== 516 //= OFinalizeGBWPage 517 //===================================================================== 518 //--------------------------------------------------------------------- OFinalizeGBWPage(OControlWizard * _pParent)519 OFinalizeGBWPage::OFinalizeGBWPage( OControlWizard* _pParent ) 520 :OGBWPage(_pParent, ModuleRes(RID_PAGE_OPTIONS_FINAL)) 521 ,m_aFrame (this, ModuleRes(FL_NAMEIT)) 522 ,m_aNameLabel (this, ModuleRes(FT_NAMEIT)) 523 ,m_aName (this, ModuleRes(ET_NAMEIT)) 524 ,m_aThatsAll (this, ModuleRes(FT_THATSALL)) 525 { 526 FreeResource(); 527 } 528 529 //--------------------------------------------------------------------- ActivatePage()530 void OFinalizeGBWPage::ActivatePage() 531 { 532 OGBWPage::ActivatePage(); 533 m_aName.GrabFocus(); 534 } 535 536 //--------------------------------------------------------------------- canAdvance() const537 bool OFinalizeGBWPage::canAdvance() const 538 { 539 return false; 540 } 541 542 //--------------------------------------------------------------------- initializePage()543 void OFinalizeGBWPage::initializePage() 544 { 545 OGBWPage::initializePage(); 546 547 const OOptionGroupSettings& rSettings = getSettings(); 548 m_aName.SetText(rSettings.sControlLabel); 549 } 550 551 //--------------------------------------------------------------------- commitPage(::svt::WizardTypes::CommitPageReason _eReason)552 sal_Bool OFinalizeGBWPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason ) 553 { 554 if (!OGBWPage::commitPage(_eReason)) 555 return sal_False; 556 557 getSettings().sControlLabel = m_aName.GetText(); 558 559 return sal_True; 560 } 561 562 //......................................................................... 563 } // namespace dbp 564 //......................................................................... 565 566