1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
29 SwCustomizeAddressListDialog::SwCustomizeAddressListDialog(
30 Window
* pParent
, const SwCSVData
& rOldData
) :
31 SfxModalDialog(pParent
, SW_RES(DLG_MM_CUSTOMIZE_ADDRESS_LIST
)),
33 #pragma warning (disable : 4355)
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
)),
47 #pragma warning (default : 4355)
49 m_pNewData( new SwCSVData(rOldData
))
52 m_aFieldsLB
.SetSelectHdl(LINK(this, SwCustomizeAddressListDialog
, ListBoxSelectHdl_Impl
));
53 Link aAddRenameLk
= LINK(this, SwCustomizeAddressListDialog
, AddRenameHdl_Impl
);
54 m_aAddPB
.SetClickHdl(aAddRenameLk
);
55 m_aRenamePB
.SetClickHdl(aAddRenameLk
);
56 m_aDeletePB
.SetClickHdl(LINK(this, SwCustomizeAddressListDialog
, DeleteHdl_Impl
));
57 Link aUpDownLk
= LINK(this, SwCustomizeAddressListDialog
, UpDownHdl_Impl
);
58 m_aUpPB
.SetClickHdl(aUpDownLk
);
59 m_aDownPB
.SetClickHdl(aUpDownLk
);
61 ::std::vector
< OUString
>::iterator aHeaderIter
;
63 for(aHeaderIter
= m_pNewData
->aDBColumnHeaders
.begin();
64 aHeaderIter
!= m_pNewData
->aDBColumnHeaders
.end(); ++aHeaderIter
)
65 m_aFieldsLB
.InsertEntry(*aHeaderIter
);
67 m_aFieldsLB
.SelectEntryPos(0);
71 SwCustomizeAddressListDialog::~SwCustomizeAddressListDialog()
75 IMPL_LINK_NOARG(SwCustomizeAddressListDialog
, ListBoxSelectHdl_Impl
)
81 IMPL_LINK(SwCustomizeAddressListDialog
, AddRenameHdl_Impl
, PushButton
*, pButton
)
83 bool bRename
= pButton
== &m_aRenamePB
;
84 sal_uInt16 nPos
= m_aFieldsLB
.GetSelectEntryPos();
85 if(nPos
== LISTBOX_ENTRY_NOTFOUND
)
88 SwAddRenameEntryDialog
* pDlg
=
89 new SwAddRenameEntryDialog(pButton
, bRename
, m_pNewData
->aDBColumnHeaders
);
92 String aTemp
= m_aFieldsLB
.GetEntry(nPos
);
93 pDlg
->SetFieldName(aTemp
);
95 if(RET_OK
== pDlg
->Execute())
97 String sNew
= pDlg
->GetFieldName();
100 m_pNewData
->aDBColumnHeaders
[nPos
] = sNew
;
101 m_aFieldsLB
.RemoveEntry(nPos
);
105 if ( m_aFieldsLB
.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND
)
106 ++nPos
; // append the new entry behind the selected
108 m_pNewData
->aDBColumnHeaders
.insert(m_pNewData
->aDBColumnHeaders
.begin() + nPos
, sNew
);
109 //add a new entry into all data arrays
111 ::std::vector
< ::std::vector
< OUString
> >::iterator aDataIter
;
112 for( aDataIter
= m_pNewData
->aDBData
.begin(); aDataIter
!= m_pNewData
->aDBData
.end(); ++aDataIter
)
113 aDataIter
->insert(aDataIter
->begin() + nPos
, sTemp
);
117 m_aFieldsLB
.InsertEntry(sNew
, nPos
);
118 m_aFieldsLB
.SelectEntryPos(nPos
);
125 IMPL_LINK_NOARG(SwCustomizeAddressListDialog
, DeleteHdl_Impl
)
127 sal_uInt16 nPos
= m_aFieldsLB
.GetSelectEntryPos();
128 m_aFieldsLB
.RemoveEntry(m_aFieldsLB
.GetSelectEntryPos());
129 m_aFieldsLB
.SelectEntryPos(nPos
> m_aFieldsLB
.GetEntryCount() - 1 ? nPos
- 1 : nPos
);
132 m_pNewData
->aDBColumnHeaders
.erase(m_pNewData
->aDBColumnHeaders
.begin() + nPos
);
134 ::std::vector
< ::std::vector
< OUString
> >::iterator aDataIter
;
135 for( aDataIter
= m_pNewData
->aDBData
.begin(); aDataIter
!= m_pNewData
->aDBData
.end(); ++aDataIter
)
136 aDataIter
->erase(aDataIter
->begin() + nPos
);
142 IMPL_LINK(SwCustomizeAddressListDialog
, UpDownHdl_Impl
, PushButton
*, pButton
)
145 sal_uInt16 nOldPos
= nPos
= m_aFieldsLB
.GetSelectEntryPos();
146 String aTemp
= m_aFieldsLB
.GetEntry(nPos
);
147 m_aFieldsLB
.RemoveEntry( nPos
);
148 if(pButton
== &m_aUpPB
)
152 m_aFieldsLB
.InsertEntry(aTemp
, nPos
);
153 m_aFieldsLB
.SelectEntryPos(nPos
);
155 OUString sHeader
= m_pNewData
->aDBColumnHeaders
[nOldPos
];
156 m_pNewData
->aDBColumnHeaders
.erase(m_pNewData
->aDBColumnHeaders
.begin() + nOldPos
);
157 m_pNewData
->aDBColumnHeaders
.insert(m_pNewData
->aDBColumnHeaders
.begin() + nPos
, sHeader
);
158 ::std::vector
< ::std::vector
< OUString
> >::iterator aDataIter
;
159 for( aDataIter
= m_pNewData
->aDBData
.begin(); aDataIter
!= m_pNewData
->aDBData
.end(); ++aDataIter
)
161 OUString sData
= (*aDataIter
)[nOldPos
];
162 aDataIter
->erase(aDataIter
->begin() + nOldPos
);
163 aDataIter
->insert(aDataIter
->begin() + nPos
, sData
);
170 void SwCustomizeAddressListDialog::UpdateButtons()
172 sal_uInt16 nPos
= m_aFieldsLB
.GetSelectEntryPos();
173 sal_uInt16 nEntries
= m_aFieldsLB
.GetEntryCount();
174 m_aUpPB
.Enable(nPos
> 0 && nEntries
> 0);
175 m_aDownPB
.Enable(nPos
< nEntries
-1);
176 m_aDeletePB
.Enable(nEntries
> 0);
177 m_aRenamePB
.Enable(nEntries
> 0);
180 SwCSVData
* SwCustomizeAddressListDialog::GetNewData()
185 SwAddRenameEntryDialog::SwAddRenameEntryDialog(
186 Window
* pParent
, bool bRename
, const ::std::vector
< OUString
>& rCSVHeader
) :
187 SfxModalDialog(pParent
, SW_RES(DLG_MM_ADD_RENAME_ENTRY
)),
189 #pragma warning (disable : 4355)
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
)),
197 #pragma warning (default : 4355)
199 m_rCSVHeader(rCSVHeader
)
202 SetText(String(SW_RES(ST_RENAME_TITLE
)));
204 m_aOK
.SetText(String(SW_RES(ST_ADD_BUTTON
)));
206 m_aFieldNameED
.SetModifyHdl(LINK(this, SwAddRenameEntryDialog
, ModifyHdl_Impl
));
207 ModifyHdl_Impl( &m_aFieldNameED
);
210 SwAddRenameEntryDialog::~SwAddRenameEntryDialog()
214 IMPL_LINK(SwAddRenameEntryDialog
, ModifyHdl_Impl
, Edit
*, pEdit
)
216 OUString sEntry
= pEdit
->GetText();
217 sal_Bool bFound
= sEntry
.isEmpty();
221 ::std::vector
< OUString
>::const_iterator aHeaderIter
;
222 for(aHeaderIter
= m_rCSVHeader
.begin();
223 aHeaderIter
!= m_rCSVHeader
.end();
225 if(*aHeaderIter
== sEntry
)
231 m_aOK
.Enable(!bFound
);
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */