tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / view / cellsh2.cxx
blob38a2e62ac1777bba79aeb2b28c2dd1b5ec4d6c24
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 <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>
38 #include <cellsh.hxx>
39 #include <dbdata.hxx>
40 #include <queryparam.hxx>
41 #include <tabvwsh.hxx>
42 #include <sc.hrc>
43 #include <globstr.hrc>
44 #include <scresid.hxx>
45 #include <global.hxx>
46 #include <scmod.hxx>
47 #include <docsh.hxx>
48 #include <document.hxx>
49 #include <uiitems.hxx>
50 #include <dbdocfun.hxx>
51 #include <reffact.hxx>
52 #include <utility>
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>
60 #include <impex.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>
71 #include <memory>
73 using namespace com::sun::star;
75 static bool lcl_GetTextToColumnsRange( const ScViewData& rData, ScRange& rRange, bool bDoEmptyCheckOnly )
77 bool bRet = false;
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() )
87 bRet = true;
91 else
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 );
97 bRet = true;
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() ) )
108 bRet = false;
111 else if ( bRet )
113 rRange.PutInOrder();
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 );
119 if ( bShrunk )
121 rRange.aStart.SetRow( nStartRow );
122 rRange.aEnd.SetRow( nEndRow );
126 return bRet;
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;
136 bool bSort = true;
137 ScRange aExternalRange;
139 if( rSortParam.nCol1 != rSortParam.nCol2 )
140 eFillDir = DIR_LEFT;
141 if( rSortParam.nRow1 != rSortParam.nRow2 )
142 eFillDir = DIR_TOP;
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();
161 else
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() );
197 else
199 bSort = false;
200 rData.GetDocShell()->CancelAutoDBRange();
203 pTabViewShell->ClearHighlightRanges();
205 return bSort;
208 namespace
210 // this registers the dialog which Find1RefWindow search for
211 class ScValidationRegisteredDlg
213 std::shared_ptr<SfxDialogController> m_xDlg;
214 public:
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()
222 m_xDlg->Close();
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();
243 switch ( nSlotId )
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(
254 u"_beamer"_ustr,
255 frame::FrameSearchFlag::CHILDREN);
256 if ( xBeamerFrame.is() )
257 bWasOpen = true;
260 if ( bWasOpen )
262 // close database beamer: just forward to SfxViewFrame
264 rViewFrame.ExecuteSlot( rReq );
266 else
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
276 if (pDBData)
277 pDBData->GetImportParam( aImportParam );
279 ScDBDocFunc::ShowInBeamer( aImportParam, &pTabViewShell->GetViewFrame() );
281 rReq.Done(); // needed because it's a toggle slot
283 break;
285 case SID_REIMPORT_DATA:
287 bool bOk = false;
288 ScDBData* pDBData = pTabViewShell->GetDBData(true,SC_DB_OLD);
289 if (pDBData)
291 ScImportParam aImportParam;
292 pDBData->GetImportParam( aImportParam );
293 if (aImportParam.bImport && !pDBData->HasImportSelection())
295 pTabViewShell->ImportData( aImportParam );
296 pDBData->SetImportParam( aImportParam ); //! Undo ??
297 bOk = true;
301 if (!bOk && ! rReq.IsAPI() )
302 pTabViewShell->ErrorMessage(STR_REIMPORT_EMPTY);
304 if( bOk )
305 rReq.Done();
307 break;
309 case SID_REFRESH_DBAREA:
311 ScDBData* pDBData = pTabViewShell->GetDBData(true,SC_DB_OLD);
312 if (pDBData)
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)
325 ScRange aNewRange;
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
340 ScRange aRange;
341 pDBData->GetArea(aRange);
342 GetViewData().GetDocShell()->RefreshPivotTables(aRange);
345 rReq.Done();
347 break;
349 case SID_SBA_BRW_INSERT:
351 OSL_FAIL( "Deprecated Slot" );
353 break;
355 case SID_DATA_FORM:
357 ScViewData& rData = GetViewData();
358 ScRange aRange;
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);
366 break;
369 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
371 ScopedVclPtr<AbstractScDataFormDlg> pDlg(pFact->CreateScDataFormDlg(
372 pTabViewShell->GetFrameWeld(), pTabViewShell));
374 pDlg->Execute();
376 rReq.Done();
378 break;
380 case SID_SUBTOTALS:
381 ExecuteSubtotals(rReq);
382 break;
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
426 rReq.Done();
429 break;
431 case SID_SORT:
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() );
452 if( bHasHeader )
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 );
475 if ( nUserIndex )
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 );
504 rReq.Done();
507 else
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() );
522 if( bHasHeader )
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 ) );
588 aRequest.Done();
590 else
592 rData.GetDocShell()->CancelAutoDBRange();
596 pDlg->StartExecuteAsync(aContext);
600 break;
602 case SID_FILTER:
604 const SfxItemSet* pArgs = rReq.GetArgs();
605 if ( pArgs )
607 OSL_FAIL("SID_FILTER with arguments?");
608 pTabViewShell->Query(
609 pArgs->Get( SCITEM_QUERYDATA ).GetQueryData(), nullptr, true );
610 rReq.Done();
612 else
614 sal_uInt16 nId = ScFilterDlgWrapper::GetChildWindowId();
615 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
616 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
618 pScMod->SetRefDialog( nId, pWnd == nullptr );
621 break;
623 case SID_SPECIAL_FILTER:
625 const SfxItemSet* pArgs = rReq.GetArgs();
626 if ( pArgs )
628 OSL_FAIL("SID_SPECIAL_FILTER with arguments?");
629 pTabViewShell->Query(
630 pArgs->Get( SCITEM_QUERYDATA ).GetQueryData(), nullptr, true );
631 rReq.Done();
633 else
635 sal_uInt16 nId = ScSpecialFilterDlgWrapper::GetChildWindowId();
636 SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
637 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
639 pScMod->SetRefDialog( nId, pWnd == nullptr );
642 break;
644 case FID_FILTER_OK:
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,
654 // switch back:
656 if ( nCurTab != nRefTab )
658 pTabViewShell->SetTabNo( nRefTab );
659 pTabViewShell->PaintExtras();
662 ScRange aAdvSource;
663 if (pQueryItem->GetAdvancedQuerySource(aAdvSource))
664 pTabViewShell->Query( pQueryItem->GetQueryData(), &aAdvSource, true );
665 else
666 pTabViewShell->Query( pQueryItem->GetQueryData(), nullptr, true );
667 rReq.Done( *pReqArgs );
670 break;
672 case SID_UNFILTER:
674 ScQueryParam aParam;
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 );
683 rReq.Done();
685 break;
687 case SID_AUTO_FILTER:
688 pTabViewShell->ToggleAutoFilter();
689 rReq.Done();
690 break;
692 case SID_AUTOFILTER_HIDE:
693 pTabViewShell->HideAutoFilter();
694 rReq.Done();
695 break;
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,
707 // switch back:
709 if ( nCurTab != nRefTab )
711 pTabViewShell->SetTabNo( nRefTab );
712 pTabViewShell->PaintExtras();
715 const ScDPObject* pDPObject = pTabViewShell->GetDialogDPObject();
716 if ( pDPObject )
718 bool bSuccess = pTabViewShell->MakePivotTable(
719 pPItem->GetData(), pPItem->GetDestRange(), pPItem->IsNewSheet(), *pDPObject );
720 SfxBoolItem aRet(0, bSuccess);
721 rReq.SetReturnValue(aRet);
723 rReq.Done();
725 #if HAVE_FEATURE_SCRIPTING
726 else if (rReq.IsAPI())
727 SbxBase::SetError(ERRCODE_BASIC_BAD_PARAMETER);
728 #endif
730 break;
732 case SID_OPENDLG_PIVOTTABLE:
733 ExecuteDataPilotDialog();
734 break;
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 );
745 break;
747 case SID_SELECT_DB:
749 if ( pReqArgs )
751 const SfxStringItem& rItem = pReqArgs->Get(SID_SELECT_DB);
752 pTabViewShell->GotoDBArea(rItem.GetValue());
753 rReq.Done();
755 else
757 ScDocument& rDoc = GetViewData().GetDocument();
758 ScDBCollection* pDBCol = rDoc.GetDBCollection();
760 if ( pDBCol )
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(),
779 SID_SELECT_DB);
780 aRequest.AppendItem(SfxStringItem(SID_SELECT_DB, aName));
781 aRequest.Done();
784 pDlg->disposeOnce();
789 break;
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();
796 if (pStrm)
797 aDialog.Init(*pStrm);
799 if (aDialog.run() == RET_OK)
800 aDialog.StartStream();
802 break;
803 case SID_DATA_STREAMS_PLAY:
805 ScDocument& rDoc = GetViewData().GetDocument();
806 sc::DocumentLinkManager& rMgr = rDoc.GetDocLinkManager();
807 sc::DataStream* pStrm = rMgr.getDataStream();
808 if (pStrm)
809 pStrm->StartImport();
811 break;
812 case SID_DATA_STREAMS_STOP:
814 ScDocument& rDoc = GetViewData().GetDocument();
815 sc::DocumentLinkManager& rMgr = rDoc.GetDocLinkManager();
816 sc::DataStream* pStrm = rMgr.getDataStream();
817 if (pStrm)
818 pStrm->StopImport();
820 break;
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);
832 break;
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);
842 break;
843 case SID_MANAGE_XML_SOURCE:
844 ExecuteXMLSourceDialog();
845 break;
846 case FID_VALIDATION:
847 case FID_CURRENTVALIDATION:
849 const SfxItemSet* pArgs = rReq.GetArgs();
850 if ( pArgs )
852 OSL_FAIL("later...");
854 else
856 SfxItemSet aArgSet( GetPool(), ScTPValidationValue::GetRanges() );
857 ScValidationMode eMode = SC_VALID_ANY;
858 ScConditionMode eOper = ScConditionMode::Equal;
859 OUString aExpr1, aExpr2;
860 bool bBlank = true;
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();
876 if ( nIndex )
878 const ScValidationData* pOldData = rDoc.GetValidationEntry( nIndex );
879 if ( pOldData )
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 ) );
917 // cell range picker
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;
938 double nVal;
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);
943 else
944 aExpr1 = aTemp1;
946 else
947 aExpr1 = aTemp1;
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;
955 double nVal;
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);
960 else
961 aExpr2 = aTemp2;
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 );
976 else
977 aExpr2 = aTemp2;
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
1008 if (!bShowHelp)
1009 aData.ResetInput(); // reset only bShowInput
1011 aData.SetError(aErrTitle, aErrText, eErrStyle); // sets bShowError to TRUE
1012 if (!bShowError)
1013 aData.ResetError(); // reset only bShowError
1015 pTabViewShell->SetValidation( aData );
1016 pTabViewShell->TestHintWindow();
1017 rReq.Done( *pOutSet );
1021 break;
1023 case SID_TEXT_TO_COLUMNS:
1025 ScViewData& rData = GetViewData();
1026 ScRange aRange;
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 );
1043 aStream.Seek(0);
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 );
1064 aStream.Seek( 0 );
1065 aImport.ImportStream( aStream, OUString(), SotClipboardFormatId::STRING );
1067 pDocSh->GetUndoManager()->LeaveListAction();
1071 break;
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();
1090 while (nWhich)
1092 switch (nWhich)
1094 case SID_REFRESH_DBAREA:
1096 // imported data without selection
1097 // or filter,sort,subtotal (also without import)
1098 bool bOk = false;
1099 ScDBData* pDBData = pTabViewShell->GetDBData(false,SC_DB_OLD);
1100 if (pDBData && rDoc.GetChangeTrack() == nullptr)
1102 if ( pDBData->HasImportParam() )
1103 bOk = !pDBData->HasImportSelection();
1104 else
1106 bOk = pDBData->HasQueryParam() ||
1107 pDBData->HasSortParam() ||
1108 pDBData->HasSubTotalParam();
1111 if (!bOk)
1112 rSet.DisableItem( nWhich );
1114 break;
1116 case SID_FILTER:
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);
1124 else
1126 ScRange aDummy;
1127 ScMarkType eMarkType = GetViewData().GetSimpleArea(aDummy);
1128 if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED)
1130 rSet.DisableItem(nWhich);
1134 break;
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 );
1150 else
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);
1162 break;
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 );
1174 break;
1176 case SID_VIEW_DATA_SOURCE_BROWSER:
1178 if (!SvtModuleOptions().IsDataBaseInstalled())
1179 rSet.Put(SfxVisibilityItem(nWhich, false));
1180 else
1181 // get state (BoolItem) from SfxViewFrame
1182 pTabViewShell->GetViewFrame().GetSlotState( nWhich, nullptr, &rSet );
1184 break;
1185 case SID_SBA_BRW_INSERT:
1187 // SBA wants a sal_Bool-item, enabled
1189 rSet.Put(SfxBoolItem(nWhich, true));
1191 break;
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);
1201 else
1203 if (!bAutoFilterTested)
1205 bAutoFilter = rDoc.HasAutoFilter(nPosX, nPosY, nTab);
1206 bAutoFilterTested = true;
1208 if (nWhich == SID_AUTO_FILTER)
1210 ScRange aDummy;
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);
1220 else
1221 rSet.Put(SfxBoolItem(nWhich, bAutoFilter));
1223 else
1224 if (!bAutoFilter)
1225 rSet.DisableItem(nWhich);
1228 break;
1230 case SID_UNFILTER:
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 )
1239 == SC_MARK_SIMPLE);
1241 if ( bSelected )
1243 if (nStartCol==nEndCol && nStartRow==nEndRow)
1244 bSelected = false;
1246 else
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 );
1257 if ( pDBData )
1259 ScQueryParam aParam;
1260 pDBData->GetQueryParam( aParam );
1261 if ( aParam.GetEntry(0).bDoQuery )
1262 bAnyQuery = true;
1265 if ( !bAnyQuery )
1266 rSet.DisableItem( nWhich );
1268 break;
1270 case SID_DEFINE_DBNAME:
1272 if ( pDocSh->IsDocShared() )
1274 rSet.DisableItem( nWhich );
1277 break;
1278 case SID_DATA_PROVIDER:
1279 break;
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);
1287 break;
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 );
1295 break;
1296 case SID_TEXT_TO_COLUMNS:
1298 ScRange aRange;
1299 if ( !lcl_GetTextToColumnsRange( rData, aRange, true ) )
1301 rSet.DisableItem( nWhich );
1304 break;
1305 case SID_MANAGE_XML_SOURCE:
1306 break;
1308 nWhich = aIter.NextWhich();
1312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */