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  rRange = rMark.GetMarkArea();
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.Col(), rRange.aStart.Row(),
103  rRange.aEnd.Col(), rRange.aEnd.Row(),
104  rRange.aStart.Tab() ) )
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  if ( const SfxBoolItem* pItem = pArgs->GetItemIfSet( SID_SORT_BYROW ) )
444  aSortParam.bByRow = pItem->GetValue();
445  if ( const SfxBoolItem* pItem = pArgs->GetItemIfSet( SID_SORT_HASHEADER ) )
446  aSortParam.bHasHeader = pItem->GetValue();
447  if ( const SfxBoolItem* pItem = pArgs->GetItemIfSet( SID_SORT_CASESENS ) )
448  aSortParam.bCaseSens = pItem->GetValue();
449  if ( const SfxBoolItem* pItem = pArgs->GetItemIfSet( SID_SORT_NATURALSORT ) )
450  aSortParam.bNaturalSort = pItem->GetValue();
451  if ( const SfxBoolItem* pItem = pArgs->GetItemIfSet( SID_SORT_INCCOMMENTS ) )
452  aSortParam.aDataAreaExtras.mbCellNotes = pItem->GetValue();
453  if ( const SfxBoolItem* pItem = pArgs->GetItemIfSet( SID_SORT_INCIMAGES ) )
454  aSortParam.aDataAreaExtras.mbCellDrawObjects = pItem->GetValue();
455  if ( const SfxBoolItem* pItem = pArgs->GetItemIfSet( SID_SORT_ATTRIBS ) )
456  aSortParam.aDataAreaExtras.mbCellFormats = pItem->GetValue();
457  if ( const SfxUInt16Item* pItem = pArgs->GetItemIfSet( SID_SORT_USERDEF ) )
458  {
459  sal_uInt16 nUserIndex = pItem->GetValue();
460  aSortParam.bUserDef = ( nUserIndex != 0 );
461  if ( nUserIndex )
462  aSortParam.nUserIndex = nUserIndex - 1; // Basic: 1-based
463  }
464 
465  SCCOLROW nField0 = 0;
466  const SfxPoolItem* pItem = nullptr;
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 =
524  pOutSet->Get( SCITEM_SORTDATA ).GetSortData();
525 
526  // subtotal when needed new
527 
528  pTabViewShell->UISort( rOutParam );
529 
530  SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
531  if (pViewFrm)
532  {
533  SfxRequest aRequest(pViewFrm, SID_SORT);
534 
535  if ( rOutParam.bInplace )
536  {
537  aRequest.AppendItem( SfxBoolItem( SID_SORT_BYROW,
538  rOutParam.bByRow ) );
539  aRequest.AppendItem( SfxBoolItem( SID_SORT_HASHEADER,
540  rOutParam.bHasHeader ) );
541  aRequest.AppendItem( SfxBoolItem( SID_SORT_CASESENS,
542  rOutParam.bCaseSens ) );
543  aRequest.AppendItem( SfxBoolItem( SID_SORT_NATURALSORT,
544  rOutParam.bNaturalSort ) );
545  aRequest.AppendItem( SfxBoolItem( SID_SORT_INCCOMMENTS,
546  rOutParam.aDataAreaExtras.mbCellNotes ) );
547  aRequest.AppendItem( SfxBoolItem( SID_SORT_INCIMAGES,
548  rOutParam.aDataAreaExtras.mbCellDrawObjects ) );
549  aRequest.AppendItem( SfxBoolItem( SID_SORT_ATTRIBS,
550  rOutParam.aDataAreaExtras.mbCellFormats ) );
551  sal_uInt16 nUser = rOutParam.bUserDef ? ( rOutParam.nUserIndex + 1 ) : 0;
552  aRequest.AppendItem( SfxUInt16Item( SID_SORT_USERDEF, nUser ) );
553  if ( rOutParam.maKeyState[0].bDoSort )
554  {
555  aRequest.AppendItem( SfxInt32Item( FN_PARAM_1,
556  rOutParam.maKeyState[0].nField + 1 ) );
557  aRequest.AppendItem( SfxBoolItem( FN_PARAM_2,
558  rOutParam.maKeyState[0].bAscending ) );
559  }
560  if ( rOutParam.maKeyState[1].bDoSort )
561  {
562  aRequest.AppendItem( SfxInt32Item( FN_PARAM_3,
563  rOutParam.maKeyState[1].nField + 1 ) );
564  aRequest.AppendItem( SfxBoolItem( FN_PARAM_4,
565  rOutParam.maKeyState[1].bAscending ) );
566  }
567  if ( rOutParam.maKeyState[2].bDoSort )
568  {
569  aRequest.AppendItem( SfxInt32Item( FN_PARAM_5,
570  rOutParam.maKeyState[2].nField + 1 ) );
571  aRequest.AppendItem( SfxBoolItem( FN_PARAM_6,
572  rOutParam.maKeyState[2].bAscending ) );
573  }
574  }
575 
576  aRequest.Done();
577  }
578  }
579  else
580  {
581  rData.GetDocShell()->CancelAutoDBRange();
582  }
583  };
584 
585  pDlg->StartExecuteAsync(aContext);
586  }
587  }
588  }
589  break;
590 
591  case SID_FILTER:
592  {
593  const SfxItemSet* pArgs = rReq.GetArgs();
594  if ( pArgs )
595  {
596  OSL_FAIL("SID_FILTER with arguments?");
597  pTabViewShell->Query(
598  pArgs->Get( SCITEM_QUERYDATA ).GetQueryData(), nullptr, true );
599  rReq.Done();
600  }
601  else
602  {
603  sal_uInt16 nId = ScFilterDlgWrapper::GetChildWindowId();
604  SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
605  SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
606 
607  pScMod->SetRefDialog( nId, pWnd == nullptr );
608  }
609  }
610  break;
611 
612  case SID_SPECIAL_FILTER:
613  {
614  const SfxItemSet* pArgs = rReq.GetArgs();
615  if ( pArgs )
616  {
617  OSL_FAIL("SID_SPECIAL_FILTER with arguments?");
618  pTabViewShell->Query(
619  pArgs->Get( SCITEM_QUERYDATA ).GetQueryData(), nullptr, true );
620  rReq.Done();
621  }
622  else
623  {
624  sal_uInt16 nId = ScSpecialFilterDlgWrapper::GetChildWindowId();
625  SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
626  SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
627 
628  pScMod->SetRefDialog( nId, pWnd == nullptr );
629  }
630  }
631  break;
632 
633  case FID_FILTER_OK:
634  {
635  const ScQueryItem* pQueryItem;
636  if ( pReqArgs && (pQueryItem =
637  pReqArgs->GetItemIfSet( SCITEM_QUERYDATA )) )
638  {
639  SCTAB nCurTab = GetViewData().GetTabNo();
640  SCTAB nRefTab = GetViewData().GetRefTabNo();
641 
642  // If RefInput switched to a different sheet from the data sheet,
643  // switch back:
644 
645  if ( nCurTab != nRefTab )
646  {
647  pTabViewShell->SetTabNo( nRefTab );
648  pTabViewShell->PaintExtras();
649  }
650 
651  ScRange aAdvSource;
652  if (pQueryItem->GetAdvancedQuerySource(aAdvSource))
653  pTabViewShell->Query( pQueryItem->GetQueryData(), &aAdvSource, true );
654  else
655  pTabViewShell->Query( pQueryItem->GetQueryData(), nullptr, true );
656  rReq.Done( *pReqArgs );
657  }
658  }
659  break;
660 
661  case SID_UNFILTER:
662  {
663  ScQueryParam aParam;
664  ScDBData* pDBData = pTabViewShell->GetDBData();
665 
666  pDBData->GetQueryParam( aParam );
667  SCSIZE nEC = aParam.GetEntryCount();
668  for (SCSIZE i=0; i<nEC; i++)
669  aParam.GetEntry(i).bDoQuery = false;
670  aParam.bDuplicate = true;
671  pTabViewShell->Query( aParam, nullptr, true );
672  rReq.Done();
673  }
674  break;
675 
676  case SID_AUTO_FILTER:
677  pTabViewShell->ToggleAutoFilter();
678  rReq.Done();
679  break;
680 
681  case SID_AUTOFILTER_HIDE:
682  pTabViewShell->HideAutoFilter();
683  rReq.Done();
684  break;
685 
686  case SID_PIVOT_TABLE:
687  {
688  const ScPivotItem* pPItem;
689  if ( pReqArgs && (pPItem =
690  pReqArgs->GetItemIfSet( SCITEM_PIVOTDATA )) )
691  {
692  SCTAB nCurTab = GetViewData().GetTabNo();
693  SCTAB nRefTab = GetViewData().GetRefTabNo();
694 
695  // If RefInput switched to a different sheet from the data sheet,
696  // switch back:
697 
698  if ( nCurTab != nRefTab )
699  {
700  pTabViewShell->SetTabNo( nRefTab );
701  pTabViewShell->PaintExtras();
702  }
703 
704  const ScDPObject* pDPObject = pTabViewShell->GetDialogDPObject();
705  if ( pDPObject )
706  {
707  bool bSuccess = pTabViewShell->MakePivotTable(
708  pPItem->GetData(), pPItem->GetDestRange(), pPItem->IsNewSheet(), *pDPObject );
709  SfxBoolItem aRet(0, bSuccess);
710  rReq.SetReturnValue(aRet);
711  }
712  rReq.Done();
713  }
714 #if HAVE_FEATURE_SCRIPTING
715  else if (rReq.IsAPI())
717 #endif
718  }
719  break;
720 
721  case SID_OPENDLG_PIVOTTABLE:
722  ExecuteDataPilotDialog();
723  break;
724  case SID_DEFINE_DBNAME:
725  {
726 
727  sal_uInt16 nId = ScDbNameDlgWrapper::GetChildWindowId();
728  SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
729  SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
730 
731  pScMod->SetRefDialog( nId, pWnd == nullptr );
732 
733  }
734  break;
735 
736  case SID_SELECT_DB:
737  {
738  if ( pReqArgs )
739  {
740  const SfxStringItem& rItem
741  = static_cast<const SfxStringItem&>(pReqArgs->Get(SID_SELECT_DB));
742  pTabViewShell->GotoDBArea(rItem.GetValue());
743  rReq.Done();
744  }
745  else
746  {
747  ScDocument& rDoc = GetViewData().GetDocument();
748  ScDBCollection* pDBCol = rDoc.GetDBCollection();
749 
750  if ( pDBCol )
751  {
752  std::vector<OUString> aList;
753  const ScDBCollection::NamedDBs& rDBs = pDBCol->getNamedDBs();
754  for (const auto& rxDB : rDBs)
755  aList.push_back(rxDB->GetName());
756 
758 
759  ScopedVclPtr<AbstractScSelEntryDlg> pDlg(pFact->CreateScSelEntryDlg(pTabViewShell->GetFrameWeld(), aList));
760  if ( pDlg->Execute() == RET_OK )
761  {
762  OUString aName = pDlg->GetSelectedEntry();
763  pTabViewShell->GotoDBArea( aName );
764  rReq.AppendItem( SfxStringItem( SID_SELECT_DB, aName ) );
765  rReq.Done();
766  }
767  }
768  }
769  }
770  break;
771  case SID_DATA_STREAMS:
772  {
773  sc::DataStreamDlg aDialog(GetViewData().GetDocShell(), pTabViewShell->GetFrameWeld());
774  ScDocument& rDoc = GetViewData().GetDocument();
775  sc::DocumentLinkManager& rMgr = rDoc.GetDocLinkManager();
776  sc::DataStream* pStrm = rMgr.getDataStream();
777  if (pStrm)
778  aDialog.Init(*pStrm);
779 
780  if (aDialog.run() == RET_OK)
781  aDialog.StartStream();
782  }
783  break;
784  case SID_DATA_STREAMS_PLAY:
785  {
786  ScDocument& rDoc = GetViewData().GetDocument();
788  sc::DataStream* pStrm = rMgr.getDataStream();
789  if (pStrm)
790  pStrm->StartImport();
791  }
792  break;
793  case SID_DATA_STREAMS_STOP:
794  {
795  ScDocument& rDoc = GetViewData().GetDocument();
797  sc::DataStream* pStrm = rMgr.getDataStream();
798  if (pStrm)
799  pStrm->StopImport();
800  }
801  break;
802  case SID_DATA_PROVIDER:
803  {
804  auto xDoc = o3tl::make_shared<ScDocument>();
805  xDoc->InsertTab(0, "test");
806  ScDocument& rDoc = GetViewData().GetDocument();
807  ScDataProviderDlg aDialog(pTabViewShell->GetDialogParent(), xDoc, &rDoc);
808  if (aDialog.run() == RET_OK)
809  {
810  aDialog.import(rDoc);
811  }
812  }
813  break;
814  case SID_DATA_PROVIDER_REFRESH:
815  {
816  ScDocument& rDoc = GetViewData().GetDocument();
817  auto& rDataMapper = rDoc.GetExternalDataMapper();
818  for (auto& rDataSource : rDataMapper.getDataSources())
819  {
820  rDataSource.refresh(&rDoc, false);
821  }
822  }
823  break;
824  case SID_MANAGE_XML_SOURCE:
825  ExecuteXMLSourceDialog();
826  break;
827  case FID_VALIDATION:
828  case FID_CURRENTVALIDATION:
829  {
830  const SfxItemSet* pArgs = rReq.GetArgs();
831  if ( pArgs )
832  {
833  OSL_FAIL("later...");
834  }
835  else
836  {
837  SfxItemSet aArgSet( GetPool(), ScTPValidationValue::GetRanges() );
840  OUString aExpr1, aExpr2;
841  bool bBlank = true;
842  sal_Int16 nListType = css::sheet::TableValidationVisibility::UNSORTED;
843  bool bShowHelp = false;
844  OUString aHelpTitle, aHelpText;
845  bool bShowError = false;
846  ScValidErrorStyle eErrStyle = SC_VALERR_STOP;
847  OUString aErrTitle, aErrText;
848 
849  ScDocument& rDoc = GetViewData().GetDocument();
850  SCCOL nCurX = GetViewData().GetCurX();
851  SCROW nCurY = GetViewData().GetCurY();
852  SCTAB nTab = GetViewData().GetTabNo();
853  ScAddress aCursorPos( nCurX, nCurY, nTab );
854  sal_uLong nIndex = rDoc.GetAttr(
855  nCurX, nCurY, nTab, ATTR_VALIDDATA )->GetValue();
856  if ( nIndex )
857  {
858  const ScValidationData* pOldData = rDoc.GetValidationEntry( nIndex );
859  if ( pOldData )
860  {
861  eMode = pOldData->GetDataMode();
862  eOper = pOldData->GetOperation();
863  sal_uInt32 nNumFmt = 0;
864  if ( eMode == SC_VALID_DATE || eMode == SC_VALID_TIME )
865  {
866  SvNumFormatType nType = ( eMode == SC_VALID_DATE ) ? SvNumFormatType::DATE
867  : SvNumFormatType::TIME;
868  nNumFmt = rDoc.GetFormatTable()->GetStandardFormat(
869  nType, ScGlobal::eLnge );
870  }
871  aExpr1 = pOldData->GetExpression( aCursorPos, 0, nNumFmt );
872  aExpr2 = pOldData->GetExpression( aCursorPos, 1, nNumFmt );
873  bBlank = pOldData->IsIgnoreBlank();
874  nListType = pOldData->GetListType();
875 
876  bShowHelp = pOldData->GetInput( aHelpTitle, aHelpText );
877  bShowError = pOldData->GetErrMsg( aErrTitle, aErrText, eErrStyle );
878 
879  aArgSet.Put( SfxUInt16Item( FID_VALID_MODE, sal::static_int_cast<sal_uInt16>(eMode) ) );
880  aArgSet.Put( SfxUInt16Item( FID_VALID_CONDMODE, sal::static_int_cast<sal_uInt16>(eOper) ) );
881  aArgSet.Put( SfxStringItem( FID_VALID_VALUE1, aExpr1 ) );
882  aArgSet.Put( SfxStringItem( FID_VALID_VALUE2, aExpr2 ) );
883  aArgSet.Put( SfxBoolItem( FID_VALID_BLANK, bBlank ) );
884  aArgSet.Put( SfxInt16Item( FID_VALID_LISTTYPE, nListType ) );
885  aArgSet.Put( SfxBoolItem( FID_VALID_SHOWHELP, bShowHelp ) );
886  aArgSet.Put( SfxStringItem( FID_VALID_HELPTITLE, aHelpTitle ) );
887  aArgSet.Put( SfxStringItem( FID_VALID_HELPTEXT, aHelpText ) );
888  aArgSet.Put( SfxBoolItem( FID_VALID_SHOWERR, bShowError ) );
889  aArgSet.Put( SfxUInt16Item( FID_VALID_ERRSTYLE, sal::static_int_cast<sal_uInt16>(eErrStyle) ) );
890  aArgSet.Put( SfxStringItem( FID_VALID_ERRTITLE, aErrTitle ) );
891  aArgSet.Put( SfxStringItem( FID_VALID_ERRTEXT, aErrText ) );
892  }
893  }
894 
895  // cell range picker
896  vcl::Window* pWin = GetViewData().GetActiveWin();
897  weld::Window* pParentWin = pWin ? pWin->GetFrameWeld() : nullptr;
898  auto xDlg = std::make_shared<ScValidationDlg>(pParentWin, &aArgSet, pTabViewShell);
899  ScValidationRegisteredDlg aRegisterThatDlgExists(pParentWin, xDlg);
900 
901  short nResult = xDlg->run();
902  if ( nResult == RET_OK )
903  {
904  const SfxItemSet* pOutSet = xDlg->GetOutputItemSet();
905 
906  if ( const SfxUInt16Item* pItem = pOutSet->GetItemIfSet( FID_VALID_MODE ) )
907  eMode = static_cast<ScValidationMode>(pItem->GetValue());
908  if ( const SfxUInt16Item* pItem = pOutSet->GetItemIfSet( FID_VALID_CONDMODE ) )
909  eOper = static_cast<ScConditionMode>(pItem->GetValue());
910  if ( const SfxStringItem* pItem = pOutSet->GetItemIfSet( FID_VALID_VALUE1 ) )
911  {
912  OUString aTemp1 = pItem->GetValue();
913  if (eMode == SC_VALID_DATE || eMode == SC_VALID_TIME)
914  {
915  sal_uInt32 nNumIndex = 0;
916  double nVal;
917  if (rDoc.GetFormatTable()->IsNumberFormat(aTemp1, nNumIndex, nVal))
918  aExpr1 = ::rtl::math::doubleToUString( nVal,
919  rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
921  else
922  aExpr1 = aTemp1;
923  }
924  else
925  aExpr1 = aTemp1;
926  }
927  if ( const SfxStringItem* pItem = pOutSet->GetItemIfSet( FID_VALID_VALUE2 ) )
928  {
929  OUString aTemp2 = pItem->GetValue();
930  if (eMode == SC_VALID_DATE || eMode == SC_VALID_TIME)
931  {
932  sal_uInt32 nNumIndex = 0;
933  double nVal;
934  if (rDoc.GetFormatTable()->IsNumberFormat(aTemp2, nNumIndex, nVal))
935  aExpr2 = ::rtl::math::doubleToUString( nVal,
936  rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
938  else
939  aExpr2 = aTemp2;
940  if ( eMode == SC_VALID_TIME ) {
941  sal_Int32 wraparound = aExpr1.compareTo(aExpr2);
942  if (wraparound > 0) {
943  if (eOper == ScConditionMode::Between) {
945  OUString tmp = aExpr1;
946  aExpr1 = aExpr2;
947  aExpr2 = tmp;
948  }
949  else if (eOper == ScConditionMode::NotBetween) {
950  eOper = ScConditionMode::Between;
951  OUString tmp = aExpr1;
952  aExpr1 = aExpr2;
953  aExpr2 = tmp;
954  }
955  }
956  }
957  }
958  else
959  aExpr2 = aTemp2;
960  }
961  if ( const SfxBoolItem* pItem = pOutSet->GetItemIfSet( FID_VALID_BLANK ) )
962  bBlank = pItem->GetValue();
963  if ( const SfxInt16Item* pItem = pOutSet->GetItemIfSet( FID_VALID_LISTTYPE ) )
964  nListType = pItem->GetValue();
965 
966  if ( const SfxBoolItem* pItem = pOutSet->GetItemIfSet( FID_VALID_SHOWHELP ) )
967  bShowHelp = pItem->GetValue();
968  if ( const SfxStringItem* pItem = pOutSet->GetItemIfSet( FID_VALID_HELPTITLE ) )
969  aHelpTitle = pItem->GetValue();
970  if ( const SfxStringItem* pItem = pOutSet->GetItemIfSet( FID_VALID_HELPTEXT ) )
971  aHelpText = pItem->GetValue();
972 
973  if ( const SfxBoolItem* pItem = pOutSet->GetItemIfSet( FID_VALID_SHOWERR ) )
974  bShowError = pItem->GetValue();
975  if ( const SfxUInt16Item* pItem = pOutSet->GetItemIfSet( FID_VALID_ERRSTYLE ) )
976  eErrStyle = static_cast<ScValidErrorStyle>(pItem->GetValue());
977  if ( const SfxStringItem* pItem = pOutSet->GetItemIfSet( FID_VALID_ERRTITLE ) )
978  aErrTitle = pItem->GetValue();
979  if ( const SfxStringItem* pItem = pOutSet->GetItemIfSet( FID_VALID_ERRTEXT ) )
980  aErrText = pItem->GetValue();
981 
982  ScValidationData aData( eMode, eOper, aExpr1, aExpr2, rDoc, aCursorPos );
983  aData.SetIgnoreBlank( bBlank );
984  aData.SetListType( nListType );
985 
986  aData.SetInput(aHelpTitle, aHelpText); // sets bShowInput to TRUE
987  if (!bShowHelp)
988  aData.ResetInput(); // reset only bShowInput
989 
990  aData.SetError(aErrTitle, aErrText, eErrStyle); // sets bShowError to TRUE
991  if (!bShowError)
992  aData.ResetError(); // reset only bShowError
993 
994  pTabViewShell->SetValidation( aData );
995  pTabViewShell->TestHintWindow();
996  rReq.Done( *pOutSet );
997  }
998  }
999  }
1000  break;
1001 
1002  case SID_TEXT_TO_COLUMNS:
1003  {
1004  ScViewData& rData = GetViewData();
1005  ScRange aRange;
1006 
1007  if ( lcl_GetTextToColumnsRange( rData, aRange, false ) )
1008  {
1009  ScDocument& rDoc = rData.GetDocument();
1010 
1011  ScImportExport aExport( rDoc, aRange );
1013 
1014  // #i87703# text to columns fails with tab separator
1015  aExport.SetDelimiter( u'\0' );
1016 
1017  SvMemoryStream aStream;
1018  aStream.SetStreamCharSet( RTL_TEXTENCODING_UNICODE );
1020  aExport.ExportStream( aStream, OUString(), SotClipboardFormatId::STRING );
1021 
1024  pTabViewShell->GetFrameWeld(), OUString(), &aStream, SC_TEXTTOCOLUMNS));
1025 
1026  if ( pDlg->Execute() == RET_OK )
1027  {
1028  ScDocShell* pDocSh = rData.GetDocShell();
1029  OSL_ENSURE( pDocSh, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDocSh is null!" );
1030 
1031  OUString aUndo = ScResId( STR_UNDO_TEXTTOCOLUMNS );
1032  pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo, 0, rData.GetViewShell()->GetViewShellId() );
1033 
1034  ScImportExport aImport( rDoc, aRange.aStart );
1035  ScAsciiOptions aOptions;
1036  pDlg->GetOptions( aOptions );
1037  pDlg->SaveParameters();
1038  aImport.SetExtOptions( aOptions );
1039  aImport.SetApi( false );
1040  aImport.SetImportBroadcast( true );
1041  aImport.SetOverwriting( true );
1042  aStream.Seek( 0 );
1043  aImport.ImportStream( aStream, OUString(), SotClipboardFormatId::STRING );
1044 
1045  pDocSh->GetUndoManager()->LeaveListAction();
1046  }
1047  }
1048  }
1049  break;
1050  }
1051 }
1052 
1054 {
1055  ScTabViewShell* pTabViewShell = GetViewData().GetViewShell();
1056  ScViewData& rData = GetViewData();
1057  ScDocShell* pDocSh = rData.GetDocShell();
1058  ScDocument& rDoc = pDocSh->GetDocument();
1059  SCCOL nPosX = rData.GetCurX();
1060  SCROW nPosY = rData.GetCurY();
1061  SCTAB nTab = rData.GetTabNo();
1062 
1063  bool bAutoFilter = false;
1064  bool bAutoFilterTested = false;
1065 
1066  SfxWhichIter aIter(rSet);
1067  sal_uInt16 nWhich = aIter.FirstWhich();
1068  while (nWhich)
1069  {
1070  switch (nWhich)
1071  {
1072  case SID_REFRESH_DBAREA:
1073  {
1074  // imported data without selection
1075  // or filter,sort,subtotal (also without import)
1076  bool bOk = false;
1077  ScDBData* pDBData = pTabViewShell->GetDBData(false,SC_DB_OLD);
1078  if (pDBData && rDoc.GetChangeTrack() == nullptr)
1079  {
1080  if ( pDBData->HasImportParam() )
1081  bOk = !pDBData->HasImportSelection();
1082  else
1083  {
1084  bOk = pDBData->HasQueryParam() ||
1085  pDBData->HasSortParam() ||
1086  pDBData->HasSubTotalParam();
1087  }
1088  }
1089  if (!bOk)
1090  rSet.DisableItem( nWhich );
1091  }
1092  break;
1093 
1094  case SID_FILTER:
1095  case SID_SPECIAL_FILTER:
1096  {
1097  ScRange aDummy;
1098  ScMarkType eMarkType = GetViewData().GetSimpleArea( aDummy);
1099  if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED)
1100  {
1101  rSet.DisableItem( nWhich );
1102  }
1103  }
1104  break;
1105 
1106  //in case of Redlining and multiselection disable
1107  case SID_SORT_ASCENDING:
1108  case SID_SORT_DESCENDING:
1109  case SCITEM_SORTDATA:
1110  case SCITEM_SUBTDATA:
1111  case SID_OPENDLG_PIVOTTABLE:
1112  {
1114 
1115  if ( pDocSh->IsReadOnly() || rDoc.GetChangeTrack()!=nullptr ||
1116  GetViewData().IsMultiMarked() )
1117  {
1118  rSet.DisableItem( nWhich );
1119  }
1120  }
1121  break;
1122 
1123  case SID_REIMPORT_DATA:
1124  {
1125  // only imported data without selection
1126  ScDBData* pDBData = pTabViewShell->GetDBData(false,SC_DB_OLD);
1127  if (!pDBData || !pDBData->HasImportParam() || pDBData->HasImportSelection() ||
1128  rDoc.GetChangeTrack()!=nullptr)
1129  {
1130  rSet.DisableItem( nWhich );
1131  }
1132  }
1133  break;
1134 
1135  case SID_VIEW_DATA_SOURCE_BROWSER:
1136  {
1137  if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::DATABASE))
1138  rSet.Put(SfxVisibilityItem(nWhich, false));
1139  else
1140  // get state (BoolItem) from SfxViewFrame
1141  pTabViewShell->GetViewFrame()->GetSlotState( nWhich, nullptr, &rSet );
1142  }
1143  break;
1144  case SID_SBA_BRW_INSERT:
1145  {
1146  // SBA wants a sal_Bool-item, enabled
1147 
1148  rSet.Put(SfxBoolItem(nWhich, true));
1149  }
1150  break;
1151 
1152  case SID_AUTO_FILTER:
1153  case SID_AUTOFILTER_HIDE:
1154  {
1155  if (!bAutoFilterTested)
1156  {
1157  bAutoFilter = rDoc.HasAutoFilter( nPosX, nPosY, nTab );
1158  bAutoFilterTested = true;
1159  }
1160  if ( nWhich == SID_AUTO_FILTER )
1161  {
1162  ScRange aDummy;
1163  ScMarkType eMarkType = GetViewData().GetSimpleArea( aDummy);
1164  if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED)
1165  {
1166  rSet.DisableItem( nWhich );
1167  }
1168  else if (rDoc.GetDPAtBlock(aDummy))
1169  {
1170  rSet.DisableItem( nWhich );
1171  }
1172  else
1173  rSet.Put( SfxBoolItem( nWhich, bAutoFilter ) );
1174  }
1175  else
1176  if (!bAutoFilter)
1177  rSet.DisableItem( nWhich );
1178  }
1179  break;
1180 
1181  case SID_UNFILTER:
1182  {
1183  SCCOL nStartCol, nEndCol;
1184  SCROW nStartRow, nEndRow;
1185  SCTAB nStartTab, nEndTab;
1186  bool bAnyQuery = false;
1187 
1188  bool bSelected = (GetViewData().GetSimpleArea(
1189  nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab )
1190  == SC_MARK_SIMPLE);
1191 
1192  if ( bSelected )
1193  {
1194  if (nStartCol==nEndCol && nStartRow==nEndRow)
1195  bSelected = false;
1196  }
1197  else
1198  {
1199  nStartCol = GetViewData().GetCurX();
1200  nStartRow = GetViewData().GetCurY();
1201  nStartTab = GetViewData().GetTabNo();
1202  }
1203 
1204  ScDBData* pDBData = bSelected
1205  ? rDoc.GetDBAtArea( nStartTab, nStartCol, nStartRow, nEndCol, nEndRow )
1206  : rDoc.GetDBAtCursor( nStartCol, nStartRow, nStartTab, ScDBDataPortion::AREA );
1207 
1208  if ( pDBData )
1209  {
1210  ScQueryParam aParam;
1211  pDBData->GetQueryParam( aParam );
1212  if ( aParam.GetEntry(0).bDoQuery )
1213  bAnyQuery = true;
1214  }
1215 
1216  if ( !bAnyQuery )
1217  rSet.DisableItem( nWhich );
1218  }
1219  break;
1220 
1221  case SID_DEFINE_DBNAME:
1222  {
1223  if ( pDocSh->IsDocShared() )
1224  {
1225  rSet.DisableItem( nWhich );
1226  }
1227  }
1228  break;
1229  case SID_DATA_PROVIDER:
1230  break;
1231  case SID_DATA_PROVIDER_REFRESH:
1232  {
1233  ScDocument& rViewDoc = GetViewData().GetDocument();
1234  auto& rDataMapper = rViewDoc.GetExternalDataMapper();
1235  if (rDataMapper.getDataSources().empty())
1236  rSet.DisableItem(nWhich);
1237  }
1238  break;
1239  case SID_DATA_STREAMS:
1240  case SID_DATA_STREAMS_PLAY:
1241  case SID_DATA_STREAMS_STOP:
1242  {
1243  if ( !officecfg::Office::Common::Misc::ExperimentalMode::get() )
1244  rSet.DisableItem( nWhich );
1245  }
1246  break;
1247  case SID_TEXT_TO_COLUMNS:
1248  {
1249  ScRange aRange;
1250  if ( !lcl_GetTextToColumnsRange( rData, aRange, true ) )
1251  {
1252  rSet.DisableItem( nWhich );
1253  }
1254  }
1255  break;
1256  case SID_MANAGE_XML_SOURCE:
1257  break;
1258  }
1259  nWhich = aIter.NextWhich();
1260  }
1261 }
1262 
1263 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3135
const SfxPoolItem * ExecuteSlot(SfxRequest &rReq, const SfxInterface *pIF=nullptr)
::std::vector< ScSortKeyState > maKeyState
Definition: sortparam.hxx:121
void TestHintWindow()
Definition: tabview3.cxx:783
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:1534
sal_Int32 nIndex
SC_DLLPUBLIC bool HasQueryParam() const
Definition: dbdata.cxx:524
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
Definition: document.hxx:825
ScDBData * GetDBData(bool bMarkArea=true, ScGetDBMode eMode=SC_DB_MAKE, ScGetDBSelection eSel=ScGetDBSelection::Keep)
Definition: dbfunc.cxx:81
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
ScAddress aStart
Definition: address.hxx:497
const ScDPObject * GetDialogDPObject() const
Definition: tabvwsh.hxx:288
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
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:205
SfxChildWindow * GetChildWindow(sal_uInt16)
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
void ErrorMessage(TranslateId pGlobStrId)
Definition: tabview2.cxx:1446
SCROW Row() const
Definition: address.hxx:274
bool MakePivotTable(const ScDPSaveData &rData, const ScRange &rDest, bool bNewTable, const ScDPObject &rSource)
Definition: dbfunc3.cxx:621
bool PaintExtras()
Definition: tabview3.cxx:2764
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:1689
void SetApi(bool bApi)
Definition: impex.hxx:157
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:37
Reference< XFrame > xFrame
void StartImport()
Definition: datastream.cxx:377
virtual void GetOptions(ScAsciiOptions &rOpt)=0
SCROW GetCurY() const
Definition: viewdata.hxx:402
don't create
Definition: global.hxx:384
void SetValidation(const ScValidationData &rNew)
Definition: viewfun2.cxx:3454
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:395
static void ShowInBeamer(const ScImportParam &rParam, const SfxViewFrame *pFrame)
Definition: dbdocimp.cxx:72
bool ImportData(const ScImportParam &rParam)
Definition: dbfunc.cxx:432
ScAddress aEnd
Definition: address.hxx:498
void Done(bool bRemove=false)
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
void ExecuteDB(SfxRequest &rReq)
Definition: cellsh2.cxx:226
void AddHighlightRange(const ScRange &rRange, const Color &rColor)
Definition: tabview3.cxx:2526
bool HasSubTotalParam() const
Definition: dbdata.cxx:542
#define SCITEM_SUBTDATA
Definition: scitems.hxx:92
const SfxItemSet * GetArgs() const
sc::DocumentLinkManager & GetDocLinkManager()
Definition: documen2.cxx:239
virtual short Execute()=0
ScConditionMode GetOperation() const
Definition: conditio.hxx:368
bool ImportStream(SvStream &, const OUString &rBaseURL, SotClipboardFormatId)
Definition: impex.cxx:383
#define SCITEM_QUERYDATA
Definition: scitems.hxx:91
bool HasAutoFilter(SCCOL nCol, SCROW nRow, SCTAB nTab)
Definition: documen3.cxx:1502
sal_uInt16 NextWhich()
const ScRange & GetMarkArea() const
Definition: markdata.hxx:83
bool mbCellDrawObjects
If TRUE, consider the presence of draw objects anchored to the cell.
Definition: sortparam.hxx:48
SC_DLLPUBLIC const ScValidationData * GetValidationEntry(sal_uLong nIndex) const
Definition: documen4.cxx:888
virtual SfxUndoManager * GetUndoManager() override
Definition: docsh.cxx:2945
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:1015
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:891
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:81
bool bNaturalSort
Definition: sortparam.hxx:114
SC_DLLPUBLIC void InputEnterHandler(ScEnterMode nBlockMode=ScEnterMode::NORMAL, bool bBeforeSavingInLOK=false)
Definition: scmod.cxx:1408
SfxFrame & GetFrame() const
int nCount
SC_DLLPUBLIC SCSIZE GetEntryCount() const
Definition: queryparam.cxx:110
SC_DLLPUBLIC sc::ExternalDataMapper & GetExternalDataMapper()
SC_DLLPUBLIC void SetRefDialog(sal_uInt16 nId, bool bVis, SfxViewFrame *pViewFrm=nullptr)
Reference dialogs.
Definition: scmod.cxx:1516
void SetInput(const OUString &rTitle, const OUString &rMsg)
Definition: validat.cxx:160
SC_DLLPUBLIC const ScQueryEntry & GetEntry(SCSIZE n) const
Definition: queryparam.cxx:115
bool IsDocShared() const
ScConditionMode
Definition: conditio.hxx:59
Mode eMode
void UpdateInputHandler(bool bForce=false, bool bStopEditing=true)
Definition: tabvwsha.cxx:668
SCTAB Tab() const
Definition: address.hxx:283
void SetRow(SCROW nRowP)
Definition: address.hxx:287
void ClearHighlightRanges()
Definition: tabview3.cxx:2536
void SetCol(SCCOL nColP)
Definition: address.hxx:291
ScValidationMode
Definition: validat.hxx:38
ScChangeTrack * GetChangeTrack() const
Definition: document.hxx:2485
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:1066
SC_DLLPUBLIC const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt16 nWhich) const
Definition: document.cxx:4764
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:357
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:1053
bool IsBlockEmpty(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab) const
Definition: document.cxx:5391
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:1091
const OUString & getNumDecimalSep() const
#define SCITEM_SORTDATA
Definition: scitems.hxx:90
void RepeatDB(bool bRecord=true)
Definition: dbfunc3.cxx:2115
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:459
bool IsMarked() const
Definition: markdata.hxx:80
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:1239
sal_Int16 SCCOL
Definition: types.hxx:21
virtual OUString GetSelectedEntry() const =0
#define SC_MOD()
Definition: scmod.hxx:249
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:2170
const OUString & GetValue() const
SC_DLLPUBLIC void SetTabNo(SCTAB nTab, bool bNew=false, bool bExtendSelection=false, bool bSameTabButMoved=false)
Definition: tabview3.cxx:1800
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:159
void SetIgnoreBlank(bool bSet)
Definition: conditio.cxx:417
bool bCaseSens
Definition: sortparam.hxx:113
const ScQueryParam & GetQueryData() const
Definition: uiitems.cxx:214
static SC_DLLPUBLIC LanguageType eLnge
Definition: global.hxx:545
bool GetAdvancedQuerySource(ScRange &rSource) const
Definition: uiitems.cxx:219
bool ExportStream(SvStream &, const OUString &rBaseURL, SotClipboardFormatId)
Definition: impex.cxx:423
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:279
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:176
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:6173
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.hxx:622
void SetImportBroadcast(bool b)
Definition: impex.hxx:158
void ResetInput()
Definition: validat.cxx:150
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:160
void SetError(const OUString &rTitle, const OUString &rMsg, ScValidErrorStyle eStyle)
Definition: validat.cxx:167
void SetStreamCharSet(rtl_TextEncoding eCharSet)
void HideAutoFilter()
Definition: dbfunc.cxx:395
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:443
void CancelAutoDBRange()
Definition: docsh5.cxx:368
DataStream * getDataStream()
NamedDBs & getNamedDBs()
Definition: dbdata.hxx:316
void HideListBox()
Definition: tabview3.cxx:2973
void UISort(const ScSortParam &rSortParam)
Definition: dbfunc.cxx:186
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_LIGHTBLUE
#define SCITEM_PIVOTDATA
Definition: scitems.hxx:94
void SetDelimiter(sal_Unicode c)
Definition: impex.hxx:133
void AppendItem(const SfxPoolItem &)
virtual std::shared_ptr< ScAsyncTabController > CreateScSortDlg(weld::Window *pParent, const SfxItemSet *pArgSet)=0
ScDirection
Definition: global.hxx:340
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:370
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:575
const ScDPSaveData & GetData() const
Definition: uiitems.hxx:237
void ResetError()
Definition: validat.cxx:155
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:401
ViewShellId GetViewShellId() const override
bool m_bDetectedRangeSegmentation false