Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "dbinsdlg.hxx"
21 :
22 : #include <memory>
23 :
24 : #include <float.h>
25 :
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 <svx/htmlmode.hxx>
53 : #include <editeng/unolingu.hxx>
54 : #include <sfx2/app.hxx>
55 : #include <svl/itemset.hxx>
56 : #include <editeng/brshitem.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>
81 :
82 : #include <dbinsdlg.hrc>
83 : #include <dbui.hrc>
84 :
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>
95 :
96 : namespace swui
97 : {
98 : SwAbstractDialogFactory * GetFactory();
99 : }
100 :
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;
109 :
110 : const char cDBFldStart = '<';
111 : const char cDBFldEnd = '>';
112 :
113 : // Helper structure for adding database rows as fields or text
114 : struct _DB_Column
115 : {
116 : enum ColType { DB_FILLTEXT, DB_COL_FIELD, DB_COL_TEXT, DB_SPLITPARA } eColType;
117 :
118 : union {
119 : String* pText;
120 : SwField* pField;
121 : sal_uLong nFormat;
122 : } DB_ColumnData;
123 : const SwInsDBColumn* pColInfo;
124 :
125 0 : _DB_Column()
126 : {
127 0 : pColInfo = 0;
128 0 : DB_ColumnData.pText = 0;
129 0 : eColType = DB_SPLITPARA;
130 0 : }
131 :
132 0 : _DB_Column( const String& rTxt )
133 : {
134 0 : pColInfo = 0;
135 0 : DB_ColumnData.pText = new String( rTxt );
136 0 : eColType = DB_FILLTEXT;
137 0 : }
138 :
139 0 : _DB_Column( const SwInsDBColumn& rInfo, sal_uLong nFormat )
140 : {
141 0 : pColInfo = &rInfo;
142 0 : DB_ColumnData.nFormat = nFormat;
143 0 : eColType = DB_COL_TEXT;
144 0 : }
145 :
146 0 : _DB_Column( const SwInsDBColumn& rInfo, SwDBField& rFld )
147 : {
148 0 : pColInfo = &rInfo;
149 0 : DB_ColumnData.pField = &rFld;
150 0 : eColType = DB_COL_FIELD;
151 0 : }
152 :
153 0 : ~_DB_Column()
154 : {
155 0 : if( DB_COL_FIELD == eColType )
156 0 : delete DB_ColumnData.pField;
157 0 : else if( DB_FILLTEXT == eColType )
158 0 : delete DB_ColumnData.pText;
159 0 : }
160 : };
161 :
162 :
163 : struct _DB_ColumnConfigData
164 : {
165 : SwInsDBColumns aDBColumns;
166 : rtl::OUString sSource, sTable, sEdit, sTblList, sTmplNm, sTAutoFmtNm;
167 : sal_Bool bIsTable : 1,
168 : bIsField : 1,
169 : bIsHeadlineOn : 1,
170 : bIsEmptyHeadln : 1;
171 :
172 0 : _DB_ColumnConfigData()
173 0 : {
174 0 : bIsTable = bIsHeadlineOn = sal_True;
175 0 : bIsField = bIsEmptyHeadln = sal_False;
176 0 : }
177 :
178 : ~_DB_ColumnConfigData();
179 : private:
180 : _DB_ColumnConfigData( const _DB_ColumnConfigData& );
181 : _DB_ColumnConfigData& operator =( const _DB_ColumnConfigData& );
182 : };
183 :
184 0 : int SwInsDBColumn::operator<( const SwInsDBColumn& rCmp ) const
185 : {
186 0 : return 0 > GetAppCollator().compareString( sColumn, rCmp.sColumn );
187 : }
188 :
189 0 : 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 )),
199 :
200 : aFlHead( this, SW_RES( FL_HEAD )),
201 : aFtDbColumn( this, SW_RES( FT_DB_COLUMN )),
202 :
203 : aLbTblDbColumn( this, SW_RES( LB_TBL_DB_COLUMN )),
204 : aLbTxtDbColumn( this, SW_RES( LB_TXT_DB_COLUMN )),
205 :
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 )),
210 :
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 )),
215 :
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 )),
227 :
228 : aBtOk( this, SW_RES( BT_OK )),
229 : aBtCancel( this, SW_RES( BT_CANCEL )),
230 : aBtHelp( this, SW_RES( BT_HELP )),
231 :
232 : aFlBottom( this, SW_RES( FL_BOTTOM )),
233 :
234 : aDBData(rData),
235 :
236 0 : aOldNumFmtLnk( aLbDbFmtFromUsr.GetSelectHdl() ),
237 : sNoTmpl( SW_RES( STR_NOTEMPL )),
238 : pView( &rView ),
239 : pTAutoFmt( 0 ),
240 : pTblSet( 0 ),
241 0 : pRep( 0 )
242 : {
243 0 : FreeResource();
244 :
245 0 : nGBFmtLen = aFlFormat.GetText().Len();
246 :
247 0 : if(xColSupp.is())
248 : {
249 0 : SwWrtShell& rSh = pView->GetWrtShell();
250 0 : SvNumberFormatter* pNumFmtr = rSh.GetNumberFormatter();
251 0 : SvNumberFormatsSupplierObj* pNumFmt = new SvNumberFormatsSupplierObj( pNumFmtr );
252 0 : Reference< util::XNumberFormatsSupplier > xDocNumFmtsSupplier = pNumFmt;
253 0 : Reference< util::XNumberFormats > xDocNumberFormats = xDocNumFmtsSupplier->getNumberFormats();
254 0 : Reference< util::XNumberFormatTypes > xDocNumberFormatTypes(xDocNumberFormats, UNO_QUERY);
255 :
256 0 : Reference<XPropertySet> xSourceProps(xDataSource, UNO_QUERY);
257 0 : Reference< util::XNumberFormats > xNumberFormats;
258 0 : if(xSourceProps.is())
259 : {
260 0 : Any aFormats = xSourceProps->getPropertyValue("NumberFormatsSupplier");
261 0 : if(aFormats.hasValue())
262 : {
263 0 : Reference< util::XNumberFormatsSupplier> xSuppl;
264 0 : aFormats >>= xSuppl;
265 0 : if(xSuppl.is())
266 : {
267 0 : xNumberFormats = xSuppl->getNumberFormats( );
268 0 : }
269 0 : }
270 : }
271 0 : Reference <XNameAccess> xCols = xColSupp->getColumns();
272 0 : Sequence<rtl::OUString> aColNames = xCols->getElementNames();
273 0 : const rtl::OUString* pColNames = aColNames.getConstArray();
274 0 : long nCount = aColNames.getLength();
275 0 : for (long n = 0; n < nCount; n++)
276 : {
277 0 : SwInsDBColumn* pNew = new SwInsDBColumn( pColNames[n], (sal_uInt16)n );
278 0 : Any aCol = xCols->getByName(pColNames[n]);
279 0 : Reference <XPropertySet> xCol;
280 0 : aCol >>= xCol;
281 0 : Any aType = xCol->getPropertyValue(rtl::OUString("Type"));
282 0 : sal_Int32 eDataType = 0;
283 0 : aType >>= eDataType;
284 0 : switch(eDataType)
285 : {
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:
300 : {
301 0 : pNew->bHasFmt = sal_True;
302 0 : Any aFormat = xCol->getPropertyValue("FormatKey");
303 0 : if(aFormat.hasValue())
304 : {
305 0 : sal_Int32 nFmt = 0;
306 0 : aFormat >>= nFmt;
307 0 : if(xNumberFormats.is())
308 : {
309 : try
310 : {
311 0 : Reference<XPropertySet> xNumProps = xNumberFormats->getByKey( nFmt );
312 0 : Any aFormatVal = xNumProps->getPropertyValue("FormatString");
313 0 : Any aLocale = xNumProps->getPropertyValue("Locale");
314 0 : rtl::OUString sFormat;
315 0 : aFormatVal >>= sFormat;
316 0 : lang::Locale aLoc;
317 0 : aLocale >>= aLoc;
318 0 : long nKey = xDocNumberFormats->queryKey( sFormat, aLoc, sal_True);
319 0 : if(nKey < 0)
320 : {
321 0 : nKey = xDocNumberFormats->addNew( sFormat, aLoc );
322 : }
323 0 : pNew->nDBNumFmt = nKey;
324 : }
325 0 : catch (const Exception&)
326 : {
327 : OSL_FAIL("illegal number format key");
328 : }
329 : }
330 : }
331 : else
332 : {
333 0 : pNew->nDBNumFmt = SwNewDBMgr::GetDbtoolsClient().getDefaultNumberFormat(xCol,
334 0 : xDocNumberFormatTypes, LanguageTag( rSh.GetCurLang() ).getLocale());
335 0 : }
336 :
337 : }
338 0 : break;
339 : }
340 0 : if( !aDBColumns.insert( pNew ).second )
341 : {
342 : OSL_ENSURE( !this, "Spaltenname mehrfach vergeben?" );
343 0 : delete pNew;
344 : }
345 0 : }
346 : }
347 :
348 : // fill paragraph templates-ListBox
349 : {
350 0 : SfxStyleSheetBasePool* pPool = pView->GetDocShell()->GetStyleSheetPool();
351 0 : pPool->SetSearchMask( SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL );
352 0 : aLbDbParaColl.InsertEntry( sNoTmpl );
353 :
354 0 : const SfxStyleSheetBase* pBase = pPool->First();
355 0 : while( pBase )
356 : {
357 0 : aLbDbParaColl.InsertEntry( pBase->GetName() );
358 0 : pBase = pPool->Next();
359 : }
360 0 : aLbDbParaColl.SelectEntryPos( 0 );
361 : }
362 :
363 : // when the cursor is inside of a table, table must NEVER be selectable
364 0 : if( pView->GetWrtShell().GetTableFmt() )
365 : {
366 0 : aRbAsTable.Enable( sal_False );
367 0 : aRbAsField.Check( sal_True );
368 0 : aRbDbFmtFromDb.Check( sal_True );
369 : }
370 : else
371 : {
372 0 : aRbAsTable.Check( sal_True );
373 0 : aRbDbFmtFromDb.Check( sal_True );
374 0 : aIbDbcolOneFrom.Enable( sal_False );
375 0 : aIbDbcolAllFrom.Enable( sal_False );
376 : }
377 :
378 0 : aRbAsTable.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, PageHdl ));
379 0 : aRbAsField.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, PageHdl ));
380 0 : aRbAsText.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, PageHdl ));
381 :
382 0 : aRbDbFmtFromDb.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, DBFormatHdl ));
383 0 : aRbDbFmtFromUsr.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, DBFormatHdl ));
384 :
385 0 : aPbTblFormat.SetClickHdl(LINK(this, SwInsertDBColAutoPilot, TblFmtHdl ));
386 0 : aPbTblAutofmt.SetClickHdl(LINK(this, SwInsertDBColAutoPilot, AutoFmtHdl ));
387 :
388 0 : aIbDbcolAllTo.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
389 0 : aIbDbcolOneTo.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
390 0 : aIbDbcolOneFrom.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
391 0 : aIbDbcolAllFrom.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
392 0 : aIbDbcolToEdit.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
393 :
394 0 : aCbTableHeadon.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, HeaderHdl ));
395 0 : aRbHeadlColnms.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, HeaderHdl ));
396 0 : aRbHeadlEmpty.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, HeaderHdl ));
397 :
398 0 : aLbTxtDbColumn.SetSelectHdl( LINK( this, SwInsertDBColAutoPilot, SelectHdl ));
399 0 : aLbTblDbColumn.SetSelectHdl( LINK( this, SwInsertDBColAutoPilot, SelectHdl ));
400 0 : aLbDbFmtFromUsr.SetSelectHdl( LINK( this, SwInsertDBColAutoPilot, SelectHdl ));
401 0 : aLbTableCol.SetSelectHdl( LINK( this, SwInsertDBColAutoPilot, SelectHdl ));
402 :
403 0 : aLbTxtDbColumn.SetDoubleClickHdl( LINK( this, SwInsertDBColAutoPilot, DblClickHdl ));
404 0 : aLbTblDbColumn.SetDoubleClickHdl( LINK( this, SwInsertDBColAutoPilot, DblClickHdl ));
405 0 : aLbTableCol.SetDoubleClickHdl( LINK( this, SwInsertDBColAutoPilot, DblClickHdl ));
406 :
407 0 : for( sal_uInt16 n = 0; n < aDBColumns.size(); ++n )
408 : {
409 0 : const String& rS = aDBColumns[ n ]->sColumn;
410 0 : aLbTblDbColumn.InsertEntry( rS, n );
411 0 : aLbTxtDbColumn.InsertEntry( rS, n );
412 0 : }
413 0 : aLbTxtDbColumn.SelectEntryPos( 0 );
414 0 : aLbTblDbColumn.SelectEntryPos( 0 );
415 :
416 : // read configuration
417 0 : Load();
418 :
419 : // initialise Controls:
420 0 : PageHdl( aRbAsTable.IsChecked() ? &aRbAsTable : &aRbAsField );
421 0 : }
422 :
423 0 : SwInsertDBColAutoPilot::~SwInsertDBColAutoPilot()
424 : {
425 0 : delete pTblSet;
426 0 : delete pRep;
427 :
428 0 : delete pTAutoFmt;
429 0 : }
430 :
431 0 : IMPL_LINK( SwInsertDBColAutoPilot, PageHdl, Button*, pButton )
432 : {
433 0 : sal_Bool bShowTbl = pButton == &aRbAsTable;
434 :
435 0 : String sTxt( pButton->GetText() );
436 0 : aFlHead.SetText( MnemonicGenerator::EraseAllMnemonicChars( sTxt ) );
437 :
438 0 : aLbTxtDbColumn.Show( !bShowTbl );
439 0 : aIbDbcolToEdit.Show( !bShowTbl );
440 0 : aEdDbText.Show( !bShowTbl );
441 0 : aFtDbParaColl.Show( !bShowTbl );
442 0 : aLbDbParaColl.Show( !bShowTbl );
443 :
444 0 : aLbTblDbColumn.Show( bShowTbl );
445 0 : aIbDbcolAllTo.Show( bShowTbl );
446 0 : aIbDbcolOneTo.Show( bShowTbl );
447 0 : aIbDbcolOneFrom.Show( bShowTbl );
448 0 : aIbDbcolAllFrom.Show( bShowTbl );
449 0 : aFtTableCol.Show( bShowTbl );
450 0 : aLbTableCol.Show( bShowTbl );
451 0 : aCbTableHeadon.Show( bShowTbl );
452 0 : aRbHeadlColnms.Show( bShowTbl );
453 0 : aRbHeadlEmpty.Show( bShowTbl );
454 0 : aPbTblFormat.Show( bShowTbl );
455 0 : aPbTblAutofmt.Show( bShowTbl );
456 :
457 0 : if( bShowTbl )
458 0 : aPbTblFormat.Enable( 0 != aLbTableCol.GetEntryCount() );
459 :
460 0 : SelectHdl( bShowTbl ? &aLbTblDbColumn : &aLbTxtDbColumn );
461 :
462 0 : return 0;
463 : }
464 :
465 0 : IMPL_LINK( SwInsertDBColAutoPilot, DBFormatHdl, Button*, pButton )
466 : {
467 0 : ListBox& rBox = aRbAsTable.IsChecked()
468 0 : ? ( 0 == aLbTableCol.GetEntryData( 0 )
469 : ? aLbTblDbColumn
470 : : aLbTableCol )
471 0 : : aLbTxtDbColumn;
472 :
473 0 : SwInsDBColumn aSrch( rBox.GetSelectEntry(), 0 );
474 0 : SwInsDBColumns::const_iterator it = aDBColumns.find( &aSrch );
475 :
476 0 : sal_Bool bFromDB = &aRbDbFmtFromDb == pButton;
477 0 : (*it)->bIsDBFmt = bFromDB;
478 0 : aLbDbFmtFromUsr.Enable( !bFromDB );
479 :
480 0 : return 0;
481 : }
482 :
483 0 : IMPL_LINK( SwInsertDBColAutoPilot, TblToFromHdl, Button*, pButton )
484 : {
485 0 : sal_Bool bChgEnable = sal_True, bEnableTo = sal_True, bEnableFrom = sal_True;
486 0 : aLbTblDbColumn.SetUpdateMode( sal_False );
487 0 : aLbTableCol.SetUpdateMode( sal_False );
488 :
489 0 : if( pButton == &aIbDbcolAllTo )
490 : {
491 0 : bEnableTo = sal_False;
492 :
493 0 : sal_uInt16 n, nInsPos = aLbTableCol.GetSelectEntryPos(),
494 0 : nCnt = aLbTblDbColumn.GetEntryCount();
495 0 : if( LISTBOX_APPEND == nInsPos )
496 0 : for( n = 0; n < nCnt; ++n )
497 : aLbTableCol.InsertEntry( aLbTblDbColumn.GetEntry( n ),
498 0 : LISTBOX_APPEND );
499 : else
500 0 : for( n = 0; n < nCnt; ++n, ++nInsPos )
501 0 : aLbTableCol.InsertEntry( aLbTblDbColumn.GetEntry( n ), nInsPos );
502 0 : aLbTblDbColumn.Clear();
503 0 : aLbTableCol.SelectEntryPos( nInsPos );
504 0 : aLbTblDbColumn.SelectEntryPos( LISTBOX_APPEND );
505 : }
506 0 : else if( pButton == &aIbDbcolOneTo &&
507 0 : LISTBOX_ENTRY_NOTFOUND != aLbTblDbColumn.GetSelectEntryPos() )
508 : {
509 0 : sal_uInt16 nInsPos = aLbTableCol.GetSelectEntryPos(),
510 0 : nDelPos = aLbTblDbColumn.GetSelectEntryPos(),
511 0 : nTopPos = aLbTblDbColumn.GetTopEntry();
512 0 : aLbTableCol.InsertEntry( aLbTblDbColumn.GetEntry( nDelPos ), nInsPos );
513 0 : aLbTblDbColumn.RemoveEntry( nDelPos );
514 :
515 0 : aLbTableCol.SelectEntryPos( nInsPos );
516 0 : if( nDelPos >= aLbTblDbColumn.GetEntryCount() )
517 0 : nDelPos = aLbTblDbColumn.GetEntryCount() - 1;
518 0 : aLbTblDbColumn.SelectEntryPos( nDelPos );
519 0 : aLbTblDbColumn.SetTopEntry( nTopPos );
520 :
521 0 : bEnableTo = 0 != aLbTblDbColumn.GetEntryCount();
522 : }
523 0 : else if( pButton == &aIbDbcolOneFrom )
524 : {
525 0 : if( LISTBOX_ENTRY_NOTFOUND != aLbTableCol.GetSelectEntryPos() )
526 : {
527 : sal_uInt16 nInsPos,
528 0 : nDelPos = aLbTableCol.GetSelectEntryPos(),
529 0 : nTopPos = aLbTableCol.GetTopEntry();
530 :
531 : // look for the right InsertPos!!
532 0 : SwInsDBColumn aSrch( aLbTableCol.GetEntry( nDelPos ), 0 );
533 0 : SwInsDBColumns::const_iterator it = aDBColumns.find( &aSrch );
534 0 : if( it == aDBColumns.begin() || (it+1) == aDBColumns.end() )
535 0 : nInsPos = it - aDBColumns.begin();
536 : else
537 : {
538 0 : nInsPos = LISTBOX_ENTRY_NOTFOUND;
539 0 : while( ++it != aDBColumns.end() &&
540 : LISTBOX_ENTRY_NOTFOUND == (nInsPos = aLbTblDbColumn.
541 0 : GetEntryPos( String( (*it)->sColumn ))) )
542 : ;
543 : }
544 :
545 0 : aLbTblDbColumn.InsertEntry( aSrch.sColumn, nInsPos );
546 0 : aLbTableCol.RemoveEntry( nDelPos );
547 :
548 0 : if( nInsPos >= aLbTblDbColumn.GetEntryCount() )
549 0 : nInsPos = aLbTblDbColumn.GetEntryCount() - 1;
550 0 : aLbTblDbColumn.SelectEntryPos( nInsPos );
551 :
552 0 : if( nDelPos >= aLbTableCol.GetEntryCount() )
553 0 : nDelPos = aLbTableCol.GetEntryCount() - 1;
554 0 : aLbTableCol.SelectEntryPos( nDelPos );
555 0 : aLbTableCol.SetTopEntry( nTopPos );
556 : }
557 : else
558 0 : bEnableTo = 0 != aLbTblDbColumn.GetEntryCount();
559 :
560 0 : bEnableFrom = 0 != aLbTableCol.GetEntryCount();
561 : }
562 0 : else if( pButton == &aIbDbcolAllFrom )
563 : {
564 0 : bEnableFrom = sal_False;
565 :
566 0 : aLbTblDbColumn.Clear();
567 0 : aLbTableCol.Clear();
568 0 : for( sal_uInt16 n = 0; n < aDBColumns.size(); ++n )
569 0 : aLbTblDbColumn.InsertEntry( aDBColumns[ n ]->sColumn, n );
570 0 : aLbTblDbColumn.SelectEntryPos( 0 );
571 : }
572 0 : else if( pButton == &aIbDbcolToEdit )
573 : {
574 0 : bChgEnable = sal_False;
575 : // move data to Edit:
576 0 : String aFld( aLbTxtDbColumn.GetSelectEntry() );
577 0 : if( aFld.Len() )
578 : {
579 0 : String aStr( aEdDbText.GetText() );
580 0 : sal_uInt16 nPos = (sal_uInt16)aEdDbText.GetSelection().Min();
581 0 : sal_uInt16 nSel = sal_uInt16(aEdDbText.GetSelection().Max()) - nPos;
582 0 : if( nSel )
583 : // first delete the existing selection
584 0 : aStr.Erase( nPos, nSel );
585 :
586 0 : aFld.Insert( cDBFldStart, 0 );
587 0 : aFld += cDBFldEnd;
588 0 : if( aStr.Len() )
589 : {
590 0 : if( nPos ) // one blank in front
591 : {
592 0 : sal_Unicode c = aStr.GetChar( nPos-1 );
593 0 : if( '\n' != c && '\r' != c )
594 0 : aFld.Insert( ' ', 0 );
595 : }
596 0 : if( nPos < aStr.Len() ) // one blank behind
597 : {
598 0 : sal_Unicode c = aStr.GetChar( nPos );
599 0 : if( '\n' != c && '\r' != c )
600 0 : aFld += ' ';
601 : }
602 : }
603 :
604 0 : aStr.Insert( aFld, nPos );
605 0 : aEdDbText.SetText( aStr );
606 0 : nPos = nPos + aFld.Len();
607 0 : aEdDbText.SetSelection( Selection( nPos ));
608 0 : }
609 : }
610 :
611 0 : if( bChgEnable )
612 : {
613 0 : aIbDbcolOneTo.Enable( bEnableTo );
614 0 : aIbDbcolAllTo.Enable( bEnableTo );
615 0 : aIbDbcolOneFrom.Enable( bEnableFrom );
616 0 : aIbDbcolAllFrom.Enable( bEnableFrom );
617 :
618 0 : aRbDbFmtFromDb.Enable( sal_False );
619 0 : aRbDbFmtFromUsr.Enable( sal_False );
620 0 : aLbDbFmtFromUsr.Enable( sal_False );
621 :
622 0 : aPbTblFormat.Enable( bEnableFrom );
623 : }
624 0 : aLbTblDbColumn.SetUpdateMode( sal_True );
625 0 : aLbTableCol.SetUpdateMode( sal_True );
626 :
627 0 : return 0;
628 : }
629 :
630 0 : IMPL_LINK( SwInsertDBColAutoPilot, DblClickHdl, ListBox*, pBox )
631 : {
632 0 : Button* pButton = 0;
633 0 : if( pBox == &aLbTxtDbColumn )
634 0 : pButton = &aIbDbcolToEdit;
635 0 : else if( pBox == &aLbTblDbColumn && aIbDbcolOneTo.IsEnabled() )
636 0 : pButton = &aIbDbcolOneTo;
637 0 : else if( pBox == &aLbTableCol && aIbDbcolOneFrom.IsEnabled() )
638 0 : pButton = &aIbDbcolOneFrom;
639 :
640 0 : if( pButton )
641 0 : TblToFromHdl( pButton );
642 :
643 0 : return 0;
644 : }
645 :
646 0 : IMPL_LINK( SwInsertDBColAutoPilot, TblFmtHdl, PushButton*, pButton )
647 : {
648 0 : SwWrtShell& rSh = pView->GetWrtShell();
649 0 : sal_Bool bNewSet = sal_False;
650 0 : if( !pTblSet )
651 : {
652 0 : bNewSet = sal_True;
653 0 : pTblSet = new SfxItemSet( rSh.GetAttrPool(), SwuiGetUITableAttrRange() );
654 :
655 : // At first acquire the simple attributes
656 0 : pTblSet->Put( SfxStringItem( FN_PARAM_TABLE_NAME, rSh.GetUniqueTblName() ));
657 0 : pTblSet->Put( SfxUInt16Item( FN_PARAM_TABLE_HEADLINE, 1 ) );
658 :
659 : pTblSet->Put( SfxUInt16Item( SID_BACKGRND_DESTINATION,
660 0 : rSh.GetViewOptions()->GetTblDest() ));
661 :
662 0 : SvxBrushItem aBrush( RES_BACKGROUND );
663 0 : pTblSet->Put( aBrush );
664 0 : pTblSet->Put( aBrush, SID_ATTR_BRUSH_ROW );
665 0 : pTblSet->Put( aBrush, SID_ATTR_BRUSH_TABLE );
666 :
667 0 : SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
668 : // table variant, when multiple table cells are selected
669 0 : aBoxInfo.SetTable( sal_True );
670 : // always show gap field
671 0 : aBoxInfo.SetDist( sal_True);
672 : // set minimum size in tables and paragraphs
673 0 : aBoxInfo.SetMinDist( sal_False );
674 : // always set default-gap
675 0 : aBoxInfo.SetDefDist( MIN_BORDER_DIST );
676 : // Single lines can have DontCare-status only in tables
677 0 : aBoxInfo.SetValid( VALID_DISABLE, sal_True );
678 0 : pTblSet->Put( aBoxInfo );
679 :
680 0 : SwGetCurColNumPara aPara;
681 0 : const sal_uInt16 nNum = rSh.GetCurColNum( &aPara );
682 : long nWidth;
683 :
684 0 : if( nNum )
685 : {
686 0 : nWidth = aPara.pPrtRect->Width();
687 0 : const SwFmtCol& rCol = aPara.pFrmFmt->GetCol();
688 0 : const SwColumns& rCols = rCol.GetColumns();
689 :
690 : // initialise nStart und nEnd for nNum == 0
691 0 : long nWidth1 = 0,
692 0 : nStart1 = 0,
693 0 : nEnd1 = nWidth;
694 0 : for( sal_uInt16 i = 0; i < nNum; ++i )
695 : {
696 0 : const SwColumn* pCol = &rCols[i];
697 0 : nStart1 = pCol->GetLeft() + nWidth1;
698 0 : nWidth1 += (long)rCol.CalcColWidth( i, (sal_uInt16)nWidth );
699 0 : nEnd1 = nWidth1 - pCol->GetRight();
700 : }
701 0 : if(nStart1 || nEnd1 != nWidth)
702 0 : nWidth = nEnd1 - nStart1;
703 : }
704 : else
705 : nWidth = rSh.GetAnyCurRect(
706 0 : FRMTYPE_FLY_ANY & rSh.GetFrmType( 0, sal_True )
707 : ? RECT_FLY_PRT_EMBEDDED
708 0 : : RECT_PAGE_PRT ).Width();
709 :
710 0 : SwTabCols aTabCols;
711 0 : aTabCols.SetRight( nWidth );
712 0 : aTabCols.SetRightMax( nWidth );
713 0 : pRep = new SwTableRep( aTabCols );
714 0 : pRep->SetAlign( text::HoriOrientation::NONE );
715 0 : pRep->SetSpace( nWidth );
716 0 : pRep->SetWidth( nWidth );
717 0 : pRep->SetWidthPercent( 100 );
718 0 : pTblSet->Put( SwPtrItem( FN_TABLE_REP, pRep ));
719 :
720 : pTblSet->Put( SfxUInt16Item( SID_HTML_MODE,
721 0 : ::GetHtmlMode( pView->GetDocShell() )));
722 : }
723 :
724 0 : if( aLbTableCol.GetEntryCount() != pRep->GetAllColCount() )
725 : {
726 : // Number of columns has changed: then the TabCols have to be adjusted
727 0 : long nWidth = pRep->GetWidth();
728 0 : sal_uInt16 nCols = aLbTableCol.GetEntryCount() - 1;
729 0 : SwTabCols aTabCols( nCols );
730 0 : aTabCols.SetRight( nWidth );
731 0 : aTabCols.SetRightMax( nWidth );
732 0 : if( nCols )
733 0 : for( sal_uInt16 n = 0, nStep = (sal_uInt16)(nWidth / (nCols+1)), nW = nStep;
734 : n < nCols; ++n, nW = nW + nStep )
735 : {
736 0 : aTabCols.Insert( nW, sal_False, n );
737 : }
738 0 : delete pRep;
739 0 : pRep = new SwTableRep( aTabCols );
740 0 : pRep->SetAlign( text::HoriOrientation::NONE );
741 0 : pRep->SetSpace( nWidth );
742 0 : pRep->SetWidth( nWidth );
743 0 : pRep->SetWidthPercent( 100 );
744 0 : pTblSet->Put( SwPtrItem( FN_TABLE_REP, pRep ));
745 : }
746 :
747 0 : SwAbstractDialogFactory* pFact = swui::GetFactory();
748 : OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
749 :
750 0 : SfxAbstractTabDialog* pDlg = pFact->CreateSwTableTabDlg( pButton, rSh.GetAttrPool(),pTblSet, &rSh, DLG_FORMAT_TABLE );
751 : OSL_ENSURE(pDlg, "Dialogdiet fail!");
752 0 : if( RET_OK == pDlg->Execute() )
753 0 : pTblSet->Put( *pDlg->GetOutputItemSet() );
754 0 : else if( bNewSet )
755 : {
756 0 : delete pTblSet, pTblSet = 0;
757 0 : delete pRep, pRep = 0;
758 : }
759 0 : delete pDlg;
760 :
761 0 : return 0;
762 : }
763 :
764 0 : IMPL_LINK( SwInsertDBColAutoPilot, AutoFmtHdl, PushButton*, pButton )
765 : {
766 0 : SwAbstractDialogFactory* pFact = swui::GetFactory();
767 : OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
768 :
769 0 : AbstractSwAutoFormatDlg* pDlg = pFact->CreateSwAutoFormatDlg(pButton, pView->GetWrtShellPtr(), sal_False, pTAutoFmt);
770 : OSL_ENSURE(pDlg, "Dialogdiet fail!");
771 0 : if( RET_OK == pDlg->Execute())
772 0 : pDlg->FillAutoFmtOfIndex( pTAutoFmt );
773 0 : delete pDlg;
774 0 : return 0;
775 : }
776 :
777 0 : IMPL_LINK( SwInsertDBColAutoPilot, SelectHdl, ListBox*, pBox )
778 : {
779 : ListBox* pGetBox = pBox == &aLbDbFmtFromUsr
780 0 : ? ( aRbAsTable.IsChecked()
781 0 : ? ( 0 == aLbTableCol.GetEntryData( 0 )
782 : ? &aLbTblDbColumn
783 : : &aLbTableCol )
784 : : &aLbTxtDbColumn )
785 0 : : pBox;
786 :
787 0 : SwInsDBColumn aSrch( pGetBox->GetSelectEntry(), 0 );
788 0 : SwInsDBColumns::const_iterator it = aDBColumns.find( &aSrch );
789 :
790 0 : if( pBox == &aLbDbFmtFromUsr )
791 : {
792 0 : if( !aSrch.sColumn.isEmpty() )
793 : {
794 0 : aOldNumFmtLnk.Call( pBox );
795 0 : (*it)->nUsrNumFmt = aLbDbFmtFromUsr.GetFormat();
796 : }
797 : }
798 : else
799 : {
800 : // set the selected FieldName at the FormatGroupBox, so that
801 : // it's clear what field is configured by the format!
802 0 : String sTxt( aFlFormat.GetText().Copy( 0, nGBFmtLen ));
803 0 : if( aSrch.sColumn.isEmpty() )
804 : {
805 0 : aRbDbFmtFromDb.Enable( sal_False );
806 0 : aRbDbFmtFromUsr.Enable( sal_False );
807 0 : aLbDbFmtFromUsr.Enable( sal_False );
808 : }
809 : else
810 : {
811 0 : sal_Bool bEnableFmt = (*it)->bHasFmt;
812 0 : aRbDbFmtFromDb.Enable( bEnableFmt );
813 0 : aRbDbFmtFromUsr.Enable( bEnableFmt );
814 :
815 0 : if( bEnableFmt )
816 : {
817 0 : (( sTxt += rtl::OUString(" (" )) += String(aSrch.sColumn) ) += (sal_Unicode)')';
818 : }
819 :
820 0 : sal_Bool bIsDBFmt = (*it)->bIsDBFmt;
821 0 : aRbDbFmtFromDb.Check( bIsDBFmt );
822 0 : aRbDbFmtFromUsr.Check( !bIsDBFmt );
823 0 : aLbDbFmtFromUsr.Enable( !bIsDBFmt );
824 0 : if( !bIsDBFmt )
825 0 : aLbDbFmtFromUsr.SetDefFormat( (*it)->nUsrNumFmt );
826 : }
827 :
828 0 : aFlFormat.SetText( sTxt );
829 :
830 : // to know later on, what ListBox was the "active", a Flag
831 : // is remembered in the 1st entry
832 0 : void* pPtr = pBox == &aLbTableCol ? &aLbTableCol : 0;
833 0 : aLbTableCol.SetEntryData( 0, pPtr );
834 : }
835 0 : return 0;
836 : }
837 :
838 0 : IMPL_LINK( SwInsertDBColAutoPilot, HeaderHdl, Button*, pButton )
839 : {
840 0 : if( pButton == &aCbTableHeadon )
841 : {
842 0 : sal_Bool bEnable = aCbTableHeadon.IsChecked();
843 :
844 0 : aRbHeadlColnms.Enable( bEnable );
845 0 : aRbHeadlEmpty.Enable( bEnable );
846 : }
847 0 : return 0;
848 : }
849 :
850 0 : static void lcl_InsTextInArr( const String& rTxt, _DB_Columns& rColArr )
851 : {
852 : _DB_Column* pNew;
853 0 : sal_uInt16 nSttPos = 0, nFndPos;
854 0 : while( STRING_NOTFOUND != ( nFndPos = rTxt.Search( '\x0A', nSttPos )) )
855 : {
856 0 : if( 1 < nFndPos )
857 : {
858 0 : pNew = new _DB_Column( rTxt.Copy( nSttPos, nFndPos -1 ) );
859 0 : rColArr.push_back( pNew );
860 : }
861 0 : pNew = new _DB_Column;
862 0 : rColArr.push_back( pNew );
863 0 : nSttPos = nFndPos + 1;
864 : }
865 0 : if( nSttPos < rTxt.Len() )
866 : {
867 0 : pNew = new _DB_Column( rTxt.Copy( nSttPos ) );
868 0 : rColArr.push_back( pNew );
869 : }
870 0 : }
871 :
872 0 : sal_Bool SwInsertDBColAutoPilot::SplitTextToColArr( const String& rTxt,
873 : _DB_Columns& rColArr,
874 : sal_Bool bInsField )
875 : {
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 0 : String sTxt( rTxt );
880 0 : sal_uInt16 nFndPos, nEndPos, nSttPos = 0;
881 :
882 0 : while( STRING_NOTFOUND != ( nFndPos = sTxt.Search( cDBFldStart, nSttPos )))
883 : {
884 0 : nSttPos = nFndPos + 1;
885 0 : if( STRING_NOTFOUND != ( nEndPos = sTxt.Search( cDBFldEnd, nSttPos+1 )))
886 : {
887 : // Text in <> brackets found: what is it:
888 0 : SwInsDBColumn aSrch( sTxt.Copy( nSttPos, nEndPos - nSttPos ), 0);
889 0 : SwInsDBColumns::const_iterator it = aDBColumns.find( &aSrch );
890 0 : if( it != aDBColumns.end() )
891 : {
892 : // that is a valid field
893 : // so surely the text "before":
894 0 : const SwInsDBColumn& rFndCol = **it;
895 :
896 : _DB_Column* pNew;
897 :
898 0 : if( 1 < nSttPos )
899 : {
900 0 : ::lcl_InsTextInArr( sTxt.Copy( 0, nSttPos-1 ), rColArr );
901 0 : sTxt.Erase( 0, nSttPos-1 );
902 : }
903 :
904 0 : sTxt.Erase( 0, (xub_StrLen)(rFndCol.sColumn.getLength() + 2) );
905 0 : nSttPos = 0;
906 :
907 0 : sal_uInt16 nSubType = 0;
908 : sal_uLong nFormat;
909 0 : if( rFndCol.bHasFmt )
910 : {
911 0 : if( rFndCol.bIsDBFmt )
912 0 : nFormat = rFndCol.nDBNumFmt;
913 : else
914 : {
915 0 : nFormat = rFndCol.nUsrNumFmt;
916 0 : nSubType = nsSwExtendedSubType::SUB_OWN_FMT;
917 : }
918 : }
919 : else
920 0 : nFormat = 0;
921 :
922 0 : if( bInsField )
923 : {
924 0 : SwWrtShell& rSh = pView->GetWrtShell();
925 : SwDBFieldType aFldType( rSh.GetDoc(), aSrch.sColumn,
926 0 : aDBData );
927 : pNew = new _DB_Column( rFndCol, *new SwDBField(
928 0 : (SwDBFieldType*)rSh.InsertFldType( aFldType ),
929 0 : nFormat ) );
930 0 : if( nSubType )
931 0 : pNew->DB_ColumnData.pField->SetSubType( nSubType );
932 : }
933 : else
934 0 : pNew = new _DB_Column( rFndCol, nFormat );
935 :
936 0 : rColArr.push_back( pNew );
937 0 : }
938 : }
939 : }
940 :
941 : // don't forget the last text
942 0 : if( sTxt.Len() )
943 0 : ::lcl_InsTextInArr( sTxt, rColArr );
944 :
945 0 : return !rColArr.empty();
946 : }
947 :
948 0 : void SwInsertDBColAutoPilot::DataToDoc( const Sequence<Any>& rSelection,
949 : Reference< XDataSource> xSource,
950 : Reference< XConnection> xConnection,
951 : Reference< sdbc::XResultSet > xResultSet )
952 : {
953 0 : const Any* pSelection = rSelection.getLength() ? rSelection.getConstArray() : 0;
954 0 : SwWrtShell& rSh = pView->GetWrtShell();
955 :
956 : //with the drag and drop interface no result set is initially available
957 0 : sal_Bool bDisposeResultSet = sal_False;
958 : // we don't have a cursor, so we have to create our own RowSet
959 0 : if ( !xResultSet.is() )
960 : {
961 0 : xResultSet = SwNewDBMgr::createCursor(aDBData.sDataSource,aDBData.sCommand,aDBData.nCommandType,xConnection);
962 0 : bDisposeResultSet = xResultSet.is();
963 : }
964 :
965 0 : Reference< sdbc::XRow > xRow(xResultSet, UNO_QUERY);
966 0 : if ( !xRow.is() )
967 0 : return;
968 :
969 0 : rSh.StartAllAction();
970 0 : sal_Bool bUndo = rSh.DoesUndo();
971 0 : if( bUndo )
972 0 : rSh.StartUndo( UNDO_EMPTY );
973 :
974 0 : sal_Bool bAsTable = aRbAsTable.IsChecked();
975 0 : SvNumberFormatter& rNumFmtr = *rSh.GetNumberFormatter();
976 :
977 0 : if( rSh.HasSelection() )
978 0 : rSh.DelRight();
979 :
980 0 : ::std::auto_ptr<SwWait> pWait;
981 :
982 0 : Reference< XColumnsSupplier > xColsSupp( xResultSet, UNO_QUERY );
983 0 : Reference <XNameAccess> xCols = xColsSupp->getColumns();
984 :
985 : do{ // middle checked loop!!
986 0 : if( bAsTable ) // Daten als Tabelle einfuegen
987 : {
988 0 : rSh.DoUndo( sal_False );
989 :
990 0 : sal_uInt16 n, nRows = 0, nCols = aLbTableCol.GetEntryCount();
991 0 : if( aCbTableHeadon.IsChecked() )
992 0 : nRows++;
993 :
994 0 : if( pSelection )
995 0 : nRows = nRows + (sal_uInt16)rSelection.getLength();
996 : else
997 0 : ++nRows;
998 :
999 : // prepare the array for the selected columns
1000 0 : std::vector<SwInsDBColumn*> aColFlds;
1001 0 : for( n = 0; n < nCols; ++n )
1002 : {
1003 0 : SwInsDBColumn aSrch( aLbTableCol.GetEntry( n ), 0 );
1004 0 : SwInsDBColumns::const_iterator it = aDBColumns.find( &aSrch );
1005 0 : if( it != aDBColumns.end() )
1006 0 : aColFlds[ n ] = *it;
1007 : else {
1008 : OSL_ENSURE( !this, "database column not found" );
1009 : }
1010 0 : }
1011 :
1012 0 : if( nCols != aColFlds.size() )
1013 : {
1014 : OSL_ENSURE( !this, "not all database columns found" );
1015 0 : nCols = aColFlds.size();
1016 : }
1017 :
1018 0 : if(!nRows || !nCols)
1019 : {
1020 : OSL_ENSURE( !this, "wrong parameters" );
1021 : break;
1022 : }
1023 :
1024 0 : const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
1025 :
1026 0 : sal_Bool bHTML = 0 != (::GetHtmlMode( pView->GetDocShell() ) & HTMLMODE_ON);
1027 : rSh.InsertTable(
1028 0 : pModOpt->GetInsTblFlags(bHTML),
1029 0 : nRows, nCols, text::HoriOrientation::FULL, (pSelection ? pTAutoFmt : 0) );
1030 0 : rSh.MoveTable( GetfnTablePrev(), GetfnTableStart() );
1031 :
1032 0 : if( pSelection && pTblSet )
1033 0 : SetTabSet();
1034 :
1035 0 : SfxItemSet aTblSet( rSh.GetAttrPool(), RES_BOXATR_FORMAT,
1036 0 : RES_BOXATR_VALUE );
1037 0 : sal_Bool bIsAutoUpdateCells = rSh.IsAutoUpdateCells();
1038 0 : rSh.SetAutoUpdateCells( sal_False );
1039 :
1040 :
1041 0 : if( aCbTableHeadon.IsChecked() )
1042 : {
1043 0 : for( n = 0; n < nCols; ++n )
1044 : {
1045 0 : if( aRbHeadlColnms.IsChecked() )
1046 : {
1047 0 : rSh.SwEditShell::Insert2( aColFlds[ n ]->sColumn );
1048 : }
1049 0 : rSh.GoNextCell();
1050 : }
1051 : }
1052 : else
1053 0 : rSh.SetRowsToRepeat( 0 );
1054 :
1055 0 : for( sal_Int32 i = 0 ; ; ++i )
1056 : {
1057 0 : sal_Bool bBreak = sal_False;
1058 : try
1059 : {
1060 0 : if(pSelection)
1061 : {
1062 0 : sal_Int32 nPos = 0;
1063 0 : pSelection[i] >>= nPos;
1064 0 : bBreak = !xResultSet->absolute(nPos);
1065 : }
1066 0 : else if(!i)
1067 0 : bBreak = !xResultSet->first();
1068 : }
1069 0 : catch (const Exception&)
1070 : {
1071 0 : bBreak = sal_True;
1072 : }
1073 0 : if(bBreak)
1074 0 : break;
1075 :
1076 0 : for( n = 0; n < nCols; ++n )
1077 : {
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 0 : if( i || n )
1082 0 : rSh.GoNextCell();
1083 :
1084 0 : const SwInsDBColumn* pEntry = aColFlds[ n ];
1085 :
1086 0 : Reference< XColumn > xColumn;
1087 0 : xCols->getByName(pEntry->sColumn) >>= xColumn;
1088 0 : Reference< XPropertySet > xColumnProps( xColumn, UNO_QUERY );
1089 0 : sal_Int32 eDataType = 0;
1090 0 : if( xColumnProps.is() )
1091 : {
1092 0 : Any aType = xColumnProps->getPropertyValue("Type");
1093 0 : aType >>= eDataType;
1094 : }
1095 : try
1096 : {
1097 0 : if( pEntry->bHasFmt )
1098 : {
1099 : SwTblBoxNumFormat aNumFmt(
1100 : pEntry->bIsDBFmt ? pEntry->nDBNumFmt
1101 0 : : pEntry->nUsrNumFmt );
1102 0 : aTblSet.Put(aNumFmt);
1103 0 : if( xColumn.is() )
1104 : {
1105 0 : double fVal = xColumn->getDouble();
1106 0 : if( xColumn->wasNull() )
1107 0 : aTblSet.ClearItem( RES_BOXATR_VALUE );
1108 : else
1109 : {
1110 0 : if(rNumFmtr.GetType(aNumFmt.GetValue()) & NUMBERFORMAT_DATE)
1111 : {
1112 0 : ::Date aStandard(1,1,1900);
1113 0 : if (*rNumFmtr.GetNullDate() != aStandard)
1114 0 : fVal += (aStandard - *rNumFmtr.GetNullDate());
1115 : }
1116 0 : aTblSet.Put( SwTblBoxValue( fVal ));
1117 : }
1118 : }
1119 : else
1120 0 : aTblSet.ClearItem( RES_BOXATR_VALUE );
1121 0 : rSh.SetTblBoxFormulaAttrs( aTblSet );
1122 : }
1123 : //#i60207# don't insert binary data as string - creates a loop
1124 0 : 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
1136 : )
1137 : {
1138 : // do nothing
1139 : }
1140 : else
1141 : {
1142 0 : rtl::OUString sVal = xColumn->getString();
1143 0 : if(!xColumn->wasNull())
1144 : {
1145 0 : rSh.SwEditShell::Insert2( sVal );
1146 0 : }
1147 : }
1148 : }
1149 0 : catch (const Exception& rExcept)
1150 : {
1151 : OSL_FAIL(rtl::OUStringToOString(rExcept.Message, osl_getThreadTextEncoding()).getStr());
1152 : (void)rExcept;
1153 : }
1154 0 : }
1155 :
1156 0 : if( !pSelection )
1157 : {
1158 0 : if ( !xResultSet->next() )
1159 0 : break;
1160 : }
1161 0 : else if( i+1 >= rSelection.getLength() )
1162 0 : break;
1163 :
1164 0 : if( 10 == i )
1165 0 : pWait = ::std::auto_ptr<SwWait>(new SwWait( *pView->GetDocShell(), sal_True ));
1166 : }
1167 :
1168 0 : rSh.MoveTable( GetfnTableCurr(), GetfnTableStart() );
1169 0 : if( !pSelection && ( pTblSet || pTAutoFmt ))
1170 : {
1171 0 : if( pTblSet )
1172 0 : SetTabSet();
1173 :
1174 0 : if( pTAutoFmt )
1175 0 : rSh.SetTableAutoFmt( *pTAutoFmt );
1176 : }
1177 0 : rSh.SetAutoUpdateCells( bIsAutoUpdateCells );
1178 : }
1179 : else // add data as fields/text
1180 : {
1181 0 : _DB_Columns aColArr;
1182 0 : if( SplitTextToColArr( aEdDbText.GetText(), aColArr, aRbAsField.IsChecked() ) )
1183 : {
1184 : // now for each data set, we can iterate over the array
1185 : // and add the data
1186 :
1187 0 : if( !rSh.IsSttPara() )
1188 0 : rSh.SwEditShell::SplitNode();
1189 0 : if( !rSh.IsEndPara() )
1190 : {
1191 0 : rSh.SwEditShell::SplitNode();
1192 0 : rSh.SwCrsrShell::Left(1,CRSR_SKIP_CHARS);
1193 : }
1194 :
1195 0 : rSh.DoUndo( sal_False );
1196 :
1197 0 : SwTxtFmtColl* pColl = 0;
1198 : {
1199 0 : String sTmplNm( aLbDbParaColl.GetSelectEntry() );
1200 0 : if( sNoTmpl != sTmplNm )
1201 : {
1202 0 : pColl = rSh.FindTxtFmtCollByName( sTmplNm );
1203 0 : if( !pColl )
1204 : {
1205 0 : sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( sTmplNm, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
1206 0 : if( USHRT_MAX != nId )
1207 0 : pColl = rSh.GetTxtCollFromPool( nId );
1208 : else
1209 0 : pColl = rSh.MakeTxtFmtColl( sTmplNm );
1210 : }
1211 0 : rSh.SetTxtFmtColl( pColl );
1212 0 : }
1213 : }
1214 :
1215 : // for adding as fields -> insert a "NextField" after
1216 : // every data set
1217 0 : SwDBFormatData aDBFormatData;
1218 0 : Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
1219 0 : Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
1220 0 : aDBFormatData.xFormatter = Reference<util::XNumberFormatter>(util::NumberFormatter::create(xContext), UNO_QUERY_THROW) ;
1221 :
1222 0 : Reference<XPropertySet> xSourceProps(xSource, UNO_QUERY);
1223 0 : if(xSourceProps.is())
1224 : {
1225 0 : Any aFormats = xSourceProps->getPropertyValue("NumberFormatsSupplier");
1226 0 : if(aFormats.hasValue())
1227 : {
1228 0 : Reference< util::XNumberFormatsSupplier> xSuppl;
1229 0 : aFormats >>= xSuppl;
1230 0 : if(xSuppl.is())
1231 : {
1232 0 : Reference< XPropertySet > xSettings = xSuppl->getNumberFormatSettings();
1233 0 : Any aNull = xSettings->getPropertyValue("NullDate");
1234 0 : aNull >>= aDBFormatData.aNullDate;
1235 0 : if(aDBFormatData.xFormatter.is())
1236 0 : aDBFormatData.xFormatter->attachNumberFormatsSupplier(xSuppl);
1237 0 : }
1238 0 : }
1239 : }
1240 0 : aDBFormatData.aLocale = LanguageTag( rSh.GetCurLang() ).getLocale();
1241 : SwDBNextSetField aNxtDBFld( (SwDBNextSetFieldType*)rSh.
1242 0 : GetFldType( 0, RES_DBNEXTSETFLD ),
1243 0 : rtl::OUString("1"), aEmptyStr, aDBData );
1244 :
1245 :
1246 0 : sal_Bool bSetCrsr = sal_True;
1247 0 : sal_uInt16 n = 0, nCols = aColArr.size();
1248 0 : ::sw::mark::IMark* pMark = NULL;
1249 0 : for( sal_Int32 i = 0 ; ; ++i )
1250 : {
1251 0 : sal_Bool bBreak = sal_False;
1252 : try
1253 : {
1254 0 : if(pSelection)
1255 : {
1256 0 : sal_Int32 nPos = 0;
1257 0 : pSelection[i] >>= nPos;
1258 0 : bBreak = !xResultSet->absolute(nPos);
1259 : }
1260 0 : else if(!i)
1261 0 : bBreak = !xResultSet->first();
1262 : }
1263 0 : catch (const Exception&)
1264 : {
1265 0 : bBreak = sal_True;
1266 : }
1267 :
1268 0 : if(bBreak)
1269 0 : break;
1270 :
1271 :
1272 0 : for( n = 0; n < nCols; ++n )
1273 : {
1274 0 : _DB_Column* pDBCol = &aColArr[ n ];
1275 0 : String sIns;
1276 0 : switch( pDBCol->eColType )
1277 : {
1278 : case _DB_Column::DB_FILLTEXT:
1279 0 : sIns = *pDBCol->DB_ColumnData.pText;
1280 0 : break;
1281 :
1282 : case _DB_Column::DB_SPLITPARA:
1283 0 : rSh.SplitNode();
1284 : // when the template is not the same as the follow template,
1285 : // the selected has to be set newly
1286 0 : if( pColl && &pColl->GetNextTxtFmtColl() != pColl )
1287 0 : rSh.SetTxtFmtColl( pColl );
1288 0 : break;
1289 :
1290 : case _DB_Column::DB_COL_FIELD:
1291 : {
1292 : SwDBField *const pFld = static_cast<SwDBField *>(
1293 0 : pDBCol->DB_ColumnData.pField->CopyField());
1294 0 : double nValue = DBL_MAX;
1295 :
1296 0 : Reference< XPropertySet > xColumnProps;
1297 0 : xCols->getByName(pDBCol->pColInfo->sColumn) >>= xColumnProps;
1298 :
1299 : pFld->SetExpansion( SwNewDBMgr::GetDBField(
1300 : xColumnProps,
1301 : aDBFormatData,
1302 0 : &nValue ) );
1303 0 : if( DBL_MAX != nValue )
1304 : {
1305 0 : Any aType = xColumnProps->getPropertyValue("Type");
1306 0 : sal_Int32 eDataType = 0;
1307 0 : aType >>= eDataType;
1308 0 : if( DataType::DATE == eDataType || DataType::TIME == eDataType ||
1309 : DataType::TIMESTAMP == eDataType)
1310 :
1311 : {
1312 0 : ::Date aStandard(1,1,1900);
1313 : ::Date aCompare(aDBFormatData.aNullDate.Day ,
1314 : aDBFormatData.aNullDate.Month,
1315 0 : aDBFormatData.aNullDate.Year);
1316 0 : if(aStandard != aCompare)
1317 0 : nValue += (aStandard - aCompare);
1318 : }
1319 0 : pFld->ChgValue( nValue, sal_True );
1320 : }
1321 0 : pFld->SetInitialized();
1322 :
1323 0 : rSh.Insert( *pFld );
1324 0 : delete pFld;
1325 : }
1326 0 : break;
1327 :
1328 : case _DB_Column::DB_COL_TEXT:
1329 : {
1330 0 : double nValue = DBL_MAX;
1331 0 : Reference< XPropertySet > xColumnProps;
1332 0 : xCols->getByName(pDBCol->pColInfo->sColumn) >>= xColumnProps;
1333 : sIns = SwNewDBMgr::GetDBField(
1334 : xColumnProps,
1335 : aDBFormatData,
1336 0 : &nValue );
1337 0 : if( pDBCol->DB_ColumnData.nFormat &&
1338 : DBL_MAX != nValue )
1339 : {
1340 : Color* pCol;
1341 0 : if(rNumFmtr.GetType(pDBCol->DB_ColumnData.nFormat) & NUMBERFORMAT_DATE)
1342 : {
1343 0 : ::Date aStandard(1,1,1900);
1344 0 : if (*rNumFmtr.GetNullDate() != aStandard)
1345 0 : nValue += (aStandard - *rNumFmtr.GetNullDate());
1346 : }
1347 : rNumFmtr.GetOutputString( nValue,
1348 : pDBCol->DB_ColumnData.nFormat,
1349 0 : sIns, &pCol );
1350 0 : }
1351 : }
1352 0 : break;
1353 : }
1354 :
1355 0 : if( sIns.Len() )
1356 0 : rSh.Insert( sIns );
1357 :
1358 0 : if( bSetCrsr && sIns.Len() )
1359 : {
1360 : // to the beginning and set a mark, so that
1361 : // the cursor can be set to the initial position
1362 : // at the end.
1363 :
1364 : rSh.SwCrsrShell::MovePara(
1365 0 : GetfnParaCurr(), GetfnParaStart() );
1366 : pMark = rSh.SetBookmark(
1367 : KeyCode(),
1368 : ::rtl::OUString(),
1369 0 : ::rtl::OUString(), IDocumentMarkAccess::UNO_BOOKMARK );
1370 : rSh.SwCrsrShell::MovePara(
1371 0 : GetfnParaCurr(), GetfnParaEnd() );
1372 0 : bSetCrsr = sal_False;
1373 : }
1374 0 : }
1375 :
1376 0 : if( !pSelection )
1377 : {
1378 0 : sal_Bool bNext = xResultSet->next();
1379 0 : if(!bNext)
1380 0 : break;
1381 : }
1382 0 : else if( i+1 >= rSelection.getLength() )
1383 0 : break;
1384 :
1385 0 : if( aRbAsField.IsChecked() )
1386 0 : rSh.Insert( aNxtDBFld );
1387 :
1388 0 : if( !rSh.IsSttPara() )
1389 0 : rSh.SwEditShell::SplitNode();
1390 :
1391 0 : if( 10 == i )
1392 0 : pWait = ::std::auto_ptr<SwWait>(new SwWait( *pView->GetDocShell(), sal_True ));
1393 : }
1394 :
1395 0 : if( !bSetCrsr && pMark != NULL)
1396 : {
1397 0 : rSh.SetMark();
1398 0 : rSh.GotoMark( pMark );
1399 0 : rSh.getIDocumentMarkAccess()->deleteMark( pMark );
1400 : break;
1401 0 : }
1402 0 : }
1403 : }
1404 : // write configuration
1405 0 : Commit();
1406 : }while( sal_False ); // middle checked loop
1407 :
1408 0 : if( bUndo )
1409 : {
1410 0 : rSh.DoUndo( sal_True );
1411 0 : rSh.AppendUndoForInsertFromDB( bAsTable );
1412 0 : rSh.EndUndo( UNDO_EMPTY );
1413 : }
1414 0 : rSh.ClearMark();
1415 0 : rSh.EndAllAction();
1416 :
1417 0 : if ( bDisposeResultSet )
1418 0 : ::comphelper::disposeComponent(xResultSet);
1419 : }
1420 :
1421 0 : void SwInsertDBColAutoPilot::SetTabSet()
1422 : {
1423 0 : SwWrtShell& rSh = pView->GetWrtShell();
1424 : const SfxPoolItem* pItem;
1425 :
1426 0 : if( pTAutoFmt )
1427 : {
1428 0 : if( pTAutoFmt->IsFrame() )
1429 : {
1430 : // border is from AutoFormat
1431 0 : pTblSet->ClearItem( RES_BOX );
1432 0 : pTblSet->ClearItem( SID_ATTR_BORDER_INNER );
1433 : }
1434 0 : if( pTAutoFmt->IsBackground() )
1435 : {
1436 0 : pTblSet->ClearItem( RES_BACKGROUND );
1437 0 : pTblSet->ClearItem( SID_ATTR_BRUSH_ROW );
1438 0 : pTblSet->ClearItem( SID_ATTR_BRUSH_TABLE );
1439 : }
1440 : }
1441 : else
1442 : {
1443 : // remove the defaults again, it makes no sense to set them
1444 0 : SvxBrushItem aBrush( RES_BACKGROUND );
1445 : static sal_uInt16 aIds[3] =
1446 : { RES_BACKGROUND, SID_ATTR_BRUSH_ROW, SID_ATTR_BRUSH_TABLE };
1447 0 : for( int i = 0; i < 3; ++i )
1448 0 : if( SFX_ITEM_SET == pTblSet->GetItemState( aIds[ i ],
1449 0 : sal_False, &pItem ) && *pItem == aBrush )
1450 0 : pTblSet->ClearItem( aIds[ i ] );
1451 : }
1452 :
1453 0 : if( SFX_ITEM_SET == pTblSet->GetItemState( FN_PARAM_TABLE_NAME, sal_False,
1454 0 : &pItem ) && ((const SfxStringItem*)pItem)->GetValue() ==
1455 0 : rSh.GetTableFmt()->GetName() )
1456 0 : pTblSet->ClearItem( FN_PARAM_TABLE_NAME );
1457 :
1458 0 : rSh.MoveTable( GetfnTableCurr(), GetfnTableStart() );
1459 0 : rSh.SetMark();
1460 0 : rSh.MoveTable( GetfnTableCurr(), GetfnTableEnd() );
1461 :
1462 0 : ItemSetToTableParam( *pTblSet, rSh );
1463 :
1464 0 : rSh.ClearMark();
1465 0 : rSh.MoveTable( GetfnTableCurr(), GetfnTableStart() );
1466 0 : }
1467 :
1468 0 : _DB_ColumnConfigData::~_DB_ColumnConfigData() {}
1469 :
1470 0 : static Sequence<rtl::OUString> lcl_createSourceNames(const String& rNodeName)
1471 : {
1472 0 : Sequence<rtl::OUString> aSourceNames(11);
1473 0 : rtl::OUString* pNames = aSourceNames.getArray();
1474 :
1475 0 : String sTmp( rNodeName );
1476 0 : const xub_StrLen nPos = sTmp.Len();
1477 : pNames[0] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1478 0 : RTL_CONSTASCII_STRINGPARAM( "/DataSource" ));
1479 : pNames[1] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1480 0 : RTL_CONSTASCII_STRINGPARAM( "/Command" ));
1481 : pNames[2] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1482 0 : RTL_CONSTASCII_STRINGPARAM( "/CommandType" ));
1483 : pNames[3] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1484 0 : RTL_CONSTASCII_STRINGPARAM( "/ColumnsToText" ));
1485 : pNames[4] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1486 0 : RTL_CONSTASCII_STRINGPARAM( "/ColumnsToTable" ));
1487 : pNames[5] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1488 0 : RTL_CONSTASCII_STRINGPARAM( "/ParaStyle" ));
1489 : pNames[6] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1490 0 : RTL_CONSTASCII_STRINGPARAM( "/TableAutoFormat" ));
1491 : pNames[7] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1492 0 : RTL_CONSTASCII_STRINGPARAM( "/IsTable" ));
1493 : pNames[8] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1494 0 : RTL_CONSTASCII_STRINGPARAM( "/IsField" ));
1495 : pNames[9] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1496 0 : RTL_CONSTASCII_STRINGPARAM( "/IsHeadlineOn" ));
1497 : pNames[10] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1498 0 : RTL_CONSTASCII_STRINGPARAM( "/IsEmptyHeadline" ));
1499 0 : return aSourceNames;
1500 : }
1501 :
1502 0 : static Sequence<rtl::OUString> lcl_CreateSubNames( const String& rSubNodeName )
1503 : {
1504 0 : Sequence<rtl::OUString> aSubSourceNames(6);
1505 0 : rtl::OUString* pNames = aSubSourceNames.getArray();
1506 0 : String sTmp( rSubNodeName );
1507 0 : const xub_StrLen nPos = sTmp.Len();
1508 : pNames[0] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1509 0 : RTL_CONSTASCII_STRINGPARAM( "/ColumnName" ));
1510 : pNames[1] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1511 0 : RTL_CONSTASCII_STRINGPARAM( "/ColumnIndex" ));
1512 : pNames[2] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1513 0 : RTL_CONSTASCII_STRINGPARAM( "/IsNumberFormat" ));
1514 : pNames[3] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1515 0 : RTL_CONSTASCII_STRINGPARAM( "/IsNumberFormatFromDataBase" ));
1516 : pNames[4] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1517 0 : RTL_CONSTASCII_STRINGPARAM( "/NumberFormat" ));
1518 : pNames[5] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1519 0 : RTL_CONSTASCII_STRINGPARAM( "/NumberFormatLocale" ));
1520 0 : return aSubSourceNames;
1521 : }
1522 :
1523 0 : static rtl::OUString lcl_CreateUniqueName(const Sequence<rtl::OUString>& aNames)
1524 : {
1525 0 : sal_Int32 nIdx = aNames.getLength();
1526 0 : const rtl::OUString* pNames = aNames.getConstArray();
1527 0 : rtl::OUString sTest("_");
1528 0 : rtl::OUString sRet;
1529 0 : while(sal_True)
1530 : {
1531 0 : sRet = sTest; sRet += rtl::OUString::valueOf(nIdx++);
1532 0 : sal_Bool bFound = sal_False;
1533 0 : for(sal_Int32 i = 0; i < aNames.getLength(); i++)
1534 : {
1535 0 : if(pNames[i] == sRet)
1536 : {
1537 0 : bFound = sal_True;
1538 0 : break;
1539 : }
1540 : }
1541 0 : if(!bFound)
1542 0 : break;
1543 : }
1544 0 : return sRet;
1545 : }
1546 :
1547 0 : void SwInsertDBColAutoPilot::Notify( const ::com::sun::star::uno::Sequence< rtl::OUString >& ) {}
1548 :
1549 0 : void SwInsertDBColAutoPilot::Commit()
1550 : {
1551 0 : Sequence <rtl::OUString> aNames = GetNodeNames(rtl::OUString());
1552 0 : const rtl::OUString* pNames = aNames.getArray();
1553 : //remove entries that contain this data source + table at first
1554 0 : for(sal_Int32 nNode = 0; nNode < aNames.getLength(); nNode++)
1555 : {
1556 0 : Sequence<rtl::OUString> aSourceNames(2);
1557 0 : rtl::OUString* pSourceNames = aSourceNames.getArray();
1558 0 : pSourceNames[0] = pNames[nNode];
1559 0 : pSourceNames[0] += "/DataSource";
1560 0 : pSourceNames[1] = pNames[nNode];
1561 0 : pSourceNames[1] += "/Command";
1562 0 : Sequence<Any> aSourceProperties = GetProperties(aSourceNames);
1563 0 : const Any* pSourceProps = aSourceProperties.getArray();
1564 0 : rtl::OUString sSource, sCommand;
1565 0 : pSourceProps[0] >>= sSource;
1566 0 : pSourceProps[1] >>= sCommand;
1567 0 : if(sSource.equals(aDBData.sDataSource) && sCommand.equals(aDBData.sCommand))
1568 : {
1569 0 : Sequence<rtl::OUString> aElements(1);
1570 0 : aElements.getArray()[0] = pNames[nNode];
1571 0 : ClearNodeElements(rtl::OUString(), aElements);
1572 : }
1573 0 : }
1574 :
1575 0 : aNames = GetNodeNames(rtl::OUString());
1576 0 : rtl::OUString sNewNode = lcl_CreateUniqueName(aNames);
1577 0 : Sequence<rtl::OUString> aNodeNames = lcl_createSourceNames(sNewNode);
1578 0 : Sequence<PropertyValue> aValues(aNodeNames.getLength());
1579 0 : PropertyValue* pValues = aValues.getArray();
1580 0 : const rtl::OUString* pNodeNames = aNodeNames.getConstArray();
1581 0 : rtl::OUString sSlash("/");
1582 0 : for(sal_Int32 i = 0; i < aNodeNames.getLength(); i++)
1583 : {
1584 0 : pValues[i].Name = sSlash;
1585 0 : pValues[i].Name += pNodeNames[i];
1586 : }
1587 :
1588 0 : pValues[0].Value <<= rtl::OUString(aDBData.sDataSource);
1589 0 : pValues[1].Value <<= rtl::OUString(aDBData.sCommand);
1590 0 : pValues[2].Value <<= aDBData.nCommandType;
1591 0 : pValues[3].Value <<= rtl::OUString(aEdDbText.GetText());
1592 :
1593 0 : String sTmp;
1594 0 : for( sal_uInt16 n = 0, nCnt = aLbTableCol.GetEntryCount(); n < nCnt; ++n )
1595 0 : ( sTmp += aLbTableCol.GetEntry( n ) ) += '\x0a';
1596 :
1597 0 : if( sTmp.Len() )
1598 0 : pValues[4].Value <<= rtl::OUString(sTmp);
1599 :
1600 0 : if( sNoTmpl != (sTmp = aLbDbParaColl.GetSelectEntry()) )
1601 0 : pValues[5].Value <<= rtl::OUString(sTmp);
1602 :
1603 0 : if( pTAutoFmt )
1604 0 : pValues[6].Value <<= rtl::OUString(pTAutoFmt->GetName());
1605 :
1606 0 : const Type& rBoolType = ::getBooleanCppuType();
1607 0 : sal_Bool bTmp = aRbAsTable.IsChecked();
1608 0 : pValues[7].Value.setValue(&bTmp, rBoolType);
1609 :
1610 0 : bTmp = aRbAsField.IsChecked();
1611 0 : pValues[8].Value.setValue(&bTmp, rBoolType);
1612 :
1613 0 : bTmp = aCbTableHeadon.IsChecked();
1614 0 : pValues[9].Value.setValue(&bTmp, rBoolType);
1615 :
1616 0 : bTmp = aRbHeadlEmpty.IsChecked();
1617 0 : pValues[10].Value.setValue(&bTmp, rBoolType);
1618 :
1619 0 : SetSetProperties(rtl::OUString(), aValues);
1620 :
1621 0 : sNewNode += "/ColumnSet";
1622 0 : rtl::OUString sDelim("/__");
1623 :
1624 0 : LanguageType ePrevLang = (LanguageType)-1;
1625 0 : rtl::OUString sPrevLang;
1626 :
1627 0 : SvNumberFormatter& rNFmtr = *pView->GetWrtShell().GetNumberFormatter();
1628 0 : for(sal_uInt16 nCol = 0; nCol < aDBColumns.size(); nCol++)
1629 : {
1630 0 : rtl::OUString sColumnNode = sNewNode;
1631 0 : SwInsDBColumn* pColumn = aDBColumns[nCol];
1632 0 : String sColumnInsertNode(sColumnNode);
1633 0 : sColumnInsertNode += sDelim;
1634 0 : if( nCol < 100 )
1635 0 : sColumnInsertNode += '0';
1636 0 : if( nCol < 10 )
1637 0 : sColumnInsertNode += '0';
1638 0 : sColumnInsertNode += String::CreateFromInt32( nCol );
1639 :
1640 0 : Sequence <rtl::OUString> aSubNodeNames = lcl_CreateSubNames(sColumnInsertNode);
1641 0 : Sequence<PropertyValue> aSubValues(aSubNodeNames.getLength());
1642 0 : PropertyValue* pSubValues = aSubValues.getArray();
1643 0 : const rtl::OUString* pSubNodeNames = aSubNodeNames.getConstArray();
1644 : sal_Int32 i;
1645 :
1646 0 : for( i = 0; i < aSubNodeNames.getLength(); i++)
1647 0 : pSubValues[i].Name = pSubNodeNames[i];
1648 0 : pSubValues[0].Value <<= pColumn->sColumn;
1649 0 : pSubValues[1].Value <<= i;
1650 :
1651 0 : sal_Bool bVal = pColumn->bHasFmt;
1652 0 : pSubValues[2].Value.setValue(&bVal, rBoolType);
1653 0 : bVal = pColumn->bIsDBFmt;
1654 0 : pSubValues[3].Value.setValue(&bVal, rBoolType);
1655 :
1656 0 : SwStyleNameMapper::FillUIName( RES_POOLCOLL_STANDARD, sTmp );
1657 0 : const SvNumberformat* pNF = rNFmtr.GetEntry( pColumn->nUsrNumFmt );
1658 : LanguageType eLang;
1659 0 : if( pNF )
1660 : {
1661 0 : pSubValues[4].Value <<= rtl::OUString(pNF->GetFormatstring());
1662 0 : eLang = pNF->GetLanguage();
1663 : }
1664 : else
1665 : {
1666 0 : pSubValues[4].Value <<= rtl::OUString(sTmp);
1667 0 : eLang = GetAppLanguage();
1668 : }
1669 :
1670 0 : if( eLang != ePrevLang )
1671 : {
1672 : /* FIXME-BCP47: handle language tags! */
1673 0 : lang::Locale aLocale( LanguageTag( eLang ).getLocale());
1674 : /* umm.. what's this string anyway, "Country-Language" instead of
1675 : * "Language-Country" ??? */
1676 0 : (( sPrevLang = aLocale.Country ) += rtl::OUString( '-' )) += aLocale.Language;
1677 0 : ePrevLang = eLang;
1678 : }
1679 :
1680 0 : pSubValues[5].Value <<= sPrevLang;
1681 0 : SetSetProperties(sColumnNode, aSubValues);
1682 0 : }
1683 0 : }
1684 :
1685 0 : void SwInsertDBColAutoPilot::Load()
1686 : {
1687 0 : Sequence <rtl::OUString> aNames = GetNodeNames(rtl::OUString());
1688 0 : const rtl::OUString* pNames = aNames.getArray();
1689 0 : SvNumberFormatter& rNFmtr = *pView->GetWrtShell().GetNumberFormatter();
1690 0 : for(sal_Int32 nNode = 0; nNode < aNames.getLength(); nNode++)
1691 : {
1692 : //search for entries with the appropriate data source and table
1693 0 : Sequence<rtl::OUString> aSourceNames = lcl_createSourceNames(pNames[nNode]);
1694 :
1695 0 : Sequence< Any> aDataSourceProps = GetProperties(aSourceNames);
1696 0 : const Any* pDataSourceProps = aDataSourceProps.getConstArray();
1697 0 : rtl::OUString sSource, sCommand;
1698 : sal_Int16 nCommandType;
1699 0 : pDataSourceProps[0] >>= sSource;
1700 0 : pDataSourceProps[1] >>= sCommand;
1701 0 : pDataSourceProps[2] >>= nCommandType;
1702 0 : if(sSource.equals(aDBData.sDataSource) && sCommand.equals(aDBData.sCommand))
1703 : {
1704 0 : _DB_ColumnConfigData* pNewData = new _DB_ColumnConfigData;
1705 0 : pNewData->sSource = sSource;
1706 0 : pNewData->sTable = sCommand;
1707 :
1708 0 : pDataSourceProps[3] >>= pNewData->sEdit;
1709 0 : pDataSourceProps[4] >>= pNewData->sTblList;
1710 0 : pDataSourceProps[5] >>= pNewData->sTmplNm;
1711 0 : pDataSourceProps[6] >>= pNewData->sTAutoFmtNm;
1712 0 : if(pDataSourceProps[7].hasValue())
1713 0 : pNewData->bIsTable = *(sal_Bool*)pDataSourceProps[7].getValue();
1714 0 : if(pDataSourceProps[8].hasValue())
1715 0 : pNewData->bIsField = *(sal_Bool*)pDataSourceProps[8].getValue();
1716 0 : if(pDataSourceProps[9].hasValue())
1717 0 : pNewData->bIsHeadlineOn = *(sal_Bool*)pDataSourceProps[9].getValue();
1718 0 : if(pDataSourceProps[10].hasValue())
1719 0 : pNewData->bIsEmptyHeadln = *(sal_Bool*)pDataSourceProps[10].getValue();
1720 :
1721 0 : rtl::OUString sSubNodeName(pNames[nNode]);
1722 0 : sSubNodeName += "/ColumnSet/";
1723 0 : Sequence <rtl::OUString> aSubNames = GetNodeNames(sSubNodeName);
1724 0 : const rtl::OUString* pSubNames = aSubNames.getConstArray();
1725 0 : for(sal_Int32 nSub = 0; nSub < aSubNames.getLength(); nSub++)
1726 : {
1727 0 : rtl::OUString sSubSubNodeName(sSubNodeName);
1728 0 : sSubSubNodeName += pSubNames[nSub];
1729 0 : Sequence <rtl::OUString> aSubNodeNames = lcl_CreateSubNames(sSubSubNodeName);
1730 0 : Sequence< Any> aSubProps = GetProperties(aSubNodeNames);
1731 0 : const Any* pSubProps = aSubProps.getConstArray();
1732 :
1733 0 : rtl::OUString sColumn;
1734 0 : pSubProps[0] >>= sColumn;
1735 : //check for existance of the loaded column name
1736 0 : sal_Bool bFound = sal_False;
1737 0 : for(sal_uInt16 nRealColumn = 0; nRealColumn < aDBColumns.size(); nRealColumn++)
1738 : {
1739 0 : if(aDBColumns[nRealColumn]->sColumn == sColumn)
1740 : {
1741 0 : bFound = sal_True;
1742 0 : break;
1743 : }
1744 : }
1745 0 : if(!bFound)
1746 0 : continue;
1747 0 : sal_Int16 nIndex = 0;
1748 0 : pSubProps[1] >>= nIndex;
1749 0 : SwInsDBColumn* pInsDBColumn = new SwInsDBColumn(sColumn, nIndex);
1750 0 : if(pSubProps[2].hasValue())
1751 0 : pInsDBColumn->bHasFmt = *(sal_Bool*)pSubProps[2].getValue();
1752 0 : if(pSubProps[3].hasValue())
1753 0 : pInsDBColumn->bIsDBFmt = *(sal_Bool*)pSubProps[3].getValue();
1754 :
1755 0 : pSubProps[4] >>= pInsDBColumn->sUsrNumFmt;
1756 0 : rtl::OUString sNumberFormatLocale;
1757 0 : pSubProps[5] >>= sNumberFormatLocale;
1758 :
1759 : /* FIXME-BCP47: handle language tags, and cope with the wrong
1760 : * Country-Language string that
1761 : * SwInsertDBColAutoPilot::Commit() writes so far! */
1762 0 : lang::Locale aLocale;
1763 0 : aLocale.Language = sNumberFormatLocale.copy(0, 2);
1764 0 : aLocale.Country = sNumberFormatLocale.copy(3, 2);
1765 0 : pInsDBColumn->eUsrNumFmtLng = LanguageTag( aLocale ).getLanguageType();
1766 :
1767 : pInsDBColumn->nUsrNumFmt = rNFmtr.GetEntryKey( pInsDBColumn->sUsrNumFmt,
1768 0 : pInsDBColumn->eUsrNumFmtLng );
1769 :
1770 :
1771 0 : pNewData->aDBColumns.insert(pInsDBColumn);
1772 0 : }
1773 0 : sal_uInt16 n = 0;
1774 0 : String sTmp( pNewData->sTblList );
1775 0 : if( sTmp.Len() )
1776 : {
1777 0 : do {
1778 0 : String sEntry( sTmp.GetToken( 0, '\x0a', n ) );
1779 : //preselect column - if they still exist!
1780 0 : if(aLbTblDbColumn.GetEntryPos(sEntry) != LISTBOX_ENTRY_NOTFOUND)
1781 : {
1782 0 : aLbTableCol.InsertEntry( sEntry );
1783 0 : aLbTblDbColumn.RemoveEntry( sEntry );
1784 0 : }
1785 0 : } while( n < sTmp.Len() );
1786 :
1787 0 : if( !aLbTblDbColumn.GetEntryCount() )
1788 : {
1789 0 : aIbDbcolAllTo.Enable( sal_False );
1790 0 : aIbDbcolOneTo.Enable( sal_False );
1791 : }
1792 0 : aIbDbcolOneFrom.Enable( sal_True );
1793 0 : aIbDbcolAllFrom.Enable( sal_True );
1794 : }
1795 0 : aEdDbText.SetText( pNewData->sEdit );
1796 :
1797 0 : sTmp = pNewData->sTmplNm;
1798 0 : if( sTmp.Len() )
1799 0 : aLbDbParaColl.SelectEntry( sTmp );
1800 : else
1801 0 : aLbDbParaColl.SelectEntryPos( 0 );
1802 :
1803 0 : delete pTAutoFmt, pTAutoFmt = 0;
1804 0 : sTmp = pNewData->sTAutoFmtNm;
1805 0 : if( sTmp.Len() )
1806 : {
1807 : // then load the AutoFmt file and look for Autoformat first
1808 0 : SwTableAutoFmtTbl aAutoFmtTbl;
1809 0 : aAutoFmtTbl.Load();
1810 0 : for( sal_uInt16 nAutoFmt = aAutoFmtTbl.size(); nAutoFmt; )
1811 0 : if( sTmp == aAutoFmtTbl[ --nAutoFmt ].GetName() )
1812 : {
1813 0 : pTAutoFmt = new SwTableAutoFmt( aAutoFmtTbl[ nAutoFmt ] );
1814 0 : break;
1815 0 : }
1816 : }
1817 :
1818 0 : aRbAsTable.Check( pNewData->bIsTable );
1819 0 : aRbAsField.Check( pNewData->bIsField );
1820 0 : aRbAsText.Check( !pNewData->bIsTable && !pNewData->bIsField );
1821 :
1822 0 : aCbTableHeadon.Check( pNewData->bIsHeadlineOn );
1823 0 : aRbHeadlColnms.Check( !pNewData->bIsEmptyHeadln );
1824 0 : aRbHeadlEmpty.Check( pNewData->bIsEmptyHeadln );
1825 0 : HeaderHdl(&aCbTableHeadon);
1826 :
1827 : // now copy the user defined Numberformat strings to the
1828 : // Shell. Then only these are available as ID
1829 0 : for( n = 0; n < aDBColumns.size() ; ++n )
1830 : {
1831 0 : SwInsDBColumn& rSet = *aDBColumns[ n ];
1832 0 : for( sal_uInt16 m = 0; m < pNewData->aDBColumns.size() ; ++m )
1833 : {
1834 0 : SwInsDBColumn& rGet = *pNewData->aDBColumns[ m ];
1835 0 : if(rGet.sColumn == rSet.sColumn)
1836 : {
1837 0 : if( rGet.bHasFmt && !rGet.bIsDBFmt )
1838 : {
1839 0 : rSet.bIsDBFmt = sal_False;
1840 : rSet.nUsrNumFmt = rNFmtr.GetEntryKey( rGet.sUsrNumFmt,
1841 0 : rGet.eUsrNumFmtLng );
1842 0 : if( NUMBERFORMAT_ENTRY_NOT_FOUND == rSet.nUsrNumFmt )
1843 : {
1844 : sal_Int32 nCheckPos;
1845 : short nType;
1846 : rNFmtr.PutEntry( rGet.sUsrNumFmt, nCheckPos, nType,
1847 0 : rSet.nUsrNumFmt, rGet.eUsrNumFmtLng );
1848 : }
1849 : }
1850 0 : break;
1851 : }
1852 : }
1853 : }
1854 :
1855 : // when the cursor is inside of a table, table must NEVER be selectable
1856 0 : if( !aRbAsTable.IsEnabled() && aRbAsTable.IsChecked() )
1857 0 : aRbAsField.Check( sal_True );
1858 0 : delete pNewData;
1859 0 : break;
1860 : }
1861 0 : }
1862 0 : }
1863 :
1864 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|