LibreOffice Module sc (master)  1
autoform.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 #ifndef INCLUDED_SC_INC_AUTOFORM_HXX
21 #define INCLUDED_SC_INC_AUTOFORM_HXX
22 
23 /*************************************************************************
24 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
25 
26  The structure of auto formatting should not be changed. It is used
27  by various code of Writer and Calc. If a change is necessary, the
28  source code of both applications must be changed!
29 
30 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
31 **************************************************************************/
32 
33 #include <svl/poolitem.hxx>
34 #include <svx/autoformathelper.hxx>
35 
36 #include "scdllapi.h"
37 #include "zforauto.hxx"
38 
39 #include <array>
40 #include <memory>
41 #include <map>
42 #include <climits>
43 
44 class ScDocument;
45 
56 {
57  std::unique_ptr<sal_uInt8[]> pData;
58  std::size_t size;
59 
60  AutoFormatSwBlob() : size(0)
61  {
62  }
63  AutoFormatSwBlob(const AutoFormatSwBlob&) = delete;
64  const AutoFormatSwBlob& operator=(const AutoFormatSwBlob&) = delete;
65 
66  void Reset()
67  {
68  pData.reset();
69  size = 0;
70  }
71 };
72 
75 {
76 public:
78 
79  ScAfVersions();
80 
81  void Load( SvStream& rStream, sal_uInt16 nVer );
82  void Write(SvStream& rStream, sal_uInt16 fileVersion);
83 };
84 
87 {
88 private:
90 
91  // number format
93 
94 public:
98 
99  // block assignment operator
101 
102  // number format
103  const ScNumFormatAbbrev& GetNumFormat() const { return aNumFormat; }
104 
105  // number format
106  void SetNumFormat( const ScNumFormatAbbrev& rNumFormat ) { aNumFormat = rNumFormat; }
107 
108  bool Load( SvStream& rStream, const ScAfVersions& rVersions, sal_uInt16 nVer );
109  bool Save( SvStream& rStream, sal_uInt16 fileVersion );
110 };
111 
113 {
114 private:
115  OUString aName;
116  sal_uInt16 nStrResId;
117  // common flags of Calc and Writer
118  bool bIncludeFont : 1;
119  bool bIncludeJustify : 1;
120  bool bIncludeFrame : 1;
121  bool bIncludeBackground : 1;
122 
123  // Calc specific flags
124  bool bIncludeValueFormat : 1;
125  bool bIncludeWidthHeight : 1;
126 
127  // Writer-specific data
129 
130  std::array<std::unique_ptr<ScAutoFormatDataField>,16> ppDataField;
131 
132  SAL_DLLPRIVATE ScAutoFormatDataField& GetField( sal_uInt16 nIndex );
133  SAL_DLLPRIVATE const ScAutoFormatDataField& GetField( sal_uInt16 nIndex ) const;
134 
135 public:
137  ScAutoFormatData( const ScAutoFormatData& rData );
138  ~ScAutoFormatData();
139 
140  void SetName( const OUString& rName ) { aName = rName; nStrResId = USHRT_MAX; }
141  const OUString& GetName() const { return aName; }
142 
143  bool GetIncludeValueFormat() const { return bIncludeValueFormat; }
144  bool GetIncludeFont() const { return bIncludeFont; }
145  bool GetIncludeJustify() const { return bIncludeJustify; }
146  bool GetIncludeFrame() const { return bIncludeFrame; }
147  bool GetIncludeBackground() const { return bIncludeBackground; }
148  bool GetIncludeWidthHeight() const { return bIncludeWidthHeight; }
149 
150  void SetIncludeValueFormat( bool bValueFormat ) { bIncludeValueFormat = bValueFormat; }
151  void SetIncludeFont( bool bFont ) { bIncludeFont = bFont; }
152  void SetIncludeJustify( bool bJustify ) { bIncludeJustify = bJustify; }
153  void SetIncludeFrame( bool bFrame ) { bIncludeFrame = bFrame; }
154  void SetIncludeBackground( bool bBackground ) { bIncludeBackground = bBackground; }
155  void SetIncludeWidthHeight( bool bWidthHeight ) { bIncludeWidthHeight = bWidthHeight; }
156 
157  const SfxPoolItem* GetItem( sal_uInt16 nIndex, sal_uInt16 nWhich ) const;
158  template<class T> const T* GetItem( sal_uInt16 nIndex, TypedWhichId<T> nWhich ) const
159  {
160  return static_cast<const T*>(GetItem(nIndex, sal_uInt16(nWhich)));
161  }
162  void PutItem( sal_uInt16 nIndex, const SfxPoolItem& rItem );
163  void CopyItem( sal_uInt16 nToIndex, sal_uInt16 nFromIndex, sal_uInt16 nWhich );
164 
165  const ScNumFormatAbbrev& GetNumFormat( sal_uInt16 nIndex ) const;
166 
167  bool IsEqualData( sal_uInt16 nIndex1, sal_uInt16 nIndex2 ) const;
168 
169  void FillToItemSet( sal_uInt16 nIndex, SfxItemSet& rItemSet, const ScDocument& rDoc ) const;
170  void GetFromItemSet( sal_uInt16 nIndex, const SfxItemSet& rItemSet, const ScNumFormatAbbrev& rNumFormat );
171 
172  bool Load( SvStream& rStream, const ScAfVersions& rVersions );
173  bool Save( SvStream& rStream, sal_uInt16 fileVersion );
174 };
175 
177  bool operator() (const OUString& left, const OUString& right) const;
178 };
179 
181 {
182  typedef std::map<OUString, std::unique_ptr<ScAutoFormatData>, DefaultFirstEntry> MapType;
183  MapType m_Data;
186 
187  ScAutoFormat(const ScAutoFormat&) = delete;
188  const ScAutoFormat operator=(const ScAutoFormat&) = delete;
189 
190 public:
191  typedef MapType::const_iterator const_iterator;
192  typedef MapType::iterator iterator;
193 
194  ScAutoFormat();
195  void Load();
196  bool Save();
197 
198  void SetSaveLater( bool bSet );
199  bool IsSaveLater() const { return mbSaveLater; }
200 
201  const ScAutoFormatData* findByIndex(size_t nIndex) const;
202  ScAutoFormatData* findByIndex(size_t nIndex);
203  iterator find(const OUString& rName);
204 
205  iterator insert(std::unique_ptr<ScAutoFormatData> pNew);
206  void erase(const iterator& it);
207 
208  size_t size() const;
209  const_iterator begin() const;
210  const_iterator end() const;
211  iterator begin();
212  iterator end();
213 };
214 
215 #endif
216 
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetName(const OUString &rName)
Definition: autoform.hxx:140
sal_uInt16 nStrResId
Definition: autoform.hxx:116
sal_uInt64 left
bool Save(SvStream &rStream, sal_uInt16 fileVersion)
Definition: autoform.cxx:241
void SetIncludeValueFormat(bool bValueFormat)
Definition: autoform.hxx:150
std::size_t size
Definition: autoform.hxx:58
const SfxPoolItem * GetItem(const SwTextAttr &rAttr, sal_uInt16 nWhich)
const OUString & GetName() const
Definition: autoform.hxx:141
std::map< OUString, std::unique_ptr< ScAutoFormatData >, DefaultFirstEntry > MapType
Definition: autoform.hxx:182
void SetIncludeWidthHeight(bool bWidthHeight)
Definition: autoform.hxx:155
ScAfVersions m_aVersions
Definition: autoform.hxx:185
bool mbSaveLater
Definition: autoform.hxx:184
AutoFormatSwBlob m_swFields
Definition: autoform.hxx:89
enumrange< T >::Iterator begin(enumrange< T >)
ScNumFormatAbbrev aNumFormat
Definition: autoform.hxx:92
bool GetIncludeWidthHeight() const
Definition: autoform.hxx:148
MapType::iterator iterator
Definition: autoform.hxx:192
std::array< std::unique_ptr< ScAutoFormatDataField >, 16 > ppDataField
Definition: autoform.hxx:130
AutoFormatSwBlob swVersions
Definition: autoform.hxx:77
AutoFormatSwBlob m_swFields
Definition: autoform.hxx:128
std::unique_ptr< sal_uInt8[]> pData
Definition: autoform.hxx:57
Contains all items for one cell of a table autoformat.
Definition: autoform.hxx:86
def right
OSQLColumns::const_iterator find(const OSQLColumns::const_iterator &first, const OSQLColumns::const_iterator &last, const OUString &_rVal, const ::comphelper::UStringMixEqual &_rCase)
bool GetIncludeBackground() const
Definition: autoform.hxx:147
void SetIncludeJustify(bool bJustify)
Definition: autoform.hxx:152
const ScNumFormatAbbrev & GetNumFormat() const
Definition: autoform.hxx:103
A binary blob of writer-specific data.
Definition: autoform.hxx:55
OUString aName
Definition: autoform.hxx:115
ScAutoFormatDataField & operator=(const ScAutoFormatDataField &rRef)=delete
size
void SetNumFormat(const ScNumFormatAbbrev &rNumFormat)
Definition: autoform.hxx:106
void SetIncludeBackground(bool bBackground)
Definition: autoform.hxx:154
void SetIncludeFont(bool bFont)
Definition: autoform.hxx:151
const T * GetItem(sal_uInt16 nIndex, TypedWhichId< T > nWhich) const
Definition: autoform.hxx:158
enumrange< T >::Iterator end(enumrange< T >)
bool GetIncludeFrame() const
Definition: autoform.hxx:146
MapType m_Data
Definition: autoform.hxx:183
bool GetIncludeFont() const
Definition: autoform.hxx:144
void Load(SvStream &rStream, sal_uInt16 nVer)
Definition: autoform.cxx:141
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
bool IsSaveLater() const
Definition: autoform.hxx:199
MapType::const_iterator const_iterator
Definition: autoform.hxx:191
const AutoFormatSwBlob & operator=(const AutoFormatSwBlob &)=delete
bool operator()(const OUString &left, const OUString &right) const
Definition: autoform.cxx:756
Struct with version numbers of the Items.
Definition: autoform.hxx:74
bool GetIncludeValueFormat() const
Definition: autoform.hxx:143
bool GetIncludeJustify() const
Definition: autoform.hxx:145
void SetIncludeFrame(bool bFrame)
Definition: autoform.hxx:153
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
void Write(SvStream &rStream, sal_uInt16 fileVersion)
Definition: autoform.cxx:151
bool Load(SvStream &rStream, const ScAfVersions &rVersions, sal_uInt16 nVer)
Definition: autoform.cxx:214