LibreOffice Module sc (master)  1
defnamesbuffer.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_SOURCE_FILTER_INC_DEFNAMESBUFFER_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_DEFNAMESBUFFER_HXX
22 
23 #include "workbookhelper.hxx"
25 #include <oox/helper/refvector.hxx>
26 
27 #include <memory>
28 
29 class ScTokenArray;
30 
31 namespace oox { class AttributeList; }
32 namespace oox { class SequenceInputStream; }
33 
34 namespace oox::xls {
35 
36 // codes for built-in names
38 const sal_Unicode BIFF_DEFNAME_AUTOOPEN = '\x01'; // Sheet macro executed when workbook is opened.
39 const sal_Unicode BIFF_DEFNAME_AUTOCLOSE = '\x02'; // Sheet macro executed when workbook is closed.
40 const sal_Unicode BIFF_DEFNAME_EXTRACT = '\x03'; // Filter output destination for advanced filter.
42 const sal_Unicode BIFF_DEFNAME_CRITERIA = '\x05'; // Filter criteria source range for advanced filter.
43 const sal_Unicode BIFF_DEFNAME_PRINTAREA = '\x06'; // Print ranges.
44 const sal_Unicode BIFF_DEFNAME_PRINTTITLES = '\x07'; // Rows/columns repeated on each page when printing.
47 const sal_Unicode BIFF_DEFNAME_AUTOACTIVATE = '\x0A'; // Sheet macro executed when workbook is activated.
48 const sal_Unicode BIFF_DEFNAME_AUTODEACTIVATE = '\x0B'; // Sheet macro executed when workbook is deactivated.
50 const sal_Unicode BIFF_DEFNAME_FILTERDATABASE = '\x0D'; // Sheet range autofilter or advanced filter works on.
52 
54 {
55  OUString maName;
56  OUString maFormula;
57  sal_Int32 mnSheet;
58  sal_Int32 mnFuncGroupId;
59  bool mbMacro;
60  bool mbFunction;
61  bool mbVBName;
62  bool mbHidden;
63 
64  explicit DefinedNameModel();
65 };
66 
69 {
70 public:
71  explicit DefinedNameBase( const WorkbookHelper& rHelper );
72 
74  const OUString& getModelName() const { return maModel.maName; }
76  const OUString& getCalcName() const { return maCalcName; }
77 
79  const OUString& getUpcaseModelName() const;
80 
81 protected:
83  mutable OUString maUpModelName;
84  OUString maCalcName;
85 };
86 
88 {
89 public:
90  explicit DefinedName( const WorkbookHelper& rHelper );
91 
93  void importDefinedName( const AttributeList& rAttribs );
95  void setFormula( const OUString& rFormula );
98 
100  void createNameObject( sal_Int32 nIndex );
102  void convertFormula( const css::uno::Sequence<css::sheet::ExternalLinkInfo>& rExternalLinks );
103  std::unique_ptr<ScTokenArray> getScTokens( const css::uno::Sequence<css::sheet::ExternalLinkInfo>& rExternalLinks );
105  bool isGlobalName() const { return mnCalcSheet < 0; }
107  bool isBuiltinName() const { return mcBuiltinId != BIFF_DEFNAME_UNKNOWN; }
109  bool isMacroFunction() const { return maModel.mbMacro && maModel.mbFunction; }
111  bool isVBName() const { return maModel.mbMacro && maModel.mbVBName; }
112 
114  sal_Int16 getLocalCalcSheet() const { return mnCalcSheet; }
118  sal_Int32 getTokenIndex() const { return mnTokenIndex; }
120  bool getAbsoluteRange( ScRange& orRange ) const;
121 
122 private:
123  typedef ::std::unique_ptr< StreamDataSequence > StreamDataSeqPtr;
124 
126  sal_Int32 mnTokenIndex;
127  sal_Int16 mnCalcSheet;
129  StreamDataSeqPtr mxFormula;
130 };
131 
132 typedef std::shared_ptr< DefinedName > DefinedNameRef;
133 
135 {
136 public:
137  explicit DefinedNamesBuffer( const WorkbookHelper& rHelper );
138 
140  DefinedNameRef importDefinedName( const AttributeList& rAttribs );
143 
145  void finalizeImport();
146 
148  DefinedNameRef getByIndex( sal_Int32 nIndex ) const;
150  DefinedNameRef getByTokenIndex( sal_Int32 nIndex ) const;
155  DefinedNameRef getByModelName( const OUString& rModelName, sal_Int16 nCalcSheet = -1 ) const;
159  DefinedNameRef getByBuiltinId( sal_Unicode cBuiltinId, sal_Int16 nCalcSheet ) const;
160 
161 private:
162  DefinedNameRef createDefinedName();
163 
164 private:
165  typedef ::std::pair< sal_Int16, OUString > SheetNameKey;
166  typedef ::std::pair< sal_Int16, sal_Unicode > BuiltinKey;
167 
172 
173  DefNameVector maDefNames;
174  DefNameNameMap maModelNameMap;
175  DefNameBuiltinMap maBuiltinMap;
176  DefNameTokenIdMap maTokenIdMap;
177 };
178 
179 } // namespace oox::xls
180 
181 #endif
182 
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Helper class to provide access to global workbook data.
DefinedNameRef importDefinedName(const AttributeList &rAttribs)
Imports a defined name from the passed attribute set.
sal_Int16 mnCalcSheet
Name index used in API token array.
sal_Int32 nIndex
ScRangeData * mpScRangeData
const sal_Unicode BIFF_DEFNAME_PRINTTITLES
DefinedNameBase(const WorkbookHelper &rHelper)
sal_Int32 mnSheet
The formula string.
void finalizeImport()
Creates all defined names in the document.
const sal_Unicode BIFF_DEFNAME_SHEETTITLE
DefinedNameRef getByModelName(const OUString &rModelName, sal_Int16 nCalcSheet=-1) const
Returns a defined name by its model name.
const OUString & getCalcName() const
Returns the name as used in the Calc document.
OUString maCalcName
Model name converted to uppercase ASCII.
RefMap< SheetNameKey, DefinedName > DefNameNameMap
OUString maUpModelName
Model data for this defined name.
const sal_Unicode BIFF_DEFNAME_CRITERIA
DefinedNameRef getByTokenIndex(sal_Int32 nIndex) const
Returns a defined name by token index (index in XDefinedNames container).
::std::pair< sal_Int16, OUString > SheetNameKey
RefMap< sal_Int32, DefinedName > DefNameTokenIdMap
OUString maFormula
The original name.
Base class for defined names and external names.
bool isBuiltinName() const
Returns true, if this defined name is a special builtin name.
sal_uInt16 sal_Unicode
StreamDataSeqPtr mxFormula
Identifier for built-in defined names.
DefinedNameRef createDefinedName()
const OUString & getModelName() const
Returns the original name as imported from or exported to the file.
DefinedNameModel()
True = name hidden in UI.
bool isVBName() const
Returns true, if this defined name is a reference to a VBA macro.
sal_Int16 getLocalCalcSheet() const
Returns the 0-based sheet index for local names, or -1 for global names.
void convertFormula(const css::uno::Sequence< css::sheet::ExternalLinkInfo > &rExternalLinks)
Converts the formula string or BIFF token array for this defined name.
const sal_Unicode BIFF_DEFNAME_DATABASE
void createNameObject(sal_Int32 nIndex)
Creates a defined name in the Calc document.
sal_Int32 getTokenIndex() const
Returns the token index used in API token arrays (com.sun.star.sheet.FormulaToken).
const sal_Unicode BIFF_DEFNAME_FILTERDATABASE
::std::pair< sal_Int16, sal_Unicode > BuiltinKey
const sal_Unicode BIFF_DEFNAME_AUTODEACTIVATE
bool isMacroFunction() const
Returns true, if this defined name is a macro function call.
::std::unique_ptr< StreamDataSequence > StreamDataSeqPtr
const sal_Unicode BIFF_DEFNAME_AUTOACTIVATE
sal_Unicode getBuiltinId() const
Returns the built-in identifier of the defined name.
bool mbVBName
True = function, false = command.
const sal_Unicode BIFF_DEFNAME_AUTOOPEN
const sal_Unicode BIFF_DEFNAME_AUTOCLOSE
const sal_Unicode BIFF_DEFNAME_EXTRACT
DefinedNamesBuffer(const WorkbookHelper &rHelper)
DefinedName(const WorkbookHelper &rHelper)
bool mbMacro
Function group identifier.
bool isGlobalName() const
Returns true, if this defined name is global in the document.
std::shared_ptr< DefinedName > DefinedNameRef
DefNameNameMap maModelNameMap
List of all defined names in insertion order.
const sal_Unicode BIFF_DEFNAME_UNKNOWN
const sal_Unicode BIFF_DEFNAME_PRINTAREA
bool mbHidden
True = VBA macro, false = sheet macro.
sal_Int32 mnFuncGroupId
Sheet index for local names.
std::unique_ptr< ScTokenArray > getScTokens(const css::uno::Sequence< css::sheet::ExternalLinkInfo > &rExternalLinks)
const sal_Unicode BIFF_DEFNAME_CONSOLIDATEAREA
DefNameBuiltinMap maBuiltinMap
Maps all defined names by sheet index and model name.
void importDefinedName(const AttributeList &rAttribs)
Sets the attributes for this defined name from the passed attribute set.
const OUString & getUpcaseModelName() const
Returns the original name as imported from or exported to the file.
RefMap< BuiltinKey, DefinedName > DefNameBuiltinMap
DefinedNameRef getByBuiltinId(sal_Unicode cBuiltinId, sal_Int16 nCalcSheet) const
Returns a built-in defined name by its built-in identifier.
sal_Int32 mnTokenIndex
ScRangeData of the defined name.
DefNameTokenIdMap maTokenIdMap
Maps all defined names by sheet index and built-in identifier.
const sal_Unicode BIFF_DEFNAME_RECORDER
RefVector< DefinedName > DefNameVector
bool getAbsoluteRange(ScRange &orRange) const
Tries to resolve the defined name to an absolute cell range.
void setFormula(const OUString &rFormula)
Sets the formula string from the body of the definedName element.
sal_Unicode mcBuiltinId
Calc sheet index for sheet-local names.
void SvStream & rStrm
DefinedNameRef getByIndex(sal_Int32 nIndex) const
Returns a defined name by zero-based index (order of appearance).
bool mbFunction
True = Macro name (VBA or sheet macro).
const sal_Unicode BIFF_DEFNAME_DATAFORM