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_EXTENSIONS_SOURCE_OLE_JSCRIPTCLASSES_HXX
21 #define INCLUDED_EXTENSIONS_SOURCE_OLE_JSCRIPTCLASSES_HXX
22 
23 #include "wincrap.hxx"
24 
25 #include "comifaces.hxx"
26 
27 
28 // Sequences are represented by prepending "[]", e.g. []char, [][]byte, [][][]object, etc.
29 
30 // To make a JScriptValue object to an out parameter, call
31 // "InitOutParam" and to make it a in/out parameter call
32 // "InitInOutParam"
33 
34 // If the object represents an out parameter then the value can after the call
35 // be retrieved by "Get".
36 
37 // From JavaScript the functions Get, Set, InitOutParam and InitInOutParam are
38 // used, that is they are accessible through IDispatch. The functions are used
39 // by the bridge.
40 
41 class JScriptValue:
42       public CComObjectRootEx<CComMultiThreadModel>,
43       public IJScriptValueObject,
44       public IDispatch
45 {
46 public:
47     JScriptValue();
48     virtual ~JScriptValue();
49 
50     BEGIN_COM_MAP(JScriptValue)
51         COM_INTERFACE_ENTRY(IDispatch)
52         COM_INTERFACE_ENTRY(IJScriptValueObject)
53 #if defined __clang__
54 #pragma clang diagnostic push
55 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
56 #endif
57     END_COM_MAP()
58 #if defined __clang__
59 #pragma clang diagnostic pop
60 #endif
61 
62     // IDispatch -------------------------------------------
63     STDMETHOD( GetTypeInfoCount)(UINT *pctinfo) override;
64 
65     STDMETHOD( GetTypeInfo)( UINT iTInfo,
66                              LCID lcid,
67                              ITypeInfo **ppTInfo) override;
68 
69     STDMETHOD( GetIDsOfNames)( REFIID riid,
70                                LPOLESTR *rgszNames,
71                                UINT cNames,
72                                LCID lcid,
73                                DISPID *rgDispId) override;
74 
75     STDMETHOD( Invoke)( DISPID dispIdMember,
76                         REFIID riid,
77                         LCID lcid,
78                         WORD wFlags,
79                         DISPPARAMS *pDispParams,
80                         VARIANT *pVarResult,
81                         EXCEPINFO *pExcepInfo,
82                         UINT *puArgErr) override;
83     // IJScriptOutParam --------------------------------------
84 
85     STDMETHOD( Set)( VARIANT type, VARIANT value) override;
86     STDMETHOD( Get)( VARIANT *val) override;
87     STDMETHOD( InitOutParam)() override;
88     STDMETHOD( InitInOutParam)( VARIANT type, VARIANT value) override;
89     STDMETHOD( IsOutParam)( VARIANT_BOOL * flag) override;
90     STDMETHOD( IsInOutParam)( VARIANT_BOOL * flag) override;
91     STDMETHOD( GetValue)( BSTR* type, VARIANT *value) override;
92 
93 
94     CComVariant m_varValue;
95     CComBSTR m_bstrType;
96     bool m_bOutParam: 1;
97     bool m_bInOutParam: 1;
98 
99 };
100 
101 // If a class is implemented in JScript, then its method
102 class JScriptOutParam:
103       public CComObjectRootEx<CComMultiThreadModel>,
104       public IDispatch
105 {
106 public:
107     JScriptOutParam();
108     virtual ~JScriptOutParam();
109 
110     BEGIN_COM_MAP(JScriptOutParam)
111         COM_INTERFACE_ENTRY(IDispatch)
112 #if defined __clang__
113 #pragma clang diagnostic push
114 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
115 #endif
116     END_COM_MAP()
117 #if defined __clang__
118 #pragma clang diagnostic pop
119 #endif
120 
121     // IDispatch -------------------------------------------
122     STDMETHOD( GetTypeInfoCount)(UINT *pctinfo) override;
123 
124     STDMETHOD( GetTypeInfo)( UINT iTInfo,
125                              LCID lcid,
126                              ITypeInfo **ppTInfo) override;
127 
128     STDMETHOD( GetIDsOfNames)( REFIID riid,
129                                LPOLESTR *rgszNames,
130                                UINT cNames,
131                                LCID lcid,
132                                DISPID *rgDispId) override;
133 
134     STDMETHOD( Invoke)( DISPID dispIdMember,
135                         REFIID riid,
136                         LCID lcid,
137                         WORD wFlags,
138                         DISPPARAMS *pDispParams,
139                         VARIANT *pVarResult,
140                         EXCEPINFO *pExcepInfo,
141                         UINT *puArgErr) override;
142 
143 
144 private:
145     CComVariant m_varValue;
146 };
147 
148 #endif
149 
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
151