Update ooo320-m1
[ooovba.git] / sc / source / ui / view / tabvwshf.cxx
blob971e646a913f4a221c53d5df75a9428e1eb6a74f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tabvwshf.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #include "scitems.hxx"
39 #include <sfx2/request.hxx>
40 #include <sfx2/bindings.hxx>
41 #include <sfx2/viewfrm.hxx>
42 #include <basic/sbstar.hxx>
43 #include <layout/layout.hxx>
44 #include <svtools/languageoptions.hxx>
45 #include <svtools/stritem.hxx>
46 #include <svtools/whiter.hxx>
47 #include <vcl/msgbox.hxx>
49 #include "tabvwsh.hxx"
50 #include "sc.hrc"
51 #include "docsh.hxx"
52 #include "document.hxx"
53 #include "shtabdlg.hxx"
54 #include "scresid.hxx"
55 //CHINA001 #include "instbdlg.hxx"
56 #include "globstr.hrc"
57 //CHINA001 #include "strindlg.hxx"
58 //CHINA001 #include "mvtabdlg.hxx"
59 #include "docfunc.hxx"
61 #include "scabstdlg.hxx" //CHINA001
63 #include "tabbgcolor.hxx" //DBW
64 #include "tabbgcolordlg.hxx" //DBW
65 #include <svx/colritem.hxx> //DBW
67 #define IS_AVAILABLE(WhichId,ppItem) \
68 (pReqArgs->GetItemState((WhichId), TRUE, ppItem ) == SFX_ITEM_SET)
70 //------------------------------------------------------------------
72 void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
74 ScViewData* pViewData = GetViewData();
75 ScDocument* pDoc = pViewData->GetDocument();
77 SCTAB nCurrentTab = pViewData->GetTabNo();
78 SCTAB nTabCount = pDoc->GetTableCount();
79 USHORT nSlot = rReq.GetSlot();
80 const SfxItemSet* pReqArgs = rReq.GetArgs();
82 HideListBox(); // Autofilter-DropDown-Listbox
84 switch ( nSlot )
86 case FID_TABLE_VISIBLE:
88 String aName;
89 pDoc->GetName( nCurrentTab, aName );
91 BOOL bVisible=TRUE;
92 if( pReqArgs != NULL )
94 const SfxPoolItem* pItem;
95 if( IS_AVAILABLE( FID_TABLE_VISIBLE, &pItem ) )
96 bVisible = ((const SfxBoolItem*)pItem)->GetValue();
99 if( ! bVisible ) // ausblenden
101 ScMarkData& rMark = pViewData->GetMarkData();
102 SCTAB nTabSelCount = rMark.GetSelectCount();
103 USHORT nVis = 0;
104 for ( SCTAB i=0; i < nTabCount && nVis<2; i++ )
105 if (pDoc->IsVisible(i))
106 ++nVis;
107 if ( nVis<2 || !pDoc->IsDocEditable() || nTabSelCount > 1 )
108 break;
110 SCTAB nHideTab;
111 if (pDoc->GetTable( aName, nHideTab ))
112 HideTable( nHideTab );
114 else // einblenden
116 ShowTable( aName );
119 break;
121 case FID_TABLE_HIDE:
123 ScMarkData& rMark = pViewData->GetMarkData();
124 SCTAB nTabSelCount = rMark.GetSelectCount();
125 USHORT nVis = 0;
126 for ( SCTAB i=0; i < nTabCount && nVis<2; i++ )
127 if (pDoc->IsVisible(i))
128 ++nVis;
129 if ( nVis<2 || !pDoc->IsDocEditable() || nTabSelCount > 1 )
130 break;
133 String aName;
134 if( pReqArgs != NULL )
136 const SfxPoolItem* pItem;
137 if( IS_AVAILABLE( FID_TABLE_HIDE, &pItem ) )
138 aName = ((const SfxStringItem*)pItem)->GetValue();
141 if (!aName.Len())
143 pDoc->GetName( nCurrentTab, aName ); // aktuelle Tabelle
144 rReq.AppendItem( SfxStringItem( FID_TABLE_HIDE, aName ) );
147 SCTAB nHideTab;
148 if (pDoc->GetTable( aName, nHideTab ))
149 HideTable( nHideTab );
151 if( ! rReq.IsAPI() )
152 rReq.Done();
154 break;
156 case FID_TABLE_SHOW:
158 String aName;
159 if ( pReqArgs )
161 const SfxPoolItem* pItem;
162 if( IS_AVAILABLE( FID_TABLE_SHOW, &pItem ) )
164 aName = ((const SfxStringItem*)pItem)->GetValue();
166 ShowTable( aName );
168 if( ! rReq.IsAPI() )
169 rReq.Done();
172 else
174 //CHINA001 ScShowTabDlg* pDlg = new ScShowTabDlg( GetDialogParent() );
175 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
176 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
178 AbstractScShowTabDlg* pDlg = pFact->CreateScShowTabDlg( GetDialogParent(), RID_SCDLG_SHOW_TAB);
179 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
181 String aTabName;
182 BOOL bFirst = TRUE;
183 for ( SCTAB i=0; i != nTabCount; i++ )
185 if (!pDoc->IsVisible(i))
187 pDoc->GetName( i, aTabName );
188 pDlg->Insert( aTabName, bFirst );
189 bFirst = FALSE;
193 if ( pDlg->Execute() == RET_OK )
195 USHORT nCount = pDlg->GetSelectEntryCount();
196 for (USHORT nPos=0; nPos<nCount; nPos++)
198 aName = pDlg->GetSelectEntry(nPos);
199 ShowTable( aName );
201 rReq.AppendItem( SfxStringItem( FID_TABLE_SHOW, aName ) );
202 rReq.Done();
204 delete pDlg;
207 break;
209 case FID_INS_TABLE:
210 case FID_INS_TABLE_EXT:
212 ScMarkData& rMark = pViewData->GetMarkData();
213 SCTAB nTabSelCount = rMark.GetSelectCount();
214 SCTAB nTabNr = nCurrentTab;
216 if ( !pDoc->IsDocEditable() )
217 break; // gesperrt
219 if ( pReqArgs != NULL ) // von Basic
221 BOOL bOk = FALSE;
222 const SfxPoolItem* pTabItem;
223 const SfxPoolItem* pNameItem;
224 String aName;
226 if ( IS_AVAILABLE( FN_PARAM_1, &pTabItem ) &&
227 IS_AVAILABLE( nSlot, &pNameItem ) )
229 // Tabellennr. von Basic: 1-basiert
231 aName = ((const SfxStringItem*)pNameItem)->GetValue();
232 nTabNr = ((const SfxUInt16Item*)pTabItem)->GetValue() - 1;
233 if ( nTabNr < nTabCount )
234 bOk = InsertTable( aName, nTabNr );
237 if (bOk)
238 rReq.Done( *pReqArgs );
239 //! sonst Fehler setzen
241 else // Dialog
243 //CHINA001 ScInsertTableDlg* pDlg = new ScInsertTableDlg(
244 //CHINA001 GetDialogParent(),
245 //CHINA001 *pViewData,nTabSelCount);
246 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
247 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
249 AbstractScInsertTableDlg* pDlg = pFact->CreateScInsertTableDlg( GetDialogParent(), *pViewData,
250 nTabSelCount, nSlot == FID_INS_TABLE_EXT,
251 RID_SCDLG_INSERT_TABLE);
252 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
253 if ( RET_OK == pDlg->Execute() )
255 if (pDlg->GetTablesFromFile())
257 SCTAB nTabs[MAXTABCOUNT];
258 SCTAB nCount = 0;
259 USHORT n = 0;
260 const String* pStr = pDlg->GetFirstTable( &n );
261 while ( pStr )
263 nTabs[nCount++] = static_cast<SCTAB>(n);
264 pStr = pDlg->GetNextTable( &n );
266 BOOL bLink = pDlg->GetTablesAsLink();
267 if (nCount != 0)
269 if(pDlg->IsTableBefore())
271 ImportTables( pDlg->GetDocShellTables(), nCount, nTabs,
272 bLink,nTabNr );
274 else
276 SCTAB nTabAfter = nTabNr+1;
278 for(SCTAB j=nCurrentTab+1;j<nTabCount;j++)
280 if(!pDoc->IsScenario(j))
282 nTabAfter=j;
283 break;
287 ImportTables( pDlg->GetDocShellTables(), nCount, nTabs,
288 bLink,nTabAfter );
292 else
294 SCTAB nCount=pDlg->GetTableCount();
295 if(pDlg->IsTableBefore())
297 if(nCount==1 && pDlg->GetFirstTable()->Len()>0)
299 rReq.AppendItem( SfxStringItem( FID_INS_TABLE, *pDlg->GetFirstTable() ) );
300 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nTabNr) + 1 ) ); // 1-based
301 rReq.Done();
303 InsertTable( *pDlg->GetFirstTable(), nTabNr );
305 else
306 InsertTables( NULL, nTabNr,nCount );
308 else
310 SCTAB nTabAfter = nTabNr+1;
311 SCTAB nSelHigh=0;
313 for(SCTAB i=0;i<nTabCount;i++)
315 if(rMark.GetTableSelect(i))
317 nSelHigh=i;
321 for(SCTAB j=nSelHigh+1;j<nTabCount;j++)
323 if(!pDoc->IsScenario(j))
325 nTabAfter=j;
326 break;
328 else // #101672#; increase nTabAfter, because it is possible that the scenario tables are the last
329 nTabAfter = j + 1;
332 if(nCount==1 && pDlg->GetFirstTable()->Len()>0)
334 rReq.AppendItem( SfxStringItem( FID_INS_TABLE, *pDlg->GetFirstTable() ) );
335 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nTabAfter) + 1 ) ); // 1-based
336 rReq.Done();
338 InsertTable( *pDlg->GetFirstTable(), nTabAfter);
340 else
342 InsertTables( NULL, nTabAfter,nCount);
348 delete pDlg;
351 break;
353 case FID_TAB_APPEND:
354 case FID_TAB_RENAME:
355 case FID_TAB_MENU_RENAME:
357 // FID_TAB_MENU_RENAME - "umbenennen" im Menu
358 // FID_TAB_RENAME - "Name"-Property fuer Basic
359 // Execute ist gleich, aber im GetState wird MENU_RENAME evtl. disabled
361 if ( nSlot == FID_TAB_MENU_RENAME )
362 nSlot = FID_TAB_RENAME; // Execute ist gleich
364 SCTAB nTabNr = pViewData->GetTabNo();
365 ScMarkData& rMark = pViewData->GetMarkData();
366 SCTAB nTabSelCount = rMark.GetSelectCount();
368 if ( !pDoc->IsDocEditable() )
369 break; // alles gesperrt
371 if ( nSlot != FID_TAB_APPEND &&
372 ( pDoc->IsTabProtected( nTabNr ) || nTabSelCount > 1 ) )
373 break; // kein Rename
375 #if 0
376 // ScSbxObject wird nicht mehr benutzt, stattdessen aus dem
377 // ScSbxTable::Notify die richtige Tabelle an der Basic-View eingestellt
378 if( rReq.IsAPI() )
380 SbxObject* pObj = GetScSbxObject();
381 ScSbxTable* pSbxTab = PTR_CAST( ScSbxTable, pObj );
382 DBG_ASSERT( pSbxTab, "pSbxTab???" );
384 if( pSbxTab )
385 nTabNr = pSbxTab->GetTableNr();
387 #endif
389 if( pReqArgs != NULL )
391 BOOL bDone = FALSE;
392 const SfxPoolItem* pItem;
393 String aName;
395 if( IS_AVAILABLE( FN_PARAM_1, &pItem ) )
396 nTabNr = ((const SfxUInt16Item*)pItem)->GetValue();
398 if( IS_AVAILABLE( nSlot, &pItem ) )
399 aName = ((const SfxStringItem*)pItem)->GetValue();
401 switch ( nSlot )
403 case FID_TAB_APPEND:
404 bDone = AppendTable( aName );
405 break;
406 case FID_TAB_RENAME:
407 bDone = RenameTable( aName, nTabNr );
408 break;
411 if( bDone )
413 rReq.Done( *pReqArgs );
416 else
418 USHORT nRet = RET_OK;
419 BOOL bDone = FALSE;
420 String aErrMsg ( ScGlobal::GetRscString( STR_INVALIDTABNAME ) );
421 String aName;
422 String aDlgTitle;
424 switch ( nSlot )
426 case FID_TAB_APPEND:
427 aDlgTitle = String(ScResId(SCSTR_APDTABLE));
428 pDoc->CreateValidTabName( aName );
429 break;
431 case FID_TAB_RENAME:
432 aDlgTitle = String(ScResId(SCSTR_RENAMETAB));
433 pDoc->GetName( pViewData->GetTabNo(), aName );
434 break;
437 //CHINA001 ScStringInputDlg* pDlg =
438 //CHINA001 new ScStringInputDlg( GetDialogParent(),
439 //CHINA001 aDlgTitle,
440 //CHINA001 String(ScResId(SCSTR_NAME)),
441 //CHINA001 aName,
442 //CHINA001 nSlot );
443 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
444 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
446 AbstractScStringInputDlg* pDlg = pFact->CreateScStringInputDlg( GetDialogParent(),
447 aDlgTitle,
448 String(ScResId(SCSTR_NAME)),
449 aName,
450 nSlot,RID_SCDLG_STRINPUT);
451 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
453 while ( !bDone && nRet == RET_OK )
455 nRet = pDlg->Execute();
457 if ( nRet == RET_OK )
459 pDlg->GetInputString( aName );
462 switch ( nSlot )
464 case FID_TAB_APPEND:
465 bDone = AppendTable( aName );
466 break;
467 case FID_TAB_RENAME:
468 bDone = RenameTable( aName, nTabNr );
469 break;
472 if ( bDone )
474 rReq.AppendItem( SfxStringItem( nSlot, aName ) );
475 rReq.Done();
477 else
479 if( rReq.IsAPI() )
481 StarBASIC::Error( SbERR_SETPROP_FAILED ); // XXX Fehlerbehandlung???
483 else
485 nRet = ErrorBox( GetDialogParent(),
486 WinBits( WB_OK | WB_DEF_OK ),
487 aErrMsg
488 ).Execute();
493 delete pDlg;
496 break;
498 case FID_TAB_MOVE:
500 if ( pDoc->GetChangeTrack() != NULL )
501 break; // bei aktiviertem ChangeTracking kein TabMove
503 BOOL bDoIt = FALSE;
504 USHORT nDoc = 0;
505 SCTAB nTab = pViewData->GetTabNo();
506 BOOL bCpy = FALSE;
507 String aDocName;
509 if( pReqArgs != NULL )
511 SCTAB nTableCount = pDoc->GetTableCount();
512 const SfxPoolItem* pItem;
514 if( IS_AVAILABLE( FID_TAB_MOVE, &pItem ) )
515 aDocName = ((const SfxStringItem*)pItem)->GetValue();
516 if( IS_AVAILABLE( FN_PARAM_1, &pItem ) )
518 // Tabelle ist 1-basiert
519 nTab = ((const SfxUInt16Item*)pItem)->GetValue() - 1;
520 if ( nTab >= nTableCount )
521 nTab = SC_TAB_APPEND;
523 if( IS_AVAILABLE( FN_PARAM_2, &pItem ) )
524 bCpy = ((const SfxBoolItem*)pItem)->GetValue();
526 if( aDocName.Len() )
528 SfxObjectShell* pSh = SfxObjectShell::GetFirst();
529 ScDocShell* pScSh = NULL;
530 USHORT i=0;
532 while ( pSh )
534 pScSh = PTR_CAST( ScDocShell, pSh );
536 if( pScSh )
538 pScSh->GetTitle();
540 if( pScSh->GetTitle() == aDocName )
542 nDoc = i;
543 ScDocument* pDestDoc = pScSh->GetDocument();
544 nTableCount = pDestDoc->GetTableCount();
545 bDoIt = pDestDoc->IsDocEditable();
546 break;
549 i++; // nur die ScDocShell's zaehlen
551 pSh = SfxObjectShell::GetNext( *pSh );
554 else // Kein Dokumentname -> neues Dokument
556 nDoc = SC_DOC_NEW;
557 bDoIt = TRUE;
560 if ( bDoIt && nTab >= nTableCount ) // ggf. anhaengen
561 nTab = SC_TAB_APPEND;
563 else
565 //CHINA001 ScMoveTableDlg* pDlg = new ScMoveTableDlg( GetDialogParent() );
566 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
567 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
569 AbstractScMoveTableDlg* pDlg = pFact->CreateScMoveTableDlg( GetDialogParent(), RID_SCDLG_MOVETAB );
570 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
572 SCTAB nTableCount = pDoc->GetTableCount();
573 ScMarkData& rMark = GetViewData()->GetMarkData();
574 SCTAB nTabSelCount = rMark.GetSelectCount();
577 if(nTableCount==nTabSelCount)
579 pDlg->SetCopyTable();
580 pDlg->EnableCopyTable(FALSE);
582 if ( pDlg->Execute() == RET_OK )
584 nDoc = pDlg->GetSelectedDocument();
585 nTab = pDlg->GetSelectedTable();
586 bCpy = pDlg->GetCopyTable();
587 bDoIt = TRUE;
589 String aFoundDocName;
590 if ( nDoc != SC_DOC_NEW )
592 ScDocShell* pSh = ScDocShell::GetShellByNum( nDoc );
593 if (pSh)
595 aFoundDocName = pSh->GetTitle();
596 if ( !pSh->GetDocument()->IsDocEditable() )
598 ErrorMessage(STR_READONLYERR);
599 bDoIt = FALSE;
603 rReq.AppendItem( SfxStringItem( FID_TAB_MOVE, aFoundDocName ) );
604 // Tabelle ist 1-basiert, wenn nicht APPEND
605 SCTAB nBasicTab = ( nTab <= MAXTAB ) ? (nTab+1) : nTab;
606 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nBasicTab) ) );
607 rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bCpy ) );
609 delete pDlg;
612 if( bDoIt )
614 rReq.Done(); // aufzeichnen, solange das Dokument noch aktiv ist
616 MoveTable( nDoc, nTab, bCpy );
619 break;
621 case FID_DELETE_TABLE:
623 // Parameter war ueberfluessig, weil die Methode an der Table haengt
625 BOOL bDoIt = rReq.IsAPI();
626 if( !bDoIt )
628 // wenn's nicht von Basic kommt, nochmal nachfragen:
630 #if ENABLE_LAYOUT
631 // Using layout::QueryBox without client code modification is
632 // deprecated, rather add HIG-complient buttons with verbs.
633 #define QueryBox( parent, winbits, question ) layout::QueryBox (parent, question, ScGlobal::GetRscString (STR_UNDO_DELETE_TAB))
634 #endif /* ENABLE_LAYOUT */
636 bDoIt = ( RET_YES ==
637 QueryBox( GetDialogParent(),
638 WinBits( WB_YES_NO | WB_DEF_YES ),
639 ScGlobal::GetRscString(STR_QUERY_DELTAB)
640 ).Execute() );
642 if( bDoIt )
644 SCTAB nNewTab = nCurrentTab;
645 SCTAB nFirstTab=0;
646 BOOL bTabFlag=FALSE;
647 ScMarkData& rMark = pViewData->GetMarkData();
648 SvShorts TheTabs;
649 for(SCTAB i=0;i<nTabCount;i++)
651 if(rMark.GetTableSelect(i) &&!pDoc->IsTabProtected(i))
653 TheTabs.Insert(i,TheTabs.Count());
654 bTabFlag=TRUE;
655 if(nNewTab==i) nNewTab++;
657 if(!bTabFlag) nFirstTab=i;
659 if(nNewTab>=nTabCount) nNewTab=nFirstTab;
661 pViewData->SetTabNo(nNewTab);
662 DeleteTables(TheTabs);
663 TheTabs.Remove(0,TheTabs.Count());
664 rReq.Done();
667 break;
669 case FID_TAB_RTL:
671 ScDocShell* pDocSh = pViewData->GetDocShell();
672 ScDocFunc aFunc(*pDocSh);
673 BOOL bSet = !pDoc->IsLayoutRTL( nCurrentTab );
675 const ScMarkData& rMark = pViewData->GetMarkData();
676 if ( rMark.GetSelectCount() != 0 )
678 // handle several sheets
680 SfxUndoManager* pUndoManager = pDocSh->GetUndoManager();
681 String aUndo = ScGlobal::GetRscString( STR_UNDO_TAB_RTL );
682 pUndoManager->EnterListAction( aUndo, aUndo );
684 for (SCTAB nTab=0; nTab<nTabCount; nTab++)
685 if ( rMark.GetTableSelect(nTab) )
686 aFunc.SetLayoutRTL( nTab, bSet, FALSE );
688 pUndoManager->LeaveListAction();
690 else
691 aFunc.SetLayoutRTL( nCurrentTab, bSet, FALSE );
693 break;
695 case FID_TAB_TOGGLE_GRID:
697 bool bShowGrid = pViewData->GetShowGrid();
698 pViewData->SetShowGrid(!bShowGrid);
699 SfxBindings& rBindings = GetViewFrame()->GetBindings();
700 rBindings.Invalidate( FID_TAB_TOGGLE_GRID );
701 PaintGrid();
702 rReq.Done();
704 break;
706 case FID_TAB_SET_TAB_BG_COLOR:
707 case FID_TAB_MENU_SET_TAB_BG_COLOR:
709 if ( nSlot == FID_TAB_MENU_SET_TAB_BG_COLOR )
710 nSlot = FID_TAB_SET_TAB_BG_COLOR;
712 SCTAB nTabNr = pViewData->GetTabNo();
713 ScMarkData& rMark = pViewData->GetMarkData();
714 SCTAB nTabSelCount = rMark.GetSelectCount();
716 ScUndoSetTabBgColorInfo* aTabBgColorUndoInfo=NULL;
717 ScUndoSetTabBgColorInfoList* aTabBgColorUndoInfoList =NULL;
719 if ( !pDoc->IsDocEditable() )
720 break;
722 if ( pDoc->IsTabProtected( nTabNr ) ) // ||nTabSelCount > 1
723 break;
725 if( pReqArgs != NULL )
727 BOOL bDone = FALSE;
728 const SfxPoolItem* pItem;
729 Color aColor;
730 if( IS_AVAILABLE( FN_PARAM_1, &pItem ) )
731 nTabNr = ((const SfxUInt16Item*)pItem)->GetValue();
733 if( IS_AVAILABLE( nSlot, &pItem ) )
734 aColor = ((const SvxColorItem*)pItem)->GetValue();
736 if ( nTabSelCount > 1 )
738 aTabBgColorUndoInfoList = new ScUndoSetTabBgColorInfoList();
739 for (SCTAB nTab=0; nTab<nTabCount; nTab++)
741 if ( rMark.GetTableSelect(nTab) && !pDoc->IsTabProtected(nTab) )
743 aTabBgColorUndoInfo = new ScUndoSetTabBgColorInfo();
744 aTabBgColorUndoInfo->nTabId = nTab;
745 aTabBgColorUndoInfo->aNewTabBgColor = aColor;
746 aTabBgColorUndoInfoList->Insert(aTabBgColorUndoInfo);
749 bDone = SetTabBgColor( aTabBgColorUndoInfoList );
751 else
753 bDone = SetTabBgColor( aColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
755 if( bDone )
757 rReq.Done( *pReqArgs );
760 else
762 USHORT nRet = RET_OK; /// temp
763 BOOL bDone = FALSE; /// temp
764 Color aTabBgColor;
765 Color aNewTabBgColor;
767 aTabBgColor = pViewData->GetTabBgColor( nCurrentTab );
768 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
769 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");
770 AbstractScTabBgColorDlg* pDlg = pFact->CreateScTabBgColorDlg(
771 GetDialogParent(),
772 String(ScResId(SCSTR_SET_TAB_BG_COLOR)),
773 String(ScResId(SCSTR_NO_TAB_BG_COLOR)),
774 aTabBgColor,
775 nSlot,RID_SCDLG_TAB_BG_COLOR);
776 while ( !bDone && nRet == RET_OK )
778 nRet = pDlg->Execute();
779 if( nRet == RET_OK )
781 Color aSelectedColor;
782 pDlg->GetSelectedColor(aSelectedColor);
783 aTabBgColorUndoInfoList = new ScUndoSetTabBgColorInfoList();
784 if ( nTabSelCount > 1 )
786 for (SCTAB nTab=0; nTab<nTabCount; nTab++)
788 if ( rMark.GetTableSelect(nTab) && !pDoc->IsTabProtected(nTab) )
790 aTabBgColorUndoInfo = new ScUndoSetTabBgColorInfo();
791 aTabBgColorUndoInfo->nTabId = nTab;
792 aTabBgColorUndoInfo->aNewTabBgColor = aSelectedColor;
793 aTabBgColorUndoInfoList->Insert(aTabBgColorUndoInfo);
796 bDone = SetTabBgColor( aTabBgColorUndoInfoList );
798 else
800 bDone = SetTabBgColor( aSelectedColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
802 if ( bDone )
804 rReq.AppendItem( SvxColorItem( aTabBgColor, nSlot ) );
805 rReq.Done();
807 else
809 if( rReq.IsAPI() )
811 StarBASIC::Error( SbERR_SETPROP_FAILED );
816 delete( pDlg );
819 break;
820 default:
821 DBG_ERROR("Unbekannte Message bei ViewShell");
822 break;
826 //------------------------------------------------------------------
828 void ScTabViewShell::GetStateTable( SfxItemSet& rSet )
830 ScViewData* pViewData = GetViewData();
831 ScDocument* pDoc = pViewData->GetDocument();
832 ScDocShell* pDocShell = pViewData->GetDocShell();
833 ScMarkData& rMark = GetViewData()->GetMarkData();
834 SCTAB nTab = pViewData->GetTabNo();
836 SCTAB nTabCount = pDoc->GetTableCount();
837 SCTAB nTabSelCount = rMark.GetSelectCount();
839 SfxWhichIter aIter(rSet);
840 USHORT nWhich = aIter.FirstWhich();
842 while ( nWhich )
844 switch ( nWhich )
847 case FID_TABLE_VISIBLE:
848 rSet.Put( SfxBoolItem( nWhich, pDoc->IsVisible(nTab) ));
849 break;
851 case FID_TABLE_HIDE:
853 USHORT nVis = 0;
854 for ( SCTAB i=0; i < nTabCount && nVis<2; i++ )
855 if (pDoc->IsVisible(i))
856 ++nVis;
858 if ( nVis<2 || !pDoc->IsDocEditable() || nTabSelCount > 1 )
859 rSet.DisableItem( nWhich );
861 break;
863 case FID_TABLE_SHOW:
865 BOOL bHasHidden = FALSE;
866 for ( SCTAB i=0; i < nTabCount && !bHasHidden; i++ )
867 if (!pDoc->IsVisible(i))
868 bHasHidden = TRUE;
869 if ( !bHasHidden || pDoc->IsDocProtected() || nTabSelCount > 1 )
870 rSet.DisableItem( nWhich );
872 break;
874 case FID_DELETE_TABLE:
876 if ( pDoc->GetChangeTrack() )
877 rSet.DisableItem( nWhich );
878 else
880 USHORT nVis = 0;
881 for ( SCTAB i=0; i < nTabCount && nVis<2; i++ )
882 if (pDoc->IsVisible(i))
883 ++nVis;
884 if ( pDoc->IsTabProtected(nTab)
885 || !pDoc->IsDocEditable()
886 || nVis < 2
887 || nTabSelCount == nTabCount)
888 rSet.DisableItem( nWhich );
891 break;
893 case FID_INS_TABLE:
894 case FID_INS_TABLE_EXT:
895 case FID_TAB_APPEND:
896 if ( !pDoc->IsDocEditable() ||
897 nTabCount > MAXTAB ||
898 ( nWhich == FID_INS_TABLE_EXT && pDocShell && pDocShell->IsDocShared() ) )
899 rSet.DisableItem( nWhich );
900 break;
902 case FID_TAB_MOVE:
903 if ( !pDoc->IsDocEditable()
904 || pDoc->GetChangeTrack() != NULL
905 || nTabCount > MAXTAB)
906 rSet.DisableItem( nWhich );
907 break;
909 // FID_TAB_MENU_RENAME - "umbenennen" im Menu
910 // FID_TAB_RENAME - "Name"-Property fuer Basic
912 case FID_TAB_MENU_RENAME:
913 if ( !pDoc->IsDocEditable() ||
914 pDoc->IsTabProtected(nTab) ||nTabSelCount > 1 ||
915 ( pDocShell && pDocShell->IsDocShared() ) )
916 rSet.DisableItem( nWhich );
917 break;
919 case FID_TAB_RENAME:
921 String aTabName;
922 pDoc->GetName( nTab, aTabName );
924 rSet.Put( SfxStringItem( nWhich, aTabName ));
927 break;
929 case FID_TAB_RTL:
931 SvtLanguageOptions aLangOpt;
932 if ( !aLangOpt.IsCTLFontEnabled() )
933 rSet.DisableItem( nWhich );
934 else
935 rSet.Put( SfxBoolItem( nWhich, pDoc->IsLayoutRTL( nTab ) ) );
937 break;
939 case FID_TAB_MENU_SET_TAB_BG_COLOR:
941 if ( !pDoc->IsDocEditable()
942 || ( pDocShell && pDocShell->IsDocShared() )
943 || pDoc->IsTabProtected(nTab) )
944 rSet.DisableItem( nWhich );
946 break;
948 case FID_TAB_SET_TAB_BG_COLOR:
950 Color aColor;
951 aColor = pViewData->GetTabBgColor( nTab );
952 rSet.Put( SvxColorItem( aColor, nWhich ) );
954 break;
956 case FID_TAB_TOGGLE_GRID:
957 rSet.Put( SfxBoolItem(nWhich, pViewData->GetShowGrid()) );
958 break;
960 nWhich = aIter.NextWhich();