LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/dbaccess/source/ui/browser - sbagrid.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 110 742 14.8 %
Date: 2013-07-09 Functions: 33 83 39.8 %
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 "sbagrid.hrc"
      22             : 
      23             : #include <svx/svxids.hrc>
      24             : 
      25             : #include <svx/numinf.hxx>
      26             : #include <svx/dbaexchange.hxx>
      27             : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      28             : 
      29             : #include "sbagrid.hxx"
      30             : #include "dlgattr.hxx"
      31             : #include "dlgsize.hxx"
      32             : #include <com/sun/star/form/XLoadable.hpp>
      33             : #include <com/sun/star/form/ControlFontDialog.hpp>
      34             : #include <com/sun/star/sdb/CommandType.hpp>
      35             : #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
      36             : #include <com/sun/star/sdb/XResultSetAccess.hpp>
      37             : #include <com/sun/star/form/XForm.hpp>
      38             : #include <com/sun/star/container/XIndexContainer.hpp>
      39             : #include <com/sun/star/util/NumberFormat.hpp>
      40             : 
      41             : #include <com/sun/star/view/XSelectionSupplier.hpp>
      42             : #include <com/sun/star/form/DataSelectionType.hpp>
      43             : #include <com/sun/star/awt/TextAlign.hpp>
      44             : #include <com/sun/star/awt/XTextComponent.hpp>
      45             : #include <com/sun/star/util/Date.hpp>
      46             : #include <com/sun/star/util/Time.hpp>
      47             : #include <com/sun/star/util/DateTime.hpp>
      48             : #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
      49             : #include <tools/diagnose_ex.h>
      50             : 
      51             : #include <svl/intitem.hxx>
      52             : #include <svx/algitem.hxx>
      53             : #include <tools/multisel.hxx>
      54             : #include <svl/numuno.hxx>
      55             : #include <svl/itempool.hxx>
      56             : #include <svl/itemset.hxx>
      57             : #include <svl/rngitem.hxx>
      58             : 
      59             : #include <vcl/waitobj.hxx>
      60             : #include <toolkit/helper/vclunohelper.hxx>
      61             : 
      62             : #include <svl/zforlist.hxx>
      63             : #include <cppuhelper/queryinterface.hxx>
      64             : #include <connectivity/dbtools.hxx>
      65             : #include <connectivity/dbconversion.hxx>
      66             : #include <cppuhelper/typeprovider.hxx>
      67             : #include <comphelper/extract.hxx>
      68             : #include <comphelper/servicehelper.hxx>
      69             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      70             : #include <com/sun/star/sdbc/DataType.hpp>
      71             : #include <vcl/msgbox.hxx>
      72             : #include "dbu_brw.hrc"
      73             : #include "browserids.hxx"
      74             : #include "dbustrings.hrc"
      75             : #include "dbu_reghelper.hxx"
      76             : #include "dbexchange.hxx"
      77             : #include "TableRowExchange.hxx"
      78             : #include "TableRow.hxx"
      79             : #include "FieldDescriptions.hxx"
      80             : #include <svtools/stringtransfer.hxx>
      81             : #include <vcl/stdtext.hxx>
      82             : #include "UITools.hxx"
      83             : #include "TokenWriter.hxx"
      84             : #include <osl/diagnose.h>
      85             : 
      86             : using namespace ::com::sun::star::ui::dialogs;
      87             : using namespace ::com::sun::star::uno;
      88             : using namespace ::com::sun::star::sdb;
      89             : using namespace ::com::sun::star::sdbc;
      90             : using namespace ::com::sun::star::sdbcx;
      91             : using namespace ::com::sun::star::beans;
      92             : using namespace ::com::sun::star::container;
      93             : using namespace ::com::sun::star::datatransfer;
      94             : using namespace ::com::sun::star::lang;
      95             : using namespace ::com::sun::star::view;
      96             : using namespace ::com::sun::star::form;
      97             : using namespace ::com::sun::star::frame;
      98             : using namespace ::com::sun::star::util;
      99             : using namespace ::dbaui;
     100             : using namespace ::dbtools;
     101             : using namespace ::svx;
     102             : using namespace ::svt;
     103             : 
     104           4 : extern "C" void SAL_CALL createRegistryInfo_SbaXGridControl()
     105             : {
     106           4 :     static OMultiInstanceAutoRegistration< SbaXGridControl > aAutoRegistration;
     107           4 : }
     108             : //-------------------------------------------------------------------------
     109           0 : ::comphelper::StringSequence SAL_CALL SbaXGridControl::getSupportedServiceNames() throw()
     110             : {
     111           0 :     return getSupportedServiceNames_Static();
     112             : }
     113             : // -------------------------------------------------------------------------
     114          10 : Reference< XInterface > SAL_CALL SbaXGridControl::Create(const Reference<XMultiServiceFactory >& _rxFactory)
     115             : {
     116          10 :     return *(new SbaXGridControl( comphelper::getComponentContext(_rxFactory) ));
     117             : }
     118             : 
     119             : //------------------------------------------------------------------
     120             : 
     121             : //------------------------------------------------------------------
     122             : //=======================================================================================
     123             : // SbaXGridControl
     124             : //=======================================================================================
     125             : 
     126             : //------------------------------------------------------------------------------
     127           0 : OUString SAL_CALL SbaXGridControl::getImplementationName() throw()
     128             : {
     129           0 :     return getImplementationName_Static();
     130             : }
     131             : 
     132             : //------------------------------------------------------------------------------
     133           8 : OUString SbaXGridControl::getImplementationName_Static() throw( RuntimeException )
     134             : {
     135           8 :     return OUString("com.sun.star.comp.dbu.SbaXGridControl");
     136             : }
     137             : 
     138             : //------------------------------------------------------------------------------
     139           4 : Sequence< OUString> SbaXGridControl::getSupportedServiceNames_Static(void) throw( RuntimeException )
     140             : {
     141           4 :     Sequence< OUString> aSupported(3);
     142           4 :     aSupported[0] = OUString("com.sun.star.form.control.InteractionGridControl");
     143           4 :     aSupported[1] = OUString("com.sun.star.form.control.GridControl");
     144           4 :     aSupported[2] = OUString("com.sun.star.awt.UnoControl");
     145           4 :     return aSupported;
     146             : }
     147             : DBG_NAME(SbaXGridControl );
     148             : //---------------------------------------------------------------------------------------
     149          11 : SbaXGridControl::SbaXGridControl(const Reference< XComponentContext >& _rM)
     150          11 :     : FmXGridControl(_rM)
     151             : {
     152             :     DBG_CTOR(SbaXGridControl ,NULL);
     153          11 : }
     154             : 
     155             : //---------------------------------------------------------------------------------------
     156          22 : SbaXGridControl::~SbaXGridControl()
     157             : {
     158             :     DBG_DTOR(SbaXGridControl ,NULL);
     159          22 : }
     160             : 
     161             : //---------------------------------------------------------------------------------------
     162          21 : FmXGridPeer* SbaXGridControl::imp_CreatePeer(Window* pParent)
     163             : {
     164          21 :     FmXGridPeer* pReturn = new SbaXGridPeer(m_xContext);
     165             : 
     166             :     // translate properties into WinBits
     167          21 :     WinBits nStyle = WB_TABSTOP;
     168          21 :     Reference< XPropertySet >  xModelSet(getModel(), UNO_QUERY);
     169          21 :     if (xModelSet.is())
     170             :     {
     171             :         try
     172             :         {
     173          21 :             if (::comphelper::getINT16(xModelSet->getPropertyValue(PROPERTY_BORDER)))
     174          21 :                 nStyle |= WB_BORDER;
     175             :         }
     176           0 :         catch(Exception&)
     177             :         {
     178             :         }
     179             : 
     180             :     }
     181             : 
     182          21 :     pReturn->Create(pParent, nStyle);
     183          21 :     return pReturn;
     184             : }
     185             : 
     186             : //------------------------------------------------------------------------------
     187         447 : Any SAL_CALL SbaXGridControl::queryInterface(const Type& _rType) throw (RuntimeException)
     188             : {
     189         447 :     Any aRet = FmXGridControl::queryInterface(_rType);
     190         447 :     return aRet.hasValue() ? aRet : ::cppu::queryInterface(_rType,(::com::sun::star::frame::XDispatch*)this);
     191             : }
     192             : 
     193             : //------------------------------------------------------------------------------
     194           0 : Sequence< Type > SAL_CALL SbaXGridControl::getTypes(  ) throw (RuntimeException)
     195             : {
     196           0 :     Sequence< Type > aTypes = FmXGridControl::getTypes();
     197             : 
     198           0 :     sal_Int32 nTypes = aTypes.getLength();
     199           0 :     aTypes.realloc(nTypes + 1);
     200           0 :     aTypes[nTypes] = ::getCppuType(static_cast< Reference< ::com::sun::star::frame::XDispatch >* >(NULL));
     201             : 
     202           0 :     return aTypes;
     203             : }
     204             : 
     205             : //------------------------------------------------------------------------------
     206           0 : Sequence< sal_Int8 > SAL_CALL SbaXGridControl::getImplementationId(  ) throw (RuntimeException)
     207             : {
     208             :     static ::cppu::OImplementationId * pId = 0;
     209           0 :     if (! pId)
     210             :     {
     211           0 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     212           0 :         if (! pId)
     213             :         {
     214           0 :             static ::cppu::OImplementationId aId;
     215           0 :             pId = &aId;
     216           0 :         }
     217             :     }
     218           0 :     return pId->getImplementationId();
     219             : }
     220             : 
     221             : //---------------------------------------------------------------------------------------
     222          21 : void SAL_CALL SbaXGridControl::createPeer(const Reference< ::com::sun::star::awt::XToolkit > & rToolkit, const Reference< ::com::sun::star::awt::XWindowPeer > & rParentPeer) throw( RuntimeException )
     223             : {
     224          21 :     FmXGridControl::createPeer(rToolkit, rParentPeer);
     225             : 
     226             :     OSL_ENSURE(!mbCreatingPeer, "FmXGridControl::createPeer : recursion!");
     227             :         // see the base class' createPeer for a comment on this
     228             : 
     229             :     // TODO: why the hell this whole class does not use any mutex?
     230             : 
     231          21 :         Reference< ::com::sun::star::frame::XDispatch >  xDisp(getPeer(), UNO_QUERY);
     232          63 :         for (   StatusMultiplexerArray::iterator aIter = m_aStatusMultiplexer.begin();
     233          42 :                 aIter != m_aStatusMultiplexer.end();
     234             :                 ++aIter)
     235             :         {
     236           0 :             if ((*aIter).second && (*aIter).second->getLength())
     237           0 :                 xDisp->addStatusListener((*aIter).second, (*aIter).first);
     238          21 :         }
     239          21 : }
     240             : 
     241             : //---------------------------------------------------------------------------------------
     242           0 : void SAL_CALL SbaXGridControl::dispatch(const ::com::sun::star::util::URL& aURL, const Sequence< PropertyValue >& aArgs) throw( RuntimeException )
     243             : {
     244           0 :     Reference< ::com::sun::star::frame::XDispatch >  xDisp(getPeer(), UNO_QUERY);
     245           0 :     if (xDisp.is())
     246           0 :         xDisp->dispatch(aURL, aArgs);
     247           0 : }
     248             : //---------------------------------------------------------------------------------------
     249           0 : void SAL_CALL SbaXGridControl::addStatusListener( const Reference< XStatusListener > & _rxListener, const URL& _rURL ) throw( RuntimeException )
     250             : {
     251           0 :     ::osl::MutexGuard aGuard( GetMutex() );
     252           0 :     if ( _rxListener.is() )
     253             :     {
     254           0 :         SbaXStatusMultiplexer*& pMultiplexer = m_aStatusMultiplexer[ _rURL ];
     255           0 :         if ( !pMultiplexer )
     256             :         {
     257           0 :             pMultiplexer = new SbaXStatusMultiplexer( *this, GetMutex() );
     258           0 :             pMultiplexer->acquire();
     259             :         }
     260             : 
     261           0 :         pMultiplexer->addInterface( _rxListener );
     262           0 :         if ( getPeer().is() )
     263             :         {
     264           0 :             if ( 1 == pMultiplexer->getLength() )
     265             :             {   // the first external listener for this URL
     266           0 :                 Reference< XDispatch >  xDisp( getPeer(), UNO_QUERY );
     267           0 :                 xDisp->addStatusListener( pMultiplexer, _rURL );
     268             :             }
     269             :             else
     270             :             {   // already have other listeners for this URL
     271           0 :                 _rxListener->statusChanged( pMultiplexer->getLastEvent() );
     272             :             }
     273             :         }
     274           0 :     }
     275           0 : }
     276             : 
     277             : //---------------------------------------------------------------------------------------
     278           0 : void SAL_CALL SbaXGridControl::removeStatusListener(const Reference< ::com::sun::star::frame::XStatusListener > & _rxListener, const ::com::sun::star::util::URL& _rURL) throw( RuntimeException )
     279             : {
     280           0 :     ::osl::MutexGuard aGuard( GetMutex() );
     281             : 
     282           0 :     SbaXStatusMultiplexer*& pMultiplexer = m_aStatusMultiplexer[_rURL];
     283           0 :     if (!pMultiplexer)
     284             :     {
     285           0 :         pMultiplexer = new SbaXStatusMultiplexer(*this,GetMutex());
     286           0 :         pMultiplexer->acquire();
     287             :     }
     288             : 
     289           0 :     if (getPeer().is() && pMultiplexer->getLength() == 1)
     290             :     {
     291           0 :         Reference< ::com::sun::star::frame::XDispatch >  xDisp(getPeer(), UNO_QUERY);
     292           0 :         xDisp->removeStatusListener(pMultiplexer, _rURL);
     293             :     }
     294           0 :     pMultiplexer->removeInterface( _rxListener );
     295           0 : }
     296             : 
     297             : //---------------------------------------------------------------------------------------
     298          12 : void SAL_CALL SbaXGridControl::dispose(void) throw( RuntimeException )
     299             : {
     300          12 :     SolarMutexGuard aGuard;
     301             : 
     302          24 :     EventObject aEvt;
     303          12 :     aEvt.Source = *this;
     304             : 
     305          36 :     for (   StatusMultiplexerArray::iterator aIter = m_aStatusMultiplexer.begin();
     306          24 :             aIter != m_aStatusMultiplexer.end();
     307             :             ++aIter)
     308             :     {
     309           0 :         if ((*aIter).second)
     310             :         {
     311           0 :             (*aIter).second->disposeAndClear(aEvt);
     312           0 :             (*aIter).second->release();
     313           0 :             (*aIter).second = NULL;
     314             :         }
     315             :     }
     316          12 :     StatusMultiplexerArray().swap(m_aStatusMultiplexer);
     317             : 
     318          24 :     FmXGridControl::dispose();
     319          12 : }
     320             : 
     321             : //=======================================================================================
     322             : // SbaXGridPeer
     323             : //=======================================================================================
     324             : DBG_NAME(SbaXGridPeer )
     325             : //---------------------------------------------------------------------------------------
     326          21 : SbaXGridPeer::SbaXGridPeer(const Reference< XComponentContext >& _rM)
     327             : : FmXGridPeer(_rM)
     328          21 : ,m_aStatusListeners(m_aMutex)
     329             : {
     330             :     DBG_CTOR(SbaXGridPeer ,NULL);
     331          21 : }
     332             : 
     333             : //---------------------------------------------------------------------------------------
     334          42 : SbaXGridPeer::~SbaXGridPeer()
     335             : {
     336             :     DBG_DTOR(SbaXGridPeer ,NULL);
     337          42 : }
     338             : 
     339             : //---------------------------------------------------------------------------------------
     340          42 : void SAL_CALL SbaXGridPeer::dispose(void) throw( RuntimeException )
     341             : {
     342          42 :     EventObject aEvt(*this);
     343             : 
     344          42 :     m_aStatusListeners.disposeAndClear(aEvt);
     345             : 
     346          42 :     FmXGridPeer::dispose();
     347          42 : }
     348             : 
     349             : //---------------------------------------------------------------------------------------
     350           0 : void SbaXGridPeer::NotifyStatusChanged(const ::com::sun::star::util::URL& _rUrl, const Reference< ::com::sun::star::frame::XStatusListener > & xControl)
     351             : {
     352           0 :     SbaGridControl* pGrid = (SbaGridControl*) GetWindow();
     353           0 :     if (!pGrid)
     354           0 :         return;
     355             : 
     356           0 :     ::com::sun::star::frame::FeatureStateEvent aEvt;
     357           0 :     aEvt.Source = *this;
     358           0 :     aEvt.IsEnabled = !pGrid->IsReadOnlyDB();
     359           0 :     aEvt.FeatureURL = _rUrl;
     360             : 
     361           0 :     ConstMapDispatchToBoolIterator aURLStatePos = m_aDispatchStates.find( classifyDispatchURL( _rUrl ) );
     362           0 :     if ( m_aDispatchStates.end() != aURLStatePos )
     363           0 :         aEvt.State <<= aURLStatePos->second;
     364             :     else
     365           0 :         aEvt.State <<= sal_False;
     366             : 
     367           0 :     if (xControl.is())
     368           0 :         xControl->statusChanged(aEvt);
     369             :     else
     370             :     {
     371           0 :         ::cppu::OInterfaceContainerHelper * pIter = m_aStatusListeners.getContainer(_rUrl);
     372             : 
     373           0 :         if (pIter)
     374             :         {
     375           0 :             ::cppu::OInterfaceIteratorHelper aListIter(*pIter);
     376           0 :             while (aListIter.hasMoreElements())
     377           0 :                 ((::com::sun::star::frame::XStatusListener*)aListIter.next())->statusChanged(aEvt);
     378             :         }
     379           0 :     }
     380             : }
     381             : 
     382             : //------------------------------------------------------------------------------
     383        1254 : Any SAL_CALL SbaXGridPeer::queryInterface(const Type& _rType) throw (RuntimeException)
     384             : {
     385        1254 :     Any aRet = ::cppu::queryInterface(_rType,(::com::sun::star::frame::XDispatch*)this);
     386        1254 :     if(aRet.hasValue())
     387          21 :         return aRet;
     388        1233 :     return FmXGridPeer::queryInterface(_rType);
     389             : }
     390             : 
     391             : //---------------------------------------------------------------------------------------
     392          21 : Reference< ::com::sun::star::frame::XDispatch >  SAL_CALL SbaXGridPeer::queryDispatch(const ::com::sun::star::util::URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags) throw( RuntimeException )
     393             : {
     394          63 :     if  (   ( aURL.Complete == ".uno:GridSlots/BrowserAttribs" ) || ( aURL.Complete == ".uno:GridSlots/RowHeight" )
     395          42 :         ||  ( aURL.Complete == ".uno:GridSlots/ColumnAttribs" )  || ( aURL.Complete == ".uno:GridSlots/ColumnWidth" )
     396             :         )
     397             :     {
     398           0 :         return (::com::sun::star::frame::XDispatch*)this;
     399             :     }
     400             : 
     401          21 :     return FmXGridPeer::queryDispatch(aURL, aTargetFrameName, nSearchFlags);
     402             : }
     403             : 
     404             : //---------------------------------------------------------------------------------------
     405           0 : IMPL_LINK( SbaXGridPeer, OnDispatchEvent, void*, /*NOTINTERESTEDIN*/ )
     406             : {
     407           0 :     SbaGridControl* pGrid = static_cast< SbaGridControl* >( GetWindow() );
     408           0 :     if ( pGrid )    // if this fails, we were disposing before arriving here
     409             :     {
     410           0 :         if ( Application::GetMainThreadIdentifier() != ::osl::Thread::getCurrentIdentifier() )
     411             :         {
     412             :             // still not in the main thread (see SbaXGridPeer::dispatch). post an event, again
     413             :             // without moving the special even to the back of the queue
     414           0 :             pGrid->PostUserEvent( LINK( this, SbaXGridPeer, OnDispatchEvent ) );
     415             :         }
     416             :         else
     417             :         {
     418           0 :             DispatchArgs aArgs = m_aDispatchArgs.front();
     419           0 :             m_aDispatchArgs.pop();
     420             : 
     421           0 :             SbaXGridPeer::dispatch( aArgs.aURL, aArgs.aArgs );
     422             :         }
     423             :     }
     424             : 
     425           0 :     return 0;
     426             : }
     427             : 
     428             : //---------------------------------------------------------------------------------------
     429           0 : SbaXGridPeer::DispatchType SbaXGridPeer::classifyDispatchURL( const URL& _rURL )
     430             : {
     431           0 :     DispatchType eURLType = dtUnknown;
     432           0 :     if ( _rURL.Complete == ".uno:GridSlots/BrowserAttribs" )
     433           0 :         eURLType = dtBrowserAttribs;
     434           0 :     else if ( _rURL.Complete == ".uno:GridSlots/RowHeight" )
     435           0 :         eURLType = dtRowHeight;
     436           0 :     else if ( _rURL.Complete == ".uno:GridSlots/ColumnAttribs" )
     437           0 :         eURLType = dtColumnAttribs;
     438           0 :     else if ( _rURL.Complete == ".uno:GridSlots/ColumnWidth" )
     439           0 :         eURLType = dtColumnWidth;
     440           0 :     return eURLType;
     441             : }
     442             : 
     443             : //---------------------------------------------------------------------------------------
     444           0 : void SAL_CALL SbaXGridPeer::dispatch(const URL& aURL, const Sequence< PropertyValue >& aArgs) throw( RuntimeException )
     445             : {
     446           0 :     SbaGridControl* pGrid = (SbaGridControl*)GetWindow();
     447           0 :     if (!pGrid)
     448           0 :         return;
     449             : 
     450           0 :     if ( Application::GetMainThreadIdentifier() != ::osl::Thread::getCurrentIdentifier() )
     451             :     {
     452             :         // we're not in the main thread. This is bad, as we want to raise windows here,
     453             :         // and VCL does not like windows to be opened in non-main threads (at least on Win32).
     454             :         // Okay, do this async. No problem with this, as XDispatch::dispatch is defined to be
     455             :         // a one-way method.
     456             : 
     457             :         // save the args
     458           0 :         DispatchArgs aDispatchArgs;
     459           0 :         aDispatchArgs.aURL = aURL;
     460           0 :         aDispatchArgs.aArgs = aArgs;
     461           0 :         m_aDispatchArgs.push( aDispatchArgs );
     462             : 
     463             :         // post an event
     464             :         // we use the Window::PostUserEvent here, instead of the application::PostUserEvent
     465             :         // this saves us from keeping track of these events - as soon as the window dies,
     466             :         // the events are deleted automatically. For the application way, we would need to
     467             :         // do this ourself.
     468             :         // As we use our grid as window, and the grid dies before we dy, this should be no problem.
     469           0 :         pGrid->PostUserEvent( LINK( this, SbaXGridPeer, OnDispatchEvent ) );
     470           0 :         return;
     471             :     }
     472             : 
     473           0 :     SolarMutexGuard aGuard;
     474           0 :     sal_Int16 nColId = -1;
     475           0 :     const PropertyValue* pArgs = aArgs.getConstArray();
     476           0 :     for (sal_uInt16 i=0; i<aArgs.getLength(); ++i, ++pArgs)
     477             :     {
     478           0 :         if (pArgs->Name == OUString("ColumnViewPos"))
     479             :         {
     480           0 :             nColId = pGrid->GetColumnIdFromViewPos(::comphelper::getINT16(pArgs->Value));
     481           0 :             break;
     482             :         }
     483           0 :         if (pArgs->Name == OUString("ColumnModelPos"))
     484             :         {
     485           0 :             nColId = pGrid->GetColumnIdFromModelPos(::comphelper::getINT16(pArgs->Value));
     486           0 :             break;
     487             :         }
     488           0 :         if (pArgs->Name == OUString("ColumnId"))
     489             :         {
     490           0 :             nColId = ::comphelper::getINT16(pArgs->Value);
     491           0 :             break;
     492             :         }
     493             :     }
     494             : 
     495           0 :     DispatchType eURLType = classifyDispatchURL( aURL );
     496             : 
     497           0 :     if ( dtUnknown != eURLType )
     498             :     {
     499             :         // notify any status listeners that the dialog is now active (well, about to be active)
     500           0 :         MapDispatchToBool::iterator aThisURLState = m_aDispatchStates.insert( MapDispatchToBool::value_type( eURLType, sal_True ) ).first;
     501           0 :         NotifyStatusChanged( aURL, NULL );
     502             : 
     503             :         // execute the dialog
     504           0 :         switch ( eURLType )
     505             :         {
     506             :             case dtBrowserAttribs:
     507           0 :                 pGrid->SetBrowserAttrs();
     508           0 :                 break;
     509             : 
     510             :             case dtRowHeight:
     511           0 :                 pGrid->SetRowHeight();
     512           0 :                 break;
     513             : 
     514             :             case dtColumnAttribs:
     515             :             {
     516             :                 OSL_ENSURE(nColId != -1, "SbaXGridPeer::dispatch : invalid parameter !");
     517           0 :                 if (nColId != -1)
     518           0 :                     break;
     519           0 :                 pGrid->SetColAttrs(nColId);
     520             :             }
     521           0 :             break;
     522             : 
     523             :             case dtColumnWidth:
     524             :             {
     525             :                 OSL_ENSURE(nColId != -1, "SbaXGridPeer::dispatch : invalid parameter !");
     526           0 :                 if (nColId != -1)
     527           0 :                     break;
     528           0 :                 pGrid->SetColWidth(nColId);
     529             :             }
     530           0 :             break;
     531             : 
     532             :             case dtUnknown:
     533           0 :                 break;
     534             :         }
     535             : 
     536             :         // notify any status listeners that the dialog vanished
     537           0 :         m_aDispatchStates.erase( aThisURLState );
     538           0 :         NotifyStatusChanged( aURL, NULL );
     539           0 :     }
     540             : }
     541             : 
     542             : //---------------------------------------------------------------------------------------
     543           0 : void SAL_CALL SbaXGridPeer::addStatusListener(const Reference< ::com::sun::star::frame::XStatusListener > & xControl, const ::com::sun::star::util::URL& aURL) throw( RuntimeException )
     544             : {
     545           0 :     ::cppu::OInterfaceContainerHelper* pCont = m_aStatusListeners.getContainer(aURL);
     546           0 :     if (!pCont)
     547           0 :         m_aStatusListeners.addInterface(aURL,xControl);
     548             :     else
     549           0 :         pCont->addInterface(xControl);
     550           0 :     NotifyStatusChanged(aURL, xControl);
     551           0 : }
     552             : 
     553             : //---------------------------------------------------------------------------------------
     554           0 : void SAL_CALL SbaXGridPeer::removeStatusListener(const Reference< ::com::sun::star::frame::XStatusListener > & xControl, const ::com::sun::star::util::URL& aURL) throw( RuntimeException )
     555             : {
     556           0 :     ::cppu::OInterfaceContainerHelper* pCont = m_aStatusListeners.getContainer(aURL);
     557           0 :     if ( pCont )
     558           0 :         pCont->removeInterface(xControl);
     559           0 : }
     560             : 
     561             : namespace
     562             : {
     563             :     class theSbaXGridPeerUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSbaXGridPeerUnoTunnelId > {};
     564             : }
     565             : 
     566         258 : const Sequence< sal_Int8 > & SbaXGridPeer::getUnoTunnelId()
     567             : {
     568         258 :     return theSbaXGridPeerUnoTunnelId::get().getSeq();
     569             : }
     570             : 
     571           0 : Sequence< Type > SAL_CALL SbaXGridPeer::getTypes() throw (RuntimeException)
     572             : {
     573           0 :     Sequence< Type > aTypes = FmXGridPeer::getTypes();
     574           0 :     sal_Int32 nOldLen = aTypes.getLength();
     575           0 :     aTypes.realloc(nOldLen + 1);
     576           0 :     aTypes.getArray()[nOldLen] = ::getCppuType( static_cast< Reference< ::com::sun::star::frame::XDispatch >* >(0) );
     577             : 
     578           0 :     return aTypes;
     579             : }
     580             : 
     581             : // return implementation specific data
     582             : //------------------------------------------------------------------
     583         257 : sal_Int64 SAL_CALL SbaXGridPeer::getSomething( const Sequence< sal_Int8 > & rId ) throw(::com::sun::star::uno::RuntimeException)
     584             : {
     585         257 :     if( rId.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(),  rId.getConstArray(), 16 ) )
     586           1 :         return reinterpret_cast< sal_Int64 >( this );
     587             : 
     588         256 :     return FmXGridPeer::getSomething(rId);
     589             : }
     590             : 
     591             : //---------------------------------------------------------------------------------------
     592           1 : SbaXGridPeer* SbaXGridPeer::getImplementation(const Reference< XInterface >& _rxIFace)
     593             : {
     594             :     Reference< XUnoTunnel > xTunnel(
     595           1 :         _rxIFace, UNO_QUERY);
     596           1 :     if (xTunnel.is())
     597           1 :         return reinterpret_cast<SbaXGridPeer*>(xTunnel->getSomething(getUnoTunnelId()));
     598           0 :     return NULL;
     599             : }
     600             : 
     601             : //---------------------------------------------------------------------------------------
     602          21 : FmGridControl* SbaXGridPeer::imp_CreateControl(Window* pParent, WinBits nStyle)
     603             : {
     604          21 :     return new SbaGridControl( m_xContext, pParent, this, nStyle);
     605             : }
     606             : 
     607             : //==================================================================
     608             : // SbaGridHeader
     609             : //==================================================================
     610             : 
     611             : //---------------------------------------------------------------------------------------
     612          21 : SbaGridHeader::SbaGridHeader(BrowseBox* pParent, WinBits nWinBits)
     613             :     :FmGridHeader(pParent, nWinBits)
     614          21 :     ,DragSourceHelper(this)
     615             : {
     616          21 : }
     617             : 
     618             : //---------------------------------------------------------------------------------------
     619           0 : void SbaGridHeader::StartDrag( sal_Int8 _nAction, const Point& _rPosPixel )
     620             : {
     621           0 :     SolarMutexGuard aGuard;
     622             :         // in the new DnD API, the solar mutex is not locked when StartDrag get's called
     623             : 
     624           0 :     ImplStartColumnDrag( _nAction, _rPosPixel );
     625           0 : }
     626             : 
     627             : //---------------------------------------------------------------------------------------
     628           0 : void SbaGridHeader::MouseButtonDown( const MouseEvent& _rMEvt )
     629             : {
     630           0 :     if (_rMEvt.IsLeft())
     631           0 :         if (_rMEvt.GetClicks() != 2)
     632             :         {
     633             :             // the base class will start a column move here, which we don't want to allow
     634             :             // (at the moment. If we store relative positions with the columns, we can allow column moves ....)
     635             : 
     636             :         }
     637             : 
     638           0 :     FmGridHeader::MouseButtonDown(_rMEvt);
     639           0 : }
     640             : 
     641             : //---------------------------------------------------------------------------------------
     642           0 : sal_Bool SbaGridHeader::ImplStartColumnDrag(sal_Int8 _nAction, const Point& _rMousePos)
     643             : {
     644           0 :     sal_uInt16 nId = GetItemId(_rMousePos);
     645           0 :     sal_Bool bResizingCol = sal_False;
     646           0 :     if (HEADERBAR_ITEM_NOTFOUND != nId)
     647             :     {
     648           0 :         Rectangle aColRect = GetItemRect(nId);
     649           0 :         aColRect.Left() += nId ? 3 : 0; // the handle col (nId == 0) does not have a left margin for resizing
     650           0 :         aColRect.Right() -= 3;
     651           0 :         bResizingCol = !aColRect.IsInside(_rMousePos);
     652             :     }
     653           0 :     if (!bResizingCol)
     654             :     {
     655             :         // force the base class to end it's drag mode
     656           0 :         EndTracking(ENDTRACK_CANCEL | ENDTRACK_END);
     657             : 
     658             :         // because we have 3d-buttons the select handler is called from MouseButtonUp, but StartDrag
     659             :         // occures earlier (while the mouse button is down)
     660             :         // so for optical reasons we select the column before really starting the drag operation.
     661           0 :         notifyColumnSelect(nId);
     662             : 
     663           0 :         static_cast<SbaGridControl*>(GetParent())->StartDrag(_nAction,
     664             :                 Point(
     665           0 :                     _rMousePos.X() + GetPosPixel().X(),     // we aren't left-justified with our parent, in contrast to the data window
     666           0 :                     _rMousePos.Y() - GetSizePixel().Height()
     667             :                 )
     668           0 :             );
     669           0 :         return sal_True;
     670             :     }
     671             : 
     672           0 :     return sal_False;
     673             : }
     674             : 
     675             : //---------------------------------------------------------------------------------------
     676           0 : void SbaGridHeader::PreExecuteColumnContextMenu(sal_uInt16 nColId, PopupMenu& rMenu)
     677             : {
     678           0 :     FmGridHeader::PreExecuteColumnContextMenu(nColId, rMenu);
     679             : 
     680             :     // some items are valid only if the db isn't readonly
     681           0 :     sal_Bool bDBIsReadOnly = ((SbaGridControl*)GetParent())->IsReadOnlyDB();
     682             : 
     683           0 :     if (bDBIsReadOnly)
     684             :     {
     685           0 :         rMenu.EnableItem(SID_FM_HIDECOL, sal_False);
     686           0 :         PopupMenu* pShowColsMenu = rMenu.GetPopupMenu(SID_FM_SHOWCOLS);
     687           0 :         if (pShowColsMenu)
     688             :         {
     689             :             // at most 16 items which mean "show column <name>"
     690           0 :             for (sal_uInt16 i=1; i<16; ++i)
     691           0 :                 pShowColsMenu->EnableItem(i, sal_False);
     692             :             // "show cols/more..." and "show cols/all"
     693           0 :             pShowColsMenu->EnableItem(SID_FM_SHOWCOLS_MORE, sal_False);
     694           0 :             pShowColsMenu->EnableItem(SID_FM_SHOWALLCOLS, sal_False);
     695             :         }
     696             :     }
     697             : 
     698             :     // prepend some new items
     699           0 :     sal_Bool bColAttrs = (nColId != (sal_uInt16)-1) && (nColId != 0);
     700           0 :     if ( bColAttrs && !bDBIsReadOnly)
     701             :     {
     702           0 :         PopupMenu aNewItems(ModuleRes(RID_SBA_GRID_COLCTXMENU));
     703           0 :         sal_uInt16 nPos = 0;
     704           0 :         sal_uInt16 nModelPos = ((SbaGridControl*)GetParent())->GetModelColumnPos(nColId);
     705           0 :         Reference< XPropertySet >  xField = ((SbaGridControl*)GetParent())->getField(nModelPos);
     706             : 
     707           0 :         if ( xField.is() )
     708             :         {
     709           0 :             switch( ::comphelper::getINT32(xField->getPropertyValue(PROPERTY_TYPE)) )
     710             :             {
     711             :             case DataType::BINARY:
     712             :             case DataType::VARBINARY:
     713             :             case DataType::LONGVARBINARY:
     714             :             case DataType::SQLNULL:
     715             :             case DataType::OBJECT:
     716             :             case DataType::BLOB:
     717             :             case DataType::CLOB:
     718             :             case DataType::REF:
     719           0 :                 break;
     720             :             default:
     721           0 :                 rMenu.InsertItem(ID_BROWSER_COLATTRSET, aNewItems.GetItemText(ID_BROWSER_COLATTRSET), 0, OString(), nPos++);
     722           0 :                 rMenu.SetHelpId(ID_BROWSER_COLATTRSET, aNewItems.GetHelpId(ID_BROWSER_COLATTRSET));
     723           0 :                 rMenu.InsertSeparator(OString(), nPos++);
     724             :             }
     725             :         }
     726             : 
     727           0 :         rMenu.InsertItem(ID_BROWSER_COLWIDTH, aNewItems.GetItemText(ID_BROWSER_COLWIDTH), 0, OString(), nPos++);
     728           0 :         rMenu.SetHelpId(ID_BROWSER_COLWIDTH, aNewItems.GetHelpId(ID_BROWSER_COLWIDTH));
     729           0 :         rMenu.InsertSeparator(OString(), nPos++);
     730             :     }
     731           0 : }
     732             : 
     733             : //---------------------------------------------------------------------------------------
     734           0 : void SbaGridHeader::PostExecuteColumnContextMenu(sal_uInt16 nColId, const PopupMenu& rMenu, sal_uInt16 nExecutionResult)
     735             : {
     736           0 :     switch (nExecutionResult)
     737             :     {
     738             :         case ID_BROWSER_COLWIDTH:
     739           0 :             ((SbaGridControl*)GetParent())->SetColWidth(nColId);
     740           0 :             break;
     741             : 
     742             :         case ID_BROWSER_COLATTRSET:
     743           0 :             ((SbaGridControl*)GetParent())->SetColAttrs(nColId);
     744           0 :             break;
     745             :         case ID_BROWSER_COLUMNINFO:
     746             :             {
     747           0 :                 sal_uInt16 nModelPos = ((SbaGridControl*)GetParent())->GetModelColumnPos(nColId);
     748           0 :                 Reference< XPropertySet >  xField = ((SbaGridControl*)GetParent())->getField(nModelPos);
     749             : 
     750           0 :                 if(!xField.is())
     751           0 :                     break;
     752           0 :                 ::std::vector< ::boost::shared_ptr<OTableRow> > vClipboardList;
     753             :                 // send it to the clipboard
     754           0 :                 vClipboardList.push_back(::boost::shared_ptr<OTableRow>(new OTableRow(xField)));
     755           0 :                 OTableRowExchange* pData = new OTableRowExchange(vClipboardList);
     756           0 :                 Reference< ::com::sun::star::datatransfer::XTransferable> xRef = pData;
     757           0 :                 pData->CopyToClipboard(GetParent());
     758             :             }
     759           0 :             break;
     760             : 
     761           0 :         default: FmGridHeader::PostExecuteColumnContextMenu(nColId, rMenu, nExecutionResult);
     762             :     }
     763           0 : }
     764             : 
     765             : //==================================================================
     766             : // SbaGridControl
     767             : //==================================================================
     768             : DBG_NAME(SbaGridControl );
     769             : //---------------------------------------------------------------------------------------
     770          21 : SbaGridControl::SbaGridControl(Reference< XComponentContext > _rM,
     771             :                                Window* pParent, FmXGridPeer* _pPeer, WinBits nBits)
     772             :     :FmGridControl(_rM,pParent, _pPeer, nBits)
     773             :     ,m_pMasterListener(NULL)
     774             :     ,m_nAsyncDropEvent(0)
     775             :     ,m_nCurrentActionColId((sal_uInt16)-1)
     776          21 :     ,m_bActivatingForDrop(sal_False)
     777             : {
     778             :     DBG_CTOR(SbaGridControl ,NULL);
     779          21 : }
     780             : 
     781             : //---------------------------------------------------------------------------------------
     782          63 : SbaGridControl::~SbaGridControl()
     783             : {
     784             :     DBG_DTOR(SbaGridControl ,NULL);
     785          21 :     if (m_nAsyncDropEvent)
     786           0 :         Application::RemoveUserEvent(m_nAsyncDropEvent);
     787          42 : }
     788             : 
     789             : //---------------------------------------------------------------------------------------
     790          21 : BrowserHeader* SbaGridControl::imp_CreateHeaderBar(BrowseBox* pParent)
     791             : {
     792          21 :     return new SbaGridHeader(pParent);
     793             : }
     794             : 
     795             : //---------------------------------------------------------------------------------------
     796           0 : CellController* SbaGridControl::GetController(long nRow, sal_uInt16 nCol)
     797             : {
     798           0 :     if ( m_bActivatingForDrop )
     799           0 :         return NULL;
     800             : 
     801           0 :     return FmGridControl::GetController(nRow, nCol);
     802             : }
     803             : 
     804             : //---------------------------------------------------------------------------------------
     805           0 : void SbaGridControl::PreExecuteRowContextMenu(sal_uInt16 nRow, PopupMenu& rMenu)
     806             : {
     807           0 :     FmGridControl::PreExecuteRowContextMenu(nRow, rMenu);
     808             : 
     809           0 :     PopupMenu aNewItems(ModuleRes(RID_SBA_GRID_ROWCTXMENU));
     810           0 :     sal_uInt16 nPos = 0;
     811             : 
     812           0 :     if (!IsReadOnlyDB())
     813             :     {
     814           0 :         rMenu.InsertItem(ID_BROWSER_TABLEATTR, aNewItems.GetItemText(ID_BROWSER_TABLEATTR), 0, OString(), nPos++);
     815           0 :         rMenu.SetHelpId(ID_BROWSER_TABLEATTR, aNewItems.GetHelpId(ID_BROWSER_TABLEATTR));
     816             : 
     817           0 :         rMenu.InsertItem(ID_BROWSER_ROWHEIGHT, aNewItems.GetItemText(ID_BROWSER_ROWHEIGHT), 0, OString(), nPos++);
     818           0 :         rMenu.SetHelpId(ID_BROWSER_ROWHEIGHT, aNewItems.GetHelpId(ID_BROWSER_ROWHEIGHT));
     819           0 :         rMenu.InsertSeparator(OString(), nPos++);
     820             :     }
     821             : 
     822           0 :     if ( GetSelectRowCount() > 0 )
     823             :     {
     824           0 :         rMenu.InsertItem(ID_BROWSER_COPY, aNewItems.GetItemText(SID_COPY), 0, OString(), nPos++);
     825           0 :         rMenu.SetHelpId(ID_BROWSER_COPY, aNewItems.GetHelpId(SID_COPY));
     826             : 
     827           0 :         rMenu.InsertSeparator(OString(), nPos++);
     828           0 :     }
     829           0 : }
     830             : 
     831             : //------------------------------------------------------------------------------
     832           0 : SvNumberFormatter* SbaGridControl::GetDatasourceFormatter()
     833             : {
     834           0 :     Reference< ::com::sun::star::util::XNumberFormatsSupplier >  xSupplier = ::dbtools::getNumberFormats(::dbtools::getConnection(Reference< XRowSet > (getDataSource(),UNO_QUERY)), sal_True, getContext());
     835             : 
     836           0 :     SvNumberFormatsSupplierObj* pSupplierImpl = SvNumberFormatsSupplierObj::getImplementation( xSupplier );
     837           0 :     if ( !pSupplierImpl )
     838           0 :         return NULL;
     839             : 
     840           0 :     SvNumberFormatter* pFormatter = pSupplierImpl->GetNumberFormatter();
     841           0 :     return pFormatter;
     842             : }
     843             : 
     844             : //------------------------------------------------------------------------------
     845           0 : void SbaGridControl::SetColWidth(sal_uInt16 nColId)
     846             : {
     847             :     // get the (UNO) column model
     848           0 :     sal_uInt16 nModelPos = GetModelColumnPos(nColId);
     849           0 :     Reference< XIndexAccess >  xCols(GetPeer()->getColumns(), UNO_QUERY);
     850           0 :     Reference< XPropertySet >  xAffectedCol;
     851           0 :     if (xCols.is() && (nModelPos != (sal_uInt16)-1))
     852           0 :         ::cppu::extractInterface(xAffectedCol,xCols->getByIndex(nModelPos));
     853             : 
     854           0 :     if (xAffectedCol.is())
     855             :     {
     856           0 :         Any aWidth = xAffectedCol->getPropertyValue(PROPERTY_WIDTH);
     857           0 :         sal_Int32 nCurWidth = aWidth.hasValue() ? ::comphelper::getINT32(aWidth) : -1;
     858             : 
     859           0 :         DlgSize aDlgColWidth(this, nCurWidth, sal_False);
     860           0 :         if (aDlgColWidth.Execute())
     861             :         {
     862           0 :             sal_Int32 nValue = aDlgColWidth.GetValue();
     863           0 :             Any aNewWidth;
     864           0 :             if (-1 == nValue)
     865             :             {   // set to default
     866           0 :                 Reference< XPropertyState >  xPropState(xAffectedCol, UNO_QUERY);
     867           0 :                 if (xPropState.is())
     868             :                 {
     869           0 :                     try { aNewWidth = xPropState->getPropertyDefault(PROPERTY_WIDTH); } catch(Exception&) { } ;
     870           0 :                 }
     871             :             }
     872             :             else
     873           0 :                 aNewWidth <<= nValue;
     874           0 :             try {  xAffectedCol->setPropertyValue(PROPERTY_WIDTH, aNewWidth); } catch(Exception&) { } ;
     875           0 :         }
     876           0 :     }
     877           0 : }
     878             : 
     879             : //------------------------------------------------------------------------------
     880           0 : void SbaGridControl::SetRowHeight()
     881             : {
     882           0 :     Reference< XPropertySet >  xCols(GetPeer()->getColumns(), UNO_QUERY);
     883           0 :     if (!xCols.is())
     884           0 :         return;
     885             : 
     886           0 :     Any aHeight = xCols->getPropertyValue(PROPERTY_ROW_HEIGHT);
     887           0 :     sal_Int32 nCurHeight = aHeight.hasValue() ? ::comphelper::getINT32(aHeight) : -1;
     888             : 
     889           0 :     DlgSize aDlgRowHeight(this, nCurHeight, sal_True);
     890           0 :     if (aDlgRowHeight.Execute())
     891             :     {
     892           0 :         sal_Int32 nValue = aDlgRowHeight.GetValue();
     893           0 :         Any aNewHeight;
     894           0 :         if ((sal_Int16)-1 == nValue)
     895             :         {   // set to default
     896           0 :             Reference< XPropertyState >  xPropState(xCols, UNO_QUERY);
     897           0 :             if (xPropState.is())
     898             :             {
     899             :                 try
     900             :                 {
     901           0 :                     aNewHeight = xPropState->getPropertyDefault(PROPERTY_ROW_HEIGHT);
     902             :                 }
     903           0 :                 catch(Exception&)
     904             :                 { }
     905           0 :             }
     906             :         }
     907             :         else
     908           0 :             aNewHeight <<= nValue;
     909             :         try
     910             :         {
     911           0 :             xCols->setPropertyValue(PROPERTY_ROW_HEIGHT, aNewHeight);
     912             :         }
     913           0 :         catch(Exception&)
     914             :         {
     915             :             OSL_FAIL("setPropertyValue: PROPERTY_ROW_HEIGHT throws a exception");
     916           0 :         }
     917           0 :     }
     918             : }
     919             : 
     920             : //------------------------------------------------------------------------------
     921           0 : void SbaGridControl::SetColAttrs(sal_uInt16 nColId)
     922             : {
     923           0 :     SvNumberFormatter* pFormatter = GetDatasourceFormatter();
     924           0 :     if (!pFormatter)
     925           0 :         return;
     926             : 
     927           0 :     sal_uInt16 nModelPos = GetModelColumnPos(nColId);
     928             : 
     929             :     // get the (UNO) column model
     930           0 :     Reference< XIndexAccess >  xCols(GetPeer()->getColumns(), UNO_QUERY);
     931           0 :     Reference< XPropertySet >  xAffectedCol;
     932           0 :     if (xCols.is() && (nModelPos != (sal_uInt16)-1))
     933           0 :         ::cppu::extractInterface(xAffectedCol,xCols->getByIndex(nModelPos));
     934             : 
     935             :     // get the field the column is bound to
     936           0 :     Reference< XPropertySet >  xField = getField(nModelPos);
     937           0 :     ::dbaui::callColumnFormatDialog(xAffectedCol,xField,pFormatter,this);//(Window::GetSettings().GetLanguage());
     938             : }
     939             : 
     940             : 
     941             : //------------------------------------------------------------------------------
     942           0 : void SbaGridControl::SetBrowserAttrs()
     943             : {
     944           0 :     Reference< XPropertySet >  xGridModel(GetPeer()->getColumns(), UNO_QUERY);
     945           0 :     if (!xGridModel.is())
     946           0 :         return;
     947             : 
     948             :     try
     949             :     {
     950           0 :         Reference< XComponentContext > xContext = getContext();
     951           0 :         Reference< XExecutableDialog > xExecute = ControlFontDialog::createWithGridModel( xContext, xGridModel);
     952           0 :         xExecute->execute();
     953             :     }
     954           0 :     catch( const Exception& )
     955             :     {
     956             :         DBG_UNHANDLED_EXCEPTION();
     957           0 :     }
     958             : }
     959             : 
     960             : //---------------------------------------------------------------------------------------
     961           0 : void SbaGridControl::PostExecuteRowContextMenu(sal_uInt16 nRow, const PopupMenu& rMenu, sal_uInt16 nExecutionResult)
     962             : {
     963           0 :     switch (nExecutionResult)
     964             :     {
     965             :         case ID_BROWSER_TABLEATTR:
     966           0 :             SetBrowserAttrs();
     967           0 :             break;
     968             :         case ID_BROWSER_ROWHEIGHT:
     969           0 :             SetRowHeight();
     970           0 :             break;
     971             :         case ID_BROWSER_COPY:
     972           0 :             CopySelectedRowsToClipboard();
     973           0 :             break;
     974             : 
     975             :         default:
     976           0 :             FmGridControl::PostExecuteRowContextMenu(nRow, rMenu, nExecutionResult);
     977           0 :             break;
     978             :     }
     979           0 : }
     980             : 
     981             : //---------------------------------------------------------------------------------------
     982           0 : void SbaGridControl::Select()
     983             : {
     984             :     // Some selection has changed ...
     985           0 :     FmGridControl::Select();
     986             : 
     987           0 :     if (m_pMasterListener)
     988           0 :         m_pMasterListener->SelectionChanged();
     989           0 : }
     990             : 
     991             : //---------------------------------------------------------------------------------------
     992          38 : void SbaGridControl::CursorMoved()
     993             : {
     994          38 :     FmGridControl::CursorMoved();
     995          38 : }
     996             : 
     997             : //---------------------------------------------------------------------------------------
     998          38 : void SbaGridControl::ActivateCell(long nRow, sal_uInt16 nCol, sal_Bool bSetCellFocus /*= sal_True*/ )
     999             : {
    1000          38 :     FmGridControl::ActivateCell(nRow, nCol, bSetCellFocus);
    1001          38 :     if (m_pMasterListener)
    1002           5 :         m_pMasterListener->CellActivated();
    1003          38 : }
    1004             : 
    1005             : //---------------------------------------------------------------------------------------
    1006          14 : void SbaGridControl::DeactivateCell(sal_Bool bUpdate /*= sal_True*/)
    1007             : {
    1008          14 :     FmGridControl::DeactivateCell(bUpdate);
    1009          14 :     if (m_pMasterListener)
    1010           2 :         m_pMasterListener->CellDeactivated();
    1011          14 : }
    1012             : 
    1013             : //---------------------------------------------------------------------------------------
    1014           2 : void SbaGridControl::onRowChange()
    1015             : {
    1016           2 :     if ( m_pMasterListener )
    1017           2 :         m_pMasterListener->RowChanged();
    1018           2 : }
    1019             : 
    1020             : //---------------------------------------------------------------------------------------
    1021           1 : void SbaGridControl::onColumnChange()
    1022             : {
    1023           1 :     if ( m_pMasterListener )
    1024           1 :         m_pMasterListener->ColumnChanged();
    1025           1 : }
    1026             : 
    1027             : //---------------------------------------------------------------------------------------
    1028           0 : void SbaGridControl::BeforeDrop()
    1029             : {
    1030           0 :     if (m_pMasterListener)
    1031           0 :         m_pMasterListener->BeforeDrop();
    1032           0 : }
    1033             : //---------------------------------------------------------------------------------------
    1034           0 : void SbaGridControl::AfterDrop()
    1035             : {
    1036           0 :     if (m_pMasterListener)
    1037           0 :         m_pMasterListener->AfterDrop();
    1038           0 : }
    1039             : 
    1040             : 
    1041             : //------------------------------------------------------------------------------
    1042           0 : Reference< XPropertySet >  SbaGridControl::getField(sal_uInt16 nModelPos)
    1043             : {
    1044           0 :     Reference< XPropertySet >  xEmptyReturn;
    1045             :     try
    1046             :     {
    1047             :         // first get the name of the column
    1048           0 :         Reference< XIndexAccess >  xCols(GetPeer()->getColumns(), UNO_QUERY);
    1049           0 :         if ( xCols.is() && xCols->getCount() > nModelPos )
    1050             :         {
    1051           0 :             Reference< XPropertySet >  xCol(xCols->getByIndex(nModelPos),UNO_QUERY);
    1052           0 :             if ( xCol.is() )
    1053           0 :                 xEmptyReturn.set(xCol->getPropertyValue(PROPERTY_BOUNDFIELD),UNO_QUERY);
    1054             :         }
    1055             :         else
    1056           0 :             OSL_FAIL("SbaGridControl::getField getColumns returns NULL or ModelPos is > than count!");
    1057             :     }
    1058           0 :     catch(Exception&)
    1059             :     {
    1060             :         OSL_FAIL("SbaGridControl::getField Exception occurred!");
    1061             :     }
    1062             : 
    1063           0 :     return xEmptyReturn;
    1064             : }
    1065             : 
    1066             : //---------------------------------------------------------------------------------------
    1067           0 : sal_Bool SbaGridControl::IsReadOnlyDB() const
    1068             : {
    1069             :     // assume yes if anything fails
    1070           0 :     sal_Bool bDBIsReadOnly = sal_True;
    1071             : 
    1072             :     // the db is the implemented by the parent of the grid control's model ...
    1073           0 :     Reference< XChild >  xColumns(GetPeer()->getColumns(), UNO_QUERY);
    1074           0 :     if (xColumns.is())
    1075             :     {
    1076           0 :         Reference< XRowSet >  xDataSource(xColumns->getParent(), UNO_QUERY);
    1077           0 :         Reference< XChild >  xConn(::dbtools::getConnection(xDataSource),UNO_QUERY);
    1078           0 :         if (xConn.is())
    1079             :         {
    1080             :             // ... and the RO-flag simply is implemented by a property
    1081           0 :             Reference< XPropertySet >  xDbProps(xConn->getParent(), UNO_QUERY);
    1082           0 :             if (xDbProps.is())
    1083             :             {
    1084           0 :                 Reference< XPropertySetInfo >  xInfo = xDbProps->getPropertySetInfo();
    1085           0 :                 if (xInfo->hasPropertyByName(PROPERTY_ISREADONLY))
    1086           0 :                     bDBIsReadOnly = ::comphelper::getBOOL(xDbProps->getPropertyValue(PROPERTY_ISREADONLY));
    1087           0 :             }
    1088           0 :         }
    1089             :     }
    1090           0 :     return bDBIsReadOnly;
    1091             : }
    1092             : 
    1093             : //---------------------------------------------------------------------------------------
    1094           0 : void SbaGridControl::MouseButtonDown( const BrowserMouseEvent& rMEvt)
    1095             : {
    1096           0 :     long nRow = GetRowAtYPosPixel(rMEvt.GetPosPixel().Y());
    1097           0 :     sal_uInt16 nColPos = GetColumnAtXPosPixel(rMEvt.GetPosPixel().X());
    1098           0 :     sal_uInt16 nViewPos = (nColPos == BROWSER_INVALIDID) ? (sal_uInt16)-1 : nColPos-1;
    1099             :         // 'the handle column' and 'no valid column' will both result in a view position of -1 !
    1100             : 
    1101           0 :     sal_Bool bHitEmptySpace = (nRow > GetRowCount()) || (nViewPos == (sal_uInt16)-1);
    1102             : 
    1103           0 :     if (bHitEmptySpace && (rMEvt.GetClicks() == 2) && rMEvt.IsMod1())
    1104           0 :         Control::MouseButtonDown(rMEvt);
    1105             :     else
    1106           0 :         FmGridControl::MouseButtonDown(rMEvt);
    1107           0 : }
    1108             : 
    1109             : //---------------------------------------------------------------------------------------
    1110           0 : void SbaGridControl::StartDrag( sal_Int8 _nAction, const Point& _rPosPixel )
    1111             : {
    1112           0 :     SolarMutexGuard aGuard;
    1113             :         // in the new DnD API, the solar mutex is not locked when StartDrag get's called
    1114             : 
    1115           0 :     sal_Bool bHandled = sal_False;
    1116             : 
    1117             :     do
    1118             :     {
    1119             :         // determine if dragging is allowed
    1120             :         // (Yes, this is controller (not view) functionality. But collecting and evaluating all the
    1121             :         // information necessary via UNO would be quite difficult (if not impossible) so
    1122             :         // my laziness says 'do it here' ...)
    1123           0 :         long nRow = GetRowAtYPosPixel(_rPosPixel.Y());
    1124           0 :         sal_uInt16 nColPos = GetColumnAtXPosPixel(_rPosPixel.X());
    1125           0 :         sal_uInt16 nViewPos = (nColPos == BROWSER_INVALIDID) ? (sal_uInt16)-1 : nColPos-1;
    1126             :             // 'the handle column' and 'no valid column' will both result in a view position of -1 !
    1127             : 
    1128           0 :         sal_Bool bCurrentRowVirtual = IsCurrentAppending() && IsModified();
    1129             :         // the current row doesn't really exist : the user's appendign a new one and already has entered some data,
    1130             :         // so the row contains data which has no counter part within the data source
    1131             : 
    1132           0 :         long nCorrectRowCount = GetRowCount();
    1133           0 :         if (GetOptions() & OPT_INSERT)
    1134           0 :             --nCorrectRowCount; // there is a empty row for inserting records
    1135           0 :         if (bCurrentRowVirtual)
    1136           0 :             --nCorrectRowCount;
    1137             : 
    1138           0 :         if ((nColPos == BROWSER_INVALIDID) || (nRow >= nCorrectRowCount))
    1139             :             break;
    1140             : 
    1141           0 :         sal_Bool bHitHandle = (nColPos == 0);
    1142             : 
    1143             :         // check which kind of dragging has to be initiated
    1144           0 :         if  (   bHitHandle                          //  the handle column
    1145             :                                                     // AND
    1146           0 :             &&  (   GetSelectRowCount()             //  at least one row is selected
    1147             :                                                     // OR
    1148           0 :                 ||  (   (nRow >= 0)                 //  a row below the header
    1149           0 :                     &&  !bCurrentRowVirtual         //  we aren't appending a new record
    1150           0 :                     &&  (nRow != GetCurrentPos())   //  a row which is not the current one
    1151             :                     )                               // OR
    1152           0 :                 ||  (   (0 == GetSelectRowCount())  // no rows selected
    1153           0 :                     &&  (-1 == nRow)                // hit the header
    1154             :                     )
    1155             :                 )
    1156             :             )
    1157             :         {   // => start dragging the row
    1158           0 :             if (GetDataWindow().IsMouseCaptured())
    1159           0 :                 GetDataWindow().ReleaseMouse();
    1160             : 
    1161           0 :             if (0 == GetSelectRowCount())
    1162             :                 // no rows selected, but here in this branch
    1163             :                 // -> the user started dragging the upper left corner, which symbolizes the whole table
    1164           0 :                 SelectAll();
    1165             : 
    1166           0 :             getMouseEvent().Clear();
    1167           0 :             DoRowDrag((sal_Int16)nRow);
    1168             : 
    1169           0 :             bHandled = sal_True;
    1170             :         }
    1171           0 :         else if (   (nRow < 0)                      // the header
    1172           0 :                 &&  (!bHitHandle)                   // non-handle column
    1173           0 :                 &&  (nViewPos < GetViewColCount())  // valid (existing) column
    1174             :                 )
    1175             :         {   // => start dragging the column
    1176           0 :             if (GetDataWindow().IsMouseCaptured())
    1177           0 :                 GetDataWindow().ReleaseMouse();
    1178             : 
    1179           0 :             getMouseEvent().Clear();
    1180           0 :             DoColumnDrag(nViewPos);
    1181             : 
    1182           0 :             bHandled = sal_True;
    1183             :         }
    1184           0 :         else if (   !bHitHandle     // non-handle column
    1185           0 :                 &&  (nRow >= 0)     // non-header row
    1186             :                 )
    1187             :         {   // => start dragging the field content
    1188           0 :             if (GetDataWindow().IsMouseCaptured())
    1189           0 :                 GetDataWindow().ReleaseMouse();
    1190             : 
    1191           0 :             getMouseEvent().Clear();
    1192           0 :             DoFieldDrag(nViewPos, (sal_Int16)nRow);
    1193             : 
    1194           0 :             bHandled = sal_True;
    1195             :         }
    1196             :     }
    1197             :     while (false);
    1198             : 
    1199           0 :     if (!bHandled)
    1200           0 :         FmGridControl::StartDrag(_nAction, _rPosPixel);
    1201           0 : }
    1202             : 
    1203             : //------------------------------------------------------------------------------
    1204           0 : void SbaGridControl::Command(const CommandEvent& rEvt)
    1205             : {
    1206           0 :     FmGridControl::Command(rEvt);
    1207           0 : }
    1208             : 
    1209             : // -----------------------------------------------------------------------
    1210           0 : void SbaGridControl::DoColumnDrag(sal_uInt16 nColumnPos)
    1211             : {
    1212           0 :     Reference< XPropertySet >  xDataSource(getDataSource(), UNO_QUERY);
    1213             :     OSL_ENSURE(xDataSource.is(), "SbaGridControl::DoColumnDrag : invalid data source !");
    1214             : 
    1215           0 :     Reference< XPropertySet > xAffectedCol;
    1216           0 :     Reference< XPropertySet > xAffectedField;
    1217           0 :     Reference< XConnection > xActiveConnection;
    1218             : 
    1219             :     // determine the field to drag
    1220           0 :     OUString sField;
    1221             :     try
    1222             :     {
    1223           0 :         xActiveConnection = ::dbtools::getConnection(Reference< XRowSet >(getDataSource(),UNO_QUERY));
    1224             : 
    1225           0 :         sal_uInt16 nModelPos = GetModelColumnPos(GetColumnIdFromViewPos(nColumnPos));
    1226           0 :         Reference< XIndexContainer >  xCols(GetPeer()->getColumns(), UNO_QUERY);
    1227           0 :         xAffectedCol.set(xCols->getByIndex(nModelPos),UNO_QUERY);
    1228           0 :         if (xAffectedCol.is())
    1229             :         {
    1230           0 :             xAffectedCol->getPropertyValue(PROPERTY_CONTROLSOURCE) >>= sField;
    1231           0 :             xAffectedField.set(xAffectedCol->getPropertyValue(PROPERTY_BOUNDFIELD),UNO_QUERY);
    1232           0 :         }
    1233             :     }
    1234           0 :     catch(Exception&)
    1235             :     {
    1236             :         OSL_FAIL("SbaGridControl::DoColumnDrag : something went wrong while getting the column");
    1237             :     }
    1238           0 :     if (sField.isEmpty())
    1239           0 :         return;
    1240             : 
    1241           0 :     OColumnTransferable* pDataTransfer = new OColumnTransferable(xDataSource, sField, xAffectedField, xActiveConnection, CTF_FIELD_DESCRIPTOR | CTF_COLUMN_DESCRIPTOR);
    1242           0 :     Reference< XTransferable > xEnsureDelete = pDataTransfer;
    1243           0 :     pDataTransfer->StartDrag(this, DND_ACTION_COPY | DND_ACTION_LINK);
    1244             : }
    1245             : 
    1246             : // -----------------------------------------------------------------------
    1247           0 : void SbaGridControl::CopySelectedRowsToClipboard()
    1248             : {
    1249             :     OSL_ENSURE( GetSelectRowCount() > 0, "SbaGridControl::CopySelectedRowsToClipboard: invalid call!" );
    1250           0 :     implTransferSelectedRows( (sal_Int16)FirstSelectedRow(), true );
    1251           0 : }
    1252             : 
    1253             : // -----------------------------------------------------------------------
    1254           0 : void SbaGridControl::DoRowDrag( sal_Int16 nRowPos )
    1255             : {
    1256           0 :     implTransferSelectedRows( nRowPos, false );
    1257           0 : }
    1258             : 
    1259             : // -----------------------------------------------------------------------
    1260           0 : void SbaGridControl::implTransferSelectedRows( sal_Int16 nRowPos, bool _bTrueIfClipboardFalseIfDrag )
    1261             : {
    1262           0 :     Reference< XPropertySet > xForm( getDataSource(), UNO_QUERY );
    1263             :     OSL_ENSURE( xForm.is(), "SbaGridControl::implTransferSelectedRows: invalid form!" );
    1264             : 
    1265             :     // build the sequence of numbers of selected rows
    1266           0 :     Sequence< Any > aSelectedRows;
    1267           0 :     sal_Bool bSelectionBookmarks = sal_True;
    1268             : 
    1269             :     // collect the affected rows
    1270           0 :     if ((GetSelectRowCount() == 0) && (nRowPos >= 0))
    1271             :     {
    1272           0 :         aSelectedRows.realloc( 1 );
    1273           0 :         aSelectedRows[0] <<= (sal_Int32)(nRowPos + 1);
    1274           0 :         bSelectionBookmarks = sal_False;
    1275             :     }
    1276           0 :     else if ( !IsAllSelected() && GetSelectRowCount() )
    1277             :     {
    1278           0 :         aSelectedRows = getSelectionBookmarks();
    1279           0 :         bSelectionBookmarks = sal_True;
    1280             :     }
    1281             : 
    1282           0 :     Reference< XResultSet> xRowSetClone;
    1283             :     try
    1284             :     {
    1285           0 :         ODataClipboard* pTransfer = new ODataClipboard( xForm, aSelectedRows, bSelectionBookmarks, getContext() );
    1286             : 
    1287           0 :         Reference< XTransferable > xEnsureDelete = pTransfer;
    1288           0 :         if ( _bTrueIfClipboardFalseIfDrag )
    1289           0 :             pTransfer->CopyToClipboard( this );
    1290             :         else
    1291           0 :             pTransfer->StartDrag(this, DND_ACTION_COPY | DND_ACTION_LINK);
    1292             :     }
    1293           0 :     catch(Exception&)
    1294             :     {
    1295           0 :     }
    1296           0 : }
    1297             : 
    1298             : // -----------------------------------------------------------------------
    1299           0 : void SbaGridControl::DoFieldDrag(sal_uInt16 nColumnPos, sal_Int16 nRowPos)
    1300             : {
    1301             :     // the only thing to do here is dragging the pure cell text
    1302             :     // the old implementation copied a SBA_FIELDDATAEXCHANGE_FORMAT, too, (which was rather expensive to obtain),
    1303             :     // but we have no client for this DnD format anymore (the mail part of SO 5.2 was the only client)
    1304             : 
    1305           0 :     OUString sCellText;
    1306             :     try
    1307             :     {
    1308           0 :         Reference< XGridFieldDataSupplier >  xFieldData(static_cast< XGridPeer* >(GetPeer()), UNO_QUERY);
    1309           0 :         Sequence<sal_Bool> aSupportingText = xFieldData->queryFieldDataType(::getCppuType(&sCellText));
    1310           0 :         if (aSupportingText.getConstArray()[nColumnPos])
    1311             :         {
    1312           0 :             Sequence< Any> aCellContents = xFieldData->queryFieldData(nRowPos, ::getCppuType(&sCellText));
    1313           0 :             sCellText = ::comphelper::getString(aCellContents.getConstArray()[nColumnPos]);
    1314           0 :             ::svt::OStringTransfer::StartStringDrag(sCellText, this, DND_ACTION_COPY);
    1315           0 :         }
    1316             :     }
    1317           0 :     catch(Exception&)
    1318             :     {
    1319             :         OSL_FAIL("SbaGridControl::DoFieldDrag : could not retrieve the cell's contents !");
    1320           0 :         return;
    1321           0 :     }
    1322             : 
    1323             : }
    1324             : /// unary_function Functor object for class ZZ returntype is void
    1325             :     struct SbaGridControlPrec : ::std::unary_function<DataFlavorExVector::value_type,bool>
    1326             :     {
    1327             :         sal_Bool    bQueryDrop;
    1328           0 :         SbaGridControlPrec(sal_Bool _bQueryDrop)
    1329           0 :             : bQueryDrop(_bQueryDrop)
    1330             :         {
    1331           0 :         }
    1332             : 
    1333           0 :         inline bool operator()(const DataFlavorExVector::value_type& _aType)
    1334             :         {
    1335           0 :             switch (_aType.mnSotId)
    1336             :             {
    1337             :                 case SOT_FORMATSTR_ID_DBACCESS_TABLE:   // table descriptor
    1338             :                 case SOT_FORMATSTR_ID_DBACCESS_QUERY:   // query descriptor
    1339             :                 case SOT_FORMATSTR_ID_DBACCESS_COMMAND: // SQL command
    1340           0 :                     return true;
    1341             :             }
    1342           0 :             return false;
    1343             :         }
    1344             :     };
    1345             : //------------------------------------------------------------------------------
    1346           0 : sal_Int8 SbaGridControl::AcceptDrop( const BrowserAcceptDropEvent& rEvt )
    1347             : {
    1348           0 :     sal_Int8 nAction = DND_ACTION_NONE;
    1349             : 
    1350             :     // we need a valid connection
    1351           0 :     if (!::dbtools::getConnection(Reference< XRowSet > (getDataSource(),UNO_QUERY)).is())
    1352           0 :         return nAction;
    1353             : 
    1354           0 :     if ( IsDropFormatSupported( FORMAT_STRING ) ) do
    1355             :     {   // odd construction, but spares us a lot of (explicit ;) goto's
    1356             : 
    1357           0 :         if (!GetEmptyRow().Is())
    1358             :             // without an empty row we're not in update mode
    1359           0 :             break;
    1360             : 
    1361           0 :         long    nRow = GetRowAtYPosPixel(rEvt.maPosPixel.Y(), sal_False);
    1362           0 :         sal_uInt16  nCol = GetColumnAtXPosPixel(rEvt.maPosPixel.X(), sal_False);
    1363             : 
    1364           0 :         long nCorrectRowCount = GetRowCount();
    1365           0 :         if (GetOptions() & OPT_INSERT)
    1366           0 :             --nCorrectRowCount; // there is a empty row for inserting records
    1367           0 :         if (IsCurrentAppending())
    1368           0 :             --nCorrectRowCount; // the current data record doesn't really exist, we are appending a new one
    1369             : 
    1370           0 :         if ((nCol == BROWSER_INVALIDID) || (nRow >= nCorrectRowCount) || GetColumnId(nCol) == 0  || GetColumnId(nCol) == BROWSER_INVALIDID )
    1371             :             // no valid cell under the mouse cursor
    1372           0 :             break;
    1373             : 
    1374           0 :         Rectangle aRect = GetCellRect(nRow, nCol, sal_False);
    1375           0 :         if (!aRect.IsInside(rEvt.maPosPixel))
    1376             :             // not dropped within a cell (a cell isn't as wide as the column - the are small spaces)
    1377           0 :             break;
    1378             : 
    1379           0 :         if ((IsModified() || (GetCurrentRow().Is() && GetCurrentRow()->IsModified())) && (GetCurrentPos() != nRow))
    1380             :             // there is a current and modified row or cell and he text is to be dropped into another one
    1381           0 :             break;
    1382             : 
    1383           0 :         CellControllerRef xCurrentController = Controller();
    1384           0 :         if (xCurrentController.Is() && xCurrentController->IsModified() && ((nRow != GetCurRow()) || (nCol != GetCurColumnId())))
    1385             :             // the current controller is modified and the user wants to drop in another cell -> no chance
    1386             :             // (when leaving the modified cell a error may occur - this is deadly while dragging)
    1387           0 :             break;
    1388             : 
    1389           0 :         Reference< XPropertySet >  xField = getField(GetModelColumnPos(nCol));
    1390           0 :         if (!xField.is())
    1391             :             // the column is not valid bound (for instance a binary field)
    1392           0 :             break;
    1393             : 
    1394             :         try
    1395             :         {
    1396           0 :             if (::comphelper::getBOOL(xField->getPropertyValue(PROPERTY_ISREADONLY)))
    1397           0 :                 break;
    1398             :         }
    1399           0 :         catch (const Exception& e )
    1400             :         {
    1401             :             (void)e; // make compiler happy
    1402             :             // assume RO
    1403           0 :             break;
    1404             :         }
    1405             : 
    1406             :         try
    1407             :         {
    1408             :             // assume that text can be dropped into a field if the column has a ::com::sun::star::awt::XTextComponent interface
    1409           0 :             Reference< XIndexAccess >  xColumnControls((::com::sun::star::form::XGridPeer*)GetPeer(), UNO_QUERY);
    1410           0 :             if (xColumnControls.is())
    1411             :             {
    1412           0 :                 Reference< ::com::sun::star::awt::XTextComponent >  xColControl;
    1413           0 :                 ::cppu::extractInterface(xColControl,xColumnControls->getByIndex(GetViewColumnPos(nCol)));
    1414           0 :                 if (xColControl.is())
    1415             :                 {
    1416           0 :                     m_bActivatingForDrop = sal_True;
    1417           0 :                     GoToRowColumnId(nRow, nCol);
    1418           0 :                     m_bActivatingForDrop = sal_False;
    1419             : 
    1420           0 :                     nAction = DND_ACTION_COPY;
    1421           0 :                 }
    1422           0 :             }
    1423             :         }
    1424           0 :         catch( const Exception& )
    1425             :         {
    1426             :             DBG_UNHANDLED_EXCEPTION();
    1427           0 :         }
    1428             : 
    1429             :     } while (false);
    1430             : 
    1431           0 :     if(nAction != DND_ACTION_COPY && GetEmptyRow().Is())
    1432             :     {
    1433           0 :         const DataFlavorExVector& _rFlavors = GetDataFlavors();
    1434           0 :         if(::std::find_if(_rFlavors.begin(),_rFlavors.end(),SbaGridControlPrec(sal_True)) != _rFlavors.end())
    1435           0 :             nAction = DND_ACTION_COPY;
    1436             :     }
    1437             : 
    1438           0 :     return (DND_ACTION_NONE != nAction) ? nAction : FmGridControl::AcceptDrop(rEvt);
    1439             : }
    1440             : 
    1441             : //------------------------------------------------------------------------------
    1442           0 : sal_Int8 SbaGridControl::ExecuteDrop( const BrowserExecuteDropEvent& rEvt )
    1443             : {
    1444             :     // we need some properties of our data source
    1445           0 :     Reference< XPropertySet >  xDataSource = getDataSource();
    1446           0 :     if (!xDataSource.is())
    1447           0 :         return DND_ACTION_NONE;
    1448             : 
    1449             :     // we need a valid connection
    1450           0 :     if (!::dbtools::getConnection(Reference< XRowSet > (xDataSource,UNO_QUERY)).is())
    1451           0 :         return DND_ACTION_NONE;
    1452             : 
    1453           0 :     if ( IsDropFormatSupported( FORMAT_STRING ) )
    1454             :     {
    1455           0 :         long    nRow = GetRowAtYPosPixel(rEvt.maPosPixel.Y(), sal_False);
    1456           0 :         sal_uInt16  nCol = GetColumnAtXPosPixel(rEvt.maPosPixel.X(), sal_False);
    1457             : 
    1458           0 :         long nCorrectRowCount = GetRowCount();
    1459           0 :         if (GetOptions() & OPT_INSERT)
    1460           0 :             --nCorrectRowCount; // there is a empty row for inserting records
    1461           0 :         if (IsCurrentAppending())
    1462           0 :             --nCorrectRowCount; // the current data record doesn't really exist, we are appending a new one
    1463             : 
    1464             :         OSL_ENSURE((nCol != BROWSER_INVALIDID) && (nRow < nCorrectRowCount), "SbaGridControl::Drop : dropped on an invalid position !");
    1465             :             // AcceptDrop should have caught this
    1466             : 
    1467             :         // from now we work with ids instead of positions
    1468           0 :         nCol = GetColumnId(nCol);
    1469             : 
    1470           0 :         GoToRowColumnId(nRow, nCol);
    1471           0 :         if (!IsEditing())
    1472           0 :             ActivateCell();
    1473             : 
    1474           0 :         CellControllerRef xCurrentController = Controller();
    1475           0 :         if (!xCurrentController.Is() || !xCurrentController->ISA(EditCellController))
    1476           0 :             return DND_ACTION_NONE;
    1477           0 :         Edit& rEdit = (Edit&)xCurrentController->GetWindow();
    1478             : 
    1479             :         // get the dropped string
    1480           0 :         TransferableDataHelper aDropped( rEvt.maDropEvent.Transferable );
    1481           0 :         OUString sDropped;
    1482           0 :         if ( !aDropped.GetString( FORMAT_STRING, sDropped ) )
    1483           0 :             return DND_ACTION_NONE;
    1484             : 
    1485           0 :         rEdit.SetText( sDropped );
    1486           0 :         xCurrentController->SetModified();
    1487           0 :         rEdit.Modify();
    1488             :             // SetText itself doesn't call a Modify as it isn't a user interaction
    1489             : 
    1490           0 :         return DND_ACTION_COPY;
    1491             :     }
    1492             : 
    1493           0 :     if(GetEmptyRow().Is())
    1494             :     {
    1495           0 :         const DataFlavorExVector& _rFlavors = GetDataFlavors();
    1496           0 :         DataFlavorExVector::const_iterator aFind = ::std::find_if(_rFlavors.begin(),_rFlavors.end(),SbaGridControlPrec(sal_True));
    1497           0 :         if( aFind != _rFlavors.end())
    1498             :         {
    1499           0 :             TransferableDataHelper aDropped( rEvt.maDropEvent.Transferable );
    1500           0 :             m_aDataDescriptor = ODataAccessObjectTransferable::extractObjectDescriptor(aDropped);
    1501           0 :             if (m_nAsyncDropEvent)
    1502           0 :                 Application::RemoveUserEvent(m_nAsyncDropEvent);
    1503           0 :             m_nAsyncDropEvent = Application::PostUserEvent(LINK(this, SbaGridControl, AsynchDropEvent));
    1504           0 :             return DND_ACTION_COPY;
    1505             :         }
    1506             :     }
    1507             : 
    1508           0 :     return DND_ACTION_NONE;
    1509             : }
    1510             : 
    1511             : //------------------------------------------------------------------------------
    1512           0 : Reference< XPropertySet >  SbaGridControl::getDataSource() const
    1513             : {
    1514           0 :     Reference< XPropertySet >  xReturn;
    1515             : 
    1516           0 :     Reference< XChild >  xColumns(GetPeer()->getColumns(), UNO_QUERY);
    1517           0 :     Reference< XPropertySet >  xDataSource;
    1518           0 :     if (xColumns.is())
    1519           0 :         xReturn = Reference< XPropertySet > (xColumns->getParent(), UNO_QUERY);
    1520             : 
    1521           0 :     return xReturn;
    1522             : }
    1523             : // -----------------------------------------------------------------------------
    1524           0 : IMPL_LINK(SbaGridControl, AsynchDropEvent, void*, /*EMPTY_ARG*/)
    1525             : {
    1526           0 :     m_nAsyncDropEvent = 0;
    1527             : 
    1528           0 :     Reference< XPropertySet >  xDataSource = getDataSource();
    1529           0 :     if ( xDataSource.is() )
    1530             :     {
    1531           0 :         sal_Bool bCountFinal = sal_False;
    1532           0 :         xDataSource->getPropertyValue(PROPERTY_ISROWCOUNTFINAL) >>= bCountFinal;
    1533           0 :         if ( !bCountFinal )
    1534           0 :             setDataSource(NULL); // deattach from grid control
    1535           0 :         Reference< XResultSetUpdate > xResultSetUpdate(xDataSource,UNO_QUERY);
    1536           0 :         ODatabaseImportExport* pImExport = new ORowSetImportExport(this,xResultSetUpdate,m_aDataDescriptor, getContext());
    1537           0 :         Reference<XEventListener> xHolder = pImExport;
    1538           0 :         Hide();
    1539             :         try
    1540             :         {
    1541           0 :             pImExport->initialize(m_aDataDescriptor);
    1542           0 :             BeforeDrop();
    1543           0 :             if(!pImExport->Read())
    1544             :             {
    1545           0 :                 OUString sError = OUString(ModuleRes(STR_NO_COLUMNNAME_MATCHING));
    1546           0 :                 throwGenericSQLException(sError,NULL);
    1547             :             }
    1548           0 :             AfterDrop();
    1549           0 :             Show();
    1550             :         }
    1551           0 :         catch(const SQLException& e)
    1552             :         {
    1553           0 :             AfterDrop();
    1554           0 :             Show();
    1555           0 :             ::dbaui::showError( ::dbtools::SQLExceptionInfo(e), this, getContext() );
    1556             :         }
    1557           0 :         catch(const Exception& )
    1558             :         {
    1559           0 :             AfterDrop();
    1560           0 :             Show();
    1561             :             DBG_UNHANDLED_EXCEPTION();
    1562             :         }
    1563           0 :         if ( !bCountFinal )
    1564           0 :             setDataSource(Reference< XRowSet >(xDataSource,UNO_QUERY));
    1565             :     }
    1566           0 :     m_aDataDescriptor.clear();
    1567             : 
    1568           0 :     return 0L;
    1569             : }
    1570             : // -------------------------------------------------------------------------
    1571           0 : OUString SbaGridControl::GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition) const
    1572             : {
    1573           0 :     OUString sRet;
    1574           0 :     if ( ::svt::BBTYPE_BROWSEBOX == eObjType )
    1575             :     {
    1576           0 :         SolarMutexGuard aGuard;
    1577           0 :         sRet = OUString(ModuleRes(STR_DATASOURCE_GRIDCONTROL_DESC));
    1578             :     }
    1579             :     else
    1580           0 :         sRet = FmGridControl::GetAccessibleObjectDescription( eObjType,_nPosition);
    1581           0 :     return sRet;
    1582             : }
    1583             : // -----------------------------------------------------------------------------
    1584           0 : void SbaGridControl::DeleteSelectedRows()
    1585             : {
    1586           0 :     FmGridControl::DeleteSelectedRows();
    1587          12 : }
    1588             : 
    1589             : 
    1590             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10