1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sd.hxx" 26 27 28 #include <svl/itemset.hxx> 29 #include <svl/style.hxx> 30 #include <svl/smplhint.hxx> 31 #include <svx/svdobj.hxx> 32 33 #include "unchss.hxx" 34 35 #include "strings.hrc" 36 #include "glob.hxx" 37 #include "sdresid.hxx" 38 #include "drawdoc.hxx" 39 #include "stlsheet.hxx" 40 #include "glob.hrc" 41 42 43 TYPEINIT1(StyleSheetUndoAction, SdUndoAction); 44 45 46 47 /************************************************************************* 48 |* 49 |* Konstruktor 50 |* 51 \************************************************************************/ 52 53 StyleSheetUndoAction::StyleSheetUndoAction(SdDrawDocument* pTheDoc, 54 SfxStyleSheet* pTheStyleSheet, 55 const SfxItemSet* pTheNewItemSet) : 56 SdUndoAction(pTheDoc) 57 { 58 DBG_ASSERT(pTheStyleSheet, "Undo ohne StyleSheet ???"); 59 pStyleSheet = pTheStyleSheet; 60 61 // ItemSets anlegen; Vorsicht, das neue koennte aus einem anderen Pool 62 // stammen, also mitsamt seinen Items clonen 63 pNewSet = new SfxItemSet((SfxItemPool&)SdrObject::GetGlobalDrawObjectItemPool(), pTheNewItemSet->GetRanges()); 64 pTheDoc->MigrateItemSet( pTheNewItemSet, pNewSet, pTheDoc ); 65 66 pOldSet = new SfxItemSet((SfxItemPool&)SdrObject::GetGlobalDrawObjectItemPool(),pStyleSheet->GetItemSet().GetRanges()); 67 pTheDoc->MigrateItemSet( &pStyleSheet->GetItemSet(), pOldSet, pTheDoc ); 68 69 aComment = String(SdResId(STR_UNDO_CHANGE_PRES_OBJECT)); 70 String aName(pStyleSheet->GetName()); 71 72 // Layoutnamen und Separator loeschen 73 String aSep( RTL_CONSTASCII_USTRINGPARAM( SD_LT_SEPARATOR ) ); 74 sal_uInt16 nPos = aName.Search(aSep); 75 if( nPos != STRING_NOTFOUND ) 76 aName.Erase(0, nPos + aSep.Len()); 77 78 if (aName == String(SdResId(STR_LAYOUT_TITLE))) 79 { 80 aName = String(SdResId(STR_PSEUDOSHEET_TITLE)); 81 } 82 else if (aName == String(SdResId(STR_LAYOUT_SUBTITLE))) 83 { 84 aName = String(SdResId(STR_PSEUDOSHEET_SUBTITLE)); 85 } 86 else if (aName == String(SdResId(STR_LAYOUT_BACKGROUND))) 87 { 88 aName = String(SdResId(STR_PSEUDOSHEET_BACKGROUND)); 89 } 90 else if (aName == String(SdResId(STR_LAYOUT_BACKGROUNDOBJECTS))) 91 { 92 aName = String(SdResId(STR_PSEUDOSHEET_BACKGROUNDOBJECTS)); 93 } 94 else if (aName == String(SdResId(STR_LAYOUT_NOTES))) 95 { 96 aName = String(SdResId(STR_PSEUDOSHEET_NOTES)); 97 } 98 else 99 { 100 String aOutlineStr(SdResId(STR_PSEUDOSHEET_OUTLINE)); 101 nPos = aName.Search(aOutlineStr); 102 if (nPos != STRING_NOTFOUND) 103 { 104 String aNumStr(aName.Copy(aOutlineStr.Len())); 105 aName = String(SdResId(STR_LAYOUT_OUTLINE)); 106 aName += aNumStr; 107 } 108 } 109 110 // Platzhalter durch Vorlagennamen ersetzen 111 nPos = aComment.Search(sal_Unicode('$')); 112 aComment.Erase(nPos, 1); 113 aComment.Insert(aName, nPos); 114 } 115 116 117 /************************************************************************* 118 |* 119 |* Undo() 120 |* 121 \************************************************************************/ 122 123 void StyleSheetUndoAction::Undo() 124 { 125 SfxItemSet aNewSet( mpDoc->GetItemPool(), pOldSet->GetRanges() ); 126 mpDoc->MigrateItemSet( pOldSet, &aNewSet, mpDoc ); 127 128 pStyleSheet->GetItemSet().Set(aNewSet); 129 if( pStyleSheet->GetFamily() == SD_STYLE_FAMILY_PSEUDO ) 130 ( (SdStyleSheet*)pStyleSheet )->GetRealStyleSheet()->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED)); 131 else 132 pStyleSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED)); 133 } 134 135 /************************************************************************* 136 |* 137 |* Redo() 138 |* 139 \************************************************************************/ 140 141 void StyleSheetUndoAction::Redo() 142 { 143 SfxItemSet aNewSet( mpDoc->GetItemPool(), pOldSet->GetRanges() ); 144 mpDoc->MigrateItemSet( pNewSet, &aNewSet, mpDoc ); 145 146 pStyleSheet->GetItemSet().Set(aNewSet); 147 if( pStyleSheet->GetFamily() == SD_STYLE_FAMILY_PSEUDO ) 148 ( (SdStyleSheet*)pStyleSheet )->GetRealStyleSheet()->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED)); 149 else 150 pStyleSheet->Broadcast(SfxSimpleHint(SFX_HINT_DATACHANGED)); 151 } 152 153 /************************************************************************* 154 |* 155 |* Destruktor 156 |* 157 \************************************************************************/ 158 159 StyleSheetUndoAction::~StyleSheetUndoAction() 160 { 161 delete pNewSet; 162 delete pOldSet; 163 } 164 165 /************************************************************************* 166 |* 167 |* Kommentar liefern 168 |* 169 \************************************************************************/ 170 171 String StyleSheetUndoAction::GetComment() const 172 { 173 return aComment; 174 } 175