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>
30 enum class SvMacroItemId
: sal_uInt16
;
32 #define SVX_MACRO_LANGUAGE_JAVASCRIPT "JavaScript"
33 #define SVX_MACRO_LANGUAGE_STARBASIC "StarBasic"
34 #define SVX_MACRO_LANGUAGE_SF "Script"
43 class SVL_DLLPUBLIC SvxMacro
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(); }
64 SvxMacro
& operator=( const SvxMacro
& rBase
);
67 inline SvxMacro::SvxMacro( const OUString
&rMacName
, const OUString
&rLibName
,
69 : aMacName( rMacName
), aLibName( rLibName
), eType( eTyp
)
72 // Macro Table, destroys the pointers in the DTor!
73 typedef std::map
<SvMacroItemId
, SvxMacro
> SvxMacroTable
;
75 #define SVX_MACROTBL_VERSION31 0
76 #define SVX_MACROTBL_VERSION40 1
78 class SVL_DLLPUBLIC SvxMacroTableDtor
81 SvxMacroTable aSvxMacroTable
;
83 SvxMacroTableDtor() {}
84 SvxMacroTableDtor( const SvxMacroTableDtor
&rCpy
) : aSvxMacroTable(rCpy
.aSvxMacroTable
) { }
86 SvxMacroTableDtor
& operator=( const SvxMacroTableDtor
&rCpy
);
87 bool operator==( const SvxMacroTableDtor
& rOther
) const;
89 void Read( SvStream
& );
90 SvStream
& Write( SvStream
& ) const;
92 bool empty() const { return aSvxMacroTable
.empty(); }
94 // returns NULL if no entry exists, or a pointer to the internal value
95 const SvxMacro
* Get(SvMacroItemId nEvent
) const;
96 // returns NULL if no entry exists, or a pointer to the internal value
97 SvxMacro
* Get(SvMacroItemId nEvent
);
98 // return true if the key exists
99 bool IsKeyValid(SvMacroItemId nEvent
) const;
100 // This stores a copy of the rMacro parameter
101 SvxMacro
& Insert(SvMacroItemId nEvent
, const SvxMacro
& rMacro
);
102 // If the entry exists, remove it from the map and release it's storage
103 void Erase(SvMacroItemId nEvent
);
108 This item describes a Macro table.
111 class SVL_DLLPUBLIC SvxMacroItem
: public SfxPoolItem
114 explicit inline SvxMacroItem ( const sal_uInt16 nId
);
116 // "pure virtual methods" of SfxPoolItem
117 virtual bool operator==( const SfxPoolItem
& ) const override
;
118 virtual bool GetPresentation( SfxItemPresentation ePres
,
122 const IntlWrapper
& ) const override
;
123 virtual SfxPoolItem
* Clone( SfxItemPool
*pPool
= nullptr ) const override
;
125 const SvxMacroTableDtor
& GetMacroTable() const { return aMacroTable
;}
126 void SetMacroTable( const SvxMacroTableDtor
& rTbl
) { aMacroTable
= rTbl
; }
128 inline const SvxMacro
& GetMacro( SvMacroItemId nEvent
) const;
129 inline bool HasMacro( SvMacroItemId nEvent
) const;
130 void SetMacro( SvMacroItemId nEvent
, const SvxMacro
& );
133 SvxMacroTableDtor aMacroTable
;
135 SvxMacroItem( const SvxMacroItem
& ) = default;
138 inline SvxMacroItem::SvxMacroItem( const sal_uInt16 nId
)
142 inline bool SvxMacroItem::HasMacro( SvMacroItemId nEvent
) const
144 return aMacroTable
.IsKeyValid( nEvent
);
146 inline const SvxMacro
& SvxMacroItem::GetMacro( SvMacroItemId nEvent
) const
148 return *(aMacroTable
.Get(nEvent
));
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */