LibreOffice Module sc (master)  1
cellsh2.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <config_features.h>
21 
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>
34 
35 #include <com/sun/star/frame/FrameSearchFlag.hpp>
36 #include <com/sun/star/sheet/TableValidationVisibility.hpp>
37 
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 <validat.hxx>
53 #include <validate.hxx>
54 #include <datamapper.hxx>
55 
56 #include <scui_def.hxx>
57 #include <scabstdlg.hxx>
58 #include <impex.hxx>
59 #include <asciiopt.hxx>
60 #include <datastream.hxx>
61 #include <datastreamdlg.hxx>
62 #include <dataproviderdlg.hxx>
63 #include <queryentry.hxx>
64 #include <markdata.hxx>
65 #include <documentlinkmgr.hxx>
66 #include <officecfg/Office/Common.hxx>
67 
68 #include <o3tl/make_shared.hxx>
69 #include <memory>
70 
71 using namespace com::sun::star;
72 
73 static bool lcl_GetTextToColumnsRange( const ScViewData& rData, ScRange& rRange, bool bDoEmptyCheckOnly )
74 {
75  bool bRet = false;
76  const ScMarkData& rMark = rData.GetMarkData();
77 
78  if ( rMark.IsMarked() )
79  {
80  if ( !rMark.IsMultiMarked() )
81  {
82  rMark.GetMarkArea( rRange );
83  if ( rRange.aStart.Col() == rRange.aEnd.Col() )
84  {
85  bRet = true;
86  }
87  }
88  }
89  else
90  {
91  const SCCOL nCol = rData.GetCurX();
92  const SCROW nRow = rData.GetCurY();
93  const SCTAB nTab = rData.GetTabNo();
94  rRange = ScRange( nCol, nRow, nTab, nCol, nRow, nTab );
95  bRet = true;
96  }
97 
98  const ScDocument& rDoc = rData.GetDocument();
99 
100  if ( bDoEmptyCheckOnly )
101  {
102  if ( bRet && rDoc.IsBlockEmpty( rRange.aStart.Tab(), rRange.aStart.Col(),
103  rRange.aStart.Row(), rRange.aEnd.Col(),
104  rRange.aEnd.Row() ) )
105  {
106  bRet = false;
107  }
108  }
109  else if ( bRet )
110  {
111  rRange.PutInOrder();
112  SCCOL nStartCol = rRange.aStart.Col(), nEndCol = rRange.aEnd.Col();
113  SCROW nStartRow = rRange.aStart.Row(), nEndRow = rRange.aEnd.Row();
114  bool bShrunk = false;
115  rDoc.ShrinkToUsedDataArea( bShrunk, rRange.aStart.Tab(), nStartCol, nStartRow,
116  nEndCol, nEndRow, false, false, true );
117  if ( bShrunk )
118  {
119  rRange.aStart.SetRow( nStartRow );
120  rRange.aEnd.SetRow( nEndRow );
121  }
122  }
123 
124  return bRet;
125 }
126 
127 static bool lcl_GetSortParam( const ScViewData& rData, const ScSortParam& rSortParam )
128 {
129  ScTabViewShell* pTabViewShell = rData.GetViewShell();
130  ScDBData* pDBData = pTabViewShell->GetDBData();
131  ScDocument& rDoc = rData.GetDocument();
132  SCTAB nTab = rData.GetTabNo();
133  ScDirection eFillDir = DIR_TOP;
134  bool bSort = true;
135  ScRange aExternalRange;
136 
137  if( rSortParam.nCol1 != rSortParam.nCol2 )
138  eFillDir = DIR_LEFT;
139  if( rSortParam.nRow1 != rSortParam.nRow2 )
140  eFillDir = DIR_TOP;
141 
142  if( rSortParam.nRow2 == rDoc.MaxRow() )
143  {
144  // Assume that user selected entire column(s), but cater for the
145  // possibility that the start row is not the first row.
146  SCSIZE nCount = rDoc.GetEmptyLinesInBlock( rSortParam.nCol1, rSortParam.nRow1, nTab,
147  rSortParam.nCol2, rSortParam.nRow2, nTab, eFillDir );
148  aExternalRange = ScRange( rSortParam.nCol1,
149  ::std::min( rSortParam.nRow1 + sal::static_int_cast<SCROW>( nCount ), rDoc.MaxRow()), nTab,
150  rSortParam.nCol2, rSortParam.nRow2, nTab);
151  aExternalRange.PutInOrder();
152  }
153  else if (rSortParam.nCol1 != rSortParam.nCol2 || rSortParam.nRow1 != rSortParam.nRow2)
154  {
155  // Preserve a preselected area.
156  aExternalRange = ScRange( rSortParam.nCol1, rSortParam.nRow1, nTab, rSortParam.nCol2, rSortParam.nRow2, nTab);
157  aExternalRange.PutInOrder();
158  }
159  else
160  aExternalRange = ScRange( rData.GetCurX(), rData.GetCurY(), nTab );
161 
162  SCROW nStartRow = aExternalRange.aStart.Row();
163  SCCOL nStartCol = aExternalRange.aStart.Col();
164  SCROW nEndRow = aExternalRange.aEnd.Row();
165  SCCOL nEndCol = aExternalRange.aEnd.Col();
166  rDoc.GetDataArea( aExternalRange.aStart.Tab(), nStartCol, nStartRow, nEndCol, nEndRow, false, false );
167  aExternalRange.aStart.SetRow( nStartRow );
168  aExternalRange.aStart.SetCol( nStartCol );
169  aExternalRange.aEnd.SetRow( nEndRow );
170  aExternalRange.aEnd.SetCol( nEndCol );
171 
172  // with LibreOfficeKit, don't try to interact with the user
174  ((rSortParam.nCol1 == rSortParam.nCol2 && aExternalRange.aStart.Col() != aExternalRange.aEnd.Col()) ||
175  (rSortParam.nRow1 == rSortParam.nRow2 && aExternalRange.aStart.Row() != aExternalRange.aEnd.Row())))
176  {
177  pTabViewShell->AddHighlightRange( aExternalRange,COL_LIGHTBLUE );
178  OUString aExtendStr( aExternalRange.Format(rDoc, ScRefFlags::VALID));
179 
180  ScRange aCurrentRange( rSortParam.nCol1, rSortParam.nRow1, nTab, rSortParam.nCol2, rSortParam.nRow2, nTab );
181  OUString aCurrentStr(aCurrentRange.Format(rDoc, ScRefFlags::VALID));
182 
184 
185  ScopedVclPtr<AbstractScSortWarningDlg> pWarningDlg(pFact->CreateScSortWarningDlg(pTabViewShell->GetFrameWeld(), aExtendStr, aCurrentStr));
186  short bResult = pWarningDlg->Execute();
187  if( bResult == BTN_EXTEND_RANGE || bResult == BTN_CURRENT_SELECTION )
188  {
189  if( bResult == BTN_EXTEND_RANGE )
190  {
191  pTabViewShell->MarkRange( aExternalRange, false );
192  pDBData->SetArea( nTab, aExternalRange.aStart.Col(), aExternalRange.aStart.Row(), aExternalRange.aEnd.Col(), aExternalRange.aEnd.Row() );
193  }
194  }
195  else
196  {
197  bSort = false;
198  rData.GetDocShell()->CancelAutoDBRange();
199  }
200 
201  pTabViewShell->ClearHighlightRanges();
202  }
203  return bSort;
204 }
205 
206 namespace
207 {
208  // this registers the dialog which Find1RefWindow search for
209  class ScValidationRegisteredDlg
210  {
211  std::shared_ptr<SfxDialogController> m_xDlg;
212  public:
213  ScValidationRegisteredDlg(weld::Window* pParent, const std::shared_ptr<SfxDialogController>& rDlg)
214  : m_xDlg(rDlg)
215  {
216  SC_MOD()->RegisterRefController(static_cast<sal_uInt16>(ScValidationDlg::SLOTID), m_xDlg, pParent);
217  }
218  ~ScValidationRegisteredDlg()
219  {
220  m_xDlg->Close();
221  SC_MOD()->UnregisterRefController(static_cast<sal_uInt16>(ScValidationDlg::SLOTID), m_xDlg);
222  }
223  };
224 }
225 
227 {
228  ScTabViewShell* pTabViewShell = GetViewData().GetViewShell();
229  sal_uInt16 nSlotId = rReq.GetSlot();
230  const SfxItemSet* pReqArgs = rReq.GetArgs();
231  ScModule* pScMod = SC_MOD();
232 
233  pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
234 
235  if ( GetViewData().HasEditView( GetViewData().GetActivePart() ) )
236  {
237  pScMod->InputEnterHandler();
238  pTabViewShell->UpdateInputHandler();
239  }
240 
241  switch ( nSlotId )
242  {
243  case SID_VIEW_DATA_SOURCE_BROWSER:
244  {
245  // check if database beamer is open
246 
247  SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame();
248  bool bWasOpen = false;
249  {
250  uno::Reference<frame::XFrame> xFrame = pViewFrame->GetFrame().GetFrameInterface();
251  uno::Reference<frame::XFrame> xBeamerFrame = xFrame->findFrame(
252  "_beamer",
253  frame::FrameSearchFlag::CHILDREN);
254  if ( xBeamerFrame.is() )
255  bWasOpen = true;
256  }
257 
258  if ( bWasOpen )
259  {
260  // close database beamer: just forward to SfxViewFrame
261 
262  pViewFrame->ExecuteSlot( rReq );
263  }
264  else
265  {
266  // show database beamer: SfxViewFrame call must be synchronous
267 
268  pViewFrame->ExecuteSlot( rReq, false ); // false = synchronous
269 
270  // select current database in database beamer
271 
272  ScImportParam aImportParam;
273  ScDBData* pDBData = pTabViewShell->GetDBData(true,SC_DB_OLD); // don't create if none found
274  if (pDBData)
275  pDBData->GetImportParam( aImportParam );
276 
277  ScDBDocFunc::ShowInBeamer( aImportParam, pTabViewShell->GetViewFrame() );
278  }
279  rReq.Done(); // needed because it's a toggle slot
280  }
281  break;
282 
283  case SID_REIMPORT_DATA:
284  {
285  bool bOk = false;
286  ScDBData* pDBData = pTabViewShell->GetDBData(true,SC_DB_OLD);
287  if (pDBData)
288  {
289  ScImportParam aImportParam;
290  pDBData->GetImportParam( aImportParam );
291  if (aImportParam.bImport && !pDBData->HasImportSelection())
292  {
293  pTabViewShell->ImportData( aImportParam );
294  pDBData->SetImportParam( aImportParam );
295  bOk = true;
296  }
297  }
298 
299  if (!bOk && ! rReq.IsAPI() )
300  pTabViewShell->ErrorMessage(STR_REIMPORT_EMPTY);
301 
302  if( bOk )
303  rReq.Done();
304  }
305  break;
306 
307  case SID_REFRESH_DBAREA:
308  {
309  ScDBData* pDBData = pTabViewShell->GetDBData(true,SC_DB_OLD);
310  if (pDBData)
311  {
312  // repeat import like SID_REIMPORT_DATA
313 
314  bool bContinue = true;
315  ScImportParam aImportParam;
316  pDBData->GetImportParam( aImportParam );
317  if (aImportParam.bImport && !pDBData->HasImportSelection())
318  {
319  bContinue = pTabViewShell->ImportData( aImportParam );
320  pDBData->SetImportParam( aImportParam );
321 
322  // mark (size may have been changed)
323  ScRange aNewRange;
324  pDBData->GetArea(aNewRange);
325  pTabViewShell->MarkRange(aNewRange);
326  }
327 
328  if ( bContinue ) // fail at import -> break
329  {
330  // internal operations, when any stored
331 
332  if ( pDBData->HasQueryParam() || pDBData->HasSortParam() ||
333  pDBData->HasSubTotalParam() )
334  pTabViewShell->RepeatDB();
335 
336  // pivot tables that have the range as data source
337 
338  ScRange aRange;
339  pDBData->GetArea(aRange);
340  GetViewData().GetDocShell()->RefreshPivotTables(aRange);
341  }
342  }
343  rReq.Done();
344  }
345  break;
346 
347  case SID_SBA_BRW_INSERT:
348  {
349  OSL_FAIL( "Deprecated Slot" );
350  }
351  break;
352 
353  case SID_DATA_FORM:
354  {
356 
358  pTabViewShell->GetFrameWeld(), pTabViewShell));
359 
360  pDlg->Execute();
361 
362  rReq.Done();
363  }
364  break;
365 
366  case SID_SUBTOTALS:
367  ExecuteSubtotals(rReq);
368  break;
369 
370  case SID_SORT_DESCENDING:
371  case SID_SORT_ASCENDING:
372  {
373  //#i60401 ux-ctest: Calc does not support all users' strategies regarding sorting data
374  //the patch comes from maoyg
375  ScSortParam aSortParam;
376  ScDBData* pDBData = pTabViewShell->GetDBData();
377  ScViewData& rData = GetViewData();
378 
379  pDBData->GetSortParam( aSortParam );
380 
381  if( lcl_GetSortParam( rData, aSortParam ) )
382  {
383  SCCOL nCol = GetViewData().GetCurX();
384  SCCOL nTab = GetViewData().GetTabNo();
385  ScDocument& rDoc = GetViewData().GetDocument();
386 
387  pDBData->GetSortParam( aSortParam );
388  bool bHasHeader = rDoc.HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, nTab );
389 
390  if( nCol < aSortParam.nCol1 )
391  nCol = aSortParam.nCol1;
392  else if( nCol > aSortParam.nCol2 )
393  nCol = aSortParam.nCol2;
394 
395  aSortParam.bHasHeader = bHasHeader;
396  aSortParam.bByRow = true;
397  aSortParam.bCaseSens = false;
398  aSortParam.bNaturalSort = false;
399  aSortParam.aDataAreaExtras.mbCellNotes = false;
400  aSortParam.aDataAreaExtras.mbCellDrawObjects = true;
401  aSortParam.aDataAreaExtras.mbCellFormats = true;
402  aSortParam.bInplace = true;
403  aSortParam.maKeyState[0].bDoSort = true;
404  aSortParam.maKeyState[0].nField = nCol;
405  aSortParam.maKeyState[0].bAscending = ( nSlotId == SID_SORT_ASCENDING );
406 
407  for ( sal_uInt16 i=1; i<aSortParam.GetSortKeyCount(); i++ )
408  aSortParam.maKeyState[i].bDoSort = false;
409 
410  pTabViewShell->UISort( aSortParam ); // subtotal when needed new
411 
412  rReq.Done();
413  }
414  }
415  break;
416 
417  case SID_SORT:
418  {
419  const SfxItemSet* pArgs = rReq.GetArgs();
420 
421  //#i60401 ux-ctest: Calc does not support all users' strategies regarding sorting data
422  //the patch comes from maoyg
423 
424  if ( pArgs ) // Basic
425  {
426  ScSortParam aSortParam;
427  ScDBData* pDBData = pTabViewShell->GetDBData();
428  ScViewData& rData = GetViewData();
429 
430  pDBData->GetSortParam( aSortParam );
431 
432  if( lcl_GetSortParam( rData, aSortParam ) )
433  {
434  ScDocument& rDoc = GetViewData().GetDocument();
435 
436  pDBData->GetSortParam( aSortParam );
437  bool bHasHeader = rDoc.HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, rData.GetTabNo() );
438  if( bHasHeader )
439  aSortParam.bHasHeader = bHasHeader;
440 
441  aSortParam.bInplace = true; // from Basic always
442 
443  const SfxPoolItem* pItem;
444  if ( pArgs->GetItemState( SID_SORT_BYROW, true, &pItem ) == SfxItemState::SET )
445  aSortParam.bByRow = static_cast<const SfxBoolItem*>(pItem)->GetValue();
446  if ( pArgs->GetItemState( SID_SORT_HASHEADER, true, &pItem ) == SfxItemState::SET )
447  aSortParam.bHasHeader = static_cast<const SfxBoolItem*>(pItem)->GetValue();
448  if ( pArgs->GetItemState( SID_SORT_CASESENS, true, &pItem ) == SfxItemState::SET )
449  aSortParam.bCaseSens = static_cast<const SfxBoolItem*>(pItem)->GetValue();
450  if ( pArgs->GetItemState( SID_SORT_NATURALSORT, true, &pItem ) == SfxItemState::SET )
451  aSortParam.bNaturalSort = static_cast<const SfxBoolItem*>(pItem)->GetValue();
452  if ( pArgs->GetItemState( SID_SORT_INCCOMMENTS, true, &pItem ) == SfxItemState::SET )
453  aSortParam.aDataAreaExtras.mbCellNotes = static_cast<const SfxBoolItem*>(pItem)->GetValue();
454  if ( pArgs->GetItemState( SID_SORT_INCIMAGES, true, &pItem ) == SfxItemState::SET )
455  aSortParam.aDataAreaExtras.mbCellDrawObjects = static_cast<const SfxBoolItem*>(pItem)->GetValue();
456  if ( pArgs->GetItemState( SID_SORT_ATTRIBS, true, &pItem ) == SfxItemState::SET )
457  aSortParam.aDataAreaExtras.mbCellFormats = static_cast<const SfxBoolItem*>(pItem)->GetValue();
458  if ( pArgs->GetItemState( SID_SORT_USERDEF, true, &pItem ) == SfxItemState::SET )
459  {
460  sal_uInt16 nUserIndex = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
461  aSortParam.bUserDef = ( nUserIndex != 0 );
462  if ( nUserIndex )
463  aSortParam.nUserIndex = nUserIndex - 1; // Basic: 1-based
464  }
465 
466  SCCOLROW nField0 = 0;
467  if ( pArgs->GetItemState( FN_PARAM_1, true, &pItem ) == SfxItemState::SET )
468  nField0 = static_cast<const SfxInt32Item*>(pItem)->GetValue();
469  aSortParam.maKeyState[0].bDoSort = ( nField0 != 0 );
470  aSortParam.maKeyState[0].nField = nField0 > 0 ? (nField0-1) : 0;
471  if ( pArgs->GetItemState( FN_PARAM_2, true, &pItem ) == SfxItemState::SET )
472  aSortParam.maKeyState[0].bAscending = static_cast<const SfxBoolItem*>(pItem)->GetValue();
473  SCCOLROW nField1 = 0;
474  if ( pArgs->GetItemState( FN_PARAM_3, true, &pItem ) == SfxItemState::SET )
475  nField1 = static_cast<const SfxInt32Item*>(pItem)->GetValue();
476  aSortParam.maKeyState[1].bDoSort = ( nField1 != 0 );
477  aSortParam.maKeyState[1].nField = nField1 > 0 ? (nField1-1) : 0;
478  if ( pArgs->GetItemState( FN_PARAM_4, true, &pItem ) == SfxItemState::SET )
479  aSortParam.maKeyState[1].bAscending = static_cast<const SfxBoolItem*>(pItem)->GetValue();
480  SCCOLROW nField2 = 0;
481  if ( pArgs->GetItemState( FN_PARAM_5, true, &pItem ) == SfxItemState::SET )
482  nField2 = static_cast<const SfxInt32Item*>(pItem)->GetValue();
483  aSortParam.maKeyState[2].bDoSort = ( nField2 != 0 );
484  aSortParam.maKeyState[2].nField = nField2 > 0 ? (nField2-1) : 0;
485  if ( pArgs->GetItemState( FN_PARAM_6, true, &pItem ) == SfxItemState::SET )
486  aSortParam.maKeyState[2].bAscending = static_cast<const SfxBoolItem*>(pItem)->GetValue();
487 
488  // subtotal when needed new
489  pTabViewShell->UISort( aSortParam );
490  rReq.Done();
491  }
492  }
493  else
494  {
495  ScSortParam aSortParam;
496  ScDBData* pDBData = pTabViewShell->GetDBData();
497  ScViewData& rData = GetViewData();
498 
499  pDBData->GetSortParam( aSortParam );
500 
501  if( lcl_GetSortParam( rData, aSortParam ) )
502  {
503  ScDocument& rDoc = GetViewData().GetDocument();
505 
506  pDBData->GetSortParam( aSortParam );
507  bool bHasHeader = rDoc.HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, rData.GetTabNo() );
508  if( bHasHeader )
509  aSortParam.bHasHeader = bHasHeader;
510 
511  aArgSet.Put( ScSortItem( SCITEM_SORTDATA, &GetViewData(), &aSortParam ) );
512 
514  std::shared_ptr<ScAsyncTabController> pDlg(pFact->CreateScSortDlg(pTabViewShell->GetFrameWeld(), &aArgSet));
515  pDlg->SetCurPageId("criteria"); // 1=sort field tab 2=sort options tab
516 
518  aContext.maEndDialogFn = [pDlg, &rData, pTabViewShell](sal_Int32 nResult)
519  {
520  if ( nResult == RET_OK )
521  {
522  const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
523  const ScSortParam& rOutParam = static_cast<const ScSortItem&>(
524  pOutSet->Get( SCITEM_SORTDATA )).GetSortData();
525 
526  // subtotal when needed new
527 
528  pTabViewShell->UISort( rOutParam );
529  }
530  else
531  {
532  rData.GetDocShell()->CancelAutoDBRange();
533  }
534  };
535 
536  pDlg->StartExecuteAsync(aContext);
537  }
538  }
539  }
540  break;
541 
542  case SID_FILTER:
543  {
544  const SfxItemSet* pArgs = rReq.GetArgs();
545  if ( pArgs )
546  {
547  OSL_FAIL("SID_FILTER with arguments?");
548  pTabViewShell->Query( static_cast<const ScQueryItem&>(
549  pArgs->Get( SCITEM_QUERYDATA )).GetQueryData(), nullptr, true );
550  rReq.Done();
551  }
552  else
553  {
554  sal_uInt16 nId = ScFilterDlgWrapper::GetChildWindowId();
555  SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
556  SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
557 
558  pScMod->SetRefDialog( nId, pWnd == nullptr );
559  }
560  }
561  break;
562 
563  case SID_SPECIAL_FILTER:
564  {
565  const SfxItemSet* pArgs = rReq.GetArgs();
566  if ( pArgs )
567  {
568  OSL_FAIL("SID_SPECIAL_FILTER with arguments?");
569  pTabViewShell->Query( static_cast<const ScQueryItem&>(
570  pArgs->Get( SCITEM_QUERYDATA )).GetQueryData(), nullptr, true );
571  rReq.Done();
572  }
573  else
574  {
575  sal_uInt16 nId = ScSpecialFilterDlgWrapper::GetChildWindowId();
576  SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
577  SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
578 
579  pScMod->SetRefDialog( nId, pWnd == nullptr );
580  }
581  }
582  break;
583 
584  case FID_FILTER_OK:
585  {
586  const SfxPoolItem* pItem;
587  if ( pReqArgs && SfxItemState::SET ==
588  pReqArgs->GetItemState( SCITEM_QUERYDATA, true, &pItem ) )
589  {
590  const ScQueryItem& rQueryItem = static_cast<const ScQueryItem&>(*pItem);
591 
592  SCTAB nCurTab = GetViewData().GetTabNo();
593  SCTAB nRefTab = GetViewData().GetRefTabNo();
594 
595  // If RefInput switched to a different sheet from the data sheet,
596  // switch back:
597 
598  if ( nCurTab != nRefTab )
599  {
600  pTabViewShell->SetTabNo( nRefTab );
601  pTabViewShell->PaintExtras();
602  }
603 
604  ScRange aAdvSource;
605  if (rQueryItem.GetAdvancedQuerySource(aAdvSource))
606  pTabViewShell->Query( rQueryItem.GetQueryData(), &aAdvSource, true );
607  else
608  pTabViewShell->Query( rQueryItem.GetQueryData(), nullptr, true );
609  rReq.Done( *pReqArgs );
610  }
611  }
612  break;
613 
614  case SID_UNFILTER:
615  {
616  ScQueryParam aParam;
617  ScDBData* pDBData = pTabViewShell->GetDBData();
618 
619  pDBData->GetQueryParam( aParam );
620  SCSIZE nEC = aParam.GetEntryCount();
621  for (SCSIZE i=0; i<nEC; i++)
622  aParam.GetEntry(i).bDoQuery = false;
623  aParam.bDuplicate = true;
624  pTabViewShell->Query( aParam, nullptr, true );
625  rReq.Done();
626  }
627  break;
628 
629  case SID_AUTO_FILTER:
630  pTabViewShell->ToggleAutoFilter();
631  rReq.Done();
632  break;
633 
634  case SID_AUTOFILTER_HIDE:
635  pTabViewShell->HideAutoFilter();
636  rReq.Done();
637  break;
638 
639  case SID_PIVOT_TABLE:
640  {
641  const SfxPoolItem* pItem;
642  if ( pReqArgs && SfxItemState::SET ==
643  pReqArgs->GetItemState( SCITEM_PIVOTDATA, true, &pItem ) )
644  {
645  SCTAB nCurTab = GetViewData().GetTabNo();
646  SCTAB nRefTab = GetViewData().GetRefTabNo();
647 
648  // If RefInput switched to a different sheet from the data sheet,
649  // switch back:
650 
651  if ( nCurTab != nRefTab )
652  {
653  pTabViewShell->SetTabNo( nRefTab );
654  pTabViewShell->PaintExtras();
655  }
656 
657  const ScDPObject* pDPObject = pTabViewShell->GetDialogDPObject();
658  if ( pDPObject )
659  {
660  const ScPivotItem* pPItem = static_cast<const ScPivotItem*>(pItem);
661  bool bSuccess = pTabViewShell->MakePivotTable(
662  pPItem->GetData(), pPItem->GetDestRange(), pPItem->IsNewSheet(), *pDPObject );
663  SfxBoolItem aRet(0, bSuccess);
664  rReq.SetReturnValue(aRet);
665  }
666  rReq.Done();
667  }
668 #if HAVE_FEATURE_SCRIPTING
669  else if (rReq.IsAPI())
671 #endif
672  }
673  break;
674 
675  case SID_OPENDLG_PIVOTTABLE:
676  ExecuteDataPilotDialog();
677  break;
678  case SID_DEFINE_DBNAME:
679  {
680 
681  sal_uInt16 nId = ScDbNameDlgWrapper::GetChildWindowId();
682  SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
683  SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
684 
685  pScMod->SetRefDialog( nId, pWnd == nullptr );
686 
687  }
688  break;
689 
690  case SID_SELECT_DB:
691  {
692  if ( pReqArgs )
693  {
694  const SfxStringItem& rItem
695  = static_cast<const SfxStringItem&>(pReqArgs->Get(SID_SELECT_DB));
696  pTabViewShell->GotoDBArea(rItem.GetValue());
697  rReq.Done();
698  }
699  else
700  {
701  ScDocument& rDoc = GetViewData().GetDocument();
702  ScDBCollection* pDBCol = rDoc.GetDBCollection();
703 
704  if ( pDBCol )
705  {
706  std::vector<OUString> aList;
707  const ScDBCollection::NamedDBs& rDBs = pDBCol->getNamedDBs();
708  for (const auto& rxDB : rDBs)
709  aList.push_back(rxDB->GetName());
710 
712 
713  ScopedVclPtr<AbstractScSelEntryDlg> pDlg(pFact->CreateScSelEntryDlg(pTabViewShell->GetFrameWeld(), aList));
714  if ( pDlg->Execute() == RET_OK )
715  {
716  OUString aName = pDlg->GetSelectedEntry();
717  pTabViewShell->GotoDBArea( aName );
718  rReq.AppendItem( SfxStringItem( SID_SELECT_DB, aName ) );
719  rReq.Done();
720  }
721  }
722  }
723  }
724  break;
725  case SID_DATA_STREAMS:
726  {
727  sc::DataStreamDlg aDialog(GetViewData().GetDocShell(), pTabViewShell->GetFrameWeld());
728  ScDocument& rDoc = GetViewData().GetDocument();
729  sc::DocumentLinkManager& rMgr = rDoc.GetDocLinkManager();
730  sc::DataStream* pStrm = rMgr.getDataStream();
731  if (pStrm)
732  aDialog.Init(*pStrm);
733 
734  if (aDialog.run() == RET_OK)
735  aDialog.StartStream();
736  }
737  break;
738  case SID_DATA_STREAMS_PLAY:
739  {
740  ScDocument& rDoc = GetViewData().GetDocument();
742  sc::DataStream* pStrm = rMgr.getDataStream();
743  if (pStrm)
744  pStrm->StartImport();
745  }
746  break;
747  case SID_DATA_STREAMS_STOP:
748  {
749  ScDocument& rDoc = GetViewData().GetDocument();
751  sc::DataStream* pStrm = rMgr.getDataStream();
752  if (pStrm)
753  pStrm->StopImport();
754  }
755  break;
756  case SID_DATA_PROVIDER:
757  {
758  auto xDoc = o3tl::make_shared<ScDocument>();
759  xDoc->InsertTab(0, "test");
760  ScDocument& rDoc = GetViewData().GetDocument();
761  ScDataProviderDlg aDialog(pTabViewShell->GetDialogParent(), xDoc, &rDoc);
762  if (aDialog.run() == RET_OK)
763  {
764  aDialog.import(rDoc);
765  }
766  }
767  break;
768  case SID_DATA_PROVIDER_REFRESH:
769  {
770  ScDocument& rDoc = GetViewData().GetDocument();
771  auto& rDataMapper = rDoc.GetExternalDataMapper();
772  for (auto& rDataSource : rDataMapper.getDataSources())
773  {
774  rDataSource.refresh(&rDoc, false);
775  }
776  }
777  break;
778  case SID_MANAGE_XML_SOURCE:
779  ExecuteXMLSourceDialog();
780  break;
781  case FID_VALIDATION:
782  case FID_CURRENTVALIDATION:
783  {
784  const SfxPoolItem* pItem;
785  const SfxItemSet* pArgs = rReq.GetArgs();
786  if ( pArgs )
787  {
788  OSL_FAIL("later...");
789  }
790  else
791  {
792  SfxItemSet aArgSet( GetPool(), ScTPValidationValue::GetRanges() );
795  OUString aExpr1, aExpr2;
796  bool bBlank = true;
797  sal_Int16 nListType = css::sheet::TableValidationVisibility::UNSORTED;
798  bool bShowHelp = false;
799  OUString aHelpTitle, aHelpText;
800  bool bShowError = false;
801  ScValidErrorStyle eErrStyle = SC_VALERR_STOP;
802  OUString aErrTitle, aErrText;
803 
804  ScDocument& rDoc = GetViewData().GetDocument();
805  SCCOL nCurX = GetViewData().GetCurX();
806  SCROW nCurY = GetViewData().GetCurY();
807  SCTAB nTab = GetViewData().GetTabNo();
808  ScAddress aCursorPos( nCurX, nCurY, nTab );
809  sal_uLong nIndex = rDoc.GetAttr(
810  nCurX, nCurY, nTab, ATTR_VALIDDATA )->GetValue();
811  if ( nIndex )
812  {
813  const ScValidationData* pOldData = rDoc.GetValidationEntry( nIndex );
814  if ( pOldData )
815  {
816  eMode = pOldData->GetDataMode();
817  eOper = pOldData->GetOperation();
818  sal_uInt32 nNumFmt = 0;
819  if ( eMode == SC_VALID_DATE || eMode == SC_VALID_TIME )
820  {
821  SvNumFormatType nType = ( eMode == SC_VALID_DATE ) ? SvNumFormatType::DATE
822  : SvNumFormatType::TIME;
823  nNumFmt = rDoc.GetFormatTable()->GetStandardFormat(
824  nType, ScGlobal::eLnge );
825  }
826  aExpr1 = pOldData->GetExpression( aCursorPos, 0, nNumFmt );
827  aExpr2 = pOldData->GetExpression( aCursorPos, 1, nNumFmt );
828  bBlank = pOldData->IsIgnoreBlank();
829  nListType = pOldData->GetListType();
830 
831  bShowHelp = pOldData->GetInput( aHelpTitle, aHelpText );
832  bShowError = pOldData->GetErrMsg( aErrTitle, aErrText, eErrStyle );
833 
834  aArgSet.Put( SfxUInt16Item( FID_VALID_MODE, sal::static_int_cast<sal_uInt16>(eMode) ) );
835  aArgSet.Put( SfxUInt16Item( FID_VALID_CONDMODE, sal::static_int_cast<sal_uInt16>(eOper) ) );
836  aArgSet.Put( SfxStringItem( FID_VALID_VALUE1, aExpr1 ) );
837  aArgSet.Put( SfxStringItem( FID_VALID_VALUE2, aExpr2 ) );
838  aArgSet.Put( SfxBoolItem( FID_VALID_BLANK, bBlank ) );
839  aArgSet.Put( SfxInt16Item( FID_VALID_LISTTYPE, nListType ) );
840  aArgSet.Put( SfxBoolItem( FID_VALID_SHOWHELP, bShowHelp ) );
841  aArgSet.Put( SfxStringItem( FID_VALID_HELPTITLE, aHelpTitle ) );
842  aArgSet.Put( SfxStringItem( FID_VALID_HELPTEXT, aHelpText ) );
843  aArgSet.Put( SfxBoolItem( FID_VALID_SHOWERR, bShowError ) );
844  aArgSet.Put( SfxUInt16Item( FID_VALID_ERRSTYLE, sal::static_int_cast<sal_uInt16>(eErrStyle) ) );
845  aArgSet.Put( SfxStringItem( FID_VALID_ERRTITLE, aErrTitle ) );
846  aArgSet.Put( SfxStringItem( FID_VALID_ERRTEXT, aErrText ) );
847  }
848  }
849 
850  // cell range picker
851  vcl::Window* pWin = GetViewData().GetActiveWin();
852  weld::Window* pParentWin = pWin ? pWin->GetFrameWeld() : nullptr;
853  auto xDlg = std::make_shared<ScValidationDlg>(pParentWin, &aArgSet, pTabViewShell);
854  ScValidationRegisteredDlg aRegisterThatDlgExists(pParentWin, xDlg);
855 
856  short nResult = xDlg->run();
857  if ( nResult == RET_OK )
858  {
859  const SfxItemSet* pOutSet = xDlg->GetOutputItemSet();
860 
861  if ( pOutSet->GetItemState( FID_VALID_MODE, true, &pItem ) == SfxItemState::SET )
862  eMode = static_cast<ScValidationMode>(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
863  if ( pOutSet->GetItemState( FID_VALID_CONDMODE, true, &pItem ) == SfxItemState::SET )
864  eOper = static_cast<ScConditionMode>(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
865  if ( pOutSet->GetItemState( FID_VALID_VALUE1, true, &pItem ) == SfxItemState::SET )
866  {
867  OUString aTemp1 = static_cast<const SfxStringItem*>(pItem)->GetValue();
868  if (eMode == SC_VALID_DATE || eMode == SC_VALID_TIME)
869  {
870  sal_uInt32 nNumIndex = 0;
871  double nVal;
872  if (rDoc.GetFormatTable()->IsNumberFormat(aTemp1, nNumIndex, nVal))
873  aExpr1 = ::rtl::math::doubleToUString( nVal,
874  rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
876  else
877  aExpr1 = aTemp1;
878  }
879  else
880  aExpr1 = aTemp1;
881  }
882  if ( pOutSet->GetItemState( FID_VALID_VALUE2, true, &pItem ) == SfxItemState::SET )
883  {
884  OUString aTemp2 = static_cast<const SfxStringItem*>(pItem)->GetValue();
885  if (eMode == SC_VALID_DATE || eMode == SC_VALID_TIME)
886  {
887  sal_uInt32 nNumIndex = 0;
888  double nVal;
889  if (rDoc.GetFormatTable()->IsNumberFormat(aTemp2, nNumIndex, nVal))
890  aExpr2 = ::rtl::math::doubleToUString( nVal,
891  rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
893  else
894  aExpr2 = aTemp2;
895  if ( eMode == SC_VALID_TIME ) {
896  sal_Int32 wraparound = aExpr1.compareTo(aExpr2);
897  if (wraparound > 0) {
898  if (eOper == ScConditionMode::Between) {
900  OUString tmp = aExpr1;
901  aExpr1 = aExpr2;
902  aExpr2 = tmp;
903  }
904  else if (eOper == ScConditionMode::NotBetween) {
905  eOper = ScConditionMode::Between;
906  OUString tmp = aExpr1;
907  aExpr1 = aExpr2;
908  aExpr2 = tmp;
909  }
910  }
911  }
912  }
913  else
914  aExpr2 = aTemp2;
915  }
916  if ( pOutSet->GetItemState( FID_VALID_BLANK, true, &pItem ) == SfxItemState::SET )
917  bBlank = static_cast<const SfxBoolItem*>(pItem)->GetValue();
918  if ( pOutSet->GetItemState( FID_VALID_LISTTYPE, true, &pItem ) == SfxItemState::SET )
919  nListType = static_cast<const SfxInt16Item*>(pItem)->GetValue();
920 
921  if ( pOutSet->GetItemState( FID_VALID_SHOWHELP, true, &pItem ) == SfxItemState::SET )
922  bShowHelp = static_cast<const SfxBoolItem*>(pItem)->GetValue();
923  if ( pOutSet->GetItemState( FID_VALID_HELPTITLE, true, &pItem ) == SfxItemState::SET )
924  aHelpTitle = static_cast<const SfxStringItem*>(pItem)->GetValue();
925  if ( pOutSet->GetItemState( FID_VALID_HELPTEXT, true, &pItem ) == SfxItemState::SET )
926  aHelpText = static_cast<const SfxStringItem*>(pItem)->GetValue();
927 
928  if ( pOutSet->GetItemState( FID_VALID_SHOWERR, true, &pItem ) == SfxItemState::SET )
929  bShowError = static_cast<const SfxBoolItem*>(pItem)->GetValue();
930  if ( pOutSet->GetItemState( FID_VALID_ERRSTYLE, true, &pItem ) == SfxItemState::SET )
931  eErrStyle = static_cast<ScValidErrorStyle>(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
932  if ( pOutSet->GetItemState( FID_VALID_ERRTITLE, true, &pItem ) == SfxItemState::SET )
933  aErrTitle = static_cast<const SfxStringItem*>(pItem)->GetValue();
934  if ( pOutSet->GetItemState( FID_VALID_ERRTEXT, true, &pItem ) == SfxItemState::SET )
935  aErrText = static_cast<const SfxStringItem*>(pItem)->GetValue();
936 
937  ScValidationData aData( eMode, eOper, aExpr1, aExpr2, rDoc, aCursorPos );
938  aData.SetIgnoreBlank( bBlank );
939  aData.SetListType( nListType );
940 
941  aData.SetInput(aHelpTitle, aHelpText); // sets bShowInput to TRUE
942  if (!bShowHelp)
943  aData.ResetInput(); // reset only bShowInput
944 
945  aData.SetError(aErrTitle, aErrText, eErrStyle); // sets bShowError to TRUE
946  if (!bShowError)
947  aData.ResetError(); // reset only bShowError
948 
949  pTabViewShell->SetValidation( aData );
950  pTabViewShell->TestHintWindow();
951  rReq.Done( *pOutSet );
952  }
953  }
954  }
955  break;
956 
957  case SID_TEXT_TO_COLUMNS:
958  {
959  ScViewData& rData = GetViewData();
960  ScRange aRange;
961 
962  if ( lcl_GetTextToColumnsRange( rData, aRange, false ) )
963  {
964  ScDocument& rDoc = rData.GetDocument();
965 
966  ScImportExport aExport( rDoc, aRange );
968 
969  // #i87703# text to columns fails with tab separator
970  aExport.SetDelimiter( u'\0' );
971 
972  SvMemoryStream aStream;
973  aStream.SetStreamCharSet( RTL_TEXTENCODING_UNICODE );
975  aExport.ExportStream( aStream, OUString(), SotClipboardFormatId::STRING );
976 
979  pTabViewShell->GetFrameWeld(), OUString(), &aStream, SC_TEXTTOCOLUMNS));
980 
981  if ( pDlg->Execute() == RET_OK )
982  {
983  ScDocShell* pDocSh = rData.GetDocShell();
984  OSL_ENSURE( pDocSh, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDocSh is null!" );
985 
986  OUString aUndo = ScResId( STR_UNDO_TEXTTOCOLUMNS );
987  pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo, 0, rData.GetViewShell()->GetViewShellId() );
988 
989  ScImportExport aImport( rDoc, aRange.aStart );
990  ScAsciiOptions aOptions;
991  pDlg->GetOptions( aOptions );
992  pDlg->SaveParameters();
993  aImport.SetExtOptions( aOptions );
994  aImport.SetApi( false );
995  aImport.SetImportBroadcast( true );
996  aImport.SetOverwriting( true );
997  aStream.Seek( 0 );
998  aImport.ImportStream( aStream, OUString(), SotClipboardFormatId::STRING );
999 
1000  pDocSh->GetUndoManager()->LeaveListAction();
1001  }
1002  }
1003  }
1004  break;
1005  }
1006 }
1007 
1009 {
1010  ScTabViewShell* pTabViewShell = GetViewData().GetViewShell();
1011  ScViewData& rData = GetViewData();
1012  ScDocShell* pDocSh = rData.GetDocShell();
1013  ScDocument& rDoc = pDocSh->GetDocument();
1014  SCCOL nPosX = rData.GetCurX();
1015  SCROW nPosY = rData.GetCurY();
1016  SCTAB nTab = rData.GetTabNo();
1017 
1018  bool bAutoFilter = false;
1019  bool bAutoFilterTested = false;
1020 
1021  SfxWhichIter aIter(rSet);
1022  sal_uInt16 nWhich = aIter.FirstWhich();
1023  while (nWhich)
1024  {
1025  switch (nWhich)
1026  {
1027  case SID_REFRESH_DBAREA:
1028  {
1029  // imported data without selection
1030  // or filter,sort,subtotal (also without import)
1031  bool bOk = false;
1032  ScDBData* pDBData = pTabViewShell->GetDBData(false,SC_DB_OLD);
1033  if (pDBData && rDoc.GetChangeTrack() == nullptr)
1034  {
1035  if ( pDBData->HasImportParam() )
1036  bOk = !pDBData->HasImportSelection();
1037  else
1038  {
1039  bOk = pDBData->HasQueryParam() ||
1040  pDBData->HasSortParam() ||
1041  pDBData->HasSubTotalParam();
1042  }
1043  }
1044  if (!bOk)
1045  rSet.DisableItem( nWhich );
1046  }
1047  break;
1048 
1049  case SID_FILTER:
1050  case SID_SPECIAL_FILTER:
1051  {
1052  ScRange aDummy;
1053  ScMarkType eMarkType = GetViewData().GetSimpleArea( aDummy);
1054  if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED)
1055  {
1056  rSet.DisableItem( nWhich );
1057  }
1058  }
1059  break;
1060 
1061  //in case of Redlining and multiselection disable
1062  case SID_SORT_ASCENDING:
1063  case SID_SORT_DESCENDING:
1064  case SCITEM_SORTDATA:
1065  case SCITEM_SUBTDATA:
1066  case SID_OPENDLG_PIVOTTABLE:
1067  {
1069 
1070  if ( pDocSh->IsReadOnly() || rDoc.GetChangeTrack()!=nullptr ||
1071  GetViewData().IsMultiMarked() )
1072  {
1073  rSet.DisableItem( nWhich );
1074  }
1075  }
1076  break;
1077 
1078  case SID_REIMPORT_DATA:
1079  {
1080  // only imported data without selection
1081  ScDBData* pDBData = pTabViewShell->GetDBData(false,SC_DB_OLD);
1082  if (!pDBData || !pDBData->HasImportParam() || pDBData->HasImportSelection() ||
1083  rDoc.GetChangeTrack()!=nullptr)
1084  {
1085  rSet.DisableItem( nWhich );
1086  }
1087  }
1088  break;
1089 
1090  case SID_VIEW_DATA_SOURCE_BROWSER:
1091  {
1092  if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::DATABASE))
1093  rSet.Put(SfxVisibilityItem(nWhich, false));
1094  else
1095  // get state (BoolItem) from SfxViewFrame
1096  pTabViewShell->GetViewFrame()->GetSlotState( nWhich, nullptr, &rSet );
1097  }
1098  break;
1099  case SID_SBA_BRW_INSERT:
1100  {
1101  // SBA wants a sal_Bool-item, enabled
1102 
1103  rSet.Put(SfxBoolItem(nWhich, true));
1104  }
1105  break;
1106 
1107  case SID_AUTO_FILTER:
1108  case SID_AUTOFILTER_HIDE:
1109  {
1110  if (!bAutoFilterTested)
1111  {
1112  bAutoFilter = rDoc.HasAutoFilter( nPosX, nPosY, nTab );
1113  bAutoFilterTested = true;
1114  }
1115  if ( nWhich == SID_AUTO_FILTER )
1116  {
1117  ScRange aDummy;
1118  ScMarkType eMarkType = GetViewData().GetSimpleArea( aDummy);
1119  if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED)
1120  {
1121  rSet.DisableItem( nWhich );
1122  }
1123  else if (rDoc.GetDPAtBlock(aDummy))
1124  {
1125  rSet.DisableItem( nWhich );
1126  }
1127  else
1128  rSet.Put( SfxBoolItem( nWhich, bAutoFilter ) );
1129  }
1130  else
1131  if (!bAutoFilter)
1132  rSet.DisableItem( nWhich );
1133  }
1134  break;
1135 
1136  case SID_UNFILTER:
1137  {
1138  SCCOL nStartCol, nEndCol;
1139  SCROW nStartRow, nEndRow;
1140  SCTAB nStartTab, nEndTab;
1141  bool bAnyQuery = false;
1142 
1143  bool bSelected = (GetViewData().GetSimpleArea(
1144  nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab )
1145  == SC_MARK_SIMPLE);
1146 
1147  if ( bSelected )
1148  {
1149  if (nStartCol==nEndCol && nStartRow==nEndRow)
1150  bSelected = false;
1151  }
1152  else
1153  {
1154  nStartCol = GetViewData().GetCurX();
1155  nStartRow = GetViewData().GetCurY();
1156  nStartTab = GetViewData().GetTabNo();
1157  }
1158 
1159  ScDBData* pDBData = bSelected
1160  ? rDoc.GetDBAtArea( nStartTab, nStartCol, nStartRow, nEndCol, nEndRow )
1161  : rDoc.GetDBAtCursor( nStartCol, nStartRow, nStartTab, ScDBDataPortion::AREA );
1162 
1163  if ( pDBData )
1164  {
1165  ScQueryParam aParam;
1166  pDBData->GetQueryParam( aParam );
1167  if ( aParam.GetEntry(0).bDoQuery )
1168  bAnyQuery = true;
1169  }
1170 
1171  if ( !bAnyQuery )
1172  rSet.DisableItem( nWhich );
1173  }
1174  break;
1175 
1176  case SID_DEFINE_DBNAME:
1177  {
1178  if ( pDocSh->IsDocShared() )
1179  {
1180  rSet.DisableItem( nWhich );
1181  }
1182  }
1183  break;
1184  case SID_DATA_PROVIDER:
1185  break;
1186  case SID_DATA_PROVIDER_REFRESH:
1187  {
1188  ScDocument& rViewDoc = GetViewData().GetDocument();
1189  auto& rDataMapper = rViewDoc.GetExternalDataMapper();
1190  if (rDataMapper.getDataSources().empty())
1191  rSet.DisableItem(nWhich);
1192  }
1193  break;
1194  case SID_DATA_STREAMS:
1195  case SID_DATA_STREAMS_PLAY:
1196  case SID_DATA_STREAMS_STOP:
1197  {
1198  if ( !officecfg::Office::Common::Misc::ExperimentalMode::get() )
1199  rSet.DisableItem( nWhich );
1200  }
1201  break;
1202  case SID_TEXT_TO_COLUMNS:
1203  {
1204  ScRange aRange;
1205  if ( !lcl_GetTextToColumnsRange( rData, aRange, true ) )
1206  {
1207  rSet.DisableItem( nWhich );
1208  }
1209  }
1210  break;
1211  case SID_MANAGE_XML_SOURCE:
1212  break;
1213  }
1214  nWhich = aIter.NextWhich();
1215  }
1216 }
1217 
1218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3108
const SfxPoolItem * ExecuteSlot(SfxRequest &rReq, const SfxInterface *pIF=nullptr)
::std::vector< ScSortKeyState > maKeyState
Definition: sortparam.hxx:121
void TestHintWindow()
Definition: tabview3.cxx:779
SfxViewFrame * GetViewFrame() const
virtual VclPtr< AbstractScSelEntryDlg > CreateScSelEntryDlg(weld::Window *pParent, const std::vector< OUString > &rEntryList)=0
sal_uInt16 nUserIndex
Definition: sortparam.hxx:110
SC_DLLPUBLIC bool HasColHeader(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab)
Definition: documen3.cxx:1532
sal_Int32 nIndex
SC_DLLPUBLIC bool HasQueryParam() const
Definition: dbdata.cxx:524
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
Definition: document.hxx:814
ScDBData * GetDBData(bool bMarkArea=true, ScGetDBMode eMode=SC_DB_MAKE, ScGetDBSelection eSel=ScGetDBSelection::Keep)
Definition: dbfunc.cxx:81
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:353
ScAddress aStart
Definition: address.hxx:499
const ScDPObject * GetDialogDPObject() const
Definition: tabvwsh.hxx:280
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:42
void SetExtOptions(const ScAsciiOptions &rOpt)
Definition: impex.cxx:201
SfxChildWindow * GetChildWindow(sal_uInt16)
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:89
void ErrorMessage(TranslateId pGlobStrId)
Definition: tabview2.cxx:1413
SCROW Row() const
Definition: address.hxx:261
bool MakePivotTable(const ScDPSaveData &rData, const ScRange &rDest, bool bNewTable, const ScDPObject &rSource)
Definition: dbfunc3.cxx:621
std::string GetValue
bool PaintExtras()
Definition: tabview3.cxx:2759
SC_DLLPUBLIC void GetSortParam(ScSortParam &rSortParam) const
Definition: dbdata.cxx:401
void MarkRange(const ScRange &rRange, bool bSetCursor=true, bool bContinue=false)
Definition: tabview3.cxx:1687
void SetApi(bool bApi)
Definition: impex.hxx:155
ScValidErrorStyle
Definition: validat.hxx:50
sal_uIntPtr sal_uLong
These options control how multi-line cells are converted during export in certain lossy formats (such...
Definition: impex.hxx:35
Reference< XFrame > xFrame
void StartImport()
Definition: datastream.cxx:377
virtual void GetOptions(ScAsciiOptions &rOpt)=0
SCROW GetCurY() const
Definition: viewdata.hxx:401
don't create
Definition: global.hxx:396
void SetValidation(const ScValidationData &rNew)
Definition: viewfun2.cxx:3415
void GotoDBArea(const OUString &rDBName)
Definition: dbfunc.cxx:54
#define BTN_EXTEND_RANGE
Definition: scui_def.hxx:65
sal_Int16 nId
sal_uInt16 FirstWhich()
bool IsNewSheet() const
Definition: uiitems.hxx:239
const ContentProperties & rData
SC_DLLPUBLIC const ScDBData * GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const
Definition: documen3.cxx:338
sal_uInt64 Seek(sal_uInt64 nPos)
SCTAB GetTabNo() const
Definition: viewdata.hxx:394
static void ShowInBeamer(const ScImportParam &rParam, const SfxViewFrame *pFrame)
Definition: dbdocimp.cxx:72
bool ImportData(const ScImportParam &rParam)
Definition: dbfunc.cxx:433
ScAddress aEnd
Definition: address.hxx:500
void Done(bool bRemove=false)
ScDocument & GetDocument() const
Definition: viewdata.hxx:379
void ExecuteDB(SfxRequest &rReq)
Definition: cellsh2.cxx:226
void AddHighlightRange(const ScRange &rRange, const Color &rColor)
Definition: tabview3.cxx:2523
bool HasSubTotalParam() const
Definition: dbdata.cxx:542
#define SCITEM_SUBTDATA
Definition: scitems.hxx:91
const SfxItemSet * GetArgs() const
sc::DocumentLinkManager & GetDocLinkManager()
Definition: documen2.cxx:228
virtual short Execute()=0
ScConditionMode GetOperation() const
Definition: conditio.hxx:369
bool ImportStream(SvStream &, const OUString &rBaseURL, SotClipboardFormatId)
Definition: impex.cxx:379
#define SCITEM_QUERYDATA
Definition: scitems.hxx:90
bool HasAutoFilter(SCCOL nCol, SCROW nRow, SCTAB nTab)
Definition: documen3.cxx:1500
SC_DLLPUBLIC void InputEnterHandler(ScEnterMode nBlockMode=ScEnterMode::NORMAL)
Definition: scmod.cxx:1359
sal_uInt16 NextWhich()
bool mbCellDrawObjects
If TRUE, consider the presence of draw objects anchored to the cell.
Definition: sortparam.hxx:48
void GetMarkArea(ScRange &rRange) const
Definition: markdata.cxx:111
SC_DLLPUBLIC const ScValidationData * GetValidationEntry(sal_uLong nIndex) const
Definition: documen4.cxx:882
virtual SfxUndoManager * GetUndoManager() override
Definition: docsh.cxx:2927
void SetListType(sal_Int16 nListType)
Definition: validat.hxx:117
weld::Window * GetFrameWeld() const
#define BTN_CURRENT_SELECTION
Definition: scui_def.hxx:66
static SC_DLLPUBLIC const LocaleDataWrapper & getLocaleData()
Definition: global.cxx:1007
void SetImportParam(const ScImportParam &rImportParam)
Definition: dbdata.cxx:490
const ScRange & GetDestRange() const
Definition: uiitems.hxx:238
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:872
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
Definition: address.hxx:44
sal_Int32 SCCOLROW
a type capable of holding either SCCOL or SCROW
Definition: types.hxx:23
bool IsMultiMarked() const
Definition: markdata.hxx:82
bool bNaturalSort
Definition: sortparam.hxx:114
SfxFrame & GetFrame() const
int nCount
SC_DLLPUBLIC SCSIZE GetEntryCount() const
Definition: queryparam.cxx:120
SC_DLLPUBLIC sc::ExternalDataMapper & GetExternalDataMapper()
SC_DLLPUBLIC void SetRefDialog(sal_uInt16 nId, bool bVis, SfxViewFrame *pViewFrm=nullptr)
Reference dialogs.
Definition: scmod.cxx:1467
void SetInput(const OUString &rTitle, const OUString &rMsg)
Definition: validat.cxx:161
SC_DLLPUBLIC const ScQueryEntry & GetEntry(SCSIZE n) const
Definition: queryparam.cxx:125
bool IsDocShared() const
ScConditionMode
Definition: conditio.hxx:60
Mode eMode
void UpdateInputHandler(bool bForce=false, bool bStopEditing=true)
Definition: tabvwsha.cxx:653
SCTAB Tab() const
Definition: address.hxx:270
void SetRow(SCROW nRowP)
Definition: address.hxx:274
void ClearHighlightRanges()
Definition: tabview3.cxx:2533
void SetCol(SCCOL nColP)
Definition: address.hxx:278
ScValidationMode
Definition: validat.hxx:38
ScChangeTrack * GetChangeTrack() const
Definition: document.hxx:2405
bool ShrinkToUsedDataArea(bool &o_bShrunk, SCTAB nTab, SCCOL &rStartCol, SCROW &rStartRow, SCCOL &rEndCol, SCROW &rEndRow, bool bColumnsOnly, bool bStickyTopRow=false, bool bStickyLeftCol=false, ScDataAreaExtras *pDataAreaExtras=nullptr) const
Shrink a range to only include used data area.
Definition: document.cxx:1063
SC_DLLPUBLIC const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt16 nWhich) const
Definition: document.cxx:4745
static void SetError(ErrCode)
ScValidationMode GetDataMode() const
Definition: validat.hxx:114
bool mbCellNotes
If TRUE, consider the presence of cell notes besides data.
Definition: sortparam.hxx:46
static bool lcl_GetSortParam(const ScViewData &rData, const ScSortParam &rSortParam)
Definition: cellsh2.cxx:127
constexpr OUStringLiteral aData
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:356
void SetArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
Definition: dbdata.cxx:322
constexpr TypedWhichId< SfxUInt32Item > ATTR_VALIDDATA(153)
void GetDBState(SfxItemSet &rSet)
Definition: cellsh2.cxx:1008
SC_DLLPUBLIC void GetDataArea(SCTAB nTab, SCCOL &rStartCol, SCROW &rStartRow, SCCOL &rEndCol, SCROW &rEndRow, bool bIncludeOld, bool bOnlyDown) const
Return the smallest area containing at least all contiguous cells having data.
Definition: document.cxx:1088
const OUString & getNumDecimalSep() const
#define SCITEM_SORTDATA
Definition: scitems.hxx:89
void RepeatDB(bool bRecord=true)
Definition: dbfunc3.cxx:2115
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:441
bool IsMarked() const
Definition: markdata.hxx:81
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
int i
const SfxPoolItem * GetSlotState(sal_uInt16 nSlotId, const SfxInterface *pIF=nullptr, SfxItemSet *pStateSet=nullptr)
void import(ScDocument &rDoc, bool bInternal=false)
ScMarkType
States GetSimpleArea() returns for the underlying selection marks, so the caller can react if the res...
Definition: viewdata.hxx:60
OUString GetExpression(const ScAddress &rCursor, sal_uInt16 nPos, sal_uInt32 nNumFmt=0, const formula::FormulaGrammar::Grammar eGrammar=formula::FormulaGrammar::GRAM_DEFAULT) const
Definition: conditio.cxx:1240
sal_Int16 SCCOL
Definition: types.hxx:21
virtual OUString GetSelectedEntry() const =0
#define SC_MOD()
Definition: scmod.hxx:250
bool HasSortParam() const
Definition: dbdata.cxx:535
OUString Format(const ScDocument &rDocument, ScRefFlags nFlags=ScRefFlags::ZERO, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1, bool bFullAddressNotation=false) const
Returns string with formatted cell range from aStart to aEnd, according to provided address conventio...
Definition: address.cxx:2212
const OUString & GetValue() const
SC_DLLPUBLIC void SetTabNo(SCTAB nTab, bool bNew=false, bool bExtendSelection=false, bool bSameTabButMoved=false)
Definition: tabview3.cxx:1798
virtual VclPtr< AbstractScDataFormDlg > CreateScDataFormDlg(weld::Window *pParent, ScTabViewShell *pTabViewShell)=0
float u
bool IsNumberFormat(const OUString &sString, sal_uInt32 &F_Index, double &fOutNumber, SvNumInputOptions eInputOptions=SvNumInputOptions::NONE)
ScDPObject * GetDPAtBlock(const ScRange &rBlock) const
Definition: documen3.cxx:391
void GetImportParam(ScImportParam &rImportParam) const
Definition: dbdata.cxx:480
SvNumFormatType
void SetOverwriting(const bool bOverwriting)
Definition: impex.hxx:157
void SetIgnoreBlank(bool bSet)
Definition: conditio.cxx:418
bool bCaseSens
Definition: sortparam.hxx:113
const ScQueryParam & GetQueryData() const
Definition: uiitems.cxx:214
bool IsBlockEmpty(SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, bool bIgnoreNotes=false) const
Definition: document.cxx:5322
static SC_DLLPUBLIC LanguageType eLnge
Definition: global.hxx:553
bool GetAdvancedQuerySource(ScRange &rSource) const
Definition: uiitems.cxx:219
bool ExportStream(SvStream &, const OUString &rBaseURL, SotClipboardFormatId)
Definition: impex.cxx:419
void GetArea(SCTAB &rTab, SCCOL &rCol1, SCROW &rRow1, SCCOL &rCol2, SCROW &rRow2) const
Definition: dbdata.cxx:300
SfxViewShell * GetViewShell() const
ScDataAreaExtras aDataAreaExtras
Definition: sortparam.hxx:109
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
SCCOL Col() const
Definition: address.hxx:266
bool IsReadOnly() const
size_t LeaveListAction()
std::function< void(sal_Int32)> maEndDialogFn
void SetReturnValue(const SfxPoolItem &)
#define ERRCODE_BASIC_BAD_PARAMETER
bool GetErrMsg(OUString &rTitle, OUString &rMsg, ScValidErrorStyle &rStyle) const
Definition: validat.cxx:177
Stores global named database ranges.
Definition: dbdata.hxx:234
SC_DLLPUBLIC SCSIZE GetEmptyLinesInBlock(SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, ScDirection eDir)
Definition: document.cxx:6097
bool mbCellFormats
If TRUE, consider the presence of cell formats.
Definition: sortparam.hxx:50
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_Int32 SCROW
Definition: types.hxx:17
sal_uInt16 GetSlot() const
void PutInOrder()
Definition: address.cxx:1582
void SetImportBroadcast(bool b)
Definition: impex.hxx:156
void ResetInput()
Definition: validat.cxx:151
void DisableItem(sal_uInt16 nWhich)
bool bHasHeader
Definition: sortparam.hxx:111
weld::Window * GetFrameWeld() const
virtual VclPtr< AbstractScImportAsciiDlg > CreateScImportAsciiDlg(weld::Window *pParent, const OUString &aDatName, SvStream *pInStream, ScImportAsciiCall eCall)=0
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
sal_uInt16 GetSortKeyCount() const
Definition: sortparam.hxx:139
OUString aName
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
Definition: scabstdlg.cxx:37
sal_uInt32 GetStandardFormat(SvNumFormatType eType, LanguageType eLnge=LANGUAGE_DONTKNOW)
void ToggleAutoFilter()
Definition: dbfunc.cxx:276
bool GetInput(OUString &rTitle, OUString &rMsg) const
Definition: validat.hxx:108
RET_OK
void SetExportTextOptions(const ScExportTextOptions &options)
Definition: impex.hxx:158
void SetError(const OUString &rTitle, const OUString &rMsg, ScValidErrorStyle eStyle)
Definition: validat.cxx:168
void SetStreamCharSet(rtl_TextEncoding eCharSet)
void HideAutoFilter()
Definition: dbfunc.cxx:396
virtual void EnterListAction(const OUString &rComment, const OUString &rRepeatComment, sal_uInt16 nId, ViewShellId nViewShellId)
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
const ScDocument & GetDocument() const
Definition: docsh.hxx:220
sal_Int16 GetListType() const
Definition: validat.hxx:116
SC_DLLPUBLIC void GetQueryParam(ScQueryParam &rQueryParam) const
Definition: dbdata.cxx:424
bool HasImportSelection() const
Definition: dbdata.hxx:201
bool bImport
Definition: global.hxx:455
void CancelAutoDBRange()
Definition: docsh5.cxx:368
DataStream * getDataStream()
NamedDBs & getNamedDBs()
Definition: dbdata.hxx:315
void HideListBox()
Definition: tabview3.cxx:2968
void UISort(const ScSortParam &rSortParam)
Definition: dbfunc.cxx:186
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_LIGHTBLUE
#define SCITEM_PIVOTDATA
Definition: scitems.hxx:93
void SetDelimiter(sal_Unicode c)
Definition: impex.hxx:131
void AppendItem(const SfxPoolItem &)
virtual std::shared_ptr< ScAsyncTabController > CreateScSortDlg(weld::Window *pParent, const SfxItemSet *pArgSet)=0
ScDirection
Definition: global.hxx:352
bool IsAPI() const
SC_DLLPUBLIC void Query(const ScQueryParam &rQueryParam, const ScRange *pAdvSource, bool bRecord)
Definition: dbfunc.cxx:234
bool IsIgnoreBlank() const
Definition: conditio.hxx:371
const ScDBData * GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, ScDBDataPortion ePortion) const
Definition: documen3.cxx:322
virtual void SaveParameters()=0
static void SetNoEndianSwap(SvStream &rStrm)
only if stream is only used in own (!) memory
Definition: impex.cxx:571
const ScDPSaveData & GetData() const
Definition: uiitems.hxx:237
void ResetError()
Definition: validat.cxx:156
weld::Window * GetDialogParent()
parent window for dialogs Problem: OLE Server!
Definition: tabvwshd.cxx:31
bool HasImportParam() const
Definition: dbdata.cxx:519
static const WhichRangesContainer & GetRanges()
Definition: validate.hxx:84
sal_Int16 SCTAB
Definition: types.hxx:22
static bool lcl_GetTextToColumnsRange(const ScViewData &rData, ScRange &rRange, bool bDoEmptyCheckOnly)
Definition: cellsh2.cxx:73
SCCOL GetCurX() const
Definition: viewdata.hxx:400
ViewShellId GetViewShellId() const override