LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - indexdialog.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 409 0.0 %
Date: 2012-08-25 Functions: 0 42 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 854 0.0 %

           Branch data     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                 :            : 
      21                 :            : #include "indexdialog.hxx"
      22                 :            : #include "dbu_dlg.hrc"
      23                 :            : #include "dbaccess_helpid.hrc"
      24                 :            : #include "indexdialog.hrc"
      25                 :            : #include "indexfieldscontrol.hxx"
      26                 :            : #include "indexcollection.hxx"
      27                 :            : #include <vcl/msgbox.hxx>
      28                 :            : #include <com/sun/star/sdb/SQLContext.hpp>
      29                 :            : #include "UITools.hxx"
      30                 :            : #include <svtools/imgdef.hxx>
      31                 :            : #include "browserids.hxx"
      32                 :            : #include <connectivity/dbtools.hxx>
      33                 :            : #include <osl/diagnose.h>
      34                 :            : //......................................................................
      35                 :            : namespace dbaui
      36                 :            : {
      37                 :            : //......................................................................
      38                 :            : 
      39                 :            :     using namespace ::com::sun::star::uno;
      40                 :            :     using namespace ::com::sun::star::container;
      41                 :            :     using namespace ::com::sun::star::sdbc;
      42                 :            :     using namespace ::com::sun::star::sdb;
      43                 :            :     using namespace ::com::sun::star::lang;
      44                 :            :     using namespace ::dbtools;
      45                 :            : 
      46                 :            :     //==================================================================
      47                 :            :     //= helper
      48                 :            :     //==================================================================
      49                 :            :     //------------------------------------------------------------------
      50                 :          0 :     sal_Bool operator ==(const OIndexField& _rLHS, const OIndexField& _rRHS)
      51                 :            :     {
      52                 :          0 :         return  (_rLHS.sFieldName == _rRHS.sFieldName)
      53 [ #  # ][ #  # ]:          0 :             &&  (_rLHS.bSortAscending == _rRHS.bSortAscending);
      54                 :            :     }
      55                 :            : 
      56                 :            :     //------------------------------------------------------------------
      57                 :          0 :     sal_Bool operator !=(const OIndexField& _rLHS, const OIndexField& _rRHS)
      58                 :            :     {
      59                 :          0 :         return !(_rLHS == _rRHS);
      60                 :            :     }
      61                 :            : 
      62                 :            :     //------------------------------------------------------------------
      63                 :          0 :     sal_Bool operator ==(const IndexFields& _rLHS, const IndexFields& _rRHS)
      64                 :            :     {
      65         [ #  # ]:          0 :         if (_rLHS.size() != _rRHS.size())
      66                 :          0 :             return sal_False;
      67                 :            : 
      68                 :          0 :         ConstIndexFieldsIterator aLeft = _rLHS.begin();
      69                 :          0 :         ConstIndexFieldsIterator aLeftEnd = _rLHS.end();
      70                 :          0 :         ConstIndexFieldsIterator aRight = _rRHS.begin();
      71 [ #  # ][ #  # ]:          0 :         for (; aLeft != aLeftEnd; ++aLeft, ++aRight)
      72                 :            :         {
      73 [ #  # ][ #  # ]:          0 :             if (*aLeft != *aRight)
      74                 :          0 :                 return sal_False;
      75                 :            :         }
      76                 :            : 
      77                 :          0 :         return sal_True;
      78                 :            :     }
      79                 :            : 
      80                 :            :     //------------------------------------------------------------------
      81                 :          0 :     sal_Bool operator !=(const IndexFields& _rLHS, const IndexFields& _rRHS)
      82                 :            :     {
      83                 :          0 :         return !(_rLHS == _rRHS);
      84                 :            :     }
      85                 :            : 
      86                 :            :     //==================================================================
      87                 :            :     //= DbaIndexList
      88                 :            :     //==================================================================
      89                 :            :     //------------------------------------------------------------------
      90                 :          0 :     DbaIndexList::DbaIndexList(Window* _pParent, const ResId& _rId)
      91                 :            :         :SvTreeListBox(_pParent, _rId)
      92 [ #  # ][ #  # ]:          0 :         ,m_bSuspendSelectHdl(sal_False)
      93                 :            :     {
      94                 :          0 :     }
      95                 :            : 
      96                 :            :     extern sal_Bool isCharOk(sal_Unicode _cChar,sal_Bool _bFirstChar,sal_Bool _bUpperCase,const ::rtl::OUString& _sAllowedChars);
      97                 :            :     //------------------------------------------------------------------
      98                 :          0 :     sal_Bool DbaIndexList::EditedEntry( SvLBoxEntry* _pEntry, const rtl::OUString& _rNewText )
      99                 :            :     {
     100                 :            :         // first check if this is valid SQL92 name
     101 [ #  # ][ #  # ]:          0 :         if ( isSQL92CheckEnabled(m_xConnection) )
     102                 :            :         {
     103 [ #  # ][ #  # ]:          0 :             Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData();
     104         [ #  # ]:          0 :             if ( xMeta.is() )
     105                 :            :             {
     106 [ #  # ][ #  # ]:          0 :                 ::rtl::OUString sAlias = ::dbtools::convertName2SQLName(_rNewText, xMeta->getExtraNameCharacters());
                 [ #  # ]
     107 [ #  # ][ #  # ]:          0 :                 if ( ( xMeta->supportsMixedCaseQuotedIdentifiers() )
                 [ #  # ]
     108                 :            :                         ?
     109                 :          0 :                         sAlias != _rNewText
     110                 :            :                         :
     111         [ #  # ]:          0 :                 !_rNewText.equalsIgnoreAsciiCase(sAlias))
     112         [ #  # ]:          0 :                     return sal_False;
     113         [ #  # ]:          0 :             }
     114                 :            :         }
     115                 :            : 
     116 [ #  # ][ #  # ]:          0 :         if (!SvTreeListBox::EditedEntry(_pEntry, _rNewText))
     117                 :          0 :             return sal_False;
     118                 :            : 
     119         [ #  # ]:          0 :         String sOldText = GetEntryText(_pEntry);
     120 [ #  # ][ #  # ]:          0 :         SvTreeListBox::SetEntryText(_pEntry, _rNewText);
                 [ #  # ]
     121                 :            : 
     122                 :          0 :         sal_Bool bValid = sal_True;
     123 [ #  # ][ #  # ]:          0 :         if (m_aEndEditHdl.IsSet())
     124         [ #  # ]:          0 :             bValid = (0 != m_aEndEditHdl.Call(_pEntry));
     125                 :            : 
     126         [ #  # ]:          0 :         if (bValid)
     127                 :          0 :             return sal_True;
     128                 :            : 
     129         [ #  # ]:          0 :         SvTreeListBox::SetEntryText(_pEntry, sOldText);
     130                 :            : 
     131         [ #  # ]:          0 :         return sal_False;
     132                 :            :     }
     133                 :            : 
     134                 :            :     //------------------------------------------------------------------
     135                 :          0 :     void DbaIndexList::enableSelectHandler()
     136                 :            :     {
     137                 :            :         OSL_ENSURE(m_bSuspendSelectHdl, "DbaIndexList::enableSelectHandler: invalid call (this is not cumulative)!");
     138                 :          0 :         m_bSuspendSelectHdl = sal_False;
     139                 :          0 :     }
     140                 :            : 
     141                 :            :     //------------------------------------------------------------------
     142                 :          0 :     void DbaIndexList::disableSelectHandler()
     143                 :            :     {
     144                 :            :         OSL_ENSURE(!m_bSuspendSelectHdl, "DbaIndexList::enableSelectHandler: invalid call (this is not cumulative)!");
     145                 :          0 :         m_bSuspendSelectHdl = sal_True;
     146                 :          0 :     }
     147                 :            : 
     148                 :            :     //------------------------------------------------------------------
     149                 :          0 :     void DbaIndexList::SelectNoHandlerCall( SvLBoxEntry* _pEntry )
     150                 :            :     {
     151                 :          0 :         disableSelectHandler();
     152                 :          0 :         Select(_pEntry, sal_True);
     153                 :          0 :         enableSelectHandler();
     154                 :          0 :     }
     155                 :            : 
     156                 :            :     //------------------------------------------------------------------
     157                 :          0 :     sal_Bool DbaIndexList::Select( SvLBoxEntry* pEntry, sal_Bool _bSelect )
     158                 :            :     {
     159                 :          0 :         sal_Bool bReturn = SvTreeListBox::Select(pEntry, _bSelect);
     160                 :            : 
     161 [ #  # ][ #  # ]:          0 :         if (m_aSelectHdl.IsSet() && !m_bSuspendSelectHdl && _bSelect)
         [ #  # ][ #  # ]
     162                 :          0 :             m_aSelectHdl.Call(this);
     163                 :            : 
     164                 :          0 :         return bReturn;
     165                 :            :     }
     166                 :            : 
     167                 :            :     //==================================================================
     168                 :            :     //= DbaIndexDialog
     169                 :            :     //==================================================================
     170                 :            : DBG_NAME(DbaIndexDialog)
     171                 :            : //------------------------------------------------------------------
     172                 :          0 :     DbaIndexDialog::DbaIndexDialog( Window* _pParent, const Sequence< ::rtl::OUString >& _rFieldNames,
     173                 :            :                                     const Reference< XNameAccess >& _rxIndexes,
     174                 :            :                                     const Reference< XConnection >& _rxConnection,
     175                 :            :                                     const Reference< XMultiServiceFactory >& _rxORB,sal_Int32 _nMaxColumnsInIndex)
     176                 :            :         :ModalDialog( _pParent, ModuleRes(DLG_INDEXDESIGN))
     177                 :            :         ,m_xConnection(_rxConnection)
     178                 :            :         ,m_aGeometrySettings(E_DIALOG, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("dbaccess.tabledesign.indexdialog")))
     179                 :            :         ,m_aActions                         (this, ModuleRes(TLB_ACTIONS))
     180                 :            :         ,m_aIndexes                         (this, ModuleRes(CTR_INDEXLIST))
     181                 :            :         ,m_aIndexDetails                    (this, ModuleRes(FL_INDEXDETAILS))
     182                 :            :         ,m_aDescriptionLabel                (this, ModuleRes(FT_DESC_LABEL))
     183                 :            :         ,m_aDescription                     (this, ModuleRes(FT_DESCRIPTION))
     184                 :            :         ,m_aUnique                          (this, ModuleRes(CB_UNIQUE))
     185                 :            :         ,m_aFieldsLabel                     (this, ModuleRes(FT_FIELDS))
     186 [ #  # ][ #  # ]:          0 :         ,m_pFields(new IndexFieldsControl   (this, ModuleRes(CTR_FIELDS),_nMaxColumnsInIndex,::dbtools::getBooleanDataSourceSetting( m_xConnection, "AddIndexAppendix" )))
     187                 :            :         ,m_aClose                           (this, ModuleRes(PB_CLOSE))
     188                 :            :         ,m_aHelp                            (this, ModuleRes(HB_HELP))
     189                 :            :         ,m_pIndexes(NULL)
     190                 :            :         ,m_pPreviousSelection(NULL)
     191                 :            :         ,m_bEditAgain(sal_False)
     192 [ #  # ][ #  # ]:          0 :         ,m_xORB(_rxORB)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     193                 :            :     {
     194                 :            :         DBG_CTOR(DbaIndexDialog,NULL);
     195                 :            : 
     196         [ #  # ]:          0 :         FreeResource();
     197                 :            : 
     198         [ #  # ]:          0 :         m_aActions.SetSelectHdl(LINK(this, DbaIndexDialog, OnIndexAction));
     199                 :            : 
     200         [ #  # ]:          0 :         m_aIndexes.SetSelectHdl(LINK(this, DbaIndexDialog, OnIndexSelected));
     201         [ #  # ]:          0 :         m_aIndexes.SetEndEditHdl(LINK(this, DbaIndexDialog, OnEntryEdited));
     202         [ #  # ]:          0 :         m_aIndexes.SetSelectionMode(SINGLE_SELECTION);
     203         [ #  # ]:          0 :         m_aIndexes.SetHighlightRange();
     204         [ #  # ]:          0 :         m_aIndexes.setConnection(m_xConnection);
     205                 :            : 
     206         [ #  # ]:          0 :         m_pFields->Init(_rFieldNames);
     207                 :            : 
     208         [ #  # ]:          0 :         setToolBox(&m_aActions);
     209                 :            : 
     210 [ #  # ][ #  # ]:          0 :         m_pIndexes = new OIndexCollection();
     211                 :            :         try
     212                 :            :         {
     213         [ #  # ]:          0 :             m_pIndexes->attach(_rxIndexes);
     214                 :            :         }
     215   [ #  #  #  #  :          0 :         catch(SQLException& e)
                      # ]
     216                 :            :         {
     217   [ #  #  #  #  :          0 :             ::dbaui::showError(SQLExceptionInfo(e),_pParent,_rxORB);
                   #  # ]
     218                 :            :         }
     219         [ #  # ]:          0 :         catch(Exception&)
     220                 :            :         {
     221                 :            :             OSL_FAIL("DbaIndexDialog::DbaIndexDialog: could not retrieve basic information from the UNO collection!");
     222                 :            :         }
     223                 :            : 
     224         [ #  # ]:          0 :         fillIndexList();
     225                 :            : 
     226         [ #  # ]:          0 :         m_aUnique.SetClickHdl(LINK(this, DbaIndexDialog, OnModified));
     227         [ #  # ]:          0 :         m_pFields->SetModifyHdl(LINK(this, DbaIndexDialog, OnModified));
     228                 :            : 
     229         [ #  # ]:          0 :         m_aClose.SetClickHdl(LINK(this, DbaIndexDialog, OnCloseDialog));
     230                 :            : 
     231                 :            :         // if all of the indexes have an empty description, we're not interested in displaying it
     232                 :          0 :         Indexes::const_iterator aCheck;
     233                 :            : 
     234 [ #  # ][ #  # ]:          0 :         for (   aCheck = m_pIndexes->begin();
                 [ #  # ]
     235                 :          0 :                 aCheck != m_pIndexes->end();
     236                 :            :                 ++aCheck
     237                 :            :             )
     238                 :            :         {
     239         [ #  # ]:          0 :             if (!aCheck->sDescription.isEmpty())
     240                 :          0 :                 break;
     241                 :            :         }
     242                 :            : 
     243 [ #  # ][ #  # ]:          0 :         if (aCheck == m_pIndexes->end())
     244                 :            :         {
     245 [ #  # ][ #  # ]:          0 :             sal_Int32 nMoveUp = m_aUnique.GetPosPixel().Y() - m_aDescriptionLabel.GetPosPixel().Y();
     246                 :            : 
     247                 :            :             // hide the controls which are necessary for the description
     248         [ #  # ]:          0 :             m_aDescription.Hide();
     249         [ #  # ]:          0 :             m_aDescriptionLabel.Hide();
     250                 :            : 
     251                 :            :             // move other controls up
     252         [ #  # ]:          0 :             Point aPos = m_aUnique.GetPosPixel();
     253                 :          0 :             aPos.Y() -= nMoveUp;
     254         [ #  # ]:          0 :             m_aUnique.SetPosPixel(aPos);
     255                 :            : 
     256         [ #  # ]:          0 :             aPos = m_aFieldsLabel.GetPosPixel();
     257                 :          0 :             aPos.Y() -= nMoveUp;
     258         [ #  # ]:          0 :             m_aFieldsLabel.SetPosPixel(aPos);
     259                 :            : 
     260         [ #  # ]:          0 :             aPos = m_pFields->GetPosPixel();
     261                 :          0 :             aPos.Y() -= nMoveUp;
     262         [ #  # ]:          0 :             m_pFields->SetPosPixel(aPos);
     263                 :            : 
     264                 :            :             // and enlarge the fields list
     265         [ #  # ]:          0 :             Size aSize = m_pFields->GetSizePixel();
     266                 :          0 :             aSize.Height() += nMoveUp;
     267         [ #  # ]:          0 :             m_pFields->SetSizePixel(aSize);
     268                 :            :         }
     269                 :          0 :     }
     270                 :            : 
     271                 :            :     //------------------------------------------------------------------
     272                 :          0 :     void DbaIndexDialog::updateToolbox()
     273                 :            :     {
     274                 :          0 :         m_aActions.EnableItem(ID_INDEX_NEW, !m_aIndexes.IsEditingActive());
     275                 :            : 
     276                 :          0 :         SvLBoxEntry* pSelected = m_aIndexes.FirstSelected();
     277                 :          0 :         sal_Bool bSelectedAnything = NULL != pSelected;
     278                 :            : 
     279                 :            : 
     280         [ #  # ]:          0 :         if (pSelected)
     281                 :            :         {
     282                 :            :             // is the current entry modified?
     283 [ #  # ][ #  # ]:          0 :             Indexes::const_iterator aSelectedPos = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(pSelected->GetUserData());
     284 [ #  # ][ #  # ]:          0 :             m_aActions.EnableItem(ID_INDEX_SAVE, aSelectedPos->isModified() || aSelectedPos->isNew());
                 [ #  # ]
     285 [ #  # ][ #  # ]:          0 :             m_aActions.EnableItem(ID_INDEX_RESET, aSelectedPos->isModified() || aSelectedPos->isNew());
                 [ #  # ]
     286 [ #  # ][ #  # ]:          0 :             bSelectedAnything = bSelectedAnything && !aSelectedPos->bPrimaryKey;
     287                 :            :         }
     288                 :            :         else
     289                 :            :         {
     290                 :          0 :             m_aActions.EnableItem(ID_INDEX_SAVE, sal_False);
     291                 :          0 :             m_aActions.EnableItem(ID_INDEX_RESET, sal_False);
     292                 :            :         }
     293                 :          0 :         m_aActions.EnableItem(ID_INDEX_DROP, bSelectedAnything);
     294                 :          0 :         m_aActions.EnableItem(ID_INDEX_RENAME, bSelectedAnything);
     295                 :          0 :     }
     296                 :            : 
     297                 :            :     //------------------------------------------------------------------
     298                 :          0 :     void DbaIndexDialog::fillIndexList()
     299                 :            :     {
     300 [ #  # ][ #  # ]:          0 :         Image aPKeyIcon(ModuleRes( IMG_PKEYICON ));
     301                 :            :         // fill the list with the index names
     302         [ #  # ]:          0 :         m_aIndexes.Clear();
     303                 :          0 :         Indexes::iterator aIndexLoop = m_pIndexes->begin();
     304                 :          0 :         Indexes::iterator aEnd = m_pIndexes->end();
     305 [ #  # ][ #  # ]:          0 :         for (; aIndexLoop != aEnd; ++aIndexLoop)
     306                 :            :         {
     307                 :          0 :             SvLBoxEntry* pNewEntry = NULL;
     308         [ #  # ]:          0 :             if (aIndexLoop->bPrimaryKey)
     309 [ #  # ][ #  # ]:          0 :                 pNewEntry = m_aIndexes.InsertEntry(aIndexLoop->sName, aPKeyIcon, aPKeyIcon);
                 [ #  # ]
     310                 :            :             else
     311 [ #  # ][ #  # ]:          0 :                 pNewEntry = m_aIndexes.InsertEntry(aIndexLoop->sName);
                 [ #  # ]
     312                 :            : 
     313         [ #  # ]:          0 :             pNewEntry->SetUserData(reinterpret_cast< void* >(sal_Int32(aIndexLoop - m_pIndexes->begin())));
     314                 :            :         }
     315                 :            : 
     316 [ #  # ][ #  # ]:          0 :         OnIndexSelected(&m_aIndexes);
     317                 :          0 :     }
     318                 :            : 
     319                 :            :     //------------------------------------------------------------------
     320 [ #  # ][ #  # ]:          0 :     DbaIndexDialog::~DbaIndexDialog( )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     321                 :            :     {
     322         [ #  # ]:          0 :         setToolBox(NULL);
     323 [ #  # ][ #  # ]:          0 :         delete m_pIndexes;
     324 [ #  # ][ #  # ]:          0 :         delete m_pFields;
     325                 :            : 
     326                 :            :         DBG_DTOR(DbaIndexDialog,NULL);
     327         [ #  # ]:          0 :     }
     328                 :            : 
     329                 :            :     //------------------------------------------------------------------
     330                 :          0 :     sal_Bool DbaIndexDialog::implCommit(SvLBoxEntry* _pEntry)
     331                 :            :     {
     332                 :            :         OSL_ENSURE(_pEntry, "DbaIndexDialog::implCommit: invalid entry!");
     333                 :            : 
     334         [ #  # ]:          0 :         Indexes::iterator aCommitPos = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(_pEntry->GetUserData());
     335                 :            : 
     336                 :            :         // if it's not a new index, remove it
     337                 :            :         // (we can't modify indexes, only drop'n'insert)
     338         [ #  # ]:          0 :         if (!aCommitPos->isNew())
     339 [ #  # ][ #  # ]:          0 :             if (!implDropIndex(_pEntry, sal_False))
     340                 :          0 :                 return sal_False;
     341                 :            : 
     342                 :            :         // create the new index
     343         [ #  # ]:          0 :         SQLExceptionInfo aExceptionInfo;
     344                 :            :         try
     345                 :            :         {
     346         [ #  # ]:          0 :             m_pIndexes->commitNewIndex(aCommitPos);
     347                 :            :         }
     348   [ #  #  #  #  :          0 :         catch(SQLContext& e) { aExceptionInfo = SQLExceptionInfo(e); }
             #  #  #  # ]
     349   [ #  #  #  #  :          0 :         catch(SQLWarning& e) { aExceptionInfo = SQLExceptionInfo(e); }
             #  #  #  # ]
     350   [ #  #  #  #  :          0 :         catch(SQLException& e) { aExceptionInfo = SQLExceptionInfo(e); }
          #  #  #  #  #  
                #  #  # ]
     351                 :            : 
     352                 :            :         // reflect the new selection in the toolbox
     353         [ #  # ]:          0 :         updateToolbox();
     354                 :            : 
     355         [ #  # ]:          0 :         if (aExceptionInfo.isValid())
     356         [ #  # ]:          0 :             showError(aExceptionInfo, this, m_xORB);
     357                 :            :         else
     358                 :            :         {
     359                 :          0 :             m_aUnique.SaveValue();
     360         [ #  # ]:          0 :             m_pFields->SaveValue();
     361                 :            :         }
     362                 :            : 
     363         [ #  # ]:          0 :         return !aExceptionInfo.isValid();
     364                 :            :     }
     365                 :            : 
     366                 :            :     //------------------------------------------------------------------
     367                 :          0 :     void DbaIndexDialog::OnNewIndex()
     368                 :            :     {
     369                 :            :         // commit the current entry, if necessary
     370 [ #  # ][ #  # ]:          0 :         if (!implCommitPreviouslySelected())
     371                 :            :             return;
     372                 :            : 
     373                 :            :         // get a new unique name for the new index
     374         [ #  # ]:          0 :         String sNewIndexName;
     375 [ #  # ][ #  # ]:          0 :         const String sNewIndexNameBase(ModuleRes(STR_LOGICAL_INDEX_NAME));
     376                 :            :         sal_Int32 i;
     377                 :            : 
     378         [ #  # ]:          0 :         for ( i = 1; i < 0x7FFFFFFF; ++i )
     379                 :            :         {
     380         [ #  # ]:          0 :             sNewIndexName = sNewIndexNameBase;
     381 [ #  # ][ #  # ]:          0 :             sNewIndexName += String::CreateFromInt32(i);
                 [ #  # ]
     382 [ #  # ][ #  # ]:          0 :             if (m_pIndexes->end() == m_pIndexes->find(sNewIndexName))
                 [ #  # ]
     383                 :          0 :                 break;
     384                 :            :         }
     385         [ #  # ]:          0 :         if ((i>0x7FFFFFFF) || (i<0))
     386                 :            :         {
     387                 :            :             OSL_FAIL("DbaIndexDialog::OnNewIndex: no free index name found!");
     388                 :            :             // can't do anything ... of course we try another base, but this could end with the same result ...
     389                 :            :             return;
     390                 :            :         }
     391                 :            : 
     392         [ #  # ]:          0 :         SvLBoxEntry* pNewEntry = m_aIndexes.InsertEntry(sNewIndexName);
     393         [ #  # ]:          0 :         m_pIndexes->insert(sNewIndexName);
     394                 :            : 
     395                 :            :         // update the user data on the entries in the list box:
     396                 :            :         // they're iterators of the index collection, and thus they have changed when removing the index
     397 [ #  # ][ #  # ]:          0 :         for (SvLBoxEntry* pAdjust = m_aIndexes.First(); pAdjust; pAdjust = m_aIndexes.Next(pAdjust))
                 [ #  # ]
     398                 :            :         {
     399 [ #  # ][ #  # ]:          0 :             Indexes::iterator aAfterInsertPos = m_pIndexes->find(m_aIndexes.GetEntryText(pAdjust));
                 [ #  # ]
     400                 :            :             OSL_ENSURE(aAfterInsertPos != m_pIndexes->end(), "DbaIndexDialog::OnNewIndex: problems with on of the entries!");
     401         [ #  # ]:          0 :             pAdjust->SetUserData(reinterpret_cast< void* >(sal_Int32(aAfterInsertPos - m_pIndexes->begin())));
     402                 :            :         }
     403                 :            : 
     404                 :            :         // select the entry and start in-place editing
     405         [ #  # ]:          0 :         m_aIndexes.SelectNoHandlerCall(pNewEntry);
     406         [ #  # ]:          0 :         OnIndexSelected(&m_aIndexes);
     407         [ #  # ]:          0 :         m_aIndexes.EditEntry(pNewEntry);
     408 [ #  # ][ #  # ]:          0 :         updateToolbox();
         [ #  # ][ #  # ]
                 [ #  # ]
     409                 :            :     }
     410                 :            : 
     411                 :            :     //------------------------------------------------------------------
     412                 :          0 :     void DbaIndexDialog::OnDropIndex(sal_Bool _bConfirm)
     413                 :            :     {
     414                 :            :         // the selected index
     415                 :          0 :         SvLBoxEntry* pSelected = m_aIndexes.FirstSelected();
     416                 :            :         OSL_ENSURE(pSelected, "DbaIndexDialog::OnDropIndex: invalid call!");
     417         [ #  # ]:          0 :         if (pSelected)
     418                 :            :         {
     419                 :            :             // let the user confirm the drop
     420         [ #  # ]:          0 :             if (_bConfirm)
     421                 :            :             {
     422 [ #  # ][ #  # ]:          0 :                 String sConfirm(ModuleRes(STR_CONFIRM_DROP_INDEX));
     423 [ #  # ][ #  # ]:          0 :                 sConfirm.SearchAndReplaceAscii("$name$", m_aIndexes.GetEntryText(pSelected));
                 [ #  # ]
     424         [ #  # ]:          0 :                 QueryBox aConfirm(this, WB_YES_NO, sConfirm);
     425 [ #  # ][ #  # ]:          0 :                 if (RET_YES != aConfirm.Execute())
     426 [ #  # ][ #  # ]:          0 :                     return;
         [ #  # ][ #  # ]
     427                 :            :             }
     428                 :            : 
     429                 :            :             // do the drop
     430                 :          0 :             implDropIndex(pSelected, sal_True);
     431                 :            : 
     432                 :            :             // reflect the new selection in the toolbox
     433                 :          0 :             updateToolbox();
     434                 :            :         }
     435                 :            :     }
     436                 :            : 
     437                 :            :     //------------------------------------------------------------------
     438                 :          0 :     sal_Bool DbaIndexDialog::implDropIndex(SvLBoxEntry* _pEntry, sal_Bool _bRemoveFromCollection)
     439                 :            :     {
     440                 :            :         // do the drop
     441         [ #  # ]:          0 :         Indexes::iterator aDropPos = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(_pEntry->GetUserData());
     442                 :            :         OSL_ENSURE(aDropPos != m_pIndexes->end(), "DbaIndexDialog::OnDropIndex: did not find the index in my collection!");
     443                 :            : 
     444         [ #  # ]:          0 :         SQLExceptionInfo aExceptionInfo;
     445                 :          0 :         sal_Bool bSuccess = sal_False;
     446                 :            :         try
     447                 :            :         {
     448         [ #  # ]:          0 :             if (_bRemoveFromCollection)
     449         [ #  # ]:          0 :                 bSuccess = m_pIndexes->drop(aDropPos);
     450                 :            :             else
     451         [ #  # ]:          0 :                 bSuccess = m_pIndexes->dropNoRemove(aDropPos);
     452                 :            :         }
     453   [ #  #  #  #  :          0 :         catch(SQLContext& e) { aExceptionInfo = SQLExceptionInfo(e); }
             #  #  #  # ]
     454   [ #  #  #  #  :          0 :         catch(SQLWarning& e) { aExceptionInfo = SQLExceptionInfo(e); }
             #  #  #  # ]
     455   [ #  #  #  #  :          0 :         catch(SQLException& e) { aExceptionInfo = SQLExceptionInfo(e); }
          #  #  #  #  #  
                #  #  # ]
     456                 :            : 
     457         [ #  # ]:          0 :         if (aExceptionInfo.isValid())
     458         [ #  # ]:          0 :             showError(aExceptionInfo, this, m_xORB);
     459 [ #  # ][ #  # ]:          0 :         else if (bSuccess && _bRemoveFromCollection)
     460                 :            :         {
     461                 :          0 :             SvLBoxTreeList* pModel = m_aIndexes.GetModel();
     462                 :            : 
     463                 :          0 :             m_aIndexes.disableSelectHandler();
     464         [ #  # ]:          0 :             pModel->Remove(_pEntry);
     465                 :          0 :             m_aIndexes.enableSelectHandler();
     466                 :            : 
     467                 :            :             // update the user data on the entries in the list box:
     468                 :            :             // they're iterators of the index collection, and thus they have changed when removing the index
     469 [ #  # ][ #  # ]:          0 :             for (SvLBoxEntry* pAdjust = m_aIndexes.First(); pAdjust; pAdjust = m_aIndexes.Next(pAdjust))
                 [ #  # ]
     470                 :            :             {
     471 [ #  # ][ #  # ]:          0 :                 Indexes::iterator aAfterDropPos = m_pIndexes->find(m_aIndexes.GetEntryText(pAdjust));
                 [ #  # ]
     472                 :            :                 OSL_ENSURE(aAfterDropPos != m_pIndexes->end(), "DbaIndexDialog::OnDropIndex: problems with on of the remaining entries!");
     473         [ #  # ]:          0 :                 pAdjust->SetUserData(reinterpret_cast< void* >(sal_Int32(aAfterDropPos - m_pIndexes->begin())));
     474                 :            :             }
     475                 :            : 
     476                 :            :             // if the remvoved entry was the selected on ...
     477         [ #  # ]:          0 :             if (m_pPreviousSelection == _pEntry)
     478                 :          0 :                 m_pPreviousSelection = NULL;
     479                 :            : 
     480                 :            :             // the Remove automatically selected another entry (if possible), but we disabled the calling of the handler
     481                 :            :             // to prevent that we missed something ... call the handler directly
     482         [ #  # ]:          0 :             OnIndexSelected(&m_aIndexes);
     483                 :            :         }
     484                 :            : 
     485         [ #  # ]:          0 :         return !aExceptionInfo.isValid();
     486                 :            :     }
     487                 :            : 
     488                 :            :     //------------------------------------------------------------------
     489                 :          0 :     void DbaIndexDialog::OnRenameIndex()
     490                 :            :     {
     491                 :            :         // the selected index
     492                 :          0 :         SvLBoxEntry* pSelected = m_aIndexes.FirstSelected();
     493                 :            :         OSL_ENSURE(pSelected, "DbaIndexDialog::OnRenameIndex: invalid call!");
     494                 :            : 
     495                 :            :         // save the changes made 'til here
     496                 :            :         // Upon leaving the edit mode, the control will be re-initialized with the
     497                 :            :         // settings from the current entry
     498                 :          0 :         implSaveModified(sal_False);
     499                 :            : 
     500                 :          0 :         m_aIndexes.EditEntry(pSelected);
     501                 :          0 :         updateToolbox();
     502                 :          0 :     }
     503                 :            : 
     504                 :            :     //------------------------------------------------------------------
     505                 :          0 :     void DbaIndexDialog::OnSaveIndex()
     506                 :            :     {
     507                 :            :         // the selected index
     508                 :            : #if OSL_DEBUG_LEVEL > 0
     509                 :            :         SvLBoxEntry* pSelected = m_aIndexes.FirstSelected();
     510                 :            :         OSL_ENSURE( pSelected, "DbaIndexDialog::OnSaveIndex: invalid call!" );
     511                 :            : #endif
     512                 :            : 
     513                 :          0 :         implCommitPreviouslySelected();
     514                 :          0 :         updateToolbox();
     515                 :          0 :     }
     516                 :            : 
     517                 :            :     //------------------------------------------------------------------
     518                 :          0 :     void DbaIndexDialog::OnResetIndex()
     519                 :            :     {
     520                 :            :         // the selected index
     521         [ #  # ]:          0 :         SvLBoxEntry* pSelected = m_aIndexes.FirstSelected();
     522                 :            :         OSL_ENSURE(pSelected, "DbaIndexDialog::OnResetIndex: invalid call!");
     523                 :            : 
     524         [ #  # ]:          0 :         Indexes::iterator aResetPos = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(pSelected->GetUserData());
     525                 :            : 
     526         [ #  # ]:          0 :         if (aResetPos->isNew())
     527                 :            :         {
     528         [ #  # ]:          0 :             OnDropIndex(sal_False);
     529                 :          0 :             return;
     530                 :            :         }
     531                 :            : 
     532         [ #  # ]:          0 :         SQLExceptionInfo aExceptionInfo;
     533                 :            :         try
     534                 :            :         {
     535         [ #  # ]:          0 :             m_pIndexes->resetIndex(aResetPos);
     536                 :            :         }
     537   [ #  #  #  #  :          0 :         catch(SQLContext& e) { aExceptionInfo = SQLExceptionInfo(e); }
             #  #  #  # ]
     538   [ #  #  #  #  :          0 :         catch(SQLWarning& e) { aExceptionInfo = SQLExceptionInfo(e); }
             #  #  #  # ]
     539   [ #  #  #  #  :          0 :         catch(SQLException& e) { aExceptionInfo = SQLExceptionInfo(e); }
          #  #  #  #  #  
                #  #  # ]
     540                 :            : 
     541         [ #  # ]:          0 :         if (aExceptionInfo.isValid())
     542         [ #  # ]:          0 :             showError(aExceptionInfo, this, m_xORB);
     543                 :            :         else
     544 [ #  # ][ #  # ]:          0 :             m_aIndexes.SetEntryText(pSelected, aResetPos->sName);
                 [ #  # ]
     545                 :            : 
     546         [ #  # ]:          0 :         updateControls(pSelected);
     547 [ #  # ][ #  # ]:          0 :         updateToolbox();
     548                 :            :     }
     549                 :            : 
     550                 :            :     //------------------------------------------------------------------
     551                 :          0 :     IMPL_LINK( DbaIndexDialog, OnIndexAction, ToolBox*, /*NOTINTERESTEDIN*/ )
     552                 :            :     {
     553                 :          0 :         sal_uInt16 nClicked = m_aActions.GetCurItemId();
     554   [ #  #  #  #  :          0 :         switch (nClicked)
                   #  # ]
     555                 :            :         {
     556                 :            :             case ID_INDEX_NEW:
     557                 :          0 :                 OnNewIndex();
     558                 :          0 :                 break;
     559                 :            :             case ID_INDEX_DROP:
     560                 :          0 :                 OnDropIndex();
     561                 :          0 :                 break;
     562                 :            :             case ID_INDEX_RENAME:
     563                 :          0 :                 OnRenameIndex();
     564                 :          0 :                 break;
     565                 :            :             case ID_INDEX_SAVE:
     566                 :          0 :                 OnSaveIndex();
     567                 :          0 :                 break;
     568                 :            :             case ID_INDEX_RESET:
     569                 :          0 :                 OnResetIndex();
     570                 :          0 :                 break;
     571                 :            :         }
     572                 :          0 :         return 0L;
     573                 :            :     }
     574                 :            : 
     575                 :            :     //------------------------------------------------------------------
     576                 :          0 :     IMPL_LINK( DbaIndexDialog, OnCloseDialog, void*, /*NOTINTERESTEDIN*/ )
     577                 :            :     {
     578         [ #  # ]:          0 :         if (m_aIndexes.IsEditingActive())
     579                 :            :         {
     580                 :            :             OSL_ENSURE(!m_bEditAgain, "DbaIndexDialog::OnCloseDialog: somebody was faster than hell!");
     581                 :            :                 // this means somebody entered a new name, which was invalid, which cause us to posted us an event,
     582                 :            :                 // and before the event arrived the user clicked onto "close". VERY fast, this user ....
     583                 :          0 :             m_aIndexes.EndEditing(sal_False);
     584         [ #  # ]:          0 :             if (m_bEditAgain)
     585                 :            :                 // could not commit the new name (started a new - asynchronous - edit trial)
     586                 :          0 :                 return 1L;
     587                 :            :         }
     588                 :            : 
     589                 :            :         // the currently selected entry
     590                 :          0 :         const SvLBoxEntry* pSelected = m_aIndexes.FirstSelected();
     591                 :            :         OSL_ENSURE(pSelected == m_pPreviousSelection, "DbaIndexDialog::OnCloseDialog: inconsistence!");
     592                 :            : 
     593                 :          0 :         sal_Int32 nResponse = RET_NO;
     594         [ #  # ]:          0 :         if (pSelected)
     595                 :            :         {
     596                 :            :             // the descriptor
     597 [ #  # ][ #  # ]:          0 :             Indexes::const_iterator aSelected = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(pSelected->GetUserData());
     598                 :            : 
     599 [ #  # ][ #  # ]:          0 :             if (aSelected->isModified() || aSelected->isNew())
                 [ #  # ]
     600                 :            :             {
     601 [ #  # ][ #  # ]:          0 :                 QueryBox aQuestion(this, ModuleRes(QUERY_SAVE_CURRENT_INDEX));
     602 [ #  # ][ #  # ]:          0 :                 nResponse = aQuestion.Execute();
     603                 :            :             }
     604                 :            :         }
     605                 :            : 
     606      [ #  #  # ]:          0 :         switch (nResponse)
     607                 :            :         {
     608                 :            :             case RET_YES:
     609         [ #  # ]:          0 :                 if (!implCommitPreviouslySelected())
     610                 :          0 :                     return 1L;
     611                 :          0 :                 break;
     612                 :            :             case RET_NO:
     613                 :          0 :                 break;
     614                 :            :             default:
     615                 :          0 :                 return 1L;
     616                 :            :         }
     617                 :            : 
     618                 :          0 :         EndDialog(RET_OK);
     619                 :            : 
     620                 :          0 :         return 0L;
     621                 :            :     }
     622                 :            : 
     623                 :            :     //------------------------------------------------------------------
     624                 :          0 :     IMPL_LINK( DbaIndexDialog, OnEditIndexAgain, SvLBoxEntry*, _pEntry )
     625                 :            :     {
     626                 :          0 :         m_bEditAgain = sal_False;
     627                 :          0 :         m_aIndexes.EditEntry(_pEntry);
     628                 :          0 :         return 0L;
     629                 :            :     }
     630                 :            : 
     631                 :            :     //------------------------------------------------------------------
     632                 :          0 :     IMPL_LINK( DbaIndexDialog, OnEntryEdited, SvLBoxEntry*, _pEntry )
     633                 :            :     {
     634         [ #  # ]:          0 :         Indexes::iterator aPosition = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(_pEntry->GetUserData());
     635                 :            : 
     636                 :            :         OSL_ENSURE(aPosition >= m_pIndexes->begin() && aPosition < m_pIndexes->end(),
     637                 :            :             "DbaIndexDialog::OnEntryEdited: invalid entry!");
     638                 :            : 
     639         [ #  # ]:          0 :         String sNewName = m_aIndexes.GetEntryText(_pEntry);
     640                 :            : 
     641 [ #  # ][ #  # ]:          0 :         Indexes::const_iterator aSameName = m_pIndexes->find(sNewName);
     642 [ #  # ][ #  # ]:          0 :         if ((aSameName != aPosition) && (m_pIndexes->end() != aSameName))
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
     643                 :            :         {
     644 [ #  # ][ #  # ]:          0 :             String sError(ModuleRes(STR_INDEX_NAME_ALREADY_USED));
     645         [ #  # ]:          0 :             sError.SearchAndReplaceAscii("$name$", sNewName);
     646         [ #  # ]:          0 :             ErrorBox aError(this, WB_OK, sError);
     647         [ #  # ]:          0 :             aError.Execute();
     648                 :            : 
     649         [ #  # ]:          0 :             updateToolbox();
     650                 :          0 :             m_bEditAgain = sal_True;
     651 [ #  # ][ #  # ]:          0 :             PostUserEvent(LINK(this, DbaIndexDialog, OnEditIndexAgain), _pEntry);
     652 [ #  # ][ #  # ]:          0 :             return 0L;
     653                 :            :         }
     654                 :            : 
     655         [ #  # ]:          0 :         aPosition->sName = sNewName;
     656                 :            : 
     657                 :            :         // rename can be done by a drop/insert combination only
     658         [ #  # ]:          0 :         if (aPosition->isNew())
     659                 :            :         {
     660         [ #  # ]:          0 :             updateToolbox();
     661                 :            :             // no commitment needed here ....
     662                 :          0 :             return 1L;
     663                 :            :         }
     664                 :            : 
     665         [ #  # ]:          0 :         if (aPosition->sName != aPosition->getOriginalName())
     666                 :            :         {
     667                 :          0 :             aPosition->setModified(sal_True);
     668         [ #  # ]:          0 :             updateToolbox();
     669                 :            :         }
     670                 :            : 
     671         [ #  # ]:          0 :         return 1L;
     672                 :            :     }
     673                 :            : 
     674                 :            :     //------------------------------------------------------------------
     675                 :          0 :     sal_Bool DbaIndexDialog::implSaveModified(sal_Bool _bPlausibility)
     676                 :            :     {
     677         [ #  # ]:          0 :         if (m_pPreviousSelection)
     678                 :            :         {
     679                 :            :             // try to commit the previously selected index
     680 [ #  # ][ #  # ]:          0 :             if (m_pFields->IsModified() && !m_pFields->SaveModified())
         [ #  # ][ #  # ]
                 [ #  # ]
     681                 :          0 :                 return sal_False;
     682                 :            : 
     683         [ #  # ]:          0 :             Indexes::iterator aPreviouslySelected = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(m_pPreviousSelection->GetUserData());
     684                 :            : 
     685                 :            :             // the unique flag
     686         [ #  # ]:          0 :             aPreviouslySelected->bUnique = m_aUnique.IsChecked();
     687         [ #  # ]:          0 :             if (m_aUnique.GetSavedValue() != m_aUnique.GetState())
     688                 :          0 :                 aPreviouslySelected->setModified(sal_True);
     689                 :            : 
     690                 :            :             // the fields
     691         [ #  # ]:          0 :             m_pFields->commitTo(aPreviouslySelected->aFields);
     692 [ #  # ][ #  # ]:          0 :             if (m_pFields->GetSavedValue() != aPreviouslySelected->aFields)
     693                 :          0 :                 aPreviouslySelected->setModified(sal_True);
     694                 :            : 
     695                 :            :             // plausibility checks
     696 [ #  # ][ #  # ]:          0 :             if (_bPlausibility && !implCheckPlausibility(aPreviouslySelected))
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
     697                 :          0 :                 return sal_False;
     698                 :            :         }
     699                 :            : 
     700                 :          0 :         return sal_True;
     701                 :            :     }
     702                 :            : 
     703                 :            :     //------------------------------------------------------------------
     704                 :          0 :     sal_Bool DbaIndexDialog::implCheckPlausibility(const ConstIndexesIterator& _rPos)
     705                 :            :     {
     706                 :            :         // need at least one field
     707         [ #  # ]:          0 :         if (0 == _rPos->aFields.size())
     708                 :            :         {
     709 [ #  # ][ #  # ]:          0 :             ErrorBox aError(this, ModuleRes(ERR_NEED_INDEX_FIELDS));
     710         [ #  # ]:          0 :             aError.Execute();
     711         [ #  # ]:          0 :             m_pFields->GrabFocus();
     712         [ #  # ]:          0 :             return sal_False;
     713                 :            :         }
     714                 :            : 
     715                 :            :         // no double fields
     716                 :            :         DECLARE_STL_STDKEY_SET( String, StringBag );
     717         [ #  # ]:          0 :         StringBag aExistentFields;
     718 [ #  # ][ #  # ]:          0 :         for (   ConstIndexFieldsIterator aFieldCheck = _rPos->aFields.begin();
     719                 :          0 :                 aFieldCheck != _rPos->aFields.end();
     720                 :            :                 ++aFieldCheck
     721                 :            :             )
     722                 :            :         {
     723 [ #  # ][ #  # ]:          0 :             if (aExistentFields.end() != aExistentFields.find(aFieldCheck->sFieldName))
                 [ #  # ]
     724                 :            :             {
     725                 :            :                 // a column is specified twice ... won't work anyway, so prevent this here and now
     726 [ #  # ][ #  # ]:          0 :                 String sMessage(ModuleRes(STR_INDEXDESIGN_DOUBLE_COLUMN_NAME));
     727         [ #  # ]:          0 :                 sMessage.SearchAndReplaceAscii("$name$", aFieldCheck->sFieldName);
     728         [ #  # ]:          0 :                 ErrorBox aError(this, WB_OK, sMessage);
     729         [ #  # ]:          0 :                 aError.Execute();
     730         [ #  # ]:          0 :                 m_pFields->GrabFocus();
     731 [ #  # ][ #  # ]:          0 :                 return sal_False;
     732                 :            :             }
     733         [ #  # ]:          0 :             aExistentFields.insert(aFieldCheck->sFieldName);
     734                 :            :         }
     735                 :            : 
     736                 :          0 :         return sal_True;
     737                 :            :     }
     738                 :            : 
     739                 :            :     //------------------------------------------------------------------
     740                 :          0 :     sal_Bool DbaIndexDialog::implCommitPreviouslySelected()
     741                 :            :     {
     742         [ #  # ]:          0 :         if (m_pPreviousSelection)
     743                 :            :         {
     744         [ #  # ]:          0 :             Indexes::iterator aPreviouslySelected = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(m_pPreviousSelection->GetUserData());
     745                 :            : 
     746 [ #  # ][ #  # ]:          0 :             if (!implSaveModified())
     747                 :          0 :                 return sal_False;
     748                 :            : 
     749                 :            :             // commit the index (if necessary)
     750 [ #  # ][ #  # ]:          0 :             if (aPreviouslySelected->isModified() && !implCommit(m_pPreviousSelection))
         [ #  # ][ #  # ]
     751                 :          0 :                 return sal_False;
     752                 :            :         }
     753                 :            : 
     754                 :          0 :         return sal_True;
     755                 :            :     }
     756                 :            : 
     757                 :            :     //------------------------------------------------------------------
     758                 :          0 :     IMPL_LINK( DbaIndexDialog, OnModified, void*, /*NOTINTERESTEDIN*/ )
     759                 :            :     {
     760                 :            :         OSL_ENSURE(m_pPreviousSelection, "DbaIndexDialog, OnModified: invalid call!");
     761         [ #  # ]:          0 :         Indexes::iterator aPosition = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(m_pPreviousSelection->GetUserData());
     762                 :            : 
     763                 :          0 :         aPosition->setModified(sal_True);
     764         [ #  # ]:          0 :         updateToolbox();
     765                 :            : 
     766                 :          0 :         return 1L;
     767                 :            :     }
     768                 :            : 
     769                 :            :     //------------------------------------------------------------------
     770                 :          0 :     void DbaIndexDialog::updateControls(const SvLBoxEntry* _pEntry)
     771                 :            :     {
     772         [ #  # ]:          0 :         if (_pEntry)
     773                 :            :         {
     774                 :            :             // the descriptor of the selected index
     775 [ #  # ][ #  # ]:          0 :             Indexes::const_iterator aSelectedIndex = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(_pEntry->GetUserData());
     776                 :            : 
     777                 :            :             // fill the controls
     778         [ #  # ]:          0 :             m_aUnique.Check(aSelectedIndex->bUnique);
     779         [ #  # ]:          0 :             m_aUnique.Enable(!aSelectedIndex->bPrimaryKey);
     780                 :          0 :             m_aUnique.SaveValue();
     781                 :            : 
     782         [ #  # ]:          0 :             m_pFields->initializeFrom(aSelectedIndex->aFields);
     783         [ #  # ]:          0 :             m_pFields->Enable(!aSelectedIndex->bPrimaryKey);
     784         [ #  # ]:          0 :             m_pFields->SaveValue();
     785                 :            : 
     786 [ #  # ][ #  # ]:          0 :             m_aDescription.SetText(aSelectedIndex->sDescription);
                 [ #  # ]
     787         [ #  # ]:          0 :             m_aDescription.Enable(!aSelectedIndex->bPrimaryKey);
     788                 :            : 
     789         [ #  # ]:          0 :             m_aDescriptionLabel.Enable(!aSelectedIndex->bPrimaryKey);
     790                 :            :         }
     791                 :            :         else
     792                 :            :         {
     793                 :          0 :             m_aUnique.Check(sal_False);
     794         [ #  # ]:          0 :             m_pFields->initializeFrom(IndexFields());
     795         [ #  # ]:          0 :             m_aDescription.SetText(String());
     796                 :            :         }
     797                 :          0 :     }
     798                 :            : 
     799                 :            :     //------------------------------------------------------------------
     800                 :          0 :     IMPL_LINK( DbaIndexDialog, OnIndexSelected, DbaIndexList*, /*NOTINTERESTEDIN*/ )
     801                 :            :     {
     802                 :          0 :         m_aIndexes.EndSelection();
     803                 :            : 
     804         [ #  # ]:          0 :         if (m_aIndexes.IsEditingActive())
     805                 :          0 :             m_aIndexes.EndEditing(sal_False);
     806                 :            : 
     807                 :            :         // commit the old data
     808         [ #  # ]:          0 :         if (m_aIndexes.FirstSelected() != m_pPreviousSelection)
     809                 :            :         {   // (this call may happen in case somebody ended an in-place edit with 'return', so we need to check this before committing)
     810         [ #  # ]:          0 :             if (!implCommitPreviouslySelected())
     811                 :            :             {
     812                 :          0 :                 m_aIndexes.SelectNoHandlerCall(m_pPreviousSelection);
     813                 :          0 :                 return 1L;
     814                 :            :             }
     815                 :            :         }
     816                 :            : 
     817                 :          0 :         sal_Bool bHaveSelection = (NULL != m_aIndexes.FirstSelected());
     818                 :            : 
     819                 :            :         // disable/enable the detail controls
     820                 :          0 :         m_aIndexDetails.Enable(bHaveSelection);
     821                 :          0 :         m_aUnique.Enable(bHaveSelection);
     822                 :          0 :         m_aDescriptionLabel.Enable(bHaveSelection);
     823                 :          0 :         m_aFieldsLabel.Enable(bHaveSelection);
     824                 :          0 :         m_pFields->Enable(bHaveSelection);
     825                 :            : 
     826                 :          0 :         SvLBoxEntry* pNewSelection = m_aIndexes.FirstSelected();
     827                 :          0 :         updateControls(pNewSelection);
     828         [ #  # ]:          0 :         if (bHaveSelection)
     829                 :          0 :             m_aIndexes.GrabFocus();
     830                 :            : 
     831                 :          0 :         m_pPreviousSelection = pNewSelection;
     832                 :            : 
     833                 :          0 :         updateToolbox();
     834                 :          0 :         return 0L;
     835                 :            :     }
     836                 :            :     // -----------------------------------------------------------------------------
     837                 :          0 :     void DbaIndexDialog::StateChanged( StateChangedType nType )
     838                 :            :     {
     839                 :          0 :         ModalDialog::StateChanged( nType );
     840                 :            : 
     841         [ #  # ]:          0 :         if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
     842                 :            :         {
     843                 :            :             // Check if we need to get new images for normal/high contrast mode
     844                 :          0 :             checkImageList();
     845                 :            :         }
     846         [ #  # ]:          0 :         else if ( nType == STATE_CHANGE_TEXT )
     847                 :            :         {
     848                 :            :             // The physical toolbar changed its outlook and shows another logical toolbar!
     849                 :            :             // We have to set the correct high contrast mode on the new tbx manager.
     850                 :            :             //  pMgr->SetHiContrast( IsHiContrastMode() );
     851                 :          0 :             checkImageList();
     852                 :            :         }
     853                 :          0 :     }
     854                 :            :     // -----------------------------------------------------------------------------
     855                 :          0 :     void DbaIndexDialog::DataChanged( const DataChangedEvent& rDCEvt )
     856                 :            :     {
     857                 :          0 :         ModalDialog::DataChanged( rDCEvt );
     858                 :            : 
     859 [ #  # ][ #  #  :          0 :         if ((( rDCEvt.GetType() == DATACHANGED_SETTINGS )   ||
             #  #  #  # ]
     860                 :          0 :             ( rDCEvt.GetType() == DATACHANGED_DISPLAY   ))  &&
     861                 :          0 :             ( rDCEvt.GetFlags() & SETTINGS_STYLE        ))
     862                 :            :         {
     863                 :            :             // Check if we need to get new images for normal/high contrast mode
     864                 :          0 :             checkImageList();
     865                 :            :         }
     866                 :          0 :     }
     867                 :            :     //------------------------------------------------------------------
     868                 :          0 :     ImageList DbaIndexDialog::getImageList(sal_Int16 _eBitmapSet) const
     869                 :            :     {
     870                 :          0 :         sal_Int16 nN = IMG_INDEX_DLG_SC;
     871         [ #  # ]:          0 :         if ( _eBitmapSet == SFX_SYMBOLS_SIZE_LARGE )
     872                 :            :         {
     873                 :          0 :             nN = IMG_INDEX_DLG_LC;
     874                 :            :         }
     875         [ #  # ]:          0 :         return ImageList(ModuleRes(nN));
     876                 :            :     }
     877                 :            :     //------------------------------------------------------------------
     878                 :          0 :     void DbaIndexDialog::resizeControls(const Size& _rDiff)
     879                 :            :     {
     880                 :            :         // we use large images so we must change them
     881 [ #  # ][ #  # ]:          0 :         if ( _rDiff.Width() || _rDiff.Height() )
                 [ #  # ]
     882                 :            :         {
     883         [ #  # ]:          0 :             Size aDlgSize = GetSizePixel();
     884                 :            :             // adjust size of dlg
     885                 :          0 :             SetSizePixel(Size(aDlgSize.Width() + _rDiff.Width(),
     886                 :          0 :                               aDlgSize.Height() + _rDiff.Height())
     887         [ #  # ]:          0 :                         );
     888         [ #  # ]:          0 :             Size aIndexSize = m_aIndexes.GetSizePixel();
     889         [ #  # ]:          0 :             m_aIndexes.SetPosSizePixel(m_aIndexes.GetPosPixel() + Point(0,_rDiff.Height()),
     890                 :          0 :                                     Size(aIndexSize.Width() + _rDiff.Width(),
     891         [ #  # ]:          0 :                                          aIndexSize.Height()));
     892                 :            : 
     893                 :            :             //now move the rest to the left side
     894                 :          0 :             Point aMove(_rDiff.Width(),_rDiff.Height());
     895 [ #  # ][ #  # ]:          0 :             m_aIndexDetails.SetPosPixel(m_aIndexDetails.GetPosPixel() + aMove);
     896 [ #  # ][ #  # ]:          0 :             m_aDescriptionLabel.SetPosPixel(m_aDescriptionLabel.GetPosPixel() + aMove);
     897 [ #  # ][ #  # ]:          0 :             m_aDescription.SetPosPixel(m_aDescription.GetPosPixel() + aMove);
     898 [ #  # ][ #  # ]:          0 :             m_aUnique.SetPosPixel(m_aUnique.GetPosPixel() + aMove);
     899 [ #  # ][ #  # ]:          0 :             m_aFieldsLabel.SetPosPixel(m_aFieldsLabel.GetPosPixel() + aMove);
     900                 :            :             OSL_ENSURE(m_pFields,"NO valid fields!");
     901 [ #  # ][ #  # ]:          0 :             m_pFields->SetPosPixel(m_pFields->GetPosPixel() + aMove);
     902 [ #  # ][ #  # ]:          0 :             m_aClose.SetPosPixel(m_aClose.GetPosPixel() + aMove);
     903 [ #  # ][ #  # ]:          0 :             m_aHelp.SetPosPixel(m_aHelp.GetPosPixel() + aMove);
     904                 :            : 
     905         [ #  # ]:          0 :             Invalidate();
     906                 :            :         }
     907                 :          0 :     }
     908                 :            : 
     909                 :            : //......................................................................
     910                 :            : }   // namespace dbaui
     911                 :            : //......................................................................
     912                 :            : 
     913                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10