update ooo310-m15
[ooovba.git] / sw / source / ui / utlui / bookctrl.cxx
blob79cd8900bd346f3948c8b944b6188714d72bc7e8
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 "bookmrk.hxx"
57 #include "bookctrl.hxx"
59 SFX_IMPL_STATUSBAR_CONTROL( SwBookmarkControl, SfxStringItem );
61 // class BookmarkPopup_Impl --------------------------------------------------
63 class BookmarkPopup_Impl : public PopupMenu
65 public:
66 BookmarkPopup_Impl();
68 USHORT GetCurId() const { return nCurId; }
70 private:
71 USHORT nCurId;
73 virtual void Select();
76 // -----------------------------------------------------------------------
78 BookmarkPopup_Impl::BookmarkPopup_Impl() :
79 PopupMenu(),
80 nCurId(USHRT_MAX)
84 // -----------------------------------------------------------------------
86 void BookmarkPopup_Impl::Select()
88 nCurId = GetCurItemId();
91 // class SvxZoomStatusBarControl ------------------------------------------
93 SwBookmarkControl::SwBookmarkControl( USHORT _nSlotId,
94 USHORT _nId,
95 StatusBar& rStb ) :
96 SfxStatusBarControl( _nSlotId, _nId, rStb )
100 // -----------------------------------------------------------------------
102 SwBookmarkControl::~SwBookmarkControl()
106 // -----------------------------------------------------------------------
108 void SwBookmarkControl::StateChanged(
109 USHORT /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
111 if( eState != SFX_ITEM_AVAILABLE || pState->ISA( SfxVoidItem ) )
112 GetStatusBar().SetItemText( GetId(), String() );
113 else if ( pState->ISA( SfxStringItem ) )
115 sPageNumber = ((SfxStringItem*)pState)->GetValue();
116 GetStatusBar().SetItemText( GetId(), sPageNumber );
120 // -----------------------------------------------------------------------
122 void SwBookmarkControl::Paint( const UserDrawEvent& )
124 GetStatusBar().SetItemText( GetId(), sPageNumber );
127 // -----------------------------------------------------------------------
129 void SwBookmarkControl::Command( const CommandEvent& rCEvt )
131 if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU &&
132 GetStatusBar().GetItemText( GetId() ).Len() )
134 CaptureMouse();
135 BookmarkPopup_Impl aPop;
136 SwWrtShell* pWrtShell = ::GetActiveWrtShell();
137 USHORT nBookCnt;
138 if( pWrtShell && 0 != ( nBookCnt = pWrtShell->GetBookmarkCnt() ) )
140 SvUShorts aBookArr;
141 for( USHORT nCount = 0; nCount < nBookCnt; ++nCount )
143 SwBookmark& rBkmk = pWrtShell->GetBookmark( nCount );
144 if( rBkmk.IsBookMark() )
146 aBookArr.Insert( nCount, aBookArr.Count() );
147 aPop.InsertItem( aBookArr.Count(), rBkmk.GetName() );
150 aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
151 USHORT nCurrId = aPop.GetCurId();
152 if( nCurrId != USHRT_MAX)
154 SfxUInt16Item aBookmark( FN_STAT_BOOKMARK, aBookArr[nCurrId-1] );
155 SfxViewFrame::Current()->GetDispatcher()->Execute( FN_STAT_BOOKMARK,
156 SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD,
157 &aBookmark, 0L );
160 ReleaseMouse();