1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <undoback.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(
38 const SfxItemSet
& rItemSet
)
39 : SdUndoAction(&rDoc
),
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
);
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
);
94 rItemSet
.ClearItem(XATTR_FILLSTYLE
);
98 void SdBackgroundObjUndoAction::restoreFillBitmap(SfxItemSet
&rItemSet
)
100 rItemSet
.Put(*mpFillBitmapItem
);
102 rItemSet
.Put(XFillStyleItem(css::drawing::FillStyle_BITMAP
));
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */