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

Generated by: LCOV version 1.10