LCOV - code coverage report
Current view: top level - sw/source/ui/dbui - customizeaddresslistdialog.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 116 0.0 %
Date: 2014-11-03 Functions: 0 17 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             : #include <boost/scoped_ptr.hpp>
      28             : 
      29           0 : SwCustomizeAddressListDialog::SwCustomizeAddressListDialog(
      30             :         vcl::Window* pParent, const SwCSVData& rOldData)
      31             :     : SfxModalDialog(pParent, "CustomizeAddrListDialog",
      32             :         "modules/swriter/ui/customizeaddrlistdialog.ui")
      33           0 :     , m_pNewData( new SwCSVData(rOldData))
      34             : {
      35           0 :     get(m_pFieldsLB, "treeview");
      36           0 :     m_pFieldsLB->SetDropDownLineCount(14);
      37           0 :     get(m_pAddPB, "add");
      38           0 :     get(m_pDeletePB, "delete");
      39           0 :     get(m_pRenamePB, "rename");
      40           0 :     get(m_pUpPB, "up");
      41           0 :     get(m_pDownPB, "down");
      42             : 
      43           0 :     m_pFieldsLB->SetSelectHdl(LINK(this, SwCustomizeAddressListDialog, ListBoxSelectHdl_Impl));
      44           0 :     Link aAddRenameLk = LINK(this, SwCustomizeAddressListDialog, AddRenameHdl_Impl );
      45           0 :     m_pAddPB->SetClickHdl(aAddRenameLk);
      46           0 :     m_pRenamePB->SetClickHdl(aAddRenameLk);
      47           0 :     m_pDeletePB->SetClickHdl(LINK(this, SwCustomizeAddressListDialog, DeleteHdl_Impl ));
      48           0 :     Link aUpDownLk = LINK(this, SwCustomizeAddressListDialog, UpDownHdl_Impl);
      49           0 :     m_pUpPB->SetClickHdl(aUpDownLk);
      50           0 :     m_pDownPB->SetClickHdl(aUpDownLk);
      51             : 
      52           0 :     std::vector< OUString >::iterator aHeaderIter;
      53             : 
      54           0 :     for(aHeaderIter = m_pNewData->aDBColumnHeaders.begin();
      55           0 :                 aHeaderIter != m_pNewData->aDBColumnHeaders.end(); ++aHeaderIter)
      56           0 :         m_pFieldsLB->InsertEntry(*aHeaderIter);
      57             : 
      58           0 :     m_pFieldsLB->SelectEntryPos(0);
      59           0 :     UpdateButtons();
      60           0 : }
      61             : 
      62           0 : SwCustomizeAddressListDialog::~SwCustomizeAddressListDialog()
      63             : {
      64           0 : }
      65             : 
      66           0 : IMPL_LINK_NOARG(SwCustomizeAddressListDialog, ListBoxSelectHdl_Impl)
      67             : {
      68           0 :     UpdateButtons();
      69           0 :     return 0;
      70             : }
      71             : 
      72           0 : IMPL_LINK(SwCustomizeAddressListDialog, AddRenameHdl_Impl, PushButton*, pButton)
      73             : {
      74           0 :     bool bRename = pButton == m_pRenamePB;
      75           0 :     sal_Int32 nPos = m_pFieldsLB->GetSelectEntryPos();
      76           0 :     if(nPos == LISTBOX_ENTRY_NOTFOUND)
      77           0 :         nPos = 0;
      78             : 
      79           0 :     boost::scoped_ptr<SwAddRenameEntryDialog> pDlg;
      80           0 :     if (bRename)
      81           0 :         pDlg.reset(new SwRenameEntryDialog(pButton, m_pNewData->aDBColumnHeaders));
      82             :     else
      83           0 :         pDlg.reset(new SwAddEntryDialog(pButton, m_pNewData->aDBColumnHeaders));
      84           0 :     if(bRename)
      85             :     {
      86           0 :         OUString aTemp = m_pFieldsLB->GetEntry(nPos);
      87           0 :         pDlg->SetFieldName(aTemp);
      88             :     }
      89           0 :     if(RET_OK == pDlg->Execute())
      90             :     {
      91           0 :         OUString sNew = pDlg->GetFieldName();
      92           0 :         if(bRename)
      93             :         {
      94           0 :             m_pNewData->aDBColumnHeaders[nPos] = sNew;
      95           0 :             m_pFieldsLB->RemoveEntry(nPos);
      96             :         }
      97             :         else
      98             :         {
      99           0 :             if ( m_pFieldsLB->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
     100           0 :                 ++nPos; // append the new entry behind the selected
     101             :             //add the new column
     102           0 :             m_pNewData->aDBColumnHeaders.insert(m_pNewData->aDBColumnHeaders.begin() + nPos, sNew);
     103             :             //add a new entry into all data arrays
     104           0 :             OUString sTemp;
     105           0 :             std::vector< std::vector< OUString > >::iterator aDataIter;
     106           0 :             for( aDataIter = m_pNewData->aDBData.begin(); aDataIter != m_pNewData->aDBData.end(); ++aDataIter)
     107           0 :                 aDataIter->insert(aDataIter->begin() + nPos, sTemp);
     108             : 
     109             :         }
     110             : 
     111           0 :         m_pFieldsLB->InsertEntry(sNew, nPos);
     112           0 :         m_pFieldsLB->SelectEntryPos(nPos);
     113             :     }
     114           0 :     pDlg.reset();
     115           0 :     UpdateButtons();
     116           0 :     return 0;
     117             : }
     118             : 
     119           0 : IMPL_LINK_NOARG(SwCustomizeAddressListDialog, DeleteHdl_Impl)
     120             : {
     121           0 :     sal_Int32 nPos = m_pFieldsLB->GetSelectEntryPos();
     122           0 :     m_pFieldsLB->RemoveEntry(m_pFieldsLB->GetSelectEntryPos());
     123           0 :     m_pFieldsLB->SelectEntryPos(nPos > m_pFieldsLB->GetEntryCount() - 1 ? nPos - 1 : nPos);
     124             : 
     125             :     //remove the column
     126           0 :     m_pNewData->aDBColumnHeaders.erase(m_pNewData->aDBColumnHeaders.begin() + nPos);
     127             :     //remove the data
     128           0 :     std::vector< std::vector< OUString > >::iterator aDataIter;
     129           0 :     for( aDataIter = m_pNewData->aDBData.begin(); aDataIter != m_pNewData->aDBData.end(); ++aDataIter)
     130           0 :         aDataIter->erase(aDataIter->begin() + nPos);
     131             : 
     132           0 :     UpdateButtons();
     133           0 :     return 0;
     134             : }
     135             : 
     136           0 : IMPL_LINK(SwCustomizeAddressListDialog, UpDownHdl_Impl, PushButton*, pButton)
     137             : {
     138             :     sal_Int32 nPos;
     139           0 :     sal_Int32 nOldPos = nPos = m_pFieldsLB->GetSelectEntryPos();
     140           0 :     OUString aTemp = m_pFieldsLB->GetEntry(nPos);
     141           0 :     m_pFieldsLB->RemoveEntry( nPos );
     142           0 :     if(pButton == m_pUpPB)
     143           0 :         --nPos;
     144             :     else
     145           0 :         ++nPos;
     146           0 :     m_pFieldsLB->InsertEntry(aTemp, nPos);
     147           0 :     m_pFieldsLB->SelectEntryPos(nPos);
     148             :     //align m_pNewData
     149           0 :     OUString sHeader = m_pNewData->aDBColumnHeaders[nOldPos];
     150           0 :     m_pNewData->aDBColumnHeaders.erase(m_pNewData->aDBColumnHeaders.begin() + nOldPos);
     151           0 :     m_pNewData->aDBColumnHeaders.insert(m_pNewData->aDBColumnHeaders.begin() + nPos, sHeader);
     152           0 :     std::vector< std::vector< OUString > >::iterator aDataIter;
     153           0 :     for( aDataIter = m_pNewData->aDBData.begin(); aDataIter != m_pNewData->aDBData.end(); ++aDataIter)
     154             :     {
     155           0 :         OUString sData = (*aDataIter)[nOldPos];
     156           0 :         aDataIter->erase(aDataIter->begin() + nOldPos);
     157           0 :         aDataIter->insert(aDataIter->begin() + nPos, sData);
     158           0 :     }
     159             : 
     160           0 :     UpdateButtons();
     161           0 :     return 0;
     162             : }
     163             : 
     164           0 : void SwCustomizeAddressListDialog::UpdateButtons()
     165             : {
     166           0 :     sal_Int32 nPos = m_pFieldsLB->GetSelectEntryPos();
     167           0 :     sal_Int32 nEntries = m_pFieldsLB->GetEntryCount();
     168           0 :     m_pUpPB->Enable(nPos > 0 && nEntries > 0);
     169           0 :     m_pDownPB->Enable(nPos < nEntries -1);
     170           0 :     m_pDeletePB->Enable(nEntries > 0);
     171           0 :     m_pRenamePB->Enable(nEntries > 0);
     172           0 : }
     173             : 
     174             : 
     175           0 : SwAddRenameEntryDialog::SwAddRenameEntryDialog(
     176             :         vcl::Window* pParent, const OString& rID, const OUString& rUIXMLDescription,
     177             :         const std::vector< OUString >& rCSVHeader)
     178             :     : SfxModalDialog(pParent, rID, rUIXMLDescription)
     179           0 :     , m_rCSVHeader(rCSVHeader)
     180             : {
     181           0 :     get(m_pOK, "ok");
     182           0 :     get(m_pFieldNameED, "entry");
     183           0 :     m_pFieldNameED->SetModifyHdl(LINK(this, SwAddRenameEntryDialog, ModifyHdl_Impl));
     184           0 :     ModifyHdl_Impl(m_pFieldNameED);
     185           0 : }
     186             : 
     187           0 : IMPL_LINK(SwAddRenameEntryDialog, ModifyHdl_Impl, Edit*, pEdit)
     188             : {
     189           0 :     OUString sEntry = pEdit->GetText();
     190           0 :     bool bFound = sEntry.isEmpty();
     191             : 
     192           0 :     if(!bFound)
     193             :     {
     194           0 :         std::vector< OUString >::const_iterator aHeaderIter;
     195           0 :         for(aHeaderIter = m_rCSVHeader.begin();
     196           0 :                     aHeaderIter != m_rCSVHeader.end();
     197             :                     ++aHeaderIter)
     198           0 :             if(*aHeaderIter == sEntry)
     199             :             {
     200           0 :                 bFound = true;
     201           0 :                 break;
     202             :             }
     203             :     }
     204           0 :     m_pOK->Enable(!bFound);
     205           0 :     return 0;
     206           0 : }
     207             : 
     208             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10