LCOV - code coverage report
Current view: top level - extensions/source/dbpilots - groupboxwiz.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 216 0.0 %
Date: 2014-11-03 Functions: 0 38 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      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>
      28             : 
      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
      34             : 
      35             : 
      36             : namespace dbp
      37             : {
      38             : 
      39             : 
      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;
      45             : 
      46             : 
      47             :     //= OGroupBoxWizard
      48             : 
      49             : 
      50           0 :     OGroupBoxWizard::OGroupBoxWizard( vcl::Window* _pParent,
      51             :             const Reference< XPropertySet >& _rxObjectModel, const Reference< XComponentContext >& _rxContext )
      52             :         :OControlWizard(_pParent, _rxObjectModel, _rxContext)
      53             :         ,m_bVisitedDefault(false)
      54           0 :         ,m_bVisitedDB(false)
      55             :     {
      56           0 :         initControlSettings(&m_aSettings);
      57             : 
      58           0 :         m_pPrevPage->SetHelpId(HID_GROUPWIZARD_PREVIOUS);
      59           0 :         m_pNextPage->SetHelpId(HID_GROUPWIZARD_NEXT);
      60           0 :         m_pCancel->SetHelpId(HID_GROUPWIZARD_CANCEL);
      61           0 :         m_pFinish->SetHelpId(HID_GROUPWIZARD_FINISH);
      62           0 :         setTitleBase(ModuleRes(RID_STR_GROUPWIZARD_TITLE).toString());
      63           0 :     }
      64             : 
      65             : 
      66           0 :     bool OGroupBoxWizard::approveControl(sal_Int16 _nClassId)
      67             :     {
      68           0 :         return FormComponentType::GROUPBOX == _nClassId;
      69             :     }
      70             : 
      71             : 
      72           0 :     OWizardPage* OGroupBoxWizard::createPage(::svt::WizardTypes::WizardState _nState)
      73             :     {
      74           0 :         switch (_nState)
      75             :         {
      76             :             case GBW_STATE_OPTIONLIST:
      77           0 :                 return new ORadioSelectionPage(this);
      78             : 
      79             :             case GBW_STATE_DEFAULTOPTION:
      80           0 :                 return new ODefaultFieldSelectionPage(this);
      81             : 
      82             :             case GBW_STATE_OPTIONVALUES:
      83           0 :                 return new OOptionValuesPage(this);
      84             : 
      85             :             case GBW_STATE_DBFIELD:
      86           0 :                 return new OOptionDBFieldPage(this);
      87             : 
      88             :             case GBW_STATE_FINALIZE:
      89           0 :                 return new OFinalizeGBWPage(this);
      90             :         }
      91             : 
      92           0 :         return NULL;
      93             :     }
      94             : 
      95             : 
      96           0 :     WizardTypes::WizardState OGroupBoxWizard::determineNextState( ::svt::WizardTypes::WizardState _nCurrentState ) const
      97             :     {
      98           0 :         switch (_nCurrentState)
      99             :         {
     100             :             case GBW_STATE_OPTIONLIST:
     101           0 :                 return GBW_STATE_DEFAULTOPTION;
     102             : 
     103             :             case GBW_STATE_DEFAULTOPTION:
     104           0 :                 return GBW_STATE_OPTIONVALUES;
     105             : 
     106             :             case GBW_STATE_OPTIONVALUES:
     107           0 :                 if (getContext().aFieldNames.getLength())
     108           0 :                     return GBW_STATE_DBFIELD;
     109             :                 else
     110           0 :                     return GBW_STATE_FINALIZE;
     111             : 
     112             :             case GBW_STATE_DBFIELD:
     113           0 :                 return GBW_STATE_FINALIZE;
     114             :         }
     115             : 
     116           0 :         return WZS_INVALID_STATE;
     117             :     }
     118             : 
     119             : 
     120           0 :     void OGroupBoxWizard::enterState(::svt::WizardTypes::WizardState _nState)
     121             :     {
     122             :         // some stuff to do before calling the base class (modifying our settings)
     123           0 :         switch (_nState)
     124             :         {
     125             :             case GBW_STATE_DEFAULTOPTION:
     126           0 :                 if (!m_bVisitedDefault)
     127             :                 {   // assume that the first of the radio buttons should be selected
     128             :                     DBG_ASSERT(m_aSettings.aLabels.size(), "OGroupBoxWizard::enterState: should never have reached this state!");
     129           0 :                     m_aSettings.sDefaultField = m_aSettings.aLabels[0];
     130             :                 }
     131           0 :                 m_bVisitedDefault = true;
     132           0 :                 break;
     133             : 
     134             :             case GBW_STATE_DBFIELD:
     135           0 :                 if (!m_bVisitedDB)
     136             :                 {   // try to generate a default for the DB field
     137             :                     // (simply use the first field in the DB names collection)
     138           0 :                     if (getContext().aFieldNames.getLength())
     139           0 :                         m_aSettings.sDBField = getContext().aFieldNames[0];
     140             :                 }
     141           0 :                 m_bVisitedDB = true;
     142           0 :                 break;
     143             :         }
     144             : 
     145             :         // setting the def button .... to be done before the base class is called, too, 'cause the base class
     146             :         // calls the pages, which are allowed to override our def button behaviour
     147           0 :         defaultButton(GBW_STATE_FINALIZE == _nState ? WZB_FINISH : WZB_NEXT);
     148             : 
     149             :         // allow "finish" on the last page only
     150           0 :         enableButtons(WZB_FINISH, GBW_STATE_FINALIZE == _nState);
     151             :         // allow previous on all pages but the first one
     152           0 :         enableButtons(WZB_PREVIOUS, GBW_STATE_OPTIONLIST != _nState);
     153             :         // allow next on all pages but the last one
     154           0 :         enableButtons(WZB_NEXT, GBW_STATE_FINALIZE != _nState);
     155             : 
     156           0 :         OControlWizard::enterState(_nState);
     157           0 :     }
     158             : 
     159             : 
     160           0 :     void OGroupBoxWizard::createRadios()
     161             :     {
     162             :         try
     163             :         {
     164           0 :             OOptionGroupLayouter aLayouter( getComponentContext() );
     165           0 :             aLayouter.doLayout(getContext(), getSettings());
     166             :         }
     167           0 :         catch(const Exception&)
     168             :         {
     169             :             OSL_FAIL("OGroupBoxWizard::createRadios: caught an exception while creating the radio shapes!");
     170             :         }
     171           0 :     }
     172             : 
     173             : 
     174           0 :     bool OGroupBoxWizard::onFinish()
     175             :     {
     176             :         // commit the basic control setttings
     177           0 :         commitControlSettings(&m_aSettings);
     178             : 
     179             :         // create the radio buttons
     180           0 :         createRadios();
     181             : 
     182           0 :         return OControlWizard::onFinish();
     183             :     }
     184             : 
     185             : 
     186             :     //= ORadioSelectionPage
     187             : 
     188             : 
     189           0 :     ORadioSelectionPage::ORadioSelectionPage( OControlWizard* _pParent )
     190           0 :         :OGBWPage(_pParent, "GroupRadioSelectionPage", "modules/sabpilot/ui/groupradioselectionpage.ui")
     191             :     {
     192           0 :         get(m_pRadioName, "radiolabels");
     193           0 :         get(m_pMoveRight, "toright");
     194           0 :         get(m_pMoveLeft, "toleft");
     195           0 :         get(m_pExistingRadios, "radiobuttons");
     196             : 
     197           0 :         if (getContext().aFieldNames.getLength())
     198             :         {
     199           0 :             enableFormDatasourceDisplay();
     200             :         }
     201             : 
     202           0 :         m_pMoveLeft->SetClickHdl(LINK(this, ORadioSelectionPage, OnMoveEntry));
     203           0 :         m_pMoveRight->SetClickHdl(LINK(this, ORadioSelectionPage, OnMoveEntry));
     204           0 :         m_pRadioName->SetModifyHdl(LINK(this, ORadioSelectionPage, OnNameModified));
     205           0 :         m_pExistingRadios->SetSelectHdl(LINK(this, ORadioSelectionPage, OnEntrySelected));
     206             : 
     207           0 :         implCheckMoveButtons();
     208           0 :         m_pExistingRadios->EnableMultiSelection(true);
     209             : 
     210           0 :         getDialog()->defaultButton(m_pMoveRight);
     211             : 
     212           0 :         m_pExistingRadios->SetAccessibleRelationMemberOf(m_pExistingRadios);
     213           0 :     }
     214             : 
     215             : 
     216           0 :     void ORadioSelectionPage::ActivatePage()
     217             :     {
     218           0 :         OGBWPage::ActivatePage();
     219           0 :         m_pRadioName->GrabFocus();
     220           0 :     }
     221             : 
     222             : 
     223           0 :     void ORadioSelectionPage::initializePage()
     224             :     {
     225           0 :         OGBWPage::initializePage();
     226             : 
     227           0 :         m_pRadioName->SetText("");
     228             : 
     229             :         // no need to initialize the list of radios here
     230             :         // (we're the only one affecting this special setting, so it will be in the same state as last time this
     231             :         // page was commited)
     232             : 
     233           0 :         implCheckMoveButtons();
     234           0 :     }
     235             : 
     236             : 
     237           0 :     bool ORadioSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
     238             :     {
     239           0 :         if (!OGBWPage::commitPage(_eReason))
     240           0 :             return false;
     241             : 
     242             :         // copy the names of the radio buttons to be inserted
     243             :         // and initialize the values
     244           0 :         OOptionGroupSettings& rSettings = getSettings();
     245           0 :         rSettings.aLabels.clear();
     246           0 :         rSettings.aValues.clear();
     247           0 :         rSettings.aLabels.reserve(m_pExistingRadios->GetEntryCount());
     248           0 :         rSettings.aValues.reserve(m_pExistingRadios->GetEntryCount());
     249           0 :         for (::svt::WizardTypes::WizardState i=0; i<m_pExistingRadios->GetEntryCount(); ++i)
     250             :         {
     251           0 :             rSettings.aLabels.push_back(m_pExistingRadios->GetEntry(i));
     252           0 :             rSettings.aValues.push_back(OUString::number((i + 1)));
     253             :         }
     254             : 
     255           0 :         return true;
     256             :     }
     257             : 
     258             : 
     259           0 :     IMPL_LINK( ORadioSelectionPage, OnMoveEntry, PushButton*, _pButton )
     260             :     {
     261           0 :         bool bMoveLeft = (m_pMoveLeft == _pButton);
     262           0 :         if (bMoveLeft)
     263             :         {
     264           0 :             while (m_pExistingRadios->GetSelectEntryCount())
     265           0 :                 m_pExistingRadios->RemoveEntry(m_pExistingRadios->GetSelectEntryPos(0));
     266             :         }
     267             :         else
     268             :         {
     269           0 :             m_pExistingRadios->InsertEntry(m_pRadioName->GetText());
     270           0 :             m_pRadioName->SetText("");
     271             :         }
     272             : 
     273           0 :         implCheckMoveButtons();
     274             : 
     275             :         //adjust the focus
     276           0 :         if (bMoveLeft)
     277           0 :             m_pExistingRadios->GrabFocus();
     278             :         else
     279           0 :             m_pRadioName->GrabFocus();
     280           0 :         return 0L;
     281             :     }
     282             : 
     283             : 
     284           0 :     IMPL_LINK( ORadioSelectionPage, OnEntrySelected, ListBox*, /*_pList*/ )
     285             :     {
     286           0 :         implCheckMoveButtons();
     287           0 :         return 0L;
     288             :     }
     289             : 
     290             : 
     291           0 :     IMPL_LINK( ORadioSelectionPage, OnNameModified, Edit*, /*_pList*/ )
     292             :     {
     293           0 :         implCheckMoveButtons();
     294           0 :         return 0L;
     295             :     }
     296             : 
     297             : 
     298           0 :     bool ORadioSelectionPage::canAdvance() const
     299             :     {
     300           0 :         return 0 != m_pExistingRadios->GetEntryCount();
     301             :     }
     302             : 
     303             : 
     304           0 :     void ORadioSelectionPage::implCheckMoveButtons()
     305             :     {
     306           0 :         bool bHaveSome = (0 != m_pExistingRadios->GetEntryCount());
     307           0 :         bool bSelectedSome = (0 != m_pExistingRadios->GetSelectEntryCount());
     308           0 :         bool bUnfinishedInput = (!m_pRadioName->GetText().isEmpty());
     309             : 
     310           0 :         m_pMoveLeft->Enable(bSelectedSome);
     311           0 :         m_pMoveRight->Enable(bUnfinishedInput);
     312             : 
     313           0 :         getDialog()->enableButtons(WZB_NEXT, bHaveSome);
     314             : 
     315           0 :         if (bUnfinishedInput)
     316             :         {
     317           0 :             if (0 == (m_pMoveRight->GetStyle() & WB_DEFBUTTON))
     318           0 :                 getDialog()->defaultButton(m_pMoveRight);
     319             :         }
     320             :         else
     321             :         {
     322           0 :             if (WB_DEFBUTTON == (m_pMoveRight->GetStyle() & WB_DEFBUTTON))
     323           0 :                 getDialog()->defaultButton(WZB_NEXT);
     324             :         }
     325           0 :     }
     326             : 
     327             : 
     328             :     //= ODefaultFieldSelectionPage
     329             : 
     330             : 
     331           0 :     ODefaultFieldSelectionPage::ODefaultFieldSelectionPage( OControlWizard* _pParent )
     332           0 :         :OMaybeListSelectionPage(_pParent, "DefaultFieldSelectionPage", "modules/sabpilot/ui/defaultfieldselectionpage.ui")
     333             :     {
     334           0 :         get(m_pDefSelYes, "defaultselectionyes");
     335           0 :         get(m_pDefSelNo, "defaultselectionno");
     336           0 :         get(m_pDefSelection, "defselectionfield");
     337             : 
     338           0 :         announceControls(*m_pDefSelYes, *m_pDefSelNo, *m_pDefSelection);
     339           0 :         m_pDefSelection->SetDropDownLineCount(10);
     340           0 :         m_pDefSelection->SetAccessibleRelationLabeledBy( m_pDefSelYes );
     341           0 :         m_pDefSelection->SetStyle(WB_DROPDOWN);
     342           0 :     }
     343             : 
     344             : 
     345           0 :     void ODefaultFieldSelectionPage::initializePage()
     346             :     {
     347           0 :         OMaybeListSelectionPage::initializePage();
     348             : 
     349           0 :         const OOptionGroupSettings& rSettings = getSettings();
     350             : 
     351             :         // fill the listbox
     352           0 :         m_pDefSelection->Clear();
     353           0 :         for (   StringArray::const_iterator aLoop = rSettings.aLabels.begin();
     354           0 :                 aLoop != rSettings.aLabels.end();
     355             :                 ++aLoop
     356             :             )
     357           0 :             m_pDefSelection->InsertEntry(*aLoop);
     358             : 
     359             : 
     360           0 :         implInitialize(rSettings.sDefaultField);
     361           0 :     }
     362             : 
     363             : 
     364           0 :     bool ODefaultFieldSelectionPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
     365             :     {
     366           0 :         if (!OMaybeListSelectionPage::commitPage(_eReason))
     367           0 :             return false;
     368             : 
     369           0 :         OOptionGroupSettings& rSettings = getSettings();
     370           0 :         implCommit(rSettings.sDefaultField);
     371             : 
     372           0 :         return true;
     373             :     }
     374             : 
     375             : 
     376             :     //= OOptionValuesPage
     377             : 
     378             : 
     379           0 :     OOptionValuesPage::OOptionValuesPage( OControlWizard* _pParent )
     380             :         :OGBWPage(_pParent, "OptionValuesPage", "modules/sabpilot/ui/optionvaluespage.ui")
     381           0 :         ,m_nLastSelection((::svt::WizardTypes::WizardState)-1)
     382             :     {
     383           0 :         get(m_pValue, "optionvalue");
     384           0 :         get(m_pOptions, "radiobuttons");
     385             : 
     386           0 :         m_pOptions->SetSelectHdl(LINK(this, OOptionValuesPage, OnOptionSelected));
     387             : 
     388           0 :         m_pOptions->SetAccessibleRelationMemberOf(m_pOptions);
     389           0 :     }
     390             : 
     391             : 
     392           0 :     IMPL_LINK( OOptionValuesPage, OnOptionSelected, ListBox*, /*NOTINTERESTEDIN*/ )
     393             :     {
     394           0 :         implTraveledOptions();
     395           0 :         return 0L;
     396             :     }
     397             : 
     398             : 
     399           0 :     void OOptionValuesPage::ActivatePage()
     400             :     {
     401           0 :         OGBWPage::ActivatePage();
     402           0 :         m_pValue->GrabFocus();
     403           0 :     }
     404             : 
     405             : 
     406           0 :     void OOptionValuesPage::implTraveledOptions()
     407             :     {
     408           0 :         if ((::svt::WizardTypes::WizardState)-1 != m_nLastSelection)
     409             :         {
     410             :             // save the value for the last option
     411             :             DBG_ASSERT((size_t)m_nLastSelection < m_aUncommittedValues.size(), "OOptionValuesPage::implTraveledOptions: invalid previous selection index!");
     412           0 :             m_aUncommittedValues[m_nLastSelection] = m_pValue->GetText();
     413             :         }
     414             : 
     415           0 :         m_nLastSelection = m_pOptions->GetSelectEntryPos();
     416             :         DBG_ASSERT((size_t)m_nLastSelection < m_aUncommittedValues.size(), "OOptionValuesPage::implTraveledOptions: invalid new selection index!");
     417           0 :         m_pValue->SetText(m_aUncommittedValues[m_nLastSelection]);
     418           0 :     }
     419             : 
     420             : 
     421           0 :     void OOptionValuesPage::initializePage()
     422             :     {
     423           0 :         OGBWPage::initializePage();
     424             : 
     425           0 :         const OOptionGroupSettings& rSettings = getSettings();
     426             :         DBG_ASSERT(rSettings.aLabels.size(), "OOptionValuesPage::initializePage: no options!!");
     427             :         DBG_ASSERT(rSettings.aLabels.size() == rSettings.aValues.size(), "OOptionValuesPage::initializePage: inconsistent data!");
     428             : 
     429             :         // fill the list with all available options
     430           0 :         m_pOptions->Clear();
     431           0 :         m_nLastSelection = -1;
     432           0 :         for (   StringArray::const_iterator aLoop = rSettings.aLabels.begin();
     433           0 :                 aLoop != rSettings.aLabels.end();
     434             :                 ++aLoop
     435             :             )
     436           0 :             m_pOptions->InsertEntry(*aLoop);
     437             : 
     438             :         // remember the values ... can't set them directly in the settings without the explicit commit call
     439             :         // so we need have a copy of the values
     440           0 :         m_aUncommittedValues = rSettings.aValues;
     441             : 
     442             :         // select the first entry
     443           0 :         m_pOptions->SelectEntryPos(0);
     444           0 :         implTraveledOptions();
     445           0 :     }
     446             : 
     447             : 
     448           0 :     bool OOptionValuesPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
     449             :     {
     450           0 :         if (!OGBWPage::commitPage(_eReason))
     451           0 :             return false;
     452             : 
     453           0 :         OOptionGroupSettings& rSettings = getSettings();
     454             : 
     455             :         // commit the current value
     456           0 :         implTraveledOptions();
     457             :         // copy the uncommitted values
     458           0 :         rSettings.aValues = m_aUncommittedValues;
     459             : 
     460           0 :         return true;
     461             :     }
     462             : 
     463             : 
     464             :     //= OOptionDBFieldPage
     465             : 
     466             : 
     467           0 :     OOptionDBFieldPage::OOptionDBFieldPage( OControlWizard* _pParent )
     468           0 :         :ODBFieldPage(_pParent)
     469             :     {
     470           0 :         setDescriptionText(ModuleRes(RID_STR_GROUPWIZ_DBFIELD).toString());
     471           0 :     }
     472             : 
     473             : 
     474           0 :     OUString& OOptionDBFieldPage::getDBFieldSetting()
     475             :     {
     476           0 :         return getSettings().sDBField;
     477             :     }
     478             : 
     479             : 
     480             :     //= OFinalizeGBWPage
     481             : 
     482             : 
     483           0 :     OFinalizeGBWPage::OFinalizeGBWPage( OControlWizard* _pParent )
     484           0 :         :OGBWPage(_pParent, "OptionsFinalPage", "modules/sabpilot/ui/optionsfinalpage.ui")
     485             :     {
     486           0 :         get(m_pName, "nameit");
     487           0 :     }
     488             : 
     489             : 
     490           0 :     void OFinalizeGBWPage::ActivatePage()
     491             :     {
     492           0 :         OGBWPage::ActivatePage();
     493           0 :         m_pName->GrabFocus();
     494           0 :     }
     495             : 
     496             : 
     497           0 :     bool OFinalizeGBWPage::canAdvance() const
     498             :     {
     499           0 :         return false;
     500             :     }
     501             : 
     502             : 
     503           0 :     void OFinalizeGBWPage::initializePage()
     504             :     {
     505           0 :         OGBWPage::initializePage();
     506             : 
     507           0 :         const OOptionGroupSettings& rSettings = getSettings();
     508           0 :         m_pName->SetText(rSettings.sControlLabel);
     509           0 :     }
     510             : 
     511             : 
     512           0 :     bool OFinalizeGBWPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
     513             :     {
     514           0 :         if (!OGBWPage::commitPage(_eReason))
     515           0 :             return false;
     516             : 
     517           0 :         getSettings().sControlLabel = m_pName->GetText();
     518             : 
     519           0 :         return true;
     520             :     }
     521             : 
     522             : 
     523           0 : }   // namespace dbp
     524             : 
     525             : 
     526             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10