Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/svl/macitem.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
#ifndef INCLUDED_SVL_MACITEM_HXX
20
#define INCLUDED_SVL_MACITEM_HXX
21
22
// class SvxMacroItem ----------------------------------------------------
23
24
#include <rtl/ustring.hxx>
25
#include <svl/svldllapi.h>
26
#include <svl/poolitem.hxx>
27
#include <map>
28
#include <utility>
29
30
class SvStream;
31
enum class SvMacroItemId : sal_uInt16;
32
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;
36
37
enum ScriptType
38
{
39
    STARBASIC,
40
    JAVASCRIPT,
41
    EXTENDED_STYPE
42
};
43
44
class SVL_DLLPUBLIC SvxMacro
45
{
46
    OUString aMacName;
47
    OUString aLibName;
48
    ScriptType eType;
49
50
public:
51
52
    SvxMacro( OUString aMacName, const OUString &rLanguage);
53
54
    SvxMacro( OUString aMacName, OUString aLibName,
55
                ScriptType eType); //  = STARBASIC removes
56
57
9.55k
    const OUString &GetLibName() const        { return aLibName; }
58
9.55k
    const OUString &GetMacName() const        { return aMacName; }
59
    const OUString &GetLanguage()const;
60
61
75
    ScriptType GetScriptType() const        { return eType; }
62
63
75
    bool HasMacro() const { return !aMacName.isEmpty(); }
64
};
65
66
inline SvxMacro::SvxMacro( OUString _aMacName, OUString _aLibName,
67
                            ScriptType eTyp )
68
1.79k
    : aMacName(std::move( _aMacName )), aLibName(std::move( _aLibName )), eType( eTyp )
69
1.79k
{}
70
71
// Macro Table, destroys the pointers in the DTor!
72
typedef std::map<SvMacroItemId, SvxMacro> SvxMacroTable;
73
74
0
#define SVX_MACROTBL_VERSION31  0
75
0
#define SVX_MACROTBL_VERSION40  1
76
77
class SVL_DLLPUBLIC SvxMacroTableDtor
78
{
79
private:
80
    SvxMacroTable aSvxMacroTable;
81
public:
82
98.0k
    SvxMacroTableDtor() {}
83
8.11k
    SvxMacroTableDtor( const SvxMacroTableDtor &rCpy ) : aSvxMacroTable(rCpy.aSvxMacroTable) { }
84
85
    SvxMacroTableDtor& operator=( const SvxMacroTableDtor &rCpy );
86
    bool operator==( const SvxMacroTableDtor& rOther ) const;
87
88
    void        Read( SvStream & );
89
    SvStream&   Write( SvStream & ) const;
90
91
69.2k
    bool empty() const { return aSvxMacroTable.empty(); }
92
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);
103
};
104
105
106
/*
107
This item describes a Macro table.
108
*/
109
110
class SVL_DLLPUBLIC SvxMacroItem final : public SfxPoolItem
111
{
112
public:
113
    DECLARE_ITEM_TYPE_FUNCTION(SvxMacroItem)
114
    explicit inline SvxMacroItem ( const sal_uInt16 nId );
115
116
    // "pure virtual methods" of SfxPoolItem
117
    virtual bool            operator==( const SfxPoolItem& ) const override;
118
    virtual bool GetPresentation( SfxItemPresentation ePres,
119
                                  MapUnit eCoreMetric,
120
                                  MapUnit ePresMetric,
121
                                  OUString &rText,
122
                                  const IntlWrapper& ) const override;
123
    virtual SvxMacroItem* Clone( SfxItemPool *pPool = nullptr ) const override;
124
125
45.0k
    const SvxMacroTableDtor& GetMacroTable() const { return aMacroTable;}
126
0
    void SetMacroTable( const SvxMacroTableDtor& rTbl ) { aMacroTable = rTbl; }
127
128
    inline const SvxMacro& GetMacro( SvMacroItemId nEvent ) const;
129
    inline bool HasMacro( SvMacroItemId nEvent ) const;
130
           void SetMacro( SvMacroItemId nEvent, const SvxMacro& );
131
132
private:
133
    SvxMacroTableDtor aMacroTable;
134
135
364
    SvxMacroItem( const SvxMacroItem& ) = default;
136
};
137
138
inline SvxMacroItem::SvxMacroItem( const sal_uInt16 nId )
139
52.7k
    : SfxPoolItem( nId )
140
52.7k
{}
141
142
inline bool SvxMacroItem::HasMacro( SvMacroItemId nEvent ) const
143
0
{
144
0
    return aMacroTable.IsKeyValid( nEvent );
145
0
}
146
inline const SvxMacro& SvxMacroItem::GetMacro( SvMacroItemId nEvent ) const
147
0
{
148
0
    return *(aMacroTable.Get(nEvent));
149
0
}
150
151
#endif
152
153
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */