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 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  void save_value()
299  {
300  m_xWidget->save_value();
301  }
302 
303  void set_entry_text(const OUString& rText)
304  {
305  m_xWidget->set_entry_text(rText);
306  }
307 
308  virtual ~SwZoomBox_Impl() override
309  {
310  disposeOnce();
311  }
312 };
313 
314 }
315 
316 SwZoomBox_Impl::SwZoomBox_Impl(vcl::Window* pParent, sal_uInt16 nSlot)
317  : InterimItemWindow(pParent, "modules/swriter/ui/zoombox.ui", "ZoomBox")
318  , m_xWidget(m_xBuilder->weld_combo_box("zoom"))
319  , nSlotId(nSlot)
320  , bRelease(true)
321 {
322  InitControlBase(m_xWidget.get());
323 
324  m_xWidget->set_help_id(HID_PVIEW_ZOOM_LB);
325  m_xWidget->set_entry_completion(false);
326  m_xWidget->connect_changed(LINK(this, SwZoomBox_Impl, SelectHdl));
327  m_xWidget->connect_key_press(LINK(this, SwZoomBox_Impl, KeyInputHdl));
328  m_xWidget->connect_entry_activate(LINK(this, SwZoomBox_Impl, ActivateHdl));
329  m_xWidget->connect_focus_out(LINK(this, SwZoomBox_Impl, FocusOutHdl));
330 
331  const char* const aZoomValues[] =
332  { RID_SVXSTR_ZOOM_25 , RID_SVXSTR_ZOOM_50 ,
333  RID_SVXSTR_ZOOM_75 , RID_SVXSTR_ZOOM_100 ,
334  RID_SVXSTR_ZOOM_150 , RID_SVXSTR_ZOOM_200 ,
335  RID_SVXSTR_ZOOM_WHOLE_PAGE, RID_SVXSTR_ZOOM_PAGE_WIDTH ,
336  RID_SVXSTR_ZOOM_OPTIMAL_VIEW };
337  for(const char* pZoomValue : aZoomValues)
338  {
339  OUString sEntry = SvxResId(pZoomValue);
340  m_xWidget->append_text(sEntry);
341  }
342 
343  int nWidth = m_xWidget->get_pixel_size(SvxResId(RID_SVXSTR_ZOOM_200)).Width();
344  m_xWidget->set_entry_width_chars(std::ceil(nWidth / m_xWidget->get_approximate_digit_width()));
345 
346  SetSizePixel(m_xWidget->get_preferred_size());
347 }
348 
349 IMPL_LINK(SwZoomBox_Impl, SelectHdl, weld::ComboBox&, rComboBox, void)
350 {
351  if (rComboBox.changed_by_direct_pick()) // only when picked from the list
352  Select();
353 }
354 
355 IMPL_LINK_NOARG(SwZoomBox_Impl, ActivateHdl, weld::ComboBox&, bool)
356 {
357  Select();
358  return true;
359 }
360 
361 void SwZoomBox_Impl::Select()
362 {
363  if( FN_PREVIEW_ZOOM == nSlotId )
364  {
365  bool bNonNumeric = true;
366 
367  OUString sEntry = m_xWidget->get_active_text().replaceAll("%", "");
368  SvxZoomItem aZoom(SvxZoomType::PERCENT,100);
369  if(sEntry == SvxResId( RID_SVXSTR_ZOOM_PAGE_WIDTH ) )
370  aZoom.SetType(SvxZoomType::PAGEWIDTH);
371  else if(sEntry == SvxResId( RID_SVXSTR_ZOOM_OPTIMAL_VIEW ) )
372  aZoom.SetType(SvxZoomType::OPTIMAL);
373  else if(sEntry == SvxResId( RID_SVXSTR_ZOOM_WHOLE_PAGE) )
374  aZoom.SetType(SvxZoomType::WHOLEPAGE);
375  else
376  {
377  bNonNumeric = false;
378 
379  sal_uInt16 nZoom = static_cast<sal_uInt16>(sEntry.toInt32());
380  if(nZoom < MINZOOM)
381  nZoom = MINZOOM;
382  if(nZoom > MAXZOOM)
383  nZoom = MAXZOOM;
384  aZoom.SetValue(nZoom);
385  }
386 
387  if (bNonNumeric)
388  {
389  // put old value back, in case its effectively the same
390  // as the picked option and no update to number comes
391  // back from writer
392  m_xWidget->set_entry_text(m_xWidget->get_saved_value());
393  }
394 
395  SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
396 
397  pCurrentShell->GetDispatcher()->ExecuteList(SID_ATTR_ZOOM,
398  SfxCallMode::ASYNCHRON, { &aZoom });
399  }
400  ReleaseFocus();
401 }
402 
403 IMPL_LINK(SwZoomBox_Impl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
404 {
405  bool bHandled = false;
406 
407  sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
408 
409  switch (nCode)
410  {
411  case KEY_TAB:
412  bRelease = false;
413  Select();
414  break;
415 
416  case KEY_ESCAPE:
417  m_xWidget->set_entry_text(m_xWidget->get_saved_value());
418  ReleaseFocus();
419  bHandled = true;
420  break;
421  }
422 
423  return bHandled || ChildKeyInput(rKEvt);
424 }
425 
426 IMPL_LINK_NOARG(SwZoomBox_Impl, FocusOutHdl, weld::Widget&, void)
427 {
428  if (!m_xWidget->has_focus()) // a combobox can be comprised of different subwidget so double-check if none of those has focus
429  m_xWidget->set_entry_text(m_xWidget->get_saved_value());
430 }
431 
432 void SwZoomBox_Impl::ReleaseFocus()
433 {
434  if ( !bRelease )
435  {
436  bRelease = true;
437  return;
438  }
440 
441  if ( pCurSh )
442  {
443  vcl::Window* pShellWnd = pCurSh->GetWindow();
444 
445  if ( pShellWnd )
446  pShellWnd->GrabFocus();
447  }
448 }
449 
451 
453  sal_uInt16 nSlotId,
454  sal_uInt16 nId,
455  ToolBox& rTbx) :
456  SfxToolBoxControl( nSlotId, nId, rTbx )
457 {
458 }
459 
461 {
462 }
463 
464 void SwPreviewZoomControl::StateChanged( sal_uInt16 /*nSID*/,
465  SfxItemState eState,
466  const SfxPoolItem* pState )
467 {
468  sal_uInt16 nId = GetId();
469  GetToolBox().EnableItem( nId, (GetItemState(pState) != SfxItemState::DISABLED) );
470  SwZoomBox_Impl* pBox = static_cast<SwZoomBox_Impl*>(GetToolBox().GetItemWindow( GetId() ));
471  if(SfxItemState::DEFAULT <= eState)
472  {
473  OUString sZoom(unicode::formatPercent(static_cast<const SfxUInt16Item*>(pState)->GetValue(),
474  Application::GetSettings().GetUILanguageTag()));
475  pBox->set_entry_text(sZoom);
476  pBox->save_value();
477  }
478 }
479 
481 {
482  VclPtrInstance<SwZoomBox_Impl> pRet( pParent, GetSlotId() );
483  return pRet.get();
484 }
485 
486 namespace {
487 
488 class SwJumpToSpecificBox_Impl final : public InterimItemWindow
489 {
490  std::unique_ptr<weld::Entry> m_xWidget;
491 
492  sal_uInt16 nSlotId;
493 
494  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
495  DECL_LINK(SelectHdl, weld::Entry&, bool);
496 public:
497  SwJumpToSpecificBox_Impl(vcl::Window* pParent, sal_uInt16 nSlot);
498  virtual void dispose() override
499  {
500  m_xWidget.reset();
502  }
503  virtual ~SwJumpToSpecificBox_Impl() override
504  {
505  disposeOnce();
506  }
507 };
508 
509 }
510 
511 IMPL_LINK(SwJumpToSpecificBox_Impl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
512 {
513  return ChildKeyInput(rKEvt);
514 }
515 
516 SwJumpToSpecificBox_Impl::SwJumpToSpecificBox_Impl(vcl::Window* pParent, sal_uInt16 nSlot)
517  : InterimItemWindow(pParent, "modules/swriter/ui/jumpposbox.ui", "JumpPosBox")
518  , m_xWidget(m_xBuilder->weld_entry("jumppos"))
519  , nSlotId(nSlot)
520 {
521  InitControlBase(m_xWidget.get());
522 
523  m_xWidget->connect_key_press(LINK(this, SwJumpToSpecificBox_Impl, KeyInputHdl));
524  m_xWidget->connect_activate(LINK(this, SwJumpToSpecificBox_Impl, SelectHdl));
525 
526  SetSizePixel(m_xWidget->get_preferred_size());
527 }
528 
529 IMPL_LINK_NOARG(SwJumpToSpecificBox_Impl, SelectHdl, weld::Entry&, bool)
530 {
531  OUString sEntry(m_xWidget->get_text());
532  SfxUInt16Item aPageNum(nSlotId);
533  aPageNum.SetValue(static_cast<sal_uInt16>(sEntry.toInt32()));
534  SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
535  pCurrentShell->GetDispatcher()->ExecuteList(nSlotId, SfxCallMode::ASYNCHRON,
536  { &aPageNum });
537  return true;
538 }
539 
541 
543  sal_uInt16 nSlotId,
544  sal_uInt16 nId,
545  ToolBox& rTbx) :
546  SfxToolBoxControl( nSlotId, nId, rTbx )
547 {}
548 
550 {}
551 
553 {
555  return pRet.get();
556 }
557 
558 namespace {
559 
560 class NavElementBox_Base;
561 class NavElementBox_Impl;
562 
563 class NavElementToolBoxControl : public svt::ToolboxController,
564  public lang::XServiceInfo
565 {
566  public:
567  explicit NavElementToolBoxControl(
568  const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
569 
570  // XInterface
571  virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
572  virtual void SAL_CALL acquire() throw () override;
573  virtual void SAL_CALL release() throw () override;
574 
575  // XServiceInfo
576  virtual OUString SAL_CALL getImplementationName() override;
577  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
578  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
579 
580  // XComponent
581  virtual void SAL_CALL dispose() override;
582 
583  // XStatusListener
584  virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override;
585 
586  // XToolbarController
587  virtual void SAL_CALL execute( sal_Int16 KeyModifier ) override;
588  virtual void SAL_CALL click() override;
589  virtual void SAL_CALL doubleClick() override;
590  virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createPopupWindow() override;
591  virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) override;
592 
593  void dispatchCommand( const css::uno::Sequence< css::beans::PropertyValue >& rArgs );
594  using svt::ToolboxController::dispatchCommand;
595 
596  private:
597  VclPtr<NavElementBox_Impl> m_xVclBox;
598  std::unique_ptr<NavElementBox_Base> m_xWeldBox;
599  NavElementBox_Base* m_pBox;
600 };
601 
602 class NavElementBox_Base
603 {
604 public:
605  NavElementBox_Base(std::unique_ptr<weld::ComboBox> xWidget,
606  const uno::Reference<frame::XFrame>& _xFrame,
607  NavElementToolBoxControl& rCtrl);
608 
609  virtual ~NavElementBox_Base()
610  {
611  }
612 
613  void set_sensitive(bool bSensitive)
614  {
615  m_xWidget->set_sensitive(bSensitive);
616  }
617 
618  void UpdateBox();
619 
620 protected:
621  std::unique_ptr<weld::ComboBox> m_xWidget;
622  NavElementToolBoxControl* m_pCtrl;
623  bool m_bRelease;
624  uno::Reference< frame::XFrame > m_xFrame;
625 
626  virtual bool DoKeyInput(const KeyEvent& rKEvt);
627 
628  DECL_LINK(SelectHdl, weld::ComboBox&, void);
629  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
630 
631  void ReleaseFocus_Impl();
632 };
633 
634 
635 class NavElementBox_Impl final : public InterimItemWindow
636  , public NavElementBox_Base
637 {
638 public:
639  NavElementBox_Impl(vcl::Window* pParent,
640  const uno::Reference<frame::XFrame>& _xFrame,
641  NavElementToolBoxControl& rCtrl);
642 
643  virtual void dispose() override
644  {
645  m_xWidget.reset();
647  }
648 
649  virtual void GetFocus() override
650  {
651  if (m_xWidget)
652  m_xWidget->grab_focus();
654  }
655 
656  virtual bool DoKeyInput(const KeyEvent& rKEvt) override;
657 
658  virtual ~NavElementBox_Impl() override
659  {
660  disposeOnce();
661  }
662 };
663 
664 }
665 
666 NavElementBox_Base::NavElementBox_Base(
667  std::unique_ptr<weld::ComboBox> xWidget,
668  const uno::Reference< frame::XFrame >& _xFrame,
669  NavElementToolBoxControl& _rCtrl )
670  : m_xWidget(std::move(xWidget))
671  , m_pCtrl(&_rCtrl)
672  , m_bRelease(true)
673  , m_xFrame(_xFrame)
674 {
675  m_xWidget->set_size_request(150, -1);
676 
677  m_xWidget->make_sorted();
678  m_xWidget->freeze();
679  for (sal_uInt16 i = 0; i < NID_COUNT; i++)
680  m_xWidget->append(OUString::number(aNavigationInsertIds[i]), SwResId(aNavigationStrIds[i]), aNavigationImgIds[i]);
681  m_xWidget->thaw();
682 
683  m_xWidget->connect_changed(LINK(this, NavElementBox_Base, SelectHdl));
684  m_xWidget->connect_key_press(LINK(this, NavElementBox_Base, KeyInputHdl));
685 }
686 
687 NavElementBox_Impl::NavElementBox_Impl(
688  vcl::Window* _pParent,
689  const uno::Reference< frame::XFrame >& _xFrame,
690  NavElementToolBoxControl& _rCtrl )
691  : InterimItemWindow(_pParent, "modules/swriter/ui/combobox.ui", "ComboBox")
692  , NavElementBox_Base(m_xBuilder->weld_combo_box("combobox"), _xFrame, _rCtrl)
693 {
694  SetSizePixel(m_xContainer->get_preferred_size());
695 }
696 
697 void NavElementBox_Base::ReleaseFocus_Impl()
698 {
699  if ( !m_bRelease )
700  {
701  m_bRelease = true;
702  return;
703  }
704 
705  if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
706  m_xFrame->getContainerWindow()->setFocus();
707 }
708 
709 IMPL_LINK(NavElementBox_Base, SelectHdl, weld::ComboBox&, rComboBox, void)
710 {
711  if (!rComboBox.changed_by_direct_pick()) // only when picked from the list
712  return;
713 
714  SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );
715 
716  sal_uInt16 nMoveType = rComboBox.get_active_id().toUInt32();
717  SwView::SetMoveType( nMoveType );
718 
719  css::uno::Sequence< css::beans::PropertyValue > aArgs;
720 
721  /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
722  This instance may be deleted in the meantime (i.e. when a dialog is opened
723  while in Dispatch()), accessing members will crash in this case. */
724  ReleaseFocus_Impl();
725 
726  m_pCtrl->dispatchCommand( aArgs );
727 }
728 
729 void NavElementBox_Base::UpdateBox()
730 {
731  sal_uInt16 nMoveType = SwView::GetMoveType();
732  for ( size_t i = 0; i < SAL_N_ELEMENTS( aNavigationInsertIds ); ++i )
733  {
734  if ( nMoveType == aNavigationInsertIds[i] )
735  {
736  const char* id = aNavigationStrIds[i];
737  OUString sText = SwResId( id );
738  m_xWidget->set_active_text(sText);
739  break;
740  }
741  }
742 }
743 
744 IMPL_LINK(NavElementBox_Base, KeyInputHdl, const KeyEvent&, rKEvt, bool)
745 {
746  return DoKeyInput(rKEvt);
747 }
748 
749 bool NavElementBox_Base::DoKeyInput(const KeyEvent& rKEvt)
750 {
751  bool bHandled = false;
752 
753  vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
754  sal_uInt16 nCode = aKeyCode.GetCode();
755 
756  switch ( nCode )
757  {
758  case KEY_TAB:
759  {
760  m_bRelease = false;
761  SelectHdl(*m_xWidget);
762  break;
763  }
764  case KEY_RETURN:
765  {
766  bHandled = true;
767  SelectHdl(*m_xWidget);
768  break;
769  }
770  case KEY_ESCAPE:
771  ReleaseFocus_Impl();
772  bHandled = true;
773  break;
774  }
775 
776  return bHandled;
777 }
778 
779 bool NavElementBox_Impl::DoKeyInput(const KeyEvent& rKEvt)
780 {
781  return NavElementBox_Base::DoKeyInput(rKEvt) || ChildKeyInput(rKEvt);
782 }
783 
784 
785 NavElementToolBoxControl::NavElementToolBoxControl( const uno::Reference< uno::XComponentContext >& rxContext )
786  : svt::ToolboxController( rxContext,
787  uno::Reference< frame::XFrame >(),
788  ".uno:NavElement" ),
789  m_pBox( nullptr )
790 {
791 }
792 
793 // XInterface
794 css::uno::Any SAL_CALL NavElementToolBoxControl::queryInterface( const css::uno::Type& aType )
795 {
796  uno::Any a = ToolboxController::queryInterface( aType );
797  if ( a.hasValue() )
798  return a;
799 
800  return ::cppu::queryInterface( aType, static_cast< lang::XServiceInfo* >( this ) );
801 }
802 
803 void SAL_CALL NavElementToolBoxControl::acquire() throw ()
804 {
805  ToolboxController::acquire();
806 }
807 
808 void SAL_CALL NavElementToolBoxControl::release() throw ()
809 {
810  ToolboxController::release();
811 }
812 
813 // XServiceInfo
814 sal_Bool SAL_CALL NavElementToolBoxControl::supportsService( const OUString& ServiceName )
815 {
816  return cppu::supportsService( this, ServiceName );
817 }
818 
819 OUString SAL_CALL NavElementToolBoxControl::getImplementationName()
820 {
821  return "lo.writer.NavElementToolBoxController";
822 }
823 
824 uno::Sequence< OUString > SAL_CALL NavElementToolBoxControl::getSupportedServiceNames()
825 {
826  return { "com.sun.star.frame.ToolbarController" };
827 }
828 
829 // XComponent
830 void SAL_CALL NavElementToolBoxControl::dispose()
831 {
833 
834  SolarMutexGuard aSolarMutexGuard;
835  m_xVclBox.disposeAndClear();
836  m_xWeldBox.reset();
837  m_pBox = nullptr;
838 }
839 
840 // XStatusListener
841 void SAL_CALL NavElementToolBoxControl::statusChanged( const frame::FeatureStateEvent& rEvent )
842 {
843  if (!m_pBox)
844  return;
845 
846  SolarMutexGuard aSolarMutexGuard;
847  if ( rEvent.FeatureURL.Path == "NavElement" )
848  {
849  if ( rEvent.IsEnabled )
850  {
851  m_pBox->set_sensitive(true);
852  m_pBox->UpdateBox();
853  }
854  else
855  m_pBox->set_sensitive(true);
856  }
857 }
858 
859 // XToolbarController
860 void SAL_CALL NavElementToolBoxControl::execute( sal_Int16 /*KeyModifier*/ )
861 {
862 }
863 
864 void SAL_CALL NavElementToolBoxControl::click()
865 {
866 }
867 
868 void SAL_CALL NavElementToolBoxControl::doubleClick()
869 {
870 }
871 
872 uno::Reference< awt::XWindow > SAL_CALL NavElementToolBoxControl::createPopupWindow()
873 {
874  return uno::Reference< awt::XWindow >();
875 }
876 
877 uno::Reference< awt::XWindow > SAL_CALL NavElementToolBoxControl::createItemWindow(
878  const uno::Reference< awt::XWindow >& xParent )
879 {
880  uno::Reference< awt::XWindow > xItemWindow;
881 
882  if (m_pBuilder)
883  {
884  SolarMutexGuard aSolarMutexGuard;
885 
886  std::unique_ptr<weld::ComboBox> xWidget(m_pBuilder->weld_combo_box("NavElementWidget"));
887 
888  xItemWindow = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get()));
889 
890  m_xWeldBox.reset(new NavElementBox_Base(std::move(xWidget), m_xFrame, *this));
891  m_pBox = m_xWeldBox.get();
892  }
893  else
894  {
895  VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent );
896  if ( pParent )
897  {
898  SolarMutexGuard aSolarMutexGuard;
899  m_xVclBox = VclPtr<NavElementBox_Impl>::Create( pParent, m_xFrame, *this );
900  m_pBox = m_xVclBox.get();
901  xItemWindow = VCLUnoHelper::GetInterface(m_xVclBox);
902  }
903  }
904 
905  return xItemWindow;
906 }
907 
908 void NavElementToolBoxControl::dispatchCommand(
909  const uno::Sequence< beans::PropertyValue >& rArgs )
910 {
911  uno::Reference< frame::XDispatchProvider > xDispatchProvider( m_xFrame, uno::UNO_QUERY );
912  if ( xDispatchProvider.is() )
913  {
914  util::URL aURL;
915  uno::Reference< frame::XDispatch > xDispatch;
916  uno::Reference< util::XURLTransformer > xURLTransformer = getURLTransformer();
917 
918  aURL.Complete = ".uno:NavElement";
919  xURLTransformer->parseStrict( aURL );
920  xDispatch = xDispatchProvider->queryDispatch( aURL, OUString(), 0 );
921  if ( xDispatch.is() )
922  xDispatch->dispatch( aURL, rArgs );
923  }
924 }
925 
926 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
928  css::uno::XComponentContext *rxContext,
929  css::uno::Sequence<css::uno::Any> const &)
930 {
931  return cppu::acquire( new NavElementToolBoxControl( rxContext ) );
932 }
933 
934 namespace {
935 
936 class PrevNextScrollToolboxController : public svt::ToolboxController,
937  public css::lang::XServiceInfo
938 {
939 public:
940  enum Type { PREVIOUS, NEXT };
941 
942  PrevNextScrollToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext, Type eType );
943 
944  // XInterface
945  virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
946  virtual void SAL_CALL acquire() throw () override;
947  virtual void SAL_CALL release() throw () override;
948 
949  // XServiceInfo
950  virtual OUString SAL_CALL getImplementationName() override;
951  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
952  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
953 
954  // XComponent
955  virtual void SAL_CALL dispose() override;
956 
957  // XStatusListener
958  virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
959 
960 private:
961  Type meType;
962 };
963 
964 }
965 
966 PrevNextScrollToolboxController::PrevNextScrollToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext, Type eType )
967  : svt::ToolboxController( rxContext,
968  css::uno::Reference< css::frame::XFrame >(),
969  (eType == PREVIOUS) ? OUString( ".uno:ScrollToPrevious" ): OUString( ".uno:ScrollToNext" ) ),
970  meType( eType )
971 {
972  addStatusListener(".uno:NavElement");
973 }
974 
975 // XInterface
976 css::uno::Any SAL_CALL PrevNextScrollToolboxController::queryInterface( const css::uno::Type& aType )
977 {
978  css::uno::Any a = ToolboxController::queryInterface( aType );
979  if ( a.hasValue() )
980  return a;
981 
982  return ::cppu::queryInterface( aType, static_cast< css::lang::XServiceInfo* >( this ) );
983 }
984 
985 void SAL_CALL PrevNextScrollToolboxController::acquire() throw ()
986 {
988 }
989 
990 void SAL_CALL PrevNextScrollToolboxController::release() throw ()
991 {
993 }
994 
995 // XServiceInfo
996 OUString SAL_CALL PrevNextScrollToolboxController::getImplementationName()
997 {
998  return meType == PrevNextScrollToolboxController::PREVIOUS?
999  OUString( "lo.writer.PreviousScrollToolboxController" ) :
1000  OUString( "lo.writer.NextScrollToolboxController" );
1001 }
1002 
1003 sal_Bool SAL_CALL PrevNextScrollToolboxController::supportsService( const OUString& ServiceName )
1004 {
1005  return cppu::supportsService(this, ServiceName);
1006 }
1007 
1008 css::uno::Sequence< OUString > SAL_CALL PrevNextScrollToolboxController::getSupportedServiceNames()
1009 {
1010  return { "com.sun.star.frame.ToolbarController" };
1011 }
1012 
1013 // XComponent
1015 {
1016  SolarMutexGuard aSolarMutexGuard;
1017 
1019 }
1020 
1021 // XStatusListener
1022 void SAL_CALL PrevNextScrollToolboxController::statusChanged( const css::frame::FeatureStateEvent& rEvent )
1023 {
1024  if (rEvent.FeatureURL.Path == "NavElement")
1025  {
1026  if (m_pToolbar)
1027  m_pToolbar->set_item_tooltip_text(m_aCommandURL.toUtf8(), lcl_GetScrollToolTip(meType != PrevNextScrollToolboxController::PREVIOUS));
1028  else
1029  {
1030  ToolBox* pToolBox = nullptr;
1031  sal_uInt16 nId = 0;
1032  if (getToolboxId(nId, &pToolBox))
1033  pToolBox->SetQuickHelpText(nId, lcl_GetScrollToolTip(meType != PrevNextScrollToolboxController::PREVIOUS));
1034  }
1035  }
1036 }
1037 
1038 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
1040  css::uno::XComponentContext *context,
1041  css::uno::Sequence<css::uno::Any> const &)
1042 {
1043  return cppu::acquire( new PrevNextScrollToolboxController( context, PrevNextScrollToolboxController::PREVIOUS ) );
1044 }
1045 
1046 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
1048  css::uno::XComponentContext *context,
1049  css::uno::Sequence<css::uno::Any> const &)
1050 {
1051  return cppu::acquire( new PrevNextScrollToolboxController( context, PrevNextScrollToolboxController::NEXT ) );
1052 }
1053 
1054 /* 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: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: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:1047
#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:464
IMPL_STATIC_LINK(SwTbxAutoTextCtrl, PopupHdl, Menu *, pMenu, bool)
Definition: workctrl.cxx:132
SwWrtShell & GetWrtShell() const
Definition: view.hxx:398
#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:927
virtual ~SwJumpToSpecificPageControl() override
Definition: workctrl.cxx:549
Reference< XNameAccess > m_xContainer
virtual void CreatePopupWindow() override
Definition: workctrl.cxx:78
OUStringLiteral const aNavigationImgIds[NAVI_ENTRIES]
Definition: workctrl.cxx:178
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: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:460
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:165
static void SetMoveType(sal_uInt16 nSet)
Definition: viewmdi.cxx:648
DECL_LINK(DoResize, Timer *, void)
bool HasReadonlySel() const
Definition: crsrsh.cxx:3332
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:552
#define NID_DRW
Definition: workctrl.hxx:34
SwDocShell * GetDocShell()
Definition: view.cxx:1108
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:1039
static SfxItemState GetItemState(const SfxPoolItem *pState)
SwPreviewZoomControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: workctrl.cxx:452
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:355
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:1605
reference_type * get() const
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
Definition: workctrl.cxx:480
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:542
constexpr sal_uInt16 KEY_TAB
IMPL_LINK(SwZoomBox_Impl, SelectHdl, weld::ComboBox &, rComboBox, void)
Definition: workctrl.cxx:349
SwGlossaryList * GetGlossaryList()
Definition: initui.cxx:172