LCOV - code coverage report
Current view: top level - sw/source/ui/dbui - dbinsdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 987 0.0 %
Date: 2012-08-25 Functions: 0 37 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

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

Generated by: LCOV version 1.10