Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet81.d @ 112:9f4c18c268b2
Update to compile and execute with dmd 2.052.
author | kntroh |
---|---|
date | Wed, 16 Mar 2011 21:53:53 +0900 |
parents | 93b0e7382fd5 |
children | 536e43f63c81 |
rev | line source |
---|---|
28 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2004 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Enzo Petrelli | |
12 *******************************************************************************/ | |
13 module org.eclipse.swt.snippets.Snippet81; | |
14 | |
15 /* | |
16 * OLE and ActiveX example snippet: browse the typelibinfo for a program id (win32 only) | |
17 * NOTE: This snippet uses internal SWT packages that are | |
18 * subject to change without notice. | |
19 * | |
20 * For a list of all SWT example snippets see | |
21 * http://www.eclipse.org/swt/snippets/ | |
22 */ | |
23 | |
24 import org.eclipse.swt.SWT; | |
25 import org.eclipse.swt.widgets.Display; | |
26 import org.eclipse.swt.widgets.Shell; | |
27 | |
28 import java.lang.all; // String | |
29 import org.eclipse.swt.internal.ole.win32.OAIDL; | |
30 import org.eclipse.swt.ole.win32.OLE; | |
31 import org.eclipse.swt.ole.win32.OleAutomation; | |
32 import org.eclipse.swt.ole.win32.OleControlSite; | |
33 import org.eclipse.swt.ole.win32.OleFrame; | |
34 import org.eclipse.swt.ole.win32.OleFunctionDescription; | |
35 import org.eclipse.swt.ole.win32.OlePropertyDescription; | |
36 | |
112 | 37 version(Tango){ |
38 import tango.io.Stdout; | |
39 import tango.io.stream.Format; | |
40 import tango.text.convert.Format; | |
41 } else { // Phobos | |
42 import std.stdio; | |
43 import std.string; | |
44 class FormatOutput(T) { | |
45 alias writefln formatln; | |
46 } | |
47 } | |
28 | 48 |
49 int main() { | |
50 int iRes = 0; | |
51 | |
52 String progID = "Shell.Explorer"; | |
53 //String progID = "Excel.Application"; | |
54 | |
55 Display oDisplay = new Display(); | |
56 Shell oShell = new Shell(oDisplay); | |
57 | |
58 OleFrame frame = new OleFrame(oShell, SWT.NONE); | |
59 OleControlSite oOleSite = null; | |
60 OleAutomation oOleAutoObj = null; | |
61 try { | |
62 oOleSite = new OleControlSite(frame, SWT.NONE, progID); | |
63 } | |
64 catch (Exception oExc) { | |
112 | 65 version(Tango){ |
66 Stdout.formatln("Exception {} creating OleControlSite on type library for {}", oExc.toString(), progID); | |
67 } else { // Phobos | |
68 writefln("Exception %s creating OleControlSite on type library for %s", oExc.toString(), progID); | |
69 } | |
28 | 70 return 1; |
71 } | |
72 try { | |
73 oOleAutoObj = new OleAutomation(oOleSite); | |
74 } | |
75 catch (Exception oExc) { | |
112 | 76 version(Tango){ |
77 Stdout.formatln("Exception {} OleAutomation on type library for {}", oExc.toString(), progID); | |
78 } else { // Phobos | |
79 writefln("Exception %s OleAutomation on type library for %s", oExc.toString(), progID); | |
80 } | |
28 | 81 return 1; |
82 } | |
83 | |
112 | 84 version(Tango){ |
85 Stdout.formatln("TypeLibrary for: '{}'", progID); | |
86 printTypeInfo(oOleAutoObj, Stdout); | |
87 } else { | |
88 writefln("TypeLibrary for: '%s'", progID); | |
89 printTypeInfo(oOleAutoObj, new FormatOutput!(char)); | |
90 } | |
28 | 91 |
92 oShell.dispose(); | |
93 oDisplay.dispose(); | |
94 return iRes; | |
95 } | |
96 | |
30
93b0e7382fd5
SWT Snippets build on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
97 private static void printTypeInfo(OleAutomation oOleAutoObj, FormatOutput!(char) oOut) |
28 | 98 { |
99 org.eclipse.swt.internal.ole.win32.OAIDL.TYPEATTR * pTypeAttr = oOleAutoObj.getTypeInfoAttributes(); | |
100 if (pTypeAttr !is null) { | |
101 if (pTypeAttr.cFuncs > 0) { | |
102 oOut.formatln("Functions :"); | |
103 for (int iIdx = 0; iIdx < pTypeAttr.cFuncs; ++iIdx) { | |
104 OleFunctionDescription oData = oOleAutoObj.getFunctionDescription(iIdx); | |
112 | 105 String sArgList = ""; |
28 | 106 int iFirstOptionalArgIndex = oData.args.length - oData.optionalArgCount; |
107 for (int iArg = 0; iArg < oData.args.length; ++iArg) { | |
108 sArgList ~= "["; | |
109 if (iArg >= iFirstOptionalArgIndex){ | |
110 sArgList ~= "optional, "; | |
111 } | |
112 sArgList ~= getDirection(oData.args[iArg].flags) ~ "] " ~ | |
113 getTypeName(oData.args[iArg].type) ~ " " ~ | |
114 oData.args[iArg].name | |
115 ; | |
116 if (iArg < oData.args.length - 1){ | |
117 sArgList ~= ", "; | |
118 } | |
119 } | |
112 | 120 version(Tango){ |
121 oOut.formatln("{} (id = {} (0x{:X8}))", getInvokeKind(oData.invokeKind), oData.id, oData.id); | |
122 oOut.formatln("\tSignature : {} {}({})", getTypeName(oData.returnType), oData.name, sArgList); | |
123 oOut.formatln("\tDescription: {}", oData.documentation); | |
124 oOut.formatln("\tHelp File : {}", oData.helpFile); | |
125 oOut.formatln(""); | |
126 } else { // Phobos | |
127 oOut.formatln("%s (id = %s (0x%8X))", getInvokeKind(oData.invokeKind), oData.id, oData.id); | |
128 oOut.formatln("\tSignature : %s %s(%s)", getTypeName(oData.returnType), oData.name, sArgList); | |
129 oOut.formatln("\tDescription: %s", oData.documentation); | |
130 oOut.formatln("\tHelp File : %s", oData.helpFile); | |
131 oOut.formatln(""); | |
132 } | |
28 | 133 } |
134 } | |
135 | |
136 if (pTypeAttr.cVars > 0) { | |
112 | 137 version(Tango){ |
138 oOut.formatln("\n\nVariables :"); | |
139 for (int iIdx = 0; iIdx < pTypeAttr.cVars; ++iIdx) { | |
140 OlePropertyDescription oData = oOleAutoObj.getPropertyDescription(iIdx); | |
141 oOut.formatln("PROPERTY (id = {} (0x{:X8})", oData.id, oData.id); | |
142 oOut.formatln("\tName : {}", oData.name); | |
143 oOut.formatln("\tType : {}", getTypeName(oData.type)); | |
144 oOut.formatln(""); | |
145 } | |
146 } else { // Phobos | |
147 oOut.formatln("\n\nVariables :"); | |
148 for (int iIdx = 0; iIdx < pTypeAttr.cVars; ++iIdx) { | |
149 OlePropertyDescription oData = oOleAutoObj.getPropertyDescription(iIdx); | |
150 oOut.formatln("PROPERTY (id = %s (0x%8X)", oData.id, oData.id); | |
151 oOut.formatln("\tName : %s", oData.name); | |
152 oOut.formatln("\tType : %s", getTypeName(oData.type)); | |
153 oOut.formatln(""); | |
154 } | |
28 | 155 } |
156 } | |
157 } | |
158 } | |
112 | 159 private static String getTypeName(int iType) { |
28 | 160 int iBase = iType & ~OLE.VT_BYREF; |
112 | 161 String sDsc = null; |
28 | 162 switch (iBase) { |
163 case OLE.VT_BOOL : sDsc = "boolean"; break; | |
164 case OLE.VT_R4 : sDsc = "float"; break; | |
165 case OLE.VT_R8 : sDsc = "double"; break; | |
166 case OLE.VT_I4 : sDsc = "int"; break; | |
167 case OLE.VT_DISPATCH : sDsc = "IDispatch"; break; | |
168 case OLE.VT_UNKNOWN : sDsc = "IUnknown"; break; | |
169 case OLE.VT_I2 : sDsc = "short"; break; | |
170 case OLE.VT_BSTR : sDsc = "String"; break; | |
171 case OLE.VT_VARIANT : sDsc = "Variant"; break; | |
172 case OLE.VT_CY : sDsc = "Currency"; break; | |
173 case OLE.VT_DATE : sDsc = "Date"; break; | |
174 case OLE.VT_UI1 : sDsc = "unsigned char"; break; | |
175 case OLE.VT_UI4 : sDsc = "unsigned int"; break; | |
176 case OLE.VT_USERDEFINED : sDsc = "UserDefined"; break; | |
177 case OLE.VT_HRESULT : sDsc = "HRESULT"; break; | |
178 case OLE.VT_VOID : sDsc = "void"; break; | |
179 case OLE.VT_UI2 : sDsc = "unsigned short"; break; | |
180 case OLE.VT_UINT : sDsc = "unsigned int"; break; | |
181 case OLE.VT_PTR : sDsc = "void *"; break; | |
182 default: break; | |
183 } | |
184 if (sDsc !is null) { | |
185 if ((iType & OLE.VT_BYREF) == OLE.VT_BYREF){ | |
186 return sDsc ~ " *"; | |
187 } | |
188 return sDsc; | |
189 } | |
112 | 190 version(Tango){ |
191 return Format("unknown {} (0x{:X4})", iType, iType); | |
192 } else { // Phobos | |
193 return format("unknown %s (0x%4X)", iType, iType); | |
194 } | |
28 | 195 } |
196 | |
112 | 197 String getDirection(int bDirection) { |
198 String sDirString = ""; | |
28 | 199 bool bComma = false; |
200 if ((bDirection & OLE.IDLFLAG_FIN) != 0) { | |
201 sDirString ~= "in"; | |
202 bComma = true; | |
203 } | |
204 if ((bDirection & OLE.IDLFLAG_FOUT) != 0) { | |
205 if (bComma) sDirString ~= ", "; | |
206 sDirString ~= "out"; | |
207 bComma = true; | |
208 } | |
209 if ((bDirection & OLE.IDLFLAG_FLCID) != 0) { | |
210 if (bComma) sDirString ~= ", "; | |
211 sDirString ~= "lcid"; | |
212 bComma = true; | |
213 } | |
214 if ((bDirection & OLE.IDLFLAG_FRETVAL) != 0) { | |
215 if (bComma) sDirString ~= ", "; | |
216 sDirString ~= "retval"; | |
217 } | |
218 return sDirString; | |
219 } | |
112 | 220 private static String getInvokeKind(int iInvKind) { |
28 | 221 switch (iInvKind) { |
222 case OLE.INVOKE_FUNC : return "METHOD"; | |
223 case OLE.INVOKE_PROPERTYGET : return "PROPERTY GET"; | |
224 case OLE.INVOKE_PROPERTYPUT : return "PROPERTY PUT"; | |
225 case OLE.INVOKE_PROPERTYPUTREF : return "PROPERTY PUT BY REF"; | |
226 default: break; | |
227 } | |
112 | 228 version(Tango){ |
229 return Format("unknown {}", iInvKind); | |
230 } else { // Phobos | |
231 return format("unknown %s", iInvKind); | |
232 } | |
28 | 233 } |
234 | |
235 |