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 <svl/intitem.hxx>
21#include <svl/slstitm.hxx>
22#include <sfx2/dispatch.hxx>
23#include <sfx2/viewfrm.hxx>
24#include <vcl/commandevent.hxx>
25#include <vcl/event.hxx>
26#include <vcl/status.hxx>
27#include <vcl/weldutils.hxx>
28#include <cmdid.h>
29#include <swmodule.hxx>
30#include <wrtsh.hxx>
31#include <IMark.hxx>
32#include <bookctrl.hxx>
33#include <map>
34
36
38 sal_uInt16 _nId,
39 StatusBar& rStb ) :
40 SfxStatusBarControl( _nSlotId, _nId, rStb )
41{
42}
43
45{
46}
47
49 sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
50{
51 if( eState != SfxItemState::DEFAULT || pState->IsVoidItem() )
52 {
53 GetStatusBar().SetItemText(GetId(), OUString());
54 GetStatusBar().SetQuickHelpText(GetId(), OUString());
55 }
56 else if (auto pStringListItem = dynamic_cast<const SfxStringListItem*>(pState))
57 {
58 const std::vector<OUString>& rStringList(pStringListItem->GetList());
59 GetStatusBar().SetItemText(GetId(), rStringList[0]);
60 GetStatusBar().SetQuickHelpText(GetId(), rStringList[1]);
61 }
62}
63
65{
66}
67
69{
70 if ( rCEvt.GetCommand() != CommandEventId::ContextMenu ||
71 GetStatusBar().GetItemText( GetId() ).isEmpty())
72 return;
73
74 SwWrtShell* pWrtShell = ::GetActiveWrtShell();
75 if( !(pWrtShell && pWrtShell->getIDocumentMarkAccess()->getAllMarksCount() > 0) )
76 return;
77
79 if (!pViewFrm)
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));
102 OUString 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: */
SFX_IMPL_STATUSBAR_CONTROL(SwBookmarkControl, SfxStringListItem)
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
CommandEventId GetCommand() const
const Point & GetMousePosPixel() const
wrapper iterator: wraps iterator of implementation while hiding MarkBase class; only IMark instances ...
Provides access to the marks of a document.
virtual const_iterator_t getBookmarksBegin() const =0
returns a STL-like random access iterator to the begin of the sequence the IBookmarks.
virtual sal_Int32 getAllMarksCount() const =0
returns the number of marks.
static SW_DLLPUBLIC MarkType GetType(const ::sw::mark::IMark &rMark)
Returns the MarkType used to create the mark.
Definition: docbm.cxx:502
virtual const_iterator_t getBookmarksEnd() const =0
returns a STL-like random access iterator to the end of the sequence of IBookmarks.
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 * >())
virtual bool IsVoidItem() const
StatusBar & GetStatusBar() const
sal_uInt16 GetId() const
static SAL_WARN_UNUSED_RESULT SfxViewFrame * Current()
SfxDispatcher * GetDispatcher()
void SetItemText(sal_uInt16 nItemId, const OUString &rText, int nCharsWidth=-1)
void SetQuickHelpText(sal_uInt16 nItemId, const OUString &rText)
virtual void StateChangedAtStatusBarControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: bookctrl.cxx:48
SwBookmarkControl(sal_uInt16 nSlotId, sal_uInt16 nId, StatusBar &rStb)
Definition: bookctrl.cxx:37
virtual ~SwBookmarkControl() override
Definition: bookctrl.cxx:44
virtual void Paint(const UserDrawEvent &rEvt) override
Definition: bookctrl.cxx:64
virtual void Command(const CommandEvent &rCEvt) override
Definition: bookctrl.cxx:68
const IDocumentMarkAccess * getIDocumentMarkAccess() const
Provides access to the document bookmark interface.
Definition: viewsh.cxx:2821
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
#define FN_STAT_BOOKMARK
Definition: cmdid.h:868
weld::Window * GetPopupParent(vcl::Window &rOutWin, tools::Rectangle &rRect)
SfxItemState
SwWrtShell * GetActiveWrtShell()
Definition: swmodul1.cxx:108