xref: /trunk/main/sc/source/ui/unoobj/cursuno.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b3f79822SAndrew Rist  * distributed with this work for additional information
6b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17b3f79822SAndrew Rist  * specific language governing permissions and limitations
18b3f79822SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "scitems.hxx"
30cdf0e10cSrcweir #include <svl/intitem.hxx>
31cdf0e10cSrcweir #include <svl/zforlist.hxx>
32cdf0e10cSrcweir #include <rtl/uuid.h>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "cursuno.hxx"
35cdf0e10cSrcweir #include "cellsuno.hxx"
36cdf0e10cSrcweir #include "docsh.hxx"
37cdf0e10cSrcweir #include "hints.hxx"
38cdf0e10cSrcweir #include "markdata.hxx"
39cdf0e10cSrcweir #include "dociter.hxx"
40cdf0e10cSrcweir #include "unoguard.hxx"
41cdf0e10cSrcweir #include "miscuno.hxx"
42cdf0e10cSrcweir 
43cdf0e10cSrcweir using namespace com::sun::star;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir //------------------------------------------------------------------------
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #define SCSHEETCELLCURSOR_SERVICE   "com.sun.star.sheet.SheetCellCursor"
48cdf0e10cSrcweir #define SCCELLCURSOR_SERVICE        "com.sun.star.table.CellCursor"
49cdf0e10cSrcweir 
50cdf0e10cSrcweir //------------------------------------------------------------------------
51cdf0e10cSrcweir 
ScCellCursorObj(ScDocShell * pDocSh,const ScRange & rR)52cdf0e10cSrcweir ScCellCursorObj::ScCellCursorObj(ScDocShell* pDocSh, const ScRange& rR) :
53cdf0e10cSrcweir     ScCellRangeObj( pDocSh, rR )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir }
56cdf0e10cSrcweir 
~ScCellCursorObj()57cdf0e10cSrcweir ScCellCursorObj::~ScCellCursorObj()
58cdf0e10cSrcweir {
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
queryInterface(const uno::Type & rType)61cdf0e10cSrcweir uno::Any SAL_CALL ScCellCursorObj::queryInterface( const uno::Type& rType ) throw(uno::RuntimeException)
62cdf0e10cSrcweir {
63cdf0e10cSrcweir     SC_QUERYINTERFACE( sheet::XSheetCellCursor )
64cdf0e10cSrcweir     SC_QUERYINTERFACE( sheet::XUsedAreaCursor )
65cdf0e10cSrcweir     SC_QUERYINTERFACE( table::XCellCursor )
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     return ScCellRangeObj::queryInterface( rType );
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
acquire()70cdf0e10cSrcweir void SAL_CALL ScCellCursorObj::acquire() throw()
71cdf0e10cSrcweir {
72cdf0e10cSrcweir     ScCellRangeObj::acquire();
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
release()75cdf0e10cSrcweir void SAL_CALL ScCellCursorObj::release() throw()
76cdf0e10cSrcweir {
77cdf0e10cSrcweir     ScCellRangeObj::release();
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
getTypes()80cdf0e10cSrcweir uno::Sequence<uno::Type> SAL_CALL ScCellCursorObj::getTypes() throw(uno::RuntimeException)
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     static uno::Sequence<uno::Type> aTypes;
83cdf0e10cSrcweir     if ( aTypes.getLength() == 0 )
84cdf0e10cSrcweir     {
85cdf0e10cSrcweir         uno::Sequence<uno::Type> aParentTypes(ScCellRangeObj::getTypes());
86cdf0e10cSrcweir         long nParentLen = aParentTypes.getLength();
87cdf0e10cSrcweir         const uno::Type* pParentPtr = aParentTypes.getConstArray();
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         aTypes.realloc( nParentLen + 3 );
90cdf0e10cSrcweir         uno::Type* pPtr = aTypes.getArray();
91cdf0e10cSrcweir         pPtr[nParentLen + 0] = getCppuType((const uno::Reference<sheet::XSheetCellCursor>*)0);
92cdf0e10cSrcweir         pPtr[nParentLen + 1] = getCppuType((const uno::Reference<sheet::XUsedAreaCursor>*)0);
93cdf0e10cSrcweir         pPtr[nParentLen + 2] = getCppuType((const uno::Reference<table::XCellCursor>*)0);
94cdf0e10cSrcweir 
95cdf0e10cSrcweir         for (long i=0; i<nParentLen; i++)
96cdf0e10cSrcweir             pPtr[i] = pParentPtr[i];                // parent types first
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir     return aTypes;
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
getImplementationId()101cdf0e10cSrcweir uno::Sequence<sal_Int8> SAL_CALL ScCellCursorObj::getImplementationId() throw(uno::RuntimeException)
102cdf0e10cSrcweir {
103cdf0e10cSrcweir     static uno::Sequence< sal_Int8 > aId;
104cdf0e10cSrcweir     if( aId.getLength() == 0 )
105cdf0e10cSrcweir     {
106cdf0e10cSrcweir         aId.realloc( 16 );
107cdf0e10cSrcweir         rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
108cdf0e10cSrcweir     }
109cdf0e10cSrcweir     return aId;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir // XSheetCellCursor
113cdf0e10cSrcweir 
collapseToCurrentRegion()114cdf0e10cSrcweir void SAL_CALL ScCellCursorObj::collapseToCurrentRegion() throw(uno::RuntimeException)
115cdf0e10cSrcweir {
116cdf0e10cSrcweir     ScUnoGuard aGuard;
117cdf0e10cSrcweir     const ScRangeList& rRanges = GetRangeList();
118cdf0e10cSrcweir     DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" );
119cdf0e10cSrcweir     ScRange aOneRange(*rRanges.GetObject(0));
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     aOneRange.Justify();
122cdf0e10cSrcweir     ScDocShell* pDocSh = GetDocShell();
123cdf0e10cSrcweir     if ( pDocSh )
124cdf0e10cSrcweir     {
125cdf0e10cSrcweir         SCCOL nStartCol = aOneRange.aStart.Col();
126cdf0e10cSrcweir         SCROW nStartRow = aOneRange.aStart.Row();
127cdf0e10cSrcweir         SCCOL nEndCol = aOneRange.aEnd.Col();
128cdf0e10cSrcweir         SCROW nEndRow = aOneRange.aEnd.Row();
129cdf0e10cSrcweir         SCTAB nTab = aOneRange.aStart.Tab();
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         pDocSh->GetDocument()->GetDataArea(
132cdf0e10cSrcweir                         nTab, nStartCol, nStartRow, nEndCol, nEndRow, sal_True, false );
133cdf0e10cSrcweir 
134cdf0e10cSrcweir         ScRange aNew( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab );
135cdf0e10cSrcweir         SetNewRange( aNew );
136cdf0e10cSrcweir     }
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
collapseToCurrentArray()139cdf0e10cSrcweir void SAL_CALL ScCellCursorObj::collapseToCurrentArray() throw(uno::RuntimeException)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     ScUnoGuard aGuard;
142cdf0e10cSrcweir     const ScRangeList& rRanges = GetRangeList();
143cdf0e10cSrcweir     DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" );
144cdf0e10cSrcweir     ScRange aOneRange(*rRanges.GetObject(0));
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     aOneRange.Justify();
147cdf0e10cSrcweir     ScAddress aCursor(aOneRange.aStart);        //  use the start address of the range
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     ScDocShell* pDocSh = GetDocShell();
150cdf0e10cSrcweir     if ( pDocSh )
151cdf0e10cSrcweir     {
152cdf0e10cSrcweir         ScDocument* pDoc = pDocSh->GetDocument();
153cdf0e10cSrcweir         ScRange aMatrix;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         // finding the matrix range is now in GetMatrixFormulaRange in the document
156cdf0e10cSrcweir         if ( pDoc->GetMatrixFormulaRange( aCursor, aMatrix ) )
157cdf0e10cSrcweir         {
158cdf0e10cSrcweir             SetNewRange( aMatrix );
159cdf0e10cSrcweir         }
160cdf0e10cSrcweir     }
161*cfd52e18Smseidel     // that's a Bug, that this assertion comes; the API Reference says, that
162cdf0e10cSrcweir     // if there is no Matrix, the Range is left unchanged; they says nothing
163cdf0e10cSrcweir     // about a exception
164cdf0e10cSrcweir     /*if (!bFound)
165cdf0e10cSrcweir     {
166cdf0e10cSrcweir         DBG_ERROR("keine Matrix");
167cdf0e10cSrcweir         //! Exception, oder was?
168cdf0e10cSrcweir     }*/
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
collapseToMergedArea()171cdf0e10cSrcweir void SAL_CALL ScCellCursorObj::collapseToMergedArea() throw(uno::RuntimeException)
172cdf0e10cSrcweir {
173cdf0e10cSrcweir     ScUnoGuard aGuard;
174cdf0e10cSrcweir     ScDocShell* pDocSh = GetDocShell();
175cdf0e10cSrcweir     if ( pDocSh )
176cdf0e10cSrcweir     {
177cdf0e10cSrcweir         const ScRangeList& rRanges = GetRangeList();
178cdf0e10cSrcweir         DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" );
179cdf0e10cSrcweir         ScRange aNewRange(*rRanges.GetObject(0));
180cdf0e10cSrcweir 
181cdf0e10cSrcweir         ScDocument* pDoc = pDocSh->GetDocument();
182cdf0e10cSrcweir         pDoc->ExtendOverlapped( aNewRange );
183cdf0e10cSrcweir         pDoc->ExtendMerge( aNewRange );                 // after ExtendOverlapped!
184cdf0e10cSrcweir 
185cdf0e10cSrcweir         SetNewRange( aNewRange );
186cdf0e10cSrcweir     }
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
expandToEntireColumns()189cdf0e10cSrcweir void SAL_CALL ScCellCursorObj::expandToEntireColumns() throw(uno::RuntimeException)
190cdf0e10cSrcweir {
191cdf0e10cSrcweir     ScUnoGuard aGuard;
192cdf0e10cSrcweir     const ScRangeList& rRanges = GetRangeList();
193cdf0e10cSrcweir     DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" );
194cdf0e10cSrcweir     ScRange aNewRange(*rRanges.GetObject(0));
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     aNewRange.aStart.SetRow( 0 );
197cdf0e10cSrcweir     aNewRange.aEnd.SetRow( MAXROW );
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     SetNewRange( aNewRange );
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
expandToEntireRows()202cdf0e10cSrcweir void SAL_CALL ScCellCursorObj::expandToEntireRows() throw(uno::RuntimeException)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir     ScUnoGuard aGuard;
205cdf0e10cSrcweir     const ScRangeList& rRanges = GetRangeList();
206cdf0e10cSrcweir     DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" );
207cdf0e10cSrcweir     ScRange aNewRange(*rRanges.GetObject(0));
208cdf0e10cSrcweir 
209cdf0e10cSrcweir     aNewRange.aStart.SetCol( 0 );
210cdf0e10cSrcweir     aNewRange.aEnd.SetCol( MAXCOL );
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     SetNewRange( aNewRange );
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
collapseToSize(sal_Int32 nColumns,sal_Int32 nRows)215cdf0e10cSrcweir void SAL_CALL ScCellCursorObj::collapseToSize( sal_Int32 nColumns, sal_Int32 nRows )
216cdf0e10cSrcweir                                                 throw(uno::RuntimeException)
217cdf0e10cSrcweir {
218cdf0e10cSrcweir     ScUnoGuard aGuard;
219cdf0e10cSrcweir     if ( nColumns <= 0 || nRows <= 0 )
220cdf0e10cSrcweir     {
221cdf0e10cSrcweir         DBG_ERROR("leerer Range geht nicht");
222cdf0e10cSrcweir         //! und dann?
223cdf0e10cSrcweir     }
224cdf0e10cSrcweir     else
225cdf0e10cSrcweir     {
226cdf0e10cSrcweir         const ScRangeList& rRanges = GetRangeList();
227cdf0e10cSrcweir         DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" );
228cdf0e10cSrcweir         ScRange aNewRange(*rRanges.GetObject(0));
229cdf0e10cSrcweir 
230cdf0e10cSrcweir         aNewRange.Justify();    //! wirklich?
231cdf0e10cSrcweir 
232cdf0e10cSrcweir         long nEndX = aNewRange.aStart.Col() + nColumns - 1;
233cdf0e10cSrcweir         long nEndY = aNewRange.aStart.Row() + nRows - 1;
234cdf0e10cSrcweir         if ( nEndX < 0 )      nEndX = 0;
235cdf0e10cSrcweir         if ( nEndX > MAXCOL ) nEndX = MAXCOL;
236cdf0e10cSrcweir         if ( nEndY < 0 )      nEndY = 0;
237cdf0e10cSrcweir         if ( nEndY > MAXROW ) nEndY = MAXROW;
238cdf0e10cSrcweir         //! Fehler/Exception oder so, wenn zu gross/zu klein?
239cdf0e10cSrcweir 
240cdf0e10cSrcweir         aNewRange.aEnd.SetCol((SCCOL)nEndX);
241cdf0e10cSrcweir         aNewRange.aEnd.SetRow((SCROW)nEndY);
242cdf0e10cSrcweir 
243cdf0e10cSrcweir         aNewRange.Justify();    //! wirklich?
244cdf0e10cSrcweir 
245cdf0e10cSrcweir         SetNewRange( aNewRange );
246cdf0e10cSrcweir     }
247cdf0e10cSrcweir }
248cdf0e10cSrcweir 
249cdf0e10cSrcweir // XUsedAreaCursor
250cdf0e10cSrcweir 
gotoStartOfUsedArea(sal_Bool bExpand)251cdf0e10cSrcweir void SAL_CALL ScCellCursorObj::gotoStartOfUsedArea( sal_Bool bExpand )
252cdf0e10cSrcweir                                             throw(uno::RuntimeException)
253cdf0e10cSrcweir {
254cdf0e10cSrcweir     ScUnoGuard aGuard;
255cdf0e10cSrcweir     ScDocShell* pDocSh = GetDocShell();
256cdf0e10cSrcweir     if ( pDocSh )
257cdf0e10cSrcweir     {
258cdf0e10cSrcweir         const ScRangeList& rRanges = GetRangeList();
259cdf0e10cSrcweir         DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" );
260cdf0e10cSrcweir         ScRange aNewRange(*rRanges.GetObject(0));
261cdf0e10cSrcweir         SCTAB nTab = aNewRange.aStart.Tab();
262cdf0e10cSrcweir 
263cdf0e10cSrcweir         SCCOL nUsedX = 0;       // Anfang holen
264cdf0e10cSrcweir         SCROW nUsedY = 0;
265cdf0e10cSrcweir         if (!pDocSh->GetDocument()->GetDataStart( nTab, nUsedX, nUsedY ))
266cdf0e10cSrcweir         {
267cdf0e10cSrcweir             nUsedX = 0;
268cdf0e10cSrcweir             nUsedY = 0;
269cdf0e10cSrcweir         }
270cdf0e10cSrcweir 
271cdf0e10cSrcweir         aNewRange.aStart.SetCol( nUsedX );
272cdf0e10cSrcweir         aNewRange.aStart.SetRow( nUsedY );
273cdf0e10cSrcweir         if (!bExpand)
274cdf0e10cSrcweir             aNewRange.aEnd = aNewRange.aStart;
275cdf0e10cSrcweir         SetNewRange( aNewRange );
276cdf0e10cSrcweir     }
277cdf0e10cSrcweir }
278cdf0e10cSrcweir 
gotoEndOfUsedArea(sal_Bool bExpand)279cdf0e10cSrcweir void SAL_CALL ScCellCursorObj::gotoEndOfUsedArea( sal_Bool bExpand )
280cdf0e10cSrcweir                                             throw(uno::RuntimeException)
281cdf0e10cSrcweir {
282cdf0e10cSrcweir     ScUnoGuard aGuard;
283cdf0e10cSrcweir     ScDocShell* pDocSh = GetDocShell();
284cdf0e10cSrcweir     if ( pDocSh )
285cdf0e10cSrcweir     {
286cdf0e10cSrcweir         const ScRangeList& rRanges = GetRangeList();
287cdf0e10cSrcweir         DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" );
288cdf0e10cSrcweir         ScRange aNewRange(*rRanges.GetObject(0));
289cdf0e10cSrcweir         SCTAB nTab = aNewRange.aStart.Tab();
290cdf0e10cSrcweir 
291cdf0e10cSrcweir         SCCOL nUsedX = 0;       // Ende holen
292cdf0e10cSrcweir         SCROW nUsedY = 0;
293cdf0e10cSrcweir         if (!pDocSh->GetDocument()->GetTableArea( nTab, nUsedX, nUsedY ))
294cdf0e10cSrcweir         {
295cdf0e10cSrcweir             nUsedX = 0;
296cdf0e10cSrcweir             nUsedY = 0;
297cdf0e10cSrcweir         }
298cdf0e10cSrcweir 
299cdf0e10cSrcweir         aNewRange.aEnd.SetCol( nUsedX );
300cdf0e10cSrcweir         aNewRange.aEnd.SetRow( nUsedY );
301cdf0e10cSrcweir         if (!bExpand)
302cdf0e10cSrcweir             aNewRange.aStart = aNewRange.aEnd;
303cdf0e10cSrcweir         SetNewRange( aNewRange );
304cdf0e10cSrcweir     }
305cdf0e10cSrcweir }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir // XCellCursor
308cdf0e10cSrcweir 
gotoStart()309cdf0e10cSrcweir void SAL_CALL ScCellCursorObj::gotoStart() throw(uno::RuntimeException)
310cdf0e10cSrcweir {
311cdf0e10cSrcweir     //  this is similar to collapseToCurrentRegion
312cdf0e10cSrcweir     //! something like gotoEdge with 4 possible directions is needed
313cdf0e10cSrcweir 
314cdf0e10cSrcweir     ScUnoGuard aGuard;
315cdf0e10cSrcweir     const ScRangeList& rRanges = GetRangeList();
316cdf0e10cSrcweir     DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" );
317cdf0e10cSrcweir     ScRange aOneRange(*rRanges.GetObject(0));
318cdf0e10cSrcweir 
319cdf0e10cSrcweir     aOneRange.Justify();
320cdf0e10cSrcweir     ScDocShell* pDocSh = GetDocShell();
321cdf0e10cSrcweir     if ( pDocSh )
322cdf0e10cSrcweir     {
323cdf0e10cSrcweir         SCCOL nStartCol = aOneRange.aStart.Col();
324cdf0e10cSrcweir         SCROW nStartRow = aOneRange.aStart.Row();
325cdf0e10cSrcweir         SCCOL nEndCol = aOneRange.aEnd.Col();
326cdf0e10cSrcweir         SCROW nEndRow = aOneRange.aEnd.Row();
327cdf0e10cSrcweir         SCTAB nTab = aOneRange.aStart.Tab();
328cdf0e10cSrcweir 
329cdf0e10cSrcweir         pDocSh->GetDocument()->GetDataArea(
330cdf0e10cSrcweir                         nTab, nStartCol, nStartRow, nEndCol, nEndRow, sal_False, false );
331cdf0e10cSrcweir 
332cdf0e10cSrcweir         ScRange aNew( nStartCol, nStartRow, nTab );
333cdf0e10cSrcweir         SetNewRange( aNew );
334cdf0e10cSrcweir     }
335cdf0e10cSrcweir }
336cdf0e10cSrcweir 
gotoEnd()337cdf0e10cSrcweir void SAL_CALL ScCellCursorObj::gotoEnd() throw(uno::RuntimeException)
338cdf0e10cSrcweir {
339cdf0e10cSrcweir     //  this is similar to collapseToCurrentRegion
340cdf0e10cSrcweir     //! something like gotoEdge with 4 possible directions is needed
341cdf0e10cSrcweir 
342cdf0e10cSrcweir     ScUnoGuard aGuard;
343cdf0e10cSrcweir     const ScRangeList& rRanges = GetRangeList();
344cdf0e10cSrcweir     DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" );
345cdf0e10cSrcweir     ScRange aOneRange(*rRanges.GetObject(0));
346cdf0e10cSrcweir 
347cdf0e10cSrcweir     aOneRange.Justify();
348cdf0e10cSrcweir     ScDocShell* pDocSh = GetDocShell();
349cdf0e10cSrcweir     if ( pDocSh )
350cdf0e10cSrcweir     {
351cdf0e10cSrcweir         SCCOL nStartCol = aOneRange.aStart.Col();
352cdf0e10cSrcweir         SCROW nStartRow = aOneRange.aStart.Row();
353cdf0e10cSrcweir         SCCOL nEndCol = aOneRange.aEnd.Col();
354cdf0e10cSrcweir         SCROW nEndRow = aOneRange.aEnd.Row();
355cdf0e10cSrcweir         SCTAB nTab = aOneRange.aStart.Tab();
356cdf0e10cSrcweir 
357cdf0e10cSrcweir         pDocSh->GetDocument()->GetDataArea(
358cdf0e10cSrcweir                         nTab, nStartCol, nStartRow, nEndCol, nEndRow, sal_False, false );
359cdf0e10cSrcweir 
360cdf0e10cSrcweir         ScRange aNew( nEndCol, nEndRow, nTab );
361cdf0e10cSrcweir         SetNewRange( aNew );
362cdf0e10cSrcweir     }
363cdf0e10cSrcweir }
364cdf0e10cSrcweir 
gotoNext()365cdf0e10cSrcweir void SAL_CALL ScCellCursorObj::gotoNext() throw(uno::RuntimeException)
366cdf0e10cSrcweir {
367cdf0e10cSrcweir     ScUnoGuard aGuard;
368cdf0e10cSrcweir     const ScRangeList& rRanges = GetRangeList();
369cdf0e10cSrcweir     DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" );
370cdf0e10cSrcweir     ScRange aOneRange(*rRanges.GetObject(0));
371cdf0e10cSrcweir 
372cdf0e10cSrcweir     aOneRange.Justify();
373cdf0e10cSrcweir     ScAddress aCursor(aOneRange.aStart);        //  bei Block immer den Start nehmen
374cdf0e10cSrcweir 
375cdf0e10cSrcweir     ScMarkData aMark;   // not used with bMarked=FALSE
376cdf0e10cSrcweir     SCCOL nNewX = aCursor.Col();
377cdf0e10cSrcweir     SCROW nNewY = aCursor.Row();
378cdf0e10cSrcweir     SCTAB nTab  = aCursor.Tab();
379cdf0e10cSrcweir     ScDocShell* pDocSh = GetDocShell();
380cdf0e10cSrcweir     if ( pDocSh )
381cdf0e10cSrcweir         pDocSh->GetDocument()->GetNextPos( nNewX,nNewY, nTab,  1,0, sal_False,sal_True, aMark );
382cdf0e10cSrcweir     //! sonst Exception oder so
383cdf0e10cSrcweir 
384cdf0e10cSrcweir     SetNewRange( ScRange( nNewX, nNewY, nTab ) );
385cdf0e10cSrcweir }
386cdf0e10cSrcweir 
gotoPrevious()387cdf0e10cSrcweir void SAL_CALL ScCellCursorObj::gotoPrevious() throw(uno::RuntimeException)
388cdf0e10cSrcweir {
389cdf0e10cSrcweir     ScUnoGuard aGuard;
390cdf0e10cSrcweir     const ScRangeList& rRanges = GetRangeList();
391cdf0e10cSrcweir     DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" );
392cdf0e10cSrcweir     ScRange aOneRange(*rRanges.GetObject(0));
393cdf0e10cSrcweir 
394cdf0e10cSrcweir     aOneRange.Justify();
395cdf0e10cSrcweir     ScAddress aCursor(aOneRange.aStart);        //  bei Block immer den Start nehmen
396cdf0e10cSrcweir 
397cdf0e10cSrcweir     ScMarkData aMark;   // not used with bMarked=FALSE
398cdf0e10cSrcweir     SCCOL nNewX = aCursor.Col();
399cdf0e10cSrcweir     SCROW nNewY = aCursor.Row();
400cdf0e10cSrcweir     SCTAB nTab  = aCursor.Tab();
401cdf0e10cSrcweir     ScDocShell* pDocSh = GetDocShell();
402cdf0e10cSrcweir     if ( pDocSh )
403cdf0e10cSrcweir         pDocSh->GetDocument()->GetNextPos( nNewX,nNewY, nTab, -1,0, sal_False,sal_True, aMark );
404cdf0e10cSrcweir     //! sonst Exception oder so
405cdf0e10cSrcweir 
406cdf0e10cSrcweir     SetNewRange( ScRange( nNewX, nNewY, nTab ) );
407cdf0e10cSrcweir }
408cdf0e10cSrcweir 
gotoOffset(sal_Int32 nColumnOffset,sal_Int32 nRowOffset)409cdf0e10cSrcweir void SAL_CALL ScCellCursorObj::gotoOffset( sal_Int32 nColumnOffset, sal_Int32 nRowOffset )
410cdf0e10cSrcweir                                                 throw(uno::RuntimeException)
411cdf0e10cSrcweir {
412cdf0e10cSrcweir     ScUnoGuard aGuard;
413cdf0e10cSrcweir     const ScRangeList& rRanges = GetRangeList();
414cdf0e10cSrcweir     DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" );
415cdf0e10cSrcweir     ScRange aOneRange(*rRanges.GetObject(0));
416cdf0e10cSrcweir     aOneRange.Justify();
417cdf0e10cSrcweir 
418cdf0e10cSrcweir     if ( aOneRange.aStart.Col() + nColumnOffset >= 0 &&
419cdf0e10cSrcweir          aOneRange.aEnd.Col()   + nColumnOffset <= MAXCOL &&
420cdf0e10cSrcweir          aOneRange.aStart.Row() + nRowOffset    >= 0 &&
421cdf0e10cSrcweir          aOneRange.aEnd.Row()   + nRowOffset    <= MAXROW )
422cdf0e10cSrcweir     {
423cdf0e10cSrcweir         ScRange aNew( (SCCOL)(aOneRange.aStart.Col() + nColumnOffset),
424cdf0e10cSrcweir                       (SCROW)(aOneRange.aStart.Row() + nRowOffset),
425cdf0e10cSrcweir                       aOneRange.aStart.Tab(),
426cdf0e10cSrcweir                       (SCCOL)(aOneRange.aEnd.Col() + nColumnOffset),
427cdf0e10cSrcweir                       (SCROW)(aOneRange.aEnd.Row() + nRowOffset),
428cdf0e10cSrcweir                       aOneRange.aEnd.Tab() );
429cdf0e10cSrcweir         SetNewRange( aNew );
430cdf0e10cSrcweir     }
431cdf0e10cSrcweir }
432cdf0e10cSrcweir 
433cdf0e10cSrcweir // XSheetCellRange
434cdf0e10cSrcweir 
getSpreadsheet()435cdf0e10cSrcweir uno::Reference<sheet::XSpreadsheet> SAL_CALL ScCellCursorObj::getSpreadsheet()
436cdf0e10cSrcweir                                                 throw(uno::RuntimeException)
437cdf0e10cSrcweir {
438cdf0e10cSrcweir     ScUnoGuard aGuard;
439cdf0e10cSrcweir     return ScCellRangeObj::getSpreadsheet();
440cdf0e10cSrcweir }
441cdf0e10cSrcweir 
442cdf0e10cSrcweir // XCellRange
443cdf0e10cSrcweir 
getCellByPosition(sal_Int32 nColumn,sal_Int32 nRow)444cdf0e10cSrcweir uno::Reference<table::XCell> SAL_CALL ScCellCursorObj::getCellByPosition(
445cdf0e10cSrcweir                                         sal_Int32 nColumn, sal_Int32 nRow )
446cdf0e10cSrcweir                                 throw(lang::IndexOutOfBoundsException, uno::RuntimeException)
447cdf0e10cSrcweir {
448cdf0e10cSrcweir     ScUnoGuard aGuard;
449cdf0e10cSrcweir     return ScCellRangeObj::getCellByPosition(nColumn,nRow);
450cdf0e10cSrcweir }
451cdf0e10cSrcweir 
getCellRangeByPosition(sal_Int32 nLeft,sal_Int32 nTop,sal_Int32 nRight,sal_Int32 nBottom)452cdf0e10cSrcweir uno::Reference<table::XCellRange> SAL_CALL ScCellCursorObj::getCellRangeByPosition(
453cdf0e10cSrcweir                 sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom )
454cdf0e10cSrcweir                                 throw(lang::IndexOutOfBoundsException, uno::RuntimeException)
455cdf0e10cSrcweir {
456cdf0e10cSrcweir     ScUnoGuard aGuard;
457cdf0e10cSrcweir     return ScCellRangeObj::getCellRangeByPosition(nLeft,nTop,nRight,nBottom);
458cdf0e10cSrcweir }
459cdf0e10cSrcweir 
getCellRangeByName(const rtl::OUString & rRange)460cdf0e10cSrcweir uno::Reference<table::XCellRange> SAL_CALL ScCellCursorObj::getCellRangeByName(
461cdf0e10cSrcweir                         const rtl::OUString& rRange ) throw(uno::RuntimeException)
462cdf0e10cSrcweir {
463cdf0e10cSrcweir     ScUnoGuard aGuard;
464cdf0e10cSrcweir     return ScCellRangeObj::getCellRangeByName(rRange);
465cdf0e10cSrcweir }
466cdf0e10cSrcweir 
467cdf0e10cSrcweir // XServiceInfo
468cdf0e10cSrcweir 
getImplementationName()469cdf0e10cSrcweir rtl::OUString SAL_CALL ScCellCursorObj::getImplementationName() throw(uno::RuntimeException)
470cdf0e10cSrcweir {
471cdf0e10cSrcweir     return rtl::OUString::createFromAscii( "ScCellCursorObj" );
472cdf0e10cSrcweir }
473cdf0e10cSrcweir 
supportsService(const rtl::OUString & rServiceName)474cdf0e10cSrcweir sal_Bool SAL_CALL ScCellCursorObj::supportsService( const rtl::OUString& rServiceName )
475cdf0e10cSrcweir                                                     throw(uno::RuntimeException)
476cdf0e10cSrcweir {
477cdf0e10cSrcweir     String aServiceStr( rServiceName );
478cdf0e10cSrcweir     return aServiceStr.EqualsAscii( SCSHEETCELLCURSOR_SERVICE ) ||
479cdf0e10cSrcweir            aServiceStr.EqualsAscii( SCCELLCURSOR_SERVICE ) ||
480cdf0e10cSrcweir            ScCellRangeObj::supportsService(rServiceName);
481cdf0e10cSrcweir }
482cdf0e10cSrcweir 
getSupportedServiceNames()483cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL ScCellCursorObj::getSupportedServiceNames()
484cdf0e10cSrcweir                                                     throw(uno::RuntimeException)
485cdf0e10cSrcweir {
486cdf0e10cSrcweir     //  get all service names from cell range
487cdf0e10cSrcweir     uno::Sequence<rtl::OUString> aParentSeq(ScCellRangeObj::getSupportedServiceNames());
488cdf0e10cSrcweir     sal_Int32 nParentLen = aParentSeq.getLength();
489cdf0e10cSrcweir     const rtl::OUString* pParentArr = aParentSeq.getConstArray();
490cdf0e10cSrcweir 
491cdf0e10cSrcweir     //  SheetCellCursor should be first (?)
492cdf0e10cSrcweir     uno::Sequence<rtl::OUString> aTotalSeq( nParentLen + 2 );
493cdf0e10cSrcweir     rtl::OUString* pTotalArr = aTotalSeq.getArray();
494cdf0e10cSrcweir     pTotalArr[0] = rtl::OUString::createFromAscii( SCSHEETCELLCURSOR_SERVICE );
495cdf0e10cSrcweir     pTotalArr[1] = rtl::OUString::createFromAscii( SCCELLCURSOR_SERVICE );
496cdf0e10cSrcweir 
497cdf0e10cSrcweir     //  append cell range services
498cdf0e10cSrcweir     for (long i=0; i<nParentLen; i++)
499cdf0e10cSrcweir         pTotalArr[i+2] = pParentArr[i];
500cdf0e10cSrcweir 
501cdf0e10cSrcweir     return aTotalSeq;
502cdf0e10cSrcweir }
503