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

Generated by: LCOV version 1.10