1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sw.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "hintids.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #ifndef _SVSTDARR_HXX 34*cdf0e10cSrcweir #define _SVSTDARR_USHORTS 35*cdf0e10cSrcweir #include <svl/svstdarr.hxx> 36*cdf0e10cSrcweir #endif 37*cdf0e10cSrcweir #include <svl/intitem.hxx> 38*cdf0e10cSrcweir #include <svl/stritem.hxx> 39*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 40*cdf0e10cSrcweir #ifndef _EVENT_HXX //autogen 41*cdf0e10cSrcweir #include <vcl/event.hxx> 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir #ifndef _STATUS_HXX //autogen 44*cdf0e10cSrcweir #include <vcl/status.hxx> 45*cdf0e10cSrcweir #endif 46*cdf0e10cSrcweir #ifndef _MENU_HXX //autogen 47*cdf0e10cSrcweir #include <vcl/menu.hxx> 48*cdf0e10cSrcweir #endif 49*cdf0e10cSrcweir #include "cmdid.h" 50*cdf0e10cSrcweir #include "errhdl.hxx" 51*cdf0e10cSrcweir #include "swmodule.hxx" 52*cdf0e10cSrcweir #include "wrtsh.hxx" 53*cdf0e10cSrcweir #include "IMark.hxx" 54*cdf0e10cSrcweir #include "bookctrl.hxx" 55*cdf0e10cSrcweir #include <map> 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir SFX_IMPL_STATUSBAR_CONTROL( SwBookmarkControl, SfxStringItem ); 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir // class BookmarkPopup_Impl -------------------------------------------------- 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir class BookmarkPopup_Impl : public PopupMenu 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir public: 64*cdf0e10cSrcweir BookmarkPopup_Impl(); 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir sal_uInt16 GetCurId() const { return nCurId; } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir private: 69*cdf0e10cSrcweir sal_uInt16 nCurId; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir virtual void Select(); 72*cdf0e10cSrcweir }; 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir // ----------------------------------------------------------------------- 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir BookmarkPopup_Impl::BookmarkPopup_Impl() : 77*cdf0e10cSrcweir PopupMenu(), 78*cdf0e10cSrcweir nCurId(USHRT_MAX) 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir // ----------------------------------------------------------------------- 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir void BookmarkPopup_Impl::Select() 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir nCurId = GetCurItemId(); 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir // class SvxZoomStatusBarControl ------------------------------------------ 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir SwBookmarkControl::SwBookmarkControl( sal_uInt16 _nSlotId, 92*cdf0e10cSrcweir sal_uInt16 _nId, 93*cdf0e10cSrcweir StatusBar& rStb ) : 94*cdf0e10cSrcweir SfxStatusBarControl( _nSlotId, _nId, rStb ) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir // ----------------------------------------------------------------------- 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir SwBookmarkControl::~SwBookmarkControl() 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir // ----------------------------------------------------------------------- 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir void SwBookmarkControl::StateChanged( 107*cdf0e10cSrcweir sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir if( eState != SFX_ITEM_AVAILABLE || pState->ISA( SfxVoidItem ) ) 110*cdf0e10cSrcweir GetStatusBar().SetItemText( GetId(), String() ); 111*cdf0e10cSrcweir else if ( pState->ISA( SfxStringItem ) ) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir sPageNumber = ((SfxStringItem*)pState)->GetValue(); 114*cdf0e10cSrcweir GetStatusBar().SetItemText( GetId(), sPageNumber ); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir // ----------------------------------------------------------------------- 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir void SwBookmarkControl::Paint( const UserDrawEvent& ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir GetStatusBar().SetItemText( GetId(), sPageNumber ); 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir // ----------------------------------------------------------------------- 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir void SwBookmarkControl::Command( const CommandEvent& rCEvt ) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU && 130*cdf0e10cSrcweir GetStatusBar().GetItemText( GetId() ).Len() ) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir CaptureMouse(); 133*cdf0e10cSrcweir BookmarkPopup_Impl aPop; 134*cdf0e10cSrcweir SwWrtShell* pWrtShell = ::GetActiveWrtShell(); 135*cdf0e10cSrcweir if( pWrtShell && pWrtShell->getIDocumentMarkAccess()->getMarksCount() > 0 ) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir IDocumentMarkAccess* const pMarkAccess = pWrtShell->getIDocumentMarkAccess(); 138*cdf0e10cSrcweir IDocumentMarkAccess::const_iterator_t ppBookmarkStart = pMarkAccess->getBookmarksBegin(); 139*cdf0e10cSrcweir sal_uInt16 nPopupId = 1; 140*cdf0e10cSrcweir ::std::map<sal_Int32, sal_uInt16> aBookmarkIdx; 141*cdf0e10cSrcweir for(IDocumentMarkAccess::const_iterator_t ppBookmark = ppBookmarkStart; 142*cdf0e10cSrcweir ppBookmark != pMarkAccess->getBookmarksEnd(); 143*cdf0e10cSrcweir ppBookmark++) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir if(IDocumentMarkAccess::BOOKMARK == IDocumentMarkAccess::GetType(**ppBookmark)) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir aPop.InsertItem( nPopupId, ppBookmark->get()->GetName() ); 148*cdf0e10cSrcweir aBookmarkIdx[nPopupId] = static_cast<sal_uInt16>(ppBookmark - ppBookmarkStart); 149*cdf0e10cSrcweir nPopupId++; 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel()); 153*cdf0e10cSrcweir sal_uInt16 nCurrId = aPop.GetCurId(); 154*cdf0e10cSrcweir if( nCurrId != USHRT_MAX) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir SfxUInt16Item aBookmark( FN_STAT_BOOKMARK, aBookmarkIdx[nCurrId] ); 157*cdf0e10cSrcweir SfxViewFrame::Current()->GetDispatcher()->Execute( FN_STAT_BOOKMARK, 158*cdf0e10cSrcweir SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD, 159*cdf0e10cSrcweir &aBookmark, 0L ); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir ReleaseMouse(); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir } 165