LibreOffice Module sc (master)  1
navipi.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 <sfx2/app.hxx>
21 #include <sfx2/bindings.hxx>
22 #include <sfx2/dispatch.hxx>
23 #include <sfx2/event.hxx>
24 #include <sfx2/navigat.hxx>
25 #include <svl/stritem.hxx>
26 #include <unotools/charclass.hxx>
27 #include <uiobject.hxx>
28 
29 #include <viewdata.hxx>
30 #include <tabvwsh.hxx>
31 #include <docsh.hxx>
32 #include <document.hxx>
33 #include <rangeutl.hxx>
34 #include <sc.hrc>
35 #include <strings.hrc>
36 #include <bitmaps.hlst>
37 #include <scresid.hxx>
38 #include <scmod.hxx>
39 #include <navicfg.hxx>
40 #include <navcitem.hxx>
41 #include <navipi.hxx>
42 #include <navsett.hxx>
43 #include <markdata.hxx>
44 
45 #include <com/sun/star/uno/Reference.hxx>
46 
47 using namespace com::sun::star;
48 
49 // maximum values for UI
50 #define SCNAV_MAXCOL (MAXCOLCOUNT)
51 // macro is sufficient since only used in ctor
52 #define SCNAV_COLDIGITS (static_cast<sal_Int32>( floor( log10( static_cast<double>(SCNAV_MAXCOL)))) + 1) // 1...256...18278
53 // precomputed constant because it is used in every change of spin button field
54 const sal_Int32 SCNAV_COLLETTERS = ::ScColToAlpha(SCNAV_MAXCOL).getLength(); // A...IV...ZZZ
55 
56 #define SCNAV_MAXROW (MAXROWCOUNT)
57 
59 {
61 
62  if ( pCurSh )
63  {
64  vcl::Window* pShellWnd = pCurSh->GetWindow();
65  if ( pShellWnd )
66  pShellWnd->GrabFocus();
67  }
68 }
69 
70 namespace
71 {
72  SCCOL NumToAlpha(SCCOL nColNo, OUString& rStr)
73  {
74  if ( nColNo > SCNAV_MAXCOL )
75  nColNo = SCNAV_MAXCOL;
76  else if ( nColNo < 1 )
77  nColNo = 1;
78 
79  ::ScColToAlpha( rStr, nColNo - 1);
80 
81  return nColNo;
82  }
83 
84  SCCOL AlphaToNum(const ScDocument& rDoc, OUString& rStr)
85  {
86  SCCOL nColumn = 0;
87 
88  if ( CharClass::isAsciiAlpha( rStr) )
89  {
90  rStr = rStr.toAsciiUpperCase();
91 
92  if (::AlphaToCol( rDoc, nColumn, rStr))
93  ++nColumn;
94 
95  if ( (rStr.getLength() > SCNAV_COLLETTERS) || (nColumn > SCNAV_MAXCOL) )
96  {
97  nColumn = SCNAV_MAXCOL;
98  NumToAlpha( nColumn, rStr );
99  }
100  }
101  else
102  rStr.clear();
103 
104  return nColumn;
105  }
106 
107  SCCOL NumStrToAlpha(OUString& rStr)
108  {
109  SCCOL nColumn = 0;
110 
111  if ( CharClass::isAsciiNumeric(rStr) )
112  nColumn = NumToAlpha( static_cast<SCCOL>(rStr.toInt32()), rStr );
113  else
114  rStr.clear();
115 
116  return nColumn;
117  }
118 }
119 
120 IMPL_LINK(ScNavigatorDlg, ParseRowInputHdl, int*, result, bool)
121 {
122  SCCOL nCol;
123 
124  OUString aStrCol = m_xEdCol->get_text();
125 
126  if (!aStrCol.isEmpty())
127  {
128  // nKeyGroup is no longer set at VCL, in cause of lack of keyinput
129 
130  if ( CharClass::isAsciiNumeric(aStrCol) )
131  nCol = NumStrToAlpha( aStrCol );
132  else
133  {
134  ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>( SfxViewShell::Current() );
135  nCol = AlphaToNum( *pViewSh->GetViewData().GetDocument(), aStrCol );
136  }
137  }
138  else
139  nCol = 0;
140 
141  *result = nCol;
142  return true;
143 }
144 
146 {
147  ReleaseFocus();
148 
149  SCROW nRow = m_xEdRow->get_value();
150  SCCOL nCol = m_xEdCol->get_value();
151 
152  if ( (nCol > 0) && (nRow > 0) )
153  SetCurrentCell(nCol - 1, nRow - 1);
154 
155  return true;
156 }
157 
158 IMPL_LINK_NOARG(ScNavigatorDlg, FormatRowOutputHdl, weld::SpinButton&, void)
159 {
160  OUString aStr;
161  ::ScColToAlpha(aStr, m_xEdCol->get_value() - 1);
162  m_xEdCol->set_text(aStr);
163 }
164 
166 {
167  ReleaseFocus();
168 
169  SCCOL nCol = m_xEdCol->get_value();
170  SCROW nRow = m_xEdRow->get_value();
171 
172  if ( (nCol > 0) && (nRow > 0) )
173  SetCurrentCell(nCol - 1, nRow - 1);
174 
175  return true;
176 }
177 
178 IMPL_LINK(ScNavigatorDlg, DocumentSelectHdl, weld::ComboBox&, rListBox, void)
179 {
181 
182  OUString aDocName = rListBox.get_active_text();
183  m_xLbEntries->SelectDoc(aDocName);
184 }
185 
186 IMPL_LINK(ScNavigatorDlg, ToolBoxSelectHdl, const OString&, rSelId, void)
187 {
188  // Switch the mode?
189  if (rSelId == "contents" || rSelId == "scenarios")
190  {
191  NavListMode eOldMode = eListMode;
192  NavListMode eNewMode;
193 
194  if (rSelId == "scenarios")
195  {
196  if (eOldMode == NAV_LMODE_SCENARIOS)
197  eNewMode = NAV_LMODE_AREAS;
198  else
199  eNewMode = NAV_LMODE_SCENARIOS;
200  }
201  else // on/off
202  {
203  if (eOldMode == NAV_LMODE_NONE)
204  eNewMode = NAV_LMODE_AREAS;
205  else
206  eNewMode = NAV_LMODE_NONE;
207  }
208  SetListMode(eNewMode);
209  UpdateButtons();
210  }
211  else if (rSelId == "dragmode")
212  m_xTbxCmd2->set_menu_item_active("dragmode", !m_xTbxCmd2->get_menu_item_active("dragmode"));
213  else
214  {
215  if (rSelId == "datarange")
216  MarkDataArea();
217  else if (rSelId == "start")
218  StartOfDataArea();
219  else if (rSelId == "end")
220  EndOfDataArea();
221  else if (rSelId == "toggle")
222  {
223  m_xLbEntries->ToggleRoot();
224  UpdateButtons();
225  }
226  }
227 }
228 
229 IMPL_LINK(ScNavigatorDlg, ToolBoxDropdownClickHdl, const OString&, rCommand, void)
230 {
231  if (!m_xTbxCmd2->get_menu_item_active(rCommand))
232  return;
233 
234  // the popup menu of the drop mode has to be called in the
235  // click (button down) and not in the select (button up)
236  if (rCommand == "dragmode")
237  {
238  switch (GetDropMode())
239  {
240  case 0:
241  m_xDragModeMenu->set_active("hyperlink", true);
242  break;
243  case 1:
244  m_xDragModeMenu->set_active("link", true);
245  break;
246  case 2:
247  m_xDragModeMenu->set_active("copy", true);
248  break;
249  }
250  }
251 }
252 
253 IMPL_LINK(ScNavigatorDlg, MenuSelectHdl, const OString&, rIdent, void)
254 {
255  if (rIdent == "hyperlink")
256  SetDropMode(0);
257  else if (rIdent == "link")
258  SetDropMode(1);
259  else if (rIdent == "copy")
260  SetDropMode(2);
261 }
262 
264 {
265  NavListMode eMode = eListMode;
266  m_xTbxCmd2->set_item_active("scenarios", eMode == NAV_LMODE_SCENARIOS);
267  m_xTbxCmd1->set_item_active("contents", eMode != NAV_LMODE_NONE);
268 
269  // the toggle button:
270  if (eMode == NAV_LMODE_SCENARIOS || eMode == NAV_LMODE_NONE)
271  {
272  m_xTbxCmd2->set_item_sensitive("toggle", false);
273  m_xTbxCmd2->set_item_active("toggle", false);
274  }
275  else
276  {
277  m_xTbxCmd2->set_item_sensitive("toggle", true);
278  bool bRootSet = m_xLbEntries->GetRootType() != ScContentId::ROOT;
279  m_xTbxCmd2->set_item_active("toggle", bRootSet);
280  }
281 
282  OUString sImageId;
283  switch (nDropMode)
284  {
285  case SC_DROPMODE_URL:
286  sImageId = RID_BMP_DROP_URL;
287  break;
288  case SC_DROPMODE_LINK:
289  sImageId = RID_BMP_DROP_LINK;
290  break;
291  case SC_DROPMODE_COPY:
292  sImageId = RID_BMP_DROP_COPY;
293  break;
294  }
295  m_xTbxCmd2->set_item_icon_name("dragmode", sImageId);
296 }
297 
299  : mnRootSelected(ScContentId::ROOT)
300  , mnChildSelected(SC_CONTENT_NOCHILD)
301 {
302  maExpandedVec.fill(false);
303 }
304 
306 
308  sal_uInt16 nId,
309  SfxBindings* pBind,
310  SAL_UNUSED_PARAMETER SfxChildWinInfo* /* pInfo */)
311  : SfxChildWindowContext(nId)
312 {
313  pNavigator = VclPtr<ScNavigatorDlg>::Create(pBind, pParent);
314  if (SfxNavigator* pNav = dynamic_cast<SfxNavigator*>(pParent))
315  pNav->SetMinOutputSizePixel(pNavigator->GetOptimalSize());
316  SetWindow(pNavigator);
317 }
318 
320  : PanelLayout(pParent, "NavigatorPanel", "modules/scalc/ui/navigatorpanel.ui", nullptr)
321  , rBindings(*pB)
322  , m_xEdCol(m_xBuilder->weld_spin_button("column"))
323  , m_xEdRow(m_xBuilder->weld_spin_button("row"))
324  , m_xTbxCmd1(m_xBuilder->weld_toolbar("toolbox1"))
325  , m_xTbxCmd2(m_xBuilder->weld_toolbar("toolbox2"))
326  , m_xLbEntries(new ScContentTree(m_xBuilder->weld_tree_view("contentbox"), this))
327  , m_xScenarioBox(m_xBuilder->weld_widget("scenariobox"))
328  , m_xWndScenarios(new ScScenarioWindow(*m_xBuilder,
329  ScResId(SCSTR_QHLP_SCEN_LISTBOX), ScResId(SCSTR_QHLP_SCEN_COMMENT)))
330  , m_xLbDocuments(m_xBuilder->weld_combo_box("documents"))
331  , m_xDragModeMenu(m_xBuilder->weld_menu("dragmodemenu"))
332  , aStrActiveWin(ScResId(SCSTR_ACTIVEWIN))
333  , pViewData(nullptr )
334  , eListMode(NAV_LMODE_NONE)
335  , nDropMode(SC_DROPMODE_URL)
336  , nCurCol(0)
337  , nCurRow(0)
338  , nCurTab(0)
339 {
340  set_id("NavigatorPanelParent"); // for uitests
341 
342  m_xEdRow->set_range(1, SCNAV_MAXROW);
343  m_xEdRow->set_width_chars(5);
344  //max rows is 1,000,000, which is too long for typical use
345  m_xEdRow->connect_activate(LINK(this, ScNavigatorDlg, ExecuteRowHdl));
346 
347  m_xEdCol->set_range(1, SCNAV_MAXCOL);
348  m_xEdCol->set_width_chars(SCNAV_COLDIGITS); // 1...256...18278 or A...IV...ZZZ
349  m_xEdCol->connect_activate(LINK(this, ScNavigatorDlg, ExecuteColHdl));
350  m_xEdCol->connect_output(LINK(this, ScNavigatorDlg, FormatRowOutputHdl));
351  m_xEdCol->connect_input(LINK(this, ScNavigatorDlg, ParseRowInputHdl));
352 
353  m_xTbxCmd1->connect_clicked(LINK(this, ScNavigatorDlg, ToolBoxSelectHdl));
354  m_xTbxCmd2->connect_clicked(LINK(this, ScNavigatorDlg, ToolBoxSelectHdl));
355 
356  m_xTbxCmd2->set_item_menu("dragmode", m_xDragModeMenu.get());
357  m_xDragModeMenu->connect_activate(LINK(this, ScNavigatorDlg, MenuSelectHdl));
358  m_xTbxCmd2->connect_menu_toggled(LINK(this, ScNavigatorDlg, ToolBoxDropdownClickHdl));
359 
360  ScNavipiCfg& rCfg = SC_MOD()->GetNavipiCfg();
361  nDropMode = rCfg.GetDragMode();
362 
363  m_xLbDocuments->set_size_request(42, -1); // set a nominal width so it takes width of surroundings
364  m_xLbDocuments->connect_changed(LINK(this, ScNavigatorDlg, DocumentSelectHdl));
365  aStrActive = " (" + ScResId(SCSTR_ACTIVE) + ")"; // " (active)"
366  aStrNotActive = " (" + ScResId(SCSTR_NOTACTIVE) + ")"; // " (not active)"
367  aStrHidden = " (" + ScResId(SCSTR_HIDDEN) + ")"; // " (hidden)"
368 
369  rBindings.ENTERREGISTRATIONS();
370 
371  mvBoundItems[0].reset(new ScNavigatorControllerItem(SID_CURRENTCELL,*this,rBindings));
372  mvBoundItems[1].reset(new ScNavigatorControllerItem(SID_CURRENTTAB,*this,rBindings));
373  mvBoundItems[2].reset(new ScNavigatorControllerItem(SID_CURRENTDOC,*this,rBindings));
374  mvBoundItems[3].reset(new ScNavigatorControllerItem(SID_SELECT_SCENARIO,*this,rBindings));
375 
376  rBindings.LEAVEREGISTRATIONS();
377 
378  StartListening( *(SfxGetpApp()) );
380 
381  m_xLbEntries->set_selection_mode( SelectionMode::Single );
382  Size aSize(LogicToPixel(Size(110, 100), MapMode(MapUnit::MapAppFont)));
383  m_xLbEntries->set_size_request(aSize.Width(), aSize.Height());
384 
385  // was a category chosen as root?
386  ScContentId nLastRoot = rCfg.GetRootType();
387  if ( nLastRoot != ScContentId::ROOT )
388  m_xLbEntries->SetRootType( nLastRoot );
389 
390  m_xLbEntries->Refresh();
391  GetDocNames(nullptr);
392 
393  UpdateButtons();
394 
395  UpdateColumn();
396  UpdateRow();
397  UpdateTable(nullptr);
398  m_xLbEntries->hide();
399  m_xScenarioBox->hide();
400 
401  aContentIdle.SetInvokeHandler( LINK( this, ScNavigatorDlg, TimeHdl ) );
402  aContentIdle.SetPriority( TaskPriority::LOWEST );
403 
404  m_xLbEntries->SetNavigatorDlgFlag(true);
405 
406  // if scenario was active, switch on
407  NavListMode eNavMode = static_cast<NavListMode>(rCfg.GetListMode());
408  if (eNavMode == NAV_LMODE_SCENARIOS)
409  m_xTbxCmd2->set_item_active("scenarios", true);
410  else
411  eNavMode = NAV_LMODE_AREAS;
412  SetListMode(eNavMode);
413 
415 }
416 
418 {
419  PanelLayout::StateChanged(nStateChange);
420  if (nStateChange == StateChangedType::InitShow)
421  {
422  // When the navigator is displayed in the sidebar, or is otherwise
423  // docked, it has the whole deck to fill. Therefore hide the button that
424  // hides all controls below the top two rows of buttons.
425  m_xTbxCmd1->set_item_visible("contents", SfxChildWindowContext::GetFloatingWindow(GetParent()) != nullptr);
426  }
427 }
428 
430 {
432 }
433 
435 {
436  disposeOnce();
437 }
438 
440 {
441  aContentIdle.Stop();
442 
443  for (auto & p : mvBoundItems)
444  p.reset();
445  pMarkArea.reset();
446 
447  EndListening( *(SfxGetpApp()) );
449 
450  m_xEdCol.reset();
451  m_xEdRow.reset();
452  m_xTbxCmd1.reset();
453  m_xTbxCmd2.reset();
454  m_xDragModeMenu.reset();
455  m_xLbEntries.reset();
456  m_xWndScenarios.reset();
457  m_xScenarioBox.reset();
458  m_xLbDocuments.reset();
460 }
461 
463 {
464  if (const SfxEventHint* pHint = dynamic_cast<const SfxEventHint*>(&rHint))
465  {
466  if (pHint->GetEventId() == SfxEventHintId::ActivateDoc)
467  {
468  m_xLbEntries->ActiveDocChanged();
469  UpdateAll();
470  }
471  }
472  else
473  {
474  const SfxHintId nHintId = rHint.GetId();
475 
476  if (nHintId == SfxHintId::ScDocNameChanged)
477  {
478  m_xLbEntries->ActiveDocChanged();
479  }
480  else if (NAV_LMODE_NONE == eListMode)
481  {
482  // Table not any more
483  }
484  else
485  {
486  switch ( nHintId )
487  {
488  case SfxHintId::ScTablesChanged:
489  m_xLbEntries->Refresh( ScContentId::TABLE );
490  break;
491 
492  case SfxHintId::ScDbAreasChanged:
493  m_xLbEntries->Refresh( ScContentId::DBAREA );
494  break;
495 
496  case SfxHintId::ScAreasChanged:
498  break;
499 
500  case SfxHintId::ScDrawChanged:
504  break;
505 
506  case SfxHintId::ScAreaLinksChanged:
508  break;
509 
510  // SfxHintId::DocChanged not only at document change
511 
512  case SfxHintId::ScNavigatorUpdateAll:
513  UpdateAll();
514  break;
515 
516  case SfxHintId::ScDataChanged:
517  case SfxHintId::ScAnyDataChanged:
518  aContentIdle.Start(); // Do not search notes immediately
519  break;
520  case SfxHintId::ScKillEditView:
521  m_xLbEntries->ObjectFresh( ScContentId::OLEOBJECT );
522  m_xLbEntries->ObjectFresh( ScContentId::DRAWING );
523  m_xLbEntries->ObjectFresh( ScContentId::GRAPHIC );
524  break;
525  case SfxHintId::ScSelectionChanged:
526  UpdateSelection();
527  break;
528  default:
529  break;
530  }
531  }
532  }
533 }
534 
535 IMPL_LINK( ScNavigatorDlg, TimeHdl, Timer*, pIdle, void )
536 {
537  if ( pIdle != &aContentIdle )
538  return;
539 
540  m_xLbEntries->Refresh( ScContentId::NOTE );
541 }
542 
543 void ScNavigatorDlg::SetDropMode(sal_uInt16 nNew)
544 {
545  nDropMode = nNew;
546  UpdateButtons();
547  ScNavipiCfg& rCfg = SC_MOD()->GetNavipiCfg();
548  rCfg.SetDragMode(nDropMode);
549 }
550 
552 {
553  if ( (nColNo+1 != nCurCol) || (nRowNo+1 != nCurRow) )
554  {
555  // SID_CURRENTCELL == Item #0 clear cache, so it's possible
556  // setting the current cell even in combined areas
557  mvBoundItems[0]->ClearCache();
558 
559  ScAddress aScAddress( nColNo, nRowNo, 0 );
560  OUString aAddr(aScAddress.Format(ScRefFlags::ADDR_ABS));
561 
562  bool bUnmark = false;
563  if ( GetViewData() )
564  bUnmark = !pViewData->GetMarkData().IsCellMarked( nColNo, nRowNo );
565 
566  SfxStringItem aPosItem( SID_CURRENTCELL, aAddr );
567  SfxBoolItem aUnmarkItem( FN_PARAM_1, bUnmark ); // cancel selection
568 
569  rBindings.GetDispatcher()->ExecuteList(SID_CURRENTCELL,
570  SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
571  { &aPosItem, &aUnmarkItem });
572  }
573 }
574 
575 void ScNavigatorDlg::SetCurrentCellStr( const OUString& rName )
576 {
577  mvBoundItems[0]->ClearCache();
578  SfxStringItem aNameItem( SID_CURRENTCELL, rName );
579 
580  rBindings.GetDispatcher()->ExecuteList(SID_CURRENTCELL,
581  SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
582  { &aNameItem });
583 }
584 
586 {
587  if ( nTabNo != nCurTab )
588  {
589  // Table for basic is base-1
590  SfxUInt16Item aTabItem( SID_CURRENTTAB, static_cast<sal_uInt16>(nTabNo) + 1 );
591  rBindings.GetDispatcher()->ExecuteList(SID_CURRENTTAB,
592  SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
593  { &aTabItem });
594  }
595 }
596 
597 void ScNavigatorDlg::SetCurrentTableStr( const OUString& rName )
598 {
599  if (!GetViewData()) return;
600 
601  ScDocument* pDoc = pViewData->GetDocument();
602  SCTAB nCount = pDoc->GetTableCount();
603  OUString aTabName;
604  SCTAB nLastSheet = 0;
605 
606  for (SCTAB i = 0; i<nCount; i++)
607  {
608  pDoc->GetName(i, aTabName);
609  if (aTabName == rName)
610  {
611  // Check if this is a Scenario sheet and if so select the sheet
612  // where it belongs to, which is the previous non-Scenario sheet.
613  if (pDoc->IsScenario(i))
614  {
615  SetCurrentTable(nLastSheet);
616  return;
617  }
618  else
619  {
621  return;
622  }
623  }
624  else
625  {
626  if (!pDoc->IsScenario(i))
627  nLastSheet = i;
628  }
629  }
630 }
631 
632 void ScNavigatorDlg::SetCurrentObject( const OUString& rName )
633 {
634  SfxStringItem aNameItem( SID_CURRENTOBJECT, rName );
635  rBindings.GetDispatcher()->ExecuteList( SID_CURRENTOBJECT,
636  SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
637  { &aNameItem });
638 }
639 
640 void ScNavigatorDlg::SetCurrentDoc( const OUString& rDocName ) // activate
641 {
642  SfxStringItem aDocItem( SID_CURRENTDOC, rDocName );
643  rBindings.GetDispatcher()->ExecuteList( SID_CURRENTDOC,
644  SfxCallMode::SYNCHRON | SfxCallMode::RECORD,
645  { &aDocItem });
646 }
647 
649 {
650  ScTabViewShell* pViewSh = GetTabViewShell();
651  if( !pViewSh )
652  return;
653 
654  uno::Reference< drawing::XShapes > xShapes = pViewSh->getSelectedXShapes();
655  if( xShapes )
656  {
657  uno::Reference< container::XIndexAccess > xIndexAccess(
658  xShapes, uno::UNO_QUERY_THROW );
659  if( xIndexAccess->getCount() > 1 )
660  return;
661  uno::Reference< drawing::XShape > xShape;
662  if( xIndexAccess->getByIndex(0) >>= xShape )
663  {
664  uno::Reference< container::XNamed > xNamed( xShape, uno::UNO_QUERY_THROW );
665  OUString sName = xNamed->getName();
666  if (!sName.isEmpty())
667  {
668  m_xLbEntries->SelectEntryByName( ScContentId::DRAWING, sName );
669  }
670  }
671  }
672 }
673 
675 {
676  return dynamic_cast<ScTabViewShell*>( SfxViewShell::Current() );
677 }
678 
680 {
681  // Don't store the settings pointer here, because the settings belong to
682  // the view, and the view may be closed while the navigator is open (reload).
683  // If the pointer is cached here again later for performance reasons, it has to
684  // be forgotten when the view is closed.
685 
686  ScTabViewShell* pViewSh = GetTabViewShell();
687  return pViewSh ? pViewSh->GetNavigatorSettings() : nullptr;
688 }
689 
691 {
692  ScTabViewShell* pViewSh = GetTabViewShell();
693  pViewData = pViewSh ? &pViewSh->GetViewData() : nullptr;
694  return pViewData;
695 }
696 
698 {
699  if ( pCol )
700  nCurCol = *pCol;
701  else if ( GetViewData() )
702  nCurCol = pViewData->GetCurX() + 1;
703 
704  m_xEdCol->set_value(nCurCol);
705 }
706 
707 void ScNavigatorDlg::UpdateRow( const SCROW* pRow )
708 {
709  if ( pRow )
710  nCurRow = *pRow;
711  else if ( GetViewData() )
712  nCurRow = pViewData->GetCurY() + 1;
713 
714  m_xEdRow->set_value(nCurRow);
715 }
716 
718 {
719  if ( pTab )
720  nCurTab = *pTab;
721  else if ( GetViewData() )
723 }
724 
726 {
727  switch (eListMode)
728  {
729  case NAV_LMODE_AREAS:
730  m_xLbEntries->Refresh();
731  break;
732  case NAV_LMODE_NONE:
734  break;
735  default:
736  break;
737  }
738 
739  aContentIdle.Stop(); // not again
740 }
741 
743 {
744  if (eMode != eListMode)
745  {
746  bool bForceParentResize = SfxChildWindowContext::GetFloatingWindow(GetParent()) &&
747  (eMode == NAV_LMODE_NONE || eListMode == NAV_LMODE_NONE);
748  SfxNavigator* pNav = bForceParentResize ? dynamic_cast<SfxNavigator*>(GetParent()) : nullptr;
749  if (pNav && eMode == NAV_LMODE_NONE) //save last normal size on minimizing
750  aExpandedSize = GetSizePixel();
751 
752  eListMode = eMode;
753 
754  switch (eMode)
755  {
756  case NAV_LMODE_NONE:
757  ShowList(false);
758  break;
759  case NAV_LMODE_AREAS:
760  m_xLbEntries->Refresh();
761  ShowList(true);
762  break;
763  case NAV_LMODE_SCENARIOS:
764  ShowScenarios();
765  break;
766  }
767 
768  UpdateButtons();
769 
770  if (eMode != NAV_LMODE_NONE)
771  {
772  ScNavipiCfg& rCfg = SC_MOD()->GetNavipiCfg();
773  rCfg.SetListMode( static_cast<sal_uInt16>(eMode) );
774  }
775 
776  if (pNav)
777  {
778  Size aOptimalSize(GetOptimalSize());
779  Size aNewSize(pNav->GetOutputSizePixel());
780  aNewSize.setHeight( eMode == NAV_LMODE_NONE ? aOptimalSize.Height() : aExpandedSize.Height() );
781  pNav->SetMinOutputSizePixel(aOptimalSize);
782  pNav->SetOutputSizePixel(aNewSize);
783  }
784  }
785 
786  if (pMarkArea)
787  UnmarkDataArea();
788 }
789 
790 void ScNavigatorDlg::ShowList(bool bShow)
791 {
792  if (bShow)
793  {
794  m_xLbEntries->show();
795  m_xLbDocuments->show();
796  }
797  else
798  {
799  m_xLbEntries->hide();
800  m_xLbDocuments->hide();
801  }
802  m_xScenarioBox->hide();
803 }
804 
806 {
807  rBindings.Invalidate( SID_SELECT_SCENARIO );
808  rBindings.Update( SID_SELECT_SCENARIO );
809 
810  m_xScenarioBox->show();
811  m_xLbDocuments->show();
812  m_xLbEntries->hide();
813 }
814 
815 // documents for Dropdown-Listbox
816 void ScNavigatorDlg::GetDocNames( const OUString* pManualSel )
817 {
818  m_xLbDocuments->clear();
819  m_xLbDocuments->freeze();
820 
821  ScDocShell* pCurrentSh = dynamic_cast<ScDocShell*>( SfxObjectShell::Current() );
822 
823  OUString aSelEntry;
825  while ( pSh )
826  {
827  if ( dynamic_cast<const ScDocShell*>( pSh) != nullptr )
828  {
829  OUString aName = pSh->GetTitle();
830  OUString aEntry = aName;
831  if (pSh == pCurrentSh)
832  aEntry += aStrActive;
833  else
834  aEntry += aStrNotActive;
835  m_xLbDocuments->append_text(aEntry);
836 
837  if ( pManualSel ? ( aName == *pManualSel )
838  : ( pSh == pCurrentSh ) )
839  aSelEntry = aEntry; // complete entry for selection
840  }
841 
842  pSh = SfxObjectShell::GetNext( *pSh );
843  }
844 
845  m_xLbDocuments->append_text(aStrActiveWin);
846 
847  OUString aHidden = m_xLbEntries->GetHiddenTitle();
848  if (!aHidden.isEmpty())
849  {
850  OUString aEntry = aHidden + aStrHidden;
851  m_xLbDocuments->append_text(aEntry);
852 
853  if ( pManualSel && aHidden == *pManualSel )
854  aSelEntry = aEntry;
855  }
856 
857  m_xLbDocuments->thaw();
858 
859  m_xLbDocuments->set_active_text(aSelEntry);
860 }
861 
863 {
864  ScTabViewShell* pViewSh = GetTabViewShell();
865 
866  if ( pViewSh )
867  {
868  if ( !pMarkArea )
869  pMarkArea.reset( new ScArea );
870 
871  pViewSh->MarkDataArea();
872  ScRange aMarkRange;
873  pViewSh->GetViewData().GetMarkData().GetMarkArea(aMarkRange);
874  pMarkArea->nColStart = aMarkRange.aStart.Col();
875  pMarkArea->nRowStart = aMarkRange.aStart.Row();
876  pMarkArea->nColEnd = aMarkRange.aEnd.Col();
877  pMarkArea->nRowEnd = aMarkRange.aEnd.Row();
878  pMarkArea->nTab = aMarkRange.aStart.Tab();
879  }
880 }
881 
883 {
884  ScTabViewShell* pViewSh = GetTabViewShell();
885 
886  if ( pViewSh )
887  {
888  pViewSh->Unmark();
889  pMarkArea.reset();
890  }
891 }
892 
894 {
895  // pMarkArea evaluate ???
896 
897  if ( GetViewData() )
898  {
899  ScMarkData& rMark = pViewData->GetMarkData();
900  ScRange aMarkRange;
901  rMark.GetMarkArea( aMarkRange );
902 
903  SCCOL nCol = aMarkRange.aStart.Col();
904  SCROW nRow = aMarkRange.aStart.Row();
905 
906  if ( (nCol+1 != m_xEdCol->get_value()) || (nRow+1 != m_xEdRow->get_value()) )
907  SetCurrentCell( nCol, nRow );
908  }
909 }
910 
912 {
913  // pMarkArea evaluate ???
914 
915  if ( GetViewData() )
916  {
917  ScMarkData& rMark = pViewData->GetMarkData();
918  ScRange aMarkRange;
919  rMark.GetMarkArea( aMarkRange );
920 
921  SCCOL nCol = aMarkRange.aEnd.Col();
922  SCROW nRow = aMarkRange.aEnd.Row();
923 
924  if ( (nCol+1 != m_xEdCol->get_value()) || (nRow+1 != m_xEdRow->get_value()) )
925  SetCurrentCell( nCol, nRow );
926  }
927 }
928 
929 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3053
std::unique_ptr< weld::ComboBox > m_xLbDocuments
Definition: navipi.hxx:105
long Width() const
sal_uInt16 GetDragMode() const
Definition: navicfg.hxx:42
SC_DLLPUBLIC void Format(OStringBuffer &r, ScRefFlags nFlags, const ScDocument *pDocument=nullptr, const Details &rDetails=detailsOOOa1) const
Definition: address.cxx:2111
void MarkDataArea(bool bIncludeCursor=true)
Definition: tabview3.cxx:1644
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
SfxHintId
ScAddress aStart
Definition: address.hxx:500
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
void SetMinOutputSizePixel(const Size &rSize)
FactoryFunction GetUITestFactory() const override
Definition: navipi.cxx:429
SCROW Row() const
Definition: address.hxx:262
void SetCurrentTable(SCTAB nTab)
Definition: navipi.cxx:585
OUString GetTitle(sal_uInt16 nMaxLen=0) const
ScViewData * pViewData
Definition: navipi.hxx:117
long Height() const
SCROW nCurRow
Definition: navipi.hxx:122
SCROW GetCurY() const
Definition: viewdata.hxx:402
void EndOfDataArea()
Definition: navipi.cxx:911
void UpdateTable(const SCTAB *pTab)
Definition: navipi.cxx:717
void ScColToAlpha(OUStringBuffer &rBuf, SCCOL nCol)
append alpha representation of column to buffer
Definition: address.cxx:1921
std::function< std::unique_ptr< UIObject >vcl::Window *)> FactoryFunction
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
OUString aStrNotActive
Definition: navipi.hxx:112
Contains settings of the navigator listbox.
Definition: navsett.hxx:30
void Unmark()
Definition: tabview3.cxx:1711
ScAddress aEnd
Definition: address.hxx:501
static SfxObjectShell * Current()
std::unique_ptr< weld::SpinButton > m_xEdCol
Definition: navipi.hxx:98
void Invalidate(sal_uInt16 nId)
SfxHintId GetId() const
void GetDocNames(const OUString *pSelEntry)
Definition: navipi.cxx:816
void fill(V val)
virtual Size GetOptimalSize() const override
bool IsCellMarked(SCCOL nCol, SCROW nRow, bool bNoSimple=false) const
Definition: markdata.cxx:285
SfxApplication * SfxGetpApp()
css::uno::Reference< css::drawing::XShapes > getSelectedXShapes()
Definition: viewuno.cxx:825
void GetMarkArea(ScRange &rRange) const
Definition: markdata.cxx:112
void UpdateAll()
Definition: navipi.cxx:725
StateChangedType
void StartOfDataArea()
Definition: navipi.cxx:893
o3tl::enumarray< ScContentId, bool > maExpandedVec
Definition: navsett.hxx:33
SCCOL nCurCol
Definition: navipi.hxx:121
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:314
int nCount
static SfxViewShell * Current()
virtual void Start() override
Mode eMode
SCTAB Tab() const
Definition: address.hxx:271
ScDocument * GetDocument() const
Definition: viewdata.cxx:859
void SetCurrentObject(const OUString &rName)
Definition: navipi.cxx:632
const char * sName
ScViewData & GetViewData()
Definition: tabview.hxx:332
void ShowScenarios()
Definition: navipi.cxx:805
std::unique_ptr< ScScenarioWindow > m_xWndScenarios
Definition: navipi.hxx:104
virtual void StateChanged(StateChangedType nStateChange) override
Definition: navipi.cxx:417
std::unique_ptr< ScArea > pMarkArea
Definition: navipi.hxx:116
OUString aStrActiveWin
Definition: navipi.hxx:114
std::unique_ptr< weld::Toolbar > m_xTbxCmd2
Definition: navipi.hxx:101
ScContentId GetRootType() const
Definition: navicfg.hxx:44
int i
NavListMode eListMode
Definition: navipi.hxx:119
sal_Int16 SCCOL
Definition: types.hxx:22
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: navipi.cxx:462
#define SC_MOD()
Definition: scmod.hxx:253
Idle aContentIdle
Definition: navipi.hxx:109
void UpdateButtons()
Definition: navipi.cxx:263
ScNavigatorSettings * GetNavigatorSettings()
Definition: tabvwsh4.cxx:1828
static ScTabViewShell * GetTabViewShell()
Definition: navipi.cxx:674
void ShowList(bool bShow)
Definition: navipi.cxx:790
OUString ScResId(const char *pId)
Definition: scdll.cxx:95
void SetDragMode(sal_uInt16 nNew)
Definition: navicfg.cxx:42
void SetCurrentDoc(const OUString &rDocName)
Definition: navipi.cxx:640
void UpdateRow(const SCROW *pRow=nullptr)
Definition: navipi.cxx:707
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
ScContentId
Definition: content.hxx:35
void GrabFocus()
std::array< std::unique_ptr< ScNavigatorControllerItem >, CTRL_ITEMS > mvBoundItems
Definition: navipi.hxx:125
ScNavigatorDlg(SfxBindings *pB, vcl::Window *pParent)
Definition: navipi.cxx:319
SCCOL Col() const
Definition: address.hxx:267
void SetCurrentCellStr(const OUString &rName)
Definition: navipi.cxx:575
void UnmarkDataArea()
Definition: navipi.cxx:882
virtual void dispose() override
Definition: navipi.cxx:439
friend class ScNavigatorControllerItem
Definition: navipi.hxx:88
void Update(sal_uInt16 nId)
virtual void dispose() override
bool AlphaToCol(const ScDocument &rDoc, SCCOL &rCol, const OUString &rStr)
get column number of A..IV... string
Definition: address.cxx:2538
sal_Int32 SCROW
Definition: types.hxx:18
std::unique_ptr< weld::Widget > m_xScenarioBox
Definition: navipi.hxx:103
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:399
static ScNavigatorSettings * GetNavigatorSettings()
Definition: navipi.cxx:679
void Stop()
SC_DLLPUBLIC bool IsScenario(SCTAB nTab) const
Definition: documen3.cxx:413
void UpdateSelection()
Definition: navipi.cxx:648
OUString aStrHidden
Definition: navipi.hxx:113
static SfxObjectShell * GetFirst(const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
std::unique_ptr< weld::Menu > m_xDragModeMenu
Definition: navipi.hxx:106
ScNavigatorSettings()
Index of selected child entry.
Definition: navipi.cxx:298
OUString aName
std::unique_ptr< ScContentTree > m_xLbEntries
Definition: navipi.hxx:102
static VclPtr< reference_type > Create(Arg &&...arg)
SfxBindings & rBindings
Definition: navipi.hxx:96
#define SFX_IMPL_CHILDWINDOWCONTEXT(Class, MyID)
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
void SetCurrentCell(SCCOL nCol, SCROW Row)
Definition: navipi.cxx:551
sal_uInt16 GetListMode() const
Definition: navicfg.hxx:40
void * p
void SetInvokeHandler(const Link< Timer *, void > &rLink)
vcl::Window * GetWindow() const
static FloatingWindow * GetFloatingWindow(vcl::Window *pParent)
static bool isAsciiNumeric(const OUString &rStr)
ROOT
void SetDropMode(sal_uInt16 nNew)
Definition: navipi.cxx:543
SfxDispatcher * GetDispatcher() const
Any result
static SfxObjectShell * GetNext(const SfxObjectShell &rPrev, const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
void SetPriority(TaskPriority ePriority)
static void ReleaseFocus()
Definition: navipi.cxx:58
std::unique_ptr< weld::SpinButton > m_xEdRow
Definition: navipi.hxx:99
void SetListMode(NavListMode eMode)
Definition: navipi.cxx:742
ScViewData * GetViewData()
Definition: navipi.cxx:690
void UpdateColumn(const SCCOL *pCol=nullptr)
Definition: navipi.cxx:697
virtual ~ScNavigatorDlg() override
Definition: navipi.cxx:434
static bool isAsciiAlpha(const OUString &rStr)
OUString aStrActive
Definition: navipi.hxx:111
aStr
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
Definition: document.cxx:213
Size aExpandedSize
Definition: navipi.hxx:108
void MarkDataArea()
Definition: navipi.cxx:862
sal_uInt16 nDropMode
Definition: navipi.hxx:120
SCTAB nCurTab
Definition: navipi.hxx:123
sal_Int16 SCTAB
Definition: types.hxx:23
void SetListMode(sal_uInt16 nNew)
Definition: navicfg.cxx:33
SCCOL GetCurX() const
Definition: viewdata.hxx:401
const sal_uLong SC_CONTENT_NOCHILD
Definition: content.hxx:41
std::unique_ptr< weld::Toolbar > m_xTbxCmd1
Definition: navipi.hxx:100
void setHeight(long nHeight)
void SetCurrentTableStr(const OUString &rName)
Definition: navipi.cxx:597