xref: /aoo41x/main/sc/source/ui/view/tabvwshf.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 #include <boost/scoped_ptr.hpp>
32 
33 #include "scitems.hxx"
34 #include <sfx2/request.hxx>
35 #include <sfx2/viewfrm.hxx>
36 #include <basic/sbstar.hxx>
37 #include <layout/layout.hxx>
38 #include <svl/languageoptions.hxx>
39 #include <svl/stritem.hxx>
40 #include <svl/whiter.hxx>
41 #include <vcl/msgbox.hxx>
42 #include <sfx2/objface.hxx>
43 #include <svx/svxdlg.hxx>
44 #include <editeng/colritem.hxx>
45 
46 #include "tabvwsh.hxx"
47 #include "sc.hrc"
48 #include "docsh.hxx"
49 #include "document.hxx"
50 #include "shtabdlg.hxx"
51 #include "scresid.hxx"
52 //CHINA001 #include "instbdlg.hxx"
53 #include "globstr.hrc"
54 //CHINA001 #include "strindlg.hxx"
55 //CHINA001 #include "mvtabdlg.hxx"
56 #include "docfunc.hxx"
57 #include "eventuno.hxx"
58 
59 #include "scabstdlg.hxx" //CHINA001
60 
61 #include "tabbgcolor.hxx"
62 #include "tabbgcolordlg.hxx"
63 #include "sccommands.h"
64 
65 using ::boost::scoped_ptr;
66 using namespace com::sun::star;
67 
68 #define IS_AVAILABLE(WhichId,ppItem) \
69     (pReqArgs->GetItemState((WhichId), sal_True, ppItem ) == SFX_ITEM_SET)
70 
71 //------------------------------------------------------------------
72 
73 void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
74 {
75 	ScViewData*	pViewData	= GetViewData();
76 	ScDocument*	pDoc		= pViewData->GetDocument();
77 
78 	SCTAB		nCurrentTab	= pViewData->GetTabNo();
79 	SCTAB		nTabCount	= pDoc->GetTableCount();
80 	sal_uInt16		nSlot		= rReq.GetSlot();
81 	const SfxItemSet* pReqArgs = rReq.GetArgs();
82 
83 	HideListBox();					// Autofilter-DropDown-Listbox
84 
85 	switch ( nSlot )
86 	{
87 		case FID_TABLE_VISIBLE:
88 			{
89 				String aName;
90 				pDoc->GetName( nCurrentTab, aName );
91 
92 				sal_Bool bVisible=sal_True;
93 				if( pReqArgs != NULL )
94 				{
95 					const SfxPoolItem* pItem;
96 					if( IS_AVAILABLE( FID_TABLE_VISIBLE, &pItem ) )
97 						bVisible = ((const SfxBoolItem*)pItem)->GetValue();
98 				}
99 
100 				if( ! bVisible )			// ausblenden
101 				{
102 					ScMarkData& rMark = pViewData->GetMarkData();
103 					SCTAB nTabSelCount = rMark.GetSelectCount();
104 					sal_uInt16 nVis = 0;
105 					for ( SCTAB i=0; i < nTabCount && nVis<2; i++ )
106 						if (pDoc->IsVisible(i))
107 							++nVis;
108 					if ( nVis<2 || !pDoc->IsDocEditable() || nTabSelCount > 1 )
109 						break;
110 
111 					SCTAB nHideTab;
112 					if (pDoc->GetTable( aName, nHideTab ))
113 						HideTable( nHideTab );
114 				}
115 				else						// einblenden
116 				{
117 					ShowTable( aName );
118 				}
119 			}
120 			break;
121 
122 		case FID_TABLE_HIDE:
123 			{
124 				ScMarkData& rMark = pViewData->GetMarkData();
125 				SCTAB nTabSelCount = rMark.GetSelectCount();
126 				sal_uInt16 nVis = 0;
127 				for ( SCTAB i=0; i < nTabCount && nVis<2; i++ )
128 					if (pDoc->IsVisible(i))
129 						++nVis;
130 				if ( nVis<2 || !pDoc->IsDocEditable() || nTabSelCount > 1 )
131 					break;
132 
133 
134 				String aName;
135 				if( pReqArgs != NULL )
136 				{
137 					const SfxPoolItem* pItem;
138 					if( IS_AVAILABLE( FID_TABLE_HIDE, &pItem ) )
139 						aName = ((const SfxStringItem*)pItem)->GetValue();
140 				}
141 
142 				if (!aName.Len())
143 				{
144 					pDoc->GetName( nCurrentTab, aName );		// aktuelle Tabelle
145 					rReq.AppendItem( SfxStringItem( FID_TABLE_HIDE, aName ) );
146 				}
147 
148 				SCTAB nHideTab;
149 				if (pDoc->GetTable( aName, nHideTab ))
150 					HideTable( nHideTab );
151 
152 				if( ! rReq.IsAPI() )
153 					rReq.Done();
154 			}
155 			break;
156 
157 		case FID_TABLE_SHOW:
158 			{
159 				String aName;
160 				if ( pReqArgs )
161 				{
162 					const SfxPoolItem* pItem;
163 					if( IS_AVAILABLE( FID_TABLE_SHOW, &pItem ) )
164 					{
165 						aName = ((const SfxStringItem*)pItem)->GetValue();
166 
167 						ShowTable( aName );
168 
169 						if( ! rReq.IsAPI() )
170 							rReq.Done();
171 					}
172 				}
173 				else
174 				{
175                     //CHINA001 ScShowTabDlg* pDlg = new ScShowTabDlg( GetDialogParent() );
176 					ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
177 					DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
178 
179 					AbstractScShowTabDlg* pDlg = pFact->CreateScShowTabDlg( GetDialogParent(), RID_SCDLG_SHOW_TAB);
180 					DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
181 
182                     String aTabName;
183                     sal_Bool bFirst = sal_True;
184 					for ( SCTAB i=0; i != nTabCount; i++ )
185 					{
186 						if (!pDoc->IsVisible(i))
187 						{
188                             pDoc->GetName( i, aTabName );
189                             pDlg->Insert( aTabName, bFirst );
190                             bFirst = sal_False;
191 						}
192 					}
193 
194 					if ( pDlg->Execute() == RET_OK )
195 					{
196 						sal_uInt16 nCount = pDlg->GetSelectEntryCount();
197 						for (sal_uInt16 nPos=0; nPos<nCount; nPos++)
198 						{
199 							aName = pDlg->GetSelectEntry(nPos);
200 							ShowTable( aName );
201 						}
202 						rReq.AppendItem( SfxStringItem( FID_TABLE_SHOW, aName ) );
203 						rReq.Done();
204 					}
205 					delete pDlg;
206 				}
207 			}
208 			break;
209 
210 		case FID_INS_TABLE:
211         case FID_INS_TABLE_EXT:
212 			{
213 				ScMarkData& rMark 	 = pViewData->GetMarkData();
214 				SCTAB	nTabSelCount = rMark.GetSelectCount();
215 				SCTAB	nTabNr		 = nCurrentTab;
216 
217 				if ( !pDoc->IsDocEditable() )
218 					break;							// gesperrt
219 
220 				if ( pReqArgs != NULL )				// von Basic
221 				{
222 					sal_Bool bOk = sal_False;
223 					const SfxPoolItem*	pTabItem;
224 					const SfxPoolItem*	pNameItem;
225 					String				aName;
226 
227 					if ( IS_AVAILABLE( FN_PARAM_1, &pTabItem ) &&
228 						 IS_AVAILABLE( nSlot, &pNameItem ) )
229 					{
230 						//	Tabellennr. von Basic: 1-basiert
231 
232 						aName = ((const SfxStringItem*)pNameItem)->GetValue();
233 						nTabNr = ((const SfxUInt16Item*)pTabItem)->GetValue() - 1;
234 						if ( nTabNr < nTabCount )
235 							bOk = InsertTable( aName, nTabNr );
236 					}
237 
238 					if (bOk)
239 						rReq.Done( *pReqArgs );
240 					//!	sonst Fehler setzen
241 				}
242 				else								// Dialog
243 				{
244 //CHINA001					ScInsertTableDlg* pDlg = new ScInsertTableDlg(
245 //CHINA001					GetDialogParent(),
246 //CHINA001					*pViewData,nTabSelCount);
247 					ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
248 					DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
249 
250 					AbstractScInsertTableDlg* pDlg = pFact->CreateScInsertTableDlg( GetDialogParent(), *pViewData,
251                                                                                     nTabSelCount, nSlot == FID_INS_TABLE_EXT,
252 																					RID_SCDLG_INSERT_TABLE);
253 					DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
254 					if ( RET_OK == pDlg->Execute() )
255 					{
256 						if (pDlg->GetTablesFromFile())
257 						{
258 							SCTAB nTabs[MAXTABCOUNT];
259 							SCTAB nCount = 0;
260 							sal_uInt16 n = 0;
261 							const String* pStr = pDlg->GetFirstTable( &n );
262 							while ( pStr )
263 							{
264 								nTabs[nCount++] = static_cast<SCTAB>(n);
265 								pStr = pDlg->GetNextTable( &n );
266 							}
267 							sal_Bool bLink = pDlg->GetTablesAsLink();
268 							if (nCount != 0)
269 							{
270 								if(pDlg->IsTableBefore())
271 								{
272 									ImportTables( pDlg->GetDocShellTables(), nCount, nTabs,
273 												bLink,nTabNr );
274 								}
275 								else
276 								{
277 									SCTAB	nTabAfter	 = nTabNr+1;
278 
279 									for(SCTAB j=nCurrentTab+1;j<nTabCount;j++)
280 									{
281 										if(!pDoc->IsScenario(j))
282 										{
283 											nTabAfter=j;
284 											break;
285 										}
286 									}
287 
288 									ImportTables( pDlg->GetDocShellTables(), nCount, nTabs,
289 												bLink,nTabAfter );
290 								}
291 							}
292 						}
293 						else
294 						{
295 							SCTAB nCount=pDlg->GetTableCount();
296 							if(pDlg->IsTableBefore())
297 							{
298 								if(nCount==1 && pDlg->GetFirstTable()->Len()>0)
299 								{
300 									rReq.AppendItem( SfxStringItem( FID_INS_TABLE, *pDlg->GetFirstTable() ) );
301 									rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nTabNr) + 1 ) );		// 1-based
302 									rReq.Done();
303 
304 									InsertTable( *pDlg->GetFirstTable(), nTabNr );
305 								}
306 								else
307 									InsertTables( NULL, nTabNr,nCount );
308 							}
309 							else
310 							{
311 								SCTAB	nTabAfter	 = nTabNr+1;
312 								SCTAB nSelHigh=0;
313 
314 								for(SCTAB i=0;i<nTabCount;i++)
315 								{
316 									if(rMark.GetTableSelect(i))
317 									{
318 										nSelHigh=i;
319 									}
320 								}
321 
322 								for(SCTAB j=nSelHigh+1;j<nTabCount;j++)
323 								{
324 									if(!pDoc->IsScenario(j))
325 									{
326 										nTabAfter=j;
327 										break;
328 									}
329                                     else // #101672#; increase nTabAfter, because it is possible that the scenario tables are the last
330                                         nTabAfter = j + 1;
331 								}
332 
333 								if(nCount==1 && pDlg->GetFirstTable()->Len()>0)
334 								{
335 									rReq.AppendItem( SfxStringItem( FID_INS_TABLE, *pDlg->GetFirstTable() ) );
336 									rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nTabAfter) + 1 ) );		// 1-based
337 									rReq.Done();
338 
339 									InsertTable( *pDlg->GetFirstTable(), nTabAfter);
340 								}
341 								else
342 								{
343 									InsertTables( NULL, nTabAfter,nCount);
344 								}
345 							}
346 						}
347 					}
348 
349 					delete pDlg;
350 				}
351 			}
352 			break;
353 
354 		case FID_TAB_APPEND:
355 		case FID_TAB_RENAME:
356 		case FID_TAB_MENU_RENAME:
357 			{
358 				//	FID_TAB_MENU_RENAME - "umbenennen" im Menu
359 				//	FID_TAB_RENAME		- "Name"-Property fuer Basic
360 				//	Execute ist gleich, aber im GetState wird MENU_RENAME evtl. disabled
361 
362 				if ( nSlot == FID_TAB_MENU_RENAME )
363 					nSlot = FID_TAB_RENAME;				// Execute ist gleich
364 
365 				SCTAB nTabNr = pViewData->GetTabNo();
366 				ScMarkData& rMark = pViewData->GetMarkData();
367 				SCTAB nTabSelCount = rMark.GetSelectCount();
368 
369 				if ( !pDoc->IsDocEditable() )
370 					break; // alles gesperrt
371 
372 				if ( nSlot != FID_TAB_APPEND &&
373 						( pDoc->IsTabProtected( nTabNr ) || nTabSelCount > 1 ) )
374 					break; // kein Rename
375 
376 #if 0
377 				//	ScSbxObject wird nicht mehr benutzt, stattdessen aus dem
378 				//	ScSbxTable::Notify die richtige Tabelle an der Basic-View eingestellt
379 				if( rReq.IsAPI() )
380 				{
381 					SbxObject* pObj = GetScSbxObject();
382 					ScSbxTable* pSbxTab = PTR_CAST( ScSbxTable, pObj );
383 					DBG_ASSERT( pSbxTab, "pSbxTab???" );
384 
385 					if( pSbxTab )
386 						nTabNr = pSbxTab->GetTableNr();
387 				}
388 #endif
389 
390 				if( pReqArgs != NULL )
391 				{
392 					sal_Bool		bDone	= sal_False;
393 					const SfxPoolItem* pItem;
394 					String		aName;
395 
396 					if( IS_AVAILABLE( FN_PARAM_1, &pItem ) )
397 						nTabNr = ((const SfxUInt16Item*)pItem)->GetValue();
398 
399 					if( IS_AVAILABLE( nSlot, &pItem ) )
400 						aName = ((const SfxStringItem*)pItem)->GetValue();
401 
402 					switch ( nSlot )
403 					{
404 						case FID_TAB_APPEND:
405 							bDone = AppendTable( aName );
406 							break;
407 						case FID_TAB_RENAME:
408 							bDone = RenameTable( aName, nTabNr );
409 							break;
410 					}
411 
412 					if( bDone )
413 					{
414 						rReq.Done( *pReqArgs );
415 					}
416 				}
417 				else
418 				{
419 					sal_uInt16		nRet	= RET_OK;
420 					sal_Bool		bDone	= sal_False;
421 					String		aErrMsg ( ScGlobal::GetRscString( STR_INVALIDTABNAME ) );
422 					String		aName;
423 					String		aDlgTitle;
424                     const sal_Char* pHelpId = 0;
425 
426 					switch ( nSlot )
427 					{
428 						case FID_TAB_APPEND:
429 							aDlgTitle = String(ScResId(SCSTR_APDTABLE));
430 							pDoc->CreateValidTabName( aName );
431                             pHelpId = HID_SC_APPEND_NAME;
432 							break;
433 
434 						case FID_TAB_RENAME:
435 							aDlgTitle = String(ScResId(SCSTR_RENAMETAB));
436 							pDoc->GetName( pViewData->GetTabNo(), aName );
437                             pHelpId = HID_SC_RENAME_NAME;
438 							break;
439 					}
440 
441 					ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
442 					DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
443 
444 					AbstractScStringInputDlg* pDlg = pFact->CreateScStringInputDlg( GetDialogParent(),
445 																					aDlgTitle,
446 																					String(ScResId(SCSTR_NAME)),
447 																					aName,
448 																					GetStaticInterface()->GetSlot(nSlot)->GetCommand(), pHelpId, RID_SCDLG_STRINPUT);
449 					DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
450 
451 					while ( !bDone && nRet == RET_OK )
452 					{
453 						nRet = pDlg->Execute();
454 
455 						if ( nRet == RET_OK )
456 						{
457 							pDlg->GetInputString( aName );
458 
459 
460 							switch ( nSlot )
461 							{
462 								case FID_TAB_APPEND:
463 									bDone = AppendTable( aName );
464 									break;
465 								case FID_TAB_RENAME:
466 									bDone = RenameTable( aName, nTabNr );
467 									break;
468 							}
469 
470 							if ( bDone )
471 							{
472 								rReq.AppendItem( SfxStringItem( nSlot, aName ) );
473 								rReq.Done();
474 							}
475 							else
476 							{
477 								if( rReq.IsAPI() )
478 								{
479 									StarBASIC::Error( SbERR_SETPROP_FAILED ); // XXX Fehlerbehandlung???
480 								}
481 								else
482 								{
483 									nRet = ErrorBox( GetDialogParent(),
484 													 WinBits( WB_OK | WB_DEF_OK ),
485 													 aErrMsg
486 												   ).Execute();
487 								}
488 							}
489 						}
490 					}
491 					delete pDlg;
492 				}
493 			}
494 			break;
495 
496 		case FID_TAB_MOVE:
497 			{
498 				if ( pDoc->GetChangeTrack() != NULL )
499 					break;		// bei aktiviertem ChangeTracking kein TabMove
500 
501 				sal_Bool   bDoIt = sal_False;
502 				sal_uInt16 nDoc = 0;
503 				SCTAB nTab = pViewData->GetTabNo();
504 				sal_Bool   bCpy = sal_False;
505 				String aDocName;
506 
507 				if( pReqArgs != NULL )
508 				{
509 					SCTAB nTableCount = pDoc->GetTableCount();
510 					const SfxPoolItem* pItem;
511 
512 					if( IS_AVAILABLE( FID_TAB_MOVE, &pItem ) )
513 						aDocName = ((const SfxStringItem*)pItem)->GetValue();
514 					if( IS_AVAILABLE( FN_PARAM_1, &pItem ) )
515 					{
516 						//	Tabelle ist 1-basiert
517 						nTab = ((const SfxUInt16Item*)pItem)->GetValue() - 1;
518 						if ( nTab >= nTableCount )
519 							nTab = SC_TAB_APPEND;
520 					}
521 					if( IS_AVAILABLE( FN_PARAM_2, &pItem ) )
522 						bCpy = ((const SfxBoolItem*)pItem)->GetValue();
523 
524 					if( aDocName.Len() )
525 					{
526 						SfxObjectShell* pSh		= SfxObjectShell::GetFirst();
527 						ScDocShell*		pScSh	= NULL;
528 						sal_uInt16			i=0;
529 
530 						while ( pSh )
531 						{
532 							pScSh = PTR_CAST( ScDocShell, pSh );
533 
534 							if( pScSh )
535 							{
536 								pScSh->GetTitle();
537 
538 								if( pScSh->GetTitle() == aDocName )
539 								{
540 									nDoc = i;
541 									ScDocument* pDestDoc = pScSh->GetDocument();
542 									nTableCount = pDestDoc->GetTableCount();
543 									bDoIt = pDestDoc->IsDocEditable();
544 									break;
545 								}
546 
547 								i++;		// nur die ScDocShell's zaehlen
548 							}
549 							pSh = SfxObjectShell::GetNext( *pSh );
550 						}
551 					}
552 					else // Kein Dokumentname -> neues Dokument
553 					{
554 						nDoc = SC_DOC_NEW;
555 						bDoIt = sal_True;
556 					}
557 
558 					if ( bDoIt && nTab >= nTableCount )		// ggf. anhaengen
559 						nTab = SC_TAB_APPEND;
560 				}
561 				else
562 				{
563 					//CHINA001 ScMoveTableDlg* pDlg = new ScMoveTableDlg( GetDialogParent() );
564 					ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
565 					DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
566 
567 					AbstractScMoveTableDlg* pDlg = pFact->CreateScMoveTableDlg( GetDialogParent(), RID_SCDLG_MOVETAB );
568 					DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
569 
570 					SCTAB nTableCount = pDoc->GetTableCount();
571 					ScMarkData& rMark		= GetViewData()->GetMarkData();
572 					SCTAB		nTabSelCount = rMark.GetSelectCount();
573 
574 
575 					if(nTableCount==nTabSelCount)
576 					{
577 						pDlg->SetCopyTable();
578 						pDlg->EnableCopyTable(sal_False);
579 					}
580 					if ( pDlg->Execute() == RET_OK )
581 					{
582 						nDoc = pDlg->GetSelectedDocument();
583 						nTab = pDlg->GetSelectedTable();
584 						bCpy = pDlg->GetCopyTable();
585 						bDoIt = sal_True;
586 
587 						String aFoundDocName;
588 						if ( nDoc != SC_DOC_NEW )
589 						{
590 							ScDocShell* pSh = ScDocShell::GetShellByNum( nDoc );
591 							if (pSh)
592 							{
593 								aFoundDocName = pSh->GetTitle();
594 								if ( !pSh->GetDocument()->IsDocEditable() )
595 								{
596 									ErrorMessage(STR_READONLYERR);
597 									bDoIt = sal_False;
598 								}
599 							}
600 						}
601 						rReq.AppendItem( SfxStringItem( FID_TAB_MOVE, aFoundDocName ) );
602 						//	Tabelle ist 1-basiert, wenn nicht APPEND
603 						SCTAB nBasicTab = ( nTab <= MAXTAB ) ? (nTab+1) : nTab;
604 						rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nBasicTab) ) );
605 						rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bCpy ) );
606 					}
607 					delete pDlg;
608 				}
609 
610 				if( bDoIt )
611 				{
612 					rReq.Done();		// aufzeichnen, solange das Dokument noch aktiv ist
613 
614 					MoveTable( nDoc, nTab, bCpy );
615 				}
616 			}
617 			break;
618 
619 		case FID_DELETE_TABLE:
620 			{
621 				//	Parameter war ueberfluessig, weil die Methode an der Table haengt
622 
623 				sal_Bool bDoIt = rReq.IsAPI();
624 				if( !bDoIt )
625 				{
626 					//	wenn's nicht von Basic kommt, nochmal nachfragen:
627 
628 #if ENABLE_LAYOUT
629 // Using layout::QueryBox without client code modification is
630 // deprecated, rather add HIG-complient buttons with verbs.
631 #define QueryBox( parent, winbits, question ) layout::QueryBox (parent, question, ScGlobal::GetRscString (STR_UNDO_DELETE_TAB))
632 #endif /* ENABLE_LAYOUT */
633 
634                         bDoIt = ( RET_YES ==
635                                   QueryBox( GetDialogParent(),
636                                             WinBits( WB_YES_NO | WB_DEF_YES ),
637                                             ScGlobal::GetRscString(STR_QUERY_DELTAB)
638                                       ).Execute() );
639 				}
640 				if( bDoIt )
641 				{
642 					SCTAB nNewTab	= nCurrentTab;
643 					SCTAB nFirstTab=0;
644 					sal_Bool   bTabFlag=sal_False;
645 					ScMarkData& rMark = pViewData->GetMarkData();
646 					SvShorts TheTabs;
647 					for(SCTAB i=0;i<nTabCount;i++)
648 					{
649 						if(rMark.GetTableSelect(i) &&!pDoc->IsTabProtected(i))
650 						{
651 							TheTabs.push_back(i);
652 							bTabFlag=sal_True;
653 							if(nNewTab==i) nNewTab++;
654 						}
655 						if(!bTabFlag) nFirstTab=i;
656 					}
657 					if(nNewTab>=nTabCount) nNewTab=nFirstTab;
658 
659 					pViewData->SetTabNo(nNewTab);
660 					DeleteTables(TheTabs);
661 					TheTabs.clear();
662 					rReq.Done();
663 				}
664 			}
665 			break;
666 
667 		case FID_TAB_RTL:
668 			{
669 				ScDocShell* pDocSh = pViewData->GetDocShell();
670 				ScDocFunc aFunc(*pDocSh);
671 				sal_Bool bSet = !pDoc->IsLayoutRTL( nCurrentTab );
672 
673 				const ScMarkData& rMark = pViewData->GetMarkData();
674 				if ( rMark.GetSelectCount() != 0 )
675 				{
676 					//	handle several sheets
677 
678 					::svl::IUndoManager* pUndoManager = pDocSh->GetUndoManager();
679 					String aUndo = ScGlobal::GetRscString( STR_UNDO_TAB_RTL );
680 					pUndoManager->EnterListAction( aUndo, aUndo );
681 
682 					for (SCTAB nTab=0; nTab<nTabCount; nTab++)
683 						if ( rMark.GetTableSelect(nTab) )
684 							aFunc.SetLayoutRTL( nTab, bSet, sal_False );
685 
686 					pUndoManager->LeaveListAction();
687 				}
688 				else
689 					aFunc.SetLayoutRTL( nCurrentTab, bSet, sal_False );
690 			}
691 			break;
692 
693         case FID_TAB_SET_TAB_BG_COLOR:
694         case FID_TAB_MENU_SET_TAB_BG_COLOR:
695             {
696                 if ( nSlot == FID_TAB_MENU_SET_TAB_BG_COLOR )
697                     nSlot = FID_TAB_SET_TAB_BG_COLOR;
698                 SCTAB nTabNr = pViewData->GetTabNo();
699                 ScMarkData& rMark = pViewData->GetMarkData();
700                 SCTAB nTabSelCount = rMark.GetSelectCount();
701                 if ( !pDoc->IsDocEditable() )
702                     break;
703 
704                 if ( pDoc->IsTabProtected( nTabNr ) ) // ||nTabSelCount > 1
705                     break;
706 
707                 if( pReqArgs != NULL )
708                 {
709                     sal_Bool                bDone = sal_False;
710                     const SfxPoolItem*  pItem;
711                     Color               aColor;
712                     if( IS_AVAILABLE( FN_PARAM_1, &pItem ) )
713                         nTabNr = ((const SfxUInt16Item*)pItem)->GetValue();
714 
715                     if( IS_AVAILABLE( nSlot, &pItem ) )
716                         aColor = ((const SvxColorItem*)pItem)->GetValue();
717 
718                     if ( nTabSelCount > 1 )
719                     {
720                         scoped_ptr<ScUndoTabColorInfo::List>
721                             pTabColorList(new ScUndoTabColorInfo::List);
722                         for (SCTAB nTab=0; nTab<nTabCount; nTab++)
723                         {
724                             if ( rMark.GetTableSelect(nTab) && !pDoc->IsTabProtected(nTab) )
725                             {
726                                 ScUndoTabColorInfo aTabColorInfo(nTab);
727                                 aTabColorInfo.maNewTabBgColor = aColor;
728                                 pTabColorList->push_back(aTabColorInfo);
729                             }
730                         }
731                         bDone = SetTabBgColor( *pTabColorList );
732                     }
733                     else
734                     {
735                         bDone = SetTabBgColor( aColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
736                     }
737                     if( bDone )
738                     {
739                         rReq.Done( *pReqArgs );
740                     }
741                 }
742                 else
743                 {
744                     sal_uInt16      nRet    = RET_OK; /// temp
745                     sal_Bool        bDone   = sal_False; /// temp
746                     Color       aTabBgColor;
747                     Color       aNewTabBgColor;
748 
749                     aTabBgColor = pDoc->GetTabBgColor( nCurrentTab );
750                     ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
751                     DBG_ASSERT(pFact, "ScAbstractFactory create fail!");
752                     AbstractScTabBgColorDlg* pDlg = pFact->CreateScTabBgColorDlg(
753                                                                 GetDialogParent(),
754                                                                 String(ScResId(SCSTR_SET_TAB_BG_COLOR)),
755                                                                 String(ScResId(SCSTR_NO_TAB_BG_COLOR)),
756                                                                 aTabBgColor,
757                                                                 CMD_FID_TAB_SET_TAB_BG_COLOR,
758                                                                 RID_SCDLG_TAB_BG_COLOR);
759                     while ( !bDone && nRet == RET_OK )
760                     {
761                         nRet = pDlg->Execute();
762                         if( nRet == RET_OK )
763                         {
764                             Color aSelectedColor;
765                             pDlg->GetSelectedColor(aSelectedColor);
766                             scoped_ptr<ScUndoTabColorInfo::List>
767                                 pTabColorList(new ScUndoTabColorInfo::List);
768                             if ( nTabSelCount > 1 )
769                             {
770                                 for  (SCTAB nTab=0; nTab<nTabCount; nTab++)
771                                 {
772                                     if ( rMark.GetTableSelect(nTab) && !pDoc->IsTabProtected(nTab) )
773                                     {
774                                         ScUndoTabColorInfo aTabColorInfo(nTab);
775                                         aTabColorInfo.maNewTabBgColor = aSelectedColor;
776                                         pTabColorList->push_back(aTabColorInfo);
777                                     }
778                                 }
779                                 bDone = SetTabBgColor( *pTabColorList );
780                             }
781                             else
782                             {
783                                 bDone = SetTabBgColor( aSelectedColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
784                             }
785                             if ( bDone )
786                             {
787                                 rReq.AppendItem( SvxColorItem( aTabBgColor, nSlot ) );
788                                 rReq.Done();
789                             }
790                             else
791                             {
792                                 if( rReq.IsAPI() )
793                                 {
794                                     StarBASIC::Error( SbERR_SETPROP_FAILED );
795                                 }
796                             }
797                         }
798                     }
799                     delete( pDlg );
800                 }
801             }
802             break;
803 
804         case FID_TAB_EVENTS:
805             {
806                 ScDocShell* pDocSh = pViewData->GetDocShell();
807                 uno::Reference<container::XNameReplace> xEvents( new ScSheetEventsObj( pDocSh, nCurrentTab ) );
808                 uno::Reference<frame::XFrame> xFrame = GetViewFrame()->GetFrame().GetFrameInterface();
809                 SvxAbstractDialogFactory* pDlgFactory = SvxAbstractDialogFactory::Create();
810                 if (pDlgFactory)
811                 {
812                     std::auto_ptr<VclAbstractDialog> pDialog( pDlgFactory->CreateSvxMacroAssignDlg(
813                         GetDialogParent(), xFrame, false, xEvents, 0 ) );
814                     if ( pDialog.get() && pDialog->Execute() == RET_OK )
815                     {
816                         // the dialog modifies the settings directly
817                     }
818                 }
819             }
820             break;
821 
822 		default:
823 			DBG_ERROR("Unbekannte Message bei ViewShell");
824 			break;
825 	}
826 }
827 
828 //------------------------------------------------------------------
829 
830 void ScTabViewShell::GetStateTable( SfxItemSet& rSet )
831 {
832 	ScViewData* pViewData	= GetViewData();
833 	ScDocument* pDoc		= pViewData->GetDocument();
834     ScDocShell* pDocShell   = pViewData->GetDocShell();
835 	ScMarkData& rMark		= GetViewData()->GetMarkData();
836 	SCTAB		nTab		= pViewData->GetTabNo();
837 
838 	SCTAB nTabCount = pDoc->GetTableCount();
839 	SCTAB nTabSelCount = rMark.GetSelectCount();
840 
841 	SfxWhichIter	aIter(rSet);
842 	sal_uInt16			nWhich = aIter.FirstWhich();
843 
844 	while ( nWhich )
845 	{
846 		switch ( nWhich )
847 		{
848 
849 			case FID_TABLE_VISIBLE:
850 				rSet.Put( SfxBoolItem( nWhich, pDoc->IsVisible(nTab) ));
851 				break;
852 
853 			case FID_TABLE_HIDE:
854 				{
855 					sal_uInt16 nVis = 0;
856 					for ( SCTAB i=0; i < nTabCount && nVis<2; i++ )
857 						if (pDoc->IsVisible(i))
858 							++nVis;
859 
860 					if ( nVis<2 || !pDoc->IsDocEditable() || nTabSelCount > 1 )
861 						rSet.DisableItem( nWhich );
862 				}
863 				break;
864 
865 			case FID_TABLE_SHOW:
866 				{
867 					sal_Bool bHasHidden = sal_False;
868 					for ( SCTAB i=0; i < nTabCount && !bHasHidden; i++ )
869 						if (!pDoc->IsVisible(i))
870 							bHasHidden = sal_True;
871 					if ( !bHasHidden || pDoc->IsDocProtected() || nTabSelCount > 1 )
872 						rSet.DisableItem( nWhich );
873 				}
874 				break;
875 
876 			case FID_DELETE_TABLE:
877 				{
878 					if ( pDoc->GetChangeTrack() )
879 						rSet.DisableItem( nWhich );
880 					else
881 					{
882 						sal_uInt16 nVis = 0;
883 						for ( SCTAB i=0; i < nTabCount && nVis<2; i++ )
884 							if (pDoc->IsVisible(i))
885 								++nVis;
886 						if (   pDoc->IsTabProtected(nTab)
887 							|| !pDoc->IsDocEditable()
888 							|| nVis < 2
889 							|| nTabSelCount == nTabCount)
890 						rSet.DisableItem( nWhich );
891 					}
892 				}
893 				break;
894 
895 			case FID_INS_TABLE:
896             case FID_INS_TABLE_EXT:
897 			case FID_TAB_APPEND:
898                 if ( !pDoc->IsDocEditable() ||
899                      nTabCount > MAXTAB ||
900                      ( nWhich == FID_INS_TABLE_EXT && pDocShell && pDocShell->IsDocShared() ) )
901 					rSet.DisableItem( nWhich );
902 				break;
903 
904 			case FID_TAB_MOVE:
905 				if (   !pDoc->IsDocEditable()
906 					|| pDoc->GetChangeTrack() != NULL
907 					|| nTabCount > MAXTAB)
908 					rSet.DisableItem( nWhich );
909 				break;
910 
911 			//	FID_TAB_MENU_RENAME - "umbenennen" im Menu
912 			//	FID_TAB_RENAME		- "Name"-Property fuer Basic
913 
914 			case FID_TAB_MENU_RENAME:
915 				if ( !pDoc->IsDocEditable() ||
916 					 pDoc->IsTabProtected(nTab) ||nTabSelCount > 1 ||
917                      ( pDocShell && pDocShell->IsDocShared() ) )
918 					rSet.DisableItem( nWhich );
919 				break;
920 
921 			case FID_TAB_RENAME:
922 				{
923 					String aTabName;
924 					pDoc->GetName( nTab, aTabName );
925 
926 					rSet.Put( SfxStringItem( nWhich, aTabName ));
927 
928 				}
929 				break;
930 
931 			case FID_TAB_RTL:
932 				{
933 					SvtLanguageOptions aLangOpt;
934 					if ( !aLangOpt.IsCTLFontEnabled() )
935 						rSet.DisableItem( nWhich );
936 					else
937 						rSet.Put( SfxBoolItem( nWhich, pDoc->IsLayoutRTL( nTab ) ) );
938 				}
939 				break;
940 
941             case FID_TAB_MENU_SET_TAB_BG_COLOR:
942                 {
943                     if ( !pDoc->IsDocEditable()
944                         || ( pDocShell && pDocShell->IsDocShared() )
945                         || pDoc->IsTabProtected(nTab) )
946                         rSet.DisableItem( nWhich );
947                 }
948                 break;
949 
950             case FID_TAB_SET_TAB_BG_COLOR:
951                 {
952                     Color aColor;
953                     aColor = pDoc->GetTabBgColor( nTab );
954                     rSet.Put( SvxColorItem( aColor, nWhich ) );
955                 }
956                 break;
957 		}
958 		nWhich = aIter.NextWhich();
959 	}
960 }
961 
962 
963 
964 
965