Bump version to 4.3-4
[LibreOffice.git] / sc / source / ui / view / cellsh1.cxx
blob9ca1e1a4a4b6dc627cd3626f226b315bf4bdee3d
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"
64 #include "spellparam.hxx"
65 #include "postit.hxx"
66 #include "clipparam.hxx"
67 #include "pivot.hxx"
68 #include "dpsdbtab.hxx"
69 #include "dpshttab.hxx"
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"
82 #include <tokenstringcontext.hxx>
83 #include <cellvalue.hxx>
84 #include <tokenarray.hxx>
85 #include <formulacell.hxx>
86 #include <gridwin.hxx>
87 #include <searchresults.hxx>
89 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
90 #include <com/sun/star/lang/XInitialization.hpp>
91 #include <com/sun/star/beans/PropertyValue.hpp>
92 #include <com/sun/star/beans/XPropertySet.hpp>
93 #include <cppuhelper/bootstrap.hxx>
94 #include <com/sun/star/i18n/TransliterationModules.hpp>
95 #include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
97 #include <boost/scoped_ptr.hpp>
99 using namespace ::com::sun::star;
100 using namespace ::com::sun::star::beans;
101 using namespace ::com::sun::star::uno;
104 void ScCellShell::ExecuteEdit( SfxRequest& rReq )
106 ScModule* pScMod = SC_MOD();
107 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
108 SfxBindings& rBindings = pTabViewShell->GetViewFrame()->GetBindings();
109 const SfxItemSet* pReqArgs = rReq.GetArgs();
110 sal_uInt16 nSlot = rReq.GetSlot();
112 pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
114 // finish input
115 if ( GetViewData()->HasEditView( GetViewData()->GetActivePart() ) )
117 switch ( nSlot )
119 case FID_DEFINE_NAME:
120 case FID_ADD_NAME:
121 case FID_USE_NAME:
122 case FID_INSERT_NAME:
123 case SID_SPELL_DIALOG:
124 case SID_HANGUL_HANJA_CONVERSION:
125 case SID_OPENDLG_CONDFRMT:
126 case SID_OPENDLG_COLORSCALE:
127 case SID_OPENDLG_DATABAR:
129 pScMod->InputEnterHandler();
130 pTabViewShell->UpdateInputHandler();
131 break;
133 default:
134 break;
138 switch ( nSlot )
141 // insert / delete cells / rows / columns
144 case FID_INS_ROW:
145 pTabViewShell->InsertCells(INS_INSROWS);
146 rReq.Done();
147 break;
149 case FID_INS_COLUMN:
150 pTabViewShell->InsertCells(INS_INSCOLS);
151 rReq.Done();
152 break;
154 case FID_INS_CELLSDOWN:
155 pTabViewShell->InsertCells(INS_CELLSDOWN);
156 rReq.Done();
157 break;
159 case FID_INS_CELLSRIGHT:
160 pTabViewShell->InsertCells(INS_CELLSRIGHT);
161 rReq.Done();
162 break;
164 case SID_DEL_ROWS:
165 pTabViewShell->DeleteCells( DEL_DELROWS );
166 rReq.Done();
167 break;
169 case SID_DEL_COLS:
170 pTabViewShell->DeleteCells( DEL_DELCOLS );
171 rReq.Done();
172 break;
174 case FID_INS_CELL:
176 InsCellCmd eCmd=INS_NONE;
178 if ( pReqArgs )
180 const SfxPoolItem* pItem;
181 OUString aFlags;
183 if( pReqArgs->HasItem( FID_INS_CELL, &pItem ) )
184 aFlags = ((const SfxStringItem*)pItem)->GetValue();
185 if( !aFlags.isEmpty() )
187 switch( aFlags[0] )
189 case 'V': eCmd = INS_CELLSDOWN ;break;
190 case '>': eCmd = INS_CELLSRIGHT ;break;
191 case 'R': eCmd = INS_INSROWS ;break;
192 case 'C': eCmd = INS_INSCOLS ;break;
196 else
198 if ( GetViewData()->SimpleColMarked() )
199 eCmd = INS_INSCOLS;
200 else if ( GetViewData()->SimpleRowMarked() )
201 eCmd = INS_INSROWS;
202 else
204 ScDocument* pDoc = GetViewData()->GetDocument();
205 bool bTheFlag=(pDoc->GetChangeTrack()!=NULL);
207 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
208 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
210 boost::scoped_ptr<AbstractScInsertCellDlg> pDlg(pFact->CreateScInsertCellDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_INSCELL, bTheFlag));
211 OSL_ENSURE(pDlg, "Dialog create fail!");
212 if (pDlg->Execute() == RET_OK)
213 eCmd = pDlg->GetInsCellCmd();
217 if (eCmd!=INS_NONE)
219 pTabViewShell->InsertCells( eCmd );
221 if( ! rReq.IsAPI() )
223 OUString aParam;
225 switch( eCmd )
227 case INS_CELLSDOWN: aParam = "V"; break;
228 case INS_CELLSRIGHT: aParam = ">"; break;
229 case INS_INSROWS: aParam = "R"; break;
230 case INS_INSCOLS: aParam = "C"; break;
231 default:
233 // added to avoid warnings
236 rReq.AppendItem( SfxStringItem( FID_INS_CELL, aParam ) );
237 rReq.Done();
241 break;
243 case FID_DELETE_CELL:
245 DelCellCmd eCmd = DEL_NONE;
247 if ( pReqArgs )
249 const SfxPoolItem* pItem;
250 OUString aFlags;
252 if( pReqArgs->HasItem( FID_DELETE_CELL, &pItem ) )
253 aFlags = ((const SfxStringItem*)pItem)->GetValue();
254 if( !aFlags.isEmpty() )
256 switch( aFlags[0] )
258 case 'U': eCmd = DEL_CELLSUP ;break;
259 case 'L': eCmd = DEL_CELLSLEFT ;break;
260 case 'R': eCmd = DEL_DELROWS ;break;
261 case 'C': eCmd = DEL_DELCOLS ;break;
265 else
267 if ( GetViewData()->SimpleColMarked() )
268 eCmd = DEL_DELCOLS;
269 else if ( GetViewData()->SimpleRowMarked() )
270 eCmd = DEL_DELROWS;
271 else
273 ScRange aRange;
274 ScDocument* pDoc = GetViewData()->GetDocument();
275 bool bTheFlag=GetViewData()->IsMultiMarked() ||
276 (GetViewData()->GetSimpleArea(aRange) == SC_MARK_SIMPLE_FILTERED) ||
277 (pDoc->GetChangeTrack() != NULL);
279 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
280 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
282 boost::scoped_ptr<AbstractScDeleteCellDlg> pDlg(pFact->CreateScDeleteCellDlg( pTabViewShell->GetDialogParent(), bTheFlag ));
283 OSL_ENSURE(pDlg, "Dialog create fail!");
285 if (pDlg->Execute() == RET_OK)
286 eCmd = pDlg->GetDelCellCmd();
290 if (eCmd != DEL_NONE )
292 pTabViewShell->DeleteCells( eCmd );
294 if( ! rReq.IsAPI() )
296 OUString aParam;
298 switch( eCmd )
300 case DEL_CELLSUP: aParam = "U"; break;
301 case DEL_CELLSLEFT: aParam = "L"; break;
302 case DEL_DELROWS: aParam = "R"; break;
303 case DEL_DELCOLS: aParam = "C"; break;
304 default:
306 // added to avoid warnings
309 rReq.AppendItem( SfxStringItem( FID_DELETE_CELL, aParam ) );
310 rReq.Done();
314 break;
317 // delete contents from cells
320 case SID_DELETE_CONTENTS:
321 pTabViewShell->DeleteContents( IDF_CONTENTS );
322 rReq.Done();
323 break;
325 case SID_DELETE:
327 sal_uInt16 nFlags = IDF_NONE;
329 if ( pReqArgs!=NULL && pTabViewShell->SelectionEditable() )
331 const SfxPoolItem* pItem;
332 OUString aFlags('A');
334 if( pReqArgs->HasItem( SID_DELETE, &pItem ) )
335 aFlags = ((const SfxStringItem*)pItem)->GetValue();
337 aFlags = aFlags.toAsciiUpperCase();
338 bool bCont = true;
340 for (sal_Int32 i=0 ; bCont && i<aFlags.getLength(); ++i)
342 switch (aFlags[i])
344 case 'A': // all
345 nFlags |= IDF_ALL;
346 bCont = false; // don't continue!
347 break;
348 case 'S': nFlags |= IDF_STRING; break;
349 case 'V': nFlags |= IDF_VALUE; break;
350 case 'D': nFlags |= IDF_DATETIME; break;
351 case 'F': nFlags |= IDF_FORMULA; break;
352 case 'N': nFlags |= IDF_NOTE; break;
353 case 'T': nFlags |= IDF_ATTRIB; break;
354 case 'O': nFlags |= IDF_OBJECTS; break;
358 else
360 ScEditableTester aTester( pTabViewShell );
361 if (aTester.IsEditable())
363 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
364 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
366 boost::scoped_ptr<AbstractScDeleteContentsDlg> pDlg(pFact->CreateScDeleteContentsDlg(pTabViewShell->GetDialogParent()));
367 OSL_ENSURE(pDlg, "Dialog create fail!");
368 ScDocument* pDoc = GetViewData()->GetDocument();
369 SCTAB nTab = GetViewData()->GetTabNo();
370 if ( pDoc->IsTabProtected(nTab) )
371 pDlg->DisableObjects();
372 if (pDlg->Execute() == RET_OK)
374 nFlags = pDlg->GetDelContentsCmdBits();
377 else
378 pTabViewShell->ErrorMessage(aTester.GetMessageId());
381 if( nFlags != IDF_NONE )
383 pTabViewShell->DeleteContents( nFlags );
385 if( ! rReq.IsAPI() )
387 OUString aFlags;
389 if( nFlags == IDF_ALL )
391 aFlags += "A";
393 else
395 if( nFlags & IDF_STRING ) aFlags += "S";
396 if( nFlags & IDF_VALUE ) aFlags += "V";
397 if( nFlags & IDF_DATETIME ) aFlags += "D";
398 if( nFlags & IDF_FORMULA ) aFlags += "F";
399 if( nFlags & IDF_NOTE ) aFlags += "N";
400 if( nFlags & IDF_ATTRIB ) aFlags += "T";
401 if( nFlags & IDF_OBJECTS ) aFlags += "O";
404 rReq.AppendItem( SfxStringItem( SID_DELETE, aFlags ) );
405 rReq.Done();
409 break;
412 // fill...
415 case FID_FILL_TO_BOTTOM:
416 pTabViewShell->FillSimple( FILL_TO_BOTTOM );
417 rReq.Done();
418 break;
420 case FID_FILL_TO_RIGHT:
421 pTabViewShell->FillSimple( FILL_TO_RIGHT );
422 rReq.Done();
423 break;
425 case FID_FILL_TO_TOP:
426 pTabViewShell->FillSimple( FILL_TO_TOP );
427 rReq.Done();
428 break;
430 case FID_FILL_TO_LEFT:
431 pTabViewShell->FillSimple( FILL_TO_LEFT );
432 rReq.Done();
433 break;
435 case FID_FILL_TAB:
437 sal_uInt16 nFlags = IDF_NONE;
438 sal_uInt16 nFunction = PASTE_NOFUNC;
439 bool bSkipEmpty = false;
440 bool bAsLink = false;
442 if ( pReqArgs!=NULL && pTabViewShell->SelectionEditable() )
444 const SfxPoolItem* pItem;
445 OUString aFlags('A');
447 if( pReqArgs->HasItem( FID_FILL_TAB, &pItem ) )
448 aFlags = ((const SfxStringItem*)pItem)->GetValue();
450 aFlags = aFlags.toAsciiUpperCase();
451 bool bCont = true;
453 for (sal_Int32 i=0; bCont && i < aFlags.getLength(); ++i)
455 switch (aFlags[i])
457 case 'A': // all
458 nFlags |= IDF_ALL;
459 bCont = false; // don't continue!
460 break;
461 case 'S': nFlags |= IDF_STRING; break;
462 case 'V': nFlags |= IDF_VALUE; break;
463 case 'D': nFlags |= IDF_DATETIME; break;
464 case 'F': nFlags |= IDF_FORMULA; break;
465 case 'N': nFlags |= IDF_NOTE; break;
466 case 'T': nFlags |= IDF_ATTRIB; break;
470 else
472 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
473 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
475 boost::scoped_ptr<AbstractScInsertContentsDlg> pDlg(pFact->CreateScInsertContentsDlg( pTabViewShell->GetDialogParent(),
476 0, /* nCheckDefaults */
477 &ScGlobal::GetRscString(STR_FILL_TAB)));
478 OSL_ENSURE(pDlg, "Dialog create fail!");
479 pDlg->SetFillMode(true);
481 if (pDlg->Execute() == RET_OK)
483 nFlags = pDlg->GetInsContentsCmdBits();
484 nFunction = pDlg->GetFormulaCmdBits();
485 bSkipEmpty = pDlg->IsSkipEmptyCells();
486 bAsLink = pDlg->IsLink();
487 // there is no MoveMode with fill tabs
491 if( nFlags != IDF_NONE )
493 pTabViewShell->FillTab( nFlags, nFunction, bSkipEmpty, bAsLink );
495 if( ! rReq.IsAPI() )
497 OUString aFlags;
499 if( nFlags == IDF_ALL )
501 aFlags += "A";
503 else
505 if( nFlags & IDF_STRING ) aFlags += "S";
506 if( nFlags & IDF_VALUE ) aFlags += "V";
507 if( nFlags & IDF_DATETIME ) aFlags += "D";
508 if( nFlags & IDF_FORMULA ) aFlags += "F";
509 if( nFlags & IDF_NOTE ) aFlags += "N";
510 if( nFlags & IDF_ATTRIB ) aFlags += "T";
513 rReq.AppendItem( SfxStringItem( FID_FILL_TAB, aFlags ) );
514 rReq.Done();
518 break;
520 case FID_FILL_SERIES:
522 SCCOL nStartCol;
523 SCROW nStartRow;
524 SCTAB nStartTab;
525 SCCOL nEndCol;
526 SCROW nEndRow;
527 SCTAB nEndTab;
528 sal_uInt16 nPossDir = FDS_OPT_NONE;
529 FillDir eFillDir = FILL_TO_BOTTOM;
530 FillCmd eFillCmd = FILL_LINEAR;
531 FillDateCmd eFillDateCmd = FILL_DAY;
532 double fStartVal = MAXDOUBLE;
533 double fIncVal = 1;
534 double fMaxVal = MAXDOUBLE;
535 bool bDoIt = false;
537 GetViewData()->GetSimpleArea( nStartCol, nStartRow, nStartTab,
538 nEndCol, nEndRow, nEndTab );
540 if( nStartCol!=nEndCol )
542 nPossDir |= FDS_OPT_HORZ;
543 eFillDir=FILL_TO_RIGHT;
546 if( nStartRow!=nEndRow )
548 nPossDir |= FDS_OPT_VERT;
549 eFillDir=FILL_TO_BOTTOM;
552 ScDocument* pDoc = GetViewData()->GetDocument();
553 SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
555 if( pReqArgs )
557 const SfxPoolItem* pItem;
558 OUString aFillDir, aFillCmd, aFillDateCmd;
559 OUString aFillStep, aFillStart, aFillMax;
560 sal_uInt32 nKey;
561 double fTmpVal;
563 bDoIt=false;
565 if( pReqArgs->HasItem( FID_FILL_SERIES, &pItem ) )
566 aFillDir = ((const SfxStringItem*)pItem)->GetValue();
567 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
568 aFillCmd = ((const SfxStringItem*)pItem)->GetValue();
569 if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
570 aFillDateCmd = ((const SfxStringItem*)pItem)->GetValue();
571 if( pReqArgs->HasItem( FN_PARAM_3, &pItem ) )
572 aFillStep = ((const SfxStringItem*)pItem)->GetValue();
573 if( pReqArgs->HasItem( FN_PARAM_4, &pItem ) )
574 aFillStart = ((const SfxStringItem*)pItem)->GetValue();
575 if( pReqArgs->HasItem( FN_PARAM_5, &pItem ) )
576 aFillMax = ((const SfxStringItem*)pItem)->GetValue();
578 if( !aFillDir.isEmpty() )
579 switch( aFillDir[0] )
581 case 'B': case 'b': eFillDir=FILL_TO_BOTTOM; break;
582 case 'R': case 'r': eFillDir=FILL_TO_RIGHT; break;
583 case 'T': case 't': eFillDir=FILL_TO_TOP; break;
584 case 'L': case 'l': eFillDir=FILL_TO_LEFT; break;
587 if( !aFillCmd.isEmpty() )
588 switch( aFillCmd[0] )
590 case 'S': case 's': eFillCmd=FILL_SIMPLE; break;
591 case 'L': case 'l': eFillCmd=FILL_LINEAR; break;
592 case 'G': case 'g': eFillCmd=FILL_GROWTH; break;
593 case 'D': case 'd': eFillCmd=FILL_DATE; break;
594 case 'A': case 'a': eFillCmd=FILL_AUTO; break;
597 if( !aFillDateCmd.isEmpty() )
598 switch( aFillDateCmd[0] )
600 case 'D': case 'd': eFillDateCmd=FILL_DAY; break;
601 case 'W': case 'w': eFillDateCmd=FILL_WEEKDAY; break;
602 case 'M': case 'm': eFillDateCmd=FILL_MONTH; break;
603 case 'Y': case 'y': eFillDateCmd=FILL_YEAR; break;
606 nKey = 0;
607 if( pFormatter->IsNumberFormat( aFillStart, nKey, fTmpVal ))
608 fStartVal = fTmpVal;
610 nKey = 0;
611 if( pFormatter->IsNumberFormat( aFillStep, nKey, fTmpVal ))
612 fIncVal = fTmpVal;
614 nKey = 0;
615 if( pFormatter->IsNumberFormat( aFillMax, nKey, fTmpVal ))
616 fMaxVal = fTmpVal;
618 bDoIt = true;
621 else // (pReqArgs == NULL) => raise Dialog
623 sal_uInt32 nPrivFormat;
624 CellType eCellType;
625 pDoc->GetNumberFormat( nStartCol, nStartRow, nStartTab, nPrivFormat );
626 pDoc->GetCellType( nStartCol, nStartRow, nStartTab,eCellType );
627 const SvNumberformat* pPrivEntry = pFormatter->GetEntry( nPrivFormat );
628 if (!pPrivEntry)
630 OSL_FAIL("Numberformat not found !!!");
632 else
634 short nPrivType = pPrivEntry->GetType();
635 if ( ( nPrivType & NUMBERFORMAT_DATE)>0)
637 eFillCmd=FILL_DATE;
639 else if(eCellType==CELLTYPE_STRING)
641 eFillCmd=FILL_AUTO;
646 OUString aStartStr;
648 // suggest default Startvalue only, when just 1 row or column
649 if ( nStartCol == nEndCol || nStartRow == nEndRow )
651 double fInputEndVal = 0.0;
652 OUString aEndStr;
654 pDoc->GetInputString( nStartCol, nStartRow, nStartTab, aStartStr);
655 pDoc->GetValue( nStartCol, nStartRow, nStartTab, fStartVal );
658 if(eFillDir==FILL_TO_BOTTOM && nStartRow < nEndRow )
660 pDoc->GetInputString( nStartCol, nStartRow+1, nStartTab, aEndStr);
661 if(!aEndStr.isEmpty())
663 pDoc->GetValue( nStartCol, nStartRow+1, nStartTab, fInputEndVal);
664 fIncVal=fInputEndVal-fStartVal;
667 else
669 if(nStartCol < nEndCol)
671 pDoc->GetInputString( nStartCol+1, nStartRow, nStartTab, aEndStr);
672 if(!aEndStr.isEmpty())
674 pDoc->GetValue( nStartCol+1, nStartRow, nStartTab, fInputEndVal);
675 fIncVal=fInputEndVal-fStartVal;
679 if(eFillCmd==FILL_DATE)
681 Date aNullDate = *pDoc->GetFormatTable()->GetNullDate();
682 Date aStartDate = aNullDate;
683 aStartDate+= (long)fStartVal;
684 Date aEndDate = aNullDate;
685 aEndDate+= (long)fInputEndVal;
686 double fTempDate=0;
688 if(aStartDate.GetYear()!=aEndDate.GetYear())
690 eFillDateCmd = FILL_YEAR;
691 fTempDate=aEndDate.GetYear()-aStartDate.GetYear();
693 if(aStartDate.GetMonth()!=aEndDate.GetMonth())
695 eFillDateCmd = FILL_MONTH;
696 fTempDate=fTempDate*12+aEndDate.GetMonth()-aStartDate.GetMonth();
698 if(aStartDate.GetDay()==aEndDate.GetDay())
700 fIncVal=fTempDate;
704 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
705 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
707 boost::scoped_ptr<AbstractScFillSeriesDlg> pDlg(pFact->CreateScFillSeriesDlg( pTabViewShell->GetDialogParent(),
708 *pDoc,
709 eFillDir, eFillCmd, eFillDateCmd,
710 aStartStr, fIncVal, fMaxVal,
711 nPossDir));
712 OSL_ENSURE(pDlg, "Dialog create fail!");
714 if ( nStartCol != nEndCol && nStartRow != nEndRow )
716 pDlg->SetEdStartValEnabled(false);
719 if ( pDlg->Execute() == RET_OK )
721 eFillDir = pDlg->GetFillDir();
722 eFillCmd = pDlg->GetFillCmd();
723 eFillDateCmd = pDlg->GetFillDateCmd();
725 if(eFillCmd==FILL_AUTO)
727 OUString aStr = pDlg->GetStartStr();
728 if(!aStr.isEmpty())
729 pTabViewShell->EnterData( nStartCol, nStartRow, nStartTab, aStr );
731 fStartVal = pDlg->GetStart();
732 fIncVal = pDlg->GetStep();
733 fMaxVal = pDlg->GetMax();
734 bDoIt = true;
738 if( bDoIt )
740 //nScFillModeMouseModifier = 0; // no Ctrl/Copy
741 pTabViewShell->FillSeries( eFillDir, eFillCmd, eFillDateCmd, fStartVal, fIncVal, fMaxVal );
743 if( ! rReq.IsAPI() )
745 OUString 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: 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: 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: 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 OUString 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 ScAddress aAdr( nFillCol, nFillRow, 0 );
890 OUString aAdrStr(aAdr.Format(SCR_ABS, pDoc, pDoc->GetAddressConvention()));
892 rReq.AppendItem( SfxStringItem( FID_FILL_AUTO, aAdrStr ) );
893 rReq.Done();
898 else
900 OSL_FAIL( "Direction not unique for autofill" );
904 break;
905 case FID_FILL_SINGLE_EDIT:
906 ExecuteFillSingleEdit();
907 break;
908 case SID_RANDOM_NUMBER_GENERATOR_DIALOG:
910 sal_uInt16 nId = ScRandomNumberGeneratorDialogWrapper::GetChildWindowId();
911 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
912 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
914 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
917 break;
918 case SID_SAMPLING_DIALOG:
920 sal_uInt16 nId = ScSamplingDialogWrapper::GetChildWindowId();
921 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
922 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
924 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
926 break;
927 case SID_DESCRIPTIVE_STATISTICS_DIALOG:
929 sal_uInt16 nId = ScDescriptiveStatisticsDialogWrapper::GetChildWindowId();
930 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
931 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
933 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
935 break;
936 case SID_ANALYSIS_OF_VARIANCE_DIALOG:
938 sal_uInt16 nId = ScAnalysisOfVarianceDialogWrapper::GetChildWindowId();
939 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
940 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
942 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
944 break;
945 case SID_CORRELATION_DIALOG:
947 sal_uInt16 nId = ScCorrelationDialogWrapper::GetChildWindowId();
948 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
949 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
951 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
953 break;
954 case SID_COVARIANCE_DIALOG:
956 sal_uInt16 nId = ScCovarianceDialogWrapper::GetChildWindowId();
957 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
958 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
960 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
962 break;
963 case SID_EXPONENTIAL_SMOOTHING_DIALOG:
965 sal_uInt16 nId = ScExponentialSmoothingDialogWrapper::GetChildWindowId();
966 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
967 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
969 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
971 break;
972 case SID_MOVING_AVERAGE_DIALOG:
974 sal_uInt16 nId = ScMovingAverageDialogWrapper::GetChildWindowId();
975 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
976 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
978 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
980 break;
981 case SID_TTEST_DIALOG:
983 sal_uInt16 nId = ScTTestDialogWrapper::GetChildWindowId();
984 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
985 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
987 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
990 break;
991 case SID_FTEST_DIALOG:
993 sal_uInt16 nId = ScFTestDialogWrapper::GetChildWindowId();
994 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
995 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
997 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
1000 break;
1002 case SID_SEARCH_RESULTS_DIALOG:
1004 const SfxPoolItem* pItem = NULL;
1005 if (pReqArgs->HasItem(SID_SEARCH_RESULTS_DIALOG, &pItem))
1007 bool bVisible = static_cast<const SfxBoolItem*>(pItem)->GetValue();
1008 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1009 // The window ID should equal the slot ID, but not a biggie if it wasn't.
1010 sal_uInt16 nId = sc::SearchResultsDlgWrapper::GetChildWindowId();
1011 pViewFrm->SetChildWindow(nId, bVisible, false);
1013 rReq.Done();
1015 break;
1017 // disposal (Outlines)
1018 // SID_AUTO_OUTLINE, SID_OUTLINE_DELETEALL in Execute (in docsh.idl)
1021 case SID_OUTLINE_HIDE:
1022 if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
1023 GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
1024 pTabViewShell->SetDataPilotDetails( false );
1025 else
1026 pTabViewShell->HideMarkedOutlines();
1027 rReq.Done();
1028 break;
1030 case SID_OUTLINE_SHOW:
1032 ScDPObject* pDPObj = GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
1033 GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
1034 if ( pDPObj )
1036 Sequence<sheet::DataPilotFieldFilter> aFilters;
1037 sal_uInt16 nOrientation;
1038 if ( pTabViewShell->HasSelectionForDrillDown( nOrientation ) )
1040 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1041 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1043 AbstractScDPShowDetailDlg* pDlg = pFact->CreateScDPShowDetailDlg(
1044 pTabViewShell->GetDialogParent(), RID_SCDLG_DPSHOWDETAIL, *pDPObj, nOrientation );
1045 OSL_ENSURE(pDlg, "Dialog create fail!");
1046 if ( pDlg->Execute() == RET_OK )
1048 OUString aNewDimName( pDlg->GetDimensionName() );
1049 pTabViewShell->SetDataPilotDetails( true, &aNewDimName );
1052 else if ( !pDPObj->IsServiceData() &&
1053 pDPObj->GetDataFieldPositionData(
1054 ScAddress( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() ),
1055 aFilters ) )
1056 pTabViewShell->ShowDataPilotSourceData( *pDPObj, aFilters );
1057 else
1058 pTabViewShell->SetDataPilotDetails(true);
1060 else
1061 pTabViewShell->ShowMarkedOutlines();
1062 rReq.Done();
1064 break;
1066 case SID_OUTLINE_MAKE:
1068 bool bColumns = false;
1069 bool bOk = true;
1071 if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
1072 GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
1074 ScDPNumGroupInfo aNumInfo;
1075 aNumInfo.mbEnable = true;
1076 aNumInfo.mbAutoStart = true;
1077 aNumInfo.mbAutoEnd = true;
1078 sal_Int32 nParts = 0;
1079 if ( pTabViewShell->HasSelectionForDateGroup( aNumInfo, nParts ) )
1081 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1082 OSL_ENSURE( pFact, "ScAbstractFactory create fail!" );
1083 Date aNullDate( *GetViewData()->GetDocument()->GetFormatTable()->GetNullDate() );
1084 AbstractScDPDateGroupDlg* pDlg = pFact->CreateScDPDateGroupDlg(
1085 pTabViewShell->GetDialogParent(), RID_SCDLG_DPDATEGROUP,
1086 aNumInfo, nParts, aNullDate );
1087 OSL_ENSURE( pDlg, "Dialog create fail!" );
1088 if( pDlg->Execute() == RET_OK )
1090 aNumInfo = pDlg->GetGroupInfo();
1091 pTabViewShell->DateGroupDataPilot( aNumInfo, pDlg->GetDatePart() );
1094 else if ( pTabViewShell->HasSelectionForNumGroup( aNumInfo ) )
1096 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1097 OSL_ENSURE( pFact, "ScAbstractFactory create fail!" );
1098 AbstractScDPNumGroupDlg* pDlg = pFact->CreateScDPNumGroupDlg(
1099 pTabViewShell->GetDialogParent(), RID_SCDLG_DPNUMGROUP, aNumInfo );
1100 OSL_ENSURE( pDlg, "Dialog create fail!" );
1101 if( pDlg->Execute() == RET_OK )
1102 pTabViewShell->NumGroupDataPilot( pDlg->GetGroupInfo() );
1104 else
1105 pTabViewShell->GroupDataPilot();
1107 bOk = false;
1109 else if( pReqArgs != NULL )
1111 const SfxPoolItem* pItem;
1112 bOk = false;
1114 if( pReqArgs->HasItem( SID_OUTLINE_MAKE, &pItem ) )
1116 OUString aCol = ((const SfxStringItem*)pItem)->GetValue();
1117 aCol = aCol.toAsciiUpperCase();
1119 switch( aCol[0] )
1121 case 'R': bColumns=false; bOk = true;break;
1122 case 'C': bColumns=true; bOk = true;break;
1126 else // Dialog, when not whole rows/columns are marked
1128 if ( GetViewData()->SimpleColMarked() && !GetViewData()->SimpleRowMarked() )
1129 bColumns = true;
1130 else if ( !GetViewData()->SimpleColMarked() && GetViewData()->SimpleRowMarked() )
1131 bColumns = false;
1132 else
1134 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1135 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1137 boost::scoped_ptr<AbstractScGroupDlg> pDlg(pFact->CreateAbstractScGroupDlg(pTabViewShell->GetDialogParent(), false));
1138 OSL_ENSURE(pDlg, "Dialog create fail!");
1139 if ( pDlg->Execute() == RET_OK )
1140 bColumns = pDlg->GetColsChecked();
1141 else
1142 bOk = false;
1145 if (bOk)
1147 pTabViewShell->MakeOutline( bColumns );
1149 if( ! rReq.IsAPI() )
1151 OUString aCol = bColumns ? OUString('C') : OUString('R');
1152 rReq.AppendItem( SfxStringItem( SID_OUTLINE_MAKE, aCol ) );
1153 rReq.Done();
1157 break;
1159 case SID_OUTLINE_REMOVE:
1161 bool bColumns = false;
1162 bool bOk = true;
1164 if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
1165 GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
1167 pTabViewShell->UngroupDataPilot();
1168 bOk = false;
1170 else if( pReqArgs != NULL )
1172 const SfxPoolItem* pItem;
1173 bOk = false;
1175 if( pReqArgs->HasItem( SID_OUTLINE_REMOVE, &pItem ) )
1177 OUString aCol = ((const SfxStringItem*)pItem)->GetValue();
1178 aCol = aCol.toAsciiUpperCase();
1180 switch (aCol[0])
1182 case 'R': bColumns=false; bOk = true;break;
1183 case 'C': bColumns=true; bOk = true;break;
1187 else // Dialog only when removal for rows and columns is possible
1189 bool bColPoss, bRowPoss;
1190 pTabViewShell->TestRemoveOutline( bColPoss, bRowPoss );
1191 if ( bColPoss && bRowPoss )
1193 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1194 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1196 boost::scoped_ptr<AbstractScGroupDlg> pDlg(pFact->CreateAbstractScGroupDlg(pTabViewShell->GetDialogParent(), true));
1197 OSL_ENSURE(pDlg, "Dialog create fail!");
1198 if ( pDlg->Execute() == RET_OK )
1199 bColumns = pDlg->GetColsChecked();
1200 else
1201 bOk = false;
1203 else if ( bColPoss )
1204 bColumns = true;
1205 else if ( bRowPoss )
1206 bColumns = false;
1207 else
1208 bOk = false;
1210 if (bOk)
1212 pTabViewShell->RemoveOutline( bColumns );
1214 if( ! rReq.IsAPI() )
1216 OUString aCol = bColumns ? OUString('C') : OUString('R');
1217 rReq.AppendItem( SfxStringItem( SID_OUTLINE_REMOVE, aCol ) );
1218 rReq.Done();
1222 break;
1225 // Clipboard
1227 case SID_COPY: // for graphs in DrawShell
1229 WaitObject aWait( GetViewData()->GetDialogParent() );
1230 pTabViewShell->CopyToClip( NULL, false, false, true );
1231 rReq.Done();
1232 GetViewData()->SetPasteMode( (ScPasteFlags) (SC_PASTE_MODE | SC_PASTE_BORDER) );
1233 pTabViewShell->ShowCursor();
1234 pTabViewShell->UpdateCopySourceOverlay();
1236 break;
1238 case SID_CUT: // for graphs in DrawShell
1240 WaitObject aWait( GetViewData()->GetDialogParent() );
1241 pTabViewShell->CutToClip( NULL, true );
1242 rReq.Done();
1243 GetViewData()->SetPasteMode( (ScPasteFlags)(SC_PASTE_MODE | SC_PASTE_BORDER));
1244 pTabViewShell->ShowCursor();
1245 pTabViewShell->UpdateCopySourceOverlay();
1247 break;
1249 case SID_PASTE:
1251 ScClipUtil::PasteFromClipboard ( GetViewData(), pTabViewShell, true );
1252 rReq.Done();
1254 break;
1256 case SID_CLIPBOARD_FORMAT_ITEMS:
1258 WaitObject aWait( GetViewData()->GetDialogParent() );
1260 sal_uLong nFormat = 0;
1261 const SfxPoolItem* pItem;
1262 if ( pReqArgs &&
1263 pReqArgs->GetItemState(nSlot, true, &pItem) == SFX_ITEM_SET &&
1264 pItem->ISA(SfxUInt32Item) )
1266 nFormat = ((const SfxUInt32Item*)pItem)->GetValue();
1269 if ( nFormat )
1271 Window* pWin = GetViewData()->GetActiveWin();
1272 bool bCells = ( ScTransferObj::GetOwnClipboard( pWin ) != NULL );
1273 bool bDraw = ( ScDrawTransferObj::GetOwnClipboard( pWin ) != NULL );
1274 bool bOle = ( nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE );
1276 if ( bCells && bOle )
1277 pTabViewShell->PasteFromSystem();
1278 else if ( bDraw && bOle )
1279 pTabViewShell->PasteDraw();
1280 else
1281 pTabViewShell->PasteFromSystem(nFormat);
1283 //?else
1284 //? pTabViewShell->PasteFromSystem();
1286 rReq.Done();
1288 pTabViewShell->CellContentChanged();
1289 break;
1291 case FID_INS_CELL_CONTENTS:
1293 sal_uInt16 nFlags = IDF_NONE;
1294 sal_uInt16 nFunction = PASTE_NOFUNC;
1295 bool bSkipEmpty = false;
1296 bool bTranspose = false;
1297 bool bAsLink = false;
1298 InsCellCmd eMoveMode = INS_NONE;
1300 Window* pWin = GetViewData()->GetActiveWin();
1301 ScDocument* pDoc = GetViewData()->GetDocument();
1302 bool bOtherDoc = !pDoc->IsClipboardSource();
1303 ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin );
1304 if ( pOwnClip )
1306 // keep a reference in case the clipboard is changed during dialog or PasteFromClip
1307 uno::Reference<datatransfer::XTransferable> aOwnClipRef( pOwnClip );
1308 if ( pReqArgs!=NULL && pTabViewShell->SelectionEditable() )
1310 const SfxPoolItem* pItem;
1311 OUString aFlags('A');
1313 if( pReqArgs->HasItem( FID_INS_CELL_CONTENTS, &pItem ) )
1314 aFlags = ((const SfxStringItem*)pItem)->GetValue();
1316 aFlags = aFlags.toAsciiUpperCase();
1317 bool bCont = true;
1319 for (sal_Int32 i=0 ; bCont && i<aFlags.getLength(); ++i)
1321 switch (aFlags[i])
1323 case 'A': // all
1324 nFlags |= IDF_ALL;
1325 bCont = false; // don't continue!
1326 break;
1327 case 'S': nFlags |= IDF_STRING; break;
1328 case 'V': nFlags |= IDF_VALUE; break;
1329 case 'D': nFlags |= IDF_DATETIME; break;
1330 case 'F': nFlags |= IDF_FORMULA; break;
1331 case 'N': nFlags |= IDF_NOTE; break;
1332 case 'T': nFlags |= IDF_ATTRIB; break;
1336 SFX_REQUEST_ARG( rReq, pFuncItem, SfxUInt16Item, FN_PARAM_1, false );
1337 SFX_REQUEST_ARG( rReq, pSkipItem, SfxBoolItem, FN_PARAM_2, false );
1338 SFX_REQUEST_ARG( rReq, pTransposeItem, SfxBoolItem, FN_PARAM_3, false );
1339 SFX_REQUEST_ARG( rReq, pLinkItem, SfxBoolItem, FN_PARAM_4, false );
1340 SFX_REQUEST_ARG( rReq, pMoveItem, SfxInt16Item, FN_PARAM_5, false );
1341 if ( pFuncItem )
1342 nFunction = pFuncItem->GetValue();
1343 if ( pSkipItem )
1344 bSkipEmpty = pSkipItem->GetValue();
1345 if ( pTransposeItem )
1346 bTranspose = pTransposeItem->GetValue();
1347 if ( pLinkItem )
1348 bAsLink = pLinkItem->GetValue();
1349 if ( pMoveItem )
1350 eMoveMode = (InsCellCmd) pMoveItem->GetValue();
1352 else
1354 ScEditableTester aTester( pTabViewShell );
1355 if (aTester.IsEditable())
1357 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1358 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1360 boost::scoped_ptr<AbstractScInsertContentsDlg> pDlg(pFact->CreateScInsertContentsDlg(pTabViewShell->GetDialogParent()));
1361 OSL_ENSURE(pDlg, "Dialog create fail!");
1362 pDlg->SetOtherDoc( bOtherDoc );
1363 // if ChangeTrack MoveMode disable
1364 pDlg->SetChangeTrack( pDoc->GetChangeTrack() != NULL );
1365 // fdo#56098 disable shift if necessary
1366 if ( !bOtherDoc && pOwnClip )
1368 ScViewData* pData = GetViewData();
1369 if ( pData->GetMarkData().GetTableSelect( pData->GetTabNo() ) )
1371 SCCOL nStartX, nEndX, nClipStartX, nClipSizeX, nRangeSizeX;
1372 SCROW nStartY, nEndY, nClipStartY, nClipSizeY, nRangeSizeY;
1373 SCTAB nStartTab, nEndTab;
1374 pOwnClip->GetDocument()->GetClipStart( nClipStartX, nClipStartY );
1375 pOwnClip->GetDocument()->GetClipArea( nClipSizeX, nClipSizeY, true );
1377 if ( !( pData->GetSimpleArea( nStartX, nStartY, nStartTab,
1378 nEndX, nEndY, nEndTab ) == SC_MARK_SIMPLE &&
1379 nStartTab == nEndTab ) )
1381 // the destination is not a simple range,
1382 // assume the destination as the current cell
1383 nStartX = nEndX = pData->GetCurX();
1384 nStartY = nEndY = pData->GetCurY();
1385 nStartTab = pData->GetTabNo();
1387 // we now have clip- and range dimensions
1388 // the size of the destination area is the larger of the two
1389 nRangeSizeX = nClipSizeX >= nEndX - nStartX ? nClipSizeX : nEndX - nStartX;
1390 nRangeSizeY = nClipSizeY >= nEndY - nStartY ? nClipSizeY : nEndY - nStartY;
1391 // When the source and destination areas intersect things may go wrong,
1392 // especially if the area contains references. This may produce data loss
1393 // (e.g. formulas that get wrong references), this scenario _must_ be avoided.
1394 ScRange aSource( nClipStartX, nClipStartY, nStartTab,
1395 nClipStartX + nClipSizeX, nClipStartY + nClipSizeY, nStartTab );
1396 ScRange aDest( nStartX, nStartY, nStartTab,
1397 nStartX + nRangeSizeX, nStartY + nRangeSizeY, nStartTab );
1398 if ( pOwnClip->GetDocument()->IsCutMode() && aSource.Intersects( aDest ) )
1399 pDlg->SetCellShiftDisabled( SC_CELL_SHIFT_DISABLE_DOWN | SC_CELL_SHIFT_DISABLE_RIGHT );
1400 else
1402 //no conflict with intersecting ranges,
1403 //check if paste plus shift will fit on sheet
1404 //and disable shift-option if no fit
1405 int nDisableShiftX = 0;
1406 int nDisableShiftY = 0;
1408 //check if horizontal shift will fit
1409 if ( !pData->GetDocument()->IsBlockEmpty( nStartTab,
1410 MAXCOL - nRangeSizeX, nStartY,
1411 MAXCOL, nStartY + nRangeSizeY, false ) )
1412 nDisableShiftX = SC_CELL_SHIFT_DISABLE_RIGHT;
1414 //check if vertical shift will fit
1415 if ( !pData->GetDocument()->IsBlockEmpty( nStartTab,
1416 nStartX, MAXROW - nRangeSizeY,
1417 nStartX + nRangeSizeX, MAXROW, false ) )
1418 nDisableShiftY = SC_CELL_SHIFT_DISABLE_DOWN;
1420 if ( nDisableShiftX || nDisableShiftY )
1421 pDlg->SetCellShiftDisabled( nDisableShiftX | nDisableShiftY );
1425 if (pDlg->Execute() == RET_OK)
1427 nFlags = pDlg->GetInsContentsCmdBits();
1428 nFunction = pDlg->GetFormulaCmdBits();
1429 bSkipEmpty = pDlg->IsSkipEmptyCells();
1430 bTranspose = pDlg->IsTranspose();
1431 bAsLink = pDlg->IsLink();
1432 eMoveMode = pDlg->GetMoveMode();
1435 else
1436 pTabViewShell->ErrorMessage(aTester.GetMessageId());
1439 if( nFlags != IDF_NONE )
1442 WaitObject aWait( GetViewData()->GetDialogParent() );
1443 if ( bAsLink && bOtherDoc )
1444 pTabViewShell->PasteFromSystem(SOT_FORMATSTR_ID_LINK); // DDE insert
1445 else
1447 pTabViewShell->PasteFromClip( nFlags, pOwnClip->GetDocument(),
1448 nFunction, bSkipEmpty, bTranspose, bAsLink,
1449 eMoveMode, IDF_NONE, true ); // allow warning dialog
1453 if( !pReqArgs )
1455 OUString aFlags;
1457 if( nFlags == IDF_ALL )
1459 aFlags += "A";
1461 else
1463 if( nFlags & IDF_STRING ) aFlags += "S";
1464 if( nFlags & IDF_VALUE ) aFlags += "V";
1465 if( nFlags & IDF_DATETIME ) aFlags += "D";
1466 if( nFlags & IDF_FORMULA ) aFlags += "F";
1467 if( nFlags & IDF_NOTE ) aFlags += "N";
1468 if( nFlags & IDF_ATTRIB ) aFlags += "T";
1471 rReq.AppendItem( SfxStringItem( FID_INS_CELL_CONTENTS, aFlags ) );
1472 rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bSkipEmpty ) );
1473 rReq.AppendItem( SfxBoolItem( FN_PARAM_3, bTranspose ) );
1474 rReq.AppendItem( SfxBoolItem( FN_PARAM_4, bAsLink ) );
1475 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, nFunction ) );
1476 rReq.AppendItem( SfxInt16Item( FN_PARAM_5, (sal_Int16) eMoveMode ) );
1477 rReq.Done();
1482 pTabViewShell->CellContentChanged(); // => PasteFromXXX ???
1483 break;
1484 case SID_PASTE_ONLY_VALUE:
1485 case SID_PASTE_ONLY_TEXT:
1486 case SID_PASTE_ONLY_FORMULA:
1488 Window* pWin = GetViewData()->GetActiveWin();
1489 if ( ScTransferObj::GetOwnClipboard( pWin ) ) // own cell data
1491 rReq.SetSlot( FID_INS_CELL_CONTENTS );
1492 OUString aFlags;
1493 if ( nSlot == SID_PASTE_ONLY_VALUE )
1494 aFlags = "V";
1495 else if ( nSlot == SID_PASTE_ONLY_TEXT )
1496 aFlags = "S";
1497 else
1498 aFlags = "F";
1499 rReq.AppendItem( SfxStringItem( FID_INS_CELL_CONTENTS, aFlags ) );
1500 ExecuteSlot( rReq, GetInterface() );
1501 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
1502 pTabViewShell->CellContentChanged();
1504 else
1505 rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1506 break;
1508 case SID_PASTE_SPECIAL:
1509 // differentiate between own cell data and draw objects/external data
1510 // this makes FID_INS_CELL_CONTENTS superfluous
1512 Window* pWin = GetViewData()->GetActiveWin();
1514 // Clipboard-ID given as parameter? Basic "PasteSpecial(Format)"
1515 const SfxPoolItem* pItem=NULL;
1516 if ( pReqArgs &&
1517 pReqArgs->GetItemState(nSlot, true, &pItem) == SFX_ITEM_SET &&
1518 pItem->ISA(SfxUInt32Item) )
1520 sal_uLong nFormat = ((const SfxUInt32Item*)pItem)->GetValue();
1521 bool bRet=true;
1523 WaitObject aWait( GetViewData()->GetDialogParent() );
1524 bool bDraw = ( ScDrawTransferObj::GetOwnClipboard( pWin ) != NULL );
1525 if ( bDraw && nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE )
1526 pTabViewShell->PasteDraw();
1527 else
1528 bRet = pTabViewShell->PasteFromSystem(nFormat, true); // TRUE: no error messages
1531 if ( bRet )
1533 rReq.SetReturnValue(SfxInt16Item(nSlot, bRet ? 1 : 0)); // 1 = success, 0 = fail
1534 rReq.Done();
1536 else
1537 // if format is not available -> fallback to request without parameters
1538 pItem = NULL;
1541 if ( !pItem )
1543 if ( ScTransferObj::GetOwnClipboard( pWin ) ) // own cell data
1545 rReq.SetSlot( FID_INS_CELL_CONTENTS );
1546 ExecuteSlot( rReq, GetInterface() );
1547 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
1549 else // draw objects or external data
1551 bool bDraw = ( ScDrawTransferObj::GetOwnClipboard( pWin ) != NULL );
1553 SvxClipboardFmtItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
1554 GetPossibleClipboardFormats( aFormats );
1556 sal_uInt16 nFormatCount = aFormats.Count();
1557 if ( nFormatCount )
1559 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1560 boost::scoped_ptr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog( pTabViewShell->GetDialogParent() ));
1561 if ( pDlg )
1563 for (sal_uInt16 i=0; i<nFormatCount; i++)
1565 sal_uLong nFormatId = aFormats.GetClipbrdFormatId( i );
1566 OUString aName = aFormats.GetClipbrdFormatName( i );
1567 // special case for paste dialog: '*' is replaced by object type
1568 if ( nFormatId == SOT_FORMATSTR_ID_EMBED_SOURCE )
1569 aName = "*";
1570 pDlg->Insert( nFormatId, aName );
1573 TransferableDataHelper aDataHelper(
1574 TransferableDataHelper::CreateFromSystemClipboard( pWin ) );
1575 sal_uLong nFormat = pDlg->GetFormat( aDataHelper.GetTransferable() );
1576 if (nFormat > 0)
1579 WaitObject aWait( GetViewData()->GetDialogParent() );
1580 if ( bDraw && nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE )
1581 pTabViewShell->PasteDraw();
1582 else
1583 pTabViewShell->PasteFromSystem(nFormat);
1585 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
1586 rReq.AppendItem( SfxUInt32Item( nSlot, nFormat ) );
1587 rReq.Done();
1589 else
1591 rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1592 rReq.Ignore();
1596 else
1597 rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1601 pTabViewShell->CellContentChanged(); // => PasteFromSystem() ???
1602 break;
1605 // other
1608 case FID_INS_ROWBRK:
1609 pTabViewShell->InsertPageBreak( false );
1610 rReq.Done();
1611 break;
1613 case FID_INS_COLBRK:
1614 pTabViewShell->InsertPageBreak( true );
1615 rReq.Done();
1616 break;
1618 case FID_DEL_ROWBRK:
1619 pTabViewShell->DeletePageBreak( false );
1620 rReq.Done();
1621 break;
1623 case FID_DEL_COLBRK:
1624 pTabViewShell->DeletePageBreak( true );
1625 rReq.Done();
1626 break;
1628 case SID_DETECTIVE_ADD_PRED:
1629 pTabViewShell->DetectiveAddPred();
1630 rReq.Done();
1631 break;
1633 case SID_DETECTIVE_DEL_PRED:
1634 pTabViewShell->DetectiveDelPred();
1635 rReq.Done();
1636 break;
1638 case SID_DETECTIVE_ADD_SUCC:
1639 pTabViewShell->DetectiveAddSucc();
1640 rReq.Done();
1641 break;
1643 case SID_DETECTIVE_DEL_SUCC:
1644 pTabViewShell->DetectiveDelSucc();
1645 rReq.Done();
1646 break;
1648 case SID_DETECTIVE_ADD_ERR:
1649 pTabViewShell->DetectiveAddError();
1650 rReq.Done();
1651 break;
1653 case SID_DETECTIVE_INVALID:
1654 pTabViewShell->DetectiveMarkInvalid();
1655 rReq.Done();
1656 break;
1658 case SID_DETECTIVE_REFRESH:
1659 pTabViewShell->DetectiveRefresh();
1660 rReq.Done();
1661 break;
1663 case SID_DETECTIVE_MARK_PRED:
1664 pTabViewShell->DetectiveMarkPred();
1665 break;
1666 case SID_DETECTIVE_MARK_SUCC:
1667 pTabViewShell->DetectiveMarkSucc();
1668 break;
1669 case SID_INSERT_CURRENT_DATE:
1670 pTabViewShell->InsertCurrentTime(
1671 NUMBERFORMAT_DATE, ScGlobal::GetRscString(STR_UNDO_INSERT_CURRENT_DATE));
1672 break;
1673 case SID_INSERT_CURRENT_TIME:
1674 pTabViewShell->InsertCurrentTime(
1675 NUMBERFORMAT_TIME, ScGlobal::GetRscString(STR_UNDO_INSERT_CURRENT_TIME));
1676 break;
1678 case SID_SPELL_DIALOG:
1680 SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame();
1681 if( rReq.GetArgs() )
1682 pViewFrame->SetChildWindow( SID_SPELL_DIALOG,
1683 static_cast< const SfxBoolItem& >( rReq.GetArgs()->
1684 Get( SID_SPELL_DIALOG ) ).GetValue() );
1685 else
1686 pViewFrame->ToggleChildWindow( SID_SPELL_DIALOG );
1688 pViewFrame->GetBindings().Invalidate( SID_SPELL_DIALOG );
1689 rReq.Ignore();
1691 break;
1693 case SID_HANGUL_HANJA_CONVERSION:
1694 pTabViewShell->DoHangulHanjaConversion();
1695 break;
1697 case SID_CHINESE_CONVERSION:
1699 //open ChineseTranslationDialog
1700 Reference< XComponentContext > xContext(
1701 ::cppu::defaultBootstrap_InitialComponentContext() ); //@todo get context from calc if that has one
1702 if(xContext.is())
1704 Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
1705 if(xMCF.is())
1707 Reference< ui::dialogs::XExecutableDialog > xDialog(
1708 xMCF->createInstanceWithContext(
1709 OUString("com.sun.star.linguistic2.ChineseTranslationDialog")
1710 , xContext), UNO_QUERY);
1711 Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
1712 if( xInit.is() )
1714 // initialize dialog
1715 Reference< awt::XWindow > xDialogParentWindow(0);
1716 Sequence<Any> aSeq(1);
1717 Any* pArray = aSeq.getArray();
1718 PropertyValue aParam;
1719 aParam.Name = "ParentWindow";
1720 aParam.Value <<= makeAny(xDialogParentWindow);
1721 pArray[0] <<= makeAny(aParam);
1722 xInit->initialize( aSeq );
1724 //execute dialog
1725 sal_Int16 nDialogRet = xDialog->execute();
1726 if( RET_OK == nDialogRet )
1728 //get some parameters from the dialog
1729 bool bToSimplified = true;
1730 bool bUseVariants = true;
1731 bool bCommonTerms = true;
1732 Reference< beans::XPropertySet > xProp( xDialog, UNO_QUERY );
1733 if( xProp.is() )
1737 xProp->getPropertyValue("IsDirectionToSimplified") >>= bToSimplified;
1738 xProp->getPropertyValue("IsUseCharacterVariants") >>= bUseVariants;
1739 xProp->getPropertyValue("IsTranslateCommonTerms") >>= bCommonTerms;
1741 catch( Exception& )
1746 //execute translation
1747 LanguageType eSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
1748 LanguageType eTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
1749 sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
1750 if( !bCommonTerms )
1751 nOptions |= i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
1753 Font aTargetFont = GetViewData()->GetActiveWin()->GetDefaultFont(
1754 DEFAULTFONT_CJK_SPREADSHEET,
1755 eTargetLang, DEFAULTFONT_FLAGS_ONLYONE );
1756 ScConversionParam aConvParam( SC_CONVERSION_CHINESE_TRANSL,
1757 eSourceLang, eTargetLang, aTargetFont, nOptions, false );
1758 pTabViewShell->DoSheetConversion( aConvParam );
1761 Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
1762 if( xComponent.is() )
1763 xComponent->dispose();
1767 break;
1769 case SID_THESAURUS:
1770 pTabViewShell->DoThesaurus();
1771 break;
1773 case SID_TOGGLE_REL:
1774 pTabViewShell->DoRefConversion();
1775 break;
1777 case SID_DEC_INDENT:
1778 pTabViewShell->ChangeIndent( false );
1779 break;
1780 case SID_INC_INDENT:
1781 pTabViewShell->ChangeIndent( true );
1782 break;
1784 case FID_USE_NAME:
1786 sal_uInt16 nFlags = pTabViewShell->GetCreateNameFlags();
1788 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1789 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1791 boost::scoped_ptr<AbstractScNameCreateDlg> pDlg(pFact->CreateScNameCreateDlg(pTabViewShell->GetDialogParent(), nFlags));
1792 OSL_ENSURE(pDlg, "Dialog create fail!");
1794 if( pDlg->Execute() )
1796 nFlags = pDlg->GetFlags();
1797 pTabViewShell->CreateNames(nFlags);
1798 rReq.Done();
1801 break;
1803 case SID_CONSOLIDATE:
1805 const SfxPoolItem* pItem;
1806 if ( pReqArgs && SFX_ITEM_SET ==
1807 pReqArgs->GetItemState( SCITEM_CONSOLIDATEDATA, true, &pItem ) )
1809 const ScConsolidateParam& rParam =
1810 ((const ScConsolidateItem*)pItem)->GetData();
1812 pTabViewShell->Consolidate( rParam );
1813 GetViewData()->GetDocument()->SetConsolidateDlgData( &rParam );
1815 rReq.Done();
1817 #ifndef DISABLE_SCRIPTING
1818 else if (rReq.IsAPI())
1819 SbxBase::SetError(SbxERR_BAD_PARAMETER);
1820 #endif
1822 break;
1824 case SID_INS_FUNCTION:
1826 const SfxBoolItem* pOkItem = (const SfxBoolItem*)&pReqArgs->Get( SID_DLG_RETOK );
1828 if ( pOkItem->GetValue() ) // OK
1830 OUString aFormula;
1831 const SfxStringItem* pSItem = (const SfxStringItem*)&pReqArgs->Get( SCITEM_STRING );
1832 const SfxBoolItem* pMatrixItem = (const SfxBoolItem*) &pReqArgs->Get( SID_DLG_MATRIX );
1834 aFormula += pSItem->GetValue();
1835 pScMod->ActivateInputWindow( &aFormula, pMatrixItem->GetValue() );
1837 else // CANCEL
1839 pScMod->ActivateInputWindow( NULL );
1841 rReq.Ignore(); // only SID_ENTER_STRING is recorded
1843 break;
1845 case FID_DEFINE_NAME:
1846 if ( pReqArgs )
1848 const SfxPoolItem* pItem;
1849 OUString aName, aSymbol, aAttrib;
1851 if( pReqArgs->HasItem( FID_DEFINE_NAME, &pItem ) )
1852 aName = ((const SfxStringItem*)pItem)->GetValue();
1854 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
1855 aSymbol = ((const SfxStringItem*)pItem)->GetValue();
1857 if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
1858 aAttrib = ((const SfxStringItem*)pItem)->GetValue();
1860 if ( !aName.isEmpty() && !aSymbol.isEmpty() )
1862 if (pTabViewShell->InsertName( aName, aSymbol, aAttrib ))
1863 rReq.Done();
1864 #ifndef DISABLE_SCRIPTING
1865 else
1866 SbxBase::SetError( SbxERR_BAD_PARAMETER ); // Basic-error
1867 #endif
1870 else
1872 sal_uInt16 nId = ScNameDlgWrapper::GetChildWindowId();
1873 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1874 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
1876 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
1878 break;
1879 case FID_ADD_NAME:
1881 sal_uInt16 nId = ScNameDefDlgWrapper::GetChildWindowId();
1882 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1883 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
1885 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
1887 break;
1889 case SID_OPENDLG_CONDFRMT:
1890 case SID_OPENDLG_COLORSCALE:
1891 case SID_OPENDLG_DATABAR:
1892 case SID_OPENDLG_ICONSET:
1893 case SID_OPENDLG_CONDDATE:
1896 ScRangeList aRangeList;
1897 ScViewData* pData = GetViewData();
1898 pData->GetMarkData().FillRangeListWithMarks(&aRangeList, false);
1900 ScDocument* pDoc = GetViewData()->GetDocument();
1901 if(pDoc->IsTabProtected(pData->GetTabNo()))
1903 //ErrorMessage( STR_ERR_CONDFORMAT_PROTECTED );
1904 break;
1907 ScAddress aPos(pData->GetCurX(), pData->GetCurY(), pData->GetTabNo());
1908 if(aRangeList.empty())
1910 ScRange* pRange = new ScRange(aPos);
1911 aRangeList.push_back(pRange);
1914 sal_Int32 nKey = 0;
1915 const ScPatternAttr* pPattern = pDoc->GetPattern(aPos.Col(), aPos.Row(), aPos.Tab());
1916 const std::vector<sal_uInt32>& rCondFormats = static_cast<const ScCondFormatItem&>(pPattern->GetItem(ATTR_CONDITIONAL)).GetCondFormatData();
1917 bool bContainsCondFormat = !rCondFormats.empty();
1918 boost::scoped_ptr<ScCondFormatDlg> pCondFormatDlg;
1919 if(bContainsCondFormat)
1921 bool bContainsExistingCondFormat = false;
1922 ScConditionalFormatList* pList = pDoc->GetCondFormList(aPos.Tab());
1923 for (std::vector<sal_uInt32>::const_iterator itr = rCondFormats.begin(), itrEnd = rCondFormats.end();
1924 itr != itrEnd; ++itr)
1926 // check if at least one existing conditional format has the same range
1927 const ScConditionalFormat* pCondFormat = pList->GetFormat(*itr);
1928 if(!pCondFormat)
1929 continue;
1931 bContainsExistingCondFormat = true;
1932 const ScRangeList& rCondFormatRange = pCondFormat->GetRange();
1933 if(rCondFormatRange == aRangeList)
1935 // found a matching range, edit this conditional format
1936 nKey = pCondFormat->GetKey();
1937 pCondFormatDlg.reset( new ScCondFormatDlg( pTabViewShell->GetDialogParent(), pDoc, pCondFormat, rCondFormatRange, aPos, condformat::dialog::NONE ) );
1938 break;
1942 // if not found a conditional format ask whether we should edit one of the existing
1943 // or should create a new overlapping conditional format
1945 if(!pCondFormatDlg && bContainsExistingCondFormat)
1947 QueryBox aBox( pTabViewShell->GetDialogParent(), WinBits( WB_YES_NO | WB_DEF_YES ),
1948 ScGlobal::GetRscString(STR_EDIT_EXISTING_COND_FORMATS) );
1949 bool bEditExisting = aBox.Execute() == RET_YES;
1950 if(bEditExisting)
1952 // differentiate between ranges where one conditional format is defined
1953 // and several formats are defined
1954 // if we have only one => open the cond format dlg to edit it
1955 // otherwise open the manage cond format dlg
1956 if(rCondFormats.size() == 1)
1958 const ScConditionalFormat* pCondFormat = pList->GetFormat(rCondFormats[0]);
1959 assert(pCondFormat);
1960 const ScRangeList& rCondFormatRange = pCondFormat->GetRange();
1961 nKey = pCondFormat->GetKey();
1962 pCondFormatDlg.reset( new ScCondFormatDlg( pTabViewShell->GetDialogParent(), pDoc, pCondFormat, rCondFormatRange, aPos, condformat::dialog::NONE ) );
1964 else
1966 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1967 boost::scoped_ptr<AbstractScCondFormatManagerDlg> pDlg(pFact->CreateScCondFormatMgrDlg( pTabViewShell->GetDialogParent(), pDoc, pList, aPos, RID_SCDLG_COND_FORMAT_MANAGER));
1968 if(pDlg->Execute() == RET_OK && pDlg->CondFormatsChanged())
1970 ScConditionalFormatList* pCondFormatList = pDlg->GetConditionalFormatList();
1971 pData->GetDocShell()->GetDocFunc().SetConditionalFormatList(pCondFormatList, aPos.Tab());
1973 // we need step out here because we don't want to open the normal dialog
1974 break;
1977 else
1979 // define an overlapping conditional format
1980 // does not need to be handled here
1986 if(!pCondFormatDlg)
1988 condformat::dialog::ScCondFormatDialogType eType = condformat::dialog::NONE;
1989 switch(nSlot)
1991 case SID_OPENDLG_CONDFRMT:
1992 eType = condformat::dialog::CONDITION;
1993 break;
1994 case SID_OPENDLG_COLORSCALE:
1995 eType = condformat::dialog::COLORSCALE;
1996 break;
1997 case SID_OPENDLG_DATABAR:
1998 eType = condformat::dialog::DATABAR;
1999 break;
2000 case SID_OPENDLG_ICONSET:
2001 eType = condformat::dialog::ICONSET;
2002 break;
2003 case SID_OPENDLG_CONDDATE:
2004 eType = condformat::dialog::DATE;
2005 break;
2006 default:
2007 assert(false);
2008 break;
2010 pCondFormatDlg.reset( new ScCondFormatDlg( pTabViewShell->GetDialogParent(), pDoc, NULL, aRangeList, aRangeList.GetTopLeftCorner(), eType ) );
2013 sal_uInt16 nId = 1;
2014 pScMod->SetRefDialog( nId, true );
2016 if( pCondFormatDlg->Execute() == RET_OK )
2018 ScConditionalFormat* pFormat = pCondFormatDlg->GetConditionalFormat();
2019 if(pFormat)
2020 pData->GetDocShell()->GetDocFunc().ReplaceConditionalFormat(nKey, pFormat, aPos.Tab(), pFormat->GetRange());
2021 else
2022 pData->GetDocShell()->GetDocFunc().ReplaceConditionalFormat(nKey, NULL, aPos.Tab(), ScRangeList());
2025 pScMod->SetRefDialog( nId, false );
2029 break;
2031 case SID_DEFINE_COLROWNAMERANGES:
2034 sal_uInt16 nId = ScColRowNameRangesDlgWrapper::GetChildWindowId();
2035 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
2036 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
2038 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
2041 break;
2043 case SID_UPDATECHART:
2045 bool bAll = false;
2047 if( pReqArgs )
2049 const SfxPoolItem* pItem;
2051 if( pReqArgs->HasItem( SID_UPDATECHART, &pItem ) )
2052 bAll = ((const SfxBoolItem*)pItem)->GetValue();
2055 pTabViewShell->UpdateCharts( bAll );
2057 if( ! rReq.IsAPI() )
2059 rReq.AppendItem( SfxBoolItem( SID_UPDATECHART, bAll ) );
2060 rReq.Done();
2063 break;
2066 case SID_TABOP:
2067 if (pReqArgs)
2069 const ScTabOpItem& rItem =
2070 (const ScTabOpItem&)
2071 pReqArgs->Get( SID_TABOP );
2073 pTabViewShell->TabOp( rItem.GetData() );
2075 rReq.Done( *pReqArgs );
2077 break;
2079 case SID_SOLVE:
2080 if (pReqArgs)
2082 const ScSolveItem& rItem =
2083 (const ScSolveItem&)
2084 pReqArgs->Get( SCITEM_SOLVEDATA );
2086 pTabViewShell->Solve( rItem.GetData() );
2088 rReq.Done( *pReqArgs );
2090 break;
2092 case FID_INSERT_NAME:
2094 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2095 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2097 boost::scoped_ptr<AbstractScNamePasteDlg> pDlg(pFact->CreateScNamePasteDlg( pTabViewShell->GetDialogParent(), GetViewData()->GetDocShell() ));
2098 OSL_ENSURE(pDlg, "Dialog create fail!");
2099 switch( pDlg->Execute() )
2101 case BTN_PASTE_LIST:
2102 pTabViewShell->InsertNameList();
2103 break;
2104 case BTN_PASTE_NAME:
2106 ScInputHandler* pHdl = pScMod->GetInputHdl( pTabViewShell );
2107 if (pHdl)
2109 // "=" in KeyEvent, switches to input-mode
2110 pScMod->InputKeyEvent( KeyEvent('=',KeyCode()) );
2112 std::vector<OUString> aNames = pDlg->GetSelectedNames();
2113 if (!aNames.empty())
2115 OUStringBuffer aBuffer;
2116 for (std::vector<OUString>::const_iterator itr = aNames.begin();
2117 itr != aNames.end(); ++itr)
2119 aBuffer.append(*itr).append(' ');
2121 pHdl->InsertFunction( aBuffer.makeStringAndClear(), false ); // without "()"
2125 break;
2128 break;
2130 case SID_RANGE_NOTETEXT:
2131 if (pReqArgs)
2133 const SfxStringItem& rTextItem = (const SfxStringItem&)pReqArgs->Get( SID_RANGE_NOTETEXT );
2135 // always cursor position
2136 ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
2137 pTabViewShell->SetNoteText( aPos, rTextItem.GetValue() );
2138 rReq.Done();
2140 break;
2142 case SID_INSERT_POSTIT:
2143 if ( pReqArgs )
2145 const SvxPostItAuthorItem& rAuthorItem = (const SvxPostItAuthorItem&)pReqArgs->Get( SID_ATTR_POSTIT_AUTHOR );
2146 const SvxPostItDateItem& rDateItem = (const SvxPostItDateItem&) pReqArgs->Get( SID_ATTR_POSTIT_DATE );
2147 const SvxPostItTextItem& rTextItem = (const SvxPostItTextItem&) pReqArgs->Get( SID_ATTR_POSTIT_TEXT );
2149 ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
2150 pTabViewShell->ReplaceNote( aPos, rTextItem.GetValue(), &rAuthorItem.GetValue(), &rDateItem.GetValue() );
2151 rReq.Done();
2153 else
2155 pTabViewShell->EditNote(); // note object to edit
2157 break;
2159 case FID_NOTE_VISIBLE:
2161 ScDocument* pDoc = GetViewData()->GetDocument();
2162 ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
2163 if( ScPostIt* pNote = pDoc->GetNote(aPos) )
2165 bool bShow;
2166 const SfxPoolItem* pItem;
2167 if ( pReqArgs && (pReqArgs->GetItemState( FID_NOTE_VISIBLE, true, &pItem ) == SFX_ITEM_SET) )
2168 bShow = ((const SfxBoolItem*) pItem)->GetValue();
2169 else
2170 bShow = !pNote->IsCaptionShown();
2172 pTabViewShell->ShowNote( bShow );
2174 if (!pReqArgs)
2175 rReq.AppendItem( SfxBoolItem( FID_NOTE_VISIBLE, bShow ) );
2177 rReq.Done();
2178 rBindings.Invalidate( FID_NOTE_VISIBLE );
2180 else
2181 rReq.Ignore();
2183 break;
2185 case FID_HIDE_NOTE:
2186 case FID_SHOW_NOTE:
2188 bool bShowNote = nSlot == FID_SHOW_NOTE;
2189 ScViewData* pData = GetViewData();
2190 ScDocument* pDoc = pData->GetDocument();
2191 ScMarkData& rMark = pData->GetMarkData();
2192 bool bDone = false;
2194 if (!rMark.IsMarked() && !rMark.IsMultiMarked())
2196 // Check current cell
2197 ScAddress aPos( pData->GetCurX(), pData->GetCurY(), pData->GetTabNo() );
2198 if( pDoc->GetNote(aPos) )
2200 pData->GetDocShell()->GetDocFunc().ShowNote( aPos, bShowNote );
2201 bDone = true;
2204 else
2206 // Check selection range
2207 ScRangeListRef aRangesRef;
2208 pData->GetMultiArea(aRangesRef);
2209 ScRangeList aRanges = *aRangesRef;
2210 size_t nRangeSize = aRanges.size();
2212 OUString aUndo = ScGlobal::GetRscString( bShowNote ? STR_UNDO_SHOWNOTE : STR_UNDO_HIDENOTE );
2213 pData->GetDocShell()->GetUndoManager()->EnterListAction( aUndo, aUndo );
2215 for ( size_t i = 0; i < nRangeSize; ++i )
2217 const ScRange * pRange = aRanges[i];
2218 const SCROW nRow0 = pRange->aStart.Row();
2219 const SCROW nRow1 = pRange->aEnd.Row();
2220 const SCCOL nCol0 = pRange->aStart.Col();
2221 const SCCOL nCol1 = pRange->aEnd.Col();
2222 const SCTAB nRangeTab = pRange->aStart.Tab();
2223 // Check by each cell
2224 for ( SCROW nRow = nRow0; nRow <= nRow1; ++nRow )
2226 for ( SCCOL nCol = nCol0; nCol <= nCol1; ++nCol )
2228 if ( pDoc->HasNote(nCol, nRow, nRangeTab) && pDoc->IsBlockEditable( nRangeTab, nCol,nRow, nCol,nRow ) )
2230 ScAddress aPos( nCol, nRow, nRangeTab );
2231 pData->GetDocShell()->GetDocFunc().ShowNote( aPos, bShowNote );
2232 bDone = true;
2238 pData->GetDocShell()->GetUndoManager()->LeaveListAction();
2240 if ( bDone )
2242 rReq.Done();
2243 rBindings.Invalidate( nSlot );
2245 else
2246 rReq.Ignore();
2249 break;
2251 case SID_DELETE_NOTE:
2252 pTabViewShell->DeleteContents( IDF_NOTE ); // delete all notes in selection
2253 rReq.Done();
2254 break;
2256 case SID_CHARMAP:
2257 if( pReqArgs != NULL )
2259 OUString aChars, aFontName;
2260 const SfxItemSet *pArgs = rReq.GetArgs();
2261 const SfxPoolItem* pItem = 0;
2262 if ( pArgs )
2263 pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP), false, &pItem);
2264 if ( pItem )
2266 const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, pItem );
2267 if ( pStringItem )
2268 aChars = pStringItem->GetValue();
2269 const SfxPoolItem* pFtItem = NULL;
2270 pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR), false, &pFtItem);
2271 const SfxStringItem* pFontItem = PTR_CAST( SfxStringItem, pFtItem );
2272 if ( pFontItem )
2273 aFontName = pFontItem->GetValue();
2276 if ( !aChars.isEmpty() )
2278 Font aFont;
2279 pTabViewShell->GetSelectionPattern()->GetFont( aFont, SC_AUTOCOL_BLACK, NULL, NULL, NULL,
2280 pTabViewShell->GetSelectionScriptType() );
2281 if ( !aFontName.isEmpty() )
2282 aFont = Font( aFontName, Size(1,1) );
2283 pTabViewShell->InsertSpecialChar( aChars, aFont );
2284 if( ! rReq.IsAPI() )
2285 rReq.Done();
2288 else
2290 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
2292 // font color doesn't matter here
2293 Font aCurFont;
2294 pTabViewShell->GetSelectionPattern()->GetFont( aCurFont, SC_AUTOCOL_BLACK, NULL, NULL, NULL,
2295 pTabViewShell->GetSelectionScriptType() );
2297 SfxAllItemSet aSet( GetPool() );
2298 aSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
2299 aSet.Put( SvxFontItem( aCurFont.GetFamily(), aCurFont.GetName(), aCurFont.GetStyleName(), aCurFont.GetPitch(), aCurFont.GetCharSet(), GetPool().GetWhich(SID_ATTR_CHAR_FONT) ) );
2301 boost::scoped_ptr<SfxAbstractDialog> pDlg(pFact->CreateSfxDialog( pTabViewShell->GetDialogParent(), aSet,
2302 pTabViewShell->GetViewFrame()->GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP ));
2304 if ( pDlg->Execute() == RET_OK )
2306 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pItem, SfxStringItem, SID_CHARMAP, false );
2307 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFontItem, SvxFontItem, SID_ATTR_CHAR_FONT, false );
2309 if ( pItem && pFontItem )
2311 Font aNewFont( pFontItem->GetFamilyName(), pFontItem->GetStyleName(), Size(1,1) );
2312 aNewFont.SetCharSet( pFontItem->GetCharSet() );
2313 aNewFont.SetPitch( pFontItem->GetPitch() );
2314 pTabViewShell->InsertSpecialChar( pItem->GetValue(), aNewFont );
2315 rReq.AppendItem( *pFontItem );
2316 rReq.AppendItem( *pItem );
2317 rReq.Done();
2321 break;
2323 case SID_SELECT_SCENARIO:
2325 // Testing
2327 if ( pReqArgs )
2329 const SfxStringItem* pItem =
2330 (const SfxStringItem*)&pReqArgs->Get( SID_SELECT_SCENARIO );
2332 if( pItem )
2334 pTabViewShell->UseScenario( pItem->GetValue() );
2335 //! why should the return value be valid?!?!
2336 rReq.SetReturnValue( SfxStringItem( SID_SELECT_SCENARIO, pItem->GetValue() ) );
2337 rReq.Done();
2339 else
2341 OSL_FAIL("NULL");
2345 break;
2347 case SID_HYPERLINK_SETLINK:
2348 if( pReqArgs )
2350 const SfxPoolItem* pItem;
2351 if( pReqArgs->HasItem( SID_HYPERLINK_SETLINK, &pItem ) )
2353 const SvxHyperlinkItem* pHyper = (const SvxHyperlinkItem*) pItem;
2354 const OUString& rName = pHyper->GetName();
2355 const OUString& rURL = pHyper->GetURL();
2356 const OUString& rTarget = pHyper->GetTargetFrame();
2357 sal_uInt16 nType = (sal_uInt16) pHyper->GetInsertMode();
2359 pTabViewShell->InsertURL( rName, rURL, rTarget, nType );
2360 rReq.Done();
2362 else
2363 rReq.Ignore();
2365 break;
2367 case SID_OPENDLG_CONDFRMT_MANAGER:
2369 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2370 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2372 ScViewData* pData = GetViewData();
2373 ScDocument* pDoc = pData->GetDocument();
2375 if(pDoc->IsTabProtected(pData->GetTabNo()))
2377 pTabViewShell->ErrorMessage( STR_ERR_CONDFORMAT_PROTECTED );
2378 break;
2381 ScAddress aPos(pData->GetCurX(), pData->GetCurY(), pData->GetTabNo());
2383 ScConditionalFormatList* pList = pDoc->GetCondFormList( aPos.Tab() );
2384 boost::scoped_ptr<AbstractScCondFormatManagerDlg> pDlg(pFact->CreateScCondFormatMgrDlg( pTabViewShell->GetDialogParent(), pDoc, pList, aPos, RID_SCDLG_COND_FORMAT_MANAGER));
2385 if(pDlg->Execute() == RET_OK && pDlg->CondFormatsChanged())
2387 ScConditionalFormatList* pCondFormatList = pDlg->GetConditionalFormatList();
2388 pData->GetDocShell()->GetDocFunc().SetConditionalFormatList(pCondFormatList, aPos.Tab());
2391 break;
2393 case SID_EXTERNAL_SOURCE:
2395 OUString aFile;
2396 OUString aFilter;
2397 OUString aOptions;
2398 OUString aSource;
2399 sal_uLong nRefresh=0;
2401 SFX_REQUEST_ARG( rReq, pFile, SfxStringItem, SID_FILE_NAME, false );
2402 SFX_REQUEST_ARG( rReq, pSource, SfxStringItem, FN_PARAM_1, false );
2403 if ( pFile && pSource )
2405 aFile = pFile->GetValue();
2406 aSource = pSource->GetValue();
2407 SFX_REQUEST_ARG( rReq, pFilter, SfxStringItem, SID_FILTER_NAME, false );
2408 if ( pFilter )
2409 aFilter = pFilter->GetValue();
2410 SFX_REQUEST_ARG( rReq, pOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, false );
2411 if ( pOptions )
2412 aOptions = pOptions->GetValue();
2413 SFX_REQUEST_ARG( rReq, pRefresh, SfxUInt32Item, FN_PARAM_2, false );
2414 if ( pRefresh )
2415 nRefresh = pRefresh->GetValue();
2417 else
2419 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2420 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2422 delete pImpl->m_pLinkedDlg;
2423 pImpl->m_pLinkedDlg =
2424 pFact->CreateScLinkedAreaDlg(pTabViewShell->GetDialogParent());
2425 OSL_ENSURE(pImpl->m_pLinkedDlg, "Dialog create fail!");
2426 delete pImpl->m_pRequest;
2427 pImpl->m_pRequest = new SfxRequest( rReq );
2428 pImpl->m_pLinkedDlg->StartExecuteModal( LINK( this, ScCellShell, DialogClosed ) );
2429 return;
2432 ExecuteExternalSource( aFile, aFilter, aOptions, aSource, nRefresh, rReq );
2434 break;
2438 default:
2439 OSL_FAIL("incorrect slot in ExecuteEdit");
2440 break;
2444 void ScCellShell::ExecuteTrans( SfxRequest& rReq )
2446 sal_Int32 nType = ScViewUtil::GetTransliterationType( rReq.GetSlot() );
2447 if ( nType )
2449 GetViewData()->GetView()->TransliterateText( nType );
2450 rReq.Done();
2454 void ScCellShell::ExecuteRotateTrans( SfxRequest& rReq )
2456 if( rReq.GetSlot() == SID_TRANSLITERATE_ROTATE_CASE )
2457 GetViewData()->GetView()->TransliterateText( m_aRotateCase.getNextMode() );
2460 void ScCellShell::ExecuteExternalSource(
2461 const OUString& _rFile, const OUString& _rFilter, const OUString& _rOptions,
2462 const OUString& _rSource, sal_uLong _nRefresh, SfxRequest& _rRequest )
2464 if ( !_rFile.isEmpty() && !_rSource.isEmpty() ) // filter may be empty
2466 ScRange aLinkRange;
2467 bool bMove = false;
2469 ScViewData* pData = GetViewData();
2470 ScMarkData& rMark = pData->GetMarkData();
2471 rMark.MarkToSimple();
2472 if ( rMark.IsMarked() )
2474 rMark.GetMarkArea( aLinkRange );
2475 bMove = true; // insert/delete cells to fit range
2477 else
2478 aLinkRange = ScRange( pData->GetCurX(), pData->GetCurY(), pData->GetTabNo() );
2480 pData->GetDocFunc().InsertAreaLink( _rFile, _rFilter, _rOptions, _rSource,
2481 aLinkRange, _nRefresh, bMove, false );
2482 _rRequest.Done();
2484 else
2485 _rRequest.Ignore();
2488 namespace {
2490 bool isDPSourceValid(const ScDPObject& rDPObj)
2492 if (rDPObj.IsImportData())
2494 // If the data type is database, check if the database is still valid.
2495 const ScImportSourceDesc* pDesc = rDPObj.GetImportSourceDesc();
2496 if (!pDesc)
2497 return false;
2499 const ScDPSaveData* pSaveData = rDPObj.GetSaveData();
2500 const ScDPDimensionSaveData* pDimData = NULL;
2501 if (pSaveData)
2502 pDimData = pSaveData->GetExistingDimensionData();
2504 const ScDPCache* pCache = pDesc->CreateCache(pDimData);
2505 if (!pCache)
2506 // cashe creation failed, probably due to invalid connection.
2507 return false;
2509 return true;
2514 void ScCellShell::ExecuteDataPilotDialog()
2516 ScModule* pScMod = SC_MOD();
2517 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2518 ScViewData* pData = GetViewData();
2519 ScDocument* pDoc = pData->GetDocument();
2521 ::boost::scoped_ptr<ScDPObject> pNewDPObject(NULL);
2523 // ScPivot is no longer used...
2524 ScDPObject* pDPObj = pDoc->GetDPAtCursor(
2525 pData->GetCurX(), pData->GetCurY(),
2526 pData->GetTabNo() );
2527 if ( pDPObj ) // on an existing table?
2529 if (isDPSourceValid(*pDPObj))
2530 pNewDPObject.reset(new ScDPObject(*pDPObj));
2532 else // create new table
2534 sal_uLong nSrcErrorId = 0;
2536 // select database range or data
2537 pTabViewShell->GetDBData( true, SC_DB_OLD );
2538 ScMarkData& rMark = GetViewData()->GetMarkData();
2539 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
2540 pTabViewShell->MarkDataArea( false );
2542 // output to cursor position for non-sheet data
2543 ScAddress aDestPos( pData->GetCurX(), pData->GetCurY(),
2544 pData->GetTabNo() );
2546 // first select type of source data
2548 bool bEnableExt = ScDPObject::HasRegisteredSources();
2550 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2551 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2553 ::boost::scoped_ptr<AbstractScDataPilotSourceTypeDlg> pTypeDlg(
2554 pFact->CreateScDataPilotSourceTypeDlg(
2555 pTabViewShell->GetDialogParent(), bEnableExt));
2557 // Populate named ranges (if any).
2558 ScRangeName* pRangeName = pDoc->GetRangeName();
2559 if (pRangeName)
2561 ScRangeName::const_iterator itr = pRangeName->begin(), itrEnd = pRangeName->end();
2562 for (; itr != itrEnd; ++itr)
2563 pTypeDlg->AppendNamedRange(itr->second->GetName());
2566 OSL_ENSURE(pTypeDlg, "Dialog create fail!");
2567 if ( pTypeDlg->Execute() == RET_OK )
2569 if ( pTypeDlg->IsExternal() )
2571 uno::Sequence<OUString> aSources = ScDPObject::GetRegisteredSources();
2572 ::boost::scoped_ptr<AbstractScDataPilotServiceDlg> pServDlg(
2573 pFact->CreateScDataPilotServiceDlg(
2574 pTabViewShell->GetDialogParent(), aSources, RID_SCDLG_DAPISERVICE));
2576 OSL_ENSURE(pServDlg, "Dialog create fail!");
2577 if ( pServDlg->Execute() == RET_OK )
2579 ScDPServiceDesc aServDesc(
2580 pServDlg->GetServiceName(),
2581 pServDlg->GetParSource(),
2582 pServDlg->GetParName(),
2583 pServDlg->GetParUser(),
2584 pServDlg->GetParPass() );
2585 pNewDPObject.reset(new ScDPObject(pDoc));
2586 pNewDPObject->SetServiceData( aServDesc );
2589 else if ( pTypeDlg->IsDatabase() )
2591 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2593 ::boost::scoped_ptr<AbstractScDataPilotDatabaseDlg> pDataDlg(
2594 pFact->CreateScDataPilotDatabaseDlg(
2595 pTabViewShell->GetDialogParent()));
2597 OSL_ENSURE(pDataDlg, "Dialog create fail!");
2598 if ( pDataDlg->Execute() == RET_OK )
2600 ScImportSourceDesc aImpDesc(pDoc);
2601 pDataDlg->GetValues( aImpDesc );
2602 pNewDPObject.reset(new ScDPObject(pDoc));
2603 pNewDPObject->SetImportDesc( aImpDesc );
2606 else if (pTypeDlg->IsNamedRange())
2608 OUString aName = pTypeDlg->GetSelectedNamedRange();
2609 ScSheetSourceDesc aShtDesc(pDoc);
2610 aShtDesc.SetRangeName(aName);
2611 nSrcErrorId = aShtDesc.CheckSourceRange();
2612 if (!nSrcErrorId)
2614 pNewDPObject.reset(new ScDPObject(pDoc));
2615 pNewDPObject->SetSheetDesc(aShtDesc);
2618 else // selection
2620 //! use database ranges (select before type dialog?)
2621 ScRange aRange;
2622 ScMarkType eType = GetViewData()->GetSimpleArea(aRange);
2623 if ( (eType & SC_MARK_SIMPLE) == SC_MARK_SIMPLE )
2625 // Shrink the range to the data area.
2626 SCCOL nStartCol = aRange.aStart.Col(), nEndCol = aRange.aEnd.Col();
2627 SCROW nStartRow = aRange.aStart.Row(), nEndRow = aRange.aEnd.Row();
2628 if (pDoc->ShrinkToDataArea(aRange.aStart.Tab(), nStartCol, nStartRow, nEndCol, nEndRow))
2630 aRange.aStart.SetCol(nStartCol);
2631 aRange.aStart.SetRow(nStartRow);
2632 aRange.aEnd.SetCol(nEndCol);
2633 aRange.aEnd.SetRow(nEndRow);
2634 rMark.SetMarkArea(aRange);
2635 pTabViewShell->MarkRange(aRange);
2638 bool bOK = true;
2639 if ( pDoc->HasSubTotalCells( aRange ) )
2641 // confirm selection if it contains SubTotal cells
2643 QueryBox aBox( pTabViewShell->GetDialogParent(),
2644 WinBits(WB_YES_NO | WB_DEF_YES),
2645 ScGlobal::GetRscString(STR_DATAPILOT_SUBTOTAL) );
2646 if (aBox.Execute() == RET_NO)
2647 bOK = false;
2649 if (bOK)
2651 ScSheetSourceDesc aShtDesc(pDoc);
2652 aShtDesc.SetSourceRange(aRange);
2653 nSrcErrorId = aShtDesc.CheckSourceRange();
2654 if (!nSrcErrorId)
2656 pNewDPObject.reset(new ScDPObject(pDoc));
2657 pNewDPObject->SetSheetDesc( aShtDesc );
2660 // output below source data
2661 if ( aRange.aEnd.Row()+2 <= MAXROW - 4 )
2662 aDestPos = ScAddress( aRange.aStart.Col(),
2663 aRange.aEnd.Row()+2,
2664 aRange.aStart.Tab() );
2670 if (nSrcErrorId)
2672 // Error occurred during data creation. Launch an error and bail out.
2673 InfoBox aBox(pTabViewShell->GetDialogParent(), ScGlobal::GetRscString(nSrcErrorId));
2674 aBox.Execute();
2675 return;
2678 if ( pNewDPObject )
2679 pNewDPObject->SetOutRange( aDestPos );
2682 pTabViewShell->SetDialogDPObject( pNewDPObject.get() ); // is copied
2683 if ( pNewDPObject )
2685 // start layout dialog
2687 sal_uInt16 nId = ScPivotLayoutWrapper::GetChildWindowId();
2688 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
2689 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
2690 pScMod->SetRefDialog( nId, pWnd ? false : true );
2694 void ScCellShell::ExecuteXMLSourceDialog()
2696 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2697 if (!pFact)
2698 return;
2700 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2701 if (!pTabViewShell)
2702 return;
2704 ScModule* pScMod = SC_MOD();
2706 sal_uInt16 nId = ScXMLSourceDlgWrapper::GetChildWindowId();
2707 SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame();
2708 SfxChildWindow* pWnd = pViewFrame->GetChildWindow(nId);
2709 pScMod->SetRefDialog(nId, pWnd ? false : true);
2712 void ScCellShell::ExecuteSubtotals(SfxRequest& rReq)
2714 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2715 const SfxItemSet* pArgs = rReq.GetArgs();
2716 if ( pArgs )
2718 pTabViewShell->DoSubTotals( ((const ScSubTotalItem&) pArgs->Get( SCITEM_SUBTDATA )).
2719 GetSubTotalData() );
2720 rReq.Done();
2721 return;
2724 boost::scoped_ptr<SfxAbstractTabDialog> pDlg;
2725 ScSubTotalParam aSubTotalParam;
2726 SfxItemSet aArgSet( GetPool(), SCITEM_SUBTDATA, SCITEM_SUBTDATA );
2728 // Only get existing named database range.
2729 ScDBData* pDBData = pTabViewShell->GetDBData(true, SC_DB_OLD);
2730 if (!pDBData)
2732 // No existing DB data at this position. Create an
2733 // anonymous DB.
2734 pDBData = pTabViewShell->GetAnonymousDBData();
2735 ScRange aDataRange;
2736 pDBData->GetArea(aDataRange);
2737 pTabViewShell->MarkRange(aDataRange, false);
2740 pDBData->GetSubTotalParam( aSubTotalParam );
2741 aSubTotalParam.bRemoveOnly = false;
2743 aArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA, GetViewData(), &aSubTotalParam ) );
2744 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2745 assert(pFact); //"ScAbstractFactory create fail
2747 pDlg.reset(pFact->CreateScSubTotalDlg(pTabViewShell->GetDialogParent(), &aArgSet));
2748 assert(pDlg); // "Dialog create fail
2749 pDlg->SetCurPageId(1);
2751 short bResult = pDlg->Execute();
2753 if ( (bResult == RET_OK) || (bResult == SCRET_REMOVE) )
2755 const SfxItemSet* pOutSet = NULL;
2757 if ( bResult == RET_OK )
2759 pOutSet = pDlg->GetOutputItemSet();
2760 aSubTotalParam =
2761 ((const ScSubTotalItem&)
2762 pOutSet->Get( SCITEM_SUBTDATA )).
2763 GetSubTotalData();
2765 else // if (bResult == SCRET_REMOVE)
2767 pOutSet = &aArgSet;
2768 aSubTotalParam.bRemoveOnly = true;
2769 aSubTotalParam.bReplace = true;
2770 aArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA,
2771 GetViewData(),
2772 &aSubTotalParam ) );
2775 pTabViewShell->DoSubTotals( aSubTotalParam );
2776 rReq.Done( *pOutSet );
2778 else
2779 GetViewData()->GetDocShell()->CancelAutoDBRange();
2782 void ScCellShell::ExecuteFillSingleEdit()
2784 ScAddress aCurPos = GetViewData()->GetCurPos();
2786 OUString aInit;
2788 if (aCurPos.Row() > 0)
2790 // Get the initial text value from the above cell.
2792 ScDocument* pDoc = GetViewData()->GetDocument();
2793 ScRefCellValue aCell;
2794 ScAddress aPrevPos = aCurPos;
2795 aPrevPos.IncRow(-1);
2796 aCell.assign(*pDoc, aPrevPos);
2798 if (aCell.meType == CELLTYPE_FORMULA)
2800 aInit = "=";
2801 const ScTokenArray* pCode = aCell.mpFormula->GetCode();
2802 sc::TokenStringContext aCxt(pDoc, pDoc->GetGrammar());
2803 aInit += pCode->CreateString(aCxt, aCurPos);
2805 else
2806 aInit = aCell.getString(pDoc);
2809 SC_MOD()->SetInputMode(SC_INPUT_TABLE, &aInit);
2812 IMPL_LINK_NOARG(ScCellShell, DialogClosed)
2814 OSL_ENSURE( pImpl->m_pLinkedDlg, "ScCellShell::DialogClosed(): invalid request" );
2815 OSL_ENSURE( pImpl->m_pRequest, "ScCellShell::DialogClosed(): invalid request" );
2816 OUString sFile, sFilter, sOptions, sSource;
2817 sal_uLong nRefresh = 0;
2819 if ( pImpl->m_pLinkedDlg->GetResult() == RET_OK )
2821 sFile = pImpl->m_pLinkedDlg->GetURL();
2822 sFilter = pImpl->m_pLinkedDlg->GetFilter();
2823 sOptions = pImpl->m_pLinkedDlg->GetOptions();
2824 sSource = pImpl->m_pLinkedDlg->GetSource();
2825 nRefresh = pImpl->m_pLinkedDlg->GetRefresh();
2826 if ( !sFile.isEmpty() )
2827 pImpl->m_pRequest->AppendItem( SfxStringItem( SID_FILE_NAME, sFile ) );
2828 if ( !sFilter.isEmpty() )
2829 pImpl->m_pRequest->AppendItem( SfxStringItem( SID_FILTER_NAME, sFilter ) );
2830 if ( !sOptions.isEmpty() )
2831 pImpl->m_pRequest->AppendItem( SfxStringItem( SID_FILE_FILTEROPTIONS, sOptions ) );
2832 if ( !sSource.isEmpty() )
2833 pImpl->m_pRequest->AppendItem( SfxStringItem( FN_PARAM_1, sSource ) );
2834 if ( nRefresh )
2835 pImpl->m_pRequest->AppendItem( SfxUInt32Item( FN_PARAM_2, nRefresh ) );
2838 ExecuteExternalSource( sFile, sFilter, sOptions, sSource, nRefresh, *(pImpl->m_pRequest) );
2839 return 0;
2842 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */