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