ieframe: Moved dialog resources to ieframe.
[wine/testsucceed.git] / programs / oleview / typelib.c
blobb28dd909f8f739922c8fdc9045d9e8a4736e08bb
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];
1202 LoadStringW(globals.hMainInst, IDS_ERROR_LOADTYPELIB,
1203 wszError, sizeof(wszError)/sizeof(wszError[0]));
1204 wsprintfW(wszMessage, wszError, typelib.wszFileName, hRes);
1205 MessageBoxW(globals.hMainWnd, wszMessage, NULL, MB_OK|MB_ICONEXCLAMATION);
1206 return 1;
1208 count = ITypeLib_GetTypeInfoCount(pTypeLib);
1210 ITypeLib_GetDocumentation(pTypeLib, -1, &bstrName, &bstrData, NULL, NULL);
1211 ITypeLib_GetLibAttr(pTypeLib, &pTLibAttr);
1213 tld = InitializeTLData();
1214 U(tvis).item.lParam = (LPARAM) tld;
1215 AddToTLDataStrW(tld, wszGeneratedInfo);
1216 AddToTLDataStrW(tld, typelib.wszFileName);
1217 AddToTLDataStrW(tld, wszNewLine);
1218 AddToTLDataStrW(tld, wszNewLine);
1219 AddToTLDataStrW(tld, wszOpenBrackets1);
1220 AddToTLDataStrW(tld, wszNewLine);
1221 AddSpaces(tld, TAB_SIZE);
1222 AddToTLDataStrW(tld, wszUUID);
1223 AddToTLDataStrW(tld, wszOpenBrackets2);
1224 StringFromGUID2(&(pTLibAttr->guid), wszText, MAX_LOAD_STRING);
1225 wszText[lstrlenW(wszText)-1] = '\0';
1226 AddToTLDataStrW(tld, &wszText[1]);
1227 AddToTLDataStrW(tld, wszCloseBrackets2);
1228 AddToTLDataStrW(tld, wszComa);
1229 AddToTLDataStrW(tld, wszNewLine);
1230 AddSpaces(tld, TAB_SIZE);
1231 wsprintfW(wszText, wszFormat2, pTLibAttr->wMajorVerNum, pTLibAttr->wMinorVerNum);
1232 AddToTLDataStrW(tld, wszText);
1234 if (bstrData)
1236 /* helpstring is optional */
1237 AddToTLDataStrW(tld, wszComa);
1238 AddToTLDataStrW(tld, wszNewLine);
1239 AddSpaces(tld, TAB_SIZE);
1240 AddToTLDataStrW(tld, wszHelpstring);
1241 AddToTLDataStrW(tld, wszOpenBrackets2);
1242 AddToTLDataStrW(tld, wszInvertedComa);
1243 AddToTLDataStrW(tld, bstrData);
1244 AddToTLDataStrW(tld, wszInvertedComa);
1245 AddToTLDataStrW(tld, wszCloseBrackets2);
1248 AddToTLDataStrW(tld, wszNewLine);
1249 AddToTLDataStrW(tld, wszCloseBrackets1);
1250 AddToTLDataStrW(tld, wszNewLine);
1251 AddToTLDataStrW(tld, wszLibrary);
1252 if (bstrName) AddToTLDataStrW(tld, bstrName);
1253 AddToTLDataStrW(tld, wszNewLine);
1254 AddToTLDataStrW(tld, wszOpenBrackets3);
1255 AddToTLDataStrW(tld, wszNewLine);
1257 AddToStrW(tld->wszInsertAfter, wszCloseBrackets3);
1258 AddToStrW(tld->wszInsertAfter, wszSemicolon);
1260 wsprintfW(wszText, wszFormat, bstrName, bstrData);
1261 SysFreeString(bstrName);
1262 SysFreeString(bstrData);
1263 tvis.hParent = (HTREEITEM)SendMessageW(typelib.hTree,
1264 TVM_INSERTITEMW, 0, (LPARAM)&tvis);
1266 for(i=0; i<count; i++)
1268 bInsert = TRUE;
1269 ITypeLib_GetTypeInfo(pTypeLib, i, &pTypeInfo);
1271 ITypeInfo_GetDocumentation(pTypeInfo, MEMBERID_NIL, &bstrName, &bstrData,
1272 &ulHelpContext, NULL);
1273 ITypeInfo_GetTypeAttr(pTypeInfo, &pTypeAttr);
1275 memset(wszText, 0, sizeof(wszText));
1276 memset(wszAfter, 0, sizeof(wszAfter));
1277 tld = InitializeTLData();
1278 U(tvis).item.lParam = (LPARAM)tld;
1279 switch(pTypeAttr->typekind)
1281 case TKIND_ENUM:
1282 AddToStrW(wszText, wszTKIND_ENUM);
1283 AddToStrW(wszText, bstrName);
1285 CreateTypedefHeader(pTypeInfo, pTypeAttr, tld);
1286 AddToTLDataStrW(tld, &wszTKIND_ENUM[lstrlenW(wszTKIND_ALIAS)]);
1287 AddToTLDataStrW(tld, wszOpenBrackets3);
1288 AddToTLDataStrW(tld,wszNewLine);
1289 AddToStrW(tld->wszInsertAfter, wszCloseBrackets3);
1290 AddToStrW(tld->wszInsertAfter, wszSpace);
1291 AddToStrW(tld->wszInsertAfter, bstrName);
1292 AddToStrW(tld->wszInsertAfter, wszSemicolon);
1293 AddToStrW(tld->wszInsertAfter, wszNewLine);
1295 bInsert = FALSE;
1296 hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1297 EnumEnums(pTypeInfo, pTypeAttr->cVars, hParent);
1298 AddChildrenData(hParent, tld);
1299 AddToTLDataStrW(tld, tld->wszInsertAfter);
1300 break;
1301 case TKIND_RECORD:
1302 AddToTLDataStrW(tld, wszTKIND_RECORD);
1303 AddToTLDataStrW(tld, wszTag);
1304 AddToTLDataStrW(tld, bstrName);
1305 AddToTLDataStrW(tld, wszSpace);
1306 AddToTLDataStrW(tld, wszOpenBrackets3);
1307 AddToTLDataStrW(tld, wszNewLine);
1309 AddToStrW(tld->wszInsertAfter, wszCloseBrackets3);
1310 AddToStrW(tld->wszInsertAfter, wszSpace);
1311 AddToStrW(tld->wszInsertAfter, bstrName);
1312 AddToStrW(tld->wszInsertAfter, wszSemicolon);
1313 AddToStrW(tld->wszInsertAfter, wszNewLine);
1315 AddToStrW(wszText, wszTKIND_RECORD);
1316 AddToStrW(wszText, bstrName);
1317 break;
1318 case TKIND_MODULE:
1319 AddToStrW(wszText, wszTKIND_MODULE);
1320 AddToStrW(wszText, bstrName);
1321 break;
1322 case TKIND_INTERFACE:
1323 CreateInterfaceInfo(pTypeInfo, pTypeAttr->cImplTypes, bstrName,
1324 bstrData, ulHelpContext, pTypeAttr, tld);
1325 tld->bPredefine = TRUE;
1327 AddToStrW(wszText, wszTKIND_INTERFACE);
1328 AddToStrW(wszText, bstrName);
1329 break;
1330 case TKIND_COCLASS:
1331 AddToStrW(wszText, wszTKIND_COCLASS);
1332 AddToStrW(wszText, bstrName);
1334 CreateCoclassHeader(pTypeInfo, pTypeAttr, tld);
1335 AddToTLDataStrW(tld, wszTKIND_COCLASS);
1336 AddToTLDataStrW(tld, bstrName);
1337 AddToTLDataStrW(tld, wszSpace);
1338 AddToTLDataStrW(tld, wszOpenBrackets3);
1339 AddToTLDataStrW(tld, wszNewLine);
1341 EnumCoclassImplTypes(pTypeInfo, pTypeAttr->cImplTypes, tld);
1343 AddToStrW(tld->wszInsertAfter, wszCloseBrackets3);
1344 AddToStrW(tld->wszInsertAfter, wszSemicolon);
1345 AddToStrW(tld->wszInsertAfter, wszNewLine);
1347 bInsert = FALSE;
1348 hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1349 AddToTLDataStrW(tld, tld->wszInsertAfter);
1350 break;
1351 case TKIND_UNION:
1352 AddToStrW(wszText, wszTKIND_UNION);
1353 AddToStrW(wszText, bstrName);
1354 break;
1355 case TKIND_DISPATCH:
1356 CreateInterfaceInfo(pTypeInfo, pTypeAttr->cImplTypes, bstrName,
1357 bstrData, ulHelpContext, pTypeAttr, tld);
1358 tld->bPredefine = TRUE;
1359 if(pTypeAttr->wTypeFlags & TYPEFLAG_FDUAL)
1360 tld->bHide = TRUE;
1361 AddToStrW(wszText, wszTKIND_DISPATCH);
1362 AddToStrW(wszText, bstrName);
1364 hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1365 hMain = tvis.hParent;
1366 tldDispatch = tld;
1368 lstrcpyW(wszText, wszProperties);
1369 tvis.hParent = hParent;
1370 tld = InitializeTLData();
1371 U(tvis).item.lParam = (LPARAM) tld;
1372 AddToTLDataStrW(tld, wszProperties);
1373 AddToTLDataStrW(tld, wszColon);
1374 AddToTLDataStrW(tld, wszNewLine);
1375 tvis.hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1376 EnumVars(pTypeInfo, pTypeAttr->cVars, tvis.hParent);
1377 AddChildrenData(tvis.hParent, tld);
1379 lstrcpyW(wszText, wszMethods);
1380 tvis.hParent = hParent;
1381 tld = InitializeTLData();
1382 U(tvis).item.lParam = (LPARAM) tld;
1383 AddToTLDataStrW(tld, wszMethods);
1384 AddToTLDataStrW(tld, wszColon);
1385 AddToTLDataStrW(tld, wszNewLine);
1386 tvis.hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1387 EnumFuncs(pTypeInfo, pTypeAttr, tvis.hParent);
1388 AddChildrenData(tvis.hParent, tld);
1390 EnumImplTypes(pTypeInfo, pTypeAttr->cImplTypes, hParent);
1391 AddChildrenData(hParent, tldDispatch);
1392 AddToTLDataStrW(tldDispatch, tldDispatch->wszInsertAfter);
1394 bInsert = FALSE;
1395 tvis.hParent = hMain;
1397 if(SUCCEEDED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo, -1, &hRefType)))
1399 bInsert = TRUE;
1401 ITypeInfo_ReleaseTypeAttr(pTypeInfo, pTypeAttr);
1402 SysFreeString(bstrName);
1403 SysFreeString(bstrData);
1405 memset(wszText, 0, sizeof(wszText));
1406 tld = InitializeTLData();
1407 U(tvis).item.lParam = (LPARAM) tld;
1409 ITypeInfo_GetRefTypeInfo(pTypeInfo, hRefType, &pRefTypeInfo);
1410 ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL, &bstrName,
1411 &bstrData, &ulHelpContext, NULL);
1412 ITypeInfo_GetTypeAttr(pRefTypeInfo, &pTypeAttr);
1414 CreateInterfaceInfo(pTypeInfo, pTypeAttr->cImplTypes, bstrName,
1415 bstrData, ulHelpContext, pTypeAttr, tld);
1416 tld->bPredefine = TRUE;
1418 AddToStrW(wszText, wszTKIND_INTERFACE);
1419 AddToStrW(wszText, bstrName);
1420 ITypeInfo_Release(pRefTypeInfo);
1422 break;
1423 case TKIND_ALIAS:
1424 AddToStrW(wszText, wszTKIND_ALIAS);
1425 CreateTypeInfo(wszText, wszAfter, pTypeAttr->tdescAlias, pTypeInfo);
1426 AddToStrW(wszText, wszSpace);
1427 AddToStrW(wszText, bstrName);
1428 AddToStrW(wszText, wszAfter);
1430 CreateTypedefHeader(pTypeInfo, pTypeAttr, tld);
1431 AddToTLDataStrW(tld, &wszText[lstrlenW(wszTKIND_ALIAS)]);
1432 AddToTLDataStrW(tld, wszSemicolon);
1433 AddToTLDataStrW(tld, wszNewLine);
1434 break;
1435 default:
1436 lstrcpyW(wszText, bstrName);
1437 WINE_FIXME("pTypeAttr->typekind == %d not supported\n",
1438 pTypeAttr->typekind);
1441 if(bInsert)
1443 hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1445 EnumVars(pTypeInfo, pTypeAttr->cVars, hParent);
1446 EnumFuncs(pTypeInfo, pTypeAttr, hParent);
1447 EnumImplTypes(pTypeInfo, pTypeAttr->cImplTypes, hParent);
1449 if(memcmp(bstrName, wszVT_UNKNOWN, sizeof(wszVT_UNKNOWN)))
1450 AddChildrenData(hParent, tld);
1451 AddToTLDataStrW(tld, tld->wszInsertAfter);
1454 ITypeInfo_ReleaseTypeAttr(pTypeInfo, pTypeAttr);
1455 ITypeInfo_Release(pTypeInfo);
1456 SysFreeString(bstrName);
1457 SysFreeString(bstrData);
1459 SendMessageW(typelib.hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)tvis.hParent);
1461 memset(&tvi, 0, sizeof(TVITEMW));
1462 tvi.mask = TVIF_PARAM;
1463 tvi.hItem = tvis.hParent;
1465 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
1466 AddPredefinitions(tvi.hItem, (TYPELIB_DATA*)(tvi.lParam));
1467 AddIdlData(tvi.hItem, (TYPELIB_DATA*)(tvi.lParam));
1468 AddToTLDataStrW((TYPELIB_DATA*)(tvi.lParam),
1469 ((TYPELIB_DATA*)(tvi.lParam))->wszInsertAfter);
1471 ITypeLib_Release(pTypeLib);
1472 return 0;
1475 void UpdateData(HTREEITEM item)
1477 TVITEMW tvi;
1479 memset(&tvi, 0, sizeof(TVITEMW));
1480 tvi.mask = TVIF_PARAM;
1481 tvi.hItem = item;
1483 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
1484 if(!tvi.lParam)
1486 SetWindowTextW(typelib.hEdit, wszSpace);
1487 return;
1490 SetWindowTextW(typelib.hEdit, ((TYPELIB_DATA*)tvi.lParam)->idl);
1493 static void TypeLibResizeChild(void)
1495 RECT client, stat;
1497 MoveWindow(typelib.hStatusBar, 0, 0, 0, 0, TRUE);
1499 if(IsWindowVisible(typelib.hStatusBar))
1500 GetClientRect(typelib.hStatusBar, &stat);
1501 else stat.bottom = 0;
1503 GetClientRect(globals.hTypeLibWnd, &client);
1504 MoveWindow(typelib.hPaneWnd, 0, 0,
1505 client.right, client.bottom-stat.bottom, TRUE);
1508 static void TypeLibMenuCommand(WPARAM wParam, HWND hWnd)
1510 BOOL vis;
1512 switch(wParam)
1514 case IDM_SAVEAS:
1515 GetSaveIdlAsPath();
1516 break;
1517 case IDM_STATUSBAR:
1518 vis = IsWindowVisible(typelib.hStatusBar);
1519 ShowWindow(typelib.hStatusBar, vis ? SW_HIDE : SW_SHOW);
1520 CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
1521 vis ? MF_UNCHECKED : MF_CHECKED);
1522 TypeLibResizeChild();
1523 break;
1524 case IDM_CLOSE:
1525 DestroyWindow(hWnd);
1526 break;
1530 static void UpdateTypeLibStatusBar(int itemID)
1532 WCHAR info[MAX_LOAD_STRING];
1534 if(!LoadStringW(globals.hMainInst, itemID, info, sizeof(info)/sizeof(info[0])))
1535 LoadStringW(globals.hMainInst, IDS_READY, info, sizeof(info)/sizeof(info[0]));
1537 SendMessageW(typelib.hStatusBar, SB_SETTEXTW, 0, (LPARAM)info);
1540 static void EmptyTLTree(void)
1542 HTREEITEM cur, del;
1543 TVITEMW tvi;
1545 tvi.mask = TVIF_PARAM;
1546 cur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
1547 TVGN_CHILD, (LPARAM)TVI_ROOT);
1549 while(TRUE)
1551 del = cur;
1552 cur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
1553 TVGN_CHILD, (LPARAM)del);
1555 if(!cur) cur = (HTREEITEM)SendMessageW(typelib.hTree,
1556 TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)del);
1557 if(!cur) cur = (HTREEITEM)SendMessageW(typelib.hTree,
1558 TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)del);
1560 tvi.hItem = del;
1561 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
1562 if(tvi.lParam)
1564 HeapFree(GetProcessHeap(), 0, ((TYPELIB_DATA *)tvi.lParam)->idl);
1565 HeapFree(GetProcessHeap(), 0, (TYPELIB_DATA *)tvi.lParam);
1568 SendMessageW(typelib.hTree, TVM_DELETEITEM, 0, (LPARAM)del);
1570 if(!cur) break;
1574 static LRESULT CALLBACK TypeLibProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1576 switch(uMsg)
1578 case WM_CREATE:
1580 if(!CreatePanedWindow(hWnd, &typelib.hPaneWnd, globals.hMainInst))
1581 DestroyWindow(hWnd);
1582 typelib.hTree = CreateWindowExW(WS_EX_CLIENTEDGE, WC_TREEVIEWW, NULL,
1583 WS_CHILD|WS_VISIBLE|TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT,
1584 0, 0, 0, 0, typelib.hPaneWnd, (HMENU)TYPELIB_TREE,
1585 globals.hMainInst, NULL);
1586 typelib.hEdit = CreateWindowExW(WS_EX_CLIENTEDGE, WC_EDITW, NULL,
1587 WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_READONLY|WS_HSCROLL|WS_VSCROLL,
1588 0, 0, 0, 0, typelib.hPaneWnd, NULL, globals.hMainInst, NULL);
1590 SetLeft(typelib.hPaneWnd, typelib.hTree);
1591 SetRight(typelib.hPaneWnd, typelib.hEdit);
1593 if(PopulateTree()) DestroyWindow(hWnd);
1594 else SetFocus(typelib.hTree);
1595 break;
1597 case WM_COMMAND:
1598 TypeLibMenuCommand(LOWORD(wParam), hWnd);
1599 case WM_MENUSELECT:
1600 UpdateTypeLibStatusBar(LOWORD(wParam));
1601 break;
1602 case WM_SETFOCUS:
1603 SetFocus(typelib.hTree);
1604 break;
1605 case WM_SIZE:
1606 if(wParam == SIZE_MINIMIZED) break;
1607 TypeLibResizeChild();
1608 break;
1609 case WM_DESTROY:
1610 EmptyTLTree();
1611 break;
1612 default:
1613 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
1615 return 0;
1618 BOOL TypeLibRegisterClassW(void)
1620 WNDCLASSW wcc;
1622 memset(&wcc, 0, sizeof(WNDCLASSW));
1623 wcc.lpfnWndProc = TypeLibProc;
1624 wcc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
1625 wcc.lpszMenuName = MAKEINTRESOURCEW(IDM_TYPELIB);
1626 wcc.lpszClassName = wszTypeLib;
1628 if(!RegisterClassW(&wcc))
1629 return FALSE;
1631 return TRUE;
1634 BOOL CreateTypeLibWindow(HINSTANCE hInst, WCHAR *wszFileName)
1636 WCHAR wszTitle[MAX_LOAD_STRING];
1637 LoadStringW(hInst, IDS_TYPELIBTITLE, wszTitle, sizeof(wszTitle)/sizeof(wszTitle[0]));
1639 if(wszFileName) lstrcpyW(typelib.wszFileName, wszFileName);
1640 else
1642 TVITEMW tvi;
1644 memset(&tvi, 0, sizeof(TVITEMW));
1645 tvi.hItem = (HTREEITEM)SendMessageW(globals.hTree, TVM_GETNEXTITEM,
1646 TVGN_CARET, 0);
1648 SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
1649 lstrcpyW(typelib.wszFileName, ((ITEM_INFO*)tvi.lParam)->path);
1652 globals.hTypeLibWnd = CreateWindowW(wszTypeLib, wszTitle,
1653 WS_OVERLAPPEDWINDOW|WS_VISIBLE,
1654 CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInst, NULL);
1655 if(!globals.hTypeLibWnd) return FALSE;
1657 typelib.hStatusBar = CreateStatusWindowW(WS_VISIBLE|WS_CHILD,
1658 wszTitle, globals.hTypeLibWnd, 0);
1660 TypeLibResizeChild();
1661 return TRUE;