LCOV - code coverage report
Current view: top level - extensions/source/propctrlr - pushbuttonnavigation.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 94 0.0 %
Date: 2012-08-25 Functions: 0 12 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                 :            : 
      29                 :            : #include "pushbuttonnavigation.hxx"
      30                 :            : #include <com/sun/star/form/FormButtonType.hpp>
      31                 :            : #include <com/sun/star/beans/XPropertyState.hpp>
      32                 :            : #include "formstrings.hxx"
      33                 :            : #include <comphelper/extract.hxx>
      34                 :            : #include <comphelper/property.hxx>
      35                 :            : #include <osl/diagnose.h>
      36                 :            : #include <tools/diagnose_ex.h>
      37                 :            : 
      38                 :            : //............................................................................
      39                 :            : namespace pcr
      40                 :            : {
      41                 :            : //............................................................................
      42                 :            : 
      43                 :            :     using namespace ::com::sun::star::uno;
      44                 :            :     using namespace ::com::sun::star::beans;
      45                 :            :     using namespace ::com::sun::star::form;
      46                 :            : 
      47                 :            :     //------------------------------------------------------------------------
      48                 :            :     namespace
      49                 :            :     {
      50                 :            :         static const sal_Int32 s_nFirstVirtualButtonType = 1 + (sal_Int32)FormButtonType_URL;
      51                 :            : 
      52                 :            :         static const sal_Char* pNavigationURLs[] =
      53                 :            :         {
      54                 :            :             ".uno:FormController/moveToFirst",
      55                 :            :             ".uno:FormController/moveToPrev",
      56                 :            :             ".uno:FormController/moveToNext",
      57                 :            :             ".uno:FormController/moveToLast",
      58                 :            :             ".uno:FormController/saveRecord",
      59                 :            :             ".uno:FormController/undoRecord",
      60                 :            :             ".uno:FormController/moveToNew",
      61                 :            :             ".uno:FormController/deleteRecord",
      62                 :            :             ".uno:FormController/refreshForm",
      63                 :            :             NULL
      64                 :            :         };
      65                 :            : 
      66                 :          0 :         static sal_Int32 lcl_getNavigationURLIndex( const ::rtl::OUString& _rNavURL )
      67                 :            :         {
      68                 :          0 :             const sal_Char** pLookup = pNavigationURLs;
      69                 :          0 :             while ( *pLookup )
      70                 :            :             {
      71                 :          0 :                 if ( _rNavURL.equalsAscii( *pLookup ) )
      72                 :          0 :                     return pLookup - pNavigationURLs;
      73                 :          0 :                 ++pLookup;
      74                 :            :             }
      75                 :          0 :             return -1;
      76                 :            :         }
      77                 :            : 
      78                 :          0 :         static const sal_Char* lcl_getNavigationURL( sal_Int32 _nButtonTypeIndex )
      79                 :            :         {
      80                 :          0 :             const sal_Char** pLookup = pNavigationURLs;
      81                 :          0 :             while ( _nButtonTypeIndex-- && *pLookup++ )
      82                 :            :                 ;
      83                 :            :             OSL_ENSURE( *pLookup, "lcl_getNavigationURL: invalid index!" );
      84                 :          0 :             return *pLookup;
      85                 :            :         }
      86                 :            :     }
      87                 :            : 
      88                 :            :     //========================================================================
      89                 :            :     //= PushButtonNavigation
      90                 :            :     //========================================================================
      91                 :            :     //------------------------------------------------------------------------
      92                 :          0 :     PushButtonNavigation::PushButtonNavigation( const Reference< XPropertySet >& _rxControlModel )
      93                 :            :         :m_xControlModel( _rxControlModel )
      94                 :          0 :         ,m_bIsPushButton( sal_False )
      95                 :            :     {
      96                 :            :         OSL_ENSURE( m_xControlModel.is(), "PushButtonNavigation::PushButtonNavigation: invalid control model!" );
      97                 :            : 
      98                 :            :         try
      99                 :            :         {
     100                 :          0 :             m_bIsPushButton = ::comphelper::hasProperty( PROPERTY_BUTTONTYPE, m_xControlModel );
     101                 :            :         }
     102                 :          0 :         catch( const Exception& )
     103                 :            :         {
     104                 :            :             OSL_FAIL( "PushButtonNavigation::PushButtonNavigation: caught an exception!" );
     105                 :            :         }
     106                 :          0 :     }
     107                 :            : 
     108                 :            :     //------------------------------------------------------------------------
     109                 :          0 :     sal_Int32 PushButtonNavigation::implGetCurrentButtonType() const SAL_THROW((Exception))
     110                 :            :     {
     111                 :          0 :         sal_Int32 nButtonType = FormButtonType_PUSH;
     112                 :          0 :         if ( !m_xControlModel.is() )
     113                 :          0 :             return nButtonType;
     114                 :          0 :         OSL_VERIFY( ::cppu::enum2int( nButtonType, m_xControlModel->getPropertyValue( PROPERTY_BUTTONTYPE ) ) );
     115                 :            : 
     116                 :          0 :         if ( nButtonType == FormButtonType_URL )
     117                 :            :         {
     118                 :            :             // there's a chance that this is a "virtual" button type
     119                 :            :             // (which are realized by special URLs)
     120                 :          0 :             ::rtl::OUString sTargetURL;
     121                 :          0 :             m_xControlModel->getPropertyValue( PROPERTY_TARGET_URL ) >>= sTargetURL;
     122                 :            : 
     123                 :          0 :             sal_Int32 nNavigationURLIndex = lcl_getNavigationURLIndex( sTargetURL );
     124                 :          0 :             if ( nNavigationURLIndex >= 0)
     125                 :            :                 // it actually *is* a virtual button type
     126                 :          0 :                 nButtonType = s_nFirstVirtualButtonType + nNavigationURLIndex;
     127                 :            :         }
     128                 :          0 :         return nButtonType;
     129                 :            :     }
     130                 :            : 
     131                 :            :     //------------------------------------------------------------------------
     132                 :          0 :     Any PushButtonNavigation::getCurrentButtonType() const SAL_THROW(())
     133                 :            :     {
     134                 :            :         OSL_ENSURE( m_bIsPushButton, "PushButtonNavigation::getCurrentButtonType: not expected to be called for forms!" );
     135                 :          0 :         Any aReturn;
     136                 :            : 
     137                 :            :         try
     138                 :            :         {
     139                 :          0 :             aReturn <<= implGetCurrentButtonType();
     140                 :            :         }
     141                 :          0 :         catch( const Exception& )
     142                 :            :         {
     143                 :            :             OSL_FAIL( "PushButtonNavigation::getCurrentButtonType: caught an exception!" );
     144                 :            :         }
     145                 :          0 :         return aReturn;
     146                 :            :     }
     147                 :            : 
     148                 :            :     //------------------------------------------------------------------------
     149                 :          0 :     void PushButtonNavigation::setCurrentButtonType( const Any& _rValue ) const SAL_THROW(())
     150                 :            :     {
     151                 :            :         OSL_ENSURE( m_bIsPushButton, "PushButtonNavigation::setCurrentButtonType: not expected to be called for forms!" );
     152                 :          0 :         if ( !m_xControlModel.is() )
     153                 :          0 :             return;
     154                 :            : 
     155                 :            :         try
     156                 :            :         {
     157                 :          0 :             sal_Int32 nButtonType = FormButtonType_PUSH;
     158                 :          0 :             OSL_VERIFY( ::cppu::enum2int( nButtonType, _rValue ) );
     159                 :          0 :             ::rtl::OUString sTargetURL;
     160                 :            : 
     161                 :          0 :             bool bIsVirtualButtonType = nButtonType >= s_nFirstVirtualButtonType;
     162                 :          0 :             if ( bIsVirtualButtonType )
     163                 :            :             {
     164                 :          0 :                 const sal_Char* pURL = lcl_getNavigationURL( nButtonType - s_nFirstVirtualButtonType );
     165                 :          0 :                 sTargetURL = ::rtl::OUString::createFromAscii( pURL );
     166                 :            : 
     167                 :          0 :                 nButtonType = FormButtonType_URL;
     168                 :            :             }
     169                 :            : 
     170                 :          0 :             m_xControlModel->setPropertyValue( PROPERTY_BUTTONTYPE, makeAny( static_cast< FormButtonType >( nButtonType ) ) );
     171                 :          0 :             m_xControlModel->setPropertyValue( PROPERTY_TARGET_URL, makeAny( sTargetURL ) );
     172                 :            :         }
     173                 :          0 :         catch( const Exception& )
     174                 :            :         {
     175                 :            :             OSL_FAIL( "PushButtonNavigation::setCurrentButtonType: caught an exception!" );
     176                 :            :         }
     177                 :            :     }
     178                 :            : 
     179                 :            :     //------------------------------------------------------------------------
     180                 :          0 :     PropertyState PushButtonNavigation::getCurrentButtonTypeState( ) const SAL_THROW(())
     181                 :            :     {
     182                 :            :         OSL_ENSURE( m_bIsPushButton, "PushButtonNavigation::getCurrentButtonTypeState: not expected to be called for forms!" );
     183                 :          0 :         PropertyState eState = PropertyState_DIRECT_VALUE;
     184                 :            : 
     185                 :            :         try
     186                 :            :         {
     187                 :          0 :             Reference< XPropertyState > xStateAccess( m_xControlModel, UNO_QUERY );
     188                 :          0 :             if ( xStateAccess.is() )
     189                 :            :             {
     190                 :            :                 // let's see what the model says about the ButtonType property
     191                 :          0 :                 eState = xStateAccess->getPropertyState( PROPERTY_BUTTONTYPE );
     192                 :          0 :                 if ( eState == PropertyState_DIRECT_VALUE )
     193                 :            :                 {
     194                 :          0 :                     sal_Int32 nRealButtonType = FormButtonType_PUSH;
     195                 :          0 :                     OSL_VERIFY( ::cppu::enum2int( nRealButtonType, m_xControlModel->getPropertyValue( PROPERTY_BUTTONTYPE ) ) );
     196                 :            :                     // perhaps it's one of the virtual button types?
     197                 :          0 :                     if ( FormButtonType_URL == nRealButtonType )
     198                 :            :                     {
     199                 :            :                         // yes, it is -> rely on the state of the URL property
     200                 :          0 :                         eState = xStateAccess->getPropertyState( PROPERTY_TARGET_URL );
     201                 :            :                     }
     202                 :            :                 }
     203                 :          0 :             }
     204                 :            :         }
     205                 :          0 :         catch( const Exception& )
     206                 :            :         {
     207                 :            :             OSL_FAIL( "PushButtonNavigation::getCurrentButtonTypeState: caught an exception!" );
     208                 :            :         }
     209                 :            : 
     210                 :          0 :         return eState;
     211                 :            :     }
     212                 :            : 
     213                 :            :     //------------------------------------------------------------------------
     214                 :          0 :     Any PushButtonNavigation::getCurrentTargetURL() const SAL_THROW(())
     215                 :            :     {
     216                 :          0 :         Any aReturn;
     217                 :          0 :         if ( !m_xControlModel.is() )
     218                 :          0 :             return aReturn;
     219                 :            : 
     220                 :            :         try
     221                 :            :         {
     222                 :          0 :             aReturn = m_xControlModel->getPropertyValue( PROPERTY_TARGET_URL );
     223                 :          0 :             if ( m_bIsPushButton )
     224                 :            :             {
     225                 :          0 :                 sal_Int32 nCurrentButtonType = implGetCurrentButtonType();
     226                 :          0 :                 bool bIsVirtualButtonType = nCurrentButtonType >= s_nFirstVirtualButtonType;
     227                 :          0 :                 if ( bIsVirtualButtonType )
     228                 :            :                 {
     229                 :            :                     // pretend (to the user) that there's no URL set - since
     230                 :            :                     // virtual button types imply a special (technical) URL which
     231                 :            :                     // the user should not see
     232                 :          0 :                     aReturn <<= ::rtl::OUString();
     233                 :            :                 }
     234                 :            :             }
     235                 :            :         }
     236                 :          0 :         catch( const Exception& )
     237                 :            :         {
     238                 :            :             OSL_FAIL( "PushButtonNavigation::getCurrentTargetURL: caught an exception!" );
     239                 :            :         }
     240                 :          0 :         return aReturn;
     241                 :            :     }
     242                 :            : 
     243                 :            :     //------------------------------------------------------------------------
     244                 :          0 :     void PushButtonNavigation::setCurrentTargetURL( const Any& _rValue ) const SAL_THROW(())
     245                 :            :     {
     246                 :          0 :         if ( !m_xControlModel.is() )
     247                 :          0 :             return;
     248                 :            : 
     249                 :            :         try
     250                 :            :         {
     251                 :          0 :             m_xControlModel->setPropertyValue( PROPERTY_TARGET_URL, _rValue );
     252                 :            :         }
     253                 :          0 :         catch( const Exception& )
     254                 :            :         {
     255                 :            :             OSL_FAIL( "PushButtonNavigation::setCurrentTargetURL: caught an exception!" );
     256                 :            :         }
     257                 :            :     }
     258                 :            : 
     259                 :            :     //------------------------------------------------------------------------
     260                 :          0 :     PropertyState PushButtonNavigation::getCurrentTargetURLState( ) const SAL_THROW(())
     261                 :            :     {
     262                 :          0 :         PropertyState eState = PropertyState_DIRECT_VALUE;
     263                 :            : 
     264                 :            :         try
     265                 :            :         {
     266                 :          0 :             Reference< XPropertyState > xStateAccess( m_xControlModel, UNO_QUERY );
     267                 :          0 :             if ( xStateAccess.is() )
     268                 :            :             {
     269                 :          0 :                 eState = xStateAccess->getPropertyState( PROPERTY_TARGET_URL );
     270                 :          0 :             }
     271                 :            :         }
     272                 :          0 :         catch( const Exception& )
     273                 :            :         {
     274                 :            :             OSL_FAIL( "PushButtonNavigation::setCurrentTargetURL: caught an exception!" );
     275                 :            :         }
     276                 :            : 
     277                 :          0 :         return eState;
     278                 :            :     }
     279                 :            : 
     280                 :            :     //------------------------------------------------------------------------
     281                 :          0 :     bool PushButtonNavigation::currentButtonTypeIsOpenURL() const
     282                 :            :     {
     283                 :          0 :         sal_Int32 nButtonType( FormButtonType_PUSH );
     284                 :            :         try
     285                 :            :         {
     286                 :          0 :             nButtonType = implGetCurrentButtonType();
     287                 :            :         }
     288                 :          0 :         catch( const Exception& )
     289                 :            :         {
     290                 :            :             DBG_UNHANDLED_EXCEPTION();
     291                 :            :         }
     292                 :          0 :         return nButtonType == FormButtonType_URL;
     293                 :            :     }
     294                 :            : 
     295                 :            :     //------------------------------------------------------------------------
     296                 :          0 :     bool PushButtonNavigation::hasNonEmptyCurrentTargetURL() const
     297                 :            :     {
     298                 :          0 :         ::rtl::OUString sTargetURL;
     299                 :          0 :         OSL_VERIFY( getCurrentTargetURL() >>= sTargetURL );
     300                 :          0 :         return !sTargetURL.isEmpty();
     301                 :            :     }
     302                 :            : 
     303                 :            : //............................................................................
     304                 :            : }   // namespace pcr
     305                 :            : //............................................................................
     306                 :            : 
     307                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10