Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / source / filter / inc / xiname.hxx
blob8d86909c0352fda5103f64a845e143c3f23f789d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include "xiroot.hxx"
23 #include "xistream.hxx"
25 #include <rangenam.hxx>
27 #include <memory>
28 #include <vector>
30 class ScTokenArray;
32 /** Represents a defined name. It may be related to a single sheet or global. */
33 class XclImpName : protected XclImpRoot
35 struct TokenStrmData
37 XclImpStream& mrStrm;
38 XclImpStreamPos maStrmPos;
39 std::size_t mnStrmPos;
40 std::size_t mnStrmSize;
42 TokenStrmData( XclImpStream& rStrm );
45 public:
46 XclImpName(const XclImpName&) = delete;
47 const XclImpName& operator=(const XclImpName&) = delete;
49 explicit XclImpName( XclImpStream& rStrm, sal_uInt16 nXclNameIdx );
51 const OUString& GetXclName() const { return maXclName; }
52 const OUString& GetScName() const { return maScName; }
53 SCTAB GetScTab() const { return mnScTab; }
54 const ScRangeData* GetScRangeData() const { return mpScData; }
55 bool IsGlobal() const { return mnScTab == SCTAB_MAX; }
56 bool IsVBName() const { return mbVBName; }
57 bool IsMacro() const { return mbMacro; }
58 void ConvertTokens();
60 private:
61 void InsertName(const ScTokenArray* pArray);
63 OUString maXclName; /// Original name read from the file.
64 OUString maScName; /// Name inserted into the Calc document.
65 const ScRangeData* mpScData; /// Pointer to Calc defined name (no ownership).
66 SCTAB mnScTab; /// Calc sheet index of local names.
67 ScRangeData::Type meNameType;
68 sal_uInt16 mnXclTab;
69 sal_uInt16 mnNameIndex;
70 bool mbVBName:1; /// true = Visual Basic procedure or function.
71 bool mbMacro:1; /// Whether it's a user-defined macro.
73 std::unique_ptr<TokenStrmData> mpTokensData; /// For later conversion of token array.
76 /** This buffer contains all internal defined names of the document.
77 @descr It manages the position of the names in the document, means if they are
78 global or attached to a specific sheet. While inserting the names into the Calc
79 document this buffer resolves conflicts caused by equal names from different
80 sheets. */
81 class XclImpNameManager : protected XclImpRoot
83 public:
84 explicit XclImpNameManager( const XclImpRoot& rRoot );
86 /** Reads a NAME record and creates an entry in this buffer. */
87 void ReadName( XclImpStream& rStrm );
89 /** Tries to find the name used in Calc, based on the original Excel defined name.
90 @param nScTab The sheet index for local names or SCTAB_MAX for global names.
91 If no local name is found, tries to find a matching global name.
92 @return Pointer to the defined name or 0 on error. */
93 const XclImpName* FindName( std::u16string_view rXclName, SCTAB nScTab ) const;
95 /** Returns the defined name specified by its Excel index.
96 @param nXclNameIdx The index of the internal defined name.
97 @return Pointer to the defined name or 0 on error. */
98 const XclImpName* GetName( sal_uInt16 nXclNameIdx ) const;
100 void ConvertAllTokens();
102 private:
103 typedef std::vector< std::unique_ptr<XclImpName> > XclImpNameList;
104 XclImpNameList maNameList;
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */