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