xref: /aoo4110/main/sc/source/ui/undo/undoutil.cxx (revision b1cdbd2c)
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_sc.hxx"
26 
27 // System - Includes -----------------------------------------------------
28 
29 
30 
31 // INCLUDE ---------------------------------------------------------------
32 
33 #include "undoutil.hxx"
34 
35 #include "docsh.hxx"
36 #include "tabvwsh.hxx"
37 #include "document.hxx"
38 #include "dbcolect.hxx"
39 #include "globstr.hrc"
40 #include "global.hxx"
41 
MarkSimpleBlock(ScDocShell * pDocShell,SCCOL nStartX,SCROW nStartY,SCTAB nStartZ,SCCOL nEndX,SCROW nEndY,SCTAB nEndZ)42 void ScUndoUtil::MarkSimpleBlock( ScDocShell* pDocShell,
43 								SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
44 								SCCOL nEndX, SCROW nEndY, SCTAB nEndZ )
45 {
46     if ( pDocShell->IsPaintLocked() )
47         return;
48 
49 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
50 	if (pViewShell)
51 	{
52 		SCTAB nViewTab = pViewShell->GetViewData()->GetTabNo();
53 		if ( nViewTab < nStartZ || nViewTab > nEndZ )
54 			pViewShell->SetTabNo( nStartZ );
55 
56 		pViewShell->DoneBlockMode();
57 		pViewShell->MoveCursorAbs( nStartX, nStartY, SC_FOLLOW_JUMP, sal_False, sal_False );
58 		pViewShell->InitOwnBlockMode();
59 		pViewShell->GetViewData()->GetMarkData().
60 				SetMarkArea( ScRange( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ) );
61         pViewShell->MarkDataChanged();
62 	}
63 }
64 
65 
MarkSimpleBlock(ScDocShell * pDocShell,const ScAddress & rBlockStart,const ScAddress & rBlockEnd)66 void ScUndoUtil::MarkSimpleBlock( ScDocShell* pDocShell,
67 								const ScAddress& rBlockStart,
68 								const ScAddress& rBlockEnd )
69 {
70 	MarkSimpleBlock( pDocShell, rBlockStart.Col(), rBlockStart.Row(), rBlockStart.Tab(),
71 								rBlockEnd.Col(), rBlockEnd.Row(), rBlockEnd.Tab() );
72 }
73 
74 
MarkSimpleBlock(ScDocShell * pDocShell,const ScRange & rRange)75 void ScUndoUtil::MarkSimpleBlock( ScDocShell* pDocShell,
76 								const ScRange& rRange )
77 {
78 	MarkSimpleBlock( pDocShell, rRange.aStart.Col(), rRange.aStart.Row(), rRange.aStart.Tab(),
79 								rRange.aEnd.Col(),   rRange.aEnd.Row(),   rRange.aEnd.Tab()   );
80 }
81 
82 
83 
GetOldDBData(ScDBData * pUndoData,ScDocument * pDoc,SCTAB nTab,SCCOL nCol1,SCROW nRow1,SCCOL nCol2,SCROW nRow2)84 ScDBData* ScUndoUtil::GetOldDBData( ScDBData* pUndoData, ScDocument* pDoc, SCTAB nTab,
85                                    SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
86 {
87     ScDBData* pRet = pDoc->GetDBAtArea( nTab, nCol1, nRow1, nCol2, nRow2 );
88 
89     if (!pRet)
90     {
91         bool bWasInternalUnnamed = false;
92         bool bWasInternalForAutoFilter = false;
93         if ( pUndoData )
94         {
95             String aName;
96             pUndoData->GetName( aName );
97             if ( pUndoData->IsInternalUnnamed() )
98             {
99                 bWasInternalUnnamed = true;
100             }
101             else if (pUndoData->IsInternalForAutoFilter())
102             {
103                 bWasInternalForAutoFilter = true;
104             }
105         }
106         DBG_ASSERT( bWasInternalUnnamed || bWasInternalForAutoFilter, "Undo: didn't find database range");
107 
108         sal_uInt16 nIndex;
109         ScDBCollection* pColl = pDoc->GetDBCollection();
110         if ( bWasInternalUnnamed
111              && pColl->SearchName( ScGlobal::GetRscString( STR_DB_NONAME ), nIndex ))
112         {
113             pRet = (*pColl)[nIndex];
114         }
115         else
116         {
117             String aNewNamed = bWasInternalForAutoFilter
118                                ? pColl->GetNewDefaultDBName()
119                                : ScGlobal::GetRscString( STR_DB_NONAME );
120             pRet = new ScDBData(
121                 aNewNamed, nTab, nCol1,nRow1, nCol2,nRow2, sal_True,
122                 pDoc->HasColHeader( nCol1,nRow1,nCol2,nRow2,nTab ) );
123             pColl->Insert( pRet );
124         }
125     }
126 
127     return pRet;
128 }
129 
130 
PaintMore(ScDocShell * pDocShell,const ScRange & rRange)131 void ScUndoUtil::PaintMore( ScDocShell* pDocShell,
132 								const ScRange& rRange )
133 {
134 	SCCOL nCol1 = rRange.aStart.Col();
135 	SCROW nRow1 = rRange.aStart.Row();
136 	SCCOL nCol2 = rRange.aEnd.Col();
137 	SCROW nRow2 = rRange.aEnd.Row();
138 	if (nCol1 > 0) --nCol1;
139 	if (nRow1 > 0) --nRow1;
140 	if (nCol2<MAXCOL) ++nCol2;
141 	if (nRow2<MAXROW) ++nRow2;
142 
143 	pDocShell->PostPaint( nCol1,nRow1,rRange.aStart.Tab(),
144 						  nCol2,nRow2,rRange.aEnd.Tab(), PAINT_GRID );
145 }
146