fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / view / tabvwsh3.cxx
blob88b2fc6fb9e9d242599b7fc4d5a33be10e28b78b
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 <sfx2/sidebar/Sidebar.hxx>
29 #include <svl/ptitem.hxx>
30 #include <svl/stritem.hxx>
31 #include <tools/urlobj.hxx>
32 #include <sfx2/objface.hxx>
33 #include <vcl/msgbox.hxx>
34 #include <vcl/vclenum.hxx>
36 #include "globstr.hrc"
37 #include "scmod.hxx"
38 #include "appoptio.hxx"
39 #include "tabvwsh.hxx"
40 #include "document.hxx"
41 #include "sc.hrc"
42 #include "inputwin.hxx"
43 #include "scresid.hxx"
44 #include "printfun.hxx"
45 #include "docsh.hxx"
46 #include "rangelst.hxx"
47 #include "prevwsh.hxx"
48 #include "rangeutl.hxx"
49 #include "reffact.hxx"
50 #include "uiitems.hxx"
51 #include "formulacell.hxx"
52 #include "inputhdl.hxx"
53 #include "autoform.hxx"
54 #include "autofmt.hxx"
55 #include "dwfunctr.hxx"
56 #include "shtabdlg.hxx"
57 #include "tabprotection.hxx"
58 #include "protectiondlg.hxx"
59 #include "markdata.hxx"
61 #include <svl/ilstitem.hxx>
62 #include <vector>
64 #include <svx/zoomslideritem.hxx>
65 #include <svx/svxdlg.hxx>
66 #include <svx/dialogs.hrc>
67 #include <comphelper/string.hxx>
68 #include "scabstdlg.hxx"
70 #include <boost/scoped_ptr.hpp>
72 /** Try to parse the given range using Calc-style syntax first, then
73 Excel-style if that fails. */
74 static sal_uInt16 lcl_ParseRange(ScRange& rScRange, const OUString& aAddress, ScDocument* pDoc, sal_uInt16 /* nSlot */)
76 sal_uInt16 nResult = rScRange.Parse(aAddress, pDoc);
77 if ( (nResult & SCA_VALID) )
78 return nResult;
80 return rScRange.Parse(aAddress, pDoc, ScAddress::Details(formula::FormulaGrammar::CONV_XL_A1, 0, 0));
83 /** Try to parse the given address using Calc-style syntax first, then
84 Excel-style if that fails. */
85 static sal_uInt16 lcl_ParseAddress(ScAddress& rScAddress, const OUString& aAddress, ScDocument* pDoc, sal_uInt16 /* nSlot */)
87 sal_uInt16 nResult = rScAddress.Parse(aAddress, pDoc);
88 if ( (nResult & SCA_VALID) )
89 return nResult;
91 return rScAddress.Parse(aAddress, pDoc, ScAddress::Details(formula::FormulaGrammar::CONV_XL_A1, 0, 0));
94 void ScTabViewShell::Execute( SfxRequest& rReq )
96 SfxViewFrame* pThisFrame = GetViewFrame();
97 SfxBindings& rBindings = pThisFrame->GetBindings();
98 ScModule* pScMod = SC_MOD();
99 const SfxItemSet* pReqArgs = rReq.GetArgs();
100 sal_uInt16 nSlot = rReq.GetSlot();
102 if (nSlot != SID_CURRENTCELL) // der kommt beim MouseButtonUp
103 HideListBox(); // Autofilter-DropDown-Listbox
105 switch ( nSlot )
107 case FID_INSERT_FILE:
109 const SfxPoolItem* pItem;
110 if ( pReqArgs &&
111 pReqArgs->GetItemState(FID_INSERT_FILE,true,&pItem) == SfxItemState::SET )
113 OUString aFileName = static_cast<const SfxStringItem*>(pItem)->GetValue();
115 // Einfuege-Position
117 Point aInsertPos;
118 if ( pReqArgs->GetItemState(FN_PARAM_1,true,&pItem) == SfxItemState::SET )
119 aInsertPos = static_cast<const SfxPointItem*>(pItem)->GetValue();
120 else
121 aInsertPos = GetInsertPos();
123 // als Link?
125 bool bAsLink = false;
126 if ( pReqArgs->GetItemState(FN_PARAM_2,true,&pItem) == SfxItemState::SET )
127 bAsLink = static_cast<const SfxBoolItem*>(pItem)->GetValue();
129 // ausfuehren
131 PasteFile( aInsertPos, aFileName, bAsLink );
134 break;
136 case SID_OPENDLG_EDIT_PRINTAREA:
138 sal_uInt16 nId = ScPrintAreasDlgWrapper::GetChildWindowId();
139 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
141 pScMod->SetRefDialog( nId, pWnd == nullptr );
143 break;
145 case SID_CHANGE_PRINTAREA:
147 if ( pReqArgs ) // OK aus Dialog
149 OUString aPrintStr;
150 OUString aRowStr;
151 OUString aColStr;
152 bool bEntire = false;
153 const SfxPoolItem* pItem;
154 if ( pReqArgs->GetItemState( SID_CHANGE_PRINTAREA, true, &pItem ) == SfxItemState::SET )
155 aPrintStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
156 if ( pReqArgs->GetItemState( FN_PARAM_2, true, &pItem ) == SfxItemState::SET )
157 aRowStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
158 if ( pReqArgs->GetItemState( FN_PARAM_3, true, &pItem ) == SfxItemState::SET )
159 aColStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
160 if ( pReqArgs->GetItemState( FN_PARAM_4, true, &pItem ) == SfxItemState::SET )
161 bEntire = static_cast<const SfxBoolItem*>(pItem)->GetValue();
163 SetPrintRanges( bEntire, &aPrintStr, &aColStr, &aRowStr, false );
165 rReq.Done();
168 break;
170 case SID_ADD_PRINTAREA:
171 case SID_DEFINE_PRINTAREA: // Menue oder Basic
173 bool bAdd = ( nSlot == SID_ADD_PRINTAREA );
174 if ( pReqArgs )
176 OUString aPrintStr;
177 const SfxPoolItem* pItem;
178 if ( pReqArgs->GetItemState( SID_DEFINE_PRINTAREA, true, &pItem ) == SfxItemState::SET )
179 aPrintStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
180 SetPrintRanges( false, &aPrintStr, NULL, NULL, bAdd );
182 else
184 SetPrintRanges( false, NULL, NULL, NULL, bAdd ); // aus Selektion
185 rReq.Done();
188 break;
190 case SID_DELETE_PRINTAREA:
192 // Clear currently defined print range if any, and reset it to
193 // print entire sheet which is the default.
194 OUString aEmpty;
195 SetPrintRanges(true, &aEmpty, NULL, NULL, false);
196 rReq.Done();
198 break;
200 case FID_DEL_MANUALBREAKS:
201 RemoveManualBreaks();
202 rReq.Done();
203 break;
205 case FID_ADJUST_PRINTZOOM:
206 AdjustPrintZoom();
207 rReq.Done();
208 break;
210 case FID_RESET_PRINTZOOM:
211 SetPrintZoom( 100, 0 ); // 100%, nicht auf Seiten
212 rReq.Done();
213 break;
215 case SID_FORMATPAGE:
216 case SID_STATUS_PAGESTYLE:
217 case SID_HFEDIT:
218 GetViewData().GetDocShell()->
219 ExecutePageStyle( *this, rReq, GetViewData().GetTabNo() );
220 break;
222 case SID_JUMPTOMARK:
223 case SID_CURRENTCELL:
224 if ( pReqArgs )
226 OUString aAddress;
227 const SfxPoolItem* pItem;
228 if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET )
229 aAddress = static_cast<const SfxStringItem*>(pItem)->GetValue();
230 else if ( nSlot == SID_JUMPTOMARK && pReqArgs->GetItemState(
231 SID_JUMPTOMARK, true, &pItem ) == SfxItemState::SET )
232 aAddress = static_cast<const SfxStringItem*>(pItem)->GetValue();
234 // #i14927# SID_CURRENTCELL with a single cell must unmark if FN_PARAM_1
235 // isn't set (for recorded macros, because IsAPI is no longer available).
236 // ScGridWindow::MouseButtonUp no longer executes the slot for a single
237 // cell if there is a multi selection.
238 bool bUnmark = ( nSlot == SID_CURRENTCELL );
239 if ( pReqArgs->GetItemState( FN_PARAM_1, true, &pItem ) == SfxItemState::SET )
240 bUnmark = static_cast<const SfxBoolItem*>(pItem)->GetValue();
242 bool bAlignToCursor = true;
243 if (pReqArgs->GetItemState(FN_PARAM_2, true, &pItem) == SfxItemState::SET)
244 bAlignToCursor = static_cast<const SfxBoolItem*>(pItem)->GetValue();
246 if ( nSlot == SID_JUMPTOMARK )
248 // URL has to be decoded for escaped characters (%20)
249 aAddress = INetURLObject::decode( aAddress,
250 INetURLObject::DECODE_WITH_CHARSET,
251 RTL_TEXTENCODING_UTF8 );
254 bool bFound = false;
255 ScViewData& rViewData = GetViewData();
256 ScDocument* pDoc = rViewData.GetDocument();
257 ScMarkData& rMark = rViewData.GetMarkData();
258 ScRange aScRange;
259 ScAddress aScAddress;
260 sal_uInt16 nResult = lcl_ParseRange(aScRange, aAddress, pDoc, nSlot);
261 SCTAB nTab = rViewData.GetTabNo();
262 bool bMark = true;
264 // Is this a range ?
265 if( nResult & SCA_VALID )
267 if ( nResult & SCA_TAB_3D )
269 if( aScRange.aStart.Tab() != nTab )
270 SetTabNo( nTab = aScRange.aStart.Tab() );
272 else
274 aScRange.aStart.SetTab( nTab );
275 aScRange.aEnd.SetTab( nTab );
278 // Is this a cell ?
279 else if ( (nResult = lcl_ParseAddress(aScAddress, aAddress, pDoc, nSlot)) & SCA_VALID )
281 if ( nResult & SCA_TAB_3D )
283 if( aScAddress.Tab() != nTab )
284 SetTabNo( nTab = aScAddress.Tab() );
286 else
287 aScAddress.SetTab( nTab );
289 aScRange = ScRange( aScAddress, aScAddress );
290 // Zellen sollen nicht markiert werden
291 bMark = false;
293 // Ist es benahmster Bereich (erst Namen dann DBBereiche) ?
294 else
296 ScRangeUtil aRangeUtil;
297 formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
298 if( ScRangeUtil::MakeRangeFromName( aAddress, pDoc, nTab, aScRange, RUTL_NAMES, eConv ) ||
299 ScRangeUtil::MakeRangeFromName( aAddress, pDoc, nTab, aScRange, RUTL_DBASE, eConv ) )
301 nResult |= SCA_VALID;
302 if( aScRange.aStart.Tab() != nTab )
303 SetTabNo( nTab = aScRange.aStart.Tab() );
307 if ( !(nResult & SCA_VALID) && comphelper::string::isdigitAsciiString(aAddress) )
309 sal_Int32 nNumeric = aAddress.toInt32();
310 if ( nNumeric > 0 && nNumeric <= MAXROW+1 )
312 // 1-basierte Zeilennummer
314 aScAddress.SetRow( (SCROW)(nNumeric - 1) );
315 aScAddress.SetCol( rViewData.GetCurX() );
316 aScAddress.SetTab( nTab );
317 aScRange = ScRange( aScAddress, aScAddress );
318 bMark = false;
319 nResult = SCA_VALID;
323 if ( !ValidRow(aScRange.aStart.Row()) || !ValidRow(aScRange.aEnd.Row()) )
324 nResult = 0;
326 // wir haben was gefunden
327 if( nResult & SCA_VALID )
329 bFound = true;
330 SCCOL nCol = aScRange.aStart.Col();
331 SCROW nRow = aScRange.aStart.Row();
332 bool bNothing = ( rViewData.GetCurX()==nCol && rViewData.GetCurY()==nRow );
334 // markieren
335 if( bMark )
337 if (rMark.IsMarked()) // ist derselbe Bereich schon markiert?
339 ScRange aOldMark;
340 rMark.GetMarkArea( aOldMark );
341 aOldMark.Justify();
342 ScRange aCurrent = aScRange;
343 aCurrent.Justify();
344 bNothing = ( aCurrent == aOldMark );
346 else
347 bNothing = false;
349 if (!bNothing)
350 MarkRange( aScRange, false ); // Cursor kommt hinterher...
352 else
354 // remove old selection, unless bUnmark argument is sal_False (from navigator)
355 if( bUnmark )
357 MoveCursorAbs( nCol, nRow,
358 SC_FOLLOW_NONE, false, false );
362 // und Cursor setzen
364 // zusammengefasste Zellen beruecksichtigen:
365 pDoc->SkipOverlapped(nCol, nRow, nTab);
367 // Navigator-Aufrufe sind nicht API!!!
369 if( bNothing )
371 if (rReq.IsAPI())
372 rReq.Ignore(); // wenn Makro, dann gar nix
373 else
374 rReq.Done(); // sonst wenigstens aufzeichnen
376 else
378 rViewData.ResetOldCursor();
379 SetCursor( nCol, nRow );
380 rBindings.Invalidate( SID_CURRENTCELL );
381 rBindings.Update( nSlot );
383 if (!rReq.IsAPI())
384 rReq.Done();
387 if (bAlignToCursor)
389 // align to cursor even if the cursor position hasn't changed,
390 // because the cursor may be set outside the visible area.
391 AlignToCursor( nCol, nRow, SC_FOLLOW_JUMP );
394 rReq.SetReturnValue( SfxStringItem( SID_CURRENTCELL, aAddress ) );
397 if (!bFound) // kein gueltiger Bereich
399 // wenn es ein Tabellenname ist, umschalten (fuer Navigator/URL's)
401 SCTAB nNameTab;
402 if ( pDoc->GetTable( aAddress, nNameTab ) )
404 bFound = true;
405 if ( nNameTab != nTab )
406 SetTabNo( nNameTab );
410 if ( !bFound && nSlot == SID_JUMPTOMARK )
412 // Grafik-Objekte probieren (nur bei URL's)
414 bFound = SelectObject( aAddress );
417 if (!bFound && !rReq.IsAPI())
418 ErrorMessage( STR_ERR_INVALID_AREA );
420 break;
422 case SID_CURRENTOBJECT:
423 if ( pReqArgs )
425 OUString aName = static_cast<const SfxStringItem&>(pReqArgs->Get(nSlot)).GetValue();
426 SelectObject( aName );
428 break;
430 case SID_CURRENTTAB:
431 if ( pReqArgs )
433 // Tabelle fuer Basic ist 1-basiert
434 SCTAB nTab = static_cast<const SfxUInt16Item&>(pReqArgs->Get(nSlot)).GetValue() - 1;
435 ScDocument* pDoc = GetViewData().GetDocument();
436 if ( nTab < pDoc->GetTableCount() )
438 SetTabNo( nTab );
439 rBindings.Update( nSlot );
441 if( ! rReq.IsAPI() )
442 rReq.Done();
444 //! sonst Fehler ?
446 break;
448 case SID_CURRENTDOC:
449 if ( pReqArgs )
451 OUString aStrDocName( static_cast<const SfxStringItem&>(pReqArgs->
452 Get(nSlot)).GetValue() );
454 SfxViewFrame* pViewFrame = NULL;
455 ScDocShell* pDocSh = static_cast<ScDocShell*>(SfxObjectShell::GetFirst());
456 bool bFound = false;
458 // zu aktivierenden ViewFrame suchen
460 while ( pDocSh && !bFound )
462 if ( pDocSh->GetTitle() == aStrDocName )
464 pViewFrame = SfxViewFrame::GetFirst( pDocSh );
465 bFound = ( NULL != pViewFrame );
468 pDocSh = static_cast<ScDocShell*>(SfxObjectShell::GetNext( *pDocSh ));
471 if ( bFound )
472 pViewFrame->GetFrame().Appear();
474 rReq.Ignore();//XXX wird von SFX erledigt
477 case SID_PRINTPREVIEW:
479 if ( !pThisFrame->GetFrame().IsInPlace() ) // nicht bei OLE
481 // print preview is now always in the same frame as the tab view
482 // -> always switch this frame back to normal view
483 // (ScPreviewShell ctor reads view data)
485 // #102785#; finish input
486 pScMod->InputEnterHandler();
488 pThisFrame->GetDispatcher()->Execute( SID_VIEWSHELL1, SfxCallMode::ASYNCHRON );
490 // else Fehler (z.B. Ole)
492 break;
494 case SID_DETECTIVE_DEL_ALL:
495 DetectiveDelAll();
496 rReq.Done();
497 break;
499 // SID_TABLE_ACTIVATE und SID_MARKAREA werden von Basic aus an der versteckten
500 // View aufgerufen, um auf der sichtbaren View zu markieren/umzuschalten:
502 case SID_TABLE_ACTIVATE:
503 OSL_FAIL("old slot SID_TABLE_ACTIVATE");
504 break;
506 case SID_REPAINT:
507 PaintGrid();
508 PaintTop();
509 PaintLeft();
510 PaintExtras();
511 rReq.Done();
512 break;
514 case FID_NORMALVIEWMODE:
515 case FID_PAGEBREAKMODE:
517 bool bWantPageBreak = nSlot == FID_PAGEBREAKMODE;
519 // check whether there is an explicit argument, use it
520 const SfxPoolItem* pItem;
521 if ( pReqArgs && pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET )
523 bool bItemValue = static_cast<const SfxBoolItem*>(pItem)->GetValue();
524 bWantPageBreak = (nSlot == FID_PAGEBREAKMODE) == bItemValue;
527 if( GetViewData().IsPagebreakMode() != bWantPageBreak )
529 SetPagebreakMode( bWantPageBreak );
530 UpdatePageBreakData();
531 SetCurSubShell( GetCurObjectSelectionType(), true );
532 PaintGrid();
533 PaintTop();
534 PaintLeft();
535 rBindings.Invalidate( nSlot );
536 rReq.AppendItem( SfxBoolItem( nSlot, true ) );
537 rReq.Done();
540 break;
542 case FID_FUNCTION_BOX:
544 // First make sure that the sidebar is visible
545 pThisFrame->ShowChildWindow(SID_SIDEBAR);
547 ::sfx2::sidebar::Sidebar::ShowPanel("FunctionsPanel",
548 pThisFrame->GetFrame().GetFrameInterface());
549 rReq.Done ();
551 break;
553 case FID_TOGGLESYNTAX:
555 bool bSet = !GetViewData().IsSyntaxMode();
556 const SfxPoolItem* pItem;
557 if ( pReqArgs && pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET )
558 bSet = static_cast<const SfxBoolItem*>(pItem)->GetValue();
559 GetViewData().SetSyntaxMode( bSet );
560 PaintGrid();
561 rBindings.Invalidate( FID_TOGGLESYNTAX );
562 rReq.AppendItem( SfxBoolItem( nSlot, bSet ) );
563 rReq.Done();
565 break;
566 case FID_TOGGLEHEADERS:
568 bool bSet = !GetViewData().IsHeaderMode();
569 const SfxPoolItem* pItem;
570 if ( pReqArgs && pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET )
571 bSet = static_cast<const SfxBoolItem*>(pItem)->GetValue();
572 GetViewData().SetHeaderMode( bSet );
573 RepeatResize();
574 rBindings.Invalidate( FID_TOGGLEHEADERS );
575 rReq.AppendItem( SfxBoolItem( nSlot, bSet ) );
576 rReq.Done();
578 break;
580 case FID_TOGGLEFORMULA:
582 ScViewData& rViewData = GetViewData();
583 const ScViewOptions& rOpts = rViewData.GetOptions();
584 bool bFormulaMode = !rOpts.GetOption( VOPT_FORMULAS );
585 const SfxPoolItem *pItem;
586 if( pReqArgs && pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET )
587 bFormulaMode = static_cast<const SfxBoolItem *>(pItem)->GetValue();
589 ScViewOptions rSetOpts = ScViewOptions( rOpts );
590 rSetOpts.SetOption( VOPT_FORMULAS, bFormulaMode );
591 rViewData.SetOptions( rSetOpts );
593 rViewData.GetDocShell()->PostPaintGridAll();
595 rBindings.Invalidate( FID_TOGGLEFORMULA );
596 rReq.AppendItem( SfxBoolItem( nSlot, bFormulaMode ) );
597 rReq.Done();
599 break;
601 case FID_TOGGLEINPUTLINE:
603 sal_uInt16 nId = ScInputWindowWrapper::GetChildWindowId();
604 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
605 bool bSet = ( pWnd == NULL );
606 const SfxPoolItem* pItem;
607 if ( pReqArgs && pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET )
608 bSet = static_cast<const SfxBoolItem*>(pItem)->GetValue();
610 pThisFrame->SetChildWindow( nId, bSet );
611 rBindings.Invalidate( FID_TOGGLEINPUTLINE );
612 rReq.AppendItem( SfxBoolItem( nSlot, bSet ) );
613 rReq.Done();
615 break;
617 case SID_ATTR_ZOOM: // Statuszeile
618 case FID_SCALE:
620 bool bSyncZoom = SC_MOD()->GetAppOptions().GetSynchronizeZoom();
621 SvxZoomType eOldZoomType = GetZoomType();
622 SvxZoomType eNewZoomType = eOldZoomType;
623 const Fraction& rOldY = GetViewData().GetZoomY(); // Y wird angezeigt
624 sal_uInt16 nOldZoom = (sal_uInt16)(( rOldY.GetNumerator() * 100 )
625 / rOldY.GetDenominator());
626 sal_uInt16 nZoom = nOldZoom;
627 bool bCancel = false;
629 if ( pReqArgs )
631 const SvxZoomItem& rZoomItem = static_cast<const SvxZoomItem&>(
632 pReqArgs->Get(SID_ATTR_ZOOM));
634 eNewZoomType = rZoomItem.GetType();
635 nZoom = rZoomItem.GetValue();
637 else
639 SfxItemSet aSet ( GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM );
640 SvxZoomItem aZoomItem( eOldZoomType, nOldZoom, SID_ATTR_ZOOM );
641 boost::scoped_ptr<AbstractSvxZoomDialog> pDlg;
642 ScMarkData& rMark = GetViewData().GetMarkData();
643 SvxZoomEnableFlags nBtnFlags = SvxZoomEnableFlags::N50
644 | SvxZoomEnableFlags::N75
645 | SvxZoomEnableFlags::N100
646 | SvxZoomEnableFlags::N150
647 | SvxZoomEnableFlags::N200
648 | SvxZoomEnableFlags::WHOLEPAGE
649 | SvxZoomEnableFlags::PAGEWIDTH;
651 if ( rMark.IsMarked() || rMark.IsMultiMarked() )
652 nBtnFlags = nBtnFlags | SvxZoomEnableFlags::OPTIMAL;
654 aZoomItem.SetValueSet( nBtnFlags );
655 aSet.Put( aZoomItem );
656 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
657 if(pFact)
659 pDlg.reset(pFact->CreateSvxZoomDialog(GetDialogParent(), aSet ));
660 OSL_ENSURE(pDlg, "Dialog creation failed!");
662 if (pDlg)
664 pDlg->SetLimits( MINZOOM, MAXZOOM );
666 bCancel = ( RET_CANCEL == pDlg->Execute() );
668 // bCancel is True only if we were in the previous if block,
669 // so no need to check again pDlg
670 if ( !bCancel )
672 const SvxZoomItem& rZoomItem = static_cast<const SvxZoomItem&>(
673 pDlg->GetOutputItemSet()->
674 Get( SID_ATTR_ZOOM ));
676 eNewZoomType = rZoomItem.GetType();
677 nZoom = rZoomItem.GetValue();
682 if ( !bCancel )
684 if ( eNewZoomType == SvxZoomType::PERCENT )
686 if ( nZoom < MINZOOM ) nZoom = MINZOOM;
687 if ( nZoom > MAXZOOM ) nZoom = MAXZOOM;
689 else
691 nZoom = CalcZoom( eNewZoomType, nOldZoom );
692 bCancel = nZoom == 0;
695 switch ( eNewZoomType )
697 case SvxZoomType::WHOLEPAGE:
698 case SvxZoomType::PAGEWIDTH:
699 SetZoomType( eNewZoomType, bSyncZoom );
700 break;
702 default:
703 SetZoomType( SvxZoomType::PERCENT, bSyncZoom );
707 if ( nZoom != nOldZoom && !bCancel )
709 if (!GetViewData().IsPagebreakMode())
711 ScAppOptions aNewOpt = pScMod->GetAppOptions();
712 aNewOpt.SetZoom( nZoom );
713 aNewOpt.SetZoomType( GetZoomType() );
714 pScMod->SetAppOptions( aNewOpt );
716 Fraction aFract( nZoom, 100 );
717 SetZoom( aFract, aFract, bSyncZoom );
718 PaintGrid();
719 PaintTop();
720 PaintLeft();
721 rBindings.Invalidate( SID_ATTR_ZOOM );
722 rReq.AppendItem( SvxZoomItem( GetZoomType(), nZoom, nSlot ) );
723 rReq.Done();
726 break;
728 case SID_ATTR_ZOOMSLIDER:
730 const SfxPoolItem* pItem = NULL;
731 bool bSyncZoom = SC_MOD()->GetAppOptions().GetSynchronizeZoom();
732 if ( pReqArgs && pReqArgs->GetItemState(SID_ATTR_ZOOMSLIDER, true, &pItem) == SfxItemState::SET )
734 const sal_uInt16 nCurrentZoom = static_cast<const SvxZoomSliderItem *>(pItem)->GetValue();
735 if( nCurrentZoom )
737 SetZoomType( SvxZoomType::PERCENT, bSyncZoom );
738 if (!GetViewData().IsPagebreakMode())
740 ScAppOptions aNewOpt = pScMod->GetAppOptions();
741 aNewOpt.SetZoom( nCurrentZoom );
742 aNewOpt.SetZoomType( GetZoomType() );
743 pScMod->SetAppOptions( aNewOpt );
745 Fraction aFract( nCurrentZoom,100 );
746 SetZoom( aFract, aFract, bSyncZoom );
747 PaintGrid();
748 PaintTop();
749 PaintLeft();
750 rBindings.Invalidate( SID_ATTR_ZOOMSLIDER );
751 rReq.Done();
755 break;
757 case FID_TAB_SELECTALL:
758 SelectAllTables();
759 rReq.Done();
760 break;
762 case FID_TAB_DESELECTALL:
763 DeselectAllTables();
764 rReq.Done();
765 break;
767 case SID_SELECT_TABLES:
769 ScViewData& rViewData = GetViewData();
770 ScDocument& rDoc = *rViewData.GetDocument();
771 ScMarkData& rMark = rViewData.GetMarkData();
772 SCTAB nTabCount = rDoc.GetTableCount();
773 SCTAB nTab;
775 ::std::vector < sal_Int32 > aIndexList;
776 SFX_REQUEST_ARG( rReq, pItem, SfxIntegerListItem, SID_SELECT_TABLES, false );
777 if ( pItem )
778 pItem->GetList( aIndexList );
779 else
781 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
782 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
784 boost::scoped_ptr<AbstractScShowTabDlg> pDlg(pFact->CreateScShowTabDlg(GetDialogParent()));
785 OSL_ENSURE(pDlg, "Dialog create fail!");
786 pDlg->SetDescription(
787 OUString( ScResId( STR_DLG_SELECTTABLES_TITLE ) ),
788 OUString( ScResId( STR_DLG_SELECTTABLES_LBNAME ) ),
789 GetStaticInterface()->GetSlot(SID_SELECT_TABLES)->GetCommand(), HID_SELECTTABLES );
791 // fill all table names with selection state
792 OUString aTabName;
793 for( nTab = 0; nTab < nTabCount; ++nTab )
795 rDoc.GetName( nTab, aTabName );
796 pDlg->Insert( aTabName, rMark.GetTableSelect( nTab ) );
799 if( pDlg->Execute() == RET_OK )
801 sal_uInt16 nSelCount = pDlg->GetSelectEntryCount();
802 sal_uInt16 nSelIx;
803 for( nSelIx = 0; nSelIx < nSelCount; ++nSelIx )
804 aIndexList.insert( aIndexList.begin()+nSelIx, pDlg->GetSelectEntryPos( nSelIx ) );
805 pDlg.reset();
806 rReq.AppendItem( SfxIntegerListItem( SID_SELECT_TABLES, aIndexList ) );
808 else
809 rReq.Ignore();
812 if ( !aIndexList.empty() )
814 sal_uInt16 nSelCount = aIndexList.size();
815 sal_uInt16 nSelIx;
816 SCTAB nFirstVisTab = 0;
818 // special case: only hidden tables selected -> do nothing
819 bool bVisSelected = false;
820 for( nSelIx = 0; !bVisSelected && (nSelIx < nSelCount); ++nSelIx )
821 bVisSelected = rDoc.IsVisible( nFirstVisTab = static_cast<SCTAB>(aIndexList[nSelIx]) );
822 if( !bVisSelected )
823 nSelCount = 0;
825 // select the tables
826 if( nSelCount )
828 for( nTab = 0; nTab < nTabCount; ++nTab )
829 rMark.SelectTable( nTab, false );
831 for( nSelIx = 0; nSelIx < nSelCount; ++nSelIx )
832 rMark.SelectTable( static_cast<SCTAB>(aIndexList[nSelIx]), true );
834 // activate another table, if current is deselected
835 if( !rMark.GetTableSelect( rViewData.GetTabNo() ) )
837 rMark.SelectTable( nFirstVisTab, true );
838 SetTabNo( nFirstVisTab );
841 rViewData.GetDocShell()->PostPaintExtras();
842 SfxBindings& rBind = rViewData.GetBindings();
843 rBind.Invalidate( FID_FILL_TAB );
844 rBind.Invalidate( FID_TAB_DESELECTALL );
847 rReq.Done();
850 break;
852 case SID_OUTLINE_DELETEALL:
853 RemoveAllOutlines();
854 rReq.Done();
855 break;
857 case SID_AUTO_OUTLINE:
858 AutoOutline();
859 rReq.Done();
860 break;
862 case SID_WINDOW_SPLIT:
864 ScSplitMode eHSplit = GetViewData().GetHSplitMode();
865 ScSplitMode eVSplit = GetViewData().GetVSplitMode();
866 if ( eHSplit == SC_SPLIT_NORMAL || eVSplit == SC_SPLIT_NORMAL ) // aufheben
867 RemoveSplit();
868 else if ( eHSplit == SC_SPLIT_FIX || eVSplit == SC_SPLIT_FIX ) // normal
869 FreezeSplitters( false );
870 else // erzeugen
871 SplitAtCursor();
872 rReq.Done();
874 InvalidateSplit();
876 break;
878 case SID_WINDOW_FIX:
880 ScSplitMode eHSplit = GetViewData().GetHSplitMode();
881 ScSplitMode eVSplit = GetViewData().GetVSplitMode();
882 if ( eHSplit == SC_SPLIT_FIX || eVSplit == SC_SPLIT_FIX ) // aufheben
883 RemoveSplit();
884 else
885 FreezeSplitters( true ); // erzeugen oder fixieren
886 rReq.Done();
888 InvalidateSplit();
890 break;
892 case FID_CHG_SHOW:
894 sal_uInt16 nId = ScHighlightChgDlgWrapper::GetChildWindowId();
895 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
897 pScMod->SetRefDialog( nId, pWnd == nullptr );
899 break;
901 case FID_CHG_ACCEPT:
903 pThisFrame->ToggleChildWindow(ScAcceptChgDlgWrapper::GetChildWindowId());
904 GetViewFrame()->GetBindings().Invalidate(FID_CHG_ACCEPT);
905 rReq.Done ();
908 sal_uInt16 nId = ScAcceptChgDlgWrapper::GetChildWindowId();
909 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
911 pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True );
914 break;
916 case FID_CHG_COMMENT:
918 ScViewData& rData = GetViewData();
919 ScAddress aCursorPos( rData.GetCurX(), rData.GetCurY(), rData.GetTabNo() );
920 ScDocShell* pDocSh = rData.GetDocShell();
922 ScChangeAction* pAction = pDocSh->GetChangeAction( aCursorPos );
923 if ( pAction )
925 const SfxPoolItem* pItem;
926 if ( pReqArgs &&
927 pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET &&
928 pItem->ISA( SfxStringItem ) )
930 OUString aComment = static_cast<const SfxStringItem*>(pItem)->GetValue();
931 pDocSh->SetChangeComment( pAction, aComment );
932 rReq.Done();
934 else
936 pDocSh->ExecuteChangeCommentDialog( pAction, GetDialogParent() );
937 rReq.Done();
941 break;
943 case SID_CREATE_SW_DRAWVIEW:
944 // wird von den Forms gerufen, wenn die DrawView mit allem Zubehoer
945 // angelegt werden muss
946 if (!GetScDrawView())
948 GetViewData().GetDocShell()->MakeDrawLayer();
949 rBindings.InvalidateAll(false);
951 break;
953 case FID_PROTECT_DOC:
955 ScDocument* pDoc = GetViewData().GetDocument();
957 if( pReqArgs )
959 const SfxPoolItem* pItem;
960 if( pReqArgs->HasItem( FID_PROTECT_DOC, &pItem ) &&
961 static_cast<const SfxBoolItem*>(pItem)->GetValue() == pDoc->IsDocProtected() )
963 rReq.Ignore();
964 break;
968 ScDocProtection* pProtect = pDoc->GetDocProtection();
969 if (pProtect && pProtect->isProtected())
971 bool bCancel = false;
972 OUString aPassword;
974 if (pProtect->isProtectedWithPass())
976 OUString aText(ScResId(SCSTR_PASSWORD));
978 VclPtrInstance< SfxPasswordDialog > pDlg(GetDialogParent(), &aText);
979 pDlg->SetText( ScResId(SCSTR_UNPROTECTDOC) );
980 pDlg->SetMinLen( 0 );
981 pDlg->SetHelpId( GetStaticInterface()->GetSlot(FID_PROTECT_DOC)->GetCommand() );
982 pDlg->SetEditHelpId( HID_PASSWD_DOC );
984 if (pDlg->Execute() == RET_OK)
985 aPassword = pDlg->GetPassword();
986 else
987 bCancel = true;
989 if (!bCancel)
991 Unprotect( TABLEID_DOC, aPassword );
992 rReq.AppendItem( SfxBoolItem( FID_PROTECT_DOC, false ) );
993 rReq.Done();
996 else
998 OUString aText(ScResId(SCSTR_PASSWORDOPT));
1000 VclPtrInstance< SfxPasswordDialog > pDlg(GetDialogParent(), &aText);
1001 pDlg->SetText( ScResId(SCSTR_PROTECTDOC) );
1002 pDlg->SetMinLen( 0 );
1003 pDlg->SetHelpId( GetStaticInterface()->GetSlot(FID_PROTECT_DOC)->GetCommand() );
1004 pDlg->SetEditHelpId( HID_PASSWD_DOC );
1005 pDlg->ShowExtras( SfxShowExtras::CONFIRM );
1007 if (pDlg->Execute() == RET_OK)
1009 OUString aPassword = pDlg->GetPassword();
1010 Protect( TABLEID_DOC, aPassword );
1011 rReq.AppendItem( SfxBoolItem( FID_PROTECT_DOC, true ) );
1012 rReq.Done();
1015 rBindings.Invalidate( FID_PROTECT_DOC );
1017 break;
1019 case FID_PROTECT_TABLE:
1021 ScDocument* pDoc = GetViewData().GetDocument();
1022 SCTAB nTab = GetViewData().GetTabNo();
1023 bool bOldProtection = pDoc->IsTabProtected(nTab);
1025 if( pReqArgs )
1027 const SfxPoolItem* pItem;
1028 bool bNewProtection = !bOldProtection;
1029 if( pReqArgs->HasItem( FID_PROTECT_TABLE, &pItem ) )
1030 bNewProtection = static_cast<const SfxBoolItem*>(pItem)->GetValue();
1031 if( bNewProtection == bOldProtection )
1033 rReq.Ignore();
1034 break;
1038 if (bOldProtection)
1040 // Unprotect a protected sheet.
1042 ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
1043 if (pProtect && pProtect->isProtectedWithPass())
1045 OUString aText( ScResId(SCSTR_PASSWORDOPT) );
1046 VclPtrInstance< SfxPasswordDialog > pDlg(GetDialogParent(), &aText);
1047 pDlg->SetText( ScResId(SCSTR_UNPROTECTTAB) );
1048 pDlg->SetMinLen( 0 );
1049 pDlg->SetHelpId( GetStaticInterface()->GetSlot(FID_PROTECT_TABLE)->GetCommand() );
1050 pDlg->SetEditHelpId( HID_PASSWD_TABLE );
1052 if (pDlg->Execute() == RET_OK)
1054 OUString aPassword = pDlg->GetPassword();
1055 Unprotect(nTab, aPassword);
1058 else
1059 // this sheet is not password-protected.
1060 Unprotect(nTab, OUString());
1062 if (!pReqArgs)
1064 rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, false) );
1065 rReq.Done();
1068 else
1070 // Protect a current sheet.
1072 VclPtrInstance< ScTableProtectionDlg > pDlg(GetDialogParent());
1074 ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
1075 if (pProtect)
1076 pDlg->SetDialogData(*pProtect);
1078 if (pDlg->Execute() == RET_OK)
1080 pScMod->InputEnterHandler();
1082 ScTableProtection aNewProtect;
1083 pDlg->WriteData(aNewProtect);
1084 ProtectSheet(nTab, aNewProtect);
1085 if (!pReqArgs)
1087 rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, true) );
1088 rReq.Done();
1092 TabChanged();
1093 UpdateInputHandler(true); // damit sofort wieder eingegeben werden kann
1094 SelectionChanged();
1096 break;
1098 case SID_OPT_LOCALE_CHANGED :
1099 { // locale changed, SYSTEM number formats changed => repaint cell contents
1100 PaintGrid();
1101 rReq.Done();
1103 break;
1105 default:
1106 OSL_FAIL("Unknown Slot at ScTabViewShell::Execute");
1107 break;
1111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */