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 RichTextEngine
* pReturn
= new RichTextEngine( pPool
.get() );
49 OutputDevice
* pOutputDevice
= pReturn
->GetRefDevice();
50 const MapMode
& aDeviceMapMode( pOutputDevice
->GetMapMode() );
52 pReturn
->SetStatusEventHdl( LINK( pReturn
, RichTextEngine
, EditEngineStatusChanged
) );
54 pPool
->SetDefaultMetric(aDeviceMapMode
.GetMapUnit());
57 vcl::Font aFont
= Application::GetSettings().GetStyleSettings().GetAppFont();
58 aFont
.SetFamilyName( u
"Times New Roman"_ustr
);
59 pPool
->SetUserDefaultItem( SvxFontItem( aFont
.GetFamilyType(), aFont
.GetFamilyName(), OUString(), aFont
.GetPitch(), aFont
.GetCharSet(), EE_CHAR_FONTINFO
) );
62 MapMode
aPointMapMode( MapUnit::MapPoint
);
63 Size
a12PointSize( OutputDevice::LogicToLogic( Size( 12, 0 ), aPointMapMode
, aDeviceMapMode
) );
64 pPool
->SetUserDefaultItem( SvxFontHeightItem( a12PointSize
.Width(), 100, EE_CHAR_FONTHEIGHT
) );
67 SvtLinguOptions aLinguOpt
;
68 pPool
->SetUserDefaultItem( SvxLanguageItem( aLinguOpt
.nDefaultLanguage
, EE_CHAR_LANGUAGE
) );
69 pPool
->SetUserDefaultItem( SvxLanguageItem( aLinguOpt
.nDefaultLanguage_CJK
, EE_CHAR_LANGUAGE_CJK
) );
70 pPool
->SetUserDefaultItem( SvxLanguageItem( aLinguOpt
.nDefaultLanguage_CTL
, EE_CHAR_LANGUAGE_CTL
) );
76 RichTextEngine
* RichTextEngine::Clone()
78 RichTextEngine
* pClone( nullptr );
80 SolarMutexGuard aGuard
;
81 std::unique_ptr
<EditTextObject
> pMyText(CreateTextObject());
82 OSL_ENSURE( pMyText
, "RichTextEngine::Clone: CreateTextObject returned nonsense!" );
87 pClone
->SetText( *pMyText
);
94 RichTextEngine::RichTextEngine( SfxItemPool
* _pPool
)
100 RichTextEngine::~RichTextEngine( )
105 void RichTextEngine::registerEngineStatusListener( IEngineStatusListener
* _pListener
)
107 OSL_ENSURE( _pListener
, "RichTextEngine::registerEngineStatusListener: invalid listener!" );
109 m_aStatusListeners
.push_back( _pListener
);
113 void RichTextEngine::revokeEngineStatusListener( IEngineStatusListener
const * _pListener
)
115 ::std::vector
< IEngineStatusListener
* >::iterator aPos
= ::std::find(
116 m_aStatusListeners
.begin(),
117 m_aStatusListeners
.end(),
120 OSL_ENSURE( aPos
!= m_aStatusListeners
.end(), "RichTextEngine::revokeEngineStatusListener: listener not registered!" );
121 if ( aPos
!= m_aStatusListeners
.end() )
122 m_aStatusListeners
.erase( aPos
);
126 IMPL_LINK( RichTextEngine
, EditEngineStatusChanged
, EditStatus
&, _rStatus
, void )
128 for (auto const& statusListener
: m_aStatusListeners
)
129 statusListener
->EditEngineStatusChanged( _rStatus
);
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */