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