LCOV - code coverage report
Current view: top level - reportdesign/source/ui/dlg - AddField.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 261 0.0 %
Date: 2012-08-25 Functions: 0 31 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : #include "AddField.hxx"
      29                 :            : #include "UITools.hxx"
      30                 :            : #include <svx/dbaexchange.hxx>
      31                 :            : #include <svx/svdpagv.hxx>
      32                 :            : #include <com/sun/star/sdb/CommandType.hpp>
      33                 :            : #include <com/sun/star/util/URL.hpp>
      34                 :            : #include <com/sun/star/sdb/XDocumentDataSource.hpp>
      35                 :            : #include <com/sun/star/util/URL.hpp>
      36                 :            : #include <com/sun/star/i18n/XCollator.hpp>
      37                 :            : 
      38                 :            : #include <vcl/waitobj.hxx>
      39                 :            : #include <vcl/svapp.hxx>
      40                 :            : #include <tools/diagnose_ex.h>
      41                 :            : #include <comphelper/stl_types.hxx>
      42                 :            : #include "rptui_slotid.hrc"
      43                 :            : 
      44                 :            : #include <connectivity/dbtools.hxx>
      45                 :            : #include "helpids.hrc"
      46                 :            : #include "RptResId.hrc"
      47                 :            : #include "CondFormat.hrc"
      48                 :            : #include "ModuleHelper.hxx"
      49                 :            : #include "uistrings.hrc"
      50                 :            : #include "ColumnInfo.hxx"
      51                 :            : 
      52                 :            : #include <comphelper/property.hxx>
      53                 :            : #include <svtools/imgdef.hxx>
      54                 :            : 
      55                 :            : namespace rptui
      56                 :            : {
      57                 :            : const long STD_WIN_SIZE_X = 180;
      58                 :            : const long STD_WIN_SIZE_Y = 320;
      59                 :            : 
      60                 :            : const long LISTBOX_BORDER = 2;
      61                 :            : 
      62                 :            : using namespace ::com::sun::star;
      63                 :            : using namespace sdbc;
      64                 :            : using namespace sdb;
      65                 :            : using namespace uno;
      66                 :            : using namespace datatransfer;
      67                 :            : using namespace beans;
      68                 :            : using namespace lang;
      69                 :            : using namespace container;
      70                 :            : using namespace ::svx;
      71                 :            : 
      72                 :            : class OAddFieldWindowListBox    : public SvTreeListBox
      73                 :            : {
      74                 :            :     OAddFieldWindow*                    m_pTabWin;
      75                 :            : 
      76                 :            :     OAddFieldWindowListBox(const OAddFieldWindowListBox&);
      77                 :            :     void operator =(const OAddFieldWindowListBox&);
      78                 :            : 
      79                 :            : public:
      80                 :            :     OAddFieldWindowListBox( OAddFieldWindow* _pParent );
      81                 :            :     virtual ~OAddFieldWindowListBox();
      82                 :            : 
      83                 :            :     sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt );
      84                 :            :     sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt );
      85                 :            : 
      86                 :            :     uno::Sequence< beans::PropertyValue > getSelectedFieldDescriptors();
      87                 :            : 
      88                 :            : protected:
      89                 :            :     // DragSourceHelper
      90                 :            :     virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel );
      91                 :            : 
      92                 :            : private:
      93                 :            :     using SvTreeListBox::ExecuteDrop;
      94                 :            : };
      95                 :            : // -----------------------------------------------------------------------------
      96                 :          0 : uno::Sequence< beans::PropertyValue > OAddFieldWindowListBox::getSelectedFieldDescriptors()
      97                 :            : {
      98                 :          0 :     uno::Sequence< beans::PropertyValue > aArgs(GetSelectionCount());
      99                 :          0 :     sal_Int32 i = 0;
     100                 :          0 :     SvLBoxEntry* pSelected = FirstSelected();
     101                 :          0 :     while( pSelected )
     102                 :            :     {
     103                 :            :         // build a descriptor for the currently selected field
     104                 :          0 :         ::svx::ODataAccessDescriptor aDescriptor;
     105                 :          0 :         m_pTabWin->fillDescriptor(pSelected,aDescriptor);
     106                 :          0 :         aArgs[i++].Value <<= aDescriptor.createPropertyValueSequence();
     107                 :          0 :         pSelected = NextSelected(pSelected);
     108                 :          0 :     }
     109                 :          0 :     return aArgs;
     110                 :            : }
     111                 :            : //==================================================================
     112                 :            : // class OAddFieldWindowListBox
     113                 :            : //==================================================================
     114                 :            : DBG_NAME( rpt_OAddFieldWindowListBox );
     115                 :            : //------------------------------------------------------------------------------
     116                 :          0 : OAddFieldWindowListBox::OAddFieldWindowListBox( OAddFieldWindow* _pParent )
     117                 :            :     :SvTreeListBox( _pParent, WB_TABSTOP|WB_BORDER|WB_SORT )
     118                 :          0 :     ,m_pTabWin( _pParent )
     119                 :            : {
     120                 :            :     DBG_CTOR( rpt_OAddFieldWindowListBox,NULL);
     121                 :          0 :     SetHelpId( HID_RPT_FIELD_SEL );
     122                 :          0 :     SetSelectionMode(MULTIPLE_SELECTION);
     123                 :          0 :     SetDragDropMode( 0xFFFF );
     124                 :          0 :     SetHighlightRange( );
     125                 :          0 : }
     126                 :            : 
     127                 :            : //------------------------------------------------------------------------------
     128                 :          0 : OAddFieldWindowListBox::~OAddFieldWindowListBox()
     129                 :            : {
     130                 :            :     DBG_DTOR( rpt_OAddFieldWindowListBox,NULL);
     131                 :          0 : }
     132                 :            : 
     133                 :            : //------------------------------------------------------------------------------
     134                 :          0 : sal_Int8 OAddFieldWindowListBox::AcceptDrop( const AcceptDropEvent& /*rEvt*/ )
     135                 :            : {
     136                 :          0 :     return DND_ACTION_NONE;
     137                 :            : }
     138                 :            : 
     139                 :            : //------------------------------------------------------------------------------
     140                 :          0 : sal_Int8 OAddFieldWindowListBox::ExecuteDrop( const ExecuteDropEvent& /*rEvt*/ )
     141                 :            : {
     142                 :          0 :     return DND_ACTION_NONE;
     143                 :            : }
     144                 :            : 
     145                 :            : //------------------------------------------------------------------------------
     146                 :          0 : void OAddFieldWindowListBox::StartDrag( sal_Int8 /*_nAction*/, const Point& /*_rPosPixel*/ )
     147                 :            : {
     148                 :          0 :     if ( GetSelectionCount() < 1 )
     149                 :            :         // no drag without a field
     150                 :          0 :         return;
     151                 :            : 
     152                 :          0 :     OMultiColumnTransferable* pDataContainer = new OMultiColumnTransferable(getSelectedFieldDescriptors());
     153                 :          0 :     Reference< XTransferable> xEnsureDelete = pDataContainer;
     154                 :            : 
     155                 :          0 :     EndSelection();
     156                 :          0 :     pDataContainer->StartDrag( this, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
     157                 :            : }
     158                 :            : //========================================================================
     159                 :            : // class OAddFieldWindow
     160                 :            : //========================================================================
     161                 :            : DBG_NAME( rpt_OAddFieldWindow );
     162                 :            : //-----------------------------------------------------------------------
     163                 :          0 : OAddFieldWindow::OAddFieldWindow(Window* pParent
     164                 :            :                                  ,const uno::Reference< beans::XPropertySet >& _xRowSet
     165                 :            :                                  )
     166                 :            :             :FloatingWindow(pParent, WinBits(WB_STDMODELESS|WB_SIZEABLE))
     167                 :            :             ,::comphelper::OPropertyChangeListener(m_aMutex)
     168                 :            :             ,::comphelper::OContainerListener(m_aMutex)
     169                 :            :             ,m_xRowSet(_xRowSet)
     170                 :            :             ,m_aActions(this,ModuleRes(RID_TB_SORTING))
     171                 :          0 :             ,m_pListBox(new OAddFieldWindowListBox( this ))
     172                 :            :             ,m_aFixedLine(this, ModuleRes(ADDFIELD_FL_HELP_SEPARATOR) )
     173                 :            :             ,m_aHelpText(this, ModuleRes(ADDFIELD_HELP_FIELD) )
     174                 :            :             ,m_aInsertButton(this, WB_TABSTOP|WB_CENTER)
     175                 :            :             ,m_nCommandType(0)
     176                 :            :             ,m_bEscapeProcessing(sal_False)
     177                 :            :             ,m_pChangeListener(NULL)
     178                 :          0 :             ,m_pContainerListener(NULL)
     179                 :            : {
     180                 :            :     DBG_CTOR( rpt_OAddFieldWindow,NULL);
     181                 :          0 :     SetHelpId( HID_RPT_FIELD_SEL_WIN );
     182                 :          0 :     SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor()) );
     183                 :          0 :     SetMinOutputSizePixel(Size(STD_WIN_SIZE_X,STD_WIN_SIZE_Y));
     184                 :            : 
     185                 :          0 :     m_aActions.SetStyle(m_aActions.GetStyle()|WB_LINESPACING);
     186                 :          0 :     m_aActions.SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor()) );
     187                 :            : 
     188                 :          0 :     m_aActions.SetSelectHdl(LINK(this, OAddFieldWindow, OnSortAction));
     189                 :          0 :     setToolBox(&m_aActions);
     190                 :          0 :     m_aActions.CheckItem(SID_FM_SORTUP);
     191                 :          0 :     m_aActions.EnableItem(SID_ADD_CONTROL_PAIR, sal_False);
     192                 :            : 
     193                 :          0 :     m_pListBox->SetDoubleClickHdl(LINK( this, OAddFieldWindow, OnDoubleClickHdl ) );
     194                 :          0 :     m_pListBox->SetSelectHdl(LINK( this, OAddFieldWindow, OnSelectHdl ) );
     195                 :          0 :     m_pListBox->SetDeselectHdl(LINK( this, OAddFieldWindow, OnSelectHdl ) );
     196                 :          0 :     m_pListBox->SetDoubleClickHdl(LINK( this, OAddFieldWindow, OnDoubleClickHdl ) );
     197                 :          0 :     m_pListBox->Show();
     198                 :          0 :     const String sTitle(ModuleRes(RID_STR_INSERT));
     199                 :          0 :     m_aInsertButton.SetText(sTitle);
     200                 :          0 :     m_aInsertButton.SetClickHdl(LINK( this, OAddFieldWindow, OnDoubleClickHdl ) );
     201                 :          0 :     m_aInsertButton.Show();
     202                 :            : 
     203                 :          0 :     m_aFixedLine.SetControlBackground( GetSettings().GetStyleSettings().GetFaceColor() );
     204                 :          0 :     m_aHelpText.SetControlBackground( GetSettings().GetStyleSettings().GetFaceColor() );
     205                 :            : 
     206                 :          0 :     SetSizePixel(Size(STD_WIN_SIZE_X,STD_WIN_SIZE_Y));
     207                 :            : 
     208                 :          0 :     if ( m_xRowSet.is() )
     209                 :            :     {
     210                 :            :         try
     211                 :            :         {
     212                 :            :             // be notified when the settings of report definition change
     213                 :          0 :             m_pChangeListener = new ::comphelper::OPropertyChangeMultiplexer( this, m_xRowSet );
     214                 :          0 :             m_pChangeListener->addProperty( PROPERTY_COMMAND );
     215                 :          0 :             m_pChangeListener->addProperty( PROPERTY_COMMANDTYPE );
     216                 :          0 :             m_pChangeListener->addProperty( PROPERTY_ESCAPEPROCESSING );
     217                 :          0 :             m_pChangeListener->addProperty( PROPERTY_FILTER );
     218                 :            :         }
     219                 :          0 :         catch( const Exception& )
     220                 :            :         {
     221                 :            :             DBG_UNHANDLED_EXCEPTION();
     222                 :            :         }
     223                 :          0 :     }
     224                 :          0 : }
     225                 :            : 
     226                 :            : //-----------------------------------------------------------------------
     227                 :          0 : OAddFieldWindow::~OAddFieldWindow()
     228                 :            : {
     229                 :          0 :     if ( m_pListBox.get() )
     230                 :            :     {
     231                 :          0 :         SvLBoxTreeList* pModel = m_pListBox->GetModel();
     232                 :          0 :         sal_uLong nCount = pModel->GetEntryCount();
     233                 :          0 :         for(sal_uLong i = 0; i< nCount;++i)
     234                 :            :         {
     235                 :          0 :             delete static_cast<ColumnInfo*>(pModel->GetEntry(i)->GetUserData());
     236                 :            :         }
     237                 :            :     }
     238                 :          0 :     if (m_pChangeListener.is())
     239                 :          0 :         m_pChangeListener->dispose();
     240                 :          0 :     if ( m_pContainerListener.is() )
     241                 :          0 :         m_pContainerListener->dispose();
     242                 :            :     DBG_DTOR( rpt_OAddFieldWindow,NULL);
     243                 :          0 : }
     244                 :            : 
     245                 :            : //-----------------------------------------------------------------------
     246                 :          0 : void OAddFieldWindow::GetFocus()
     247                 :            : {
     248                 :          0 :     if ( m_pListBox.get() )
     249                 :          0 :         m_pListBox->GrabFocus();
     250                 :            :     else
     251                 :          0 :         FloatingWindow::GetFocus();
     252                 :          0 : }
     253                 :            : //-----------------------------------------------------------------------
     254                 :          0 : uno::Sequence< beans::PropertyValue > OAddFieldWindow::getSelectedFieldDescriptors()
     255                 :            : {
     256                 :          0 :     return m_pListBox->getSelectedFieldDescriptors();
     257                 :            : }
     258                 :            : 
     259                 :            : //-----------------------------------------------------------------------
     260                 :          0 : long OAddFieldWindow::PreNotify( NotifyEvent& _rNEvt )
     261                 :            : {
     262                 :          0 :     if ( EVENT_KEYINPUT == _rNEvt.GetType() )
     263                 :            :     {
     264                 :          0 :         const KeyCode& rKeyCode = _rNEvt.GetKeyEvent()->GetKeyCode();
     265                 :          0 :         if ( ( 0 == rKeyCode.GetModifier() ) && ( KEY_RETURN == rKeyCode.GetCode() ) )
     266                 :            :         {
     267                 :          0 :             if ( m_aCreateLink.IsSet() )
     268                 :            :             {
     269                 :          0 :                 m_aCreateLink.Call(this);
     270                 :          0 :                 return 1;
     271                 :            :             }
     272                 :            :         }
     273                 :            :     }
     274                 :            : 
     275                 :          0 :     return FloatingWindow::PreNotify( _rNEvt );
     276                 :            : }
     277                 :            : //-----------------------------------------------------------------------
     278                 :          0 : void OAddFieldWindow::_propertyChanged( const beans::PropertyChangeEvent& _evt ) throw( uno::RuntimeException )
     279                 :            : {
     280                 :            :     OSL_ENSURE( _evt.Source == m_xRowSet, "OAddFieldWindow::_propertyChanged: where did this come from?" );
     281                 :            :     (void)_evt;
     282                 :          0 :     Update();
     283                 :          0 : }
     284                 :            : 
     285                 :            : //-----------------------------------------------------------------------
     286                 :            : namespace
     287                 :            : {
     288                 :          0 :     void lcl_addToList( OAddFieldWindowListBox& _rListBox, const uno::Sequence< ::rtl::OUString >& _rEntries )
     289                 :            :     {
     290                 :          0 :         const ::rtl::OUString* pEntries = _rEntries.getConstArray();
     291                 :          0 :         sal_Int32 nEntries = _rEntries.getLength();
     292                 :          0 :         for ( sal_Int32 i = 0; i < nEntries; ++i, ++pEntries )
     293                 :          0 :             _rListBox.InsertEntry( *pEntries,NULL,sal_False,LIST_APPEND,new ColumnInfo(*pEntries) );
     294                 :          0 :     }
     295                 :          0 :     void lcl_addToList( OAddFieldWindowListBox& _rListBox, const uno::Reference< container::XNameAccess>& i_xColumns )
     296                 :            :     {
     297                 :          0 :         uno::Sequence< ::rtl::OUString > aEntries = i_xColumns->getElementNames();
     298                 :          0 :         const ::rtl::OUString* pEntries = aEntries.getConstArray();
     299                 :          0 :         sal_Int32 nEntries = aEntries.getLength();
     300                 :          0 :         for ( sal_Int32 i = 0; i < nEntries; ++i, ++pEntries )
     301                 :            :         {
     302                 :          0 :             uno::Reference< beans::XPropertySet> xColumn(i_xColumns->getByName(*pEntries),UNO_QUERY_THROW);
     303                 :          0 :             ::rtl::OUString sLabel;
     304                 :          0 :             if ( xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_LABEL) )
     305                 :          0 :                 xColumn->getPropertyValue(PROPERTY_LABEL) >>= sLabel;
     306                 :          0 :             if ( !sLabel.isEmpty() )
     307                 :          0 :                 _rListBox.InsertEntry( sLabel,NULL,sal_False,LIST_APPEND,new ColumnInfo(*pEntries,sLabel) );
     308                 :            :             else
     309                 :          0 :                 _rListBox.InsertEntry( *pEntries,NULL,sal_False,LIST_APPEND,new ColumnInfo(*pEntries,sLabel) );
     310                 :          0 :         }
     311                 :          0 :     }
     312                 :            : }
     313                 :            : 
     314                 :            : //-----------------------------------------------------------------------
     315                 :          0 : void OAddFieldWindow::Update()
     316                 :            : {
     317                 :          0 :     if ( m_pContainerListener.is() )
     318                 :          0 :         m_pContainerListener->dispose();
     319                 :          0 :     m_pContainerListener = NULL;
     320                 :          0 :     m_xColumns.clear();
     321                 :            : 
     322                 :            :     try
     323                 :            :     {
     324                 :            :         // ListBox loeschen
     325                 :          0 :         m_pListBox->Clear();
     326                 :          0 :         const sal_uInt16 nItemCount = m_aActions.GetItemCount();
     327                 :          0 :         for (sal_uInt16 j = 0; j< nItemCount; ++j)
     328                 :            :         {
     329                 :          0 :             m_aActions.EnableItem(m_aActions.GetItemId(j),sal_False);
     330                 :            :         }
     331                 :            : 
     332                 :          0 :         String aTitle(ModuleRes(RID_STR_FIELDSELECTION));
     333                 :          0 :         SetText(aTitle);
     334                 :          0 :         if ( m_xRowSet.is() )
     335                 :            :         {
     336                 :          0 :             ::rtl::OUString sCommand( m_aCommandName );
     337                 :          0 :             sal_Int32       nCommandType( m_nCommandType );
     338                 :          0 :             sal_Bool        bEscapeProcessing( m_bEscapeProcessing );
     339                 :          0 :             ::rtl::OUString sFilter( m_sFilter );
     340                 :            : 
     341                 :          0 :             OSL_VERIFY( m_xRowSet->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand );
     342                 :          0 :             OSL_VERIFY( m_xRowSet->getPropertyValue( PROPERTY_COMMANDTYPE ) >>= nCommandType );
     343                 :          0 :             OSL_VERIFY( m_xRowSet->getPropertyValue( PROPERTY_ESCAPEPROCESSING ) >>= bEscapeProcessing );
     344                 :          0 :             OSL_VERIFY( m_xRowSet->getPropertyValue( PROPERTY_FILTER ) >>= sFilter );
     345                 :            : 
     346                 :          0 :             m_aCommandName  = sCommand;
     347                 :          0 :             m_nCommandType  = nCommandType;
     348                 :          0 :             m_bEscapeProcessing = bEscapeProcessing;
     349                 :          0 :             m_sFilter = sFilter;
     350                 :            : 
     351                 :            :             // add the columns to the list
     352                 :          0 :             uno::Reference< sdbc::XConnection> xCon = getConnection();
     353                 :          0 :             if ( xCon.is() && !m_aCommandName.isEmpty() )
     354                 :          0 :                 m_xColumns = dbtools::getFieldsByCommandDescriptor( xCon, GetCommandType(), GetCommand(), m_xHoldAlive );
     355                 :          0 :             if ( m_xColumns.is() )
     356                 :            :             {
     357                 :          0 :                 lcl_addToList( *m_pListBox, m_xColumns );
     358                 :          0 :                 uno::Reference< container::XContainer> xContainer(m_xColumns,uno::UNO_QUERY);
     359                 :          0 :                 if ( xContainer.is() )
     360                 :          0 :                     m_pContainerListener = new ::comphelper::OContainerListenerAdapter(this,xContainer);
     361                 :            :             }
     362                 :            : 
     363                 :            :             // add the parameter columns to the list
     364                 :          0 :             uno::Reference< ::com::sun::star::sdbc::XRowSet > xRowSet(m_xRowSet,uno::UNO_QUERY);
     365                 :          0 :             Sequence< ::rtl::OUString > aParamNames( getParameterNames( xRowSet ) );
     366                 :          0 :             lcl_addToList( *m_pListBox, aParamNames );
     367                 :            : 
     368                 :            :             // set title
     369                 :          0 :             aTitle.AppendAscii(" ");
     370                 :          0 :             aTitle += m_aCommandName.getStr();
     371                 :          0 :             SetText( aTitle );
     372                 :          0 :             if ( !m_aCommandName.isEmpty() )
     373                 :            :             {
     374                 :          0 :                 for (sal_uInt16 i = 0; i < nItemCount; ++i)
     375                 :            :                 {
     376                 :          0 :                     m_aActions.EnableItem(m_aActions.GetItemId(i));
     377                 :            :                 }
     378                 :            :             }
     379                 :          0 :                 OnSelectHdl(NULL);
     380                 :          0 :         }
     381                 :            :     }
     382                 :          0 :     catch( const Exception& )
     383                 :            :     {
     384                 :            :         DBG_UNHANDLED_EXCEPTION();
     385                 :            :     }
     386                 :          0 : }
     387                 :            : 
     388                 :            : //-----------------------------------------------------------------------
     389                 :          0 : void OAddFieldWindow::Resize()
     390                 :            : {
     391                 :          0 :     FloatingWindow::Resize();
     392                 :            : 
     393                 :          0 :     const Size aWindowSize( GetOutputSizePixel() );
     394                 :            : 
     395                 :            : 
     396                 :          0 :     const Size aRelated(LogicToPixel( Size( RELATED_CONTROLS, RELATED_CONTROLS ), MAP_APPFONT ));
     397                 :          0 :     const Size aFixedTextSize(LogicToPixel( Size( FIXEDTEXT_WIDTH, FIXEDTEXT_HEIGHT ), MAP_APPFONT ));
     398                 :            : 
     399                 :            :     // ToolBar
     400                 :          0 :     Size aToolbarSize( m_aActions.GetSizePixel() );
     401                 :          0 :     Point aToolbarPos( aRelated.Width(), aRelated.Height());
     402                 :          0 :     m_aActions.SetPosPixel(Point(aToolbarPos.X(), aToolbarPos.Y()));
     403                 :            : 
     404                 :          0 :     Size aLBSize( aWindowSize );
     405                 :          0 :     aLBSize.Width()  -= ( 2 * aRelated.Width() );
     406                 :            : 
     407                 :            :     // help text
     408                 :          0 :     const Size aHelpTextSize = m_aHelpText.CalcMinimumSize(aLBSize.Width());
     409                 :            : 
     410                 :            :     // ListBox
     411                 :          0 :     Point aLBPos( aRelated.Width(), aRelated.Height() + aToolbarSize.Height() + aRelated.Height() );
     412                 :            : 
     413                 :          0 :     aLBSize.Height() -= aToolbarSize.Height();   //         Toolbar
     414                 :          0 :     aLBSize.Height() -= (6*aRelated.Height());   //         6 * gap
     415                 :          0 :     aLBSize.Height() -= aFixedTextSize.Height(); //         fixed line
     416                 :          0 :     aLBSize.Height() -= aHelpTextSize.Height();  //         help text
     417                 :          0 :     m_pListBox->SetPosSizePixel( aLBPos, aLBSize );
     418                 :            : 
     419                 :            :     // FixedLine
     420                 :          0 :     Size aFLSize( aLBSize.Width(),aFixedTextSize.Height() );
     421                 :          0 :     Point aFLPos( aRelated.Width(), aLBPos.Y() + aLBSize.Height() + aRelated.Height());
     422                 :          0 :     m_aFixedLine.SetPosSizePixel( aFLPos, aFLSize );
     423                 :            : 
     424                 :            :     // Help text
     425                 :          0 :     Point aFTPos( aRelated.Width(), aFLPos.Y() + aFLSize.Height() + aRelated.Height() );
     426                 :          0 :     m_aHelpText.SetPosSizePixel( aFTPos, aHelpTextSize );
     427                 :          0 : }
     428                 :            : // -----------------------------------------------------------------------------
     429                 :          0 : uno::Reference< sdbc::XConnection> OAddFieldWindow::getConnection() const
     430                 :            : {
     431                 :          0 :     return uno::Reference< sdbc::XConnection>(m_xRowSet->getPropertyValue( PROPERTY_ACTIVECONNECTION ),uno::UNO_QUERY);
     432                 :            : }
     433                 :            : // -----------------------------------------------------------------------------
     434                 :          0 : void OAddFieldWindow::fillDescriptor(SvLBoxEntry* _pSelected,::svx::ODataAccessDescriptor& _rDescriptor)
     435                 :            : {
     436                 :          0 :     if ( _pSelected && m_xColumns.is() )
     437                 :            :     {
     438                 :          0 :         uno::Reference<container::XChild> xChild(getConnection(),uno::UNO_QUERY);
     439                 :          0 :         if ( xChild.is( ) )
     440                 :            :         {
     441                 :          0 :             uno::Reference<sdb::XDocumentDataSource> xDocument( xChild->getParent(), uno::UNO_QUERY );
     442                 :          0 :             if ( xDocument.is() )
     443                 :            :             {
     444                 :          0 :                 uno::Reference<frame::XModel> xModel(xDocument->getDatabaseDocument(),uno::UNO_QUERY);
     445                 :          0 :                 if ( xModel.is() )
     446                 :          0 :                     _rDescriptor[ daDatabaseLocation ] <<= xModel->getURL();
     447                 :          0 :             }
     448                 :            :         }
     449                 :            : 
     450                 :          0 :         _rDescriptor[ ::svx::daCommand ]            <<= GetCommand();
     451                 :          0 :         _rDescriptor[ ::svx::daCommandType ]        <<= GetCommandType();
     452                 :          0 :         _rDescriptor[ ::svx::daEscapeProcessing ]   <<= GetEscapeProcessing();
     453                 :          0 :         _rDescriptor[ ::svx::daConnection ]         <<= getConnection();
     454                 :            : 
     455                 :          0 :         ColumnInfo* pInfo = static_cast<ColumnInfo*>(_pSelected->GetUserData());
     456                 :          0 :         _rDescriptor[ ::svx::daColumnName ]         <<= pInfo->sColumnName;
     457                 :          0 :         if ( m_xColumns->hasByName( pInfo->sColumnName ) )
     458                 :          0 :             _rDescriptor[ ::svx::daColumnObject ] <<= m_xColumns->getByName(pInfo->sColumnName);
     459                 :            :     }
     460                 :          0 : }
     461                 :            : // -----------------------------------------------------------------------------
     462                 :          0 : void OAddFieldWindow::_elementInserted( const container::ContainerEvent& _rEvent )  throw(::com::sun::star::uno::RuntimeException)
     463                 :            : {
     464                 :          0 :     if ( m_pListBox.get() )
     465                 :            :     {
     466                 :          0 :         ::rtl::OUString sName;
     467                 :          0 :         if ( (_rEvent.Accessor >>= sName) && m_xColumns->hasByName(sName) )
     468                 :            :         {
     469                 :          0 :             uno::Reference< beans::XPropertySet> xColumn(m_xColumns->getByName(sName),UNO_QUERY_THROW);
     470                 :          0 :             ::rtl::OUString sLabel;
     471                 :          0 :             if ( xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_LABEL) )
     472                 :          0 :                 xColumn->getPropertyValue(PROPERTY_LABEL) >>= sLabel;
     473                 :          0 :             if ( !sLabel.isEmpty() )
     474                 :          0 :                 m_pListBox->InsertEntry( sLabel,NULL,sal_False,LIST_APPEND,new ColumnInfo(sName,sLabel) );
     475                 :            :             else
     476                 :          0 :                 m_pListBox->InsertEntry( sName,NULL,sal_False,LIST_APPEND,new ColumnInfo(sName,sLabel) );
     477                 :          0 :         }
     478                 :            :     }
     479                 :          0 : }
     480                 :            : // -----------------------------------------------------------------------------
     481                 :          0 : void OAddFieldWindow::_elementRemoved( const container::ContainerEvent& /*_rEvent*/ ) throw(::com::sun::star::uno::RuntimeException)
     482                 :            : {
     483                 :          0 :     if ( m_pListBox.get() )
     484                 :            :     {
     485                 :          0 :         m_pListBox->Clear();
     486                 :          0 :         if ( m_xColumns.is() )
     487                 :          0 :             lcl_addToList( *m_pListBox, m_xColumns );
     488                 :            :     }
     489                 :          0 : }
     490                 :            : // -----------------------------------------------------------------------------
     491                 :          0 : void OAddFieldWindow::_elementReplaced( const container::ContainerEvent& /*_rEvent*/ ) throw(::com::sun::star::uno::RuntimeException)
     492                 :            : {
     493                 :          0 : }
     494                 :            : // -----------------------------------------------------------------------------
     495                 :          0 : IMPL_LINK( OAddFieldWindow, OnSelectHdl, void* ,/*_pAddFieldDlg*/)
     496                 :            : {
     497                 :          0 :     m_aActions.EnableItem(SID_ADD_CONTROL_PAIR, ( m_pListBox.get() && m_pListBox->GetSelectionCount() > 0 ));
     498                 :            : 
     499                 :          0 :     return 0L;
     500                 :            : }
     501                 :            : // -----------------------------------------------------------------------------
     502                 :          0 : IMPL_LINK( OAddFieldWindow, OnDoubleClickHdl, void* ,/*_pAddFieldDlg*/)
     503                 :            : {
     504                 :          0 :     if ( m_aCreateLink.IsSet() )
     505                 :          0 :         m_aCreateLink.Call(this);
     506                 :            : 
     507                 :          0 :     return 0L;
     508                 :            : }
     509                 :            : //------------------------------------------------------------------------------
     510                 :          0 : ImageList OAddFieldWindow::getImageList(sal_Int16 _eBitmapSet) const
     511                 :            : {
     512                 :          0 :     sal_Int16 nN = IMG_ADDFIELD_DLG_SC;
     513                 :          0 :     if ( _eBitmapSet == SFX_SYMBOLS_SIZE_LARGE )
     514                 :          0 :         nN = IMG_ADDFIELD_DLG_LC;
     515                 :          0 :     return ImageList(ModuleRes(nN));
     516                 :            : }
     517                 :            : //------------------------------------------------------------------
     518                 :          0 : void OAddFieldWindow::resizeControls(const Size& _rDiff)
     519                 :            : {
     520                 :            :     // we use large images so we must change them
     521                 :          0 :     if ( _rDiff.Width() || _rDiff.Height() )
     522                 :            :     {
     523                 :          0 :         Invalidate();
     524                 :            :     }
     525                 :          0 : }
     526                 :            : //------------------------------------------------------------------
     527                 :          0 : IMPL_LINK( OAddFieldWindow, OnSortAction, ToolBox*, /*NOTINTERESTEDIN*/ )
     528                 :            : {
     529                 :          0 :     const sal_uInt16 nCurItem = m_aActions.GetCurItemId();
     530                 :          0 :     if ( SID_ADD_CONTROL_PAIR == nCurItem )
     531                 :          0 :         OnDoubleClickHdl(NULL);
     532                 :            :     else
     533                 :            :     {
     534                 :          0 :         if ( SID_FM_REMOVE_FILTER_SORT == nCurItem || !m_aActions.IsItemChecked(nCurItem) )
     535                 :            :         {
     536                 :          0 :             const sal_uInt16 nItemCount = m_aActions.GetItemCount();
     537                 :          0 :             for (sal_uInt16 j = 0; j< nItemCount; ++j)
     538                 :            :             {
     539                 :          0 :                 const sal_uInt16 nItemId = m_aActions.GetItemId(j);
     540                 :          0 :                 if ( nCurItem != nItemId )
     541                 :          0 :                     m_aActions.CheckItem(nItemId,sal_False);
     542                 :            :             }
     543                 :          0 :             SvSortMode eSortMode = SortNone;
     544                 :          0 :             if ( SID_FM_REMOVE_FILTER_SORT != nCurItem )
     545                 :            :             {
     546                 :          0 :                 m_aActions.CheckItem(nCurItem,!m_aActions.IsItemChecked(nCurItem));
     547                 :          0 :                 if ( m_aActions.IsItemChecked(SID_FM_SORTUP) )
     548                 :          0 :                     eSortMode = SortAscending;
     549                 :          0 :                 else if ( m_aActions.IsItemChecked(SID_FM_SORTDOWN) )
     550                 :          0 :                     eSortMode = SortDescending;
     551                 :            :             }
     552                 :            : 
     553                 :          0 :             m_pListBox->GetModel()->SetSortMode(eSortMode);
     554                 :          0 :             if ( SID_FM_REMOVE_FILTER_SORT == nCurItem )
     555                 :          0 :                 Update();
     556                 :            : 
     557                 :          0 :             m_pListBox->GetModel()->Resort();
     558                 :            :         }
     559                 :            :     }
     560                 :          0 :     return 0L;
     561                 :            : }
     562                 :            : // -----------------------------------------------------------------------------
     563                 :            : // =============================================================================
     564                 :            : } // namespace rptui
     565                 :            : // =============================================================================
     566                 :            : 
     567                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10