LCOV - code coverage report
Current view: top level - libreoffice/svx/source/accessibility - AccessibleEmptyEditSource.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 130 0.0 %
Date: 2012-12-27 Functions: 0 73 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : //------------------------------------------------------------------------
      22             : //
      23             : // Global header
      24             : //
      25             : //------------------------------------------------------------------------
      26             : #include <svl/itemset.hxx>
      27             : #include <editeng/editdata.hxx>
      28             : #include <editeng/outliner.hxx>
      29             : #include <svx/svdmodel.hxx>
      30             : #include <svx/svdobj.hxx>
      31             : #include <svx/svdpool.hxx>
      32             : 
      33             : //------------------------------------------------------------------------
      34             : //
      35             : // Project-local header
      36             : //
      37             : //------------------------------------------------------------------------
      38             : 
      39             : #include "AccessibleEmptyEditSource.hxx"
      40             : #include <svx/unoshtxt.hxx>
      41             : 
      42             : namespace accessibility
      43             : {
      44             : 
      45             :     /** This class simply wraps a SvxTextEditSource, forwarding all
      46             :         methods except the GetBroadcaster() call
      47             :      */
      48             :     class AccessibleProxyEditSource_Impl : public SvxEditSource
      49             :     {
      50             :     public:
      51             :         /** Construct AccessibleEmptyEditSource_Impl
      52             : 
      53             :             @param rBrdCast
      54             : 
      55             :             Proxy broadcaster to allow seamless flipping of edit source implementations. ProxyEditSource and EmptyEditSource
      56             :          */
      57             :         AccessibleProxyEditSource_Impl( SdrObject&      rObj,
      58             :                                         SdrView&        rView,
      59             :                                         const Window&   rViewWindow );
      60             :         ~AccessibleProxyEditSource_Impl();
      61             : 
      62             :         // from the SvxEditSource interface
      63             :         SvxTextForwarder*       GetTextForwarder();
      64             :         SvxViewForwarder*       GetViewForwarder();
      65             :         SvxEditViewForwarder*   GetEditViewForwarder( sal_Bool bCreate = sal_False );
      66             : 
      67             :         SvxEditSource*          Clone() const;
      68             : 
      69             :         void                    UpdateData();
      70             : 
      71             :         SfxBroadcaster&         GetBroadcaster() const;
      72             : 
      73             :     private:
      74             :         SvxTextEditSource       maEditSource;
      75             : 
      76             :     };
      77             : 
      78             :     /** Dummy class, faking exactly one empty paragraph for EditEngine accessibility
      79             :      */
      80             :     class AccessibleEmptyEditSource_Impl : public SvxEditSource, public SvxViewForwarder, public SvxTextForwarder, public SfxBroadcaster
      81             :     {
      82             :     public:
      83             : 
      84           0 :         AccessibleEmptyEditSource_Impl() {}
      85           0 :         ~AccessibleEmptyEditSource_Impl() {}
      86             : 
      87             :         // from the SfxListener interface
      88             :         void                    Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
      89             : 
      90             :         // SvxEditSource
      91           0 :         SvxTextForwarder*       GetTextForwarder() { return this; }
      92           0 :         SvxViewForwarder*       GetViewForwarder() { return this; }
      93           0 :         SvxEditSource*          Clone() const { return NULL; }
      94           0 :         void                    UpdateData() {}
      95           0 :         SfxBroadcaster&         GetBroadcaster() const { return *(const_cast<AccessibleEmptyEditSource_Impl*>(this)); }
      96             : 
      97             :         // SvxTextForwarder
      98           0 :         sal_uInt16          GetParagraphCount() const { return 1; }
      99           0 :         sal_uInt16          GetTextLen( sal_uInt16 /*nParagraph*/ ) const { return 0; }
     100           0 :         String          GetText( const ESelection& /*rSel*/ ) const { return String(); }
     101           0 :         SfxItemSet      GetAttribs( const ESelection& /*rSel*/, sal_Bool /*bOnlyHardAttrib*/ = 0 ) const
     102             :         {
     103             :             // AW: Very dangerous: The former implementation used a SfxItemPool created on the
     104             :             // fly which of course was deleted again ASAP. Thus, the returned SfxItemSet was using
     105             :             // a deleted Pool by design.
     106           0 :             return SfxItemSet(SdrObject::GetGlobalDrawObjectItemPool());
     107             :         }
     108           0 :         SfxItemSet      GetParaAttribs( sal_uInt16 /*nPara*/ ) const { return GetAttribs(ESelection()); }
     109           0 :         void            SetParaAttribs( sal_uInt16 /*nPara*/, const SfxItemSet& /*rSet*/ ) {}
     110           0 :         void            RemoveAttribs( const ESelection& /*rSelection*/, sal_Bool /*bRemoveParaAttribs*/, sal_uInt16 /*nWhich*/ ){}
     111           0 :         void            GetPortions( sal_uInt16 /*nPara*/, std::vector<sal_uInt16>& /*rList*/ ) const {}
     112             : 
     113           0 :         sal_uInt16          GetItemState( const ESelection& /*rSel*/, sal_uInt16 /*nWhich*/ ) const { return 0; }
     114           0 :         sal_uInt16          GetItemState( sal_uInt16 /*nPara*/, sal_uInt16 /*nWhich*/ ) const { return 0; }
     115             : 
     116           0 :         SfxItemPool*    GetPool() const { return NULL; }
     117             : 
     118           0 :         void            QuickInsertText( const String& /*rText*/, const ESelection& /*rSel*/ ) {}
     119           0 :         void            QuickInsertField( const SvxFieldItem& /*rFld*/, const ESelection& /*rSel*/ ) {}
     120           0 :         void            QuickSetAttribs( const SfxItemSet& /*rSet*/, const ESelection& /*rSel*/ ) {}
     121           0 :         void            QuickInsertLineBreak( const ESelection& /*rSel*/ ) {}
     122             : 
     123           0 :         const SfxItemSet * GetEmptyItemSetPtr() { return 0; }
     124             : 
     125           0 :         void        AppendParagraph() {}
     126           0 :         xub_StrLen  AppendTextPortion( sal_uInt16 /*nPara*/, const String & /*rText*/, const SfxItemSet & /*rSet*/ ) { return 0; }
     127             : 
     128             :         //XTextCopy
     129           0 :         void        CopyText(const SvxTextForwarder& ){}
     130             : 
     131           0 :         XubString       CalcFieldValue( const SvxFieldItem& /*rField*/, sal_uInt16 /*nPara*/, sal_uInt16 /*nPos*/, Color*& /*rpTxtColor*/, Color*& /*rpFldColor*/ )
     132             :         {
     133           0 :             return  XubString();
     134             :         }
     135           0 :         void            FieldClicked( const SvxFieldItem&, sal_uInt16, xub_StrLen ) {;}
     136             : 
     137           0 :         sal_Bool            IsValid() const { return sal_True; }
     138             : 
     139             :         void            SetNotifyHdl( const Link& ) {}
     140           0 :         LanguageType    GetLanguage( sal_uInt16, sal_uInt16 ) const { return LANGUAGE_DONTKNOW; }
     141           0 :         sal_uInt16          GetFieldCount( sal_uInt16 ) const { return 0; }
     142           0 :         EFieldInfo      GetFieldInfo( sal_uInt16, sal_uInt16 ) const { return EFieldInfo(); }
     143           0 :         EBulletInfo     GetBulletInfo( sal_uInt16 ) const { return EBulletInfo(); }
     144           0 :         Rectangle       GetCharBounds( sal_uInt16, sal_uInt16 ) const { return Rectangle(); }
     145           0 :         Rectangle       GetParaBounds( sal_uInt16 ) const { return Rectangle(); }
     146           0 :         MapMode         GetMapMode() const { return MapMode(); }
     147           0 :         OutputDevice*   GetRefDevice() const { return NULL; }
     148           0 :         sal_Bool        GetIndexAtPoint( const Point&, sal_uInt16&, sal_uInt16& ) const { return sal_False; }
     149           0 :         sal_Bool        GetWordIndices( sal_uInt16, sal_uInt16, sal_uInt16&, sal_uInt16& ) const { return sal_False; }
     150           0 :         sal_Bool        GetAttributeRun( sal_uInt16&, sal_uInt16&, sal_uInt16, sal_uInt16 ) const { return sal_False; }
     151           0 :         sal_uInt16          GetLineCount( sal_uInt16 nPara ) const { return nPara == 0 ? 1 : 0; }
     152           0 :         sal_uInt16          GetLineLen( sal_uInt16, sal_uInt16 ) const { return 0; }
     153           0 :         void            GetLineBoundaries( /*out*/sal_uInt16 & rStart, /*out*/sal_uInt16 & rEnd, sal_uInt16 /*nParagraph*/, sal_uInt16 /*nLine*/ ) const  { rStart = rEnd = 0; }
     154           0 :         sal_uInt16          GetLineNumberAtIndex( sal_uInt16 /*nPara*/, sal_uInt16 /*nIndex*/ ) const   { return 0; }
     155             : 
     156             :         // the following two methods would, strictly speaking, require
     157             :         // a switch to a real EditSource, too. Fortunately, the
     158             :         // AccessibleEditableTextPara implementation currently always
     159             :         // calls GetEditViewForwarder(true) before doing
     160             :         // changes. Thus, we rely on this behabviour here (problem
     161             :         // when that changes: via accessibility API, it would no
     162             :         // longer be possible to enter text in previously empty
     163             :         // shapes).
     164           0 :         sal_Bool        Delete( const ESelection& ) { return sal_False; }
     165           0 :         sal_Bool        InsertText( const String&, const ESelection& ) { return sal_False; }
     166           0 :         sal_Bool        QuickFormatDoc( sal_Bool ) { return sal_True; }
     167           0 :         sal_Int16       GetDepth( sal_uInt16 ) const { return -1; }
     168           0 :         sal_Bool        SetDepth( sal_uInt16, sal_Int16 ) { return sal_True; }
     169             : 
     170           0 :         Rectangle       GetVisArea() const { return Rectangle(); }
     171           0 :         Point           LogicToPixel( const Point& rPoint, const MapMode& /*rMapMode*/ ) const { return rPoint; }
     172           0 :         Point           PixelToLogic( const Point& rPoint, const MapMode& /*rMapMode*/ ) const { return rPoint; }
     173             : 
     174             :     };
     175             : 
     176             :     // -------------------------------------------------------------------------
     177             :     // Implementing AccessibleProxyEditSource_Impl
     178             :     // -------------------------------------------------------------------------
     179             : 
     180           0 :     AccessibleProxyEditSource_Impl::AccessibleProxyEditSource_Impl( SdrObject&      rObj,
     181             :                                                                     SdrView&        rView,
     182             :                                                                     const Window&   rViewWindow ) :
     183           0 :         maEditSource( rObj, 0, rView, rViewWindow )
     184             :     {
     185           0 :     }
     186             : 
     187           0 :     AccessibleProxyEditSource_Impl::~AccessibleProxyEditSource_Impl()
     188             :     {
     189           0 :     }
     190             : 
     191           0 :     SvxTextForwarder* AccessibleProxyEditSource_Impl::GetTextForwarder()
     192             :     {
     193           0 :         return maEditSource.GetTextForwarder();
     194             :     }
     195             : 
     196           0 :     SvxViewForwarder* AccessibleProxyEditSource_Impl::GetViewForwarder()
     197             :     {
     198           0 :         return maEditSource.GetViewForwarder();
     199             :     }
     200             : 
     201           0 :     SvxEditViewForwarder* AccessibleProxyEditSource_Impl::GetEditViewForwarder( sal_Bool bCreate )
     202             :     {
     203           0 :         return maEditSource.GetEditViewForwarder( bCreate );
     204             :     }
     205             : 
     206           0 :     SvxEditSource* AccessibleProxyEditSource_Impl::Clone() const
     207             :     {
     208           0 :         return maEditSource.Clone();
     209             :     }
     210             : 
     211           0 :     void AccessibleProxyEditSource_Impl::UpdateData()
     212             :     {
     213           0 :         maEditSource.UpdateData();
     214           0 :     }
     215             : 
     216           0 :     SfxBroadcaster& AccessibleProxyEditSource_Impl::GetBroadcaster() const
     217             :     {
     218           0 :         return maEditSource.GetBroadcaster();
     219             :     }
     220             : 
     221             : 
     222             :     // -------------------------------------------------------------------------
     223             :     // Implementing AccessibleEmptyEditSource
     224             :     // -------------------------------------------------------------------------
     225             : 
     226           0 :     AccessibleEmptyEditSource::AccessibleEmptyEditSource( SdrObject&    rObj,
     227             :                                                           SdrView&      rView,
     228             :                                                           const Window& rViewWindow ) :
     229           0 :         mpEditSource( new AccessibleEmptyEditSource_Impl() ),
     230             :         mrObj(rObj),
     231             :         mrView(rView),
     232             :         mrViewWindow(rViewWindow),
     233           0 :         mbEditSourceEmpty( true )
     234             :     {
     235           0 :         if( mrObj.GetModel() )
     236           0 :             StartListening( *mrObj.GetModel() );
     237           0 :     }
     238             : 
     239           0 :     AccessibleEmptyEditSource::~AccessibleEmptyEditSource()
     240             :     {
     241           0 :         if( !mbEditSourceEmpty )
     242             :         {
     243             :             // deregister as listener
     244           0 :             if( mpEditSource.get() )
     245           0 :                 EndListening( mpEditSource->GetBroadcaster() );
     246             :         }
     247             :         else
     248             :         {
     249           0 :             if( mrObj.GetModel() )
     250           0 :                 EndListening( *mrObj.GetModel() );
     251             :         }
     252           0 :     }
     253             : 
     254           0 :     SvxTextForwarder* AccessibleEmptyEditSource::GetTextForwarder()
     255             :     {
     256           0 :         if( !mpEditSource.get() )
     257           0 :             return NULL;
     258             : 
     259           0 :         return mpEditSource->GetTextForwarder();
     260             :     }
     261             : 
     262           0 :     SvxViewForwarder* AccessibleEmptyEditSource::GetViewForwarder()
     263             :     {
     264           0 :         if( !mpEditSource.get() )
     265           0 :             return NULL;
     266             : 
     267           0 :         return mpEditSource->GetViewForwarder();
     268             :     }
     269             : 
     270           0 :     void AccessibleEmptyEditSource::Switch2ProxyEditSource()
     271             :     {
     272             :         // deregister EmptyEditSource model listener
     273           0 :         if( mrObj.GetModel() )
     274           0 :             EndListening( *mrObj.GetModel() );
     275             : 
     276             :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
     277           0 :         ::std::auto_ptr< SvxEditSource > pProxySource( new AccessibleProxyEditSource_Impl(mrObj, mrView, mrViewWindow) );
     278           0 :         ::std::auto_ptr< SvxEditSource > tmp = mpEditSource;
     279             :         SAL_WNODEPRECATED_DECLARATIONS_POP
     280           0 :         mpEditSource = pProxySource;
     281           0 :         pProxySource = tmp;
     282             : 
     283             :         // register as listener
     284           0 :         StartListening( mpEditSource->GetBroadcaster() );
     285             : 
     286             :         // we've irrevocably a full EditSource now.
     287           0 :         mbEditSourceEmpty = false;
     288           0 :     }
     289             : 
     290           0 :     SvxEditViewForwarder* AccessibleEmptyEditSource::GetEditViewForwarder( sal_Bool bCreate )
     291             :     {
     292           0 :         if( !mpEditSource.get() )
     293           0 :             return NULL;
     294             : 
     295             :         // switch edit source, if not yet done
     296           0 :         if( mbEditSourceEmpty && bCreate )
     297           0 :             Switch2ProxyEditSource();
     298             : 
     299           0 :         return mpEditSource->GetEditViewForwarder( bCreate );
     300             :     }
     301             : 
     302           0 :     SvxEditSource* AccessibleEmptyEditSource::Clone() const
     303             :     {
     304           0 :         if( !mpEditSource.get() )
     305           0 :             return NULL;
     306             : 
     307           0 :         return mpEditSource->Clone();
     308             :     }
     309             : 
     310           0 :     void AccessibleEmptyEditSource::UpdateData()
     311             :     {
     312           0 :         if( mpEditSource.get() )
     313           0 :             mpEditSource->UpdateData();
     314           0 :     }
     315             : 
     316           0 :     SfxBroadcaster& AccessibleEmptyEditSource::GetBroadcaster() const
     317             :     {
     318           0 :         return *(const_cast<AccessibleEmptyEditSource*>(this));
     319             :     }
     320             : 
     321           0 :     void AccessibleEmptyEditSource::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
     322             :     {
     323           0 :         const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint );
     324             : 
     325           0 :         if( pSdrHint && pSdrHint->GetKind() == HINT_BEGEDIT &&
     326           0 :             &mrObj == pSdrHint->GetObject() && mpEditSource.get() )
     327             :         {
     328             :             // switch edit source, if not yet done. This is necessary
     329             :             // to become a full-fledged EditSource the first time a
     330             :             // user start entering text in a previously empty object.
     331           0 :             if( mbEditSourceEmpty )
     332           0 :                 Switch2ProxyEditSource();
     333             :         }
     334           0 :         else if (pSdrHint && pSdrHint->GetObject()!=NULL)
     335             :         {
     336             :             // When the SdrObject just got a para outliner object then
     337             :             // switch the edit source.
     338           0 :             if (pSdrHint->GetObject()->GetOutlinerParaObject() != NULL)
     339           0 :                 Switch2ProxyEditSource();
     340             :         }
     341             : 
     342             :         // forward messages
     343           0 :         Broadcast( rHint );
     344           0 :     }
     345             : 
     346             : } // end of namespace accessibility
     347             : 
     348             : //------------------------------------------------------------------------
     349             : 
     350             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10