LibreOffice Module sc (master)  1
undoutil.cxx
Go to the documentation of this file.
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 #include <undoutil.hxx>
21 
22 #include <docsh.hxx>
23 #include <tabvwsh.hxx>
24 #include <document.hxx>
25 #include <dbdata.hxx>
26 #include <globalnames.hxx>
27 #include <global.hxx>
28 #include <markdata.hxx>
29 
30 void ScUndoUtil::MarkSimpleBlock( const ScDocShell* pDocShell,
31  SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
32  SCCOL nEndX, SCROW nEndY, SCTAB nEndZ )
33 {
34  if ( pDocShell->IsPaintLocked() )
35  return;
36 
38  if (pViewShell)
39  {
40  SCTAB nViewTab = pViewShell->GetViewData().GetTabNo();
41  if ( nViewTab < nStartZ || nViewTab > nEndZ )
42  pViewShell->SetTabNo( nStartZ );
43 
44  pViewShell->DoneBlockMode();
45  pViewShell->MoveCursorAbs( nStartX, nStartY, SC_FOLLOW_JUMP, false, false );
46  pViewShell->InitOwnBlockMode();
47  pViewShell->GetViewData().GetMarkData().
48  SetMarkArea( ScRange( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ) );
49  pViewShell->MarkDataChanged();
50  }
51 }
52 
53 void ScUndoUtil::MarkSimpleBlock( const ScDocShell* pDocShell,
54  const ScAddress& rBlockStart,
55  const ScAddress& rBlockEnd )
56 {
57  MarkSimpleBlock( pDocShell, rBlockStart.Col(), rBlockStart.Row(), rBlockStart.Tab(),
58  rBlockEnd.Col(), rBlockEnd.Row(), rBlockEnd.Tab() );
59 }
60 
61 void ScUndoUtil::MarkSimpleBlock( const ScDocShell* pDocShell,
62  const ScRange& rRange )
63 {
64  MarkSimpleBlock( pDocShell, rRange.aStart.Col(), rRange.aStart.Row(), rRange.aStart.Tab(),
65  rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aEnd.Tab() );
66 }
67 
68 ScDBData* ScUndoUtil::GetOldDBData( const ScDBData* pUndoData, ScDocument* pDoc, SCTAB nTab,
69  SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
70 {
71  ScDBData* pRet = pDoc->GetDBAtArea( nTab, nCol1, nRow1, nCol2, nRow2 );
72 
73  if (!pRet)
74  {
75  bool bWasTemp = false;
76  if ( pUndoData )
77  {
78  const OUString& aName = pUndoData->GetName();
79  if ( aName == STR_DB_LOCAL_NONAME )
80  bWasTemp = true;
81  }
82  OSL_ENSURE(bWasTemp, "Undo: didn't find database range");
83  pRet = pDoc->GetAnonymousDBData(nTab);
84  if (!pRet)
85  {
86  pRet = new ScDBData( STR_DB_LOCAL_NONAME, nTab,
87  nCol1,nRow1, nCol2,nRow2, true,
88  pDoc->HasColHeader( nCol1,nRow1,nCol2,nRow2,nTab ) );
89  pDoc->SetAnonymousDBData(nTab, std::unique_ptr<ScDBData>(pRet));
90  }
91  }
92 
93  return pRet;
94 }
95 
97  const ScRange& rRange )
98 {
99  SCCOL nCol1 = rRange.aStart.Col();
100  SCROW nRow1 = rRange.aStart.Row();
101  SCCOL nCol2 = rRange.aEnd.Col();
102  SCROW nRow2 = rRange.aEnd.Row();
103  ScDocument& rDoc = pDocShell->GetDocument();
104  if (nCol1 > 0) --nCol1;
105  if (nRow1 > 0) --nRow1;
106  if (nCol2<rDoc.MaxCol()) ++nCol2;
107  if (nRow2<rDoc.MaxRow()) ++nRow2;
108 
109  pDocShell->PostPaint( nCol1,nRow1,rRange.aStart.Tab(),
110  nCol2,nRow2,rRange.aEnd.Tab(), PaintPartFlags::Grid );
111 }
112 
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3053
SC_DLLPUBLIC bool HasColHeader(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab)
Definition: documen3.cxx:1489
ScAddress aStart
Definition: address.hxx:500
SC_DLLPUBLIC ScDBData * GetAnonymousDBData(SCTAB nTab)
Definition: document.cxx:307
SCROW Row() const
Definition: address.hxx:262
SC_DLLPUBLIC void SetAnonymousDBData(SCTAB nTab, std::unique_ptr< ScDBData > pDBData)
Definition: document.cxx:319
#define STR_DB_LOCAL_NONAME
Definition: globalnames.hxx:13
static void MarkSimpleBlock(const ScDocShell *pDocShell, SCCOL nStartX, SCROW nStartY, SCTAB nStartZ, SCCOL nEndX, SCROW nEndY, SCTAB nEndZ)
Mark Block (invisible - has to be repainted)
Definition: undoutil.cxx:30
const ScDBData * GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const
Definition: documen3.cxx:319
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
ScAddress aEnd
Definition: address.hxx:501
SC_DLLPUBLIC void MoveCursorAbs(SCCOL nCurX, SCROW nCurY, ScFollowMode eMode, bool bShift, bool bControl, bool bKeepOld=false, bool bKeepSel=false)
Definition: tabview3.cxx:1178
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:873
void MarkDataChanged()
Definition: tabview3.cxx:1734
SCTAB Tab() const
Definition: address.hxx:271
void DoneBlockMode(bool bContinue=false)
Definition: tabview2.cxx:408
ScViewData & GetViewData()
Definition: tabview.hxx:332
static void PaintMore(ScDocShell *pDocShell, const ScRange &rRange)
Definition: undoutil.cxx:96
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:872
sal_Int16 SCCOL
Definition: types.hxx:22
SC_DLLPUBLIC void SetTabNo(SCTAB nTab, bool bNew=false, bool bExtendSelection=false, bool bSameTabButMoved=false)
Definition: tabview3.cxx:1786
const OUString & GetName() const
Definition: dbdata.hxx:122
void InitOwnBlockMode()
Definition: tabview2.cxx:331
void PostPaint(SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, PaintPartFlags nPart, sal_uInt16 nExtFlags=0)
Definition: docsh3.cxx:99
SCCOL Col() const
Definition: address.hxx:267
bool IsPaintLocked() const
Definition: docsh.hxx:320
sal_Int32 SCROW
Definition: types.hxx:18
static ScTabViewShell * GetActiveViewShell()
Definition: tabvwsh4.cxx:1023
static ScDBData * GetOldDBData(const ScDBData *pUndoData, ScDocument *pDoc, SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Search for Data base range in Document ("untitled" or by region) create new if not found...
Definition: undoutil.cxx:68
OUString aName
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
sal_Int16 SCTAB
Definition: types.hxx:23