1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
31 enum class SvMacroItemId
: sal_uInt16
;
33 inline constexpr OUString SVX_MACRO_LANGUAGE_JAVASCRIPT
= u
"JavaScript"_ustr
;
34 inline constexpr OUString SVX_MACRO_LANGUAGE_STARBASIC
= u
"StarBasic"_ustr
;
35 inline constexpr OUString SVX_MACRO_LANGUAGE_SF
= u
"Script"_ustr
;
44 class SVL_DLLPUBLIC SvxMacro
52 SvxMacro( OUString aMacName
, const OUString
&rLanguage
);
54 SvxMacro( OUString aMacName
, OUString aLibName
,
55 ScriptType eType
); // = STARBASIC removes
57 const OUString
&GetLibName() const { return aLibName
; }
58 const OUString
&GetMacName() const { return aMacName
; }
59 OUString
GetLanguage()const;
61 ScriptType
GetScriptType() const { return eType
; }
63 bool HasMacro() const { return !aMacName
.isEmpty(); }
66 inline SvxMacro::SvxMacro( OUString _aMacName
, OUString _aLibName
,
68 : aMacName(std::move( _aMacName
)), aLibName(std::move( _aLibName
)), eType( eTyp
)
71 // Macro Table, destroys the pointers in the DTor!
72 typedef std::map
<SvMacroItemId
, SvxMacro
> SvxMacroTable
;
74 #define SVX_MACROTBL_VERSION31 0
75 #define SVX_MACROTBL_VERSION40 1
77 class SVL_DLLPUBLIC SvxMacroTableDtor
80 SvxMacroTable aSvxMacroTable
;
82 SvxMacroTableDtor() {}
83 SvxMacroTableDtor( const SvxMacroTableDtor
&rCpy
) : aSvxMacroTable(rCpy
.aSvxMacroTable
) { }
85 SvxMacroTableDtor
& operator=( const SvxMacroTableDtor
&rCpy
);
86 bool operator==( const SvxMacroTableDtor
& rOther
) const;
88 void Read( SvStream
& );
89 SvStream
& Write( SvStream
& ) const;
91 bool empty() const { return aSvxMacroTable
.empty(); }
93 // returns NULL if no entry exists, or a pointer to the internal value
94 const SvxMacro
* Get(SvMacroItemId nEvent
) const;
95 // returns NULL if no entry exists, or a pointer to the internal value
96 SvxMacro
* Get(SvMacroItemId nEvent
);
97 // return true if the key exists
98 bool IsKeyValid(SvMacroItemId nEvent
) const;
99 // This stores a copy of the rMacro parameter
100 SvxMacro
& Insert(SvMacroItemId nEvent
, const SvxMacro
& rMacro
);
101 // If the entry exists, remove it from the map and release it's storage
102 void Erase(SvMacroItemId nEvent
);
107 This item describes a Macro table.
110 class SVL_DLLPUBLIC SvxMacroItem final
: public SfxPoolItem
113 explicit inline SvxMacroItem ( const sal_uInt16 nId
);
115 // "pure virtual methods" of SfxPoolItem
116 virtual bool operator==( const SfxPoolItem
& ) const override
;
117 virtual bool GetPresentation( SfxItemPresentation ePres
,
121 const IntlWrapper
& ) const override
;
122 virtual SvxMacroItem
* Clone( SfxItemPool
*pPool
= nullptr ) const override
;
124 const SvxMacroTableDtor
& GetMacroTable() const { return aMacroTable
;}
125 void SetMacroTable( const SvxMacroTableDtor
& rTbl
) { aMacroTable
= rTbl
; }
127 inline const SvxMacro
& GetMacro( SvMacroItemId nEvent
) const;
128 inline bool HasMacro( SvMacroItemId nEvent
) const;
129 void SetMacro( SvMacroItemId nEvent
, const SvxMacro
& );
132 SvxMacroTableDtor aMacroTable
;
134 SvxMacroItem( const SvxMacroItem
& ) = default;
137 inline SvxMacroItem::SvxMacroItem( const sal_uInt16 nId
)
141 inline bool SvxMacroItem::HasMacro( SvMacroItemId nEvent
) const
143 return aMacroTable
.IsKeyValid( nEvent
);
145 inline const SvxMacro
& SvxMacroItem::GetMacro( SvMacroItemId nEvent
) const
147 return *(aMacroTable
.Get(nEvent
));
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */