LCOV - code coverage report
Current view: top level - sw/source/core/uibase/utlui - tmplctrl.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 53 0.0 %
Date: 2014-04-14 Functions: 0 13 0.0 %
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           0 : 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           0 : SwTemplateControl::SwTemplateControl( sal_uInt16 _nSlotId,
      62             :                                       sal_uInt16 _nId,
      63             :                                       StatusBar& rStb ) :
      64           0 :     SfxStatusBarControl( _nSlotId, _nId, rStb )
      65             : {
      66           0 : }
      67             : 
      68           0 : SwTemplateControl::~SwTemplateControl()
      69             : {
      70           0 : }
      71             : 
      72           0 : void SwTemplateControl::StateChanged(
      73             :     sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
      74             : {
      75           0 :     if( eState != SFX_ITEM_AVAILABLE || pState->ISA( SfxVoidItem ) )
      76           0 :         GetStatusBar().SetItemText( GetId(), OUString() );
      77           0 :     else if ( pState->ISA( SfxStringItem ) )
      78             :     {
      79           0 :         sTemplate = ((SfxStringItem*)pState)->GetValue();
      80           0 :         GetStatusBar().SetItemText( GetId(), sTemplate );
      81             :     }
      82           0 : }
      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 :                         nCount++;
     114           0 :                         aPop.InsertItem( nCount, pStyle->GetName() );
     115           0 :                         pStyle = pPool->Next();
     116             :                     }
     117             : 
     118           0 :                     aPop.Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
     119           0 :                     sal_uInt16 nCurrId = aPop.GetCurId();
     120           0 :                     if( nCurrId != USHRT_MAX)
     121             :                     {
     122             :                         // looks a bit awkward, but another way is not possible
     123           0 :                         pStyle = pPool->operator[]( nCurrId - 1 );
     124           0 :                         SfxStringItem aStyle( FN_SET_PAGE_STYLE, pStyle->GetName() );
     125           0 :                         pWrtShell->GetView().GetViewFrame()->GetDispatcher()->Execute(
     126             :                                     FN_SET_PAGE_STYLE,
     127             :                                     SFX_CALLMODE_SLOT|SFX_CALLMODE_RECORD,
     128           0 :                                     &aStyle, 0L );
     129             :                     }
     130             :                 }
     131             :             }
     132             :         }
     133           0 :         ReleaseMouse();
     134             :     }
     135           0 : }
     136             : 
     137             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10