1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: customizeaddresslistdialog.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #ifdef SW_DLLIMPLEMENTATION
35 #undef SW_DLLIMPLEMENTATION
37 #include <swtypes.hxx>
38 #include <customizeaddresslistdialog.hxx>
39 #include <createaddresslistdialog.hxx>
40 #include <vcl/scrbar.hxx>
41 #include <vcl/msgbox.hxx>
42 #include <customizeaddresslistdialog.hrc>
48 /*-- 13.04.2004 14:27:21---------------------------------------------------
50 -----------------------------------------------------------------------*/
51 SwCustomizeAddressListDialog::SwCustomizeAddressListDialog(
52 Window
* pParent
, const SwCSVData
& rOldData
) :
53 SfxModalDialog(pParent
, SW_RES(DLG_MM_CUSTOMIZE_ADDRESS_LIST
)),
55 #pragma warning (disable : 4355)
57 m_aFieldsFT( this, SW_RES( FT_FIELDS
)),
58 m_aFieldsLB( this, SW_RES( LB_FIELDS
)),
59 m_aAddPB( this, SW_RES( PB_ADD
)),
60 m_aDeletePB( this, SW_RES( PB_DELETE
)),
61 m_aRenamePB( this, SW_RES( PB_RENAME
)),
62 m_aUpPB( this, SW_RES( PB_UP
)),
63 m_aDownPB( this, SW_RES( PB_DOWN
)),
64 m_aSeparatorFL( this, SW_RES( FL_SEPARATOR
)),
65 m_aOK( this, SW_RES( PB_OK
)),
66 m_aCancel( this, SW_RES( PB_CANCEL
)),
67 m_aHelp( this, SW_RES( PB_HELP
)),
69 #pragma warning (default : 4355)
71 m_pNewData( new SwCSVData(rOldData
))
74 m_aFieldsLB
.SetSelectHdl(LINK(this, SwCustomizeAddressListDialog
, ListBoxSelectHdl_Impl
));
75 Link aAddRenameLk
= LINK(this, SwCustomizeAddressListDialog
, AddRenameHdl_Impl
);
76 m_aAddPB
.SetClickHdl(aAddRenameLk
);
77 m_aRenamePB
.SetClickHdl(aAddRenameLk
);
78 m_aDeletePB
.SetClickHdl(LINK(this, SwCustomizeAddressListDialog
, DeleteHdl_Impl
));
79 Link aUpDownLk
= LINK(this, SwCustomizeAddressListDialog
, UpDownHdl_Impl
);
80 m_aUpPB
.SetClickHdl(aUpDownLk
);
81 m_aDownPB
.SetClickHdl(aUpDownLk
);
83 ::std::vector
< ::rtl::OUString
>::iterator aHeaderIter
;
85 for(aHeaderIter
= m_pNewData
->aDBColumnHeaders
.begin();
86 aHeaderIter
!= m_pNewData
->aDBColumnHeaders
.end(); ++aHeaderIter
)
87 m_aFieldsLB
.InsertEntry(*aHeaderIter
);
89 m_aFieldsLB
.SelectEntryPos(0);
92 /*-- 13.04.2004 14:34:07---------------------------------------------------
94 -----------------------------------------------------------------------*/
95 SwCustomizeAddressListDialog::~SwCustomizeAddressListDialog()
99 /*-- 12.08.2004 12:58:00---------------------------------------------------
101 -----------------------------------------------------------------------*/
102 IMPL_LINK(SwCustomizeAddressListDialog
, ListBoxSelectHdl_Impl
, ListBox
*, EMPTYARG
)
107 /*-- 13.04.2004 15:02:14---------------------------------------------------
109 -----------------------------------------------------------------------*/
110 IMPL_LINK(SwCustomizeAddressListDialog
, AddRenameHdl_Impl
, PushButton
*, pButton
)
112 bool bRename
= pButton
== &m_aRenamePB
;
113 USHORT nPos
= m_aFieldsLB
.GetSelectEntryPos();
114 if(nPos
== LISTBOX_ENTRY_NOTFOUND
)
117 SwAddRenameEntryDialog
* pDlg
=
118 new SwAddRenameEntryDialog(pButton
, bRename
, m_pNewData
->aDBColumnHeaders
);
121 String aTemp
= m_aFieldsLB
.GetEntry(nPos
);
122 pDlg
->SetFieldName(aTemp
);
124 if(RET_OK
== pDlg
->Execute())
126 String sNew
= pDlg
->GetFieldName();
129 m_pNewData
->aDBColumnHeaders
[nPos
] = sNew
;
130 m_aFieldsLB
.RemoveEntry(nPos
);
134 if ( m_aFieldsLB
.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND
)
135 ++nPos
; // append the new entry behind the selected
137 m_pNewData
->aDBColumnHeaders
.insert(m_pNewData
->aDBColumnHeaders
.begin() + nPos
, sNew
);
138 //add a new entry into all data arrays
140 ::std::vector
< ::std::vector
< ::rtl::OUString
> >::iterator aDataIter
;
141 for( aDataIter
= m_pNewData
->aDBData
.begin(); aDataIter
!= m_pNewData
->aDBData
.end(); ++aDataIter
)
142 aDataIter
->insert(aDataIter
->begin() + nPos
, sTemp
);
146 m_aFieldsLB
.InsertEntry(sNew
, nPos
);
147 m_aFieldsLB
.SelectEntryPos(nPos
);
153 /*-- 13.04.2004 15:02:14---------------------------------------------------
155 -----------------------------------------------------------------------*/
156 IMPL_LINK(SwCustomizeAddressListDialog
, DeleteHdl_Impl
, PushButton
*, EMPTYARG
)
158 USHORT nPos
= m_aFieldsLB
.GetSelectEntryPos();
159 m_aFieldsLB
.RemoveEntry(m_aFieldsLB
.GetSelectEntryPos());
160 m_aFieldsLB
.SelectEntryPos(nPos
> m_aFieldsLB
.GetEntryCount() - 1 ? nPos
- 1 : nPos
);
163 m_pNewData
->aDBColumnHeaders
.erase(m_pNewData
->aDBColumnHeaders
.begin() + nPos
);
165 ::std::vector
< ::std::vector
< ::rtl::OUString
> >::iterator aDataIter
;
166 for( aDataIter
= m_pNewData
->aDBData
.begin(); aDataIter
!= m_pNewData
->aDBData
.end(); ++aDataIter
)
167 aDataIter
->erase(aDataIter
->begin() + nPos
);
172 /*-- 13.04.2004 15:02:15---------------------------------------------------
174 -----------------------------------------------------------------------*/
175 IMPL_LINK(SwCustomizeAddressListDialog
, UpDownHdl_Impl
, PushButton
*, pButton
)
178 USHORT nOldPos
= nPos
= m_aFieldsLB
.GetSelectEntryPos();
179 String aTemp
= m_aFieldsLB
.GetEntry(nPos
);
180 m_aFieldsLB
.RemoveEntry( nPos
);
181 if(pButton
== &m_aUpPB
)
185 m_aFieldsLB
.InsertEntry(aTemp
, nPos
);
186 m_aFieldsLB
.SelectEntryPos(nPos
);
188 ::rtl::OUString sHeader
= m_pNewData
->aDBColumnHeaders
[nOldPos
];
189 m_pNewData
->aDBColumnHeaders
.erase(m_pNewData
->aDBColumnHeaders
.begin() + nOldPos
);
190 m_pNewData
->aDBColumnHeaders
.insert(m_pNewData
->aDBColumnHeaders
.begin() + nPos
, sHeader
);
191 ::std::vector
< ::std::vector
< ::rtl::OUString
> >::iterator aDataIter
;
192 for( aDataIter
= m_pNewData
->aDBData
.begin(); aDataIter
!= m_pNewData
->aDBData
.end(); ++aDataIter
)
194 ::rtl::OUString sData
= (*aDataIter
)[nOldPos
];
195 aDataIter
->erase(aDataIter
->begin() + nOldPos
);
196 aDataIter
->insert(aDataIter
->begin() + nPos
, sData
);
202 /*-- 19.04.2004 14:51:49---------------------------------------------------
204 -----------------------------------------------------------------------*/
205 void SwCustomizeAddressListDialog::UpdateButtons()
207 USHORT nPos
= m_aFieldsLB
.GetSelectEntryPos();
208 USHORT nEntries
= m_aFieldsLB
.GetEntryCount();
209 m_aUpPB
.Enable(nPos
> 0 && nEntries
> 0);
210 m_aDownPB
.Enable(nPos
< nEntries
-1);
211 m_aDeletePB
.Enable(nEntries
> 0);
212 m_aRenamePB
.Enable(nEntries
> 0);
214 /*-- 19.04.2004 14:51:49---------------------------------------------------
216 -----------------------------------------------------------------------*/
217 SwCSVData
* SwCustomizeAddressListDialog::GetNewData()
222 /*-- 13.04.2004 13:48:41---------------------------------------------------
224 -----------------------------------------------------------------------*/
225 SwAddRenameEntryDialog::SwAddRenameEntryDialog(
226 Window
* pParent
, bool bRename
, const ::std::vector
< ::rtl::OUString
>& rCSVHeader
) :
227 SfxModalDialog(pParent
, SW_RES(DLG_MM_ADD_RENAME_ENTRY
)),
229 #pragma warning (disable : 4355)
231 m_aFieldNameFT( this, SW_RES( FT_FIELDNAME
)),
232 m_aFieldNameED( this, SW_RES( ED_FIELDNAME
)),
233 m_aOK( this, SW_RES( PB_OK
)),
234 m_aCancel( this, SW_RES( PB_CANCEL
)),
235 m_aHelp( this, SW_RES( PB_HELP
)),
237 #pragma warning (default : 4355)
239 m_rCSVHeader(rCSVHeader
)
242 SetText(String(SW_RES(ST_RENAME_TITLE
)));
244 m_aOK
.SetText(String(SW_RES(ST_ADD_BUTTON
)));
246 m_aFieldNameED
.SetModifyHdl(LINK(this, SwAddRenameEntryDialog
, ModifyHdl_Impl
));
247 ModifyHdl_Impl( &m_aFieldNameED
);
249 /*-- 13.04.2004 13:48:41---------------------------------------------------
251 -----------------------------------------------------------------------*/
252 SwAddRenameEntryDialog::~SwAddRenameEntryDialog()
255 /*-- 19.04.2004 15:31:34---------------------------------------------------
257 -----------------------------------------------------------------------*/
258 IMPL_LINK(SwAddRenameEntryDialog
, ModifyHdl_Impl
, Edit
*, pEdit
)
260 ::rtl::OUString sEntry
= pEdit
->GetText();
261 BOOL bFound
= sEntry
.getLength() ? FALSE
: TRUE
;
265 ::std::vector
< ::rtl::OUString
>::const_iterator aHeaderIter
;
266 for(aHeaderIter
= m_rCSVHeader
.begin();
267 aHeaderIter
!= m_rCSVHeader
.end();
269 if(*aHeaderIter
== sEntry
)
275 m_aOK
.Enable(!bFound
);