File: | home/maarten/src/libreoffice/core/include/rtl/ref.hxx |
Warning: | line 192, column 9 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 <sal/config.h> | |||
21 | ||||
22 | #include <memory> | |||
23 | ||||
24 | #include <scitems.hxx> | |||
25 | #include <editeng/boxitem.hxx> | |||
26 | #include <editeng/justifyitem.hxx> | |||
27 | #include <svl/srchitem.hxx> | |||
28 | #include <sfx2/linkmgr.hxx> | |||
29 | #include <vcl/virdev.hxx> | |||
30 | #include <sfx2/app.hxx> | |||
31 | #include <svx/svdundo.hxx> | |||
32 | ||||
33 | #include <undoblk.hxx> | |||
34 | #include <globstr.hrc> | |||
35 | #include <scresid.hxx> | |||
36 | #include <global.hxx> | |||
37 | #include <arealink.hxx> | |||
38 | #include <patattr.hxx> | |||
39 | #include <target.hxx> | |||
40 | #include <document.hxx> | |||
41 | #include <docpool.hxx> | |||
42 | #include <docsh.hxx> | |||
43 | #include <tabvwsh.hxx> | |||
44 | #include <undoolk.hxx> | |||
45 | #include <undoutil.hxx> | |||
46 | #include <chgtrack.hxx> | |||
47 | #include <paramisc.hxx> | |||
48 | #include <postit.hxx> | |||
49 | #include <progress.hxx> | |||
50 | #include <editutil.hxx> | |||
51 | #include <editdataarray.hxx> | |||
52 | #include <rowheightcontext.hxx> | |||
53 | ||||
54 | // TODO: | |||
55 | /*A*/ // SetOptimalHeight on Document, when no View | |||
56 | ||||
57 | ScUndoDeleteContents::ScUndoDeleteContents( | |||
58 | ScDocShell* pNewDocShell, | |||
59 | const ScMarkData& rMark, const ScRange& rRange, | |||
60 | ScDocumentUniquePtr&& pNewUndoDoc, bool bNewMulti, | |||
61 | InsertDeleteFlags nNewFlags, bool bObjects ) | |||
62 | : ScSimpleUndo( pNewDocShell ), | |||
63 | aRange ( rRange ), | |||
64 | aMarkData ( rMark ), | |||
65 | pUndoDoc ( std::move(pNewUndoDoc) ), | |||
66 | nFlags ( nNewFlags ), | |||
67 | bMulti ( bNewMulti ) // unnecessary | |||
68 | { | |||
69 | if (bObjects) | |||
70 | pDrawUndo = GetSdrUndoAction( &pDocShell->GetDocument() ); | |||
71 | ||||
72 | if ( !(aMarkData.IsMarked() || aMarkData.IsMultiMarked()) ) // if no cell is selected: | |||
73 | aMarkData.SetMarkArea( aRange ); // select cell under cursor | |||
74 | ||||
75 | SetChangeTrack(); | |||
76 | } | |||
77 | ||||
78 | ScUndoDeleteContents::~ScUndoDeleteContents() | |||
79 | { | |||
80 | pUndoDoc.reset(); | |||
81 | pDrawUndo.reset(); | |||
82 | } | |||
83 | ||||
84 | OUString ScUndoDeleteContents::GetComment() const | |||
85 | { | |||
86 | return ScResId( STR_UNDO_DELETECONTENTSreinterpret_cast<char const *>("STR_UNDO_DELETECONTENTS" "\004" u8"Delete") ); // "Delete" | |||
87 | } | |||
88 | ||||
89 | void ScUndoDeleteContents::SetDataSpans( const std::shared_ptr<DataSpansType>& pSpans ) | |||
90 | { | |||
91 | mpDataSpans = pSpans; | |||
92 | } | |||
93 | ||||
94 | void ScUndoDeleteContents::SetChangeTrack() | |||
95 | { | |||
96 | ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack(); | |||
97 | if ( pChangeTrack && (nFlags & InsertDeleteFlags::CONTENTS) ) | |||
98 | pChangeTrack->AppendContentRange( aRange, pUndoDoc.get(), | |||
99 | nStartChangeAction, nEndChangeAction ); | |||
100 | else | |||
101 | nStartChangeAction = nEndChangeAction = 0; | |||
102 | } | |||
103 | ||||
104 | void ScUndoDeleteContents::DoChange( const bool bUndo ) | |||
105 | { | |||
106 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
107 | ||||
108 | SetViewMarkData( aMarkData ); | |||
109 | ||||
110 | sal_uInt16 nExtFlags = 0; | |||
111 | ||||
112 | if (bUndo) // only Undo | |||
113 | { | |||
114 | InsertDeleteFlags nUndoFlags = InsertDeleteFlags::NONE; // copy either all or none of the content | |||
115 | if (nFlags & InsertDeleteFlags::CONTENTS) // (Only the correct ones have been copied into UndoDoc) | |||
116 | nUndoFlags |= InsertDeleteFlags::CONTENTS; | |||
117 | if (nFlags & InsertDeleteFlags::ATTRIB) | |||
118 | nUndoFlags |= InsertDeleteFlags::ATTRIB; | |||
119 | if (nFlags & InsertDeleteFlags::EDITATTR) // Edit-Engine attribute | |||
120 | nUndoFlags |= InsertDeleteFlags::STRING; // -> Cells will be changed | |||
121 | // do not create clones of note captions, they will be restored via drawing undo | |||
122 | nUndoFlags |= InsertDeleteFlags::NOCAPTIONS; | |||
123 | ||||
124 | ScRange aCopyRange = aRange; | |||
125 | SCTAB nTabCount = rDoc.GetTableCount(); | |||
126 | aCopyRange.aStart.SetTab(0); | |||
127 | aCopyRange.aEnd.SetTab(nTabCount-1); | |||
128 | ||||
129 | pUndoDoc->CopyToDocument(aCopyRange, nUndoFlags, bMulti, rDoc, &aMarkData); | |||
130 | ||||
131 | DoSdrUndoAction( pDrawUndo.get(), &rDoc ); | |||
132 | ||||
133 | ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack(); | |||
134 | if ( pChangeTrack ) | |||
135 | pChangeTrack->Undo( nStartChangeAction, nEndChangeAction ); | |||
136 | ||||
137 | pDocShell->UpdatePaintExt( nExtFlags, aRange ); // content after the change | |||
138 | } | |||
139 | else // only Redo | |||
140 | { | |||
141 | pDocShell->UpdatePaintExt( nExtFlags, aRange ); // content before the change | |||
142 | ||||
143 | aMarkData.MarkToMulti(); | |||
144 | RedoSdrUndoAction( pDrawUndo.get() ); | |||
145 | // do not delete objects and note captions, they have been removed via drawing undo | |||
146 | InsertDeleteFlags nRedoFlags = (nFlags & ~InsertDeleteFlags::OBJECTS) | InsertDeleteFlags::NOCAPTIONS; | |||
147 | rDoc.DeleteSelection( nRedoFlags, aMarkData ); | |||
148 | aMarkData.MarkToSimple(); | |||
149 | ||||
150 | SetChangeTrack(); | |||
151 | } | |||
152 | ||||
153 | if (nFlags & InsertDeleteFlags::CONTENTS) | |||
154 | { | |||
155 | // Broadcast only when the content changes. fdo#74687 | |||
156 | if (mpDataSpans) | |||
157 | BroadcastChanges(*mpDataSpans); | |||
158 | else | |||
159 | BroadcastChanges(aRange); | |||
160 | } | |||
161 | ||||
162 | ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); | |||
163 | if ( !( pViewShell && pViewShell->AdjustRowHeight( | |||
164 | aRange.aStart.Row(), aRange.aEnd.Row() ) ) ) | |||
165 | /*A*/ pDocShell->PostPaint( aRange, PaintPartFlags::Grid | PaintPartFlags::Extras, nExtFlags ); | |||
166 | ||||
167 | if (pViewShell) | |||
168 | pViewShell->CellContentChanged(); | |||
169 | ||||
170 | ShowTable( aRange ); | |||
171 | } | |||
172 | ||||
173 | void ScUndoDeleteContents::Undo() | |||
174 | { | |||
175 | BeginUndo(); | |||
176 | DoChange( true ); | |||
177 | EndUndo(); | |||
178 | ||||
179 | HelperNotifyChanges::NotifyIfChangesListeners(*pDocShell, aRange); | |||
180 | } | |||
181 | ||||
182 | void ScUndoDeleteContents::Redo() | |||
183 | { | |||
184 | BeginRedo(); | |||
185 | DoChange( false ); | |||
186 | EndRedo(); | |||
187 | ||||
188 | HelperNotifyChanges::NotifyIfChangesListeners(*pDocShell, aRange); | |||
189 | } | |||
190 | ||||
191 | void ScUndoDeleteContents::Repeat(SfxRepeatTarget& rTarget) | |||
192 | { | |||
193 | if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr) | |||
194 | static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->DeleteContents( nFlags ); | |||
195 | } | |||
196 | ||||
197 | bool ScUndoDeleteContents::CanRepeat(SfxRepeatTarget& rTarget) const | |||
198 | { | |||
199 | return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr; | |||
200 | } | |||
201 | ||||
202 | ScUndoFillTable::ScUndoFillTable( ScDocShell* pNewDocShell, | |||
203 | const ScMarkData& rMark, | |||
204 | SCCOL nStartX, SCROW nStartY, SCTAB nStartZ, | |||
205 | SCCOL nEndX, SCROW nEndY, SCTAB nEndZ, | |||
206 | ScDocumentUniquePtr pNewUndoDoc, bool bNewMulti, SCTAB nSrc, | |||
207 | InsertDeleteFlags nFlg, ScPasteFunc nFunc, bool bSkip, bool bLink ) | |||
208 | : ScSimpleUndo( pNewDocShell ), | |||
209 | aRange ( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ), | |||
210 | aMarkData ( rMark ), | |||
211 | pUndoDoc ( std::move(pNewUndoDoc) ), | |||
212 | nFlags ( nFlg ), | |||
213 | nFunction ( nFunc ), | |||
214 | nSrcTab ( nSrc ), | |||
215 | bMulti ( bNewMulti ), | |||
216 | bSkipEmpty ( bSkip ), | |||
217 | bAsLink ( bLink ) | |||
218 | { | |||
219 | SetChangeTrack(); | |||
220 | } | |||
221 | ||||
222 | ScUndoFillTable::~ScUndoFillTable() | |||
223 | { | |||
224 | } | |||
225 | ||||
226 | OUString ScUndoFillTable::GetComment() const | |||
227 | { | |||
228 | return ScResId( STR_FILL_TABreinterpret_cast<char const *>("STR_FILL_TAB" "\004" u8"Fill Sheets" ) ); | |||
229 | } | |||
230 | ||||
231 | void ScUndoFillTable::SetChangeTrack() | |||
232 | { | |||
233 | ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack(); | |||
234 | if ( pChangeTrack ) | |||
235 | { | |||
236 | SCTAB nTabCount = pDocShell->GetDocument().GetTableCount(); | |||
237 | ScRange aWorkRange(aRange); | |||
238 | nStartChangeAction = 0; | |||
239 | sal_uLong nTmpAction; | |||
240 | for (const auto& rTab : aMarkData) | |||
241 | { | |||
242 | if (rTab >= nTabCount) | |||
243 | break; | |||
244 | if (rTab != nSrcTab) | |||
245 | { | |||
246 | aWorkRange.aStart.SetTab(rTab); | |||
247 | aWorkRange.aEnd.SetTab(rTab); | |||
248 | pChangeTrack->AppendContentRange( aWorkRange, pUndoDoc.get(), | |||
249 | nTmpAction, nEndChangeAction ); | |||
250 | if ( !nStartChangeAction ) | |||
251 | nStartChangeAction = nTmpAction; | |||
252 | } | |||
253 | } | |||
254 | } | |||
255 | else | |||
256 | nStartChangeAction = nEndChangeAction = 0; | |||
257 | } | |||
258 | ||||
259 | void ScUndoFillTable::DoChange( const bool bUndo ) | |||
260 | { | |||
261 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
262 | ||||
263 | SetViewMarkData( aMarkData ); | |||
264 | ||||
265 | if (bUndo) // only Undo | |||
266 | { | |||
267 | SCTAB nTabCount = rDoc.GetTableCount(); | |||
268 | ScRange aWorkRange(aRange); | |||
269 | for (const auto& rTab : aMarkData) | |||
270 | { | |||
271 | if (rTab >= nTabCount) | |||
272 | break; | |||
273 | if (rTab != nSrcTab) | |||
274 | { | |||
275 | aWorkRange.aStart.SetTab(rTab); | |||
276 | aWorkRange.aEnd.SetTab(rTab); | |||
277 | if (bMulti) | |||
278 | rDoc.DeleteSelectionTab( rTab, InsertDeleteFlags::ALL, aMarkData ); | |||
279 | else | |||
280 | rDoc.DeleteAreaTab( aWorkRange, InsertDeleteFlags::ALL ); | |||
281 | pUndoDoc->CopyToDocument(aWorkRange, InsertDeleteFlags::ALL, bMulti, rDoc, &aMarkData); | |||
282 | } | |||
283 | } | |||
284 | ||||
285 | ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack(); | |||
286 | if ( pChangeTrack ) | |||
287 | pChangeTrack->Undo( nStartChangeAction, nEndChangeAction ); | |||
288 | } | |||
289 | else // only Redo | |||
290 | { | |||
291 | aMarkData.MarkToMulti(); | |||
292 | rDoc.FillTabMarked( nSrcTab, aMarkData, nFlags, nFunction, bSkipEmpty, bAsLink ); | |||
293 | aMarkData.MarkToSimple(); | |||
294 | SetChangeTrack(); | |||
295 | } | |||
296 | ||||
297 | pDocShell->PostPaint(0,0,0,rDoc.MaxCol(),rDoc.MaxRow(),MAXTAB, PaintPartFlags::Grid|PaintPartFlags::Extras); | |||
298 | pDocShell->PostDataChanged(); | |||
299 | ||||
300 | // CellContentChanged comes with the selection | |||
301 | ||||
302 | ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); | |||
303 | if (pViewShell) | |||
304 | { | |||
305 | SCTAB nTab = pViewShell->GetViewData().GetTabNo(); | |||
306 | if ( !aMarkData.GetTableSelect(nTab) ) | |||
307 | pViewShell->SetTabNo( nSrcTab ); | |||
308 | ||||
309 | pViewShell->DoneBlockMode(); // causes problems otherwise since selection is on the wrong sheet. | |||
310 | } | |||
311 | } | |||
312 | ||||
313 | void ScUndoFillTable::Undo() | |||
314 | { | |||
315 | BeginUndo(); | |||
316 | DoChange( true ); | |||
317 | EndUndo(); | |||
318 | } | |||
319 | ||||
320 | void ScUndoFillTable::Redo() | |||
321 | { | |||
322 | BeginRedo(); | |||
323 | DoChange( false ); | |||
324 | EndRedo(); | |||
325 | } | |||
326 | ||||
327 | void ScUndoFillTable::Repeat(SfxRepeatTarget& rTarget) | |||
328 | { | |||
329 | if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr) | |||
330 | static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->FillTab( nFlags, nFunction, bSkipEmpty, bAsLink ); | |||
331 | } | |||
332 | ||||
333 | bool ScUndoFillTable::CanRepeat(SfxRepeatTarget& rTarget) const | |||
334 | { | |||
335 | return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr; | |||
336 | } | |||
337 | ||||
338 | ScUndoSelectionAttr::ScUndoSelectionAttr( ScDocShell* pNewDocShell, | |||
339 | const ScMarkData& rMark, | |||
340 | SCCOL nStartX, SCROW nStartY, SCTAB nStartZ, | |||
341 | SCCOL nEndX, SCROW nEndY, SCTAB nEndZ, | |||
342 | ScDocumentUniquePtr pNewUndoDoc, bool bNewMulti, | |||
343 | const ScPatternAttr* pNewApply, | |||
344 | const SvxBoxItem* pNewOuter, const SvxBoxInfoItem* pNewInner, | |||
345 | const ScRange* pRangeCover ) | |||
346 | : ScSimpleUndo( pNewDocShell ), | |||
347 | aMarkData ( rMark ), | |||
348 | aRange ( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ), | |||
349 | mpDataArray(new ScEditDataArray), | |||
350 | pUndoDoc ( std::move(pNewUndoDoc) ), | |||
351 | bMulti ( bNewMulti ) | |||
352 | { | |||
353 | ScDocumentPool* pPool = pDocShell->GetDocument().GetPool(); | |||
354 | pApplyPattern = const_cast<ScPatternAttr*>(&pPool->Put( *pNewApply )); | |||
355 | pLineOuter = pNewOuter ? const_cast<SvxBoxItem*>( &pPool->Put( *pNewOuter ) ) : nullptr; | |||
356 | pLineInner = pNewInner ? const_cast<SvxBoxInfoItem*>( &pPool->Put( *pNewInner ) ) : nullptr; | |||
357 | aRangeCover = pRangeCover ? *pRangeCover : aRange; | |||
358 | } | |||
359 | ||||
360 | ScUndoSelectionAttr::~ScUndoSelectionAttr() | |||
361 | { | |||
362 | ScDocumentPool* pPool = pDocShell->GetDocument().GetPool(); | |||
363 | pPool->Remove(*pApplyPattern); | |||
364 | if (pLineOuter) | |||
365 | pPool->Remove(*pLineOuter); | |||
366 | if (pLineInner) | |||
367 | pPool->Remove(*pLineInner); | |||
368 | ||||
369 | pUndoDoc.reset(); | |||
370 | } | |||
371 | ||||
372 | OUString ScUndoSelectionAttr::GetComment() const | |||
373 | { | |||
374 | //"Attribute" "/Lines" | |||
375 | return ScResId( pLineOuter ? STR_UNDO_SELATTRLINESreinterpret_cast<char const *>("STR_UNDO_SELATTRLINES" "\004" u8"Attributes/Lines") : STR_UNDO_SELATTRreinterpret_cast<char const *>("STR_UNDO_SELATTR" "\004" u8"Attributes") ); | |||
376 | } | |||
377 | ||||
378 | ScEditDataArray* ScUndoSelectionAttr::GetDataArray() | |||
379 | { | |||
380 | return mpDataArray.get(); | |||
381 | } | |||
382 | ||||
383 | void ScUndoSelectionAttr::DoChange( const bool bUndo ) | |||
384 | { | |||
385 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
386 | ||||
387 | SetViewMarkData( aMarkData ); | |||
388 | ||||
389 | ScRange aEffRange( aRangeCover ); | |||
390 | if ( rDoc.HasAttrib( aEffRange, HasAttrFlags::Merged ) ) // merged cells? | |||
391 | rDoc.ExtendMerge( aEffRange ); | |||
392 | ||||
393 | sal_uInt16 nExtFlags = 0; | |||
394 | pDocShell->UpdatePaintExt( nExtFlags, aEffRange ); | |||
395 | ||||
396 | ChangeEditData(bUndo); | |||
397 | ||||
398 | if (bUndo) // only for Undo | |||
399 | { | |||
400 | ScRange aCopyRange = aRangeCover; | |||
401 | SCTAB nTabCount = rDoc.GetTableCount(); | |||
402 | aCopyRange.aStart.SetTab(0); | |||
403 | aCopyRange.aEnd.SetTab(nTabCount-1); | |||
404 | pUndoDoc->CopyToDocument(aCopyRange, InsertDeleteFlags::ATTRIB, bMulti, rDoc, &aMarkData); | |||
405 | } | |||
406 | else // only for Redo | |||
407 | { | |||
408 | aMarkData.MarkToMulti(); | |||
409 | rDoc.ApplySelectionPattern( *pApplyPattern, aMarkData ); | |||
410 | aMarkData.MarkToSimple(); | |||
411 | ||||
412 | if (pLineOuter) | |||
413 | rDoc.ApplySelectionFrame(aMarkData, *pLineOuter, pLineInner); | |||
414 | } | |||
415 | ||||
416 | ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); | |||
417 | if ( !( pViewShell && pViewShell->AdjustBlockHeight() ) ) | |||
418 | /*A*/ pDocShell->PostPaint( aEffRange, PaintPartFlags::Grid | PaintPartFlags::Extras, nExtFlags ); | |||
419 | ||||
420 | ShowTable( aRange ); | |||
421 | } | |||
422 | ||||
423 | void ScUndoSelectionAttr::ChangeEditData( const bool bUndo ) | |||
424 | { | |||
425 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
426 | for (const ScEditDataArray::Item* pItem = mpDataArray->First(); pItem; pItem = mpDataArray->Next()) | |||
427 | { | |||
428 | ScAddress aPos(pItem->GetCol(), pItem->GetRow(), pItem->GetTab()); | |||
429 | if (rDoc.GetCellType(aPos) != CELLTYPE_EDIT) | |||
430 | continue; | |||
431 | ||||
432 | if (bUndo) | |||
433 | { | |||
434 | if (pItem->GetOldData()) | |||
435 | rDoc.SetEditText(aPos, *pItem->GetOldData(), nullptr); | |||
436 | else | |||
437 | rDoc.SetEmptyCell(aPos); | |||
438 | } | |||
439 | else | |||
440 | { | |||
441 | if (pItem->GetNewData()) | |||
442 | rDoc.SetEditText(aPos, *pItem->GetNewData(), nullptr); | |||
443 | else | |||
444 | rDoc.SetEmptyCell(aPos); | |||
445 | } | |||
446 | } | |||
447 | } | |||
448 | ||||
449 | void ScUndoSelectionAttr::Undo() | |||
450 | { | |||
451 | BeginUndo(); | |||
452 | DoChange( true ); | |||
453 | EndUndo(); | |||
454 | } | |||
455 | ||||
456 | void ScUndoSelectionAttr::Redo() | |||
457 | { | |||
458 | BeginRedo(); | |||
459 | DoChange( false ); | |||
460 | EndRedo(); | |||
461 | } | |||
462 | ||||
463 | void ScUndoSelectionAttr::Repeat(SfxRepeatTarget& rTarget) | |||
464 | { | |||
465 | if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr) | |||
466 | { | |||
467 | ScTabViewShell& rViewShell = *static_cast<ScTabViewTarget&>(rTarget).GetViewShell(); | |||
468 | if (pLineOuter) | |||
469 | rViewShell.ApplyPatternLines(*pApplyPattern, *pLineOuter, pLineInner); | |||
470 | else | |||
471 | rViewShell.ApplySelectionPattern( *pApplyPattern ); | |||
472 | } | |||
473 | } | |||
474 | ||||
475 | bool ScUndoSelectionAttr::CanRepeat(SfxRepeatTarget& rTarget) const | |||
476 | { | |||
477 | return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr; | |||
478 | } | |||
479 | ||||
480 | ScUndoAutoFill::ScUndoAutoFill( ScDocShell* pNewDocShell, | |||
481 | const ScRange& rRange, const ScRange& rSourceArea, | |||
482 | ScDocumentUniquePtr pNewUndoDoc, const ScMarkData& rMark, | |||
483 | FillDir eNewFillDir, FillCmd eNewFillCmd, FillDateCmd eNewFillDateCmd, | |||
484 | double fNewStartValue, double fNewStepValue, double fNewMaxValue ) | |||
485 | : ScBlockUndo( pNewDocShell, rRange, SC_UNDO_AUTOHEIGHT ), | |||
486 | aSource ( rSourceArea ), | |||
487 | aMarkData ( rMark ), | |||
488 | pUndoDoc ( std::move(pNewUndoDoc) ), | |||
489 | eFillDir ( eNewFillDir ), | |||
490 | eFillCmd ( eNewFillCmd ), | |||
491 | eFillDateCmd ( eNewFillDateCmd ), | |||
492 | fStartValue ( fNewStartValue ), | |||
493 | fStepValue ( fNewStepValue ), | |||
494 | fMaxValue ( fNewMaxValue ) | |||
495 | { | |||
496 | SetChangeTrack(); | |||
497 | } | |||
498 | ||||
499 | ScUndoAutoFill::~ScUndoAutoFill() | |||
500 | { | |||
501 | } | |||
502 | ||||
503 | OUString ScUndoAutoFill::GetComment() const | |||
504 | { | |||
505 | return ScResId( STR_UNDO_AUTOFILLreinterpret_cast<char const *>("STR_UNDO_AUTOFILL" "\004" u8"Fill") ); //"Fill" | |||
506 | } | |||
507 | ||||
508 | void ScUndoAutoFill::SetChangeTrack() | |||
509 | { | |||
510 | ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack(); | |||
511 | if ( pChangeTrack ) | |||
512 | pChangeTrack->AppendContentRange( aBlockRange, pUndoDoc.get(), | |||
513 | nStartChangeAction, nEndChangeAction ); | |||
514 | else | |||
515 | nStartChangeAction = nEndChangeAction = 0; | |||
516 | } | |||
517 | ||||
518 | void ScUndoAutoFill::Undo() | |||
519 | { | |||
520 | BeginUndo(); | |||
521 | ||||
522 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
523 | ||||
524 | SCTAB nTabCount = rDoc.GetTableCount(); | |||
525 | for (const auto& rTab : aMarkData) | |||
526 | { | |||
527 | if (rTab >= nTabCount) | |||
528 | break; | |||
529 | ScRange aWorkRange = aBlockRange; | |||
530 | aWorkRange.aStart.SetTab(rTab); | |||
531 | aWorkRange.aEnd.SetTab(rTab); | |||
532 | ||||
533 | sal_uInt16 nExtFlags = 0; | |||
534 | pDocShell->UpdatePaintExt( nExtFlags, aWorkRange ); | |||
535 | rDoc.DeleteAreaTab( aWorkRange, InsertDeleteFlags::AUTOFILL ); | |||
536 | pUndoDoc->CopyToDocument(aWorkRange, InsertDeleteFlags::AUTOFILL, false, rDoc); | |||
537 | ||||
538 | // Actually we'd only need to broadcast the cells inserted during | |||
539 | // CopyToDocument(), as DeleteAreaTab() broadcasts deleted cells. For | |||
540 | // this we'd need to either record the span sets or let | |||
541 | // CopyToDocument() broadcast. | |||
542 | BroadcastChanges( aWorkRange); | |||
543 | ||||
544 | rDoc.ExtendMerge( aWorkRange, true ); | |||
545 | pDocShell->PostPaint( aWorkRange, PaintPartFlags::Grid, nExtFlags ); | |||
546 | } | |||
547 | pDocShell->PostDataChanged(); | |||
548 | ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); | |||
549 | if (pViewShell) | |||
550 | pViewShell->CellContentChanged(); | |||
551 | ||||
552 | ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack(); | |||
553 | if ( pChangeTrack ) | |||
554 | pChangeTrack->Undo( nStartChangeAction, nEndChangeAction ); | |||
555 | ||||
556 | EndUndo(); | |||
557 | } | |||
558 | ||||
559 | void ScUndoAutoFill::Redo() | |||
560 | { | |||
561 | BeginRedo(); | |||
562 | ||||
563 | //! Select sheet | |||
564 | ||||
565 | SCCOLROW nCount = 0; | |||
566 | switch (eFillDir) | |||
567 | { | |||
568 | case FILL_TO_BOTTOM: | |||
569 | nCount = aBlockRange.aEnd.Row() - aSource.aEnd.Row(); | |||
570 | break; | |||
571 | case FILL_TO_RIGHT: | |||
572 | nCount = aBlockRange.aEnd.Col() - aSource.aEnd.Col(); | |||
573 | break; | |||
574 | case FILL_TO_TOP: | |||
575 | nCount = aSource.aStart.Row() - aBlockRange.aStart.Row(); | |||
576 | break; | |||
577 | case FILL_TO_LEFT: | |||
578 | nCount = aSource.aStart.Col() - aBlockRange.aStart.Col(); | |||
579 | break; | |||
580 | } | |||
581 | ||||
582 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
583 | if ( fStartValue != MAXDOUBLE1.7e307 ) | |||
584 | { | |||
585 | SCCOL nValX = (eFillDir == FILL_TO_LEFT) ? aSource.aEnd.Col() : aSource.aStart.Col(); | |||
586 | SCROW nValY = (eFillDir == FILL_TO_TOP ) ? aSource.aEnd.Row() : aSource.aStart.Row(); | |||
587 | SCTAB nTab = aSource.aStart.Tab(); | |||
588 | rDoc.SetValue( nValX, nValY, nTab, fStartValue ); | |||
589 | } | |||
590 | sal_uLong nProgCount; | |||
591 | if (eFillDir == FILL_TO_BOTTOM || eFillDir == FILL_TO_TOP) | |||
592 | nProgCount = aSource.aEnd.Col() - aSource.aStart.Col() + 1; | |||
593 | else | |||
594 | nProgCount = aSource.aEnd.Row() - aSource.aStart.Row() + 1; | |||
595 | nProgCount *= nCount; | |||
596 | ScProgress aProgress( rDoc.GetDocumentShell(), | |||
597 | ScResId(STR_FILL_SERIES_PROGRESSreinterpret_cast<char const *>("STR_FILL_SERIES_PROGRESS" "\004" u8"Fill Row...")), nProgCount, true ); | |||
598 | ||||
599 | rDoc.Fill( aSource.aStart.Col(), aSource.aStart.Row(), | |||
600 | aSource.aEnd.Col(), aSource.aEnd.Row(), &aProgress, | |||
601 | aMarkData, nCount, | |||
602 | eFillDir, eFillCmd, eFillDateCmd, | |||
603 | fStepValue, fMaxValue ); | |||
604 | ||||
605 | SetChangeTrack(); | |||
606 | ||||
607 | pDocShell->PostPaint( aBlockRange, PaintPartFlags::Grid ); | |||
608 | pDocShell->PostDataChanged(); | |||
609 | ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); | |||
610 | if (pViewShell) | |||
611 | pViewShell->CellContentChanged(); | |||
612 | ||||
613 | EndRedo(); | |||
614 | } | |||
615 | ||||
616 | void ScUndoAutoFill::Repeat(SfxRepeatTarget& rTarget) | |||
617 | { | |||
618 | if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr) | |||
619 | { | |||
620 | ScTabViewShell& rViewShell = *static_cast<ScTabViewTarget&>(rTarget).GetViewShell(); | |||
621 | if (eFillCmd==FILL_SIMPLE) | |||
622 | rViewShell.FillSimple( eFillDir ); | |||
623 | else | |||
624 | rViewShell.FillSeries( eFillDir, eFillCmd, eFillDateCmd, | |||
625 | fStartValue, fStepValue, fMaxValue ); | |||
626 | } | |||
627 | } | |||
628 | ||||
629 | bool ScUndoAutoFill::CanRepeat(SfxRepeatTarget& rTarget) const | |||
630 | { | |||
631 | return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr; | |||
632 | } | |||
633 | ||||
634 | ScUndoMerge::ScUndoMerge(ScDocShell* pNewDocShell, const ScCellMergeOption& rOption, | |||
635 | bool bMergeContents, ScDocumentUniquePtr pUndoDoc, std::unique_ptr<SdrUndoAction> pDrawUndo) | |||
636 | : ScSimpleUndo(pNewDocShell) | |||
637 | , maOption(rOption) | |||
638 | , mbMergeContents(bMergeContents) | |||
639 | , mxUndoDoc(std::move(pUndoDoc)) | |||
640 | , mpDrawUndo(std::move(pDrawUndo)) | |||
641 | { | |||
642 | } | |||
643 | ||||
644 | ScUndoMerge::~ScUndoMerge() | |||
645 | { | |||
646 | mpDrawUndo.reset(); | |||
647 | } | |||
648 | ||||
649 | OUString ScUndoMerge::GetComment() const | |||
650 | { | |||
651 | return ScResId( STR_UNDO_MERGEreinterpret_cast<char const *>("STR_UNDO_MERGE" "\004" u8"Merge" ) ); | |||
652 | } | |||
653 | ||||
654 | void ScUndoMerge::DoChange( bool bUndo ) const | |||
655 | { | |||
656 | using ::std::set; | |||
657 | ||||
658 | if (maOption.maTabs.empty()) | |||
659 | // Nothing to do. | |||
660 | return; | |||
661 | ||||
662 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
663 | ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); | |||
664 | ||||
665 | ScRange aCurRange = maOption.getSingleRange(ScDocShell::GetCurTab()); | |||
666 | ScUndoUtil::MarkSimpleBlock(pDocShell, aCurRange); | |||
667 | ||||
668 | for (const SCTAB nTab : maOption.maTabs) | |||
669 | { | |||
670 | ScRange aRange = maOption.getSingleRange(nTab); | |||
671 | ||||
672 | if (bUndo) | |||
673 | // remove merge (contents are copied back below from undo document) | |||
674 | rDoc.RemoveMerge( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aStart.Tab() ); | |||
675 | else | |||
676 | { | |||
677 | // repeat merge, but do not remove note captions (will be done by drawing redo below) | |||
678 | rDoc.DoMerge( aRange.aStart.Tab(), | |||
679 | aRange.aStart.Col(), aRange.aStart.Row(), | |||
680 | aRange.aEnd.Col(), aRange.aEnd.Row(), false ); | |||
681 | ||||
682 | if (maOption.mbCenter) | |||
683 | { | |||
684 | rDoc.ApplyAttr( aRange.aStart.Col(), aRange.aStart.Row(), | |||
685 | aRange.aStart.Tab(), | |||
686 | SvxHorJustifyItem( SvxCellHorJustify::Center, ATTR_HOR_JUSTIFY ) ); | |||
687 | rDoc.ApplyAttr( aRange.aStart.Col(), aRange.aStart.Row(), | |||
688 | aRange.aStart.Tab(), | |||
689 | SvxVerJustifyItem( SvxCellVerJustify::Center, ATTR_VER_JUSTIFY ) ); | |||
690 | } | |||
691 | } | |||
692 | ||||
693 | // undo -> copy back deleted contents | |||
694 | if (bUndo && mxUndoDoc) | |||
695 | { | |||
696 | // If there are note captions to be deleted during Undo they were | |||
697 | // kept or moved during the merge and copied to the Undo document | |||
698 | // without cloning the caption. Forget the target area's caption | |||
699 | // pointer that is identical to the one in the Undo document | |||
700 | // instead of deleting it. | |||
701 | rDoc.DeleteAreaTab( aRange, | |||
702 | InsertDeleteFlags::CONTENTS | InsertDeleteFlags::NOCAPTIONS | InsertDeleteFlags::FORGETCAPTIONS ); | |||
703 | mxUndoDoc->CopyToDocument(aRange, InsertDeleteFlags::ALL|InsertDeleteFlags::NOCAPTIONS, false, rDoc); | |||
704 | } | |||
705 | ||||
706 | // redo -> merge contents again | |||
707 | else if (!bUndo && mbMergeContents) | |||
708 | { | |||
709 | rDoc.DoMergeContents( aRange.aStart.Tab(), | |||
710 | aRange.aStart.Col(), aRange.aStart.Row(), | |||
711 | aRange.aEnd.Col(), aRange.aEnd.Row() ); | |||
712 | } | |||
713 | ||||
714 | if (bUndo) | |||
715 | DoSdrUndoAction( mpDrawUndo.get(), &rDoc ); | |||
716 | else | |||
717 | RedoSdrUndoAction( mpDrawUndo.get() ); | |||
718 | ||||
719 | bool bDidPaint = false; | |||
720 | if ( pViewShell ) | |||
721 | { | |||
722 | pViewShell->SetTabNo(nTab); | |||
723 | bDidPaint = pViewShell->AdjustRowHeight(maOption.mnStartRow, maOption.mnEndRow); | |||
724 | } | |||
725 | ||||
726 | if (!bDidPaint) | |||
727 | ScUndoUtil::PaintMore(pDocShell, aRange); | |||
728 | ||||
729 | rDoc.BroadcastCells(aRange, SfxHintId::ScDataChanged); | |||
730 | } | |||
731 | ||||
732 | ShowTable(aCurRange); | |||
733 | } | |||
734 | ||||
735 | void ScUndoMerge::Undo() | |||
736 | { | |||
737 | BeginUndo(); | |||
738 | DoChange( true ); | |||
739 | EndUndo(); | |||
740 | } | |||
741 | ||||
742 | void ScUndoMerge::Redo() | |||
743 | { | |||
744 | BeginRedo(); | |||
745 | DoChange( false ); | |||
746 | EndRedo(); | |||
747 | } | |||
748 | ||||
749 | void ScUndoMerge::Repeat(SfxRepeatTarget& rTarget) | |||
750 | { | |||
751 | if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr) | |||
752 | { | |||
753 | ScTabViewShell& rViewShell = *static_cast<ScTabViewTarget&>(rTarget).GetViewShell(); | |||
754 | bool bCont = false; | |||
755 | rViewShell.MergeCells( false, bCont, false ); | |||
756 | } | |||
757 | } | |||
758 | ||||
759 | bool ScUndoMerge::CanRepeat(SfxRepeatTarget& rTarget) const | |||
760 | { | |||
761 | return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr; | |||
762 | } | |||
763 | ||||
764 | ScUndoAutoFormat::ScUndoAutoFormat( ScDocShell* pNewDocShell, | |||
765 | const ScRange& rRange, ScDocumentUniquePtr pNewUndoDoc, | |||
766 | const ScMarkData& rMark, bool bNewSize, sal_uInt16 nNewFormatNo ) | |||
767 | : ScBlockUndo( pNewDocShell, rRange, bNewSize ? SC_UNDO_MANUALHEIGHT : SC_UNDO_AUTOHEIGHT ), | |||
768 | pUndoDoc ( std::move(pNewUndoDoc) ), | |||
769 | aMarkData ( rMark ), | |||
770 | bSize ( bNewSize ), | |||
771 | nFormatNo ( nNewFormatNo ) | |||
772 | { | |||
773 | } | |||
774 | ||||
775 | ScUndoAutoFormat::~ScUndoAutoFormat() | |||
776 | { | |||
777 | } | |||
778 | ||||
779 | OUString ScUndoAutoFormat::GetComment() const | |||
780 | { | |||
781 | return ScResId( STR_UNDO_AUTOFORMATreinterpret_cast<char const *>("STR_UNDO_AUTOFORMAT" "\004" u8"AutoFormat") ); //"Auto-Format" | |||
782 | } | |||
783 | ||||
784 | void ScUndoAutoFormat::Undo() | |||
785 | { | |||
786 | BeginUndo(); | |||
787 | ||||
788 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
789 | ||||
790 | SCTAB nTabCount = rDoc.GetTableCount(); | |||
791 | rDoc.DeleteArea( aBlockRange.aStart.Col(), aBlockRange.aStart.Row(), | |||
792 | aBlockRange.aEnd.Col(), aBlockRange.aEnd.Row(), | |||
793 | aMarkData, InsertDeleteFlags::ATTRIB ); | |||
794 | ScRange aCopyRange = aBlockRange; | |||
795 | aCopyRange.aStart.SetTab(0); | |||
796 | aCopyRange.aEnd.SetTab(nTabCount-1); | |||
797 | pUndoDoc->CopyToDocument(aCopyRange, InsertDeleteFlags::ATTRIB, false, rDoc, &aMarkData); | |||
798 | ||||
799 | // cell heights and widths (InsertDeleteFlags::NONE) | |||
800 | if (bSize) | |||
801 | { | |||
802 | SCCOL nStartX = aBlockRange.aStart.Col(); | |||
803 | SCROW nStartY = aBlockRange.aStart.Row(); | |||
804 | SCTAB nStartZ = aBlockRange.aStart.Tab(); | |||
805 | SCCOL nEndX = aBlockRange.aEnd.Col(); | |||
806 | SCROW nEndY = aBlockRange.aEnd.Row(); | |||
807 | SCTAB nEndZ = aBlockRange.aEnd.Tab(); | |||
808 | ||||
809 | pUndoDoc->CopyToDocument( nStartX, 0, 0, nEndX, rDoc.MaxRow(), nTabCount-1, | |||
810 | InsertDeleteFlags::NONE, false, rDoc, &aMarkData ); | |||
811 | pUndoDoc->CopyToDocument( 0, nStartY, 0, rDoc.MaxCol(), nEndY, nTabCount-1, | |||
812 | InsertDeleteFlags::NONE, false, rDoc, &aMarkData ); | |||
813 | pDocShell->PostPaint( 0, 0, nStartZ, rDoc.MaxCol(), rDoc.MaxRow(), nEndZ, | |||
814 | PaintPartFlags::Grid | PaintPartFlags::Left | PaintPartFlags::Top, SC_PF_LINES1 ); | |||
815 | } | |||
816 | else | |||
817 | pDocShell->PostPaint( aBlockRange, PaintPartFlags::Grid, SC_PF_LINES1 ); | |||
818 | ||||
819 | EndUndo(); | |||
820 | } | |||
821 | ||||
822 | void ScUndoAutoFormat::Redo() | |||
823 | { | |||
824 | BeginRedo(); | |||
825 | ||||
826 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
827 | ||||
828 | SCCOL nStartX = aBlockRange.aStart.Col(); | |||
829 | SCROW nStartY = aBlockRange.aStart.Row(); | |||
830 | SCTAB nStartZ = aBlockRange.aStart.Tab(); | |||
831 | SCCOL nEndX = aBlockRange.aEnd.Col(); | |||
832 | SCROW nEndY = aBlockRange.aEnd.Row(); | |||
833 | SCTAB nEndZ = aBlockRange.aEnd.Tab(); | |||
834 | ||||
835 | rDoc.AutoFormat( nStartX, nStartY, nEndX, nEndY, nFormatNo, aMarkData ); | |||
836 | ||||
837 | if (bSize) | |||
| ||||
838 | { | |||
839 | ScopedVclPtrInstance< VirtualDevice > pVirtDev; | |||
840 | Fraction aZoomX(1,1); | |||
841 | Fraction aZoomY = aZoomX; | |||
842 | double nPPTX,nPPTY; | |||
843 | ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); | |||
844 | if (pViewShell) | |||
845 | { | |||
846 | ScViewData& rData = pViewShell->GetViewData(); | |||
847 | nPPTX = rData.GetPPTX(); | |||
848 | nPPTY = rData.GetPPTY(); | |||
849 | aZoomX = rData.GetZoomX(); | |||
850 | aZoomY = rData.GetZoomY(); | |||
851 | } | |||
852 | else | |||
853 | { | |||
854 | // Keep zoom at 100 | |||
855 | nPPTX = ScGlobal::nScreenPPTX; | |||
856 | nPPTY = ScGlobal::nScreenPPTY; | |||
857 | } | |||
858 | ||||
859 | sc::RowHeightContext aCxt(rDoc.MaxRow(), nPPTX, nPPTY, aZoomX, aZoomY, pVirtDev); | |||
860 | for (SCTAB nTab=nStartZ; nTab<=nEndZ; nTab++) | |||
861 | { | |||
862 | ScMarkData aDestMark(rDoc.GetSheetLimits()); | |||
863 | aDestMark.SelectOneTable( nTab ); | |||
864 | aDestMark.SetMarkArea( ScRange( nStartX, nStartY, nTab, nEndX, nEndY, nTab ) ); | |||
865 | aDestMark.MarkToMulti(); | |||
866 | ||||
867 | // as SC_SIZE_VISOPT | |||
868 | for (SCROW nRow=nStartY; nRow<=nEndY; nRow++) | |||
869 | { | |||
870 | CRFlags nOld = rDoc.GetRowFlags(nRow,nTab); | |||
871 | bool bHidden = rDoc.RowHidden(nRow, nTab); | |||
872 | if ( !bHidden && ( nOld & CRFlags::ManualSize ) ) | |||
873 | rDoc.SetRowFlags( nRow, nTab, nOld & ~CRFlags::ManualSize ); | |||
874 | } | |||
875 | ||||
876 | bool bChanged = rDoc.SetOptimalHeight(aCxt, nStartY, nEndY, nTab); | |||
877 | ||||
878 | for (SCCOL nCol=nStartX; nCol<=nEndX; nCol++) | |||
879 | if (!rDoc.ColHidden(nCol, nTab)) | |||
880 | { | |||
881 | sal_uInt16 nThisSize = STD_EXTRA_WIDTH113 + rDoc.GetOptimalColWidth( nCol, nTab, | |||
882 | pVirtDev, nPPTX, nPPTY, aZoomX, aZoomY, false/*bFormula*/, | |||
883 | &aDestMark ); | |||
884 | rDoc.SetColWidth( nCol, nTab, nThisSize ); | |||
885 | rDoc.ShowCol( nCol, nTab, true ); | |||
886 | } | |||
887 | ||||
888 | // tdf#76183: recalculate objects' positions | |||
889 | if (bChanged) | |||
890 | rDoc.SetDrawPageSize(nTab); | |||
891 | } | |||
892 | ||||
893 | pDocShell->PostPaint( 0, 0, nStartZ, | |||
894 | rDoc.MaxCol(), rDoc.MaxRow(), nEndZ, | |||
895 | PaintPartFlags::Grid | PaintPartFlags::Left | PaintPartFlags::Top, SC_PF_LINES1); | |||
896 | } | |||
897 | else | |||
898 | pDocShell->PostPaint( aBlockRange, PaintPartFlags::Grid, SC_PF_LINES1 ); | |||
899 | ||||
900 | EndRedo(); | |||
901 | } | |||
902 | ||||
903 | void ScUndoAutoFormat::Repeat(SfxRepeatTarget& rTarget) | |||
904 | { | |||
905 | if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr) | |||
906 | static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->AutoFormat( nFormatNo ); | |||
907 | } | |||
908 | ||||
909 | bool ScUndoAutoFormat::CanRepeat(SfxRepeatTarget& rTarget) const | |||
910 | { | |||
911 | return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr; | |||
912 | } | |||
913 | ||||
914 | ScUndoReplace::ScUndoReplace( ScDocShell* pNewDocShell, const ScMarkData& rMark, | |||
915 | SCCOL nCurX, SCROW nCurY, SCTAB nCurZ, | |||
916 | const OUString& rNewUndoStr, ScDocumentUniquePtr pNewUndoDoc, | |||
917 | const SvxSearchItem* pItem ) | |||
918 | : ScSimpleUndo( pNewDocShell ), | |||
919 | aCursorPos ( nCurX, nCurY, nCurZ ), | |||
920 | aMarkData ( rMark ), | |||
921 | aUndoStr ( rNewUndoStr ), | |||
922 | pUndoDoc ( std::move(pNewUndoDoc) ) | |||
923 | { | |||
924 | pSearchItem.reset( new SvxSearchItem( *pItem ) ); | |||
925 | SetChangeTrack(); | |||
926 | } | |||
927 | ||||
928 | ScUndoReplace::~ScUndoReplace() | |||
929 | { | |||
930 | pUndoDoc.reset(); | |||
931 | pSearchItem.reset(); | |||
932 | } | |||
933 | ||||
934 | void ScUndoReplace::SetChangeTrack() | |||
935 | { | |||
936 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
937 | ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack(); | |||
938 | if ( pChangeTrack ) | |||
939 | { | |||
940 | if ( pUndoDoc ) | |||
941 | { //! UndoDoc includes only the changed cells, | |||
942 | // that is why an Iterator can be used | |||
943 | pChangeTrack->AppendContentsIfInRefDoc( *pUndoDoc, | |||
944 | nStartChangeAction, nEndChangeAction ); | |||
945 | } | |||
946 | else | |||
947 | { | |||
948 | nStartChangeAction = pChangeTrack->GetActionMax() + 1; | |||
949 | ScChangeActionContent* pContent = new ScChangeActionContent( | |||
950 | ScRange( aCursorPos) ); | |||
951 | ScCellValue aCell; | |||
952 | aCell.assign(rDoc, aCursorPos); | |||
953 | pContent->SetOldValue( aUndoStr, &rDoc ); | |||
954 | pContent->SetNewValue(aCell, &rDoc); | |||
955 | pChangeTrack->Append( pContent ); | |||
956 | nEndChangeAction = pChangeTrack->GetActionMax(); | |||
957 | } | |||
958 | } | |||
959 | else | |||
960 | nStartChangeAction = nEndChangeAction = 0; | |||
961 | } | |||
962 | ||||
963 | OUString ScUndoReplace::GetComment() const | |||
964 | { | |||
965 | return ScResId( STR_UNDO_REPLACEreinterpret_cast<char const *>("STR_UNDO_REPLACE" "\004" u8"Replace") ); // "Replace" | |||
966 | } | |||
967 | ||||
968 | void ScUndoReplace::Undo() | |||
969 | { | |||
970 | BeginUndo(); | |||
971 | ||||
972 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
973 | ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); | |||
974 | ||||
975 | ShowTable( aCursorPos.Tab() ); | |||
976 | ||||
977 | if (pUndoDoc) // only for ReplaceAll !! | |||
978 | { | |||
979 | OSL_ENSURE(pSearchItem->GetCommand() == SvxSearchCmd::REPLACE_ALL,do { if (true && (!(pSearchItem->GetCommand() == SvxSearchCmd ::REPLACE_ALL))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/undo/undoblk3.cxx" ":" "980" ": "), "%s", "ScUndoReplace:: Wrong Mode"); } } while (false) | |||
980 | "ScUndoReplace:: Wrong Mode")do { if (true && (!(pSearchItem->GetCommand() == SvxSearchCmd ::REPLACE_ALL))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/undo/undoblk3.cxx" ":" "980" ": "), "%s", "ScUndoReplace:: Wrong Mode"); } } while (false); | |||
981 | ||||
982 | SetViewMarkData( aMarkData ); | |||
983 | ||||
984 | //! selected sheet | |||
985 | //! select range ? | |||
986 | ||||
987 | // Undo document has no row/column information, thus copy with | |||
988 | // bColRowFlags = FALSE to not destroy Outline groups | |||
989 | ||||
990 | InsertDeleteFlags nUndoFlags = (pSearchItem->GetPattern()) ? InsertDeleteFlags::ATTRIB : InsertDeleteFlags::CONTENTS; | |||
991 | pUndoDoc->CopyToDocument( 0, 0, 0, | |||
992 | rDoc.MaxCol(), rDoc.MaxRow(), MAXTAB, | |||
993 | nUndoFlags, false, rDoc, nullptr, false ); // without row flags | |||
994 | pDocShell->PostPaintGridAll(); | |||
995 | } | |||
996 | else if (pSearchItem->GetPattern() && | |||
997 | pSearchItem->GetCommand() == SvxSearchCmd::REPLACE) | |||
998 | { | |||
999 | OUString aTempStr = pSearchItem->GetSearchString(); // toggle | |||
1000 | pSearchItem->SetSearchString(pSearchItem->GetReplaceString()); | |||
1001 | pSearchItem->SetReplaceString(aTempStr); | |||
1002 | rDoc.ReplaceStyle( *pSearchItem, | |||
1003 | aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), | |||
1004 | aMarkData); | |||
1005 | pSearchItem->SetReplaceString(pSearchItem->GetSearchString()); | |||
1006 | pSearchItem->SetSearchString(aTempStr); | |||
1007 | if (pViewShell) | |||
1008 | pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(), | |||
1009 | SC_FOLLOW_JUMP, false, false ); | |||
1010 | pDocShell->PostPaintGridAll(); | |||
1011 | } | |||
1012 | else if (pSearchItem->GetCellType() == SvxSearchCellType::NOTE) | |||
1013 | { | |||
1014 | ScPostIt* pNote = rDoc.GetNote(aCursorPos); | |||
1015 | OSL_ENSURE( pNote, "ScUndoReplace::Undo - cell does not contain a note" )do { if (true && (!(pNote))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/undo/undoblk3.cxx" ":" "1015" ": "), "%s", "ScUndoReplace::Undo - cell does not contain a note" ); } } while (false); | |||
1016 | if (pNote) | |||
1017 | pNote->SetText( aCursorPos, aUndoStr ); | |||
1018 | if (pViewShell) | |||
1019 | pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(), | |||
1020 | SC_FOLLOW_JUMP, false, false ); | |||
1021 | } | |||
1022 | else | |||
1023 | { | |||
1024 | // aUndoStr may contain line breaks | |||
1025 | if ( aUndoStr.indexOf('\n') != -1 ) | |||
1026 | { | |||
1027 | ScFieldEditEngine& rEngine = rDoc.GetEditEngine(); | |||
1028 | rEngine.SetTextCurrentDefaults(aUndoStr); | |||
1029 | rDoc.SetEditText(aCursorPos, rEngine.CreateTextObject()); | |||
1030 | } | |||
1031 | else | |||
1032 | rDoc.SetString( aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), aUndoStr ); | |||
1033 | if (pViewShell) | |||
1034 | pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(), | |||
1035 | SC_FOLLOW_JUMP, false, false ); | |||
1036 | pDocShell->PostPaintGridAll(); | |||
1037 | } | |||
1038 | ||||
1039 | ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack(); | |||
1040 | if ( pChangeTrack ) | |||
1041 | pChangeTrack->Undo( nStartChangeAction, nEndChangeAction ); | |||
1042 | ||||
1043 | EndUndo(); | |||
1044 | } | |||
1045 | ||||
1046 | void ScUndoReplace::Redo() | |||
1047 | { | |||
1048 | BeginRedo(); | |||
1049 | ||||
1050 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
1051 | ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); | |||
1052 | ||||
1053 | if (pViewShell) | |||
1054 | pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(), | |||
1055 | SC_FOLLOW_JUMP, false, false ); | |||
1056 | if (pUndoDoc) | |||
1057 | { | |||
1058 | if (pViewShell) | |||
1059 | { | |||
1060 | SetViewMarkData( aMarkData ); | |||
1061 | ||||
1062 | pViewShell->SearchAndReplace( pSearchItem.get(), false, true ); | |||
1063 | } | |||
1064 | } | |||
1065 | else if (pSearchItem->GetPattern() && | |||
1066 | pSearchItem->GetCommand() == SvxSearchCmd::REPLACE) | |||
1067 | { | |||
1068 | rDoc.ReplaceStyle( *pSearchItem, | |||
1069 | aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), | |||
1070 | aMarkData); | |||
1071 | pDocShell->PostPaintGridAll(); | |||
1072 | } | |||
1073 | else | |||
1074 | if (pViewShell) | |||
1075 | pViewShell->SearchAndReplace( pSearchItem.get(), false, true ); | |||
1076 | ||||
1077 | SetChangeTrack(); | |||
1078 | ||||
1079 | EndRedo(); | |||
1080 | } | |||
1081 | ||||
1082 | void ScUndoReplace::Repeat(SfxRepeatTarget& rTarget) | |||
1083 | { | |||
1084 | if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr) | |||
1085 | static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->SearchAndReplace( pSearchItem.get(), true, false ); | |||
1086 | } | |||
1087 | ||||
1088 | bool ScUndoReplace::CanRepeat(SfxRepeatTarget& rTarget) const | |||
1089 | { | |||
1090 | return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr; | |||
1091 | } | |||
1092 | ||||
1093 | // multi-operation (only simple blocks) | |||
1094 | ScUndoTabOp::ScUndoTabOp( ScDocShell* pNewDocShell, | |||
1095 | SCCOL nStartX, SCROW nStartY, SCTAB nStartZ, | |||
1096 | SCCOL nEndX, SCROW nEndY, SCTAB nEndZ, ScDocumentUniquePtr pNewUndoDoc, | |||
1097 | const ScRefAddress& rFormulaCell, | |||
1098 | const ScRefAddress& rFormulaEnd, | |||
1099 | const ScRefAddress& rRowCell, | |||
1100 | const ScRefAddress& rColCell, | |||
1101 | ScTabOpParam::Mode eMode ) | |||
1102 | : ScSimpleUndo( pNewDocShell ), | |||
1103 | aRange ( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ), | |||
1104 | pUndoDoc ( std::move(pNewUndoDoc) ), | |||
1105 | theFormulaCell ( rFormulaCell ), | |||
1106 | theFormulaEnd ( rFormulaEnd ), | |||
1107 | theRowCell ( rRowCell ), | |||
1108 | theColCell ( rColCell ), | |||
1109 | meMode(eMode) | |||
1110 | { | |||
1111 | } | |||
1112 | ||||
1113 | ScUndoTabOp::~ScUndoTabOp() | |||
1114 | { | |||
1115 | } | |||
1116 | ||||
1117 | OUString ScUndoTabOp::GetComment() const | |||
1118 | { | |||
1119 | return ScResId( STR_UNDO_TABOPreinterpret_cast<char const *>("STR_UNDO_TABOP" "\004" u8"Multiple operations" ) ); // "Multiple operation" | |||
1120 | } | |||
1121 | ||||
1122 | void ScUndoTabOp::Undo() | |||
1123 | { | |||
1124 | BeginUndo(); | |||
1125 | ||||
1126 | ScUndoUtil::MarkSimpleBlock( pDocShell, aRange ); | |||
1127 | ||||
1128 | sal_uInt16 nExtFlags = 0; | |||
1129 | pDocShell->UpdatePaintExt( nExtFlags, aRange ); | |||
1130 | ||||
1131 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
1132 | rDoc.DeleteAreaTab( aRange,InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE ); | |||
1133 | pUndoDoc->CopyToDocument( aRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, rDoc ); | |||
1134 | pDocShell->PostPaint( aRange, PaintPartFlags::Grid, nExtFlags ); | |||
1135 | pDocShell->PostDataChanged(); | |||
1136 | ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); | |||
1137 | if (pViewShell) | |||
1138 | pViewShell->CellContentChanged(); | |||
1139 | ||||
1140 | EndUndo(); | |||
1141 | } | |||
1142 | ||||
1143 | void ScUndoTabOp::Redo() | |||
1144 | { | |||
1145 | BeginRedo(); | |||
1146 | ||||
1147 | ScUndoUtil::MarkSimpleBlock( pDocShell, aRange ); | |||
1148 | ||||
1149 | ScTabOpParam aParam(theFormulaCell, theFormulaEnd, theRowCell, theColCell, meMode); | |||
1150 | ||||
1151 | ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); | |||
1152 | if (pViewShell) | |||
1153 | pViewShell->TabOp( aParam, false); | |||
1154 | ||||
1155 | EndRedo(); | |||
1156 | } | |||
1157 | ||||
1158 | void ScUndoTabOp::Repeat(SfxRepeatTarget& /* rTarget */) | |||
1159 | { | |||
1160 | } | |||
1161 | ||||
1162 | bool ScUndoTabOp::CanRepeat(SfxRepeatTarget& /* rTarget */) const | |||
1163 | { | |||
1164 | return false; | |||
1165 | } | |||
1166 | ||||
1167 | ScUndoConversion::ScUndoConversion( | |||
1168 | ScDocShell* pNewDocShell, const ScMarkData& rMark, | |||
1169 | SCCOL nCurX, SCROW nCurY, SCTAB nCurZ, ScDocumentUniquePtr pNewUndoDoc, | |||
1170 | SCCOL nNewX, SCROW nNewY, SCTAB nNewZ, ScDocumentUniquePtr pNewRedoDoc, | |||
1171 | const ScConversionParam& rConvParam ) : | |||
1172 | ScSimpleUndo( pNewDocShell ), | |||
1173 | aMarkData( rMark ), | |||
1174 | aCursorPos( nCurX, nCurY, nCurZ ), | |||
1175 | pUndoDoc( std::move(pNewUndoDoc) ), | |||
1176 | aNewCursorPos( nNewX, nNewY, nNewZ ), | |||
1177 | pRedoDoc( std::move(pNewRedoDoc) ), | |||
1178 | maConvParam( rConvParam ) | |||
1179 | { | |||
1180 | SetChangeTrack(); | |||
1181 | } | |||
1182 | ||||
1183 | ScUndoConversion::~ScUndoConversion() | |||
1184 | { | |||
1185 | pUndoDoc.reset(); | |||
1186 | pRedoDoc.reset(); | |||
1187 | } | |||
1188 | ||||
1189 | void ScUndoConversion::SetChangeTrack() | |||
1190 | { | |||
1191 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
1192 | ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack(); | |||
1193 | if ( pChangeTrack ) | |||
1194 | { | |||
1195 | if ( pUndoDoc ) | |||
1196 | pChangeTrack->AppendContentsIfInRefDoc( *pUndoDoc, | |||
1197 | nStartChangeAction, nEndChangeAction ); | |||
1198 | else | |||
1199 | { | |||
1200 | OSL_FAIL( "ScUndoConversion::SetChangeTrack: no UndoDoc" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/undo/undoblk3.cxx" ":" "1200" ": "), "%s", "ScUndoConversion::SetChangeTrack: no UndoDoc" ); } } while (false); | |||
1201 | nStartChangeAction = nEndChangeAction = 0; | |||
1202 | } | |||
1203 | } | |||
1204 | else | |||
1205 | nStartChangeAction = nEndChangeAction = 0; | |||
1206 | } | |||
1207 | ||||
1208 | OUString ScUndoConversion::GetComment() const | |||
1209 | { | |||
1210 | OUString aText; | |||
1211 | switch( maConvParam.GetType() ) | |||
1212 | { | |||
1213 | case SC_CONVERSION_SPELLCHECK: aText = ScResId( STR_UNDO_SPELLINGreinterpret_cast<char const *>("STR_UNDO_SPELLING" "\004" u8"Spellcheck") ); break; | |||
1214 | case SC_CONVERSION_HANGULHANJA: aText = ScResId( STR_UNDO_HANGULHANJAreinterpret_cast<char const *>("STR_UNDO_HANGULHANJA" "\004" u8"Hangul/Hanja Conversion") ); break; | |||
1215 | case SC_CONVERSION_CHINESE_TRANSL: aText = ScResId( STR_UNDO_CHINESE_TRANSLATIONreinterpret_cast<char const *>("STR_UNDO_CHINESE_TRANSLATION" "\004" u8"Chinese conversion") ); break; | |||
1216 | default: OSL_FAIL( "ScUndoConversion::GetComment - unknown conversion type" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/undo/undoblk3.cxx" ":" "1216" ": "), "%s", "ScUndoConversion::GetComment - unknown conversion type" ); } } while (false); | |||
1217 | } | |||
1218 | return aText; | |||
1219 | } | |||
1220 | ||||
1221 | void ScUndoConversion::DoChange( ScDocument* pRefDoc, const ScAddress& rCursorPos ) | |||
1222 | { | |||
1223 | if (pRefDoc) | |||
1224 | { | |||
1225 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
1226 | ShowTable( rCursorPos.Tab() ); | |||
1227 | ||||
1228 | SetViewMarkData( aMarkData ); | |||
1229 | ||||
1230 | SCTAB nTabCount = rDoc.GetTableCount(); | |||
1231 | // Undo/Redo-doc has only selected tables | |||
1232 | ||||
1233 | bool bMulti = aMarkData.IsMultiMarked(); | |||
1234 | pRefDoc->CopyToDocument( 0, 0, 0, | |||
1235 | rDoc.MaxCol(), rDoc.MaxRow(), nTabCount-1, | |||
1236 | InsertDeleteFlags::CONTENTS, bMulti, rDoc, &aMarkData ); | |||
1237 | ||||
1238 | // Reset the spell checking results to re-check on paint, otherwise | |||
1239 | // we show the previous spelling markers (or lack thereof on misspellings). | |||
1240 | ScDocShell::GetViewData()->GetActiveWin()->ResetAutoSpell(); | |||
1241 | pDocShell->PostPaintGridAll(); | |||
1242 | } | |||
1243 | else | |||
1244 | { | |||
1245 | OSL_FAIL("no Un-/RedoDoc for Un-/RedoSpelling")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/undo/undoblk3.cxx" ":" "1245" ": "), "%s", "no Un-/RedoDoc for Un-/RedoSpelling" ); } } while (false); | |||
1246 | } | |||
1247 | } | |||
1248 | ||||
1249 | void ScUndoConversion::Undo() | |||
1250 | { | |||
1251 | BeginUndo(); | |||
1252 | DoChange( pUndoDoc.get(), aCursorPos ); | |||
1253 | ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack(); | |||
1254 | if ( pChangeTrack ) | |||
1255 | pChangeTrack->Undo( nStartChangeAction, nEndChangeAction ); | |||
1256 | EndUndo(); | |||
1257 | } | |||
1258 | ||||
1259 | void ScUndoConversion::Redo() | |||
1260 | { | |||
1261 | BeginRedo(); | |||
1262 | DoChange( pRedoDoc.get(), aNewCursorPos ); | |||
1263 | SetChangeTrack(); | |||
1264 | EndRedo(); | |||
1265 | } | |||
1266 | ||||
1267 | void ScUndoConversion::Repeat( SfxRepeatTarget& rTarget ) | |||
1268 | { | |||
1269 | if( dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr ) | |||
1270 | static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->DoSheetConversion( maConvParam ); | |||
1271 | } | |||
1272 | ||||
1273 | bool ScUndoConversion::CanRepeat(SfxRepeatTarget& rTarget) const | |||
1274 | { | |||
1275 | return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr; | |||
1276 | } | |||
1277 | ||||
1278 | ScUndoRefConversion::ScUndoRefConversion( ScDocShell* pNewDocShell, | |||
1279 | const ScRange& aMarkRange, const ScMarkData& rMark, | |||
1280 | ScDocumentUniquePtr pNewUndoDoc, ScDocumentUniquePtr pNewRedoDoc, bool bNewMulti) : | |||
1281 | ScSimpleUndo( pNewDocShell ), | |||
1282 | aMarkData ( rMark ), | |||
1283 | pUndoDoc ( std::move(pNewUndoDoc) ), | |||
1284 | pRedoDoc ( std::move(pNewRedoDoc) ), | |||
1285 | aRange ( aMarkRange ), | |||
1286 | bMulti ( bNewMulti ) | |||
1287 | { | |||
1288 | assert(pUndoDoc && pUndoDoc)(static_cast <bool> (pUndoDoc && pUndoDoc) ? void (0) : __assert_fail ("pUndoDoc && pUndoDoc", "/home/maarten/src/libreoffice/core/sc/source/ui/undo/undoblk3.cxx" , 1288, __extension__ __PRETTY_FUNCTION__)); | |||
1289 | SetChangeTrack(); | |||
1290 | } | |||
1291 | ||||
1292 | ScUndoRefConversion::~ScUndoRefConversion() | |||
1293 | { | |||
1294 | pUndoDoc.reset(); | |||
1295 | pRedoDoc.reset(); | |||
1296 | } | |||
1297 | ||||
1298 | OUString ScUndoRefConversion::GetComment() const | |||
1299 | { | |||
1300 | return ScResId( STR_UNDO_ENTERDATAreinterpret_cast<char const *>("STR_UNDO_ENTERDATA" "\004" u8"Input") ); // "Input" | |||
1301 | } | |||
1302 | ||||
1303 | void ScUndoRefConversion::SetChangeTrack() | |||
1304 | { | |||
1305 | ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack(); | |||
1306 | if ( pChangeTrack ) | |||
1307 | pChangeTrack->AppendContentsIfInRefDoc( *pUndoDoc, | |||
1308 | nStartChangeAction, nEndChangeAction ); | |||
1309 | else | |||
1310 | nStartChangeAction = nEndChangeAction = 0; | |||
1311 | } | |||
1312 | ||||
1313 | void ScUndoRefConversion::DoChange( ScDocument* pRefDoc) | |||
1314 | { | |||
1315 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
1316 | ||||
1317 | ShowTable(aRange); | |||
1318 | ||||
1319 | SetViewMarkData( aMarkData ); | |||
1320 | ||||
1321 | ScRange aCopyRange = aRange; | |||
1322 | SCTAB nTabCount = rDoc.GetTableCount(); | |||
1323 | aCopyRange.aStart.SetTab(0); | |||
1324 | aCopyRange.aEnd.SetTab(nTabCount-1); | |||
1325 | pRefDoc->CopyToDocument( aCopyRange, InsertDeleteFlags::ALL, bMulti, rDoc, &aMarkData ); | |||
1326 | pDocShell->PostPaint( aRange, PaintPartFlags::Grid); | |||
1327 | pDocShell->PostDataChanged(); | |||
1328 | ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); | |||
1329 | if (pViewShell) | |||
1330 | pViewShell->CellContentChanged(); | |||
1331 | } | |||
1332 | ||||
1333 | void ScUndoRefConversion::Undo() | |||
1334 | { | |||
1335 | BeginUndo(); | |||
1336 | if (pUndoDoc) | |||
1337 | DoChange(pUndoDoc.get()); | |||
1338 | ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack(); | |||
1339 | if ( pChangeTrack ) | |||
1340 | pChangeTrack->Undo( nStartChangeAction, nEndChangeAction ); | |||
1341 | EndUndo(); | |||
1342 | } | |||
1343 | ||||
1344 | void ScUndoRefConversion::Redo() | |||
1345 | { | |||
1346 | BeginRedo(); | |||
1347 | if (pRedoDoc) | |||
1348 | DoChange(pRedoDoc.get()); | |||
1349 | SetChangeTrack(); | |||
1350 | EndRedo(); | |||
1351 | } | |||
1352 | ||||
1353 | void ScUndoRefConversion::Repeat(SfxRepeatTarget& rTarget) | |||
1354 | { | |||
1355 | if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr) | |||
1356 | static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->DoRefConversion(); | |||
1357 | } | |||
1358 | ||||
1359 | bool ScUndoRefConversion::CanRepeat(SfxRepeatTarget& rTarget) const | |||
1360 | { | |||
1361 | return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr; | |||
1362 | } | |||
1363 | ||||
1364 | ScUndoRefreshLink::ScUndoRefreshLink(ScDocShell* pNewDocShell, | |||
1365 | ScDocumentUniquePtr pNewUndoDoc) | |||
1366 | : ScSimpleUndo(pNewDocShell) | |||
1367 | , xUndoDoc(std::move(pNewUndoDoc)) | |||
1368 | { | |||
1369 | } | |||
1370 | ||||
1371 | OUString ScUndoRefreshLink::GetComment() const | |||
1372 | { | |||
1373 | return ScResId( STR_UNDO_UPDATELINKreinterpret_cast<char const *>("STR_UNDO_UPDATELINK" "\004" u8"Update Link") ); | |||
1374 | } | |||
1375 | ||||
1376 | void ScUndoRefreshLink::Undo() | |||
1377 | { | |||
1378 | BeginUndo(); | |||
1379 | ||||
1380 | bool bMakeRedo = !xRedoDoc; | |||
1381 | if (bMakeRedo) | |||
1382 | xRedoDoc.reset(new ScDocument(SCDOCMODE_UNDO)); | |||
1383 | ||||
1384 | bool bFirst = true; | |||
1385 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
1386 | SCTAB nCount = rDoc.GetTableCount(); | |||
1387 | for (SCTAB nTab=0; nTab<nCount; nTab++) | |||
1388 | if (xUndoDoc->HasTable(nTab)) | |||
1389 | { | |||
1390 | ScRange aRange(0,0,nTab,rDoc.MaxCol(),rDoc.MaxRow(),nTab); | |||
1391 | if (bMakeRedo) | |||
1392 | { | |||
1393 | if (bFirst) | |||
1394 | xRedoDoc->InitUndo(rDoc, nTab, nTab, true, true); | |||
1395 | else | |||
1396 | xRedoDoc->AddUndoTab(nTab, nTab, true, true); | |||
1397 | bFirst = false; | |||
1398 | rDoc.CopyToDocument(aRange, InsertDeleteFlags::ALL, false, *xRedoDoc); | |||
1399 | xRedoDoc->SetLink(nTab, | |||
1400 | rDoc.GetLinkMode(nTab), | |||
1401 | rDoc.GetLinkDoc(nTab), | |||
1402 | rDoc.GetLinkFlt(nTab), | |||
1403 | rDoc.GetLinkOpt(nTab), | |||
1404 | rDoc.GetLinkTab(nTab), | |||
1405 | rDoc.GetLinkRefreshDelay(nTab)); | |||
1406 | xRedoDoc->SetTabBgColor( nTab, rDoc.GetTabBgColor(nTab) ); | |||
1407 | } | |||
1408 | ||||
1409 | rDoc.DeleteAreaTab( aRange,InsertDeleteFlags::ALL ); | |||
1410 | xUndoDoc->CopyToDocument(aRange, InsertDeleteFlags::ALL, false, rDoc); | |||
1411 | rDoc.SetLink(nTab, xUndoDoc->GetLinkMode(nTab), xUndoDoc->GetLinkDoc(nTab), | |||
1412 | xUndoDoc->GetLinkFlt(nTab), xUndoDoc->GetLinkOpt(nTab), | |||
1413 | xUndoDoc->GetLinkTab(nTab), | |||
1414 | xUndoDoc->GetLinkRefreshDelay(nTab) ); | |||
1415 | rDoc.SetTabBgColor(nTab, xUndoDoc->GetTabBgColor(nTab)); | |||
1416 | } | |||
1417 | ||||
1418 | pDocShell->PostPaintGridAll(); | |||
1419 | pDocShell->PostPaintExtras(); | |||
1420 | ||||
1421 | EndUndo(); | |||
1422 | } | |||
1423 | ||||
1424 | void ScUndoRefreshLink::Redo() | |||
1425 | { | |||
1426 | OSL_ENSURE(xRedoDoc, "No RedoDoc for ScUndoRefreshLink::Redo")do { if (true && (!(xRedoDoc))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/undo/undoblk3.cxx" ":" "1426" ": "), "%s", "No RedoDoc for ScUndoRefreshLink::Redo" ); } } while (false); | |||
1427 | ||||
1428 | BeginUndo(); | |||
1429 | ||||
1430 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
1431 | SCTAB nCount = rDoc.GetTableCount(); | |||
1432 | for (SCTAB nTab=0; nTab<nCount; nTab++) | |||
1433 | if (xRedoDoc->HasTable(nTab)) | |||
1434 | { | |||
1435 | ScRange aRange(0,0,nTab,rDoc.MaxCol(),rDoc.MaxRow(),nTab); | |||
1436 | ||||
1437 | rDoc.DeleteAreaTab( aRange, InsertDeleteFlags::ALL ); | |||
1438 | xRedoDoc->CopyToDocument(aRange, InsertDeleteFlags::ALL, false, rDoc); | |||
1439 | rDoc.SetLink(nTab, | |||
1440 | xRedoDoc->GetLinkMode(nTab), | |||
1441 | xRedoDoc->GetLinkDoc(nTab), | |||
1442 | xRedoDoc->GetLinkFlt(nTab), | |||
1443 | xRedoDoc->GetLinkOpt(nTab), | |||
1444 | xRedoDoc->GetLinkTab(nTab), | |||
1445 | xRedoDoc->GetLinkRefreshDelay(nTab) ); | |||
1446 | rDoc.SetTabBgColor(nTab, xRedoDoc->GetTabBgColor(nTab)); | |||
1447 | } | |||
1448 | ||||
1449 | pDocShell->PostPaintGridAll(); | |||
1450 | pDocShell->PostPaintExtras(); | |||
1451 | ||||
1452 | EndUndo(); | |||
1453 | } | |||
1454 | ||||
1455 | void ScUndoRefreshLink::Repeat(SfxRepeatTarget& /* rTarget */) | |||
1456 | { | |||
1457 | // makes no sense | |||
1458 | } | |||
1459 | ||||
1460 | bool ScUndoRefreshLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const | |||
1461 | { | |||
1462 | return false; | |||
1463 | } | |||
1464 | ||||
1465 | static ScAreaLink* lcl_FindAreaLink( const sfx2::LinkManager* pLinkManager, const OUString& rDoc, | |||
1466 | const OUString& rFlt, const OUString& rOpt, | |||
1467 | const OUString& rSrc, const ScRange& rDest ) | |||
1468 | { | |||
1469 | const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks(); | |||
1470 | sal_uInt16 nCount = pLinkManager->GetLinks().size(); | |||
1471 | for (sal_uInt16 i=0; i<nCount; i++) | |||
1472 | { | |||
1473 | ::sfx2::SvBaseLink* pBase = rLinks[i].get(); | |||
1474 | if (dynamic_cast<const ScAreaLink*>( pBase) != nullptr) | |||
1475 | if ( static_cast<ScAreaLink*>(pBase)->IsEqual( rDoc, rFlt, rOpt, rSrc, rDest ) ) | |||
1476 | return static_cast<ScAreaLink*>(pBase); | |||
1477 | } | |||
1478 | ||||
1479 | OSL_FAIL("ScAreaLink not found")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/undo/undoblk3.cxx" ":" "1479" ": "), "%s", "ScAreaLink not found"); } } while ( false); | |||
1480 | return nullptr; | |||
1481 | } | |||
1482 | ||||
1483 | ScUndoInsertAreaLink::ScUndoInsertAreaLink( ScDocShell* pShell, | |||
1484 | const OUString& rDoc, | |||
1485 | const OUString& rFlt, const OUString& rOpt, | |||
1486 | const OUString& rArea, const ScRange& rDestRange, | |||
1487 | sal_uLong nRefresh ) | |||
1488 | : ScSimpleUndo ( pShell ), | |||
1489 | aDocName ( rDoc ), | |||
1490 | aFltName ( rFlt ), | |||
1491 | aOptions ( rOpt ), | |||
1492 | aAreaName ( rArea ), | |||
1493 | aRange ( rDestRange ), | |||
1494 | nRefreshDelay ( nRefresh ) | |||
1495 | { | |||
1496 | } | |||
1497 | ||||
1498 | ScUndoInsertAreaLink::~ScUndoInsertAreaLink() | |||
1499 | { | |||
1500 | } | |||
1501 | ||||
1502 | OUString ScUndoInsertAreaLink::GetComment() const | |||
1503 | { | |||
1504 | return ScResId( STR_UNDO_INSERTAREALINKreinterpret_cast<char const *>("STR_UNDO_INSERTAREALINK" "\004" u8"Insert Link") ); | |||
1505 | } | |||
1506 | ||||
1507 | void ScUndoInsertAreaLink::Undo() | |||
1508 | { | |||
1509 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
1510 | sfx2::LinkManager* pLinkManager = rDoc.GetLinkManager(); | |||
1511 | ||||
1512 | ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aDocName, aFltName, aOptions, | |||
1513 | aAreaName, aRange ); | |||
1514 | if (pLink) | |||
1515 | pLinkManager->Remove( pLink ); | |||
1516 | ||||
1517 | SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScAreaLinksChanged ) ); // Navigator | |||
1518 | } | |||
1519 | ||||
1520 | void ScUndoInsertAreaLink::Redo() | |||
1521 | { | |||
1522 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
1523 | sfx2::LinkManager* pLinkManager = rDoc.GetLinkManager(); | |||
1524 | ||||
1525 | ScAreaLink* pLink = new ScAreaLink( pDocShell, aDocName, aFltName, aOptions, | |||
1526 | aAreaName, aRange.aStart, nRefreshDelay ); | |||
1527 | pLink->SetInCreate( true ); | |||
1528 | pLink->SetDestArea( aRange ); | |||
1529 | pLinkManager->InsertFileLink( *pLink, sfx2::SvBaseLinkObjectType::ClientFile, aDocName, &aFltName, &aAreaName ); | |||
1530 | pLink->Update(); | |||
1531 | pLink->SetInCreate( false ); | |||
1532 | ||||
1533 | SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScAreaLinksChanged ) ); // Navigator | |||
1534 | } | |||
1535 | ||||
1536 | void ScUndoInsertAreaLink::Repeat(SfxRepeatTarget& /* rTarget */) | |||
1537 | { | |||
1538 | // makes no sense | |||
1539 | } | |||
1540 | ||||
1541 | bool ScUndoInsertAreaLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const | |||
1542 | { | |||
1543 | return false; | |||
1544 | } | |||
1545 | ||||
1546 | ScUndoRemoveAreaLink::ScUndoRemoveAreaLink( ScDocShell* pShell, | |||
1547 | const OUString& rDoc, const OUString& rFlt, const OUString& rOpt, | |||
1548 | const OUString& rArea, const ScRange& rDestRange, | |||
1549 | sal_uLong nRefresh ) | |||
1550 | : ScSimpleUndo ( pShell ), | |||
1551 | aDocName ( rDoc ), | |||
1552 | aFltName ( rFlt ), | |||
1553 | aOptions ( rOpt ), | |||
1554 | aAreaName ( rArea ), | |||
1555 | aRange ( rDestRange ), | |||
1556 | nRefreshDelay ( nRefresh ) | |||
1557 | { | |||
1558 | } | |||
1559 | ||||
1560 | ScUndoRemoveAreaLink::~ScUndoRemoveAreaLink() | |||
1561 | { | |||
1562 | } | |||
1563 | ||||
1564 | OUString ScUndoRemoveAreaLink::GetComment() const | |||
1565 | { | |||
1566 | return ScResId( STR_UNDO_REMOVELINKreinterpret_cast<char const *>("STR_UNDO_REMOVELINK" "\004" u8"Unlink") ); //! own text ?? | |||
1567 | } | |||
1568 | ||||
1569 | void ScUndoRemoveAreaLink::Undo() | |||
1570 | { | |||
1571 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
1572 | sfx2::LinkManager* pLinkManager = rDoc.GetLinkManager(); | |||
1573 | ||||
1574 | ScAreaLink* pLink = new ScAreaLink( pDocShell, aDocName, aFltName, aOptions, | |||
1575 | aAreaName, aRange.aStart, nRefreshDelay ); | |||
1576 | pLink->SetInCreate( true ); | |||
1577 | pLink->SetDestArea( aRange ); | |||
1578 | pLinkManager->InsertFileLink( *pLink, sfx2::SvBaseLinkObjectType::ClientFile, aDocName, &aFltName, &aAreaName ); | |||
1579 | pLink->Update(); | |||
1580 | pLink->SetInCreate( false ); | |||
1581 | ||||
1582 | SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScAreaLinksChanged ) ); // Navigator | |||
1583 | } | |||
1584 | ||||
1585 | void ScUndoRemoveAreaLink::Redo() | |||
1586 | { | |||
1587 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
1588 | sfx2::LinkManager* pLinkManager = rDoc.GetLinkManager(); | |||
1589 | ||||
1590 | ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aDocName, aFltName, aOptions, | |||
1591 | aAreaName, aRange ); | |||
1592 | if (pLink) | |||
1593 | pLinkManager->Remove( pLink ); | |||
1594 | ||||
1595 | SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScAreaLinksChanged ) ); // Navigator | |||
1596 | } | |||
1597 | ||||
1598 | void ScUndoRemoveAreaLink::Repeat(SfxRepeatTarget& /* rTarget */) | |||
1599 | { | |||
1600 | // makes no sense | |||
1601 | } | |||
1602 | ||||
1603 | bool ScUndoRemoveAreaLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const | |||
1604 | { | |||
1605 | return false; | |||
1606 | } | |||
1607 | ||||
1608 | ScUndoUpdateAreaLink::ScUndoUpdateAreaLink( ScDocShell* pShell, | |||
1609 | const OUString& rOldD, const OUString& rOldF, const OUString& rOldO, | |||
1610 | const OUString& rOldA, const ScRange& rOldR, sal_uLong nOldRD, | |||
1611 | const OUString& rNewD, const OUString& rNewF, const OUString& rNewO, | |||
1612 | const OUString& rNewA, const ScRange& rNewR, sal_uLong nNewRD, | |||
1613 | ScDocumentUniquePtr pUndo, ScDocumentUniquePtr pRedo, bool bDoInsert ) | |||
1614 | : ScSimpleUndo( pShell ), | |||
1615 | aOldDoc ( rOldD ), | |||
1616 | aOldFlt ( rOldF ), | |||
1617 | aOldOpt ( rOldO ), | |||
1618 | aOldArea ( rOldA ), | |||
1619 | aOldRange ( rOldR ), | |||
1620 | aNewDoc ( rNewD ), | |||
1621 | aNewFlt ( rNewF ), | |||
1622 | aNewOpt ( rNewO ), | |||
1623 | aNewArea ( rNewA ), | |||
1624 | aNewRange ( rNewR ), | |||
1625 | xUndoDoc ( std::move(pUndo) ), | |||
1626 | xRedoDoc ( std::move(pRedo) ), | |||
1627 | nOldRefresh ( nOldRD ), | |||
1628 | nNewRefresh ( nNewRD ), | |||
1629 | bWithInsert ( bDoInsert ) | |||
1630 | { | |||
1631 | OSL_ENSURE( aOldRange.aStart == aNewRange.aStart, "AreaLink moved ?" )do { if (true && (!(aOldRange.aStart == aNewRange.aStart ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/sc/source/ui/undo/undoblk3.cxx" ":" "1631" ": "), "%s", "AreaLink moved ?"); } } while (false ); | |||
1632 | } | |||
1633 | ||||
1634 | OUString ScUndoUpdateAreaLink::GetComment() const | |||
1635 | { | |||
1636 | return ScResId( STR_UNDO_UPDATELINKreinterpret_cast<char const *>("STR_UNDO_UPDATELINK" "\004" u8"Update Link") ); //! own text ?? | |||
1637 | } | |||
1638 | ||||
1639 | void ScUndoUpdateAreaLink::DoChange( const bool bUndo ) const | |||
1640 | { | |||
1641 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
1642 | ||||
1643 | SCCOL nEndX = std::max( aOldRange.aEnd.Col(), aNewRange.aEnd.Col() ); | |||
1644 | SCROW nEndY = std::max( aOldRange.aEnd.Row(), aNewRange.aEnd.Row() ); | |||
1645 | SCTAB nEndZ = std::max( aOldRange.aEnd.Tab(), aNewRange.aEnd.Tab() ); //? | |||
1646 | ||||
1647 | if ( bUndo ) | |||
1648 | { | |||
1649 | if ( bWithInsert ) | |||
1650 | { | |||
1651 | rDoc.FitBlock( aNewRange, aOldRange ); | |||
1652 | rDoc.DeleteAreaTab( aOldRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE ); | |||
1653 | xUndoDoc->UndoToDocument(aOldRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, rDoc); | |||
1654 | } | |||
1655 | else | |||
1656 | { | |||
1657 | ScRange aCopyRange( aOldRange.aStart, ScAddress(nEndX,nEndY,nEndZ) ); | |||
1658 | rDoc.DeleteAreaTab( aCopyRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE ); | |||
1659 | xUndoDoc->CopyToDocument(aCopyRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, rDoc); | |||
1660 | } | |||
1661 | } | |||
1662 | else | |||
1663 | { | |||
1664 | if ( bWithInsert ) | |||
1665 | { | |||
1666 | rDoc.FitBlock( aOldRange, aNewRange ); | |||
1667 | rDoc.DeleteAreaTab( aNewRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE ); | |||
1668 | xRedoDoc->CopyToDocument(aNewRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, rDoc); | |||
1669 | } | |||
1670 | else | |||
1671 | { | |||
1672 | ScRange aCopyRange( aOldRange.aStart, ScAddress(nEndX,nEndY,nEndZ) ); | |||
1673 | rDoc.DeleteAreaTab( aCopyRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE ); | |||
1674 | xRedoDoc->CopyToDocument(aCopyRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, rDoc); | |||
1675 | } | |||
1676 | } | |||
1677 | ||||
1678 | ScRange aWorkRange( aNewRange.aStart, ScAddress( nEndX, nEndY, nEndZ ) ); | |||
1679 | rDoc.ExtendMerge( aWorkRange, true ); | |||
1680 | ||||
1681 | // Paint | |||
1682 | ||||
1683 | if ( aNewRange.aEnd.Col() != aOldRange.aEnd.Col() ) | |||
1684 | aWorkRange.aEnd.SetCol(rDoc.MaxCol()); | |||
1685 | if ( aNewRange.aEnd.Row() != aOldRange.aEnd.Row() ) | |||
1686 | aWorkRange.aEnd.SetRow(rDoc.MaxRow()); | |||
1687 | ||||
1688 | if ( !pDocShell->AdjustRowHeight( aWorkRange.aStart.Row(), aWorkRange.aEnd.Row(), aWorkRange.aStart.Tab() ) ) | |||
1689 | pDocShell->PostPaint( aWorkRange, PaintPartFlags::Grid ); | |||
1690 | ||||
1691 | pDocShell->PostDataChanged(); | |||
1692 | ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); | |||
1693 | if (pViewShell) | |||
1694 | pViewShell->CellContentChanged(); | |||
1695 | } | |||
1696 | ||||
1697 | void ScUndoUpdateAreaLink::Undo() | |||
1698 | { | |||
1699 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
1700 | sfx2::LinkManager* pLinkManager = rDoc.GetLinkManager(); | |||
1701 | ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aNewDoc, aNewFlt, aNewOpt, | |||
1702 | aNewArea, aNewRange ); | |||
1703 | if (pLink) | |||
1704 | { | |||
1705 | pLink->SetSource( aOldDoc, aOldFlt, aOldOpt, aOldArea ); // old data in Link | |||
1706 | pLink->SetDestArea( aOldRange ); | |||
1707 | pLink->SetRefreshDelay( nOldRefresh ); | |||
1708 | } | |||
1709 | ||||
1710 | DoChange(true); | |||
1711 | } | |||
1712 | ||||
1713 | void ScUndoUpdateAreaLink::Redo() | |||
1714 | { | |||
1715 | ScDocument& rDoc = pDocShell->GetDocument(); | |||
1716 | sfx2::LinkManager* pLinkManager = rDoc.GetLinkManager(); | |||
1717 | ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aOldDoc, aOldFlt, aOldOpt, | |||
1718 | aOldArea, aOldRange ); | |||
1719 | if (pLink) | |||
1720 | { | |||
1721 | pLink->SetSource( aNewDoc, aNewFlt, aNewOpt, aNewArea ); // new values in link | |||
1722 | pLink->SetDestArea( aNewRange ); | |||
1723 | pLink->SetRefreshDelay( nNewRefresh ); | |||
1724 | } | |||
1725 | ||||
1726 | DoChange(false); | |||
1727 | } | |||
1728 | ||||
1729 | void ScUndoUpdateAreaLink::Repeat(SfxRepeatTarget& /* rTarget */) | |||
1730 | { | |||
1731 | // makes no sense | |||
1732 | } | |||
1733 | ||||
1734 | bool ScUndoUpdateAreaLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const | |||
1735 | { | |||
1736 | return false; | |||
1737 | } | |||
1738 | ||||
1739 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_VCL_PTR_HXX |
21 | #define INCLUDED_VCL_PTR_HXX |
22 | |
23 | #include <sal/config.h> |
24 | |
25 | #include <rtl/ref.hxx> |
26 | |
27 | #include <utility> |
28 | #include <type_traits> |
29 | |
30 | #ifdef DBG_UTIL |
31 | #ifndef _WIN32 |
32 | #include <vcl/vclmain.hxx> |
33 | #endif |
34 | #endif |
35 | |
36 | class VclReferenceBase; |
37 | |
38 | namespace vcl::detail { |
39 | |
40 | template<typename> |
41 | constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; } |
42 | |
43 | template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase( |
44 | int (*)[sizeof(T)]) |
45 | { return std::is_base_of<VclReferenceBase, T>::value; } |
46 | |
47 | } // namespace vcl::detail |
48 | |
49 | /** |
50 | * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses. |
51 | * |
52 | * For more details on the design please see vcl/README.lifecycle |
53 | * |
54 | * @param reference_type must be a subclass of vcl::Window |
55 | */ |
56 | template <class reference_type> |
57 | class VclPtr |
58 | { |
59 | static_assert( |
60 | vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>( |
61 | nullptr), |
62 | "template argument type must be derived from VclReferenceBase"); |
63 | |
64 | ::rtl::Reference<reference_type> m_rInnerRef; |
65 | |
66 | public: |
67 | /** Constructor... |
68 | */ |
69 | VclPtr() |
70 | : m_rInnerRef() |
71 | {} |
72 | |
73 | /** Constructor... |
74 | */ |
75 | VclPtr (reference_type * pBody) |
76 | : m_rInnerRef(pBody) |
77 | {} |
78 | |
79 | /** Constructor... that doesn't take a ref. |
80 | */ |
81 | VclPtr (reference_type * pBody, __sal_NoAcquire) |
82 | : m_rInnerRef(pBody, SAL_NO_ACQUIRE) |
83 | {} |
84 | |
85 | /** Up-casting conversion constructor: Copies interface reference. |
86 | |
87 | Does not work for up-casts to ambiguous bases. For the special case of |
88 | up-casting to Reference< XInterface >, see the corresponding conversion |
89 | operator. |
90 | |
91 | @param rRef another reference |
92 | */ |
93 | template< class derived_type > |
94 | VclPtr( |
95 | const VclPtr< derived_type > & rRef, |
96 | typename std::enable_if< |
97 | std::is_base_of<reference_type, derived_type>::value, int>::type |
98 | = 0 ) |
99 | : m_rInnerRef( static_cast<reference_type*>(rRef) ) |
100 | { |
101 | } |
102 | |
103 | #if defined(DBG_UTIL) && !defined(_WIN32) |
104 | virtual ~VclPtr() |
105 | { |
106 | assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain ::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 106, __extension__ __PRETTY_FUNCTION__)); |
107 | // We can be one of the intermediate counts, but if we are the last |
108 | // VclPtr keeping this object alive, then something forgot to call dispose(). |
109 | assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)) |
110 | && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)); |
111 | } |
112 | VclPtr(VclPtr const &) = default; |
113 | VclPtr(VclPtr &&) = default; |
114 | VclPtr & operator =(VclPtr const &) = default; |
115 | VclPtr & operator =(VclPtr &&) = default; |
116 | #endif |
117 | |
118 | /** |
119 | * A construction helper for VclPtr. Since VclPtr types are created |
120 | * with a reference-count of one - to help fit into the existing |
121 | * code-flow; this helps us to construct them easily. |
122 | * |
123 | * For more details on the design please see vcl/README.lifecycle |
124 | * |
125 | * @tparam reference_type must be a subclass of vcl::Window |
126 | */ |
127 | template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg) |
128 | { |
129 | return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ); |
130 | } |
131 | |
132 | /** Probably most common used: handle->someBodyOp(). |
133 | */ |
134 | reference_type * operator->() const |
135 | { |
136 | return m_rInnerRef.get(); |
137 | } |
138 | |
139 | /** Get the body. Can be used instead of operator->(). |
140 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() |
141 | are the same. |
142 | */ |
143 | reference_type * get() const |
144 | { |
145 | return m_rInnerRef.get(); |
146 | } |
147 | |
148 | void set(reference_type *pBody) |
149 | { |
150 | m_rInnerRef.set(pBody); |
151 | } |
152 | |
153 | void reset(reference_type *pBody) |
154 | { |
155 | m_rInnerRef.set(pBody); |
156 | } |
157 | |
158 | /** Up-casting copy assignment operator. |
159 | |
160 | Does not work for up-casts to ambiguous bases. |
161 | |
162 | @param rRef another reference |
163 | */ |
164 | template<typename derived_type> |
165 | typename std::enable_if< |
166 | std::is_base_of<reference_type, derived_type>::value, |
167 | VclPtr &>::type |
168 | operator =(VclPtr<derived_type> const & rRef) |
169 | { |
170 | m_rInnerRef.set(rRef.get()); |
171 | return *this; |
172 | } |
173 | |
174 | VclPtr & operator =(reference_type * pBody) |
175 | { |
176 | m_rInnerRef.set(pBody); |
177 | return *this; |
178 | } |
179 | |
180 | operator reference_type * () const |
181 | { |
182 | return m_rInnerRef.get(); |
183 | } |
184 | |
185 | explicit operator bool () const |
186 | { |
187 | return m_rInnerRef.get() != nullptr; |
188 | } |
189 | |
190 | void clear() |
191 | { |
192 | m_rInnerRef.clear(); |
193 | } |
194 | |
195 | void reset() |
196 | { |
197 | m_rInnerRef.clear(); |
198 | } |
199 | |
200 | void disposeAndClear() |
201 | { |
202 | // hold it alive for the lifetime of this method |
203 | ::rtl::Reference<reference_type> aTmp(m_rInnerRef); |
204 | m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-) |
205 | if (aTmp.get()) { |
206 | aTmp->disposeOnce(); |
207 | } |
208 | } |
209 | |
210 | /** Needed to place VclPtr's into STL collection. |
211 | */ |
212 | bool operator< (const VclPtr<reference_type> & handle) const |
213 | { |
214 | return (m_rInnerRef < handle.m_rInnerRef); |
215 | } |
216 | }; // class VclPtr |
217 | |
218 | template<typename T1, typename T2> |
219 | inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
220 | return p1.get() == p2.get(); |
221 | } |
222 | |
223 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2) |
224 | { |
225 | return p1.get() == p2; |
226 | } |
227 | |
228 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) { |
229 | return p1.get() == p2; |
230 | } |
231 | |
232 | template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2) |
233 | { |
234 | return p1 == p2.get(); |
235 | } |
236 | |
237 | template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) { |
238 | return p1 == p2.get(); |
239 | } |
240 | |
241 | template<typename T1, typename T2> |
242 | inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
243 | return !(p1 == p2); |
244 | } |
245 | |
246 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2) |
247 | { |
248 | return !(p1 == p2); |
249 | } |
250 | |
251 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) { |
252 | return !(p1 == p2); |
253 | } |
254 | |
255 | template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2) |
256 | { |
257 | return !(p1 == p2); |
258 | } |
259 | |
260 | template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) { |
261 | return !(p1 == p2); |
262 | } |
263 | |
264 | /** |
265 | * A construction helper for a temporary VclPtr. Since VclPtr types |
266 | * are created with a reference-count of one - to help fit into |
267 | * the existing code-flow; this helps us to construct them easily. |
268 | * see also VclPtr::Create and ScopedVclPtr |
269 | * |
270 | * For more details on the design please see vcl/README.lifecycle |
271 | * |
272 | * @param reference_type must be a subclass of vcl::Window |
273 | */ |
274 | template <class reference_type> |
275 | class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type> |
276 | { |
277 | public: |
278 | template<typename... Arg> VclPtrInstance(Arg &&... arg) |
279 | : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
280 | { |
281 | } |
282 | |
283 | /** |
284 | * Override and disallow this, to prevent people accidentally calling it and actually |
285 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
286 | */ |
287 | template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete; |
288 | }; |
289 | |
290 | template <class reference_type> |
291 | class ScopedVclPtr : public VclPtr<reference_type> |
292 | { |
293 | public: |
294 | /** Constructor... |
295 | */ |
296 | ScopedVclPtr() |
297 | : VclPtr<reference_type>() |
298 | {} |
299 | |
300 | /** Constructor |
301 | */ |
302 | ScopedVclPtr (reference_type * pBody) |
303 | : VclPtr<reference_type>(pBody) |
304 | {} |
305 | |
306 | /** Copy constructor... |
307 | */ |
308 | ScopedVclPtr (const VclPtr<reference_type> & handle) |
309 | : VclPtr<reference_type>(handle) |
310 | {} |
311 | |
312 | /** |
313 | Assignment that releases the last reference. |
314 | */ |
315 | void disposeAndReset(reference_type *pBody) |
316 | { |
317 | if (pBody != this->get()) { |
318 | VclPtr<reference_type>::disposeAndClear(); |
319 | VclPtr<reference_type>::set(pBody); |
320 | } |
321 | } |
322 | |
323 | /** |
324 | Assignment that releases the last reference. |
325 | */ |
326 | ScopedVclPtr<reference_type>& operator = (reference_type * pBody) |
327 | { |
328 | disposeAndReset(pBody); |
329 | return *this; |
330 | } |
331 | |
332 | /** Up-casting conversion constructor: Copies interface reference. |
333 | |
334 | Does not work for up-casts to ambiguous bases. For the special case of |
335 | up-casting to Reference< XInterface >, see the corresponding conversion |
336 | operator. |
337 | |
338 | @param rRef another reference |
339 | */ |
340 | template< class derived_type > |
341 | ScopedVclPtr( |
342 | const VclPtr< derived_type > & rRef, |
343 | typename std::enable_if< |
344 | std::is_base_of<reference_type, derived_type>::value, int>::type |
345 | = 0 ) |
346 | : VclPtr<reference_type>( rRef ) |
347 | { |
348 | } |
349 | |
350 | /** Up-casting assignment operator. |
351 | |
352 | Does not work for up-casts to ambiguous bases. |
353 | |
354 | @param rRef another VclPtr |
355 | */ |
356 | template<typename derived_type> |
357 | typename std::enable_if< |
358 | std::is_base_of<reference_type, derived_type>::value, |
359 | ScopedVclPtr &>::type |
360 | operator =(VclPtr<derived_type> const & rRef) |
361 | { |
362 | disposeAndReset(rRef.get()); |
363 | return *this; |
364 | } |
365 | |
366 | /** |
367 | * Override and disallow this, to prevent people accidentally calling it and actually |
368 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
369 | */ |
370 | template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete; |
371 | |
372 | ~ScopedVclPtr() |
373 | { |
374 | VclPtr<reference_type>::disposeAndClear(); |
375 | assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get( ) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 375, __extension__ __PRETTY_FUNCTION__)); // make sure there are no lingering references |
376 | } |
377 | |
378 | private: |
379 | // Most likely we don't want this default copy-constructor. |
380 | ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete; |
381 | // And certainly we don't want a default assignment operator. |
382 | ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete; |
383 | // And disallow reset as that doesn't call disposeAndClear on the original reference |
384 | void reset() = delete; |
385 | void reset(reference_type *pBody) = delete; |
386 | |
387 | protected: |
388 | ScopedVclPtr (reference_type * pBody, __sal_NoAcquire) |
389 | : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE) |
390 | {} |
391 | }; |
392 | |
393 | /** |
394 | * A construction helper for ScopedVclPtr. Since VclPtr types are created |
395 | * with a reference-count of one - to help fit into the existing |
396 | * code-flow; this helps us to construct them easily. |
397 | * |
398 | * For more details on the design please see vcl/README.lifecycle |
399 | * |
400 | * @param reference_type must be a subclass of vcl::Window |
401 | */ |
402 | #if defined _MSC_VER |
403 | #pragma warning(push) |
404 | #pragma warning(disable: 4521) // " multiple copy constructors specified" |
405 | #endif |
406 | template <class reference_type> |
407 | class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type> |
408 | { |
409 | public: |
410 | template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg) |
411 | : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
412 | { |
413 | } |
414 | |
415 | /** |
416 | * Override and disallow this, to prevent people accidentally calling it and actually |
417 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
418 | */ |
419 | template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete; |
420 | |
421 | private: |
422 | // Prevent the above perfect forwarding ctor from hijacking (accidental) |
423 | // attempts at ScopedVclPtrInstance copy construction (where the hijacking |
424 | // would typically lead to somewhat obscure error messages); both non-const |
425 | // and const variants are needed here, as the ScopedVclPtr base class has a |
426 | // const--variant copy ctor, so the implicitly declared copy ctor for |
427 | // ScopedVclPtrInstance would also be the const variant, so non-const copy |
428 | // construction attempts would be hijacked by the perfect forwarding ctor; |
429 | // but if we only declared a non-const variant here, the const variant would |
430 | // no longer be implicitly declared (as there would already be an explicitly |
431 | // declared copy ctor), so const copy construction attempts would then be |
432 | // hijacked by the perfect forwarding ctor: |
433 | ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete; |
434 | ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete; |
435 | }; |
436 | #if defined _MSC_VER |
437 | #pragma warning(pop) |
438 | #endif |
439 | |
440 | #endif // INCLUDED_VCL_PTR_HXX |
441 | |
442 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_RTL_REF_HXX | ||||||||
21 | #define INCLUDED_RTL_REF_HXX | ||||||||
22 | |||||||||
23 | #include "sal/config.h" | ||||||||
24 | |||||||||
25 | #include <cassert> | ||||||||
26 | #include <cstddef> | ||||||||
27 | #include <functional> | ||||||||
28 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
29 | #include <type_traits> | ||||||||
30 | #endif | ||||||||
31 | |||||||||
32 | #include "sal/types.h" | ||||||||
33 | |||||||||
34 | namespace rtl | ||||||||
35 | { | ||||||||
36 | |||||||||
37 | /** Template reference class for reference type. | ||||||||
38 | */ | ||||||||
39 | template <class reference_type> | ||||||||
40 | class Reference | ||||||||
41 | { | ||||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||||
43 | */ | ||||||||
44 | reference_type * m_pBody; | ||||||||
45 | |||||||||
46 | |||||||||
47 | public: | ||||||||
48 | /** Constructor... | ||||||||
49 | */ | ||||||||
50 | Reference() | ||||||||
51 | : m_pBody (NULL__null) | ||||||||
52 | {} | ||||||||
53 | |||||||||
54 | |||||||||
55 | /** Constructor... | ||||||||
56 | */ | ||||||||
57 | Reference (reference_type * pBody, __sal_NoAcquire) | ||||||||
58 | : m_pBody (pBody) | ||||||||
59 | { | ||||||||
60 | } | ||||||||
61 | |||||||||
62 | /** Constructor... | ||||||||
63 | */ | ||||||||
64 | Reference (reference_type * pBody) | ||||||||
65 | : m_pBody (pBody) | ||||||||
66 | { | ||||||||
67 | if (m_pBody) | ||||||||
68 | m_pBody->acquire(); | ||||||||
69 | } | ||||||||
70 | |||||||||
71 | /** Copy constructor... | ||||||||
72 | */ | ||||||||
73 | Reference (const Reference<reference_type> & handle) | ||||||||
74 | : m_pBody (handle.m_pBody) | ||||||||
75 | { | ||||||||
76 | if (m_pBody) | ||||||||
77 | m_pBody->acquire(); | ||||||||
78 | } | ||||||||
79 | |||||||||
80 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
81 | /** Move constructor... | ||||||||
82 | */ | ||||||||
83 | Reference (Reference<reference_type> && handle) noexcept | ||||||||
84 | : m_pBody (handle.m_pBody) | ||||||||
85 | { | ||||||||
86 | handle.m_pBody = nullptr; | ||||||||
87 | } | ||||||||
88 | #endif | ||||||||
89 | |||||||||
90 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
91 | /** Up-casting conversion constructor: Copies interface reference. | ||||||||
92 | |||||||||
93 | Does not work for up-casts to ambiguous bases. | ||||||||
94 | |||||||||
95 | @param rRef another reference | ||||||||
96 | */ | ||||||||
97 | template< class derived_type > | ||||||||
98 | inline Reference( | ||||||||
99 | const Reference< derived_type > & rRef, | ||||||||
100 | std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 ) | ||||||||
101 | : m_pBody (rRef.get()) | ||||||||
102 | { | ||||||||
103 | if (m_pBody) | ||||||||
104 | m_pBody->acquire(); | ||||||||
105 | } | ||||||||
106 | #endif | ||||||||
107 | |||||||||
108 | /** Destructor... | ||||||||
109 | */ | ||||||||
110 | ~Reference() COVERITY_NOEXCEPT_FALSE | ||||||||
111 | { | ||||||||
112 | if (m_pBody) | ||||||||
113 | m_pBody->release(); | ||||||||
114 | } | ||||||||
115 | |||||||||
116 | /** Set... | ||||||||
117 | Similar to assignment. | ||||||||
118 | */ | ||||||||
119 | Reference<reference_type> & | ||||||||
120 | SAL_CALL set (reference_type * pBody) | ||||||||
121 | { | ||||||||
122 | if (pBody) | ||||||||
123 | pBody->acquire(); | ||||||||
124 | reference_type * const pOld = m_pBody; | ||||||||
125 | m_pBody = pBody; | ||||||||
126 | if (pOld) | ||||||||
127 | pOld->release(); | ||||||||
128 | return *this; | ||||||||
129 | } | ||||||||
130 | |||||||||
131 | /** Assignment. | ||||||||
132 | Unbinds this instance from its body (if bound) and | ||||||||
133 | bind it to the body represented by the handle. | ||||||||
134 | */ | ||||||||
135 | Reference<reference_type> & | ||||||||
136 | SAL_CALL operator= (const Reference<reference_type> & handle) | ||||||||
137 | { | ||||||||
138 | return set( handle.m_pBody ); | ||||||||
139 | } | ||||||||
140 | |||||||||
141 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
142 | /** Assignment. | ||||||||
143 | * Unbinds this instance from its body (if bound), | ||||||||
144 | * bind it to the body represented by the handle, and | ||||||||
145 | * set the body represented by the handle to nullptr. | ||||||||
146 | */ | ||||||||
147 | Reference<reference_type> & | ||||||||
148 | operator= (Reference<reference_type> && handle) | ||||||||
149 | { | ||||||||
150 | // self-movement guts ourself | ||||||||
151 | if (m_pBody) | ||||||||
152 | m_pBody->release(); | ||||||||
153 | m_pBody = handle.m_pBody; | ||||||||
154 | handle.m_pBody = nullptr; | ||||||||
155 | return *this; | ||||||||
156 | } | ||||||||
157 | #endif | ||||||||
158 | |||||||||
159 | /** Assignment... | ||||||||
160 | */ | ||||||||
161 | Reference<reference_type> & | ||||||||
162 | SAL_CALL operator= (reference_type * pBody) | ||||||||
163 | { | ||||||||
164 | return set( pBody ); | ||||||||
165 | } | ||||||||
166 | |||||||||
167 | /** Unbind the body from this handle. | ||||||||
168 | Note that for a handle representing a large body, | ||||||||
169 | "handle.clear().set(new body());" _might_ | ||||||||
170 | perform a little bit better than "handle.set(new body());", | ||||||||
171 | since in the second case two large objects exist in memory | ||||||||
172 | (the old body and the new body). | ||||||||
173 | */ | ||||||||
174 | Reference<reference_type> & SAL_CALL clear() | ||||||||
175 | { | ||||||||
176 | if (m_pBody
| ||||||||
177 | { | ||||||||
178 | reference_type * const pOld = m_pBody; | ||||||||
179 | m_pBody = NULL__null; | ||||||||
180 | pOld->release(); | ||||||||
181 | } | ||||||||
182 | return *this; | ||||||||
183 | } | ||||||||
184 | |||||||||
185 | |||||||||
186 | /** Get the body. Can be used instead of operator->(). | ||||||||
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() | ||||||||
188 | are the same. | ||||||||
189 | */ | ||||||||
190 | reference_type * SAL_CALL get() const | ||||||||
191 | { | ||||||||
192 | return m_pBody; | ||||||||
| |||||||||
193 | } | ||||||||
194 | |||||||||
195 | |||||||||
196 | /** Probably most common used: handle->someBodyOp(). | ||||||||
197 | */ | ||||||||
198 | reference_type * SAL_CALL operator->() const | ||||||||
199 | { | ||||||||
200 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 200, __extension__ __PRETTY_FUNCTION__)); | ||||||||
201 | return m_pBody; | ||||||||
202 | } | ||||||||
203 | |||||||||
204 | |||||||||
205 | /** Allows (*handle).someBodyOp(). | ||||||||
206 | */ | ||||||||
207 | reference_type & SAL_CALL operator*() const | ||||||||
208 | { | ||||||||
209 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 209, __extension__ __PRETTY_FUNCTION__)); | ||||||||
210 | return *m_pBody; | ||||||||
211 | } | ||||||||
212 | |||||||||
213 | |||||||||
214 | /** Returns True if the handle does point to a valid body. | ||||||||
215 | */ | ||||||||
216 | bool SAL_CALL is() const | ||||||||
217 | { | ||||||||
218 | return (m_pBody != NULL__null); | ||||||||
219 | } | ||||||||
220 | |||||||||
221 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
222 | /** Returns True if the handle does point to a valid body. | ||||||||
223 | */ | ||||||||
224 | explicit operator bool() const | ||||||||
225 | { | ||||||||
226 | return is(); | ||||||||
227 | } | ||||||||
228 | #endif | ||||||||
229 | |||||||||
230 | /** Returns True if this points to pBody. | ||||||||
231 | */ | ||||||||
232 | bool SAL_CALL operator== (const reference_type * pBody) const | ||||||||
233 | { | ||||||||
234 | return (m_pBody == pBody); | ||||||||
235 | } | ||||||||
236 | |||||||||
237 | |||||||||
238 | /** Returns True if handle points to the same body. | ||||||||
239 | */ | ||||||||
240 | bool | ||||||||
241 | SAL_CALL operator== (const Reference<reference_type> & handle) const | ||||||||
242 | { | ||||||||
243 | return (m_pBody == handle.m_pBody); | ||||||||
244 | } | ||||||||
245 | |||||||||
246 | |||||||||
247 | /** Needed to place References into STL collection. | ||||||||
248 | */ | ||||||||
249 | bool | ||||||||
250 | SAL_CALL operator!= (const Reference<reference_type> & handle) const | ||||||||
251 | { | ||||||||
252 | return (m_pBody != handle.m_pBody); | ||||||||
253 | } | ||||||||
254 | |||||||||
255 | |||||||||
256 | /** Needed to place References into STL collection. | ||||||||
257 | */ | ||||||||
258 | bool | ||||||||
259 | SAL_CALL operator< (const Reference<reference_type> & handle) const | ||||||||
260 | { | ||||||||
261 | return (m_pBody < handle.m_pBody); | ||||||||
262 | } | ||||||||
263 | |||||||||
264 | |||||||||
265 | /** Needed to place References into STL collection. | ||||||||
266 | */ | ||||||||
267 | bool | ||||||||
268 | SAL_CALL operator> (const Reference<reference_type> & handle) const | ||||||||
269 | { | ||||||||
270 | return (m_pBody > handle.m_pBody); | ||||||||
271 | } | ||||||||
272 | }; | ||||||||
273 | |||||||||
274 | } // namespace rtl | ||||||||
275 | |||||||||
276 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
277 | namespace std | ||||||||
278 | { | ||||||||
279 | |||||||||
280 | /// @cond INTERNAL | ||||||||
281 | /** | ||||||||
282 | Make rtl::Reference hashable by default for use in STL containers. | ||||||||
283 | |||||||||
284 | @since LibreOffice 6.3 | ||||||||
285 | */ | ||||||||
286 | template<typename T> | ||||||||
287 | struct hash<::rtl::Reference<T>> | ||||||||
288 | { | ||||||||
289 | std::size_t operator()(::rtl::Reference<T> const & s) const | ||||||||
290 | { return std::size_t(s.get()); } | ||||||||
291 | }; | ||||||||
292 | /// @endcond | ||||||||
293 | |||||||||
294 | } | ||||||||
295 | |||||||||
296 | #endif | ||||||||
297 | |||||||||
298 | #endif /* ! INCLUDED_RTL_REF_HXX */ | ||||||||
299 | |||||||||
300 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_VCL_Reference_HXX |
20 | #define INCLUDED_VCL_Reference_HXX |
21 | |
22 | #include <vcl/dllapi.h> |
23 | #include <osl/interlck.h> |
24 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
32 | void acquire() const |
33 | { |
34 | osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1); |
35 | } |
36 | |
37 | void release() const |
38 | { |
39 | if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |