Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet81.d @ 104:88652073d1c2
More work on icu
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 02 May 2009 11:27:24 +0200 |
parents | 93b0e7382fd5 |
children | 9f4c18c268b2 |
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 | |
37 import tango.io.Stdout; | |
30
93b0e7382fd5
SWT Snippets build on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
38 import tango.io.stream.Format; |
28 | 39 import tango.text.convert.Format; |
40 | |
41 int main() { | |
42 int iRes = 0; | |
43 | |
44 String progID = "Shell.Explorer"; | |
45 //String progID = "Excel.Application"; | |
46 | |
47 Display oDisplay = new Display(); | |
48 Shell oShell = new Shell(oDisplay); | |
49 | |
50 OleFrame frame = new OleFrame(oShell, SWT.NONE); | |
51 OleControlSite oOleSite = null; | |
52 OleAutomation oOleAutoObj = null; | |
53 try { | |
54 oOleSite = new OleControlSite(frame, SWT.NONE, progID); | |
55 } | |
56 catch (Exception oExc) { | |
57 Stdout.formatln("Exception {} creating OleControlSite on type library for {}", oExc.toString(), progID); | |
58 return 1; | |
59 } | |
60 try { | |
61 oOleAutoObj = new OleAutomation(oOleSite); | |
62 } | |
63 catch (Exception oExc) { | |
64 Stdout.formatln("Exception {} OleAutomation on type library for {}", oExc.toString(), progID); | |
65 return 1; | |
66 } | |
67 | |
68 Stdout.formatln("TypeLibrary for: '{}'", progID); | |
69 printTypeInfo(oOleAutoObj, Stdout); | |
70 | |
71 oShell.dispose(); | |
72 oDisplay.dispose(); | |
73 return iRes; | |
74 } | |
75 | |
30
93b0e7382fd5
SWT Snippets build on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
76 private static void printTypeInfo(OleAutomation oOleAutoObj, FormatOutput!(char) oOut) |
28 | 77 { |
78 org.eclipse.swt.internal.ole.win32.OAIDL.TYPEATTR * pTypeAttr = oOleAutoObj.getTypeInfoAttributes(); | |
79 if (pTypeAttr !is null) { | |
80 if (pTypeAttr.cFuncs > 0) { | |
81 oOut.formatln("Functions :"); | |
82 for (int iIdx = 0; iIdx < pTypeAttr.cFuncs; ++iIdx) { | |
83 OleFunctionDescription oData = oOleAutoObj.getFunctionDescription(iIdx); | |
84 char[] sArgList = ""; | |
85 int iFirstOptionalArgIndex = oData.args.length - oData.optionalArgCount; | |
86 for (int iArg = 0; iArg < oData.args.length; ++iArg) { | |
87 sArgList ~= "["; | |
88 if (iArg >= iFirstOptionalArgIndex){ | |
89 sArgList ~= "optional, "; | |
90 } | |
91 sArgList ~= getDirection(oData.args[iArg].flags) ~ "] " ~ | |
92 getTypeName(oData.args[iArg].type) ~ " " ~ | |
93 oData.args[iArg].name | |
94 ; | |
95 if (iArg < oData.args.length - 1){ | |
96 sArgList ~= ", "; | |
97 } | |
98 } | |
99 oOut.formatln("{} (id = {} (0x{:X8}))", getInvokeKind(oData.invokeKind), oData.id, oData.id); | |
100 oOut.formatln("\tSignature : {} {}({})", getTypeName(oData.returnType), oData.name, sArgList); | |
101 oOut.formatln("\tDescription: {}", oData.documentation); | |
102 oOut.formatln("\tHelp File : {}", oData.helpFile); | |
103 oOut.formatln(""); | |
104 } | |
105 } | |
106 | |
107 if (pTypeAttr.cVars > 0) { | |
108 oOut.formatln("\n\nVariables :"); | |
109 for (int iIdx = 0; iIdx < pTypeAttr.cVars; ++iIdx) { | |
110 OlePropertyDescription oData = oOleAutoObj.getPropertyDescription(iIdx); | |
111 oOut.formatln("PROPERTY (id = {} (0x{:X8})", oData.id, oData.id); | |
112 oOut.formatln("\tName : {}", oData.name); | |
113 oOut.formatln("\tType : {}", getTypeName(oData.type)); | |
114 oOut.formatln(""); | |
115 } | |
116 } | |
117 } | |
118 } | |
119 private static char[] getTypeName(int iType) { | |
120 int iBase = iType & ~OLE.VT_BYREF; | |
121 char[] sDsc = null; | |
122 switch (iBase) { | |
123 case OLE.VT_BOOL : sDsc = "boolean"; break; | |
124 case OLE.VT_R4 : sDsc = "float"; break; | |
125 case OLE.VT_R8 : sDsc = "double"; break; | |
126 case OLE.VT_I4 : sDsc = "int"; break; | |
127 case OLE.VT_DISPATCH : sDsc = "IDispatch"; break; | |
128 case OLE.VT_UNKNOWN : sDsc = "IUnknown"; break; | |
129 case OLE.VT_I2 : sDsc = "short"; break; | |
130 case OLE.VT_BSTR : sDsc = "String"; break; | |
131 case OLE.VT_VARIANT : sDsc = "Variant"; break; | |
132 case OLE.VT_CY : sDsc = "Currency"; break; | |
133 case OLE.VT_DATE : sDsc = "Date"; break; | |
134 case OLE.VT_UI1 : sDsc = "unsigned char"; break; | |
135 case OLE.VT_UI4 : sDsc = "unsigned int"; break; | |
136 case OLE.VT_USERDEFINED : sDsc = "UserDefined"; break; | |
137 case OLE.VT_HRESULT : sDsc = "HRESULT"; break; | |
138 case OLE.VT_VOID : sDsc = "void"; break; | |
139 case OLE.VT_UI2 : sDsc = "unsigned short"; break; | |
140 case OLE.VT_UINT : sDsc = "unsigned int"; break; | |
141 case OLE.VT_PTR : sDsc = "void *"; break; | |
142 default: break; | |
143 } | |
144 if (sDsc !is null) { | |
145 if ((iType & OLE.VT_BYREF) == OLE.VT_BYREF){ | |
146 return sDsc ~ " *"; | |
147 } | |
148 return sDsc; | |
149 } | |
150 return Format("unknown {} (0x{:X4})", iType, iType); | |
151 } | |
152 | |
153 char[] getDirection(int bDirection) { | |
154 char[] sDirString = ""; | |
155 bool bComma = false; | |
156 if ((bDirection & OLE.IDLFLAG_FIN) != 0) { | |
157 sDirString ~= "in"; | |
158 bComma = true; | |
159 } | |
160 if ((bDirection & OLE.IDLFLAG_FOUT) != 0) { | |
161 if (bComma) sDirString ~= ", "; | |
162 sDirString ~= "out"; | |
163 bComma = true; | |
164 } | |
165 if ((bDirection & OLE.IDLFLAG_FLCID) != 0) { | |
166 if (bComma) sDirString ~= ", "; | |
167 sDirString ~= "lcid"; | |
168 bComma = true; | |
169 } | |
170 if ((bDirection & OLE.IDLFLAG_FRETVAL) != 0) { | |
171 if (bComma) sDirString ~= ", "; | |
172 sDirString ~= "retval"; | |
173 } | |
174 return sDirString; | |
175 } | |
176 private static char[] getInvokeKind(int iInvKind) { | |
177 switch (iInvKind) { | |
178 case OLE.INVOKE_FUNC : return "METHOD"; | |
179 case OLE.INVOKE_PROPERTYGET : return "PROPERTY GET"; | |
180 case OLE.INVOKE_PROPERTYPUT : return "PROPERTY PUT"; | |
181 case OLE.INVOKE_PROPERTYPUTREF : return "PROPERTY PUT BY REF"; | |
182 default: break; | |
183 } | |
184 return Format("unknown {}", iInvKind); | |
185 } | |
186 | |
187 |