1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "hintids.hxx"
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>
29 #include "swmodule.hxx"
32 #include "bookctrl.hxx"
35 SFX_IMPL_STATUSBAR_CONTROL( SwBookmarkControl
, SfxStringItem
);
37 class BookmarkPopup_Impl
: public PopupMenu
42 sal_uInt16
GetCurId() const { return nCurId
; }
47 virtual void Select();
50 BookmarkPopup_Impl::BookmarkPopup_Impl() :
56 void BookmarkPopup_Impl::Select()
58 nCurId
= GetCurItemId();
61 SwBookmarkControl::SwBookmarkControl( sal_uInt16 _nSlotId
,
64 SfxStatusBarControl( _nSlotId
, _nId
, rStb
)
68 SwBookmarkControl::~SwBookmarkControl()
72 void SwBookmarkControl::StateChanged(
73 sal_uInt16
/*nSID*/, SfxItemState eState
, const SfxPoolItem
* pState
)
75 if( eState
!= SFX_ITEM_AVAILABLE
|| pState
->ISA( SfxVoidItem
) )
76 GetStatusBar().SetItemText( GetId(), String() );
77 else if ( pState
->ISA( SfxStringItem
) )
79 sPageNumber
= ((SfxStringItem
*)pState
)->GetValue();
80 GetStatusBar().SetItemText( GetId(), sPageNumber
);
84 void SwBookmarkControl::Paint( const UserDrawEvent
& )
86 GetStatusBar().SetItemText( GetId(), sPageNumber
);
89 void SwBookmarkControl::Command( const CommandEvent
& rCEvt
)
91 if ( rCEvt
.GetCommand() == COMMAND_CONTEXTMENU
&&
92 GetStatusBar().GetItemText( GetId() ).Len() )
95 BookmarkPopup_Impl aPop
;
96 SwWrtShell
* pWrtShell
= ::GetActiveWrtShell();
97 if( pWrtShell
&& pWrtShell
->getIDocumentMarkAccess()->getMarksCount() > 0 )
99 IDocumentMarkAccess
* const pMarkAccess
= pWrtShell
->getIDocumentMarkAccess();
100 IDocumentMarkAccess::const_iterator_t ppBookmarkStart
= pMarkAccess
->getBookmarksBegin();
101 sal_uInt16 nPopupId
= 1;
102 ::std::map
<sal_Int32
, sal_uInt16
> aBookmarkIdx
;
103 for(IDocumentMarkAccess::const_iterator_t ppBookmark
= ppBookmarkStart
;
104 ppBookmark
!= pMarkAccess
->getBookmarksEnd();
107 if(IDocumentMarkAccess::BOOKMARK
== IDocumentMarkAccess::GetType(**ppBookmark
))
109 aPop
.InsertItem( nPopupId
, ppBookmark
->get()->GetName() );
110 aBookmarkIdx
[nPopupId
] = static_cast<sal_uInt16
>(ppBookmark
- ppBookmarkStart
);
114 aPop
.Execute( &GetStatusBar(), rCEvt
.GetMousePosPixel());
115 sal_uInt16 nCurrId
= aPop
.GetCurId();
116 if( nCurrId
!= USHRT_MAX
)
118 SfxUInt16Item
aBookmark( FN_STAT_BOOKMARK
, aBookmarkIdx
[nCurrId
] );
119 SfxViewFrame::Current()->GetDispatcher()->Execute( FN_STAT_BOOKMARK
,
120 SFX_CALLMODE_ASYNCHRON
|SFX_CALLMODE_RECORD
,
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */