bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / ui / view / tabvwshf.cxx
blobf3db8bc07b283d8827a7071e8876c8e32975e14f
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 sal_Bool bVisible=sal_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<String> 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 String aName;
115 std::vector<String> 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 AbstractScShowTabDlg* pDlg = pFact->CreateScShowTabDlg( GetDialogParent(), RID_SCDLG_SHOW_TAB);
135 OSL_ENSURE(pDlg, "Dialog create fail!");
137 OUString aTabName;
138 sal_Bool bFirst = sal_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();
161 delete pDlg;
164 break;
166 case FID_INS_TABLE:
167 case FID_INS_TABLE_EXT:
169 ScMarkData& rMark = pViewData->GetMarkData();
170 SCTAB nTabSelCount = rMark.GetSelectCount();
171 SCTAB nTabNr = nCurrentTab;
173 if ( !pDoc->IsDocEditable() )
174 break; // gesperrt
176 if ( pReqArgs != NULL ) // von Basic
178 sal_Bool bOk = false;
179 const SfxPoolItem* pTabItem;
180 const SfxPoolItem* pNameItem;
181 String aName;
183 if ( pReqArgs->HasItem( FN_PARAM_1, &pTabItem ) &&
184 pReqArgs->HasItem( nSlot, &pNameItem ) )
186 // Tabellennr. von Basic: 1-basiert
188 aName = ((const SfxStringItem*)pNameItem)->GetValue();
189 nTabNr = ((const SfxUInt16Item*)pTabItem)->GetValue() - 1;
190 if ( nTabNr < nTabCount )
191 bOk = InsertTable( aName, nTabNr );
194 if (bOk)
195 rReq.Done( *pReqArgs );
196 //! sonst Fehler setzen
198 else // Dialog
200 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
201 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
203 AbstractScInsertTableDlg* pDlg = pFact->CreateScInsertTableDlg(GetDialogParent(), *pViewData,
204 nTabSelCount, nSlot == FID_INS_TABLE_EXT);
205 OSL_ENSURE(pDlg, "Dialog create fail!");
206 if ( RET_OK == pDlg->Execute() )
208 if (pDlg->GetTablesFromFile())
210 std::vector<SCTAB> nTabs;
211 sal_uInt16 n = 0;
212 const String* pStr = pDlg->GetFirstTable( &n );
213 while ( pStr )
215 nTabs.push_back( static_cast<SCTAB>(n) );
216 pStr = pDlg->GetNextTable( &n );
218 sal_Bool bLink = pDlg->GetTablesAsLink();
219 if (!nTabs.empty())
221 if(pDlg->IsTableBefore())
223 ImportTables( pDlg->GetDocShellTables(), nTabs.size(), &nTabs[0],
224 bLink,nTabNr );
226 else
228 SCTAB nTabAfter = nTabNr+1;
230 for(SCTAB j=nCurrentTab+1;j<nTabCount;j++)
232 if(!pDoc->IsScenario(j))
234 nTabAfter=j;
235 break;
239 ImportTables( pDlg->GetDocShellTables(), nTabs.size(), &nTabs[0],
240 bLink,nTabAfter );
244 else
246 SCTAB nCount=pDlg->GetTableCount();
247 if(pDlg->IsTableBefore())
249 if(nCount==1 && pDlg->GetFirstTable()->Len()>0)
251 rReq.AppendItem( SfxStringItem( FID_INS_TABLE, *pDlg->GetFirstTable() ) );
252 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nTabNr) + 1 ) ); // 1-based
253 rReq.Done();
255 InsertTable( *pDlg->GetFirstTable(), nTabNr );
257 else
259 std::vector<OUString> aNames(0);
260 InsertTables( aNames, nTabNr,nCount );
263 else
265 SCTAB nTabAfter = nTabNr+1;
266 SCTAB nSelHigh = rMark.GetLastSelected();
268 for(SCTAB j=nSelHigh+1;j<nTabCount;j++)
270 if(!pDoc->IsScenario(j))
272 nTabAfter=j;
273 break;
275 else // #101672#; increase nTabAfter, because it is possible that the scenario tables are the last
276 nTabAfter = j + 1;
279 if(nCount==1 && pDlg->GetFirstTable()->Len()>0)
281 rReq.AppendItem( SfxStringItem( FID_INS_TABLE, *pDlg->GetFirstTable() ) );
282 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nTabAfter) + 1 ) ); // 1-based
283 rReq.Done();
285 InsertTable( *pDlg->GetFirstTable(), nTabAfter);
287 else
289 std::vector<OUString> aNames(0);
290 InsertTables( aNames, nTabAfter,nCount);
296 delete pDlg;
299 break;
301 case FID_TAB_APPEND:
302 case FID_TAB_RENAME:
303 case FID_TAB_MENU_RENAME:
305 // FID_TAB_MENU_RENAME - "umbenennen" im Menu
306 // FID_TAB_RENAME - "Name"-Property fuer Basic
307 // Execute ist gleich, aber im GetState wird MENU_RENAME evtl. disabled
309 if ( nSlot == FID_TAB_MENU_RENAME )
310 nSlot = FID_TAB_RENAME; // Execute ist gleich
312 SCTAB nTabNr = pViewData->GetTabNo();
313 ScMarkData& rMark = pViewData->GetMarkData();
314 SCTAB nTabSelCount = rMark.GetSelectCount();
316 if ( !pDoc->IsDocEditable() )
317 break; // alles gesperrt
319 if ( nSlot != FID_TAB_APPEND &&
320 ( pDoc->IsTabProtected( nTabNr ) || nTabSelCount > 1 ) )
321 break; // kein Rename
323 if( pReqArgs != NULL )
325 sal_Bool bDone = false;
326 const SfxPoolItem* pItem;
327 String aName;
329 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
330 nTabNr = ((const SfxUInt16Item*)pItem)->GetValue();
332 if( pReqArgs->HasItem( nSlot, &pItem ) )
333 aName = ((const SfxStringItem*)pItem)->GetValue();
335 switch ( nSlot )
337 case FID_TAB_APPEND:
338 bDone = AppendTable( aName );
339 break;
340 case FID_TAB_RENAME:
341 bDone = RenameTable( aName, nTabNr );
342 break;
345 if( bDone )
347 rReq.Done( *pReqArgs );
350 else
352 sal_uInt16 nRet = RET_OK;
353 sal_Bool bDone = false;
354 String aErrMsg ( ScGlobal::GetRscString( STR_INVALIDTABNAME ) );
355 OUString aName;
356 String aDlgTitle;
357 const sal_Char* pHelpId = 0;
359 switch ( nSlot )
361 case FID_TAB_APPEND:
362 aDlgTitle = String(ScResId(SCSTR_APDTABLE));
363 pDoc->CreateValidTabName( aName );
364 pHelpId = HID_SC_APPEND_NAME;
365 break;
367 case FID_TAB_RENAME:
368 aDlgTitle = String(ScResId(SCSTR_RENAMETAB));
369 pDoc->GetName( pViewData->GetTabNo(), aName );
370 pHelpId = HID_SC_RENAME_NAME;
371 break;
374 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
375 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
377 AbstractScStringInputDlg* pDlg = pFact->CreateScStringInputDlg(
378 GetDialogParent(), aDlgTitle, String(ScResId(SCSTR_NAME)),
379 aName, GetStaticInterface()->GetSlot(nSlot)->GetCommand(),
380 pHelpId, RID_SCDLG_STRINPUT);
382 OSL_ENSURE(pDlg, "Dialog create fail!");
384 while ( !bDone && nRet == RET_OK )
386 nRet = pDlg->Execute();
388 if ( nRet == RET_OK )
390 pDlg->GetInputString( aName );
393 switch ( nSlot )
395 case FID_TAB_APPEND:
396 bDone = AppendTable( aName );
397 break;
398 case FID_TAB_RENAME:
399 bDone = RenameTable( aName, nTabNr );
400 break;
403 if ( bDone )
405 rReq.AppendItem( SfxStringItem( nSlot, aName ) );
406 rReq.Done();
408 else
410 if( rReq.IsAPI() )
412 #ifndef DISABLE_SCRIPTING
413 StarBASIC::Error( SbERR_SETPROP_FAILED ); // XXX Fehlerbehandlung???
414 #endif
416 else
418 nRet = ErrorBox( GetDialogParent(),
419 WinBits( WB_OK | WB_DEF_OK ),
420 aErrMsg
421 ).Execute();
426 delete pDlg;
429 break;
431 case FID_TAB_MOVE:
433 if ( pDoc->GetChangeTrack() != NULL )
434 break; // bei aktiviertem ChangeTracking kein TabMove
436 sal_Bool bDoIt = false;
437 sal_uInt16 nDoc = 0;
438 SCTAB nTab = pViewData->GetTabNo();
439 sal_Bool bCpy = false;
440 OUString aDocName;
441 OUString aTabName;
443 if( pReqArgs != NULL )
445 SCTAB nTableCount = pDoc->GetTableCount();
446 const SfxPoolItem* pItem;
448 if( pReqArgs->HasItem( FID_TAB_MOVE, &pItem ) )
449 aDocName = ((const SfxStringItem*)pItem)->GetValue();
450 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
452 // Tabelle ist 1-basiert
453 nTab = ((const SfxUInt16Item*)pItem)->GetValue() - 1;
454 if ( nTab >= nTableCount )
455 nTab = SC_TAB_APPEND;
457 if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
458 bCpy = ((const SfxBoolItem*)pItem)->GetValue();
460 if (!aDocName.isEmpty())
462 SfxObjectShell* pSh = SfxObjectShell::GetFirst();
463 ScDocShell* pScSh = NULL;
464 sal_uInt16 i=0;
466 while ( pSh )
468 pScSh = PTR_CAST( ScDocShell, pSh );
470 if( pScSh )
472 pScSh->GetTitle();
474 if (aDocName.equals(pScSh->GetTitle()))
476 nDoc = i;
477 ScDocument* pDestDoc = pScSh->GetDocument();
478 nTableCount = pDestDoc->GetTableCount();
479 bDoIt = pDestDoc->IsDocEditable();
480 break;
483 i++; // nur die ScDocShell's zaehlen
485 pSh = SfxObjectShell::GetNext( *pSh );
488 else // Kein Dokumentname -> neues Dokument
490 nDoc = SC_DOC_NEW;
491 bDoIt = sal_True;
494 if ( bDoIt && nTab >= nTableCount ) // ggf. anhaengen
495 nTab = SC_TAB_APPEND;
497 else
499 OUString aDefaultName;
500 pDoc->GetName( pViewData->GetTabNo(), aDefaultName );
502 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
503 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
505 AbstractScMoveTableDlg* pDlg = pFact->CreateScMoveTableDlg( GetDialogParent(),
506 aDefaultName,
507 RID_SCDLG_MOVETAB );
508 OSL_ENSURE(pDlg, "Dialog create fail!");
510 SCTAB nTableCount = pDoc->GetTableCount();
511 ScMarkData& rMark = GetViewData()->GetMarkData();
512 SCTAB nTabSelCount = rMark.GetSelectCount();
515 if(nTableCount==nTabSelCount)
517 pDlg->SetForceCopyTable();
520 // We support direct renaming of sheet only when one sheet
521 // is selected.
522 pDlg->EnableRenameTable(nTabSelCount == 1);
524 if ( pDlg->Execute() == RET_OK )
526 nDoc = pDlg->GetSelectedDocument();
527 nTab = pDlg->GetSelectedTable();
528 bCpy = pDlg->GetCopyTable();
529 bool bRna = pDlg->GetRenameTable();
530 // Leave aTabName string empty, when Rename is FALSE.
531 if( bRna )
533 pDlg->GetTabNameString( aTabName );
535 bDoIt = true;
537 String aFoundDocName;
538 if ( nDoc != SC_DOC_NEW )
540 ScDocShell* pSh = ScDocShell::GetShellByNum( nDoc );
541 if (pSh)
543 aFoundDocName = pSh->GetTitle();
544 if ( !pSh->GetDocument()->IsDocEditable() )
546 ErrorMessage(STR_READONLYERR);
547 bDoIt = false;
551 rReq.AppendItem( SfxStringItem( FID_TAB_MOVE, aFoundDocName ) );
552 // Tabelle ist 1-basiert, wenn nicht APPEND
553 SCTAB nBasicTab = ( nTab <= MAXTAB ) ? (nTab+1) : nTab;
554 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nBasicTab) ) );
555 rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bCpy ) );
557 delete pDlg;
560 if( bDoIt )
562 rReq.Done(); // aufzeichnen, solange das Dokument noch aktiv ist
564 MoveTable( nDoc, nTab, bCpy, &aTabName );
567 break;
569 case FID_DELETE_TABLE:
571 // Parameter war ueberfluessig, weil die Methode an der Table haengt
573 sal_Bool bDoIt = rReq.IsAPI();
574 if( !bDoIt )
576 // wenn's nicht von Basic kommt, nochmal nachfragen:
578 bDoIt = ( RET_YES ==
579 QueryBox( GetDialogParent(),
580 WinBits( WB_YES_NO | WB_DEF_YES ),
581 ScGlobal::GetRscString(STR_QUERY_DELTAB)
582 ).Execute() );
584 if( bDoIt )
586 SCTAB nNewTab = nCurrentTab;
587 SCTAB nFirstTab=0;
588 bool bTabFlag=false;
589 ScMarkData& rMark = pViewData->GetMarkData();
590 std::vector<SCTAB> TheTabs;
591 for(SCTAB i=0;i<nTabCount;i++)
593 if(rMark.GetTableSelect(i) &&!pDoc->IsTabProtected(i))
595 TheTabs.push_back(i);
596 bTabFlag=true;
597 if(nNewTab==i) nNewTab++;
599 if(!bTabFlag) nFirstTab=i;
601 if(nNewTab>=nTabCount) nNewTab=nFirstTab;
603 pViewData->SetTabNo(nNewTab);
604 DeleteTables(TheTabs);
605 TheTabs.clear();
606 rReq.Done();
609 break;
611 case FID_TAB_RTL:
613 ScDocShell* pDocSh = pViewData->GetDocShell();
614 ScDocFunc &rFunc = pDocSh->GetDocFunc();
615 sal_Bool bSet = !pDoc->IsLayoutRTL( nCurrentTab );
617 const ScMarkData& rMark = pViewData->GetMarkData();
618 if ( rMark.GetSelectCount() != 0 )
620 // handle several sheets
622 ::svl::IUndoManager* pUndoManager = pDocSh->GetUndoManager();
623 String aUndo = ScGlobal::GetRscString( STR_UNDO_TAB_RTL );
624 pUndoManager->EnterListAction( aUndo, aUndo );
626 ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
627 for (; itr != itrEnd; ++itr)
628 rFunc.SetLayoutRTL( *itr, bSet, false );
630 pUndoManager->LeaveListAction();
632 else
633 rFunc.SetLayoutRTL( nCurrentTab, bSet, false );
635 break;
637 case FID_TAB_TOGGLE_GRID:
639 bool bShowGrid = pViewData->GetShowGrid();
640 pViewData->SetShowGrid(!bShowGrid);
641 SfxBindings& rBindings = GetViewFrame()->GetBindings();
642 rBindings.Invalidate( FID_TAB_TOGGLE_GRID );
643 PaintGrid();
644 rReq.Done();
646 break;
648 case FID_TAB_SET_TAB_BG_COLOR:
649 case FID_TAB_MENU_SET_TAB_BG_COLOR:
651 if ( nSlot == FID_TAB_MENU_SET_TAB_BG_COLOR )
652 nSlot = FID_TAB_SET_TAB_BG_COLOR;
653 SCTAB nTabNr = pViewData->GetTabNo();
654 ScMarkData& rMark = pViewData->GetMarkData();
655 SCTAB nTabSelCount = rMark.GetSelectCount();
656 if ( !pDoc->IsDocEditable() )
657 break;
659 if ( pDoc->IsTabProtected( nTabNr ) ) // ||nTabSelCount > 1
660 break;
662 if( pReqArgs != NULL )
664 sal_Bool bDone = false;
665 const SfxPoolItem* pItem;
666 Color aColor;
667 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
668 nTabNr = ((const SfxUInt16Item*)pItem)->GetValue();
670 if( pReqArgs->HasItem( nSlot, &pItem ) )
671 aColor = ((const SvxColorItem*)pItem)->GetValue();
673 if ( nTabSelCount > 1 )
675 scoped_ptr<ScUndoTabColorInfo::List>
676 pTabColorList(new ScUndoTabColorInfo::List);
677 ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end();
678 for (; itr != itrEnd; ++itr)
680 if ( !pDoc->IsTabProtected(*itr) )
682 ScUndoTabColorInfo aTabColorInfo(*itr);
683 aTabColorInfo.maNewTabBgColor = aColor;
684 pTabColorList->push_back(aTabColorInfo);
687 bDone = SetTabBgColor( *pTabColorList );
689 else
691 bDone = SetTabBgColor( aColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
693 if( bDone )
695 rReq.Done( *pReqArgs );
698 else
700 sal_uInt16 nRet = RET_OK; /// temp
701 sal_Bool bDone = false; /// temp
702 Color aTabBgColor;
704 aTabBgColor = pDoc->GetTabBgColor( nCurrentTab );
705 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
706 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
707 AbstractScTabBgColorDlg* pDlg = pFact->CreateScTabBgColorDlg(
708 GetDialogParent(),
709 String(ScResId(SCSTR_SET_TAB_BG_COLOR)),
710 String(ScResId(SCSTR_NO_TAB_BG_COLOR)),
711 aTabBgColor,
712 CMD_FID_TAB_SET_TAB_BG_COLOR,
713 RID_SCDLG_TAB_BG_COLOR);
714 while ( !bDone && nRet == RET_OK )
716 nRet = pDlg->Execute();
717 if( nRet == RET_OK )
719 Color aSelectedColor;
720 pDlg->GetSelectedColor(aSelectedColor);
721 scoped_ptr<ScUndoTabColorInfo::List>
722 pTabColorList(new ScUndoTabColorInfo::List);
723 if ( nTabSelCount > 1 )
725 ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end();
726 for (; itr != itrEnd; ++itr)
728 if ( !pDoc->IsTabProtected(*itr) )
730 ScUndoTabColorInfo aTabColorInfo(*itr);
731 aTabColorInfo.maNewTabBgColor = aSelectedColor;
732 pTabColorList->push_back(aTabColorInfo);
735 bDone = SetTabBgColor( *pTabColorList );
737 else
739 bDone = SetTabBgColor( aSelectedColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
741 if ( bDone )
743 rReq.AppendItem( SvxColorItem( aTabBgColor, nSlot ) );
744 rReq.Done();
746 else
748 if( rReq.IsAPI() )
750 #ifndef DISABLE_SCRIPTING
751 StarBASIC::Error( SbERR_SETPROP_FAILED );
752 #endif
757 delete( pDlg );
760 break;
762 case FID_TAB_EVENTS:
764 ScDocShell* pDocSh = pViewData->GetDocShell();
765 uno::Reference<container::XNameReplace> xEvents( new ScSheetEventsObj( pDocSh, nCurrentTab ) );
766 uno::Reference<frame::XFrame> xFrame = GetViewFrame()->GetFrame().GetFrameInterface();
767 SvxAbstractDialogFactory* pDlgFactory = SvxAbstractDialogFactory::Create();
768 if (pDlgFactory)
770 std::auto_ptr<VclAbstractDialog> pDialog( pDlgFactory->CreateSvxMacroAssignDlg(
771 GetDialogParent(), xFrame, false, xEvents, 0 ) );
772 if ( pDialog.get() && pDialog->Execute() == RET_OK )
774 // the dialog modifies the settings directly
778 break;
780 default:
781 OSL_FAIL("Unbekannte Message bei ViewShell");
782 break;
786 //------------------------------------------------------------------
788 void ScTabViewShell::GetStateTable( SfxItemSet& rSet )
790 ScViewData* pViewData = GetViewData();
791 ScDocument* pDoc = pViewData->GetDocument();
792 ScDocShell* pDocShell = pViewData->GetDocShell();
793 ScMarkData& rMark = GetViewData()->GetMarkData();
794 SCTAB nTab = pViewData->GetTabNo();
796 SCTAB nTabCount = pDoc->GetTableCount();
797 SCTAB nTabSelCount = rMark.GetSelectCount();
799 SfxWhichIter aIter(rSet);
800 sal_uInt16 nWhich = aIter.FirstWhich();
802 while ( nWhich )
804 switch ( nWhich )
807 case FID_TABLE_VISIBLE:
808 rSet.Put( SfxBoolItem( nWhich, pDoc->IsVisible(nTab) ));
809 break;
811 case FID_TABLE_HIDE:
813 sal_uInt16 nVis = 0;
814 // enable menu : check to make sure we won't hide all sheets. we need at least one visible at all times.
815 for ( SCTAB i=0; i < nTabCount && nVis<nTabSelCount + 1; i++ )
816 if (pDoc->IsVisible(i))
817 ++nVis;
818 if ( nVis<=nTabSelCount || !pDoc->IsDocEditable() )
819 rSet.DisableItem( nWhich );
821 break;
823 case FID_TABLE_SHOW:
825 sal_Bool bHasHidden = false;
826 for ( SCTAB i=0; i < nTabCount && !bHasHidden; i++ )
827 if (!pDoc->IsVisible(i))
828 bHasHidden = sal_True;
829 if ( !bHasHidden || pDoc->IsDocProtected() || nTabSelCount > 1 )
830 rSet.DisableItem( nWhich );
832 break;
834 case FID_DELETE_TABLE:
836 if ( pDoc->GetChangeTrack() )
837 rSet.DisableItem( nWhich );
838 else
840 sal_uInt16 nVis = 0;
841 for ( SCTAB i=0; i < nTabCount && nVis<2; i++ )
842 if (pDoc->IsVisible(i))
843 ++nVis;
844 if ( pDoc->IsTabProtected(nTab)
845 || !pDoc->IsDocEditable()
846 || nVis < 2
847 || nTabSelCount == nTabCount)
848 rSet.DisableItem( nWhich );
851 break;
853 case FID_INS_TABLE:
854 case FID_INS_TABLE_EXT:
855 case FID_TAB_APPEND:
856 if ( !pDoc->IsDocEditable() ||
857 nTabCount > MAXTAB ||
858 ( nWhich == FID_INS_TABLE_EXT && pDocShell && pDocShell->IsDocShared() ) )
859 rSet.DisableItem( nWhich );
860 break;
862 case FID_TAB_MOVE:
863 if ( !pDoc->IsDocEditable()
864 || pDoc->GetChangeTrack() != NULL
865 || nTabCount > MAXTAB)
866 rSet.DisableItem( nWhich );
867 break;
869 // FID_TAB_MENU_RENAME - "umbenennen" im Menu
870 // FID_TAB_RENAME - "Name"-Property fuer Basic
872 case FID_TAB_MENU_RENAME:
873 if ( !pDoc->IsDocEditable() ||
874 pDoc->IsTabProtected(nTab) ||nTabSelCount > 1 ||
875 ( pDocShell && pDocShell->IsDocShared() ) )
876 rSet.DisableItem( nWhich );
877 break;
879 case FID_TAB_RENAME:
881 OUString aTabName;
882 pDoc->GetName( nTab, aTabName );
884 rSet.Put( SfxStringItem( nWhich, aTabName ));
887 break;
889 case FID_TAB_RTL:
891 SvtLanguageOptions aLangOpt;
892 if ( !aLangOpt.IsCTLFontEnabled() )
893 rSet.DisableItem( nWhich );
894 else
895 rSet.Put( SfxBoolItem( nWhich, pDoc->IsLayoutRTL( nTab ) ) );
897 break;
899 case FID_TAB_MENU_SET_TAB_BG_COLOR:
901 if ( !pDoc->IsDocEditable()
902 || ( pDocShell && pDocShell->IsDocShared() )
903 || pDoc->IsTabProtected(nTab) )
904 rSet.DisableItem( nWhich );
906 break;
908 case FID_TAB_SET_TAB_BG_COLOR:
910 Color aColor;
911 aColor = pDoc->GetTabBgColor( nTab );
912 rSet.Put( SvxColorItem( aColor, nWhich ) );
914 break;
916 case FID_TAB_TOGGLE_GRID:
917 rSet.Put( SfxBoolItem(nWhich, pViewData->GetShowGrid()) );
918 break;
920 nWhich = aIter.NextWhich();
927 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */