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"
25
26#include <memory>
27
28class ScTokenArray;
29
30namespace oox { class AttributeList; }
31namespace oox { class SequenceInputStream; }
32
33namespace oox::xls {
34
35// codes for built-in names
37const sal_Unicode BIFF_DEFNAME_AUTOOPEN = '\x01'; // Sheet macro executed when workbook is opened.
38const sal_Unicode BIFF_DEFNAME_AUTOCLOSE = '\x02'; // Sheet macro executed when workbook is closed.
39const sal_Unicode BIFF_DEFNAME_EXTRACT = '\x03'; // Filter output destination for advanced filter.
41const sal_Unicode BIFF_DEFNAME_CRITERIA = '\x05'; // Filter criteria source range for advanced filter.
42const sal_Unicode BIFF_DEFNAME_PRINTAREA = '\x06'; // Print ranges.
43const sal_Unicode BIFF_DEFNAME_PRINTTITLES = '\x07'; // Rows/columns repeated on each page when printing.
46const sal_Unicode BIFF_DEFNAME_AUTOACTIVATE = '\x0A'; // Sheet macro executed when workbook is activated.
47const sal_Unicode BIFF_DEFNAME_AUTODEACTIVATE = '\x0B'; // Sheet macro executed when workbook is deactivated.
49const 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;
60 bool mbVBName;
61 bool mbHidden;
62
63 explicit DefinedNameModel();
64};
65
68{
69public:
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
80protected:
82 mutable OUString maUpModelName;
83 OUString maCalcName;
84};
85
86class DefinedName final : public DefinedNameBase
87{
88public:
89 explicit DefinedName( const WorkbookHelper& rHelper );
90 virtual ~DefinedName() override;
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; }
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 bool isValid(const css::uno::Sequence<css::sheet::ExternalLinkInfo>& rExternalLinks) const;
122
123private:
124 typedef ::std::unique_ptr< StreamDataSequence > StreamDataSeqPtr;
125
127 sal_Int32 mnTokenIndex;
128 sal_Int16 mnCalcSheet;
131};
132
133typedef std::shared_ptr< DefinedName > DefinedNameRef;
134
136{
137public:
138 explicit DefinedNamesBuffer( const WorkbookHelper& rHelper );
139
144
146 void finalizeImport();
147
149 DefinedNameRef getByIndex( sal_Int32 nIndex ) const;
151 DefinedNameRef getByTokenIndex( sal_Int32 nIndex ) const;
156 DefinedNameRef getByModelName( const OUString& rModelName, sal_Int16 nCalcSheet = -1 ) const;
160 DefinedNameRef getByBuiltinId( sal_Unicode cBuiltinId, sal_Int16 nCalcSheet ) const;
161
162private:
164
165private:
166 typedef ::std::pair< sal_Int16, OUString > SheetNameKey;
167 typedef ::std::pair< sal_Int16, sal_Unicode > BuiltinKey;
168
173
178};
179
180} // namespace oox::xls
181
182/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base class for defined names and external names.
const OUString & getModelName() const
Returns the original name as imported from or exported to the file.
OUString maUpModelName
Model data for this defined name.
const OUString & getUpcaseModelName() const
Returns the original name as imported from or exported to the file.
const OUString & getCalcName() const
Returns the name as used in the Calc document.
OUString maCalcName
Model name converted to uppercase ASCII.
DefinedNameBase(const WorkbookHelper &rHelper)
bool isBuiltinName() const
Returns true, if this defined name is a special builtin name.
void convertFormula(const css::uno::Sequence< css::sheet::ExternalLinkInfo > &rExternalLinks)
Converts the formula string or BIFF token array for this defined name.
void createNameObject(sal_Int32 nIndex)
Creates a defined name in the Calc document.
StreamDataSeqPtr mxFormula
Identifier for built-in defined names.
sal_Int16 mnCalcSheet
Name index used in API token array.
bool isValid(const css::uno::Sequence< css::sheet::ExternalLinkInfo > &rExternalLinks) const
sal_Int16 getLocalCalcSheet() const
Returns the 0-based sheet index for local names, or -1 for global names.
void importDefinedName(const AttributeList &rAttribs)
Sets the attributes for this defined name from the passed attribute set.
sal_Int32 mnTokenIndex
ScRangeData of the defined name.
bool isMacroFunction() const
Returns true, if this defined name is a macro function call.
bool isGlobalName() const
Returns true, if this defined name is global in the document.
virtual ~DefinedName() override
bool getAbsoluteRange(ScRange &orRange) const
Tries to resolve the defined name to an absolute cell range.
::std::unique_ptr< StreamDataSequence > StreamDataSeqPtr
sal_Unicode mcBuiltinId
Calc sheet index for sheet-local names.
sal_Int32 getTokenIndex() const
Returns the token index used in API token arrays (com.sun.star.sheet.FormulaToken).
void setFormula(const OUString &rFormula)
Sets the formula string from the body of the definedName element.
sal_Unicode getBuiltinId() const
Returns the built-in identifier of the defined name.
bool isVBName() const
Returns true, if this defined name is a reference to a VBA macro.
std::unique_ptr< ScTokenArray > getScTokens(const css::uno::Sequence< css::sheet::ExternalLinkInfo > &rExternalLinks)
DefinedName(const WorkbookHelper &rHelper)
DefNameTokenIdMap maTokenIdMap
Maps all defined names by sheet index and built-in identifier.
DefinedNameRef getByModelName(const OUString &rModelName, sal_Int16 nCalcSheet=-1) const
Returns a defined name by its model name.
DefNameNameMap maModelNameMap
List of all defined names in insertion order.
::std::pair< sal_Int16, sal_Unicode > BuiltinKey
DefinedNameRef getByBuiltinId(sal_Unicode cBuiltinId, sal_Int16 nCalcSheet) const
Returns a built-in defined name by its built-in identifier.
RefMap< BuiltinKey, DefinedName > DefNameBuiltinMap
DefNameBuiltinMap maBuiltinMap
Maps all defined names by sheet index and model name.
DefinedNameRef importDefinedName(const AttributeList &rAttribs)
Imports a defined name from the passed attribute set.
void finalizeImport()
Creates all defined names in the document.
RefVector< DefinedName > DefNameVector
RefMap< sal_Int32, DefinedName > DefNameTokenIdMap
DefinedNameRef getByTokenIndex(sal_Int32 nIndex) const
Returns a defined name by token index (index in XDefinedNames container).
DefinedNamesBuffer(const WorkbookHelper &rHelper)
DefinedNameRef createDefinedName()
RefMap< SheetNameKey, DefinedName > DefNameNameMap
DefinedNameRef getByIndex(sal_Int32 nIndex) const
Returns a defined name by zero-based index (order of appearance).
::std::pair< sal_Int16, OUString > SheetNameKey
Helper class to provide access to global workbook data.
std::pair< ScRangeData *, bool > RangeDataRet
sal_Int32 nIndex
void SvStream & rStrm
const sal_Unicode BIFF_DEFNAME_AUTOCLOSE
const sal_Unicode BIFF_DEFNAME_CRITERIA
const sal_Unicode BIFF_DEFNAME_UNKNOWN
const sal_Unicode BIFF_DEFNAME_DATABASE
const sal_Unicode BIFF_DEFNAME_DATAFORM
const sal_Unicode BIFF_DEFNAME_CONSOLIDATEAREA
const sal_Unicode BIFF_DEFNAME_AUTOOPEN
std::shared_ptr< DefinedName > DefinedNameRef
const sal_Unicode BIFF_DEFNAME_SHEETTITLE
const sal_Unicode BIFF_DEFNAME_AUTODEACTIVATE
const sal_Unicode BIFF_DEFNAME_EXTRACT
const sal_Unicode BIFF_DEFNAME_RECORDER
const sal_Unicode BIFF_DEFNAME_PRINTAREA
const sal_Unicode BIFF_DEFNAME_AUTOACTIVATE
const sal_Unicode BIFF_DEFNAME_PRINTTITLES
const sal_Unicode BIFF_DEFNAME_FILTERDATABASE
bool mbMacro
Function group identifier.
bool mbVBName
True = function, false = command.
sal_Int32 mnFuncGroupId
Sheet index for local names.
bool mbFunction
True = Macro name (VBA or sheet macro).
sal_Int32 mnSheet
The formula string.
bool mbHidden
True = VBA macro, false = sheet macro.
DefinedNameModel()
True = name hidden in UI.
OUString maFormula
The original name.
sal_uInt16 sal_Unicode