1*efeef26fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*efeef26fSAndrew Rist * distributed with this work for additional information 6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance 9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*efeef26fSAndrew Rist * software distributed under the License is distributed on an 15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the 17*efeef26fSAndrew Rist * specific language governing permissions and limitations 18*efeef26fSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*efeef26fSAndrew Rist *************************************************************/ 21*efeef26fSAndrew Rist 22*efeef26fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sw.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "hintids.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #ifndef _SVSTDARR_HXX 30cdf0e10cSrcweir #define _SVSTDARR_USHORTS 31cdf0e10cSrcweir #include <svl/svstdarr.hxx> 32cdf0e10cSrcweir #endif 33cdf0e10cSrcweir #include <svl/intitem.hxx> 34cdf0e10cSrcweir #include <svl/stritem.hxx> 35cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 36cdf0e10cSrcweir #ifndef _EVENT_HXX //autogen 37cdf0e10cSrcweir #include <vcl/event.hxx> 38cdf0e10cSrcweir #endif 39cdf0e10cSrcweir #ifndef _STATUS_HXX //autogen 40cdf0e10cSrcweir #include <vcl/status.hxx> 41cdf0e10cSrcweir #endif 42cdf0e10cSrcweir #ifndef _MENU_HXX //autogen 43cdf0e10cSrcweir #include <vcl/menu.hxx> 44cdf0e10cSrcweir #endif 45cdf0e10cSrcweir #include "cmdid.h" 46cdf0e10cSrcweir #include "errhdl.hxx" 47cdf0e10cSrcweir #include "swmodule.hxx" 48cdf0e10cSrcweir #include "wrtsh.hxx" 49cdf0e10cSrcweir #include "IMark.hxx" 50cdf0e10cSrcweir #include "bookctrl.hxx" 51cdf0e10cSrcweir #include <map> 52cdf0e10cSrcweir 53cdf0e10cSrcweir SFX_IMPL_STATUSBAR_CONTROL( SwBookmarkControl, SfxStringItem ); 54cdf0e10cSrcweir 55cdf0e10cSrcweir // class BookmarkPopup_Impl -------------------------------------------------- 56cdf0e10cSrcweir 57cdf0e10cSrcweir class BookmarkPopup_Impl : public PopupMenu 58cdf0e10cSrcweir { 59cdf0e10cSrcweir public: 60cdf0e10cSrcweir BookmarkPopup_Impl(); 61cdf0e10cSrcweir 62cdf0e10cSrcweir sal_uInt16 GetCurId() const { return nCurId; } 63cdf0e10cSrcweir 64cdf0e10cSrcweir private: 65cdf0e10cSrcweir sal_uInt16 nCurId; 66cdf0e10cSrcweir 67cdf0e10cSrcweir virtual void Select(); 68cdf0e10cSrcweir }; 69cdf0e10cSrcweir 70cdf0e10cSrcweir // ----------------------------------------------------------------------- 71cdf0e10cSrcweir 72cdf0e10cSrcweir BookmarkPopup_Impl::BookmarkPopup_Impl() : 73cdf0e10cSrcweir PopupMenu(), 74cdf0e10cSrcweir nCurId(USHRT_MAX) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir } 77cdf0e10cSrcweir 78cdf0e10cSrcweir // ----------------------------------------------------------------------- 79cdf0e10cSrcweir 80cdf0e10cSrcweir void BookmarkPopup_Impl::Select() 81cdf0e10cSrcweir { 82cdf0e10cSrcweir nCurId = GetCurItemId(); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir // class SvxZoomStatusBarControl ------------------------------------------ 86cdf0e10cSrcweir 87cdf0e10cSrcweir SwBookmarkControl::SwBookmarkControl( sal_uInt16 _nSlotId, 88cdf0e10cSrcweir sal_uInt16 _nId, 89cdf0e10cSrcweir StatusBar& rStb ) : 90cdf0e10cSrcweir SfxStatusBarControl( _nSlotId, _nId, rStb ) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir // ----------------------------------------------------------------------- 95cdf0e10cSrcweir 96cdf0e10cSrcweir SwBookmarkControl::~SwBookmarkControl() 97cdf0e10cSrcweir { 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir // ----------------------------------------------------------------------- 101cdf0e10cSrcweir 102cdf0e10cSrcweir void SwBookmarkControl::StateChanged( 103cdf0e10cSrcweir sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir if( eState != SFX_ITEM_AVAILABLE || pState->ISA( SfxVoidItem ) ) 106cdf0e10cSrcweir GetStatusBar().SetItemText( GetId(), String() ); 107cdf0e10cSrcweir else if ( pState->ISA( SfxStringItem ) ) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir sPageNumber = ((SfxStringItem*)pState)->GetValue(); 110cdf0e10cSrcweir GetStatusBar().SetItemText( GetId(), sPageNumber ); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir // ----------------------------------------------------------------------- 115cdf0e10cSrcweir 116cdf0e10cSrcweir void SwBookmarkControl::Paint( const UserDrawEvent& ) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir GetStatusBar().SetItemText( GetId(), sPageNumber ); 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir // ----------------------------------------------------------------------- 122cdf0e10cSrcweir 123cdf0e10cSrcweir void SwBookmarkControl::Command( const CommandEvent& rCEvt ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU && 126cdf0e10cSrcweir GetStatusBar().GetItemText( GetId() ).Len() ) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir CaptureMouse(); 129cdf0e10cSrcweir BookmarkPopup_Impl aPop; 130cdf0e10cSrcweir SwWrtShell* pWrtShell = ::GetActiveWrtShell(); 131cdf0e10cSrcweir if( pWrtShell && pWrtShell->getIDocumentMarkAccess()->getMarksCount() > 0 ) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir IDocumentMarkAccess* const pMarkAccess = pWrtShell->getIDocumentMarkAccess(); 134cdf0e10cSrcweir IDocumentMarkAccess::const_iterator_t ppBookmarkStart = pMarkAccess->getBookmarksBegin(); 135cdf0e10cSrcweir sal_uInt16 nPopupId = 1; 136cdf0e10cSrcweir ::std::map<sal_Int32, sal_uInt16> aBookmarkIdx; 137cdf0e10cSrcweir for(IDocumentMarkAccess::const_iterator_t ppBookmark = ppBookmarkStart; 138cdf0e10cSrcweir ppBookmark != pMarkAccess->getBookmarksEnd(); 139cdf0e10cSrcweir ppBookmark++) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir if(IDocumentMarkAccess::BOOKMARK == IDocumentMarkAccess::GetType(**ppBookmark)) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir aPop.InsertItem( nPopupId, ppBookmark->get()->GetName() ); 144cdf0e10cSrcweir aBookmarkIdx[nPopupId] = static_cast<sal_uInt16>(ppBookmark - ppBookmarkStart); 145cdf0e10cSrcweir nPopupId++; 146cdf0e10cSrcweir } 147cdf0e10cSrcweir } 148cdf0e10cSrcweir aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel()); 149cdf0e10cSrcweir sal_uInt16 nCurrId = aPop.GetCurId(); 150cdf0e10cSrcweir if( nCurrId != USHRT_MAX) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir SfxUInt16Item aBookmark( FN_STAT_BOOKMARK, aBookmarkIdx[nCurrId] ); 153cdf0e10cSrcweir SfxViewFrame::Current()->GetDispatcher()->Execute( FN_STAT_BOOKMARK, 154cdf0e10cSrcweir SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD, 155cdf0e10cSrcweir &aBookmark, 0L ); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir } 158cdf0e10cSrcweir ReleaseMouse(); 159cdf0e10cSrcweir } 160cdf0e10cSrcweir } 161