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