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

Generated by: LCOV version 1.10