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 <hintids.hxx>
21 #include <swtypes.hxx>
22 #include <strings.hrc>
23 
24 #include <svl/intitem.hxx>
25 #include <svl/stritem.hxx>
26 #include <svl/eitem.hxx>
27 #include <sfx2/dispatch.hxx>
28 #include <sfx2/viewfrm.hxx>
29 #include <vcl/commandevent.hxx>
30 #include <vcl/event.hxx>
31 #include <vcl/status.hxx>
32 #include <vcl/menu.hxx>
33 #include <cmdid.h>
34 #include <swmodule.hxx>
35 #include <wrtsh.hxx>
36 #include <IMark.hxx>
37 #include <bookctrl.hxx>
38 #include <map>
39 
41 
43 {
44 public:
46 
47  sal_uInt16 GetCurId() const { return nCurId; }
48 
49 private:
50  sal_uInt16 nCurId;
51 
52  virtual void Select() override;
53 };
54 
56  PopupMenu(),
57  nCurId(USHRT_MAX)
58 {
59 }
60 
62 {
63  nCurId = GetCurItemId();
64 }
65 
67  sal_uInt16 _nId,
68  StatusBar& rStb ) :
69  SfxStatusBarControl( _nSlotId, _nId, rStb )
70 {
71 }
72 
74 {
75 }
76 
78  sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
79 {
80  if( eState != SfxItemState::DEFAULT || pState->IsVoidItem() )
81  GetStatusBar().SetItemText( GetId(), OUString() );
82  else if (const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>(pState))
83  {
84  sPageNumber = pStringItem->GetValue();
86  }
87  else if (const SfxBoolItem* pBoolItem = dynamic_cast<const SfxBoolItem*>(pState))
88  {
89  if (pBoolItem->GetValue()) // Indicates whether to show extended tooltip
90  GetStatusBar().SetQuickHelpText(GetId(), SwResId(STR_BOOKCTRL_HINT_EXTENDED));
91  else
92  GetStatusBar().SetQuickHelpText(GetId(), SwResId(STR_BOOKCTRL_HINT));
93  }
94 
95 }
96 
98 {
99 }
100 
102 {
103  if ( rCEvt.GetCommand() == CommandEventId::ContextMenu &&
104  !GetStatusBar().GetItemText( GetId() ).isEmpty() )
105  {
107  SwWrtShell* pWrtShell = ::GetActiveWrtShell();
108  if( pWrtShell && pWrtShell->getIDocumentMarkAccess()->getAllMarksCount() > 0 )
109  {
110  IDocumentMarkAccess* const pMarkAccess = pWrtShell->getIDocumentMarkAccess();
111  IDocumentMarkAccess::const_iterator_t ppBookmarkStart = pMarkAccess->getBookmarksBegin();
112  sal_uInt16 nPopupId = 1;
113  std::map<sal_Int32, sal_uInt16> aBookmarkIdx;
114  for(IDocumentMarkAccess::const_iterator_t ppBookmark = ppBookmarkStart;
115  ppBookmark != pMarkAccess->getBookmarksEnd();
116  ++ppBookmark)
117  {
119  {
120  aPop->InsertItem( nPopupId, (*ppBookmark)->GetName() );
121  aBookmarkIdx[nPopupId] = static_cast<sal_uInt16>(ppBookmark - ppBookmarkStart);
122  nPopupId++;
123  }
124  }
125  aPop->Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
126  sal_uInt16 nCurrId = aPop->GetCurId();
127  if( nCurrId != USHRT_MAX)
128  {
129  SfxUInt16Item aBookmark( FN_STAT_BOOKMARK, aBookmarkIdx[nCurrId] );
131  SfxCallMode::ASYNCHRON|SfxCallMode::RECORD,
132  { &aBookmark });
133  }
134  }
135  }
136 }
137 
138 /* 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:812
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:474
const OUString & GetItemText(sal_uInt16 nItemId) const
SwWrtShell * GetActiveWrtShell()
Definition: swmodul1.cxx:115
Provides access to the marks of a document.
void SetItemText(sal_uInt16 nItemId, const OUString &rText, int nCharsWidth=-1)
virtual ~SwBookmarkControl() override
Definition: bookctrl.cxx:73
SwBookmarkControl(sal_uInt16 nSlotId, sal_uInt16 nId, StatusBar &rStb)
Definition: bookctrl.cxx:66
sal_uInt16 Execute(vcl::Window *pWindow, const Point &rPopupPos)
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
sal_uInt16 nCurId
Definition: bookctrl.cxx:50
sal_uInt16 GetCurId() const
Definition: bookctrl.cxx:47
const IDocumentMarkAccess * getIDocumentMarkAccess() const
Provides access to the document bookmark interface.
Definition: viewsh.cxx:2595
virtual bool IsVoidItem() const
virtual void Paint(const UserDrawEvent &rEvt) override
Definition: bookctrl.cxx:97
virtual void Select() override
Definition: bookctrl.cxx:61
sal_uInt16 GetId() const
virtual const_iterator_t getBookmarksEnd() const =0
returns a STL-like random access iterator to the end of the sequence of IBookmarks.
virtual void Command(const CommandEvent &rCEvt) override
Definition: bookctrl.cxx:101
sal_uInt16 GetCurItemId() const
CommandEventId GetCommand() const
OUString sPageNumber
Definition: bookctrl.hxx:40
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: bookctrl.cxx:77
OUString SwResId(const char *pId)
Definition: swmodule.cxx:190
const Point & GetMousePosPixel() const
void InsertItem(sal_uInt16 nItemId, const OUString &rStr, MenuItemBits nItemBits=MenuItemBits::NONE, const OString &rIdent=OString(), sal_uInt16 nPos=MENU_APPEND)
void SetQuickHelpText(sal_uInt16 nItemId, const OUString &rText)
static SfxViewFrame * Current()
SfxItemState
virtual sal_Int32 getAllMarksCount() const =0
returns the number of marks.
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:261
virtual const_iterator_t getBookmarksBegin() const =0
returns a STL-like random access iterator to the begin of the sequence the IBookmarks.
StatusBar & GetStatusBar() const
SFX_IMPL_STATUSBAR_CONTROL(SwBookmarkControl, SfxStringItem)