LCOV - code coverage report
Current view: top level - toolkit/source/controls - tabpagemodel.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 15 152 9.9 %
Date: 2014-11-03 Functions: 4 27 14.8 %
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 <toolkit/controls/tabpagemodel.hxx>
      21             : 
      22             : #include <vcl/svapp.hxx>
      23             : #include <vcl/window.hxx>
      24             : #include <vcl/wall.hxx>
      25             : #include <toolkit/helper/property.hxx>
      26             : #include <toolkit/controls/stdtabcontroller.hxx>
      27             : #include <com/sun/star/awt/UnoControlDialogModelProvider.hpp>
      28             : #include <com/sun/star/awt/tab/XTabPage.hpp>
      29             : #include <com/sun/star/beans/XPropertySet.hpp>
      30             : #include <com/sun/star/uno/XComponentContext.hpp>
      31             : #include <cppuhelper/supportsservice.hxx>
      32             : #include <cppuhelper/typeprovider.hxx>
      33             : #include <tools/debug.hxx>
      34             : #include <tools/diagnose_ex.h>
      35             : #include <comphelper/sequence.hxx>
      36             : #include <vcl/outdev.hxx>
      37             : 
      38             : #include <toolkit/helper/vclunohelper.hxx>
      39             : #include <unotools/ucbstreamhelper.hxx>
      40             : #include <vcl/graph.hxx>
      41             : #include <vcl/image.hxx>
      42             : #include <toolkit/controls/geometrycontrolmodel.hxx>
      43             : #include <toolkit/controls/controlmodelcontainerbase.hxx>
      44             : #include <toolkit/controls/unocontrolcontainer.hxx>
      45             : #include <cppuhelper/basemutex.hxx>
      46             : #include <cppuhelper/implbase2.hxx>
      47             : 
      48             : #include "helper/unopropertyarrayhelper.hxx"
      49             : 
      50             : using namespace ::com::sun::star;
      51             : using namespace ::com::sun::star::uno;
      52             : using namespace ::com::sun::star::awt;
      53             : 
      54           2 : UnoControlTabPageModel::UnoControlTabPageModel( Reference< XComponentContext > const & i_factory )
      55           2 :     :ControlModelContainerBase( i_factory )
      56             : {
      57           2 :     ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
      58           2 :     ImplRegisterProperty( BASEPROPERTY_TITLE );
      59           2 :     ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
      60           2 :     ImplRegisterProperty( BASEPROPERTY_HELPURL );
      61           2 : }
      62             : 
      63           0 : OUString SAL_CALL UnoControlTabPageModel::getImplementationName() throw(css::uno::RuntimeException, std::exception)
      64             : {
      65           0 :     return OUString("stardiv.Toolkit.UnoControlTabPageModel");
      66             : }
      67             : 
      68           0 : css::uno::Sequence< OUString > SAL_CALL UnoControlTabPageModel::getSupportedServiceNames() throw(css::uno::RuntimeException, std::exception)
      69             : {
      70           0 :     css::uno::Sequence< OUString > aNames = ControlModelContainerBase::getSupportedServiceNames( );
      71           0 :     aNames.realloc( aNames.getLength() + 1 );
      72           0 :     aNames[ aNames.getLength() - 1 ] = OUString("com.sun.star.awt.tab.UnoControlTabPageModel");
      73           0 :     return aNames;
      74             : }
      75             : 
      76           0 : OUString UnoControlTabPageModel::getServiceName( ) throw(RuntimeException, std::exception)
      77             : {
      78           0 :     return OUString("com.sun.star.awt.tab.UnoControlTabPageModel");
      79             : }
      80             : 
      81           8 : Any UnoControlTabPageModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
      82             : {
      83           8 :     Any aAny;
      84             : 
      85           8 :     switch ( nPropId )
      86             :     {
      87             :         case BASEPROPERTY_DEFAULTCONTROL:
      88           2 :             aAny <<= OUString("com.sun.star.awt.tab.UnoControlTabPage");
      89           2 :             break;
      90             :         default:
      91           6 :             aAny = UnoControlModel::ImplGetDefaultValue( nPropId );
      92             :     }
      93             : 
      94           8 :     return aAny;
      95             : }
      96             : 
      97           0 : ::cppu::IPropertyArrayHelper& UnoControlTabPageModel::getInfoHelper()
      98             : {
      99             :     static UnoPropertyArrayHelper* pHelper = NULL;
     100           0 :     if ( !pHelper )
     101             :     {
     102           0 :         Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
     103           0 :         pHelper = new UnoPropertyArrayHelper( aIDs );
     104             :     }
     105           0 :     return *pHelper;
     106             : }
     107             : // beans::XMultiPropertySet
     108           0 : uno::Reference< beans::XPropertySetInfo > UnoControlTabPageModel::getPropertySetInfo(  ) throw(uno::RuntimeException, std::exception)
     109             : {
     110           0 :     static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
     111           0 :     return xInfo;
     112             : }
     113             : ////----- XInitialization -------------------------------------------------------------------
     114           0 : void SAL_CALL UnoControlTabPageModel::initialize (const Sequence<Any>& rArguments)
     115             :             throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException, std::exception)
     116             : {
     117           0 :     sal_Int16 nPageId = -1;
     118           0 :     if ( rArguments.getLength() == 1 )
     119             :     {
     120           0 :          if ( !( rArguments[ 0 ] >>= nPageId ))
     121           0 :              throw lang::IllegalArgumentException();
     122           0 :         m_nTabPageId = nPageId;
     123             :     }
     124           0 :     else if ( rArguments.getLength() == 2 )
     125             :     {
     126           0 :         if ( !( rArguments[ 0 ] >>= nPageId ))
     127           0 :              throw lang::IllegalArgumentException();
     128           0 :         m_nTabPageId = nPageId;
     129           0 :         OUString sURL;
     130           0 :         if ( !( rArguments[ 1 ] >>= sURL ))
     131           0 :             throw lang::IllegalArgumentException();
     132           0 :         Reference<container::XNameContainer > xDialogModel = awt::UnoControlDialogModelProvider::create( m_xContext, sURL );
     133           0 :         if ( xDialogModel.is() )
     134             :         {
     135           0 :             Sequence< OUString> aNames = xDialogModel->getElementNames();
     136           0 :             const OUString* pIter = aNames.getConstArray();
     137           0 :             const OUString* pEnd = pIter + aNames.getLength();
     138           0 :             for(;pIter != pEnd;++pIter)
     139             :             {
     140             :                 try
     141             :                 {
     142           0 :                     Any aElement(xDialogModel->getByName(*pIter));
     143           0 :                     xDialogModel->removeByName(*pIter);
     144           0 :                     insertByName(*pIter,aElement);
     145             :                 }
     146           0 :                 catch(const Exception& ex)
     147             :                 {
     148             :                     (void)ex;
     149             :                 }
     150             :             }
     151           0 :             Reference<XPropertySet> xDialogProp(xDialogModel,UNO_QUERY);
     152           0 :             if ( xDialogProp.is() )
     153             :             {
     154           0 :                 static const OUString s_sResourceResolver("ResourceResolver");
     155           0 :                 Reference<XPropertySet> xThis(*this,UNO_QUERY);
     156           0 :                 xThis->setPropertyValue(s_sResourceResolver,xDialogProp->getPropertyValue(s_sResourceResolver));
     157           0 :                 xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_TITLE),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_TITLE)));
     158           0 :                 xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT)));
     159           0 :                 xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL)));
     160           0 :             }
     161           0 :         }
     162             :     }
     163             :     else
     164           0 :         m_nTabPageId = -1;
     165           0 : }
     166             : 
     167             : 
     168           0 : UnoControlTabPage::UnoControlTabPage( const uno::Reference< uno::XComponentContext >& rxContext )
     169             :     :UnoControlTabPage_Base(rxContext)
     170           0 :     ,m_bWindowListener(false)
     171             : {
     172           0 :     maComponentInfos.nWidth = 280;
     173           0 :     maComponentInfos.nHeight = 400;
     174           0 : }
     175           0 : UnoControlTabPage::~UnoControlTabPage()
     176             : {
     177           0 : }
     178             : 
     179           0 : OUString UnoControlTabPage::GetComponentServiceName()
     180             : {
     181           0 :     return OUString("TabPageModel");
     182             : }
     183             : 
     184           0 : OUString SAL_CALL UnoControlTabPage::getImplementationName()
     185             :     throw (css::uno::RuntimeException, std::exception)
     186             : {
     187           0 :     return OUString("stardiv.Toolkit.UnoControlTabPage");
     188             : }
     189             : 
     190           0 : sal_Bool SAL_CALL UnoControlTabPage::supportsService(OUString const & ServiceName)
     191             :     throw (css::uno::RuntimeException, std::exception)
     192             : {
     193           0 :     return cppu::supportsService(this, ServiceName);
     194             : }
     195             : 
     196           0 : css::uno::Sequence<OUString> SAL_CALL UnoControlTabPage::getSupportedServiceNames()
     197             :     throw (css::uno::RuntimeException, std::exception)
     198             : {
     199           0 :     css::uno::Sequence< OUString > aSeq(1);
     200           0 :     aSeq[0] = OUString("com.sun.star.awt.tab.UnoControlTabPage");
     201           0 :     return aSeq;
     202             : }
     203             : 
     204           0 : void UnoControlTabPage::dispose() throw(RuntimeException, std::exception)
     205             : {
     206           0 :     SolarMutexGuard aSolarGuard;
     207             : 
     208           0 :     lang::EventObject aEvt;
     209           0 :     aEvt.Source = static_cast< ::cppu::OWeakObject* >( this );
     210           0 :     ControlContainerBase::dispose();
     211           0 : }
     212             : 
     213           0 : void SAL_CALL UnoControlTabPage::disposing( const lang::EventObject& Source )throw(RuntimeException, std::exception)
     214             : {
     215           0 :      ControlContainerBase::disposing( Source );
     216           0 : }
     217             : 
     218           0 : void UnoControlTabPage::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer >  & rParentPeer ) throw(RuntimeException, std::exception)
     219             : {
     220           0 :     SolarMutexGuard aSolarGuard;
     221           0 :     ImplUpdateResourceResolver();
     222             : 
     223           0 :     UnoControlContainer::createPeer( rxToolkit, rParentPeer );
     224             : 
     225           0 :     Reference < tab::XTabPage > xTabPage( getPeer(), UNO_QUERY );
     226           0 :     if ( xTabPage.is() )
     227             :     {
     228           0 :         if ( !m_bWindowListener )
     229             :         {
     230           0 :             Reference< XWindowListener > xWL( static_cast< cppu::OWeakObject*>( this ), UNO_QUERY );
     231           0 :             addWindowListener( xWL );
     232           0 :             m_bWindowListener = true;
     233             :         }
     234           0 :     }
     235           0 : }
     236             : 
     237           0 : static ::Size ImplMapPixelToAppFont( OutputDevice* pOutDev, const ::Size& aSize )
     238             : {
     239           0 :     ::Size aTmp = pOutDev->PixelToLogic( aSize, MAP_APPFONT );
     240           0 :     return aTmp;
     241             : }
     242             : // ::com::sun::star::awt::XWindowListener
     243           0 : void SAL_CALL UnoControlTabPage::windowResized( const ::com::sun::star::awt::WindowEvent& e )
     244             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     245             : {
     246           0 :     OutputDevice*pOutDev = Application::GetDefaultDevice();
     247             :     DBG_ASSERT( pOutDev, "Missing Default Device!" );
     248           0 :     if ( pOutDev && !mbSizeModified )
     249             :     {
     250             :         // Currentley we are simply using MAP_APPFONT
     251           0 :         ::Size aAppFontSize( e.Width, e.Height );
     252             : 
     253           0 :         Reference< XControl > xDialogControl( *this, UNO_QUERY_THROW );
     254           0 :         Reference< XDevice > xDialogDevice( xDialogControl->getPeer(), UNO_QUERY );
     255             :         OSL_ENSURE( xDialogDevice.is(), "UnoDialogControl::windowResized: no peer, but a windowResized event?" );
     256           0 :         if ( xDialogDevice.is() )
     257             :         {
     258           0 :             DeviceInfo aDeviceInfo( xDialogDevice->getInfo() );
     259           0 :             aAppFontSize.Width() -= aDeviceInfo.LeftInset + aDeviceInfo.RightInset;
     260           0 :             aAppFontSize.Height() -= aDeviceInfo.TopInset + aDeviceInfo.BottomInset;
     261             :         }
     262             : 
     263           0 :         aAppFontSize = ImplMapPixelToAppFont( pOutDev, aAppFontSize );
     264             : 
     265             :         // Remember that changes have been done by listener. No need to
     266             :         // update the position because of property change event.
     267           0 :         mbSizeModified = true;
     268           0 :         Sequence< OUString > aProps( 2 );
     269           0 :         Sequence< Any > aValues( 2 );
     270             :         // Properties in a sequence must be sorted!
     271           0 :         aProps[0] = "Height";
     272           0 :         aProps[1] = "Width";
     273           0 :         aValues[0] <<= aAppFontSize.Height();
     274           0 :         aValues[1] <<= aAppFontSize.Width();
     275             : 
     276           0 :         ImplSetPropertyValues( aProps, aValues, true );
     277           0 :         mbSizeModified = false;
     278             :     }
     279           0 : }
     280             : 
     281           0 : void SAL_CALL UnoControlTabPage::windowMoved( const ::com::sun::star::awt::WindowEvent& e )
     282             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     283             : {
     284           0 :     OutputDevice*pOutDev = Application::GetDefaultDevice();
     285             :     DBG_ASSERT( pOutDev, "Missing Default Device!" );
     286           0 :     if ( pOutDev && !mbPosModified )
     287             :     {
     288             :         // Currentley we are simply using MAP_APPFONT
     289           0 :         ::Size aTmp( e.X, e.Y );
     290           0 :         aTmp = ImplMapPixelToAppFont( pOutDev, aTmp );
     291             : 
     292             :         // Remember that changes have been done by listener. No need to
     293             :         // update the position because of property change event.
     294           0 :         mbPosModified = true;
     295           0 :         Sequence< OUString > aProps( 2 );
     296           0 :         Sequence< Any > aValues( 2 );
     297           0 :         aProps[0] = "PositionX";
     298           0 :         aProps[1] = "PositionY";
     299           0 :         aValues[0] <<= aTmp.Width();
     300           0 :         aValues[1] <<= aTmp.Height();
     301             : 
     302           0 :         ImplSetPropertyValues( aProps, aValues, true );
     303           0 :         mbPosModified = false;
     304             :     }
     305           0 : }
     306             : 
     307           0 : void SAL_CALL UnoControlTabPage::windowShown( const ::com::sun::star::lang::EventObject& e )
     308             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     309             : {
     310             :     (void)e;
     311           0 : }
     312             : 
     313           0 : void SAL_CALL UnoControlTabPage::windowHidden( const ::com::sun::star::lang::EventObject& e )
     314             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     315             : {
     316             :     (void)e;
     317           0 : }
     318             : 
     319             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     320           0 : stardiv_Toolkit_UnoControlTabPageModel_get_implementation(
     321             :     css::uno::XComponentContext *context,
     322             :     css::uno::Sequence<css::uno::Any> const &)
     323             : {
     324           0 :     return cppu::acquire(new UnoControlTabPageModel(context));
     325             : }
     326             : 
     327             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     328           0 : stardiv_Toolkit_UnoControlTabPage_get_implementation(
     329             :     css::uno::XComponentContext *context,
     330             :     css::uno::Sequence<css::uno::Any> const &)
     331             : {
     332           0 :     return cppu::acquire(new UnoControlTabPage(context));
     333        1227 : }
     334             : 
     335             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10