update credits
[LibreOffice.git] / sw / source / ui / dbui / dbinsdlg.cxx
blob8de8676fd7e2bb7ced3f612b7b88fb3035794949
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "dbinsdlg.hxx"
22 #include <memory>
24 #include <float.h>
26 #include <hintids.hxx>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/container/XNameAccess.hpp>
29 #include <com/sun/star/sdbc/XDataSource.hpp>
30 #include <com/sun/star/sdbc/XRow.hpp>
31 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
32 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
33 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
34 #include <com/sun/star/sdb/CommandType.hpp>
35 #include <com/sun/star/sdb/XColumn.hpp>
36 #include <com/sun/star/sdb/XDatabaseAccess.hpp>
37 #include <com/sun/star/sdbc/DataType.hpp>
38 #include <com/sun/star/sdbc/ResultSetType.hpp>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include <com/sun/star/util/NumberFormatter.hpp>
41 #include <com/sun/star/util/XNumberFormatTypes.hpp>
42 #include <com/sun/star/sdbc/XRowSet.hpp>
43 #include <comphelper/processfactory.hxx>
44 #include <editeng/langitem.hxx>
45 #include <svl/numuno.hxx>
46 #include <svl/stritem.hxx>
47 #include <vcl/msgbox.hxx>
48 #include <vcl/svapp.hxx>
49 #include <vcl/mnemonic.hxx>
50 #include <svl/style.hxx>
51 #include <svl/zformat.hxx>
52 #include <sfx2/htmlmode.hxx>
53 #include <editeng/unolingu.hxx>
54 #include <sfx2/app.hxx>
55 #include <svl/itemset.hxx>
56 #include <editeng/brushitem.hxx>
57 #include <editeng/boxitem.hxx>
58 #include <svx/rulritem.hxx>
59 #include <swdbtoolsclient.hxx>
60 #include <tabledlg.hxx>
61 #include <fmtclds.hxx>
62 #include <tabcol.hxx>
63 #include <uiitems.hxx>
64 #include <viewopt.hxx>
65 #include <uitool.hxx>
66 #include <wrtsh.hxx>
67 #include <wview.hxx>
68 #include <docsh.hxx>
69 #include <dbmgr.hxx>
70 #include <tblafmt.hxx>
71 #include <cellatr.hxx>
72 #include <swtable.hxx>
73 #include <dbfld.hxx>
74 #include <fmtcol.hxx>
75 #include <section.hxx>
76 #include <swwait.hxx>
77 #include <modcfg.hxx>
78 #include <swmodule.hxx>
79 #include <poolfmt.hxx>
80 #include <crsskip.hxx>
82 #include <dbinsdlg.hrc>
83 #include <dbui.hrc>
85 #include <cmdid.h>
86 #include <helpid.h>
87 #include <cfgid.h>
88 #include <SwStyleNameMapper.hxx>
89 #include <comphelper/uno3.hxx>
90 #include "tabsh.hxx"
91 #include "swabstdlg.hxx"
92 #include "table.hrc"
93 #include <unomid.h>
94 #include <IDocumentMarkAccess.hxx>
96 namespace swui
98 SwAbstractDialogFactory * GetFactory();
101 using namespace ::com::sun::star;
102 using namespace ::com::sun::star::beans;
103 using namespace ::com::sun::star::container;
104 using namespace ::com::sun::star::lang;
105 using namespace ::com::sun::star::sdb;
106 using namespace ::com::sun::star::sdbc;
107 using namespace ::com::sun::star::sdbcx;
108 using namespace ::com::sun::star::uno;
110 const char cDBFldStart = '<';
111 const char cDBFldEnd = '>';
113 // Helper structure for adding database rows as fields or text
114 struct _DB_Column
116 enum ColType { DB_FILLTEXT, DB_COL_FIELD, DB_COL_TEXT, DB_SPLITPARA } eColType;
118 union {
119 String* pText;
120 SwField* pField;
121 sal_uLong nFormat;
122 } DB_ColumnData;
123 const SwInsDBColumn* pColInfo;
125 _DB_Column()
127 pColInfo = 0;
128 DB_ColumnData.pText = 0;
129 eColType = DB_SPLITPARA;
132 _DB_Column( const String& rTxt )
134 pColInfo = 0;
135 DB_ColumnData.pText = new String( rTxt );
136 eColType = DB_FILLTEXT;
139 _DB_Column( const SwInsDBColumn& rInfo, sal_uLong nFormat )
141 pColInfo = &rInfo;
142 DB_ColumnData.nFormat = nFormat;
143 eColType = DB_COL_TEXT;
146 _DB_Column( const SwInsDBColumn& rInfo, SwDBField& rFld )
148 pColInfo = &rInfo;
149 DB_ColumnData.pField = &rFld;
150 eColType = DB_COL_FIELD;
153 ~_DB_Column()
155 if( DB_COL_FIELD == eColType )
156 delete DB_ColumnData.pField;
157 else if( DB_FILLTEXT == eColType )
158 delete DB_ColumnData.pText;
163 struct _DB_ColumnConfigData
165 SwInsDBColumns aDBColumns;
166 OUString sSource, sTable, sEdit, sTblList, sTmplNm, sTAutoFmtNm;
167 sal_Bool bIsTable : 1,
168 bIsField : 1,
169 bIsHeadlineOn : 1,
170 bIsEmptyHeadln : 1;
172 _DB_ColumnConfigData()
174 bIsTable = bIsHeadlineOn = sal_True;
175 bIsField = bIsEmptyHeadln = sal_False;
178 ~_DB_ColumnConfigData();
179 private:
180 _DB_ColumnConfigData( const _DB_ColumnConfigData& );
181 _DB_ColumnConfigData& operator =( const _DB_ColumnConfigData& );
184 int SwInsDBColumn::operator<( const SwInsDBColumn& rCmp ) const
186 return 0 > GetAppCollator().compareString( sColumn, rCmp.sColumn );
189 SwInsertDBColAutoPilot::SwInsertDBColAutoPilot( SwView& rView,
190 Reference<XDataSource> xDataSource,
191 Reference<sdbcx::XColumnsSupplier> xColSupp,
192 const SwDBData& rData )
193 : SfxModalDialog( rView.GetWindow(), SW_RES( DLG_AP_INSERT_DB_SEL )),
194 ConfigItem("Office.Writer/InsertData/DataSet", CONFIG_MODE_DELAYED_UPDATE),
195 aFtInsertData( this, SW_RES( FT_INSERT_DATA )),
196 aRbAsTable( this, SW_RES( RB_AS_TABLE )),
197 aRbAsField( this, SW_RES( RB_AS_FIELD )),
198 aRbAsText( this, SW_RES( RB_AS_TEXT )),
200 aFlHead( this, SW_RES( FL_HEAD )),
201 aFtDbColumn( this, SW_RES( FT_DB_COLUMN )),
203 aLbTblDbColumn( this, SW_RES( LB_TBL_DB_COLUMN )),
204 aLbTxtDbColumn( this, SW_RES( LB_TXT_DB_COLUMN )),
206 aFlFormat( this, SW_RES( FL_FORMAT )),
207 aRbDbFmtFromDb( this, SW_RES( RB_DBFMT_FROM_DB )),
208 aRbDbFmtFromUsr( this, SW_RES( RB_DBFMT_FROM_USR )),
209 aLbDbFmtFromUsr( this, &rView, SW_RES( LB_DBFMT_FROM_USR )),
211 aIbDbcolToEdit( this, SW_RES( IB_DBCOL_TOEDIT )),
212 aEdDbText( this, SW_RES( ED_DB_TEXT )),
213 aFtDbParaColl( this, SW_RES( FT_DB_PARA_COLL )),
214 aLbDbParaColl( this, SW_RES( LB_DB_PARA_COLL )),
216 aIbDbcolAllTo( this, SW_RES( IB_DBCOL_ALL_TO )),
217 aIbDbcolOneTo( this, SW_RES( IB_DBCOL_ONE_TO )),
218 aIbDbcolOneFrom( this, SW_RES( IB_DBCOL_ONE_FROM )),
219 aIbDbcolAllFrom( this, SW_RES( IB_DBCOL_ALL_FROM )),
220 aFtTableCol( this, SW_RES( FT_TABLE_COL )),
221 aLbTableCol( this, SW_RES( LB_TABLE_COL )),
222 aCbTableHeadon( this, SW_RES( CB_TABLE_HEADON )),
223 aRbHeadlColnms( this, SW_RES( RB_HEADL_COLNMS )),
224 aRbHeadlEmpty( this, SW_RES( RB_HEADL_EMPTY )),
225 aPbTblFormat( this, SW_RES( PB_TBL_FORMAT )),
226 aPbTblAutofmt( this, SW_RES( PB_TBL_AUTOFMT )),
228 aBtOk( this, SW_RES( BT_OK )),
229 aBtCancel( this, SW_RES( BT_CANCEL )),
230 aBtHelp( this, SW_RES( BT_HELP )),
232 aFlBottom( this, SW_RES( FL_BOTTOM )),
234 aDBData(rData),
236 aOldNumFmtLnk( aLbDbFmtFromUsr.GetSelectHdl() ),
237 sNoTmpl( SW_RES( STR_NOTEMPL )),
238 pView( &rView ),
239 pTAutoFmt( 0 ),
240 pTblSet( 0 ),
241 pRep( 0 )
243 FreeResource();
245 nGBFmtLen = aFlFormat.GetText().getLength();
247 if(xColSupp.is())
249 SwWrtShell& rSh = pView->GetWrtShell();
250 SvNumberFormatter* pNumFmtr = rSh.GetNumberFormatter();
251 SvNumberFormatsSupplierObj* pNumFmt = new SvNumberFormatsSupplierObj( pNumFmtr );
252 Reference< util::XNumberFormatsSupplier > xDocNumFmtsSupplier = pNumFmt;
253 Reference< util::XNumberFormats > xDocNumberFormats = xDocNumFmtsSupplier->getNumberFormats();
254 Reference< util::XNumberFormatTypes > xDocNumberFormatTypes(xDocNumberFormats, UNO_QUERY);
256 Reference<XPropertySet> xSourceProps(xDataSource, UNO_QUERY);
257 Reference< util::XNumberFormats > xNumberFormats;
258 if(xSourceProps.is())
260 Any aFormats = xSourceProps->getPropertyValue("NumberFormatsSupplier");
261 if(aFormats.hasValue())
263 Reference< util::XNumberFormatsSupplier> xSuppl;
264 aFormats >>= xSuppl;
265 if(xSuppl.is())
267 xNumberFormats = xSuppl->getNumberFormats( );
271 Reference <XNameAccess> xCols = xColSupp->getColumns();
272 Sequence<OUString> aColNames = xCols->getElementNames();
273 const OUString* pColNames = aColNames.getConstArray();
274 long nCount = aColNames.getLength();
275 for (long n = 0; n < nCount; n++)
277 SwInsDBColumn* pNew = new SwInsDBColumn( pColNames[n], (sal_uInt16)n );
278 Any aCol = xCols->getByName(pColNames[n]);
279 Reference <XPropertySet> xCol;
280 aCol >>= xCol;
281 Any aType = xCol->getPropertyValue(OUString("Type"));
282 sal_Int32 eDataType = 0;
283 aType >>= eDataType;
284 switch(eDataType)
286 case DataType::BIT:
287 case DataType::BOOLEAN:
288 case DataType::TINYINT:
289 case DataType::SMALLINT:
290 case DataType::INTEGER:
291 case DataType::BIGINT:
292 case DataType::FLOAT:
293 case DataType::REAL:
294 case DataType::DOUBLE:
295 case DataType::NUMERIC:
296 case DataType::DECIMAL:
297 case DataType::DATE:
298 case DataType::TIME:
299 case DataType::TIMESTAMP:
301 pNew->bHasFmt = sal_True;
302 Any aFormat = xCol->getPropertyValue("FormatKey");
303 if(aFormat.hasValue())
305 sal_Int32 nFmt = 0;
306 aFormat >>= nFmt;
307 if(xNumberFormats.is())
311 Reference<XPropertySet> xNumProps = xNumberFormats->getByKey( nFmt );
312 Any aFormatVal = xNumProps->getPropertyValue("FormatString");
313 Any aLocale = xNumProps->getPropertyValue("Locale");
314 OUString sFormat;
315 aFormatVal >>= sFormat;
316 lang::Locale aLoc;
317 aLocale >>= aLoc;
318 long nKey = xDocNumberFormats->queryKey( sFormat, aLoc, sal_True);
319 if(nKey < 0)
321 nKey = xDocNumberFormats->addNew( sFormat, aLoc );
323 pNew->nDBNumFmt = nKey;
325 catch (const Exception&)
327 OSL_FAIL("illegal number format key");
331 else
333 pNew->nDBNumFmt = SwNewDBMgr::GetDbtoolsClient().getDefaultNumberFormat(xCol,
334 xDocNumberFormatTypes, LanguageTag( rSh.GetCurLang() ).getLocale());
338 break;
340 if( !aDBColumns.insert( pNew ).second )
342 OSL_ENSURE( !this, "Spaltenname mehrfach vergeben?" );
343 delete pNew;
348 // fill paragraph templates-ListBox
350 SfxStyleSheetBasePool* pPool = pView->GetDocShell()->GetStyleSheetPool();
351 pPool->SetSearchMask( SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL );
352 aLbDbParaColl.InsertEntry( sNoTmpl );
354 const SfxStyleSheetBase* pBase = pPool->First();
355 while( pBase )
357 aLbDbParaColl.InsertEntry( pBase->GetName() );
358 pBase = pPool->Next();
360 aLbDbParaColl.SelectEntryPos( 0 );
363 // when the cursor is inside of a table, table must NEVER be selectable
364 if( pView->GetWrtShell().GetTableFmt() )
366 aRbAsTable.Enable( sal_False );
367 aRbAsField.Check( sal_True );
368 aRbDbFmtFromDb.Check( sal_True );
370 else
372 aRbAsTable.Check( sal_True );
373 aRbDbFmtFromDb.Check( sal_True );
374 aIbDbcolOneFrom.Enable( sal_False );
375 aIbDbcolAllFrom.Enable( sal_False );
378 aRbAsTable.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, PageHdl ));
379 aRbAsField.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, PageHdl ));
380 aRbAsText.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, PageHdl ));
382 aRbDbFmtFromDb.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, DBFormatHdl ));
383 aRbDbFmtFromUsr.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, DBFormatHdl ));
385 aPbTblFormat.SetClickHdl(LINK(this, SwInsertDBColAutoPilot, TblFmtHdl ));
386 aPbTblAutofmt.SetClickHdl(LINK(this, SwInsertDBColAutoPilot, AutoFmtHdl ));
388 aIbDbcolAllTo.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
389 aIbDbcolOneTo.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
390 aIbDbcolOneFrom.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
391 aIbDbcolAllFrom.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
392 aIbDbcolToEdit.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
394 aCbTableHeadon.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, HeaderHdl ));
395 aRbHeadlColnms.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, HeaderHdl ));
396 aRbHeadlEmpty.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, HeaderHdl ));
398 aLbTxtDbColumn.SetSelectHdl( LINK( this, SwInsertDBColAutoPilot, SelectHdl ));
399 aLbTblDbColumn.SetSelectHdl( LINK( this, SwInsertDBColAutoPilot, SelectHdl ));
400 aLbDbFmtFromUsr.SetSelectHdl( LINK( this, SwInsertDBColAutoPilot, SelectHdl ));
401 aLbTableCol.SetSelectHdl( LINK( this, SwInsertDBColAutoPilot, SelectHdl ));
403 aLbTxtDbColumn.SetDoubleClickHdl( LINK( this, SwInsertDBColAutoPilot, DblClickHdl ));
404 aLbTblDbColumn.SetDoubleClickHdl( LINK( this, SwInsertDBColAutoPilot, DblClickHdl ));
405 aLbTableCol.SetDoubleClickHdl( LINK( this, SwInsertDBColAutoPilot, DblClickHdl ));
407 for( sal_uInt16 n = 0; n < aDBColumns.size(); ++n )
409 const String& rS = aDBColumns[ n ]->sColumn;
410 aLbTblDbColumn.InsertEntry( rS, n );
411 aLbTxtDbColumn.InsertEntry( rS, n );
413 aLbTxtDbColumn.SelectEntryPos( 0 );
414 aLbTblDbColumn.SelectEntryPos( 0 );
416 // read configuration
417 Load();
419 // initialise Controls:
420 PageHdl( aRbAsTable.IsChecked() ? &aRbAsTable : &aRbAsField );
423 SwInsertDBColAutoPilot::~SwInsertDBColAutoPilot()
425 delete pTblSet;
426 delete pRep;
428 delete pTAutoFmt;
431 IMPL_LINK( SwInsertDBColAutoPilot, PageHdl, Button*, pButton )
433 sal_Bool bShowTbl = pButton == &aRbAsTable;
435 String sTxt( pButton->GetText() );
436 aFlHead.SetText( MnemonicGenerator::EraseAllMnemonicChars( sTxt ) );
438 aLbTxtDbColumn.Show( !bShowTbl );
439 aIbDbcolToEdit.Show( !bShowTbl );
440 aEdDbText.Show( !bShowTbl );
441 aFtDbParaColl.Show( !bShowTbl );
442 aLbDbParaColl.Show( !bShowTbl );
444 aLbTblDbColumn.Show( bShowTbl );
445 aIbDbcolAllTo.Show( bShowTbl );
446 aIbDbcolOneTo.Show( bShowTbl );
447 aIbDbcolOneFrom.Show( bShowTbl );
448 aIbDbcolAllFrom.Show( bShowTbl );
449 aFtTableCol.Show( bShowTbl );
450 aLbTableCol.Show( bShowTbl );
451 aCbTableHeadon.Show( bShowTbl );
452 aRbHeadlColnms.Show( bShowTbl );
453 aRbHeadlEmpty.Show( bShowTbl );
454 aPbTblFormat.Show( bShowTbl );
455 aPbTblAutofmt.Show( bShowTbl );
457 if( bShowTbl )
458 aPbTblFormat.Enable( 0 != aLbTableCol.GetEntryCount() );
460 SelectHdl( bShowTbl ? &aLbTblDbColumn : &aLbTxtDbColumn );
462 return 0;
465 IMPL_LINK( SwInsertDBColAutoPilot, DBFormatHdl, Button*, pButton )
467 ListBox& rBox = aRbAsTable.IsChecked()
468 ? ( 0 == aLbTableCol.GetEntryData( 0 )
469 ? aLbTblDbColumn
470 : aLbTableCol )
471 : aLbTxtDbColumn;
473 SwInsDBColumn aSrch( rBox.GetSelectEntry(), 0 );
474 SwInsDBColumns::const_iterator it = aDBColumns.find( &aSrch );
476 sal_Bool bFromDB = &aRbDbFmtFromDb == pButton;
477 (*it)->bIsDBFmt = bFromDB;
478 aLbDbFmtFromUsr.Enable( !bFromDB );
480 return 0;
483 IMPL_LINK( SwInsertDBColAutoPilot, TblToFromHdl, Button*, pButton )
485 sal_Bool bChgEnable = sal_True, bEnableTo = sal_True, bEnableFrom = sal_True;
486 aLbTblDbColumn.SetUpdateMode( sal_False );
487 aLbTableCol.SetUpdateMode( sal_False );
489 if( pButton == &aIbDbcolAllTo )
491 bEnableTo = sal_False;
493 sal_uInt16 n, nInsPos = aLbTableCol.GetSelectEntryPos(),
494 nCnt = aLbTblDbColumn.GetEntryCount();
495 if( LISTBOX_APPEND == nInsPos )
496 for( n = 0; n < nCnt; ++n )
497 aLbTableCol.InsertEntry( aLbTblDbColumn.GetEntry( n ),
498 LISTBOX_APPEND );
499 else
500 for( n = 0; n < nCnt; ++n, ++nInsPos )
501 aLbTableCol.InsertEntry( aLbTblDbColumn.GetEntry( n ), nInsPos );
502 aLbTblDbColumn.Clear();
503 aLbTableCol.SelectEntryPos( nInsPos );
504 aLbTblDbColumn.SelectEntryPos( LISTBOX_APPEND );
506 else if( pButton == &aIbDbcolOneTo &&
507 LISTBOX_ENTRY_NOTFOUND != aLbTblDbColumn.GetSelectEntryPos() )
509 sal_uInt16 nInsPos = aLbTableCol.GetSelectEntryPos(),
510 nDelPos = aLbTblDbColumn.GetSelectEntryPos(),
511 nTopPos = aLbTblDbColumn.GetTopEntry();
512 aLbTableCol.InsertEntry( aLbTblDbColumn.GetEntry( nDelPos ), nInsPos );
513 aLbTblDbColumn.RemoveEntry( nDelPos );
515 aLbTableCol.SelectEntryPos( nInsPos );
516 if( nDelPos >= aLbTblDbColumn.GetEntryCount() )
517 nDelPos = aLbTblDbColumn.GetEntryCount() - 1;
518 aLbTblDbColumn.SelectEntryPos( nDelPos );
519 aLbTblDbColumn.SetTopEntry( nTopPos );
521 bEnableTo = 0 != aLbTblDbColumn.GetEntryCount();
523 else if( pButton == &aIbDbcolOneFrom )
525 if( LISTBOX_ENTRY_NOTFOUND != aLbTableCol.GetSelectEntryPos() )
527 sal_uInt16 nInsPos,
528 nDelPos = aLbTableCol.GetSelectEntryPos(),
529 nTopPos = aLbTableCol.GetTopEntry();
531 // look for the right InsertPos!!
532 SwInsDBColumn aSrch( aLbTableCol.GetEntry( nDelPos ), 0 );
533 SwInsDBColumns::const_iterator it = aDBColumns.find( &aSrch );
534 if( it == aDBColumns.begin() || (it+1) == aDBColumns.end() )
535 nInsPos = it - aDBColumns.begin();
536 else
538 nInsPos = LISTBOX_ENTRY_NOTFOUND;
539 while( ++it != aDBColumns.end() &&
540 LISTBOX_ENTRY_NOTFOUND == (nInsPos = aLbTblDbColumn.
541 GetEntryPos( String( (*it)->sColumn ))) )
545 aLbTblDbColumn.InsertEntry( aSrch.sColumn, nInsPos );
546 aLbTableCol.RemoveEntry( nDelPos );
548 if( nInsPos >= aLbTblDbColumn.GetEntryCount() )
549 nInsPos = aLbTblDbColumn.GetEntryCount() - 1;
550 aLbTblDbColumn.SelectEntryPos( nInsPos );
552 if( nDelPos >= aLbTableCol.GetEntryCount() )
553 nDelPos = aLbTableCol.GetEntryCount() - 1;
554 aLbTableCol.SelectEntryPos( nDelPos );
555 aLbTableCol.SetTopEntry( nTopPos );
557 else
558 bEnableTo = 0 != aLbTblDbColumn.GetEntryCount();
560 bEnableFrom = 0 != aLbTableCol.GetEntryCount();
562 else if( pButton == &aIbDbcolAllFrom )
564 bEnableFrom = sal_False;
566 aLbTblDbColumn.Clear();
567 aLbTableCol.Clear();
568 for( sal_uInt16 n = 0; n < aDBColumns.size(); ++n )
569 aLbTblDbColumn.InsertEntry( aDBColumns[ n ]->sColumn, n );
570 aLbTblDbColumn.SelectEntryPos( 0 );
572 else if( pButton == &aIbDbcolToEdit )
574 bChgEnable = sal_False;
575 // move data to Edit:
576 String aFld( aLbTxtDbColumn.GetSelectEntry() );
577 if( aFld.Len() )
579 String aStr( aEdDbText.GetText() );
580 sal_uInt16 nPos = (sal_uInt16)aEdDbText.GetSelection().Min();
581 sal_uInt16 nSel = sal_uInt16(aEdDbText.GetSelection().Max()) - nPos;
582 if( nSel )
583 // first delete the existing selection
584 aStr.Erase( nPos, nSel );
586 aFld.Insert( cDBFldStart, 0 );
587 aFld += cDBFldEnd;
588 if( aStr.Len() )
590 if( nPos ) // one blank in front
592 sal_Unicode c = aStr.GetChar( nPos-1 );
593 if( '\n' != c && '\r' != c )
594 aFld.Insert( ' ', 0 );
596 if( nPos < aStr.Len() ) // one blank behind
598 sal_Unicode c = aStr.GetChar( nPos );
599 if( '\n' != c && '\r' != c )
600 aFld += ' ';
604 aStr.Insert( aFld, nPos );
605 aEdDbText.SetText( aStr );
606 nPos = nPos + aFld.Len();
607 aEdDbText.SetSelection( Selection( nPos ));
611 if( bChgEnable )
613 aIbDbcolOneTo.Enable( bEnableTo );
614 aIbDbcolAllTo.Enable( bEnableTo );
615 aIbDbcolOneFrom.Enable( bEnableFrom );
616 aIbDbcolAllFrom.Enable( bEnableFrom );
618 aRbDbFmtFromDb.Enable( sal_False );
619 aRbDbFmtFromUsr.Enable( sal_False );
620 aLbDbFmtFromUsr.Enable( sal_False );
622 aPbTblFormat.Enable( bEnableFrom );
624 aLbTblDbColumn.SetUpdateMode( sal_True );
625 aLbTableCol.SetUpdateMode( sal_True );
627 return 0;
630 IMPL_LINK( SwInsertDBColAutoPilot, DblClickHdl, ListBox*, pBox )
632 Button* pButton = 0;
633 if( pBox == &aLbTxtDbColumn )
634 pButton = &aIbDbcolToEdit;
635 else if( pBox == &aLbTblDbColumn && aIbDbcolOneTo.IsEnabled() )
636 pButton = &aIbDbcolOneTo;
637 else if( pBox == &aLbTableCol && aIbDbcolOneFrom.IsEnabled() )
638 pButton = &aIbDbcolOneFrom;
640 if( pButton )
641 TblToFromHdl( pButton );
643 return 0;
646 IMPL_LINK( SwInsertDBColAutoPilot, TblFmtHdl, PushButton*, pButton )
648 SwWrtShell& rSh = pView->GetWrtShell();
649 bool bNewSet = false;
650 if( !pTblSet )
652 bNewSet = true;
653 pTblSet = new SfxItemSet( rSh.GetAttrPool(), SwuiGetUITableAttrRange() );
655 // At first acquire the simple attributes
656 pTblSet->Put( SfxStringItem( FN_PARAM_TABLE_NAME, rSh.GetUniqueTblName() ));
657 pTblSet->Put( SfxUInt16Item( FN_PARAM_TABLE_HEADLINE, 1 ) );
659 pTblSet->Put( SfxUInt16Item( SID_BACKGRND_DESTINATION,
660 rSh.GetViewOptions()->GetTblDest() ));
662 SvxBrushItem aBrush( RES_BACKGROUND );
663 pTblSet->Put( aBrush );
664 pTblSet->Put( aBrush, SID_ATTR_BRUSH_ROW );
665 pTblSet->Put( aBrush, SID_ATTR_BRUSH_TABLE );
667 SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
668 // table variant, when multiple table cells are selected
669 aBoxInfo.SetTable( sal_True );
670 // always show gap field
671 aBoxInfo.SetDist( sal_True);
672 // set minimum size in tables and paragraphs
673 aBoxInfo.SetMinDist( sal_False );
674 // always set default-gap
675 aBoxInfo.SetDefDist( MIN_BORDER_DIST );
676 // Single lines can have DontCare-status only in tables
677 aBoxInfo.SetValid( VALID_DISABLE, sal_True );
678 pTblSet->Put( aBoxInfo );
680 SwGetCurColNumPara aPara;
681 const sal_uInt16 nNum = rSh.GetCurColNum( &aPara );
682 long nWidth;
684 if( nNum )
686 nWidth = aPara.pPrtRect->Width();
687 const SwFmtCol& rCol = aPara.pFrmFmt->GetCol();
688 const SwColumns& rCols = rCol.GetColumns();
690 // initialise nStart und nEnd for nNum == 0
691 long nWidth1 = 0,
692 nStart1 = 0,
693 nEnd1 = nWidth;
694 for( sal_uInt16 i = 0; i < nNum; ++i )
696 const SwColumn* pCol = &rCols[i];
697 nStart1 = pCol->GetLeft() + nWidth1;
698 nWidth1 += (long)rCol.CalcColWidth( i, (sal_uInt16)nWidth );
699 nEnd1 = nWidth1 - pCol->GetRight();
701 if(nStart1 || nEnd1 != nWidth)
702 nWidth = nEnd1 - nStart1;
704 else
705 nWidth = rSh.GetAnyCurRect(
706 FRMTYPE_FLY_ANY & rSh.GetFrmType( 0, sal_True )
707 ? RECT_FLY_PRT_EMBEDDED
708 : RECT_PAGE_PRT ).Width();
710 SwTabCols aTabCols;
711 aTabCols.SetRight( nWidth );
712 aTabCols.SetRightMax( nWidth );
713 pRep = new SwTableRep( aTabCols );
714 pRep->SetAlign( text::HoriOrientation::NONE );
715 pRep->SetSpace( nWidth );
716 pRep->SetWidth( nWidth );
717 pRep->SetWidthPercent( 100 );
718 pTblSet->Put( SwPtrItem( FN_TABLE_REP, pRep ));
720 pTblSet->Put( SfxUInt16Item( SID_HTML_MODE,
721 ::GetHtmlMode( pView->GetDocShell() )));
724 if( aLbTableCol.GetEntryCount() != pRep->GetAllColCount() )
726 // Number of columns has changed: then the TabCols have to be adjusted
727 long nWidth = pRep->GetWidth();
728 sal_uInt16 nCols = aLbTableCol.GetEntryCount() - 1;
729 SwTabCols aTabCols( nCols );
730 aTabCols.SetRight( nWidth );
731 aTabCols.SetRightMax( nWidth );
732 if( nCols )
733 for( sal_uInt16 n = 0, nStep = (sal_uInt16)(nWidth / (nCols+1)), nW = nStep;
734 n < nCols; ++n, nW = nW + nStep )
736 aTabCols.Insert( nW, sal_False, n );
738 delete pRep;
739 pRep = new SwTableRep( aTabCols );
740 pRep->SetAlign( text::HoriOrientation::NONE );
741 pRep->SetSpace( nWidth );
742 pRep->SetWidth( nWidth );
743 pRep->SetWidthPercent( 100 );
744 pTblSet->Put( SwPtrItem( FN_TABLE_REP, pRep ));
747 SwAbstractDialogFactory* pFact = swui::GetFactory();
748 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
750 SfxAbstractTabDialog* pDlg = pFact->CreateSwTableTabDlg(pButton, rSh.GetAttrPool(), pTblSet, &rSh);
751 OSL_ENSURE(pDlg, "Dialogdiet fail!");
752 if( RET_OK == pDlg->Execute() )
753 pTblSet->Put( *pDlg->GetOutputItemSet() );
754 else if( bNewSet )
756 delete pTblSet, pTblSet = 0;
757 delete pRep, pRep = 0;
759 delete pDlg;
761 return 0;
764 IMPL_LINK( SwInsertDBColAutoPilot, AutoFmtHdl, PushButton*, pButton )
766 SwAbstractDialogFactory* pFact = swui::GetFactory();
767 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
769 AbstractSwAutoFormatDlg* pDlg = pFact->CreateSwAutoFormatDlg(pButton, pView->GetWrtShellPtr(), sal_False, pTAutoFmt);
770 OSL_ENSURE(pDlg, "Dialogdiet fail!");
771 if( RET_OK == pDlg->Execute())
772 pDlg->FillAutoFmtOfIndex( pTAutoFmt );
773 delete pDlg;
774 return 0;
777 IMPL_LINK( SwInsertDBColAutoPilot, SelectHdl, ListBox*, pBox )
779 ListBox* pGetBox = pBox == &aLbDbFmtFromUsr
780 ? ( aRbAsTable.IsChecked()
781 ? ( 0 == aLbTableCol.GetEntryData( 0 )
782 ? &aLbTblDbColumn
783 : &aLbTableCol )
784 : &aLbTxtDbColumn )
785 : pBox;
787 SwInsDBColumn aSrch( pGetBox->GetSelectEntry(), 0 );
788 SwInsDBColumns::const_iterator it = aDBColumns.find( &aSrch );
790 if( pBox == &aLbDbFmtFromUsr )
792 if( !aSrch.sColumn.isEmpty() )
794 aOldNumFmtLnk.Call( pBox );
795 (*it)->nUsrNumFmt = aLbDbFmtFromUsr.GetFormat();
798 else
800 // set the selected FieldName at the FormatGroupBox, so that
801 // it's clear what field is configured by the format!
802 String sTxt( aFlFormat.GetText().copy( 0, nGBFmtLen ));
803 if( aSrch.sColumn.isEmpty() )
805 aRbDbFmtFromDb.Enable( sal_False );
806 aRbDbFmtFromUsr.Enable( sal_False );
807 aLbDbFmtFromUsr.Enable( sal_False );
809 else
811 sal_Bool bEnableFmt = (*it)->bHasFmt;
812 aRbDbFmtFromDb.Enable( bEnableFmt );
813 aRbDbFmtFromUsr.Enable( bEnableFmt );
815 if( bEnableFmt )
817 (( sTxt += OUString(" (" )) += String(aSrch.sColumn) ) += (sal_Unicode)')';
820 sal_Bool bIsDBFmt = (*it)->bIsDBFmt;
821 aRbDbFmtFromDb.Check( bIsDBFmt );
822 aRbDbFmtFromUsr.Check( !bIsDBFmt );
823 aLbDbFmtFromUsr.Enable( !bIsDBFmt );
824 if( !bIsDBFmt )
825 aLbDbFmtFromUsr.SetDefFormat( (*it)->nUsrNumFmt );
828 aFlFormat.SetText( sTxt );
830 // to know later on, what ListBox was the "active", a Flag
831 // is remembered in the 1st entry
832 void* pPtr = pBox == &aLbTableCol ? &aLbTableCol : 0;
833 aLbTableCol.SetEntryData( 0, pPtr );
835 return 0;
838 IMPL_LINK( SwInsertDBColAutoPilot, HeaderHdl, Button*, pButton )
840 if( pButton == &aCbTableHeadon )
842 sal_Bool bEnable = aCbTableHeadon.IsChecked();
844 aRbHeadlColnms.Enable( bEnable );
845 aRbHeadlEmpty.Enable( bEnable );
847 return 0;
850 static void lcl_InsTextInArr( const String& rTxt, _DB_Columns& rColArr )
852 _DB_Column* pNew;
853 sal_uInt16 nSttPos = 0, nFndPos;
854 while( STRING_NOTFOUND != ( nFndPos = rTxt.Search( '\x0A', nSttPos )) )
856 if( 1 < nFndPos )
858 pNew = new _DB_Column( rTxt.Copy( nSttPos, nFndPos -1 ) );
859 rColArr.push_back( pNew );
861 pNew = new _DB_Column;
862 rColArr.push_back( pNew );
863 nSttPos = nFndPos + 1;
865 if( nSttPos < rTxt.Len() )
867 pNew = new _DB_Column( rTxt.Copy( nSttPos ) );
868 rColArr.push_back( pNew );
872 bool SwInsertDBColAutoPilot::SplitTextToColArr( const String& rTxt,
873 _DB_Columns& rColArr,
874 sal_Bool bInsField )
876 // create each of the database columns from the text again
877 // and then save in an array
878 // database columns are in <> and must be present in the columns' array:
879 String sTxt( rTxt );
880 sal_uInt16 nFndPos, nEndPos, nSttPos = 0;
882 while( STRING_NOTFOUND != ( nFndPos = sTxt.Search( cDBFldStart, nSttPos )))
884 nSttPos = nFndPos + 1;
885 if( STRING_NOTFOUND != ( nEndPos = sTxt.Search( cDBFldEnd, nSttPos+1 )))
887 // Text in <> brackets found: what is it:
888 SwInsDBColumn aSrch( sTxt.Copy( nSttPos, nEndPos - nSttPos ), 0);
889 SwInsDBColumns::const_iterator it = aDBColumns.find( &aSrch );
890 if( it != aDBColumns.end() )
892 // that is a valid field
893 // so surely the text "before":
894 const SwInsDBColumn& rFndCol = **it;
896 _DB_Column* pNew;
898 if( 1 < nSttPos )
900 ::lcl_InsTextInArr( sTxt.Copy( 0, nSttPos-1 ), rColArr );
901 sTxt.Erase( 0, nSttPos-1 );
904 sTxt.Erase( 0, (xub_StrLen)(rFndCol.sColumn.getLength() + 2) );
905 nSttPos = 0;
907 sal_uInt16 nSubType = 0;
908 sal_uLong nFormat;
909 if( rFndCol.bHasFmt )
911 if( rFndCol.bIsDBFmt )
912 nFormat = rFndCol.nDBNumFmt;
913 else
915 nFormat = rFndCol.nUsrNumFmt;
916 nSubType = nsSwExtendedSubType::SUB_OWN_FMT;
919 else
920 nFormat = 0;
922 if( bInsField )
924 SwWrtShell& rSh = pView->GetWrtShell();
925 SwDBFieldType aFldType( rSh.GetDoc(), aSrch.sColumn,
926 aDBData );
927 pNew = new _DB_Column( rFndCol, *new SwDBField(
928 (SwDBFieldType*)rSh.InsertFldType( aFldType ),
929 nFormat ) );
930 if( nSubType )
931 pNew->DB_ColumnData.pField->SetSubType( nSubType );
933 else
934 pNew = new _DB_Column( rFndCol, nFormat );
936 rColArr.push_back( pNew );
941 // don't forget the last text
942 if( sTxt.Len() )
943 ::lcl_InsTextInArr( sTxt, rColArr );
945 return !rColArr.empty();
948 void SwInsertDBColAutoPilot::DataToDoc( const Sequence<Any>& rSelection,
949 Reference< XDataSource> xSource,
950 Reference< XConnection> xConnection,
951 Reference< sdbc::XResultSet > xResultSet )
953 const Any* pSelection = rSelection.getLength() ? rSelection.getConstArray() : 0;
954 SwWrtShell& rSh = pView->GetWrtShell();
956 //with the drag and drop interface no result set is initially available
957 sal_Bool bDisposeResultSet = sal_False;
958 // we don't have a cursor, so we have to create our own RowSet
959 if ( !xResultSet.is() )
961 xResultSet = SwNewDBMgr::createCursor(aDBData.sDataSource,aDBData.sCommand,aDBData.nCommandType,xConnection);
962 bDisposeResultSet = xResultSet.is();
965 Reference< sdbc::XRow > xRow(xResultSet, UNO_QUERY);
966 if ( !xRow.is() )
967 return;
969 rSh.StartAllAction();
970 sal_Bool bUndo = rSh.DoesUndo();
971 if( bUndo )
972 rSh.StartUndo( UNDO_EMPTY );
974 sal_Bool bAsTable = aRbAsTable.IsChecked();
975 SvNumberFormatter& rNumFmtr = *rSh.GetNumberFormatter();
977 if( rSh.HasSelection() )
978 rSh.DelRight();
980 ::std::auto_ptr<SwWait> pWait;
982 Reference< XColumnsSupplier > xColsSupp( xResultSet, UNO_QUERY );
983 Reference <XNameAccess> xCols = xColsSupp->getColumns();
985 do{ // middle checked loop!!
986 if( bAsTable ) // Daten als Tabelle einfuegen
988 rSh.DoUndo( sal_False );
990 sal_uInt16 n, nRows = 0, nCols = aLbTableCol.GetEntryCount();
991 if( aCbTableHeadon.IsChecked() )
992 nRows++;
994 if( pSelection )
995 nRows = nRows + (sal_uInt16)rSelection.getLength();
996 else
997 ++nRows;
999 // prepare the array for the selected columns
1000 std::vector<SwInsDBColumn*> aColFlds;
1001 for( n = 0; n < nCols; ++n )
1003 SwInsDBColumn aSrch( aLbTableCol.GetEntry( n ), 0 );
1004 SwInsDBColumns::const_iterator it = aDBColumns.find( &aSrch );
1005 if (it != aDBColumns.end())
1006 aColFlds.push_back(*it);
1007 else {
1008 OSL_ENSURE( !this, "database column not found" );
1012 if( nCols != aColFlds.size() )
1014 OSL_ENSURE( !this, "not all database columns found" );
1015 nCols = aColFlds.size();
1018 if(!nRows || !nCols)
1020 OSL_ENSURE( !this, "wrong parameters" );
1021 break;
1024 const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
1026 sal_Bool bHTML = 0 != (::GetHtmlMode( pView->GetDocShell() ) & HTMLMODE_ON);
1027 rSh.InsertTable(
1028 pModOpt->GetInsTblFlags(bHTML),
1029 nRows, nCols, text::HoriOrientation::FULL, (pSelection ? pTAutoFmt : 0) );
1030 rSh.MoveTable( GetfnTablePrev(), GetfnTableStart() );
1032 if( pSelection && pTblSet )
1033 SetTabSet();
1035 SfxItemSet aTblSet( rSh.GetAttrPool(), RES_BOXATR_FORMAT,
1036 RES_BOXATR_VALUE );
1037 sal_Bool bIsAutoUpdateCells = rSh.IsAutoUpdateCells();
1038 rSh.SetAutoUpdateCells( sal_False );
1041 if( aCbTableHeadon.IsChecked() )
1043 for( n = 0; n < nCols; ++n )
1045 if( aRbHeadlColnms.IsChecked() )
1047 rSh.SwEditShell::Insert2( aColFlds[ n ]->sColumn );
1049 rSh.GoNextCell();
1052 else
1053 rSh.SetRowsToRepeat( 0 );
1055 for( sal_Int32 i = 0 ; ; ++i )
1057 bool bBreak = false;
1060 if(pSelection)
1062 sal_Int32 nPos = 0;
1063 pSelection[i] >>= nPos;
1064 bBreak = !xResultSet->absolute(nPos);
1066 else if(!i)
1067 bBreak = !xResultSet->first();
1069 catch (const Exception&)
1071 bBreak = true;
1073 if(bBreak)
1074 break;
1076 for( n = 0; n < nCols; ++n )
1078 // at the very first time, NO GoNextCell, because we're
1079 // already in it. Also no GoNextCell after the Insert,
1080 // because an empty line is added at the end.
1081 if( i || n )
1082 rSh.GoNextCell();
1084 const SwInsDBColumn* pEntry = aColFlds[ n ];
1086 Reference< XColumn > xColumn;
1087 xCols->getByName(pEntry->sColumn) >>= xColumn;
1088 Reference< XPropertySet > xColumnProps( xColumn, UNO_QUERY );
1089 sal_Int32 eDataType = 0;
1090 if( xColumnProps.is() )
1092 Any aType = xColumnProps->getPropertyValue("Type");
1093 aType >>= eDataType;
1097 if( pEntry->bHasFmt )
1099 SwTblBoxNumFormat aNumFmt(
1100 pEntry->bIsDBFmt ? pEntry->nDBNumFmt
1101 : pEntry->nUsrNumFmt );
1102 aTblSet.Put(aNumFmt);
1103 if( xColumn.is() )
1105 double fVal = xColumn->getDouble();
1106 if( xColumn->wasNull() )
1107 aTblSet.ClearItem( RES_BOXATR_VALUE );
1108 else
1110 if(rNumFmtr.GetType(aNumFmt.GetValue()) & NUMBERFORMAT_DATE)
1112 ::Date aStandard(1,1,1900);
1113 if (*rNumFmtr.GetNullDate() != aStandard)
1114 fVal += (aStandard - *rNumFmtr.GetNullDate());
1116 aTblSet.Put( SwTblBoxValue( fVal ));
1119 else
1120 aTblSet.ClearItem( RES_BOXATR_VALUE );
1121 rSh.SetTblBoxFormulaAttrs( aTblSet );
1123 //#i60207# don't insert binary data as string - creates a loop
1124 else if( DataType::BINARY == eDataType ||
1125 DataType::VARBINARY == eDataType ||
1126 DataType::LONGVARBINARY== eDataType ||
1127 DataType::SQLNULL == eDataType ||
1128 DataType::OTHER == eDataType ||
1129 DataType::OBJECT == eDataType ||
1130 DataType::DISTINCT == eDataType ||
1131 DataType::STRUCT == eDataType ||
1132 DataType::ARRAY == eDataType ||
1133 DataType::BLOB == eDataType ||
1134 DataType::CLOB == eDataType ||
1135 DataType::REF == eDataType
1138 // do nothing
1140 else
1142 OUString sVal = xColumn->getString();
1143 if(!xColumn->wasNull())
1145 rSh.SwEditShell::Insert2( sVal );
1149 catch (const Exception& rExcept)
1151 OSL_FAIL(OUStringToOString(rExcept.Message, osl_getThreadTextEncoding()).getStr());
1152 (void)rExcept;
1156 if( !pSelection )
1158 if ( !xResultSet->next() )
1159 break;
1161 else if( i+1 >= rSelection.getLength() )
1162 break;
1164 if( 10 == i )
1165 pWait = ::std::auto_ptr<SwWait>(new SwWait( *pView->GetDocShell(), sal_True ));
1168 rSh.MoveTable( GetfnTableCurr(), GetfnTableStart() );
1169 if( !pSelection && ( pTblSet || pTAutoFmt ))
1171 if( pTblSet )
1172 SetTabSet();
1174 if( pTAutoFmt )
1175 rSh.SetTableAutoFmt( *pTAutoFmt );
1177 rSh.SetAutoUpdateCells( bIsAutoUpdateCells );
1179 else // add data as fields/text
1181 _DB_Columns aColArr;
1182 if( SplitTextToColArr( aEdDbText.GetText(), aColArr, aRbAsField.IsChecked() ) )
1184 // now for each data set, we can iterate over the array
1185 // and add the data
1187 if( !rSh.IsSttPara() )
1188 rSh.SwEditShell::SplitNode();
1189 if( !rSh.IsEndPara() )
1191 rSh.SwEditShell::SplitNode();
1192 rSh.SwCrsrShell::Left(1,CRSR_SKIP_CHARS);
1195 rSh.DoUndo( sal_False );
1197 SwTxtFmtColl* pColl = 0;
1199 String sTmplNm( aLbDbParaColl.GetSelectEntry() );
1200 if( sNoTmpl != sTmplNm )
1202 pColl = rSh.FindTxtFmtCollByName( sTmplNm );
1203 if( !pColl )
1205 sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( sTmplNm, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
1206 if( USHRT_MAX != nId )
1207 pColl = rSh.GetTxtCollFromPool( nId );
1208 else
1209 pColl = rSh.MakeTxtFmtColl( sTmplNm );
1211 rSh.SetTxtFmtColl( pColl );
1215 // for adding as fields -> insert a "NextField" after
1216 // every data set
1217 SwDBFormatData aDBFormatData;
1218 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
1219 aDBFormatData.xFormatter = Reference<util::XNumberFormatter>(util::NumberFormatter::create(xContext), UNO_QUERY_THROW) ;
1221 Reference<XPropertySet> xSourceProps(xSource, UNO_QUERY);
1222 if(xSourceProps.is())
1224 Any aFormats = xSourceProps->getPropertyValue("NumberFormatsSupplier");
1225 if(aFormats.hasValue())
1227 Reference< util::XNumberFormatsSupplier> xSuppl;
1228 aFormats >>= xSuppl;
1229 if(xSuppl.is())
1231 Reference< XPropertySet > xSettings = xSuppl->getNumberFormatSettings();
1232 Any aNull = xSettings->getPropertyValue("NullDate");
1233 aNull >>= aDBFormatData.aNullDate;
1234 if(aDBFormatData.xFormatter.is())
1235 aDBFormatData.xFormatter->attachNumberFormatsSupplier(xSuppl);
1239 aDBFormatData.aLocale = LanguageTag( rSh.GetCurLang() ).getLocale();
1240 SwDBNextSetField aNxtDBFld( (SwDBNextSetFieldType*)rSh.
1241 GetFldType( 0, RES_DBNEXTSETFLD ),
1242 OUString("1"), aEmptyStr, aDBData );
1245 bool bSetCrsr = true;
1246 sal_uInt16 n = 0, nCols = aColArr.size();
1247 ::sw::mark::IMark* pMark = NULL;
1248 for( sal_Int32 i = 0 ; ; ++i )
1250 bool bBreak = false;
1253 if(pSelection)
1255 sal_Int32 nPos = 0;
1256 pSelection[i] >>= nPos;
1257 bBreak = !xResultSet->absolute(nPos);
1259 else if(!i)
1260 bBreak = !xResultSet->first();
1262 catch (const Exception&)
1264 bBreak = true;
1267 if(bBreak)
1268 break;
1271 for( n = 0; n < nCols; ++n )
1273 _DB_Column* pDBCol = &aColArr[ n ];
1274 String sIns;
1275 switch( pDBCol->eColType )
1277 case _DB_Column::DB_FILLTEXT:
1278 sIns = *pDBCol->DB_ColumnData.pText;
1279 break;
1281 case _DB_Column::DB_SPLITPARA:
1282 rSh.SplitNode();
1283 // when the template is not the same as the follow template,
1284 // the selected has to be set newly
1285 if( pColl && &pColl->GetNextTxtFmtColl() != pColl )
1286 rSh.SetTxtFmtColl( pColl );
1287 break;
1289 case _DB_Column::DB_COL_FIELD:
1291 SwDBField *const pFld = static_cast<SwDBField *>(
1292 pDBCol->DB_ColumnData.pField->CopyField());
1293 double nValue = DBL_MAX;
1295 Reference< XPropertySet > xColumnProps;
1296 xCols->getByName(pDBCol->pColInfo->sColumn) >>= xColumnProps;
1298 pFld->SetExpansion( SwNewDBMgr::GetDBField(
1299 xColumnProps,
1300 aDBFormatData,
1301 &nValue ) );
1302 if( DBL_MAX != nValue )
1304 Any aType = xColumnProps->getPropertyValue("Type");
1305 sal_Int32 eDataType = 0;
1306 aType >>= eDataType;
1307 if( DataType::DATE == eDataType || DataType::TIME == eDataType ||
1308 DataType::TIMESTAMP == eDataType)
1311 ::Date aStandard(1,1,1900);
1312 ::Date aCompare(aDBFormatData.aNullDate.Day ,
1313 aDBFormatData.aNullDate.Month,
1314 aDBFormatData.aNullDate.Year);
1315 if(aStandard != aCompare)
1316 nValue += (aStandard - aCompare);
1318 pFld->ChgValue( nValue, sal_True );
1320 pFld->SetInitialized();
1322 rSh.Insert( *pFld );
1323 delete pFld;
1325 break;
1327 case _DB_Column::DB_COL_TEXT:
1329 double nValue = DBL_MAX;
1330 Reference< XPropertySet > xColumnProps;
1331 xCols->getByName(pDBCol->pColInfo->sColumn) >>= xColumnProps;
1332 sIns = SwNewDBMgr::GetDBField(
1333 xColumnProps,
1334 aDBFormatData,
1335 &nValue );
1336 if( pDBCol->DB_ColumnData.nFormat &&
1337 DBL_MAX != nValue )
1339 Color* pCol;
1340 if(rNumFmtr.GetType(pDBCol->DB_ColumnData.nFormat) & NUMBERFORMAT_DATE)
1342 ::Date aStandard(1,1,1900);
1343 if (*rNumFmtr.GetNullDate() != aStandard)
1344 nValue += (aStandard - *rNumFmtr.GetNullDate());
1346 rNumFmtr.GetOutputString( nValue,
1347 pDBCol->DB_ColumnData.nFormat,
1348 sIns, &pCol );
1351 break;
1354 if( sIns.Len() )
1355 rSh.Insert( sIns );
1357 if( bSetCrsr && sIns.Len() )
1359 // to the beginning and set a mark, so that
1360 // the cursor can be set to the initial position
1361 // at the end.
1363 rSh.SwCrsrShell::MovePara(
1364 GetfnParaCurr(), GetfnParaStart() );
1365 pMark = rSh.SetBookmark(
1366 KeyCode(),
1367 OUString(),
1368 OUString(), IDocumentMarkAccess::UNO_BOOKMARK );
1369 rSh.SwCrsrShell::MovePara(
1370 GetfnParaCurr(), GetfnParaEnd() );
1371 bSetCrsr = false;
1375 if( !pSelection )
1377 sal_Bool bNext = xResultSet->next();
1378 if(!bNext)
1379 break;
1381 else if( i+1 >= rSelection.getLength() )
1382 break;
1384 if( aRbAsField.IsChecked() )
1385 rSh.Insert( aNxtDBFld );
1387 if( !rSh.IsSttPara() )
1388 rSh.SwEditShell::SplitNode();
1390 if( 10 == i )
1391 pWait = ::std::auto_ptr<SwWait>(new SwWait( *pView->GetDocShell(), sal_True ));
1394 if( !bSetCrsr && pMark != NULL)
1396 rSh.SetMark();
1397 rSh.GotoMark( pMark );
1398 rSh.getIDocumentMarkAccess()->deleteMark( pMark );
1399 break;
1403 // write configuration
1404 Commit();
1405 }while( false ); // middle checked loop
1407 if( bUndo )
1409 rSh.DoUndo( sal_True );
1410 rSh.AppendUndoForInsertFromDB( bAsTable );
1411 rSh.EndUndo( UNDO_EMPTY );
1413 rSh.ClearMark();
1414 rSh.EndAllAction();
1416 if ( bDisposeResultSet )
1417 ::comphelper::disposeComponent(xResultSet);
1420 void SwInsertDBColAutoPilot::SetTabSet()
1422 SwWrtShell& rSh = pView->GetWrtShell();
1423 const SfxPoolItem* pItem;
1425 if( pTAutoFmt )
1427 if( pTAutoFmt->IsFrame() )
1429 // border is from AutoFormat
1430 pTblSet->ClearItem( RES_BOX );
1431 pTblSet->ClearItem( SID_ATTR_BORDER_INNER );
1433 if( pTAutoFmt->IsBackground() )
1435 pTblSet->ClearItem( RES_BACKGROUND );
1436 pTblSet->ClearItem( SID_ATTR_BRUSH_ROW );
1437 pTblSet->ClearItem( SID_ATTR_BRUSH_TABLE );
1440 else
1442 // remove the defaults again, it makes no sense to set them
1443 SvxBrushItem aBrush( RES_BACKGROUND );
1444 static sal_uInt16 aIds[3] =
1445 { RES_BACKGROUND, SID_ATTR_BRUSH_ROW, SID_ATTR_BRUSH_TABLE };
1446 for( int i = 0; i < 3; ++i )
1447 if( SFX_ITEM_SET == pTblSet->GetItemState( aIds[ i ],
1448 sal_False, &pItem ) && *pItem == aBrush )
1449 pTblSet->ClearItem( aIds[ i ] );
1452 if( SFX_ITEM_SET == pTblSet->GetItemState( FN_PARAM_TABLE_NAME, sal_False,
1453 &pItem ) && ((const SfxStringItem*)pItem)->GetValue() ==
1454 rSh.GetTableFmt()->GetName() )
1455 pTblSet->ClearItem( FN_PARAM_TABLE_NAME );
1457 rSh.MoveTable( GetfnTableCurr(), GetfnTableStart() );
1458 rSh.SetMark();
1459 rSh.MoveTable( GetfnTableCurr(), GetfnTableEnd() );
1461 ItemSetToTableParam( *pTblSet, rSh );
1463 rSh.ClearMark();
1464 rSh.MoveTable( GetfnTableCurr(), GetfnTableStart() );
1467 _DB_ColumnConfigData::~_DB_ColumnConfigData() {}
1469 static Sequence<OUString> lcl_createSourceNames(const String& rNodeName)
1471 Sequence<OUString> aSourceNames(11);
1472 OUString* pNames = aSourceNames.getArray();
1474 String sTmp( rNodeName );
1475 const xub_StrLen nPos = sTmp.Len();
1476 pNames[0] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1477 RTL_CONSTASCII_STRINGPARAM( "/DataSource" ));
1478 pNames[1] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1479 RTL_CONSTASCII_STRINGPARAM( "/Command" ));
1480 pNames[2] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1481 RTL_CONSTASCII_STRINGPARAM( "/CommandType" ));
1482 pNames[3] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1483 RTL_CONSTASCII_STRINGPARAM( "/ColumnsToText" ));
1484 pNames[4] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1485 RTL_CONSTASCII_STRINGPARAM( "/ColumnsToTable" ));
1486 pNames[5] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1487 RTL_CONSTASCII_STRINGPARAM( "/ParaStyle" ));
1488 pNames[6] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1489 RTL_CONSTASCII_STRINGPARAM( "/TableAutoFormat" ));
1490 pNames[7] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1491 RTL_CONSTASCII_STRINGPARAM( "/IsTable" ));
1492 pNames[8] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1493 RTL_CONSTASCII_STRINGPARAM( "/IsField" ));
1494 pNames[9] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1495 RTL_CONSTASCII_STRINGPARAM( "/IsHeadlineOn" ));
1496 pNames[10] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1497 RTL_CONSTASCII_STRINGPARAM( "/IsEmptyHeadline" ));
1498 return aSourceNames;
1501 static Sequence<OUString> lcl_CreateSubNames( const String& rSubNodeName )
1503 Sequence<OUString> aSubSourceNames(6);
1504 OUString* pNames = aSubSourceNames.getArray();
1505 String sTmp( rSubNodeName );
1506 const xub_StrLen nPos = sTmp.Len();
1507 pNames[0] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1508 RTL_CONSTASCII_STRINGPARAM( "/ColumnName" ));
1509 pNames[1] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1510 RTL_CONSTASCII_STRINGPARAM( "/ColumnIndex" ));
1511 pNames[2] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1512 RTL_CONSTASCII_STRINGPARAM( "/IsNumberFormat" ));
1513 pNames[3] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1514 RTL_CONSTASCII_STRINGPARAM( "/IsNumberFormatFromDataBase" ));
1515 pNames[4] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1516 RTL_CONSTASCII_STRINGPARAM( "/NumberFormat" ));
1517 pNames[5] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1518 RTL_CONSTASCII_STRINGPARAM( "/NumberFormatLocale" ));
1519 return aSubSourceNames;
1522 static OUString lcl_CreateUniqueName(const Sequence<OUString>& aNames)
1524 sal_Int32 nIdx = aNames.getLength();
1525 const OUString* pNames = aNames.getConstArray();
1526 OUString sTest("_");
1527 OUString sRet;
1528 while(true)
1530 sRet = sTest; sRet += OUString::valueOf(nIdx++);
1531 bool bFound = false;
1532 for(sal_Int32 i = 0; i < aNames.getLength(); i++)
1534 if(pNames[i] == sRet)
1536 bFound = true;
1537 break;
1540 if(!bFound)
1541 break;
1543 return sRet;
1546 void SwInsertDBColAutoPilot::Notify( const ::com::sun::star::uno::Sequence< OUString >& ) {}
1548 void SwInsertDBColAutoPilot::Commit()
1550 Sequence <OUString> aNames = GetNodeNames(OUString());
1551 const OUString* pNames = aNames.getArray();
1552 //remove entries that contain this data source + table at first
1553 for(sal_Int32 nNode = 0; nNode < aNames.getLength(); nNode++)
1555 Sequence<OUString> aSourceNames(2);
1556 OUString* pSourceNames = aSourceNames.getArray();
1557 pSourceNames[0] = pNames[nNode];
1558 pSourceNames[0] += "/DataSource";
1559 pSourceNames[1] = pNames[nNode];
1560 pSourceNames[1] += "/Command";
1561 Sequence<Any> aSourceProperties = GetProperties(aSourceNames);
1562 const Any* pSourceProps = aSourceProperties.getArray();
1563 OUString sSource, sCommand;
1564 pSourceProps[0] >>= sSource;
1565 pSourceProps[1] >>= sCommand;
1566 if(sSource.equals(aDBData.sDataSource) && sCommand.equals(aDBData.sCommand))
1568 Sequence<OUString> aElements(1);
1569 aElements.getArray()[0] = pNames[nNode];
1570 ClearNodeElements(OUString(), aElements);
1574 aNames = GetNodeNames(OUString());
1575 OUString sNewNode = lcl_CreateUniqueName(aNames);
1576 Sequence<OUString> aNodeNames = lcl_createSourceNames(sNewNode);
1577 Sequence<PropertyValue> aValues(aNodeNames.getLength());
1578 PropertyValue* pValues = aValues.getArray();
1579 const OUString* pNodeNames = aNodeNames.getConstArray();
1580 OUString sSlash("/");
1581 for(sal_Int32 i = 0; i < aNodeNames.getLength(); i++)
1583 pValues[i].Name = sSlash;
1584 pValues[i].Name += pNodeNames[i];
1587 pValues[0].Value <<= OUString(aDBData.sDataSource);
1588 pValues[1].Value <<= OUString(aDBData.sCommand);
1589 pValues[2].Value <<= aDBData.nCommandType;
1590 pValues[3].Value <<= OUString(aEdDbText.GetText());
1592 String sTmp;
1593 for( sal_uInt16 n = 0, nCnt = aLbTableCol.GetEntryCount(); n < nCnt; ++n )
1594 ( sTmp += aLbTableCol.GetEntry( n ) ) += '\x0a';
1596 if( sTmp.Len() )
1597 pValues[4].Value <<= OUString(sTmp);
1599 if( sNoTmpl != (sTmp = aLbDbParaColl.GetSelectEntry()) )
1600 pValues[5].Value <<= OUString(sTmp);
1602 if( pTAutoFmt )
1603 pValues[6].Value <<= OUString(pTAutoFmt->GetName());
1605 const Type& rBoolType = ::getBooleanCppuType();
1606 sal_Bool bTmp = aRbAsTable.IsChecked();
1607 pValues[7].Value.setValue(&bTmp, rBoolType);
1609 bTmp = aRbAsField.IsChecked();
1610 pValues[8].Value.setValue(&bTmp, rBoolType);
1612 bTmp = aCbTableHeadon.IsChecked();
1613 pValues[9].Value.setValue(&bTmp, rBoolType);
1615 bTmp = aRbHeadlEmpty.IsChecked();
1616 pValues[10].Value.setValue(&bTmp, rBoolType);
1618 SetSetProperties(OUString(), aValues);
1620 sNewNode += "/ColumnSet";
1621 OUString sDelim("/__");
1623 LanguageType ePrevLang = (LanguageType)-1;
1624 OUString sPrevLang;
1626 SvNumberFormatter& rNFmtr = *pView->GetWrtShell().GetNumberFormatter();
1627 for(sal_uInt16 nCol = 0; nCol < aDBColumns.size(); nCol++)
1629 OUString sColumnNode = sNewNode;
1630 SwInsDBColumn* pColumn = aDBColumns[nCol];
1631 String sColumnInsertNode(sColumnNode);
1632 sColumnInsertNode += sDelim;
1633 if( nCol < 100 )
1634 sColumnInsertNode += '0';
1635 if( nCol < 10 )
1636 sColumnInsertNode += '0';
1637 sColumnInsertNode += OUString::number( nCol );
1639 Sequence <OUString> aSubNodeNames = lcl_CreateSubNames(sColumnInsertNode);
1640 Sequence<PropertyValue> aSubValues(aSubNodeNames.getLength());
1641 PropertyValue* pSubValues = aSubValues.getArray();
1642 const OUString* pSubNodeNames = aSubNodeNames.getConstArray();
1643 sal_Int32 i;
1645 for( i = 0; i < aSubNodeNames.getLength(); i++)
1646 pSubValues[i].Name = pSubNodeNames[i];
1647 pSubValues[0].Value <<= pColumn->sColumn;
1648 pSubValues[1].Value <<= i;
1650 sal_Bool bVal = pColumn->bHasFmt;
1651 pSubValues[2].Value.setValue(&bVal, rBoolType);
1652 bVal = pColumn->bIsDBFmt;
1653 pSubValues[3].Value.setValue(&bVal, rBoolType);
1655 SwStyleNameMapper::FillUIName( RES_POOLCOLL_STANDARD, sTmp );
1656 const SvNumberformat* pNF = rNFmtr.GetEntry( pColumn->nUsrNumFmt );
1657 LanguageType eLang;
1658 if( pNF )
1660 pSubValues[4].Value <<= OUString(pNF->GetFormatstring());
1661 eLang = pNF->GetLanguage();
1663 else
1665 pSubValues[4].Value <<= OUString(sTmp);
1666 eLang = GetAppLanguage();
1669 if( eLang != ePrevLang )
1671 /* FIXME-BCP47: handle language tags! */
1672 lang::Locale aLocale( LanguageTag( eLang ).getLocale());
1673 /* umm.. what's this string anyway, "Country-Language" instead of
1674 * "Language-Country" ??? */
1675 (( sPrevLang = aLocale.Country ) += OUString( '-' )) += aLocale.Language;
1676 ePrevLang = eLang;
1679 pSubValues[5].Value <<= sPrevLang;
1680 SetSetProperties(sColumnNode, aSubValues);
1684 void SwInsertDBColAutoPilot::Load()
1686 Sequence <OUString> aNames = GetNodeNames(OUString());
1687 const OUString* pNames = aNames.getArray();
1688 SvNumberFormatter& rNFmtr = *pView->GetWrtShell().GetNumberFormatter();
1689 for(sal_Int32 nNode = 0; nNode < aNames.getLength(); nNode++)
1691 //search for entries with the appropriate data source and table
1692 Sequence<OUString> aSourceNames = lcl_createSourceNames(pNames[nNode]);
1694 Sequence< Any> aDataSourceProps = GetProperties(aSourceNames);
1695 const Any* pDataSourceProps = aDataSourceProps.getConstArray();
1696 OUString sSource, sCommand;
1697 sal_Int16 nCommandType;
1698 pDataSourceProps[0] >>= sSource;
1699 pDataSourceProps[1] >>= sCommand;
1700 pDataSourceProps[2] >>= nCommandType;
1701 if(sSource.equals(aDBData.sDataSource) && sCommand.equals(aDBData.sCommand))
1703 _DB_ColumnConfigData* pNewData = new _DB_ColumnConfigData;
1704 pNewData->sSource = sSource;
1705 pNewData->sTable = sCommand;
1707 pDataSourceProps[3] >>= pNewData->sEdit;
1708 pDataSourceProps[4] >>= pNewData->sTblList;
1709 pDataSourceProps[5] >>= pNewData->sTmplNm;
1710 pDataSourceProps[6] >>= pNewData->sTAutoFmtNm;
1711 if(pDataSourceProps[7].hasValue())
1712 pNewData->bIsTable = *(sal_Bool*)pDataSourceProps[7].getValue();
1713 if(pDataSourceProps[8].hasValue())
1714 pNewData->bIsField = *(sal_Bool*)pDataSourceProps[8].getValue();
1715 if(pDataSourceProps[9].hasValue())
1716 pNewData->bIsHeadlineOn = *(sal_Bool*)pDataSourceProps[9].getValue();
1717 if(pDataSourceProps[10].hasValue())
1718 pNewData->bIsEmptyHeadln = *(sal_Bool*)pDataSourceProps[10].getValue();
1720 OUString sSubNodeName(pNames[nNode]);
1721 sSubNodeName += "/ColumnSet/";
1722 Sequence <OUString> aSubNames = GetNodeNames(sSubNodeName);
1723 const OUString* pSubNames = aSubNames.getConstArray();
1724 for(sal_Int32 nSub = 0; nSub < aSubNames.getLength(); nSub++)
1726 OUString sSubSubNodeName(sSubNodeName);
1727 sSubSubNodeName += pSubNames[nSub];
1728 Sequence <OUString> aSubNodeNames = lcl_CreateSubNames(sSubSubNodeName);
1729 Sequence< Any> aSubProps = GetProperties(aSubNodeNames);
1730 const Any* pSubProps = aSubProps.getConstArray();
1732 OUString sColumn;
1733 pSubProps[0] >>= sColumn;
1734 //check for existance of the loaded column name
1735 bool bFound = false;
1736 for(sal_uInt16 nRealColumn = 0; nRealColumn < aDBColumns.size(); nRealColumn++)
1738 if(aDBColumns[nRealColumn]->sColumn == sColumn)
1740 bFound = true;
1741 break;
1744 if(!bFound)
1745 continue;
1746 sal_Int16 nIndex = 0;
1747 pSubProps[1] >>= nIndex;
1748 SwInsDBColumn* pInsDBColumn = new SwInsDBColumn(sColumn, nIndex);
1749 if(pSubProps[2].hasValue())
1750 pInsDBColumn->bHasFmt = *(sal_Bool*)pSubProps[2].getValue();
1751 if(pSubProps[3].hasValue())
1752 pInsDBColumn->bIsDBFmt = *(sal_Bool*)pSubProps[3].getValue();
1754 pSubProps[4] >>= pInsDBColumn->sUsrNumFmt;
1755 OUString sNumberFormatLocale;
1756 pSubProps[5] >>= sNumberFormatLocale;
1758 /* FIXME-BCP47: handle language tags, and cope with the wrong
1759 * Country-Language string that
1760 * SwInsertDBColAutoPilot::Commit() writes so far! */
1761 lang::Locale aLocale;
1762 aLocale.Language = sNumberFormatLocale.copy(0, 2);
1763 aLocale.Country = sNumberFormatLocale.copy(3, 2);
1764 pInsDBColumn->eUsrNumFmtLng = LanguageTag( aLocale ).getLanguageType();
1766 pInsDBColumn->nUsrNumFmt = rNFmtr.GetEntryKey( pInsDBColumn->sUsrNumFmt,
1767 pInsDBColumn->eUsrNumFmtLng );
1770 pNewData->aDBColumns.insert(pInsDBColumn);
1772 sal_Int32 n = 0;
1773 String sTmp( pNewData->sTblList );
1774 if( sTmp.Len() )
1776 do {
1777 String sEntry( sTmp.GetToken( 0, '\x0a', n ) );
1778 //preselect column - if they still exist!
1779 if(aLbTblDbColumn.GetEntryPos(sEntry) != LISTBOX_ENTRY_NOTFOUND)
1781 aLbTableCol.InsertEntry( sEntry );
1782 aLbTblDbColumn.RemoveEntry( sEntry );
1784 } while( n < sTmp.Len() );
1786 if( !aLbTblDbColumn.GetEntryCount() )
1788 aIbDbcolAllTo.Enable( sal_False );
1789 aIbDbcolOneTo.Enable( sal_False );
1791 aIbDbcolOneFrom.Enable( sal_True );
1792 aIbDbcolAllFrom.Enable( sal_True );
1794 aEdDbText.SetText( pNewData->sEdit );
1796 sTmp = pNewData->sTmplNm;
1797 if( sTmp.Len() )
1798 aLbDbParaColl.SelectEntry( sTmp );
1799 else
1800 aLbDbParaColl.SelectEntryPos( 0 );
1802 delete pTAutoFmt, pTAutoFmt = 0;
1803 sTmp = pNewData->sTAutoFmtNm;
1804 if( sTmp.Len() )
1806 // then load the AutoFmt file and look for Autoformat first
1807 SwTableAutoFmtTbl aAutoFmtTbl;
1808 aAutoFmtTbl.Load();
1809 for( sal_uInt16 nAutoFmt = aAutoFmtTbl.size(); nAutoFmt; )
1810 if( sTmp == aAutoFmtTbl[ --nAutoFmt ].GetName() )
1812 pTAutoFmt = new SwTableAutoFmt( aAutoFmtTbl[ nAutoFmt ] );
1813 break;
1817 aRbAsTable.Check( pNewData->bIsTable );
1818 aRbAsField.Check( pNewData->bIsField );
1819 aRbAsText.Check( !pNewData->bIsTable && !pNewData->bIsField );
1821 aCbTableHeadon.Check( pNewData->bIsHeadlineOn );
1822 aRbHeadlColnms.Check( !pNewData->bIsEmptyHeadln );
1823 aRbHeadlEmpty.Check( pNewData->bIsEmptyHeadln );
1824 HeaderHdl(&aCbTableHeadon);
1826 // now copy the user defined Numberformat strings to the
1827 // Shell. Then only these are available as ID
1828 for( n = 0; n < (sal_Int32) aDBColumns.size() ; ++n )
1830 SwInsDBColumn& rSet = *aDBColumns[ n ];
1831 for( sal_uInt16 m = 0; m < pNewData->aDBColumns.size() ; ++m )
1833 SwInsDBColumn& rGet = *pNewData->aDBColumns[ m ];
1834 if(rGet.sColumn == rSet.sColumn)
1836 if( rGet.bHasFmt && !rGet.bIsDBFmt )
1838 rSet.bIsDBFmt = sal_False;
1839 rSet.nUsrNumFmt = rNFmtr.GetEntryKey( rGet.sUsrNumFmt,
1840 rGet.eUsrNumFmtLng );
1841 if( NUMBERFORMAT_ENTRY_NOT_FOUND == rSet.nUsrNumFmt )
1843 sal_Int32 nCheckPos;
1844 short nType;
1845 rNFmtr.PutEntry( rGet.sUsrNumFmt, nCheckPos, nType,
1846 rSet.nUsrNumFmt, rGet.eUsrNumFmtLng );
1849 break;
1854 // when the cursor is inside of a table, table must NEVER be selectable
1855 if( !aRbAsTable.IsEnabled() && aRbAsTable.IsChecked() )
1856 aRbAsField.Check( sal_True );
1857 delete pNewData;
1858 break;
1863 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */