fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / view / cellsh1.cxx
blob6c2a7ef429f683f07a287a5d7af1868a4f420e85
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 <config_features.h>
22 #include <com/sun/star/i18n/TextConversionOption.hpp>
23 #include <com/sun/star/sheet/DataPilotFieldFilter.hpp>
25 #include "scitems.hxx"
26 #include <sfx2/viewfrm.hxx>
28 #include <svl/stritem.hxx>
29 #include <svl/whiter.hxx>
30 #include <svl/zforlist.hxx>
31 #include <svl/zformat.hxx>
32 #include <sfx2/dispatch.hxx>
33 #include <sfx2/request.hxx>
34 #include <vcl/msgbox.hxx>
35 #include <svx/svxdlg.hxx>
36 #include <sot/formats.hxx>
37 #include <svx/postattr.hxx>
38 #include <editeng/fontitem.hxx>
39 #include <svx/clipfmtitem.hxx>
40 #include <sfx2/passwd.hxx>
41 #include <svx/hlnkitem.hxx>
42 #include <basic/sbxcore.hxx>
43 #include <unotools/useroptions.hxx>
44 #include <vcl/waitobj.hxx>
45 #include <vcl/builderfactory.hxx>
46 #include <unotools/localedatawrapper.hxx>
48 #include "cellsh.hxx"
49 #include "sc.hrc"
50 #include "document.hxx"
51 #include "patattr.hxx"
52 #include "scmod.hxx"
53 #include "scresid.hxx"
54 #include "tabvwsh.hxx"
55 #include "impex.hxx"
56 #include "reffind.hxx"
57 #include "uiitems.hxx"
58 #include "reffact.hxx"
59 #include "inputhdl.hxx"
60 #include "transobj.hxx"
61 #include "drwtrans.hxx"
62 #include "docfunc.hxx"
63 #include "editable.hxx"
64 #include "dpobject.hxx"
65 #include "dpsave.hxx"
66 #include "dpgroup.hxx"
67 #include "spellparam.hxx"
68 #include "postit.hxx"
69 #include "clipparam.hxx"
70 #include "pivot.hxx"
71 #include "dpsdbtab.hxx"
72 #include "dpshttab.hxx"
73 #include "dbdata.hxx"
74 #include "docsh.hxx"
75 #include "cliputil.hxx"
76 #include "markdata.hxx"
77 #include "docpool.hxx"
78 #include "condformatdlg.hxx"
79 #include "attrib.hxx"
81 #include "globstr.hrc"
82 #include "scui_def.hxx"
83 #include <svx/dialogs.hrc>
84 #include "scabstdlg.hxx"
85 #include <tokenstringcontext.hxx>
86 #include <cellvalue.hxx>
87 #include <tokenarray.hxx>
88 #include <formulacell.hxx>
89 #include <gridwin.hxx>
90 #include <searchresults.hxx>
92 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
93 #include <com/sun/star/lang/XInitialization.hpp>
94 #include <com/sun/star/beans/PropertyValue.hpp>
95 #include <com/sun/star/beans/XPropertySet.hpp>
96 #include <cppuhelper/bootstrap.hxx>
97 #include <com/sun/star/i18n/TransliterationModules.hpp>
98 #include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
100 #include <boost/scoped_ptr.hpp>
102 using namespace ::com::sun::star;
103 using namespace ::com::sun::star::beans;
104 using namespace ::com::sun::star::uno;
106 void ScCellShell::ExecuteEdit( SfxRequest& rReq )
108 ScModule* pScMod = SC_MOD();
109 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
110 SfxBindings& rBindings = pTabViewShell->GetViewFrame()->GetBindings();
111 const SfxItemSet* pReqArgs = rReq.GetArgs();
112 sal_uInt16 nSlot = rReq.GetSlot();
114 pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
116 // finish input
117 if ( GetViewData()->HasEditView( GetViewData()->GetActivePart() ) )
119 switch ( nSlot )
121 case FID_DEFINE_NAME:
122 case FID_ADD_NAME:
123 case FID_USE_NAME:
124 case FID_INSERT_NAME:
125 case SID_SPELL_DIALOG:
126 case SID_HANGUL_HANJA_CONVERSION:
127 case SID_OPENDLG_CONDFRMT:
128 case SID_OPENDLG_COLORSCALE:
129 case SID_OPENDLG_DATABAR:
131 pScMod->InputEnterHandler();
132 pTabViewShell->UpdateInputHandler();
133 break;
135 default:
136 break;
140 switch ( nSlot )
143 // insert / delete cells / rows / columns
145 case FID_INS_ROW:
146 pTabViewShell->InsertCells(INS_INSROWS);
147 rReq.Done();
148 break;
150 case FID_INS_COLUMN:
151 pTabViewShell->InsertCells(INS_INSCOLS);
152 rReq.Done();
153 break;
155 case FID_INS_CELLSDOWN:
156 pTabViewShell->InsertCells(INS_CELLSDOWN);
157 rReq.Done();
158 break;
160 case FID_INS_CELLSRIGHT:
161 pTabViewShell->InsertCells(INS_CELLSRIGHT);
162 rReq.Done();
163 break;
165 case SID_DEL_ROWS:
166 pTabViewShell->DeleteCells( DEL_DELROWS );
167 rReq.Done();
168 break;
170 case SID_DEL_COLS:
171 pTabViewShell->DeleteCells( DEL_DELCOLS );
172 rReq.Done();
173 break;
175 case FID_INS_CELL:
177 InsCellCmd eCmd=INS_NONE;
179 if ( pReqArgs )
181 const SfxPoolItem* pItem;
182 OUString aFlags;
184 if( pReqArgs->HasItem( FID_INS_CELL, &pItem ) )
185 aFlags = static_cast<const SfxStringItem*>(pItem)->GetValue();
186 if( !aFlags.isEmpty() )
188 switch( aFlags[0] )
190 case 'V': eCmd = INS_CELLSDOWN ;break;
191 case '>': eCmd = INS_CELLSRIGHT ;break;
192 case 'R': eCmd = INS_INSROWS ;break;
193 case 'C': eCmd = INS_INSCOLS ;break;
197 else
199 if ( GetViewData()->SimpleColMarked() )
200 eCmd = INS_INSCOLS;
201 else if ( GetViewData()->SimpleRowMarked() )
202 eCmd = INS_INSROWS;
203 else
205 ScDocument* pDoc = GetViewData()->GetDocument();
206 bool bTheFlag=(pDoc->GetChangeTrack()!=NULL);
208 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
209 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
211 boost::scoped_ptr<AbstractScInsertCellDlg> pDlg(pFact->CreateScInsertCellDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_INSCELL, bTheFlag));
212 OSL_ENSURE(pDlg, "Dialog create fail!");
213 if (pDlg->Execute() == RET_OK)
214 eCmd = pDlg->GetInsCellCmd();
218 if (eCmd!=INS_NONE)
220 pTabViewShell->InsertCells( eCmd );
222 if( ! rReq.IsAPI() )
224 OUString aParam;
226 switch( eCmd )
228 case INS_CELLSDOWN: aParam = "V"; break;
229 case INS_CELLSRIGHT: aParam = ">"; break;
230 case INS_INSROWS: aParam = "R"; break;
231 case INS_INSCOLS: aParam = "C"; break;
232 default:
234 // added to avoid warnings
237 rReq.AppendItem( SfxStringItem( FID_INS_CELL, aParam ) );
238 rReq.Done();
242 break;
244 case FID_DELETE_CELL:
246 DelCellCmd eCmd = DEL_NONE;
248 if ( pReqArgs )
250 const SfxPoolItem* pItem;
251 OUString aFlags;
253 if( pReqArgs->HasItem( FID_DELETE_CELL, &pItem ) )
254 aFlags = static_cast<const SfxStringItem*>(pItem)->GetValue();
255 if( !aFlags.isEmpty() )
257 switch( aFlags[0] )
259 case 'U': eCmd = DEL_CELLSUP ;break;
260 case 'L': eCmd = DEL_CELLSLEFT ;break;
261 case 'R': eCmd = DEL_DELROWS ;break;
262 case 'C': eCmd = DEL_DELCOLS ;break;
266 else
268 if ( GetViewData()->SimpleColMarked() )
269 eCmd = DEL_DELCOLS;
270 else if ( GetViewData()->SimpleRowMarked() )
271 eCmd = DEL_DELROWS;
272 else
274 ScRange aRange;
275 ScDocument* pDoc = GetViewData()->GetDocument();
276 bool bTheFlag=GetViewData()->IsMultiMarked() ||
277 (GetViewData()->GetSimpleArea(aRange) == SC_MARK_SIMPLE_FILTERED) ||
278 (pDoc->GetChangeTrack() != NULL);
280 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
281 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
283 boost::scoped_ptr<AbstractScDeleteCellDlg> pDlg(pFact->CreateScDeleteCellDlg( pTabViewShell->GetDialogParent(), bTheFlag ));
284 OSL_ENSURE(pDlg, "Dialog create fail!");
286 if (pDlg->Execute() == RET_OK)
287 eCmd = pDlg->GetDelCellCmd();
291 if (eCmd != DEL_NONE )
293 pTabViewShell->DeleteCells( eCmd );
295 if( ! rReq.IsAPI() )
297 OUString aParam;
299 switch( eCmd )
301 case DEL_CELLSUP: aParam = "U"; break;
302 case DEL_CELLSLEFT: aParam = "L"; break;
303 case DEL_DELROWS: aParam = "R"; break;
304 case DEL_DELCOLS: aParam = "C"; break;
305 default:
307 // added to avoid warnings
310 rReq.AppendItem( SfxStringItem( FID_DELETE_CELL, aParam ) );
311 rReq.Done();
315 break;
317 // delete contents from cells
319 case SID_DELETE_CONTENTS:
320 pTabViewShell->DeleteContents( IDF_CONTENTS );
321 rReq.Done();
322 break;
324 case SID_DELETE:
326 InsertDeleteFlags nFlags = IDF_NONE;
328 if ( pReqArgs!=NULL && pTabViewShell->SelectionEditable() )
330 const SfxPoolItem* pItem;
331 OUString aFlags('A');
333 if( pReqArgs->HasItem( SID_DELETE, &pItem ) )
334 aFlags = static_cast<const SfxStringItem*>(pItem)->GetValue();
336 aFlags = aFlags.toAsciiUpperCase();
337 bool bCont = true;
339 for (sal_Int32 i=0 ; bCont && i<aFlags.getLength(); ++i)
341 switch (aFlags[i])
343 case 'A': // all
344 nFlags |= IDF_ALL;
345 bCont = false; // don't continue!
346 break;
347 case 'S': nFlags |= IDF_STRING; break;
348 case 'V': nFlags |= IDF_VALUE; break;
349 case 'D': nFlags |= IDF_DATETIME; break;
350 case 'F': nFlags |= IDF_FORMULA; break;
351 case 'N': nFlags |= IDF_NOTE; break;
352 case 'T': nFlags |= IDF_ATTRIB; break;
353 case 'O': nFlags |= IDF_OBJECTS; break;
357 else
359 ScEditableTester aTester( pTabViewShell );
360 if (aTester.IsEditable())
362 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
363 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
365 boost::scoped_ptr<AbstractScDeleteContentsDlg> pDlg(pFact->CreateScDeleteContentsDlg(pTabViewShell->GetDialogParent()));
366 OSL_ENSURE(pDlg, "Dialog create fail!");
367 ScDocument* pDoc = GetViewData()->GetDocument();
368 SCTAB nTab = GetViewData()->GetTabNo();
369 if ( pDoc->IsTabProtected(nTab) )
370 pDlg->DisableObjects();
371 if (pDlg->Execute() == RET_OK)
373 nFlags = pDlg->GetDelContentsCmdBits();
376 else
377 pTabViewShell->ErrorMessage(aTester.GetMessageId());
380 if( nFlags != IDF_NONE )
382 pTabViewShell->DeleteContents( nFlags );
384 if( ! rReq.IsAPI() )
386 OUString aFlags;
388 if( nFlags == IDF_ALL )
390 aFlags += "A";
392 else
394 if( nFlags & IDF_STRING ) aFlags += "S";
395 if( nFlags & IDF_VALUE ) aFlags += "V";
396 if( nFlags & IDF_DATETIME ) aFlags += "D";
397 if( nFlags & IDF_FORMULA ) aFlags += "F";
398 if( nFlags & IDF_NOTE ) aFlags += "N";
399 if( nFlags & IDF_ATTRIB ) aFlags += "T";
400 if( nFlags & IDF_OBJECTS ) aFlags += "O";
403 rReq.AppendItem( SfxStringItem( SID_DELETE, aFlags ) );
404 rReq.Done();
408 break;
410 // 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 InsertDeleteFlags nFlags = IDF_NONE;
435 sal_uInt16 nFunction = PASTE_NOFUNC;
436 bool bSkipEmpty = false;
437 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 = static_cast<const SfxStringItem*>(pItem)->GetValue();
447 aFlags = aFlags.toAsciiUpperCase();
448 bool bCont = 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 boost::scoped_ptr<AbstractScInsertContentsDlg> pDlg(pFact->CreateScInsertContentsDlg( pTabViewShell->GetDialogParent(),
473 IDF_NONE, /* 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
488 if( nFlags != IDF_NONE )
490 pTabViewShell->FillTab( nFlags, nFunction, bSkipEmpty, bAsLink );
492 if( ! rReq.IsAPI() )
494 OUString aFlags;
496 if( nFlags == IDF_ALL )
498 aFlags += "A";
500 else
502 if( nFlags & IDF_STRING ) aFlags += "S";
503 if( nFlags & IDF_VALUE ) aFlags += "V";
504 if( nFlags & IDF_DATETIME ) aFlags += "D";
505 if( nFlags & IDF_FORMULA ) aFlags += "F";
506 if( nFlags & IDF_NOTE ) aFlags += "N";
507 if( nFlags & IDF_ATTRIB ) aFlags += "T";
510 rReq.AppendItem( SfxStringItem( FID_FILL_TAB, aFlags ) );
511 rReq.Done();
515 break;
517 case FID_FILL_SERIES:
519 SCCOL nStartCol;
520 SCROW nStartRow;
521 SCTAB nStartTab;
522 SCCOL nEndCol;
523 SCROW nEndRow;
524 SCTAB nEndTab;
525 sal_uInt16 nPossDir = FDS_OPT_NONE;
526 FillDir eFillDir = FILL_TO_BOTTOM;
527 FillCmd eFillCmd = FILL_LINEAR;
528 FillDateCmd eFillDateCmd = FILL_DAY;
529 double fStartVal = MAXDOUBLE;
530 double fIncVal = 1;
531 double fMaxVal = MAXDOUBLE;
532 bool bDoIt = false;
534 GetViewData()->GetSimpleArea( nStartCol, nStartRow, nStartTab,
535 nEndCol, nEndRow, nEndTab );
537 if( nStartCol!=nEndCol )
539 nPossDir |= FDS_OPT_HORZ;
540 eFillDir=FILL_TO_RIGHT;
543 if( nStartRow!=nEndRow )
545 nPossDir |= FDS_OPT_VERT;
546 eFillDir=FILL_TO_BOTTOM;
549 ScDocument* pDoc = GetViewData()->GetDocument();
550 SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
552 if( pReqArgs )
554 const SfxPoolItem* pItem;
555 OUString aFillDir, aFillCmd, aFillDateCmd;
556 OUString aFillStep, aFillStart, aFillMax;
557 sal_uInt32 nKey;
558 double fTmpVal;
560 bDoIt=false;
562 if( pReqArgs->HasItem( FID_FILL_SERIES, &pItem ) )
563 aFillDir = static_cast<const SfxStringItem*>(pItem)->GetValue();
564 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
565 aFillCmd = static_cast<const SfxStringItem*>(pItem)->GetValue();
566 if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
567 aFillDateCmd = static_cast<const SfxStringItem*>(pItem)->GetValue();
568 if( pReqArgs->HasItem( FN_PARAM_3, &pItem ) )
569 aFillStep = static_cast<const SfxStringItem*>(pItem)->GetValue();
570 if( pReqArgs->HasItem( FN_PARAM_4, &pItem ) )
571 aFillStart = static_cast<const SfxStringItem*>(pItem)->GetValue();
572 if( pReqArgs->HasItem( FN_PARAM_5, &pItem ) )
573 aFillMax = static_cast<const SfxStringItem*>(pItem)->GetValue();
575 if( !aFillDir.isEmpty() )
576 switch( aFillDir[0] )
578 case 'B': case 'b': eFillDir=FILL_TO_BOTTOM; break;
579 case 'R': case 'r': eFillDir=FILL_TO_RIGHT; break;
580 case 'T': case 't': eFillDir=FILL_TO_TOP; break;
581 case 'L': case 'l': eFillDir=FILL_TO_LEFT; break;
584 if( !aFillCmd.isEmpty() )
585 switch( aFillCmd[0] )
587 case 'S': case 's': eFillCmd=FILL_SIMPLE; break;
588 case 'L': case 'l': eFillCmd=FILL_LINEAR; break;
589 case 'G': case 'g': eFillCmd=FILL_GROWTH; break;
590 case 'D': case 'd': eFillCmd=FILL_DATE; break;
591 case 'A': case 'a': eFillCmd=FILL_AUTO; break;
594 if( !aFillDateCmd.isEmpty() )
595 switch( aFillDateCmd[0] )
597 case 'D': case 'd': eFillDateCmd=FILL_DAY; break;
598 case 'W': case 'w': eFillDateCmd=FILL_WEEKDAY; break;
599 case 'M': case 'm': eFillDateCmd=FILL_MONTH; break;
600 case 'Y': case 'y': eFillDateCmd=FILL_YEAR; break;
603 nKey = 0;
604 if( pFormatter->IsNumberFormat( aFillStart, nKey, fTmpVal ))
605 fStartVal = fTmpVal;
607 nKey = 0;
608 if( pFormatter->IsNumberFormat( aFillStep, nKey, fTmpVal ))
609 fIncVal = fTmpVal;
611 nKey = 0;
612 if( pFormatter->IsNumberFormat( aFillMax, nKey, fTmpVal ))
613 fMaxVal = fTmpVal;
615 bDoIt = true;
618 else // (pReqArgs == NULL) => raise Dialog
620 sal_uInt32 nPrivFormat;
621 CellType eCellType;
622 pDoc->GetNumberFormat( nStartCol, nStartRow, nStartTab, nPrivFormat );
623 pDoc->GetCellType( nStartCol, nStartRow, nStartTab,eCellType );
624 const SvNumberformat* pPrivEntry = pFormatter->GetEntry( nPrivFormat );
625 if (!pPrivEntry)
627 OSL_FAIL("Numberformat not found !!!");
629 else
631 short nPrivType = pPrivEntry->GetType();
632 if ( ( nPrivType & css::util::NumberFormat::DATE)>0)
634 eFillCmd=FILL_DATE;
636 else if(eCellType==CELLTYPE_STRING)
638 eFillCmd=FILL_AUTO;
642 OUString aStartStr;
644 // suggest default Startvalue only, when just 1 row or column
645 if ( nStartCol == nEndCol || nStartRow == nEndRow )
647 double fInputEndVal = 0.0;
648 OUString aEndStr;
650 pDoc->GetInputString( nStartCol, nStartRow, nStartTab, aStartStr);
651 pDoc->GetValue( nStartCol, nStartRow, nStartTab, fStartVal );
653 if(eFillDir==FILL_TO_BOTTOM && nStartRow < nEndRow )
655 pDoc->GetInputString( nStartCol, nStartRow+1, nStartTab, aEndStr);
656 if(!aEndStr.isEmpty())
658 pDoc->GetValue( nStartCol, nStartRow+1, nStartTab, fInputEndVal);
659 fIncVal=fInputEndVal-fStartVal;
662 else
664 if(nStartCol < nEndCol)
666 pDoc->GetInputString( nStartCol+1, nStartRow, nStartTab, aEndStr);
667 if(!aEndStr.isEmpty())
669 pDoc->GetValue( nStartCol+1, nStartRow, nStartTab, fInputEndVal);
670 fIncVal=fInputEndVal-fStartVal;
674 if(eFillCmd==FILL_DATE)
676 Date aNullDate = *pDoc->GetFormatTable()->GetNullDate();
677 Date aStartDate = aNullDate;
678 aStartDate+= (long)fStartVal;
679 Date aEndDate = aNullDate;
680 aEndDate+= (long)fInputEndVal;
681 double fTempDate=0;
683 if(aStartDate.GetYear()!=aEndDate.GetYear())
685 eFillDateCmd = FILL_YEAR;
686 fTempDate=aEndDate.GetYear()-aStartDate.GetYear();
688 if(aStartDate.GetMonth()!=aEndDate.GetMonth())
690 eFillDateCmd = FILL_MONTH;
691 fTempDate=fTempDate*12+aEndDate.GetMonth()-aStartDate.GetMonth();
693 if(aStartDate.GetDay()==aEndDate.GetDay())
695 fIncVal=fTempDate;
699 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
700 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
702 boost::scoped_ptr<AbstractScFillSeriesDlg> pDlg(pFact->CreateScFillSeriesDlg( pTabViewShell->GetDialogParent(),
703 *pDoc,
704 eFillDir, eFillCmd, eFillDateCmd,
705 aStartStr, fIncVal, fMaxVal,
706 nPossDir));
707 OSL_ENSURE(pDlg, "Dialog create fail!");
709 if ( nStartCol != nEndCol && nStartRow != nEndRow )
711 pDlg->SetEdStartValEnabled(false);
714 if ( pDlg->Execute() == RET_OK )
716 eFillDir = pDlg->GetFillDir();
717 eFillCmd = pDlg->GetFillCmd();
718 eFillDateCmd = pDlg->GetFillDateCmd();
720 if(eFillCmd==FILL_AUTO)
722 OUString aStr = pDlg->GetStartStr();
723 if(!aStr.isEmpty())
724 pTabViewShell->EnterData( nStartCol, nStartRow, nStartTab, aStr );
726 fStartVal = pDlg->GetStart();
727 fIncVal = pDlg->GetStep();
728 fMaxVal = pDlg->GetMax();
729 bDoIt = true;
733 if( bDoIt )
735 //nScFillModeMouseModifier = 0; // no Ctrl/Copy
736 pTabViewShell->FillSeries( eFillDir, eFillCmd, eFillDateCmd, fStartVal, fIncVal, fMaxVal );
738 if( ! rReq.IsAPI() )
740 OUString aPara;
741 Color* pColor=0;
743 switch( eFillDir )
745 case FILL_TO_BOTTOM: aPara = "B"; break;
746 case FILL_TO_RIGHT: aPara = "R"; break;
747 case FILL_TO_TOP: aPara = "T"; break;
748 case FILL_TO_LEFT: aPara = "L"; break;
749 default: break;
751 rReq.AppendItem( SfxStringItem( FID_FILL_SERIES, aPara ) );
753 switch( eFillCmd )
755 case FILL_SIMPLE: aPara = "S"; break;
756 case FILL_LINEAR: aPara = "L"; break;
757 case FILL_GROWTH: aPara = "G"; break;
758 case FILL_DATE: aPara = "D"; break;
759 case FILL_AUTO: aPara = "A"; break;
760 default: break;
762 rReq.AppendItem( SfxStringItem( FN_PARAM_1, aPara ) );
764 switch( eFillDateCmd )
766 case FILL_DAY: aPara = "D"; break;
767 case FILL_WEEKDAY: aPara = "W"; break;
768 case FILL_MONTH: aPara = "M"; break;
769 case FILL_YEAR: aPara = "Y"; break;
770 default: break;
772 rReq.AppendItem( SfxStringItem( FN_PARAM_2, aPara ) );
774 sal_uLong nFormatKey = pFormatter->GetStandardFormat(css::util::NumberFormat::NUMBER,
775 ScGlobal::eLnge );
777 pFormatter->GetOutputString( fIncVal, nFormatKey, aPara, &pColor );
778 rReq.AppendItem( SfxStringItem( FN_PARAM_3, aPara ) );
780 pFormatter->GetOutputString( fStartVal, nFormatKey, aPara, &pColor );
781 rReq.AppendItem( SfxStringItem( FN_PARAM_4, aPara ) );
783 pFormatter->GetOutputString( fMaxVal, nFormatKey, aPara, &pColor );
784 rReq.AppendItem( SfxStringItem( FN_PARAM_5, aPara ) );
786 rReq.Done();
790 break;
792 case FID_FILL_AUTO:
794 SCCOL nStartCol;
795 SCROW nStartRow;
796 SCCOL nEndCol;
797 SCROW nEndRow;
798 SCTAB nStartTab, nEndTab;
800 GetViewData()->GetFillData( nStartCol, nStartRow, nEndCol, nEndRow );
801 SCCOL nFillCol = GetViewData()->GetRefEndX();
802 SCROW nFillRow = GetViewData()->GetRefEndY();
803 ScDocument* pDoc = GetViewData()->GetDocument();
805 if( pReqArgs != NULL )
807 const SfxPoolItem* pItem;
809 if( pReqArgs->HasItem( FID_FILL_AUTO, &pItem ) )
811 ScAddress aScAddress;
812 OUString aArg = static_cast<const SfxStringItem*>(pItem)->GetValue();
814 if( aScAddress.Parse( aArg, pDoc, pDoc->GetAddressConvention() ) & SCA_VALID )
816 nFillRow = aScAddress.Row();
817 nFillCol = aScAddress.Col();
821 GetViewData()->GetSimpleArea( nStartCol,nStartRow,nStartTab,
822 nEndCol,nEndRow,nEndTab );
824 else // call via mouse
826 // not in a merged cell
828 if ( nStartCol == nEndCol && nStartRow == nEndRow )
830 SCCOL nMergeCol = nStartCol;
831 SCROW nMergeRow = nStartRow;
832 if ( GetViewData()->GetDocument()->ExtendMerge(
833 nStartCol, nStartRow, nMergeCol, nMergeRow,
834 GetViewData()->GetTabNo() ) )
836 if ( nFillCol >= nStartCol && nFillCol <= nMergeCol && nFillRow == nStartRow )
837 nFillCol = nStartCol;
838 if ( nFillRow >= nStartRow && nFillRow <= nMergeRow && nFillCol == nStartCol )
839 nFillRow = nStartRow;
844 if ( nFillCol != nEndCol || nFillRow != nEndRow )
846 if ( nFillCol==nEndCol || nFillRow==nEndRow )
848 FillDir eDir = FILL_TO_BOTTOM;
849 SCCOLROW nCount = 0;
851 if ( nFillCol==nEndCol )
853 if ( nFillRow > nEndRow )
855 eDir = FILL_TO_BOTTOM;
856 nCount = nFillRow - nEndRow;
858 else if ( nFillRow < nStartRow )
860 eDir = FILL_TO_TOP;
861 nCount = nStartRow - nFillRow;
864 else
866 if ( nFillCol > nEndCol )
868 eDir = FILL_TO_RIGHT;
869 nCount = nFillCol - nEndCol;
871 else if ( nFillCol < nStartCol )
873 eDir = FILL_TO_LEFT;
874 nCount = nStartCol - nFillCol;
878 if ( nCount != 0)
880 pTabViewShell->FillAuto( eDir, nStartCol, nStartRow, nEndCol, nEndRow, nCount );
882 if( ! rReq.IsAPI() )
884 ScAddress aAdr( nFillCol, nFillRow, 0 );
885 OUString aAdrStr(aAdr.Format(SCR_ABS, pDoc, pDoc->GetAddressConvention()));
887 rReq.AppendItem( SfxStringItem( FID_FILL_AUTO, aAdrStr ) );
888 rReq.Done();
893 else
895 OSL_FAIL( "Direction not unique for autofill" );
899 break;
900 case FID_FILL_SINGLE_EDIT:
901 ExecuteFillSingleEdit();
902 break;
903 case SID_RANDOM_NUMBER_GENERATOR_DIALOG:
905 sal_uInt16 nId = ScRandomNumberGeneratorDialogWrapper::GetChildWindowId();
906 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
907 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
909 pScMod->SetRefDialog( nId, pWnd == nullptr );
912 break;
913 case SID_SAMPLING_DIALOG:
915 sal_uInt16 nId = ScSamplingDialogWrapper::GetChildWindowId();
916 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
917 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
919 pScMod->SetRefDialog( nId, pWnd == nullptr );
921 break;
922 case SID_DESCRIPTIVE_STATISTICS_DIALOG:
924 sal_uInt16 nId = ScDescriptiveStatisticsDialogWrapper::GetChildWindowId();
925 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
926 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
928 pScMod->SetRefDialog( nId, pWnd == nullptr );
930 break;
931 case SID_ANALYSIS_OF_VARIANCE_DIALOG:
933 sal_uInt16 nId = ScAnalysisOfVarianceDialogWrapper::GetChildWindowId();
934 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
935 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
937 pScMod->SetRefDialog( nId, pWnd == nullptr );
939 break;
940 case SID_CORRELATION_DIALOG:
942 sal_uInt16 nId = ScCorrelationDialogWrapper::GetChildWindowId();
943 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
944 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
946 pScMod->SetRefDialog( nId, pWnd == nullptr );
948 break;
949 case SID_COVARIANCE_DIALOG:
951 sal_uInt16 nId = ScCovarianceDialogWrapper::GetChildWindowId();
952 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
953 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
955 pScMod->SetRefDialog( nId, pWnd == nullptr );
957 break;
958 case SID_EXPONENTIAL_SMOOTHING_DIALOG:
960 sal_uInt16 nId = ScExponentialSmoothingDialogWrapper::GetChildWindowId();
961 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
962 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
964 pScMod->SetRefDialog( nId, pWnd == nullptr );
966 break;
967 case SID_MOVING_AVERAGE_DIALOG:
969 sal_uInt16 nId = ScMovingAverageDialogWrapper::GetChildWindowId();
970 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
971 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
973 pScMod->SetRefDialog( nId, pWnd == nullptr );
975 break;
976 case SID_TTEST_DIALOG:
978 sal_uInt16 nId = ScTTestDialogWrapper::GetChildWindowId();
979 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
980 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
982 pScMod->SetRefDialog( nId, pWnd == nullptr );
985 break;
986 case SID_FTEST_DIALOG:
988 sal_uInt16 nId = ScFTestDialogWrapper::GetChildWindowId();
989 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
990 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
992 pScMod->SetRefDialog( nId, pWnd == nullptr );
995 break;
996 case SID_ZTEST_DIALOG:
998 sal_uInt16 nId = ScZTestDialogWrapper::GetChildWindowId();
999 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1000 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
1002 pScMod->SetRefDialog( nId, pWnd == nullptr );
1005 break;
1006 case SID_CHI_SQUARE_TEST_DIALOG:
1008 sal_uInt16 nId = ScChiSquareTestDialogWrapper::GetChildWindowId();
1009 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1010 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
1012 pScMod->SetRefDialog( nId, pWnd == nullptr );
1015 break;
1017 case SID_SEARCH_RESULTS_DIALOG:
1019 const SfxPoolItem* pItem = NULL;
1020 if (pReqArgs && pReqArgs->HasItem(SID_SEARCH_RESULTS_DIALOG, &pItem))
1022 bool bVisible = static_cast<const SfxBoolItem*>(pItem)->GetValue();
1023 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1024 // The window ID should equal the slot ID, but not a biggie if it wasn't.
1025 sal_uInt16 nId = sc::SearchResultsDlgWrapper::GetChildWindowId();
1026 pViewFrm->SetChildWindow(nId, bVisible, false);
1028 rReq.Done();
1030 break;
1032 // disposal (Outlines)
1033 // SID_AUTO_OUTLINE, SID_OUTLINE_DELETEALL in Execute (in docsh.idl)
1035 case SID_OUTLINE_HIDE:
1036 if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
1037 GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
1038 pTabViewShell->SetDataPilotDetails( false );
1039 else
1040 pTabViewShell->HideMarkedOutlines();
1041 rReq.Done();
1042 break;
1044 case SID_OUTLINE_SHOW:
1046 ScDPObject* pDPObj = GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
1047 GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
1048 if ( pDPObj )
1050 Sequence<sheet::DataPilotFieldFilter> aFilters;
1051 sal_uInt16 nOrientation;
1052 if ( pTabViewShell->HasSelectionForDrillDown( nOrientation ) )
1054 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1055 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1057 AbstractScDPShowDetailDlg* pDlg = pFact->CreateScDPShowDetailDlg(
1058 pTabViewShell->GetDialogParent(), RID_SCDLG_DPSHOWDETAIL, *pDPObj, nOrientation );
1059 OSL_ENSURE(pDlg, "Dialog create fail!");
1060 if ( pDlg->Execute() == RET_OK )
1062 OUString aNewDimName( pDlg->GetDimensionName() );
1063 pTabViewShell->SetDataPilotDetails( true, &aNewDimName );
1066 else if ( !pDPObj->IsServiceData() &&
1067 pDPObj->GetDataFieldPositionData(
1068 ScAddress( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() ),
1069 aFilters ) )
1070 pTabViewShell->ShowDataPilotSourceData( *pDPObj, aFilters );
1071 else
1072 pTabViewShell->SetDataPilotDetails(true);
1074 else
1075 pTabViewShell->ShowMarkedOutlines();
1076 rReq.Done();
1078 break;
1080 case SID_OUTLINE_MAKE:
1082 bool bColumns = false;
1083 bool bOk = true;
1085 if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
1086 GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
1088 ScDPNumGroupInfo aNumInfo;
1089 aNumInfo.mbEnable = true;
1090 aNumInfo.mbAutoStart = true;
1091 aNumInfo.mbAutoEnd = true;
1092 sal_Int32 nParts = 0;
1093 if ( pTabViewShell->HasSelectionForDateGroup( aNumInfo, nParts ) )
1095 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1096 OSL_ENSURE( pFact, "ScAbstractFactory create fail!" );
1097 Date aNullDate( *GetViewData()->GetDocument()->GetFormatTable()->GetNullDate() );
1098 AbstractScDPDateGroupDlg* pDlg = pFact->CreateScDPDateGroupDlg(
1099 pTabViewShell->GetDialogParent(), RID_SCDLG_DPDATEGROUP,
1100 aNumInfo, nParts, aNullDate );
1101 OSL_ENSURE( pDlg, "Dialog create fail!" );
1102 if( pDlg->Execute() == RET_OK )
1104 aNumInfo = pDlg->GetGroupInfo();
1105 pTabViewShell->DateGroupDataPilot( aNumInfo, pDlg->GetDatePart() );
1108 else if ( pTabViewShell->HasSelectionForNumGroup( aNumInfo ) )
1110 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1111 OSL_ENSURE( pFact, "ScAbstractFactory create fail!" );
1112 AbstractScDPNumGroupDlg* pDlg = pFact->CreateScDPNumGroupDlg(
1113 pTabViewShell->GetDialogParent(), RID_SCDLG_DPNUMGROUP, aNumInfo );
1114 OSL_ENSURE( pDlg, "Dialog create fail!" );
1115 if( pDlg->Execute() == RET_OK )
1116 pTabViewShell->NumGroupDataPilot( pDlg->GetGroupInfo() );
1118 else
1119 pTabViewShell->GroupDataPilot();
1121 bOk = false;
1123 else if( pReqArgs != NULL )
1125 const SfxPoolItem* pItem;
1126 bOk = false;
1128 if( pReqArgs->HasItem( SID_OUTLINE_MAKE, &pItem ) )
1130 OUString aCol = static_cast<const SfxStringItem*>(pItem)->GetValue();
1131 aCol = aCol.toAsciiUpperCase();
1133 switch( aCol[0] )
1135 case 'R': bColumns=false; bOk = true;break;
1136 case 'C': bColumns=true; bOk = true;break;
1140 else // Dialog, when not whole rows/columns are marked
1142 if ( GetViewData()->SimpleColMarked() && !GetViewData()->SimpleRowMarked() )
1143 bColumns = true;
1144 else if ( !GetViewData()->SimpleColMarked() && GetViewData()->SimpleRowMarked() )
1145 bColumns = false;
1146 else
1148 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1149 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1151 boost::scoped_ptr<AbstractScGroupDlg> pDlg(pFact->CreateAbstractScGroupDlg(pTabViewShell->GetDialogParent(), false));
1152 OSL_ENSURE(pDlg, "Dialog create fail!");
1153 if ( pDlg->Execute() == RET_OK )
1154 bColumns = pDlg->GetColsChecked();
1155 else
1156 bOk = false;
1159 if (bOk)
1161 pTabViewShell->MakeOutline( bColumns );
1163 if( ! rReq.IsAPI() )
1165 OUString aCol = bColumns ? OUString('C') : OUString('R');
1166 rReq.AppendItem( SfxStringItem( SID_OUTLINE_MAKE, aCol ) );
1167 rReq.Done();
1171 break;
1173 case SID_OUTLINE_REMOVE:
1175 bool bColumns = false;
1176 bool bOk = true;
1178 if ( GetViewData()->GetDocument()->GetDPAtCursor( GetViewData()->GetCurX(),
1179 GetViewData()->GetCurY(), GetViewData()->GetTabNo() ) )
1181 pTabViewShell->UngroupDataPilot();
1182 bOk = false;
1184 else if( pReqArgs != NULL )
1186 const SfxPoolItem* pItem;
1187 bOk = false;
1189 if( pReqArgs->HasItem( SID_OUTLINE_REMOVE, &pItem ) )
1191 OUString aCol = static_cast<const SfxStringItem*>(pItem)->GetValue();
1192 aCol = aCol.toAsciiUpperCase();
1194 switch (aCol[0])
1196 case 'R': bColumns=false; bOk = true;break;
1197 case 'C': bColumns=true; bOk = true;break;
1201 else // Dialog only when removal for rows and columns is possible
1203 bool bColPoss, bRowPoss;
1204 pTabViewShell->TestRemoveOutline( bColPoss, bRowPoss );
1205 if ( bColPoss && bRowPoss )
1207 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1208 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1210 boost::scoped_ptr<AbstractScGroupDlg> pDlg(pFact->CreateAbstractScGroupDlg(pTabViewShell->GetDialogParent(), true));
1211 OSL_ENSURE(pDlg, "Dialog create fail!");
1212 if ( pDlg->Execute() == RET_OK )
1213 bColumns = pDlg->GetColsChecked();
1214 else
1215 bOk = false;
1217 else if ( bColPoss )
1218 bColumns = true;
1219 else if ( bRowPoss )
1220 bColumns = false;
1221 else
1222 bOk = false;
1224 if (bOk)
1226 pTabViewShell->RemoveOutline( bColumns );
1228 if( ! rReq.IsAPI() )
1230 OUString aCol = bColumns ? OUString('C') : OUString('R');
1231 rReq.AppendItem( SfxStringItem( SID_OUTLINE_REMOVE, aCol ) );
1232 rReq.Done();
1236 break;
1238 // Clipboard
1240 case SID_COPY: // for graphs in DrawShell
1242 WaitObject aWait( GetViewData()->GetDialogParent() );
1243 pTabViewShell->CopyToClip( NULL, false, false, true );
1244 rReq.Done();
1245 GetViewData()->SetPasteMode( (ScPasteFlags) (SC_PASTE_MODE | SC_PASTE_BORDER) );
1246 pTabViewShell->ShowCursor();
1247 pTabViewShell->UpdateCopySourceOverlay();
1249 break;
1251 case SID_CUT: // for graphs in DrawShell
1253 WaitObject aWait( GetViewData()->GetDialogParent() );
1254 pTabViewShell->CutToClip( NULL, true );
1255 rReq.Done();
1256 GetViewData()->SetPasteMode( (ScPasteFlags)(SC_PASTE_MODE | SC_PASTE_BORDER));
1257 pTabViewShell->ShowCursor();
1258 pTabViewShell->UpdateCopySourceOverlay();
1260 break;
1262 case SID_PASTE:
1264 ScClipUtil::PasteFromClipboard ( GetViewData(), pTabViewShell, true );
1265 rReq.Done();
1267 break;
1269 case SID_CLIPBOARD_FORMAT_ITEMS:
1271 WaitObject aWait( GetViewData()->GetDialogParent() );
1273 SotClipboardFormatId nFormat = SotClipboardFormatId::NONE;
1274 const SfxPoolItem* pItem;
1275 if ( pReqArgs &&
1276 pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET &&
1277 pItem->ISA(SfxUInt32Item) )
1279 nFormat = static_cast<SotClipboardFormatId>(static_cast<const SfxUInt32Item*>(pItem)->GetValue());
1282 if ( nFormat != SotClipboardFormatId::NONE )
1284 vcl::Window* pWin = GetViewData()->GetActiveWin();
1285 bool bCells = ( ScTransferObj::GetOwnClipboard( pWin ) != NULL );
1286 bool bDraw = ( ScDrawTransferObj::GetOwnClipboard( pWin ) != NULL );
1287 bool bOle = ( nFormat == SotClipboardFormatId::EMBED_SOURCE );
1289 if ( bCells && bOle )
1290 pTabViewShell->PasteFromSystem();
1291 else if ( bDraw && bOle )
1292 pTabViewShell->PasteDraw();
1293 else
1294 pTabViewShell->PasteFromSystem(nFormat);
1296 //?else
1297 //? pTabViewShell->PasteFromSystem();
1299 rReq.Done();
1301 pTabViewShell->CellContentChanged();
1302 break;
1304 case FID_INS_CELL_CONTENTS:
1306 InsertDeleteFlags nFlags = IDF_NONE;
1307 sal_uInt16 nFunction = PASTE_NOFUNC;
1308 InsCellCmd eMoveMode = INS_NONE;
1310 vcl::Window* pWin = GetViewData()->GetActiveWin();
1311 ScDocument* pDoc = GetViewData()->GetDocument();
1312 bool bOtherDoc = !pDoc->IsClipboardSource();
1313 ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin );
1314 if ( pOwnClip )
1316 bool bSkipEmpty = false;
1317 bool bTranspose = false;
1318 bool bAsLink = false;
1320 // keep a reference in case the clipboard is changed during dialog or PasteFromClip
1321 uno::Reference<datatransfer::XTransferable> aOwnClipRef( pOwnClip );
1322 if ( pReqArgs!=NULL && pTabViewShell->SelectionEditable() )
1324 const SfxPoolItem* pItem;
1325 OUString aFlags('A');
1327 if( pReqArgs->HasItem( FID_INS_CELL_CONTENTS, &pItem ) )
1328 aFlags = static_cast<const SfxStringItem*>(pItem)->GetValue();
1330 aFlags = aFlags.toAsciiUpperCase();
1331 bool bCont = true;
1333 for (sal_Int32 i=0 ; bCont && i<aFlags.getLength(); ++i)
1335 switch (aFlags[i])
1337 case 'A': // all
1338 nFlags |= IDF_ALL;
1339 bCont = false; // don't continue!
1340 break;
1341 case 'S': nFlags |= IDF_STRING; break;
1342 case 'V': nFlags |= IDF_VALUE; break;
1343 case 'D': nFlags |= IDF_DATETIME; break;
1344 case 'F': nFlags |= IDF_FORMULA; break;
1345 case 'N': nFlags |= IDF_NOTE; break;
1346 case 'T': nFlags |= IDF_ATTRIB; break;
1350 SFX_REQUEST_ARG( rReq, pFuncItem, SfxUInt16Item, FN_PARAM_1, false );
1351 SFX_REQUEST_ARG( rReq, pSkipItem, SfxBoolItem, FN_PARAM_2, false );
1352 SFX_REQUEST_ARG( rReq, pTransposeItem, SfxBoolItem, FN_PARAM_3, false );
1353 SFX_REQUEST_ARG( rReq, pLinkItem, SfxBoolItem, FN_PARAM_4, false );
1354 SFX_REQUEST_ARG( rReq, pMoveItem, SfxInt16Item, FN_PARAM_5, false );
1355 if ( pFuncItem )
1356 nFunction = pFuncItem->GetValue();
1357 if ( pSkipItem )
1358 bSkipEmpty = pSkipItem->GetValue();
1359 if ( pTransposeItem )
1360 bTranspose = pTransposeItem->GetValue();
1361 if ( pLinkItem )
1362 bAsLink = pLinkItem->GetValue();
1363 if ( pMoveItem )
1364 eMoveMode = (InsCellCmd) pMoveItem->GetValue();
1366 else
1368 ScEditableTester aTester( pTabViewShell );
1369 if (aTester.IsEditable())
1371 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1372 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1374 boost::scoped_ptr<AbstractScInsertContentsDlg> pDlg(pFact->CreateScInsertContentsDlg(pTabViewShell->GetDialogParent()));
1375 OSL_ENSURE(pDlg, "Dialog create fail!");
1376 pDlg->SetOtherDoc( bOtherDoc );
1377 // if ChangeTrack MoveMode disable
1378 pDlg->SetChangeTrack( pDoc->GetChangeTrack() != NULL );
1379 // fdo#56098 disable shift if necessary
1380 if ( !bOtherDoc && pOwnClip )
1382 ScViewData* pData = GetViewData();
1383 if ( pData->GetMarkData().GetTableSelect( pData->GetTabNo() ) )
1385 SCCOL nStartX, nEndX, nClipStartX, nClipSizeX, nRangeSizeX;
1386 SCROW nStartY, nEndY, nClipStartY, nClipSizeY, nRangeSizeY;
1387 SCTAB nStartTab, nEndTab;
1388 pOwnClip->GetDocument()->GetClipStart( nClipStartX, nClipStartY );
1389 pOwnClip->GetDocument()->GetClipArea( nClipSizeX, nClipSizeY, true );
1391 if ( !( pData->GetSimpleArea( nStartX, nStartY, nStartTab,
1392 nEndX, nEndY, nEndTab ) == SC_MARK_SIMPLE &&
1393 nStartTab == nEndTab ) )
1395 // the destination is not a simple range,
1396 // assume the destination as the current cell
1397 nStartX = nEndX = pData->GetCurX();
1398 nStartY = nEndY = pData->GetCurY();
1399 nStartTab = pData->GetTabNo();
1401 // we now have clip- and range dimensions
1402 // the size of the destination area is the larger of the two
1403 nRangeSizeX = nClipSizeX >= nEndX - nStartX ? nClipSizeX : nEndX - nStartX;
1404 nRangeSizeY = nClipSizeY >= nEndY - nStartY ? nClipSizeY : nEndY - nStartY;
1405 // When the source and destination areas intersect things may go wrong,
1406 // especially if the area contains references. This may produce data loss
1407 // (e.g. formulas that get wrong references), this scenario _must_ be avoided.
1408 ScRange aSource( nClipStartX, nClipStartY, nStartTab,
1409 nClipStartX + nClipSizeX, nClipStartY + nClipSizeY, nStartTab );
1410 ScRange aDest( nStartX, nStartY, nStartTab,
1411 nStartX + nRangeSizeX, nStartY + nRangeSizeY, nStartTab );
1412 if ( pOwnClip->GetDocument()->IsCutMode() && aSource.Intersects( aDest ) )
1413 pDlg->SetCellShiftDisabled( SC_CELL_SHIFT_DISABLE_DOWN | SC_CELL_SHIFT_DISABLE_RIGHT );
1414 else
1416 //no conflict with intersecting ranges,
1417 //check if paste plus shift will fit on sheet
1418 //and disable shift-option if no fit
1419 int nDisableShiftX = 0;
1420 int nDisableShiftY = 0;
1422 //check if horizontal shift will fit
1423 if ( !pData->GetDocument()->IsBlockEmpty( nStartTab,
1424 MAXCOL - nRangeSizeX, nStartY,
1425 MAXCOL, nStartY + nRangeSizeY, false ) )
1426 nDisableShiftX = SC_CELL_SHIFT_DISABLE_RIGHT;
1428 //check if vertical shift will fit
1429 if ( !pData->GetDocument()->IsBlockEmpty( nStartTab,
1430 nStartX, MAXROW - nRangeSizeY,
1431 nStartX + nRangeSizeX, MAXROW, false ) )
1432 nDisableShiftY = SC_CELL_SHIFT_DISABLE_DOWN;
1434 if ( nDisableShiftX || nDisableShiftY )
1435 pDlg->SetCellShiftDisabled( nDisableShiftX | nDisableShiftY );
1439 if (pDlg->Execute() == RET_OK)
1441 nFlags = pDlg->GetInsContentsCmdBits();
1442 nFunction = pDlg->GetFormulaCmdBits();
1443 bSkipEmpty = pDlg->IsSkipEmptyCells();
1444 bTranspose = pDlg->IsTranspose();
1445 bAsLink = pDlg->IsLink();
1446 eMoveMode = pDlg->GetMoveMode();
1449 else
1450 pTabViewShell->ErrorMessage(aTester.GetMessageId());
1453 if( nFlags != IDF_NONE )
1456 WaitObject aWait( GetViewData()->GetDialogParent() );
1457 if ( bAsLink && bOtherDoc )
1458 pTabViewShell->PasteFromSystem(SotClipboardFormatId::LINK); // DDE insert
1459 else
1461 pTabViewShell->PasteFromClip( nFlags, pOwnClip->GetDocument(),
1462 nFunction, bSkipEmpty, bTranspose, bAsLink,
1463 eMoveMode, IDF_NONE, true ); // allow warning dialog
1467 if( !pReqArgs )
1469 OUString aFlags;
1471 if( nFlags == IDF_ALL )
1473 aFlags += "A";
1475 else
1477 if( nFlags & IDF_STRING ) aFlags += "S";
1478 if( nFlags & IDF_VALUE ) aFlags += "V";
1479 if( nFlags & IDF_DATETIME ) aFlags += "D";
1480 if( nFlags & IDF_FORMULA ) aFlags += "F";
1481 if( nFlags & IDF_NOTE ) aFlags += "N";
1482 if( nFlags & IDF_ATTRIB ) aFlags += "T";
1485 rReq.AppendItem( SfxStringItem( FID_INS_CELL_CONTENTS, aFlags ) );
1486 rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bSkipEmpty ) );
1487 rReq.AppendItem( SfxBoolItem( FN_PARAM_3, bTranspose ) );
1488 rReq.AppendItem( SfxBoolItem( FN_PARAM_4, bAsLink ) );
1489 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, nFunction ) );
1490 rReq.AppendItem( SfxInt16Item( FN_PARAM_5, (sal_Int16) eMoveMode ) );
1491 rReq.Done();
1496 pTabViewShell->CellContentChanged(); // => PasteFromXXX ???
1497 break;
1498 case SID_PASTE_ONLY_VALUE:
1499 case SID_PASTE_ONLY_TEXT:
1500 case SID_PASTE_ONLY_FORMULA:
1502 vcl::Window* pWin = GetViewData()->GetActiveWin();
1503 if ( ScTransferObj::GetOwnClipboard( pWin ) ) // own cell data
1505 rReq.SetSlot( FID_INS_CELL_CONTENTS );
1506 OUString aFlags;
1507 if ( nSlot == SID_PASTE_ONLY_VALUE )
1508 aFlags = "V";
1509 else if ( nSlot == SID_PASTE_ONLY_TEXT )
1510 aFlags = "S";
1511 else
1512 aFlags = "F";
1513 rReq.AppendItem( SfxStringItem( FID_INS_CELL_CONTENTS, aFlags ) );
1514 ExecuteSlot( rReq, GetInterface() );
1515 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
1516 pTabViewShell->CellContentChanged();
1518 else
1519 rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1520 break;
1522 case SID_PASTE_SPECIAL:
1523 // differentiate between own cell data and draw objects/external data
1524 // this makes FID_INS_CELL_CONTENTS superfluous
1526 vcl::Window* pWin = GetViewData()->GetActiveWin();
1528 // Clipboard-ID given as parameter? Basic "PasteSpecial(Format)"
1529 const SfxPoolItem* pItem=NULL;
1530 if ( pReqArgs &&
1531 pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET &&
1532 pItem->ISA(SfxUInt32Item) )
1534 SotClipboardFormatId nFormat = static_cast<SotClipboardFormatId>(static_cast<const SfxUInt32Item*>(pItem)->GetValue());
1535 bool bRet=true;
1537 WaitObject aWait( GetViewData()->GetDialogParent() );
1538 bool bDraw = ( ScDrawTransferObj::GetOwnClipboard( pWin ) != NULL );
1539 if ( bDraw && nFormat == SotClipboardFormatId::EMBED_SOURCE )
1540 pTabViewShell->PasteDraw();
1541 else
1542 bRet = pTabViewShell->PasteFromSystem(nFormat, true); // TRUE: no error messages
1545 if ( bRet )
1547 rReq.SetReturnValue(SfxInt16Item(nSlot, bRet ? 1 : 0)); // 1 = success, 0 = fail
1548 rReq.Done();
1550 else
1551 // if format is not available -> fallback to request without parameters
1552 pItem = NULL;
1555 if ( !pItem )
1557 if ( ScTransferObj::GetOwnClipboard( pWin ) ) // own cell data
1559 rReq.SetSlot( FID_INS_CELL_CONTENTS );
1560 ExecuteSlot( rReq, GetInterface() );
1561 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
1563 else // draw objects or external data
1565 bool bDraw = ( ScDrawTransferObj::GetOwnClipboard( pWin ) != NULL );
1567 SvxClipboardFormatItem aFormats( SID_CLIPBOARD_FORMAT_ITEMS );
1568 GetPossibleClipboardFormats( aFormats );
1570 sal_uInt16 nFormatCount = aFormats.Count();
1571 if ( nFormatCount )
1573 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1574 boost::scoped_ptr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog( pTabViewShell->GetDialogParent() ));
1575 if ( pDlg )
1577 for (sal_uInt16 i=0; i<nFormatCount; i++)
1579 SotClipboardFormatId nFormatId = aFormats.GetClipbrdFormatId( i );
1580 OUString aName = aFormats.GetClipbrdFormatName( i );
1581 // special case for paste dialog: '*' is replaced by object type
1582 if ( nFormatId == SotClipboardFormatId::EMBED_SOURCE )
1583 aName = "*";
1584 pDlg->Insert( nFormatId, aName );
1587 TransferableDataHelper aDataHelper(
1588 TransferableDataHelper::CreateFromSystemClipboard( pWin ) );
1589 SotClipboardFormatId nFormat = pDlg->GetFormat( aDataHelper.GetTransferable() );
1590 if (nFormat != SotClipboardFormatId::NONE)
1593 WaitObject aWait( GetViewData()->GetDialogParent() );
1594 if ( bDraw && nFormat == SotClipboardFormatId::EMBED_SOURCE )
1595 pTabViewShell->PasteDraw();
1596 else
1597 pTabViewShell->PasteFromSystem(nFormat);
1599 rReq.SetReturnValue(SfxInt16Item(nSlot, 1)); // 1 = success
1600 rReq.AppendItem( SfxUInt32Item( nSlot, static_cast<sal_uInt32>(nFormat) ) );
1601 rReq.Done();
1603 else
1605 rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1606 rReq.Ignore();
1610 else
1611 rReq.SetReturnValue(SfxInt16Item(nSlot, 0)); // 0 = fail
1615 pTabViewShell->CellContentChanged(); // => PasteFromSystem() ???
1616 break;
1618 // other
1620 case FID_INS_ROWBRK:
1621 pTabViewShell->InsertPageBreak( false );
1622 rReq.Done();
1623 break;
1625 case FID_INS_COLBRK:
1626 pTabViewShell->InsertPageBreak( true );
1627 rReq.Done();
1628 break;
1630 case FID_DEL_ROWBRK:
1631 pTabViewShell->DeletePageBreak( false );
1632 rReq.Done();
1633 break;
1635 case FID_DEL_COLBRK:
1636 pTabViewShell->DeletePageBreak( true );
1637 rReq.Done();
1638 break;
1640 case SID_DETECTIVE_ADD_PRED:
1641 pTabViewShell->DetectiveAddPred();
1642 rReq.Done();
1643 break;
1645 case SID_DETECTIVE_DEL_PRED:
1646 pTabViewShell->DetectiveDelPred();
1647 rReq.Done();
1648 break;
1650 case SID_DETECTIVE_ADD_SUCC:
1651 pTabViewShell->DetectiveAddSucc();
1652 rReq.Done();
1653 break;
1655 case SID_DETECTIVE_DEL_SUCC:
1656 pTabViewShell->DetectiveDelSucc();
1657 rReq.Done();
1658 break;
1660 case SID_DETECTIVE_ADD_ERR:
1661 pTabViewShell->DetectiveAddError();
1662 rReq.Done();
1663 break;
1665 case SID_DETECTIVE_INVALID:
1666 pTabViewShell->DetectiveMarkInvalid();
1667 rReq.Done();
1668 break;
1670 case SID_DETECTIVE_REFRESH:
1671 pTabViewShell->DetectiveRefresh();
1672 rReq.Done();
1673 break;
1675 case SID_DETECTIVE_MARK_PRED:
1676 pTabViewShell->DetectiveMarkPred();
1677 break;
1678 case SID_DETECTIVE_MARK_SUCC:
1679 pTabViewShell->DetectiveMarkSucc();
1680 break;
1681 case SID_INSERT_CURRENT_DATE:
1682 pTabViewShell->InsertCurrentTime(
1683 css::util::NumberFormat::DATE, ScGlobal::GetRscString(STR_UNDO_INSERT_CURRENT_DATE));
1684 break;
1685 case SID_INSERT_CURRENT_TIME:
1686 pTabViewShell->InsertCurrentTime(
1687 css::util::NumberFormat::TIME, ScGlobal::GetRscString(STR_UNDO_INSERT_CURRENT_TIME));
1688 break;
1690 case SID_SPELL_DIALOG:
1692 SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame();
1693 if( rReq.GetArgs() )
1694 pViewFrame->SetChildWindow( SID_SPELL_DIALOG,
1695 static_cast< const SfxBoolItem& >( rReq.GetArgs()->
1696 Get( SID_SPELL_DIALOG ) ).GetValue() );
1697 else
1698 pViewFrame->ToggleChildWindow( SID_SPELL_DIALOG );
1700 pViewFrame->GetBindings().Invalidate( SID_SPELL_DIALOG );
1701 rReq.Ignore();
1703 break;
1705 case SID_HANGUL_HANJA_CONVERSION:
1706 pTabViewShell->DoHangulHanjaConversion();
1707 break;
1709 case SID_CHINESE_CONVERSION:
1711 //open ChineseTranslationDialog
1712 Reference< XComponentContext > xContext(
1713 ::cppu::defaultBootstrap_InitialComponentContext() ); //@todo get context from calc if that has one
1714 if(xContext.is())
1716 Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
1717 if(xMCF.is())
1719 Reference< ui::dialogs::XExecutableDialog > xDialog(
1720 xMCF->createInstanceWithContext(
1721 OUString("com.sun.star.linguistic2.ChineseTranslationDialog")
1722 , xContext), UNO_QUERY);
1723 Reference< lang::XInitialization > xInit( xDialog, UNO_QUERY );
1724 if( xInit.is() )
1726 // initialize dialog
1727 Reference< awt::XWindow > xDialogParentWindow(0);
1728 Sequence<Any> aSeq(1);
1729 Any* pArray = aSeq.getArray();
1730 PropertyValue aParam;
1731 aParam.Name = "ParentWindow";
1732 aParam.Value <<= makeAny(xDialogParentWindow);
1733 pArray[0] <<= makeAny(aParam);
1734 xInit->initialize( aSeq );
1736 //execute dialog
1737 sal_Int16 nDialogRet = xDialog->execute();
1738 if( RET_OK == nDialogRet )
1740 //get some parameters from the dialog
1741 bool bToSimplified = true;
1742 bool bUseVariants = true;
1743 bool bCommonTerms = true;
1744 Reference< beans::XPropertySet > xProp( xDialog, UNO_QUERY );
1745 if( xProp.is() )
1749 xProp->getPropertyValue("IsDirectionToSimplified") >>= bToSimplified;
1750 xProp->getPropertyValue("IsUseCharacterVariants") >>= bUseVariants;
1751 xProp->getPropertyValue("IsTranslateCommonTerms") >>= bCommonTerms;
1753 catch( Exception& )
1758 //execute translation
1759 LanguageType eSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONAL : LANGUAGE_CHINESE_SIMPLIFIED;
1760 LanguageType eTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIED : LANGUAGE_CHINESE_TRADITIONAL;
1761 sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
1762 if( !bCommonTerms )
1763 nOptions |= i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
1765 vcl::Font aTargetFont = OutputDevice::GetDefaultFont(
1766 DefaultFontType::CJK_SPREADSHEET,
1767 eTargetLang, GetDefaultFontFlags::OnlyOne );
1768 ScConversionParam aConvParam( SC_CONVERSION_CHINESE_TRANSL,
1769 eSourceLang, eTargetLang, aTargetFont, nOptions, false );
1770 pTabViewShell->DoSheetConversion( aConvParam );
1773 Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY );
1774 if( xComponent.is() )
1775 xComponent->dispose();
1779 break;
1781 case SID_CONVERT_FORMULA_TO_VALUE:
1783 pTabViewShell->ConvertFormulaToValue();
1785 break;
1786 case SID_THESAURUS:
1787 pTabViewShell->DoThesaurus();
1788 break;
1790 case SID_TOGGLE_REL:
1791 pTabViewShell->DoRefConversion();
1792 break;
1794 case SID_DEC_INDENT:
1795 pTabViewShell->ChangeIndent( false );
1796 break;
1797 case SID_INC_INDENT:
1798 pTabViewShell->ChangeIndent( true );
1799 break;
1801 case FID_USE_NAME:
1803 sal_uInt16 nFlags = pTabViewShell->GetCreateNameFlags();
1805 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1806 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1808 boost::scoped_ptr<AbstractScNameCreateDlg> pDlg(pFact->CreateScNameCreateDlg(pTabViewShell->GetDialogParent(), nFlags));
1809 OSL_ENSURE(pDlg, "Dialog create fail!");
1811 if( pDlg->Execute() )
1813 nFlags = pDlg->GetFlags();
1814 pTabViewShell->CreateNames(nFlags);
1815 rReq.Done();
1818 break;
1820 case SID_CONSOLIDATE:
1822 const SfxPoolItem* pItem;
1823 if ( pReqArgs && SfxItemState::SET ==
1824 pReqArgs->GetItemState( SCITEM_CONSOLIDATEDATA, true, &pItem ) )
1826 const ScConsolidateParam& rParam =
1827 static_cast<const ScConsolidateItem*>(pItem)->GetData();
1829 pTabViewShell->Consolidate( rParam );
1830 GetViewData()->GetDocument()->SetConsolidateDlgData( &rParam );
1832 rReq.Done();
1834 #if HAVE_FEATURE_SCRIPTING
1835 else if (rReq.IsAPI())
1836 SbxBase::SetError(SbxERR_BAD_PARAMETER);
1837 #endif
1839 break;
1841 case SID_INS_FUNCTION:
1843 const SfxBoolItem* pOkItem = static_cast<const SfxBoolItem*>(&pReqArgs->Get( SID_DLG_RETOK ));
1845 if ( pOkItem->GetValue() ) // OK
1847 OUString aFormula;
1848 const SfxStringItem* pSItem = static_cast<const SfxStringItem*>(&pReqArgs->Get( SCITEM_STRING ));
1849 const SfxBoolItem* pMatrixItem = static_cast<const SfxBoolItem*>(&pReqArgs->Get( SID_DLG_MATRIX ));
1851 aFormula += pSItem->GetValue();
1852 pScMod->ActivateInputWindow( &aFormula, pMatrixItem->GetValue() );
1854 else // CANCEL
1856 pScMod->ActivateInputWindow( NULL );
1858 rReq.Ignore(); // only SID_ENTER_STRING is recorded
1860 break;
1862 case FID_DEFINE_NAME:
1863 if ( pReqArgs )
1865 const SfxPoolItem* pItem;
1866 OUString aName, aSymbol, aAttrib;
1868 if( pReqArgs->HasItem( FID_DEFINE_NAME, &pItem ) )
1869 aName = static_cast<const SfxStringItem*>(pItem)->GetValue();
1871 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
1872 aSymbol = static_cast<const SfxStringItem*>(pItem)->GetValue();
1874 if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
1875 aAttrib = static_cast<const SfxStringItem*>(pItem)->GetValue();
1877 if ( !aName.isEmpty() && !aSymbol.isEmpty() )
1879 if (pTabViewShell->InsertName( aName, aSymbol, aAttrib ))
1880 rReq.Done();
1881 #if HAVE_FEATURE_SCRIPTING
1882 else
1883 SbxBase::SetError( SbxERR_BAD_PARAMETER ); // Basic-error
1884 #endif
1887 else
1889 sal_uInt16 nId = ScNameDlgWrapper::GetChildWindowId();
1890 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1891 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
1893 pScMod->SetRefDialog( nId, pWnd == nullptr );
1895 break;
1896 case FID_ADD_NAME:
1898 sal_uInt16 nId = ScNameDefDlgWrapper::GetChildWindowId();
1899 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1900 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
1902 pScMod->SetRefDialog( nId, pWnd == nullptr );
1904 break;
1906 case SID_OPENDLG_CONDFRMT:
1907 case SID_OPENDLG_COLORSCALE:
1908 case SID_OPENDLG_DATABAR:
1909 case SID_OPENDLG_ICONSET:
1910 case SID_OPENDLG_CONDDATE:
1912 sal_uInt32 nIndex = sal_uInt32(-1);
1913 sal_uInt8 nType = 0;
1914 bool bManaged = false;
1916 // Get the pool item stored it by Conditional Format Manager Dialog.
1917 const SfxPoolItem* pItem = NULL;
1918 sal_uInt32 nItems(pTabViewShell->GetPool().GetItemCount2( SCITEM_STRING ));
1919 for( sal_uInt32 nIter = 0; nIter < nItems; ++nIter )
1921 if( NULL != (pItem = pTabViewShell->GetPool().GetItem2( SCITEM_STRING, nIter ) ) )
1923 if ( ScCondFormatDlg::ParseXmlString(
1924 static_cast<const SfxStringItem*>(pItem)->GetValue(),
1925 nIndex, nType, bManaged))
1926 break;
1930 // Check if the Conditional Manager Dialog is editing or adding
1931 // conditional format item.
1932 if ( bManaged )
1934 sal_uInt16 nId = ScCondFormatDlgWrapper::GetChildWindowId();
1935 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
1936 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
1938 pScMod->SetRefDialog( nId, pWnd == nullptr );
1939 break;
1942 ScRangeList aRangeList;
1943 ScViewData* pData = GetViewData();
1944 pData->GetMarkData().FillRangeListWithMarks(&aRangeList, false);
1946 ScDocument* pDoc = GetViewData()->GetDocument();
1947 if(pDoc->IsTabProtected(pData->GetTabNo()))
1949 //ErrorMessage( STR_ERR_CONDFORMAT_PROTECTED );
1950 break;
1953 ScAddress aPos(pData->GetCurX(), pData->GetCurY(), pData->GetTabNo());
1954 if(aRangeList.empty())
1956 ScRange* pRange = new ScRange(aPos);
1957 aRangeList.push_back(pRange);
1960 const ScConditionalFormat* pCondFormat = NULL;
1961 const ScPatternAttr* pPattern = pDoc->GetPattern(aPos.Col(), aPos.Row(), aPos.Tab());
1962 const std::vector<sal_uInt32>& rCondFormats = static_cast<const ScCondFormatItem&>(pPattern->GetItem(ATTR_CONDITIONAL)).GetCondFormatData();
1963 bool bContainsCondFormat = !rCondFormats.empty();
1964 bool bCondFormatDlg = false;
1965 if(bContainsCondFormat)
1967 bool bContainsExistingCondFormat = false;
1968 ScConditionalFormatList* pList = pDoc->GetCondFormList(aPos.Tab());
1969 for (std::vector<sal_uInt32>::const_iterator itr = rCondFormats.begin(), itrEnd = rCondFormats.end();
1970 itr != itrEnd; ++itr)
1972 // check if at least one existing conditional format has the same range
1973 pCondFormat = pList->GetFormat(*itr);
1974 if(!pCondFormat)
1975 continue;
1977 bContainsExistingCondFormat = true;
1978 const ScRangeList& rCondFormatRange = pCondFormat->GetRange();
1979 if(rCondFormatRange == aRangeList)
1981 // found a matching range, edit this conditional format
1982 bCondFormatDlg = true;
1983 break;
1987 // if not found a conditional format ask whether we should edit one of the existing
1988 // or should create a new overlapping conditional format
1989 if(!bCondFormatDlg && bContainsExistingCondFormat)
1991 ScopedVclPtrInstance<QueryBox> aBox( pTabViewShell->GetDialogParent(), WinBits( WB_YES_NO | WB_DEF_YES ),
1992 ScGlobal::GetRscString(STR_EDIT_EXISTING_COND_FORMATS) );
1993 bool bEditExisting = aBox->Execute() == RET_YES;
1994 if(bEditExisting)
1996 // differentiate between ranges where one conditional format is defined
1997 // and several formats are defined
1998 // if we have only one => open the cond format dlg to edit it
1999 // otherwise open the manage cond format dlg
2000 if(rCondFormats.size() == 1)
2002 pCondFormat = pList->GetFormat(rCondFormats[0]);
2003 assert(pCondFormat);
2004 bCondFormatDlg = true;
2006 else
2008 // Queue message to open Conditional Format Manager Dialog.
2009 GetViewData()->GetDispatcher().Execute( SID_OPENDLG_CONDFRMT_MANAGER, SfxCallMode::ASYNCHRON );
2010 break;
2013 else
2015 // define an overlapping conditional format
2016 // does not need to be handled here
2021 condformat::dialog::ScCondFormatDialogType eType = condformat::dialog::NONE;
2022 switch(nSlot)
2024 case SID_OPENDLG_CONDFRMT:
2025 eType = condformat::dialog::CONDITION;
2026 break;
2027 case SID_OPENDLG_COLORSCALE:
2028 eType = condformat::dialog::COLORSCALE;
2029 break;
2030 case SID_OPENDLG_DATABAR:
2031 eType = condformat::dialog::DATABAR;
2032 break;
2033 case SID_OPENDLG_ICONSET:
2034 eType = condformat::dialog::ICONSET;
2035 break;
2036 case SID_OPENDLG_CONDDATE:
2037 eType = condformat::dialog::DATE;
2038 break;
2039 default:
2040 assert(false);
2041 break;
2045 if(bCondFormatDlg || !bContainsCondFormat)
2047 // Put the xml string parameter to initialize the
2048 // Conditional Format Dialog.
2049 pTabViewShell->GetPool().Put( SfxStringItem( SCITEM_STRING,
2050 ScCondFormatDlg::GenerateXmlString(
2051 pCondFormat ? pCondFormat->GetKey() : sal_uInt32(-1),
2052 sal_uInt8(eType),
2053 false
2054 ) ) );
2056 sal_uInt16 nId = ScCondFormatDlgWrapper::GetChildWindowId();
2057 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
2058 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
2060 pScMod->SetRefDialog( nId, pWnd == nullptr );
2063 break;
2065 case SID_DEFINE_COLROWNAMERANGES:
2068 sal_uInt16 nId = ScColRowNameRangesDlgWrapper::GetChildWindowId();
2069 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
2070 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
2072 pScMod->SetRefDialog( nId, pWnd == nullptr );
2075 break;
2077 case SID_UPDATECHART:
2079 bool bAll = false;
2081 if( pReqArgs )
2083 const SfxPoolItem* pItem;
2085 if( pReqArgs->HasItem( SID_UPDATECHART, &pItem ) )
2086 bAll = static_cast<const SfxBoolItem*>(pItem)->GetValue();
2089 pTabViewShell->UpdateCharts( bAll );
2091 if( ! rReq.IsAPI() )
2093 rReq.AppendItem( SfxBoolItem( SID_UPDATECHART, bAll ) );
2094 rReq.Done();
2097 break;
2099 case SID_TABOP:
2100 if (pReqArgs)
2102 const ScTabOpItem& rItem =
2103 static_cast<const ScTabOpItem&>(
2104 pReqArgs->Get( SID_TABOP ));
2106 pTabViewShell->TabOp( rItem.GetData() );
2108 rReq.Done( *pReqArgs );
2110 break;
2112 case SID_SOLVE:
2113 if (pReqArgs)
2115 const ScSolveItem& rItem =
2116 static_cast<const ScSolveItem&>(
2117 pReqArgs->Get( SCITEM_SOLVEDATA ));
2119 pTabViewShell->Solve( rItem.GetData() );
2121 rReq.Done( *pReqArgs );
2123 break;
2125 case FID_INSERT_NAME:
2127 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2128 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2130 boost::scoped_ptr<AbstractScNamePasteDlg> pDlg(pFact->CreateScNamePasteDlg( pTabViewShell->GetDialogParent(), GetViewData()->GetDocShell() ));
2131 OSL_ENSURE(pDlg, "Dialog create fail!");
2132 switch( pDlg->Execute() )
2134 case BTN_PASTE_LIST:
2135 pTabViewShell->InsertNameList();
2136 break;
2137 case BTN_PASTE_NAME:
2139 ScInputHandler* pHdl = pScMod->GetInputHdl( pTabViewShell );
2140 if (pHdl)
2142 // "=" in KeyEvent, switches to input-mode
2143 (void)pScMod->InputKeyEvent( KeyEvent('=', vcl::KeyCode()) );
2145 std::vector<OUString> aNames = pDlg->GetSelectedNames();
2146 if (!aNames.empty())
2148 OUStringBuffer aBuffer;
2149 for (std::vector<OUString>::const_iterator itr = aNames.begin();
2150 itr != aNames.end(); ++itr)
2152 aBuffer.append(*itr).append(' ');
2154 pHdl->InsertFunction( aBuffer.makeStringAndClear(), false ); // without "()"
2158 break;
2161 break;
2163 case SID_RANGE_NOTETEXT:
2164 if (pReqArgs)
2166 const SfxStringItem& rTextItem = static_cast<const SfxStringItem&>(pReqArgs->Get( SID_RANGE_NOTETEXT ));
2168 // always cursor position
2169 ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
2170 pTabViewShell->SetNoteText( aPos, rTextItem.GetValue() );
2171 rReq.Done();
2173 break;
2175 case SID_INSERT_POSTIT:
2176 case SID_EDIT_POSTIT:
2177 if ( pReqArgs )
2179 const SvxPostItAuthorItem& rAuthorItem = static_cast<const SvxPostItAuthorItem&>(pReqArgs->Get( SID_ATTR_POSTIT_AUTHOR ));
2180 const SvxPostItDateItem& rDateItem = static_cast<const SvxPostItDateItem&>(pReqArgs->Get( SID_ATTR_POSTIT_DATE ));
2181 const SvxPostItTextItem& rTextItem = static_cast<const SvxPostItTextItem&>(pReqArgs->Get( SID_ATTR_POSTIT_TEXT ));
2183 ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
2184 pTabViewShell->ReplaceNote( aPos, rTextItem.GetValue(), &rAuthorItem.GetValue(), &rDateItem.GetValue() );
2185 rReq.Done();
2187 else
2189 pTabViewShell->EditNote(); // note object to edit
2191 break;
2193 case FID_NOTE_VISIBLE:
2195 ScDocument* pDoc = GetViewData()->GetDocument();
2196 ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
2197 if( ScPostIt* pNote = pDoc->GetNote(aPos) )
2199 bool bShow;
2200 const SfxPoolItem* pItem;
2201 if ( pReqArgs && (pReqArgs->GetItemState( FID_NOTE_VISIBLE, true, &pItem ) == SfxItemState::SET) )
2202 bShow = static_cast<const SfxBoolItem*>(pItem)->GetValue();
2203 else
2204 bShow = !pNote->IsCaptionShown();
2206 pTabViewShell->ShowNote( bShow );
2208 if (!pReqArgs)
2209 rReq.AppendItem( SfxBoolItem( FID_NOTE_VISIBLE, bShow ) );
2211 rReq.Done();
2212 rBindings.Invalidate( FID_NOTE_VISIBLE );
2214 else
2215 rReq.Ignore();
2217 break;
2219 case FID_HIDE_NOTE:
2220 case FID_SHOW_NOTE:
2222 bool bShowNote = nSlot == FID_SHOW_NOTE;
2223 ScViewData* pData = GetViewData();
2224 ScDocument* pDoc = pData->GetDocument();
2225 ScMarkData& rMark = pData->GetMarkData();
2226 bool bDone = false;
2228 if (!rMark.IsMarked() && !rMark.IsMultiMarked())
2230 // Check current cell
2231 ScAddress aPos( pData->GetCurX(), pData->GetCurY(), pData->GetTabNo() );
2232 if( pDoc->GetNote(aPos) )
2234 pData->GetDocShell()->GetDocFunc().ShowNote( aPos, bShowNote );
2235 bDone = true;
2238 else
2240 // Check selection range
2241 ScRangeListRef aRangesRef;
2242 pData->GetMultiArea(aRangesRef);
2243 ScRangeList aRanges = *aRangesRef;
2244 size_t nRangeSize = aRanges.size();
2246 OUString aUndo = ScGlobal::GetRscString( bShowNote ? STR_UNDO_SHOWNOTE : STR_UNDO_HIDENOTE );
2247 pData->GetDocShell()->GetUndoManager()->EnterListAction( aUndo, aUndo );
2249 for ( size_t i = 0; i < nRangeSize; ++i )
2251 const ScRange * pRange = aRanges[i];
2252 const SCROW nRow0 = pRange->aStart.Row();
2253 const SCROW nRow1 = pRange->aEnd.Row();
2254 const SCCOL nCol0 = pRange->aStart.Col();
2255 const SCCOL nCol1 = pRange->aEnd.Col();
2256 const SCTAB nRangeTab = pRange->aStart.Tab();
2257 // Check by each cell
2258 for ( SCROW nRow = nRow0; nRow <= nRow1; ++nRow )
2260 for ( SCCOL nCol = nCol0; nCol <= nCol1; ++nCol )
2262 if ( pDoc->HasNote(nCol, nRow, nRangeTab) && pDoc->IsBlockEditable( nRangeTab, nCol,nRow, nCol,nRow ) )
2264 ScAddress aPos( nCol, nRow, nRangeTab );
2265 pData->GetDocShell()->GetDocFunc().ShowNote( aPos, bShowNote );
2266 bDone = true;
2272 pData->GetDocShell()->GetUndoManager()->LeaveListAction();
2274 if ( bDone )
2276 rReq.Done();
2277 rBindings.Invalidate( nSlot );
2279 else
2280 rReq.Ignore();
2283 break;
2285 case SID_DELETE_NOTE:
2286 pTabViewShell->DeleteContents( IDF_NOTE ); // delete all notes in selection
2287 rReq.Done();
2288 break;
2290 case SID_CHARMAP:
2291 if( pReqArgs != NULL )
2293 OUString aChars, aFontName;
2294 const SfxItemSet *pArgs = rReq.GetArgs();
2295 const SfxPoolItem* pItem = 0;
2296 if ( pArgs )
2297 pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP), false, &pItem);
2298 if ( pItem )
2300 const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, pItem );
2301 if ( pStringItem )
2302 aChars = pStringItem->GetValue();
2303 const SfxPoolItem* pFtItem = NULL;
2304 pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR), false, &pFtItem);
2305 const SfxStringItem* pFontItem = PTR_CAST( SfxStringItem, pFtItem );
2306 if ( pFontItem )
2307 aFontName = pFontItem->GetValue();
2310 if ( !aChars.isEmpty() )
2312 vcl::Font aFont;
2313 pTabViewShell->GetSelectionPattern()->GetFont( aFont, SC_AUTOCOL_BLACK, NULL, NULL, NULL,
2314 pTabViewShell->GetSelectionScriptType() );
2315 if ( !aFontName.isEmpty() )
2316 aFont = vcl::Font( aFontName, Size(1,1) );
2317 pTabViewShell->InsertSpecialChar( aChars, aFont );
2318 if( ! rReq.IsAPI() )
2319 rReq.Done();
2322 else
2324 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
2326 // font color doesn't matter here
2327 vcl::Font aCurFont;
2328 pTabViewShell->GetSelectionPattern()->GetFont( aCurFont, SC_AUTOCOL_BLACK, NULL, NULL, NULL,
2329 pTabViewShell->GetSelectionScriptType() );
2331 SfxAllItemSet aSet( GetPool() );
2332 aSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
2333 aSet.Put( SvxFontItem( aCurFont.GetFamily(), aCurFont.GetName(), aCurFont.GetStyleName(), aCurFont.GetPitch(), aCurFont.GetCharSet(), GetPool().GetWhich(SID_ATTR_CHAR_FONT) ) );
2335 boost::scoped_ptr<SfxAbstractDialog> pDlg(pFact->CreateSfxDialog( pTabViewShell->GetDialogParent(), aSet,
2336 pTabViewShell->GetViewFrame()->GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP ));
2338 if ( pDlg->Execute() == RET_OK )
2340 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pItem, SfxStringItem, SID_CHARMAP, false );
2341 SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pFontItem, SvxFontItem, SID_ATTR_CHAR_FONT, false );
2343 if ( pItem && pFontItem )
2345 vcl::Font aNewFont( pFontItem->GetFamilyName(), pFontItem->GetStyleName(), Size(1,1) );
2346 aNewFont.SetCharSet( pFontItem->GetCharSet() );
2347 aNewFont.SetPitch( pFontItem->GetPitch() );
2348 pTabViewShell->InsertSpecialChar( pItem->GetValue(), aNewFont );
2349 rReq.AppendItem( *pFontItem );
2350 rReq.AppendItem( *pItem );
2351 rReq.Done();
2355 break;
2357 case SID_SELECT_SCENARIO:
2359 // Testing
2361 if ( pReqArgs )
2363 const SfxStringItem* pItem =
2364 static_cast<const SfxStringItem*>(&pReqArgs->Get( SID_SELECT_SCENARIO ));
2366 if( pItem )
2368 pTabViewShell->UseScenario( pItem->GetValue() );
2369 //! why should the return value be valid?!?!
2370 rReq.SetReturnValue( SfxStringItem( SID_SELECT_SCENARIO, pItem->GetValue() ) );
2371 rReq.Done();
2373 else
2375 OSL_FAIL("NULL");
2379 break;
2381 case SID_HYPERLINK_SETLINK:
2382 if( pReqArgs )
2384 const SfxPoolItem* pItem;
2385 if( pReqArgs->HasItem( SID_HYPERLINK_SETLINK, &pItem ) )
2387 const SvxHyperlinkItem* pHyper = static_cast<const SvxHyperlinkItem*>(pItem);
2388 const OUString& rName = pHyper->GetName();
2389 const OUString& rURL = pHyper->GetURL();
2390 const OUString& rTarget = pHyper->GetTargetFrame();
2391 sal_uInt16 nType = (sal_uInt16) pHyper->GetInsertMode();
2393 pTabViewShell->InsertURL( rName, rURL, rTarget, nType );
2394 rReq.Done();
2396 else
2397 rReq.Ignore();
2399 break;
2401 case SID_OPENDLG_CONDFRMT_MANAGER:
2403 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2404 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2406 ScViewData* pData = GetViewData();
2407 ScDocument* pDoc = pData->GetDocument();
2409 if(pDoc->IsTabProtected(pData->GetTabNo()))
2411 pTabViewShell->ErrorMessage( STR_ERR_CONDFORMAT_PROTECTED );
2412 break;
2415 ScAddress aPos(pData->GetCurX(), pData->GetCurY(), pData->GetTabNo());
2417 ScConditionalFormatList* pList = pDoc->GetCondFormList( aPos.Tab() );
2418 boost::scoped_ptr<AbstractScCondFormatManagerDlg> pDlg(pFact->CreateScCondFormatMgrDlg(
2419 pTabViewShell->GetDialogParent(), pDoc, pList, aPos, RID_SCDLG_COND_FORMAT_MANAGER));
2420 short nRet = pDlg->Execute();
2421 if(nRet == RET_OK && pDlg->CondFormatsChanged())
2423 ScConditionalFormatList* pCondFormatList = pDlg->GetConditionalFormatList();
2424 pData->GetDocShell()->GetDocFunc().SetConditionalFormatList(pCondFormatList, aPos.Tab());
2426 else if(nRet == DLG_RET_ADD)
2428 // Put the xml string parameter to initialize the
2429 // Conditional Format Dialog. ( add new )
2430 pTabViewShell->GetPool().Put( SfxStringItem( SCITEM_STRING,
2431 ScCondFormatDlg::GenerateXmlString(
2432 sal_uInt32(-1),
2433 sal_uInt8(condformat::dialog::ScCondFormatDialogType::CONDITION),
2434 true
2435 ) ) );
2437 // Queue message to open Conditional Format Dialog
2438 GetViewData()->GetDispatcher().Execute( SID_OPENDLG_CONDFRMT, SfxCallMode::ASYNCHRON );
2440 else if (nRet == DLG_RET_EDIT)
2442 ScConditionalFormat* pFormat = pDlg->GetCondFormatSelected();
2443 // Put the xml string parameter to initialize the
2444 // Conditional Format Dialog. ( edit selected conditional format )
2445 pTabViewShell->GetPool().Put( SfxStringItem( SCITEM_STRING,
2446 ScCondFormatDlg::GenerateXmlString(
2447 pFormat ? pFormat->GetKey() : sal_uInt32(-1),
2448 sal_uInt8(condformat::dialog::ScCondFormatDialogType::CONDITION),
2449 true
2450 ) ) );
2452 // Queue message to open Conditional Format Dialog
2453 GetViewData()->GetDispatcher().Execute( SID_OPENDLG_CONDFRMT, SfxCallMode::ASYNCHRON );
2456 break;
2458 case SID_EXTERNAL_SOURCE:
2460 OUString aFile;
2461 OUString aFilter;
2462 OUString aOptions;
2463 OUString aSource;
2464 sal_uLong nRefresh=0;
2466 SFX_REQUEST_ARG( rReq, pFile, SfxStringItem, SID_FILE_NAME, false );
2467 SFX_REQUEST_ARG( rReq, pSource, SfxStringItem, FN_PARAM_1, false );
2468 if ( pFile && pSource )
2470 aFile = pFile->GetValue();
2471 aSource = pSource->GetValue();
2472 SFX_REQUEST_ARG( rReq, pFilter, SfxStringItem, SID_FILTER_NAME, false );
2473 if ( pFilter )
2474 aFilter = pFilter->GetValue();
2475 SFX_REQUEST_ARG( rReq, pOptions, SfxStringItem, SID_FILE_FILTEROPTIONS, false );
2476 if ( pOptions )
2477 aOptions = pOptions->GetValue();
2478 SFX_REQUEST_ARG( rReq, pRefresh, SfxUInt32Item, FN_PARAM_2, false );
2479 if ( pRefresh )
2480 nRefresh = pRefresh->GetValue();
2482 else
2484 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2485 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2487 delete pImpl->m_pLinkedDlg;
2488 pImpl->m_pLinkedDlg =
2489 pFact->CreateScLinkedAreaDlg(pTabViewShell->GetDialogParent());
2490 OSL_ENSURE(pImpl->m_pLinkedDlg, "Dialog create fail!");
2491 delete pImpl->m_pRequest;
2492 pImpl->m_pRequest = new SfxRequest( rReq );
2493 pImpl->m_pLinkedDlg->StartExecuteModal( LINK( this, ScCellShell, DialogClosed ) );
2494 return;
2497 ExecuteExternalSource( aFile, aFilter, aOptions, aSource, nRefresh, rReq );
2499 break;
2501 default:
2502 OSL_FAIL("incorrect slot in ExecuteEdit");
2503 break;
2507 void ScCellShell::ExecuteTrans( SfxRequest& rReq )
2509 sal_Int32 nType = ScViewUtil::GetTransliterationType( rReq.GetSlot() );
2510 if ( nType )
2512 GetViewData()->GetView()->TransliterateText( nType );
2513 rReq.Done();
2517 void ScCellShell::ExecuteRotateTrans( SfxRequest& rReq )
2519 if( rReq.GetSlot() == SID_TRANSLITERATE_ROTATE_CASE )
2520 GetViewData()->GetView()->TransliterateText( m_aRotateCase.getNextMode() );
2523 void ScCellShell::ExecuteExternalSource(
2524 const OUString& _rFile, const OUString& _rFilter, const OUString& _rOptions,
2525 const OUString& _rSource, sal_uLong _nRefresh, SfxRequest& _rRequest )
2527 if ( !_rFile.isEmpty() && !_rSource.isEmpty() ) // filter may be empty
2529 ScRange aLinkRange;
2530 bool bMove = false;
2532 ScViewData* pData = GetViewData();
2533 ScMarkData& rMark = pData->GetMarkData();
2534 rMark.MarkToSimple();
2535 if ( rMark.IsMarked() )
2537 rMark.GetMarkArea( aLinkRange );
2538 bMove = true; // insert/delete cells to fit range
2540 else
2541 aLinkRange = ScRange( pData->GetCurX(), pData->GetCurY(), pData->GetTabNo() );
2543 pData->GetDocFunc().InsertAreaLink( _rFile, _rFilter, _rOptions, _rSource,
2544 aLinkRange, _nRefresh, bMove, false );
2545 _rRequest.Done();
2547 else
2548 _rRequest.Ignore();
2551 namespace {
2553 bool isDPSourceValid(const ScDPObject& rDPObj)
2555 if (rDPObj.IsImportData())
2557 // If the data type is database, check if the database is still valid.
2558 const ScImportSourceDesc* pDesc = rDPObj.GetImportSourceDesc();
2559 if (!pDesc)
2560 return false;
2562 const ScDPSaveData* pSaveData = rDPObj.GetSaveData();
2563 const ScDPDimensionSaveData* pDimData = NULL;
2564 if (pSaveData)
2565 pDimData = pSaveData->GetExistingDimensionData();
2567 const ScDPCache* pCache = pDesc->CreateCache(pDimData);
2568 if (!pCache)
2569 // cashe creation failed, probably due to invalid connection.
2570 return false;
2572 return true;
2577 void ScCellShell::ExecuteDataPilotDialog()
2579 ScModule* pScMod = SC_MOD();
2580 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2581 ScViewData* pData = GetViewData();
2582 ScDocument* pDoc = pData->GetDocument();
2584 ::boost::scoped_ptr<ScDPObject> pNewDPObject(NULL);
2586 // ScPivot is no longer used...
2587 ScDPObject* pDPObj = pDoc->GetDPAtCursor(
2588 pData->GetCurX(), pData->GetCurY(),
2589 pData->GetTabNo() );
2590 if ( pDPObj ) // on an existing table?
2592 if (isDPSourceValid(*pDPObj))
2593 pNewDPObject.reset(new ScDPObject(*pDPObj));
2595 else // create new table
2597 sal_uLong nSrcErrorId = 0;
2599 // select database range or data
2600 pTabViewShell->GetDBData( true, SC_DB_OLD );
2601 ScMarkData& rMark = GetViewData()->GetMarkData();
2602 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
2603 pTabViewShell->MarkDataArea( false );
2605 // output to cursor position for non-sheet data
2606 ScAddress aDestPos( pData->GetCurX(), pData->GetCurY(),
2607 pData->GetTabNo() );
2609 // first select type of source data
2611 bool bEnableExt = ScDPObject::HasRegisteredSources();
2613 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2614 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2616 ::boost::scoped_ptr<AbstractScDataPilotSourceTypeDlg> pTypeDlg(
2617 pFact->CreateScDataPilotSourceTypeDlg(
2618 pTabViewShell->GetDialogParent(), bEnableExt));
2620 // Populate named ranges (if any).
2621 ScRangeName* pRangeName = pDoc->GetRangeName();
2622 if (pRangeName)
2624 ScRangeName::const_iterator itr = pRangeName->begin(), itrEnd = pRangeName->end();
2625 for (; itr != itrEnd; ++itr)
2626 pTypeDlg->AppendNamedRange(itr->second->GetName());
2629 OSL_ENSURE(pTypeDlg, "Dialog create fail!");
2630 if ( pTypeDlg->Execute() == RET_OK )
2632 if ( pTypeDlg->IsExternal() )
2634 uno::Sequence<OUString> aSources = ScDPObject::GetRegisteredSources();
2635 ::boost::scoped_ptr<AbstractScDataPilotServiceDlg> pServDlg(
2636 pFact->CreateScDataPilotServiceDlg(
2637 pTabViewShell->GetDialogParent(), aSources, RID_SCDLG_DAPISERVICE));
2639 OSL_ENSURE(pServDlg, "Dialog create fail!");
2640 if ( pServDlg->Execute() == RET_OK )
2642 ScDPServiceDesc aServDesc(
2643 pServDlg->GetServiceName(),
2644 pServDlg->GetParSource(),
2645 pServDlg->GetParName(),
2646 pServDlg->GetParUser(),
2647 pServDlg->GetParPass() );
2648 pNewDPObject.reset(new ScDPObject(pDoc));
2649 pNewDPObject->SetServiceData( aServDesc );
2652 else if ( pTypeDlg->IsDatabase() )
2654 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
2656 ::boost::scoped_ptr<AbstractScDataPilotDatabaseDlg> pDataDlg(
2657 pFact->CreateScDataPilotDatabaseDlg(
2658 pTabViewShell->GetDialogParent()));
2660 OSL_ENSURE(pDataDlg, "Dialog create fail!");
2661 if ( pDataDlg->Execute() == RET_OK )
2663 ScImportSourceDesc aImpDesc(pDoc);
2664 pDataDlg->GetValues( aImpDesc );
2665 pNewDPObject.reset(new ScDPObject(pDoc));
2666 pNewDPObject->SetImportDesc( aImpDesc );
2669 else if (pTypeDlg->IsNamedRange())
2671 OUString aName = pTypeDlg->GetSelectedNamedRange();
2672 ScSheetSourceDesc aShtDesc(pDoc);
2673 aShtDesc.SetRangeName(aName);
2674 nSrcErrorId = aShtDesc.CheckSourceRange();
2675 if (!nSrcErrorId)
2677 pNewDPObject.reset(new ScDPObject(pDoc));
2678 pNewDPObject->SetSheetDesc(aShtDesc);
2681 else // selection
2683 //! use database ranges (select before type dialog?)
2684 ScRange aRange;
2685 ScMarkType eType = GetViewData()->GetSimpleArea(aRange);
2686 if ( (eType & SC_MARK_SIMPLE) == SC_MARK_SIMPLE )
2688 // Shrink the range to the data area.
2689 SCCOL nStartCol = aRange.aStart.Col(), nEndCol = aRange.aEnd.Col();
2690 SCROW nStartRow = aRange.aStart.Row(), nEndRow = aRange.aEnd.Row();
2691 if (pDoc->ShrinkToDataArea(aRange.aStart.Tab(), nStartCol, nStartRow, nEndCol, nEndRow))
2693 aRange.aStart.SetCol(nStartCol);
2694 aRange.aStart.SetRow(nStartRow);
2695 aRange.aEnd.SetCol(nEndCol);
2696 aRange.aEnd.SetRow(nEndRow);
2697 rMark.SetMarkArea(aRange);
2698 pTabViewShell->MarkRange(aRange);
2701 bool bOK = true;
2702 if ( pDoc->HasSubTotalCells( aRange ) )
2704 // confirm selection if it contains SubTotal cells
2706 ScopedVclPtrInstance<QueryBox> aBox( pTabViewShell->GetDialogParent(),
2707 WinBits(WB_YES_NO | WB_DEF_YES),
2708 ScGlobal::GetRscString(STR_DATAPILOT_SUBTOTAL) );
2709 if (aBox->Execute() == RET_NO)
2710 bOK = false;
2712 if (bOK)
2714 ScSheetSourceDesc aShtDesc(pDoc);
2715 aShtDesc.SetSourceRange(aRange);
2716 nSrcErrorId = aShtDesc.CheckSourceRange();
2717 if (!nSrcErrorId)
2719 pNewDPObject.reset(new ScDPObject(pDoc));
2720 pNewDPObject->SetSheetDesc( aShtDesc );
2723 // output below source data
2724 if ( aRange.aEnd.Row()+2 <= MAXROW - 4 )
2725 aDestPos = ScAddress( aRange.aStart.Col(),
2726 aRange.aEnd.Row()+2,
2727 aRange.aStart.Tab() );
2733 if (nSrcErrorId)
2735 // Error occurred during data creation. Launch an error and bail out.
2736 ScopedVclPtrInstance< InfoBox > aBox(pTabViewShell->GetDialogParent(), ScGlobal::GetRscString(nSrcErrorId));
2737 aBox->Execute();
2738 return;
2741 if ( pNewDPObject )
2742 pNewDPObject->SetOutRange( aDestPos );
2745 pTabViewShell->SetDialogDPObject( pNewDPObject.get() ); // is copied
2746 if ( pNewDPObject )
2748 // start layout dialog
2750 sal_uInt16 nId = ScPivotLayoutWrapper::GetChildWindowId();
2751 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
2752 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
2753 pScMod->SetRefDialog( nId, pWnd == nullptr );
2757 void ScCellShell::ExecuteXMLSourceDialog()
2759 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2760 if (!pFact)
2761 return;
2763 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2764 if (!pTabViewShell)
2765 return;
2767 ScModule* pScMod = SC_MOD();
2769 sal_uInt16 nId = ScXMLSourceDlgWrapper::GetChildWindowId();
2770 SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame();
2771 SfxChildWindow* pWnd = pViewFrame->GetChildWindow(nId);
2772 pScMod->SetRefDialog(nId, pWnd == nullptr);
2775 void ScCellShell::ExecuteSubtotals(SfxRequest& rReq)
2777 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
2778 const SfxItemSet* pArgs = rReq.GetArgs();
2779 if ( pArgs )
2781 pTabViewShell->DoSubTotals( static_cast<const ScSubTotalItem&>( pArgs->Get( SCITEM_SUBTDATA )).
2782 GetSubTotalData() );
2783 rReq.Done();
2784 return;
2787 boost::scoped_ptr<SfxAbstractTabDialog> pDlg;
2788 ScSubTotalParam aSubTotalParam;
2789 SfxItemSet aArgSet( GetPool(), SCITEM_SUBTDATA, SCITEM_SUBTDATA );
2791 // Only get existing named database range.
2792 ScDBData* pDBData = pTabViewShell->GetDBData(true, SC_DB_OLD);
2793 if (!pDBData)
2795 // No existing DB data at this position. Create an
2796 // anonymous DB.
2797 pDBData = pTabViewShell->GetAnonymousDBData();
2798 ScRange aDataRange;
2799 pDBData->GetArea(aDataRange);
2800 pTabViewShell->MarkRange(aDataRange, false);
2803 pDBData->GetSubTotalParam( aSubTotalParam );
2804 aSubTotalParam.bRemoveOnly = false;
2806 aArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA, GetViewData(), &aSubTotalParam ) );
2807 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
2808 assert(pFact); //"ScAbstractFactory create fail
2810 pDlg.reset(pFact->CreateScSubTotalDlg(pTabViewShell->GetDialogParent(), &aArgSet));
2811 assert(pDlg); // "Dialog create fail
2812 pDlg->SetCurPageId(1);
2814 short bResult = pDlg->Execute();
2816 if ( (bResult == RET_OK) || (bResult == SCRET_REMOVE) )
2818 const SfxItemSet* pOutSet = NULL;
2820 if ( bResult == RET_OK )
2822 pOutSet = pDlg->GetOutputItemSet();
2823 aSubTotalParam =
2824 static_cast<const ScSubTotalItem&>(
2825 pOutSet->Get( SCITEM_SUBTDATA )).
2826 GetSubTotalData();
2828 else // if (bResult == SCRET_REMOVE)
2830 pOutSet = &aArgSet;
2831 aSubTotalParam.bRemoveOnly = true;
2832 aSubTotalParam.bReplace = true;
2833 aArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA,
2834 GetViewData(),
2835 &aSubTotalParam ) );
2838 pTabViewShell->DoSubTotals( aSubTotalParam );
2839 rReq.Done( *pOutSet );
2841 else
2842 GetViewData()->GetDocShell()->CancelAutoDBRange();
2845 void ScCellShell::ExecuteFillSingleEdit()
2847 ScAddress aCurPos = GetViewData()->GetCurPos();
2849 OUString aInit;
2851 if (aCurPos.Row() > 0)
2853 // Get the initial text value from the above cell.
2855 ScDocument* pDoc = GetViewData()->GetDocument();
2856 ScRefCellValue aCell;
2857 ScAddress aPrevPos = aCurPos;
2858 aPrevPos.IncRow(-1);
2859 aCell.assign(*pDoc, aPrevPos);
2861 if (aCell.meType == CELLTYPE_FORMULA)
2863 aInit = "=";
2864 const ScTokenArray* pCode = aCell.mpFormula->GetCode();
2865 sc::TokenStringContext aCxt(pDoc, pDoc->GetGrammar());
2866 aInit += pCode->CreateString(aCxt, aCurPos);
2868 else
2869 aInit = aCell.getString(pDoc);
2872 SC_MOD()->SetInputMode(SC_INPUT_TABLE, &aInit);
2875 IMPL_LINK_NOARG(ScCellShell, DialogClosed)
2877 assert(pImpl->m_pLinkedDlg && "ScCellShell::DialogClosed(): invalid request");
2878 assert(pImpl->m_pRequest && "ScCellShell::DialogClosed(): invalid request");
2879 OUString sFile, sFilter, sOptions, sSource;
2880 sal_uLong nRefresh = 0;
2882 if ( pImpl->m_pLinkedDlg->GetResult() == RET_OK )
2884 sFile = pImpl->m_pLinkedDlg->GetURL();
2885 sFilter = pImpl->m_pLinkedDlg->GetFilter();
2886 sOptions = pImpl->m_pLinkedDlg->GetOptions();
2887 sSource = pImpl->m_pLinkedDlg->GetSource();
2888 nRefresh = pImpl->m_pLinkedDlg->GetRefresh();
2889 if ( !sFile.isEmpty() )
2890 pImpl->m_pRequest->AppendItem( SfxStringItem( SID_FILE_NAME, sFile ) );
2891 if ( !sFilter.isEmpty() )
2892 pImpl->m_pRequest->AppendItem( SfxStringItem( SID_FILTER_NAME, sFilter ) );
2893 if ( !sOptions.isEmpty() )
2894 pImpl->m_pRequest->AppendItem( SfxStringItem( SID_FILE_FILTEROPTIONS, sOptions ) );
2895 if ( !sSource.isEmpty() )
2896 pImpl->m_pRequest->AppendItem( SfxStringItem( FN_PARAM_1, sSource ) );
2897 if ( nRefresh )
2898 pImpl->m_pRequest->AppendItem( SfxUInt32Item( FN_PARAM_2, nRefresh ) );
2901 ExecuteExternalSource( sFile, sFilter, sOptions, sSource, nRefresh, *(pImpl->m_pRequest) );
2902 return 0;
2905 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */