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

Generated by: LCOV version 1.10