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