bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / ui / view / cellsh1.cxx
blob049df13d4d36fdcc8d5c7a9152554ea8efd267a6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/i18n/TextConversionOption.hpp>
21 #include <com/sun/star/sheet/DataPilotFieldFilter.hpp>
23 #include "scitems.hxx"
24 #include <sfx2/viewfrm.hxx>
26 #include <svl/stritem.hxx>
27 #include <svl/whiter.hxx>
28 #include <svl/zforlist.hxx>
29 #include <svl/zformat.hxx>
30 #include <sfx2/dispatch.hxx>
31 #include <sfx2/request.hxx>
32 #include <vcl/msgbox.hxx>
33 #include <svx/svxdlg.hxx>
34 #include <sot/formats.hxx>
35 #include <svx/postattr.hxx>
36 #include <editeng/fontitem.hxx>
37 #include <svx/clipfmtitem.hxx>
38 #include <sfx2/passwd.hxx>
39 #include <svx/hlnkitem.hxx>
40 #include <basic/sbxcore.hxx>
41 #include <unotools/useroptions.hxx>
42 #include <vcl/waitobj.hxx>
43 #include <unotools/localedatawrapper.hxx>
45 #include "cellsh.hxx"
46 #include "sc.hrc"
47 #include "document.hxx"
48 #include "patattr.hxx"
49 #include "scmod.hxx"
50 #include "scresid.hxx"
51 #include "tabvwsh.hxx"
52 #include "impex.hxx"
53 #include "reffind.hxx"
54 #include "uiitems.hxx"
55 #include "reffact.hxx"
56 #include "inputhdl.hxx"
57 #include "transobj.hxx"
58 #include "drwtrans.hxx"
59 #include "docfunc.hxx"
60 #include "editable.hxx"
61 #include "dpobject.hxx"
62 #include "dpsave.hxx"
63 #include "dpgroup.hxx" // for ScDPNumGroupInfo
64 #include "spellparam.hxx"
65 #include "postit.hxx"
66 #include "clipparam.hxx"
67 #include "pivot.hxx"
68 #include "dpsdbtab.hxx" // ScImportSourceDesc
69 #include "dpshttab.hxx" // ScSheetSourceDesc
70 #include "dbdata.hxx"
71 #include "docsh.hxx"
72 #include "cliputil.hxx"
73 #include "markdata.hxx"
74 #include "docpool.hxx"
75 #include "condformatdlg.hxx"
76 #include "attrib.hxx"
78 #include "globstr.hrc"
79 #include "scui_def.hxx"
80 #include <svx/dialogs.hrc>
81 #include "scabstdlg.hxx"
83 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
84 #include <com/sun/star/lang/XInitialization.hpp>
85 #include <com/sun/star/beans/PropertyValue.hpp>
86 #include <com/sun/star/beans/XPropertySet.hpp>
87 #include <cppuhelper/bootstrap.hxx>
88 #include <com/sun/star/i18n/TransliterationModules.hpp>
89 #include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
91 #include <boost/scoped_ptr.hpp>
93 using namespace ::com::sun::star;
94 using namespace ::com::sun::star::beans;
95 using namespace ::com::sun::star::uno;
97 //------------------------------------------------------------------
98 void ScCellShell::ExecuteEdit( SfxRequest& rReq )
100 ScModule* pScMod = SC_MOD();
101 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
102 SfxBindings& rBindings = pTabViewShell->GetViewFrame()->GetBindings();
103 const SfxItemSet* pReqArgs = rReq.GetArgs();
104 sal_uInt16 nSlot = rReq.GetSlot();
106 pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
108 // finish input
109 if ( GetViewData()->HasEditView( GetViewData()->GetActivePart() ) )
111 switch ( nSlot )
113 case FID_DEFINE_NAME:
114 case FID_ADD_NAME:
115 case FID_USE_NAME:
116 case FID_INSERT_NAME:
117 case SID_SPELL_DIALOG:
118 case SID_HANGUL_HANJA_CONVERSION:
119 case SID_OPENDLG_CONDFRMT:
120 case SID_OPENDLG_COLORSCALE:
121 case SID_OPENDLG_DATABAR:
123 pScMod->InputEnterHandler();
124 pTabViewShell->UpdateInputHandler();
125 break;
127 default:
128 break;
132 switch ( nSlot )
135 // insert / delete cells / rows / columns
138 case FID_INS_ROW:
139 pTabViewShell->InsertCells(INS_INSROWS);
140 rReq.Done();
141 break;
143 case FID_INS_COLUMN:
144 pTabViewShell->InsertCells(INS_INSCOLS);
145 rReq.Done();
146 break;
148 case FID_INS_CELLSDOWN:
149 pTabViewShell->InsertCells(INS_CELLSDOWN);
150 rReq.Done();
151 break;
153 case FID_INS_CELLSRIGHT:
154 pTabViewShell->InsertCells(INS_CELLSRIGHT);
155 rReq.Done();
156 break;
158 case SID_DEL_ROWS:
159 pTabViewShell->DeleteCells( DEL_DELROWS );
160 rReq.Done();
161 break;
163 case SID_DEL_COLS:
164 pTabViewShell->DeleteCells( DEL_DELCOLS );
165 rReq.Done();
166 break;
168 case FID_INS_CELL:
170 InsCellCmd eCmd=INS_NONE;
172 if ( pReqArgs )
174 const SfxPoolItem* pItem;
175 String aFlags;
177 if( pReqArgs->HasItem( FID_INS_CELL, &pItem ) )
178 aFlags = ((const SfxStringItem*)pItem)->GetValue();
179 if( aFlags.Len() )
181 switch( aFlags.GetChar(0) )
183 case 'V': eCmd = INS_CELLSDOWN ;break;
184 case '>': eCmd = INS_CELLSRIGHT ;break;
185 case 'R': eCmd = INS_INSROWS ;break;
186 case 'C': eCmd = INS_INSCOLS ;break;
190 else
192 if ( GetViewData()->SimpleColMarked() )
193 eCmd = INS_INSCOLS;
194 else if ( GetViewData()->SimpleRowMarked() )
195 eCmd = INS_INSROWS;
196 else
198 ScDocument* pDoc = GetViewData()->GetDocument();
199 sal_Bool bTheFlag=(pDoc->GetChangeTrack()!=NULL);
201 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
202 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
204 AbstractScInsertCellDlg* pDlg = pFact->CreateScInsertCellDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_INSCELL, bTheFlag);
205 OSL_ENSURE(pDlg, "Dialog create fail!");
206 if (pDlg->Execute() == RET_OK)
207 eCmd = pDlg->GetInsCellCmd();
208 delete pDlg;
212 if (eCmd!=INS_NONE)
214 pTabViewShell->InsertCells( eCmd );
216 if( ! rReq.IsAPI() )
218 String aParam;
220 switch( eCmd )
222 case INS_CELLSDOWN: aParam='V'; break;
223 case INS_CELLSRIGHT: aParam='>'; break;
224 case INS_INSROWS: aParam='R'; break;
225 case INS_INSCOLS: aParam='C'; break;
226 default:
228 // added to avoid warnings
231 rReq.AppendItem( SfxStringItem( FID_INS_CELL, aParam ) );
232 rReq.Done();
236 break;
238 case FID_DELETE_CELL:
240 DelCellCmd eCmd = DEL_NONE;
242 if ( pReqArgs )
244 const SfxPoolItem* pItem;
245 String aFlags;
247 if( pReqArgs->HasItem( FID_DELETE_CELL, &pItem ) )
248 aFlags = ((const SfxStringItem*)pItem)->GetValue();
249 if( aFlags.Len() )
251 switch( aFlags.GetChar(0) )
253 case 'U': eCmd = DEL_CELLSUP ;break;
254 case 'L': eCmd = DEL_CELLSLEFT ;break;
255 case 'R': eCmd = DEL_DELROWS ;break;
256 case 'C': eCmd = DEL_DELCOLS ;break;
260 else
262 if ( GetViewData()->SimpleColMarked() )
263 eCmd = DEL_DELCOLS;
264 else if ( GetViewData()->SimpleRowMarked() )
265 eCmd = DEL_DELROWS;
266 else
268 ScRange aRange;
269 ScDocument* pDoc = GetViewData()->GetDocument();
270 bool bTheFlag=GetViewData()->IsMultiMarked() ||
271 (GetViewData()->GetSimpleArea(aRange) == SC_MARK_SIMPLE_FILTERED) ||
272 (pDoc->GetChangeTrack() != NULL);
274 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
275 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
277 AbstractScDeleteCellDlg* pDlg = pFact->CreateScDeleteCellDlg( pTabViewShell->GetDialogParent(), bTheFlag );
278 OSL_ENSURE(pDlg, "Dialog create fail!");
280 if (pDlg->Execute() == RET_OK)
281 eCmd = pDlg->GetDelCellCmd();
282 delete pDlg;
286 if (eCmd != DEL_NONE )
288 pTabViewShell->DeleteCells( eCmd );
290 if( ! rReq.IsAPI() )
292 String aParam;
294 switch( eCmd )
296 case DEL_CELLSUP: aParam='U'; break;
297 case DEL_CELLSLEFT: aParam='L'; break;
298 case DEL_DELROWS: aParam='R'; break;
299 case DEL_DELCOLS: aParam='C'; break;
300 default:
302 // added to avoid warnings
305 rReq.AppendItem( SfxStringItem( FID_DELETE_CELL, aParam ) );
306 rReq.Done();
310 break;
313 // delete contents from cells
316 case SID_DELETE_CONTENTS:
317 pTabViewShell->DeleteContents( IDF_CONTENTS );
318 rReq.Done();
319 break;
321 case SID_DELETE:
323 sal_uInt16 nFlags = IDF_NONE;
325 if ( pReqArgs!=NULL && pTabViewShell->SelectionEditable() )
327 const SfxPoolItem* pItem;
328 String aFlags = OUString('A');
330 if( pReqArgs->HasItem( SID_DELETE, &pItem ) )
331 aFlags = ((const SfxStringItem*)pItem)->GetValue();
333 aFlags.ToUpperAscii();
334 sal_Bool bCont = sal_True;
336 for( xub_StrLen i=0 ; bCont && i<aFlags.Len() ; i++ )
338 switch( aFlags.GetChar(i) )
340 case 'A': // all
341 nFlags |= IDF_ALL;
342 bCont = false; // don't continue!
343 break;
344 case 'S': nFlags |= IDF_STRING; break;
345 case 'V': nFlags |= IDF_VALUE; break;
346 case 'D': nFlags |= IDF_DATETIME; break;
347 case 'F': nFlags |= IDF_FORMULA; break;
348 case 'N': nFlags |= IDF_NOTE; break;
349 case 'T': nFlags |= IDF_ATTRIB; break;
350 case 'O': nFlags |= IDF_OBJECTS; break;
354 else
356 ScEditableTester aTester( pTabViewShell );
357 if (aTester.IsEditable())
359 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
360 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
362 AbstractScDeleteContentsDlg* pDlg = pFact->CreateScDeleteContentsDlg(pTabViewShell->GetDialogParent());
363 OSL_ENSURE(pDlg, "Dialog create fail!");
364 ScDocument* pDoc = GetViewData()->GetDocument();
365 SCTAB nTab = GetViewData()->GetTabNo();
366 if ( pDoc->IsTabProtected(nTab) )
367 pDlg->DisableObjects();
368 if (pDlg->Execute() == RET_OK)
370 nFlags = pDlg->GetDelContentsCmdBits();
372 delete pDlg;
374 else
375 pTabViewShell->ErrorMessage(aTester.GetMessageId());
378 if( nFlags != IDF_NONE )
380 pTabViewShell->DeleteContents( nFlags );
382 if( ! rReq.IsAPI() )
384 String aFlags;
386 if( nFlags == IDF_ALL )
388 aFlags += 'A';
390 else
392 if( nFlags & IDF_STRING ) aFlags += 'S';
393 if( nFlags & IDF_VALUE ) aFlags += 'V';
394 if( nFlags & IDF_DATETIME ) aFlags += 'D';
395 if( nFlags & IDF_FORMULA ) aFlags += 'F';
396 if( nFlags & IDF_NOTE ) aFlags += 'N';
397 if( nFlags & IDF_ATTRIB ) aFlags += 'T';
398 if( nFlags & IDF_OBJECTS ) aFlags += 'O';
401 rReq.AppendItem( SfxStringItem( SID_DELETE, aFlags ) );
402 rReq.Done();
406 break;
409 // fill...
412 case FID_FILL_TO_BOTTOM:
413 pTabViewShell->FillSimple( FILL_TO_BOTTOM );
414 rReq.Done();
415 break;
417 case FID_FILL_TO_RIGHT:
418 pTabViewShell->FillSimple( FILL_TO_RIGHT );
419 rReq.Done();
420 break;
422 case FID_FILL_TO_TOP:
423 pTabViewShell->FillSimple( FILL_TO_TOP );
424 rReq.Done();
425 break;
427 case FID_FILL_TO_LEFT:
428 pTabViewShell->FillSimple( FILL_TO_LEFT );
429 rReq.Done();
430 break;
432 case FID_FILL_TAB:
434 sal_uInt16 nFlags = IDF_NONE;
435 sal_uInt16 nFunction = PASTE_NOFUNC;
436 sal_Bool bSkipEmpty = false;
437 sal_Bool bAsLink = false;
439 if ( pReqArgs!=NULL && pTabViewShell->SelectionEditable() )
441 const SfxPoolItem* pItem;
442 String aFlags = OUString('A');
444 if( pReqArgs->HasItem( FID_FILL_TAB, &pItem ) )
445 aFlags = ((const SfxStringItem*)pItem)->GetValue();
447 aFlags.ToUpperAscii();
448 sal_Bool bCont = sal_True;
450 for( xub_StrLen i=0 ; bCont && i<aFlags.Len() ; i++ )
452 switch( aFlags.GetChar(i) )
454 case 'A': // all
455 nFlags |= IDF_ALL;
456 bCont = false; // don't continue!
457 break;
458 case 'S': nFlags |= IDF_STRING; break;
459 case 'V': nFlags |= IDF_VALUE; break;
460 case 'D': nFlags |= IDF_DATETIME; break;
461 case 'F': nFlags |= IDF_FORMULA; break;
462 case 'N': nFlags |= IDF_NOTE; break;
463 case 'T': nFlags |= IDF_ATTRIB; break;
467 else
469 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
470 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
472 AbstractScInsertContentsDlg* pDlg = pFact->CreateScInsertContentsDlg( pTabViewShell->GetDialogParent(),
473 RID_SCDLG_INSCONT, 0, /* nCheckDefaults */
474 &ScGlobal::GetRscString(STR_FILL_TAB));
475 OSL_ENSURE(pDlg, "Dialog create fail!");
476 pDlg->SetFillMode(true);
478 if (pDlg->Execute() == RET_OK)
480 nFlags = pDlg->GetInsContentsCmdBits();
481 nFunction = pDlg->GetFormulaCmdBits();
482 bSkipEmpty = pDlg->IsSkipEmptyCells();
483 bAsLink = pDlg->IsLink();
484 // there is no MoveMode with fill tabs
486 delete pDlg;
489 if( nFlags != IDF_NONE )
491 pTabViewShell->FillTab( nFlags, nFunction, bSkipEmpty, bAsLink );
493 if( ! rReq.IsAPI() )
495 String aFlags;
497 if( nFlags == IDF_ALL )
499 aFlags += 'A';
501 else
503 if( nFlags & IDF_STRING ) aFlags += 'S';
504 if( nFlags & IDF_VALUE ) aFlags += 'V';
505 if( nFlags & IDF_DATETIME ) aFlags += 'D';
506 if( nFlags & IDF_FORMULA ) aFlags += 'F';
507 if( nFlags & IDF_NOTE ) aFlags += 'N';
508 if( nFlags & IDF_ATTRIB ) aFlags += 'T';
511 rReq.AppendItem( SfxStringItem( FID_FILL_TAB, aFlags ) );
512 rReq.Done();
516 break;
518 case FID_FILL_SERIES:
520 SCCOL nStartCol;
521 SCROW nStartRow;
522 SCTAB nStartTab;
523 SCCOL nEndCol;
524 SCROW nEndRow;
525 SCTAB nEndTab;
526 sal_uInt16 nPossDir = FDS_OPT_NONE;
527 FillDir eFillDir = FILL_TO_BOTTOM;
528 FillCmd eFillCmd = FILL_LINEAR;
529 FillDateCmd eFillDateCmd = FILL_DAY;
530 double fStartVal = MAXDOUBLE;
531 double fIncVal = 1;
532 double fMaxVal = MAXDOUBLE;
533 sal_Bool bDoIt = false;
535 GetViewData()->GetSimpleArea( nStartCol, nStartRow, nStartTab,
536 nEndCol, nEndRow, nEndTab );
538 if( nStartCol!=nEndCol )
540 nPossDir |= FDS_OPT_HORZ;
541 eFillDir=FILL_TO_RIGHT;
544 if( nStartRow!=nEndRow )
546 nPossDir |= FDS_OPT_VERT;
547 eFillDir=FILL_TO_BOTTOM;
550 ScDocument* pDoc = GetViewData()->GetDocument();
551 SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
553 if( pReqArgs )
555 const SfxPoolItem* pItem;
556 String aFillDir, aFillCmd, aFillDateCmd;
557 String aFillStep, aFillStart, aFillMax;
558 sal_uInt32 nKey;
559 double fTmpVal;
561 bDoIt=false;
563 if( pReqArgs->HasItem( FID_FILL_SERIES, &pItem ) )
564 aFillDir = ((const SfxStringItem*)pItem)->GetValue();
565 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
566 aFillCmd = ((const SfxStringItem*)pItem)->GetValue();
567 if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
568 aFillDateCmd = ((const SfxStringItem*)pItem)->GetValue();
569 if( pReqArgs->HasItem( FN_PARAM_3, &pItem ) )
570 aFillStep = ((const SfxStringItem*)pItem)->GetValue();
571 if( pReqArgs->HasItem( FN_PARAM_4, &pItem ) )
572 aFillStart = ((const SfxStringItem*)pItem)->GetValue();
573 if( pReqArgs->HasItem( FN_PARAM_5, &pItem ) )
574 aFillMax = ((const SfxStringItem*)pItem)->GetValue();
576 if( aFillDir.Len() )
577 switch( aFillDir.GetChar(0) )
579 case 'B': case 'b': eFillDir=FILL_TO_BOTTOM; break;
580 case 'R': case 'r': eFillDir=FILL_TO_RIGHT; break;
581 case 'T': case 't': eFillDir=FILL_TO_TOP; break;
582 case 'L': case 'l': eFillDir=FILL_TO_LEFT; break;
585 if( aFillCmd.Len() )
586 switch( aFillCmd.GetChar(0) )
588 case 'S': case 's': eFillCmd=FILL_SIMPLE; break;
589 case 'L': case 'l': eFillCmd=FILL_LINEAR; break;
590 case 'G': case 'g': eFillCmd=FILL_GROWTH; break;
591 case 'D': case 'd': eFillCmd=FILL_DATE; break;
592 case 'A': case 'a': eFillCmd=FILL_AUTO; break;
595 if( aFillDateCmd.Len() )
596 switch( aFillDateCmd.GetChar(0) )
598 case 'D': case 'd': eFillDateCmd=FILL_DAY; break;
599 case 'W': case 'w': eFillDateCmd=FILL_WEEKDAY; break;
600 case 'M': case 'm': eFillDateCmd=FILL_MONTH; break;
601 case 'Y': case 'y': eFillDateCmd=FILL_YEAR; break;
604 nKey = 0;
605 if( pFormatter->IsNumberFormat( aFillStart, nKey, fTmpVal ))
606 fStartVal = fTmpVal;
608 nKey = 0;
609 if( pFormatter->IsNumberFormat( aFillStep, nKey, fTmpVal ))
610 fIncVal = fTmpVal;
612 nKey = 0;
613 if( pFormatter->IsNumberFormat( aFillMax, nKey, fTmpVal ))
614 fMaxVal = fTmpVal;
616 bDoIt = sal_True;
619 else // (pReqArgs == NULL) => raise Dialog
621 sal_uInt32 nPrivFormat;
622 CellType eCellType;
623 pDoc->GetNumberFormat( nStartCol, nStartRow, nStartTab, nPrivFormat );
624 pDoc->GetCellType( nStartCol, nStartRow, nStartTab,eCellType );
625 const SvNumberformat* pPrivEntry = pFormatter->GetEntry( nPrivFormat );
626 if (!pPrivEntry)
628 OSL_FAIL("Numberformat not found !!!");
630 else
632 short nPrivType = pPrivEntry->GetType();
633 if ( ( nPrivType & NUMBERFORMAT_DATE)>0)
635 eFillCmd=FILL_DATE;
637 else if(eCellType==CELLTYPE_STRING)
639 eFillCmd=FILL_AUTO;
644 String aStartStr;
646 // suggest default Startvalue only, when just 1 row or column
647 if ( nStartCol == nEndCol || nStartRow == nEndRow )
649 double fInputEndVal = 0.0;
650 String aEndStr;
652 pDoc->GetInputString( nStartCol, nStartRow, nStartTab, aStartStr);
653 pDoc->GetValue( nStartCol, nStartRow, nStartTab, fStartVal );
656 if(eFillDir==FILL_TO_BOTTOM && nStartRow < nEndRow )
658 pDoc->GetInputString( nStartCol, nStartRow+1, nStartTab, aEndStr);
659 if(aEndStr.Len()>0)
661 pDoc->GetValue( nStartCol, nStartRow+1, nStartTab, fInputEndVal);
662 fIncVal=fInputEndVal-fStartVal;
665 else
667 if(nStartCol < nEndCol)
669 pDoc->GetInputString( nStartCol+1, nStartRow, nStartTab, aEndStr);
670 if(aEndStr.Len()>0)
672 pDoc->GetValue( nStartCol+1, nStartRow, nStartTab, fInputEndVal);
673 fIncVal=fInputEndVal-fStartVal;
677 if(eFillCmd==FILL_DATE)
679 Date aNullDate = *pDoc->GetFormatTable()->GetNullDate();
680 Date aStartDate = aNullDate;
681 aStartDate+= (long)fStartVal;
682 Date aEndDate = aNullDate;
683 aEndDate+= (long)fInputEndVal;
684 double fTempDate=0;
686 if(aStartDate.GetYear()!=aEndDate.GetYear())
688 eFillDateCmd = FILL_YEAR;
689 fTempDate=aEndDate.GetYear()-aStartDate.GetYear();
691 if(aStartDate.GetMonth()!=aEndDate.GetMonth())
693 eFillDateCmd = FILL_MONTH;
694 fTempDate=fTempDate*12+aEndDate.GetMonth()-aStartDate.GetMonth();
696 if(aStartDate.GetDay()==aEndDate.GetDay())
698 fIncVal=fTempDate;
702 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
703 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
705 AbstractScFillSeriesDlg* pDlg = pFact->CreateScFillSeriesDlg( pTabViewShell->GetDialogParent(),
706 *pDoc,
707 eFillDir, eFillCmd, eFillDateCmd,
708 aStartStr, fIncVal, fMaxVal,
709 nPossDir,
710 RID_SCDLG_FILLSERIES);
711 OSL_ENSURE(pDlg, "Dialog create fail!");
713 if ( nStartCol != nEndCol && nStartRow != nEndRow )
715 pDlg->SetEdStartValEnabled(false);
718 if ( pDlg->Execute() == RET_OK )
720 eFillDir = pDlg->GetFillDir();
721 eFillCmd = pDlg->GetFillCmd();
722 eFillDateCmd = pDlg->GetFillDateCmd();
724 if(eFillCmd==FILL_AUTO)
726 String aStr=pDlg->GetStartStr();
727 if(aStr.Len()>0)
728 pTabViewShell->EnterData( nStartCol, nStartRow, nStartTab, aStr );
730 fStartVal = pDlg->GetStart();
731 fIncVal = pDlg->GetStep();
732 fMaxVal = pDlg->GetMax();
733 bDoIt = sal_True;
735 delete pDlg;
738 if( bDoIt )
740 //nScFillModeMouseModifier = 0; // no Ctrl/Copy
741 pTabViewShell->FillSeries( eFillDir, eFillCmd, eFillDateCmd, fStartVal, fIncVal, fMaxVal );
743 if( ! rReq.IsAPI() )
745 String aPara;
746 Color* pColor=0;
748 switch( eFillDir )
750 case FILL_TO_BOTTOM: aPara = 'B'; break;
751 case FILL_TO_RIGHT: aPara = 'R'; break;
752 case FILL_TO_TOP: aPara = 'T'; break;
753 case FILL_TO_LEFT: aPara = 'L'; break;
754 default: aPara.Erase(); break;
756 rReq.AppendItem( SfxStringItem( FID_FILL_SERIES, aPara ) );
758 switch( eFillCmd )
760 case FILL_SIMPLE: aPara = 'S'; break;
761 case FILL_LINEAR: aPara = 'L'; break;
762 case FILL_GROWTH: aPara = 'G'; break;
763 case FILL_DATE: aPara = 'D'; break;
764 case FILL_AUTO: aPara = 'A'; break;
765 default: aPara.Erase(); break;
767 rReq.AppendItem( SfxStringItem( FN_PARAM_1, aPara ) );
769 switch( eFillDateCmd )
771 case FILL_DAY: aPara = 'D'; break;
772 case FILL_WEEKDAY: aPara = 'W'; break;
773 case FILL_MONTH: aPara = 'M'; break;
774 case FILL_YEAR: aPara = 'Y'; break;
775 default: aPara.Erase(); break;
777 rReq.AppendItem( SfxStringItem( FN_PARAM_2, aPara ) );
779 sal_uLong nFormatKey = pFormatter->GetStandardFormat(NUMBERFORMAT_NUMBER,
780 ScGlobal::eLnge );
782 pFormatter->GetOutputString( fIncVal, nFormatKey, aPara, &pColor );
783 rReq.AppendItem( SfxStringItem( FN_PARAM_3, aPara ) );
785 pFormatter->GetOutputString( fStartVal, nFormatKey, aPara, &pColor );
786 rReq.AppendItem( SfxStringItem( FN_PARAM_4, aPara ) );
788 pFormatter->GetOutputString( fMaxVal, nFormatKey, aPara, &pColor );
789 rReq.AppendItem( SfxStringItem( FN_PARAM_5, aPara ) );
791 rReq.Done();
795 break;
797 case FID_FILL_AUTO:
799 SCCOL nStartCol;
800 SCROW nStartRow;
801 SCCOL nEndCol;
802 SCROW nEndRow;
803 SCTAB nStartTab, nEndTab;
805 GetViewData()->GetFillData( nStartCol, nStartRow, nEndCol, nEndRow );
806 SCCOL nFillCol = GetViewData()->GetRefEndX();
807 SCROW nFillRow = GetViewData()->GetRefEndY();
808 ScDocument* pDoc = GetViewData()->GetDocument();
810 if( pReqArgs != NULL )
812 const SfxPoolItem* pItem;
814 if( pReqArgs->HasItem( FID_FILL_AUTO, &pItem ) )
816 ScAddress aScAddress;
817 String aArg = ((const SfxStringItem*)pItem)->GetValue();
819 if( aScAddress.Parse( aArg, pDoc, pDoc->GetAddressConvention() ) & SCA_VALID )
821 nFillRow = aScAddress.Row();
822 nFillCol = aScAddress.Col();
826 GetViewData()->GetSimpleArea( nStartCol,nStartRow,nStartTab,
827 nEndCol,nEndRow,nEndTab );
829 else // call via mouse
831 // not in a merged cell
833 if ( nStartCol == nEndCol && nStartRow == nEndRow )
835 SCCOL nMergeCol = nStartCol;
836 SCROW nMergeRow = nStartRow;
837 if ( GetViewData()->GetDocument()->ExtendMerge(
838 nStartCol, nStartRow, nMergeCol, nMergeRow,
839 GetViewData()->GetTabNo() ) )
841 if ( nFillCol >= nStartCol && nFillCol <= nMergeCol && nFillRow == nStartRow )
842 nFillCol = nStartCol;
843 if ( nFillRow >= nStartRow && nFillRow <= nMergeRow && nFillCol == nStartCol )
844 nFillRow = nStartRow;
849 if ( nFillCol != nEndCol || nFillRow != nEndRow )
851 if ( nFillCol==nEndCol || nFillRow==nEndRow )
853 FillDir eDir = FILL_TO_BOTTOM;
854 SCCOLROW nCount = 0;
856 if ( nFillCol==nEndCol )
858 if ( nFillRow > nEndRow )
860 eDir = FILL_TO_BOTTOM;
861 nCount = nFillRow - nEndRow;
863 else if ( nFillRow < nStartRow )
865 eDir = FILL_TO_TOP;
866 nCount = nStartRow - nFillRow;
869 else
871 if ( nFillCol > nEndCol )
873 eDir = FILL_TO_RIGHT;
874 nCount = nFillCol - nEndCol;
876 else if ( nFillCol < nStartCol )
878 eDir = FILL_TO_LEFT;
879 nCount = nStartCol - nFillCol;
883 if ( nCount != 0)
885 pTabViewShell->FillAuto( eDir, nStartCol, nStartRow, nEndCol, nEndRow, nCount );
887 if( ! rReq.IsAPI() )
889 String aAdrStr;
890 ScAddress aAdr( nFillCol, nFillRow, 0 );
891 aAdr.Format( aAdrStr, SCR_ABS, pDoc, pDoc->GetAddressConvention() );
893 rReq.AppendItem( SfxStringItem( FID_FILL_AUTO, aAdrStr ) );
894 rReq.Done();
899 else
901 OSL_FAIL( "Direction not unique for autofill" );
905 break;
908 // disposal (Outlines)
909 // SID_AUTO_OUTLINE, SID_OUTLINE_DELETEALL in Execute (in docsh.idl)
912 case SID_OUTLINE_HIDE:
913 if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
914 GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
915 pTabViewShell->SetDataPilotDetails( false );
916 else
917 pTabViewShell->HideMarkedOutlines();
918 rReq.Done();
919 break;
921 case SID_OUTLINE_SHOW:
923 ScDPObject* pDPObj = GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
924 GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
925 if ( pDPObj )
927 Sequence<sheet::DataPilotFieldFilter> aFilters;
928 sal_uInt16 nOrientation;
929 if ( pTabViewShell->HasSelectionForDrillDown( nOrientation ) )
931 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
932 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
934 AbstractScDPShowDetailDlg* pDlg = pFact->CreateScDPShowDetailDlg(
935 pTabViewShell->GetDialogParent(), RID_SCDLG_DPSHOWDETAIL, *pDPObj, nOrientation );
936 OSL_ENSURE(pDlg, "Dialog create fail!");
937 if ( pDlg->Execute() == RET_OK )
939 OUString aNewDimName( pDlg->GetDimensionName() );
940 pTabViewShell->SetDataPilotDetails( true, &aNewDimName );
943 else if ( !pDPObj->IsServiceData() &&
944 pDPObj->GetDataFieldPositionData(
945 ScAddress( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() ),
946 aFilters ) )
947 pTabViewShell->ShowDataPilotSourceData( *pDPObj, aFilters );
948 else
949 pTabViewShell->SetDataPilotDetails(true);
951 else
952 pTabViewShell->ShowMarkedOutlines();
953 rReq.Done();
955 break;
957 case SID_OUTLINE_MAKE:
959 sal_Bool bColumns = false;
960 sal_Bool bOk = sal_True;
962 if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
963 GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
965 ScDPNumGroupInfo aNumInfo;
966 aNumInfo.mbEnable = true;
967 aNumInfo.mbAutoStart = true;
968 aNumInfo.mbAutoEnd = true;
969 sal_Int32 nParts = 0;
970 if ( pTabViewShell->HasSelectionForDateGroup( aNumInfo, nParts ) )
972 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
973 OSL_ENSURE( pFact, "ScAbstractFactory create fail!" );
974 Date aNullDate( *GetViewData()->GetDocument()->GetFormatTable()->GetNullDate() );
975 AbstractScDPDateGroupDlg* pDlg = pFact->CreateScDPDateGroupDlg(
976 pTabViewShell->GetDialogParent(), RID_SCDLG_DPDATEGROUP,
977 aNumInfo, nParts, aNullDate );
978 OSL_ENSURE( pDlg, "Dialog create fail!" );
979 if( pDlg->Execute() == RET_OK )
981 aNumInfo = pDlg->GetGroupInfo();
982 pTabViewShell->DateGroupDataPilot( aNumInfo, pDlg->GetDatePart() );
985 else if ( pTabViewShell->HasSelectionForNumGroup( aNumInfo ) )
987 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
988 OSL_ENSURE( pFact, "ScAbstractFactory create fail!" );
989 AbstractScDPNumGroupDlg* pDlg = pFact->CreateScDPNumGroupDlg(
990 pTabViewShell->GetDialogParent(), RID_SCDLG_DPNUMGROUP, aNumInfo );
991 OSL_ENSURE( pDlg, "Dialog create fail!" );
992 if( pDlg->Execute() == RET_OK )
993 pTabViewShell->NumGroupDataPilot( pDlg->GetGroupInfo() );
995 else
996 pTabViewShell->GroupDataPilot();
998 bOk = false;
1000 else if( pReqArgs != NULL )
1002 const SfxPoolItem* pItem;
1003 bOk = false;
1005 if( pReqArgs->HasItem( SID_OUTLINE_MAKE, &pItem ) )
1007 String aCol = ((const SfxStringItem*)pItem)->GetValue();
1008 aCol.ToUpperAscii();
1010 switch( aCol.GetChar(0) )
1012 case 'R': bColumns=false; bOk = sal_True;break;
1013 case 'C': bColumns=sal_True; bOk = sal_True;break;
1017 else // Dialog, when not whole rows/columns are marked
1019 if ( GetViewData()->SimpleColMarked() && !GetViewData()->SimpleRowMarked() )
1020 bColumns = sal_True;
1021 else if ( !GetViewData()->SimpleColMarked() && GetViewData()->SimpleRowMarked() )
1022 bColumns = false;
1023 else
1025 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1026 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1028 AbstractScGroupDlg* pDlg = pFact->CreateAbstractScGroupDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_GRP_MAKE, RID_SCDLG_GRP_MAKE,false);
1029 OSL_ENSURE(pDlg, "Dialog create fail!");
1030 if ( pDlg->Execute() == RET_OK )
1031 bColumns = pDlg->GetColsChecked();
1032 else
1033 bOk = false;
1034 delete pDlg;
1037 if (bOk)
1039 pTabViewShell->MakeOutline( bColumns );
1041 if( ! rReq.IsAPI() )
1043 OUString aCol = bColumns ? OUString('C') : OUString('R');
1044 rReq.AppendItem( SfxStringItem( SID_OUTLINE_MAKE, aCol ) );
1045 rReq.Done();
1049 break;
1051 case SID_OUTLINE_REMOVE:
1053 sal_Bool bColumns = false;
1054 sal_Bool bOk = sal_True;
1056 if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
1057 GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
1059 pTabViewShell->UngroupDataPilot();
1060 bOk = false;
1062 else if( pReqArgs != NULL )
1064 const SfxPoolItem* pItem;
1065 bOk = false;
1067 if( pReqArgs->HasItem( SID_OUTLINE_REMOVE, &pItem ) )
1069 String aCol = ((const SfxStringItem*)pItem)->GetValue();
1070 aCol.ToUpperAscii();
1072 switch( aCol.GetChar(0) )
1074 case 'R': bColumns=false; bOk = sal_True;break;
1075 case 'C': bColumns=sal_True; bOk = sal_True;break;
1079 else // Dialog only when removal for rows and columns is possible
1081 sal_Bool bColPoss, bRowPoss;
1082 pTabViewShell->TestRemoveOutline( bColPoss, bRowPoss );
1083 if ( bColPoss && bRowPoss )
1085 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1086 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1088 AbstractScGroupDlg* pDlg = pFact->CreateAbstractScGroupDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_GRP_KILL, RID_SCDLG_GRP_KILL,true);
1089 OSL_ENSURE(pDlg, "Dialog create fail!");
1090 if ( pDlg->Execute() == RET_OK )
1091 bColumns = pDlg->GetColsChecked();
1092 else
1093 bOk = false;
1094 delete pDlg;
1096 else if ( bColPoss )
1097 bColumns = sal_True;
1098 else if ( bRowPoss )
1099 bColumns = false;
1100 else
1101 bOk = false;
1103 if (bOk)
1105 pTabViewShell->RemoveOutline( bColumns );
1107 if( ! rReq.IsAPI() )
1109 OUString aCol = bColumns ? OUString('C') : OUString('R');
1110 rReq.AppendItem( SfxStringItem( SID_OUTLINE_REMOVE, aCol ) );
1111 rReq.Done();
1115 break;
1118 // Clipboard
1122 case SID_COPY: // for graphs in DrawShell
1124 WaitObject aWait( GetViewData()->GetDialogParent() );
1125 pTabViewShell->CopyToClip( NULL, false, false, true );
1126 rReq.Done();
1127 GetViewData()->SetPasteMode( (ScPasteFlags) (SC_PASTE_MODE | SC_PASTE_BORDER) );
1128 pTabViewShell->ShowCursor();
1129 pTabViewShell->UpdateCopySourceOverlay();
1131 break;
1133 case SID_CUT: // for graphs in DrawShell
1135 WaitObject aWait( GetViewData()->GetDialogParent() );
1136 pTabViewShell->CutToClip( NULL, true );
1137 rReq.Done();
1138 GetViewData()->SetPasteMode( (ScPasteFlags)(SC_PASTE_MODE | SC_PASTE_BORDER));
1139 pTabViewShell->ShowCursor();
1140 pTabViewShell->UpdateCopySourceOverlay();
1142 break;
1144 case SID_PASTE:
1146 ScClipUtil::PasteFromClipboard ( GetViewData(), pTabViewShell, true );
1147 rReq.Done();
1149 break;
1151 case SID_CLIPBOARD_FORMAT_ITEMS:
1153 WaitObject aWait( GetViewData()->GetDialogParent() );
1155 sal_uLong nFormat = 0;
1156 const SfxPoolItem* pItem;
1157 if ( pReqArgs &&
1158 pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET &&
1159 pItem->ISA(SfxUInt32Item) )
1161 nFormat = ((const SfxUInt32Item*)pItem)->GetValue();
1164 if ( nFormat )
1166 Window* pWin = GetViewData()->GetActiveWin();
1167 sal_Bool bCells = ( ScTransferObj::GetOwnClipboard( pWin ) != NULL );
1168 sal_Bool bDraw = ( ScDrawTransferObj::GetOwnClipboard( pWin ) != NULL );
1169 sal_Bool bOle = ( nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE );
1171 if ( bCells && bOle )
1172 pTabViewShell->PasteFromSystem();
1173 else if ( bDraw && bOle )
1174 pTabViewShell->PasteDraw();
1175 else
1176 pTabViewShell->PasteFromSystem(nFormat);
1178 //?else
1179 //? pTabViewShell->PasteFromSystem();
1181 rReq.Done();
1183 pTabViewShell->CellContentChanged();
1184 break;
1186 case FID_INS_CELL_CONTENTS:
1188 sal_uInt16 nFlags = IDF_NONE;
1189 sal_uInt16 nFunction = PASTE_NOFUNC;
1190 sal_Bool bSkipEmpty = false;
1191 sal_Bool bTranspose = false;
1192 sal_Bool bAsLink = false;
1193 InsCellCmd eMoveMode = INS_NONE;
1195 Window* pWin = GetViewData()->GetActiveWin();
1196 ScDocument* pDoc = GetViewData()->GetDocument();
1197 sal_Bool bOtherDoc = !pDoc->IsClipboardSource();
1198 ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin );
1199 if ( pOwnClip )
1201 // keep a reference in case the clipboard is changed during dialog or PasteFromClip
1202 uno::Reference<datatransfer::XTransferable> aOwnClipRef( pOwnClip );
1203 if ( pReqArgs!=NULL && pTabViewShell->SelectionEditable() )
1205 const SfxPoolItem* pItem;
1206 String aFlags = OUString('A');
1208 if( pReqArgs->HasItem( FID_INS_CELL_CONTENTS, &pItem ) )
1209 aFlags = ((const SfxStringItem*)pItem)->GetValue();
1211 aFlags.ToUpperAscii();
1212 sal_Bool bCont = sal_True;
1214 for( xub_StrLen i=0 ; bCont && i<aFlags.Len() ; i++ )
1216 switch( aFlags.GetChar(i) )
1218 case 'A': // all
1219 nFlags |= IDF_ALL;
1220 bCont = false; // don't continue!
1221 break;
1222 case 'S': nFlags |= IDF_STRING; break;
1223 case 'V': nFlags |= IDF_VALUE; break;
1224 case 'D': nFlags |= IDF_DATETIME; break;
1225 case 'F': nFlags |= IDF_FORMULA; break;
1226 case 'N': nFlags |= IDF_NOTE; break;
1227 case 'T': nFlags |= IDF_ATTRIB; break;
1231 SFX_REQUEST_ARG( rReq, pFuncItem, SfxUInt16Item, FN_PARAM_1, false );
1232 SFX_REQUEST_ARG( rReq, pSkipItem, SfxBoolItem, FN_PARAM_2, false );
1233 SFX_REQUEST_ARG( rReq, pTransposeItem, SfxBoolItem, FN_PARAM_3, false );
1234 SFX_REQUEST_ARG( rReq, pLinkItem, SfxBoolItem, FN_PARAM_4, false );
1235 SFX_REQUEST_ARG( rReq, pMoveItem, SfxInt16Item, FN_PARAM_5, false );
1236 if ( pFuncItem )
1237 nFunction = pFuncItem->GetValue();
1238 if ( pSkipItem )
1239 bSkipEmpty = pSkipItem->GetValue();
1240 if ( pTransposeItem )
1241 bTranspose = pTransposeItem->GetValue();
1242 if ( pLinkItem )
1243 bAsLink = pLinkItem->GetValue();
1244 if ( pMoveItem )
1245 eMoveMode = (InsCellCmd) pMoveItem->GetValue();
1247 else
1249 ScEditableTester aTester( pTabViewShell );
1250 if (aTester.IsEditable())
1252 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1253 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1255 AbstractScInsertContentsDlg* pDlg = pFact->CreateScInsertContentsDlg( pTabViewShell->GetDialogParent(),
1256 RID_SCDLG_INSCONT);
1257 OSL_ENSURE(pDlg, "Dialog create fail!");
1258 pDlg->SetOtherDoc( bOtherDoc );
1259 // if ChangeTrack MoveMode disable
1260 pDlg->SetChangeTrack( pDoc->GetChangeTrack() != NULL );
1261 // fdo#56098 disable shift if necessary
1262 if ( !bOtherDoc && pOwnClip )
1264 ScViewData* pData = GetViewData();
1265 if ( pData->GetMarkData().GetTableSelect( pData->GetTabNo() ) )
1267 SCCOL nStartX, nEndX, nClipStartX, nClipSizeX, nRangeSizeX;
1268 SCROW nStartY, nEndY, nClipStartY, nClipSizeY, nRangeSizeY;
1269 SCTAB nStartTab, nEndTab;
1270 pOwnClip->GetDocument()->GetClipStart( nClipStartX, nClipStartY );
1271 pOwnClip->GetDocument()->GetClipArea( nClipSizeX, nClipSizeY, sal_True );
1273 if ( !( pData->GetSimpleArea( nStartX, nStartY, nStartTab,
1274 nEndX, nEndY, nEndTab ) == SC_MARK_SIMPLE &&
1275 nStartTab == nEndTab ) )
1277 // the destination is not a simple range,
1278 // assume the destination as the current cell
1279 nStartX = nEndX = pData->GetCurX();
1280 nStartY = nEndY = pData->GetCurY();
1281 nStartTab = pData->GetTabNo();
1283 // we now have clip- and range dimensions
1284 // the size of the destination area is the larger of the two
1285 nRangeSizeX = nClipSizeX >= nEndX - nStartX ? nClipSizeX : nEndX - nStartX;
1286 nRangeSizeY = nClipSizeY >= nEndY - nStartY ? nClipSizeY : nEndY - nStartY;
1287 // When the source and destination areas intersect things may go wrong,
1288 // especially if the area contains references. This may produce data loss
1289 // (e.g. formulas that get wrong references), this scenario _must_ be avoided.
1290 ScRange aSource( nClipStartX, nClipStartY, nStartTab,
1291 nClipStartX + nClipSizeX, nClipStartY + nClipSizeY, nStartTab );
1292 ScRange aDest( nStartX, nStartY, nStartTab,
1293 nStartX + nRangeSizeX, nStartY + nRangeSizeY, nStartTab );
1294 if ( pOwnClip->GetDocument()->IsCutMode() && aSource.Intersects( aDest ) )
1295 pDlg->SetCellShiftDisabled( SC_CELL_SHIFT_DISABLE_DOWN | SC_CELL_SHIFT_DISABLE_RIGHT );
1296 else
1298 //no conflict with intersecting ranges,
1299 //check if paste plus shift will fit on sheet
1300 //and disable shift-option if no fit
1301 int nDisableShiftX = 0;
1302 int nDisableShiftY = 0;
1304 //check if horizontal shift will fit
1305 if ( !pData->GetDocument()->IsBlockEmpty( nStartTab,
1306 MAXCOL - nRangeSizeX, nStartY,
1307 MAXCOL, nStartY + nRangeSizeY, false ) )
1308 nDisableShiftX = SC_CELL_SHIFT_DISABLE_RIGHT;
1310 //check if vertical shift will fit
1311 if ( !pData->GetDocument()->IsBlockEmpty( nStartTab,
1312 nStartX, MAXROW - nRangeSizeY,
1313 nStartX + nRangeSizeX, MAXROW, false ) )
1314 nDisableShiftY = SC_CELL_SHIFT_DISABLE_DOWN;
1316 if ( nDisableShiftX || nDisableShiftY )
1317 pDlg->SetCellShiftDisabled( nDisableShiftX | nDisableShiftY );
1321 if (pDlg->Execute() == RET_OK)
1323 nFlags = pDlg->GetInsContentsCmdBits();
1324 nFunction = pDlg->GetFormulaCmdBits();
1325 bSkipEmpty = pDlg->IsSkipEmptyCells();
1326 bTranspose = pDlg->IsTranspose();
1327 bAsLink = pDlg->IsLink();
1328 eMoveMode = pDlg->GetMoveMode();
1330 delete pDlg;
1332 else
1333 pTabViewShell->ErrorMessage(aTester.GetMessageId());
1336 if( nFlags != IDF_NONE )
1339 WaitObject aWait( GetViewData()->GetDialogParent() );
1340 if ( bAsLink && bOtherDoc )
1341 pTabViewShell->PasteFromSystem(SOT_FORMATSTR_ID_LINK); // DDE insert
1342 else
1344 pTabViewShell->PasteFromClip( nFlags, pOwnClip->GetDocument(),
1345 nFunction, bSkipEmpty, bTranspose, bAsLink,
1346 eMoveMode, IDF_NONE, sal_True ); // allow warning dialog
1350 if( !pReqArgs )
1352 String aFlags;
1354 if( nFlags == IDF_ALL )
1356 aFlags += 'A';
1358 else
1360 if( nFlags & IDF_STRING ) aFlags += 'S';
1361 if( nFlags & IDF_VALUE ) aFlags += 'V';
1362 if( nFlags & IDF_DATETIME ) aFlags += 'D';
1363 if( nFlags & IDF_FORMULA ) aFlags += 'F';
1364 if( nFlags & IDF_NOTE ) aFlags += 'N';
1365 if( nFlags & IDF_ATTRIB ) aFlags += 'T';
1368 rReq.AppendItem( SfxStringItem( FID_INS_CELL_CONTENTS, aFlags ) );
1369 rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bSkipEmpty ) );
1370 rReq.AppendItem( SfxBoolItem( FN_PARAM_3, bTranspose ) );
1371 rReq.AppendItem( SfxBoolItem( FN_PARAM_4, bAsLink ) );
1372 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, nFunction ) );
1373 rReq.AppendItem( SfxInt16Item( FN_PARAM_5, (sal_Int16) eMoveMode ) );
1374 rReq.Done();
1379 pTabViewShell->CellContentChanged(); // => PasteFromXXX ???
1380 break;
1381 case SID_PASTE_ONLY_VALUE:
1382 case SID_PASTE_ONLY_TEXT:
1383 case SID_PASTE_ONLY_FORMULA:
1385 Window* pWin = GetViewData()->GetActiveWin();
1386 if ( ScTransferObj::GetOwnClipboard( pWin ) ) // own cell data
1388 rReq.SetSlot( FID_INS_CELL_CONTENTS );
1389 OUString aFlags;
1390 if ( nSlot == SID_PASTE_ONLY_VALUE )
1391 aFlags = "V";
1392 else if ( nSlot == SID_PASTE_ONLY_TEXT )
1393 aFlags = "S";
1394 else
1395 aFlags = "F";
1396 rReq.AppendItem( SfxStringItem( FID_INS_CELL_CONTENTS, aFlags ) );
1397 ExecuteSlot( rReq, GetInterface() );
1398 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
1399 pTabViewShell->CellContentChanged();
1401 else
1402 rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1403 break;
1405 case SID_PASTE_SPECIAL:
1406 // differentiate between own cell data and draw objects/external data
1407 // this makes FID_INS_CELL_CONTENTS superfluous
1409 Window* pWin = GetViewData()->GetActiveWin();
1411 // Clipboard-ID given as parameter? Basic "PasteSpecial(Format)"
1412 const SfxPoolItem* pItem=NULL;
1413 if ( pReqArgs &&
1414 pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET &&
1415 pItem->ISA(SfxUInt32Item) )
1417 sal_uLong nFormat = ((const SfxUInt32Item*)pItem)->GetValue();
1418 sal_Bool bRet=sal_True;
1420 WaitObject aWait( GetViewData()->GetDialogParent() );
1421 sal_Bool bDraw = ( ScDrawTransferObj::GetOwnClipboard( pWin ) != NULL );
1422 if ( bDraw && nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE )
1423 pTabViewShell->PasteDraw();
1424 else
1425 bRet = pTabViewShell->PasteFromSystem(nFormat, sal_True); // TRUE: no error messages
1428 if ( bRet )
1430 rReq.SetReturnValue(SfxInt16Item(nSlot, bRet)); // 1 = success, 0 = fail
1431 rReq.Done();
1433 else
1434 // if format is not available -> fallback to request without parameters
1435 pItem = NULL;
1438 if ( !pItem )
1440 if ( ScTransferObj::GetOwnClipboard( pWin ) ) // own cell data
1442 rReq.SetSlot( FID_INS_CELL_CONTENTS );
1443 ExecuteSlot( rReq, GetInterface() );
1444 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
1446 else // draw objects or external data
1448 sal_Bool bDraw = ( ScDrawTransferObj::GetOwnClipboard( pWin ) != NULL );
1450 SvxClipboardFmtItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
1451 GetPossibleClipboardFormats( aFormats );
1453 sal_uInt16 nFormatCount = aFormats.Count();
1454 if ( nFormatCount )
1456 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1457 SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( pTabViewShell->GetDialogParent() );
1458 if ( pDlg )
1460 for (sal_uInt16 i=0; i<nFormatCount; i++)
1462 sal_uLong nFormatId = aFormats.GetClipbrdFormatId( i );
1463 String aName = aFormats.GetClipbrdFormatName( i );
1464 // special case for paste dialog: '*' is replaced by object type
1465 if ( nFormatId == SOT_FORMATSTR_ID_EMBED_SOURCE )
1466 aName.Assign((sal_Unicode)'*');
1467 pDlg->Insert( nFormatId, aName );
1470 TransferableDataHelper aDataHelper(
1471 TransferableDataHelper::CreateFromSystemClipboard( pWin ) );
1472 sal_uLong nFormat = pDlg->GetFormat( aDataHelper.GetTransferable() );
1473 if (nFormat > 0)
1476 WaitObject aWait( GetViewData()->GetDialogParent() );
1477 if ( bDraw && nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE )
1478 pTabViewShell->PasteDraw();
1479 else
1480 pTabViewShell->PasteFromSystem(nFormat);
1482 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
1483 rReq.AppendItem( SfxUInt32Item( nSlot, nFormat ) );
1484 rReq.Done();
1486 else
1488 rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1489 rReq.Ignore();
1492 delete pDlg;
1495 else
1496 rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1500 pTabViewShell->CellContentChanged(); // => PasteFromSystem() ???
1501 break;
1504 // other
1507 case FID_INS_ROWBRK:
1508 pTabViewShell->InsertPageBreak( false );
1509 rReq.Done();
1510 break;
1512 case FID_INS_COLBRK:
1513 pTabViewShell->InsertPageBreak( sal_True );
1514 rReq.Done();
1515 break;
1517 case FID_DEL_ROWBRK:
1518 pTabViewShell->DeletePageBreak( false );
1519 rReq.Done();
1520 break;
1522 case FID_DEL_COLBRK:
1523 pTabViewShell->DeletePageBreak( sal_True );
1524 rReq.Done();
1525 break;
1527 case SID_DETECTIVE_ADD_PRED:
1528 pTabViewShell->DetectiveAddPred();
1529 rReq.Done();
1530 break;
1532 case SID_DETECTIVE_DEL_PRED:
1533 pTabViewShell->DetectiveDelPred();
1534 rReq.Done();
1535 break;
1537 case SID_DETECTIVE_ADD_SUCC:
1538 pTabViewShell->DetectiveAddSucc();
1539 rReq.Done();
1540 break;
1542 case SID_DETECTIVE_DEL_SUCC:
1543 pTabViewShell->DetectiveDelSucc();
1544 rReq.Done();
1545 break;
1547 case SID_DETECTIVE_ADD_ERR:
1548 pTabViewShell->DetectiveAddError();
1549 rReq.Done();
1550 break;
1552 case SID_DETECTIVE_INVALID:
1553 pTabViewShell->DetectiveMarkInvalid();
1554 rReq.Done();
1555 break;
1557 case SID_DETECTIVE_REFRESH:
1558 pTabViewShell->DetectiveRefresh();
1559 rReq.Done();
1560 break;
1562 case SID_DETECTIVE_MARK_PRED:
1563 pTabViewShell->DetectiveMarkPred();
1564 break;
1565 case SID_DETECTIVE_MARK_SUCC:
1566 pTabViewShell->DetectiveMarkSucc();
1567 break;
1568 case SID_INSERT_CURRENT_DATE:
1569 pTabViewShell->InsertCurrentTime(
1570 NUMBERFORMAT_DATE, ScGlobal::GetRscString(STR_UNDO_INSERT_CURRENT_DATE));
1571 break;
1572 case SID_INSERT_CURRENT_TIME:
1573 pTabViewShell->InsertCurrentTime(
1574 NUMBERFORMAT_TIME, ScGlobal::GetRscString(STR_UNDO_INSERT_CURRENT_TIME));
1575 break;
1577 case SID_SPELL_DIALOG:
1579 SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame();
1580 if( rReq.GetArgs() )
1581 pViewFrame->SetChildWindow( SID_SPELL_DIALOG,
1582 static_cast< const SfxBoolItem& >( rReq.GetArgs()->
1583 Get( SID_SPELL_DIALOG ) ).GetValue() );
1584 else
1585 pViewFrame->ToggleChildWindow( SID_SPELL_DIALOG );
1587 pViewFrame->GetBindings().Invalidate( SID_SPELL_DIALOG );
1588 rReq.Ignore();
1590 break;
1592 case SID_HANGUL_HANJA_CONVERSION:
1593 pTabViewShell->DoHangulHanjaConversion();
1594 break;
1596 case SID_CHINESE_CONVERSION:
1598 //open ChineseTranslationDialog
1599 Reference< XComponentContext > xContext(
1600 ::cppu::defaultBootstrap_InitialComponentContext() ); //@todo get context from calc if that has one
1601 if(xContext.is())
1603 Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
1604 if(xMCF.is())
1606 Reference< ui::dialogs::XExecutableDialog > xDialog(
1607 xMCF->createInstanceWithContext(
1608 OUString("com.sun.star.linguistic2.ChineseTranslationDialog")
1609 , xContext), UNO_QUERY);
1610 Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
1611 if( xInit.is() )
1613 // initialize dialog
1614 Reference< awt::XWindow > xDialogParentWindow(0);
1615 Sequence<Any> aSeq(1);
1616 Any* pArray = aSeq.getArray();
1617 PropertyValue aParam;
1618 aParam.Name = OUString("ParentWindow");
1619 aParam.Value <<= makeAny(xDialogParentWindow);
1620 pArray[0] <<= makeAny(aParam);
1621 xInit->initialize( aSeq );
1623 //execute dialog
1624 sal_Int16 nDialogRet = xDialog->execute();
1625 if( RET_OK == nDialogRet )
1627 //get some parameters from the dialog
1628 sal_Bool bToSimplified = sal_True;
1629 sal_Bool bUseVariants = sal_True;
1630 sal_Bool bCommonTerms = sal_True;
1631 Reference< beans::XPropertySet > xProp( xDialog, UNO_QUERY );
1632 if( xProp.is() )
1636 xProp->getPropertyValue( OUString("IsDirectionToSimplified") ) >>= bToSimplified;
1637 xProp->getPropertyValue( OUString("IsUseCharacterVariants") ) >>= bUseVariants;
1638 xProp->getPropertyValue( OUString("IsTranslateCommonTerms") ) >>= bCommonTerms;
1640 catch( Exception& )
1645 //execute translation
1646 LanguageType eSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
1647 LanguageType eTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
1648 sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
1649 if( !bCommonTerms )
1650 nOptions |= i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
1652 Font aTargetFont = GetViewData()->GetActiveWin()->GetDefaultFont(
1653 DEFAULTFONT_CJK_SPREADSHEET,
1654 eTargetLang, DEFAULTFONT_FLAGS_ONLYONE );
1655 ScConversionParam aConvParam( SC_CONVERSION_CHINESE_TRANSL,
1656 eSourceLang, eTargetLang, aTargetFont, nOptions, false );
1657 pTabViewShell->DoSheetConversion( aConvParam );
1660 Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
1661 if( xComponent.is() )
1662 xComponent->dispose();
1666 break;
1668 case SID_THESAURUS:
1669 pTabViewShell->DoThesaurus();
1670 break;
1672 case SID_TOGGLE_REL:
1673 pTabViewShell->DoRefConversion();
1674 break;
1676 case SID_DEC_INDENT:
1677 pTabViewShell->ChangeIndent( false );
1678 break;
1679 case SID_INC_INDENT:
1680 pTabViewShell->ChangeIndent( sal_True );
1681 break;
1683 case FID_USE_NAME:
1685 sal_uInt16 nFlags = pTabViewShell->GetCreateNameFlags();
1687 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1688 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1690 AbstractScNameCreateDlg* pDlg = pFact->CreateScNameCreateDlg(pTabViewShell->GetDialogParent(), nFlags);
1691 OSL_ENSURE(pDlg, "Dialog create fail!");
1693 if( pDlg->Execute() )
1695 nFlags = pDlg->GetFlags();
1696 pTabViewShell->CreateNames(nFlags);
1697 rReq.Done();
1699 delete pDlg;
1701 break;
1703 case SID_CONSOLIDATE:
1705 const SfxPoolItem* pItem;
1706 if ( pReqArgs && SFX_ITEM_SET ==
1707 pReqArgs->GetItemState( SCITEM_CONSOLIDATEDATA, sal_True, &pItem ) )
1709 const ScConsolidateParam& rParam =
1710 ((const ScConsolidateItem*)pItem)->GetData();
1712 pTabViewShell->Consolidate( rParam );
1713 GetViewData()->GetDocument()->SetConsolidateDlgData( &rParam );
1715 rReq.Done();
1717 #ifndef DISABLE_SCRIPTING
1718 else if (rReq.IsAPI())
1719 SbxBase::SetError(SbxERR_BAD_PARAMETER);
1720 #endif
1722 break;
1724 case SID_INS_FUNCTION:
1726 const SfxBoolItem* pOkItem = (const SfxBoolItem*)&pReqArgs->Get( SID_DLG_RETOK );
1728 if ( pOkItem->GetValue() ) // OK
1730 String aFormula;
1731 const SfxStringItem* pSItem = (const SfxStringItem*)&pReqArgs->Get( SCITEM_STRING );
1732 const SfxBoolItem* pMatrixItem = (const SfxBoolItem*) &pReqArgs->Get( SID_DLG_MATRIX );
1734 aFormula += pSItem->GetValue();
1735 pScMod->ActivateInputWindow( &aFormula, pMatrixItem->GetValue() );
1737 else // CANCEL
1739 pScMod->ActivateInputWindow( NULL );
1741 rReq.Ignore(); // only SID_ENTER_STRING is recorded
1743 break;
1745 case FID_DEFINE_NAME:
1746 if ( pReqArgs )
1748 const SfxPoolItem* pItem;
1749 String aName, aSymbol, aAttrib;
1751 if( pReqArgs->HasItem( FID_DEFINE_NAME, &pItem ) )
1752 aName = ((const SfxStringItem*)pItem)->GetValue();
1754 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
1755 aSymbol = ((const SfxStringItem*)pItem)->GetValue();
1757 if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
1758 aAttrib = ((const SfxStringItem*)pItem)->GetValue();
1760 if ( aName.Len() && aSymbol.Len() )
1762 if (pTabViewShell->InsertName( aName, aSymbol, aAttrib ))
1763 rReq.Done();
1764 #ifndef DISABLE_SCRIPTING
1765 else
1766 SbxBase::SetError( SbxERR_BAD_PARAMETER ); // Basic-error
1767 #endif
1770 else
1772 sal_uInt16 nId = ScNameDlgWrapper::GetChildWindowId();
1773 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1774 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
1776 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
1778 break;
1779 case FID_ADD_NAME:
1781 sal_uInt16 nId = ScNameDefDlgWrapper::GetChildWindowId();
1782 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1783 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
1785 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
1787 break;
1789 case SID_OPENDLG_CONDFRMT:
1790 case SID_OPENDLG_COLORSCALE:
1791 case SID_OPENDLG_DATABAR:
1792 case SID_OPENDLG_ICONSET:
1793 case SID_OPENDLG_CONDDATE:
1796 ScRangeList aRangeList;
1797 ScViewData* pData = GetViewData();
1798 pData->GetMarkData().FillRangeListWithMarks(&aRangeList, false);
1800 ScDocument* pDoc = GetViewData()->GetDocument();
1801 if(pDoc->IsTabProtected(pData->GetTabNo()))
1803 //ErrorMessage( STR_ERR_CONDFORMAT_PROTECTED );
1804 break;
1807 ScAddress aPos(pData->GetCurX(), pData->GetCurY(), pData->GetTabNo());
1808 if(aRangeList.empty())
1810 ScRange* pRange = new ScRange(aPos);
1811 aRangeList.push_back(pRange);
1814 sal_Int32 nKey = 0;
1815 const ScPatternAttr* pPattern = pDoc->GetPattern(aPos.Col(), aPos.Row(), aPos.Tab());
1816 const std::vector<sal_uInt32>& rCondFormats = static_cast<const ScCondFormatItem&>(pPattern->GetItem(ATTR_CONDITIONAL)).GetCondFormatData();
1817 bool bContainsCondFormat = !rCondFormats.empty();
1818 boost::scoped_ptr<ScCondFormatDlg> pCondFormatDlg;
1819 if(bContainsCondFormat)
1821 bool bContainsExistingCondFormat = false;
1822 ScConditionalFormatList* pList = pDoc->GetCondFormList(aPos.Tab());
1823 for (std::vector<sal_uInt32>::const_iterator itr = rCondFormats.begin(), itrEnd = rCondFormats.end();
1824 itr != itrEnd; ++itr)
1826 // check if at least one existing conditional format has the same range
1827 const ScConditionalFormat* pCondFormat = pList->GetFormat(*itr);
1828 if(!pCondFormat)
1829 continue;
1831 bContainsExistingCondFormat = true;
1832 const ScRangeList& rCondFormatRange = pCondFormat->GetRange();
1833 if(rCondFormatRange == aRangeList)
1835 // found a matching range, edit this conditional format
1836 nKey = pCondFormat->GetKey();
1837 pCondFormatDlg.reset( new ScCondFormatDlg( pTabViewShell->GetDialogParent(), pDoc, pCondFormat, rCondFormatRange, aPos, condformat::dialog::NONE ) );
1838 break;
1842 // if not found a conditional format ask whether we should edit one of the existing
1843 // or should create a new overlapping conditional format
1845 if(!pCondFormatDlg && bContainsExistingCondFormat)
1847 QueryBox aBox( pTabViewShell->GetDialogParent(), WinBits( WB_YES_NO | WB_DEF_YES ),
1848 ScGlobal::GetRscString(STR_EDIT_EXISTING_COND_FORMATS) );
1849 bool bEditExisting = aBox.Execute() == RET_YES;
1850 if(bEditExisting)
1852 // differentiate between ranges where one conditional format is defined
1853 // and several formats are defined
1854 // if we have only one => open the cond format dlg to edit it
1855 // otherwise open the manage cond format dlg
1856 if(rCondFormats.size() == 1)
1858 const ScConditionalFormat* pCondFormat = pList->GetFormat(rCondFormats[0]);
1859 assert(pCondFormat);
1860 const ScRangeList& rCondFormatRange = pCondFormat->GetRange();
1861 nKey = pCondFormat->GetKey();
1862 pCondFormatDlg.reset( new ScCondFormatDlg( pTabViewShell->GetDialogParent(), pDoc, pCondFormat, rCondFormatRange, aPos, condformat::dialog::NONE ) );
1864 else
1866 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1867 boost::scoped_ptr<AbstractScCondFormatManagerDlg> pDlg(pFact->CreateScCondFormatMgrDlg( pTabViewShell->GetDialogParent(), pDoc, pList, aPos, RID_SCDLG_COND_FORMAT_MANAGER));
1868 if(pDlg->Execute() == RET_OK && pDlg->CondFormatsChanged())
1870 ScConditionalFormatList* pCondFormatList = pDlg->GetConditionalFormatList();
1871 pData->GetDocShell()->GetDocFunc().SetConditionalFormatList(pCondFormatList, aPos.Tab());
1873 // we need step out here because we don't want to open the normal dialog
1874 break;
1877 else
1879 // define an overlapping conditional format
1880 // does not need to be handled here
1886 if(!pCondFormatDlg)
1888 condformat::dialog::ScCondFormatDialogType eType = condformat::dialog::NONE;
1889 switch(nSlot)
1891 case SID_OPENDLG_CONDFRMT:
1892 eType = condformat::dialog::CONDITION;
1893 break;
1894 case SID_OPENDLG_COLORSCALE:
1895 eType = condformat::dialog::COLORSCALE;
1896 break;
1897 case SID_OPENDLG_DATABAR:
1898 eType = condformat::dialog::DATABAR;
1899 break;
1900 case SID_OPENDLG_ICONSET:
1901 eType = condformat::dialog::ICONSET;
1902 break;
1903 case SID_OPENDLG_CONDDATE:
1904 eType = condformat::dialog::DATE;
1905 break;
1906 default:
1907 assert(false);
1908 break;
1910 pCondFormatDlg.reset( new ScCondFormatDlg( pTabViewShell->GetDialogParent(), pDoc, NULL, aRangeList, aRangeList.GetTopLeftCorner(), eType ) );
1913 sal_uInt16 nId = 1;
1914 pScMod->SetRefDialog( nId, true );
1916 if( pCondFormatDlg->Execute() == RET_OK )
1918 ScConditionalFormat* pFormat = pCondFormatDlg->GetConditionalFormat();
1919 if(pFormat)
1920 pData->GetDocShell()->GetDocFunc().ReplaceConditionalFormat(nKey, pFormat, aPos.Tab(), pFormat->GetRange());
1921 else
1922 pData->GetDocShell()->GetDocFunc().ReplaceConditionalFormat(nKey, NULL, aPos.Tab(), ScRangeList());
1925 pScMod->SetRefDialog( nId, false );
1929 break;
1931 case SID_DEFINE_COLROWNAMERANGES:
1934 sal_uInt16 nId = ScColRowNameRangesDlgWrapper::GetChildWindowId();
1935 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1936 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
1938 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
1941 break;
1943 case SID_UPDATECHART:
1945 sal_Bool bAll = false;
1947 if( pReqArgs )
1949 const SfxPoolItem* pItem;
1951 if( pReqArgs->HasItem( SID_UPDATECHART, &pItem ) )
1952 bAll = ((const SfxBoolItem*)pItem)->GetValue();
1955 pTabViewShell->UpdateCharts( bAll );
1957 if( ! rReq.IsAPI() )
1959 rReq.AppendItem( SfxBoolItem( SID_UPDATECHART, bAll ) );
1960 rReq.Done();
1963 break;
1966 case SID_TABOP:
1967 if (pReqArgs)
1969 const ScTabOpItem& rItem =
1970 (const ScTabOpItem&)
1971 pReqArgs->Get( SID_TABOP );
1973 pTabViewShell->TabOp( rItem.GetData() );
1975 rReq.Done( *pReqArgs );
1977 break;
1979 case SID_SOLVE:
1980 if (pReqArgs)
1982 const ScSolveItem& rItem =
1983 (const ScSolveItem&)
1984 pReqArgs->Get( SCITEM_SOLVEDATA );
1986 pTabViewShell->Solve( rItem.GetData() );
1988 rReq.Done( *pReqArgs );
1990 break;
1992 case FID_INSERT_NAME:
1994 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1995 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1997 AbstractScNamePasteDlg* pDlg = pFact->CreateScNamePasteDlg( pTabViewShell->GetDialogParent(), GetViewData()->GetDocShell() );
1998 OSL_ENSURE(pDlg, "Dialog create fail!");
1999 switch( pDlg->Execute() )
2001 case BTN_PASTE_LIST:
2002 pTabViewShell->InsertNameList();
2003 break;
2004 case BTN_PASTE_NAME:
2006 ScInputHandler* pHdl = pScMod->GetInputHdl( pTabViewShell );
2007 if (pHdl)
2009 // "=" in KeyEvent, switches to input-mode
2010 pScMod->InputKeyEvent( KeyEvent('=',KeyCode()) );
2012 std::vector<OUString> aNames = pDlg->GetSelectedNames();
2013 if (!aNames.empty())
2015 OUStringBuffer aBuffer;
2016 for (std::vector<OUString>::const_iterator itr = aNames.begin();
2017 itr != aNames.end(); ++itr)
2019 aBuffer.append(*itr).append(' ');
2021 pHdl->InsertFunction( aBuffer.makeStringAndClear(), false ); // without "()"
2025 break;
2027 delete pDlg;
2029 break;
2031 case SID_RANGE_NOTETEXT:
2032 if (pReqArgs)
2034 const SfxStringItem& rTextItem = (const SfxStringItem&)pReqArgs->Get( SID_RANGE_NOTETEXT );
2036 // always cursor position
2037 ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
2038 pTabViewShell->SetNoteText( aPos, rTextItem.GetValue() );
2039 rReq.Done();
2041 break;
2043 case SID_INSERT_POSTIT:
2044 if ( pReqArgs )
2046 const SvxPostItAuthorItem& rAuthorItem = (const SvxPostItAuthorItem&)pReqArgs->Get( SID_ATTR_POSTIT_AUTHOR );
2047 const SvxPostItDateItem& rDateItem = (const SvxPostItDateItem&) pReqArgs->Get( SID_ATTR_POSTIT_DATE );
2048 const SvxPostItTextItem& rTextItem = (const SvxPostItTextItem&) pReqArgs->Get( SID_ATTR_POSTIT_TEXT );
2050 ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
2051 pTabViewShell->ReplaceNote( aPos, rTextItem.GetValue(), &rAuthorItem.GetValue(), &rDateItem.GetValue() );
2052 rReq.Done();
2054 else
2056 pTabViewShell->EditNote(); // note object to edit
2058 break;
2060 case FID_NOTE_VISIBLE:
2062 ScDocument* pDoc = GetViewData()->GetDocument();
2063 ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
2064 if( ScPostIt* pNote = pDoc->GetNotes( aPos.Tab() )->findByAddress(aPos) )
2066 bool bShow;
2067 const SfxPoolItem* pItem;
2068 if ( pReqArgs && (pReqArgs->GetItemState( FID_NOTE_VISIBLE, sal_True, &pItem ) == SFX_ITEM_SET) )
2069 bShow = ((const SfxBoolItem*) pItem)->GetValue();
2070 else
2071 bShow = !pNote->IsCaptionShown();
2073 pTabViewShell->ShowNote( bShow );
2075 if (!pReqArgs)
2076 rReq.AppendItem( SfxBoolItem( FID_NOTE_VISIBLE, bShow ) );
2078 rReq.Done();
2079 rBindings.Invalidate( FID_NOTE_VISIBLE );
2081 else
2082 rReq.Ignore();
2084 break;
2086 case FID_HIDE_NOTE:
2087 case FID_SHOW_NOTE:
2089 bool bShowNote = nSlot == FID_SHOW_NOTE;
2090 ScViewData* pData = GetViewData();
2091 ScDocument* pDoc = pData->GetDocument();
2092 ScMarkData& rMark = pData->GetMarkData();
2093 bool bDone = false;
2095 if (!rMark.IsMarked() && !rMark.IsMultiMarked())
2097 // Check current cell
2098 ScAddress aPos( pData->GetCurX(), pData->GetCurY(), pData->GetTabNo() );
2099 if( pDoc->GetNotes( aPos.Tab() )->findByAddress(aPos) )
2101 pData->GetDocShell()->GetDocFunc().ShowNote( aPos, bShowNote );
2102 bDone = true;
2105 else
2107 // Check selection range
2108 ScRangeListRef aRangesRef;
2109 pData->GetMultiArea(aRangesRef);
2110 ScRangeList aRanges = *aRangesRef;
2111 size_t nRangeSize = aRanges.size();
2113 String aUndo = ScGlobal::GetRscString( bShowNote ? STR_UNDO_SHOWNOTE : STR_UNDO_HIDENOTE );
2114 pData->GetDocShell()->GetUndoManager()->EnterListAction( aUndo, aUndo );
2116 for ( size_t i = 0; i < nRangeSize; ++i )
2118 const ScRange * pRange = aRanges[i];
2119 const SCROW nRow0 = pRange->aStart.Row();
2120 const SCROW nRow1 = pRange->aEnd.Row();
2121 const SCCOL nCol0 = pRange->aStart.Col();
2122 const SCCOL nCol1 = pRange->aEnd.Col();
2123 const SCTAB nRangeTab = pRange->aStart.Tab();
2124 const size_t nCellNumber = ( nRow1 - nRow0 ) * ( nCol1 - nCol0 );
2125 ScNotes *pNotes = pDoc->GetNotes(nRangeTab);
2127 if ( nCellNumber < pNotes->size() )
2129 // Check by each cell
2130 for ( SCROW nRow = nRow0; nRow <= nRow1; ++nRow )
2132 for ( SCCOL nCol = nCol0; nCol <= nCol1; ++nCol )
2134 ScPostIt* pNote = pNotes->findByAddress(nCol, nRow);
2135 if ( pNote && pDoc->IsBlockEditable( nRangeTab, nCol,nRow, nCol,nRow ) )
2137 ScAddress aPos( nCol, nRow, nRangeTab );
2138 pData->GetDocShell()->GetDocFunc().ShowNote( aPos, bShowNote );
2139 bDone = true;
2144 else
2146 // Check by each document note
2147 for (ScNotes::const_iterator itr = pNotes->begin(); itr != pNotes->end(); ++itr)
2149 SCCOL nCol = itr->first.first;
2150 SCROW nRow = itr->first.second;
2152 if ( nCol <= nCol1 && nRow <= nRow1 && nCol >= nCol0 && nRow >= nRow0 )
2154 ScAddress aPos( nCol, nRow, nRangeTab );
2155 pData->GetDocShell()->GetDocFunc().ShowNote( aPos, bShowNote );
2156 bDone = true;
2162 pData->GetDocShell()->GetUndoManager()->LeaveListAction();
2164 if ( bDone )
2166 rReq.Done();
2167 rBindings.Invalidate( nSlot );
2169 else
2170 rReq.Ignore();
2173 break;
2175 case SID_DELETE_NOTE:
2176 pTabViewShell->DeleteContents( IDF_NOTE ); // delete all notes in selection
2177 rReq.Done();
2178 break;
2180 case SID_CHARMAP:
2181 if( pReqArgs != NULL )
2183 String aChars, aFontName;
2184 const SfxItemSet *pArgs = rReq.GetArgs();
2185 const SfxPoolItem* pItem = 0;
2186 if ( pArgs )
2187 pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP), false, &pItem);
2188 if ( pItem )
2190 const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, pItem );
2191 if ( pStringItem )
2192 aChars = pStringItem->GetValue();
2193 const SfxPoolItem* pFtItem = NULL;
2194 pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR), false, &pFtItem);
2195 const SfxStringItem* pFontItem = PTR_CAST( SfxStringItem, pFtItem );
2196 if ( pFontItem )
2197 aFontName = pFontItem->GetValue();
2200 if ( aChars.Len() )
2202 Font aFont;
2203 pTabViewShell->GetSelectionPattern()->GetFont( aFont, SC_AUTOCOL_BLACK, NULL, NULL, NULL,
2204 pTabViewShell->GetSelectionScriptType() );
2205 if ( aFontName.Len() )
2206 aFont = Font( aFontName, Size(1,1) );
2207 pTabViewShell->InsertSpecialChar( aChars, aFont );
2208 if( ! rReq.IsAPI() )
2209 rReq.Done();
2212 else
2214 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
2216 // font color doesn't matter here
2217 Font aCurFont;
2218 pTabViewShell->GetSelectionPattern()->GetFont( aCurFont, SC_AUTOCOL_BLACK, NULL, NULL, NULL,
2219 pTabViewShell->GetSelectionScriptType() );
2221 SfxAllItemSet aSet( GetPool() );
2222 aSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
2223 aSet.Put( SvxFontItem( aCurFont.GetFamily(), aCurFont.GetName(), aCurFont.GetStyleName(), aCurFont.GetPitch(), aCurFont.GetCharSet(), GetPool().GetWhich(SID_ATTR_CHAR_FONT) ) );
2225 SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( pTabViewShell->GetDialogParent(), aSet,
2226 pTabViewShell->GetViewFrame()->GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP );
2228 if ( pDlg->Execute() == RET_OK )
2230 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pItem, SfxStringItem, SID_CHARMAP, false );
2231 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFontItem, SvxFontItem, SID_ATTR_CHAR_FONT, false );
2233 if ( pItem && pFontItem )
2235 Font aNewFont( pFontItem->GetFamilyName(), pFontItem->GetStyleName(), Size(1,1) );
2236 aNewFont.SetCharSet( pFontItem->GetCharSet() );
2237 aNewFont.SetPitch( pFontItem->GetPitch() );
2238 pTabViewShell->InsertSpecialChar( pItem->GetValue(), aNewFont );
2239 rReq.AppendItem( *pFontItem );
2240 rReq.AppendItem( *pItem );
2241 rReq.Done();
2244 delete pDlg;
2246 break;
2248 case SID_SELECT_SCENARIO:
2250 // Testing
2252 if ( pReqArgs )
2254 const SfxStringItem* pItem =
2255 (const SfxStringItem*)&pReqArgs->Get( SID_SELECT_SCENARIO );
2257 if( pItem )
2259 pTabViewShell->UseScenario( pItem->GetValue() );
2260 //! why should the return value be valid?!?!
2261 rReq.SetReturnValue( SfxStringItem( SID_SELECT_SCENARIO, pItem->GetValue() ) );
2262 rReq.Done();
2264 else
2266 OSL_FAIL("NULL");
2270 break;
2272 case SID_HYPERLINK_SETLINK:
2273 if( pReqArgs )
2275 const SfxPoolItem* pItem;
2276 if( pReqArgs->HasItem( SID_HYPERLINK_SETLINK, &pItem ) )
2278 const SvxHyperlinkItem* pHyper = (const SvxHyperlinkItem*) pItem;
2279 const String& rName = pHyper->GetName();
2280 const String& rURL = pHyper->GetURL();
2281 const String& rTarget = pHyper->GetTargetFrame();
2282 sal_uInt16 nType = (sal_uInt16) pHyper->GetInsertMode();
2284 pTabViewShell->InsertURL( rName, rURL, rTarget, nType );
2285 rReq.Done();
2287 else
2288 rReq.Ignore();
2290 break;
2292 case SID_OPENDLG_CONDFRMT_MANAGER:
2294 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2295 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2297 ScViewData* pData = GetViewData();
2298 ScDocument* pDoc = pData->GetDocument();
2300 if(pDoc->IsTabProtected(pData->GetTabNo()))
2302 pTabViewShell->ErrorMessage( STR_ERR_CONDFORMAT_PROTECTED );
2303 break;
2306 ScAddress aPos(pData->GetCurX(), pData->GetCurY(), pData->GetTabNo());
2308 ScConditionalFormatList* pList = pDoc->GetCondFormList( aPos.Tab() );
2309 boost::scoped_ptr<AbstractScCondFormatManagerDlg> pDlg(pFact->CreateScCondFormatMgrDlg( pTabViewShell->GetDialogParent(), pDoc, pList, aPos, RID_SCDLG_COND_FORMAT_MANAGER));
2310 if(pDlg->Execute() == RET_OK && pDlg->CondFormatsChanged())
2312 ScConditionalFormatList* pCondFormatList = pDlg->GetConditionalFormatList();
2313 pData->GetDocShell()->GetDocFunc().SetConditionalFormatList(pCondFormatList, aPos.Tab());
2316 break;
2318 case SID_EXTERNAL_SOURCE:
2320 String aFile;
2321 String aFilter;
2322 String aOptions;
2323 String aSource;
2324 sal_uLong nRefresh=0;
2326 SFX_REQUEST_ARG( rReq, pFile, SfxStringItem, SID_FILE_NAME, false );
2327 SFX_REQUEST_ARG( rReq, pSource, SfxStringItem, FN_PARAM_1, false );
2328 if ( pFile && pSource )
2330 aFile = pFile->GetValue();
2331 aSource = pSource->GetValue();
2332 SFX_REQUEST_ARG( rReq, pFilter, SfxStringItem, SID_FILTER_NAME, false );
2333 if ( pFilter )
2334 aFilter = pFilter->GetValue();
2335 SFX_REQUEST_ARG( rReq, pOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, false );
2336 if ( pOptions )
2337 aOptions = pOptions->GetValue();
2338 SFX_REQUEST_ARG( rReq, pRefresh, SfxUInt32Item, FN_PARAM_2, false );
2339 if ( pRefresh )
2340 nRefresh = pRefresh->GetValue();
2342 else
2344 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2345 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2347 delete pImpl->m_pLinkedDlg;
2348 pImpl->m_pLinkedDlg =
2349 pFact->CreateScLinkedAreaDlg(pTabViewShell->GetDialogParent());
2350 OSL_ENSURE(pImpl->m_pLinkedDlg, "Dialog create fail!");
2351 delete pImpl->m_pRequest;
2352 pImpl->m_pRequest = new SfxRequest( rReq );
2353 pImpl->m_pLinkedDlg->StartExecuteModal( LINK( this, ScCellShell, DialogClosed ) );
2354 return;
2357 ExecuteExternalSource( aFile, aFilter, aOptions, aSource, nRefresh, rReq );
2359 break;
2365 default:
2366 OSL_FAIL("incorrect slot in ExecuteEdit");
2367 break;
2371 void ScCellShell::ExecuteTrans( SfxRequest& rReq )
2373 sal_Int32 nType = ScViewUtil::GetTransliterationType( rReq.GetSlot() );
2374 if ( nType )
2376 GetViewData()->GetView()->TransliterateText( nType );
2377 rReq.Done();
2381 void ScCellShell::ExecuteRotateTrans( SfxRequest& rReq )
2383 if( rReq.GetSlot() == SID_TRANSLITERATE_ROTATE_CASE )
2384 GetViewData()->GetView()->TransliterateText( m_aRotateCase.getNextMode() );
2387 void ScCellShell::ExecuteExternalSource(
2388 const String& _rFile, const String& _rFilter, const String& _rOptions,
2389 const String& _rSource, sal_uLong _nRefresh, SfxRequest& _rRequest )
2391 if ( _rFile.Len() && _rSource.Len() ) // filter may be empty
2393 ScRange aLinkRange;
2394 sal_Bool bMove = false;
2396 ScViewData* pData = GetViewData();
2397 ScMarkData& rMark = pData->GetMarkData();
2398 rMark.MarkToSimple();
2399 if ( rMark.IsMarked() )
2401 rMark.GetMarkArea( aLinkRange );
2402 bMove = sal_True; // insert/delete cells to fit range
2404 else
2405 aLinkRange = ScRange( pData->GetCurX(), pData->GetCurY(), pData->GetTabNo() );
2407 pData->GetDocFunc().InsertAreaLink( _rFile, _rFilter, _rOptions, _rSource,
2408 aLinkRange, _nRefresh, bMove, false );
2409 _rRequest.Done();
2411 else
2412 _rRequest.Ignore();
2415 namespace {
2417 bool isDPSourceValid(const ScDPObject& rDPObj)
2419 if (rDPObj.IsImportData())
2421 // If the data type is database, check if the database is still valid.
2422 const ScImportSourceDesc* pDesc = rDPObj.GetImportSourceDesc();
2423 if (!pDesc)
2424 return false;
2426 const ScDPSaveData* pSaveData = rDPObj.GetSaveData();
2427 const ScDPDimensionSaveData* pDimData = NULL;
2428 if (pSaveData)
2429 pDimData = pSaveData->GetExistingDimensionData();
2431 const ScDPCache* pCache = pDesc->CreateCache(pDimData);
2432 if (!pCache)
2433 // cashe creation failed, probably due to invalid connection.
2434 return false;
2436 return true;
2441 void ScCellShell::ExecuteDataPilotDialog()
2443 ScModule* pScMod = SC_MOD();
2444 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2445 ScViewData* pData = GetViewData();
2446 ScDocument* pDoc = pData->GetDocument();
2448 ::boost::scoped_ptr<ScDPObject> pNewDPObject(NULL);
2450 // ScPivot is no longer used...
2451 ScDPObject* pDPObj = pDoc->GetDPAtCursor(
2452 pData->GetCurX(), pData->GetCurY(),
2453 pData->GetTabNo() );
2454 if ( pDPObj ) // on an existing table?
2456 if (isDPSourceValid(*pDPObj))
2457 pNewDPObject.reset(new ScDPObject(*pDPObj));
2459 else // create new table
2461 sal_uLong nSrcErrorId = 0;
2463 // select database range or data
2464 pTabViewShell->GetDBData( true, SC_DB_OLD );
2465 ScMarkData& rMark = GetViewData()->GetMarkData();
2466 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
2467 pTabViewShell->MarkDataArea( false );
2469 // output to cursor position for non-sheet data
2470 ScAddress aDestPos( pData->GetCurX(), pData->GetCurY(),
2471 pData->GetTabNo() );
2473 // first select type of source data
2475 bool bEnableExt = ScDPObject::HasRegisteredSources();
2477 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2478 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2480 ::boost::scoped_ptr<AbstractScDataPilotSourceTypeDlg> pTypeDlg(
2481 pFact->CreateScDataPilotSourceTypeDlg(
2482 pTabViewShell->GetDialogParent(), bEnableExt));
2484 // Populate named ranges (if any).
2485 ScRangeName* pRangeName = pDoc->GetRangeName();
2486 if (pRangeName)
2488 ScRangeName::const_iterator itr = pRangeName->begin(), itrEnd = pRangeName->end();
2489 for (; itr != itrEnd; ++itr)
2490 pTypeDlg->AppendNamedRange(itr->second->GetName());
2493 OSL_ENSURE(pTypeDlg, "Dialog create fail!");
2494 if ( pTypeDlg->Execute() == RET_OK )
2496 if ( pTypeDlg->IsExternal() )
2498 uno::Sequence<OUString> aSources = ScDPObject::GetRegisteredSources();
2499 ::boost::scoped_ptr<AbstractScDataPilotServiceDlg> pServDlg(
2500 pFact->CreateScDataPilotServiceDlg(
2501 pTabViewShell->GetDialogParent(), aSources, RID_SCDLG_DAPISERVICE));
2503 OSL_ENSURE(pServDlg, "Dialog create fail!");
2504 if ( pServDlg->Execute() == RET_OK )
2506 ScDPServiceDesc aServDesc(
2507 pServDlg->GetServiceName(),
2508 pServDlg->GetParSource(),
2509 pServDlg->GetParName(),
2510 pServDlg->GetParUser(),
2511 pServDlg->GetParPass() );
2512 pNewDPObject.reset(new ScDPObject(pDoc));
2513 pNewDPObject->SetServiceData( aServDesc );
2516 else if ( pTypeDlg->IsDatabase() )
2518 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2520 ::boost::scoped_ptr<AbstractScDataPilotDatabaseDlg> pDataDlg(
2521 pFact->CreateScDataPilotDatabaseDlg(
2522 pTabViewShell->GetDialogParent(), RID_SCDLG_DAPIDATA));
2524 OSL_ENSURE(pDataDlg, "Dialog create fail!");
2525 if ( pDataDlg->Execute() == RET_OK )
2527 ScImportSourceDesc aImpDesc(pDoc);
2528 pDataDlg->GetValues( aImpDesc );
2529 pNewDPObject.reset(new ScDPObject(pDoc));
2530 pNewDPObject->SetImportDesc( aImpDesc );
2533 else if (pTypeDlg->IsNamedRange())
2535 OUString aName = pTypeDlg->GetSelectedNamedRange();
2536 ScSheetSourceDesc aShtDesc(pDoc);
2537 aShtDesc.SetRangeName(aName);
2538 nSrcErrorId = aShtDesc.CheckSourceRange();
2539 if (!nSrcErrorId)
2541 pNewDPObject.reset(new ScDPObject(pDoc));
2542 pNewDPObject->SetSheetDesc(aShtDesc);
2545 else // selection
2547 //! use database ranges (select before type dialog?)
2548 ScRange aRange;
2549 ScMarkType eType = GetViewData()->GetSimpleArea(aRange);
2550 if ( (eType & SC_MARK_SIMPLE) == SC_MARK_SIMPLE )
2552 // Shrink the range to the data area.
2553 SCCOL nStartCol = aRange.aStart.Col(), nEndCol = aRange.aEnd.Col();
2554 SCROW nStartRow = aRange.aStart.Row(), nEndRow = aRange.aEnd.Row();
2555 if (pDoc->ShrinkToDataArea(aRange.aStart.Tab(), nStartCol, nStartRow, nEndCol, nEndRow))
2557 aRange.aStart.SetCol(nStartCol);
2558 aRange.aStart.SetRow(nStartRow);
2559 aRange.aEnd.SetCol(nEndCol);
2560 aRange.aEnd.SetRow(nEndRow);
2561 rMark.SetMarkArea(aRange);
2562 pTabViewShell->MarkRange(aRange);
2565 bool bOK = true;
2566 if ( pDoc->HasSubTotalCells( aRange ) )
2568 // confirm selection if it contains SubTotal cells
2570 QueryBox aBox( pTabViewShell->GetDialogParent(),
2571 WinBits(WB_YES_NO | WB_DEF_YES),
2572 ScGlobal::GetRscString(STR_DATAPILOT_SUBTOTAL) );
2573 if (aBox.Execute() == RET_NO)
2574 bOK = false;
2576 if (bOK)
2578 ScSheetSourceDesc aShtDesc(pDoc);
2579 aShtDesc.SetSourceRange(aRange);
2580 nSrcErrorId = aShtDesc.CheckSourceRange();
2581 if (!nSrcErrorId)
2583 pNewDPObject.reset(new ScDPObject(pDoc));
2584 pNewDPObject->SetSheetDesc( aShtDesc );
2587 // output below source data
2588 if ( aRange.aEnd.Row()+2 <= MAXROW - 4 )
2589 aDestPos = ScAddress( aRange.aStart.Col(),
2590 aRange.aEnd.Row()+2,
2591 aRange.aStart.Tab() );
2597 if (nSrcErrorId)
2599 // Error occurred during data creation. Launch an error and bail out.
2600 InfoBox aBox(pTabViewShell->GetDialogParent(), ScGlobal::GetRscString(nSrcErrorId));
2601 aBox.Execute();
2602 return;
2605 if ( pNewDPObject )
2606 pNewDPObject->SetOutRange( aDestPos );
2609 pTabViewShell->SetDialogDPObject( pNewDPObject.get() ); // is copied
2610 if ( pNewDPObject )
2612 // start layout dialog
2614 sal_uInt16 nId = ScPivotLayoutWrapper::GetChildWindowId();
2615 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
2616 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
2617 pScMod->SetRefDialog( nId, pWnd ? false : true );
2621 void ScCellShell::ExecuteXMLSourceDialog()
2623 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2624 if (!pFact)
2625 return;
2627 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2628 if (!pTabViewShell)
2629 return;
2631 ScModule* pScMod = SC_MOD();
2633 sal_uInt16 nId = ScXMLSourceDlgWrapper::GetChildWindowId();
2634 SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame();
2635 SfxChildWindow* pWnd = pViewFrame->GetChildWindow(nId);
2636 pScMod->SetRefDialog(nId, pWnd ? false : true);
2639 void ScCellShell::ExecuteSubtotals(SfxRequest& rReq)
2641 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2642 const SfxItemSet* pArgs = rReq.GetArgs();
2643 if ( pArgs )
2645 pTabViewShell->DoSubTotals( ((const ScSubTotalItem&) pArgs->Get( SCITEM_SUBTDATA )).
2646 GetSubTotalData() );
2647 rReq.Done();
2648 return;
2651 SfxAbstractTabDialog * pDlg = NULL;
2652 ScSubTotalParam aSubTotalParam;
2653 SfxItemSet aArgSet( GetPool(), SCITEM_SUBTDATA, SCITEM_SUBTDATA );
2655 // Only get existing named database range.
2656 ScDBData* pDBData = pTabViewShell->GetDBData(true, SC_DB_OLD);
2657 if (!pDBData)
2659 // No existing DB data at this position. Create an
2660 // anonymous DB.
2661 pDBData = pTabViewShell->GetAnonymousDBData();
2662 ScRange aDataRange;
2663 pDBData->GetArea(aDataRange);
2664 pTabViewShell->MarkRange(aDataRange, false);
2666 if (!pDBData)
2667 return;
2669 pDBData->GetSubTotalParam( aSubTotalParam );
2670 aSubTotalParam.bRemoveOnly = false;
2672 aArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA, GetViewData(), &aSubTotalParam ) );
2673 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2674 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2676 pDlg = pFact->CreateScSubTotalDlg( pTabViewShell->GetDialogParent(), &aArgSet, RID_SCDLG_SUBTOTALS );
2677 OSL_ENSURE(pDlg, "Dialog create fail!");
2678 pDlg->SetCurPageId(1);
2680 short bResult = pDlg->Execute();
2682 if ( (bResult == RET_OK) || (bResult == SCRET_REMOVE) )
2684 const SfxItemSet* pOutSet = NULL;
2686 if ( bResult == RET_OK )
2688 pOutSet = pDlg->GetOutputItemSet();
2689 aSubTotalParam =
2690 ((const ScSubTotalItem&)
2691 pOutSet->Get( SCITEM_SUBTDATA )).
2692 GetSubTotalData();
2694 else // if (bResult == SCRET_REMOVE)
2696 pOutSet = &aArgSet;
2697 aSubTotalParam.bRemoveOnly = sal_True;
2698 aSubTotalParam.bReplace = sal_True;
2699 aArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA,
2700 GetViewData(),
2701 &aSubTotalParam ) );
2704 pTabViewShell->DoSubTotals( aSubTotalParam );
2705 rReq.Done( *pOutSet );
2707 else
2708 GetViewData()->GetDocShell()->CancelAutoDBRange();
2710 delete pDlg;
2713 IMPL_LINK_NOARG(ScCellShell, DialogClosed)
2715 OSL_ENSURE( pImpl->m_pLinkedDlg, "ScCellShell::DialogClosed(): invalid request" );
2716 OSL_ENSURE( pImpl->m_pRequest, "ScCellShell::DialogClosed(): invalid request" );
2717 String sFile, sFilter, sOptions, sSource;
2718 sal_uLong nRefresh = 0;
2720 if ( pImpl->m_pLinkedDlg->GetResult() == RET_OK )
2722 sFile = pImpl->m_pLinkedDlg->GetURL();
2723 sFilter = pImpl->m_pLinkedDlg->GetFilter();
2724 sOptions = pImpl->m_pLinkedDlg->GetOptions();
2725 sSource = pImpl->m_pLinkedDlg->GetSource();
2726 nRefresh = pImpl->m_pLinkedDlg->GetRefresh();
2727 if ( sFile.Len() )
2728 pImpl->m_pRequest->AppendItem( SfxStringItem( SID_FILE_NAME, sFile ) );
2729 if ( sFilter.Len() )
2730 pImpl->m_pRequest->AppendItem( SfxStringItem( SID_FILTER_NAME, sFilter ) );
2731 if ( sOptions.Len() )
2732 pImpl->m_pRequest->AppendItem( SfxStringItem( SID_FILE_FILTEROPTIONS, sOptions ) );
2733 if ( sSource.Len() )
2734 pImpl->m_pRequest->AppendItem( SfxStringItem( FN_PARAM_1, sSource ) );
2735 if ( nRefresh )
2736 pImpl->m_pRequest->AppendItem( SfxUInt32Item( FN_PARAM_2, nRefresh ) );
2739 ExecuteExternalSource( sFile, sFilter, sOptions, sSource, nRefresh, *(pImpl->m_pRequest) );
2740 return 0;
2743 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */