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 #define SVX_MACRO_LANGUAGE_JAVASCRIPT "JavaScript"
32 #define SVX_MACRO_LANGUAGE_STARBASIC "StarBasic"
33 #define SVX_MACRO_LANGUAGE_SF "Script"
42 class SVL_DLLPUBLIC SvxMacro
50 SvxMacro( const OUString
&rMacName
, const OUString
&rLanguage
);
52 SvxMacro( const OUString
&rMacName
, const OUString
&rLibName
,
53 ScriptType eType
); // = STARBASIC removes
55 const OUString
&GetLibName() const { return aLibName
; }
56 const OUString
&GetMacName() const { return aMacName
; }
57 OUString
GetLanguage()const;
59 ScriptType
GetScriptType() const { return eType
; }
61 bool HasMacro() const { return !aMacName
.isEmpty(); }
63 SvxMacro
& operator=( const SvxMacro
& rBase
);
66 inline SvxMacro::SvxMacro( const OUString
&rMacName
, const OUString
&rLibName
,
68 : aMacName( rMacName
), aLibName( rLibName
), eType( eTyp
)
71 // Macro Table, destroys the pointers in the DTor!
72 typedef std::map
<sal_uInt16
, SvxMacro
> SvxMacroTable
;
74 #define SVX_MACROTBL_VERSION31 0
75 #define SVX_MACROTBL_VERSION40 1
77 #define SVX_MACROTBL_AKTVERSION SVX_MACROTBL_VERSION40
79 class SVL_DLLPUBLIC SvxMacroTableDtor
82 SvxMacroTable aSvxMacroTable
;
84 inline SvxMacroTableDtor() {}
85 inline SvxMacroTableDtor( const SvxMacroTableDtor
&rCpy
) : aSvxMacroTable(rCpy
.aSvxMacroTable
) { }
87 SvxMacroTableDtor
& operator=( const SvxMacroTableDtor
&rCpy
);
88 bool operator==( const SvxMacroTableDtor
& rOther
) const;
90 void Read( SvStream
&, sal_uInt16 nVersion
= SVX_MACROTBL_AKTVERSION
);
91 SvStream
& Write( SvStream
& ) const;
93 static sal_uInt16
GetVersion() { return SVX_MACROTBL_AKTVERSION
; }
95 SvxMacroTable::iterator
begin() { return aSvxMacroTable
.begin(); }
96 SvxMacroTable::const_iterator
begin() const { return aSvxMacroTable
.begin(); }
97 SvxMacroTable::iterator
end() { return aSvxMacroTable
.end(); }
98 SvxMacroTable::const_iterator
end () const { return aSvxMacroTable
.end(); }
99 SvxMacroTable::size_type
size() const { return aSvxMacroTable
.size(); }
100 bool empty() const { return aSvxMacroTable
.empty(); }
102 // returns NULL if no entry exists, or a pointer to the internal value
103 const SvxMacro
* Get(sal_uInt16 nEvent
) const;
104 // returns NULL if no entry exists, or a pointer to the internal value
105 SvxMacro
* Get(sal_uInt16 nEvent
);
106 // return true if the key exists
107 bool IsKeyValid(sal_uInt16 nEvent
) const;
108 // This stores a copy of the rMacro parameter
109 SvxMacro
& Insert(sal_uInt16 nEvent
, const SvxMacro
& rMacro
);
110 // If the entry exists, remove it from the map and release it's storage
111 void Erase(sal_uInt16 nEvent
);
116 This item describes a Macro table.
119 class SVL_DLLPUBLIC SvxMacroItem
: public SfxPoolItem
122 static SfxPoolItem
* CreateDefault();
124 explicit inline SvxMacroItem ( const sal_uInt16 nId
);
126 // "pure virtual methods" of SfxPoolItem
127 virtual bool operator==( const SfxPoolItem
& ) const override
;
128 virtual bool GetPresentation( SfxItemPresentation ePres
,
129 SfxMapUnit eCoreMetric
,
130 SfxMapUnit ePresMetric
,
132 const IntlWrapper
* = nullptr ) const override
;
133 virtual SfxPoolItem
* Clone( SfxItemPool
*pPool
= nullptr ) const override
;
134 virtual SfxPoolItem
* Create(SvStream
&, sal_uInt16
) const override
;
135 virtual SvStream
& Store(SvStream
&, sal_uInt16 nItemVersion
) const override
;
136 virtual sal_uInt16
GetVersion( sal_uInt16 nFileFormatVersion
) const override
;
138 inline const SvxMacroTableDtor
& GetMacroTable() const { return aMacroTable
;}
139 inline void SetMacroTable( const SvxMacroTableDtor
& rTbl
) { aMacroTable
= rTbl
; }
141 inline const SvxMacro
& GetMacro( sal_uInt16 nEvent
) const;
142 inline bool HasMacro( sal_uInt16 nEvent
) const;
143 void SetMacro( sal_uInt16 nEvent
, const SvxMacro
& );
146 SvxMacroTableDtor aMacroTable
;
148 inline SvxMacroItem( const SvxMacroItem
& );
149 SvxMacroItem
&operator=( const SvxMacroItem
& ) = delete;
152 inline SvxMacroItem::SvxMacroItem( const sal_uInt16 nId
)
155 inline SvxMacroItem::SvxMacroItem( const SvxMacroItem
&rCpy
)
156 : SfxPoolItem( rCpy
),
157 aMacroTable( rCpy
.GetMacroTable() )
160 inline bool SvxMacroItem::HasMacro( sal_uInt16 nEvent
) const
162 return aMacroTable
.IsKeyValid( nEvent
);
164 inline const SvxMacro
& SvxMacroItem::GetMacro( sal_uInt16 nEvent
) const
166 return *(aMacroTable
.Get(nEvent
));
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */