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