LCOV - code coverage report
Current view: top level - framework/source/uielement - togglebuttontoolbarcontroller.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 122 0.8 %
Date: 2015-06-13 12:38:46 Functions: 2 11 18.2 %
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 "uielement/togglebuttontoolbarcontroller.hxx"
      21             : 
      22             : #include <framework/addonsoptions.hxx>
      23             : 
      24             : #include <com/sun/star/util/XURLTransformer.hpp>
      25             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      26             : #include <com/sun/star/beans/PropertyValue.hpp>
      27             : #include <com/sun/star/frame/XControlNotificationListener.hpp>
      28             : #include <com/sun/star/util/XMacroExpander.hpp>
      29             : #include <com/sun/star/uno/XComponentContext.hpp>
      30             : #include <com/sun/star/beans/XPropertySet.hpp>
      31             : 
      32             : #include <rtl/uri.hxx>
      33             : #include <osl/mutex.hxx>
      34             : #include <comphelper/processfactory.hxx>
      35             : #include <unotools/ucbstreamhelper.hxx>
      36             : #include <vcl/svapp.hxx>
      37             : #include <vcl/mnemonic.hxx>
      38             : #include <vcl/window.hxx>
      39             : #include <vcl/graph.hxx>
      40             : #include <vcl/bitmap.hxx>
      41             : #include <vcl/graphicfilter.hxx>
      42             : #include <vcl/toolbox.hxx>
      43             : #include <svtools/miscopt.hxx>
      44             : 
      45             : using namespace ::com::sun::star;
      46             : using namespace ::com::sun::star::awt;
      47             : using namespace ::com::sun::star::uno;
      48             : using namespace ::com::sun::star::beans;
      49             : using namespace ::com::sun::star::lang;
      50             : using namespace ::com::sun::star::frame;
      51             : using namespace ::com::sun::star::util;
      52             : 
      53             : namespace framework
      54             : {
      55             : 
      56           0 : ToggleButtonToolbarController::ToggleButtonToolbarController(
      57             :     const Reference< XComponentContext >&    rxContext,
      58             :     const Reference< XFrame >&               rFrame,
      59             :     ToolBox*                                 pToolbar,
      60             :     sal_uInt16                                   nID,
      61             :     Style                                    eStyle,
      62             :     const OUString&                          aCommand ) :
      63             :     ComplexToolbarController( rxContext, rFrame, pToolbar, nID, aCommand ),
      64           0 :     m_eStyle( eStyle )
      65             : {
      66           0 :     if ( eStyle == STYLE_DROPDOWNBUTTON )
      67           0 :         m_pToolbar->SetItemBits( m_nID, ToolBoxItemBits::DROPDOWNONLY | m_pToolbar->GetItemBits( m_nID ) );
      68           0 :     else if ( eStyle == STYLE_TOGGLE_DROPDOWNBUTTON )
      69           0 :         m_pToolbar->SetItemBits( m_nID, ToolBoxItemBits::DROPDOWN | m_pToolbar->GetItemBits( m_nID ) );
      70           0 : }
      71             : 
      72           0 : ToggleButtonToolbarController::~ToggleButtonToolbarController()
      73             : {
      74           0 : }
      75             : 
      76           0 : void SAL_CALL ToggleButtonToolbarController::dispose()
      77             : throw ( RuntimeException, std::exception )
      78             : {
      79           0 :     SolarMutexGuard aSolarMutexGuard;
      80           0 :     ComplexToolbarController::dispose();
      81           0 : }
      82             : 
      83           0 : Sequence<PropertyValue> ToggleButtonToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
      84             : {
      85           0 :     Sequence<PropertyValue> aArgs( 2 );
      86             : 
      87             :     // Add key modifier to argument list
      88           0 :     aArgs[0].Name = "KeyModifier";
      89           0 :     aArgs[0].Value <<= KeyModifier;
      90           0 :     aArgs[1].Name = "Text";
      91           0 :     aArgs[1].Value <<= m_aCurrentSelection;
      92           0 :     return aArgs;
      93             : }
      94             : 
      95           0 : uno::Reference< awt::XWindow > SAL_CALL ToggleButtonToolbarController::createPopupWindow()
      96             : throw (::com::sun::star::uno::RuntimeException, std::exception)
      97             : {
      98           0 :     uno::Reference< awt::XWindow > xWindow;
      99             : 
     100           0 :     SolarMutexGuard aSolarMutexGuard;
     101           0 :     if (( m_eStyle == STYLE_DROPDOWNBUTTON ) ||
     102           0 :         ( m_eStyle == STYLE_TOGGLE_DROPDOWNBUTTON ))
     103             :     {
     104             :         // create popup menu
     105           0 :         ::PopupMenu aPopup;
     106           0 :         const sal_uInt32 nCount = m_aDropdownMenuList.size();
     107           0 :         for ( sal_uInt32 i = 0; i < nCount; i++ )
     108             :         {
     109           0 :             OUString aLabel( m_aDropdownMenuList[i] );
     110           0 :             aPopup.InsertItem( sal_uInt16( i+1 ), aLabel );
     111           0 :             if ( aLabel == m_aCurrentSelection )
     112           0 :                 aPopup.CheckItem( sal_uInt16( i+1 ), true );
     113             :             else
     114           0 :                 aPopup.CheckItem( sal_uInt16( i+1 ), false );
     115           0 :         }
     116             : 
     117           0 :         m_pToolbar->SetItemDown( m_nID, true );
     118           0 :         aPopup.SetSelectHdl( LINK( this, ToggleButtonToolbarController, MenuSelectHdl ));
     119           0 :         aPopup.Execute( m_pToolbar, m_pToolbar->GetItemRect( m_nID ));
     120           0 :         m_pToolbar->SetItemDown( m_nID, false );
     121             :     }
     122             : 
     123           0 :     return xWindow;
     124             : }
     125             : 
     126           0 : void ToggleButtonToolbarController::executeControlCommand( const ::com::sun::star::frame::ControlCommand& rControlCommand )
     127             : {
     128           0 :     SolarMutexGuard aSolarMutexGuard;
     129             : 
     130           0 :     if (( m_eStyle == STYLE_DROPDOWNBUTTON ) ||
     131           0 :         ( m_eStyle == STYLE_TOGGLE_DROPDOWNBUTTON ))
     132             :     {
     133           0 :         if ( rControlCommand.Command == "SetList" )
     134             :         {
     135           0 :             for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     136             :             {
     137           0 :                 if ( rControlCommand.Arguments[i].Name == "List" )
     138             :                 {
     139           0 :                     Sequence< OUString > aList;
     140           0 :                     m_aDropdownMenuList.clear();
     141             : 
     142           0 :                     rControlCommand.Arguments[i].Value >>= aList;
     143           0 :                     for ( sal_Int32 j = 0; j < aList.getLength(); j++ )
     144           0 :                         m_aDropdownMenuList.push_back( aList[j] );
     145             : 
     146             :                     // send notification
     147           0 :                     uno::Sequence< beans::NamedValue > aInfo( 1 );
     148           0 :                     aInfo[0].Name  = "List";
     149           0 :                     aInfo[0].Value <<= aList;
     150             :                     addNotifyInfo( OUString( "ListChanged" ),
     151             :                                 getDispatchFromCommand( m_aCommandURL ),
     152           0 :                                 aInfo );
     153             : 
     154           0 :                     break;
     155             :                 }
     156             :             }
     157             :         }
     158           0 :         else if ( rControlCommand.Command == "CheckItemPos" )
     159             :         {
     160           0 :             for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     161             :             {
     162           0 :                 if ( rControlCommand.Arguments[i].Name == "Pos" )
     163             :                 {
     164           0 :                     sal_Int32 nPos( -1 );
     165             : 
     166           0 :                     rControlCommand.Arguments[i].Value >>= nPos;
     167           0 :                     if ( nPos >= 0 &&
     168           0 :                          ( sal::static_int_cast< sal_uInt32 >(nPos)
     169           0 :                            < m_aDropdownMenuList.size() ) )
     170             :                     {
     171           0 :                         m_aCurrentSelection = m_aDropdownMenuList[nPos];
     172             : 
     173             :                         // send notification
     174           0 :                         uno::Sequence< beans::NamedValue > aInfo( 1 );
     175           0 :                         aInfo[0].Name  = "ItemChecked";
     176           0 :                         aInfo[0].Value <<= nPos;
     177             :                         addNotifyInfo( OUString( "Pos" ),
     178             :                                     getDispatchFromCommand( m_aCommandURL ),
     179           0 :                                     aInfo );
     180             :                     }
     181           0 :                     break;
     182             :                 }
     183             :             }
     184             :         }
     185           0 :         else if ( rControlCommand.Command == "AddEntry" )
     186             :         {
     187           0 :             OUString   aText;
     188           0 :             for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     189             :             {
     190           0 :                 if ( rControlCommand.Arguments[i].Name == "Text" )
     191             :                 {
     192           0 :                     if ( rControlCommand.Arguments[i].Value >>= aText )
     193           0 :                         m_aDropdownMenuList.push_back( aText );
     194           0 :                     break;
     195             :                 }
     196           0 :             }
     197             :         }
     198           0 :         else if ( rControlCommand.Command == "InsertEntry" )
     199             :         {
     200           0 :             sal_Int32      nPos( COMBOBOX_APPEND );
     201           0 :             sal_Int32      nSize = sal_Int32( m_aDropdownMenuList.size() );
     202           0 :             OUString  aText;
     203           0 :             for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     204             :             {
     205           0 :                 if ( rControlCommand.Arguments[i].Name == "Pos" )
     206             :                 {
     207           0 :                     sal_Int32 nTmpPos = 0;
     208           0 :                     if ( rControlCommand.Arguments[i].Value >>= nTmpPos )
     209             :                     {
     210           0 :                         if (( nTmpPos >= 0 ) && ( nTmpPos < sal_Int32( nSize )))
     211           0 :                             nPos = nTmpPos;
     212             :                     }
     213             :                 }
     214           0 :                 else if ( rControlCommand.Arguments[i].Name == "Text" )
     215           0 :                     rControlCommand.Arguments[i].Value >>= aText;
     216             :             }
     217             : 
     218           0 :             std::vector< OUString >::iterator aIter = m_aDropdownMenuList.begin();
     219           0 :             aIter += nPos;
     220           0 :             m_aDropdownMenuList.insert( aIter, aText );
     221             :         }
     222           0 :         else if ( rControlCommand.Command == "RemoveEntryPos" )
     223             :         {
     224           0 :             for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     225             :             {
     226           0 :                 if ( rControlCommand.Arguments[i].Name == "Pos" )
     227             :                 {
     228           0 :                     sal_Int32 nPos( -1 );
     229           0 :                     if ( rControlCommand.Arguments[i].Value >>= nPos )
     230             :                     {
     231           0 :                         if ( nPos < sal_Int32( m_aDropdownMenuList.size() ))
     232             :                         {
     233           0 :                             m_aDropdownMenuList.erase(m_aDropdownMenuList.begin() + nPos);
     234             :                         }
     235             :                     }
     236           0 :                     break;
     237             :                 }
     238             :             }
     239             :         }
     240           0 :         else if ( rControlCommand.Command == "RemoveEntryText" )
     241             :         {
     242           0 :             for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     243             :             {
     244           0 :                 if ( rControlCommand.Arguments[i].Name == "Text" )
     245             :                 {
     246           0 :                     OUString aText;
     247           0 :                     if ( rControlCommand.Arguments[i].Value >>= aText )
     248             :                     {
     249           0 :                         sal_Int32 nSize = sal_Int32( m_aDropdownMenuList.size() );
     250           0 :                         for ( sal_Int32 j = 0; j < nSize; j++ )
     251             :                         {
     252           0 :                             if ( m_aDropdownMenuList[j] == aText )
     253             :                             {
     254           0 :                                 m_aDropdownMenuList.erase(m_aDropdownMenuList.begin() + j);
     255           0 :                                 break;
     256             :                             }
     257             :                         }
     258             :                     }
     259           0 :                     break;
     260             :                 }
     261             :             }
     262             :         }
     263           0 :     }
     264           0 : }
     265             : 
     266           0 : IMPL_LINK( ToggleButtonToolbarController, MenuSelectHdl, Menu *, pMenu )
     267             : {
     268           0 :     SolarMutexGuard aGuard;
     269             : 
     270           0 :     sal_uInt16 nItemId = pMenu->GetCurItemId();
     271           0 :     if ( nItemId > 0 && nItemId <= m_aDropdownMenuList.size() )
     272             :     {
     273           0 :         m_aCurrentSelection = m_aDropdownMenuList[nItemId-1];
     274             : 
     275           0 :         execute( 0 );
     276             :     }
     277           0 :     return 0;
     278             : }
     279             : 
     280         648 : } // namespace
     281             : 
     282             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11