update dev300-m58
[ooovba.git] / sc / source / ui / view / tabvwsha.cxx
blob8b01326748547c5757a5100175b93649b1eda30c
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: tabvwsha.cxx,v $
10 * $Revision: 1.28.14.1 $
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 #define _ZFORLIST_DECLARE_TABLE
39 #include "scitems.hxx"
40 #include <svtools/slstitm.hxx>
41 #include <svtools/stritem.hxx>
42 #include <svtools/whiter.hxx>
43 #include <svtools/zformat.hxx>
44 #include <svx/boxitem.hxx>
45 #include <svx/numinf.hxx>
46 #include <svx/srchitem.hxx>
47 #include <svx/zoomslideritem.hxx>
48 #include <sfx2/bindings.hxx>
49 #include <sfx2/viewfrm.hxx>
50 #include <sfx2/dispatch.hxx>
51 #include <sfx2/request.hxx>
52 #include <vcl/msgbox.hxx>
54 #include "global.hxx"
55 #include "attrib.hxx"
56 #include "patattr.hxx"
57 #include "document.hxx"
58 #include "cell.hxx" // Input Status Edit-Zellen
59 #include "globstr.hrc"
60 #include "scmod.hxx"
61 #include "inputhdl.hxx"
62 #include "inputwin.hxx"
63 #include "docsh.hxx"
64 #include "viewdata.hxx"
65 //CHINA001 #include "attrdlg.hxx"
66 #include "appoptio.hxx"
67 #include "sc.hrc"
68 #include "stlpool.hxx"
69 #include "tabvwsh.hxx"
70 #include "dwfunctr.hxx"
71 #include "scabstdlg.hxx" //CHINA001
72 #include "compiler.hxx"
75 BOOL ScTabViewShell::GetFunction( String& rFuncStr, sal_uInt16 nErrCode )
77 String aStr;
79 ScSubTotalFunc eFunc = (ScSubTotalFunc) SC_MOD()->GetAppOptions().GetStatusFunc();
81 if (eFunc == SUBTOTAL_FUNC_CNT || eFunc == SUBTOTAL_FUNC_CNT2)
82 nErrCode = 0;
84 if (nErrCode)
86 rFuncStr = ScGlobal::GetLongErrorString(nErrCode);
87 return true;
90 USHORT nGlobStrId = 0;
91 switch (eFunc)
93 case SUBTOTAL_FUNC_AVE: nGlobStrId = STR_FUN_TEXT_AVG; break;
94 case SUBTOTAL_FUNC_CNT: nGlobStrId = STR_FUN_TEXT_COUNT; break;
95 case SUBTOTAL_FUNC_CNT2: nGlobStrId = STR_FUN_TEXT_COUNT2; break;
96 case SUBTOTAL_FUNC_MAX: nGlobStrId = STR_FUN_TEXT_MAX; break;
97 case SUBTOTAL_FUNC_MIN: nGlobStrId = STR_FUN_TEXT_MIN; break;
98 case SUBTOTAL_FUNC_SUM: nGlobStrId = STR_FUN_TEXT_SUM; break;
99 default:
101 // added to avoid warnings
104 if (nGlobStrId)
106 ScViewData* pViewData = GetViewData();
107 ScDocument* pDoc = pViewData->GetDocument();
108 ScMarkData& rMark = pViewData->GetMarkData();
109 SCCOL nPosX = pViewData->GetCurX();
110 SCROW nPosY = pViewData->GetCurY();
111 SCTAB nTab = pViewData->GetTabNo();
113 aStr = ScGlobal::GetRscString(nGlobStrId);
114 aStr += '=';
116 ScAddress aCursor( nPosX, nPosY, nTab );
117 double nVal;
118 if ( pDoc->GetSelectionFunction( eFunc, aCursor, rMark, nVal ) )
120 if ( nVal == 0.0 )
121 aStr += '0';
122 else
124 // Anzahl im Standardformat, die anderen nach Cursorposition
125 SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
126 sal_uInt32 nNumFmt = 0;
127 if ( eFunc != SUBTOTAL_FUNC_CNT && eFunc != SUBTOTAL_FUNC_CNT2 )
129 // Zahlformat aus Attributen oder Formel
130 pDoc->GetNumberFormat( nPosX, nPosY, nTab, nNumFmt );
131 if ( (nNumFmt % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
133 ScBaseCell* pCell;
134 pDoc->GetCell( nPosX, nPosY, nTab, pCell );
135 if (pCell && pCell->GetCellType() == CELLTYPE_FORMULA)
138 nNumFmt = ((ScFormulaCell*)pCell)->GetStandardFormat(*pFormatter, nNumFmt );
143 String aValStr;
144 Color* pDummy;
145 pFormatter->GetOutputString( nVal, nNumFmt, aValStr, &pDummy );
146 aStr += aValStr;
150 rFuncStr = aStr;
151 return TRUE;
154 return FALSE;
159 // Funktionen, die je nach Selektion disabled sind
160 // Default:
161 // SID_DELETE,
162 // SID_DELETE_CONTENTS,
163 // FID_DELETE_CELL
164 // FID_VALIDATION
167 void __EXPORT ScTabViewShell::GetState( SfxItemSet& rSet )
169 ScViewData* pViewData = GetViewData();
170 ScDocument* pDoc = pViewData->GetDocument();
171 ScDocShell* pDocShell = pViewData->GetDocShell();
172 ScMarkData& rMark = pViewData->GetMarkData();
173 SCCOL nPosX = pViewData->GetCurX();
174 SCROW nPosY = pViewData->GetCurY();
175 SCTAB nTab = pViewData->GetTabNo();
176 USHORT nMyId = 0;
178 SfxViewFrame* pThisFrame = GetViewFrame();
179 BOOL bOle = GetViewFrame()->GetFrame()->IsInPlace();
181 SCTAB nTabCount = pDoc->GetTableCount();
182 SCTAB nTabSelCount = rMark.GetSelectCount();
184 SfxWhichIter aIter(rSet);
185 USHORT nWhich = aIter.FirstWhich();
187 while ( nWhich )
189 switch ( nWhich )
191 case FID_CHG_COMMENT:
193 ScDocShell* pDocSh = GetViewData()->GetDocShell();
194 ScAddress aPos( nPosX, nPosY, nTab );
195 if ( pDocSh->IsReadOnly() || !pDocSh->GetChangeAction(aPos) || pDocSh->IsDocShared() )
196 rSet.DisableItem( nWhich );
198 break;
200 case SID_OPENDLG_EDIT_PRINTAREA:
201 case SID_ADD_PRINTAREA:
202 case SID_DEFINE_PRINTAREA:
204 if ( pDocShell && pDocShell->IsDocShared() )
206 rSet.DisableItem( nWhich );
209 break;
211 case SID_DELETE_PRINTAREA:
212 if ( nTabSelCount > 1 )
214 // #i22589# also take "Print Entire Sheet" into account here
215 BOOL bHas = FALSE;
216 for (SCTAB i=0; !bHas && i<nTabCount; i++)
217 bHas = rMark.GetTableSelect(i) && (pDoc->GetPrintRangeCount(i) || pDoc->IsPrintEntireSheet(i));
218 if (!bHas)
219 rSet.DisableItem( nWhich );
221 else if ( !pDoc->GetPrintRangeCount( nTab ) && !pDoc->IsPrintEntireSheet( nTab ) )
222 rSet.DisableItem( nWhich );
223 if ( pDocShell && pDocShell->IsDocShared() )
225 rSet.DisableItem( nWhich );
227 break;
229 case SID_STATUS_PAGESTYLE:
230 case SID_HFEDIT:
231 GetViewData()->GetDocShell()->GetStatePageStyle( *this, rSet, nTab );
232 break;
234 case SID_SEARCH_ITEM:
236 SvxSearchItem aItem(ScGlobal::GetSearchItem()); // make a copy.
237 // Search on current selection if a range is marked.
238 aItem.SetSelection(rMark.IsMarked());
239 rSet.Put(aItem);
240 break;
243 case SID_SEARCH_OPTIONS:
245 USHORT nOptions = 0xffff; // alles erlaubt
246 // wenn ReadOnly, kein Ersetzen:
247 if (GetViewData()->GetDocShell()->IsReadOnly())
248 nOptions &= ~( SEARCH_OPTIONS_REPLACE | SEARCH_OPTIONS_REPLACE_ALL );
249 rSet.Put( SfxUInt16Item( nWhich, nOptions ) );
251 break;
253 case SID_CURRENTCELL:
255 ScAddress aScAddress( GetViewData()->GetCurX(), GetViewData()->GetCurY(), 0 );
256 String aAddr;
257 aScAddress.Format( aAddr, SCA_ABS, NULL, pDoc->GetAddressConvention() );
258 SfxStringItem aPosItem( SID_CURRENTCELL, aAddr );
260 rSet.Put( aPosItem );
262 break;
264 case SID_CURRENTTAB:
265 // Tabelle fuer Basic ist 1-basiert
266 rSet.Put( SfxUInt16Item( nWhich, static_cast<sal_uInt16>(GetViewData()->GetTabNo()) + 1 ) );
267 break;
269 case SID_CURRENTDOC:
270 rSet.Put( SfxStringItem( nWhich, GetViewData()->GetDocShell()->GetTitle() ) );
271 break;
273 case FID_TOGGLEINPUTLINE:
275 USHORT nId = ScInputWindowWrapper::GetChildWindowId();
277 if ( pThisFrame->KnowsChildWindow( nId ) )
279 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
280 rSet.Put( SfxBoolItem( nWhich, pWnd ? TRUE : FALSE ) );
282 else
283 rSet.DisableItem( nWhich );
285 break;
287 case FID_DEL_MANUALBREAKS:
288 if (!pDoc->HasManualBreaks(nTab))
289 rSet.DisableItem( nWhich );
290 break;
292 case FID_RESET_PRINTZOOM:
294 // disablen, wenn schon Default eingestellt
296 String aStyleName = pDoc->GetPageStyle( nTab );
297 ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool();
298 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName,
299 SFX_STYLE_FAMILY_PAGE );
300 DBG_ASSERT( pStyleSheet, "PageStyle not found" );
301 if ( pStyleSheet )
303 SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
304 USHORT nScale = ((const SfxUInt16Item&)
305 rStyleSet.Get(ATTR_PAGE_SCALE)).GetValue();
306 USHORT nPages = ((const SfxUInt16Item&)
307 rStyleSet.Get(ATTR_PAGE_SCALETOPAGES)).GetValue();
308 if ( nScale == 100 && nPages == 0 )
309 rSet.DisableItem( nWhich );
312 break;
314 case FID_SCALE:
315 case SID_ATTR_ZOOM:
316 if ( bOle )
317 rSet.DisableItem( nWhich );
318 else
320 const Fraction& rOldY = GetViewData()->GetZoomY();
321 USHORT nZoom = (USHORT)(( rOldY.GetNumerator() * 100 )
322 / rOldY.GetDenominator());
323 rSet.Put( SvxZoomItem( SVX_ZOOM_PERCENT, nZoom, nWhich ) );
325 break;
327 case SID_ATTR_ZOOMSLIDER:
329 if ( bOle )
330 rSet.DisableItem( nWhich );
331 else
333 const Fraction& rOldY = GetViewData()->GetZoomY();
334 USHORT nCurrentZoom = (USHORT)(( rOldY.GetNumerator() * 100 ) / rOldY.GetDenominator());
336 if( nCurrentZoom )
338 SvxZoomSliderItem aZoomSliderItem( nCurrentZoom, MINZOOM, MAXZOOM, SID_ATTR_ZOOMSLIDER );
339 aZoomSliderItem.AddSnappingPoint( 100 );
340 rSet.Put( aZoomSliderItem );
344 break;
346 case FID_TOGGLESYNTAX:
347 rSet.Put(SfxBoolItem(nWhich, GetViewData()->IsSyntaxMode()));
348 break;
350 case FID_TOGGLEHEADERS:
351 rSet.Put(SfxBoolItem(nWhich, GetViewData()->IsHeaderMode()));
352 break;
354 case FID_TOGGLEFORMULA:
356 const ScViewOptions& rOpts = pViewData->GetOptions();
357 BOOL bFormulaMode = rOpts.GetOption( VOPT_FORMULAS );
358 rSet.Put(SfxBoolItem(nWhich, bFormulaMode ));
360 break;
362 case FID_NORMALVIEWMODE:
363 case FID_PAGEBREAKMODE:
364 // always handle both slots - they exclude each other
365 if ( bOle )
367 rSet.DisableItem( FID_NORMALVIEWMODE );
368 rSet.DisableItem( FID_PAGEBREAKMODE );
370 else
372 rSet.Put(SfxBoolItem(FID_NORMALVIEWMODE, !GetViewData()->IsPagebreakMode()));
373 rSet.Put(SfxBoolItem(FID_PAGEBREAKMODE, GetViewData()->IsPagebreakMode()));
375 break;
377 case FID_FUNCTION_BOX:
378 nMyId = ScFunctionChildWindow::GetChildWindowId();
379 rSet.Put(SfxBoolItem(FID_FUNCTION_BOX, pThisFrame->HasChildWindow(nMyId)));
380 break;
382 case FID_PROTECT_DOC:
384 if ( pDocShell && pDocShell->IsDocShared() )
386 rSet.DisableItem( nWhich );
388 else
390 rSet.Put( SfxBoolItem( nWhich, pDoc->IsDocProtected() ) );
393 break;
395 case FID_PROTECT_TABLE:
397 if ( pDocShell && pDocShell->IsDocShared() )
399 rSet.DisableItem( nWhich );
401 else
403 rSet.Put( SfxBoolItem( nWhich, pDoc->IsTabProtected( nTab ) ) );
406 break;
408 case SID_AUTO_OUTLINE:
410 if (pDoc->GetChangeTrack()!=NULL || GetViewData()->IsMultiMarked())
412 rSet.DisableItem( nWhich );
415 break;
417 case SID_OUTLINE_DELETEALL:
419 SCTAB nOlTab = GetViewData()->GetTabNo();
420 ScOutlineTable* pOlTable = pDoc->GetOutlineTable( nOlTab );
421 if (pOlTable == NULL)
422 rSet.DisableItem( nWhich );
424 break;
426 case SID_WINDOW_SPLIT:
427 rSet.Put(SfxBoolItem(nWhich,
428 pViewData->GetHSplitMode() == SC_SPLIT_NORMAL ||
429 pViewData->GetVSplitMode() == SC_SPLIT_NORMAL ));
430 break;
432 case SID_WINDOW_FIX:
433 rSet.Put(SfxBoolItem(nWhich,
434 pViewData->GetHSplitMode() == SC_SPLIT_FIX ||
435 pViewData->GetVSplitMode() == SC_SPLIT_FIX ));
436 break;
438 case FID_CHG_SHOW:
440 if ( pDoc->GetChangeTrack() == NULL || ( pDocShell && pDocShell->IsDocShared() ) )
441 rSet.DisableItem( nWhich );
443 break;
444 case FID_CHG_ACCEPT:
446 rSet.Put(SfxBoolItem(FID_CHG_ACCEPT,
447 pThisFrame->HasChildWindow(FID_CHG_ACCEPT)));
448 if(pDoc->GetChangeTrack()==NULL)
450 if ( !pThisFrame->HasChildWindow(FID_CHG_ACCEPT) )
452 rSet.DisableItem( nWhich);
455 if ( pDocShell && pDocShell->IsDocShared() )
457 rSet.DisableItem( nWhich );
460 break;
462 case SID_FORMATPAGE:
463 //! bei geschuetzten Tabellen ???
464 if ( pDocShell && ( pDocShell->IsReadOnly() || pDocShell->IsDocShared() ) )
465 rSet.DisableItem( nWhich );
466 break;
468 case SID_PRINTPREVIEW:
469 // #58924# Toggle-Slot braucht einen State
470 rSet.Put( SfxBoolItem( nWhich, FALSE ) );
471 break;
473 case SID_READONLY_MODE:
474 rSet.Put( SfxBoolItem( nWhich, GetViewData()->GetDocShell()->IsReadOnly() ) );
475 break;
477 case FID_TAB_DESELECTALL:
478 if ( nTabSelCount == 1 )
479 rSet.DisableItem( nWhich ); // enabled only if several sheets are selected
480 break;
482 } // switch ( nWitch )
483 nWhich = aIter.NextWhich();
484 } // while ( nWitch )
487 //------------------------------------------------------------------
488 void ScTabViewShell::ExecuteCellFormatDlg( SfxRequest& rReq, USHORT nTabPage )
490 //CHINA001 ScAttrDlg* pDlg = NULL;
491 SfxAbstractTabDialog * pDlg = NULL; //CHINA001
492 ScDocument* pDoc = GetViewData()->GetDocument();
494 SvxBoxItem aLineOuter( ATTR_BORDER );
495 SvxBoxInfoItem aLineInner( ATTR_BORDER_INNER );
497 SvxNumberInfoItem* pNumberInfoItem = NULL;
498 const ScPatternAttr* pOldAttrs = GetSelectionPattern();
499 SfxItemSet* pOldSet = new SfxItemSet(
500 pOldAttrs->GetItemSet() );
503 // Umrandungs-Items holen und in den Set packen:
504 GetSelectionFrame( aLineOuter, aLineInner );
505 pOldSet->Put( aLineOuter );
506 pOldSet->Put( aLineInner );
508 // NumberFormat Value aus Value und Language erzeugen und eintueten
509 pOldSet->Put( SfxUInt32Item( ATTR_VALUE_FORMAT,
510 pOldAttrs->GetNumberFormat( pDoc->GetFormatTable() ) ) );
512 MakeNumberInfoItem( pDoc, GetViewData(), &pNumberInfoItem );
514 pOldSet->MergeRange( SID_ATTR_NUMBERFORMAT_INFO, SID_ATTR_NUMBERFORMAT_INFO );
515 pOldSet->Put(*pNumberInfoItem );
517 bInFormatDialog = TRUE;
518 //CHINA001 pDlg = new ScAttrDlg( GetViewFrame(), GetDialogParent(), pOldSet );
519 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
520 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
522 pDlg = pFact->CreateScAttrDlg( GetViewFrame(), GetDialogParent(), pOldSet, RID_SCDLG_ATTR);
523 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
524 if ( nTabPage != 0xffff )
525 pDlg->SetCurPageId( nTabPage );
526 short nResult = pDlg->Execute();
527 bInFormatDialog = FALSE;
529 if ( nResult == RET_OK )
531 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
533 const SfxPoolItem* pItem=NULL;
534 if(pOutSet->GetItemState(SID_ATTR_NUMBERFORMAT_INFO,TRUE,&pItem)==SFX_ITEM_SET)
537 UpdateNumberFormatter( pDoc,(const SvxNumberInfoItem&)*pItem);
540 ApplyAttributes( pOutSet, pOldSet );
542 rReq.Done( *pOutSet );
544 delete pOldSet;
545 delete pNumberInfoItem;
546 delete pDlg;
549 //------------------------------------------------------------------
551 bool ScTabViewShell::IsRefInputMode() const
553 ScModule* pScMod = SC_MOD();
554 if ( pScMod )
556 if( pScMod->IsRefDialogOpen() )
557 return pScMod->IsFormulaMode();
558 if( pScMod->IsFormulaMode() )
560 ScInputHandler* pHdl = pScMod->GetInputHdl();
561 if ( pHdl )
563 String aString = pHdl->GetEditString();
564 if ( !pHdl->GetSelIsRef() && aString.Len() > 1 &&
565 ( aString.GetChar(0) == '+' || aString.GetChar(0) == '-' ) )
567 const ScViewData* pViewData = GetViewData();
568 if ( pViewData )
570 ScDocument* pDoc = pViewData->GetDocument();
571 if ( pDoc )
573 const ScAddress aPos( pViewData->GetCurPos() );
574 ScCompiler aComp( pDoc, aPos );
575 aComp.SetGrammar(pDoc->GetGrammar());
576 aComp.SetCloseBrackets( false );
577 ScTokenArray* pArr = aComp.CompileString( aString );
578 if ( pArr && pArr->MayReferenceFollow() )
580 return true;
585 else
587 return true;
593 return false;
596 //------------------------------------------------------------------
598 void ScTabViewShell::ExecuteInputDirect()
600 if ( !IsRefInputMode() )
602 ScModule* pScMod = SC_MOD();
603 if ( pScMod )
605 pScMod->InputEnterHandler();
610 //------------------------------------------------------------------
612 void ScTabViewShell::UpdateInputHandler( BOOL bForce /* = FALSE */, BOOL bStopEditing /* = TRUE */ )
614 ScInputHandler* pHdl = pInputHandler ? pInputHandler : SC_MOD()->GetInputHdl();
616 if ( pHdl )
618 String aString;
619 const EditTextObject* pObject = NULL;
620 ScViewData* pViewData = GetViewData();
621 ScDocument* pDoc = pViewData->GetDocument();
622 CellType eType;
623 SCCOL nPosX = pViewData->GetCurX();
624 SCROW nPosY = pViewData->GetCurY();
625 SCTAB nTab = pViewData->GetTabNo();
626 SCTAB nStartTab = 0;
627 SCTAB nEndTab = 0;
628 SCCOL nStartCol = 0;
629 SCROW nStartRow = 0;
630 SCCOL nEndCol = 0;
631 SCROW nEndRow = 0;
633 pViewData->GetSimpleArea( nStartCol, nStartRow, nStartTab,
634 nEndCol, nEndRow, nEndTab );
636 PutInOrder( nStartCol, nEndCol );
637 PutInOrder( nStartRow, nEndRow );
638 PutInOrder( nStartTab, nEndTab );
640 BOOL bHideFormula = FALSE;
641 BOOL bHideAll = FALSE;
643 if (pDoc->IsTabProtected(nTab))
645 const ScProtectionAttr* pProt = (const ScProtectionAttr*)
646 pDoc->GetAttr( nPosX,nPosY,nTab,
647 ATTR_PROTECTION);
648 bHideFormula = pProt->GetHideFormula();
649 bHideAll = pProt->GetHideCell();
652 if (!bHideAll)
654 pDoc->GetCellType( nPosX, nPosY, nTab, eType );
655 if (eType == CELLTYPE_FORMULA)
657 if (!bHideFormula)
658 pDoc->GetFormula( nPosX, nPosY, nTab, aString );
660 else if (eType == CELLTYPE_EDIT)
662 ScBaseCell* pCell;
663 pDoc->GetCell( nPosX, nPosY, nTab, pCell );
664 ((ScEditCell*)pCell)->GetData( pObject );
666 else
668 pDoc->GetInputString( nPosX, nPosY, nTab, aString );
669 if (eType == CELLTYPE_STRING)
671 // Bei Bedarf ein ' vorneweg, damit der String nicht ungewollt
672 // als Zahl interpretiert wird, und um dem Benutzer zu zeigen,
673 // dass es ein String ist (#35060#).
674 //! Auch bei Zahlformat "Text"? -> dann beim Editieren wegnehmen
676 SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
677 sal_uInt32 nNumFmt;
678 pDoc->GetNumberFormat( nPosX, nPosY, nTab, nNumFmt );
679 double fDummy;
680 if ( pFormatter->IsNumberFormat(aString, nNumFmt, fDummy) )
681 aString.Insert('\'',0);
686 ScInputHdlState aState( ScAddress( nPosX, nPosY, nTab ),
687 ScAddress( nStartCol, nStartRow, nTab ),
688 ScAddress( nEndCol, nEndRow, nTab ),
689 aString,
690 pObject );
692 // if using the view's local input handler, this view can always be set
693 // as current view inside NotifyChange.
694 ScTabViewShell* pSourceSh = pInputHandler ? this : NULL;
696 pHdl->NotifyChange( &aState, bForce, pSourceSh, bStopEditing );
699 SfxBindings& rBindings = GetViewFrame()->GetBindings();
700 rBindings.Invalidate( SID_STATUS_SUM ); // immer zusammen mit Eingabezeile
701 rBindings.Invalidate( SID_ATTR_SIZE );
702 rBindings.Invalidate( SID_TABLE_CELL );
705 void ScTabViewShell::UpdateInputHandlerCellAdjust( SvxCellHorJustify eJust )
707 if( ScInputHandler* pHdl = pInputHandler ? pInputHandler : SC_MOD()->GetInputHdl() )
708 pHdl->UpdateCellAdjust( eJust );
711 //------------------------------------------------------------------
713 void __EXPORT ScTabViewShell::ExecuteSave( SfxRequest& rReq )
715 // nur SID_SAVEDOC / SID_SAVEASDOC
717 // Eingabe auf jeden Fall abschliessen, auch wenn eine Formel bearbeitet wird
718 SC_MOD()->InputEnterHandler();
720 if ( GetViewData()->GetDocShell()->IsDocShared() )
722 GetViewData()->GetDocShell()->SetDocumentModified();
725 // ansonsten normal weiter
726 GetViewData()->GetDocShell()->ExecuteSlot( rReq );
729 void __EXPORT ScTabViewShell::GetSaveState( SfxItemSet& rSet )
731 SfxShell* pDocSh = GetViewData()->GetDocShell();
733 SfxWhichIter aIter(rSet);
734 USHORT nWhich = aIter.FirstWhich();
735 while( nWhich )
737 if ( nWhich != SID_SAVEDOC || !GetViewData()->GetDocShell()->IsDocShared() )
739 // get state from DocShell
740 pDocSh->GetSlotState( nWhich, NULL, &rSet );
742 nWhich = aIter.NextWhich();
746 //------------------------------------------------------------------
748 void ScTabViewShell::ExecuteUndo(SfxRequest& rReq)
750 SfxShell* pSh = GetViewData()->GetDispatcher().GetShell(0);
751 SfxUndoManager* pUndoManager = pSh->GetUndoManager();
753 const SfxItemSet* pReqArgs = rReq.GetArgs();
754 ScDocShell* pDocSh = GetViewData()->GetDocShell();
756 USHORT nSlot = rReq.GetSlot();
757 switch ( nSlot )
759 case SID_UNDO:
760 case SID_REDO:
761 if ( pUndoManager )
763 BOOL bIsUndo = ( nSlot == SID_UNDO );
765 USHORT nCount = 1;
766 const SfxPoolItem* pItem;
767 if ( pReqArgs && pReqArgs->GetItemState( nSlot, TRUE, &pItem ) == SFX_ITEM_SET )
768 nCount = ((const SfxUInt16Item*)pItem)->GetValue();
770 // lock paint for more than one cell undo action (not for editing within a cell)
771 BOOL bLockPaint = ( nCount > 1 && pUndoManager == GetUndoManager() );
772 if ( bLockPaint )
773 pDocSh->LockPaint();
775 for (USHORT i=0; i<nCount; i++)
777 if ( bIsUndo )
778 pUndoManager->Undo(0);
779 else
780 pUndoManager->Redo(0);
783 if ( bLockPaint )
784 pDocSh->UnlockPaint();
786 GetViewFrame()->GetBindings().InvalidateAll(sal_False);
788 break;
789 // default:
790 // GetViewFrame()->ExecuteSlot( rReq );
794 void ScTabViewShell::GetUndoState(SfxItemSet &rSet)
796 SfxShell* pSh = GetViewData()->GetDispatcher().GetShell(0);
797 SfxUndoManager* pUndoManager = pSh->GetUndoManager();
799 SfxWhichIter aIter(rSet);
800 USHORT nWhich = aIter.FirstWhich();
801 while ( nWhich )
803 switch (nWhich)
805 case SID_GETUNDOSTRINGS:
806 case SID_GETREDOSTRINGS:
808 SfxStringListItem aStrLst( nWhich );
809 if ( pUndoManager )
811 List* pList = aStrLst.GetList();
812 BOOL bIsUndo = ( nWhich == SID_GETUNDOSTRINGS );
813 USHORT nCount = bIsUndo ? pUndoManager->GetUndoActionCount() : pUndoManager->GetRedoActionCount();
814 for (USHORT i=0; i<nCount; i++)
815 pList->Insert( new String( bIsUndo ? pUndoManager->GetUndoActionComment(i) :
816 pUndoManager->GetRedoActionComment(i) ),
817 LIST_APPEND );
819 rSet.Put( aStrLst );
821 break;
822 default:
823 // get state from sfx view frame
824 GetViewFrame()->GetSlotState( nWhich, NULL, &rSet );
827 nWhich = aIter.NextWhich();
832 //------------------------------------------------------------------
834 void ScTabViewShell::ExecDrawOpt( SfxRequest& rReq )
836 ScViewOptions aViewOptions = GetViewData()->GetOptions();
837 ScGridOptions aGridOptions = aViewOptions.GetGridOptions();
839 SfxBindings& rBindings = GetViewFrame()->GetBindings();
840 const SfxItemSet* pArgs = rReq.GetArgs();
841 const SfxPoolItem* pItem;
842 USHORT nSlotId = rReq.GetSlot();
843 switch (nSlotId)
845 case SID_GRID_VISIBLE:
846 if ( pArgs && pArgs->GetItemState(nSlotId,TRUE,&pItem) == SFX_ITEM_SET )
848 aGridOptions.SetGridVisible( ((const SfxBoolItem*)pItem)->GetValue() );
849 aViewOptions.SetGridOptions(aGridOptions);
850 rBindings.Invalidate(SID_GRID_VISIBLE);
852 break;
854 case SID_GRID_USE:
855 if ( pArgs && pArgs->GetItemState(nSlotId,TRUE,&pItem) == SFX_ITEM_SET )
857 aGridOptions.SetUseGridSnap( ((const SfxBoolItem*)pItem)->GetValue() );
858 aViewOptions.SetGridOptions(aGridOptions);
859 rBindings.Invalidate(SID_GRID_USE);
861 break;
863 case SID_HELPLINES_MOVE:
864 if ( pArgs && pArgs->GetItemState(nSlotId,TRUE,&pItem) == SFX_ITEM_SET )
866 aViewOptions.SetOption( VOPT_HELPLINES, ((const SfxBoolItem*)pItem)->GetValue() );
867 rBindings.Invalidate(SID_HELPLINES_MOVE);
869 break;
872 GetViewData()->SetOptions(aViewOptions);
875 void ScTabViewShell::GetDrawOptState( SfxItemSet& rSet )
877 SfxBoolItem aBool;
879 const ScViewOptions& rViewOptions = GetViewData()->GetOptions();
880 const ScGridOptions& rGridOptions = rViewOptions.GetGridOptions();
882 aBool.SetValue(rGridOptions.GetGridVisible());
883 aBool.SetWhich( SID_GRID_VISIBLE );
884 rSet.Put( aBool );
886 aBool.SetValue(rGridOptions.GetUseGridSnap());
887 aBool.SetWhich( SID_GRID_USE );
888 rSet.Put( aBool );
890 aBool.SetValue(rViewOptions.GetOption( VOPT_HELPLINES ));
891 aBool.SetWhich( SID_HELPLINES_MOVE );
892 rSet.Put( aBool );