LCOV - code coverage report
Current view: top level - framework/source/uielement - dropdownboxtoolbarcontroller.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 137 0.0 %
Date: 2014-04-11 Functions: 0 19 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 "uielement/dropdownboxtoolbarcontroller.hxx"
      21             : 
      22             : #include <com/sun/star/util/XURLTransformer.hpp>
      23             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      24             : #include <com/sun/star/beans/PropertyValue.hpp>
      25             : #include <com/sun/star/frame/status/ItemStatus.hpp>
      26             : #include <com/sun/star/frame/status/ItemState.hpp>
      27             : #include <com/sun/star/frame/status/Visibility.hpp>
      28             : #include <com/sun/star/frame/XControlNotificationListener.hpp>
      29             : 
      30             : #include <svtools/toolboxcontroller.hxx>
      31             : #include <osl/mutex.hxx>
      32             : #include <vcl/svapp.hxx>
      33             : #include <vcl/mnemonic.hxx>
      34             : #include <vcl/toolbox.hxx>
      35             : 
      36             : using namespace ::com::sun::star;
      37             : using namespace ::com::sun::star::awt;
      38             : using namespace ::com::sun::star::uno;
      39             : using namespace ::com::sun::star::beans;
      40             : using namespace ::com::sun::star::lang;
      41             : using namespace ::com::sun::star::frame;
      42             : using namespace ::com::sun::star::frame::status;
      43             : using namespace ::com::sun::star::util;
      44             : 
      45             : namespace framework
      46             : {
      47             : 
      48             : // Wrapper class to notify controller about events from ListBox.
      49             : // Unfortunaltly the events are notifed through virtual methods instead
      50             : // of Listeners.
      51             : 
      52             : class ListBoxControl : public ListBox
      53             : {
      54             :     public:
      55             :         ListBoxControl( Window* pParent, WinBits nStyle, IListBoxListener* pListBoxListener );
      56             :         virtual ~ListBoxControl();
      57             : 
      58             :         virtual void Select() SAL_OVERRIDE;
      59             :         virtual void DoubleClick() SAL_OVERRIDE;
      60             :         virtual void GetFocus() SAL_OVERRIDE;
      61             :         virtual void LoseFocus() SAL_OVERRIDE;
      62             :         virtual bool PreNotify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
      63             : 
      64             :     private:
      65             :         IListBoxListener* m_pListBoxListener;
      66             : };
      67             : 
      68           0 : ListBoxControl::ListBoxControl( Window* pParent, WinBits nStyle, IListBoxListener* pListBoxListener ) :
      69             :     ListBox( pParent, nStyle )
      70           0 :     , m_pListBoxListener( pListBoxListener )
      71             : {
      72           0 : }
      73             : 
      74           0 : ListBoxControl::~ListBoxControl()
      75             : {
      76           0 :     m_pListBoxListener = 0;
      77           0 : }
      78             : 
      79           0 : void ListBoxControl::Select()
      80             : {
      81           0 :     ListBox::Select();
      82           0 :     if ( m_pListBoxListener )
      83           0 :         m_pListBoxListener->Select();
      84           0 : }
      85             : 
      86           0 : void ListBoxControl::DoubleClick()
      87             : {
      88           0 :     ListBox::DoubleClick();
      89           0 :     if ( m_pListBoxListener )
      90           0 :         m_pListBoxListener->DoubleClick();
      91           0 : }
      92             : 
      93           0 : void ListBoxControl::GetFocus()
      94             : {
      95           0 :     ListBox::GetFocus();
      96           0 :     if ( m_pListBoxListener )
      97           0 :         m_pListBoxListener->GetFocus();
      98           0 : }
      99             : 
     100           0 : void ListBoxControl::LoseFocus()
     101             : {
     102           0 :     ListBox::LoseFocus();
     103           0 :     if ( m_pListBoxListener )
     104           0 :         m_pListBoxListener->LoseFocus();
     105           0 : }
     106             : 
     107           0 : bool ListBoxControl::PreNotify( NotifyEvent& rNEvt )
     108             : {
     109           0 :     bool nRet = false;
     110           0 :     if ( m_pListBoxListener )
     111           0 :         nRet = m_pListBoxListener->PreNotify( rNEvt );
     112           0 :     if ( !nRet )
     113           0 :         nRet = ListBox::PreNotify( rNEvt );
     114             : 
     115           0 :     return nRet;
     116             : }
     117             : 
     118           0 : DropdownToolbarController::DropdownToolbarController(
     119             :     const Reference< XComponentContext >&    rxContext,
     120             :     const Reference< XFrame >&               rFrame,
     121             :     ToolBox*                                 pToolbar,
     122             :     sal_uInt16                                   nID,
     123             :     sal_Int32                                nWidth,
     124             :     const OUString&                          aCommand ) :
     125             :     ComplexToolbarController( rxContext, rFrame, pToolbar, nID, aCommand )
     126           0 :     ,   m_pListBoxControl( 0 )
     127             : {
     128           0 :     m_pListBoxControl = new ListBoxControl( m_pToolbar, WB_DROPDOWN|WB_AUTOHSCROLL|WB_BORDER, this );
     129           0 :     if ( nWidth == 0 )
     130           0 :         nWidth = 100;
     131             : 
     132             :     // default dropdown size
     133           0 :     ::Size aLogicalSize( 0, 160 );
     134           0 :     ::Size aPixelSize = m_pListBoxControl->LogicToPixel( aLogicalSize, MAP_APPFONT );
     135             : 
     136           0 :     m_pListBoxControl->SetSizePixel( ::Size( nWidth, aPixelSize.Height() ));
     137           0 :     m_pToolbar->SetItemWindow( m_nID, m_pListBoxControl );
     138           0 :     m_pListBoxControl->SetDropDownLineCount( 5 );
     139           0 : }
     140             : 
     141           0 : DropdownToolbarController::~DropdownToolbarController()
     142             : {
     143           0 : }
     144             : 
     145           0 : void SAL_CALL DropdownToolbarController::dispose()
     146             : throw ( RuntimeException, std::exception )
     147             : {
     148           0 :     SolarMutexGuard aSolarMutexGuard;
     149             : 
     150           0 :     m_pToolbar->SetItemWindow( m_nID, 0 );
     151           0 :     delete m_pListBoxControl;
     152             : 
     153           0 :     ComplexToolbarController::dispose();
     154             : 
     155           0 :     m_pListBoxControl = 0;
     156           0 : }
     157             : 
     158           0 : Sequence<PropertyValue> DropdownToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
     159             : {
     160           0 :     Sequence<PropertyValue> aArgs( 2 );
     161           0 :     OUString aSelectedText = m_pListBoxControl->GetSelectEntry();
     162             : 
     163             :     // Add key modifier to argument list
     164           0 :     aArgs[0].Name = "KeyModifier";
     165           0 :     aArgs[0].Value <<= KeyModifier;
     166           0 :     aArgs[1].Name = "Text";
     167           0 :     aArgs[1].Value <<= aSelectedText;
     168           0 :     return aArgs;
     169             : }
     170             : 
     171           0 : void DropdownToolbarController::Select()
     172             : {
     173           0 :     if ( m_pListBoxControl->GetEntryCount() > 0 )
     174             :     {
     175           0 :         Window::PointerState aState = m_pListBoxControl->GetPointerState();
     176             : 
     177           0 :         sal_uInt16 nKeyModifier = sal_uInt16( aState.mnState & KEY_MODTYPE );
     178           0 :         execute( nKeyModifier );
     179             :     }
     180           0 : }
     181             : 
     182           0 : void DropdownToolbarController::DoubleClick()
     183             : {
     184           0 : }
     185             : 
     186           0 : void DropdownToolbarController::GetFocus()
     187             : {
     188           0 :     notifyFocusGet();
     189           0 : }
     190             : 
     191           0 : void DropdownToolbarController::LoseFocus()
     192             : {
     193           0 :     notifyFocusLost();
     194           0 : }
     195             : 
     196           0 : bool DropdownToolbarController::PreNotify( NotifyEvent& /*rNEvt*/ )
     197             : {
     198           0 :     return false;
     199             : }
     200             : 
     201           0 : void DropdownToolbarController::executeControlCommand( const ::com::sun::star::frame::ControlCommand& rControlCommand )
     202             : {
     203           0 :     if ( rControlCommand.Command == "SetList" )
     204             :     {
     205           0 :         for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     206             :         {
     207           0 :             if ( rControlCommand.Arguments[i].Name == "List" )
     208             :             {
     209           0 :                 Sequence< OUString > aList;
     210           0 :                 m_pListBoxControl->Clear();
     211             : 
     212           0 :                 rControlCommand.Arguments[i].Value >>= aList;
     213           0 :                 for ( sal_Int32 j = 0; j < aList.getLength(); j++ )
     214           0 :                     m_pListBoxControl->InsertEntry( aList[j] );
     215             : 
     216           0 :                 m_pListBoxControl->SelectEntryPos( 0 );
     217             : 
     218             :                 // send notification
     219           0 :                 uno::Sequence< beans::NamedValue > aInfo( 1 );
     220           0 :                 aInfo[0].Name  = "List";
     221           0 :                 aInfo[0].Value <<= aList;
     222             :                 addNotifyInfo( OUString( "ListChanged" ),
     223             :                                getDispatchFromCommand( m_aCommandURL ),
     224           0 :                                aInfo );
     225             : 
     226           0 :                 break;
     227             :             }
     228             :         }
     229             :     }
     230           0 :     else if ( rControlCommand.Command == "AddEntry" )
     231             :     {
     232           0 :         sal_Int32      nPos( LISTBOX_APPEND );
     233           0 :         OUString   aText;
     234           0 :         for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     235             :         {
     236           0 :             if ( rControlCommand.Arguments[i].Name == "Text" )
     237             :             {
     238           0 :                 if ( rControlCommand.Arguments[i].Value >>= aText )
     239           0 :                     m_pListBoxControl->InsertEntry( aText, nPos );
     240           0 :                 break;
     241             :             }
     242           0 :         }
     243             :     }
     244           0 :     else if ( rControlCommand.Command == "InsertEntry" )
     245             :     {
     246           0 :         sal_Int32      nPos( LISTBOX_APPEND );
     247           0 :         OUString   aText;
     248           0 :         for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     249             :         {
     250           0 :             if ( rControlCommand.Arguments[i].Name == "Pos" )
     251             :             {
     252           0 :                 sal_Int32 nTmpPos = 0;
     253           0 :                 if ( rControlCommand.Arguments[i].Value >>= nTmpPos )
     254             :                 {
     255           0 :                     if (( nTmpPos >= 0 ) &&
     256           0 :                         ( nTmpPos < sal_Int32( m_pListBoxControl->GetEntryCount() )))
     257           0 :                         nPos = nTmpPos;
     258             :                 }
     259             :             }
     260           0 :             else if ( rControlCommand.Arguments[i].Name == "Text" )
     261           0 :                 rControlCommand.Arguments[i].Value >>= aText;
     262             :         }
     263             : 
     264           0 :         m_pListBoxControl->InsertEntry( aText, nPos );
     265             :     }
     266           0 :     else if ( rControlCommand.Command == "RemoveEntryPos" )
     267             :     {
     268           0 :         for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     269             :         {
     270           0 :             if ( rControlCommand.Arguments[i].Name == "Pos" )
     271             :             {
     272           0 :                 sal_Int32 nPos( -1 );
     273           0 :                 if ( rControlCommand.Arguments[i].Value >>= nPos )
     274             :                 {
     275           0 :                     if ( 0 <= nPos && nPos < sal_Int32( m_pListBoxControl->GetEntryCount() ))
     276           0 :                         m_pListBoxControl->RemoveEntry( nPos );
     277             :                 }
     278           0 :                 break;
     279             :             }
     280             :         }
     281             :     }
     282           0 :     else if ( rControlCommand.Command == "RemoveEntryText" )
     283             :     {
     284           0 :         for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     285             :         {
     286           0 :             if ( rControlCommand.Arguments[i].Name == "Text" )
     287             :             {
     288           0 :                 OUString aText;
     289           0 :                 if ( rControlCommand.Arguments[i].Value >>= aText )
     290           0 :                     m_pListBoxControl->RemoveEntry( aText );
     291           0 :                 break;
     292             :             }
     293             :         }
     294             :     }
     295           0 :     else if ( rControlCommand.Command == "SetDropDownLines" )
     296             :     {
     297           0 :         for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     298             :         {
     299           0 :             if ( rControlCommand.Arguments[i].Name == "Lines" )
     300             :             {
     301           0 :                 sal_Int32 nValue( 5 );
     302           0 :                 rControlCommand.Arguments[i].Value >>= nValue;
     303           0 :                 m_pListBoxControl->SetDropDownLineCount( sal_uInt16( nValue ));
     304           0 :                 break;
     305             :             }
     306             :         }
     307             :     }
     308           0 : }
     309             : 
     310             : } // namespace
     311             : 
     312             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10