Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "unmovss.hxx"
22 : #include "DrawDocShell.hxx"
23 : #include "drawdoc.hxx"
24 : #include "stlsheet.hxx"
25 : #include "stlpool.hxx"
26 :
27 0 : SdMoveStyleSheetsUndoAction::SdMoveStyleSheetsUndoAction( SdDrawDocument* pTheDoc, SdStyleSheetVector& rTheStyles, bool bInserted)
28 : : SdUndoAction(pTheDoc)
29 0 : , mbMySheets( !bInserted )
30 : {
31 0 : maStyles.swap( rTheStyles );
32 :
33 0 : maListOfChildLists.resize( maStyles.size() );
34 : // create list with lists of style sheet children
35 0 : std::size_t i = 0;
36 0 : for(SdStyleSheetVector::iterator iter = maStyles.begin(); iter != maStyles.end(); ++iter )
37 : {
38 0 : maListOfChildLists[i++] = SdStyleSheetPool::CreateChildList( (*iter).get() );
39 : }
40 0 : }
41 :
42 0 : void SdMoveStyleSheetsUndoAction::Undo()
43 : {
44 0 : SfxStyleSheetBasePool* pPool = mpDoc->GetStyleSheetPool();
45 :
46 0 : if (mbMySheets)
47 : {
48 : // the styles have to be inserted in the pool
49 :
50 : // first insert all styles to the pool
51 0 : for(SdStyleSheetVector::iterator iter = maStyles.begin(); iter != maStyles.end(); ++iter )
52 : {
53 0 : pPool->Insert((*iter).get());
54 : }
55 :
56 : // now assign the children again
57 0 : std::vector< SdStyleSheetVector >::iterator childlistiter( maListOfChildLists.begin() );
58 0 : for(SdStyleSheetVector::iterator iter = maStyles.begin(); iter != maStyles.end(); ++iter, ++childlistiter )
59 : {
60 0 : OUString aParent((*iter)->GetName());
61 0 : for( SdStyleSheetVector::iterator childiter = (*childlistiter).begin(); childiter != (*childlistiter).end(); ++childiter )
62 : {
63 0 : (*childiter)->SetParent(aParent);
64 : }
65 0 : }
66 : }
67 : else
68 : {
69 : // remove the styles again from the pool
70 0 : for(SdStyleSheetVector::iterator iter = maStyles.begin(); iter != maStyles.end(); ++iter )
71 : {
72 0 : pPool->Remove((*iter).get());
73 : }
74 : }
75 0 : mbMySheets = !mbMySheets;
76 0 : }
77 :
78 0 : void SdMoveStyleSheetsUndoAction::Redo()
79 : {
80 0 : Undo();
81 0 : }
82 :
83 0 : SdMoveStyleSheetsUndoAction::~SdMoveStyleSheetsUndoAction()
84 : {
85 0 : }
86 :
87 0 : OUString SdMoveStyleSheetsUndoAction::GetComment() const
88 : {
89 0 : return OUString();
90 : }
91 :
92 :
93 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|