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