1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26
27
28
29 // INCLUDE ---------------------------------------------------------------
30
31 #include "scitems.hxx"
32 #include <editeng/eeitem.hxx>
33
34 #include <sfx2/app.hxx>
35 //CHINA001 #include <svx/zoom.hxx>
36 #include <sfx2/bindings.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <sfx2/passwd.hxx>
39 #include <sfx2/request.hxx>
40 #include <svl/ptitem.hxx>
41 #include <svl/stritem.hxx>
42 #include <tools/urlobj.hxx>
43 #include <sfx2/objface.hxx>
44 #include <vcl/msgbox.hxx>
45 #include <vcl/vclenum.hxx>
46
47 #include "globstr.hrc"
48 #include "scmod.hxx"
49 #include "appoptio.hxx"
50 #include "tabvwsh.hxx"
51 #include "document.hxx"
52 #include "sc.hrc"
53 #include "inputwin.hxx"
54 #include "scresid.hxx"
55 #include "printfun.hxx"
56 #include "docsh.hxx"
57 #include "rangelst.hxx"
58 #include "prevwsh.hxx"
59 #include "rangeutl.hxx"
60 #include "reffact.hxx"
61 #include "uiitems.hxx"
62 #include "cell.hxx"
63 #include "inputhdl.hxx"
64 //CHINA001 #include "scendlg.hxx"
65 //CHINA001 #include "mtrindlg.hxx"
66 #include "autoform.hxx"
67 #include "autofmt.hxx"
68 #include "dwfunctr.hxx"
69 #include "shtabdlg.hxx"
70 #include "tabprotection.hxx"
71 #include "protectiondlg.hxx"
72
73 #include <svl/ilstitem.hxx>
74 #define _SVSTDARR_ULONGS
75 #include <svl/svstdarr.hxx>
76
77 #include <svx/zoomslideritem.hxx>
78 #include <svx/svxdlg.hxx> //CHINA001
79 #include <svx/dialogs.hrc> //CHINA001
80 #include "scabstdlg.hxx" //CHINA001
81
82 #include <memory>
83
84 using ::std::auto_ptr;
85
86 #define IS_EDITMODE() GetViewData()->HasEditView( GetViewData()->GetActivePart() )
87 #define IS_AVAILABLE(WhichId,ppItem) \
88 (pReqArgs->GetItemState((WhichId), sal_True, ppItem ) == SFX_ITEM_SET)
89 #define GET_STRING(nid) ((const SfxStringItem&)pReqArgs->Get(nid)).GetValue()
90 #define GET_UINT16(nid) ((const SfxUInt16Item&)pReqArgs->Get(nid)).GetValue()
91 #define GET_BOOL(nid) ((const SfxBoolItem&)pReqArgs->Get(nid)).GetValue()
92 #define RECALC_PAGE(pDocSh) ScPrintFunc( pDocSh, GetPrinter(), nCurTab ).UpdatePages()
93
94 //------------------------------------------------------------------
95
96 /** Try to parse the given range using Calc-style syntax first, then
97 Excel-style if that fails. */
lcl_ParseRange(ScRange & rScRange,const String & aAddress,ScDocument * pDoc,sal_uInt16)98 sal_uInt16 lcl_ParseRange(ScRange& rScRange, const String& aAddress, ScDocument* pDoc, sal_uInt16 /* nSlot */)
99 {
100 sal_uInt16 nResult = rScRange.Parse(aAddress, pDoc);
101 if ( (nResult & SCA_VALID) )
102 return nResult;
103
104 return rScRange.Parse(aAddress, pDoc, ScAddress::Details(formula::FormulaGrammar::CONV_XL_A1, 0, 0));
105 }
106
107 /** Try to parse the given address using Calc-style syntax first, then
108 Excel-style if that fails. */
lcl_ParseAddress(ScAddress & rScAddress,const String & aAddress,ScDocument * pDoc,sal_uInt16)109 sal_uInt16 lcl_ParseAddress(ScAddress& rScAddress, const String& aAddress, ScDocument* pDoc, sal_uInt16 /* nSlot */)
110 {
111 sal_uInt16 nResult = rScAddress.Parse(aAddress, pDoc);
112 if ( (nResult & SCA_VALID) )
113 return nResult;
114
115 return rScAddress.Parse(aAddress, pDoc, ScAddress::Details(formula::FormulaGrammar::CONV_XL_A1, 0, 0));
116 }
117
Execute(SfxRequest & rReq)118 void ScTabViewShell::Execute( SfxRequest& rReq )
119 {
120 SfxViewFrame* pThisFrame = GetViewFrame();
121 SfxBindings& rBindings = pThisFrame->GetBindings();
122 ScModule* pScMod = SC_MOD();
123 const SfxItemSet* pReqArgs = rReq.GetArgs();
124 sal_uInt16 nSlot = rReq.GetSlot();
125
126 if (nSlot != SID_CURRENTCELL) // der kommt beim MouseButtonUp
127 HideListBox(); // Autofilter-DropDown-Listbox
128
129 switch ( nSlot )
130 {
131 case FID_INSERT_FILE:
132 {
133 const SfxPoolItem* pItem;
134 if ( pReqArgs &&
135 pReqArgs->GetItemState(FID_INSERT_FILE,sal_True,&pItem) == SFX_ITEM_SET )
136 {
137 String aFileName = ((const SfxStringItem*)pItem)->GetValue();
138
139 // Einfuege-Position
140
141 Point aInsertPos;
142 if ( pReqArgs->GetItemState(FN_PARAM_1,sal_True,&pItem) == SFX_ITEM_SET )
143 aInsertPos = ((const SfxPointItem*)pItem)->GetValue();
144 else
145 aInsertPos = GetInsertPos();
146
147 // als Link?
148
149 sal_Bool bAsLink = sal_False;
150 if ( pReqArgs->GetItemState(FN_PARAM_2,sal_True,&pItem) == SFX_ITEM_SET )
151 bAsLink = ((const SfxBoolItem*)pItem)->GetValue();
152
153 // ausfuehren
154
155 PasteFile( aInsertPos, aFileName, bAsLink );
156 }
157 }
158 break;
159
160 case SID_OPENDLG_EDIT_PRINTAREA:
161 {
162 sal_uInt16 nId = ScPrintAreasDlgWrapper::GetChildWindowId();
163 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
164
165 pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True );
166 }
167 break;
168
169 case SID_CHANGE_PRINTAREA:
170 {
171 if ( pReqArgs ) // OK aus Dialog
172 {
173 String aPrintStr;
174 String aRowStr;
175 String aColStr;
176 sal_Bool bEntire = sal_False;
177 const SfxPoolItem* pItem;
178 if ( pReqArgs->GetItemState( SID_CHANGE_PRINTAREA, sal_True, &pItem ) == SFX_ITEM_SET )
179 aPrintStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
180 if ( pReqArgs->GetItemState( FN_PARAM_2, sal_True, &pItem ) == SFX_ITEM_SET )
181 aRowStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
182 if ( pReqArgs->GetItemState( FN_PARAM_3, sal_True, &pItem ) == SFX_ITEM_SET )
183 aColStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
184 if ( pReqArgs->GetItemState( FN_PARAM_4, sal_True, &pItem ) == SFX_ITEM_SET )
185 bEntire = static_cast<const SfxBoolItem*>(pItem)->GetValue();
186
187 SetPrintRanges( bEntire, &aPrintStr, &aColStr, &aRowStr, sal_False );
188
189 rReq.Done();
190 }
191 }
192 break;
193
194 case SID_ADD_PRINTAREA:
195 case SID_DEFINE_PRINTAREA: // Menue oder Basic
196 {
197 sal_Bool bAdd = ( nSlot == SID_ADD_PRINTAREA );
198 if ( pReqArgs )
199 {
200 String aPrintStr;
201 const SfxPoolItem* pItem;
202 if ( pReqArgs->GetItemState( SID_DEFINE_PRINTAREA, sal_True, &pItem ) == SFX_ITEM_SET )
203 aPrintStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
204 SetPrintRanges( sal_False, &aPrintStr, NULL, NULL, bAdd );
205 }
206 else
207 {
208 SetPrintRanges( sal_False, NULL, NULL, NULL, bAdd ); // aus Selektion
209 rReq.Done();
210 }
211 }
212 break;
213
214 case SID_DELETE_PRINTAREA:
215 {
216 String aEmpty;
217 SetPrintRanges( sal_False, &aEmpty, NULL, NULL, sal_False ); // Druckbereich loeschen
218 rReq.Done();
219 }
220 break;
221
222 case FID_DEL_MANUALBREAKS:
223 RemoveManualBreaks();
224 rReq.Done();
225 break;
226
227 case FID_ADJUST_PRINTZOOM:
228 AdjustPrintZoom();
229 rReq.Done();
230 break;
231
232 case FID_RESET_PRINTZOOM:
233 SetPrintZoom( 100, 0 ); // 100%, nicht auf Seiten
234 rReq.Done();
235 break;
236
237 case SID_FORMATPAGE:
238 case SID_STATUS_PAGESTYLE:
239 case SID_HFEDIT:
240 GetViewData()->GetDocShell()->
241 ExecutePageStyle( *this, rReq, GetViewData()->GetTabNo() );
242 break;
243
244 case SID_JUMPTOMARK:
245 case SID_CURRENTCELL:
246 if ( pReqArgs )
247 {
248 String aAddress;
249 const SfxPoolItem* pItem;
250 if ( pReqArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET )
251 aAddress = ((const SfxStringItem*)pItem)->GetValue();
252 else if ( nSlot == SID_JUMPTOMARK && pReqArgs->GetItemState(
253 SID_JUMPTOMARK, sal_True, &pItem ) == SFX_ITEM_SET )
254 aAddress = ((const SfxStringItem*)pItem)->GetValue();
255
256 // #i14927# SID_CURRENTCELL with a single cell must unmark if FN_PARAM_1
257 // isn't set (for recorded macros, because IsAPI is no longer available).
258 // ScGridWindow::MouseButtonUp no longer executes the slot for a single
259 // cell if there is a multi selection.
260 sal_Bool bUnmark = ( nSlot == SID_CURRENTCELL );
261 if ( pReqArgs->GetItemState( FN_PARAM_1, sal_True, &pItem ) == SFX_ITEM_SET )
262 bUnmark = ((const SfxBoolItem*)pItem)->GetValue();
263
264 if ( nSlot == SID_JUMPTOMARK )
265 {
266 // #106586# URL has to be decoded for escaped characters (%20)
267 aAddress = INetURLObject::decode( aAddress, INET_HEX_ESCAPE,
268 INetURLObject::DECODE_WITH_CHARSET,
269 RTL_TEXTENCODING_UTF8 );
270 }
271
272 sal_Bool bFound = sal_False;
273 ScViewData* pViewData = GetViewData();
274 ScDocument* pDoc = pViewData->GetDocument();
275 ScMarkData& rMark = pViewData->GetMarkData();
276 ScRange aScRange;
277 ScAddress aScAddress;
278 sal_uInt16 nResult = lcl_ParseRange(aScRange, aAddress, pDoc, nSlot);
279 SCTAB nTab = pViewData->GetTabNo();
280 sal_Bool bMark = sal_True;
281
282 // Is this a range ?
283 if( nResult & SCA_VALID )
284 {
285 if ( nResult & SCA_TAB_3D )
286 {
287 if( aScRange.aStart.Tab() != nTab )
288 SetTabNo( nTab = aScRange.aStart.Tab() );
289 }
290 else
291 {
292 aScRange.aStart.SetTab( nTab );
293 aScRange.aEnd.SetTab( nTab );
294 }
295 }
296 // Is this a cell ?
297 else if ( (nResult = lcl_ParseAddress(aScAddress, aAddress, pDoc, nSlot)) & SCA_VALID )
298 {
299 if ( nResult & SCA_TAB_3D )
300 {
301 if( aScAddress.Tab() != nTab )
302 SetTabNo( nTab = aScAddress.Tab() );
303 }
304 else
305 aScAddress.SetTab( nTab );
306
307 aScRange = ScRange( aScAddress, aScAddress );
308 // Zellen sollen nicht markiert werden
309 bMark = sal_False;
310 }
311 // Ist es benahmster Bereich (erst Namen dann DBBereiche) ?
312 else
313 {
314 ScRangeUtil aRangeUtil;
315 formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
316 if( aRangeUtil.MakeRangeFromName( aAddress, pDoc, nTab, aScRange, RUTL_NAMES, eConv ) ||
317 aRangeUtil.MakeRangeFromName( aAddress, pDoc, nTab, aScRange, RUTL_DBASE, eConv ) )
318 {
319 nResult |= SCA_VALID;
320 if( aScRange.aStart.Tab() != nTab )
321 SetTabNo( nTab = aScRange.aStart.Tab() );
322 }
323 }
324
325 if ( !(nResult & SCA_VALID) &&
326 ByteString(aAddress, RTL_TEXTENCODING_ASCII_US).IsNumericAscii() )
327 {
328 sal_Int32 nNumeric = aAddress.ToInt32();
329 if ( nNumeric > 0 && nNumeric <= MAXROW+1 )
330 {
331 // 1-basierte Zeilennummer
332
333 aScAddress.SetRow( (SCROW)(nNumeric - 1) );
334 aScAddress.SetCol( pViewData->GetCurX() );
335 aScAddress.SetTab( nTab );
336 aScRange = ScRange( aScAddress, aScAddress );
337 bMark = sal_False;
338 nResult = SCA_VALID;
339 }
340 }
341
342 if ( !ValidRow(aScRange.aStart.Row()) || !ValidRow(aScRange.aEnd.Row()) )
343 nResult = 0;
344
345 // wir haben was gefunden
346 if( nResult & SCA_VALID )
347 {
348 bFound = sal_True;
349 SCCOL nCol = aScRange.aStart.Col();
350 SCROW nRow = aScRange.aStart.Row();
351 sal_Bool bNothing = ( pViewData->GetCurX()==nCol && pViewData->GetCurY()==nRow );
352
353 // markieren
354 if( bMark )
355 {
356 if (rMark.IsMarked()) // ist derselbe Bereich schon markiert?
357 {
358 ScRange aOldMark;
359 rMark.GetMarkArea( aOldMark );
360 aOldMark.Justify();
361 ScRange aCurrent = aScRange;
362 aCurrent.Justify();
363 bNothing = ( aCurrent == aOldMark );
364 }
365 else
366 bNothing = sal_False;
367
368 if (!bNothing)
369 MarkRange( aScRange, sal_False ); // Cursor kommt hinterher...
370 }
371 else
372 {
373 // remove old selection, unless bUnmark argument is sal_False (from navigator)
374 if( bUnmark )
375 {
376 MoveCursorAbs( nCol, nRow,
377 SC_FOLLOW_NONE, sal_False, sal_False );
378 }
379 }
380
381 // und Cursor setzen
382
383 // zusammengefasste Zellen beruecksichtigen:
384 while ( pDoc->IsHorOverlapped( nCol, nRow, nTab ) ) //! ViewData !!!
385 --nCol;
386 while ( pDoc->IsVerOverlapped( nCol, nRow, nTab ) )
387 --nRow;
388
389 // Navigator-Aufrufe sind nicht API!!!
390
391 if( bNothing )
392 {
393 if (rReq.IsAPI())
394 rReq.Ignore(); // wenn Makro, dann gar nix
395 else
396 rReq.Done(); // sonst wenigstens aufzeichnen
397 }
398 else
399 {
400 pViewData->ResetOldCursor();
401 SetCursor( nCol, nRow );
402 AlignToCursor( nCol, nRow, SC_FOLLOW_JUMP );
403 rBindings.Invalidate( SID_CURRENTCELL );
404 rBindings.Update( nSlot );
405
406 if (!rReq.IsAPI())
407 rReq.Done();
408 }
409
410 rReq.SetReturnValue( SfxStringItem( SID_CURRENTCELL, aAddress ) );
411 }
412
413 if (!bFound) // kein gueltiger Bereich
414 {
415 // wenn es ein Tabellenname ist, umschalten (fuer Navigator/URL's)
416
417 SCTAB nNameTab;
418 if ( pDoc->GetTable( aAddress, nNameTab ) )
419 {
420 bFound = sal_True;
421 if ( nNameTab != nTab )
422 SetTabNo( nNameTab );
423 }
424 }
425
426 if ( !bFound && nSlot == SID_JUMPTOMARK )
427 {
428 // Grafik-Objekte probieren (nur bei URL's)
429
430 bFound = SelectObject( aAddress );
431 }
432
433 if (!bFound && !rReq.IsAPI())
434 ErrorMessage( STR_ERR_INVALID_AREA );
435 }
436 break;
437
438 case SID_CURRENTOBJECT:
439 if ( pReqArgs )
440 {
441 String aName = ((const SfxStringItem&)pReqArgs->Get(nSlot)).GetValue();
442 SelectObject( aName );
443 }
444 break;
445
446 case SID_CURRENTTAB:
447 if ( pReqArgs )
448 {
449 // Tabelle fuer Basic ist 1-basiert
450 SCTAB nTab = ((const SfxUInt16Item&)pReqArgs->Get(nSlot)).GetValue() - 1;
451 ScDocument* pDoc = GetViewData()->GetDocument();
452 if ( nTab < pDoc->GetTableCount() )
453 {
454 SetTabNo( nTab );
455 rBindings.Update( nSlot );
456
457 if( ! rReq.IsAPI() )
458 rReq.Done();
459 }
460 //! sonst Fehler ?
461 }
462 break;
463
464 case SID_CURRENTDOC:
465 if ( pReqArgs )
466 {
467 String aStrDocName( ((const SfxStringItem&)pReqArgs->
468 Get(nSlot)).GetValue() );
469
470 SfxViewFrame* pViewFrame = NULL;
471 ScDocShell* pDocSh = (ScDocShell*)SfxObjectShell::GetFirst();
472 sal_Bool bFound = sal_False;
473
474 // zu aktivierenden ViewFrame suchen
475
476 while ( pDocSh && !bFound )
477 {
478 if ( pDocSh->GetTitle() == aStrDocName )
479 {
480 pViewFrame = SfxViewFrame::GetFirst( pDocSh );
481 bFound = ( NULL != pViewFrame );
482 }
483
484 pDocSh = (ScDocShell*)SfxObjectShell::GetNext( *pDocSh );
485 }
486
487 if ( bFound )
488 pViewFrame->GetFrame().Appear();
489
490 rReq.Ignore();//XXX wird von SFX erledigt
491 }
492
493 case SID_ATTR_SIZE://XXX ???
494 break;
495
496
497 case SID_PRINTPREVIEW:
498 {
499 if ( !pThisFrame->GetFrame().IsInPlace() ) // nicht bei OLE
500 {
501 // print preview is now always in the same frame as the tab view
502 // -> always switch this frame back to normal view
503 // (ScPreviewShell ctor reads view data)
504
505 // #102785#; finish input
506 pScMod->InputEnterHandler();
507
508 pThisFrame->GetDispatcher()->Execute( SID_VIEWSHELL1, SFX_CALLMODE_ASYNCHRON );
509 }
510 // else Fehler (z.B. Ole)
511 }
512 break;
513
514 case SID_DETECTIVE_DEL_ALL:
515 DetectiveDelAll();
516 rReq.Done();
517 break;
518
519 // SID_TABLE_ACTIVATE und SID_MARKAREA werden von Basic aus an der versteckten
520 // View aufgerufen, um auf der sichtbaren View zu markieren/umzuschalten:
521
522 case SID_TABLE_ACTIVATE:
523 DBG_ERROR("old slot SID_TABLE_ACTIVATE");
524 break;
525
526 case SID_REPAINT:
527 PaintGrid();
528 PaintTop();
529 PaintLeft();
530 PaintExtras();
531 rReq.Done();
532 break;
533
534 case FID_NORMALVIEWMODE:
535 case FID_PAGEBREAKMODE:
536 {
537 sal_Bool bWantPageBreak = nSlot == FID_PAGEBREAKMODE;
538
539 // check whether there is an explicit argument, use it
540 const SfxPoolItem* pItem;
541 if ( pReqArgs && pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET )
542 {
543 sal_Bool bItemValue = ((const SfxBoolItem*)pItem)->GetValue();
544 bWantPageBreak = (nSlot == FID_PAGEBREAKMODE) == bItemValue;
545 }
546
547 if( GetViewData()->IsPagebreakMode() != bWantPageBreak )
548 {
549 SetPagebreakMode( bWantPageBreak );
550 UpdatePageBreakData();
551 SetCurSubShell( GetCurObjectSelectionType(), sal_True );
552 PaintGrid();
553 PaintTop();
554 PaintLeft();
555 rBindings.Invalidate( nSlot );
556 rReq.AppendItem( SfxBoolItem( nSlot, sal_True ) );
557 rReq.Done();
558 }
559 }
560 break;
561
562 case FID_FUNCTION_BOX:
563 {
564 sal_uInt16 nChildId = ScFunctionChildWindow::GetChildWindowId();
565 if ( rReq.GetArgs() )
566 pThisFrame->SetChildWindow( nChildId, ((const SfxBoolItem&) (rReq.GetArgs()->Get(FID_FUNCTION_BOX))).GetValue());
567 else
568 {
569 pThisFrame->ToggleChildWindow( nChildId );
570 rReq.AppendItem( SfxBoolItem( FID_FUNCTION_BOX , pThisFrame->HasChildWindow( nChildId ) ) );
571 }
572
573 GetViewFrame()->GetBindings().Invalidate(FID_FUNCTION_BOX);
574 rReq.Done ();
575 }
576 break;
577
578
579 case FID_TOGGLESYNTAX:
580 {
581 sal_Bool bSet = !GetViewData()->IsSyntaxMode();
582 const SfxPoolItem* pItem;
583 if ( pReqArgs && pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET )
584 bSet = ((const SfxBoolItem*)pItem)->GetValue();
585 GetViewData()->SetSyntaxMode( bSet );
586 PaintGrid();
587 rBindings.Invalidate( FID_TOGGLESYNTAX );
588 rReq.AppendItem( SfxBoolItem( nSlot, bSet ) );
589 rReq.Done();
590 }
591 break;
592 case FID_TOGGLEHEADERS:
593 {
594 sal_Bool bSet = !GetViewData()->IsHeaderMode();
595 const SfxPoolItem* pItem;
596 if ( pReqArgs && pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET )
597 bSet = ((const SfxBoolItem*)pItem)->GetValue();
598 GetViewData()->SetHeaderMode( bSet );
599 RepeatResize();
600 rBindings.Invalidate( FID_TOGGLEHEADERS );
601 rReq.AppendItem( SfxBoolItem( nSlot, bSet ) );
602 rReq.Done();
603 }
604 break;
605
606 case FID_TOGGLEFORMULA:
607 {
608 ScViewData* pViewData = GetViewData();
609 const ScViewOptions& rOpts = pViewData->GetOptions();
610 sal_Bool bFormulaMode = !rOpts.GetOption( VOPT_FORMULAS );
611 const SfxPoolItem *pItem;
612 if( pReqArgs && pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET )
613 bFormulaMode = ((const SfxBoolItem *)pItem)->GetValue();
614
615 ScViewOptions rSetOpts = ScViewOptions( rOpts );
616 rSetOpts.SetOption( VOPT_FORMULAS, bFormulaMode );
617 pViewData->SetOptions( rSetOpts );
618
619 pViewData->GetDocShell()->PostPaintGridAll();
620
621 rBindings.Invalidate( FID_TOGGLEFORMULA );
622 rReq.AppendItem( SfxBoolItem( nSlot, bFormulaMode ) );
623 rReq.Done();
624 }
625 break;
626
627 case FID_TOGGLEINPUTLINE:
628 {
629 sal_uInt16 nId = ScInputWindowWrapper::GetChildWindowId();
630 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
631 sal_Bool bSet = ( pWnd == NULL );
632 const SfxPoolItem* pItem;
633 if ( pReqArgs && pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET )
634 bSet = ((const SfxBoolItem*)pItem)->GetValue();
635
636 pThisFrame->SetChildWindow( nId, bSet );
637 rBindings.Invalidate( FID_TOGGLEINPUTLINE );
638 rReq.AppendItem( SfxBoolItem( nSlot, bSet ) );
639 rReq.Done();
640 }
641 break;
642
643 case SID_ATTR_ZOOM: // Statuszeile
644 case FID_SCALE:
645 {
646 sal_Bool bSyncZoom = SC_MOD()->GetAppOptions().GetSynchronizeZoom();
647 SvxZoomType eOldZoomType = GetZoomType();
648 SvxZoomType eNewZoomType = eOldZoomType;
649 const Fraction& rOldY = GetViewData()->GetZoomY(); // Y wird angezeigt
650 sal_uInt16 nOldZoom = (sal_uInt16)(( rOldY.GetNumerator() * 100 )
651 / rOldY.GetDenominator());
652 sal_uInt16 nZoom = nOldZoom;
653 sal_Bool bCancel = sal_False;
654
655 if ( pReqArgs )
656 {
657 const SvxZoomItem& rZoomItem = (const SvxZoomItem&)
658 pReqArgs->Get(SID_ATTR_ZOOM);
659
660 eNewZoomType = rZoomItem.GetType();
661 nZoom = rZoomItem.GetValue();
662 }
663 else
664 {
665 SfxItemSet aSet ( GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM );
666 SvxZoomItem aZoomItem( eOldZoomType, nOldZoom, SID_ATTR_ZOOM );
667 //CHINA001 SvxZoomDialog* pDlg = NULL;
668 AbstractSvxZoomDialog* pDlg = NULL;
669 ScMarkData& rMark = GetViewData()->GetMarkData();
670 sal_uInt16 nBtnFlags = SVX_ZOOM_ENABLE_50
671 | SVX_ZOOM_ENABLE_75
672 | SVX_ZOOM_ENABLE_100
673 | SVX_ZOOM_ENABLE_150
674 | SVX_ZOOM_ENABLE_200
675 | SVX_ZOOM_ENABLE_WHOLEPAGE
676 | SVX_ZOOM_ENABLE_PAGEWIDTH;
677
678 if ( rMark.IsMarked() || rMark.IsMultiMarked() )
679 nBtnFlags = nBtnFlags | SVX_ZOOM_ENABLE_OPTIMAL;
680
681 aZoomItem.SetValueSet( nBtnFlags );
682 aSet.Put( aZoomItem );
683 //CHINA001 pDlg = new SvxZoomDialog( GetDialogParent(), aSet );
684 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
685 if(pFact)
686 {
687 pDlg = pFact->CreateSvxZoomDialog(GetDialogParent(), aSet );
688 DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
689 }
690 pDlg->SetLimits( MINZOOM, MAXZOOM );
691
692 bCancel = ( RET_CANCEL == pDlg->Execute() );
693
694 if ( !bCancel )
695 {
696 const SvxZoomItem& rZoomItem = (const SvxZoomItem&)
697 pDlg->GetOutputItemSet()->
698 Get( SID_ATTR_ZOOM );
699
700 eNewZoomType = rZoomItem.GetType();
701 nZoom = rZoomItem.GetValue();
702 }
703
704 delete pDlg;
705 }
706
707 if ( !bCancel )
708 {
709 if ( eNewZoomType == SVX_ZOOM_PERCENT )
710 {
711 if ( nZoom < MINZOOM ) nZoom = MINZOOM;
712 if ( nZoom > MAXZOOM ) nZoom = MAXZOOM;
713 }
714 else
715 {
716 nZoom = CalcZoom( eNewZoomType, nOldZoom );
717 bCancel = nZoom == 0;
718 }
719
720 switch ( eNewZoomType )
721 {
722 case SVX_ZOOM_WHOLEPAGE:
723 case SVX_ZOOM_PAGEWIDTH:
724 SetZoomType( eNewZoomType, bSyncZoom );
725 break;
726
727 default:
728 SetZoomType( SVX_ZOOM_PERCENT, bSyncZoom );
729 }
730 }
731
732 if ( nZoom != nOldZoom && !bCancel )
733 {
734 if (!GetViewData()->IsPagebreakMode())
735 {
736 ScAppOptions aNewOpt = pScMod->GetAppOptions();
737 aNewOpt.SetZoom( nZoom );
738 aNewOpt.SetZoomType( GetZoomType() );
739 pScMod->SetAppOptions( aNewOpt );
740 }
741 Fraction aFract( nZoom, 100 );
742 SetZoom( aFract, aFract, bSyncZoom );
743 PaintGrid();
744 PaintTop();
745 PaintLeft();
746 rBindings.Invalidate( SID_ATTR_ZOOM );
747 rReq.AppendItem( SvxZoomItem( GetZoomType(), nZoom, nSlot ) );
748 rReq.Done();
749 }
750 }
751 break;
752
753 case SID_ATTR_ZOOMSLIDER:
754 {
755 const SfxPoolItem* pItem = NULL;
756 sal_Bool bSyncZoom = SC_MOD()->GetAppOptions().GetSynchronizeZoom();
757 if ( pReqArgs && pReqArgs->GetItemState(SID_ATTR_ZOOMSLIDER, sal_True, &pItem) == SFX_ITEM_SET )
758 {
759 const sal_uInt16 nCurrentZoom = ((const SvxZoomSliderItem *)pItem)->GetValue();
760 if( nCurrentZoom )
761 {
762 SetZoomType( SVX_ZOOM_PERCENT, bSyncZoom );
763 if (!GetViewData()->IsPagebreakMode())
764 {
765 ScAppOptions aNewOpt = pScMod->GetAppOptions();
766 aNewOpt.SetZoom( nCurrentZoom );
767 aNewOpt.SetZoomType( GetZoomType() );
768 pScMod->SetAppOptions( aNewOpt );
769 }
770 Fraction aFract( nCurrentZoom,100 );
771 SetZoom( aFract, aFract, bSyncZoom );
772 PaintGrid();
773 PaintTop();
774 PaintLeft();
775 rBindings.Invalidate( SID_ATTR_ZOOMSLIDER );
776 rReq.Done();
777 }
778 }
779 }
780 break;
781
782 //----------------------------------------------------------------
783
784 case FID_TAB_SELECTALL:
785 SelectAllTables();
786 rReq.Done();
787 break;
788
789 case FID_TAB_DESELECTALL:
790 DeselectAllTables();
791 rReq.Done();
792 break;
793
794 case SID_SELECT_TABLES:
795 {
796 ScViewData& rViewData = *GetViewData();
797 ScDocument& rDoc = *rViewData.GetDocument();
798 ScMarkData& rMark = rViewData.GetMarkData();
799 SCTAB nTabCount = rDoc.GetTableCount();
800 SCTAB nTab;
801
802 SvULongs aIndexList( 4, 4 );
803 SFX_REQUEST_ARG( rReq, pItem, SfxIntegerListItem, SID_SELECT_TABLES, sal_False );
804 if ( pItem )
805 pItem->GetList( aIndexList );
806 else
807 {
808 //CHINA001 ScShowTabDlg* pDlg = new ScShowTabDlg( GetDialogParent() );
809 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
810 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
811
812 AbstractScShowTabDlg* pDlg = pFact->CreateScShowTabDlg( GetDialogParent(), RID_SCDLG_SHOW_TAB);
813 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
814 pDlg->SetDescription(
815 String( ScResId( STR_DLG_SELECTTABLES_TITLE ) ),
816 String( ScResId( STR_DLG_SELECTTABLES_LBNAME ) ),
817 GetStaticInterface()->GetSlot(SID_SELECT_TABLES)->GetCommand(), HID_SELECTTABLES );
818
819 // fill all table names with selection state
820 String aTabName;
821 for( nTab = 0; nTab < nTabCount; ++nTab )
822 {
823 rDoc.GetName( nTab, aTabName );
824 pDlg->Insert( aTabName, rMark.GetTableSelect( nTab ) );
825 }
826
827 if( pDlg->Execute() == RET_OK )
828 {
829 sal_uInt16 nSelCount = pDlg->GetSelectEntryCount();
830 sal_uInt16 nSelIx;
831 for( nSelIx = 0; nSelIx < nSelCount; ++nSelIx )
832 aIndexList.Insert( pDlg->GetSelectEntryPos( nSelIx ), nSelIx );
833 delete pDlg;
834 rReq.AppendItem( SfxIntegerListItem( SID_SELECT_TABLES, aIndexList ) );
835 }
836 else
837 rReq.Ignore();
838 }
839
840 if ( aIndexList.Count() )
841 {
842 sal_uInt16 nSelCount = aIndexList.Count();
843 sal_uInt16 nSelIx;
844 SCTAB nFirstVisTab = 0;
845
846 // special case: only hidden tables selected -> do nothing
847 sal_Bool bVisSelected = sal_False;
848 for( nSelIx = 0; !bVisSelected && (nSelIx < nSelCount); ++nSelIx )
849 bVisSelected = rDoc.IsVisible( nFirstVisTab = static_cast<SCTAB>(aIndexList[nSelIx]) );
850 if( !bVisSelected )
851 nSelCount = 0;
852
853 // select the tables
854 if( nSelCount )
855 {
856 for( nTab = 0; nTab < nTabCount; ++nTab )
857 rMark.SelectTable( nTab, sal_False );
858
859 for( nSelIx = 0; nSelIx < nSelCount; ++nSelIx )
860 rMark.SelectTable( static_cast<SCTAB>(aIndexList[nSelIx]), sal_True );
861
862 // activate another table, if current is deselected
863 if( !rMark.GetTableSelect( rViewData.GetTabNo() ) )
864 {
865 rMark.SelectTable( nFirstVisTab, sal_True );
866 SetTabNo( nFirstVisTab );
867 }
868
869 rViewData.GetDocShell()->PostPaintExtras();
870 SfxBindings& rBind = rViewData.GetBindings();
871 rBind.Invalidate( FID_FILL_TAB );
872 rBind.Invalidate( FID_TAB_DESELECTALL );
873 }
874
875 rReq.Done();
876 }
877 }
878 break;
879
880
881 case SID_OUTLINE_DELETEALL:
882 RemoveAllOutlines();
883 rReq.Done();
884 break;
885
886 case SID_AUTO_OUTLINE:
887 AutoOutline();
888 rReq.Done();
889 break;
890
891
892 case SID_WINDOW_SPLIT:
893 {
894 ScSplitMode eHSplit = GetViewData()->GetHSplitMode();
895 ScSplitMode eVSplit = GetViewData()->GetVSplitMode();
896 if ( eHSplit == SC_SPLIT_NORMAL || eVSplit == SC_SPLIT_NORMAL ) // aufheben
897 RemoveSplit();
898 else if ( eHSplit == SC_SPLIT_FIX || eVSplit == SC_SPLIT_FIX ) // normal
899 FreezeSplitters( sal_False );
900 else // erzeugen
901 SplitAtCursor();
902 rReq.Done();
903
904 InvalidateSplit();
905 }
906 break;
907
908 case SID_WINDOW_FIX:
909 {
910 ScSplitMode eHSplit = GetViewData()->GetHSplitMode();
911 ScSplitMode eVSplit = GetViewData()->GetVSplitMode();
912 if ( eHSplit == SC_SPLIT_FIX || eVSplit == SC_SPLIT_FIX ) // aufheben
913 RemoveSplit();
914 else
915 FreezeSplitters( sal_True ); // erzeugen oder fixieren
916 rReq.Done();
917
918 InvalidateSplit();
919 }
920 break;
921
922 // ----------------------------------------------------------------
923
924 case FID_CHG_SHOW:
925 {
926 sal_uInt16 nId = ScHighlightChgDlgWrapper::GetChildWindowId();
927 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
928
929 pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True );
930 }
931 break;
932
933 case FID_CHG_ACCEPT:
934 {
935 pThisFrame->ToggleChildWindow(ScAcceptChgDlgWrapper::GetChildWindowId());
936 GetViewFrame()->GetBindings().Invalidate(FID_CHG_ACCEPT);
937 rReq.Done ();
938
939 /*
940 sal_uInt16 nId = ScAcceptChgDlgWrapper::GetChildWindowId();
941 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
942
943 pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True );
944 */
945 }
946 break;
947
948 case FID_CHG_COMMENT:
949 {
950 ScViewData* pData = GetViewData();
951 ScAddress aCursorPos( pData->GetCurX(), pData->GetCurY(), pData->GetTabNo() );
952 ScDocShell* pDocSh = pData->GetDocShell();
953
954 ScChangeAction* pAction = pDocSh->GetChangeAction( aCursorPos );
955 if ( pAction )
956 {
957 const SfxPoolItem* pItem;
958 if ( pReqArgs &&
959 pReqArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET &&
960 pItem->ISA( SfxStringItem ) )
961 {
962 String aComment = ((const SfxStringItem*)pItem)->GetValue();
963 pDocSh->SetChangeComment( pAction, aComment );
964 rReq.Done();
965 }
966 else
967 {
968 pDocSh->ExecuteChangeCommentDialog( pAction, GetDialogParent() );
969 rReq.Done();
970 }
971 }
972 }
973 break;
974
975 case SID_CREATE_SW_DRAWVIEW:
976 // wird von den Forms gerufen, wenn die DrawView mit allem Zubehoer
977 // angelegt werden muss
978 if (!GetScDrawView())
979 {
980 GetViewData()->GetDocShell()->MakeDrawLayer();
981 rBindings.InvalidateAll(sal_False);
982 }
983 break;
984
985 case FID_PROTECT_DOC:
986 {
987 ScDocument* pDoc = GetViewData()->GetDocument();
988 SfxPasswordDialog* pDlg;
989
990 if( pReqArgs )
991 {
992 const SfxPoolItem* pItem;
993 if( IS_AVAILABLE( FID_PROTECT_DOC, &pItem ) &&
994 ((const SfxBoolItem*)pItem)->GetValue() == pDoc->IsDocProtected() )
995 {
996 rReq.Ignore();
997 break;
998 }
999 }
1000
1001 ScDocProtection* pProtect = pDoc->GetDocProtection();
1002 if (pProtect && pProtect->isProtected())
1003 {
1004 sal_Bool bCancel = sal_False;
1005 String aPassword;
1006
1007 if (pProtect->isProtectedWithPass())
1008 {
1009 String aText( ScResId(SCSTR_PASSWORD) );
1010
1011 pDlg = new SfxPasswordDialog( GetDialogParent(), &aText );
1012 pDlg->SetText( ScResId(SCSTR_UNPROTECTDOC) );
1013 pDlg->SetMinLen( 0 );
1014 pDlg->SetHelpId( GetStaticInterface()->GetSlot(FID_PROTECT_DOC)->GetCommand() );
1015 pDlg->SetEditHelpId( HID_PASSWD_DOC );
1016
1017 if (pDlg->Execute() == RET_OK)
1018 aPassword = pDlg->GetPassword();
1019 else
1020 bCancel = sal_True;
1021 delete pDlg;
1022 }
1023 if (!bCancel)
1024 {
1025 Unprotect( TABLEID_DOC, aPassword );
1026 rReq.AppendItem( SfxBoolItem( FID_PROTECT_DOC, sal_False ) );
1027 rReq.Done();
1028 }
1029 }
1030 else
1031 {
1032 String aText( ScResId(SCSTR_PASSWORDOPT) );
1033
1034 pDlg = new SfxPasswordDialog( GetDialogParent(), &aText );
1035 pDlg->SetText( ScResId(SCSTR_PROTECTDOC) );
1036 pDlg->SetMinLen( 0 );
1037 pDlg->SetHelpId( GetStaticInterface()->GetSlot(FID_PROTECT_DOC)->GetCommand() );
1038 pDlg->SetEditHelpId( HID_PASSWD_DOC );
1039 pDlg->ShowExtras( SHOWEXTRAS_CONFIRM );
1040
1041 if (pDlg->Execute() == RET_OK)
1042 {
1043 String aPassword = pDlg->GetPassword();
1044 Protect( TABLEID_DOC, aPassword );
1045 rReq.AppendItem( SfxBoolItem( FID_PROTECT_DOC, sal_True ) );
1046 rReq.Done();
1047 }
1048
1049 delete pDlg;
1050 }
1051 rBindings.Invalidate( FID_PROTECT_DOC );
1052 }
1053 break;
1054
1055
1056 case FID_PROTECT_TABLE:
1057 {
1058 ScDocument* pDoc = GetViewData()->GetDocument();
1059 SCTAB nTab = GetViewData()->GetTabNo();
1060 bool bOldProtection = pDoc->IsTabProtected(nTab);
1061
1062 #if ENABLE_SHEET_PROTECTION
1063
1064 if( pReqArgs )
1065 {
1066 const SfxPoolItem* pItem;
1067 bool bNewProtection = !bOldProtection;
1068 if( IS_AVAILABLE( FID_PROTECT_TABLE, &pItem ) )
1069 bNewProtection = ((const SfxBoolItem*)pItem)->GetValue();
1070 if( bNewProtection == bOldProtection )
1071 {
1072 rReq.Ignore();
1073 break;
1074 }
1075 }
1076
1077 if (bOldProtection)
1078 {
1079 // Unprotect a protected sheet.
1080
1081 ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
1082 if (pProtect && pProtect->isProtectedWithPass())
1083 {
1084 String aText( ScResId(SCSTR_PASSWORDOPT) );
1085 auto_ptr<SfxPasswordDialog> pDlg(new SfxPasswordDialog(GetDialogParent(), &aText));
1086 pDlg->SetText( ScResId(SCSTR_UNPROTECTTAB) );
1087 pDlg->SetMinLen( 0 );
1088 pDlg->SetHelpId( GetStaticInterface()->GetSlot(FID_PROTECT_TABLE)->GetCommand() );
1089 pDlg->SetEditHelpId( HID_PASSWD_TABLE );
1090
1091 if (pDlg->Execute() == RET_OK)
1092 {
1093 String aPassword = pDlg->GetPassword();
1094 Unprotect(nTab, aPassword);
1095 }
1096 }
1097 else
1098 // this sheet is not password-protected.
1099 Unprotect(nTab, String());
1100
1101 if (!pReqArgs)
1102 {
1103 rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, false) );
1104 rReq.Done();
1105 }
1106 }
1107 else
1108 {
1109 // Protect a current sheet.
1110
1111 auto_ptr<ScTableProtectionDlg> pDlg(new ScTableProtectionDlg(GetDialogParent()));
1112
1113 ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
1114 if (pProtect)
1115 pDlg->SetDialogData(*pProtect);
1116
1117 if (pDlg->Execute() == RET_OK)
1118 {
1119 pScMod->InputEnterHandler();
1120
1121 ScTableProtection aNewProtect;
1122 pDlg->WriteData(aNewProtect);
1123 ProtectSheet(nTab, aNewProtect);
1124 if (!pReqArgs)
1125 {
1126 rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, true) );
1127 rReq.Done();
1128 }
1129 }
1130 }
1131 #else
1132 auto_ptr<SfxPasswordDialog> pDlg;
1133 String aPassword;
1134 sal_Bool bCancel = sal_False;
1135 bool bNewProtection = ! bOldProtection;
1136
1137 if( pReqArgs )
1138 {
1139 const SfxPoolItem* pItem;
1140 if( IS_AVAILABLE( FID_PROTECT_TABLE, &pItem ) )
1141 bNewProtection = ((const SfxBoolItem*)pItem)->GetValue();
1142 if( bNewProtection == bOldProtection )
1143 {
1144 rReq.Ignore();
1145 break;
1146 }
1147 }
1148
1149 if ( bOldProtection)
1150 {
1151 // Unprotect a protected sheet.
1152
1153 ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
1154 if (pProtect && pProtect->isProtectedWithPass())
1155 {
1156 String aText( ScResId(SCSTR_PASSWORDOPT) );
1157 pDlg.reset(new SfxPasswordDialog(GetDialogParent(), &aText));
1158 pDlg->SetText( ScResId(SCSTR_UNPROTECTTAB) );
1159 pDlg->SetMinLen( 0 );
1160 pDlg->SetHelpId( GetStaticInterface()->GetSlot(FID_PROTECT_TABLE)->GetCommand() );
1161 pDlg->SetEditHelpId( HID_PASSWD_TABLE );
1162
1163 if (pDlg->Execute() == RET_OK)
1164 aPassword = pDlg->GetPassword();
1165 else
1166 bCancel = sal_True;
1167 }
1168
1169 if (!pReqArgs)
1170 {
1171 rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, false) );
1172 rReq.Done();
1173 }
1174 }
1175 else
1176 {
1177 String aText( ScResId(SCSTR_PASSWORDOPT) );
1178
1179 pDlg.reset(new SfxPasswordDialog(GetDialogParent(), &aText));
1180 pDlg->SetText( ScResId(SCSTR_PROTECTTAB) );
1181 pDlg->SetMinLen( 0 );
1182 pDlg->SetHelpId( GetStaticInterface()->GetSlot(FID_PROTECT_TABLE)->GetCommand() );
1183 pDlg->SetEditHelpId( HID_PASSWD_TABLE );
1184 pDlg->ShowExtras( SHOWEXTRAS_CONFIRM );
1185
1186 if (pDlg->Execute() == RET_OK)
1187 aPassword = pDlg->GetPassword();
1188 else
1189 bCancel = sal_True;
1190 }
1191
1192 if( !bCancel )
1193 {
1194 if ( bOldProtection )
1195 Unprotect( nTab, aPassword );
1196 else
1197 {
1198 pScMod->InputEnterHandler();
1199
1200 Protect( nTab, aPassword );
1201 }
1202
1203 if( !pReqArgs )
1204 {
1205 rReq.AppendItem( SfxBoolItem( FID_PROTECT_TABLE, bNewProtection ) );
1206 rReq.Done();
1207 }
1208 }
1209 #endif
1210 TabChanged();
1211 UpdateInputHandler(true); // damit sofort wieder eingegeben werden kann
1212 SelectionChanged();
1213 }
1214 break;
1215
1216 case SID_OPT_LOCALE_CHANGED :
1217 { // locale changed, SYSTEM number formats changed => repaint cell contents
1218 PaintGrid();
1219 rReq.Done();
1220 }
1221 break;
1222
1223 default:
1224 DBG_ERROR("Unbekannter Slot bei ScTabViewShell::Execute");
1225 break;
1226 }
1227 }
1228
1229
1230
1231