LCOV - code coverage report
Current view: top level - forms/source/richtext - richtextengine.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 46 47 97.9 %
Date: 2015-06-13 12:38:46 Functions: 9 9 100.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 "richtextengine.hxx"
      21             : #include <svl/itempool.hxx>
      22             : #include <editeng/eeitem.hxx>
      23             : #include <editeng/editobj.hxx>
      24             : #include <editeng/fhgtitem.hxx>
      25             : #include <editeng/fontitem.hxx>
      26             : #include <editeng/langitem.hxx>
      27             : #include <vcl/svapp.hxx>
      28             : #include <tools/mapunit.hxx>
      29             : #include <vcl/mapmod.hxx>
      30             : #include <vcl/outdev.hxx>
      31             : #include <vcl/settings.hxx>
      32             : #include <unotools/lingucfg.hxx>
      33             : #include <svl/undo.hxx>
      34             : #include <osl/mutex.hxx>
      35             : 
      36             : #include <algorithm>
      37             : #include <functional>
      38             : #include <boost/scoped_ptr.hpp>
      39             : 
      40             : namespace frm
      41             : {
      42             : 
      43             : 
      44             : 
      45             :     //= RichTextEngine
      46             : 
      47             : 
      48         109 :     RichTextEngine* RichTextEngine::Create()
      49             :     {
      50         109 :         SolarMutexGuard g;
      51             : 
      52         109 :         SfxItemPool* pPool = EditEngine::CreatePool();
      53         109 :         pPool->FreezeIdRanges();
      54             : 
      55         109 :         RichTextEngine* pReturn = new RichTextEngine( pPool );
      56         109 :         OutputDevice* pOutputDevice = pReturn->GetRefDevice();
      57         218 :         MapMode aDeviceMapMode( pOutputDevice->GetMapMode() );
      58             : 
      59         109 :         pReturn->SetStatusEventHdl( LINK( pReturn, RichTextEngine, EditEngineStatusChanged ) );
      60             : 
      61         109 :         pPool->SetDefaultMetric(  (SfxMapUnit)( aDeviceMapMode.GetMapUnit() ) );
      62             : 
      63             :         // defaults
      64         218 :         vcl::Font aFont = Application::GetSettings().GetStyleSettings().GetAppFont();
      65         109 :         aFont.SetName( "Times New Roman" );
      66         109 :         pPool->SetPoolDefaultItem( SvxFontItem( aFont.GetFamily(), aFont.GetName(), OUString(), aFont.GetPitch(), aFont.GetCharSet(), EE_CHAR_FONTINFO ) );
      67             : 
      68             :         // 12 pt font size
      69         218 :         MapMode aPointMapMode( MAP_POINT );
      70         109 :         Size a12PointSize( OutputDevice::LogicToLogic( Size( 12, 0 ), aPointMapMode, aDeviceMapMode ) );
      71         109 :         pPool->SetPoolDefaultItem( SvxFontHeightItem( a12PointSize.Width(), 100, EE_CHAR_FONTHEIGHT ) );
      72             : 
      73             :         // font languages
      74         218 :         SvtLinguOptions aLinguOpt;
      75         109 :         pPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt.nDefaultLanguage, EE_CHAR_LANGUAGE ) );
      76         109 :         pPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt.nDefaultLanguage_CJK, EE_CHAR_LANGUAGE_CJK ) );
      77         109 :         pPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt.nDefaultLanguage_CTL, EE_CHAR_LANGUAGE_CTL ) );
      78             : 
      79         218 :         return pReturn;
      80             :     }
      81             : 
      82             : 
      83           2 :     RichTextEngine* RichTextEngine::Clone()
      84             :     {
      85           2 :         RichTextEngine* pClone( NULL );
      86             :         {
      87           2 :             SolarMutexGuard aGuard;
      88           4 :             boost::scoped_ptr<EditTextObject> pMyText(CreateTextObject());
      89             :             OSL_ENSURE( pMyText, "RichTextEngine::Clone: CreateTextObject returned nonsense!" );
      90             : 
      91           2 :             pClone = Create();
      92             : 
      93           2 :             if ( pMyText )
      94           4 :                 pClone->SetText( *pMyText );
      95             :         }
      96             : 
      97           2 :         return pClone;
      98             :     }
      99             : 
     100             : 
     101         109 :     RichTextEngine::RichTextEngine( SfxItemPool* _pPool )
     102             :         :EditEngine( _pPool )
     103         109 :         ,m_pEnginePool( _pPool )
     104             :     {
     105         109 :     }
     106             : 
     107             : 
     108         202 :     RichTextEngine::~RichTextEngine( )
     109             :     {
     110         202 :     }
     111             : 
     112             : 
     113          20 :     void RichTextEngine::registerEngineStatusListener( IEngineStatusListener* _pListener )
     114             :     {
     115             :         OSL_ENSURE( _pListener, "RichTextEngine::registerEngineStatusListener: invalid listener!" );
     116          20 :         if ( _pListener )
     117          20 :             m_aStatusListeners.push_back( _pListener );
     118          20 :     }
     119             : 
     120             : 
     121          20 :     void RichTextEngine::revokeEngineStatusListener( IEngineStatusListener* _pListener )
     122             :     {
     123             :         ::std::vector< IEngineStatusListener* >::iterator aPos = ::std::find_if(
     124             :             m_aStatusListeners.begin(),
     125             :             m_aStatusListeners.end(),
     126             :             ::std::bind2nd( ::std::equal_to< IEngineStatusListener* >( ), _pListener )
     127          20 :         );
     128             :         OSL_ENSURE( aPos != m_aStatusListeners.end(), "RichTextEngine::revokeEngineStatusListener: listener not registered!" );
     129          20 :         if ( aPos != m_aStatusListeners.end() )
     130          20 :             m_aStatusListeners.erase( aPos );
     131          20 :     }
     132             : 
     133             : 
     134          36 :     IMPL_LINK( RichTextEngine, EditEngineStatusChanged, EditStatus*, _pStatus )
     135             :     {
     136          54 :         for ( ::std::vector< IEngineStatusListener* >::const_iterator aLoop = m_aStatusListeners.begin();
     137          36 :               aLoop != m_aStatusListeners.end();
     138             :               ++aLoop
     139             :             )
     140           0 :             (*aLoop)->EditEngineStatusChanged( *_pStatus );
     141          18 :         return 0L;
     142             :     }
     143             : 
     144             : 
     145             : }   // namespace frm
     146             : 
     147             : 
     148             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11