1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_forms.hxx"
30 #include "richtextengine.hxx"
31 #include <svl/itempool.hxx>
32 #include <editeng/eeitem.hxx>
33 #include <editeng/editobj.hxx>
34 #define ITEMID_FONTHEIGHT   EE_CHAR_FONTHEIGHT
35 #include <editeng/fhgtitem.hxx>
36 #define ITEMID_FONT         EE_CHAR_FONTHEIGHT
37 #include <editeng/fontitem.hxx>
38 #define ITEMID_LANGUAGE     EE_CHAR_LANGUAGE
39 #include <editeng/langitem.hxx>
40 #include <vcl/svapp.hxx>
41 #include <tools/mapunit.hxx>
42 #include <vcl/mapmod.hxx>
43 #include <vcl/outdev.hxx>
44 #include <unotools/lingucfg.hxx>
45 #include <svl/undo.hxx>
46 #include <vos/mutex.hxx>
47 
48 #include <algorithm>
49 #include <functional>
50 
51 //........................................................................
52 namespace frm
53 {
54 //........................................................................
55 
56 	//====================================================================
57 	//= RichTextEngine
58 	//====================================================================
59 	//--------------------------------------------------------------------
60     RichTextEngine* RichTextEngine::Create()
61     {
62         SfxItemPool* pPool = EditEngine::CreatePool();
63 	    pPool->FreezeIdRanges();
64 
65         RichTextEngine* pReturn = new RichTextEngine( pPool );
66         OutputDevice* pOutputDevice = pReturn->GetRefDevice();
67 	    MapMode aDeviceMapMode( pOutputDevice->GetMapMode() );
68 
69         pReturn->SetStatusEventHdl( LINK( pReturn, RichTextEngine, EditEngineStatusChanged ) );
70 
71 	    pPool->SetDefaultMetric(  (SfxMapUnit)( aDeviceMapMode.GetMapUnit() ) );
72 
73         // defaults
74         Font aFont = Application::GetSettings().GetStyleSettings().GetAppFont();
75 	    aFont.SetName( String( RTL_CONSTASCII_USTRINGPARAM( "Times New Roman" ) ) );
76 	    pPool->SetPoolDefaultItem( SvxFontItem( aFont.GetFamily(), aFont.GetName(), String(), aFont.GetPitch(), aFont.GetCharSet(), EE_CHAR_FONTINFO ) );
77 
78         // 12 pt font size
79 	    MapMode aPointMapMode( MAP_POINT );
80         Size a12PointSize( OutputDevice::LogicToLogic( Size( 12, 0 ), aPointMapMode, aDeviceMapMode ) );
81 	    pPool->SetPoolDefaultItem( SvxFontHeightItem( a12PointSize.Width(), 100, EE_CHAR_FONTHEIGHT ) );
82 
83         // font languages
84         SvtLinguOptions aLinguOpt;
85 	    pPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt.nDefaultLanguage, EE_CHAR_LANGUAGE ) );
86         pPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt.nDefaultLanguage_CJK, EE_CHAR_LANGUAGE_CJK ) );
87         pPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt.nDefaultLanguage_CTL, EE_CHAR_LANGUAGE_CTL ) );
88 
89         return pReturn;
90     }
91 
92 	//--------------------------------------------------------------------
93     RichTextEngine* RichTextEngine::Clone()
94     {
95         RichTextEngine* pClone( NULL );
96         {
97             ::vos::OGuard aGuard( Application::GetSolarMutex() );
98             EditTextObject* pMyText = CreateTextObject();
99             OSL_ENSURE( pMyText, "RichTextEngine::Clone: CreateTextObject returned nonsense!" );
100 
101             pClone = Create();
102 
103             if ( pMyText )
104                 pClone->SetText( *pMyText );
105             delete pMyText;
106         }
107 
108         return pClone;
109     }
110 
111     DBG_NAME(RichTextEngine)
112 	//--------------------------------------------------------------------
113     RichTextEngine::RichTextEngine( SfxItemPool* _pPool )
114         :EditEngine( _pPool )
115         ,m_pEnginePool( _pPool )
116     {
117         DBG_CTOR(RichTextEngine,NULL);
118     }
119 
120 	//--------------------------------------------------------------------
121     RichTextEngine::~RichTextEngine( )
122     {
123         //delete m_pEnginePool; // must be done after the RichTextEngine was deleted
124         DBG_DTOR(RichTextEngine,NULL);
125     }
126 
127 	//--------------------------------------------------------------------
128     void RichTextEngine::registerEngineStatusListener( IEngineStatusListener* _pListener )
129     {
130         OSL_ENSURE( _pListener, "RichTextEngine::registerEngineStatusListener: invalid listener!" );
131         if ( _pListener )
132             m_aStatusListeners.push_back( _pListener );
133     }
134 
135 	//--------------------------------------------------------------------
136     void RichTextEngine::revokeEngineStatusListener( IEngineStatusListener* _pListener )
137     {
138         ::std::vector< IEngineStatusListener* >::iterator aPos = ::std::find_if(
139             m_aStatusListeners.begin(),
140             m_aStatusListeners.end(),
141             ::std::bind2nd( ::std::equal_to< IEngineStatusListener* >( ), _pListener )
142         );
143         OSL_ENSURE( aPos != m_aStatusListeners.end(), "RichTextEngine::revokeEngineStatusListener: listener not registered!" );
144         if ( aPos != m_aStatusListeners.end() )
145             m_aStatusListeners.erase( aPos );
146     }
147 
148     //--------------------------------------------------------------------
149     IMPL_LINK( RichTextEngine, EditEngineStatusChanged, EditStatus*, _pStatus )
150     {
151         for ( ::std::vector< IEngineStatusListener* >::const_iterator aLoop = m_aStatusListeners.begin();
152               aLoop != m_aStatusListeners.end();
153               ++aLoop
154             )
155             (*aLoop)->EditEngineStatusChanged( *_pStatus );
156         return 0L;
157     }
158 
159 //........................................................................
160 }   // namespace frm
161 //........................................................................
162 
163