1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef __JSCRIPTCLASSES_HXX
24 #define __JSCRIPTCLASSES_HXX
25 
26 
27 #pragma warning (push,1)
28 #pragma warning (disable:4548)
29 
30 #include <tools/presys.h>
31 //#include "stdafx.h"
32 #define STRICT
33 #define _WIN32_WINNT 0x0400
34 #define _WIN32_DCOM
35 #if OSL_DEBUG_LEVEL > 0
36 //#define _ATL_DEBUG_INTERFACES
37 #endif
38 #include <atlbase.h>
39 extern CComModule _Module;
40 #include <atlcom.h>
41 #include <tools/postsys.h>
42 
43 #pragma warning (pop)
44 #pragma warning (disable:4505)
45     // disable "unreferenced local function has been removed" globally
46 
47 #include "comifaces.hxx"
48 
49 
50 
51 // Sequences are represented by prepending "[]", e.g. []char, [][]byte, [][][]object, etc.
52 
53 // To make a JScriptValue object to an out parameter, call
54 // "InitOutParam" and to make it a in/out parameter call
55 // "InitInOutParam"
56 
57 // If the object represents an out parameter then the value can after the call
58 // be retrived by "Get".
59 
60 // From JavaScript the functions Get, Set, InitOutParam and InitInOutParam are
61 // used, that is they are accessible through IDispatch. The functions are used
62 // by the bridge.
63 
64 class JScriptValue:
65 	  public CComObjectRootEx<CComMultiThreadModel>,
66 	  public IJScriptValueObject,
67 	  public IDispatch
68 {
69 public:
70 	JScriptValue();
71 	virtual ~JScriptValue();
72 
73 	BEGIN_COM_MAP(JScriptValue)
74 		COM_INTERFACE_ENTRY(IDispatch)
75 		COM_INTERFACE_ENTRY(IJScriptValueObject)
76 	END_COM_MAP()
77 
78 	// IDispatch -------------------------------------------
79 	STDMETHOD( GetTypeInfoCount)(UINT *pctinfo);
80 
81 	STDMETHOD( GetTypeInfo)( UINT iTInfo,
82 							 LCID lcid,
83 							 ITypeInfo **ppTInfo);
84 
85 	STDMETHOD( GetIDsOfNames)( REFIID riid,
86 							   LPOLESTR *rgszNames,
87 							   UINT cNames,
88 							   LCID lcid,
89 							   DISPID *rgDispId);
90 
91 	STDMETHOD( Invoke)( DISPID dispIdMember,
92 						REFIID riid,
93 						LCID lcid,
94 						WORD wFlags,
95 						DISPPARAMS *pDispParams,
96 						VARIANT *pVarResult,
97 						EXCEPINFO *pExcepInfo,
98 						UINT *puArgErr);
99 	// IJScriptOutParam --------------------------------------
100 
101 	STDMETHOD( Set)( VARIANT type, VARIANT value);
102 	STDMETHOD( Get)( VARIANT *val);
103 	STDMETHOD( InitOutParam)();
104 	STDMETHOD( InitInOutParam)( VARIANT type, VARIANT value);
105 	STDMETHOD( IsOutParam)( VARIANT_BOOL * flag);
106 	STDMETHOD( IsInOutParam)( VARIANT_BOOL * flag);
107 	STDMETHOD( GetValue)( BSTR* type, VARIANT *value);
108 
109 
110 	CComVariant m_varValue;
111 	CComBSTR m_bstrType;
112 	unsigned m_bOutParam: 1;
113 	unsigned m_bInOutParam: 1;
114 
115 };
116 
117 // If a class is implemented in JScript, then its method
118 class JScriptOutParam:
119 	  public CComObjectRootEx<CComMultiThreadModel>,
120 	  public IDispatch
121 {
122 public:
123 	JScriptOutParam();
124 	virtual ~JScriptOutParam();
125 
126 	BEGIN_COM_MAP(JScriptOutParam)
127 		COM_INTERFACE_ENTRY(IDispatch)
128 	END_COM_MAP()
129 
130 	// IDispatch -------------------------------------------
131 	STDMETHOD( GetTypeInfoCount)(UINT *pctinfo);
132 
133 	STDMETHOD( GetTypeInfo)( UINT iTInfo,
134 							 LCID lcid,
135 							 ITypeInfo **ppTInfo);
136 
137 	STDMETHOD( GetIDsOfNames)( REFIID riid,
138 							   LPOLESTR *rgszNames,
139 							   UINT cNames,
140 							   LCID lcid,
141 							   DISPID *rgDispId);
142 
143 	STDMETHOD( Invoke)( DISPID dispIdMember,
144 						REFIID riid,
145 						LCID lcid,
146 						WORD wFlags,
147 						DISPPARAMS *pDispParams,
148 						VARIANT *pVarResult,
149 						EXCEPINFO *pExcepInfo,
150 						UINT *puArgErr);
151 
152 
153 private:
154 	CComVariant m_varValue;
155 };
156 
157 #endif
158