Mercurial > projects > dwt2
comparison 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 |
comparison
equal
deleted
inserted
replaced
111:b6e9904989ed | 112:9f4c18c268b2 |
---|---|
32 import org.eclipse.swt.ole.win32.OleControlSite; | 32 import org.eclipse.swt.ole.win32.OleControlSite; |
33 import org.eclipse.swt.ole.win32.OleFrame; | 33 import org.eclipse.swt.ole.win32.OleFrame; |
34 import org.eclipse.swt.ole.win32.OleFunctionDescription; | 34 import org.eclipse.swt.ole.win32.OleFunctionDescription; |
35 import org.eclipse.swt.ole.win32.OlePropertyDescription; | 35 import org.eclipse.swt.ole.win32.OlePropertyDescription; |
36 | 36 |
37 import tango.io.Stdout; | 37 version(Tango){ |
38 import tango.io.stream.Format; | 38 import tango.io.Stdout; |
39 import tango.text.convert.Format; | 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 } | |
40 | 48 |
41 int main() { | 49 int main() { |
42 int iRes = 0; | 50 int iRes = 0; |
43 | 51 |
44 String progID = "Shell.Explorer"; | 52 String progID = "Shell.Explorer"; |
52 OleAutomation oOleAutoObj = null; | 60 OleAutomation oOleAutoObj = null; |
53 try { | 61 try { |
54 oOleSite = new OleControlSite(frame, SWT.NONE, progID); | 62 oOleSite = new OleControlSite(frame, SWT.NONE, progID); |
55 } | 63 } |
56 catch (Exception oExc) { | 64 catch (Exception oExc) { |
57 Stdout.formatln("Exception {} creating OleControlSite on type library for {}", oExc.toString(), progID); | 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 } | |
58 return 1; | 70 return 1; |
59 } | 71 } |
60 try { | 72 try { |
61 oOleAutoObj = new OleAutomation(oOleSite); | 73 oOleAutoObj = new OleAutomation(oOleSite); |
62 } | 74 } |
63 catch (Exception oExc) { | 75 catch (Exception oExc) { |
64 Stdout.formatln("Exception {} OleAutomation on type library for {}", oExc.toString(), progID); | 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 } | |
65 return 1; | 81 return 1; |
66 } | 82 } |
67 | 83 |
68 Stdout.formatln("TypeLibrary for: '{}'", progID); | 84 version(Tango){ |
69 printTypeInfo(oOleAutoObj, Stdout); | 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 } | |
70 | 91 |
71 oShell.dispose(); | 92 oShell.dispose(); |
72 oDisplay.dispose(); | 93 oDisplay.dispose(); |
73 return iRes; | 94 return iRes; |
74 } | 95 } |
79 if (pTypeAttr !is null) { | 100 if (pTypeAttr !is null) { |
80 if (pTypeAttr.cFuncs > 0) { | 101 if (pTypeAttr.cFuncs > 0) { |
81 oOut.formatln("Functions :"); | 102 oOut.formatln("Functions :"); |
82 for (int iIdx = 0; iIdx < pTypeAttr.cFuncs; ++iIdx) { | 103 for (int iIdx = 0; iIdx < pTypeAttr.cFuncs; ++iIdx) { |
83 OleFunctionDescription oData = oOleAutoObj.getFunctionDescription(iIdx); | 104 OleFunctionDescription oData = oOleAutoObj.getFunctionDescription(iIdx); |
84 char[] sArgList = ""; | 105 String sArgList = ""; |
85 int iFirstOptionalArgIndex = oData.args.length - oData.optionalArgCount; | 106 int iFirstOptionalArgIndex = oData.args.length - oData.optionalArgCount; |
86 for (int iArg = 0; iArg < oData.args.length; ++iArg) { | 107 for (int iArg = 0; iArg < oData.args.length; ++iArg) { |
87 sArgList ~= "["; | 108 sArgList ~= "["; |
88 if (iArg >= iFirstOptionalArgIndex){ | 109 if (iArg >= iFirstOptionalArgIndex){ |
89 sArgList ~= "optional, "; | 110 sArgList ~= "optional, "; |
94 ; | 115 ; |
95 if (iArg < oData.args.length - 1){ | 116 if (iArg < oData.args.length - 1){ |
96 sArgList ~= ", "; | 117 sArgList ~= ", "; |
97 } | 118 } |
98 } | 119 } |
99 oOut.formatln("{} (id = {} (0x{:X8}))", getInvokeKind(oData.invokeKind), oData.id, oData.id); | 120 version(Tango){ |
100 oOut.formatln("\tSignature : {} {}({})", getTypeName(oData.returnType), oData.name, sArgList); | 121 oOut.formatln("{} (id = {} (0x{:X8}))", getInvokeKind(oData.invokeKind), oData.id, oData.id); |
101 oOut.formatln("\tDescription: {}", oData.documentation); | 122 oOut.formatln("\tSignature : {} {}({})", getTypeName(oData.returnType), oData.name, sArgList); |
102 oOut.formatln("\tHelp File : {}", oData.helpFile); | 123 oOut.formatln("\tDescription: {}", oData.documentation); |
103 oOut.formatln(""); | 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 } | |
104 } | 133 } |
105 } | 134 } |
106 | 135 |
107 if (pTypeAttr.cVars > 0) { | 136 if (pTypeAttr.cVars > 0) { |
108 oOut.formatln("\n\nVariables :"); | 137 version(Tango){ |
109 for (int iIdx = 0; iIdx < pTypeAttr.cVars; ++iIdx) { | 138 oOut.formatln("\n\nVariables :"); |
110 OlePropertyDescription oData = oOleAutoObj.getPropertyDescription(iIdx); | 139 for (int iIdx = 0; iIdx < pTypeAttr.cVars; ++iIdx) { |
111 oOut.formatln("PROPERTY (id = {} (0x{:X8})", oData.id, oData.id); | 140 OlePropertyDescription oData = oOleAutoObj.getPropertyDescription(iIdx); |
112 oOut.formatln("\tName : {}", oData.name); | 141 oOut.formatln("PROPERTY (id = {} (0x{:X8})", oData.id, oData.id); |
113 oOut.formatln("\tType : {}", getTypeName(oData.type)); | 142 oOut.formatln("\tName : {}", oData.name); |
114 oOut.formatln(""); | 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 } | |
115 } | 155 } |
116 } | 156 } |
117 } | 157 } |
118 } | 158 } |
119 private static char[] getTypeName(int iType) { | 159 private static String getTypeName(int iType) { |
120 int iBase = iType & ~OLE.VT_BYREF; | 160 int iBase = iType & ~OLE.VT_BYREF; |
121 char[] sDsc = null; | 161 String sDsc = null; |
122 switch (iBase) { | 162 switch (iBase) { |
123 case OLE.VT_BOOL : sDsc = "boolean"; break; | 163 case OLE.VT_BOOL : sDsc = "boolean"; break; |
124 case OLE.VT_R4 : sDsc = "float"; break; | 164 case OLE.VT_R4 : sDsc = "float"; break; |
125 case OLE.VT_R8 : sDsc = "double"; break; | 165 case OLE.VT_R8 : sDsc = "double"; break; |
126 case OLE.VT_I4 : sDsc = "int"; break; | 166 case OLE.VT_I4 : sDsc = "int"; break; |
145 if ((iType & OLE.VT_BYREF) == OLE.VT_BYREF){ | 185 if ((iType & OLE.VT_BYREF) == OLE.VT_BYREF){ |
146 return sDsc ~ " *"; | 186 return sDsc ~ " *"; |
147 } | 187 } |
148 return sDsc; | 188 return sDsc; |
149 } | 189 } |
150 return Format("unknown {} (0x{:X4})", iType, iType); | 190 version(Tango){ |
151 } | 191 return Format("unknown {} (0x{:X4})", iType, iType); |
152 | 192 } else { // Phobos |
153 char[] getDirection(int bDirection) { | 193 return format("unknown %s (0x%4X)", iType, iType); |
154 char[] sDirString = ""; | 194 } |
195 } | |
196 | |
197 String getDirection(int bDirection) { | |
198 String sDirString = ""; | |
155 bool bComma = false; | 199 bool bComma = false; |
156 if ((bDirection & OLE.IDLFLAG_FIN) != 0) { | 200 if ((bDirection & OLE.IDLFLAG_FIN) != 0) { |
157 sDirString ~= "in"; | 201 sDirString ~= "in"; |
158 bComma = true; | 202 bComma = true; |
159 } | 203 } |
171 if (bComma) sDirString ~= ", "; | 215 if (bComma) sDirString ~= ", "; |
172 sDirString ~= "retval"; | 216 sDirString ~= "retval"; |
173 } | 217 } |
174 return sDirString; | 218 return sDirString; |
175 } | 219 } |
176 private static char[] getInvokeKind(int iInvKind) { | 220 private static String getInvokeKind(int iInvKind) { |
177 switch (iInvKind) { | 221 switch (iInvKind) { |
178 case OLE.INVOKE_FUNC : return "METHOD"; | 222 case OLE.INVOKE_FUNC : return "METHOD"; |
179 case OLE.INVOKE_PROPERTYGET : return "PROPERTY GET"; | 223 case OLE.INVOKE_PROPERTYGET : return "PROPERTY GET"; |
180 case OLE.INVOKE_PROPERTYPUT : return "PROPERTY PUT"; | 224 case OLE.INVOKE_PROPERTYPUT : return "PROPERTY PUT"; |
181 case OLE.INVOKE_PROPERTYPUTREF : return "PROPERTY PUT BY REF"; | 225 case OLE.INVOKE_PROPERTYPUTREF : return "PROPERTY PUT BY REF"; |
182 default: break; | 226 default: break; |
183 } | 227 } |
184 return Format("unknown {}", iInvKind); | 228 version(Tango){ |
185 } | 229 return Format("unknown {}", iInvKind); |
186 | 230 } else { // Phobos |
187 | 231 return format("unknown %s", iInvKind); |
232 } | |
233 } | |
234 | |
235 |