LibreOffice Module sw (master)  1
workctrl.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 <sal/config.h>
21 
22 #include <i18nutil/unicode.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <sfx2/bindings.hxx>
25 #include <swmodule.hxx>
26 #include <view.hxx>
27 #include <initui.hxx>
28 #include <docsh.hxx>
29 #include <gloshdl.hxx>
30 #include <gloslst.hxx>
31 #include <workctrl.hxx>
32 #include <strings.hrc>
33 #include <cmdid.h>
34 #include <helpids.h>
35 #include <wrtsh.hxx>
38 #include <vcl/event.hxx>
39 #include <vcl/menu.hxx>
40 #include <vcl/settings.hxx>
41 #include <rtl/ustring.hxx>
42 #include <swabstdlg.hxx>
43 #include <sfx2/zoomitem.hxx>
44 #include <vcl/svapp.hxx>
45 #include <vcl/weldutils.hxx>
46 #include <svx/dialmgr.hxx>
47 #include <svx/strings.hrc>
48 #include <bitmaps.hlst>
50 #include <com/sun/star/frame/XFrame.hpp>
51 
52 #include <sfx2/viewfrm.hxx>
53 
54 // Size check
55 #define NAVI_ENTRIES 21
56 
57 using namespace ::com::sun::star;
58 using namespace ::com::sun::star::uno;
59 using namespace ::com::sun::star::beans;
60 using namespace ::com::sun::star::frame;
61 
63 
65  sal_uInt16 nSlotId,
66  ToolBoxItemId nId,
67  ToolBox& rTbx ) :
68  SfxToolBoxControl( nSlotId, nId, rTbx )
69 {
70  rTbx.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rTbx.GetItemBits( nId ) );
71 }
72 
74 {
75 }
76 
78 {
79  SwView* pView = ::GetActiveView();
80  if(pView && !pView->GetDocShell()->IsReadOnly() &&
81  !pView->GetWrtShell().HasReadonlySel() )
82  {
83  Link<Menu*,bool> aLnk = LINK(this, SwTbxAutoTextCtrl, PopupHdl);
84 
87  const size_t nGroupCount = pGlossaryList->GetGroupCount();
88  for(size_t i = 1; i <= nGroupCount; ++i)
89  {
90  OUString sTitle = pGlossaryList->GetGroupTitle(i - 1);
91  const sal_uInt16 nBlockCount = pGlossaryList->GetBlockCount(i -1);
92  if(nBlockCount)
93  {
94  sal_uInt16 nIndex = o3tl::narrowing<sal_uInt16>(100*i);
95  // but insert without extension
96  pPopup->InsertItem( i, sTitle);
98  pSub->SetSelectHdl(aLnk);
99  pPopup->SetPopupMenu(i, pSub);
100  for(sal_uInt16 j = 0; j < nBlockCount; j++)
101  {
102  OUString sLongName(pGlossaryList->GetBlockLongName(i - 1, j));
103  OUString sShortName(pGlossaryList->GetBlockShortName(i - 1, j));
104 
105  OUString sEntry = sShortName + " - " + sLongName;
106  pSub->InsertItem(++nIndex, sEntry);
107  }
108  }
109  }
110 
111  ToolBox* pToolBox = &GetToolBox();
112  ToolBoxItemId nId = GetId();
113  pToolBox->SetItemDown( nId, true );
114 
115  pPopup->Execute( pToolBox, pToolBox->GetItemRect( nId ),
116  (pToolBox->GetAlign() == WindowAlign::Top || pToolBox->GetAlign() == WindowAlign::Bottom) ?
117  PopupMenuFlags::ExecuteDown : PopupMenuFlags::ExecuteRight );
118 
119  pToolBox->SetItemDown( nId, false );
120  }
122 }
123 
125  SfxItemState,
126  const SfxPoolItem* pState )
127 {
128  GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SfxItemState::DISABLED) );
129 }
130 
131 IMPL_STATIC_LINK(SwTbxAutoTextCtrl, PopupHdl, Menu*, pMenu, bool)
132 {
133  sal_uInt16 nId = pMenu->GetCurItemId();
134 
135  sal_uInt16 nBlock = nId / 100;
136 
138  OUString sGroup = pGlossaryList->GetGroupName(nBlock - 1);
139  OUString sShortName =
140  pGlossaryList->GetBlockShortName(nBlock - 1, nId - (100 * nBlock) - 1);
141 
142  SwGlossaryHdl* pGlosHdl = ::GetActiveView()->GetGlosHdl();
144  ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc();
145  if ( fnSetActGroup )
146  (*fnSetActGroup)( sGroup );
147  pGlosHdl->SetCurGroup(sGroup, true);
148  pGlosHdl->InsertGlossary(sShortName);
149 
150  return false;
151 }
152 
153 // Navigation-Popup
154 // determine the order of the toolbox items
155 static sal_uInt16 aNavigationInsertIds[ NAVI_ENTRIES ] =
156 {
157  NID_TBL,
158  NID_FRM,
159  NID_GRF,
160  NID_OLE,
161  NID_PGE,
162  NID_OUTL,
163  NID_MARK,
164  NID_DRW,
165  NID_CTRL,
166  NID_REG,
167  NID_BKM,
168  NID_SEL,
169  NID_FTN,
170  NID_POSTIT,
171  NID_SRCH_REP,
175  NID_RECENCY,
176  NID_FIELD,
178 };
179 
180 rtl::OUStringConstExpr constexpr aNavigationImgIds[ NAVI_ENTRIES ] =
181 {
182  RID_BMP_RIBBAR_TBL,
183  RID_BMP_RIBBAR_FRM,
184  RID_BMP_RIBBAR_GRF,
185  RID_BMP_RIBBAR_OLE,
186  RID_BMP_RIBBAR_PGE,
187  RID_BMP_RIBBAR_OUTL,
188  RID_BMP_RIBBAR_MARK,
189  RID_BMP_RIBBAR_DRW,
190  RID_BMP_RIBBAR_CTRL,
191  RID_BMP_RIBBAR_REG,
192  RID_BMP_RIBBAR_BKM,
193  RID_BMP_RIBBAR_SEL,
194  RID_BMP_RIBBAR_FTN,
195  RID_BMP_RIBBAR_POSTIT,
196  RID_BMP_RIBBAR_REP,
197  RID_BMP_RIBBAR_ENTRY,
198  RID_BMP_RIBBAR_FORMULA,
199  RID_BMP_RIBBAR_ERROR,
200  RID_BMP_RIBBAR_RECENCY,
201  RID_BMP_RIBBAR_FIELD,
202  RID_BMP_RIBBAR_FIELD_BYTYPE
203 };
204 
206 {
207  STR_CONTENT_TYPE_TABLE,
208  STR_CONTENT_TYPE_FRAME,
209  STR_CONTENT_TYPE_GRAPHIC,
210  STR_CONTENT_TYPE_OLE,
211  ST_PGE,
212  STR_CONTENT_TYPE_OUTLINE,
213  ST_MARK,
214  STR_CONTENT_TYPE_DRAWOBJECT,
215  ST_CTRL,
216  STR_CONTENT_TYPE_REGION,
217  STR_CONTENT_TYPE_BOOKMARK,
218  ST_SEL,
219  STR_CONTENT_TYPE_FOOTNOTE,
220  STR_CONTENT_TYPE_POSTIT,
221  ST_SRCH_REP,
222  STR_CONTENT_TYPE_INDEX,
223  ST_TABLE_FORMULA,
224  ST_TABLE_FORMULA_ERROR,
225  ST_RECENCY,
226  STR_CONTENT_TYPE_TEXTFIELD,
227  ST_FIELD_BYTYPE
228 };
229 
230 // these are global strings
232 {
233  STR_IMGBTN_TBL_DOWN,
234  STR_IMGBTN_FRM_DOWN,
235  STR_IMGBTN_PGE_DOWN,
236  STR_IMGBTN_DRW_DOWN,
237  STR_IMGBTN_CTRL_DOWN,
238  STR_IMGBTN_REG_DOWN,
239  STR_IMGBTN_BKM_DOWN,
240  STR_IMGBTN_GRF_DOWN,
241  STR_IMGBTN_OLE_DOWN,
242  STR_IMGBTN_OUTL_DOWN,
243  STR_IMGBTN_SEL_DOWN,
244  STR_IMGBTN_FTN_DOWN,
245  STR_IMGBTN_MARK_DOWN,
246  STR_IMGBTN_POSTIT_DOWN,
247  STR_IMGBTN_SRCH_REP_DOWN,
248  STR_IMGBTN_INDEX_ENTRY_DOWN,
249  STR_IMGBTN_TBLFML_DOWN,
250  STR_IMGBTN_TBLFML_ERR_DOWN,
251  STR_IMGBTN_RECENCY_DOWN,
252  STR_IMGBTN_FIELD_DOWN,
253  STR_IMGBTN_FIELD_BYTYPE_DOWN,
254  STR_IMGBTN_TBL_UP,
255  STR_IMGBTN_FRM_UP,
256  STR_IMGBTN_PGE_UP,
257  STR_IMGBTN_DRW_UP,
258  STR_IMGBTN_CTRL_UP,
259  STR_IMGBTN_REG_UP,
260  STR_IMGBTN_BKM_UP,
261  STR_IMGBTN_GRF_UP,
262  STR_IMGBTN_OLE_UP,
263  STR_IMGBTN_OUTL_UP,
264  STR_IMGBTN_SEL_UP,
265  STR_IMGBTN_FTN_UP,
266  STR_IMGBTN_MARK_UP,
267  STR_IMGBTN_POSTIT_UP,
268  STR_IMGBTN_SRCH_REP_UP,
269  STR_IMGBTN_INDEX_ENTRY_UP,
270  STR_IMGBTN_TBLFML_UP,
271  STR_IMGBTN_TBLFML_ERR_UP,
272  STR_IMGBTN_RECENCY_UP,
273  STR_IMGBTN_FIELD_UP,
274  STR_IMGBTN_FIELD_BYTYPE_UP,
275 };
276 
277 static OUString lcl_GetScrollToolTip(bool bNext)
278 {
279  sal_uInt16 nResId = SwView::GetMoveType();
280  OUString sToolTip = SwResId(STR_IMGBTN_ARY[(!bNext ? NID_COUNT : 0) + nResId - NID_START]);
281  if (nResId == NID_FIELD_BYTYPE)
282  {
283  OUString sFieldType;
284  SwWrtShell* pWrtSh = GetActiveWrtShell();
285  if (pWrtSh)
286  {
287  SwField* pCurField = pWrtSh->GetCurField(true);
288  if (pCurField)
289  sFieldType = SwFieldType::GetTypeStr(pCurField->GetTypeId());
290  }
291  if (!sFieldType.isEmpty())
292  sToolTip = sToolTip.replaceFirst(u"%FIELDTYPE", sFieldType);
293  else
294  sToolTip = SwResId(SW_STR_NONE);
295  }
296  return sToolTip;
297 }
298 
299 namespace {
300 
301 class SwZoomBox_Impl final : public InterimItemWindow
302 {
303  std::unique_ptr<weld::ComboBox> m_xWidget;
304  sal_uInt16 m_nSlotId;
305  bool m_bRelease;
306 
307  DECL_LINK(SelectHdl, weld::ComboBox&, void);
308  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
309  DECL_LINK(ActivateHdl, weld::ComboBox&, bool);
310  DECL_LINK(FocusOutHdl, weld::Widget&, void);
311 
312  void Select();
313 
314  void ReleaseFocus();
315 
316 public:
317  SwZoomBox_Impl(vcl::Window* pParent, sal_uInt16 nSlot);
318 
319  virtual void dispose() override
320  {
321  m_xWidget.reset();
323  }
324 
325  void save_value()
326  {
327  m_xWidget->save_value();
328  }
329 
330  void set_entry_text(const OUString& rText)
331  {
332  m_xWidget->set_entry_text(rText);
333  }
334 
335  virtual ~SwZoomBox_Impl() override
336  {
337  disposeOnce();
338  }
339 };
340 
341 }
342 
343 SwZoomBox_Impl::SwZoomBox_Impl(vcl::Window* pParent, sal_uInt16 nSlot)
344  : InterimItemWindow(pParent, "modules/swriter/ui/zoombox.ui", "ZoomBox")
345  , m_xWidget(m_xBuilder->weld_combo_box("zoom"))
346  , m_nSlotId(nSlot)
347  , m_bRelease(true)
348 {
349  InitControlBase(m_xWidget.get());
350 
351  m_xWidget->set_help_id(HID_PVIEW_ZOOM_LB);
352  m_xWidget->set_entry_completion(false);
353  m_xWidget->connect_changed(LINK(this, SwZoomBox_Impl, SelectHdl));
354  m_xWidget->connect_key_press(LINK(this, SwZoomBox_Impl, KeyInputHdl));
355  m_xWidget->connect_entry_activate(LINK(this, SwZoomBox_Impl, ActivateHdl));
356  m_xWidget->connect_focus_out(LINK(this, SwZoomBox_Impl, FocusOutHdl));
357 
358  const TranslateId aZoomValues[] =
359  { RID_SVXSTR_ZOOM_25 , RID_SVXSTR_ZOOM_50 ,
360  RID_SVXSTR_ZOOM_75 , RID_SVXSTR_ZOOM_100 ,
361  RID_SVXSTR_ZOOM_150 , RID_SVXSTR_ZOOM_200 ,
362  RID_SVXSTR_ZOOM_WHOLE_PAGE, RID_SVXSTR_ZOOM_PAGE_WIDTH ,
363  RID_SVXSTR_ZOOM_OPTIMAL_VIEW };
364  for(const TranslateId& pZoomValue : aZoomValues)
365  {
366  OUString sEntry = SvxResId(pZoomValue);
367  m_xWidget->append_text(sEntry);
368  }
369 
370  int nWidth = m_xWidget->get_pixel_size(SvxResId(RID_SVXSTR_ZOOM_200)).Width();
371  m_xWidget->set_entry_width_chars(std::ceil(nWidth / m_xWidget->get_approximate_digit_width()));
372 
373  SetSizePixel(m_xWidget->get_preferred_size());
374 }
375 
376 IMPL_LINK(SwZoomBox_Impl, SelectHdl, weld::ComboBox&, rComboBox, void)
377 {
378  if (rComboBox.changed_by_direct_pick()) // only when picked from the list
379  Select();
380 }
381 
382 IMPL_LINK_NOARG(SwZoomBox_Impl, ActivateHdl, weld::ComboBox&, bool)
383 {
384  Select();
385  return true;
386 }
387 
388 void SwZoomBox_Impl::Select()
389 {
390  if( FN_PREVIEW_ZOOM == m_nSlotId )
391  {
392  bool bNonNumeric = true;
393 
394  OUString sEntry = m_xWidget->get_active_text().replaceAll("%", "");
395  SvxZoomItem aZoom(SvxZoomType::PERCENT,100);
396  if(sEntry == SvxResId( RID_SVXSTR_ZOOM_PAGE_WIDTH ) )
397  aZoom.SetType(SvxZoomType::PAGEWIDTH);
398  else if(sEntry == SvxResId( RID_SVXSTR_ZOOM_OPTIMAL_VIEW ) )
399  aZoom.SetType(SvxZoomType::OPTIMAL);
400  else if(sEntry == SvxResId( RID_SVXSTR_ZOOM_WHOLE_PAGE) )
401  aZoom.SetType(SvxZoomType::WHOLEPAGE);
402  else
403  {
404  bNonNumeric = false;
405 
406  sal_uInt16 nZoom = o3tl::narrowing<sal_uInt16>(sEntry.toInt32());
407  if(nZoom < MINZOOM)
408  nZoom = MINZOOM;
409  if(nZoom > MAXZOOM)
410  nZoom = MAXZOOM;
411  aZoom.SetValue(nZoom);
412  }
413 
414  if (bNonNumeric)
415  {
416  // put old value back, in case its effectively the same
417  // as the picked option and no update to number comes
418  // back from writer
419  m_xWidget->set_entry_text(m_xWidget->get_saved_value());
420  }
421 
422  SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
423 
424  pCurrentShell->GetDispatcher()->ExecuteList(SID_ATTR_ZOOM,
425  SfxCallMode::ASYNCHRON, { &aZoom });
426  }
427  ReleaseFocus();
428 }
429 
430 IMPL_LINK(SwZoomBox_Impl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
431 {
432  bool bHandled = false;
433 
434  sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
435 
436  switch (nCode)
437  {
438  case KEY_TAB:
439  m_bRelease = false;
440  Select();
441  break;
442 
443  case KEY_ESCAPE:
444  m_xWidget->set_entry_text(m_xWidget->get_saved_value());
445  ReleaseFocus();
446  bHandled = true;
447  break;
448  }
449 
450  return bHandled || ChildKeyInput(rKEvt);
451 }
452 
453 IMPL_LINK_NOARG(SwZoomBox_Impl, FocusOutHdl, weld::Widget&, void)
454 {
455  if (!m_xWidget->has_focus()) // a combobox can be comprised of different subwidget so double-check if none of those has focus
456  m_xWidget->set_entry_text(m_xWidget->get_saved_value());
457 }
458 
459 void SwZoomBox_Impl::ReleaseFocus()
460 {
461  if ( !m_bRelease )
462  {
463  m_bRelease = true;
464  return;
465  }
467 
468  if ( pCurSh )
469  {
470  vcl::Window* pShellWnd = pCurSh->GetWindow();
471 
472  if ( pShellWnd )
473  pShellWnd->GrabFocus();
474  }
475 }
476 
478 
480  sal_uInt16 nSlotId,
481  ToolBoxItemId nId,
482  ToolBox& rTbx) :
483  SfxToolBoxControl( nSlotId, nId, rTbx )
484 {
485 }
486 
488 {
489 }
490 
492  SfxItemState eState,
493  const SfxPoolItem* pState )
494 {
495  ToolBoxItemId nId = GetId();
496  GetToolBox().EnableItem( nId, (GetItemState(pState) != SfxItemState::DISABLED) );
497  SwZoomBox_Impl* pBox = static_cast<SwZoomBox_Impl*>(GetToolBox().GetItemWindow( GetId() ));
498  if(SfxItemState::DEFAULT <= eState)
499  {
500  OUString sZoom(unicode::formatPercent(static_cast<const SfxUInt16Item*>(pState)->GetValue(),
501  Application::GetSettings().GetUILanguageTag()));
502  pBox->set_entry_text(sZoom);
503  pBox->save_value();
504  }
505 }
506 
508 {
509  VclPtrInstance<SwZoomBox_Impl> pRet( pParent, GetSlotId() );
510  return pRet.get();
511 }
512 
513 namespace {
514 
515 class SwJumpToSpecificBox_Impl final : public InterimItemWindow
516 {
517  std::unique_ptr<weld::Entry> m_xWidget;
518 
519  sal_uInt16 m_nSlotId;
520 
521  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
522  DECL_LINK(SelectHdl, weld::Entry&, bool);
523 public:
524  SwJumpToSpecificBox_Impl(vcl::Window* pParent, sal_uInt16 nSlot);
525  virtual void dispose() override
526  {
527  m_xWidget.reset();
529  }
530  virtual ~SwJumpToSpecificBox_Impl() override
531  {
532  disposeOnce();
533  }
534 };
535 
536 }
537 
538 IMPL_LINK(SwJumpToSpecificBox_Impl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
539 {
540  return ChildKeyInput(rKEvt);
541 }
542 
543 SwJumpToSpecificBox_Impl::SwJumpToSpecificBox_Impl(vcl::Window* pParent, sal_uInt16 nSlot)
544  : InterimItemWindow(pParent, "modules/swriter/ui/jumpposbox.ui", "JumpPosBox")
545  , m_xWidget(m_xBuilder->weld_entry("jumppos"))
546  , m_nSlotId(nSlot)
547 {
548  InitControlBase(m_xWidget.get());
549 
550  m_xWidget->connect_key_press(LINK(this, SwJumpToSpecificBox_Impl, KeyInputHdl));
551  m_xWidget->connect_activate(LINK(this, SwJumpToSpecificBox_Impl, SelectHdl));
552 
553  SetSizePixel(m_xWidget->get_preferred_size());
554 }
555 
556 IMPL_LINK_NOARG(SwJumpToSpecificBox_Impl, SelectHdl, weld::Entry&, bool)
557 {
558  OUString sEntry(m_xWidget->get_text());
559  SfxUInt16Item aPageNum(m_nSlotId);
560  aPageNum.SetValue(o3tl::narrowing<sal_uInt16>(sEntry.toInt32()));
561  SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
562  pCurrentShell->GetDispatcher()->ExecuteList(m_nSlotId, SfxCallMode::ASYNCHRON,
563  { &aPageNum });
564  return true;
565 }
566 
568 
570  sal_uInt16 nSlotId,
571  ToolBoxItemId nId,
572  ToolBox& rTbx) :
573  SfxToolBoxControl( nSlotId, nId, rTbx )
574 {}
575 
577 {}
578 
580 {
582  return pRet.get();
583 }
584 
585 NavElementBox_Base::NavElementBox_Base(std::unique_ptr<weld::ComboBox> xComboBox,
586  const uno::Reference<frame::XFrame>& xFrame)
587  : m_xComboBox(std::move(xComboBox))
588  ,m_xFrame(xFrame)
589  ,m_bRelease(true)
590 {
591  m_xComboBox->set_size_request(150, -1);
592 
593  m_xComboBox->make_sorted();
594  m_xComboBox->freeze();
595  for (sal_uInt16 i = 0; i < NID_COUNT; i++)
596  m_xComboBox->append(OUString::number(aNavigationInsertIds[i]),
597  SwResId(aNavigationStrIds[i]), OUString(aNavigationImgIds[i]));
598  m_xComboBox->thaw();
599 
600  m_xComboBox->connect_changed(LINK(this, NavElementBox_Base, SelectHdl));
601  m_xComboBox->connect_key_press(LINK(this, NavElementBox_Base, KeyInputHdl));
602 }
603 
605  const uno::Reference<frame::XFrame>& xFrame)
606  : InterimItemWindow(pParent, "modules/swriter/ui/combobox.ui", "ComboBox")
607  ,NavElementBox_Base(m_xBuilder->weld_combo_box("combobox"), xFrame)
608 {
609  SetSizePixel(m_xContainer->get_preferred_size());
610 }
611 
613 {
614  if ( !m_bRelease )
615  {
616  m_bRelease = true;
617  return;
618  }
619 
620  if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
621  m_xFrame->getContainerWindow()->setFocus();
622 }
623 
624 IMPL_STATIC_LINK(NavElementBox_Base, SelectHdl, weld::ComboBox&, rComboBox, void)
625 {
626  if (!rComboBox.changed_by_direct_pick()) // only when picked from the list
627  return;
628  SfxUInt32Item aParam(FN_NAV_ELEMENT, rComboBox.get_active_id().toUInt32());
629  const SfxPoolItem* aArgs[2];
630  aArgs[0] = &aParam;
631  aArgs[1] = nullptr;
633  pDispatch->Execute(FN_NAV_ELEMENT, SfxCallMode::SYNCHRON, aArgs);
634 }
635 
637 {
638  sal_uInt16 nMoveType = SwView::GetMoveType();
639  for (size_t i = 0; i < SAL_N_ELEMENTS(aNavigationInsertIds); ++i)
640  {
641  if (nMoveType == aNavigationInsertIds[i])
642  {
643  m_xComboBox->set_active_text(SwResId(aNavigationStrIds[i]));
644  break;
645  }
646  }
647 }
648 
649 IMPL_LINK(NavElementBox_Base, KeyInputHdl, const KeyEvent&, rKEvt, bool)
650 {
651  return DoKeyInput(rKEvt);
652 }
653 
655 {
656  return false;
657 }
658 
660 {
661  if (KEY_ESCAPE == rKEvt.GetKeyCode().GetCode())
662  {
664  return true;
665  }
666  return ChildKeyInput(rKEvt);
667 }
668 
669 NavElementToolBoxControl::NavElementToolBoxControl( const uno::Reference< uno::XComponentContext >& rxContext )
670  : svt::ToolboxController( rxContext,
671  uno::Reference< frame::XFrame >(),
672  ".uno:NavElement" ),
673  m_pBox( nullptr )
674 {
675 }
676 
677 // XInterface
678 css::uno::Any SAL_CALL NavElementToolBoxControl::queryInterface( const css::uno::Type& aType )
679 {
680  uno::Any a = ToolboxController::queryInterface( aType );
681  if ( a.hasValue() )
682  return a;
683 
684  return ::cppu::queryInterface( aType, static_cast< lang::XServiceInfo* >( this ) );
685 }
686 
687 void SAL_CALL NavElementToolBoxControl::acquire() noexcept
688 {
689  ToolboxController::acquire();
690 }
691 
692 void SAL_CALL NavElementToolBoxControl::release() noexcept
693 {
694  ToolboxController::release();
695 }
696 
697 // XServiceInfo
698 sal_Bool SAL_CALL NavElementToolBoxControl::supportsService( const OUString& ServiceName )
699 {
700  return cppu::supportsService( this, ServiceName );
701 }
702 
704 {
705  return "lo.writer.NavElementToolBoxController";
706 }
707 
708 uno::Sequence< OUString > SAL_CALL NavElementToolBoxControl::getSupportedServiceNames()
709 {
710  return { "com.sun.star.frame.ToolbarController" };
711 }
712 
713 // XComponent
715 {
717 
718  SolarMutexGuard aSolarMutexGuard;
720  m_xWeldBox.reset();
721  m_pBox = nullptr;
722 }
723 
724 // XStatusListener
725 void SAL_CALL NavElementToolBoxControl::statusChanged( const frame::FeatureStateEvent& rEvent )
726 {
727  if (!m_pBox)
728  return;
729 
730  SolarMutexGuard aSolarMutexGuard;
731  if ( rEvent.FeatureURL.Path != "NavElement" )
732  return;
733 
734  if ( rEvent.IsEnabled )
735  {
736  m_pBox->set_sensitive(true);
737  m_pBox->UpdateBox();
738  }
739  else
740  m_pBox->set_sensitive(true);
741 
742  SwView* pView = GetActiveView();
743  if (pView && pView->GetViewFrame())
744  {
747  }
748 }
749 
750 // XToolbarController
751 void SAL_CALL NavElementToolBoxControl::execute( sal_Int16 /*KeyModifier*/ )
752 {
753 }
754 
756 {
757 }
758 
760 {
761 }
762 
763 uno::Reference< awt::XWindow > SAL_CALL NavElementToolBoxControl::createPopupWindow()
764 {
765  return uno::Reference< awt::XWindow >();
766 }
767 
768 uno::Reference< awt::XWindow > SAL_CALL NavElementToolBoxControl::createItemWindow(
769  const uno::Reference< awt::XWindow >& xParent )
770 {
771  uno::Reference< awt::XWindow > xItemWindow;
772 
773  if (m_pBuilder)
774  {
775  SolarMutexGuard aSolarMutexGuard;
776 
777  std::unique_ptr<weld::ComboBox> xWidget(m_pBuilder->weld_combo_box("NavElementWidget"));
778 
779  xItemWindow = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get()));
780 
781  m_xWeldBox.reset(new NavElementBox_Base(std::move(xWidget), m_xFrame));
782  m_pBox = m_xWeldBox.get();
783  }
784  else
785  {
786  VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent );
787  if ( pParent )
788  {
789  SolarMutexGuard aSolarMutexGuard;
791  m_pBox = m_xVclBox.get();
792  xItemWindow = VCLUnoHelper::GetInterface(m_xVclBox);
793  }
794  }
795 
796  return xItemWindow;
797 }
798 
799 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
801  css::uno::XComponentContext *rxContext,
802  css::uno::Sequence<css::uno::Any> const &)
803 {
804  return cppu::acquire( new NavElementToolBoxControl( rxContext ) );
805 }
806 
807 namespace {
808 
809 class PrevNextScrollToolboxController : public svt::ToolboxController,
810  public css::lang::XServiceInfo
811 {
812 public:
813  enum Type { PREVIOUS, NEXT };
814 
815  PrevNextScrollToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext, Type eType );
816 
817  // XInterface
818  virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
819  virtual void SAL_CALL acquire() noexcept override;
820  virtual void SAL_CALL release() noexcept override;
821 
822  // XServiceInfo
823  virtual OUString SAL_CALL getImplementationName() override;
824  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
825  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
826 
827  // XComponent
828  virtual void SAL_CALL dispose() override;
829 
830  // XStatusListener
831  virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
832 
833 private:
834  Type meType;
835 };
836 
837 }
838 
839 PrevNextScrollToolboxController::PrevNextScrollToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext, Type eType )
840  : svt::ToolboxController( rxContext,
841  css::uno::Reference< css::frame::XFrame >(),
842  (eType == PREVIOUS) ? OUString( ".uno:ScrollToPrevious" ): OUString( ".uno:ScrollToNext" ) ),
843  meType( eType )
844 {
845  addStatusListener(".uno:NavElement");
846 }
847 
848 // XInterface
849 css::uno::Any SAL_CALL PrevNextScrollToolboxController::queryInterface( const css::uno::Type& aType )
850 {
851  css::uno::Any a = ToolboxController::queryInterface( aType );
852  if ( a.hasValue() )
853  return a;
854 
855  return ::cppu::queryInterface( aType, static_cast< css::lang::XServiceInfo* >( this ) );
856 }
857 
858 void SAL_CALL PrevNextScrollToolboxController::acquire() noexcept
859 {
861 }
862 
863 void SAL_CALL PrevNextScrollToolboxController::release() noexcept
864 {
866 }
867 
868 // XServiceInfo
869 OUString SAL_CALL PrevNextScrollToolboxController::getImplementationName()
870 {
871  return meType == PrevNextScrollToolboxController::PREVIOUS?
872  OUString( "lo.writer.PreviousScrollToolboxController" ) :
873  OUString( "lo.writer.NextScrollToolboxController" );
874 }
875 
876 sal_Bool SAL_CALL PrevNextScrollToolboxController::supportsService( const OUString& ServiceName )
877 {
878  return cppu::supportsService(this, ServiceName);
879 }
880 
881 css::uno::Sequence< OUString > SAL_CALL PrevNextScrollToolboxController::getSupportedServiceNames()
882 {
883  return { "com.sun.star.frame.ToolbarController" };
884 }
885 
886 // XComponent
888 {
889  SolarMutexGuard aSolarMutexGuard;
890 
892 }
893 
894 // XStatusListener
895 void SAL_CALL PrevNextScrollToolboxController::statusChanged( const css::frame::FeatureStateEvent& rEvent )
896 {
897  if (rEvent.FeatureURL.Path == "NavElement")
898  {
899  if (m_pToolbar)
900  m_pToolbar->set_item_tooltip_text(m_aCommandURL.toUtf8(), lcl_GetScrollToolTip(meType != PrevNextScrollToolboxController::PREVIOUS));
901  else
902  {
903  ToolBox* pToolBox = nullptr;
905  if (getToolboxId(nId, &pToolBox))
906  pToolBox->SetQuickHelpText(nId, lcl_GetScrollToolTip(meType != PrevNextScrollToolboxController::PREVIOUS));
907  }
908  }
909  else if (rEvent.FeatureURL.Path == "ScrollToPrevious" || rEvent.FeatureURL.Path == "ScrollToNext")
910  {
911  if (m_pToolbar)
912  m_pToolbar->set_item_sensitive(m_aCommandURL.toUtf8(), rEvent.IsEnabled);
913  else
914  {
915  ToolBox* pToolBox = nullptr;
916  ToolBoxItemId nId;
917  if (getToolboxId(nId, &pToolBox))
918  pToolBox->EnableItem(nId, rEvent.IsEnabled);
919  }
920  }
921 }
922 
923 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
925  css::uno::XComponentContext *context,
926  css::uno::Sequence<css::uno::Any> const &)
927 {
928  return cppu::acquire( new PrevNextScrollToolboxController( context, PrevNextScrollToolboxController::PREVIOUS ) );
929 }
930 
931 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
933  css::uno::XComponentContext *context,
934  css::uno::Sequence<css::uno::Any> const &)
935 {
936  return cppu::acquire( new PrevNextScrollToolboxController( context, PrevNextScrollToolboxController::NEXT ) );
937 }
938 
939 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewFrame * GetViewFrame() const
#define MAXZOOM
Definition: view.hxx:81
Type
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
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 * >())
void set_sensitive(bool bSensitive)
Definition: workctrl.hxx:110
#define MINZOOM
Definition: view.hxx:80
sal_uInt16 GetBlockCount(size_t nGroup)
Definition: gloslst.cxx:199
bool hasValue()
sal_Int32 nIndex
#define NID_GRF
Definition: workctrl.hxx:42
#define NID_POSTIT
Definition: workctrl.hxx:48
static sal_uInt16 GetMoveType()
Definition: viewmdi.cxx:703
virtual void SAL_CALL dispose() override
Definition: workctrl.cxx:714
virtual void SAL_CALL dispose() override
virtual ~SwTbxAutoTextCtrl() override
Definition: workctrl.cxx:73
ToolBoxItemBits GetItemBits(ToolBoxItemId nItemId) const
SwView * GetActiveView()
Definition: swmodul1.cxx:116
vcl::Window * GetItemWindow(ToolBoxItemId nItemId) const
#define NID_BKM
Definition: workctrl.hxx:41
#define FN_PREVIEW_ZOOM
Definition: cmdid.h:180
std::string GetValue
#define NID_MARK
Definition: workctrl.hxx:47
ToolBox & GetToolBox() const
void(* GlossarySetActGroup)(const OUString &rNewGroup)
Definition: swabstdlg.hxx:88
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * lo_writer_NextScrollToolboxController_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: workctrl.cxx:932
virtual bool DoKeyInput(const KeyEvent &)
Definition: workctrl.cxx:654
#define NID_SEL
Definition: workctrl.hxx:45
virtual void SAL_CALL acquire() noexcept override
void disposeAndClear()
virtual std::unique_ptr< ComboBox > weld_combo_box(const OString &id)=0
static const AllSettings & GetSettings()
Base class of all fields.
Definition: fldbas.hxx:291
SwWrtShell * GetActiveWrtShell()
Definition: swmodul1.cxx:108
virtual bool DoKeyInput(const KeyEvent &rKEvt) override
Definition: workctrl.cxx:659
css::uno::Reference< css::lang::XComponent > m_xFrame
virtual void SetSizePixel(const Size &rNewSize)
#define NID_TABLE_FORMULA
Definition: workctrl.hxx:51
virtual void SAL_CALL click() override
Definition: workctrl.cxx:755
bool ChildKeyInput(const KeyEvent &rKEvt)
Reference
sal_Int16 nId
#define NID_OUTL
Definition: workctrl.hxx:44
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
virtual void SAL_CALL doubleClick() override
Definition: workctrl.cxx:759
sal_uInt16 GetCode() const
size_t GetGroupCount()
Definition: gloslst.cxx:169
uno::Reference< frame::XFrame > m_xFrame
Definition: workctrl.hxx:119
sal_uInt16 Execute(vcl::Window *pWindow, const Point &rPopupPos)
static SfxObjectShell * Current()
void Invalidate(sal_uInt16 nId)
SwJumpToSpecificPageControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
Definition: workctrl.cxx:569
static const OUString & GetTypeStr(SwFieldTypesEnum nTypeId)
Definition: fldbas.cxx:122
virtual void SAL_CALL release() noexcept override
Definition: workctrl.cxx:692
tools::Rectangle GetItemRect(ToolBoxItemId nItemId)
IMPL_STATIC_LINK(SwTbxAutoTextCtrl, PopupHdl, Menu *, pMenu, bool)
Definition: workctrl.cxx:131
NavElementToolBoxControl(const css::uno::Reference< css::uno::XComponentContext > &rServiceManager)
Definition: workctrl.cxx:669
virtual void StateChangedAtToolBoxControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: workctrl.cxx:124
SwWrtShell & GetWrtShell() const
Definition: view.hxx:413
#define NID_SRCH_REP
Definition: workctrl.hxx:49
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * lo_writer_NavElementToolBoxController_get_implementation(css::uno::XComponentContext *rxContext, css::uno::Sequence< css::uno::Any > const &)
Definition: workctrl.cxx:800
Used by the UI to modify the document model.
Definition: wrtsh.hxx:96
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:164
virtual ~SwJumpToSpecificPageControl() override
Definition: workctrl.cxx:576
void SetItemDown(ToolBoxItemId nItemId, bool bDown)
virtual void CreatePopupWindow() override
Definition: workctrl.cxx:77
NavElementBox_Base * m_pBox
Definition: workctrl.hxx:191
exports com.sun.star. frame
PREVIOUS
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
SwField * GetCurField(const bool bIncludeInputFieldAtStart=false) const
Definition: crstrvl.cxx:974
void SetItemBits(ToolBoxItemId nItemId, ToolBoxItemBits nBits)
OUString SvxResId(TranslateId aId)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
static SfxViewShell * Current()
bool getToolboxId(ToolBoxItemId &rItemId, ToolBox **ppToolBox)
void SetCurGroup(const OUString &aGrp, bool bApi=false, bool bAlwaysCreateNew=false)
Definition: gloshdl.cxx:94
virtual void SAL_CALL release() noexcept override
OUString GetBlockLongName(size_t nGroup, sal_uInt16 nBlock)
Definition: gloslst.cxx:210
OUString GetGroupName(size_t nPos)
Definition: gloslst.cxx:176
OUString GetBlockShortName(size_t nGroup, sal_uInt16 nBlock)
Definition: gloslst.cxx:221
weld::Builder * m_pBuilder
void addStatusListener(const OUString &aCommandURL)
sal_uInt16 nCode
virtual void SAL_CALL execute(sal_Int16 KeyModifier) override
Definition: workctrl.cxx:751
virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent &Event) override
Definition: workctrl.cxx:725
#define NAVI_ENTRIES
Definition: workctrl.cxx:55
void SetPopupMenu(sal_uInt16 nItemId, PopupMenu *pMenu)
#define SAL_N_ELEMENTS(arr)
std::unique_ptr< NavElementBox_Base > m_xWeldBox
Definition: workctrl.hxx:190
static sal_uInt16 aNavigationInsertIds[NAVI_ENTRIES]
Definition: workctrl.cxx:155
void SetSelectHdl(const Link< Menu *, bool > &rLink)
void EndSelection()
SfxDispatcher * GetDispatcher() const
int i
#define NID_INDEX_ENTRY
Definition: workctrl.hxx:50
#define NID_START
Definition: workctrl.hxx:34
uno_Any a
OUString GetGroupTitle(size_t nPos)
Definition: gloslst.cxx:188
static OUString lcl_GetScrollToolTip(bool bNext)
Definition: workctrl.cxx:277
void SetQuickHelpText(ToolBoxItemId nItemId, const OUString &rText)
SwPreviewZoomControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
Definition: workctrl.cxx:479
static SwGlossaryList * pGlossaryList
Definition: initui.cxx:41
virtual ~SwPreviewZoomControl() override
Definition: workctrl.cxx:487
SfxBindings & GetBindings()
NavElementBox_Impl(vcl::Window *pParent, const uno::Reference< frame::XFrame > &xFrame)
Definition: workctrl.cxx:604
float u
unsigned char sal_Bool
#define FN_SCROLL_NEXT
Definition: cmdid.h:188
#define NID_REG
Definition: workctrl.hxx:40
#define NID_TABLE_FORMULA_ERROR
Definition: workctrl.hxx:52
virtual void SAL_CALL acquire() noexcept override
Definition: workctrl.cxx:687
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
#define FN_SCROLL_PREV
Definition: cmdid.h:187
NavElementBox_Base(std::unique_ptr< weld::ComboBox > xComboBox, const uno::Reference< frame::XFrame > &xFrame)
Definition: workctrl.cxx:585
#define NID_FTN
Definition: workctrl.hxx:46
#define NID_RECENCY
Definition: workctrl.hxx:53
bool HasReadonlySel() const
Definition: crsrsh.cxx:3355
void GrabFocus()
SwTbxAutoTextCtrl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
Definition: workctrl.cxx:64
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
Definition: workctrl.cxx:579
#define NID_DRW
Definition: workctrl.hxx:38
SwDocShell * GetDocShell()
Definition: view.cxx:1132
SFX_IMPL_TOOLBOX_CONTROL(SwTbxAutoTextCtrl, SfxVoidItem)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: workctrl.cxx:698
bool IsReadOnly() const
void EnableItem(ToolBoxItemId nItemId, bool bEnable=true)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * lo_writer_PreviousScrollToolboxController_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: workctrl.cxx:924
static SfxItemState GetItemState(const SfxPoolItem *pState)
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
Definition: workctrl.cxx:678
NEXT
#define NID_OLE
Definition: workctrl.hxx:43
void InsertItem(sal_uInt16 nItemId, const OUString &rStr, MenuItemBits nItemBits=MenuItemBits::NONE, const OString &rIdent=OString(), sal_uInt16 nPos=MENU_APPEND)
SwFieldTypesEnum GetTypeId() const
Definition: fldbas.cxx:257
#define FN_NAV_ELEMENT
Definition: cmdid.h:186
bool InsertGlossary(const OUString &rName)
Definition: gloshdl.cxx:489
const vcl::KeyCode & GetKeyCode() const
#define NID_PGE
Definition: workctrl.hxx:37
#define NID_CTRL
Definition: workctrl.hxx:39
static SfxViewFrame * Current()
static OUString formatPercent(double dNumber, const LanguageTag &rLangTag)
virtual void StateChangedAtToolBoxControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: workctrl.cxx:491
SfxItemState
#define NID_TBL
Definition: workctrl.hxx:35
IMPL_LINK_NOARG(SwZoomBox_Impl, ActivateHdl, weld::ComboBox &, bool)
Definition: workctrl.cxx:382
std::unique_ptr< weld::Container > m_xContainer
const TranslateId STR_IMGBTN_ARY[]
Definition: workctrl.cxx:231
constexpr sal_uInt16 KEY_ESCAPE
virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createPopupWindow() override
Definition: workctrl.cxx:763
virtual void dispose() override
WindowAlign GetAlign() const
ToolBoxItemId GetId() const
static VclPtr< reference_type > Create(Arg &&...arg)
unsigned short GetSlotId() const
void ReleaseFocus_Impl()
Definition: workctrl.cxx:612
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: workctrl.cxx:708
vcl::Window * GetWindow() const
VclPtr< NavElementBox_Impl > m_xVclBox
Definition: workctrl.hxx:189
css::uno::Reference< css::frame::XFrame > m_xFrame
SwGlossaryHdl * GetGlosHdl()
Definition: view.cxx:1666
SfxDispatcher * GetDispatcher() const
virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow(const css::uno::Reference< css::awt::XWindow > &Parent) override
Definition: workctrl.cxx:768
reference_type * get() const
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
Definition: workctrl.cxx:507
#define NID_FIELD_BYTYPE
Definition: workctrl.hxx:55
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
virtual OUString SAL_CALL getImplementationName() override
Definition: workctrl.cxx:703
const TranslateId aNavigationStrIds[NAVI_ENTRIES]
Definition: workctrl.cxx:205
std::unique_ptr< weld::Image > m_xWidget
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
constexpr OStringLiteral HID_PVIEW_ZOOM_LB
Definition: helpids.h:101
virtual GlossarySetActGroup SetGlossaryActGroupFunc()=0
#define NID_FRM
Definition: workctrl.hxx:36
#define NID_COUNT
Definition: workctrl.hxx:56
RedlineType meType
rtl::OUStringConstExpr constexpr aNavigationImgIds[NAVI_ENTRIES]
Definition: workctrl.cxx:180
Definition: view.hxx:144
std::unique_ptr< weld::ComboBox > m_xComboBox
Definition: workctrl.hxx:118
constexpr sal_uInt16 KEY_TAB
#define NID_FIELD
Definition: workctrl.hxx:54
IMPL_LINK(SwZoomBox_Impl, SelectHdl, weld::ComboBox &, rComboBox, void)
Definition: workctrl.cxx:376
SwGlossaryList * GetGlossaryList()
Definition: initui.cxx:174