LCOV - code coverage report
Current view: top level - svx/source/form - tabwin.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 176 0.0 %
Date: 2014-04-14 Functions: 0 28 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10