LibreOffice Module sw (master)  1
bookctrl.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 <swtypes.hxx>
21 #include <strings.hrc>
22 
23 #include <svl/intitem.hxx>
24 #include <svl/slstitm.hxx>
25 #include <svl/eitem.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <vcl/commandevent.hxx>
29 #include <vcl/event.hxx>
30 #include <vcl/status.hxx>
31 #include <vcl/weldutils.hxx>
32 #include <cmdid.h>
33 #include <swmodule.hxx>
34 #include <wrtsh.hxx>
35 #include <IMark.hxx>
36 #include <bookctrl.hxx>
37 #include <map>
38 
40 
42  sal_uInt16 _nId,
43  StatusBar& rStb ) :
44  SfxStatusBarControl( _nSlotId, _nId, rStb )
45 {
46 }
47 
49 {
50 }
51 
53  sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
54 {
55  if( eState != SfxItemState::DEFAULT || pState->IsVoidItem() )
56  {
57  GetStatusBar().SetItemText(GetId(), OUString());
58  GetStatusBar().SetQuickHelpText(GetId(), OUString());
59  }
60  else if (auto pStringListItem = dynamic_cast<const SfxStringListItem*>(pState))
61  {
62  const std::vector<OUString>& rStringList(pStringListItem->GetList());
63  GetStatusBar().SetItemText(GetId(), rStringList[0]);
64  GetStatusBar().SetQuickHelpText(GetId(), rStringList[1]);
65  }
66 }
67 
69 {
70 }
71 
73 {
74  if ( rCEvt.GetCommand() != CommandEventId::ContextMenu ||
75  GetStatusBar().GetItemText( GetId() ).isEmpty())
76  return;
77 
78  SwWrtShell* pWrtShell = ::GetActiveWrtShell();
79  if( !(pWrtShell && pWrtShell->getIDocumentMarkAccess()->getAllMarksCount() > 0) )
80  return;
81 
82  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, "modules/swriter/ui/bookmarkmenu.ui"));
83  std::unique_ptr<weld::Menu> xPopup(xBuilder->weld_menu("menu"));
84 
85  IDocumentMarkAccess* const pMarkAccess = pWrtShell->getIDocumentMarkAccess();
86  IDocumentMarkAccess::const_iterator_t ppBookmarkStart = pMarkAccess->getBookmarksBegin();
87  sal_uInt32 nPopupId = 1;
88  std::map<sal_Int32, sal_uInt16> aBookmarkIdx;
89  for(IDocumentMarkAccess::const_iterator_t ppBookmark = ppBookmarkStart;
90  ppBookmark != pMarkAccess->getBookmarksEnd();
91  ++ppBookmark)
92  {
94  {
95  xPopup->append(OUString::number(nPopupId), (*ppBookmark)->GetName());
96  aBookmarkIdx[nPopupId] = o3tl::narrowing<sal_uInt16>(ppBookmark - ppBookmarkStart);
97  nPopupId++;
98  }
99  }
100  ::tools::Rectangle aRect(rCEvt.GetMousePosPixel(), Size(1, 1));
101  weld::Window* pParent = weld::GetPopupParent(GetStatusBar(), aRect);
102  OString sResult = xPopup->popup_at_rect(pParent, aRect);
103  if (!sResult.isEmpty())
104  {
105  SfxUInt16Item aBookmark( FN_STAT_BOOKMARK, aBookmarkIdx[sResult.toUInt32()] );
107  SfxCallMode::ASYNCHRON|SfxCallMode::RECORD,
108  { &aBookmark });
109  }
110 }
111 
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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 FN_STAT_BOOKMARK
Definition: cmdid.h:834
SfxDispatcher * GetDispatcher()
wrapper iterator: wraps iterator of implementation while hiding MarkBase class; only IMark instances ...
static SW_DLLPUBLIC MarkType GetType(const ::sw::mark::IMark &rMark)
Returns the MarkType used to create the mark.
Definition: docbm.cxx:478
const OUString & GetItemText(sal_uInt16 nItemId) const
SwWrtShell * GetActiveWrtShell()
Definition: swmodul1.cxx:108
Provides access to the marks of a document.
void SetItemText(sal_uInt16 nItemId, const OUString &rText, int nCharsWidth=-1)
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false)
virtual ~SwBookmarkControl() override
Definition: bookctrl.cxx:48
SwBookmarkControl(sal_uInt16 nSlotId, sal_uInt16 nId, StatusBar &rStb)
Definition: bookctrl.cxx:41
Used by the UI to modify the document model.
Definition: wrtsh.hxx:93
SFX_IMPL_STATUSBAR_CONTROL(SwBookmarkControl, SfxStringListItem)
const IDocumentMarkAccess * getIDocumentMarkAccess() const
Provides access to the document bookmark interface.
Definition: viewsh.cxx:2665
virtual bool IsVoidItem() const
virtual void Paint(const UserDrawEvent &rEvt) override
Definition: bookctrl.cxx:68
sal_uInt16 GetId() const
virtual void Command(const CommandEvent &rCEvt) override
Definition: bookctrl.cxx:72
weld::Window * GetPopupParent(vcl::Window &rOutWin, tools::Rectangle &rRect)
CommandEventId GetCommand() const
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: bookctrl.cxx:52
const Point & GetMousePosPixel() const
void SetQuickHelpText(sal_uInt16 nItemId, const OUString &rText)
static SfxViewFrame * Current()
SfxItemState
virtual sal_Int32 getAllMarksCount() const =0
returns the number of marks.
StatusBar & GetStatusBar() const