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