Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / ribbar / workctrl.cxx
blobeed488a72c46fd9f737d60ff45807185823dbacc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <i18nutil/unicode.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <sfx2/bindings.hxx>
25 #include <swmodule.hxx>
26 #include <utility>
27 #include <view.hxx>
28 #include <initui.hxx>
29 #include <docsh.hxx>
30 #include <gloshdl.hxx>
31 #include <gloslst.hxx>
32 #include <workctrl.hxx>
33 #include <strings.hrc>
34 #include <cmdid.h>
35 #include <helpids.h>
36 #include <wrtsh.hxx>
37 #include <cppuhelper/queryinterface.hxx>
38 #include <cppuhelper/supportsservice.hxx>
39 #include <vcl/event.hxx>
40 #include <vcl/menu.hxx>
41 #include <vcl/settings.hxx>
42 #include <rtl/ustring.hxx>
43 #include <swabstdlg.hxx>
44 #include <sfx2/zoomitem.hxx>
45 #include <vcl/svapp.hxx>
46 #include <vcl/weldutils.hxx>
47 #include <svx/dialmgr.hxx>
48 #include <svx/strings.hrc>
49 #include <bitmaps.hlst>
50 #include <toolkit/helper/vclunohelper.hxx>
51 #include <com/sun/star/frame/XFrame.hpp>
53 #include <sfx2/viewfrm.hxx>
55 // Size check
56 #define NAVI_ENTRIES 21
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;
63 SFX_IMPL_TOOLBOX_CONTROL( SwTbxAutoTextCtrl, SfxVoidItem );
65 SwTbxAutoTextCtrl::SwTbxAutoTextCtrl(
66 sal_uInt16 nSlotId,
67 ToolBoxItemId nId,
68 ToolBox& rTbx ) :
69 SfxToolBoxControl( nSlotId, nId, rTbx )
71 rTbx.SetItemBits( nId, ToolBoxItemBits::DROPDOWN | rTbx.GetItemBits( nId ) );
74 SwTbxAutoTextCtrl::~SwTbxAutoTextCtrl()
78 void SwTbxAutoTextCtrl::CreatePopupWindow()
80 SwView* pView = ::GetActiveView();
81 if(pView && !pView->GetDocShell()->IsReadOnly() &&
82 !pView->GetWrtShell().HasReadonlySel() )
84 Link<Menu*,bool> aLnk = LINK(this, SwTbxAutoTextCtrl, PopupHdl);
86 ScopedVclPtrInstance<PopupMenu> pPopup;
87 SwGlossaryList* pGlossaryList = ::GetGlossaryList();
88 const size_t nGroupCount = pGlossaryList->GetGroupCount();
89 for(size_t i = 1; i <= nGroupCount; ++i)
91 OUString sTitle = pGlossaryList->GetGroupTitle(i - 1);
92 const sal_uInt16 nBlockCount = pGlossaryList->GetBlockCount(i -1);
93 if(nBlockCount)
95 sal_uInt16 nIndex = o3tl::narrowing<sal_uInt16>(100*i);
96 // but insert without extension
97 pPopup->InsertItem( i, sTitle);
98 VclPtrInstance<PopupMenu> pSub;
99 pSub->SetSelectHdl(aLnk);
100 pPopup->SetPopupMenu(i, pSub);
101 for(sal_uInt16 j = 0; j < nBlockCount; j++)
103 OUString sLongName(pGlossaryList->GetBlockLongName(i - 1, j));
104 OUString sShortName(pGlossaryList->GetBlockShortName(i - 1, j));
106 OUString sEntry = sShortName + " - " + sLongName;
107 pSub->InsertItem(++nIndex, sEntry);
112 ToolBox* pToolBox = &GetToolBox();
113 ToolBoxItemId nId = GetId();
114 pToolBox->SetItemDown( nId, true );
116 pPopup->Execute( pToolBox, pToolBox->GetItemRect( nId ),
117 (pToolBox->GetAlign() == WindowAlign::Top || pToolBox->GetAlign() == WindowAlign::Bottom) ?
118 PopupMenuFlags::ExecuteDown : PopupMenuFlags::ExecuteRight );
120 pToolBox->SetItemDown( nId, false );
122 GetToolBox().EndSelection();
125 void SwTbxAutoTextCtrl::StateChangedAtToolBoxControl( sal_uInt16,
126 SfxItemState,
127 const SfxPoolItem* pState )
129 GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SfxItemState::DISABLED) );
132 IMPL_STATIC_LINK(SwTbxAutoTextCtrl, PopupHdl, Menu*, pMenu, bool)
134 sal_uInt16 nId = pMenu->GetCurItemId();
136 sal_uInt16 nBlock = nId / 100;
138 SwGlossaryList* pGlossaryList = ::GetGlossaryList();
139 OUString sGroup = pGlossaryList->GetGroupName(nBlock - 1);
140 OUString sShortName =
141 pGlossaryList->GetBlockShortName(nBlock - 1, nId - (100 * nBlock) - 1);
143 if (SwView* pView = GetActiveView())
145 SwGlossaryHdl* pGlosHdl = pView->GetGlosHdl();
146 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
147 ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc();
148 if ( fnSetActGroup )
149 (*fnSetActGroup)( sGroup );
150 pGlosHdl->SetCurGroup(sGroup, true);
151 pGlosHdl->InsertGlossary(sShortName);
154 return false;
157 // Navigation-Popup
158 // determine the order of the toolbox items
159 static sal_uInt16 aNavigationInsertIds[ NAVI_ENTRIES ] =
161 NID_TBL,
162 NID_FRM,
163 NID_GRF,
164 NID_OLE,
165 NID_PGE,
166 NID_OUTL,
167 NID_MARK,
168 NID_DRW,
169 NID_CTRL,
170 NID_REG,
171 NID_BKM,
172 NID_SEL,
173 NID_FTN,
174 NID_POSTIT,
175 NID_SRCH_REP,
176 NID_INDEX_ENTRY,
177 NID_TABLE_FORMULA,
178 NID_TABLE_FORMULA_ERROR,
179 NID_RECENCY,
180 NID_FIELD,
181 NID_FIELD_BYTYPE
184 rtl::OUStringConstExpr constexpr aNavigationImgIds[ NAVI_ENTRIES ] =
186 RID_BMP_RIBBAR_TBL,
187 RID_BMP_RIBBAR_FRM,
188 RID_BMP_RIBBAR_GRF,
189 RID_BMP_RIBBAR_OLE,
190 RID_BMP_RIBBAR_PGE,
191 RID_BMP_RIBBAR_OUTL,
192 RID_BMP_RIBBAR_MARK,
193 RID_BMP_RIBBAR_DRW,
194 RID_BMP_RIBBAR_CTRL,
195 RID_BMP_RIBBAR_REG,
196 RID_BMP_RIBBAR_BKM,
197 RID_BMP_RIBBAR_SEL,
198 RID_BMP_RIBBAR_FTN,
199 RID_BMP_RIBBAR_POSTIT,
200 RID_BMP_RIBBAR_REP,
201 RID_BMP_RIBBAR_ENTRY,
202 RID_BMP_RIBBAR_FORMULA,
203 RID_BMP_RIBBAR_ERROR,
204 RID_BMP_RIBBAR_RECENCY,
205 RID_BMP_RIBBAR_FIELD,
206 RID_BMP_RIBBAR_FIELD_BYTYPE
209 const TranslateId aNavigationStrIds[ NAVI_ENTRIES ] =
211 STR_CONTENT_TYPE_TABLE,
212 STR_CONTENT_TYPE_FRAME,
213 STR_CONTENT_TYPE_GRAPHIC,
214 STR_CONTENT_TYPE_OLE,
215 ST_PGE,
216 STR_CONTENT_TYPE_OUTLINE,
217 ST_MARK,
218 STR_CONTENT_TYPE_DRAWOBJECT,
219 ST_CTRL,
220 STR_CONTENT_TYPE_REGION,
221 STR_CONTENT_TYPE_BOOKMARK,
222 ST_SEL,
223 STR_CONTENT_TYPE_FOOTNOTE,
224 STR_CONTENT_TYPE_POSTIT,
225 ST_SRCH_REP,
226 STR_CONTENT_TYPE_INDEX,
227 ST_TABLE_FORMULA,
228 ST_TABLE_FORMULA_ERROR,
229 ST_RECENCY,
230 STR_CONTENT_TYPE_TEXTFIELD,
231 ST_FIELD_BYTYPE
234 // these are global strings
235 const TranslateId STR_IMGBTN_ARY[] =
237 STR_IMGBTN_TBL_DOWN,
238 STR_IMGBTN_FRM_DOWN,
239 STR_IMGBTN_PGE_DOWN,
240 STR_IMGBTN_DRW_DOWN,
241 STR_IMGBTN_CTRL_DOWN,
242 STR_IMGBTN_REG_DOWN,
243 STR_IMGBTN_BKM_DOWN,
244 STR_IMGBTN_GRF_DOWN,
245 STR_IMGBTN_OLE_DOWN,
246 STR_IMGBTN_OUTL_DOWN,
247 STR_IMGBTN_SEL_DOWN,
248 STR_IMGBTN_FTN_DOWN,
249 STR_IMGBTN_MARK_DOWN,
250 STR_IMGBTN_POSTIT_DOWN,
251 STR_IMGBTN_SRCH_REP_DOWN,
252 STR_IMGBTN_INDEX_ENTRY_DOWN,
253 STR_IMGBTN_TBLFML_DOWN,
254 STR_IMGBTN_TBLFML_ERR_DOWN,
255 STR_IMGBTN_RECENCY_DOWN,
256 STR_IMGBTN_FIELD_DOWN,
257 STR_IMGBTN_FIELD_BYTYPE_DOWN,
258 STR_IMGBTN_TBL_UP,
259 STR_IMGBTN_FRM_UP,
260 STR_IMGBTN_PGE_UP,
261 STR_IMGBTN_DRW_UP,
262 STR_IMGBTN_CTRL_UP,
263 STR_IMGBTN_REG_UP,
264 STR_IMGBTN_BKM_UP,
265 STR_IMGBTN_GRF_UP,
266 STR_IMGBTN_OLE_UP,
267 STR_IMGBTN_OUTL_UP,
268 STR_IMGBTN_SEL_UP,
269 STR_IMGBTN_FTN_UP,
270 STR_IMGBTN_MARK_UP,
271 STR_IMGBTN_POSTIT_UP,
272 STR_IMGBTN_SRCH_REP_UP,
273 STR_IMGBTN_INDEX_ENTRY_UP,
274 STR_IMGBTN_TBLFML_UP,
275 STR_IMGBTN_TBLFML_ERR_UP,
276 STR_IMGBTN_RECENCY_UP,
277 STR_IMGBTN_FIELD_UP,
278 STR_IMGBTN_FIELD_BYTYPE_UP,
281 static OUString lcl_GetScrollToolTip(bool bNext)
283 sal_uInt16 nResId = SwView::GetMoveType();
284 OUString sToolTip = SwResId(STR_IMGBTN_ARY[(!bNext ? NID_COUNT : 0) + nResId - NID_START]);
285 if (nResId == NID_FIELD_BYTYPE)
287 OUString sFieldType;
288 SwWrtShell* pWrtSh = GetActiveWrtShell();
289 if (pWrtSh)
291 SwField* pCurField = pWrtSh->GetCurField(true);
292 if (pCurField)
293 sFieldType = SwFieldType::GetTypeStr(pCurField->GetTypeId());
295 if (!sFieldType.isEmpty())
296 sToolTip = sToolTip.replaceFirst(u"%FIELDTYPE", sFieldType);
297 else
298 sToolTip = SwResId(SW_STR_NONE);
300 return sToolTip;
303 namespace {
305 class SwZoomBox_Impl final : public InterimItemWindow
307 std::unique_ptr<weld::ComboBox> m_xWidget;
308 sal_uInt16 m_nSlotId;
309 bool m_bRelease;
311 DECL_LINK(SelectHdl, weld::ComboBox&, void);
312 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
313 DECL_LINK(ActivateHdl, weld::ComboBox&, bool);
314 DECL_LINK(FocusOutHdl, weld::Widget&, void);
316 void Select();
318 void ReleaseFocus();
320 public:
321 SwZoomBox_Impl(vcl::Window* pParent, sal_uInt16 nSlot);
323 virtual void dispose() override
325 m_xWidget.reset();
326 InterimItemWindow::dispose();
329 void save_value()
331 m_xWidget->save_value();
334 void set_entry_text(const OUString& rText)
336 m_xWidget->set_entry_text(rText);
339 virtual ~SwZoomBox_Impl() override
341 disposeOnce();
347 SwZoomBox_Impl::SwZoomBox_Impl(vcl::Window* pParent, sal_uInt16 nSlot)
348 : InterimItemWindow(pParent, "modules/swriter/ui/zoombox.ui", "ZoomBox")
349 , m_xWidget(m_xBuilder->weld_combo_box("zoom"))
350 , m_nSlotId(nSlot)
351 , m_bRelease(true)
353 InitControlBase(m_xWidget.get());
355 m_xWidget->set_help_id(HID_PVIEW_ZOOM_LB);
356 m_xWidget->set_entry_completion(false);
357 m_xWidget->connect_changed(LINK(this, SwZoomBox_Impl, SelectHdl));
358 m_xWidget->connect_key_press(LINK(this, SwZoomBox_Impl, KeyInputHdl));
359 m_xWidget->connect_entry_activate(LINK(this, SwZoomBox_Impl, ActivateHdl));
360 m_xWidget->connect_focus_out(LINK(this, SwZoomBox_Impl, FocusOutHdl));
362 const TranslateId aZoomValues[] =
363 { RID_SVXSTR_ZOOM_25 , RID_SVXSTR_ZOOM_50 ,
364 RID_SVXSTR_ZOOM_75 , RID_SVXSTR_ZOOM_100 ,
365 RID_SVXSTR_ZOOM_150 , RID_SVXSTR_ZOOM_200 ,
366 RID_SVXSTR_ZOOM_WHOLE_PAGE, RID_SVXSTR_ZOOM_PAGE_WIDTH ,
367 RID_SVXSTR_ZOOM_OPTIMAL_VIEW };
368 for(const TranslateId& pZoomValue : aZoomValues)
370 OUString sEntry = SvxResId(pZoomValue);
371 m_xWidget->append_text(sEntry);
374 int nWidth = m_xWidget->get_pixel_size(SvxResId(RID_SVXSTR_ZOOM_200)).Width();
375 m_xWidget->set_entry_width_chars(std::ceil(nWidth / m_xWidget->get_approximate_digit_width()));
377 SetSizePixel(m_xWidget->get_preferred_size());
380 IMPL_LINK(SwZoomBox_Impl, SelectHdl, weld::ComboBox&, rComboBox, void)
382 if (rComboBox.changed_by_direct_pick()) // only when picked from the list
383 Select();
386 IMPL_LINK_NOARG(SwZoomBox_Impl, ActivateHdl, weld::ComboBox&, bool)
388 Select();
389 return true;
392 void SwZoomBox_Impl::Select()
394 if( FN_PREVIEW_ZOOM == m_nSlotId )
396 bool bNonNumeric = true;
398 OUString sEntry = m_xWidget->get_active_text().replaceAll("%", "");
399 SvxZoomItem aZoom(SvxZoomType::PERCENT,100);
400 if(sEntry == SvxResId( RID_SVXSTR_ZOOM_PAGE_WIDTH ) )
401 aZoom.SetType(SvxZoomType::PAGEWIDTH);
402 else if(sEntry == SvxResId( RID_SVXSTR_ZOOM_OPTIMAL_VIEW ) )
403 aZoom.SetType(SvxZoomType::OPTIMAL);
404 else if(sEntry == SvxResId( RID_SVXSTR_ZOOM_WHOLE_PAGE) )
405 aZoom.SetType(SvxZoomType::WHOLEPAGE);
406 else
408 bNonNumeric = false;
410 sal_uInt16 nZoom = o3tl::narrowing<sal_uInt16>(sEntry.toInt32());
411 if(nZoom < MINZOOM)
412 nZoom = MINZOOM;
413 if(nZoom > MAXZOOM)
414 nZoom = MAXZOOM;
415 aZoom.SetValue(nZoom);
418 if (bNonNumeric)
420 // put old value back, in case its effectively the same
421 // as the picked option and no update to number comes
422 // back from writer
423 m_xWidget->set_entry_text(m_xWidget->get_saved_value());
426 if (SfxObjectShell* pCurrentShell = SfxObjectShell::Current())
428 pCurrentShell->GetDispatcher()->ExecuteList(SID_ATTR_ZOOM,
429 SfxCallMode::ASYNCHRON, { &aZoom });
432 ReleaseFocus();
435 IMPL_LINK(SwZoomBox_Impl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
437 bool bHandled = false;
439 sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
441 switch (nCode)
443 case KEY_TAB:
444 m_bRelease = false;
445 Select();
446 break;
448 case KEY_ESCAPE:
449 m_xWidget->set_entry_text(m_xWidget->get_saved_value());
450 ReleaseFocus();
451 bHandled = true;
452 break;
455 return bHandled || ChildKeyInput(rKEvt);
458 IMPL_LINK_NOARG(SwZoomBox_Impl, FocusOutHdl, weld::Widget&, void)
460 if (!m_xWidget->has_focus()) // a combobox can be comprised of different subwidget so double-check if none of those has focus
461 m_xWidget->set_entry_text(m_xWidget->get_saved_value());
464 void SwZoomBox_Impl::ReleaseFocus()
466 if ( !m_bRelease )
468 m_bRelease = true;
469 return;
471 SfxViewShell* pCurSh = SfxViewShell::Current();
473 if ( pCurSh )
475 vcl::Window* pShellWnd = pCurSh->GetWindow();
477 if ( pShellWnd )
478 pShellWnd->GrabFocus();
482 SFX_IMPL_TOOLBOX_CONTROL( SwPreviewZoomControl, SfxUInt16Item);
484 SwPreviewZoomControl::SwPreviewZoomControl(
485 sal_uInt16 nSlotId,
486 ToolBoxItemId nId,
487 ToolBox& rTbx) :
488 SfxToolBoxControl( nSlotId, nId, rTbx )
492 SwPreviewZoomControl::~SwPreviewZoomControl()
496 void SwPreviewZoomControl::StateChangedAtToolBoxControl( sal_uInt16 /*nSID*/,
497 SfxItemState eState,
498 const SfxPoolItem* pState )
500 ToolBoxItemId nId = GetId();
501 GetToolBox().EnableItem( nId, (GetItemState(pState) != SfxItemState::DISABLED) );
502 SwZoomBox_Impl* pBox = static_cast<SwZoomBox_Impl*>(GetToolBox().GetItemWindow( GetId() ));
503 if(SfxItemState::DEFAULT <= eState)
505 OUString sZoom(unicode::formatPercent(static_cast<const SfxUInt16Item*>(pState)->GetValue(),
506 Application::GetSettings().GetUILanguageTag()));
507 pBox->set_entry_text(sZoom);
508 pBox->save_value();
512 VclPtr<InterimItemWindow> SwPreviewZoomControl::CreateItemWindow( vcl::Window *pParent )
514 VclPtrInstance<SwZoomBox_Impl> pRet( pParent, GetSlotId() );
515 return pRet.get();
518 namespace {
520 class SwJumpToSpecificBox_Impl final : public InterimItemWindow
522 std::unique_ptr<weld::Entry> m_xWidget;
524 sal_uInt16 m_nSlotId;
526 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
527 DECL_LINK(SelectHdl, weld::Entry&, bool);
528 public:
529 SwJumpToSpecificBox_Impl(vcl::Window* pParent, sal_uInt16 nSlot);
530 virtual void dispose() override
532 m_xWidget.reset();
533 InterimItemWindow::dispose();
535 virtual ~SwJumpToSpecificBox_Impl() override
537 disposeOnce();
543 IMPL_LINK(SwJumpToSpecificBox_Impl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
545 return ChildKeyInput(rKEvt);
548 SwJumpToSpecificBox_Impl::SwJumpToSpecificBox_Impl(vcl::Window* pParent, sal_uInt16 nSlot)
549 : InterimItemWindow(pParent, "modules/swriter/ui/jumpposbox.ui", "JumpPosBox")
550 , m_xWidget(m_xBuilder->weld_entry("jumppos"))
551 , m_nSlotId(nSlot)
553 InitControlBase(m_xWidget.get());
555 m_xWidget->connect_key_press(LINK(this, SwJumpToSpecificBox_Impl, KeyInputHdl));
556 m_xWidget->connect_activate(LINK(this, SwJumpToSpecificBox_Impl, SelectHdl));
558 SetSizePixel(m_xWidget->get_preferred_size());
561 IMPL_LINK_NOARG(SwJumpToSpecificBox_Impl, SelectHdl, weld::Entry&, bool)
563 OUString sEntry(m_xWidget->get_text());
564 SfxUInt16Item aPageNum(m_nSlotId);
565 aPageNum.SetValue(o3tl::narrowing<sal_uInt16>(sEntry.toInt32()));
566 if (SfxObjectShell* pCurrentShell = SfxObjectShell::Current())
568 pCurrentShell->GetDispatcher()->ExecuteList(m_nSlotId, SfxCallMode::ASYNCHRON,
569 { &aPageNum });
571 return true;
574 SFX_IMPL_TOOLBOX_CONTROL( SwJumpToSpecificPageControl, SfxUInt16Item);
576 SwJumpToSpecificPageControl::SwJumpToSpecificPageControl(
577 sal_uInt16 nSlotId,
578 ToolBoxItemId nId,
579 ToolBox& rTbx) :
580 SfxToolBoxControl( nSlotId, nId, rTbx )
583 SwJumpToSpecificPageControl::~SwJumpToSpecificPageControl()
586 VclPtr<InterimItemWindow> SwJumpToSpecificPageControl::CreateItemWindow( vcl::Window *pParent )
588 VclPtrInstance<SwJumpToSpecificBox_Impl> pRet( pParent, GetSlotId() );
589 return pRet.get();
592 NavElementBox_Base::NavElementBox_Base(std::unique_ptr<weld::ComboBox> xComboBox,
593 uno::Reference<frame::XFrame> xFrame)
594 : m_xComboBox(std::move(xComboBox))
595 ,m_xFrame(std::move(xFrame))
597 m_xComboBox->set_size_request(150, -1);
599 m_xComboBox->make_sorted();
600 m_xComboBox->freeze();
601 for (sal_uInt16 i = 0; i < NID_COUNT; i++)
602 m_xComboBox->append(OUString::number(aNavigationInsertIds[i]),
603 SwResId(aNavigationStrIds[i]), OUString(aNavigationImgIds[i]));
604 m_xComboBox->thaw();
606 m_xComboBox->connect_changed(LINK(this, NavElementBox_Base, SelectHdl));
607 m_xComboBox->connect_key_press(LINK(this, NavElementBox_Base, KeyInputHdl));
610 NavElementBox_Impl::NavElementBox_Impl(vcl::Window* pParent,
611 const uno::Reference<frame::XFrame>& xFrame)
612 : InterimItemWindow(pParent, "modules/swriter/ui/combobox.ui", "ComboBox")
613 ,NavElementBox_Base(m_xBuilder->weld_combo_box("combobox"), xFrame)
615 SetSizePixel(m_xContainer->get_preferred_size());
618 void NavElementBox_Base::ReleaseFocus_Impl()
620 if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
621 m_xFrame->getContainerWindow()->setFocus();
624 IMPL_STATIC_LINK(NavElementBox_Base, SelectHdl, weld::ComboBox&, rComboBox, void)
626 if (!rComboBox.changed_by_direct_pick()) // only when picked from the list
627 return;
628 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
629 if (!pViewFrm)
630 return;
631 SfxUInt32Item aParam(FN_NAV_ELEMENT, rComboBox.get_active_id().toUInt32());
632 const SfxPoolItem* aArgs[2];
633 aArgs[0] = &aParam;
634 aArgs[1] = nullptr;
635 SfxDispatcher* pDispatch = pViewFrm->GetBindings().GetDispatcher();
636 pDispatch->Execute(FN_NAV_ELEMENT, SfxCallMode::SYNCHRON, aArgs);
639 void NavElementBox_Base::UpdateBox()
641 sal_uInt16 nMoveType = SwView::GetMoveType();
642 for (size_t i = 0; i < SAL_N_ELEMENTS(aNavigationInsertIds); ++i)
644 if (nMoveType == aNavigationInsertIds[i])
646 m_xComboBox->set_active_text(SwResId(aNavigationStrIds[i]));
647 break;
652 IMPL_LINK(NavElementBox_Base, KeyInputHdl, const KeyEvent&, rKEvt, bool)
654 return DoKeyInput(rKEvt);
657 bool NavElementBox_Base::DoKeyInput(const KeyEvent& /*rKEvt*/)
659 return false;
662 bool NavElementBox_Impl::DoKeyInput(const KeyEvent& rKEvt)
664 if (KEY_ESCAPE == rKEvt.GetKeyCode().GetCode())
666 ReleaseFocus_Impl();
667 return true;
669 return ChildKeyInput(rKEvt);
672 NavElementToolBoxControl::NavElementToolBoxControl( const uno::Reference< uno::XComponentContext >& rxContext )
673 : NavElementToolBoxControl_Base( rxContext,
674 uno::Reference< frame::XFrame >(),
675 ".uno:NavElement" ),
676 m_pBox( nullptr )
680 // XServiceInfo
681 sal_Bool SAL_CALL NavElementToolBoxControl::supportsService( const OUString& ServiceName )
683 return cppu::supportsService( this, ServiceName );
686 OUString SAL_CALL NavElementToolBoxControl::getImplementationName()
688 return "lo.writer.NavElementToolBoxController";
691 uno::Sequence< OUString > SAL_CALL NavElementToolBoxControl::getSupportedServiceNames()
693 return { "com.sun.star.frame.ToolbarController" };
696 // XComponent
697 void SAL_CALL NavElementToolBoxControl::dispose()
699 svt::ToolboxController::dispose();
701 SolarMutexGuard aSolarMutexGuard;
702 m_xVclBox.disposeAndClear();
703 m_xWeldBox.reset();
704 m_pBox = nullptr;
707 // XStatusListener
708 void SAL_CALL NavElementToolBoxControl::statusChanged( const frame::FeatureStateEvent& rEvent )
710 if (!m_pBox)
711 return;
713 SolarMutexGuard aSolarMutexGuard;
714 if ( rEvent.FeatureURL.Path != "NavElement" )
715 return;
717 if ( rEvent.IsEnabled )
719 m_pBox->set_sensitive(true);
720 m_pBox->UpdateBox();
722 else
723 m_pBox->set_sensitive(true);
725 if (SwView* pView = GetActiveView())
727 pView->GetViewFrame().GetBindings().Invalidate(FN_SCROLL_NEXT);
728 pView->GetViewFrame().GetBindings().Invalidate(FN_SCROLL_PREV);
732 // XToolbarController
733 void SAL_CALL NavElementToolBoxControl::execute( sal_Int16 /*KeyModifier*/ )
737 void SAL_CALL NavElementToolBoxControl::click()
741 void SAL_CALL NavElementToolBoxControl::doubleClick()
745 uno::Reference< awt::XWindow > SAL_CALL NavElementToolBoxControl::createPopupWindow()
747 return uno::Reference< awt::XWindow >();
750 uno::Reference< awt::XWindow > SAL_CALL NavElementToolBoxControl::createItemWindow(
751 const uno::Reference< awt::XWindow >& xParent )
753 uno::Reference< awt::XWindow > xItemWindow;
755 if (m_pBuilder)
757 SolarMutexGuard aSolarMutexGuard;
759 std::unique_ptr<weld::ComboBox> xWidget(m_pBuilder->weld_combo_box("NavElementWidget"));
761 xItemWindow = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get()));
763 m_xWeldBox.reset(new NavElementBox_Base(std::move(xWidget), m_xFrame));
764 m_pBox = m_xWeldBox.get();
766 else
768 VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent );
769 if ( pParent )
771 SolarMutexGuard aSolarMutexGuard;
772 m_xVclBox = VclPtr<NavElementBox_Impl>::Create( pParent, m_xFrame );
773 m_pBox = m_xVclBox.get();
774 xItemWindow = VCLUnoHelper::GetInterface(m_xVclBox);
778 return xItemWindow;
781 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
782 lo_writer_NavElementToolBoxController_get_implementation(
783 css::uno::XComponentContext *rxContext,
784 css::uno::Sequence<css::uno::Any> const &)
786 return cppu::acquire( new NavElementToolBoxControl( rxContext ) );
789 namespace {
791 typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo> PrevNextScrollToolboxController_Base;
792 class PrevNextScrollToolboxController : public PrevNextScrollToolboxController_Base
794 public:
795 enum Type { PREVIOUS, NEXT };
797 PrevNextScrollToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext, Type eType );
799 // XServiceInfo
800 virtual OUString SAL_CALL getImplementationName() override;
801 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
802 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
804 // XComponent
805 virtual void SAL_CALL dispose() override;
807 // XStatusListener
808 virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
810 private:
811 Type meType;
816 PrevNextScrollToolboxController::PrevNextScrollToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext, Type eType )
817 : PrevNextScrollToolboxController_Base( rxContext,
818 css::uno::Reference< css::frame::XFrame >(),
819 (eType == PREVIOUS) ? OUString( ".uno:ScrollToPrevious" ): OUString( ".uno:ScrollToNext" ) ),
820 meType( eType )
822 addStatusListener(".uno:NavElement");
825 // XServiceInfo
826 OUString SAL_CALL PrevNextScrollToolboxController::getImplementationName()
828 return meType == PrevNextScrollToolboxController::PREVIOUS?
829 OUString( "lo.writer.PreviousScrollToolboxController" ) :
830 OUString( "lo.writer.NextScrollToolboxController" );
833 sal_Bool SAL_CALL PrevNextScrollToolboxController::supportsService( const OUString& ServiceName )
835 return cppu::supportsService(this, ServiceName);
838 css::uno::Sequence< OUString > SAL_CALL PrevNextScrollToolboxController::getSupportedServiceNames()
840 return { "com.sun.star.frame.ToolbarController" };
843 // XComponent
844 void SAL_CALL PrevNextScrollToolboxController::dispose()
846 SolarMutexGuard aSolarMutexGuard;
848 svt::ToolboxController::dispose();
851 // XStatusListener
852 void SAL_CALL PrevNextScrollToolboxController::statusChanged( const css::frame::FeatureStateEvent& rEvent )
854 if (rEvent.FeatureURL.Path == "NavElement")
856 if (m_pToolbar)
857 m_pToolbar->set_item_tooltip_text(m_aCommandURL, lcl_GetScrollToolTip(meType != PrevNextScrollToolboxController::PREVIOUS));
858 else
860 ToolBox* pToolBox = nullptr;
861 ToolBoxItemId nId;
862 if (getToolboxId(nId, &pToolBox))
863 pToolBox->SetQuickHelpText(nId, lcl_GetScrollToolTip(meType != PrevNextScrollToolboxController::PREVIOUS));
866 else if (rEvent.FeatureURL.Path == "ScrollToPrevious" || rEvent.FeatureURL.Path == "ScrollToNext")
868 if (m_pToolbar)
869 m_pToolbar->set_item_sensitive(m_aCommandURL, rEvent.IsEnabled);
870 else
872 ToolBox* pToolBox = nullptr;
873 ToolBoxItemId nId;
874 if (getToolboxId(nId, &pToolBox))
875 pToolBox->EnableItem(nId, rEvent.IsEnabled);
880 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
881 lo_writer_PreviousScrollToolboxController_get_implementation(
882 css::uno::XComponentContext *context,
883 css::uno::Sequence<css::uno::Any> const &)
885 return cppu::acquire( new PrevNextScrollToolboxController( context, PrevNextScrollToolboxController::PREVIOUS ) );
888 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
889 lo_writer_NextScrollToolboxController_get_implementation(
890 css::uno::XComponentContext *context,
891 css::uno::Sequence<css::uno::Any> const &)
893 return cppu::acquire( new PrevNextScrollToolboxController( context, PrevNextScrollToolboxController::NEXT ) );
896 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */