LibreOffice Module forms (master) 1
richtextengine.cxx
Go to the documentation of this file.
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#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 <vcl/settings.hxx>
32#include <unotools/lingucfg.hxx>
33#include <osl/diagnose.h>
34
35#include <algorithm>
36#include <memory>
37
38namespace frm
39{
40 //= RichTextEngine
41
42
44 {
46
48 pPool->FreezeIdRanges();
49
50 RichTextEngine* pReturn = new RichTextEngine( pPool.get() );
51 OutputDevice* pOutputDevice = pReturn->GetRefDevice();
52 const MapMode& aDeviceMapMode( pOutputDevice->GetMapMode() );
53
54 pReturn->SetStatusEventHdl( LINK( pReturn, RichTextEngine, EditEngineStatusChanged ) );
55
56 pPool->SetDefaultMetric(aDeviceMapMode.GetMapUnit());
57
58 // defaults
60 aFont.SetFamilyName( "Times New Roman" );
61 pPool->SetPoolDefaultItem( SvxFontItem( aFont.GetFamilyType(), aFont.GetFamilyName(), OUString(), aFont.GetPitch(), aFont.GetCharSet(), EE_CHAR_FONTINFO ) );
62
63 // 12 pt font size
64 MapMode aPointMapMode( MapUnit::MapPoint );
65 Size a12PointSize( OutputDevice::LogicToLogic( Size( 12, 0 ), aPointMapMode, aDeviceMapMode ) );
66 pPool->SetPoolDefaultItem( SvxFontHeightItem( a12PointSize.Width(), 100, EE_CHAR_FONTHEIGHT ) );
67
68 // font languages
69 SvtLinguOptions aLinguOpt;
70 pPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt.nDefaultLanguage, EE_CHAR_LANGUAGE ) );
71 pPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt.nDefaultLanguage_CJK, EE_CHAR_LANGUAGE_CJK ) );
72 pPool->SetPoolDefaultItem( SvxLanguageItem( aLinguOpt.nDefaultLanguage_CTL, EE_CHAR_LANGUAGE_CTL ) );
73
74 return pReturn;
75 }
76
77
79 {
80 RichTextEngine* pClone( nullptr );
81 {
82 SolarMutexGuard aGuard;
83 std::unique_ptr<EditTextObject> pMyText(CreateTextObject());
84 OSL_ENSURE( pMyText, "RichTextEngine::Clone: CreateTextObject returned nonsense!" );
85
86 pClone = Create();
87
88 if ( pMyText )
89 pClone->SetText( *pMyText );
90 }
91
92 return pClone;
93 }
94
95
97 :EditEngine( _pPool )
98 {
99 }
100
101
103 {
104 }
105
106
108 {
109 OSL_ENSURE( _pListener, "RichTextEngine::registerEngineStatusListener: invalid listener!" );
110 if ( _pListener )
111 m_aStatusListeners.push_back( _pListener );
112 }
113
114
116 {
117 ::std::vector< IEngineStatusListener* >::iterator aPos = ::std::find(
118 m_aStatusListeners.begin(),
119 m_aStatusListeners.end(),
120 _pListener
121 );
122 OSL_ENSURE( aPos != m_aStatusListeners.end(), "RichTextEngine::revokeEngineStatusListener: listener not registered!" );
123 if ( aPos != m_aStatusListeners.end() )
124 m_aStatusListeners.erase( aPos );
125 }
126
127
128 IMPL_LINK( RichTextEngine, EditEngineStatusChanged, EditStatus&, _rStatus, void )
129 {
130 for (auto const& statusListener : m_aStatusListeners)
131 statusListener->EditEngineStatusChanged( _rStatus );
132 }
133
134
135} // namespace frm
136
137
138/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
std::unique_ptr< EditTextObject > CreateTextObject()
void SetText(const OUString &rStr)
OutputDevice * GetRefDevice() const
static rtl::Reference< SfxItemPool > CreatePool()
void SetStatusEventHdl(const Link< EditStatus &, void > &rLink)
MapUnit GetMapUnit() const
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
const MapMode & GetMapMode() const
constexpr tools::Long Width() const
const vcl::Font & GetAppFont() const
RichTextEngine(SfxItemPool *_pPool)
constructs a new RichTextEngine.
void revokeEngineStatusListener(IEngineStatusListener const *_pListener)
static RichTextEngine * Create()
void registerEngineStatusListener(IEngineStatusListener *_pListener)
::std::vector< IEngineStatusListener * > m_aStatusListeners
RichTextEngine * Clone()
virtual ~RichTextEngine() override
FontFamily GetFamilyType()
const OUString & GetFamilyName() const
FontPitch GetPitch()
void SetFamilyName(const OUString &rFamilyName)
rtl_TextEncoding GetCharSet() const
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT(EE_CHAR_START+2)
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE_CTL(EE_CHAR_START+16)
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE_CJK(EE_CHAR_START+15)
constexpr TypedWhichId< SvxLanguageItem > EE_CHAR_LANGUAGE(EE_CHAR_START+14)
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO(EE_CHAR_START+1)
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25
IMPL_LINK(OClickableImageBaseModel, OnImageImportDone, Graphic *, i_pGraphic, void)
LanguageType nDefaultLanguage
LanguageType nDefaultLanguage_CTL
LanguageType nDefaultLanguage_CJK