merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / view / viewdata.cxx
blobba0e03d0fc0d033c6210a36bde6e3be9f4c9e8ca
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewdata.cxx,v $
10 * $Revision: 1.65.24.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #include "scitems.hxx"
39 #include <svx/eeitem.hxx>
42 #include <sfx2/viewfrm.hxx>
43 #include <svx/adjitem.hxx>
44 #include <svx/algitem.hxx>
45 #include <svx/brshitem.hxx>
46 #include <svtools/colorcfg.hxx>
47 #include <svx/editview.hxx>
48 #include <svx/editstat.hxx>
49 #include <svx/outliner.hxx>
50 #include <svx/unolingu.hxx>
52 #include <vcl/svapp.hxx>
53 #include <rtl/math.hxx>
55 #include "viewdata.hxx"
56 #include "docoptio.hxx"
57 #include "scmod.hxx"
58 #include "global.hxx"
59 #include "document.hxx"
60 #include "attrib.hxx"
61 #include "tabview.hxx"
62 #include "tabvwsh.hxx"
63 #include "docsh.hxx"
64 #include "sc.hrc"
65 #include "patattr.hxx"
66 #include "editutil.hxx"
67 #include "scextopt.hxx"
68 #include "miscuno.hxx"
69 #include "unonames.hxx"
70 #include "inputopt.hxx"
71 #include "viewutil.hxx"
72 #include <xmloff/xmluconv.hxx>
73 #include "ViewSettingsSequenceDefines.hxx"
74 #include <rtl/ustrbuf.hxx>
75 #include <comphelper/processfactory.hxx>
76 #include <com/sun/star/container/XNameContainer.hpp>
78 using namespace com::sun::star;
80 // STATIC DATA -----------------------------------------------------------
82 #define SC_GROWY_SMALL_EXTRA 100
83 #define SC_GROWY_BIG_EXTRA 200
85 #define TAG_TABBARWIDTH "tw:"
87 static BOOL bMoveArea = FALSE; //! Member?
88 USHORT nEditAdjust = SVX_ADJUST_LEFT; //! Member !!!
90 //==================================================================
92 ScViewDataTable::ScViewDataTable() :
93 eZoomType( SVX_ZOOM_PERCENT ),
94 aZoomX( 1,1 ),
95 aZoomY( 1,1 ),
96 aPageZoomX( 3,5 ), // Page-Default: 60%
97 aPageZoomY( 3,5 ),
98 nHSplitPos( 0 ),
99 nVSplitPos( 0 ),
100 eHSplitMode( SC_SPLIT_NONE ),
101 eVSplitMode( SC_SPLIT_NONE ),
102 eWhichActive( SC_SPLIT_BOTTOMLEFT ),
103 nFixPosX( 0 ),
104 nFixPosY( 0 ),
105 nCurX( 0 ),
106 nCurY( 0 ),
107 bShowGrid( true ),
108 bOldCurValid( FALSE ),
109 aTabBgColor( Color(COL_AUTO) )
111 nPosX[0]=nPosX[1]=0;
112 nPosY[0]=nPosY[1]=0;
113 nTPosX[0]=nTPosX[1]=0;
114 nTPosY[0]=nTPosY[1]=0;
115 nMPosX[0]=nMPosX[1]=0;
116 nMPosY[0]=nMPosY[1]=0;
117 nPixPosX[0]=nPixPosX[1]=0;
118 nPixPosY[0]=nPixPosY[1]=0;
121 ScViewDataTable::~ScViewDataTable()
125 void ScViewDataTable::WriteUserDataSequence(uno::Sequence <beans::PropertyValue>& rSettings, const ScViewData& /*rViewData*/, SCTAB /*nTab*/)
127 rSettings.realloc(SC_TABLE_VIEWSETTINGS_COUNT);
128 beans::PropertyValue* pSettings = rSettings.getArray();
129 if (pSettings)
131 pSettings[SC_CURSOR_X].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_CURSORPOSITIONX));
132 pSettings[SC_CURSOR_X].Value <<= sal_Int32(nCurX);
133 pSettings[SC_CURSOR_Y].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_CURSORPOSITIONY));
134 pSettings[SC_CURSOR_Y].Value <<= sal_Int32(nCurY);
135 pSettings[SC_HORIZONTAL_SPLIT_MODE].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_HORIZONTALSPLITMODE));
136 pSettings[SC_HORIZONTAL_SPLIT_MODE].Value <<= sal_Int16(eHSplitMode);
137 pSettings[SC_VERTICAL_SPLIT_MODE].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_VERTICALSPLITMODE));
138 pSettings[SC_VERTICAL_SPLIT_MODE].Value <<= sal_Int16(eVSplitMode);
139 pSettings[SC_HORIZONTAL_SPLIT_POSITION].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_HORIZONTALSPLITPOSITION));
140 if (eHSplitMode == SC_SPLIT_FIX)
141 pSettings[SC_HORIZONTAL_SPLIT_POSITION].Value <<= sal_Int32(nFixPosX);
142 else
143 pSettings[SC_HORIZONTAL_SPLIT_POSITION].Value <<= sal_Int32(nHSplitPos);
144 pSettings[SC_VERTICAL_SPLIT_POSITION].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_VERTICALSPLITPOSITION));
145 if (eVSplitMode == SC_SPLIT_FIX)
146 pSettings[SC_VERTICAL_SPLIT_POSITION].Value <<= sal_Int32(nFixPosY);
147 else
148 pSettings[SC_VERTICAL_SPLIT_POSITION].Value <<= sal_Int32(nVSplitPos);
149 pSettings[SC_ACTIVE_SPLIT_RANGE].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ACTIVESPLITRANGE));
150 pSettings[SC_ACTIVE_SPLIT_RANGE].Value <<= sal_Int16(eWhichActive);
151 pSettings[SC_POSITION_LEFT].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_POSITIONLEFT));
152 pSettings[SC_POSITION_LEFT].Value <<= sal_Int32(nPosX[SC_SPLIT_LEFT]);
153 pSettings[SC_POSITION_RIGHT].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_POSITIONRIGHT));
154 pSettings[SC_POSITION_RIGHT].Value <<= sal_Int32(nPosX[SC_SPLIT_RIGHT]);
155 pSettings[SC_POSITION_TOP].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_POSITIONTOP));
156 pSettings[SC_POSITION_TOP].Value <<= sal_Int32(nPosY[SC_SPLIT_TOP]);
157 pSettings[SC_POSITION_BOTTOM].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_POSITIONBOTTOM));
158 pSettings[SC_POSITION_BOTTOM].Value <<= sal_Int32(nPosY[SC_SPLIT_BOTTOM]);
160 sal_Int32 nZoomValue ((aZoomY.GetNumerator() * 100) / aZoomY.GetDenominator());
161 sal_Int32 nPageZoomValue ((aPageZoomY.GetNumerator() * 100) / aPageZoomY.GetDenominator());
162 pSettings[SC_TABLE_ZOOM_TYPE].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ZOOMTYPE));
163 pSettings[SC_TABLE_ZOOM_TYPE].Value <<= sal_Int16(eZoomType);
164 pSettings[SC_TABLE_ZOOM_VALUE].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ZOOMVALUE));
165 pSettings[SC_TABLE_ZOOM_VALUE].Value <<= nZoomValue;
166 pSettings[SC_TABLE_PAGE_VIEW_ZOOM_VALUE].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_PAGEVIEWZOOMVALUE));
167 pSettings[SC_TABLE_PAGE_VIEW_ZOOM_VALUE].Value <<= nPageZoomValue;
169 pSettings[SC_TABLE_SHOWGRID].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_SHOWGRID));
170 pSettings[SC_TABLE_SHOWGRID].Value <<= static_cast<sal_Bool>(bShowGrid);
173 if ( !IsDefaultTabBgColor() )
175 pSettings[SC_TABLE_TAB_BG_COLOR].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_TABCOLOR));
176 pSettings[SC_TABLE_TAB_BG_COLOR].Value <<= static_cast<sal_Int32>(aTabBgColor.GetColor());
178 // pSettings[SC_TABLE_SELECTED].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_TABLESELECTED));
179 // pSettings[SC_TABLE_SELECTED].Value <<= bool(rViewData.GetMarkData().GetTableSelect( nTab ));
183 void ScViewDataTable::ReadUserDataSequence(const uno::Sequence <beans::PropertyValue>& aSettings, ScViewData& rViewData, SCTAB nTab, bool& rHasZoom )
185 rHasZoom = false;
187 sal_Int32 nCount(aSettings.getLength());
188 sal_Int32 nTemp32(0);
189 sal_Int16 nTemp16(0);
190 sal_Int32 nTempPosV(0);
191 sal_Int32 nTempPosH(0);
192 sal_Int32 nTempPosVTw(0);
193 sal_Int32 nTempPosHTw(0);
194 bool bHasVSplitInTwips = false;
195 bool bHasHSplitInTwips = false;
196 for (sal_Int32 i = 0; i < nCount; i++)
198 rtl::OUString sName(aSettings[i].Name);
199 if (sName.compareToAscii(SC_CURSORPOSITIONX) == 0)
201 aSettings[i].Value >>= nTemp32;
202 nCurX = SanitizeCol( static_cast<SCCOL>(nTemp32));
204 else if (sName.compareToAscii(SC_CURSORPOSITIONY) == 0)
206 aSettings[i].Value >>= nTemp32;
207 nCurY = SanitizeRow( static_cast<SCROW>(nTemp32));
209 else if (sName.compareToAscii(SC_HORIZONTALSPLITMODE) == 0)
211 aSettings[i].Value >>= nTemp16;
212 eHSplitMode = static_cast<ScSplitMode>(nTemp16);
214 else if (sName.compareToAscii(SC_VERTICALSPLITMODE) == 0)
216 aSettings[i].Value >>= nTemp16;
217 eVSplitMode = static_cast<ScSplitMode>(nTemp16);
219 else if (sName.compareToAscii(SC_HORIZONTALSPLITPOSITION) == 0)
221 aSettings[i].Value >>= nTempPosH;
222 bHasHSplitInTwips = false;
224 else if (sName.compareToAscii(SC_VERTICALSPLITPOSITION) == 0)
226 aSettings[i].Value >>= nTempPosV;
227 bHasVSplitInTwips = false;
229 else if (sName.compareToAscii(SC_HORIZONTALSPLITPOSITION_TWIPS) == 0)
231 aSettings[i].Value >>= nTempPosHTw;
232 bHasHSplitInTwips = true;
234 else if (sName.compareToAscii(SC_VERTICALSPLITPOSITION_TWIPS) == 0)
236 aSettings[i].Value >>= nTempPosVTw;
237 bHasVSplitInTwips = true;
239 else if (sName.compareToAscii(SC_ACTIVESPLITRANGE) == 0)
241 aSettings[i].Value >>= nTemp16;
242 eWhichActive = static_cast<ScSplitPos>(nTemp16);
244 else if (sName.compareToAscii(SC_POSITIONLEFT) == 0)
246 aSettings[i].Value >>= nTemp32;
247 nPosX[SC_SPLIT_LEFT] = SanitizeCol( static_cast<SCCOL>(nTemp32));
249 else if (sName.compareToAscii(SC_POSITIONRIGHT) == 0)
251 aSettings[i].Value >>= nTemp32;
252 nPosX[SC_SPLIT_RIGHT] = SanitizeCol( static_cast<SCCOL>(nTemp32));
254 else if (sName.compareToAscii(SC_POSITIONTOP) == 0)
256 aSettings[i].Value >>= nTemp32;
257 nPosY[SC_SPLIT_TOP] = SanitizeRow( static_cast<SCROW>(nTemp32));
259 else if (sName.compareToAscii(SC_POSITIONBOTTOM) == 0)
261 aSettings[i].Value >>= nTemp32;
262 nPosY[SC_SPLIT_BOTTOM] = SanitizeRow( static_cast<SCROW>(nTemp32));
264 else if (sName.compareToAscii(SC_ZOOMTYPE) == 0)
266 aSettings[i].Value >>= nTemp16;
267 eZoomType = SvxZoomType(nTemp16);
268 rHasZoom = true; // set if there is any zoom information
270 else if (sName.compareToAscii(SC_ZOOMVALUE) == 0)
272 aSettings[i].Value >>= nTemp32;
273 Fraction aZoom(nTemp32, 100);
274 aZoomX = aZoomY = aZoom;
275 rHasZoom = true;
277 else if (sName.compareToAscii(SC_PAGEVIEWZOOMVALUE) == 0)
279 aSettings[i].Value >>= nTemp32;
280 Fraction aZoom(nTemp32, 100);
281 aPageZoomX = aPageZoomY = aZoom;
282 rHasZoom = true;
284 else if (sName.compareToAscii(SC_UNO_SHOWGRID) == 0)
286 aSettings[i].Value >>= bShowGrid;
288 else if (sName.compareToAscii(SC_TABLESELECTED) == 0)
290 bool bSelected = false;
291 aSettings[i].Value >>= bSelected;
292 rViewData.GetMarkData().SelectTable( nTab, bSelected );
294 else if (sName.compareToAscii(SC_UNO_TABCOLOR) == 0)
296 sal_Int32 nColor = COL_AUTO;
297 aSettings[i].Value >>= nColor;
298 if (nColor != COL_AUTO)
299 aTabBgColor.SetColor(static_cast<ColorData>(nColor));
302 if (eHSplitMode == SC_SPLIT_FIX)
303 nFixPosX = SanitizeCol( static_cast<SCCOL>( bHasHSplitInTwips ? nTempPosHTw : nTempPosH ));
304 else
305 nHSplitPos = bHasHSplitInTwips ? static_cast< long >( nTempPosHTw * rViewData.GetPPTX() ) : nTempPosH;
307 if (eVSplitMode == SC_SPLIT_FIX)
308 nFixPosY = SanitizeRow( static_cast<SCROW>( bHasVSplitInTwips ? nTempPosVTw : nTempPosV ));
309 else
310 nVSplitPos = bHasVSplitInTwips ? static_cast< long >( nTempPosVTw * rViewData.GetPPTY() ) : nTempPosV;
313 //==================================================================
315 ScViewData::ScViewData( ScDocShell* pDocSh, ScTabViewShell* pViewSh )
316 : pDocShell ( pDocSh ),
317 pDoc ( NULL ),
318 pView ( pViewSh ),
319 pViewShell ( pViewSh ),
320 pOptions ( new ScViewOptions ),
321 pSpellingView ( NULL ),
322 aLogicMode ( MAP_100TH_MM ),
323 eDefZoomType( SVX_ZOOM_PERCENT ),
324 aDefZoomX ( 1,1 ),
325 aDefZoomY ( 1,1 ),
326 aDefPageZoomX( 3,5 ),
327 aDefPageZoomY( 3,5 ),
328 eRefType ( SC_REFTYPE_NONE ),
329 nTabNo ( 0 ),
330 nRefTabNo ( 0 ),
331 nPasteFlags ( SC_PASTE_NONE ),
332 eEditActivePart( SC_SPLIT_BOTTOMLEFT ),
333 bActive ( TRUE ), //! wie initialisieren?
334 bIsRefMode ( FALSE ),
335 bDelMarkValid( FALSE ),
336 nFillMode ( SC_FILL_NONE ),
337 bPagebreak ( FALSE ),
338 bSelCtrlMouseClick( FALSE )
341 SetGridMode ( TRUE );
342 SetSyntaxMode ( FALSE );
343 SetHeaderMode ( TRUE );
344 SetTabMode ( TRUE );
345 SetVScrollMode ( TRUE );
346 SetHScrollMode ( TRUE );
347 SetOutlineMode ( TRUE );
349 aScrSize = Size( (long) ( STD_COL_WIDTH * PIXEL_PER_TWIPS * OLE_STD_CELLS_X ),
350 (long) ( ScGlobal::nStdRowHeight * PIXEL_PER_TWIPS * OLE_STD_CELLS_Y ) );
351 pTabData[0] = new ScViewDataTable;
352 for ( SCTAB i = 1; i <= MAXTAB; i++ )
353 pTabData[i] = NULL;
354 pThisTab = pTabData[nTabNo];
355 for (USHORT j=0; j<4; j++)
357 pEditView[j] = NULL;
358 bEditActive[j] = FALSE;
361 nEditEndCol = nEditStartCol = nEditCol = 0;
362 nEditEndRow = nEditRow = 0;
363 nTabStartCol = SC_TABSTART_NONE;
365 if (pDocShell)
367 pDoc = pDocShell->GetDocument();
368 *pOptions = pDoc->GetViewOptions();
371 // keine ausgeblendete Tabelle anzeigen:
372 if (pDoc && !pDoc->IsVisible(nTabNo))
374 while ( !pDoc->IsVisible(nTabNo) && pDoc->HasTable(nTabNo+1) )
375 ++nTabNo;
377 pTabData[nTabNo] = new ScViewDataTable;
378 pThisTab = pTabData[nTabNo];
381 CalcPPT();
384 ScViewData::ScViewData( const ScViewData& rViewData )
385 : pDocShell ( rViewData.pDocShell ),
386 pDoc ( rViewData.pDoc ),
387 pView ( rViewData.pView ),
388 pViewShell ( rViewData.pViewShell ),
389 pOptions ( new ScViewOptions( *(rViewData.pOptions) ) ),
390 pSpellingView ( rViewData.pSpellingView ),
391 aLogicMode ( rViewData.aLogicMode ),
392 eDefZoomType( rViewData.eDefZoomType ),
393 aDefZoomX ( rViewData.aDefZoomX ),
394 aDefZoomY ( rViewData.aDefZoomY ),
395 aDefPageZoomX( rViewData.aDefPageZoomX ),
396 aDefPageZoomY( rViewData.aDefPageZoomY ),
397 eRefType ( SC_REFTYPE_NONE ),
398 nTabNo ( rViewData.nTabNo ),
399 nRefTabNo ( rViewData.nTabNo ), // kein RefMode
400 eEditActivePart( rViewData.eEditActivePart ),
401 bActive ( TRUE ), //! wie initialisieren?
402 bIsRefMode ( FALSE ),
403 bDelMarkValid( FALSE ),
404 nFillMode ( SC_FILL_NONE ),
405 bPagebreak ( rViewData.bPagebreak ),
406 bSelCtrlMouseClick( rViewData.bSelCtrlMouseClick )
409 SetGridMode ( rViewData.IsGridMode() );
410 SetSyntaxMode ( rViewData.IsSyntaxMode() );
411 SetHeaderMode ( rViewData.IsHeaderMode() );
412 SetTabMode ( rViewData.IsTabMode() );
413 SetVScrollMode ( rViewData.IsVScrollMode() );
414 SetHScrollMode ( rViewData.IsHScrollMode() );
415 SetOutlineMode ( rViewData.IsOutlineMode() );
417 aScrSize = rViewData.aScrSize;
418 for ( SCTAB i = 0; i <= MAXTAB; i++ )
419 if (rViewData.pTabData[i])
420 pTabData[i] = new ScViewDataTable( *rViewData.pTabData[i] );
421 else
422 pTabData[i] = NULL;
423 pThisTab = pTabData[nTabNo];
424 for (USHORT j=0; j<4; j++)
426 pEditView[j] = NULL;
427 bEditActive[j] = FALSE;
430 nEditEndCol = nEditStartCol = nEditCol = 0;
431 nEditEndRow = nEditRow = 0;
432 nTabStartCol = SC_TABSTART_NONE;
433 CalcPPT();
436 void ScViewData::InitData( ScDocument* pDocument )
438 pDoc = pDocument;
439 *pOptions = pDoc->GetViewOptions();
442 //UNUSED2008-05 void ScViewData::InitFrom( const ScViewData* pRef )
443 //UNUSED2008-05 {
444 //UNUSED2008-05 if (pRef==NULL)
445 //UNUSED2008-05 {
446 //UNUSED2008-05 DBG_ERROR("ScViewData::InitFrom mit NULL");
447 //UNUSED2008-05 return;
448 //UNUSED2008-05 }
449 //UNUSED2008-05
450 //UNUSED2008-05 aScrSize = pRef->aScrSize;
451 //UNUSED2008-05 nTabNo = pRef->nTabNo;
452 //UNUSED2008-05 eDefZoomType = pRef->eDefZoomType;
453 //UNUSED2008-05 aDefZoomX = pRef->aDefZoomX;
454 //UNUSED2008-05 aDefZoomY = pRef->aDefZoomY;
455 //UNUSED2008-05 aDefPageZoomX = pRef->aDefPageZoomX;
456 //UNUSED2008-05 aDefPageZoomY = pRef->aDefPageZoomY;
457 //UNUSED2008-05 bPagebreak = pRef->bPagebreak;
458 //UNUSED2008-05 aLogicMode = pRef->aLogicMode;
459 //UNUSED2008-05
460 //UNUSED2008-05 SetGridMode ( pRef->IsGridMode() );
461 //UNUSED2008-05 SetSyntaxMode ( pRef->IsSyntaxMode() );
462 //UNUSED2008-05 SetHeaderMode ( pRef->IsHeaderMode() );
463 //UNUSED2008-05 SetTabMode ( pRef->IsTabMode() );
464 //UNUSED2008-05 SetVScrollMode ( pRef->IsVScrollMode() );
465 //UNUSED2008-05 SetHScrollMode ( pRef->IsHScrollMode() );
466 //UNUSED2008-05 SetOutlineMode ( pRef->IsOutlineMode() );
467 //UNUSED2008-05
468 //UNUSED2008-05 for (SCTAB i=0; i<=MAXTAB; i++)
469 //UNUSED2008-05 {
470 //UNUSED2008-05 delete pTabData[i];
471 //UNUSED2008-05 if (pRef->pTabData[i])
472 //UNUSED2008-05 pTabData[i] = new ScViewDataTable( *pRef->pTabData[i] );
473 //UNUSED2008-05 else
474 //UNUSED2008-05 pTabData[i] = NULL;
475 //UNUSED2008-05 }
476 //UNUSED2008-05 pThisTab = pTabData[nTabNo];
477 //UNUSED2008-05 CalcPPT();
478 //UNUSED2008-05 }
479 //UNUSED2008-05
480 //UNUSED2008-05 void ScViewData::SetDocShell( ScDocShell* pShell )
481 //UNUSED2008-05 {
482 //UNUSED2008-05 pDocShell = pShell;
483 //UNUSED2008-05 pDoc = pDocShell->GetDocument();
484 //UNUSED2008-05 *pOptions = pDoc->GetViewOptions();
485 //UNUSED2008-05 CalcPPT();
486 //UNUSED2008-05 }
488 ScDocument* ScViewData::GetDocument() const
490 if (pDoc)
491 return pDoc;
492 else if (pDocShell)
493 return pDocShell->GetDocument();
495 DBG_ERROR("kein Document an ViewData");
496 return NULL;
499 ScViewData::~ScViewData()
501 for (SCTAB i=0; i<=MAXTAB; i++)
502 if (pTabData[i])
503 delete pTabData[i];
505 KillEditView();
506 delete pOptions;
509 void ScViewData::UpdateThis()
513 pThisTab = pTabData[nTabNo];
514 if (!pThisTab)
516 if (nTabNo>0)
517 --nTabNo;
518 else
519 pThisTab = pTabData[0] = new ScViewDataTable;
521 // hier keine Assertion, weil sonst Paints kommen, bevor alles initialisiert ist!
524 while (!pThisTab);
527 void ScViewData::InsertTab( SCTAB nTab )
529 delete pTabData[MAXTAB];
531 for (SCTAB i=MAXTAB; i>nTab; i--)
532 pTabData[i] = pTabData[i-1];
534 pTabData[nTab] = NULL; // force creating new
535 CreateTabData( nTab );
537 UpdateThis();
538 aMarkData.InsertTab( nTab );
541 void ScViewData::DeleteTab( SCTAB nTab )
543 delete pTabData[nTab];
545 for (SCTAB i=nTab; i<MAXTAB; i++)
546 pTabData[i] = pTabData[i+1];
548 pTabData[MAXTAB] = NULL;
550 UpdateThis();
551 aMarkData.DeleteTab( nTab );
554 void ScViewData::CopyTab( SCTAB nSrcTab, SCTAB nDestTab )
556 if (nDestTab==SC_TAB_APPEND)
557 nDestTab = pDoc->GetTableCount() - 1; // am Doc muss vorher kopiert worden sein
559 if (nDestTab > MAXTAB)
561 DBG_ERROR("Zuviele Tabellen");
562 return;
565 delete pTabData[MAXTAB];
567 for (SCTAB i=MAXTAB; i>nDestTab; i--)
568 pTabData[i] = pTabData[i-1];
570 if ( pTabData[nSrcTab] )
571 pTabData[nDestTab] = new ScViewDataTable( *pTabData[nSrcTab] );
572 else
573 pTabData[nDestTab] = NULL;
575 UpdateThis();
576 aMarkData.InsertTab( nDestTab );
579 void ScViewData::MoveTab( SCTAB nSrcTab, SCTAB nDestTab )
581 if (nDestTab==SC_TAB_APPEND)
582 nDestTab = pDoc->GetTableCount() - 1;
584 SCTAB i;
585 ScViewDataTable* pTab = pTabData[nSrcTab];
587 SCTAB nInsTab = nDestTab;
588 if ( nSrcTab < nDestTab )
590 --nInsTab;
591 for (i=nSrcTab; i<nDestTab; i++)
592 pTabData[i] = pTabData[i+1];
594 else
595 for (i=nSrcTab; i>nDestTab; i--)
596 pTabData[i] = pTabData[i-1];
598 pTabData[nDestTab] = pTab;
600 UpdateThis();
601 aMarkData.DeleteTab( nSrcTab );
602 aMarkData.InsertTab( nInsTab ); // ggf. angepasst
605 void ScViewData::SetTabBgColor( Color rTabBgColor, SCTAB nTab )
607 if ( rTabBgColor != Color(COL_AUTO) )
609 if ( !pTabData[nTab] )
610 CreateTabData( nTab );
611 pTabData[nTab]->aTabBgColor = rTabBgColor;
613 else
615 if ( pTabData[nTab] )
616 pTabData[nTab]->aTabBgColor = Color( COL_AUTO );
620 Color ScViewData::GetTabBgColor( SCTAB nTab ) const
622 if ( !pTabData[nTab] )
623 return Color(COL_AUTO);
624 return pTabData[nTab]->aTabBgColor;
627 BOOL ScViewData::IsDefaultTabBgColor( SCTAB nTab ) const
629 if ( !pTabData[nTab] )
630 return true;
631 BOOL bResult = pTabData[nTab]->aTabBgColor==Color( COL_AUTO ) ? TRUE : FALSE;
632 return bResult;
635 //UNUSED2008-05 void ScViewData::UpdateOle( ScSplitPos /* eWhich */ )
636 //UNUSED2008-05 {
637 //UNUSED2008-05 GetDocShell()->UpdateOle(this);
638 //UNUSED2008-05 }
640 void ScViewData::SetViewShell( ScTabViewShell* pViewSh )
642 if (pViewSh)
644 pViewShell = pViewSh;
645 pView = pViewSh;
647 else
649 pViewShell = NULL;
650 pView = NULL;
653 void ScViewData::CreateTabData( std::vector< SCTAB >& rvTabs )
655 std::vector< SCTAB >::iterator it_end = rvTabs.end();
656 for ( std::vector< SCTAB >::iterator it = rvTabs.begin(); it != it_end; ++it )
657 if ( !pTabData[*it] )
658 CreateTabData( *it );
661 void ScViewData::SetZoomType( SvxZoomType eNew, std::vector< SCTAB >& tabs )
663 BOOL bAll = ( tabs.size() == 0 );
665 if ( !bAll ) // create associated table data
666 CreateTabData( tabs );
668 std::vector< SCTAB >::iterator it_end = tabs.end();
669 std::vector< SCTAB >::iterator it = tabs.begin();
670 for ( SCTAB i = ( bAll ? 0 : *it ); ( bAll ? i <= MAXTAB : it != it_end ); ++i , ++it )
672 if ( pTabData[i] )
673 pTabData[i]->eZoomType = eNew;
676 if ( bAll )
677 eDefZoomType = eNew;
680 void ScViewData::SetZoomType( SvxZoomType eNew, BOOL bAll )
682 std::vector< SCTAB > vTabs; // Empty for all tabs
683 if ( !bAll ) // get selected tabs
685 SCTAB nTabCount = pDoc->GetTableCount();
686 for (SCTAB i=0; i<nTabCount; i++)
688 if ( aMarkData.GetTableSelect(i) )
689 vTabs.push_back( i );
692 SetZoomType( eNew, vTabs );
695 void ScViewData::SetZoom( const Fraction& rNewX, const Fraction& rNewY, std::vector< SCTAB >& tabs )
697 BOOL bAll = ( tabs.size() == 0 );
698 if ( !bAll ) // create associated table data
699 CreateTabData( tabs );
700 Fraction aFrac20( 1,5 );
701 Fraction aFrac400( 4,1 );
703 Fraction aValidX = rNewX;
704 if (aValidX<aFrac20)
705 aValidX = aFrac20;
706 if (aValidX>aFrac400)
707 aValidX = aFrac400;
709 Fraction aValidY = rNewY;
710 if (aValidY<aFrac20)
711 aValidY = aFrac20;
712 if (aValidY>aFrac400)
713 aValidY = aFrac400;
715 std::vector< SCTAB >::iterator it_end = tabs.end();
716 std::vector< SCTAB >::iterator it = tabs.begin();
718 for ( SCTAB i = ( bAll ? 0 : *it ); ( bAll ? i <= MAXTAB : it != it_end ); ++i , ++it )
720 if ( pTabData[i] )
722 if ( bPagebreak )
724 pTabData[i]->aPageZoomX = aValidX;
725 pTabData[i]->aPageZoomY = aValidY;
727 else
729 pTabData[i]->aZoomX = aValidX;
730 pTabData[i]->aZoomY = aValidY;
734 RefreshZoom();
737 void ScViewData::SetZoom( const Fraction& rNewX, const Fraction& rNewY, BOOL bAll )
739 std::vector< SCTAB > vTabs;
740 if ( !bAll ) // get selected tabs
742 SCTAB nTabCount = pDoc->GetTableCount();
743 for (SCTAB i=0; i<nTabCount; i++)
745 if ( aMarkData.GetTableSelect(i) )
746 vTabs.push_back( i );
749 SetZoom( rNewX, rNewY, vTabs );
752 void ScViewData::SetShowGrid( bool bShow )
754 CreateSelectedTabData();
755 pTabData[nTabNo]->bShowGrid = bShow;
758 void ScViewData::RefreshZoom()
760 // recalculate zoom-dependent values (only for current sheet)
762 CalcPPT();
763 RecalcPixPos();
764 aScenButSize = Size(0,0);
765 aLogicMode.SetScaleX( GetZoomX() );
766 aLogicMode.SetScaleY( GetZoomY() );
769 void ScViewData::MoveNextRow()
771 ScRange aMarkRange;
772 aMarkData.GetMarkArea(aMarkRange);
773 aMarkRange.aStart.Set(aMarkRange.aStart.Col(), aMarkRange.aStart.Row() +1, aMarkRange.aStart.Tab());
774 aMarkData.SetMarkArea(aMarkRange);
777 void ScViewData::MovePrevRow()
779 ScRange aMarkRange;
780 aMarkData.GetMarkArea(aMarkRange);
781 aMarkRange.aStart.Set(aMarkRange.aStart.Col(), aMarkRange.aStart.Row() -1, aMarkRange.aStart.Tab());
782 aMarkData.SetMarkArea(aMarkRange);
785 void ScViewData::SetPagebreakMode( BOOL bSet )
787 bPagebreak = bSet;
789 RefreshZoom();
793 ScMarkType ScViewData::GetSimpleArea( ScRange & rRange, ScMarkData & rNewMark ) const
795 ScMarkType eMarkType = SC_MARK_NONE;
797 if ( rNewMark.IsMarked() || rNewMark.IsMultiMarked() )
799 if ( rNewMark.IsMultiMarked() )
800 rNewMark.MarkToSimple();
802 if ( rNewMark.IsMarked() && !rNewMark.IsMultiMarked() )
804 rNewMark.GetMarkArea( rRange );
805 if (ScViewUtil::HasFiltered( rRange, GetDocument()))
806 eMarkType = SC_MARK_SIMPLE_FILTERED;
807 else
808 eMarkType = SC_MARK_SIMPLE;
810 else
811 eMarkType = SC_MARK_MULTI;
813 if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED)
815 if (eMarkType == SC_MARK_NONE)
816 eMarkType = SC_MARK_SIMPLE;
817 rRange = ScRange( GetCurX(), GetCurY(), GetTabNo() );
819 return eMarkType;
823 ScMarkType ScViewData::GetSimpleArea( SCCOL& rStartCol, SCROW& rStartRow, SCTAB& rStartTab,
824 SCCOL& rEndCol, SCROW& rEndRow, SCTAB& rEndTab ) const
826 // parameter bMergeMark is no longer needed: The view's selection is never modified
827 // (a local copy is used), and a multi selection that adds to a single range can always
828 // be treated like a single selection (#108266# - GetSimpleArea isn't used in selection
829 // handling itself)
831 ScRange aRange;
832 ScMarkData aNewMark( aMarkData ); // use a local copy for MarkToSimple
833 ScMarkType eMarkType = GetSimpleArea( aRange, aNewMark);
834 aRange.GetVars( rStartCol, rStartRow, rStartTab, rEndCol, rEndRow, rEndTab);
835 return eMarkType;
838 ScMarkType ScViewData::GetSimpleArea( ScRange& rRange ) const
840 // parameter bMergeMark is no longer needed, see above
842 ScMarkData aNewMark( aMarkData ); // use a local copy for MarkToSimple
843 return GetSimpleArea( rRange, aNewMark);
846 void ScViewData::GetMultiArea( ScRangeListRef& rRange ) const
848 // parameter bMergeMark is no longer needed, see GetSimpleArea
850 ScMarkData aNewMark( aMarkData ); // use a local copy for MarkToSimple
852 BOOL bMulti = aNewMark.IsMultiMarked();
853 if (bMulti)
855 aNewMark.MarkToSimple();
856 bMulti = aNewMark.IsMultiMarked();
858 if (bMulti)
860 rRange = new ScRangeList;
861 aNewMark.FillRangeListWithMarks( rRange, FALSE );
863 else
865 ScRange aSimple;
866 GetSimpleArea(aSimple);
867 rRange = new ScRangeList;
868 rRange->Append(aSimple);
872 BOOL ScViewData::SimpleColMarked()
874 SCCOL nStartCol;
875 SCROW nStartRow;
876 SCTAB nStartTab;
877 SCCOL nEndCol;
878 SCROW nEndRow;
879 SCTAB nEndTab;
880 if (GetSimpleArea(nStartCol,nStartRow,nStartTab,nEndCol,nEndRow,nEndTab) == SC_MARK_SIMPLE)
881 if (nStartRow==0 && nEndRow==MAXROW)
882 return TRUE;
884 return FALSE;
887 BOOL ScViewData::SimpleRowMarked()
889 SCCOL nStartCol;
890 SCROW nStartRow;
891 SCTAB nStartTab;
892 SCCOL nEndCol;
893 SCROW nEndRow;
894 SCTAB nEndTab;
895 if (GetSimpleArea(nStartCol,nStartRow,nStartTab,nEndCol,nEndRow,nEndTab) == SC_MARK_SIMPLE)
896 if (nStartCol==0 && nEndCol==MAXCOL)
897 return TRUE;
899 return FALSE;
902 BOOL ScViewData::IsMultiMarked()
904 // Test for "real" multi selection, calling MarkToSimple on a local copy,
905 // and taking filtered in simple area marks into account.
907 ScRange aDummy;
908 ScMarkType eType = GetSimpleArea(aDummy);
909 return (eType & SC_MARK_SIMPLE) != SC_MARK_SIMPLE;
912 void ScViewData::SetFillMode( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow )
914 nFillMode = SC_FILL_FILL;
915 nFillStartX = nStartCol;
916 nFillStartY = nStartRow;
917 nFillEndX = nEndCol;
918 nFillEndY = nEndRow;
921 void ScViewData::SetDragMode( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
922 BYTE nMode )
924 nFillMode = nMode;
925 nFillStartX = nStartCol;
926 nFillStartY = nStartRow;
927 nFillEndX = nEndCol;
928 nFillEndY = nEndRow;
931 void ScViewData::ResetFillMode()
933 nFillMode = SC_FILL_NONE;
936 void ScViewData::GetFillData( SCCOL& rStartCol, SCROW& rStartRow,
937 SCCOL& rEndCol, SCROW& rEndRow )
939 rStartCol = nFillStartX;
940 rStartRow = nFillStartY;
941 rEndCol = nFillEndX;
942 rEndRow = nFillEndY;
945 SCCOL ScViewData::GetOldCurX() const
947 if (pThisTab->bOldCurValid)
948 return pThisTab->nOldCurX;
949 else
950 return pThisTab->nCurX;
953 SCROW ScViewData::GetOldCurY() const
955 if (pThisTab->bOldCurValid)
956 return pThisTab->nOldCurY;
957 else
958 return pThisTab->nCurY;
961 void ScViewData::SetOldCursor( SCCOL nNewX, SCROW nNewY )
963 pThisTab->nOldCurX = nNewX;
964 pThisTab->nOldCurY = nNewY;
965 pThisTab->bOldCurValid = TRUE;
968 void ScViewData::ResetOldCursor()
970 pThisTab->bOldCurValid = FALSE;
973 Rectangle ScViewData::GetEditArea( ScSplitPos eWhich, SCCOL nPosX, SCROW nPosY,
974 Window* pWin, const ScPatternAttr* pPattern,
975 BOOL bForceToTop )
977 return ScEditUtil( pDoc, nPosX, nPosY, nTabNo, GetScrPos(nPosX,nPosY,eWhich,TRUE),
978 pWin, nPPTX, nPPTY, GetZoomX(), GetZoomY() ).
979 GetEditArea( pPattern, bForceToTop );
982 void ScViewData::SetEditEngine( ScSplitPos eWhich,
983 ScEditEngineDefaulter* pNewEngine,
984 Window* pWin, SCCOL nNewX, SCROW nNewY )
986 BOOL bLayoutRTL = pDoc->IsLayoutRTL( nTabNo );
987 ScHSplitPos eHWhich = WhichH(eWhich);
989 BOOL bWasThere = FALSE;
990 if (pEditView[eWhich])
992 // Wenn die View schon da ist, nichts aufrufen, was die Cursorposition aendert
994 if (bEditActive[eWhich])
995 bWasThere = TRUE;
996 else
997 pEditView[eWhich]->SetEditEngine(pNewEngine);
999 if (pEditView[eWhich]->GetWindow() != pWin)
1001 pEditView[eWhich]->SetWindow(pWin);
1002 DBG_ERROR("EditView Window geaendert");
1005 else
1007 pEditView[eWhich] = new EditView( pNewEngine, pWin );
1010 // bei IdleFormat wird manchmal ein Cursor gemalt, wenn die View schon weg ist (23576)
1012 ULONG nEC = pNewEngine->GetControlWord();
1013 pNewEngine->SetControlWord(nEC & ~EE_CNTRL_DOIDLEFORMAT);
1015 ULONG nVC = pEditView[eWhich]->GetControlWord();
1016 pEditView[eWhich]->SetControlWord(nVC & ~EV_CNTRL_AUTOSCROLL);
1018 bEditActive[eWhich] = TRUE;
1020 const ScPatternAttr* pPattern = pDoc->GetPattern( nNewX, nNewY, nTabNo );
1021 SvxCellHorJustify eJust = (SvxCellHorJustify)((const SvxHorJustifyItem&)
1022 pPattern->GetItem( ATTR_HOR_JUSTIFY )).GetValue();
1024 BOOL bBreak = ( eJust == SVX_HOR_JUSTIFY_BLOCK ) ||
1025 ((SfxBoolItem&)pPattern->GetItem(ATTR_LINEBREAK)).GetValue();
1027 BOOL bAsianVertical = pNewEngine->IsVertical(); // set by InputHandler
1029 Rectangle aPixRect = ScEditUtil( pDoc, nNewX,nNewY,nTabNo, GetScrPos(nNewX,nNewY,eWhich),
1030 pWin, nPPTX,nPPTY,GetZoomX(),GetZoomY() ).
1031 GetEditArea( pPattern, TRUE );
1033 // when right-aligned, leave space for the cursor
1034 // in vertical mode, editing is always right-aligned
1035 if ( nEditAdjust == SVX_ADJUST_RIGHT || bAsianVertical )
1036 aPixRect.Right() += 1;
1038 Rectangle aOutputArea = pWin->PixelToLogic( aPixRect, GetLogicMode() );
1039 pEditView[eWhich]->SetOutputArea( aOutputArea );
1041 if ( bActive && eWhich == GetActivePart() )
1043 // keep the part that has the active edit view available after
1044 // switching sheets or reference input on a different part
1045 eEditActivePart = eWhich;
1047 // modify members nEditCol etc. only if also extending for needed area
1048 nEditCol = nNewX;
1049 nEditRow = nNewY;
1050 const ScMergeAttr* pMergeAttr = (ScMergeAttr*)&pPattern->GetItem(ATTR_MERGE);
1051 nEditEndCol = nEditCol;
1052 if (pMergeAttr->GetColMerge() > 1)
1053 nEditEndCol += pMergeAttr->GetColMerge() - 1;
1054 nEditEndRow = nEditRow;
1055 if (pMergeAttr->GetRowMerge() > 1)
1056 nEditEndRow += pMergeAttr->GetRowMerge() - 1;
1057 nEditStartCol = nEditCol;
1059 // For growing use only the alignment value from the attribute, numbers
1060 // (existing or started) with default aligment extend to the right.
1061 BOOL bGrowCentered = ( eJust == SVX_HOR_JUSTIFY_CENTER );
1062 BOOL bGrowToLeft = ( eJust == SVX_HOR_JUSTIFY_RIGHT ); // visual left
1063 BOOL bGrowBackwards = bGrowToLeft; // logical left
1064 if ( bLayoutRTL )
1065 bGrowBackwards = !bGrowBackwards; // invert on RTL sheet
1066 if ( bAsianVertical )
1067 bGrowCentered = bGrowToLeft = bGrowBackwards = FALSE; // keep old behavior for asian mode
1069 long nSizeXPix;
1070 if (bBreak && !bAsianVertical)
1071 nSizeXPix = aPixRect.GetWidth(); // Papersize -> kein H-Scrolling
1072 else
1074 DBG_ASSERT(pView,"keine View fuer EditView");
1076 if ( bGrowCentered )
1078 // growing into both directions until one edge is reached
1079 //! should be limited to whole cells in both directions
1080 long nLeft = aPixRect.Left();
1081 long nRight = pView->GetGridWidth(eHWhich) - aPixRect.Right();
1082 nSizeXPix = aPixRect.GetWidth() + 2 * Min( nLeft, nRight );
1084 else if ( bGrowToLeft )
1085 nSizeXPix = aPixRect.Right(); // space that's available in the window when growing to the left
1086 else
1087 nSizeXPix = pView->GetGridWidth(eHWhich) - aPixRect.Left();
1089 if ( nSizeXPix <= 0 )
1090 nSizeXPix = aPixRect.GetWidth(); // editing outside to the right of the window -> keep cell width
1092 DBG_ASSERT(pView,"keine View fuer EditView");
1093 long nSizeYPix = pView->GetGridHeight(WhichV(eWhich)) - aPixRect.Top();
1094 if ( nSizeYPix <= 0 )
1095 nSizeYPix = aPixRect.GetHeight(); // editing outside below the window -> keep cell height
1097 Size aPaperSize = pView->GetActiveWin()->PixelToLogic( Size( nSizeXPix, nSizeYPix ), GetLogicMode() );
1098 if ( bBreak && !bAsianVertical && SC_MOD()->GetInputOptions().GetTextWysiwyg() )
1100 // #95593# if text is formatted for printer, use the exact same paper width
1101 // (and same line breaks) as for output.
1103 Fraction aFract(1,1);
1104 Rectangle aUtilRect = ScEditUtil( pDoc,nNewX,nNewY,nTabNo, Point(0,0), pWin,
1105 HMM_PER_TWIPS, HMM_PER_TWIPS, aFract, aFract ).GetEditArea( pPattern, FALSE );
1106 aPaperSize.Width() = aUtilRect.GetWidth();
1108 pNewEngine->SetPaperSize( aPaperSize );
1110 // sichtbarer Ausschnitt
1111 Size aPaper = pNewEngine->GetPaperSize();
1112 Rectangle aVis = pEditView[eWhich]->GetVisArea();
1113 long nDiff = aVis.Right() - aVis.Left();
1114 if ( nEditAdjust == SVX_ADJUST_RIGHT )
1116 aVis.Right() = aPaper.Width() - 1;
1117 bMoveArea = !bLayoutRTL;
1119 else if ( nEditAdjust == SVX_ADJUST_CENTER )
1121 aVis.Right() = ( aPaper.Width() - 1 + nDiff ) / 2;
1122 bMoveArea = TRUE; // always
1124 else
1126 aVis.Right() = nDiff;
1127 bMoveArea = bLayoutRTL;
1129 aVis.Left() = aVis.Right() - nDiff;
1130 // --> OD 2005-12-22 #i49561#
1131 // Important note:
1132 // The set offset of the visible area of the EditView for centered and
1133 // right alignment in horizontal layout is consider by instances of
1134 // class <ScEditObjectViewForwarder> in its methods <LogicToPixel(..)>
1135 // and <PixelToLogic(..)>. This is needed for the correct visibility
1136 // of paragraphs in edit mode at the accessibility API.
1137 // <--
1138 pEditView[eWhich]->SetVisArea(aVis);
1141 // UpdateMode has been disabled in ScInputHandler::StartTable
1142 // must be enabled before EditGrowY (GetTextHeight)
1143 pNewEngine->SetUpdateMode( TRUE );
1145 pNewEngine->SetStatusEventHdl( LINK( this, ScViewData, EditEngineHdl ) );
1147 EditGrowY( TRUE ); // adjust to existing text content
1148 EditGrowX();
1150 Point aDocPos = pEditView[eWhich]->GetWindowPosTopLeft(0);
1151 if (aDocPos.Y() < aOutputArea.Top())
1152 pEditView[eWhich]->Scroll( 0, aOutputArea.Top() - aDocPos.Y() );
1154 //! Status (Event) zuruecksetzen
1157 // hier muss bEditActive schon gesetzt sein
1158 // (wegen Map-Mode bei Paint)
1159 if (!bWasThere)
1160 pNewEngine->InsertView(pEditView[eWhich]);
1162 // Hintergrundfarbe der Zelle
1163 Color aBackCol = ((const SvxBrushItem&)pPattern->GetItem(ATTR_BACKGROUND)).GetColor();
1165 ScModule* pScMod = SC_MOD();
1166 // #105733# SvtAccessibilityOptions::GetIsForBorders is no longer used (always assumed TRUE)
1167 if ( aBackCol.GetTransparency() > 0 ||
1168 Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
1170 aBackCol.SetColor( pScMod->GetColorConfig().GetColorValue(svtools::DOCCOLOR).nColor );
1172 pEditView[eWhich]->SetBackgroundColor( aBackCol );
1174 pEditView[eWhich]->Invalidate(); // noetig ??
1175 // noetig, wenn Position geaendert
1178 IMPL_LINK_INLINE_START( ScViewData, EmptyEditHdl, EditStatus *, EMPTYARG )
1180 return 0;
1182 IMPL_LINK_INLINE_END( ScViewData, EmptyEditHdl, EditStatus *, EMPTYARG )
1184 IMPL_LINK( ScViewData, EditEngineHdl, EditStatus *, pStatus )
1186 ULONG nStatus = pStatus->GetStatusWord();
1187 if (nStatus & (EE_STAT_HSCROLL | EE_STAT_TEXTHEIGHTCHANGED | EE_STAT_TEXTWIDTHCHANGED | EE_STAT_CURSOROUT))
1189 EditGrowY();
1190 EditGrowX();
1192 if (nStatus & EE_STAT_CURSOROUT)
1194 ScSplitPos eWhich = GetActivePart();
1195 if (pEditView[eWhich])
1196 pEditView[eWhich]->ShowCursor(FALSE);
1199 return 0;
1202 void ScViewData::EditGrowX()
1204 ScDocument* pLocalDoc = GetDocument();
1206 ScSplitPos eWhich = GetActivePart();
1207 ScHSplitPos eHWhich = WhichH(eWhich);
1208 EditView* pCurView = pEditView[eWhich];
1210 if ( !pCurView || !bEditActive[eWhich])
1211 return;
1213 BOOL bLayoutRTL = pLocalDoc->IsLayoutRTL( nTabNo );
1215 ScEditEngineDefaulter* pEngine =
1216 (ScEditEngineDefaulter*) pCurView->GetEditEngine();
1217 Window* pWin = pCurView->GetWindow();
1219 SCCOL nLeft = GetPosX(eHWhich);
1220 SCCOL nRight = nLeft + VisibleCellsX(eHWhich);
1222 Size aSize = pEngine->GetPaperSize();
1223 Rectangle aArea = pCurView->GetOutputArea();
1224 long nOldRight = aArea.Right();
1226 // Margin ist schon bei der urspruenglichen Breite beruecksichtigt
1227 long nTextWidth = pEngine->CalcTextWidth();
1229 BOOL bChanged = FALSE;
1230 BOOL bAsianVertical = pEngine->IsVertical();
1232 // get bGrow... variables the same way as in SetEditEngine
1233 const ScPatternAttr* pPattern = pLocalDoc->GetPattern( nEditCol, nEditRow, nTabNo );
1234 SvxCellHorJustify eJust = (SvxCellHorJustify)((const SvxHorJustifyItem&)
1235 pPattern->GetItem( ATTR_HOR_JUSTIFY )).GetValue();
1236 BOOL bGrowCentered = ( eJust == SVX_HOR_JUSTIFY_CENTER );
1237 BOOL bGrowToLeft = ( eJust == SVX_HOR_JUSTIFY_RIGHT ); // visual left
1238 BOOL bGrowBackwards = bGrowToLeft; // logical left
1239 if ( bLayoutRTL )
1240 bGrowBackwards = !bGrowBackwards; // invert on RTL sheet
1241 if ( bAsianVertical )
1242 bGrowCentered = bGrowToLeft = bGrowBackwards = FALSE; // keep old behavior for asian mode
1244 BOOL bUnevenGrow = FALSE;
1245 if ( bGrowCentered )
1247 while (aArea.GetWidth() + 0 < nTextWidth && ( nEditStartCol > nLeft || nEditEndCol < nRight ) )
1249 long nLogicLeft = 0;
1250 if ( nEditStartCol > nLeft )
1252 --nEditStartCol;
1253 long nLeftPix = ToPixel( pLocalDoc->GetColWidth( nEditStartCol, nTabNo ), nPPTX );
1254 nLogicLeft = pWin->PixelToLogic(Size(nLeftPix,0)).Width();
1256 long nLogicRight = 0;
1257 if ( nEditEndCol < nRight )
1259 ++nEditEndCol;
1260 long nRightPix = ToPixel( pLocalDoc->GetColWidth( nEditEndCol, nTabNo ), nPPTX );
1261 nLogicRight = pWin->PixelToLogic(Size(nRightPix,0)).Width();
1264 aArea.Left() -= bLayoutRTL ? nLogicRight : nLogicLeft;
1265 aArea.Right() += bLayoutRTL ? nLogicLeft : nLogicRight;
1267 if ( aArea.Right() > aArea.Left() + aSize.Width() - 1 )
1269 long nCenter = ( aArea.Left() + aArea.Right() ) / 2;
1270 long nHalf = aSize.Width() / 2;
1271 aArea.Left() = nCenter - nHalf + 1;
1272 aArea.Right() = nCenter + aSize.Width() - nHalf - 1;
1275 bChanged = TRUE;
1276 if ( nLogicLeft != nLogicRight )
1277 bUnevenGrow = TRUE;
1280 else if ( bGrowBackwards )
1282 while (aArea.GetWidth() + 0 < nTextWidth && nEditStartCol > nLeft)
1284 --nEditStartCol;
1285 long nPix = ToPixel( pLocalDoc->GetColWidth( nEditStartCol, nTabNo ), nPPTX );
1286 long nLogicWidth = pWin->PixelToLogic(Size(nPix,0)).Width();
1287 if ( !bLayoutRTL )
1288 aArea.Left() -= nLogicWidth;
1289 else
1290 aArea.Right() += nLogicWidth;
1292 if ( aArea.Right() > aArea.Left() + aSize.Width() - 1 )
1294 if ( !bLayoutRTL )
1295 aArea.Left() = aArea.Right() - aSize.Width() + 1;
1296 else
1297 aArea.Right() = aArea.Left() + aSize.Width() - 1;
1300 bChanged = TRUE;
1303 else
1305 while (aArea.GetWidth() + 0 < nTextWidth && nEditEndCol < nRight)
1307 ++nEditEndCol;
1308 long nPix = ToPixel( pLocalDoc->GetColWidth( nEditEndCol, nTabNo ), nPPTX );
1309 long nLogicWidth = pWin->PixelToLogic(Size(nPix,0)).Width();
1310 if ( bLayoutRTL )
1311 aArea.Left() -= nLogicWidth;
1312 else
1313 aArea.Right() += nLogicWidth;
1315 if ( aArea.Right() > aArea.Left() + aSize.Width() - 1 )
1317 if ( bLayoutRTL )
1318 aArea.Left() = aArea.Right() - aSize.Width() + 1;
1319 else
1320 aArea.Right() = aArea.Left() + aSize.Width() - 1;
1323 bChanged = TRUE;
1327 if (bChanged)
1329 if ( bMoveArea || bGrowCentered || bGrowBackwards || bLayoutRTL )
1331 Rectangle aVis = pCurView->GetVisArea();
1333 if ( bGrowCentered )
1335 // switch to center-aligned (undo?) and reset VisArea to center
1337 pEngine->SetDefaultItem( SvxAdjustItem( SVX_ADJUST_CENTER, EE_PARA_JUST ) );
1339 long nCenter = aSize.Width() / 2;
1340 long nVisSize = aArea.GetWidth();
1341 aVis.Left() = nCenter - nVisSize / 2;
1342 aVis.Right() = aVis.Left() + nVisSize - 1;
1344 else if ( bGrowToLeft )
1346 // switch to right-aligned (undo?) and reset VisArea to the right
1348 pEngine->SetDefaultItem( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
1350 aVis.Right() = aSize.Width() - 1;
1351 aVis.Left() = aSize.Width() - aArea.GetWidth(); // with the new, increased area
1353 else
1355 // switch to left-aligned (undo?) and reset VisArea to the left
1357 pEngine->SetDefaultItem( SvxAdjustItem( SVX_ADJUST_LEFT, EE_PARA_JUST ) );
1359 long nMove = aVis.Left();
1360 aVis.Left() = 0;
1361 aVis.Right() -= nMove;
1363 pCurView->SetVisArea( aVis );
1364 bMoveArea = FALSE;
1367 pCurView->SetOutputArea(aArea);
1369 // In vertical mode, the whole text is moved to the next cell (right-aligned),
1370 // so everything must be repainted. Otherwise, paint only the new area.
1371 // If growing in centered alignment, if the cells left and right have different sizes,
1372 // the whole text will move, and may not even obscure all of the original display.
1373 if ( bUnevenGrow )
1375 aArea.Left() = pWin->PixelToLogic( Point(0,0) ).X();
1376 aArea.Right() = pWin->PixelToLogic( aScrSize ).Width();
1378 else if ( !bAsianVertical && !bGrowToLeft && !bGrowCentered )
1379 aArea.Left() = nOldRight;
1380 pWin->Invalidate(aArea);
1384 void ScViewData::EditGrowY( BOOL bInitial )
1386 ScSplitPos eWhich = GetActivePart();
1387 ScVSplitPos eVWhich = WhichV(eWhich);
1388 EditView* pCurView = pEditView[eWhich];
1390 if ( !pCurView || !bEditActive[eWhich])
1391 return;
1393 ULONG nControl = pEditView[eWhich]->GetControlWord();
1394 if ( nControl & EV_CNTRL_AUTOSCROLL )
1396 // if end of screen had already been reached and scrolling enabled,
1397 // don't further try to grow the edit area
1399 pCurView->SetOutputArea( pCurView->GetOutputArea() ); // re-align to pixels
1400 return;
1403 EditEngine* pEngine = pCurView->GetEditEngine();
1404 Window* pWin = pCurView->GetWindow();
1406 SCROW nBottom = GetPosY(eVWhich) + VisibleCellsY(eVWhich);
1408 Size aSize = pEngine->GetPaperSize();
1409 Rectangle aArea = pCurView->GetOutputArea();
1410 long nOldBottom = aArea.Bottom();
1411 long nTextHeight = pEngine->GetTextHeight();
1413 // #106635# When editing a formula in a cell with optimal height, allow a larger portion
1414 // to be clipped before extending to following rows, to avoid obscuring cells for
1415 // reference input (next row is likely to be useful in formulas).
1416 long nAllowedExtra = SC_GROWY_SMALL_EXTRA;
1417 if ( nEditEndRow == nEditRow && !( pDoc->GetRowFlags( nEditRow, nTabNo ) & CR_MANUALSIZE ) &&
1418 pEngine->GetParagraphCount() <= 1 )
1420 // If the (only) paragraph starts with a '=', it's a formula.
1421 // If this is the initial call and the text is empty, allow the larger value, too,
1422 // because this occurs in the normal progress of editing a formula.
1423 // Subsequent calls with empty text might involve changed attributes (including
1424 // font height), so they are treated like normal text.
1425 String aText = pEngine->GetText( (USHORT) 0 );
1426 if ( ( aText.Len() == 0 && bInitial ) || aText.GetChar(0) == (sal_Unicode)'=' )
1427 nAllowedExtra = SC_GROWY_BIG_EXTRA;
1430 BOOL bChanged = FALSE;
1431 BOOL bMaxReached = FALSE;
1432 while (aArea.GetHeight() + nAllowedExtra < nTextHeight && nEditEndRow < nBottom && !bMaxReached)
1434 ++nEditEndRow;
1435 ScDocument* pLocalDoc = GetDocument();
1436 long nPix = ToPixel( pLocalDoc->GetRowHeight( nEditEndRow, nTabNo ), nPPTY );
1437 aArea.Bottom() += pWin->PixelToLogic(Size(0,nPix)).Height();
1439 if ( aArea.Bottom() > aArea.Top() + aSize.Height() - 1 )
1441 aArea.Bottom() = aArea.Top() + aSize.Height() - 1;
1442 bMaxReached = TRUE; // don't occupy more cells beyond paper size
1445 bChanged = TRUE;
1446 nAllowedExtra = SC_GROWY_SMALL_EXTRA; // larger value is only for first row
1449 if (bChanged)
1451 pCurView->SetOutputArea(aArea);
1453 if (nEditEndRow >= nBottom || bMaxReached)
1455 if ((nControl & EV_CNTRL_AUTOSCROLL) == 0)
1456 pCurView->SetControlWord( nControl | EV_CNTRL_AUTOSCROLL );
1459 aArea.Top() = nOldBottom;
1460 pWin->Invalidate(aArea);
1464 void ScViewData::ResetEditView()
1466 EditEngine* pEngine = NULL;
1467 for (USHORT i=0; i<4; i++)
1468 if (pEditView[i])
1470 if (bEditActive[i])
1472 pEngine = pEditView[i]->GetEditEngine();
1473 pEngine->RemoveView(pEditView[i]);
1474 pEditView[i]->SetOutputArea( Rectangle() );
1476 bEditActive[i] = FALSE;
1479 if (pEngine)
1480 pEngine->SetStatusEventHdl( LINK( this, ScViewData, EmptyEditHdl ) );
1483 void ScViewData::KillEditView()
1485 for (USHORT i=0; i<4; i++)
1486 if (pEditView[i])
1488 if (bEditActive[i])
1489 pEditView[i]->GetEditEngine()->RemoveView(pEditView[i]);
1490 delete pEditView[i];
1491 pEditView[i] = NULL;
1495 void ScViewData::GetEditView( ScSplitPos eWhich, EditView*& rViewPtr, SCCOL& rCol, SCROW& rRow )
1497 rViewPtr = pEditView[eWhich];
1498 rCol = nEditCol;
1499 rRow = nEditRow;
1502 void ScViewData::CreateTabData( SCTAB nNewTab )
1504 if (!pTabData[nNewTab])
1506 pTabData[nNewTab] = new ScViewDataTable;
1508 pTabData[nNewTab]->eZoomType = eDefZoomType;
1509 pTabData[nNewTab]->aZoomX = aDefZoomX;
1510 pTabData[nNewTab]->aZoomY = aDefZoomY;
1511 pTabData[nNewTab]->aPageZoomX = aDefPageZoomX;
1512 pTabData[nNewTab]->aPageZoomY = aDefPageZoomY;
1516 void ScViewData::CreateSelectedTabData()
1518 SCTAB nTabCount = pDoc->GetTableCount();
1519 for (SCTAB i=0; i<nTabCount; i++)
1520 if ( aMarkData.GetTableSelect(i) && !pTabData[i] )
1521 CreateTabData( i );
1524 void ScViewData::SetTabNo( SCTAB nNewTab )
1526 if (!ValidTab(nNewTab))
1528 DBG_ERROR("falsche Tabellennummer");
1529 return;
1532 nTabNo = nNewTab;
1533 CreateTabData(nTabNo);
1534 pThisTab = pTabData[nTabNo];
1536 CalcPPT(); // for common column width correction
1537 RecalcPixPos(); //! nicht immer noetig!
1540 void ScViewData::SetActivePart( ScSplitPos eNewActive )
1542 pThisTab->eWhichActive = eNewActive;
1545 Point ScViewData::GetScrPos( SCCOL nWhereX, SCROW nWhereY, ScHSplitPos eWhich ) const
1547 DBG_ASSERT( eWhich==SC_SPLIT_LEFT || eWhich==SC_SPLIT_RIGHT, "Falsche Position" );
1548 ScSplitPos ePos = ( eWhich == SC_SPLIT_LEFT ) ? SC_SPLIT_BOTTOMLEFT : SC_SPLIT_BOTTOMRIGHT;
1549 return GetScrPos( nWhereX, nWhereY, ePos );
1552 Point ScViewData::GetScrPos( SCCOL nWhereX, SCROW nWhereY, ScVSplitPos eWhich ) const
1554 DBG_ASSERT( eWhich==SC_SPLIT_TOP || eWhich==SC_SPLIT_BOTTOM, "Falsche Position" );
1555 ScSplitPos ePos = ( eWhich == SC_SPLIT_TOP ) ? SC_SPLIT_TOPLEFT : SC_SPLIT_BOTTOMLEFT;
1556 return GetScrPos( nWhereX, nWhereY, ePos );
1559 Point ScViewData::GetScrPos( SCCOL nWhereX, SCROW nWhereY, ScSplitPos eWhich,
1560 BOOL bAllowNeg ) const
1562 ScHSplitPos eWhichX = SC_SPLIT_LEFT;
1563 ScVSplitPos eWhichY = SC_SPLIT_BOTTOM;
1564 switch( eWhich )
1566 case SC_SPLIT_TOPLEFT:
1567 eWhichX = SC_SPLIT_LEFT;
1568 eWhichY = SC_SPLIT_TOP;
1569 break;
1570 case SC_SPLIT_TOPRIGHT:
1571 eWhichX = SC_SPLIT_RIGHT;
1572 eWhichY = SC_SPLIT_TOP;
1573 break;
1574 case SC_SPLIT_BOTTOMLEFT:
1575 eWhichX = SC_SPLIT_LEFT;
1576 eWhichY = SC_SPLIT_BOTTOM;
1577 break;
1578 case SC_SPLIT_BOTTOMRIGHT:
1579 eWhichX = SC_SPLIT_RIGHT;
1580 eWhichY = SC_SPLIT_BOTTOM;
1581 break;
1584 if (pView)
1586 ((ScViewData*)this)->aScrSize.Width() = pView->GetGridWidth(eWhichX);
1587 ((ScViewData*)this)->aScrSize.Height() = pView->GetGridHeight(eWhichY);
1590 USHORT nTSize;
1592 SCCOL nPosX = GetPosX(eWhichX);
1593 SCCOL nX;
1595 long nScrPosX=0;
1596 if (nWhereX >= nPosX)
1597 for (nX=nPosX; nX<nWhereX && (bAllowNeg || nScrPosX<=aScrSize.Width()); nX++)
1599 if ( nX > MAXCOL )
1600 nScrPosX = 65535;
1601 else
1603 nTSize = pDoc->GetColWidth( nX, nTabNo );
1604 if (nTSize)
1606 long nSizeXPix = ToPixel( nTSize, nPPTX );
1607 nScrPosX += nSizeXPix;
1611 else if (bAllowNeg)
1612 for (nX=nPosX; nX>nWhereX;)
1614 --nX;
1615 nTSize = pDoc->GetColWidth( nX, nTabNo );
1616 if (nTSize)
1618 long nSizeXPix = ToPixel( nTSize, nPPTX );
1619 nScrPosX -= nSizeXPix;
1623 SCROW nPosY = GetPosY(eWhichY);
1624 SCROW nY;
1626 long nScrPosY=0;
1627 if (nWhereY >= nPosY)
1628 for (nY=nPosY; nY<nWhereY && (bAllowNeg || nScrPosY<=aScrSize.Height()); nY++)
1630 if ( nY > MAXROW )
1631 nScrPosY = 65535;
1632 else
1634 nTSize = pDoc->FastGetRowHeight( nY, nTabNo );
1635 if (nTSize)
1637 long nSizeYPix = ToPixel( nTSize, nPPTY );
1638 nScrPosY += nSizeYPix;
1640 else if ( nY < MAXROW )
1642 // skip multiple hidden rows (forward only for now)
1643 SCROW nNext = pDoc->FirstVisibleRow(nY + 1, MAXROW, nTabNo);
1644 if ( nNext > MAXROW )
1645 nY = MAXROW;
1646 else
1647 nY = nNext - 1; // +=nDir advances to next visible row
1651 else if (bAllowNeg)
1652 for (nY=nPosY; nY>nWhereY;)
1654 --nY;
1655 nTSize = pDoc->FastGetRowHeight( nY, nTabNo );
1656 if (nTSize)
1658 long nSizeYPix = ToPixel( nTSize, nPPTY );
1659 nScrPosY -= nSizeYPix;
1663 if ( pDoc->IsLayoutRTL( nTabNo ) )
1665 // mirror horizontal position
1666 nScrPosX = aScrSize.Width() - 1 - nScrPosX;
1669 if (nScrPosX > 32767) nScrPosX=32767;
1670 if (nScrPosY > 32767) nScrPosY=32767;
1671 return Point( nScrPosX, nScrPosY );
1675 // Anzahl Zellen auf einem Bildschirm
1678 SCCOL ScViewData::CellsAtX( SCsCOL nPosX, SCsCOL nDir, ScHSplitPos eWhichX, USHORT nScrSizeX ) const
1680 DBG_ASSERT( nDir==1 || nDir==-1, "falscher CellsAt Aufruf" );
1682 if (pView)
1683 ((ScViewData*)this)->aScrSize.Width() = pView->GetGridWidth(eWhichX);
1685 SCsCOL nX;
1686 USHORT nScrPosX = 0;
1687 if (nScrSizeX == SC_SIZE_NONE) nScrSizeX = (USHORT) aScrSize.Width();
1689 if (nDir==1)
1690 nX = nPosX; // vorwaerts
1691 else
1692 nX = nPosX-1; // rueckwaerts
1694 BOOL bOut = FALSE;
1695 for ( ; nScrPosX<=nScrSizeX && !bOut; nX = sal::static_int_cast<SCsCOL>(nX + nDir) )
1697 SCsCOL nColNo = nX;
1698 if ( nColNo < 0 || nColNo > MAXCOL )
1699 bOut = TRUE;
1700 else
1702 USHORT nTSize = pDoc->GetColWidth( nColNo, nTabNo );
1703 if (nTSize)
1705 long nSizeXPix = ToPixel( nTSize, nPPTX );
1706 nScrPosX = sal::static_int_cast<USHORT>( nScrPosX + (USHORT) nSizeXPix );
1711 if (nDir==1)
1712 nX = sal::static_int_cast<SCsCOL>( nX - nPosX );
1713 else
1714 nX = (nPosX-1)-nX;
1716 if (nX>0) --nX;
1717 return nX;
1720 SCROW ScViewData::CellsAtY( SCsROW nPosY, SCsROW nDir, ScVSplitPos eWhichY, USHORT nScrSizeY ) const
1722 DBG_ASSERT( nDir==1 || nDir==-1, "falscher CellsAt Aufruf" );
1724 if (pView)
1725 ((ScViewData*)this)->aScrSize.Height() = pView->GetGridHeight(eWhichY);
1727 SCROW nY;
1728 USHORT nScrPosY = 0;
1730 if (nScrSizeY == SC_SIZE_NONE) nScrSizeY = (USHORT) aScrSize.Height();
1732 if (nDir==1)
1733 nY = nPosY; // vorwaerts
1734 else
1735 nY = nPosY-1; // rueckwaerts
1737 BOOL bOut = FALSE;
1738 for ( ; nScrPosY<=nScrSizeY && !bOut; nY+=nDir )
1740 SCsROW nRowNo = nY;
1741 if ( nRowNo < 0 || nRowNo > MAXROW )
1742 bOut = TRUE;
1743 else
1745 // USHORT nTSize = pDoc->GetRowHeight( nRowNo, nTabNo );
1746 USHORT nTSize = pDoc->FastGetRowHeight( nRowNo, nTabNo );
1747 if (nTSize)
1749 long nSizeYPix = ToPixel( nTSize, nPPTY );
1750 nScrPosY = sal::static_int_cast<USHORT>( nScrPosY + (USHORT) nSizeYPix );
1752 else if ( nDir == 1 && nRowNo < MAXROW )
1754 // skip multiple hidden rows (forward only for now)
1755 SCROW nNext = pDoc->FirstVisibleRow(nRowNo + 1, MAXROW, nTabNo);
1756 if ( nNext > MAXROW )
1758 // same behavior as without the optimization: set bOut with nY=MAXROW+1
1759 nY = MAXROW+1;
1760 bOut = TRUE;
1762 else
1763 nY = nNext - 1; // +=nDir advances to next visible row
1768 if (nDir==1)
1769 nY -= nPosY;
1770 else
1771 nY = (nPosY-1)-nY;
1773 if (nY>0) --nY;
1774 return nY;
1777 SCCOL ScViewData::VisibleCellsX( ScHSplitPos eWhichX ) const
1779 return CellsAtX( GetPosX( eWhichX ), 1, eWhichX, SC_SIZE_NONE );
1782 SCROW ScViewData::VisibleCellsY( ScVSplitPos eWhichY ) const
1784 return CellsAtY( GetPosY( eWhichY ), 1, eWhichY, SC_SIZE_NONE );
1787 SCCOL ScViewData::PrevCellsX( ScHSplitPos eWhichX ) const
1789 return CellsAtX( GetPosX( eWhichX ), -1, eWhichX, SC_SIZE_NONE );
1792 SCROW ScViewData::PrevCellsY( ScVSplitPos eWhichY ) const
1794 return CellsAtY( GetPosY( eWhichY ), -1, eWhichY, SC_SIZE_NONE );
1797 //UNUSED2008-05 SCCOL ScViewData::LastCellsX( ScHSplitPos eWhichX ) const
1798 //UNUSED2008-05 {
1799 //UNUSED2008-05 return CellsAtX( MAXCOL+1, -1, eWhichX, SC_SIZE_NONE );
1800 //UNUSED2008-05 }
1801 //UNUSED2008-05
1802 //UNUSED2008-05 SCROW ScViewData::LastCellsY( ScVSplitPos eWhichY ) const
1803 //UNUSED2008-05 {
1804 //UNUSED2008-05 return CellsAtY( MAXROW+1, -1, eWhichY, SC_SIZE_NONE );
1805 //UNUSED2008-05 }
1807 BOOL ScViewData::GetMergeSizePixel( SCCOL nX, SCROW nY, long& rSizeXPix, long& rSizeYPix )
1809 const ScMergeAttr* pMerge = (const ScMergeAttr*) pDoc->GetAttr( nX,nY,nTabNo, ATTR_MERGE );
1810 if ( pMerge->GetColMerge() > 1 || pMerge->GetRowMerge() > 1 )
1812 long nOutWidth = 0;
1813 long nOutHeight = 0;
1814 SCCOL nCountX = pMerge->GetColMerge();
1815 for (SCCOL i=0; i<nCountX; i++)
1816 nOutWidth += ToPixel( pDoc->GetColWidth(nX+i,nTabNo), nPPTX );
1817 SCROW nCountY = pMerge->GetRowMerge();
1819 for (SCROW nRow = nY; nRow <= nY+nCountY-1; ++nRow)
1821 SCROW nLastRow = nRow;
1822 if (pDoc->RowHidden(nRow, nTabNo, NULL, &nLastRow))
1824 nRow = nLastRow;
1825 continue;
1828 USHORT nHeight = pDoc->GetRowHeight(nRow, nTabNo);
1829 nOutHeight += ToPixel(nHeight, nPPTY);
1832 rSizeXPix = nOutWidth;
1833 rSizeYPix = nOutHeight;
1834 return TRUE;
1836 else
1838 rSizeXPix = ToPixel( pDoc->GetColWidth( nX, nTabNo ), nPPTX );
1839 rSizeYPix = ToPixel( pDoc->GetRowHeight( nY, nTabNo ), nPPTY );
1840 return FALSE;
1844 BOOL ScViewData::GetPosFromPixel( long nClickX, long nClickY, ScSplitPos eWhich,
1845 SCsCOL& rPosX, SCsROW& rPosY,
1846 BOOL bTestMerge, BOOL bRepair, BOOL bNextIfLarge )
1848 // special handling of 0 is now in ScViewFunctionSet::SetCursorAtPoint
1850 ScHSplitPos eHWhich = WhichH(eWhich);
1851 ScVSplitPos eVWhich = WhichV(eWhich);
1853 if ( pDoc->IsLayoutRTL( nTabNo ) )
1855 // mirror horizontal position
1856 if (pView)
1857 aScrSize.Width() = pView->GetGridWidth(eHWhich);
1858 nClickX = aScrSize.Width() - 1 - nClickX;
1861 SCsCOL nStartPosX = GetPosX(eHWhich);
1862 SCsROW nStartPosY = GetPosY(eVWhich);
1863 rPosX = nStartPosX;
1864 rPosY = nStartPosY;
1865 long nScrX = 0;
1866 long nScrY = 0;
1868 if (nClickX > 0)
1870 while ( rPosX<=MAXCOL && nClickX >= nScrX )
1872 nScrX += ToPixel( pDoc->GetColWidth( rPosX, nTabNo ), nPPTX );
1873 ++rPosX;
1875 --rPosX;
1877 else
1879 while ( rPosX>0 && nClickX < nScrX )
1881 --rPosX;
1882 nScrX -= ToPixel( pDoc->GetColWidth( rPosX, nTabNo ), nPPTX );
1886 if (nClickY > 0)
1888 while ( rPosY<=MAXROW && nClickY >= nScrY )
1890 nScrY += ToPixel( pDoc->FastGetRowHeight( rPosY, nTabNo ), nPPTY );
1891 ++rPosY;
1893 --rPosY;
1895 else
1897 while ( rPosY>0 && nClickY < nScrY )
1899 --rPosY;
1900 nScrY -= ToPixel( pDoc->FastGetRowHeight( rPosY, nTabNo ), nPPTY );
1904 if (bNextIfLarge) // zu grosse Zellen ?
1906 if ( rPosX == nStartPosX && nClickX > 0 )
1908 if (pView)
1909 aScrSize.Width() = pView->GetGridWidth(eHWhich);
1910 if ( nClickX > aScrSize.Width() )
1911 ++rPosX;
1913 if ( rPosY == nStartPosY && nClickY > 0 )
1915 if (pView)
1916 aScrSize.Height() = pView->GetGridHeight(eVWhich);
1917 if ( nClickY > aScrSize.Height() )
1918 ++rPosY;
1922 if (rPosX<0) rPosX=0;
1923 if (rPosX>MAXCOL) rPosX=MAXCOL;
1924 if (rPosY<0) rPosY=0;
1925 if (rPosY>MAXROW) rPosY=MAXROW;
1927 if (bTestMerge)
1929 //! public Methode um Position anzupassen
1931 SCCOL nOrigX = rPosX;
1932 SCROW nOrigY = rPosY;
1933 pDoc->SkipOverlapped(rPosX, rPosY, nTabNo);
1934 bool bHOver = (nOrigX != rPosX);
1935 bool bVOver = (nOrigY != rPosY);
1937 if ( bRepair && ( bHOver || bVOver ) )
1939 const ScMergeAttr* pMerge = (const ScMergeAttr*)
1940 pDoc->GetAttr( rPosX, rPosY, nTabNo, ATTR_MERGE );
1941 if ( ( bHOver && pMerge->GetColMerge() <= 1 ) ||
1942 ( bVOver && pMerge->GetRowMerge() <= 1 ) )
1944 DBG_ERROR("Merge-Fehler gefunden");
1946 pDoc->RemoveFlagsTab( 0,0, MAXCOL,MAXROW, nTabNo, SC_MF_HOR | SC_MF_VER );
1947 SCCOL nEndCol = MAXCOL;
1948 SCROW nEndRow = MAXROW;
1949 pDoc->ExtendMerge( 0,0, nEndCol,nEndRow, nTabNo, TRUE, FALSE );
1950 if (pDocShell)
1951 pDocShell->PostPaint( ScRange(0,0,nTabNo,MAXCOL,MAXROW,nTabNo), PAINT_GRID );
1956 return FALSE;
1959 void ScViewData::GetMouseQuadrant( const Point& rClickPos, ScSplitPos eWhich,
1960 SCsCOL nPosX, SCsROW nPosY, BOOL& rLeft, BOOL& rTop )
1962 BOOL bLayoutRTL = pDoc->IsLayoutRTL( nTabNo );
1963 long nLayoutSign = bLayoutRTL ? -1 : 1;
1965 Point aCellStart = GetScrPos( nPosX, nPosY, eWhich, TRUE );
1966 long nSizeX;
1967 long nSizeY;
1968 GetMergeSizePixel( nPosX, nPosY, nSizeX, nSizeY );
1969 rLeft = ( rClickPos.X() - aCellStart.X() ) * nLayoutSign <= nSizeX / 2;
1970 rTop = rClickPos.Y() - aCellStart.Y() <= nSizeY / 2;
1973 void ScViewData::SetPosX( ScHSplitPos eWhich, SCCOL nNewPosX )
1975 if (nNewPosX != 0)
1977 SCCOL nOldPosX = pThisTab->nPosX[eWhich];
1978 long nTPosX = pThisTab->nTPosX[eWhich];
1979 long nPixPosX = pThisTab->nPixPosX[eWhich];
1980 SCCOL i;
1981 if ( nNewPosX > nOldPosX )
1982 for ( i=nOldPosX; i<nNewPosX; i++ )
1984 long nThis = pDoc->GetColWidth( i,nTabNo );
1985 nTPosX -= nThis;
1986 nPixPosX -= ToPixel(sal::static_int_cast<USHORT>(nThis), nPPTX);
1988 else
1989 for ( i=nNewPosX; i<nOldPosX; i++ )
1991 long nThis = pDoc->GetColWidth( i,nTabNo );
1992 nTPosX += nThis;
1993 nPixPosX += ToPixel(sal::static_int_cast<USHORT>(nThis), nPPTX);
1996 pThisTab->nPosX[eWhich] = nNewPosX;
1997 pThisTab->nTPosX[eWhich] = nTPosX;
1998 pThisTab->nMPosX[eWhich] = (long) (nTPosX * HMM_PER_TWIPS);
1999 pThisTab->nPixPosX[eWhich] = nPixPosX;
2001 else
2002 pThisTab->nPixPosX[eWhich] =
2003 pThisTab->nTPosX[eWhich] =
2004 pThisTab->nMPosX[eWhich] =
2005 pThisTab->nPosX[eWhich] = 0;
2008 void ScViewData::SetPosY( ScVSplitPos eWhich, SCROW nNewPosY )
2010 if (nNewPosY != 0)
2012 SCROW nOldPosY = pThisTab->nPosY[eWhich];
2013 long nTPosY = pThisTab->nTPosY[eWhich];
2014 long nPixPosY = pThisTab->nPixPosY[eWhich];
2015 SCROW i;
2016 if ( nNewPosY > nOldPosY )
2017 for ( i=nOldPosY; i<nNewPosY; i++ )
2019 long nThis = pDoc->FastGetRowHeight( i,nTabNo );
2020 nTPosY -= nThis;
2021 nPixPosY -= ToPixel(sal::static_int_cast<USHORT>(nThis), nPPTY);
2023 else
2024 for ( i=nNewPosY; i<nOldPosY; i++ )
2026 long nThis = pDoc->FastGetRowHeight( i,nTabNo );
2027 nTPosY += nThis;
2028 nPixPosY += ToPixel(sal::static_int_cast<USHORT>(nThis), nPPTY);
2031 pThisTab->nPosY[eWhich] = nNewPosY;
2032 pThisTab->nTPosY[eWhich] = nTPosY;
2033 pThisTab->nMPosY[eWhich] = (long) (nTPosY * HMM_PER_TWIPS);
2034 pThisTab->nPixPosY[eWhich] = nPixPosY;
2036 else
2037 pThisTab->nPixPosY[eWhich] =
2038 pThisTab->nTPosY[eWhich] =
2039 pThisTab->nMPosY[eWhich] =
2040 pThisTab->nPosY[eWhich] = 0;
2043 void ScViewData::RecalcPixPos() // nach Zoom-Aenderungen
2045 for (USHORT eWhich=0; eWhich<2; eWhich++)
2047 long nPixPosX = 0;
2048 SCCOL nPosX = pThisTab->nPosX[eWhich];
2049 for (SCCOL i=0; i<nPosX; i++)
2050 nPixPosX -= ToPixel(pDoc->GetColWidth(i,nTabNo), nPPTX);
2051 pThisTab->nPixPosX[eWhich] = nPixPosX;
2053 long nPixPosY = 0;
2054 SCROW nPosY = pThisTab->nPosY[eWhich];
2055 for (SCROW j=0; j<nPosY; j++)
2056 nPixPosY -= ToPixel(pDoc->FastGetRowHeight(j,nTabNo), nPPTY);
2057 pThisTab->nPixPosY[eWhich] = nPixPosY;
2061 const MapMode& ScViewData::GetLogicMode( ScSplitPos eWhich )
2063 aLogicMode.SetOrigin( Point( pThisTab->nMPosX[WhichH(eWhich)],
2064 pThisTab->nMPosY[WhichV(eWhich)] ) );
2065 return aLogicMode;
2068 const MapMode& ScViewData::GetLogicMode()
2070 aLogicMode.SetOrigin( Point() );
2071 return aLogicMode;
2074 void ScViewData::SetScreen( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
2076 SCCOL nCol;
2077 SCROW nRow;
2078 USHORT nTSize;
2079 long nSizePix;
2080 long nScrPosX = 0;
2081 long nScrPosY = 0;
2083 SetActivePart( SC_SPLIT_BOTTOMLEFT );
2084 SetPosX( SC_SPLIT_LEFT, nCol1 );
2085 SetPosY( SC_SPLIT_BOTTOM, nRow1 );
2087 for (nCol=nCol1; nCol<=nCol2; nCol++)
2089 nTSize = pDoc->GetColWidth( nCol, nTabNo );
2090 if (nTSize)
2092 nSizePix = ToPixel( nTSize, nPPTX );
2093 nScrPosX += (USHORT) nSizePix;
2097 for (nRow=nRow1; nRow<=nRow2; nRow++)
2099 nTSize = pDoc->FastGetRowHeight( nRow, nTabNo );
2100 if (nTSize)
2102 nSizePix = ToPixel( nTSize, nPPTY );
2103 nScrPosY += (USHORT) nSizePix;
2107 aScrSize = Size( nScrPosX, nScrPosY );
2110 void ScViewData::SetScreenPos( const Point& rVisAreaStart )
2112 long nSize;
2113 long nTwips;
2114 long nAdd;
2115 BOOL bEnd;
2117 nSize = 0;
2118 nTwips = (long) (rVisAreaStart.X() / HMM_PER_TWIPS);
2119 if ( pDoc->IsLayoutRTL( nTabNo ) )
2120 nTwips = -nTwips;
2121 SCCOL nX1 = 0;
2122 bEnd = FALSE;
2123 while (!bEnd)
2125 nAdd = (long) pDoc->GetColWidth(nX1,nTabNo);
2126 if (nSize+nAdd <= nTwips+1 && nX1<MAXCOL)
2128 nSize += nAdd;
2129 ++nX1;
2131 else
2132 bEnd = TRUE;
2135 nSize = 0;
2136 nTwips = (long) (rVisAreaStart.Y() / HMM_PER_TWIPS);
2137 SCROW nY1 = 0;
2138 bEnd = FALSE;
2139 while (!bEnd)
2141 nAdd = (long) pDoc->FastGetRowHeight(nY1,nTabNo);
2142 if (nSize+nAdd <= nTwips+1 && nY1<MAXROW)
2144 nSize += nAdd;
2145 ++nY1;
2147 else
2148 bEnd = TRUE;
2151 SetActivePart( SC_SPLIT_BOTTOMLEFT );
2152 SetPosX( SC_SPLIT_LEFT, nX1 );
2153 SetPosY( SC_SPLIT_BOTTOM, nY1 );
2155 SetCurX( nX1 );
2156 SetCurY( nY1 );
2159 void ScViewData::SetScreen( const Rectangle& rVisArea )
2161 SetScreenPos( rVisArea.TopLeft() );
2163 // hier ohne GetOutputFactor(), weil fuer Ausgabe in Metafile
2165 aScrSize = rVisArea.GetSize();
2166 aScrSize.Width() = (long)
2167 ( aScrSize.Width() * ScGlobal::nScreenPPTX / HMM_PER_TWIPS );
2168 aScrSize.Height() = (long)
2169 ( aScrSize.Height() * ScGlobal::nScreenPPTY / HMM_PER_TWIPS );
2172 SfxObjectShell* ScViewData::GetSfxDocShell() const
2174 return pDocShell;
2177 SfxBindings& ScViewData::GetBindings()
2179 DBG_ASSERT( pViewShell, "GetBindings() without ViewShell" );
2180 return pViewShell->GetViewFrame()->GetBindings();
2183 SfxDispatcher& ScViewData::GetDispatcher()
2185 DBG_ASSERT( pViewShell, "GetDispatcher() without ViewShell" );
2186 return *pViewShell->GetViewFrame()->GetDispatcher();
2189 Window* ScViewData::GetDialogParent()
2191 DBG_ASSERT( pViewShell, "GetDialogParent() ohne ViewShell" );
2192 return pViewShell->GetDialogParent();
2195 Window* ScViewData::GetActiveWin()
2197 DBG_ASSERT( pView, "GetActiveWin() ohne View" );
2198 return pView->GetActiveWin();
2201 ScDrawView* ScViewData::GetScDrawView()
2203 DBG_ASSERT( pView, "GetScDrawView() ohne View" );
2204 return pView->GetScDrawView();
2207 BOOL ScViewData::IsMinimized()
2209 DBG_ASSERT( pView, "IsMinimized() ohne View" );
2210 return pView->IsMinimized();
2213 void ScViewData::UpdateScreenZoom( const Fraction& rNewX, const Fraction& rNewY )
2215 Fraction aOldX = GetZoomX();
2216 Fraction aOldY = GetZoomY();
2218 SetZoom( rNewX, rNewY, FALSE );
2220 Fraction aWidth = GetZoomX();
2221 aWidth *= Fraction( aScrSize.Width(),1 );
2222 aWidth /= aOldX;
2224 Fraction aHeight = GetZoomY();
2225 aHeight *= Fraction( aScrSize.Height(),1 );
2226 aHeight /= aOldY;
2228 aScrSize.Width() = (long) aWidth;
2229 aScrSize.Height() = (long) aHeight;
2232 void ScViewData::CalcPPT()
2234 nPPTX = ScGlobal::nScreenPPTX * (double) GetZoomX();
2235 if (pDocShell)
2236 nPPTX = nPPTX / pDocShell->GetOutputFactor(); // Faktor ist Drucker zu Bildschirm
2237 nPPTY = ScGlobal::nScreenPPTY * (double) GetZoomY();
2239 // #83616# if detective objects are present,
2240 // try to adjust horizontal scale so the most common column width has minimal rounding errors,
2241 // to avoid differences between cell and drawing layer output
2243 if ( pDoc && pDoc->HasDetectiveObjects(nTabNo) )
2245 SCCOL nEndCol = 0;
2246 SCROW nDummy = 0;
2247 pDoc->GetTableArea( nTabNo, nEndCol, nDummy );
2248 if (nEndCol<20)
2249 nEndCol = 20; // same end position as when determining draw scale
2251 USHORT nTwips = pDoc->GetCommonWidth( nEndCol, nTabNo );
2252 if ( nTwips )
2254 double fOriginal = nTwips * nPPTX;
2255 if ( fOriginal < static_cast<double>(nEndCol) )
2257 // if one column is smaller than the column count,
2258 // rounding errors are likely to add up to a whole column.
2260 double fRounded = ::rtl::math::approxFloor( fOriginal + 0.5 );
2261 if ( fRounded > 0.0 )
2263 double fScale = fRounded / fOriginal + 1E-6;
2264 if ( fScale >= 0.9 && fScale <= 1.1 )
2265 nPPTX *= fScale;
2272 //------------------------------------------------------------------
2274 #define SC_OLD_TABSEP '/'
2275 #define SC_NEW_TABSEP '+'
2277 void ScViewData::WriteUserData(String& rData)
2279 // nZoom (bis 364v) oder nZoom/nPageZoom/bPageMode (ab 364w)
2280 // nTab
2281 // Tab-ControlBreite
2282 // pro Tabelle:
2283 // CursorX/CursorY/HSplitMode/VSplitMode/HSplitPos/VSplitPos/SplitActive/
2284 // PosX[links]/PosX[rechts]/PosY[oben]/PosY[unten]
2285 // wenn Zeilen groesser 8192, "+" statt "/"
2287 USHORT nZoom = (USHORT)((pThisTab->aZoomY.GetNumerator() * 100) / pThisTab->aZoomY.GetDenominator());
2288 rData = String::CreateFromInt32( nZoom );
2289 rData += '/';
2290 nZoom = (USHORT)((pThisTab->aPageZoomY.GetNumerator() * 100) / pThisTab->aPageZoomY.GetDenominator());
2291 rData += String::CreateFromInt32( nZoom );
2292 rData += '/';
2293 if (bPagebreak)
2294 rData += '1';
2295 else
2296 rData += '0';
2298 rData += ';';
2299 rData += String::CreateFromInt32( nTabNo );
2300 rData += ';';
2301 rData.AppendAscii(RTL_CONSTASCII_STRINGPARAM( TAG_TABBARWIDTH ));
2302 rData += String::CreateFromInt32( pView->GetTabBarWidth() );
2304 SCTAB nTabCount = pDoc->GetTableCount();
2305 for (SCTAB i=0; i<nTabCount; i++)
2307 rData += ';'; // Numerierung darf auf keinen Fall durcheinanderkommen
2308 if (pTabData[i])
2310 sal_Unicode cTabSep = SC_OLD_TABSEP; // wie 3.1
2311 if ( pTabData[i]->nCurY > MAXROW_30 ||
2312 pTabData[i]->nPosY[0] > MAXROW_30 || pTabData[i]->nPosY[1] > MAXROW_30 ||
2313 ( pTabData[i]->eVSplitMode == SC_SPLIT_FIX &&
2314 pTabData[i]->nFixPosY > MAXROW_30 ) )
2316 cTabSep = SC_NEW_TABSEP; // um eine 3.1-Version nicht umzubringen
2320 rData += String::CreateFromInt32( pTabData[i]->nCurX );
2321 rData += cTabSep;
2322 rData += String::CreateFromInt32( pTabData[i]->nCurY );
2323 rData += cTabSep;
2324 rData += String::CreateFromInt32( pTabData[i]->eHSplitMode );
2325 rData += cTabSep;
2326 rData += String::CreateFromInt32( pTabData[i]->eVSplitMode );
2327 rData += cTabSep;
2328 if ( pTabData[i]->eHSplitMode == SC_SPLIT_FIX )
2329 rData += String::CreateFromInt32( pTabData[i]->nFixPosX );
2330 else
2331 rData += String::CreateFromInt32( pTabData[i]->nHSplitPos );
2332 rData += cTabSep;
2333 if ( pTabData[i]->eVSplitMode == SC_SPLIT_FIX )
2334 rData += String::CreateFromInt32( pTabData[i]->nFixPosY );
2335 else
2336 rData += String::CreateFromInt32( pTabData[i]->nVSplitPos );
2337 rData += cTabSep;
2338 rData += String::CreateFromInt32( pTabData[i]->eWhichActive );
2339 rData += cTabSep;
2340 rData += String::CreateFromInt32( pTabData[i]->nPosX[0] );
2341 rData += cTabSep;
2342 rData += String::CreateFromInt32( pTabData[i]->nPosX[1] );
2343 rData += cTabSep;
2344 rData += String::CreateFromInt32( pTabData[i]->nPosY[0] );
2345 rData += cTabSep;
2346 rData += String::CreateFromInt32( pTabData[i]->nPosY[1] );
2351 void ScViewData::ReadUserData(const String& rData)
2353 if (!rData.Len()) // Leerer String kommt bei "neu Laden"
2354 return; // dann auch ohne Assertion beenden
2356 xub_StrLen nCount = rData.GetTokenCount(';');
2357 if ( nCount <= 2 )
2359 // #45208# beim Reload in der Seitenansicht sind evtl. die Preview-UserData
2360 // stehengelassen worden. Den Zoom von der Preview will man hier nicht...
2361 DBG_ERROR("ReadUserData: das sind nicht meine Daten");
2362 return;
2365 String aTabOpt;
2366 xub_StrLen nTagLen = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(TAG_TABBARWIDTH)).Len();
2368 //-------------------
2369 // nicht pro Tabelle:
2370 //-------------------
2371 SCTAB nTabStart = 2;
2373 Fraction aZoomX, aZoomY, aPageZoomX, aPageZoomY; //! evaluate (all sheets?)
2375 String aZoomStr = rData.GetToken(0); // Zoom/PageZoom/Modus
2376 USHORT nNormZoom = sal::static_int_cast<USHORT>(aZoomStr.GetToken(0,'/').ToInt32());
2377 if ( nNormZoom >= MINZOOM && nNormZoom <= MAXZOOM )
2378 aZoomX = aZoomY = Fraction( nNormZoom, 100 ); // "normaler" Zoom (immer)
2379 USHORT nPageZoom = sal::static_int_cast<USHORT>(aZoomStr.GetToken(1,'/').ToInt32());
2380 if ( nPageZoom >= MINZOOM && nPageZoom <= MAXZOOM )
2381 aPageZoomX = aPageZoomY = Fraction( nPageZoom, 100 ); // Pagebreak-Zoom, wenn gesetzt
2382 sal_Unicode cMode = aZoomStr.GetToken(2,'/').GetChar(0); // 0 oder "0"/"1"
2383 SetPagebreakMode( cMode == '1' );
2384 // SetPagebreakMode muss immer gerufen werden wegen CalcPPT / RecalcPixPos()
2387 // Tabelle kann ungueltig geworden sein (z.B. letzte Version):
2389 SCTAB nNewTab = static_cast<SCTAB>(rData.GetToken(1).ToInt32());
2390 if (pDoc->HasTable( nNewTab ))
2391 SetTabNo(nNewTab);
2394 // wenn vorhanden, TabBar-Breite holen:
2396 aTabOpt = rData.GetToken(2);
2398 if ( nTagLen && aTabOpt.Copy(0,nTagLen).EqualsAscii(TAG_TABBARWIDTH) )
2400 pView->SetTabBarWidth( aTabOpt.Copy(nTagLen).ToInt32() );
2401 nTabStart = 3;
2404 //-------------
2405 // pro Tabelle:
2406 //-------------
2407 SCTAB nPos = 0;
2408 while ( nCount > nPos+nTabStart )
2410 aTabOpt = rData.GetToken(static_cast<xub_StrLen>(nPos+nTabStart));
2411 if (!pTabData[nPos])
2412 pTabData[nPos] = new ScViewDataTable;
2414 sal_Unicode cTabSep = 0;
2415 if (aTabOpt.GetTokenCount(SC_OLD_TABSEP) >= 11)
2416 cTabSep = SC_OLD_TABSEP;
2417 #ifndef SC_LIMIT_ROWS
2418 else if (aTabOpt.GetTokenCount(SC_NEW_TABSEP) >= 11)
2419 cTabSep = SC_NEW_TABSEP;
2420 // '+' ist nur erlaubt, wenn wir mit Zeilen > 8192 umgehen koennen
2421 #endif
2423 if (cTabSep)
2425 pTabData[nPos]->nCurX = SanitizeCol( static_cast<SCCOL>(aTabOpt.GetToken(0,cTabSep).ToInt32()));
2426 pTabData[nPos]->nCurY = SanitizeRow( aTabOpt.GetToken(1,cTabSep).ToInt32());
2427 pTabData[nPos]->eHSplitMode = (ScSplitMode) aTabOpt.GetToken(2,cTabSep).ToInt32();
2428 pTabData[nPos]->eVSplitMode = (ScSplitMode) aTabOpt.GetToken(3,cTabSep).ToInt32();
2430 if ( pTabData[nPos]->eHSplitMode == SC_SPLIT_FIX )
2432 pTabData[nPos]->nFixPosX = SanitizeCol( static_cast<SCCOL>(aTabOpt.GetToken(4,cTabSep).ToInt32()));
2433 UpdateFixX(nPos);
2435 else
2436 pTabData[nPos]->nHSplitPos = aTabOpt.GetToken(4,cTabSep).ToInt32();
2438 if ( pTabData[nPos]->eVSplitMode == SC_SPLIT_FIX )
2440 pTabData[nPos]->nFixPosY = SanitizeRow( aTabOpt.GetToken(5,cTabSep).ToInt32());
2441 UpdateFixY(nPos);
2443 else
2444 pTabData[nPos]->nVSplitPos = aTabOpt.GetToken(5,cTabSep).ToInt32();
2446 pTabData[nPos]->eWhichActive = (ScSplitPos) aTabOpt.GetToken(6,cTabSep).ToInt32();
2447 pTabData[nPos]->nPosX[0] = SanitizeCol( static_cast<SCCOL>(aTabOpt.GetToken(7,cTabSep).ToInt32()));
2448 pTabData[nPos]->nPosX[1] = SanitizeCol( static_cast<SCCOL>(aTabOpt.GetToken(8,cTabSep).ToInt32()));
2449 pTabData[nPos]->nPosY[0] = SanitizeRow( aTabOpt.GetToken(9,cTabSep).ToInt32());
2450 pTabData[nPos]->nPosY[1] = SanitizeRow( aTabOpt.GetToken(10,cTabSep).ToInt32());
2452 // Test, ob der aktive Teil laut SplitMode ueberhaupt existiert
2453 // (Bug #44516#)
2454 ScSplitPos eTest = pTabData[nPos]->eWhichActive;
2455 if ( ( WhichH( eTest ) == SC_SPLIT_RIGHT &&
2456 pTabData[nPos]->eHSplitMode == SC_SPLIT_NONE ) ||
2457 ( WhichV( eTest ) == SC_SPLIT_TOP &&
2458 pTabData[nPos]->eVSplitMode == SC_SPLIT_NONE ) )
2460 // dann wieder auf Default (unten links)
2461 pTabData[nPos]->eWhichActive = SC_SPLIT_BOTTOMLEFT;
2462 DBG_ERROR("SplitPos musste korrigiert werden");
2465 ++nPos;
2468 RecalcPixPos();
2471 void ScViewData::WriteExtOptions( ScExtDocOptions& rDocOpt ) const
2473 // *** Fill extended document data for export filters ***
2475 // document settings
2476 ScExtDocSettings& rDocSett = rDocOpt.GetDocSettings();
2478 // displayed sheet
2479 rDocSett.mnDisplTab = GetTabNo();
2481 // width of the tabbar, relative to frame window width
2482 rDocSett.mfTabBarWidth = pView->GetPendingRelTabBarWidth();
2483 if( rDocSett.mfTabBarWidth < 0.0 )
2484 rDocSett.mfTabBarWidth = pView->GetRelTabBarWidth();
2486 // sheet settings
2487 for( SCTAB nTab = 0, nTabCount = pDoc->GetTableCount(); nTab < nTabCount; ++nTab )
2489 if( const ScViewDataTable* pViewTab = pTabData[ nTab ] )
2491 ScExtTabSettings& rTabSett = rDocOpt.GetOrCreateTabSettings( nTab );
2493 // split mode
2494 ScSplitMode eHSplit = pViewTab->eHSplitMode;
2495 ScSplitMode eVSplit = pViewTab->eVSplitMode;
2496 bool bHSplit = eHSplit != SC_SPLIT_NONE;
2497 bool bVSplit = eVSplit != SC_SPLIT_NONE;
2498 bool bRealSplit = (eHSplit == SC_SPLIT_NORMAL) || (eVSplit == SC_SPLIT_NORMAL);
2499 bool bFrozen = (eHSplit == SC_SPLIT_FIX) || (eVSplit == SC_SPLIT_FIX);
2500 DBG_ASSERT( !bRealSplit || !bFrozen, "ScViewData::WriteExtOptions - split and freeze in same sheet" );
2501 rTabSett.mbFrozenPanes = !bRealSplit && bFrozen;
2503 // split and freeze position
2504 rTabSett.maSplitPos = Point( 0, 0 );
2505 rTabSett.maFreezePos.Set( 0, 0, nTab );
2506 if( bRealSplit )
2508 Point& rSplitPos = rTabSett.maSplitPos;
2509 rSplitPos = Point( bHSplit ? pViewTab->nHSplitPos : 0, bVSplit ? pViewTab->nVSplitPos : 0 );
2510 rSplitPos = Application::GetDefaultDevice()->PixelToLogic( rSplitPos, MapMode( MAP_TWIP ) );
2511 if( pDocShell )
2512 rSplitPos.X() = (long)((double)rSplitPos.X() / pDocShell->GetOutputFactor());
2514 else if( bFrozen )
2516 if( bHSplit ) rTabSett.maFreezePos.SetCol( pViewTab->nFixPosX );
2517 if( bVSplit ) rTabSett.maFreezePos.SetRow( pViewTab->nFixPosY );
2520 // first visible cell in top-left and additional panes
2521 rTabSett.maFirstVis.Set( pViewTab->nPosX[ SC_SPLIT_LEFT ], pViewTab->nPosY[ bVSplit ? SC_SPLIT_TOP : SC_SPLIT_BOTTOM ], nTab );
2522 rTabSett.maSecondVis.Set( pViewTab->nPosX[ SC_SPLIT_RIGHT ], pViewTab->nPosY[ SC_SPLIT_BOTTOM ], nTab );
2524 // active pane
2525 switch( pViewTab->eWhichActive )
2527 // no horizontal split -> always use left panes
2528 // no vertical split -> always use top panes
2529 case SC_SPLIT_TOPLEFT:
2530 rTabSett.meActivePane = SCEXT_PANE_TOPLEFT;
2531 break;
2532 case SC_SPLIT_TOPRIGHT:
2533 rTabSett.meActivePane = bHSplit ? SCEXT_PANE_TOPRIGHT : SCEXT_PANE_TOPLEFT;
2534 break;
2535 case SC_SPLIT_BOTTOMLEFT:
2536 rTabSett.meActivePane = bVSplit ? SCEXT_PANE_BOTTOMLEFT : SCEXT_PANE_TOPLEFT;
2537 break;
2538 case SC_SPLIT_BOTTOMRIGHT:
2539 rTabSett.meActivePane = bHSplit ?
2540 (bVSplit ? SCEXT_PANE_BOTTOMRIGHT : SCEXT_PANE_TOPRIGHT) :
2541 (bVSplit ? SCEXT_PANE_BOTTOMLEFT : SCEXT_PANE_TOPLEFT);
2542 break;
2545 // cursor position
2546 rTabSett.maCursor.Set( pViewTab->nCurX, pViewTab->nCurY, nTab );
2548 // sheet selection and selected ranges
2549 const ScMarkData& rMarkData = GetMarkData();
2550 rTabSett.mbSelected = rMarkData.GetTableSelect( nTab );
2551 rMarkData.FillRangeListWithMarks( &rTabSett.maSelection, TRUE );
2553 // grid color
2554 rTabSett.maGridColor.SetColor( COL_AUTO );
2555 if( pOptions )
2557 const Color& rGridColor = pOptions->GetGridColor();
2558 if( rGridColor.GetColor() != SC_STD_GRIDCOLOR )
2559 rTabSett.maGridColor = rGridColor;
2561 rTabSett.mbShowGrid = pViewTab->bShowGrid;
2563 // view mode and zoom
2564 rTabSett.mbPageMode = bPagebreak;
2565 rTabSett.mnNormalZoom = static_cast< long >( pViewTab->aZoomY * Fraction( 100.0 ) );
2566 rTabSett.mnPageZoom = static_cast< long >( pViewTab->aPageZoomY * Fraction( 100.0 ) );
2568 // Tab Bg Color
2569 rTabSett.maTabBgColor = pViewTab->aTabBgColor;
2574 void ScViewData::ReadExtOptions( const ScExtDocOptions& rDocOpt )
2576 // *** Get extended document data from import filters ***
2578 if( !rDocOpt.IsChanged() ) return;
2580 // document settings
2581 const ScExtDocSettings& rDocSett = rDocOpt.GetDocSettings();
2583 // displayed sheet
2584 SetTabNo( rDocSett.mnDisplTab );
2586 /* Width of the tabbar, relative to frame window width. We do not have the
2587 correct width of the frame window here -> store in ScTabView, which sets
2588 the size in the next resize. */
2589 pView->SetPendingRelTabBarWidth( rDocSett.mfTabBarWidth );
2591 // sheet settings
2592 for( SCTAB nTab = 0, nTabCount = pDoc->GetTableCount(); nTab < nTabCount; ++nTab )
2594 if( const ScExtTabSettings* pTabSett = rDocOpt.GetTabSettings( nTab ) )
2596 if( !pTabData[ nTab ] )
2597 pTabData[ nTab ] = new ScViewDataTable;
2599 const ScExtTabSettings& rTabSett = *pTabSett;
2600 ScViewDataTable& rViewTab = *pTabData[ nTab ];
2602 // split mode initialization
2603 bool bFrozen = rTabSett.mbFrozenPanes;
2604 bool bHSplit = bFrozen ? (rTabSett.maFreezePos.Col() > 0) : (rTabSett.maSplitPos.X() > 0);
2605 bool bVSplit = bFrozen ? (rTabSett.maFreezePos.Row() > 0) : (rTabSett.maSplitPos.Y() > 0);
2607 // first visible cell of top-left pane and additional panes
2608 rViewTab.nPosX[ SC_SPLIT_LEFT ] = rTabSett.maFirstVis.Col();
2609 rViewTab.nPosY[ bVSplit ? SC_SPLIT_TOP : SC_SPLIT_BOTTOM ] = rTabSett.maFirstVis.Row();
2610 if( bHSplit ) rViewTab.nPosX[ SC_SPLIT_RIGHT ] = rTabSett.maSecondVis.Col();
2611 if( bVSplit ) rViewTab.nPosY[ SC_SPLIT_BOTTOM ] = rTabSett.maSecondVis.Row();
2613 // split mode, split and freeze position
2614 rViewTab.eHSplitMode = rViewTab.eVSplitMode = SC_SPLIT_NONE;
2615 rViewTab.nHSplitPos = rViewTab.nVSplitPos = 0;
2616 rViewTab.nFixPosX = 0;
2617 rViewTab.nFixPosY = 0;
2618 if( bFrozen )
2620 if( bHSplit )
2622 rViewTab.eHSplitMode = SC_SPLIT_FIX;
2623 rViewTab.nFixPosX = rTabSett.maFreezePos.Col();
2624 UpdateFixX( nTab );
2626 if( bVSplit )
2628 rViewTab.eVSplitMode = SC_SPLIT_FIX;
2629 rViewTab.nFixPosY = rTabSett.maFreezePos.Row();
2630 UpdateFixY( nTab );
2633 else
2635 Point aPixel = Application::GetDefaultDevice()->LogicToPixel(
2636 rTabSett.maSplitPos, MapMode( MAP_TWIP ) ); //! Zoom?
2637 // #109648# - the test for use of printer metrics for text formatting here
2638 // effectively results in the nFactor = 1.0 regardless of the Option setting.
2639 if( pDocShell && SC_MOD()->GetInputOptions().GetTextWysiwyg())
2641 double nFactor = pDocShell->GetOutputFactor();
2642 aPixel.X() = (long)( aPixel.X() * nFactor + 0.5 );
2644 if( bHSplit )
2646 rViewTab.eHSplitMode = SC_SPLIT_NORMAL;
2647 rViewTab.nHSplitPos = aPixel.X();
2649 if( bVSplit )
2651 rViewTab.eVSplitMode = SC_SPLIT_NORMAL;
2652 rViewTab.nVSplitPos = aPixel.Y();
2656 // active pane
2657 ScSplitPos ePos = SC_SPLIT_BOTTOMLEFT;
2658 switch( rTabSett.meActivePane )
2660 // no horizontal split -> always use left panes
2661 // no vertical split -> always use *bottom* panes
2662 case SCEXT_PANE_TOPLEFT:
2663 ePos = bVSplit ? SC_SPLIT_TOPLEFT : SC_SPLIT_BOTTOMLEFT;
2664 break;
2665 case SCEXT_PANE_TOPRIGHT:
2666 ePos = bHSplit ?
2667 (bVSplit ? SC_SPLIT_TOPRIGHT : SC_SPLIT_BOTTOMRIGHT) :
2668 (bVSplit ? SC_SPLIT_TOPLEFT : SC_SPLIT_BOTTOMLEFT);
2669 break;
2670 case SCEXT_PANE_BOTTOMLEFT:
2671 ePos = SC_SPLIT_BOTTOMLEFT;
2672 break;
2673 case SCEXT_PANE_BOTTOMRIGHT:
2674 ePos = bHSplit ? SC_SPLIT_BOTTOMRIGHT : SC_SPLIT_BOTTOMLEFT;
2675 break;
2677 rViewTab.eWhichActive = ePos;
2679 // cursor position
2680 const ScAddress& rCursor = rTabSett.maCursor;
2681 if( rCursor.IsValid() )
2683 rViewTab.nCurX = rCursor.Col();
2684 rViewTab.nCurY = rCursor.Row();
2687 // sheet selection and selected ranges
2688 ScMarkData& rMarkData = GetMarkData();
2689 rMarkData.SelectTable( nTab, rTabSett.mbSelected );
2691 // zoom for each sheet
2692 if( rTabSett.mnNormalZoom )
2693 rViewTab.aZoomX = rViewTab.aZoomY = Fraction( rTabSett.mnNormalZoom, 100L );
2694 if( rTabSett.mnPageZoom )
2695 rViewTab.aPageZoomX = rViewTab.aPageZoomY = Fraction( rTabSett.mnPageZoom, 100L );
2697 rViewTab.bShowGrid = rTabSett.mbShowGrid;
2699 // get some settings from displayed Excel sheet, set at Calc document
2700 if( nTab == GetTabNo() )
2702 // selection only for displayed sheet, do not select single cell
2703 // Disabled, does not work correctly. Anyway, our own XML filters do not import a selection at all.
2704 // const ScRangeList& rSel = rTabSett.maSelection;
2705 // if( (rSel.Count() >= 2) || ((rSel.Count() == 1) && (*rSel.GetObject( 0 ) != ScRange( rCursor ))) )
2706 // rMarkData.MarkFromRangeList( rTabSett.maSelection, FALSE );
2708 // grid color -- #i47435# set automatic grid color explicitly
2709 if( pOptions )
2711 Color aGridColor( rTabSett.maGridColor );
2712 if( aGridColor.GetColor() == COL_AUTO )
2713 aGridColor.SetColor( SC_STD_GRIDCOLOR );
2714 pOptions->SetGridColor( aGridColor, EMPTY_STRING );
2717 // view mode and default zoom (for new sheets) from current sheet
2718 if( rTabSett.mnNormalZoom )
2719 aDefZoomX = aDefZoomY = Fraction( rTabSett.mnNormalZoom, 100L );
2720 if( rTabSett.mnPageZoom )
2721 aDefPageZoomX = aDefPageZoomY = Fraction( rTabSett.mnPageZoom, 100L );
2722 /* #i46820# set pagebreak mode via SetPagebreakMode(), this will
2723 update map modes that are needed to draw text correctly. */
2724 SetPagebreakMode( rTabSett.mbPageMode );
2727 // Tab Bg Color
2728 if( !rTabSett.IsDefaultTabBgColor() )
2729 rViewTab.aTabBgColor = rTabSett.maTabBgColor;
2733 // RecalcPixPos oder so - auch nMPos - auch bei ReadUserData ??!?!
2736 void ScViewData::WriteUserDataSequence(uno::Sequence <beans::PropertyValue>& rSettings)
2738 rSettings.realloc(SC_VIEWSETTINGS_COUNT);
2739 // + 1, because we have to put the view id in the sequence
2740 beans::PropertyValue* pSettings = rSettings.getArray();
2741 if (pSettings)
2743 sal_uInt16 nViewID(pViewShell->GetViewFrame()->GetCurViewId());
2744 pSettings[SC_VIEW_ID].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_VIEWID));
2745 rtl::OUStringBuffer sBuffer(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_VIEW)));
2746 SvXMLUnitConverter::convertNumber(sBuffer, static_cast<sal_Int32>(nViewID));
2747 pSettings[SC_VIEW_ID].Value <<= sBuffer.makeStringAndClear();
2749 SCTAB nTabCount (pDoc->GetTableCount());
2750 uno::Reference<lang::XMultiServiceFactory> xServiceFactory =
2751 comphelper::getProcessServiceFactory();
2752 DBG_ASSERT( xServiceFactory.is(), "got no service manager" );
2753 if( xServiceFactory.is() )
2755 rtl::OUString sName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.NamedPropertyValues"));
2756 uno::Reference<container::XNameContainer> xNameContainer = uno::Reference<container::XNameContainer>(xServiceFactory->createInstance(sName), uno::UNO_QUERY);
2757 if (xNameContainer.is())
2759 for (SCTAB nTab=0; nTab<nTabCount; nTab++)
2761 if (pTabData[nTab])
2763 uno::Sequence <beans::PropertyValue> aTableViewSettings;
2764 pTabData[nTab]->WriteUserDataSequence(aTableViewSettings, *this, nTab);
2765 String sTabName;
2766 GetDocument()->GetName( nTab, sTabName );
2767 rtl::OUString sOUName(sTabName);
2768 uno::Any aAny;
2769 aAny <<= aTableViewSettings;
2772 xNameContainer->insertByName(sTabName, aAny);
2774 //#101739#; two tables with the same name are possible
2775 catch ( container::ElementExistException& )
2777 DBG_ERRORFILE("seems there are two tables with the same name");
2779 catch ( uno::RuntimeException& )
2781 DBG_ERRORFILE("something went wrong");
2785 pSettings[SC_TABLE_VIEWSETTINGS].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_TABLES));
2786 pSettings[SC_TABLE_VIEWSETTINGS].Value <<= xNameContainer;
2790 String sName;
2791 GetDocument()->GetName( nTabNo, sName );
2792 rtl::OUString sOUName(sName);
2793 pSettings[SC_ACTIVE_TABLE].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ACTIVETABLE));
2794 pSettings[SC_ACTIVE_TABLE].Value <<= sOUName;
2795 pSettings[SC_HORIZONTAL_SCROLL_BAR_WIDTH].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_HORIZONTALSCROLLBARWIDTH));
2796 pSettings[SC_HORIZONTAL_SCROLL_BAR_WIDTH].Value <<= sal_Int32(pView->GetTabBarWidth());
2797 sal_Int32 nZoomValue ((pThisTab->aZoomY.GetNumerator() * 100) / pThisTab->aZoomY.GetDenominator());
2798 sal_Int32 nPageZoomValue ((pThisTab->aPageZoomY.GetNumerator() * 100) / pThisTab->aPageZoomY.GetDenominator());
2799 pSettings[SC_ZOOM_TYPE].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ZOOMTYPE));
2800 pSettings[SC_ZOOM_TYPE].Value <<= sal_Int16(pThisTab->eZoomType);
2801 pSettings[SC_ZOOM_VALUE].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ZOOMVALUE));
2802 pSettings[SC_ZOOM_VALUE].Value <<= nZoomValue;
2803 pSettings[SC_PAGE_VIEW_ZOOM_VALUE].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_PAGEVIEWZOOMVALUE));
2804 pSettings[SC_PAGE_VIEW_ZOOM_VALUE].Value <<= nPageZoomValue;
2805 pSettings[SC_PAGE_BREAK_PREVIEW].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_SHOWPAGEBREAKPREVIEW));
2806 ScUnoHelpFunctions::SetBoolInAny( pSettings[SC_PAGE_BREAK_PREVIEW].Value, bPagebreak);
2808 if (pOptions)
2810 pSettings[SC_SHOWZERO].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_SHOWZERO));
2811 ScUnoHelpFunctions::SetBoolInAny( pSettings[SC_SHOWZERO].Value, pOptions->GetOption( VOPT_NULLVALS ) );
2812 pSettings[SC_SHOWNOTES].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_SHOWNOTES));
2813 ScUnoHelpFunctions::SetBoolInAny( pSettings[SC_SHOWNOTES].Value, pOptions->GetOption( VOPT_NOTES ) );
2814 pSettings[SC_SHOWGRID].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_SHOWGRID));
2815 ScUnoHelpFunctions::SetBoolInAny( pSettings[SC_SHOWGRID].Value, pOptions->GetOption( VOPT_GRID ) );
2816 pSettings[SC_GRIDCOLOR].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_GRIDCOLOR));
2817 String aColorName;
2818 Color aColor = pOptions->GetGridColor(&aColorName);
2819 pSettings[SC_GRIDCOLOR].Value <<= static_cast<sal_Int64>(aColor.GetColor());
2820 pSettings[SC_SHOWPAGEBR].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_SHOWPAGEBR));
2821 ScUnoHelpFunctions::SetBoolInAny( pSettings[SC_SHOWPAGEBR].Value, pOptions->GetOption( VOPT_PAGEBREAKS ) );
2822 pSettings[SC_COLROWHDR].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_COLROWHDR));
2823 ScUnoHelpFunctions::SetBoolInAny( pSettings[SC_COLROWHDR].Value, pOptions->GetOption( VOPT_HEADER ) );
2824 pSettings[SC_SHEETTABS].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_SHEETTABS));
2825 ScUnoHelpFunctions::SetBoolInAny( pSettings[SC_SHEETTABS].Value, pOptions->GetOption( VOPT_TABCONTROLS ) );
2826 pSettings[SC_OUTLSYMB].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_OUTLSYMB));
2827 ScUnoHelpFunctions::SetBoolInAny( pSettings[SC_OUTLSYMB].Value, pOptions->GetOption( VOPT_OUTLINER ) );
2829 const ScGridOptions& aGridOpt = pOptions->GetGridOptions();
2830 pSettings[SC_SNAPTORASTER].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_SNAPTORASTER));
2831 ScUnoHelpFunctions::SetBoolInAny( pSettings[SC_SNAPTORASTER].Value, aGridOpt.GetUseGridSnap() );
2832 pSettings[SC_RASTERVIS].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_RASTERVIS));
2833 ScUnoHelpFunctions::SetBoolInAny( pSettings[SC_RASTERVIS].Value, aGridOpt.GetGridVisible() );
2834 pSettings[SC_RASTERRESX].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_RASTERRESX));
2835 pSettings[SC_RASTERRESX].Value <<= static_cast<sal_Int32> ( aGridOpt.GetFldDrawX() );
2836 pSettings[SC_RASTERRESY].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_RASTERRESY));
2837 pSettings[SC_RASTERRESY].Value <<= static_cast<sal_Int32> ( aGridOpt.GetFldDrawY() );
2838 pSettings[SC_RASTERSUBX].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_RASTERSUBX));
2839 pSettings[SC_RASTERSUBX].Value <<= static_cast<sal_Int32> ( aGridOpt.GetFldDivisionX() );
2840 pSettings[SC_RASTERSUBY].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_RASTERSUBY));
2841 pSettings[SC_RASTERSUBY].Value <<= static_cast<sal_Int32> ( aGridOpt.GetFldDivisionY() );
2842 pSettings[SC_RASTERSYNC].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_RASTERSYNC));
2843 ScUnoHelpFunctions::SetBoolInAny( pSettings[SC_RASTERSYNC].Value, aGridOpt.GetSynchronize() );
2848 void ScViewData::ReadUserDataSequence(const uno::Sequence <beans::PropertyValue>& rSettings)
2850 Fraction aZoomX, aZoomY, aPageZoomX, aPageZoomY; //! evaluate (all sheets?)
2852 std::vector<bool> aHasZoomVect( GetDocument()->GetTableCount(), false );
2854 sal_Int32 nCount(rSettings.getLength());
2855 sal_Int32 nTemp32(0);
2856 sal_Int16 nTemp16(0);
2857 sal_Bool bPageMode(sal_False);
2858 for (sal_Int32 i = 0; i < nCount; i++)
2860 // SC_VIEWID has to parse and use by mba
2861 rtl::OUString sName(rSettings[i].Name);
2862 if (sName.compareToAscii(SC_TABLES) == 0)
2864 uno::Reference<container::XNameContainer> xNameContainer;
2865 if ((rSettings[i].Value >>= xNameContainer) && xNameContainer->hasElements())
2867 uno::Sequence< rtl::OUString > aNames(xNameContainer->getElementNames());
2868 for (sal_Int32 nTabPos = 0; nTabPos < aNames.getLength(); nTabPos++)
2870 String sTabName(aNames[nTabPos]);
2871 SCTAB nTab(0);
2872 if (GetDocument()->GetTable(sTabName, nTab))
2874 uno::Any aAny = xNameContainer->getByName(aNames[nTabPos]);
2875 uno::Sequence<beans::PropertyValue> aTabSettings;
2876 if (aAny >>= aTabSettings)
2878 pTabData[nTab] = new ScViewDataTable;
2879 bool bHasZoom = false;
2880 pTabData[nTab]->ReadUserDataSequence(aTabSettings, *this, nTab, bHasZoom);
2881 aHasZoomVect[nTab] = bHasZoom;
2887 else if (sName.compareToAscii(SC_ACTIVETABLE) == 0)
2889 rtl::OUString sValue;
2890 if(rSettings[i].Value >>= sValue)
2892 String sTabName(sValue);
2893 SCTAB nTab(0);
2894 if (GetDocument()->GetTable(sTabName, nTab))
2895 nTabNo = nTab;
2898 else if (sName.compareToAscii(SC_HORIZONTALSCROLLBARWIDTH) == 0)
2900 if (rSettings[i].Value >>= nTemp32)
2901 pView->SetTabBarWidth(nTemp32);
2903 else if (sName.compareToAscii(SC_RELHORIZONTALTABBARWIDTH) == 0)
2905 double fWidth = 0.0;
2906 if (rSettings[i].Value >>= fWidth)
2907 pView->SetPendingRelTabBarWidth( fWidth );
2909 else if (sName.compareToAscii(SC_ZOOMTYPE) == 0)
2911 if (rSettings[i].Value >>= nTemp16)
2912 eDefZoomType = SvxZoomType(nTemp16);
2914 else if (sName.compareToAscii(SC_ZOOMVALUE) == 0)
2916 if (rSettings[i].Value >>= nTemp32)
2918 Fraction aZoom(nTemp32, 100);
2919 aDefZoomX = aDefZoomY = aZoom;
2922 else if (sName.compareToAscii(SC_PAGEVIEWZOOMVALUE) == 0)
2924 if (rSettings[i].Value >>= nTemp32)
2926 Fraction aZoom(nTemp32, 100);
2927 aDefPageZoomX = aDefPageZoomY = aZoom;
2930 else if (sName.compareToAscii(SC_SHOWPAGEBREAKPREVIEW) == 0)
2931 bPageMode = ScUnoHelpFunctions::GetBoolFromAny( rSettings[i].Value );
2932 else if ( sName.compareToAscii( SC_UNO_SHOWZERO ) == 0 )
2933 pOptions->SetOption(VOPT_NULLVALS, ScUnoHelpFunctions::GetBoolFromAny( rSettings[i].Value ) );
2934 else if ( sName.compareToAscii( SC_UNO_SHOWNOTES ) == 0 )
2935 pOptions->SetOption(VOPT_NOTES, ScUnoHelpFunctions::GetBoolFromAny( rSettings[i].Value ) );
2936 else if ( sName.compareToAscii( SC_UNO_SHOWGRID ) == 0 )
2937 pOptions->SetOption(VOPT_GRID, ScUnoHelpFunctions::GetBoolFromAny( rSettings[i].Value ) );
2938 else if ( sName.compareToAscii( SC_UNO_GRIDCOLOR ) == 0 )
2940 sal_Int64 nColor = 0;
2941 if (rSettings[i].Value >>= nColor)
2943 String aColorName;
2944 Color aColor(static_cast<sal_uInt32>(nColor));
2945 // #i47435# set automatic grid color explicitly
2946 if( aColor.GetColor() == COL_AUTO )
2947 aColor.SetColor( SC_STD_GRIDCOLOR );
2948 pOptions->SetGridColor(aColor, aColorName);
2951 else if ( sName.compareToAscii( SC_UNO_SHOWPAGEBR ) == 0 )
2952 pOptions->SetOption(VOPT_PAGEBREAKS, ScUnoHelpFunctions::GetBoolFromAny( rSettings[i].Value ) );
2953 else if ( sName.compareToAscii( SC_UNO_COLROWHDR ) == 0 )
2954 pOptions->SetOption(VOPT_HEADER, ScUnoHelpFunctions::GetBoolFromAny( rSettings[i].Value ) );
2955 else if ( sName.compareToAscii( SC_UNO_SHEETTABS ) == 0 )
2956 pOptions->SetOption(VOPT_TABCONTROLS, ScUnoHelpFunctions::GetBoolFromAny( rSettings[i].Value ) );
2957 else if ( sName.compareToAscii( SC_UNO_OUTLSYMB ) == 0 )
2958 pOptions->SetOption(VOPT_OUTLINER, ScUnoHelpFunctions::GetBoolFromAny( rSettings[i].Value ) );
2959 else if ( sName.compareToAscii( SC_UNO_SHOWOBJ ) == 0 )
2961 // #i80528# placeholders not supported anymore
2962 if ( rSettings[i].Value >>= nTemp16 )
2963 pOptions->SetObjMode( VOBJ_TYPE_OLE, (nTemp16 == 1) ? VOBJ_MODE_HIDE : VOBJ_MODE_SHOW );
2965 else if ( sName.compareToAscii( SC_UNO_SHOWCHARTS ) == 0 )
2967 // #i80528# placeholders not supported anymore
2968 if ( rSettings[i].Value >>= nTemp16 )
2969 pOptions->SetObjMode( VOBJ_TYPE_CHART, (nTemp16 == 1) ? VOBJ_MODE_HIDE : VOBJ_MODE_SHOW );
2971 else if ( sName.compareToAscii( SC_UNO_SHOWDRAW ) == 0 )
2973 // #i80528# placeholders not supported anymore
2974 if ( rSettings[i].Value >>= nTemp16 )
2975 pOptions->SetObjMode( VOBJ_TYPE_DRAW, (nTemp16 == 1) ? VOBJ_MODE_HIDE : VOBJ_MODE_SHOW );
2977 else
2979 ScGridOptions aGridOpt(pOptions->GetGridOptions());
2980 if ( sName.compareToAscii( SC_UNO_SNAPTORASTER ) == 0 )
2981 aGridOpt.SetUseGridSnap( ScUnoHelpFunctions::GetBoolFromAny( rSettings[i].Value ) );
2982 else if ( sName.compareToAscii( SC_UNO_RASTERVIS ) == 0 )
2983 aGridOpt.SetGridVisible( ScUnoHelpFunctions::GetBoolFromAny( rSettings[i].Value ) );
2984 else if ( sName.compareToAscii( SC_UNO_RASTERRESX ) == 0 )
2985 aGridOpt.SetFldDrawX( static_cast <sal_uInt32> ( ScUnoHelpFunctions::GetInt32FromAny( rSettings[i].Value ) ) );
2986 else if ( sName.compareToAscii( SC_UNO_RASTERRESY ) == 0 )
2987 aGridOpt.SetFldDrawY( static_cast <sal_uInt32> ( ScUnoHelpFunctions::GetInt32FromAny( rSettings[i].Value ) ) );
2988 else if ( sName.compareToAscii( SC_UNO_RASTERSUBX ) == 0 )
2989 aGridOpt.SetFldDivisionX( static_cast <sal_uInt32> ( ScUnoHelpFunctions::GetInt32FromAny( rSettings[i].Value ) ) );
2990 else if ( sName.compareToAscii( SC_UNO_RASTERSUBY ) == 0 )
2991 aGridOpt.SetFldDivisionY( static_cast <sal_uInt32> ( ScUnoHelpFunctions::GetInt32FromAny( rSettings[i].Value ) ) );
2992 else if ( sName.compareToAscii( SC_UNO_RASTERSYNC ) == 0 )
2993 aGridOpt.SetSynchronize( ScUnoHelpFunctions::GetBoolFromAny( rSettings[i].Value ) );
2994 pOptions->SetGridOptions(aGridOpt);
2998 // copy default zoom to sheets where a different one wasn't specified
2999 for (SCTAB nZoomTab=0; nZoomTab<=MAXTAB; ++nZoomTab)
3000 if (pTabData[nZoomTab] && ( nZoomTab >= static_cast<SCTAB>(aHasZoomVect.size()) || !aHasZoomVect[nZoomTab] ))
3002 pTabData[nZoomTab]->eZoomType = eDefZoomType;
3003 pTabData[nZoomTab]->aZoomX = aDefZoomX;
3004 pTabData[nZoomTab]->aZoomY = aDefZoomY;
3005 pTabData[nZoomTab]->aPageZoomX = aDefPageZoomX;
3006 pTabData[nZoomTab]->aPageZoomY = aDefPageZoomY;
3009 if (nCount)
3010 SetPagebreakMode( bPageMode );
3012 // #i47426# write view options to document, needed e.g. for Excel export
3013 pDoc->SetViewOptions( *pOptions );
3016 void ScViewData::SetOptions( const ScViewOptions& rOpt )
3018 // if visibility of horiz. ScrollBar is changed, TabBar may have to be resized...
3019 BOOL bHScrollChanged = ( rOpt.GetOption(VOPT_HSCROLL) != pOptions->GetOption(VOPT_HSCROLL) );
3021 // if graphics are turned on or off, animation has to be started or stopped
3022 // graphics are controlled by VOBJ_TYPE_OLE
3023 BOOL bGraphicsChanged = ( pOptions->GetObjMode(VOBJ_TYPE_OLE) !=
3024 rOpt.GetObjMode(VOBJ_TYPE_OLE) );
3026 *pOptions = rOpt;
3027 DBG_ASSERT( pView, "No View" );
3029 if( pView )
3031 pView->ViewOptionsHasChanged( bHScrollChanged, bGraphicsChanged );
3035 Point ScViewData::GetMousePosPixel()
3037 DBG_ASSERT( pView, "GetMousePosPixel() ohne View" );
3038 return pView->GetMousePosPixel();
3041 void ScViewData::UpdateInputHandler( BOOL bForce, BOOL bStopEditing )
3043 if (pViewShell)
3044 pViewShell->UpdateInputHandler( bForce, bStopEditing );
3047 BOOL ScViewData::IsOle()
3049 return pDocShell && pDocShell->IsOle();
3052 BOOL ScViewData::UpdateFixX( SCTAB nTab ) // TRUE = Wert geaendert
3054 if (!ValidTab(nTab)) // Default
3055 nTab=nTabNo; // akuelle Tabelle
3057 if (!pView || pTabData[nTab]->eHSplitMode != SC_SPLIT_FIX)
3058 return FALSE;
3060 ScDocument* pLocalDoc = GetDocument();
3061 if (!pLocalDoc->HasTable(nTab)) // #114007# if called from reload, the sheet may not exist
3062 return FALSE;
3064 SCCOL nFix = pTabData[nTab]->nFixPosX;
3065 long nNewPos = 0;
3066 for (SCCOL nX=pTabData[nTab]->nPosX[SC_SPLIT_LEFT]; nX<nFix; nX++)
3068 USHORT nTSize = pLocalDoc->GetColWidth( nX, nTab );
3069 if (nTSize)
3071 long nPix = ToPixel( nTSize, nPPTX );
3072 nNewPos += nPix;
3075 nNewPos += pView->GetGridOffset().X();
3076 if (nNewPos != pTabData[nTab]->nHSplitPos)
3078 pTabData[nTab]->nHSplitPos = nNewPos;
3079 if (nTab == nTabNo)
3080 RecalcPixPos(); //! sollte nicht noetig sein !!!
3081 return TRUE;
3084 return FALSE;
3087 BOOL ScViewData::UpdateFixY( SCTAB nTab ) // TRUE = Wert geaendert
3089 if (!ValidTab(nTab)) // Default
3090 nTab=nTabNo; // akuelle Tabelle
3092 if (!pView || pTabData[nTab]->eVSplitMode != SC_SPLIT_FIX)
3093 return FALSE;
3095 ScDocument* pLocalDoc = GetDocument();
3096 if (!pLocalDoc->HasTable(nTab)) // #114007# if called from reload, the sheet may not exist
3097 return FALSE;
3099 SCROW nFix = pTabData[nTab]->nFixPosY;
3100 long nNewPos = 0;
3101 for (SCROW nY=pTabData[nTab]->nPosY[SC_SPLIT_TOP]; nY<nFix; nY++)
3103 USHORT nTSize = pLocalDoc->FastGetRowHeight( nY, nTab );
3104 if (nTSize)
3106 long nPix = ToPixel( nTSize, nPPTY );
3107 nNewPos += nPix;
3110 nNewPos += pView->GetGridOffset().Y();
3111 if (nNewPos != pTabData[nTab]->nVSplitPos)
3113 pTabData[nTab]->nVSplitPos = nNewPos;
3114 if (nTab == nTabNo)
3115 RecalcPixPos(); //! sollte nicht noetig sein !!!
3116 return TRUE;
3119 return FALSE;
3122 void ScViewData::UpdateOutlinerFlags( Outliner& rOutl ) const
3124 ScDocument* pLocalDoc = GetDocument();
3125 BOOL bOnlineSpell = pLocalDoc->GetDocOptions().IsAutoSpell();
3127 ULONG nCntrl = rOutl.GetControlWord();
3128 nCntrl |= EE_CNTRL_URLSFXEXECUTE;
3129 nCntrl |= EE_CNTRL_MARKFIELDS;
3130 nCntrl |= EE_CNTRL_AUTOCORRECT;
3131 if( bOnlineSpell )
3132 nCntrl |= EE_CNTRL_ONLINESPELLING;
3133 else
3134 nCntrl &= ~EE_CNTRL_ONLINESPELLING;
3135 rOutl.SetControlWord(nCntrl);
3137 rOutl.SetCalcFieldValueHdl( LINK( SC_MOD(), ScModule, CalcFieldValueHdl ) );
3139 // #97417# don't call GetSpellChecker if online spelling isn't enabled.
3140 // The language for AutoCorrect etc. is taken from the pool defaults
3141 // (set in ScDocument::UpdateDrawLanguages)
3143 if ( bOnlineSpell )
3145 com::sun::star::uno::Reference<com::sun::star::linguistic2::XSpellChecker1> xXSpellChecker1( LinguMgr::GetSpellChecker() );
3146 rOutl.SetSpeller( xXSpellChecker1 );
3149 rOutl.SetDefaultHorizontalTextDirection(
3150 (EEHorizontalTextDirection)pLocalDoc->GetEditTextDirection( nTabNo ) );
3153 ScAddress ScViewData::GetCurPos() const
3155 return ScAddress( GetCurX(), GetCurY(), GetTabNo() );