LCOV - code coverage report
Current view: top level - libreoffice/framework/source/uielement - comboboxtoolbarcontroller.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 183 0.0 %
Date: 2012-12-27 Functions: 0 23 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             : 
      21             : #include "uielement/comboboxtoolbarcontroller.hxx"
      22             : 
      23             : #include "uielement/toolbar.hxx"
      24             : 
      25             : #include <com/sun/star/util/XURLTransformer.hpp>
      26             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      27             : #include <com/sun/star/beans/PropertyValue.hpp>
      28             : #include <com/sun/star/frame/status/ItemStatus.hpp>
      29             : #include <com/sun/star/frame/status/ItemState.hpp>
      30             : #include <com/sun/star/frame/status/Visibility.hpp>
      31             : #include <com/sun/star/frame/XControlNotificationListener.hpp>
      32             : #include <com/sun/star/util/Color.hpp>
      33             : 
      34             : #include <svtools/toolboxcontroller.hxx>
      35             : #include <osl/mutex.hxx>
      36             : #include <vcl/svapp.hxx>
      37             : #include <vcl/mnemonic.hxx>
      38             : #include <vcl/toolbox.hxx>
      39             : #include <vcl/combobox.hxx>
      40             : 
      41             : using namespace ::com::sun::star;
      42             : using namespace ::com::sun::star::uno;
      43             : using namespace ::com::sun::star::beans;
      44             : using namespace ::com::sun::star::lang;
      45             : using namespace ::com::sun::star::frame;
      46             : using namespace ::com::sun::star::frame::status;
      47             : using namespace ::com::sun::star::util;
      48             : 
      49             : namespace framework
      50             : {
      51             : 
      52             : // ------------------------------------------------------------------
      53             : 
      54             : // Wrapper class to notify controller about events from combobox.
      55             : // Unfortunaltly the events are notifed through virtual methods instead
      56             : // of Listeners.
      57             : 
      58             : class ComboBoxControl : public ComboBox
      59             : {
      60             :     public:
      61             :         ComboBoxControl( Window* pParent, WinBits nStyle, IComboBoxListener* pComboBoxListener );
      62             :         virtual ~ComboBoxControl();
      63             : 
      64             :         virtual void Select();
      65             :         virtual void DoubleClick();
      66             :         virtual void Modify();
      67             :         virtual void KeyInput( const ::KeyEvent& rKEvt );
      68             :         virtual void GetFocus();
      69             :         virtual void LoseFocus();
      70             :         virtual long PreNotify( NotifyEvent& rNEvt );
      71             : 
      72             :     private:
      73             :         IComboBoxListener* m_pComboBoxListener;
      74             : };
      75             : 
      76           0 : ComboBoxControl::ComboBoxControl( Window* pParent, WinBits nStyle, IComboBoxListener* pComboBoxListener ) :
      77             :     ComboBox( pParent, nStyle )
      78           0 :     , m_pComboBoxListener( pComboBoxListener )
      79             : {
      80           0 : }
      81             : 
      82           0 : ComboBoxControl::~ComboBoxControl()
      83             : {
      84           0 :     m_pComboBoxListener = 0;
      85           0 : }
      86             : 
      87           0 : void ComboBoxControl::Select()
      88             : {
      89           0 :     ComboBox::Select();
      90           0 :     if ( m_pComboBoxListener )
      91           0 :         m_pComboBoxListener->Select();
      92           0 : }
      93             : 
      94           0 : void ComboBoxControl::DoubleClick()
      95             : {
      96           0 :     ComboBox::DoubleClick();
      97           0 :     if ( m_pComboBoxListener )
      98           0 :         m_pComboBoxListener->DoubleClick();
      99           0 : }
     100             : 
     101           0 : void ComboBoxControl::Modify()
     102             : {
     103           0 :     ComboBox::Modify();
     104           0 :     if ( m_pComboBoxListener )
     105           0 :         m_pComboBoxListener->Modify();
     106           0 : }
     107             : 
     108           0 : void ComboBoxControl::KeyInput( const ::KeyEvent& rKEvt )
     109             : {
     110           0 :     ComboBox::KeyInput( rKEvt );
     111           0 :     if ( m_pComboBoxListener )
     112           0 :         m_pComboBoxListener->KeyInput( rKEvt );
     113           0 : }
     114             : 
     115           0 : void ComboBoxControl::GetFocus()
     116             : {
     117           0 :     ComboBox::GetFocus();
     118           0 :     if ( m_pComboBoxListener )
     119           0 :         m_pComboBoxListener->GetFocus();
     120           0 : }
     121             : 
     122           0 : void ComboBoxControl::LoseFocus()
     123             : {
     124           0 :     ComboBox::LoseFocus();
     125           0 :     if ( m_pComboBoxListener )
     126           0 :         m_pComboBoxListener->LoseFocus();
     127           0 : }
     128             : 
     129           0 : long ComboBoxControl::PreNotify( NotifyEvent& rNEvt )
     130             : {
     131           0 :     long nRet( 0 );
     132           0 :     if ( m_pComboBoxListener )
     133           0 :         nRet = m_pComboBoxListener->PreNotify( rNEvt );
     134           0 :     if ( nRet == 0 )
     135           0 :         nRet = ComboBox::PreNotify( rNEvt );
     136             : 
     137           0 :     return nRet;
     138             : }
     139             : 
     140             : // ------------------------------------------------------------------
     141             : 
     142           0 : ComboboxToolbarController::ComboboxToolbarController(
     143             :     const Reference< XMultiServiceFactory >& rServiceManager,
     144             :     const Reference< XFrame >&               rFrame,
     145             :     ToolBox*                                 pToolbar,
     146             :     sal_uInt16                                   nID,
     147             :     sal_Int32                                nWidth,
     148             :     const ::rtl::OUString&                          aCommand ) :
     149             :     ComplexToolbarController( rServiceManager, rFrame, pToolbar, nID, aCommand )
     150           0 :     ,   m_pComboBox( 0 )
     151             : {
     152           0 :     m_pComboBox = new ComboBoxControl( m_pToolbar, WB_DROPDOWN, this );
     153           0 :     if ( nWidth == 0 )
     154           0 :         nWidth = 100;
     155             : 
     156             :     // default dropdown size
     157           0 :     ::Size aLogicalSize( 8, 160 );
     158           0 :     ::Size aPixelSize = m_pComboBox->LogicToPixel( aLogicalSize, MAP_APPFONT );
     159             : 
     160           0 :     m_pComboBox->SetSizePixel( ::Size( nWidth, aPixelSize.Height() ));
     161           0 :     m_pToolbar->SetItemWindow( m_nID, m_pComboBox );
     162           0 : }
     163             : 
     164             : // ------------------------------------------------------------------
     165             : 
     166           0 : ComboboxToolbarController::~ComboboxToolbarController()
     167             : {
     168           0 : }
     169             : 
     170             : // ------------------------------------------------------------------
     171             : 
     172           0 : void SAL_CALL ComboboxToolbarController::dispose()
     173             : throw ( RuntimeException )
     174             : {
     175           0 :     SolarMutexGuard aSolarMutexGuard;
     176             : 
     177           0 :     m_pToolbar->SetItemWindow( m_nID, 0 );
     178           0 :     delete m_pComboBox;
     179             : 
     180           0 :     ComplexToolbarController::dispose();
     181             : 
     182           0 :     m_pComboBox = 0;
     183           0 : }
     184             : 
     185             : // ------------------------------------------------------------------
     186           0 : Sequence<PropertyValue> ComboboxToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
     187             : {
     188           0 :     Sequence<PropertyValue> aArgs( 2 );
     189           0 :     ::rtl::OUString aSelectedText = m_pComboBox->GetText();
     190             : 
     191             :     // Add key modifier to argument list
     192           0 :     aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "KeyModifier" ));
     193           0 :     aArgs[0].Value <<= KeyModifier;
     194           0 :     aArgs[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ));
     195           0 :     aArgs[1].Value <<= aSelectedText;
     196           0 :     return aArgs;
     197             : }
     198             : 
     199             : // ------------------------------------------------------------------
     200             : 
     201           0 : void ComboboxToolbarController::Select()
     202             : {
     203           0 :     if ( m_pComboBox->GetEntryCount() > 0 )
     204             :     {
     205           0 :         Window::PointerState aState = m_pComboBox->GetPointerState();
     206             : 
     207           0 :         sal_uInt16 nKeyModifier = sal_uInt16( aState.mnState & KEY_MODTYPE );
     208           0 :         execute( nKeyModifier );
     209             :     }
     210           0 : }
     211             : 
     212           0 : void ComboboxToolbarController::DoubleClick()
     213             : {
     214           0 : }
     215             : 
     216           0 : void ComboboxToolbarController::Modify()
     217             : {
     218           0 :     notifyTextChanged( m_pComboBox->GetText() );
     219           0 : }
     220             : 
     221           0 : void ComboboxToolbarController::KeyInput( const ::KeyEvent& )
     222             : {
     223           0 : }
     224             : 
     225           0 : void ComboboxToolbarController::GetFocus()
     226             : {
     227           0 :     notifyFocusGet();
     228           0 : }
     229             : 
     230           0 : void ComboboxToolbarController::LoseFocus()
     231             : {
     232           0 :     notifyFocusLost();
     233           0 : }
     234             : 
     235           0 : long ComboboxToolbarController::PreNotify( NotifyEvent& rNEvt )
     236             : {
     237           0 :     switch ( rNEvt.GetType() )
     238             :     {
     239             :         case EVENT_KEYINPUT :
     240             :             {
     241           0 :                 const ::KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
     242           0 :                 const KeyCode& rKeyCode = pKeyEvent->GetKeyCode();
     243           0 :                 if(( rKeyCode.GetModifier() | rKeyCode.GetCode()) == KEY_RETURN )
     244             :                 {
     245             :                     // Call execute only with non-empty text
     246           0 :                     if ( m_pComboBox->GetText().Len() > 0 )
     247           0 :                         execute( rKeyCode.GetModifier() );
     248           0 :                     return 1;
     249             :                 }
     250             :             }
     251           0 :             break;
     252             :         case EVENT_GETFOCUS :
     253           0 :             notifyFocusGet();
     254           0 :             break;
     255             :         case EVENT_LOSEFOCUS :
     256           0 :             notifyFocusLost();
     257           0 :             break;
     258             :         default :
     259           0 :             break;
     260             :     }
     261           0 :     return 0;
     262             : }
     263             : 
     264             : // --------------------------------------------------------
     265             : 
     266           0 : void ComboboxToolbarController::executeControlCommand( const ::com::sun::star::frame::ControlCommand& rControlCommand )
     267             : {
     268           0 :     if ( rControlCommand.Command.equalsAsciiL( "SetText", 7 ))
     269             :     {
     270           0 :         for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     271             :         {
     272           0 :             if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
     273             :             {
     274           0 :                 rtl::OUString aText;
     275           0 :                 rControlCommand.Arguments[i].Value >>= aText;
     276           0 :                 m_pComboBox->SetText( aText );
     277             : 
     278             :                 // send notification
     279           0 :                 notifyTextChanged( aText );
     280           0 :                 break;
     281             :             }
     282             :         }
     283             :     }
     284           0 :     else if ( rControlCommand.Command.equalsAsciiL( "SetList", 7 ))
     285             :     {
     286           0 :         for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     287             :         {
     288           0 :             if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "List", 4 ))
     289             :             {
     290           0 :                 Sequence< ::rtl::OUString > aList;
     291           0 :                 m_pComboBox->Clear();
     292             : 
     293           0 :                 rControlCommand.Arguments[i].Value >>= aList;
     294           0 :                 for ( sal_Int32 j = 0; j < aList.getLength(); j++ )
     295           0 :                     m_pComboBox->InsertEntry( aList[j] );
     296             : 
     297             :                 // send notification
     298           0 :                 uno::Sequence< beans::NamedValue > aInfo( 1 );
     299           0 :                 aInfo[0].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "List" ));
     300           0 :                 aInfo[0].Value <<= aList;
     301             :                 addNotifyInfo( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ListChanged" )),
     302             :                                getDispatchFromCommand( m_aCommandURL ),
     303           0 :                                aInfo );
     304             : 
     305           0 :                 break;
     306             :             }
     307             :         }
     308             :     }
     309           0 :     else if ( rControlCommand.Command.equalsAsciiL( "AddEntry", 8 ))
     310             :     {
     311           0 :         sal_uInt16      nPos( COMBOBOX_APPEND );
     312           0 :         rtl::OUString   aText;
     313           0 :         for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     314             :         {
     315           0 :             if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
     316             :             {
     317           0 :                 if ( rControlCommand.Arguments[i].Value >>= aText )
     318           0 :                     m_pComboBox->InsertEntry( aText, nPos );
     319           0 :                 break;
     320             :             }
     321           0 :         }
     322             :     }
     323           0 :     else if ( rControlCommand.Command.equalsAsciiL( "InsertEntry", 11 ))
     324             :     {
     325           0 :         sal_uInt16      nPos( COMBOBOX_APPEND );
     326           0 :         rtl::OUString   aText;
     327           0 :         for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     328             :         {
     329           0 :             if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Pos", 3 ))
     330             :             {
     331           0 :                 sal_Int32 nTmpPos = 0;
     332           0 :                 if ( rControlCommand.Arguments[i].Value >>= nTmpPos )
     333             :                 {
     334           0 :                     if (( nTmpPos >= 0 ) &&
     335           0 :                         ( nTmpPos < sal_Int32( m_pComboBox->GetEntryCount() )))
     336           0 :                         nPos = sal_uInt16( nTmpPos );
     337             :                 }
     338             :             }
     339           0 :             else if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
     340           0 :                 rControlCommand.Arguments[i].Value >>= aText;
     341             :         }
     342             : 
     343           0 :         m_pComboBox->InsertEntry( aText, nPos );
     344             :     }
     345           0 :     else if ( rControlCommand.Command.equalsAsciiL( "RemoveEntryPos", 14 ))
     346             :     {
     347           0 :         for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     348             :         {
     349           0 :             if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Pos", 3 ))
     350             :             {
     351           0 :                 sal_Int32 nPos( -1 );
     352           0 :                 if ( rControlCommand.Arguments[i].Value >>= nPos )
     353             :                 {
     354           0 :                     if ( nPos < sal_Int32( m_pComboBox->GetEntryCount() ))
     355           0 :                         m_pComboBox->RemoveEntry( sal_uInt16( nPos ));
     356             :                 }
     357             :                 break;
     358             :             }
     359             :         }
     360             :     }
     361           0 :     else if ( rControlCommand.Command.equalsAsciiL( "RemoveEntryText", 15 ))
     362             :     {
     363           0 :         for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     364             :         {
     365           0 :             if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
     366             :             {
     367           0 :                 rtl::OUString aText;
     368           0 :                 if ( rControlCommand.Arguments[i].Value >>= aText )
     369           0 :                     m_pComboBox->RemoveEntry( aText );
     370           0 :                 break;
     371             :             }
     372             :         }
     373             :     }
     374           0 :     else if ( rControlCommand.Command.equalsAsciiL( "SetDropDownLines", 16 ))
     375             :     {
     376           0 :         for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     377             :         {
     378           0 :             if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Lines", 5 ))
     379             :             {
     380           0 :                 sal_Int32 nValue( 5 );
     381           0 :                 rControlCommand.Arguments[i].Value >>= nValue;
     382           0 :                 m_pComboBox->SetDropDownLineCount( sal_uInt16( nValue ));
     383             :                 break;
     384             :             }
     385             :         }
     386             :     }
     387           0 :     else if ( rControlCommand.Command.equalsAsciiL( "SetBackgroundColor", 18 ))
     388             :     {
     389           0 :         for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     390             :         {
     391           0 :             if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Color", 5 ))
     392             :             {
     393           0 :                 com::sun::star::util::Color aColor(0);
     394           0 :                 if ( rControlCommand.Arguments[i].Value >>= aColor )
     395             :                 {
     396           0 :                     ::Color aBackColor( static_cast< sal_uInt32 >( aColor ));
     397           0 :                     m_pComboBox->SetControlBackground( aBackColor );
     398             :                 }
     399             :                 break;
     400             :             }
     401             :         }
     402             :     }
     403           0 :     else if ( rControlCommand.Command.equalsAsciiL( "SetTextColor", 12 ))
     404             :     {
     405           0 :         for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     406             :         {
     407           0 :             if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Color", 5 ))
     408             :             {
     409           0 :                 com::sun::star::util::Color aColor(0);
     410           0 :                 if ( rControlCommand.Arguments[i].Value >>= aColor )
     411             :                 {
     412           0 :                     ::Color aForeColor( static_cast< sal_uInt32 >( aColor ));
     413           0 :                     m_pComboBox->SetControlForeground( aForeColor );
     414             :                 }
     415             :                 break;
     416             :             }
     417             :         }
     418             :     }
     419           0 : }
     420             : 
     421             : } // namespace
     422             : 
     423             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10