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_sc.hxx" 30 31 // System - Includes ----------------------------------------------------- 32 33 34 35 #ifndef PCH 36 #include "scitems.hxx" // SearchItem 37 #endif 38 39 // INCLUDE --------------------------------------------------------------- 40 41 #include "undoblk.hxx" 42 #include "document.hxx" 43 #include "docsh.hxx" 44 #include "tabvwsh.hxx" 45 #include "olinetab.hxx" 46 #include "globstr.hrc" 47 #include "global.hxx" 48 #include "target.hxx" 49 50 #include "undoolk.hxx" //! GetUndo ins Document verschieben! 51 52 53 // STATIC DATA ----------------------------------------------------------- 54 55 TYPEINIT1(ScUndoWidthOrHeight, SfxUndoAction); 56 57 // ----------------------------------------------------------------------- 58 59 60 61 // 62 // Spaltenbreiten oder Zeilenhoehen aendern 63 // 64 65 ScUndoWidthOrHeight::ScUndoWidthOrHeight( ScDocShell* pNewDocShell, 66 const ScMarkData& rMark, 67 SCCOLROW nNewStart, SCTAB nNewStartTab, SCCOLROW nNewEnd, SCTAB nNewEndTab, 68 ScDocument* pNewUndoDoc, SCCOLROW nNewCnt, SCCOLROW* pNewRanges, 69 ScOutlineTable* pNewUndoTab, 70 ScSizeMode eNewMode, sal_uInt16 nNewSizeTwips, sal_Bool bNewWidth ) : 71 ScSimpleUndo( pNewDocShell ), 72 aMarkData( rMark ), 73 nStart( nNewStart ), 74 nEnd( nNewEnd ), 75 nStartTab( nNewStartTab ), 76 nEndTab( nNewEndTab ), 77 pUndoDoc( pNewUndoDoc ), 78 pUndoTab( pNewUndoTab ), 79 nRangeCnt( nNewCnt ), 80 pRanges( pNewRanges ), 81 nNewSize( nNewSizeTwips ), 82 bWidth( bNewWidth ), 83 eMode( eNewMode ), 84 pDrawUndo( NULL ) 85 { 86 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() ); 87 } 88 89 __EXPORT ScUndoWidthOrHeight::~ScUndoWidthOrHeight() 90 { 91 delete[] pRanges; 92 delete pUndoDoc; 93 delete pUndoTab; 94 DeleteSdrUndoAction( pDrawUndo ); 95 } 96 97 String __EXPORT ScUndoWidthOrHeight::GetComment() const 98 { 99 // [ "optimale " ] "Spaltenbreite" | "Zeilenhoehe" 100 return ( bWidth ? 101 ( ( eMode == SC_SIZE_OPTIMAL )? 102 ScGlobal::GetRscString( STR_UNDO_OPTCOLWIDTH ) : 103 ScGlobal::GetRscString( STR_UNDO_COLWIDTH ) 104 ) : 105 ( ( eMode == SC_SIZE_OPTIMAL )? 106 ScGlobal::GetRscString( STR_UNDO_OPTROWHEIGHT ) : 107 ScGlobal::GetRscString( STR_UNDO_ROWHEIGHT ) 108 ) ); 109 } 110 111 void __EXPORT ScUndoWidthOrHeight::Undo() 112 { 113 BeginUndo(); 114 115 ScDocument* pDoc = pDocShell->GetDocument(); 116 117 SCCOLROW nPaintStart = nStart > 0 ? nStart-1 : static_cast<SCCOLROW>(0); 118 119 if (eMode==SC_SIZE_OPTIMAL) 120 { 121 if ( SetViewMarkData( aMarkData ) ) 122 nPaintStart = 0; // paint all, because of changed selection 123 } 124 125 //! outlines from all tables? 126 if (pUndoTab) // Outlines mit gespeichert? 127 pDoc->SetOutlineTable( nStartTab, pUndoTab ); 128 129 SCTAB nTabCount = pDoc->GetTableCount(); 130 SCTAB nTab; 131 for (nTab=0; nTab<nTabCount; nTab++) 132 if (aMarkData.GetTableSelect(nTab)) 133 { 134 if (bWidth) // Width 135 { 136 pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab, 137 static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE, 138 sal_False, pDoc ); 139 pDoc->UpdatePageBreaks( nTab ); 140 pDocShell->PostPaint( static_cast<SCCOL>(nPaintStart), 0, nTab, 141 MAXCOL, MAXROW, nTab, PAINT_GRID | PAINT_TOP ); 142 } 143 else // Height 144 { 145 pUndoDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, sal_False, pDoc ); 146 pDoc->UpdatePageBreaks( nTab ); 147 pDocShell->PostPaint( 0, nPaintStart, nTab, MAXCOL, MAXROW, nTab, PAINT_GRID | PAINT_LEFT ); 148 } 149 } 150 151 DoSdrUndoAction( pDrawUndo, pDoc ); 152 153 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); 154 if (pViewShell) 155 { 156 pViewShell->UpdateScrollBars(); 157 158 SCTAB nCurrentTab = pViewShell->GetViewData()->GetTabNo(); 159 if ( nCurrentTab < nStartTab || nCurrentTab > nEndTab ) 160 pViewShell->SetTabNo( nStartTab ); 161 } 162 163 EndUndo(); 164 } 165 166 void __EXPORT ScUndoWidthOrHeight::Redo() 167 { 168 BeginRedo(); 169 170 sal_Bool bPaintAll = sal_False; 171 if (eMode==SC_SIZE_OPTIMAL) 172 { 173 if ( SetViewMarkData( aMarkData ) ) 174 bPaintAll = sal_True; // paint all, because of changed selection 175 } 176 177 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); 178 if (pViewShell) 179 { 180 SCTAB nTab = pViewShell->GetViewData()->GetTabNo(); 181 if ( nTab < nStartTab || nTab > nEndTab ) 182 pViewShell->SetTabNo( nStartTab ); 183 } 184 185 // SetWidthOrHeight aendert aktuelle Tabelle ! 186 if ( pViewShell ) 187 pViewShell->SetWidthOrHeight( bWidth, nRangeCnt, pRanges, eMode, nNewSize, sal_False, sal_True, &aMarkData ); 188 189 // paint grid if selection was changed directly at the MarkData 190 if (bPaintAll) 191 pDocShell->PostPaint( 0, 0, nStartTab, MAXCOL, MAXROW, nEndTab, PAINT_GRID ); 192 193 EndRedo(); 194 } 195 196 void __EXPORT ScUndoWidthOrHeight::Repeat(SfxRepeatTarget& rTarget) 197 { 198 if (rTarget.ISA(ScTabViewTarget)) 199 ((ScTabViewTarget&)rTarget).GetViewShell()->SetMarkedWidthOrHeight( bWidth, eMode, nNewSize, sal_True ); 200 } 201 202 sal_Bool __EXPORT ScUndoWidthOrHeight::CanRepeat(SfxRepeatTarget& rTarget) const 203 { 204 return (rTarget.ISA(ScTabViewTarget)); 205 } 206 207 208