1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_editeng.hxx"
26
27 #include <outl_pch.hxx>
28
29 #define _OUTLINER_CXX
30 #include <editeng/outliner.hxx>
31 #include <editeng/outlobj.hxx>
32 #include <outleeng.hxx>
33 #include <editeng/editobj.hxx>
34 #include <vcl/bitmap.hxx>
35 #include <tools/stream.hxx>
36
37 //////////////////////////////////////////////////////////////////////////////
38
39 class ImplOutlinerParaObject
40 {
41 public:
42 // data members
43 EditTextObject* mpEditTextObject;
44 ParagraphDataVector maParagraphDataVector;
45 bool mbIsEditDoc;
46
47 // refcounter
48 sal_uInt32 mnRefCount;
49
50 // constuctor
ImplOutlinerParaObject(EditTextObject * pEditTextObject,const ParagraphDataVector & rParagraphDataVector,bool bIsEditDoc)51 ImplOutlinerParaObject(EditTextObject* pEditTextObject, const ParagraphDataVector& rParagraphDataVector, bool bIsEditDoc)
52 : mpEditTextObject(pEditTextObject),
53 maParagraphDataVector(rParagraphDataVector),
54 mbIsEditDoc(bIsEditDoc),
55 mnRefCount(0)
56 {
57 if( (maParagraphDataVector.size() == 0) && (pEditTextObject->GetParagraphCount() != 0) )
58 maParagraphDataVector.resize(pEditTextObject->GetParagraphCount());
59 }
60
61 // destructor
~ImplOutlinerParaObject()62 ~ImplOutlinerParaObject()
63 {
64 delete mpEditTextObject;
65 }
66
operator ==(const ImplOutlinerParaObject & rCandidate) const67 bool operator==(const ImplOutlinerParaObject& rCandidate) const
68 {
69 return (*mpEditTextObject == *rCandidate.mpEditTextObject
70 && maParagraphDataVector == rCandidate.maParagraphDataVector
71 && mbIsEditDoc == rCandidate.mbIsEditDoc);
72 }
73
74 // #i102062#
isWrongListEqual(const ImplOutlinerParaObject & rCompare) const75 bool isWrongListEqual(const ImplOutlinerParaObject& rCompare) const
76 {
77 return mpEditTextObject->isWrongListEqual(*rCompare.mpEditTextObject);
78 }
79 };
80
81 //////////////////////////////////////////////////////////////////////////////
82
ImplMakeUnique()83 void OutlinerParaObject::ImplMakeUnique()
84 {
85 if(mpImplOutlinerParaObject->mnRefCount)
86 {
87 ImplOutlinerParaObject* pNew = new ImplOutlinerParaObject(
88 mpImplOutlinerParaObject->mpEditTextObject->Clone(),
89 mpImplOutlinerParaObject->maParagraphDataVector,
90 mpImplOutlinerParaObject->mbIsEditDoc);
91 mpImplOutlinerParaObject->mnRefCount--;
92 mpImplOutlinerParaObject = pNew;
93 }
94 }
95
OutlinerParaObject(const EditTextObject & rEditTextObject,const ParagraphDataVector & rParagraphDataVector,bool bIsEditDoc)96 OutlinerParaObject::OutlinerParaObject(const EditTextObject& rEditTextObject, const ParagraphDataVector& rParagraphDataVector, bool bIsEditDoc)
97 : mpImplOutlinerParaObject(new ImplOutlinerParaObject(rEditTextObject.Clone(), rParagraphDataVector, bIsEditDoc))
98 {
99 }
100
OutlinerParaObject(const EditTextObject & rEditTextObject)101 OutlinerParaObject::OutlinerParaObject( const EditTextObject& rEditTextObject)
102 : mpImplOutlinerParaObject( new ImplOutlinerParaObject( rEditTextObject.Clone(), ParagraphDataVector(), true))
103 {}
104
OutlinerParaObject(const OutlinerParaObject & rCandidate)105 OutlinerParaObject::OutlinerParaObject(const OutlinerParaObject& rCandidate)
106 : mpImplOutlinerParaObject(rCandidate.mpImplOutlinerParaObject)
107 {
108 mpImplOutlinerParaObject->mnRefCount++;
109 }
110
~OutlinerParaObject()111 OutlinerParaObject::~OutlinerParaObject()
112 {
113 if(mpImplOutlinerParaObject->mnRefCount)
114 {
115 mpImplOutlinerParaObject->mnRefCount--;
116 }
117 else
118 {
119 delete mpImplOutlinerParaObject;
120 }
121 }
122
operator =(const OutlinerParaObject & rCandidate)123 OutlinerParaObject& OutlinerParaObject::operator=(const OutlinerParaObject& rCandidate)
124 {
125 if(rCandidate.mpImplOutlinerParaObject != mpImplOutlinerParaObject)
126 {
127 if(mpImplOutlinerParaObject->mnRefCount)
128 {
129 mpImplOutlinerParaObject->mnRefCount--;
130 }
131 else
132 {
133 delete mpImplOutlinerParaObject;
134 }
135
136 mpImplOutlinerParaObject = rCandidate.mpImplOutlinerParaObject;
137 mpImplOutlinerParaObject->mnRefCount++;
138 }
139
140 return *this;
141 }
142
operator ==(const OutlinerParaObject & rCandidate) const143 bool OutlinerParaObject::operator==(const OutlinerParaObject& rCandidate) const
144 {
145 if(rCandidate.mpImplOutlinerParaObject == mpImplOutlinerParaObject)
146 {
147 return true;
148 }
149
150 return (*rCandidate.mpImplOutlinerParaObject == *mpImplOutlinerParaObject);
151 }
152
153 // #i102062#
isWrongListEqual(const OutlinerParaObject & rCompare) const154 bool OutlinerParaObject::isWrongListEqual(const OutlinerParaObject& rCompare) const
155 {
156 if(rCompare.mpImplOutlinerParaObject == mpImplOutlinerParaObject)
157 {
158 return true;
159 }
160
161 return mpImplOutlinerParaObject->isWrongListEqual(*rCompare.mpImplOutlinerParaObject);
162 }
163
GetOutlinerMode() const164 sal_uInt16 OutlinerParaObject::GetOutlinerMode() const
165 {
166 return mpImplOutlinerParaObject->mpEditTextObject->GetUserType();
167 }
168
SetOutlinerMode(sal_uInt16 nNew)169 void OutlinerParaObject::SetOutlinerMode(sal_uInt16 nNew)
170 {
171 if(mpImplOutlinerParaObject->mpEditTextObject->GetUserType() != nNew)
172 {
173 ImplMakeUnique();
174 mpImplOutlinerParaObject->mpEditTextObject->SetUserType(nNew);
175 }
176 }
177
IsVertical() const178 bool OutlinerParaObject::IsVertical() const
179 {
180 return mpImplOutlinerParaObject->mpEditTextObject->IsVertical();
181 }
182
SetVertical(bool bNew)183 void OutlinerParaObject::SetVertical(bool bNew)
184 {
185 if((bool)mpImplOutlinerParaObject->mpEditTextObject->IsVertical() != bNew)
186 {
187 ImplMakeUnique();
188 mpImplOutlinerParaObject->mpEditTextObject->SetVertical(bNew);
189 }
190 }
191
Count() const192 sal_uInt32 OutlinerParaObject::Count() const
193 {
194 return mpImplOutlinerParaObject->maParagraphDataVector.size();
195 }
196
GetDepth(sal_uInt16 nPara) const197 sal_Int16 OutlinerParaObject::GetDepth(sal_uInt16 nPara) const
198 {
199 if(nPara < mpImplOutlinerParaObject->maParagraphDataVector.size())
200 {
201 return mpImplOutlinerParaObject->maParagraphDataVector[nPara].getDepth();
202 }
203 else
204 {
205 return -1;
206 }
207 }
208
GetTextObject() const209 const EditTextObject& OutlinerParaObject::GetTextObject() const
210 {
211 return *mpImplOutlinerParaObject->mpEditTextObject;
212 }
213
IsEditDoc() const214 bool OutlinerParaObject::IsEditDoc() const
215 {
216 return mpImplOutlinerParaObject->mbIsEditDoc;
217 }
218
GetParagraphData(sal_uInt32 nIndex) const219 const ParagraphData& OutlinerParaObject::GetParagraphData(sal_uInt32 nIndex) const
220 {
221 if(nIndex < mpImplOutlinerParaObject->maParagraphDataVector.size())
222 {
223 return mpImplOutlinerParaObject->maParagraphDataVector[nIndex];
224 }
225 else
226 {
227 OSL_ENSURE(false, "OutlinerParaObject::GetParagraphData: Access out of range (!)");
228 static ParagraphData aEmptyParagraphData;
229 return aEmptyParagraphData;
230 }
231 }
232
ClearPortionInfo()233 void OutlinerParaObject::ClearPortionInfo()
234 {
235 ImplMakeUnique();
236 mpImplOutlinerParaObject->mpEditTextObject->ClearPortionInfo();
237 }
238
ChangeStyleSheets(const XubString & rOldName,SfxStyleFamily eOldFamily,const XubString & rNewName,SfxStyleFamily eNewFamily)239 bool OutlinerParaObject::ChangeStyleSheets(const XubString& rOldName, SfxStyleFamily eOldFamily, const XubString& rNewName, SfxStyleFamily eNewFamily)
240 {
241 ImplMakeUnique();
242 return mpImplOutlinerParaObject->mpEditTextObject->ChangeStyleSheets(rOldName, eOldFamily, rNewName, eNewFamily);
243 }
244
ChangeStyleSheetName(SfxStyleFamily eFamily,const XubString & rOldName,const XubString & rNewName)245 void OutlinerParaObject::ChangeStyleSheetName(SfxStyleFamily eFamily, const XubString& rOldName, const XubString& rNewName)
246 {
247 ImplMakeUnique();
248 mpImplOutlinerParaObject->mpEditTextObject->ChangeStyleSheetName(eFamily, rOldName, rNewName);
249 }
250
SetStyleSheets(sal_uInt16 nLevel,const XubString rNewName,const SfxStyleFamily & rNewFamily)251 void OutlinerParaObject::SetStyleSheets(sal_uInt16 nLevel, const XubString rNewName, const SfxStyleFamily& rNewFamily)
252 {
253 const sal_uInt32 nCount(mpImplOutlinerParaObject->maParagraphDataVector.size());
254
255 if(nCount)
256 {
257 ImplMakeUnique();
258 sal_uInt16 nDecrementer(sal::static_int_cast< sal_uInt16 >(nCount));
259
260 for(;nDecrementer;)
261 {
262 if(GetDepth(--nDecrementer) == nLevel)
263 {
264 mpImplOutlinerParaObject->mpEditTextObject->SetStyleSheet(nDecrementer, rNewName, rNewFamily);
265 }
266 }
267 }
268 }
269
270 //////////////////////////////////////////////////////////////////////////////
271 // eof
272