LCOV - code coverage report
Current view: top level - sw/source/uibase/utlui - bookctrl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 13 49 26.5 %
Date: 2014-11-03 Functions: 8 15 53.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "hintids.hxx"
      21             : 
      22             : #include <svl/intitem.hxx>
      23             : #include <svl/stritem.hxx>
      24             : #include <sfx2/dispatch.hxx>
      25             : #include <vcl/event.hxx>
      26             : #include <vcl/status.hxx>
      27             : #include <vcl/menu.hxx>
      28             : #include "cmdid.h"
      29             : #include "swmodule.hxx"
      30             : #include "wrtsh.hxx"
      31             : #include "IMark.hxx"
      32             : #include "bookctrl.hxx"
      33             : #include <map>
      34             : 
      35         944 : SFX_IMPL_STATUSBAR_CONTROL( SwBookmarkControl, SfxStringItem );
      36             : 
      37           0 : class BookmarkPopup_Impl : public PopupMenu
      38             : {
      39             : public:
      40             :     BookmarkPopup_Impl();
      41             : 
      42           0 :     sal_uInt16          GetCurId() const { return nCurId; }
      43             : 
      44             : private:
      45             :     sal_uInt16          nCurId;
      46             : 
      47             :     virtual void    Select() SAL_OVERRIDE;
      48             : };
      49             : 
      50           0 : BookmarkPopup_Impl::BookmarkPopup_Impl() :
      51             :     PopupMenu(),
      52           0 :     nCurId(USHRT_MAX)
      53             : {
      54           0 : }
      55             : 
      56           0 : void BookmarkPopup_Impl::Select()
      57             : {
      58           0 :     nCurId = GetCurItemId();
      59           0 : }
      60             : 
      61         854 : SwBookmarkControl::SwBookmarkControl( sal_uInt16 _nSlotId,
      62             :                                       sal_uInt16 _nId,
      63             :                                       StatusBar& rStb ) :
      64         854 :     SfxStatusBarControl( _nSlotId, _nId, rStb )
      65             : {
      66         854 : }
      67             : 
      68        1708 : SwBookmarkControl::~SwBookmarkControl()
      69             : {
      70        1708 : }
      71             : 
      72        1242 : void SwBookmarkControl::StateChanged(
      73             :     sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
      74             : {
      75        1242 :     if( eState != SfxItemState::DEFAULT || pState->ISA( SfxVoidItem ) )
      76           0 :         GetStatusBar().SetItemText( GetId(), OUString() );
      77        1242 :     else if ( pState->ISA( SfxStringItem ) )
      78             :     {
      79        1242 :         sPageNumber = ((SfxStringItem*)pState)->GetValue();
      80        1242 :         GetStatusBar().SetItemText( GetId(), sPageNumber );
      81             :     }
      82        1242 : }
      83             : 
      84           0 : void SwBookmarkControl::Paint( const UserDrawEvent&  )
      85             : {
      86           0 :     GetStatusBar().SetItemText( GetId(), sPageNumber );
      87           0 : }
      88             : 
      89           0 : void SwBookmarkControl::Command( const CommandEvent& rCEvt )
      90             : {
      91           0 :     if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU &&
      92           0 :             !GetStatusBar().GetItemText( GetId() ).isEmpty() )
      93             :     {
      94           0 :         CaptureMouse();
      95           0 :         BookmarkPopup_Impl aPop;
      96           0 :         SwWrtShell* pWrtShell = ::GetActiveWrtShell();
      97           0 :         if( pWrtShell && pWrtShell->getIDocumentMarkAccess()->getAllMarksCount() > 0 )
      98             :         {
      99           0 :             IDocumentMarkAccess* const pMarkAccess = pWrtShell->getIDocumentMarkAccess();
     100           0 :             IDocumentMarkAccess::const_iterator_t ppBookmarkStart = pMarkAccess->getBookmarksBegin();
     101           0 :             sal_uInt16 nPopupId = 1;
     102           0 :             ::std::map<sal_Int32, sal_uInt16> aBookmarkIdx;
     103           0 :             for(IDocumentMarkAccess::const_iterator_t ppBookmark = ppBookmarkStart;
     104           0 :                 ppBookmark != pMarkAccess->getBookmarksEnd();
     105             :                 ++ppBookmark)
     106             :             {
     107           0 :                 if(IDocumentMarkAccess::BOOKMARK == IDocumentMarkAccess::GetType(**ppBookmark))
     108             :                 {
     109           0 :                     aPop.InsertItem( nPopupId, ppBookmark->get()->GetName() );
     110           0 :                     aBookmarkIdx[nPopupId] = static_cast<sal_uInt16>(ppBookmark - ppBookmarkStart);
     111           0 :                     nPopupId++;
     112             :                 }
     113             :             }
     114           0 :             aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
     115           0 :             sal_uInt16 nCurrId = aPop.GetCurId();
     116           0 :             if( nCurrId != USHRT_MAX)
     117             :             {
     118           0 :                 SfxUInt16Item aBookmark( FN_STAT_BOOKMARK, aBookmarkIdx[nCurrId] );
     119             :                 SfxViewFrame::Current()->GetDispatcher()->Execute( FN_STAT_BOOKMARK,
     120             :                     SfxCallMode::ASYNCHRON|SfxCallMode::RECORD,
     121           0 :                                         &aBookmark, 0L );
     122           0 :             }
     123             :         }
     124           0 :         ReleaseMouse();
     125             :     }
     126         270 : }
     127             : 
     128             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10