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