mshtml: Removed no longer used attr_name from event_info_t.
[wine.git] / programs / oleview / typelib.c
blobcbf6ab1f6d0da12736d77146181ff2713ada2182
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"
24 #include "wine/unicode.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(oleview);
28 TYPELIB typelib;
29 static const WCHAR wszTypeLib[] = { 'T','Y','P','E','L','I','B','\0' };
31 static const WCHAR wszFailed[] = { '<','f','a','i','l','e','d','>','\0' };
32 static const WCHAR wszSpace[] = { ' ','\0' };
33 static const WCHAR wszAsterix[] = { '*','\0' };
34 static const WCHAR wszComa[] = { ',','\0' };
35 static const WCHAR wszEquals[] = { '=','\0' };
36 static const WCHAR wszSemicolon[] = { ';','\0' };
37 static const WCHAR wszNewLine[] = { '\n','\0' };
38 static const WCHAR wszOpenBrackets1[] = { '[','\0' };
39 static const WCHAR wszCloseBrackets1[] = { ']','\0' };
40 static const WCHAR wszOpenBrackets2[] = { '(','\0' };
41 static const WCHAR wszCloseBrackets2[] = { ')','\0' };
42 static const WCHAR wszOpenBrackets3[] = { '{','\0' };
43 static const WCHAR wszCloseBrackets3[] = { '}','\0' };
44 static const WCHAR wszInvertedComa[] = { '"','\0' };
45 static const WCHAR wszColon[] = { ':','\0' };
47 static const WCHAR wszUUID[] = { 'u','u','i','d','\0' };
48 static const WCHAR wszOdl[] = { 'o','d','l','\0' };
50 static const WCHAR wszVT_BOOL[]
51 = { 'V','A','R','I','A','N','T','_','B','O','O','L','\0' };
52 static const WCHAR wszVT_UI1[]
53 = { 'u','n','s','i','g','n','e','d',' ','c','h','a','r','\0' };
54 static const WCHAR wszVT_UI2[]
55 = { 'u','n','s','i','g','n','e','d',' ','s','h','o','r','t','\0' };
56 static const WCHAR wszVT_UI4[]
57 = { 'u','n','s','i','g','n','e','d',' ','l','o','n','g','\0' };
58 static const WCHAR wszVT_UI8[] = { 'u','i','n','t','6','4','\0' };
59 static const WCHAR wszVT_UINT[]
60 = { 'u','n','s','i','g','n','e','d',' ','i','n','t','\0' };
61 static const WCHAR wszVT_I1[] = { 'c','h','a','r','\0' };
62 static const WCHAR wszVT_I2[] = { 's','h','o','r','t','\0' };
63 static const WCHAR wszVT_I4[] = { 'l','o','n','g','\0' };
64 static const WCHAR wszVT_I8[] = { 'i','n','t','6','4','\0' };
65 static const WCHAR wszVT_R4[] = { 's','i','n','g','l','e','\0' };
66 static const WCHAR wszVT_INT[] = { 'i','n','t','\0' };
67 static const WCHAR wszVT_BSTR[] = { 'B','S','T','R','\0' };
68 static const WCHAR wszVT_CY[] = { 'C','U','R','R','E','N','C','Y','\0' };
69 static const WCHAR wszVT_VARIANT[] = { 'V','A','R','I','A','N','T','\0' };
70 static const WCHAR wszVT_VOID[] = { 'v','o','i','d','\0' };
71 static const WCHAR wszVT_ERROR[] = { 'S','C','O','D','E','\0' };
72 static const WCHAR wszVT_LPSTR[] = { 'L','P','S','T','R','\0' };
73 static const WCHAR wszVT_LPWSTR[] = { 'L','P','W','S','T','R','\0' };
74 static const WCHAR wszVT_HRESULT[] = { 'H','R','E','S','U','L','T','\0' };
75 static const WCHAR wszVT_UNKNOWN[] = { 'I','U','n','k','n','o','w','n','\0' };
76 static const WCHAR wszVT_DISPATCH[] = { 'I','D','i','s','p','a','t','c','h','\0' };
77 static const WCHAR wszVT_DATE[] = { 'D','A','T','E','\0' };
78 static const WCHAR wszVT_R8[] = { 'd','o','u','b','l','e','\0' };
79 static const WCHAR wszVT_SAFEARRAY[] = { 'S','A','F','E','A','R','R','A','Y','\0' };
81 static const WCHAR wszFormat[] = { '0','x','%','.','8','l','x','\0' };
82 static const WCHAR wszStdCall[] = { '_','s','t','d','c','a','l','l','\0' };
83 static const WCHAR wszId[] = { 'i','d','\0' };
84 static const WCHAR wszHelpstring[] = { 'h','e','l','p','s','t','r','i','n','g','\0' };
85 static const WCHAR wszPropPut[] = { 'p','r','o','p','p','u','t','\0' };
86 static const WCHAR wszPropGet[] = { 'p','r','o','p','g','e','t','\0' };
87 static const WCHAR wszPropPutRef[] = { 'p','r','o','p','p','u','t','r','e','f','\0' };
88 static const WCHAR wszPARAMFLAG_FIN[] = { 'i','n','\0' };
89 static const WCHAR wszPARAMFLAG_FOUT[] = { 'o','u','t','\0' };
90 static const WCHAR wszPARAMFLAG_FLCID[] = { 'c','i','d','\0' };
91 static const WCHAR wszPARAMFLAG_FRETVAL[] = { 'r','e','t','v','a','l','\0' };
92 static const WCHAR wszPARAMFLAG_FOPT[] = { 'o','p','t','i','o','n','a','l','\0' };
93 static const WCHAR wszPARAMFLAG_FHASCUSTDATA[]
94 = { 'h','a','s','c','u','s','t','d','a','t','a','\0' };
95 static const WCHAR wszDefaultValue[]
96 = { 'd','e','f','a','u','l','t','v','a','l','u','e','\0' };
98 static const WCHAR wszReadOnly[] = { 'r','e','a','d','o','n','l','y','\0' };
99 static const WCHAR wszConst[] = { 'c','o','n','s','t','\0' };
101 static void ShowLastError(void)
103 DWORD error = GetLastError();
104 LPWSTR lpMsgBuf;
105 WCHAR wszTitle[MAX_LOAD_STRING];
107 LoadStringW(globals.hMainInst, IDS_TYPELIBTITLE, wszTitle,
108 sizeof(wszTitle)/sizeof(wszTitle[0]));
109 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
110 NULL, error, 0, (LPWSTR)&lpMsgBuf, 0, NULL);
111 MessageBoxW(NULL, lpMsgBuf, wszTitle, MB_OK | MB_ICONERROR);
112 LocalFree(lpMsgBuf);
113 return;
116 static void SaveIdl(WCHAR *wszFileName)
118 HTREEITEM hIDL;
119 TVITEMW tvi;
120 HANDLE hFile;
121 DWORD len, dwNumWrite;
122 char *wszIdl;
123 TYPELIB_DATA *data;
125 hIDL = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
126 TVGN_CHILD, (LPARAM)TVI_ROOT);
128 memset(&tvi, 0, sizeof(TVITEMW));
129 tvi.hItem = hIDL;
131 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
132 data = (TYPELIB_DATA *)tvi.lParam;
134 hFile = CreateFileW(wszFileName, GENERIC_WRITE, FILE_SHARE_WRITE,
135 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
136 if(hFile == INVALID_HANDLE_VALUE)
138 ShowLastError();
139 return;
142 len = WideCharToMultiByte( CP_UTF8, 0, data->idl, data->idlLen, NULL, 0, NULL, NULL );
143 wszIdl = HeapAlloc(GetProcessHeap(), 0, len);
144 WideCharToMultiByte( CP_UTF8, 0, data->idl, data->idlLen, wszIdl, len, NULL, NULL );
146 if(!WriteFile(hFile, wszIdl, len, &dwNumWrite, NULL))
147 ShowLastError();
149 HeapFree(GetProcessHeap(), 0, wszIdl);
150 CloseHandle(hFile);
153 static void GetSaveIdlAsPath(void)
155 OPENFILENAMEW saveidl;
156 WCHAR *pFileName;
157 WCHAR wszPath[MAX_LOAD_STRING];
158 WCHAR wszDir[MAX_LOAD_STRING];
159 static const WCHAR wszDefaultExt[] = { 'i','d','l',0 };
160 static const WCHAR wszIdlFiles[] = { '*','.','i','d','l','\0','\0' };
162 memset(&saveidl, 0, sizeof(saveidl));
164 lstrcpyW(wszDir, typelib.wszFileName);
165 pFileName = wszDir + lstrlenW(wszDir);
166 while(*pFileName != '.' && *pFileName != '\\' && *pFileName != '/'
167 && pFileName > wszDir) pFileName -= 1;
168 if(*pFileName == '.')
170 *pFileName = '\0';
171 while(*pFileName != '\\' && *pFileName != '/' && pFileName > wszDir)
172 pFileName -= 1;
174 if(*pFileName == '\\' || *pFileName == '/') pFileName += 1;
175 lstrcpyW(wszPath, pFileName);
177 GetCurrentDirectoryW(MAX_LOAD_STRING, wszDir);
179 saveidl.lStructSize = sizeof(OPENFILENAMEW);
180 saveidl.hwndOwner = globals.hTypeLibWnd;
181 saveidl.hInstance = globals.hMainInst;
182 saveidl.lpstrFilter = wszIdlFiles;
183 saveidl.lpstrFile = wszPath;
184 saveidl.nMaxFile = MAX_LOAD_STRING;
185 saveidl.lpstrInitialDir = wszDir;
186 saveidl.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
187 saveidl.lpstrDefExt = wszDefaultExt;
189 if (GetSaveFileNameW(&saveidl))
190 SaveIdl(wszPath);
193 static void AddToStrW(WCHAR *wszDest, const WCHAR *wszSource)
195 lstrcpyW(&wszDest[lstrlenW(wszDest)], wszSource);
198 static void AddToTLDataStrW(TYPELIB_DATA *pTLData, const WCHAR *wszSource)
200 int SourceLen = lstrlenW(wszSource);
202 pTLData->idl = HeapReAlloc(GetProcessHeap(), 0, pTLData->idl,
203 sizeof(WCHAR)*(pTLData->idlLen+SourceLen+1));
205 memcpy(&pTLData->idl[pTLData->idlLen], wszSource, sizeof(WCHAR)*(SourceLen+1));
206 pTLData->idlLen += SourceLen;
209 static void AddToTLDataStrWithTabsW(TYPELIB_DATA *pTLData, WCHAR *wszSource)
211 int lineLen = lstrlenW(wszSource);
212 int newLinesNo = 0;
213 WCHAR *pSourcePos = wszSource;
214 WCHAR *pSourceBeg;
216 if(!lineLen) return;
217 while(*pSourcePos)
219 if(*pSourcePos == *wszNewLine) newLinesNo++;
220 pSourcePos += 1;
222 if(*(pSourcePos - 1) != *wszNewLine) newLinesNo++;
224 pTLData->idl = HeapReAlloc(GetProcessHeap(), 0, pTLData->idl,
225 sizeof(WCHAR)*(pTLData->idlLen+lineLen+4*newLinesNo+1));
227 pSourcePos = wszSource;
228 pSourceBeg = wszSource;
229 while(newLinesNo)
231 if(*pSourcePos != *wszNewLine && *pSourcePos)
233 pSourcePos += 1;
234 continue;
236 newLinesNo--;
238 if(*pSourcePos)
240 *pSourcePos = '\0';
241 lineLen = lstrlenW(pSourceBeg)+1;
242 *pSourcePos = '\n';
243 pSourcePos += 1;
245 else lineLen = lstrlenW(pSourceBeg);
247 pTLData->idl[pTLData->idlLen] = *wszSpace;
248 pTLData->idl[pTLData->idlLen+1] = *wszSpace;
249 pTLData->idl[pTLData->idlLen+2] = *wszSpace;
250 pTLData->idl[pTLData->idlLen+3] = *wszSpace;
251 memcpy(&pTLData->idl[pTLData->idlLen+4], pSourceBeg, sizeof(WCHAR)*lineLen);
252 pTLData->idlLen += lineLen + 4;
253 pTLData->idl[pTLData->idlLen] = '\0';
255 pSourceBeg = pSourcePos;
259 static TYPELIB_DATA *InitializeTLData(void)
261 TYPELIB_DATA *pTLData;
263 pTLData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TYPELIB_DATA));
265 pTLData->idl = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR));
266 pTLData->idl[0] = '\0';
268 return pTLData;
271 static void AddSpaces(TYPELIB_DATA *pTLData, int tabSize)
273 for(; tabSize>0; tabSize--)
274 AddToTLDataStrW(pTLData, wszSpace);
277 static void AddChildrenData(HTREEITEM hParent, TYPELIB_DATA *pData)
279 HTREEITEM hCur;
280 TVITEMW tvi;
282 memset(&tvi, 0, sizeof(tvi));
284 hCur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
285 TVGN_CHILD, (LPARAM)hParent);
286 if(!hCur) return;
290 tvi.hItem = hCur;
291 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
292 if(tvi.lParam && ((TYPELIB_DATA *)(tvi.lParam))->idlLen)
293 AddToTLDataStrWithTabsW(pData, ((TYPELIB_DATA *)(tvi.lParam))->idl);
294 } while((hCur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
295 TVGN_NEXT, (LPARAM)hCur)));
298 static void CreateTypeInfo(WCHAR *wszAddTo, WCHAR *wszAddAfter, TYPEDESC tdesc, ITypeInfo *pTypeInfo)
300 int i;
301 BSTR bstrData;
302 HRESULT hRes;
303 ITypeInfo *pRefTypeInfo;
304 WCHAR wszBuf[MAX_LOAD_STRING];
305 WCHAR wszFormat[] = { '[','%','l','u',']','\0' };
307 switch(tdesc.vt&VT_TYPEMASK)
309 #define VTADDTOSTR(x) case x:\
310 AddToStrW(wszAddTo, wsz##x);\
311 break
312 VTADDTOSTR(VT_BOOL);
313 VTADDTOSTR(VT_UI1);
314 VTADDTOSTR(VT_UI2);
315 VTADDTOSTR(VT_UI4);
316 VTADDTOSTR(VT_UI8);
317 VTADDTOSTR(VT_UINT);
318 VTADDTOSTR(VT_I1);
319 VTADDTOSTR(VT_I2);
320 VTADDTOSTR(VT_I4);
321 VTADDTOSTR(VT_I8);
322 VTADDTOSTR(VT_R4);
323 VTADDTOSTR(VT_INT);
324 VTADDTOSTR(VT_BSTR);
325 VTADDTOSTR(VT_CY);
326 VTADDTOSTR(VT_VARIANT);
327 VTADDTOSTR(VT_VOID);
328 VTADDTOSTR(VT_ERROR);
329 VTADDTOSTR(VT_LPSTR);
330 VTADDTOSTR(VT_LPWSTR);
331 VTADDTOSTR(VT_HRESULT);
332 VTADDTOSTR(VT_UNKNOWN);
333 VTADDTOSTR(VT_DISPATCH);
334 VTADDTOSTR(VT_DATE);
335 VTADDTOSTR(VT_R8);
336 case VT_CARRAY:
337 for(i=0; i<U(tdesc).lpadesc->cDims; i++)
339 wsprintfW(wszBuf, wszFormat, U(tdesc).lpadesc->rgbounds[i].cElements);
340 AddToStrW(wszAddAfter, wszBuf);
342 CreateTypeInfo(wszAddTo, wszAddAfter, U(tdesc).lpadesc->tdescElem, pTypeInfo);
343 break;
344 case VT_SAFEARRAY:
345 AddToStrW(wszAddTo, wszVT_SAFEARRAY);
346 AddToStrW(wszAddTo, wszOpenBrackets2);
347 CreateTypeInfo(wszAddTo, wszAddAfter, *U(tdesc).lptdesc, pTypeInfo);
348 AddToStrW(wszAddTo, wszCloseBrackets2);
349 break;
350 case VT_PTR:
351 CreateTypeInfo(wszAddTo, wszAddAfter, *U(tdesc).lptdesc, pTypeInfo);
352 AddToStrW(wszAddTo, wszAsterix);
353 break;
354 case VT_USERDEFINED:
355 hRes = ITypeInfo_GetRefTypeInfo(pTypeInfo,
356 U(tdesc).hreftype, &pRefTypeInfo);
357 if(SUCCEEDED(hRes))
359 ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL,
360 &bstrData, NULL, NULL, NULL);
361 AddToStrW(wszAddTo, bstrData);
362 SysFreeString(bstrData);
363 ITypeInfo_Release(pRefTypeInfo);
365 else AddToStrW(wszAddTo, wszFailed);
366 break;
367 default:
368 WINE_FIXME("tdesc.vt&VT_TYPEMASK == %d not supported\n",
369 tdesc.vt&VT_TYPEMASK);
373 static int EnumVars(ITypeInfo *pTypeInfo, int cVars, HTREEITEM hParent)
375 int i;
376 TVINSERTSTRUCTW tvis;
377 VARDESC *pVarDesc;
378 BSTR bstrName;
379 WCHAR wszText[MAX_LOAD_STRING];
380 WCHAR wszAfter[MAX_LOAD_STRING];
382 U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM;
383 U(tvis).item.cchTextMax = MAX_LOAD_STRING;
384 U(tvis).item.pszText = wszText;
385 tvis.hInsertAfter = TVI_LAST;
386 tvis.hParent = hParent;
388 for(i=0; i<cVars; i++)
390 TYPELIB_DATA *tld;
392 if(FAILED(ITypeInfo_GetVarDesc(pTypeInfo, i, &pVarDesc))) continue;
393 if(FAILED(ITypeInfo_GetDocumentation(pTypeInfo, pVarDesc->memid, &bstrName,
394 NULL, NULL, NULL))) continue;
396 tld = InitializeTLData();
397 U(tvis).item.lParam = (LPARAM) tld;
398 if(pVarDesc->memid < MIN_VAR_ID)
401 AddToTLDataStrW(tld, wszOpenBrackets1);
402 AddToTLDataStrW(tld, wszId);
403 AddToTLDataStrW(tld, wszOpenBrackets2);
404 wsprintfW(wszText, wszFormat, pVarDesc->memid);
405 AddToTLDataStrW(tld, wszText);
406 memset(wszText, 0, sizeof(wszText));
407 AddToTLDataStrW(tld, wszCloseBrackets2);
409 if(pVarDesc->wVarFlags & VARFLAG_FREADONLY)
411 AddToTLDataStrW(tld, wszComa);
412 AddToTLDataStrW(tld, wszSpace);
413 AddToTLDataStrW(tld, wszReadOnly);
415 AddToTLDataStrW(tld, wszCloseBrackets1);
416 AddToTLDataStrW(tld, wszNewLine);
419 memset(wszText, 0, sizeof(wszText));
420 memset(wszAfter, 0, sizeof(wszAfter));
421 CreateTypeInfo(wszText, wszAfter, pVarDesc->elemdescVar.tdesc, pTypeInfo);
422 AddToStrW(wszText, wszSpace);
423 if (bstrName) AddToStrW(wszText, bstrName);
424 AddToStrW(wszText, wszAfter);
425 AddToTLDataStrW(tld, wszText);
426 AddToTLDataStrW(tld, wszSemicolon);
427 AddToTLDataStrW(tld, wszNewLine);
429 SendMessageW(typelib.hTree, TVM_INSERTITEMW, 0, (LPARAM)&tvis);
430 SysFreeString(bstrName);
431 ITypeInfo_ReleaseVarDesc(pTypeInfo, pVarDesc);
434 return 0;
437 static int EnumEnums(ITypeInfo *pTypeInfo, int cVars, HTREEITEM hParent)
439 int i;
440 TVINSERTSTRUCTW tvis;
441 VARDESC *pVarDesc;
442 BSTR bstrName;
443 WCHAR wszText[MAX_LOAD_STRING];
444 WCHAR wszAfter[MAX_LOAD_STRING];
446 U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM;
447 U(tvis).item.cchTextMax = MAX_LOAD_STRING;
448 U(tvis).item.pszText = wszText;
449 tvis.hInsertAfter = TVI_LAST;
450 tvis.hParent = hParent;
452 for(i=0; i<cVars; i++)
454 TYPELIB_DATA *tld;
456 if(FAILED(ITypeInfo_GetVarDesc(pTypeInfo, i, &pVarDesc))) continue;
457 if(FAILED(ITypeInfo_GetDocumentation(pTypeInfo, pVarDesc->memid, &bstrName,
458 NULL, NULL, NULL))) continue;
460 tld = InitializeTLData();
461 U(tvis).item.lParam = (LPARAM) tld;
463 memset(wszText, 0, sizeof(wszText));
464 memset(wszAfter, 0, sizeof(wszAfter));
466 if (pVarDesc->varkind == VAR_CONST)
468 VARIANT var;
469 VariantInit(&var);
470 if (VariantChangeType(&var, U(*pVarDesc).lpvarValue, 0, VT_BSTR) == S_OK)
472 AddToStrW(wszText, wszConst);
473 AddToStrW(wszText, wszSpace);
474 AddToStrW(wszAfter, wszSpace);
475 AddToStrW(wszAfter, wszEquals);
476 AddToStrW(wszAfter, wszSpace);
477 AddToStrW(wszAfter, V_BSTR(&var));
481 CreateTypeInfo(wszText, wszAfter, pVarDesc->elemdescVar.tdesc, pTypeInfo);
482 AddToStrW(wszText, wszSpace);
483 AddToStrW(wszText, bstrName);
484 AddToStrW(wszText, wszAfter);
485 AddToTLDataStrW(tld, bstrName);
486 AddToTLDataStrW(tld, wszAfter);
487 if (i<cVars-1)
488 AddToTLDataStrW(tld, wszComa);
489 AddToTLDataStrW(tld, wszNewLine);
491 SendMessageW(typelib.hTree, TVM_INSERTITEMW, 0, (LPARAM)&tvis);
492 SysFreeString(bstrName);
493 ITypeInfo_ReleaseVarDesc(pTypeInfo, pVarDesc);
496 return 0;
499 static int EnumFuncs(ITypeInfo *pTypeInfo, TYPEATTR *pTypeAttr, HTREEITEM hParent)
501 int i, j;
502 int cFuncs;
503 unsigned namesNo;
504 TVINSERTSTRUCTW tvis;
505 FUNCDESC *pFuncDesc;
506 BSTR bstrName, bstrHelpString, *bstrParamNames;
507 WCHAR wszText[MAX_LOAD_STRING];
508 WCHAR wszAfter[MAX_LOAD_STRING];
509 WCHAR szRhs[] = {'r','h','s',0}; /* Right-hand side of a propput */
510 BOOL bFirst;
512 U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM;
513 tvis.hInsertAfter = TVI_LAST;
514 tvis.hParent = hParent;
516 cFuncs = pTypeAttr->cFuncs;
518 i = 0;
519 if(pTypeAttr->wTypeFlags & TYPEFLAG_FDUAL) { /* skip 7 members of IDispatch */
520 cFuncs += 7;
521 i += 7;
524 for(; i<cFuncs; i++)
526 TYPELIB_DATA *tld;
528 if(FAILED(ITypeInfo_GetFuncDesc(pTypeInfo, i, &pFuncDesc))) continue;
530 if(FAILED(ITypeInfo_GetDocumentation(pTypeInfo, pFuncDesc->memid, &bstrName,
531 &bstrHelpString, NULL, NULL))) continue;
533 memset(wszText, 0, sizeof(wszText));
534 memset(wszAfter, 0, sizeof(wszAfter));
535 tld = InitializeTLData();
536 U(tvis).item.cchTextMax = SysStringLen(bstrName);
537 U(tvis).item.pszText = bstrName;
538 U(tvis).item.lParam = (LPARAM) tld;
539 bFirst = TRUE;
540 if(pFuncDesc->memid < MIN_FUNC_ID || pTypeAttr->wTypeFlags & TYPEFLAG_FDUAL)
542 AddToTLDataStrW(tld, wszOpenBrackets1);
543 bFirst = FALSE;
544 AddToTLDataStrW(tld, wszId);
545 AddToTLDataStrW(tld, wszOpenBrackets2);
546 wsprintfW(wszText, wszFormat, pFuncDesc->memid);
547 AddToTLDataStrW(tld, wszText);
548 AddToTLDataStrW(tld, wszCloseBrackets2);
549 memset(wszText, 0, sizeof(wszText));
552 CreateTypeInfo(wszText, wszAfter, pFuncDesc->elemdescFunc.tdesc, pTypeInfo);
553 switch(pFuncDesc->invkind)
555 case INVOKE_PROPERTYGET:
556 if(bFirst) AddToTLDataStrW(tld, wszOpenBrackets1);
557 else
559 AddToTLDataStrW(tld, wszComa);
560 AddToTLDataStrW(tld, wszSpace);
562 bFirst = FALSE;
563 AddToTLDataStrW(tld, wszPropGet);
564 break;
565 case INVOKE_PROPERTYPUT:
566 if(bFirst) AddToTLDataStrW(tld, wszOpenBrackets1);
567 else
569 AddToTLDataStrW(tld, wszComa);
570 AddToTLDataStrW(tld, wszSpace);
572 bFirst = FALSE;
573 AddToTLDataStrW(tld, wszPropPut);
574 break;
575 case INVOKE_PROPERTYPUTREF:
576 if(bFirst) AddToTLDataStrW(tld, wszOpenBrackets1);
577 else
579 AddToTLDataStrW(tld, wszComa);
580 AddToTLDataStrW(tld, wszSpace);
582 bFirst = FALSE;
583 AddToTLDataStrW(tld, wszPropPutRef);
584 break;
585 default:;
587 if(SysStringLen(bstrHelpString))
589 if(bFirst) AddToTLDataStrW(tld, wszOpenBrackets1);
590 else
592 AddToTLDataStrW(tld, wszComa);
593 AddToTLDataStrW(tld, wszSpace);
595 bFirst = FALSE;
596 AddToTLDataStrW(tld, wszHelpstring);
597 AddToTLDataStrW(tld, wszOpenBrackets2);
598 AddToTLDataStrW(tld, wszInvertedComa);
599 AddToTLDataStrW(tld, bstrHelpString);
600 AddToTLDataStrW(tld, wszInvertedComa);
601 AddToTLDataStrW(tld, wszCloseBrackets2);
603 if(!bFirst)
605 AddToTLDataStrW(tld, wszCloseBrackets1);
606 AddToTLDataStrW(tld, wszNewLine);
609 if(pTypeAttr->wTypeFlags & TYPEFLAG_FOLEAUTOMATION) {
610 AddToTLDataStrW(tld, wszVT_HRESULT);
611 if(strcmpW(wszText, wszVT_VOID)) pFuncDesc->cParams++;
613 else {
614 AddToTLDataStrW(tld, wszText);
615 AddToTLDataStrW(tld, wszAfter);
618 bstrParamNames = HeapAlloc(GetProcessHeap(), 0,
619 sizeof(BSTR)*(pFuncDesc->cParams+1));
620 if(FAILED(ITypeInfo_GetNames(pTypeInfo, pFuncDesc->memid, bstrParamNames,
621 pFuncDesc->cParams+1, &namesNo)))
623 HeapFree(GetProcessHeap(), 0, bstrParamNames);
624 continue;
626 SysFreeString(bstrParamNames[0]);
628 AddToTLDataStrW(tld, wszSpace);
629 if(pFuncDesc->memid >= MIN_FUNC_ID)
631 AddToTLDataStrW(tld, wszStdCall);
632 AddToTLDataStrW(tld, wszSpace);
634 if (bstrName) AddToTLDataStrW(tld, bstrName);
635 AddToTLDataStrW(tld, wszOpenBrackets2);
637 for(j=0; j<pFuncDesc->cParams; j++)
639 if(j != 0) AddToTLDataStrW(tld, wszComa);
640 if(pFuncDesc->cParams != 1)
642 AddToTLDataStrW(tld, wszNewLine);
643 AddSpaces(tld, TAB_SIZE);
645 bFirst = TRUE;
646 #define ENUM_PARAM_FLAG(x)\
647 if(U(pFuncDesc->lprgelemdescParam[j]).paramdesc.wParamFlags & x) \
649 if(bFirst) AddToTLDataStrW(tld,\
650 wszOpenBrackets1);\
651 else\
653 AddToTLDataStrW(tld, wszComa);\
654 AddToTLDataStrW(tld, wszSpace);\
656 bFirst = FALSE;\
657 AddToTLDataStrW(tld, wsz##x);\
659 ENUM_PARAM_FLAG(PARAMFLAG_FIN);
660 ENUM_PARAM_FLAG(PARAMFLAG_FOUT);
661 ENUM_PARAM_FLAG(PARAMFLAG_FLCID);
662 ENUM_PARAM_FLAG(PARAMFLAG_FRETVAL);
663 ENUM_PARAM_FLAG(PARAMFLAG_FOPT);
664 ENUM_PARAM_FLAG(PARAMFLAG_FHASCUSTDATA);
666 if(U(pFuncDesc->lprgelemdescParam[j]).paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT)
668 VARIANT var, *param=&U(pFuncDesc->lprgelemdescParam[j]).paramdesc.pparamdescex->varDefaultValue;
669 VariantInit(&var);
670 if(bFirst) AddToTLDataStrW(tld,
671 wszOpenBrackets1);
672 else
674 AddToTLDataStrW(tld, wszComa);
675 AddToTLDataStrW(tld, wszSpace);
677 bFirst = FALSE;
678 AddToTLDataStrW(tld, wszDefaultValue);
679 AddToTLDataStrW(tld, wszOpenBrackets2);
680 if (V_VT(param) == VT_BSTR)
682 AddToTLDataStrW(tld, wszInvertedComa);
683 AddToTLDataStrW(tld, V_BSTR(param));
684 AddToTLDataStrW(tld, wszInvertedComa);
685 } else if (VariantChangeType(&var, param, 0, VT_BSTR) == S_OK)
686 AddToTLDataStrW(tld, V_BSTR(&var));
687 AddToTLDataStrW(tld, wszCloseBrackets2);
690 if(!bFirst)
692 AddToTLDataStrW(tld, wszCloseBrackets1);
693 AddToTLDataStrW(tld, wszSpace);
696 memset(wszText, 0, sizeof(wszText));
697 memset(wszAfter, 0, sizeof(wszAfter));
698 CreateTypeInfo(wszText, wszAfter, pFuncDesc->lprgelemdescParam[j].tdesc,
699 pTypeInfo);
700 AddToTLDataStrW(tld, wszText);
701 AddToTLDataStrW(tld, wszAfter);
702 AddToTLDataStrW(tld, wszSpace);
703 if (j+1 < namesNo) {
704 if (bstrParamNames[j+1])
706 AddToTLDataStrW(tld, bstrParamNames[j+1]);
707 SysFreeString(bstrParamNames[j+1]);
709 } else {
710 AddToTLDataStrW(tld, szRhs);
713 AddToTLDataStrW(tld, wszCloseBrackets2);
714 AddToTLDataStrW(tld, wszSemicolon);
715 AddToTLDataStrW(tld, wszNewLine);
717 SendMessageW(typelib.hTree, TVM_INSERTITEMW, 0, (LPARAM)&tvis);
718 HeapFree(GetProcessHeap(), 0, bstrParamNames);
719 SysFreeString(bstrName);
720 SysFreeString(bstrHelpString);
721 ITypeInfo_ReleaseFuncDesc(pTypeInfo, pFuncDesc);
724 return 0;
727 static int EnumImplTypes(ITypeInfo *pTypeInfo, int cImplTypes, HTREEITEM hParent)
729 int i;
730 TVINSERTSTRUCTW tvis;
731 ITypeInfo *pRefTypeInfo;
732 HREFTYPE hRefType;
733 TYPEATTR *pTypeAttr;
734 BSTR bstrName;
735 WCHAR wszInheritedInterfaces[MAX_LOAD_STRING];
737 if(!cImplTypes) return 0;
739 LoadStringW(globals.hMainInst, IDS_INHERITINTERFACES, wszInheritedInterfaces,
740 sizeof(wszInheritedInterfaces)/sizeof(wszInheritedInterfaces[0]));
742 U(tvis).item.mask = TVIF_TEXT;
743 U(tvis).item.cchTextMax = MAX_LOAD_STRING;
744 U(tvis).item.pszText = wszInheritedInterfaces;
745 tvis.hInsertAfter = TVI_LAST;
746 tvis.hParent = hParent;
748 tvis.hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
750 for(i=0; i<cImplTypes; i++)
752 if(FAILED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo, i, &hRefType))) continue;
753 if(FAILED(ITypeInfo_GetRefTypeInfo(pTypeInfo, hRefType, &pRefTypeInfo)))
754 continue;
755 if(FAILED(ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL, &bstrName,
756 NULL, NULL, NULL)))
758 ITypeInfo_Release(pRefTypeInfo);
759 continue;
761 if(FAILED(ITypeInfo_GetTypeAttr(pRefTypeInfo, &pTypeAttr)))
763 ITypeInfo_Release(pRefTypeInfo);
764 continue;
767 U(tvis).item.cchTextMax = SysStringLen(bstrName);
768 U(tvis).item.pszText = bstrName;
770 hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
771 EnumVars(pRefTypeInfo, pTypeAttr->cVars, hParent);
772 EnumFuncs(pRefTypeInfo, pTypeAttr, hParent);
773 EnumImplTypes(pRefTypeInfo, pTypeAttr->cImplTypes, hParent);
775 SysFreeString(bstrName);
776 ITypeInfo_ReleaseTypeAttr(pRefTypeInfo, pTypeAttr);
777 ITypeInfo_Release(pRefTypeInfo);
780 return 0;
783 static void EnumCoclassImplTypes(ITypeInfo *pTypeInfo,
784 int cImplTypes, TYPELIB_DATA *pTLData)
786 int i;
787 ITypeInfo *pRefTypeInfo;
788 HREFTYPE hRefType;
789 TYPEATTR *pTypeAttr;
790 BSTR bstrName;
791 BOOL bFirst;
792 INT flags;
793 const WCHAR wszTKIND_INTERFACE[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' };
794 const WCHAR wszTKIND_DISPATCH[]
795 = { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' };
796 const WCHAR wszIMPLTYPEFLAG_FDEFAULT[]
797 = { 'd','e','f','a','u','l','t','\0' };
798 const WCHAR wszIMPLTYPEFLAG_FSOURCE[]
799 = { 's','o','u','r','c','e','\0' };
800 const WCHAR wszIMPLTYPEFLAG_FRESTRICTED[]
801 = { 'r','e','s','t','r','i','c','t','e','d','\0' };
803 for(i=0; i<cImplTypes; i++)
805 if(FAILED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo, i, &hRefType))) continue;
806 if(FAILED(ITypeInfo_GetRefTypeInfo(pTypeInfo, hRefType, &pRefTypeInfo)))
807 continue;
808 if(FAILED(ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL, &bstrName,
809 NULL, NULL, NULL)))
811 ITypeInfo_Release(pRefTypeInfo);
812 continue;
814 if(FAILED(ITypeInfo_GetTypeAttr(pRefTypeInfo, &pTypeAttr)))
816 ITypeInfo_Release(pRefTypeInfo);
817 continue;
820 AddSpaces(pTLData, TAB_SIZE);
821 ITypeInfo_GetImplTypeFlags(pTypeInfo, i, &flags);
822 bFirst = TRUE;
823 #define ENUM_IMPLTYPEFLAG(x)\
824 if(flags & x) \
826 if(bFirst) AddToTLDataStrW(pTLData,\
827 wszOpenBrackets1);\
828 else\
830 AddToTLDataStrW(pTLData, wszComa);\
831 AddToTLDataStrW(pTLData, wszSpace);\
833 bFirst = FALSE;\
834 AddToTLDataStrW(pTLData, wsz##x);\
836 ENUM_IMPLTYPEFLAG(IMPLTYPEFLAG_FDEFAULT);
837 ENUM_IMPLTYPEFLAG(IMPLTYPEFLAG_FSOURCE);
838 ENUM_IMPLTYPEFLAG(IMPLTYPEFLAG_FRESTRICTED);
839 if(!bFirst)
841 AddToTLDataStrW(pTLData, wszCloseBrackets1);
842 AddToTLDataStrW(pTLData, wszSpace);
845 if(pTypeAttr->typekind == TKIND_INTERFACE ||
846 (pTypeAttr->wTypeFlags & TYPEFLAG_FDUAL))
847 AddToTLDataStrW(pTLData, wszTKIND_INTERFACE);
848 else if(pTypeAttr->typekind == TKIND_DISPATCH)
849 AddToTLDataStrW(pTLData, wszTKIND_DISPATCH);
850 AddToTLDataStrW(pTLData, wszSpace);
852 AddToTLDataStrW(pTLData, bstrName);
853 AddToTLDataStrW(pTLData, wszSemicolon);
854 AddToTLDataStrW(pTLData, wszNewLine);
856 SysFreeString(bstrName);
857 ITypeInfo_ReleaseTypeAttr(pRefTypeInfo, pTypeAttr);
858 ITypeInfo_Release(pRefTypeInfo);
862 static void AddIdlData(HTREEITEM hCur, TYPELIB_DATA *pTLData)
864 TVITEMW tvi;
866 hCur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
867 TVGN_CHILD, (LPARAM)hCur);
868 memset(&tvi, 0, sizeof(TVITEMW));
869 tvi.mask = TVIF_PARAM;
871 while(hCur)
873 tvi.hItem = hCur;
874 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
875 if(!((TYPELIB_DATA*)(tvi.lParam))->bHide) {
876 AddToTLDataStrW(pTLData, wszNewLine);
877 AddToTLDataStrWithTabsW(pTLData, ((TYPELIB_DATA*)(tvi.lParam))->idl);
879 hCur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
880 TVGN_NEXT, (LPARAM)hCur);
884 static void AddPredefinitions(HTREEITEM hFirst, TYPELIB_DATA *pTLData)
886 HTREEITEM hCur;
887 TVITEMW tvi;
888 WCHAR wszText[MAX_LOAD_STRING];
889 WCHAR wszPredefinition[] = { '/','/',' ','T','L','i','b',' ',':','\n',
890 '/','/',' ','F','o','r','w','a','r','d',' ','d','e','c','l','a','r','e',' ',
891 'a','l','l',' ','t','y','p','e','s',' ','d','e','f','i','n','e','d',' ',
892 'i','n',' ','t','h','i','s',' ','t','y','p','e','l','i','b','\0' };
894 hFirst = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
895 TVGN_CHILD, (LPARAM)hFirst);
897 AddToTLDataStrWithTabsW(pTLData, wszPredefinition);
898 AddToTLDataStrW(pTLData, wszNewLine);
900 hCur = hFirst;
901 memset(&tvi, 0, sizeof(TVITEMW));
902 tvi.mask = TVIF_TEXT|TVIF_PARAM;
903 tvi.cchTextMax = MAX_LOAD_STRING;
904 tvi.pszText = wszText;
905 while(hCur)
907 tvi.hItem = hCur;
908 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
909 if(((TYPELIB_DATA*)(tvi.lParam))->bPredefine &&
910 !((TYPELIB_DATA*)(tvi.lParam))->bHide)
912 AddToStrW(wszText, wszSemicolon);
913 AddToTLDataStrWithTabsW(pTLData, wszText);
914 AddToTLDataStrW(pTLData, wszNewLine);
916 hCur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
917 TVGN_NEXT, (LPARAM)hCur);
921 static void CreateInterfaceInfo(ITypeInfo *pTypeInfo, int cImplTypes, WCHAR *wszName,
922 WCHAR *wszHelpString, ULONG ulHelpContext, TYPEATTR *pTypeAttr,
923 TYPELIB_DATA *pTLData)
925 ITypeInfo *pRefTypeInfo;
926 HREFTYPE hRefType;
927 BSTR bstrName;
928 WCHAR wszGuid[MAX_LOAD_STRING];
929 WCHAR wszHelpContext[MAX_LOAD_STRING];
931 const WCHAR wszInterface[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' };
932 const WCHAR wszDispinterface[]
933 = { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' };
934 const WCHAR wszHelpcontext[] = { 'h','e','l','p','c','o','n','t','e','x','t','\0' };
935 const WCHAR wszTYPEFLAG_FAPPOBJECT[] = { 'a','p','p','o','b','j','e','c','t','\0' };
936 const WCHAR wszTYPEFLAG_FCANCREATE[] = { 'c','a','n','c','r','e','a','t','e','\0' };
937 const WCHAR wszTYPEFLAG_FLICENSED[] = { 'l','i','c','e','n','s','e','d','\0' };
938 const WCHAR wszTYPEFLAG_FPREDECLID[] = { 'p','r','e','d','e','c','l','i','d','\0' };
939 const WCHAR wszTYPEFLAG_FHIDDEN[] = { 'h','i','d','d','e','n','\0' };
940 const WCHAR wszTYPEFLAG_FCONTROL[] = { 'c','o','n','t','r','o','l','\0' };
941 const WCHAR wszTYPEFLAG_FDUAL[] = { 'd','u','a','l','\0' };
942 const WCHAR wszTYPEFLAG_FNONEXTENSIBLE[]
943 = { 'n','o','n','e','x','t','e','n','s','i','b','l','e','\0' };
944 const WCHAR wszTYPEFLAG_FOLEAUTOMATION[]
945 = { 'o','l','e','a','u','t','o','m','a','t','i','o','n','\0' };
946 const WCHAR wszTYPEFLAG_FRESTRICTED[]
947 = { 'r','e','s','t','r','i','c','t','e','d','\0' };
948 const WCHAR wszTYPEFLAG_FAGGREGATABLE[]
949 = { 'a','g','g','r','e','g','a','t','a','b','l','e','\0' };
950 const WCHAR wszTYPEFLAG_FREPLACEABLE[]
951 = { 'r','e','p','l','a','c','a','b','l','e','\0' };
952 const WCHAR wszTYPEFLAG_FREVERSEBIND[]
953 = { 'r','e','v','e','r','s','e','b','i','n','d','\0' };
954 const WCHAR wszTYPEFLAG_FPROXY[] = { 'p','r','o','x','y','\0' };
956 AddToTLDataStrW(pTLData, wszOpenBrackets1);
957 AddToTLDataStrW(pTLData, wszNewLine);
958 if(pTypeAttr->typekind != TKIND_DISPATCH)
960 AddSpaces(pTLData, TAB_SIZE);
961 AddToTLDataStrW(pTLData, wszOdl);
962 AddToTLDataStrW(pTLData, wszComa);
963 AddToTLDataStrW(pTLData, wszNewLine);
965 AddSpaces(pTLData, TAB_SIZE);
966 AddToTLDataStrW(pTLData, wszUUID);
967 AddToTLDataStrW(pTLData, wszOpenBrackets2);
968 StringFromGUID2(&(pTypeAttr->guid), wszGuid, MAX_LOAD_STRING);
969 wszGuid[lstrlenW(wszGuid)-1] = '\0';
970 AddToTLDataStrW(pTLData, &wszGuid[1]);
971 AddToTLDataStrW(pTLData, wszCloseBrackets2);
972 if(wszHelpString)
974 AddToTLDataStrW(pTLData, wszComa);
975 AddToTLDataStrW(pTLData, wszNewLine);
976 AddSpaces(pTLData, TAB_SIZE);
977 AddToTLDataStrW(pTLData, wszHelpstring);
978 AddToTLDataStrW(pTLData, wszOpenBrackets2);
979 AddToTLDataStrW(pTLData, wszInvertedComa);
980 AddToTLDataStrW(pTLData, wszHelpString);
981 AddToTLDataStrW(pTLData, wszInvertedComa);
982 AddToTLDataStrW(pTLData, wszCloseBrackets2);
984 if(ulHelpContext)
986 AddToTLDataStrW(pTLData, wszComa);
987 AddToTLDataStrW(pTLData, wszNewLine);
988 AddSpaces(pTLData, TAB_SIZE);
989 AddToTLDataStrW(pTLData, wszHelpcontext);
990 AddToTLDataStrW(pTLData, wszOpenBrackets2);
991 wsprintfW(wszHelpContext, wszFormat, ulHelpContext);
992 AddToTLDataStrW(pTLData, wszHelpContext);
993 AddToTLDataStrW(pTLData, wszCloseBrackets2);
995 if(pTypeAttr->wTypeFlags)
997 #define ENUM_FLAGS(x) if(pTypeAttr->wTypeFlags & x)\
999 AddToTLDataStrW(pTLData, wszComa);\
1000 AddToTLDataStrW(pTLData, wszNewLine);\
1001 AddSpaces(pTLData, TAB_SIZE);\
1002 AddToTLDataStrW(pTLData, wsz##x);\
1004 ENUM_FLAGS(TYPEFLAG_FAPPOBJECT);
1005 ENUM_FLAGS(TYPEFLAG_FCANCREATE);
1006 ENUM_FLAGS(TYPEFLAG_FLICENSED);
1007 ENUM_FLAGS(TYPEFLAG_FPREDECLID);
1008 ENUM_FLAGS(TYPEFLAG_FHIDDEN);
1009 ENUM_FLAGS(TYPEFLAG_FCONTROL);
1010 ENUM_FLAGS(TYPEFLAG_FDUAL);
1011 ENUM_FLAGS(TYPEFLAG_FNONEXTENSIBLE);
1012 ENUM_FLAGS(TYPEFLAG_FOLEAUTOMATION);
1013 ENUM_FLAGS(TYPEFLAG_FRESTRICTED);
1014 ENUM_FLAGS(TYPEFLAG_FAGGREGATABLE);
1015 ENUM_FLAGS(TYPEFLAG_FREPLACEABLE);
1016 ENUM_FLAGS(TYPEFLAG_FREVERSEBIND);
1017 ENUM_FLAGS(TYPEFLAG_FPROXY);
1019 AddToTLDataStrW(pTLData, wszNewLine);
1020 AddToTLDataStrW(pTLData, wszCloseBrackets1);
1021 AddToTLDataStrW(pTLData, wszNewLine);
1022 if(pTypeAttr->typekind != TKIND_DISPATCH) AddToTLDataStrW(pTLData, wszInterface);
1023 else AddToTLDataStrW(pTLData, wszDispinterface);
1024 AddToTLDataStrW(pTLData, wszName);
1025 AddToTLDataStrW(pTLData, wszSpace);
1026 if(cImplTypes && pTypeAttr->typekind != TKIND_DISPATCH)
1028 AddToTLDataStrW(pTLData, wszColon);
1029 AddToTLDataStrW(pTLData, wszSpace);
1031 ITypeInfo_GetRefTypeOfImplType(pTypeInfo, 0, &hRefType);
1032 if (SUCCEEDED(ITypeInfo_GetRefTypeInfo(pTypeInfo, hRefType, &pRefTypeInfo)))
1034 ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL, &bstrName,
1035 NULL, NULL, NULL);
1036 AddToTLDataStrW(pTLData, bstrName);
1037 AddToTLDataStrW(pTLData, wszSpace);
1039 SysFreeString(bstrName);
1040 ITypeInfo_Release(pRefTypeInfo);
1042 else
1043 AddToTLDataStrW(pTLData, wszFailed);
1045 AddToTLDataStrW(pTLData, wszOpenBrackets3);
1046 AddToTLDataStrW(pTLData, wszNewLine);
1048 AddToStrW(pTLData->wszInsertAfter, wszCloseBrackets3);
1049 AddToStrW(pTLData->wszInsertAfter, wszSemicolon);
1050 AddToStrW(pTLData->wszInsertAfter, wszNewLine);
1053 static void CreateTypedefHeader(ITypeInfo *pTypeInfo,
1054 TYPEATTR *pTypeAttr, TYPELIB_DATA *pTLData)
1056 BOOL bFirst = TRUE;
1057 WCHAR wszGuid[MAX_LOAD_STRING];
1058 const WCHAR wszTypedef[] = { 't','y','p','e','d','e','f',' ','\0' };
1059 const WCHAR wszPublic[] = { 'p','u','b','l','i','c','\0' };
1061 AddToTLDataStrW(pTLData, wszTypedef);
1062 if(memcmp(&pTypeAttr->guid, &GUID_NULL, sizeof(GUID)))
1064 AddToTLDataStrW(pTLData, wszOpenBrackets1);
1065 bFirst = FALSE;
1066 AddToTLDataStrW(pTLData, wszUUID);
1067 AddToTLDataStrW(pTLData, wszOpenBrackets2);
1068 StringFromGUID2(&(pTypeAttr->guid), wszGuid, MAX_LOAD_STRING);
1069 wszGuid[lstrlenW(wszGuid)-1] = '\0';
1070 AddToTLDataStrW(pTLData, &wszGuid[1]);
1071 AddToTLDataStrW(pTLData, wszCloseBrackets2);
1073 if(pTypeAttr->typekind == TKIND_ALIAS)
1075 if(bFirst) AddToTLDataStrW(pTLData, wszOpenBrackets1);
1076 else
1078 AddToTLDataStrW(pTLData, wszComa);
1079 AddToTLDataStrW(pTLData, wszSpace);
1081 bFirst = FALSE;
1082 AddToTLDataStrW(pTLData, wszPublic);
1084 if(!bFirst)
1086 AddToTLDataStrW(pTLData, wszCloseBrackets1);
1087 AddToTLDataStrW(pTLData, wszNewLine);
1091 static void CreateCoclassHeader(ITypeInfo *pTypeInfo,
1092 TYPEATTR *pTypeAttr, TYPELIB_DATA *pTLData)
1094 WCHAR wszGuid[MAX_LOAD_STRING];
1095 BSTR bstrHelpString;
1096 const WCHAR wszNoncreatable[]
1097 = { 'n','o','n','c','r','e','a','t','a','b','l','e','\0' };
1099 AddToTLDataStrW(pTLData, wszOpenBrackets1);
1100 AddToTLDataStrW(pTLData, wszNewLine);
1102 AddSpaces(pTLData, TAB_SIZE);
1103 AddToTLDataStrW(pTLData, wszUUID);
1104 AddToTLDataStrW(pTLData, wszOpenBrackets2);
1105 StringFromGUID2(&(pTypeAttr->guid), wszGuid, MAX_LOAD_STRING);
1106 wszGuid[lstrlenW(wszGuid)-1] = '\0';
1107 AddToTLDataStrW(pTLData, &wszGuid[1]);
1108 AddToTLDataStrW(pTLData, wszCloseBrackets2);
1110 if(SUCCEEDED(ITypeInfo_GetDocumentation(pTypeInfo, MEMBERID_NIL, NULL,
1111 &bstrHelpString, NULL, NULL)))
1113 if(SysStringLen(bstrHelpString))
1115 AddToTLDataStrW(pTLData, wszComa);
1116 AddToTLDataStrW(pTLData, wszNewLine);
1117 AddSpaces(pTLData, TAB_SIZE);
1118 AddToTLDataStrW(pTLData, wszHelpstring);
1119 AddToTLDataStrW(pTLData, wszOpenBrackets2);
1120 AddToTLDataStrW(pTLData, wszInvertedComa);
1121 AddToTLDataStrW(pTLData, bstrHelpString);
1122 AddToTLDataStrW(pTLData, wszInvertedComa);
1123 AddToTLDataStrW(pTLData, wszCloseBrackets2);
1125 SysFreeString(bstrHelpString);
1128 if(!(pTypeAttr->wTypeFlags & TYPEFLAG_FCANCREATE))
1130 AddToTLDataStrW(pTLData, wszComa);
1131 AddToTLDataStrW(pTLData, wszNewLine);
1132 AddSpaces(pTLData, TAB_SIZE);
1133 AddToTLDataStrW(pTLData, wszNoncreatable);
1136 AddToTLDataStrW(pTLData, wszNewLine);
1137 AddToTLDataStrW(pTLData, wszCloseBrackets1);
1138 AddToTLDataStrW(pTLData, wszNewLine);
1141 static int PopulateTree(void)
1143 TVINSERTSTRUCTW tvis;
1144 TVITEMW tvi;
1145 ITypeLib *pTypeLib;
1146 TLIBATTR *pTLibAttr;
1147 ITypeInfo *pTypeInfo, *pRefTypeInfo;
1148 HREFTYPE hRefType;
1149 TYPEATTR *pTypeAttr;
1150 INT count, i;
1151 ULONG ulHelpContext;
1152 BSTR bstrName;
1153 BSTR bstrData;
1154 WCHAR wszText[MAX_LOAD_STRING];
1155 WCHAR wszAfter[MAX_LOAD_STRING];
1156 HRESULT hRes;
1157 HTREEITEM hParent;
1158 HTREEITEM hMain;
1159 BOOL bInsert;
1160 TYPELIB_DATA *tldDispatch;
1161 TYPELIB_DATA *tld;
1163 const WCHAR wszGeneratedInfo[] = { '/','/',' ','G','e','n','e','r','a','t','e','d',
1164 ' ','.','I','D','L',' ','f','i','l','e',' ','(','b','y',' ','t','h','e',' ',
1165 'O','L','E','/','C','O','M',' ','O','b','j','e','c','t',' ',
1166 'V','i','e','w','e','r',')','\n','/','/','\n','/','/',' ',
1167 't','y','p','e','l','i','b',' ','f','i','l','e','n','a','m','e',':',' ','\0'};
1169 const WCHAR wszFormat[] = { '%','s',' ','(','%','s',')','\0' };
1170 const WCHAR wszFormat2[] = { 'v','e','r','s','i','o','n',
1171 '(','%','l','d','.','%','l','d',')','\0' };
1173 const WCHAR wszTKIND_ENUM[] = { 't','y','p','e','d','e','f',' ','e','n','u','m',' ','\0' };
1174 const WCHAR wszTKIND_RECORD[]
1175 = { 't','y','p','e','d','e','f',' ','s','t','r','u','c','t',' ','\0' };
1176 const WCHAR wszTKIND_MODULE[] = { 'm','o','d','u','l','e',' ','\0' };
1177 const WCHAR wszTKIND_INTERFACE[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' };
1178 const WCHAR wszTKIND_DISPATCH[]
1179 = { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' };
1180 const WCHAR wszTKIND_COCLASS[] = { 'c','o','c','l','a','s','s',' ','\0' };
1181 const WCHAR wszTKIND_ALIAS[] = { 't','y','p','e','d','e','f',' ','\0' };
1182 const WCHAR wszTKIND_UNION[]
1183 = { 't','y','p','e','d','e','f',' ','u','n','i','o','n',' ','\0' };
1185 const WCHAR wszLibrary[] = { 'l','i','b','r','a','r','y',' ','\0' };
1186 const WCHAR wszTag[] = { 't','a','g','\0' };
1188 WCHAR wszProperties[] = { 'p','r','o','p','e','r','t','i','e','s','\0' };
1189 WCHAR wszMethods[] = { 'm','e','t','h','o','d','s','\0' };
1191 U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM;
1192 U(tvis).item.cchTextMax = MAX_LOAD_STRING;
1193 U(tvis).item.pszText = wszText;
1194 tvis.hInsertAfter = TVI_LAST;
1195 tvis.hParent = TVI_ROOT;
1197 if(FAILED((hRes = LoadTypeLib(typelib.wszFileName, &pTypeLib))))
1199 WCHAR wszMessage[MAX_LOAD_STRING];
1200 WCHAR wszError[MAX_LOAD_STRING];
1201 DWORD_PTR args[2];
1203 LoadStringW(globals.hMainInst, IDS_ERROR_LOADTYPELIB,
1204 wszError, sizeof(wszError)/sizeof(wszError[0]));
1205 args[0] = (DWORD_PTR)typelib.wszFileName;
1206 args[1] = hRes;
1207 FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
1208 wszError, 0, 0, wszMessage, sizeof(wszMessage)/sizeof(*wszMessage), (__ms_va_list*)args);
1209 MessageBoxW(globals.hMainWnd, wszMessage, NULL, MB_OK|MB_ICONEXCLAMATION);
1210 return 1;
1212 count = ITypeLib_GetTypeInfoCount(pTypeLib);
1214 ITypeLib_GetDocumentation(pTypeLib, -1, &bstrName, &bstrData, NULL, NULL);
1215 ITypeLib_GetLibAttr(pTypeLib, &pTLibAttr);
1217 tld = InitializeTLData();
1218 U(tvis).item.lParam = (LPARAM) tld;
1219 AddToTLDataStrW(tld, wszGeneratedInfo);
1220 AddToTLDataStrW(tld, typelib.wszFileName);
1221 AddToTLDataStrW(tld, wszNewLine);
1222 AddToTLDataStrW(tld, wszNewLine);
1223 AddToTLDataStrW(tld, wszOpenBrackets1);
1224 AddToTLDataStrW(tld, wszNewLine);
1225 AddSpaces(tld, TAB_SIZE);
1226 AddToTLDataStrW(tld, wszUUID);
1227 AddToTLDataStrW(tld, wszOpenBrackets2);
1228 StringFromGUID2(&(pTLibAttr->guid), wszText, MAX_LOAD_STRING);
1229 wszText[lstrlenW(wszText)-1] = '\0';
1230 AddToTLDataStrW(tld, &wszText[1]);
1231 AddToTLDataStrW(tld, wszCloseBrackets2);
1232 AddToTLDataStrW(tld, wszComa);
1233 AddToTLDataStrW(tld, wszNewLine);
1234 AddSpaces(tld, TAB_SIZE);
1235 wsprintfW(wszText, wszFormat2, pTLibAttr->wMajorVerNum, pTLibAttr->wMinorVerNum);
1236 AddToTLDataStrW(tld, wszText);
1238 if (bstrData)
1240 /* helpstring is optional */
1241 AddToTLDataStrW(tld, wszComa);
1242 AddToTLDataStrW(tld, wszNewLine);
1243 AddSpaces(tld, TAB_SIZE);
1244 AddToTLDataStrW(tld, wszHelpstring);
1245 AddToTLDataStrW(tld, wszOpenBrackets2);
1246 AddToTLDataStrW(tld, wszInvertedComa);
1247 AddToTLDataStrW(tld, bstrData);
1248 AddToTLDataStrW(tld, wszInvertedComa);
1249 AddToTLDataStrW(tld, wszCloseBrackets2);
1252 AddToTLDataStrW(tld, wszNewLine);
1253 AddToTLDataStrW(tld, wszCloseBrackets1);
1254 AddToTLDataStrW(tld, wszNewLine);
1255 AddToTLDataStrW(tld, wszLibrary);
1256 if (bstrName) AddToTLDataStrW(tld, bstrName);
1257 AddToTLDataStrW(tld, wszNewLine);
1258 AddToTLDataStrW(tld, wszOpenBrackets3);
1259 AddToTLDataStrW(tld, wszNewLine);
1261 AddToStrW(tld->wszInsertAfter, wszCloseBrackets3);
1262 AddToStrW(tld->wszInsertAfter, wszSemicolon);
1264 wsprintfW(wszText, wszFormat, bstrName, bstrData);
1265 SysFreeString(bstrName);
1266 SysFreeString(bstrData);
1267 tvis.hParent = (HTREEITEM)SendMessageW(typelib.hTree,
1268 TVM_INSERTITEMW, 0, (LPARAM)&tvis);
1270 for(i=0; i<count; i++)
1272 bInsert = TRUE;
1273 ITypeLib_GetTypeInfo(pTypeLib, i, &pTypeInfo);
1275 ITypeInfo_GetDocumentation(pTypeInfo, MEMBERID_NIL, &bstrName, &bstrData,
1276 &ulHelpContext, NULL);
1277 ITypeInfo_GetTypeAttr(pTypeInfo, &pTypeAttr);
1279 memset(wszText, 0, sizeof(wszText));
1280 memset(wszAfter, 0, sizeof(wszAfter));
1281 tld = InitializeTLData();
1282 U(tvis).item.lParam = (LPARAM)tld;
1283 switch(pTypeAttr->typekind)
1285 case TKIND_ENUM:
1286 AddToStrW(wszText, wszTKIND_ENUM);
1287 AddToStrW(wszText, bstrName);
1289 CreateTypedefHeader(pTypeInfo, pTypeAttr, tld);
1290 AddToTLDataStrW(tld, &wszTKIND_ENUM[lstrlenW(wszTKIND_ALIAS)]);
1291 AddToTLDataStrW(tld, wszOpenBrackets3);
1292 AddToTLDataStrW(tld,wszNewLine);
1293 AddToStrW(tld->wszInsertAfter, wszCloseBrackets3);
1294 AddToStrW(tld->wszInsertAfter, wszSpace);
1295 AddToStrW(tld->wszInsertAfter, bstrName);
1296 AddToStrW(tld->wszInsertAfter, wszSemicolon);
1297 AddToStrW(tld->wszInsertAfter, wszNewLine);
1299 bInsert = FALSE;
1300 hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1301 EnumEnums(pTypeInfo, pTypeAttr->cVars, hParent);
1302 AddChildrenData(hParent, tld);
1303 AddToTLDataStrW(tld, tld->wszInsertAfter);
1304 break;
1305 case TKIND_RECORD:
1306 AddToTLDataStrW(tld, wszTKIND_RECORD);
1307 AddToTLDataStrW(tld, wszTag);
1308 AddToTLDataStrW(tld, bstrName);
1309 AddToTLDataStrW(tld, wszSpace);
1310 AddToTLDataStrW(tld, wszOpenBrackets3);
1311 AddToTLDataStrW(tld, wszNewLine);
1313 AddToStrW(tld->wszInsertAfter, wszCloseBrackets3);
1314 AddToStrW(tld->wszInsertAfter, wszSpace);
1315 AddToStrW(tld->wszInsertAfter, bstrName);
1316 AddToStrW(tld->wszInsertAfter, wszSemicolon);
1317 AddToStrW(tld->wszInsertAfter, wszNewLine);
1319 AddToStrW(wszText, wszTKIND_RECORD);
1320 AddToStrW(wszText, bstrName);
1321 break;
1322 case TKIND_MODULE:
1323 AddToStrW(wszText, wszTKIND_MODULE);
1324 AddToStrW(wszText, bstrName);
1325 break;
1326 case TKIND_INTERFACE:
1327 CreateInterfaceInfo(pTypeInfo, pTypeAttr->cImplTypes, bstrName,
1328 bstrData, ulHelpContext, pTypeAttr, tld);
1329 tld->bPredefine = TRUE;
1331 AddToStrW(wszText, wszTKIND_INTERFACE);
1332 AddToStrW(wszText, bstrName);
1333 break;
1334 case TKIND_COCLASS:
1335 AddToStrW(wszText, wszTKIND_COCLASS);
1336 AddToStrW(wszText, bstrName);
1338 CreateCoclassHeader(pTypeInfo, pTypeAttr, tld);
1339 AddToTLDataStrW(tld, wszTKIND_COCLASS);
1340 AddToTLDataStrW(tld, bstrName);
1341 AddToTLDataStrW(tld, wszSpace);
1342 AddToTLDataStrW(tld, wszOpenBrackets3);
1343 AddToTLDataStrW(tld, wszNewLine);
1345 EnumCoclassImplTypes(pTypeInfo, pTypeAttr->cImplTypes, tld);
1347 AddToStrW(tld->wszInsertAfter, wszCloseBrackets3);
1348 AddToStrW(tld->wszInsertAfter, wszSemicolon);
1349 AddToStrW(tld->wszInsertAfter, wszNewLine);
1351 bInsert = FALSE;
1352 hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1353 AddToTLDataStrW(tld, tld->wszInsertAfter);
1354 break;
1355 case TKIND_UNION:
1356 AddToStrW(wszText, wszTKIND_UNION);
1357 AddToStrW(wszText, bstrName);
1358 break;
1359 case TKIND_DISPATCH:
1360 CreateInterfaceInfo(pTypeInfo, pTypeAttr->cImplTypes, bstrName,
1361 bstrData, ulHelpContext, pTypeAttr, tld);
1362 tld->bPredefine = TRUE;
1363 if(pTypeAttr->wTypeFlags & TYPEFLAG_FDUAL)
1364 tld->bHide = TRUE;
1365 AddToStrW(wszText, wszTKIND_DISPATCH);
1366 AddToStrW(wszText, bstrName);
1368 hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1369 hMain = tvis.hParent;
1370 tldDispatch = tld;
1372 lstrcpyW(wszText, wszProperties);
1373 tvis.hParent = hParent;
1374 tld = InitializeTLData();
1375 U(tvis).item.lParam = (LPARAM) tld;
1376 AddToTLDataStrW(tld, wszProperties);
1377 AddToTLDataStrW(tld, wszColon);
1378 AddToTLDataStrW(tld, wszNewLine);
1379 tvis.hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1380 EnumVars(pTypeInfo, pTypeAttr->cVars, tvis.hParent);
1381 AddChildrenData(tvis.hParent, tld);
1383 lstrcpyW(wszText, wszMethods);
1384 tvis.hParent = hParent;
1385 tld = InitializeTLData();
1386 U(tvis).item.lParam = (LPARAM) tld;
1387 AddToTLDataStrW(tld, wszMethods);
1388 AddToTLDataStrW(tld, wszColon);
1389 AddToTLDataStrW(tld, wszNewLine);
1390 tvis.hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1391 EnumFuncs(pTypeInfo, pTypeAttr, tvis.hParent);
1392 AddChildrenData(tvis.hParent, tld);
1394 EnumImplTypes(pTypeInfo, pTypeAttr->cImplTypes, hParent);
1395 AddChildrenData(hParent, tldDispatch);
1396 AddToTLDataStrW(tldDispatch, tldDispatch->wszInsertAfter);
1398 bInsert = FALSE;
1399 tvis.hParent = hMain;
1401 if(SUCCEEDED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo, -1, &hRefType)))
1403 bInsert = TRUE;
1405 ITypeInfo_ReleaseTypeAttr(pTypeInfo, pTypeAttr);
1406 SysFreeString(bstrName);
1407 SysFreeString(bstrData);
1409 memset(wszText, 0, sizeof(wszText));
1410 tld = InitializeTLData();
1411 U(tvis).item.lParam = (LPARAM) tld;
1413 ITypeInfo_GetRefTypeInfo(pTypeInfo, hRefType, &pRefTypeInfo);
1414 ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL, &bstrName,
1415 &bstrData, &ulHelpContext, NULL);
1416 ITypeInfo_GetTypeAttr(pRefTypeInfo, &pTypeAttr);
1418 CreateInterfaceInfo(pTypeInfo, pTypeAttr->cImplTypes, bstrName,
1419 bstrData, ulHelpContext, pTypeAttr, tld);
1420 tld->bPredefine = TRUE;
1422 AddToStrW(wszText, wszTKIND_INTERFACE);
1423 AddToStrW(wszText, bstrName);
1424 ITypeInfo_Release(pRefTypeInfo);
1426 break;
1427 case TKIND_ALIAS:
1428 AddToStrW(wszText, wszTKIND_ALIAS);
1429 CreateTypeInfo(wszText, wszAfter, pTypeAttr->tdescAlias, pTypeInfo);
1430 AddToStrW(wszText, wszSpace);
1431 AddToStrW(wszText, bstrName);
1432 AddToStrW(wszText, wszAfter);
1434 CreateTypedefHeader(pTypeInfo, pTypeAttr, tld);
1435 AddToTLDataStrW(tld, &wszText[lstrlenW(wszTKIND_ALIAS)]);
1436 AddToTLDataStrW(tld, wszSemicolon);
1437 AddToTLDataStrW(tld, wszNewLine);
1438 break;
1439 default:
1440 lstrcpyW(wszText, bstrName);
1441 WINE_FIXME("pTypeAttr->typekind == %d not supported\n",
1442 pTypeAttr->typekind);
1445 if(bInsert)
1447 hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1449 EnumVars(pTypeInfo, pTypeAttr->cVars, hParent);
1450 EnumFuncs(pTypeInfo, pTypeAttr, hParent);
1451 EnumImplTypes(pTypeInfo, pTypeAttr->cImplTypes, hParent);
1453 if(memcmp(bstrName, wszVT_UNKNOWN, sizeof(wszVT_UNKNOWN)))
1454 AddChildrenData(hParent, tld);
1455 AddToTLDataStrW(tld, tld->wszInsertAfter);
1458 ITypeInfo_ReleaseTypeAttr(pTypeInfo, pTypeAttr);
1459 ITypeInfo_Release(pTypeInfo);
1460 SysFreeString(bstrName);
1461 SysFreeString(bstrData);
1463 SendMessageW(typelib.hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)tvis.hParent);
1465 memset(&tvi, 0, sizeof(TVITEMW));
1466 tvi.mask = TVIF_PARAM;
1467 tvi.hItem = tvis.hParent;
1469 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
1470 AddPredefinitions(tvi.hItem, (TYPELIB_DATA*)(tvi.lParam));
1471 AddIdlData(tvi.hItem, (TYPELIB_DATA*)(tvi.lParam));
1472 AddToTLDataStrW((TYPELIB_DATA*)(tvi.lParam),
1473 ((TYPELIB_DATA*)(tvi.lParam))->wszInsertAfter);
1475 ITypeLib_Release(pTypeLib);
1476 return 0;
1479 void UpdateData(HTREEITEM item)
1481 TVITEMW tvi;
1483 memset(&tvi, 0, sizeof(TVITEMW));
1484 tvi.mask = TVIF_PARAM;
1485 tvi.hItem = item;
1487 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
1488 if(!tvi.lParam)
1490 SetWindowTextW(typelib.hEdit, wszSpace);
1491 return;
1494 SetWindowTextW(typelib.hEdit, ((TYPELIB_DATA*)tvi.lParam)->idl);
1497 static void TypeLibResizeChild(void)
1499 RECT client, stat;
1501 MoveWindow(typelib.hStatusBar, 0, 0, 0, 0, TRUE);
1503 if(IsWindowVisible(typelib.hStatusBar))
1504 GetClientRect(typelib.hStatusBar, &stat);
1505 else stat.bottom = 0;
1507 GetClientRect(globals.hTypeLibWnd, &client);
1508 MoveWindow(typelib.hPaneWnd, 0, 0,
1509 client.right, client.bottom-stat.bottom, TRUE);
1512 static void TypeLibMenuCommand(WPARAM wParam, HWND hWnd)
1514 BOOL vis;
1516 switch(wParam)
1518 case IDM_SAVEAS:
1519 GetSaveIdlAsPath();
1520 break;
1521 case IDM_STATUSBAR:
1522 vis = IsWindowVisible(typelib.hStatusBar);
1523 ShowWindow(typelib.hStatusBar, vis ? SW_HIDE : SW_SHOW);
1524 CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
1525 vis ? MF_UNCHECKED : MF_CHECKED);
1526 TypeLibResizeChild();
1527 break;
1528 case IDM_CLOSE:
1529 DestroyWindow(hWnd);
1530 break;
1534 static void UpdateTypeLibStatusBar(int itemID)
1536 WCHAR info[MAX_LOAD_STRING];
1538 if(!LoadStringW(globals.hMainInst, itemID, info, sizeof(info)/sizeof(info[0])))
1539 LoadStringW(globals.hMainInst, IDS_READY, info, sizeof(info)/sizeof(info[0]));
1541 SendMessageW(typelib.hStatusBar, SB_SETTEXTW, 0, (LPARAM)info);
1544 static void EmptyTLTree(void)
1546 HTREEITEM cur, del;
1547 TVITEMW tvi;
1549 tvi.mask = TVIF_PARAM;
1550 cur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
1551 TVGN_CHILD, (LPARAM)TVI_ROOT);
1553 while(TRUE)
1555 del = cur;
1556 cur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
1557 TVGN_CHILD, (LPARAM)del);
1559 if(!cur) cur = (HTREEITEM)SendMessageW(typelib.hTree,
1560 TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)del);
1561 if(!cur) cur = (HTREEITEM)SendMessageW(typelib.hTree,
1562 TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)del);
1564 tvi.hItem = del;
1565 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
1566 if(tvi.lParam)
1568 HeapFree(GetProcessHeap(), 0, ((TYPELIB_DATA *)tvi.lParam)->idl);
1569 HeapFree(GetProcessHeap(), 0, (TYPELIB_DATA *)tvi.lParam);
1572 SendMessageW(typelib.hTree, TVM_DELETEITEM, 0, (LPARAM)del);
1574 if(!cur) break;
1578 static LRESULT CALLBACK TypeLibProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1580 switch(uMsg)
1582 case WM_CREATE:
1584 if(!CreatePanedWindow(hWnd, &typelib.hPaneWnd, globals.hMainInst))
1585 DestroyWindow(hWnd);
1586 typelib.hTree = CreateWindowExW(WS_EX_CLIENTEDGE, WC_TREEVIEWW, NULL,
1587 WS_CHILD|WS_VISIBLE|TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT,
1588 0, 0, 0, 0, typelib.hPaneWnd, (HMENU)TYPELIB_TREE,
1589 globals.hMainInst, NULL);
1590 typelib.hEdit = CreateWindowExW(WS_EX_CLIENTEDGE, WC_EDITW, NULL,
1591 WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_READONLY|WS_HSCROLL|WS_VSCROLL,
1592 0, 0, 0, 0, typelib.hPaneWnd, NULL, globals.hMainInst, NULL);
1594 SetLeft(typelib.hPaneWnd, typelib.hTree);
1595 SetRight(typelib.hPaneWnd, typelib.hEdit);
1597 if(PopulateTree()) DestroyWindow(hWnd);
1598 else SetFocus(typelib.hTree);
1599 break;
1601 case WM_COMMAND:
1602 TypeLibMenuCommand(LOWORD(wParam), hWnd);
1603 case WM_MENUSELECT:
1604 UpdateTypeLibStatusBar(LOWORD(wParam));
1605 break;
1606 case WM_SETFOCUS:
1607 SetFocus(typelib.hTree);
1608 break;
1609 case WM_SIZE:
1610 if(wParam == SIZE_MINIMIZED) break;
1611 TypeLibResizeChild();
1612 break;
1613 case WM_DESTROY:
1614 EmptyTLTree();
1615 break;
1616 default:
1617 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
1619 return 0;
1622 BOOL TypeLibRegisterClassW(void)
1624 WNDCLASSW wcc;
1626 memset(&wcc, 0, sizeof(WNDCLASSW));
1627 wcc.lpfnWndProc = TypeLibProc;
1628 wcc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
1629 wcc.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
1630 wcc.lpszMenuName = MAKEINTRESOURCEW(IDM_TYPELIB);
1631 wcc.lpszClassName = wszTypeLib;
1633 if(!RegisterClassW(&wcc))
1634 return FALSE;
1636 return TRUE;
1639 BOOL CreateTypeLibWindow(HINSTANCE hInst, WCHAR *wszFileName)
1641 WCHAR wszTitle[MAX_LOAD_STRING];
1642 LoadStringW(hInst, IDS_TYPELIBTITLE, wszTitle, sizeof(wszTitle)/sizeof(wszTitle[0]));
1644 if(wszFileName) lstrcpyW(typelib.wszFileName, wszFileName);
1645 else
1647 TVITEMW tvi;
1649 memset(&tvi, 0, sizeof(TVITEMW));
1650 tvi.hItem = (HTREEITEM)SendMessageW(globals.hTree, TVM_GETNEXTITEM,
1651 TVGN_CARET, 0);
1653 SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
1654 lstrcpyW(typelib.wszFileName, ((ITEM_INFO*)tvi.lParam)->path);
1657 globals.hTypeLibWnd = CreateWindowW(wszTypeLib, wszTitle,
1658 WS_OVERLAPPEDWINDOW|WS_VISIBLE,
1659 CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInst, NULL);
1660 if(!globals.hTypeLibWnd) return FALSE;
1662 typelib.hStatusBar = CreateStatusWindowW(WS_VISIBLE|WS_CHILD,
1663 wszTitle, globals.hTypeLibWnd, 0);
1665 TypeLibResizeChild();
1666 return TRUE;