LCOV - code coverage report
Current view: top level - sw/source/core/text - atrhndl.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 11 11 100.0 %
Date: 2015-06-13 12:38:46 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_SW_SOURCE_CORE_TEXT_ATRHNDL_HXX
      21             : #define INCLUDED_SW_SOURCE_CORE_TEXT_ATRHNDL_HXX
      22             : 
      23             : #define INITIAL_NUM_ATTR 3
      24             : #define NUM_ATTRIBUTE_STACKS 44
      25             : 
      26             : #include <txatbase.hxx>
      27             : #include <swfntcch.hxx>
      28             : 
      29             : class SwAttrSet;
      30             : class IDocumentSettingAccess;
      31             : class SwViewShell;
      32             : class SfxPoolItem;
      33             : extern const sal_uInt8 StackPos[];
      34             : 
      35             : /**
      36             :  * Used by Attribute Iterators to organize attributes on stacks to
      37             :  * find the valid attribute in each category
      38             :  */
      39             : class SwAttrHandler
      40             : {
      41             : private:
      42             : 
      43             :     /// Container for SwTextAttr Objects
      44             :     class SwAttrStack
      45             :     {
      46             :     private:
      47             :         SwTextAttr* pInitialArray[ INITIAL_NUM_ATTR ];
      48             :         SwTextAttr** pArray;
      49             :         sal_uInt16 nCount; // number of elements on stack
      50             :         sal_uInt16 nSize;  // number of positions in Array
      51             : 
      52             :     public:
      53             :         // Ctor, Dtor
      54             :         inline SwAttrStack();
      55     8164244 :         inline ~SwAttrStack() {
      56     8164244 :             if ( nSize > INITIAL_NUM_ATTR ) delete [] pArray; }
      57             : 
      58             :         // reset stack
      59     2732840 :         inline void Reset() { nCount = 0; };
      60             : 
      61             :         // insert on top
      62      235544 :         inline void Push( const SwTextAttr& rAttr ) { Insert( rAttr, nCount ); };
      63             :         // insert at specified position, take care for not inserting behind
      64             :         // the value returned by Count()
      65             :         void Insert( const SwTextAttr& rAttr, const sal_uInt16 nPos );
      66             : 
      67             :         // remove specified attribute
      68             :         void Remove( const SwTextAttr& rAttr );
      69             : 
      70             :         // get attribute from top if exists, otherwise 0
      71             :         const SwTextAttr* Top() const;
      72             : 
      73             :         // number of elements on stack
      74        1416 :         inline sal_uInt16 Count() const { return nCount; };
      75             : 
      76             :         // returns position of rAttr on Stack if found, otherwise USHRT_MAX
      77             :         // can be used for Remove of an attribute
      78             :         sal_uInt16 Pos( const SwTextAttr& rAttr ) const;
      79             :     };
      80             : 
      81             :     SwAttrStack aAttrStack[ NUM_ATTRIBUTE_STACKS ]; // stack collection
      82             :     const SfxPoolItem* pDefaultArray[ NUM_DEFAULT_VALUES ];
      83             :     const IDocumentSettingAccess* mpIDocumentSettingAccess;
      84             :     const SwViewShell* mpShell;
      85             : 
      86             :     // This is the base font for the paragraph. It is stored in order to have
      87             :     // a template, if we have to restart the attribute evaluation
      88             :     SwFont* pFnt;
      89             : 
      90             :     bool bVertLayout;
      91             : 
      92             :     // change font according to pool item
      93             :     void FontChg(const SfxPoolItem& rItem, SwFont& rFnt, bool bPush );
      94             : 
      95             :     // push attribute to specified stack, returns true, if attribute has
      96             :     // been pushed on top of stack (important for stacks containing different
      97             :     // attributes with different priority and redlining)
      98             :     bool Push( const SwTextAttr& rAttr, const SfxPoolItem& rItem );
      99             : 
     100             :     // apply top attribute on stack to font
     101             :     void ActivateTop( SwFont& rFnt, sal_uInt16 nStackPos );
     102             : 
     103             : public:
     104             :     // Ctor
     105             :     SwAttrHandler();
     106             :     ~SwAttrHandler();
     107             : 
     108             :     // set default attributes to values in rAttrSet or from cache
     109             :     void Init( const SwAttrSet& rAttrSet,
     110             :                const IDocumentSettingAccess& rIDocumentSettingAccess,
     111             :                const SwViewShell* pShell );
     112             :     void Init( const SfxPoolItem** pPoolItem, const SwAttrSet* pAttrSet,
     113             :                const IDocumentSettingAccess& rIDocumentSettingAccess,
     114             :                const SwViewShell* pShell, SwFont& rFnt,
     115             :                bool bVertLayout );
     116             : 
     117             :     // remove everything from internal stacks, keep default data
     118             :     void Reset( );
     119             : 
     120             :     // insert specified attribute and change font
     121             :     void PushAndChg( const SwTextAttr& rAttr, SwFont& rFnt );
     122             : 
     123             :     // remove specified attribute and reset font
     124             :     void PopAndChg( const SwTextAttr& rAttr, SwFont& rFnt );
     125             :     void Pop( const SwTextAttr& rAttr );
     126             : 
     127             :     // apply script dependent attributes
     128             :     // void ChangeScript( SwFont& rFnt, const sal_uInt8 nScr );
     129             : 
     130             :     // returns the default value for stack nStack
     131             :     inline const SfxPoolItem& GetDefault( const sal_uInt16 nAttribID ) const;
     132             :     // do not call these if you only used the small init function
     133             :     inline void ResetFont( SwFont& rFnt ) const;
     134             :     inline const SwFont* GetFont() const;
     135             : 
     136             :     void GetDefaultAscentAndHeight(SwViewShell* pShell,
     137             :                                    OutputDevice& rOut,
     138             :                                    sal_uInt16& nAscent,
     139             :                                    sal_uInt16& nHeight) const;
     140             : };
     141             : 
     142             : inline const SfxPoolItem& SwAttrHandler::GetDefault( const sal_uInt16 nAttribID ) const
     143             : {
     144             :     OSL_ENSURE( nAttribID < RES_TXTATR_END,
     145             :             "this attrib does not ex."
     146             :             );
     147             :     OSL_ENSURE( pDefaultArray[ StackPos[ nAttribID ] ], "array not initialized" );
     148             :     return *pDefaultArray[ StackPos[ nAttribID ] ];
     149             : }
     150             : 
     151       62110 : inline void SwAttrHandler::ResetFont( SwFont& rFnt ) const
     152             : {
     153             :     OSL_ENSURE( pFnt, "ResetFont without a font" );
     154       62110 :     if ( pFnt )
     155       62110 :         rFnt = *pFnt;
     156       62110 : };
     157             : 
     158         623 : inline const SwFont* SwAttrHandler::GetFont() const
     159             : {
     160         623 :     return pFnt;
     161             : };
     162             : 
     163             : #endif
     164             : 
     165             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11