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