jscript: Implement ScriptTypeInfo_GetDocumentation.
[wine.git] / programs / oleview / typelib.c
blob92dbebc41d5f9009712988813906f64fe2334c0d
1 /*
2 * OleView (typelib.c)
4 * Copyright 2006 Piotr Caban
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "main.h"
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(oleview);
27 TYPELIB typelib;
28 static const WCHAR wszTypeLib[] = { 'T','Y','P','E','L','I','B','\0' };
30 static const WCHAR wszFailed[] = { '<','f','a','i','l','e','d','>','\0' };
31 static const WCHAR wszSpace[] = { ' ','\0' };
32 static const WCHAR wszAsterix[] = { '*','\0' };
33 static const WCHAR wszComa[] = { ',','\0' };
34 static const WCHAR wszEquals[] = { '=','\0' };
35 static const WCHAR wszSemicolon[] = { ';','\0' };
36 static const WCHAR wszNewLine[] = { '\n','\0' };
37 static const WCHAR wszOpenBrackets1[] = { '[','\0' };
38 static const WCHAR wszCloseBrackets1[] = { ']','\0' };
39 static const WCHAR wszOpenBrackets2[] = { '(','\0' };
40 static const WCHAR wszCloseBrackets2[] = { ')','\0' };
41 static const WCHAR wszOpenBrackets3[] = { '{','\0' };
42 static const WCHAR wszCloseBrackets3[] = { '}','\0' };
43 static const WCHAR wszInvertedComa[] = { '"','\0' };
44 static const WCHAR wszColon[] = { ':','\0' };
46 static const WCHAR wszUUID[] = { 'u','u','i','d','\0' };
47 static const WCHAR wszOdl[] = { 'o','d','l','\0' };
49 static const WCHAR wszVT_BOOL[]
50 = { 'V','A','R','I','A','N','T','_','B','O','O','L','\0' };
51 static const WCHAR wszVT_UI1[]
52 = { 'u','n','s','i','g','n','e','d',' ','c','h','a','r','\0' };
53 static const WCHAR wszVT_UI2[]
54 = { 'u','n','s','i','g','n','e','d',' ','s','h','o','r','t','\0' };
55 static const WCHAR wszVT_UI4[]
56 = { 'u','n','s','i','g','n','e','d',' ','l','o','n','g','\0' };
57 static const WCHAR wszVT_UI8[] = { 'u','i','n','t','6','4','\0' };
58 static const WCHAR wszVT_UINT[]
59 = { 'u','n','s','i','g','n','e','d',' ','i','n','t','\0' };
60 static const WCHAR wszVT_I1[] = { 'c','h','a','r','\0' };
61 static const WCHAR wszVT_I2[] = { 's','h','o','r','t','\0' };
62 static const WCHAR wszVT_I4[] = { 'l','o','n','g','\0' };
63 static const WCHAR wszVT_I8[] = { 'i','n','t','6','4','\0' };
64 static const WCHAR wszVT_R4[] = { 's','i','n','g','l','e','\0' };
65 static const WCHAR wszVT_INT[] = { 'i','n','t','\0' };
66 static const WCHAR wszVT_BSTR[] = { 'B','S','T','R','\0' };
67 static const WCHAR wszVT_CY[] = { 'C','U','R','R','E','N','C','Y','\0' };
68 static const WCHAR wszVT_VARIANT[] = { 'V','A','R','I','A','N','T','\0' };
69 static const WCHAR wszVT_VOID[] = { 'v','o','i','d','\0' };
70 static const WCHAR wszVT_ERROR[] = { 'S','C','O','D','E','\0' };
71 static const WCHAR wszVT_LPSTR[] = { 'L','P','S','T','R','\0' };
72 static const WCHAR wszVT_LPWSTR[] = { 'L','P','W','S','T','R','\0' };
73 static const WCHAR wszVT_HRESULT[] = { 'H','R','E','S','U','L','T','\0' };
74 static const WCHAR wszVT_UNKNOWN[] = { 'I','U','n','k','n','o','w','n','\0' };
75 static const WCHAR wszVT_DISPATCH[] = { 'I','D','i','s','p','a','t','c','h','\0' };
76 static const WCHAR wszVT_DATE[] = { 'D','A','T','E','\0' };
77 static const WCHAR wszVT_R8[] = { 'd','o','u','b','l','e','\0' };
78 static const WCHAR wszVT_SAFEARRAY[] = { 'S','A','F','E','A','R','R','A','Y','\0' };
80 static const WCHAR wszFormat[] = { '0','x','%','.','8','l','x','\0' };
81 static const WCHAR wszStdCall[] = { '_','s','t','d','c','a','l','l','\0' };
82 static const WCHAR wszId[] = { 'i','d','\0' };
83 static const WCHAR wszHelpstring[] = { 'h','e','l','p','s','t','r','i','n','g','\0' };
84 static const WCHAR wszPropPut[] = { 'p','r','o','p','p','u','t','\0' };
85 static const WCHAR wszPropGet[] = { 'p','r','o','p','g','e','t','\0' };
86 static const WCHAR wszPropPutRef[] = { 'p','r','o','p','p','u','t','r','e','f','\0' };
87 static const WCHAR wszPARAMFLAG_FIN[] = { 'i','n','\0' };
88 static const WCHAR wszPARAMFLAG_FOUT[] = { 'o','u','t','\0' };
89 static const WCHAR wszPARAMFLAG_FLCID[] = { 'c','i','d','\0' };
90 static const WCHAR wszPARAMFLAG_FRETVAL[] = { 'r','e','t','v','a','l','\0' };
91 static const WCHAR wszPARAMFLAG_FOPT[] = { 'o','p','t','i','o','n','a','l','\0' };
92 static const WCHAR wszPARAMFLAG_FHASCUSTDATA[]
93 = { 'h','a','s','c','u','s','t','d','a','t','a','\0' };
94 static const WCHAR wszDefaultValue[]
95 = { 'd','e','f','a','u','l','t','v','a','l','u','e','\0' };
97 static const WCHAR wszReadOnly[] = { 'r','e','a','d','o','n','l','y','\0' };
98 static const WCHAR wszConst[] = { 'c','o','n','s','t','\0' };
100 static void ShowLastError(void)
102 DWORD error = GetLastError();
103 LPWSTR lpMsgBuf;
104 WCHAR wszTitle[MAX_LOAD_STRING];
106 LoadStringW(globals.hMainInst, IDS_TYPELIBTITLE, wszTitle, ARRAY_SIZE(wszTitle));
107 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
108 NULL, error, 0, (LPWSTR)&lpMsgBuf, 0, NULL);
109 MessageBoxW(NULL, lpMsgBuf, wszTitle, MB_OK | MB_ICONERROR);
110 LocalFree(lpMsgBuf);
111 return;
114 static void SaveIdl(WCHAR *wszFileName)
116 HTREEITEM hIDL;
117 TVITEMW tvi;
118 HANDLE hFile;
119 DWORD len, dwNumWrite;
120 char *wszIdl;
121 TYPELIB_DATA *data;
123 hIDL = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
124 TVGN_CHILD, (LPARAM)TVI_ROOT);
126 memset(&tvi, 0, sizeof(TVITEMW));
127 tvi.hItem = hIDL;
129 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
130 data = (TYPELIB_DATA *)tvi.lParam;
132 hFile = CreateFileW(wszFileName, GENERIC_WRITE, FILE_SHARE_WRITE,
133 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
134 if(hFile == INVALID_HANDLE_VALUE)
136 ShowLastError();
137 return;
140 len = WideCharToMultiByte( CP_UTF8, 0, data->idl, data->idlLen, NULL, 0, NULL, NULL );
141 wszIdl = HeapAlloc(GetProcessHeap(), 0, len);
142 WideCharToMultiByte( CP_UTF8, 0, data->idl, data->idlLen, wszIdl, len, NULL, NULL );
144 if(!WriteFile(hFile, wszIdl, len, &dwNumWrite, NULL))
145 ShowLastError();
147 HeapFree(GetProcessHeap(), 0, wszIdl);
148 CloseHandle(hFile);
151 static void GetSaveIdlAsPath(void)
153 OPENFILENAMEW saveidl;
154 WCHAR *pFileName;
155 WCHAR wszPath[MAX_LOAD_STRING];
156 WCHAR wszDir[MAX_LOAD_STRING];
157 static const WCHAR wszDefaultExt[] = { 'i','d','l',0 };
158 static const WCHAR wszIdlFiles[] = { '*','.','i','d','l','\0','\0' };
160 memset(&saveidl, 0, sizeof(saveidl));
162 lstrcpyW(wszDir, typelib.wszFileName);
163 pFileName = wszDir + lstrlenW(wszDir);
164 while(*pFileName != '.' && *pFileName != '\\' && *pFileName != '/'
165 && pFileName > wszDir) pFileName -= 1;
166 if(*pFileName == '.')
168 *pFileName = '\0';
169 while(*pFileName != '\\' && *pFileName != '/' && pFileName > wszDir)
170 pFileName -= 1;
172 if(*pFileName == '\\' || *pFileName == '/') pFileName += 1;
173 lstrcpyW(wszPath, pFileName);
175 GetCurrentDirectoryW(MAX_LOAD_STRING, wszDir);
177 saveidl.lStructSize = sizeof(OPENFILENAMEW);
178 saveidl.hwndOwner = globals.hTypeLibWnd;
179 saveidl.hInstance = globals.hMainInst;
180 saveidl.lpstrFilter = wszIdlFiles;
181 saveidl.lpstrFile = wszPath;
182 saveidl.nMaxFile = MAX_LOAD_STRING;
183 saveidl.lpstrInitialDir = wszDir;
184 saveidl.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
185 saveidl.lpstrDefExt = wszDefaultExt;
187 if (GetSaveFileNameW(&saveidl))
188 SaveIdl(wszPath);
191 static void AddToStrW(WCHAR *wszDest, const WCHAR *wszSource)
193 lstrcpyW(&wszDest[lstrlenW(wszDest)], wszSource);
196 static void AddToTLDataStrW(TYPELIB_DATA *pTLData, const WCHAR *wszSource)
198 int SourceLen = lstrlenW(wszSource);
200 pTLData->idl = HeapReAlloc(GetProcessHeap(), 0, pTLData->idl,
201 sizeof(WCHAR)*(pTLData->idlLen+SourceLen+1));
203 memcpy(&pTLData->idl[pTLData->idlLen], wszSource, sizeof(WCHAR)*(SourceLen+1));
204 pTLData->idlLen += SourceLen;
207 static void AddToTLDataStrWithTabsW(TYPELIB_DATA *pTLData, WCHAR *wszSource)
209 int lineLen = lstrlenW(wszSource);
210 int newLinesNo = 0;
211 WCHAR *pSourcePos = wszSource;
212 WCHAR *pSourceBeg;
214 if(!lineLen) return;
215 while(*pSourcePos)
217 if(*pSourcePos == *wszNewLine) newLinesNo++;
218 pSourcePos += 1;
220 if(*(pSourcePos - 1) != *wszNewLine) newLinesNo++;
222 pTLData->idl = HeapReAlloc(GetProcessHeap(), 0, pTLData->idl,
223 sizeof(WCHAR)*(pTLData->idlLen+lineLen+4*newLinesNo+1));
225 pSourcePos = wszSource;
226 pSourceBeg = wszSource;
227 while(newLinesNo)
229 if(*pSourcePos != *wszNewLine && *pSourcePos)
231 pSourcePos += 1;
232 continue;
234 newLinesNo--;
236 if(*pSourcePos)
238 *pSourcePos = '\0';
239 lineLen = lstrlenW(pSourceBeg)+1;
240 *pSourcePos = '\n';
241 pSourcePos += 1;
243 else lineLen = lstrlenW(pSourceBeg);
245 pTLData->idl[pTLData->idlLen] = *wszSpace;
246 pTLData->idl[pTLData->idlLen+1] = *wszSpace;
247 pTLData->idl[pTLData->idlLen+2] = *wszSpace;
248 pTLData->idl[pTLData->idlLen+3] = *wszSpace;
249 memcpy(&pTLData->idl[pTLData->idlLen+4], pSourceBeg, sizeof(WCHAR)*lineLen);
250 pTLData->idlLen += lineLen + 4;
251 pTLData->idl[pTLData->idlLen] = '\0';
253 pSourceBeg = pSourcePos;
257 static TYPELIB_DATA *InitializeTLData(void)
259 TYPELIB_DATA *pTLData;
261 pTLData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TYPELIB_DATA));
263 pTLData->idl = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR));
264 pTLData->idl[0] = '\0';
266 return pTLData;
269 static void AddSpaces(TYPELIB_DATA *pTLData, int tabSize)
271 for(; tabSize>0; tabSize--)
272 AddToTLDataStrW(pTLData, wszSpace);
275 static void AddChildrenData(HTREEITEM hParent, TYPELIB_DATA *pData)
277 HTREEITEM hCur;
278 TVITEMW tvi;
280 memset(&tvi, 0, sizeof(tvi));
282 hCur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
283 TVGN_CHILD, (LPARAM)hParent);
284 if(!hCur) return;
288 tvi.hItem = hCur;
289 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
290 if(tvi.lParam && ((TYPELIB_DATA *)(tvi.lParam))->idlLen)
291 AddToTLDataStrWithTabsW(pData, ((TYPELIB_DATA *)(tvi.lParam))->idl);
292 } while((hCur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
293 TVGN_NEXT, (LPARAM)hCur)));
296 static void CreateTypeInfo(WCHAR *wszAddTo, WCHAR *wszAddAfter, TYPEDESC tdesc, ITypeInfo *pTypeInfo)
298 int i;
299 BSTR bstrData;
300 HRESULT hRes;
301 ITypeInfo *pRefTypeInfo;
302 WCHAR wszBuf[MAX_LOAD_STRING];
303 WCHAR wszFormat[] = { '[','%','l','u',']','\0' };
305 switch(tdesc.vt&VT_TYPEMASK)
307 #define VTADDTOSTR(x) case x:\
308 AddToStrW(wszAddTo, wsz##x);\
309 break
310 VTADDTOSTR(VT_BOOL);
311 VTADDTOSTR(VT_UI1);
312 VTADDTOSTR(VT_UI2);
313 VTADDTOSTR(VT_UI4);
314 VTADDTOSTR(VT_UI8);
315 VTADDTOSTR(VT_UINT);
316 VTADDTOSTR(VT_I1);
317 VTADDTOSTR(VT_I2);
318 VTADDTOSTR(VT_I4);
319 VTADDTOSTR(VT_I8);
320 VTADDTOSTR(VT_R4);
321 VTADDTOSTR(VT_INT);
322 VTADDTOSTR(VT_BSTR);
323 VTADDTOSTR(VT_CY);
324 VTADDTOSTR(VT_VARIANT);
325 VTADDTOSTR(VT_VOID);
326 VTADDTOSTR(VT_ERROR);
327 VTADDTOSTR(VT_LPSTR);
328 VTADDTOSTR(VT_LPWSTR);
329 VTADDTOSTR(VT_HRESULT);
330 VTADDTOSTR(VT_UNKNOWN);
331 VTADDTOSTR(VT_DISPATCH);
332 VTADDTOSTR(VT_DATE);
333 VTADDTOSTR(VT_R8);
334 case VT_CARRAY:
335 for(i=0; i<U(tdesc).lpadesc->cDims; i++)
337 wsprintfW(wszBuf, wszFormat, U(tdesc).lpadesc->rgbounds[i].cElements);
338 AddToStrW(wszAddAfter, wszBuf);
340 CreateTypeInfo(wszAddTo, wszAddAfter, U(tdesc).lpadesc->tdescElem, pTypeInfo);
341 break;
342 case VT_SAFEARRAY:
343 AddToStrW(wszAddTo, wszVT_SAFEARRAY);
344 AddToStrW(wszAddTo, wszOpenBrackets2);
345 CreateTypeInfo(wszAddTo, wszAddAfter, *U(tdesc).lptdesc, pTypeInfo);
346 AddToStrW(wszAddTo, wszCloseBrackets2);
347 break;
348 case VT_PTR:
349 CreateTypeInfo(wszAddTo, wszAddAfter, *U(tdesc).lptdesc, pTypeInfo);
350 AddToStrW(wszAddTo, wszAsterix);
351 break;
352 case VT_USERDEFINED:
353 hRes = ITypeInfo_GetRefTypeInfo(pTypeInfo,
354 U(tdesc).hreftype, &pRefTypeInfo);
355 if(SUCCEEDED(hRes))
357 ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL,
358 &bstrData, NULL, NULL, NULL);
359 AddToStrW(wszAddTo, bstrData);
360 SysFreeString(bstrData);
361 ITypeInfo_Release(pRefTypeInfo);
363 else AddToStrW(wszAddTo, wszFailed);
364 break;
365 default:
366 WINE_FIXME("tdesc.vt&VT_TYPEMASK == %d not supported\n",
367 tdesc.vt&VT_TYPEMASK);
371 static int EnumVars(ITypeInfo *pTypeInfo, int cVars, HTREEITEM hParent)
373 int i;
374 TVINSERTSTRUCTW tvis;
375 VARDESC *pVarDesc;
376 BSTR bstrName;
377 WCHAR wszText[MAX_LOAD_STRING];
378 WCHAR wszAfter[MAX_LOAD_STRING];
380 U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM;
381 U(tvis).item.cchTextMax = MAX_LOAD_STRING;
382 U(tvis).item.pszText = wszText;
383 tvis.hInsertAfter = TVI_LAST;
384 tvis.hParent = hParent;
386 for(i=0; i<cVars; i++)
388 TYPELIB_DATA *tld;
390 if(FAILED(ITypeInfo_GetVarDesc(pTypeInfo, i, &pVarDesc))) continue;
391 if(FAILED(ITypeInfo_GetDocumentation(pTypeInfo, pVarDesc->memid, &bstrName,
392 NULL, NULL, NULL))) continue;
394 tld = InitializeTLData();
395 U(tvis).item.lParam = (LPARAM) tld;
396 if(pVarDesc->memid < MIN_VAR_ID)
399 AddToTLDataStrW(tld, wszOpenBrackets1);
400 AddToTLDataStrW(tld, wszId);
401 AddToTLDataStrW(tld, wszOpenBrackets2);
402 wsprintfW(wszText, wszFormat, pVarDesc->memid);
403 AddToTLDataStrW(tld, wszText);
404 memset(wszText, 0, sizeof(wszText));
405 AddToTLDataStrW(tld, wszCloseBrackets2);
407 if(pVarDesc->wVarFlags & VARFLAG_FREADONLY)
409 AddToTLDataStrW(tld, wszComa);
410 AddToTLDataStrW(tld, wszSpace);
411 AddToTLDataStrW(tld, wszReadOnly);
413 AddToTLDataStrW(tld, wszCloseBrackets1);
414 AddToTLDataStrW(tld, wszNewLine);
417 memset(wszText, 0, sizeof(wszText));
418 memset(wszAfter, 0, sizeof(wszAfter));
419 CreateTypeInfo(wszText, wszAfter, pVarDesc->elemdescVar.tdesc, pTypeInfo);
420 AddToStrW(wszText, wszSpace);
421 if (bstrName) AddToStrW(wszText, bstrName);
422 AddToStrW(wszText, wszAfter);
423 AddToTLDataStrW(tld, wszText);
424 AddToTLDataStrW(tld, wszSemicolon);
425 AddToTLDataStrW(tld, wszNewLine);
427 SendMessageW(typelib.hTree, TVM_INSERTITEMW, 0, (LPARAM)&tvis);
428 SysFreeString(bstrName);
429 ITypeInfo_ReleaseVarDesc(pTypeInfo, pVarDesc);
432 return 0;
435 static int EnumEnums(ITypeInfo *pTypeInfo, int cVars, HTREEITEM hParent)
437 int i;
438 TVINSERTSTRUCTW tvis;
439 VARDESC *pVarDesc;
440 BSTR bstrName;
441 WCHAR wszText[MAX_LOAD_STRING];
442 WCHAR wszAfter[MAX_LOAD_STRING];
444 U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM;
445 U(tvis).item.cchTextMax = MAX_LOAD_STRING;
446 U(tvis).item.pszText = wszText;
447 tvis.hInsertAfter = TVI_LAST;
448 tvis.hParent = hParent;
450 for(i=0; i<cVars; i++)
452 TYPELIB_DATA *tld;
454 if(FAILED(ITypeInfo_GetVarDesc(pTypeInfo, i, &pVarDesc))) continue;
455 if(FAILED(ITypeInfo_GetDocumentation(pTypeInfo, pVarDesc->memid, &bstrName,
456 NULL, NULL, NULL))) continue;
458 tld = InitializeTLData();
459 U(tvis).item.lParam = (LPARAM) tld;
461 memset(wszText, 0, sizeof(wszText));
462 memset(wszAfter, 0, sizeof(wszAfter));
464 if (pVarDesc->varkind == VAR_CONST)
466 VARIANT var;
467 VariantInit(&var);
468 if (VariantChangeType(&var, U(*pVarDesc).lpvarValue, 0, VT_BSTR) == S_OK)
470 AddToStrW(wszText, wszConst);
471 AddToStrW(wszText, wszSpace);
472 AddToStrW(wszAfter, wszSpace);
473 AddToStrW(wszAfter, wszEquals);
474 AddToStrW(wszAfter, wszSpace);
475 AddToStrW(wszAfter, V_BSTR(&var));
479 CreateTypeInfo(wszText, wszAfter, pVarDesc->elemdescVar.tdesc, pTypeInfo);
480 AddToStrW(wszText, wszSpace);
481 AddToStrW(wszText, bstrName);
482 AddToStrW(wszText, wszAfter);
483 AddToTLDataStrW(tld, bstrName);
484 AddToTLDataStrW(tld, wszAfter);
485 if (i<cVars-1)
486 AddToTLDataStrW(tld, wszComa);
487 AddToTLDataStrW(tld, wszNewLine);
489 SendMessageW(typelib.hTree, TVM_INSERTITEMW, 0, (LPARAM)&tvis);
490 SysFreeString(bstrName);
491 ITypeInfo_ReleaseVarDesc(pTypeInfo, pVarDesc);
494 return 0;
497 static int EnumFuncs(ITypeInfo *pTypeInfo, TYPEATTR *pTypeAttr, HTREEITEM hParent)
499 int i, j;
500 int cFuncs;
501 unsigned namesNo;
502 TVINSERTSTRUCTW tvis;
503 FUNCDESC *pFuncDesc;
504 BSTR bstrName, bstrHelpString, *bstrParamNames;
505 WCHAR wszText[MAX_LOAD_STRING];
506 WCHAR wszAfter[MAX_LOAD_STRING];
507 WCHAR szRhs[] = {'r','h','s',0}; /* Right-hand side of a propput */
508 BOOL bFirst;
510 U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM;
511 tvis.hInsertAfter = TVI_LAST;
512 tvis.hParent = hParent;
514 cFuncs = pTypeAttr->cFuncs;
516 i = 0;
517 if(pTypeAttr->wTypeFlags & TYPEFLAG_FDUAL) { /* skip 7 members of IDispatch */
518 cFuncs += 7;
519 i += 7;
522 for(; i<cFuncs; i++)
524 TYPELIB_DATA *tld;
526 if(FAILED(ITypeInfo_GetFuncDesc(pTypeInfo, i, &pFuncDesc))) continue;
528 if(FAILED(ITypeInfo_GetDocumentation(pTypeInfo, pFuncDesc->memid, &bstrName,
529 &bstrHelpString, NULL, NULL))) continue;
531 memset(wszText, 0, sizeof(wszText));
532 memset(wszAfter, 0, sizeof(wszAfter));
533 tld = InitializeTLData();
534 U(tvis).item.cchTextMax = SysStringLen(bstrName);
535 U(tvis).item.pszText = bstrName;
536 U(tvis).item.lParam = (LPARAM) tld;
537 bFirst = TRUE;
538 if(pFuncDesc->memid < MIN_FUNC_ID || pTypeAttr->wTypeFlags & TYPEFLAG_FDUAL)
540 AddToTLDataStrW(tld, wszOpenBrackets1);
541 bFirst = FALSE;
542 AddToTLDataStrW(tld, wszId);
543 AddToTLDataStrW(tld, wszOpenBrackets2);
544 wsprintfW(wszText, wszFormat, pFuncDesc->memid);
545 AddToTLDataStrW(tld, wszText);
546 AddToTLDataStrW(tld, wszCloseBrackets2);
547 memset(wszText, 0, sizeof(wszText));
550 CreateTypeInfo(wszText, wszAfter, pFuncDesc->elemdescFunc.tdesc, pTypeInfo);
551 switch(pFuncDesc->invkind)
553 case INVOKE_PROPERTYGET:
554 if(bFirst) AddToTLDataStrW(tld, wszOpenBrackets1);
555 else
557 AddToTLDataStrW(tld, wszComa);
558 AddToTLDataStrW(tld, wszSpace);
560 bFirst = FALSE;
561 AddToTLDataStrW(tld, wszPropGet);
562 break;
563 case INVOKE_PROPERTYPUT:
564 if(bFirst) AddToTLDataStrW(tld, wszOpenBrackets1);
565 else
567 AddToTLDataStrW(tld, wszComa);
568 AddToTLDataStrW(tld, wszSpace);
570 bFirst = FALSE;
571 AddToTLDataStrW(tld, wszPropPut);
572 break;
573 case INVOKE_PROPERTYPUTREF:
574 if(bFirst) AddToTLDataStrW(tld, wszOpenBrackets1);
575 else
577 AddToTLDataStrW(tld, wszComa);
578 AddToTLDataStrW(tld, wszSpace);
580 bFirst = FALSE;
581 AddToTLDataStrW(tld, wszPropPutRef);
582 break;
583 default:;
585 if(SysStringLen(bstrHelpString))
587 if(bFirst) AddToTLDataStrW(tld, wszOpenBrackets1);
588 else
590 AddToTLDataStrW(tld, wszComa);
591 AddToTLDataStrW(tld, wszSpace);
593 bFirst = FALSE;
594 AddToTLDataStrW(tld, wszHelpstring);
595 AddToTLDataStrW(tld, wszOpenBrackets2);
596 AddToTLDataStrW(tld, wszInvertedComa);
597 AddToTLDataStrW(tld, bstrHelpString);
598 AddToTLDataStrW(tld, wszInvertedComa);
599 AddToTLDataStrW(tld, wszCloseBrackets2);
601 if(!bFirst)
603 AddToTLDataStrW(tld, wszCloseBrackets1);
604 AddToTLDataStrW(tld, wszNewLine);
607 if(pTypeAttr->wTypeFlags & TYPEFLAG_FOLEAUTOMATION) {
608 AddToTLDataStrW(tld, wszVT_HRESULT);
609 if(lstrcmpW(wszText, wszVT_VOID)) pFuncDesc->cParams++;
611 else {
612 AddToTLDataStrW(tld, wszText);
613 AddToTLDataStrW(tld, wszAfter);
616 bstrParamNames = HeapAlloc(GetProcessHeap(), 0,
617 sizeof(BSTR)*(pFuncDesc->cParams+1));
618 if(FAILED(ITypeInfo_GetNames(pTypeInfo, pFuncDesc->memid, bstrParamNames,
619 pFuncDesc->cParams+1, &namesNo)))
621 HeapFree(GetProcessHeap(), 0, bstrParamNames);
622 continue;
624 SysFreeString(bstrParamNames[0]);
626 AddToTLDataStrW(tld, wszSpace);
627 if(pFuncDesc->memid >= MIN_FUNC_ID)
629 AddToTLDataStrW(tld, wszStdCall);
630 AddToTLDataStrW(tld, wszSpace);
632 if (bstrName) AddToTLDataStrW(tld, bstrName);
633 AddToTLDataStrW(tld, wszOpenBrackets2);
635 for(j=0; j<pFuncDesc->cParams; j++)
637 if(j != 0) AddToTLDataStrW(tld, wszComa);
638 if(pFuncDesc->cParams != 1)
640 AddToTLDataStrW(tld, wszNewLine);
641 AddSpaces(tld, TAB_SIZE);
643 bFirst = TRUE;
644 #define ENUM_PARAM_FLAG(x)\
645 if(U(pFuncDesc->lprgelemdescParam[j]).paramdesc.wParamFlags & x) \
647 if(bFirst) AddToTLDataStrW(tld,\
648 wszOpenBrackets1);\
649 else\
651 AddToTLDataStrW(tld, wszComa);\
652 AddToTLDataStrW(tld, wszSpace);\
654 bFirst = FALSE;\
655 AddToTLDataStrW(tld, wsz##x);\
657 ENUM_PARAM_FLAG(PARAMFLAG_FIN);
658 ENUM_PARAM_FLAG(PARAMFLAG_FOUT);
659 ENUM_PARAM_FLAG(PARAMFLAG_FLCID);
660 ENUM_PARAM_FLAG(PARAMFLAG_FRETVAL);
661 ENUM_PARAM_FLAG(PARAMFLAG_FOPT);
662 ENUM_PARAM_FLAG(PARAMFLAG_FHASCUSTDATA);
664 if(U(pFuncDesc->lprgelemdescParam[j]).paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT)
666 VARIANT var, *param=&U(pFuncDesc->lprgelemdescParam[j]).paramdesc.pparamdescex->varDefaultValue;
667 VariantInit(&var);
668 if(bFirst) AddToTLDataStrW(tld,
669 wszOpenBrackets1);
670 else
672 AddToTLDataStrW(tld, wszComa);
673 AddToTLDataStrW(tld, wszSpace);
675 bFirst = FALSE;
676 AddToTLDataStrW(tld, wszDefaultValue);
677 AddToTLDataStrW(tld, wszOpenBrackets2);
678 if (V_VT(param) == VT_BSTR)
680 AddToTLDataStrW(tld, wszInvertedComa);
681 AddToTLDataStrW(tld, V_BSTR(param));
682 AddToTLDataStrW(tld, wszInvertedComa);
683 } else if (VariantChangeType(&var, param, 0, VT_BSTR) == S_OK)
684 AddToTLDataStrW(tld, V_BSTR(&var));
685 AddToTLDataStrW(tld, wszCloseBrackets2);
688 if(!bFirst)
690 AddToTLDataStrW(tld, wszCloseBrackets1);
691 AddToTLDataStrW(tld, wszSpace);
694 memset(wszText, 0, sizeof(wszText));
695 memset(wszAfter, 0, sizeof(wszAfter));
696 CreateTypeInfo(wszText, wszAfter, pFuncDesc->lprgelemdescParam[j].tdesc,
697 pTypeInfo);
698 AddToTLDataStrW(tld, wszText);
699 AddToTLDataStrW(tld, wszAfter);
700 AddToTLDataStrW(tld, wszSpace);
701 if (j+1 < namesNo) {
702 if (bstrParamNames[j+1])
704 AddToTLDataStrW(tld, bstrParamNames[j+1]);
705 SysFreeString(bstrParamNames[j+1]);
707 } else {
708 AddToTLDataStrW(tld, szRhs);
711 AddToTLDataStrW(tld, wszCloseBrackets2);
712 AddToTLDataStrW(tld, wszSemicolon);
713 AddToTLDataStrW(tld, wszNewLine);
715 SendMessageW(typelib.hTree, TVM_INSERTITEMW, 0, (LPARAM)&tvis);
716 HeapFree(GetProcessHeap(), 0, bstrParamNames);
717 SysFreeString(bstrName);
718 SysFreeString(bstrHelpString);
719 ITypeInfo_ReleaseFuncDesc(pTypeInfo, pFuncDesc);
722 return 0;
725 static int EnumImplTypes(ITypeInfo *pTypeInfo, int cImplTypes, HTREEITEM hParent)
727 int i;
728 TVINSERTSTRUCTW tvis;
729 ITypeInfo *pRefTypeInfo;
730 HREFTYPE hRefType;
731 TYPEATTR *pTypeAttr;
732 BSTR bstrName;
733 WCHAR wszInheritedInterfaces[MAX_LOAD_STRING];
735 if(!cImplTypes) return 0;
737 LoadStringW(globals.hMainInst, IDS_INHERITINTERFACES, wszInheritedInterfaces,
738 ARRAY_SIZE(wszInheritedInterfaces));
740 U(tvis).item.mask = TVIF_TEXT;
741 U(tvis).item.cchTextMax = MAX_LOAD_STRING;
742 U(tvis).item.pszText = wszInheritedInterfaces;
743 tvis.hInsertAfter = TVI_LAST;
744 tvis.hParent = hParent;
746 tvis.hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
748 for(i=0; i<cImplTypes; i++)
750 if(FAILED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo, i, &hRefType))) continue;
751 if(FAILED(ITypeInfo_GetRefTypeInfo(pTypeInfo, hRefType, &pRefTypeInfo)))
752 continue;
753 if(FAILED(ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL, &bstrName,
754 NULL, NULL, NULL)))
756 ITypeInfo_Release(pRefTypeInfo);
757 continue;
759 if(FAILED(ITypeInfo_GetTypeAttr(pRefTypeInfo, &pTypeAttr)))
761 ITypeInfo_Release(pRefTypeInfo);
762 continue;
765 U(tvis).item.cchTextMax = SysStringLen(bstrName);
766 U(tvis).item.pszText = bstrName;
768 hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
769 EnumVars(pRefTypeInfo, pTypeAttr->cVars, hParent);
770 EnumFuncs(pRefTypeInfo, pTypeAttr, hParent);
771 EnumImplTypes(pRefTypeInfo, pTypeAttr->cImplTypes, hParent);
773 SysFreeString(bstrName);
774 ITypeInfo_ReleaseTypeAttr(pRefTypeInfo, pTypeAttr);
775 ITypeInfo_Release(pRefTypeInfo);
778 return 0;
781 static void EnumCoclassImplTypes(ITypeInfo *pTypeInfo,
782 int cImplTypes, TYPELIB_DATA *pTLData)
784 int i;
785 ITypeInfo *pRefTypeInfo;
786 HREFTYPE hRefType;
787 TYPEATTR *pTypeAttr;
788 BSTR bstrName;
789 BOOL bFirst;
790 INT flags;
791 const WCHAR wszTKIND_INTERFACE[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' };
792 const WCHAR wszTKIND_DISPATCH[]
793 = { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' };
794 const WCHAR wszIMPLTYPEFLAG_FDEFAULT[]
795 = { 'd','e','f','a','u','l','t','\0' };
796 const WCHAR wszIMPLTYPEFLAG_FSOURCE[]
797 = { 's','o','u','r','c','e','\0' };
798 const WCHAR wszIMPLTYPEFLAG_FRESTRICTED[]
799 = { 'r','e','s','t','r','i','c','t','e','d','\0' };
801 for(i=0; i<cImplTypes; i++)
803 if(FAILED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo, i, &hRefType))) continue;
804 if(FAILED(ITypeInfo_GetRefTypeInfo(pTypeInfo, hRefType, &pRefTypeInfo)))
805 continue;
806 if(FAILED(ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL, &bstrName,
807 NULL, NULL, NULL)))
809 ITypeInfo_Release(pRefTypeInfo);
810 continue;
812 if(FAILED(ITypeInfo_GetTypeAttr(pRefTypeInfo, &pTypeAttr)))
814 ITypeInfo_Release(pRefTypeInfo);
815 continue;
818 AddSpaces(pTLData, TAB_SIZE);
819 ITypeInfo_GetImplTypeFlags(pTypeInfo, i, &flags);
820 bFirst = TRUE;
821 #define ENUM_IMPLTYPEFLAG(x)\
822 if(flags & x) \
824 if(bFirst) AddToTLDataStrW(pTLData,\
825 wszOpenBrackets1);\
826 else\
828 AddToTLDataStrW(pTLData, wszComa);\
829 AddToTLDataStrW(pTLData, wszSpace);\
831 bFirst = FALSE;\
832 AddToTLDataStrW(pTLData, wsz##x);\
834 ENUM_IMPLTYPEFLAG(IMPLTYPEFLAG_FDEFAULT);
835 ENUM_IMPLTYPEFLAG(IMPLTYPEFLAG_FSOURCE);
836 ENUM_IMPLTYPEFLAG(IMPLTYPEFLAG_FRESTRICTED);
837 if(!bFirst)
839 AddToTLDataStrW(pTLData, wszCloseBrackets1);
840 AddToTLDataStrW(pTLData, wszSpace);
843 if(pTypeAttr->typekind == TKIND_INTERFACE ||
844 (pTypeAttr->wTypeFlags & TYPEFLAG_FDUAL))
845 AddToTLDataStrW(pTLData, wszTKIND_INTERFACE);
846 else if(pTypeAttr->typekind == TKIND_DISPATCH)
847 AddToTLDataStrW(pTLData, wszTKIND_DISPATCH);
848 AddToTLDataStrW(pTLData, wszSpace);
850 AddToTLDataStrW(pTLData, bstrName);
851 AddToTLDataStrW(pTLData, wszSemicolon);
852 AddToTLDataStrW(pTLData, wszNewLine);
854 SysFreeString(bstrName);
855 ITypeInfo_ReleaseTypeAttr(pRefTypeInfo, pTypeAttr);
856 ITypeInfo_Release(pRefTypeInfo);
860 static void AddIdlData(HTREEITEM hCur, TYPELIB_DATA *pTLData)
862 TVITEMW tvi;
864 hCur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
865 TVGN_CHILD, (LPARAM)hCur);
866 memset(&tvi, 0, sizeof(TVITEMW));
867 tvi.mask = TVIF_PARAM;
869 while(hCur)
871 tvi.hItem = hCur;
872 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
873 if(!((TYPELIB_DATA*)(tvi.lParam))->bHide) {
874 AddToTLDataStrW(pTLData, wszNewLine);
875 AddToTLDataStrWithTabsW(pTLData, ((TYPELIB_DATA*)(tvi.lParam))->idl);
877 hCur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
878 TVGN_NEXT, (LPARAM)hCur);
882 static void AddPredefinitions(HTREEITEM hFirst, TYPELIB_DATA *pTLData)
884 HTREEITEM hCur;
885 TVITEMW tvi;
886 WCHAR wszText[MAX_LOAD_STRING];
887 WCHAR wszPredefinition[] = { '/','/',' ','T','L','i','b',' ',':','\n',
888 '/','/',' ','F','o','r','w','a','r','d',' ','d','e','c','l','a','r','e',' ',
889 'a','l','l',' ','t','y','p','e','s',' ','d','e','f','i','n','e','d',' ',
890 'i','n',' ','t','h','i','s',' ','t','y','p','e','l','i','b','\0' };
892 hFirst = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
893 TVGN_CHILD, (LPARAM)hFirst);
895 AddToTLDataStrWithTabsW(pTLData, wszPredefinition);
896 AddToTLDataStrW(pTLData, wszNewLine);
898 hCur = hFirst;
899 memset(&tvi, 0, sizeof(TVITEMW));
900 tvi.mask = TVIF_TEXT|TVIF_PARAM;
901 tvi.cchTextMax = MAX_LOAD_STRING;
902 tvi.pszText = wszText;
903 while(hCur)
905 tvi.hItem = hCur;
906 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
907 if(((TYPELIB_DATA*)(tvi.lParam))->bPredefine &&
908 !((TYPELIB_DATA*)(tvi.lParam))->bHide)
910 AddToStrW(wszText, wszSemicolon);
911 AddToTLDataStrWithTabsW(pTLData, wszText);
912 AddToTLDataStrW(pTLData, wszNewLine);
914 hCur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
915 TVGN_NEXT, (LPARAM)hCur);
919 static void CreateInterfaceInfo(ITypeInfo *pTypeInfo, int cImplTypes, WCHAR *wszName,
920 WCHAR *wszHelpString, ULONG ulHelpContext, TYPEATTR *pTypeAttr,
921 TYPELIB_DATA *pTLData)
923 ITypeInfo *pRefTypeInfo;
924 HREFTYPE hRefType;
925 BSTR bstrName;
926 WCHAR wszGuid[MAX_LOAD_STRING];
927 WCHAR wszHelpContext[MAX_LOAD_STRING];
929 const WCHAR wszInterface[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' };
930 const WCHAR wszDispinterface[]
931 = { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' };
932 const WCHAR wszHelpcontext[] = { 'h','e','l','p','c','o','n','t','e','x','t','\0' };
933 const WCHAR wszTYPEFLAG_FAPPOBJECT[] = { 'a','p','p','o','b','j','e','c','t','\0' };
934 const WCHAR wszTYPEFLAG_FCANCREATE[] = { 'c','a','n','c','r','e','a','t','e','\0' };
935 const WCHAR wszTYPEFLAG_FLICENSED[] = { 'l','i','c','e','n','s','e','d','\0' };
936 const WCHAR wszTYPEFLAG_FPREDECLID[] = { 'p','r','e','d','e','c','l','i','d','\0' };
937 const WCHAR wszTYPEFLAG_FHIDDEN[] = { 'h','i','d','d','e','n','\0' };
938 const WCHAR wszTYPEFLAG_FCONTROL[] = { 'c','o','n','t','r','o','l','\0' };
939 const WCHAR wszTYPEFLAG_FDUAL[] = { 'd','u','a','l','\0' };
940 const WCHAR wszTYPEFLAG_FNONEXTENSIBLE[]
941 = { 'n','o','n','e','x','t','e','n','s','i','b','l','e','\0' };
942 const WCHAR wszTYPEFLAG_FOLEAUTOMATION[]
943 = { 'o','l','e','a','u','t','o','m','a','t','i','o','n','\0' };
944 const WCHAR wszTYPEFLAG_FRESTRICTED[]
945 = { 'r','e','s','t','r','i','c','t','e','d','\0' };
946 const WCHAR wszTYPEFLAG_FAGGREGATABLE[]
947 = { 'a','g','g','r','e','g','a','t','a','b','l','e','\0' };
948 const WCHAR wszTYPEFLAG_FREPLACEABLE[]
949 = { 'r','e','p','l','a','c','a','b','l','e','\0' };
950 const WCHAR wszTYPEFLAG_FREVERSEBIND[]
951 = { 'r','e','v','e','r','s','e','b','i','n','d','\0' };
952 const WCHAR wszTYPEFLAG_FPROXY[] = { 'p','r','o','x','y','\0' };
954 AddToTLDataStrW(pTLData, wszOpenBrackets1);
955 AddToTLDataStrW(pTLData, wszNewLine);
956 if(pTypeAttr->typekind != TKIND_DISPATCH)
958 AddSpaces(pTLData, TAB_SIZE);
959 AddToTLDataStrW(pTLData, wszOdl);
960 AddToTLDataStrW(pTLData, wszComa);
961 AddToTLDataStrW(pTLData, wszNewLine);
963 AddSpaces(pTLData, TAB_SIZE);
964 AddToTLDataStrW(pTLData, wszUUID);
965 AddToTLDataStrW(pTLData, wszOpenBrackets2);
966 StringFromGUID2(&(pTypeAttr->guid), wszGuid, MAX_LOAD_STRING);
967 wszGuid[lstrlenW(wszGuid)-1] = '\0';
968 AddToTLDataStrW(pTLData, &wszGuid[1]);
969 AddToTLDataStrW(pTLData, wszCloseBrackets2);
970 if(wszHelpString)
972 AddToTLDataStrW(pTLData, wszComa);
973 AddToTLDataStrW(pTLData, wszNewLine);
974 AddSpaces(pTLData, TAB_SIZE);
975 AddToTLDataStrW(pTLData, wszHelpstring);
976 AddToTLDataStrW(pTLData, wszOpenBrackets2);
977 AddToTLDataStrW(pTLData, wszInvertedComa);
978 AddToTLDataStrW(pTLData, wszHelpString);
979 AddToTLDataStrW(pTLData, wszInvertedComa);
980 AddToTLDataStrW(pTLData, wszCloseBrackets2);
982 if(ulHelpContext)
984 AddToTLDataStrW(pTLData, wszComa);
985 AddToTLDataStrW(pTLData, wszNewLine);
986 AddSpaces(pTLData, TAB_SIZE);
987 AddToTLDataStrW(pTLData, wszHelpcontext);
988 AddToTLDataStrW(pTLData, wszOpenBrackets2);
989 wsprintfW(wszHelpContext, wszFormat, ulHelpContext);
990 AddToTLDataStrW(pTLData, wszHelpContext);
991 AddToTLDataStrW(pTLData, wszCloseBrackets2);
993 if(pTypeAttr->wTypeFlags)
995 #define ENUM_FLAGS(x) if(pTypeAttr->wTypeFlags & x)\
997 AddToTLDataStrW(pTLData, wszComa);\
998 AddToTLDataStrW(pTLData, wszNewLine);\
999 AddSpaces(pTLData, TAB_SIZE);\
1000 AddToTLDataStrW(pTLData, wsz##x);\
1002 ENUM_FLAGS(TYPEFLAG_FAPPOBJECT);
1003 ENUM_FLAGS(TYPEFLAG_FCANCREATE);
1004 ENUM_FLAGS(TYPEFLAG_FLICENSED);
1005 ENUM_FLAGS(TYPEFLAG_FPREDECLID);
1006 ENUM_FLAGS(TYPEFLAG_FHIDDEN);
1007 ENUM_FLAGS(TYPEFLAG_FCONTROL);
1008 ENUM_FLAGS(TYPEFLAG_FDUAL);
1009 ENUM_FLAGS(TYPEFLAG_FNONEXTENSIBLE);
1010 ENUM_FLAGS(TYPEFLAG_FOLEAUTOMATION);
1011 ENUM_FLAGS(TYPEFLAG_FRESTRICTED);
1012 ENUM_FLAGS(TYPEFLAG_FAGGREGATABLE);
1013 ENUM_FLAGS(TYPEFLAG_FREPLACEABLE);
1014 ENUM_FLAGS(TYPEFLAG_FREVERSEBIND);
1015 ENUM_FLAGS(TYPEFLAG_FPROXY);
1017 AddToTLDataStrW(pTLData, wszNewLine);
1018 AddToTLDataStrW(pTLData, wszCloseBrackets1);
1019 AddToTLDataStrW(pTLData, wszNewLine);
1020 if(pTypeAttr->typekind != TKIND_DISPATCH) AddToTLDataStrW(pTLData, wszInterface);
1021 else AddToTLDataStrW(pTLData, wszDispinterface);
1022 AddToTLDataStrW(pTLData, wszName);
1023 AddToTLDataStrW(pTLData, wszSpace);
1024 if(cImplTypes && pTypeAttr->typekind != TKIND_DISPATCH)
1026 AddToTLDataStrW(pTLData, wszColon);
1027 AddToTLDataStrW(pTLData, wszSpace);
1029 ITypeInfo_GetRefTypeOfImplType(pTypeInfo, 0, &hRefType);
1030 if (SUCCEEDED(ITypeInfo_GetRefTypeInfo(pTypeInfo, hRefType, &pRefTypeInfo)))
1032 ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL, &bstrName,
1033 NULL, NULL, NULL);
1034 AddToTLDataStrW(pTLData, bstrName);
1035 AddToTLDataStrW(pTLData, wszSpace);
1037 SysFreeString(bstrName);
1038 ITypeInfo_Release(pRefTypeInfo);
1040 else
1041 AddToTLDataStrW(pTLData, wszFailed);
1043 AddToTLDataStrW(pTLData, wszOpenBrackets3);
1044 AddToTLDataStrW(pTLData, wszNewLine);
1046 AddToStrW(pTLData->wszInsertAfter, wszCloseBrackets3);
1047 AddToStrW(pTLData->wszInsertAfter, wszSemicolon);
1048 AddToStrW(pTLData->wszInsertAfter, wszNewLine);
1051 static void CreateTypedefHeader(ITypeInfo *pTypeInfo,
1052 TYPEATTR *pTypeAttr, TYPELIB_DATA *pTLData)
1054 BOOL bFirst = TRUE;
1055 WCHAR wszGuid[MAX_LOAD_STRING];
1056 const WCHAR wszTypedef[] = { 't','y','p','e','d','e','f',' ','\0' };
1057 const WCHAR wszPublic[] = { 'p','u','b','l','i','c','\0' };
1059 AddToTLDataStrW(pTLData, wszTypedef);
1060 if(memcmp(&pTypeAttr->guid, &GUID_NULL, sizeof(GUID)))
1062 AddToTLDataStrW(pTLData, wszOpenBrackets1);
1063 bFirst = FALSE;
1064 AddToTLDataStrW(pTLData, wszUUID);
1065 AddToTLDataStrW(pTLData, wszOpenBrackets2);
1066 StringFromGUID2(&(pTypeAttr->guid), wszGuid, MAX_LOAD_STRING);
1067 wszGuid[lstrlenW(wszGuid)-1] = '\0';
1068 AddToTLDataStrW(pTLData, &wszGuid[1]);
1069 AddToTLDataStrW(pTLData, wszCloseBrackets2);
1071 if(pTypeAttr->typekind == TKIND_ALIAS)
1073 if(bFirst) AddToTLDataStrW(pTLData, wszOpenBrackets1);
1074 else
1076 AddToTLDataStrW(pTLData, wszComa);
1077 AddToTLDataStrW(pTLData, wszSpace);
1079 bFirst = FALSE;
1080 AddToTLDataStrW(pTLData, wszPublic);
1082 if(!bFirst)
1084 AddToTLDataStrW(pTLData, wszCloseBrackets1);
1085 AddToTLDataStrW(pTLData, wszNewLine);
1089 static void CreateCoclassHeader(ITypeInfo *pTypeInfo,
1090 TYPEATTR *pTypeAttr, TYPELIB_DATA *pTLData)
1092 WCHAR wszGuid[MAX_LOAD_STRING];
1093 BSTR bstrHelpString;
1094 const WCHAR wszNoncreatable[]
1095 = { 'n','o','n','c','r','e','a','t','a','b','l','e','\0' };
1097 AddToTLDataStrW(pTLData, wszOpenBrackets1);
1098 AddToTLDataStrW(pTLData, wszNewLine);
1100 AddSpaces(pTLData, TAB_SIZE);
1101 AddToTLDataStrW(pTLData, wszUUID);
1102 AddToTLDataStrW(pTLData, wszOpenBrackets2);
1103 StringFromGUID2(&(pTypeAttr->guid), wszGuid, MAX_LOAD_STRING);
1104 wszGuid[lstrlenW(wszGuid)-1] = '\0';
1105 AddToTLDataStrW(pTLData, &wszGuid[1]);
1106 AddToTLDataStrW(pTLData, wszCloseBrackets2);
1108 if(SUCCEEDED(ITypeInfo_GetDocumentation(pTypeInfo, MEMBERID_NIL, NULL,
1109 &bstrHelpString, NULL, NULL)))
1111 if(SysStringLen(bstrHelpString))
1113 AddToTLDataStrW(pTLData, wszComa);
1114 AddToTLDataStrW(pTLData, wszNewLine);
1115 AddSpaces(pTLData, TAB_SIZE);
1116 AddToTLDataStrW(pTLData, wszHelpstring);
1117 AddToTLDataStrW(pTLData, wszOpenBrackets2);
1118 AddToTLDataStrW(pTLData, wszInvertedComa);
1119 AddToTLDataStrW(pTLData, bstrHelpString);
1120 AddToTLDataStrW(pTLData, wszInvertedComa);
1121 AddToTLDataStrW(pTLData, wszCloseBrackets2);
1123 SysFreeString(bstrHelpString);
1126 if(!(pTypeAttr->wTypeFlags & TYPEFLAG_FCANCREATE))
1128 AddToTLDataStrW(pTLData, wszComa);
1129 AddToTLDataStrW(pTLData, wszNewLine);
1130 AddSpaces(pTLData, TAB_SIZE);
1131 AddToTLDataStrW(pTLData, wszNoncreatable);
1134 AddToTLDataStrW(pTLData, wszNewLine);
1135 AddToTLDataStrW(pTLData, wszCloseBrackets1);
1136 AddToTLDataStrW(pTLData, wszNewLine);
1139 static int PopulateTree(void)
1141 TVINSERTSTRUCTW tvis;
1142 TVITEMW tvi;
1143 ITypeLib *pTypeLib;
1144 TLIBATTR *pTLibAttr;
1145 ITypeInfo *pTypeInfo, *pRefTypeInfo;
1146 HREFTYPE hRefType;
1147 TYPEATTR *pTypeAttr;
1148 INT count, i;
1149 ULONG ulHelpContext;
1150 BSTR bstrName;
1151 BSTR bstrData;
1152 WCHAR wszText[MAX_LOAD_STRING];
1153 WCHAR wszAfter[MAX_LOAD_STRING];
1154 HRESULT hRes;
1155 HTREEITEM hParent;
1156 HTREEITEM hMain;
1157 BOOL bInsert;
1158 TYPELIB_DATA *tldDispatch;
1159 TYPELIB_DATA *tld;
1161 const WCHAR wszGeneratedInfo[] = { '/','/',' ','G','e','n','e','r','a','t','e','d',
1162 ' ','.','I','D','L',' ','f','i','l','e',' ','(','b','y',' ','t','h','e',' ',
1163 'O','L','E','/','C','O','M',' ','O','b','j','e','c','t',' ',
1164 'V','i','e','w','e','r',')','\n','/','/','\n','/','/',' ',
1165 't','y','p','e','l','i','b',' ','f','i','l','e','n','a','m','e',':',' ','\0'};
1167 const WCHAR wszFormat[] = { '%','s',' ','(','%','s',')','\0' };
1168 const WCHAR wszFormat2[] = { 'v','e','r','s','i','o','n',
1169 '(','%','l','d','.','%','l','d',')','\0' };
1171 const WCHAR wszTKIND_ENUM[] = { 't','y','p','e','d','e','f',' ','e','n','u','m',' ','\0' };
1172 const WCHAR wszTKIND_RECORD[]
1173 = { 't','y','p','e','d','e','f',' ','s','t','r','u','c','t',' ','\0' };
1174 const WCHAR wszTKIND_MODULE[] = { 'm','o','d','u','l','e',' ','\0' };
1175 const WCHAR wszTKIND_INTERFACE[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' };
1176 const WCHAR wszTKIND_DISPATCH[]
1177 = { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' };
1178 const WCHAR wszTKIND_COCLASS[] = { 'c','o','c','l','a','s','s',' ','\0' };
1179 const WCHAR wszTKIND_ALIAS[] = { 't','y','p','e','d','e','f',' ','\0' };
1180 const WCHAR wszTKIND_UNION[]
1181 = { 't','y','p','e','d','e','f',' ','u','n','i','o','n',' ','\0' };
1183 const WCHAR wszLibrary[] = { 'l','i','b','r','a','r','y',' ','\0' };
1184 const WCHAR wszTag[] = { 't','a','g','\0' };
1186 WCHAR wszProperties[] = { 'p','r','o','p','e','r','t','i','e','s','\0' };
1187 WCHAR wszMethods[] = { 'm','e','t','h','o','d','s','\0' };
1189 U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM;
1190 U(tvis).item.cchTextMax = MAX_LOAD_STRING;
1191 U(tvis).item.pszText = wszText;
1192 tvis.hInsertAfter = TVI_LAST;
1193 tvis.hParent = TVI_ROOT;
1195 if(FAILED((hRes = LoadTypeLib(typelib.wszFileName, &pTypeLib))))
1197 WCHAR wszMessage[MAX_LOAD_STRING];
1198 WCHAR wszError[MAX_LOAD_STRING];
1199 DWORD_PTR args[2];
1201 LoadStringW(globals.hMainInst, IDS_ERROR_LOADTYPELIB, wszError, ARRAY_SIZE(wszError));
1202 args[0] = (DWORD_PTR)typelib.wszFileName;
1203 args[1] = hRes;
1204 FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
1205 wszError, 0, 0, wszMessage, ARRAY_SIZE(wszMessage), (__ms_va_list*)args);
1206 MessageBoxW(globals.hMainWnd, wszMessage, NULL, MB_OK|MB_ICONEXCLAMATION);
1207 return 1;
1209 count = ITypeLib_GetTypeInfoCount(pTypeLib);
1211 ITypeLib_GetDocumentation(pTypeLib, -1, &bstrName, &bstrData, NULL, NULL);
1212 ITypeLib_GetLibAttr(pTypeLib, &pTLibAttr);
1214 tld = InitializeTLData();
1215 U(tvis).item.lParam = (LPARAM) tld;
1216 AddToTLDataStrW(tld, wszGeneratedInfo);
1217 AddToTLDataStrW(tld, typelib.wszFileName);
1218 AddToTLDataStrW(tld, wszNewLine);
1219 AddToTLDataStrW(tld, wszNewLine);
1220 AddToTLDataStrW(tld, wszOpenBrackets1);
1221 AddToTLDataStrW(tld, wszNewLine);
1222 AddSpaces(tld, TAB_SIZE);
1223 AddToTLDataStrW(tld, wszUUID);
1224 AddToTLDataStrW(tld, wszOpenBrackets2);
1225 StringFromGUID2(&(pTLibAttr->guid), wszText, MAX_LOAD_STRING);
1226 wszText[lstrlenW(wszText)-1] = '\0';
1227 AddToTLDataStrW(tld, &wszText[1]);
1228 AddToTLDataStrW(tld, wszCloseBrackets2);
1229 AddToTLDataStrW(tld, wszComa);
1230 AddToTLDataStrW(tld, wszNewLine);
1231 AddSpaces(tld, TAB_SIZE);
1232 wsprintfW(wszText, wszFormat2, pTLibAttr->wMajorVerNum, pTLibAttr->wMinorVerNum);
1233 AddToTLDataStrW(tld, wszText);
1235 if (bstrData)
1237 /* helpstring is optional */
1238 AddToTLDataStrW(tld, wszComa);
1239 AddToTLDataStrW(tld, wszNewLine);
1240 AddSpaces(tld, TAB_SIZE);
1241 AddToTLDataStrW(tld, wszHelpstring);
1242 AddToTLDataStrW(tld, wszOpenBrackets2);
1243 AddToTLDataStrW(tld, wszInvertedComa);
1244 AddToTLDataStrW(tld, bstrData);
1245 AddToTLDataStrW(tld, wszInvertedComa);
1246 AddToTLDataStrW(tld, wszCloseBrackets2);
1249 AddToTLDataStrW(tld, wszNewLine);
1250 AddToTLDataStrW(tld, wszCloseBrackets1);
1251 AddToTLDataStrW(tld, wszNewLine);
1252 AddToTLDataStrW(tld, wszLibrary);
1253 if (bstrName) AddToTLDataStrW(tld, bstrName);
1254 AddToTLDataStrW(tld, wszNewLine);
1255 AddToTLDataStrW(tld, wszOpenBrackets3);
1256 AddToTLDataStrW(tld, wszNewLine);
1258 AddToStrW(tld->wszInsertAfter, wszCloseBrackets3);
1259 AddToStrW(tld->wszInsertAfter, wszSemicolon);
1261 wsprintfW(wszText, wszFormat, bstrName, bstrData);
1262 SysFreeString(bstrName);
1263 SysFreeString(bstrData);
1264 tvis.hParent = (HTREEITEM)SendMessageW(typelib.hTree,
1265 TVM_INSERTITEMW, 0, (LPARAM)&tvis);
1267 for(i=0; i<count; i++)
1269 bInsert = TRUE;
1270 ITypeLib_GetTypeInfo(pTypeLib, i, &pTypeInfo);
1272 ITypeInfo_GetDocumentation(pTypeInfo, MEMBERID_NIL, &bstrName, &bstrData,
1273 &ulHelpContext, NULL);
1274 ITypeInfo_GetTypeAttr(pTypeInfo, &pTypeAttr);
1276 memset(wszText, 0, sizeof(wszText));
1277 memset(wszAfter, 0, sizeof(wszAfter));
1278 tld = InitializeTLData();
1279 U(tvis).item.lParam = (LPARAM)tld;
1280 switch(pTypeAttr->typekind)
1282 case TKIND_ENUM:
1283 AddToStrW(wszText, wszTKIND_ENUM);
1284 AddToStrW(wszText, bstrName);
1286 CreateTypedefHeader(pTypeInfo, pTypeAttr, tld);
1287 AddToTLDataStrW(tld, &wszTKIND_ENUM[lstrlenW(wszTKIND_ALIAS)]);
1288 AddToTLDataStrW(tld, wszOpenBrackets3);
1289 AddToTLDataStrW(tld,wszNewLine);
1290 AddToStrW(tld->wszInsertAfter, wszCloseBrackets3);
1291 AddToStrW(tld->wszInsertAfter, wszSpace);
1292 AddToStrW(tld->wszInsertAfter, bstrName);
1293 AddToStrW(tld->wszInsertAfter, wszSemicolon);
1294 AddToStrW(tld->wszInsertAfter, wszNewLine);
1296 bInsert = FALSE;
1297 hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1298 EnumEnums(pTypeInfo, pTypeAttr->cVars, hParent);
1299 AddChildrenData(hParent, tld);
1300 AddToTLDataStrW(tld, tld->wszInsertAfter);
1301 break;
1302 case TKIND_RECORD:
1303 AddToTLDataStrW(tld, wszTKIND_RECORD);
1304 AddToTLDataStrW(tld, wszTag);
1305 AddToTLDataStrW(tld, bstrName);
1306 AddToTLDataStrW(tld, wszSpace);
1307 AddToTLDataStrW(tld, wszOpenBrackets3);
1308 AddToTLDataStrW(tld, wszNewLine);
1310 AddToStrW(tld->wszInsertAfter, wszCloseBrackets3);
1311 AddToStrW(tld->wszInsertAfter, wszSpace);
1312 AddToStrW(tld->wszInsertAfter, bstrName);
1313 AddToStrW(tld->wszInsertAfter, wszSemicolon);
1314 AddToStrW(tld->wszInsertAfter, wszNewLine);
1316 AddToStrW(wszText, wszTKIND_RECORD);
1317 AddToStrW(wszText, bstrName);
1318 break;
1319 case TKIND_MODULE:
1320 AddToStrW(wszText, wszTKIND_MODULE);
1321 AddToStrW(wszText, bstrName);
1322 break;
1323 case TKIND_INTERFACE:
1324 CreateInterfaceInfo(pTypeInfo, pTypeAttr->cImplTypes, bstrName,
1325 bstrData, ulHelpContext, pTypeAttr, tld);
1326 tld->bPredefine = TRUE;
1328 AddToStrW(wszText, wszTKIND_INTERFACE);
1329 AddToStrW(wszText, bstrName);
1330 break;
1331 case TKIND_COCLASS:
1332 AddToStrW(wszText, wszTKIND_COCLASS);
1333 AddToStrW(wszText, bstrName);
1335 CreateCoclassHeader(pTypeInfo, pTypeAttr, tld);
1336 AddToTLDataStrW(tld, wszTKIND_COCLASS);
1337 AddToTLDataStrW(tld, bstrName);
1338 AddToTLDataStrW(tld, wszSpace);
1339 AddToTLDataStrW(tld, wszOpenBrackets3);
1340 AddToTLDataStrW(tld, wszNewLine);
1342 EnumCoclassImplTypes(pTypeInfo, pTypeAttr->cImplTypes, tld);
1344 AddToStrW(tld->wszInsertAfter, wszCloseBrackets3);
1345 AddToStrW(tld->wszInsertAfter, wszSemicolon);
1346 AddToStrW(tld->wszInsertAfter, wszNewLine);
1348 bInsert = FALSE;
1349 hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1350 AddToTLDataStrW(tld, tld->wszInsertAfter);
1351 break;
1352 case TKIND_UNION:
1353 AddToStrW(wszText, wszTKIND_UNION);
1354 AddToStrW(wszText, bstrName);
1355 break;
1356 case TKIND_DISPATCH:
1357 CreateInterfaceInfo(pTypeInfo, pTypeAttr->cImplTypes, bstrName,
1358 bstrData, ulHelpContext, pTypeAttr, tld);
1359 tld->bPredefine = TRUE;
1360 if(pTypeAttr->wTypeFlags & TYPEFLAG_FDUAL)
1361 tld->bHide = TRUE;
1362 AddToStrW(wszText, wszTKIND_DISPATCH);
1363 AddToStrW(wszText, bstrName);
1365 hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1366 hMain = tvis.hParent;
1367 tldDispatch = tld;
1369 lstrcpyW(wszText, wszProperties);
1370 tvis.hParent = hParent;
1371 tld = InitializeTLData();
1372 U(tvis).item.lParam = (LPARAM) tld;
1373 AddToTLDataStrW(tld, wszProperties);
1374 AddToTLDataStrW(tld, wszColon);
1375 AddToTLDataStrW(tld, wszNewLine);
1376 tvis.hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1377 EnumVars(pTypeInfo, pTypeAttr->cVars, tvis.hParent);
1378 AddChildrenData(tvis.hParent, tld);
1380 lstrcpyW(wszText, wszMethods);
1381 tvis.hParent = hParent;
1382 tld = InitializeTLData();
1383 U(tvis).item.lParam = (LPARAM) tld;
1384 AddToTLDataStrW(tld, wszMethods);
1385 AddToTLDataStrW(tld, wszColon);
1386 AddToTLDataStrW(tld, wszNewLine);
1387 tvis.hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1388 EnumFuncs(pTypeInfo, pTypeAttr, tvis.hParent);
1389 AddChildrenData(tvis.hParent, tld);
1391 EnumImplTypes(pTypeInfo, pTypeAttr->cImplTypes, hParent);
1392 AddChildrenData(hParent, tldDispatch);
1393 AddToTLDataStrW(tldDispatch, tldDispatch->wszInsertAfter);
1395 bInsert = FALSE;
1396 tvis.hParent = hMain;
1398 if(SUCCEEDED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo, -1, &hRefType)))
1400 bInsert = TRUE;
1402 ITypeInfo_ReleaseTypeAttr(pTypeInfo, pTypeAttr);
1403 SysFreeString(bstrName);
1404 SysFreeString(bstrData);
1406 memset(wszText, 0, sizeof(wszText));
1407 tld = InitializeTLData();
1408 U(tvis).item.lParam = (LPARAM) tld;
1410 ITypeInfo_GetRefTypeInfo(pTypeInfo, hRefType, &pRefTypeInfo);
1411 ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL, &bstrName,
1412 &bstrData, &ulHelpContext, NULL);
1413 ITypeInfo_GetTypeAttr(pRefTypeInfo, &pTypeAttr);
1415 CreateInterfaceInfo(pTypeInfo, pTypeAttr->cImplTypes, bstrName,
1416 bstrData, ulHelpContext, pTypeAttr, tld);
1417 tld->bPredefine = TRUE;
1419 AddToStrW(wszText, wszTKIND_INTERFACE);
1420 AddToStrW(wszText, bstrName);
1421 ITypeInfo_Release(pRefTypeInfo);
1423 break;
1424 case TKIND_ALIAS:
1425 AddToStrW(wszText, wszTKIND_ALIAS);
1426 CreateTypeInfo(wszText, wszAfter, pTypeAttr->tdescAlias, pTypeInfo);
1427 AddToStrW(wszText, wszSpace);
1428 AddToStrW(wszText, bstrName);
1429 AddToStrW(wszText, wszAfter);
1431 CreateTypedefHeader(pTypeInfo, pTypeAttr, tld);
1432 AddToTLDataStrW(tld, &wszText[lstrlenW(wszTKIND_ALIAS)]);
1433 AddToTLDataStrW(tld, wszSemicolon);
1434 AddToTLDataStrW(tld, wszNewLine);
1435 break;
1436 default:
1437 lstrcpyW(wszText, bstrName);
1438 WINE_FIXME("pTypeAttr->typekind == %d not supported\n",
1439 pTypeAttr->typekind);
1442 if(bInsert)
1444 hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1446 EnumVars(pTypeInfo, pTypeAttr->cVars, hParent);
1447 EnumFuncs(pTypeInfo, pTypeAttr, hParent);
1448 EnumImplTypes(pTypeInfo, pTypeAttr->cImplTypes, hParent);
1450 if(memcmp(bstrName, wszVT_UNKNOWN, sizeof(wszVT_UNKNOWN)))
1451 AddChildrenData(hParent, tld);
1452 AddToTLDataStrW(tld, tld->wszInsertAfter);
1455 ITypeInfo_ReleaseTypeAttr(pTypeInfo, pTypeAttr);
1456 ITypeInfo_Release(pTypeInfo);
1457 SysFreeString(bstrName);
1458 SysFreeString(bstrData);
1460 SendMessageW(typelib.hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)tvis.hParent);
1462 memset(&tvi, 0, sizeof(TVITEMW));
1463 tvi.mask = TVIF_PARAM;
1464 tvi.hItem = tvis.hParent;
1466 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
1467 AddPredefinitions(tvi.hItem, (TYPELIB_DATA*)(tvi.lParam));
1468 AddIdlData(tvi.hItem, (TYPELIB_DATA*)(tvi.lParam));
1469 AddToTLDataStrW((TYPELIB_DATA*)(tvi.lParam),
1470 ((TYPELIB_DATA*)(tvi.lParam))->wszInsertAfter);
1472 ITypeLib_Release(pTypeLib);
1473 return 0;
1476 void UpdateData(HTREEITEM item)
1478 TVITEMW tvi;
1480 memset(&tvi, 0, sizeof(TVITEMW));
1481 tvi.mask = TVIF_PARAM;
1482 tvi.hItem = item;
1484 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
1485 if(!tvi.lParam)
1487 SetWindowTextW(typelib.hEdit, wszSpace);
1488 return;
1491 SetWindowTextW(typelib.hEdit, ((TYPELIB_DATA*)tvi.lParam)->idl);
1494 static void TypeLibResizeChild(void)
1496 RECT client, stat;
1498 MoveWindow(typelib.hStatusBar, 0, 0, 0, 0, TRUE);
1500 if(IsWindowVisible(typelib.hStatusBar))
1501 GetClientRect(typelib.hStatusBar, &stat);
1502 else stat.bottom = 0;
1504 GetClientRect(globals.hTypeLibWnd, &client);
1505 MoveWindow(typelib.hPaneWnd, 0, 0,
1506 client.right, client.bottom-stat.bottom, TRUE);
1509 static void TypeLibMenuCommand(WPARAM wParam, HWND hWnd)
1511 BOOL vis;
1513 switch(wParam)
1515 case IDM_SAVEAS:
1516 GetSaveIdlAsPath();
1517 break;
1518 case IDM_STATUSBAR:
1519 vis = IsWindowVisible(typelib.hStatusBar);
1520 ShowWindow(typelib.hStatusBar, vis ? SW_HIDE : SW_SHOW);
1521 CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
1522 vis ? MF_UNCHECKED : MF_CHECKED);
1523 TypeLibResizeChild();
1524 break;
1525 case IDM_CLOSE:
1526 DestroyWindow(hWnd);
1527 break;
1531 static void UpdateTypeLibStatusBar(int itemID)
1533 WCHAR info[MAX_LOAD_STRING];
1535 if(!LoadStringW(globals.hMainInst, itemID, info, ARRAY_SIZE(info)))
1536 LoadStringW(globals.hMainInst, IDS_READY, info, ARRAY_SIZE(info));
1538 SendMessageW(typelib.hStatusBar, SB_SETTEXTW, 0, (LPARAM)info);
1541 static void EmptyTLTree(void)
1543 HTREEITEM cur, del;
1544 TVITEMW tvi;
1546 tvi.mask = TVIF_PARAM;
1547 cur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
1548 TVGN_CHILD, (LPARAM)TVI_ROOT);
1550 while(TRUE)
1552 del = cur;
1553 cur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
1554 TVGN_CHILD, (LPARAM)del);
1556 if(!cur) cur = (HTREEITEM)SendMessageW(typelib.hTree,
1557 TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)del);
1558 if(!cur) cur = (HTREEITEM)SendMessageW(typelib.hTree,
1559 TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)del);
1561 tvi.hItem = del;
1562 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
1563 if(tvi.lParam)
1565 HeapFree(GetProcessHeap(), 0, ((TYPELIB_DATA *)tvi.lParam)->idl);
1566 HeapFree(GetProcessHeap(), 0, (TYPELIB_DATA *)tvi.lParam);
1569 SendMessageW(typelib.hTree, TVM_DELETEITEM, 0, (LPARAM)del);
1571 if(!cur) break;
1575 static LRESULT CALLBACK TypeLibProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1577 switch(uMsg)
1579 case WM_CREATE:
1581 if(!CreatePanedWindow(hWnd, &typelib.hPaneWnd, globals.hMainInst))
1582 DestroyWindow(hWnd);
1583 typelib.hTree = CreateWindowExW(WS_EX_CLIENTEDGE, WC_TREEVIEWW, NULL,
1584 WS_CHILD|WS_VISIBLE|TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT,
1585 0, 0, 0, 0, typelib.hPaneWnd, (HMENU)TYPELIB_TREE,
1586 globals.hMainInst, NULL);
1587 typelib.hEdit = CreateWindowExW(WS_EX_CLIENTEDGE, WC_EDITW, NULL,
1588 WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_READONLY|WS_HSCROLL|WS_VSCROLL,
1589 0, 0, 0, 0, typelib.hPaneWnd, NULL, globals.hMainInst, NULL);
1591 SetLeft(typelib.hPaneWnd, typelib.hTree);
1592 SetRight(typelib.hPaneWnd, typelib.hEdit);
1594 if(PopulateTree()) DestroyWindow(hWnd);
1595 else SetFocus(typelib.hTree);
1596 break;
1598 case WM_COMMAND:
1599 TypeLibMenuCommand(LOWORD(wParam), hWnd);
1600 break;
1601 case WM_MENUSELECT:
1602 UpdateTypeLibStatusBar(LOWORD(wParam));
1603 break;
1604 case WM_SETFOCUS:
1605 SetFocus(typelib.hTree);
1606 break;
1607 case WM_SIZE:
1608 if(wParam == SIZE_MINIMIZED) break;
1609 TypeLibResizeChild();
1610 break;
1611 case WM_DESTROY:
1612 EmptyTLTree();
1613 break;
1614 default:
1615 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
1617 return 0;
1620 BOOL TypeLibRegisterClassW(void)
1622 WNDCLASSW wcc;
1624 memset(&wcc, 0, sizeof(WNDCLASSW));
1625 wcc.lpfnWndProc = TypeLibProc;
1626 wcc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
1627 wcc.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
1628 wcc.lpszMenuName = MAKEINTRESOURCEW(IDM_TYPELIB);
1629 wcc.lpszClassName = wszTypeLib;
1631 if(!RegisterClassW(&wcc))
1632 return FALSE;
1634 return TRUE;
1637 BOOL CreateTypeLibWindow(HINSTANCE hInst, WCHAR *wszFileName)
1639 WCHAR wszTitle[MAX_LOAD_STRING];
1640 LoadStringW(hInst, IDS_TYPELIBTITLE, wszTitle, ARRAY_SIZE(wszTitle));
1642 if(wszFileName) lstrcpyW(typelib.wszFileName, wszFileName);
1643 else
1645 TVITEMW tvi;
1647 memset(&tvi, 0, sizeof(TVITEMW));
1648 tvi.hItem = (HTREEITEM)SendMessageW(globals.hTree, TVM_GETNEXTITEM,
1649 TVGN_CARET, 0);
1651 SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
1652 lstrcpyW(typelib.wszFileName, ((ITEM_INFO*)tvi.lParam)->path);
1655 globals.hTypeLibWnd = CreateWindowW(wszTypeLib, wszTitle,
1656 WS_OVERLAPPEDWINDOW|WS_VISIBLE,
1657 CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInst, NULL);
1658 if(!globals.hTypeLibWnd) return FALSE;
1660 typelib.hStatusBar = CreateStatusWindowW(WS_VISIBLE|WS_CHILD,
1661 wszTitle, globals.hTypeLibWnd, 0);
1663 TypeLibResizeChild();
1664 return TRUE;