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