1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bookctrl.cxx,v $
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"
37 #define _SVSTDARR_USHORTS
38 #include <svtools/svstdarr.hxx>
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>
46 #ifndef _STATUS_HXX //autogen
47 #include <vcl/status.hxx>
49 #ifndef _MENU_HXX //autogen
50 #include <vcl/menu.hxx>
54 #include "swmodule.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
68 USHORT
GetCurId() const { return nCurId
; }
73 virtual void Select();
76 // -----------------------------------------------------------------------
78 BookmarkPopup_Impl::BookmarkPopup_Impl() :
84 // -----------------------------------------------------------------------
86 void BookmarkPopup_Impl::Select()
88 nCurId
= GetCurItemId();
91 // class SvxZoomStatusBarControl ------------------------------------------
93 SwBookmarkControl::SwBookmarkControl( USHORT _nSlotId
,
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() )
135 BookmarkPopup_Impl aPop
;
136 SwWrtShell
* pWrtShell
= ::GetActiveWrtShell();
138 if( pWrtShell
&& 0 != ( nBookCnt
= pWrtShell
->GetBookmarkCnt() ) )
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
,