LCOV - code coverage report
Current view: top level - sw/source/uibase/utlui - tmplctrl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 13 52 25.0 %
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 <svl/style.hxx>
      21             : #include <vcl/menu.hxx>
      22             : #include <svl/stritem.hxx>
      23             : #include <sfx2/dispatch.hxx>
      24             : #include <vcl/status.hxx>
      25             : 
      26             : #include "wrtsh.hxx"
      27             : #include "view.hxx"
      28             : #include "swmodule.hxx"
      29             : #include "cmdid.h"
      30             : #include "docsh.hxx"
      31             : #include "tmplctrl.hxx"
      32             : 
      33         944 : SFX_IMPL_STATUSBAR_CONTROL( SwTemplateControl, SfxStringItem );
      34             : 
      35           0 : class SwTemplatePopup_Impl : public PopupMenu
      36             : {
      37             : public:
      38             :     SwTemplatePopup_Impl();
      39             : 
      40           0 :     sal_uInt16          GetCurId() const { return nCurId; }
      41             : 
      42             : private:
      43             :     sal_uInt16          nCurId;
      44             : 
      45             :     virtual void    Select() SAL_OVERRIDE;
      46             : };
      47             : 
      48           0 : SwTemplatePopup_Impl::SwTemplatePopup_Impl() :
      49             :     PopupMenu(),
      50           0 :     nCurId(USHRT_MAX)
      51             : {
      52           0 : }
      53             : 
      54           0 : void SwTemplatePopup_Impl::Select()
      55             : {
      56           0 :     nCurId = GetCurItemId();
      57           0 : }
      58             : 
      59             : // class SvxZoomStatusBarControl
      60             : 
      61         854 : SwTemplateControl::SwTemplateControl( sal_uInt16 _nSlotId,
      62             :                                       sal_uInt16 _nId,
      63             :                                       StatusBar& rStb ) :
      64         854 :     SfxStatusBarControl( _nSlotId, _nId, rStb )
      65             : {
      66         854 : }
      67             : 
      68        1708 : SwTemplateControl::~SwTemplateControl()
      69             : {
      70        1708 : }
      71             : 
      72        1039 : void SwTemplateControl::StateChanged(
      73             :     sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
      74             : {
      75        1039 :     if( eState != SfxItemState::DEFAULT || pState->ISA( SfxVoidItem ) )
      76           0 :         GetStatusBar().SetItemText( GetId(), OUString() );
      77        1039 :     else if ( pState->ISA( SfxStringItem ) )
      78             :     {
      79        1039 :         sTemplate = ((SfxStringItem*)pState)->GetValue();
      80        1039 :         GetStatusBar().SetItemText( GetId(), sTemplate );
      81             :     }
      82        1039 : }
      83             : 
      84           0 : void SwTemplateControl::Paint( const UserDrawEvent&  )
      85             : {
      86           0 :     GetStatusBar().SetItemText( GetId(), sTemplate );
      87           0 : }
      88             : 
      89           0 : void SwTemplateControl::Command( const CommandEvent& rCEvt )
      90             : {
      91           0 :     if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU &&
      92           0 :             !GetStatusBar().GetItemText( GetId() ).isEmpty() )
      93             :     {
      94           0 :         CaptureMouse();
      95           0 :         SwTemplatePopup_Impl aPop;
      96             :         {
      97           0 :             SwView* pView = ::GetActiveView();
      98             :             SwWrtShell* pWrtShell;
      99           0 :             if( pView && 0 != (pWrtShell = pView->GetWrtShellPtr()) &&
     100           0 :                 !pWrtShell->SwCrsrShell::HasSelection()&&
     101           0 :                 !pWrtShell->IsSelFrmMode() &&
     102           0 :                 !pWrtShell->IsObjSelected())
     103             :             {
     104           0 :                 SfxStyleSheetBasePool* pPool = pView->GetDocShell()->
     105           0 :                                                             GetStyleSheetPool();
     106           0 :                 pPool->SetSearchMask(SFX_STYLE_FAMILY_PAGE, SFXSTYLEBIT_ALL);
     107           0 :                 if( pPool->Count() > 1 )
     108             :                 {
     109           0 :                     sal_uInt16 nCount = 0;
     110           0 :                     SfxStyleSheetBase* pStyle = pPool->First();
     111           0 :                     while( pStyle )
     112             :                     {
     113           0 :                         aPop.InsertItem( ++nCount, pStyle->GetName() );
     114           0 :                         pStyle = pPool->Next();
     115             :                     }
     116             : 
     117           0 :                     aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
     118           0 :                     const sal_uInt16 nCurrId = aPop.GetCurId();
     119           0 :                     if( nCurrId != USHRT_MAX)
     120             :                     {
     121             :                         // looks a bit awkward, but another way is not possible
     122           0 :                         pStyle = pPool->operator[]( nCurrId - 1 );
     123           0 :                         SfxStringItem aStyle( FN_SET_PAGE_STYLE, pStyle->GetName() );
     124           0 :                         pWrtShell->GetView().GetViewFrame()->GetDispatcher()->Execute(
     125             :                                     FN_SET_PAGE_STYLE,
     126             :                                     SfxCallMode::SLOT|SfxCallMode::RECORD,
     127           0 :                                     &aStyle, 0L );
     128             :                     }
     129             :                 }
     130             :             }
     131             :         }
     132           0 :         ReleaseMouse();
     133             :     }
     134         270 : }
     135             : 
     136             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10