xref: /aoo41x/main/sc/source/ui/view/tabvwsha.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 
32 
33 // INCLUDE ---------------------------------------------------------------
34 
35 #define _ZFORLIST_DECLARE_TABLE
36 #include "scitems.hxx"
37 #include <svl/stritem.hxx>
38 #include <svl/whiter.hxx>
39 #include <svl/zformat.hxx>
40 #include <editeng/boxitem.hxx>
41 #include <svx/numinf.hxx>
42 #include <svl/srchitem.hxx>
43 #include <svx/zoomslideritem.hxx>
44 #include <sfx2/bindings.hxx>
45 #include <sfx2/viewfrm.hxx>
46 #include <sfx2/dispatch.hxx>
47 #include <sfx2/request.hxx>
48 #include <vcl/msgbox.hxx>
49 
50 #include "global.hxx"
51 #include "attrib.hxx"
52 #include "patattr.hxx"
53 #include "document.hxx"
54 #include "cell.hxx"             // Input Status Edit-Zellen
55 #include "globstr.hrc"
56 #include "scmod.hxx"
57 #include "inputhdl.hxx"
58 #include "inputwin.hxx"
59 #include "docsh.hxx"
60 #include "viewdata.hxx"
61 //CHINA001 #include "attrdlg.hxx"
62 #include "appoptio.hxx"
63 #include "sc.hrc"
64 #include "stlpool.hxx"
65 #include "tabvwsh.hxx"
66 #include "dwfunctr.hxx"
67 #include "scabstdlg.hxx" //CHINA001
68 #include "compiler.hxx"
69 
70 
71 sal_Bool ScTabViewShell::GetFunction( String& rFuncStr, sal_uInt16 nErrCode )
72 {
73 	String aStr;
74 
75 	ScSubTotalFunc eFunc = (ScSubTotalFunc) SC_MOD()->GetAppOptions().GetStatusFunc();
76     ScViewData* pViewData	= GetViewData();
77     ScMarkData& rMark		= pViewData->GetMarkData();
78     bool bIgnoreError = (rMark.IsMarked() || rMark.IsMultiMarked());
79 
80     if (bIgnoreError && (eFunc == SUBTOTAL_FUNC_CNT || eFunc == SUBTOTAL_FUNC_CNT2))
81         nErrCode = 0;
82 
83     if (nErrCode)
84     {
85         rFuncStr = ScGlobal::GetLongErrorString(nErrCode);
86         return true;
87     }
88 
89 	sal_uInt16 nGlobStrId = 0;
90 	switch (eFunc)
91 	{
92 		case SUBTOTAL_FUNC_AVE:	 nGlobStrId = STR_FUN_TEXT_AVG; break;
93 		case SUBTOTAL_FUNC_CNT:	 nGlobStrId = STR_FUN_TEXT_COUNT; break;
94 		case SUBTOTAL_FUNC_CNT2: nGlobStrId = STR_FUN_TEXT_COUNT2; break;
95 		case SUBTOTAL_FUNC_MAX:	 nGlobStrId = STR_FUN_TEXT_MAX; break;
96 		case SUBTOTAL_FUNC_MIN:	 nGlobStrId = STR_FUN_TEXT_MIN; break;
97 		case SUBTOTAL_FUNC_SUM:	 nGlobStrId = STR_FUN_TEXT_SUM; break;
98         default:
99         {
100             // added to avoid warnings
101         }
102 	}
103 	if (nGlobStrId)
104 	{
105 		ScDocument* pDoc		= pViewData->GetDocument();
106 		SCCOL		nPosX		= pViewData->GetCurX();
107 		SCROW		nPosY		= pViewData->GetCurY();
108 		SCTAB		nTab		= pViewData->GetTabNo();
109 
110 		aStr = ScGlobal::GetRscString(nGlobStrId);
111 		aStr += '=';
112 
113         ScAddress aCursor( nPosX, nPosY, nTab );
114 		double nVal;
115 		if ( pDoc->GetSelectionFunction( eFunc, aCursor, rMark, nVal ) )
116 		{
117             if ( nVal == 0.0 )
118                 aStr += '0';
119             else
120             {
121 		        //	Anzahl im Standardformat, die anderen nach Cursorposition
122                 SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
123 		        sal_uInt32 nNumFmt = 0;
124 		        if ( eFunc != SUBTOTAL_FUNC_CNT && eFunc != SUBTOTAL_FUNC_CNT2 )
125 		        {
126 			        //	Zahlformat aus Attributen oder Formel
127 			        pDoc->GetNumberFormat( nPosX, nPosY, nTab, nNumFmt );
128 			        if ( (nNumFmt % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
129 			        {
130 				        ScBaseCell* pCell;
131 				        pDoc->GetCell( nPosX, nPosY, nTab, pCell );
132 				        if (pCell && pCell->GetCellType() == CELLTYPE_FORMULA)
133                         {
134 
135 					        nNumFmt = ((ScFormulaCell*)pCell)->GetStandardFormat(*pFormatter, nNumFmt );
136                         }
137 			        }
138 		        }
139 
140 			    String aValStr;
141 			    Color* pDummy;
142 			    pFormatter->GetOutputString( nVal, nNumFmt, aValStr, &pDummy );
143 			    aStr += aValStr;
144             }
145 		}
146 
147 		rFuncStr = aStr;
148 		return sal_True;
149 	}
150 
151 	return sal_False;
152 }
153 
154 
155 
156 //	Funktionen, die je nach Selektion disabled sind
157 //	Default:
158 //		SID_DELETE,
159 //		SID_DELETE_CONTENTS,
160 //		FID_DELETE_CELL
161 //		FID_VALIDATION
162 
163 
164 void __EXPORT ScTabViewShell::GetState( SfxItemSet& rSet )
165 {
166 	ScViewData* pViewData	= GetViewData();
167 	ScDocument* pDoc		= pViewData->GetDocument();
168     ScDocShell* pDocShell   = pViewData->GetDocShell();
169 	ScMarkData& rMark		= pViewData->GetMarkData();
170 	SCCOL		nPosX		= pViewData->GetCurX();
171 	SCROW		nPosY		= pViewData->GetCurY();
172 	SCTAB		nTab		= pViewData->GetTabNo();
173 	sal_uInt16		nMyId		= 0;
174 
175 	SfxViewFrame* pThisFrame = GetViewFrame();
176     sal_Bool bOle = GetViewFrame()->GetFrame().IsInPlace();
177 
178 	SCTAB nTabCount = pDoc->GetTableCount();
179 	SCTAB nTabSelCount = rMark.GetSelectCount();
180 
181 	SfxWhichIter	aIter(rSet);
182 	sal_uInt16			nWhich = aIter.FirstWhich();
183 
184 	while ( nWhich )
185 	{
186 		switch ( nWhich )
187 		{
188 			case FID_CHG_COMMENT:
189 				{
190 					ScDocShell* pDocSh = GetViewData()->GetDocShell();
191 					ScAddress aPos( nPosX, nPosY, nTab );
192 					if ( pDocSh->IsReadOnly() || !pDocSh->GetChangeAction(aPos) || pDocSh->IsDocShared() )
193 						rSet.DisableItem( nWhich );
194 				}
195 				break;
196 
197             case SID_OPENDLG_EDIT_PRINTAREA:
198             case SID_ADD_PRINTAREA:
199             case SID_DEFINE_PRINTAREA:
200                 {
201                     if ( pDocShell && pDocShell->IsDocShared() )
202                     {
203                         rSet.DisableItem( nWhich );
204                     }
205                 }
206                 break;
207 
208 			case SID_DELETE_PRINTAREA:
209 				if ( nTabSelCount > 1 )
210 				{
211                     // #i22589# also take "Print Entire Sheet" into account here
212 					sal_Bool bHas = sal_False;
213                     for (SCTAB i=0; !bHas && i<nTabCount; i++)
214                         bHas = rMark.GetTableSelect(i) && (pDoc->GetPrintRangeCount(i) || pDoc->IsPrintEntireSheet(i));
215 					if (!bHas)
216 						rSet.DisableItem( nWhich );
217 				}
218                 else if ( !pDoc->GetPrintRangeCount( nTab ) && !pDoc->IsPrintEntireSheet( nTab ) )
219 					rSet.DisableItem( nWhich );
220                 if ( pDocShell && pDocShell->IsDocShared() )
221                 {
222                     rSet.DisableItem( nWhich );
223                 }
224 				break;
225 
226 			case SID_STATUS_PAGESTYLE:
227 			case SID_HFEDIT:
228 				GetViewData()->GetDocShell()->GetStatePageStyle( *this, rSet, nTab );
229 				break;
230 
231 			case SID_SEARCH_ITEM:
232 				rSet.Put( ScGlobal::GetSearchItem() );
233 				break;
234 
235 			case SID_SEARCH_OPTIONS:
236 				{
237 					sal_uInt16 nOptions = 0xffff;		// alles erlaubt
238 													// wenn ReadOnly, kein Ersetzen:
239 					if (GetViewData()->GetDocShell()->IsReadOnly())
240 						nOptions &= ~( SEARCH_OPTIONS_REPLACE | SEARCH_OPTIONS_REPLACE_ALL );
241 					rSet.Put( SfxUInt16Item( nWhich, nOptions ) );
242 				}
243 				break;
244 
245 			case SID_CURRENTCELL:
246 				{
247 					ScAddress aScAddress( GetViewData()->GetCurX(), GetViewData()->GetCurY(), 0 );
248 					String	aAddr;
249 					aScAddress.Format( aAddr, SCA_ABS, NULL, pDoc->GetAddressConvention() );
250 					SfxStringItem	aPosItem( SID_CURRENTCELL, aAddr );
251 
252 					rSet.Put( aPosItem );
253 				}
254 				break;
255 
256 			case SID_CURRENTTAB:
257 				//	Tabelle fuer Basic ist 1-basiert
258 				rSet.Put( SfxUInt16Item( nWhich, static_cast<sal_uInt16>(GetViewData()->GetTabNo()) + 1 ) );
259 				break;
260 
261 			case SID_CURRENTDOC:
262 				rSet.Put( SfxStringItem( nWhich, GetViewData()->GetDocShell()->GetTitle() ) );
263 				break;
264 
265 			case FID_TOGGLEINPUTLINE:
266 				{
267 					sal_uInt16 nId = ScInputWindowWrapper::GetChildWindowId();
268 
269 					if ( pThisFrame->KnowsChildWindow( nId ) )
270 					{
271 						SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
272 						rSet.Put( SfxBoolItem( nWhich, pWnd ? sal_True : sal_False ) );
273 					}
274 					else
275 						rSet.DisableItem( nWhich );
276 				}
277 				break;
278 
279 			case FID_DEL_MANUALBREAKS:
280 				if (!pDoc->HasManualBreaks(nTab))
281 					rSet.DisableItem( nWhich );
282 				break;
283 
284 			case FID_RESET_PRINTZOOM:
285 				{
286 					//	disablen, wenn schon Default eingestellt
287 
288 					String aStyleName = pDoc->GetPageStyle( nTab );
289 					ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool();
290 					SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName,
291 													SFX_STYLE_FAMILY_PAGE );
292 					DBG_ASSERT( pStyleSheet, "PageStyle not found" );
293 					if ( pStyleSheet )
294 					{
295 						SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
296 						sal_uInt16 nScale = ((const SfxUInt16Item&)
297 											rStyleSet.Get(ATTR_PAGE_SCALE)).GetValue();
298 						sal_uInt16 nPages = ((const SfxUInt16Item&)
299 											rStyleSet.Get(ATTR_PAGE_SCALETOPAGES)).GetValue();
300 						if ( nScale == 100 && nPages == 0 )
301 							rSet.DisableItem( nWhich );
302 					}
303 				}
304 				break;
305 
306 			case FID_SCALE:
307 			case SID_ATTR_ZOOM:
308 				if ( bOle )
309 					rSet.DisableItem( nWhich );
310 				else
311 				{
312 					const Fraction& rOldY = GetViewData()->GetZoomY();
313 					sal_uInt16 nZoom = (sal_uInt16)(( rOldY.GetNumerator() * 100 )
314 												/ rOldY.GetDenominator());
315 					rSet.Put( SvxZoomItem( SVX_ZOOM_PERCENT, nZoom, nWhich ) );
316 				}
317 				break;
318 
319             case SID_ATTR_ZOOMSLIDER:
320                 {
321                     if ( bOle )
322                         rSet.DisableItem( nWhich );
323                     else
324                     {
325                         const Fraction& rOldY = GetViewData()->GetZoomY();
326                         sal_uInt16 nCurrentZoom = (sal_uInt16)(( rOldY.GetNumerator() * 100 ) / rOldY.GetDenominator());
327 
328                         if( nCurrentZoom )
329                         {
330                             SvxZoomSliderItem aZoomSliderItem( nCurrentZoom, MINZOOM, MAXZOOM, SID_ATTR_ZOOMSLIDER );
331                             aZoomSliderItem.AddSnappingPoint( 100 );
332                             rSet.Put( aZoomSliderItem );
333                         }
334                     }
335                 }
336                 break;
337 
338 			case FID_TOGGLESYNTAX:
339 				rSet.Put(SfxBoolItem(nWhich, GetViewData()->IsSyntaxMode()));
340 				break;
341 
342 			case FID_TOGGLEHEADERS:
343 				rSet.Put(SfxBoolItem(nWhich, GetViewData()->IsHeaderMode()));
344 				break;
345 
346             case FID_TOGGLEFORMULA:
347                 {
348                     const ScViewOptions& rOpts = pViewData->GetOptions();
349                     sal_Bool bFormulaMode = rOpts.GetOption( VOPT_FORMULAS );
350                     rSet.Put(SfxBoolItem(nWhich, bFormulaMode ));
351                 }
352                 break;
353 
354             case FID_NORMALVIEWMODE:
355 			case FID_PAGEBREAKMODE:
356                 // always handle both slots - they exclude each other
357 				if ( bOle )
358                 {
359                     rSet.DisableItem( FID_NORMALVIEWMODE );
360                     rSet.DisableItem( FID_PAGEBREAKMODE );
361                 }
362 				else
363                 {
364                     rSet.Put(SfxBoolItem(FID_NORMALVIEWMODE, !GetViewData()->IsPagebreakMode()));
365                     rSet.Put(SfxBoolItem(FID_PAGEBREAKMODE, GetViewData()->IsPagebreakMode()));
366                 }
367 				break;
368 
369 			case FID_FUNCTION_BOX:
370 				nMyId = ScFunctionChildWindow::GetChildWindowId();
371 				rSet.Put(SfxBoolItem(FID_FUNCTION_BOX, pThisFrame->HasChildWindow(nMyId)));
372 				break;
373 
374 			case FID_PROTECT_DOC:
375                 {
376                     if ( pDocShell && pDocShell->IsDocShared() )
377                     {
378                         rSet.DisableItem( nWhich );
379                     }
380                     else
381                     {
382                         rSet.Put( SfxBoolItem( nWhich, pDoc->IsDocProtected() ) );
383                     }
384                 }
385 				break;
386 
387 			case FID_PROTECT_TABLE:
388                 {
389                     if ( pDocShell && pDocShell->IsDocShared() )
390                     {
391                         rSet.DisableItem( nWhich );
392                     }
393                     else
394                     {
395                         rSet.Put( SfxBoolItem( nWhich, pDoc->IsTabProtected( nTab ) ) );
396                     }
397                 }
398 				break;
399 
400 			case SID_AUTO_OUTLINE:
401 				{
402 					if (pDoc->GetChangeTrack()!=NULL || GetViewData()->IsMultiMarked())
403 					{
404 						rSet.DisableItem( nWhich );
405 					}
406 				}
407 				break;
408 
409 			case SID_OUTLINE_DELETEALL:
410 				{
411 					SCTAB nOlTab = GetViewData()->GetTabNo();
412 					ScOutlineTable* pOlTable = pDoc->GetOutlineTable( nOlTab );
413 					if (pOlTable == NULL)
414 						rSet.DisableItem( nWhich );
415 				}
416 				break;
417 
418 			case SID_WINDOW_SPLIT:
419 				rSet.Put(SfxBoolItem(nWhich,
420 							pViewData->GetHSplitMode() == SC_SPLIT_NORMAL ||
421 							pViewData->GetVSplitMode() == SC_SPLIT_NORMAL ));
422 				break;
423 
424 			case SID_WINDOW_FIX:
425 				rSet.Put(SfxBoolItem(nWhich,
426 							pViewData->GetHSplitMode() == SC_SPLIT_FIX ||
427 							pViewData->GetVSplitMode() == SC_SPLIT_FIX ));
428 				break;
429 
430 			case FID_CHG_SHOW:
431 				{
432                     if ( pDoc->GetChangeTrack() == NULL || ( pDocShell && pDocShell->IsDocShared() ) )
433                         rSet.DisableItem( nWhich );
434 				}
435 				break;
436 			case FID_CHG_ACCEPT:
437 				{
438 					rSet.Put(SfxBoolItem(FID_CHG_ACCEPT,
439 							pThisFrame->HasChildWindow(FID_CHG_ACCEPT)));
440 					if(pDoc->GetChangeTrack()==NULL)
441 					{
442 						if ( !pThisFrame->HasChildWindow(FID_CHG_ACCEPT) )
443 						{
444 							rSet.DisableItem( nWhich);
445 						}
446 					}
447                     if ( pDocShell && pDocShell->IsDocShared() )
448                     {
449                         rSet.DisableItem( nWhich );
450                     }
451 				}
452 				break;
453 
454 			case SID_FORMATPAGE:
455 				//!	bei geschuetzten Tabellen ???
456                 if ( pDocShell && ( pDocShell->IsReadOnly() || pDocShell->IsDocShared() ) )
457 					rSet.DisableItem( nWhich );
458 				break;
459 
460 			case SID_PRINTPREVIEW:
461 				// #58924# Toggle-Slot braucht einen State
462 				rSet.Put( SfxBoolItem( nWhich, sal_False ) );
463 				break;
464 
465 			case SID_READONLY_MODE:
466 				rSet.Put( SfxBoolItem( nWhich, GetViewData()->GetDocShell()->IsReadOnly() ) );
467 				break;
468 
469             case FID_TAB_DESELECTALL:
470                 if ( nTabSelCount == 1 )
471                     rSet.DisableItem( nWhich );     // enabled only if several sheets are selected
472                 break;
473 
474 		} // switch ( nWitch )
475 		nWhich = aIter.NextWhich();
476 	} // while ( nWitch )
477 }
478 
479 //------------------------------------------------------------------
480 void ScTabViewShell::ExecuteCellFormatDlg( SfxRequest& rReq, sal_uInt16 nTabPage )
481 {
482 	//CHINA001 ScAttrDlg*				pDlg	= NULL;
483 	SfxAbstractTabDialog * pDlg	= NULL; //CHINA001
484 	ScDocument* 			pDoc	= GetViewData()->GetDocument();
485 
486 	SvxBoxItem				aLineOuter( ATTR_BORDER );
487 	SvxBoxInfoItem			aLineInner( ATTR_BORDER_INNER );
488 
489 	SvxNumberInfoItem*		pNumberInfoItem = NULL;
490 	const ScPatternAttr*	pOldAttrs		= GetSelectionPattern();
491 	SfxItemSet* 			pOldSet 		= new SfxItemSet(
492 													pOldAttrs->GetItemSet() );
493 
494 
495 	// Umrandungs-Items holen und in den Set packen:
496 	GetSelectionFrame( aLineOuter, aLineInner );
497 	pOldSet->Put( aLineOuter );
498 	pOldSet->Put( aLineInner );
499 
500 	// NumberFormat Value aus Value und Language erzeugen und eintueten
501 	pOldSet->Put( SfxUInt32Item( ATTR_VALUE_FORMAT,
502 		pOldAttrs->GetNumberFormat( pDoc->GetFormatTable() ) ) );
503 
504 	MakeNumberInfoItem( pDoc, GetViewData(), &pNumberInfoItem );
505 
506 	pOldSet->MergeRange( SID_ATTR_NUMBERFORMAT_INFO, SID_ATTR_NUMBERFORMAT_INFO );
507 	pOldSet->Put(*pNumberInfoItem );
508 
509 	bInFormatDialog = sal_True;
510 	//CHINA001 pDlg = new ScAttrDlg( GetViewFrame(), GetDialogParent(), pOldSet );
511 	ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
512 	DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
513 
514 	pDlg = pFact->CreateScAttrDlg( GetViewFrame(), GetDialogParent(), pOldSet, RID_SCDLG_ATTR);
515 	DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
516 	if ( nTabPage != 0xffff )
517 		pDlg->SetCurPageId( nTabPage );
518 	short nResult = pDlg->Execute();
519 	bInFormatDialog = sal_False;
520 
521 	if ( nResult == RET_OK )
522 	{
523 		const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
524 
525 		const SfxPoolItem* pItem=NULL;
526 		if(pOutSet->GetItemState(SID_ATTR_NUMBERFORMAT_INFO,sal_True,&pItem)==SFX_ITEM_SET)
527 		{
528 
529 			UpdateNumberFormatter( pDoc,(const SvxNumberInfoItem&)*pItem);
530 		}
531 
532 		ApplyAttributes( pOutSet, pOldSet );
533 
534 		rReq.Done( *pOutSet );
535 	}
536 	delete pOldSet;
537 	delete pNumberInfoItem;
538 	delete pDlg;
539 }
540 
541 //------------------------------------------------------------------
542 
543 bool ScTabViewShell::IsRefInputMode() const
544 {
545     ScModule* pScMod = SC_MOD();
546     if ( pScMod )
547     {
548         if( pScMod->IsRefDialogOpen() )
549             return pScMod->IsFormulaMode();
550         if( pScMod->IsFormulaMode() )
551         {
552             ScInputHandler* pHdl = pScMod->GetInputHdl();
553             if ( pHdl )
554             {
555                 String aString = pHdl->GetEditString();
556                 if ( !pHdl->GetSelIsRef() && aString.Len() > 1 &&
557                      ( aString.GetChar(0) == '+' || aString.GetChar(0) == '-' ) )
558                 {
559                     const ScViewData* pViewData = GetViewData();
560                     if ( pViewData )
561                     {
562                         ScDocument* pDoc = pViewData->GetDocument();
563                         if ( pDoc )
564                         {
565                             const ScAddress aPos( pViewData->GetCurPos() );
566                             ScCompiler aComp( pDoc, aPos );
567                             aComp.SetGrammar(pDoc->GetGrammar());
568                             aComp.SetCloseBrackets( false );
569                             ScTokenArray* pArr = aComp.CompileString( aString );
570                             if ( pArr && pArr->MayReferenceFollow() )
571                             {
572                                 return true;
573                             }
574                         }
575                     }
576                 }
577                 else
578                 {
579                     return true;
580                 }
581             }
582         }
583     }
584 
585     return false;
586 }
587 
588 //------------------------------------------------------------------
589 
590 void ScTabViewShell::ExecuteInputDirect()
591 {
592     if ( !IsRefInputMode() )
593     {
594         ScModule* pScMod = SC_MOD();
595         if ( pScMod )
596         {
597             pScMod->InputEnterHandler();
598         }
599     }
600 }
601 
602 //------------------------------------------------------------------
603 
604 void ScTabViewShell::UpdateInputHandler( sal_Bool bForce /* = sal_False */, sal_Bool bStopEditing /* = sal_True */ )
605 {
606 	ScInputHandler* pHdl = pInputHandler ? pInputHandler : SC_MOD()->GetInputHdl();
607 
608 	if ( pHdl )
609 	{
610 		String					aString;
611 		const EditTextObject*	pObject 	= NULL;
612 		ScViewData*				pViewData	= GetViewData();
613 		ScDocument*				pDoc		= pViewData->GetDocument();
614 		CellType				eType;
615 		SCCOL					nPosX		= pViewData->GetCurX();
616 		SCROW					nPosY		= pViewData->GetCurY();
617 		SCTAB					nTab		= pViewData->GetTabNo();
618 		SCTAB					nStartTab	= 0;
619 		SCTAB					nEndTab 	= 0;
620 		SCCOL					nStartCol	= 0;
621 		SCROW					nStartRow	= 0;
622 		SCCOL					nEndCol 	= 0;
623 		SCROW					nEndRow 	= 0;
624 
625 		pViewData->GetSimpleArea( nStartCol, nStartRow, nStartTab,
626 								  nEndCol,   nEndRow,   nEndTab );
627 
628 		PutInOrder( nStartCol, nEndCol );
629 		PutInOrder( nStartRow, nEndRow );
630 		PutInOrder( nStartTab, nEndTab );
631 
632 		sal_Bool bHideFormula = sal_False;
633 		sal_Bool bHideAll	  = sal_False;
634 
635 		if (pDoc->IsTabProtected(nTab))
636 		{
637 			const ScProtectionAttr* pProt = (const ScProtectionAttr*)
638 											pDoc->GetAttr( nPosX,nPosY,nTab,
639 														   ATTR_PROTECTION);
640 			bHideFormula = pProt->GetHideFormula();
641 			bHideAll	 = pProt->GetHideCell();
642 		}
643 
644 		if (!bHideAll)
645 		{
646 			pDoc->GetCellType( nPosX, nPosY, nTab, eType );
647 			if (eType == CELLTYPE_FORMULA)
648 			{
649 				if (!bHideFormula)
650 					pDoc->GetFormula( nPosX, nPosY, nTab, aString );
651 			}
652 			else if (eType == CELLTYPE_EDIT)
653 			{
654 				ScBaseCell* pCell;
655 				pDoc->GetCell( nPosX, nPosY, nTab, pCell );
656 				((ScEditCell*)pCell)->GetData( pObject );
657 			}
658 			else
659 			{
660 				pDoc->GetInputString( nPosX, nPosY, nTab, aString );
661 				if (eType == CELLTYPE_STRING)
662 				{
663 					//	Bei Bedarf ein ' vorneweg, damit der String nicht ungewollt
664 					//	als Zahl interpretiert wird, und um dem Benutzer zu zeigen,
665 					//	dass es ein String ist (#35060#).
666 					//!	Auch bei Zahlformat "Text"? -> dann beim Editieren wegnehmen
667 
668 					SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
669 					sal_uInt32 nNumFmt;
670 					pDoc->GetNumberFormat( nPosX, nPosY, nTab, nNumFmt );
671 					double fDummy;
672 					if ( pFormatter->IsNumberFormat(aString, nNumFmt, fDummy) )
673 						aString.Insert('\'',0);
674 				}
675 			}
676 		}
677 
678 		ScInputHdlState	aState( ScAddress( nPosX,	  nPosY, 	 nTab ),
679 								ScAddress( nStartCol, nStartRow, nTab ),
680 								ScAddress( nEndCol,	  nEndRow,   nTab ),
681 								aString,
682 								pObject );
683 
684 		//	if using the view's local input handler, this view can always be set
685 		//	as current view inside NotifyChange.
686 		ScTabViewShell* pSourceSh = pInputHandler ? this : NULL;
687 
688 		pHdl->NotifyChange( &aState, bForce, pSourceSh, bStopEditing );
689 	}
690 
691 	SfxBindings& rBindings = GetViewFrame()->GetBindings();
692 	rBindings.Invalidate( SID_STATUS_SUM );			// immer zusammen mit Eingabezeile
693 	rBindings.Invalidate( SID_ATTR_SIZE );
694     rBindings.Invalidate( SID_TABLE_CELL );
695 }
696 
697 void ScTabViewShell::UpdateInputHandlerCellAdjust( SvxCellHorJustify eJust )
698 {
699     if( ScInputHandler* pHdl = pInputHandler ? pInputHandler : SC_MOD()->GetInputHdl() )
700         pHdl->UpdateCellAdjust( eJust );
701 }
702 
703 //------------------------------------------------------------------
704 
705 void __EXPORT ScTabViewShell::ExecuteSave( SfxRequest& rReq )
706 {
707 	//	nur SID_SAVEDOC / SID_SAVEASDOC
708 
709 	// Eingabe auf jeden Fall abschliessen, auch wenn eine Formel bearbeitet wird
710 	SC_MOD()->InputEnterHandler();
711 
712     if ( GetViewData()->GetDocShell()->IsDocShared() )
713     {
714         GetViewData()->GetDocShell()->SetDocumentModified();
715     }
716 
717 	// ansonsten normal weiter
718 	GetViewData()->GetDocShell()->ExecuteSlot( rReq );
719 }
720 
721 void __EXPORT ScTabViewShell::GetSaveState( SfxItemSet& rSet )
722 {
723 	SfxShell* pDocSh = GetViewData()->GetDocShell();
724 
725 	SfxWhichIter aIter(rSet);
726 	sal_uInt16 nWhich = aIter.FirstWhich();
727 	while( nWhich )
728 	{
729         if ( nWhich != SID_SAVEDOC || !GetViewData()->GetDocShell()->IsDocShared() )
730         {
731             // get state from DocShell
732             pDocSh->GetSlotState( nWhich, NULL, &rSet );
733         }
734 		nWhich = aIter.NextWhich();
735 	}
736 }
737 
738 //------------------------------------------------------------------
739 
740 void ScTabViewShell::ExecDrawOpt( SfxRequest& rReq )
741 {
742 	ScViewOptions aViewOptions = GetViewData()->GetOptions();
743 	ScGridOptions aGridOptions = aViewOptions.GetGridOptions();
744 
745 	SfxBindings& rBindings = GetViewFrame()->GetBindings();
746 	const SfxItemSet* pArgs = rReq.GetArgs();
747 	const SfxPoolItem* pItem;
748 	sal_uInt16 nSlotId = rReq.GetSlot();
749 	switch (nSlotId)
750 	{
751 		case SID_GRID_VISIBLE:
752 			if ( pArgs && pArgs->GetItemState(nSlotId,sal_True,&pItem) == SFX_ITEM_SET )
753 			{
754 				aGridOptions.SetGridVisible( ((const SfxBoolItem*)pItem)->GetValue() );
755 				aViewOptions.SetGridOptions(aGridOptions);
756 				rBindings.Invalidate(SID_GRID_VISIBLE);
757 			}
758 			break;
759 
760 		case SID_GRID_USE:
761 			if ( pArgs && pArgs->GetItemState(nSlotId,sal_True,&pItem) == SFX_ITEM_SET )
762 			{
763 				aGridOptions.SetUseGridSnap( ((const SfxBoolItem*)pItem)->GetValue() );
764 				aViewOptions.SetGridOptions(aGridOptions);
765 				rBindings.Invalidate(SID_GRID_USE);
766 			}
767 			break;
768 
769 		case SID_HELPLINES_MOVE:
770 			if ( pArgs && pArgs->GetItemState(nSlotId,sal_True,&pItem) == SFX_ITEM_SET )
771 			{
772 				aViewOptions.SetOption( VOPT_HELPLINES, ((const SfxBoolItem*)pItem)->GetValue() );
773 				rBindings.Invalidate(SID_HELPLINES_MOVE);
774 			}
775 			break;
776 	}
777 
778 	GetViewData()->SetOptions(aViewOptions);
779 }
780 
781 void ScTabViewShell::GetDrawOptState( SfxItemSet& rSet )
782 {
783 	SfxBoolItem aBool;
784 
785 	const ScViewOptions& rViewOptions = GetViewData()->GetOptions();
786 	const ScGridOptions& rGridOptions = rViewOptions.GetGridOptions();
787 
788 	aBool.SetValue(rGridOptions.GetGridVisible());
789 	aBool.SetWhich( SID_GRID_VISIBLE );
790 	rSet.Put( aBool );
791 
792 	aBool.SetValue(rGridOptions.GetUseGridSnap());
793 	aBool.SetWhich( SID_GRID_USE );
794 	rSet.Put( aBool );
795 
796 	aBool.SetValue(rViewOptions.GetOption( VOPT_HELPLINES ));
797 	aBool.SetWhich( SID_HELPLINES_MOVE );
798 	rSet.Put( aBool );
799 }
800 
801 
802 
803 
804