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