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