tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / sd / source / ui / func / undoback.cxx
blob768ca2ec2f1ac7c5c6e12aa68eedb474dfe5d459
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <memory>
21 #include <undoback.hxx>
23 #include <sdpage.hxx>
24 #include <sdresid.hxx>
25 #include <strings.hrc>
27 #include <com/sun/star/drawing/FillStyle.hpp>
29 #include <svl/itemset.hxx>
31 #include <svx/xdef.hxx>
32 #include <svx/xfillit0.hxx>
33 #include <svx/xbtmpit.hxx>
35 SdBackgroundObjUndoAction::SdBackgroundObjUndoAction(
36 SdDrawDocument& rDoc,
37 SdPage& rPage,
38 const SfxItemSet& rItemSet)
39 : SdUndoAction(&rDoc),
40 mrPage(rPage),
41 mpItemSet(std::make_unique<SfxItemSet>(rItemSet)),
42 mbHasFillBitmap(false)
44 OUString aString( SdResId( STR_UNDO_CHANGE_PAGEFORMAT ) );
45 SetComment( aString );
46 saveFillBitmap(*mpItemSet);
49 void SdBackgroundObjUndoAction::ImplRestoreBackgroundObj()
51 std::unique_ptr<SfxItemSet> pNew = std::make_unique<SfxItemSet>(mrPage.getSdrPageProperties().GetItemSet());
52 mrPage.getSdrPageProperties().ClearItem();
53 if (bool(mpFillBitmapItem))
54 restoreFillBitmap(*mpItemSet);
55 mpFillBitmapItem.reset();
56 mbHasFillBitmap = false;
57 mrPage.getSdrPageProperties().PutItemSet(*mpItemSet);
58 mpItemSet = std::move(pNew);
59 saveFillBitmap(*mpItemSet);
61 // tell the page that it's visualization has changed
62 mrPage.ActionChanged();
65 void SdBackgroundObjUndoAction::Undo()
67 ImplRestoreBackgroundObj();
70 void SdBackgroundObjUndoAction::Redo()
72 ImplRestoreBackgroundObj();
75 SdUndoAction* SdBackgroundObjUndoAction::Clone() const
77 std::unique_ptr<SdBackgroundObjUndoAction> pCopy = std::make_unique<SdBackgroundObjUndoAction>(*mpDoc, mrPage, *mpItemSet);
78 if (mpFillBitmapItem)
79 pCopy->mpFillBitmapItem.reset(mpFillBitmapItem->Clone());
80 pCopy->mbHasFillBitmap = mbHasFillBitmap;
81 return pCopy.release();
84 void SdBackgroundObjUndoAction::saveFillBitmap(SfxItemSet &rItemSet)
86 if (const XFillBitmapItem *pItem = rItemSet.GetItemIfSet(XATTR_FILLBITMAP, false))
87 mpFillBitmapItem.reset(pItem->Clone());
88 if (bool(mpFillBitmapItem))
90 if (const XFillStyleItem* pItem = rItemSet.GetItemIfSet(XATTR_FILLSTYLE, false))
91 mbHasFillBitmap = pItem->GetValue() == css::drawing::FillStyle_BITMAP;
92 rItemSet.ClearItem(XATTR_FILLBITMAP);
93 if (mbHasFillBitmap)
94 rItemSet.ClearItem(XATTR_FILLSTYLE);
98 void SdBackgroundObjUndoAction::restoreFillBitmap(SfxItemSet &rItemSet)
100 rItemSet.Put(*mpFillBitmapItem);
101 if (mbHasFillBitmap)
102 rItemSet.Put(XFillStyleItem(css::drawing::FillStyle_BITMAP));
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */