bump product version to 4.1.6.2
[LibreOffice.git] / forms / source / richtext / richtextengine.cxx
blob6b045babb2477b602a90a32fb4c89e7dd75bba19
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 <unotools/lingucfg.hxx>
32 #include <svl/undo.hxx>
33 #include <osl/mutex.hxx>
35 #include <algorithm>
36 #include <functional>
38 //........................................................................
39 namespace frm
41 //........................................................................
43 //====================================================================
44 //= RichTextEngine
45 //====================================================================
46 //--------------------------------------------------------------------
47 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() ) );
60 // defaults
61 Font aFont = Application::GetSettings().GetStyleSettings().GetAppFont();
62 aFont.SetName( String( "Times New Roman" ) );
63 pPool->SetPoolDefaultItem( SvxFontItem( aFont.GetFamily(), aFont.GetName(), String(), aFont.GetPitch(), aFont.GetCharSet(), EE_CHAR_FONTINFO ) );
65 // 12 pt font size
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 ) );
70 // font languages
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 ) );
76 return pReturn;
79 //--------------------------------------------------------------------
80 RichTextEngine* RichTextEngine::Clone()
82 RichTextEngine* pClone( NULL );
84 SolarMutexGuard aGuard;
85 EditTextObject* pMyText = CreateTextObject();
86 OSL_ENSURE( pMyText, "RichTextEngine::Clone: CreateTextObject returned nonsense!" );
88 pClone = Create();
90 if ( pMyText )
91 pClone->SetText( *pMyText );
92 delete pMyText;
95 return pClone;
98 DBG_NAME(RichTextEngine)
99 //--------------------------------------------------------------------
100 RichTextEngine::RichTextEngine( SfxItemPool* _pPool )
101 :EditEngine( _pPool )
102 ,m_pEnginePool( _pPool )
104 DBG_CTOR(RichTextEngine,NULL);
107 //--------------------------------------------------------------------
108 RichTextEngine::~RichTextEngine( )
110 DBG_DTOR(RichTextEngine,NULL);
113 //--------------------------------------------------------------------
114 void RichTextEngine::registerEngineStatusListener( IEngineStatusListener* _pListener )
116 OSL_ENSURE( _pListener, "RichTextEngine::registerEngineStatusListener: invalid listener!" );
117 if ( _pListener )
118 m_aStatusListeners.push_back( _pListener );
121 //--------------------------------------------------------------------
122 void RichTextEngine::revokeEngineStatusListener( IEngineStatusListener* _pListener )
124 ::std::vector< IEngineStatusListener* >::iterator aPos = ::std::find_if(
125 m_aStatusListeners.begin(),
126 m_aStatusListeners.end(),
127 ::std::bind2nd( ::std::equal_to< IEngineStatusListener* >( ), _pListener )
129 OSL_ENSURE( aPos != m_aStatusListeners.end(), "RichTextEngine::revokeEngineStatusListener: listener not registered!" );
130 if ( aPos != m_aStatusListeners.end() )
131 m_aStatusListeners.erase( aPos );
134 //--------------------------------------------------------------------
135 IMPL_LINK( RichTextEngine, EditEngineStatusChanged, EditStatus*, _pStatus )
137 for ( ::std::vector< IEngineStatusListener* >::const_iterator aLoop = m_aStatusListeners.begin();
138 aLoop != m_aStatusListeners.end();
139 ++aLoop
141 (*aLoop)->EditEngineStatusChanged( *_pStatus );
142 return 0L;
145 //........................................................................
146 } // namespace frm
147 //........................................................................
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */