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

Generated by: LCOV version 1.10