LCOV - code coverage report
Current view: top level - include/editeng - unoedsrc.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 4 6 66.7 %
Date: 2015-06-13 12:38:46 Functions: 6 9 66.7 %
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             : #ifndef INCLUDED_EDITENG_UNOEDSRC_HXX
      21             : #define INCLUDED_EDITENG_UNOEDSRC_HXX
      22             : 
      23             : #include <com/sun/star/accessibility/TextSegment.hpp>
      24             : 
      25             : #include <i18nlangtag/lang.h>
      26             : #include <rtl/ustring.hxx>
      27             : #include <tools/gen.hxx>
      28             : #include <vcl/mapmod.hxx>
      29             : #include <tools/color.hxx>
      30             : #include <svl/poolitem.hxx>
      31             : #include <svl/itempool.hxx>
      32             : #include <editeng/editengdllapi.h>
      33             : #include <editeng/editeng.hxx>
      34             : 
      35             : #include <list>
      36             : 
      37             : struct ESelection;
      38             : struct EFieldInfo;
      39             : struct EBulletInfo;
      40             : class OutputDevice;
      41             : class SfxItemSet;
      42             : class SvxTextForwarder;
      43             : class SvxViewForwarder;
      44             : class SvxEditViewForwarder;
      45             : class SvxFieldItem;
      46             : class SfxBroadcaster;
      47             : class SvxUnoTextRangeBase;
      48             : 
      49             : typedef std::list< SvxUnoTextRangeBase* > SvxUnoTextRangeBaseList;
      50             : 
      51             : /** Wrapper class for unified EditEngine/Outliner access
      52             : 
      53             :     This class wraps a textual object, which might or might not
      54             :     contain an EditEngine/Outliner. Is used e.g. for filling an
      55             :     EditEngine with the content of a cell, note page or page template.
      56             : */
      57      139873 : class EDITENG_DLLPUBLIC SvxEditSource
      58             : {
      59             : public:
      60             :     virtual                 ~SvxEditSource();
      61             : 
      62             :     /// Returns a new reference to the same object. This is a shallow copy
      63             :     virtual SvxEditSource*      Clone() const = 0;
      64             : 
      65             :     /** Query the text forwarder
      66             : 
      67             :         @return the text forwarder, or NULL if the underlying object is dead
      68             :      */
      69             :     virtual SvxTextForwarder*   GetTextForwarder() = 0;
      70             : 
      71             :     /** Query the view forwarder
      72             : 
      73             :         @return the view forwarder, or NULL if the underlying object
      74             :         is dead, or if no view is available
      75             : 
      76             :         @derive default implementation provided, overriding is optional
      77             :      */
      78             :      virtual SvxViewForwarder*  GetViewForwarder();
      79             : 
      80             :     /** Query the edit view forwarder
      81             : 
      82             :         @param bCreate
      83             :         Determines whether an EditView should be created, if there is
      84             :         none active. If set to sal_True, and the underlying object is
      85             :         not in EditMode, the text forwarder changes and the object is
      86             :         set to EditMode.
      87             : 
      88             :         @return the edit view forwarder, or NULL if the underlying
      89             :         object is dead, or if no view is available (if bCreate is
      90             :         sal_False, NULL is also returned if the object is not in
      91             :         EditMode)
      92             : 
      93             :         @derive default implementation provided, overriding is optional
      94             : 
      95             :         @attention If this method is called with bCreate equal to
      96             :         sal_True, all previously returned text forwarder can become
      97             :         invalid
      98             :      */
      99             :     virtual SvxEditViewForwarder*  GetEditViewForwarder( bool bCreate = false );
     100             : 
     101             :     /// Write back data to model
     102             :     virtual void                UpdateData() = 0;
     103             : 
     104             :     /** Returns broadcaster the underlying edit engine's events are sent from
     105             : 
     106             :         @derive default implementation provided, overriding is optional
     107             :      */
     108             :     virtual SfxBroadcaster&     GetBroadcaster() const;
     109             : 
     110             :     /** adds the given SvxUnoTextRangeBase to the text object
     111             :         capsulated by this SvxEditSource. This allows the text
     112             :         object to inform all created text ranges about changes
     113             :         and also allows to re use already created instances.
     114             :         All SvxUnoTextRangeBase must remove itself with
     115             :         removeRange() before theire deleted. */
     116             :     virtual void addRange( SvxUnoTextRangeBase* pNewRange );
     117             : 
     118             :     /** removes the given SvxUnoTextRangeBase from the text
     119             :         object capsulated by this SvxEditSource. This text range
     120             :         will not be informed any longer of changes on the underlying
     121             :         text and will also not re used anymore. */
     122             :     virtual void removeRange( SvxUnoTextRangeBase* pOldRange );
     123             : 
     124             :     /** returns a const list of all text ranges that are registered
     125             :         for the underlying text object. */
     126             :     virtual const SvxUnoTextRangeBaseList& getRanges() const;
     127             : };
     128             : 
     129             : 
     130             : /** Contains an EditEngine or an Outliner and unifies access to them.
     131             : 
     132             :     The EditEngine-UNO objects use this class only. To reflect changes
     133             :     not only in the EditEngine, but also in the model data, call
     134             :     SvxEditSource::UpdateData(). This copies back the data to the model's
     135             :     EditTextObject/OutlinerParaObject.
     136             :  */
     137       29517 : class EDITENG_DLLPUBLIC SvxTextForwarder
     138             : {
     139             : public:
     140             :     virtual             ~SvxTextForwarder();
     141             : 
     142             :     virtual sal_Int32   GetParagraphCount() const = 0;
     143             :     virtual sal_Int32  GetTextLen( sal_Int32 nParagraph ) const = 0;
     144             :     virtual OUString    GetText( const ESelection& rSel ) const = 0;
     145             :     virtual SfxItemSet  GetAttribs( const ESelection& rSel, EditEngineAttribs nOnlyHardAttrib = EditEngineAttribs_All ) const = 0;
     146             :     virtual SfxItemSet  GetParaAttribs( sal_Int32 nPara ) const = 0;
     147             :     virtual void        SetParaAttribs( sal_Int32 nPara, const SfxItemSet& rSet ) = 0;
     148             :     virtual void        RemoveAttribs( const ESelection& rSelection, bool bRemoveParaAttribs, sal_uInt16 nWhich ) = 0;
     149             :     virtual void        GetPortions( sal_Int32 nPara, std::vector<sal_Int32>& rList ) const = 0;
     150             : 
     151             :     virtual SfxItemState    GetItemState( const ESelection& rSel, sal_uInt16 nWhich ) const = 0;
     152             :     virtual SfxItemState    GetItemState( sal_Int32 nPara, sal_uInt16 nWhich ) const = 0;
     153             : 
     154             :     virtual void        QuickInsertText( const OUString& rText, const ESelection& rSel ) = 0;
     155             :     virtual void        QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel ) = 0;
     156             :     virtual void        QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel ) = 0;
     157             :     virtual void        QuickInsertLineBreak( const ESelection& rSel ) = 0;
     158             : 
     159             :     virtual OUString    CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rpTxtColor, Color*& rpFldColor ) = 0;
     160             :     virtual void         FieldClicked( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos ) = 0;
     161             : 
     162             :     virtual SfxItemPool* GetPool() const = 0;
     163             : 
     164             :     virtual const SfxItemSet*   GetEmptyItemSetPtr() = 0;
     165             : 
     166             :     // implementation functions for XParagraphAppend and XTextPortionAppend
     167             :     virtual void        AppendParagraph() = 0;
     168             :     virtual sal_Int32   AppendTextPortion( sal_Int32 nPara, const OUString &rText, const SfxItemSet &rSet ) = 0;
     169             : 
     170             :     // XTextCopy
     171             :     virtual void        CopyText(const SvxTextForwarder& rSource) = 0;
     172             : 
     173             :     /** Query state of forwarder
     174             : 
     175             :         @return false, if no longer valid
     176             :      */
     177             :     virtual bool       IsValid() const = 0;
     178             : 
     179             :     /** Query language of character at given position on the underlying edit engine
     180             : 
     181             :         @param nPara[0 .. n-1]
     182             :         Index of paragraph to query language in
     183             : 
     184             :         @param nIndex[0 .. m-1]
     185             :         Index of character to query language of
     186             :      */
     187             :     virtual LanguageType    GetLanguage( sal_Int32 nPara, sal_Int32 nIndex ) const = 0;
     188             : 
     189             :     /** Query number of fields in the underlying edit engine
     190             : 
     191             :         @param nPara[0 .. n-1]
     192             :         Index of paragraph to query field number in
     193             :      */
     194             :     virtual sal_Int32          GetFieldCount( sal_Int32 nPara ) const = 0;
     195             : 
     196             :     /** Query information for given field number in the underlying edit engine
     197             : 
     198             :         @param nPara[0 .. n-1]
     199             :         Index of paragraph to query field info in
     200             : 
     201             :         @param nField[0 .. m-1]
     202             :         Index of field to query information of
     203             :      */
     204             :     virtual EFieldInfo      GetFieldInfo( sal_Int32 nPara, sal_uInt16 nField ) const = 0;
     205             : 
     206             :     /** Query information regarding bullets for given paragraph on the underlying edit engine
     207             : 
     208             :         @param nPara[0 .. n-1]
     209             :         Index of paragraph to query bullet info on
     210             :      */
     211             :     virtual EBulletInfo     GetBulletInfo( sal_Int32 nPara ) const = 0;
     212             : 
     213           0 :     virtual void            SetUpdateModeForAcc(bool) {}
     214           0 :     virtual bool            GetUpdateModeForAcc() const { return true; }
     215             : 
     216             :     /** Query the bounding rectangle of the given character
     217             : 
     218             :         @param nPara[0 .. n]
     219             :         Index of paragraph to query the bounds in.  <p>The virtual
     220             :         character after the last character of the represented text,
     221             :         i.e. the one at position n is a special case.  Because it does
     222             :         not represent an existing character its bounding box is
     223             :         defined in relation to preceding characters.  It should be
     224             :         roughly equivalent to the bounding box of some character when
     225             :         inserted at the end of the text.  Its height typically being
     226             :         the maximal height of all the characters in the text or the
     227             :         height of the preceding character, its width being at least
     228             :         one pixel so that the bounding box is not degenerate.<br>
     229             : 
     230             :         @param nIndex[0 .. m-1]
     231             :         Index of character to query the bounds of
     232             : 
     233             :         @return rectangle in logical coordinates, relative to upper
     234             :         left corner of text. The coordinates returned here are to be
     235             :         interpreted in the map mode given by GetMapMode().
     236             :     */
     237             :     virtual Rectangle       GetCharBounds( sal_Int32 nPara, sal_Int32 nIndex ) const = 0;
     238             : 
     239             :     /** Query the bounding rectangle of the given paragraph
     240             : 
     241             :         @param nPara[0 .. n-1]
     242             :         Index of paragraph to query the bounds of
     243             : 
     244             :         @return rectangle in logical coordinates, relative to upper
     245             :         left corner of text. The coordinates returned here are to be
     246             :         interpreted in the map mode given by GetMapMode().
     247             :      */
     248             :     virtual Rectangle       GetParaBounds( sal_Int32 nPara ) const = 0;
     249             : 
     250             :     /** Query the map mode of the underlying EditEngine/Outliner
     251             : 
     252             :         @return the map mode used on the EditEngine/Outliner. The
     253             :         values returned by GetParaBounds() and GetCharBounds() are to
     254             :         be interpreted in this map mode, the point given to
     255             :         GetIndexAtPoint() is interpreted in this map mode.
     256             :      */
     257             :     virtual MapMode         GetMapMode() const = 0;
     258             : 
     259             :     /** Query the reference output device of the underlying EditEngine/Outliner
     260             : 
     261             :         @return the OutputDevice used from the EditEngine/Outliner to
     262             :         format the text. It should be used when performing e.g. font
     263             :         calculations, since this is usually a printer with fonts and
     264             :         resolution different from the screen.
     265             :      */
     266             :     virtual OutputDevice*   GetRefDevice() const = 0;
     267             : 
     268             :     /** Query paragraph and character index of the character at the
     269             :         given point. Returns sal_True on success, sal_False otherwise
     270             : 
     271             :         @param rPoint
     272             :         Point to query text position of. Is interpreted in logical
     273             :         coordinates, relativ to the upper left corner of the text, and
     274             :         in the map mode given by GetMapMode()
     275             : 
     276             :         @param rPara[0 .. n-1]
     277             :         Index of paragraph the point is within
     278             : 
     279             :         @param rIndex[0 .. m-1]
     280             :         Index of character the point is over
     281             : 
     282             :         @return true, if the point is over any text and both rPara and rIndex are valid
     283             : 
     284             :      */
     285             :     virtual bool            GetIndexAtPoint( const Point& rPoint, sal_Int32& rPara, sal_Int32& rIndex ) const = 0;
     286             : 
     287             :     /** Get the start and the end index of the word at the given index
     288             : 
     289             :         An index value on a word leads from the first character of
     290             :         that word up to and including the last space before the next
     291             :         word. The index values returned do not contain any leading or
     292             :         trailing white-space. If the input indices are invalid,
     293             :         sal_False is returned.
     294             : 
     295             :         @param nPara[0 .. n-1]
     296             :         Index of paragraph to start the search in
     297             : 
     298             :         @param nIndex[0 .. m-1]
     299             :         Index of character to query the search on
     300             : 
     301             :         @param rStart
     302             :         Start index (in the same paragraph)
     303             : 
     304             :         @param rEnd
     305             :         End index (in the same paragraph), this point to the last
     306             :         character still contained in the query
     307             : 
     308             :         @return true, if the result is non-empty
     309             :      */
     310             :     virtual bool             GetWordIndices( sal_Int32 nPara, sal_Int32 nIndex, sal_Int32& rStart, sal_Int32& rEnd ) const = 0;
     311             : 
     312             :     /** Query range of similar attributes
     313             : 
     314             :         Please note that the range returned is half-open: [nStartIndex,nEndIndex)
     315             : 
     316             :         @param nStartIndex
     317             :         Herein, the start index of the range of similar attributes is returned
     318             : 
     319             :         @param nEndIndex
     320             :         Herein, the end index (exclusive) of the range of similar attributes is returned
     321             : 
     322             :         @param nIndex
     323             :         The character index from which the range of similar attributed characters is requested
     324             : 
     325             :         @return true, if the range has been successfully determined
     326             :      */
     327             :     virtual bool               GetAttributeRun( sal_Int32& nStartIndex, sal_Int32& nEndIndex, sal_Int32 nPara, sal_Int32 nIndex, bool bInCell = false ) const = 0;
     328             : 
     329             :     /** Query number of lines in the formatted paragraph
     330             : 
     331             :         @param nPara[0 .. n-1]
     332             :         Index of paragraph to query number of lines in
     333             : 
     334             :         @return number of lines in given paragraph
     335             : 
     336             :      */
     337             :     virtual sal_Int32          GetLineCount( sal_Int32 nPara ) const = 0;
     338             : 
     339             :     /** Query line length
     340             : 
     341             :         @param nPara[0 .. n-1]
     342             :         Index of paragraph to query line length in
     343             : 
     344             :         @param nLine[0 .. m-1]
     345             :         Index of line in paragraph to query line length of
     346             : 
     347             :      */
     348             :     virtual sal_Int32         GetLineLen( sal_Int32 nPara, sal_Int32 nLine ) const = 0;
     349             : 
     350             :     /** Query bounds of line in paragraph
     351             : 
     352             :         @param rStart [output param; 0 .. text_len]
     353             :         The index in the paragraph text that belongs to the chara at the start of the line
     354             : 
     355             :         @param rEnd [output param; 0 .. text_len]
     356             :         The index in the paragraph text that follows the last chara in the line
     357             : 
     358             :         @param nParagraph[0 .. n-1]
     359             :         Index of paragraph to query line length in
     360             : 
     361             :         @param nLine[0 .. m-1]
     362             :         Index of line in paragraph to query line length of
     363             : 
     364             :      */
     365             :     virtual void            GetLineBoundaries( /*out*/sal_Int32 &rStart, /*out*/sal_Int32 &rEnd, sal_Int32 nParagraph, sal_Int32 nLine ) const = 0;
     366             : 
     367             :     /** Query the line number for a index in the paragraphs text
     368             : 
     369             :         @param nPara[0 .. n-1]
     370             :         Index of paragraph to query line length in
     371             : 
     372             :         @param nIndex[0 .. m-1]
     373             :         Index of the char in the paragraph text
     374             : 
     375             :         @returns [0 .. k-1]
     376             :         The line number of the char in the paragraph
     377             :      */
     378             :     virtual sal_Int32          GetLineNumberAtIndex( sal_Int32 nPara, sal_Int32 nIndex ) const = 0;
     379             : 
     380             :     /** Delete given text range and reformat text
     381             : 
     382             :         @param rSelection
     383             :         The text range to be deleted
     384             : 
     385             :         @return true if text has been successfully deleted
     386             :      */
     387             :     virtual bool            Delete( const ESelection& rSelection ) = 0;
     388             : 
     389             :      /** Insert/Replace given text in given range and reformat text
     390             : 
     391             :           @param rText
     392             :          Text to insert/replace
     393             : 
     394             :          @param rSel
     395             :          Selection where text should be replaced. The empty selection inserts
     396             : 
     397             :          @return true if text has been successfully inserted
     398             :       */
     399             :     virtual bool            InsertText( const OUString& rText, const ESelection& rSel ) = 0;
     400             : 
     401             :      /** Updates the formatting
     402             : 
     403             :           @see EditEngine::QuickFormatDoc() for details
     404             : 
     405             :          @return true if text have been successfully reformatted
     406             :       */
     407             :     virtual bool            QuickFormatDoc( bool bFull = false ) = 0;
     408             : 
     409             :     /** Get the outline depth of given paragraph
     410             : 
     411             :         @param nPara
     412             :         Index of the paragraph to query the depth of
     413             : 
     414             :         @return the outline level of the given paragraph. The range is
     415             :         [0,n), where n is the maximal outline level.
     416             :      */
     417             :     virtual sal_Int16       GetDepth( sal_Int32 nPara ) const = 0;
     418             : 
     419             :     /** Set the outline depth of given paragraph
     420             : 
     421             :         @param nPara
     422             :         Index of the paragraph to set the depth of
     423             : 
     424             :         @param nNewDepth
     425             :         The depth to set on the given paragraph. The range is
     426             :         [0,n), where n is the maximal outline level.
     427             : 
     428             :         @return true, if depth could be successfully set. Reasons for
     429             :         failure are e.g. the text does not support outline level
     430             :         (EditEngine), or the depth range is exceeded.
     431             :      */
     432             :     virtual bool            SetDepth( sal_Int32 nPara, sal_Int16 nNewDepth ) = 0;
     433             : 
     434             :     virtual sal_Int32 GetNumberingStartValue( sal_Int32 nPara );
     435             :     virtual void SetNumberingStartValue( sal_Int32 nPara, sal_Int32 nNumberingStartValue );
     436             : 
     437             :     virtual bool IsParaIsNumberingRestart( sal_Int32 nPara );
     438             :     virtual void SetParaIsNumberingRestart( sal_Int32 nPara, bool bParaIsNumberingRestart );
     439             : };
     440             : 
     441             : /** Encapsulates the document view for the purpose of unified
     442             :     EditEngine/Outliner access.
     443             : 
     444             :     This one has to be different from the SvxEditViewForwarder, since
     445             :     the latter is only valid in edit mode.
     446             :  */
     447      123234 : class EDITENG_DLLPUBLIC SvxViewForwarder
     448             : {
     449             : public:
     450             :     virtual             ~SvxViewForwarder();
     451             : 
     452             :     /** Query state of forwarder
     453             : 
     454             :         @return sal_False, if no longer valid
     455             :      */
     456             :     virtual bool        IsValid() const = 0;
     457             : 
     458             :     /** Query visible area of the view containing the text
     459             : 
     460             :         @return the visible rectangle of the text, i.e. the part of
     461             :         the EditEngine or Outliner that is currently on screen. The
     462             :         values are already in screen coordinates (pixel), and have to
     463             :         be relative to the EditEngine/Outliner's upper left corner.
     464             :      */
     465             :     virtual Rectangle   GetVisArea() const = 0;
     466             : 
     467             :     /** Convert from logical, EditEngine-relative coordinates to screen coordinates
     468             : 
     469             :         @param rPoint
     470             :         Point in logical, EditEngine-relative coordinates.
     471             : 
     472             :         @param rMapMode
     473             :         The map mode to interpret the coordinates in.
     474             : 
     475             :         @return the point in screen coordinates
     476             :      */
     477             :     virtual Point       LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const = 0;
     478             : 
     479             :     /** Convert from screen to logical, EditEngine-relative coordinates
     480             : 
     481             :         @param rPoint
     482             :         Point in screen coordinates
     483             : 
     484             :         @param rMapMode
     485             :         The map mode to interpret the coordinates in.
     486             : 
     487             :         @return the point in logical coordinates.
     488             :      */
     489             :     virtual Point       PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const = 0;
     490             : 
     491             : };
     492             : 
     493             : 
     494             : /** Encapsulates EditView and OutlinerView for the purpose of unified
     495             :     EditEngine/Outliner access
     496             :  */
     497          72 : class SvxEditViewForwarder : public SvxViewForwarder
     498             : {
     499             : public:
     500             : 
     501             :     /** Query current selection.
     502             : 
     503             :         @param rSelection
     504             :         Contains the current selection after method call
     505             : 
     506             :         @return false, if there is no view or no selection (the empty selection _is_ a selection)
     507             : 
     508             :      */
     509             :     virtual bool GetSelection( ESelection& rSelection ) const = 0;
     510             : 
     511             :     /** Set selection in view.
     512             : 
     513             :         @param rSelection
     514             :         The selection to set
     515             : 
     516             :         @return false, if there is no view or selection is invalid
     517             :      */
     518             :     virtual bool SetSelection( const ESelection& rSelection ) = 0;
     519             : 
     520             :     /** Copy current selection to clipboard.
     521             : 
     522             :         @return false if no selection or no view (the empty selection _is_ a selection)
     523             :      */
     524             :     virtual bool Copy() = 0;
     525             : 
     526             :     /** Cut current selection to clipboard.
     527             : 
     528             :         @eturn balse if no selection or no view (the empty selection _is_ a selection)
     529             :      */
     530             :     virtual bool Cut() = 0;
     531             : 
     532             :     /** Paste clipboard into current selection.
     533             : 
     534             :         @return false if no view or no selection (the empty selection _is_ a selection)
     535             :      */
     536             :     virtual bool Paste() = 0;
     537             : 
     538             : };
     539             : 
     540             : #endif
     541             : 
     542             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11