11d2dbeb0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
31d2dbeb0SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
41d2dbeb0SAndrew Rist * or more contributor license agreements. See the NOTICE file
51d2dbeb0SAndrew Rist * distributed with this work for additional information
61d2dbeb0SAndrew Rist * regarding copyright ownership. The ASF licenses this file
71d2dbeb0SAndrew Rist * to you under the Apache License, Version 2.0 (the
81d2dbeb0SAndrew Rist * "License"); you may not use this file except in compliance
91d2dbeb0SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
111d2dbeb0SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
131d2dbeb0SAndrew Rist * Unless required by applicable law or agreed to in writing,
141d2dbeb0SAndrew Rist * software distributed under the License is distributed on an
151d2dbeb0SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
161d2dbeb0SAndrew Rist * KIND, either express or implied. See the License for the
171d2dbeb0SAndrew Rist * specific language governing permissions and limitations
181d2dbeb0SAndrew Rist * under the License.
19cdf0e10cSrcweir *
201d2dbeb0SAndrew Rist *************************************************************/
211d2dbeb0SAndrew Rist
221d2dbeb0SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #ifndef _ATRHNDL_HXX
25cdf0e10cSrcweir #define _ATRHNDL_HXX
26cdf0e10cSrcweir
27cdf0e10cSrcweir #define INITIAL_NUM_ATTR 3
28*69a74367SOliver-Rainer Wittmann #define NUM_ATTRIBUTE_STACKS 41
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include <txatbase.hxx>
31cdf0e10cSrcweir #include <swfntcch.hxx>
32cdf0e10cSrcweir
33cdf0e10cSrcweir class SwAttrSet;
34cdf0e10cSrcweir class IDocumentSettingAccess;
35cdf0e10cSrcweir class ViewShell;
36cdf0e10cSrcweir class SfxPoolItem;
37cdf0e10cSrcweir extern const sal_uInt8 StackPos[];
38cdf0e10cSrcweir
39cdf0e10cSrcweir /*************************************************************************
40cdf0e10cSrcweir * class SwAttrHandler
41cdf0e10cSrcweir *
42cdf0e10cSrcweir * Used by Attribute Iterators to organize attributes on stacks to
43cdf0e10cSrcweir * find the valid attribute in each category
44cdf0e10cSrcweir *************************************************************************/
45cdf0e10cSrcweir
46cdf0e10cSrcweir class SwAttrHandler
47cdf0e10cSrcweir {
48cdf0e10cSrcweir private:
49cdf0e10cSrcweir
50cdf0e10cSrcweir /*************************************************************************
51cdf0e10cSrcweir * class SwAttrStack
52cdf0e10cSrcweir *
53cdf0e10cSrcweir * Container for SwTxtAttr Objects
54cdf0e10cSrcweir *************************************************************************/
55cdf0e10cSrcweir
56cdf0e10cSrcweir class SwAttrStack
57cdf0e10cSrcweir {
58cdf0e10cSrcweir private:
59cdf0e10cSrcweir SwTxtAttr* pInitialArray[ INITIAL_NUM_ATTR ];
60cdf0e10cSrcweir SwTxtAttr** pArray;
61cdf0e10cSrcweir sal_uInt16 nCount; // number of elements on stack
62cdf0e10cSrcweir sal_uInt16 nSize; // number of positions in Array
63cdf0e10cSrcweir
64cdf0e10cSrcweir public:
65cdf0e10cSrcweir // Ctor, Dtor
66cdf0e10cSrcweir inline SwAttrStack();
~SwAttrStack()67cdf0e10cSrcweir inline ~SwAttrStack() {
68cdf0e10cSrcweir if ( nSize > INITIAL_NUM_ATTR ) delete [] pArray; }
69cdf0e10cSrcweir
70cdf0e10cSrcweir // reset stack
Reset()71cdf0e10cSrcweir inline void Reset() { nCount = 0; };
72cdf0e10cSrcweir
73cdf0e10cSrcweir // insert on top
Push(const SwTxtAttr & rAttr)74cdf0e10cSrcweir inline void Push( const SwTxtAttr& rAttr ) { Insert( rAttr, nCount ); };
75cdf0e10cSrcweir // insert at specified position, take care for not inserting behind
76cdf0e10cSrcweir // the value returned by Count()
77cdf0e10cSrcweir void Insert( const SwTxtAttr& rAttr, const sal_uInt16 nPos );
78cdf0e10cSrcweir
79cdf0e10cSrcweir // remove specified attribute
80cdf0e10cSrcweir void Remove( const SwTxtAttr& rAttr );
81cdf0e10cSrcweir
82cdf0e10cSrcweir // get attribute from top if exists, otherwise 0
83cdf0e10cSrcweir const SwTxtAttr* Top() const;
84cdf0e10cSrcweir
85cdf0e10cSrcweir // number of elements on stack
Count() const86cdf0e10cSrcweir inline sal_uInt16 Count() const { return nCount; };
87cdf0e10cSrcweir
88cdf0e10cSrcweir // returns position of rAttr on Stack if found, otherwise USHRT_MAX
89cdf0e10cSrcweir // can be used for Remove of an attribute
90cdf0e10cSrcweir sal_uInt16 Pos( const SwTxtAttr& rAttr ) const;
91cdf0e10cSrcweir };
92cdf0e10cSrcweir
93cdf0e10cSrcweir SwAttrStack aAttrStack[ NUM_ATTRIBUTE_STACKS ]; // stack collection
94cdf0e10cSrcweir const SfxPoolItem* pDefaultArray[ NUM_DEFAULT_VALUES ];
95cdf0e10cSrcweir const IDocumentSettingAccess* mpIDocumentSettingAccess;
96cdf0e10cSrcweir const ViewShell* mpShell;
97cdf0e10cSrcweir
98cdf0e10cSrcweir // This is the base font for the paragraph. It is stored in order to have
99cdf0e10cSrcweir // a template, if we have to restart the attribute evaluation
100cdf0e10cSrcweir SwFont* pFnt;
101cdf0e10cSrcweir
102cdf0e10cSrcweir sal_Bool bVertLayout;
103cdf0e10cSrcweir
104cdf0e10cSrcweir // change font according to pool item
105cdf0e10cSrcweir void FontChg(const SfxPoolItem& rItem, SwFont& rFnt, sal_Bool bPush );
106cdf0e10cSrcweir
107cdf0e10cSrcweir // push attribute to specified stack, returns true, if attribute has
108cdf0e10cSrcweir // been pushed on top of stack (important for stacks containing different
109cdf0e10cSrcweir // attributes with different priority and redlining)
110cdf0e10cSrcweir sal_Bool Push( const SwTxtAttr& rAttr, const SfxPoolItem& rItem );
111cdf0e10cSrcweir
112cdf0e10cSrcweir // apply top attribute on stack to font
113cdf0e10cSrcweir void ActivateTop( SwFont& rFnt, sal_uInt16 nStackPos );
114cdf0e10cSrcweir
115cdf0e10cSrcweir public:
116cdf0e10cSrcweir // Ctor
117cdf0e10cSrcweir SwAttrHandler();
118cdf0e10cSrcweir ~SwAttrHandler();
119cdf0e10cSrcweir
120cdf0e10cSrcweir // set default attributes to values in rAttrSet or from cache
121cdf0e10cSrcweir void Init( const SwAttrSet& rAttrSet,
122cdf0e10cSrcweir const IDocumentSettingAccess& rIDocumentSettingAccess,
123cdf0e10cSrcweir const ViewShell* pShell );
124cdf0e10cSrcweir void Init( const SfxPoolItem** pPoolItem, const SwAttrSet* pAttrSet,
125cdf0e10cSrcweir const IDocumentSettingAccess& rIDocumentSettingAccess,
126cdf0e10cSrcweir const ViewShell* pShell, SwFont& rFnt,
127cdf0e10cSrcweir sal_Bool bVertLayout );
128cdf0e10cSrcweir
129cdf0e10cSrcweir // remove everything from internal stacks, keep default data
130cdf0e10cSrcweir void Reset( );
131cdf0e10cSrcweir
132cdf0e10cSrcweir // insert specified attribute and change font
133cdf0e10cSrcweir void PushAndChg( const SwTxtAttr& rAttr, SwFont& rFnt );
134cdf0e10cSrcweir
135cdf0e10cSrcweir // remove specified attribute and reset font
136cdf0e10cSrcweir void PopAndChg( const SwTxtAttr& rAttr, SwFont& rFnt );
137cdf0e10cSrcweir void Pop( const SwTxtAttr& rAttr );
138cdf0e10cSrcweir
139cdf0e10cSrcweir // apply script dependent attributes
140cdf0e10cSrcweir // void ChangeScript( SwFont& rFnt, const sal_uInt8 nScr );
141cdf0e10cSrcweir
142cdf0e10cSrcweir // returns the default value for stack nStack
143cdf0e10cSrcweir inline const SfxPoolItem& GetDefault( const sal_uInt16 nAttribID ) const;
144cdf0e10cSrcweir // do not call these if you only used the small init function
145cdf0e10cSrcweir inline void ResetFont( SwFont& rFnt ) const;
146cdf0e10cSrcweir inline const SwFont* GetFont() const;
147cdf0e10cSrcweir
148cdf0e10cSrcweir void GetDefaultAscentAndHeight(ViewShell* pShell,
149cdf0e10cSrcweir OutputDevice& rOut,
150cdf0e10cSrcweir sal_uInt16& nAscent,
151cdf0e10cSrcweir sal_uInt16& nHeight) const;
152cdf0e10cSrcweir };
153cdf0e10cSrcweir
GetDefault(const sal_uInt16 nAttribID) const154cdf0e10cSrcweir inline const SfxPoolItem& SwAttrHandler::GetDefault( const sal_uInt16 nAttribID ) const
155cdf0e10cSrcweir {
156cdf0e10cSrcweir ASSERT( nAttribID < RES_TXTATR_END,
157cdf0e10cSrcweir "this attrib does not ex."
158cdf0e10cSrcweir );
159cdf0e10cSrcweir ASSERT( pDefaultArray[ StackPos[ nAttribID ] ], "array not initialized" );
160cdf0e10cSrcweir return *pDefaultArray[ StackPos[ nAttribID ] ];
161cdf0e10cSrcweir }
162cdf0e10cSrcweir
ResetFont(SwFont & rFnt) const163cdf0e10cSrcweir inline void SwAttrHandler::ResetFont( SwFont& rFnt ) const
164cdf0e10cSrcweir {
165cdf0e10cSrcweir ASSERT( pFnt, "ResetFont without a font" );
166cdf0e10cSrcweir if ( pFnt )
167cdf0e10cSrcweir rFnt = *pFnt;
168cdf0e10cSrcweir };
169cdf0e10cSrcweir
GetFont() const170cdf0e10cSrcweir inline const SwFont* SwAttrHandler::GetFont() const
171cdf0e10cSrcweir {
172cdf0e10cSrcweir return pFnt;
173cdf0e10cSrcweir };
174cdf0e10cSrcweir
175cdf0e10cSrcweir #endif
176