Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/oox/ole/vbamodule.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
20
#ifndef INCLUDED_OOX_OLE_VBAMODULE_HXX
21
#define INCLUDED_OOX_OLE_VBAMODULE_HXX
22
23
#include <com/sun/star/uno/Reference.hxx>
24
#include <rtl/textenc.h>
25
#include <rtl/ustring.hxx>
26
#include <sal/types.h>
27
#include <vector>
28
29
namespace com::sun::star {
30
    namespace container { class XNameAccess; }
31
    namespace container { class XNameContainer; }
32
    namespace frame { class XModel; }
33
    namespace uno { class XComponentContext; }
34
}
35
36
namespace oox {
37
    class BinaryInputStream;
38
    class StorageBase;
39
}
40
41
namespace oox::ole {
42
43
/** Stores, which key shortcut maps to which VBA macro method. */
44
struct VbaMacroKeyAndMethodBinding
45
{
46
    // This describes a key combination in "raw" VBA Macro form, that
47
    // still needs translated to a key event that can be used in
48
    // LibreOffice.
49
    OUString msApiKey;
50
    // The name of the macro method
51
    OUString msMethodName;
52
};
53
54
class VbaModule
55
{
56
public:
57
    explicit            VbaModule(
58
                            const css::uno::Reference< css::uno::XComponentContext >& rxContext,
59
                            const css::uno::Reference< css::frame::XModel >& rxDocModel,
60
                            OUString aName,
61
                            rtl_TextEncoding eTextEnc,
62
                            bool bExecutable );
63
64
    /** Returns the module type (com.sun.star.script.ModuleType constant). */
65
0
    sal_Int32    getType() const { return mnType; }
66
    /** Sets the passed module type. */
67
24
    void         setType( sal_Int32 nType ) { mnType = nType; }
68
69
    /** Returns the name of the module. */
70
0
    const OUString& getName() const { return maName; }
71
    /** Returns the stream name of the module. */
72
25
    const OUString& getStreamName() const { return maStreamName; }
73
74
    /** Imports all records for this module until the MODULEEND record. */
75
    void                importDirRecords( BinaryInputStream& rDirStrm );
76
77
    /** Imports the VBA source code into the passed Basic library. */
78
    void                createAndImportModule(
79
                            StorageBase& rVbaStrg,
80
                            const css::uno::Reference< css::container::XNameContainer >& rxBasicLib,
81
                            const css::uno::Reference< css::container::XNameAccess >& rxDocObjectNA );
82
    /** Creates an empty Basic module in the passed Basic library. */
83
    void                createEmptyModule(
84
                            const css::uno::Reference< css::container::XNameContainer >& rxBasicLib,
85
                            const css::uno::Reference< css::container::XNameAccess >& rxDocObjectNA ) const;
86
87
    void registerShortcutKeys();
88
89
private:
90
    /** Reads and returns the VBA source code from the passed storage. */
91
    OUString     readSourceCode( StorageBase& rVbaStrg );
92
93
    /** Creates a new Basic module and inserts it into the passed Basic library. */
94
    void                createModule(
95
                            std::u16string_view rVBASourceCode,
96
                            const css::uno::Reference< css::container::XNameContainer >& rxBasicLib,
97
                            const css::uno::Reference< css::container::XNameAccess >& rxDocObjectNA ) const;
98
99
private:
100
    css::uno::Reference< css::uno::XComponentContext >
101
                        mxContext;          ///< Component context with service manager.
102
    css::uno::Reference< css::frame::XModel >
103
                        mxDocModel;         ///< Document model used to import/export the VBA project.
104
    OUString            maName;
105
    OUString            maStreamName;
106
    OUString            maDocString;
107
    rtl_TextEncoding    meTextEnc;
108
    sal_Int32           mnType;
109
    sal_uInt32          mnOffset;
110
    bool                mbReadOnly;
111
    bool                mbPrivate;
112
    bool                mbExecutable;
113
114
    /** Keys and VBA macro method bindings */
115
    std::vector<VbaMacroKeyAndMethodBinding> maKeyBindings;
116
};
117
118
119
} // namespace oox::ole
120
121
#endif
122
123
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */