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 :
22 : #include <svl/intitem.hxx>
23 : #include <svl/stritem.hxx>
24 : #include <sfx2/dispatch.hxx>
25 : #include <vcl/event.hxx>
26 : #include <vcl/status.hxx>
27 : #include <vcl/menu.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 :
35 10 : SFX_IMPL_STATUSBAR_CONTROL( SwBookmarkControl, SfxStringItem );
36 :
37 : // class BookmarkPopup_Impl --------------------------------------------------
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();
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 : // class SvxZoomStatusBarControl ------------------------------------------
64 :
65 0 : SwBookmarkControl::SwBookmarkControl( sal_uInt16 _nSlotId,
66 : sal_uInt16 _nId,
67 : StatusBar& rStb ) :
68 0 : SfxStatusBarControl( _nSlotId, _nId, rStb )
69 : {
70 0 : }
71 :
72 0 : SwBookmarkControl::~SwBookmarkControl()
73 : {
74 0 : }
75 :
76 0 : void SwBookmarkControl::StateChanged(
77 : sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
78 : {
79 0 : if( eState != SFX_ITEM_AVAILABLE || pState->ISA( SfxVoidItem ) )
80 0 : GetStatusBar().SetItemText( GetId(), String() );
81 0 : else if ( pState->ISA( SfxStringItem ) )
82 : {
83 0 : sPageNumber = ((SfxStringItem*)pState)->GetValue();
84 0 : GetStatusBar().SetItemText( GetId(), sPageNumber );
85 : }
86 0 : }
87 :
88 0 : void SwBookmarkControl::Paint( const UserDrawEvent& )
89 : {
90 0 : GetStatusBar().SetItemText( GetId(), sPageNumber );
91 0 : }
92 :
93 0 : void SwBookmarkControl::Command( const CommandEvent& rCEvt )
94 : {
95 0 : if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU &&
96 0 : GetStatusBar().GetItemText( GetId() ).Len() )
97 : {
98 0 : CaptureMouse();
99 0 : BookmarkPopup_Impl aPop;
100 0 : SwWrtShell* pWrtShell = ::GetActiveWrtShell();
101 0 : if( pWrtShell && pWrtShell->getIDocumentMarkAccess()->getMarksCount() > 0 )
102 : {
103 0 : IDocumentMarkAccess* const pMarkAccess = pWrtShell->getIDocumentMarkAccess();
104 0 : IDocumentMarkAccess::const_iterator_t ppBookmarkStart = pMarkAccess->getBookmarksBegin();
105 0 : sal_uInt16 nPopupId = 1;
106 0 : ::std::map<sal_Int32, sal_uInt16> aBookmarkIdx;
107 0 : for(IDocumentMarkAccess::const_iterator_t ppBookmark = ppBookmarkStart;
108 0 : ppBookmark != pMarkAccess->getBookmarksEnd();
109 : ++ppBookmark)
110 : {
111 0 : if(IDocumentMarkAccess::BOOKMARK == IDocumentMarkAccess::GetType(**ppBookmark))
112 : {
113 0 : aPop.InsertItem( nPopupId, ppBookmark->get()->GetName() );
114 0 : aBookmarkIdx[nPopupId] = static_cast<sal_uInt16>(ppBookmark - ppBookmarkStart);
115 0 : nPopupId++;
116 : }
117 : }
118 0 : aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
119 0 : sal_uInt16 nCurrId = aPop.GetCurId();
120 0 : if( nCurrId != USHRT_MAX)
121 : {
122 0 : SfxUInt16Item aBookmark( FN_STAT_BOOKMARK, aBookmarkIdx[nCurrId] );
123 : SfxViewFrame::Current()->GetDispatcher()->Execute( FN_STAT_BOOKMARK,
124 : SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD,
125 0 : &aBookmark, 0L );
126 0 : }
127 : }
128 0 : ReleaseMouse();
129 : }
130 0 : }
131 :
132 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|