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 #pragma once
21 
22 #include "workbookhelper.hxx"
24 #include <oox/helper/refvector.hxx>
25 
26 #include <memory>
27 
28 class ScTokenArray;
29 
30 namespace oox { class AttributeList; }
31 namespace oox { class SequenceInputStream; }
32 
33 namespace oox::xls {
34 
35 // codes for built-in names
37 const sal_Unicode BIFF_DEFNAME_AUTOOPEN = '\x01'; // Sheet macro executed when workbook is opened.
38 const sal_Unicode BIFF_DEFNAME_AUTOCLOSE = '\x02'; // Sheet macro executed when workbook is closed.
39 const sal_Unicode BIFF_DEFNAME_EXTRACT = '\x03'; // Filter output destination for advanced filter.
41 const sal_Unicode BIFF_DEFNAME_CRITERIA = '\x05'; // Filter criteria source range for advanced filter.
42 const sal_Unicode BIFF_DEFNAME_PRINTAREA = '\x06'; // Print ranges.
43 const sal_Unicode BIFF_DEFNAME_PRINTTITLES = '\x07'; // Rows/columns repeated on each page when printing.
46 const sal_Unicode BIFF_DEFNAME_AUTOACTIVATE = '\x0A'; // Sheet macro executed when workbook is activated.
47 const sal_Unicode BIFF_DEFNAME_AUTODEACTIVATE = '\x0B'; // Sheet macro executed when workbook is deactivated.
49 const sal_Unicode BIFF_DEFNAME_FILTERDATABASE = '\x0D'; // Sheet range autofilter or advanced filter works on.
51 
53 {
54  OUString maName;
55  OUString maFormula;
56  sal_Int32 mnSheet;
57  sal_Int32 mnFuncGroupId;
58  bool mbMacro;
59  bool mbFunction;
60  bool mbVBName;
61  bool mbHidden;
62 
63  explicit DefinedNameModel();
64 };
65 
68 {
69 public:
70  explicit DefinedNameBase( const WorkbookHelper& rHelper );
71 
73  const OUString& getModelName() const { return maModel.maName; }
75  const OUString& getCalcName() const { return maCalcName; }
76 
78  const OUString& getUpcaseModelName() const;
79 
80 protected:
82  mutable OUString maUpModelName;
83  OUString maCalcName;
84 };
85 
87 {
88 public:
89  explicit DefinedName( const WorkbookHelper& rHelper );
90 
92  void importDefinedName( const AttributeList& rAttribs );
94  void setFormula( const OUString& rFormula );
97 
99  void createNameObject( sal_Int32 nIndex );
101  void convertFormula( const css::uno::Sequence<css::sheet::ExternalLinkInfo>& rExternalLinks );
102  std::unique_ptr<ScTokenArray> getScTokens( const css::uno::Sequence<css::sheet::ExternalLinkInfo>& rExternalLinks );
104  bool isGlobalName() const { return mnCalcSheet < 0; }
106  bool isBuiltinName() const { return mcBuiltinId != BIFF_DEFNAME_UNKNOWN; }
108  bool isMacroFunction() const { return maModel.mbMacro && maModel.mbFunction; }
110  bool isVBName() const { return maModel.mbMacro && maModel.mbVBName; }
111 
113  sal_Int16 getLocalCalcSheet() const { return mnCalcSheet; }
117  sal_Int32 getTokenIndex() const { return mnTokenIndex; }
119  bool getAbsoluteRange( ScRange& orRange ) const;
120 
121 private:
122  typedef ::std::unique_ptr< StreamDataSequence > StreamDataSeqPtr;
123 
125  sal_Int32 mnTokenIndex;
126  sal_Int16 mnCalcSheet;
128  StreamDataSeqPtr mxFormula;
129 };
130 
131 typedef std::shared_ptr< DefinedName > DefinedNameRef;
132 
134 {
135 public:
136  explicit DefinedNamesBuffer( const WorkbookHelper& rHelper );
137 
139  DefinedNameRef importDefinedName( const AttributeList& rAttribs );
142 
144  void finalizeImport();
145 
147  DefinedNameRef getByIndex( sal_Int32 nIndex ) const;
149  DefinedNameRef getByTokenIndex( sal_Int32 nIndex ) const;
154  DefinedNameRef getByModelName( const OUString& rModelName, sal_Int16 nCalcSheet = -1 ) const;
158  DefinedNameRef getByBuiltinId( sal_Unicode cBuiltinId, sal_Int16 nCalcSheet ) const;
159 
160 private:
161  DefinedNameRef createDefinedName();
162 
163 private:
164  typedef ::std::pair< sal_Int16, OUString > SheetNameKey;
165  typedef ::std::pair< sal_Int16, sal_Unicode > BuiltinKey;
166 
171 
172  DefNameVector maDefNames;
173  DefNameNameMap maModelNameMap;
174  DefNameBuiltinMap maBuiltinMap;
175  DefNameTokenIdMap maTokenIdMap;
176 };
177 
178 } // namespace oox::xls
179 
180 /* 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