xref: /AOO41X/main/sc/source/ui/undo/undoutil.cxx (revision 54628ca40d27d15cc98fe861da7fff7e60c2f7d6)
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 
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 
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 
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 
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         sal_Bool bWasTemp = sal_False;
92         if ( pUndoData )
93         {
94             String aName;
95             pUndoData->GetName( aName );
96 //          if ( aName == ScGlobal::GetRscString( STR_DB_NONAME ) )
97             if (pUndoData->IsBuildin())
98                 bWasTemp = sal_True;
99         }
100         DBG_ASSERT(bWasTemp, "Undo: didn't find database range");
101 
102         sal_uInt16 nIndex;
103         ScDBCollection* pColl = pDoc->GetDBCollection();
104         if (pColl->SearchName( ScGlobal::GetRscString( STR_DB_NONAME ), nIndex ))
105             pRet = (*pColl)[nIndex];
106         else
107         {
108             String  aNoNamed = pColl->GetNewDefaultDBName();
109             pRet = new ScDBData( aNoNamed/*ScGlobal::GetRscString( STR_DB_NONAME )*/, nTab,
110                                 nCol1,nRow1, nCol2,nRow2, sal_True,
111                                 pDoc->HasColHeader( nCol1,nRow1,nCol2,nRow2,nTab ) );
112             pColl->Insert( pRet );
113         }
114     }
115 
116     return pRet;
117 }
118 
119 
120 void ScUndoUtil::PaintMore( ScDocShell* pDocShell,
121                                 const ScRange& rRange )
122 {
123     SCCOL nCol1 = rRange.aStart.Col();
124     SCROW nRow1 = rRange.aStart.Row();
125     SCCOL nCol2 = rRange.aEnd.Col();
126     SCROW nRow2 = rRange.aEnd.Row();
127     if (nCol1 > 0) --nCol1;
128     if (nRow1 > 0) --nRow1;
129     if (nCol2<MAXCOL) ++nCol2;
130     if (nRow2<MAXROW) ++nRow2;
131 
132     pDocShell->PostPaint( nCol1,nRow1,rRange.aStart.Tab(),
133                           nCol2,nRow2,rRange.aEnd.Tab(), PAINT_GRID );
134 }
135