GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / sc / source / ui / view / tabvwsh3.cxx
blob5cc58dc4b7cc8250ac061d61f95b584ea9a81243
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "scitems.hxx"
21 #include <editeng/eeitem.hxx>
23 #include <sfx2/app.hxx>
24 #include <sfx2/bindings.hxx>
25 #include <sfx2/dispatch.hxx>
26 #include <sfx2/passwd.hxx>
27 #include <sfx2/request.hxx>
28 #include <svl/ptitem.hxx>
29 #include <svl/stritem.hxx>
30 #include <tools/urlobj.hxx>
31 #include <sfx2/objface.hxx>
32 #include <vcl/msgbox.hxx>
33 #include <vcl/vclenum.hxx>
35 #include "globstr.hrc"
36 #include "scmod.hxx"
37 #include "appoptio.hxx"
38 #include "tabvwsh.hxx"
39 #include "document.hxx"
40 #include "sc.hrc"
41 #include "inputwin.hxx"
42 #include "scresid.hxx"
43 #include "printfun.hxx"
44 #include "docsh.hxx"
45 #include "rangelst.hxx"
46 #include "prevwsh.hxx"
47 #include "rangeutl.hxx"
48 #include "reffact.hxx"
49 #include "uiitems.hxx"
50 #include "formulacell.hxx"
51 #include "inputhdl.hxx"
52 #include "autoform.hxx"
53 #include "autofmt.hxx"
54 #include "dwfunctr.hxx"
55 #include "shtabdlg.hxx"
56 #include "tabprotection.hxx"
57 #include "protectiondlg.hxx"
58 #include "markdata.hxx"
60 #include <svl/ilstitem.hxx>
61 #include <vector>
63 #include <svx/zoomslideritem.hxx>
64 #include <svx/svxdlg.hxx>
65 #include <svx/dialogs.hrc>
66 #include <comphelper/string.hxx>
67 #include "scabstdlg.hxx"
69 #include <memory>
71 using ::std::auto_ptr;
73 //------------------------------------------------------------------
75 /** Try to parse the given range using Calc-style syntax first, then
76 Excel-style if that fails. */
77 static sal_uInt16 lcl_ParseRange(ScRange& rScRange, const OUString& aAddress, ScDocument* pDoc, sal_uInt16 /* nSlot */)
79 sal_uInt16 nResult = rScRange.Parse(aAddress, pDoc);
80 if ( (nResult & SCA_VALID) )
81 return nResult;
83 return rScRange.Parse(aAddress, pDoc, ScAddress::Details(formula::FormulaGrammar::CONV_XL_A1, 0, 0));
86 /** Try to parse the given address using Calc-style syntax first, then
87 Excel-style if that fails. */
88 static sal_uInt16 lcl_ParseAddress(ScAddress& rScAddress, const OUString& aAddress, ScDocument* pDoc, sal_uInt16 /* nSlot */)
90 sal_uInt16 nResult = rScAddress.Parse(aAddress, pDoc);
91 if ( (nResult & SCA_VALID) )
92 return nResult;
94 return rScAddress.Parse(aAddress, pDoc, ScAddress::Details(formula::FormulaGrammar::CONV_XL_A1, 0, 0));
97 void ScTabViewShell::Execute( SfxRequest& rReq )
99 SfxViewFrame* pThisFrame = GetViewFrame();
100 SfxBindings& rBindings = pThisFrame->GetBindings();
101 ScModule* pScMod = SC_MOD();
102 const SfxItemSet* pReqArgs = rReq.GetArgs();
103 sal_uInt16 nSlot = rReq.GetSlot();
105 if (nSlot != SID_CURRENTCELL) // der kommt beim MouseButtonUp
106 HideListBox(); // Autofilter-DropDown-Listbox
108 switch ( nSlot )
110 case FID_INSERT_FILE:
112 const SfxPoolItem* pItem;
113 if ( pReqArgs &&
114 pReqArgs->GetItemState(FID_INSERT_FILE,sal_True,&pItem) == SFX_ITEM_SET )
116 OUString aFileName = ((const SfxStringItem*)pItem)->GetValue();
118 // Einfuege-Position
120 Point aInsertPos;
121 if ( pReqArgs->GetItemState(FN_PARAM_1,sal_True,&pItem) == SFX_ITEM_SET )
122 aInsertPos = ((const SfxPointItem*)pItem)->GetValue();
123 else
124 aInsertPos = GetInsertPos();
126 // als Link?
128 sal_Bool bAsLink = false;
129 if ( pReqArgs->GetItemState(FN_PARAM_2,sal_True,&pItem) == SFX_ITEM_SET )
130 bAsLink = ((const SfxBoolItem*)pItem)->GetValue();
132 // ausfuehren
134 PasteFile( aInsertPos, aFileName, bAsLink );
137 break;
139 case SID_OPENDLG_EDIT_PRINTAREA:
141 sal_uInt16 nId = ScPrintAreasDlgWrapper::GetChildWindowId();
142 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
144 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
146 break;
148 case SID_CHANGE_PRINTAREA:
150 if ( pReqArgs ) // OK aus Dialog
152 OUString aPrintStr;
153 OUString aRowStr;
154 OUString aColStr;
155 sal_Bool bEntire = false;
156 const SfxPoolItem* pItem;
157 if ( pReqArgs->GetItemState( SID_CHANGE_PRINTAREA, sal_True, &pItem ) == SFX_ITEM_SET )
158 aPrintStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
159 if ( pReqArgs->GetItemState( FN_PARAM_2, sal_True, &pItem ) == SFX_ITEM_SET )
160 aRowStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
161 if ( pReqArgs->GetItemState( FN_PARAM_3, sal_True, &pItem ) == SFX_ITEM_SET )
162 aColStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
163 if ( pReqArgs->GetItemState( FN_PARAM_4, sal_True, &pItem ) == SFX_ITEM_SET )
164 bEntire = static_cast<const SfxBoolItem*>(pItem)->GetValue();
166 SetPrintRanges( bEntire, &aPrintStr, &aColStr, &aRowStr, false );
168 rReq.Done();
171 break;
173 case SID_ADD_PRINTAREA:
174 case SID_DEFINE_PRINTAREA: // Menue oder Basic
176 sal_Bool bAdd = ( nSlot == SID_ADD_PRINTAREA );
177 if ( pReqArgs )
179 OUString aPrintStr;
180 const SfxPoolItem* pItem;
181 if ( pReqArgs->GetItemState( SID_DEFINE_PRINTAREA, sal_True, &pItem ) == SFX_ITEM_SET )
182 aPrintStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
183 SetPrintRanges( false, &aPrintStr, NULL, NULL, bAdd );
185 else
187 SetPrintRanges( false, NULL, NULL, NULL, bAdd ); // aus Selektion
188 rReq.Done();
191 break;
193 case SID_DELETE_PRINTAREA:
195 OUString aEmpty;
196 SetPrintRanges( false, &aEmpty, NULL, NULL, false ); // Druckbereich loeschen
197 rReq.Done();
199 break;
201 case FID_DEL_MANUALBREAKS:
202 RemoveManualBreaks();
203 rReq.Done();
204 break;
206 case FID_ADJUST_PRINTZOOM:
207 AdjustPrintZoom();
208 rReq.Done();
209 break;
211 case FID_RESET_PRINTZOOM:
212 SetPrintZoom( 100, 0 ); // 100%, nicht auf Seiten
213 rReq.Done();
214 break;
216 case SID_FORMATPAGE:
217 case SID_STATUS_PAGESTYLE:
218 case SID_HFEDIT:
219 GetViewData()->GetDocShell()->
220 ExecutePageStyle( *this, rReq, GetViewData()->GetTabNo() );
221 break;
223 case SID_JUMPTOMARK:
224 case SID_CURRENTCELL:
225 if ( pReqArgs )
227 OUString aAddress;
228 const SfxPoolItem* pItem;
229 if ( pReqArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET )
230 aAddress = ((const SfxStringItem*)pItem)->GetValue();
231 else if ( nSlot == SID_JUMPTOMARK && pReqArgs->GetItemState(
232 SID_JUMPTOMARK, sal_True, &pItem ) == SFX_ITEM_SET )
233 aAddress = ((const SfxStringItem*)pItem)->GetValue();
235 // #i14927# SID_CURRENTCELL with a single cell must unmark if FN_PARAM_1
236 // isn't set (for recorded macros, because IsAPI is no longer available).
237 // ScGridWindow::MouseButtonUp no longer executes the slot for a single
238 // cell if there is a multi selection.
239 sal_Bool bUnmark = ( nSlot == SID_CURRENTCELL );
240 if ( pReqArgs->GetItemState( FN_PARAM_1, sal_True, &pItem ) == SFX_ITEM_SET )
241 bUnmark = ((const SfxBoolItem*)pItem)->GetValue();
243 bool bAlignToCursor = true;
244 if (pReqArgs->GetItemState(FN_PARAM_2, true, &pItem) == SFX_ITEM_SET)
245 bAlignToCursor = static_cast<const SfxBoolItem*>(pItem)->GetValue();
247 if ( nSlot == SID_JUMPTOMARK )
249 // URL has to be decoded for escaped characters (%20)
250 aAddress = INetURLObject::decode( aAddress, INET_HEX_ESCAPE,
251 INetURLObject::DECODE_WITH_CHARSET,
252 RTL_TEXTENCODING_UTF8 );
255 sal_Bool bFound = false;
256 ScViewData* pViewData = GetViewData();
257 ScDocument* pDoc = pViewData->GetDocument();
258 ScMarkData& rMark = pViewData->GetMarkData();
259 ScRange aScRange;
260 ScAddress aScAddress;
261 sal_uInt16 nResult = lcl_ParseRange(aScRange, aAddress, pDoc, nSlot);
262 SCTAB nTab = pViewData->GetTabNo();
263 sal_Bool bMark = sal_True;
265 // Is this a range ?
266 if( nResult & SCA_VALID )
268 if ( nResult & SCA_TAB_3D )
270 if( aScRange.aStart.Tab() != nTab )
271 SetTabNo( nTab = aScRange.aStart.Tab() );
273 else
275 aScRange.aStart.SetTab( nTab );
276 aScRange.aEnd.SetTab( nTab );
279 // Is this a cell ?
280 else if ( (nResult = lcl_ParseAddress(aScAddress, aAddress, pDoc, nSlot)) & SCA_VALID )
282 if ( nResult & SCA_TAB_3D )
284 if( aScAddress.Tab() != nTab )
285 SetTabNo( nTab = aScAddress.Tab() );
287 else
288 aScAddress.SetTab( nTab );
290 aScRange = ScRange( aScAddress, aScAddress );
291 // Zellen sollen nicht markiert werden
292 bMark = false;
294 // Ist es benahmster Bereich (erst Namen dann DBBereiche) ?
295 else
297 ScRangeUtil aRangeUtil;
298 formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
299 if( aRangeUtil.MakeRangeFromName( aAddress, pDoc, nTab, aScRange, RUTL_NAMES, eConv ) ||
300 aRangeUtil.MakeRangeFromName( aAddress, pDoc, nTab, aScRange, RUTL_DBASE, eConv ) )
302 nResult |= SCA_VALID;
303 if( aScRange.aStart.Tab() != nTab )
304 SetTabNo( nTab = aScRange.aStart.Tab() );
308 if ( !(nResult & SCA_VALID) && comphelper::string::isdigitAsciiString(aAddress) )
310 sal_Int32 nNumeric = aAddress.toInt32();
311 if ( nNumeric > 0 && nNumeric <= MAXROW+1 )
313 // 1-basierte Zeilennummer
315 aScAddress.SetRow( (SCROW)(nNumeric - 1) );
316 aScAddress.SetCol( pViewData->GetCurX() );
317 aScAddress.SetTab( nTab );
318 aScRange = ScRange( aScAddress, aScAddress );
319 bMark = false;
320 nResult = SCA_VALID;
324 if ( !ValidRow(aScRange.aStart.Row()) || !ValidRow(aScRange.aEnd.Row()) )
325 nResult = 0;
327 // wir haben was gefunden
328 if( nResult & SCA_VALID )
330 bFound = sal_True;
331 SCCOL nCol = aScRange.aStart.Col();
332 SCROW nRow = aScRange.aStart.Row();
333 sal_Bool bNothing = ( pViewData->GetCurX()==nCol && pViewData->GetCurY()==nRow );
335 // markieren
336 if( bMark )
338 if (rMark.IsMarked()) // ist derselbe Bereich schon markiert?
340 ScRange aOldMark;
341 rMark.GetMarkArea( aOldMark );
342 aOldMark.Justify();
343 ScRange aCurrent = aScRange;
344 aCurrent.Justify();
345 bNothing = ( aCurrent == aOldMark );
347 else
348 bNothing = false;
350 if (!bNothing)
351 MarkRange( aScRange, false ); // Cursor kommt hinterher...
353 else
355 // remove old selection, unless bUnmark argument is sal_False (from navigator)
356 if( bUnmark )
358 MoveCursorAbs( nCol, nRow,
359 SC_FOLLOW_NONE, false, false );
363 // und Cursor setzen
365 // zusammengefasste Zellen beruecksichtigen:
366 pDoc->SkipOverlapped(nCol, nRow, nTab);
368 // Navigator-Aufrufe sind nicht API!!!
370 if( bNothing )
372 if (rReq.IsAPI())
373 rReq.Ignore(); // wenn Makro, dann gar nix
374 else
375 rReq.Done(); // sonst wenigstens aufzeichnen
377 else
379 pViewData->ResetOldCursor();
380 SetCursor( nCol, nRow );
381 rBindings.Invalidate( SID_CURRENTCELL );
382 rBindings.Update( nSlot );
384 if (!rReq.IsAPI())
385 rReq.Done();
388 if (bAlignToCursor)
390 // align to cursor even if the cursor position hasn't changed,
391 // because the cursor may be set outside the visible area.
392 AlignToCursor( nCol, nRow, SC_FOLLOW_JUMP );
395 rReq.SetReturnValue( SfxStringItem( SID_CURRENTCELL, aAddress ) );
398 if (!bFound) // kein gueltiger Bereich
400 // wenn es ein Tabellenname ist, umschalten (fuer Navigator/URL's)
402 SCTAB nNameTab;
403 if ( pDoc->GetTable( aAddress, nNameTab ) )
405 bFound = sal_True;
406 if ( nNameTab != nTab )
407 SetTabNo( nNameTab );
411 if ( !bFound && nSlot == SID_JUMPTOMARK )
413 // Grafik-Objekte probieren (nur bei URL's)
415 bFound = SelectObject( aAddress );
418 if (!bFound && !rReq.IsAPI())
419 ErrorMessage( STR_ERR_INVALID_AREA );
421 break;
423 case SID_CURRENTOBJECT:
424 if ( pReqArgs )
426 OUString aName = ((const SfxStringItem&)pReqArgs->Get(nSlot)).GetValue();
427 SelectObject( aName );
429 break;
431 case SID_CURRENTTAB:
432 if ( pReqArgs )
434 // Tabelle fuer Basic ist 1-basiert
435 SCTAB nTab = ((const SfxUInt16Item&)pReqArgs->Get(nSlot)).GetValue() - 1;
436 ScDocument* pDoc = GetViewData()->GetDocument();
437 if ( nTab < pDoc->GetTableCount() )
439 SetTabNo( nTab );
440 rBindings.Update( nSlot );
442 if( ! rReq.IsAPI() )
443 rReq.Done();
445 //! sonst Fehler ?
447 break;
449 case SID_CURRENTDOC:
450 if ( pReqArgs )
452 OUString aStrDocName( ((const SfxStringItem&)pReqArgs->
453 Get(nSlot)).GetValue() );
455 SfxViewFrame* pViewFrame = NULL;
456 ScDocShell* pDocSh = (ScDocShell*)SfxObjectShell::GetFirst();
457 sal_Bool bFound = false;
459 // zu aktivierenden ViewFrame suchen
461 while ( pDocSh && !bFound )
463 if ( pDocSh->GetTitle() == aStrDocName )
465 pViewFrame = SfxViewFrame::GetFirst( pDocSh );
466 bFound = ( NULL != pViewFrame );
469 pDocSh = (ScDocShell*)SfxObjectShell::GetNext( *pDocSh );
472 if ( bFound )
473 pViewFrame->GetFrame().Appear();
475 rReq.Ignore();//XXX wird von SFX erledigt
478 case SID_ATTR_SIZE://XXX ???
479 break;
482 case SID_PRINTPREVIEW:
484 if ( !pThisFrame->GetFrame().IsInPlace() ) // nicht bei OLE
486 // print preview is now always in the same frame as the tab view
487 // -> always switch this frame back to normal view
488 // (ScPreviewShell ctor reads view data)
490 // #102785#; finish input
491 pScMod->InputEnterHandler();
493 pThisFrame->GetDispatcher()->Execute( SID_VIEWSHELL1, SFX_CALLMODE_ASYNCHRON );
495 // else Fehler (z.B. Ole)
497 break;
499 case SID_DETECTIVE_DEL_ALL:
500 DetectiveDelAll();
501 rReq.Done();
502 break;
504 // SID_TABLE_ACTIVATE und SID_MARKAREA werden von Basic aus an der versteckten
505 // View aufgerufen, um auf der sichtbaren View zu markieren/umzuschalten:
507 case SID_TABLE_ACTIVATE:
508 OSL_FAIL("old slot SID_TABLE_ACTIVATE");
509 break;
511 case SID_REPAINT:
512 PaintGrid();
513 PaintTop();
514 PaintLeft();
515 PaintExtras();
516 rReq.Done();
517 break;
519 case FID_NORMALVIEWMODE:
520 case FID_PAGEBREAKMODE:
522 bool bWantPageBreak = nSlot == FID_PAGEBREAKMODE;
524 // check whether there is an explicit argument, use it
525 const SfxPoolItem* pItem;
526 if ( pReqArgs && pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET )
528 sal_Bool bItemValue = ((const SfxBoolItem*)pItem)->GetValue();
529 bWantPageBreak = (nSlot == FID_PAGEBREAKMODE) == bItemValue;
532 if( GetViewData()->IsPagebreakMode() != bWantPageBreak )
534 SetPagebreakMode( bWantPageBreak );
535 UpdatePageBreakData();
536 SetCurSubShell( GetCurObjectSelectionType(), sal_True );
537 PaintGrid();
538 PaintTop();
539 PaintLeft();
540 rBindings.Invalidate( nSlot );
541 rReq.AppendItem( SfxBoolItem( nSlot, sal_True ) );
542 rReq.Done();
545 break;
547 case FID_FUNCTION_BOX:
549 sal_uInt16 nChildId = ScFunctionChildWindow::GetChildWindowId();
550 if ( rReq.GetArgs() )
551 pThisFrame->SetChildWindow( nChildId, ((const SfxBoolItem&) (rReq.GetArgs()->Get(FID_FUNCTION_BOX))).GetValue());
552 else
554 pThisFrame->ToggleChildWindow( nChildId );
555 rReq.AppendItem( SfxBoolItem( FID_FUNCTION_BOX , pThisFrame->HasChildWindow( nChildId ) ) );
558 GetViewFrame()->GetBindings().Invalidate(FID_FUNCTION_BOX);
559 rReq.Done ();
561 break;
564 case FID_TOGGLESYNTAX:
566 sal_Bool bSet = !GetViewData()->IsSyntaxMode();
567 const SfxPoolItem* pItem;
568 if ( pReqArgs && pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET )
569 bSet = ((const SfxBoolItem*)pItem)->GetValue();
570 GetViewData()->SetSyntaxMode( bSet );
571 PaintGrid();
572 rBindings.Invalidate( FID_TOGGLESYNTAX );
573 rReq.AppendItem( SfxBoolItem( nSlot, bSet ) );
574 rReq.Done();
576 break;
577 case FID_TOGGLEHEADERS:
579 sal_Bool bSet = !GetViewData()->IsHeaderMode();
580 const SfxPoolItem* pItem;
581 if ( pReqArgs && pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET )
582 bSet = ((const SfxBoolItem*)pItem)->GetValue();
583 GetViewData()->SetHeaderMode( bSet );
584 RepeatResize();
585 rBindings.Invalidate( FID_TOGGLEHEADERS );
586 rReq.AppendItem( SfxBoolItem( nSlot, bSet ) );
587 rReq.Done();
589 break;
591 case FID_TOGGLEFORMULA:
593 ScViewData* pViewData = GetViewData();
594 const ScViewOptions& rOpts = pViewData->GetOptions();
595 sal_Bool bFormulaMode = !rOpts.GetOption( VOPT_FORMULAS );
596 const SfxPoolItem *pItem;
597 if( pReqArgs && pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET )
598 bFormulaMode = ((const SfxBoolItem *)pItem)->GetValue();
600 ScViewOptions rSetOpts = ScViewOptions( rOpts );
601 rSetOpts.SetOption( VOPT_FORMULAS, bFormulaMode );
602 pViewData->SetOptions( rSetOpts );
604 pViewData->GetDocShell()->PostPaintGridAll();
606 rBindings.Invalidate( FID_TOGGLEFORMULA );
607 rReq.AppendItem( SfxBoolItem( nSlot, bFormulaMode ) );
608 rReq.Done();
610 break;
612 case FID_TOGGLEINPUTLINE:
614 sal_uInt16 nId = ScInputWindowWrapper::GetChildWindowId();
615 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
616 sal_Bool bSet = ( pWnd == NULL );
617 const SfxPoolItem* pItem;
618 if ( pReqArgs && pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET )
619 bSet = ((const SfxBoolItem*)pItem)->GetValue();
621 pThisFrame->SetChildWindow( nId, bSet );
622 rBindings.Invalidate( FID_TOGGLEINPUTLINE );
623 rReq.AppendItem( SfxBoolItem( nSlot, bSet ) );
624 rReq.Done();
626 break;
628 case SID_ATTR_ZOOM: // Statuszeile
629 case FID_SCALE:
631 sal_Bool bSyncZoom = SC_MOD()->GetAppOptions().GetSynchronizeZoom();
632 SvxZoomType eOldZoomType = GetZoomType();
633 SvxZoomType eNewZoomType = eOldZoomType;
634 const Fraction& rOldY = GetViewData()->GetZoomY(); // Y wird angezeigt
635 sal_uInt16 nOldZoom = (sal_uInt16)(( rOldY.GetNumerator() * 100 )
636 / rOldY.GetDenominator());
637 sal_uInt16 nZoom = nOldZoom;
638 sal_Bool bCancel = false;
640 if ( pReqArgs )
642 const SvxZoomItem& rZoomItem = (const SvxZoomItem&)
643 pReqArgs->Get(SID_ATTR_ZOOM);
645 eNewZoomType = rZoomItem.GetType();
646 nZoom = rZoomItem.GetValue();
648 else
650 SfxItemSet aSet ( GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM );
651 SvxZoomItem aZoomItem( eOldZoomType, nOldZoom, SID_ATTR_ZOOM );
652 AbstractSvxZoomDialog* pDlg = NULL;
653 ScMarkData& rMark = GetViewData()->GetMarkData();
654 sal_uInt16 nBtnFlags = SVX_ZOOM_ENABLE_50
655 | SVX_ZOOM_ENABLE_75
656 | SVX_ZOOM_ENABLE_100
657 | SVX_ZOOM_ENABLE_150
658 | SVX_ZOOM_ENABLE_200
659 | SVX_ZOOM_ENABLE_WHOLEPAGE
660 | SVX_ZOOM_ENABLE_PAGEWIDTH;
662 if ( rMark.IsMarked() || rMark.IsMultiMarked() )
663 nBtnFlags = nBtnFlags | SVX_ZOOM_ENABLE_OPTIMAL;
665 aZoomItem.SetValueSet( nBtnFlags );
666 aSet.Put( aZoomItem );
667 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
668 if(pFact)
670 pDlg = pFact->CreateSvxZoomDialog(GetDialogParent(), aSet );
671 OSL_ENSURE(pDlg, "Dialogdiet fail!");
673 if (pDlg)
675 pDlg->SetLimits( MINZOOM, MAXZOOM );
677 bCancel = ( RET_CANCEL == pDlg->Execute() );
679 // bCancel is True only if we were in the previous if block,
680 // so no need to check again pDlg
681 if ( !bCancel )
683 const SvxZoomItem& rZoomItem = (const SvxZoomItem&)
684 pDlg->GetOutputItemSet()->
685 Get( SID_ATTR_ZOOM );
687 eNewZoomType = rZoomItem.GetType();
688 nZoom = rZoomItem.GetValue();
691 delete pDlg;
694 if ( !bCancel )
696 if ( eNewZoomType == SVX_ZOOM_PERCENT )
698 if ( nZoom < MINZOOM ) nZoom = MINZOOM;
699 if ( nZoom > MAXZOOM ) nZoom = MAXZOOM;
701 else
703 nZoom = CalcZoom( eNewZoomType, nOldZoom );
704 bCancel = nZoom == 0;
707 switch ( eNewZoomType )
709 case SVX_ZOOM_WHOLEPAGE:
710 case SVX_ZOOM_PAGEWIDTH:
711 SetZoomType( eNewZoomType, bSyncZoom );
712 break;
714 default:
715 SetZoomType( SVX_ZOOM_PERCENT, bSyncZoom );
719 if ( nZoom != nOldZoom && !bCancel )
721 if (!GetViewData()->IsPagebreakMode())
723 ScAppOptions aNewOpt = pScMod->GetAppOptions();
724 aNewOpt.SetZoom( nZoom );
725 aNewOpt.SetZoomType( GetZoomType() );
726 pScMod->SetAppOptions( aNewOpt );
728 Fraction aFract( nZoom, 100 );
729 SetZoom( aFract, aFract, bSyncZoom );
730 PaintGrid();
731 PaintTop();
732 PaintLeft();
733 rBindings.Invalidate( SID_ATTR_ZOOM );
734 rReq.AppendItem( SvxZoomItem( GetZoomType(), nZoom, nSlot ) );
735 rReq.Done();
738 break;
740 case SID_ATTR_ZOOMSLIDER:
742 const SfxPoolItem* pItem = NULL;
743 sal_Bool bSyncZoom = SC_MOD()->GetAppOptions().GetSynchronizeZoom();
744 if ( pReqArgs && pReqArgs->GetItemState(SID_ATTR_ZOOMSLIDER, sal_True, &pItem) == SFX_ITEM_SET )
746 const sal_uInt16 nCurrentZoom = ((const SvxZoomSliderItem *)pItem)->GetValue();
747 if( nCurrentZoom )
749 SetZoomType( SVX_ZOOM_PERCENT, bSyncZoom );
750 if (!GetViewData()->IsPagebreakMode())
752 ScAppOptions aNewOpt = pScMod->GetAppOptions();
753 aNewOpt.SetZoom( nCurrentZoom );
754 aNewOpt.SetZoomType( GetZoomType() );
755 pScMod->SetAppOptions( aNewOpt );
757 Fraction aFract( nCurrentZoom,100 );
758 SetZoom( aFract, aFract, bSyncZoom );
759 PaintGrid();
760 PaintTop();
761 PaintLeft();
762 rBindings.Invalidate( SID_ATTR_ZOOMSLIDER );
763 rReq.Done();
767 break;
769 //----------------------------------------------------------------
771 case FID_TAB_SELECTALL:
772 SelectAllTables();
773 rReq.Done();
774 break;
776 case FID_TAB_DESELECTALL:
777 DeselectAllTables();
778 rReq.Done();
779 break;
781 case SID_SELECT_TABLES:
783 ScViewData& rViewData = *GetViewData();
784 ScDocument& rDoc = *rViewData.GetDocument();
785 ScMarkData& rMark = rViewData.GetMarkData();
786 SCTAB nTabCount = rDoc.GetTableCount();
787 SCTAB nTab;
789 ::std::vector < sal_Int32 > aIndexList;
790 SFX_REQUEST_ARG( rReq, pItem, SfxIntegerListItem, SID_SELECT_TABLES, false );
791 if ( pItem )
792 pItem->GetList( aIndexList );
793 else
795 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
796 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
798 AbstractScShowTabDlg* pDlg = pFact->CreateScShowTabDlg( GetDialogParent(), RID_SCDLG_SHOW_TAB);
799 OSL_ENSURE(pDlg, "Dialog create fail!");
800 pDlg->SetDescription(
801 OUString( ScResId( STR_DLG_SELECTTABLES_TITLE ) ),
802 OUString( ScResId( STR_DLG_SELECTTABLES_LBNAME ) ),
803 GetStaticInterface()->GetSlot(SID_SELECT_TABLES)->GetCommand(), HID_SELECTTABLES );
805 // fill all table names with selection state
806 OUString aTabName;
807 for( nTab = 0; nTab < nTabCount; ++nTab )
809 rDoc.GetName( nTab, aTabName );
810 pDlg->Insert( aTabName, rMark.GetTableSelect( nTab ) );
813 if( pDlg->Execute() == RET_OK )
815 sal_uInt16 nSelCount = pDlg->GetSelectEntryCount();
816 sal_uInt16 nSelIx;
817 for( nSelIx = 0; nSelIx < nSelCount; ++nSelIx )
818 aIndexList.insert( aIndexList.begin()+nSelIx, pDlg->GetSelectEntryPos( nSelIx ) );
819 delete pDlg;
820 rReq.AppendItem( SfxIntegerListItem( SID_SELECT_TABLES, aIndexList ) );
822 else
823 rReq.Ignore();
826 if ( !aIndexList.empty() )
828 sal_uInt16 nSelCount = aIndexList.size();
829 sal_uInt16 nSelIx;
830 SCTAB nFirstVisTab = 0;
832 // special case: only hidden tables selected -> do nothing
833 sal_Bool bVisSelected = false;
834 for( nSelIx = 0; !bVisSelected && (nSelIx < nSelCount); ++nSelIx )
835 bVisSelected = rDoc.IsVisible( nFirstVisTab = static_cast<SCTAB>(aIndexList[nSelIx]) );
836 if( !bVisSelected )
837 nSelCount = 0;
839 // select the tables
840 if( nSelCount )
842 for( nTab = 0; nTab < nTabCount; ++nTab )
843 rMark.SelectTable( nTab, false );
845 for( nSelIx = 0; nSelIx < nSelCount; ++nSelIx )
846 rMark.SelectTable( static_cast<SCTAB>(aIndexList[nSelIx]), sal_True );
848 // activate another table, if current is deselected
849 if( !rMark.GetTableSelect( rViewData.GetTabNo() ) )
851 rMark.SelectTable( nFirstVisTab, sal_True );
852 SetTabNo( nFirstVisTab );
855 rViewData.GetDocShell()->PostPaintExtras();
856 SfxBindings& rBind = rViewData.GetBindings();
857 rBind.Invalidate( FID_FILL_TAB );
858 rBind.Invalidate( FID_TAB_DESELECTALL );
861 rReq.Done();
864 break;
867 case SID_OUTLINE_DELETEALL:
868 RemoveAllOutlines();
869 rReq.Done();
870 break;
872 case SID_AUTO_OUTLINE:
873 AutoOutline();
874 rReq.Done();
875 break;
878 case SID_WINDOW_SPLIT:
880 ScSplitMode eHSplit = GetViewData()->GetHSplitMode();
881 ScSplitMode eVSplit = GetViewData()->GetVSplitMode();
882 if ( eHSplit == SC_SPLIT_NORMAL || eVSplit == SC_SPLIT_NORMAL ) // aufheben
883 RemoveSplit();
884 else if ( eHSplit == SC_SPLIT_FIX || eVSplit == SC_SPLIT_FIX ) // normal
885 FreezeSplitters( false );
886 else // erzeugen
887 SplitAtCursor();
888 rReq.Done();
890 InvalidateSplit();
892 break;
894 case SID_WINDOW_FIX:
896 ScSplitMode eHSplit = GetViewData()->GetHSplitMode();
897 ScSplitMode eVSplit = GetViewData()->GetVSplitMode();
898 if ( eHSplit == SC_SPLIT_FIX || eVSplit == SC_SPLIT_FIX ) // aufheben
899 RemoveSplit();
900 else
901 FreezeSplitters( sal_True ); // erzeugen oder fixieren
902 rReq.Done();
904 InvalidateSplit();
906 break;
908 // ----------------------------------------------------------------
910 case FID_CHG_SHOW:
912 sal_uInt16 nId = ScHighlightChgDlgWrapper::GetChildWindowId();
913 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
915 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
917 break;
919 case FID_CHG_ACCEPT:
921 pThisFrame->ToggleChildWindow(ScAcceptChgDlgWrapper::GetChildWindowId());
922 GetViewFrame()->GetBindings().Invalidate(FID_CHG_ACCEPT);
923 rReq.Done ();
926 sal_uInt16 nId = ScAcceptChgDlgWrapper::GetChildWindowId();
927 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
929 pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True );
932 break;
934 case FID_CHG_COMMENT:
936 ScViewData* pData = GetViewData();
937 ScAddress aCursorPos( pData->GetCurX(), pData->GetCurY(), pData->GetTabNo() );
938 ScDocShell* pDocSh = pData->GetDocShell();
940 ScChangeAction* pAction = pDocSh->GetChangeAction( aCursorPos );
941 if ( pAction )
943 const SfxPoolItem* pItem;
944 if ( pReqArgs &&
945 pReqArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET &&
946 pItem->ISA( SfxStringItem ) )
948 OUString aComment = ((const SfxStringItem*)pItem)->GetValue();
949 pDocSh->SetChangeComment( pAction, aComment );
950 rReq.Done();
952 else
954 pDocSh->ExecuteChangeCommentDialog( pAction, GetDialogParent() );
955 rReq.Done();
959 break;
961 case SID_CREATE_SW_DRAWVIEW:
962 // wird von den Forms gerufen, wenn die DrawView mit allem Zubehoer
963 // angelegt werden muss
964 if (!GetScDrawView())
966 GetViewData()->GetDocShell()->MakeDrawLayer();
967 rBindings.InvalidateAll(false);
969 break;
971 case FID_PROTECT_DOC:
973 ScDocument* pDoc = GetViewData()->GetDocument();
974 SfxPasswordDialog* pDlg;
976 if( pReqArgs )
978 const SfxPoolItem* pItem;
979 if( pReqArgs->HasItem( FID_PROTECT_DOC, &pItem ) &&
980 ((const SfxBoolItem*)pItem)->GetValue() == static_cast<sal_Bool>(pDoc->IsDocProtected()) )
982 rReq.Ignore();
983 break;
987 ScDocProtection* pProtect = pDoc->GetDocProtection();
988 if (pProtect && pProtect->isProtected())
990 sal_Bool bCancel = false;
991 OUString aPassword;
993 if (pProtect->isProtectedWithPass())
995 OUString aText(ScResId(SCSTR_PASSWORD));
997 pDlg = new SfxPasswordDialog(GetDialogParent(), &aText);
998 pDlg->SetText( ScResId(SCSTR_UNPROTECTDOC) );
999 pDlg->SetMinLen( 0 );
1000 pDlg->SetHelpId( GetStaticInterface()->GetSlot(FID_PROTECT_DOC)->GetCommand() );
1001 pDlg->SetEditHelpId( HID_PASSWD_DOC );
1003 if (pDlg->Execute() == RET_OK)
1004 aPassword = pDlg->GetPassword();
1005 else
1006 bCancel = sal_True;
1007 delete pDlg;
1009 if (!bCancel)
1011 Unprotect( TABLEID_DOC, aPassword );
1012 rReq.AppendItem( SfxBoolItem( FID_PROTECT_DOC, false ) );
1013 rReq.Done();
1016 else
1018 OUString aText(ScResId(SCSTR_PASSWORDOPT));
1020 pDlg = new SfxPasswordDialog( GetDialogParent(), &aText );
1021 pDlg->SetText( ScResId(SCSTR_PROTECTDOC) );
1022 pDlg->SetMinLen( 0 );
1023 pDlg->SetHelpId( GetStaticInterface()->GetSlot(FID_PROTECT_DOC)->GetCommand() );
1024 pDlg->SetEditHelpId( HID_PASSWD_DOC );
1025 pDlg->ShowExtras( SHOWEXTRAS_CONFIRM );
1027 if (pDlg->Execute() == RET_OK)
1029 OUString aPassword = pDlg->GetPassword();
1030 Protect( TABLEID_DOC, aPassword );
1031 rReq.AppendItem( SfxBoolItem( FID_PROTECT_DOC, sal_True ) );
1032 rReq.Done();
1035 delete pDlg;
1037 rBindings.Invalidate( FID_PROTECT_DOC );
1039 break;
1042 case FID_PROTECT_TABLE:
1044 ScDocument* pDoc = GetViewData()->GetDocument();
1045 SCTAB nTab = GetViewData()->GetTabNo();
1046 bool bOldProtection = pDoc->IsTabProtected(nTab);
1048 if( pReqArgs )
1050 const SfxPoolItem* pItem;
1051 bool bNewProtection = !bOldProtection;
1052 if( pReqArgs->HasItem( FID_PROTECT_TABLE, &pItem ) )
1053 bNewProtection = ((const SfxBoolItem*)pItem)->GetValue();
1054 if( bNewProtection == bOldProtection )
1056 rReq.Ignore();
1057 break;
1061 if (bOldProtection)
1063 // Unprotect a protected sheet.
1065 ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
1066 if (pProtect && pProtect->isProtectedWithPass())
1068 OUString aText( ScResId(SCSTR_PASSWORDOPT) );
1069 auto_ptr<SfxPasswordDialog> pDlg(new SfxPasswordDialog(GetDialogParent(), &aText));
1070 pDlg->SetText( ScResId(SCSTR_UNPROTECTTAB) );
1071 pDlg->SetMinLen( 0 );
1072 pDlg->SetHelpId( GetStaticInterface()->GetSlot(FID_PROTECT_TABLE)->GetCommand() );
1073 pDlg->SetEditHelpId( HID_PASSWD_TABLE );
1075 if (pDlg->Execute() == RET_OK)
1077 OUString aPassword = pDlg->GetPassword();
1078 Unprotect(nTab, aPassword);
1081 else
1082 // this sheet is not password-protected.
1083 Unprotect(nTab, OUString());
1085 if (!pReqArgs)
1087 rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, false) );
1088 rReq.Done();
1091 else
1093 // Protect a current sheet.
1095 auto_ptr<ScTableProtectionDlg> pDlg(new ScTableProtectionDlg(GetDialogParent()));
1097 ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
1098 if (pProtect)
1099 pDlg->SetDialogData(*pProtect);
1101 if (pDlg->Execute() == RET_OK)
1103 pScMod->InputEnterHandler();
1105 ScTableProtection aNewProtect;
1106 pDlg->WriteData(aNewProtect);
1107 ProtectSheet(nTab, aNewProtect);
1108 if (!pReqArgs)
1110 rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, true) );
1111 rReq.Done();
1115 TabChanged();
1116 UpdateInputHandler(true); // damit sofort wieder eingegeben werden kann
1117 SelectionChanged();
1119 break;
1121 case SID_OPT_LOCALE_CHANGED :
1122 { // locale changed, SYSTEM number formats changed => repaint cell contents
1123 PaintGrid();
1124 rReq.Done();
1126 break;
1128 default:
1129 OSL_FAIL("Unbekannter Slot bei ScTabViewShell::Execute");
1130 break;
1136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */