Bump version to 4.3-4
[LibreOffice.git] / sc / source / ui / view / tabvwshf.cxx
blob01b33721543d6dd08ee39f4428dc99795e2e92f3
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 .
21 #include <boost/scoped_ptr.hpp>
23 #include "scitems.hxx"
24 #include <sfx2/request.hxx>
25 #include <sfx2/bindings.hxx>
26 #include <sfx2/viewfrm.hxx>
27 #include <basic/sbstar.hxx>
28 #include <svl/languageoptions.hxx>
29 #include <svl/stritem.hxx>
30 #include <svl/whiter.hxx>
31 #include <vcl/msgbox.hxx>
32 #include <sfx2/objface.hxx>
33 #include <svx/svxdlg.hxx>
34 #include <editeng/colritem.hxx>
36 #include "tabvwsh.hxx"
37 #include "sc.hrc"
38 #include "docsh.hxx"
39 #include "document.hxx"
40 #include "shtabdlg.hxx"
41 #include "scresid.hxx"
42 #include "globstr.hrc"
43 #include "docfunc.hxx"
44 #include "eventuno.hxx"
46 #include "scabstdlg.hxx"
48 #include "tabbgcolor.hxx"
49 #include "tabbgcolordlg.hxx"
50 #include "sccommands.h"
51 #include "markdata.hxx"
53 #include <vector>
55 using ::boost::scoped_ptr;
56 using namespace com::sun::star;
58 void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
60 ScViewData* pViewData = GetViewData();
61 ScDocument* pDoc = pViewData->GetDocument();
63 SCTAB nCurrentTab = pViewData->GetTabNo();
64 SCTAB nTabCount = pDoc->GetTableCount();
65 sal_uInt16 nSlot = rReq.GetSlot();
66 const SfxItemSet* pReqArgs = rReq.GetArgs();
68 HideListBox(); // Autofilter-DropDown-Listbox
70 switch ( nSlot )
72 case FID_TABLE_VISIBLE:
74 OUString aName;
75 pDoc->GetName( nCurrentTab, aName );
77 bool bVisible=true;
78 if( pReqArgs != NULL )
80 const SfxPoolItem* pItem;
81 if( pReqArgs->HasItem( FID_TABLE_VISIBLE, &pItem ) )
82 bVisible = ((const SfxBoolItem*)pItem)->GetValue();
85 if( ! bVisible ) // ausblenden
87 if ( pDoc->IsDocEditable() )
89 ScMarkData& rMark = pViewData->GetMarkData();
90 HideTable( rMark );
93 else // einblenden
95 std::vector<OUString> rNames;
96 rNames.push_back(aName);
97 ShowTable( rNames );
100 break;
102 case FID_TABLE_HIDE:
104 if ( pDoc->IsDocEditable() )
106 ScMarkData& rMark = pViewData->GetMarkData();
107 HideTable( rMark );
110 break;
112 case FID_TABLE_SHOW:
114 OUString aName;
115 std::vector<OUString> rNames;
116 if ( pReqArgs )
118 const SfxPoolItem* pItem;
119 if( pReqArgs->HasItem( FID_TABLE_SHOW, &pItem ) )
121 aName = ((const SfxStringItem*)pItem)->GetValue();
122 rNames.push_back(aName);
123 ShowTable( rNames );
125 if( ! rReq.IsAPI() )
126 rReq.Done();
129 else
131 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
132 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
134 boost::scoped_ptr<AbstractScShowTabDlg> pDlg(pFact->CreateScShowTabDlg(GetDialogParent()));
135 OSL_ENSURE(pDlg, "Dialog create fail!");
137 OUString aTabName;
138 bool bFirst = true;
139 for ( SCTAB i=0; i != nTabCount; i++ )
141 if (!pDoc->IsVisible(i))
143 pDoc->GetName( i, aTabName );
144 pDlg->Insert( aTabName, bFirst );
145 bFirst = false;
149 if ( pDlg->Execute() == RET_OK )
151 sal_uInt16 nCount = pDlg->GetSelectEntryCount();
152 for (sal_uInt16 nPos=0; nPos<nCount; nPos++)
154 aName = pDlg->GetSelectEntry(nPos);
155 rReq.AppendItem( SfxStringItem( FID_TABLE_SHOW, aName ) );
156 rNames.push_back(aName);
158 ShowTable( rNames );
159 rReq.Done();
163 break;
165 case FID_INS_TABLE:
166 case FID_INS_TABLE_EXT:
168 ScMarkData& rMark = pViewData->GetMarkData();
169 SCTAB nTabSelCount = rMark.GetSelectCount();
170 SCTAB nTabNr = nCurrentTab;
172 if ( !pDoc->IsDocEditable() )
173 break; // gesperrt
175 if ( pReqArgs != NULL ) // von Basic
177 bool bOk = false;
178 const SfxPoolItem* pTabItem;
179 const SfxPoolItem* pNameItem;
180 OUString aName;
182 if ( pReqArgs->HasItem( FN_PARAM_1, &pTabItem ) &&
183 pReqArgs->HasItem( nSlot, &pNameItem ) )
185 // Tabellennr. von Basic: 1-basiert
187 aName = ((const SfxStringItem*)pNameItem)->GetValue();
188 nTabNr = ((const SfxUInt16Item*)pTabItem)->GetValue() - 1;
189 if ( nTabNr < nTabCount )
190 bOk = InsertTable( aName, nTabNr );
193 if (bOk)
194 rReq.Done( *pReqArgs );
195 //! sonst Fehler setzen
197 else // Dialog
199 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
200 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
202 boost::scoped_ptr<AbstractScInsertTableDlg> pDlg(pFact->CreateScInsertTableDlg(GetDialogParent(), *pViewData,
203 nTabSelCount, nSlot == FID_INS_TABLE_EXT));
204 OSL_ENSURE(pDlg, "Dialog create fail!");
205 if ( RET_OK == pDlg->Execute() )
207 if (pDlg->GetTablesFromFile())
209 std::vector<SCTAB> nTabs;
210 sal_uInt16 n = 0;
211 const OUString* pStr = pDlg->GetFirstTable( &n );
212 while ( pStr )
214 nTabs.push_back( static_cast<SCTAB>(n) );
215 pStr = pDlg->GetNextTable( &n );
217 bool bLink = pDlg->GetTablesAsLink();
218 if (!nTabs.empty())
220 if(pDlg->IsTableBefore())
222 ImportTables( pDlg->GetDocShellTables(), nTabs.size(), &nTabs[0],
223 bLink,nTabNr );
225 else
227 SCTAB nTabAfter = nTabNr+1;
229 for(SCTAB j=nCurrentTab+1;j<nTabCount;j++)
231 if(!pDoc->IsScenario(j))
233 nTabAfter=j;
234 break;
238 ImportTables( pDlg->GetDocShellTables(), nTabs.size(), &nTabs[0],
239 bLink,nTabAfter );
243 else
245 SCTAB nCount=pDlg->GetTableCount();
246 if(pDlg->IsTableBefore())
248 if(nCount==1 && !pDlg->GetFirstTable()->isEmpty())
250 rReq.AppendItem( SfxStringItem( FID_INS_TABLE, *pDlg->GetFirstTable() ) );
251 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nTabNr) + 1 ) ); // 1-based
252 rReq.Done();
254 InsertTable( *pDlg->GetFirstTable(), nTabNr );
256 else
258 std::vector<OUString> aNames(0);
259 InsertTables( aNames, nTabNr,nCount );
262 else
264 SCTAB nTabAfter = nTabNr+1;
265 SCTAB nSelHigh = rMark.GetLastSelected();
267 for(SCTAB j=nSelHigh+1;j<nTabCount;j++)
269 if(!pDoc->IsScenario(j))
271 nTabAfter=j;
272 break;
274 else // #101672#; increase nTabAfter, because it is possible that the scenario tables are the last
275 nTabAfter = j + 1;
278 if(nCount==1 && !pDlg->GetFirstTable()->isEmpty())
280 rReq.AppendItem( SfxStringItem( FID_INS_TABLE, *pDlg->GetFirstTable() ) );
281 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nTabAfter) + 1 ) ); // 1-based
282 rReq.Done();
284 InsertTable( *pDlg->GetFirstTable(), nTabAfter);
286 else
288 std::vector<OUString> aNames(0);
289 InsertTables( aNames, nTabAfter,nCount);
296 break;
298 case FID_TAB_APPEND:
299 case FID_TAB_RENAME:
300 case FID_TAB_MENU_RENAME:
302 // FID_TAB_MENU_RENAME - "umbenennen" im Menu
303 // FID_TAB_RENAME - "Name"-Property fuer Basic
304 // Execute ist gleich, aber im GetState wird MENU_RENAME evtl. disabled
306 if ( nSlot == FID_TAB_MENU_RENAME )
307 nSlot = FID_TAB_RENAME; // Execute ist gleich
309 SCTAB nTabNr = pViewData->GetTabNo();
310 ScMarkData& rMark = pViewData->GetMarkData();
311 SCTAB nTabSelCount = rMark.GetSelectCount();
313 if ( !pDoc->IsDocEditable() )
314 break; // alles gesperrt
316 if ( nSlot != FID_TAB_APPEND &&
317 ( pDoc->IsTabProtected( nTabNr ) || nTabSelCount > 1 ) )
318 break; // kein Rename
320 if( pReqArgs != NULL )
322 bool bDone = false;
323 const SfxPoolItem* pItem;
324 OUString aName;
326 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
327 nTabNr = ((const SfxUInt16Item*)pItem)->GetValue();
329 if( pReqArgs->HasItem( nSlot, &pItem ) )
330 aName = ((const SfxStringItem*)pItem)->GetValue();
332 switch ( nSlot )
334 case FID_TAB_APPEND:
335 bDone = AppendTable( aName );
336 break;
337 case FID_TAB_RENAME:
338 bDone = RenameTable( aName, nTabNr );
339 break;
342 if( bDone )
344 rReq.Done( *pReqArgs );
347 else
349 sal_uInt16 nRet = RET_OK;
350 bool bDone = false;
351 OUString aErrMsg ( ScGlobal::GetRscString( STR_INVALIDTABNAME ) );
352 OUString aName;
353 OUString aDlgTitle;
354 const sal_Char* pHelpId = 0;
356 switch ( nSlot )
358 case FID_TAB_APPEND:
359 aDlgTitle = OUString(ScResId(SCSTR_APDTABLE));
360 pDoc->CreateValidTabName( aName );
361 pHelpId = HID_SC_APPEND_NAME;
362 break;
364 case FID_TAB_RENAME:
365 aDlgTitle = OUString(ScResId(SCSTR_RENAMETAB));
366 pDoc->GetName( pViewData->GetTabNo(), aName );
367 pHelpId = HID_SC_RENAME_NAME;
368 break;
371 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
372 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
374 boost::scoped_ptr<AbstractScStringInputDlg> pDlg(pFact->CreateScStringInputDlg(
375 GetDialogParent(), aDlgTitle, OUString(ScResId(SCSTR_NAME)),
376 aName, GetStaticInterface()->GetSlot(nSlot)->GetCommand(),
377 pHelpId));
379 OSL_ENSURE(pDlg, "Dialog create fail!");
381 while ( !bDone && nRet == RET_OK )
383 nRet = pDlg->Execute();
385 if ( nRet == RET_OK )
387 aName = pDlg->GetInputString();
390 switch ( nSlot )
392 case FID_TAB_APPEND:
393 bDone = AppendTable( aName );
394 break;
395 case FID_TAB_RENAME:
396 bDone = RenameTable( aName, nTabNr );
397 break;
400 if ( bDone )
402 rReq.AppendItem( SfxStringItem( nSlot, aName ) );
403 rReq.Done();
405 else
407 if( rReq.IsAPI() )
409 #ifndef DISABLE_SCRIPTING
410 StarBASIC::Error( SbERR_SETPROP_FAILED ); // XXX Fehlerbehandlung???
411 #endif
413 else
415 nRet = ErrorBox( GetDialogParent(),
416 WinBits( WB_OK | WB_DEF_OK ),
417 aErrMsg
418 ).Execute();
425 break;
427 case FID_TAB_MOVE:
429 if ( pDoc->GetChangeTrack() != NULL )
430 break; // bei aktiviertem ChangeTracking kein TabMove
432 bool bDoIt = false;
433 sal_uInt16 nDoc = 0;
434 SCTAB nTab = pViewData->GetTabNo();
435 bool bCpy = false;
436 OUString aDocName;
437 OUString aTabName;
439 if( pReqArgs != NULL )
441 SCTAB nTableCount = pDoc->GetTableCount();
442 const SfxPoolItem* pItem;
444 if( pReqArgs->HasItem( FID_TAB_MOVE, &pItem ) )
445 aDocName = ((const SfxStringItem*)pItem)->GetValue();
446 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
448 // Tabelle ist 1-basiert
449 nTab = ((const SfxUInt16Item*)pItem)->GetValue() - 1;
450 if ( nTab >= nTableCount )
451 nTab = SC_TAB_APPEND;
453 if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
454 bCpy = ((const SfxBoolItem*)pItem)->GetValue();
456 if (!aDocName.isEmpty())
458 SfxObjectShell* pSh = SfxObjectShell::GetFirst();
459 ScDocShell* pScSh = NULL;
460 sal_uInt16 i=0;
462 while ( pSh )
464 pScSh = PTR_CAST( ScDocShell, pSh );
466 if( pScSh )
468 pScSh->GetTitle();
470 if (aDocName.equals(pScSh->GetTitle()))
472 nDoc = i;
473 ScDocument* pDestDoc = pScSh->GetDocument();
474 nTableCount = pDestDoc->GetTableCount();
475 bDoIt = pDestDoc->IsDocEditable();
476 break;
479 i++; // nur die ScDocShell's zaehlen
481 pSh = SfxObjectShell::GetNext( *pSh );
484 else // Kein Dokumentname -> neues Dokument
486 nDoc = SC_DOC_NEW;
487 bDoIt = true;
490 if ( bDoIt && nTab >= nTableCount ) // ggf. anhaengen
491 nTab = SC_TAB_APPEND;
493 else
495 OUString aDefaultName;
496 pDoc->GetName( pViewData->GetTabNo(), aDefaultName );
498 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
499 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
501 boost::scoped_ptr<AbstractScMoveTableDlg> pDlg(pFact->CreateScMoveTableDlg(GetDialogParent(),
502 aDefaultName));
503 OSL_ENSURE(pDlg, "Dialog create fail!");
505 SCTAB nTableCount = pDoc->GetTableCount();
506 ScMarkData& rMark = GetViewData()->GetMarkData();
507 SCTAB nTabSelCount = rMark.GetSelectCount();
510 if(nTableCount==nTabSelCount)
512 pDlg->SetForceCopyTable();
515 // We support direct renaming of sheet only when one sheet
516 // is selected.
517 pDlg->EnableRenameTable(nTabSelCount == 1);
519 if ( pDlg->Execute() == RET_OK )
521 nDoc = pDlg->GetSelectedDocument();
522 nTab = pDlg->GetSelectedTable();
523 bCpy = pDlg->GetCopyTable();
524 bool bRna = pDlg->GetRenameTable();
525 // Leave aTabName string empty, when Rename is FALSE.
526 if( bRna )
528 pDlg->GetTabNameString( aTabName );
530 bDoIt = true;
532 OUString aFoundDocName;
533 if ( nDoc != SC_DOC_NEW )
535 ScDocShell* pSh = ScDocShell::GetShellByNum( nDoc );
536 if (pSh)
538 aFoundDocName = pSh->GetTitle();
539 if ( !pSh->GetDocument()->IsDocEditable() )
541 ErrorMessage(STR_READONLYERR);
542 bDoIt = false;
546 rReq.AppendItem( SfxStringItem( FID_TAB_MOVE, aFoundDocName ) );
547 // Tabelle ist 1-basiert, wenn nicht APPEND
548 SCTAB nBasicTab = ( nTab <= MAXTAB ) ? (nTab+1) : nTab;
549 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nBasicTab) ) );
550 rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bCpy ) );
554 if( bDoIt )
556 rReq.Done(); // aufzeichnen, solange das Dokument noch aktiv ist
558 MoveTable( nDoc, nTab, bCpy, &aTabName );
561 break;
563 case FID_DELETE_TABLE:
565 // Parameter war ueberfluessig, weil die Methode an der Table haengt
567 bool bDoIt = rReq.IsAPI();
568 if( !bDoIt )
570 // wenn's nicht von Basic kommt, nochmal nachfragen:
572 bDoIt = ( RET_YES ==
573 QueryBox( GetDialogParent(),
574 WinBits( WB_YES_NO | WB_DEF_YES ),
575 ScGlobal::GetRscString(STR_QUERY_DELTAB)
576 ).Execute() );
578 if( bDoIt )
580 SCTAB nNewTab = nCurrentTab;
581 SCTAB nFirstTab=0;
582 bool bTabFlag=false;
583 ScMarkData& rMark = pViewData->GetMarkData();
584 std::vector<SCTAB> TheTabs;
585 for(SCTAB i=0;i<nTabCount;i++)
587 if(rMark.GetTableSelect(i) &&!pDoc->IsTabProtected(i))
589 TheTabs.push_back(i);
590 bTabFlag=true;
591 if(nNewTab==i) nNewTab++;
593 if(!bTabFlag) nFirstTab=i;
595 if(nNewTab>=nTabCount) nNewTab=nFirstTab;
597 pViewData->SetTabNo(nNewTab);
598 DeleteTables(TheTabs);
599 TheTabs.clear();
600 rReq.Done();
603 break;
605 case FID_TAB_RTL:
607 ScDocShell* pDocSh = pViewData->GetDocShell();
608 ScDocFunc &rFunc = pDocSh->GetDocFunc();
609 bool bSet = !pDoc->IsLayoutRTL( nCurrentTab );
611 const ScMarkData& rMark = pViewData->GetMarkData();
612 if ( rMark.GetSelectCount() != 0 )
614 // handle several sheets
616 ::svl::IUndoManager* pUndoManager = pDocSh->GetUndoManager();
617 OUString aUndo = ScGlobal::GetRscString( STR_UNDO_TAB_RTL );
618 pUndoManager->EnterListAction( aUndo, aUndo );
620 ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
621 for (; itr != itrEnd; ++itr)
622 rFunc.SetLayoutRTL( *itr, bSet, false );
624 pUndoManager->LeaveListAction();
626 else
627 rFunc.SetLayoutRTL( nCurrentTab, bSet, false );
629 break;
631 case FID_TAB_TOGGLE_GRID:
633 bool bShowGrid = pViewData->GetShowGrid();
634 pViewData->SetShowGrid(!bShowGrid);
635 SfxBindings& rBindings = GetViewFrame()->GetBindings();
636 rBindings.Invalidate( FID_TAB_TOGGLE_GRID );
637 PaintGrid();
638 rReq.Done();
640 break;
642 case FID_TAB_SET_TAB_BG_COLOR:
643 case FID_TAB_MENU_SET_TAB_BG_COLOR:
645 if ( nSlot == FID_TAB_MENU_SET_TAB_BG_COLOR )
646 nSlot = FID_TAB_SET_TAB_BG_COLOR;
647 SCTAB nTabNr = pViewData->GetTabNo();
648 ScMarkData& rMark = pViewData->GetMarkData();
649 SCTAB nTabSelCount = rMark.GetSelectCount();
650 if ( !pDoc->IsDocEditable() )
651 break;
653 if ( pDoc->IsTabProtected( nTabNr ) ) // ||nTabSelCount > 1
654 break;
656 if( pReqArgs != NULL )
658 bool bDone = false;
659 const SfxPoolItem* pItem;
660 Color aColor;
661 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
662 nTabNr = ((const SfxUInt16Item*)pItem)->GetValue();
664 if( pReqArgs->HasItem( nSlot, &pItem ) )
665 aColor = ((const SvxColorItem*)pItem)->GetValue();
667 if ( nTabSelCount > 1 )
669 scoped_ptr<ScUndoTabColorInfo::List>
670 pTabColorList(new ScUndoTabColorInfo::List);
671 ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end();
672 for (; itr != itrEnd; ++itr)
674 if ( !pDoc->IsTabProtected(*itr) )
676 ScUndoTabColorInfo aTabColorInfo(*itr);
677 aTabColorInfo.maNewTabBgColor = aColor;
678 pTabColorList->push_back(aTabColorInfo);
681 bDone = SetTabBgColor( *pTabColorList );
683 else
685 bDone = SetTabBgColor( aColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
687 if( bDone )
689 rReq.Done( *pReqArgs );
692 else
694 sal_uInt16 nRet = RET_OK; /// temp
695 bool bDone = false; /// temp
696 Color aTabBgColor;
698 aTabBgColor = pDoc->GetTabBgColor( nCurrentTab );
699 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
700 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
701 boost::scoped_ptr<AbstractScTabBgColorDlg> pDlg(pFact->CreateScTabBgColorDlg(
702 GetDialogParent(),
703 OUString(ScResId(SCSTR_SET_TAB_BG_COLOR)),
704 OUString(ScResId(SCSTR_NO_TAB_BG_COLOR)),
705 aTabBgColor,
706 CMD_FID_TAB_SET_TAB_BG_COLOR));
707 while ( !bDone && nRet == RET_OK )
709 nRet = pDlg->Execute();
710 if( nRet == RET_OK )
712 Color aSelectedColor;
713 pDlg->GetSelectedColor(aSelectedColor);
714 scoped_ptr<ScUndoTabColorInfo::List>
715 pTabColorList(new ScUndoTabColorInfo::List);
716 if ( nTabSelCount > 1 )
718 ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end();
719 for (; itr != itrEnd; ++itr)
721 if ( !pDoc->IsTabProtected(*itr) )
723 ScUndoTabColorInfo aTabColorInfo(*itr);
724 aTabColorInfo.maNewTabBgColor = aSelectedColor;
725 pTabColorList->push_back(aTabColorInfo);
728 bDone = SetTabBgColor( *pTabColorList );
730 else
732 bDone = SetTabBgColor( aSelectedColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
734 if ( bDone )
736 rReq.AppendItem( SvxColorItem( aTabBgColor, nSlot ) );
737 rReq.Done();
739 else
741 if( rReq.IsAPI() )
743 #ifndef DISABLE_SCRIPTING
744 StarBASIC::Error( SbERR_SETPROP_FAILED );
745 #endif
752 break;
754 case FID_TAB_EVENTS:
756 ScDocShell* pDocSh = pViewData->GetDocShell();
757 uno::Reference<container::XNameReplace> xEvents( new ScSheetEventsObj( pDocSh, nCurrentTab ) );
758 uno::Reference<frame::XFrame> xFrame = GetViewFrame()->GetFrame().GetFrameInterface();
759 SvxAbstractDialogFactory* pDlgFactory = SvxAbstractDialogFactory::Create();
760 if (pDlgFactory)
762 boost::scoped_ptr<VclAbstractDialog> pDialog( pDlgFactory->CreateSvxMacroAssignDlg(
763 GetDialogParent(), xFrame, false, xEvents, 0 ) );
764 if ( pDialog.get() && pDialog->Execute() == RET_OK )
766 // the dialog modifies the settings directly
770 break;
772 default:
773 OSL_FAIL("Unbekannte Message bei ViewShell");
774 break;
778 void ScTabViewShell::GetStateTable( SfxItemSet& rSet )
780 ScViewData* pViewData = GetViewData();
781 ScDocument* pDoc = pViewData->GetDocument();
782 ScDocShell* pDocShell = pViewData->GetDocShell();
783 ScMarkData& rMark = GetViewData()->GetMarkData();
784 SCTAB nTab = pViewData->GetTabNo();
786 SCTAB nTabCount = pDoc->GetTableCount();
787 SCTAB nTabSelCount = rMark.GetSelectCount();
789 SfxWhichIter aIter(rSet);
790 sal_uInt16 nWhich = aIter.FirstWhich();
792 while ( nWhich )
794 switch ( nWhich )
797 case FID_TABLE_VISIBLE:
798 rSet.Put( SfxBoolItem( nWhich, pDoc->IsVisible(nTab) ));
799 break;
801 case FID_TABLE_HIDE:
803 sal_uInt16 nVis = 0;
804 // enable menu : check to make sure we won't hide all sheets. we need at least one visible at all times.
805 for ( SCTAB i=0; i < nTabCount && nVis<nTabSelCount + 1; i++ )
806 if (pDoc->IsVisible(i))
807 ++nVis;
808 if ( nVis<=nTabSelCount || !pDoc->IsDocEditable() )
809 rSet.DisableItem( nWhich );
811 break;
813 case FID_TABLE_SHOW:
815 bool bHasHidden = false;
816 for ( SCTAB i=0; i < nTabCount && !bHasHidden; i++ )
817 if (!pDoc->IsVisible(i))
818 bHasHidden = true;
819 if ( !bHasHidden || pDoc->IsDocProtected() || nTabSelCount > 1 )
820 rSet.DisableItem( nWhich );
822 break;
824 case FID_DELETE_TABLE:
826 if ( pDoc->GetChangeTrack() )
827 rSet.DisableItem( nWhich );
828 else
830 sal_uInt16 nVis = 0;
831 for ( SCTAB i=0; i < nTabCount && nVis<2; i++ )
832 if (pDoc->IsVisible(i))
833 ++nVis;
834 if ( pDoc->IsTabProtected(nTab)
835 || !pDoc->IsDocEditable()
836 || nVis < 2
837 || nTabSelCount == nTabCount)
838 rSet.DisableItem( nWhich );
841 break;
843 case FID_INS_TABLE:
844 case FID_INS_TABLE_EXT:
845 case FID_TAB_APPEND:
846 if ( !pDoc->IsDocEditable() ||
847 nTabCount > MAXTAB ||
848 ( nWhich == FID_INS_TABLE_EXT && pDocShell && pDocShell->IsDocShared() ) )
849 rSet.DisableItem( nWhich );
850 break;
852 case FID_TAB_MOVE:
853 if ( !pDoc->IsDocEditable()
854 || pDoc->GetChangeTrack() != NULL
855 || nTabCount > MAXTAB)
856 rSet.DisableItem( nWhich );
857 break;
859 // FID_TAB_MENU_RENAME - "umbenennen" im Menu
860 // FID_TAB_RENAME - "Name"-Property fuer Basic
862 case FID_TAB_MENU_RENAME:
863 if ( !pDoc->IsDocEditable() ||
864 pDoc->IsTabProtected(nTab) ||nTabSelCount > 1 ||
865 ( pDocShell && pDocShell->IsDocShared() ) )
866 rSet.DisableItem( nWhich );
867 break;
869 case FID_TAB_RENAME:
871 OUString aTabName;
872 pDoc->GetName( nTab, aTabName );
874 rSet.Put( SfxStringItem( nWhich, aTabName ));
877 break;
879 case FID_TAB_RTL:
881 SvtLanguageOptions aLangOpt;
882 if ( !aLangOpt.IsCTLFontEnabled() )
883 rSet.DisableItem( nWhich );
884 else
885 rSet.Put( SfxBoolItem( nWhich, pDoc->IsLayoutRTL( nTab ) ) );
887 break;
889 case FID_TAB_MENU_SET_TAB_BG_COLOR:
891 if ( !pDoc->IsDocEditable()
892 || ( pDocShell && pDocShell->IsDocShared() )
893 || pDoc->IsTabProtected(nTab) )
894 rSet.DisableItem( nWhich );
896 break;
898 case FID_TAB_SET_TAB_BG_COLOR:
900 Color aColor;
901 aColor = pDoc->GetTabBgColor( nTab );
902 rSet.Put( SvxColorItem( aColor, nWhich ) );
904 break;
906 case FID_TAB_TOGGLE_GRID:
907 rSet.Put( SfxBoolItem(nWhich, pViewData->GetShowGrid()) );
908 break;
910 nWhich = aIter.NextWhich();
915 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */