Bump version to 4.3-4
[LibreOffice.git] / sc / source / ui / view / tabvwsh3.cxx
blob58665e25b37666ef322a8d01910c11276e35dfbe
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 <boost/scoped_ptr.hpp>
71 /** Try to parse the given range using Calc-style syntax first, then
72 Excel-style if that fails. */
73 static sal_uInt16 lcl_ParseRange(ScRange& rScRange, const OUString& aAddress, ScDocument* pDoc, sal_uInt16 /* nSlot */)
75 sal_uInt16 nResult = rScRange.Parse(aAddress, pDoc);
76 if ( (nResult & SCA_VALID) )
77 return nResult;
79 return rScRange.Parse(aAddress, pDoc, ScAddress::Details(formula::FormulaGrammar::CONV_XL_A1, 0, 0));
82 /** Try to parse the given address using Calc-style syntax first, then
83 Excel-style if that fails. */
84 static sal_uInt16 lcl_ParseAddress(ScAddress& rScAddress, const OUString& aAddress, ScDocument* pDoc, sal_uInt16 /* nSlot */)
86 sal_uInt16 nResult = rScAddress.Parse(aAddress, pDoc);
87 if ( (nResult & SCA_VALID) )
88 return nResult;
90 return rScAddress.Parse(aAddress, pDoc, ScAddress::Details(formula::FormulaGrammar::CONV_XL_A1, 0, 0));
93 void ScTabViewShell::Execute( SfxRequest& rReq )
95 SfxViewFrame* pThisFrame = GetViewFrame();
96 SfxBindings& rBindings = pThisFrame->GetBindings();
97 ScModule* pScMod = SC_MOD();
98 const SfxItemSet* pReqArgs = rReq.GetArgs();
99 sal_uInt16 nSlot = rReq.GetSlot();
101 if (nSlot != SID_CURRENTCELL) // der kommt beim MouseButtonUp
102 HideListBox(); // Autofilter-DropDown-Listbox
104 switch ( nSlot )
106 case FID_INSERT_FILE:
108 const SfxPoolItem* pItem;
109 if ( pReqArgs &&
110 pReqArgs->GetItemState(FID_INSERT_FILE,true,&pItem) == SFX_ITEM_SET )
112 OUString aFileName = ((const SfxStringItem*)pItem)->GetValue();
114 // Einfuege-Position
116 Point aInsertPos;
117 if ( pReqArgs->GetItemState(FN_PARAM_1,true,&pItem) == SFX_ITEM_SET )
118 aInsertPos = ((const SfxPointItem*)pItem)->GetValue();
119 else
120 aInsertPos = GetInsertPos();
122 // als Link?
124 bool bAsLink = false;
125 if ( pReqArgs->GetItemState(FN_PARAM_2,true,&pItem) == SFX_ITEM_SET )
126 bAsLink = ((const SfxBoolItem*)pItem)->GetValue();
128 // ausfuehren
130 PasteFile( aInsertPos, aFileName, bAsLink );
133 break;
135 case SID_OPENDLG_EDIT_PRINTAREA:
137 sal_uInt16 nId = ScPrintAreasDlgWrapper::GetChildWindowId();
138 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
140 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
142 break;
144 case SID_CHANGE_PRINTAREA:
146 if ( pReqArgs ) // OK aus Dialog
148 OUString aPrintStr;
149 OUString aRowStr;
150 OUString aColStr;
151 bool bEntire = false;
152 const SfxPoolItem* pItem;
153 if ( pReqArgs->GetItemState( SID_CHANGE_PRINTAREA, true, &pItem ) == SFX_ITEM_SET )
154 aPrintStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
155 if ( pReqArgs->GetItemState( FN_PARAM_2, true, &pItem ) == SFX_ITEM_SET )
156 aRowStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
157 if ( pReqArgs->GetItemState( FN_PARAM_3, true, &pItem ) == SFX_ITEM_SET )
158 aColStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
159 if ( pReqArgs->GetItemState( FN_PARAM_4, true, &pItem ) == SFX_ITEM_SET )
160 bEntire = static_cast<const SfxBoolItem*>(pItem)->GetValue();
162 SetPrintRanges( bEntire, &aPrintStr, &aColStr, &aRowStr, false );
164 rReq.Done();
167 break;
169 case SID_ADD_PRINTAREA:
170 case SID_DEFINE_PRINTAREA: // Menue oder Basic
172 bool bAdd = ( nSlot == SID_ADD_PRINTAREA );
173 if ( pReqArgs )
175 OUString aPrintStr;
176 const SfxPoolItem* pItem;
177 if ( pReqArgs->GetItemState( SID_DEFINE_PRINTAREA, true, &pItem ) == SFX_ITEM_SET )
178 aPrintStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
179 SetPrintRanges( false, &aPrintStr, NULL, NULL, bAdd );
181 else
183 SetPrintRanges( false, NULL, NULL, NULL, bAdd ); // aus Selektion
184 rReq.Done();
187 break;
189 case SID_DELETE_PRINTAREA:
191 // Clear currently defined print range if any, and reset it to
192 // print entire sheet which is the default.
193 OUString aEmpty;
194 SetPrintRanges(true, &aEmpty, NULL, NULL, false);
195 rReq.Done();
197 break;
199 case FID_DEL_MANUALBREAKS:
200 RemoveManualBreaks();
201 rReq.Done();
202 break;
204 case FID_ADJUST_PRINTZOOM:
205 AdjustPrintZoom();
206 rReq.Done();
207 break;
209 case FID_RESET_PRINTZOOM:
210 SetPrintZoom( 100, 0 ); // 100%, nicht auf Seiten
211 rReq.Done();
212 break;
214 case SID_FORMATPAGE:
215 case SID_STATUS_PAGESTYLE:
216 case SID_HFEDIT:
217 GetViewData()->GetDocShell()->
218 ExecutePageStyle( *this, rReq, GetViewData()->GetTabNo() );
219 break;
221 case SID_JUMPTOMARK:
222 case SID_CURRENTCELL:
223 if ( pReqArgs )
225 OUString aAddress;
226 const SfxPoolItem* pItem;
227 if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SFX_ITEM_SET )
228 aAddress = ((const SfxStringItem*)pItem)->GetValue();
229 else if ( nSlot == SID_JUMPTOMARK && pReqArgs->GetItemState(
230 SID_JUMPTOMARK, true, &pItem ) == SFX_ITEM_SET )
231 aAddress = ((const SfxStringItem*)pItem)->GetValue();
233 // #i14927# SID_CURRENTCELL with a single cell must unmark if FN_PARAM_1
234 // isn't set (for recorded macros, because IsAPI is no longer available).
235 // ScGridWindow::MouseButtonUp no longer executes the slot for a single
236 // cell if there is a multi selection.
237 bool bUnmark = ( nSlot == SID_CURRENTCELL );
238 if ( pReqArgs->GetItemState( FN_PARAM_1, true, &pItem ) == SFX_ITEM_SET )
239 bUnmark = ((const SfxBoolItem*)pItem)->GetValue();
241 bool bAlignToCursor = true;
242 if (pReqArgs->GetItemState(FN_PARAM_2, true, &pItem) == SFX_ITEM_SET)
243 bAlignToCursor = static_cast<const SfxBoolItem*>(pItem)->GetValue();
245 if ( nSlot == SID_JUMPTOMARK )
247 // URL has to be decoded for escaped characters (%20)
248 aAddress = INetURLObject::decode( aAddress, '%',
249 INetURLObject::DECODE_WITH_CHARSET,
250 RTL_TEXTENCODING_UTF8 );
253 bool bFound = false;
254 ScViewData* pViewData = GetViewData();
255 ScDocument* pDoc = pViewData->GetDocument();
256 ScMarkData& rMark = pViewData->GetMarkData();
257 ScRange aScRange;
258 ScAddress aScAddress;
259 sal_uInt16 nResult = lcl_ParseRange(aScRange, aAddress, pDoc, nSlot);
260 SCTAB nTab = pViewData->GetTabNo();
261 bool bMark = true;
263 // Is this a range ?
264 if( nResult & SCA_VALID )
266 if ( nResult & SCA_TAB_3D )
268 if( aScRange.aStart.Tab() != nTab )
269 SetTabNo( nTab = aScRange.aStart.Tab() );
271 else
273 aScRange.aStart.SetTab( nTab );
274 aScRange.aEnd.SetTab( nTab );
277 // Is this a cell ?
278 else if ( (nResult = lcl_ParseAddress(aScAddress, aAddress, pDoc, nSlot)) & SCA_VALID )
280 if ( nResult & SCA_TAB_3D )
282 if( aScAddress.Tab() != nTab )
283 SetTabNo( nTab = aScAddress.Tab() );
285 else
286 aScAddress.SetTab( nTab );
288 aScRange = ScRange( aScAddress, aScAddress );
289 // Zellen sollen nicht markiert werden
290 bMark = false;
292 // Ist es benahmster Bereich (erst Namen dann DBBereiche) ?
293 else
295 ScRangeUtil aRangeUtil;
296 formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
297 if( aRangeUtil.MakeRangeFromName( aAddress, pDoc, nTab, aScRange, RUTL_NAMES, eConv ) ||
298 aRangeUtil.MakeRangeFromName( aAddress, pDoc, nTab, aScRange, RUTL_DBASE, eConv ) )
300 nResult |= SCA_VALID;
301 if( aScRange.aStart.Tab() != nTab )
302 SetTabNo( nTab = aScRange.aStart.Tab() );
306 if ( !(nResult & SCA_VALID) && comphelper::string::isdigitAsciiString(aAddress) )
308 sal_Int32 nNumeric = aAddress.toInt32();
309 if ( nNumeric > 0 && nNumeric <= MAXROW+1 )
311 // 1-basierte Zeilennummer
313 aScAddress.SetRow( (SCROW)(nNumeric - 1) );
314 aScAddress.SetCol( pViewData->GetCurX() );
315 aScAddress.SetTab( nTab );
316 aScRange = ScRange( aScAddress, aScAddress );
317 bMark = false;
318 nResult = SCA_VALID;
322 if ( !ValidRow(aScRange.aStart.Row()) || !ValidRow(aScRange.aEnd.Row()) )
323 nResult = 0;
325 // wir haben was gefunden
326 if( nResult & SCA_VALID )
328 bFound = true;
329 SCCOL nCol = aScRange.aStart.Col();
330 SCROW nRow = aScRange.aStart.Row();
331 bool bNothing = ( pViewData->GetCurX()==nCol && pViewData->GetCurY()==nRow );
333 // markieren
334 if( bMark )
336 if (rMark.IsMarked()) // ist derselbe Bereich schon markiert?
338 ScRange aOldMark;
339 rMark.GetMarkArea( aOldMark );
340 aOldMark.Justify();
341 ScRange aCurrent = aScRange;
342 aCurrent.Justify();
343 bNothing = ( aCurrent == aOldMark );
345 else
346 bNothing = false;
348 if (!bNothing)
349 MarkRange( aScRange, false ); // Cursor kommt hinterher...
351 else
353 // remove old selection, unless bUnmark argument is sal_False (from navigator)
354 if( bUnmark )
356 MoveCursorAbs( nCol, nRow,
357 SC_FOLLOW_NONE, false, false );
361 // und Cursor setzen
363 // zusammengefasste Zellen beruecksichtigen:
364 pDoc->SkipOverlapped(nCol, nRow, nTab);
366 // Navigator-Aufrufe sind nicht API!!!
368 if( bNothing )
370 if (rReq.IsAPI())
371 rReq.Ignore(); // wenn Makro, dann gar nix
372 else
373 rReq.Done(); // sonst wenigstens aufzeichnen
375 else
377 pViewData->ResetOldCursor();
378 SetCursor( nCol, nRow );
379 rBindings.Invalidate( SID_CURRENTCELL );
380 rBindings.Update( nSlot );
382 if (!rReq.IsAPI())
383 rReq.Done();
386 if (bAlignToCursor)
388 // align to cursor even if the cursor position hasn't changed,
389 // because the cursor may be set outside the visible area.
390 AlignToCursor( nCol, nRow, SC_FOLLOW_JUMP );
393 rReq.SetReturnValue( SfxStringItem( SID_CURRENTCELL, aAddress ) );
396 if (!bFound) // kein gueltiger Bereich
398 // wenn es ein Tabellenname ist, umschalten (fuer Navigator/URL's)
400 SCTAB nNameTab;
401 if ( pDoc->GetTable( aAddress, nNameTab ) )
403 bFound = true;
404 if ( nNameTab != nTab )
405 SetTabNo( nNameTab );
409 if ( !bFound && nSlot == SID_JUMPTOMARK )
411 // Grafik-Objekte probieren (nur bei URL's)
413 bFound = SelectObject( aAddress );
416 if (!bFound && !rReq.IsAPI())
417 ErrorMessage( STR_ERR_INVALID_AREA );
419 break;
421 case SID_CURRENTOBJECT:
422 if ( pReqArgs )
424 OUString aName = ((const SfxStringItem&)pReqArgs->Get(nSlot)).GetValue();
425 SelectObject( aName );
427 break;
429 case SID_CURRENTTAB:
430 if ( pReqArgs )
432 // Tabelle fuer Basic ist 1-basiert
433 SCTAB nTab = ((const SfxUInt16Item&)pReqArgs->Get(nSlot)).GetValue() - 1;
434 ScDocument* pDoc = GetViewData()->GetDocument();
435 if ( nTab < pDoc->GetTableCount() )
437 SetTabNo( nTab );
438 rBindings.Update( nSlot );
440 if( ! rReq.IsAPI() )
441 rReq.Done();
443 //! sonst Fehler ?
445 break;
447 case SID_CURRENTDOC:
448 if ( pReqArgs )
450 OUString aStrDocName( ((const SfxStringItem&)pReqArgs->
451 Get(nSlot)).GetValue() );
453 SfxViewFrame* pViewFrame = NULL;
454 ScDocShell* pDocSh = (ScDocShell*)SfxObjectShell::GetFirst();
455 bool bFound = false;
457 // zu aktivierenden ViewFrame suchen
459 while ( pDocSh && !bFound )
461 if ( pDocSh->GetTitle() == aStrDocName )
463 pViewFrame = SfxViewFrame::GetFirst( pDocSh );
464 bFound = ( NULL != pViewFrame );
467 pDocSh = (ScDocShell*)SfxObjectShell::GetNext( *pDocSh );
470 if ( bFound )
471 pViewFrame->GetFrame().Appear();
473 rReq.Ignore();//XXX wird von SFX erledigt
476 case SID_ATTR_SIZE://XXX ???
477 break;
480 case SID_PRINTPREVIEW:
482 if ( !pThisFrame->GetFrame().IsInPlace() ) // nicht bei OLE
484 // print preview is now always in the same frame as the tab view
485 // -> always switch this frame back to normal view
486 // (ScPreviewShell ctor reads view data)
488 // #102785#; finish input
489 pScMod->InputEnterHandler();
491 pThisFrame->GetDispatcher()->Execute( SID_VIEWSHELL1, SFX_CALLMODE_ASYNCHRON );
493 // else Fehler (z.B. Ole)
495 break;
497 case SID_DETECTIVE_DEL_ALL:
498 DetectiveDelAll();
499 rReq.Done();
500 break;
502 // SID_TABLE_ACTIVATE und SID_MARKAREA werden von Basic aus an der versteckten
503 // View aufgerufen, um auf der sichtbaren View zu markieren/umzuschalten:
505 case SID_TABLE_ACTIVATE:
506 OSL_FAIL("old slot SID_TABLE_ACTIVATE");
507 break;
509 case SID_REPAINT:
510 PaintGrid();
511 PaintTop();
512 PaintLeft();
513 PaintExtras();
514 rReq.Done();
515 break;
517 case FID_NORMALVIEWMODE:
518 case FID_PAGEBREAKMODE:
520 bool bWantPageBreak = nSlot == FID_PAGEBREAKMODE;
522 // check whether there is an explicit argument, use it
523 const SfxPoolItem* pItem;
524 if ( pReqArgs && pReqArgs->GetItemState(nSlot, true, &pItem) == SFX_ITEM_SET )
526 bool bItemValue = ((const SfxBoolItem*)pItem)->GetValue();
527 bWantPageBreak = (nSlot == FID_PAGEBREAKMODE) == bItemValue;
530 if( GetViewData()->IsPagebreakMode() != bWantPageBreak )
532 SetPagebreakMode( bWantPageBreak );
533 UpdatePageBreakData();
534 SetCurSubShell( GetCurObjectSelectionType(), true );
535 PaintGrid();
536 PaintTop();
537 PaintLeft();
538 rBindings.Invalidate( nSlot );
539 rReq.AppendItem( SfxBoolItem( nSlot, true ) );
540 rReq.Done();
543 break;
545 case FID_FUNCTION_BOX:
547 sal_uInt16 nChildId = ScFunctionChildWindow::GetChildWindowId();
548 if ( rReq.GetArgs() )
549 pThisFrame->SetChildWindow( nChildId, ((const SfxBoolItem&) (rReq.GetArgs()->Get(FID_FUNCTION_BOX))).GetValue());
550 else
552 pThisFrame->ToggleChildWindow( nChildId );
553 rReq.AppendItem( SfxBoolItem( FID_FUNCTION_BOX , pThisFrame->HasChildWindow( nChildId ) ) );
556 GetViewFrame()->GetBindings().Invalidate(FID_FUNCTION_BOX);
557 rReq.Done ();
559 break;
562 case FID_TOGGLESYNTAX:
564 bool bSet = !GetViewData()->IsSyntaxMode();
565 const SfxPoolItem* pItem;
566 if ( pReqArgs && pReqArgs->GetItemState(nSlot, true, &pItem) == SFX_ITEM_SET )
567 bSet = ((const SfxBoolItem*)pItem)->GetValue();
568 GetViewData()->SetSyntaxMode( bSet );
569 PaintGrid();
570 rBindings.Invalidate( FID_TOGGLESYNTAX );
571 rReq.AppendItem( SfxBoolItem( nSlot, bSet ) );
572 rReq.Done();
574 break;
575 case FID_TOGGLEHEADERS:
577 bool bSet = !GetViewData()->IsHeaderMode();
578 const SfxPoolItem* pItem;
579 if ( pReqArgs && pReqArgs->GetItemState(nSlot, true, &pItem) == SFX_ITEM_SET )
580 bSet = ((const SfxBoolItem*)pItem)->GetValue();
581 GetViewData()->SetHeaderMode( bSet );
582 RepeatResize();
583 rBindings.Invalidate( FID_TOGGLEHEADERS );
584 rReq.AppendItem( SfxBoolItem( nSlot, bSet ) );
585 rReq.Done();
587 break;
589 case FID_TOGGLEFORMULA:
591 ScViewData* pViewData = GetViewData();
592 const ScViewOptions& rOpts = pViewData->GetOptions();
593 bool bFormulaMode = !rOpts.GetOption( VOPT_FORMULAS );
594 const SfxPoolItem *pItem;
595 if( pReqArgs && pReqArgs->GetItemState(nSlot, true, &pItem) == SFX_ITEM_SET )
596 bFormulaMode = ((const SfxBoolItem *)pItem)->GetValue();
598 ScViewOptions rSetOpts = ScViewOptions( rOpts );
599 rSetOpts.SetOption( VOPT_FORMULAS, bFormulaMode );
600 pViewData->SetOptions( rSetOpts );
602 pViewData->GetDocShell()->PostPaintGridAll();
604 rBindings.Invalidate( FID_TOGGLEFORMULA );
605 rReq.AppendItem( SfxBoolItem( nSlot, bFormulaMode ) );
606 rReq.Done();
608 break;
610 case FID_TOGGLEINPUTLINE:
612 sal_uInt16 nId = ScInputWindowWrapper::GetChildWindowId();
613 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
614 bool bSet = ( pWnd == NULL );
615 const SfxPoolItem* pItem;
616 if ( pReqArgs && pReqArgs->GetItemState(nSlot, true, &pItem) == SFX_ITEM_SET )
617 bSet = ((const SfxBoolItem*)pItem)->GetValue();
619 pThisFrame->SetChildWindow( nId, bSet );
620 rBindings.Invalidate( FID_TOGGLEINPUTLINE );
621 rReq.AppendItem( SfxBoolItem( nSlot, bSet ) );
622 rReq.Done();
624 break;
626 case SID_ATTR_ZOOM: // Statuszeile
627 case FID_SCALE:
629 bool bSyncZoom = SC_MOD()->GetAppOptions().GetSynchronizeZoom();
630 SvxZoomType eOldZoomType = GetZoomType();
631 SvxZoomType eNewZoomType = eOldZoomType;
632 const Fraction& rOldY = GetViewData()->GetZoomY(); // Y wird angezeigt
633 sal_uInt16 nOldZoom = (sal_uInt16)(( rOldY.GetNumerator() * 100 )
634 / rOldY.GetDenominator());
635 sal_uInt16 nZoom = nOldZoom;
636 bool bCancel = false;
638 if ( pReqArgs )
640 const SvxZoomItem& rZoomItem = (const SvxZoomItem&)
641 pReqArgs->Get(SID_ATTR_ZOOM);
643 eNewZoomType = rZoomItem.GetType();
644 nZoom = rZoomItem.GetValue();
646 else
648 SfxItemSet aSet ( GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM );
649 SvxZoomItem aZoomItem( eOldZoomType, nOldZoom, SID_ATTR_ZOOM );
650 boost::scoped_ptr<AbstractSvxZoomDialog> pDlg;
651 ScMarkData& rMark = GetViewData()->GetMarkData();
652 sal_uInt16 nBtnFlags = SVX_ZOOM_ENABLE_50
653 | SVX_ZOOM_ENABLE_75
654 | SVX_ZOOM_ENABLE_100
655 | SVX_ZOOM_ENABLE_150
656 | SVX_ZOOM_ENABLE_200
657 | SVX_ZOOM_ENABLE_WHOLEPAGE
658 | SVX_ZOOM_ENABLE_PAGEWIDTH;
660 if ( rMark.IsMarked() || rMark.IsMultiMarked() )
661 nBtnFlags = nBtnFlags | SVX_ZOOM_ENABLE_OPTIMAL;
663 aZoomItem.SetValueSet( nBtnFlags );
664 aSet.Put( aZoomItem );
665 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
666 if(pFact)
668 pDlg.reset(pFact->CreateSvxZoomDialog(GetDialogParent(), aSet ));
669 OSL_ENSURE(pDlg, "Dialogdiet fail!");
671 if (pDlg)
673 pDlg->SetLimits( MINZOOM, MAXZOOM );
675 bCancel = ( RET_CANCEL == pDlg->Execute() );
677 // bCancel is True only if we were in the previous if block,
678 // so no need to check again pDlg
679 if ( !bCancel )
681 const SvxZoomItem& rZoomItem = (const SvxZoomItem&)
682 pDlg->GetOutputItemSet()->
683 Get( SID_ATTR_ZOOM );
685 eNewZoomType = rZoomItem.GetType();
686 nZoom = rZoomItem.GetValue();
691 if ( !bCancel )
693 if ( eNewZoomType == SVX_ZOOM_PERCENT )
695 if ( nZoom < MINZOOM ) nZoom = MINZOOM;
696 if ( nZoom > MAXZOOM ) nZoom = MAXZOOM;
698 else
700 nZoom = CalcZoom( eNewZoomType, nOldZoom );
701 bCancel = nZoom == 0;
704 switch ( eNewZoomType )
706 case SVX_ZOOM_WHOLEPAGE:
707 case SVX_ZOOM_PAGEWIDTH:
708 SetZoomType( eNewZoomType, bSyncZoom );
709 break;
711 default:
712 SetZoomType( SVX_ZOOM_PERCENT, bSyncZoom );
716 if ( nZoom != nOldZoom && !bCancel )
718 if (!GetViewData()->IsPagebreakMode())
720 ScAppOptions aNewOpt = pScMod->GetAppOptions();
721 aNewOpt.SetZoom( nZoom );
722 aNewOpt.SetZoomType( GetZoomType() );
723 pScMod->SetAppOptions( aNewOpt );
725 Fraction aFract( nZoom, 100 );
726 SetZoom( aFract, aFract, bSyncZoom );
727 PaintGrid();
728 PaintTop();
729 PaintLeft();
730 rBindings.Invalidate( SID_ATTR_ZOOM );
731 rReq.AppendItem( SvxZoomItem( GetZoomType(), nZoom, nSlot ) );
732 rReq.Done();
735 break;
737 case SID_ATTR_ZOOMSLIDER:
739 const SfxPoolItem* pItem = NULL;
740 bool bSyncZoom = SC_MOD()->GetAppOptions().GetSynchronizeZoom();
741 if ( pReqArgs && pReqArgs->GetItemState(SID_ATTR_ZOOMSLIDER, true, &pItem) == SFX_ITEM_SET )
743 const sal_uInt16 nCurrentZoom = ((const SvxZoomSliderItem *)pItem)->GetValue();
744 if( nCurrentZoom )
746 SetZoomType( SVX_ZOOM_PERCENT, bSyncZoom );
747 if (!GetViewData()->IsPagebreakMode())
749 ScAppOptions aNewOpt = pScMod->GetAppOptions();
750 aNewOpt.SetZoom( nCurrentZoom );
751 aNewOpt.SetZoomType( GetZoomType() );
752 pScMod->SetAppOptions( aNewOpt );
754 Fraction aFract( nCurrentZoom,100 );
755 SetZoom( aFract, aFract, bSyncZoom );
756 PaintGrid();
757 PaintTop();
758 PaintLeft();
759 rBindings.Invalidate( SID_ATTR_ZOOMSLIDER );
760 rReq.Done();
764 break;
766 case FID_TAB_SELECTALL:
767 SelectAllTables();
768 rReq.Done();
769 break;
771 case FID_TAB_DESELECTALL:
772 DeselectAllTables();
773 rReq.Done();
774 break;
776 case SID_SELECT_TABLES:
778 ScViewData& rViewData = *GetViewData();
779 ScDocument& rDoc = *rViewData.GetDocument();
780 ScMarkData& rMark = rViewData.GetMarkData();
781 SCTAB nTabCount = rDoc.GetTableCount();
782 SCTAB nTab;
784 ::std::vector < sal_Int32 > aIndexList;
785 SFX_REQUEST_ARG( rReq, pItem, SfxIntegerListItem, SID_SELECT_TABLES, false );
786 if ( pItem )
787 pItem->GetList( aIndexList );
788 else
790 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
791 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
793 boost::scoped_ptr<AbstractScShowTabDlg> pDlg(pFact->CreateScShowTabDlg(GetDialogParent()));
794 OSL_ENSURE(pDlg, "Dialog create fail!");
795 pDlg->SetDescription(
796 OUString( ScResId( STR_DLG_SELECTTABLES_TITLE ) ),
797 OUString( ScResId( STR_DLG_SELECTTABLES_LBNAME ) ),
798 GetStaticInterface()->GetSlot(SID_SELECT_TABLES)->GetCommand(), HID_SELECTTABLES );
800 // fill all table names with selection state
801 OUString aTabName;
802 for( nTab = 0; nTab < nTabCount; ++nTab )
804 rDoc.GetName( nTab, aTabName );
805 pDlg->Insert( aTabName, rMark.GetTableSelect( nTab ) );
808 if( pDlg->Execute() == RET_OK )
810 sal_uInt16 nSelCount = pDlg->GetSelectEntryCount();
811 sal_uInt16 nSelIx;
812 for( nSelIx = 0; nSelIx < nSelCount; ++nSelIx )
813 aIndexList.insert( aIndexList.begin()+nSelIx, pDlg->GetSelectEntryPos( nSelIx ) );
814 pDlg.reset();
815 rReq.AppendItem( SfxIntegerListItem( SID_SELECT_TABLES, aIndexList ) );
817 else
818 rReq.Ignore();
821 if ( !aIndexList.empty() )
823 sal_uInt16 nSelCount = aIndexList.size();
824 sal_uInt16 nSelIx;
825 SCTAB nFirstVisTab = 0;
827 // special case: only hidden tables selected -> do nothing
828 bool bVisSelected = false;
829 for( nSelIx = 0; !bVisSelected && (nSelIx < nSelCount); ++nSelIx )
830 bVisSelected = rDoc.IsVisible( nFirstVisTab = static_cast<SCTAB>(aIndexList[nSelIx]) );
831 if( !bVisSelected )
832 nSelCount = 0;
834 // select the tables
835 if( nSelCount )
837 for( nTab = 0; nTab < nTabCount; ++nTab )
838 rMark.SelectTable( nTab, false );
840 for( nSelIx = 0; nSelIx < nSelCount; ++nSelIx )
841 rMark.SelectTable( static_cast<SCTAB>(aIndexList[nSelIx]), true );
843 // activate another table, if current is deselected
844 if( !rMark.GetTableSelect( rViewData.GetTabNo() ) )
846 rMark.SelectTable( nFirstVisTab, true );
847 SetTabNo( nFirstVisTab );
850 rViewData.GetDocShell()->PostPaintExtras();
851 SfxBindings& rBind = rViewData.GetBindings();
852 rBind.Invalidate( FID_FILL_TAB );
853 rBind.Invalidate( FID_TAB_DESELECTALL );
856 rReq.Done();
859 break;
862 case SID_OUTLINE_DELETEALL:
863 RemoveAllOutlines();
864 rReq.Done();
865 break;
867 case SID_AUTO_OUTLINE:
868 AutoOutline();
869 rReq.Done();
870 break;
873 case SID_WINDOW_SPLIT:
875 ScSplitMode eHSplit = GetViewData()->GetHSplitMode();
876 ScSplitMode eVSplit = GetViewData()->GetVSplitMode();
877 if ( eHSplit == SC_SPLIT_NORMAL || eVSplit == SC_SPLIT_NORMAL ) // aufheben
878 RemoveSplit();
879 else if ( eHSplit == SC_SPLIT_FIX || eVSplit == SC_SPLIT_FIX ) // normal
880 FreezeSplitters( false );
881 else // erzeugen
882 SplitAtCursor();
883 rReq.Done();
885 InvalidateSplit();
887 break;
889 case SID_WINDOW_FIX:
891 ScSplitMode eHSplit = GetViewData()->GetHSplitMode();
892 ScSplitMode eVSplit = GetViewData()->GetVSplitMode();
893 if ( eHSplit == SC_SPLIT_FIX || eVSplit == SC_SPLIT_FIX ) // aufheben
894 RemoveSplit();
895 else
896 FreezeSplitters( true ); // erzeugen oder fixieren
897 rReq.Done();
899 InvalidateSplit();
901 break;
903 case FID_CHG_SHOW:
905 sal_uInt16 nId = ScHighlightChgDlgWrapper::GetChildWindowId();
906 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
908 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
910 break;
912 case FID_CHG_ACCEPT:
914 pThisFrame->ToggleChildWindow(ScAcceptChgDlgWrapper::GetChildWindowId());
915 GetViewFrame()->GetBindings().Invalidate(FID_CHG_ACCEPT);
916 rReq.Done ();
919 sal_uInt16 nId = ScAcceptChgDlgWrapper::GetChildWindowId();
920 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
922 pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True );
925 break;
927 case FID_CHG_COMMENT:
929 ScViewData* pData = GetViewData();
930 ScAddress aCursorPos( pData->GetCurX(), pData->GetCurY(), pData->GetTabNo() );
931 ScDocShell* pDocSh = pData->GetDocShell();
933 ScChangeAction* pAction = pDocSh->GetChangeAction( aCursorPos );
934 if ( pAction )
936 const SfxPoolItem* pItem;
937 if ( pReqArgs &&
938 pReqArgs->GetItemState( nSlot, true, &pItem ) == SFX_ITEM_SET &&
939 pItem->ISA( SfxStringItem ) )
941 OUString aComment = ((const SfxStringItem*)pItem)->GetValue();
942 pDocSh->SetChangeComment( pAction, aComment );
943 rReq.Done();
945 else
947 pDocSh->ExecuteChangeCommentDialog( pAction, GetDialogParent() );
948 rReq.Done();
952 break;
954 case SID_CREATE_SW_DRAWVIEW:
955 // wird von den Forms gerufen, wenn die DrawView mit allem Zubehoer
956 // angelegt werden muss
957 if (!GetScDrawView())
959 GetViewData()->GetDocShell()->MakeDrawLayer();
960 rBindings.InvalidateAll(false);
962 break;
964 case FID_PROTECT_DOC:
966 ScDocument* pDoc = GetViewData()->GetDocument();
968 if( pReqArgs )
970 const SfxPoolItem* pItem;
971 if( pReqArgs->HasItem( FID_PROTECT_DOC, &pItem ) &&
972 ((const SfxBoolItem*)pItem)->GetValue() == pDoc->IsDocProtected() )
974 rReq.Ignore();
975 break;
979 ScDocProtection* pProtect = pDoc->GetDocProtection();
980 if (pProtect && pProtect->isProtected())
982 bool bCancel = false;
983 OUString aPassword;
985 if (pProtect->isProtectedWithPass())
987 OUString aText(ScResId(SCSTR_PASSWORD));
989 boost::scoped_ptr<SfxPasswordDialog> pDlg(new SfxPasswordDialog(GetDialogParent(), &aText));
990 pDlg->SetText( ScResId(SCSTR_UNPROTECTDOC) );
991 pDlg->SetMinLen( 0 );
992 pDlg->SetHelpId( GetStaticInterface()->GetSlot(FID_PROTECT_DOC)->GetCommand() );
993 pDlg->SetEditHelpId( HID_PASSWD_DOC );
995 if (pDlg->Execute() == RET_OK)
996 aPassword = pDlg->GetPassword();
997 else
998 bCancel = true;
1000 if (!bCancel)
1002 Unprotect( TABLEID_DOC, aPassword );
1003 rReq.AppendItem( SfxBoolItem( FID_PROTECT_DOC, false ) );
1004 rReq.Done();
1007 else
1009 OUString aText(ScResId(SCSTR_PASSWORDOPT));
1011 boost::scoped_ptr<SfxPasswordDialog> pDlg(new SfxPasswordDialog(GetDialogParent(), &aText));
1012 pDlg->SetText( ScResId(SCSTR_PROTECTDOC) );
1013 pDlg->SetMinLen( 0 );
1014 pDlg->SetHelpId( GetStaticInterface()->GetSlot(FID_PROTECT_DOC)->GetCommand() );
1015 pDlg->SetEditHelpId( HID_PASSWD_DOC );
1016 pDlg->ShowExtras( SHOWEXTRAS_CONFIRM );
1018 if (pDlg->Execute() == RET_OK)
1020 OUString aPassword = pDlg->GetPassword();
1021 Protect( TABLEID_DOC, aPassword );
1022 rReq.AppendItem( SfxBoolItem( FID_PROTECT_DOC, true ) );
1023 rReq.Done();
1026 rBindings.Invalidate( FID_PROTECT_DOC );
1028 break;
1031 case FID_PROTECT_TABLE:
1033 ScDocument* pDoc = GetViewData()->GetDocument();
1034 SCTAB nTab = GetViewData()->GetTabNo();
1035 bool bOldProtection = pDoc->IsTabProtected(nTab);
1037 if( pReqArgs )
1039 const SfxPoolItem* pItem;
1040 bool bNewProtection = !bOldProtection;
1041 if( pReqArgs->HasItem( FID_PROTECT_TABLE, &pItem ) )
1042 bNewProtection = ((const SfxBoolItem*)pItem)->GetValue();
1043 if( bNewProtection == bOldProtection )
1045 rReq.Ignore();
1046 break;
1050 if (bOldProtection)
1052 // Unprotect a protected sheet.
1054 ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
1055 if (pProtect && pProtect->isProtectedWithPass())
1057 OUString aText( ScResId(SCSTR_PASSWORDOPT) );
1058 boost::scoped_ptr<SfxPasswordDialog> pDlg(new SfxPasswordDialog(GetDialogParent(), &aText));
1059 pDlg->SetText( ScResId(SCSTR_UNPROTECTTAB) );
1060 pDlg->SetMinLen( 0 );
1061 pDlg->SetHelpId( GetStaticInterface()->GetSlot(FID_PROTECT_TABLE)->GetCommand() );
1062 pDlg->SetEditHelpId( HID_PASSWD_TABLE );
1064 if (pDlg->Execute() == RET_OK)
1066 OUString aPassword = pDlg->GetPassword();
1067 Unprotect(nTab, aPassword);
1070 else
1071 // this sheet is not password-protected.
1072 Unprotect(nTab, OUString());
1074 if (!pReqArgs)
1076 rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, false) );
1077 rReq.Done();
1080 else
1082 // Protect a current sheet.
1084 boost::scoped_ptr<ScTableProtectionDlg> pDlg(new ScTableProtectionDlg(GetDialogParent()));
1086 ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
1087 if (pProtect)
1088 pDlg->SetDialogData(*pProtect);
1090 if (pDlg->Execute() == RET_OK)
1092 pScMod->InputEnterHandler();
1094 ScTableProtection aNewProtect;
1095 pDlg->WriteData(aNewProtect);
1096 ProtectSheet(nTab, aNewProtect);
1097 if (!pReqArgs)
1099 rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, true) );
1100 rReq.Done();
1104 TabChanged();
1105 UpdateInputHandler(true); // damit sofort wieder eingegeben werden kann
1106 SelectionChanged();
1108 break;
1110 case SID_OPT_LOCALE_CHANGED :
1111 { // locale changed, SYSTEM number formats changed => repaint cell contents
1112 PaintGrid();
1113 rReq.Done();
1115 break;
1117 default:
1118 OSL_FAIL("Unbekannter Slot bei ScTabViewShell::Execute");
1119 break;
1123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */