1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _MAILMERGEADDRESSBLOCKPAGE_HXX
28 #define _MAILMERGEADDRESSBLOCKPAGE_HXX
29 
30 #include <svtools/wizardmachine.hxx>
31 #ifndef _SV_BUTTON_HXX
32 #include <vcl/button.hxx>
33 #endif
34 #include <svtools/stdctrl.hxx>
35 #include <mailmergehelper.hxx>
36 #include <sfx2/basedlgs.hxx>
37 #include <vcl/edit.hxx>
38 #include <vcl/lstbox.hxx>
39 #include <svtools/svmedit.hxx>
40 #include <svtools/headbar.hxx>
41 #include <svtools/svtreebx.hxx>
42 #include <vcl/combobox.hxx>
43 #include <svl/lstner.hxx>
44 class SwMailMergeWizard;
45 class SwMailMergeConfigItem;
46 /*-- 13.04.2004 15:50:37---------------------------------------------------
47 
48   -----------------------------------------------------------------------*/
49 class SwMailMergeAddressBlockPage : public svt::OWizardPage
50 {
51     SwBoldFixedInfo     m_aHeaderFI;
52     FixedInfo           m_aFirstFI;
53     FixedInfo           m_aAddressListFI;
54     PushButton          m_aAddressListPB;
55     FixedInfo           m_aCurrentAddressFI;
56 
57     FixedLine           m_aFirstFL;
58 
59     FixedInfo           m_aSecondFI;
60     FixedInfo           m_aSettingsFI;
61     CheckBox            m_aAddressCB;
62     SwAddressPreview    m_aSettingsWIN;
63     PushButton          m_aSettingsPB;
64 
65     CheckBox            m_aHideEmptyParagraphsCB;
66 
67     FixedLine           m_aSecondFL;
68 
69     FixedInfo           m_aThirdFI;
70     FixedInfo           m_aMatchFieldsFI;
71 
72     PushButton          m_aAssignPB;
73 
74     FixedLine           m_aThirdFL;
75 
76     FixedInfo           m_aFourthFI;
77     FixedInfo           m_aPreviewFI;
78 
79     SwAddressPreview    m_aPreviewWIN;
80     FixedInfo           m_aDocumentIndexFI;
81     ImageButton         m_aPrevSetIB;
82     ImageButton         m_aNextSetIB;
83 
84     String              m_sDocument;
85     String              m_sCurrentAddress;
86     String              m_sChangeAddress;
87 
88     SwMailMergeWizard*  m_pWizard;
89 
90     DECL_LINK(AddressListHdl_Impl, PushButton*);
91     DECL_LINK(SettingsHdl_Impl, PushButton*);
92     DECL_LINK(AssignHdl_Impl, PushButton*);
93     DECL_LINK(AddressBlockHdl_Impl, CheckBox*);
94     DECL_LINK(InsertDataHdl_Impl, ImageButton*);
95     DECL_LINK(AddressBlockSelectHdl_Impl, SwAddressPreview*);
96     DECL_LINK(HideParagraphsHdl_Impl, CheckBox*);
97 
98     void                EnableAddressBlock(sal_Bool bAll, sal_Bool bSelective);
99 
100     virtual void        ActivatePage();
101     virtual sal_Bool    commitPage( ::svt::WizardTypes::CommitPageReason _eReason );
102 	virtual bool        canAdvance() const;
103 
104 public:
105     SwMailMergeAddressBlockPage( SwMailMergeWizard* _pParent);
106     ~SwMailMergeAddressBlockPage();
107 
108     SwMailMergeWizard*  GetWizard() { return m_pWizard;}
109 };
110 /*-- 13.04.2004 15:45:31---------------------------------------------------
111 
112   -----------------------------------------------------------------------*/
113 class SwSelectAddressBlockDialog : public SfxModalDialog
114 {
115     FixedText           m_aSelectFT;
116     SwAddressPreview    m_aPreview;
117     PushButton          m_aNewPB;
118     PushButton          m_aCustomizePB;
119     PushButton          m_aDeletePB;
120 
121     FixedInfo           m_aSettingsFI;
122     RadioButton         m_aNeverRB;
123     RadioButton         m_aAlwaysRB;
124     RadioButton         m_aDependentRB;
125     Edit                m_aCountryED;
126 
127     FixedLine           m_aSeparatorFL;
128 
129     OKButton            m_aOK;
130     CancelButton        m_aCancel;
131     HelpButton          m_aHelp;
132 
133     com::sun::star::uno::Sequence< ::rtl::OUString>    m_aAddressBlocks;
134     SwMailMergeConfigItem& m_rConfig;
135 
136     DECL_LINK(NewCustomizeHdl_Impl, PushButton*);
137     DECL_LINK(DeleteHdl_Impl, PushButton*);
138     DECL_LINK(IncludeHdl_Impl, RadioButton*);
139 
140     using Window::SetSettings;
141 
142 public:
143     SwSelectAddressBlockDialog(Window* pParent, SwMailMergeConfigItem& rConfig);
144     ~SwSelectAddressBlockDialog();
145 
146     void    SetAddressBlocks(const com::sun::star::uno::Sequence< ::rtl::OUString>& rBlocks,
147                                 sal_uInt16 nSelected);
148     const com::sun::star::uno::Sequence< ::rtl::OUString>&    GetAddressBlocks();
149 
150     void                SetSettings(sal_Bool bIsCountry, ::rtl::OUString sCountry);
151     sal_Bool            IsIncludeCountry() const {return !m_aNeverRB.IsChecked();}
152     ::rtl::OUString     GetCountry() const;
153 };
154 
155 
156 /*-- 26.05.2004 11:16:25---------------------------------------------------
157 
158   -----------------------------------------------------------------------*/
159 class SwCustomizeAddressBlockDialog;
160 class DDListBox : public SvTreeListBox
161 {
162     SwCustomizeAddressBlockDialog*   m_pParentDialog;
163 public:
164     DDListBox(SwCustomizeAddressBlockDialog* pParent, const ResId rResId);
165     ~DDListBox();
166 
167     virtual void        StartDrag( sal_Int8 nAction, const Point& rPosPixel );
168 };
169 /*-- 26.05.2004 11:16:25---------------------------------------------------
170 
171   -----------------------------------------------------------------------*/
172 #define MOVE_ITEM_LEFT           1
173 #define MOVE_ITEM_RIGHT          2
174 #define MOVE_ITEM_UP             4
175 #define MOVE_ITEM_DOWN           8
176 
177 class AddressMultiLineEdit : public MultiLineEdit, public SfxListener
178 {
179     Link                            m_aSelectionLink;
180     SwCustomizeAddressBlockDialog*  m_pParentDialog;
181 
182     using Window::Notify;
183 
184     using MultiLineEdit::SetText;
185 
186 protected:
187     long            PreNotify( NotifyEvent& rNEvt );
188 public:
189     AddressMultiLineEdit(SwCustomizeAddressBlockDialog* pParent, const ResId& rResId);
190     ~AddressMultiLineEdit();
191 
192     virtual void    Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
193 
194     void            SetSelectionChangedHdl( const Link& rLink ) {m_aSelectionLink = rLink;}
195 
196     void            SetText( const String& rStr );
197     String          GetAddress();
198 
199     void            InsertNewEntry( const String& rStr );
200     void            InsertNewEntryAtPosition( const String& rStr, sal_uLong nPara, sal_uInt16 nIndex );
201     void            RemoveCurrentEntry();
202 
203     void            MoveCurrentItem(sal_uInt16 nMove);
204     sal_uInt16      IsCurrentItemMoveable();
205     bool            HasCurrentItem();
206     String          GetCurrentItem();
207     void            SelectCurrentItem();
208 };
209 /*-- 13.04.2004 15:45:31---------------------------------------------------
210     Dialog is used to create custom address blocks as well as
211     custom greeting lines
212   -----------------------------------------------------------------------*/
213 class SwRestrictedComboBox : public ComboBox
214 {
215 	String sForbiddenChars;
216 
217 protected:
218 	virtual void KeyInput( const KeyEvent& );
219 	virtual void		Modify();
220 public:
221     SwRestrictedComboBox(Window* pParent, const ResId& rResId):
222         ComboBox( pParent, rResId ){}
223 
224     ~SwRestrictedComboBox();
225 
226 	void			SetForbiddenChars(const String& rSet){sForbiddenChars = rSet;}
227 
228 };
229 class SwCustomizeAddressBlockDialog : public SfxModalDialog
230 {
231     friend class DDListBox;
232     friend class AddressMultiLineEdit;
233 public:
234     enum DialogType
235     {
236         ADDRESSBLOCK_NEW,
237         ADDRESSBLOCK_EDIT,
238         GREETING_FEMALE,
239         GREETING_MALE
240     };
241 private:
242     FixedText       m_aAddressElementsFT;
243     DDListBox       m_aAddressElementsLB;
244 
245     ImageButton     m_aInsertFieldIB;
246     ImageButton     m_aRemoveFieldIB;
247 
248     FixedText               m_aDragFT;
249     AddressMultiLineEdit    m_aDragED;
250     ImageButton             m_aUpIB;
251     ImageButton             m_aLeftIB;
252     ImageButton             m_aRightIB;
253     ImageButton             m_aDownIB;
254 
255     FixedText               m_aFieldFT;
256     SwRestrictedComboBox    m_aFieldCB;
257 
258     FixedInfo               m_aPreviewFI;
259     SwAddressPreview        m_aPreviewWIN;
260 
261     FixedLine               m_aSeparatorFL;
262 
263     OKButton                m_aOK;
264     CancelButton            m_aCancel;
265     HelpButton              m_aHelp;
266 
267     ::std::vector<String>   m_aSalutations;
268     ::std::vector<String>   m_aPunctuations;
269 
270     String                  m_sCurrentSalutation;
271     String                  m_sCurrentPunctuation;
272     String                  m_sCurrentText;
273 
274     SwMailMergeConfigItem&  m_rConfigItem;
275     DialogType              m_eType;
276 
277     DECL_LINK(OKHdl_Impl, OKButton*);
278     DECL_LINK(ListBoxSelectHdl_Impl, DDListBox*);
279     DECL_LINK(EditModifyHdl_Impl, AddressMultiLineEdit*);
280     DECL_LINK(ImageButtonHdl_Impl, ImageButton*);
281     DECL_LINK(SelectionChangedHdl_Impl, AddressMultiLineEdit*);
282     DECL_LINK(FieldChangeHdl_Impl, ComboBox*);
283 
284     bool            HasItem_Impl(sal_Int32 nUserData);
285     sal_Int32       GetSelectedItem_Impl();
286     void            UpdateImageButtons_Impl();
287     void            MoveFocus( Window* pMember, bool bNext );
288 
289 public:
290     SwCustomizeAddressBlockDialog(Window* pParent, SwMailMergeConfigItem& rConfig, DialogType);
291     ~SwCustomizeAddressBlockDialog();
292 
293     void            SetAddress(const ::rtl::OUString& rAddress);
294     ::rtl::OUString GetAddress();
295 };
296 /*-- 13.04.2004 17:41:11---------------------------------------------------
297 
298   -----------------------------------------------------------------------*/
299 class SwAssignFieldsControl;
300 class SwAssignFieldsDialog : public SfxModalDialog
301 {
302     FixedInfo               m_aMatchingFI;
303     SwAssignFieldsControl*  m_pFieldsControl;
304 
305     FixedInfo               m_aPreviewFI;
306     SwAddressPreview        m_aPreviewWIN;
307 
308     FixedLine               m_aSeparatorFL;
309 
310     OKButton                m_aOK;
311     CancelButton            m_aCancel;
312     HelpButton              m_aHelp;
313 
314     String                  m_sNone;
315     ::rtl::OUString         m_rPreviewString;
316 
317     SwMailMergeConfigItem&  m_rConfigItem;
318 
319     ::com::sun::star::uno::Sequence< ::rtl::OUString > CreateAssignments();
320     DECL_LINK(OkHdl_Impl, PushButton*);
321     DECL_LINK(AssignmentModifyHdl_Impl, void*);
322 
323 public:
324     SwAssignFieldsDialog(Window* pParent,
325                 SwMailMergeConfigItem& rConfigItem,
326                 const ::rtl::OUString& rPreview,
327                 bool bIsAddressBlock);
328     ~SwAssignFieldsDialog();
329 };
330 #endif
331 
332 
333