GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / sc / source / ui / view / cellsh1.cxx
blob5b3c6b9f5dd85835e4202aa016a3d50c5c6cda33
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"
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 OUString aFlags;
177 if( pReqArgs->HasItem( FID_INS_CELL, &pItem ) )
178 aFlags = ((const SfxStringItem*)pItem)->GetValue();
179 if( !aFlags.isEmpty() )
181 switch( aFlags[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 OUString 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 OUString aFlags;
247 if( pReqArgs->HasItem( FID_DELETE_CELL, &pItem ) )
248 aFlags = ((const SfxStringItem*)pItem)->GetValue();
249 if( !aFlags.isEmpty() )
251 switch( aFlags[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 OUString 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 OUString aFlags('A');
330 if( pReqArgs->HasItem( SID_DELETE, &pItem ) )
331 aFlags = ((const SfxStringItem*)pItem)->GetValue();
333 aFlags = aFlags.toAsciiUpperCase();
334 sal_Bool bCont = sal_True;
336 for (sal_Int32 i=0 ; bCont && i<aFlags.getLength(); ++i)
338 switch (aFlags[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 OUString 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 OUString aFlags('A');
444 if( pReqArgs->HasItem( FID_FILL_TAB, &pItem ) )
445 aFlags = ((const SfxStringItem*)pItem)->GetValue();
447 aFlags = aFlags.toAsciiUpperCase();
448 sal_Bool bCont = sal_True;
450 for (sal_Int32 i=0; bCont && i < aFlags.getLength(); ++i)
452 switch (aFlags[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 OUString 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 OUString aFillDir, aFillCmd, aFillDateCmd;
557 OUString 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.isEmpty() )
577 switch( aFillDir[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.isEmpty() )
586 switch( aFillCmd[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.isEmpty() )
596 switch( aFillDateCmd[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 OUString aStartStr;
646 // suggest default Startvalue only, when just 1 row or column
647 if ( nStartCol == nEndCol || nStartRow == nEndRow )
649 double fInputEndVal = 0.0;
650 OUString 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.isEmpty())
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.isEmpty())
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 OSL_ENSURE(pDlg, "Dialog create fail!");
712 if ( nStartCol != nEndCol && nStartRow != nEndRow )
714 pDlg->SetEdStartValEnabled(false);
717 if ( pDlg->Execute() == RET_OK )
719 eFillDir = pDlg->GetFillDir();
720 eFillCmd = pDlg->GetFillCmd();
721 eFillDateCmd = pDlg->GetFillDateCmd();
723 if(eFillCmd==FILL_AUTO)
725 OUString aStr = pDlg->GetStartStr();
726 if(!aStr.isEmpty())
727 pTabViewShell->EnterData( nStartCol, nStartRow, nStartTab, aStr );
729 fStartVal = pDlg->GetStart();
730 fIncVal = pDlg->GetStep();
731 fMaxVal = pDlg->GetMax();
732 bDoIt = sal_True;
734 delete pDlg;
737 if( bDoIt )
739 //nScFillModeMouseModifier = 0; // no Ctrl/Copy
740 pTabViewShell->FillSeries( eFillDir, eFillCmd, eFillDateCmd, fStartVal, fIncVal, fMaxVal );
742 if( ! rReq.IsAPI() )
744 OUString aPara;
745 Color* pColor=0;
747 switch( eFillDir )
749 case FILL_TO_BOTTOM: aPara = "B"; break;
750 case FILL_TO_RIGHT: aPara = "R"; break;
751 case FILL_TO_TOP: aPara = "T"; break;
752 case FILL_TO_LEFT: aPara = "L"; break;
753 default: break;
755 rReq.AppendItem( SfxStringItem( FID_FILL_SERIES, aPara ) );
757 switch( eFillCmd )
759 case FILL_SIMPLE: aPara = "S"; break;
760 case FILL_LINEAR: aPara = "L"; break;
761 case FILL_GROWTH: aPara = "G"; break;
762 case FILL_DATE: aPara = "D"; break;
763 case FILL_AUTO: aPara = "A"; break;
764 default: break;
766 rReq.AppendItem( SfxStringItem( FN_PARAM_1, aPara ) );
768 switch( eFillDateCmd )
770 case FILL_DAY: aPara = "D"; break;
771 case FILL_WEEKDAY: aPara = "W"; break;
772 case FILL_MONTH: aPara = "M"; break;
773 case FILL_YEAR: aPara = "Y"; break;
774 default: break;
776 rReq.AppendItem( SfxStringItem( FN_PARAM_2, aPara ) );
778 sal_uLong nFormatKey = pFormatter->GetStandardFormat(NUMBERFORMAT_NUMBER,
779 ScGlobal::eLnge );
781 pFormatter->GetOutputString( fIncVal, nFormatKey, aPara, &pColor );
782 rReq.AppendItem( SfxStringItem( FN_PARAM_3, aPara ) );
784 pFormatter->GetOutputString( fStartVal, nFormatKey, aPara, &pColor );
785 rReq.AppendItem( SfxStringItem( FN_PARAM_4, aPara ) );
787 pFormatter->GetOutputString( fMaxVal, nFormatKey, aPara, &pColor );
788 rReq.AppendItem( SfxStringItem( FN_PARAM_5, aPara ) );
790 rReq.Done();
794 break;
796 case FID_FILL_AUTO:
798 SCCOL nStartCol;
799 SCROW nStartRow;
800 SCCOL nEndCol;
801 SCROW nEndRow;
802 SCTAB nStartTab, nEndTab;
804 GetViewData()->GetFillData( nStartCol, nStartRow, nEndCol, nEndRow );
805 SCCOL nFillCol = GetViewData()->GetRefEndX();
806 SCROW nFillRow = GetViewData()->GetRefEndY();
807 ScDocument* pDoc = GetViewData()->GetDocument();
809 if( pReqArgs != NULL )
811 const SfxPoolItem* pItem;
813 if( pReqArgs->HasItem( FID_FILL_AUTO, &pItem ) )
815 ScAddress aScAddress;
816 OUString aArg = ((const SfxStringItem*)pItem)->GetValue();
818 if( aScAddress.Parse( aArg, pDoc, pDoc->GetAddressConvention() ) & SCA_VALID )
820 nFillRow = aScAddress.Row();
821 nFillCol = aScAddress.Col();
825 GetViewData()->GetSimpleArea( nStartCol,nStartRow,nStartTab,
826 nEndCol,nEndRow,nEndTab );
828 else // call via mouse
830 // not in a merged cell
832 if ( nStartCol == nEndCol && nStartRow == nEndRow )
834 SCCOL nMergeCol = nStartCol;
835 SCROW nMergeRow = nStartRow;
836 if ( GetViewData()->GetDocument()->ExtendMerge(
837 nStartCol, nStartRow, nMergeCol, nMergeRow,
838 GetViewData()->GetTabNo() ) )
840 if ( nFillCol >= nStartCol && nFillCol <= nMergeCol && nFillRow == nStartRow )
841 nFillCol = nStartCol;
842 if ( nFillRow >= nStartRow && nFillRow <= nMergeRow && nFillCol == nStartCol )
843 nFillRow = nStartRow;
848 if ( nFillCol != nEndCol || nFillRow != nEndRow )
850 if ( nFillCol==nEndCol || nFillRow==nEndRow )
852 FillDir eDir = FILL_TO_BOTTOM;
853 SCCOLROW nCount = 0;
855 if ( nFillCol==nEndCol )
857 if ( nFillRow > nEndRow )
859 eDir = FILL_TO_BOTTOM;
860 nCount = nFillRow - nEndRow;
862 else if ( nFillRow < nStartRow )
864 eDir = FILL_TO_TOP;
865 nCount = nStartRow - nFillRow;
868 else
870 if ( nFillCol > nEndCol )
872 eDir = FILL_TO_RIGHT;
873 nCount = nFillCol - nEndCol;
875 else if ( nFillCol < nStartCol )
877 eDir = FILL_TO_LEFT;
878 nCount = nStartCol - nFillCol;
882 if ( nCount != 0)
884 pTabViewShell->FillAuto( eDir, nStartCol, nStartRow, nEndCol, nEndRow, nCount );
886 if( ! rReq.IsAPI() )
888 ScAddress aAdr( nFillCol, nFillRow, 0 );
889 OUString aAdrStr(aAdr.Format(SCR_ABS, pDoc, pDoc->GetAddressConvention()));
891 rReq.AppendItem( SfxStringItem( FID_FILL_AUTO, aAdrStr ) );
892 rReq.Done();
897 else
899 OSL_FAIL( "Direction not unique for autofill" );
903 break;
904 case SID_RANDOM_NUMBER_GENERATOR_DIALOG:
906 sal_uInt16 nId = ScRandomNumberGeneratorDialogWrapper::GetChildWindowId();
907 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
908 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
910 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
913 break;
914 case SID_SAMPLING_DIALOG:
916 sal_uInt16 nId = ScSamplingDialogWrapper::GetChildWindowId();
917 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
918 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
920 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
922 break;
923 case SID_DESCRIPTIVE_STATISTICS_DIALOG:
925 sal_uInt16 nId = ScDescriptiveStatisticsDialogWrapper::GetChildWindowId();
926 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
927 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
929 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
931 break;
932 case SID_ANALYSIS_OF_VARIANCE_DIALOG:
934 sal_uInt16 nId = ScAnalysisOfVarianceDialogWrapper::GetChildWindowId();
935 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
936 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
938 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
940 break;
941 case SID_CORRELATION_DIALOG:
943 sal_uInt16 nId = ScCorrelationDialogWrapper::GetChildWindowId();
944 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
945 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
947 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
949 break;
950 case SID_COVARIANCE_DIALOG:
952 sal_uInt16 nId = ScCovarianceDialogWrapper::GetChildWindowId();
953 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
954 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
956 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
958 break;
959 case SID_EXPONENTIAL_SMOOTHING_DIALOG:
961 sal_uInt16 nId = ScExponentialSmoothingDialogWrapper::GetChildWindowId();
962 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
963 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
965 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
967 break;
968 case SID_MOVING_AVERAGE_DIALOG:
970 sal_uInt16 nId = ScMovingAverageDialogWrapper::GetChildWindowId();
971 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
972 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
974 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
976 break;
979 // disposal (Outlines)
980 // SID_AUTO_OUTLINE, SID_OUTLINE_DELETEALL in Execute (in docsh.idl)
983 case SID_OUTLINE_HIDE:
984 if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
985 GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
986 pTabViewShell->SetDataPilotDetails( false );
987 else
988 pTabViewShell->HideMarkedOutlines();
989 rReq.Done();
990 break;
992 case SID_OUTLINE_SHOW:
994 ScDPObject* pDPObj = GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
995 GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
996 if ( pDPObj )
998 Sequence<sheet::DataPilotFieldFilter> aFilters;
999 sal_uInt16 nOrientation;
1000 if ( pTabViewShell->HasSelectionForDrillDown( nOrientation ) )
1002 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1003 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1005 AbstractScDPShowDetailDlg* pDlg = pFact->CreateScDPShowDetailDlg(
1006 pTabViewShell->GetDialogParent(), RID_SCDLG_DPSHOWDETAIL, *pDPObj, nOrientation );
1007 OSL_ENSURE(pDlg, "Dialog create fail!");
1008 if ( pDlg->Execute() == RET_OK )
1010 OUString aNewDimName( pDlg->GetDimensionName() );
1011 pTabViewShell->SetDataPilotDetails( true, &aNewDimName );
1014 else if ( !pDPObj->IsServiceData() &&
1015 pDPObj->GetDataFieldPositionData(
1016 ScAddress( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() ),
1017 aFilters ) )
1018 pTabViewShell->ShowDataPilotSourceData( *pDPObj, aFilters );
1019 else
1020 pTabViewShell->SetDataPilotDetails(true);
1022 else
1023 pTabViewShell->ShowMarkedOutlines();
1024 rReq.Done();
1026 break;
1028 case SID_OUTLINE_MAKE:
1030 sal_Bool bColumns = false;
1031 sal_Bool bOk = sal_True;
1033 if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
1034 GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
1036 ScDPNumGroupInfo aNumInfo;
1037 aNumInfo.mbEnable = true;
1038 aNumInfo.mbAutoStart = true;
1039 aNumInfo.mbAutoEnd = true;
1040 sal_Int32 nParts = 0;
1041 if ( pTabViewShell->HasSelectionForDateGroup( aNumInfo, nParts ) )
1043 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1044 OSL_ENSURE( pFact, "ScAbstractFactory create fail!" );
1045 Date aNullDate( *GetViewData()->GetDocument()->GetFormatTable()->GetNullDate() );
1046 AbstractScDPDateGroupDlg* pDlg = pFact->CreateScDPDateGroupDlg(
1047 pTabViewShell->GetDialogParent(), RID_SCDLG_DPDATEGROUP,
1048 aNumInfo, nParts, aNullDate );
1049 OSL_ENSURE( pDlg, "Dialog create fail!" );
1050 if( pDlg->Execute() == RET_OK )
1052 aNumInfo = pDlg->GetGroupInfo();
1053 pTabViewShell->DateGroupDataPilot( aNumInfo, pDlg->GetDatePart() );
1056 else if ( pTabViewShell->HasSelectionForNumGroup( aNumInfo ) )
1058 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1059 OSL_ENSURE( pFact, "ScAbstractFactory create fail!" );
1060 AbstractScDPNumGroupDlg* pDlg = pFact->CreateScDPNumGroupDlg(
1061 pTabViewShell->GetDialogParent(), RID_SCDLG_DPNUMGROUP, aNumInfo );
1062 OSL_ENSURE( pDlg, "Dialog create fail!" );
1063 if( pDlg->Execute() == RET_OK )
1064 pTabViewShell->NumGroupDataPilot( pDlg->GetGroupInfo() );
1066 else
1067 pTabViewShell->GroupDataPilot();
1069 bOk = false;
1071 else if( pReqArgs != NULL )
1073 const SfxPoolItem* pItem;
1074 bOk = false;
1076 if( pReqArgs->HasItem( SID_OUTLINE_MAKE, &pItem ) )
1078 OUString aCol = ((const SfxStringItem*)pItem)->GetValue();
1079 aCol = aCol.toAsciiUpperCase();
1081 switch( aCol[0] )
1083 case 'R': bColumns=false; bOk = true;break;
1084 case 'C': bColumns=true; bOk = true;break;
1088 else // Dialog, when not whole rows/columns are marked
1090 if ( GetViewData()->SimpleColMarked() && !GetViewData()->SimpleRowMarked() )
1091 bColumns = sal_True;
1092 else if ( !GetViewData()->SimpleColMarked() && GetViewData()->SimpleRowMarked() )
1093 bColumns = false;
1094 else
1096 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1097 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1099 AbstractScGroupDlg* pDlg = pFact->CreateAbstractScGroupDlg(pTabViewShell->GetDialogParent(), false);
1100 OSL_ENSURE(pDlg, "Dialog create fail!");
1101 if ( pDlg->Execute() == RET_OK )
1102 bColumns = pDlg->GetColsChecked();
1103 else
1104 bOk = false;
1105 delete pDlg;
1108 if (bOk)
1110 pTabViewShell->MakeOutline( bColumns );
1112 if( ! rReq.IsAPI() )
1114 OUString aCol = bColumns ? OUString('C') : OUString('R');
1115 rReq.AppendItem( SfxStringItem( SID_OUTLINE_MAKE, aCol ) );
1116 rReq.Done();
1120 break;
1122 case SID_OUTLINE_REMOVE:
1124 sal_Bool bColumns = false;
1125 sal_Bool bOk = sal_True;
1127 if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
1128 GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
1130 pTabViewShell->UngroupDataPilot();
1131 bOk = false;
1133 else if( pReqArgs != NULL )
1135 const SfxPoolItem* pItem;
1136 bOk = false;
1138 if( pReqArgs->HasItem( SID_OUTLINE_REMOVE, &pItem ) )
1140 OUString aCol = ((const SfxStringItem*)pItem)->GetValue();
1141 aCol = aCol.toAsciiUpperCase();
1143 switch (aCol[0])
1145 case 'R': bColumns=false; bOk = true;break;
1146 case 'C': bColumns=true; bOk = true;break;
1150 else // Dialog only when removal for rows and columns is possible
1152 sal_Bool bColPoss, bRowPoss;
1153 pTabViewShell->TestRemoveOutline( bColPoss, bRowPoss );
1154 if ( bColPoss && bRowPoss )
1156 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1157 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1159 AbstractScGroupDlg* pDlg = pFact->CreateAbstractScGroupDlg(pTabViewShell->GetDialogParent(), true);
1160 OSL_ENSURE(pDlg, "Dialog create fail!");
1161 if ( pDlg->Execute() == RET_OK )
1162 bColumns = pDlg->GetColsChecked();
1163 else
1164 bOk = false;
1165 delete pDlg;
1167 else if ( bColPoss )
1168 bColumns = sal_True;
1169 else if ( bRowPoss )
1170 bColumns = false;
1171 else
1172 bOk = false;
1174 if (bOk)
1176 pTabViewShell->RemoveOutline( bColumns );
1178 if( ! rReq.IsAPI() )
1180 OUString aCol = bColumns ? OUString('C') : OUString('R');
1181 rReq.AppendItem( SfxStringItem( SID_OUTLINE_REMOVE, aCol ) );
1182 rReq.Done();
1186 break;
1189 // Clipboard
1193 case SID_COPY: // for graphs in DrawShell
1195 WaitObject aWait( GetViewData()->GetDialogParent() );
1196 pTabViewShell->CopyToClip( NULL, false, false, true );
1197 rReq.Done();
1198 GetViewData()->SetPasteMode( (ScPasteFlags) (SC_PASTE_MODE | SC_PASTE_BORDER) );
1199 pTabViewShell->ShowCursor();
1200 pTabViewShell->UpdateCopySourceOverlay();
1202 break;
1204 case SID_CUT: // for graphs in DrawShell
1206 WaitObject aWait( GetViewData()->GetDialogParent() );
1207 pTabViewShell->CutToClip( NULL, true );
1208 rReq.Done();
1209 GetViewData()->SetPasteMode( (ScPasteFlags)(SC_PASTE_MODE | SC_PASTE_BORDER));
1210 pTabViewShell->ShowCursor();
1211 pTabViewShell->UpdateCopySourceOverlay();
1213 break;
1215 case SID_PASTE:
1217 ScClipUtil::PasteFromClipboard ( GetViewData(), pTabViewShell, true );
1218 rReq.Done();
1220 break;
1222 case SID_CLIPBOARD_FORMAT_ITEMS:
1224 WaitObject aWait( GetViewData()->GetDialogParent() );
1226 sal_uLong nFormat = 0;
1227 const SfxPoolItem* pItem;
1228 if ( pReqArgs &&
1229 pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET &&
1230 pItem->ISA(SfxUInt32Item) )
1232 nFormat = ((const SfxUInt32Item*)pItem)->GetValue();
1235 if ( nFormat )
1237 Window* pWin = GetViewData()->GetActiveWin();
1238 sal_Bool bCells = ( ScTransferObj::GetOwnClipboard( pWin ) != NULL );
1239 sal_Bool bDraw = ( ScDrawTransferObj::GetOwnClipboard( pWin ) != NULL );
1240 sal_Bool bOle = ( nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE );
1242 if ( bCells && bOle )
1243 pTabViewShell->PasteFromSystem();
1244 else if ( bDraw && bOle )
1245 pTabViewShell->PasteDraw();
1246 else
1247 pTabViewShell->PasteFromSystem(nFormat);
1249 //?else
1250 //? pTabViewShell->PasteFromSystem();
1252 rReq.Done();
1254 pTabViewShell->CellContentChanged();
1255 break;
1257 case FID_INS_CELL_CONTENTS:
1259 sal_uInt16 nFlags = IDF_NONE;
1260 sal_uInt16 nFunction = PASTE_NOFUNC;
1261 sal_Bool bSkipEmpty = false;
1262 sal_Bool bTranspose = false;
1263 sal_Bool bAsLink = false;
1264 InsCellCmd eMoveMode = INS_NONE;
1266 Window* pWin = GetViewData()->GetActiveWin();
1267 ScDocument* pDoc = GetViewData()->GetDocument();
1268 sal_Bool bOtherDoc = !pDoc->IsClipboardSource();
1269 ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin );
1270 if ( pOwnClip )
1272 // keep a reference in case the clipboard is changed during dialog or PasteFromClip
1273 uno::Reference<datatransfer::XTransferable> aOwnClipRef( pOwnClip );
1274 if ( pReqArgs!=NULL && pTabViewShell->SelectionEditable() )
1276 const SfxPoolItem* pItem;
1277 OUString aFlags('A');
1279 if( pReqArgs->HasItem( FID_INS_CELL_CONTENTS, &pItem ) )
1280 aFlags = ((const SfxStringItem*)pItem)->GetValue();
1282 aFlags = aFlags.toAsciiUpperCase();
1283 sal_Bool bCont = sal_True;
1285 for (sal_Int32 i=0 ; bCont && i<aFlags.getLength(); ++i)
1287 switch (aFlags[i])
1289 case 'A': // all
1290 nFlags |= IDF_ALL;
1291 bCont = false; // don't continue!
1292 break;
1293 case 'S': nFlags |= IDF_STRING; break;
1294 case 'V': nFlags |= IDF_VALUE; break;
1295 case 'D': nFlags |= IDF_DATETIME; break;
1296 case 'F': nFlags |= IDF_FORMULA; break;
1297 case 'N': nFlags |= IDF_NOTE; break;
1298 case 'T': nFlags |= IDF_ATTRIB; break;
1302 SFX_REQUEST_ARG( rReq, pFuncItem, SfxUInt16Item, FN_PARAM_1, false );
1303 SFX_REQUEST_ARG( rReq, pSkipItem, SfxBoolItem, FN_PARAM_2, false );
1304 SFX_REQUEST_ARG( rReq, pTransposeItem, SfxBoolItem, FN_PARAM_3, false );
1305 SFX_REQUEST_ARG( rReq, pLinkItem, SfxBoolItem, FN_PARAM_4, false );
1306 SFX_REQUEST_ARG( rReq, pMoveItem, SfxInt16Item, FN_PARAM_5, false );
1307 if ( pFuncItem )
1308 nFunction = pFuncItem->GetValue();
1309 if ( pSkipItem )
1310 bSkipEmpty = pSkipItem->GetValue();
1311 if ( pTransposeItem )
1312 bTranspose = pTransposeItem->GetValue();
1313 if ( pLinkItem )
1314 bAsLink = pLinkItem->GetValue();
1315 if ( pMoveItem )
1316 eMoveMode = (InsCellCmd) pMoveItem->GetValue();
1318 else
1320 ScEditableTester aTester( pTabViewShell );
1321 if (aTester.IsEditable())
1323 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1324 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1326 AbstractScInsertContentsDlg* pDlg = pFact->CreateScInsertContentsDlg( pTabViewShell->GetDialogParent(),
1327 RID_SCDLG_INSCONT);
1328 OSL_ENSURE(pDlg, "Dialog create fail!");
1329 pDlg->SetOtherDoc( bOtherDoc );
1330 // if ChangeTrack MoveMode disable
1331 pDlg->SetChangeTrack( pDoc->GetChangeTrack() != NULL );
1332 // fdo#56098 disable shift if necessary
1333 if ( !bOtherDoc && pOwnClip )
1335 ScViewData* pData = GetViewData();
1336 if ( pData->GetMarkData().GetTableSelect( pData->GetTabNo() ) )
1338 SCCOL nStartX, nEndX, nClipStartX, nClipSizeX, nRangeSizeX;
1339 SCROW nStartY, nEndY, nClipStartY, nClipSizeY, nRangeSizeY;
1340 SCTAB nStartTab, nEndTab;
1341 pOwnClip->GetDocument()->GetClipStart( nClipStartX, nClipStartY );
1342 pOwnClip->GetDocument()->GetClipArea( nClipSizeX, nClipSizeY, sal_True );
1344 if ( !( pData->GetSimpleArea( nStartX, nStartY, nStartTab,
1345 nEndX, nEndY, nEndTab ) == SC_MARK_SIMPLE &&
1346 nStartTab == nEndTab ) )
1348 // the destination is not a simple range,
1349 // assume the destination as the current cell
1350 nStartX = nEndX = pData->GetCurX();
1351 nStartY = nEndY = pData->GetCurY();
1352 nStartTab = pData->GetTabNo();
1354 // we now have clip- and range dimensions
1355 // the size of the destination area is the larger of the two
1356 nRangeSizeX = nClipSizeX >= nEndX - nStartX ? nClipSizeX : nEndX - nStartX;
1357 nRangeSizeY = nClipSizeY >= nEndY - nStartY ? nClipSizeY : nEndY - nStartY;
1358 // When the source and destination areas intersect things may go wrong,
1359 // especially if the area contains references. This may produce data loss
1360 // (e.g. formulas that get wrong references), this scenario _must_ be avoided.
1361 ScRange aSource( nClipStartX, nClipStartY, nStartTab,
1362 nClipStartX + nClipSizeX, nClipStartY + nClipSizeY, nStartTab );
1363 ScRange aDest( nStartX, nStartY, nStartTab,
1364 nStartX + nRangeSizeX, nStartY + nRangeSizeY, nStartTab );
1365 if ( pOwnClip->GetDocument()->IsCutMode() && aSource.Intersects( aDest ) )
1366 pDlg->SetCellShiftDisabled( SC_CELL_SHIFT_DISABLE_DOWN | SC_CELL_SHIFT_DISABLE_RIGHT );
1367 else
1369 //no conflict with intersecting ranges,
1370 //check if paste plus shift will fit on sheet
1371 //and disable shift-option if no fit
1372 int nDisableShiftX = 0;
1373 int nDisableShiftY = 0;
1375 //check if horizontal shift will fit
1376 if ( !pData->GetDocument()->IsBlockEmpty( nStartTab,
1377 MAXCOL - nRangeSizeX, nStartY,
1378 MAXCOL, nStartY + nRangeSizeY, false ) )
1379 nDisableShiftX = SC_CELL_SHIFT_DISABLE_RIGHT;
1381 //check if vertical shift will fit
1382 if ( !pData->GetDocument()->IsBlockEmpty( nStartTab,
1383 nStartX, MAXROW - nRangeSizeY,
1384 nStartX + nRangeSizeX, MAXROW, false ) )
1385 nDisableShiftY = SC_CELL_SHIFT_DISABLE_DOWN;
1387 if ( nDisableShiftX || nDisableShiftY )
1388 pDlg->SetCellShiftDisabled( nDisableShiftX | nDisableShiftY );
1392 if (pDlg->Execute() == RET_OK)
1394 nFlags = pDlg->GetInsContentsCmdBits();
1395 nFunction = pDlg->GetFormulaCmdBits();
1396 bSkipEmpty = pDlg->IsSkipEmptyCells();
1397 bTranspose = pDlg->IsTranspose();
1398 bAsLink = pDlg->IsLink();
1399 eMoveMode = pDlg->GetMoveMode();
1401 delete pDlg;
1403 else
1404 pTabViewShell->ErrorMessage(aTester.GetMessageId());
1407 if( nFlags != IDF_NONE )
1410 WaitObject aWait( GetViewData()->GetDialogParent() );
1411 if ( bAsLink && bOtherDoc )
1412 pTabViewShell->PasteFromSystem(SOT_FORMATSTR_ID_LINK); // DDE insert
1413 else
1415 pTabViewShell->PasteFromClip( nFlags, pOwnClip->GetDocument(),
1416 nFunction, bSkipEmpty, bTranspose, bAsLink,
1417 eMoveMode, IDF_NONE, sal_True ); // allow warning dialog
1421 if( !pReqArgs )
1423 OUString aFlags;
1425 if( nFlags == IDF_ALL )
1427 aFlags += "A";
1429 else
1431 if( nFlags & IDF_STRING ) aFlags += "S";
1432 if( nFlags & IDF_VALUE ) aFlags += "V";
1433 if( nFlags & IDF_DATETIME ) aFlags += "D";
1434 if( nFlags & IDF_FORMULA ) aFlags += "F";
1435 if( nFlags & IDF_NOTE ) aFlags += "N";
1436 if( nFlags & IDF_ATTRIB ) aFlags += "T";
1439 rReq.AppendItem( SfxStringItem( FID_INS_CELL_CONTENTS, aFlags ) );
1440 rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bSkipEmpty ) );
1441 rReq.AppendItem( SfxBoolItem( FN_PARAM_3, bTranspose ) );
1442 rReq.AppendItem( SfxBoolItem( FN_PARAM_4, bAsLink ) );
1443 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, nFunction ) );
1444 rReq.AppendItem( SfxInt16Item( FN_PARAM_5, (sal_Int16) eMoveMode ) );
1445 rReq.Done();
1450 pTabViewShell->CellContentChanged(); // => PasteFromXXX ???
1451 break;
1452 case SID_PASTE_ONLY_VALUE:
1453 case SID_PASTE_ONLY_TEXT:
1454 case SID_PASTE_ONLY_FORMULA:
1456 Window* pWin = GetViewData()->GetActiveWin();
1457 if ( ScTransferObj::GetOwnClipboard( pWin ) ) // own cell data
1459 rReq.SetSlot( FID_INS_CELL_CONTENTS );
1460 OUString aFlags;
1461 if ( nSlot == SID_PASTE_ONLY_VALUE )
1462 aFlags = "V";
1463 else if ( nSlot == SID_PASTE_ONLY_TEXT )
1464 aFlags = "S";
1465 else
1466 aFlags = "F";
1467 rReq.AppendItem( SfxStringItem( FID_INS_CELL_CONTENTS, aFlags ) );
1468 ExecuteSlot( rReq, GetInterface() );
1469 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
1470 pTabViewShell->CellContentChanged();
1472 else
1473 rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1474 break;
1476 case SID_PASTE_SPECIAL:
1477 // differentiate between own cell data and draw objects/external data
1478 // this makes FID_INS_CELL_CONTENTS superfluous
1480 Window* pWin = GetViewData()->GetActiveWin();
1482 // Clipboard-ID given as parameter? Basic "PasteSpecial(Format)"
1483 const SfxPoolItem* pItem=NULL;
1484 if ( pReqArgs &&
1485 pReqArgs->GetItemState(nSlot, sal_True, &pItem) == SFX_ITEM_SET &&
1486 pItem->ISA(SfxUInt32Item) )
1488 sal_uLong nFormat = ((const SfxUInt32Item*)pItem)->GetValue();
1489 sal_Bool bRet=sal_True;
1491 WaitObject aWait( GetViewData()->GetDialogParent() );
1492 sal_Bool bDraw = ( ScDrawTransferObj::GetOwnClipboard( pWin ) != NULL );
1493 if ( bDraw && nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE )
1494 pTabViewShell->PasteDraw();
1495 else
1496 bRet = pTabViewShell->PasteFromSystem(nFormat, sal_True); // TRUE: no error messages
1499 if ( bRet )
1501 rReq.SetReturnValue(SfxInt16Item(nSlot, bRet)); // 1 = success, 0 = fail
1502 rReq.Done();
1504 else
1505 // if format is not available -> fallback to request without parameters
1506 pItem = NULL;
1509 if ( !pItem )
1511 if ( ScTransferObj::GetOwnClipboard( pWin ) ) // own cell data
1513 rReq.SetSlot( FID_INS_CELL_CONTENTS );
1514 ExecuteSlot( rReq, GetInterface() );
1515 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
1517 else // draw objects or external data
1519 sal_Bool bDraw = ( ScDrawTransferObj::GetOwnClipboard( pWin ) != NULL );
1521 SvxClipboardFmtItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
1522 GetPossibleClipboardFormats( aFormats );
1524 sal_uInt16 nFormatCount = aFormats.Count();
1525 if ( nFormatCount )
1527 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1528 SfxAbstractPasteDialog* pDlg = pFact->CreatePasteDialog( pTabViewShell->GetDialogParent() );
1529 if ( pDlg )
1531 for (sal_uInt16 i=0; i<nFormatCount; i++)
1533 sal_uLong nFormatId = aFormats.GetClipbrdFormatId( i );
1534 OUString aName = aFormats.GetClipbrdFormatName( i );
1535 // special case for paste dialog: '*' is replaced by object type
1536 if ( nFormatId == SOT_FORMATSTR_ID_EMBED_SOURCE )
1537 aName = "*";
1538 pDlg->Insert( nFormatId, aName );
1541 TransferableDataHelper aDataHelper(
1542 TransferableDataHelper::CreateFromSystemClipboard( pWin ) );
1543 sal_uLong nFormat = pDlg->GetFormat( aDataHelper.GetTransferable() );
1544 if (nFormat > 0)
1547 WaitObject aWait( GetViewData()->GetDialogParent() );
1548 if ( bDraw && nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE )
1549 pTabViewShell->PasteDraw();
1550 else
1551 pTabViewShell->PasteFromSystem(nFormat);
1553 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
1554 rReq.AppendItem( SfxUInt32Item( nSlot, nFormat ) );
1555 rReq.Done();
1557 else
1559 rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1560 rReq.Ignore();
1563 delete pDlg;
1566 else
1567 rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1571 pTabViewShell->CellContentChanged(); // => PasteFromSystem() ???
1572 break;
1575 // other
1578 case FID_INS_ROWBRK:
1579 pTabViewShell->InsertPageBreak( false );
1580 rReq.Done();
1581 break;
1583 case FID_INS_COLBRK:
1584 pTabViewShell->InsertPageBreak( sal_True );
1585 rReq.Done();
1586 break;
1588 case FID_DEL_ROWBRK:
1589 pTabViewShell->DeletePageBreak( false );
1590 rReq.Done();
1591 break;
1593 case FID_DEL_COLBRK:
1594 pTabViewShell->DeletePageBreak( sal_True );
1595 rReq.Done();
1596 break;
1598 case SID_DETECTIVE_ADD_PRED:
1599 pTabViewShell->DetectiveAddPred();
1600 rReq.Done();
1601 break;
1603 case SID_DETECTIVE_DEL_PRED:
1604 pTabViewShell->DetectiveDelPred();
1605 rReq.Done();
1606 break;
1608 case SID_DETECTIVE_ADD_SUCC:
1609 pTabViewShell->DetectiveAddSucc();
1610 rReq.Done();
1611 break;
1613 case SID_DETECTIVE_DEL_SUCC:
1614 pTabViewShell->DetectiveDelSucc();
1615 rReq.Done();
1616 break;
1618 case SID_DETECTIVE_ADD_ERR:
1619 pTabViewShell->DetectiveAddError();
1620 rReq.Done();
1621 break;
1623 case SID_DETECTIVE_INVALID:
1624 pTabViewShell->DetectiveMarkInvalid();
1625 rReq.Done();
1626 break;
1628 case SID_DETECTIVE_REFRESH:
1629 pTabViewShell->DetectiveRefresh();
1630 rReq.Done();
1631 break;
1633 case SID_DETECTIVE_MARK_PRED:
1634 pTabViewShell->DetectiveMarkPred();
1635 break;
1636 case SID_DETECTIVE_MARK_SUCC:
1637 pTabViewShell->DetectiveMarkSucc();
1638 break;
1639 case SID_INSERT_CURRENT_DATE:
1640 pTabViewShell->InsertCurrentTime(
1641 NUMBERFORMAT_DATE, ScGlobal::GetRscString(STR_UNDO_INSERT_CURRENT_DATE));
1642 break;
1643 case SID_INSERT_CURRENT_TIME:
1644 pTabViewShell->InsertCurrentTime(
1645 NUMBERFORMAT_TIME, ScGlobal::GetRscString(STR_UNDO_INSERT_CURRENT_TIME));
1646 break;
1648 case SID_SPELL_DIALOG:
1650 SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame();
1651 if( rReq.GetArgs() )
1652 pViewFrame->SetChildWindow( SID_SPELL_DIALOG,
1653 static_cast< const SfxBoolItem& >( rReq.GetArgs()->
1654 Get( SID_SPELL_DIALOG ) ).GetValue() );
1655 else
1656 pViewFrame->ToggleChildWindow( SID_SPELL_DIALOG );
1658 pViewFrame->GetBindings().Invalidate( SID_SPELL_DIALOG );
1659 rReq.Ignore();
1661 break;
1663 case SID_HANGUL_HANJA_CONVERSION:
1664 pTabViewShell->DoHangulHanjaConversion();
1665 break;
1667 case SID_CHINESE_CONVERSION:
1669 //open ChineseTranslationDialog
1670 Reference< XComponentContext > xContext(
1671 ::cppu::defaultBootstrap_InitialComponentContext() ); //@todo get context from calc if that has one
1672 if(xContext.is())
1674 Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
1675 if(xMCF.is())
1677 Reference< ui::dialogs::XExecutableDialog > xDialog(
1678 xMCF->createInstanceWithContext(
1679 OUString("com.sun.star.linguistic2.ChineseTranslationDialog")
1680 , xContext), UNO_QUERY);
1681 Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
1682 if( xInit.is() )
1684 // initialize dialog
1685 Reference< awt::XWindow > xDialogParentWindow(0);
1686 Sequence<Any> aSeq(1);
1687 Any* pArray = aSeq.getArray();
1688 PropertyValue aParam;
1689 aParam.Name = "ParentWindow";
1690 aParam.Value <<= makeAny(xDialogParentWindow);
1691 pArray[0] <<= makeAny(aParam);
1692 xInit->initialize( aSeq );
1694 //execute dialog
1695 sal_Int16 nDialogRet = xDialog->execute();
1696 if( RET_OK == nDialogRet )
1698 //get some parameters from the dialog
1699 sal_Bool bToSimplified = sal_True;
1700 sal_Bool bUseVariants = sal_True;
1701 sal_Bool bCommonTerms = sal_True;
1702 Reference< beans::XPropertySet > xProp( xDialog, UNO_QUERY );
1703 if( xProp.is() )
1707 xProp->getPropertyValue("IsDirectionToSimplified") >>= bToSimplified;
1708 xProp->getPropertyValue("IsUseCharacterVariants") >>= bUseVariants;
1709 xProp->getPropertyValue("IsTranslateCommonTerms") >>= bCommonTerms;
1711 catch( Exception& )
1716 //execute translation
1717 LanguageType eSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
1718 LanguageType eTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
1719 sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
1720 if( !bCommonTerms )
1721 nOptions |= i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
1723 Font aTargetFont = GetViewData()->GetActiveWin()->GetDefaultFont(
1724 DEFAULTFONT_CJK_SPREADSHEET,
1725 eTargetLang, DEFAULTFONT_FLAGS_ONLYONE );
1726 ScConversionParam aConvParam( SC_CONVERSION_CHINESE_TRANSL,
1727 eSourceLang, eTargetLang, aTargetFont, nOptions, false );
1728 pTabViewShell->DoSheetConversion( aConvParam );
1731 Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
1732 if( xComponent.is() )
1733 xComponent->dispose();
1737 break;
1739 case SID_THESAURUS:
1740 pTabViewShell->DoThesaurus();
1741 break;
1743 case SID_TOGGLE_REL:
1744 pTabViewShell->DoRefConversion();
1745 break;
1747 case SID_DEC_INDENT:
1748 pTabViewShell->ChangeIndent( false );
1749 break;
1750 case SID_INC_INDENT:
1751 pTabViewShell->ChangeIndent( sal_True );
1752 break;
1754 case FID_USE_NAME:
1756 sal_uInt16 nFlags = pTabViewShell->GetCreateNameFlags();
1758 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1759 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1761 AbstractScNameCreateDlg* pDlg = pFact->CreateScNameCreateDlg(pTabViewShell->GetDialogParent(), nFlags);
1762 OSL_ENSURE(pDlg, "Dialog create fail!");
1764 if( pDlg->Execute() )
1766 nFlags = pDlg->GetFlags();
1767 pTabViewShell->CreateNames(nFlags);
1768 rReq.Done();
1770 delete pDlg;
1772 break;
1774 case SID_CONSOLIDATE:
1776 const SfxPoolItem* pItem;
1777 if ( pReqArgs && SFX_ITEM_SET ==
1778 pReqArgs->GetItemState( SCITEM_CONSOLIDATEDATA, sal_True, &pItem ) )
1780 const ScConsolidateParam& rParam =
1781 ((const ScConsolidateItem*)pItem)->GetData();
1783 pTabViewShell->Consolidate( rParam );
1784 GetViewData()->GetDocument()->SetConsolidateDlgData( &rParam );
1786 rReq.Done();
1788 #ifndef DISABLE_SCRIPTING
1789 else if (rReq.IsAPI())
1790 SbxBase::SetError(SbxERR_BAD_PARAMETER);
1791 #endif
1793 break;
1795 case SID_INS_FUNCTION:
1797 const SfxBoolItem* pOkItem = (const SfxBoolItem*)&pReqArgs->Get( SID_DLG_RETOK );
1799 if ( pOkItem->GetValue() ) // OK
1801 OUString aFormula;
1802 const SfxStringItem* pSItem = (const SfxStringItem*)&pReqArgs->Get( SCITEM_STRING );
1803 const SfxBoolItem* pMatrixItem = (const SfxBoolItem*) &pReqArgs->Get( SID_DLG_MATRIX );
1805 aFormula += pSItem->GetValue();
1806 pScMod->ActivateInputWindow( &aFormula, pMatrixItem->GetValue() );
1808 else // CANCEL
1810 pScMod->ActivateInputWindow( NULL );
1812 rReq.Ignore(); // only SID_ENTER_STRING is recorded
1814 break;
1816 case FID_DEFINE_NAME:
1817 if ( pReqArgs )
1819 const SfxPoolItem* pItem;
1820 OUString aName, aSymbol, aAttrib;
1822 if( pReqArgs->HasItem( FID_DEFINE_NAME, &pItem ) )
1823 aName = ((const SfxStringItem*)pItem)->GetValue();
1825 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
1826 aSymbol = ((const SfxStringItem*)pItem)->GetValue();
1828 if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
1829 aAttrib = ((const SfxStringItem*)pItem)->GetValue();
1831 if ( !aName.isEmpty() && !aSymbol.isEmpty() )
1833 if (pTabViewShell->InsertName( aName, aSymbol, aAttrib ))
1834 rReq.Done();
1835 #ifndef DISABLE_SCRIPTING
1836 else
1837 SbxBase::SetError( SbxERR_BAD_PARAMETER ); // Basic-error
1838 #endif
1841 else
1843 sal_uInt16 nId = ScNameDlgWrapper::GetChildWindowId();
1844 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1845 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
1847 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
1849 break;
1850 case FID_ADD_NAME:
1852 sal_uInt16 nId = ScNameDefDlgWrapper::GetChildWindowId();
1853 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1854 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
1856 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
1858 break;
1860 case SID_OPENDLG_CONDFRMT:
1861 case SID_OPENDLG_COLORSCALE:
1862 case SID_OPENDLG_DATABAR:
1863 case SID_OPENDLG_ICONSET:
1864 case SID_OPENDLG_CONDDATE:
1867 ScRangeList aRangeList;
1868 ScViewData* pData = GetViewData();
1869 pData->GetMarkData().FillRangeListWithMarks(&aRangeList, false);
1871 ScDocument* pDoc = GetViewData()->GetDocument();
1872 if(pDoc->IsTabProtected(pData->GetTabNo()))
1874 //ErrorMessage( STR_ERR_CONDFORMAT_PROTECTED );
1875 break;
1878 ScAddress aPos(pData->GetCurX(), pData->GetCurY(), pData->GetTabNo());
1879 if(aRangeList.empty())
1881 ScRange* pRange = new ScRange(aPos);
1882 aRangeList.push_back(pRange);
1885 sal_Int32 nKey = 0;
1886 const ScPatternAttr* pPattern = pDoc->GetPattern(aPos.Col(), aPos.Row(), aPos.Tab());
1887 const std::vector<sal_uInt32>& rCondFormats = static_cast<const ScCondFormatItem&>(pPattern->GetItem(ATTR_CONDITIONAL)).GetCondFormatData();
1888 bool bContainsCondFormat = !rCondFormats.empty();
1889 boost::scoped_ptr<ScCondFormatDlg> pCondFormatDlg;
1890 if(bContainsCondFormat)
1892 bool bContainsExistingCondFormat = false;
1893 ScConditionalFormatList* pList = pDoc->GetCondFormList(aPos.Tab());
1894 for (std::vector<sal_uInt32>::const_iterator itr = rCondFormats.begin(), itrEnd = rCondFormats.end();
1895 itr != itrEnd; ++itr)
1897 // check if at least one existing conditional format has the same range
1898 const ScConditionalFormat* pCondFormat = pList->GetFormat(*itr);
1899 if(!pCondFormat)
1900 continue;
1902 bContainsExistingCondFormat = true;
1903 const ScRangeList& rCondFormatRange = pCondFormat->GetRange();
1904 if(rCondFormatRange == aRangeList)
1906 // found a matching range, edit this conditional format
1907 nKey = pCondFormat->GetKey();
1908 pCondFormatDlg.reset( new ScCondFormatDlg( pTabViewShell->GetDialogParent(), pDoc, pCondFormat, rCondFormatRange, aPos, condformat::dialog::NONE ) );
1909 break;
1913 // if not found a conditional format ask whether we should edit one of the existing
1914 // or should create a new overlapping conditional format
1916 if(!pCondFormatDlg && bContainsExistingCondFormat)
1918 QueryBox aBox( pTabViewShell->GetDialogParent(), WinBits( WB_YES_NO | WB_DEF_YES ),
1919 ScGlobal::GetRscString(STR_EDIT_EXISTING_COND_FORMATS) );
1920 bool bEditExisting = aBox.Execute() == RET_YES;
1921 if(bEditExisting)
1923 // differentiate between ranges where one conditional format is defined
1924 // and several formats are defined
1925 // if we have only one => open the cond format dlg to edit it
1926 // otherwise open the manage cond format dlg
1927 if(rCondFormats.size() == 1)
1929 const ScConditionalFormat* pCondFormat = pList->GetFormat(rCondFormats[0]);
1930 assert(pCondFormat);
1931 const ScRangeList& rCondFormatRange = pCondFormat->GetRange();
1932 nKey = pCondFormat->GetKey();
1933 pCondFormatDlg.reset( new ScCondFormatDlg( pTabViewShell->GetDialogParent(), pDoc, pCondFormat, rCondFormatRange, aPos, condformat::dialog::NONE ) );
1935 else
1937 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1938 boost::scoped_ptr<AbstractScCondFormatManagerDlg> pDlg(pFact->CreateScCondFormatMgrDlg( pTabViewShell->GetDialogParent(), pDoc, pList, aPos, RID_SCDLG_COND_FORMAT_MANAGER));
1939 if(pDlg->Execute() == RET_OK && pDlg->CondFormatsChanged())
1941 ScConditionalFormatList* pCondFormatList = pDlg->GetConditionalFormatList();
1942 pData->GetDocShell()->GetDocFunc().SetConditionalFormatList(pCondFormatList, aPos.Tab());
1944 // we need step out here because we don't want to open the normal dialog
1945 break;
1948 else
1950 // define an overlapping conditional format
1951 // does not need to be handled here
1957 if(!pCondFormatDlg)
1959 condformat::dialog::ScCondFormatDialogType eType = condformat::dialog::NONE;
1960 switch(nSlot)
1962 case SID_OPENDLG_CONDFRMT:
1963 eType = condformat::dialog::CONDITION;
1964 break;
1965 case SID_OPENDLG_COLORSCALE:
1966 eType = condformat::dialog::COLORSCALE;
1967 break;
1968 case SID_OPENDLG_DATABAR:
1969 eType = condformat::dialog::DATABAR;
1970 break;
1971 case SID_OPENDLG_ICONSET:
1972 eType = condformat::dialog::ICONSET;
1973 break;
1974 case SID_OPENDLG_CONDDATE:
1975 eType = condformat::dialog::DATE;
1976 break;
1977 default:
1978 assert(false);
1979 break;
1981 pCondFormatDlg.reset( new ScCondFormatDlg( pTabViewShell->GetDialogParent(), pDoc, NULL, aRangeList, aRangeList.GetTopLeftCorner(), eType ) );
1984 sal_uInt16 nId = 1;
1985 pScMod->SetRefDialog( nId, true );
1987 if( pCondFormatDlg->Execute() == RET_OK )
1989 ScConditionalFormat* pFormat = pCondFormatDlg->GetConditionalFormat();
1990 if(pFormat)
1991 pData->GetDocShell()->GetDocFunc().ReplaceConditionalFormat(nKey, pFormat, aPos.Tab(), pFormat->GetRange());
1992 else
1993 pData->GetDocShell()->GetDocFunc().ReplaceConditionalFormat(nKey, NULL, aPos.Tab(), ScRangeList());
1996 pScMod->SetRefDialog( nId, false );
2000 break;
2002 case SID_DEFINE_COLROWNAMERANGES:
2005 sal_uInt16 nId = ScColRowNameRangesDlgWrapper::GetChildWindowId();
2006 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
2007 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
2009 pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
2012 break;
2014 case SID_UPDATECHART:
2016 sal_Bool bAll = false;
2018 if( pReqArgs )
2020 const SfxPoolItem* pItem;
2022 if( pReqArgs->HasItem( SID_UPDATECHART, &pItem ) )
2023 bAll = ((const SfxBoolItem*)pItem)->GetValue();
2026 pTabViewShell->UpdateCharts( bAll );
2028 if( ! rReq.IsAPI() )
2030 rReq.AppendItem( SfxBoolItem( SID_UPDATECHART, bAll ) );
2031 rReq.Done();
2034 break;
2037 case SID_TABOP:
2038 if (pReqArgs)
2040 const ScTabOpItem& rItem =
2041 (const ScTabOpItem&)
2042 pReqArgs->Get( SID_TABOP );
2044 pTabViewShell->TabOp( rItem.GetData() );
2046 rReq.Done( *pReqArgs );
2048 break;
2050 case SID_SOLVE:
2051 if (pReqArgs)
2053 const ScSolveItem& rItem =
2054 (const ScSolveItem&)
2055 pReqArgs->Get( SCITEM_SOLVEDATA );
2057 pTabViewShell->Solve( rItem.GetData() );
2059 rReq.Done( *pReqArgs );
2061 break;
2063 case FID_INSERT_NAME:
2065 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2066 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2068 AbstractScNamePasteDlg* pDlg = pFact->CreateScNamePasteDlg( pTabViewShell->GetDialogParent(), GetViewData()->GetDocShell() );
2069 OSL_ENSURE(pDlg, "Dialog create fail!");
2070 switch( pDlg->Execute() )
2072 case BTN_PASTE_LIST:
2073 pTabViewShell->InsertNameList();
2074 break;
2075 case BTN_PASTE_NAME:
2077 ScInputHandler* pHdl = pScMod->GetInputHdl( pTabViewShell );
2078 if (pHdl)
2080 // "=" in KeyEvent, switches to input-mode
2081 pScMod->InputKeyEvent( KeyEvent('=',KeyCode()) );
2083 std::vector<OUString> aNames = pDlg->GetSelectedNames();
2084 if (!aNames.empty())
2086 OUStringBuffer aBuffer;
2087 for (std::vector<OUString>::const_iterator itr = aNames.begin();
2088 itr != aNames.end(); ++itr)
2090 aBuffer.append(*itr).append(' ');
2092 pHdl->InsertFunction( aBuffer.makeStringAndClear(), false ); // without "()"
2096 break;
2098 delete pDlg;
2100 break;
2102 case SID_RANGE_NOTETEXT:
2103 if (pReqArgs)
2105 const SfxStringItem& rTextItem = (const SfxStringItem&)pReqArgs->Get( SID_RANGE_NOTETEXT );
2107 // always cursor position
2108 ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
2109 pTabViewShell->SetNoteText( aPos, rTextItem.GetValue() );
2110 rReq.Done();
2112 break;
2114 case SID_INSERT_POSTIT:
2115 if ( pReqArgs )
2117 const SvxPostItAuthorItem& rAuthorItem = (const SvxPostItAuthorItem&)pReqArgs->Get( SID_ATTR_POSTIT_AUTHOR );
2118 const SvxPostItDateItem& rDateItem = (const SvxPostItDateItem&) pReqArgs->Get( SID_ATTR_POSTIT_DATE );
2119 const SvxPostItTextItem& rTextItem = (const SvxPostItTextItem&) pReqArgs->Get( SID_ATTR_POSTIT_TEXT );
2121 ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
2122 pTabViewShell->ReplaceNote( aPos, rTextItem.GetValue(), &rAuthorItem.GetValue(), &rDateItem.GetValue() );
2123 rReq.Done();
2125 else
2127 pTabViewShell->EditNote(); // note object to edit
2129 break;
2131 case FID_NOTE_VISIBLE:
2133 ScDocument* pDoc = GetViewData()->GetDocument();
2134 ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
2135 if( ScPostIt* pNote = pDoc->GetNote(aPos) )
2137 bool bShow;
2138 const SfxPoolItem* pItem;
2139 if ( pReqArgs && (pReqArgs->GetItemState( FID_NOTE_VISIBLE, sal_True, &pItem ) == SFX_ITEM_SET) )
2140 bShow = ((const SfxBoolItem*) pItem)->GetValue();
2141 else
2142 bShow = !pNote->IsCaptionShown();
2144 pTabViewShell->ShowNote( bShow );
2146 if (!pReqArgs)
2147 rReq.AppendItem( SfxBoolItem( FID_NOTE_VISIBLE, bShow ) );
2149 rReq.Done();
2150 rBindings.Invalidate( FID_NOTE_VISIBLE );
2152 else
2153 rReq.Ignore();
2155 break;
2157 case FID_HIDE_NOTE:
2158 case FID_SHOW_NOTE:
2160 bool bShowNote = nSlot == FID_SHOW_NOTE;
2161 ScViewData* pData = GetViewData();
2162 ScDocument* pDoc = pData->GetDocument();
2163 ScMarkData& rMark = pData->GetMarkData();
2164 bool bDone = false;
2166 if (!rMark.IsMarked() && !rMark.IsMultiMarked())
2168 // Check current cell
2169 ScAddress aPos( pData->GetCurX(), pData->GetCurY(), pData->GetTabNo() );
2170 if( pDoc->GetNote(aPos) )
2172 pData->GetDocShell()->GetDocFunc().ShowNote( aPos, bShowNote );
2173 bDone = true;
2176 else
2178 // Check selection range
2179 ScRangeListRef aRangesRef;
2180 pData->GetMultiArea(aRangesRef);
2181 ScRangeList aRanges = *aRangesRef;
2182 size_t nRangeSize = aRanges.size();
2184 OUString aUndo = ScGlobal::GetRscString( bShowNote ? STR_UNDO_SHOWNOTE : STR_UNDO_HIDENOTE );
2185 pData->GetDocShell()->GetUndoManager()->EnterListAction( aUndo, aUndo );
2187 for ( size_t i = 0; i < nRangeSize; ++i )
2189 const ScRange * pRange = aRanges[i];
2190 const SCROW nRow0 = pRange->aStart.Row();
2191 const SCROW nRow1 = pRange->aEnd.Row();
2192 const SCCOL nCol0 = pRange->aStart.Col();
2193 const SCCOL nCol1 = pRange->aEnd.Col();
2194 const SCTAB nRangeTab = pRange->aStart.Tab();
2195 // Check by each cell
2196 for ( SCROW nRow = nRow0; nRow <= nRow1; ++nRow )
2198 for ( SCCOL nCol = nCol0; nCol <= nCol1; ++nCol )
2200 if ( pDoc->HasNote(nCol, nRow, nRangeTab) && pDoc->IsBlockEditable( nRangeTab, nCol,nRow, nCol,nRow ) )
2202 ScAddress aPos( nCol, nRow, nRangeTab );
2203 pData->GetDocShell()->GetDocFunc().ShowNote( aPos, bShowNote );
2204 bDone = true;
2210 pData->GetDocShell()->GetUndoManager()->LeaveListAction();
2212 if ( bDone )
2214 rReq.Done();
2215 rBindings.Invalidate( nSlot );
2217 else
2218 rReq.Ignore();
2221 break;
2223 case SID_DELETE_NOTE:
2224 pTabViewShell->DeleteContents( IDF_NOTE ); // delete all notes in selection
2225 rReq.Done();
2226 break;
2228 case SID_CHARMAP:
2229 if( pReqArgs != NULL )
2231 OUString aChars, aFontName;
2232 const SfxItemSet *pArgs = rReq.GetArgs();
2233 const SfxPoolItem* pItem = 0;
2234 if ( pArgs )
2235 pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP), false, &pItem);
2236 if ( pItem )
2238 const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, pItem );
2239 if ( pStringItem )
2240 aChars = pStringItem->GetValue();
2241 const SfxPoolItem* pFtItem = NULL;
2242 pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR), false, &pFtItem);
2243 const SfxStringItem* pFontItem = PTR_CAST( SfxStringItem, pFtItem );
2244 if ( pFontItem )
2245 aFontName = pFontItem->GetValue();
2248 if ( !aChars.isEmpty() )
2250 Font aFont;
2251 pTabViewShell->GetSelectionPattern()->GetFont( aFont, SC_AUTOCOL_BLACK, NULL, NULL, NULL,
2252 pTabViewShell->GetSelectionScriptType() );
2253 if ( !aFontName.isEmpty() )
2254 aFont = Font( aFontName, Size(1,1) );
2255 pTabViewShell->InsertSpecialChar( aChars, aFont );
2256 if( ! rReq.IsAPI() )
2257 rReq.Done();
2260 else
2262 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
2264 // font color doesn't matter here
2265 Font aCurFont;
2266 pTabViewShell->GetSelectionPattern()->GetFont( aCurFont, SC_AUTOCOL_BLACK, NULL, NULL, NULL,
2267 pTabViewShell->GetSelectionScriptType() );
2269 SfxAllItemSet aSet( GetPool() );
2270 aSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
2271 aSet.Put( SvxFontItem( aCurFont.GetFamily(), aCurFont.GetName(), aCurFont.GetStyleName(), aCurFont.GetPitch(), aCurFont.GetCharSet(), GetPool().GetWhich(SID_ATTR_CHAR_FONT) ) );
2273 SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( pTabViewShell->GetDialogParent(), aSet,
2274 pTabViewShell->GetViewFrame()->GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP );
2276 if ( pDlg->Execute() == RET_OK )
2278 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pItem, SfxStringItem, SID_CHARMAP, false );
2279 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFontItem, SvxFontItem, SID_ATTR_CHAR_FONT, false );
2281 if ( pItem && pFontItem )
2283 Font aNewFont( pFontItem->GetFamilyName(), pFontItem->GetStyleName(), Size(1,1) );
2284 aNewFont.SetCharSet( pFontItem->GetCharSet() );
2285 aNewFont.SetPitch( pFontItem->GetPitch() );
2286 pTabViewShell->InsertSpecialChar( pItem->GetValue(), aNewFont );
2287 rReq.AppendItem( *pFontItem );
2288 rReq.AppendItem( *pItem );
2289 rReq.Done();
2292 delete pDlg;
2294 break;
2296 case SID_SELECT_SCENARIO:
2298 // Testing
2300 if ( pReqArgs )
2302 const SfxStringItem* pItem =
2303 (const SfxStringItem*)&pReqArgs->Get( SID_SELECT_SCENARIO );
2305 if( pItem )
2307 pTabViewShell->UseScenario( pItem->GetValue() );
2308 //! why should the return value be valid?!?!
2309 rReq.SetReturnValue( SfxStringItem( SID_SELECT_SCENARIO, pItem->GetValue() ) );
2310 rReq.Done();
2312 else
2314 OSL_FAIL("NULL");
2318 break;
2320 case SID_HYPERLINK_SETLINK:
2321 if( pReqArgs )
2323 const SfxPoolItem* pItem;
2324 if( pReqArgs->HasItem( SID_HYPERLINK_SETLINK, &pItem ) )
2326 const SvxHyperlinkItem* pHyper = (const SvxHyperlinkItem*) pItem;
2327 const OUString& rName = pHyper->GetName();
2328 const OUString& rURL = pHyper->GetURL();
2329 const OUString& rTarget = pHyper->GetTargetFrame();
2330 sal_uInt16 nType = (sal_uInt16) pHyper->GetInsertMode();
2332 pTabViewShell->InsertURL( rName, rURL, rTarget, nType );
2333 rReq.Done();
2335 else
2336 rReq.Ignore();
2338 break;
2340 case SID_OPENDLG_CONDFRMT_MANAGER:
2342 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2343 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2345 ScViewData* pData = GetViewData();
2346 ScDocument* pDoc = pData->GetDocument();
2348 if(pDoc->IsTabProtected(pData->GetTabNo()))
2350 pTabViewShell->ErrorMessage( STR_ERR_CONDFORMAT_PROTECTED );
2351 break;
2354 ScAddress aPos(pData->GetCurX(), pData->GetCurY(), pData->GetTabNo());
2356 ScConditionalFormatList* pList = pDoc->GetCondFormList( aPos.Tab() );
2357 boost::scoped_ptr<AbstractScCondFormatManagerDlg> pDlg(pFact->CreateScCondFormatMgrDlg( pTabViewShell->GetDialogParent(), pDoc, pList, aPos, RID_SCDLG_COND_FORMAT_MANAGER));
2358 if(pDlg->Execute() == RET_OK && pDlg->CondFormatsChanged())
2360 ScConditionalFormatList* pCondFormatList = pDlg->GetConditionalFormatList();
2361 pData->GetDocShell()->GetDocFunc().SetConditionalFormatList(pCondFormatList, aPos.Tab());
2364 break;
2366 case SID_EXTERNAL_SOURCE:
2368 OUString aFile;
2369 OUString aFilter;
2370 OUString aOptions;
2371 OUString aSource;
2372 sal_uLong nRefresh=0;
2374 SFX_REQUEST_ARG( rReq, pFile, SfxStringItem, SID_FILE_NAME, false );
2375 SFX_REQUEST_ARG( rReq, pSource, SfxStringItem, FN_PARAM_1, false );
2376 if ( pFile && pSource )
2378 aFile = pFile->GetValue();
2379 aSource = pSource->GetValue();
2380 SFX_REQUEST_ARG( rReq, pFilter, SfxStringItem, SID_FILTER_NAME, false );
2381 if ( pFilter )
2382 aFilter = pFilter->GetValue();
2383 SFX_REQUEST_ARG( rReq, pOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, false );
2384 if ( pOptions )
2385 aOptions = pOptions->GetValue();
2386 SFX_REQUEST_ARG( rReq, pRefresh, SfxUInt32Item, FN_PARAM_2, false );
2387 if ( pRefresh )
2388 nRefresh = pRefresh->GetValue();
2390 else
2392 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2393 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2395 delete pImpl->m_pLinkedDlg;
2396 pImpl->m_pLinkedDlg =
2397 pFact->CreateScLinkedAreaDlg(pTabViewShell->GetDialogParent());
2398 OSL_ENSURE(pImpl->m_pLinkedDlg, "Dialog create fail!");
2399 delete pImpl->m_pRequest;
2400 pImpl->m_pRequest = new SfxRequest( rReq );
2401 pImpl->m_pLinkedDlg->StartExecuteModal( LINK( this, ScCellShell, DialogClosed ) );
2402 return;
2405 ExecuteExternalSource( aFile, aFilter, aOptions, aSource, nRefresh, rReq );
2407 break;
2413 default:
2414 OSL_FAIL("incorrect slot in ExecuteEdit");
2415 break;
2419 void ScCellShell::ExecuteTrans( SfxRequest& rReq )
2421 sal_Int32 nType = ScViewUtil::GetTransliterationType( rReq.GetSlot() );
2422 if ( nType )
2424 GetViewData()->GetView()->TransliterateText( nType );
2425 rReq.Done();
2429 void ScCellShell::ExecuteRotateTrans( SfxRequest& rReq )
2431 if( rReq.GetSlot() == SID_TRANSLITERATE_ROTATE_CASE )
2432 GetViewData()->GetView()->TransliterateText( m_aRotateCase.getNextMode() );
2435 void ScCellShell::ExecuteExternalSource(
2436 const OUString& _rFile, const OUString& _rFilter, const OUString& _rOptions,
2437 const OUString& _rSource, sal_uLong _nRefresh, SfxRequest& _rRequest )
2439 if ( !_rFile.isEmpty() && !_rSource.isEmpty() ) // filter may be empty
2441 ScRange aLinkRange;
2442 sal_Bool bMove = false;
2444 ScViewData* pData = GetViewData();
2445 ScMarkData& rMark = pData->GetMarkData();
2446 rMark.MarkToSimple();
2447 if ( rMark.IsMarked() )
2449 rMark.GetMarkArea( aLinkRange );
2450 bMove = sal_True; // insert/delete cells to fit range
2452 else
2453 aLinkRange = ScRange( pData->GetCurX(), pData->GetCurY(), pData->GetTabNo() );
2455 pData->GetDocFunc().InsertAreaLink( _rFile, _rFilter, _rOptions, _rSource,
2456 aLinkRange, _nRefresh, bMove, false );
2457 _rRequest.Done();
2459 else
2460 _rRequest.Ignore();
2463 namespace {
2465 bool isDPSourceValid(const ScDPObject& rDPObj)
2467 if (rDPObj.IsImportData())
2469 // If the data type is database, check if the database is still valid.
2470 const ScImportSourceDesc* pDesc = rDPObj.GetImportSourceDesc();
2471 if (!pDesc)
2472 return false;
2474 const ScDPSaveData* pSaveData = rDPObj.GetSaveData();
2475 const ScDPDimensionSaveData* pDimData = NULL;
2476 if (pSaveData)
2477 pDimData = pSaveData->GetExistingDimensionData();
2479 const ScDPCache* pCache = pDesc->CreateCache(pDimData);
2480 if (!pCache)
2481 // cashe creation failed, probably due to invalid connection.
2482 return false;
2484 return true;
2489 void ScCellShell::ExecuteDataPilotDialog()
2491 ScModule* pScMod = SC_MOD();
2492 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2493 ScViewData* pData = GetViewData();
2494 ScDocument* pDoc = pData->GetDocument();
2496 ::boost::scoped_ptr<ScDPObject> pNewDPObject(NULL);
2498 // ScPivot is no longer used...
2499 ScDPObject* pDPObj = pDoc->GetDPAtCursor(
2500 pData->GetCurX(), pData->GetCurY(),
2501 pData->GetTabNo() );
2502 if ( pDPObj ) // on an existing table?
2504 if (isDPSourceValid(*pDPObj))
2505 pNewDPObject.reset(new ScDPObject(*pDPObj));
2507 else // create new table
2509 sal_uLong nSrcErrorId = 0;
2511 // select database range or data
2512 pTabViewShell->GetDBData( true, SC_DB_OLD );
2513 ScMarkData& rMark = GetViewData()->GetMarkData();
2514 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
2515 pTabViewShell->MarkDataArea( false );
2517 // output to cursor position for non-sheet data
2518 ScAddress aDestPos( pData->GetCurX(), pData->GetCurY(),
2519 pData->GetTabNo() );
2521 // first select type of source data
2523 bool bEnableExt = ScDPObject::HasRegisteredSources();
2525 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2526 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2528 ::boost::scoped_ptr<AbstractScDataPilotSourceTypeDlg> pTypeDlg(
2529 pFact->CreateScDataPilotSourceTypeDlg(
2530 pTabViewShell->GetDialogParent(), bEnableExt));
2532 // Populate named ranges (if any).
2533 ScRangeName* pRangeName = pDoc->GetRangeName();
2534 if (pRangeName)
2536 ScRangeName::const_iterator itr = pRangeName->begin(), itrEnd = pRangeName->end();
2537 for (; itr != itrEnd; ++itr)
2538 pTypeDlg->AppendNamedRange(itr->second->GetName());
2541 OSL_ENSURE(pTypeDlg, "Dialog create fail!");
2542 if ( pTypeDlg->Execute() == RET_OK )
2544 if ( pTypeDlg->IsExternal() )
2546 uno::Sequence<OUString> aSources = ScDPObject::GetRegisteredSources();
2547 ::boost::scoped_ptr<AbstractScDataPilotServiceDlg> pServDlg(
2548 pFact->CreateScDataPilotServiceDlg(
2549 pTabViewShell->GetDialogParent(), aSources, RID_SCDLG_DAPISERVICE));
2551 OSL_ENSURE(pServDlg, "Dialog create fail!");
2552 if ( pServDlg->Execute() == RET_OK )
2554 ScDPServiceDesc aServDesc(
2555 pServDlg->GetServiceName(),
2556 pServDlg->GetParSource(),
2557 pServDlg->GetParName(),
2558 pServDlg->GetParUser(),
2559 pServDlg->GetParPass() );
2560 pNewDPObject.reset(new ScDPObject(pDoc));
2561 pNewDPObject->SetServiceData( aServDesc );
2564 else if ( pTypeDlg->IsDatabase() )
2566 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2568 ::boost::scoped_ptr<AbstractScDataPilotDatabaseDlg> pDataDlg(
2569 pFact->CreateScDataPilotDatabaseDlg(
2570 pTabViewShell->GetDialogParent(), RID_SCDLG_DAPIDATA));
2572 OSL_ENSURE(pDataDlg, "Dialog create fail!");
2573 if ( pDataDlg->Execute() == RET_OK )
2575 ScImportSourceDesc aImpDesc(pDoc);
2576 pDataDlg->GetValues( aImpDesc );
2577 pNewDPObject.reset(new ScDPObject(pDoc));
2578 pNewDPObject->SetImportDesc( aImpDesc );
2581 else if (pTypeDlg->IsNamedRange())
2583 OUString aName = pTypeDlg->GetSelectedNamedRange();
2584 ScSheetSourceDesc aShtDesc(pDoc);
2585 aShtDesc.SetRangeName(aName);
2586 nSrcErrorId = aShtDesc.CheckSourceRange();
2587 if (!nSrcErrorId)
2589 pNewDPObject.reset(new ScDPObject(pDoc));
2590 pNewDPObject->SetSheetDesc(aShtDesc);
2593 else // selection
2595 //! use database ranges (select before type dialog?)
2596 ScRange aRange;
2597 ScMarkType eType = GetViewData()->GetSimpleArea(aRange);
2598 if ( (eType & SC_MARK_SIMPLE) == SC_MARK_SIMPLE )
2600 // Shrink the range to the data area.
2601 SCCOL nStartCol = aRange.aStart.Col(), nEndCol = aRange.aEnd.Col();
2602 SCROW nStartRow = aRange.aStart.Row(), nEndRow = aRange.aEnd.Row();
2603 if (pDoc->ShrinkToDataArea(aRange.aStart.Tab(), nStartCol, nStartRow, nEndCol, nEndRow))
2605 aRange.aStart.SetCol(nStartCol);
2606 aRange.aStart.SetRow(nStartRow);
2607 aRange.aEnd.SetCol(nEndCol);
2608 aRange.aEnd.SetRow(nEndRow);
2609 rMark.SetMarkArea(aRange);
2610 pTabViewShell->MarkRange(aRange);
2613 bool bOK = true;
2614 if ( pDoc->HasSubTotalCells( aRange ) )
2616 // confirm selection if it contains SubTotal cells
2618 QueryBox aBox( pTabViewShell->GetDialogParent(),
2619 WinBits(WB_YES_NO | WB_DEF_YES),
2620 ScGlobal::GetRscString(STR_DATAPILOT_SUBTOTAL) );
2621 if (aBox.Execute() == RET_NO)
2622 bOK = false;
2624 if (bOK)
2626 ScSheetSourceDesc aShtDesc(pDoc);
2627 aShtDesc.SetSourceRange(aRange);
2628 nSrcErrorId = aShtDesc.CheckSourceRange();
2629 if (!nSrcErrorId)
2631 pNewDPObject.reset(new ScDPObject(pDoc));
2632 pNewDPObject->SetSheetDesc( aShtDesc );
2635 // output below source data
2636 if ( aRange.aEnd.Row()+2 <= MAXROW - 4 )
2637 aDestPos = ScAddress( aRange.aStart.Col(),
2638 aRange.aEnd.Row()+2,
2639 aRange.aStart.Tab() );
2645 if (nSrcErrorId)
2647 // Error occurred during data creation. Launch an error and bail out.
2648 InfoBox aBox(pTabViewShell->GetDialogParent(), ScGlobal::GetRscString(nSrcErrorId));
2649 aBox.Execute();
2650 return;
2653 if ( pNewDPObject )
2654 pNewDPObject->SetOutRange( aDestPos );
2657 pTabViewShell->SetDialogDPObject( pNewDPObject.get() ); // is copied
2658 if ( pNewDPObject )
2660 // start layout dialog
2662 sal_uInt16 nId = ScPivotLayoutWrapper::GetChildWindowId();
2663 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
2664 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
2665 pScMod->SetRefDialog( nId, pWnd ? false : true );
2669 void ScCellShell::ExecuteXMLSourceDialog()
2671 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2672 if (!pFact)
2673 return;
2675 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2676 if (!pTabViewShell)
2677 return;
2679 ScModule* pScMod = SC_MOD();
2681 sal_uInt16 nId = ScXMLSourceDlgWrapper::GetChildWindowId();
2682 SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame();
2683 SfxChildWindow* pWnd = pViewFrame->GetChildWindow(nId);
2684 pScMod->SetRefDialog(nId, pWnd ? false : true);
2687 void ScCellShell::ExecuteSubtotals(SfxRequest& rReq)
2689 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2690 const SfxItemSet* pArgs = rReq.GetArgs();
2691 if ( pArgs )
2693 pTabViewShell->DoSubTotals( ((const ScSubTotalItem&) pArgs->Get( SCITEM_SUBTDATA )).
2694 GetSubTotalData() );
2695 rReq.Done();
2696 return;
2699 SfxAbstractTabDialog * pDlg = NULL;
2700 ScSubTotalParam aSubTotalParam;
2701 SfxItemSet aArgSet( GetPool(), SCITEM_SUBTDATA, SCITEM_SUBTDATA );
2703 // Only get existing named database range.
2704 ScDBData* pDBData = pTabViewShell->GetDBData(true, SC_DB_OLD);
2705 if (!pDBData)
2707 // No existing DB data at this position. Create an
2708 // anonymous DB.
2709 pDBData = pTabViewShell->GetAnonymousDBData();
2710 ScRange aDataRange;
2711 pDBData->GetArea(aDataRange);
2712 pTabViewShell->MarkRange(aDataRange, false);
2714 if (!pDBData)
2715 return;
2717 pDBData->GetSubTotalParam( aSubTotalParam );
2718 aSubTotalParam.bRemoveOnly = false;
2720 aArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA, GetViewData(), &aSubTotalParam ) );
2721 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2722 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2724 pDlg = pFact->CreateScSubTotalDlg( pTabViewShell->GetDialogParent(), &aArgSet, RID_SCDLG_SUBTOTALS );
2725 OSL_ENSURE(pDlg, "Dialog create fail!");
2726 pDlg->SetCurPageId(1);
2728 short bResult = pDlg->Execute();
2730 if ( (bResult == RET_OK) || (bResult == SCRET_REMOVE) )
2732 const SfxItemSet* pOutSet = NULL;
2734 if ( bResult == RET_OK )
2736 pOutSet = pDlg->GetOutputItemSet();
2737 aSubTotalParam =
2738 ((const ScSubTotalItem&)
2739 pOutSet->Get( SCITEM_SUBTDATA )).
2740 GetSubTotalData();
2742 else // if (bResult == SCRET_REMOVE)
2744 pOutSet = &aArgSet;
2745 aSubTotalParam.bRemoveOnly = sal_True;
2746 aSubTotalParam.bReplace = sal_True;
2747 aArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA,
2748 GetViewData(),
2749 &aSubTotalParam ) );
2752 pTabViewShell->DoSubTotals( aSubTotalParam );
2753 rReq.Done( *pOutSet );
2755 else
2756 GetViewData()->GetDocShell()->CancelAutoDBRange();
2758 delete pDlg;
2761 IMPL_LINK_NOARG(ScCellShell, DialogClosed)
2763 OSL_ENSURE( pImpl->m_pLinkedDlg, "ScCellShell::DialogClosed(): invalid request" );
2764 OSL_ENSURE( pImpl->m_pRequest, "ScCellShell::DialogClosed(): invalid request" );
2765 OUString sFile, sFilter, sOptions, sSource;
2766 sal_uLong nRefresh = 0;
2768 if ( pImpl->m_pLinkedDlg->GetResult() == RET_OK )
2770 sFile = pImpl->m_pLinkedDlg->GetURL();
2771 sFilter = pImpl->m_pLinkedDlg->GetFilter();
2772 sOptions = pImpl->m_pLinkedDlg->GetOptions();
2773 sSource = pImpl->m_pLinkedDlg->GetSource();
2774 nRefresh = pImpl->m_pLinkedDlg->GetRefresh();
2775 if ( !sFile.isEmpty() )
2776 pImpl->m_pRequest->AppendItem( SfxStringItem( SID_FILE_NAME, sFile ) );
2777 if ( !sFilter.isEmpty() )
2778 pImpl->m_pRequest->AppendItem( SfxStringItem( SID_FILTER_NAME, sFilter ) );
2779 if ( !sOptions.isEmpty() )
2780 pImpl->m_pRequest->AppendItem( SfxStringItem( SID_FILE_FILTEROPTIONS, sOptions ) );
2781 if ( !sSource.isEmpty() )
2782 pImpl->m_pRequest->AppendItem( SfxStringItem( FN_PARAM_1, sSource ) );
2783 if ( nRefresh )
2784 pImpl->m_pRequest->AppendItem( SfxUInt32Item( FN_PARAM_2, nRefresh ) );
2787 ExecuteExternalSource( sFile, sFilter, sOptions, sSource, nRefresh, *(pImpl->m_pRequest) );
2788 return 0;
2791 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */