merge the formfield patch from ooo-build
[ooovba.git] / sw / inc / dbmgr.hxx
blobdc464837b533b0103303c2134f7f24c774194e87
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dbmgr.hxx,v $
10 * $Revision: 1.37 $
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 ************************************************************************/
30 #ifndef _SWDBMGR_HXX
31 #define _SWDBMGR_HXX
34 #include <tools/string.hxx>
35 #include <tools/link.hxx>
36 #include <svtools/svarray.hxx>
37 #include <com/sun/star/util/Date.hpp>
38 #include "swdllapi.h"
39 #include <swdbdata.hxx>
40 #include <com/sun/star/uno/Reference.h>
41 #include <com/sun/star/uno/Sequence.hxx>
42 #include <com/sun/star/lang/Locale.hpp>
43 #include <com/sun/star/beans/PropertyValue.hpp>
44 namespace com{namespace sun{namespace star{
45 namespace sdbc{
46 class XConnection;
47 class XStatement;
48 class XDataSource;
49 class XResultSet;
51 namespace beans{
53 class XPropertySet;
54 struct PropertyValue;
56 namespace sdbcx{
57 class XColumnsSupplier;
59 namespace util{
60 class XNumberFormatter;
62 namespace mail{
63 class XSmtpService;
65 }}}
66 namespace svx {
67 class ODataAccessDescriptor;
70 struct SwDBFormatData
72 com::sun::star::util::Date aNullDate;
73 com::sun::star::uno::Reference< com::sun::star::util::XNumberFormatter> xFormatter;
74 com::sun::star::lang::Locale aLocale;
77 class SwView;
78 class SwWrtShell;
79 class SwPrtOptions;
80 class SfxProgress;
81 class ListBox;
82 class Button;
83 class SvNumberFormatter;
84 class SwDbtoolsClient;
85 class SwXMailMerge;
86 class SwMailMergeConfigItem;
88 // -----------------------------------------------------------------------
90 enum DBMgrOptions
92 DBMGR_MERGE, // Datensaetze in Felder
93 DBMGR_INSERT, // Datensaetze in Text
94 DBMGR_MERGE_MAILMERGE, // Serienbriefe drucken
95 DBMGR_MERGE_MAILING, // Serienbriefe als email versenden
96 DBMGR_MERGE_MAILFILES, // Serienbriefe als Datei(en) speichern
97 DBMGR_MERGE_DOCUMENTS, // Print merged documents
98 DBMGR_MERGE_SINGLE_FILE // save merge as single file
101 // -----------------------------------------------------------------------
103 /*--------------------------------------------------------------------
104 Beschreibung: (neue) Logische Datenbanken verwalten
105 --------------------------------------------------------------------*/
106 #define SW_DB_SELECT_UNKNOWN 0
107 #define SW_DB_SELECT_TABLE 1
108 #define SW_DB_SELECT_QUERY 2
110 struct SwDSParam : public SwDBData
112 com::sun::star::util::Date aNullDate;
114 ::com::sun::star::uno::Reference<com::sun::star::util::XNumberFormatter> xFormatter;
115 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> xConnection;
116 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement> xStatement;
117 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet> xResultSet;
118 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aSelection;
119 BOOL bScrollable;
120 BOOL bEndOfDB;
121 BOOL bAfterSelection;
122 long nSelectionIndex;
124 SwDSParam(const SwDBData& rData) :
125 SwDBData(rData),
126 bScrollable(FALSE),
127 bEndOfDB(FALSE),
128 bAfterSelection(FALSE),
129 nSelectionIndex(0)
132 SwDSParam(const SwDBData& rData,
133 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& xResSet,
134 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rSelection) :
135 SwDBData(rData),
136 xResultSet(xResSet),
137 aSelection(rSelection),
138 bScrollable(TRUE),
139 bEndOfDB(FALSE),
140 bAfterSelection(FALSE),
141 nSelectionIndex(0)
144 void CheckEndOfDB()
146 if(bEndOfDB)
147 bAfterSelection = TRUE;
150 typedef SwDSParam* SwDSParamPtr;
151 SV_DECL_PTRARR_DEL(SwDSParamArr, SwDSParamPtr, 0, 5)
153 struct SwMergeDescriptor
155 USHORT nMergeType;
156 SwWrtShell& rSh;
157 const ::svx::ODataAccessDescriptor& rDescriptor;
158 String sSaveToFilter; //export filter to save resulting files
159 String sSaveToFilterOptions; //
160 com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSaveToFilterData;
162 String sSubject;
163 String sAddressFromColumn;
164 String sMailBody;
165 String sAttachmentName;
166 ::com::sun::star::uno::Sequence< ::rtl::OUString > aCopiesTo;
167 ::com::sun::star::uno::Sequence< ::rtl::OUString > aBlindCopiesTo;
169 ::com::sun::star::uno::Reference< com::sun::star::mail::XSmtpService > xSmtpServer;
171 sal_Bool bSendAsHTML;
172 sal_Bool bSendAsAttachment;
174 sal_Bool bPrintAsync;
175 sal_Bool bCreateSingleFile;
177 SwMailMergeConfigItem* pMailMergeConfigItem;
179 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aPrintOptions;
181 SwMergeDescriptor( USHORT nType, SwWrtShell& rShell, ::svx::ODataAccessDescriptor& rDesc ) :
182 nMergeType(nType),
183 rSh(rShell),
184 rDescriptor(rDesc),
185 bSendAsHTML( sal_True ),
186 bSendAsAttachment( sal_False ),
187 bPrintAsync( sal_True ),
188 bCreateSingleFile( sal_False ),
189 pMailMergeConfigItem(0)
194 struct SwNewDBMgr_Impl;
195 class SwConnectionDisposedListener_Impl;
196 class AbstractMailMergeDlg;
198 class SW_DLLPUBLIC SwNewDBMgr
200 friend class SwConnectionDisposedListener_Impl;
202 static SwDbtoolsClient* pDbtoolsClient;
204 String sEMailAddrFld; // Mailing: Spaltenname der E-Mail Adresse
205 String sSubject; // Mailing: Subject
206 String sAttached; // Mailing: Attachte Files
207 USHORT nMergeType;
208 BOOL bInitDBFields : 1; // TRUE: Datenbank an Feldern beim Mergen
209 BOOL bSingleJobs : 1; // Einzelne Druckjobs bei Aufruf aus Basic
210 BOOL bCancel : 1; // Serienbrief-Save abgebrochen
212 BOOL bInMerge : 1; //merge process active
213 BOOL bMergeSilent : 1; // suppress display of dialogs/boxes (used when called over API)
214 BOOL bMergeLock : 1; // prevent update of database fields while document is
215 // actually printed at the ViewShell
216 SwDSParamArr aDataSourceParams;
217 SwNewDBMgr_Impl* pImpl;
218 const SwXMailMerge* pMergeEvtSrc; // != 0 if mail merge events are to be send
220 SW_DLLPRIVATE SwDSParam* FindDSData(const SwDBData& rData, BOOL bCreate);
221 SW_DLLPRIVATE SwDSParam* FindDSConnection(const ::rtl::OUString& rSource, BOOL bCreate);
224 SW_DLLPRIVATE DECL_LINK( PrtCancelHdl, Button * );
226 // Datensaetze als Text ins Dokument einfuegen
227 SW_DLLPRIVATE void ImportFromConnection( SwWrtShell* pSh);
229 // Einzelnen Datensatz als Text ins Dokument einfuegen
230 SW_DLLPRIVATE void ImportDBEntry(SwWrtShell* pSh);
232 // merge to file _and_ merge to e-Mail
233 SW_DLLPRIVATE BOOL MergeMailFiles(SwWrtShell* pSh,
234 const SwMergeDescriptor& rMergeDescriptor );
235 SW_DLLPRIVATE BOOL ToNextRecord(SwDSParam* pParam);
237 public:
238 SwNewDBMgr();
239 ~SwNewDBMgr();
241 // Art des aktellen Mergens. Siehe DBMgrOptions-enum
242 inline USHORT GetMergeType() const { return nMergeType; }
243 inline void SetMergeType( USHORT nTyp ) { nMergeType = nTyp; }
245 // MailMergeEvent source
246 const SwXMailMerge * GetMailMergeEvtSrc() const { return pMergeEvtSrc; }
247 void SetMailMergeEvtSrc( const SwXMailMerge *pSrc ) { pMergeEvtSrc = pSrc; }
249 inline BOOL IsMergeSilent() const { return bMergeSilent != 0; }
250 inline void SetMergeSilent( BOOL bVal ) { bMergeSilent = bVal; }
252 // Mischen von Datensaetzen in Felder
253 BOOL MergeNew( const SwMergeDescriptor& rMergeDesc );
254 BOOL Merge(SwWrtShell* pSh);
255 // Mischen von Datensaetzen in Felder, dann drucken
256 BOOL MergePrint( SwView& rView,
257 SwPrtOptions& rOpt, SfxProgress& rProgress, BOOL bIsAPI );
258 // printing parts of a merge result document
259 BOOL MergePrintDocuments( SwView& rView,
260 SwPrtOptions& rOpt, SfxProgress& rProgress, BOOL bIsAPI );
262 // Datenbankfelder mit fehlendem Datenbankname initialisieren
263 inline BOOL IsInitDBFields() const { return bInitDBFields; }
264 inline void SetInitDBFields(BOOL b) { bInitDBFields = b; }
266 // Serienbriefe einzelnd oder alle zusammen drucken/speichern
267 inline BOOL IsSingleJobs() const { return bSingleJobs; }
268 inline void SetSingleJobs(BOOL b) { bSingleJobs = b; }
270 // Mailing
271 // email-Daten setzen
272 inline void SetEMailColumn(const String& sColName) { sEMailAddrFld = sColName; }
273 inline void SetSubject(const String& sSbj) { sSubject = sSbj; }
274 inline void SetAttachment(const String& sAtt) { sAttached = sAtt; }
277 // Listbox mit allen Tabellennamen einer Datenbank fuellen
278 BOOL GetTableNames(ListBox* pListBox, const String& rDBName );
280 // Listbox mit allen Spaltennamen einer Datenbanktabelle fuellen
281 BOOL GetColumnNames(ListBox* pListBox,
282 const String& rDBName, const String& rTableName, BOOL bAppend = FALSE);
283 BOOL GetColumnNames(ListBox* pListBox,
284 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> xConnection,
285 const String& rTableName, BOOL bAppend = FALSE);
287 ULONG GetColumnFmt( ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource> xSource,
288 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> xConnection,
289 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> xColumn,
290 SvNumberFormatter* pNFmtr,
291 long nLanguage );
293 ULONG GetColumnFmt( const String& rDBName,
294 const String& rTableName,
295 const String& rColNm,
296 SvNumberFormatter* pNFmtr,
297 long nLanguage );
298 sal_Int32 GetColumnType( const String& rDBName,
299 const String& rTableName,
300 const String& rColNm );
302 inline BOOL IsInMerge() const { return bInMerge; }
303 void EndMerge();
305 void ExecuteFormLetter(SwWrtShell& rSh,
306 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rProperties,
307 BOOL bWithDataSourceBrowser = FALSE);
309 void InsertText(SwWrtShell& rSh,
310 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rProperties);
312 // check if a data source is open
313 BOOL IsDataSourceOpen(const String& rDataSource,
314 const String& rTableOrQuery, sal_Bool bMergeOnly);
316 // open the source while fields are updated - for the calculator only!
317 BOOL OpenDataSource(const String& rDataSource, const String& rTableOrQuery,
318 sal_Int32 nCommandType = -1, bool bCreate = false);
319 sal_uInt32 GetSelectedRecordId(const String& rDataSource, const String& rTableOrQuery, sal_Int32 nCommandType = -1);
320 BOOL GetColumnCnt(const String& rSourceName, const String& rTableName,
321 const String& rColumnName, sal_uInt32 nAbsRecordId, long nLanguage,
322 String& rResult, double* pNumber);
323 //create and store or find an already stored connection to a data source for use
324 //in SwFldMgr and SwDBTreeList
325 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>
326 RegisterConnection(::rtl::OUString& rSource);
328 const SwDSParam* CreateDSData(const SwDBData& rData)
329 {return FindDSData(rData, TRUE);}
330 const SwDSParamArr& GetDSParamArray() const {return aDataSourceParams;}
333 //close all data sources - after fields were updated
334 void CloseAll(BOOL bIncludingMerge = TRUE);
336 BOOL GetMergeColumnCnt(const String& rColumnName, USHORT nLanguage,
337 String &rResult, double *pNumber, sal_uInt32 *pFormat);
338 BOOL ToNextMergeRecord();
339 BOOL ToNextRecord(const String& rDataSource, const String& rTableOrQuery, sal_Int32 nCommandType = -1);
341 BOOL ExistsNextRecord()const;
342 sal_uInt32 GetSelectedRecordId();
343 sal_Bool ToRecordId(sal_Int32 nSet);
345 const SwDBData& GetAddressDBName();
347 static String GetDBField(
348 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xColumnProp,
349 const SwDBFormatData& rDBFormatData,
350 double *pNumber = NULL);
352 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>
353 GetConnection(const String& rDataSource,
354 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource>& rxSource);
356 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier>
357 GetColumnSupplier(::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>,
358 const String& rTableOrQuery,
359 BYTE eTableOrQuery = SW_DB_SELECT_UNKNOWN);
361 static ::com::sun::star::uno::Sequence<rtl::OUString> GetExistingDatabaseNames();
364 Loads a data source from file and registers it. Returns the registered name.
366 static String LoadAndRegisterDataSource();
368 static SwDbtoolsClient& GetDbtoolsClient();
369 // has to be called from _FinitUI()
370 static void RemoveDbtoolsClient();
372 /** try to get the data source from the given connection through the XChild interface.
373 If this is not possible, the data source will be created through its name.
374 @param _xConnection
375 The connection which should support the XChild interface. (not a must)
376 @param _sDataSourceName
377 The data source name will be used to create the data source when the connection can not be used for it.
378 @return
379 The data source.
381 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource>
382 getDataSourceAsParent(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,const ::rtl::OUString& _sDataSourceName);
384 /** creates a RowSet, which must be disposed after use.
385 @param _sDataSourceName
386 The data source name
387 @param _sCommand
388 The command.
389 @param _nCommandType
390 The type of the command.
391 @param _xConnection
392 The active connection which may be <NULL/>.
393 @return
394 The new created RowSet.
397 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>
398 createCursor( const ::rtl::OUString& _sDataSourceName,
399 const ::rtl::OUString& _sCommand,
400 sal_Int32 _nCommandType,
401 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection
403 //merge into one document - returns the number of merged docs
404 sal_Int32 MergeDocuments( SwMailMergeConfigItem& rMMConfig, SwView& rSourceView );
407 #endif