1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _ATRHNDL_HXX 29 #define _ATRHNDL_HXX 30 31 #define INITIAL_NUM_ATTR 3 32 #define NUM_ATTRIBUTE_STACKS 40 33 34 #include <txatbase.hxx> 35 #include <swfntcch.hxx> 36 37 class SwAttrSet; 38 class IDocumentSettingAccess; 39 class ViewShell; 40 class SfxPoolItem; 41 extern const sal_uInt8 StackPos[]; 42 43 /************************************************************************* 44 * class SwAttrHandler 45 * 46 * Used by Attribute Iterators to organize attributes on stacks to 47 * find the valid attribute in each category 48 *************************************************************************/ 49 50 class SwAttrHandler 51 { 52 private: 53 54 /************************************************************************* 55 * class SwAttrStack 56 * 57 * Container for SwTxtAttr Objects 58 *************************************************************************/ 59 60 class SwAttrStack 61 { 62 private: 63 SwTxtAttr* pInitialArray[ INITIAL_NUM_ATTR ]; 64 SwTxtAttr** pArray; 65 sal_uInt16 nCount; // number of elements on stack 66 sal_uInt16 nSize; // number of positions in Array 67 68 public: 69 // Ctor, Dtor 70 inline SwAttrStack(); 71 inline ~SwAttrStack() { 72 if ( nSize > INITIAL_NUM_ATTR ) delete [] pArray; } 73 74 // reset stack 75 inline void Reset() { nCount = 0; }; 76 77 // insert on top 78 inline void Push( const SwTxtAttr& rAttr ) { Insert( rAttr, nCount ); }; 79 // insert at specified position, take care for not inserting behind 80 // the value returned by Count() 81 void Insert( const SwTxtAttr& rAttr, const sal_uInt16 nPos ); 82 83 // remove specified attribute 84 void Remove( const SwTxtAttr& rAttr ); 85 86 // get attribute from top if exists, otherwise 0 87 const SwTxtAttr* Top() const; 88 89 // number of elements on stack 90 inline sal_uInt16 Count() const { return nCount; }; 91 92 // returns position of rAttr on Stack if found, otherwise USHRT_MAX 93 // can be used for Remove of an attribute 94 sal_uInt16 Pos( const SwTxtAttr& rAttr ) const; 95 }; 96 97 SwAttrStack aAttrStack[ NUM_ATTRIBUTE_STACKS ]; // stack collection 98 const SfxPoolItem* pDefaultArray[ NUM_DEFAULT_VALUES ]; 99 const IDocumentSettingAccess* mpIDocumentSettingAccess; 100 const ViewShell* mpShell; 101 102 // This is the base font for the paragraph. It is stored in order to have 103 // a template, if we have to restart the attribute evaluation 104 SwFont* pFnt; 105 106 sal_Bool bVertLayout; 107 108 // change font according to pool item 109 void FontChg(const SfxPoolItem& rItem, SwFont& rFnt, sal_Bool bPush ); 110 111 // push attribute to specified stack, returns true, if attribute has 112 // been pushed on top of stack (important for stacks containing different 113 // attributes with different priority and redlining) 114 sal_Bool Push( const SwTxtAttr& rAttr, const SfxPoolItem& rItem ); 115 116 // apply top attribute on stack to font 117 void ActivateTop( SwFont& rFnt, sal_uInt16 nStackPos ); 118 119 public: 120 // Ctor 121 SwAttrHandler(); 122 ~SwAttrHandler(); 123 124 // set default attributes to values in rAttrSet or from cache 125 void Init( const SwAttrSet& rAttrSet, 126 const IDocumentSettingAccess& rIDocumentSettingAccess, 127 const ViewShell* pShell ); 128 void Init( const SfxPoolItem** pPoolItem, const SwAttrSet* pAttrSet, 129 const IDocumentSettingAccess& rIDocumentSettingAccess, 130 const ViewShell* pShell, SwFont& rFnt, 131 sal_Bool bVertLayout ); 132 133 // remove everything from internal stacks, keep default data 134 void Reset( ); 135 136 // insert specified attribute and change font 137 void PushAndChg( const SwTxtAttr& rAttr, SwFont& rFnt ); 138 139 // remove specified attribute and reset font 140 void PopAndChg( const SwTxtAttr& rAttr, SwFont& rFnt ); 141 void Pop( const SwTxtAttr& rAttr ); 142 143 // apply script dependent attributes 144 // void ChangeScript( SwFont& rFnt, const sal_uInt8 nScr ); 145 146 // returns the default value for stack nStack 147 inline const SfxPoolItem& GetDefault( const sal_uInt16 nAttribID ) const; 148 // do not call these if you only used the small init function 149 inline void ResetFont( SwFont& rFnt ) const; 150 inline const SwFont* GetFont() const; 151 152 void GetDefaultAscentAndHeight(ViewShell* pShell, 153 OutputDevice& rOut, 154 sal_uInt16& nAscent, 155 sal_uInt16& nHeight) const; 156 }; 157 158 inline const SfxPoolItem& SwAttrHandler::GetDefault( const sal_uInt16 nAttribID ) const 159 { 160 ASSERT( nAttribID < RES_TXTATR_END, 161 "this attrib does not ex." 162 ); 163 ASSERT( pDefaultArray[ StackPos[ nAttribID ] ], "array not initialized" ); 164 return *pDefaultArray[ StackPos[ nAttribID ] ]; 165 } 166 167 inline void SwAttrHandler::ResetFont( SwFont& rFnt ) const 168 { 169 ASSERT( pFnt, "ResetFont without a font" ); 170 if ( pFnt ) 171 rFnt = *pFnt; 172 }; 173 174 inline const SwFont* SwAttrHandler::GetFont() const 175 { 176 return pFnt; 177 }; 178 179 #endif 180