LCOV - code coverage report
Current view: top level - svx/source/form - fmtools.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 189 0.0 %
Date: 2014-04-14 Functions: 0 22 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 "fmprop.hrc"
      22             : #include "fmservs.hxx"
      23             : #include "svx/fmtools.hxx"
      24             : #include "svx/dbtoolsclient.hxx"
      25             : #include "svx/fmglob.hxx"
      26             : 
      27             : #include <com/sun/star/awt/LineEndFormat.hpp>
      28             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      29             : #include <com/sun/star/beans/XIntrospection.hpp>
      30             : #include <com/sun/star/container/XChild.hpp>
      31             : #include <com/sun/star/form/XForm.hpp>
      32             : #include <com/sun/star/form/XFormComponent.hpp>
      33             : #include <com/sun/star/form/XGridColumnFactory.hpp>
      34             : #include <com/sun/star/io/XActiveDataSink.hpp>
      35             : #include <com/sun/star/io/XActiveDataSource.hpp>
      36             : #include <com/sun/star/io/XObjectInputStream.hpp>
      37             : #include <com/sun/star/io/XObjectOutputStream.hpp>
      38             : #include <com/sun/star/io/XPersistObject.hpp>
      39             : #include <com/sun/star/lang/Locale.hpp>
      40             : #include <com/sun/star/lang/XServiceInfo.hpp>
      41             : #include <com/sun/star/sdb/CommandType.hpp>
      42             : #include <com/sun/star/sdb/ErrorCondition.hpp>
      43             : #include <com/sun/star/sdb/ErrorMessageDialog.hpp>
      44             : #include <com/sun/star/sdb/SQLContext.hpp>
      45             : #include <com/sun/star/sdb/XCompletedConnection.hpp>
      46             : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
      47             : #include <com/sun/star/sdb/XResultSetAccess.hpp>
      48             : #include <com/sun/star/sdbc/DataType.hpp>
      49             : #include <com/sun/star/sdbc/XDataSource.hpp>
      50             : #include <com/sun/star/sdbcx/Privilege.hpp>
      51             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      52             : #include <com/sun/star/task/XInteractionHandler.hpp>
      53             : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      54             : #include <com/sun/star/uno/XNamingService.hpp>
      55             : #include <com/sun/star/util/Language.hpp>
      56             : #include <com/sun/star/util/NumberFormat.hpp>
      57             : #include <com/sun/star/util/XCloneable.hpp>
      58             : #include <com/sun/star/util/XNumberFormatTypes.hpp>
      59             : #include <com/sun/star/util/XNumberFormats.hpp>
      60             : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
      61             : #include <com/sun/star/util/XNumberFormatter.hpp>
      62             : 
      63             : #include <basic/sbxvar.hxx>
      64             : #include <svl/eitem.hxx>
      65             : #include <svl/stritem.hxx>
      66             : #include <comphelper/container.hxx>
      67             : #include <comphelper/extract.hxx>
      68             : #include <comphelper/processfactory.hxx>
      69             : #include <comphelper/property.hxx>
      70             : #include <comphelper/sequence.hxx>
      71             : #include <comphelper/types.hxx>
      72             : #include <comphelper/uno3.hxx>
      73             : #include <connectivity/dbexception.hxx>
      74             : #include <connectivity/dbtools.hxx>
      75             : #include <cppuhelper/typeprovider.hxx>
      76             : #include <rtl/math.hxx>
      77             : #include <sfx2/bindings.hxx>
      78             : #include <toolkit/helper/vclunohelper.hxx>
      79             : #include <tools/debug.hxx>
      80             : #include <vcl/stdtext.hxx>
      81             : #include <vcl/svapp.hxx>
      82             : 
      83             : #include <algorithm>
      84             : 
      85             : using namespace ::com::sun::star::uno;
      86             : using namespace ::com::sun::star::util;
      87             : using namespace ::com::sun::star::lang;
      88             : using namespace ::com::sun::star::frame;
      89             : using namespace ::com::sun::star::awt;
      90             : using namespace ::com::sun::star::beans;
      91             : using namespace ::com::sun::star::container;
      92             : using namespace ::com::sun::star::ui::dialogs;
      93             : using namespace ::com::sun::star::sdbc;
      94             : using namespace ::com::sun::star::sdbcx;
      95             : using namespace ::com::sun::star::sdb;
      96             : using namespace ::com::sun::star::task;
      97             : using namespace ::com::sun::star::form;
      98             : using namespace ::svxform;
      99             : using namespace ::connectivity::simple;
     100             : 
     101             : 
     102             : namespace
     103             : {
     104           0 :     static bool lcl_shouldDisplayError( const Any& _rError )
     105             :     {
     106           0 :         SQLException aError;
     107           0 :         if ( !( _rError >>= aError ) )
     108           0 :             return true;
     109             : 
     110           0 :         if ( ! aError.Message.startsWith( "[OOoBase]" ) )
     111             :             // it is an exception *not* thrown by an OOo Base core component
     112           0 :             return true;
     113             : 
     114             :         // the only exception we do not display ATM is a RowSetVetoException, which
     115             :         // has been raised because an XRowSetApprovalListener vetoed a change
     116           0 :         if ( aError.ErrorCode + ErrorCondition::ROW_SET_OPERATION_VETOED == 0 )
     117           0 :             return false;
     118             : 
     119             :         // everything else is to be displayed
     120           0 :         return true;
     121             :     }
     122             : }
     123             : 
     124             : 
     125           0 : void displayException(const Any& _rExcept, Window* _pParent)
     126             : {
     127             :     // check whether we need to display it
     128           0 :     if ( !lcl_shouldDisplayError( _rExcept ) )
     129           0 :         return;
     130             : 
     131             :     try
     132             :     {
     133             :         // the parent window
     134           0 :         Window* pParentWindow = _pParent ? _pParent : GetpApp()->GetDefDialogParent();
     135           0 :         Reference< XWindow > xParentWindow = VCLUnoHelper::GetInterface(pParentWindow);
     136             : 
     137           0 :         Reference< XExecutableDialog > xErrorDialog = ErrorMessageDialog::create(::comphelper::getProcessComponentContext(), "", xParentWindow, _rExcept);
     138           0 :         xErrorDialog->execute();
     139             :     }
     140           0 :     catch(const Exception&)
     141             :     {
     142             :         OSL_FAIL("displayException: could not display the error message!");
     143             :     }
     144             : }
     145             : 
     146             : 
     147           0 : void displayException(const ::com::sun::star::sdbc::SQLException& _rExcept, Window* _pParent)
     148             : {
     149           0 :     displayException(makeAny(_rExcept), _pParent);
     150           0 : }
     151             : 
     152             : 
     153           0 : void displayException(const ::com::sun::star::sdbc::SQLWarning& _rExcept, Window* _pParent)
     154             : {
     155           0 :     displayException(makeAny(_rExcept), _pParent);
     156           0 : }
     157             : 
     158             : 
     159           0 : void displayException(const ::com::sun::star::sdb::SQLContext& _rExcept, Window* _pParent)
     160             : {
     161           0 :     displayException(makeAny(_rExcept), _pParent);
     162           0 : }
     163             : 
     164             : 
     165           0 : void displayException(const ::com::sun::star::sdb::SQLErrorEvent& _rEvent, Window* _pParent)
     166             : {
     167           0 :     displayException(_rEvent.Reason, _pParent);
     168           0 : }
     169             : 
     170             : 
     171           0 : sal_Int32 getElementPos(const Reference< ::com::sun::star::container::XIndexAccess>& xCont, const Reference< XInterface >& xElement)
     172             : {
     173           0 :     sal_Int32 nIndex = -1;
     174           0 :     if (!xCont.is())
     175           0 :         return nIndex;
     176             : 
     177             : 
     178           0 :     Reference< XInterface > xNormalized( xElement, UNO_QUERY );
     179             :     DBG_ASSERT( xElement.is(), "getElementPos: invalid element!" );
     180           0 :     if ( xNormalized.is() )
     181             :     {
     182             :         // Feststellen an welcher Position sich das Kind befindet
     183           0 :         nIndex = xCont->getCount();
     184           0 :         while (nIndex--)
     185             :         {
     186             :             try
     187             :             {
     188           0 :                 Reference< XInterface > xCurrent(xCont->getByIndex( nIndex ),UNO_QUERY);
     189             :                 DBG_ASSERT( xCurrent.get() == Reference< XInterface >( xCurrent, UNO_QUERY ).get(),
     190             :                     "getElementPos: container element not normalized!" );
     191           0 :                 if ( xNormalized.get() == xCurrent.get() )
     192           0 :                     break;
     193             :             }
     194           0 :             catch(Exception&)
     195             :             {
     196             :                 OSL_FAIL( "getElementPos: caught an exception!" );
     197             :             }
     198             : 
     199             :         }
     200             :     }
     201           0 :     return nIndex;
     202             : }
     203             : 
     204             : 
     205           0 : OUString getLabelName(const Reference< ::com::sun::star::beans::XPropertySet>& xControlModel)
     206             : {
     207           0 :     if (!xControlModel.is())
     208           0 :         return OUString();
     209             : 
     210           0 :     if (::comphelper::hasProperty(FM_PROP_CONTROLLABEL, xControlModel))
     211             :     {
     212           0 :         Reference< ::com::sun::star::beans::XPropertySet> xLabelSet;
     213           0 :         xControlModel->getPropertyValue(FM_PROP_CONTROLLABEL) >>= xLabelSet;
     214           0 :         if (xLabelSet.is() && ::comphelper::hasProperty(FM_PROP_LABEL, xLabelSet))
     215             :         {
     216           0 :             Any aLabel( xLabelSet->getPropertyValue(FM_PROP_LABEL) );
     217           0 :             if ((aLabel.getValueTypeClass() == TypeClass_STRING) && !::comphelper::getString(aLabel).isEmpty())
     218           0 :                 return ::comphelper::getString(aLabel);
     219           0 :         }
     220             :     }
     221             : 
     222           0 :     return ::comphelper::getString(xControlModel->getPropertyValue(FM_PROP_CONTROLSOURCE));
     223             : }
     224             : 
     225             : 
     226             : // = CursorWrapper
     227             : 
     228           0 : CursorWrapper::CursorWrapper(const Reference< ::com::sun::star::sdbc::XRowSet>& _rxCursor, bool bUseCloned)
     229             : {
     230           0 :     ImplConstruct(Reference< ::com::sun::star::sdbc::XResultSet>(_rxCursor, UNO_QUERY), bUseCloned);
     231           0 : }
     232             : 
     233             : 
     234           0 : CursorWrapper::CursorWrapper(const Reference< ::com::sun::star::sdbc::XResultSet>& _rxCursor, bool bUseCloned)
     235             : {
     236           0 :     ImplConstruct(_rxCursor, bUseCloned);
     237           0 : }
     238             : 
     239             : 
     240           0 : void CursorWrapper::ImplConstruct(const Reference< ::com::sun::star::sdbc::XResultSet>& _rxCursor, bool bUseCloned)
     241             : {
     242           0 :     if (bUseCloned)
     243             :     {
     244           0 :         Reference< ::com::sun::star::sdb::XResultSetAccess> xAccess(_rxCursor, UNO_QUERY);
     245             :         try
     246             :         {
     247           0 :             m_xMoveOperations = xAccess.is() ? xAccess->createResultSet() : Reference< ::com::sun::star::sdbc::XResultSet>();
     248             :         }
     249           0 :         catch(Exception&)
     250             :         {
     251           0 :         }
     252             :     }
     253             :     else
     254           0 :         m_xMoveOperations   = _rxCursor;
     255             : 
     256           0 :     m_xBookmarkOperations   = m_xBookmarkOperations.query( m_xMoveOperations );
     257           0 :     m_xColumnsSupplier      = m_xColumnsSupplier.query( m_xMoveOperations );
     258           0 :     m_xPropertyAccess       = m_xPropertyAccess.query( m_xMoveOperations );
     259             : 
     260           0 :     if ( !m_xMoveOperations.is() || !m_xBookmarkOperations.is() || !m_xColumnsSupplier.is() || !m_xPropertyAccess.is() )
     261             :     {   // all or nothing !!
     262           0 :         m_xMoveOperations = NULL;
     263           0 :         m_xBookmarkOperations = NULL;
     264           0 :         m_xColumnsSupplier = NULL;
     265             :     }
     266             :     else
     267           0 :         m_xGeneric = m_xMoveOperations.get();
     268           0 : }
     269             : 
     270             : 
     271           0 : const CursorWrapper& CursorWrapper::operator=(const Reference< ::com::sun::star::sdbc::XRowSet>& _rxCursor)
     272             : {
     273           0 :     m_xMoveOperations = Reference< ::com::sun::star::sdbc::XResultSet>(_rxCursor, UNO_QUERY);
     274           0 :     m_xBookmarkOperations = Reference< ::com::sun::star::sdbcx::XRowLocate>(_rxCursor, UNO_QUERY);
     275           0 :     m_xColumnsSupplier = Reference< ::com::sun::star::sdbcx::XColumnsSupplier>(_rxCursor, UNO_QUERY);
     276           0 :     if (!m_xMoveOperations.is() || !m_xBookmarkOperations.is() || !m_xColumnsSupplier.is())
     277             :     {   // all or nothing !!
     278           0 :         m_xMoveOperations = NULL;
     279           0 :         m_xBookmarkOperations = NULL;
     280           0 :         m_xColumnsSupplier = NULL;
     281             :     }
     282           0 :     return *this;
     283             : }
     284             : 
     285             : 
     286           0 : FmXDisposeListener::~FmXDisposeListener()
     287             : {
     288           0 :     setAdapter(NULL);
     289           0 : }
     290             : 
     291             : 
     292           0 : void FmXDisposeListener::setAdapter(FmXDisposeMultiplexer* pAdapter)
     293             : {
     294           0 :     if (m_pAdapter)
     295             :     {
     296           0 :         ::osl::MutexGuard aGuard(m_rMutex);
     297           0 :         m_pAdapter->release();
     298           0 :         m_pAdapter = NULL;
     299             :     }
     300             : 
     301           0 :     if (pAdapter)
     302             :     {
     303           0 :         ::osl::MutexGuard aGuard(m_rMutex);
     304           0 :         m_pAdapter = pAdapter;
     305           0 :         m_pAdapter->acquire();
     306             :     }
     307           0 : }
     308             : 
     309             : 
     310             : 
     311           0 : FmXDisposeMultiplexer::FmXDisposeMultiplexer(FmXDisposeListener* _pListener, const Reference< ::com::sun::star::lang::XComponent>& _rxObject, sal_Int16 _nId)
     312             :     :m_xObject(_rxObject)
     313             :     ,m_pListener(_pListener)
     314           0 :     ,m_nId(_nId)
     315             : {
     316           0 :     m_pListener->setAdapter(this);
     317             : 
     318           0 :     if (m_xObject.is())
     319           0 :         m_xObject->addEventListener(this);
     320           0 : }
     321             : 
     322             : 
     323           0 : FmXDisposeMultiplexer::~FmXDisposeMultiplexer()
     324             : {
     325           0 : }
     326             : 
     327             : // ::com::sun::star::lang::XEventListener
     328             : 
     329           0 : void FmXDisposeMultiplexer::disposing(const ::com::sun::star::lang::EventObject& _Source) throw( RuntimeException, std::exception )
     330             : {
     331           0 :     Reference< ::com::sun::star::lang::XEventListener> xPreventDelete(this);
     332             : 
     333           0 :     if (m_pListener)
     334             :     {
     335           0 :         m_pListener->disposing(_Source, m_nId);
     336           0 :         m_pListener->setAdapter(NULL);
     337           0 :         m_pListener = NULL;
     338             :     }
     339           0 :     m_xObject = NULL;
     340           0 : }
     341             : 
     342             : 
     343           0 : void FmXDisposeMultiplexer::dispose()
     344             : {
     345           0 :     if (m_xObject.is())
     346             :     {
     347           0 :         Reference< ::com::sun::star::lang::XEventListener> xPreventDelete(this);
     348             : 
     349           0 :         m_xObject->removeEventListener(this);
     350           0 :         m_xObject = NULL;
     351             : 
     352           0 :         m_pListener->setAdapter(NULL);
     353           0 :         m_pListener = NULL;
     354             :     }
     355           0 : }
     356             : 
     357             : 
     358             : 
     359           0 : sal_Int16 getControlTypeByObject(const Reference< ::com::sun::star::lang::XServiceInfo>& _rxObject)
     360             : {
     361             :     // ask for the persistent service name
     362           0 :     Reference< ::com::sun::star::io::XPersistObject> xPersistence(_rxObject, UNO_QUERY);
     363             :     DBG_ASSERT(xPersistence.is(), "::getControlTypeByObject : argument shold be an ::com::sun::star::io::XPersistObject !");
     364           0 :     if (!xPersistence.is())
     365           0 :         return OBJ_FM_CONTROL;
     366             : 
     367           0 :     OUString sPersistentServiceName = xPersistence->getServiceName();
     368           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_EDIT))   // 5.0-Name
     369             :     {
     370             :         // may be a simple edit field or a formatted field, dependent of the supported services
     371           0 :         if (_rxObject->supportsService(FM_SUN_COMPONENT_FORMATTEDFIELD))
     372           0 :             return OBJ_FM_FORMATTEDFIELD;
     373           0 :         return OBJ_FM_EDIT;
     374             :     }
     375           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_TEXTFIELD))
     376           0 :         return OBJ_FM_EDIT;
     377           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_COMMANDBUTTON))
     378           0 :         return OBJ_FM_BUTTON;
     379           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_FIXEDTEXT))
     380           0 :         return OBJ_FM_FIXEDTEXT;
     381           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_LISTBOX))
     382           0 :         return OBJ_FM_LISTBOX;
     383           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_CHECKBOX))
     384           0 :         return OBJ_FM_CHECKBOX;
     385           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_RADIOBUTTON))
     386           0 :         return OBJ_FM_RADIOBUTTON;
     387           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_GROUPBOX))
     388           0 :         return OBJ_FM_GROUPBOX;
     389           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_COMBOBOX))
     390           0 :         return OBJ_FM_COMBOBOX;
     391           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_GRID))   // 5.0-Name
     392           0 :         return OBJ_FM_GRID;
     393           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_GRIDCONTROL))
     394           0 :         return OBJ_FM_GRID;
     395           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_IMAGEBUTTON))
     396           0 :         return OBJ_FM_IMAGEBUTTON;
     397           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_FILECONTROL))
     398           0 :         return OBJ_FM_FILECONTROL;
     399           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_DATEFIELD))
     400           0 :         return OBJ_FM_DATEFIELD;
     401           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_TIMEFIELD))
     402           0 :         return OBJ_FM_TIMEFIELD;
     403           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_NUMERICFIELD))
     404           0 :         return OBJ_FM_NUMERICFIELD;
     405           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_CURRENCYFIELD))
     406           0 :         return OBJ_FM_CURRENCYFIELD;
     407           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_PATTERNFIELD))
     408           0 :         return OBJ_FM_PATTERNFIELD;
     409           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_HIDDEN)) // 5.0-Name
     410           0 :         return OBJ_FM_HIDDEN;
     411           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_HIDDENCONTROL))
     412           0 :         return OBJ_FM_HIDDEN;
     413           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_IMAGECONTROL))
     414           0 :         return OBJ_FM_IMAGECONTROL;
     415           0 :     if (sPersistentServiceName.equals(FM_COMPONENT_FORMATTEDFIELD))
     416             :     {
     417             :         OSL_FAIL("::getControlTypeByObject : suspicious persistent service name (formatted field) !");
     418             :             // objects with that service name should exist as they aren't compatible with older versions
     419           0 :         return OBJ_FM_FORMATTEDFIELD;
     420             :     }
     421           0 :     if ( sPersistentServiceName.equals( FM_SUN_COMPONENT_SCROLLBAR ) )
     422           0 :         return OBJ_FM_SCROLLBAR;
     423           0 :     if ( sPersistentServiceName.equals( FM_SUN_COMPONENT_SPINBUTTON) )
     424           0 :         return OBJ_FM_SPINBUTTON;
     425           0 :     if (sPersistentServiceName.equals(FM_SUN_COMPONENT_NAVIGATIONBAR))
     426           0 :         return OBJ_FM_NAVIGATIONBAR;
     427             : 
     428             :     OSL_FAIL("::getControlTypeByObject : unknown object type !");
     429           0 :     return OBJ_FM_CONTROL;
     430             : }
     431             : 
     432             : 
     433           0 : bool isRowSetAlive(const Reference< XInterface >& _rxRowSet)
     434             : {
     435           0 :     bool bIsAlive = false;
     436           0 :     Reference< ::com::sun::star::sdbcx::XColumnsSupplier> xSupplyCols(_rxRowSet, UNO_QUERY);
     437           0 :     Reference< ::com::sun::star::container::XIndexAccess> xCols;
     438           0 :     if (xSupplyCols.is())
     439           0 :         xCols = Reference< ::com::sun::star::container::XIndexAccess>(xSupplyCols->getColumns(), UNO_QUERY);
     440           0 :     if (xCols.is() && (xCols->getCount() > 0))
     441           0 :         bIsAlive = true;
     442             : 
     443           0 :     return bIsAlive;
     444             : }
     445             : 
     446             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10