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