Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include "richtextengine.hxx"
21 : : #include <svl/itempool.hxx>
22 : : #include <editeng/eeitem.hxx>
23 : : #include <editeng/editobj.hxx>
24 : : #define ITEMID_FONTHEIGHT EE_CHAR_FONTHEIGHT
25 : : #include <editeng/fhgtitem.hxx>
26 : : #define ITEMID_FONT EE_CHAR_FONTHEIGHT
27 : : #include <editeng/fontitem.hxx>
28 : : #define ITEMID_LANGUAGE EE_CHAR_LANGUAGE
29 : : #include <editeng/langitem.hxx>
30 : : #include <vcl/svapp.hxx>
31 : : #include <tools/mapunit.hxx>
32 : : #include <vcl/mapmod.hxx>
33 : : #include <vcl/outdev.hxx>
34 : : #include <unotools/lingucfg.hxx>
35 : : #include <svl/undo.hxx>
36 : : #include <osl/mutex.hxx>
37 : :
38 : : #include <algorithm>
39 : : #include <functional>
40 : :
41 : : //........................................................................
42 : : namespace frm
43 : : {
44 : : //........................................................................
45 : :
46 : : //====================================================================
47 : : //= RichTextEngine
48 : : //====================================================================
49 : : //--------------------------------------------------------------------
50 : 204 : RichTextEngine* RichTextEngine::Create()
51 : : {
52 [ + - ]: 204 : SfxItemPool* pPool = EditEngine::CreatePool();
53 [ + - ]: 204 : pPool->FreezeIdRanges();
54 : :
55 [ + - ][ + - ]: 204 : RichTextEngine* pReturn = new RichTextEngine( pPool );
56 [ + - ]: 204 : OutputDevice* pOutputDevice = pReturn->GetRefDevice();
57 [ + - ]: 204 : MapMode aDeviceMapMode( pOutputDevice->GetMapMode() );
58 : :
59 [ + - ][ + - ]: 204 : pReturn->SetStatusEventHdl( LINK( pReturn, RichTextEngine, EditEngineStatusChanged ) );
60 : :
61 [ + - ]: 204 : pPool->SetDefaultMetric( (SfxMapUnit)( aDeviceMapMode.GetMapUnit() ) );
62 : :
63 : : // defaults
64 [ + - ][ + - ]: 204 : Font aFont = Application::GetSettings().GetStyleSettings().GetAppFont();
65 [ + - ][ + - ]: 204 : aFont.SetName( String( RTL_CONSTASCII_USTRINGPARAM( "Times New Roman" ) ) );
[ + - ][ + - ]
66 [ + - ][ + - ]: 204 : pPool->SetPoolDefaultItem( SvxFontItem( aFont.GetFamily(), aFont.GetName(), String(), aFont.GetPitch(), aFont.GetCharSet(), EE_CHAR_FONTINFO ) );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
67 : :
68 : : // 12 pt font size
69 [ + - ]: 204 : MapMode aPointMapMode( MAP_POINT );
70 [ + - ]: 204 : Size a12PointSize( OutputDevice::LogicToLogic( Size( 12, 0 ), aPointMapMode, aDeviceMapMode ) );
71 [ + - ][ + - ]: 204 : pPool->SetPoolDefaultItem( SvxFontHeightItem( a12PointSize.Width(), 100, EE_CHAR_FONTHEIGHT ) );
[ + - ]
72 : :
73 : : // font languages
74 [ + - ]: 204 : SvtLinguOptions aLinguOpt;
75 [ + - ][ + - ]: 204 : pPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt.nDefaultLanguage, EE_CHAR_LANGUAGE ) );
[ + - ]
76 [ + - ][ + - ]: 204 : pPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt.nDefaultLanguage_CJK, EE_CHAR_LANGUAGE_CJK ) );
[ + - ]
77 [ + - ][ + - ]: 204 : pPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt.nDefaultLanguage_CTL, EE_CHAR_LANGUAGE_CTL ) );
[ + - ]
78 : :
79 [ + - ][ + - ]: 204 : return pReturn;
[ + - ][ + - ]
80 : : }
81 : :
82 : : //--------------------------------------------------------------------
83 : 4 : RichTextEngine* RichTextEngine::Clone()
84 : : {
85 : 4 : RichTextEngine* pClone( NULL );
86 : : {
87 [ + - ]: 4 : SolarMutexGuard aGuard;
88 [ + - ]: 4 : EditTextObject* pMyText = CreateTextObject();
89 : : OSL_ENSURE( pMyText, "RichTextEngine::Clone: CreateTextObject returned nonsense!" );
90 : :
91 [ + - ]: 4 : pClone = Create();
92 : :
93 [ + - ]: 4 : if ( pMyText )
94 [ + - ]: 4 : pClone->SetText( *pMyText );
95 [ + - ][ + - ]: 4 : delete pMyText;
[ + - ]
96 : : }
97 : :
98 : 4 : return pClone;
99 : : }
100 : :
101 : : DBG_NAME(RichTextEngine)
102 : : //--------------------------------------------------------------------
103 : 204 : RichTextEngine::RichTextEngine( SfxItemPool* _pPool )
104 : : :EditEngine( _pPool )
105 [ + - ]: 204 : ,m_pEnginePool( _pPool )
106 : : {
107 : : DBG_CTOR(RichTextEngine,NULL);
108 : 204 : }
109 : :
110 : : //--------------------------------------------------------------------
111 : 185 : RichTextEngine::~RichTextEngine( )
112 : : {
113 : : DBG_DTOR(RichTextEngine,NULL);
114 [ - + ]: 370 : }
115 : :
116 : : //--------------------------------------------------------------------
117 : 40 : void RichTextEngine::registerEngineStatusListener( IEngineStatusListener* _pListener )
118 : : {
119 : : OSL_ENSURE( _pListener, "RichTextEngine::registerEngineStatusListener: invalid listener!" );
120 [ + - ]: 40 : if ( _pListener )
121 : 40 : m_aStatusListeners.push_back( _pListener );
122 : 40 : }
123 : :
124 : : //--------------------------------------------------------------------
125 : 40 : void RichTextEngine::revokeEngineStatusListener( IEngineStatusListener* _pListener )
126 : : {
127 : : ::std::vector< IEngineStatusListener* >::iterator aPos = ::std::find_if(
128 : : m_aStatusListeners.begin(),
129 : : m_aStatusListeners.end(),
130 : : ::std::bind2nd( ::std::equal_to< IEngineStatusListener* >( ), _pListener )
131 [ + - ][ + - ]: 40 : );
132 : : OSL_ENSURE( aPos != m_aStatusListeners.end(), "RichTextEngine::revokeEngineStatusListener: listener not registered!" );
133 [ + - ][ + - ]: 40 : if ( aPos != m_aStatusListeners.end() )
134 [ + - ]: 40 : m_aStatusListeners.erase( aPos );
135 : 40 : }
136 : :
137 : : //--------------------------------------------------------------------
138 : 39 : IMPL_LINK( RichTextEngine, EditEngineStatusChanged, EditStatus*, _pStatus )
139 : : {
140 [ + - ][ + - ]: 78 : for ( ::std::vector< IEngineStatusListener* >::const_iterator aLoop = m_aStatusListeners.begin();
[ - + ]
141 : 39 : aLoop != m_aStatusListeners.end();
142 : : ++aLoop
143 : : )
144 [ # # ]: 0 : (*aLoop)->EditEngineStatusChanged( *_pStatus );
145 : 39 : return 0L;
146 : : }
147 : :
148 : : //........................................................................
149 : : } // namespace frm
150 : : //........................................................................
151 : :
152 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|