LibreOffice Module sw (master)  1
atrhndl.hxx
Go to the documentation of this file.
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 #pragma once
21 #define NUM_ATTRIBUTE_STACKS 44
22 
23 #include <memory>
24 #include <vector>
25 #include <swfntcch.hxx>
26 
27 class SwTextAttr;
28 class SwAttrSet;
30 class SwViewShell;
31 class SfxPoolItem;
32 extern const sal_uInt8 StackPos[];
33 
39 {
40 private:
41  std::vector<const SwTextAttr*> m_aAttrStack[NUM_ATTRIBUTE_STACKS]; // stack collection
45 
46  // This is the base font for the paragraph. It is stored in order to have
47  // a template, if we have to restart the attribute evaluation
48  std::unique_ptr<SwFont> m_pFnt;
49 
52 
53  const SwTextAttr* GetTop(sal_uInt16 nStack);
54  void RemoveFromStack(sal_uInt16 nWhich, const SwTextAttr& rAttr);
55 
56  // change font according to pool item
57  void FontChg(const SfxPoolItem& rItem, SwFont& rFnt, bool bPush );
58 
59  // push attribute to specified stack, returns true, if attribute has
60  // been pushed on top of stack (important for stacks containing different
61  // attributes with different priority and redlining)
62  bool Push( const SwTextAttr& rAttr, const SfxPoolItem& rItem );
63 
64  // apply top attribute on stack to font
65  void ActivateTop( SwFont& rFnt, sal_uInt16 nStackPos );
66 
67 public:
68  // Ctor
69  SwAttrHandler();
71 
72  // set default attributes to values in rAttrSet or from cache
73  void Init( const SwAttrSet& rAttrSet,
74  const IDocumentSettingAccess& rIDocumentSettingAccess );
75  void Init( const SfxPoolItem** pPoolItem, const SwAttrSet* pAttrSet,
76  const IDocumentSettingAccess& rIDocumentSettingAccess,
77  const SwViewShell* pShell, SwFont& rFnt,
78  bool bVertLayout, bool bVertLayoutLRBT );
79 
80  bool IsVertLayout() const { return m_bVertLayout; }
81 
82  // remove everything from internal stacks, keep default data
83  void Reset( );
84 
85  // insert specified attribute and change font
86  void PushAndChg( const SwTextAttr& rAttr, SwFont& rFnt );
87 
88  // remove specified attribute and reset font
89  void PopAndChg( const SwTextAttr& rAttr, SwFont& rFnt );
90  void Pop( const SwTextAttr& rAttr );
91 
92  // apply script dependent attributes
93  // void ChangeScript( SwFont& rFnt, const sal_uInt8 nScr );
94 
95  // do not call these if you only used the small init function
96  inline void ResetFont( SwFont& rFnt ) const;
97  inline const SwFont* GetFont() const;
98 
99  void GetDefaultAscentAndHeight(SwViewShell const * pShell,
100  OutputDevice const & rOut,
101  sal_uInt16& nAscent,
102  sal_uInt16& nHeight) const;
103 };
104 
105 inline void SwAttrHandler::ResetFont( SwFont& rFnt ) const
106 {
107  OSL_ENSURE(m_pFnt, "ResetFont without a font");
108  if (m_pFnt)
109  rFnt = *m_pFnt;
110 };
111 
112 inline const SwFont* SwAttrHandler::GetFont() const
113 {
114  return m_pFnt.get();
115 };
116 
117 
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void Pop(const SwTextAttr &rAttr)
Only used during redlining.
Definition: atrstck.cxx:467
void PopAndChg(const SwTextAttr &rAttr, SwFont &rFnt)
Definition: atrstck.cxx:427
void FontChg(const SfxPoolItem &rItem, SwFont &rFnt, bool bPush)
When popping an attribute from the stack, the top more remaining attribute in the stack becomes valid...
Definition: atrstck.cxx:570
const SfxPoolItem * m_pDefaultArray[NUM_DEFAULT_VALUES]
Definition: atrhndl.hxx:42
void ResetFont(SwFont &rFnt) const
Definition: atrhndl.hxx:105
#define NUM_DEFAULT_VALUES
Definition: swfntcch.hxx:22
const SwFont * GetFont() const
Definition: atrhndl.hxx:112
bool m_bVertLayoutLRBT
Definition: atrhndl.hxx:51
bool m_bVertLayout
Definition: atrhndl.hxx:50
Used by Attribute Iterators to organize attributes on stacks to find the valid attribute in each cate...
Definition: atrhndl.hxx:38
std::unique_ptr< SwFont > m_pFnt
Definition: atrhndl.hxx:48
const sal_uInt8 StackPos[]
Attribute to Stack Mapping.
Definition: atrstck.cxx:69
void Reset()
Definition: atrstck.cxx:336
void Init(const SwAttrSet &rAttrSet, const IDocumentSettingAccess &rIDocumentSettingAccess)
Definition: atrstck.cxx:278
#define NUM_ATTRIBUTE_STACKS
Definition: atrhndl.hxx:21
bool IsVertLayout() const
Definition: atrhndl.hxx:80
const IDocumentSettingAccess * m_pIDocumentSettingAccess
Definition: atrhndl.hxx:43
Provides access to settings of a document.
void RemoveFromStack(sal_uInt16 nWhich, const SwTextAttr &rAttr)
Definition: atrstck.cxx:419
void GetDefaultAscentAndHeight(SwViewShell const *pShell, OutputDevice const &rOut, sal_uInt16 &nAscent, sal_uInt16 &nHeight) const
Takes the default font and calculated the ascent and height.
Definition: atrstck.cxx:833
bool Push(const SwTextAttr &rAttr, const SfxPoolItem &rItem)
Definition: atrstck.cxx:391
const SwTextAttr * GetTop(sal_uInt16 nStack)
Definition: atrstck.cxx:386
const SwViewShell * m_pShell
Definition: atrhndl.hxx:44
unsigned char sal_uInt8
void ActivateTop(SwFont &rFnt, sal_uInt16 nStackPos)
Definition: atrstck.cxx:478
std::vector< const SwTextAttr * > m_aAttrStack[NUM_ATTRIBUTE_STACKS]
Definition: atrhndl.hxx:41
void PushAndChg(const SwTextAttr &rAttr, SwFont &rFnt)
Definition: atrstck.cxx:342