LCOV - code coverage report
Current view: top level - svx/source/form - fmpage.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 36 94 38.3 %
Date: 2015-06-13 12:38:46 Functions: 13 19 68.4 %
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 <sal/macros.h>
      21             : 
      22             : #include <svx/fmpage.hxx>
      23             : #include <com/sun/star/beans/XPropertySet.hpp>
      24             : #include <com/sun/star/container/XNameContainer.hpp>
      25             : 
      26             : 
      27             : #include <svx/fmmodel.hxx>
      28             : 
      29             : #include "fmobj.hxx"
      30             : 
      31             : #include <svx/fmresids.hrc>
      32             : #include <svx/dialmgr.hxx>
      33             : 
      34             : #include "fmpgeimp.hxx"
      35             : 
      36             : #include <sfx2/objsh.hxx>
      37             : #include <svx/svditer.hxx>
      38             : #include <svx/svdview.hxx>
      39             : #include <tools/urlobj.hxx>
      40             : #include <vcl/help.hxx>
      41             : 
      42             : 
      43             : #include <svx/fmglob.hxx>
      44             : #include "fmprop.hrc"
      45             : #include "fmundo.hxx"
      46             : #include "svx/fmtools.hxx"
      47             : using namespace ::svxform;
      48             : #include <comphelper/property.hxx>
      49             : 
      50             : using com::sun::star::uno::Reference;
      51             : using com::sun::star::uno::UNO_QUERY;
      52             : using com::sun::star::container::XChild;
      53             : using com::sun::star::container::XNameContainer;
      54             : 
      55      278801 : TYPEINIT1(FmFormPage, SdrPage);
      56             : 
      57             : 
      58        6280 : FmFormPage::FmFormPage(FmFormModel& rModel, bool bMasterPage)
      59             :            :SdrPage(rModel, bMasterPage)
      60        6280 :            ,m_pImpl( new FmFormPageImpl( *this ) )
      61             : {
      62        6280 : }
      63             : 
      64             : 
      65           1 : FmFormPage::FmFormPage(const FmFormPage& rPage)
      66             :            :SdrPage(rPage)
      67           1 :            ,m_pImpl(new FmFormPageImpl( *this ) )
      68             : {
      69           1 : }
      70             : 
      71           1 : void FmFormPage::lateInit(const FmFormPage& rPage, FmFormModel* const pNewModel)
      72             : {
      73           1 :     SdrPage::lateInit( rPage, pNewModel );
      74             : 
      75           1 :     m_pImpl->initFrom( rPage.GetImpl() );
      76           1 :     m_sPageName = rPage.m_sPageName;
      77           1 : }
      78             : 
      79             : 
      80       12444 : FmFormPage::~FmFormPage()
      81             : {
      82        6222 :     delete m_pImpl;
      83        6222 : }
      84             : 
      85             : 
      86        6282 : void FmFormPage::SetModel(SdrModel* pNewModel)
      87             : {
      88             :     /* #35055# */
      89             :     // we want to call the super's "SetModel" method even if the model is the
      90             :     // same, in case code somewhere in the system depends on it.  But our code
      91             :     // doesn't, so get the old model to do a check.
      92        6282 :     SdrModel *pOldModel = GetModel();
      93             : 
      94        6282 :     SdrPage::SetModel( pNewModel );
      95             : 
      96             :     /* #35055# */
      97        6282 :     if ( ( pOldModel != pNewModel ) && m_pImpl )
      98             :     {
      99             :         try
     100             :         {
     101           0 :             Reference< css::form::XForms > xForms( m_pImpl->getForms( false ) );
     102           0 :             if ( xForms.is() )
     103             :             {
     104             :                 // we want to keep the current collection, just reset the model
     105             :                 // with which it's associated.
     106           0 :                 FmFormModel* pDrawModel = static_cast<FmFormModel*>( GetModel() );
     107           0 :                 SfxObjectShell* pObjShell = pDrawModel->GetObjectShell();
     108           0 :                 if ( pObjShell )
     109           0 :                     xForms->setParent( pObjShell->GetModel() );
     110           0 :             }
     111             :         }
     112           0 :         catch( ::com::sun::star::uno::Exception const& )
     113             :         {
     114             :             OSL_FAIL( "UNO Exception caught resetting model for m_pImpl (FmFormPageImpl) in FmFormPage::SetModel" );
     115             :         }
     116             :     }
     117        6282 : }
     118             : 
     119             : 
     120           0 : SdrPage* FmFormPage::Clone() const
     121             : {
     122           0 :     return Clone(0);
     123             : }
     124             : 
     125           0 : SdrPage* FmFormPage::Clone(SdrModel* const pNewModel) const
     126             : {
     127           0 :     FmFormPage* const pNewPage = new FmFormPage(*this);
     128           0 :     FmFormModel* pFormModel = 0;
     129           0 :     if (pNewModel)
     130             :     {
     131           0 :         pFormModel = dynamic_cast<FmFormModel*>(pNewModel);
     132             :         assert(pFormModel);
     133             :     }
     134           0 :     pNewPage->lateInit(*this, pFormModel);
     135           0 :     return pNewPage;
     136             : }
     137             : 
     138             : 
     139       15207 : void FmFormPage::InsertObject(SdrObject* pObj, size_t nPos,
     140             :                               const SdrInsertReason* pReason)
     141             : {
     142       15207 :     SdrPage::InsertObject( pObj, nPos, pReason );
     143       15207 :     if (GetModel() && (!pReason || pReason->GetReason() != SDRREASON_STREAMING))
     144       15207 :         static_cast<FmFormModel*>(GetModel())->GetUndoEnv().Inserted(pObj);
     145       15207 : }
     146             : 
     147             : 
     148       23996 : const Reference< css::form::XForms > & FmFormPage::GetForms( bool _bForceCreate ) const
     149             : {
     150       23996 :     const SdrPage& rMasterPage( *this );
     151       23996 :     const FmFormPage* pFormPage = dynamic_cast< const FmFormPage* >( &rMasterPage );
     152             :     OSL_ENSURE( pFormPage, "FmFormPage::GetForms: referenced page is no FmFormPage - is this allowed?!" );
     153       23996 :     if ( !pFormPage )
     154           0 :         pFormPage = this;
     155             : 
     156       23996 :     return pFormPage->m_pImpl->getForms( _bForceCreate );
     157             : }
     158             : 
     159             : 
     160           0 : bool FmFormPage::RequestHelp( vcl::Window* pWindow, SdrView* pView,
     161             :                               const HelpEvent& rEvt )
     162             : {
     163           0 :     if( pView->IsAction() )
     164           0 :         return false;
     165             : 
     166           0 :     Point aPos = rEvt.GetMousePosPixel();
     167           0 :     aPos = pWindow->ScreenToOutputPixel( aPos );
     168           0 :     aPos = pWindow->PixelToLogic( aPos );
     169             : 
     170           0 :     SdrObject* pObj = NULL;
     171           0 :     SdrPageView* pPV = NULL;
     172           0 :     if ( !pView->PickObj( aPos, 0, pObj, pPV, SdrSearchOptions::DEEP ) )
     173           0 :         return false;
     174             : 
     175           0 :     FmFormObj* pFormObject = FmFormObj::GetFormObject( pObj );
     176           0 :     if ( !pFormObject )
     177           0 :         return false;
     178             : 
     179           0 :     OUString aHelpText;
     180           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >  xSet( pFormObject->GetUnoControlModel(), ::com::sun::star::uno::UNO_QUERY );
     181           0 :     if (xSet.is())
     182             :     {
     183           0 :         if (::comphelper::hasProperty(FM_PROP_HELPTEXT, xSet))
     184           0 :             aHelpText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_HELPTEXT)).getStr();
     185             : 
     186           0 :         if (aHelpText.isEmpty() && ::comphelper::hasProperty(FM_PROP_TARGET_URL, xSet))
     187             :         {
     188           0 :             OUString aText = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_TARGET_URL));
     189           0 :             INetURLObject aUrl(aText);
     190             : 
     191             :             // testen, ob es ein Protokoll-Typ ist, den ich anzeigen will
     192           0 :             INetProtocol aProtocol = aUrl.GetProtocol();
     193             :             static const INetProtocol s_aQuickHelpSupported[] =
     194             :                 {   INetProtocol::Ftp, INetProtocol::Http, INetProtocol::File, INetProtocol::Mailto,
     195             :                     INetProtocol::Https, INetProtocol::Javascript,
     196             :                     INetProtocol::Ldap
     197             :                 };
     198           0 :             for (sal_uInt16 i=0; i<sizeof(s_aQuickHelpSupported)/sizeof(s_aQuickHelpSupported[0]); ++i)
     199           0 :                 if (s_aQuickHelpSupported[i] == aProtocol)
     200             :                 {
     201           0 :                     aHelpText = INetURLObject::decode(aUrl.GetURLNoPass(), INetURLObject::DECODE_UNAMBIGUOUS);
     202           0 :                     break;
     203           0 :                 }
     204             :         }
     205             :     }
     206           0 :     if ( !aHelpText.isEmpty() )
     207             :     {
     208             :         // Hilfe anzeigen
     209           0 :         Rectangle aItemRect = pObj->GetCurrentBoundRect();
     210           0 :         aItemRect = pWindow->LogicToPixel( aItemRect );
     211           0 :         Point aPt = pWindow->OutputToScreenPixel( aItemRect.TopLeft() );
     212           0 :         aItemRect.Left()   = aPt.X();
     213           0 :         aItemRect.Top()    = aPt.Y();
     214           0 :         aPt = pWindow->OutputToScreenPixel( aItemRect.BottomRight() );
     215           0 :         aItemRect.Right()  = aPt.X();
     216           0 :         aItemRect.Bottom() = aPt.Y();
     217           0 :         if( rEvt.GetMode() == HelpEventMode::BALLOON )
     218           0 :             Help::ShowBalloon( pWindow, aItemRect.Center(), aItemRect, aHelpText);
     219             :         else
     220           0 :             Help::ShowQuickHelp( pWindow, aItemRect, aHelpText );
     221             :     }
     222           0 :     return true;
     223             : }
     224             : 
     225             : 
     226        8220 : SdrObject* FmFormPage::RemoveObject(size_t nObjNum)
     227             : {
     228        8220 :     SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
     229        8220 :     if (pObj && GetModel())
     230        8220 :         static_cast<FmFormModel*>(GetModel())->GetUndoEnv().Removed(pObj);
     231        8220 :     return pObj;
     232         435 : }
     233             : 
     234             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11