LCOV - code coverage report
Current view: top level - extensions/source/dbpilots - gridwizard.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 208 0.0 %
Date: 2012-08-25 Functions: 0 22 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "gridwizard.hxx"
      30                 :            : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      31                 :            : #include <com/sun/star/sdbc/DataType.hpp>
      32                 :            : #include <comphelper/stl_types.hxx>
      33                 :            : #include <tools/string.hxx>
      34                 :            : #include <com/sun/star/form/XGridColumnFactory.hpp>
      35                 :            : #include <com/sun/star/awt/MouseWheelBehavior.hpp>
      36                 :            : #include <com/sun/star/container/XNameContainer.hpp>
      37                 :            : #include <tools/debug.hxx>
      38                 :            : #include "dbptools.hxx"
      39                 :            : #include "dbpilots.hrc"
      40                 :            : 
      41                 :            : #define GW_STATE_DATASOURCE_SELECTION   0
      42                 :            : #define GW_STATE_FIELDSELECTION         1
      43                 :            : 
      44                 :            : //.........................................................................
      45                 :            : namespace dbp
      46                 :            : {
      47                 :            : //.........................................................................
      48                 :            : 
      49                 :            :     using namespace ::com::sun::star::uno;
      50                 :            :     using namespace ::com::sun::star::lang;
      51                 :            :     using namespace ::com::sun::star::beans;
      52                 :            :     using namespace ::com::sun::star::sdbc;
      53                 :            :     using namespace ::com::sun::star::container;
      54                 :            :     using namespace ::com::sun::star::form;
      55                 :            :     using namespace ::com::sun::star::awt;
      56                 :            :     using namespace ::svt;
      57                 :            : 
      58                 :            :     //=====================================================================
      59                 :            :     //= OGridWizard
      60                 :            :     //=====================================================================
      61                 :            :     //---------------------------------------------------------------------
      62                 :          0 :     OGridWizard::OGridWizard( Window* _pParent,
      63                 :            :             const Reference< XPropertySet >& _rxObjectModel, const Reference< XMultiServiceFactory >& _rxORB )
      64                 :            :         :OControlWizard(_pParent, ModuleRes(RID_DLG_GRIDWIZARD), _rxObjectModel, _rxORB)
      65                 :          0 :         ,m_bHadDataSelection(sal_True)
      66                 :            :     {
      67                 :          0 :         initControlSettings(&m_aSettings);
      68                 :            : 
      69                 :          0 :         m_pPrevPage->SetHelpId(HID_GRIDWIZARD_PREVIOUS);
      70                 :          0 :         m_pNextPage->SetHelpId(HID_GRIDWIZARD_NEXT);
      71                 :          0 :         m_pCancel->SetHelpId(HID_GRIDWIZARD_CANCEL);
      72                 :          0 :         m_pFinish->SetHelpId(HID_GRIDWIZARD_FINISH);
      73                 :            : 
      74                 :            :         // if we do not need the data source selection page ...
      75                 :          0 :         if (!needDatasourceSelection())
      76                 :            :         {   // ... skip it!
      77                 :          0 :             skip(1);
      78                 :          0 :             m_bHadDataSelection = sal_False;
      79                 :            :         }
      80                 :          0 :     }
      81                 :            : 
      82                 :            :     //---------------------------------------------------------------------
      83                 :          0 :     sal_Bool OGridWizard::approveControl(sal_Int16 _nClassId)
      84                 :            :     {
      85                 :          0 :         if (FormComponentType::GRIDCONTROL != _nClassId)
      86                 :          0 :             return sal_False;
      87                 :            : 
      88                 :          0 :         Reference< XGridColumnFactory > xColumnFactory(getContext().xObjectModel, UNO_QUERY);
      89                 :          0 :         if (!xColumnFactory.is())
      90                 :          0 :             return sal_False;
      91                 :            : 
      92                 :          0 :         return sal_True;
      93                 :            :     }
      94                 :            : 
      95                 :            :     //---------------------------------------------------------------------
      96                 :          0 :     void OGridWizard::implApplySettings()
      97                 :            :     {
      98                 :          0 :         const OControlWizardContext& rContext = getContext();
      99                 :            : 
     100                 :            :         // the factory for the columns
     101                 :          0 :         Reference< XGridColumnFactory > xColumnFactory(rContext.xObjectModel, UNO_QUERY);
     102                 :            :         DBG_ASSERT(xColumnFactory.is(), "OGridWizard::implApplySettings: should never have made it 'til here!");
     103                 :            :             // (if we're here, what the hell happened in approveControl??)
     104                 :            : 
     105                 :            :         // the container for the columns
     106                 :          0 :         Reference< XNameContainer > xColumnContainer(rContext.xObjectModel, UNO_QUERY);
     107                 :            :         DBG_ASSERT(xColumnContainer.is(), "OGridWizard::implApplySettings: no container!");
     108                 :            : 
     109                 :          0 :         if (!xColumnFactory.is() || !xColumnContainer.is())
     110                 :          0 :             return;
     111                 :            : 
     112                 :          0 :         static const ::rtl::OUString s_sDataFieldProperty   ("DataField");
     113                 :          0 :         static const ::rtl::OUString s_sLabelProperty       ("Label");
     114                 :          0 :         static const ::rtl::OUString s_sWidthProperty       ("Width");
     115                 :          0 :         static const ::rtl::OUString s_sMouseWheelBehavior ("MouseWheelBehavior");
     116                 :          0 :         static const ::rtl::OUString s_sEmptyString;
     117                 :            : 
     118                 :            :         // collect "descriptors" for the to-be-created (grid)columns
     119                 :            :         DECLARE_STL_VECTOR( ::rtl::OUString, OUStringArray );
     120                 :          0 :         OUStringArray aColumnServiceNames;  // service names to be used with the XGridColumnFactory
     121                 :          0 :         OUStringArray aColumnLabelPostfixes;    // postfixes to append to the column labels
     122                 :          0 :         OUStringArray aFormFieldNames;      // data field names
     123                 :            : 
     124                 :          0 :         aColumnServiceNames.reserve(getSettings().aSelectedFields.getLength());
     125                 :          0 :         aColumnLabelPostfixes.reserve(getSettings().aSelectedFields.getLength());
     126                 :          0 :         aFormFieldNames.reserve(getSettings().aSelectedFields.getLength());
     127                 :            : 
     128                 :            :         // loop through the selected field names
     129                 :          0 :         const ::rtl::OUString* pSelectedFields = getSettings().aSelectedFields.getConstArray();
     130                 :          0 :         const ::rtl::OUString* pEnd = pSelectedFields + getSettings().aSelectedFields.getLength();
     131                 :          0 :         for (;pSelectedFields < pEnd; ++pSelectedFields)
     132                 :            :         {
     133                 :            :             // get the information for the selected column
     134                 :          0 :             sal_Int32 nFieldType = DataType::OTHER;
     135                 :          0 :             OControlWizardContext::TNameTypeMap::const_iterator aFind = rContext.aTypes.find(*pSelectedFields);
     136                 :          0 :             if ( aFind != rContext.aTypes.end() )
     137                 :          0 :                 nFieldType = aFind->second;
     138                 :            : 
     139                 :          0 :             aFormFieldNames.push_back(*pSelectedFields);
     140                 :          0 :             switch (nFieldType)
     141                 :            :             {
     142                 :            :                 case DataType::BIT:
     143                 :            :                 case DataType::BOOLEAN:
     144                 :          0 :                     aColumnServiceNames.push_back(::rtl::OUString("CheckBox"));
     145                 :          0 :                     aColumnLabelPostfixes.push_back(s_sEmptyString);
     146                 :          0 :                     break;
     147                 :            : 
     148                 :            :                 case DataType::TINYINT:
     149                 :            :                 case DataType::SMALLINT:
     150                 :            :                 case DataType::INTEGER:
     151                 :          0 :                     aColumnServiceNames.push_back(::rtl::OUString("NumericField"));
     152                 :          0 :                     aColumnLabelPostfixes.push_back(s_sEmptyString);
     153                 :          0 :                     break;
     154                 :            : 
     155                 :            :                 case DataType::FLOAT:
     156                 :            :                 case DataType::REAL:
     157                 :            :                 case DataType::DOUBLE:
     158                 :            :                 case DataType::NUMERIC:
     159                 :            :                 case DataType::DECIMAL:
     160                 :          0 :                     aColumnServiceNames.push_back(::rtl::OUString("FormattedField"));
     161                 :          0 :                     aColumnLabelPostfixes.push_back(s_sEmptyString);
     162                 :          0 :                     break;
     163                 :            : 
     164                 :            :                 case DataType::DATE:
     165                 :          0 :                     aColumnServiceNames.push_back(::rtl::OUString("DateField"));
     166                 :          0 :                     aColumnLabelPostfixes.push_back(s_sEmptyString);
     167                 :          0 :                     break;
     168                 :            : 
     169                 :            :                 case DataType::TIME:
     170                 :          0 :                     aColumnServiceNames.push_back(::rtl::OUString("TimeField"));
     171                 :          0 :                     aColumnLabelPostfixes.push_back(s_sEmptyString);
     172                 :          0 :                     break;
     173                 :            : 
     174                 :            :                 case DataType::TIMESTAMP:
     175                 :          0 :                     aColumnServiceNames.push_back(::rtl::OUString("DateField"));
     176                 :          0 :                     aColumnLabelPostfixes.push_back(String(ModuleRes(RID_STR_DATEPOSTFIX)));
     177                 :            : 
     178                 :          0 :                     aFormFieldNames.push_back(*pSelectedFields);
     179                 :          0 :                     aColumnServiceNames.push_back(::rtl::OUString("TimeField"));
     180                 :          0 :                     aColumnLabelPostfixes.push_back(String(ModuleRes(RID_STR_TIMEPOSTFIX)));
     181                 :          0 :                     break;
     182                 :            : 
     183                 :            :                 default:
     184                 :          0 :                     aColumnServiceNames.push_back(::rtl::OUString("TextField"));
     185                 :          0 :                     aColumnLabelPostfixes.push_back(s_sEmptyString);
     186                 :            :             }
     187                 :            :         }
     188                 :            : 
     189                 :            :         DBG_ASSERT( aFormFieldNames.size() == aColumnServiceNames.size()
     190                 :            :                 &&  aColumnServiceNames.size() == aColumnLabelPostfixes.size(),
     191                 :            :                 "OGridWizard::implApplySettings: inconsistent descriptor sequences!");
     192                 :            : 
     193                 :            :         // now loop through the descriptions and create the (grid)columns out of th descriptors
     194                 :            :         {
     195                 :          0 :             Reference< XNameAccess > xExistenceChecker(xColumnContainer.get());
     196                 :            : 
     197                 :          0 :             ConstOUStringArrayIterator pColumnServiceName = aColumnServiceNames.begin();
     198                 :          0 :             ConstOUStringArrayIterator pColumnLabelPostfix = aColumnLabelPostfixes.begin();
     199                 :          0 :             ConstOUStringArrayIterator pFormFieldName = aFormFieldNames.begin();
     200                 :          0 :             ConstOUStringArrayIterator pColumnServiceNameEnd = aColumnServiceNames.end();
     201                 :            : 
     202                 :          0 :             for (;pColumnServiceName < pColumnServiceNameEnd; ++pColumnServiceName, ++pColumnLabelPostfix, ++pFormFieldName)
     203                 :            :             {
     204                 :            :                 // create a (grid)column for the (resultset)column
     205                 :            :                 try
     206                 :            :                 {
     207                 :          0 :                     Reference< XPropertySet > xColumn( xColumnFactory->createColumn(*pColumnServiceName), UNO_SET_THROW );
     208                 :          0 :                     Reference< XPropertySetInfo > xColumnPSI( xColumn->getPropertySetInfo(), UNO_SET_THROW );
     209                 :            : 
     210                 :          0 :                     ::rtl::OUString sColumnName(*pColumnServiceName);
     211                 :          0 :                     disambiguateName(xExistenceChecker, sColumnName);
     212                 :            : 
     213                 :            :                     // the data field the column should be bound to
     214                 :          0 :                     xColumn->setPropertyValue(s_sDataFieldProperty, makeAny(*pFormFieldName));
     215                 :            :                     // the label
     216                 :          0 :                     xColumn->setPropertyValue(s_sLabelProperty, makeAny(::rtl::OUString(*pFormFieldName) += *pColumnLabelPostfix));
     217                 :            :                     // the width (<void/> => column will be auto-sized)
     218                 :          0 :                     xColumn->setPropertyValue(s_sWidthProperty, Any());
     219                 :            : 
     220                 :          0 :                     if ( xColumnPSI->hasPropertyByName( s_sMouseWheelBehavior ) )
     221                 :          0 :                         xColumn->setPropertyValue( s_sMouseWheelBehavior, makeAny( MouseWheelBehavior::SCROLL_DISABLED ) );
     222                 :            : 
     223                 :            :                     // insert the column
     224                 :          0 :                     xColumnContainer->insertByName(sColumnName, makeAny(xColumn));
     225                 :            :                 }
     226                 :          0 :                 catch(const Exception&)
     227                 :            :                 {
     228                 :            :                     OSL_FAIL( ( ::rtl::OString("OGridWizard::implApplySettings: unexpected exception while creating the grid column for field ")
     229                 :            :                             += ::rtl::OString(pFormFieldName->getStr(), pFormFieldName->getLength(), osl_getThreadTextEncoding())
     230                 :            :                             += ::rtl::OString("!") ).getStr() );
     231                 :            :                 }
     232                 :          0 :             }
     233                 :          0 :         }
     234                 :            :     }
     235                 :            : 
     236                 :            :     //---------------------------------------------------------------------
     237                 :          0 :     OWizardPage* OGridWizard::createPage(WizardState _nState)
     238                 :            :     {
     239                 :          0 :         switch (_nState)
     240                 :            :         {
     241                 :            :             case GW_STATE_DATASOURCE_SELECTION:
     242                 :          0 :                 return new OTableSelectionPage(this);
     243                 :            :             case GW_STATE_FIELDSELECTION:
     244                 :          0 :                 return new OGridFieldsSelection(this);
     245                 :            :         }
     246                 :            : 
     247                 :          0 :         return NULL;
     248                 :            :     }
     249                 :            : 
     250                 :            :     //---------------------------------------------------------------------
     251                 :          0 :     WizardTypes::WizardState OGridWizard::determineNextState( WizardState _nCurrentState ) const
     252                 :            :     {
     253                 :          0 :         switch (_nCurrentState)
     254                 :            :         {
     255                 :            :             case GW_STATE_DATASOURCE_SELECTION:
     256                 :          0 :                 return GW_STATE_FIELDSELECTION;
     257                 :            :             case GW_STATE_FIELDSELECTION:
     258                 :          0 :                 return WZS_INVALID_STATE;
     259                 :            :         }
     260                 :            : 
     261                 :          0 :         return WZS_INVALID_STATE;
     262                 :            :     }
     263                 :            : 
     264                 :            :     //---------------------------------------------------------------------
     265                 :          0 :     void OGridWizard::enterState(WizardState _nState)
     266                 :            :     {
     267                 :          0 :         OControlWizard::enterState(_nState);
     268                 :            : 
     269                 :          0 :         enableButtons(WZB_PREVIOUS, m_bHadDataSelection ? (GW_STATE_DATASOURCE_SELECTION < _nState) : GW_STATE_FIELDSELECTION < _nState);
     270                 :          0 :         enableButtons(WZB_NEXT, GW_STATE_FIELDSELECTION != _nState);
     271                 :          0 :         if (_nState < GW_STATE_FIELDSELECTION)
     272                 :          0 :             enableButtons(WZB_FINISH, sal_False);
     273                 :            : 
     274                 :          0 :         if (GW_STATE_FIELDSELECTION == _nState)
     275                 :          0 :             defaultButton(WZB_FINISH);
     276                 :          0 :     }
     277                 :            : 
     278                 :            :     //---------------------------------------------------------------------
     279                 :          0 :     sal_Bool OGridWizard::leaveState(WizardState _nState)
     280                 :            :     {
     281                 :          0 :         if (!OControlWizard::leaveState(_nState))
     282                 :          0 :             return sal_False;
     283                 :            : 
     284                 :          0 :         if (GW_STATE_FIELDSELECTION == _nState)
     285                 :          0 :             defaultButton(WZB_NEXT);
     286                 :            : 
     287                 :          0 :         return sal_True;
     288                 :            :     }
     289                 :            : 
     290                 :            :     //---------------------------------------------------------------------
     291                 :          0 :     sal_Bool OGridWizard::onFinish()
     292                 :            :     {
     293                 :          0 :         if ( !OControlWizard::onFinish() )
     294                 :          0 :             return sal_False;
     295                 :            : 
     296                 :          0 :         implApplySettings();
     297                 :            : 
     298                 :          0 :         return sal_True;
     299                 :            :     }
     300                 :            : 
     301                 :            :     //=====================================================================
     302                 :            :     //= OGridFieldsSelection
     303                 :            :     //=====================================================================
     304                 :            :     //---------------------------------------------------------------------
     305                 :          0 :     OGridFieldsSelection::OGridFieldsSelection( OGridWizard* _pParent )
     306                 :            :         :OGridPage(_pParent, ModuleRes(RID_PAGE_GW_FIELDSELECTION))
     307                 :            :         ,m_aFrame               (this, ModuleRes(FL_FRAME))
     308                 :            :         ,m_aExistFieldsLabel    (this, ModuleRes(FT_EXISTING_FIELDS))
     309                 :            :         ,m_aExistFields         (this, ModuleRes(LB_EXISTING_FIELDS))
     310                 :            :         ,m_aSelectOne           (this, ModuleRes(PB_FIELDRIGHT))
     311                 :            :         ,m_aSelectAll           (this, ModuleRes(PB_ALLFIELDSRIGHT))
     312                 :            :         ,m_aDeselectOne         (this, ModuleRes(PB_FIELDLEFT))
     313                 :            :         ,m_aDeselectAll         (this, ModuleRes(PB_ALLFIELDSLEFT))
     314                 :            :         ,m_aSelFieldsLabel      (this, ModuleRes(FT_SELECTED_FIELDS))
     315                 :          0 :         ,m_aSelFields           (this, ModuleRes(LB_SELECTED_FIELDS))
     316                 :            :     {
     317                 :          0 :         FreeResource();
     318                 :            : 
     319                 :          0 :         enableFormDatasourceDisplay();
     320                 :            : 
     321                 :          0 :         m_aSelectOne.SetClickHdl(LINK(this, OGridFieldsSelection, OnMoveOneEntry));
     322                 :          0 :         m_aSelectAll.SetClickHdl(LINK(this, OGridFieldsSelection, OnMoveAllEntries));
     323                 :          0 :         m_aDeselectOne.SetClickHdl(LINK(this, OGridFieldsSelection, OnMoveOneEntry));
     324                 :          0 :         m_aDeselectAll.SetClickHdl(LINK(this, OGridFieldsSelection, OnMoveAllEntries));
     325                 :            : 
     326                 :          0 :         m_aExistFields.SetSelectHdl(LINK(this, OGridFieldsSelection, OnEntrySelected));
     327                 :          0 :         m_aSelFields.SetSelectHdl(LINK(this, OGridFieldsSelection, OnEntrySelected));
     328                 :          0 :         m_aExistFields.SetDoubleClickHdl(LINK(this, OGridFieldsSelection, OnEntryDoubleClicked));
     329                 :          0 :         m_aSelFields.SetDoubleClickHdl(LINK(this, OGridFieldsSelection, OnEntryDoubleClicked));
     330                 :          0 :     }
     331                 :            : 
     332                 :            :     //---------------------------------------------------------------------
     333                 :          0 :     void OGridFieldsSelection::ActivatePage()
     334                 :            :     {
     335                 :          0 :         OGridPage::ActivatePage();
     336                 :          0 :         m_aExistFields.GrabFocus();
     337                 :          0 :     }
     338                 :            : 
     339                 :            :     //---------------------------------------------------------------------
     340                 :          0 :     bool OGridFieldsSelection::canAdvance() const
     341                 :            :     {
     342                 :          0 :         return false;
     343                 :            :             // we're the last page in our wizard
     344                 :            :     }
     345                 :            : 
     346                 :            :     //---------------------------------------------------------------------
     347                 :          0 :     void OGridFieldsSelection::initializePage()
     348                 :            :     {
     349                 :          0 :         OGridPage::initializePage();
     350                 :            : 
     351                 :          0 :         const OControlWizardContext& rContext = getContext();
     352                 :          0 :         fillListBox(m_aExistFields, rContext.aFieldNames);
     353                 :            : 
     354                 :          0 :         m_aSelFields.Clear();
     355                 :          0 :         const OGridSettings& rSettings = getSettings();
     356                 :          0 :         const ::rtl::OUString* pSelected = rSettings.aSelectedFields.getConstArray();
     357                 :          0 :         const ::rtl::OUString* pEnd = pSelected + rSettings.aSelectedFields.getLength();
     358                 :          0 :         for (; pSelected < pEnd; ++pSelected)
     359                 :            :         {
     360                 :          0 :             m_aSelFields.InsertEntry(*pSelected);
     361                 :          0 :             m_aExistFields.RemoveEntry(*pSelected);
     362                 :            :         }
     363                 :            : 
     364                 :          0 :         implCheckButtons();
     365                 :          0 :     }
     366                 :            : 
     367                 :            :     //---------------------------------------------------------------------
     368                 :          0 :     sal_Bool OGridFieldsSelection::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
     369                 :            :     {
     370                 :          0 :         if (!OGridPage::commitPage(_eReason))
     371                 :          0 :             return sal_False;
     372                 :            : 
     373                 :          0 :         OGridSettings& rSettings = getSettings();
     374                 :          0 :         sal_uInt16 nSelected = m_aSelFields.GetEntryCount();
     375                 :            : 
     376                 :          0 :         rSettings.aSelectedFields.realloc(nSelected);
     377                 :          0 :         ::rtl::OUString* pSelected = rSettings.aSelectedFields.getArray();
     378                 :            : 
     379                 :          0 :         for (sal_uInt16 i=0; i<nSelected; ++i, ++pSelected)
     380                 :          0 :             *pSelected = m_aSelFields.GetEntry(i);
     381                 :            : 
     382                 :          0 :         return sal_True;
     383                 :            :     }
     384                 :            : 
     385                 :            :     //---------------------------------------------------------------------
     386                 :          0 :     void OGridFieldsSelection::implCheckButtons()
     387                 :            :     {
     388                 :          0 :         m_aSelectOne.Enable(m_aExistFields.GetSelectEntryCount() != 0);
     389                 :          0 :         m_aSelectAll.Enable(m_aExistFields.GetEntryCount() != 0);
     390                 :            : 
     391                 :          0 :         m_aDeselectOne.Enable(m_aSelFields.GetSelectEntryCount() != 0);
     392                 :          0 :         m_aDeselectAll.Enable(m_aSelFields.GetEntryCount() != 0);
     393                 :            : 
     394                 :          0 :         getDialog()->enableButtons(WZB_FINISH, 0 != m_aSelFields.GetEntryCount());
     395                 :          0 :     }
     396                 :            : 
     397                 :            :     //---------------------------------------------------------------------
     398                 :          0 :     IMPL_LINK(OGridFieldsSelection, OnEntryDoubleClicked, ListBox*, _pList)
     399                 :            :     {
     400                 :          0 :         PushButton* pSimulateButton = &m_aExistFields == _pList ? &m_aSelectOne : &m_aDeselectOne;
     401                 :          0 :         if (pSimulateButton->IsEnabled())
     402                 :          0 :             return OnMoveOneEntry( pSimulateButton );
     403                 :            :         else
     404                 :          0 :             return 1L;
     405                 :            :     }
     406                 :            : 
     407                 :            :     //---------------------------------------------------------------------
     408                 :          0 :     IMPL_LINK(OGridFieldsSelection, OnEntrySelected, ListBox*, /*NOTINTERESTEDIN*/)
     409                 :            :     {
     410                 :          0 :         implCheckButtons();
     411                 :          0 :         return 0L;
     412                 :            :     }
     413                 :            : 
     414                 :            :     //---------------------------------------------------------------------
     415                 :          0 :     IMPL_LINK(OGridFieldsSelection, OnMoveOneEntry, PushButton*, _pButton)
     416                 :            :     {
     417                 :          0 :         sal_Bool bMoveRight = (&m_aSelectOne == _pButton);
     418                 :          0 :         ListBox& rMoveTo = bMoveRight ? m_aSelFields : m_aExistFields;
     419                 :            : 
     420                 :            :         // the index of the selected entry
     421                 :          0 :         sal_uInt16 nSelected = bMoveRight ? m_aExistFields.GetSelectEntryPos() : m_aSelFields.GetSelectEntryPos();
     422                 :            :         // the (original) relative position of the entry
     423                 :          0 :         sal_IntPtr nRelativeIndex = reinterpret_cast<sal_IntPtr>(bMoveRight ? m_aExistFields.GetEntryData(nSelected) : m_aSelFields.GetEntryData(nSelected));
     424                 :            : 
     425                 :          0 :         sal_uInt16 nInsertPos = LISTBOX_APPEND;
     426                 :          0 :         if (!bMoveRight)
     427                 :            :         {   // need to determine an insert pos which reflects the original
     428                 :          0 :             nInsertPos = 0;
     429                 :          0 :             while (nInsertPos < rMoveTo.GetEntryCount())
     430                 :            :             {
     431                 :          0 :                 if (reinterpret_cast<sal_IntPtr>(rMoveTo.GetEntryData(nInsertPos)) > nRelativeIndex)
     432                 :          0 :                     break;
     433                 :          0 :                 ++nInsertPos;
     434                 :            :             }
     435                 :            :         }
     436                 :            : 
     437                 :            :         // the text of the entry to move
     438                 :          0 :         String sMovingEntry = bMoveRight ? m_aExistFields.GetEntry(nSelected) : m_aSelFields.GetEntry(nSelected);
     439                 :            : 
     440                 :            :         // insert the entry
     441                 :          0 :         nInsertPos = rMoveTo.InsertEntry(sMovingEntry, nInsertPos);
     442                 :            :         // preserve it's "relative position" entry data
     443                 :          0 :         rMoveTo.SetEntryData(nInsertPos, reinterpret_cast<void*>(nRelativeIndex));
     444                 :            : 
     445                 :            :         // remove the entry from it's old list
     446                 :          0 :         if (bMoveRight)
     447                 :            :         {
     448                 :          0 :             sal_uInt16 nSelectPos = m_aExistFields.GetSelectEntryPos();
     449                 :          0 :             m_aExistFields.RemoveEntry(nSelected);
     450                 :          0 :             if ((LISTBOX_ENTRY_NOTFOUND != nSelectPos) && (nSelectPos < m_aExistFields.GetEntryCount()))
     451                 :          0 :                 m_aExistFields.SelectEntryPos(nSelectPos);
     452                 :            : 
     453                 :          0 :             m_aExistFields.GrabFocus();
     454                 :            :         }
     455                 :            :         else
     456                 :            :         {
     457                 :          0 :             sal_uInt16 nSelectPos = m_aSelFields.GetSelectEntryPos();
     458                 :          0 :             m_aSelFields.RemoveEntry(nSelected);
     459                 :          0 :             if ((LISTBOX_ENTRY_NOTFOUND != nSelectPos) && (nSelectPos < m_aSelFields.GetEntryCount()))
     460                 :          0 :                 m_aSelFields.SelectEntryPos(nSelectPos);
     461                 :            : 
     462                 :          0 :             m_aSelFields.GrabFocus();
     463                 :            :         }
     464                 :            : 
     465                 :          0 :         implCheckButtons();
     466                 :          0 :         return 0;
     467                 :            :     }
     468                 :            : 
     469                 :            :     //---------------------------------------------------------------------
     470                 :          0 :     IMPL_LINK(OGridFieldsSelection, OnMoveAllEntries, PushButton*, _pButton)
     471                 :            :     {
     472                 :          0 :         sal_Bool bMoveRight = (&m_aSelectAll == _pButton);
     473                 :          0 :         m_aExistFields.Clear();
     474                 :          0 :         m_aSelFields.Clear();
     475                 :          0 :         fillListBox(bMoveRight ? m_aSelFields : m_aExistFields, getContext().aFieldNames);
     476                 :            : 
     477                 :          0 :         implCheckButtons();
     478                 :          0 :         return 0;
     479                 :            :     }
     480                 :            : 
     481                 :            : //.........................................................................
     482                 :            : }   // namespace dbp
     483                 :            : //.........................................................................
     484                 :            : 
     485                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10