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