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 91 : static const SvxItemPropertySet* ImplGetSvxTextPortionPropertySet()
34 : {
35 : static const SfxItemPropertyMapEntry aSvxTextPortionPropertyMap[] =
36 : {
37 750 : SVX_UNOEDIT_CHAR_PROPERTIES,
38 15 : SVX_UNOEDIT_FONT_PROPERTIES,
39 75 : SVX_UNOEDIT_OUTLINER_PROPERTIES,
40 210 : SVX_UNOEDIT_PARA_PROPERTIES,
41 : {OUString("TextField"), EE_FEATURE_FIELD,
42 15 : cppu::UnoType<text::XTextField>::get(), beans::PropertyAttribute::READONLY, 0 },
43 : {OUString("TextPortionType"), WID_PORTIONTYPE,
44 15 : ::cppu::UnoType<OUString>::get(), beans::PropertyAttribute::READONLY, 0 },
45 : {OUString("TextUserDefinedAttributes"), EE_CHAR_XMLATTRIBS,
46 15 : cppu::UnoType<com::sun::star::container::XNameContainer>::get(), 0, 0},
47 : {OUString("ParaUserDefinedAttributes"), EE_PARA_XMLATTRIBS,
48 15 : cppu::UnoType<com::sun::star::container::XNameContainer>::get(), 0, 0},
49 : { OUString(), 0, css::uno::Type(), 0, 0 }
50 1216 : };
51 91 : static SvxItemPropertySet aSvxTextPortionPropertySet( aSvxTextPortionPropertyMap, EditEngine::GetGlobalItemPool() );
52 91 : return &aSvxTextPortionPropertySet;
53 : }
54 :
55 91 : SwTextAPIObject::SwTextAPIObject( SwTextAPIEditSource* p )
56 : : SvxUnoText( p, ImplGetSvxTextPortionPropertySet(), uno::Reference < text::XText >() )
57 91 : , pSource(p)
58 : {
59 91 : }
60 :
61 273 : SwTextAPIObject::~SwTextAPIObject() throw()
62 : {
63 91 : pSource->Dispose();
64 91 : delete pSource;
65 182 : }
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 2406 : SwTextAPIEditSource::SwTextAPIEditSource( const SwTextAPIEditSource& rSource )
78 2406 : : SvxEditSource( *this )
79 : {
80 : // shallow copy; uses internal refcounting
81 2406 : pImpl = rSource.pImpl;
82 2406 : pImpl->mnRef++;
83 2406 : }
84 :
85 2406 : SvxEditSource* SwTextAPIEditSource::Clone() const
86 : {
87 2406 : return new SwTextAPIEditSource( *this );
88 : }
89 :
90 1796 : void SwTextAPIEditSource::UpdateData()
91 : {
92 : // data is kept in outliner all the time
93 1796 : }
94 :
95 91 : SwTextAPIEditSource::SwTextAPIEditSource(SwDoc* pDoc)
96 91 : : pImpl(new SwTextAPIEditSource_Impl)
97 : {
98 91 : pImpl->mpPool = &pDoc->GetDocShell()->GetPool();
99 91 : pImpl->mpDoc = pDoc;
100 91 : pImpl->mpOutliner = 0;
101 91 : pImpl->mpTextForwarder = 0;
102 91 : pImpl->mnRef = 1;
103 91 : }
104 :
105 7491 : SwTextAPIEditSource::~SwTextAPIEditSource()
106 : {
107 2497 : if (!--pImpl->mnRef)
108 91 : delete pImpl;
109 4994 : }
110 :
111 182 : void SwTextAPIEditSource::Dispose()
112 : {
113 182 : pImpl->mpPool=0;
114 182 : pImpl->mpDoc=0;
115 182 : DELETEZ(pImpl->mpTextForwarder);
116 182 : DELETEZ(pImpl->mpOutliner);
117 182 : }
118 :
119 23715 : SvxTextForwarder* SwTextAPIEditSource::GetTextForwarder()
120 : {
121 23715 : if( !pImpl->mpPool )
122 0 : return 0; // mpPool == 0 can be used to flag this as disposed
123 :
124 23715 : if( !pImpl->mpOutliner )
125 : {
126 : //init draw model first
127 91 : pImpl->mpDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
128 91 : pImpl->mpOutliner = new Outliner( pImpl->mpPool, OUTLINERMODE_TEXTOBJECT );
129 91 : pImpl->mpDoc->SetCalcFieldValueHdl( pImpl->mpOutliner );
130 : }
131 :
132 23715 : if( !pImpl->mpTextForwarder )
133 91 : pImpl->mpTextForwarder = new SvxOutlinerForwarder( *pImpl->mpOutliner, false );
134 :
135 23715 : return pImpl->mpTextForwarder;
136 : }
137 :
138 38 : void SwTextAPIEditSource::SetText( OutlinerParaObject& rText )
139 : {
140 38 : if ( pImpl->mpPool )
141 : {
142 38 : 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 38 : pImpl->mpOutliner->SetText( rText );
151 : }
152 38 : }
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 75 : OutlinerParaObject* SwTextAPIEditSource::CreateText()
172 : {
173 75 : if ( pImpl->mpPool && pImpl->mpOutliner )
174 75 : return pImpl->mpOutliner->CreateParaObject();
175 : else
176 0 : return 0;
177 : }
178 :
179 75 : OUString SwTextAPIEditSource::GetText()
180 : {
181 75 : if ( pImpl->mpPool && pImpl->mpOutliner )
182 75 : return pImpl->mpOutliner->GetEditEngine().GetText();
183 : else
184 0 : return OUString();
185 177 : }
186 :
187 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|