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 <customizeaddresslistdialog.hrc>
26 : #include <dbui.hrc>
27 : #include <helpid.h>
28 :
29 0 : SwCustomizeAddressListDialog::SwCustomizeAddressListDialog(
30 : Window* pParent, const SwCSVData& rOldData) :
31 : SfxModalDialog(pParent, SW_RES(DLG_MM_CUSTOMIZE_ADDRESS_LIST)),
32 : #ifdef MSC
33 : #pragma warning (disable : 4355)
34 : #endif
35 : m_aFieldsFT( this, SW_RES( FT_FIELDS)),
36 : m_aFieldsLB( this, SW_RES( LB_FIELDS)),
37 : m_aAddPB( this, SW_RES( PB_ADD)),
38 : m_aDeletePB( this, SW_RES( PB_DELETE)),
39 : m_aRenamePB( this, SW_RES( PB_RENAME)),
40 : m_aUpPB( this, SW_RES( PB_UP)),
41 : m_aDownPB( this, SW_RES( PB_DOWN)),
42 : m_aSeparatorFL( this, SW_RES( FL_SEPARATOR)),
43 : m_aOK( this, SW_RES( PB_OK)),
44 : m_aCancel( this, SW_RES( PB_CANCEL)),
45 : m_aHelp( this, SW_RES( PB_HELP)),
46 : #ifdef MSC
47 : #pragma warning (default : 4355)
48 : #endif
49 0 : m_pNewData( new SwCSVData(rOldData))
50 : {
51 0 : FreeResource();
52 0 : m_aFieldsLB.SetSelectHdl(LINK(this, SwCustomizeAddressListDialog, ListBoxSelectHdl_Impl));
53 0 : Link aAddRenameLk = LINK(this, SwCustomizeAddressListDialog, AddRenameHdl_Impl );
54 0 : m_aAddPB.SetClickHdl(aAddRenameLk);
55 0 : m_aRenamePB.SetClickHdl(aAddRenameLk);
56 0 : m_aDeletePB.SetClickHdl(LINK(this, SwCustomizeAddressListDialog, DeleteHdl_Impl ));
57 0 : Link aUpDownLk = LINK(this, SwCustomizeAddressListDialog, UpDownHdl_Impl);
58 0 : m_aUpPB.SetClickHdl(aUpDownLk);
59 0 : m_aDownPB.SetClickHdl(aUpDownLk);
60 :
61 0 : ::std::vector< ::rtl::OUString >::iterator aHeaderIter;
62 :
63 0 : for(aHeaderIter = m_pNewData->aDBColumnHeaders.begin();
64 0 : aHeaderIter != m_pNewData->aDBColumnHeaders.end(); ++aHeaderIter)
65 0 : m_aFieldsLB.InsertEntry(*aHeaderIter);
66 :
67 0 : m_aFieldsLB.SelectEntryPos(0);
68 0 : UpdateButtons();
69 0 : }
70 :
71 0 : SwCustomizeAddressListDialog::~SwCustomizeAddressListDialog()
72 : {
73 0 : }
74 :
75 0 : IMPL_LINK_NOARG(SwCustomizeAddressListDialog, ListBoxSelectHdl_Impl)
76 : {
77 0 : UpdateButtons();
78 0 : return 0;
79 : }
80 :
81 0 : IMPL_LINK(SwCustomizeAddressListDialog, AddRenameHdl_Impl, PushButton*, pButton)
82 : {
83 0 : bool bRename = pButton == &m_aRenamePB;
84 0 : sal_uInt16 nPos = m_aFieldsLB.GetSelectEntryPos();
85 0 : if(nPos == LISTBOX_ENTRY_NOTFOUND)
86 0 : nPos = 0;
87 :
88 : SwAddRenameEntryDialog* pDlg =
89 0 : new SwAddRenameEntryDialog(pButton, bRename, m_pNewData->aDBColumnHeaders);
90 0 : if(bRename)
91 : {
92 0 : String aTemp = m_aFieldsLB.GetEntry(nPos);
93 0 : pDlg->SetFieldName(aTemp);
94 : }
95 0 : if(RET_OK == pDlg->Execute())
96 : {
97 0 : String sNew = pDlg->GetFieldName();
98 0 : if(bRename)
99 : {
100 0 : m_pNewData->aDBColumnHeaders[nPos] = sNew;
101 0 : m_aFieldsLB.RemoveEntry(nPos);
102 : }
103 : else
104 : {
105 0 : if ( m_aFieldsLB.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
106 0 : ++nPos; // append the new entry behind the selected
107 : //add the new column
108 0 : m_pNewData->aDBColumnHeaders.insert(m_pNewData->aDBColumnHeaders.begin() + nPos, sNew);
109 : //add a new entry into all data arrays
110 0 : String sTemp;
111 0 : ::std::vector< ::std::vector< ::rtl::OUString > >::iterator aDataIter;
112 0 : for( aDataIter = m_pNewData->aDBData.begin(); aDataIter != m_pNewData->aDBData.end(); ++aDataIter)
113 0 : aDataIter->insert(aDataIter->begin() + nPos, sTemp);
114 :
115 : }
116 :
117 0 : m_aFieldsLB.InsertEntry(sNew, nPos);
118 0 : m_aFieldsLB.SelectEntryPos(nPos);
119 : }
120 0 : delete pDlg;
121 0 : UpdateButtons();
122 0 : return 0;
123 : }
124 :
125 0 : IMPL_LINK_NOARG(SwCustomizeAddressListDialog, DeleteHdl_Impl)
126 : {
127 0 : sal_uInt16 nPos = m_aFieldsLB.GetSelectEntryPos();
128 0 : m_aFieldsLB.RemoveEntry(m_aFieldsLB.GetSelectEntryPos());
129 0 : m_aFieldsLB.SelectEntryPos(nPos > m_aFieldsLB.GetEntryCount() - 1 ? nPos - 1 : nPos);
130 :
131 : //remove the column
132 0 : m_pNewData->aDBColumnHeaders.erase(m_pNewData->aDBColumnHeaders.begin() + nPos);
133 : //remove the data
134 0 : ::std::vector< ::std::vector< ::rtl::OUString > >::iterator aDataIter;
135 0 : for( aDataIter = m_pNewData->aDBData.begin(); aDataIter != m_pNewData->aDBData.end(); ++aDataIter)
136 0 : aDataIter->erase(aDataIter->begin() + nPos);
137 :
138 0 : UpdateButtons();
139 0 : return 0;
140 : }
141 :
142 0 : IMPL_LINK(SwCustomizeAddressListDialog, UpDownHdl_Impl, PushButton*, pButton)
143 : {
144 : sal_uInt16 nPos;
145 0 : sal_uInt16 nOldPos = nPos = m_aFieldsLB.GetSelectEntryPos();
146 0 : String aTemp = m_aFieldsLB.GetEntry(nPos);
147 0 : m_aFieldsLB.RemoveEntry( nPos );
148 0 : if(pButton == &m_aUpPB)
149 0 : --nPos;
150 : else
151 0 : ++nPos;
152 0 : m_aFieldsLB.InsertEntry(aTemp, nPos);
153 0 : m_aFieldsLB.SelectEntryPos(nPos);
154 : //align m_pNewData
155 0 : ::rtl::OUString sHeader = m_pNewData->aDBColumnHeaders[nOldPos];
156 0 : m_pNewData->aDBColumnHeaders.erase(m_pNewData->aDBColumnHeaders.begin() + nOldPos);
157 0 : m_pNewData->aDBColumnHeaders.insert(m_pNewData->aDBColumnHeaders.begin() + nPos, sHeader);
158 0 : ::std::vector< ::std::vector< ::rtl::OUString > >::iterator aDataIter;
159 0 : for( aDataIter = m_pNewData->aDBData.begin(); aDataIter != m_pNewData->aDBData.end(); ++aDataIter)
160 : {
161 0 : ::rtl::OUString sData = (*aDataIter)[nOldPos];
162 0 : aDataIter->erase(aDataIter->begin() + nOldPos);
163 0 : aDataIter->insert(aDataIter->begin() + nPos, sData);
164 0 : }
165 :
166 0 : UpdateButtons();
167 0 : return 0;
168 : }
169 :
170 0 : void SwCustomizeAddressListDialog::UpdateButtons()
171 : {
172 0 : sal_uInt16 nPos = m_aFieldsLB.GetSelectEntryPos();
173 0 : sal_uInt16 nEntries = m_aFieldsLB.GetEntryCount();
174 0 : m_aUpPB.Enable(nPos > 0 && nEntries > 0);
175 0 : m_aDownPB.Enable(nPos < nEntries -1);
176 0 : m_aDeletePB.Enable(nEntries > 0);
177 0 : m_aRenamePB.Enable(nEntries > 0);
178 0 : }
179 :
180 0 : SwCSVData* SwCustomizeAddressListDialog::GetNewData()
181 : {
182 0 : return m_pNewData;
183 : }
184 :
185 0 : SwAddRenameEntryDialog::SwAddRenameEntryDialog(
186 : Window* pParent, bool bRename, const ::std::vector< ::rtl::OUString >& rCSVHeader) :
187 : SfxModalDialog(pParent, SW_RES(DLG_MM_ADD_RENAME_ENTRY)),
188 : #ifdef MSC
189 : #pragma warning (disable : 4355)
190 : #endif
191 : m_aFieldNameFT( this, SW_RES( FT_FIELDNAME)),
192 : m_aFieldNameED( this, SW_RES( ED_FIELDNAME)),
193 : m_aOK( this, SW_RES( PB_OK)),
194 : m_aCancel( this, SW_RES( PB_CANCEL)),
195 : m_aHelp( this, SW_RES( PB_HELP)),
196 : #ifdef MSC
197 : #pragma warning (default : 4355)
198 : #endif
199 0 : m_rCSVHeader(rCSVHeader)
200 : {
201 0 : if(bRename)
202 0 : SetText(String(SW_RES(ST_RENAME_TITLE)));
203 : else
204 0 : m_aOK.SetText(String(SW_RES(ST_ADD_BUTTON)));
205 0 : FreeResource();
206 0 : m_aFieldNameED.SetModifyHdl(LINK(this, SwAddRenameEntryDialog, ModifyHdl_Impl));
207 0 : ModifyHdl_Impl( &m_aFieldNameED );
208 0 : }
209 :
210 0 : SwAddRenameEntryDialog::~SwAddRenameEntryDialog()
211 : {
212 0 : }
213 :
214 0 : IMPL_LINK(SwAddRenameEntryDialog, ModifyHdl_Impl, Edit*, pEdit)
215 : {
216 0 : ::rtl::OUString sEntry = pEdit->GetText();
217 0 : sal_Bool bFound = sEntry.isEmpty();
218 :
219 0 : if(!bFound)
220 : {
221 0 : ::std::vector< ::rtl::OUString >::const_iterator aHeaderIter;
222 0 : for(aHeaderIter = m_rCSVHeader.begin();
223 0 : aHeaderIter != m_rCSVHeader.end();
224 : ++aHeaderIter)
225 0 : if(*aHeaderIter == sEntry)
226 : {
227 0 : bFound = sal_True;
228 0 : break;
229 : }
230 : }
231 0 : m_aOK.Enable(!bFound);
232 0 : return 0;
233 : }
234 :
235 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|