Update ooo320-m1
[ooovba.git] / sc / source / ui / view / tabvwsh3.cxx
blob296b83821b9f824134418c0674482055e4218dc8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 FID_TAB_DESELECTALL:
813 DeselectAllTables();
814 rReq.Done();
815 break;
817 case SID_SELECT_TABLES:
819 ScViewData& rViewData = *GetViewData();
820 ScDocument& rDoc = *rViewData.GetDocument();
821 ScMarkData& rMark = rViewData.GetMarkData();
822 SCTAB nTabCount = rDoc.GetTableCount();
823 SCTAB nTab;
825 SvULongs aIndexList( 4, 4 );
826 SFX_REQUEST_ARG( rReq, pItem, SfxIntegerListItem, SID_SELECT_TABLES, sal_False );
827 if ( pItem )
828 pItem->GetList( aIndexList );
829 else
831 //CHINA001 ScShowTabDlg* pDlg = new ScShowTabDlg( GetDialogParent() );
832 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
833 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
835 AbstractScShowTabDlg* pDlg = pFact->CreateScShowTabDlg( GetDialogParent(), RID_SCDLG_SHOW_TAB);
836 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
837 pDlg->SetDescription(
838 String( ScResId( STR_DLG_SELECTTABLES_TITLE ) ),
839 String( ScResId( STR_DLG_SELECTTABLES_LBNAME ) ),
840 SID_SELECT_TABLES, HID_SELECTTABLES );
842 // fill all table names with selection state
843 String aTabName;
844 for( nTab = 0; nTab < nTabCount; ++nTab )
846 rDoc.GetName( nTab, aTabName );
847 pDlg->Insert( aTabName, rMark.GetTableSelect( nTab ) );
850 if( pDlg->Execute() == RET_OK )
852 sal_uInt16 nSelCount = pDlg->GetSelectEntryCount();
853 sal_uInt16 nSelIx;
854 for( nSelIx = 0; nSelIx < nSelCount; ++nSelIx )
855 aIndexList.Insert( pDlg->GetSelectEntryPos( nSelIx ), nSelIx );
856 delete pDlg;
857 rReq.AppendItem( SfxIntegerListItem( SID_SELECT_TABLES, aIndexList ) );
859 else
860 rReq.Ignore();
863 if ( aIndexList.Count() )
865 sal_uInt16 nSelCount = aIndexList.Count();
866 sal_uInt16 nSelIx;
867 SCTAB nFirstVisTab = 0;
869 // special case: only hidden tables selected -> do nothing
870 sal_Bool bVisSelected = sal_False;
871 for( nSelIx = 0; !bVisSelected && (nSelIx < nSelCount); ++nSelIx )
872 bVisSelected = rDoc.IsVisible( nFirstVisTab = static_cast<SCTAB>(aIndexList[nSelIx]) );
873 if( !bVisSelected )
874 nSelCount = 0;
876 // select the tables
877 if( nSelCount )
879 for( nTab = 0; nTab < nTabCount; ++nTab )
880 rMark.SelectTable( nTab, sal_False );
882 for( nSelIx = 0; nSelIx < nSelCount; ++nSelIx )
883 rMark.SelectTable( static_cast<SCTAB>(aIndexList[nSelIx]), sal_True );
885 // activate another table, if current is deselected
886 if( !rMark.GetTableSelect( rViewData.GetTabNo() ) )
888 rMark.SelectTable( nFirstVisTab, sal_True );
889 SetTabNo( nFirstVisTab );
892 rViewData.GetDocShell()->PostPaintExtras();
893 SfxBindings& rBind = rViewData.GetBindings();
894 rBind.Invalidate( FID_FILL_TAB );
895 rBind.Invalidate( FID_TAB_DESELECTALL );
898 rReq.Done();
901 break;
904 case SID_OUTLINE_DELETEALL:
905 RemoveAllOutlines();
906 rReq.Done();
907 break;
909 case SID_AUTO_OUTLINE:
910 AutoOutline();
911 rReq.Done();
912 break;
915 case SID_WINDOW_SPLIT:
917 ScSplitMode eHSplit = GetViewData()->GetHSplitMode();
918 ScSplitMode eVSplit = GetViewData()->GetVSplitMode();
919 if ( eHSplit == SC_SPLIT_NORMAL || eVSplit == SC_SPLIT_NORMAL ) // aufheben
920 RemoveSplit();
921 else if ( eHSplit == SC_SPLIT_FIX || eVSplit == SC_SPLIT_FIX ) // normal
922 FreezeSplitters( FALSE );
923 else // erzeugen
924 SplitAtCursor();
925 rReq.Done();
927 InvalidateSplit();
929 break;
931 case SID_WINDOW_FIX:
933 ScSplitMode eHSplit = GetViewData()->GetHSplitMode();
934 ScSplitMode eVSplit = GetViewData()->GetVSplitMode();
935 if ( eHSplit == SC_SPLIT_FIX || eVSplit == SC_SPLIT_FIX ) // aufheben
936 RemoveSplit();
937 else
938 FreezeSplitters( TRUE ); // erzeugen oder fixieren
939 rReq.Done();
941 InvalidateSplit();
943 break;
945 // ----------------------------------------------------------------
947 case FID_CHG_SHOW:
949 USHORT nId = ScHighlightChgDlgWrapper::GetChildWindowId();
950 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
952 pScMod->SetRefDialog( nId, pWnd ? FALSE : TRUE );
954 break;
956 case FID_CHG_ACCEPT:
958 pThisFrame->ToggleChildWindow(ScAcceptChgDlgWrapper::GetChildWindowId());
959 GetViewFrame()->GetBindings().Invalidate(FID_CHG_ACCEPT);
960 rReq.Done ();
963 USHORT nId = ScAcceptChgDlgWrapper::GetChildWindowId();
964 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
966 pScMod->SetRefDialog( nId, pWnd ? FALSE : TRUE );
969 break;
971 case FID_CHG_COMMENT:
973 ScViewData* pData = GetViewData();
974 ScAddress aCursorPos( pData->GetCurX(), pData->GetCurY(), pData->GetTabNo() );
975 ScDocShell* pDocSh = pData->GetDocShell();
977 ScChangeAction* pAction = pDocSh->GetChangeAction( aCursorPos );
978 if ( pAction )
980 const SfxPoolItem* pItem;
981 if ( pReqArgs &&
982 pReqArgs->GetItemState( nSlot, TRUE, &pItem ) == SFX_ITEM_SET &&
983 pItem->ISA( SfxStringItem ) )
985 String aComment = ((const SfxStringItem*)pItem)->GetValue();
986 pDocSh->SetChangeComment( pAction, aComment );
987 rReq.Done();
989 else
991 pDocSh->ExecuteChangeCommentDialog( pAction, GetDialogParent() );
992 rReq.Done();
996 break;
998 case SID_CREATE_SW_DRAWVIEW:
999 // wird von den Forms gerufen, wenn die DrawView mit allem Zubehoer
1000 // angelegt werden muss
1001 if (!GetScDrawView())
1003 GetViewData()->GetDocShell()->MakeDrawLayer();
1004 rBindings.InvalidateAll(FALSE);
1006 break;
1008 case FID_PROTECT_DOC:
1010 ScDocument* pDoc = GetViewData()->GetDocument();
1011 SfxPasswordDialog* pDlg;
1013 if( pReqArgs )
1015 const SfxPoolItem* pItem;
1016 if( IS_AVAILABLE( FID_PROTECT_DOC, &pItem ) &&
1017 ((const SfxBoolItem*)pItem)->GetValue() == pDoc->IsDocProtected() )
1019 rReq.Ignore();
1020 break;
1024 ScDocProtection* pProtect = pDoc->GetDocProtection();
1025 if (pProtect && pProtect->isProtected())
1027 BOOL bCancel = FALSE;
1028 String aPassword;
1030 if (pProtect->isProtectedWithPass())
1032 String aText( ScResId(SCSTR_PASSWORD) );
1034 pDlg = new SfxPasswordDialog( GetDialogParent(), &aText );
1035 pDlg->SetText( ScResId(SCSTR_UNPROTECTDOC) );
1036 pDlg->SetMinLen( 0 );
1037 pDlg->SetHelpId( FID_PROTECT_DOC );
1038 pDlg->SetEditHelpId( HID_PASSWD_DOC );
1040 if (pDlg->Execute() == RET_OK)
1041 aPassword = pDlg->GetPassword();
1042 else
1043 bCancel = TRUE;
1044 delete pDlg;
1046 if (!bCancel)
1048 Unprotect( TABLEID_DOC, aPassword );
1049 rReq.AppendItem( SfxBoolItem( FID_PROTECT_DOC, FALSE ) );
1050 rReq.Done();
1053 else
1055 String aText( ScResId(SCSTR_PASSWORDOPT) );
1057 pDlg = new SfxPasswordDialog( GetDialogParent(), &aText );
1058 pDlg->SetText( ScResId(SCSTR_PROTECTDOC) );
1059 pDlg->SetMinLen( 0 );
1060 pDlg->SetHelpId( FID_PROTECT_DOC );
1061 pDlg->SetEditHelpId( HID_PASSWD_DOC );
1062 pDlg->ShowExtras( SHOWEXTRAS_CONFIRM );
1064 if (pDlg->Execute() == RET_OK)
1066 String aPassword = pDlg->GetPassword();
1067 Protect( TABLEID_DOC, aPassword );
1068 rReq.AppendItem( SfxBoolItem( FID_PROTECT_DOC, TRUE ) );
1069 rReq.Done();
1072 delete pDlg;
1074 rBindings.Invalidate( FID_PROTECT_DOC );
1076 break;
1079 case FID_PROTECT_TABLE:
1081 ScDocument* pDoc = GetViewData()->GetDocument();
1082 SCTAB nTab = GetViewData()->GetTabNo();
1083 bool bOldProtection = pDoc->IsTabProtected(nTab);
1085 #if ENABLE_SHEET_PROTECTION
1087 if( pReqArgs )
1089 const SfxPoolItem* pItem;
1090 bool bNewProtection = !bOldProtection;
1091 if( IS_AVAILABLE( FID_PROTECT_TABLE, &pItem ) )
1092 bNewProtection = ((const SfxBoolItem*)pItem)->GetValue();
1093 if( bNewProtection == bOldProtection )
1095 rReq.Ignore();
1096 break;
1100 if (bOldProtection)
1102 // Unprotect a protected sheet.
1104 ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
1105 if (pProtect && pProtect->isProtectedWithPass())
1107 String aText( ScResId(SCSTR_PASSWORDOPT) );
1108 auto_ptr<SfxPasswordDialog> pDlg(new SfxPasswordDialog(GetDialogParent(), &aText));
1109 pDlg->SetText( ScResId(SCSTR_UNPROTECTTAB) );
1110 pDlg->SetMinLen( 0 );
1111 pDlg->SetHelpId( FID_PROTECT_TABLE );
1112 pDlg->SetEditHelpId( HID_PASSWD_TABLE );
1114 if (pDlg->Execute() == RET_OK)
1116 String aPassword = pDlg->GetPassword();
1117 Unprotect(nTab, aPassword);
1120 else
1121 // this sheet is not password-protected.
1122 Unprotect(nTab, String());
1124 if (!pReqArgs)
1126 rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, false) );
1127 rReq.Done();
1130 else
1132 // Protect a current sheet.
1134 auto_ptr<ScTableProtectionDlg> pDlg(new ScTableProtectionDlg(GetDialogParent()));
1136 ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
1137 if (pProtect)
1138 pDlg->SetDialogData(*pProtect);
1140 if (pDlg->Execute() == RET_OK)
1142 pScMod->InputEnterHandler();
1144 ScTableProtection aNewProtect;
1145 pDlg->WriteData(aNewProtect);
1146 ProtectSheet(nTab, aNewProtect);
1147 if (!pReqArgs)
1149 rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, true) );
1150 rReq.Done();
1154 #else
1155 auto_ptr<SfxPasswordDialog> pDlg;
1156 String aPassword;
1157 BOOL bCancel = FALSE;
1158 bool bNewProtection = ! bOldProtection;
1160 if( pReqArgs )
1162 const SfxPoolItem* pItem;
1163 if( IS_AVAILABLE( FID_PROTECT_TABLE, &pItem ) )
1164 bNewProtection = ((const SfxBoolItem*)pItem)->GetValue();
1165 if( bNewProtection == bOldProtection )
1167 rReq.Ignore();
1168 break;
1172 if ( bOldProtection)
1174 // Unprotect a protected sheet.
1176 ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
1177 if (pProtect && pProtect->isProtectedWithPass())
1179 String aText( ScResId(SCSTR_PASSWORDOPT) );
1180 pDlg.reset(new SfxPasswordDialog(GetDialogParent(), &aText));
1181 pDlg->SetText( ScResId(SCSTR_UNPROTECTTAB) );
1182 pDlg->SetMinLen( 0 );
1183 pDlg->SetHelpId( FID_PROTECT_TABLE );
1184 pDlg->SetEditHelpId( HID_PASSWD_TABLE );
1186 if (pDlg->Execute() == RET_OK)
1187 aPassword = pDlg->GetPassword();
1188 else
1189 bCancel = TRUE;
1192 if (!pReqArgs)
1194 rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, false) );
1195 rReq.Done();
1198 else
1200 String aText( ScResId(SCSTR_PASSWORDOPT) );
1202 pDlg.reset(new SfxPasswordDialog(GetDialogParent(), &aText));
1203 pDlg->SetText( ScResId(SCSTR_PROTECTTAB) );
1204 pDlg->SetMinLen( 0 );
1205 pDlg->SetHelpId( FID_PROTECT_TABLE );
1206 pDlg->SetEditHelpId( HID_PASSWD_TABLE );
1207 pDlg->ShowExtras( SHOWEXTRAS_CONFIRM );
1209 if (pDlg->Execute() == RET_OK)
1210 aPassword = pDlg->GetPassword();
1211 else
1212 bCancel = TRUE;
1215 if( !bCancel )
1217 if ( bOldProtection )
1218 Unprotect( nTab, aPassword );
1219 else
1221 pScMod->InputEnterHandler();
1223 Protect( nTab, aPassword );
1226 if( !pReqArgs )
1228 rReq.AppendItem( SfxBoolItem( FID_PROTECT_TABLE, bNewProtection ) );
1229 rReq.Done();
1232 #endif
1233 TabChanged();
1234 UpdateInputHandler(true); // damit sofort wieder eingegeben werden kann
1235 SelectionChanged();
1237 break;
1239 case SID_OPT_LOCALE_CHANGED :
1240 { // locale changed, SYSTEM number formats changed => repaint cell contents
1241 PaintGrid();
1242 rReq.Done();
1244 break;
1246 case SID_OUTPLACE_OBJECT:
1247 case SID_INPLACE_OBJECT:
1249 SdrView* pDrView = GetSdrView();
1250 if ( pDrView )
1252 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
1253 if (rMarkList.GetMarkCount() == 1)
1255 BOOL bOle = GetViewFrame()->GetFrame()->IsInPlace();
1256 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
1257 if( pObj && pObj->ISA( SdrOle2Obj ) && !bOle )
1259 if( nSlot == SID_OUTPLACE_OBJECT )
1260 ActivateObject( static_cast< SdrOle2Obj* >( pObj ),
1261 embed::EmbedVerbs::MS_OLEVERB_OPEN );
1262 else
1263 ActivateObject( static_cast< SdrOle2Obj* >( pObj ),
1264 embed::EmbedVerbs::MS_OLEVERB_PRIMARY );
1268 break;
1271 default:
1272 DBG_ERROR("Unbekannter Slot bei ScTabViewShell::Execute");
1273 break;