cid#1640468 Dereference after null check
[LibreOffice.git] / forms / source / richtext / richtextengine.cxx
blob6be1d246e19022df78a95220a427827f73b8048d
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 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());
56 // defaults
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 ) );
61 // 12 pt font size
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 ) );
66 // font languages
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 ) );
72 return pReturn;
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!" );
84 pClone = Create();
86 if ( pMyText )
87 pClone->SetText( *pMyText );
90 return pClone;
94 RichTextEngine::RichTextEngine( SfxItemPool* _pPool )
95 :EditEngine( _pPool )
100 RichTextEngine::~RichTextEngine( )
105 void RichTextEngine::registerEngineStatusListener( IEngineStatusListener* _pListener )
107 OSL_ENSURE( _pListener, "RichTextEngine::registerEngineStatusListener: invalid listener!" );
108 if ( _pListener )
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(),
118 _pListener
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 );
133 } // namespace frm
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */