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

Generated by: LCOV version 1.10