merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / view / tabvwsha.cxx
blob4005e5dce519b7915eb8733bac00e9cb58953d8a
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();
80 ScViewData* pViewData = GetViewData();
81 ScMarkData& rMark = pViewData->GetMarkData();
82 bool bIgnoreError = (rMark.IsMarked() || rMark.IsMultiMarked());
84 if (bIgnoreError && (eFunc == SUBTOTAL_FUNC_CNT || eFunc == SUBTOTAL_FUNC_CNT2))
85 nErrCode = 0;
87 if (nErrCode)
89 rFuncStr = ScGlobal::GetLongErrorString(nErrCode);
90 return true;
93 USHORT nGlobStrId = 0;
94 switch (eFunc)
96 case SUBTOTAL_FUNC_AVE: nGlobStrId = STR_FUN_TEXT_AVG; break;
97 case SUBTOTAL_FUNC_CNT: nGlobStrId = STR_FUN_TEXT_COUNT; break;
98 case SUBTOTAL_FUNC_CNT2: nGlobStrId = STR_FUN_TEXT_COUNT2; break;
99 case SUBTOTAL_FUNC_MAX: nGlobStrId = STR_FUN_TEXT_MAX; break;
100 case SUBTOTAL_FUNC_MIN: nGlobStrId = STR_FUN_TEXT_MIN; break;
101 case SUBTOTAL_FUNC_SUM: nGlobStrId = STR_FUN_TEXT_SUM; break;
102 default:
104 // added to avoid warnings
107 if (nGlobStrId)
109 ScDocument* pDoc = pViewData->GetDocument();
110 SCCOL nPosX = pViewData->GetCurX();
111 SCROW nPosY = pViewData->GetCurY();
112 SCTAB nTab = pViewData->GetTabNo();
114 aStr = ScGlobal::GetRscString(nGlobStrId);
115 aStr += '=';
117 ScAddress aCursor( nPosX, nPosY, nTab );
118 double nVal;
119 if ( pDoc->GetSelectionFunction( eFunc, aCursor, rMark, nVal ) )
121 if ( nVal == 0.0 )
122 aStr += '0';
123 else
125 // Anzahl im Standardformat, die anderen nach Cursorposition
126 SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
127 sal_uInt32 nNumFmt = 0;
128 if ( eFunc != SUBTOTAL_FUNC_CNT && eFunc != SUBTOTAL_FUNC_CNT2 )
130 // Zahlformat aus Attributen oder Formel
131 pDoc->GetNumberFormat( nPosX, nPosY, nTab, nNumFmt );
132 if ( (nNumFmt % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
134 ScBaseCell* pCell;
135 pDoc->GetCell( nPosX, nPosY, nTab, pCell );
136 if (pCell && pCell->GetCellType() == CELLTYPE_FORMULA)
139 nNumFmt = ((ScFormulaCell*)pCell)->GetStandardFormat(*pFormatter, nNumFmt );
144 String aValStr;
145 Color* pDummy;
146 pFormatter->GetOutputString( nVal, nNumFmt, aValStr, &pDummy );
147 aStr += aValStr;
151 rFuncStr = aStr;
152 return TRUE;
155 return FALSE;
160 // Funktionen, die je nach Selektion disabled sind
161 // Default:
162 // SID_DELETE,
163 // SID_DELETE_CONTENTS,
164 // FID_DELETE_CELL
165 // FID_VALIDATION
168 void __EXPORT ScTabViewShell::GetState( SfxItemSet& rSet )
170 ScViewData* pViewData = GetViewData();
171 ScDocument* pDoc = pViewData->GetDocument();
172 ScDocShell* pDocShell = pViewData->GetDocShell();
173 ScMarkData& rMark = pViewData->GetMarkData();
174 SCCOL nPosX = pViewData->GetCurX();
175 SCROW nPosY = pViewData->GetCurY();
176 SCTAB nTab = pViewData->GetTabNo();
177 USHORT nMyId = 0;
179 SfxViewFrame* pThisFrame = GetViewFrame();
180 BOOL bOle = GetViewFrame()->GetFrame()->IsInPlace();
182 SCTAB nTabCount = pDoc->GetTableCount();
183 SCTAB nTabSelCount = rMark.GetSelectCount();
185 SfxWhichIter aIter(rSet);
186 USHORT nWhich = aIter.FirstWhich();
188 while ( nWhich )
190 switch ( nWhich )
192 case FID_CHG_COMMENT:
194 ScDocShell* pDocSh = GetViewData()->GetDocShell();
195 ScAddress aPos( nPosX, nPosY, nTab );
196 if ( pDocSh->IsReadOnly() || !pDocSh->GetChangeAction(aPos) || pDocSh->IsDocShared() )
197 rSet.DisableItem( nWhich );
199 break;
201 case SID_OPENDLG_EDIT_PRINTAREA:
202 case SID_ADD_PRINTAREA:
203 case SID_DEFINE_PRINTAREA:
205 if ( pDocShell && pDocShell->IsDocShared() )
207 rSet.DisableItem( nWhich );
210 break;
212 case SID_DELETE_PRINTAREA:
213 if ( nTabSelCount > 1 )
215 // #i22589# also take "Print Entire Sheet" into account here
216 BOOL bHas = FALSE;
217 for (SCTAB i=0; !bHas && i<nTabCount; i++)
218 bHas = rMark.GetTableSelect(i) && (pDoc->GetPrintRangeCount(i) || pDoc->IsPrintEntireSheet(i));
219 if (!bHas)
220 rSet.DisableItem( nWhich );
222 else if ( !pDoc->GetPrintRangeCount( nTab ) && !pDoc->IsPrintEntireSheet( nTab ) )
223 rSet.DisableItem( nWhich );
224 if ( pDocShell && pDocShell->IsDocShared() )
226 rSet.DisableItem( nWhich );
228 break;
230 case SID_STATUS_PAGESTYLE:
231 case SID_HFEDIT:
232 GetViewData()->GetDocShell()->GetStatePageStyle( *this, rSet, nTab );
233 break;
235 case SID_SEARCH_ITEM:
237 SvxSearchItem aItem(ScGlobal::GetSearchItem()); // make a copy.
238 // Search on current selection if a range is marked.
239 aItem.SetSelection(rMark.IsMarked());
240 rSet.Put(aItem);
241 break;
244 case SID_SEARCH_OPTIONS:
246 USHORT nOptions = 0xffff; // alles erlaubt
247 // wenn ReadOnly, kein Ersetzen:
248 if (GetViewData()->GetDocShell()->IsReadOnly())
249 nOptions &= ~( SEARCH_OPTIONS_REPLACE | SEARCH_OPTIONS_REPLACE_ALL );
250 rSet.Put( SfxUInt16Item( nWhich, nOptions ) );
252 break;
254 case SID_CURRENTCELL:
256 ScAddress aScAddress( GetViewData()->GetCurX(), GetViewData()->GetCurY(), 0 );
257 String aAddr;
258 aScAddress.Format( aAddr, SCA_ABS, NULL, pDoc->GetAddressConvention() );
259 SfxStringItem aPosItem( SID_CURRENTCELL, aAddr );
261 rSet.Put( aPosItem );
263 break;
265 case SID_CURRENTTAB:
266 // Tabelle fuer Basic ist 1-basiert
267 rSet.Put( SfxUInt16Item( nWhich, static_cast<sal_uInt16>(GetViewData()->GetTabNo()) + 1 ) );
268 break;
270 case SID_CURRENTDOC:
271 rSet.Put( SfxStringItem( nWhich, GetViewData()->GetDocShell()->GetTitle() ) );
272 break;
274 case FID_TOGGLEINPUTLINE:
276 USHORT nId = ScInputWindowWrapper::GetChildWindowId();
278 if ( pThisFrame->KnowsChildWindow( nId ) )
280 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
281 rSet.Put( SfxBoolItem( nWhich, pWnd ? TRUE : FALSE ) );
283 else
284 rSet.DisableItem( nWhich );
286 break;
288 case FID_DEL_MANUALBREAKS:
289 if (!pDoc->HasManualBreaks(nTab))
290 rSet.DisableItem( nWhich );
291 break;
293 case FID_RESET_PRINTZOOM:
295 // disablen, wenn schon Default eingestellt
297 String aStyleName = pDoc->GetPageStyle( nTab );
298 ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool();
299 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName,
300 SFX_STYLE_FAMILY_PAGE );
301 DBG_ASSERT( pStyleSheet, "PageStyle not found" );
302 if ( pStyleSheet )
304 SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
305 USHORT nScale = ((const SfxUInt16Item&)
306 rStyleSet.Get(ATTR_PAGE_SCALE)).GetValue();
307 USHORT nPages = ((const SfxUInt16Item&)
308 rStyleSet.Get(ATTR_PAGE_SCALETOPAGES)).GetValue();
309 if ( nScale == 100 && nPages == 0 )
310 rSet.DisableItem( nWhich );
313 break;
315 case FID_SCALE:
316 case SID_ATTR_ZOOM:
317 if ( bOle )
318 rSet.DisableItem( nWhich );
319 else
321 const Fraction& rOldY = GetViewData()->GetZoomY();
322 USHORT nZoom = (USHORT)(( rOldY.GetNumerator() * 100 )
323 / rOldY.GetDenominator());
324 rSet.Put( SvxZoomItem( SVX_ZOOM_PERCENT, nZoom, nWhich ) );
326 break;
328 case SID_ATTR_ZOOMSLIDER:
330 if ( bOle )
331 rSet.DisableItem( nWhich );
332 else
334 const Fraction& rOldY = GetViewData()->GetZoomY();
335 USHORT nCurrentZoom = (USHORT)(( rOldY.GetNumerator() * 100 ) / rOldY.GetDenominator());
337 if( nCurrentZoom )
339 SvxZoomSliderItem aZoomSliderItem( nCurrentZoom, MINZOOM, MAXZOOM, SID_ATTR_ZOOMSLIDER );
340 aZoomSliderItem.AddSnappingPoint( 100 );
341 rSet.Put( aZoomSliderItem );
345 break;
347 case FID_TOGGLESYNTAX:
348 rSet.Put(SfxBoolItem(nWhich, GetViewData()->IsSyntaxMode()));
349 break;
351 case FID_TOGGLEHEADERS:
352 rSet.Put(SfxBoolItem(nWhich, GetViewData()->IsHeaderMode()));
353 break;
355 case FID_TOGGLEFORMULA:
357 const ScViewOptions& rOpts = pViewData->GetOptions();
358 BOOL bFormulaMode = rOpts.GetOption( VOPT_FORMULAS );
359 rSet.Put(SfxBoolItem(nWhich, bFormulaMode ));
361 break;
363 case FID_NORMALVIEWMODE:
364 case FID_PAGEBREAKMODE:
365 // always handle both slots - they exclude each other
366 if ( bOle )
368 rSet.DisableItem( FID_NORMALVIEWMODE );
369 rSet.DisableItem( FID_PAGEBREAKMODE );
371 else
373 rSet.Put(SfxBoolItem(FID_NORMALVIEWMODE, !GetViewData()->IsPagebreakMode()));
374 rSet.Put(SfxBoolItem(FID_PAGEBREAKMODE, GetViewData()->IsPagebreakMode()));
376 break;
378 case FID_FUNCTION_BOX:
379 nMyId = ScFunctionChildWindow::GetChildWindowId();
380 rSet.Put(SfxBoolItem(FID_FUNCTION_BOX, pThisFrame->HasChildWindow(nMyId)));
381 break;
383 case FID_PROTECT_DOC:
385 if ( pDocShell && pDocShell->IsDocShared() )
387 rSet.DisableItem( nWhich );
389 else
391 rSet.Put( SfxBoolItem( nWhich, pDoc->IsDocProtected() ) );
394 break;
396 case FID_PROTECT_TABLE:
398 if ( pDocShell && pDocShell->IsDocShared() )
400 rSet.DisableItem( nWhich );
402 else
404 rSet.Put( SfxBoolItem( nWhich, pDoc->IsTabProtected( nTab ) ) );
407 break;
409 case SID_AUTO_OUTLINE:
411 if (pDoc->GetChangeTrack()!=NULL || GetViewData()->IsMultiMarked())
413 rSet.DisableItem( nWhich );
416 break;
418 case SID_OUTLINE_DELETEALL:
420 SCTAB nOlTab = GetViewData()->GetTabNo();
421 ScOutlineTable* pOlTable = pDoc->GetOutlineTable( nOlTab );
422 if (pOlTable == NULL)
423 rSet.DisableItem( nWhich );
425 break;
427 case SID_WINDOW_SPLIT:
428 rSet.Put(SfxBoolItem(nWhich,
429 pViewData->GetHSplitMode() == SC_SPLIT_NORMAL ||
430 pViewData->GetVSplitMode() == SC_SPLIT_NORMAL ));
431 break;
433 case SID_WINDOW_FIX:
434 rSet.Put(SfxBoolItem(nWhich,
435 pViewData->GetHSplitMode() == SC_SPLIT_FIX ||
436 pViewData->GetVSplitMode() == SC_SPLIT_FIX ));
437 break;
439 case FID_CHG_SHOW:
441 if ( pDoc->GetChangeTrack() == NULL || ( pDocShell && pDocShell->IsDocShared() ) )
442 rSet.DisableItem( nWhich );
444 break;
445 case FID_CHG_ACCEPT:
447 rSet.Put(SfxBoolItem(FID_CHG_ACCEPT,
448 pThisFrame->HasChildWindow(FID_CHG_ACCEPT)));
449 if(pDoc->GetChangeTrack()==NULL)
451 if ( !pThisFrame->HasChildWindow(FID_CHG_ACCEPT) )
453 rSet.DisableItem( nWhich);
456 if ( pDocShell && pDocShell->IsDocShared() )
458 rSet.DisableItem( nWhich );
461 break;
463 case SID_FORMATPAGE:
464 //! bei geschuetzten Tabellen ???
465 if ( pDocShell && ( pDocShell->IsReadOnly() || pDocShell->IsDocShared() ) )
466 rSet.DisableItem( nWhich );
467 break;
469 case SID_PRINTPREVIEW:
470 // #58924# Toggle-Slot braucht einen State
471 rSet.Put( SfxBoolItem( nWhich, FALSE ) );
472 break;
474 case SID_READONLY_MODE:
475 rSet.Put( SfxBoolItem( nWhich, GetViewData()->GetDocShell()->IsReadOnly() ) );
476 break;
478 case FID_TAB_DESELECTALL:
479 if ( nTabSelCount == 1 )
480 rSet.DisableItem( nWhich ); // enabled only if several sheets are selected
481 break;
483 } // switch ( nWitch )
484 nWhich = aIter.NextWhich();
485 } // while ( nWitch )
488 //------------------------------------------------------------------
489 void ScTabViewShell::ExecuteCellFormatDlg( SfxRequest& rReq, USHORT nTabPage )
491 //CHINA001 ScAttrDlg* pDlg = NULL;
492 SfxAbstractTabDialog * pDlg = NULL; //CHINA001
493 ScDocument* pDoc = GetViewData()->GetDocument();
495 SvxBoxItem aLineOuter( ATTR_BORDER );
496 SvxBoxInfoItem aLineInner( ATTR_BORDER_INNER );
498 SvxNumberInfoItem* pNumberInfoItem = NULL;
499 const ScPatternAttr* pOldAttrs = GetSelectionPattern();
500 SfxItemSet* pOldSet = new SfxItemSet(
501 pOldAttrs->GetItemSet() );
504 // Umrandungs-Items holen und in den Set packen:
505 GetSelectionFrame( aLineOuter, aLineInner );
506 pOldSet->Put( aLineOuter );
507 pOldSet->Put( aLineInner );
509 // NumberFormat Value aus Value und Language erzeugen und eintueten
510 pOldSet->Put( SfxUInt32Item( ATTR_VALUE_FORMAT,
511 pOldAttrs->GetNumberFormat( pDoc->GetFormatTable() ) ) );
513 MakeNumberInfoItem( pDoc, GetViewData(), &pNumberInfoItem );
515 pOldSet->MergeRange( SID_ATTR_NUMBERFORMAT_INFO, SID_ATTR_NUMBERFORMAT_INFO );
516 pOldSet->Put(*pNumberInfoItem );
518 bInFormatDialog = TRUE;
519 //CHINA001 pDlg = new ScAttrDlg( GetViewFrame(), GetDialogParent(), pOldSet );
520 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
521 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
523 pDlg = pFact->CreateScAttrDlg( GetViewFrame(), GetDialogParent(), pOldSet, RID_SCDLG_ATTR);
524 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
525 if ( nTabPage != 0xffff )
526 pDlg->SetCurPageId( nTabPage );
527 short nResult = pDlg->Execute();
528 bInFormatDialog = FALSE;
530 if ( nResult == RET_OK )
532 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
534 const SfxPoolItem* pItem=NULL;
535 if(pOutSet->GetItemState(SID_ATTR_NUMBERFORMAT_INFO,TRUE,&pItem)==SFX_ITEM_SET)
538 UpdateNumberFormatter( pDoc,(const SvxNumberInfoItem&)*pItem);
541 ApplyAttributes( pOutSet, pOldSet );
543 rReq.Done( *pOutSet );
545 delete pOldSet;
546 delete pNumberInfoItem;
547 delete pDlg;
550 //------------------------------------------------------------------
552 bool ScTabViewShell::IsRefInputMode() const
554 ScModule* pScMod = SC_MOD();
555 if ( pScMod )
557 if( pScMod->IsRefDialogOpen() )
558 return pScMod->IsFormulaMode();
559 if( pScMod->IsFormulaMode() )
561 ScInputHandler* pHdl = pScMod->GetInputHdl();
562 if ( pHdl )
564 String aString = pHdl->GetEditString();
565 if ( !pHdl->GetSelIsRef() && aString.Len() > 1 &&
566 ( aString.GetChar(0) == '+' || aString.GetChar(0) == '-' ) )
568 const ScViewData* pViewData = GetViewData();
569 if ( pViewData )
571 ScDocument* pDoc = pViewData->GetDocument();
572 if ( pDoc )
574 const ScAddress aPos( pViewData->GetCurPos() );
575 ScCompiler aComp( pDoc, aPos );
576 aComp.SetGrammar(pDoc->GetGrammar());
577 aComp.SetCloseBrackets( false );
578 ScTokenArray* pArr = aComp.CompileString( aString );
579 if ( pArr && pArr->MayReferenceFollow() )
581 return true;
586 else
588 return true;
594 return false;
597 //------------------------------------------------------------------
599 void ScTabViewShell::ExecuteInputDirect()
601 if ( !IsRefInputMode() )
603 ScModule* pScMod = SC_MOD();
604 if ( pScMod )
606 pScMod->InputEnterHandler();
611 //------------------------------------------------------------------
613 void ScTabViewShell::UpdateInputHandler( BOOL bForce /* = FALSE */, BOOL bStopEditing /* = TRUE */ )
615 ScInputHandler* pHdl = pInputHandler ? pInputHandler : SC_MOD()->GetInputHdl();
617 if ( pHdl )
619 String aString;
620 const EditTextObject* pObject = NULL;
621 ScViewData* pViewData = GetViewData();
622 ScDocument* pDoc = pViewData->GetDocument();
623 CellType eType;
624 SCCOL nPosX = pViewData->GetCurX();
625 SCROW nPosY = pViewData->GetCurY();
626 SCTAB nTab = pViewData->GetTabNo();
627 SCTAB nStartTab = 0;
628 SCTAB nEndTab = 0;
629 SCCOL nStartCol = 0;
630 SCROW nStartRow = 0;
631 SCCOL nEndCol = 0;
632 SCROW nEndRow = 0;
634 pViewData->GetSimpleArea( nStartCol, nStartRow, nStartTab,
635 nEndCol, nEndRow, nEndTab );
637 PutInOrder( nStartCol, nEndCol );
638 PutInOrder( nStartRow, nEndRow );
639 PutInOrder( nStartTab, nEndTab );
641 BOOL bHideFormula = FALSE;
642 BOOL bHideAll = FALSE;
644 if (pDoc->IsTabProtected(nTab))
646 const ScProtectionAttr* pProt = (const ScProtectionAttr*)
647 pDoc->GetAttr( nPosX,nPosY,nTab,
648 ATTR_PROTECTION);
649 bHideFormula = pProt->GetHideFormula();
650 bHideAll = pProt->GetHideCell();
653 if (!bHideAll)
655 pDoc->GetCellType( nPosX, nPosY, nTab, eType );
656 if (eType == CELLTYPE_FORMULA)
658 if (!bHideFormula)
659 pDoc->GetFormula( nPosX, nPosY, nTab, aString );
661 else if (eType == CELLTYPE_EDIT)
663 ScBaseCell* pCell;
664 pDoc->GetCell( nPosX, nPosY, nTab, pCell );
665 ((ScEditCell*)pCell)->GetData( pObject );
667 else
669 pDoc->GetInputString( nPosX, nPosY, nTab, aString );
670 if (eType == CELLTYPE_STRING)
672 // Bei Bedarf ein ' vorneweg, damit der String nicht ungewollt
673 // als Zahl interpretiert wird, und um dem Benutzer zu zeigen,
674 // dass es ein String ist (#35060#).
675 //! Auch bei Zahlformat "Text"? -> dann beim Editieren wegnehmen
677 SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
678 sal_uInt32 nNumFmt;
679 pDoc->GetNumberFormat( nPosX, nPosY, nTab, nNumFmt );
680 double fDummy;
681 if ( pFormatter->IsNumberFormat(aString, nNumFmt, fDummy) )
682 aString.Insert('\'',0);
687 ScInputHdlState aState( ScAddress( nPosX, nPosY, nTab ),
688 ScAddress( nStartCol, nStartRow, nTab ),
689 ScAddress( nEndCol, nEndRow, nTab ),
690 aString,
691 pObject );
693 // if using the view's local input handler, this view can always be set
694 // as current view inside NotifyChange.
695 ScTabViewShell* pSourceSh = pInputHandler ? this : NULL;
697 pHdl->NotifyChange( &aState, bForce, pSourceSh, bStopEditing );
700 SfxBindings& rBindings = GetViewFrame()->GetBindings();
701 rBindings.Invalidate( SID_STATUS_SUM ); // immer zusammen mit Eingabezeile
702 rBindings.Invalidate( SID_ATTR_SIZE );
703 rBindings.Invalidate( SID_TABLE_CELL );
706 void ScTabViewShell::UpdateInputHandlerCellAdjust( SvxCellHorJustify eJust )
708 if( ScInputHandler* pHdl = pInputHandler ? pInputHandler : SC_MOD()->GetInputHdl() )
709 pHdl->UpdateCellAdjust( eJust );
712 //------------------------------------------------------------------
714 void __EXPORT ScTabViewShell::ExecuteSave( SfxRequest& rReq )
716 // nur SID_SAVEDOC / SID_SAVEASDOC
718 // Eingabe auf jeden Fall abschliessen, auch wenn eine Formel bearbeitet wird
719 SC_MOD()->InputEnterHandler();
721 if ( GetViewData()->GetDocShell()->IsDocShared() )
723 GetViewData()->GetDocShell()->SetDocumentModified();
726 // ansonsten normal weiter
727 GetViewData()->GetDocShell()->ExecuteSlot( rReq );
730 void __EXPORT ScTabViewShell::GetSaveState( SfxItemSet& rSet )
732 SfxShell* pDocSh = GetViewData()->GetDocShell();
734 SfxWhichIter aIter(rSet);
735 USHORT nWhich = aIter.FirstWhich();
736 while( nWhich )
738 if ( nWhich != SID_SAVEDOC || !GetViewData()->GetDocShell()->IsDocShared() )
740 // get state from DocShell
741 pDocSh->GetSlotState( nWhich, NULL, &rSet );
743 nWhich = aIter.NextWhich();
747 //------------------------------------------------------------------
749 void ScTabViewShell::ExecuteUndo(SfxRequest& rReq)
751 SfxShell* pSh = GetViewData()->GetDispatcher().GetShell(0);
752 SfxUndoManager* pUndoManager = pSh->GetUndoManager();
754 const SfxItemSet* pReqArgs = rReq.GetArgs();
755 ScDocShell* pDocSh = GetViewData()->GetDocShell();
757 USHORT nSlot = rReq.GetSlot();
758 switch ( nSlot )
760 case SID_UNDO:
761 case SID_REDO:
762 if ( pUndoManager )
764 BOOL bIsUndo = ( nSlot == SID_UNDO );
766 USHORT nCount = 1;
767 const SfxPoolItem* pItem;
768 if ( pReqArgs && pReqArgs->GetItemState( nSlot, TRUE, &pItem ) == SFX_ITEM_SET )
769 nCount = ((const SfxUInt16Item*)pItem)->GetValue();
771 // lock paint for more than one cell undo action (not for editing within a cell)
772 BOOL bLockPaint = ( nCount > 1 && pUndoManager == GetUndoManager() );
773 if ( bLockPaint )
774 pDocSh->LockPaint();
776 for (USHORT i=0; i<nCount; i++)
778 if ( bIsUndo )
779 pUndoManager->Undo(0);
780 else
781 pUndoManager->Redo(0);
784 if ( bLockPaint )
785 pDocSh->UnlockPaint();
787 GetViewFrame()->GetBindings().InvalidateAll(sal_False);
789 break;
790 // default:
791 // GetViewFrame()->ExecuteSlot( rReq );
795 void ScTabViewShell::GetUndoState(SfxItemSet &rSet)
797 SfxShell* pSh = GetViewData()->GetDispatcher().GetShell(0);
798 SfxUndoManager* pUndoManager = pSh->GetUndoManager();
800 SfxWhichIter aIter(rSet);
801 USHORT nWhich = aIter.FirstWhich();
802 while ( nWhich )
804 switch (nWhich)
806 case SID_GETUNDOSTRINGS:
807 case SID_GETREDOSTRINGS:
809 SfxStringListItem aStrLst( nWhich );
810 if ( pUndoManager )
812 List* pList = aStrLst.GetList();
813 BOOL bIsUndo = ( nWhich == SID_GETUNDOSTRINGS );
814 USHORT nCount = bIsUndo ? pUndoManager->GetUndoActionCount() : pUndoManager->GetRedoActionCount();
815 for (USHORT i=0; i<nCount; i++)
816 pList->Insert( new String( bIsUndo ? pUndoManager->GetUndoActionComment(i) :
817 pUndoManager->GetRedoActionComment(i) ),
818 LIST_APPEND );
820 rSet.Put( aStrLst );
822 break;
823 default:
824 // get state from sfx view frame
825 GetViewFrame()->GetSlotState( nWhich, NULL, &rSet );
828 nWhich = aIter.NextWhich();
833 //------------------------------------------------------------------
835 void ScTabViewShell::ExecDrawOpt( SfxRequest& rReq )
837 ScViewOptions aViewOptions = GetViewData()->GetOptions();
838 ScGridOptions aGridOptions = aViewOptions.GetGridOptions();
840 SfxBindings& rBindings = GetViewFrame()->GetBindings();
841 const SfxItemSet* pArgs = rReq.GetArgs();
842 const SfxPoolItem* pItem;
843 USHORT nSlotId = rReq.GetSlot();
844 switch (nSlotId)
846 case SID_GRID_VISIBLE:
847 if ( pArgs && pArgs->GetItemState(nSlotId,TRUE,&pItem) == SFX_ITEM_SET )
849 aGridOptions.SetGridVisible( ((const SfxBoolItem*)pItem)->GetValue() );
850 aViewOptions.SetGridOptions(aGridOptions);
851 rBindings.Invalidate(SID_GRID_VISIBLE);
853 break;
855 case SID_GRID_USE:
856 if ( pArgs && pArgs->GetItemState(nSlotId,TRUE,&pItem) == SFX_ITEM_SET )
858 aGridOptions.SetUseGridSnap( ((const SfxBoolItem*)pItem)->GetValue() );
859 aViewOptions.SetGridOptions(aGridOptions);
860 rBindings.Invalidate(SID_GRID_USE);
862 break;
864 case SID_HELPLINES_MOVE:
865 if ( pArgs && pArgs->GetItemState(nSlotId,TRUE,&pItem) == SFX_ITEM_SET )
867 aViewOptions.SetOption( VOPT_HELPLINES, ((const SfxBoolItem*)pItem)->GetValue() );
868 rBindings.Invalidate(SID_HELPLINES_MOVE);
870 break;
873 GetViewData()->SetOptions(aViewOptions);
876 void ScTabViewShell::GetDrawOptState( SfxItemSet& rSet )
878 SfxBoolItem aBool;
880 const ScViewOptions& rViewOptions = GetViewData()->GetOptions();
881 const ScGridOptions& rGridOptions = rViewOptions.GetGridOptions();
883 aBool.SetValue(rGridOptions.GetGridVisible());
884 aBool.SetWhich( SID_GRID_VISIBLE );
885 rSet.Put( aBool );
887 aBool.SetValue(rGridOptions.GetUseGridSnap());
888 aBool.SetWhich( SID_GRID_USE );
889 rSet.Put( aBool );
891 aBool.SetValue(rViewOptions.GetOption( VOPT_HELPLINES ));
892 aBool.SetWhich( SID_HELPLINES_MOVE );
893 rSet.Put( aBool );