1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "scitems.hxx"
21 #include <sfx2/viewfrm.hxx>
22 #include <sfx2/app.hxx>
23 #include <sfx2/request.hxx>
24 #include <svl/aeitem.hxx>
25 #include <basic/sbxcore.hxx>
26 #include <svl/whiter.hxx>
27 #include <svl/zforlist.hxx>
28 #include <vcl/msgbox.hxx>
29 #include <svl/stritem.hxx>
30 #include <svl/visitem.hxx>
31 #include <unotools/moduleoptions.hxx>
33 #include <com/sun/star/frame/FrameSearchFlag.hpp>
34 #include <com/sun/star/sdbc/XResultSet.hpp>
37 #include "tabvwsh.hxx"
39 #include "globstr.hrc"
41 #include "globalnames.hxx"
44 #include "document.hxx"
45 #include "uiitems.hxx"
47 #include "dbdocfun.hxx"
48 #include "filtdlg.hxx"
49 #include "dbnamdlg.hxx"
50 #include "reffact.hxx"
51 #include "pvlaydlg.hxx"
52 #include "validat.hxx"
53 #include "scresid.hxx"
55 #include "validate.hrc" // ScValidationDlg
56 #include "scui_def.hxx"
57 #include "scabstdlg.hxx"
59 #include "asciiopt.hxx"
60 #include "queryentry.hxx"
61 #include "markdata.hxx"
63 using namespace com::sun::star
;
65 static bool lcl_GetTextToColumnsRange( const ScViewData
* pData
, ScRange
& rRange
)
67 OSL_ENSURE( pData
, "lcl_GetTextToColumnsRange: pData is null!" );
70 const ScMarkData
& rMark
= pData
->GetMarkData();
72 if ( rMark
.IsMarked() )
74 if ( !rMark
.IsMultiMarked() )
76 rMark
.GetMarkArea( rRange
);
77 if ( rRange
.aStart
.Col() == rRange
.aEnd
.Col() )
85 const SCCOL nCol
= pData
->GetCurX();
86 const SCROW nRow
= pData
->GetCurY();
87 const SCTAB nTab
= pData
->GetTabNo();
88 rRange
= ScRange( nCol
, nRow
, nTab
, nCol
, nRow
, nTab
);
92 const ScDocument
* pDoc
= pData
->GetDocument();
93 OSL_ENSURE( pDoc
, "lcl_GetTextToColumnsRange: pDoc is null!" );
95 if ( bRet
&& pDoc
->IsBlockEmpty( rRange
.aStart
.Tab(), rRange
.aStart
.Col(),
96 rRange
.aStart
.Row(), rRange
.aEnd
.Col(),
105 static sal_Bool
lcl_GetSortParam( const ScViewData
* pData
, ScSortParam
& rSortParam
)
107 ScTabViewShell
* pTabViewShell
= pData
->GetViewShell();
108 ScDBData
* pDBData
= pTabViewShell
->GetDBData();
109 ScDocument
* pDoc
= pData
->GetDocument();
110 SCTAB nTab
= pData
->GetTabNo();
111 ScDirection eFillDir
= DIR_TOP
;
112 sal_Bool bSort
= sal_True
;
113 ScRange aExternalRange
;
115 if( rSortParam
.nCol1
!= rSortParam
.nCol2
)
117 if( rSortParam
.nRow1
!= rSortParam
.nRow2
)
120 SCSIZE nCount
= pDoc
->GetEmptyLinesInBlock( rSortParam
.nCol1
, rSortParam
.nRow1
, nTab
, rSortParam
.nCol2
, rSortParam
.nRow2
, nTab
, eFillDir
);
122 if( rSortParam
.nRow2
== MAXROW
)
123 aExternalRange
= ScRange( rSortParam
.nCol1
,sal::static_int_cast
<SCROW
>( nCount
), nTab
);
125 aExternalRange
= ScRange( pData
->GetCurX(), pData
->GetCurY(), nTab
);
127 SCROW nStartRow
= aExternalRange
.aStart
.Row();
128 SCCOL nStartCol
= aExternalRange
.aStart
.Col();
129 SCROW nEndRow
= aExternalRange
.aEnd
.Row();
130 SCCOL nEndCol
= aExternalRange
.aEnd
.Col();
131 pDoc
->GetDataArea( aExternalRange
.aStart
.Tab(), nStartCol
, nStartRow
, nEndCol
, nEndRow
, false, false );
132 aExternalRange
.aStart
.SetRow( nStartRow
);
133 aExternalRange
.aStart
.SetCol( nStartCol
);
134 aExternalRange
.aEnd
.SetRow( nEndRow
);
135 aExternalRange
.aEnd
.SetCol( nEndCol
);
137 if(( rSortParam
.nCol1
== rSortParam
.nCol2
&& aExternalRange
.aStart
.Col() != aExternalRange
.aEnd
.Col() ) ||
138 ( rSortParam
.nRow1
== rSortParam
.nRow2
&& aExternalRange
.aStart
.Row() != aExternalRange
.aEnd
.Row() ) )
140 sal_uInt16 nFmt
= SCA_VALID
;
141 String aExtendStr
,aCurrentStr
;
143 pTabViewShell
->AddHighlightRange( aExternalRange
,Color( COL_LIGHTBLUE
) );
144 ScRange
rExtendRange( aExternalRange
.aStart
.Col(), aExternalRange
.aStart
.Row(), nTab
, aExternalRange
.aEnd
.Col(), aExternalRange
.aEnd
.Row(), nTab
);
145 rExtendRange
.Format( aExtendStr
, nFmt
, pDoc
);
147 ScRange
rCurrentRange( rSortParam
.nCol1
, rSortParam
.nRow1
, nTab
, rSortParam
.nCol2
, rSortParam
.nRow2
, nTab
);
148 rCurrentRange
.Format( aCurrentStr
, nFmt
, pDoc
);
150 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
151 OSL_ENSURE(pFact
, "ScAbstractFactory create fail!");
153 VclAbstractDialog
* pWarningDlg
= pFact
->CreateScSortWarningDlg( pTabViewShell
->GetDialogParent(),aExtendStr
,aCurrentStr
,RID_SCDLG_SORT_WARNING
);
154 OSL_ENSURE(pWarningDlg
, "Dialog create fail!");
155 short bResult
= pWarningDlg
->Execute();
156 if( bResult
== BTN_EXTEND_RANGE
|| bResult
== BTN_CURRENT_SELECTION
)
158 if( bResult
== BTN_EXTEND_RANGE
)
160 pTabViewShell
->MarkRange( aExternalRange
, false );
161 pDBData
->SetArea( nTab
, aExternalRange
.aStart
.Col(), aExternalRange
.aStart
.Row(), aExternalRange
.aEnd
.Col(), aExternalRange
.aEnd
.Row() );
167 pData
->GetDocShell()->CancelAutoDBRange();
171 pTabViewShell
->ClearHighlightRanges();
176 //after end execute from !IsModalInputMode, it is safer to delay deleting
179 long DelayDeleteAbstractDialog( void *pAbstractDialog
, void * /*pArg*/ )
181 delete reinterpret_cast<VclAbstractDialog
*>( pAbstractDialog
);
186 void ScCellShell::ExecuteDB( SfxRequest
& rReq
)
188 ScTabViewShell
* pTabViewShell
= GetViewData()->GetViewShell();
189 sal_uInt16 nSlotId
= rReq
.GetSlot();
190 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
191 ScModule
* pScMod
= SC_MOD();
193 pTabViewShell
->HideListBox(); // Autofilter-DropDown-Listbox
195 if ( GetViewData()->HasEditView( GetViewData()->GetActivePart() ) )
197 pScMod
->InputEnterHandler();
198 pTabViewShell
->UpdateInputHandler();
203 case SID_VIEW_DATA_SOURCE_BROWSER
:
205 // check if database beamer is open
207 SfxViewFrame
* pViewFrame
= pTabViewShell
->GetViewFrame();
208 sal_Bool bWasOpen
= false;
210 uno::Reference
<frame::XFrame
> xFrame
= pViewFrame
->GetFrame().GetFrameInterface();
211 uno::Reference
<frame::XFrame
> xBeamerFrame
= xFrame
->findFrame(
212 rtl::OUString("_beamer"),
213 frame::FrameSearchFlag::CHILDREN
);
214 if ( xBeamerFrame
.is() )
220 // close database beamer: just forward to SfxViewFrame
222 pViewFrame
->ExecuteSlot( rReq
);
226 // show database beamer: SfxViewFrame call must be synchronous
228 pViewFrame
->ExecuteSlot( rReq
, (sal_Bool
) false ); // sal_False = synchronous
230 // select current database in database beamer
232 ScImportParam aImportParam
;
233 ScDBData
* pDBData
= pTabViewShell
->GetDBData(sal_True
,SC_DB_OLD
); // don't create if none found
235 pDBData
->GetImportParam( aImportParam
);
237 ScDBDocFunc::ShowInBeamer( aImportParam
, pTabViewShell
->GetViewFrame() );
239 rReq
.Done(); // needed because it's a toggle slot
243 case SID_REIMPORT_DATA
:
245 sal_Bool bOk
= false;
246 ScDBData
* pDBData
= pTabViewShell
->GetDBData(sal_True
,SC_DB_OLD
);
249 ScImportParam aImportParam
;
250 pDBData
->GetImportParam( aImportParam
);
251 if (aImportParam
.bImport
&& !pDBData
->HasImportSelection())
253 pTabViewShell
->ImportData( aImportParam
);
254 pDBData
->SetImportParam( aImportParam
); //! Undo ??
259 if (!bOk
&& ! rReq
.IsAPI() )
260 pTabViewShell
->ErrorMessage(STR_REIMPORT_EMPTY
);
267 case SID_REFRESH_DBAREA
:
269 ScDBData
* pDBData
= pTabViewShell
->GetDBData(sal_True
,SC_DB_OLD
);
272 // repeat import like SID_REIMPORT_DATA
274 sal_Bool bContinue
= sal_True
;
275 ScImportParam aImportParam
;
276 pDBData
->GetImportParam( aImportParam
);
277 if (aImportParam
.bImport
&& !pDBData
->HasImportSelection())
279 bContinue
= pTabViewShell
->ImportData( aImportParam
);
280 pDBData
->SetImportParam( aImportParam
); //! Undo ??
282 // mark (size may have been changed)
284 pDBData
->GetArea(aNewRange
);
285 pTabViewShell
->MarkRange(aNewRange
);
288 if ( bContinue
) // fail at import -> break
290 // internal operations, when any stored
292 if ( pDBData
->HasQueryParam() || pDBData
->HasSortParam() ||
293 pDBData
->HasSubTotalParam() )
294 pTabViewShell
->RepeatDB();
296 // pivot tables that have the range as data source
299 pDBData
->GetArea(aRange
);
300 GetViewData()->GetDocShell()->RefreshPivotTables(aRange
);
307 case SID_SBA_BRW_INSERT
:
309 OSL_FAIL( "Deprecated Slot" );
315 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
316 OSL_ENSURE(pFact
, "ScAbstractFactory create fail!");
318 AbstractScDataFormDlg
* pDlg
= pFact
->CreateScDataFormDlg( pTabViewShell
->GetDialogParent(),RID_SCDLG_DATAFORM
, pTabViewShell
);
319 OSL_ENSURE(pDlg
, "Dialog create fail!");
328 ExecuteSubtotals(rReq
);
331 case SID_SORT_DESCENDING
:
332 case SID_SORT_ASCENDING
:
334 //#i60401 ux-ctest: Calc does not support all users' strategies regarding sorting data
335 //the patch comes from maoyg
336 ScSortParam aSortParam
;
337 ScDBData
* pDBData
= pTabViewShell
->GetDBData();
338 ScViewData
* pData
= GetViewData();
340 pDBData
->GetSortParam( aSortParam
);
342 if( lcl_GetSortParam( pData
, aSortParam
) )
344 SfxItemSet
aArgSet( GetPool(), SCITEM_SORTDATA
, SCITEM_SORTDATA
);
345 SCCOL nCol
= GetViewData()->GetCurX();
346 SCCOL nTab
= GetViewData()->GetTabNo();
347 ScDocument
* pDoc
= GetViewData()->GetDocument();
349 pDBData
->GetSortParam( aSortParam
);
350 sal_Bool bHasHeader
= pDoc
->HasColHeader( aSortParam
.nCol1
, aSortParam
.nRow1
, aSortParam
.nCol2
, aSortParam
.nRow2
, nTab
);
352 if( nCol
< aSortParam
.nCol1
)
353 nCol
= aSortParam
.nCol1
;
354 else if( nCol
> aSortParam
.nCol2
)
355 nCol
= aSortParam
.nCol2
;
357 aSortParam
.bHasHeader
= bHasHeader
;
358 aSortParam
.bByRow
= true;
359 aSortParam
.bCaseSens
= false;
360 aSortParam
.bNaturalSort
= false;
361 aSortParam
.bIncludePattern
= true;
362 aSortParam
.bInplace
= true;
363 aSortParam
.maKeyState
[0].bDoSort
= true;
364 aSortParam
.maKeyState
[0].nField
= nCol
;
365 aSortParam
.maKeyState
[0].bAscending
= ( nSlotId
== SID_SORT_ASCENDING
);
367 for ( sal_uInt16 i
=1; i
<aSortParam
.GetSortKeyCount(); i
++ )
368 aSortParam
.maKeyState
[i
].bDoSort
= false;
370 aArgSet
.Put( ScSortItem( SCITEM_SORTDATA
, GetViewData(), &aSortParam
) );
372 pTabViewShell
->UISort( aSortParam
); // subtotal when needed new
381 const SfxItemSet
* pArgs
= rReq
.GetArgs();
383 //#i60401 ux-ctest: Calc does not support all users' strategies regarding sorting data
384 //the patch comes from maoyg
386 if ( pArgs
) // Basic
388 ScSortParam aSortParam
;
389 ScDBData
* pDBData
= pTabViewShell
->GetDBData();
390 ScViewData
* pData
= GetViewData();
392 pDBData
->GetSortParam( aSortParam
);
394 if( lcl_GetSortParam( pData
, aSortParam
) )
396 ScDocument
* pDoc
= GetViewData()->GetDocument();
398 pDBData
->GetSortParam( aSortParam
);
399 sal_Bool bHasHeader
= pDoc
->HasColHeader( aSortParam
.nCol1
, aSortParam
.nRow1
, aSortParam
.nCol2
, aSortParam
.nRow2
, pData
->GetTabNo() );
401 aSortParam
.bHasHeader
= bHasHeader
;
403 aSortParam
.bInplace
= sal_True
; // from Basic always
405 const SfxPoolItem
* pItem
;
406 if ( pArgs
->GetItemState( SID_SORT_BYROW
, sal_True
, &pItem
) == SFX_ITEM_SET
)
407 aSortParam
.bByRow
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
408 if ( pArgs
->GetItemState( SID_SORT_HASHEADER
, sal_True
, &pItem
) == SFX_ITEM_SET
)
409 aSortParam
.bHasHeader
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
410 if ( pArgs
->GetItemState( SID_SORT_CASESENS
, sal_True
, &pItem
) == SFX_ITEM_SET
)
411 aSortParam
.bCaseSens
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
412 if ( pArgs
->GetItemState( SID_SORT_NATURALSORT
, true, &pItem
) == SFX_ITEM_SET
)
413 aSortParam
.bNaturalSort
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
414 if ( pArgs
->GetItemState( SID_SORT_ATTRIBS
, true, &pItem
) == SFX_ITEM_SET
)
415 aSortParam
.bIncludePattern
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
416 if ( pArgs
->GetItemState( SID_SORT_USERDEF
, sal_True
, &pItem
) == SFX_ITEM_SET
)
418 sal_uInt16 nUserIndex
= static_cast<const SfxUInt16Item
*>(pItem
)->GetValue();
419 aSortParam
.bUserDef
= ( nUserIndex
!= 0 );
421 aSortParam
.nUserIndex
= nUserIndex
- 1; // Basic: 1-based
424 SCCOLROW nField0
= 0;
425 if ( pArgs
->GetItemState( FN_PARAM_1
, sal_True
, &pItem
) == SFX_ITEM_SET
)
426 nField0
= static_cast<const SfxInt32Item
*>(pItem
)->GetValue();
427 aSortParam
.maKeyState
[0].bDoSort
= ( nField0
!= 0 );
428 aSortParam
.maKeyState
[0].nField
= nField0
> 0 ? (nField0
-1) : 0;
429 if ( pArgs
->GetItemState( FN_PARAM_2
, sal_True
, &pItem
) == SFX_ITEM_SET
)
430 aSortParam
.maKeyState
[0].bAscending
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
431 SCCOLROW nField1
= 0;
432 if ( pArgs
->GetItemState( FN_PARAM_3
, sal_True
, &pItem
) == SFX_ITEM_SET
)
433 nField1
= static_cast<const SfxInt32Item
*>(pItem
)->GetValue();
434 aSortParam
.maKeyState
[1].bDoSort
= ( nField1
!= 0 );
435 aSortParam
.maKeyState
[1].nField
= nField1
> 0 ? (nField1
-1) : 0;
436 if ( pArgs
->GetItemState( FN_PARAM_4
, sal_True
, &pItem
) == SFX_ITEM_SET
)
437 aSortParam
.maKeyState
[1].bAscending
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
438 SCCOLROW nField2
= 0;
439 if ( pArgs
->GetItemState( FN_PARAM_5
, sal_True
, &pItem
) == SFX_ITEM_SET
)
440 nField2
= static_cast<const SfxInt32Item
*>(pItem
)->GetValue();
441 aSortParam
.maKeyState
[2].bDoSort
= ( nField2
!= 0 );
442 aSortParam
.maKeyState
[2].nField
= nField2
> 0 ? (nField2
-1) : 0;
443 if ( pArgs
->GetItemState( FN_PARAM_6
, sal_True
, &pItem
) == SFX_ITEM_SET
)
444 aSortParam
.maKeyState
[2].bAscending
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
446 // subtotal when needed new
447 pTabViewShell
->UISort( aSortParam
);
453 ScSortParam aSortParam
;
454 ScDBData
* pDBData
= pTabViewShell
->GetDBData();
455 ScViewData
* pData
= GetViewData();
457 pDBData
->GetSortParam( aSortParam
);
459 if( lcl_GetSortParam( pData
, aSortParam
) )
461 SfxAbstractTabDialog
* pDlg
= NULL
;
462 ScDocument
* pDoc
= GetViewData()->GetDocument();
463 SfxItemSet
aArgSet( GetPool(), SCITEM_SORTDATA
, SCITEM_SORTDATA
);
465 pDBData
->GetSortParam( aSortParam
);
466 sal_Bool bHasHeader
= pDoc
->HasColHeader( aSortParam
.nCol1
, aSortParam
.nRow1
, aSortParam
.nCol2
, aSortParam
.nRow2
, pData
->GetTabNo() );
468 aSortParam
.bHasHeader
= bHasHeader
;
470 aArgSet
.Put( ScSortItem( SCITEM_SORTDATA
, GetViewData(), &aSortParam
) );
472 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
473 OSL_ENSURE(pFact
, "ScAbstractFactory create fail!");
475 pDlg
= pFact
->CreateScSortDlg( pTabViewShell
->GetDialogParent(), &aArgSet
, RID_SCDLG_SORT
);
476 OSL_ENSURE(pDlg
, "Dialog create fail!");
477 pDlg
->SetCurPageId(1); // 1=sort field tab 2=sort options tab
479 if ( pDlg
->Execute() == RET_OK
)
481 const SfxItemSet
* pOutSet
= pDlg
->GetOutputItemSet();
482 const ScSortParam
& rOutParam
= ((const ScSortItem
&)
483 pOutSet
->Get( SCITEM_SORTDATA
)).GetSortData();
485 // subtotal when needed new
487 pTabViewShell
->UISort( rOutParam
);
489 if ( rOutParam
.bInplace
)
491 rReq
.AppendItem( SfxBoolItem( SID_SORT_BYROW
,
492 rOutParam
.bByRow
) );
493 rReq
.AppendItem( SfxBoolItem( SID_SORT_HASHEADER
,
494 rOutParam
.bHasHeader
) );
495 rReq
.AppendItem( SfxBoolItem( SID_SORT_CASESENS
,
496 rOutParam
.bCaseSens
) );
497 rReq
.AppendItem( SfxBoolItem( SID_SORT_NATURALSORT
,
498 rOutParam
.bNaturalSort
) );
499 rReq
.AppendItem( SfxBoolItem( SID_SORT_ATTRIBS
,
500 rOutParam
.bIncludePattern
) );
501 sal_uInt16 nUser
= rOutParam
.bUserDef
? ( rOutParam
.nUserIndex
+ 1 ) : 0;
502 rReq
.AppendItem( SfxUInt16Item( SID_SORT_USERDEF
, nUser
) );
503 if ( rOutParam
.maKeyState
[0].bDoSort
)
505 rReq
.AppendItem( SfxInt32Item( FN_PARAM_1
,
506 rOutParam
.maKeyState
[0].nField
+ 1 ) );
507 rReq
.AppendItem( SfxBoolItem( FN_PARAM_2
,
508 rOutParam
.maKeyState
[0].bAscending
) );
510 if ( rOutParam
.maKeyState
[1].bDoSort
)
512 rReq
.AppendItem( SfxInt32Item( FN_PARAM_3
,
513 rOutParam
.maKeyState
[1].nField
+ 1 ) );
514 rReq
.AppendItem( SfxBoolItem( FN_PARAM_4
,
515 rOutParam
.maKeyState
[1].bAscending
) );
517 if ( rOutParam
.maKeyState
[2].bDoSort
)
519 rReq
.AppendItem( SfxInt32Item( FN_PARAM_5
,
520 rOutParam
.maKeyState
[2].nField
+ 1 ) );
521 rReq
.AppendItem( SfxBoolItem( FN_PARAM_6
,
522 rOutParam
.maKeyState
[2].bAscending
) );
529 GetViewData()->GetDocShell()->CancelAutoDBRange();
539 const SfxItemSet
* pArgs
= rReq
.GetArgs();
542 OSL_FAIL("SID_FILTER with arguments?");
543 pTabViewShell
->Query( ((const ScQueryItem
&)
544 pArgs
->Get( SCITEM_QUERYDATA
)).GetQueryData(), NULL
, sal_True
);
549 sal_uInt16 nId
= ScFilterDlgWrapper::GetChildWindowId();
550 SfxViewFrame
* pViewFrm
= pTabViewShell
->GetViewFrame();
551 SfxChildWindow
* pWnd
= pViewFrm
->GetChildWindow( nId
);
553 pScMod
->SetRefDialog( nId
, pWnd
? false : sal_True
);
558 case SID_SPECIAL_FILTER
:
560 const SfxItemSet
* pArgs
= rReq
.GetArgs();
563 OSL_FAIL("SID_SPECIAL_FILTER with arguments?");
564 pTabViewShell
->Query( ((const ScQueryItem
&)
565 pArgs
->Get( SCITEM_QUERYDATA
)).GetQueryData(), NULL
, sal_True
);
570 sal_uInt16 nId
= ScSpecialFilterDlgWrapper::GetChildWindowId();
571 SfxViewFrame
* pViewFrm
= pTabViewShell
->GetViewFrame();
572 SfxChildWindow
* pWnd
= pViewFrm
->GetChildWindow( nId
);
574 pScMod
->SetRefDialog( nId
, pWnd
? false : sal_True
);
581 const SfxPoolItem
* pItem
;
582 if ( pReqArgs
&& SFX_ITEM_SET
==
583 pReqArgs
->GetItemState( SCITEM_QUERYDATA
, sal_True
, &pItem
) )
585 const ScQueryItem
& rQueryItem
= static_cast<const ScQueryItem
&>(*pItem
);
587 SCTAB nCurTab
= GetViewData()->GetTabNo();
588 SCTAB nRefTab
= GetViewData()->GetRefTabNo();
590 // If RefInput switched to a different sheet from the data sheet,
593 if ( nCurTab
!= nRefTab
)
595 pTabViewShell
->SetTabNo( nRefTab
);
596 pTabViewShell
->PaintExtras();
600 if (rQueryItem
.GetAdvancedQuerySource(aAdvSource
))
601 pTabViewShell
->Query( rQueryItem
.GetQueryData(), &aAdvSource
, sal_True
);
603 pTabViewShell
->Query( rQueryItem
.GetQueryData(), NULL
, sal_True
);
604 rReq
.Done( *pReqArgs
);
612 ScDBData
* pDBData
= pTabViewShell
->GetDBData();
614 pDBData
->GetQueryParam( aParam
);
615 SCSIZE nEC
= aParam
.GetEntryCount();
616 for (SCSIZE i
=0; i
<nEC
; i
++)
617 aParam
.GetEntry(i
).bDoQuery
= false;
618 aParam
.bDuplicate
= sal_True
;
619 pTabViewShell
->Query( aParam
, NULL
, sal_True
);
624 case SID_AUTO_FILTER
:
625 pTabViewShell
->ToggleAutoFilter();
629 case SID_AUTOFILTER_HIDE
:
630 pTabViewShell
->HideAutoFilter();
634 case SID_PIVOT_TABLE
:
636 const SfxPoolItem
* pItem
;
637 if ( pReqArgs
&& SFX_ITEM_SET
==
638 pReqArgs
->GetItemState( SCITEM_PIVOTDATA
, sal_True
, &pItem
) )
640 SCTAB nCurTab
= GetViewData()->GetTabNo();
641 SCTAB nRefTab
= GetViewData()->GetRefTabNo();
643 // If RefInput switched to a different sheet from the data sheet,
646 if ( nCurTab
!= nRefTab
)
648 pTabViewShell
->SetTabNo( nRefTab
);
649 pTabViewShell
->PaintExtras();
652 const ScDPObject
* pDPObject
= pTabViewShell
->GetDialogDPObject();
655 const ScPivotItem
* pPItem
= (const ScPivotItem
*)pItem
;
656 bool bSuccess
= pTabViewShell
->MakePivotTable(
657 pPItem
->GetData(), pPItem
->GetDestRange(), pPItem
->IsNewSheet(), *pDPObject
);
658 SfxBoolItem
aRet(0, bSuccess
);
659 rReq
.SetReturnValue(aRet
);
663 #ifndef DISABLE_SCRIPTING
664 else if (rReq
.IsAPI())
665 SbxBase::SetError(SbxERR_BAD_PARAMETER
);
670 case SID_OPENDLG_PIVOTTABLE
:
671 ExecuteDataPilotDialog();
673 case SID_DEFINE_DBNAME
:
676 sal_uInt16 nId
= ScDbNameDlgWrapper::GetChildWindowId();
677 SfxViewFrame
* pViewFrm
= pTabViewShell
->GetViewFrame();
678 SfxChildWindow
* pWnd
= pViewFrm
->GetChildWindow( nId
);
680 pScMod
->SetRefDialog( nId
, pWnd
? false : sal_True
);
689 const SfxStringItem
* pItem
=
690 (const SfxStringItem
*)&pReqArgs
->Get( SID_SELECT_DB
);
694 pTabViewShell
->GotoDBArea( pItem
->GetValue() );
704 ScDocument
* pDoc
= GetViewData()->GetDocument();
705 ScDBCollection
* pDBCol
= pDoc
->GetDBCollection();
709 std::vector
<String
> aList
;
710 const ScDBCollection::NamedDBs
& rDBs
= pDBCol
->getNamedDBs();
711 ScDBCollection::NamedDBs::const_iterator itr
= rDBs
.begin(), itrEnd
= rDBs
.end();
712 for (; itr
!= itrEnd
; ++itr
)
713 aList
.push_back(itr
->GetName());
715 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
716 OSL_ENSURE(pFact
, "ScAbstractFactory create fail!");
718 AbstractScSelEntryDlg
* pDlg
= pFact
->CreateScSelEntryDlg( pTabViewShell
->GetDialogParent(),
720 String(ScResId(SCSTR_SELECTDB
)),
721 String(ScResId(SCSTR_AREAS
)),
724 OSL_ENSURE(pDlg
, "Dialog create fail!");
725 if ( pDlg
->Execute() == RET_OK
)
727 String aName
= pDlg
->GetSelectEntry();
728 pTabViewShell
->GotoDBArea( aName
);
729 rReq
.AppendItem( SfxStringItem( SID_SELECT_DB
, aName
) );
739 case SID_MANAGE_XML_SOURCE
:
740 ExecuteXMLSourceDialog();
744 const SfxPoolItem
* pItem
;
745 const SfxItemSet
* pArgs
= rReq
.GetArgs();
748 OSL_FAIL("later...");
752 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
753 OSL_ENSURE(pFact
, "ScAbstractFactory create fail!");
754 ::GetTabPageRanges ScTPValidationValueGetRanges
= pFact
->GetTabPageRangesFunc(TP_VALIDATION_VALUES
);
755 OSL_ENSURE(ScTPValidationValueGetRanges
, "TabPage create fail!");
756 SfxItemSet
aArgSet( GetPool(), (*ScTPValidationValueGetRanges
)() );
757 ScValidationMode eMode
= SC_VALID_ANY
;
758 ScConditionMode eOper
= SC_COND_EQUAL
;
759 String aExpr1
, aExpr2
;
760 sal_Bool bBlank
= sal_True
;
761 sal_Int16 nListType
= ValidListType::UNSORTED
;
762 sal_Bool bShowHelp
= false;
763 String aHelpTitle
, aHelpText
;
764 sal_Bool bShowError
= false;
765 ScValidErrorStyle eErrStyle
= SC_VALERR_STOP
;
766 String aErrTitle
, aErrText
;
768 ScDocument
* pDoc
= GetViewData()->GetDocument();
769 SCCOL nCurX
= GetViewData()->GetCurX();
770 SCROW nCurY
= GetViewData()->GetCurY();
771 SCTAB nTab
= GetViewData()->GetTabNo();
772 ScAddress
aCursorPos( nCurX
, nCurY
, nTab
);
773 sal_uLong nIndex
= ((SfxUInt32Item
*)pDoc
->GetAttr(
774 nCurX
, nCurY
, nTab
, ATTR_VALIDDATA
))->GetValue();
777 const ScValidationData
* pOldData
= pDoc
->GetValidationEntry( nIndex
);
780 eMode
= pOldData
->GetDataMode();
781 eOper
= pOldData
->GetOperation();
782 sal_uLong nNumFmt
= 0;
783 if ( eMode
== SC_VALID_DATE
|| eMode
== SC_VALID_TIME
)
785 short nType
= ( eMode
== SC_VALID_DATE
) ? NUMBERFORMAT_DATE
787 nNumFmt
= pDoc
->GetFormatTable()->GetStandardFormat(
788 nType
, ScGlobal::eLnge
);
790 aExpr1
= pOldData
->GetExpression( aCursorPos
, 0, nNumFmt
);
791 aExpr2
= pOldData
->GetExpression( aCursorPos
, 1, nNumFmt
);
792 bBlank
= pOldData
->IsIgnoreBlank();
793 nListType
= pOldData
->GetListType();
795 bShowHelp
= pOldData
->GetInput( aHelpTitle
, aHelpText
);
796 bShowError
= pOldData
->GetErrMsg( aErrTitle
, aErrText
, eErrStyle
);
798 aArgSet
.Put( SfxAllEnumItem( FID_VALID_MODE
, sal::static_int_cast
<sal_uInt16
>(eMode
) ) );
799 aArgSet
.Put( SfxAllEnumItem( FID_VALID_CONDMODE
, sal::static_int_cast
<sal_uInt16
>(eOper
) ) );
800 aArgSet
.Put( SfxStringItem( FID_VALID_VALUE1
, aExpr1
) );
801 aArgSet
.Put( SfxStringItem( FID_VALID_VALUE2
, aExpr2
) );
802 aArgSet
.Put( SfxBoolItem( FID_VALID_BLANK
, bBlank
) );
803 aArgSet
.Put( SfxInt16Item( FID_VALID_LISTTYPE
, nListType
) );
804 aArgSet
.Put( SfxBoolItem( FID_VALID_SHOWHELP
, bShowHelp
) );
805 aArgSet
.Put( SfxStringItem( FID_VALID_HELPTITLE
, aHelpTitle
) );
806 aArgSet
.Put( SfxStringItem( FID_VALID_HELPTEXT
, aHelpText
) );
807 aArgSet
.Put( SfxBoolItem( FID_VALID_SHOWERR
, bShowError
) );
808 aArgSet
.Put( SfxAllEnumItem( FID_VALID_ERRSTYLE
, sal::static_int_cast
<sal_uInt16
>(eErrStyle
) ) );
809 aArgSet
.Put( SfxStringItem( FID_VALID_ERRTITLE
, aErrTitle
) );
810 aArgSet
.Put( SfxStringItem( FID_VALID_ERRTEXT
, aErrText
) );
815 SfxAbstractTabDialog
* pDlg
= pFact
->CreateScValidationDlg( NULL
, &aArgSet
, TAB_DLG_VALIDATION
, pTabViewShell
);
816 OSL_ENSURE(pDlg
, "Dialog create fail!");
818 short nResult
= pDlg
->Execute();
819 //When picking Cell Range, other Tab may be switched. Need restore the correct tab
820 pTabViewShell
->SetTabNo( nTab
);
821 if ( nResult
== RET_OK
)
823 const SfxItemSet
* pOutSet
= pDlg
->GetOutputItemSet();
825 if ( pOutSet
->GetItemState( FID_VALID_MODE
, sal_True
, &pItem
) == SFX_ITEM_SET
)
826 eMode
= (ScValidationMode
) ((const SfxAllEnumItem
*)pItem
)->GetValue();
827 if ( pOutSet
->GetItemState( FID_VALID_CONDMODE
, sal_True
, &pItem
) == SFX_ITEM_SET
)
828 eOper
= (ScConditionMode
) ((const SfxAllEnumItem
*)pItem
)->GetValue();
829 if ( pOutSet
->GetItemState( FID_VALID_VALUE1
, sal_True
, &pItem
) == SFX_ITEM_SET
)
831 String aTemp1
= ((const SfxStringItem
*)pItem
)->GetValue();
832 if (eMode
== SC_VALID_DATE
|| eMode
== SC_VALID_TIME
)
834 sal_uInt32 nNumIndex
= 0;
836 if (pDoc
->GetFormatTable()->IsNumberFormat(aTemp1
, nNumIndex
, nVal
))
837 aExpr1
=String( ::rtl::math::doubleToUString( nVal
,
838 rtl_math_StringFormat_Automatic
, rtl_math_DecimalPlaces_Max
,
839 ScGlobal::pLocaleData
->getNumDecimalSep()[0], sal_True
));
846 if ( pOutSet
->GetItemState( FID_VALID_VALUE2
, sal_True
, &pItem
) == SFX_ITEM_SET
)
848 String aTemp2
= ((const SfxStringItem
*)pItem
)->GetValue();
849 if (eMode
== SC_VALID_DATE
|| eMode
== SC_VALID_TIME
)
851 sal_uInt32 nNumIndex
= 0;
853 if (pDoc
->GetFormatTable()->IsNumberFormat(aTemp2
, nNumIndex
, nVal
))
854 aExpr2
=String( ::rtl::math::doubleToUString( nVal
,
855 rtl_math_StringFormat_Automatic
, rtl_math_DecimalPlaces_Max
,
856 ScGlobal::pLocaleData
->getNumDecimalSep()[0], sal_True
));
864 if ( pOutSet
->GetItemState( FID_VALID_BLANK
, sal_True
, &pItem
) == SFX_ITEM_SET
)
865 bBlank
= ((const SfxBoolItem
*)pItem
)->GetValue();
866 if ( pOutSet
->GetItemState( FID_VALID_LISTTYPE
, sal_True
, &pItem
) == SFX_ITEM_SET
)
867 nListType
= ((const SfxInt16Item
*)pItem
)->GetValue();
869 if ( pOutSet
->GetItemState( FID_VALID_SHOWHELP
, sal_True
, &pItem
) == SFX_ITEM_SET
)
870 bShowHelp
= ((const SfxBoolItem
*)pItem
)->GetValue();
871 if ( pOutSet
->GetItemState( FID_VALID_HELPTITLE
, sal_True
, &pItem
) == SFX_ITEM_SET
)
872 aHelpTitle
= ((const SfxStringItem
*)pItem
)->GetValue();
873 if ( pOutSet
->GetItemState( FID_VALID_HELPTEXT
, sal_True
, &pItem
) == SFX_ITEM_SET
)
874 aHelpText
= ((const SfxStringItem
*)pItem
)->GetValue();
876 if ( pOutSet
->GetItemState( FID_VALID_SHOWERR
, sal_True
, &pItem
) == SFX_ITEM_SET
)
877 bShowError
= ((const SfxBoolItem
*)pItem
)->GetValue();
878 if ( pOutSet
->GetItemState( FID_VALID_ERRSTYLE
, sal_True
, &pItem
) == SFX_ITEM_SET
)
879 eErrStyle
= (ScValidErrorStyle
) ((const SfxAllEnumItem
*)pItem
)->GetValue();
880 if ( pOutSet
->GetItemState( FID_VALID_ERRTITLE
, sal_True
, &pItem
) == SFX_ITEM_SET
)
881 aErrTitle
= ((const SfxStringItem
*)pItem
)->GetValue();
882 if ( pOutSet
->GetItemState( FID_VALID_ERRTEXT
, sal_True
, &pItem
) == SFX_ITEM_SET
)
883 aErrText
= ((const SfxStringItem
*)pItem
)->GetValue();
885 ScValidationData
aData( eMode
, eOper
, aExpr1
, aExpr2
, pDoc
, aCursorPos
);
886 aData
.SetIgnoreBlank( bBlank
);
887 aData
.SetListType( nListType
);
889 aData
.SetInput(aHelpTitle
, aHelpText
); // sets bShowInput to TRUE
891 aData
.ResetInput(); // reset only bShowInput
893 aData
.SetError(aErrTitle
, aErrText
, eErrStyle
); // sets bShowError to TRUE
895 aData
.ResetError(); // reset only bShowError
897 pTabViewShell
->SetValidation( aData
);
898 pTabViewShell
->TestHintWindow();
899 rReq
.Done( *pOutSet
);
901 //after end execute from !IsModalInputMode, it is safer to delay deleting
903 Application::PostUserEvent( Link( pDlg
, &DelayDeleteAbstractDialog
) );
908 case SID_TEXT_TO_COLUMNS
:
910 ScViewData
* pData
= GetViewData();
911 OSL_ENSURE( pData
, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pData is null!" );
914 if ( lcl_GetTextToColumnsRange( pData
, aRange
) )
916 ScDocument
* pDoc
= pData
->GetDocument();
917 OSL_ENSURE( pDoc
, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDoc is null!" );
919 ScImportExport
aExport( pDoc
, aRange
);
920 aExport
.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::None
, 0, false ) );
922 // #i87703# text to columns fails with tab separator
923 aExport
.SetDelimiter( static_cast< sal_Unicode
>( 0 ) );
925 SvMemoryStream aStream
;
926 aStream
.SetStreamCharSet( RTL_TEXTENCODING_UNICODE
);
927 ScImportExport::SetNoEndianSwap( aStream
);
928 aExport
.ExportStream( aStream
, String(), FORMAT_STRING
);
930 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
931 OSL_ENSURE( pFact
, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pFact is null!" );
932 AbstractScImportAsciiDlg
*pDlg
= pFact
->CreateScImportAsciiDlg(
933 NULL
, String(), &aStream
, RID_SCDLG_ASCII
,SC_TEXTTOCOLUMNS
);
934 OSL_ENSURE( pDlg
, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDlg is null!" );
936 if ( pDlg
->Execute() == RET_OK
)
938 ScDocShell
* pDocSh
= pData
->GetDocShell();
939 OSL_ENSURE( pDocSh
, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDocSh is null!" );
941 String aUndo
= ScGlobal::GetRscString( STR_UNDO_TEXTTOCOLUMNS
);
942 pDocSh
->GetUndoManager()->EnterListAction( aUndo
, aUndo
);
944 ScImportExport
aImport( pDoc
, aRange
.aStart
);
945 ScAsciiOptions aOptions
;
946 pDlg
->GetOptions( aOptions
);
947 pDlg
->SaveParameters();
948 aImport
.SetExtOptions( aOptions
);
949 aImport
.SetApi( false );
951 aImport
.ImportStream( aStream
, String(), FORMAT_STRING
);
953 pDocSh
->GetUndoManager()->LeaveListAction();
962 void ScCellShell::GetDBState( SfxItemSet
& rSet
)
964 ScTabViewShell
* pTabViewShell
= GetViewData()->GetViewShell();
965 ScViewData
* pData
= GetViewData();
966 ScDocShell
* pDocSh
= pData
->GetDocShell();
967 ScDocument
* pDoc
= pDocSh
->GetDocument();
968 SCCOL nPosX
= pData
->GetCurX();
969 SCROW nPosY
= pData
->GetCurY();
970 SCTAB nTab
= pData
->GetTabNo();
972 sal_Bool bAutoFilter
= false;
973 sal_Bool bAutoFilterTested
= false;
975 SfxWhichIter
aIter(rSet
);
976 sal_uInt16 nWhich
= aIter
.FirstWhich();
981 case SID_REFRESH_DBAREA
:
983 // imported data without selection
984 // or filter,sort,subtotal (also without import)
985 sal_Bool bOk
= false;
986 ScDBData
* pDBData
= pTabViewShell
->GetDBData(false,SC_DB_OLD
);
987 if (pDBData
&& pDoc
->GetChangeTrack() == NULL
)
989 if ( pDBData
->HasImportParam() )
990 bOk
= !pDBData
->HasImportSelection();
993 bOk
= pDBData
->HasQueryParam() ||
994 pDBData
->HasSortParam() ||
995 pDBData
->HasSubTotalParam();
999 rSet
.DisableItem( nWhich
);
1004 case SID_SPECIAL_FILTER
:
1007 ScMarkType eMarkType
= GetViewData()->GetSimpleArea( aDummy
);
1008 if (eMarkType
!= SC_MARK_SIMPLE
&& eMarkType
!= SC_MARK_SIMPLE_FILTERED
)
1010 rSet
.DisableItem( nWhich
);
1016 //in case of Redlining and multiselection disable
1017 case SID_SORT_ASCENDING
:
1018 case SID_SORT_DESCENDING
:
1019 case SCITEM_SORTDATA
:
1020 case SCITEM_SUBTDATA
:
1021 case SID_OPENDLG_PIVOTTABLE
:
1023 //! move ReadOnly check to idl flags
1025 if ( pDocSh
->IsReadOnly() || pDoc
->GetChangeTrack()!=NULL
||
1026 GetViewData()->IsMultiMarked() )
1028 rSet
.DisableItem( nWhich
);
1033 case SID_REIMPORT_DATA
:
1035 // only imported data without selection
1036 ScDBData
* pDBData
= pTabViewShell
->GetDBData(false,SC_DB_OLD
);
1037 if (!pDBData
|| !pDBData
->HasImportParam() || pDBData
->HasImportSelection() ||
1038 pDoc
->GetChangeTrack()!=NULL
)
1040 rSet
.DisableItem( nWhich
);
1045 case SID_VIEW_DATA_SOURCE_BROWSER
:
1047 if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE
))
1048 rSet
.Put(SfxVisibilityItem(nWhich
, false));
1050 // get state (BoolItem) from SfxViewFrame
1051 pTabViewShell
->GetViewFrame()->GetSlotState( nWhich
, NULL
, &rSet
);
1054 case SID_SBA_BRW_INSERT
:
1056 // SBA wants a sal_Bool-item, enabled
1058 sal_Bool bEnable
= sal_True
;
1059 rSet
.Put(SfxBoolItem(nWhich
, bEnable
));
1063 case SID_AUTO_FILTER
:
1064 case SID_AUTOFILTER_HIDE
:
1066 if (!bAutoFilterTested
)
1068 bAutoFilter
= pDoc
->HasAutoFilter( nPosX
, nPosY
, nTab
);
1069 bAutoFilterTested
= sal_True
;
1071 if ( nWhich
== SID_AUTO_FILTER
)
1074 ScMarkType eMarkType
= GetViewData()->GetSimpleArea( aDummy
);
1075 if (eMarkType
!= SC_MARK_SIMPLE
&& eMarkType
!= SC_MARK_SIMPLE_FILTERED
)
1077 rSet
.DisableItem( nWhich
);
1079 else if (pDoc
->GetDPAtBlock(aDummy
))
1081 rSet
.DisableItem( nWhich
);
1084 rSet
.Put( SfxBoolItem( nWhich
, bAutoFilter
) );
1088 rSet
.DisableItem( nWhich
);
1094 SCCOL nStartCol
, nEndCol
;
1095 SCROW nStartRow
, nEndRow
;
1096 SCTAB nStartTab
, nEndTab
;
1097 sal_Bool bAnyQuery
= false;
1099 sal_Bool bSelected
= (GetViewData()->GetSimpleArea(
1100 nStartCol
, nStartRow
, nStartTab
, nEndCol
, nEndRow
, nEndTab
)
1105 if (nStartCol
==nEndCol
&& nStartRow
==nEndRow
)
1110 nStartCol
= GetViewData()->GetCurX();
1111 nStartRow
= GetViewData()->GetCurY();
1112 nStartTab
= GetViewData()->GetTabNo();
1115 ScDBData
* pDBData
= bSelected
1116 ? pDoc
->GetDBAtArea( nStartTab
, nStartCol
, nStartRow
, nEndCol
, nEndRow
)
1117 : pDoc
->GetDBAtCursor( nStartCol
, nStartRow
, nStartTab
);
1121 ScQueryParam aParam
;
1122 pDBData
->GetQueryParam( aParam
);
1123 if ( aParam
.GetEntry(0).bDoQuery
)
1124 bAnyQuery
= sal_True
;
1128 rSet
.DisableItem( nWhich
);
1132 case SID_DEFINE_DBNAME
:
1134 if ( pDocSh
&& pDocSh
->IsDocShared() )
1136 rSet
.DisableItem( nWhich
);
1141 case SID_TEXT_TO_COLUMNS
:
1144 if ( !lcl_GetTextToColumnsRange( pData
, aRange
) )
1146 rSet
.DisableItem( nWhich
);
1151 nWhich
= aIter
.NextWhich();
1157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */