xref: /aoo41x/main/sw/source/ui/inc/mailmergehelper.hxx (revision 1d2dbeb0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _MAILMERGEHELPER_HXX
24 #define _MAILMERGEHELPER_HXX
25 
26 #include <svtools/stdctrl.hxx>
27 #include <unotools/configitem.hxx>
28 #include <com/sun/star/uno/Sequence.h>
29 #include "com/sun/star/mail/XAuthenticator.hpp"
30 #include "com/sun/star/mail/XConnectionListener.hpp"
31 #include "com/sun/star/uno/XCurrentContext.hpp"
32 #include "com/sun/star/mail/XMailMessage.hpp"
33 #include "com/sun/star/datatransfer/XTransferable.hpp"
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <cppuhelper/implbase1.hxx>
36 #include <cppuhelper/compbase1.hxx>
37 #include <cppuhelper/compbase2.hxx>
38 #include <vcl/scrbar.hxx>
39 #include "swdllapi.h"
40 
41 
42 class SwMailMergeConfigItem;
43 namespace com{ namespace sun{ namespace star{
44     namespace uno{
45         class XComponentContext;
46     }
47     namespace lang{
48         class XMultiServiceFactory;
49     }
50     namespace mail{
51         class XSmtpService;
52         class XMailService;
53     }
54 }}}
55 /*-- 14.06.2004 12:27:42---------------------------------------------------
56 
57   -----------------------------------------------------------------------*/
58 namespace SwMailMergeHelper
59 {
60     SW_DLLPUBLIC String  CallSaveAsDialog(String& rFilter);
61     SW_DLLPUBLIC bool    CheckMailAddress( const ::rtl::OUString& rMailAddress );
62     SW_DLLPUBLIC com::sun::star::uno::Reference< com::sun::star::mail::XSmtpService >
63                          ConnectToSmtpServer( SwMailMergeConfigItem& rConfigItem,
64                             com::sun::star::uno::Reference< com::sun::star::mail::XMailService >&  xInMailService,
65                             const String& rInMailServerPassword,
66                             const String& rOutMailServerPassword,
67                             Window* pDialogParentWindow = 0 );
68 }
69 /* -----------------06.04.2004 10:29-----------------
70 
71  --------------------------------------------------*/
72 class SW_DLLPUBLIC SwBoldFixedInfo : public FixedInfo
73 {
74 public:
75     SwBoldFixedInfo(Window* pParent, const ResId& rResId);
76     ~SwBoldFixedInfo();
77 };
78 struct SwAddressPreview_Impl;
79 namespace com{namespace sun{namespace star{
80     namespace container{
81         class XNameAccess;
82     }
83 }}}
84 
85 /*-- 27.04.2004 13:20:00---------------------------------------------------
86     Preview window used to show the possible selection of address blocks
87     and also the resulting address filled with database data
88   -----------------------------------------------------------------------*/
89 class SW_DLLPUBLIC SwAddressPreview : public Window
90 {
91     ScrollBar               aVScrollBar;
92     SwAddressPreview_Impl*  pImpl;
93     Link                    m_aSelectHdl;
94 
95     void DrawText_Impl( const ::rtl::OUString& rAddress, const Point& rTopLeft, const Size& rSize, bool bIsSelected);
96 
97     virtual void        Paint(const Rectangle&);
98     virtual void        MouseButtonDown( const MouseEvent& rMEvt );
99     virtual void        KeyInput( const KeyEvent& rKEvt );
100     virtual void        StateChanged( StateChangedType nStateChange );
101     void                UpdateScrollBar();
102 
103     DECL_LINK(ScrollHdl, ScrollBar*);
104 
105 public:
106     SwAddressPreview(Window* pParent, const ResId rResId);
107     ~SwAddressPreview();
108 
109     /** The address string is a list of address elements separated by spaces
110     and breaks. The addresses fit into the given layout. If more addresses then
111     rows/columns should be used a scrollbar will be added.
112 
113      AddAddress appends the new address to the already added ones.
114      Initially the first added address will be selected
115     */
116     void                    AddAddress(const ::rtl::OUString& rAddress);
117     //  for preview mode - replaces the currently used address by the given one
118     void                    SetAddress(const ::rtl::OUString& rAddress);
119     // removes all addresses
120     void                    Clear();
121 
122     // returns the selected address
123     sal_uInt16              GetSelectedAddress() const;
124     void                    SelectAddress(sal_uInt16 nSelect);
125     void                    ReplaceSelectedAddress(const ::rtl::OUString&);
126     void                    RemoveSelectedAddress();
127 
128     // set the number of rows and columns of addresses
129     void                    SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns);
130     void                    EnableScrollBar(bool bEnable = true);
131 
132     // fill the actual data into a string (address block or greeting)
133     static String FillData(
134             const ::rtl::OUString& rAddress,
135             SwMailMergeConfigItem& rConfigItem,
136             const ::com::sun::star::uno::Sequence< ::rtl::OUString>* pAssignments = 0);
137 
SetSelectHdl(const Link & rLink)138     void    SetSelectHdl (const Link& rLink) {m_aSelectHdl = rLink;}
139 };
140 
141 /*-- 11.05.2004 15:39:59---------------------------------------------------
142     iterate over an address block or a greeting line
143     the iterator returns the parts either as pure string
144     or as column
145   -----------------------------------------------------------------------*/
146 struct SwMergeAddressItem
147 {
148     String  sText;
149     bool    bIsColumn;
150     bool    bIsReturn;
SwMergeAddressItemSwMergeAddressItem151     SwMergeAddressItem() :
152         bIsColumn(false),
153         bIsReturn(false) {}
154 };
155 class SW_DLLPUBLIC   SwAddressIterator
156 {
157     String sAddress;
158 public:
SwAddressIterator(const String & rAddress)159     SwAddressIterator(const String& rAddress) :
160         sAddress(rAddress){}
161 
162     SwMergeAddressItem  Next();
HasMore() const163     bool                HasMore() const{return sAddress.Len() > 0;}
164 };
165 
166 /*-- 21.05.2004 10:31:15---------------------------------------------------
167 
168   -----------------------------------------------------------------------*/
169 class SW_DLLPUBLIC SwAuthenticator :
170     public cppu::WeakImplHelper1< ::com::sun::star::mail::XAuthenticator>
171 {
172     ::rtl::OUString m_aUserName;
173     ::rtl::OUString m_aPassword;
174     Window*         m_pParentWindow;
175 public:
SwAuthenticator()176     SwAuthenticator() : m_pParentWindow(0) {}
SwAuthenticator(const::rtl::OUString & username,const::rtl::OUString & password,Window * pParent)177     SwAuthenticator(const ::rtl::OUString& username, const ::rtl::OUString& password, Window* pParent) :
178         m_aUserName(username),
179         m_aPassword(password),
180         m_pParentWindow( pParent )
181     {}
182     ~SwAuthenticator();
183 
184     virtual ::rtl::OUString SAL_CALL getUserName( ) throw (::com::sun::star::uno::RuntimeException);
185     virtual ::rtl::OUString SAL_CALL getPassword(  ) throw (::com::sun::star::uno::RuntimeException);
186 
187 };
188 /*-- 25.08.2004 12:48:47---------------------------------------------------
189 
190   -----------------------------------------------------------------------*/
191 class SW_DLLPUBLIC SwConnectionContext :
192     public cppu::WeakImplHelper1< ::com::sun::star::uno::XCurrentContext >
193 {
194     ::rtl::OUString     m_sMailServer;
195     sal_Int16           m_nPort;
196     ::rtl::OUString     m_sConnectionType;
197 
198 public:
199     SwConnectionContext(const ::rtl::OUString& rMailServer, sal_Int16 nPort, const ::rtl::OUString& rConnectionType);
200     ~SwConnectionContext();
201 
202     virtual ::com::sun::star::uno::Any SAL_CALL     getValueByName( const ::rtl::OUString& Name )
203                                                             throw (::com::sun::star::uno::RuntimeException);
204 };
205 /*-- 21.05.2004 10:39:20---------------------------------------------------
206 
207   -----------------------------------------------------------------------*/
208 class SwMutexBase
209 {
210 public:
211     osl::Mutex m_aMutex;
212 };
213 /*-- 21.05.2004 10:39:20---------------------------------------------------
214 
215   -----------------------------------------------------------------------*/
216 class SW_DLLPUBLIC SwConnectionListener :
217         public SwMutexBase,
218         public cppu::WeakComponentImplHelper1< ::com::sun::star::mail::XConnectionListener >
219 {
220     using cppu::WeakComponentImplHelperBase::disposing;
221 
222 public:
SwConnectionListener()223     SwConnectionListener() :
224         cppu::WeakComponentImplHelper1< ::com::sun::star::mail::XConnectionListener>(m_aMutex)
225     {}
226     ~SwConnectionListener();
227 
228     virtual void SAL_CALL connected(const ::com::sun::star::lang::EventObject& aEvent)
229         throw (::com::sun::star::uno::RuntimeException);
230 
231     virtual void SAL_CALL disconnected(const ::com::sun::star::lang::EventObject& aEvent)
232         throw (::com::sun::star::uno::RuntimeException);
233 
234     virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& aEvent)
235         throw(com::sun::star::uno::RuntimeException);
236 };
237 
238 /*-- 13.07.2004 09:02:12---------------------------------------------------
239 
240   -----------------------------------------------------------------------*/
241 class SwMailTransferable :
242         public SwMutexBase,
243         public cppu::WeakComponentImplHelper2
244         <
245             ::com::sun::star::datatransfer::XTransferable,
246             ::com::sun::star::beans::XPropertySet
247         >
248 {
249     rtl::OUString  m_aMimeType;
250     rtl::OUString  m_sBody;
251     rtl::OUString  m_aURL;
252     rtl::OUString  m_aName;
253     bool           m_bIsBody;
254 
255     public:
256     SwMailTransferable(const rtl::OUString& rURL, const rtl::OUString& rName, const rtl::OUString& rMimeType);
257     SwMailTransferable(const rtl::OUString& rBody, const rtl::OUString& rMimeType);
258     ~SwMailTransferable();
259     virtual ::com::sun::star::uno::Any SAL_CALL
260                         getTransferData( const ::com::sun::star::datatransfer::DataFlavor& aFlavor )
261                             throw (::com::sun::star::datatransfer::UnsupportedFlavorException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
262     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::datatransfer::DataFlavor > SAL_CALL
263                         getTransferDataFlavors(  )
264                             throw (::com::sun::star::uno::RuntimeException) ;
265     virtual ::sal_Bool SAL_CALL
266                         isDataFlavorSupported( const ::com::sun::star::datatransfer::DataFlavor& aFlavor )
267                             throw (::com::sun::star::uno::RuntimeException);
268 
269     //XPropertySet
270     virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
271     virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
272     virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
273     virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
274     virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
275     virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
276     virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
277 
278 };
279 
280 /*-- 22.06.2004 16:38:34---------------------------------------------------
281 
282   -----------------------------------------------------------------------*/
283 class SwMailMessage :
284         public SwMutexBase,
285         public cppu::WeakComponentImplHelper1< ::com::sun::star::mail::XMailMessage >
286 {
287     ::rtl::OUString                                                                         m_sSenderName;
288     ::rtl::OUString                                                                         m_sSenderAddress;
289     ::rtl::OUString                                                                         m_sReplyToAddress;
290     ::rtl::OUString                                                                         m_sSubject;
291 
292     ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable>        m_xBody;
293 //    ::com::sun::star::mail::MailMessageBody                                                 m_aBody;
294 
295     ::com::sun::star::uno::Sequence< ::rtl::OUString >                                      m_aRecipients;
296     ::com::sun::star::uno::Sequence< ::rtl::OUString >                                      m_aCcRecipients;
297     ::com::sun::star::uno::Sequence< ::rtl::OUString >                                      m_aBccRecipients;
298 //    ::com::sun::star::uno::Sequence< ::com::sun::star::mail::MailAttachmentDescriptor >     m_aAttachments;
299     ::com::sun::star::uno::Sequence<  ::com::sun::star::mail::MailAttachment >              m_aAttachments;
300 public:
301     SwMailMessage();
302     ~SwMailMessage();
303 
304     // Attributes
305     virtual ::rtl::OUString SAL_CALL    getSenderName() throw (::com::sun::star::uno::RuntimeException);
306     virtual ::rtl::OUString SAL_CALL    getSenderAddress() throw (::com::sun::star::uno::RuntimeException);
307     virtual ::rtl::OUString SAL_CALL    getReplyToAddress() throw (::com::sun::star::uno::RuntimeException);
308     virtual void SAL_CALL               setReplyToAddress( const ::rtl::OUString& _replytoaddress ) throw (::com::sun::star::uno::RuntimeException);
309     virtual ::rtl::OUString SAL_CALL    getSubject() throw (::com::sun::star::uno::RuntimeException);
310     virtual void SAL_CALL               setSubject( const ::rtl::OUString& _subject ) throw (::com::sun::star::uno::RuntimeException);
311 
312     virtual ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > SAL_CALL
313                                         getBody()
314                                                 throw (::com::sun::star::uno::RuntimeException);
315     virtual void SAL_CALL               setBody( const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& _body )
316                                                 throw (::com::sun::star::uno::RuntimeException);
317 
318     // Methods
319     virtual void SAL_CALL               addRecipient( const ::rtl::OUString& sRecipientAddress ) throw (::com::sun::star::uno::RuntimeException);
320     virtual void SAL_CALL               addCcRecipient( const ::rtl::OUString& sRecipientAddress ) throw (::com::sun::star::uno::RuntimeException);
321     virtual void SAL_CALL               addBccRecipient( const ::rtl::OUString& sRecipientAddress ) throw (::com::sun::star::uno::RuntimeException);
322     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
323                                         getRecipients(  ) throw (::com::sun::star::uno::RuntimeException);
324     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
325                                         getCcRecipients(  ) throw (::com::sun::star::uno::RuntimeException);
326     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
327                                         getBccRecipients(  ) throw (::com::sun::star::uno::RuntimeException);
328     virtual void SAL_CALL               addAttachment( const ::com::sun::star::mail::MailAttachment& aMailAttachment )
329                                             throw (::com::sun::star::uno::RuntimeException);
330     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::mail::MailAttachment > SAL_CALL
331                                         getAttachments(  ) throw (::com::sun::star::uno::RuntimeException);
SetSenderName(const::rtl::OUString & rSenderName)332     void                                SetSenderName(const ::rtl::OUString& rSenderName)
333                                                 {m_sSenderName = rSenderName;}
SetSenderAddress(const::rtl::OUString & rSenderAddress)334     void                                SetSenderAddress(const ::rtl::OUString& rSenderAddress)
335                                                 {m_sSenderAddress = rSenderAddress;}
336 };
337 /*-- 21.05.2004 10:17:22---------------------------------------------------
338 
339   -----------------------------------------------------------------------*/
340 SW_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext>
341         getCurrentCmpCtx(
342             ::com::sun::star::uno::Reference<
343                 ::com::sun::star::lang::XMultiServiceFactory> rSrvMgr);
344 #endif
345 
346