LCOV - code coverage report
Current view: top level - svx/source/form - fmtextcontrolshell.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 163 488 33.4 %
Date: 2014-11-03 Functions: 25 52 48.1 %
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 "fmprop.hrc"
      22             : #include "svx/fmresids.hrc"
      23             : #include "fmtextcontroldialogs.hxx"
      24             : #include "fmtextcontrolfeature.hxx"
      25             : #include "fmtextcontrolshell.hxx"
      26             : #include "editeng/crossedoutitem.hxx"
      27             : #include "svx/dialmgr.hxx"
      28             : #include "editeng/editeng.hxx"
      29             : #include "editeng/eeitem.hxx"
      30             : #include "svx/fmglob.hxx"
      31             : #include "editeng/scriptspaceitem.hxx"
      32             : #include "svx/svxids.hrc"
      33             : #include "editeng/udlnitem.hxx"
      34             : 
      35             : #include <com/sun/star/beans/XPropertySet.hpp>
      36             : #include <com/sun/star/awt/FontDescriptor.hpp>
      37             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      38             : #include <com/sun/star/form/XForm.hpp>
      39             : #include <com/sun/star/container/XChild.hpp>
      40             : #include <com/sun/star/awt/XFocusListener.hpp>
      41             : #include <com/sun/star/awt/XMouseListener.hpp>
      42             : #include <com/sun/star/util/URLTransformer.hpp>
      43             : 
      44             : #include <comphelper/processfactory.hxx>
      45             : #include <cppuhelper/implbase1.hxx>
      46             : #include <sfx2/app.hxx>
      47             : #include <sfx2/bindings.hxx>
      48             : #include <sfx2/dispatch.hxx>
      49             : #include <sfx2/msgpool.hxx>
      50             : #include <sfx2/objsh.hxx>
      51             : #include <sfx2/request.hxx>
      52             : #include <sfx2/sfxuno.hxx>
      53             : #include <sfx2/viewfrm.hxx>
      54             : #include <svl/eitem.hxx>
      55             : #include <svl/intitem.hxx>
      56             : #include <svl/itempool.hxx>
      57             : #include <svl/languageoptions.hxx>
      58             : #include <svtools/stringtransfer.hxx>
      59             : #include <svl/whiter.hxx>
      60             : #include <toolkit/helper/vclunohelper.hxx>
      61             : #include <tools/diagnose_ex.h>
      62             : #include <vcl/msgbox.hxx>
      63             : #include <vcl/outdev.hxx>
      64             : #include <osl/mutex.hxx>
      65             : 
      66             : 
      67             : namespace svx
      68             : {
      69             : 
      70             : 
      71             :     using namespace ::com::sun::star;
      72             :     using namespace ::com::sun::star::uno;
      73             :     using namespace ::com::sun::star::awt;
      74             :     using namespace ::com::sun::star::form;
      75             :     using namespace ::com::sun::star::form::runtime;
      76             :     using namespace ::com::sun::star::lang;
      77             :     using namespace ::com::sun::star::frame;
      78             :     using namespace ::com::sun::star::util;
      79             :     using namespace ::com::sun::star::beans;
      80             :     using namespace ::com::sun::star::container;
      81             : 
      82             : 
      83             :     typedef sal_uInt16 WhichId;
      84             : 
      85             : 
      86             :     static SfxSlotId pTextControlSlots[] =
      87             :     {
      88             :         SID_CLIPBOARD_FORMAT_ITEMS,
      89             :         SID_CUT,
      90             :         SID_COPY,
      91             :         SID_PASTE,
      92             :         SID_SELECTALL,
      93             : //        SID_ATTR_TABSTOP,           /* 2 */
      94             :         SID_ATTR_CHAR_FONT,
      95             :         SID_ATTR_CHAR_POSTURE,
      96             :         SID_ATTR_CHAR_WEIGHT,
      97             :         SID_ATTR_CHAR_SHADOWED,
      98             :         SID_ATTR_CHAR_WORDLINEMODE,
      99             :         SID_ATTR_CHAR_CONTOUR,
     100             :         SID_ATTR_CHAR_STRIKEOUT,
     101             :         SID_ATTR_CHAR_UNDERLINE,
     102             :         SID_ATTR_CHAR_FONTHEIGHT,
     103             :         SID_ATTR_CHAR_COLOR,
     104             :         SID_ATTR_CHAR_KERNING,
     105             :         SID_ATTR_CHAR_LANGUAGE,     /* 20 */
     106             :         SID_ATTR_CHAR_ESCAPEMENT,
     107             :         SID_ATTR_PARA_ADJUST,       /* 28 */
     108             :         SID_ATTR_PARA_ADJUST_LEFT,
     109             :         SID_ATTR_PARA_ADJUST_RIGHT,
     110             :         SID_ATTR_PARA_ADJUST_CENTER,
     111             :         SID_ATTR_PARA_ADJUST_BLOCK,
     112             :         SID_ATTR_PARA_LINESPACE,    /* 33 */
     113             :         SID_ATTR_PARA_LINESPACE_10,
     114             :         SID_ATTR_PARA_LINESPACE_15,
     115             :         SID_ATTR_PARA_LINESPACE_20,
     116             :         SID_ATTR_LRSPACE,           /* 48 */
     117             :         SID_ATTR_ULSPACE,           /* 49 */
     118             :         SID_ATTR_CHAR_AUTOKERN,
     119             :         SID_SET_SUPER_SCRIPT,
     120             :         SID_SET_SUB_SCRIPT,
     121             :         SID_CHAR_DLG,
     122             :         SID_PARA_DLG,
     123             : //        SID_TEXTDIRECTION_LEFT_TO_RIGHT, /* 907 */
     124             : //        SID_TEXTDIRECTION_TOP_TO_BOTTOM,
     125             :         SID_ATTR_CHAR_SCALEWIDTH,       /* 911 */
     126             :         SID_ATTR_CHAR_RELIEF,
     127             :         SID_ATTR_PARA_LEFT_TO_RIGHT,    /* 950 */
     128             :         SID_ATTR_PARA_RIGHT_TO_LEFT,
     129             :         SID_ATTR_CHAR_OVERLINE,
     130             :         0
     131             :     };
     132             : 
     133             :     // slots which we are not responsible for on the SfxShell level, but
     134             :     // need to handle during the "paragraph attributes" and/or "character
     135             :     // attributes" dialogs
     136             :     static SfxSlotId pDialogSlots[] =
     137             :     {
     138             :         SID_ATTR_TABSTOP,
     139             :         SID_ATTR_PARA_HANGPUNCTUATION,
     140             :         SID_ATTR_PARA_FORBIDDEN_RULES,
     141             :         SID_ATTR_PARA_SCRIPTSPACE,
     142             :         SID_ATTR_CHAR_LATIN_LANGUAGE,
     143             :         SID_ATTR_CHAR_CJK_LANGUAGE,
     144             :         SID_ATTR_CHAR_CTL_LANGUAGE,
     145             :         SID_ATTR_CHAR_LATIN_FONT,
     146             :         SID_ATTR_CHAR_CJK_FONT,
     147             :         SID_ATTR_CHAR_CTL_FONT,
     148             :         SID_ATTR_CHAR_LATIN_FONTHEIGHT,
     149             :         SID_ATTR_CHAR_CJK_FONTHEIGHT,
     150             :         SID_ATTR_CHAR_CTL_FONTHEIGHT,
     151             :         SID_ATTR_CHAR_LATIN_WEIGHT,
     152             :         SID_ATTR_CHAR_CJK_WEIGHT,
     153             :         SID_ATTR_CHAR_CTL_WEIGHT,
     154             :         SID_ATTR_CHAR_LATIN_POSTURE,
     155             :         SID_ATTR_CHAR_CJK_POSTURE,
     156             :         SID_ATTR_CHAR_CTL_POSTURE,
     157             :         SID_ATTR_CHAR_EMPHASISMARK,
     158             :         0
     159             :     };
     160             : 
     161             :     typedef ::cppu::WeakImplHelper1 <   XFocusListener
     162             :                                     >   FmFocusListenerAdapter_Base;
     163             :     class FmFocusListenerAdapter : public FmFocusListenerAdapter_Base
     164             :     {
     165             :     private:
     166             :         IFocusObserver*         m_pObserver;
     167             :         Reference< XWindow >    m_xWindow;
     168             : 
     169             :     public:
     170             :         FmFocusListenerAdapter( const Reference< XControl >& _rxControl, IFocusObserver* _pObserver );
     171             : 
     172             :         // clean up the instance
     173             :         void    dispose();
     174             : 
     175             :     protected:
     176             :         virtual ~FmFocusListenerAdapter();
     177             : 
     178             :     protected:
     179             :         virtual void SAL_CALL focusGained( const FocusEvent& e ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     180             :         virtual void SAL_CALL focusLost( const FocusEvent& e ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     181             :         virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     182             :     };
     183             : 
     184             : 
     185             : 
     186           6 :     FmFocusListenerAdapter::FmFocusListenerAdapter( const Reference< XControl >& _rxControl, IFocusObserver* _pObserver )
     187             :         :m_pObserver( _pObserver )
     188           6 :         ,m_xWindow( _rxControl, UNO_QUERY )
     189             :     {
     190             : 
     191             :         DBG_ASSERT( m_xWindow.is(), "FmFocusListenerAdapter::FmFocusListenerAdapter: invalid control!" );
     192           6 :         osl_atomic_increment( &m_refCount );
     193             :         {
     194             :             try
     195             :             {
     196           6 :                 if ( m_xWindow.is() )
     197           6 :                     m_xWindow->addFocusListener( this );
     198             :             }
     199           0 :             catch( const Exception& )
     200             :             {
     201             :                 DBG_UNHANDLED_EXCEPTION();
     202             :             }
     203             :         }
     204           6 :         osl_atomic_decrement( &m_refCount );
     205           6 :     }
     206             : 
     207             : 
     208          18 :     FmFocusListenerAdapter::~FmFocusListenerAdapter()
     209             :     {
     210           6 :         acquire();
     211           6 :         dispose();
     212             : 
     213          12 :     }
     214             : 
     215             : 
     216          12 :     void FmFocusListenerAdapter::dispose()
     217             :     {
     218          12 :         if ( m_xWindow.is() )
     219             :         {
     220           6 :             m_xWindow->removeFocusListener( this );
     221           6 :             m_xWindow.clear();
     222             :         }
     223          12 :     }
     224             : 
     225             : 
     226           0 :     void SAL_CALL FmFocusListenerAdapter::focusGained( const FocusEvent& e ) throw (RuntimeException, std::exception)
     227             :     {
     228           0 :         if ( m_pObserver )
     229           0 :             m_pObserver->focusGained( e );
     230           0 :     }
     231             : 
     232             : 
     233           2 :     void SAL_CALL FmFocusListenerAdapter::focusLost( const FocusEvent& e ) throw (RuntimeException, std::exception)
     234             :     {
     235           2 :         if ( m_pObserver )
     236           2 :             m_pObserver->focusLost( e );
     237           2 :     }
     238             : 
     239             : 
     240           0 :     void SAL_CALL FmFocusListenerAdapter::disposing( const EventObject& Source ) throw (RuntimeException, std::exception)
     241             :     {
     242             :         (void)Source;
     243             :         DBG_ASSERT( Source.Source == m_xWindow, "FmFocusListenerAdapter::disposing: where did this come from?" );
     244           0 :         m_xWindow.clear();
     245           0 :     }
     246             : 
     247             :     typedef ::cppu::WeakImplHelper1 <   XMouseListener
     248             :                                     >   FmMouseListenerAdapter_Base;
     249             :     class FmMouseListenerAdapter : public FmMouseListenerAdapter_Base
     250             :     {
     251             :     private:
     252             :         IContextRequestObserver*  m_pObserver;
     253             :         Reference< XWindow >    m_xWindow;
     254             : 
     255             :     public:
     256             :         FmMouseListenerAdapter( const Reference< XControl >& _rxControl, IContextRequestObserver* _pObserver );
     257             : 
     258             :         // clean up the instance
     259             :         void    dispose();
     260             : 
     261             :     protected:
     262             :         virtual ~FmMouseListenerAdapter();
     263             : 
     264             :     protected:
     265             :         virtual void SAL_CALL mousePressed( const awt::MouseEvent& e ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     266             :         virtual void SAL_CALL mouseReleased( const awt::MouseEvent& e ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     267             :         virtual void SAL_CALL mouseEntered( const awt::MouseEvent& e ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     268             :         virtual void SAL_CALL mouseExited( const awt::MouseEvent& e ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     269             :         virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     270             :     };
     271             : 
     272           0 :     FmMouseListenerAdapter::FmMouseListenerAdapter( const Reference< XControl >& _rxControl, IContextRequestObserver* _pObserver )
     273             :         :m_pObserver( _pObserver )
     274           0 :         ,m_xWindow( _rxControl, UNO_QUERY )
     275             :     {
     276             : 
     277             :         DBG_ASSERT( m_xWindow.is(), "FmMouseListenerAdapter::FmMouseListenerAdapter: invalid control!" );
     278           0 :         osl_atomic_increment( &m_refCount );
     279             :         {
     280             :             try
     281             :             {
     282           0 :                 if ( m_xWindow.is() )
     283           0 :                     m_xWindow->addMouseListener( this );
     284             :             }
     285           0 :             catch( const Exception& )
     286             :             {
     287             :                 DBG_UNHANDLED_EXCEPTION();
     288             :             }
     289             :         }
     290           0 :         osl_atomic_decrement( &m_refCount );
     291           0 :     }
     292             : 
     293             : 
     294           0 :     FmMouseListenerAdapter::~FmMouseListenerAdapter()
     295             :     {
     296           0 :         acquire();
     297           0 :         dispose();
     298             : 
     299           0 :     }
     300             : 
     301             : 
     302           0 :     void FmMouseListenerAdapter::dispose()
     303             :     {
     304           0 :         if ( m_xWindow.is() )
     305             :         {
     306           0 :             m_xWindow->removeMouseListener( this );
     307           0 :             m_xWindow.clear();
     308             :         }
     309           0 :     }
     310             : 
     311             : 
     312           0 :     void SAL_CALL FmMouseListenerAdapter::mousePressed( const awt::MouseEvent& _rEvent ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     313             :     {
     314           0 :         SolarMutexGuard aGuard;
     315             :         // is this a request for a context menu?
     316           0 :         if ( _rEvent.PopupTrigger )
     317             :         {
     318           0 :             if ( m_pObserver )
     319           0 :                 m_pObserver->contextMenuRequested( _rEvent );
     320           0 :         }
     321           0 :     }
     322             : 
     323             : 
     324           0 :     void SAL_CALL FmMouseListenerAdapter::mouseReleased( const awt::MouseEvent& /*e*/ ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     325             :     {
     326             :         // not interested in
     327           0 :     }
     328             : 
     329             : 
     330           0 :     void SAL_CALL FmMouseListenerAdapter::mouseEntered( const awt::MouseEvent& /*e*/ ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     331             :     {
     332             :         // not interested in
     333           0 :     }
     334             : 
     335             : 
     336           0 :     void SAL_CALL FmMouseListenerAdapter::mouseExited( const awt::MouseEvent& /*e*/ ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     337             :     {
     338             :         // not interested in
     339           0 :     }
     340             : 
     341             : 
     342           0 :     void SAL_CALL FmMouseListenerAdapter::disposing( const EventObject& Source ) throw (RuntimeException, std::exception)
     343             :     {
     344             :         (void)Source;
     345             :         DBG_ASSERT( Source.Source == m_xWindow, "FmMouseListenerAdapter::disposing: where did this come from?" );
     346           0 :         m_xWindow.clear();
     347           0 :     }
     348             : 
     349             : 
     350             :     //= FmTextControlShell
     351             : 
     352             : 
     353             :     namespace
     354             :     {
     355             : 
     356           0 :         void lcl_translateUnoStateToItem( SfxSlotId _nSlot, const Any& _rUnoState, SfxItemSet& _rSet )
     357             :         {
     358           0 :             WhichId nWhich = _rSet.GetPool()->GetWhich( _nSlot );
     359           0 :             if ( !_rUnoState.hasValue() )
     360             :             {
     361           0 :                 if  ( ( _nSlot != SID_CUT )
     362           0 :                    && ( _nSlot != SID_COPY )
     363           0 :                    && ( _nSlot != SID_PASTE )
     364             :                     )
     365             :                 {
     366           0 :                     _rSet.InvalidateItem( nWhich );
     367             :                 }
     368             :             }
     369             :             else
     370             :             {
     371           0 :                 switch ( _rUnoState.getValueType().getTypeClass() )
     372             :                 {
     373             :                 case TypeClass_BOOLEAN:
     374             :                 {
     375           0 :                     bool bState = false;
     376           0 :                     _rUnoState >>= bState;
     377           0 :                     if ( _nSlot == SID_ATTR_PARA_SCRIPTSPACE )
     378           0 :                         _rSet.Put( SvxScriptSpaceItem( bState, nWhich ) );
     379             :                     else
     380           0 :                         _rSet.Put( SfxBoolItem( nWhich, bState ) );
     381             :                 }
     382           0 :                 break;
     383             : 
     384             :                 default:
     385             :                 {
     386           0 :                     Sequence< PropertyValue > aComplexState;
     387           0 :                     if ( _rUnoState >>= aComplexState )
     388             :                     {
     389           0 :                         if ( !aComplexState.getLength() )
     390           0 :                             _rSet.InvalidateItem( nWhich );
     391             :                         else
     392             :                         {
     393           0 :                             SfxAllItemSet aAllItems( _rSet );
     394           0 :                             TransformParameters( _nSlot, aComplexState, aAllItems );
     395           0 :                             const SfxPoolItem* pTransformed = aAllItems.GetItem( nWhich );
     396             :                             OSL_ENSURE( pTransformed, "lcl_translateUnoStateToItem: non-empty parameter sequence leading to empty item?" );
     397           0 :                             if ( pTransformed )
     398           0 :                                 _rSet.Put( *pTransformed );
     399             :                             else
     400           0 :                                 _rSet.InvalidateItem( nWhich );
     401             :                         }
     402             :                     }
     403             :                     else
     404             :                     {
     405             :                         OSL_FAIL( "lcl_translateUnoStateToItem: invalid state!" );
     406           0 :                     }
     407             :                 }
     408             :                 }
     409             :             }
     410           0 :         }
     411             : 
     412             : 
     413           0 :         OUString lcl_getUnoSlotName( SfxApplication&, SfxSlotId _nSlotId )
     414             :         {
     415           0 :             OUString sSlotUnoName;
     416             : 
     417           0 :             SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool( NULL );
     418           0 :             const SfxSlot* pSlot = rSlotPool.GetSlot( _nSlotId );
     419             : 
     420           0 :             const sal_Char* pAsciiUnoName = NULL;
     421           0 :             if ( pSlot )
     422             :             {
     423           0 :                 pAsciiUnoName = pSlot->GetUnoName();
     424             :             }
     425             :             else
     426             :             {
     427             :                 // some hard-coded slots, which do not have a UNO name at SFX level, but which
     428             :                 // we nevertheless need to transport via UNO mechanisms, so we need a name
     429           0 :                 switch ( _nSlotId )
     430             :                 {
     431           0 :                 case SID_ATTR_PARA_HANGPUNCTUATION: pAsciiUnoName = "AllowHangingPunctuation"; break;
     432           0 :                 case SID_ATTR_PARA_FORBIDDEN_RULES: pAsciiUnoName = "ApplyForbiddenCharacterRules"; break;
     433           0 :                 case SID_ATTR_PARA_SCRIPTSPACE: pAsciiUnoName = "UseScriptSpacing"; break;
     434             :                 }
     435             :             }
     436             : 
     437           0 :             if ( pAsciiUnoName )
     438             :             {
     439           0 :                 sSlotUnoName = ".uno:";
     440           0 :                 sSlotUnoName += OUString::createFromAscii( pAsciiUnoName );
     441             :             }
     442             : #if OSL_DEBUG_LEVEL > 0
     443             :             else
     444             :             {
     445             :                 OString sMessage( "lcl_getUnoSlotName: invalid slot id, or invalid slot, or no UNO name!\n" );
     446             :                 sMessage += "(slot id: ";
     447             :                 sMessage += OString::number( _nSlotId );
     448             :                 sMessage += ")";
     449             :                 OSL_FAIL( sMessage.getStr() );
     450             :             }
     451             : #endif
     452           0 :             return sSlotUnoName;
     453             :         }
     454             : 
     455             : 
     456           2 :         bool lcl_determineReadOnly( const Reference< XControl >& _rxControl )
     457             :         {
     458           2 :             bool bIsReadOnlyModel = true;
     459             :             try
     460             :             {
     461           2 :                 Reference< XPropertySet > xModelProps;
     462           2 :                 if ( _rxControl.is() )
     463           2 :                     xModelProps.set(_rxControl->getModel(), css::uno::UNO_QUERY);
     464           4 :                 Reference< XPropertySetInfo > xModelPropInfo;
     465           2 :                 if ( xModelProps.is() )
     466           2 :                     xModelPropInfo = xModelProps->getPropertySetInfo();
     467             : 
     468           2 :                 if ( !xModelPropInfo.is() || !xModelPropInfo->hasPropertyByName( FM_PROP_READONLY ) )
     469           2 :                     bIsReadOnlyModel = true;
     470             :                 else
     471             :                 {
     472           0 :                     bool bReadOnly = true;
     473           0 :                     xModelProps->getPropertyValue( FM_PROP_READONLY ) >>= bReadOnly;
     474           0 :                     bIsReadOnlyModel = bReadOnly;
     475           2 :                 }
     476             :             }
     477           0 :             catch( const Exception& )
     478             :             {
     479             :                 DBG_UNHANDLED_EXCEPTION();
     480             :             }
     481           2 :             return bIsReadOnlyModel;
     482             :         }
     483             : 
     484             : 
     485           0 :         static vcl::Window* lcl_getWindow( const Reference< XControl >& _rxControl )
     486             :         {
     487           0 :             vcl::Window* pWindow = NULL;
     488             :             try
     489             :             {
     490           0 :                 Reference< XWindowPeer > xControlPeer;
     491           0 :                 if ( _rxControl.is() )
     492           0 :                     xControlPeer = _rxControl->getPeer();
     493           0 :                 if ( xControlPeer.is() )
     494           0 :                     pWindow = VCLUnoHelper::GetWindow( xControlPeer );
     495             :             }
     496           0 :             catch( const Exception& )
     497             :             {
     498             :                 DBG_UNHANDLED_EXCEPTION();
     499             :             }
     500             : 
     501           0 :             return pWindow;
     502             :         }
     503             : 
     504             : 
     505           2 :         bool lcl_isRichText( const Reference< XControl >& _rxControl )
     506             :         {
     507           2 :             if ( !_rxControl.is() )
     508           0 :                 return false;
     509             : 
     510           2 :             bool bIsRichText = false;
     511             :             try
     512             :             {
     513           2 :                 Reference< XPropertySet > xModelProps( _rxControl->getModel(), UNO_QUERY );
     514           4 :                 Reference< XPropertySetInfo > xPSI;
     515           2 :                 if ( xModelProps.is() )
     516           2 :                     xPSI = xModelProps->getPropertySetInfo();
     517           4 :                 OUString sRichTextPropertyName = "RichText";
     518           2 :                 if ( xPSI.is() && xPSI->hasPropertyByName( sRichTextPropertyName ) )
     519             :                 {
     520           0 :                     OSL_VERIFY( xModelProps->getPropertyValue( sRichTextPropertyName ) >>= bIsRichText );
     521           2 :                 }
     522             :             }
     523           0 :             catch( const Exception& )
     524             :             {
     525             :                 DBG_UNHANDLED_EXCEPTION();
     526             :             }
     527           2 :             return bIsRichText;
     528             :         }
     529             :     }
     530             : 
     531             : 
     532        5452 :     FmTextControlShell::FmTextControlShell( SfxViewFrame* _pFrame )
     533             :         :m_bActiveControl( false )
     534             :         ,m_bActiveControlIsReadOnly( true )
     535             :         ,m_bActiveControlIsRichText( false )
     536             :         ,m_pViewFrame( _pFrame )
     537        5452 :         ,m_rBindings( _pFrame->GetBindings() )
     538       10904 :         ,m_bNeedClipboardInvalidation( true )
     539             :     {
     540        5452 :         m_aClipboardInvalidation.SetTimeoutHdl( LINK( this, FmTextControlShell, OnInvalidateClipboard ) );
     541        5452 :         m_aClipboardInvalidation.SetTimeout( 200 );
     542        5452 :     }
     543             : 
     544             : 
     545       16350 :     FmTextControlShell::~FmTextControlShell()
     546             :     {
     547        5450 :         dispose();
     548       10900 :     }
     549             : 
     550             : 
     551           0 :     IMPL_LINK( FmTextControlShell, OnInvalidateClipboard, void*, /*_pNotInterestedIn*/ )
     552             :     {
     553           0 :         if ( m_bNeedClipboardInvalidation )
     554             :         {
     555             :             OSL_TRACE( "FmTextControlShell::ClipBoard: invalidating clipboard slots" );
     556           0 :             m_rBindings.Invalidate( SID_CUT );
     557           0 :             m_rBindings.Invalidate( SID_COPY );
     558           0 :             m_rBindings.Invalidate( SID_PASTE );
     559           0 :             m_bNeedClipboardInvalidation = false;
     560             :         }
     561           0 :         return 0L;
     562             :     }
     563             : 
     564             : 
     565           0 :     void FmTextControlShell::transferFeatureStatesToItemSet( ControlFeatures& _rDispatchers, SfxAllItemSet& _rSet, bool _bTranslateLatin )
     566             :     {
     567           0 :         SfxItemPool& rPool = *_rSet.GetPool();
     568             : 
     569           0 :         for (   ControlFeatures::const_iterator aFeature = _rDispatchers.begin();
     570           0 :                 aFeature != _rDispatchers.end();
     571             :                 ++aFeature
     572             :             )
     573             :         {
     574           0 :             SfxSlotId nSlotId( aFeature->first );
     575             :             #if OSL_DEBUG_LEVEL > 0
     576             :                 OUString sUnoSlotName;
     577             :                 if ( SfxGetpApp() )
     578             :                     sUnoSlotName = lcl_getUnoSlotName( *SfxGetpApp(), nSlotId );
     579             :                 else
     580             :                     sUnoSlotName = "<unknown>";
     581             :                 OString sUnoSlotNameAscii( "\"" );
     582             :                 sUnoSlotNameAscii += OString( sUnoSlotName.getStr(), sUnoSlotName.getLength(), RTL_TEXTENCODING_ASCII_US );
     583             :                 sUnoSlotNameAscii += "\"";
     584             :             #endif
     585             : 
     586           0 :             if ( _bTranslateLatin )
     587             :             {
     588             :                 // A rich text control offers a dispatcher for the "Font" slot/feature.
     589             :                 // Sadly, the semantics of the dispatches is that the feature "Font" depends
     590             :                 // on the current cursor position: If it's on latin text, it's the "latin font"
     591             :                 // which is set up at the control. If it's on CJK text, it's the "CJK font", and
     592             :                 // aequivalent for "CTL font".
     593             :                 // The same holds for some other font related features/slots.
     594             :                 // Thus, we have separate dispatches for "Latin Font", "Latin Font Size", etc,
     595             :                 // which are only "virtual", in a sense that there exist no item with this id.
     596             :                 // So when we encounter such a dispatcher for, say, "Latin Font", we need to
     597             :                 // put an item into the set which has the "Font" id.
     598             : 
     599           0 :                 switch ( nSlotId )
     600             :                 {
     601           0 :                 case SID_ATTR_CHAR_LATIN_FONT:      nSlotId = SID_ATTR_CHAR_FONT; break;
     602           0 :                 case SID_ATTR_CHAR_LATIN_FONTHEIGHT:nSlotId = SID_ATTR_CHAR_FONTHEIGHT; break;
     603           0 :                 case SID_ATTR_CHAR_LATIN_LANGUAGE:  nSlotId = SID_ATTR_CHAR_LANGUAGE; break;
     604           0 :                 case SID_ATTR_CHAR_LATIN_POSTURE:   nSlotId = SID_ATTR_CHAR_POSTURE; break;
     605           0 :                 case SID_ATTR_CHAR_LATIN_WEIGHT:    nSlotId = SID_ATTR_CHAR_WEIGHT; break;
     606             :                 }
     607             :             }
     608             : 
     609           0 :             WhichId nWhich = rPool.GetWhich( nSlotId );
     610           0 :             bool bIsInPool = rPool.IsInRange( nWhich );
     611           0 :             if ( bIsInPool )
     612             :             {
     613             :                 #if OSL_DEBUG_LEVEL > 0
     614             :                     bool bFeatureIsEnabled = aFeature->second->isFeatureEnabled();
     615             :                     OString sMessage( "FmTextControlShell::transferFeatureStatesToItemSet: found a feature state for " );
     616             :                     sMessage += sUnoSlotNameAscii;
     617             :                     if ( !bFeatureIsEnabled )
     618             :                         sMessage += " (disabled)";
     619             :                     OSL_TRACE( "%s", sMessage.getStr() );
     620             :                 #endif
     621             : 
     622           0 :                 lcl_translateUnoStateToItem( nSlotId, aFeature->second->getFeatureState(), _rSet );
     623             :             }
     624             :             #if OSL_DEBUG_LEVEL > 0
     625             :             else
     626             :             {
     627             :                 OString sMessage( "FmTextControlShell::transferFeatureStatesToItemSet: found a feature state for " );
     628             :                 sMessage += sUnoSlotNameAscii;
     629             :                 sMessage += ", but could not translate it into an item!";
     630             :                 OSL_TRACE( "%s", sMessage.getStr() );
     631             :             }
     632             :             #endif
     633             :         }
     634           0 :     }
     635             : 
     636             : 
     637           0 :     void FmTextControlShell::executeAttributeDialog( AttributeSet _eSet, SfxRequest& _rReq )
     638             :     {
     639           0 :         const SvxFontListItem* pFontList = PTR_CAST( SvxFontListItem, m_pViewFrame->GetObjectShell()->GetItem( SID_ATTR_CHAR_FONTLIST ) );
     640             :         DBG_ASSERT( pFontList, "FmTextControlShell::executeAttributeDialog: no font list item!" );
     641           0 :         if ( !pFontList )
     642           0 :             return;
     643             : 
     644           0 :         SfxItemPool* pPool = EditEngine::CreatePool();
     645           0 :         pPool->FreezeIdRanges();
     646           0 :         boost::scoped_ptr< SfxItemSet > xPureItems( new SfxItemSet( *pPool ) );
     647             : 
     648             :         // put the current states of the items into the set
     649           0 :         boost::scoped_ptr<SfxAllItemSet> xCurrentItems( new SfxAllItemSet( *xPureItems ) );
     650           0 :         transferFeatureStatesToItemSet( m_aControlFeatures, *xCurrentItems );
     651             : 
     652             :         // additional items, which we are not responsible for at the SfxShell level,
     653             :         // but which need to be forwarded to the dialog, anyway
     654           0 :         ControlFeatures aAdditionalFestures;
     655           0 :         fillFeatureDispatchers( m_xActiveControl, pDialogSlots, aAdditionalFestures );
     656           0 :         transferFeatureStatesToItemSet( aAdditionalFestures, *xCurrentItems, true );
     657             : 
     658             :         boost::scoped_ptr<SfxTabDialog> xDialog ( _eSet == eCharAttribs
     659           0 :                                                 ? static_cast< SfxTabDialog* >( new TextControlCharAttribDialog( NULL, *xCurrentItems, *pFontList ) )
     660           0 :                                                 : static_cast< SfxTabDialog* >( new TextControlParaAttribDialog( NULL, *xCurrentItems ) ) );
     661           0 :         if ( RET_OK == xDialog->Execute() )
     662             :         {
     663           0 :             const SfxItemSet& rModifiedItems = *xDialog->GetOutputItemSet();
     664           0 :             for ( WhichId nWhich = pPool->GetFirstWhich(); nWhich <= pPool->GetLastWhich(); ++nWhich )
     665             :             {
     666           0 :                 if ( rModifiedItems.GetItemState( nWhich ) == SfxItemState::SET )
     667             :                 {
     668           0 :                     SfxSlotId nSlotForItemSet = pPool->GetSlotId( nWhich );
     669           0 :                     const SfxPoolItem* pModifiedItem = rModifiedItems.GetItem( nWhich );
     670             : 
     671             : 
     672           0 :                     SfxSlotId nSlotForDispatcher = nSlotForItemSet;
     673           0 :                     switch ( nSlotForDispatcher )
     674             :                     {
     675           0 :                         case SID_ATTR_CHAR_FONT:      nSlotForDispatcher = SID_ATTR_CHAR_LATIN_FONT; break;
     676           0 :                         case SID_ATTR_CHAR_FONTHEIGHT:nSlotForDispatcher = SID_ATTR_CHAR_LATIN_FONTHEIGHT; break;
     677           0 :                         case SID_ATTR_CHAR_LANGUAGE:  nSlotForDispatcher = SID_ATTR_CHAR_LATIN_LANGUAGE; break;
     678           0 :                         case SID_ATTR_CHAR_POSTURE:   nSlotForDispatcher = SID_ATTR_CHAR_LATIN_POSTURE; break;
     679           0 :                         case SID_ATTR_CHAR_WEIGHT:    nSlotForDispatcher = SID_ATTR_CHAR_LATIN_WEIGHT; break;
     680             :                     }
     681             : 
     682             :                     // do we already have a dispatcher for this slot/feature?
     683           0 :                     ControlFeatures::const_iterator aFeaturePos = m_aControlFeatures.find( nSlotForDispatcher );
     684           0 :                     bool bFound = aFeaturePos != m_aControlFeatures.end( );
     685             : 
     686           0 :                     if ( !bFound )
     687             :                     {
     688           0 :                         aFeaturePos = aAdditionalFestures.find( nSlotForDispatcher );
     689           0 :                         bFound = aFeaturePos != aAdditionalFestures.end( );
     690             :                     }
     691             : 
     692           0 :                     if ( bFound )
     693             :                     {
     694           0 :                         Sequence< PropertyValue > aArgs;
     695             :                         // temporarily put the modified item into a "clean" set,
     696             :                         // and let TransformItems calc the respective UNO parameters
     697           0 :                         xPureItems->Put( *pModifiedItem );
     698           0 :                         TransformItems( nSlotForItemSet, *xPureItems, aArgs );
     699           0 :                         xPureItems->ClearItem( nWhich );
     700             : 
     701           0 :                         if  (   ( nSlotForItemSet == SID_ATTR_PARA_HANGPUNCTUATION )
     702           0 :                             ||  ( nSlotForItemSet == SID_ATTR_PARA_FORBIDDEN_RULES )
     703           0 :                             ||  ( nSlotForItemSet == SID_ATTR_PARA_SCRIPTSPACE )
     704             :                             )
     705             :                         {
     706             :                             // these are no UNO slots, they need special handling since TransformItems cannot
     707             :                             // handle them
     708             :                             DBG_ASSERT( aArgs.getLength() == 0, "FmTextControlShell::executeAttributeDialog: these are no UNO slots - are they?" );
     709             : 
     710           0 :                             const SfxBoolItem* pBoolItem = PTR_CAST( SfxBoolItem, pModifiedItem );
     711             :                             DBG_ASSERT( pBoolItem, "FmTextControlShell::executeAttributeDialog: no bool item?!" );
     712           0 :                             if ( pBoolItem )
     713             :                             {
     714           0 :                                 aArgs.realloc( 1 );
     715           0 :                                 aArgs[ 0 ].Name = "Enable";
     716           0 :                                 aArgs[ 0 ].Value <<= pBoolItem->GetValue();
     717             :                             }
     718             :                         }
     719             : 
     720             :                         // dispatch this
     721           0 :                         aFeaturePos->second->dispatch( aArgs );
     722             :                     }
     723             :                 #if OSL_DEBUG_LEVEL > 0
     724             :                     else
     725             :                     {
     726             :                         OString sError( "FmTextControShell::executeAttributeDialog: Could not handle the following item:" );
     727             :                         sError += "\n  SlotID: "; sError += OString::number( nSlotForItemSet );
     728             :                         sError += "\n  WhichID: "; sError += OString::number( nWhich );
     729             :                         sError += "\n  UNO name: ";
     730             : 
     731             :                         OUString sUnoSlotName = lcl_getUnoSlotName( *SfxGetpApp(), nSlotForItemSet );
     732             :                         if ( !sUnoSlotName.isEmpty() )
     733             :                             sError += OString( sUnoSlotName.getStr(), sUnoSlotName.getLength(), RTL_TEXTENCODING_ASCII_US );
     734             :                         else
     735             :                             sError += "unknown (no SfxSlot)";
     736             :                         OSL_FAIL( sError.getStr() );
     737             :                     }
     738             :                 #endif
     739             :                 }
     740             :             }
     741           0 :             _rReq.Done( rModifiedItems );
     742             :         }
     743             : 
     744           0 :         xDialog.reset();
     745           0 :         xCurrentItems.reset();
     746           0 :         xPureItems.reset();
     747           0 :         SfxItemPool::Free(pPool);
     748             :     }
     749             : 
     750             : 
     751           0 :     bool FmTextControlShell::executeSelectAll( )
     752             :     {
     753             :         try
     754             :         {
     755           0 :             if ( m_xActiveTextComponent.is() )
     756             :             {
     757           0 :                 sal_Int32 nTextLen = m_xActiveTextComponent->getText().getLength();
     758           0 :                 m_xActiveTextComponent->setSelection( awt::Selection( 0, nTextLen ) );
     759           0 :                 return true;
     760             :             }
     761             :         }
     762           0 :         catch( const Exception& )
     763             :         {
     764             :             DBG_UNHANDLED_EXCEPTION();
     765             :         }
     766           0 :         return false;   // not handled
     767             :     }
     768             : 
     769             : 
     770           0 :     bool FmTextControlShell::executeClipboardSlot( SfxSlotId _nSlot )
     771             :     {
     772             :         try
     773             :         {
     774           0 :             if ( m_xActiveTextComponent.is() )
     775             :             {
     776           0 :                 switch ( _nSlot )
     777             :                 {
     778             :                 case SID_COPY:
     779             :                 case SID_CUT:
     780             :                 {
     781           0 :                     OUString sSelectedText( m_xActiveTextComponent->getSelectedText() );
     782           0 :                     ::svt::OStringTransfer::CopyString( sSelectedText, lcl_getWindow( m_xActiveControl ) );
     783           0 :                     if ( SID_CUT == _nSlot )
     784             :                     {
     785           0 :                         awt::Selection aSelection( m_xActiveTextComponent->getSelection() );
     786           0 :                         m_xActiveTextComponent->insertText( aSelection, OUString() );
     787           0 :                     }
     788             :                 }
     789           0 :                 break;
     790             :                 case SID_PASTE:
     791             :                 {
     792           0 :                     OUString sClipboardContent;
     793           0 :                     OSL_VERIFY( ::svt::OStringTransfer::PasteString( sClipboardContent, lcl_getWindow( m_xActiveControl ) ) );
     794           0 :                     awt::Selection aSelection( m_xActiveTextComponent->getSelection() );
     795           0 :                     m_xActiveTextComponent->insertText( aSelection, sClipboardContent );
     796             :                 }
     797           0 :                 break;
     798             :                 default:
     799             :                     OSL_FAIL( "FmTextControlShell::executeClipboardSlot: invalid slot!" );
     800             :                 }
     801           0 :                 return true;
     802             :             }
     803             :         }
     804           0 :         catch( const Exception& )
     805             :         {
     806             :             DBG_UNHANDLED_EXCEPTION();
     807             :         }
     808           0 :         return false;   // not handled
     809             :     }
     810             : 
     811             : 
     812           0 :     void FmTextControlShell::ExecuteTextAttribute( SfxRequest& _rReq )
     813             :     {
     814           0 :         SfxSlotId nSlot = _rReq.GetSlot();
     815             : 
     816           0 :         ControlFeatures::const_iterator aFeaturePos = m_aControlFeatures.find( nSlot );
     817           0 :         if ( aFeaturePos == m_aControlFeatures.end() )
     818             :         {
     819             :             // special slots
     820           0 :             switch ( nSlot )
     821             :             {
     822             :             case SID_CHAR_DLG:
     823           0 :                 executeAttributeDialog( eCharAttribs, _rReq );
     824           0 :                 break;
     825             : 
     826             :             case SID_PARA_DLG:
     827           0 :                 executeAttributeDialog( eParaAttribs, _rReq );
     828           0 :                 break;
     829             : 
     830             :             case SID_SELECTALL:
     831           0 :                 executeSelectAll();
     832           0 :                 break;
     833             : 
     834             :             case SID_CUT:
     835             :             case SID_COPY:
     836             :             case SID_PASTE:
     837           0 :                 executeClipboardSlot( nSlot );
     838           0 :                 break;
     839             : 
     840             :             default:
     841             :                 DBG_ASSERT( aFeaturePos != m_aControlFeatures.end(), "FmTextControShell::ExecuteTextAttribute: I have no such dispatcher, and cannot handle it at all!" );
     842           0 :                 return;
     843             :             }
     844             :         }
     845             :         else
     846             :         {
     847             :             // slots which are dispatched to the control
     848             : 
     849           0 :             switch ( nSlot )
     850             :             {
     851             :             case SID_ATTR_CHAR_STRIKEOUT:
     852             :             case SID_ATTR_CHAR_UNDERLINE:
     853             :             case SID_ATTR_CHAR_OVERLINE:
     854             :             {
     855           0 :                 SfxItemSet aToggled( *_rReq.GetArgs() );
     856             : 
     857           0 :                 lcl_translateUnoStateToItem( nSlot, aFeaturePos->second->getFeatureState(), aToggled );
     858           0 :                 WhichId nWhich = aToggled.GetPool()->GetWhich( nSlot );
     859           0 :                 const SfxPoolItem* pItem = aToggled.GetItem( nWhich );
     860           0 :                 if ( ( SID_ATTR_CHAR_UNDERLINE == nSlot ) || ( SID_ATTR_CHAR_OVERLINE == nSlot ) )
     861             :                 {
     862           0 :                     const SvxOverlineItem* pTextLine = PTR_CAST( SvxOverlineItem, pItem );
     863             :                     DBG_ASSERT( pTextLine, "FmTextControlShell::ExecuteTextAttribute: ooops - no underline/overline item!" );
     864           0 :                     if ( pTextLine )
     865             :                     {
     866           0 :                         FontUnderline eTL = pTextLine->GetLineStyle();
     867           0 :                         if ( SID_ATTR_CHAR_UNDERLINE == nSlot ) {
     868           0 :                             aToggled.Put( SvxUnderlineItem( eTL == UNDERLINE_SINGLE ? UNDERLINE_NONE : UNDERLINE_SINGLE, nWhich ) );
     869             :                         } else {
     870           0 :                             aToggled.Put( SvxOverlineItem( eTL == UNDERLINE_SINGLE ? UNDERLINE_NONE : UNDERLINE_SINGLE, nWhich ) );
     871             :                         }
     872           0 :                     }
     873             :                 }
     874             :                 else
     875             :                 {
     876           0 :                     const SvxCrossedOutItem* pCrossedOut = PTR_CAST( SvxCrossedOutItem, pItem );
     877             :                     DBG_ASSERT( pCrossedOut, "FmTextControlShell::ExecuteTextAttribute: ooops - no CrossedOut item!" );
     878           0 :                     if ( pCrossedOut )
     879             :                     {
     880           0 :                         FontStrikeout eFS = pCrossedOut->GetStrikeout();
     881           0 :                         aToggled.Put( SvxCrossedOutItem( eFS == STRIKEOUT_SINGLE ? STRIKEOUT_NONE : STRIKEOUT_SINGLE, nWhich ) );
     882             :                     }
     883             :                 }
     884             : 
     885           0 :                 Sequence< PropertyValue > aArguments;
     886           0 :                 TransformItems( nSlot, aToggled, aArguments );
     887           0 :                 aFeaturePos->second->dispatch( aArguments );
     888             :             }
     889           0 :             break;
     890             : 
     891             :             case SID_ATTR_CHAR_FONTHEIGHT:
     892             :             case SID_ATTR_CHAR_FONT:
     893             :             case SID_ATTR_CHAR_POSTURE:
     894             :             case SID_ATTR_CHAR_WEIGHT:
     895             :             case SID_ATTR_CHAR_SHADOWED:
     896             :             case SID_ATTR_CHAR_CONTOUR:
     897             :             case SID_SET_SUPER_SCRIPT:
     898             :             case SID_SET_SUB_SCRIPT:
     899             :             {
     900           0 :                 const SfxItemSet* pArgs = _rReq.GetArgs();
     901           0 :                 Sequence< PropertyValue > aArgs;
     902           0 :                 if ( pArgs )
     903           0 :                     TransformItems( nSlot, *pArgs, aArgs );
     904           0 :                 aFeaturePos->second->dispatch( aArgs );
     905             :             }
     906           0 :             break;
     907             : 
     908             :             default:
     909           0 :                 if ( aFeaturePos->second->isFeatureEnabled() )
     910           0 :                     aFeaturePos->second->dispatch();
     911           0 :                 break;
     912             :             }
     913             :         }
     914           0 :         _rReq.Done();
     915             :     }
     916             : 
     917             : 
     918           2 :     void FmTextControlShell::GetTextAttributeState( SfxItemSet& _rSet )
     919             :     {
     920           2 :         SfxWhichIter aIter( _rSet );
     921           2 :         sal_uInt16 nSlot = aIter.FirstWhich();
     922           6 :         while ( nSlot )
     923             :         {
     924           2 :             if  (   ( nSlot == SID_ATTR_PARA_LEFT_TO_RIGHT )
     925           2 :                 ||  ( nSlot == SID_ATTR_PARA_RIGHT_TO_LEFT )
     926             :                 )
     927             :             {
     928           0 :                 if ( !SvtLanguageOptions().IsCTLFontEnabled() )
     929             :                 {
     930           0 :                     _rSet.DisableItem( nSlot );
     931           0 :                     nSlot = aIter.NextWhich();
     932           0 :                     continue;
     933             :                 }
     934             :             }
     935             : 
     936           2 :             ControlFeatures::const_iterator aFeaturePos = m_aControlFeatures.find( nSlot );
     937           2 :             if ( aFeaturePos != m_aControlFeatures.end() )
     938             :             {
     939           0 :                 if ( aFeaturePos->second->isFeatureEnabled() )
     940           0 :                     lcl_translateUnoStateToItem( nSlot, aFeaturePos->second->getFeatureState(), _rSet );
     941             :                 else
     942           0 :                     _rSet.DisableItem( nSlot );
     943             :             }
     944             :             else
     945             :             {
     946           2 :                 bool bDisable = false;
     947             : 
     948           2 :                 bool bNeedWriteableControl = false;
     949           2 :                 bool bNeedTextComponent = false;
     950           2 :                 bool bNeedSelection = false;
     951             : 
     952           2 :                 switch ( nSlot )
     953             :                 {
     954             :                 case SID_CHAR_DLG:
     955             :                 case SID_PARA_DLG:
     956           0 :                     bDisable |= m_aControlFeatures.empty();
     957           0 :                     bNeedWriteableControl = true;
     958           0 :                     break;
     959             : 
     960             :                 case SID_CUT:
     961           0 :                     bNeedSelection = true;
     962           0 :                     bNeedTextComponent = true;
     963           0 :                     bNeedWriteableControl = true;
     964             :                     OSL_TRACE( "FmTextControlShell::ClipBoard: need to invalidate again" );
     965           0 :                     m_bNeedClipboardInvalidation = true;
     966           0 :                     break;
     967             : 
     968             :                 case SID_PASTE:
     969             :                 {
     970           0 :                     vcl::Window* pActiveControlVCLWindow = lcl_getWindow( m_xActiveControl );
     971           0 :                     if ( pActiveControlVCLWindow )
     972             :                     {
     973           0 :                         TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( pActiveControlVCLWindow) );
     974           0 :                         bDisable |= !aDataHelper.HasFormat( SOT_FORMAT_STRING );
     975             :                     }
     976             :                     else
     977           0 :                         bDisable |= true;
     978             : 
     979           0 :                     bNeedTextComponent = true;
     980           0 :                     bNeedWriteableControl = true;
     981             :                 }
     982           0 :                 break;
     983             : 
     984             :                 case SID_COPY:
     985           2 :                     bNeedTextComponent = true;
     986           2 :                     bNeedSelection = true;
     987           2 :                     break;
     988             : 
     989             :                 case SID_SELECTALL:
     990           0 :                     bNeedTextComponent = true;
     991           0 :                     break;
     992             : 
     993             :                 default:
     994             :                     // slot is unknown at all
     995           0 :                     bDisable |= true;
     996           0 :                     break;
     997             :                 }
     998             :                 SAL_WARN_IF( bNeedSelection && !bNeedTextComponent, "svx.form", "FmTextControlShell::GetTextAttributeState: bNeedSelection should imply bNeedTextComponent!" );
     999             : 
    1000           2 :                 if ( !bDisable && bNeedWriteableControl )
    1001           0 :                     bDisable |= !IsActiveControl( ) || m_bActiveControlIsReadOnly;
    1002             : 
    1003           2 :                 if ( !bDisable && bNeedTextComponent )
    1004           2 :                     bDisable |= !m_xActiveTextComponent.is();
    1005             : 
    1006           2 :                 if ( !bDisable && bNeedSelection )
    1007             :                 {
    1008           0 :                     awt::Selection aSelection = m_xActiveTextComponent->getSelection();
    1009           0 :                     bDisable |= aSelection.Min == aSelection.Max;
    1010             :                 }
    1011             : 
    1012           2 :                 if ( bDisable )
    1013           2 :                     _rSet.DisableItem( nSlot );
    1014             :             }
    1015             : 
    1016           2 :             nSlot = aIter.NextWhich();
    1017           2 :         }
    1018           2 :     }
    1019             : 
    1020             : 
    1021       41938 :     bool FmTextControlShell::IsActiveControl( bool _bCountRichTextOnly ) const
    1022             :     {
    1023       41938 :         if ( _bCountRichTextOnly && !m_bActiveControlIsRichText )
    1024        7237 :             return false;
    1025             : 
    1026       34701 :         return m_bActiveControl;
    1027             :     }
    1028             : 
    1029             : 
    1030       10900 :     void FmTextControlShell::dispose()
    1031             :     {
    1032       10900 :         if ( IsActiveControl() )
    1033           0 :             controlDeactivated();
    1034       10900 :         if ( isControllerListening() )
    1035           0 :             stopControllerListening();
    1036       10900 :     }
    1037             : 
    1038             : 
    1039        5498 :     void FmTextControlShell::designModeChanged( bool /*_bNewDesignMode*/ )
    1040             :     {
    1041        5498 :         m_rBindings.Invalidate( pTextControlSlots );
    1042        5498 :     }
    1043             : 
    1044             : 
    1045           2 :     void FmTextControlShell::formActivated( const Reference< runtime::XFormController >& _rxController )
    1046             :     {
    1047             : #if OSL_DEBUG_LEVEL > 0
    1048             :         OString sTrace( "FmTextControlShell::formActivated: 0x" );
    1049             :         sTrace += OString::number( reinterpret_cast<sal_IntPtr>(_rxController.get()), 16 );
    1050             :         OSL_TRACE( "%s", sTrace.getStr() );
    1051             : #endif
    1052             : 
    1053             :         DBG_ASSERT( _rxController.is(), "FmTextControlShell::formActivated: invalid controller!" );
    1054           2 :         if ( !_rxController.is() )
    1055           0 :             return;
    1056             : 
    1057             :         // sometimes, a form controller notifies activations, even if it's already activated
    1058           2 :         if ( m_xActiveController == _rxController )
    1059           0 :             return;
    1060             : 
    1061             :         try
    1062             :         {
    1063           2 :             startControllerListening( _rxController );
    1064           2 :             controlActivated( _rxController->getCurrentControl() );
    1065             :         }
    1066           0 :         catch( const Exception& )
    1067             :         {
    1068             :             DBG_UNHANDLED_EXCEPTION();
    1069             :         }
    1070             :     }
    1071             : 
    1072             : 
    1073           2 :     void FmTextControlShell::formDeactivated( const Reference< runtime::XFormController >& _rxController )
    1074             :     {
    1075             : #if OSL_DEBUG_LEVEL > 0
    1076             :         OString sTrace( "FmTextControlShell::formDeactivated: 0x" );
    1077             :         sTrace += OString::number( reinterpret_cast<sal_IntPtr>(_rxController.get()), 16 );
    1078             :         OSL_TRACE( "%s", sTrace.getStr() );
    1079             : #endif
    1080             :         (void)_rxController;
    1081             : 
    1082           2 :         if ( IsActiveControl() )
    1083           0 :             controlDeactivated();
    1084           2 :         if ( isControllerListening() )
    1085           2 :             stopControllerListening();
    1086           2 :     }
    1087             : 
    1088             : 
    1089           2 :     void FmTextControlShell::startControllerListening( const Reference< runtime::XFormController >& _rxController )
    1090             :     {
    1091             :         OSL_PRECOND( _rxController.is(), "FmTextControlShell::startControllerListening: invalid controller!" );
    1092           2 :         if ( !_rxController.is() )
    1093           2 :             return;
    1094             : 
    1095             :         OSL_PRECOND( !isControllerListening(), "FmTextControlShell::startControllerListening: already listening!" );
    1096           2 :         if ( isControllerListening() )
    1097           0 :             stopControllerListening( );
    1098             :         DBG_ASSERT( !isControllerListening(), "FmTextControlShell::startControllerListening: inconsistence!" );
    1099             : 
    1100             :         try
    1101             :         {
    1102           2 :             Sequence< Reference< XControl > > aControls( _rxController->getControls() );
    1103           2 :             m_aControlObservers.resize( 0 );
    1104           2 :             m_aControlObservers.reserve( aControls.getLength() );
    1105             : 
    1106           2 :             const Reference< XControl >* pControls = aControls.getConstArray();
    1107           2 :             const Reference< XControl >* pControlsEnd = pControls + aControls.getLength();
    1108           8 :             for ( ; pControls != pControlsEnd; ++pControls )
    1109             :             {
    1110           6 :                 m_aControlObservers.push_back( FocusListenerAdapter( new FmFocusListenerAdapter( *pControls, this ) ) );
    1111           2 :             }
    1112             :         }
    1113           0 :         catch( const Exception& )
    1114             :         {
    1115             :             DBG_UNHANDLED_EXCEPTION();
    1116             :         }
    1117             : 
    1118           2 :         m_xActiveController = _rxController;
    1119             :     }
    1120             : 
    1121             : 
    1122           2 :     void FmTextControlShell::stopControllerListening( )
    1123             :     {
    1124             :         OSL_PRECOND( isControllerListening(), "FmTextControlShell::stopControllerListening: inconsistence!" );
    1125             : 
    1126             :         // dispose all listeners associated with the controls of the active controller
    1127          24 :         for (   FocusListenerAdapters::iterator aLoop = m_aControlObservers.begin();
    1128          16 :                 aLoop != m_aControlObservers.end();
    1129             :                 ++aLoop
    1130             :             )
    1131             :         {
    1132           6 :             (*aLoop)->dispose();
    1133             :         }
    1134             : 
    1135           2 :         FocusListenerAdapters aEmpty;
    1136           2 :         m_aControlObservers.swap( aEmpty );
    1137             : 
    1138           2 :         m_xActiveController.clear();
    1139           2 :     }
    1140             : 
    1141             : 
    1142         605 :     void FmTextControlShell::implClearActiveControlRef()
    1143             :     {
    1144             :         // no more features for this control
    1145        1815 :         for (   ControlFeatures::iterator aLoop = m_aControlFeatures.begin();
    1146        1210 :                 aLoop != m_aControlFeatures.end();
    1147             :                 ++aLoop
    1148             :             )
    1149             :         {
    1150           0 :             aLoop->second->dispose();
    1151             :         }
    1152             : 
    1153         605 :         ControlFeatures aEmpty;
    1154         605 :         m_aControlFeatures.swap( aEmpty );
    1155             : 
    1156         605 :         if ( m_aContextMenuObserver.get() )
    1157             :         {
    1158           0 :             m_aContextMenuObserver->dispose();
    1159           0 :             m_aContextMenuObserver = MouseListenerAdapter();
    1160             :         }
    1161             : 
    1162         605 :         if ( m_xActiveTextComponent.is() )
    1163             :         {
    1164             :             OSL_TRACE( "FmTextControlShell::ClipBoard: stopping timer for clipboard invalidation" );
    1165           0 :             m_aClipboardInvalidation.Stop();
    1166             :         }
    1167             :         // no more active control
    1168         605 :         m_xActiveControl.clear();
    1169         605 :         m_xActiveTextComponent.clear();
    1170         605 :         m_bActiveControlIsReadOnly = true;
    1171         605 :         m_bActiveControlIsRichText = false;
    1172         605 :         m_bActiveControl = false;
    1173         605 :     }
    1174             : 
    1175             : 
    1176           0 :     void FmTextControlShell::controlDeactivated( )
    1177             :     {
    1178             :         DBG_ASSERT( IsActiveControl(), "FmTextControlShell::controlDeactivated: no active control!" );
    1179             : 
    1180           0 :         m_bActiveControl = false;
    1181             : 
    1182           0 :         m_rBindings.Invalidate( pTextControlSlots );
    1183           0 :     }
    1184             : 
    1185             : 
    1186           2 :     void FmTextControlShell::controlActivated( const Reference< XControl >& _rxControl )
    1187             :     {
    1188             :         // ensure that all knittings with the previously active control are lost
    1189           2 :         if ( m_xActiveControl.is() )
    1190           0 :             implClearActiveControlRef();
    1191             :         DBG_ASSERT( m_aControlFeatures.empty(), "FmTextControlShell::controlActivated: should have no dispatchers when I'm here!" );
    1192             : 
    1193             : #if OSL_DEBUG_LEVEL > 0
    1194             :         {
    1195             :             Sequence< Reference< XControl > > aActiveControls;
    1196             :             if ( m_xActiveController.is() )
    1197             :                 aActiveControls = m_xActiveController->getControls();
    1198             : 
    1199             :             bool bFoundThisControl = false;
    1200             : 
    1201             :             const Reference< XControl >* pControls = aActiveControls.getConstArray();
    1202             :             const Reference< XControl >* pControlsEnd = pControls + aActiveControls.getLength();
    1203             :             for ( ; ( pControls != pControlsEnd ) && !bFoundThisControl; ++pControls )
    1204             :             {
    1205             :                 if ( *pControls == _rxControl )
    1206             :                     bFoundThisControl = true;
    1207             :             }
    1208             :             DBG_ASSERT( bFoundThisControl, "FmTextControlShell::controlActivated: only controls which belong to the active controller can be activated!" );
    1209             :         }
    1210             : #endif
    1211             :         // ask the control for dispatchers for our text-related slots
    1212           2 :         fillFeatureDispatchers( _rxControl, pTextControlSlots, m_aControlFeatures );
    1213             : 
    1214             :         // remember this control
    1215           2 :         m_xActiveControl = _rxControl;
    1216           2 :         m_xActiveTextComponent.set(_rxControl, css::uno::UNO_QUERY);
    1217           2 :         m_bActiveControlIsReadOnly = lcl_determineReadOnly( m_xActiveControl );
    1218           2 :         m_bActiveControlIsRichText = lcl_isRichText( m_xActiveControl );
    1219             : 
    1220             :         // if we found a rich text control, we need context menu support
    1221           2 :         if ( m_bActiveControlIsRichText )
    1222             :         {
    1223             :             DBG_ASSERT( NULL == m_aContextMenuObserver.get(), "FmTextControlShell::controlActivated: already have an observer!" );
    1224           0 :             m_aContextMenuObserver = MouseListenerAdapter( new FmMouseListenerAdapter( _rxControl, this ) );
    1225             :         }
    1226             : 
    1227           2 :         if ( m_xActiveTextComponent.is() )
    1228             :         {
    1229             :             OSL_TRACE( "FmTextControlShell::ClipBoard: starting timer for clipboard invalidation" );
    1230           0 :             m_aClipboardInvalidation.Start();
    1231             :         }
    1232             : 
    1233           2 :         m_bActiveControl = true;
    1234             : 
    1235           2 :         m_rBindings.Invalidate( pTextControlSlots );
    1236             : 
    1237           2 :         if ( m_pViewFrame )
    1238           2 :             m_pViewFrame->UIFeatureChanged();
    1239             : 
    1240             :         // don't call the activation handler if we don't have any slots we can serve
    1241             :         // The activation handler is used to put the shell on the top of the dispatcher stack,
    1242             :         // so it's preferred when slots are distributed.
    1243             :         // Note that this is a slight hack, to prevent that we grab slots from the SfxDispatcher
    1244             :         // which should be served by other shells (e.g. Cut/Copy/Paste).
    1245             :         // A real solution would be a forwarding-mechanism for slots: We should be on the top
    1246             :         // if we're active, but if we cannot handle the slot, then we need to tell the dispatcher
    1247             :         // to skip our shell, and pass the slot to the next one. However, this mechanism is not
    1248             :         // not in place in SFX.
    1249             :         // Another possibility would be to have dedicated shells for the slots which we might
    1250             :         // or might not be able to serve. However, this could probably increase the number of
    1251             :         // shells too much (In theory, nearly every slot could have an own shell then).
    1252             : 
    1253             :         // #i51621# / 2005-08-19 / frank.schoenheit@sun.com
    1254             :         // bool bHaveAnyServeableSlots = m_xActiveTextComponent.is() || !m_aControlFeatures.empty();
    1255             :         // LEM: not calling m_aControlActivatonHandler causes fdo#63695, so disable this hack for now.
    1256           2 :         if ( m_aControlActivationHandler.IsSet() /* && bHaveAnyServeableSlots */ )
    1257           2 :             m_aControlActivationHandler.Call( NULL );
    1258             : 
    1259           2 :         m_bNeedClipboardInvalidation = true;
    1260           2 :     }
    1261             : 
    1262             : 
    1263           2 :     void FmTextControlShell::fillFeatureDispatchers(  const Reference< XControl > _rxControl, SfxSlotId* _pZeroTerminatedSlots,
    1264             :             ControlFeatures& _rDispatchers )
    1265             :     {
    1266           2 :         Reference< XDispatchProvider > xProvider( _rxControl, UNO_QUERY );
    1267           2 :         SfxApplication* pApplication = SfxGetpApp();
    1268             :         DBG_ASSERT( pApplication, "FmTextControlShell::fillFeatureDispatchers: no SfxApplication!" );
    1269           2 :         if ( xProvider.is() && pApplication )
    1270             :         {
    1271           0 :             SfxSlotId* pSlots = _pZeroTerminatedSlots;
    1272           0 :             while ( *pSlots )
    1273             :             {
    1274           0 :                 FmTextControlFeature* pDispatcher = implGetFeatureDispatcher( xProvider, pApplication, *pSlots );
    1275           0 :                 if ( pDispatcher )
    1276           0 :                     _rDispatchers.insert( ControlFeatures::value_type( *pSlots, ControlFeature( pDispatcher ) ) );
    1277             : 
    1278           0 :                 ++pSlots;
    1279             :             }
    1280           2 :         }
    1281           2 :     }
    1282             : 
    1283             : 
    1284           0 :     void FmTextControlShell::impl_parseURL_nothrow( URL& _rURL )
    1285             :     {
    1286             :         try
    1287             :         {
    1288           0 :             if ( !m_xURLTransformer.is() )
    1289             :             {
    1290           0 :                 m_xURLTransformer = util::URLTransformer::create( ::comphelper::getProcessComponentContext() );
    1291             :             }
    1292           0 :             if ( m_xURLTransformer.is() )
    1293           0 :                 m_xURLTransformer->parseStrict( _rURL );
    1294             :         }
    1295           0 :         catch( const Exception& )
    1296             :         {
    1297             :             DBG_UNHANDLED_EXCEPTION();
    1298             :         }
    1299           0 :     }
    1300             : 
    1301             : 
    1302           0 :     FmTextControlFeature* FmTextControlShell::implGetFeatureDispatcher( const Reference< XDispatchProvider >& _rxProvider, SfxApplication* _pApplication, SfxSlotId _nSlot )
    1303             :     {
    1304             :         OSL_PRECOND( _rxProvider.is() && _pApplication, "FmTextControlShell::implGetFeatureDispatcher: invalid arg(s)!" );
    1305           0 :         URL aFeatureURL;
    1306           0 :         aFeatureURL.Complete = lcl_getUnoSlotName( *_pApplication, _nSlot );
    1307           0 :         impl_parseURL_nothrow( aFeatureURL );
    1308           0 :         Reference< XDispatch > xDispatcher = _rxProvider->queryDispatch( aFeatureURL, OUString(), 0xFF );
    1309           0 :         if ( xDispatcher.is() )
    1310           0 :             return new FmTextControlFeature( xDispatcher, aFeatureURL, _nSlot, this );
    1311           0 :         return NULL;
    1312             :     }
    1313             : 
    1314             : 
    1315           0 :     void FmTextControlShell::Invalidate( SfxSlotId _nSlot )
    1316             :     {
    1317           0 :         m_rBindings.Invalidate( _nSlot );
    1318             :         // despite this method being called "Invalidate", we also update here - this gives more immediate
    1319             :         // feedback in the UI
    1320           0 :         m_rBindings.Update( _nSlot );
    1321           0 :     }
    1322             : 
    1323             : 
    1324           0 :     void FmTextControlShell::focusGained( const ::com::sun::star::awt::FocusEvent& _rEvent )
    1325             :     {
    1326           0 :         Reference< XControl > xControl( _rEvent.Source, UNO_QUERY );
    1327             : 
    1328             : #if OSL_DEBUG_LEVEL > 0
    1329             :         OString sTrace( "FmTextControlShell::focusGained: 0x" );
    1330             :         sTrace += OString::number( reinterpret_cast<sal_IntPtr>(xControl.get()), 16 );
    1331             :         OSL_TRACE( "%s", sTrace.getStr() );
    1332             : #endif
    1333             : 
    1334             :         DBG_ASSERT( xControl.is(), "FmTextControlShell::focusGained: suspicious focus event!" );
    1335           0 :         if ( xControl.is() )
    1336           0 :             controlActivated( xControl );
    1337           0 :     }
    1338             : 
    1339             : 
    1340           2 :     void FmTextControlShell::focusLost( const ::com::sun::star::awt::FocusEvent& _rEvent )
    1341             :     {
    1342           2 :         Reference< XControl > xControl( _rEvent.Source, UNO_QUERY );
    1343             : 
    1344             : #if OSL_DEBUG_LEVEL > 0
    1345             :         OString sTrace( "FmTextControlShell::focusLost: 0x" );
    1346             :         sTrace += OString::number( reinterpret_cast<sal_IntPtr>(xControl.get()), 16 );
    1347             :         OSL_TRACE( "%s", sTrace.getStr() );
    1348             : #endif
    1349             : 
    1350           2 :         m_bActiveControl = false;
    1351           2 :     }
    1352             : 
    1353             : 
    1354         605 :     void FmTextControlShell::ForgetActiveControl()
    1355             :     {
    1356         605 :         implClearActiveControlRef();
    1357         605 :     }
    1358             : 
    1359             : 
    1360           0 :     void FmTextControlShell::contextMenuRequested( const awt::MouseEvent& /*_rEvent*/ )
    1361             :     {
    1362           0 :         m_rBindings.GetDispatcher()->ExecutePopup( SVX_RES( RID_FM_TEXTATTRIBUTE_MENU ) );
    1363           0 :     }
    1364             : 
    1365             : 
    1366         651 : } // namespace svx
    1367             : 
    1368             : 
    1369             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10