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 <svx/dialmgr.hxx>
45 #include <svx/strings.hrc>
46 #include <bitmaps.hlst>
48 #include <svx/srchdlg.hxx>
49 #include <com/sun/star/frame/XDispatchProvider.hpp>
50 #include <com/sun/star/frame/XFrame.hpp>
51 #include <com/sun/star/lang/XServiceInfo.hpp>
52 #include <com/sun/star/util/XURLTransformer.hpp>
53 
54 // Size check
55 #define NAVI_ENTRIES 18
56 
57 using namespace ::com::sun::star;
58 using namespace ::com::sun::star::uno;
59 using namespace ::com::sun::star::beans;
60 using namespace ::com::sun::star::frame;
61 
63 
65  sal_uInt16 nSlotId,
66  sal_uInt16 nId,
67  ToolBox& rTbx ) :
68  SfxToolBoxControl( nSlotId, nId, rTbx )
69 {
70  rTbx.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rTbx.GetItemBits( nId ) );
71 }
72 
74 {
75 }
76 
78 {
79  SwView* pView = ::GetActiveView();
80  if(pView && !pView->GetDocShell()->IsReadOnly() &&
81  !pView->GetWrtShell().HasReadonlySel() )
82  {
83  Link<Menu*,bool> aLnk = LINK(this, SwTbxAutoTextCtrl, PopupHdl);
84 
87  const size_t nGroupCount = pGlossaryList->GetGroupCount();
88  for(size_t i = 1; i <= nGroupCount; ++i)
89  {
90  OUString sTitle = pGlossaryList->GetGroupTitle(i - 1);
91  const sal_uInt16 nBlockCount = pGlossaryList->GetBlockCount(i -1);
92  if(nBlockCount)
93  {
94  sal_uInt16 nIndex = static_cast<sal_uInt16>(100*i);
95  // but insert without extension
96  pPopup->InsertItem( i, sTitle);
98  pSub->SetSelectHdl(aLnk);
99  pPopup->SetPopupMenu(i, pSub);
100  for(sal_uInt16 j = 0; j < nBlockCount; j++)
101  {
102  OUString sLongName(pGlossaryList->GetBlockLongName(i - 1, j));
103  OUString sShortName(pGlossaryList->GetBlockShortName(i - 1, j));
104 
105  OUString sEntry = sShortName + " - " + sLongName;
106  pSub->InsertItem(++nIndex, sEntry);
107  }
108  }
109  }
110 
111  ToolBox* pToolBox = &GetToolBox();
112  sal_uInt16 nId = GetId();
113  pToolBox->SetItemDown( nId, true );
114 
115  pPopup->Execute( pToolBox, pToolBox->GetItemRect( nId ),
116  (pToolBox->GetAlign() == WindowAlign::Top || pToolBox->GetAlign() == WindowAlign::Bottom) ?
117  PopupMenuFlags::ExecuteDown : PopupMenuFlags::ExecuteRight );
118 
119  pToolBox->SetItemDown( nId, false );
120  }
122 }
123 
125  SfxItemState,
126  const SfxPoolItem* pState )
127 {
128  GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SfxItemState::DISABLED) );
129 }
130 
131 IMPL_STATIC_LINK(SwTbxAutoTextCtrl, PopupHdl, Menu*, pMenu, bool)
132 {
133  sal_uInt16 nId = pMenu->GetCurItemId();
134 
135  sal_uInt16 nBlock = nId / 100;
136 
138  OUString sGroup = pGlossaryList->GetGroupName(nBlock - 1);
139  OUString sShortName =
140  pGlossaryList->GetBlockShortName(nBlock - 1, nId - (100 * nBlock) - 1);
141 
142  SwGlossaryHdl* pGlosHdl = ::GetActiveView()->GetGlosHdl();
144  ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc();
145  if ( fnSetActGroup )
146  (*fnSetActGroup)( sGroup );
147  pGlosHdl->SetCurGroup(sGroup, true);
148  pGlosHdl->InsertGlossary(sShortName);
149 
150  return false;
151 }
152 
153 // Navigation-Popup
154 // determine the order of the toolbox items
155 static sal_uInt16 aNavigationInsertIds[ NAVI_ENTRIES ] =
156 {
157  NID_TBL,
158  NID_FRM,
159  NID_GRF,
160  NID_OLE,
161  NID_PGE,
162  NID_OUTL,
163  NID_MARK,
164  NID_DRW,
165  NID_CTRL,
166  NID_REG,
167  NID_BKM,
168  NID_SEL,
169  NID_FTN,
170  NID_POSTIT,
171  NID_SRCH_REP,
175 };
176 
177 static OUStringLiteral const aNavigationImgIds[ NAVI_ENTRIES ] =
178 {
179  RID_BMP_RIBBAR_TBL,
180  RID_BMP_RIBBAR_FRM,
181  RID_BMP_RIBBAR_GRF,
182  RID_BMP_RIBBAR_OLE,
183  RID_BMP_RIBBAR_PGE,
184  RID_BMP_RIBBAR_OUTL,
185  RID_BMP_RIBBAR_MARK,
186  RID_BMP_RIBBAR_DRW,
187  RID_BMP_RIBBAR_CTRL,
188  RID_BMP_RIBBAR_REG,
189  RID_BMP_RIBBAR_BKM,
190  RID_BMP_RIBBAR_SEL,
191  RID_BMP_RIBBAR_FTN,
192  RID_BMP_RIBBAR_POSTIT,
193  RID_BMP_RIBBAR_REP,
194  RID_BMP_RIBBAR_ENTRY,
195  RID_BMP_RIBBAR_FORMULA,
196  RID_BMP_RIBBAR_ERROR
197 };
198 
199 static const char* aNavigationStrIds[ NAVI_ENTRIES ] =
200 {
201  ST_TBL,
202  ST_FRM,
203  ST_GRF,
204  ST_OLE,
205  ST_PGE,
206  ST_OUTL,
207  ST_MARK,
208  ST_DRW,
209  ST_CTRL,
210  ST_REG,
211  ST_BKM,
212  ST_SEL,
213  ST_FTN,
214  ST_POSTIT,
215  ST_SRCH_REP,
216  ST_INDEX_ENTRY,
217  ST_TABLE_FORMULA,
218  ST_TABLE_FORMULA_ERROR
219 };
220 
221 // these are global strings
222 static const char* STR_IMGBTN_ARY[] =
223 {
224  STR_IMGBTN_TBL_DOWN,
225  STR_IMGBTN_FRM_DOWN,
226  STR_IMGBTN_PGE_DOWN,
227  STR_IMGBTN_DRW_DOWN,
228  STR_IMGBTN_CTRL_DOWN,
229  STR_IMGBTN_REG_DOWN,
230  STR_IMGBTN_BKM_DOWN,
231  STR_IMGBTN_GRF_DOWN,
232  STR_IMGBTN_OLE_DOWN,
233  STR_IMGBTN_OUTL_DOWN,
234  STR_IMGBTN_SEL_DOWN,
235  STR_IMGBTN_FTN_DOWN,
236  STR_IMGBTN_MARK_DOWN,
237  STR_IMGBTN_POSTIT_DOWN,
238  STR_IMGBTN_SRCH_REP_DOWN,
239  STR_IMGBTN_INDEX_ENTRY_DOWN,
240  STR_IMGBTN_TBLFML_DOWN,
241  STR_IMGBTN_TBLFML_ERR_DOWN,
242  STR_IMGBTN_TBL_UP,
243  STR_IMGBTN_FRM_UP,
244  STR_IMGBTN_PGE_UP,
245  STR_IMGBTN_DRW_UP,
246  STR_IMGBTN_CTRL_UP,
247  STR_IMGBTN_REG_UP,
248  STR_IMGBTN_BKM_UP,
249  STR_IMGBTN_GRF_UP,
250  STR_IMGBTN_OLE_UP,
251  STR_IMGBTN_OUTL_UP,
252  STR_IMGBTN_SEL_UP,
253  STR_IMGBTN_FTN_UP,
254  STR_IMGBTN_MARK_UP,
255  STR_IMGBTN_POSTIT_UP,
256  STR_IMGBTN_SRCH_REP_UP,
257  STR_IMGBTN_INDEX_ENTRY_UP,
258  STR_IMGBTN_TBLFML_UP,
259  STR_IMGBTN_TBLFML_ERR_UP
260 };
261 
262 static OUString lcl_GetScrollToolTip(bool bNext)
263 {
264  sal_uInt16 nResId = SwView::GetMoveType();
265  if (!bNext)
266  nResId += NID_COUNT;
267  const char* id = STR_IMGBTN_ARY[nResId - NID_START];
268  return id ? SwResId(id): OUString();
269 }
270 
271 namespace {
272 
273 class SwZoomBox_Impl final : public InterimItemWindow
274 {
275  std::unique_ptr<weld::ComboBox> m_xWidget;
276  sal_uInt16 const nSlotId;
277  bool bRelease;
278 
279  DECL_LINK(SelectHdl, weld::ComboBox&, void);
280  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
281  DECL_LINK(ActivateHdl, weld::ComboBox&, bool);
282  DECL_LINK(FocusOutHdl, weld::Widget&, void);
283 
284  void Select();
285 
286  void ReleaseFocus();
287 
288 public:
289  SwZoomBox_Impl(vcl::Window* pParent, sal_uInt16 nSlot);
290 
291  virtual void dispose() override
292  {
293  m_xWidget.reset();
295  }
296 
297  virtual void GetFocus() override
298  {
299  if (m_xWidget)
300  m_xWidget->grab_focus();
302  }
303 
304  void save_value()
305  {
306  m_xWidget->save_value();
307  }
308 
309  void set_entry_text(const OUString& rText)
310  {
311  m_xWidget->set_entry_text(rText);
312  }
313 
314  virtual ~SwZoomBox_Impl() override
315  {
316  disposeOnce();
317  }
318 };
319 
320 }
321 
322 SwZoomBox_Impl::SwZoomBox_Impl(vcl::Window* pParent, sal_uInt16 nSlot)
323  : InterimItemWindow(pParent, "modules/swriter/ui/zoombox.ui", "ZoomBox")
324  , m_xWidget(m_xBuilder->weld_combo_box("zoom"))
325  , nSlotId(nSlot)
326  , bRelease(true)
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 const 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 void GetFocus() override
508  {
509  if (m_xWidget)
510  m_xWidget->grab_focus();
512  }
513  virtual ~SwJumpToSpecificBox_Impl() override
514  {
515  disposeOnce();
516  }
517 };
518 
519 }
520 
521 IMPL_LINK(SwJumpToSpecificBox_Impl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
522 {
523  return ChildKeyInput(rKEvt);
524 }
525 
526 SwJumpToSpecificBox_Impl::SwJumpToSpecificBox_Impl(vcl::Window* pParent, sal_uInt16 nSlot)
527  : InterimItemWindow(pParent, "modules/swriter/ui/jumpposbox.ui", "JumpPosBox")
528  , m_xWidget(m_xBuilder->weld_entry("jumppos"))
529  , nSlotId(nSlot)
530 {
531  m_xWidget->connect_key_press(LINK(this, SwJumpToSpecificBox_Impl, KeyInputHdl));
532  m_xWidget->connect_activate(LINK(this, SwJumpToSpecificBox_Impl, SelectHdl));
533 
534  SetSizePixel(m_xWidget->get_preferred_size());
535 }
536 
537 IMPL_LINK_NOARG(SwJumpToSpecificBox_Impl, SelectHdl, weld::Entry&, bool)
538 {
539  OUString sEntry(m_xWidget->get_text());
540  SfxUInt16Item aPageNum(nSlotId);
541  aPageNum.SetValue(static_cast<sal_uInt16>(sEntry.toInt32()));
542  SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
543  pCurrentShell->GetDispatcher()->ExecuteList(nSlotId, SfxCallMode::ASYNCHRON,
544  { &aPageNum });
545  return true;
546 }
547 
549 
551  sal_uInt16 nSlotId,
552  sal_uInt16 nId,
553  ToolBox& rTbx) :
554  SfxToolBoxControl( nSlotId, nId, rTbx )
555 {}
556 
558 {}
559 
561 {
563  return pRet.get();
564 }
565 
566 namespace {
567 
568 class NavElementBox_Impl;
569 class NavElementToolBoxControl : public svt::ToolboxController,
570  public lang::XServiceInfo
571 {
572  public:
573  explicit NavElementToolBoxControl(
574  const css::uno::Reference< css::uno::XComponentContext >& rServiceManager );
575 
576  // XInterface
577  virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
578  virtual void SAL_CALL acquire() throw () override;
579  virtual void SAL_CALL release() throw () override;
580 
581  // XServiceInfo
582  virtual OUString SAL_CALL getImplementationName() override;
583  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
584  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
585 
586  // XComponent
587  virtual void SAL_CALL dispose() override;
588 
589  // XStatusListener
590  virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override;
591 
592  // XToolbarController
593  virtual void SAL_CALL execute( sal_Int16 KeyModifier ) override;
594  virtual void SAL_CALL click() override;
595  virtual void SAL_CALL doubleClick() override;
596  virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createPopupWindow() override;
597  virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) override;
598 
599  void dispatchCommand( const css::uno::Sequence< css::beans::PropertyValue >& rArgs );
600  using svt::ToolboxController::dispatchCommand;
601 
602  private:
603  VclPtr<NavElementBox_Impl> m_pBox;
604 };
605 
606 class NavElementBox_Impl final : public InterimItemWindow
607 {
608 public:
609  NavElementBox_Impl(vcl::Window* pParent,
610  const uno::Reference<frame::XFrame>& _xFrame,
611  NavElementToolBoxControl& rCtrl);
612 
613  virtual void dispose() override
614  {
615  m_xWidget.reset();
617  }
618 
619  virtual void GetFocus() override
620  {
621  if (m_xWidget)
622  m_xWidget->grab_focus();
624  }
625 
626  virtual ~NavElementBox_Impl() override
627  {
628  disposeOnce();
629  }
630 
631  void Update();
632 
633 private:
634  std::unique_ptr<weld::ComboBox> m_xWidget;
635  NavElementToolBoxControl* m_pCtrl;
636  bool m_bRelease;
637  uno::Reference< frame::XFrame > m_xFrame;
638 
639  DECL_LINK(SelectHdl, weld::ComboBox&, void);
640  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
641 
642  void ReleaseFocus_Impl();
643 };
644 
645 }
646 
647 NavElementBox_Impl::NavElementBox_Impl(
648  vcl::Window* _pParent,
649  const uno::Reference< frame::XFrame >& _xFrame,
650  NavElementToolBoxControl& _rCtrl )
651  : InterimItemWindow(_pParent, "modules/swriter/ui/combobox.ui", "ComboBox")
652  , m_xWidget(m_xBuilder->weld_combo_box("combobox"))
653  , m_pCtrl(&_rCtrl)
654  , m_bRelease(true)
655  , m_xFrame(_xFrame)
656 {
657  m_xWidget->set_size_request(42, -1); // set to something small so the size set at the .ui takes precedence
658 
659  for (sal_uInt16 i = 0; i < NID_COUNT; ++i)
660  m_xWidget->append("", SwResId(aNavigationStrIds[i]), aNavigationImgIds[i]);
661  m_xWidget->connect_changed(LINK(this, NavElementBox_Impl, SelectHdl));
662  m_xWidget->connect_key_press(LINK(this, NavElementBox_Impl, KeyInputHdl));
663 
664  SetSizePixel(m_xContainer->get_preferred_size());
665 }
666 
667 void NavElementBox_Impl::ReleaseFocus_Impl()
668 {
669  if ( !m_bRelease )
670  {
671  m_bRelease = true;
672  return;
673  }
674 
675  if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
676  m_xFrame->getContainerWindow()->setFocus();
677 }
678 
679 IMPL_LINK(NavElementBox_Impl, SelectHdl, weld::ComboBox&, rComboBox, void)
680 {
681  if (rComboBox.changed_by_direct_pick()) // only when picked from the list
682  {
683  SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );
684 
685  sal_uInt16 nPos = rComboBox.get_active();
686  sal_uInt16 nMoveType = aNavigationInsertIds[nPos];
687  SwView::SetMoveType( nMoveType );
688 
689  css::uno::Sequence< css::beans::PropertyValue > aArgs;
690 
691  /* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
692  This instance may be deleted in the meantime (i.e. when a dialog is opened
693  while in Dispatch()), accessing members will crash in this case. */
694  ReleaseFocus_Impl();
695 
696  m_pCtrl->dispatchCommand( aArgs );
697  }
698 }
699 
700 void NavElementBox_Impl::Update()
701 {
702  sal_uInt16 nMoveType = SwView::GetMoveType();
703  for ( size_t i = 0; i < SAL_N_ELEMENTS( aNavigationInsertIds ); ++i )
704  {
705  if ( nMoveType == aNavigationInsertIds[i] )
706  {
707  const char* id = aNavigationStrIds[i];
708  OUString sText = SwResId( id );
709  m_xWidget->set_active_text(sText);
710  break;
711  }
712  }
713 }
714 
715 IMPL_LINK(NavElementBox_Impl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
716 {
717  bool bHandled = false;
718 
719  vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
720  sal_uInt16 nCode = aKeyCode.GetCode();
721 
722  switch ( nCode )
723  {
724  case KEY_TAB:
725  {
726  m_bRelease = false;
727  SelectHdl(*m_xWidget);
728  break;
729  }
730  case KEY_RETURN:
731  {
732  bHandled = true;
733  SelectHdl(*m_xWidget);
734  break;
735  }
736  case KEY_ESCAPE:
737  ReleaseFocus_Impl();
738  bHandled = true;
739  break;
740  }
741 
742  return bHandled || ChildKeyInput(rKEvt);
743 }
744 
745 NavElementToolBoxControl::NavElementToolBoxControl( const uno::Reference< uno::XComponentContext >& rxContext )
746  : svt::ToolboxController( rxContext,
747  uno::Reference< frame::XFrame >(),
748  ".uno:NavElement" ),
749  m_pBox( nullptr )
750 {
751 }
752 
753 // XInterface
754 css::uno::Any SAL_CALL NavElementToolBoxControl::queryInterface( const css::uno::Type& aType )
755 {
756  uno::Any a = ToolboxController::queryInterface( aType );
757  if ( a.hasValue() )
758  return a;
759 
760  return ::cppu::queryInterface( aType, static_cast< lang::XServiceInfo* >( this ) );
761 }
762 
763 void SAL_CALL NavElementToolBoxControl::acquire() throw ()
764 {
765  ToolboxController::acquire();
766 }
767 
768 void SAL_CALL NavElementToolBoxControl::release() throw ()
769 {
770  ToolboxController::release();
771 }
772 
773 // XServiceInfo
774 sal_Bool SAL_CALL NavElementToolBoxControl::supportsService( const OUString& ServiceName )
775 {
776  return cppu::supportsService( this, ServiceName );
777 }
778 
779 OUString SAL_CALL NavElementToolBoxControl::getImplementationName()
780 {
781  return "lo.writer.NavElementToolBoxController";
782 }
783 
784 uno::Sequence< OUString > SAL_CALL NavElementToolBoxControl::getSupportedServiceNames()
785 {
786  return { "com.sun.star.frame.ToolbarController" };
787 }
788 
789 // XComponent
790 void SAL_CALL NavElementToolBoxControl::dispose()
791 {
793 
794  SolarMutexGuard aSolarMutexGuard;
795  m_pBox.disposeAndClear();
796 }
797 
798 // XStatusListener
799 void SAL_CALL NavElementToolBoxControl::statusChanged( const frame::FeatureStateEvent& rEvent )
800 {
801  if ( m_pBox )
802  {
803  SolarMutexGuard aSolarMutexGuard;
804  if ( rEvent.FeatureURL.Path == "NavElement" )
805  {
806  if ( rEvent.IsEnabled )
807  {
808  m_pBox->Enable();
809  m_pBox->Update();
810  }
811  else
812  m_pBox->Disable();
813  }
814  }
815 }
816 
817 // XToolbarController
818 void SAL_CALL NavElementToolBoxControl::execute( sal_Int16 /*KeyModifier*/ )
819 {
820 }
821 
822 void SAL_CALL NavElementToolBoxControl::click()
823 {
824 }
825 
826 void SAL_CALL NavElementToolBoxControl::doubleClick()
827 {
828 }
829 
830 uno::Reference< awt::XWindow > SAL_CALL NavElementToolBoxControl::createPopupWindow()
831 {
832  return uno::Reference< awt::XWindow >();
833 }
834 
835 uno::Reference< awt::XWindow > SAL_CALL NavElementToolBoxControl::createItemWindow(
836  const uno::Reference< awt::XWindow >& xParent )
837 {
838  uno::Reference< awt::XWindow > xItemWindow;
839 
840  VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent );
841  if ( pParent )
842  {
843  SolarMutexGuard aSolarMutexGuard;
844  m_pBox = VclPtr<NavElementBox_Impl>::Create( pParent, m_xFrame, *this );
845  xItemWindow = VCLUnoHelper::GetInterface( m_pBox );
846  }
847 
848  uno::Reference< util::XURLTransformer > xURLTransformer = getURLTransformer();
849 
850  return xItemWindow;
851 }
852 
853 void NavElementToolBoxControl::dispatchCommand(
854  const uno::Sequence< beans::PropertyValue >& rArgs )
855 {
856  uno::Reference< frame::XDispatchProvider > xDispatchProvider( m_xFrame, uno::UNO_QUERY );
857  if ( xDispatchProvider.is() )
858  {
859  util::URL aURL;
860  uno::Reference< frame::XDispatch > xDispatch;
861  uno::Reference< util::XURLTransformer > xURLTransformer = getURLTransformer();
862 
863  aURL.Complete = ".uno:NavElement";
864  xURLTransformer->parseStrict( aURL );
865  xDispatch = xDispatchProvider->queryDispatch( aURL, OUString(), 0 );
866  if ( xDispatch.is() )
867  xDispatch->dispatch( aURL, rArgs );
868  }
869 }
870 
871 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
873  css::uno::XComponentContext *rxContext,
874  css::uno::Sequence<css::uno::Any> const &)
875 {
876  return cppu::acquire( new NavElementToolBoxControl( rxContext ) );
877 }
878 
879 namespace {
880 
881 class PrevNextScrollToolboxController : public svt::ToolboxController,
882  public css::lang::XServiceInfo
883 {
884 public:
885  enum Type { PREVIOUS, NEXT };
886 
887  PrevNextScrollToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext, Type eType );
888 
889  // XInterface
890  virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
891  virtual void SAL_CALL acquire() throw () override;
892  virtual void SAL_CALL release() throw () override;
893 
894  // XServiceInfo
895  virtual OUString SAL_CALL getImplementationName() override;
896  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
897  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
898 
899  // XComponent
900  virtual void SAL_CALL dispose() override;
901 
902  // XStatusListener
903  virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
904 
905 private:
906  Type const meType;
907 };
908 
909 }
910 
911 PrevNextScrollToolboxController::PrevNextScrollToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext, Type eType )
912  : svt::ToolboxController( rxContext,
913  css::uno::Reference< css::frame::XFrame >(),
914  (eType == PREVIOUS) ? OUString( ".uno:ScrollToPrevious" ): OUString( ".uno:ScrollToNext" ) ),
915  meType( eType )
916 {
917  addStatusListener(".uno:NavElement");
918 }
919 
920 // XInterface
921 css::uno::Any SAL_CALL PrevNextScrollToolboxController::queryInterface( const css::uno::Type& aType )
922 {
923  css::uno::Any a = ToolboxController::queryInterface( aType );
924  if ( a.hasValue() )
925  return a;
926 
927  return ::cppu::queryInterface( aType, static_cast< css::lang::XServiceInfo* >( this ) );
928 }
929 
930 void SAL_CALL PrevNextScrollToolboxController::acquire() throw ()
931 {
933 }
934 
935 void SAL_CALL PrevNextScrollToolboxController::release() throw ()
936 {
938 }
939 
940 // XServiceInfo
941 OUString SAL_CALL PrevNextScrollToolboxController::getImplementationName()
942 {
943  return meType == PrevNextScrollToolboxController::PREVIOUS?
944  OUString( "lo.writer.PreviousScrollToolboxController" ) :
945  OUString( "lo.writer.NextScrollToolboxController" );
946 }
947 
948 sal_Bool SAL_CALL PrevNextScrollToolboxController::supportsService( const OUString& ServiceName )
949 {
950  return cppu::supportsService(this, ServiceName);
951 }
952 
953 css::uno::Sequence< OUString > SAL_CALL PrevNextScrollToolboxController::getSupportedServiceNames()
954 {
955  return { "com.sun.star.frame.ToolbarController" };
956 }
957 
958 // XComponent
960 {
961  SolarMutexGuard aSolarMutexGuard;
962 
964 }
965 
966 // XStatusListener
967 void SAL_CALL PrevNextScrollToolboxController::statusChanged( const css::frame::FeatureStateEvent& rEvent )
968 {
969  if ( rEvent.FeatureURL.Path == "NavElement" )
970  {
971  ToolBox* pToolBox = nullptr;
972  sal_uInt16 nId = 0;
973  if ( getToolboxId( nId, &pToolBox ) )
974  pToolBox->SetQuickHelpText( nId, ( meType == PrevNextScrollToolboxController::PREVIOUS?lcl_GetScrollToolTip( false ):
975  lcl_GetScrollToolTip( true ) ) );
976  }
977 }
978 
979 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
981  css::uno::XComponentContext *context,
982  css::uno::Sequence<css::uno::Any> const &)
983 {
984  return cppu::acquire( new PrevNextScrollToolboxController( context, PrevNextScrollToolboxController::PREVIOUS ) );
985 }
986 
987 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
989  css::uno::XComponentContext *context,
990  css::uno::Sequence<css::uno::Any> const &)
991 {
992  return cppu::acquire( new PrevNextScrollToolboxController( context, PrevNextScrollToolboxController::NEXT ) );
993 }
994 
995 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual VclPtr< vcl::Window > CreateItemWindow(vcl::Window *pParent) override
Definition: workctrl.cxx:560
#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:73
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:988
#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:131
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:872
virtual ~SwJumpToSpecificPageControl() override
Definition: workctrl.cxx:557
Reference< XNameAccess > m_xContainer
virtual void CreatePopupWindow() override
Definition: workctrl.cxx:77
static OUStringLiteral const aNavigationImgIds[NAVI_ENTRIES]
Definition: workctrl.cxx:177
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:64
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:55
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:155
void SetSelectHdl(const Link< Menu *, bool > &rLink)
void EndSelection()
SfxDispatcher * GetDispatcher() const
#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:262
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:199
int i
static const char * STR_IMGBTN_ARY[]
Definition: workctrl.cxx:222
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:3320
void GrabFocus()
void SetItemDown(sal_uInt16 nItemId, bool bDown)
static void SetSearchLabel(const SearchLabel &rSL)
#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:124
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:980
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
#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:1604
virtual VclPtr< vcl::Window > CreateItemWindow(vcl::Window *pParent) override
Definition: workctrl.cxx:484
reference_type * get() const
RedlineType const meType
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
Definition: view.hxx:146
sal_uInt16 nPos
SwJumpToSpecificPageControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: workctrl.cxx:550
constexpr sal_uInt16 KEY_TAB
IMPL_LINK(SwZoomBox_Impl, SelectHdl, weld::ComboBox &, rComboBox, void)
Definition: workctrl.cxx:353
SwGlossaryList * GetGlossaryList()
Definition: initui.cxx:172