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( ); 185 virtual ::rtl::OUString SAL_CALL getPassword( ); 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 }; 204 /*-- 21.05.2004 10:39:20--------------------------------------------------- 205 206 -----------------------------------------------------------------------*/ 207 class SwMutexBase 208 { 209 public: 210 osl::Mutex m_aMutex; 211 }; 212 /*-- 21.05.2004 10:39:20--------------------------------------------------- 213 214 -----------------------------------------------------------------------*/ 215 class SW_DLLPUBLIC SwConnectionListener : 216 public SwMutexBase, 217 public cppu::WeakComponentImplHelper1< ::com::sun::star::mail::XConnectionListener > 218 { 219 using cppu::WeakComponentImplHelperBase::disposing; 220 221 public: SwConnectionListener()222 SwConnectionListener() : 223 cppu::WeakComponentImplHelper1< ::com::sun::star::mail::XConnectionListener>(m_aMutex) 224 {} 225 ~SwConnectionListener(); 226 227 virtual void SAL_CALL connected(const ::com::sun::star::lang::EventObject& aEvent); 228 229 virtual void SAL_CALL disconnected(const ::com::sun::star::lang::EventObject& aEvent); 230 231 virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& aEvent); 232 }; 233 234 /*-- 13.07.2004 09:02:12--------------------------------------------------- 235 236 -----------------------------------------------------------------------*/ 237 class SwMailTransferable : 238 public SwMutexBase, 239 public cppu::WeakComponentImplHelper2 240 < 241 ::com::sun::star::datatransfer::XTransferable, 242 ::com::sun::star::beans::XPropertySet 243 > 244 { 245 rtl::OUString m_aMimeType; 246 rtl::OUString m_sBody; 247 rtl::OUString m_aURL; 248 rtl::OUString m_aName; 249 bool m_bIsBody; 250 251 public: 252 SwMailTransferable(const rtl::OUString& rURL, const rtl::OUString& rName, const rtl::OUString& rMimeType); 253 SwMailTransferable(const rtl::OUString& rBody, const rtl::OUString& rMimeType); 254 ~SwMailTransferable(); 255 virtual ::com::sun::star::uno::Any SAL_CALL 256 getTransferData( const ::com::sun::star::datatransfer::DataFlavor& aFlavor ); 257 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::datatransfer::DataFlavor > SAL_CALL 258 getTransferDataFlavors( ) ; 259 virtual ::sal_Bool SAL_CALL 260 isDataFlavorSupported( const ::com::sun::star::datatransfer::DataFlavor& aFlavor ); 261 262 //XPropertySet 263 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ); 264 virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ); 265 virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ); 266 virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ); 267 virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ); 268 virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ); 269 virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ); 270 271 }; 272 273 /*-- 22.06.2004 16:38:34--------------------------------------------------- 274 275 -----------------------------------------------------------------------*/ 276 class SwMailMessage : 277 public SwMutexBase, 278 public cppu::WeakComponentImplHelper1< ::com::sun::star::mail::XMailMessage > 279 { 280 ::rtl::OUString m_sSenderName; 281 ::rtl::OUString m_sSenderAddress; 282 ::rtl::OUString m_sReplyToAddress; 283 ::rtl::OUString m_sSubject; 284 285 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable> m_xBody; 286 // ::com::sun::star::mail::MailMessageBody m_aBody; 287 288 ::com::sun::star::uno::Sequence< ::rtl::OUString > m_aRecipients; 289 ::com::sun::star::uno::Sequence< ::rtl::OUString > m_aCcRecipients; 290 ::com::sun::star::uno::Sequence< ::rtl::OUString > m_aBccRecipients; 291 // ::com::sun::star::uno::Sequence< ::com::sun::star::mail::MailAttachmentDescriptor > m_aAttachments; 292 ::com::sun::star::uno::Sequence< ::com::sun::star::mail::MailAttachment > m_aAttachments; 293 public: 294 SwMailMessage(); 295 ~SwMailMessage(); 296 297 // Attributes 298 virtual ::rtl::OUString SAL_CALL getSenderName(); 299 virtual ::rtl::OUString SAL_CALL getSenderAddress(); 300 virtual ::rtl::OUString SAL_CALL getReplyToAddress(); 301 virtual void SAL_CALL setReplyToAddress( const ::rtl::OUString& _replytoaddress ); 302 virtual ::rtl::OUString SAL_CALL getSubject(); 303 virtual void SAL_CALL setSubject( const ::rtl::OUString& _subject ); 304 305 virtual ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > SAL_CALL 306 getBody(); 307 virtual void SAL_CALL setBody( const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& _body ); 308 309 // Methods 310 virtual void SAL_CALL addRecipient( const ::rtl::OUString& sRecipientAddress ); 311 virtual void SAL_CALL addCcRecipient( const ::rtl::OUString& sRecipientAddress ); 312 virtual void SAL_CALL addBccRecipient( const ::rtl::OUString& sRecipientAddress ); 313 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL 314 getRecipients( ); 315 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL 316 getCcRecipients( ); 317 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL 318 getBccRecipients( ); 319 virtual void SAL_CALL addAttachment( const ::com::sun::star::mail::MailAttachment& aMailAttachment ); 320 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::mail::MailAttachment > SAL_CALL 321 getAttachments( ); SetSenderName(const::rtl::OUString & rSenderName)322 void SetSenderName(const ::rtl::OUString& rSenderName) 323 {m_sSenderName = rSenderName;} SetSenderAddress(const::rtl::OUString & rSenderAddress)324 void SetSenderAddress(const ::rtl::OUString& rSenderAddress) 325 {m_sSenderAddress = rSenderAddress;} 326 }; 327 /*-- 21.05.2004 10:17:22--------------------------------------------------- 328 329 -----------------------------------------------------------------------*/ 330 SW_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> 331 getCurrentCmpCtx( 332 ::com::sun::star::uno::Reference< 333 ::com::sun::star::lang::XMultiServiceFactory> rSrvMgr); 334 #endif 335