1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_forms.hxx"
26 #include "richtextengine.hxx"
27 #include <svl/itempool.hxx>
28 #include <editeng/eeitem.hxx>
29 #include <editeng/editobj.hxx>
30 #define ITEMID_FONTHEIGHT   EE_CHAR_FONTHEIGHT
31 #include <editeng/fhgtitem.hxx>
32 #define ITEMID_FONT         EE_CHAR_FONTHEIGHT
33 #include <editeng/fontitem.hxx>
34 #define ITEMID_LANGUAGE     EE_CHAR_LANGUAGE
35 #include <editeng/langitem.hxx>
36 #include <vcl/svapp.hxx>
37 #include <tools/mapunit.hxx>
38 #include <vcl/mapmod.hxx>
39 #include <vcl/outdev.hxx>
40 #include <unotools/lingucfg.hxx>
41 #include <svl/undo.hxx>
42 #include <vos/mutex.hxx>
43 
44 #include <algorithm>
45 #include <functional>
46 
47 //........................................................................
48 namespace frm
49 {
50 //........................................................................
51 
52 	//====================================================================
53 	//= RichTextEngine
54 	//====================================================================
55 	//--------------------------------------------------------------------
Create()56     RichTextEngine* RichTextEngine::Create()
57     {
58         SfxItemPool* pPool = EditEngine::CreatePool();
59 	    pPool->FreezeIdRanges();
60 
61         RichTextEngine* pReturn = new RichTextEngine( pPool );
62         OutputDevice* pOutputDevice = pReturn->GetRefDevice();
63 	    MapMode aDeviceMapMode( pOutputDevice->GetMapMode() );
64 
65         pReturn->SetStatusEventHdl( LINK( pReturn, RichTextEngine, EditEngineStatusChanged ) );
66 
67 	    pPool->SetDefaultMetric(  (SfxMapUnit)( aDeviceMapMode.GetMapUnit() ) );
68 
69         // defaults
70         Font aFont = Application::GetSettings().GetStyleSettings().GetAppFont();
71 	    aFont.SetName( String( RTL_CONSTASCII_USTRINGPARAM( "Times New Roman" ) ) );
72 	    pPool->SetPoolDefaultItem( SvxFontItem( aFont.GetFamily(), aFont.GetName(), String(), aFont.GetPitch(), aFont.GetCharSet(), EE_CHAR_FONTINFO ) );
73 
74         // 12 pt font size
75 	    MapMode aPointMapMode( MAP_POINT );
76         Size a12PointSize( OutputDevice::LogicToLogic( Size( 12, 0 ), aPointMapMode, aDeviceMapMode ) );
77 	    pPool->SetPoolDefaultItem( SvxFontHeightItem( a12PointSize.Width(), 100, EE_CHAR_FONTHEIGHT ) );
78 
79         // font languages
80         SvtLinguOptions aLinguOpt;
81 	    pPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt.nDefaultLanguage, EE_CHAR_LANGUAGE ) );
82         pPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt.nDefaultLanguage_CJK, EE_CHAR_LANGUAGE_CJK ) );
83         pPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt.nDefaultLanguage_CTL, EE_CHAR_LANGUAGE_CTL ) );
84 
85         return pReturn;
86     }
87 
88 	//--------------------------------------------------------------------
Clone()89     RichTextEngine* RichTextEngine::Clone()
90     {
91         RichTextEngine* pClone( NULL );
92         {
93             ::vos::OGuard aGuard( Application::GetSolarMutex() );
94             EditTextObject* pMyText = CreateTextObject();
95             OSL_ENSURE( pMyText, "RichTextEngine::Clone: CreateTextObject returned nonsense!" );
96 
97             pClone = Create();
98 
99             if ( pMyText )
100                 pClone->SetText( *pMyText );
101             delete pMyText;
102         }
103 
104         return pClone;
105     }
106 
DBG_NAME(RichTextEngine)107     DBG_NAME(RichTextEngine)
108 	//--------------------------------------------------------------------
109     RichTextEngine::RichTextEngine( SfxItemPool* _pPool )
110         :EditEngine( _pPool )
111         ,m_pEnginePool( _pPool )
112     {
113         DBG_CTOR(RichTextEngine,NULL);
114     }
115 
116 	//--------------------------------------------------------------------
~RichTextEngine()117     RichTextEngine::~RichTextEngine( )
118     {
119         //delete m_pEnginePool; // must be done after the RichTextEngine was deleted
120         DBG_DTOR(RichTextEngine,NULL);
121     }
122 
123 	//--------------------------------------------------------------------
registerEngineStatusListener(IEngineStatusListener * _pListener)124     void RichTextEngine::registerEngineStatusListener( IEngineStatusListener* _pListener )
125     {
126         OSL_ENSURE( _pListener, "RichTextEngine::registerEngineStatusListener: invalid listener!" );
127         if ( _pListener )
128             m_aStatusListeners.push_back( _pListener );
129     }
130 
131 	//--------------------------------------------------------------------
revokeEngineStatusListener(IEngineStatusListener * _pListener)132     void RichTextEngine::revokeEngineStatusListener( IEngineStatusListener* _pListener )
133     {
134         ::std::vector< IEngineStatusListener* >::iterator aPos = ::std::find_if(
135             m_aStatusListeners.begin(),
136             m_aStatusListeners.end(),
137             ::std::bind2nd( ::std::equal_to< IEngineStatusListener* >( ), _pListener )
138         );
139         OSL_ENSURE( aPos != m_aStatusListeners.end(), "RichTextEngine::revokeEngineStatusListener: listener not registered!" );
140         if ( aPos != m_aStatusListeners.end() )
141             m_aStatusListeners.erase( aPos );
142     }
143 
144     //--------------------------------------------------------------------
IMPL_LINK(RichTextEngine,EditEngineStatusChanged,EditStatus *,_pStatus)145     IMPL_LINK( RichTextEngine, EditEngineStatusChanged, EditStatus*, _pStatus )
146     {
147         for ( ::std::vector< IEngineStatusListener* >::const_iterator aLoop = m_aStatusListeners.begin();
148               aLoop != m_aStatusListeners.end();
149               ++aLoop
150             )
151             (*aLoop)->EditEngineStatusChanged( *_pStatus );
152         return 0L;
153     }
154 
155 //........................................................................
156 }   // namespace frm
157 //........................................................................
158 
159