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