1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sw.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifdef SW_DLLIMPLEMENTATION
32*cdf0e10cSrcweir #undef SW_DLLIMPLEMENTATION
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir #include <swtypes.hxx>
35*cdf0e10cSrcweir #include <customizeaddresslistdialog.hxx>
36*cdf0e10cSrcweir #include <createaddresslistdialog.hxx>
37*cdf0e10cSrcweir #include <vcl/scrbar.hxx>
38*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
39*cdf0e10cSrcweir #include <customizeaddresslistdialog.hrc>
40*cdf0e10cSrcweir #include <dbui.hrc>
41*cdf0e10cSrcweir #include <helpid.h>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir /*-- 13.04.2004 14:27:21---------------------------------------------------
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
48*cdf0e10cSrcweir SwCustomizeAddressListDialog::SwCustomizeAddressListDialog(
49*cdf0e10cSrcweir         Window* pParent, const SwCSVData& rOldData) :
50*cdf0e10cSrcweir     SfxModalDialog(pParent, SW_RES(DLG_MM_CUSTOMIZE_ADDRESS_LIST)),
51*cdf0e10cSrcweir #ifdef MSC
52*cdf0e10cSrcweir #pragma warning (disable : 4355)
53*cdf0e10cSrcweir #endif
54*cdf0e10cSrcweir     m_aFieldsFT( this, SW_RES(    FT_FIELDS)),
55*cdf0e10cSrcweir     m_aFieldsLB( this, SW_RES(    LB_FIELDS)),
56*cdf0e10cSrcweir     m_aAddPB( this, SW_RES(       PB_ADD)),
57*cdf0e10cSrcweir     m_aDeletePB( this, SW_RES(    PB_DELETE)),
58*cdf0e10cSrcweir     m_aRenamePB( this, SW_RES(    PB_RENAME)),
59*cdf0e10cSrcweir     m_aUpPB( this, SW_RES(        PB_UP)),
60*cdf0e10cSrcweir     m_aDownPB( this, SW_RES(      PB_DOWN)),
61*cdf0e10cSrcweir     m_aSeparatorFL( this, SW_RES( FL_SEPARATOR)),
62*cdf0e10cSrcweir     m_aOK( this, SW_RES(          PB_OK)),
63*cdf0e10cSrcweir     m_aCancel( this, SW_RES(      PB_CANCEL)),
64*cdf0e10cSrcweir     m_aHelp( this, SW_RES(        PB_HELP)),
65*cdf0e10cSrcweir #ifdef MSC
66*cdf0e10cSrcweir #pragma warning (default : 4355)
67*cdf0e10cSrcweir #endif
68*cdf0e10cSrcweir     m_pNewData( new SwCSVData(rOldData))
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir     FreeResource();
71*cdf0e10cSrcweir     m_aFieldsLB.SetSelectHdl(LINK(this, SwCustomizeAddressListDialog, ListBoxSelectHdl_Impl));
72*cdf0e10cSrcweir     Link aAddRenameLk = LINK(this, SwCustomizeAddressListDialog, AddRenameHdl_Impl );
73*cdf0e10cSrcweir     m_aAddPB.SetClickHdl(aAddRenameLk);
74*cdf0e10cSrcweir     m_aRenamePB.SetClickHdl(aAddRenameLk);
75*cdf0e10cSrcweir     m_aDeletePB.SetClickHdl(LINK(this, SwCustomizeAddressListDialog, DeleteHdl_Impl ));
76*cdf0e10cSrcweir     Link aUpDownLk = LINK(this, SwCustomizeAddressListDialog, UpDownHdl_Impl);
77*cdf0e10cSrcweir     m_aUpPB.SetClickHdl(aUpDownLk);
78*cdf0e10cSrcweir     m_aDownPB.SetClickHdl(aUpDownLk);
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir     ::std::vector< ::rtl::OUString >::iterator aHeaderIter;
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir     for(aHeaderIter = m_pNewData->aDBColumnHeaders.begin();
83*cdf0e10cSrcweir                 aHeaderIter != m_pNewData->aDBColumnHeaders.end(); ++aHeaderIter)
84*cdf0e10cSrcweir         m_aFieldsLB.InsertEntry(*aHeaderIter);
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir     m_aFieldsLB.SelectEntryPos(0);
87*cdf0e10cSrcweir     UpdateButtons();
88*cdf0e10cSrcweir }
89*cdf0e10cSrcweir /*-- 13.04.2004 14:34:07---------------------------------------------------
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
92*cdf0e10cSrcweir SwCustomizeAddressListDialog::~SwCustomizeAddressListDialog()
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir /*-- 12.08.2004 12:58:00---------------------------------------------------
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
99*cdf0e10cSrcweir IMPL_LINK(SwCustomizeAddressListDialog, ListBoxSelectHdl_Impl, ListBox*, EMPTYARG)
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir     UpdateButtons();
102*cdf0e10cSrcweir     return 0;
103*cdf0e10cSrcweir }
104*cdf0e10cSrcweir /*-- 13.04.2004 15:02:14---------------------------------------------------
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
107*cdf0e10cSrcweir IMPL_LINK(SwCustomizeAddressListDialog, AddRenameHdl_Impl, PushButton*, pButton)
108*cdf0e10cSrcweir {
109*cdf0e10cSrcweir     bool bRename = pButton == &m_aRenamePB;
110*cdf0e10cSrcweir     sal_uInt16 nPos = m_aFieldsLB.GetSelectEntryPos();
111*cdf0e10cSrcweir     if(nPos == LISTBOX_ENTRY_NOTFOUND)
112*cdf0e10cSrcweir         nPos = 0;
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir     SwAddRenameEntryDialog* pDlg =
115*cdf0e10cSrcweir             new SwAddRenameEntryDialog(pButton, bRename, m_pNewData->aDBColumnHeaders);
116*cdf0e10cSrcweir     if(bRename)
117*cdf0e10cSrcweir     {
118*cdf0e10cSrcweir         String aTemp = m_aFieldsLB.GetEntry(nPos);
119*cdf0e10cSrcweir         pDlg->SetFieldName(aTemp);
120*cdf0e10cSrcweir     }
121*cdf0e10cSrcweir     if(RET_OK == pDlg->Execute())
122*cdf0e10cSrcweir     {
123*cdf0e10cSrcweir         String sNew = pDlg->GetFieldName();
124*cdf0e10cSrcweir         if(bRename)
125*cdf0e10cSrcweir         {
126*cdf0e10cSrcweir             m_pNewData->aDBColumnHeaders[nPos] = sNew;
127*cdf0e10cSrcweir             m_aFieldsLB.RemoveEntry(nPos);
128*cdf0e10cSrcweir         }
129*cdf0e10cSrcweir         else
130*cdf0e10cSrcweir         {
131*cdf0e10cSrcweir             if ( m_aFieldsLB.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
132*cdf0e10cSrcweir                 ++nPos; // append the new entry behind the selected
133*cdf0e10cSrcweir             //add the new column
134*cdf0e10cSrcweir             m_pNewData->aDBColumnHeaders.insert(m_pNewData->aDBColumnHeaders.begin() + nPos, sNew);
135*cdf0e10cSrcweir             //add a new entry into all data arrays
136*cdf0e10cSrcweir             String sTemp;
137*cdf0e10cSrcweir             ::std::vector< ::std::vector< ::rtl::OUString > >::iterator aDataIter;
138*cdf0e10cSrcweir             for( aDataIter = m_pNewData->aDBData.begin(); aDataIter != m_pNewData->aDBData.end(); ++aDataIter)
139*cdf0e10cSrcweir                 aDataIter->insert(aDataIter->begin() + nPos, sTemp);
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir         }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir         m_aFieldsLB.InsertEntry(sNew, nPos);
144*cdf0e10cSrcweir         m_aFieldsLB.SelectEntryPos(nPos);
145*cdf0e10cSrcweir     }
146*cdf0e10cSrcweir     delete pDlg;
147*cdf0e10cSrcweir     UpdateButtons();
148*cdf0e10cSrcweir     return 0;
149*cdf0e10cSrcweir }
150*cdf0e10cSrcweir /*-- 13.04.2004 15:02:14---------------------------------------------------
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
153*cdf0e10cSrcweir IMPL_LINK(SwCustomizeAddressListDialog, DeleteHdl_Impl, PushButton*, EMPTYARG)
154*cdf0e10cSrcweir {
155*cdf0e10cSrcweir     sal_uInt16 nPos = m_aFieldsLB.GetSelectEntryPos();
156*cdf0e10cSrcweir     m_aFieldsLB.RemoveEntry(m_aFieldsLB.GetSelectEntryPos());
157*cdf0e10cSrcweir     m_aFieldsLB.SelectEntryPos(nPos > m_aFieldsLB.GetEntryCount() - 1 ? nPos - 1 : nPos);
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir     //remove the column
160*cdf0e10cSrcweir     m_pNewData->aDBColumnHeaders.erase(m_pNewData->aDBColumnHeaders.begin() + nPos);
161*cdf0e10cSrcweir     //remove the data
162*cdf0e10cSrcweir     ::std::vector< ::std::vector< ::rtl::OUString > >::iterator aDataIter;
163*cdf0e10cSrcweir     for( aDataIter = m_pNewData->aDBData.begin(); aDataIter != m_pNewData->aDBData.end(); ++aDataIter)
164*cdf0e10cSrcweir         aDataIter->erase(aDataIter->begin() + nPos);
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir     UpdateButtons();
167*cdf0e10cSrcweir     return 0;
168*cdf0e10cSrcweir }
169*cdf0e10cSrcweir /*-- 13.04.2004 15:02:15---------------------------------------------------
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
172*cdf0e10cSrcweir IMPL_LINK(SwCustomizeAddressListDialog, UpDownHdl_Impl, PushButton*, pButton)
173*cdf0e10cSrcweir {
174*cdf0e10cSrcweir     sal_uInt16 nPos;
175*cdf0e10cSrcweir     sal_uInt16 nOldPos = nPos = m_aFieldsLB.GetSelectEntryPos();
176*cdf0e10cSrcweir     String aTemp = m_aFieldsLB.GetEntry(nPos);
177*cdf0e10cSrcweir     m_aFieldsLB.RemoveEntry( nPos );
178*cdf0e10cSrcweir     if(pButton == &m_aUpPB)
179*cdf0e10cSrcweir         --nPos;
180*cdf0e10cSrcweir     else
181*cdf0e10cSrcweir         ++nPos;
182*cdf0e10cSrcweir     m_aFieldsLB.InsertEntry(aTemp, nPos);
183*cdf0e10cSrcweir     m_aFieldsLB.SelectEntryPos(nPos);
184*cdf0e10cSrcweir     //align m_pNewData
185*cdf0e10cSrcweir     ::rtl::OUString sHeader = m_pNewData->aDBColumnHeaders[nOldPos];
186*cdf0e10cSrcweir     m_pNewData->aDBColumnHeaders.erase(m_pNewData->aDBColumnHeaders.begin() + nOldPos);
187*cdf0e10cSrcweir     m_pNewData->aDBColumnHeaders.insert(m_pNewData->aDBColumnHeaders.begin() + nPos, sHeader);
188*cdf0e10cSrcweir     ::std::vector< ::std::vector< ::rtl::OUString > >::iterator aDataIter;
189*cdf0e10cSrcweir     for( aDataIter = m_pNewData->aDBData.begin(); aDataIter != m_pNewData->aDBData.end(); ++aDataIter)
190*cdf0e10cSrcweir     {
191*cdf0e10cSrcweir         ::rtl::OUString sData = (*aDataIter)[nOldPos];
192*cdf0e10cSrcweir         aDataIter->erase(aDataIter->begin() + nOldPos);
193*cdf0e10cSrcweir         aDataIter->insert(aDataIter->begin() + nPos, sData);
194*cdf0e10cSrcweir     }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir     UpdateButtons();
197*cdf0e10cSrcweir     return 0;
198*cdf0e10cSrcweir }
199*cdf0e10cSrcweir /*-- 19.04.2004 14:51:49---------------------------------------------------
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
202*cdf0e10cSrcweir void SwCustomizeAddressListDialog::UpdateButtons()
203*cdf0e10cSrcweir {
204*cdf0e10cSrcweir     sal_uInt16 nPos = m_aFieldsLB.GetSelectEntryPos();
205*cdf0e10cSrcweir     sal_uInt16 nEntries = m_aFieldsLB.GetEntryCount();
206*cdf0e10cSrcweir     m_aUpPB.Enable(nPos > 0 && nEntries > 0);
207*cdf0e10cSrcweir     m_aDownPB.Enable(nPos < nEntries -1);
208*cdf0e10cSrcweir     m_aDeletePB.Enable(nEntries > 0);
209*cdf0e10cSrcweir     m_aRenamePB.Enable(nEntries > 0);
210*cdf0e10cSrcweir }
211*cdf0e10cSrcweir /*-- 19.04.2004 14:51:49---------------------------------------------------
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
214*cdf0e10cSrcweir SwCSVData*    SwCustomizeAddressListDialog::GetNewData()
215*cdf0e10cSrcweir {
216*cdf0e10cSrcweir     return m_pNewData;
217*cdf0e10cSrcweir }
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir /*-- 13.04.2004 13:48:41---------------------------------------------------
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
222*cdf0e10cSrcweir SwAddRenameEntryDialog::SwAddRenameEntryDialog(
223*cdf0e10cSrcweir         Window* pParent, bool bRename, const ::std::vector< ::rtl::OUString >& rCSVHeader) :
224*cdf0e10cSrcweir     SfxModalDialog(pParent, SW_RES(DLG_MM_ADD_RENAME_ENTRY)),
225*cdf0e10cSrcweir #ifdef MSC
226*cdf0e10cSrcweir #pragma warning (disable : 4355)
227*cdf0e10cSrcweir #endif
228*cdf0e10cSrcweir     m_aFieldNameFT( this, SW_RES( FT_FIELDNAME)),
229*cdf0e10cSrcweir     m_aFieldNameED( this, SW_RES( ED_FIELDNAME)),
230*cdf0e10cSrcweir     m_aOK( this, SW_RES(          PB_OK)),
231*cdf0e10cSrcweir     m_aCancel( this, SW_RES(      PB_CANCEL)),
232*cdf0e10cSrcweir     m_aHelp( this, SW_RES(        PB_HELP)),
233*cdf0e10cSrcweir #ifdef MSC
234*cdf0e10cSrcweir #pragma warning (default : 4355)
235*cdf0e10cSrcweir #endif
236*cdf0e10cSrcweir     m_rCSVHeader(rCSVHeader)
237*cdf0e10cSrcweir {
238*cdf0e10cSrcweir     if(bRename)
239*cdf0e10cSrcweir         SetText(String(SW_RES(ST_RENAME_TITLE)));
240*cdf0e10cSrcweir     else
241*cdf0e10cSrcweir         m_aOK.SetText(String(SW_RES(ST_ADD_BUTTON)));
242*cdf0e10cSrcweir     FreeResource();
243*cdf0e10cSrcweir     m_aFieldNameED.SetModifyHdl(LINK(this, SwAddRenameEntryDialog, ModifyHdl_Impl));
244*cdf0e10cSrcweir     ModifyHdl_Impl( &m_aFieldNameED );
245*cdf0e10cSrcweir }
246*cdf0e10cSrcweir /*-- 13.04.2004 13:48:41---------------------------------------------------
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
249*cdf0e10cSrcweir SwAddRenameEntryDialog::~SwAddRenameEntryDialog()
250*cdf0e10cSrcweir {
251*cdf0e10cSrcweir }
252*cdf0e10cSrcweir /*-- 19.04.2004 15:31:34---------------------------------------------------
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
255*cdf0e10cSrcweir IMPL_LINK(SwAddRenameEntryDialog, ModifyHdl_Impl, Edit*, pEdit)
256*cdf0e10cSrcweir {
257*cdf0e10cSrcweir     ::rtl::OUString sEntry = pEdit->GetText();
258*cdf0e10cSrcweir     sal_Bool bFound = sEntry.getLength() ? sal_False : sal_True;
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir     if(!bFound)
261*cdf0e10cSrcweir     {
262*cdf0e10cSrcweir         ::std::vector< ::rtl::OUString >::const_iterator aHeaderIter;
263*cdf0e10cSrcweir         for(aHeaderIter = m_rCSVHeader.begin();
264*cdf0e10cSrcweir                     aHeaderIter != m_rCSVHeader.end();
265*cdf0e10cSrcweir                     ++aHeaderIter)
266*cdf0e10cSrcweir             if(*aHeaderIter == sEntry)
267*cdf0e10cSrcweir             {
268*cdf0e10cSrcweir                 bFound = sal_True;
269*cdf0e10cSrcweir                 break;
270*cdf0e10cSrcweir             }
271*cdf0e10cSrcweir     }
272*cdf0e10cSrcweir     m_aOK.Enable(!bFound);
273*cdf0e10cSrcweir     return 0;
274*cdf0e10cSrcweir }
275