LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svtools/source/uno - unogridcolumnfacade.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 77 133 57.9 %
Date: 2013-07-09 Functions: 26 39 66.7 %
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             : #include "unogridcolumnfacade.hxx"
      21             : #include "unocontroltablemodel.hxx"
      22             : 
      23             : #include "svtools/table/defaultinputhandler.hxx"
      24             : #include "svtools/table/gridtablerenderer.hxx"
      25             : #include "svtools/table/tablecontrol.hxx"
      26             : 
      27             : #include <com/sun/star/awt/grid/XGridColumn.hpp>
      28             : #include <com/sun/star/view/SelectionType.hpp>
      29             : #include <com/sun/star/awt/grid/XGridColumnListener.hpp>
      30             : 
      31             : #include <comphelper/stlunosequence.hxx>
      32             : #include <tools/debug.hxx>
      33             : #include <tools/diagnose_ex.h>
      34             : #include <vcl/svapp.hxx>
      35             : #include <osl/mutex.hxx>
      36             : 
      37             : // .....................................................................................................................
      38             : namespace svt { namespace table
      39             : {
      40             : // .....................................................................................................................
      41             : 
      42             :     using ::com::sun::star::uno::Reference;
      43             :     using ::com::sun::star::uno::RuntimeException;
      44             :     using ::com::sun::star::uno::Sequence;
      45             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      46             :     using ::com::sun::star::uno::UNO_QUERY;
      47             :     using ::com::sun::star::awt::grid::XGridColumn;
      48             :     using ::com::sun::star::uno::XInterface;
      49             :     using ::com::sun::star::uno::Exception;
      50             :     using ::com::sun::star::awt::grid::XGridColumnListener;
      51             :     using ::com::sun::star::lang::EventObject;
      52             :     using ::com::sun::star::awt::grid::GridColumnEvent;
      53             :     using ::com::sun::star::uno::Any;
      54             :     using ::com::sun::star::style::HorizontalAlignment_LEFT;
      55             :     using ::com::sun::star::style::HorizontalAlignment;
      56             : 
      57             :     //------------------------------------------------------------------------------------------------------------------
      58             :     namespace
      59             :     {
      60             :         template< class ATTRIBUTE_TYPE >
      61          16 :         void lcl_set( Reference< XGridColumn > const & i_column, void ( SAL_CALL XGridColumn::*i_setter )( ATTRIBUTE_TYPE ),
      62             :             ATTRIBUTE_TYPE i_value )
      63             :         {
      64             :             try
      65             :             {
      66          16 :                 (i_column.get()->*i_setter) ( i_value );
      67             :             }
      68           0 :             catch( const Exception& )
      69             :             {
      70             :                 DBG_UNHANDLED_EXCEPTION();
      71             :             }
      72          16 :         }
      73             : 
      74             :         template< class ATTRIBUTE_TYPE >
      75         180 :         ATTRIBUTE_TYPE lcl_get( Reference< XGridColumn > const & i_column, ATTRIBUTE_TYPE ( SAL_CALL XGridColumn::*i_getter )() )
      76             :         {
      77         180 :             ATTRIBUTE_TYPE value = ATTRIBUTE_TYPE();
      78             :             try
      79             :             {
      80         180 :                 value = (i_column.get()->*i_getter)();
      81             :             }
      82           0 :             catch( const Exception& )
      83             :             {
      84             :                 DBG_UNHANDLED_EXCEPTION();
      85             :             }
      86         180 :             return value;
      87             :         }
      88             :     }
      89             : 
      90             :     //==================================================================================================================
      91             :     //= ColumnChangeMultiplexer
      92             :     //==================================================================================================================
      93             :     typedef ::cppu::WeakImplHelper1 <   XGridColumnListener
      94             :                                     >   ColumnChangeMultiplexer_Base;
      95             :     class ColumnChangeMultiplexer   :public ColumnChangeMultiplexer_Base
      96             :                                     ,public ::boost::noncopyable
      97             :     {
      98             :     public:
      99             :         ColumnChangeMultiplexer( UnoGridColumnFacade& i_colImpl );
     100             : 
     101             :         void dispose();
     102             : 
     103             :     protected:
     104             :         ~ColumnChangeMultiplexer();
     105             : 
     106             :         // XGridColumnListener
     107             :         virtual void SAL_CALL columnChanged( const GridColumnEvent& i_event ) throw (RuntimeException);
     108             : 
     109             :         // XEventListener
     110             :         virtual void SAL_CALL disposing( const EventObject& i_event ) throw (RuntimeException);
     111             : 
     112             :     private:
     113             :         UnoGridColumnFacade* m_pColumnImplementation;
     114             :     };
     115             : 
     116             :     //------------------------------------------------------------------------------------------------------------------
     117           3 :     ColumnChangeMultiplexer::ColumnChangeMultiplexer( UnoGridColumnFacade& i_colImpl )
     118           3 :         :m_pColumnImplementation( &i_colImpl )
     119             :     {
     120           3 :     }
     121             : 
     122             :     //------------------------------------------------------------------------------------------------------------------
     123           6 :     ColumnChangeMultiplexer::~ColumnChangeMultiplexer()
     124             :     {
     125           6 :     }
     126             : 
     127             :     //------------------------------------------------------------------------------------------------------------------
     128           1 :     void ColumnChangeMultiplexer::dispose()
     129             :     {
     130             :         DBG_TESTSOLARMUTEX();
     131           1 :         m_pColumnImplementation = NULL;
     132           1 :     }
     133             : 
     134             :     //------------------------------------------------------------------------------------------------------------------
     135           8 :     void SAL_CALL ColumnChangeMultiplexer::columnChanged( const GridColumnEvent& i_event ) throw (RuntimeException)
     136             :     {
     137           8 :         if ( i_event.AttributeName == "DataColumnIndex" )
     138             :         {
     139           0 :             SolarMutexGuard aGuard;
     140           0 :             if ( m_pColumnImplementation != NULL )
     141           0 :                 m_pColumnImplementation->dataColumnIndexChanged();
     142           8 :             return;
     143             :         }
     144             : 
     145           8 :         ColumnAttributeGroup nChangedAttributes( COL_ATTRS_NONE );
     146             : 
     147           8 :         if ( i_event.AttributeName == "HorizontalAlign" )
     148           0 :             nChangedAttributes |= COL_ATTRS_APPEARANCE;
     149             : 
     150          16 :         if  (   i_event.AttributeName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("ColumnWidth"))
     151           0 :             ||  i_event.AttributeName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MaxWidth"))
     152           0 :             ||  i_event.AttributeName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("MinWidth"))
     153           0 :             ||  i_event.AttributeName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("PreferredWidth"))
     154           0 :             ||  i_event.AttributeName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Resizeable"))
     155           8 :             ||  i_event.AttributeName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Flexibility"))
     156             :             )
     157           8 :             nChangedAttributes |= COL_ATTRS_WIDTH;
     158             : 
     159             :         OSL_ENSURE( nChangedAttributes != COL_ATTRS_NONE,
     160             :             "ColumnChangeMultiplexer::columnChanged: unknown column attributed changed!" );
     161             : 
     162           8 :         SolarMutexGuard aGuard;
     163           8 :         if ( m_pColumnImplementation != NULL )
     164           8 :             m_pColumnImplementation->columnChanged( nChangedAttributes );
     165             :     }
     166             : 
     167             :     //------------------------------------------------------------------------------------------------------------------
     168           2 :     void SAL_CALL ColumnChangeMultiplexer::disposing( const EventObject& i_event ) throw (RuntimeException)
     169             :     {
     170             :         OSL_UNUSED( i_event );
     171           2 :     }
     172             : 
     173             :     //==================================================================================================================
     174             :     //= UnoGridColumnFacade
     175             :     //==================================================================================================================
     176             :     //------------------------------------------------------------------------------------------------------------------
     177           3 :     UnoGridColumnFacade::UnoGridColumnFacade( UnoControlTableModel const & i_owner, Reference< XGridColumn > const & i_gridColumn )
     178             :         :m_pOwner( &i_owner )
     179             :         ,m_nDataColumnIndex( -1 )
     180             :         ,m_xGridColumn( i_gridColumn, UNO_QUERY_THROW )
     181           3 :         ,m_pChangeMultiplexer( new ColumnChangeMultiplexer( *this ) )
     182             :     {
     183           3 :         m_xGridColumn->addGridColumnListener( m_pChangeMultiplexer.get() );
     184           3 :         impl_updateDataColumnIndex_nothrow();
     185           3 :     }
     186             : 
     187             :     //------------------------------------------------------------------------------------------------------------------
     188           6 :     UnoGridColumnFacade::~UnoGridColumnFacade()
     189             :     {
     190           6 :     }
     191             : 
     192             :     //------------------------------------------------------------------------------------------------------------------
     193           1 :     void UnoGridColumnFacade::dispose()
     194             :     {
     195             :         DBG_TESTSOLARMUTEX();
     196           2 :         ENSURE_OR_RETURN_VOID( m_pOwner != NULL, "UnoGridColumnFacade::dispose: already disposed!" );
     197             : 
     198           1 :         m_xGridColumn->removeGridColumnListener( m_pChangeMultiplexer.get() );
     199           1 :         m_pChangeMultiplexer->dispose();
     200           1 :         m_pChangeMultiplexer.clear();
     201           1 :         m_xGridColumn.clear();
     202           1 :         m_pOwner = NULL;
     203             :     }
     204             : 
     205             :     //------------------------------------------------------------------------------------------------------------------
     206           3 :     void UnoGridColumnFacade::impl_updateDataColumnIndex_nothrow()
     207             :     {
     208           3 :         m_nDataColumnIndex = -1;
     209           6 :         ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
     210             :         try
     211             :         {
     212           3 :             m_nDataColumnIndex = m_xGridColumn->getDataColumnIndex();
     213             :         }
     214           0 :         catch( const Exception& )
     215             :         {
     216             :             DBG_UNHANDLED_EXCEPTION();
     217             :         }
     218             :     }
     219             : 
     220             :     //------------------------------------------------------------------------------------------------------------------
     221           0 :     void UnoGridColumnFacade::dataColumnIndexChanged()
     222             :     {
     223             :         DBG_TESTSOLARMUTEX();
     224           0 :         impl_updateDataColumnIndex_nothrow();
     225           0 :         if ( m_pOwner != NULL )
     226           0 :             m_pOwner->notifyAllDataChanged();
     227           0 :     }
     228             : 
     229             :     //------------------------------------------------------------------------------------------------------------------
     230           8 :     void UnoGridColumnFacade::columnChanged( ColumnAttributeGroup const i_attributeGroup )
     231             :     {
     232             :         DBG_TESTSOLARMUTEX();
     233           8 :         if ( m_pOwner != NULL )
     234           8 :             m_pOwner->notifyColumnChange( m_pOwner->getColumnPos( *this ), i_attributeGroup );
     235           8 :     }
     236             : 
     237             :     //------------------------------------------------------------------------------------------------------------------
     238           0 :     Any UnoGridColumnFacade::getID() const
     239             :     {
     240           0 :         Any aID;
     241           0 :         ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", aID );
     242             :         try
     243             :         {
     244           0 :             aID = m_xGridColumn->getIdentifier();
     245             :         }
     246           0 :         catch( const Exception& )
     247             :         {
     248             :             DBG_UNHANDLED_EXCEPTION();
     249             :         }
     250           0 :         return aID;
     251             :     }
     252             : 
     253             :     //------------------------------------------------------------------------------------------------------------------
     254           0 :     void UnoGridColumnFacade::setID( const Any& i_ID )
     255             :     {
     256           0 :         ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
     257             :         try
     258             :         {
     259           0 :             m_xGridColumn->setIdentifier( i_ID );
     260             :         }
     261           0 :         catch( const Exception& )
     262             :         {
     263             :             DBG_UNHANDLED_EXCEPTION();
     264             :         }
     265             :     }
     266             : 
     267             :     //------------------------------------------------------------------------------------------------------------------
     268           2 :     String UnoGridColumnFacade::getName() const
     269             :     {
     270           2 :         OUString sName;
     271           2 :         ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", sName );
     272             :         try
     273             :         {
     274           2 :             sName = m_xGridColumn->getTitle();
     275             :         }
     276           0 :         catch( const Exception& )
     277             :         {
     278             :             DBG_UNHANDLED_EXCEPTION();
     279             :         }
     280           2 :         return sName;
     281             :     }
     282             : 
     283             :     //------------------------------------------------------------------------------------------------------------------
     284           0 :     void UnoGridColumnFacade::setName( const String& _rName )
     285             :     {
     286           0 :         ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
     287             :         try
     288             :         {
     289           0 :             m_xGridColumn->setTitle( _rName );
     290             :         }
     291           0 :         catch( const Exception& )
     292             :         {
     293             :             DBG_UNHANDLED_EXCEPTION();
     294             :         }
     295             :     }
     296             : 
     297             :     //------------------------------------------------------------------------------------------------------------------
     298           0 :     String UnoGridColumnFacade::getHelpText() const
     299             :     {
     300           0 :         OUString sHelpText;
     301           0 :         ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", sHelpText );
     302             :         try
     303             :         {
     304           0 :             sHelpText = m_xGridColumn->getHelpText();
     305             :         }
     306           0 :         catch( const Exception& )
     307             :         {
     308             :             DBG_UNHANDLED_EXCEPTION();
     309             :         }
     310           0 :         return sHelpText;
     311             :     }
     312             : 
     313             :     //------------------------------------------------------------------------------------------------------------------
     314           0 :     void UnoGridColumnFacade::setHelpText( const String& i_helpText )
     315             :     {
     316           0 :         ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
     317             :         try
     318             :         {
     319           0 :             m_xGridColumn->setHelpText( i_helpText );
     320             :         }
     321           0 :         catch( const Exception& )
     322             :         {
     323             :             DBG_UNHANDLED_EXCEPTION();
     324             :         }
     325             :     }
     326             : 
     327             :     //------------------------------------------------------------------------------------------------------------------
     328          32 :     bool UnoGridColumnFacade::isResizable() const
     329             :     {
     330          32 :         ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", false );
     331          32 :         return lcl_get( m_xGridColumn, &XGridColumn::getResizeable );
     332             :     }
     333             : 
     334             :     //------------------------------------------------------------------------------------------------------------------
     335           0 :     void UnoGridColumnFacade::setResizable( bool i_resizable )
     336             :     {
     337           0 :         ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
     338           0 :         lcl_set( m_xGridColumn, &XGridColumn::setResizeable, sal_Bool( i_resizable ) );
     339             :     }
     340             : 
     341             :     //------------------------------------------------------------------------------------------------------------------
     342          32 :     sal_Int32 UnoGridColumnFacade::getFlexibility() const
     343             :     {
     344          32 :         ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 1 );
     345          32 :         return lcl_get( m_xGridColumn, &XGridColumn::getFlexibility );
     346             :     }
     347             : 
     348             :     //------------------------------------------------------------------------------------------------------------------
     349           0 :     void UnoGridColumnFacade::setFlexibility( sal_Int32 const i_flexibility )
     350             :     {
     351           0 :         ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
     352           0 :         lcl_set( m_xGridColumn, &XGridColumn::setFlexibility, i_flexibility );
     353             :     }
     354             : 
     355             :     //------------------------------------------------------------------------------------------------------------------
     356          48 :     TableMetrics UnoGridColumnFacade::getWidth() const
     357             :     {
     358          48 :         ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 );
     359          48 :         return lcl_get( m_xGridColumn, &XGridColumn::getColumnWidth );
     360             :     }
     361             : 
     362             :     //------------------------------------------------------------------------------------------------------------------
     363          16 :     void UnoGridColumnFacade::setWidth( TableMetrics _nWidth )
     364             :     {
     365          32 :         ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
     366          16 :         lcl_set( m_xGridColumn, &XGridColumn::setColumnWidth, _nWidth );
     367             :     }
     368             : 
     369             :     //------------------------------------------------------------------------------------------------------------------
     370          32 :     TableMetrics UnoGridColumnFacade::getMinWidth() const
     371             :     {
     372          32 :         ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 );
     373          32 :         return lcl_get( m_xGridColumn, &XGridColumn::getMinWidth );
     374             :     }
     375             : 
     376             :     //------------------------------------------------------------------------------------------------------------------
     377           0 :     void UnoGridColumnFacade::setMinWidth( TableMetrics _nMinWidth )
     378             :     {
     379           0 :         ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
     380           0 :         lcl_set( m_xGridColumn, &XGridColumn::setMinWidth, _nMinWidth );
     381             :     }
     382             : 
     383             :     //------------------------------------------------------------------------------------------------------------------
     384          32 :     TableMetrics UnoGridColumnFacade::getMaxWidth() const
     385             :     {
     386          32 :         ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", 0 );
     387          32 :         return lcl_get( m_xGridColumn, &XGridColumn::getMaxWidth );
     388             :     }
     389             : 
     390             :     //------------------------------------------------------------------------------------------------------------------
     391           0 :     void UnoGridColumnFacade::setMaxWidth( TableMetrics _nMaxWidth )
     392             :     {
     393           0 :         ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
     394           0 :         lcl_set( m_xGridColumn, &XGridColumn::setMinWidth, _nMaxWidth );
     395             :     }
     396             : 
     397             :     //------------------------------------------------------------------------------------------------------------------
     398           4 :     ::com::sun::star::style::HorizontalAlignment UnoGridColumnFacade::getHorizontalAlign()
     399             :     {
     400           4 :         ENSURE_OR_RETURN( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!", HorizontalAlignment_LEFT );
     401           4 :         return lcl_get( m_xGridColumn, &XGridColumn::getHorizontalAlign );
     402             :     }
     403             : 
     404             :     //------------------------------------------------------------------------------------------------------------------
     405           0 :     void UnoGridColumnFacade::setHorizontalAlign( com::sun::star::style::HorizontalAlignment _align )
     406             :     {
     407           0 :         ENSURE_OR_RETURN_VOID( m_xGridColumn.is(), "UnoGridColumnFacade: already disposed!" );
     408           0 :         lcl_set( m_xGridColumn, &XGridColumn::setHorizontalAlign, _align );
     409             :     }
     410             : 
     411             : // .....................................................................................................................
     412         465 : } } // svt::table
     413             : // .....................................................................................................................
     414             : 
     415             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10