update dev300-m58
[ooovba.git] / sw / source / ui / dbui / dbinsdlg.cxx
blobefd27f336577d845d78a6ca3b1867544104f92eb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dbinsdlg.cxx,v $
10 * $Revision: 1.63 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #ifdef SW_DLLIMPLEMENTATION
34 #undef SW_DLLIMPLEMENTATION
35 #endif
37 #include "dbinsdlg.hxx"
39 #ifndef INCLUDED_MEMORY
40 #include <memory>
41 #define INCLUDED_MEMORY
42 #endif
44 #ifndef INCLUDED_FLOAT_H
45 #include <float.h>
46 #define INCLUDED_FLOAT_H
47 #endif
48 #include <hintids.hxx>
49 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
50 #include <com/sun/star/container/XNameAccess.hpp>
51 #include <com/sun/star/sdbc/XDataSource.hpp>
52 #include <com/sun/star/sdbc/XRow.hpp>
53 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
54 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
55 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
56 #include <com/sun/star/sdb/CommandType.hpp>
57 #include <com/sun/star/sdb/XColumn.hpp>
58 #include <com/sun/star/sdb/XDatabaseAccess.hpp>
59 #include <com/sun/star/sdbc/DataType.hpp>
60 #include <com/sun/star/sdbc/ResultSetType.hpp>
61 #include <com/sun/star/beans/XPropertySet.hpp>
62 #include <com/sun/star/util/XNumberFormatter.hpp>
63 #include <com/sun/star/util/XNumberFormatTypes.hpp>
64 #include <com/sun/star/sdbc/XRowSet.hpp>
65 #include <comphelper/processfactory.hxx>
66 #include <svx/langitem.hxx>
67 #include <svtools/numuno.hxx>
68 #include <svtools/stritem.hxx>
69 #include <vcl/msgbox.hxx>
70 #include <vcl/svapp.hxx>
71 #ifndef __SV_MNEMONIC_HXX
72 #include <vcl/mnemonic.hxx>
73 #endif
74 #include <svtools/style.hxx>
75 #include <svtools/zformat.hxx>
76 #include <svx/htmlmode.hxx>
77 #include <svx/unolingu.hxx>
78 #include <sfx2/app.hxx>
79 #include <svtools/itemset.hxx>
80 #include <svx/brshitem.hxx>
81 #include <svx/boxitem.hxx>
82 #include <svx/rulritem.hxx>
83 #include <swdbtoolsclient.hxx>
84 #ifndef _SWTABLEREP_HXX //autogen
85 #include <tabledlg.hxx>
86 #endif
87 #include <fmtclds.hxx>
88 #include <tabcol.hxx>
89 #include <uiitems.hxx>
90 #include <viewopt.hxx>
91 #include <uitool.hxx>
92 #include <wrtsh.hxx>
93 #ifndef _WVIEW_HXX
94 #include <wview.hxx>
95 #endif
96 #ifndef _DOCSH_HXX
97 #include <docsh.hxx>
98 #endif
99 #ifndef _DBMGR_HXX
100 #include <dbmgr.hxx>
101 #endif
102 #include <tblafmt.hxx>
103 #include <cellatr.hxx>
104 #include <swtable.hxx>
105 #include <dbfld.hxx>
106 #include <fmtcol.hxx>
107 #include <section.hxx>
108 #include <swwait.hxx>
109 #include <modcfg.hxx>
110 #include <swmodule.hxx>
111 #include <poolfmt.hxx>
112 #include <crsskip.hxx>
114 #ifndef _DBINSDLG_HRC
115 #include <dbinsdlg.hrc>
116 #endif
117 #ifndef _DBUI_HRC
118 #include <dbui.hrc>
119 #endif
121 #ifndef _CMDID_H
122 #include <cmdid.h>
123 #endif
124 #ifndef _HELPID_H
125 #include <helpid.h>
126 #endif
127 #include <cfgid.h>
128 #include <SwStyleNameMapper.hxx>
129 #include <comphelper/uno3.hxx>
130 #include "tabsh.hxx"
131 #include "swabstdlg.hxx"
132 #include "table.hrc"
133 #include <unomid.h>
134 #include <IDocumentMarkAccess.hxx>
137 namespace swui
139 SwAbstractDialogFactory * GetFactory();
142 using namespace ::com::sun::star;
143 using namespace ::com::sun::star::uno;
144 using namespace ::com::sun::star::container;
145 using namespace ::com::sun::star::lang;
146 using namespace ::com::sun::star::sdb;
147 using namespace ::com::sun::star::sdbc;
148 using namespace ::com::sun::star::sdbcx;
149 using namespace ::com::sun::star::beans;
151 // tblafmt.hxx
152 SV_IMPL_PTRARR( _SwTableAutoFmtTbl, SwTableAutoFmt* )
154 const char cDBFldStart = '<';
155 const char cDBFldEnd = '>';
157 // Hilfsstruktur fuers einfuegen von Datenbankspalten als Felder oder Text
158 struct _DB_Column
160 enum ColType { DB_FILLTEXT, DB_COL_FIELD, DB_COL_TEXT, DB_SPLITPARA } eColType;
162 union {
163 String* pText;
164 SwField* pField;
165 ULONG nFormat;
166 } DB_ColumnData;
167 const SwInsDBColumn* pColInfo;
169 _DB_Column()
171 pColInfo = 0;
172 DB_ColumnData.pText = 0;
173 eColType = DB_SPLITPARA;
176 _DB_Column( const String& rTxt )
178 pColInfo = 0;
179 DB_ColumnData.pText = new String( rTxt );
180 eColType = DB_FILLTEXT;
183 _DB_Column( const SwInsDBColumn& rInfo, ULONG nFormat )
185 pColInfo = &rInfo;
186 DB_ColumnData.nFormat = nFormat;
187 eColType = DB_COL_TEXT;
190 _DB_Column( const SwInsDBColumn& rInfo, SwDBField& rFld )
192 pColInfo = &rInfo;
193 DB_ColumnData.pField = &rFld;
194 eColType = DB_COL_FIELD;
197 ~_DB_Column()
199 if( DB_COL_FIELD == eColType )
200 delete DB_ColumnData.pField;
201 else if( DB_FILLTEXT == eColType )
202 delete DB_ColumnData.pText;
206 typedef _DB_Column* _DB_ColumnPtr;
207 SV_DECL_PTRARR_DEL( _DB_Columns, _DB_ColumnPtr, 32, 32 )
208 SV_IMPL_PTRARR( _DB_Columns, _DB_ColumnPtr )
210 SV_IMPL_OP_PTRARR_SORT( SwInsDBColumns, SwInsDBColumnPtr )
212 /* \f */
214 #define DBCOLUMN_CONFIG_VERSION1 1
215 #define DBCOLUMN_CONFIG_VERSION DBCOLUMN_CONFIG_VERSION1
216 #define DBCOLUMN_MAXDATA 5
218 struct _DB_ColumnConfigData
220 SwInsDBColumns aDBColumns;
221 rtl::OUString sSource, sTable, sEdit, sTblList, sTmplNm, sTAutoFmtNm;
222 BOOL bIsTable : 1,
223 bIsField : 1,
224 bIsHeadlineOn : 1,
225 bIsEmptyHeadln : 1;
227 _DB_ColumnConfigData()
229 bIsTable = bIsHeadlineOn = TRUE;
230 bIsField = bIsEmptyHeadln = FALSE;
233 ~_DB_ColumnConfigData();
234 private:
235 _DB_ColumnConfigData( const _DB_ColumnConfigData& );
236 _DB_ColumnConfigData& operator =( const _DB_ColumnConfigData& );
239 /* \f */
241 int SwInsDBColumn::operator<( const SwInsDBColumn& rCmp ) const
243 return 0 > GetAppCollator().compareString( sColumn, rCmp.sColumn );
245 /* ---------------------------------------------------------------------------
247 ---------------------------------------------------------------------------*/
248 SwInsertDBColAutoPilot::SwInsertDBColAutoPilot( SwView& rView,
249 Reference<XDataSource> xDataSource,
250 Reference<sdbcx::XColumnsSupplier> xColSupp,
251 const SwDBData& rData )
252 : SfxModalDialog( rView.GetWindow(), SW_RES( DLG_AP_INSERT_DB_SEL )),
253 ConfigItem(C2U("Office.Writer/InsertData/DataSet"), CONFIG_MODE_DELAYED_UPDATE),
254 aFtInsertData( this, SW_RES( FT_INSERT_DATA )),
255 aRbAsTable( this, SW_RES( RB_AS_TABLE )),
256 aRbAsField( this, SW_RES( RB_AS_FIELD )),
257 aRbAsText( this, SW_RES( RB_AS_TEXT )),
259 aFlHead( this, SW_RES( FL_HEAD )),
260 aFtDbColumn( this, SW_RES( FT_DB_COLUMN )),
262 aLbTblDbColumn( this, SW_RES( LB_TBL_DB_COLUMN )),
263 aLbTxtDbColumn( this, SW_RES( LB_TXT_DB_COLUMN )),
265 aFlFormat( this, SW_RES( FL_FORMAT )),
266 aRbDbFmtFromDb( this, SW_RES( RB_DBFMT_FROM_DB )),
267 aRbDbFmtFromUsr( this, SW_RES( RB_DBFMT_FROM_USR )),
268 aLbDbFmtFromUsr( this, &rView, SW_RES( LB_DBFMT_FROM_USR )),
270 aIbDbcolToEdit( this, SW_RES( IB_DBCOL_TOEDIT )),
271 aEdDbText( this, SW_RES( ED_DB_TEXT )),
272 aFtDbParaColl( this, SW_RES( FT_DB_PARA_COLL )),
273 aLbDbParaColl( this, SW_RES( LB_DB_PARA_COLL )),
275 aIbDbcolAllTo( this, SW_RES( IB_DBCOL_ALL_TO )),
276 aIbDbcolOneTo( this, SW_RES( IB_DBCOL_ONE_TO )),
277 aIbDbcolOneFrom( this, SW_RES( IB_DBCOL_ONE_FROM )),
278 aIbDbcolAllFrom( this, SW_RES( IB_DBCOL_ALL_FROM )),
279 aFtTableCol( this, SW_RES( FT_TABLE_COL )),
280 aLbTableCol( this, SW_RES( LB_TABLE_COL )),
281 aCbTableHeadon( this, SW_RES( CB_TABLE_HEADON )),
282 aRbHeadlColnms( this, SW_RES( RB_HEADL_COLNMS )),
283 aRbHeadlEmpty( this, SW_RES( RB_HEADL_EMPTY )),
284 aPbTblFormat( this, SW_RES( PB_TBL_FORMAT )),
285 aPbTblAutofmt( this, SW_RES( PB_TBL_AUTOFMT )),
287 aBtOk( this, SW_RES( BT_OK )),
288 aBtCancel( this, SW_RES( BT_CANCEL )),
289 aBtHelp( this, SW_RES( BT_HELP )),
291 aFlBottom( this, SW_RES( FL_BOTTOM )),
293 aDBData(rData),
295 aOldNumFmtLnk( aLbDbFmtFromUsr.GetSelectHdl() ),
296 sNoTmpl( SW_RES( STR_NOTEMPL )),
297 pView( &rView ),
298 pTAutoFmt( 0 ),
299 pTblSet( 0 ),
300 pRep( 0 )
302 FreeResource();
304 nGBFmtLen = aFlFormat.GetText().Len();
306 if(xColSupp.is())
308 SwWrtShell& rSh = pView->GetWrtShell();
309 Locale aDocLocale( SvxCreateLocale( rSh.GetCurLang() ));
310 SvNumberFormatter* pNumFmtr = rSh.GetNumberFormatter();
311 SvNumberFormatsSupplierObj* pNumFmt = new SvNumberFormatsSupplierObj( pNumFmtr );
312 Reference< util::XNumberFormatsSupplier > xDocNumFmtsSupplier = pNumFmt;
313 Reference< util::XNumberFormats > xDocNumberFormats = xDocNumFmtsSupplier->getNumberFormats();
314 Reference< util::XNumberFormatTypes > xDocNumberFormatTypes(xDocNumberFormats, UNO_QUERY);
316 Reference<XPropertySet> xSourceProps(xDataSource, UNO_QUERY);
317 Reference< util::XNumberFormats > xNumberFormats;
318 if(xSourceProps.is())
320 Any aFormats = xSourceProps->getPropertyValue(C2U("NumberFormatsSupplier"));
321 if(aFormats.hasValue())
323 Reference< util::XNumberFormatsSupplier> xSuppl;
324 aFormats >>= xSuppl;
325 if(xSuppl.is())
327 xNumberFormats = xSuppl->getNumberFormats( );
331 Reference <XNameAccess> xCols = xColSupp->getColumns();
332 Sequence<rtl::OUString> aColNames = xCols->getElementNames();
333 const rtl::OUString* pColNames = aColNames.getConstArray();
334 long nCount = aColNames.getLength();
335 for (long n = 0; n < nCount; n++)
337 SwInsDBColumn* pNew = new SwInsDBColumn( pColNames[n], (USHORT)n );
338 Any aCol = xCols->getByName(pColNames[n]);
339 Reference <XPropertySet> xCol;
340 aCol >>= xCol;
341 Any aType = xCol->getPropertyValue(C2S("Type"));
342 sal_Int32 eDataType = 0;
343 aType >>= eDataType;
344 switch(eDataType)
346 case DataType::BIT:
347 case DataType::BOOLEAN:
348 case DataType::TINYINT:
349 case DataType::SMALLINT:
350 case DataType::INTEGER:
351 case DataType::BIGINT:
352 case DataType::FLOAT:
353 case DataType::REAL:
354 case DataType::DOUBLE:
355 case DataType::NUMERIC:
356 case DataType::DECIMAL:
357 case DataType::DATE:
358 case DataType::TIME:
359 case DataType::TIMESTAMP:
361 pNew->bHasFmt = TRUE;
362 Any aFormat = xCol->getPropertyValue(C2U("FormatKey"));
363 if(aFormat.hasValue())
365 sal_Int32 nFmt = 0;
366 aFormat >>= nFmt;
367 if(xNumberFormats.is())
371 Reference<XPropertySet> xNumProps = xNumberFormats->getByKey( nFmt );
372 Any aFormatVal = xNumProps->getPropertyValue(C2U("FormatString"));
373 Any aLocale = xNumProps->getPropertyValue(C2U("Locale"));
374 rtl::OUString sFormat;
375 aFormatVal >>= sFormat;
376 lang::Locale aLoc;
377 aLocale >>= aLoc;
378 long nKey = xDocNumberFormats->queryKey( sFormat, aLoc, sal_True);
379 if(nKey < 0)
381 nKey = xDocNumberFormats->addNew( sFormat, aLoc );
383 pNew->nDBNumFmt = nKey;
385 catch(const Exception& )
387 DBG_ERROR("illegal number format key");
391 else
393 pNew->nDBNumFmt = SwNewDBMgr::GetDbtoolsClient().getDefaultNumberFormat(xCol,
394 xDocNumberFormatTypes, aDocLocale);
398 break;
400 if( !aDBColumns.Insert( pNew ))
402 ASSERT( !this, "Spaltenname mehrfach vergeben?" );
403 delete pNew;
408 // Absatzvorlagen-ListBox fuellen
410 SfxStyleSheetBasePool* pPool = pView->GetDocShell()->GetStyleSheetPool();
411 pPool->SetSearchMask( SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL );
412 aLbDbParaColl.InsertEntry( sNoTmpl );
414 const SfxStyleSheetBase* pBase = pPool->First();
415 while( pBase )
417 aLbDbParaColl.InsertEntry( pBase->GetName() );
418 pBase = pPool->Next();
420 aLbDbParaColl.SelectEntryPos( 0 );
423 // steht der Cursor in einer Tabelle, darf NIE Tabelle auswaehlbar sein
424 if( pView->GetWrtShell().GetTableFmt() )
426 aRbAsTable.Enable( FALSE );
427 aRbAsField.Check( TRUE );
428 aRbDbFmtFromDb.Check( TRUE );
430 else
432 aRbAsTable.Check( TRUE );
433 aRbDbFmtFromDb.Check( TRUE );
434 aIbDbcolOneFrom.Enable( FALSE );
435 aIbDbcolAllFrom.Enable( FALSE );
438 aRbAsTable.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, PageHdl ));
439 aRbAsField.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, PageHdl ));
440 aRbAsText.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, PageHdl ));
442 aRbDbFmtFromDb.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, DBFormatHdl ));
443 aRbDbFmtFromUsr.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, DBFormatHdl ));
445 aPbTblFormat.SetClickHdl(LINK(this, SwInsertDBColAutoPilot, TblFmtHdl ));
446 aPbTblAutofmt.SetClickHdl(LINK(this, SwInsertDBColAutoPilot, AutoFmtHdl ));
448 aIbDbcolAllTo.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
449 aIbDbcolOneTo.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
450 aIbDbcolOneFrom.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
451 aIbDbcolAllFrom.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
452 aIbDbcolToEdit.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, TblToFromHdl ));
454 aCbTableHeadon.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, HeaderHdl ));
455 aRbHeadlColnms.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, HeaderHdl ));
456 aRbHeadlEmpty.SetClickHdl( LINK(this, SwInsertDBColAutoPilot, HeaderHdl ));
458 aLbTxtDbColumn.SetSelectHdl( LINK( this, SwInsertDBColAutoPilot, SelectHdl ));
459 aLbTblDbColumn.SetSelectHdl( LINK( this, SwInsertDBColAutoPilot, SelectHdl ));
460 aLbDbFmtFromUsr.SetSelectHdl( LINK( this, SwInsertDBColAutoPilot, SelectHdl ));
461 aLbTableCol.SetSelectHdl( LINK( this, SwInsertDBColAutoPilot, SelectHdl ));
463 aLbTxtDbColumn.SetDoubleClickHdl( LINK( this, SwInsertDBColAutoPilot, DblClickHdl ));
464 aLbTblDbColumn.SetDoubleClickHdl( LINK( this, SwInsertDBColAutoPilot, DblClickHdl ));
465 aLbTableCol.SetDoubleClickHdl( LINK( this, SwInsertDBColAutoPilot, DblClickHdl ));
467 for( USHORT n = 0; n < aDBColumns.Count(); ++n )
469 const String& rS = aDBColumns[ n ]->sColumn;
470 aLbTblDbColumn.InsertEntry( rS, n );
471 aLbTxtDbColumn.InsertEntry( rS, n );
473 aLbTxtDbColumn.SelectEntryPos( 0 );
474 aLbTblDbColumn.SelectEntryPos( 0 );
476 // read configuration
477 Load();
479 // Controls initialisieren:
480 PageHdl( aRbAsTable.IsChecked() ? &aRbAsTable : &aRbAsField );
482 /* ---------------------------------------------------------------------------
484 ---------------------------------------------------------------------------*/
485 SwInsertDBColAutoPilot::~SwInsertDBColAutoPilot()
487 delete pTblSet;
488 delete pRep;
490 // delete pConfig;
491 delete pTAutoFmt;
493 /* ---------------------------------------------------------------------------
495 ---------------------------------------------------------------------------*/
496 IMPL_LINK( SwInsertDBColAutoPilot, PageHdl, Button*, pButton )
498 BOOL bShowTbl = pButton == &aRbAsTable;
500 String sTxt( pButton->GetText() );
501 aFlHead.SetText( MnemonicGenerator::EraseAllMnemonicChars( sTxt ) );
503 aLbTxtDbColumn.Show( !bShowTbl );
504 aIbDbcolToEdit.Show( !bShowTbl );
505 aEdDbText.Show( !bShowTbl );
506 aFtDbParaColl.Show( !bShowTbl );
507 aLbDbParaColl.Show( !bShowTbl );
509 aLbTblDbColumn.Show( bShowTbl );
510 aIbDbcolAllTo.Show( bShowTbl );
511 aIbDbcolOneTo.Show( bShowTbl );
512 aIbDbcolOneFrom.Show( bShowTbl );
513 aIbDbcolAllFrom.Show( bShowTbl );
514 aFtTableCol.Show( bShowTbl );
515 aLbTableCol.Show( bShowTbl );
516 aCbTableHeadon.Show( bShowTbl );
517 aRbHeadlColnms.Show( bShowTbl );
518 aRbHeadlEmpty.Show( bShowTbl );
519 aPbTblFormat.Show( bShowTbl );
520 aPbTblAutofmt.Show( bShowTbl );
522 if( bShowTbl )
523 aPbTblFormat.Enable( 0 != aLbTableCol.GetEntryCount() );
525 SelectHdl( bShowTbl ? &aLbTblDbColumn : &aLbTxtDbColumn );
527 return 0;
529 /* ---------------------------------------------------------------------------
531 ---------------------------------------------------------------------------*/
532 IMPL_LINK( SwInsertDBColAutoPilot, DBFormatHdl, Button*, pButton )
534 USHORT nFndPos;
535 ListBox& rBox = aRbAsTable.IsChecked()
536 ? ( 0 == aLbTableCol.GetEntryData( 0 )
537 ? aLbTblDbColumn
538 : aLbTableCol )
539 : aLbTxtDbColumn;
541 SwInsDBColumn aSrch( rBox.GetSelectEntry(), 0 );
542 aDBColumns.Seek_Entry( &aSrch, &nFndPos );
544 BOOL bFromDB = &aRbDbFmtFromDb == pButton;
545 aDBColumns[ nFndPos ]->bIsDBFmt = bFromDB;
546 aLbDbFmtFromUsr.Enable( !bFromDB );
548 return 0;
550 /* ---------------------------------------------------------------------------
552 ---------------------------------------------------------------------------*/
553 IMPL_LINK( SwInsertDBColAutoPilot, TblToFromHdl, Button*, pButton )
555 BOOL bChgEnable = TRUE, bEnableTo = TRUE, bEnableFrom = TRUE;
556 aLbTblDbColumn.SetUpdateMode( FALSE );
557 aLbTableCol.SetUpdateMode( FALSE );
559 if( pButton == &aIbDbcolAllTo )
561 bEnableTo = FALSE;
563 USHORT n, nInsPos = aLbTableCol.GetSelectEntryPos(),
564 nCnt = aLbTblDbColumn.GetEntryCount();
565 if( LISTBOX_APPEND == nInsPos )
566 for( n = 0; n < nCnt; ++n )
567 aLbTableCol.InsertEntry( aLbTblDbColumn.GetEntry( n ),
568 LISTBOX_APPEND );
569 else
570 for( n = 0; n < nCnt; ++n, ++nInsPos )
571 aLbTableCol.InsertEntry( aLbTblDbColumn.GetEntry( n ), nInsPos );
572 aLbTblDbColumn.Clear();
573 aLbTableCol.SelectEntryPos( nInsPos );
574 aLbTblDbColumn.SelectEntryPos( LISTBOX_APPEND );
576 else if( pButton == &aIbDbcolOneTo &&
577 LISTBOX_ENTRY_NOTFOUND != aLbTblDbColumn.GetSelectEntryPos() )
579 USHORT nInsPos = aLbTableCol.GetSelectEntryPos(),
580 nDelPos = aLbTblDbColumn.GetSelectEntryPos(),
581 nTopPos = aLbTblDbColumn.GetTopEntry();
582 aLbTableCol.InsertEntry( aLbTblDbColumn.GetEntry( nDelPos ), nInsPos );
583 aLbTblDbColumn.RemoveEntry( nDelPos );
585 aLbTableCol.SelectEntryPos( nInsPos );
586 if( nDelPos >= aLbTblDbColumn.GetEntryCount() )
587 nDelPos = aLbTblDbColumn.GetEntryCount() - 1;
588 aLbTblDbColumn.SelectEntryPos( nDelPos );
589 aLbTblDbColumn.SetTopEntry( nTopPos );
591 bEnableTo = 0 != aLbTblDbColumn.GetEntryCount();
593 else if( pButton == &aIbDbcolOneFrom )
595 if( LISTBOX_ENTRY_NOTFOUND != aLbTableCol.GetSelectEntryPos() )
597 USHORT nFndPos, nInsPos,
598 nDelPos = aLbTableCol.GetSelectEntryPos(),
599 nTopPos = aLbTableCol.GetTopEntry();
601 // die richtige InsertPos suchen!!
602 SwInsDBColumn aSrch( aLbTableCol.GetEntry( nDelPos ), 0 );
603 aDBColumns.Seek_Entry( &aSrch, &nFndPos );
604 if( !nFndPos || nFndPos == aDBColumns.Count()-1 )
605 nInsPos = nFndPos;
606 else
608 nInsPos = LISTBOX_ENTRY_NOTFOUND;
609 while( ++nFndPos < aDBColumns.Count() &&
610 LISTBOX_ENTRY_NOTFOUND == (nInsPos = aLbTblDbColumn.
611 GetEntryPos( String(aDBColumns[ nFndPos ]->sColumn ))) )
615 aLbTblDbColumn.InsertEntry( aSrch.sColumn, nInsPos );
616 aLbTableCol.RemoveEntry( nDelPos );
618 if( nInsPos >= aLbTblDbColumn.GetEntryCount() )
619 nInsPos = aLbTblDbColumn.GetEntryCount() - 1;
620 aLbTblDbColumn.SelectEntryPos( nInsPos );
622 if( nDelPos >= aLbTableCol.GetEntryCount() )
623 nDelPos = aLbTableCol.GetEntryCount() - 1;
624 aLbTableCol.SelectEntryPos( nDelPos );
625 aLbTableCol.SetTopEntry( nTopPos );
627 else
628 bEnableTo = 0 != aLbTblDbColumn.GetEntryCount();
630 bEnableFrom = 0 != aLbTableCol.GetEntryCount();
632 else if( pButton == &aIbDbcolAllFrom )
634 bEnableFrom = FALSE;
636 aLbTblDbColumn.Clear();
637 aLbTableCol.Clear();
638 for( USHORT n = 0; n < aDBColumns.Count(); ++n )
639 aLbTblDbColumn.InsertEntry( aDBColumns[ n ]->sColumn, n );
640 aLbTblDbColumn.SelectEntryPos( 0 );
642 else if( pButton == &aIbDbcolToEdit )
644 bChgEnable = FALSE;
645 // Daten ins Edit moven:
646 String aFld( aLbTxtDbColumn.GetSelectEntry() );
647 if( aFld.Len() )
649 String aStr( aEdDbText.GetText() );
650 USHORT nPos = (USHORT)aEdDbText.GetSelection().Min();
651 USHORT nSel = USHORT(aEdDbText.GetSelection().Max()) - nPos;
652 if( nSel )
653 // dann loesche erstmal die bestehende Selektion
654 aStr.Erase( nPos, nSel );
656 aFld.Insert( cDBFldStart, 0 );
657 aFld += cDBFldEnd;
658 if( aStr.Len() )
660 if( nPos ) // ein Space davor
662 sal_Unicode c = aStr.GetChar( nPos-1 );
663 if( '\n' != c && '\r' != c )
664 aFld.Insert( ' ', 0 );
666 if( nPos < aStr.Len() ) // ein Space dahinter
668 sal_Unicode c = aStr.GetChar( nPos );
669 if( '\n' != c && '\r' != c )
670 aFld += ' ';
674 aStr.Insert( aFld, nPos );
675 aEdDbText.SetText( aStr );
676 nPos = nPos + aFld.Len();
677 aEdDbText.SetSelection( Selection( nPos ));
681 if( bChgEnable )
683 aIbDbcolOneTo.Enable( bEnableTo );
684 aIbDbcolAllTo.Enable( bEnableTo );
685 aIbDbcolOneFrom.Enable( bEnableFrom );
686 aIbDbcolAllFrom.Enable( bEnableFrom );
688 aRbDbFmtFromDb.Enable( FALSE );
689 aRbDbFmtFromUsr.Enable( FALSE );
690 aLbDbFmtFromUsr.Enable( FALSE );
692 aPbTblFormat.Enable( bEnableFrom );
694 aLbTblDbColumn.SetUpdateMode( TRUE );
695 aLbTableCol.SetUpdateMode( TRUE );
697 return 0;
699 /* ---------------------------------------------------------------------------
701 ---------------------------------------------------------------------------*/
702 IMPL_LINK( SwInsertDBColAutoPilot, DblClickHdl, ListBox*, pBox )
704 Button* pButton = 0;
705 if( pBox == &aLbTxtDbColumn )
706 pButton = &aIbDbcolToEdit;
707 else if( pBox == &aLbTblDbColumn && aIbDbcolOneTo.IsEnabled() )
708 pButton = &aIbDbcolOneTo;
709 else if( pBox == &aLbTableCol && aIbDbcolOneFrom.IsEnabled() )
710 pButton = &aIbDbcolOneFrom;
712 if( pButton )
713 TblToFromHdl( pButton );
715 return 0;
717 /* ---------------------------------------------------------------------------
719 ---------------------------------------------------------------------------*/
720 IMPL_LINK( SwInsertDBColAutoPilot, TblFmtHdl, PushButton*, pButton )
722 SwWrtShell& rSh = pView->GetWrtShell();
723 BOOL bNewSet = FALSE;
724 if( !pTblSet )
726 bNewSet = TRUE;
727 pTblSet = new SfxItemSet( rSh.GetAttrPool(), SwuiGetUITableAttrRange() );
729 //Ersteinmal die einfachen Attribute besorgen.
730 pTblSet->Put( SfxStringItem( FN_PARAM_TABLE_NAME, rSh.GetUniqueTblName() ));
731 pTblSet->Put( SfxUInt16Item( FN_PARAM_TABLE_HEADLINE, 1 ) );
733 pTblSet->Put( SfxUInt16Item( SID_BACKGRND_DESTINATION,
734 rSh.GetViewOptions()->GetTblDest() ));
736 SvxBrushItem aBrush( RES_BACKGROUND );
737 pTblSet->Put( aBrush );
738 pTblSet->Put( aBrush, SID_ATTR_BRUSH_ROW );
739 pTblSet->Put( aBrush, SID_ATTR_BRUSH_TABLE );
741 SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
742 // Tabellenvariante, wenn mehrere Tabellenzellen selektiert
743 aBoxInfo.SetTable( TRUE );
744 // Abstandsfeld immer anzeigen
745 aBoxInfo.SetDist( TRUE);
746 // Minimalgroesse in Tabellen und Absaetzen setzen
747 aBoxInfo.SetMinDist( FALSE );
748 // Default-Abstand immer setzen
749 aBoxInfo.SetDefDist( MIN_BORDER_DIST );
750 // Einzelne Linien koennen nur in Tabellen DontCare-Status haben
751 aBoxInfo.SetValid( VALID_DISABLE, TRUE );
752 pTblSet->Put( aBoxInfo );
754 SwGetCurColNumPara aPara;
755 const USHORT nNum = rSh.GetCurColNum( &aPara );
756 long nWidth;
758 if( nNum )
760 nWidth = aPara.pPrtRect->Width();
761 const SwFmtCol& rCol = aPara.pFrmFmt->GetCol();
762 const SwColumns& rCols = rCol.GetColumns();
764 //nStart und nEnd initialisieren fuer nNum == 0
765 long nWidth1 = 0,
766 nStart1 = 0,
767 nEnd1 = nWidth;
768 for( USHORT i = 0; i < nNum; ++i )
770 SwColumn* pCol = rCols[i];
771 nStart1 = pCol->GetLeft() + nWidth1;
772 nWidth1 += (long)rCol.CalcColWidth( i, (USHORT)nWidth );
773 nEnd1 = nWidth1 - pCol->GetRight();
775 if(nStart1 || nEnd1 != nWidth)
776 nWidth = nEnd1 - nStart1;
778 else
779 nWidth = rSh.GetAnyCurRect(
780 FRMTYPE_FLY_ANY & rSh.GetFrmType( 0, TRUE )
781 ? RECT_FLY_PRT_EMBEDDED
782 : RECT_PAGE_PRT ).Width();
784 SwTabCols aTabCols;
785 aTabCols.SetRight( nWidth );
786 aTabCols.SetRightMax( nWidth );
787 pRep = new SwTableRep( aTabCols, FALSE );
788 pRep->SetAlign( text::HoriOrientation::NONE );
789 pRep->SetSpace( nWidth );
790 pRep->SetWidth( nWidth );
791 pRep->SetWidthPercent( 100 );
792 pTblSet->Put( SwPtrItem( FN_TABLE_REP, pRep ));
794 pTblSet->Put( SfxUInt16Item( SID_HTML_MODE,
795 ::GetHtmlMode( pView->GetDocShell() )));
798 if( aLbTableCol.GetEntryCount() != pRep->GetAllColCount() )
800 // Anzahl der Spalten hat sich geaendert: dann muessen die
801 // TabCols angepasst werden
802 long nWidth = pRep->GetWidth();
803 USHORT nCols = aLbTableCol.GetEntryCount() - 1;
804 SwTabCols aTabCols( nCols );
805 aTabCols.SetRight( nWidth );
806 aTabCols.SetRightMax( nWidth );
807 if( nCols )
808 for( USHORT n = 0, nStep = (USHORT)(nWidth / (nCols+1)), nW = nStep;
809 n < nCols; ++n, nW = nW + nStep )
811 aTabCols.Insert( nW, FALSE, n );
813 delete pRep;
814 pRep = new SwTableRep( aTabCols, FALSE );
815 pRep->SetAlign( text::HoriOrientation::NONE );
816 pRep->SetSpace( nWidth );
817 pRep->SetWidth( nWidth );
818 pRep->SetWidthPercent( 100 );
819 pTblSet->Put( SwPtrItem( FN_TABLE_REP, pRep ));
822 SwAbstractDialogFactory* pFact = swui::GetFactory();
823 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
825 SfxAbstractTabDialog* pDlg = pFact->CreateSwTableTabDlg( pButton, rSh.GetAttrPool(),pTblSet, &rSh, DLG_FORMAT_TABLE );
826 DBG_ASSERT(pDlg, "Dialogdiet fail!");
827 if( RET_OK == pDlg->Execute() )
828 pTblSet->Put( *pDlg->GetOutputItemSet() );
829 else if( bNewSet )
831 delete pTblSet, pTblSet = 0;
832 delete pRep, pRep = 0;
834 delete pDlg;
836 return 0;
838 /* ---------------------------------------------------------------------------
840 ---------------------------------------------------------------------------*/
841 IMPL_LINK( SwInsertDBColAutoPilot, AutoFmtHdl, PushButton*, pButton )
843 SwAbstractDialogFactory* pFact = swui::GetFactory();
844 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
846 AbstractSwAutoFormatDlg* pDlg = pFact->CreateSwAutoFormatDlg(pButton, pView->GetWrtShellPtr(),DLG_AUTOFMT_TABLE, FALSE, pTAutoFmt);
847 DBG_ASSERT(pDlg, "Dialogdiet fail!");
848 if( RET_OK == pDlg->Execute())
849 pDlg->FillAutoFmtOfIndex( pTAutoFmt );
850 delete pDlg;
851 return 0;
853 /* ---------------------------------------------------------------------------
855 ---------------------------------------------------------------------------*/
856 IMPL_LINK( SwInsertDBColAutoPilot, SelectHdl, ListBox*, pBox )
858 ListBox* pGetBox = pBox == &aLbDbFmtFromUsr
859 ? ( aRbAsTable.IsChecked()
860 ? ( 0 == aLbTableCol.GetEntryData( 0 )
861 ? &aLbTblDbColumn
862 : &aLbTableCol )
863 : &aLbTxtDbColumn )
864 : pBox;
866 USHORT nFndPos;
867 SwInsDBColumn aSrch( pGetBox->GetSelectEntry(), 0 );
868 aDBColumns.Seek_Entry( &aSrch, &nFndPos );
870 if( pBox == &aLbDbFmtFromUsr )
872 if( aSrch.sColumn.getLength() )
874 aOldNumFmtLnk.Call( pBox );
875 aDBColumns[ nFndPos ]->nUsrNumFmt = aLbDbFmtFromUsr.GetFormat();
878 else
880 // an der FormatGroupBox den ausgewaehlten FeldNamen setzen, damit
881 // klar ist, welches Feld ueber das Format eingestellt wird!
882 String sTxt( aFlFormat.GetText().Copy( 0, nGBFmtLen ));
883 if( !aSrch.sColumn.getLength() )
885 aRbDbFmtFromDb.Enable( FALSE );
886 aRbDbFmtFromUsr.Enable( FALSE );
887 aLbDbFmtFromUsr.Enable( FALSE );
889 else
891 BOOL bEnableFmt = aDBColumns[ nFndPos ]->bHasFmt;
892 aRbDbFmtFromDb.Enable( bEnableFmt );
893 aRbDbFmtFromUsr.Enable( bEnableFmt );
895 if( bEnableFmt )
897 (( sTxt += C2S(" (" )) += String(aSrch.sColumn) ) += (sal_Unicode)')';
900 BOOL bIsDBFmt = aDBColumns[ nFndPos ]->bIsDBFmt;
901 aRbDbFmtFromDb.Check( bIsDBFmt );
902 aRbDbFmtFromUsr.Check( !bIsDBFmt );
903 aLbDbFmtFromUsr.Enable( !bIsDBFmt );
904 if( !bIsDBFmt )
905 aLbDbFmtFromUsr.SetDefFormat( aDBColumns[ nFndPos ]->nUsrNumFmt );
908 aFlFormat.SetText( sTxt );
910 // um spaeter zu wissen, welche ListBox die "aktive" war, wird sich
911 // im 1. Eintrag ein Flag gemerkt,
912 void* pPtr = pBox == &aLbTableCol ? &aLbTableCol : 0;
913 aLbTableCol.SetEntryData( 0, pPtr );
915 return 0;
917 /* ---------------------------------------------------------------------------
919 ---------------------------------------------------------------------------*/
920 IMPL_LINK( SwInsertDBColAutoPilot, HeaderHdl, Button*, pButton )
922 if( pButton == &aCbTableHeadon )
924 BOOL bEnable = aCbTableHeadon.IsChecked();
926 aRbHeadlColnms.Enable( bEnable );
927 aRbHeadlEmpty.Enable( bEnable );
929 return 0;
931 /* ---------------------------------------------------------------------------
933 ---------------------------------------------------------------------------*/
934 static void lcl_InsTextInArr( const String& rTxt, _DB_Columns& rColArr )
936 _DB_Column* pNew;
937 USHORT nSttPos = 0, nFndPos;
938 while( STRING_NOTFOUND != ( nFndPos = rTxt.Search( '\x0A', nSttPos )) )
940 if( 1 < nFndPos )
942 pNew = new _DB_Column( rTxt.Copy( nSttPos, nFndPos -1 ) );
943 rColArr.Insert( pNew, rColArr.Count() );
945 pNew = new _DB_Column;
946 rColArr.Insert( pNew, rColArr.Count() );
947 nSttPos = nFndPos + 1;
949 if( nSttPos < rTxt.Len() )
951 pNew = new _DB_Column( rTxt.Copy( nSttPos ) );
952 rColArr.Insert( pNew, rColArr.Count() );
955 /* ---------------------------------------------------------------------------
957 ---------------------------------------------------------------------------*/
958 BOOL SwInsertDBColAutoPilot::SplitTextToColArr( const String& rTxt,
959 _DB_Columns& rColArr,
960 BOOL bInsField )
962 // aus dem Text wieder die einzelnen Datenbank - Spalten erzeugen
963 // und dann in einem Array speichern
964 // Die Datenbankspalten stehen in <> und muessen im Array der Spalten
965 // vorhanden sein:
966 String sTxt( rTxt );
967 USHORT nFndPos, nEndPos, nSttPos = 0;
969 while( STRING_NOTFOUND != ( nFndPos = sTxt.Search( cDBFldStart, nSttPos )))
971 nSttPos = nFndPos + 1;
972 if( STRING_NOTFOUND != ( nEndPos = sTxt.Search( cDBFldEnd, nSttPos+1 )))
974 // Text in <> geklammert gefunden: was ist es denn:
975 SwInsDBColumn aSrch( sTxt.Copy( nSttPos, nEndPos - nSttPos ), 0);
976 if( aDBColumns.Seek_Entry( &aSrch, &nFndPos ) )
978 // das ist ein gueltiges Feld
979 // also sicher den Text "davor":
980 const SwInsDBColumn& rFndCol = *aDBColumns[ nFndPos ];
982 _DB_Column* pNew;
984 if( 1 < nSttPos )
986 ::lcl_InsTextInArr( sTxt.Copy( 0, nSttPos-1 ), rColArr );
987 sTxt.Erase( 0, nSttPos-1 );
990 sTxt.Erase( 0, (xub_StrLen)(rFndCol.sColumn.getLength() + 2) );
991 nSttPos = 0;
993 USHORT nSubType = 0;
994 ULONG nFormat;
995 if( rFndCol.bHasFmt )
997 if( rFndCol.bIsDBFmt )
998 nFormat = rFndCol.nDBNumFmt;
999 else
1001 nFormat = rFndCol.nUsrNumFmt;
1002 nSubType = nsSwExtendedSubType::SUB_OWN_FMT;
1005 else
1006 nFormat = 0;
1008 if( bInsField )
1010 SwWrtShell& rSh = pView->GetWrtShell();
1011 SwDBFieldType aFldType( rSh.GetDoc(), aSrch.sColumn,
1012 aDBData );
1013 pNew = new _DB_Column( rFndCol, *new SwDBField(
1014 (SwDBFieldType*)rSh.InsertFldType( aFldType ),
1015 nFormat ) );
1016 if( nSubType )
1017 pNew->DB_ColumnData.pField->SetSubType( nSubType );
1019 else
1020 pNew = new _DB_Column( rFndCol, nFormat );
1022 rColArr.Insert( pNew, rColArr.Count() );
1027 // den letzten Text nicht vergessen
1028 if( sTxt.Len() )
1029 ::lcl_InsTextInArr( sTxt, rColArr );
1031 return 0 != rColArr.Count();
1033 /* ---------------------------------------------------------------------------
1035 ---------------------------------------------------------------------------*/
1036 void SwInsertDBColAutoPilot::DataToDoc( const Sequence<Any>& rSelection,
1037 Reference< XDataSource> xSource,
1038 Reference< XConnection> xConnection,
1039 Reference< sdbc::XResultSet > xResultSet )
1041 const Any* pSelection = rSelection.getLength() ? rSelection.getConstArray() : 0;
1042 SwWrtShell& rSh = pView->GetWrtShell();
1044 //with the drag and drop interface no result set is initially available
1045 BOOL bDisposeResultSet = FALSE;
1046 // we don't have a cursor, so we have to create our own RowSet
1047 if ( !xResultSet.is() )
1049 xResultSet = SwNewDBMgr::createCursor(aDBData.sDataSource,aDBData.sCommand,aDBData.nCommandType,xConnection);
1050 bDisposeResultSet = xResultSet.is();
1053 Reference< sdbc::XRow > xRow(xResultSet, UNO_QUERY);
1054 if ( !xRow.is() )
1055 return;
1057 rSh.StartAllAction();
1058 BOOL bUndo = rSh.DoesUndo();
1059 if( bUndo )
1060 rSh.StartUndo( UNDO_EMPTY );
1062 BOOL bAsTable = aRbAsTable.IsChecked();
1063 SvNumberFormatter& rNumFmtr = *rSh.GetNumberFormatter();
1065 if( rSh.HasSelection() )
1066 rSh.DelRight();
1068 ::std::auto_ptr<SwWait> pWait;
1070 Reference< XColumnsSupplier > xColsSupp( xResultSet, UNO_QUERY );
1071 Reference <XNameAccess> xCols = xColsSupp->getColumns();
1073 do{ // middle checked loop!!
1074 if( bAsTable ) // Daten als Tabelle einfuegen
1076 rSh.DoUndo( FALSE );
1078 USHORT n, nRows = 0, nCols = aLbTableCol.GetEntryCount();
1079 if( aCbTableHeadon.IsChecked() )
1080 nRows++;
1082 if( pSelection )
1083 nRows = nRows + (USHORT)rSelection.getLength();
1084 else
1085 ++nRows;
1087 // bereite das Array fuer die ausgewaehlten Spalten auf
1088 SwInsDBColumns_SAR aColFlds( 255 >= nCols ? (BYTE)nCols : 255, 5 );
1089 for( n = 0; n < nCols; ++n )
1091 USHORT nFndPos;
1092 SwInsDBColumn aSrch( aLbTableCol.GetEntry( n ), 0 );
1093 if( aDBColumns.Seek_Entry( &aSrch, &nFndPos ) )
1094 aColFlds.Insert( aDBColumns[ nFndPos ], n );
1095 else {
1096 ASSERT( !this, "Datenbankspalte nicht mehr gefunden" );
1100 if( nCols != aColFlds.Count() )
1102 ASSERT( !this, "nicht alle Datenbankspalten gefunden" );
1103 nCols = aColFlds.Count();
1106 if(!nRows || !nCols)
1108 ASSERT( !this, "wrong parameters" );
1109 break;
1112 const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
1114 BOOL bHTML = 0 != (::GetHtmlMode( pView->GetDocShell() ) & HTMLMODE_ON);
1115 rSh.InsertTable(
1116 pModOpt->GetInsTblFlags(bHTML),
1117 nRows, nCols, text::HoriOrientation::FULL, (pSelection ? pTAutoFmt : 0) );
1118 rSh.MoveTable( GetfnTablePrev(), GetfnTableStart() );
1120 if( pSelection && pTblSet )
1121 SetTabSet();
1123 SfxItemSet aTblSet( rSh.GetAttrPool(), RES_BOXATR_FORMAT,
1124 RES_BOXATR_VALUE );
1125 BOOL bIsAutoUpdateCells = rSh.IsAutoUpdateCells();
1126 rSh.SetAutoUpdateCells( FALSE );
1129 if( aCbTableHeadon.IsChecked() )
1131 for( n = 0; n < nCols; ++n )
1133 if( aRbHeadlColnms.IsChecked() )
1134 rSh.SwEditShell::Insert( aColFlds[ n ]->sColumn );
1135 rSh.GoNextCell();
1138 else
1139 rSh.SetRowsToRepeat( 0 );
1141 for( sal_Int32 i = 0 ; ; ++i )
1143 BOOL bBreak = FALSE;
1146 if(pSelection)
1148 sal_Int32 nPos = 0;
1149 pSelection[i] >>= nPos;
1150 bBreak = !xResultSet->absolute(nPos);
1152 else if(!i)
1153 bBreak = !xResultSet->first();
1155 catch(const Exception& )
1157 bBreak = TRUE;
1159 if(bBreak)
1160 break;
1162 for( n = 0; n < nCols; ++n )
1164 // beim aller erstenmal KEIN GoNextCell, weil wir schon
1165 // drin stehen. Auch nicht nach dem Insert das GoNextCell,
1166 // weil am Ende eine leere Zeile einfuegt wird.
1167 if( i || n )
1168 rSh.GoNextCell();
1170 const SwInsDBColumn* pEntry = aColFlds[ n ];
1172 Reference< XColumn > xColumn;
1173 xCols->getByName(pEntry->sColumn) >>= xColumn;
1174 Reference< XPropertySet > xColumnProps( xColumn, UNO_QUERY );
1175 sal_Int32 eDataType = 0;
1176 if( xColumnProps.is() )
1178 Any aType = xColumnProps->getPropertyValue(C2U("Type"));
1179 aType >>= eDataType;
1183 if( pEntry->bHasFmt )
1185 SwTblBoxNumFormat aNumFmt(
1186 pEntry->bIsDBFmt ? pEntry->nDBNumFmt
1187 : pEntry->nUsrNumFmt );
1188 aTblSet.Put(aNumFmt);
1189 if( xColumn.is() )
1191 double fVal = xColumn->getDouble();
1192 if( xColumn->wasNull() )
1193 aTblSet.ClearItem( RES_BOXATR_VALUE );
1194 else
1196 if(rNumFmtr.GetType(aNumFmt.GetValue()) & NUMBERFORMAT_DATE)
1198 ::Date aStandard(1,1,1900);
1199 if (*rNumFmtr.GetNullDate() != aStandard)
1200 fVal += (aStandard - *rNumFmtr.GetNullDate());
1202 aTblSet.Put( SwTblBoxValue( fVal ));
1205 else
1206 aTblSet.ClearItem( RES_BOXATR_VALUE );
1207 rSh.SetTblBoxFormulaAttrs( aTblSet );
1209 //#i60207# don't insert binary data as string - creates a loop
1210 else if( DataType::BINARY == eDataType ||
1211 DataType::VARBINARY == eDataType ||
1212 DataType::LONGVARBINARY== eDataType ||
1213 DataType::SQLNULL == eDataType ||
1214 DataType::OTHER == eDataType ||
1215 DataType::OBJECT == eDataType ||
1216 DataType::DISTINCT == eDataType ||
1217 DataType::STRUCT == eDataType ||
1218 DataType::ARRAY == eDataType ||
1219 DataType::BLOB == eDataType ||
1220 DataType::CLOB == eDataType ||
1221 DataType::REF == eDataType
1224 // do nothing
1226 else
1228 rtl::OUString sVal = xColumn->getString();
1229 if(!xColumn->wasNull())
1230 rSh.SwEditShell::Insert( sVal );
1233 catch(Exception&
1234 #ifdef DBG_UTIL
1235 aExcept
1236 #endif
1239 DBG_ERROR(ByteString(String(aExcept.Message), gsl_getSystemTextEncoding()).GetBuffer());
1243 if( !pSelection )
1245 if ( !xResultSet->next() )
1246 break;
1248 else if( i+1 >= rSelection.getLength() )
1249 break;
1251 if( 10 == i )
1252 pWait = ::std::auto_ptr<SwWait>(new SwWait( *pView->GetDocShell(), TRUE ));
1255 rSh.MoveTable( GetfnTableCurr(), GetfnTableStart() );
1256 if( !pSelection && ( pTblSet || pTAutoFmt ))
1258 if( pTblSet )
1259 SetTabSet();
1261 if( pTAutoFmt )
1262 rSh.SetTableAutoFmt( *pTAutoFmt );
1264 rSh.SetAutoUpdateCells( bIsAutoUpdateCells );
1266 else // Daten als Felder/Text einfuegen
1268 _DB_Columns aColArr;
1269 if( SplitTextToColArr( aEdDbText.GetText(), aColArr, aRbAsField.IsChecked() ) )
1271 // jetzt kann bei jedem Datensatz einfach ueber das Array iteriert
1272 // und die Daten eingefuegt werden
1274 if( !rSh.IsSttPara() )
1275 rSh.SwEditShell::SplitNode();
1276 if( !rSh.IsEndPara() )
1278 rSh.SwEditShell::SplitNode();
1279 rSh.SwCrsrShell::Left(1,CRSR_SKIP_CHARS);
1282 rSh.DoUndo( FALSE );
1284 SwTxtFmtColl* pColl = 0;
1286 String sTmplNm( aLbDbParaColl.GetSelectEntry() );
1287 if( sNoTmpl != sTmplNm )
1289 pColl = rSh.FindTxtFmtCollByName( sTmplNm );
1290 if( !pColl )
1292 USHORT nId = SwStyleNameMapper::GetPoolIdFromUIName( sTmplNm, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
1293 if( USHRT_MAX != nId )
1294 pColl = rSh.GetTxtCollFromPool( nId );
1295 else
1296 pColl = rSh.MakeTxtFmtColl( sTmplNm );
1298 rSh.SetTxtFmtColl( pColl );
1302 // fuers Einfuegen als Felder -> nach jedem Datensatz ein
1303 // "NextField" einfuegen
1304 SwDBFormatData aDBFormatData;
1305 Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
1306 if( xMgr.is() )
1308 Reference<XInterface> xInstance = xMgr->createInstance( C2U( "com.sun.star.util.NumberFormatter" ));
1309 aDBFormatData.xFormatter = Reference<util::XNumberFormatter>(xInstance, UNO_QUERY) ;
1312 Reference<XPropertySet> xSourceProps(xSource, UNO_QUERY);
1313 if(xSourceProps.is())
1315 Any aFormats = xSourceProps->getPropertyValue(C2U("NumberFormatsSupplier"));
1316 if(aFormats.hasValue())
1318 Reference< util::XNumberFormatsSupplier> xSuppl;
1319 aFormats >>= xSuppl;
1320 if(xSuppl.is())
1322 Reference< XPropertySet > xSettings = xSuppl->getNumberFormatSettings();
1323 Any aNull = xSettings->getPropertyValue(C2U("NullDate"));
1324 aNull >>= aDBFormatData.aNullDate;
1325 if(aDBFormatData.xFormatter.is())
1326 aDBFormatData.xFormatter->attachNumberFormatsSupplier(xSuppl);
1330 aDBFormatData.aLocale = SvxCreateLocale( rSh.GetCurLang() );
1331 SwDBNextSetField aNxtDBFld( (SwDBNextSetFieldType*)rSh.
1332 GetFldType( 0, RES_DBNEXTSETFLD ),
1333 C2S("1"), aEmptyStr, aDBData );
1336 BOOL bSetCrsr = TRUE;
1337 USHORT n = 0, nCols = aColArr.Count();
1338 ::sw::mark::IMark* pMark = NULL;
1339 for( sal_Int32 i = 0 ; ; ++i )
1341 BOOL bBreak = FALSE;
1344 if(pSelection)
1346 sal_Int32 nPos = 0;
1347 pSelection[i] >>= nPos;
1348 bBreak = !xResultSet->absolute(nPos);
1350 else if(!i)
1351 bBreak = !xResultSet->first();
1353 catch(Exception&)
1355 bBreak = TRUE;
1358 if(bBreak)
1359 break;
1362 for( n = 0; n < nCols; ++n )
1364 _DB_Column* pDBCol = aColArr[ n ];
1365 String sIns;
1366 switch( pDBCol->eColType )
1368 case _DB_Column::DB_FILLTEXT:
1369 sIns = *pDBCol->DB_ColumnData.pText;
1370 break;
1372 case _DB_Column::DB_SPLITPARA:
1373 rSh.SplitNode();
1374 // wenn nicht die gleiche Vorlage die Follow Vorlage
1375 // ist, dann muss die ausgewaehlte neu gesetzt werden
1376 if( pColl && &pColl->GetNextTxtFmtColl() != pColl )
1377 rSh.SetTxtFmtColl( pColl );
1378 break;
1380 case _DB_Column::DB_COL_FIELD:
1382 SwDBField* pFld = (SwDBField*)pDBCol->DB_ColumnData.
1383 pField->Copy();
1384 double nValue = DBL_MAX;
1386 Reference< XPropertySet > xColumnProps;
1387 xCols->getByName(pDBCol->pColInfo->sColumn) >>= xColumnProps;
1389 pFld->SetExpansion( SwNewDBMgr::GetDBField(
1390 xColumnProps,
1391 aDBFormatData,
1392 &nValue ) );
1393 if( DBL_MAX != nValue )
1395 Any aType = xColumnProps->getPropertyValue(C2U("Type"));
1396 sal_Int32 eDataType = 0;
1397 aType >>= eDataType;
1398 if( DataType::DATE == eDataType || DataType::TIME == eDataType ||
1399 DataType::TIMESTAMP == eDataType)
1402 ::Date aStandard(1,1,1900);
1403 ::Date aCompare(aDBFormatData.aNullDate.Day ,
1404 aDBFormatData.aNullDate.Month,
1405 aDBFormatData.aNullDate.Year);
1406 if(aStandard != aCompare)
1407 nValue += (aStandard - aCompare);
1409 pFld->ChgValue( nValue, TRUE );
1411 pFld->SetInitialized();
1413 rSh.Insert( *pFld );
1414 delete pFld;
1416 break;
1418 case _DB_Column::DB_COL_TEXT:
1420 double nValue = DBL_MAX;
1421 Reference< XPropertySet > xColumnProps;
1422 xCols->getByName(pDBCol->pColInfo->sColumn) >>= xColumnProps;
1423 sIns = SwNewDBMgr::GetDBField(
1424 xColumnProps,
1425 aDBFormatData,
1426 &nValue );
1427 if( pDBCol->DB_ColumnData.nFormat &&
1428 DBL_MAX != nValue )
1430 Color* pCol;
1431 if(rNumFmtr.GetType(pDBCol->DB_ColumnData.nFormat) & NUMBERFORMAT_DATE)
1433 ::Date aStandard(1,1,1900);
1434 if (*rNumFmtr.GetNullDate() != aStandard)
1435 nValue += (aStandard - *rNumFmtr.GetNullDate());
1437 rNumFmtr.GetOutputString( nValue,
1438 pDBCol->DB_ColumnData.nFormat,
1439 sIns, &pCol );
1442 break;
1445 if( sIns.Len() )
1446 rSh.Insert( sIns );
1448 if( bSetCrsr && sIns.Len() )
1450 // zum Anfang und eine Mark setzen, damit der
1451 // Cursor am Ende wieder auf Anfangsposition
1452 // gesetzt werden kann.
1454 // rSh.SwCrsrShell::MovePara( fnParaCurr, fnParaStart );
1455 rSh.SwCrsrShell::MovePara(
1456 GetfnParaCurr(), GetfnParaStart() );
1457 pMark = rSh.SetBookmark(
1458 KeyCode(),
1459 ::rtl::OUString(),
1460 ::rtl::OUString(), IDocumentMarkAccess::UNO_BOOKMARK );
1461 // rSh.SwCrsrShell::MovePara( fnParaCurr, fnParaEnd );
1462 rSh.SwCrsrShell::MovePara(
1463 GetfnParaCurr(), GetfnParaEnd() );
1464 bSetCrsr = FALSE;
1468 if( !pSelection )
1470 BOOL bNext = xResultSet->next();
1471 if(!bNext)
1472 break;
1474 else if( i+1 >= rSelection.getLength() )
1475 break;
1477 if( aRbAsField.IsChecked() )
1478 rSh.Insert( aNxtDBFld );
1480 if( !rSh.IsSttPara() )
1481 rSh.SwEditShell::SplitNode();
1483 if( 10 == i )
1484 pWait = ::std::auto_ptr<SwWait>(new SwWait( *pView->GetDocShell(), TRUE ));
1487 if( !bSetCrsr && pMark != NULL)
1489 rSh.SetMark();
1490 rSh.GotoMark( pMark );
1491 rSh.getIDocumentMarkAccess()->deleteMark( pMark );
1492 break;
1496 // write configuration
1497 Commit();
1498 }while( FALSE ); // middle checked loop
1500 if( bUndo )
1502 rSh.DoUndo( TRUE );
1503 rSh.AppendUndoForInsertFromDB( bAsTable );
1504 rSh.EndUndo( UNDO_EMPTY );
1506 rSh.ClearMark();
1507 rSh.EndAllAction();
1509 if ( bDisposeResultSet )
1510 ::comphelper::disposeComponent(xResultSet);
1512 void SwInsertDBColAutoPilot::SetTabSet()
1514 SwWrtShell& rSh = pView->GetWrtShell();
1515 const SfxPoolItem* pItem;
1517 if( pTAutoFmt )
1519 if( pTAutoFmt->IsFrame() )
1521 // Umrandung kommt vom AutoFormat
1522 pTblSet->ClearItem( RES_BOX );
1523 pTblSet->ClearItem( SID_ATTR_BORDER_INNER );
1525 if( pTAutoFmt->IsBackground() )
1527 pTblSet->ClearItem( RES_BACKGROUND );
1528 pTblSet->ClearItem( SID_ATTR_BRUSH_ROW );
1529 pTblSet->ClearItem( SID_ATTR_BRUSH_TABLE );
1532 else
1534 // die Defaults wieder entfernen, es macht keinen Sinn sie zu setzen
1535 SvxBrushItem aBrush( RES_BACKGROUND );
1536 static USHORT __READONLY_DATA aIds[3] =
1537 { RES_BACKGROUND, SID_ATTR_BRUSH_ROW, SID_ATTR_BRUSH_TABLE };
1538 for( int i = 0; i < 3; ++i )
1539 if( SFX_ITEM_SET == pTblSet->GetItemState( aIds[ i ],
1540 FALSE, &pItem ) && *pItem == aBrush )
1541 pTblSet->ClearItem( aIds[ i ] );
1544 if( SFX_ITEM_SET == pTblSet->GetItemState( FN_PARAM_TABLE_NAME, FALSE,
1545 &pItem ) && ((const SfxStringItem*)pItem)->GetValue() ==
1546 rSh.GetTableFmt()->GetName() )
1547 pTblSet->ClearItem( FN_PARAM_TABLE_NAME );
1549 rSh.MoveTable( GetfnTableCurr(), GetfnTableStart() );
1550 rSh.SetMark();
1551 rSh.MoveTable( GetfnTableCurr(), GetfnTableEnd() );
1553 ItemSetToTableParam( *pTblSet, rSh );
1555 rSh.ClearMark();
1556 rSh.MoveTable( GetfnTableCurr(), GetfnTableStart() );
1559 /* \f */
1562 _DB_ColumnConfigData::~_DB_ColumnConfigData() {}
1564 /* -----------------------------05.12.00 16:15--------------------------------
1566 ---------------------------------------------------------------------------*/
1567 static Sequence<rtl::OUString> lcl_createSourceNames(const String& rNodeName)
1569 Sequence<rtl::OUString> aSourceNames(11);
1570 rtl::OUString* pNames = aSourceNames.getArray();
1572 String sTmp( rNodeName );
1573 const xub_StrLen nPos = sTmp.Len();
1574 pNames[0] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1575 RTL_CONSTASCII_STRINGPARAM( "/DataSource" ));
1576 pNames[1] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1577 RTL_CONSTASCII_STRINGPARAM( "/Command" ));
1578 pNames[2] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1579 RTL_CONSTASCII_STRINGPARAM( "/CommandType" ));
1580 pNames[3] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1581 RTL_CONSTASCII_STRINGPARAM( "/ColumnsToText" ));
1582 pNames[4] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1583 RTL_CONSTASCII_STRINGPARAM( "/ColumnsToTable" ));
1584 pNames[5] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1585 RTL_CONSTASCII_STRINGPARAM( "/ParaStyle" ));
1586 pNames[6] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1587 RTL_CONSTASCII_STRINGPARAM( "/TableAutoFormat" ));
1588 pNames[7] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1589 RTL_CONSTASCII_STRINGPARAM( "/IsTable" ));
1590 pNames[8] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1591 RTL_CONSTASCII_STRINGPARAM( "/IsField" ));
1592 pNames[9] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1593 RTL_CONSTASCII_STRINGPARAM( "/IsHeadlineOn" ));
1594 pNames[10] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1595 RTL_CONSTASCII_STRINGPARAM( "/IsEmptyHeadline" ));
1596 return aSourceNames;
1598 /* -----------------------------05.12.00 16:25--------------------------------
1600 ---------------------------------------------------------------------------*/
1601 static Sequence<rtl::OUString> lcl_CreateSubNames( const String& rSubNodeName )
1603 Sequence<rtl::OUString> aSubSourceNames(6);
1604 rtl::OUString* pNames = aSubSourceNames.getArray();
1605 String sTmp( rSubNodeName );
1606 const xub_StrLen nPos = sTmp.Len();
1607 pNames[0] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1608 RTL_CONSTASCII_STRINGPARAM( "/ColumnName" ));
1609 pNames[1] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1610 RTL_CONSTASCII_STRINGPARAM( "/ColumnIndex" ));
1611 pNames[2] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1612 RTL_CONSTASCII_STRINGPARAM( "/IsNumberFormat" ));
1613 pNames[3] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1614 RTL_CONSTASCII_STRINGPARAM( "/IsNumberFormatFromDataBase" ));
1615 pNames[4] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1616 RTL_CONSTASCII_STRINGPARAM( "/NumberFormat" ));
1617 pNames[5] = sTmp.ReplaceAscii( nPos, STRING_MAXLEN,
1618 RTL_CONSTASCII_STRINGPARAM( "/NumberFormatLocale" ));
1619 return aSubSourceNames;
1621 /* -----------------------------06.12.00 13:03--------------------------------
1623 ---------------------------------------------------------------------------*/
1624 static rtl::OUString lcl_CreateUniqueName(const Sequence<rtl::OUString>& aNames)
1626 sal_Int32 nIdx = aNames.getLength();
1627 const rtl::OUString* pNames = aNames.getConstArray();
1628 rtl::OUString sTest(C2U("_"));
1629 rtl::OUString sRet;
1630 while(sal_True)
1632 sRet = sTest; sRet += rtl::OUString::valueOf(nIdx++);
1633 sal_Bool bFound = sal_False;
1634 for(sal_Int32 i = 0; i < aNames.getLength(); i++)
1636 if(pNames[i] == sRet)
1638 bFound = sal_True;
1639 break;
1642 if(!bFound)
1643 break;
1645 return sRet;
1647 /* -----------------------------05.12.00 15:00--------------------------------
1649 ---------------------------------------------------------------------------*/
1650 void SwInsertDBColAutoPilot::Commit()
1652 Sequence <rtl::OUString> aNames = GetNodeNames(rtl::OUString());
1653 const rtl::OUString* pNames = aNames.getArray();
1654 //remove entries that contain this data source + table at first
1655 for(sal_Int32 nNode = 0; nNode < aNames.getLength(); nNode++)
1657 Sequence<rtl::OUString> aSourceNames(2);
1658 rtl::OUString* pSourceNames = aSourceNames.getArray();
1659 pSourceNames[0] = pNames[nNode];
1660 pSourceNames[0] += C2U("/DataSource");
1661 pSourceNames[1] = pNames[nNode];
1662 pSourceNames[1] += C2U("/Command");
1663 Sequence<Any> aSourceProperties = GetProperties(aSourceNames);
1664 const Any* pSourceProps = aSourceProperties.getArray();
1665 rtl::OUString sSource, sCommand;
1666 pSourceProps[0] >>= sSource;
1667 pSourceProps[1] >>= sCommand;
1668 if(sSource.equals(aDBData.sDataSource) && sCommand.equals(aDBData.sCommand))
1670 Sequence<rtl::OUString> aElements(1);
1671 aElements.getArray()[0] = pNames[nNode];
1672 ClearNodeElements(rtl::OUString(), aElements);
1676 aNames = GetNodeNames(rtl::OUString());
1677 rtl::OUString sNewNode = lcl_CreateUniqueName(aNames);
1678 Sequence<rtl::OUString> aNodeNames = lcl_createSourceNames(sNewNode);
1679 Sequence<PropertyValue> aValues(aNodeNames.getLength());
1680 PropertyValue* pValues = aValues.getArray();
1681 const rtl::OUString* pNodeNames = aNodeNames.getConstArray();
1682 rtl::OUString sSlash(C2U("/"));
1683 for(sal_Int32 i = 0; i < aNodeNames.getLength(); i++)
1685 pValues[i].Name = sSlash;
1686 pValues[i].Name += pNodeNames[i];
1689 pValues[0].Value <<= rtl::OUString(aDBData.sDataSource);
1690 pValues[1].Value <<= rtl::OUString(aDBData.sCommand);
1691 pValues[2].Value <<= aDBData.nCommandType;
1692 pValues[3].Value <<= rtl::OUString(aEdDbText.GetText());
1694 String sTmp;
1695 for( USHORT n = 0, nCnt = aLbTableCol.GetEntryCount(); n < nCnt; ++n )
1696 ( sTmp += aLbTableCol.GetEntry( n ) ) += '\x0a';
1698 if( sTmp.Len() )
1699 pValues[4].Value <<= rtl::OUString(sTmp);
1701 if( sNoTmpl != (sTmp = aLbDbParaColl.GetSelectEntry()) )
1702 pValues[5].Value <<= rtl::OUString(sTmp);
1704 if( pTAutoFmt )
1705 pValues[6].Value <<= rtl::OUString(pTAutoFmt->GetName());
1707 const Type& rBoolType = ::getBooleanCppuType();
1708 sal_Bool bTmp = aRbAsTable.IsChecked();
1709 pValues[7].Value.setValue(&bTmp, rBoolType);
1711 bTmp = aRbAsField.IsChecked();
1712 pValues[8].Value.setValue(&bTmp, rBoolType);
1714 bTmp = aCbTableHeadon.IsChecked();
1715 pValues[9].Value.setValue(&bTmp, rBoolType);
1717 bTmp = aRbHeadlEmpty.IsChecked();
1718 pValues[10].Value.setValue(&bTmp, rBoolType);
1720 SetSetProperties(rtl::OUString(), aValues);
1722 sNewNode += C2U("/ColumnSet");
1723 String sDelim( String::CreateFromAscii( "/__" ));
1725 LanguageType ePrevLang = (LanguageType)-1;
1726 rtl::OUString sPrevLang;
1728 SvNumberFormatter& rNFmtr = *pView->GetWrtShell().GetNumberFormatter();
1729 for(USHORT nCol = 0; nCol < aDBColumns.Count(); nCol++)
1731 rtl::OUString sColumnNode = sNewNode;
1732 SwInsDBColumn* pColumn = aDBColumns[nCol];
1733 String sColumnInsertNode(sColumnNode);
1734 sColumnInsertNode += sDelim;
1735 if( nCol < 100 )
1736 sColumnInsertNode += '0';
1737 if( nCol < 10 )
1738 sColumnInsertNode += '0';
1739 sColumnInsertNode += String::CreateFromInt32( nCol );
1741 Sequence <rtl::OUString> aSubNodeNames = lcl_CreateSubNames(sColumnInsertNode);
1742 Sequence<PropertyValue> aSubValues(aSubNodeNames.getLength());
1743 PropertyValue* pSubValues = aSubValues.getArray();
1744 const rtl::OUString* pSubNodeNames = aSubNodeNames.getConstArray();
1745 sal_Int32 i;
1747 for( i = 0; i < aSubNodeNames.getLength(); i++)
1748 pSubValues[i].Name = pSubNodeNames[i];
1749 pSubValues[0].Value <<= pColumn->sColumn;
1750 pSubValues[1].Value <<= i;
1752 sal_Bool bVal = pColumn->bHasFmt;
1753 pSubValues[2].Value.setValue(&bVal, rBoolType);
1754 bVal = pColumn->bIsDBFmt;
1755 pSubValues[3].Value.setValue(&bVal, rBoolType);
1757 SwStyleNameMapper::FillUIName( RES_POOLCOLL_STANDARD, sTmp );
1758 const SvNumberformat* pNF = rNFmtr.GetEntry( pColumn->nUsrNumFmt );
1759 LanguageType eLang;
1760 if( pNF )
1762 pSubValues[4].Value <<= rtl::OUString(pNF->GetFormatstring());
1763 eLang = pNF->GetLanguage();
1765 else
1767 pSubValues[4].Value <<= rtl::OUString(sTmp);
1768 eLang = (LanguageType)GetAppLanguage();
1771 if( eLang != ePrevLang )
1773 Locale aLocale;
1774 aLocale = SvxLanguageToLocale( aLocale, eLang );
1775 (( sPrevLang = aLocale.Country ) += rtl::OUString( '-' )) += aLocale.Language;
1776 ePrevLang = eLang;
1779 pSubValues[5].Value <<= sPrevLang;
1780 SetSetProperties(sColumnNode, aSubValues);
1783 /* -----------------------------05.12.00 15:00--------------------------------
1785 ---------------------------------------------------------------------------*/
1786 void SwInsertDBColAutoPilot::Load()
1788 Sequence <rtl::OUString> aNames = GetNodeNames(rtl::OUString());
1789 const rtl::OUString* pNames = aNames.getArray();
1790 SvNumberFormatter& rNFmtr = *pView->GetWrtShell().GetNumberFormatter();
1791 for(sal_Int32 nNode = 0; nNode < aNames.getLength(); nNode++)
1793 //search for entries with the appropriate data source and table
1794 Sequence<rtl::OUString> aSourceNames = lcl_createSourceNames(pNames[nNode]);
1796 Sequence< Any> aDataSourceProps = GetProperties(aSourceNames);
1797 const Any* pDataSourceProps = aDataSourceProps.getConstArray();
1798 rtl::OUString sSource, sCommand;
1799 sal_Int16 nCommandType;
1800 pDataSourceProps[0] >>= sSource;
1801 pDataSourceProps[1] >>= sCommand;
1802 pDataSourceProps[2] >>= nCommandType;
1803 if(sSource.equals(aDBData.sDataSource) && sCommand.equals(aDBData.sCommand))
1805 _DB_ColumnConfigData* pNewData = new _DB_ColumnConfigData;
1806 pNewData->sSource = sSource;
1807 pNewData->sTable = sCommand;
1809 pDataSourceProps[3] >>= pNewData->sEdit;
1810 pDataSourceProps[4] >>= pNewData->sTblList;
1811 pDataSourceProps[5] >>= pNewData->sTmplNm;
1812 pDataSourceProps[6] >>= pNewData->sTAutoFmtNm;
1813 if(pDataSourceProps[7].hasValue())
1814 pNewData->bIsTable = *(sal_Bool*)pDataSourceProps[7].getValue();
1815 if(pDataSourceProps[8].hasValue())
1816 pNewData->bIsField = *(sal_Bool*)pDataSourceProps[8].getValue();
1817 if(pDataSourceProps[9].hasValue())
1818 pNewData->bIsHeadlineOn = *(sal_Bool*)pDataSourceProps[9].getValue();
1819 if(pDataSourceProps[10].hasValue())
1820 pNewData->bIsEmptyHeadln = *(sal_Bool*)pDataSourceProps[10].getValue();
1822 rtl::OUString sSubNodeName(pNames[nNode]);
1823 sSubNodeName += C2U("/ColumnSet/");
1824 Sequence <rtl::OUString> aSubNames = GetNodeNames(sSubNodeName);
1825 const rtl::OUString* pSubNames = aSubNames.getConstArray();
1826 for(sal_Int32 nSub = 0; nSub < aSubNames.getLength(); nSub++)
1828 rtl::OUString sSubSubNodeName(sSubNodeName);
1829 sSubSubNodeName += pSubNames[nSub];
1830 Sequence <rtl::OUString> aSubNodeNames = lcl_CreateSubNames(sSubSubNodeName);
1831 Sequence< Any> aSubProps = GetProperties(aSubNodeNames);
1832 const Any* pSubProps = aSubProps.getConstArray();
1834 rtl::OUString sColumn;
1835 pSubProps[0] >>= sColumn;
1836 //check for existance of the loaded column name
1837 sal_Bool bFound = sal_False;
1838 for(sal_Int32 nRealColumn = 0; nRealColumn < aDBColumns.Count(); nRealColumn++)
1840 if(aDBColumns[(USHORT)nRealColumn]->sColumn == sColumn)
1842 bFound = sal_True;
1843 break;
1846 if(!bFound)
1847 continue;
1848 sal_Int16 nIndex = 0;
1849 pSubProps[1] >>= nIndex;
1850 SwInsDBColumnPtr pInsDBColumn = new SwInsDBColumn(sColumn, nIndex);
1851 if(pSubProps[2].hasValue())
1852 pInsDBColumn->bHasFmt = *(sal_Bool*)pSubProps[2].getValue();
1853 if(pSubProps[3].hasValue())
1854 pInsDBColumn->bIsDBFmt = *(sal_Bool*)pSubProps[3].getValue();
1856 pSubProps[4] >>= pInsDBColumn->sUsrNumFmt;
1857 rtl::OUString sNumberFormatLocale;
1858 pSubProps[5] >>= sNumberFormatLocale;
1860 Locale aLocale;
1861 aLocale.Language = sNumberFormatLocale.copy(0, 2);
1862 aLocale.Country = sNumberFormatLocale.copy(3, 2);
1863 pInsDBColumn->eUsrNumFmtLng = SvxLocaleToLanguage( aLocale );
1865 pInsDBColumn->nUsrNumFmt = rNFmtr.GetEntryKey( pInsDBColumn->sUsrNumFmt,
1866 pInsDBColumn->eUsrNumFmtLng );
1868 // pInsDBColumn->nDBNumFmt
1870 pNewData->aDBColumns.Insert(pInsDBColumn);
1872 USHORT n = 0;
1873 String sTmp( pNewData->sTblList );
1874 if( sTmp.Len() )
1876 do {
1877 String sEntry( sTmp.GetToken( 0, '\x0a', n ) );
1878 //preselect column - if they still exist!
1879 if(aLbTblDbColumn.GetEntryPos(sEntry) != LISTBOX_ENTRY_NOTFOUND)
1881 aLbTableCol.InsertEntry( sEntry );
1882 aLbTblDbColumn.RemoveEntry( sEntry );
1884 } while( n < sTmp.Len() );
1886 if( !aLbTblDbColumn.GetEntryCount() )
1888 aIbDbcolAllTo.Enable( FALSE );
1889 aIbDbcolOneTo.Enable( FALSE );
1891 aIbDbcolOneFrom.Enable( TRUE );
1892 aIbDbcolAllFrom.Enable( TRUE );
1894 aEdDbText.SetText( pNewData->sEdit );
1896 sTmp = pNewData->sTmplNm;
1897 if( sTmp.Len() )
1898 aLbDbParaColl.SelectEntry( sTmp );
1899 else
1900 aLbDbParaColl.SelectEntryPos( 0 );
1902 if( pTAutoFmt )
1903 delete pTAutoFmt, pTAutoFmt = 0;
1904 sTmp = pNewData->sTAutoFmtNm;
1905 if( sTmp.Len() )
1907 // dann erstmal die AutoFmt-Datei laden und das Autoformat suchen
1908 SwTableAutoFmtTbl aAutoFmtTbl;
1909 aAutoFmtTbl.Load();
1910 for( USHORT nAutoFmt = aAutoFmtTbl.Count(); nAutoFmt; )
1911 if( sTmp == aAutoFmtTbl[ --nAutoFmt ]->GetName() )
1913 pTAutoFmt = new SwTableAutoFmt( *aAutoFmtTbl[ nAutoFmt ] );
1914 break;
1918 aRbAsTable.Check( pNewData->bIsTable );
1919 aRbAsField.Check( pNewData->bIsField );
1920 aRbAsText.Check( !pNewData->bIsTable && !pNewData->bIsField );
1922 aCbTableHeadon.Check( pNewData->bIsHeadlineOn );
1923 aRbHeadlColnms.Check( !pNewData->bIsEmptyHeadln );
1924 aRbHeadlEmpty.Check( pNewData->bIsEmptyHeadln );
1925 HeaderHdl(&aCbTableHeadon);
1927 // jetzt noch die benutzerdefinierten Numberformat Strings in die
1928 // Shell kopieren. Nur diese sind dann als ID verfuegbar
1929 for( n = 0; n < aDBColumns.Count() ; ++n )
1931 SwInsDBColumn& rSet = *aDBColumns[ n ];
1932 for( USHORT m = 0; m < pNewData->aDBColumns.Count() ; ++m )
1934 const SwInsDBColumn& rGet = *pNewData->aDBColumns[ m ];
1935 if(rGet.sColumn == rSet.sColumn)
1937 if( rGet.bHasFmt && !rGet.bIsDBFmt )
1939 rSet.bIsDBFmt = FALSE;
1940 rSet.nUsrNumFmt = rNFmtr.GetEntryKey( rGet.sUsrNumFmt,
1941 rGet.eUsrNumFmtLng );
1942 if( NUMBERFORMAT_ENTRY_NOT_FOUND == rSet.nUsrNumFmt )
1944 xub_StrLen nCheckPos;
1945 short nType;
1946 rNFmtr.PutEntry( (String&)rGet.sUsrNumFmt, nCheckPos, nType,
1947 rSet.nUsrNumFmt, rGet.eUsrNumFmtLng );
1950 break;
1955 // steht der Cursor in einer Tabelle, darf NIE Tabelle auswaehlbar sein
1956 if( !aRbAsTable.IsEnabled() && aRbAsTable.IsChecked() )
1957 aRbAsField.Check( TRUE );
1958 delete pNewData;
1959 break;