update ooo310-m15
[ooovba.git] / sc / source / ui / view / tabvwsh3.cxx
blob224824b8208fd85490d2bccd251d974425beef33
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tabvwsh3.cxx,v $
10 * $Revision: 1.40 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #include "scitems.hxx"
39 #include <svx/eeitem.hxx>
40 #include <svx/svdmark.hxx>
41 #include <svx/svdoole2.hxx>
42 #include <svx/svdview.hxx>
44 #include <sfx2/app.hxx>
45 //CHINA001 #include <svx/zoom.hxx>
46 #include <sfx2/bindings.hxx>
47 #include <sfx2/dispatch.hxx>
48 #include <sfx2/passwd.hxx>
49 #include <sfx2/request.hxx>
50 #include <sfx2/topfrm.hxx>
51 #include <svtools/ptitem.hxx>
52 #include <svtools/stritem.hxx>
53 #include <tools/urlobj.hxx>
55 #include <vcl/msgbox.hxx>
56 #include <vcl/vclenum.hxx>
58 #include <com/sun/star/embed/EmbedVerbs.hpp>
60 #include "globstr.hrc"
61 #include "scmod.hxx"
62 #include "appoptio.hxx"
63 #include "tabvwsh.hxx"
64 #include "document.hxx"
65 #include "sc.hrc"
66 #include "inputwin.hxx"
67 #include "scresid.hxx"
68 #include "printfun.hxx"
69 #include "docsh.hxx"
70 #include "rangelst.hxx"
71 #include "prevwsh.hxx"
72 #include "rangeutl.hxx"
73 #include "reffact.hxx"
74 #include "uiitems.hxx"
75 #include "cell.hxx"
76 #include "inputhdl.hxx"
77 //CHINA001 #include "scendlg.hxx"
78 //CHINA001 #include "mtrindlg.hxx"
79 #include "autoform.hxx"
80 #include "autofmt.hxx"
81 #include "dwfunctr.hxx"
82 #include "shtabdlg.hxx"
83 #include "tabprotection.hxx"
84 #include "protectiondlg.hxx"
86 #include <svtools/ilstitem.hxx>
87 #define _SVSTDARR_ULONGS
88 #include <svtools/svstdarr.hxx>
90 #include <svx/zoomslideritem.hxx>
91 #include <svx/svxdlg.hxx> //CHINA001
92 #include <svx/dialogs.hrc> //CHINA001
93 #include "scabstdlg.hxx" //CHINA001
95 #include <memory>
97 using ::std::auto_ptr;
99 #define IS_EDITMODE() GetViewData()->HasEditView( GetViewData()->GetActivePart() )
100 #define IS_AVAILABLE(WhichId,ppItem) \
101 (pReqArgs->GetItemState((WhichId), TRUE, ppItem ) == SFX_ITEM_SET)
102 #define GET_STRING(nid) ((const SfxStringItem&)pReqArgs->Get(nid)).GetValue()
103 #define GET_UINT16(nid) ((const SfxUInt16Item&)pReqArgs->Get(nid)).GetValue()
104 #define GET_BOOL(nid) ((const SfxBoolItem&)pReqArgs->Get(nid)).GetValue()
105 #define RECALC_PAGE(pDocSh) ScPrintFunc( pDocSh, GetPrinter(), nCurTab ).UpdatePages()
107 using namespace com::sun::star;
109 //------------------------------------------------------------------
111 /** Try to parse the given range using Calc-style syntax first, then
112 Excel-style if that fails. */
113 USHORT lcl_ParseRange(ScRange& rScRange, const String& aAddress, ScDocument* pDoc, USHORT /* nSlot */)
115 USHORT nResult = rScRange.Parse(aAddress, pDoc);
116 if ( (nResult & SCA_VALID) )
117 return nResult;
119 return rScRange.Parse(aAddress, pDoc, ScAddress::Details(formula::FormulaGrammar::CONV_XL_A1, 0, 0));
122 /** Try to parse the given address using Calc-style syntax first, then
123 Excel-style if that fails. */
124 USHORT lcl_ParseAddress(ScAddress& rScAddress, const String& aAddress, ScDocument* pDoc, USHORT /* nSlot */)
126 USHORT nResult = rScAddress.Parse(aAddress, pDoc);
127 if ( (nResult & SCA_VALID) )
128 return nResult;
130 return rScAddress.Parse(aAddress, pDoc, ScAddress::Details(formula::FormulaGrammar::CONV_XL_A1, 0, 0));
133 void ScTabViewShell::Execute( SfxRequest& rReq )
135 SfxViewFrame* pThisFrame = GetViewFrame();
136 SfxBindings& rBindings = pThisFrame->GetBindings();
137 ScModule* pScMod = SC_MOD();
138 const SfxItemSet* pReqArgs = rReq.GetArgs();
139 USHORT nSlot = rReq.GetSlot();
141 if (nSlot != SID_CURRENTCELL) // der kommt beim MouseButtonUp
142 HideListBox(); // Autofilter-DropDown-Listbox
144 switch ( nSlot )
146 case FID_INSERT_FILE:
148 const SfxPoolItem* pItem;
149 if ( pReqArgs &&
150 pReqArgs->GetItemState(FID_INSERT_FILE,TRUE,&pItem) == SFX_ITEM_SET )
152 String aFileName = ((const SfxStringItem*)pItem)->GetValue();
154 // Einfuege-Position
156 Point aInsertPos;
157 if ( pReqArgs->GetItemState(FN_PARAM_1,TRUE,&pItem) == SFX_ITEM_SET )
158 aInsertPos = ((const SfxPointItem*)pItem)->GetValue();
159 else
160 aInsertPos = GetInsertPos();
162 // als Link?
164 BOOL bAsLink = FALSE;
165 if ( pReqArgs->GetItemState(FN_PARAM_2,TRUE,&pItem) == SFX_ITEM_SET )
166 bAsLink = ((const SfxBoolItem*)pItem)->GetValue();
168 // ausfuehren
170 PasteFile( aInsertPos, aFileName, bAsLink );
173 break;
175 case SID_OPENDLG_EDIT_PRINTAREA:
177 USHORT nId = ScPrintAreasDlgWrapper::GetChildWindowId();
178 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
180 pScMod->SetRefDialog( nId, pWnd ? FALSE : TRUE );
182 break;
184 case SID_CHANGE_PRINTAREA:
186 if ( pReqArgs ) // OK aus Dialog
188 String aPrintStr;
189 String aRowStr;
190 String aColStr;
191 BOOL bEntire = FALSE;
192 const SfxPoolItem* pItem;
193 if ( pReqArgs->GetItemState( SID_CHANGE_PRINTAREA, TRUE, &pItem ) == SFX_ITEM_SET )
194 aPrintStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
195 if ( pReqArgs->GetItemState( FN_PARAM_2, TRUE, &pItem ) == SFX_ITEM_SET )
196 aRowStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
197 if ( pReqArgs->GetItemState( FN_PARAM_3, TRUE, &pItem ) == SFX_ITEM_SET )
198 aColStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
199 if ( pReqArgs->GetItemState( FN_PARAM_4, TRUE, &pItem ) == SFX_ITEM_SET )
200 bEntire = static_cast<const SfxBoolItem*>(pItem)->GetValue();
202 SetPrintRanges( bEntire, &aPrintStr, &aColStr, &aRowStr, FALSE );
204 rReq.Done();
207 break;
209 case SID_ADD_PRINTAREA:
210 case SID_DEFINE_PRINTAREA: // Menue oder Basic
212 BOOL bAdd = ( nSlot == SID_ADD_PRINTAREA );
213 if ( pReqArgs )
215 String aPrintStr;
216 const SfxPoolItem* pItem;
217 if ( pReqArgs->GetItemState( SID_DEFINE_PRINTAREA, TRUE, &pItem ) == SFX_ITEM_SET )
218 aPrintStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
219 SetPrintRanges( FALSE, &aPrintStr, NULL, NULL, bAdd );
221 else
223 SetPrintRanges( FALSE, NULL, NULL, NULL, bAdd ); // aus Selektion
224 rReq.Done();
227 break;
229 case SID_DELETE_PRINTAREA:
231 String aEmpty;
232 SetPrintRanges( FALSE, &aEmpty, NULL, NULL, FALSE ); // Druckbereich loeschen
233 rReq.Done();
235 break;
237 case FID_DEL_MANUALBREAKS:
238 RemoveManualBreaks();
239 rReq.Done();
240 break;
242 case FID_ADJUST_PRINTZOOM:
243 AdjustPrintZoom();
244 rReq.Done();
245 break;
247 case FID_RESET_PRINTZOOM:
248 SetPrintZoom( 100, 0 ); // 100%, nicht auf Seiten
249 rReq.Done();
250 break;
252 case SID_FORMATPAGE:
253 case SID_STATUS_PAGESTYLE:
254 case SID_HFEDIT:
255 GetViewData()->GetDocShell()->
256 ExecutePageStyle( *this, rReq, GetViewData()->GetTabNo() );
257 break;
259 case SID_JUMPTOMARK:
260 case SID_CURRENTCELL:
261 if ( pReqArgs )
263 String aAddress;
264 const SfxPoolItem* pItem;
265 if ( pReqArgs->GetItemState( nSlot, TRUE, &pItem ) == SFX_ITEM_SET )
266 aAddress = ((const SfxStringItem*)pItem)->GetValue();
267 else if ( nSlot == SID_JUMPTOMARK && pReqArgs->GetItemState(
268 SID_JUMPTOMARK, TRUE, &pItem ) == SFX_ITEM_SET )
269 aAddress = ((const SfxStringItem*)pItem)->GetValue();
271 // #i14927# SID_CURRENTCELL with a single cell must unmark if FN_PARAM_1
272 // isn't set (for recorded macros, because IsAPI is no longer available).
273 // ScGridWindow::MouseButtonUp no longer executes the slot for a single
274 // cell if there is a multi selection.
275 BOOL bUnmark = ( nSlot == SID_CURRENTCELL );
276 if ( pReqArgs->GetItemState( FN_PARAM_1, TRUE, &pItem ) == SFX_ITEM_SET )
277 bUnmark = ((const SfxBoolItem*)pItem)->GetValue();
279 bool bAlignToCursor = true;
280 if (pReqArgs->GetItemState(FN_PARAM_2, true, &pItem) == SFX_ITEM_SET)
281 bAlignToCursor = static_cast<const SfxBoolItem*>(pItem)->GetValue();
283 if ( nSlot == SID_JUMPTOMARK )
285 // #106586# URL has to be decoded for escaped characters (%20)
286 aAddress = INetURLObject::decode( aAddress, INET_HEX_ESCAPE,
287 INetURLObject::DECODE_WITH_CHARSET,
288 RTL_TEXTENCODING_UTF8 );
291 BOOL bFound = FALSE;
292 ScViewData* pViewData = GetViewData();
293 ScDocument* pDoc = pViewData->GetDocument();
294 ScMarkData& rMark = pViewData->GetMarkData();
295 ScRange aScRange;
296 ScAddress aScAddress;
297 USHORT nResult = lcl_ParseRange(aScRange, aAddress, pDoc, nSlot);
298 SCTAB nTab = pViewData->GetTabNo();
299 BOOL bMark = TRUE;
301 // Is this a range ?
302 if( nResult & SCA_VALID )
304 if ( nResult & SCA_TAB_3D )
306 if( aScRange.aStart.Tab() != nTab )
307 SetTabNo( nTab = aScRange.aStart.Tab() );
309 else
311 aScRange.aStart.SetTab( nTab );
312 aScRange.aEnd.SetTab( nTab );
315 // Is this a cell ?
316 else if ( (nResult = lcl_ParseAddress(aScAddress, aAddress, pDoc, nSlot)) & SCA_VALID )
318 if ( nResult & SCA_TAB_3D )
320 if( aScAddress.Tab() != nTab )
321 SetTabNo( nTab = aScAddress.Tab() );
323 else
324 aScAddress.SetTab( nTab );
326 aScRange = ScRange( aScAddress, aScAddress );
327 // Zellen sollen nicht markiert werden
328 bMark = FALSE;
330 // Ist es benahmster Bereich (erst Namen dann DBBereiche) ?
331 else
333 ScRangeUtil aRangeUtil;
334 formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
335 if( aRangeUtil.MakeRangeFromName( aAddress, pDoc, nTab, aScRange, RUTL_NAMES, eConv ) ||
336 aRangeUtil.MakeRangeFromName( aAddress, pDoc, nTab, aScRange, RUTL_DBASE, eConv ) )
338 nResult |= SCA_VALID;
339 if( aScRange.aStart.Tab() != nTab )
340 SetTabNo( nTab = aScRange.aStart.Tab() );
344 if ( !(nResult & SCA_VALID) &&
345 ByteString(aAddress, RTL_TEXTENCODING_ASCII_US).IsNumericAscii() )
347 sal_Int32 nNumeric = aAddress.ToInt32();
348 if ( nNumeric > 0 && nNumeric <= MAXROW+1 )
350 // 1-basierte Zeilennummer
352 aScAddress.SetRow( (SCROW)(nNumeric - 1) );
353 aScAddress.SetCol( pViewData->GetCurX() );
354 aScAddress.SetTab( nTab );
355 aScRange = ScRange( aScAddress, aScAddress );
356 bMark = FALSE;
357 nResult = SCA_VALID;
361 if ( !ValidRow(aScRange.aStart.Row()) || !ValidRow(aScRange.aEnd.Row()) )
362 nResult = 0;
364 // wir haben was gefunden
365 if( nResult & SCA_VALID )
367 bFound = TRUE;
368 SCCOL nCol = aScRange.aStart.Col();
369 SCROW nRow = aScRange.aStart.Row();
370 BOOL bNothing = ( pViewData->GetCurX()==nCol && pViewData->GetCurY()==nRow );
372 // markieren
373 if( bMark )
375 if (rMark.IsMarked()) // ist derselbe Bereich schon markiert?
377 ScRange aOldMark;
378 rMark.GetMarkArea( aOldMark );
379 aOldMark.Justify();
380 ScRange aCurrent = aScRange;
381 aCurrent.Justify();
382 bNothing = ( aCurrent == aOldMark );
384 else
385 bNothing = FALSE;
387 if (!bNothing)
388 MarkRange( aScRange, FALSE ); // Cursor kommt hinterher...
390 else
392 // remove old selection, unless bUnmark argument is FALSE (from navigator)
393 if( bUnmark )
395 MoveCursorAbs( nCol, nRow,
396 SC_FOLLOW_NONE, FALSE, FALSE );
400 // und Cursor setzen
402 // zusammengefasste Zellen beruecksichtigen:
403 pDoc->SkipOverlapped(nCol, nRow, nTab);
405 // Navigator-Aufrufe sind nicht API!!!
407 if( bNothing )
409 if (rReq.IsAPI())
410 rReq.Ignore(); // wenn Makro, dann gar nix
411 else
412 rReq.Done(); // sonst wenigstens aufzeichnen
414 else
416 pViewData->ResetOldCursor();
417 SetCursor( nCol, nRow );
418 rBindings.Invalidate( SID_CURRENTCELL );
419 rBindings.Update( nSlot );
421 if (!rReq.IsAPI())
422 rReq.Done();
425 if (bAlignToCursor)
427 // align to cursor even if the cursor position hasn't changed,
428 // because the cursor may be set outside the visible area.
429 AlignToCursor( nCol, nRow, SC_FOLLOW_JUMP );
432 rReq.SetReturnValue( SfxStringItem( SID_CURRENTCELL, aAddress ) );
435 if (!bFound) // kein gueltiger Bereich
437 // wenn es ein Tabellenname ist, umschalten (fuer Navigator/URL's)
439 SCTAB nNameTab;
440 if ( pDoc->GetTable( aAddress, nNameTab ) )
442 bFound = TRUE;
443 if ( nNameTab != nTab )
444 SetTabNo( nNameTab );
448 if ( !bFound && nSlot == SID_JUMPTOMARK )
450 // Grafik-Objekte probieren (nur bei URL's)
452 bFound = SelectObject( aAddress );
455 if (!bFound && !rReq.IsAPI())
456 ErrorMessage( STR_ERR_INVALID_AREA );
458 break;
460 case SID_CURRENTOBJECT:
461 if ( pReqArgs )
463 String aName = ((const SfxStringItem&)pReqArgs->Get(nSlot)).GetValue();
464 SelectObject( aName );
466 break;
468 case SID_CURRENTTAB:
469 if ( pReqArgs )
471 // Tabelle fuer Basic ist 1-basiert
472 SCTAB nTab = ((const SfxUInt16Item&)pReqArgs->Get(nSlot)).GetValue() - 1;
473 ScDocument* pDoc = GetViewData()->GetDocument();
474 if ( nTab < pDoc->GetTableCount() )
476 SetTabNo( nTab );
477 rBindings.Update( nSlot );
479 if( ! rReq.IsAPI() )
480 rReq.Done();
482 //! sonst Fehler ?
484 break;
486 case SID_CURRENTDOC:
487 if ( pReqArgs )
489 String aStrDocName( ((const SfxStringItem&)pReqArgs->
490 Get(nSlot)).GetValue() );
492 SfxViewFrame* pViewFrame = NULL;
493 ScDocShell* pDocSh = (ScDocShell*)SfxObjectShell::GetFirst();
494 BOOL bFound = FALSE;
496 // zu aktivierenden ViewFrame suchen
498 while ( pDocSh && !bFound )
500 if ( pDocSh->GetTitle() == aStrDocName )
502 pViewFrame = SfxViewFrame::GetFirst( pDocSh, TYPE(SfxTopViewFrame) );
503 bFound = ( NULL != pViewFrame );
506 pDocSh = (ScDocShell*)SfxObjectShell::GetNext( *pDocSh );
509 if ( bFound )
510 if ( pViewFrame->ISA(SfxTopViewFrame) )
511 pViewFrame->GetFrame()->Appear();
513 rReq.Ignore();//XXX wird von SFX erledigt
516 case SID_ATTR_SIZE://XXX ???
517 break;
520 case SID_PRINTPREVIEW:
522 if ( !pThisFrame->GetFrame()->IsInPlace() ) // nicht bei OLE
524 // print preview is now always in the same frame as the tab view
525 // -> always switch this frame back to normal view
526 // (ScPreviewShell ctor reads view data)
528 // #102785#; finish input
529 pScMod->InputEnterHandler();
531 pThisFrame->GetDispatcher()->Execute( SID_VIEWSHELL1, SFX_CALLMODE_ASYNCHRON );
533 // else Fehler (z.B. Ole)
535 break;
537 case SID_DETECTIVE_DEL_ALL:
538 DetectiveDelAll();
539 rReq.Done();
540 break;
542 // SID_TABLE_ACTIVATE und SID_MARKAREA werden von Basic aus an der versteckten
543 // View aufgerufen, um auf der sichtbaren View zu markieren/umzuschalten:
545 case SID_TABLE_ACTIVATE:
546 DBG_ERROR("old slot SID_TABLE_ACTIVATE");
547 break;
549 case SID_REPAINT:
550 PaintGrid();
551 PaintTop();
552 PaintLeft();
553 PaintExtras();
554 rReq.Done();
555 break;
557 case FID_NORMALVIEWMODE:
558 case FID_PAGEBREAKMODE:
560 BOOL bWantPageBreak = nSlot == FID_PAGEBREAKMODE;
562 // check whether there is an explicit argument, use it
563 const SfxPoolItem* pItem;
564 if ( pReqArgs && pReqArgs->GetItemState(nSlot, TRUE, &pItem) == SFX_ITEM_SET )
566 BOOL bItemValue = ((const SfxBoolItem*)pItem)->GetValue();
567 bWantPageBreak = (nSlot == FID_PAGEBREAKMODE) == bItemValue;
570 if( GetViewData()->IsPagebreakMode() != bWantPageBreak )
572 SetPagebreakMode( bWantPageBreak );
573 UpdatePageBreakData();
574 SetCurSubShell( GetCurObjectSelectionType(), TRUE );
575 PaintGrid();
576 PaintTop();
577 PaintLeft();
578 rBindings.Invalidate( nSlot );
579 rReq.AppendItem( SfxBoolItem( nSlot, TRUE ) );
580 rReq.Done();
583 break;
585 case FID_FUNCTION_BOX:
587 USHORT nChildId = ScFunctionChildWindow::GetChildWindowId();
588 if ( rReq.GetArgs() )
589 pThisFrame->SetChildWindow( nChildId, ((const SfxBoolItem&) (rReq.GetArgs()->Get(FID_FUNCTION_BOX))).GetValue());
590 else
592 pThisFrame->ToggleChildWindow( nChildId );
593 rReq.AppendItem( SfxBoolItem( FID_FUNCTION_BOX , pThisFrame->HasChildWindow( nChildId ) ) );
596 GetViewFrame()->GetBindings().Invalidate(FID_FUNCTION_BOX);
597 rReq.Done ();
599 break;
602 case FID_TOGGLESYNTAX:
604 BOOL bSet = !GetViewData()->IsSyntaxMode();
605 const SfxPoolItem* pItem;
606 if ( pReqArgs && pReqArgs->GetItemState(nSlot, TRUE, &pItem) == SFX_ITEM_SET )
607 bSet = ((const SfxBoolItem*)pItem)->GetValue();
608 GetViewData()->SetSyntaxMode( bSet );
609 PaintGrid();
610 rBindings.Invalidate( FID_TOGGLESYNTAX );
611 rReq.AppendItem( SfxBoolItem( nSlot, bSet ) );
612 rReq.Done();
614 break;
615 case FID_TOGGLEHEADERS:
617 BOOL bSet = !GetViewData()->IsHeaderMode();
618 const SfxPoolItem* pItem;
619 if ( pReqArgs && pReqArgs->GetItemState(nSlot, TRUE, &pItem) == SFX_ITEM_SET )
620 bSet = ((const SfxBoolItem*)pItem)->GetValue();
621 GetViewData()->SetHeaderMode( bSet );
622 RepeatResize();
623 rBindings.Invalidate( FID_TOGGLEHEADERS );
624 rReq.AppendItem( SfxBoolItem( nSlot, bSet ) );
625 rReq.Done();
627 break;
629 case FID_TOGGLEFORMULA:
631 ScViewData* pViewData = GetViewData();
632 const ScViewOptions& rOpts = pViewData->GetOptions();
633 BOOL bFormulaMode = !rOpts.GetOption( VOPT_FORMULAS );
634 const SfxPoolItem *pItem;
635 if( pReqArgs && pReqArgs->GetItemState(nSlot, TRUE, &pItem) == SFX_ITEM_SET )
636 bFormulaMode = ((const SfxBoolItem *)pItem)->GetValue();
638 ScViewOptions rSetOpts = ScViewOptions( rOpts );
639 rSetOpts.SetOption( VOPT_FORMULAS, bFormulaMode );
640 pViewData->SetOptions( rSetOpts );
642 pViewData->GetDocShell()->PostPaintGridAll();
644 rBindings.Invalidate( FID_TOGGLEFORMULA );
645 rReq.AppendItem( SfxBoolItem( nSlot, bFormulaMode ) );
646 rReq.Done();
648 break;
650 case FID_TOGGLEINPUTLINE:
652 USHORT nId = ScInputWindowWrapper::GetChildWindowId();
653 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
654 BOOL bSet = ( pWnd == NULL );
655 const SfxPoolItem* pItem;
656 if ( pReqArgs && pReqArgs->GetItemState(nSlot, TRUE, &pItem) == SFX_ITEM_SET )
657 bSet = ((const SfxBoolItem*)pItem)->GetValue();
659 pThisFrame->SetChildWindow( nId, bSet );
660 rBindings.Invalidate( FID_TOGGLEINPUTLINE );
661 rReq.AppendItem( SfxBoolItem( nSlot, bSet ) );
662 rReq.Done();
664 break;
666 case SID_ATTR_ZOOM: // Statuszeile
667 case FID_SCALE:
669 BOOL bSyncZoom = SC_MOD()->GetAppOptions().GetSynchronizeZoom();
670 SvxZoomType eOldZoomType = GetZoomType();
671 SvxZoomType eNewZoomType = eOldZoomType;
672 const Fraction& rOldY = GetViewData()->GetZoomY(); // Y wird angezeigt
673 USHORT nOldZoom = (USHORT)(( rOldY.GetNumerator() * 100 )
674 / rOldY.GetDenominator());
675 USHORT nZoom = nOldZoom;
676 BOOL bCancel = FALSE;
678 if ( pReqArgs )
680 const SvxZoomItem& rZoomItem = (const SvxZoomItem&)
681 pReqArgs->Get(SID_ATTR_ZOOM);
683 eNewZoomType = rZoomItem.GetType();
684 nZoom = rZoomItem.GetValue();
686 else
688 SfxItemSet aSet ( GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM );
689 SvxZoomItem aZoomItem( eOldZoomType, nOldZoom, SID_ATTR_ZOOM );
690 //CHINA001 SvxZoomDialog* pDlg = NULL;
691 AbstractSvxZoomDialog* pDlg = NULL;
692 ScMarkData& rMark = GetViewData()->GetMarkData();
693 USHORT nBtnFlags = SVX_ZOOM_ENABLE_50
694 | SVX_ZOOM_ENABLE_75
695 | SVX_ZOOM_ENABLE_100
696 | SVX_ZOOM_ENABLE_150
697 | SVX_ZOOM_ENABLE_200
698 | SVX_ZOOM_ENABLE_WHOLEPAGE
699 | SVX_ZOOM_ENABLE_PAGEWIDTH;
701 if ( rMark.IsMarked() || rMark.IsMultiMarked() )
702 nBtnFlags = nBtnFlags | SVX_ZOOM_ENABLE_OPTIMAL;
704 aZoomItem.SetValueSet( nBtnFlags );
705 aSet.Put( aZoomItem );
706 //CHINA001 pDlg = new SvxZoomDialog( GetDialogParent(), aSet );
707 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
708 if(pFact)
710 pDlg = pFact->CreateSvxZoomDialog(GetDialogParent(), aSet, RID_SVXDLG_ZOOM);
711 DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
713 pDlg->SetLimits( MINZOOM, MAXZOOM );
715 bCancel = ( RET_CANCEL == pDlg->Execute() );
717 if ( !bCancel )
719 const SvxZoomItem& rZoomItem = (const SvxZoomItem&)
720 pDlg->GetOutputItemSet()->
721 Get( SID_ATTR_ZOOM );
723 eNewZoomType = rZoomItem.GetType();
724 nZoom = rZoomItem.GetValue();
727 delete pDlg;
730 if ( !bCancel )
732 if ( eNewZoomType == SVX_ZOOM_PERCENT )
734 if ( nZoom < MINZOOM ) nZoom = MINZOOM;
735 if ( nZoom > MAXZOOM ) nZoom = MAXZOOM;
737 else
739 nZoom = CalcZoom( eNewZoomType, nOldZoom );
740 bCancel = nZoom == 0;
743 switch ( eNewZoomType )
745 case SVX_ZOOM_WHOLEPAGE:
746 case SVX_ZOOM_PAGEWIDTH:
747 SetZoomType( eNewZoomType, bSyncZoom );
748 break;
750 default:
751 SetZoomType( SVX_ZOOM_PERCENT, bSyncZoom );
755 if ( nZoom != nOldZoom && !bCancel )
757 if (!GetViewData()->IsPagebreakMode())
759 ScAppOptions aNewOpt = pScMod->GetAppOptions();
760 aNewOpt.SetZoom( nZoom );
761 aNewOpt.SetZoomType( GetZoomType() );
762 pScMod->SetAppOptions( aNewOpt );
764 Fraction aFract( nZoom, 100 );
765 SetZoom( aFract, aFract, bSyncZoom );
766 PaintGrid();
767 PaintTop();
768 PaintLeft();
769 rBindings.Invalidate( SID_ATTR_ZOOM );
770 rReq.AppendItem( SvxZoomItem( GetZoomType(), nZoom, nSlot ) );
771 rReq.Done();
774 break;
776 case SID_ATTR_ZOOMSLIDER:
778 const SfxPoolItem* pItem = NULL;
779 BOOL bSyncZoom = SC_MOD()->GetAppOptions().GetSynchronizeZoom();
780 if ( pReqArgs && pReqArgs->GetItemState(SID_ATTR_ZOOMSLIDER, TRUE, &pItem) == SFX_ITEM_SET )
782 const USHORT nCurrentZoom = ((const SvxZoomSliderItem *)pItem)->GetValue();
783 if( nCurrentZoom )
785 SetZoomType( SVX_ZOOM_PERCENT, bSyncZoom );
786 if (!GetViewData()->IsPagebreakMode())
788 ScAppOptions aNewOpt = pScMod->GetAppOptions();
789 aNewOpt.SetZoom( nCurrentZoom );
790 aNewOpt.SetZoomType( GetZoomType() );
791 pScMod->SetAppOptions( aNewOpt );
793 Fraction aFract( nCurrentZoom,100 );
794 SetZoom( aFract, aFract, bSyncZoom );
795 PaintGrid();
796 PaintTop();
797 PaintLeft();
798 rBindings.Invalidate( SID_ATTR_ZOOMSLIDER );
799 rReq.Done();
803 break;
805 //----------------------------------------------------------------
807 case FID_TAB_SELECTALL:
808 SelectAllTables();
809 rReq.Done();
810 break;
812 case SID_SELECT_TABLES:
814 ScViewData& rViewData = *GetViewData();
815 ScDocument& rDoc = *rViewData.GetDocument();
816 ScMarkData& rMark = rViewData.GetMarkData();
817 SCTAB nTabCount = rDoc.GetTableCount();
818 SCTAB nTab;
820 SvULongs aIndexList( 4, 4 );
821 SFX_REQUEST_ARG( rReq, pItem, SfxIntegerListItem, SID_SELECT_TABLES, sal_False );
822 if ( pItem )
823 pItem->GetList( aIndexList );
824 else
826 //CHINA001 ScShowTabDlg* pDlg = new ScShowTabDlg( GetDialogParent() );
827 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
828 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
830 AbstractScShowTabDlg* pDlg = pFact->CreateScShowTabDlg( GetDialogParent(), RID_SCDLG_SHOW_TAB);
831 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
832 pDlg->SetDescription(
833 String( ScResId( STR_DLG_SELECTTABLES_TITLE ) ),
834 String( ScResId( STR_DLG_SELECTTABLES_LBNAME ) ),
835 SID_SELECT_TABLES, HID_SELECTTABLES );
837 // fill all table names with selection state
838 String aTabName;
839 for( nTab = 0; nTab < nTabCount; ++nTab )
841 rDoc.GetName( nTab, aTabName );
842 pDlg->Insert( aTabName, rMark.GetTableSelect( nTab ) );
845 if( pDlg->Execute() == RET_OK )
847 sal_uInt16 nSelCount = pDlg->GetSelectEntryCount();
848 sal_uInt16 nSelIx;
849 for( nSelIx = 0; nSelIx < nSelCount; ++nSelIx )
850 aIndexList.Insert( pDlg->GetSelectEntryPos( nSelIx ), nSelIx );
851 delete pDlg;
852 rReq.AppendItem( SfxIntegerListItem( SID_SELECT_TABLES, aIndexList ) );
854 else
855 rReq.Ignore();
858 if ( aIndexList.Count() )
860 sal_uInt16 nSelCount = aIndexList.Count();
861 sal_uInt16 nSelIx;
862 SCTAB nFirstVisTab = 0;
864 // special case: only hidden tables selected -> do nothing
865 sal_Bool bVisSelected = sal_False;
866 for( nSelIx = 0; !bVisSelected && (nSelIx < nSelCount); ++nSelIx )
867 bVisSelected = rDoc.IsVisible( nFirstVisTab = static_cast<SCTAB>(aIndexList[nSelIx]) );
868 if( !bVisSelected )
869 nSelCount = 0;
871 // select the tables
872 if( nSelCount )
874 for( nTab = 0; nTab < nTabCount; ++nTab )
875 rMark.SelectTable( nTab, sal_False );
877 for( nSelIx = 0; nSelIx < nSelCount; ++nSelIx )
878 rMark.SelectTable( static_cast<SCTAB>(aIndexList[nSelIx]), sal_True );
880 // activate another table, if current is deselected
881 if( !rMark.GetTableSelect( rViewData.GetTabNo() ) )
883 rMark.SelectTable( nFirstVisTab, sal_True );
884 SetTabNo( nFirstVisTab );
887 rViewData.GetDocShell()->PostPaintExtras();
888 rViewData.GetBindings().Invalidate( FID_FILL_TAB );
891 rReq.Done();
894 break;
897 case SID_OUTLINE_DELETEALL:
898 RemoveAllOutlines();
899 rReq.Done();
900 break;
902 case SID_AUTO_OUTLINE:
903 AutoOutline();
904 rReq.Done();
905 break;
908 case SID_WINDOW_SPLIT:
910 ScSplitMode eHSplit = GetViewData()->GetHSplitMode();
911 ScSplitMode eVSplit = GetViewData()->GetVSplitMode();
912 if ( eHSplit == SC_SPLIT_NORMAL || eVSplit == SC_SPLIT_NORMAL ) // aufheben
913 RemoveSplit();
914 else if ( eHSplit == SC_SPLIT_FIX || eVSplit == SC_SPLIT_FIX ) // normal
915 FreezeSplitters( FALSE );
916 else // erzeugen
917 SplitAtCursor();
918 rReq.Done();
920 InvalidateSplit();
922 break;
924 case SID_WINDOW_FIX:
926 ScSplitMode eHSplit = GetViewData()->GetHSplitMode();
927 ScSplitMode eVSplit = GetViewData()->GetVSplitMode();
928 if ( eHSplit == SC_SPLIT_FIX || eVSplit == SC_SPLIT_FIX ) // aufheben
929 RemoveSplit();
930 else
931 FreezeSplitters( TRUE ); // erzeugen oder fixieren
932 rReq.Done();
934 InvalidateSplit();
936 break;
938 // ----------------------------------------------------------------
940 case FID_CHG_SHOW:
942 USHORT nId = ScHighlightChgDlgWrapper::GetChildWindowId();
943 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
945 pScMod->SetRefDialog( nId, pWnd ? FALSE : TRUE );
947 break;
949 case FID_CHG_ACCEPT:
951 pThisFrame->ToggleChildWindow(ScAcceptChgDlgWrapper::GetChildWindowId());
952 GetViewFrame()->GetBindings().Invalidate(FID_CHG_ACCEPT);
953 rReq.Done ();
956 USHORT nId = ScAcceptChgDlgWrapper::GetChildWindowId();
957 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
959 pScMod->SetRefDialog( nId, pWnd ? FALSE : TRUE );
962 break;
964 case FID_CHG_COMMENT:
966 ScViewData* pData = GetViewData();
967 ScAddress aCursorPos( pData->GetCurX(), pData->GetCurY(), pData->GetTabNo() );
968 ScDocShell* pDocSh = pData->GetDocShell();
970 ScChangeAction* pAction = pDocSh->GetChangeAction( aCursorPos );
971 if ( pAction )
973 const SfxPoolItem* pItem;
974 if ( pReqArgs &&
975 pReqArgs->GetItemState( nSlot, TRUE, &pItem ) == SFX_ITEM_SET &&
976 pItem->ISA( SfxStringItem ) )
978 String aComment = ((const SfxStringItem*)pItem)->GetValue();
979 pDocSh->SetChangeComment( pAction, aComment );
980 rReq.Done();
982 else
984 pDocSh->ExecuteChangeCommentDialog( pAction, GetDialogParent() );
985 rReq.Done();
989 break;
991 case SID_CREATE_SW_DRAWVIEW:
992 // wird von den Forms gerufen, wenn die DrawView mit allem Zubehoer
993 // angelegt werden muss
994 if (!GetScDrawView())
996 GetViewData()->GetDocShell()->MakeDrawLayer();
997 rBindings.InvalidateAll(FALSE);
999 break;
1001 case FID_PROTECT_DOC:
1003 ScDocument* pDoc = GetViewData()->GetDocument();
1004 SfxPasswordDialog* pDlg;
1006 if( pReqArgs )
1008 const SfxPoolItem* pItem;
1009 if( IS_AVAILABLE( FID_PROTECT_DOC, &pItem ) &&
1010 ((const SfxBoolItem*)pItem)->GetValue() == pDoc->IsDocProtected() )
1012 rReq.Ignore();
1013 break;
1017 ScDocProtection* pProtect = pDoc->GetDocProtection();
1018 if (pProtect && pProtect->isProtected())
1020 BOOL bCancel = FALSE;
1021 String aPassword;
1023 if (pProtect->isProtectedWithPass())
1025 String aText( ScResId(SCSTR_PASSWORD) );
1027 pDlg = new SfxPasswordDialog( GetDialogParent(), &aText );
1028 pDlg->SetText( ScResId(SCSTR_UNPROTECTDOC) );
1029 pDlg->SetMinLen( 0 );
1030 pDlg->SetHelpId( FID_PROTECT_DOC );
1031 pDlg->SetEditHelpId( HID_PASSWD_DOC );
1033 if (pDlg->Execute() == RET_OK)
1034 aPassword = pDlg->GetPassword();
1035 else
1036 bCancel = TRUE;
1037 delete pDlg;
1039 if (!bCancel)
1041 Unprotect( TABLEID_DOC, aPassword );
1042 rReq.AppendItem( SfxBoolItem( FID_PROTECT_DOC, FALSE ) );
1043 rReq.Done();
1046 else
1048 String aText( ScResId(SCSTR_PASSWORDOPT) );
1050 pDlg = new SfxPasswordDialog( GetDialogParent(), &aText );
1051 pDlg->SetText( ScResId(SCSTR_PROTECTDOC) );
1052 pDlg->SetMinLen( 0 );
1053 pDlg->SetHelpId( FID_PROTECT_DOC );
1054 pDlg->SetEditHelpId( HID_PASSWD_DOC );
1055 pDlg->ShowExtras( SHOWEXTRAS_CONFIRM );
1057 if (pDlg->Execute() == RET_OK)
1059 String aPassword = pDlg->GetPassword();
1060 Protect( TABLEID_DOC, aPassword );
1061 rReq.AppendItem( SfxBoolItem( FID_PROTECT_DOC, TRUE ) );
1062 rReq.Done();
1065 delete pDlg;
1067 rBindings.Invalidate( FID_PROTECT_DOC );
1069 break;
1072 case FID_PROTECT_TABLE:
1074 ScDocument* pDoc = GetViewData()->GetDocument();
1075 SCTAB nTab = GetViewData()->GetTabNo();
1076 bool bOldProtection = pDoc->IsTabProtected(nTab);
1078 #if ENABLE_SHEET_PROTECTION
1080 if( pReqArgs )
1082 const SfxPoolItem* pItem;
1083 bool bNewProtection = !bOldProtection;
1084 if( IS_AVAILABLE( FID_PROTECT_TABLE, &pItem ) )
1085 bNewProtection = ((const SfxBoolItem*)pItem)->GetValue();
1086 if( bNewProtection == bOldProtection )
1088 rReq.Ignore();
1089 break;
1093 if (bOldProtection)
1095 // Unprotect a protected sheet.
1097 ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
1098 if (pProtect && pProtect->isProtectedWithPass())
1100 String aText( ScResId(SCSTR_PASSWORDOPT) );
1101 auto_ptr<SfxPasswordDialog> pDlg(new SfxPasswordDialog(GetDialogParent(), &aText));
1102 pDlg->SetText( ScResId(SCSTR_UNPROTECTTAB) );
1103 pDlg->SetMinLen( 0 );
1104 pDlg->SetHelpId( FID_PROTECT_TABLE );
1105 pDlg->SetEditHelpId( HID_PASSWD_TABLE );
1107 if (pDlg->Execute() == RET_OK)
1109 String aPassword = pDlg->GetPassword();
1110 Unprotect(nTab, aPassword);
1113 else
1114 // this sheet is not password-protected.
1115 Unprotect(nTab, String());
1117 if (!pReqArgs)
1119 rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, false) );
1120 rReq.Done();
1123 else
1125 // Protect a current sheet.
1127 auto_ptr<ScTableProtectionDlg> pDlg(new ScTableProtectionDlg(GetDialogParent()));
1129 ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
1130 if (pProtect)
1131 pDlg->SetDialogData(*pProtect);
1133 if (pDlg->Execute() == RET_OK)
1135 pScMod->InputEnterHandler();
1137 ScTableProtection aNewProtect;
1138 pDlg->WriteData(aNewProtect);
1139 ProtectSheet(nTab, aNewProtect);
1140 if (!pReqArgs)
1142 rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, true) );
1143 rReq.Done();
1147 #else
1148 auto_ptr<SfxPasswordDialog> pDlg;
1149 String aPassword;
1150 BOOL bCancel = FALSE;
1151 BOOL bNewProtection = ! bOldProtection;
1153 if( pReqArgs )
1155 const SfxPoolItem* pItem;
1156 if( IS_AVAILABLE( FID_PROTECT_TABLE, &pItem ) )
1157 bNewProtection = ((const SfxBoolItem*)pItem)->GetValue();
1158 if( bNewProtection == bOldProtection )
1160 rReq.Ignore();
1161 break;
1165 if ( bOldProtection)
1167 // Unprotect a protected sheet.
1169 ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
1170 if (pProtect && pProtect->isProtectedWithPass())
1172 String aText( ScResId(SCSTR_PASSWORDOPT) );
1173 pDlg.reset(new SfxPasswordDialog(GetDialogParent(), &aText));
1174 pDlg->SetText( ScResId(SCSTR_UNPROTECTTAB) );
1175 pDlg->SetMinLen( 0 );
1176 pDlg->SetHelpId( FID_PROTECT_TABLE );
1177 pDlg->SetEditHelpId( HID_PASSWD_TABLE );
1179 if (pDlg->Execute() == RET_OK)
1180 aPassword = pDlg->GetPassword();
1181 else
1182 bCancel = TRUE;
1185 if (!pReqArgs)
1187 rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, false) );
1188 rReq.Done();
1191 else
1193 String aText( ScResId(SCSTR_PASSWORDOPT) );
1195 pDlg.reset(new SfxPasswordDialog(GetDialogParent(), &aText));
1196 pDlg->SetText( ScResId(SCSTR_PROTECTTAB) );
1197 pDlg->SetMinLen( 0 );
1198 pDlg->SetHelpId( FID_PROTECT_TABLE );
1199 pDlg->SetEditHelpId( HID_PASSWD_TABLE );
1200 pDlg->ShowExtras( SHOWEXTRAS_CONFIRM );
1202 if (pDlg->Execute() == RET_OK)
1203 aPassword = pDlg->GetPassword();
1204 else
1205 bCancel = TRUE;
1208 if( !bCancel )
1210 if ( bOldProtection )
1211 Unprotect( nTab, aPassword );
1212 else
1214 pScMod->InputEnterHandler();
1216 Protect( nTab, aPassword );
1219 if( !pReqArgs )
1221 rReq.AppendItem( SfxBoolItem( FID_PROTECT_TABLE, bNewProtection ) );
1222 rReq.Done();
1225 #endif
1226 TabChanged();
1227 UpdateInputHandler(true); // damit sofort wieder eingegeben werden kann
1228 SelectionChanged();
1230 break;
1232 case SID_OPT_LOCALE_CHANGED :
1233 { // locale changed, SYSTEM number formats changed => repaint cell contents
1234 PaintGrid();
1235 rReq.Done();
1237 break;
1239 case SID_OUTPLACE_OBJECT:
1240 case SID_INPLACE_OBJECT:
1242 SdrView* pDrView = GetSdrView();
1243 if ( pDrView )
1245 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
1246 if (rMarkList.GetMarkCount() == 1)
1248 BOOL bOle = GetViewFrame()->GetFrame()->IsInPlace();
1249 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
1250 if( pObj && pObj->ISA( SdrOle2Obj ) && !bOle )
1252 if( nSlot == SID_OUTPLACE_OBJECT )
1253 ActivateObject( static_cast< SdrOle2Obj* >( pObj ),
1254 embed::EmbedVerbs::MS_OLEVERB_OPEN );
1255 else
1256 ActivateObject( static_cast< SdrOle2Obj* >( pObj ),
1257 embed::EmbedVerbs::MS_OLEVERB_PRIMARY );
1261 break;
1264 default:
1265 DBG_ERROR("Unbekannter Slot bei ScTabViewShell::Execute");
1266 break;