1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: richtextengine.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_forms.hxx"
33 #include "richtextengine.hxx"
34 #include <svtools/itempool.hxx>
35 #include <svx/eeitem.hxx>
36 #include <svx/editobj.hxx>
37 #define ITEMID_FONTHEIGHT EE_CHAR_FONTHEIGHT
38 #include <svx/fhgtitem.hxx>
39 #define ITEMID_FONT EE_CHAR_FONTHEIGHT
40 #include <svx/fontitem.hxx>
41 #define ITEMID_LANGUAGE EE_CHAR_LANGUAGE
42 #include <svx/langitem.hxx>
43 #include <vcl/svapp.hxx>
44 #include <vcl/mapunit.hxx>
45 #include <vcl/mapmod.hxx>
46 #include <vcl/outdev.hxx>
47 #include <svtools/lingucfg.hxx>
48 #include <svtools/undo.hxx>
49 #include <vos/mutex.hxx>
54 //........................................................................
57 //........................................................................
59 //====================================================================
61 //====================================================================
62 //--------------------------------------------------------------------
63 RichTextEngine
* RichTextEngine::Create()
65 SfxItemPool
* pPool
= EditEngine::CreatePool();
66 pPool
->FreezeIdRanges();
68 RichTextEngine
* pReturn
= new RichTextEngine( pPool
);
69 OutputDevice
* pOutputDevice
= pReturn
->GetRefDevice();
70 MapMode
aDeviceMapMode( pOutputDevice
->GetMapMode() );
72 pReturn
->SetStatusEventHdl( LINK( pReturn
, RichTextEngine
, EditEngineStatusChanged
) );
74 pPool
->SetDefaultMetric( (SfxMapUnit
)( aDeviceMapMode
.GetMapUnit() ) );
77 Font aFont
= Application::GetSettings().GetStyleSettings().GetAppFont();
78 aFont
.SetName( String( RTL_CONSTASCII_USTRINGPARAM( "Times New Roman" ) ) );
79 pPool
->SetPoolDefaultItem( SvxFontItem( aFont
.GetFamily(), aFont
.GetName(), String(), aFont
.GetPitch(), aFont
.GetCharSet(), EE_CHAR_FONTINFO
) );
82 MapMode
aPointMapMode( MAP_POINT
);
83 Size
a12PointSize( OutputDevice::LogicToLogic( Size( 12, 0 ), aPointMapMode
, aDeviceMapMode
) );
84 pPool
->SetPoolDefaultItem( SvxFontHeightItem( a12PointSize
.Width(), 100, EE_CHAR_FONTHEIGHT
) );
87 SvtLinguOptions aLinguOpt
;
88 pPool
->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt
.nDefaultLanguage
, EE_CHAR_LANGUAGE
) );
89 pPool
->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt
.nDefaultLanguage_CJK
, EE_CHAR_LANGUAGE_CJK
) );
90 pPool
->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt
.nDefaultLanguage_CTL
, EE_CHAR_LANGUAGE_CTL
) );
95 //--------------------------------------------------------------------
96 RichTextEngine
* RichTextEngine::Clone()
98 RichTextEngine
* pClone( NULL
);
100 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
101 EditTextObject
* pMyText
= CreateTextObject();
102 OSL_ENSURE( pMyText
, "RichTextEngine::Clone: CreateTextObject returned nonsense!" );
107 pClone
->SetText( *pMyText
);
114 DBG_NAME(RichTextEngine
)
115 //--------------------------------------------------------------------
116 RichTextEngine::RichTextEngine( SfxItemPool
* _pPool
)
117 :EditEngine( _pPool
)
118 ,m_pEnginePool( _pPool
)
120 DBG_CTOR(RichTextEngine
,NULL
);
123 //--------------------------------------------------------------------
124 RichTextEngine::~RichTextEngine( )
126 //delete m_pEnginePool; // must be done after the RichTextEngine was deleted
127 DBG_DTOR(RichTextEngine
,NULL
);
130 //--------------------------------------------------------------------
131 void RichTextEngine::registerEngineStatusListener( IEngineStatusListener
* _pListener
)
133 OSL_ENSURE( _pListener
, "RichTextEngine::registerEngineStatusListener: invalid listener!" );
135 m_aStatusListeners
.push_back( _pListener
);
138 //--------------------------------------------------------------------
139 void RichTextEngine::revokeEngineStatusListener( IEngineStatusListener
* _pListener
)
141 ::std::vector
< IEngineStatusListener
* >::iterator aPos
= ::std::find_if(
142 m_aStatusListeners
.begin(),
143 m_aStatusListeners
.end(),
144 ::std::bind2nd( ::std::equal_to
< IEngineStatusListener
* >( ), _pListener
)
146 OSL_ENSURE( aPos
!= m_aStatusListeners
.end(), "RichTextEngine::revokeEngineStatusListener: listener not registered!" );
147 if ( aPos
!= m_aStatusListeners
.end() )
148 m_aStatusListeners
.erase( aPos
);
151 //--------------------------------------------------------------------
152 IMPL_LINK( RichTextEngine
, EditEngineStatusChanged
, EditStatus
*, _pStatus
)
154 for ( ::std::vector
< IEngineStatusListener
* >::const_iterator aLoop
= m_aStatusListeners
.begin();
155 aLoop
!= m_aStatusListeners
.end();
158 (*aLoop
)->EditEngineStatusChanged( *_pStatus
);
162 //........................................................................
164 //........................................................................