LCOV - code coverage report
Current view: top level - sc/inc - editutil.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 10 12 83.3 %
Date: 2015-06-13 12:38:46 Functions: 16 18 88.9 %
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_SC_INC_EDITUTIL_HXX
      21             : #define INCLUDED_SC_INC_EDITUTIL_HXX
      22             : 
      23             : #include "scdllapi.h"
      24             : #include "address.hxx"
      25             : #include <editeng/editeng.hxx>
      26             : #include <svx/pageitem.hxx>
      27             : #include <tools/date.hxx>
      28             : #include <tools/time.hxx>
      29             : #include <tools/gen.hxx>
      30             : #include <tools/fract.hxx>
      31             : #include <vcl/outdev.hxx>
      32             : 
      33             : class ScDocument;
      34             : class ScPatternAttr;
      35             : class ScEditEngineDefaulter;
      36             : 
      37           0 : class ScEditUtil
      38             : {
      39             :     ScDocument*     pDoc;
      40             :     SCCOL           nCol;
      41             :     SCROW           nRow;
      42             :     SCTAB           nTab;
      43             :     Point           aScrPos;
      44             :     VclPtr<OutputDevice> pDev; // MapMode has to be set
      45             :     double          nPPTX;
      46             :     double          nPPTY;
      47             :     Fraction        aZoomX;
      48             :     Fraction        aZoomY;
      49             : 
      50             : public:
      51             :     static OUString ModifyDelimiters( const OUString& rOld );
      52             : 
      53             :     /// Retrieves string with paragraphs delimited by spaces
      54             :     static OUString GetSpaceDelimitedString( const EditEngine& rEngine );
      55             : 
      56             :     /// Retrieves string with paragraphs delimited by new lines ('\n').
      57             :     static OUString GetMultilineString( const EditEngine& rEngine );
      58             :     static OUString GetMultilineString( const EditTextObject& rEdit );
      59             : 
      60             :     /** Retrieves string with paragraphs delimited by new lines ('\n').
      61             : 
      62             :         @param pDoc
      63             :                If not NULL, use pDoc->GetEditEngine() to retrieve field content.
      64             :                If NULL, a static mutex-guarded ScFieldEditEngine is used that
      65             :                is not capable of resolving document specific fields; avoid.
      66             :      */
      67             :     SC_DLLPUBLIC static OUString GetString( const EditTextObject& rEditText, const ScDocument* pDoc );
      68             : 
      69             :     static EditTextObject* CreateURLObjectFromURL(
      70             :         ScDocument& rDoc, const OUString& rURL, const OUString& rText );
      71             : 
      72             :     static void RemoveCharAttribs( EditTextObject& rEditText, const ScPatternAttr& rAttr );
      73             : 
      74             :     static EditTextObject* Clone( const EditTextObject& rSrc, ScDocument& rDestDoc );
      75             : 
      76             :     static OUString GetCellFieldValue(
      77             :         const SvxFieldData& rFieldData, const ScDocument* pDoc, Color** ppTextColor );
      78             : 
      79             : public:
      80             :                 ScEditUtil( ScDocument* pDocument, SCCOL nX, SCROW nY, SCTAB nZ,
      81             :                             const Point& rScrPosPixel,
      82             :                             OutputDevice* pDevice, double nScaleX, double nScaleY,
      83             :                             const Fraction& rX, const Fraction& rY );
      84             : 
      85             :     Rectangle   GetEditArea( const ScPatternAttr* pPattern, bool bForceToTop );
      86             : };
      87             : 
      88             : class ScEditAttrTester
      89             : {
      90             :     ScEditEngineDefaulter* pEngine;
      91             :     SfxItemSet* pEditAttrs;
      92             :     bool        bNeedsObject;
      93             :     bool        bNeedsCellAttr;
      94             : 
      95             : public:
      96             :                 ScEditAttrTester( ScEditEngineDefaulter* pEng );
      97             :                 ~ScEditAttrTester();
      98             : 
      99         220 :     bool                NeedsObject() const     { return bNeedsObject; }
     100         220 :     bool                NeedsCellAttr() const   { return bNeedsCellAttr; }
     101         176 :     const SfxItemSet&   GetAttribs() const      { return *pEditAttrs; }
     102             : };
     103             : 
     104             : // construct pool before constructing EditEngine, destroy pool after EditEngine
     105             : class ScEnginePoolHelper
     106             : {
     107             : protected:
     108             :     SfxItemPool*    pEnginePool;
     109             :     SfxItemSet*     pDefaults;
     110             :     bool            bDeleteEnginePool;
     111             :     bool            bDeleteDefaults;
     112             : 
     113             :                     ScEnginePoolHelper( SfxItemPool* pEnginePool,
     114             :                         bool bDeleteEnginePool = false );
     115             :                     ScEnginePoolHelper( const ScEnginePoolHelper& rOrg );
     116             :     virtual         ~ScEnginePoolHelper();
     117             : };
     118             : 
     119             : class SC_DLLPUBLIC ScEditEngineDefaulter : public ScEnginePoolHelper, public EditEngine
     120             : {
     121             : private:
     122             :     using EditEngine::SetText;
     123             : 
     124             : public:
     125             :                     /// bDeleteEnginePool: Engine becomes the owner of the pool
     126             :                     /// and deletes it on destruction
     127             :                     ScEditEngineDefaulter( SfxItemPool* pEnginePool,
     128             :                         bool bDeleteEnginePool = false );
     129             :                     /// If rOrg.bDeleteEnginePool: pool gets cloned and will be
     130             :                     /// deleted on destruction. Defaults are not set.
     131             :                     ScEditEngineDefaulter( const ScEditEngineDefaulter& rOrg );
     132             :     virtual         ~ScEditEngineDefaulter();
     133             : 
     134             :                     /// Creates a copy of SfxItemSet if bRememberCopy set
     135             :     void            SetDefaults( const SfxItemSet& rDefaults, bool bRememberCopy = true );
     136             : 
     137             :                     /// Becomes the owner of the SfxItemSet if bTakeOwnership set
     138             :     void            SetDefaults( SfxItemSet* pDefaults, bool bTakeOwnership = true );
     139             : 
     140             :                     /// Set the item in the default ItemSet which is created
     141             :                     /// if it doesn't exist yet.
     142             :                     /// The default ItemSet is then applied to each paragraph.
     143             :     void            SetDefaultItem( const SfxPoolItem& rItem );
     144             : 
     145             :                     /// Returns the stored defaults, used to find non-default character attributes
     146             :     const SfxItemSet& GetDefaults();
     147             : 
     148             :                     /// Overwritten method to be able to apply defaults already set
     149             :     void            SetText( const EditTextObject& rTextObject );
     150             :                     /// Current defaults are not applied, new defaults are applied
     151             :     void            SetTextNewDefaults( const EditTextObject& rTextObject,
     152             :                         const SfxItemSet& rDefaults, bool bRememberCopy = true );
     153             :                     /// Current defaults are not applied, new defaults are applied
     154             :     void            SetTextNewDefaults( const EditTextObject& rTextObject,
     155             :                         SfxItemSet* pDefaults, bool bTakeOwnership = true );
     156             : 
     157             :                     /// Overwritten method to be able to apply defaults already set
     158             :     void            SetText( const OUString& rText );
     159             :                     /// Current defaults are not applied, new defaults are applied
     160             :     void            SetTextNewDefaults( const OUString& rText,
     161             :                         const SfxItemSet& rDefaults, bool bRememberCopy = true );
     162             :                     /// Current defaults are not applied, new defaults are applied
     163             :     void            SetTextNewDefaults( const OUString& rText,
     164             :                         SfxItemSet* pDefaults, bool bTakeOwnership = true );
     165             : 
     166             :                     /// Paragraph attributes that are not defaults are copied to
     167             :                     /// character attributes and all paragraph attributes reset
     168             :     void            RemoveParaAttribs();
     169             : 
     170             :                     /// Re-apply existing defaults if set, same as in SetText,
     171             :                     /// but without EnableUndo/SetUpdateMode.
     172             :     void            RepeatDefaults();
     173             : };
     174             : 
     175             : // 1/100 mm
     176        1158 : class SC_DLLPUBLIC ScTabEditEngine : public ScEditEngineDefaulter
     177             : {
     178             : private:
     179             :     void    Init(const ScPatternAttr& rPattern);
     180             : public:
     181             :     ScTabEditEngine( ScDocument* pDoc );            // Default
     182             :     ScTabEditEngine( const ScPatternAttr& rPattern,
     183             :                     SfxItemPool* pEnginePool,
     184             :                     SfxItemPool* pTextObjectPool = NULL );
     185             : };
     186             : 
     187       12746 : struct ScHeaderFieldData
     188             : {
     189             :     OUString    aTitle;             // title or file name (if no title)
     190             :     OUString    aLongDocName;       // path and file name
     191             :     OUString    aShortDocName;      // pure file name
     192             :     OUString    aTabName;
     193             :     Date        aDate;
     194             :     tools::Time aTime;
     195             :     long        nPageNo;
     196             :     long        nTotalPages;
     197             :     SvxNumType  eNumType;
     198             : 
     199             :     ScHeaderFieldData();
     200             : };
     201             : 
     202             : // for field commands (or just fields?) in a table
     203        2356 : class SC_DLLPUBLIC ScFieldEditEngine : public ScEditEngineDefaulter
     204             : {
     205             : private:
     206             :     ScDocument* mpDoc;
     207             :     bool bExecuteURL;
     208             : 
     209             : public:
     210             :     ScFieldEditEngine(
     211             :         ScDocument* pDoc, SfxItemPool* pEnginePool, SfxItemPool* pTextObjectPool = NULL,
     212             :         bool bDeleteEnginePool = false);
     213             : 
     214         239 :     void SetExecuteURL(bool bSet)    { bExecuteURL = bSet; }
     215             : 
     216             :     virtual void    FieldClicked( const SvxFieldItem& rField, sal_Int32, sal_Int32 ) SAL_OVERRIDE;
     217             :     virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rTxtColor, Color*& rFldColor ) SAL_OVERRIDE;
     218             : };
     219             : 
     220             : // for headers/footers with fields
     221        6542 : class SC_DLLPUBLIC ScHeaderEditEngine : public ScEditEngineDefaulter
     222             : {
     223             : private:
     224             :     ScHeaderFieldData   aData;
     225             : 
     226             : public:
     227             :     ScHeaderEditEngine( SfxItemPool* pEnginePool, bool bDeleteEnginePool = false );
     228             :     virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rTxtColor, Color*& rFldColor ) SAL_OVERRIDE;
     229             : 
     230           0 :     void SetNumType(SvxNumType eNew)                { aData.eNumType = eNew; }
     231        3642 :     void SetData(const ScHeaderFieldData& rNew)     { aData = rNew; }
     232             : };
     233             : 
     234             : // for Note text objects.
     235          24 : class ScNoteEditEngine : public ScEditEngineDefaulter
     236             : {
     237             : 
     238             : public:
     239             :     ScNoteEditEngine( SfxItemPool* pEnginePool,
     240             :                 SfxItemPool* pTextObjectPool = NULL,
     241             :                 bool bDeleteEnginePool = false );
     242             : 
     243             : };
     244             : 
     245             : //  SvxFieldData derivations were moved to Svx (comment can be deleted?)
     246             : 
     247             : #endif
     248             : 
     249             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11