Line data Source code
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 <utlui.hrc>
23 :
24 : #include <svl/intitem.hxx>
25 : #include <svl/stritem.hxx>
26 : #include <sfx2/dispatch.hxx>
27 : #include <vcl/event.hxx>
28 : #include <vcl/status.hxx>
29 : #include <vcl/menu.hxx>
30 : #include "cmdid.h"
31 : #include "swmodule.hxx"
32 : #include "wrtsh.hxx"
33 : #include "IMark.hxx"
34 : #include "bookctrl.hxx"
35 : #include <map>
36 :
37 405 : SFX_IMPL_STATUSBAR_CONTROL( SwBookmarkControl, SfxStringItem );
38 :
39 0 : class BookmarkPopup_Impl : public PopupMenu
40 : {
41 : public:
42 : BookmarkPopup_Impl();
43 :
44 0 : sal_uInt16 GetCurId() const { return nCurId; }
45 :
46 : private:
47 : sal_uInt16 nCurId;
48 :
49 : virtual void Select() SAL_OVERRIDE;
50 : };
51 :
52 0 : BookmarkPopup_Impl::BookmarkPopup_Impl() :
53 : PopupMenu(),
54 0 : nCurId(USHRT_MAX)
55 : {
56 0 : }
57 :
58 0 : void BookmarkPopup_Impl::Select()
59 : {
60 0 : nCurId = GetCurItemId();
61 0 : }
62 :
63 346 : SwBookmarkControl::SwBookmarkControl( sal_uInt16 _nSlotId,
64 : sal_uInt16 _nId,
65 : StatusBar& rStb ) :
66 346 : SfxStatusBarControl( _nSlotId, _nId, rStb )
67 : {
68 346 : }
69 :
70 692 : SwBookmarkControl::~SwBookmarkControl()
71 : {
72 692 : }
73 :
74 720 : void SwBookmarkControl::StateChanged(
75 : sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
76 : {
77 720 : if( eState != SfxItemState::DEFAULT || pState->ISA( SfxVoidItem ) )
78 0 : GetStatusBar().SetItemText( GetId(), OUString() );
79 720 : else if ( pState->ISA( SfxStringItem ) )
80 : {
81 669 : sPageNumber = static_cast<const SfxStringItem*>(pState)->GetValue();
82 669 : GetStatusBar().SetItemText( GetId(), sPageNumber );
83 : }
84 51 : else if ( pState->ISA( SfxBoolItem ) )
85 : {
86 51 : if (static_cast<const SfxBoolItem*>(pState)->GetValue()) // Indicates whether to show extended tooltip
87 0 : GetStatusBar().SetQuickHelpText(GetId(), SW_RESSTR(STR_BOOKCTRL_HINT_EXTENDED));
88 : else
89 51 : GetStatusBar().SetQuickHelpText(GetId(), SW_RESSTR(STR_BOOKCTRL_HINT));
90 : }
91 :
92 720 : }
93 :
94 0 : void SwBookmarkControl::Paint( const UserDrawEvent& )
95 : {
96 0 : GetStatusBar().SetItemText( GetId(), sPageNumber );
97 0 : }
98 :
99 0 : void SwBookmarkControl::Command( const CommandEvent& rCEvt )
100 : {
101 0 : if ( rCEvt.GetCommand() == CommandEventId::ContextMenu &&
102 0 : !GetStatusBar().GetItemText( GetId() ).isEmpty() )
103 : {
104 0 : BookmarkPopup_Impl aPop;
105 0 : SwWrtShell* pWrtShell = ::GetActiveWrtShell();
106 0 : if( pWrtShell && pWrtShell->getIDocumentMarkAccess()->getAllMarksCount() > 0 )
107 : {
108 0 : IDocumentMarkAccess* const pMarkAccess = pWrtShell->getIDocumentMarkAccess();
109 0 : IDocumentMarkAccess::const_iterator_t ppBookmarkStart = pMarkAccess->getBookmarksBegin();
110 0 : sal_uInt16 nPopupId = 1;
111 0 : ::std::map<sal_Int32, sal_uInt16> aBookmarkIdx;
112 0 : for(IDocumentMarkAccess::const_iterator_t ppBookmark = ppBookmarkStart;
113 0 : ppBookmark != pMarkAccess->getBookmarksEnd();
114 : ++ppBookmark)
115 : {
116 0 : if(IDocumentMarkAccess::MarkType::BOOKMARK == IDocumentMarkAccess::GetType(**ppBookmark))
117 : {
118 0 : aPop.InsertItem( nPopupId, ppBookmark->get()->GetName() );
119 0 : aBookmarkIdx[nPopupId] = static_cast<sal_uInt16>(ppBookmark - ppBookmarkStart);
120 0 : nPopupId++;
121 : }
122 : }
123 0 : aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
124 0 : sal_uInt16 nCurrId = aPop.GetCurId();
125 0 : if( nCurrId != USHRT_MAX)
126 : {
127 0 : SfxUInt16Item aBookmark( FN_STAT_BOOKMARK, aBookmarkIdx[nCurrId] );
128 : SfxViewFrame::Current()->GetDispatcher()->Execute( FN_STAT_BOOKMARK,
129 : SfxCallMode::ASYNCHRON|SfxCallMode::RECORD,
130 0 : &aBookmark, 0L );
131 0 : }
132 0 : }
133 : }
134 177 : }
135 :
136 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|