LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / forms / source / richtext / richtextengine.cxx
blob14f50a6fca4dcc6c342ec1b2f4fa31e7162c41e1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
35 #include <algorithm>
36 #include <memory>
38 namespace frm
40 //= RichTextEngine
43 RichTextEngine* RichTextEngine::Create()
45 SolarMutexGuard g;
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());
58 // defaults
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 ) );
63 // 12 pt font size
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 ) );
68 // font languages
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 ) );
74 return pReturn;
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!" );
86 pClone = Create();
88 if ( pMyText )
89 pClone->SetText( *pMyText );
92 return pClone;
96 RichTextEngine::RichTextEngine( SfxItemPool* _pPool )
97 :EditEngine( _pPool )
102 RichTextEngine::~RichTextEngine( )
107 void RichTextEngine::registerEngineStatusListener( IEngineStatusListener* _pListener )
109 OSL_ENSURE( _pListener, "RichTextEngine::registerEngineStatusListener: invalid listener!" );
110 if ( _pListener )
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(),
120 _pListener
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 );
135 } // namespace frm
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */