1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
45 RichTextEngine
* RichTextEngine::Create()
49 SfxItemPool
* pPool
= EditEngine::CreatePool();
50 pPool
->FreezeIdRanges();
52 RichTextEngine
* pReturn
= new RichTextEngine( pPool
);
53 OutputDevice
* pOutputDevice
= pReturn
->GetRefDevice();
54 MapMode
aDeviceMapMode( pOutputDevice
->GetMapMode() );
56 pReturn
->SetStatusEventHdl( LINK( pReturn
, RichTextEngine
, EditEngineStatusChanged
) );
58 pPool
->SetDefaultMetric( (SfxMapUnit
)( aDeviceMapMode
.GetMapUnit() ) );
61 vcl::Font aFont
= Application::GetSettings().GetStyleSettings().GetAppFont();
62 aFont
.SetFamilyName( "Times New Roman" );
63 pPool
->SetPoolDefaultItem( SvxFontItem( aFont
.GetFamilyType(), aFont
.GetFamilyName(), OUString(), aFont
.GetPitch(), aFont
.GetCharSet(), EE_CHAR_FONTINFO
) );
66 MapMode
aPointMapMode( MAP_POINT
);
67 Size
a12PointSize( OutputDevice::LogicToLogic( Size( 12, 0 ), aPointMapMode
, aDeviceMapMode
) );
68 pPool
->SetPoolDefaultItem( SvxFontHeightItem( a12PointSize
.Width(), 100, EE_CHAR_FONTHEIGHT
) );
71 SvtLinguOptions aLinguOpt
;
72 pPool
->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt
.nDefaultLanguage
, EE_CHAR_LANGUAGE
) );
73 pPool
->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt
.nDefaultLanguage_CJK
, EE_CHAR_LANGUAGE_CJK
) );
74 pPool
->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt
.nDefaultLanguage_CTL
, EE_CHAR_LANGUAGE_CTL
) );
80 RichTextEngine
* RichTextEngine::Clone()
82 RichTextEngine
* pClone( nullptr );
84 SolarMutexGuard aGuard
;
85 std::unique_ptr
<EditTextObject
> pMyText(CreateTextObject());
86 OSL_ENSURE( pMyText
, "RichTextEngine::Clone: CreateTextObject returned nonsense!" );
91 pClone
->SetText( *pMyText
);
98 RichTextEngine::RichTextEngine( SfxItemPool
* _pPool
)
100 ,m_pEnginePool( _pPool
)
105 RichTextEngine::~RichTextEngine( )
110 void RichTextEngine::registerEngineStatusListener( IEngineStatusListener
* _pListener
)
112 OSL_ENSURE( _pListener
, "RichTextEngine::registerEngineStatusListener: invalid listener!" );
114 m_aStatusListeners
.push_back( _pListener
);
118 void RichTextEngine::revokeEngineStatusListener( IEngineStatusListener
* _pListener
)
120 ::std::vector
< IEngineStatusListener
* >::iterator aPos
= ::std::find_if(
121 m_aStatusListeners
.begin(),
122 m_aStatusListeners
.end(),
123 ::std::bind2nd( ::std::equal_to
< IEngineStatusListener
* >( ), _pListener
)
125 OSL_ENSURE( aPos
!= m_aStatusListeners
.end(), "RichTextEngine::revokeEngineStatusListener: listener not registered!" );
126 if ( aPos
!= m_aStatusListeners
.end() )
127 m_aStatusListeners
.erase( aPos
);
131 IMPL_LINK_TYPED( RichTextEngine
, EditEngineStatusChanged
, EditStatus
&, _rStatus
, void )
133 for ( ::std::vector
< IEngineStatusListener
* >::const_iterator aLoop
= m_aStatusListeners
.begin();
134 aLoop
!= m_aStatusListeners
.end();
137 (*aLoop
)->EditEngineStatusChanged( _rStatus
);
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */