LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/ui/misc - UITools.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 789 0.0 %
Date: 2012-12-27 Functions: 0 42 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "UITools.hxx"
      22             : #include <sfx2/docfilt.hxx>
      23             : #include "callbacks.hxx"
      24             : #include "dbustrings.hrc"
      25             : #include "dbu_resource.hrc"
      26             : #include "dlgsave.hxx"
      27             : #include "dbtreelistbox.hxx"
      28             : #include "defaultobjectnamecheck.hxx"
      29             : #include <comphelper/extract.hxx>
      30             : #include <com/sun/star/sdb/DatabaseContext.hpp>
      31             : #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
      32             : #include <com/sun/star/sdb/XCompletedConnection.hpp>
      33             : #include <com/sun/star/sdbc/XDataSource.hpp>
      34             : #include <com/sun/star/sdb/SQLContext.hpp>
      35             : #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
      36             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      37             : #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
      38             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      39             : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
      40             : #include <com/sun/star/sdbcx/XAppend.hpp>
      41             : #include <com/sun/star/sdbc/XRow.hpp>
      42             : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
      43             : #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
      44             : #include <com/sun/star/sdbc/ColumnValue.hpp>
      45             : #include <com/sun/star/task/InteractionHandler.hpp>
      46             : #include <com/sun/star/ucb/XContent.hpp>
      47             : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      48             : #include <com/sun/star/beans/PropertyValue.hpp>
      49             : #include <com/sun/star/container/XIndexAccess.hpp>
      50             : #include <com/sun/star/container/XNameContainer.hpp>
      51             : #include <com/sun/star/ucb/InteractiveIOException.hpp>
      52             : #include <com/sun/star/sdb/XDocumentDataSource.hpp>
      53             : #include <com/sun/star/ucb/IOErrorCode.hpp>
      54             : #include <toolkit/helper/vclunohelper.hxx>
      55             : #include <toolkit/awt/vclxwindow.hxx>
      56             : #include <vcl/stdtext.hxx>
      57             : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      58             : #include <com/sun/star/beans/XPropertySet.hpp>
      59             : #include <com/sun/star/container/XNameAccess.hpp>
      60             : #include <com/sun/star/container/XContainer.hpp>
      61             : #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
      62             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      63             : #include <com/sun/star/awt/TextAlign.hpp>
      64             : #include <com/sun/star/awt/FontDescriptor.hpp>
      65             : #include <com/sun/star/awt/FontWeight.hpp>
      66             : #include <com/sun/star/awt/FontRelief.hpp>
      67             : #include <com/sun/star/awt/FontWidth.hpp>
      68             : #include <com/sun/star/frame/XModel.hpp>
      69             : #include "dlgattr.hrc"
      70             : #include "TypeInfo.hxx"
      71             : #include "FieldDescriptions.hxx"
      72             : #include <comphelper/processfactory.hxx>
      73             : #include <comphelper/stl_types.hxx>
      74             : #include <comphelper/componentcontext.hxx>
      75             : 
      76             : #include <svx/svxids.hrc>
      77             : 
      78             : #include <svl/itempool.hxx>
      79             : #include <tools/string.hxx>
      80             : #include "dbaccess_helpid.hrc"
      81             : #include <svl/itemset.hxx>
      82             : #include "sbagrid.hrc"
      83             : #include <svl/rngitem.hxx>
      84             : #include <svl/intitem.hxx>
      85             : #include <svx/algitem.hxx>
      86             : #include <svx/numinf.hxx>
      87             : #include <svl/zforlist.hxx>
      88             : #include "dlgattr.hxx"
      89             : #include <vcl/msgbox.hxx>
      90             : #include <com/sun/star/container/XChild.hpp>
      91             : #include <com/sun/star/util/NumberFormatter.hpp>
      92             : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
      93             : #include <com/sun/star/util/XNumberFormatter.hpp>
      94             : #include "dbu_misc.hrc"
      95             : #include "sqlmessage.hxx"
      96             : #include <com/sun/star/util/NumberFormat.hpp>
      97             : #include <com/sun/star/util/URL.hpp>
      98             : #include <vcl/toolbox.hxx>
      99             : #include "dlgsize.hxx"
     100             : #include <svtools/editbrowsebox.hxx>
     101             : #include <unotools/configmgr.hxx>
     102             : #include <svtools/helpopt.hxx>
     103             : #include <ucbhelper/content.hxx>
     104             : #include <tools/urlobj.hxx>
     105             : #include <tools/diagnose_ex.h>
     106             : #include <svl/numuno.hxx>
     107             : #include <unotools/pathoptions.hxx>
     108             : #include <svl/filenotation.hxx>
     109             : #include <svtools/fileview.hxx>
     110             : #include <connectivity/FValue.hxx>
     111             : 
     112             : #include <editeng/justifyitem.hxx>
     113             : 
     114             : // .........................................................................
     115             : namespace dbaui
     116             : {
     117             : // .........................................................................
     118             : using namespace ::dbtools;
     119             : using namespace ::comphelper;
     120             : using namespace ::com::sun::star;
     121             : using namespace ::com::sun::star::uno;
     122             : using namespace ::com::sun::star::task;
     123             : using namespace ::com::sun::star::sdbcx;
     124             : using namespace ::com::sun::star::sdbc;
     125             : using namespace ::com::sun::star::sdb;
     126             : using namespace ::com::sun::star::util;
     127             : using namespace ::com::sun::star::ucb;
     128             : using namespace ::com::sun::star::beans;
     129             : using namespace ::com::sun::star::container;
     130             : using namespace ::com::sun::star::lang;
     131             : using namespace ::com::sun::star::ui::dialogs;
     132             : using namespace ::svt;
     133             : using ::com::sun::star::ucb::InteractiveIOException;
     134             : using ::com::sun::star::ucb::IOErrorCode_NO_FILE;
     135             : using ::com::sun::star::ucb::IOErrorCode_NOT_EXISTING;
     136             : using ::com::sun::star::frame::XModel;
     137             : 
     138             : // -----------------------------------------------------------------------------
     139           0 : SQLExceptionInfo createConnection(  const ::rtl::OUString& _rsDataSourceName,
     140             :                                      const Reference< ::com::sun::star::container::XNameAccess >& _xDatabaseContext,
     141             :                                     const Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
     142             :                                     Reference< ::com::sun::star::lang::XEventListener>& _rEvtLst,
     143             :                                     Reference< ::com::sun::star::sdbc::XConnection>& _rOUTConnection )
     144             : {
     145           0 :     Reference<XPropertySet> xProp;
     146             :     try
     147             :     {
     148           0 :         xProp.set(_xDatabaseContext->getByName(_rsDataSourceName),UNO_QUERY);
     149             :     }
     150           0 :     catch(const Exception&)
     151             :     {
     152             :     }
     153           0 :     SQLExceptionInfo aInfo;
     154             : 
     155           0 :     return createConnection(xProp,_rxContext,_rEvtLst,_rOUTConnection);
     156             : }
     157             : // -----------------------------------------------------------------------------
     158           0 : SQLExceptionInfo createConnection(  const Reference< ::com::sun::star::beans::XPropertySet>& _xDataSource,
     159             :                                     const Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
     160             :                                     Reference< ::com::sun::star::lang::XEventListener>& _rEvtLst,
     161             :                                     Reference< ::com::sun::star::sdbc::XConnection>& _rOUTConnection )
     162             : {
     163           0 :     SQLExceptionInfo aInfo;
     164           0 :     if ( !_xDataSource.is() )
     165             :     {
     166             :         OSL_FAIL("createConnection: coult not retrieve the data source!");
     167             :         return aInfo;
     168             :     }
     169             : 
     170           0 :     ::rtl::OUString sPwd, sUser;
     171           0 :     sal_Bool bPwdReq = sal_False;
     172             :     try
     173             :     {
     174           0 :         _xDataSource->getPropertyValue(PROPERTY_PASSWORD) >>= sPwd;
     175           0 :         bPwdReq = ::cppu::any2bool(_xDataSource->getPropertyValue(PROPERTY_ISPASSWORDREQUIRED));
     176           0 :         _xDataSource->getPropertyValue(PROPERTY_USER) >>= sUser;
     177             :     }
     178           0 :     catch(const Exception&)
     179             :     {
     180             :         OSL_FAIL("createConnection: error while retrieving data source properties!");
     181             :     }
     182             : 
     183             : 
     184             :     try
     185             :     {
     186           0 :         if(bPwdReq && sPwd.isEmpty())
     187             :         {   // password required, but empty -> connect using an interaction handler
     188           0 :             Reference<XCompletedConnection> xConnectionCompletion(_xDataSource, UNO_QUERY);
     189           0 :             if (!xConnectionCompletion.is())
     190             :             {
     191             :                 OSL_FAIL("createConnection: missing an interface ... need an error message here!");
     192             :             }
     193             :             else
     194             :             {   // instantiate the default SDB interaction handler
     195           0 :                 Reference< XInteractionHandler > xHandler( InteractionHandler::createWithParent(_rxContext, 0), UNO_QUERY);
     196           0 :                 _rOUTConnection = xConnectionCompletion->connectWithCompletion(xHandler);
     197           0 :             }
     198             :         }
     199             :         else
     200             :         {
     201           0 :             Reference<XDataSource> xDataSource(_xDataSource,UNO_QUERY);
     202           0 :             _rOUTConnection = xDataSource->getConnection(sUser, sPwd);
     203             :         }
     204             :         // be notified when connection is in disposing
     205           0 :         Reference< XComponent >  xComponent(_rOUTConnection, UNO_QUERY);
     206           0 :         if (xComponent.is() && _rEvtLst.is())
     207           0 :             xComponent->addEventListener(_rEvtLst);
     208             :     }
     209           0 :     catch(const SQLContext& e) { aInfo = SQLExceptionInfo(e); }
     210           0 :     catch(const SQLWarning& e) { aInfo = SQLExceptionInfo(e); }
     211           0 :     catch(const SQLException& e) { aInfo = SQLExceptionInfo(e); }
     212           0 :     catch(const Exception&) { OSL_FAIL("SbaTableQueryBrowser::OnExpandEntry: could not connect - unknown exception!"); }
     213             : 
     214           0 :     return aInfo;
     215             : }
     216             : // -----------------------------------------------------------------------------
     217           0 : Reference< XDataSource > getDataSourceByName( const ::rtl::OUString& _rDataSourceName,
     218             :     Window* _pErrorMessageParent, Reference< XComponentContext > _rxContext, ::dbtools::SQLExceptionInfo* _pErrorInfo )
     219             : {
     220           0 :     Reference< XDatabaseContext > xDatabaseContext = DatabaseContext::create(_rxContext);
     221             : 
     222           0 :     Reference< XDataSource > xDatasource;
     223           0 :     Any aError;
     224           0 :     SQLExceptionInfo aSQLError;
     225             :     try
     226             :     {
     227           0 :         xDatabaseContext->getByName( _rDataSourceName ) >>= xDatasource;
     228             :     }
     229           0 :     catch(const WrappedTargetException& e)
     230             :     {
     231           0 :         InteractiveIOException aIOException;
     232           0 :         if  (   ( e.TargetException >>= aIOException )
     233             :             &&  (   ( aIOException.Code == IOErrorCode_NO_FILE )
     234             :                 ||  ( aIOException.Code == IOErrorCode_NOT_EXISTING )
     235             :                 )
     236             :             )
     237             :         {
     238           0 :             String sErrorMessage = String( ModuleRes( STR_FILE_DOES_NOT_EXIST ) );
     239           0 :             OFileNotation aTransformer( e.Message );
     240           0 :             sErrorMessage.SearchAndReplaceAscii( "$file$", aTransformer.get( OFileNotation::N_SYSTEM ) );
     241           0 :             aSQLError = SQLExceptionInfo( sErrorMessage ).get();
     242             :         }
     243             :         else
     244             :         {
     245           0 :             aSQLError = SQLExceptionInfo( e.TargetException );
     246           0 :             if ( !aSQLError.isValid() )
     247           0 :                 aError = e.TargetException;
     248           0 :         }
     249             :     }
     250           0 :     catch( const Exception& )
     251             :     {
     252             :         DBG_UNHANDLED_EXCEPTION();
     253             :     }
     254             : 
     255           0 :     if ( xDatasource.is() )
     256           0 :         return xDatasource;
     257             : 
     258           0 :     if ( aSQLError.isValid() )
     259             :     {
     260           0 :         if ( _pErrorInfo )
     261             :         {
     262           0 :             *_pErrorInfo = aSQLError;
     263             :         }
     264             :         else
     265             :         {
     266           0 :             showError( aSQLError, _pErrorMessageParent, _rxContext );
     267             :         }
     268             :     }
     269             : 
     270           0 :     return Reference<XDataSource>();
     271             : }
     272             : // -----------------------------------------------------------------------------
     273           0 : Reference< XInterface > getDataSourceOrModel(const Reference< XInterface >& _xObject)
     274             : {
     275           0 :     Reference< XInterface > xRet;
     276           0 :     Reference<XDocumentDataSource> xDocumentDataSource(_xObject,UNO_QUERY);
     277           0 :     if ( xDocumentDataSource.is() )
     278           0 :         xRet = xDocumentDataSource->getDatabaseDocument();
     279             : 
     280           0 :     if ( !xRet.is() )
     281             :     {
     282           0 :         Reference<XOfficeDatabaseDocument> xOfficeDoc(_xObject,UNO_QUERY);
     283           0 :         if ( xOfficeDoc.is() )
     284           0 :             xRet = xOfficeDoc->getDataSource();
     285             :     }
     286             : 
     287           0 :     return xRet;
     288             : }
     289             : // -----------------------------------------------------------------------------
     290           0 : void showError(const SQLExceptionInfo& _rInfo,Window* _pParent,const Reference< XComponentContext >& _rxContext)
     291             : {
     292             :     OSL_ENSURE(_pParent,"showError: Parent window must be NOT NULL!");
     293           0 :     ::dbtools::showError(_rInfo,VCLUnoHelper::GetInterface(_pParent), _rxContext);
     294           0 : }
     295             : 
     296             : // -----------------------------------------------------------------------------
     297             : 
     298           0 : TOTypeInfoSP getTypeInfoFromType(const OTypeInfoMap& _rTypeInfo,
     299             :                                sal_Int32 _nType,
     300             :                                const ::rtl::OUString& _sTypeName,
     301             :                                const ::rtl::OUString& _sCreateParams,
     302             :                                sal_Int32 _nPrecision,
     303             :                                sal_Int32 _nScale,
     304             :                                sal_Bool _bAutoIncrement,
     305             :                                sal_Bool& _brForceToType)
     306             : {
     307           0 :     TOTypeInfoSP pTypeInfo;
     308           0 :     _brForceToType = sal_False;
     309             :     // search for type
     310           0 :     ::std::pair<OTypeInfoMap::const_iterator, OTypeInfoMap::const_iterator> aPair = _rTypeInfo.equal_range(_nType);
     311           0 :     OTypeInfoMap::const_iterator aIter = aPair.first;
     312           0 :     if(aIter != _rTypeInfo.end()) // compare with end is correct here
     313             :     {
     314           0 :         for(;aIter != aPair.second;++aIter)
     315             :         {
     316             :             // search the best matching type
     317             :     #ifdef DBG_UTIL
     318             :             ::rtl::OUString sDBTypeName         = aIter->second->aTypeName;         (void)sDBTypeName;
     319             :             sal_Int32       nDBTypePrecision    = aIter->second->nPrecision;        (void)nDBTypePrecision;
     320             :             sal_Int32       nDBTypeScale        = aIter->second->nMaximumScale;     (void)nDBTypeScale;
     321             :             sal_Bool        bDBAutoIncrement    = aIter->second->bAutoIncrement;    (void)bDBAutoIncrement;
     322             :     #endif
     323           0 :             if  (   (
     324           0 :                         _sTypeName.isEmpty()
     325           0 :                     ||  (aIter->second->aTypeName.equalsIgnoreAsciiCase(_sTypeName))
     326             :                     )
     327             :                 &&  (
     328             :                         (
     329           0 :                                 !aIter->second->aCreateParams.getLength()
     330           0 :                             &&  _sCreateParams.isEmpty()
     331             :                         )
     332             :                     ||  (
     333           0 :                                 (aIter->second->nPrecision      >= _nPrecision)
     334           0 :                             &&  (aIter->second->nMaximumScale   >= _nScale)
     335           0 :                             &&  ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
     336             :                         )
     337             :                     )
     338             :                 )
     339           0 :                 break;
     340             :         }
     341             : 
     342           0 :         if (aIter == aPair.second)
     343             :         {
     344           0 :             for(aIter = aPair.first; aIter != aPair.second; ++aIter)
     345             :             {
     346           0 :                 sal_Int32 nPrec = aIter->second->nPrecision;
     347           0 :                 sal_Int32 nScale = aIter->second->nMaximumScale;
     348             :                 // search the best matching type (now comparing the local names)
     349           0 :                 if  (   (aIter->second->aLocalTypeName.equalsIgnoreAsciiCase(_sTypeName))
     350             :                     &&  (nPrec  >= _nPrecision)
     351             :                     &&  (nScale >= _nScale)
     352           0 :                     &&  ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
     353             :                     )
     354             :                 {
     355             :                     OSL_FAIL((  ::rtl::OString("getTypeInfoFromType: assuming column type ")
     356             :                         +=  ::rtl::OString(aIter->second->aTypeName.getStr(), aIter->second->aTypeName.getLength(), osl_getThreadTextEncoding())
     357             :                         +=  ::rtl::OString("\" (expected type name ")
     358             :                         +=  ::rtl::OString(_sTypeName.getStr(), _sTypeName.getLength(), osl_getThreadTextEncoding())
     359             :                         +=  ::rtl::OString(" matches the type's local name).")).getStr());
     360           0 :                     break;
     361             :                 }
     362             :             }
     363             :         }
     364             : 
     365           0 :         if (aIter == aPair.second)
     366             :         {   // no match for the names, no match for the local names
     367             :             // -> drop the precision and the scale restriction, accept any type with the property
     368             :             // type id (nType)
     369             : 
     370           0 :             for(aIter = aPair.first; aIter != aPair.second; ++aIter)
     371             :             {
     372             :                 // search the best matching type (now comparing the local names)
     373             : #ifdef DBG_UTIL
     374             :                 ::rtl::OUString sDBTypeName = aIter->second->aTypeName;
     375             : #endif
     376           0 :                 sal_Int32 nPrec = aIter->second->nPrecision;
     377           0 :                 sal_Int32 nScale = aIter->second->nMaximumScale;
     378           0 :                 if  (   (nPrec  >= _nPrecision)
     379             :                     &&  (nScale >= _nScale)
     380           0 :                     &&  ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
     381             :                     )
     382           0 :                     break;
     383             :             }
     384             :         }
     385           0 :         if (aIter == aPair.second)
     386             :         {
     387           0 :             if ( _bAutoIncrement )
     388             :             {
     389           0 :                 for(aIter = aPair.first; aIter != aPair.second; ++aIter)
     390             :                 {
     391             :                     // search the best matching type (now comparing the local names)
     392             : #ifdef DBG_UTIL
     393             :                     ::rtl::OUString sDBTypeName = aIter->second->aTypeName;
     394             : #endif
     395           0 :                     sal_Int32 nScale = aIter->second->nMaximumScale;
     396           0 :                     if  (   (nScale >= _nScale)
     397           0 :                         &&  (aIter->second->bAutoIncrement  == _bAutoIncrement)
     398             :                         )
     399           0 :                         break;
     400             :                 }
     401           0 :                 if ( aIter == aPair.second )
     402             :                 {
     403             :                     // try it without the auto increment flag
     404             :                     pTypeInfo = getTypeInfoFromType(_rTypeInfo,
     405             :                                    _nType,
     406             :                                    _sTypeName,
     407             :                                    _sCreateParams,
     408             :                                    _nPrecision,
     409             :                                    _nScale,
     410             :                                    sal_False,
     411           0 :                                    _brForceToType);
     412             :                 }
     413             :                 else
     414           0 :                     pTypeInfo = aIter->second;
     415             :             }
     416             :             else
     417             :             {
     418           0 :                 pTypeInfo = aPair.first->second;
     419           0 :                 _brForceToType = sal_True;
     420             :             }
     421             :         }
     422             :         else
     423           0 :             pTypeInfo = aIter->second;
     424             :     }
     425             :     else
     426             :     {
     427           0 :         ::comphelper::TStringMixEqualFunctor aCase(sal_False);
     428             :         // search for typeinfo where the typename is equal _sTypeName
     429           0 :         OTypeInfoMap::const_iterator typeInfoLoop = _rTypeInfo.begin();
     430           0 :         OTypeInfoMap::const_iterator typeInfoEnd  = _rTypeInfo.end();
     431           0 :         for (; typeInfoLoop != typeInfoEnd; ++typeInfoLoop)
     432             :         {
     433           0 :             if ( aCase( typeInfoLoop->second->getDBName() , _sTypeName ) )
     434             :             {
     435           0 :                 pTypeInfo = typeInfoLoop->second;
     436           0 :                 break;
     437             :             }
     438             :         }
     439             :     }
     440             : 
     441             :     OSL_ENSURE(pTypeInfo, "getTypeInfoFromType: no type info found for this type!");
     442           0 :     return pTypeInfo;
     443             : }
     444             : // -----------------------------------------------------------------------------
     445           0 : void fillTypeInfo(  const Reference< ::com::sun::star::sdbc::XConnection>& _rxConnection,
     446             :                     const String& _rsTypeNames,
     447             :                     OTypeInfoMap& _rTypeInfoMap,
     448             :                     ::std::vector<OTypeInfoMap::iterator>& _rTypeInfoIters)
     449             : {
     450           0 :     if(!_rxConnection.is())
     451           0 :         return;
     452           0 :     Reference< XResultSet> xRs = _rxConnection->getMetaData ()->getTypeInfo ();
     453           0 :     Reference< XRow> xRow(xRs,UNO_QUERY);
     454             :     // Information for a single SQL type
     455           0 :     if(xRs.is())
     456             :     {
     457           0 :         static const ::rtl::OUString aB1(RTL_CONSTASCII_USTRINGPARAM(" [ "));
     458           0 :         static const ::rtl::OUString aB2(RTL_CONSTASCII_USTRINGPARAM(" ]"));
     459           0 :         Reference<XResultSetMetaData> xResultSetMetaData = Reference<XResultSetMetaDataSupplier>(xRs,UNO_QUERY)->getMetaData();
     460           0 :         ::connectivity::ORowSetValue aValue;
     461           0 :         ::std::vector<sal_Int32> aTypes;
     462           0 :         ::std::vector<sal_Bool> aNullable;
     463             :         // Loop on the result set until we reach end of file
     464           0 :         while (xRs->next())
     465             :         {
     466           0 :             TOTypeInfoSP pInfo(new OTypeInfo());
     467           0 :             sal_Int32 nPos = 1;
     468           0 :             if ( aTypes.empty() )
     469             :             {
     470           0 :                 sal_Int32 nCount = xResultSetMetaData->getColumnCount();
     471           0 :                 if ( nCount < 1 )
     472           0 :                     nCount = 18;
     473           0 :                 aTypes.reserve(nCount+1);
     474           0 :                 aTypes.push_back(-1);
     475           0 :                 aNullable.push_back(sal_False);
     476           0 :                 for (sal_Int32 j = 1; j <= nCount ; ++j)
     477             :                 {
     478           0 :                     aTypes.push_back(xResultSetMetaData->getColumnType(j));
     479           0 :                     aNullable.push_back(xResultSetMetaData->isNullable(j) != ColumnValue::NO_NULLS);
     480             :                 }
     481             :             }
     482             : 
     483           0 :             aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
     484           0 :             pInfo->aTypeName        = aValue;
     485           0 :             ++nPos;
     486           0 :             aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
     487           0 :             pInfo->nType            = aValue;
     488           0 :             ++nPos;
     489           0 :             aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
     490           0 :             pInfo->nPrecision       = aValue;
     491           0 :             ++nPos;
     492           0 :             aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
     493           0 :             pInfo->aLiteralPrefix   = aValue;
     494           0 :             ++nPos;
     495           0 :             aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
     496           0 :             pInfo->aLiteralSuffix   = aValue;
     497           0 :             ++nPos;
     498           0 :             aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
     499           0 :             pInfo->aCreateParams    = aValue;
     500           0 :             ++nPos;
     501           0 :             aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
     502           0 :             pInfo->bNullable        = (sal_Int32)aValue == ColumnValue::NULLABLE;
     503           0 :             ++nPos;
     504           0 :             aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
     505           0 :             pInfo->bCaseSensitive   = (sal_Bool)aValue;
     506           0 :             ++nPos;
     507           0 :             aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
     508           0 :             pInfo->nSearchType      = aValue;
     509           0 :             ++nPos;
     510           0 :             aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
     511           0 :             pInfo->bUnsigned        = (sal_Bool)aValue;
     512           0 :             ++nPos;
     513           0 :             aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
     514           0 :             pInfo->bCurrency        = (sal_Bool)aValue;
     515           0 :             ++nPos;
     516           0 :             aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
     517           0 :             pInfo->bAutoIncrement   = (sal_Bool)aValue;
     518           0 :             ++nPos;
     519           0 :             aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
     520           0 :             pInfo->aLocalTypeName   = aValue;
     521           0 :             ++nPos;
     522           0 :             aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
     523           0 :             pInfo->nMinimumScale    = aValue;
     524           0 :             ++nPos;
     525           0 :             aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
     526           0 :             pInfo->nMaximumScale    = aValue;
     527           0 :             nPos = 18;
     528           0 :             aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
     529             : 
     530             :             // check if values are less than zero like it happens in a oracle jdbc driver
     531           0 :             if( pInfo->nPrecision < 0)
     532           0 :                 pInfo->nPrecision = 0;
     533           0 :             if( pInfo->nMinimumScale < 0)
     534           0 :                 pInfo->nMinimumScale = 0;
     535           0 :             if( pInfo->nMaximumScale < 0)
     536           0 :                 pInfo->nMaximumScale = 0;
     537             : 
     538           0 :             String aName;
     539           0 :             switch(pInfo->nType)
     540             :             {
     541             :                 case DataType::CHAR:
     542           0 :                     aName = _rsTypeNames.GetToken(TYPE_CHAR);
     543           0 :                     break;
     544             :                 case DataType::VARCHAR:
     545           0 :                     aName = _rsTypeNames.GetToken(TYPE_TEXT);
     546           0 :                     break;
     547             :                 case DataType::DECIMAL:
     548           0 :                     aName = _rsTypeNames.GetToken(TYPE_DECIMAL);
     549           0 :                     break;
     550             :                 case DataType::NUMERIC:
     551           0 :                     aName = _rsTypeNames.GetToken(TYPE_NUMERIC);
     552           0 :                     break;
     553             :                 case DataType::BIGINT:
     554           0 :                     aName = _rsTypeNames.GetToken(TYPE_BIGINT);
     555           0 :                     break;
     556             :                 case DataType::FLOAT:
     557           0 :                     aName = _rsTypeNames.GetToken(TYPE_FLOAT);
     558           0 :                     break;
     559             :                 case DataType::DOUBLE:
     560           0 :                     aName = _rsTypeNames.GetToken(TYPE_DOUBLE);
     561           0 :                     break;
     562             :                 case DataType::LONGVARCHAR:
     563           0 :                     aName = _rsTypeNames.GetToken(TYPE_MEMO);
     564           0 :                     break;
     565             :                 case DataType::LONGVARBINARY:
     566           0 :                     aName = _rsTypeNames.GetToken(TYPE_IMAGE);
     567           0 :                     break;
     568             :                 case DataType::DATE:
     569           0 :                     aName = _rsTypeNames.GetToken(TYPE_DATE);
     570           0 :                     break;
     571             :                 case DataType::TIME:
     572           0 :                     aName = _rsTypeNames.GetToken(TYPE_TIME);
     573           0 :                     break;
     574             :                 case DataType::TIMESTAMP:
     575           0 :                     aName = _rsTypeNames.GetToken(TYPE_DATETIME);
     576           0 :                     break;
     577             :                 case DataType::BIT:
     578           0 :                     if ( !pInfo->aCreateParams.isEmpty() )
     579             :                     {
     580           0 :                         aName = _rsTypeNames.GetToken(TYPE_BIT);
     581           0 :                         break;
     582             :                     }
     583             :                     // run through
     584             :                 case DataType::BOOLEAN:
     585           0 :                     aName = _rsTypeNames.GetToken(TYPE_BOOL);
     586           0 :                     break;
     587             :                 case DataType::TINYINT:
     588           0 :                     aName = _rsTypeNames.GetToken(TYPE_TINYINT);
     589           0 :                     break;
     590             :                 case DataType::SMALLINT:
     591           0 :                     aName = _rsTypeNames.GetToken(TYPE_SMALLINT);
     592           0 :                     break;
     593             :                 case DataType::INTEGER:
     594           0 :                     aName = _rsTypeNames.GetToken(TYPE_INTEGER);
     595           0 :                     break;
     596             :                 case DataType::REAL:
     597           0 :                     aName = _rsTypeNames.GetToken(TYPE_REAL);
     598           0 :                     break;
     599             :                 case DataType::BINARY:
     600           0 :                     aName = _rsTypeNames.GetToken(TYPE_BINARY);
     601           0 :                     break;
     602             :                 case DataType::VARBINARY:
     603           0 :                     aName = _rsTypeNames.GetToken(TYPE_VARBINARY);
     604           0 :                     break;
     605             :                 case DataType::SQLNULL:
     606           0 :                     aName = _rsTypeNames.GetToken(TYPE_SQLNULL);
     607           0 :                     break;
     608             :                 case DataType::OBJECT:
     609           0 :                     aName = _rsTypeNames.GetToken(TYPE_OBJECT);
     610           0 :                     break;
     611             :                 case DataType::DISTINCT:
     612           0 :                     aName = _rsTypeNames.GetToken(TYPE_DISTINCT);
     613           0 :                     break;
     614             :                 case DataType::STRUCT:
     615           0 :                     aName = _rsTypeNames.GetToken(TYPE_STRUCT);
     616           0 :                     break;
     617             :                 case DataType::ARRAY:
     618           0 :                     aName = _rsTypeNames.GetToken(TYPE_ARRAY);
     619           0 :                     break;
     620             :                 case DataType::BLOB:
     621           0 :                     aName = _rsTypeNames.GetToken(TYPE_BLOB);
     622           0 :                     break;
     623             :                 case DataType::CLOB:
     624           0 :                     aName = _rsTypeNames.GetToken(TYPE_CLOB);
     625           0 :                     break;
     626             :                 case DataType::REF:
     627           0 :                     aName = _rsTypeNames.GetToken(TYPE_REF);
     628           0 :                     break;
     629             :                 case DataType::OTHER:
     630           0 :                     aName = _rsTypeNames.GetToken(TYPE_OTHER);
     631           0 :                     break;
     632             :             }
     633           0 :             if ( aName.Len() )
     634             :             {
     635           0 :                 pInfo->aUIName = aName.GetBuffer();
     636           0 :                 pInfo->aUIName += aB1;
     637             :             }
     638           0 :             pInfo->aUIName += pInfo->aTypeName;
     639           0 :             if ( aName.Len() )
     640           0 :                 pInfo->aUIName += aB2;
     641             :             // Now that we have the type info, save it in the multimap
     642           0 :             _rTypeInfoMap.insert(OTypeInfoMap::value_type(pInfo->nType,pInfo));
     643           0 :         }
     644             :         // for a faster index access
     645           0 :         _rTypeInfoIters.reserve(_rTypeInfoMap.size());
     646             : 
     647           0 :         OTypeInfoMap::iterator aIter = _rTypeInfoMap.begin();
     648           0 :         OTypeInfoMap::iterator aEnd = _rTypeInfoMap.end();
     649           0 :         for(;aIter != aEnd;++aIter)
     650           0 :             _rTypeInfoIters.push_back(aIter);
     651             : 
     652             :         // Close the result set/statement.
     653             : 
     654           0 :         ::comphelper::disposeComponent(xRs);
     655           0 :     }
     656             : }
     657             : // -----------------------------------------------------------------------------
     658           0 : void setColumnProperties(const Reference<XPropertySet>& _rxColumn,const OFieldDescription* _pFieldDesc)
     659             : {
     660           0 :     _rxColumn->setPropertyValue(PROPERTY_NAME,makeAny(_pFieldDesc->GetName()));
     661           0 :     _rxColumn->setPropertyValue(PROPERTY_TYPENAME,makeAny(_pFieldDesc->getTypeInfo()->aTypeName));
     662           0 :     _rxColumn->setPropertyValue(PROPERTY_TYPE,makeAny(_pFieldDesc->GetType()));
     663           0 :     _rxColumn->setPropertyValue(PROPERTY_PRECISION,makeAny(_pFieldDesc->GetPrecision()));
     664           0 :     _rxColumn->setPropertyValue(PROPERTY_SCALE,makeAny(_pFieldDesc->GetScale()));
     665           0 :     _rxColumn->setPropertyValue(PROPERTY_ISNULLABLE, makeAny(_pFieldDesc->GetIsNullable()));
     666           0 :     _rxColumn->setPropertyValue(PROPERTY_ISAUTOINCREMENT,::cppu::bool2any(_pFieldDesc->IsAutoIncrement()));
     667           0 :     _rxColumn->setPropertyValue(PROPERTY_DESCRIPTION,makeAny(_pFieldDesc->GetDescription()));
     668           0 :     if ( _rxColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_ISCURRENCY) && _pFieldDesc->IsCurrency() )
     669           0 :         _rxColumn->setPropertyValue(PROPERTY_ISCURRENCY,::cppu::bool2any(_pFieldDesc->IsCurrency()));
     670             :     // set autoincrement value when available
     671             :     // and only set when the entry is not empty, that lets the value in the column untouched
     672           0 :     if ( _pFieldDesc->IsAutoIncrement() && !_pFieldDesc->GetAutoIncrementValue().isEmpty() && _rxColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_AUTOINCREMENTCREATION) )
     673           0 :         _rxColumn->setPropertyValue(PROPERTY_AUTOINCREMENTCREATION,makeAny(_pFieldDesc->GetAutoIncrementValue()));
     674           0 : }
     675             : // -----------------------------------------------------------------------------
     676           0 : ::rtl::OUString createDefaultName(const Reference< XDatabaseMetaData>& _xMetaData,const Reference<XNameAccess>& _xTables,const ::rtl::OUString& _sName)
     677             : {
     678             :     OSL_ENSURE(_xMetaData.is(),"No MetaData!");
     679           0 :     ::rtl::OUString sDefaultName = _sName;
     680             :     try
     681             :     {
     682           0 :         ::rtl::OUString sCatalog,sSchema,sCompsedName;
     683           0 :         if(_xMetaData->supportsCatalogsInTableDefinitions())
     684             :         {
     685             :             try
     686             :             {
     687           0 :                 Reference< XConnection> xCon = _xMetaData->getConnection();
     688           0 :                 if ( xCon.is() )
     689           0 :                     sCatalog = xCon->getCatalog();
     690           0 :                 if ( sCatalog.isEmpty() )
     691             :                 {
     692           0 :                     Reference<XResultSet> xRes = _xMetaData->getCatalogs();
     693           0 :                     Reference<XRow> xRow(xRes,UNO_QUERY);
     694           0 :                     while(xRes.is() && xRes->next())
     695             :                     {
     696           0 :                         sCatalog = xRow->getString(1);
     697           0 :                         if(!xRow->wasNull())
     698           0 :                             break;
     699           0 :                     }
     700           0 :                 }
     701             :             }
     702           0 :             catch(const SQLException&)
     703             :             {
     704             :             }
     705             :         }
     706           0 :         if(_xMetaData->supportsSchemasInTableDefinitions())
     707             :         {
     708           0 :             sSchema = _xMetaData->getUserName();
     709             :         }
     710           0 :         sCompsedName = ::dbtools::composeTableName( _xMetaData, sCatalog, sSchema, _sName, sal_False, ::dbtools::eInDataManipulation );
     711           0 :         sDefaultName = ::dbtools::createUniqueName(_xTables,sCompsedName);
     712             :     }
     713           0 :     catch(const SQLException&)
     714             :     {
     715             :     }
     716           0 :     return sDefaultName;
     717             : }
     718             : // -----------------------------------------------------------------------------
     719           0 : sal_Bool checkDataSourceAvailable(const ::rtl::OUString& _sDataSourceName,const Reference< ::com::sun::star::uno::XComponentContext >& _xContext)
     720             : {
     721           0 :     Reference< XDatabaseContext > xDataBaseContext = DatabaseContext::create(_xContext);
     722           0 :     sal_Bool bRet = xDataBaseContext->hasByName(_sDataSourceName);
     723           0 :     if ( !bRet )
     724             :     { // try if this one is a URL
     725             :         try
     726             :         {
     727           0 :             bRet = xDataBaseContext->getByName(_sDataSourceName).hasValue();
     728             :         }
     729           0 :         catch(const Exception&)
     730             :         {
     731             :         }
     732             :     }
     733           0 :     return bRet;
     734             : }
     735             : // -----------------------------------------------------------------------------
     736           0 : sal_Int32 mapTextAllign(const SvxCellHorJustify& _eAlignment)
     737             : {
     738           0 :     sal_Int32 nAlignment = com::sun::star::awt::TextAlign::LEFT;
     739           0 :     switch (_eAlignment)
     740             :     {
     741             :         case SVX_HOR_JUSTIFY_STANDARD:
     742           0 :         case SVX_HOR_JUSTIFY_LEFT:      nAlignment = ::com::sun::star::awt::TextAlign::LEFT;    break;
     743           0 :         case SVX_HOR_JUSTIFY_CENTER:    nAlignment = ::com::sun::star::awt::TextAlign::CENTER;  break;
     744           0 :         case SVX_HOR_JUSTIFY_RIGHT:     nAlignment = ::com::sun::star::awt::TextAlign::RIGHT;   break;
     745             :         default:
     746             :             OSL_FAIL("Invalid TextAlign!");
     747             :     }
     748           0 :     return nAlignment;
     749             : }
     750             : // -----------------------------------------------------------------------------
     751           0 : SvxCellHorJustify mapTextJustify(const sal_Int32& _nAlignment)
     752             : {
     753           0 :     SvxCellHorJustify eJustify = SVX_HOR_JUSTIFY_LEFT;
     754           0 :     switch (_nAlignment)
     755             :     {
     756           0 :         case ::com::sun::star::awt::TextAlign::LEFT     : eJustify = SVX_HOR_JUSTIFY_LEFT; break;
     757           0 :         case ::com::sun::star::awt::TextAlign::CENTER   : eJustify = SVX_HOR_JUSTIFY_CENTER; break;
     758           0 :         case ::com::sun::star::awt::TextAlign::RIGHT    : eJustify = SVX_HOR_JUSTIFY_RIGHT; break;
     759             :         default:
     760             :             OSL_FAIL("Invalid TextAlign!");
     761             :     }
     762           0 :     return eJustify;
     763             : }
     764             : // -----------------------------------------------------------------------------
     765           0 : float ConvertFontWeight( ::FontWeight eWeight )
     766             : {
     767           0 :     if( eWeight == WEIGHT_DONTKNOW )
     768           0 :         return ::com::sun::star::awt::FontWeight::DONTKNOW;
     769           0 :     else if( eWeight == WEIGHT_THIN )
     770           0 :         return ::com::sun::star::awt::FontWeight::THIN;
     771           0 :     else if( eWeight == WEIGHT_ULTRALIGHT )
     772           0 :         return ::com::sun::star::awt::FontWeight::ULTRALIGHT;
     773           0 :     else if( eWeight == WEIGHT_LIGHT )
     774           0 :         return ::com::sun::star::awt::FontWeight::LIGHT;
     775           0 :     else if( eWeight == WEIGHT_SEMILIGHT )
     776           0 :         return ::com::sun::star::awt::FontWeight::SEMILIGHT;
     777           0 :     else if( ( eWeight == WEIGHT_NORMAL ) || ( eWeight == WEIGHT_MEDIUM ) )
     778           0 :         return ::com::sun::star::awt::FontWeight::NORMAL;
     779           0 :     else if( eWeight == WEIGHT_SEMIBOLD )
     780           0 :         return ::com::sun::star::awt::FontWeight::SEMIBOLD;
     781           0 :     else if( eWeight == WEIGHT_BOLD )
     782           0 :         return ::com::sun::star::awt::FontWeight::BOLD;
     783           0 :     else if( eWeight == WEIGHT_ULTRABOLD )
     784           0 :         return ::com::sun::star::awt::FontWeight::ULTRABOLD;
     785           0 :     else if( eWeight == WEIGHT_BLACK )
     786           0 :         return ::com::sun::star::awt::FontWeight::BLACK;
     787             : 
     788             :     OSL_FAIL("Unknown FontWeigth" );
     789           0 :     return ::com::sun::star::awt::FontWeight::DONTKNOW;
     790             : }
     791             : // -----------------------------------------------------------------------------
     792           0 : float ConvertFontWidth( ::FontWidth eWidth )
     793             : {
     794           0 :     if( eWidth == WIDTH_DONTKNOW )
     795           0 :         return ::com::sun::star::awt::FontWidth::DONTKNOW;
     796           0 :     else if( eWidth == WIDTH_ULTRA_CONDENSED )
     797           0 :         return ::com::sun::star::awt::FontWidth::ULTRACONDENSED;
     798           0 :     else if( eWidth == WIDTH_EXTRA_CONDENSED )
     799           0 :         return ::com::sun::star::awt::FontWidth::EXTRACONDENSED;
     800           0 :     else if( eWidth == WIDTH_CONDENSED )
     801           0 :         return ::com::sun::star::awt::FontWidth::CONDENSED;
     802           0 :     else if( eWidth == WIDTH_SEMI_CONDENSED )
     803           0 :         return ::com::sun::star::awt::FontWidth::SEMICONDENSED;
     804           0 :     else if( eWidth == WIDTH_NORMAL )
     805           0 :         return ::com::sun::star::awt::FontWidth::NORMAL;
     806           0 :     else if( eWidth == WIDTH_SEMI_EXPANDED )
     807           0 :         return ::com::sun::star::awt::FontWidth::SEMIEXPANDED;
     808           0 :     else if( eWidth == WIDTH_EXPANDED )
     809           0 :         return ::com::sun::star::awt::FontWidth::EXPANDED;
     810           0 :     else if( eWidth == WIDTH_EXTRA_EXPANDED )
     811           0 :         return ::com::sun::star::awt::FontWidth::EXTRAEXPANDED;
     812           0 :     else if( eWidth == WIDTH_ULTRA_EXPANDED )
     813           0 :         return ::com::sun::star::awt::FontWidth::ULTRAEXPANDED;
     814             : 
     815             :     OSL_FAIL("Unknown FontWidth" );
     816           0 :     return ::com::sun::star::awt::FontWidth::DONTKNOW;
     817             : }
     818             : // -----------------------------------------------------------------------------
     819           0 : ::com::sun::star::awt::FontDescriptor CreateFontDescriptor( const Font& rFont )
     820             : {
     821           0 :     ::com::sun::star::awt::FontDescriptor aFD;
     822           0 :     aFD.Name            = rFont.GetName();
     823           0 :     aFD.StyleName       = rFont.GetStyleName();
     824           0 :     aFD.Height          = (sal_Int16)rFont.GetSize().Height();
     825           0 :     aFD.Width           = (sal_Int16)rFont.GetSize().Width();
     826           0 :     aFD.Family          = sal::static_int_cast< sal_Int16 >(rFont.GetFamily());
     827           0 :     aFD.CharSet         = rFont.GetCharSet();
     828           0 :     aFD.Pitch           = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
     829           0 :     aFD.CharacterWidth  = ConvertFontWidth( rFont.GetWidthType() );
     830           0 :     aFD.Weight          = ConvertFontWeight( rFont.GetWeight() );
     831           0 :     aFD.Slant           = (::com::sun::star::awt::FontSlant)rFont.GetItalic();
     832             :     aFD.Underline       = sal::static_int_cast< sal_Int16 >(
     833           0 :         rFont.GetUnderline());
     834             :     aFD.Strikeout       = sal::static_int_cast< sal_Int16 >(
     835           0 :         rFont.GetStrikeout());
     836           0 :     aFD.Orientation     = rFont.GetOrientation();
     837           0 :     aFD.Kerning         = rFont.IsKerning();
     838           0 :     aFD.WordLineMode    = rFont.IsWordLineMode();
     839           0 :     aFD.Type            = 0;   // ??? => Nur an Metric...
     840           0 :     return aFD;
     841             : }
     842             : // -----------------------------------------------------------------------------
     843           0 : void callColumnFormatDialog(const Reference<XPropertySet>& xAffectedCol,
     844             :                             const Reference<XPropertySet>& xField,
     845             :                             SvNumberFormatter* _pFormatter,
     846             :                             Window* _pParent)
     847             : {
     848           0 :     if (xAffectedCol.is() && xField.is())
     849             :     {
     850             :         try
     851             :         {
     852           0 :             Reference< XPropertySetInfo >  xInfo = xAffectedCol->getPropertySetInfo();
     853           0 :             sal_Bool bHasFormat = xInfo->hasPropertyByName(PROPERTY_FORMATKEY);
     854           0 :             sal_Int32 nDataType = ::comphelper::getINT32(xField->getPropertyValue(PROPERTY_TYPE));
     855             : 
     856           0 :             SvxCellHorJustify eJustify(SVX_HOR_JUSTIFY_STANDARD);
     857           0 :             Any aAlignment = xAffectedCol->getPropertyValue(PROPERTY_ALIGN);
     858           0 :             if (aAlignment.hasValue())
     859           0 :                 eJustify = dbaui::mapTextJustify(::comphelper::getINT16(aAlignment));
     860           0 :             sal_Int32  nFormatKey = 0;
     861           0 :             if ( bHasFormat )
     862           0 :                 nFormatKey = ::comphelper::getINT32(xAffectedCol->getPropertyValue(PROPERTY_FORMATKEY));
     863             : 
     864           0 :             sal_uInt16 nFlags = 0;
     865           0 :             if(callColumnFormatDialog(_pParent,_pFormatter,nDataType,nFormatKey,eJustify,nFlags,bHasFormat))
     866             :             {
     867           0 :                 xAffectedCol->setPropertyValue(PROPERTY_ALIGN, makeAny((sal_Int16)dbaui::mapTextAllign(eJustify)));
     868           0 :                 if (nFlags & TP_ATTR_NUMBER)
     869           0 :                     xAffectedCol->setPropertyValue(PROPERTY_FORMATKEY, makeAny(nFormatKey));
     870             : 
     871           0 :             }
     872             :         }
     873           0 :         catch( const Exception& )
     874             :         {
     875             :             DBG_UNHANDLED_EXCEPTION();
     876             :         }
     877             :     }
     878           0 : }
     879             : // -----------------------------------------------------------------------------
     880           0 : sal_Bool callColumnFormatDialog(Window* _pParent,
     881             :                                 SvNumberFormatter* _pFormatter,
     882             :                                 sal_Int32 _nDataType,
     883             :                                 sal_Int32& _nFormatKey,
     884             :                                 SvxCellHorJustify& _eJustify,
     885             :                                 sal_uInt16& _nFlags,
     886             :                                 sal_Bool  _bHasFormat)
     887             : {
     888           0 :     sal_Bool bRet = sal_False;
     889             :     // the allowed format changes depending on the type of the field ...
     890           0 :     _nFlags = TP_ATTR_ALIGN;
     891             : 
     892           0 :     if (_bHasFormat)
     893           0 :         _nFlags |= TP_ATTR_NUMBER;
     894             : 
     895             :     // ------------
     896             :     // UNO->ItemSet
     897             :     static SfxItemInfo aItemInfos[] =
     898             :     {
     899             :         { 0, 0 },
     900             :         { SID_ATTR_NUMBERFORMAT_VALUE,      SFX_ITEM_POOLABLE },
     901             :         { SID_ATTR_ALIGN_HOR_JUSTIFY,       SFX_ITEM_POOLABLE },
     902             :         { SID_ATTR_NUMBERFORMAT_ONE_AREA,   SFX_ITEM_POOLABLE },
     903             :         { SID_ATTR_NUMBERFORMAT_INFO,       SFX_ITEM_POOLABLE }
     904             :     };
     905             :     static sal_uInt16 aAttrMap[] =
     906             :     {
     907             :         SBA_DEF_RANGEFORMAT, SBA_ATTR_ALIGN_HOR_JUSTIFY,
     908             :         SID_ATTR_NUMBERFORMAT_ONE_AREA, SID_ATTR_NUMBERFORMAT_ONE_AREA,
     909             :         SID_ATTR_NUMBERFORMAT_INFO, SID_ATTR_NUMBERFORMAT_INFO,
     910             :         0
     911             :     };
     912             : 
     913             :     SfxPoolItem* pDefaults[] =
     914             :     {
     915           0 :         new SfxRangeItem(SBA_DEF_RANGEFORMAT, SBA_DEF_FMTVALUE, SBA_ATTR_ALIGN_HOR_JUSTIFY),
     916           0 :         new SfxUInt32Item(SBA_DEF_FMTVALUE),
     917           0 :         new SvxHorJustifyItem(SVX_HOR_JUSTIFY_STANDARD, SBA_ATTR_ALIGN_HOR_JUSTIFY),
     918           0 :         new SfxBoolItem(SID_ATTR_NUMBERFORMAT_ONE_AREA, sal_False),
     919           0 :         new SvxNumberInfoItem(SID_ATTR_NUMBERFORMAT_INFO)
     920           0 :     };
     921             : 
     922           0 :     SfxItemPool* pPool = new SfxItemPool(rtl::OUString("GridBrowserProperties"), SBA_DEF_RANGEFORMAT, SBA_ATTR_ALIGN_HOR_JUSTIFY, aItemInfos, pDefaults);
     923           0 :     pPool->SetDefaultMetric( SFX_MAPUNIT_TWIP );    // ripped, don't understand why
     924           0 :     pPool->FreezeIdRanges();                        // the same
     925             : 
     926           0 :     SfxItemSet* pFormatDescriptor = new SfxItemSet(*pPool, aAttrMap);
     927             :     // fill it
     928           0 :     pFormatDescriptor->Put(SvxHorJustifyItem(_eJustify, SBA_ATTR_ALIGN_HOR_JUSTIFY));
     929           0 :     sal_Bool bText = sal_False;
     930           0 :     if (_bHasFormat)
     931             :     {
     932             :         // if the col is bound to a text field we have to disallow all non-text formats
     933           0 :         if ((DataType::CHAR == _nDataType) || (DataType::VARCHAR == _nDataType) || (DataType::LONGVARCHAR == _nDataType) || (DataType::CLOB == _nDataType))
     934             :         {
     935           0 :             bText = sal_True;
     936           0 :             pFormatDescriptor->Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_ONE_AREA, sal_True));
     937           0 :             if (!_pFormatter->IsTextFormat(_nFormatKey))
     938             :                 // text fields can only have text formats
     939           0 :                 _nFormatKey = _pFormatter->GetStandardFormat(NUMBERFORMAT_TEXT,_pParent->GetSettings().GetLanguageTag().getLanguageType());
     940             :         }
     941             : 
     942           0 :         pFormatDescriptor->Put(SfxUInt32Item(SBA_DEF_FMTVALUE, _nFormatKey));
     943             :     }
     944             : 
     945           0 :     if (!bText)
     946             :     {
     947           0 :         double dPreviewVal = 1234.56789;
     948           0 :         SvxNumberInfoItem aFormatter(_pFormatter, dPreviewVal, SID_ATTR_NUMBERFORMAT_INFO);
     949           0 :         pFormatDescriptor->Put(aFormatter);
     950             :     }
     951             : 
     952             :     {   // want the dialog to be destroyed before our set
     953           0 :         SbaSbAttrDlg aDlg(_pParent, pFormatDescriptor, _pFormatter, _nFlags);
     954           0 :         if (RET_OK == aDlg.Execute())
     955             :         {
     956             :             // ------------
     957             :             // ItemSet->UNO
     958             :             // UNO-properties
     959           0 :             const SfxItemSet* pSet = aDlg.GetExampleSet();
     960             :             // (of course we could put the modified items directly into the column, but then the UNO-model
     961             :             // won't reflect these changes, and why do we have a model, then ?)
     962             : 
     963             :             // horizontal justify
     964           0 :             SFX_ITEMSET_GET(*pSet, pHorJustify, SvxHorJustifyItem, SBA_ATTR_ALIGN_HOR_JUSTIFY, sal_True);
     965             : 
     966           0 :             _eJustify = (SvxCellHorJustify)pHorJustify->GetValue();
     967             : 
     968             :             // format key
     969           0 :             if (_nFlags & TP_ATTR_NUMBER)
     970             :             {
     971           0 :                 SFX_ITEMSET_GET(*pSet, pFormat, SfxUInt32Item, SBA_DEF_FMTVALUE, sal_True);
     972           0 :                 _nFormatKey = (sal_Int32)pFormat->GetValue();
     973             :             }
     974           0 :             bRet = sal_True;
     975             :         }
     976             :             // deleted formats
     977           0 :         const SfxItemSet* pResult = aDlg.GetOutputItemSet();
     978           0 :         if (pResult)
     979             :         {
     980           0 :             const SfxPoolItem* pItem = pResult->GetItem( SID_ATTR_NUMBERFORMAT_INFO );
     981           0 :             const SvxNumberInfoItem* pInfoItem = static_cast<const SvxNumberInfoItem*>(pItem);
     982           0 :             if (pInfoItem && pInfoItem->GetDelCount())
     983             :             {
     984           0 :                 const sal_uInt32* pDeletedKeys = pInfoItem->GetDelArray();
     985             : 
     986           0 :                 for (sal_uInt16 i=0; i< pInfoItem->GetDelCount(); ++i, ++pDeletedKeys)
     987           0 :                     _pFormatter->DeleteEntry(*pDeletedKeys);
     988             :             }
     989           0 :         }
     990             :     }
     991             : 
     992           0 :     delete pFormatDescriptor;
     993           0 :     SfxItemPool::Free(pPool);
     994           0 :     for (sal_uInt16 i=0; i<sizeof(pDefaults)/sizeof(pDefaults[0]); ++i)
     995           0 :         delete pDefaults[i];
     996             : 
     997           0 :     return bRet;
     998             : }
     999             : 
    1000             : //------------------------------------------------------------------------------
    1001           0 : const SfxFilter* getStandardDatabaseFilter()
    1002             : {
    1003           0 :     const SfxFilter* pFilter = SfxFilter::GetFilterByName(rtl::OUString("StarOffice XML (Base)"));
    1004             :     OSL_ENSURE(pFilter,"Filter: StarOffice XML (Base) could not be found!");
    1005           0 :     return pFilter;
    1006             : }
    1007             : 
    1008             : 
    1009             : // -----------------------------------------------------------------------------
    1010           0 : sal_Bool appendToFilter(const Reference<XConnection>& _xConnection,
    1011             :                         const ::rtl::OUString& _sName,
    1012             :                         const Reference< XComponentContext >& _rxContext,
    1013             :                         Window* _pParent)
    1014             : {
    1015           0 :     sal_Bool bRet = sal_False;
    1016           0 :     Reference< XChild> xChild(_xConnection,UNO_QUERY);
    1017           0 :     if(xChild.is())
    1018             :     {
    1019           0 :         Reference< XPropertySet> xProp(xChild->getParent(),UNO_QUERY);
    1020           0 :         if(xProp.is())
    1021             :         {
    1022           0 :             Sequence< ::rtl::OUString > aFilter;
    1023           0 :             xProp->getPropertyValue(PROPERTY_TABLEFILTER) >>= aFilter;
    1024             :             // first check if we have something like SCHEMA.%
    1025           0 :             sal_Bool bHasToInsert = sal_True;
    1026           0 :             const ::rtl::OUString* pBegin = aFilter.getConstArray();
    1027           0 :             const ::rtl::OUString* pEnd = pBegin + aFilter.getLength();
    1028           0 :             for (;pBegin != pEnd; ++pBegin)
    1029             :             {
    1030           0 :                 if(pBegin->indexOf('%') != -1)
    1031             :                 {
    1032             :                     sal_Int32 nLen;
    1033           0 :                     if((nLen = pBegin->lastIndexOf('.')) != -1 && !pBegin->compareTo(_sName,nLen))
    1034           0 :                         bHasToInsert = sal_False;
    1035           0 :                     else if(pBegin->getLength() == 1)
    1036           0 :                         bHasToInsert = sal_False;
    1037             :                 }
    1038             :             }
    1039             : 
    1040           0 :             bRet = sal_True;
    1041           0 :             if(bHasToInsert)
    1042             :             {
    1043           0 :                 if(! ::dbaui::checkDataSourceAvailable(::comphelper::getString(xProp->getPropertyValue(PROPERTY_NAME)),_rxContext))
    1044             :                 {
    1045           0 :                     String aMessage(ModuleRes(STR_TABLEDESIGN_DATASOURCE_DELETED));
    1046           0 :                     OSQLWarningBox( _pParent, aMessage ).Execute();
    1047           0 :                     bRet = sal_False;
    1048             :                 }
    1049             :                 else
    1050             :                 {
    1051           0 :                     aFilter.realloc(aFilter.getLength()+1);
    1052           0 :                     aFilter.getArray()[aFilter.getLength()-1] = _sName;
    1053           0 :                     xProp->setPropertyValue(PROPERTY_TABLEFILTER,makeAny(aFilter));
    1054             :                 }
    1055           0 :             }
    1056           0 :         }
    1057             :     }
    1058           0 :     return bRet;
    1059             : }
    1060             : // -----------------------------------------------------------------------------
    1061           0 : void notifySystemWindow(Window* _pWindow,Window* _pToRegister, ::comphelper::mem_fun1_t<TaskPaneList,Window*> _rMemFunc)
    1062             : {
    1063             :     OSL_ENSURE(_pWindow,"Window can not be null!");
    1064           0 :     SystemWindow* pSystemWindow = _pWindow ? _pWindow->GetSystemWindow() : NULL;
    1065           0 :     if ( pSystemWindow )
    1066             :     {
    1067           0 :         _rMemFunc( pSystemWindow->GetTaskPaneList(), _pToRegister );
    1068             :     }
    1069           0 : }
    1070             : // -----------------------------------------------------------------------------
    1071           0 : void adjustToolBoxSize(ToolBox* _pToolBox)
    1072             : {
    1073             :     // adjust the toolbox size, otherwise large bitmaps don't fit into
    1074           0 :     Size aOldSize = _pToolBox->GetSizePixel();
    1075           0 :     Size aSize = _pToolBox->CalcWindowSizePixel();
    1076           0 :     if ( !aSize.Width() )
    1077           0 :         aSize.Width() = aOldSize.Width();
    1078           0 :     else if ( !aSize.Height() )
    1079           0 :         aSize.Height() = aOldSize.Height();
    1080             : 
    1081           0 :     Size aTbSize = _pToolBox->GetSizePixel();
    1082           0 :     if ( (aSize.Width() && aSize.Width() != aTbSize.Width()) ||
    1083           0 :             (aSize.Height() && aSize.Height() != aTbSize.Height()) )
    1084             :     {
    1085           0 :         _pToolBox->SetPosSizePixel( _pToolBox->GetPosPixel(), aSize );
    1086           0 :         _pToolBox->Invalidate();
    1087             :     }
    1088           0 : }
    1089             : // -----------------------------------------------------------------------------
    1090           0 : void adjustBrowseBoxColumnWidth( ::svt::EditBrowseBox* _pBox, sal_uInt16 _nColId )
    1091             : {
    1092           0 :     sal_Int32 nColSize = -1;
    1093           0 :     sal_uInt32 nDefaultWidth = _pBox->GetDefaultColumnWidth( _pBox->GetColumnTitle( _nColId ) );
    1094           0 :     if ( nDefaultWidth != _pBox->GetColumnWidth( _nColId ) )
    1095             :     {
    1096           0 :         Size aSizeMM = _pBox->PixelToLogic( Size( _pBox->GetColumnWidth( _nColId ), 0 ), MapMode( MAP_MM ) );
    1097           0 :         nColSize = aSizeMM.Width() * 10;
    1098             :     }
    1099             : 
    1100           0 :     Size aDefaultMM = _pBox->PixelToLogic( Size( nDefaultWidth, 0 ), MapMode( MAP_MM ) );
    1101             : 
    1102           0 :     DlgSize aColumnSizeDlg( _pBox, nColSize, sal_False, aDefaultMM.Width() * 10 );
    1103           0 :     if ( aColumnSizeDlg.Execute() )
    1104             :     {
    1105           0 :         sal_Int32 nValue = aColumnSizeDlg.GetValue();
    1106           0 :         if ( -1 == nValue )
    1107             :         {   // default width
    1108           0 :             nValue = _pBox->GetDefaultColumnWidth( _pBox->GetColumnTitle( _nColId ) );
    1109             :         }
    1110             :         else
    1111             :         {
    1112           0 :             Size aSizeMM( nValue / 10, 0 );
    1113           0 :             nValue = _pBox->LogicToPixel( aSizeMM, MapMode( MAP_MM ) ).Width();
    1114             :         }
    1115           0 :         _pBox->SetColumnWidth( _nColId, nValue );
    1116           0 :     }
    1117           0 : }
    1118             : // -----------------------------------------------------------------------------
    1119             : // check if SQL92 name checking is enabled
    1120           0 : sal_Bool isSQL92CheckEnabled(const Reference<XConnection>& _xConnection)
    1121             : {
    1122           0 :     return ::dbtools::getBooleanDataSourceSetting( _xConnection, PROPERTY_ENABLESQL92CHECK.ascii );
    1123             : }
    1124             : // -----------------------------------------------------------------------------
    1125           0 : sal_Bool isAppendTableAliasEnabled(const Reference<XConnection>& _xConnection)
    1126             : {
    1127           0 :     return ::dbtools::getBooleanDataSourceSetting( _xConnection, INFO_APPEND_TABLE_ALIAS.ascii );
    1128             : }
    1129             : 
    1130             : // -----------------------------------------------------------------------------
    1131           0 : sal_Bool generateAsBeforeTableAlias(const Reference<XConnection>& _xConnection)
    1132             : {
    1133           0 :     return ::dbtools::getBooleanDataSourceSetting( _xConnection, INFO_AS_BEFORE_CORRELATION_NAME.ascii );
    1134             : }
    1135             : 
    1136             : // -----------------------------------------------------------------------------
    1137           0 : void fillAutoIncrementValue(const Reference<XPropertySet>& _xDatasource,
    1138             :                             sal_Bool& _rAutoIncrementValueEnabled,
    1139             :                             ::rtl::OUString& _rsAutoIncrementValue)
    1140             : {
    1141           0 :     if ( _xDatasource.is() )
    1142             :     {
    1143             :         OSL_ENSURE(_xDatasource->getPropertySetInfo()->hasPropertyByName(PROPERTY_INFO),"NO datasource supplied!");
    1144           0 :         Sequence<PropertyValue> aInfo;
    1145           0 :         _xDatasource->getPropertyValue(PROPERTY_INFO) >>= aInfo;
    1146             : 
    1147             :         // search the right propertyvalue
    1148             :         const PropertyValue* pValue =::std::find_if(aInfo.getConstArray(),
    1149           0 :                                                     aInfo.getConstArray() + aInfo.getLength(),
    1150           0 :                                                     ::std::bind2nd(TPropertyValueEqualFunctor(),PROPERTY_AUTOINCREMENTCREATION));
    1151           0 :         if ( pValue && pValue != (aInfo.getConstArray() + aInfo.getLength()) )
    1152           0 :             pValue->Value >>= _rsAutoIncrementValue;
    1153             :         pValue =::std::find_if(aInfo.getConstArray(),
    1154           0 :                                                     aInfo.getConstArray() + aInfo.getLength(),
    1155           0 :                                                     ::std::bind2nd(TPropertyValueEqualFunctor(),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsAutoRetrievingEnabled")) ));
    1156           0 :         if ( pValue && pValue != (aInfo.getConstArray() + aInfo.getLength()) )
    1157           0 :             pValue->Value >>= _rAutoIncrementValueEnabled;
    1158             :     }
    1159           0 : }
    1160             : // -----------------------------------------------------------------------------
    1161           0 : void fillAutoIncrementValue(const Reference<XConnection>& _xConnection,
    1162             :                             sal_Bool& _rAutoIncrementValueEnabled,
    1163             :                             ::rtl::OUString& _rsAutoIncrementValue)
    1164             : {
    1165           0 :     Reference< XChild> xChild(_xConnection,UNO_QUERY);
    1166           0 :     if(xChild.is())
    1167             :     {
    1168           0 :         Reference< XPropertySet> xProp(xChild->getParent(),UNO_QUERY);
    1169           0 :         fillAutoIncrementValue(xProp,_rAutoIncrementValueEnabled,_rsAutoIncrementValue);
    1170           0 :     }
    1171           0 : }
    1172             : // -----------------------------------------------------------------------------
    1173           0 : ::rtl::OUString getStrippedDatabaseName(const Reference<XPropertySet>& _xDataSource,::rtl::OUString& _rsDatabaseName)
    1174             : {
    1175           0 :     if ( _rsDatabaseName.isEmpty() && _xDataSource.is() )
    1176             :     {
    1177             :         try
    1178             :         {
    1179           0 :             _xDataSource->getPropertyValue(PROPERTY_NAME) >>= _rsDatabaseName;
    1180             :         }
    1181           0 :         catch(const Exception& )
    1182             :         {
    1183             :             DBG_UNHANDLED_EXCEPTION();
    1184             :         }
    1185             :     }
    1186           0 :     ::rtl::OUString sName = _rsDatabaseName;
    1187           0 :     INetURLObject aURL(sName);
    1188           0 :     if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
    1189           0 :         sName = aURL.getBase(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_UNAMBIGUOUS);
    1190           0 :     return sName;
    1191             : }
    1192             : // -----------------------------------------------------------------------------
    1193           0 : void AppendConfigToken( ::rtl::OUString& _rURL, sal_Bool _bQuestionMark )
    1194             : {
    1195             :     // query part exists?
    1196           0 :     if ( _bQuestionMark )
    1197             :         // no, so start with '?'
    1198           0 :         _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("?"));
    1199             :     else
    1200             :         // yes, so only append with '&'
    1201           0 :         _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("&"));
    1202             : 
    1203             :     // set parameters
    1204           0 :     _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Language="));
    1205           0 :     _rURL += utl::ConfigManager::getLocale();
    1206           0 :     _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("&System="));
    1207           0 :     _rURL += SvtHelpOptions().GetSystem();
    1208           0 : }
    1209             : 
    1210             : namespace
    1211             : {
    1212             :     // -----------------------------------------------------------------------
    1213             : 
    1214           0 :     sal_Bool GetHelpAnchor_Impl( const ::rtl::OUString& _rURL, ::rtl::OUString& _rAnchor )
    1215             :     {
    1216           0 :         sal_Bool bRet = sal_False;
    1217           0 :         ::rtl::OUString sAnchor;
    1218             : 
    1219             :         try
    1220             :         {
    1221             :             ::ucbhelper::Content aCnt( INetURLObject( _rURL ).GetMainURL( INetURLObject::NO_DECODE ),
    1222             :                                  Reference< ::com::sun::star::ucb::XCommandEnvironment >(),
    1223           0 :                                  comphelper::getProcessComponentContext() );
    1224           0 :             if ( ( aCnt.getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AnchorName")) ) >>= sAnchor ) )
    1225             :             {
    1226             : 
    1227           0 :                 if ( !sAnchor.isEmpty() )
    1228             :                 {
    1229           0 :                     _rAnchor = sAnchor;
    1230           0 :                     bRet = sal_True;
    1231             :                 }
    1232             :             }
    1233             :             else
    1234             :             {
    1235             :                 SAL_WARN( "dbaccess.ui", "Property 'AnchorName' is missing" );
    1236           0 :             }
    1237             :         }
    1238           0 :         catch( Exception& )
    1239             :         {
    1240             :         }
    1241             : 
    1242           0 :         return bRet;
    1243             :     }
    1244             : // .........................................................................
    1245             : } // annonymous
    1246             : // .........................................................................
    1247             : // -----------------------------------------------------------------------------
    1248           0 : ::com::sun::star::util::URL createHelpAgentURL(const ::rtl::OUString& _sModuleName, const rtl::OString& sHelpId)
    1249             : {
    1250           0 :     ::com::sun::star::util::URL aURL;
    1251           0 :     aURL.Complete = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.help://" ) );
    1252           0 :     aURL.Complete += _sModuleName;
    1253           0 :     aURL.Complete += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) );
    1254           0 :     aURL.Complete += ::rtl::OStringToOUString(sHelpId, RTL_TEXTENCODING_UTF8);
    1255             : 
    1256           0 :     ::rtl::OUString sAnchor;
    1257           0 :     ::rtl::OUString sTempURL = aURL.Complete;
    1258           0 :     AppendConfigToken( sTempURL, sal_True );
    1259           0 :     sal_Bool bHasAnchor = GetHelpAnchor_Impl( sTempURL, sAnchor );
    1260           0 :     AppendConfigToken(aURL.Complete,sal_True);
    1261           0 :     if ( bHasAnchor )
    1262             :     {
    1263           0 :         aURL.Complete += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#"));
    1264           0 :         aURL.Complete += sAnchor;
    1265             :     }
    1266           0 :     return aURL;
    1267             : }
    1268             : // -----------------------------------------------------------------------------
    1269           0 : void setEvalDateFormatForFormatter(Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter)
    1270             : {
    1271             :     OSL_ENSURE( _rxFormatter.is(),"setEvalDateFormatForFormatter: Formatter is NULL!");
    1272           0 :     if ( _rxFormatter.is() )
    1273             :     {
    1274           0 :         Reference< ::com::sun::star::util::XNumberFormatsSupplier >  xSupplier = _rxFormatter->getNumberFormatsSupplier();
    1275             : 
    1276           0 :         Reference< XUnoTunnel > xTunnel(xSupplier,UNO_QUERY);
    1277           0 :         SvNumberFormatsSupplierObj* pSupplierImpl = reinterpret_cast<SvNumberFormatsSupplierObj*>(xTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
    1278             :         OSL_ENSURE(pSupplierImpl,"No Supplier!");
    1279             : 
    1280           0 :         if ( pSupplierImpl )
    1281             :         {
    1282           0 :             SvNumberFormatter* pFormatter = pSupplierImpl->GetNumberFormatter();
    1283           0 :             pFormatter->SetEvalDateFormat(NF_EVALDATEFORMAT_FORMAT);
    1284           0 :         }
    1285             :     }
    1286           0 : }
    1287             : // -----------------------------------------------------------------------------
    1288           0 : TOTypeInfoSP queryPrimaryKeyType(const OTypeInfoMap& _rTypeInfo)
    1289             : {
    1290           0 :     TOTypeInfoSP pTypeInfo;
    1291             :     // first we search for a type which supports autoIncrement
    1292           0 :     OTypeInfoMap::const_iterator aIter = _rTypeInfo.begin();
    1293           0 :     OTypeInfoMap::const_iterator aEnd  = _rTypeInfo.end();
    1294           0 :     for(;aIter != aEnd;++aIter)
    1295             :     {
    1296             :         // OJ: we don't want to set an autoincrement column to be key
    1297             :         // because we don't have the possiblity to know how to create
    1298             :         // such auto increment column later on
    1299             :         // so until we know how to do it, we create a column without autoincrement
    1300             :         //  if ( !aIter->second->bAutoIncrement )
    1301             :         {   // therefor we have searched
    1302           0 :             if ( aIter->second->nType == DataType::INTEGER )
    1303             :             {
    1304           0 :                 pTypeInfo = aIter->second; // alternative
    1305           0 :                 break;
    1306             :             }
    1307           0 :             else if ( !pTypeInfo.get() && aIter->second->nType == DataType::DOUBLE )
    1308           0 :                 pTypeInfo = aIter->second; // alternative
    1309           0 :             else if ( !pTypeInfo.get() && aIter->second->nType == DataType::REAL )
    1310           0 :                 pTypeInfo = aIter->second; // alternative
    1311             :         }
    1312             :     }
    1313           0 :     if ( !pTypeInfo.get() ) // just a fallback
    1314           0 :         pTypeInfo = queryTypeInfoByType(DataType::VARCHAR,_rTypeInfo);
    1315             : 
    1316             :     OSL_ENSURE(pTypeInfo.get(),"checkColumns: cann't find a type which is useable as a key!");
    1317           0 :     return pTypeInfo;
    1318             : }
    1319             : // -----------------------------------------------------------------------------
    1320           0 : TOTypeInfoSP queryTypeInfoByType(sal_Int32 _nDataType,const OTypeInfoMap& _rTypeInfo)
    1321             : {
    1322           0 :     OTypeInfoMap::const_iterator aIter = _rTypeInfo.find(_nDataType);
    1323           0 :     if(aIter != _rTypeInfo.end())
    1324           0 :         return aIter->second;
    1325             :     // fall back if the type is unknown
    1326           0 :     TOTypeInfoSP pTypeInfo;
    1327           0 :     switch(_nDataType)
    1328             :     {
    1329             :         case DataType::TINYINT:
    1330           0 :             if( (pTypeInfo = queryTypeInfoByType(DataType::SMALLINT,_rTypeInfo) ) )
    1331           0 :                 break;
    1332             :             // run through
    1333             :         case DataType::SMALLINT:
    1334           0 :             if( (pTypeInfo = queryTypeInfoByType(DataType::INTEGER,_rTypeInfo) ) )
    1335           0 :                 break;
    1336             :             // run through
    1337             :         case DataType::INTEGER:
    1338           0 :             if( (pTypeInfo = queryTypeInfoByType(DataType::FLOAT,_rTypeInfo) ) )
    1339           0 :                 break;
    1340             :             // run through
    1341             :         case DataType::FLOAT:
    1342           0 :             if( (pTypeInfo = queryTypeInfoByType(DataType::REAL,_rTypeInfo) ) )
    1343           0 :                 break;
    1344             :             // run through
    1345             :         case DataType::DATE:
    1346             :         case DataType::TIME:
    1347           0 :             if( DataType::DATE == _nDataType || DataType::TIME == _nDataType )
    1348             :             {
    1349           0 :                 if( (pTypeInfo = queryTypeInfoByType(DataType::TIMESTAMP,_rTypeInfo) ) )
    1350           0 :                     break;
    1351             :             }
    1352             :             // run through
    1353             :         case DataType::TIMESTAMP:
    1354             :         case DataType::REAL:
    1355             :         case DataType::BIGINT:
    1356           0 :             if (  (pTypeInfo = queryTypeInfoByType(DataType::DOUBLE,_rTypeInfo) ) )
    1357           0 :                 break;
    1358             :             // run through
    1359             :         case DataType::DOUBLE:
    1360           0 :             if (  (pTypeInfo = queryTypeInfoByType(DataType::NUMERIC,_rTypeInfo) ) )
    1361           0 :                 break;
    1362             :             // run through
    1363             :         case DataType::NUMERIC:
    1364           0 :              pTypeInfo = queryTypeInfoByType(DataType::DECIMAL,_rTypeInfo);
    1365           0 :             break;
    1366             :         case DataType::DECIMAL:
    1367           0 :             if (  (pTypeInfo = queryTypeInfoByType(DataType::NUMERIC,_rTypeInfo) ) )
    1368           0 :                 break;
    1369           0 :             if (  (pTypeInfo = queryTypeInfoByType(DataType::DOUBLE,_rTypeInfo) ) )
    1370           0 :                 break;
    1371           0 :             break;
    1372             :         case DataType::VARCHAR:
    1373           0 :             if (  (pTypeInfo = queryTypeInfoByType(DataType::LONGVARCHAR,_rTypeInfo) ) )
    1374           0 :                 break;
    1375           0 :             break;
    1376             :         case DataType::LONGVARCHAR:
    1377           0 :             if (  (pTypeInfo = queryTypeInfoByType(DataType::CLOB,_rTypeInfo) ) )
    1378           0 :                 break;
    1379           0 :             break;
    1380             :         default:
    1381             :             ;
    1382             :     }
    1383           0 :     if ( !pTypeInfo )
    1384             :     {
    1385           0 :         ::rtl::OUString sCreate(RTL_CONSTASCII_USTRINGPARAM("x")),sTypeName;
    1386           0 :         sal_Bool bForce = sal_True;
    1387           0 :         pTypeInfo = ::dbaui::getTypeInfoFromType(_rTypeInfo,DataType::VARCHAR,sTypeName,sCreate,50,0,sal_False,bForce);
    1388             :     }
    1389             :     OSL_ENSURE(pTypeInfo,"Wrong DataType supplied!");
    1390           0 :     return pTypeInfo;
    1391             : }
    1392             : // -----------------------------------------------------------------------------
    1393           0 : sal_Int32 askForUserAction(Window* _pParent,sal_uInt16 _nTitle,sal_uInt16 _nText,sal_Bool _bAll,const ::rtl::OUString& _sName)
    1394             : {
    1395           0 :     SolarMutexGuard aGuard;
    1396           0 :     String aMsg = String(ModuleRes(_nText));
    1397           0 :     aMsg.SearchAndReplace(rtl::OUString("%1"),String(_sName));
    1398           0 :     OSQLMessageBox aAsk(_pParent,String(ModuleRes(_nTitle )),aMsg,WB_YES_NO | WB_DEF_YES,OSQLMessageBox::Query);
    1399           0 :     if ( _bAll )
    1400             :     {
    1401           0 :         aAsk.AddButton(String(ModuleRes(STR_BUTTON_TEXT_ALL)), RET_ALL, 0);
    1402           0 :         aAsk.GetPushButton(RET_ALL)->SetHelpId(HID_CONFIRM_DROP_BUTTON_ALL);
    1403             :     }
    1404           0 :     return aAsk.Execute();
    1405             : }
    1406             : 
    1407             : // -----------------------------------------------------------------------------
    1408             : namespace
    1409             : {
    1410           0 :     static ::rtl::OUString lcl_createSDBCLevelStatement( const ::rtl::OUString& _rStatement, const Reference< XConnection >& _rxConnection )
    1411             :     {
    1412           0 :         ::rtl::OUString sSDBCLevelStatement( _rStatement );
    1413             :         try
    1414             :         {
    1415           0 :             Reference< XMultiServiceFactory > xAnalyzerFactory( _rxConnection, UNO_QUERY_THROW );
    1416           0 :             Reference< XSingleSelectQueryAnalyzer > xAnalyzer( xAnalyzerFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
    1417           0 :             xAnalyzer->setQuery( _rStatement );
    1418           0 :             sSDBCLevelStatement = xAnalyzer->getQueryWithSubstitution();
    1419             :         }
    1420           0 :         catch( const Exception& )
    1421             :         {
    1422             :             DBG_UNHANDLED_EXCEPTION();
    1423             :         }
    1424           0 :         return sSDBCLevelStatement;
    1425             :     }
    1426             : }
    1427             : 
    1428             : // -----------------------------------------------------------------------------
    1429           0 : Reference< XPropertySet > createView( const ::rtl::OUString& _rName, const Reference< XConnection >& _rxConnection,
    1430             :                                     const ::rtl::OUString& _rCommand )
    1431             : {
    1432           0 :     Reference<XViewsSupplier> xSup(_rxConnection,UNO_QUERY);
    1433           0 :     Reference< XNameAccess > xViews;
    1434           0 :     if(xSup.is())
    1435           0 :         xViews = xSup->getViews();
    1436           0 :     Reference<XDataDescriptorFactory> xFact(xViews,UNO_QUERY);
    1437             :     OSL_ENSURE(xFact.is(),"No XDataDescriptorFactory available!");
    1438           0 :     if(!xFact.is())
    1439           0 :         return NULL;
    1440             : 
    1441           0 :     Reference<XPropertySet> xView = xFact->createDataDescriptor();
    1442           0 :     if ( !xView.is() )
    1443           0 :         return NULL;
    1444             : 
    1445           0 :     ::rtl::OUString sCatalog,sSchema,sTable;
    1446           0 :     ::dbtools::qualifiedNameComponents(_rxConnection->getMetaData(),
    1447             :                                         _rName,
    1448             :                                         sCatalog,
    1449             :                                         sSchema,
    1450             :                                         sTable,
    1451           0 :                                         ::dbtools::eInDataManipulation);
    1452             : 
    1453           0 :     xView->setPropertyValue(PROPERTY_CATALOGNAME,makeAny(sCatalog));
    1454           0 :     xView->setPropertyValue(PROPERTY_SCHEMANAME,makeAny(sSchema));
    1455           0 :     xView->setPropertyValue(PROPERTY_NAME,makeAny(sTable));
    1456             : 
    1457           0 :     xView->setPropertyValue( PROPERTY_COMMAND, makeAny( _rCommand ) );
    1458             : 
    1459           0 :     Reference<XAppend> xAppend(xViews,UNO_QUERY);
    1460           0 :     if(xAppend.is())
    1461           0 :         xAppend->appendByDescriptor(xView);
    1462             : 
    1463           0 :     xView = NULL;
    1464             :     // we need to reget the view because after appending it it is no longer valid
    1465             :     // but this time it isn't a view object it is a table object with type "VIEW"
    1466           0 :     Reference<XTablesSupplier> xTabSup(_rxConnection,UNO_QUERY);
    1467           0 :     Reference< XNameAccess > xTables;
    1468           0 :     if ( xTabSup.is() )
    1469             :     {
    1470           0 :         xTables = xTabSup->getTables();
    1471           0 :         if ( xTables.is() && xTables->hasByName( _rName ) )
    1472           0 :             xTables->getByName( _rName ) >>= xView;
    1473             :     }
    1474             : 
    1475           0 :     return xView;
    1476             : }
    1477             : 
    1478             : // -----------------------------------------------------------------------------
    1479           0 : Reference<XPropertySet> createView( const ::rtl::OUString& _rName, const Reference< XConnection >& _rxConnection
    1480             :                                    ,const Reference<XPropertySet>& _rxSourceObject)
    1481             : {
    1482           0 :     ::rtl::OUString sCommand;
    1483           0 :     Reference< XPropertySetInfo > xPSI( _rxSourceObject->getPropertySetInfo(), UNO_SET_THROW );
    1484           0 :     if ( xPSI->hasPropertyByName( PROPERTY_COMMAND ) )
    1485             :     {
    1486           0 :         _rxSourceObject->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand;
    1487             : 
    1488           0 :         sal_Bool bEscapeProcessing( sal_False );
    1489           0 :         OSL_VERIFY( _rxSourceObject->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) >>= bEscapeProcessing );
    1490           0 :         if ( bEscapeProcessing )
    1491           0 :             sCommand = lcl_createSDBCLevelStatement( sCommand, _rxConnection );
    1492             :     }
    1493             :     else
    1494             :     {
    1495           0 :         sCommand = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SELECT * FROM " ) );
    1496           0 :         sCommand += composeTableNameForSelect( _rxConnection, _rxSourceObject );
    1497             :     }
    1498           0 :     return createView( _rName, _rxConnection, sCommand );
    1499             : }
    1500             : 
    1501             : // -----------------------------------------------------------------------------
    1502           0 : sal_Bool insertHierachyElement( Window* _pParent, const Reference< XComponentContext >& _rxContext,
    1503             :                            const Reference<XHierarchicalNameContainer>& _xNames,
    1504             :                            const String& _sParentFolder,
    1505             :                            sal_Bool _bForm,
    1506             :                            sal_Bool _bCollection,
    1507             :                            const Reference<XContent>& _xContent,
    1508             :                            sal_Bool _bMove)
    1509             : {
    1510             :     OSL_ENSURE( _xNames.is(), "insertHierachyElement: illegal name container!" );
    1511           0 :     if ( !_xNames.is() )
    1512           0 :         return sal_False;
    1513             : 
    1514           0 :     Reference<XNameAccess> xNameAccess( _xNames, UNO_QUERY );
    1515           0 :     ::rtl::OUString sName = _sParentFolder;
    1516           0 :     if ( _xNames->hasByHierarchicalName(sName) )
    1517             :     {
    1518           0 :         Reference<XChild> xChild(_xNames->getByHierarchicalName(sName),UNO_QUERY);
    1519           0 :         xNameAccess.set(xChild,UNO_QUERY);
    1520           0 :         if ( !xNameAccess.is() && xChild.is() )
    1521           0 :             xNameAccess.set(xChild->getParent(),UNO_QUERY);
    1522             :     }
    1523             : 
    1524             :     OSL_ENSURE( xNameAccess.is(), "insertHierachyElement: could not find the proper name container!" );
    1525           0 :     if ( !xNameAccess.is() )
    1526           0 :         return sal_False;
    1527             : 
    1528           0 :     ::rtl::OUString sNewName;
    1529           0 :     Reference<XPropertySet> xProp(_xContent,UNO_QUERY);
    1530           0 :     if ( xProp.is() )
    1531           0 :         xProp->getPropertyValue(PROPERTY_NAME) >>= sNewName;
    1532             : 
    1533           0 :     if ( !_bMove || sNewName.isEmpty() )
    1534             :     {
    1535           0 :         String sTargetName,sLabel;
    1536           0 :         if ( sNewName.isEmpty() || xNameAccess->hasByName(sNewName) )
    1537             :         {
    1538           0 :             if ( !sNewName.isEmpty() )
    1539           0 :                 sTargetName = sNewName;
    1540             :             else
    1541           0 :                 sTargetName = String(ModuleRes( _bCollection ? STR_NEW_FOLDER : ((_bForm) ? RID_STR_FORM : RID_STR_REPORT)));
    1542           0 :             sLabel = String(ModuleRes( _bCollection ? STR_FOLDER_LABEL  : ((_bForm) ? STR_FRM_LABEL : STR_RPT_LABEL)));
    1543           0 :             sTargetName = ::dbtools::createUniqueName(xNameAccess,sTargetName);
    1544             : 
    1545             : 
    1546             :             // here we have everything needed to create a new query object ...
    1547           0 :             HierarchicalNameCheck aNameChecker( _xNames.get(), sName );
    1548             :             // ... ehm, except a new name
    1549             :             OSaveAsDlg aAskForName( _pParent,
    1550             :                                     _rxContext,
    1551             :                                     sTargetName,
    1552             :                                     sLabel,
    1553             :                                     aNameChecker,
    1554           0 :                                     SAD_ADDITIONAL_DESCRIPTION | SAD_TITLE_PASTE_AS);
    1555           0 :             if ( RET_OK != aAskForName.Execute() )
    1556             :                 // cancelled by the user
    1557           0 :                 return sal_False;
    1558             : 
    1559           0 :             sNewName = aAskForName.getName();
    1560           0 :         }
    1561             :     }
    1562           0 :     else if ( xNameAccess->hasByName(sNewName) )
    1563             :     {
    1564           0 :         String sError(ModuleRes(STR_NAME_ALREADY_EXISTS));
    1565           0 :         sError.SearchAndReplaceAscii("#",sNewName);
    1566           0 :         throw SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")) ,0,Any());
    1567             :     }
    1568             : 
    1569             :     try
    1570             :     {
    1571           0 :         Reference<XMultiServiceFactory> xORB( xNameAccess, UNO_QUERY_THROW );
    1572           0 :         Sequence< Any > aArguments(3);
    1573           0 :         PropertyValue aValue;
    1574             :         // set as folder
    1575           0 :         aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"));
    1576           0 :         aValue.Value <<= sNewName;
    1577           0 :         aArguments[0] <<= aValue;
    1578             :         //parent
    1579           0 :         aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent"));
    1580           0 :         aValue.Value <<= xNameAccess;
    1581           0 :         aArguments[1] <<= aValue;
    1582             : 
    1583           0 :         aValue.Name = PROPERTY_EMBEDDEDOBJECT;
    1584           0 :         aValue.Value <<= _xContent;
    1585           0 :         aArguments[2] <<= aValue;
    1586             : 
    1587           0 :         ::rtl::OUString sServiceName(_bCollection ? ((_bForm) ? SERVICE_NAME_FORM_COLLECTION : SERVICE_NAME_REPORT_COLLECTION) : SERVICE_SDB_DOCUMENTDEFINITION);
    1588             : 
    1589           0 :         Reference<XContent > xNew( xORB->createInstanceWithArguments( sServiceName, aArguments ), UNO_QUERY_THROW );
    1590           0 :         Reference< XNameContainer > xNameContainer( xNameAccess, UNO_QUERY_THROW );
    1591           0 :         xNameContainer->insertByName( sNewName, makeAny( xNew ) );
    1592             :     }
    1593           0 :     catch( const IllegalArgumentException& e )
    1594             :     {
    1595           0 :         ::dbtools::throwGenericSQLException( e.Message, e.Context );
    1596             :     }
    1597           0 :     catch( const Exception& )
    1598             :     {
    1599             :         DBG_UNHANDLED_EXCEPTION();
    1600           0 :         return sal_False;
    1601             :     }
    1602             : 
    1603           0 :     return sal_True;
    1604             : }
    1605             : // -----------------------------------------------------------------------------
    1606           0 : Reference< XNumberFormatter > getNumberFormatter(const Reference< XConnection >& _rxConnection, const Reference< ::com::sun::star::uno::XComponentContext >& _rxContext )
    1607             : {
    1608             :     // ---------------------------------------------------------------
    1609             :     // create a formatter working with the connections format supplier
    1610           0 :     Reference< XNumberFormatter > xFormatter;
    1611             : 
    1612             :     try
    1613             :     {
    1614           0 :         Reference< ::com::sun::star::util::XNumberFormatsSupplier >  xSupplier(::dbtools::getNumberFormats(_rxConnection, sal_True, _rxContext));
    1615             : 
    1616           0 :         if ( xSupplier.is() )
    1617             :         {
    1618             :             // create a new formatter
    1619             :             xFormatter = Reference< util::XNumberFormatter > (
    1620           0 :                 util::NumberFormatter::create( _rxContext ), UNO_QUERY_THROW);
    1621           0 :             xFormatter->attachNumberFormatsSupplier(xSupplier);
    1622           0 :         }
    1623             :     }
    1624           0 :     catch(const Exception&)
    1625             :     {
    1626             :         DBG_UNHANDLED_EXCEPTION();
    1627             :     }
    1628           0 :     return xFormatter;
    1629             : }
    1630             : 
    1631             : 
    1632             : // .........................................................................
    1633           0 : } // dbaui
    1634             : // .........................................................................
    1635             : 
    1636             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10