LibreOffice Module sc (master)  1
checklistmenu.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 <checklistmenu.hxx>
21 #include <globstr.hrc>
22 #include <scresid.hxx>
23 #include <strings.hrc>
24 #include <bitmaps.hlst>
25 
26 #include <vcl/decoview.hxx>
27 #include <vcl/event.hxx>
28 #include <vcl/dockwin.hxx>
29 #include <vcl/settings.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/virdev.hxx>
32 #include <rtl/math.hxx>
33 #include <tools/wintypes.hxx>
34 #include <unotools/charclass.hxx>
35 
36 #include <document.hxx>
37 
38 using namespace com::sun::star;
39 using ::com::sun::star::uno::Reference;
40 
42  : mbEnabled(true)
43 {
44 }
45 
47  : mpSubMenu(nullptr)
48  , mnMenuPos(MENU_NOT_SELECTED)
49  , mpParent(pParent)
50 {
52  maTimer.SetTimeout(Application::GetSettings().GetMouseSettings().GetMenuDelay());
53 }
54 
56 {
57  mpSubMenu = nullptr;
58  mnMenuPos = MENU_NOT_SELECTED;
59  maTimer.Stop();
60 }
61 
63 {
64  mpParent->handleMenuTimeout(this);
65 }
66 
68 {
69  executeMenuItem(mxMenu->get_selected_index());
70  return true;
71 }
72 
73 IMPL_LINK(ScCheckListMenuControl, MenuKeyInputHdl, const KeyEvent&, rKEvt, bool)
74 {
75  const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode();
76 
77  switch (rKeyCode.GetCode())
78  {
79  case KEY_LEFT:
80  {
82  if (pParentMenu)
83  pParentMenu->get_widget().endSubMenu(*this);
84  break;
85  }
86  case KEY_RIGHT:
87  {
89  break;
90 
91  const MenuItemData& rMenu = maMenuItems[mnSelectedMenu];
92  if (!rMenu.mbEnabled || !rMenu.mxSubMenuWin)
93  break;
94 
96  maOpenTimer.mpSubMenu = rMenu.mxSubMenuWin.get();
97  launchSubMenu(true);
98  }
99  }
100 
101  return false;
102 }
103 
105 {
106  sal_uInt32 nSelectedMenu = MENU_NOT_SELECTED;
107  if (!mxMenu->get_selected(mxScratchIter.get()))
108  {
109  // reselect current item if its submenu is up and the launching item
110  // became unselected
111  if (mnSelectedMenu < maMenuItems.size() &&
112  maMenuItems[mnSelectedMenu].mxSubMenuWin &&
113  maMenuItems[mnSelectedMenu].mxSubMenuWin->IsVisible())
114  {
115  mxMenu->select(mnSelectedMenu);
116  return;
117  }
118  }
119  else
120  nSelectedMenu = mxMenu->get_iter_index_in_parent(*mxScratchIter);
121 
122  setSelectedMenuItem(nSelectedMenu, true);
123 }
124 
125 void ScCheckListMenuControl::addMenuItem(const OUString& rText, Action* pAction)
126 {
127  MenuItemData aItem;
128  aItem.mbEnabled = true;
129  aItem.mxAction.reset(pAction);
130  maMenuItems.emplace_back(std::move(aItem));
131 
132  mxMenu->append_text(rText);
133  if (mbCanHaveSubMenu)
134  mxMenu->set_image(mxMenu->n_children() - 1, css::uno::Reference<css::graphic::XGraphic>(), 1);
135 }
136 
138 {
139  MenuItemData aItem;
140  maMenuItems.emplace_back(std::move(aItem));
141 
142  mxMenu->append_separator("separator" + OUString::number(maMenuItems.size()));
143 }
144 
145 IMPL_LINK(ScCheckListMenuControl, TreeSizeAllocHdl, const Size&, rSize, void)
146 {
148  std::vector<int> aWidths;
149  aWidths.push_back(rSize.Width() - (mxMenu->get_text_height() * 3) / 4 - 6);
150  mxMenu->set_column_fixed_widths(aWidths);
151 }
152 
154 {
155  int nWidth = (mxMenu->get_text_height() * 3) / 4;
156  mxDropDown->SetOutputSizePixel(Size(nWidth, nWidth));
157  DecorationView aDecoView(mxDropDown.get());
158  aDecoView.DrawSymbol(tools::Rectangle(Point(0, 0), Size(nWidth, nWidth)),
159  SymbolType::SPIN_RIGHT, mxDropDown->GetTextColor(),
160  DrawSymbolFlags::NONE);
161 }
162 
163 ScCheckListMenuWindow* ScCheckListMenuControl::addSubMenuItem(const OUString& rText, bool bEnabled)
164 {
166 
167  MenuItemData aItem;
168  aItem.mbEnabled = bEnabled;
169  vcl::Window *pContainer = mxFrame->GetWindow(GetWindowType::FirstChild);
171  false, -1, mxFrame.get()));
172  maMenuItems.emplace_back(std::move(aItem));
173 
174  mxMenu->append_text(rText);
175  if (mbCanHaveSubMenu)
176  mxMenu->set_image(mxMenu->n_children() - 1, *mxDropDown, 1);
177 
178  return maMenuItems.back().mxSubMenuWin.get();
179 }
180 
182 {
183  if (nPos >= maMenuItems.size())
184  return;
185 
186  if (!maMenuItems[nPos].mxAction)
187  // no action is defined.
188  return;
189 
191 
192  maMenuItems[nPos].mxAction->execute();
193 }
194 
195 void ScCheckListMenuControl::setSelectedMenuItem(size_t nPos, bool bSubMenuTimer)
196 {
197  if (mnSelectedMenu == nPos)
198  // nothing to do.
199  return;
200 
201  selectMenuItem(nPos, bSubMenuTimer);
202 }
203 
205 {
206  if (pTimer == &maOpenTimer)
207  {
208  // Close any open submenu immediately.
210  {
212  maCloseTimer.mpSubMenu = nullptr;
214  }
215 
216  launchSubMenu(false);
217  }
218  else if (pTimer == &maCloseTimer)
219  {
220  // end submenu.
222  {
223  maOpenTimer.mpSubMenu = nullptr;
224 
226  maCloseTimer.mpSubMenu = nullptr;
227 
229  }
230  }
231 }
232 
234 {
235  if (!pMenu)
236  return;
237 
238  // Set the submenu on launch queue.
240  {
241  if (maOpenTimer.mpSubMenu == pMenu)
242  {
243  if (pMenu == maCloseTimer.mpSubMenu)
245  return;
246  }
247 
248  // new submenu is being requested.
250  }
251 
252  maOpenTimer.mpSubMenu = pMenu;
253  maOpenTimer.mnMenuPos = nPos;
255 }
256 
258 {
259  if (!maOpenTimer.mpSubMenu)
260  // There is no submenu to close.
261  return;
262 
263  // Stop any submenu on queue for opening.
265 
269 }
270 
272 {
274  if (!pSubMenu)
275  return;
276 
277  if (!mxMenu->get_selected(mxScratchIter.get()))
278  return;
279 
280  tools::Rectangle aRect = mxMenu->get_row_area(*mxScratchIter);
281  ScCheckListMenuControl& rSubMenuControl = pSubMenu->get_widget();
282  rSubMenuControl.StartPopupMode(aRect, FloatWinPopupFlags::Right);
283  if (bSetMenuPos)
284  rSubMenuControl.setSelectedMenuItem(0, false); // select menu item after the popup becomes fully visible.
285 
286  mxMenu->select(*mxScratchIter);
287  rSubMenuControl.GrabFocus();
288 }
289 
290 IMPL_LINK_NOARG(ScCheckListMenuControl, PostPopdownHdl, void*, void)
291 {
292  mnAsyncPostPopdownId = nullptr;
293  mxMenu->grab_focus();
294 }
295 
297 {
298  rSubMenu.EndPopupMode();
299  maOpenTimer.reset();
300 
301  // EndPopup sends a user event, and we want this focus to be set after that has done its conflicting focus-setting work
304 
305  size_t nMenuPos = getSubMenuPos(&rSubMenu);
306  if (nMenuPos != MENU_NOT_SELECTED)
307  {
308  mnSelectedMenu = nMenuPos;
309  mxMenu->select(mnSelectedMenu);
310  }
311 }
312 
314 {
315  mxMenu->set_size_request(-1, mxMenu->get_preferred_size().Height() + 2);
316 }
317 
318 void ScCheckListMenuControl::selectMenuItem(size_t nPos, bool bSubMenuTimer)
319 {
320  mxMenu->select(nPos == MENU_NOT_SELECTED ? -1 : nPos);
321  mnSelectedMenu = nPos;
322 
323  if (nPos >= maMenuItems.size() || nPos == MENU_NOT_SELECTED)
324  {
326  return;
327  }
328 
329  if (!maMenuItems[nPos].mbEnabled)
330  {
332  return;
333  }
334 
335  ScCheckListMenuWindow* pParentMenu = mxFrame->GetParentMenu();
336  if (pParentMenu)
337  pParentMenu->get_widget().setSubMenuFocused(this);
338 
339  if (bSubMenuTimer)
340  {
341  if (maMenuItems[nPos].mxSubMenuWin)
342  {
343  ScCheckListMenuWindow* pSubMenu = maMenuItems[nPos].mxSubMenuWin.get();
344  queueLaunchSubMenu(nPos, pSubMenu);
345  }
346  else
348  }
349 }
350 
352 {
354 }
355 
357 {
358  size_t n = maMenuItems.size();
359  for (size_t i = 0; i < n; ++i)
360  {
361  if (!maMenuItems[i].mxSubMenuWin)
362  continue;
363  if (&maMenuItems[i].mxSubMenuWin->get_widget() == pSubMenu)
364  return i;
365  }
366  return MENU_NOT_SELECTED;
367 }
368 
370 {
372  size_t nMenuPos = getSubMenuPos(pSubMenu);
373  if (mnSelectedMenu != nMenuPos)
374  {
375  mnSelectedMenu = nMenuPos;
376  mxMenu->select(mnSelectedMenu);
377  }
378 }
379 
381 {
383  mxFrame->EnableDocking(false);
384 }
385 
387 {
388  mxFrame->EnableDocking(true);
389  DockingManager* pDockingManager = vcl::Window::GetDockingManager();
390  pDockingManager->SetPopupModeEndHdl(mxFrame, LINK(this, ScCheckListMenuControl, PopupModeEndHdl));
391  pDockingManager->StartPopupMode(mxFrame, rRect, (eFlags | FloatWinPopupFlags::GrabFocus));
392 }
393 
395 {
396  EndPopupMode();
397  ScCheckListMenuWindow* pParentMenu = mxFrame->GetParentMenu();
398  if (pParentMenu)
399  pParentMenu->get_widget().terminateAllPopupMenus();
400 }
401 
403  mbAllowEmptySet(true), mbRTL(false)
404 {
405 }
406 
408  : mbVisible(true)
409  , mbDate(false)
410  , mbLeaf(false)
411  , meDatePartType(YEAR)
412 {
413 }
414 
416  ScDocument* pDoc, bool bCanHaveSubMenu,
417  bool bHasDates, int nWidth)
418  : mxFrame(pParent)
419  , mxBuilder(Application::CreateInterimBuilder(pContainer, "modules/scalc/ui/filterdropdown.ui", false))
420  , mxContainer(mxBuilder->weld_container("FilterDropDown"))
421  , mxMenu(mxBuilder->weld_tree_view("menu"))
422  , mxScratchIter(mxMenu->make_iterator())
423  , mxEdSearch(mxBuilder->weld_entry("search_edit"))
424  , mxBox(mxBuilder->weld_widget("box"))
425  , mxListChecks(mxBuilder->weld_tree_view("check_list_box"))
426  , mxTreeChecks(mxBuilder->weld_tree_view("check_tree_box"))
427  , mxChkToggleAll(mxBuilder->weld_check_button("toggle_all"))
428  , mxBtnSelectSingle(mxBuilder->weld_button("select_current"))
429  , mxBtnUnselectSingle(mxBuilder->weld_button("unselect_current"))
430  , mxButtonBox(mxBuilder->weld_box("buttonbox"))
431  , mxBtnOk(mxBuilder->weld_button("ok"))
432  , mxBtnCancel(mxBuilder->weld_button("cancel"))
433  , mxDropDown(mxMenu->create_virtual_device())
434  , mnCheckWidthReq(-1)
435  , mnWndWidth(0)
436  , mePrevToggleAllState(TRISTATE_INDET)
437  , mnSelectedMenu(MENU_NOT_SELECTED)
438  , mpDoc(pDoc)
439  , mnAsyncPostPopdownId(nullptr)
440  , mbHasDates(bHasDates)
441  , mbCanHaveSubMenu(bCanHaveSubMenu)
442  , maOpenTimer(this)
443  , maCloseTimer(this)
444 {
445  /*
446  tdf#136559 If we have no dates we don't need a tree
447  structure, just a list. GtkListStore can be then
448  used which is much faster than a GtkTreeStore, so
449  with no dates switch to the treeview which uses the
450  faster GtkListStore
451  */
452  if (mbHasDates)
453  mpChecks = mxTreeChecks.get();
454  else
455  {
456  mxTreeChecks->hide();
457  mxListChecks->show();
458  mpChecks = mxListChecks.get();
459  }
460 
461  bool bIsSubMenu = pParent->GetParentMenu();
462 
463  int nChecksHeight = mxTreeChecks->get_height_rows(9);
464  if (!bIsSubMenu && nWidth != -1)
465  {
466  mnCheckWidthReq = nWidth - mxFrame->get_border_width() * 2 - 4;
467  mxTreeChecks->set_size_request(mnCheckWidthReq, nChecksHeight);
468  mxListChecks->set_size_request(mnCheckWidthReq, nChecksHeight);
469  }
470 
471  // sort ok/cancel into native order, if this was a dialog they would be auto-sorted, but this
472  // popup isn't a true dialog
473  mxButtonBox->sort_native_button_order();
474 
475  if (!bIsSubMenu)
476  {
477  mxTreeChecks->enable_toggle_buttons(weld::ColumnToggleType::Check);
478  mxListChecks->enable_toggle_buttons(weld::ColumnToggleType::Check);
479 
480  mxBox->show();
481  mxEdSearch->show();
482  mxButtonBox->show();
483  }
484 
485  mxContainer->connect_focus_in(LINK(this, ScCheckListMenuControl, FocusHdl));
486  mxMenu->connect_row_activated(LINK(this, ScCheckListMenuControl, RowActivatedHdl));
487  mxMenu->connect_changed(LINK(this, ScCheckListMenuControl, SelectHdl));
488  mxMenu->connect_key_press(LINK(this, ScCheckListMenuControl, MenuKeyInputHdl));
489 
490  if (!bIsSubMenu)
491  {
492  mxBtnOk->connect_clicked(LINK(this, ScCheckListMenuControl, ButtonHdl));
493  mxBtnCancel->connect_clicked(LINK(this, ScCheckListMenuControl, ButtonHdl));
494  mxEdSearch->connect_changed(LINK(this, ScCheckListMenuControl, EdModifyHdl));
495  mxEdSearch->connect_activate(LINK(this, ScCheckListMenuControl, EdActivateHdl));
496  mxTreeChecks->connect_toggled(LINK(this, ScCheckListMenuControl, CheckHdl));
497  mxTreeChecks->connect_key_press(LINK(this, ScCheckListMenuControl, KeyInputHdl));
498  mxListChecks->connect_toggled(LINK(this, ScCheckListMenuControl, CheckHdl));
499  mxListChecks->connect_key_press(LINK(this, ScCheckListMenuControl, KeyInputHdl));
500  mxChkToggleAll->connect_toggled(LINK(this, ScCheckListMenuControl, TriStateHdl));
501  mxBtnSelectSingle->connect_clicked(LINK(this, ScCheckListMenuControl, ButtonHdl));
502  mxBtnUnselectSingle->connect_clicked(LINK(this, ScCheckListMenuControl, ButtonHdl));
503  }
504 
505  if (mbCanHaveSubMenu)
506  {
507  CreateDropDown();
508  mxMenu->connect_size_allocate(LINK(this, ScCheckListMenuControl, TreeSizeAllocHdl));
509  }
510 
511  if (!bIsSubMenu)
512  {
513  // determine what width the checklist will end up with
514  mnCheckWidthReq = mxContainer->get_preferred_size().Width();
515  // make that size fixed now, we can now use mnCheckWidthReq to speed up
516  // bulk_insert_for_each
517  mxTreeChecks->set_size_request(mnCheckWidthReq, nChecksHeight);
518  mxListChecks->set_size_request(mnCheckWidthReq, nChecksHeight);
519  }
520 }
521 
523 {
524  GrabFocus();
525 }
526 
528 {
529  if (mxEdSearch->get_visible())
530  mxEdSearch->grab_focus();
531  else
532  {
533  mxMenu->set_cursor(0);
534  mxMenu->grab_focus();
535  }
536 }
537 
539 {
540  EndPopupMode();
541  for (auto& rMenuItem : maMenuItems)
542  rMenuItem.mxSubMenuWin.disposeAndClear();
544  {
546  mnAsyncPostPopdownId = nullptr;
547  }
548 }
549 
551  bool bTreeMode, int nWidth, ScCheckListMenuWindow* pParentMenu)
552  : DockingWindow(pParent, "InterimDockParent", "svx/ui/interimdockparent.ui")
553  , mxParentMenu(pParentMenu)
554  , mxBox(get("box"))
555 {
557  mxControl.reset(new ScCheckListMenuControl(this, mxBox.get(), pDoc, bCanHaveSubMenu, bTreeMode, nWidth));
558  SetBackground(Application::GetSettings().GetStyleSettings().GetMenuColor());
559  set_id("check_list_menu");
560 }
561 
563 {
564  if (rNEvt.GetType() == MouseNotifyEvent::MOUSEMOVE)
565  {
566  ScCheckListMenuControl& rMenuControl = get_widget();
567  rMenuControl.queueCloseSubMenu();
568  rMenuControl.clearSelectedMenuItem();
569  }
570  return DockingWindow::EventNotify(rNEvt);
571 }
572 
574 {
575  disposeOnce();
576 }
577 
579 {
580  mxControl.reset();
584 }
585 
587 {
589  if (!mxControl)
590  return;
591  mxControl->GrabFocus();
592 }
593 
595 {
596  mxMenu->set_size_request(-1, mxMenu->get_preferred_size().Height() + 2);
597  mnSelectedMenu = 0;
598  mxMenu->set_cursor(mnSelectedMenu);
599  mxMenu->unselect_all();
600 
601  mnWndWidth = mxContainer->get_preferred_size().Width() + mxFrame->get_border_width() * 2 + 4;
602 }
603 
605 {
606  mpChecks->all_foreach([this, bSet](weld::TreeIter& rEntry){
607  mpChecks->set_toggle(rEntry, bSet ? TRISTATE_TRUE : TRISTATE_FALSE);
608  return false;
609  });
610 
612  {
613  // We need to have at least one member selected.
614  mxBtnOk->set_sensitive(GetCheckedEntryCount() != 0);
615  }
616 }
617 
619 {
620  setAllMemberState(!bSet);
621  std::unique_ptr<weld::TreeIter> xEntry = mpChecks->make_iterator();
622  if (!mpChecks->get_cursor(xEntry.get()))
623  return;
624  mpChecks->set_toggle(*xEntry, bSet ? TRISTATE_TRUE : TRISTATE_FALSE);
625 }
626 
628 {
629  if (&rBtn == mxBtnOk.get())
630  close(true);
631  else if (&rBtn == mxBtnCancel.get())
632  close(false);
633  else if (&rBtn == mxBtnSelectSingle.get() || &rBtn == mxBtnUnselectSingle.get())
634  {
635  selectCurrentMemberOnly(&rBtn == mxBtnSelectSingle.get());
636  std::unique_ptr<weld::TreeIter> xEntry = mpChecks->make_iterator();
637  if (!mpChecks->get_cursor(xEntry.get()))
638  xEntry.reset();
639  Check(xEntry.get());
640  }
641 }
642 
644 {
645  switch (mePrevToggleAllState)
646  {
647  case TRISTATE_FALSE:
648  mxChkToggleAll->set_state(TRISTATE_TRUE);
649  setAllMemberState(true);
650  break;
651  case TRISTATE_TRUE:
652  mxChkToggleAll->set_state(TRISTATE_FALSE);
653  setAllMemberState(false);
654  break;
655  case TRISTATE_INDET:
656  default:
657  mxChkToggleAll->set_state(TRISTATE_TRUE);
658  setAllMemberState(true);
659  break;
660  }
661 
662  mePrevToggleAllState = mxChkToggleAll->get_state();
663 }
664 
665 namespace
666 {
667  void insertMember(weld::TreeView& rView, const weld::TreeIter& rIter, const ScCheckListMember& rMember, bool bChecked)
668  {
669  OUString aLabel = rMember.maName;
670  if (aLabel.isEmpty())
671  aLabel = ScResId(STR_EMPTYDATA);
672  rView.set_toggle(rIter, bChecked ? TRISTATE_TRUE : TRISTATE_FALSE);
673  rView.set_text(rIter, aLabel, 0);
674  }
675 }
676 
678 {
679  OUString aSearchText = mxEdSearch->get_text();
680  aSearchText = ScGlobal::getCharClassPtr()->lowercase( aSearchText );
681  bool bSearchTextEmpty = aSearchText.isEmpty();
682  size_t n = maMembers.size();
683  size_t nSelCount = 0;
684 
685  mpChecks->freeze();
686 
687  // This branch is the general case, the other is an optimized variant of
688  // this one where we can take advantage of knowing we have no hierarchy
689  if (mbHasDates)
690  {
691  bool bSomeDateDeletes = false;
692 
693  for (size_t i = 0; i < n; ++i)
694  {
695  bool bIsDate = maMembers[i].mbDate;
696  bool bPartialMatch = false;
697 
698  OUString aLabelDisp = maMembers[i].maName;
699  if ( aLabelDisp.isEmpty() )
700  aLabelDisp = ScResId( STR_EMPTYDATA );
701 
702  if ( !bSearchTextEmpty )
703  {
704  if ( !bIsDate )
705  bPartialMatch = ( ScGlobal::getCharClassPtr()->lowercase( aLabelDisp ).indexOf( aSearchText ) != -1 );
706  else if ( maMembers[i].meDatePartType == ScCheckListMember::DAY ) // Match with both numerical and text version of month
707  bPartialMatch = (ScGlobal::getCharClassPtr()->lowercase( OUString(
708  maMembers[i].maRealName + maMembers[i].maDateParts[1] )).indexOf( aSearchText ) != -1);
709  else
710  continue;
711  }
712  else if ( bIsDate && maMembers[i].meDatePartType != ScCheckListMember::DAY )
713  continue;
714 
715  if ( bSearchTextEmpty )
716  {
717  auto xLeaf = ShowCheckEntry(aLabelDisp, maMembers[i], true, maMembers[i].mbVisible);
718  updateMemberParents(xLeaf.get(), i);
719  if ( maMembers[i].mbVisible )
720  ++nSelCount;
721  continue;
722  }
723 
724  if ( bPartialMatch )
725  {
726  auto xLeaf = ShowCheckEntry(aLabelDisp, maMembers[i]);
727  updateMemberParents(xLeaf.get(), i);
728  ++nSelCount;
729  }
730  else
731  {
732  ShowCheckEntry(aLabelDisp, maMembers[i], false, false);
733  if( bIsDate )
734  bSomeDateDeletes = true;
735  }
736  }
737 
738  if ( bSomeDateDeletes )
739  {
740  for (size_t i = 0; i < n; ++i)
741  {
742  if (!maMembers[i].mbDate)
743  continue;
744  if (maMembers[i].meDatePartType != ScCheckListMember::DAY)
745  continue;
746  updateMemberParents(nullptr, i);
747  }
748  }
749  }
750  else
751  {
752  // when there are a lot of rows, it is cheaper to simply clear the tree and either
753  // re-initialise or just insert the filtered lines
754  mpChecks->clear();
755 
756  if (bSearchTextEmpty)
757  nSelCount = initMembers();
758  else
759  {
760  std::vector<size_t> aShownIndexes;
761 
762  for (size_t i = 0; i < n; ++i)
763  {
764  assert(!maMembers[i].mbDate);
765 
766  OUString aLabelDisp = maMembers[i].maName;
767  if ( aLabelDisp.isEmpty() )
768  aLabelDisp = ScResId( STR_EMPTYDATA );
769 
770  bool bPartialMatch = ScGlobal::getCharClassPtr()->lowercase( aLabelDisp ).indexOf( aSearchText ) != -1;
771 
772  if (!bPartialMatch)
773  continue;
774 
775  aShownIndexes.push_back(i);
776  }
777 
778  std::vector<int> aFixedWidths { mnCheckWidthReq };
779  // tdf#122419 insert in the fastest order, this might be backwards.
780  mpChecks->bulk_insert_for_each(aShownIndexes.size(), [this, &aShownIndexes, &nSelCount](weld::TreeIter& rIter, int i) {
781  size_t nIndex = aShownIndexes[i];
782  insertMember(*mpChecks, rIter, maMembers[nIndex], true);
783  ++nSelCount;
784  }, &aFixedWidths);
785  }
786  }
787 
788 
789  mpChecks->thaw();
790 
791  if ( nSelCount == n )
792  mxChkToggleAll->set_state( TRISTATE_TRUE );
793  else if ( nSelCount == 0 )
794  mxChkToggleAll->set_state( TRISTATE_FALSE );
795  else
796  mxChkToggleAll->set_state( TRISTATE_INDET );
797 
798  if ( !maConfig.mbAllowEmptySet )
799  {
800  const bool bEmptySet( nSelCount == 0 );
801  mpChecks->set_sensitive(!bEmptySet);
802  mxChkToggleAll->set_sensitive(!bEmptySet);
803  mxBtnSelectSingle->set_sensitive(!bEmptySet);
804  mxBtnUnselectSingle->set_sensitive(!bEmptySet);
805  mxBtnOk->set_sensitive(!bEmptySet);
806  }
807 }
808 
810 {
811  if (mxBtnOk->get_sensitive())
812  close(true);
813  return true;
814 }
815 
816 IMPL_LINK( ScCheckListMenuControl, CheckHdl, const weld::TreeView::iter_col&, rRowCol, void )
817 {
818  Check(&rRowCol.first);
819 }
820 
822 {
823  if (pEntry)
824  CheckEntry(*pEntry, mpChecks->get_toggle(*pEntry) == TRISTATE_TRUE);
825  size_t nNumChecked = GetCheckedEntryCount();
826  if (nNumChecked == maMembers.size())
827  // all members visible
828  mxChkToggleAll->set_state(TRISTATE_TRUE);
829  else if (nNumChecked == 0)
830  // no members visible
831  mxChkToggleAll->set_state(TRISTATE_FALSE);
832  else
833  mxChkToggleAll->set_state(TRISTATE_INDET);
834 
836  // We need to have at least one member selected.
837  mxBtnOk->set_sensitive(nNumChecked != 0);
838 
839  mePrevToggleAllState = mxChkToggleAll->get_state();
840 }
841 
843 {
844  if ( !maMembers[nIdx].mbDate || maMembers[nIdx].meDatePartType != ScCheckListMember::DAY )
845  return;
846 
847  OUString aYearName = maMembers[nIdx].maDateParts[0];
848  OUString aMonthName = maMembers[nIdx].maDateParts[1];
849  auto aItr = maYearMonthMap.find(aYearName + aMonthName);
850 
851  if ( pLeaf )
852  {
853  std::unique_ptr<weld::TreeIter> xYearEntry;
854  std::unique_ptr<weld::TreeIter> xMonthEntry = mpChecks->make_iterator(pLeaf);
855  if (!mpChecks->iter_parent(*xMonthEntry))
856  xMonthEntry.reset();
857  else
858  {
859  xYearEntry = mpChecks->make_iterator(xMonthEntry.get());
860  if (!mpChecks->iter_parent(*xYearEntry))
861  xYearEntry.reset();
862  }
863 
864  maMembers[nIdx].mxParent = std::move(xMonthEntry);
865  if ( aItr != maYearMonthMap.end() )
866  {
867  size_t nMonthIdx = aItr->second;
868  maMembers[nMonthIdx].mxParent = std::move(xYearEntry);
869  }
870  }
871  else
872  {
873  std::unique_ptr<weld::TreeIter> xYearEntry = FindEntry(nullptr, aYearName);
874  if (aItr != maYearMonthMap.end() && !xYearEntry)
875  {
876  size_t nMonthIdx = aItr->second;
877  maMembers[nMonthIdx].mxParent.reset();
878  maMembers[nIdx].mxParent.reset();
879  }
880  else if (xYearEntry && !FindEntry(xYearEntry.get(), aMonthName))
881  maMembers[nIdx].mxParent.reset();
882  }
883 }
884 
886 {
887  maMembers.reserve(n);
888 }
889 
890 void ScCheckListMenuControl::addDateMember(const OUString& rsName, double nVal, bool bVisible)
891 {
892  SvNumberFormatter* pFormatter = mpDoc->GetFormatTable();
893 
894  // Convert the numeric date value to a date object.
895  Date aDate = pFormatter->GetNullDate();
896  aDate.AddDays(rtl::math::approxFloor(nVal));
897 
898  sal_Int16 nYear = aDate.GetYear();
899  sal_uInt16 nMonth = aDate.GetMonth();
900  sal_uInt16 nDay = aDate.GetDay();
901 
902  // Get the localized month name list.
903  CalendarWrapper* pCalendar = ScGlobal::GetCalendar();
904  uno::Sequence<i18n::CalendarItem2> aMonths = pCalendar->getMonths();
905  if (aMonths.getLength() < nMonth)
906  return;
907 
908  OUString aYearName = OUString::number(nYear);
909  OUString aMonthName = aMonths[nMonth-1].FullName;
910  OUString aDayName = OUString::number(nDay);
911 
912  if ( aDayName.getLength() == 1 )
913  aDayName = "0" + aDayName;
914 
915  mpChecks->freeze();
916 
917  std::unique_ptr<weld::TreeIter> xYearEntry = FindEntry(nullptr, aYearName);
918  if (!xYearEntry)
919  {
920  xYearEntry = mpChecks->make_iterator();
921  mpChecks->insert(nullptr, -1, nullptr, nullptr, nullptr, nullptr, false, xYearEntry.get());
922  mpChecks->set_toggle(*xYearEntry, TRISTATE_FALSE);
923  mpChecks->set_text(*xYearEntry, aYearName, 0);
924  ScCheckListMember aMemYear;
925  aMemYear.maName = aYearName;
926  aMemYear.maRealName = rsName;
927  aMemYear.mbDate = true;
928  aMemYear.mbLeaf = false;
929  aMemYear.mbVisible = bVisible;
930  aMemYear.mxParent.reset();
932  maMembers.emplace_back(std::move(aMemYear));
933  }
934 
935  std::unique_ptr<weld::TreeIter> xMonthEntry = FindEntry(xYearEntry.get(), aMonthName);
936  if (!xMonthEntry)
937  {
938  xMonthEntry = mpChecks->make_iterator();
939  mpChecks->insert(xYearEntry.get(), -1, nullptr, nullptr, nullptr, nullptr, false, xMonthEntry.get());
940  mpChecks->set_toggle(*xMonthEntry, TRISTATE_FALSE);
941  mpChecks->set_text(*xMonthEntry, aMonthName, 0);
942  ScCheckListMember aMemMonth;
943  aMemMonth.maName = aMonthName;
944  aMemMonth.maRealName = rsName;
945  aMemMonth.mbDate = true;
946  aMemMonth.mbLeaf = false;
947  aMemMonth.mbVisible = bVisible;
948  aMemMonth.mxParent = std::move(xYearEntry);
950  maMembers.emplace_back(std::move(aMemMonth));
951  maYearMonthMap[aYearName + aMonthName] = maMembers.size() - 1;
952  }
953 
954  std::unique_ptr<weld::TreeIter> xDayEntry = FindEntry(xMonthEntry.get(), aDayName);
955  if (!xDayEntry)
956  {
957  xDayEntry = mpChecks->make_iterator();
958  mpChecks->insert(xMonthEntry.get(), -1, nullptr, nullptr, nullptr, nullptr, false, xDayEntry.get());
959  mpChecks->set_toggle(*xDayEntry, TRISTATE_FALSE);
960  mpChecks->set_text(*xDayEntry, aDayName, 0);
961  ScCheckListMember aMemDay;
962  aMemDay.maName = aDayName;
963  aMemDay.maRealName = rsName;
964  aMemDay.maDateParts.resize(2);
965  aMemDay.maDateParts[0] = aYearName;
966  aMemDay.maDateParts[1] = aMonthName;
967  aMemDay.mbDate = true;
968  aMemDay.mbLeaf = true;
969  aMemDay.mbVisible = bVisible;
970  aMemDay.mxParent = std::move(xMonthEntry);
972  maMembers.emplace_back(std::move(aMemDay));
973  }
974 
975  mpChecks->thaw();
976 }
977 
978 void ScCheckListMenuControl::addMember(const OUString& rName, bool bVisible)
979 {
980  ScCheckListMember aMember;
981  aMember.maName = rName;
982  aMember.mbDate = false;
983  aMember.mbLeaf = true;
984  aMember.mbVisible = bVisible;
985  aMember.mxParent.reset();
986  maMembers.emplace_back(std::move(aMember));
987 }
988 
989 std::unique_ptr<weld::TreeIter> ScCheckListMenuControl::FindEntry(const weld::TreeIter* pParent, const OUString& sNode)
990 {
991  std::unique_ptr<weld::TreeIter> xEntry = mpChecks->make_iterator(pParent);
992  bool bEntry = pParent ? mpChecks->iter_children(*xEntry) : mpChecks->get_iter_first(*xEntry);
993  while (bEntry)
994  {
995  if (sNode == mpChecks->get_text(*xEntry, 0))
996  return xEntry;
997  bEntry = mpChecks->iter_next_sibling(*xEntry);
998  }
999  return nullptr;
1000 }
1001 
1002 void ScCheckListMenuControl::GetRecursiveChecked(const weld::TreeIter* pEntry, std::unordered_set<OUString>& vOut,
1003  OUString& rLabel)
1004 {
1005  if (mpChecks->get_toggle(*pEntry) != TRISTATE_TRUE)
1006  return;
1007 
1008  // We have to hash parents and children together.
1009  // Per convention for easy access in getResult()
1010  // "child;parent;grandparent" while descending.
1011  if (rLabel.isEmpty())
1012  rLabel = mpChecks->get_text(*pEntry, 0);
1013  else
1014  rLabel = mpChecks->get_text(*pEntry, 0) + ";" + rLabel;
1015 
1016  // Prerequisite: the selection mechanism guarantees that if a child is
1017  // selected then also the parent is selected, so we only have to
1018  // inspect the children in case the parent is selected.
1019  if (!mpChecks->iter_has_child(*pEntry))
1020  return;
1021 
1022  std::unique_ptr<weld::TreeIter> xChild(mpChecks->make_iterator(pEntry));
1023  bool bChild = mpChecks->iter_children(*xChild);
1024  while (bChild)
1025  {
1026  OUString aLabel = rLabel;
1027  GetRecursiveChecked(xChild.get(), vOut, aLabel);
1028  if (!aLabel.isEmpty() && aLabel != rLabel)
1029  vOut.insert(aLabel);
1030  bChild = mpChecks->iter_next_sibling(*xChild);
1031  }
1032  // Let the caller not add the parent alone.
1033  rLabel.clear();
1034 }
1035 
1036 std::unordered_set<OUString> ScCheckListMenuControl::GetAllChecked()
1037 {
1038  std::unordered_set<OUString> vResults(0);
1039 
1040  std::unique_ptr<weld::TreeIter> xEntry = mpChecks->make_iterator();
1041  bool bEntry = mpChecks->get_iter_first(*xEntry);
1042  while (bEntry)
1043  {
1044  OUString aLabel;
1045  GetRecursiveChecked(xEntry.get(), vResults, aLabel);
1046  if (!aLabel.isEmpty())
1047  vResults.insert(aLabel);
1048  bEntry = mpChecks->iter_next_sibling(*xEntry);
1049  }
1050 
1051  return vResults;
1052 }
1053 
1054 bool ScCheckListMenuControl::IsChecked(const OUString& sName, const weld::TreeIter* pParent)
1055 {
1056  std::unique_ptr<weld::TreeIter> xEntry = FindEntry(pParent, sName);
1057  return xEntry && mpChecks->get_toggle(*xEntry) == TRISTATE_TRUE;
1058 }
1059 
1060 void ScCheckListMenuControl::CheckEntry(const OUString& sName, const weld::TreeIter* pParent, bool bCheck)
1061 {
1062  std::unique_ptr<weld::TreeIter> xEntry = FindEntry(pParent, sName);
1063  if (xEntry)
1064  CheckEntry(*xEntry, bCheck);
1065 }
1066 
1067 // Recursively check all children of rParent
1069 {
1070  mpChecks->set_toggle(rParent, bCheck ? TRISTATE_TRUE : TRISTATE_FALSE);
1071  std::unique_ptr<weld::TreeIter> xEntry = mpChecks->make_iterator(&rParent);
1072  bool bEntry = mpChecks->iter_children(*xEntry);
1073  while (bEntry)
1074  {
1075  CheckAllChildren(*xEntry, bCheck);
1076  bEntry = mpChecks->iter_next_sibling(*xEntry);
1077  }
1078 }
1079 
1080 void ScCheckListMenuControl::CheckEntry(const weld::TreeIter& rParent, bool bCheck)
1081 {
1082  // recursively check all items below rParent
1083  CheckAllChildren(rParent, bCheck);
1084  // checking rParent can affect ancestors, e.g. if ancestor is unchecked and rParent is
1085  // now checked then the ancestor needs to be checked also
1086  if (!mpChecks->get_iter_depth(rParent))
1087  return;
1088 
1089  std::unique_ptr<weld::TreeIter> xAncestor(mpChecks->make_iterator(&rParent));
1090  bool bAncestor = mpChecks->iter_parent(*xAncestor);
1091  while (bAncestor)
1092  {
1093  // if any first level children checked then ancestor
1094  // needs to be checked, similarly if no first level children
1095  // checked then ancestor needs to be unchecked
1096  std::unique_ptr<weld::TreeIter> xChild(mpChecks->make_iterator(xAncestor.get()));
1097  bool bChild = mpChecks->iter_children(*xChild);
1098  bool bChildChecked = false;
1099 
1100  while (bChild)
1101  {
1102  if (mpChecks->get_toggle(*xChild) == TRISTATE_TRUE)
1103  {
1104  bChildChecked = true;
1105  break;
1106  }
1107  bChild = mpChecks->iter_next_sibling(*xChild);
1108  }
1109  mpChecks->set_toggle(*xAncestor, bChildChecked ? TRISTATE_TRUE : TRISTATE_FALSE);
1110  bAncestor = mpChecks->iter_parent(*xAncestor);
1111  }
1112 }
1113 
1114 std::unique_ptr<weld::TreeIter> ScCheckListMenuControl::ShowCheckEntry(const OUString& sName, ScCheckListMember& rMember, bool bShow, bool bCheck)
1115 {
1116  std::unique_ptr<weld::TreeIter> xEntry;
1117  if (!rMember.mbDate || rMember.mxParent)
1118  xEntry = FindEntry(rMember.mxParent.get(), sName);
1119 
1120  if ( bShow )
1121  {
1122  if (!xEntry)
1123  {
1124  if (rMember.mbDate)
1125  {
1126  if (rMember.maDateParts.empty())
1127  return nullptr;
1128 
1129  std::unique_ptr<weld::TreeIter> xYearEntry = FindEntry(nullptr, rMember.maDateParts[0]);
1130  if (!xYearEntry)
1131  {
1132  xYearEntry = mpChecks->make_iterator();
1133  mpChecks->insert(nullptr, -1, nullptr, nullptr, nullptr, nullptr, false, xYearEntry.get());
1134  mpChecks->set_toggle(*xYearEntry, TRISTATE_FALSE);
1135  mpChecks->set_text(*xYearEntry, rMember.maDateParts[0], 0);
1136  }
1137  std::unique_ptr<weld::TreeIter> xMonthEntry = FindEntry(xYearEntry.get(), rMember.maDateParts[1]);
1138  if (!xMonthEntry)
1139  {
1140  xMonthEntry = mpChecks->make_iterator();
1141  mpChecks->insert(xYearEntry.get(), -1, nullptr, nullptr, nullptr, nullptr, false, xMonthEntry.get());
1142  mpChecks->set_toggle(*xMonthEntry, TRISTATE_FALSE);
1143  mpChecks->set_text(*xMonthEntry, rMember.maDateParts[1], 0);
1144  }
1145  std::unique_ptr<weld::TreeIter> xDayEntry = FindEntry(xMonthEntry.get(), rMember.maName);
1146  if (!xDayEntry)
1147  {
1148  xDayEntry = mpChecks->make_iterator();
1149  mpChecks->insert(xMonthEntry.get(), -1, nullptr, nullptr, nullptr, nullptr, false, xDayEntry.get());
1150  mpChecks->set_toggle(*xDayEntry, TRISTATE_FALSE);
1151  mpChecks->set_text(*xDayEntry, rMember.maName, 0);
1152  }
1153  return xDayEntry; // Return leaf node
1154  }
1155 
1156  xEntry = mpChecks->make_iterator();
1157  mpChecks->append(xEntry.get());
1158  mpChecks->set_toggle(*xEntry, bCheck ? TRISTATE_TRUE : TRISTATE_FALSE);
1159  mpChecks->set_text(*xEntry, sName, 0);
1160  }
1161  else
1162  CheckEntry(*xEntry, bCheck);
1163  }
1164  else if (xEntry)
1165  {
1166  mpChecks->remove(*xEntry);
1167  if (rMember.mxParent)
1168  {
1169  std::unique_ptr<weld::TreeIter> xParent(mpChecks->make_iterator(rMember.mxParent.get()));
1170  while (xParent && !mpChecks->iter_has_child(*xParent))
1171  {
1172  std::unique_ptr<weld::TreeIter> xTmp(mpChecks->make_iterator(xParent.get()));
1173  if (!mpChecks->iter_parent(*xParent))
1174  xParent.reset();
1175  mpChecks->remove(*xTmp);
1176  }
1177  }
1178  }
1179  return nullptr;
1180 }
1181 
1183 {
1184  int nRet = 0;
1185 
1186  mpChecks->all_foreach([this, &nRet](weld::TreeIter& rEntry){
1187  if (mpChecks->get_toggle(rEntry) == TRISTATE_TRUE)
1188  ++nRet;
1189  return false;
1190  });
1191 
1192  return nRet;
1193 }
1194 
1195 IMPL_LINK(ScCheckListMenuControl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
1196 {
1197  const vcl::KeyCode& rKey = rKEvt.GetKeyCode();
1198 
1199  if ( rKey.GetCode() == KEY_RETURN || rKey.GetCode() == KEY_SPACE )
1200  {
1201  std::unique_ptr<weld::TreeIter> xEntry = mpChecks->make_iterator();
1202  bool bEntry = mpChecks->get_cursor(xEntry.get());
1203  if (bEntry)
1204  {
1205  bool bOldCheck = mpChecks->get_toggle(*xEntry) == TRISTATE_TRUE;
1206  CheckEntry(*xEntry, !bOldCheck);
1207  bool bNewCheck = mpChecks->get_toggle(*xEntry) == TRISTATE_TRUE;
1208  if (bOldCheck != bNewCheck)
1209  Check(xEntry.get());
1210  }
1211  return true;
1212  }
1213 
1214  return false;
1215 }
1216 
1217 size_t ScCheckListMenuControl::initMembers(int nMaxMemberWidth)
1218 {
1219  size_t n = maMembers.size();
1220  size_t nVisMemCount = 0;
1221 
1222  if (nMaxMemberWidth == -1)
1223  nMaxMemberWidth = mnCheckWidthReq;
1224 
1225  if (!mpChecks->n_children() && !mbHasDates)
1226  {
1227  std::vector<int> aFixedWidths { nMaxMemberWidth };
1228  // tdf#134038 insert in the fastest order, this might be backwards so only do it for
1229  // the !mbHasDates case where no entry depends on another to exist before getting
1230  // inserted. We cannot retain pre-existing treeview content, only clear and fill it.
1231  mpChecks->bulk_insert_for_each(n, [this, &nVisMemCount](weld::TreeIter& rIter, int i) {
1232  assert(!maMembers[i].mbDate);
1233  insertMember(*mpChecks, rIter, maMembers[i], maMembers[i].mbVisible);
1234  if (maMembers[i].mbVisible)
1235  ++nVisMemCount;
1236  }, &aFixedWidths);
1237  }
1238  else
1239  {
1240  mpChecks->freeze();
1241 
1242  std::unique_ptr<weld::TreeIter> xEntry = mpChecks->make_iterator();
1243  std::vector<std::unique_ptr<weld::TreeIter>> aExpandRows;
1244 
1245  for (size_t i = 0; i < n; ++i)
1246  {
1247  if (maMembers[i].mbDate)
1248  {
1249  CheckEntry(maMembers[i].maName, maMembers[i].mxParent.get(), maMembers[i].mbVisible);
1250  // Expand first node of checked dates
1251  if (!maMembers[i].mxParent && IsChecked(maMembers[i].maName, maMembers[i].mxParent.get()))
1252  {
1253  std::unique_ptr<weld::TreeIter> xDateEntry = FindEntry(nullptr, maMembers[i].maName);
1254  if (xDateEntry)
1255  aExpandRows.emplace_back(std::move(xDateEntry));
1256  }
1257  }
1258  else
1259  {
1260  mpChecks->append(xEntry.get());
1261  insertMember(*mpChecks, *xEntry, maMembers[i], maMembers[i].mbVisible);
1262  }
1263 
1264  if (maMembers[i].mbVisible)
1265  ++nVisMemCount;
1266  }
1267 
1268  mpChecks->thaw();
1269 
1270  for (auto& rRow : aExpandRows)
1271  mpChecks->expand_row(*rRow);
1272  }
1273 
1274  if (nVisMemCount == n)
1275  {
1276  // all members visible
1277  mxChkToggleAll->set_state(TRISTATE_TRUE);
1279  }
1280  else if (nVisMemCount == 0)
1281  {
1282  // no members visible
1283  mxChkToggleAll->set_state(TRISTATE_FALSE);
1285  }
1286  else
1287  {
1288  mxChkToggleAll->set_state(TRISTATE_INDET);
1290  }
1291 
1292  if (nVisMemCount)
1293  mpChecks->select(0);
1294 
1295  return nVisMemCount;
1296 }
1297 
1299 {
1300  maConfig = rConfig;
1301 }
1302 
1304 {
1305  return mxChkToggleAll->get_state() == TRISTATE_TRUE;
1306 }
1307 
1309 {
1310  ResultType aResult;
1311  std::unordered_set<OUString> vCheckeds = GetAllChecked();
1312  size_t n = maMembers.size();
1313  for (size_t i = 0; i < n; ++i)
1314  {
1315  if ( maMembers[i].mbLeaf )
1316  {
1317  OUStringBuffer aLabel = maMembers[i].maName;
1318  if (aLabel.isEmpty())
1319  aLabel = ScResId(STR_EMPTYDATA);
1320 
1321  /* TODO: performance-wise this looks suspicious, concatenating to
1322  * do the lookup for each leaf item seems wasteful. */
1323  // Checked labels are in the form "child;parent;grandparent".
1324  if (maMembers[i].mxParent)
1325  {
1326  std::unique_ptr<weld::TreeIter> xIter(mpChecks->make_iterator(maMembers[i].mxParent.get()));
1327  do
1328  {
1329  aLabel.append(";").append(mpChecks->get_text(*xIter));
1330  }
1331  while (mpChecks->iter_parent(*xIter));
1332  }
1333 
1334  bool bState = vCheckeds.find(aLabel.makeStringAndClear()) != vCheckeds.end();
1335 
1336  ResultEntry aResultEntry;
1337  aResultEntry.bValid = bState;
1338  if ( maMembers[i].mbDate )
1339  aResultEntry.aName = maMembers[i].maRealName;
1340  else
1341  aResultEntry.aName = maMembers[i].maName;
1342  aResultEntry.bDate = maMembers[i].mbDate;
1343  aResult.insert(aResultEntry);
1344  }
1345  }
1346  rResult.swap(aResult);
1347 }
1348 
1350 {
1351  prepWindow();
1353  // We need to have at least one member selected.
1354  mxBtnOk->set_sensitive(GetCheckedEntryCount() != 0);
1355 
1356  tools::Rectangle aRect(rRect);
1357  if (maConfig.mbRTL)
1358  {
1359  // In RTL mode, the logical "left" is visual "right".
1360  tools::Long nLeft = aRect.Left() - aRect.GetWidth();
1361  aRect.SetLeft( nLeft );
1362  }
1363  else if (mnWndWidth < aRect.GetWidth())
1364  {
1365  // Target rectangle (i.e. cell width) is wider than the window.
1366  // Simulate right-aligned launch by modifying the target rectangle
1367  // size.
1368  tools::Long nDiff = aRect.GetWidth() - mnWndWidth;
1369  aRect.AdjustLeft(nDiff );
1370  }
1371 
1372  StartPopupMode(aRect, FloatWinPopupFlags::Down);
1373 }
1374 
1376 {
1377  if (bOK && mxOKAction)
1378  mxOKAction->execute();
1379  EndPopupMode();
1380 }
1381 
1382 void ScCheckListMenuControl::setExtendedData(std::unique_ptr<ExtendedData> p)
1383 {
1384  mxExtendedData = std::move(p);
1385 }
1386 
1388 {
1389  return mxExtendedData.get();
1390 }
1391 
1393 {
1394  mxOKAction.reset(p);
1395 }
1396 
1398 {
1399  mxPopupEndAction.reset(p);
1400 }
1401 
1403 {
1404  clearSelectedMenuItem();
1405  if (mxPopupEndAction)
1406  mxPopupEndAction->execute();
1407 }
1408 
1409 int ScCheckListMenuControl::GetTextWidth(const OUString& rsName) const
1410 {
1411  return mxDropDown->GetTextWidth(rsName);
1412 }
1413 
1415 {
1416  int nBorder = mxFrame->get_border_width() * 2 + 4;
1417  int nNewWidth = nMaxTextWidth - nBorder;
1418  if (nNewWidth > mnCheckWidthReq)
1419  {
1420  mnCheckWidthReq = nNewWidth;
1421  int nChecksHeight = mpChecks->get_height_rows(9);
1422  mpChecks->set_size_request(mnCheckWidthReq, nChecksHeight);
1423  }
1424  return mnCheckWidthReq + nBorder;
1425 }
1426 
1427 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
virtual void set_text(int row, const OUString &rText, int col=-1)=0
IMPL_LINK_NOARG(ScCheckListMenuControl::SubMenuItemData, TimeoutHdl, Timer *, void)
std::set< ResultEntry > ResultType
void setDeferredProperties()
sal_Int32 nIndex
std::unique_ptr< weld::Button > mxBtnUnselectSingle
VclPtr< ScCheckListMenuWindow > mxParentMenu
void updateMemberParents(const weld::TreeIter *pLeaf, size_t nIdx)
void setOKAction(Action *p)
std::vector< MenuItemData > maMenuItems
ScCheckListMenuWindow(vcl::Window *pParent, ScDocument *pDoc, bool bCanHaveSubMenu, bool bTreeMode, int nWidth=-1, ScCheckListMenuWindow *pParentMenu=nullptr)
void prepWindow()
Calculate the appropriate window size based on the menu items.
virtual bool iter_parent(TreeIter &rIter) const =0
std::unique_ptr< weld::TreeIter > mxParent
std::unique_ptr< weld::Button > mxBtnSelectSingle
virtual void insert(const TreeIter *pParent, int pos, const OUString *pStr, const OUString *pId, const OUString *pIconName, VirtualDevice *pImageSurface, bool bChildrenOnDemand, TreeIter *pRet)=0
void executeMenuItem(size_t nPos)
int mnWndWidth
matching width request for mxChecks
long Long
WeakReference< XInterface > mxParent
static const AllSettings & GetSettings()
sal_Int64 n
VclPtr< ScCheckListMenuWindow > mxFrame
void SetPopupModeEndHdl(const vcl::Window *pWindow, const Link< FloatingWindow *, void > &rLink)
Reference< container::XNameAccess > mxContainer
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
std::unique_ptr< weld::TreeView > mxMenu
virtual ~ScCheckListMenuWindow() override
sal_uInt16 GetCode() const
tools::Long GetWidth() const
ImplSVEvent * mnAsyncPostPopdownId
void queueLaunchSubMenu(size_t nPos, ScCheckListMenuWindow *pMenu)
std::unordered_set< OUString > GetAllChecked()
ScCheckListMenuWindow * GetParentMenu()
void selectMenuItem(size_t nPos, bool bSubMenuTimer)
VclPtr< vcl::Window > mxBox
bool IsChecked(const OUString &sName, const weld::TreeIter *pParent)
constexpr sal_uInt16 KEY_SPACE
void StartPopupMode(const tools::Rectangle &rRect, FloatWinPopupFlags eFlags)
TRISTATE_TRUE
TriState mePrevToggleAllState
whole window width.
void CheckAllChildren(const weld::TreeIter &rEntry, bool bCheck)
virtual TriState get_toggle(int row, int col=-1) const =0
virtual std::unique_ptr< TreeIter > make_iterator(const TreeIter *pOrig=nullptr) const =0
virtual void thaw()=0
void CheckEntry(const OUString &sName, const weld::TreeIter *pParent, bool bCheck)
IMPL_LINK(ScCheckListMenuControl, MenuKeyInputHdl, const KeyEvent &, rKEvt, bool)
void setPopupEndAction(Action *p)
void SetBackground()
Action to perform when an event takes place.
Configuration options for this popup window.
std::unique_ptr< weld::TreeIter > mxScratchIter
ScCheckListMenuControl(ScCheckListMenuWindow *pParent, vcl::Window *pContainer, ScDocument *pDoc, bool bCanHaveSubMenu, bool bTreeMode, int nWidth)
tools::Long Left() const
void SetLeft(tools::Long v)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
sal_uInt16 GetMonth() const
std::unique_ptr< weld::TreeIter > ShowCheckEntry(const OUString &sName, ScCheckListMember &rMember, bool bShow=true, bool bCheck=true)
std::pair< const TreeIter &, int > iter_col
virtual int n_children() const =0
VclPtr< ScCheckListMenuWindow > mpSubMenu
void setAllMemberState(bool bSet)
static constexpr size_t MENU_NOT_SELECTED
TRISTATE_INDET
void addMenuItem(const OUString &rText, Action *pAction)
virtual void bulk_insert_for_each(int nSourceCount, const std::function< void(TreeIter &, int nSourceIndex)> &func, const std::vector< int > *pFixedWidths=nullptr)=0
sal_Int16 GetYear() const
void handleMenuTimeout(const SubMenuItemData *pTimer)
static void RemoveUserEvent(ImplSVEvent *nUserEvent)
SubMenuItemData maOpenTimer
std::unique_ptr< Action > mxOKAction
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:438
void clear()
void getResult(ResultType &rResult)
int IncreaseWindowWidthToFitText(int nMaxTextWidth)
virtual void dispose() override
std::vector< OUString > maDateParts
void setMemberSize(size_t n)
std::unique_ptr< weld::TreeView > mxTreeChecks
int i
VclPtr< ScCheckListMenuWindow > mxSubMenuWin
virtual void set_toggle(int row, TriState eState, int col=-1)=0
int GetCheckedEntryCount() const
std::shared_ptr< Action > mxAction
virtual void freeze()=0
std::unique_ptr< weld::CheckButton > mxChkToggleAll
std::vector< ScCheckListMember > maMembers
void setSubMenuFocused(const ScCheckListMenuControl *pSubMenu)
TRISTATE_FALSE
std::map< OUString, size_t > maYearMonthMap
virtual bool iter_has_child(const TreeIter &rIter) const =0
std::unique_ptr< weld::Box > mxButtonBox
std::unique_ptr< weld::Button > mxBtnOk
size_t initMembers(int nMaxMemberWidth=-1)
OUString ScResId(const char *pId)
Definition: scdll.cxx:95
virtual void GetFocus() override
virtual void Start() override
ExtendedData * getExtendedData()
Get the store auxiliary data, or NULL if no such data is stored.
sal_uInt16 GetDay() const
void setExtendedData(std::unique_ptr< ExtendedData > p)
Set auxiliary data that the client code might need.
MouseNotifyEvent GetType() const
void AddDays(sal_Int32 nAddDays)
virtual OUString get_text(int row, int col=-1) const =0
virtual void dispose() override
ScCheckListMenuWindow * addSubMenuItem(const OUString &rText, bool bEnabled)
void endSubMenu(ScCheckListMenuControl &rSubMenu)
void setConfig(const Config &rConfig)
OUString lowercase(const OUString &rStr, sal_Int32 nPos, sal_Int32 nCount) const
virtual void expand_row(const TreeIter &rIter)=0
void SetTimeout(sal_uInt64 nTimeoutMs)
DatePartType meDatePartType
FloatWinPopupFlags
virtual bool get_cursor(TreeIter *pIter) const =0
void launchSubMenu(bool bSetMenuPos)
std::unique_ptr< weld::TreeIter > FindEntry(const weld::TreeIter *pParent, const OUString &sNode)
std::unique_ptr< ExtendedData > mxExtendedData
constexpr sal_uInt16 KEY_RETURN
SubMenuItemData(ScCheckListMenuControl *pParent)
vcl::Window * GetWindow(GetWindowType nType) const
bool close
constexpr sal_uInt16 KEY_RIGHT
virtual bool iter_children(TreeIter &rIter) const =0
virtual void remove(int pos)=0
virtual bool EventNotify(NotifyEvent &rNEvt) override
void reset(reference_type *pBody)
void launch(const tools::Rectangle &rRect)
tools::Long const nBorder
RegionData_Impl * mpParent
void addMember(const OUString &rName, bool bVisible)
void set_id(const OUString &rID)
ScopedVclPtr< VirtualDevice > mxDropDown
SubMenuItemData maCloseTimer
void EnableDocking(bool bEnable=true)
virtual void select(int pos)=0
virtual void all_foreach(const std::function< bool(TreeIter &)> &func)=0
weld::TreeView * mpChecks
bool mbVisible
static CalendarWrapper * GetCalendar()
Definition: global.cxx:1020
void Stop()
int GetTextWidth(const OUString &rsName) const
virtual void GetFocus()
std::unique_ptr< weld::Widget > mxBox
void terminateAllPopupMenus()
Dismiss all visible popup menus and set focus back to the application window.
OUString maName
css::uno::Sequence< css::i18n::CalendarItem2 > getMonths() const
virtual bool get_iter_first(TreeIter &rIter) const =0
std::unique_ptr< weld::Container > mxContainer
virtual int get_height_rows(int nRows) const =0
static SC_DLLPUBLIC const CharClass * getCharClassPtr()
Definition: global.cxx:1011
OUString aLabel
void SetInvokeHandler(const Link< Timer *, void > &rLink)
void EndPopupMode(const vcl::Window *pWin)
ScCheckListMenuControl & get_widget()
std::unique_ptr< Action > mxPopupEndAction
void selectCurrentMemberOnly(bool bSet)
This class implements a popup window for field button, for quick access of hide-item list...
void append(TreeIter *pRet=nullptr)
void addDateMember(const OUString &rName, double nVal, bool bVisible)
VirtualDevice * get() const
void GetRecursiveChecked(const weld::TreeIter *pEntry, std::unordered_set< OUString > &vOut, OUString &rLabel)
void StartPopupMode(const vcl::Window *pWin, const tools::Rectangle &rRect, FloatWinPopupFlags nPopupModeFlags)
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
virtual bool iter_next_sibling(TreeIter &rIter) const =0
void DrawSymbol(const tools::Rectangle &rRect, SymbolType eType, const Color &rColor, DrawSymbolFlags nStyle=DrawSymbolFlags::NONE)
constexpr sal_uInt16 KEY_LEFT
std::unique_ptr< ScCheckListMenuControl, o3tl::default_delete< ScCheckListMenuControl > > mxControl
const Date & GetNullDate() const
virtual void set_size_request(int nWidth, int nHeight)=0
void setSelectedMenuItem(size_t nPos, bool bSubMenuTimer)
Extended data that the client code may need to store.
std::unique_ptr< weld::TreeView > mxListChecks
sal_Int32 get_border_width() const
void Check(const weld::TreeIter *pIter)
std::unique_ptr< weld::Button > mxBtnCancel
std::unique_ptr< weld::Entry > mxEdSearch
static DockingManager * GetDockingManager()
virtual int get_iter_depth(const TreeIter &rIter) const =0
size_t getSubMenuPos(const ScCheckListMenuControl *pSubMenu)
virtual bool EventNotify(NotifyEvent &rNEvt) override