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 #include <osl/diagnose.h>
30 
31 void ScUndoUtil::MarkSimpleBlock( const ScDocShell* pDocShell,
32  SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
33  SCCOL nEndX, SCROW nEndY, SCTAB nEndZ )
34 {
35  if ( pDocShell->IsPaintLocked() )
36  return;
37 
39  if (!pViewShell)
40  return;
41 
42  SCTAB nViewTab = pViewShell->GetViewData().GetTabNo();
43  if ( nViewTab < nStartZ || nViewTab > nEndZ )
44  pViewShell->SetTabNo( nStartZ );
45 
46  pViewShell->DoneBlockMode();
47  pViewShell->MoveCursorAbs( nStartX, nStartY, SC_FOLLOW_JUMP, false, false );
48  pViewShell->InitOwnBlockMode();
49  pViewShell->GetViewData().GetMarkData().
50  SetMarkArea( ScRange( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ) );
51  pViewShell->MarkDataChanged();
52 }
53 
54 void ScUndoUtil::MarkSimpleBlock( const ScDocShell* pDocShell,
55  const ScAddress& rBlockStart,
56  const ScAddress& rBlockEnd )
57 {
58  MarkSimpleBlock( pDocShell, rBlockStart.Col(), rBlockStart.Row(), rBlockStart.Tab(),
59  rBlockEnd.Col(), rBlockEnd.Row(), rBlockEnd.Tab() );
60 }
61 
62 void ScUndoUtil::MarkSimpleBlock( const ScDocShell* pDocShell,
63  const ScRange& rRange )
64 {
65  MarkSimpleBlock( pDocShell, rRange.aStart.Col(), rRange.aStart.Row(), rRange.aStart.Tab(),
66  rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aEnd.Tab() );
67 }
68 
69 ScDBData* ScUndoUtil::GetOldDBData( const ScDBData* pUndoData, ScDocument* pDoc, SCTAB nTab,
70  SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
71 {
72  ScDBData* pRet = pDoc->GetDBAtArea( nTab, nCol1, nRow1, nCol2, nRow2 );
73 
74  if (!pRet)
75  {
76  bool bWasTemp = false;
77  if ( pUndoData )
78  {
79  const OUString& aName = pUndoData->GetName();
80  if ( aName == STR_DB_LOCAL_NONAME )
81  bWasTemp = true;
82  }
83  OSL_ENSURE(bWasTemp, "Undo: didn't find database range");
84  pRet = pDoc->GetAnonymousDBData(nTab);
85  if (!pRet)
86  {
87  pRet = new ScDBData( STR_DB_LOCAL_NONAME, nTab,
88  nCol1,nRow1, nCol2,nRow2, true,
89  pDoc->HasColHeader( nCol1,nRow1,nCol2,nRow2,nTab ) );
90  pDoc->SetAnonymousDBData(nTab, std::unique_ptr<ScDBData>(pRet));
91  }
92  }
93 
94  return pRet;
95 }
96 
98  const ScRange& rRange )
99 {
100  SCCOL nCol1 = rRange.aStart.Col();
101  SCROW nRow1 = rRange.aStart.Row();
102  SCCOL nCol2 = rRange.aEnd.Col();
103  SCROW nRow2 = rRange.aEnd.Row();
104  ScDocument& rDoc = pDocShell->GetDocument();
105  if (nCol1 > 0) --nCol1;
106  if (nRow1 > 0) --nRow1;
107  if (nCol2<rDoc.MaxCol()) ++nCol2;
108  if (nRow2<rDoc.MaxRow()) ++nRow2;
109 
110  pDocShell->PostPaint( nCol1,nRow1,rRange.aStart.Tab(),
111  nCol2,nRow2,rRange.aEnd.Tab(), PaintPartFlags::Grid );
112 }
113 
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3108
SC_DLLPUBLIC bool HasColHeader(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab)
Definition: documen3.cxx:1532
ScAddress aStart
Definition: address.hxx:499
SC_DLLPUBLIC ScDBData * GetAnonymousDBData(SCTAB nTab)
Definition: document.cxx:307
SCROW Row() const
Definition: address.hxx:261
SC_DLLPUBLIC void SetAnonymousDBData(SCTAB nTab, std::unique_ptr< ScDBData > pDBData)
Definition: document.cxx:319
#define STR_DB_LOCAL_NONAME
Definition: globalnames.hxx:12
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:31
SC_DLLPUBLIC const ScDBData * GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const
Definition: documen3.cxx:338
SCTAB GetTabNo() const
Definition: viewdata.hxx:394
ScAddress aEnd
Definition: address.hxx:500
SC_DLLPUBLIC void MoveCursorAbs(SCCOL nCurX, SCROW nCurY, ScFollowMode eMode, bool bShift, bool bControl, bool bKeepOld=false, bool bKeepSel=false)
Definition: tabview3.cxx:1190
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:872
void MarkDataChanged()
Definition: tabview3.cxx:1746
SCTAB Tab() const
Definition: address.hxx:270
void DoneBlockMode(bool bContinue=false)
Definition: tabview2.cxx:409
ScViewData & GetViewData()
Definition: tabview.hxx:333
static void PaintMore(ScDocShell *pDocShell, const ScRange &rRange)
Definition: undoutil.cxx:97
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:871
sal_Int16 SCCOL
Definition: types.hxx:21
SC_DLLPUBLIC void SetTabNo(SCTAB nTab, bool bNew=false, bool bExtendSelection=false, bool bSameTabButMoved=false)
Definition: tabview3.cxx:1798
const OUString & GetName() const
Definition: dbdata.hxx:121
void InitOwnBlockMode()
Definition: tabview2.cxx:332
void PostPaint(SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, PaintPartFlags nPart, sal_uInt16 nExtFlags=0)
Definition: docsh3.cxx:101
SCCOL Col() const
Definition: address.hxx:266
bool IsPaintLocked() const
Definition: docsh.hxx:326
sal_Int32 SCROW
Definition: types.hxx:17
static ScTabViewShell * GetActiveViewShell()
Definition: tabvwsh4.cxx:1038
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:69
OUString aName
const ScDocument & GetDocument() const
Definition: docsh.hxx:220
sal_Int16 SCTAB
Definition: types.hxx:22