fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / undo / undostyl.cxx
blob6e9c5f61b902fadd84dcb893ca4043f482023c01
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 <svl/itemset.hxx>
21 #include <vcl/virdev.hxx>
23 #include "undostyl.hxx"
24 #include "docsh.hxx"
25 #include "docpool.hxx"
26 #include "stlpool.hxx"
27 #include "printfun.hxx"
28 #include "scmod.hxx"
29 #include "inputhdl.hxx"
30 #include "globstr.hrc"
32 TYPEINIT1(ScUndoModifyStyle, ScSimpleUndo);
33 TYPEINIT1(ScUndoApplyPageStyle, ScSimpleUndo);
35 // modify style (cell or page style)
37 ScStyleSaveData::ScStyleSaveData() :
38 pItems( NULL )
42 ScStyleSaveData::ScStyleSaveData( const ScStyleSaveData& rOther ) :
43 aName( rOther.aName ),
44 aParent( rOther.aParent )
46 if (rOther.pItems)
47 pItems = new SfxItemSet( *rOther.pItems );
48 else
49 pItems = NULL;
52 ScStyleSaveData::~ScStyleSaveData()
54 delete pItems;
57 ScStyleSaveData& ScStyleSaveData::operator=( const ScStyleSaveData& rOther )
59 aName = rOther.aName;
60 aParent = rOther.aParent;
62 delete pItems;
63 if (rOther.pItems)
64 pItems = new SfxItemSet( *rOther.pItems );
65 else
66 pItems = NULL;
68 return *this;
71 void ScStyleSaveData::InitFromStyle( const SfxStyleSheetBase* pSource )
73 if ( pSource )
75 aName = pSource->GetName();
76 aParent = pSource->GetParent();
77 delete pItems;
78 pItems = new SfxItemSet( const_cast<SfxStyleSheetBase*>(pSource)->GetItemSet() );
80 else
81 *this = ScStyleSaveData(); // empty
84 ScUndoModifyStyle::ScUndoModifyStyle( ScDocShell* pDocSh, SfxStyleFamily eFam,
85 const ScStyleSaveData& rOld, const ScStyleSaveData& rNew ) :
86 ScSimpleUndo( pDocSh ),
87 eFamily( eFam ),
88 aOldData( rOld ),
89 aNewData( rNew )
93 ScUndoModifyStyle::~ScUndoModifyStyle()
97 OUString ScUndoModifyStyle::GetComment() const
99 sal_uInt16 nId = (eFamily == SFX_STYLE_FAMILY_PARA) ?
100 STR_UNDO_EDITCELLSTYLE :
101 STR_UNDO_EDITPAGESTYLE;
102 return ScGlobal::GetRscString( nId );
105 static void lcl_DocStyleChanged( ScDocument* pDoc, SfxStyleSheetBase* pStyle, bool bRemoved )
107 //! move to document or docshell
109 ScopedVclPtrInstance< VirtualDevice > pVDev;
110 Point aLogic = pVDev->LogicToPixel( Point(1000,1000), MAP_TWIP );
111 double nPPTX = aLogic.X() / 1000.0;
112 double nPPTY = aLogic.Y() / 1000.0;
113 Fraction aZoom(1,1);
114 pDoc->StyleSheetChanged( pStyle, bRemoved, pVDev, nPPTX, nPPTY, aZoom, aZoom );
116 ScInputHandler* pHdl = SC_MOD()->GetInputHdl();
117 if (pHdl)
118 pHdl->ForgetLastPattern();
121 void ScUndoModifyStyle::DoChange( ScDocShell* pDocSh, const OUString& rName,
122 SfxStyleFamily eStyleFamily, const ScStyleSaveData& rData )
124 ScDocument& rDoc = pDocSh->GetDocument();
125 ScStyleSheetPool* pStlPool = rDoc.GetStyleSheetPool();
126 OUString aNewName = rData.GetName();
127 bool bDelete = aNewName.isEmpty(); // no new name -> delete style
128 bool bNew = ( rName.isEmpty() && !bDelete ); // creating new style
130 SfxStyleSheetBase* pStyle = NULL;
131 if ( !rName.isEmpty() )
133 // find old style to modify
134 pStyle = pStlPool->Find( rName, eStyleFamily );
135 OSL_ENSURE( pStyle, "style not found" );
137 if ( pStyle && !bDelete )
139 // set new name
140 pStyle->SetName( aNewName );
143 else if ( !bDelete )
145 // create style (with new name)
146 pStyle = &pStlPool->Make( aNewName, eStyleFamily, SFXSTYLEBIT_USERDEF );
148 if ( eStyleFamily == SFX_STYLE_FAMILY_PARA )
149 rDoc.GetPool()->CellStyleCreated( aNewName, &rDoc );
152 if ( pStyle )
154 if ( bDelete )
156 if ( eStyleFamily == SFX_STYLE_FAMILY_PARA )
157 lcl_DocStyleChanged( &rDoc, pStyle, true ); // TRUE: remove usage of style
158 else
159 rDoc.RemovePageStyleInUse( rName );
161 // delete style
162 pStlPool->Remove( pStyle );
164 else
166 // modify style
168 OUString aNewParent = rData.GetParent();
169 if ( aNewParent != pStyle->GetParent() )
170 pStyle->SetParent( aNewParent );
172 SfxItemSet& rStyleSet = pStyle->GetItemSet();
173 const SfxItemSet* pNewSet = rData.GetItems();
174 OSL_ENSURE( pNewSet, "no ItemSet for style" );
175 if (pNewSet)
176 rStyleSet.Set( *pNewSet, false );
178 if ( eStyleFamily == SFX_STYLE_FAMILY_PARA )
180 lcl_DocStyleChanged( &rDoc, pStyle, false ); // cell styles: row heights
182 else
184 // page styles
186 if ( bNew && aNewName != rName )
187 rDoc.RenamePageStyleInUse( rName, aNewName );
189 if (pNewSet)
190 rDoc.ModifyStyleSheet( *pStyle, *pNewSet );
192 pDocSh->PageStyleModified( aNewName, true );
197 pDocSh->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID|PAINT_LEFT );
199 //! undo/redo document modifications for deleted styles
200 //! undo/redo modifications of number formatter
203 void ScUndoModifyStyle::Undo()
205 BeginUndo();
206 DoChange( pDocShell, aNewData.GetName(), eFamily, aOldData );
207 EndUndo();
210 void ScUndoModifyStyle::Redo()
212 BeginRedo();
213 DoChange( pDocShell, aOldData.GetName(), eFamily, aNewData );
214 EndRedo();
217 void ScUndoModifyStyle::Repeat(SfxRepeatTarget& /* rTarget */)
221 bool ScUndoModifyStyle::CanRepeat(SfxRepeatTarget& /* rTarget */) const
223 return false; // no repeat possible
226 // apply page style
228 ScUndoApplyPageStyle::ApplyStyleEntry::ApplyStyleEntry( SCTAB nTab, const OUString& rOldStyle ) :
229 mnTab( nTab ),
230 maOldStyle( rOldStyle )
234 ScUndoApplyPageStyle::ScUndoApplyPageStyle( ScDocShell* pDocSh, const OUString& rNewStyle ) :
235 ScSimpleUndo( pDocSh ),
236 maNewStyle( rNewStyle )
240 ScUndoApplyPageStyle::~ScUndoApplyPageStyle()
244 void ScUndoApplyPageStyle::AddSheetAction( SCTAB nTab, const OUString& rOldStyle )
246 maEntries.push_back( ApplyStyleEntry( nTab, rOldStyle ) );
249 OUString ScUndoApplyPageStyle::GetComment() const
251 return ScGlobal::GetRscString( STR_UNDO_APPLYPAGESTYLE );
254 void ScUndoApplyPageStyle::Undo()
256 BeginUndo();
257 for( ApplyStyleVec::const_iterator aIt = maEntries.begin(), aEnd = maEntries.end(); aIt != aEnd; ++aIt )
259 pDocShell->GetDocument().SetPageStyle( aIt->mnTab, aIt->maOldStyle );
260 ScPrintFunc( pDocShell, pDocShell->GetPrinter(), aIt->mnTab ).UpdatePages();
262 EndUndo();
265 void ScUndoApplyPageStyle::Redo()
267 BeginRedo();
268 for( ApplyStyleVec::const_iterator aIt = maEntries.begin(), aEnd = maEntries.end(); aIt != aEnd; ++aIt )
270 pDocShell->GetDocument().SetPageStyle( aIt->mnTab, maNewStyle );
271 ScPrintFunc( pDocShell, pDocShell->GetPrinter(), aIt->mnTab ).UpdatePages();
273 EndRedo();
276 void ScUndoApplyPageStyle::Repeat(SfxRepeatTarget& /* rTarget */)
278 //! set same page style to current tab
281 bool ScUndoApplyPageStyle::CanRepeat(SfxRepeatTarget& /* rTarget */) const
283 return false;
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */