xref: /trunk/main/sw/source/ui/dbui/dbinsdlg.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 #ifdef SW_DLLIMPLEMENTATION
31 #undef SW_DLLIMPLEMENTATION
32 #endif
33 
34 #include "dbinsdlg.hxx"
35 
36 #include <memory>
37 
38 #include <float.h>
39 
40 #include <hintids.hxx>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/container/XNameAccess.hpp>
43 #include <com/sun/star/sdbc/XDataSource.hpp>
44 #include <com/sun/star/sdbc/XRow.hpp>
45 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
46 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
47 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
48 #include <com/sun/star/sdb/CommandType.hpp>
49 #include <com/sun/star/sdb/XColumn.hpp>
50 #include <com/sun/star/sdb/XDatabaseAccess.hpp>
51 #include <com/sun/star/sdbc/DataType.hpp>
52 #include <com/sun/star/sdbc/ResultSetType.hpp>
53 #include <com/sun/star/beans/XPropertySet.hpp>
54 #include <com/sun/star/util/XNumberFormatter.hpp>
55 #include <com/sun/star/util/XNumberFormatTypes.hpp>
56 #include <com/sun/star/sdbc/XRowSet.hpp>
57 #include <comphelper/processfactory.hxx>
58 #include <editeng/langitem.hxx>
59 #include <svl/numuno.hxx>
60 #include <svl/stritem.hxx>
61 #include <vcl/msgbox.hxx>
62 #include <vcl/svapp.hxx>
63 #include <vcl/mnemonic.hxx>
64 #include <svl/style.hxx>
65 #include <svl/zformat.hxx>
66 #include <svx/htmlmode.hxx>
67 #include <editeng/unolingu.hxx>
68 #include <sfx2/app.hxx>
69 #include <svl/itemset.hxx>
70 #include <editeng/brshitem.hxx>
71 #include <editeng/boxitem.hxx>
72 #include <svx/rulritem.hxx>
73 #include <swdbtoolsclient.hxx>
74 #include <tabledlg.hxx>
75 #include <fmtclds.hxx>
76 #include <tabcol.hxx>
77 #include <uiitems.hxx>
78 #include <viewopt.hxx>
79 #include <uitool.hxx>
80 #include <wrtsh.hxx>
81 #include <wview.hxx>
82 #include <docsh.hxx>
83 #include <dbmgr.hxx>
84 #include <tblafmt.hxx>
85 #include <cellatr.hxx>
86 #include <swtable.hxx>
87 #include <dbfld.hxx>
88 #include <fmtcol.hxx>
89 #include <section.hxx>
90 #include <swwait.hxx>
91 #include <modcfg.hxx>
92 #include <swmodule.hxx>
93 #include <poolfmt.hxx>
94 #include <crsskip.hxx>
95 
96 #include <dbinsdlg.hrc>
97 #include <dbui.hrc>
98 
99 #include <cmdid.h>
100 #include <helpid.h>
101 #include <cfgid.h>
102 #include <SwStyleNameMapper.hxx>
103 #include <comphelper/uno3.hxx>
104 #include "tabsh.hxx"
105 #include "swabstdlg.hxx"
106 #include "table.hrc"
107 #include <unomid.h>
108 #include <IDocumentMarkAccess.hxx>
109 
110 
111 namespace swui
112 {
113     SwAbstractDialogFactory * GetFactory();
114 }
115 
116 using namespace ::com::sun::star;
117 using namespace ::com::sun::star::uno;
118 using namespace ::com::sun::star::container;
119 using namespace ::com::sun::star::lang;
120 using namespace ::com::sun::star::sdb;
121 using namespace ::com::sun::star::sdbc;
122 using namespace ::com::sun::star::sdbcx;
123 using namespace ::com::sun::star::beans;
124 
125 // tblafmt.hxx
126 SV_IMPL_PTRARR( _SwTableAutoFmtTbl, SwTableAutoFmt* )
127 
128 const char cDBFldStart  = '<';
129 const char cDBFldEnd    = '>';
130 
131 // Hilfsstruktur fuers einfuegen von Datenbankspalten als Felder oder Text
132 struct _DB_Column
133 {
134     enum ColType { DB_FILLTEXT, DB_COL_FIELD, DB_COL_TEXT, DB_SPLITPARA } eColType;
135 
136     union {
137         String* pText;
138         SwField* pField;
139         sal_uLong nFormat;
140     } DB_ColumnData;
141     const SwInsDBColumn* pColInfo;
142 
143     _DB_Column()
144     {
145         pColInfo = 0;
146         DB_ColumnData.pText = 0;
147         eColType = DB_SPLITPARA;
148     }
149 
150     _DB_Column( const String& rTxt )
151     {
152         pColInfo = 0;
153         DB_ColumnData.pText = new String( rTxt );
154         eColType = DB_FILLTEXT;
155     }
156 
157     _DB_Column( const SwInsDBColumn& rInfo, sal_uLong nFormat )
158     {
159         pColInfo = &rInfo;
160         DB_ColumnData.nFormat = nFormat;
161         eColType = DB_COL_TEXT;
162     }
163 
164     _DB_Column( const SwInsDBColumn& rInfo, SwDBField& rFld )
165     {
166         pColInfo = &rInfo;
167         DB_ColumnData.pField = &rFld;
168         eColType = DB_COL_FIELD;
169     }
170 
171     ~_DB_Column()
172     {
173         if( DB_COL_FIELD == eColType )
174             delete DB_ColumnData.pField;
175         else if( DB_FILLTEXT == eColType )
176             delete DB_ColumnData.pText;
177     }
178 };
179 
180 typedef _DB_Column* _DB_ColumnPtr;
181 SV_DECL_PTRARR_DEL( _DB_Columns, _DB_ColumnPtr, 32, 32 )
182 SV_IMPL_PTRARR( _DB_Columns, _DB_ColumnPtr )
183 
184 SV_IMPL_OP_PTRARR_SORT( SwInsDBColumns, SwInsDBColumnPtr )
185 
186 /*  */
187 
188 #define DBCOLUMN_CONFIG_VERSION1    1
189 #define DBCOLUMN_CONFIG_VERSION     DBCOLUMN_CONFIG_VERSION1
190 #define DBCOLUMN_MAXDATA            5
191 
192 struct _DB_ColumnConfigData
193 {
194     SwInsDBColumns aDBColumns;
195     rtl::OUString sSource, sTable, sEdit, sTblList, sTmplNm, sTAutoFmtNm;
196     sal_Bool bIsTable : 1,
197          bIsField : 1,
198          bIsHeadlineOn : 1,
199          bIsEmptyHeadln : 1;
200 
201     _DB_ColumnConfigData()
202     {
203         bIsTable = bIsHeadlineOn = sal_True;
204         bIsField = bIsEmptyHeadln = sal_False;
205     }
206 
207     ~_DB_ColumnConfigData();
208 private:
209     _DB_ColumnConfigData( const _DB_ColumnConfigData& );
210     _DB_ColumnConfigData& operator =( const _DB_ColumnConfigData& );
211 };
212 
213 /*  */
214 
215 int SwInsDBColumn::operator<( const SwInsDBColumn& rCmp ) const
216 {
217     return 0 > GetAppCollator().compareString( sColumn, rCmp.sColumn );
218 }
219 /* ---------------------------------------------------------------------------
220 
221  ---------------------------------------------------------------------------*/
222 SwInsertDBColAutoPilot::SwInsertDBColAutoPilot( SwView& rView,
223         Reference<XDataSource> xDataSource,
224         Reference<sdbcx::XColumnsSupplier> xColSupp,
225         const SwDBData& rData )
226     : SfxModalDialog( rView.GetWindow(), SW_RES( DLG_AP_INSERT_DB_SEL )),
227     ConfigItem(C2U("Office.Writer/InsertData/DataSet"), CONFIG_MODE_DELAYED_UPDATE),
228     aFtInsertData( this, SW_RES( FT_INSERT_DATA )),
229     aRbAsTable( this, SW_RES( RB_AS_TABLE )),
230     aRbAsField( this, SW_RES( RB_AS_FIELD )),
231     aRbAsText( this, SW_RES( RB_AS_TEXT )),
232 
233     aFlHead( this, SW_RES( FL_HEAD )),
234     aFtDbColumn( this, SW_RES( FT_DB_COLUMN )),
235 
236     aLbTblDbColumn( this, SW_RES( LB_TBL_DB_COLUMN )),
237     aLbTxtDbColumn( this, SW_RES( LB_TXT_DB_COLUMN )),
238 
239     aFlFormat( this, SW_RES( FL_FORMAT )),
240     aRbDbFmtFromDb( this, SW_RES( RB_DBFMT_FROM_DB )),
241     aRbDbFmtFromUsr( this, SW_RES( RB_DBFMT_FROM_USR )),
242     aLbDbFmtFromUsr( this, &rView, SW_RES( LB_DBFMT_FROM_USR )),
243 
244     aIbDbcolToEdit( this, SW_RES( IB_DBCOL_TOEDIT )),
245     aEdDbText( this, SW_RES( ED_DB_TEXT )),
246     aFtDbParaColl( this, SW_RES( FT_DB_PARA_COLL )),
247     aLbDbParaColl( this, SW_RES( LB_DB_PARA_COLL )),
248 
249     aIbDbcolAllTo( this, SW_RES( IB_DBCOL_ALL_TO )),
250     aIbDbcolOneTo( this, SW_RES( IB_DBCOL_ONE_TO )),
251     aIbDbcolOneFrom( this, SW_RES( IB_DBCOL_ONE_FROM )),
252     aIbDbcolAllFrom( this, SW_RES( IB_DBCOL_ALL_FROM )),
253     aFtTableCol( this, SW_RES( FT_TABLE_COL )),
254     aLbTableCol( this, SW_RES( LB_TABLE_COL )),
255     aCbTableHeadon( this, SW_RES( CB_TABLE_HEADON )),
256     aRbHeadlColnms( this, SW_RES( RB_HEADL_COLNMS )),
257     aRbHeadlEmpty( this, SW_RES( RB_HEADL_EMPTY )),
258     aPbTblFormat( this, SW_RES( PB_TBL_FORMAT )),
259     aPbTblAutofmt( this, SW_RES( PB_TBL_AUTOFMT )),
260 
261     aBtOk( this, SW_RES( BT_OK )),
262     aBtCancel( this, SW_RES( BT_CANCEL )),
263     aBtHelp( this, SW_RES( BT_HELP )),
264 
265     aFlBottom( this, SW_RES( FL_BOTTOM )),
266 
267     aDBData(rData),
268 
269     aOldNumFmtLnk( aLbDbFmtFromUsr.GetSelectHdl() ),
270     sNoTmpl( SW_RES( STR_NOTEMPL )),
271     pView( &rView ),
272     pTAutoFmt( 0 ),
273     pTblSet( 0 ),
274     pRep( 0 )
275 {
276     FreeResource();
277 
278     nGBFmtLen = aFlFormat.GetText().Len();
279 
280     if(xColSupp.is())
281     {
282         SwWrtShell& rSh = pView->GetWrtShell();
283         Locale aDocLocale( SvxCreateLocale( rSh.GetCurLang() ));
284         SvNumberFormatter* pNumFmtr = rSh.GetNumberFormatter();
285         SvNumberFormatsSupplierObj* pNumFmt = new SvNumberFormatsSupplierObj( pNumFmtr );
286         Reference< util::XNumberFormatsSupplier >  xDocNumFmtsSupplier = pNumFmt;
287         Reference< util::XNumberFormats > xDocNumberFormats = xDocNumFmtsSupplier->getNumberFormats();
288         Reference< util::XNumberFormatTypes > xDocNumberFormatTypes(xDocNumberFormats, UNO_QUERY);
289 
290         Reference<XPropertySet> xSourceProps(xDataSource, UNO_QUERY);
291         Reference< util::XNumberFormats > xNumberFormats;
292         if(xSourceProps.is())
293         {
294             Any aFormats = xSourceProps->getPropertyValue(C2U("NumberFormatsSupplier"));
295             if(aFormats.hasValue())
296             {
297                 Reference< util::XNumberFormatsSupplier> xSuppl;
298                 aFormats >>= xSuppl;
299                 if(xSuppl.is())
300                 {
301                     xNumberFormats = xSuppl->getNumberFormats(  );
302                 }
303             }
304         }
305         Reference <XNameAccess> xCols = xColSupp->getColumns();
306         Sequence<rtl::OUString> aColNames = xCols->getElementNames();
307         const rtl::OUString* pColNames = aColNames.getConstArray();
308         long nCount = aColNames.getLength();
309         for (long n = 0; n < nCount; n++)
310         {
311             SwInsDBColumn* pNew = new SwInsDBColumn( pColNames[n], (sal_uInt16)n );
312             Any aCol = xCols->getByName(pColNames[n]);
313             Reference <XPropertySet> xCol;
314             aCol >>= xCol;
315             Any aType = xCol->getPropertyValue(C2S("Type"));
316             sal_Int32 eDataType = 0;
317             aType >>= eDataType;
318             switch(eDataType)
319             {
320                 case DataType::BIT:
321                 case DataType::BOOLEAN:
322                 case DataType::TINYINT:
323                 case DataType::SMALLINT:
324                 case DataType::INTEGER:
325                 case DataType::BIGINT:
326                 case DataType::FLOAT:
327                 case DataType::REAL:
328                 case DataType::DOUBLE:
329                 case DataType::NUMERIC:
330                 case DataType::DECIMAL:
331                 case DataType::DATE:
332                 case DataType::TIME:
333                 case DataType::TIMESTAMP:
334                 {
335                     pNew->bHasFmt = sal_True;
336                     Any aFormat = xCol->getPropertyValue(C2U("FormatKey"));
337                     if(aFormat.hasValue())
338                     {
339                         sal_Int32 nFmt = 0;
340                         aFormat >>= nFmt;
341                         if(xNumberFormats.is())
342                         {
343                             try
344                             {
345                                 Reference<XPropertySet> xNumProps = xNumberFormats->getByKey( nFmt );
346                                 Any aFormatVal = xNumProps->getPropertyValue(C2U("FormatString"));
347                                 Any aLocale = xNumProps->getPropertyValue(C2U("Locale"));
348                                 rtl::OUString sFormat;
349                                 aFormatVal >>= sFormat;
350                                 lang::Locale aLoc;
351                                 aLocale >>= aLoc;
352                                 long nKey = xDocNumberFormats->queryKey( sFormat, aLoc, sal_True);
353                                 if(nKey < 0)
354                                 {
355                                     nKey = xDocNumberFormats->addNew( sFormat, aLoc );
356                                 }
357                                 pNew->nDBNumFmt = nKey;
358                             }
359                             catch(const Exception& )
360                             {
361                                 DBG_ERROR("illegal number format key");
362                             }
363                         }
364                     }
365                     else
366                     {
367                         pNew->nDBNumFmt = SwNewDBMgr::GetDbtoolsClient().getDefaultNumberFormat(xCol,
368                                                     xDocNumberFormatTypes, aDocLocale);
369                     }
370 
371                 }
372                 break;
373             }
374             if( !aDBColumns.Insert( pNew ))
375             {
376                 ASSERT( !this, "Spaltenname mehrfach vergeben?" );
377                 delete pNew;
378             }
379         }
380     }
381 
382     // Absatzvorlagen-ListBox fuellen
383     {
384         SfxStyleSheetBasePool* pPool = pView->GetDocShell()->GetStyleSheetPool();
385         pPool->SetSearchMask( SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL );
386         aLbDbParaColl.InsertEntry( sNoTmpl );
387 
388         const SfxStyleSheetBase* pBase = pPool->First();
389         while( pBase )
390         {
391             aLbDbParaColl.InsertEntry( pBase->GetName() );
392             pBase = pPool->Next();
393         }
394         aLbDbParaColl.SelectEntryPos( 0 );
395     }
396 
397     // steht der Cursor in einer Tabelle, darf NIE Tabelle auswaehlbar sein
398     if( pView->GetWrtShell().GetTableFmt() )
399     {
400         aRbAsTable.Enable( sal_False );
401         aRbAsField.Check( sal_True );
402         aRbDbFmtFromDb.Check( sal_True );
403     }
404     else
405     {
406         aRbAsTable.Check( sal_True );
407         aRbDbFmtFromDb.Check( sal_True );
408         aIbDbcolOneFrom.Enable( sal_False );
409         aIbDbcolAllFrom.Enable( sal_False );
410     }
411 
412     aRbAsTable.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, PageHdl ));
413     aRbAsField.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, PageHdl ));
414     aRbAsText.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, PageHdl ));
415 
416     aRbDbFmtFromDb.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, DBFormatHdl ));
417     aRbDbFmtFromUsr.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, DBFormatHdl ));
418 
419     aPbTblFormat.SetClickHdl(LINK(this, SwInsertDBColAutoPilot, TblFmtHdl ));
420     aPbTblAutofmt.SetClickHdl(LINK(this, SwInsertDBColAutoPilot, AutoFmtHdl ));
421 
422     aIbDbcolAllTo.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
423     aIbDbcolOneTo.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
424     aIbDbcolOneFrom.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
425     aIbDbcolAllFrom.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
426     aIbDbcolToEdit.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
427 
428     aCbTableHeadon.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, HeaderHdl ));
429     aRbHeadlColnms.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, HeaderHdl ));
430     aRbHeadlEmpty.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, HeaderHdl ));
431 
432     aLbTxtDbColumn.SetSelectHdl( LINK( this, SwInsertDBColAutoPilot, SelectHdl ));
433     aLbTblDbColumn.SetSelectHdl( LINK( this, SwInsertDBColAutoPilot, SelectHdl ));
434     aLbDbFmtFromUsr.SetSelectHdl( LINK( this, SwInsertDBColAutoPilot, SelectHdl ));
435     aLbTableCol.SetSelectHdl( LINK( this, SwInsertDBColAutoPilot, SelectHdl ));
436 
437     aLbTxtDbColumn.SetDoubleClickHdl( LINK( this, SwInsertDBColAutoPilot, DblClickHdl ));
438     aLbTblDbColumn.SetDoubleClickHdl( LINK( this, SwInsertDBColAutoPilot, DblClickHdl ));
439     aLbTableCol.SetDoubleClickHdl( LINK( this, SwInsertDBColAutoPilot, DblClickHdl ));
440 
441     for( sal_uInt16 n = 0; n < aDBColumns.Count(); ++n )
442     {
443         const String& rS = aDBColumns[ n ]->sColumn;
444         aLbTblDbColumn.InsertEntry( rS, n );
445         aLbTxtDbColumn.InsertEntry( rS, n );
446     }
447     aLbTxtDbColumn.SelectEntryPos( 0 );
448     aLbTblDbColumn.SelectEntryPos( 0 );
449 
450     // read configuration
451     Load();
452 
453     // Controls initialisieren:
454     PageHdl( aRbAsTable.IsChecked() ? &aRbAsTable : &aRbAsField );
455 }
456 /* ---------------------------------------------------------------------------
457 
458  ---------------------------------------------------------------------------*/
459 SwInsertDBColAutoPilot::~SwInsertDBColAutoPilot()
460 {
461     delete pTblSet;
462     delete pRep;
463 
464 //  delete pConfig;
465     delete pTAutoFmt;
466 }
467 /* ---------------------------------------------------------------------------
468 
469  ---------------------------------------------------------------------------*/
470 IMPL_LINK( SwInsertDBColAutoPilot, PageHdl, Button*, pButton )
471 {
472     sal_Bool bShowTbl = pButton == &aRbAsTable;
473 
474     String sTxt( pButton->GetText() );
475     aFlHead.SetText( MnemonicGenerator::EraseAllMnemonicChars( sTxt ) );
476 
477     aLbTxtDbColumn.Show( !bShowTbl );
478     aIbDbcolToEdit.Show( !bShowTbl );
479     aEdDbText.Show( !bShowTbl );
480     aFtDbParaColl.Show( !bShowTbl );
481     aLbDbParaColl.Show( !bShowTbl );
482 
483     aLbTblDbColumn.Show( bShowTbl );
484     aIbDbcolAllTo.Show( bShowTbl );
485     aIbDbcolOneTo.Show( bShowTbl );
486     aIbDbcolOneFrom.Show( bShowTbl );
487     aIbDbcolAllFrom.Show( bShowTbl );
488     aFtTableCol.Show( bShowTbl );
489     aLbTableCol.Show( bShowTbl );
490     aCbTableHeadon.Show( bShowTbl );
491     aRbHeadlColnms.Show( bShowTbl );
492     aRbHeadlEmpty.Show( bShowTbl );
493     aPbTblFormat.Show( bShowTbl );
494     aPbTblAutofmt.Show( bShowTbl );
495 
496     if( bShowTbl )
497         aPbTblFormat.Enable( 0 != aLbTableCol.GetEntryCount() );
498 
499     SelectHdl( bShowTbl ? &aLbTblDbColumn : &aLbTxtDbColumn );
500 
501     return 0;
502 }
503 /* ---------------------------------------------------------------------------
504 
505  ---------------------------------------------------------------------------*/
506 IMPL_LINK( SwInsertDBColAutoPilot, DBFormatHdl, Button*, pButton )
507 {
508     sal_uInt16 nFndPos;
509     ListBox& rBox = aRbAsTable.IsChecked()
510                         ? ( 0 == aLbTableCol.GetEntryData( 0 )
511                             ? aLbTblDbColumn
512                             : aLbTableCol )
513                         : aLbTxtDbColumn;
514 
515     SwInsDBColumn aSrch( rBox.GetSelectEntry(), 0 );
516     aDBColumns.Seek_Entry( &aSrch, &nFndPos );
517 
518     sal_Bool bFromDB = &aRbDbFmtFromDb == pButton;
519     aDBColumns[ nFndPos ]->bIsDBFmt = bFromDB;
520     aLbDbFmtFromUsr.Enable( !bFromDB );
521 
522     return 0;
523 }
524 /* ---------------------------------------------------------------------------
525 
526  ---------------------------------------------------------------------------*/
527 IMPL_LINK( SwInsertDBColAutoPilot, TblToFromHdl, Button*, pButton )
528 {
529     sal_Bool bChgEnable = sal_True, bEnableTo = sal_True, bEnableFrom = sal_True;
530     aLbTblDbColumn.SetUpdateMode( sal_False );
531     aLbTableCol.SetUpdateMode( sal_False );
532 
533     if( pButton == &aIbDbcolAllTo )
534     {
535         bEnableTo = sal_False;
536 
537         sal_uInt16 n, nInsPos = aLbTableCol.GetSelectEntryPos(),
538                nCnt = aLbTblDbColumn.GetEntryCount();
539         if( LISTBOX_APPEND == nInsPos )
540             for( n = 0; n < nCnt; ++n )
541                 aLbTableCol.InsertEntry( aLbTblDbColumn.GetEntry( n ),
542                                             LISTBOX_APPEND );
543         else
544             for( n = 0; n < nCnt; ++n, ++nInsPos )
545                 aLbTableCol.InsertEntry( aLbTblDbColumn.GetEntry( n ), nInsPos );
546         aLbTblDbColumn.Clear();
547         aLbTableCol.SelectEntryPos( nInsPos );
548         aLbTblDbColumn.SelectEntryPos( LISTBOX_APPEND );
549     }
550     else if( pButton == &aIbDbcolOneTo &&
551             LISTBOX_ENTRY_NOTFOUND != aLbTblDbColumn.GetSelectEntryPos() )
552     {
553         sal_uInt16 nInsPos = aLbTableCol.GetSelectEntryPos(),
554                nDelPos = aLbTblDbColumn.GetSelectEntryPos(),
555                nTopPos = aLbTblDbColumn.GetTopEntry();
556         aLbTableCol.InsertEntry( aLbTblDbColumn.GetEntry( nDelPos ), nInsPos );
557         aLbTblDbColumn.RemoveEntry( nDelPos );
558 
559         aLbTableCol.SelectEntryPos( nInsPos );
560         if( nDelPos >= aLbTblDbColumn.GetEntryCount() )
561             nDelPos = aLbTblDbColumn.GetEntryCount() - 1;
562         aLbTblDbColumn.SelectEntryPos( nDelPos );
563         aLbTblDbColumn.SetTopEntry( nTopPos );
564 
565         bEnableTo = 0 != aLbTblDbColumn.GetEntryCount();
566     }
567     else if( pButton == &aIbDbcolOneFrom )
568     {
569         if( LISTBOX_ENTRY_NOTFOUND != aLbTableCol.GetSelectEntryPos() )
570         {
571             sal_uInt16 nFndPos, nInsPos,
572                     nDelPos = aLbTableCol.GetSelectEntryPos(),
573                     nTopPos = aLbTableCol.GetTopEntry();
574 
575             // die richtige InsertPos suchen!!
576             SwInsDBColumn aSrch( aLbTableCol.GetEntry( nDelPos ), 0 );
577             aDBColumns.Seek_Entry( &aSrch, &nFndPos );
578             if( !nFndPos || nFndPos == aDBColumns.Count()-1 )
579                 nInsPos = nFndPos;
580             else
581             {
582                 nInsPos = LISTBOX_ENTRY_NOTFOUND;
583                 while( ++nFndPos < aDBColumns.Count() &&
584                         LISTBOX_ENTRY_NOTFOUND == (nInsPos = aLbTblDbColumn.
585                         GetEntryPos( String(aDBColumns[ nFndPos ]->sColumn ))) )
586                     ;
587             }
588 
589             aLbTblDbColumn.InsertEntry( aSrch.sColumn, nInsPos );
590             aLbTableCol.RemoveEntry( nDelPos );
591 
592             if( nInsPos >= aLbTblDbColumn.GetEntryCount() )
593                 nInsPos = aLbTblDbColumn.GetEntryCount() - 1;
594             aLbTblDbColumn.SelectEntryPos( nInsPos );
595 
596             if( nDelPos >= aLbTableCol.GetEntryCount() )
597                 nDelPos = aLbTableCol.GetEntryCount() - 1;
598             aLbTableCol.SelectEntryPos( nDelPos );
599             aLbTableCol.SetTopEntry( nTopPos );
600         }
601         else
602             bEnableTo = 0 != aLbTblDbColumn.GetEntryCount();
603 
604         bEnableFrom = 0 != aLbTableCol.GetEntryCount();
605     }
606     else if( pButton == &aIbDbcolAllFrom )
607     {
608         bEnableFrom = sal_False;
609 
610         aLbTblDbColumn.Clear();
611         aLbTableCol.Clear();
612         for( sal_uInt16 n = 0; n < aDBColumns.Count(); ++n )
613             aLbTblDbColumn.InsertEntry( aDBColumns[ n ]->sColumn, n );
614         aLbTblDbColumn.SelectEntryPos( 0 );
615     }
616     else if( pButton == &aIbDbcolToEdit )
617     {
618         bChgEnable = sal_False;
619         // Daten ins Edit moven:
620         String aFld( aLbTxtDbColumn.GetSelectEntry() );
621         if( aFld.Len() )
622         {
623             String aStr( aEdDbText.GetText() );
624             sal_uInt16 nPos = (sal_uInt16)aEdDbText.GetSelection().Min();
625             sal_uInt16 nSel = sal_uInt16(aEdDbText.GetSelection().Max()) - nPos;
626             if( nSel )
627                 // dann loesche erstmal die bestehende Selektion
628                 aStr.Erase( nPos, nSel );
629 
630             aFld.Insert( cDBFldStart, 0 );
631             aFld += cDBFldEnd;
632             if( aStr.Len() )
633             {
634                 if( nPos )                          // ein Space davor
635                 {
636                     sal_Unicode c = aStr.GetChar( nPos-1 );
637                     if( '\n' != c && '\r' != c )
638                         aFld.Insert( ' ', 0 );
639                 }
640                 if( nPos < aStr.Len() )             // ein Space dahinter
641                 {
642                     sal_Unicode c = aStr.GetChar( nPos );
643                     if( '\n' != c && '\r' != c )
644                         aFld += ' ';
645                 }
646             }
647 
648             aStr.Insert( aFld, nPos );
649             aEdDbText.SetText( aStr );
650             nPos = nPos + aFld.Len();
651             aEdDbText.SetSelection( Selection( nPos ));
652         }
653     }
654 
655     if( bChgEnable )
656     {
657         aIbDbcolOneTo.Enable( bEnableTo );
658         aIbDbcolAllTo.Enable( bEnableTo );
659         aIbDbcolOneFrom.Enable( bEnableFrom );
660         aIbDbcolAllFrom.Enable( bEnableFrom );
661 
662         aRbDbFmtFromDb.Enable( sal_False );
663         aRbDbFmtFromUsr.Enable( sal_False );
664         aLbDbFmtFromUsr.Enable( sal_False );
665 
666         aPbTblFormat.Enable( bEnableFrom );
667     }
668     aLbTblDbColumn.SetUpdateMode( sal_True );
669     aLbTableCol.SetUpdateMode( sal_True );
670 
671     return 0;
672 }
673 /* ---------------------------------------------------------------------------
674 
675  ---------------------------------------------------------------------------*/
676 IMPL_LINK( SwInsertDBColAutoPilot, DblClickHdl, ListBox*, pBox )
677 {
678     Button* pButton = 0;
679     if( pBox == &aLbTxtDbColumn )
680         pButton = &aIbDbcolToEdit;
681     else if( pBox == &aLbTblDbColumn && aIbDbcolOneTo.IsEnabled() )
682         pButton = &aIbDbcolOneTo;
683     else if( pBox == &aLbTableCol && aIbDbcolOneFrom.IsEnabled() )
684         pButton = &aIbDbcolOneFrom;
685 
686     if( pButton )
687         TblToFromHdl( pButton );
688 
689     return 0;
690 }
691 /* ---------------------------------------------------------------------------
692 
693  ---------------------------------------------------------------------------*/
694 IMPL_LINK( SwInsertDBColAutoPilot, TblFmtHdl, PushButton*, pButton )
695 {
696     SwWrtShell& rSh = pView->GetWrtShell();
697     sal_Bool bNewSet = sal_False;
698     if( !pTblSet )
699     {
700         bNewSet = sal_True;
701         pTblSet = new SfxItemSet( rSh.GetAttrPool(), SwuiGetUITableAttrRange() );
702 
703         //Ersteinmal die einfachen Attribute besorgen.
704         pTblSet->Put( SfxStringItem( FN_PARAM_TABLE_NAME, rSh.GetUniqueTblName() ));
705         pTblSet->Put( SfxUInt16Item( FN_PARAM_TABLE_HEADLINE, 1 ) );
706 
707         pTblSet->Put( SfxUInt16Item( SID_BACKGRND_DESTINATION,
708                                     rSh.GetViewOptions()->GetTblDest() ));
709 
710         SvxBrushItem aBrush( RES_BACKGROUND );
711         pTblSet->Put( aBrush );
712         pTblSet->Put( aBrush, SID_ATTR_BRUSH_ROW );
713         pTblSet->Put( aBrush, SID_ATTR_BRUSH_TABLE );
714 
715         SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
716             // Tabellenvariante, wenn mehrere Tabellenzellen selektiert
717         aBoxInfo.SetTable( sal_True );
718             // Abstandsfeld immer anzeigen
719         aBoxInfo.SetDist( sal_True);
720             // Minimalgroesse in Tabellen und Absaetzen setzen
721         aBoxInfo.SetMinDist( sal_False );
722             // Default-Abstand immer setzen
723         aBoxInfo.SetDefDist( MIN_BORDER_DIST );
724             // Einzelne Linien koennen nur in Tabellen DontCare-Status haben
725         aBoxInfo.SetValid( VALID_DISABLE, sal_True );
726         pTblSet->Put( aBoxInfo );
727 
728         SwGetCurColNumPara aPara;
729         const sal_uInt16 nNum = rSh.GetCurColNum( &aPara );
730         long nWidth;
731 
732         if( nNum )
733         {
734             nWidth = aPara.pPrtRect->Width();
735             const SwFmtCol& rCol = aPara.pFrmFmt->GetCol();
736             const SwColumns& rCols = rCol.GetColumns();
737 
738             //nStart und nEnd initialisieren fuer nNum == 0
739             long nWidth1 = 0,
740                 nStart1 = 0,
741                 nEnd1 = nWidth;
742             for( sal_uInt16 i = 0; i < nNum; ++i )
743             {
744                 SwColumn* pCol = rCols[i];
745                 nStart1 = pCol->GetLeft() + nWidth1;
746                 nWidth1 += (long)rCol.CalcColWidth( i, (sal_uInt16)nWidth );
747                 nEnd1 = nWidth1 - pCol->GetRight();
748             }
749             if(nStart1 || nEnd1 != nWidth)
750                 nWidth = nEnd1 - nStart1;
751         }
752         else
753             nWidth = rSh.GetAnyCurRect(
754                                 FRMTYPE_FLY_ANY & rSh.GetFrmType( 0, sal_True )
755                                               ? RECT_FLY_PRT_EMBEDDED
756                                               : RECT_PAGE_PRT ).Width();
757 
758         SwTabCols aTabCols;
759         aTabCols.SetRight( nWidth );
760         aTabCols.SetRightMax( nWidth );
761         pRep = new SwTableRep( aTabCols, sal_False );
762         pRep->SetAlign( text::HoriOrientation::NONE );
763         pRep->SetSpace( nWidth );
764         pRep->SetWidth( nWidth );
765         pRep->SetWidthPercent( 100 );
766         pTblSet->Put( SwPtrItem( FN_TABLE_REP, pRep ));
767 
768         pTblSet->Put( SfxUInt16Item( SID_HTML_MODE,
769                     ::GetHtmlMode( pView->GetDocShell() )));
770     }
771 
772     if( aLbTableCol.GetEntryCount() != pRep->GetAllColCount() )
773     {
774         // Anzahl der Spalten hat sich geaendert: dann muessen die
775         // TabCols angepasst werden
776         long nWidth = pRep->GetWidth();
777         sal_uInt16 nCols = aLbTableCol.GetEntryCount() - 1;
778         SwTabCols aTabCols( nCols );
779         aTabCols.SetRight( nWidth  );
780         aTabCols.SetRightMax( nWidth );
781         if( nCols )
782             for( sal_uInt16 n = 0, nStep = (sal_uInt16)(nWidth / (nCols+1)), nW = nStep;
783                     n < nCols; ++n, nW = nW + nStep )
784             {
785                 aTabCols.Insert( nW, sal_False, n );
786             }
787         delete pRep;
788         pRep = new SwTableRep( aTabCols, sal_False );
789         pRep->SetAlign( text::HoriOrientation::NONE );
790         pRep->SetSpace( nWidth );
791         pRep->SetWidth( nWidth );
792         pRep->SetWidthPercent( 100 );
793         pTblSet->Put( SwPtrItem( FN_TABLE_REP, pRep ));
794     }
795 
796     SwAbstractDialogFactory* pFact = swui::GetFactory();
797     DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
798 
799     SfxAbstractTabDialog* pDlg = pFact->CreateSwTableTabDlg(  pButton, rSh.GetAttrPool(),pTblSet, &rSh, DLG_FORMAT_TABLE );
800     DBG_ASSERT(pDlg, "Dialogdiet fail!");
801     if( RET_OK == pDlg->Execute() )
802         pTblSet->Put( *pDlg->GetOutputItemSet() );
803     else if( bNewSet )
804     {
805         delete pTblSet, pTblSet = 0;
806         delete pRep, pRep = 0;
807     }
808     delete pDlg;
809 
810     return 0;
811 }
812 /* ---------------------------------------------------------------------------
813 
814  ---------------------------------------------------------------------------*/
815 IMPL_LINK( SwInsertDBColAutoPilot, AutoFmtHdl, PushButton*, pButton )
816 {
817     SwAbstractDialogFactory* pFact = swui::GetFactory();
818     DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
819 
820     AbstractSwAutoFormatDlg* pDlg = pFact->CreateSwAutoFormatDlg(pButton, pView->GetWrtShellPtr(),DLG_AUTOFMT_TABLE, sal_False, pTAutoFmt);
821     DBG_ASSERT(pDlg, "Dialogdiet fail!");
822     if( RET_OK == pDlg->Execute())
823         pDlg->FillAutoFmtOfIndex( pTAutoFmt );
824     delete pDlg;
825     return 0;
826 }
827 /* ---------------------------------------------------------------------------
828 
829  ---------------------------------------------------------------------------*/
830 IMPL_LINK( SwInsertDBColAutoPilot, SelectHdl, ListBox*, pBox )
831 {
832     ListBox* pGetBox = pBox == &aLbDbFmtFromUsr
833                             ? ( aRbAsTable.IsChecked()
834                                     ? ( 0 == aLbTableCol.GetEntryData( 0 )
835                                         ? &aLbTblDbColumn
836                                         : &aLbTableCol )
837                                     : &aLbTxtDbColumn )
838                             : pBox;
839 
840     sal_uInt16 nFndPos;
841     SwInsDBColumn aSrch( pGetBox->GetSelectEntry(), 0 );
842     aDBColumns.Seek_Entry( &aSrch, &nFndPos );
843 
844     if( pBox == &aLbDbFmtFromUsr )
845     {
846         if( aSrch.sColumn.getLength() )
847         {
848             aOldNumFmtLnk.Call( pBox );
849             aDBColumns[ nFndPos ]->nUsrNumFmt = aLbDbFmtFromUsr.GetFormat();
850         }
851     }
852     else
853     {
854         // an der FormatGroupBox den ausgewaehlten FeldNamen setzen, damit
855         // klar ist, welches Feld ueber das Format eingestellt wird!
856         String sTxt( aFlFormat.GetText().Copy( 0, nGBFmtLen ));
857         if( !aSrch.sColumn.getLength() )
858         {
859             aRbDbFmtFromDb.Enable( sal_False );
860             aRbDbFmtFromUsr.Enable( sal_False );
861             aLbDbFmtFromUsr.Enable( sal_False );
862         }
863         else
864         {
865             sal_Bool bEnableFmt = aDBColumns[ nFndPos ]->bHasFmt;
866             aRbDbFmtFromDb.Enable( bEnableFmt );
867             aRbDbFmtFromUsr.Enable( bEnableFmt );
868 
869             if( bEnableFmt )
870             {
871                 (( sTxt += C2S(" (" )) += String(aSrch.sColumn) ) += (sal_Unicode)')';
872             }
873 
874             sal_Bool bIsDBFmt = aDBColumns[ nFndPos ]->bIsDBFmt;
875             aRbDbFmtFromDb.Check( bIsDBFmt );
876             aRbDbFmtFromUsr.Check( !bIsDBFmt );
877             aLbDbFmtFromUsr.Enable( !bIsDBFmt );
878             if( !bIsDBFmt )
879                 aLbDbFmtFromUsr.SetDefFormat( aDBColumns[ nFndPos ]->nUsrNumFmt );
880         }
881 
882         aFlFormat.SetText( sTxt );
883 
884         // um spaeter zu wissen, welche ListBox die "aktive" war, wird sich
885         // im 1. Eintrag ein Flag gemerkt,
886         void* pPtr = pBox == &aLbTableCol ? &aLbTableCol : 0;
887         aLbTableCol.SetEntryData( 0, pPtr );
888     }
889     return 0;
890 }
891 /* ---------------------------------------------------------------------------
892 
893  ---------------------------------------------------------------------------*/
894 IMPL_LINK( SwInsertDBColAutoPilot, HeaderHdl, Button*, pButton )
895 {
896     if( pButton == &aCbTableHeadon )
897     {
898         sal_Bool bEnable = aCbTableHeadon.IsChecked();
899 
900         aRbHeadlColnms.Enable( bEnable );
901         aRbHeadlEmpty.Enable( bEnable );
902     }
903     return 0;
904 }
905 /* ---------------------------------------------------------------------------
906 
907  ---------------------------------------------------------------------------*/
908 static void lcl_InsTextInArr( const String& rTxt, _DB_Columns& rColArr )
909 {
910     _DB_Column* pNew;
911     sal_uInt16 nSttPos = 0, nFndPos;
912     while( STRING_NOTFOUND != ( nFndPos = rTxt.Search( '\x0A', nSttPos )) )
913     {
914         if( 1 < nFndPos )
915         {
916             pNew = new _DB_Column( rTxt.Copy( nSttPos, nFndPos -1 ) );
917             rColArr.Insert( pNew, rColArr.Count() );
918         }
919         pNew = new _DB_Column;
920         rColArr.Insert( pNew, rColArr.Count() );
921         nSttPos = nFndPos + 1;
922     }
923     if( nSttPos < rTxt.Len() )
924     {
925         pNew = new _DB_Column( rTxt.Copy( nSttPos ) );
926         rColArr.Insert( pNew, rColArr.Count() );
927     }
928 }
929 /* ---------------------------------------------------------------------------
930 
931  ---------------------------------------------------------------------------*/
932 sal_Bool SwInsertDBColAutoPilot::SplitTextToColArr( const String& rTxt,
933                                 _DB_Columns& rColArr,
934                                 sal_Bool bInsField )
935 {
936     // aus dem Text wieder die einzelnen Datenbank - Spalten erzeugen
937     // und dann in einem Array speichern
938     // Die Datenbankspalten stehen in <> und muessen im Array der Spalten
939     // vorhanden sein:
940     String sTxt( rTxt );
941     sal_uInt16 nFndPos, nEndPos, nSttPos = 0;
942 
943     while( STRING_NOTFOUND != ( nFndPos = sTxt.Search( cDBFldStart, nSttPos )))
944     {
945         nSttPos = nFndPos + 1;
946         if( STRING_NOTFOUND != ( nEndPos = sTxt.Search( cDBFldEnd, nSttPos+1 )))
947         {
948             // Text in <> geklammert gefunden: was ist es denn:
949             SwInsDBColumn aSrch( sTxt.Copy( nSttPos, nEndPos - nSttPos ), 0);
950             if( aDBColumns.Seek_Entry( &aSrch, &nFndPos ) )
951             {
952                 // das ist ein gueltiges Feld
953                 // also sicher den Text "davor":
954                 const SwInsDBColumn& rFndCol = *aDBColumns[ nFndPos ];
955 
956                 _DB_Column* pNew;
957 
958                 if( 1 < nSttPos )
959                 {
960                     ::lcl_InsTextInArr( sTxt.Copy( 0, nSttPos-1 ), rColArr );
961                     sTxt.Erase( 0, nSttPos-1 );
962                 }
963 
964                 sTxt.Erase( 0, (xub_StrLen)(rFndCol.sColumn.getLength() + 2) );
965                 nSttPos = 0;
966 
967                 sal_uInt16 nSubType = 0;
968                 sal_uLong nFormat;
969                 if( rFndCol.bHasFmt )
970                 {
971                     if( rFndCol.bIsDBFmt )
972                         nFormat =  rFndCol.nDBNumFmt;
973                     else
974                     {
975                         nFormat = rFndCol.nUsrNumFmt;
976                         nSubType = nsSwExtendedSubType::SUB_OWN_FMT;
977                     }
978                 }
979                 else
980                     nFormat = 0;
981 
982                 if( bInsField )
983                 {
984                     SwWrtShell& rSh = pView->GetWrtShell();
985                     SwDBFieldType aFldType( rSh.GetDoc(), aSrch.sColumn,
986                                             aDBData );
987                     pNew = new _DB_Column( rFndCol, *new SwDBField(
988                             (SwDBFieldType*)rSh.InsertFldType( aFldType ),
989                                                             nFormat ) );
990                     if( nSubType )
991                         pNew->DB_ColumnData.pField->SetSubType( nSubType );
992                 }
993                 else
994                     pNew = new _DB_Column( rFndCol, nFormat );
995 
996                 rColArr.Insert( pNew, rColArr.Count() );
997             }
998         }
999     }
1000 
1001     // den letzten Text nicht vergessen
1002     if( sTxt.Len() )
1003         ::lcl_InsTextInArr( sTxt, rColArr );
1004 
1005     return 0 != rColArr.Count();
1006 }
1007 /* ---------------------------------------------------------------------------
1008 
1009  ---------------------------------------------------------------------------*/
1010 void SwInsertDBColAutoPilot::DataToDoc( const Sequence<Any>& rSelection,
1011     Reference< XDataSource> xSource,
1012     Reference< XConnection> xConnection,
1013     Reference< sdbc::XResultSet > xResultSet )
1014 {
1015     const Any* pSelection = rSelection.getLength() ? rSelection.getConstArray() : 0;
1016     SwWrtShell& rSh = pView->GetWrtShell();
1017 
1018     //with the drag and drop interface no result set is initially available
1019     sal_Bool bDisposeResultSet = sal_False;
1020     // we don't have a cursor, so we have to create our own RowSet
1021     if ( !xResultSet.is() )
1022     {
1023         xResultSet = SwNewDBMgr::createCursor(aDBData.sDataSource,aDBData.sCommand,aDBData.nCommandType,xConnection);
1024         bDisposeResultSet = xResultSet.is();
1025     }
1026 
1027     Reference< sdbc::XRow > xRow(xResultSet, UNO_QUERY);
1028     if ( !xRow.is() )
1029         return;
1030 
1031     rSh.StartAllAction();
1032     sal_Bool bUndo = rSh.DoesUndo();
1033     if( bUndo )
1034         rSh.StartUndo( UNDO_EMPTY );
1035 
1036     sal_Bool bAsTable = aRbAsTable.IsChecked();
1037     SvNumberFormatter& rNumFmtr = *rSh.GetNumberFormatter();
1038 
1039     if( rSh.HasSelection() )
1040         rSh.DelRight();
1041 
1042     ::std::auto_ptr<SwWait> pWait;
1043 
1044     Reference< XColumnsSupplier > xColsSupp( xResultSet, UNO_QUERY );
1045     Reference <XNameAccess> xCols = xColsSupp->getColumns();
1046 
1047     do{                                 // middle checked loop!!
1048     if( bAsTable )          // Daten als Tabelle einfuegen
1049     {
1050         rSh.DoUndo( sal_False );
1051 
1052         sal_uInt16 n, nRows = 0, nCols = aLbTableCol.GetEntryCount();
1053         if( aCbTableHeadon.IsChecked() )
1054             nRows++;
1055 
1056         if( pSelection )
1057             nRows = nRows + (sal_uInt16)rSelection.getLength();
1058         else
1059             ++nRows;
1060 
1061         // bereite das Array fuer die ausgewaehlten Spalten auf
1062         SwInsDBColumns_SAR aColFlds( 255 >= nCols ? (sal_uInt8)nCols : 255, 5 );
1063         for( n = 0; n < nCols; ++n )
1064         {
1065             sal_uInt16 nFndPos;
1066             SwInsDBColumn aSrch( aLbTableCol.GetEntry( n ), 0 );
1067             if( aDBColumns.Seek_Entry( &aSrch, &nFndPos ) )
1068                 aColFlds.Insert( aDBColumns[ nFndPos ], n );
1069             else {
1070                 ASSERT( !this, "Datenbankspalte nicht mehr gefunden" );
1071             }
1072         }
1073 
1074         if( nCols != aColFlds.Count() )
1075         {
1076             ASSERT( !this, "nicht alle Datenbankspalten gefunden" );
1077             nCols = aColFlds.Count();
1078         }
1079 
1080         if(!nRows || !nCols)
1081         {
1082             ASSERT( !this, "wrong parameters" );
1083             break;
1084         }
1085 
1086         const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
1087 
1088         sal_Bool bHTML = 0 != (::GetHtmlMode( pView->GetDocShell() ) & HTMLMODE_ON);
1089         rSh.InsertTable(
1090             pModOpt->GetInsTblFlags(bHTML),
1091             nRows, nCols, text::HoriOrientation::FULL, (pSelection ? pTAutoFmt : 0) );
1092         rSh.MoveTable( GetfnTablePrev(), GetfnTableStart() );
1093 
1094         if( pSelection && pTblSet )
1095             SetTabSet();
1096 
1097         SfxItemSet aTblSet( rSh.GetAttrPool(), RES_BOXATR_FORMAT,
1098                                                 RES_BOXATR_VALUE );
1099         sal_Bool bIsAutoUpdateCells = rSh.IsAutoUpdateCells();
1100         rSh.SetAutoUpdateCells( sal_False );
1101 
1102 
1103         if( aCbTableHeadon.IsChecked() )
1104         {
1105             for( n = 0; n < nCols; ++n )
1106             {
1107                 if( aRbHeadlColnms.IsChecked() )
1108                 {
1109                     rSh.SwEditShell::Insert2( aColFlds[ n ]->sColumn );
1110                 }
1111                 rSh.GoNextCell();
1112             }
1113         }
1114         else
1115             rSh.SetRowsToRepeat( 0 );
1116 
1117         for( sal_Int32 i = 0 ; ; ++i )
1118         {
1119             sal_Bool bBreak = sal_False;
1120             try
1121             {
1122                 if(pSelection)
1123                 {
1124                     sal_Int32 nPos = 0;
1125                     pSelection[i] >>= nPos;
1126                     bBreak = !xResultSet->absolute(nPos);
1127                 }
1128                 else if(!i)
1129                     bBreak = !xResultSet->first();
1130             }
1131             catch(const Exception& )
1132             {
1133                 bBreak = sal_True;
1134             }
1135             if(bBreak)
1136                 break;
1137 
1138             for( n = 0; n < nCols; ++n )
1139             {
1140                 // beim aller erstenmal KEIN GoNextCell, weil wir schon
1141                 // drin stehen. Auch nicht nach dem Insert das GoNextCell,
1142                 // weil am Ende eine leere Zeile einfuegt wird.
1143                 if( i || n )
1144                     rSh.GoNextCell();
1145 
1146                 const SwInsDBColumn* pEntry = aColFlds[ n ];
1147 
1148                 Reference< XColumn > xColumn;
1149                 xCols->getByName(pEntry->sColumn) >>= xColumn;
1150                 Reference< XPropertySet > xColumnProps( xColumn, UNO_QUERY );
1151                 sal_Int32 eDataType = 0;
1152                 if( xColumnProps.is() )
1153                 {
1154                     Any aType = xColumnProps->getPropertyValue(C2U("Type"));
1155                     aType >>= eDataType;
1156                 }
1157                 try
1158                 {
1159                     if( pEntry->bHasFmt )
1160                     {
1161                         SwTblBoxNumFormat aNumFmt(
1162                                         pEntry->bIsDBFmt ? pEntry->nDBNumFmt
1163                                                         : pEntry->nUsrNumFmt );
1164                         aTblSet.Put(aNumFmt);
1165                         if( xColumn.is() )
1166                         {
1167                             double fVal = xColumn->getDouble();
1168                             if( xColumn->wasNull() )
1169                                 aTblSet.ClearItem( RES_BOXATR_VALUE );
1170                             else
1171                             {
1172                                 if(rNumFmtr.GetType(aNumFmt.GetValue()) & NUMBERFORMAT_DATE)
1173                                 {
1174                                     ::Date aStandard(1,1,1900);
1175                                     if (*rNumFmtr.GetNullDate() != aStandard)
1176                                         fVal += (aStandard - *rNumFmtr.GetNullDate());
1177                                 }
1178                                 aTblSet.Put( SwTblBoxValue( fVal ));
1179                             }
1180                         }
1181                         else
1182                             aTblSet.ClearItem( RES_BOXATR_VALUE );
1183                         rSh.SetTblBoxFormulaAttrs( aTblSet );
1184                     }
1185                     //#i60207# don't insert binary data as string - creates a loop
1186                     else if( DataType::BINARY       == eDataType ||
1187                              DataType::VARBINARY    == eDataType ||
1188                              DataType::LONGVARBINARY== eDataType ||
1189                              DataType::SQLNULL      == eDataType ||
1190                              DataType::OTHER        == eDataType ||
1191                              DataType::OBJECT       == eDataType ||
1192                              DataType::DISTINCT     == eDataType ||
1193                              DataType::STRUCT       == eDataType ||
1194                              DataType::ARRAY        == eDataType ||
1195                              DataType::BLOB         == eDataType ||
1196                              DataType::CLOB         == eDataType ||
1197                              DataType::REF          == eDataType
1198                              )
1199                     {
1200                         // do nothing
1201                     }
1202                     else
1203                     {
1204                         rtl::OUString sVal =  xColumn->getString();
1205                         if(!xColumn->wasNull())
1206                         {
1207                             rSh.SwEditShell::Insert2( sVal );
1208                         }
1209                     }
1210                 }
1211                 catch(Exception&
1212 #ifdef DBG_UTIL
1213                             aExcept
1214 #endif
1215                 )
1216                 {
1217                     DBG_ERROR(ByteString(String(aExcept.Message), gsl_getSystemTextEncoding()).GetBuffer());
1218                 }
1219             }
1220 
1221             if( !pSelection )
1222             {
1223                 if ( !xResultSet->next() )
1224                     break;
1225             }
1226             else if( i+1 >= rSelection.getLength() )
1227                 break;
1228 
1229             if( 10 == i )
1230                 pWait = ::std::auto_ptr<SwWait>(new SwWait( *pView->GetDocShell(), sal_True ));
1231         }
1232 
1233         rSh.MoveTable( GetfnTableCurr(), GetfnTableStart() );
1234         if( !pSelection && ( pTblSet || pTAutoFmt ))
1235         {
1236             if( pTblSet )
1237                 SetTabSet();
1238 
1239             if( pTAutoFmt )
1240                 rSh.SetTableAutoFmt( *pTAutoFmt );
1241         }
1242         rSh.SetAutoUpdateCells( bIsAutoUpdateCells );
1243     }
1244     else                            // Daten als Felder/Text einfuegen
1245     {
1246         _DB_Columns aColArr;
1247         if( SplitTextToColArr( aEdDbText.GetText(), aColArr, aRbAsField.IsChecked() ) )
1248         {
1249             // jetzt kann bei jedem Datensatz einfach ueber das Array iteriert
1250             // und die Daten eingefuegt werden
1251 
1252             if( !rSh.IsSttPara() )
1253                 rSh.SwEditShell::SplitNode();
1254             if( !rSh.IsEndPara() )
1255             {
1256                 rSh.SwEditShell::SplitNode();
1257                 rSh.SwCrsrShell::Left(1,CRSR_SKIP_CHARS);
1258             }
1259 
1260             rSh.DoUndo( sal_False );
1261 
1262             SwTxtFmtColl* pColl = 0;
1263             {
1264                 String sTmplNm( aLbDbParaColl.GetSelectEntry() );
1265                 if( sNoTmpl != sTmplNm )
1266                 {
1267                     pColl = rSh.FindTxtFmtCollByName( sTmplNm );
1268                     if( !pColl )
1269                     {
1270                         sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( sTmplNm, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
1271                         if( USHRT_MAX != nId )
1272                             pColl = rSh.GetTxtCollFromPool( nId );
1273                         else
1274                             pColl = rSh.MakeTxtFmtColl( sTmplNm );
1275                     }
1276                     rSh.SetTxtFmtColl( pColl );
1277                 }
1278             }
1279 
1280             // fuers Einfuegen als Felder -> nach jedem Datensatz ein
1281             // "NextField" einfuegen
1282             SwDBFormatData aDBFormatData;
1283             Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
1284             if( xMgr.is() )
1285             {
1286                 Reference<XInterface> xInstance = xMgr->createInstance( C2U( "com.sun.star.util.NumberFormatter" ));
1287                 aDBFormatData.xFormatter = Reference<util::XNumberFormatter>(xInstance, UNO_QUERY) ;
1288             }
1289 
1290             Reference<XPropertySet> xSourceProps(xSource, UNO_QUERY);
1291             if(xSourceProps.is())
1292             {
1293               Any aFormats = xSourceProps->getPropertyValue(C2U("NumberFormatsSupplier"));
1294               if(aFormats.hasValue())
1295               {
1296                   Reference< util::XNumberFormatsSupplier> xSuppl;
1297                   aFormats >>= xSuppl;
1298                   if(xSuppl.is())
1299                   {
1300                         Reference< XPropertySet > xSettings = xSuppl->getNumberFormatSettings();
1301                         Any aNull = xSettings->getPropertyValue(C2U("NullDate"));
1302                         aNull >>= aDBFormatData.aNullDate;
1303                         if(aDBFormatData.xFormatter.is())
1304                             aDBFormatData.xFormatter->attachNumberFormatsSupplier(xSuppl);
1305                   }
1306               }
1307             }
1308             aDBFormatData.aLocale = SvxCreateLocale( rSh.GetCurLang() );
1309             SwDBNextSetField aNxtDBFld( (SwDBNextSetFieldType*)rSh.
1310                                         GetFldType( 0, RES_DBNEXTSETFLD ),
1311                                         C2S("1"), aEmptyStr, aDBData );
1312 
1313 
1314             sal_Bool bSetCrsr = sal_True;
1315             sal_uInt16 n = 0, nCols = aColArr.Count();
1316             ::sw::mark::IMark* pMark = NULL;
1317             for( sal_Int32 i = 0 ; ; ++i )
1318             {
1319                 sal_Bool bBreak = sal_False;
1320                 try
1321                 {
1322                     if(pSelection)
1323                     {
1324                         sal_Int32 nPos = 0;
1325                         pSelection[i] >>= nPos;
1326                         bBreak = !xResultSet->absolute(nPos);
1327                     }
1328                     else if(!i)
1329                         bBreak = !xResultSet->first();
1330                 }
1331                 catch(Exception&)
1332                 {
1333                     bBreak = sal_True;
1334                 }
1335 
1336                 if(bBreak)
1337                     break;
1338 
1339 
1340                 for( n = 0; n < nCols; ++n )
1341                 {
1342                     _DB_Column* pDBCol = aColArr[ n ];
1343                     String sIns;
1344                     switch( pDBCol->eColType )
1345                     {
1346                     case _DB_Column::DB_FILLTEXT:
1347                         sIns =  *pDBCol->DB_ColumnData.pText;
1348                         break;
1349 
1350                     case _DB_Column::DB_SPLITPARA:
1351                         rSh.SplitNode();
1352                         // wenn nicht die gleiche Vorlage die Follow Vorlage
1353                         // ist, dann muss die ausgewaehlte neu gesetzt werden
1354                         if( pColl && &pColl->GetNextTxtFmtColl() != pColl )
1355                             rSh.SetTxtFmtColl( pColl );
1356                         break;
1357 
1358                     case _DB_Column::DB_COL_FIELD:
1359                         {
1360                             SwDBField *const pFld = static_cast<SwDBField *>(
1361                                 pDBCol->DB_ColumnData.pField->CopyField());
1362                             double nValue = DBL_MAX;
1363 
1364                             Reference< XPropertySet > xColumnProps;
1365                             xCols->getByName(pDBCol->pColInfo->sColumn) >>= xColumnProps;
1366 
1367                             pFld->SetExpansion( SwNewDBMgr::GetDBField(
1368                                                 xColumnProps,
1369                                                 aDBFormatData,
1370                                                 &nValue ) );
1371                             if( DBL_MAX != nValue )
1372                             {
1373                                 Any aType = xColumnProps->getPropertyValue(C2U("Type"));
1374                                 sal_Int32 eDataType = 0;
1375                                 aType >>= eDataType;
1376                                 if( DataType::DATE == eDataType  || DataType::TIME == eDataType  ||
1377                                     DataType::TIMESTAMP  == eDataType)
1378 
1379                                 {
1380                                     ::Date aStandard(1,1,1900);
1381                                     ::Date aCompare(aDBFormatData.aNullDate.Day ,
1382                                                     aDBFormatData.aNullDate.Month,
1383                                                     aDBFormatData.aNullDate.Year);
1384                                     if(aStandard != aCompare)
1385                                         nValue += (aStandard - aCompare);
1386                                 }
1387                                 pFld->ChgValue( nValue, sal_True );
1388                             }
1389                             pFld->SetInitialized();
1390 
1391                             rSh.Insert( *pFld );
1392                             delete pFld;
1393                         }
1394                         break;
1395 
1396                     case _DB_Column::DB_COL_TEXT:
1397                         {
1398                             double nValue = DBL_MAX;
1399                             Reference< XPropertySet > xColumnProps;
1400                             xCols->getByName(pDBCol->pColInfo->sColumn) >>= xColumnProps;
1401                             sIns = SwNewDBMgr::GetDBField(
1402                                                 xColumnProps,
1403                                                 aDBFormatData,
1404                                                 &nValue );
1405                             if( pDBCol->DB_ColumnData.nFormat &&
1406                                 DBL_MAX != nValue )
1407                             {
1408                                 Color* pCol;
1409                                 if(rNumFmtr.GetType(pDBCol->DB_ColumnData.nFormat) & NUMBERFORMAT_DATE)
1410                                 {
1411                                     ::Date aStandard(1,1,1900);
1412                                     if (*rNumFmtr.GetNullDate() != aStandard)
1413                                         nValue += (aStandard - *rNumFmtr.GetNullDate());
1414                                 }
1415                                 rNumFmtr.GetOutputString( nValue,
1416                                             pDBCol->DB_ColumnData.nFormat,
1417                                             sIns, &pCol );
1418                             }
1419                         }
1420                         break;
1421                     }
1422 
1423                     if( sIns.Len() )
1424                         rSh.Insert( sIns );
1425 
1426                     if( bSetCrsr && sIns.Len() )
1427                     {
1428                         // zum Anfang und eine Mark setzen, damit der
1429                         // Cursor am Ende wieder auf Anfangsposition
1430                         // gesetzt werden kann.
1431 
1432                         // rSh.SwCrsrShell::MovePara( fnParaCurr, fnParaStart );
1433                         rSh.SwCrsrShell::MovePara(
1434                             GetfnParaCurr(), GetfnParaStart() );
1435                         pMark = rSh.SetBookmark(
1436                             KeyCode(),
1437                             ::rtl::OUString(),
1438                             ::rtl::OUString(), IDocumentMarkAccess::UNO_BOOKMARK );
1439                         // rSh.SwCrsrShell::MovePara( fnParaCurr, fnParaEnd );
1440                         rSh.SwCrsrShell::MovePara(
1441                             GetfnParaCurr(), GetfnParaEnd() );
1442                         bSetCrsr = sal_False;
1443                     }
1444                 }
1445 
1446                 if( !pSelection )
1447                 {
1448                     sal_Bool bNext = xResultSet->next();
1449                     if(!bNext)
1450                         break;
1451                 }
1452                 else if( i+1 >= rSelection.getLength() )
1453                     break;
1454 
1455                 if( aRbAsField.IsChecked() )
1456                     rSh.Insert( aNxtDBFld );
1457 
1458                 if( !rSh.IsSttPara() )
1459                     rSh.SwEditShell::SplitNode();
1460 
1461                 if( 10 == i )
1462                     pWait = ::std::auto_ptr<SwWait>(new SwWait( *pView->GetDocShell(), sal_True ));
1463             }
1464 
1465             if( !bSetCrsr && pMark != NULL)
1466             {
1467                 rSh.SetMark();
1468                 rSh.GotoMark( pMark );
1469                 rSh.getIDocumentMarkAccess()->deleteMark( pMark );
1470                 break;
1471             }
1472         }
1473     }
1474     // write configuration
1475     Commit();
1476     }while( sal_False );                    // middle checked loop
1477 
1478     if( bUndo )
1479     {
1480         rSh.DoUndo( sal_True );
1481         rSh.AppendUndoForInsertFromDB( bAsTable );
1482         rSh.EndUndo( UNDO_EMPTY );
1483     }
1484     rSh.ClearMark();
1485     rSh.EndAllAction();
1486 
1487     if ( bDisposeResultSet )
1488         ::comphelper::disposeComponent(xResultSet);
1489 }
1490 void SwInsertDBColAutoPilot::SetTabSet()
1491 {
1492     SwWrtShell& rSh = pView->GetWrtShell();
1493     const SfxPoolItem* pItem;
1494 
1495     if( pTAutoFmt )
1496     {
1497         if( pTAutoFmt->IsFrame() )
1498         {
1499             // Umrandung kommt vom AutoFormat
1500             pTblSet->ClearItem( RES_BOX );
1501             pTblSet->ClearItem( SID_ATTR_BORDER_INNER );
1502         }
1503         if( pTAutoFmt->IsBackground() )
1504         {
1505             pTblSet->ClearItem( RES_BACKGROUND );
1506             pTblSet->ClearItem( SID_ATTR_BRUSH_ROW );
1507             pTblSet->ClearItem( SID_ATTR_BRUSH_TABLE );
1508         }
1509     }
1510     else
1511     {
1512         // die Defaults wieder entfernen, es macht keinen Sinn sie zu setzen
1513         SvxBrushItem aBrush( RES_BACKGROUND );
1514         static sal_uInt16 __READONLY_DATA aIds[3] =
1515             { RES_BACKGROUND, SID_ATTR_BRUSH_ROW, SID_ATTR_BRUSH_TABLE };
1516         for( int i = 0; i < 3; ++i )
1517             if( SFX_ITEM_SET == pTblSet->GetItemState( aIds[ i ],
1518                 sal_False, &pItem ) && *pItem == aBrush )
1519                 pTblSet->ClearItem( aIds[ i ] );
1520     }
1521 
1522     if( SFX_ITEM_SET == pTblSet->GetItemState( FN_PARAM_TABLE_NAME, sal_False,
1523         &pItem ) && ((const SfxStringItem*)pItem)->GetValue() ==
1524                     rSh.GetTableFmt()->GetName() )
1525         pTblSet->ClearItem( FN_PARAM_TABLE_NAME );
1526 
1527     rSh.MoveTable( GetfnTableCurr(), GetfnTableStart() );
1528     rSh.SetMark();
1529     rSh.MoveTable( GetfnTableCurr(), GetfnTableEnd() );
1530 
1531     ItemSetToTableParam( *pTblSet, rSh );
1532 
1533     rSh.ClearMark();
1534     rSh.MoveTable( GetfnTableCurr(), GetfnTableStart() );
1535 }
1536 
1537 /*  */
1538 
1539 
1540 _DB_ColumnConfigData::~_DB_ColumnConfigData() {}
1541 
1542 /* -----------------------------05.12.00 16:15--------------------------------
1543 
1544  ---------------------------------------------------------------------------*/
1545 static Sequence<rtl::OUString> lcl_createSourceNames(const String& rNodeName)
1546 {
1547     Sequence<rtl::OUString> aSourceNames(11);
1548     rtl::OUString* pNames = aSourceNames.getArray();
1549 
1550     String sTmp( rNodeName );
1551     const xub_StrLen nPos = sTmp.Len();
1552     pNames[0] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1553                             RTL_CONSTASCII_STRINGPARAM( "/DataSource" ));
1554     pNames[1] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1555                             RTL_CONSTASCII_STRINGPARAM( "/Command" ));
1556     pNames[2] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1557                             RTL_CONSTASCII_STRINGPARAM( "/CommandType" ));
1558     pNames[3] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1559                             RTL_CONSTASCII_STRINGPARAM( "/ColumnsToText" ));
1560     pNames[4] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1561                             RTL_CONSTASCII_STRINGPARAM( "/ColumnsToTable" ));
1562     pNames[5] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1563                             RTL_CONSTASCII_STRINGPARAM( "/ParaStyle" ));
1564     pNames[6] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1565                             RTL_CONSTASCII_STRINGPARAM( "/TableAutoFormat" ));
1566     pNames[7] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1567                             RTL_CONSTASCII_STRINGPARAM( "/IsTable" ));
1568     pNames[8] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1569                             RTL_CONSTASCII_STRINGPARAM( "/IsField" ));
1570     pNames[9] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1571                             RTL_CONSTASCII_STRINGPARAM( "/IsHeadlineOn" ));
1572     pNames[10] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1573                             RTL_CONSTASCII_STRINGPARAM( "/IsEmptyHeadline" ));
1574     return aSourceNames;
1575 }
1576 /* -----------------------------05.12.00 16:25--------------------------------
1577 
1578  ---------------------------------------------------------------------------*/
1579 static Sequence<rtl::OUString> lcl_CreateSubNames( const String& rSubNodeName )
1580 {
1581     Sequence<rtl::OUString> aSubSourceNames(6);
1582     rtl::OUString* pNames = aSubSourceNames.getArray();
1583     String sTmp( rSubNodeName );
1584     const xub_StrLen nPos = sTmp.Len();
1585     pNames[0] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1586                             RTL_CONSTASCII_STRINGPARAM( "/ColumnName" ));
1587     pNames[1] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1588                             RTL_CONSTASCII_STRINGPARAM( "/ColumnIndex" ));
1589     pNames[2] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1590                             RTL_CONSTASCII_STRINGPARAM( "/IsNumberFormat" ));
1591     pNames[3] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1592                             RTL_CONSTASCII_STRINGPARAM( "/IsNumberFormatFromDataBase" ));
1593     pNames[4] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1594                             RTL_CONSTASCII_STRINGPARAM( "/NumberFormat" ));
1595     pNames[5] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1596                             RTL_CONSTASCII_STRINGPARAM( "/NumberFormatLocale" ));
1597     return aSubSourceNames;
1598 }
1599 /* -----------------------------06.12.00 13:03--------------------------------
1600 
1601  ---------------------------------------------------------------------------*/
1602 static rtl::OUString lcl_CreateUniqueName(const Sequence<rtl::OUString>& aNames)
1603 {
1604     sal_Int32 nIdx = aNames.getLength();
1605     const rtl::OUString* pNames = aNames.getConstArray();
1606     rtl::OUString sTest(C2U("_"));
1607     rtl::OUString sRet;
1608     while(sal_True)
1609     {
1610         sRet = sTest; sRet += rtl::OUString::valueOf(nIdx++);
1611         sal_Bool bFound = sal_False;
1612         for(sal_Int32 i = 0; i < aNames.getLength(); i++)
1613         {
1614             if(pNames[i] == sRet)
1615             {
1616                 bFound = sal_True;
1617                 break;
1618             }
1619         }
1620         if(!bFound)
1621             break;
1622     }
1623     return sRet;
1624 }
1625 /* -----------------------------05.12.00 15:00--------------------------------
1626 
1627  ---------------------------------------------------------------------------*/
1628 void SwInsertDBColAutoPilot::Notify( const ::com::sun::star::uno::Sequence< rtl::OUString >&  ) {}
1629 
1630 void SwInsertDBColAutoPilot::Commit()
1631 {
1632     Sequence <rtl::OUString> aNames = GetNodeNames(rtl::OUString());
1633     const rtl::OUString* pNames = aNames.getArray();
1634     //remove entries that contain this data source + table at first
1635     for(sal_Int32 nNode = 0; nNode < aNames.getLength(); nNode++)
1636     {
1637         Sequence<rtl::OUString> aSourceNames(2);
1638         rtl::OUString* pSourceNames = aSourceNames.getArray();
1639         pSourceNames[0] = pNames[nNode];
1640         pSourceNames[0] += C2U("/DataSource");
1641         pSourceNames[1] = pNames[nNode];
1642         pSourceNames[1] += C2U("/Command");
1643         Sequence<Any> aSourceProperties = GetProperties(aSourceNames);
1644         const Any* pSourceProps = aSourceProperties.getArray();
1645         rtl::OUString sSource, sCommand;
1646         pSourceProps[0] >>= sSource;
1647         pSourceProps[1] >>= sCommand;
1648         if(sSource.equals(aDBData.sDataSource) && sCommand.equals(aDBData.sCommand))
1649         {
1650             Sequence<rtl::OUString> aElements(1);
1651             aElements.getArray()[0] = pNames[nNode];
1652             ClearNodeElements(rtl::OUString(), aElements);
1653         }
1654     }
1655 
1656     aNames = GetNodeNames(rtl::OUString());
1657     rtl::OUString sNewNode = lcl_CreateUniqueName(aNames);
1658     Sequence<rtl::OUString> aNodeNames = lcl_createSourceNames(sNewNode);
1659     Sequence<PropertyValue> aValues(aNodeNames.getLength());
1660     PropertyValue* pValues = aValues.getArray();
1661     const rtl::OUString* pNodeNames = aNodeNames.getConstArray();
1662     rtl::OUString sSlash(C2U("/"));
1663     for(sal_Int32 i = 0; i < aNodeNames.getLength(); i++)
1664     {
1665         pValues[i].Name = sSlash;
1666         pValues[i].Name += pNodeNames[i];
1667     }
1668 
1669     pValues[0].Value <<= rtl::OUString(aDBData.sDataSource);
1670     pValues[1].Value <<= rtl::OUString(aDBData.sCommand);
1671     pValues[2].Value <<= aDBData.nCommandType;
1672     pValues[3].Value <<= rtl::OUString(aEdDbText.GetText());
1673 
1674     String sTmp;
1675     for( sal_uInt16 n = 0, nCnt = aLbTableCol.GetEntryCount(); n < nCnt; ++n )
1676         ( sTmp += aLbTableCol.GetEntry( n ) ) += '\x0a';
1677 
1678     if( sTmp.Len() )
1679         pValues[4].Value <<= rtl::OUString(sTmp);
1680 
1681     if( sNoTmpl != (sTmp = aLbDbParaColl.GetSelectEntry()) )
1682         pValues[5].Value <<= rtl::OUString(sTmp);
1683 
1684     if( pTAutoFmt )
1685         pValues[6].Value <<= rtl::OUString(pTAutoFmt->GetName());
1686 
1687     const Type& rBoolType = ::getBooleanCppuType();
1688     sal_Bool bTmp = aRbAsTable.IsChecked();
1689     pValues[7].Value.setValue(&bTmp, rBoolType);
1690 
1691     bTmp = aRbAsField.IsChecked();
1692     pValues[8].Value.setValue(&bTmp, rBoolType);
1693 
1694     bTmp = aCbTableHeadon.IsChecked();
1695     pValues[9].Value.setValue(&bTmp, rBoolType);
1696 
1697     bTmp = aRbHeadlEmpty.IsChecked();
1698     pValues[10].Value.setValue(&bTmp, rBoolType);
1699 
1700     SetSetProperties(rtl::OUString(), aValues);
1701 
1702     sNewNode += C2U("/ColumnSet");
1703     String sDelim( String::CreateFromAscii( "/__" ));
1704 
1705     LanguageType ePrevLang = (LanguageType)-1;
1706     rtl::OUString sPrevLang;
1707 
1708     SvNumberFormatter& rNFmtr = *pView->GetWrtShell().GetNumberFormatter();
1709     for(sal_uInt16 nCol = 0; nCol < aDBColumns.Count(); nCol++)
1710     {
1711         rtl::OUString sColumnNode = sNewNode;
1712         SwInsDBColumn* pColumn = aDBColumns[nCol];
1713         String sColumnInsertNode(sColumnNode);
1714         sColumnInsertNode += sDelim;
1715         if( nCol < 100 )
1716             sColumnInsertNode += '0';
1717         if( nCol < 10 )
1718             sColumnInsertNode += '0';
1719         sColumnInsertNode += String::CreateFromInt32(  nCol );
1720 
1721         Sequence <rtl::OUString> aSubNodeNames = lcl_CreateSubNames(sColumnInsertNode);
1722         Sequence<PropertyValue> aSubValues(aSubNodeNames.getLength());
1723         PropertyValue* pSubValues = aSubValues.getArray();
1724         const rtl::OUString* pSubNodeNames = aSubNodeNames.getConstArray();
1725         sal_Int32 i;
1726 
1727         for( i = 0; i < aSubNodeNames.getLength(); i++)
1728             pSubValues[i].Name = pSubNodeNames[i];
1729         pSubValues[0].Value <<= pColumn->sColumn;
1730         pSubValues[1].Value <<= i;
1731 
1732         sal_Bool bVal = pColumn->bHasFmt;
1733         pSubValues[2].Value.setValue(&bVal, rBoolType);
1734         bVal = pColumn->bIsDBFmt;
1735         pSubValues[3].Value.setValue(&bVal, rBoolType);
1736 
1737         SwStyleNameMapper::FillUIName( RES_POOLCOLL_STANDARD, sTmp );
1738         const SvNumberformat* pNF = rNFmtr.GetEntry( pColumn->nUsrNumFmt );
1739         LanguageType eLang;
1740         if( pNF )
1741         {
1742             pSubValues[4].Value <<= rtl::OUString(pNF->GetFormatstring());
1743             eLang = pNF->GetLanguage();
1744         }
1745         else
1746         {
1747             pSubValues[4].Value <<= rtl::OUString(sTmp);
1748             eLang = (LanguageType)GetAppLanguage();
1749         }
1750 
1751         if( eLang != ePrevLang )
1752         {
1753             Locale aLocale;
1754             aLocale = SvxLanguageToLocale( aLocale, eLang );
1755             (( sPrevLang = aLocale.Country ) += rtl::OUString( '-' )) += aLocale.Language;
1756             ePrevLang = eLang;
1757         }
1758 
1759         pSubValues[5].Value <<=  sPrevLang;
1760         SetSetProperties(sColumnNode, aSubValues);
1761     }
1762 }
1763 /* -----------------------------05.12.00 15:00--------------------------------
1764 
1765  ---------------------------------------------------------------------------*/
1766 void SwInsertDBColAutoPilot::Load()
1767 {
1768     Sequence <rtl::OUString> aNames = GetNodeNames(rtl::OUString());
1769     const rtl::OUString* pNames = aNames.getArray();
1770     SvNumberFormatter& rNFmtr = *pView->GetWrtShell().GetNumberFormatter();
1771     for(sal_Int32 nNode = 0; nNode < aNames.getLength(); nNode++)
1772     {
1773         //search for entries with the appropriate data source and table
1774         Sequence<rtl::OUString> aSourceNames = lcl_createSourceNames(pNames[nNode]);
1775 
1776         Sequence< Any> aDataSourceProps = GetProperties(aSourceNames);
1777         const Any* pDataSourceProps = aDataSourceProps.getConstArray();
1778         rtl::OUString sSource, sCommand;
1779         sal_Int16 nCommandType;
1780         pDataSourceProps[0] >>= sSource;
1781         pDataSourceProps[1] >>= sCommand;
1782         pDataSourceProps[2] >>= nCommandType;
1783         if(sSource.equals(aDBData.sDataSource) && sCommand.equals(aDBData.sCommand))
1784         {
1785             _DB_ColumnConfigData* pNewData = new _DB_ColumnConfigData;
1786             pNewData->sSource = sSource;
1787             pNewData->sTable = sCommand;
1788 
1789             pDataSourceProps[3] >>= pNewData->sEdit;
1790             pDataSourceProps[4] >>= pNewData->sTblList;
1791             pDataSourceProps[5] >>= pNewData->sTmplNm;
1792             pDataSourceProps[6] >>= pNewData->sTAutoFmtNm;
1793             if(pDataSourceProps[7].hasValue())
1794                 pNewData->bIsTable = *(sal_Bool*)pDataSourceProps[7].getValue();
1795             if(pDataSourceProps[8].hasValue())
1796                 pNewData->bIsField = *(sal_Bool*)pDataSourceProps[8].getValue();
1797             if(pDataSourceProps[9].hasValue())
1798                 pNewData->bIsHeadlineOn = *(sal_Bool*)pDataSourceProps[9].getValue();
1799             if(pDataSourceProps[10].hasValue())
1800                 pNewData->bIsEmptyHeadln = *(sal_Bool*)pDataSourceProps[10].getValue();
1801 
1802             rtl::OUString sSubNodeName(pNames[nNode]);
1803             sSubNodeName += C2U("/ColumnSet/");
1804             Sequence <rtl::OUString> aSubNames = GetNodeNames(sSubNodeName);
1805             const rtl::OUString* pSubNames = aSubNames.getConstArray();
1806             for(sal_Int32 nSub = 0; nSub < aSubNames.getLength(); nSub++)
1807             {
1808                 rtl::OUString sSubSubNodeName(sSubNodeName);
1809                 sSubSubNodeName += pSubNames[nSub];
1810                 Sequence <rtl::OUString> aSubNodeNames = lcl_CreateSubNames(sSubSubNodeName);
1811                 Sequence< Any> aSubProps = GetProperties(aSubNodeNames);
1812                 const Any* pSubProps = aSubProps.getConstArray();
1813 
1814                 rtl::OUString sColumn;
1815                 pSubProps[0] >>= sColumn;
1816                 //check for existance of the loaded column name
1817                 sal_Bool bFound = sal_False;
1818                 for(sal_Int32 nRealColumn = 0; nRealColumn < aDBColumns.Count(); nRealColumn++)
1819                 {
1820                     if(aDBColumns[(sal_uInt16)nRealColumn]->sColumn == sColumn)
1821                     {
1822                         bFound = sal_True;
1823                         break;
1824                     }
1825                 }
1826                 if(!bFound)
1827                     continue;
1828                 sal_Int16 nIndex = 0;
1829                 pSubProps[1] >>= nIndex;
1830                 SwInsDBColumnPtr pInsDBColumn = new SwInsDBColumn(sColumn, nIndex);
1831                 if(pSubProps[2].hasValue())
1832                     pInsDBColumn->bHasFmt = *(sal_Bool*)pSubProps[2].getValue();
1833                 if(pSubProps[3].hasValue())
1834                     pInsDBColumn->bIsDBFmt = *(sal_Bool*)pSubProps[3].getValue();
1835 
1836                 pSubProps[4] >>= pInsDBColumn->sUsrNumFmt;
1837                 rtl::OUString sNumberFormatLocale;
1838                 pSubProps[5] >>= sNumberFormatLocale;
1839 
1840                 Locale aLocale;
1841                 aLocale.Language = sNumberFormatLocale.copy(0, 2);
1842                 aLocale.Country = sNumberFormatLocale.copy(3, 2);
1843                 pInsDBColumn->eUsrNumFmtLng = SvxLocaleToLanguage( aLocale );
1844 
1845                 pInsDBColumn->nUsrNumFmt = rNFmtr.GetEntryKey( pInsDBColumn->sUsrNumFmt,
1846                                                         pInsDBColumn->eUsrNumFmtLng );
1847 
1848 //              pInsDBColumn->nDBNumFmt
1849 
1850                 pNewData->aDBColumns.Insert(pInsDBColumn);
1851             }
1852             sal_uInt16 n = 0;
1853             String sTmp( pNewData->sTblList );
1854             if( sTmp.Len() )
1855             {
1856                 do {
1857                     String sEntry( sTmp.GetToken( 0, '\x0a', n ) );
1858                     //preselect column - if they still exist!
1859                     if(aLbTblDbColumn.GetEntryPos(sEntry) != LISTBOX_ENTRY_NOTFOUND)
1860                     {
1861                         aLbTableCol.InsertEntry( sEntry );
1862                         aLbTblDbColumn.RemoveEntry( sEntry );
1863                     }
1864                 } while( n < sTmp.Len() );
1865 
1866                 if( !aLbTblDbColumn.GetEntryCount() )
1867                 {
1868                     aIbDbcolAllTo.Enable( sal_False );
1869                     aIbDbcolOneTo.Enable( sal_False );
1870                 }
1871                 aIbDbcolOneFrom.Enable( sal_True );
1872                 aIbDbcolAllFrom.Enable( sal_True );
1873             }
1874             aEdDbText.SetText( pNewData->sEdit );
1875 
1876             sTmp = pNewData->sTmplNm;
1877             if( sTmp.Len() )
1878                 aLbDbParaColl.SelectEntry( sTmp );
1879             else
1880                 aLbDbParaColl.SelectEntryPos( 0 );
1881 
1882             if( pTAutoFmt )
1883                 delete pTAutoFmt, pTAutoFmt = 0;
1884             sTmp = pNewData->sTAutoFmtNm;
1885             if( sTmp.Len() )
1886             {
1887                 // dann erstmal die AutoFmt-Datei laden und das Autoformat suchen
1888                 SwTableAutoFmtTbl aAutoFmtTbl;
1889                 aAutoFmtTbl.Load();
1890                 for( sal_uInt16 nAutoFmt = aAutoFmtTbl.Count(); nAutoFmt; )
1891                     if( sTmp == aAutoFmtTbl[ --nAutoFmt ]->GetName() )
1892                     {
1893                         pTAutoFmt = new SwTableAutoFmt( *aAutoFmtTbl[ nAutoFmt ] );
1894                         break;
1895                     }
1896             }
1897 
1898             aRbAsTable.Check( pNewData->bIsTable );
1899             aRbAsField.Check( pNewData->bIsField );
1900             aRbAsText.Check( !pNewData->bIsTable && !pNewData->bIsField );
1901 
1902             aCbTableHeadon.Check( pNewData->bIsHeadlineOn );
1903             aRbHeadlColnms.Check( !pNewData->bIsEmptyHeadln );
1904             aRbHeadlEmpty.Check( pNewData->bIsEmptyHeadln );
1905             HeaderHdl(&aCbTableHeadon);
1906 
1907             // jetzt noch die benutzerdefinierten Numberformat Strings in die
1908             // Shell kopieren. Nur diese sind dann als ID verfuegbar
1909             for( n = 0; n < aDBColumns.Count() ; ++n )
1910             {
1911                 SwInsDBColumn& rSet = *aDBColumns[ n ];
1912                 for( sal_uInt16 m = 0; m < pNewData->aDBColumns.Count() ; ++m )
1913                 {
1914                     SwInsDBColumn& rGet = *pNewData->aDBColumns[ m ];
1915                     if(rGet.sColumn == rSet.sColumn)
1916                     {
1917                         if( rGet.bHasFmt && !rGet.bIsDBFmt )
1918                         {
1919                             rSet.bIsDBFmt = sal_False;
1920                             rSet.nUsrNumFmt = rNFmtr.GetEntryKey( rGet.sUsrNumFmt,
1921                                                                     rGet.eUsrNumFmtLng );
1922                             if( NUMBERFORMAT_ENTRY_NOT_FOUND == rSet.nUsrNumFmt )
1923                             {
1924                                 xub_StrLen nCheckPos;
1925                                 short nType;
1926                                 String sTmpFmt = rGet.sUsrNumFmt;
1927                                 rNFmtr.PutEntry( sTmpFmt, nCheckPos, nType,
1928                                                 rSet.nUsrNumFmt, rGet.eUsrNumFmtLng );
1929                                 rGet.sUsrNumFmt = sTmpFmt;
1930                             }
1931                         }
1932                         break;
1933                     }
1934                 }
1935             }
1936 
1937             // steht der Cursor in einer Tabelle, darf NIE Tabelle auswaehlbar sein
1938             if( !aRbAsTable.IsEnabled() && aRbAsTable.IsChecked() )
1939                 aRbAsField.Check( sal_True );
1940             delete pNewData;
1941             break;
1942         }
1943     }
1944 }
1945 
1946