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/stritem.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/menu.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 
41 namespace {
42 
43 class BookmarkPopup_Impl : public PopupMenu
44 {
45 public:
46  BookmarkPopup_Impl();
47 
48  sal_uInt16 GetCurId() const { return nCurId; }
49 
50 private:
51  sal_uInt16 nCurId;
52 
53  virtual void Select() override;
54 };
55 
56 }
57 
58 BookmarkPopup_Impl::BookmarkPopup_Impl() :
59  PopupMenu(),
60  nCurId(USHRT_MAX)
61 {
62 }
63 
64 void BookmarkPopup_Impl::Select()
65 {
66  nCurId = GetCurItemId();
67 }
68 
70  sal_uInt16 _nId,
71  StatusBar& rStb ) :
72  SfxStatusBarControl( _nSlotId, _nId, rStb )
73 {
74 }
75 
77 {
78 }
79 
81  sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
82 {
83  if( eState != SfxItemState::DEFAULT || pState->IsVoidItem() )
84  GetStatusBar().SetItemText( GetId(), OUString() );
85  else if (const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>(pState))
86  {
87  sPageNumber = pStringItem->GetValue();
89  }
90  else if (const SfxBoolItem* pBoolItem = dynamic_cast<const SfxBoolItem*>(pState))
91  {
92  if (pBoolItem->GetValue()) // Indicates whether to show extended tooltip
93  GetStatusBar().SetQuickHelpText(GetId(), SwResId(STR_BOOKCTRL_HINT_EXTENDED));
94  else
95  GetStatusBar().SetQuickHelpText(GetId(), SwResId(STR_BOOKCTRL_HINT));
96  }
97 
98 }
99 
101 {
102 }
103 
105 {
106  if ( rCEvt.GetCommand() == CommandEventId::ContextMenu &&
107  !GetStatusBar().GetItemText( GetId() ).isEmpty() )
108  {
110  SwWrtShell* pWrtShell = ::GetActiveWrtShell();
111  if( pWrtShell && pWrtShell->getIDocumentMarkAccess()->getAllMarksCount() > 0 )
112  {
113  IDocumentMarkAccess* const pMarkAccess = pWrtShell->getIDocumentMarkAccess();
114  IDocumentMarkAccess::const_iterator_t ppBookmarkStart = pMarkAccess->getBookmarksBegin();
115  sal_uInt16 nPopupId = 1;
116  std::map<sal_Int32, sal_uInt16> aBookmarkIdx;
117  for(IDocumentMarkAccess::const_iterator_t ppBookmark = ppBookmarkStart;
118  ppBookmark != pMarkAccess->getBookmarksEnd();
119  ++ppBookmark)
120  {
122  {
123  aPop->InsertItem( nPopupId, (*ppBookmark)->GetName() );
124  aBookmarkIdx[nPopupId] = static_cast<sal_uInt16>(ppBookmark - ppBookmarkStart);
125  nPopupId++;
126  }
127  }
128  aPop->Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
129  sal_uInt16 nCurrId = aPop->GetCurId();
130  if( nCurrId != USHRT_MAX)
131  {
132  SfxUInt16Item aBookmark( FN_STAT_BOOKMARK, aBookmarkIdx[nCurrId] );
134  SfxCallMode::ASYNCHRON|SfxCallMode::RECORD,
135  { &aBookmark });
136  }
137  }
138  }
139 }
140 
141 /* 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:825
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:107
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:76
SwBookmarkControl(sal_uInt16 nSlotId, sal_uInt16 nId, StatusBar &rStb)
Definition: bookctrl.cxx:69
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
const IDocumentMarkAccess * getIDocumentMarkAccess() const
Provides access to the document bookmark interface.
Definition: viewsh.cxx:2589
virtual bool IsVoidItem() const
virtual void Paint(const UserDrawEvent &rEvt) override
Definition: bookctrl.cxx:100
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:104
CommandEventId GetCommand() const
OUString sPageNumber
Definition: bookctrl.hxx:40
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: bookctrl.cxx:80
OUString SwResId(const char *pId)
Definition: swmodule.cxx:178
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.
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:253
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)
virtual void Select()