LCOV - code coverage report
Current view: top level - svx/source/tbxctrls - bulletsnumbering.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 28 101 27.7 %
Date: 2015-06-13 12:38:46 Functions: 8 17 47.1 %
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 <com/sun/star/text/DefaultNumberingProvider.hpp>
      21             : #include <com/sun/star/text/XNumberingFormatter.hpp>
      22             : 
      23             : #include <comphelper/processfactory.hxx>
      24             : #include <i18nlangtag/mslangid.hxx>
      25             : #include <sfx2/imagemgr.hxx>
      26             : #include <svtools/popupwindowcontroller.hxx>
      27             : #include <svtools/toolbarmenu.hxx>
      28             : #include <svx/dialogs.hrc>
      29             : #include <svx/dialmgr.hxx>
      30             : #include <svx/numvset.hxx>
      31             : #include <vcl/toolbox.hxx>
      32             : #include <vcl/settings.hxx>
      33             : 
      34             : #define NUM_PAGETYPE_BULLET         0
      35             : #define NUM_PAGETYPE_SINGLENUM      1
      36             : 
      37             : class NumberingToolBoxControl;
      38             : 
      39             : class NumberingPopup : public svtools::ToolbarMenu
      40             : {
      41             :     bool mbBulletItem;
      42             :     NumberingToolBoxControl& mrController;
      43             :     VclPtr<SvxNumValueSet> mpValueSet;
      44             :     DECL_LINK( VSSelectHdl, void * );
      45             : 
      46             : public:
      47             :     NumberingPopup( NumberingToolBoxControl& rController,
      48             :                     const css::uno::Reference< css::frame::XFrame >& rFrame,
      49             :                     vcl::Window* pParent, bool bBulletItem );
      50             :     virtual ~NumberingPopup();
      51             :     virtual void dispose() SAL_OVERRIDE;
      52             : 
      53             :     virtual void statusChanged( const css::frame::FeatureStateEvent& rEvent )
      54             :         throw ( css::uno::RuntimeException ) SAL_OVERRIDE;
      55             : };
      56             : 
      57        2726 : class NumberingToolBoxControl : public svt::PopupWindowController
      58             : {
      59             :     bool mbBulletItem;
      60             : 
      61             : public:
      62             :     explicit NumberingToolBoxControl( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
      63             :     virtual VclPtr<vcl::Window> createPopupWindow( vcl::Window* pParent ) SAL_OVERRIDE;
      64             :     bool IsInImpressDraw();
      65             : 
      66             :     // XStatusListener
      67             :     virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent )
      68             :         throw ( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      69             : 
      70             :     // XInitialization
      71             :     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
      72             :         throw ( css::uno::Exception, css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      73             : 
      74             :     // XServiceInfo
      75             :     virtual OUString SAL_CALL getImplementationName()
      76             :         throw ( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      77             :     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
      78             :         throw ( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      79             : 
      80             :     using svt::ToolboxController::createPopupWindow;
      81             : };
      82             : 
      83             : //class NumberingPopup
      84           0 : NumberingPopup::NumberingPopup( NumberingToolBoxControl& rController,
      85             :                                 const css::uno::Reference< css::frame::XFrame >& rFrame,
      86             :                                 vcl::Window* pParent, bool bBulletItem ) :
      87             :     ToolbarMenu( rFrame, pParent, WB_STDPOPUP ),
      88             :     mbBulletItem( bBulletItem ),
      89           0 :     mrController( rController )
      90             : {
      91           0 :     WinBits nBits = WB_TABSTOP | WB_MENUSTYLEVALUESET | WB_FLATVALUESET | WB_NO_DIRECTSELECT;
      92           0 :     mpValueSet = VclPtr<SvxNumValueSet>::Create( this, nBits );
      93           0 :     mpValueSet->init( mbBulletItem ? NUM_PAGETYPE_BULLET : NUM_PAGETYPE_SINGLENUM );
      94             : 
      95           0 :     if ( !mbBulletItem )
      96             :     {
      97           0 :         css::uno::Reference< css::text::XDefaultNumberingProvider > xDefNum = css::text::DefaultNumberingProvider::create( comphelper::getProcessComponentContext() );
      98           0 :         if ( xDefNum.is() )
      99             :         {
     100           0 :             css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > aNumberings;
     101           0 :             css::lang::Locale aLocale = GetSettings().GetLanguageTag().getLocale();
     102             :             try
     103             :             {
     104           0 :                 aNumberings = xDefNum->getDefaultContinuousNumberingLevels( aLocale );
     105             :             }
     106           0 :             catch( css::uno::Exception& )
     107             :             {}
     108             : 
     109           0 :             css::uno::Reference< css::text::XNumberingFormatter > xFormat( xDefNum, css::uno::UNO_QUERY );
     110           0 :             mpValueSet->SetNumberingSettings( aNumberings, xFormat, aLocale );
     111           0 :         }
     112             :     }
     113             : 
     114           0 :     Size aItemSize( LogicToPixel( Size( 30, 42 ), MAP_APPFONT ) );
     115           0 :     mpValueSet->SetExtraSpacing( 2 );
     116           0 :     mpValueSet->SetOutputSizePixel( mpValueSet->CalcWindowSizePixel( aItemSize ) );
     117           0 :     mpValueSet->SetColor( GetSettings().GetStyleSettings().GetFieldColor() );
     118             : 
     119           0 :     appendEntry( 0, mpValueSet );
     120           0 :     appendSeparator();
     121             : 
     122           0 :     if ( mbBulletItem )
     123           0 :         appendEntry( 1, SVX_RESSTR( RID_SVXSTR_MOREBULLETS ), ::GetImage( rFrame, ".uno:OutlineBullet", false ) );
     124             :     else
     125           0 :         appendEntry( 1, SVX_RESSTR( RID_SVXSTR_MORENUMBERING ), ::GetImage( rFrame, ".uno:OutlineBullet", false ) );
     126             : 
     127           0 :     SetOutputSizePixel( getMenuSize() );
     128           0 :     Link<> aLink =  LINK( this, NumberingPopup, VSSelectHdl );
     129           0 :     mpValueSet->SetSelectHdl( aLink );
     130           0 :     SetSelectHdl( aLink );
     131             : 
     132           0 :     if ( mbBulletItem )
     133           0 :         AddStatusListener( ".uno:CurrentBulletListType" );
     134             :     else
     135           0 :         AddStatusListener( ".uno:CurrentNumListType" );
     136           0 : }
     137             : 
     138           0 : NumberingPopup::~NumberingPopup()
     139             : {
     140           0 :     disposeOnce();
     141           0 : }
     142             : 
     143           0 : void NumberingPopup::dispose()
     144             : {
     145           0 :     mpValueSet.clear();
     146           0 :     ToolbarMenu::dispose();
     147           0 : }
     148             : 
     149           0 : void NumberingPopup::statusChanged( const css::frame::FeatureStateEvent& rEvent )
     150             :     throw ( css::uno::RuntimeException )
     151             : {
     152           0 :     mpValueSet->SetNoSelection();
     153             : 
     154             :     sal_Int32 nSelItem;
     155           0 :     if ( rEvent.State >>= nSelItem )
     156           0 :         mpValueSet->SelectItem( nSelItem );
     157           0 : }
     158             : 
     159           0 : IMPL_LINK( NumberingPopup, VSSelectHdl, void *, pControl )
     160             : {
     161           0 :     if ( IsInPopupMode() )
     162           0 :         EndPopupMode();
     163             : 
     164           0 :     if ( pControl == mpValueSet )
     165             :     {
     166           0 :         sal_uInt16 nSelItem = mpValueSet->GetSelectItemId();
     167           0 :         css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 );
     168           0 :         if ( mbBulletItem )
     169             :         {
     170           0 :             aArgs[0].Name = "SetBullet";
     171           0 :             aArgs[0].Value <<= sal_uInt16( nSelItem );
     172           0 :             mrController.dispatchCommand( ".uno:SetBullet", aArgs );
     173             :         }
     174             :         else
     175             :         {
     176           0 :             aArgs[0].Name = "SetNumber";
     177           0 :             aArgs[0].Value <<= sal_uInt16( nSelItem );
     178           0 :             mrController.dispatchCommand( ".uno:SetNumber", aArgs );
     179           0 :         }
     180             :     }
     181           0 :     else if ( getSelectedEntryId() == 1 )
     182             :     {
     183           0 :         OUString aPageName;
     184           0 :         if ( mrController.IsInImpressDraw() )
     185           0 :             aPageName = "customize";
     186             :         else
     187             :             // Writer variants
     188           0 :             aPageName = "options";
     189             : 
     190           0 :         css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 );
     191           0 :         aArgs[0].Name = "Page";
     192           0 :         aArgs[0].Value <<= aPageName;
     193           0 :         mrController.dispatchCommand( ".uno:OutlineBullet", aArgs );
     194             :     }
     195             : 
     196           0 :     return 0;
     197             : }
     198             : 
     199             : 
     200             : //class NumberingToolBoxControl
     201        1363 : NumberingToolBoxControl::NumberingToolBoxControl( const css::uno::Reference< css::uno::XComponentContext >& rxContext ):
     202             :     svt::PopupWindowController( rxContext, css::uno::Reference< css::frame::XFrame >(), OUString() ),
     203        1363 :     mbBulletItem( false )
     204             : {
     205        1363 : }
     206             : 
     207           0 : VclPtr<vcl::Window> NumberingToolBoxControl::createPopupWindow( vcl::Window* pParent )
     208             : {
     209           0 :     return VclPtr<NumberingPopup>::Create( *this, m_xFrame, pParent, mbBulletItem );
     210             : }
     211             : 
     212           0 : bool NumberingToolBoxControl::IsInImpressDraw()
     213             : {
     214           0 :     return ( m_sModuleName == "com.sun.star.presentation.PresentationDocument" ||
     215           0 :              m_sModuleName == "com.sun.star.drawing.DrawingDocument" );
     216             : }
     217             : 
     218        2392 : void SAL_CALL NumberingToolBoxControl::statusChanged( const css::frame::FeatureStateEvent& rEvent )
     219             :     throw ( css::uno::RuntimeException, std::exception )
     220             : {
     221        2392 :     ToolBox* pToolBox = 0;
     222        2392 :     sal_uInt16 nId = 0;
     223        2392 :     if ( getToolboxId( nId, &pToolBox ) )
     224             :     {
     225        2392 :         pToolBox->EnableItem( nId, rEvent.IsEnabled );
     226             :         bool bChecked;
     227        2392 :         if ( rEvent.State >>= bChecked )
     228        2392 :             pToolBox->CheckItem( nId, bChecked );
     229             :     }
     230        2392 : }
     231             : 
     232        2038 : void SAL_CALL NumberingToolBoxControl::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
     233             :     throw ( css::uno::Exception, css::uno::RuntimeException, std::exception )
     234             : {
     235        2038 :     svt::PopupWindowController::initialize( aArguments );
     236             : 
     237        2038 :     ToolBox* pToolBox = 0;
     238        2038 :     sal_uInt16 nId = 0;
     239        2038 :     if ( getToolboxId( nId, &pToolBox ) )
     240        2038 :         pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ToolBoxItemBits::DROPDOWN );
     241             : 
     242        2038 :     mbBulletItem = m_aCommandURL == ".uno:DefaultBullet";
     243        2038 : }
     244             : 
     245           1 : OUString SAL_CALL NumberingToolBoxControl::getImplementationName()
     246             :     throw ( css::uno::RuntimeException, std::exception )
     247             : {
     248           1 :     return OUString( "com.sun.star.comp.svx.NumberingToolBoxControl" );
     249             : }
     250             : 
     251           1 : css::uno::Sequence< OUString > SAL_CALL NumberingToolBoxControl::getSupportedServiceNames()
     252             :     throw ( css::uno::RuntimeException, std::exception )
     253             : {
     254           1 :     css::uno::Sequence< OUString > aRet( 1 );
     255           1 :     aRet[0] = "com.sun.star.frame.ToolbarController";
     256           1 :     return aRet;
     257             : }
     258             : 
     259             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     260        1363 : com_sun_star_comp_svx_NumberingToolBoxControl_get_implementation(
     261             :     css::uno::XComponentContext *rxContext,
     262             :     css::uno::Sequence<css::uno::Any> const & )
     263             : {
     264        1363 :     return cppu::acquire( new NumberingToolBoxControl( rxContext ) );
     265             : }
     266             : 
     267             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11