fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / view / tabvwshf.cxx
blobc3ae18dfa9d8cec4907cc9deff190f6a0603d960
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 <config_features.h>
22 #include <boost/scoped_ptr.hpp>
24 #include "scitems.hxx"
25 #include <sfx2/request.hxx>
26 #include <sfx2/bindings.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <basic/sbstar.hxx>
29 #include <svl/languageoptions.hxx>
30 #include <svl/stritem.hxx>
31 #include <svl/whiter.hxx>
32 #include <vcl/msgbox.hxx>
33 #include <sfx2/objface.hxx>
34 #include <svx/svxdlg.hxx>
35 #include <editeng/colritem.hxx>
37 #include "tabvwsh.hxx"
38 #include "sc.hrc"
39 #include "docsh.hxx"
40 #include "document.hxx"
41 #include "shtabdlg.hxx"
42 #include "scresid.hxx"
43 #include "globstr.hrc"
44 #include "docfunc.hxx"
45 #include "eventuno.hxx"
47 #include "scabstdlg.hxx"
49 #include "tabbgcolor.hxx"
50 #include "tabbgcolordlg.hxx"
51 #include "sccommands.h"
52 #include "markdata.hxx"
54 #include <vector>
56 using ::boost::scoped_ptr;
57 using namespace com::sun::star;
59 void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
61 ScViewData& rViewData = GetViewData();
62 ScDocument* pDoc = rViewData.GetDocument();
64 SCTAB nCurrentTab = rViewData.GetTabNo();
65 SCTAB nTabCount = pDoc->GetTableCount();
66 sal_uInt16 nSlot = rReq.GetSlot();
67 const SfxItemSet* pReqArgs = rReq.GetArgs();
69 HideListBox(); // Autofilter-DropDown-Listbox
71 switch ( nSlot )
73 case FID_TABLE_VISIBLE:
75 OUString aName;
76 pDoc->GetName( nCurrentTab, aName );
78 bool bVisible=true;
79 if( pReqArgs != NULL )
81 const SfxPoolItem* pItem;
82 if( pReqArgs->HasItem( FID_TABLE_VISIBLE, &pItem ) )
83 bVisible = static_cast<const SfxBoolItem*>(pItem)->GetValue();
86 if( ! bVisible ) // fade out
88 if ( pDoc->IsDocEditable() )
90 ScMarkData& rMark = rViewData.GetMarkData();
91 HideTable( rMark );
94 else // fade in
96 std::vector<OUString> rNames;
97 rNames.push_back(aName);
98 ShowTable( rNames );
101 break;
103 case FID_TABLE_HIDE:
105 if ( pDoc->IsDocEditable() )
107 ScMarkData& rMark = rViewData.GetMarkData();
108 HideTable( rMark );
111 break;
113 case FID_TABLE_SHOW:
115 OUString aName;
116 std::vector<OUString> rNames;
117 if ( pReqArgs )
119 const SfxPoolItem* pItem;
120 if( pReqArgs->HasItem( FID_TABLE_SHOW, &pItem ) )
122 aName = static_cast<const SfxStringItem*>(pItem)->GetValue();
123 rNames.push_back(aName);
124 ShowTable( rNames );
126 if( ! rReq.IsAPI() )
127 rReq.Done();
130 else
132 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
133 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
135 boost::scoped_ptr<AbstractScShowTabDlg> pDlg(pFact->CreateScShowTabDlg(GetDialogParent()));
136 OSL_ENSURE(pDlg, "Dialog create fail!");
138 OUString aTabName;
139 bool bFirst = true;
140 for ( SCTAB i=0; i != nTabCount; i++ )
142 if (!pDoc->IsVisible(i))
144 pDoc->GetName( i, aTabName );
145 pDlg->Insert( aTabName, bFirst );
146 bFirst = false;
150 if ( pDlg->Execute() == RET_OK )
152 sal_uInt16 nCount = pDlg->GetSelectEntryCount();
153 for (sal_uInt16 nPos=0; nPos<nCount; nPos++)
155 aName = pDlg->GetSelectEntry(nPos);
156 rReq.AppendItem( SfxStringItem( FID_TABLE_SHOW, aName ) );
157 rNames.push_back(aName);
159 ShowTable( rNames );
160 rReq.Done();
164 break;
166 case FID_INS_TABLE:
167 case FID_INS_TABLE_EXT:
169 ScMarkData& rMark = rViewData.GetMarkData();
170 SCTAB nTabSelCount = rMark.GetSelectCount();
171 SCTAB nTabNr = nCurrentTab;
173 if ( !pDoc->IsDocEditable() )
174 break; // locked
176 if ( pReqArgs != NULL ) // from basic
178 bool bOk = false;
179 const SfxPoolItem* pTabItem;
180 const SfxPoolItem* pNameItem;
181 OUString aName;
183 if ( pReqArgs->HasItem( FN_PARAM_1, &pTabItem ) &&
184 pReqArgs->HasItem( nSlot, &pNameItem ) )
186 // tablenumber from basic: 1-based
188 aName = static_cast<const SfxStringItem*>(pNameItem)->GetValue();
189 nTabNr = static_cast<const SfxUInt16Item*>(pTabItem)->GetValue() - 1;
190 if ( nTabNr < nTabCount )
191 bOk = InsertTable( aName, nTabNr );
194 if (bOk)
195 rReq.Done( *pReqArgs );
196 //! else set error
198 else // dialog
200 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
201 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
203 boost::scoped_ptr<AbstractScInsertTableDlg> pDlg(pFact->CreateScInsertTableDlg(GetDialogParent(), rViewData,
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 OUString* pStr = pDlg->GetFirstTable( &n );
213 while ( pStr )
215 nTabs.push_back( static_cast<SCTAB>(n) );
216 pStr = pDlg->GetNextTable( &n );
218 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()->isEmpty())
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()->isEmpty())
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);
297 break;
299 case FID_TAB_APPEND:
300 case FID_TAB_RENAME:
301 case FID_TAB_MENU_RENAME:
303 // FID_TAB_MENU_RENAME - "rename" in menu
304 // FID_TAB_RENAME - "name"-property for basic
305 // equal execute, but MENU_RENAME may be disabled inside GetState
307 if ( nSlot == FID_TAB_MENU_RENAME )
308 nSlot = FID_TAB_RENAME; // equal execute
310 SCTAB nTabNr = rViewData.GetTabNo();
311 ScMarkData& rMark = rViewData.GetMarkData();
312 SCTAB nTabSelCount = rMark.GetSelectCount();
314 if ( !pDoc->IsDocEditable() )
315 break; // evrything locked
317 if ( nSlot != FID_TAB_APPEND &&
318 ( pDoc->IsTabProtected( nTabNr ) || nTabSelCount > 1 ) )
319 break; // no rename
321 if( pReqArgs != NULL )
323 bool bDone = false;
324 const SfxPoolItem* pItem;
325 OUString aName;
327 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
328 nTabNr = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
330 if( pReqArgs->HasItem( nSlot, &pItem ) )
331 aName = static_cast<const SfxStringItem*>(pItem)->GetValue();
333 switch ( nSlot )
335 case FID_TAB_APPEND:
336 bDone = AppendTable( aName );
337 break;
338 case FID_TAB_RENAME:
339 bDone = RenameTable( aName, nTabNr );
340 break;
343 if( bDone )
345 rReq.Done( *pReqArgs );
348 else
350 sal_uInt16 nRet = RET_OK;
351 bool bDone = false;
352 OUString aErrMsg ( ScGlobal::GetRscString( STR_INVALIDTABNAME ) );
353 OUString aName;
354 OUString aDlgTitle;
355 const sal_Char* pHelpId = 0;
357 switch ( nSlot )
359 case FID_TAB_APPEND:
360 aDlgTitle = OUString(ScResId(SCSTR_APDTABLE));
361 pDoc->CreateValidTabName( aName );
362 pHelpId = HID_SC_APPEND_NAME;
363 break;
365 case FID_TAB_RENAME:
366 aDlgTitle = OUString(ScResId(SCSTR_RENAMETAB));
367 pDoc->GetName( rViewData.GetTabNo(), aName );
368 pHelpId = HID_SC_RENAME_NAME;
369 break;
372 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
373 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
375 boost::scoped_ptr<AbstractScStringInputDlg> pDlg(pFact->CreateScStringInputDlg(
376 GetDialogParent(), aDlgTitle, OUString(ScResId(SCSTR_NAME)),
377 aName, GetStaticInterface()->GetSlot(nSlot)->GetCommand(),
378 pHelpId));
380 OSL_ENSURE(pDlg, "Dialog create fail!");
382 while ( !bDone && nRet == RET_OK )
384 nRet = pDlg->Execute();
386 if ( nRet == RET_OK )
388 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 #if HAVE_FEATURE_SCRIPTING
410 StarBASIC::Error( SbERR_SETPROP_FAILED ); // XXX error handling???
411 #endif
413 else
415 nRet = ScopedVclPtr<MessageDialog>::Create(GetDialogParent(),
416 aErrMsg
417 )->Execute();
424 break;
426 case FID_TAB_MOVE:
428 if ( pDoc->GetChangeTrack() != NULL )
429 break; // if ChangeTracking is active, then no TabMove
431 bool bDoIt = false;
432 sal_uInt16 nDoc = 0;
433 SCTAB nTab = rViewData.GetTabNo();
434 bool bCpy = false;
435 OUString aDocName;
436 OUString aTabName;
438 if( pReqArgs != NULL )
440 SCTAB nTableCount = pDoc->GetTableCount();
441 const SfxPoolItem* pItem;
443 if( pReqArgs->HasItem( FID_TAB_MOVE, &pItem ) )
444 aDocName = static_cast<const SfxStringItem*>(pItem)->GetValue();
445 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
447 // table is 1-based
448 nTab = static_cast<const SfxUInt16Item*>(pItem)->GetValue() - 1;
449 if ( nTab >= nTableCount )
450 nTab = SC_TAB_APPEND;
452 if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
453 bCpy = static_cast<const SfxBoolItem*>(pItem)->GetValue();
455 if (!aDocName.isEmpty())
457 SfxObjectShell* pSh = SfxObjectShell::GetFirst();
458 ScDocShell* pScSh = NULL;
459 sal_uInt16 i=0;
461 while ( pSh )
463 pScSh = PTR_CAST( ScDocShell, pSh );
465 if( pScSh )
467 pScSh->GetTitle();
469 if (aDocName.equals(pScSh->GetTitle()))
471 nDoc = i;
472 ScDocument& rDestDoc = pScSh->GetDocument();
473 nTableCount = rDestDoc.GetTableCount();
474 bDoIt = rDestDoc.IsDocEditable();
475 break;
478 i++; // only count ScDocShell
480 pSh = SfxObjectShell::GetNext( *pSh );
483 else // no doc-name -> new doc
485 nDoc = SC_DOC_NEW;
486 bDoIt = true;
489 if ( bDoIt && nTab >= nTableCount ) // if necessary append
490 nTab = SC_TAB_APPEND;
492 else
494 OUString aDefaultName;
495 pDoc->GetName( rViewData.GetTabNo(), aDefaultName );
497 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
498 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
500 boost::scoped_ptr<AbstractScMoveTableDlg> pDlg(pFact->CreateScMoveTableDlg(GetDialogParent(),
501 aDefaultName));
502 OSL_ENSURE(pDlg, "Dialog create fail!");
504 SCTAB nTableCount = pDoc->GetTableCount();
505 ScMarkData& rMark = GetViewData().GetMarkData();
506 SCTAB nTabSelCount = rMark.GetSelectCount();
508 if(nTableCount==nTabSelCount)
510 pDlg->SetForceCopyTable();
513 // We support direct renaming of sheet only when one sheet
514 // is selected.
515 pDlg->EnableRenameTable(nTabSelCount == 1);
517 if ( pDlg->Execute() == RET_OK )
519 nDoc = pDlg->GetSelectedDocument();
520 nTab = pDlg->GetSelectedTable();
521 bCpy = pDlg->GetCopyTable();
522 bool bRna = pDlg->GetRenameTable();
523 // Leave aTabName string empty, when Rename is FALSE.
524 if( bRna )
526 pDlg->GetTabNameString( aTabName );
528 bDoIt = true;
530 OUString aFoundDocName;
531 if ( nDoc != SC_DOC_NEW )
533 ScDocShell* pSh = ScDocShell::GetShellByNum( nDoc );
534 if (pSh)
536 aFoundDocName = pSh->GetTitle();
537 if ( !pSh->GetDocument().IsDocEditable() )
539 ErrorMessage(STR_READONLYERR);
540 bDoIt = false;
544 rReq.AppendItem( SfxStringItem( FID_TAB_MOVE, aFoundDocName ) );
545 // 1-based table, if not APPEND
546 SCTAB nBasicTab = ( nTab <= MAXTAB ) ? (nTab+1) : nTab;
547 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nBasicTab) ) );
548 rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bCpy ) );
552 if( bDoIt )
554 rReq.Done(); // record, while doc is active
556 MoveTable( nDoc, nTab, bCpy, &aTabName );
559 break;
561 case FID_DELETE_TABLE:
563 // unnecessary parameter -> method depends on table
565 bool bDoIt = rReq.IsAPI();
566 if( !bDoIt )
568 // source isn't basic -> ask again
570 bDoIt = ( RET_YES ==
571 ScopedVclPtr<QueryBox>::Create( GetDialogParent(),
572 WinBits( WB_YES_NO | WB_DEF_YES ),
573 ScGlobal::GetRscString(STR_QUERY_DELTAB)
574 )->Execute() );
576 if( bDoIt )
578 SCTAB nNewTab = nCurrentTab;
579 SCTAB nFirstTab=0;
580 bool bTabFlag=false;
581 ScMarkData& rMark = rViewData.GetMarkData();
582 std::vector<SCTAB> TheTabs;
583 for(SCTAB i=0;i<nTabCount;i++)
585 if(rMark.GetTableSelect(i) &&!pDoc->IsTabProtected(i))
587 TheTabs.push_back(i);
588 bTabFlag=true;
589 if(nNewTab==i) nNewTab++;
591 if(!bTabFlag) nFirstTab=i;
593 if(nNewTab>=nTabCount) nNewTab=nFirstTab;
595 rViewData.SetTabNo(nNewTab);
596 DeleteTables(TheTabs);
597 TheTabs.clear();
598 rReq.Done();
601 break;
603 case FID_TAB_RTL:
605 ScDocShell* pDocSh = rViewData.GetDocShell();
606 ScDocFunc &rFunc = pDocSh->GetDocFunc();
607 bool bSet = !pDoc->IsLayoutRTL( nCurrentTab );
609 const ScMarkData& rMark = rViewData.GetMarkData();
610 if ( rMark.GetSelectCount() != 0 )
612 // handle several sheets
614 ::svl::IUndoManager* pUndoManager = pDocSh->GetUndoManager();
615 OUString aUndo = ScGlobal::GetRscString( STR_UNDO_TAB_RTL );
616 pUndoManager->EnterListAction( aUndo, aUndo );
618 ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
619 for (; itr != itrEnd; ++itr)
620 rFunc.SetLayoutRTL( *itr, bSet, false );
622 pUndoManager->LeaveListAction();
624 else
625 rFunc.SetLayoutRTL( nCurrentTab, bSet, false );
627 break;
629 case FID_TAB_TOGGLE_GRID:
631 bool bShowGrid = rViewData.GetShowGrid();
632 rViewData.SetShowGrid(!bShowGrid);
633 SfxBindings& rBindings = GetViewFrame()->GetBindings();
634 rBindings.Invalidate( FID_TAB_TOGGLE_GRID );
635 PaintGrid();
636 rReq.Done();
638 break;
640 case FID_TAB_SET_TAB_BG_COLOR:
641 case FID_TAB_MENU_SET_TAB_BG_COLOR:
643 if ( nSlot == FID_TAB_MENU_SET_TAB_BG_COLOR )
644 nSlot = FID_TAB_SET_TAB_BG_COLOR;
645 SCTAB nTabNr = rViewData.GetTabNo();
646 ScMarkData& rMark = rViewData.GetMarkData();
647 SCTAB nTabSelCount = rMark.GetSelectCount();
648 if ( !pDoc->IsDocEditable() )
649 break;
651 if ( pDoc->IsTabProtected( nTabNr ) ) // ||nTabSelCount > 1
652 break;
654 if( pReqArgs != NULL )
656 bool bDone = false;
657 const SfxPoolItem* pItem;
658 Color aColor;
659 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
660 nTabNr = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
662 if( pReqArgs->HasItem( nSlot, &pItem ) )
663 aColor = static_cast<const SvxColorItem*>(pItem)->GetValue();
665 if ( nTabSelCount > 1 )
667 scoped_ptr<ScUndoTabColorInfo::List>
668 pTabColorList(new ScUndoTabColorInfo::List);
669 ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end();
670 for (; itr != itrEnd; ++itr)
672 if ( !pDoc->IsTabProtected(*itr) )
674 ScUndoTabColorInfo aTabColorInfo(*itr);
675 aTabColorInfo.maNewTabBgColor = aColor;
676 pTabColorList->push_back(aTabColorInfo);
679 bDone = SetTabBgColor( *pTabColorList );
681 else
683 bDone = SetTabBgColor( aColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
685 if( bDone )
687 rReq.Done( *pReqArgs );
690 else
692 sal_uInt16 nRet = RET_OK; /// temp
693 bool bDone = false; /// temp
694 Color aTabBgColor;
696 aTabBgColor = pDoc->GetTabBgColor( nCurrentTab );
697 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
698 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
699 boost::scoped_ptr<AbstractScTabBgColorDlg> pDlg(pFact->CreateScTabBgColorDlg(
700 GetDialogParent(),
701 OUString(ScResId(SCSTR_SET_TAB_BG_COLOR)),
702 OUString(ScResId(SCSTR_NO_TAB_BG_COLOR)),
703 aTabBgColor,
704 CMD_FID_TAB_SET_TAB_BG_COLOR));
705 while ( !bDone && nRet == RET_OK )
707 nRet = pDlg->Execute();
708 if( nRet == RET_OK )
710 Color aSelectedColor;
711 pDlg->GetSelectedColor(aSelectedColor);
712 scoped_ptr<ScUndoTabColorInfo::List>
713 pTabColorList(new ScUndoTabColorInfo::List);
714 if ( nTabSelCount > 1 )
716 ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end();
717 for (; itr != itrEnd; ++itr)
719 if ( !pDoc->IsTabProtected(*itr) )
721 ScUndoTabColorInfo aTabColorInfo(*itr);
722 aTabColorInfo.maNewTabBgColor = aSelectedColor;
723 pTabColorList->push_back(aTabColorInfo);
726 bDone = SetTabBgColor( *pTabColorList );
728 else
730 bDone = SetTabBgColor( aSelectedColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
732 if ( bDone )
734 rReq.AppendItem( SvxColorItem( aTabBgColor, nSlot ) );
735 rReq.Done();
737 else
739 if( rReq.IsAPI() )
741 #if HAVE_FEATURE_SCRIPTING
742 StarBASIC::Error( SbERR_SETPROP_FAILED );
743 #endif
750 break;
752 case FID_TAB_EVENTS:
754 ScDocShell* pDocSh = rViewData.GetDocShell();
755 uno::Reference<container::XNameReplace> xEvents( new ScSheetEventsObj( pDocSh, nCurrentTab ) );
756 uno::Reference<frame::XFrame> xFrame = GetViewFrame()->GetFrame().GetFrameInterface();
757 SvxAbstractDialogFactory* pDlgFactory = SvxAbstractDialogFactory::Create();
758 if (pDlgFactory)
760 boost::scoped_ptr<VclAbstractDialog> pDialog( pDlgFactory->CreateSvxMacroAssignDlg(
761 GetDialogParent(), xFrame, false, xEvents, 0 ) );
762 if ( pDialog.get() && pDialog->Execute() == RET_OK )
764 // the dialog modifies the settings directly
768 break;
770 default:
771 OSL_FAIL("Unbekannte Message bei ViewShell");
772 break;
776 void ScTabViewShell::GetStateTable( SfxItemSet& rSet )
778 ScViewData& rViewData = GetViewData();
779 ScDocument* pDoc = rViewData.GetDocument();
780 ScDocShell* pDocShell = rViewData.GetDocShell();
781 ScMarkData& rMark = GetViewData().GetMarkData();
782 SCTAB nTab = rViewData.GetTabNo();
784 SCTAB nTabCount = pDoc->GetTableCount();
785 SCTAB nTabSelCount = rMark.GetSelectCount();
787 SfxWhichIter aIter(rSet);
788 sal_uInt16 nWhich = aIter.FirstWhich();
790 while ( nWhich )
792 switch ( nWhich )
795 case FID_TABLE_VISIBLE:
796 rSet.Put( SfxBoolItem( nWhich, pDoc->IsVisible(nTab) ));
797 break;
799 case FID_TABLE_HIDE:
801 sal_uInt16 nVis = 0;
802 // enable menu : check to make sure we won't hide all sheets. we need at least one visible at all times.
803 for ( SCTAB i=0; i < nTabCount && nVis<nTabSelCount + 1; i++ )
804 if (pDoc->IsVisible(i))
805 ++nVis;
806 if ( nVis<=nTabSelCount || !pDoc->IsDocEditable() )
807 rSet.DisableItem( nWhich );
809 break;
811 case FID_TABLE_SHOW:
813 bool bHasHidden = false;
814 for ( SCTAB i=0; i < nTabCount && !bHasHidden; i++ )
815 if (!pDoc->IsVisible(i))
816 bHasHidden = true;
817 if ( !bHasHidden || pDoc->IsDocProtected() || nTabSelCount > 1 )
818 rSet.DisableItem( nWhich );
820 break;
822 case FID_DELETE_TABLE:
824 if ( pDoc->GetChangeTrack() )
825 rSet.DisableItem( nWhich );
826 else
828 sal_uInt16 nVis = 0;
829 for ( SCTAB i=0; i < nTabCount && nVis<2; i++ )
830 if (pDoc->IsVisible(i))
831 ++nVis;
832 if ( pDoc->IsTabProtected(nTab)
833 || !pDoc->IsDocEditable()
834 || nVis < 2
835 || nTabSelCount == nTabCount)
836 rSet.DisableItem( nWhich );
839 break;
841 case FID_INS_TABLE:
842 case FID_INS_TABLE_EXT:
843 case FID_TAB_APPEND:
844 if ( !pDoc->IsDocEditable() ||
845 nTabCount > MAXTAB ||
846 ( nWhich == FID_INS_TABLE_EXT && pDocShell && pDocShell->IsDocShared() ) )
847 rSet.DisableItem( nWhich );
848 break;
850 case FID_TAB_MOVE:
851 if ( !pDoc->IsDocEditable()
852 || pDoc->GetChangeTrack() != NULL
853 || nTabCount > MAXTAB)
854 rSet.DisableItem( nWhich );
855 break;
857 // FID_TAB_MENU_RENAME - "rename" from Menu
858 // FID_TAB_RENAME - "name"-property for Basic
860 case FID_TAB_MENU_RENAME:
861 if ( !pDoc->IsDocEditable() ||
862 pDoc->IsTabProtected(nTab) ||nTabSelCount > 1 ||
863 ( pDocShell && pDocShell->IsDocShared() ) )
864 rSet.DisableItem( nWhich );
865 break;
867 case FID_TAB_RENAME:
869 OUString aTabName;
870 pDoc->GetName( nTab, aTabName );
872 rSet.Put( SfxStringItem( nWhich, aTabName ));
875 break;
877 case FID_TAB_RTL:
879 SvtLanguageOptions aLangOpt;
880 if ( !aLangOpt.IsCTLFontEnabled() )
881 rSet.DisableItem( nWhich );
882 else
883 rSet.Put( SfxBoolItem( nWhich, pDoc->IsLayoutRTL( nTab ) ) );
885 break;
887 case FID_TAB_MENU_SET_TAB_BG_COLOR:
889 if ( !pDoc->IsDocEditable()
890 || ( pDocShell && pDocShell->IsDocShared() )
891 || pDoc->IsTabProtected(nTab) )
892 rSet.DisableItem( nWhich );
894 break;
896 case FID_TAB_SET_TAB_BG_COLOR:
898 Color aColor;
899 aColor = pDoc->GetTabBgColor( nTab );
900 rSet.Put( SvxColorItem( aColor, nWhich ) );
902 break;
904 case FID_TAB_TOGGLE_GRID:
905 rSet.Put( SfxBoolItem(nWhich, rViewData.GetShowGrid()) );
906 break;
908 nWhich = aIter.NextWhich();
912 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */