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