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 <textapi.hxx>
21 : #include <doc.hxx>
22 : #include <IDocumentDrawModelAccess.hxx>
23 : #include <docsh.hxx>
24 : #include <editeng/eeitem.hxx>
25 : #include <editeng/editeng.hxx>
26 :
27 : #include <com/sun/star/text/XTextField.hpp>
28 : #include <com/sun/star/container/XNameContainer.hpp>
29 : #include <com/sun/star/beans/PropertyAttribute.hpp>
30 :
31 : using namespace com::sun::star;
32 :
33 122 : static const SvxItemPropertySet* ImplGetSvxTextPortionPropertySet()
34 : {
35 : static const SfxItemPropertyMapEntry aSvxTextPortionPropertyMap[] =
36 : {
37 1176 : SVX_UNOEDIT_CHAR_PROPERTIES,
38 24 : SVX_UNOEDIT_FONT_PROPERTIES,
39 120 : SVX_UNOEDIT_OUTLINER_PROPERTIES,
40 336 : SVX_UNOEDIT_PARA_PROPERTIES,
41 : {OUString("TextField"), EE_FEATURE_FIELD,
42 24 : cppu::UnoType<text::XTextField>::get(), beans::PropertyAttribute::READONLY, 0 },
43 : {OUString("TextPortionType"), WID_PORTIONTYPE,
44 24 : ::cppu::UnoType<OUString>::get(), beans::PropertyAttribute::READONLY, 0 },
45 : {OUString("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS,
46 24 : cppu::UnoType<com::sun::star::container::XNameContainer>::get(), 0, 0},
47 : {OUString("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS,
48 24 : cppu::UnoType<com::sun::star::container::XNameContainer>::get(), 0, 0},
49 : { OUString(), 0, css::uno::Type(), 0, 0 }
50 1898 : };
51 122 : static SvxItemPropertySet aSvxTextPortionPropertySet( aSvxTextPortionPropertyMap, EditEngine::GetGlobalItemPool() );
52 122 : return &aSvxTextPortionPropertySet;
53 : }
54 :
55 122 : SwTextAPIObject::SwTextAPIObject( SwTextAPIEditSource* p )
56 : : SvxUnoText( p, ImplGetSvxTextPortionPropertySet(), uno::Reference < text::XText >() )
57 122 : , pSource(p)
58 : {
59 122 : }
60 :
61 366 : SwTextAPIObject::~SwTextAPIObject() throw()
62 : {
63 122 : pSource->Dispose();
64 122 : delete pSource;
65 244 : }
66 :
67 : struct SwTextAPIEditSource_Impl
68 : {
69 : // needed for "internal" refcounting
70 : SfxItemPool* mpPool;
71 : SwDoc* mpDoc;
72 : Outliner* mpOutliner;
73 : SvxOutlinerForwarder* mpTextForwarder;
74 : sal_Int32 mnRef;
75 : };
76 :
77 2198 : SwTextAPIEditSource::SwTextAPIEditSource( const SwTextAPIEditSource& rSource )
78 2198 : : SvxEditSource( *this )
79 : {
80 : // shallow copy; uses internal refcounting
81 2198 : pImpl = rSource.pImpl;
82 2198 : pImpl->mnRef++;
83 2198 : }
84 :
85 2198 : SvxEditSource* SwTextAPIEditSource::Clone() const
86 : {
87 2198 : return new SwTextAPIEditSource( *this );
88 : }
89 :
90 2232 : void SwTextAPIEditSource::UpdateData()
91 : {
92 : // data is kept in outliner all the time
93 2232 : }
94 :
95 122 : SwTextAPIEditSource::SwTextAPIEditSource(SwDoc* pDoc)
96 122 : : pImpl(new SwTextAPIEditSource_Impl)
97 : {
98 122 : pImpl->mpPool = &pDoc->GetDocShell()->GetPool();
99 122 : pImpl->mpDoc = pDoc;
100 122 : pImpl->mpOutliner = 0;
101 122 : pImpl->mpTextForwarder = 0;
102 122 : pImpl->mnRef = 1;
103 122 : }
104 :
105 6960 : SwTextAPIEditSource::~SwTextAPIEditSource()
106 : {
107 2320 : if (!--pImpl->mnRef)
108 122 : delete pImpl;
109 4640 : }
110 :
111 244 : void SwTextAPIEditSource::Dispose()
112 : {
113 244 : pImpl->mpPool=0;
114 244 : pImpl->mpDoc=0;
115 244 : DELETEZ(pImpl->mpTextForwarder);
116 244 : DELETEZ(pImpl->mpOutliner);
117 244 : }
118 :
119 24354 : SvxTextForwarder* SwTextAPIEditSource::GetTextForwarder()
120 : {
121 24354 : if( !pImpl->mpPool )
122 0 : return 0; // mpPool == 0 can be used to flag this as disposed
123 :
124 24354 : if( !pImpl->mpOutliner )
125 : {
126 : //init draw model first
127 122 : pImpl->mpDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
128 122 : pImpl->mpOutliner = new Outliner( pImpl->mpPool, OUTLINERMODE_TEXTOBJECT );
129 122 : pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner );
130 : }
131 :
132 24354 : if( !pImpl->mpTextForwarder )
133 122 : pImpl->mpTextForwarder = new SvxOutlinerForwarder( *pImpl->mpOutliner, false );
134 :
135 24354 : return pImpl->mpTextForwarder;
136 : }
137 :
138 36 : void SwTextAPIEditSource::SetText( OutlinerParaObject& rText )
139 : {
140 36 : if ( pImpl->mpPool )
141 : {
142 36 : if( !pImpl->mpOutliner )
143 : {
144 : //init draw model first
145 0 : pImpl->mpDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
146 0 : pImpl->mpOutliner = new Outliner( pImpl->mpPool, OUTLINERMODE_TEXTOBJECT );
147 0 : pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner );
148 : }
149 :
150 36 : pImpl->mpOutliner->SetText( rText );
151 : }
152 36 : }
153 :
154 0 : void SwTextAPIEditSource::SetString( const OUString& rText )
155 : {
156 0 : if ( pImpl->mpPool )
157 : {
158 0 : if( !pImpl->mpOutliner )
159 : {
160 : //init draw model first
161 0 : pImpl->mpDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
162 0 : pImpl->mpOutliner = new Outliner( pImpl->mpPool, OUTLINERMODE_TEXTOBJECT );
163 0 : pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner );
164 : }
165 : else
166 0 : pImpl->mpOutliner->Clear();
167 0 : pImpl->mpOutliner->Insert( rText );
168 : }
169 0 : }
170 :
171 100 : OutlinerParaObject* SwTextAPIEditSource::CreateText()
172 : {
173 100 : if ( pImpl->mpPool && pImpl->mpOutliner )
174 100 : return pImpl->mpOutliner->CreateParaObject();
175 : else
176 0 : return 0;
177 : }
178 :
179 100 : OUString SwTextAPIEditSource::GetText()
180 : {
181 100 : if ( pImpl->mpPool && pImpl->mpOutliner )
182 100 : return pImpl->mpOutliner->GetEditEngine().GetText();
183 : else
184 0 : return OUString();
185 270 : }
186 :
187 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|