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 <svl/intitem.hxx>
21 : #include <editeng/editeng.hxx>
22 : #include <editeng/editview.hxx>
23 : #include <editeng/editdata.hxx>
24 : #include <editeng/eerdll.hxx>
25 : #include <editeng/lrspitem.hxx>
26 : #include <editeng/fhgtitem.hxx>
27 :
28 : #define _OUTLINER_CXX
29 : #include <editeng/outliner.hxx>
30 : #include <editeng/outlobj.hxx>
31 : #include <outleeng.hxx>
32 : #include <editeng/editobj.hxx>
33 : #include <vcl/bitmap.hxx>
34 : #include <tools/stream.hxx>
35 :
36 : //////////////////////////////////////////////////////////////////////////////
37 :
38 : class ImplOutlinerParaObject
39 : {
40 : public:
41 : // data members
42 : EditTextObject* mpEditTextObject;
43 : ParagraphDataVector maParagraphDataVector;
44 : bool mbIsEditDoc;
45 :
46 : // refcounter
47 : sal_uInt32 mnRefCount;
48 :
49 : // constuctor
50 9328 : ImplOutlinerParaObject(EditTextObject* pEditTextObject, const ParagraphDataVector& rParagraphDataVector, bool bIsEditDoc)
51 : : mpEditTextObject(pEditTextObject),
52 : maParagraphDataVector(rParagraphDataVector),
53 : mbIsEditDoc(bIsEditDoc),
54 9328 : mnRefCount(0)
55 : {
56 9328 : if( maParagraphDataVector.empty() && (pEditTextObject->GetParagraphCount() != 0) )
57 67 : maParagraphDataVector.resize(pEditTextObject->GetParagraphCount());
58 9328 : }
59 :
60 : // destructor
61 9282 : ~ImplOutlinerParaObject()
62 9282 : {
63 9282 : delete mpEditTextObject;
64 9282 : }
65 :
66 30 : bool operator==(const ImplOutlinerParaObject& rCandidate) const
67 : {
68 30 : return (*mpEditTextObject == *rCandidate.mpEditTextObject
69 0 : && maParagraphDataVector == rCandidate.maParagraphDataVector
70 30 : && mbIsEditDoc == rCandidate.mbIsEditDoc);
71 : }
72 :
73 : // #i102062#
74 0 : bool isWrongListEqual(const ImplOutlinerParaObject& rCompare) const
75 : {
76 0 : return mpEditTextObject->isWrongListEqual(*rCompare.mpEditTextObject);
77 : }
78 : };
79 :
80 : //////////////////////////////////////////////////////////////////////////////
81 :
82 10293 : void OutlinerParaObject::ImplMakeUnique()
83 : {
84 10293 : if(mpImplOutlinerParaObject->mnRefCount)
85 : {
86 : ImplOutlinerParaObject* pNew = new ImplOutlinerParaObject(
87 15 : mpImplOutlinerParaObject->mpEditTextObject->Clone(),
88 : mpImplOutlinerParaObject->maParagraphDataVector,
89 15 : mpImplOutlinerParaObject->mbIsEditDoc);
90 15 : mpImplOutlinerParaObject->mnRefCount--;
91 15 : mpImplOutlinerParaObject = pNew;
92 : }
93 10293 : }
94 :
95 9313 : OutlinerParaObject::OutlinerParaObject(const EditTextObject& rEditTextObject, const ParagraphDataVector& rParagraphDataVector, bool bIsEditDoc)
96 9313 : : mpImplOutlinerParaObject(new ImplOutlinerParaObject(rEditTextObject.Clone(), rParagraphDataVector, bIsEditDoc))
97 : {
98 9313 : }
99 :
100 707 : OutlinerParaObject::OutlinerParaObject(const OutlinerParaObject& rCandidate)
101 707 : : mpImplOutlinerParaObject(rCandidate.mpImplOutlinerParaObject)
102 : {
103 707 : mpImplOutlinerParaObject->mnRefCount++;
104 707 : }
105 :
106 9936 : OutlinerParaObject::~OutlinerParaObject()
107 : {
108 9936 : if(mpImplOutlinerParaObject->mnRefCount)
109 : {
110 654 : mpImplOutlinerParaObject->mnRefCount--;
111 : }
112 : else
113 : {
114 9282 : delete mpImplOutlinerParaObject;
115 : }
116 9936 : }
117 :
118 0 : OutlinerParaObject& OutlinerParaObject::operator=(const OutlinerParaObject& rCandidate)
119 : {
120 0 : if(rCandidate.mpImplOutlinerParaObject != mpImplOutlinerParaObject)
121 : {
122 0 : if(mpImplOutlinerParaObject->mnRefCount)
123 : {
124 0 : mpImplOutlinerParaObject->mnRefCount--;
125 : }
126 : else
127 : {
128 0 : delete mpImplOutlinerParaObject;
129 : }
130 :
131 0 : mpImplOutlinerParaObject = rCandidate.mpImplOutlinerParaObject;
132 0 : mpImplOutlinerParaObject->mnRefCount++;
133 : }
134 :
135 0 : return *this;
136 : }
137 :
138 38 : bool OutlinerParaObject::operator==(const OutlinerParaObject& rCandidate) const
139 : {
140 38 : if(rCandidate.mpImplOutlinerParaObject == mpImplOutlinerParaObject)
141 : {
142 8 : return true;
143 : }
144 :
145 30 : return (*rCandidate.mpImplOutlinerParaObject == *mpImplOutlinerParaObject);
146 : }
147 :
148 : // #i102062#
149 8 : bool OutlinerParaObject::isWrongListEqual(const OutlinerParaObject& rCompare) const
150 : {
151 8 : if(rCompare.mpImplOutlinerParaObject == mpImplOutlinerParaObject)
152 : {
153 8 : return true;
154 : }
155 :
156 0 : return mpImplOutlinerParaObject->isWrongListEqual(*rCompare.mpImplOutlinerParaObject);
157 : }
158 :
159 12323 : sal_uInt16 OutlinerParaObject::GetOutlinerMode() const
160 : {
161 12323 : return mpImplOutlinerParaObject->mpEditTextObject->GetUserType();
162 : }
163 :
164 9313 : void OutlinerParaObject::SetOutlinerMode(sal_uInt16 nNew)
165 : {
166 9313 : if(mpImplOutlinerParaObject->mpEditTextObject->GetUserType() != nNew)
167 : {
168 9313 : ImplMakeUnique();
169 9313 : mpImplOutlinerParaObject->mpEditTextObject->SetUserType(nNew);
170 : }
171 9313 : }
172 :
173 8243 : bool OutlinerParaObject::IsVertical() const
174 : {
175 8243 : return mpImplOutlinerParaObject->mpEditTextObject->IsVertical();
176 : }
177 :
178 56 : void OutlinerParaObject::SetVertical(bool bNew)
179 : {
180 56 : if((bool)mpImplOutlinerParaObject->mpEditTextObject->IsVertical() != bNew)
181 : {
182 0 : ImplMakeUnique();
183 0 : mpImplOutlinerParaObject->mpEditTextObject->SetVertical(bNew);
184 : }
185 56 : }
186 :
187 25198 : sal_uInt32 OutlinerParaObject::Count() const
188 : {
189 25198 : return mpImplOutlinerParaObject->maParagraphDataVector.size();
190 : }
191 :
192 0 : sal_Int16 OutlinerParaObject::GetDepth(sal_uInt16 nPara) const
193 : {
194 0 : if(nPara < mpImplOutlinerParaObject->maParagraphDataVector.size())
195 : {
196 0 : return mpImplOutlinerParaObject->maParagraphDataVector[nPara].getDepth();
197 : }
198 : else
199 : {
200 0 : return -1;
201 : }
202 : }
203 :
204 21813 : const EditTextObject& OutlinerParaObject::GetTextObject() const
205 : {
206 21813 : return *mpImplOutlinerParaObject->mpEditTextObject;
207 : }
208 :
209 3367 : bool OutlinerParaObject::IsEditDoc() const
210 : {
211 3367 : return mpImplOutlinerParaObject->mbIsEditDoc;
212 : }
213 :
214 12875 : const ParagraphData& OutlinerParaObject::GetParagraphData(sal_uInt32 nIndex) const
215 : {
216 12875 : if(nIndex < mpImplOutlinerParaObject->maParagraphDataVector.size())
217 : {
218 12875 : return mpImplOutlinerParaObject->maParagraphDataVector[nIndex];
219 : }
220 : else
221 : {
222 : OSL_FAIL("OutlinerParaObject::GetParagraphData: Access out of range (!)");
223 0 : static ParagraphData aEmptyParagraphData;
224 0 : return aEmptyParagraphData;
225 : }
226 : }
227 :
228 0 : void OutlinerParaObject::ClearPortionInfo()
229 : {
230 0 : ImplMakeUnique();
231 0 : mpImplOutlinerParaObject->mpEditTextObject->ClearPortionInfo();
232 0 : }
233 :
234 980 : bool OutlinerParaObject::ChangeStyleSheets(const OUString& rOldName,
235 : SfxStyleFamily eOldFamily, const OUString& rNewName, SfxStyleFamily eNewFamily)
236 : {
237 980 : ImplMakeUnique();
238 980 : return mpImplOutlinerParaObject->mpEditTextObject->ChangeStyleSheets(rOldName, eOldFamily, rNewName, eNewFamily);
239 : }
240 :
241 0 : void OutlinerParaObject::ChangeStyleSheetName(SfxStyleFamily eFamily,
242 : const OUString& rOldName, const OUString& rNewName)
243 : {
244 0 : ImplMakeUnique();
245 0 : mpImplOutlinerParaObject->mpEditTextObject->ChangeStyleSheetName(eFamily, rOldName, rNewName);
246 0 : }
247 :
248 0 : void OutlinerParaObject::SetStyleSheets(sal_uInt16 nLevel, const OUString rNewName,
249 : const SfxStyleFamily& rNewFamily)
250 : {
251 0 : const sal_uInt32 nCount(mpImplOutlinerParaObject->maParagraphDataVector.size());
252 :
253 0 : if(nCount)
254 : {
255 0 : ImplMakeUnique();
256 0 : sal_uInt16 nDecrementer(sal::static_int_cast< sal_uInt16 >(nCount));
257 :
258 0 : for(;nDecrementer;)
259 : {
260 0 : if(GetDepth(--nDecrementer) == nLevel)
261 : {
262 0 : mpImplOutlinerParaObject->mpEditTextObject->SetStyleSheet(nDecrementer, rNewName, rNewFamily);
263 : }
264 : }
265 : }
266 0 : }
267 :
268 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|