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 <config_features.h>
22 #include <basic/sberrors.hxx>
23 #include <scitems.hxx>
24 #include <comphelper/lok.hxx>
25 #include <sfx2/viewfrm.hxx>
26 #include <sfx2/request.hxx>
27 #include <basic/sbxcore.hxx>
28 #include <svl/whiter.hxx>
29 #include <svl/numformat.hxx>
30 #include <svl/zforlist.hxx>
31 #include <svl/stritem.hxx>
32 #include <svl/visitem.hxx>
33 #include <unotools/moduleoptions.hxx>
35 #include <com/sun/star/frame/FrameSearchFlag.hpp>
36 #include <com/sun/star/sheet/TableValidationVisibility.hpp>
40 #include <queryparam.hxx>
41 #include <tabvwsh.hxx>
43 #include <globstr.hrc>
44 #include <scresid.hxx>
48 #include <document.hxx>
49 #include <uiitems.hxx>
50 #include <dbdocfun.hxx>
51 #include <reffact.hxx>
53 #include <validat.hxx>
54 #include <validate.hxx>
55 #include <datamapper.hxx>
56 #include <datafdlg.hxx>
58 #include <scui_def.hxx>
59 #include <scabstdlg.hxx>
61 #include <asciiopt.hxx>
62 #include <datastream.hxx>
63 #include <datastreamdlg.hxx>
64 #include <dataproviderdlg.hxx>
65 #include <queryentry.hxx>
66 #include <markdata.hxx>
67 #include <documentlinkmgr.hxx>
68 #include <officecfg/Office/Common.hxx>
70 #include <o3tl/make_shared.hxx>
73 using namespace com::sun::star
;
75 static bool lcl_GetTextToColumnsRange( const ScViewData
& rData
, ScRange
& rRange
, bool bDoEmptyCheckOnly
)
78 const ScMarkData
& rMark
= rData
.GetMarkData();
80 if ( rMark
.IsMarked() )
82 if ( !rMark
.IsMultiMarked() )
84 rRange
= rMark
.GetMarkArea();
85 if ( rRange
.aStart
.Col() == rRange
.aEnd
.Col() )
93 const SCCOL nCol
= rData
.GetCurX();
94 const SCROW nRow
= rData
.GetCurY();
95 const SCTAB nTab
= rData
.GetTabNo();
96 rRange
= ScRange( nCol
, nRow
, nTab
, nCol
, nRow
, nTab
);
100 const ScDocument
& rDoc
= rData
.GetDocument();
102 if ( bDoEmptyCheckOnly
)
104 if ( bRet
&& rDoc
.IsBlockEmpty( rRange
.aStart
.Col(), rRange
.aStart
.Row(),
105 rRange
.aEnd
.Col(), rRange
.aEnd
.Row(),
106 rRange
.aStart
.Tab() ) )
114 SCCOL nStartCol
= rRange
.aStart
.Col(), nEndCol
= rRange
.aEnd
.Col();
115 SCROW nStartRow
= rRange
.aStart
.Row(), nEndRow
= rRange
.aEnd
.Row();
116 bool bShrunk
= false;
117 rDoc
.ShrinkToUsedDataArea( bShrunk
, rRange
.aStart
.Tab(), nStartCol
, nStartRow
,
118 nEndCol
, nEndRow
, false, false, true );
121 rRange
.aStart
.SetRow( nStartRow
);
122 rRange
.aEnd
.SetRow( nEndRow
);
129 static bool lcl_GetSortParam( const ScViewData
& rData
, const ScSortParam
& rSortParam
)
131 ScTabViewShell
* pTabViewShell
= rData
.GetViewShell();
132 ScDBData
* pDBData
= pTabViewShell
->GetDBData();
133 ScDocument
& rDoc
= rData
.GetDocument();
134 SCTAB nTab
= rData
.GetTabNo();
135 ScDirection eFillDir
= DIR_TOP
;
137 ScRange aExternalRange
;
139 if( rSortParam
.nCol1
!= rSortParam
.nCol2
)
141 if( rSortParam
.nRow1
!= rSortParam
.nRow2
)
144 if( rSortParam
.nRow2
== rDoc
.MaxRow() )
146 // Assume that user selected entire column(s), but cater for the
147 // possibility that the start row is not the first row.
148 SCSIZE nCount
= rDoc
.GetEmptyLinesInBlock( rSortParam
.nCol1
, rSortParam
.nRow1
, nTab
,
149 rSortParam
.nCol2
, rSortParam
.nRow2
, nTab
, eFillDir
);
150 aExternalRange
= ScRange( rSortParam
.nCol1
,
151 ::std::min( rSortParam
.nRow1
+ sal::static_int_cast
<SCROW
>( nCount
), rDoc
.MaxRow()), nTab
,
152 rSortParam
.nCol2
, rSortParam
.nRow2
, nTab
);
153 aExternalRange
.PutInOrder();
155 else if (rSortParam
.nCol1
!= rSortParam
.nCol2
|| rSortParam
.nRow1
!= rSortParam
.nRow2
)
157 // Preserve a preselected area.
158 aExternalRange
= ScRange( rSortParam
.nCol1
, rSortParam
.nRow1
, nTab
, rSortParam
.nCol2
, rSortParam
.nRow2
, nTab
);
159 aExternalRange
.PutInOrder();
162 aExternalRange
= ScRange( rData
.GetCurX(), rData
.GetCurY(), nTab
);
164 SCROW nStartRow
= aExternalRange
.aStart
.Row();
165 SCCOL nStartCol
= aExternalRange
.aStart
.Col();
166 SCROW nEndRow
= aExternalRange
.aEnd
.Row();
167 SCCOL nEndCol
= aExternalRange
.aEnd
.Col();
168 rDoc
.GetDataArea( aExternalRange
.aStart
.Tab(), nStartCol
, nStartRow
, nEndCol
, nEndRow
, false, false );
169 aExternalRange
.aStart
.SetRow( nStartRow
);
170 aExternalRange
.aStart
.SetCol( nStartCol
);
171 aExternalRange
.aEnd
.SetRow( nEndRow
);
172 aExternalRange
.aEnd
.SetCol( nEndCol
);
174 // with LibreOfficeKit, don't try to interact with the user
175 if (!comphelper::LibreOfficeKit::isActive() &&
176 ((rSortParam
.nCol1
== rSortParam
.nCol2
&& aExternalRange
.aStart
.Col() != aExternalRange
.aEnd
.Col()) ||
177 (rSortParam
.nRow1
== rSortParam
.nRow2
&& aExternalRange
.aStart
.Row() != aExternalRange
.aEnd
.Row())))
179 pTabViewShell
->AddHighlightRange( aExternalRange
,COL_LIGHTBLUE
);
180 OUString
aExtendStr( aExternalRange
.Format(rDoc
, ScRefFlags::VALID
));
182 ScRange
aCurrentRange( rSortParam
.nCol1
, rSortParam
.nRow1
, nTab
, rSortParam
.nCol2
, rSortParam
.nRow2
, nTab
);
183 OUString
aCurrentStr(aCurrentRange
.Format(rDoc
, ScRefFlags::VALID
));
185 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
187 ScopedVclPtr
<AbstractScSortWarningDlg
> pWarningDlg(pFact
->CreateScSortWarningDlg(pTabViewShell
->GetFrameWeld(), aExtendStr
, aCurrentStr
));
188 short bResult
= pWarningDlg
->Execute();
189 if( bResult
== BTN_EXTEND_RANGE
|| bResult
== BTN_CURRENT_SELECTION
)
191 if( bResult
== BTN_EXTEND_RANGE
)
193 pTabViewShell
->MarkRange( aExternalRange
, false );
194 pDBData
->SetArea( nTab
, aExternalRange
.aStart
.Col(), aExternalRange
.aStart
.Row(), aExternalRange
.aEnd
.Col(), aExternalRange
.aEnd
.Row() );
200 rData
.GetDocShell()->CancelAutoDBRange();
203 pTabViewShell
->ClearHighlightRanges();
210 // this registers the dialog which Find1RefWindow search for
211 class ScValidationRegisteredDlg
213 std::shared_ptr
<SfxDialogController
> m_xDlg
;
215 ScValidationRegisteredDlg(weld::Window
* pParent
, std::shared_ptr
<SfxDialogController
> xDlg
)
216 : m_xDlg(std::move(xDlg
))
218 ScModule::get()->RegisterRefController(static_cast<sal_uInt16
>(ScValidationDlg::SLOTID
), m_xDlg
, pParent
);
220 ~ScValidationRegisteredDlg()
223 ScModule::get()->UnregisterRefController(static_cast<sal_uInt16
>(ScValidationDlg::SLOTID
), m_xDlg
);
228 void ScCellShell::ExecuteDB( SfxRequest
& rReq
)
230 ScTabViewShell
* pTabViewShell
= GetViewData().GetViewShell();
231 sal_uInt16 nSlotId
= rReq
.GetSlot();
232 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
233 ScModule
* pScMod
= ScModule::get();
235 pTabViewShell
->HideListBox(); // Autofilter-DropDown-Listbox
237 if ( GetViewData().HasEditView( GetViewData().GetActivePart() ) )
239 pScMod
->InputEnterHandler();
240 pTabViewShell
->UpdateInputHandler();
245 case SID_VIEW_DATA_SOURCE_BROWSER
:
247 // check if database beamer is open
249 SfxViewFrame
& rViewFrame
= pTabViewShell
->GetViewFrame();
250 bool bWasOpen
= false;
252 uno::Reference
<frame::XFrame
> xFrame
= rViewFrame
.GetFrame().GetFrameInterface();
253 uno::Reference
<frame::XFrame
> xBeamerFrame
= xFrame
->findFrame(
255 frame::FrameSearchFlag::CHILDREN
);
256 if ( xBeamerFrame
.is() )
262 // close database beamer: just forward to SfxViewFrame
264 rViewFrame
.ExecuteSlot( rReq
);
268 // show database beamer: SfxViewFrame call must be synchronous
270 rViewFrame
.ExecuteSlot( rReq
, false ); // false = synchronous
272 // select current database in database beamer
274 ScImportParam aImportParam
;
275 ScDBData
* pDBData
= pTabViewShell
->GetDBData(true,SC_DB_OLD
); // don't create if none found
277 pDBData
->GetImportParam( aImportParam
);
279 ScDBDocFunc::ShowInBeamer( aImportParam
, &pTabViewShell
->GetViewFrame() );
281 rReq
.Done(); // needed because it's a toggle slot
285 case SID_REIMPORT_DATA
:
288 ScDBData
* pDBData
= pTabViewShell
->GetDBData(true,SC_DB_OLD
);
291 ScImportParam aImportParam
;
292 pDBData
->GetImportParam( aImportParam
);
293 if (aImportParam
.bImport
&& !pDBData
->HasImportSelection())
295 pTabViewShell
->ImportData( aImportParam
);
296 pDBData
->SetImportParam( aImportParam
); //! Undo ??
301 if (!bOk
&& ! rReq
.IsAPI() )
302 pTabViewShell
->ErrorMessage(STR_REIMPORT_EMPTY
);
309 case SID_REFRESH_DBAREA
:
311 ScDBData
* pDBData
= pTabViewShell
->GetDBData(true,SC_DB_OLD
);
314 // repeat import like SID_REIMPORT_DATA
316 bool bContinue
= true;
317 ScImportParam aImportParam
;
318 pDBData
->GetImportParam( aImportParam
);
319 if (aImportParam
.bImport
&& !pDBData
->HasImportSelection())
321 bContinue
= pTabViewShell
->ImportData( aImportParam
);
322 pDBData
->SetImportParam( aImportParam
); //! Undo ??
324 // mark (size may have been changed)
326 pDBData
->GetArea(aNewRange
);
327 pTabViewShell
->MarkRange(aNewRange
);
330 if ( bContinue
) // fail at import -> break
332 // internal operations, when any stored
334 if ( pDBData
->HasQueryParam() || pDBData
->HasSortParam() ||
335 pDBData
->HasSubTotalParam() )
336 pTabViewShell
->RepeatDB();
338 // pivot tables that have the range as data source
341 pDBData
->GetArea(aRange
);
342 GetViewData().GetDocShell()->RefreshPivotTables(aRange
);
349 case SID_SBA_BRW_INSERT
:
351 OSL_FAIL( "Deprecated Slot" );
357 ScViewData
& rData
= GetViewData();
359 rData
.GetSimpleArea( aRange
);
360 ScAddress aStart
= aRange
.aStart
;
361 ScAddress aEnd
= aRange
.aEnd
;
363 if((aEnd
.Col() - aStart
.Col()) >= MAX_DATAFORM_COLS
)
365 rData
.GetDocShell()->ErrorMessage(STR_TOO_MANY_COLUMNS_DATA_FORM
);
369 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
371 ScopedVclPtr
<AbstractScDataFormDlg
> pDlg(pFact
->CreateScDataFormDlg(
372 pTabViewShell
->GetFrameWeld(), pTabViewShell
));
381 ExecuteSubtotals(rReq
);
384 case SID_SORT_DESCENDING
:
385 case SID_SORT_ASCENDING
:
387 //#i60401 ux-ctest: Calc does not support all users' strategies regarding sorting data
388 //the patch comes from maoyg
389 ScSortParam aSortParam
;
390 ScDBData
* pDBData
= pTabViewShell
->GetDBData();
391 ScViewData
& rData
= GetViewData();
393 pDBData
->GetSortParam( aSortParam
);
395 if( lcl_GetSortParam( rData
, aSortParam
) )
397 SCCOL nCol
= GetViewData().GetCurX();
398 SCCOL nTab
= GetViewData().GetTabNo();
399 ScDocument
& rDoc
= GetViewData().GetDocument();
401 pDBData
->GetSortParam( aSortParam
);
402 bool bHasHeader
= rDoc
.HasColHeader( aSortParam
.nCol1
, aSortParam
.nRow1
, aSortParam
.nCol2
, aSortParam
.nRow2
, nTab
);
404 if( nCol
< aSortParam
.nCol1
)
405 nCol
= aSortParam
.nCol1
;
406 else if( nCol
> aSortParam
.nCol2
)
407 nCol
= aSortParam
.nCol2
;
409 aSortParam
.bHasHeader
= bHasHeader
;
410 aSortParam
.bByRow
= true;
411 aSortParam
.bCaseSens
= false;
412 aSortParam
.bNaturalSort
= false;
413 aSortParam
.aDataAreaExtras
.mbCellNotes
= false;
414 aSortParam
.aDataAreaExtras
.mbCellDrawObjects
= true;
415 aSortParam
.aDataAreaExtras
.mbCellFormats
= true;
416 aSortParam
.bInplace
= true;
417 aSortParam
.maKeyState
[0].bDoSort
= true;
418 aSortParam
.maKeyState
[0].nField
= nCol
;
419 aSortParam
.maKeyState
[0].bAscending
= ( nSlotId
== SID_SORT_ASCENDING
);
421 for ( sal_uInt16 i
=1; i
<aSortParam
.GetSortKeyCount(); i
++ )
422 aSortParam
.maKeyState
[i
].bDoSort
= false;
424 pTabViewShell
->UISort( aSortParam
); // subtotal when needed new
433 const SfxItemSet
* pArgs
= rReq
.GetArgs();
435 //#i60401 ux-ctest: Calc does not support all users' strategies regarding sorting data
436 //the patch comes from maoyg
438 if ( pArgs
) // Basic
440 ScSortParam aSortParam
;
441 ScDBData
* pDBData
= pTabViewShell
->GetDBData();
442 ScViewData
& rData
= GetViewData();
444 pDBData
->GetSortParam( aSortParam
);
446 if( lcl_GetSortParam( rData
, aSortParam
) )
448 ScDocument
& rDoc
= GetViewData().GetDocument();
450 pDBData
->GetSortParam( aSortParam
);
451 bool bHasHeader
= rDoc
.HasColHeader( aSortParam
.nCol1
, aSortParam
.nRow1
, aSortParam
.nCol2
, aSortParam
.nRow2
, rData
.GetTabNo() );
453 aSortParam
.bHasHeader
= bHasHeader
;
455 aSortParam
.bInplace
= true; // from Basic always
457 if ( const SfxBoolItem
* pItem
= pArgs
->GetItemIfSet( SID_SORT_BYROW
) )
458 aSortParam
.bByRow
= pItem
->GetValue();
459 if ( const SfxBoolItem
* pItem
= pArgs
->GetItemIfSet( SID_SORT_HASHEADER
) )
460 aSortParam
.bHasHeader
= pItem
->GetValue();
461 if ( const SfxBoolItem
* pItem
= pArgs
->GetItemIfSet( SID_SORT_CASESENS
) )
462 aSortParam
.bCaseSens
= pItem
->GetValue();
463 if ( const SfxBoolItem
* pItem
= pArgs
->GetItemIfSet( SID_SORT_NATURALSORT
) )
464 aSortParam
.bNaturalSort
= pItem
->GetValue();
465 if ( const SfxBoolItem
* pItem
= pArgs
->GetItemIfSet( SID_SORT_INCCOMMENTS
) )
466 aSortParam
.aDataAreaExtras
.mbCellNotes
= pItem
->GetValue();
467 if ( const SfxBoolItem
* pItem
= pArgs
->GetItemIfSet( SID_SORT_INCIMAGES
) )
468 aSortParam
.aDataAreaExtras
.mbCellDrawObjects
= pItem
->GetValue();
469 if ( const SfxBoolItem
* pItem
= pArgs
->GetItemIfSet( SID_SORT_ATTRIBS
) )
470 aSortParam
.aDataAreaExtras
.mbCellFormats
= pItem
->GetValue();
471 if ( const SfxUInt16Item
* pItem
= pArgs
->GetItemIfSet( SID_SORT_USERDEF
) )
473 sal_uInt16 nUserIndex
= pItem
->GetValue();
474 aSortParam
.bUserDef
= ( nUserIndex
!= 0 );
476 aSortParam
.nUserIndex
= nUserIndex
- 1; // Basic: 1-based
479 SCCOLROW nField0
= 0;
480 const SfxPoolItem
* pItem
= nullptr;
481 if ( pArgs
->GetItemState( FN_PARAM_1
, true, &pItem
) == SfxItemState::SET
)
482 nField0
= static_cast<const SfxInt32Item
*>(pItem
)->GetValue();
483 aSortParam
.maKeyState
[0].bDoSort
= ( nField0
!= 0 );
484 aSortParam
.maKeyState
[0].nField
= nField0
> 0 ? (nField0
-1) : 0;
485 if ( pArgs
->GetItemState( FN_PARAM_2
, true, &pItem
) == SfxItemState::SET
)
486 aSortParam
.maKeyState
[0].bAscending
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
487 SCCOLROW nField1
= 0;
488 if ( pArgs
->GetItemState( FN_PARAM_3
, true, &pItem
) == SfxItemState::SET
)
489 nField1
= static_cast<const SfxInt32Item
*>(pItem
)->GetValue();
490 aSortParam
.maKeyState
[1].bDoSort
= ( nField1
!= 0 );
491 aSortParam
.maKeyState
[1].nField
= nField1
> 0 ? (nField1
-1) : 0;
492 if ( pArgs
->GetItemState( FN_PARAM_4
, true, &pItem
) == SfxItemState::SET
)
493 aSortParam
.maKeyState
[1].bAscending
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
494 SCCOLROW nField2
= 0;
495 if ( pArgs
->GetItemState( FN_PARAM_5
, true, &pItem
) == SfxItemState::SET
)
496 nField2
= static_cast<const SfxInt32Item
*>(pItem
)->GetValue();
497 aSortParam
.maKeyState
[2].bDoSort
= ( nField2
!= 0 );
498 aSortParam
.maKeyState
[2].nField
= nField2
> 0 ? (nField2
-1) : 0;
499 if ( pArgs
->GetItemState( FN_PARAM_6
, true, &pItem
) == SfxItemState::SET
)
500 aSortParam
.maKeyState
[2].bAscending
= static_cast<const SfxBoolItem
*>(pItem
)->GetValue();
502 // subtotal when needed new
503 pTabViewShell
->UISort( aSortParam
);
509 ScSortParam aSortParam
;
510 ScDBData
* pDBData
= pTabViewShell
->GetDBData();
511 ScViewData
& rData
= GetViewData();
513 pDBData
->GetSortParam( aSortParam
);
515 if( lcl_GetSortParam( rData
, aSortParam
) )
517 ScDocument
& rDoc
= GetViewData().GetDocument();
518 SfxItemSetFixed
<SCITEM_SORTDATA
, SCITEM_SORTDATA
> aArgSet( GetPool() );
520 pDBData
->GetSortParam( aSortParam
);
521 bool bHasHeader
= rDoc
.HasColHeader( aSortParam
.nCol1
, aSortParam
.nRow1
, aSortParam
.nCol2
, aSortParam
.nRow2
, rData
.GetTabNo() );
523 aSortParam
.bHasHeader
= bHasHeader
;
525 aArgSet
.Put( ScSortItem( SCITEM_SORTDATA
, &GetViewData(), &aSortParam
) );
527 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
528 std::shared_ptr
<ScAsyncTabController
> pDlg(pFact
->CreateScSortDlg(pTabViewShell
->GetFrameWeld(), &aArgSet
));
529 pDlg
->SetCurPageId(u
"criteria"_ustr
); // 1=sort field tab 2=sort options tab
531 VclAbstractDialog::AsyncContext aContext
;
532 aContext
.maEndDialogFn
= [pDlg
, &rData
, pTabViewShell
](sal_Int32 nResult
)
534 if ( nResult
== RET_OK
)
536 const SfxItemSet
* pOutSet
= pDlg
->GetOutputItemSet();
537 const ScSortParam
& rOutParam
=
538 pOutSet
->Get( SCITEM_SORTDATA
).GetSortData();
540 // subtotal when needed new
542 pTabViewShell
->UISort( rOutParam
);
544 SfxViewFrame
& rViewFrm
= pTabViewShell
->GetViewFrame();
545 SfxRequest
aRequest(rViewFrm
, SID_SORT
);
547 if ( rOutParam
.bInplace
)
549 aRequest
.AppendItem( SfxBoolItem( SID_SORT_BYROW
,
550 rOutParam
.bByRow
) );
551 aRequest
.AppendItem( SfxBoolItem( SID_SORT_HASHEADER
,
552 rOutParam
.bHasHeader
) );
553 aRequest
.AppendItem( SfxBoolItem( SID_SORT_CASESENS
,
554 rOutParam
.bCaseSens
) );
555 aRequest
.AppendItem( SfxBoolItem( SID_SORT_NATURALSORT
,
556 rOutParam
.bNaturalSort
) );
557 aRequest
.AppendItem( SfxBoolItem( SID_SORT_INCCOMMENTS
,
558 rOutParam
.aDataAreaExtras
.mbCellNotes
) );
559 aRequest
.AppendItem( SfxBoolItem( SID_SORT_INCIMAGES
,
560 rOutParam
.aDataAreaExtras
.mbCellDrawObjects
) );
561 aRequest
.AppendItem( SfxBoolItem( SID_SORT_ATTRIBS
,
562 rOutParam
.aDataAreaExtras
.mbCellFormats
) );
563 sal_uInt16 nUser
= rOutParam
.bUserDef
? ( rOutParam
.nUserIndex
+ 1 ) : 0;
564 aRequest
.AppendItem( SfxUInt16Item( SID_SORT_USERDEF
, nUser
) );
565 if ( rOutParam
.maKeyState
[0].bDoSort
)
567 aRequest
.AppendItem( SfxInt32Item( TypedWhichId
<SfxInt32Item
>(FN_PARAM_1
),
568 rOutParam
.maKeyState
[0].nField
+ 1 ) );
569 aRequest
.AppendItem( SfxBoolItem( FN_PARAM_2
,
570 rOutParam
.maKeyState
[0].bAscending
) );
572 if ( rOutParam
.maKeyState
[1].bDoSort
)
574 aRequest
.AppendItem( SfxInt32Item( TypedWhichId
<SfxInt32Item
>(FN_PARAM_3
),
575 rOutParam
.maKeyState
[1].nField
+ 1 ) );
576 aRequest
.AppendItem( SfxBoolItem( FN_PARAM_4
,
577 rOutParam
.maKeyState
[1].bAscending
) );
579 if ( rOutParam
.maKeyState
[2].bDoSort
)
581 aRequest
.AppendItem( SfxInt32Item( TypedWhichId
<SfxInt32Item
>(FN_PARAM_5
),
582 rOutParam
.maKeyState
[2].nField
+ 1 ) );
583 aRequest
.AppendItem( SfxBoolItem( FN_PARAM_6
,
584 rOutParam
.maKeyState
[2].bAscending
) );
592 rData
.GetDocShell()->CancelAutoDBRange();
596 pDlg
->StartExecuteAsync(aContext
);
604 const SfxItemSet
* pArgs
= rReq
.GetArgs();
607 OSL_FAIL("SID_FILTER with arguments?");
608 pTabViewShell
->Query(
609 pArgs
->Get( SCITEM_QUERYDATA
).GetQueryData(), nullptr, true );
614 sal_uInt16 nId
= ScFilterDlgWrapper::GetChildWindowId();
615 SfxViewFrame
& rViewFrm
= pTabViewShell
->GetViewFrame();
616 SfxChildWindow
* pWnd
= rViewFrm
.GetChildWindow( nId
);
618 pScMod
->SetRefDialog( nId
, pWnd
== nullptr );
623 case SID_SPECIAL_FILTER
:
625 const SfxItemSet
* pArgs
= rReq
.GetArgs();
628 OSL_FAIL("SID_SPECIAL_FILTER with arguments?");
629 pTabViewShell
->Query(
630 pArgs
->Get( SCITEM_QUERYDATA
).GetQueryData(), nullptr, true );
635 sal_uInt16 nId
= ScSpecialFilterDlgWrapper::GetChildWindowId();
636 SfxViewFrame
& rViewFrm
= pTabViewShell
->GetViewFrame();
637 SfxChildWindow
* pWnd
= rViewFrm
.GetChildWindow( nId
);
639 pScMod
->SetRefDialog( nId
, pWnd
== nullptr );
646 const ScQueryItem
* pQueryItem
;
647 if ( pReqArgs
&& (pQueryItem
=
648 pReqArgs
->GetItemIfSet( SCITEM_QUERYDATA
)) )
650 SCTAB nCurTab
= GetViewData().GetTabNo();
651 SCTAB nRefTab
= GetViewData().GetRefTabNo();
653 // If RefInput switched to a different sheet from the data sheet,
656 if ( nCurTab
!= nRefTab
)
658 pTabViewShell
->SetTabNo( nRefTab
);
659 pTabViewShell
->PaintExtras();
663 if (pQueryItem
->GetAdvancedQuerySource(aAdvSource
))
664 pTabViewShell
->Query( pQueryItem
->GetQueryData(), &aAdvSource
, true );
666 pTabViewShell
->Query( pQueryItem
->GetQueryData(), nullptr, true );
667 rReq
.Done( *pReqArgs
);
675 ScDBData
* pDBData
= pTabViewShell
->GetDBData();
677 pDBData
->GetQueryParam( aParam
);
678 SCSIZE nEC
= aParam
.GetEntryCount();
679 for (SCSIZE i
=0; i
<nEC
; i
++)
680 aParam
.GetEntry(i
).bDoQuery
= false;
681 aParam
.bDuplicate
= true;
682 pTabViewShell
->Query( aParam
, nullptr, true );
687 case SID_AUTO_FILTER
:
688 pTabViewShell
->ToggleAutoFilter();
692 case SID_AUTOFILTER_HIDE
:
693 pTabViewShell
->HideAutoFilter();
697 case SID_PIVOT_TABLE
:
699 const ScPivotItem
* pPItem
;
700 if ( pReqArgs
&& (pPItem
=
701 pReqArgs
->GetItemIfSet( SCITEM_PIVOTDATA
)) )
703 SCTAB nCurTab
= GetViewData().GetTabNo();
704 SCTAB nRefTab
= GetViewData().GetRefTabNo();
706 // If RefInput switched to a different sheet from the data sheet,
709 if ( nCurTab
!= nRefTab
)
711 pTabViewShell
->SetTabNo( nRefTab
);
712 pTabViewShell
->PaintExtras();
715 const ScDPObject
* pDPObject
= pTabViewShell
->GetDialogDPObject();
718 bool bSuccess
= pTabViewShell
->MakePivotTable(
719 pPItem
->GetData(), pPItem
->GetDestRange(), pPItem
->IsNewSheet(), *pDPObject
);
720 SfxBoolItem
aRet(0, bSuccess
);
721 rReq
.SetReturnValue(aRet
);
725 #if HAVE_FEATURE_SCRIPTING
726 else if (rReq
.IsAPI())
727 SbxBase::SetError(ERRCODE_BASIC_BAD_PARAMETER
);
732 case SID_OPENDLG_PIVOTTABLE
:
733 ExecuteDataPilotDialog();
735 case SID_DEFINE_DBNAME
:
738 sal_uInt16 nId
= ScDbNameDlgWrapper::GetChildWindowId();
739 SfxViewFrame
& rViewFrm
= pTabViewShell
->GetViewFrame();
740 SfxChildWindow
* pWnd
= rViewFrm
.GetChildWindow( nId
);
742 pScMod
->SetRefDialog( nId
, pWnd
== nullptr );
751 const SfxStringItem
& rItem
= pReqArgs
->Get(SID_SELECT_DB
);
752 pTabViewShell
->GotoDBArea(rItem
.GetValue());
757 ScDocument
& rDoc
= GetViewData().GetDocument();
758 ScDBCollection
* pDBCol
= rDoc
.GetDBCollection();
762 std::vector
<OUString
> aList
;
763 const ScDBCollection::NamedDBs
& rDBs
= pDBCol
->getNamedDBs();
764 for (const auto& rxDB
: rDBs
)
765 aList
.push_back(rxDB
->GetName());
767 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
769 VclPtr
<AbstractScSelEntryDlg
> pDlg(
770 pFact
->CreateScSelEntryDlg(pTabViewShell
->GetFrameWeld(), aList
));
771 pDlg
->StartExecuteAsync(
772 [pTabViewShell
, pDlg
](sal_Int32 nResult
)
774 if (nResult
== RET_OK
)
776 OUString aName
= pDlg
->GetSelectedEntry();
777 pTabViewShell
->GotoDBArea(aName
);
778 SfxRequest
aRequest(pTabViewShell
->GetViewFrame(),
780 aRequest
.AppendItem(SfxStringItem(SID_SELECT_DB
, aName
));
790 case SID_DATA_STREAMS
:
792 sc::DataStreamDlg
aDialog(GetViewData().GetDocShell(), pTabViewShell
->GetFrameWeld());
793 ScDocument
& rDoc
= GetViewData().GetDocument();
794 sc::DocumentLinkManager
& rMgr
= rDoc
.GetDocLinkManager();
795 sc::DataStream
* pStrm
= rMgr
.getDataStream();
797 aDialog
.Init(*pStrm
);
799 if (aDialog
.run() == RET_OK
)
800 aDialog
.StartStream();
803 case SID_DATA_STREAMS_PLAY
:
805 ScDocument
& rDoc
= GetViewData().GetDocument();
806 sc::DocumentLinkManager
& rMgr
= rDoc
.GetDocLinkManager();
807 sc::DataStream
* pStrm
= rMgr
.getDataStream();
809 pStrm
->StartImport();
812 case SID_DATA_STREAMS_STOP
:
814 ScDocument
& rDoc
= GetViewData().GetDocument();
815 sc::DocumentLinkManager
& rMgr
= rDoc
.GetDocLinkManager();
816 sc::DataStream
* pStrm
= rMgr
.getDataStream();
821 case SID_DATA_PROVIDER
:
823 auto xDoc
= o3tl::make_shared
<ScDocument
>();
824 xDoc
->InsertTab(0, u
"test"_ustr
);
825 ScDocument
& rDoc
= GetViewData().GetDocument();
826 ScDataProviderDlg
aDialog(pTabViewShell
->GetDialogParent(), std::move(xDoc
), &rDoc
);
827 if (aDialog
.run() == RET_OK
)
829 aDialog
.import(rDoc
);
833 case SID_DATA_PROVIDER_REFRESH
:
835 ScDocument
& rDoc
= GetViewData().GetDocument();
836 auto& rDataMapper
= rDoc
.GetExternalDataMapper();
837 for (auto& rDataSource
: rDataMapper
.getDataSources())
839 rDataSource
.refresh(&rDoc
, false);
843 case SID_MANAGE_XML_SOURCE
:
844 ExecuteXMLSourceDialog();
847 case FID_CURRENTVALIDATION
:
849 const SfxItemSet
* pArgs
= rReq
.GetArgs();
852 OSL_FAIL("later...");
856 SfxItemSet
aArgSet( GetPool(), ScTPValidationValue::GetRanges() );
857 ScValidationMode eMode
= SC_VALID_ANY
;
858 ScConditionMode eOper
= ScConditionMode::Equal
;
859 OUString aExpr1
, aExpr2
;
861 bool bCaseSensitive
= false;
862 sal_Int16 nListType
= css::sheet::TableValidationVisibility::UNSORTED
;
863 bool bShowHelp
= false;
864 OUString aHelpTitle
, aHelpText
;
865 bool bShowError
= false;
866 ScValidErrorStyle eErrStyle
= SC_VALERR_STOP
;
867 OUString aErrTitle
, aErrText
;
869 ScDocument
& rDoc
= GetViewData().GetDocument();
870 SCCOL nCurX
= GetViewData().GetCurX();
871 SCROW nCurY
= GetViewData().GetCurY();
872 SCTAB nTab
= GetViewData().GetTabNo();
873 ScAddress
aCursorPos( nCurX
, nCurY
, nTab
);
874 sal_uInt32 nIndex
= rDoc
.GetAttr(
875 nCurX
, nCurY
, nTab
, ATTR_VALIDDATA
)->GetValue();
878 const ScValidationData
* pOldData
= rDoc
.GetValidationEntry( nIndex
);
881 eMode
= pOldData
->GetDataMode();
882 eOper
= pOldData
->GetOperation();
883 sal_uInt32 nNumFmt
= 0;
884 if ( eMode
== SC_VALID_DATE
|| eMode
== SC_VALID_TIME
)
886 SvNumFormatType nType
= ( eMode
== SC_VALID_DATE
) ? SvNumFormatType::DATE
887 : SvNumFormatType::TIME
;
888 nNumFmt
= rDoc
.GetFormatTable()->GetStandardFormat(
889 nType
, ScGlobal::eLnge
);
891 aExpr1
= pOldData
->GetExpression( aCursorPos
, 0, nNumFmt
);
892 aExpr2
= pOldData
->GetExpression( aCursorPos
, 1, nNumFmt
);
893 bBlank
= pOldData
->IsIgnoreBlank();
894 bCaseSensitive
= pOldData
->IsCaseSensitive();
895 nListType
= pOldData
->GetListType();
897 bShowHelp
= pOldData
->GetInput( aHelpTitle
, aHelpText
);
898 bShowError
= pOldData
->GetErrMsg( aErrTitle
, aErrText
, eErrStyle
);
900 aArgSet
.Put( SfxUInt16Item( FID_VALID_MODE
, sal::static_int_cast
<sal_uInt16
>(eMode
) ) );
901 aArgSet
.Put( SfxUInt16Item( FID_VALID_CONDMODE
, sal::static_int_cast
<sal_uInt16
>(eOper
) ) );
902 aArgSet
.Put( SfxStringItem( FID_VALID_VALUE1
, aExpr1
) );
903 aArgSet
.Put( SfxStringItem( FID_VALID_VALUE2
, aExpr2
) );
904 aArgSet
.Put( SfxBoolItem( FID_VALID_BLANK
, bBlank
) );
905 aArgSet
.Put( SfxBoolItem( FID_VALID_CASESENS
, bCaseSensitive
) );
906 aArgSet
.Put( SfxInt16Item( FID_VALID_LISTTYPE
, nListType
) );
907 aArgSet
.Put( SfxBoolItem( FID_VALID_SHOWHELP
, bShowHelp
) );
908 aArgSet
.Put( SfxStringItem( FID_VALID_HELPTITLE
, aHelpTitle
) );
909 aArgSet
.Put( SfxStringItem( FID_VALID_HELPTEXT
, aHelpText
) );
910 aArgSet
.Put( SfxBoolItem( FID_VALID_SHOWERR
, bShowError
) );
911 aArgSet
.Put( SfxUInt16Item( FID_VALID_ERRSTYLE
, sal::static_int_cast
<sal_uInt16
>(eErrStyle
) ) );
912 aArgSet
.Put( SfxStringItem( FID_VALID_ERRTITLE
, aErrTitle
) );
913 aArgSet
.Put( SfxStringItem( FID_VALID_ERRTEXT
, aErrText
) );
918 vcl::Window
* pWin
= GetViewData().GetActiveWin();
919 weld::Window
* pParentWin
= pWin
? pWin
->GetFrameWeld() : nullptr;
920 auto xDlg
= std::make_shared
<ScValidationDlg
>(pParentWin
, &aArgSet
, pTabViewShell
);
921 ScValidationRegisteredDlg
aRegisterThatDlgExists(pParentWin
, xDlg
);
923 short nResult
= xDlg
->run();
924 if ( nResult
== RET_OK
)
926 const SfxItemSet
* pOutSet
= xDlg
->GetOutputItemSet();
928 if ( const SfxUInt16Item
* pItem
= pOutSet
->GetItemIfSet( FID_VALID_MODE
) )
929 eMode
= static_cast<ScValidationMode
>(pItem
->GetValue());
930 if ( const SfxUInt16Item
* pItem
= pOutSet
->GetItemIfSet( FID_VALID_CONDMODE
) )
931 eOper
= static_cast<ScConditionMode
>(pItem
->GetValue());
932 if ( const SfxStringItem
* pItem
= pOutSet
->GetItemIfSet( FID_VALID_VALUE1
) )
934 OUString aTemp1
= pItem
->GetValue();
935 if (eMode
== SC_VALID_DATE
|| eMode
== SC_VALID_TIME
)
937 sal_uInt32 nNumIndex
= 0;
939 if (rDoc
.GetFormatTable()->IsNumberFormat(aTemp1
, nNumIndex
, nVal
))
940 aExpr1
= ::rtl::math::doubleToUString( nVal
,
941 rtl_math_StringFormat_Automatic
, rtl_math_DecimalPlaces_Max
,
942 ScGlobal::getLocaleData().getNumDecimalSep()[0], true);
949 if ( const SfxStringItem
* pItem
= pOutSet
->GetItemIfSet( FID_VALID_VALUE2
) )
951 OUString aTemp2
= pItem
->GetValue();
952 if (eMode
== SC_VALID_DATE
|| eMode
== SC_VALID_TIME
)
954 sal_uInt32 nNumIndex
= 0;
956 if (rDoc
.GetFormatTable()->IsNumberFormat(aTemp2
, nNumIndex
, nVal
))
957 aExpr2
= ::rtl::math::doubleToUString( nVal
,
958 rtl_math_StringFormat_Automatic
, rtl_math_DecimalPlaces_Max
,
959 ScGlobal::getLocaleData().getNumDecimalSep()[0], true);
962 if ( eMode
== SC_VALID_TIME
) {
963 sal_Int32 wraparound
= aExpr1
.compareTo(aExpr2
);
964 if (wraparound
> 0) {
965 if (eOper
== ScConditionMode::Between
) {
966 eOper
= ScConditionMode::NotBetween
;
967 std::swap( aExpr1
, aExpr2
);
969 else if (eOper
== ScConditionMode::NotBetween
) {
970 eOper
= ScConditionMode::Between
;
971 std::swap( aExpr1
, aExpr2
);
979 if ( const SfxBoolItem
* pItem
= pOutSet
->GetItemIfSet( FID_VALID_BLANK
) )
980 bBlank
= pItem
->GetValue();
981 if ( const SfxBoolItem
* pItem
= pOutSet
->GetItemIfSet( FID_VALID_CASESENS
) )
982 bCaseSensitive
= pItem
->GetValue();
983 if ( const SfxInt16Item
* pItem
= pOutSet
->GetItemIfSet( FID_VALID_LISTTYPE
) )
984 nListType
= pItem
->GetValue();
986 if ( const SfxBoolItem
* pItem
= pOutSet
->GetItemIfSet( FID_VALID_SHOWHELP
) )
987 bShowHelp
= pItem
->GetValue();
988 if ( const SfxStringItem
* pItem
= pOutSet
->GetItemIfSet( FID_VALID_HELPTITLE
) )
989 aHelpTitle
= pItem
->GetValue();
990 if ( const SfxStringItem
* pItem
= pOutSet
->GetItemIfSet( FID_VALID_HELPTEXT
) )
991 aHelpText
= pItem
->GetValue();
993 if ( const SfxBoolItem
* pItem
= pOutSet
->GetItemIfSet( FID_VALID_SHOWERR
) )
994 bShowError
= pItem
->GetValue();
995 if ( const SfxUInt16Item
* pItem
= pOutSet
->GetItemIfSet( FID_VALID_ERRSTYLE
) )
996 eErrStyle
= static_cast<ScValidErrorStyle
>(pItem
->GetValue());
997 if ( const SfxStringItem
* pItem
= pOutSet
->GetItemIfSet( FID_VALID_ERRTITLE
) )
998 aErrTitle
= pItem
->GetValue();
999 if ( const SfxStringItem
* pItem
= pOutSet
->GetItemIfSet( FID_VALID_ERRTEXT
) )
1000 aErrText
= pItem
->GetValue();
1002 ScValidationData
aData( eMode
, eOper
, aExpr1
, aExpr2
, rDoc
, aCursorPos
);
1003 aData
.SetIgnoreBlank( bBlank
);
1004 aData
.SetCaseSensitive( bCaseSensitive
);
1005 aData
.SetListType( nListType
);
1007 aData
.SetInput(aHelpTitle
, aHelpText
); // sets bShowInput to TRUE
1009 aData
.ResetInput(); // reset only bShowInput
1011 aData
.SetError(aErrTitle
, aErrText
, eErrStyle
); // sets bShowError to TRUE
1013 aData
.ResetError(); // reset only bShowError
1015 pTabViewShell
->SetValidation( aData
);
1016 pTabViewShell
->TestHintWindow();
1017 rReq
.Done( *pOutSet
);
1023 case SID_TEXT_TO_COLUMNS
:
1025 ScViewData
& rData
= GetViewData();
1028 if ( lcl_GetTextToColumnsRange( rData
, aRange
, false ) )
1030 ScDocument
& rDoc
= rData
.GetDocument();
1032 ScImportExport
aExport( rDoc
, aRange
);
1033 aExport
.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::None
, 0, false ) );
1035 // #i87703# text to columns fails with tab separator
1036 aExport
.SetDelimiter( u
'\0' );
1038 SvMemoryStream aStream
;
1039 aStream
.SetStreamCharSet( RTL_TEXTENCODING_UNICODE
);
1040 ScImportExport::SetNoEndianSwap( aStream
);
1041 aExport
.ExportStream( aStream
, OUString(), SotClipboardFormatId::STRING
);
1044 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
1045 ScopedVclPtr
<AbstractScImportAsciiDlg
> pDlg(pFact
->CreateScImportAsciiDlg(
1046 pTabViewShell
->GetFrameWeld(), OUString(), &aStream
, SC_TEXTTOCOLUMNS
));
1048 if ( pDlg
->Execute() == RET_OK
)
1050 ScDocShell
* pDocSh
= rData
.GetDocShell();
1051 OSL_ENSURE( pDocSh
, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDocSh is null!" );
1053 OUString aUndo
= ScResId( STR_UNDO_TEXTTOCOLUMNS
);
1054 pDocSh
->GetUndoManager()->EnterListAction( aUndo
, aUndo
, 0, rData
.GetViewShell()->GetViewShellId() );
1056 ScImportExport
aImport( rDoc
, aRange
.aStart
);
1057 ScAsciiOptions aOptions
;
1058 pDlg
->GetOptions( aOptions
);
1059 pDlg
->SaveParameters();
1060 aImport
.SetExtOptions( aOptions
);
1061 aImport
.SetApi( false );
1062 aImport
.SetImportBroadcast( true );
1063 aImport
.SetOverwriting( true );
1065 aImport
.ImportStream( aStream
, OUString(), SotClipboardFormatId::STRING
);
1067 pDocSh
->GetUndoManager()->LeaveListAction();
1075 void ScCellShell::GetDBState( SfxItemSet
& rSet
)
1077 ScTabViewShell
* pTabViewShell
= GetViewData().GetViewShell();
1078 ScViewData
& rData
= GetViewData();
1079 ScDocShell
* pDocSh
= rData
.GetDocShell();
1080 ScDocument
& rDoc
= pDocSh
->GetDocument();
1081 SCCOL nPosX
= rData
.GetCurX();
1082 SCROW nPosY
= rData
.GetCurY();
1083 SCTAB nTab
= rData
.GetTabNo();
1085 bool bAutoFilter
= false;
1086 bool bAutoFilterTested
= false;
1088 SfxWhichIter
aIter(rSet
);
1089 sal_uInt16 nWhich
= aIter
.FirstWhich();
1094 case SID_REFRESH_DBAREA
:
1096 // imported data without selection
1097 // or filter,sort,subtotal (also without import)
1099 ScDBData
* pDBData
= pTabViewShell
->GetDBData(false,SC_DB_OLD
);
1100 if (pDBData
&& rDoc
.GetChangeTrack() == nullptr)
1102 if ( pDBData
->HasImportParam() )
1103 bOk
= !pDBData
->HasImportSelection();
1106 bOk
= pDBData
->HasQueryParam() ||
1107 pDBData
->HasSortParam() ||
1108 pDBData
->HasSubTotalParam();
1112 rSet
.DisableItem( nWhich
);
1117 case SID_SPECIAL_FILTER
:
1119 const ScTableProtection
* pTabProt
= rDoc
.GetTabProtection(nTab
);
1120 if (pTabProt
&& pTabProt
->isProtected() && !pTabProt
->isOptionEnabled(ScTableProtection::AUTOFILTER
))
1122 rSet
.DisableItem(nWhich
);
1127 ScMarkType eMarkType
= GetViewData().GetSimpleArea(aDummy
);
1128 if (eMarkType
!= SC_MARK_SIMPLE
&& eMarkType
!= SC_MARK_SIMPLE_FILTERED
)
1130 rSet
.DisableItem(nWhich
);
1136 //in case of Redlining and multiselection disable
1137 case SID_SORT_ASCENDING
:
1138 case SID_SORT_DESCENDING
:
1139 case SCITEM_SORTDATA
:
1140 case SCITEM_SUBTDATA
:
1141 case SID_OPENDLG_PIVOTTABLE
:
1143 //! move ReadOnly check to idl flags
1145 if ( pDocSh
->IsReadOnly() || rDoc
.GetChangeTrack()!=nullptr ||
1146 GetViewData().IsMultiMarked() )
1148 rSet
.DisableItem( nWhich
);
1152 if (nWhich
== SID_OPENDLG_PIVOTTABLE
)
1154 const ScTableProtection
* pTabProt
= rDoc
.GetTabProtection(nTab
);
1155 if (pTabProt
&& pTabProt
->isProtected() && !pTabProt
->isOptionEnabled(ScTableProtection::PIVOT_TABLES
))
1157 rSet
.DisableItem(nWhich
);
1164 case SID_REIMPORT_DATA
:
1166 // only imported data without selection
1167 ScDBData
* pDBData
= pTabViewShell
->GetDBData(false,SC_DB_OLD
);
1168 if (!pDBData
|| !pDBData
->HasImportParam() || pDBData
->HasImportSelection() ||
1169 rDoc
.GetChangeTrack()!=nullptr)
1171 rSet
.DisableItem( nWhich
);
1176 case SID_VIEW_DATA_SOURCE_BROWSER
:
1178 if (!SvtModuleOptions().IsDataBaseInstalled())
1179 rSet
.Put(SfxVisibilityItem(nWhich
, false));
1181 // get state (BoolItem) from SfxViewFrame
1182 pTabViewShell
->GetViewFrame().GetSlotState( nWhich
, nullptr, &rSet
);
1185 case SID_SBA_BRW_INSERT
:
1187 // SBA wants a sal_Bool-item, enabled
1189 rSet
.Put(SfxBoolItem(nWhich
, true));
1193 case SID_AUTO_FILTER
:
1194 case SID_AUTOFILTER_HIDE
:
1196 const ScTableProtection
* pTabProt
= rDoc
.GetTabProtection(nTab
);
1197 if (pTabProt
&& pTabProt
->isProtected() && !pTabProt
->isOptionEnabled(ScTableProtection::AUTOFILTER
))
1199 rSet
.DisableItem(nWhich
);
1203 if (!bAutoFilterTested
)
1205 bAutoFilter
= rDoc
.HasAutoFilter(nPosX
, nPosY
, nTab
);
1206 bAutoFilterTested
= true;
1208 if (nWhich
== SID_AUTO_FILTER
)
1211 ScMarkType eMarkType
= GetViewData().GetSimpleArea(aDummy
);
1212 if (eMarkType
!= SC_MARK_SIMPLE
&& eMarkType
!= SC_MARK_SIMPLE_FILTERED
)
1214 rSet
.DisableItem(nWhich
);
1216 else if (rDoc
.GetDPAtBlock(aDummy
))
1218 rSet
.DisableItem(nWhich
);
1221 rSet
.Put(SfxBoolItem(nWhich
, bAutoFilter
));
1225 rSet
.DisableItem(nWhich
);
1232 SCCOL nStartCol
, nEndCol
;
1233 SCROW nStartRow
, nEndRow
;
1234 SCTAB nStartTab
, nEndTab
;
1235 bool bAnyQuery
= false;
1237 bool bSelected
= (GetViewData().GetSimpleArea(
1238 nStartCol
, nStartRow
, nStartTab
, nEndCol
, nEndRow
, nEndTab
)
1243 if (nStartCol
==nEndCol
&& nStartRow
==nEndRow
)
1248 nStartCol
= GetViewData().GetCurX();
1249 nStartRow
= GetViewData().GetCurY();
1250 nStartTab
= GetViewData().GetTabNo();
1253 ScDBData
* pDBData
= bSelected
1254 ? rDoc
.GetDBAtArea( nStartTab
, nStartCol
, nStartRow
, nEndCol
, nEndRow
)
1255 : rDoc
.GetDBAtCursor( nStartCol
, nStartRow
, nStartTab
, ScDBDataPortion::AREA
);
1259 ScQueryParam aParam
;
1260 pDBData
->GetQueryParam( aParam
);
1261 if ( aParam
.GetEntry(0).bDoQuery
)
1266 rSet
.DisableItem( nWhich
);
1270 case SID_DEFINE_DBNAME
:
1272 if ( pDocSh
->IsDocShared() )
1274 rSet
.DisableItem( nWhich
);
1278 case SID_DATA_PROVIDER
:
1280 case SID_DATA_PROVIDER_REFRESH
:
1282 ScDocument
& rViewDoc
= GetViewData().GetDocument();
1283 auto& rDataMapper
= rViewDoc
.GetExternalDataMapper();
1284 if (rDataMapper
.getDataSources().empty())
1285 rSet
.DisableItem(nWhich
);
1288 case SID_DATA_STREAMS
:
1289 case SID_DATA_STREAMS_PLAY
:
1290 case SID_DATA_STREAMS_STOP
:
1292 if ( !officecfg::Office::Common::Misc::ExperimentalMode::get() )
1293 rSet
.DisableItem( nWhich
);
1296 case SID_TEXT_TO_COLUMNS
:
1299 if ( !lcl_GetTextToColumnsRange( rData
, aRange
, true ) )
1301 rSet
.DisableItem( nWhich
);
1305 case SID_MANAGE_XML_SOURCE
:
1308 nWhich
= aIter
.NextWhich();
1312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */