LCOV - code coverage report
Current view: top level - svx/source/form - tabwin.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 2 176 1.1 %
Date: 2014-11-03 Functions: 3 30 10.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "tabwin.hxx"
      22             : #include "svx/fmtools.hxx"
      23             : #include "fmservs.hxx"
      24             : #include "stringlistresource.hxx"
      25             : 
      26             : #include <svx/svxids.hrc>
      27             : #include <svx/dbaexchange.hxx>
      28             : #include <com/sun/star/sdb/CommandType.hpp>
      29             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      30             : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
      31             : #include <com/sun/star/sdbc/XPreparedStatement.hpp>
      32             : #include <com/sun/star/awt/XControlContainer.hpp>
      33             : #include <com/sun/star/util/XLocalizedAliases.hpp>
      34             : #include <comphelper/processfactory.hxx>
      35             : 
      36             : #include "fmhelp.hrc"
      37             : #include <svx/fmshell.hxx>
      38             : #include "fmshimp.hxx"
      39             : #include "svx/dbtoolsclient.hxx"
      40             : #include <svx/fmpage.hxx>
      41             : 
      42             : #include "fmpgeimp.hxx"
      43             : 
      44             : #include "fmprop.hrc"
      45             : 
      46             : #include "svx/fmresids.hrc"
      47             : #include <svx/dialmgr.hxx>
      48             : #include <svx/svdpagv.hxx>
      49             : #include <sfx2/objitem.hxx>
      50             : #include <sfx2/dispatch.hxx>
      51             : #include <comphelper/property.hxx>
      52             : #include <sfx2/frame.hxx>
      53             : #include <svx/dataaccessdescriptor.hxx>
      54             : #include "svtools/treelistentry.hxx"
      55             : #include <vcl/settings.hxx>
      56             : 
      57             : const long STD_WIN_SIZE_X = 120;
      58             : const long STD_WIN_SIZE_Y = 150;
      59             : 
      60             : const long LISTBOX_BORDER = 2;
      61             : 
      62             : using namespace ::com::sun::star::sdbc;
      63             : using namespace ::com::sun::star::sdb;
      64             : using namespace ::com::sun::star::uno;
      65             : using namespace ::com::sun::star::datatransfer;
      66             : using namespace ::com::sun::star::beans;
      67             : using namespace ::com::sun::star::lang;
      68             : using namespace ::com::sun::star::form;
      69             : using namespace ::com::sun::star::container;
      70             : using namespace ::com::sun::star;
      71             : using namespace ::svxform;
      72             : using namespace ::svx;
      73             : 
      74             : namespace {
      75             : 
      76             : struct ColumnInfo
      77             : {
      78             :     OUString sColumnName;
      79             :     OUString sLabel;
      80           0 :     ColumnInfo(const OUString& i_sColumnName,const OUString& i_sLabel)
      81             :         : sColumnName(i_sColumnName)
      82           0 :         , sLabel(i_sLabel)
      83             :     {
      84           0 :     }
      85             : };
      86             : 
      87             : }
      88             : 
      89           0 : static void lcl_addToList( SvTreeListBox& _rListBox, const uno::Reference< container::XNameAccess>& i_xColumns )
      90             : {
      91           0 :     uno::Sequence< OUString > aEntries = i_xColumns->getElementNames();
      92           0 :     const OUString* pEntries = aEntries.getConstArray();
      93           0 :     sal_Int32 nEntries = aEntries.getLength();
      94           0 :     for ( sal_Int32 i = 0; i < nEntries; ++i, ++pEntries )
      95             :     {
      96           0 :         uno::Reference< beans::XPropertySet> xColumn(i_xColumns->getByName(*pEntries),UNO_QUERY_THROW);
      97           0 :         OUString sLabel;
      98           0 :         if ( xColumn->getPropertySetInfo()->hasPropertyByName(FM_PROP_LABEL) )
      99           0 :             xColumn->getPropertyValue(FM_PROP_LABEL) >>= sLabel;
     100           0 :         if ( !sLabel.isEmpty() )
     101           0 :             _rListBox.InsertEntry( sLabel, NULL, false, TREELIST_APPEND, new ColumnInfo(*pEntries,sLabel) );
     102             :         else
     103           0 :             _rListBox.InsertEntry( *pEntries, NULL, false, TREELIST_APPEND, new ColumnInfo(*pEntries,sLabel) );
     104           0 :     }
     105           0 : }
     106             : 
     107           0 : FmFieldWinListBox::FmFieldWinListBox( FmFieldWin* pParent )
     108             :     :SvTreeListBox( pParent, WB_HASBUTTONS|WB_BORDER )
     109           0 :     ,pTabWin( pParent )
     110             : {
     111           0 :     SetHelpId( HID_FIELD_SEL );
     112             : 
     113           0 :     SetHighlightRange( );
     114           0 : }
     115             : 
     116             : 
     117           0 : FmFieldWinListBox::~FmFieldWinListBox()
     118             : {
     119           0 : }
     120             : 
     121             : 
     122           0 : sal_Int8 FmFieldWinListBox::AcceptDrop( const AcceptDropEvent& /*rEvt*/ )
     123             : {
     124           0 :     return DND_ACTION_NONE;
     125             : }
     126             : 
     127             : 
     128           0 : sal_Int8 FmFieldWinListBox::ExecuteDrop( const ExecuteDropEvent& /*rEvt*/ )
     129             : {
     130           0 :     return DND_ACTION_NONE;
     131             : }
     132             : 
     133             : 
     134           0 : bool FmFieldWinListBox::DoubleClickHdl()
     135             : {
     136           0 :     if ( pTabWin->createSelectionControls() )
     137           0 :         return true;
     138             : 
     139           0 :     return SvTreeListBox::DoubleClickHdl();
     140             : }
     141             : 
     142             : 
     143           0 : void FmFieldWinListBox::StartDrag( sal_Int8 /*_nAction*/, const Point& /*_rPosPixel*/ )
     144             : {
     145           0 :     SvTreeListEntry* pSelected = FirstSelected();
     146           0 :     if (!pSelected)
     147             :         // no drag without a field
     148           0 :         return;
     149             : 
     150           0 :     ::svx::ODataAccessDescriptor aDescriptor;
     151           0 :     aDescriptor[ daDataSource ] <<= pTabWin->GetDatabaseName();
     152           0 :     aDescriptor[ daConnection ] <<= pTabWin->GetConnection().getTyped();
     153           0 :     aDescriptor[ daCommand ]    <<= pTabWin->GetObjectName();
     154           0 :     aDescriptor[ daCommandType ]<<= pTabWin->GetObjectType();
     155           0 :     ColumnInfo* pInfo = static_cast<ColumnInfo*>(pSelected->GetUserData());
     156           0 :     aDescriptor[ daColumnName ] <<= pInfo->sColumnName;
     157             : 
     158             :     TransferableHelper* pTransferColumn = new OColumnTransferable(
     159             :         aDescriptor, CTF_FIELD_DESCRIPTOR | CTF_CONTROL_EXCHANGE | CTF_COLUMN_DESCRIPTOR
     160           0 :     );
     161           0 :     Reference< XTransferable> xEnsureDelete = pTransferColumn;
     162           0 :     if (pTransferColumn)
     163             :     {
     164           0 :         EndSelection();
     165           0 :         pTransferColumn->StartDrag( this, DND_ACTION_COPY );
     166           0 :     }
     167             : }
     168             : 
     169           0 : FmFieldWinData::FmFieldWinData()
     170             : {
     171           0 : }
     172             : 
     173             : 
     174           0 : FmFieldWinData::~FmFieldWinData()
     175             : {
     176           0 : }
     177             : 
     178           0 : FmFieldWin::FmFieldWin(SfxBindings* _pBindings, SfxChildWindow* _pMgr, vcl::Window* _pParent)
     179             :             :SfxFloatingWindow(_pBindings, _pMgr, _pParent, WinBits(WB_STDMODELESS|WB_SIZEABLE))
     180             :             ,SfxControllerItem(SID_FM_FIELDS_CONTROL, *_pBindings)
     181             :             ,::comphelper::OPropertyChangeListener(m_aMutex)
     182           0 :             ,pData(new FmFieldWinData)
     183             :             ,m_nObjectType(0)
     184           0 :             ,m_pChangeListener(NULL)
     185             : {
     186           0 :     SetHelpId( HID_FIELD_SEL_WIN );
     187             : 
     188           0 :     SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor()) );
     189           0 :     pListBox = new FmFieldWinListBox( this );
     190           0 :     pListBox->Show();
     191           0 :     UpdateContent(NULL);
     192           0 :     SetSizePixel(Size(STD_WIN_SIZE_X,STD_WIN_SIZE_Y));
     193           0 : }
     194             : 
     195             : 
     196           0 : FmFieldWin::~FmFieldWin()
     197             : {
     198           0 :     if (m_pChangeListener)
     199             :     {
     200           0 :         m_pChangeListener->dispose();
     201           0 :         m_pChangeListener->release();
     202             :         //  delete m_pChangeListener;
     203             :     }
     204           0 :     delete pListBox;
     205           0 :     delete pData;
     206           0 : }
     207             : 
     208             : 
     209           0 : void FmFieldWin::GetFocus()
     210             : {
     211           0 :     if ( pListBox )
     212           0 :         pListBox->GrabFocus();
     213             :     else
     214           0 :         SfxFloatingWindow::GetFocus();
     215           0 : }
     216             : 
     217             : 
     218           0 : bool FmFieldWin::createSelectionControls( )
     219             : {
     220           0 :     SvTreeListEntry* pSelected = pListBox->FirstSelected();
     221           0 :     if ( pSelected )
     222             :     {
     223             :         // build a descriptor for the currently selected field
     224           0 :         ODataAccessDescriptor aDescr;
     225           0 :         aDescr.setDataSource(GetDatabaseName());
     226             : 
     227           0 :         aDescr[ daConnection ]  <<= GetConnection().getTyped();
     228             : 
     229           0 :         aDescr[ daCommand ]     <<= GetObjectName();
     230           0 :         aDescr[ daCommandType ] <<= GetObjectType();
     231           0 :         ColumnInfo* pInfo = static_cast<ColumnInfo*>(pSelected->GetUserData());
     232           0 :         aDescr[ daColumnName ]  <<= pInfo->sColumnName;//OUString( pListBox->GetEntryText( pSelected) );
     233             : 
     234             :         // transfer this to the SFX world
     235           0 :         SfxUnoAnyItem aDescriptorItem( SID_FM_DATACCESS_DESCRIPTOR, makeAny( aDescr.createPropertyValueSequence() ) );
     236             :         const SfxPoolItem* pArgs[] =
     237             :         {
     238             :             &aDescriptorItem, NULL
     239           0 :         };
     240             : 
     241             :         // execute the create slot
     242           0 :         GetBindings().Execute( SID_FM_CREATE_FIELDCONTROL, pArgs );
     243             :     }
     244             : 
     245           0 :     return NULL != pSelected;
     246             : }
     247             : 
     248             : 
     249           0 : bool FmFieldWin::PreNotify( NotifyEvent& _rNEvt )
     250             : {
     251           0 :     if ( EVENT_KEYINPUT == _rNEvt.GetType() )
     252             :     {
     253           0 :         const vcl::KeyCode& rKeyCode = _rNEvt.GetKeyEvent()->GetKeyCode();
     254           0 :         if ( ( 0 == rKeyCode.GetModifier() ) && ( KEY_RETURN == rKeyCode.GetCode() ) )
     255             :         {
     256           0 :             if ( createSelectionControls() )
     257           0 :                 return true;
     258             :         }
     259             :     }
     260             : 
     261           0 :     return SfxFloatingWindow::PreNotify( _rNEvt );
     262             : }
     263             : 
     264             : 
     265           0 : bool FmFieldWin::Close()
     266             : {
     267           0 :     return SfxFloatingWindow::Close();
     268             : }
     269             : 
     270             : 
     271           0 : void FmFieldWin::_propertyChanged(const ::com::sun::star::beans::PropertyChangeEvent& evt) throw( ::com::sun::star::uno::RuntimeException )
     272             : {
     273           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >  xForm(evt.Source, ::com::sun::star::uno::UNO_QUERY);
     274           0 :     UpdateContent(xForm);
     275           0 : }
     276             : 
     277             : 
     278           0 : void FmFieldWin::StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState)
     279             : {
     280           0 :     if (!pState  || SID_FM_FIELDS_CONTROL != nSID)
     281           0 :         return;
     282             : 
     283           0 :     if (eState >= SfxItemState::DEFAULT)
     284             :     {
     285           0 :         FmFormShell* pShell = PTR_CAST(FmFormShell, static_cast<const SfxObjectItem*>(pState)->GetShell());
     286           0 :         UpdateContent(pShell);
     287             :     }
     288             :     else
     289           0 :         UpdateContent(NULL);
     290             : }
     291             : 
     292             : 
     293           0 : void FmFieldWin::UpdateContent(FmFormShell* pShell)
     294             : {
     295           0 :     pListBox->Clear();
     296           0 :     OUString aTitle(SVX_RESSTR(RID_STR_FIELDSELECTION));
     297           0 :     SetText( aTitle );
     298             : 
     299           0 :     if (!pShell || !pShell->GetImpl())
     300           0 :         return;
     301             : 
     302           0 :     Reference< XForm >  xForm = pShell->GetImpl()->getCurrentForm();
     303           0 :     if ( xForm.is() )
     304           0 :         UpdateContent( xForm );
     305             : }
     306             : 
     307             : 
     308           0 : void FmFieldWin::UpdateContent(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm > & xForm)
     309             : {
     310             :     try
     311             :     {
     312             :         // ListBox loeschen
     313           0 :         pListBox->Clear();
     314           0 :         OUString aTitle(SVX_RES(RID_STR_FIELDSELECTION));
     315           0 :         SetText(aTitle);
     316             : 
     317           0 :         if (!xForm.is())
     318           0 :             return;
     319             : 
     320           0 :         Reference< XPreparedStatement >  xStatement;
     321           0 :         Reference< XPropertySet >  xSet(xForm, UNO_QUERY);
     322             : 
     323           0 :         m_aObjectName   = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_COMMAND));
     324           0 :         m_aDatabaseName = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_DATASOURCE));
     325           0 :         m_nObjectType   = ::comphelper::getINT32(xSet->getPropertyValue(FM_PROP_COMMANDTYPE));
     326             : 
     327             :         // get the connection of the form
     328           0 :         OStaticDataAccessTools aTools;
     329             :         m_aConnection.reset(
     330             :             aTools.connectRowset( Reference< XRowSet >( xForm, UNO_QUERY ), ::comphelper::getProcessComponentContext(), true ),
     331             :             SharedConnection::NoTakeOwnership
     332           0 :         );
     333             :         // TODO: When incompatible changes (such as extending the "virtualdbtools" interface by ensureRowSetConnection)
     334             :         // are allowed, again, we should change this: dbtools should consistently use SharedConnection all over
     335             :         // the place, and connectRowset should be replaced with ensureRowSetConnection
     336             : 
     337             :         // get the fields of the object
     338             : 
     339           0 :         if ( m_aConnection.is() && !m_aObjectName.isEmpty() )
     340             :         {
     341           0 :             Reference< XComponent > xKeepFieldsAlive;
     342           0 :             Reference< XNameAccess > xColumns = getFieldsByCommandDescriptor( m_aConnection, m_nObjectType, m_aObjectName,xKeepFieldsAlive );
     343           0 :             if ( xColumns.is() )
     344           0 :                 lcl_addToList(*pListBox,xColumns);
     345             :         }
     346             : 
     347             :         // Prefix setzen
     348           0 :         OUString  aPrefix;
     349           0 :         StringListResource aPrefixes( SVX_RES( RID_RSC_TABWIN_PREFIX ) );
     350             : 
     351           0 :         switch (m_nObjectType)
     352             :         {
     353             :             case CommandType::TABLE:
     354           0 :                 aPrefix = aPrefixes[0];
     355           0 :                 break;
     356             :             case CommandType::QUERY:
     357           0 :                 aPrefix = aPrefixes[1];
     358           0 :                 break;
     359             :             default:
     360           0 :                 aPrefix = aPrefixes[2];
     361           0 :                 break;
     362             :         }
     363             : 
     364             :         // an dem PropertySet nach Aenderungen der ControlSource lauschen
     365           0 :         if (m_pChangeListener)
     366             :         {
     367           0 :             m_pChangeListener->dispose();
     368           0 :             m_pChangeListener->release();
     369             :         }
     370           0 :         m_pChangeListener = new ::comphelper::OPropertyChangeMultiplexer(this, xSet);
     371           0 :         m_pChangeListener->acquire();
     372           0 :         m_pChangeListener->addProperty(FM_PROP_DATASOURCE);
     373           0 :         m_pChangeListener->addProperty(FM_PROP_COMMAND);
     374           0 :         m_pChangeListener->addProperty(FM_PROP_COMMANDTYPE);
     375             : 
     376             :         // Titel setzen
     377           0 :         aTitle = aTitle + " " + aPrefix + " " + OUString(m_aObjectName.getStr());
     378           0 :         SetText( aTitle );
     379             :     }
     380           0 :     catch( const Exception& )
     381             :     {
     382             :         OSL_FAIL( "FmTabWin::UpdateContent: caught an exception!" );
     383             :     }
     384             : }
     385             : 
     386             : 
     387           0 : void FmFieldWin::Resize()
     388             : {
     389           0 :     SfxFloatingWindow::Resize();
     390             : 
     391           0 :     Size aOutputSize( GetOutputSizePixel() );
     392             : 
     393             : 
     394             : 
     395             :     // Groesse der ::com::sun::star::form::ListBox anpassen
     396           0 :     Point aLBPos( LISTBOX_BORDER, LISTBOX_BORDER );
     397           0 :     Size aLBSize( aOutputSize );
     398           0 :     aLBSize.Width() -= (2*LISTBOX_BORDER);
     399           0 :     aLBSize.Height() -= (2*LISTBOX_BORDER);
     400             : 
     401           0 :     pListBox->SetPosSizePixel( aLBPos, aLBSize );
     402           0 : }
     403             : 
     404             : 
     405           0 : void FmFieldWin::FillInfo( SfxChildWinInfo& rInfo ) const
     406             : {
     407           0 :     rInfo.bVisible = false;
     408           0 : }
     409             : 
     410             : 
     411         170 : SFX_IMPL_FLOATINGWINDOW(FmFieldWinMgr, SID_FM_ADD_FIELD)
     412             : 
     413             : 
     414           0 : FmFieldWinMgr::FmFieldWinMgr(vcl::Window* _pParent, sal_uInt16 _nId,
     415             :                SfxBindings* _pBindings, SfxChildWinInfo* _pInfo)
     416           0 :               :SfxChildWindow(_pParent, _nId)
     417             : {
     418           0 :     pWindow = new FmFieldWin(_pBindings, this, _pParent);
     419           0 :     SetHideNotDelete(true);
     420           0 :     eChildAlignment = SFX_ALIGN_NOALIGNMENT;
     421           0 :     static_cast<SfxFloatingWindow*>(pWindow)->Initialize( _pInfo );
     422         594 : }
     423             : 
     424             : 
     425             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10