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 <osl/diagnose.h>
43 RichTextEngine
* RichTextEngine::Create()
47 rtl::Reference
<SfxItemPool
> pPool
= EditEngine::CreatePool();
48 pPool
->FreezeIdRanges();
50 RichTextEngine
* pReturn
= new RichTextEngine( pPool
.get() );
51 OutputDevice
* pOutputDevice
= pReturn
->GetRefDevice();
52 const MapMode
& aDeviceMapMode( pOutputDevice
->GetMapMode() );
54 pReturn
->SetStatusEventHdl( LINK( pReturn
, RichTextEngine
, EditEngineStatusChanged
) );
56 pPool
->SetDefaultMetric(aDeviceMapMode
.GetMapUnit());
59 vcl::Font aFont
= Application::GetSettings().GetStyleSettings().GetAppFont();
60 aFont
.SetFamilyName( "Times New Roman" );
61 pPool
->SetPoolDefaultItem( SvxFontItem( aFont
.GetFamilyType(), aFont
.GetFamilyName(), OUString(), aFont
.GetPitch(), aFont
.GetCharSet(), EE_CHAR_FONTINFO
) );
64 MapMode
aPointMapMode( MapUnit::MapPoint
);
65 Size
a12PointSize( OutputDevice::LogicToLogic( Size( 12, 0 ), aPointMapMode
, aDeviceMapMode
) );
66 pPool
->SetPoolDefaultItem( SvxFontHeightItem( a12PointSize
.Width(), 100, EE_CHAR_FONTHEIGHT
) );
69 SvtLinguOptions aLinguOpt
;
70 pPool
->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt
.nDefaultLanguage
, EE_CHAR_LANGUAGE
) );
71 pPool
->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt
.nDefaultLanguage_CJK
, EE_CHAR_LANGUAGE_CJK
) );
72 pPool
->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt
.nDefaultLanguage_CTL
, EE_CHAR_LANGUAGE_CTL
) );
78 RichTextEngine
* RichTextEngine::Clone()
80 RichTextEngine
* pClone( nullptr );
82 SolarMutexGuard aGuard
;
83 std::unique_ptr
<EditTextObject
> pMyText(CreateTextObject());
84 OSL_ENSURE( pMyText
, "RichTextEngine::Clone: CreateTextObject returned nonsense!" );
89 pClone
->SetText( *pMyText
);
96 RichTextEngine::RichTextEngine( SfxItemPool
* _pPool
)
102 RichTextEngine::~RichTextEngine( )
107 void RichTextEngine::registerEngineStatusListener( IEngineStatusListener
* _pListener
)
109 OSL_ENSURE( _pListener
, "RichTextEngine::registerEngineStatusListener: invalid listener!" );
111 m_aStatusListeners
.push_back( _pListener
);
115 void RichTextEngine::revokeEngineStatusListener( IEngineStatusListener
const * _pListener
)
117 ::std::vector
< IEngineStatusListener
* >::iterator aPos
= ::std::find(
118 m_aStatusListeners
.begin(),
119 m_aStatusListeners
.end(),
122 OSL_ENSURE( aPos
!= m_aStatusListeners
.end(), "RichTextEngine::revokeEngineStatusListener: listener not registered!" );
123 if ( aPos
!= m_aStatusListeners
.end() )
124 m_aStatusListeners
.erase( aPos
);
128 IMPL_LINK( RichTextEngine
, EditEngineStatusChanged
, EditStatus
&, _rStatus
, void )
130 for (auto const& statusListener
: m_aStatusListeners
)
131 statusListener
->EditEngineStatusChanged( _rStatus
);
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */