LCOV - code coverage report
Current view: top level - sw/source/ui/dbui - customizeaddresslistdialog.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 133 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 21 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <swtypes.hxx>
      21             : #include <customizeaddresslistdialog.hxx>
      22             : #include <createaddresslistdialog.hxx>
      23             : #include <vcl/scrbar.hxx>
      24             : #include <vcl/msgbox.hxx>
      25             : #include <dbui.hrc>
      26             : #include <helpid.h>
      27             : 
      28           0 : SwCustomizeAddressListDialog::SwCustomizeAddressListDialog(
      29             :         vcl::Window* pParent, const SwCSVData& rOldData)
      30             :     : SfxModalDialog(pParent, "CustomizeAddrListDialog",
      31             :         "modules/swriter/ui/customizeaddrlistdialog.ui")
      32           0 :     , m_pNewData( new SwCSVData(rOldData))
      33             : {
      34           0 :     get(m_pFieldsLB, "treeview");
      35           0 :     m_pFieldsLB->SetDropDownLineCount(14);
      36           0 :     get(m_pAddPB, "add");
      37           0 :     get(m_pDeletePB, "delete");
      38           0 :     get(m_pRenamePB, "rename");
      39           0 :     get(m_pUpPB, "up");
      40           0 :     get(m_pDownPB, "down");
      41             : 
      42           0 :     m_pFieldsLB->SetSelectHdl(LINK(this, SwCustomizeAddressListDialog, ListBoxSelectHdl_Impl));
      43           0 :     Link<> aAddRenameLk = LINK(this, SwCustomizeAddressListDialog, AddRenameHdl_Impl );
      44           0 :     m_pAddPB->SetClickHdl(aAddRenameLk);
      45           0 :     m_pRenamePB->SetClickHdl(aAddRenameLk);
      46           0 :     m_pDeletePB->SetClickHdl(LINK(this, SwCustomizeAddressListDialog, DeleteHdl_Impl ));
      47           0 :     Link<> aUpDownLk = LINK(this, SwCustomizeAddressListDialog, UpDownHdl_Impl);
      48           0 :     m_pUpPB->SetClickHdl(aUpDownLk);
      49           0 :     m_pDownPB->SetClickHdl(aUpDownLk);
      50             : 
      51           0 :     std::vector< OUString >::iterator aHeaderIter;
      52             : 
      53           0 :     for(aHeaderIter = m_pNewData->aDBColumnHeaders.begin();
      54           0 :                 aHeaderIter != m_pNewData->aDBColumnHeaders.end(); ++aHeaderIter)
      55           0 :         m_pFieldsLB->InsertEntry(*aHeaderIter);
      56             : 
      57           0 :     m_pFieldsLB->SelectEntryPos(0);
      58           0 :     UpdateButtons();
      59           0 : }
      60             : 
      61           0 : SwCustomizeAddressListDialog::~SwCustomizeAddressListDialog()
      62             : {
      63           0 :     disposeOnce();
      64           0 : }
      65             : 
      66           0 : void SwCustomizeAddressListDialog::dispose()
      67             : {
      68           0 :     m_pFieldsLB.clear();
      69           0 :     m_pAddPB.clear();
      70           0 :     m_pDeletePB.clear();
      71           0 :     m_pRenamePB.clear();
      72           0 :     m_pUpPB.clear();
      73           0 :     m_pDownPB.clear();
      74           0 :     SfxModalDialog::dispose();
      75           0 : }
      76             : 
      77             : 
      78           0 : IMPL_LINK_NOARG(SwCustomizeAddressListDialog, ListBoxSelectHdl_Impl)
      79             : {
      80           0 :     UpdateButtons();
      81           0 :     return 0;
      82             : }
      83             : 
      84           0 : IMPL_LINK(SwCustomizeAddressListDialog, AddRenameHdl_Impl, PushButton*, pButton)
      85             : {
      86           0 :     bool bRename = pButton == m_pRenamePB;
      87           0 :     sal_Int32 nPos = m_pFieldsLB->GetSelectEntryPos();
      88           0 :     if(nPos == LISTBOX_ENTRY_NOTFOUND)
      89           0 :         nPos = 0;
      90             : 
      91           0 :     ScopedVclPtr<SwAddRenameEntryDialog> pDlg;
      92           0 :     if (bRename)
      93           0 :         pDlg.reset(VclPtr<SwRenameEntryDialog>::Create(pButton, m_pNewData->aDBColumnHeaders));
      94             :     else
      95           0 :         pDlg.reset(VclPtr<SwAddEntryDialog>::Create(pButton, m_pNewData->aDBColumnHeaders));
      96           0 :     if(bRename)
      97             :     {
      98           0 :         OUString aTemp = m_pFieldsLB->GetEntry(nPos);
      99           0 :         pDlg->SetFieldName(aTemp);
     100             :     }
     101           0 :     if(RET_OK == pDlg->Execute())
     102             :     {
     103           0 :         OUString sNew = pDlg->GetFieldName();
     104           0 :         if(bRename)
     105             :         {
     106           0 :             m_pNewData->aDBColumnHeaders[nPos] = sNew;
     107           0 :             m_pFieldsLB->RemoveEntry(nPos);
     108             :         }
     109             :         else
     110             :         {
     111           0 :             if ( m_pFieldsLB->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
     112           0 :                 ++nPos; // append the new entry behind the selected
     113             :             //add the new column
     114           0 :             m_pNewData->aDBColumnHeaders.insert(m_pNewData->aDBColumnHeaders.begin() + nPos, sNew);
     115             :             //add a new entry into all data arrays
     116           0 :             OUString sTemp;
     117           0 :             std::vector< std::vector< OUString > >::iterator aDataIter;
     118           0 :             for( aDataIter = m_pNewData->aDBData.begin(); aDataIter != m_pNewData->aDBData.end(); ++aDataIter)
     119           0 :                 aDataIter->insert(aDataIter->begin() + nPos, sTemp);
     120             : 
     121             :         }
     122             : 
     123           0 :         m_pFieldsLB->InsertEntry(sNew, nPos);
     124           0 :         m_pFieldsLB->SelectEntryPos(nPos);
     125             :     }
     126           0 :     UpdateButtons();
     127           0 :     return 0;
     128             : }
     129             : 
     130           0 : IMPL_LINK_NOARG(SwCustomizeAddressListDialog, DeleteHdl_Impl)
     131             : {
     132           0 :     sal_Int32 nPos = m_pFieldsLB->GetSelectEntryPos();
     133           0 :     m_pFieldsLB->RemoveEntry(m_pFieldsLB->GetSelectEntryPos());
     134           0 :     m_pFieldsLB->SelectEntryPos(nPos > m_pFieldsLB->GetEntryCount() - 1 ? nPos - 1 : nPos);
     135             : 
     136             :     //remove the column
     137           0 :     m_pNewData->aDBColumnHeaders.erase(m_pNewData->aDBColumnHeaders.begin() + nPos);
     138             :     //remove the data
     139           0 :     std::vector< std::vector< OUString > >::iterator aDataIter;
     140           0 :     for( aDataIter = m_pNewData->aDBData.begin(); aDataIter != m_pNewData->aDBData.end(); ++aDataIter)
     141           0 :         aDataIter->erase(aDataIter->begin() + nPos);
     142             : 
     143           0 :     UpdateButtons();
     144           0 :     return 0;
     145             : }
     146             : 
     147           0 : IMPL_LINK(SwCustomizeAddressListDialog, UpDownHdl_Impl, PushButton*, pButton)
     148             : {
     149             :     sal_Int32 nPos;
     150           0 :     sal_Int32 nOldPos = nPos = m_pFieldsLB->GetSelectEntryPos();
     151           0 :     OUString aTemp = m_pFieldsLB->GetEntry(nPos);
     152           0 :     m_pFieldsLB->RemoveEntry( nPos );
     153           0 :     if(pButton == m_pUpPB)
     154           0 :         --nPos;
     155             :     else
     156           0 :         ++nPos;
     157           0 :     m_pFieldsLB->InsertEntry(aTemp, nPos);
     158           0 :     m_pFieldsLB->SelectEntryPos(nPos);
     159             :     //align m_pNewData
     160           0 :     OUString sHeader = m_pNewData->aDBColumnHeaders[nOldPos];
     161           0 :     m_pNewData->aDBColumnHeaders.erase(m_pNewData->aDBColumnHeaders.begin() + nOldPos);
     162           0 :     m_pNewData->aDBColumnHeaders.insert(m_pNewData->aDBColumnHeaders.begin() + nPos, sHeader);
     163           0 :     std::vector< std::vector< OUString > >::iterator aDataIter;
     164           0 :     for( aDataIter = m_pNewData->aDBData.begin(); aDataIter != m_pNewData->aDBData.end(); ++aDataIter)
     165             :     {
     166           0 :         OUString sData = (*aDataIter)[nOldPos];
     167           0 :         aDataIter->erase(aDataIter->begin() + nOldPos);
     168           0 :         aDataIter->insert(aDataIter->begin() + nPos, sData);
     169           0 :     }
     170             : 
     171           0 :     UpdateButtons();
     172           0 :     return 0;
     173             : }
     174             : 
     175           0 : void SwCustomizeAddressListDialog::UpdateButtons()
     176             : {
     177           0 :     sal_Int32 nPos = m_pFieldsLB->GetSelectEntryPos();
     178           0 :     sal_Int32 nEntries = m_pFieldsLB->GetEntryCount();
     179           0 :     m_pUpPB->Enable(nPos > 0 && nEntries > 0);
     180           0 :     m_pDownPB->Enable(nPos < nEntries -1);
     181           0 :     m_pDeletePB->Enable(nEntries > 0);
     182           0 :     m_pRenamePB->Enable(nEntries > 0);
     183           0 : }
     184             : 
     185             : 
     186           0 : SwAddRenameEntryDialog::SwAddRenameEntryDialog(
     187             :         vcl::Window* pParent, const OUString& rID, const OUString& rUIXMLDescription,
     188             :         const std::vector< OUString >& rCSVHeader)
     189             :     : SfxModalDialog(pParent, rID, rUIXMLDescription)
     190           0 :     , m_rCSVHeader(rCSVHeader)
     191             : {
     192           0 :     get(m_pOK, "ok");
     193           0 :     get(m_pFieldNameED, "entry");
     194           0 :     m_pFieldNameED->SetModifyHdl(LINK(this, SwAddRenameEntryDialog, ModifyHdl_Impl));
     195           0 :     ModifyHdl_Impl(m_pFieldNameED);
     196           0 : }
     197             : 
     198           0 : SwAddRenameEntryDialog::~SwAddRenameEntryDialog()
     199             : {
     200           0 :     disposeOnce();
     201           0 : }
     202             : 
     203           0 : void SwAddRenameEntryDialog::dispose()
     204             : {
     205           0 :     m_pFieldNameED.clear();
     206           0 :     m_pOK.clear();
     207           0 :     SfxModalDialog::dispose();
     208           0 : }
     209             : 
     210           0 : IMPL_LINK(SwAddRenameEntryDialog, ModifyHdl_Impl, Edit*, pEdit)
     211             : {
     212           0 :     OUString sEntry = pEdit->GetText();
     213           0 :     bool bFound = sEntry.isEmpty();
     214             : 
     215           0 :     if(!bFound)
     216             :     {
     217           0 :         std::vector< OUString >::const_iterator aHeaderIter;
     218           0 :         for(aHeaderIter = m_rCSVHeader.begin();
     219           0 :                     aHeaderIter != m_rCSVHeader.end();
     220             :                     ++aHeaderIter)
     221           0 :             if(*aHeaderIter == sEntry)
     222             :             {
     223           0 :                 bFound = true;
     224           0 :                 break;
     225             :             }
     226             :     }
     227           0 :     m_pOK->Enable(!bFound);
     228           0 :     return 0;
     229           0 : }
     230             : 
     231             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11