tdf#144672 fix Index entries in Naviator are always grayed out
[LibreOffice.git] / include / svl / macitem.hxx
blob4d89510346c94b59f2832654ba1f0bf898fd1020
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 .
19 #ifndef INCLUDED_SVL_MACITEM_HXX
20 #define INCLUDED_SVL_MACITEM_HXX
22 // class SvxMacroItem ----------------------------------------------------
24 #include <rtl/ustring.hxx>
25 #include <svl/svldllapi.h>
26 #include <svl/poolitem.hxx>
27 #include <map>
29 class SvStream;
30 enum class SvMacroItemId : sal_uInt16;
32 inline constexpr OUStringLiteral SVX_MACRO_LANGUAGE_JAVASCRIPT = u"JavaScript";
33 inline constexpr OUStringLiteral SVX_MACRO_LANGUAGE_STARBASIC = u"StarBasic";
34 inline constexpr OUStringLiteral SVX_MACRO_LANGUAGE_SF = u"Script";
36 enum ScriptType
38 STARBASIC,
39 JAVASCRIPT,
40 EXTENDED_STYPE
43 class SVL_DLLPUBLIC SvxMacro
45 OUString aMacName;
46 OUString aLibName;
47 ScriptType eType;
49 public:
51 SvxMacro( const OUString &rMacName, const OUString &rLanguage);
53 SvxMacro( const OUString &rMacName, const OUString &rLibName,
54 ScriptType eType); // = STARBASIC removes
56 const OUString &GetLibName() const { return aLibName; }
57 const OUString &GetMacName() const { return aMacName; }
58 OUString GetLanguage()const;
60 ScriptType GetScriptType() const { return eType; }
62 bool HasMacro() const { return !aMacName.isEmpty(); }
65 inline SvxMacro::SvxMacro( const OUString &rMacName, const OUString &rLibName,
66 ScriptType eTyp )
67 : aMacName( rMacName ), aLibName( rLibName ), eType( eTyp )
70 // Macro Table, destroys the pointers in the DTor!
71 typedef std::map<SvMacroItemId, SvxMacro> SvxMacroTable;
73 #define SVX_MACROTBL_VERSION31 0
74 #define SVX_MACROTBL_VERSION40 1
76 class SVL_DLLPUBLIC SvxMacroTableDtor
78 private:
79 SvxMacroTable aSvxMacroTable;
80 public:
81 SvxMacroTableDtor() {}
82 SvxMacroTableDtor( const SvxMacroTableDtor &rCpy ) : aSvxMacroTable(rCpy.aSvxMacroTable) { }
84 SvxMacroTableDtor& operator=( const SvxMacroTableDtor &rCpy );
85 bool operator==( const SvxMacroTableDtor& rOther ) const;
87 void Read( SvStream & );
88 SvStream& Write( SvStream & ) const;
90 bool empty() const { return aSvxMacroTable.empty(); }
92 // returns NULL if no entry exists, or a pointer to the internal value
93 const SvxMacro* Get(SvMacroItemId nEvent) const;
94 // returns NULL if no entry exists, or a pointer to the internal value
95 SvxMacro* Get(SvMacroItemId nEvent);
96 // return true if the key exists
97 bool IsKeyValid(SvMacroItemId nEvent) const;
98 // This stores a copy of the rMacro parameter
99 SvxMacro& Insert(SvMacroItemId nEvent, const SvxMacro& rMacro);
100 // If the entry exists, remove it from the map and release it's storage
101 void Erase(SvMacroItemId nEvent);
106 This item describes a Macro table.
109 class SVL_DLLPUBLIC SvxMacroItem final : public SfxPoolItem
111 public:
112 explicit inline SvxMacroItem ( const sal_uInt16 nId );
114 // "pure virtual methods" of SfxPoolItem
115 virtual bool operator==( const SfxPoolItem& ) const override;
116 virtual bool GetPresentation( SfxItemPresentation ePres,
117 MapUnit eCoreMetric,
118 MapUnit ePresMetric,
119 OUString &rText,
120 const IntlWrapper& ) const override;
121 virtual SvxMacroItem* Clone( SfxItemPool *pPool = nullptr ) const override;
123 const SvxMacroTableDtor& GetMacroTable() const { return aMacroTable;}
124 void SetMacroTable( const SvxMacroTableDtor& rTbl ) { aMacroTable = rTbl; }
126 inline const SvxMacro& GetMacro( SvMacroItemId nEvent ) const;
127 inline bool HasMacro( SvMacroItemId nEvent ) const;
128 void SetMacro( SvMacroItemId nEvent, const SvxMacro& );
130 private:
131 SvxMacroTableDtor aMacroTable;
133 SvxMacroItem( const SvxMacroItem& ) = default;
136 inline SvxMacroItem::SvxMacroItem( const sal_uInt16 nId )
137 : SfxPoolItem( nId )
140 inline bool SvxMacroItem::HasMacro( SvMacroItemId nEvent ) const
142 return aMacroTable.IsKeyValid( nEvent );
144 inline const SvxMacro& SvxMacroItem::GetMacro( SvMacroItemId nEvent ) const
146 return *(aMacroTable.Get(nEvent));
149 #endif
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */