LCOV - code coverage report
Current view: top level - libreoffice/framework/source/uielement - edittoolbarcontroller.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 23 89 25.8 %
Date: 2012-12-27 Functions: 7 19 36.8 %
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/edittoolbarcontroller.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             : 
      33             : #include <svtools/toolboxcontroller.hxx>
      34             : #include <osl/mutex.hxx>
      35             : #include <vcl/svapp.hxx>
      36             : #include <vcl/mnemonic.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             : // ------------------------------------------------------------------
      50             : 
      51             : // Wrapper class to notify controller about events from edit.
      52             : // Unfortunaltly the events are notifed through virtual methods instead
      53             : // of Listeners.
      54             : 
      55             : class EditControl : public Edit
      56             : {
      57             :     public:
      58             :         EditControl( Window* pParent, WinBits nStyle, IEditListener* pEditListener );
      59             :         virtual ~EditControl();
      60             : 
      61             :         virtual void Modify();
      62             :         virtual void KeyInput( const ::KeyEvent& rKEvt );
      63             :         virtual void GetFocus();
      64             :         virtual void LoseFocus();
      65             :         virtual long PreNotify( NotifyEvent& rNEvt );
      66             : 
      67             :     private:
      68             :         IEditListener* m_pEditListener;
      69             : };
      70             : 
      71         236 : EditControl::EditControl( Window* pParent, WinBits nStyle, IEditListener* pEditListener ) :
      72             :     Edit( pParent, nStyle )
      73         236 :     , m_pEditListener( pEditListener )
      74             : {
      75         236 : }
      76             : 
      77         189 : EditControl::~EditControl()
      78             : {
      79          63 :     m_pEditListener = 0;
      80         126 : }
      81             : 
      82           0 : void EditControl::Modify()
      83             : {
      84           0 :     Edit::Modify();
      85           0 :     if ( m_pEditListener )
      86           0 :         m_pEditListener->Modify();
      87           0 : }
      88             : 
      89           0 : void EditControl::KeyInput( const ::KeyEvent& rKEvt )
      90             : {
      91           0 :     Edit::KeyInput( rKEvt );
      92           0 :     if ( m_pEditListener )
      93           0 :         m_pEditListener->KeyInput( rKEvt );
      94           0 : }
      95             : 
      96           0 : void EditControl::GetFocus()
      97             : {
      98           0 :     Edit::GetFocus();
      99           0 :     if ( m_pEditListener )
     100           0 :         m_pEditListener->GetFocus();
     101           0 : }
     102             : 
     103           0 : void EditControl::LoseFocus()
     104             : {
     105           0 :     Edit::LoseFocus();
     106           0 :     if ( m_pEditListener )
     107           0 :         m_pEditListener->LoseFocus();
     108           0 : }
     109             : 
     110           0 : long EditControl::PreNotify( NotifyEvent& rNEvt )
     111             : {
     112           0 :     long nRet( 0 );
     113           0 :     if ( m_pEditListener )
     114           0 :         nRet = m_pEditListener->PreNotify( rNEvt );
     115           0 :     if ( nRet == 0 )
     116           0 :         nRet = Edit::PreNotify( rNEvt );
     117             : 
     118           0 :     return nRet;
     119             : }
     120             : 
     121             : // ------------------------------------------------------------------
     122             : 
     123         236 : EditToolbarController::EditToolbarController(
     124             :     const Reference< XMultiServiceFactory >& rServiceManager,
     125             :     const Reference< XFrame >&               rFrame,
     126             :     ToolBox*                                 pToolbar,
     127             :     sal_uInt16                                   nID,
     128             :     sal_Int32                                nWidth,
     129             :     const ::rtl::OUString&                          aCommand ) :
     130             :     ComplexToolbarController( rServiceManager, rFrame, pToolbar, nID, aCommand )
     131         236 :     ,   m_pEditControl( 0 )
     132             : {
     133         236 :     m_pEditControl = new EditControl( m_pToolbar, WB_BORDER, this );
     134         236 :     if ( nWidth == 0 )
     135           0 :         nWidth = 100;
     136             : 
     137             :     // Calculate height of the edit field according to the application font height
     138         236 :     sal_Int32 nHeight = getFontSizePixel( m_pEditControl ) + 6 + 1;
     139             : 
     140         236 :     m_pEditControl->SetSizePixel( ::Size( nWidth, nHeight ));
     141         236 :     m_pToolbar->SetItemWindow( m_nID, m_pEditControl );
     142         236 : }
     143             : 
     144             : // ------------------------------------------------------------------
     145             : 
     146         126 : EditToolbarController::~EditToolbarController()
     147             : {
     148         126 : }
     149             : 
     150             : // ------------------------------------------------------------------
     151             : 
     152          63 : void SAL_CALL EditToolbarController::dispose()
     153             : throw ( RuntimeException )
     154             : {
     155          63 :     SolarMutexGuard aSolarMutexGuard;
     156             : 
     157          63 :     m_pToolbar->SetItemWindow( m_nID, 0 );
     158          63 :     delete m_pEditControl;
     159             : 
     160          63 :     ComplexToolbarController::dispose();
     161             : 
     162          63 :     m_pEditControl = 0;
     163          63 : }
     164             : 
     165             : // ------------------------------------------------------------------
     166           0 : Sequence<PropertyValue> EditToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
     167             : {
     168           0 :     Sequence<PropertyValue> aArgs( 2 );
     169           0 :     ::rtl::OUString aSelectedText = m_pEditControl->GetText();
     170             : 
     171             :     // Add key modifier to argument list
     172           0 :     aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "KeyModifier" ));
     173           0 :     aArgs[0].Value <<= KeyModifier;
     174           0 :     aArgs[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ));
     175           0 :     aArgs[1].Value <<= aSelectedText;
     176           0 :     return aArgs;
     177             : }
     178             : 
     179             : // ------------------------------------------------------------------
     180             : 
     181           0 : void EditToolbarController::Modify()
     182             : {
     183           0 :     notifyTextChanged( m_pEditControl->GetText() );
     184           0 : }
     185             : 
     186           0 : void EditToolbarController::KeyInput( const ::KeyEvent& /*rKEvt*/ )
     187             : {
     188           0 : }
     189             : 
     190           0 : void EditToolbarController::GetFocus()
     191             : {
     192           0 :     notifyFocusGet();
     193           0 : }
     194             : 
     195           0 : void EditToolbarController::LoseFocus()
     196             : {
     197           0 :     notifyFocusLost();
     198           0 : }
     199             : 
     200           0 : long EditToolbarController::PreNotify( NotifyEvent& rNEvt )
     201             : {
     202           0 :     if( rNEvt.GetType() == EVENT_KEYINPUT )
     203             :     {
     204           0 :         const ::KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
     205           0 :         const KeyCode& rKeyCode = pKeyEvent->GetKeyCode();
     206           0 :         if(( rKeyCode.GetModifier() | rKeyCode.GetCode()) == KEY_RETURN )
     207             :         {
     208             :             // Call execute only with non-empty text
     209           0 :             if ( m_pEditControl->GetText().Len() > 0 )
     210           0 :                 execute( rKeyCode.GetModifier() );
     211           0 :             return 1;
     212             :         }
     213             :     }
     214             : 
     215           0 :     return 0;
     216             : }
     217             : 
     218             : // --------------------------------------------------------
     219             : 
     220           0 : void EditToolbarController::executeControlCommand( const ::com::sun::star::frame::ControlCommand& rControlCommand )
     221             : {
     222           0 :     if ( rControlCommand.Command.equalsAsciiL( "SetText", 7 ))
     223             :     {
     224           0 :         for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
     225             :         {
     226           0 :             if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
     227             :             {
     228           0 :                 rtl::OUString aText;
     229           0 :                 rControlCommand.Arguments[i].Value >>= aText;
     230           0 :                 m_pEditControl->SetText( aText );
     231             : 
     232             :                 // send notification
     233           0 :                 notifyTextChanged( aText );
     234           0 :                 break;
     235             :             }
     236             :         }
     237             :     }
     238           0 : }
     239             : 
     240             : } // namespace
     241             : 
     242             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10