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