xref: /trunk/main/sd/source/ui/func/unmovss.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include "unmovss.hxx"
32 #include "DrawDocShell.hxx"
33 #include "drawdoc.hxx"
34 #include "stlsheet.hxx"
35 #include "stlpool.hxx"
36 
37 SdMoveStyleSheetsUndoAction::SdMoveStyleSheetsUndoAction( SdDrawDocument* pTheDoc, SdStyleSheetVector& rTheStyles, bool bInserted)
38 : SdUndoAction(pTheDoc)
39 , mbMySheets( !bInserted )
40 {
41     maStyles.swap( rTheStyles );
42 
43     maListOfChildLists.resize( maStyles.size() );
44     // Liste mit den Listen der StyleSheet-Kinder erstellen
45     std::size_t i = 0;
46     for(SdStyleSheetVector::iterator iter = maStyles.begin(); iter != maStyles.end(); iter++ )
47     {
48         maListOfChildLists[i++] = SdStyleSheetPool::CreateChildList( (*iter).get() );
49     }
50 }
51 
52 /*************************************************************************
53 |*
54 |* Undo()
55 |*
56 \************************************************************************/
57 
58 void SdMoveStyleSheetsUndoAction::Undo()
59 {
60     SfxStyleSheetBasePool* pPool  = mpDoc->GetStyleSheetPool();
61 
62     if (mbMySheets)
63     {
64         // the styles have to be inserted in the pool
65 
66         // first insert all styles to the pool
67         for(SdStyleSheetVector::iterator iter = maStyles.begin(); iter != maStyles.end(); iter++ )
68         {
69             pPool->Insert((*iter).get());
70         }
71 
72         // now assign the childs again
73         std::vector< SdStyleSheetVector >::iterator childlistiter( maListOfChildLists.begin() );
74         for(SdStyleSheetVector::iterator iter = maStyles.begin(); iter != maStyles.end(); iter++, childlistiter++ )
75         {
76             String aParent((*iter)->GetName());
77             for( SdStyleSheetVector::iterator childiter = (*childlistiter).begin(); childiter != (*childlistiter).end(); childiter++ )
78             {
79                 (*childiter)->SetParent(aParent);
80             }
81         }
82     }
83     else
84     {
85         // remove the styles again from the pool
86         for(SdStyleSheetVector::iterator iter = maStyles.begin(); iter != maStyles.end(); iter++ )
87         {
88             pPool->Remove((*iter).get());
89         }
90     }
91     mbMySheets = !mbMySheets;
92 }
93 
94 void SdMoveStyleSheetsUndoAction::Redo()
95 {
96     Undo();
97 }
98 
99 SdMoveStyleSheetsUndoAction::~SdMoveStyleSheetsUndoAction()
100 {
101 }
102 
103 String SdMoveStyleSheetsUndoAction::GetComment() const
104 {
105     return String();
106 }
107 
108 
109