Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <boost/scoped_ptr.hpp>
22 :
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>
35 :
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"
45 :
46 : #include "scabstdlg.hxx"
47 :
48 : #include "tabbgcolor.hxx"
49 : #include "tabbgcolordlg.hxx"
50 : #include "sccommands.h"
51 : #include "markdata.hxx"
52 :
53 : #include <vector>
54 :
55 : using ::boost::scoped_ptr;
56 : using namespace com::sun::star;
57 :
58 0 : void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
59 : {
60 0 : ScViewData* pViewData = GetViewData();
61 0 : ScDocument* pDoc = pViewData->GetDocument();
62 :
63 0 : SCTAB nCurrentTab = pViewData->GetTabNo();
64 0 : SCTAB nTabCount = pDoc->GetTableCount();
65 0 : sal_uInt16 nSlot = rReq.GetSlot();
66 0 : const SfxItemSet* pReqArgs = rReq.GetArgs();
67 :
68 0 : HideListBox(); // Autofilter-DropDown-Listbox
69 :
70 0 : switch ( nSlot )
71 : {
72 : case FID_TABLE_VISIBLE:
73 : {
74 0 : OUString aName;
75 0 : pDoc->GetName( nCurrentTab, aName );
76 :
77 0 : sal_Bool bVisible=sal_True;
78 0 : if( pReqArgs != NULL )
79 : {
80 : const SfxPoolItem* pItem;
81 0 : if( pReqArgs->HasItem( FID_TABLE_VISIBLE, &pItem ) )
82 0 : bVisible = ((const SfxBoolItem*)pItem)->GetValue();
83 : }
84 :
85 0 : if( ! bVisible ) // ausblenden
86 : {
87 0 : if ( pDoc->IsDocEditable() )
88 : {
89 0 : ScMarkData& rMark = pViewData->GetMarkData();
90 0 : HideTable( rMark );
91 : }
92 : }
93 : else // einblenden
94 : {
95 0 : std::vector<String> rNames;
96 0 : rNames.push_back(aName);
97 0 : ShowTable( rNames );
98 0 : }
99 : }
100 0 : break;
101 :
102 : case FID_TABLE_HIDE:
103 : {
104 0 : if ( pDoc->IsDocEditable() )
105 : {
106 0 : ScMarkData& rMark = pViewData->GetMarkData();
107 0 : HideTable( rMark );
108 : }
109 : }
110 0 : break;
111 :
112 : case FID_TABLE_SHOW:
113 : {
114 0 : String aName;
115 0 : std::vector<String> rNames;
116 0 : if ( pReqArgs )
117 : {
118 : const SfxPoolItem* pItem;
119 0 : if( pReqArgs->HasItem( FID_TABLE_SHOW, &pItem ) )
120 : {
121 0 : aName = ((const SfxStringItem*)pItem)->GetValue();
122 0 : rNames.push_back(aName);
123 0 : ShowTable( rNames );
124 :
125 0 : if( ! rReq.IsAPI() )
126 0 : rReq.Done();
127 : }
128 : }
129 : else
130 : {
131 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
132 : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
133 :
134 0 : AbstractScShowTabDlg* pDlg = pFact->CreateScShowTabDlg( GetDialogParent(), RID_SCDLG_SHOW_TAB);
135 : OSL_ENSURE(pDlg, "Dialog create fail!");
136 :
137 0 : OUString aTabName;
138 0 : sal_Bool bFirst = sal_True;
139 0 : for ( SCTAB i=0; i != nTabCount; i++ )
140 : {
141 0 : if (!pDoc->IsVisible(i))
142 : {
143 0 : pDoc->GetName( i, aTabName );
144 0 : pDlg->Insert( aTabName, bFirst );
145 0 : bFirst = false;
146 : }
147 : }
148 :
149 0 : if ( pDlg->Execute() == RET_OK )
150 : {
151 0 : sal_uInt16 nCount = pDlg->GetSelectEntryCount();
152 0 : for (sal_uInt16 nPos=0; nPos<nCount; nPos++)
153 : {
154 0 : aName = pDlg->GetSelectEntry(nPos);
155 0 : rReq.AppendItem( SfxStringItem( FID_TABLE_SHOW, aName ) );
156 0 : rNames.push_back(aName);
157 : }
158 0 : ShowTable( rNames );
159 0 : rReq.Done();
160 : }
161 0 : delete pDlg;
162 0 : }
163 : }
164 0 : break;
165 :
166 : case FID_INS_TABLE:
167 : case FID_INS_TABLE_EXT:
168 : {
169 0 : ScMarkData& rMark = pViewData->GetMarkData();
170 0 : SCTAB nTabSelCount = rMark.GetSelectCount();
171 0 : SCTAB nTabNr = nCurrentTab;
172 :
173 0 : if ( !pDoc->IsDocEditable() )
174 0 : break; // gesperrt
175 :
176 0 : if ( pReqArgs != NULL ) // von Basic
177 : {
178 0 : sal_Bool bOk = false;
179 : const SfxPoolItem* pTabItem;
180 : const SfxPoolItem* pNameItem;
181 0 : String aName;
182 :
183 0 : if ( pReqArgs->HasItem( FN_PARAM_1, &pTabItem ) &&
184 0 : pReqArgs->HasItem( nSlot, &pNameItem ) )
185 : {
186 : // Tabellennr. von Basic: 1-basiert
187 :
188 0 : aName = ((const SfxStringItem*)pNameItem)->GetValue();
189 0 : nTabNr = ((const SfxUInt16Item*)pTabItem)->GetValue() - 1;
190 0 : if ( nTabNr < nTabCount )
191 0 : bOk = InsertTable( aName, nTabNr );
192 : }
193 :
194 0 : if (bOk)
195 0 : rReq.Done( *pReqArgs );
196 : //! sonst Fehler setzen
197 : }
198 : else // Dialog
199 : {
200 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
201 : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
202 :
203 : AbstractScInsertTableDlg* pDlg = pFact->CreateScInsertTableDlg(GetDialogParent(), *pViewData,
204 0 : nTabSelCount, nSlot == FID_INS_TABLE_EXT);
205 : OSL_ENSURE(pDlg, "Dialog create fail!");
206 0 : if ( RET_OK == pDlg->Execute() )
207 : {
208 0 : if (pDlg->GetTablesFromFile())
209 : {
210 0 : std::vector<SCTAB> nTabs;
211 0 : sal_uInt16 n = 0;
212 0 : const String* pStr = pDlg->GetFirstTable( &n );
213 0 : while ( pStr )
214 : {
215 0 : nTabs.push_back( static_cast<SCTAB>(n) );
216 0 : pStr = pDlg->GetNextTable( &n );
217 : }
218 0 : sal_Bool bLink = pDlg->GetTablesAsLink();
219 0 : if (!nTabs.empty())
220 : {
221 0 : if(pDlg->IsTableBefore())
222 : {
223 0 : ImportTables( pDlg->GetDocShellTables(), nTabs.size(), &nTabs[0],
224 0 : bLink,nTabNr );
225 : }
226 : else
227 : {
228 0 : SCTAB nTabAfter = nTabNr+1;
229 :
230 0 : for(SCTAB j=nCurrentTab+1;j<nTabCount;j++)
231 : {
232 0 : if(!pDoc->IsScenario(j))
233 : {
234 0 : nTabAfter=j;
235 0 : break;
236 : }
237 : }
238 :
239 0 : ImportTables( pDlg->GetDocShellTables(), nTabs.size(), &nTabs[0],
240 0 : bLink,nTabAfter );
241 : }
242 0 : }
243 : }
244 : else
245 : {
246 0 : SCTAB nCount=pDlg->GetTableCount();
247 0 : if(pDlg->IsTableBefore())
248 : {
249 0 : if(nCount==1 && pDlg->GetFirstTable()->Len()>0)
250 : {
251 0 : rReq.AppendItem( SfxStringItem( FID_INS_TABLE, *pDlg->GetFirstTable() ) );
252 0 : rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nTabNr) + 1 ) ); // 1-based
253 0 : rReq.Done();
254 :
255 0 : InsertTable( *pDlg->GetFirstTable(), nTabNr );
256 : }
257 : else
258 : {
259 0 : std::vector<OUString> aNames(0);
260 0 : InsertTables( aNames, nTabNr,nCount );
261 : }
262 : }
263 : else
264 : {
265 0 : SCTAB nTabAfter = nTabNr+1;
266 0 : SCTAB nSelHigh = rMark.GetLastSelected();
267 :
268 0 : for(SCTAB j=nSelHigh+1;j<nTabCount;j++)
269 : {
270 0 : if(!pDoc->IsScenario(j))
271 : {
272 0 : nTabAfter=j;
273 0 : break;
274 : }
275 : else // #101672#; increase nTabAfter, because it is possible that the scenario tables are the last
276 0 : nTabAfter = j + 1;
277 : }
278 :
279 0 : if(nCount==1 && pDlg->GetFirstTable()->Len()>0)
280 : {
281 0 : rReq.AppendItem( SfxStringItem( FID_INS_TABLE, *pDlg->GetFirstTable() ) );
282 0 : rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nTabAfter) + 1 ) ); // 1-based
283 0 : rReq.Done();
284 :
285 0 : InsertTable( *pDlg->GetFirstTable(), nTabAfter);
286 : }
287 : else
288 : {
289 0 : std::vector<OUString> aNames(0);
290 0 : InsertTables( aNames, nTabAfter,nCount);
291 : }
292 : }
293 : }
294 : }
295 :
296 0 : delete pDlg;
297 : }
298 : }
299 0 : break;
300 :
301 : case FID_TAB_APPEND:
302 : case FID_TAB_RENAME:
303 : case FID_TAB_MENU_RENAME:
304 : {
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
308 :
309 0 : if ( nSlot == FID_TAB_MENU_RENAME )
310 0 : nSlot = FID_TAB_RENAME; // Execute ist gleich
311 :
312 0 : SCTAB nTabNr = pViewData->GetTabNo();
313 0 : ScMarkData& rMark = pViewData->GetMarkData();
314 0 : SCTAB nTabSelCount = rMark.GetSelectCount();
315 :
316 0 : if ( !pDoc->IsDocEditable() )
317 0 : break; // alles gesperrt
318 :
319 0 : if ( nSlot != FID_TAB_APPEND &&
320 0 : ( pDoc->IsTabProtected( nTabNr ) || nTabSelCount > 1 ) )
321 0 : break; // kein Rename
322 :
323 0 : if( pReqArgs != NULL )
324 : {
325 0 : sal_Bool bDone = false;
326 : const SfxPoolItem* pItem;
327 0 : String aName;
328 :
329 0 : if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
330 0 : nTabNr = ((const SfxUInt16Item*)pItem)->GetValue();
331 :
332 0 : if( pReqArgs->HasItem( nSlot, &pItem ) )
333 0 : aName = ((const SfxStringItem*)pItem)->GetValue();
334 :
335 0 : switch ( nSlot )
336 : {
337 : case FID_TAB_APPEND:
338 0 : bDone = AppendTable( aName );
339 0 : break;
340 : case FID_TAB_RENAME:
341 0 : bDone = RenameTable( aName, nTabNr );
342 0 : break;
343 : }
344 :
345 0 : if( bDone )
346 : {
347 0 : rReq.Done( *pReqArgs );
348 0 : }
349 : }
350 : else
351 : {
352 0 : sal_uInt16 nRet = RET_OK;
353 0 : sal_Bool bDone = false;
354 0 : String aErrMsg ( ScGlobal::GetRscString( STR_INVALIDTABNAME ) );
355 0 : OUString aName;
356 0 : String aDlgTitle;
357 0 : const sal_Char* pHelpId = 0;
358 :
359 0 : switch ( nSlot )
360 : {
361 : case FID_TAB_APPEND:
362 0 : aDlgTitle = String(ScResId(SCSTR_APDTABLE));
363 0 : pDoc->CreateValidTabName( aName );
364 0 : pHelpId = HID_SC_APPEND_NAME;
365 0 : break;
366 :
367 : case FID_TAB_RENAME:
368 0 : aDlgTitle = String(ScResId(SCSTR_RENAMETAB));
369 0 : pDoc->GetName( pViewData->GetTabNo(), aName );
370 0 : pHelpId = HID_SC_RENAME_NAME;
371 0 : break;
372 : }
373 :
374 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
375 : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
376 :
377 : AbstractScStringInputDlg* pDlg = pFact->CreateScStringInputDlg(
378 : GetDialogParent(), aDlgTitle, String(ScResId(SCSTR_NAME)),
379 0 : aName, GetStaticInterface()->GetSlot(nSlot)->GetCommand(),
380 0 : pHelpId, RID_SCDLG_STRINPUT);
381 :
382 : OSL_ENSURE(pDlg, "Dialog create fail!");
383 :
384 0 : while ( !bDone && nRet == RET_OK )
385 : {
386 0 : nRet = pDlg->Execute();
387 :
388 0 : if ( nRet == RET_OK )
389 : {
390 0 : pDlg->GetInputString( aName );
391 :
392 :
393 0 : switch ( nSlot )
394 : {
395 : case FID_TAB_APPEND:
396 0 : bDone = AppendTable( aName );
397 0 : break;
398 : case FID_TAB_RENAME:
399 0 : bDone = RenameTable( aName, nTabNr );
400 0 : break;
401 : }
402 :
403 0 : if ( bDone )
404 : {
405 0 : rReq.AppendItem( SfxStringItem( nSlot, aName ) );
406 0 : rReq.Done();
407 : }
408 : else
409 : {
410 0 : if( rReq.IsAPI() )
411 : {
412 : #ifndef DISABLE_SCRIPTING
413 0 : StarBASIC::Error( SbERR_SETPROP_FAILED ); // XXX Fehlerbehandlung???
414 : #endif
415 : }
416 : else
417 : {
418 : nRet = ErrorBox( GetDialogParent(),
419 : WinBits( WB_OK | WB_DEF_OK ),
420 : aErrMsg
421 0 : ).Execute();
422 : }
423 : }
424 : }
425 : }
426 0 : delete pDlg;
427 : }
428 : }
429 0 : break;
430 :
431 : case FID_TAB_MOVE:
432 : {
433 0 : if ( pDoc->GetChangeTrack() != NULL )
434 0 : break; // bei aktiviertem ChangeTracking kein TabMove
435 :
436 0 : sal_Bool bDoIt = false;
437 0 : sal_uInt16 nDoc = 0;
438 0 : SCTAB nTab = pViewData->GetTabNo();
439 0 : sal_Bool bCpy = false;
440 0 : OUString aDocName;
441 0 : OUString aTabName;
442 :
443 0 : if( pReqArgs != NULL )
444 : {
445 0 : SCTAB nTableCount = pDoc->GetTableCount();
446 : const SfxPoolItem* pItem;
447 :
448 0 : if( pReqArgs->HasItem( FID_TAB_MOVE, &pItem ) )
449 0 : aDocName = ((const SfxStringItem*)pItem)->GetValue();
450 0 : if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
451 : {
452 : // Tabelle ist 1-basiert
453 0 : nTab = ((const SfxUInt16Item*)pItem)->GetValue() - 1;
454 0 : if ( nTab >= nTableCount )
455 0 : nTab = SC_TAB_APPEND;
456 : }
457 0 : if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
458 0 : bCpy = ((const SfxBoolItem*)pItem)->GetValue();
459 :
460 0 : if (!aDocName.isEmpty())
461 : {
462 0 : SfxObjectShell* pSh = SfxObjectShell::GetFirst();
463 0 : ScDocShell* pScSh = NULL;
464 0 : sal_uInt16 i=0;
465 :
466 0 : while ( pSh )
467 : {
468 0 : pScSh = PTR_CAST( ScDocShell, pSh );
469 :
470 0 : if( pScSh )
471 : {
472 0 : pScSh->GetTitle();
473 :
474 0 : if (aDocName.equals(pScSh->GetTitle()))
475 : {
476 0 : nDoc = i;
477 0 : ScDocument* pDestDoc = pScSh->GetDocument();
478 0 : nTableCount = pDestDoc->GetTableCount();
479 0 : bDoIt = pDestDoc->IsDocEditable();
480 0 : break;
481 : }
482 :
483 0 : i++; // nur die ScDocShell's zaehlen
484 : }
485 0 : pSh = SfxObjectShell::GetNext( *pSh );
486 : }
487 : }
488 : else // Kein Dokumentname -> neues Dokument
489 : {
490 0 : nDoc = SC_DOC_NEW;
491 0 : bDoIt = sal_True;
492 : }
493 :
494 0 : if ( bDoIt && nTab >= nTableCount ) // ggf. anhaengen
495 0 : nTab = SC_TAB_APPEND;
496 : }
497 : else
498 : {
499 0 : OUString aDefaultName;
500 0 : pDoc->GetName( pViewData->GetTabNo(), aDefaultName );
501 :
502 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
503 : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
504 :
505 : AbstractScMoveTableDlg* pDlg = pFact->CreateScMoveTableDlg( GetDialogParent(),
506 : aDefaultName,
507 0 : RID_SCDLG_MOVETAB );
508 : OSL_ENSURE(pDlg, "Dialog create fail!");
509 :
510 0 : SCTAB nTableCount = pDoc->GetTableCount();
511 0 : ScMarkData& rMark = GetViewData()->GetMarkData();
512 0 : SCTAB nTabSelCount = rMark.GetSelectCount();
513 :
514 :
515 0 : if(nTableCount==nTabSelCount)
516 : {
517 0 : pDlg->SetForceCopyTable();
518 : }
519 :
520 : // We support direct renaming of sheet only when one sheet
521 : // is selected.
522 0 : pDlg->EnableRenameTable(nTabSelCount == 1);
523 :
524 0 : if ( pDlg->Execute() == RET_OK )
525 : {
526 0 : nDoc = pDlg->GetSelectedDocument();
527 0 : nTab = pDlg->GetSelectedTable();
528 0 : bCpy = pDlg->GetCopyTable();
529 0 : bool bRna = pDlg->GetRenameTable();
530 : // Leave aTabName string empty, when Rename is FALSE.
531 0 : if( bRna )
532 : {
533 0 : pDlg->GetTabNameString( aTabName );
534 : }
535 0 : bDoIt = true;
536 :
537 0 : String aFoundDocName;
538 0 : if ( nDoc != SC_DOC_NEW )
539 : {
540 0 : ScDocShell* pSh = ScDocShell::GetShellByNum( nDoc );
541 0 : if (pSh)
542 : {
543 0 : aFoundDocName = pSh->GetTitle();
544 0 : if ( !pSh->GetDocument()->IsDocEditable() )
545 : {
546 0 : ErrorMessage(STR_READONLYERR);
547 0 : bDoIt = false;
548 : }
549 : }
550 : }
551 0 : rReq.AppendItem( SfxStringItem( FID_TAB_MOVE, aFoundDocName ) );
552 : // Tabelle ist 1-basiert, wenn nicht APPEND
553 0 : SCTAB nBasicTab = ( nTab <= MAXTAB ) ? (nTab+1) : nTab;
554 0 : rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nBasicTab) ) );
555 0 : rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bCpy ) );
556 : }
557 0 : delete pDlg;
558 : }
559 :
560 0 : if( bDoIt )
561 : {
562 0 : rReq.Done(); // aufzeichnen, solange das Dokument noch aktiv ist
563 :
564 0 : MoveTable( nDoc, nTab, bCpy, &aTabName );
565 0 : }
566 : }
567 0 : break;
568 :
569 : case FID_DELETE_TABLE:
570 : {
571 : // Parameter war ueberfluessig, weil die Methode an der Table haengt
572 :
573 0 : sal_Bool bDoIt = rReq.IsAPI();
574 0 : if( !bDoIt )
575 : {
576 : // wenn's nicht von Basic kommt, nochmal nachfragen:
577 :
578 0 : bDoIt = ( RET_YES ==
579 : QueryBox( GetDialogParent(),
580 : WinBits( WB_YES_NO | WB_DEF_YES ),
581 0 : ScGlobal::GetRscString(STR_QUERY_DELTAB)
582 0 : ).Execute() );
583 : }
584 0 : if( bDoIt )
585 : {
586 0 : SCTAB nNewTab = nCurrentTab;
587 0 : SCTAB nFirstTab=0;
588 0 : bool bTabFlag=false;
589 0 : ScMarkData& rMark = pViewData->GetMarkData();
590 0 : std::vector<SCTAB> TheTabs;
591 0 : for(SCTAB i=0;i<nTabCount;i++)
592 : {
593 0 : if(rMark.GetTableSelect(i) &&!pDoc->IsTabProtected(i))
594 : {
595 0 : TheTabs.push_back(i);
596 0 : bTabFlag=true;
597 0 : if(nNewTab==i) nNewTab++;
598 : }
599 0 : if(!bTabFlag) nFirstTab=i;
600 : }
601 0 : if(nNewTab>=nTabCount) nNewTab=nFirstTab;
602 :
603 0 : pViewData->SetTabNo(nNewTab);
604 0 : DeleteTables(TheTabs);
605 0 : TheTabs.clear();
606 0 : rReq.Done();
607 : }
608 : }
609 0 : break;
610 :
611 : case FID_TAB_RTL:
612 : {
613 0 : ScDocShell* pDocSh = pViewData->GetDocShell();
614 0 : ScDocFunc &rFunc = pDocSh->GetDocFunc();
615 0 : sal_Bool bSet = !pDoc->IsLayoutRTL( nCurrentTab );
616 :
617 0 : const ScMarkData& rMark = pViewData->GetMarkData();
618 0 : if ( rMark.GetSelectCount() != 0 )
619 : {
620 : // handle several sheets
621 :
622 0 : ::svl::IUndoManager* pUndoManager = pDocSh->GetUndoManager();
623 0 : String aUndo = ScGlobal::GetRscString( STR_UNDO_TAB_RTL );
624 0 : pUndoManager->EnterListAction( aUndo, aUndo );
625 :
626 0 : ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end();
627 0 : for (; itr != itrEnd; ++itr)
628 0 : rFunc.SetLayoutRTL( *itr, bSet, false );
629 :
630 0 : pUndoManager->LeaveListAction();
631 : }
632 : else
633 0 : rFunc.SetLayoutRTL( nCurrentTab, bSet, false );
634 : }
635 0 : break;
636 :
637 : case FID_TAB_TOGGLE_GRID:
638 : {
639 0 : bool bShowGrid = pViewData->GetShowGrid();
640 0 : pViewData->SetShowGrid(!bShowGrid);
641 0 : SfxBindings& rBindings = GetViewFrame()->GetBindings();
642 0 : rBindings.Invalidate( FID_TAB_TOGGLE_GRID );
643 0 : PaintGrid();
644 0 : rReq.Done();
645 : }
646 0 : break;
647 :
648 : case FID_TAB_SET_TAB_BG_COLOR:
649 : case FID_TAB_MENU_SET_TAB_BG_COLOR:
650 : {
651 0 : if ( nSlot == FID_TAB_MENU_SET_TAB_BG_COLOR )
652 0 : nSlot = FID_TAB_SET_TAB_BG_COLOR;
653 0 : SCTAB nTabNr = pViewData->GetTabNo();
654 0 : ScMarkData& rMark = pViewData->GetMarkData();
655 0 : SCTAB nTabSelCount = rMark.GetSelectCount();
656 0 : if ( !pDoc->IsDocEditable() )
657 0 : break;
658 :
659 0 : if ( pDoc->IsTabProtected( nTabNr ) ) // ||nTabSelCount > 1
660 0 : break;
661 :
662 0 : if( pReqArgs != NULL )
663 : {
664 0 : sal_Bool bDone = false;
665 : const SfxPoolItem* pItem;
666 0 : Color aColor;
667 0 : if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
668 0 : nTabNr = ((const SfxUInt16Item*)pItem)->GetValue();
669 :
670 0 : if( pReqArgs->HasItem( nSlot, &pItem ) )
671 0 : aColor = ((const SvxColorItem*)pItem)->GetValue();
672 :
673 0 : if ( nTabSelCount > 1 )
674 : {
675 : scoped_ptr<ScUndoTabColorInfo::List>
676 0 : pTabColorList(new ScUndoTabColorInfo::List);
677 0 : ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end();
678 0 : for (; itr != itrEnd; ++itr)
679 : {
680 0 : if ( !pDoc->IsTabProtected(*itr) )
681 : {
682 0 : ScUndoTabColorInfo aTabColorInfo(*itr);
683 0 : aTabColorInfo.maNewTabBgColor = aColor;
684 0 : pTabColorList->push_back(aTabColorInfo);
685 : }
686 : }
687 0 : bDone = SetTabBgColor( *pTabColorList );
688 : }
689 : else
690 : {
691 0 : bDone = SetTabBgColor( aColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
692 : }
693 0 : if( bDone )
694 : {
695 0 : rReq.Done( *pReqArgs );
696 : }
697 : }
698 : else
699 : {
700 0 : sal_uInt16 nRet = RET_OK; /// temp
701 0 : sal_Bool bDone = false; /// temp
702 0 : Color aTabBgColor;
703 :
704 0 : aTabBgColor = pDoc->GetTabBgColor( nCurrentTab );
705 0 : 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 0 : RID_SCDLG_TAB_BG_COLOR);
714 0 : while ( !bDone && nRet == RET_OK )
715 : {
716 0 : nRet = pDlg->Execute();
717 0 : if( nRet == RET_OK )
718 : {
719 0 : Color aSelectedColor;
720 0 : pDlg->GetSelectedColor(aSelectedColor);
721 : scoped_ptr<ScUndoTabColorInfo::List>
722 0 : pTabColorList(new ScUndoTabColorInfo::List);
723 0 : if ( nTabSelCount > 1 )
724 : {
725 0 : ScMarkData::iterator itr = rMark.begin(), itrEnd = rMark.end();
726 0 : for (; itr != itrEnd; ++itr)
727 : {
728 0 : if ( !pDoc->IsTabProtected(*itr) )
729 : {
730 0 : ScUndoTabColorInfo aTabColorInfo(*itr);
731 0 : aTabColorInfo.maNewTabBgColor = aSelectedColor;
732 0 : pTabColorList->push_back(aTabColorInfo);
733 : }
734 : }
735 0 : bDone = SetTabBgColor( *pTabColorList );
736 : }
737 : else
738 : {
739 0 : bDone = SetTabBgColor( aSelectedColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
740 : }
741 0 : if ( bDone )
742 : {
743 0 : rReq.AppendItem( SvxColorItem( aTabBgColor, nSlot ) );
744 0 : rReq.Done();
745 : }
746 : else
747 : {
748 0 : if( rReq.IsAPI() )
749 : {
750 : #ifndef DISABLE_SCRIPTING
751 0 : StarBASIC::Error( SbERR_SETPROP_FAILED );
752 : #endif
753 : }
754 0 : }
755 : }
756 : }
757 0 : delete( pDlg );
758 : }
759 : }
760 0 : break;
761 :
762 : case FID_TAB_EVENTS:
763 : {
764 0 : ScDocShell* pDocSh = pViewData->GetDocShell();
765 0 : uno::Reference<container::XNameReplace> xEvents( new ScSheetEventsObj( pDocSh, nCurrentTab ) );
766 0 : uno::Reference<frame::XFrame> xFrame = GetViewFrame()->GetFrame().GetFrameInterface();
767 0 : SvxAbstractDialogFactory* pDlgFactory = SvxAbstractDialogFactory::Create();
768 0 : if (pDlgFactory)
769 : {
770 : std::auto_ptr<VclAbstractDialog> pDialog( pDlgFactory->CreateSvxMacroAssignDlg(
771 0 : GetDialogParent(), xFrame, false, xEvents, 0 ) );
772 0 : if ( pDialog.get() && pDialog->Execute() == RET_OK )
773 : {
774 : // the dialog modifies the settings directly
775 0 : }
776 0 : }
777 : }
778 0 : break;
779 :
780 : default:
781 : OSL_FAIL("Unbekannte Message bei ViewShell");
782 0 : break;
783 : }
784 0 : }
785 :
786 : //------------------------------------------------------------------
787 :
788 180 : void ScTabViewShell::GetStateTable( SfxItemSet& rSet )
789 : {
790 180 : ScViewData* pViewData = GetViewData();
791 180 : ScDocument* pDoc = pViewData->GetDocument();
792 180 : ScDocShell* pDocShell = pViewData->GetDocShell();
793 180 : ScMarkData& rMark = GetViewData()->GetMarkData();
794 180 : SCTAB nTab = pViewData->GetTabNo();
795 :
796 180 : SCTAB nTabCount = pDoc->GetTableCount();
797 180 : SCTAB nTabSelCount = rMark.GetSelectCount();
798 :
799 180 : SfxWhichIter aIter(rSet);
800 180 : sal_uInt16 nWhich = aIter.FirstWhich();
801 :
802 540 : while ( nWhich )
803 : {
804 180 : switch ( nWhich )
805 : {
806 :
807 : case FID_TABLE_VISIBLE:
808 0 : rSet.Put( SfxBoolItem( nWhich, pDoc->IsVisible(nTab) ));
809 0 : break;
810 :
811 : case FID_TABLE_HIDE:
812 : {
813 0 : 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 0 : for ( SCTAB i=0; i < nTabCount && nVis<nTabSelCount + 1; i++ )
816 0 : if (pDoc->IsVisible(i))
817 0 : ++nVis;
818 0 : if ( nVis<=nTabSelCount || !pDoc->IsDocEditable() )
819 0 : rSet.DisableItem( nWhich );
820 : }
821 0 : break;
822 :
823 : case FID_TABLE_SHOW:
824 : {
825 0 : sal_Bool bHasHidden = false;
826 0 : for ( SCTAB i=0; i < nTabCount && !bHasHidden; i++ )
827 0 : if (!pDoc->IsVisible(i))
828 0 : bHasHidden = sal_True;
829 0 : if ( !bHasHidden || pDoc->IsDocProtected() || nTabSelCount > 1 )
830 0 : rSet.DisableItem( nWhich );
831 : }
832 0 : break;
833 :
834 : case FID_DELETE_TABLE:
835 : {
836 0 : if ( pDoc->GetChangeTrack() )
837 0 : rSet.DisableItem( nWhich );
838 : else
839 : {
840 0 : sal_uInt16 nVis = 0;
841 0 : for ( SCTAB i=0; i < nTabCount && nVis<2; i++ )
842 0 : if (pDoc->IsVisible(i))
843 0 : ++nVis;
844 0 : if ( pDoc->IsTabProtected(nTab)
845 0 : || !pDoc->IsDocEditable()
846 0 : || nVis < 2
847 0 : || nTabSelCount == nTabCount)
848 0 : rSet.DisableItem( nWhich );
849 : }
850 : }
851 0 : break;
852 :
853 : case FID_INS_TABLE:
854 : case FID_INS_TABLE_EXT:
855 : case FID_TAB_APPEND:
856 0 : if ( !pDoc->IsDocEditable() ||
857 0 : nTabCount > MAXTAB ||
858 0 : ( nWhich == FID_INS_TABLE_EXT && pDocShell && pDocShell->IsDocShared() ) )
859 0 : rSet.DisableItem( nWhich );
860 0 : break;
861 :
862 : case FID_TAB_MOVE:
863 0 : if ( !pDoc->IsDocEditable()
864 0 : || pDoc->GetChangeTrack() != NULL
865 0 : || nTabCount > MAXTAB)
866 0 : rSet.DisableItem( nWhich );
867 0 : break;
868 :
869 : // FID_TAB_MENU_RENAME - "umbenennen" im Menu
870 : // FID_TAB_RENAME - "Name"-Property fuer Basic
871 :
872 : case FID_TAB_MENU_RENAME:
873 0 : if ( !pDoc->IsDocEditable() ||
874 0 : pDoc->IsTabProtected(nTab) ||nTabSelCount > 1 ||
875 0 : ( pDocShell && pDocShell->IsDocShared() ) )
876 0 : rSet.DisableItem( nWhich );
877 0 : break;
878 :
879 : case FID_TAB_RENAME:
880 : {
881 0 : OUString aTabName;
882 0 : pDoc->GetName( nTab, aTabName );
883 :
884 0 : rSet.Put( SfxStringItem( nWhich, aTabName ));
885 :
886 : }
887 0 : break;
888 :
889 : case FID_TAB_RTL:
890 : {
891 0 : SvtLanguageOptions aLangOpt;
892 0 : if ( !aLangOpt.IsCTLFontEnabled() )
893 0 : rSet.DisableItem( nWhich );
894 : else
895 0 : rSet.Put( SfxBoolItem( nWhich, pDoc->IsLayoutRTL( nTab ) ) );
896 : }
897 0 : break;
898 :
899 : case FID_TAB_MENU_SET_TAB_BG_COLOR:
900 : {
901 0 : if ( !pDoc->IsDocEditable()
902 0 : || ( pDocShell && pDocShell->IsDocShared() )
903 0 : || pDoc->IsTabProtected(nTab) )
904 0 : rSet.DisableItem( nWhich );
905 : }
906 0 : break;
907 :
908 : case FID_TAB_SET_TAB_BG_COLOR:
909 : {
910 0 : Color aColor;
911 0 : aColor = pDoc->GetTabBgColor( nTab );
912 0 : rSet.Put( SvxColorItem( aColor, nWhich ) );
913 : }
914 0 : break;
915 :
916 : case FID_TAB_TOGGLE_GRID:
917 180 : rSet.Put( SfxBoolItem(nWhich, pViewData->GetShowGrid()) );
918 180 : break;
919 : }
920 180 : nWhich = aIter.NextWhich();
921 180 : }
922 273 : }
923 :
924 :
925 :
926 :
927 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|