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

Generated by: LCOV version 1.10