oleview: Use the explicit W types/functions in typelib.c.
[wine/hacks.git] / programs / oleview / typelib.c
blob6ce96cf426caef131809c61a31976caeb643c535
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 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 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 AddToTLDataStrW(tld, bstrParamNames[j+1]);
705 SysFreeString(bstrParamNames[j+1]);
706 } else {
707 AddToTLDataStrW(tld, szRhs);
710 AddToTLDataStrW(tld, wszCloseBrackets2);
711 AddToTLDataStrW(tld, wszSemicolon);
712 AddToTLDataStrW(tld, wszNewLine);
714 SendMessageW(typelib.hTree, TVM_INSERTITEMW, 0, (LPARAM)&tvis);
715 HeapFree(GetProcessHeap(), 0, bstrParamNames);
716 SysFreeString(bstrName);
717 SysFreeString(bstrHelpString);
718 ITypeInfo_ReleaseFuncDesc(pTypeInfo, pFuncDesc);
721 return 0;
724 static int EnumImplTypes(ITypeInfo *pTypeInfo, int cImplTypes, HTREEITEM hParent)
726 int i;
727 TVINSERTSTRUCTW tvis;
728 ITypeInfo *pRefTypeInfo;
729 HREFTYPE hRefType;
730 TYPEATTR *pTypeAttr;
731 BSTR bstrName;
732 WCHAR wszInheritedInterfaces[MAX_LOAD_STRING];
734 if(!cImplTypes) return 0;
736 LoadStringW(globals.hMainInst, IDS_INHERITINTERFACES, wszInheritedInterfaces,
737 sizeof(wszInheritedInterfaces)/sizeof(wszInheritedInterfaces[0]));
739 U(tvis).item.mask = TVIF_TEXT;
740 U(tvis).item.cchTextMax = MAX_LOAD_STRING;
741 U(tvis).item.pszText = wszInheritedInterfaces;
742 tvis.hInsertAfter = TVI_LAST;
743 tvis.hParent = hParent;
745 tvis.hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
747 for(i=0; i<cImplTypes; i++)
749 if(FAILED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo, i, &hRefType))) continue;
750 if(FAILED(ITypeInfo_GetRefTypeInfo(pTypeInfo, hRefType, &pRefTypeInfo)))
751 continue;
752 if(FAILED(ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL, &bstrName,
753 NULL, NULL, NULL)))
755 ITypeInfo_Release(pRefTypeInfo);
756 continue;
758 if(FAILED(ITypeInfo_GetTypeAttr(pRefTypeInfo, &pTypeAttr)))
760 ITypeInfo_Release(pRefTypeInfo);
761 continue;
764 U(tvis).item.cchTextMax = SysStringLen(bstrName);
765 U(tvis).item.pszText = bstrName;
767 hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
768 EnumVars(pRefTypeInfo, pTypeAttr->cVars, hParent);
769 EnumFuncs(pRefTypeInfo, pTypeAttr, hParent);
770 EnumImplTypes(pRefTypeInfo, pTypeAttr->cImplTypes, hParent);
772 SysFreeString(bstrName);
773 ITypeInfo_ReleaseTypeAttr(pRefTypeInfo, pTypeAttr);
774 ITypeInfo_Release(pRefTypeInfo);
777 return 0;
780 static void EnumCoclassImplTypes(ITypeInfo *pTypeInfo,
781 int cImplTypes, TYPELIB_DATA *pTLData)
783 int i;
784 ITypeInfo *pRefTypeInfo;
785 HREFTYPE hRefType;
786 TYPEATTR *pTypeAttr;
787 BSTR bstrName;
788 BOOL bFirst;
789 INT flags;
790 const WCHAR wszTKIND_INTERFACE[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' };
791 const WCHAR wszTKIND_DISPATCH[]
792 = { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' };
793 const WCHAR wszIMPLTYPEFLAG_FDEFAULT[]
794 = { 'd','e','f','a','u','l','t','\0' };
795 const WCHAR wszIMPLTYPEFLAG_FSOURCE[]
796 = { 's','o','u','r','c','e','\0' };
797 const WCHAR wszIMPLTYPEFLAG_FRESTRICTED[]
798 = { 'r','e','s','t','r','i','c','t','e','d','\0' };
800 for(i=0; i<cImplTypes; i++)
802 if(FAILED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo, i, &hRefType))) continue;
803 if(FAILED(ITypeInfo_GetRefTypeInfo(pTypeInfo, hRefType, &pRefTypeInfo)))
804 continue;
805 if(FAILED(ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL, &bstrName,
806 NULL, NULL, NULL)))
808 ITypeInfo_Release(pRefTypeInfo);
809 continue;
811 if(FAILED(ITypeInfo_GetTypeAttr(pRefTypeInfo, &pTypeAttr)))
813 ITypeInfo_Release(pRefTypeInfo);
814 continue;
817 AddSpaces(pTLData, TAB_SIZE);
818 ITypeInfo_GetImplTypeFlags(pTypeInfo, i, &flags);
819 bFirst = TRUE;
820 #define ENUM_IMPLTYPEFLAG(x)\
821 if(flags & x) \
823 if(bFirst) AddToTLDataStrW(pTLData,\
824 wszOpenBrackets1);\
825 else\
827 AddToTLDataStrW(pTLData, wszComa);\
828 AddToTLDataStrW(pTLData, wszSpace);\
830 bFirst = FALSE;\
831 AddToTLDataStrW(pTLData, wsz##x);\
833 ENUM_IMPLTYPEFLAG(IMPLTYPEFLAG_FDEFAULT);
834 ENUM_IMPLTYPEFLAG(IMPLTYPEFLAG_FSOURCE);
835 ENUM_IMPLTYPEFLAG(IMPLTYPEFLAG_FRESTRICTED);
836 if(!bFirst)
838 AddToTLDataStrW(pTLData, wszCloseBrackets1);
839 AddToTLDataStrW(pTLData, wszSpace);
842 if(pTypeAttr->typekind == TKIND_INTERFACE ||
843 (pTypeAttr->wTypeFlags & TYPEFLAG_FDUAL))
844 AddToTLDataStrW(pTLData, wszTKIND_INTERFACE);
845 else if(pTypeAttr->typekind == TKIND_DISPATCH)
846 AddToTLDataStrW(pTLData, wszTKIND_DISPATCH);
847 AddToTLDataStrW(pTLData, wszSpace);
849 AddToTLDataStrW(pTLData, bstrName);
850 AddToTLDataStrW(pTLData, wszSemicolon);
851 AddToTLDataStrW(pTLData, wszNewLine);
853 SysFreeString(bstrName);
854 ITypeInfo_ReleaseTypeAttr(pRefTypeInfo, pTypeAttr);
855 ITypeInfo_Release(pRefTypeInfo);
859 static void AddIdlData(HTREEITEM hCur, TYPELIB_DATA *pTLData)
861 TVITEMW tvi;
863 hCur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
864 TVGN_CHILD, (LPARAM)hCur);
865 memset(&tvi, 0, sizeof(TVITEMW));
866 tvi.mask = TVIF_PARAM;
868 while(hCur)
870 tvi.hItem = hCur;
871 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
872 if(!((TYPELIB_DATA*)(tvi.lParam))->bHide) {
873 AddToTLDataStrW(pTLData, wszNewLine);
874 AddToTLDataStrWithTabsW(pTLData, ((TYPELIB_DATA*)(tvi.lParam))->idl);
876 hCur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
877 TVGN_NEXT, (LPARAM)hCur);
881 static void AddPredefinitions(HTREEITEM hFirst, TYPELIB_DATA *pTLData)
883 HTREEITEM hCur;
884 TVITEMW tvi;
885 WCHAR wszText[MAX_LOAD_STRING];
886 WCHAR wszPredefinition[] = { '/','/',' ','T','L','i','b',' ',':','\n',
887 '/','/',' ','F','o','r','w','a','r','d',' ','d','e','c','l','a','r','e',' ',
888 'a','l','l',' ','t','y','p','e','s',' ','d','e','f','i','n','e','d',' ',
889 'i','n',' ','t','h','i','s',' ','t','y','p','e','l','i','b','\0' };
891 hFirst = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
892 TVGN_CHILD, (LPARAM)hFirst);
894 AddToTLDataStrWithTabsW(pTLData, wszPredefinition);
895 AddToTLDataStrW(pTLData, wszNewLine);
897 hCur = hFirst;
898 memset(&tvi, 0, sizeof(TVITEMW));
899 tvi.mask = TVIF_TEXT|TVIF_PARAM;
900 tvi.cchTextMax = MAX_LOAD_STRING;
901 tvi.pszText = wszText;
902 while(hCur)
904 tvi.hItem = hCur;
905 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
906 if(((TYPELIB_DATA*)(tvi.lParam))->bPredefine &&
907 !((TYPELIB_DATA*)(tvi.lParam))->bHide)
909 AddToStrW(wszText, wszSemicolon);
910 AddToTLDataStrWithTabsW(pTLData, wszText);
911 AddToTLDataStrW(pTLData, wszNewLine);
913 hCur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
914 TVGN_NEXT, (LPARAM)hCur);
918 static void CreateInterfaceInfo(ITypeInfo *pTypeInfo, int cImplTypes, WCHAR *wszName,
919 WCHAR *wszHelpString, unsigned long ulHelpContext, TYPEATTR *pTypeAttr,
920 TYPELIB_DATA *pTLData)
922 ITypeInfo *pRefTypeInfo;
923 HREFTYPE hRefType;
924 BSTR bstrName;
925 WCHAR wszGuid[MAX_LOAD_STRING];
926 WCHAR wszHelpContext[MAX_LOAD_STRING];
928 const WCHAR wszInterface[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' };
929 const WCHAR wszDispinterface[]
930 = { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' };
931 const WCHAR wszHelpcontext[] = { 'h','e','l','p','c','o','n','t','e','x','t','\0' };
932 const WCHAR wszTYPEFLAG_FAPPOBJECT[] = { 'a','p','p','o','b','j','e','c','t','\0' };
933 const WCHAR wszTYPEFLAG_FCANCREATE[] = { 'c','a','n','c','r','e','a','t','e','\0' };
934 const WCHAR wszTYPEFLAG_FLICENSED[] = { 'l','i','c','e','n','s','e','d','\0' };
935 const WCHAR wszTYPEFLAG_FPREDECLID[] = { 'p','r','e','d','e','c','l','i','d','\0' };
936 const WCHAR wszTYPEFLAG_FHIDDEN[] = { 'h','i','d','d','e','n','\0' };
937 const WCHAR wszTYPEFLAG_FCONTROL[] = { 'c','o','n','t','r','o','l','\0' };
938 const WCHAR wszTYPEFLAG_FDUAL[] = { 'd','u','a','l','\0' };
939 const WCHAR wszTYPEFLAG_FNONEXTENSIBLE[]
940 = { 'n','o','n','e','x','t','e','n','s','i','b','l','e','\0' };
941 const WCHAR wszTYPEFLAG_FOLEAUTOMATION[]
942 = { 'o','l','e','a','u','t','o','m','a','t','i','o','n','\0' };
943 const WCHAR wszTYPEFLAG_FRESTRICTED[]
944 = { 'r','e','s','t','r','i','c','t','e','d','\0' };
945 const WCHAR wszTYPEFLAG_FAGGREGATABLE[]
946 = { 'a','g','g','r','e','g','a','t','a','b','l','e','\0' };
947 const WCHAR wszTYPEFLAG_FREPLACEABLE[]
948 = { 'r','e','p','l','a','c','a','b','l','e','\0' };
949 const WCHAR wszTYPEFLAG_FREVERSEBIND[]
950 = { 'r','e','v','e','r','s','e','b','i','n','d','\0' };
951 const WCHAR wszTYPEFLAG_FPROXY[] = { 'p','r','o','x','y','\0' };
953 AddToTLDataStrW(pTLData, wszOpenBrackets1);
954 AddToTLDataStrW(pTLData, wszNewLine);
955 if(pTypeAttr->typekind != TKIND_DISPATCH)
957 AddSpaces(pTLData, TAB_SIZE);
958 AddToTLDataStrW(pTLData, wszOdl);
959 AddToTLDataStrW(pTLData, wszComa);
960 AddToTLDataStrW(pTLData, wszNewLine);
962 AddSpaces(pTLData, TAB_SIZE);
963 AddToTLDataStrW(pTLData, wszUUID);
964 AddToTLDataStrW(pTLData, wszOpenBrackets2);
965 StringFromGUID2(&(pTypeAttr->guid), wszGuid, MAX_LOAD_STRING);
966 wszGuid[lstrlenW(wszGuid)-1] = '\0';
967 AddToTLDataStrW(pTLData, &wszGuid[1]);
968 AddToTLDataStrW(pTLData, wszCloseBrackets2);
969 if(wszHelpString)
971 AddToTLDataStrW(pTLData, wszComa);
972 AddToTLDataStrW(pTLData, wszNewLine);
973 AddSpaces(pTLData, TAB_SIZE);
974 AddToTLDataStrW(pTLData, wszHelpstring);
975 AddToTLDataStrW(pTLData, wszOpenBrackets2);
976 AddToTLDataStrW(pTLData, wszInvertedComa);
977 AddToTLDataStrW(pTLData, wszHelpString);
978 AddToTLDataStrW(pTLData, wszInvertedComa);
979 AddToTLDataStrW(pTLData, wszCloseBrackets2);
981 if(ulHelpContext)
983 AddToTLDataStrW(pTLData, wszComa);
984 AddToTLDataStrW(pTLData, wszNewLine);
985 AddSpaces(pTLData, TAB_SIZE);
986 AddToTLDataStrW(pTLData, wszHelpcontext);
987 AddToTLDataStrW(pTLData, wszOpenBrackets2);
988 wsprintfW(wszHelpContext, wszFormat, ulHelpContext);
989 AddToTLDataStrW(pTLData, wszHelpContext);
990 AddToTLDataStrW(pTLData, wszCloseBrackets2);
992 if(pTypeAttr->wTypeFlags)
994 #define ENUM_FLAGS(x) if(pTypeAttr->wTypeFlags & x)\
996 AddToTLDataStrW(pTLData, wszComa);\
997 AddToTLDataStrW(pTLData, wszNewLine);\
998 AddSpaces(pTLData, TAB_SIZE);\
999 AddToTLDataStrW(pTLData, wsz##x);\
1001 ENUM_FLAGS(TYPEFLAG_FAPPOBJECT);
1002 ENUM_FLAGS(TYPEFLAG_FCANCREATE);
1003 ENUM_FLAGS(TYPEFLAG_FLICENSED);
1004 ENUM_FLAGS(TYPEFLAG_FPREDECLID);
1005 ENUM_FLAGS(TYPEFLAG_FHIDDEN);
1006 ENUM_FLAGS(TYPEFLAG_FCONTROL);
1007 ENUM_FLAGS(TYPEFLAG_FDUAL);
1008 ENUM_FLAGS(TYPEFLAG_FNONEXTENSIBLE);
1009 ENUM_FLAGS(TYPEFLAG_FOLEAUTOMATION);
1010 ENUM_FLAGS(TYPEFLAG_FRESTRICTED);
1011 ENUM_FLAGS(TYPEFLAG_FAGGREGATABLE);
1012 ENUM_FLAGS(TYPEFLAG_FREPLACEABLE);
1013 ENUM_FLAGS(TYPEFLAG_FREVERSEBIND);
1014 ENUM_FLAGS(TYPEFLAG_FPROXY);
1016 AddToTLDataStrW(pTLData, wszNewLine);
1017 AddToTLDataStrW(pTLData, wszCloseBrackets1);
1018 AddToTLDataStrW(pTLData, wszNewLine);
1019 if(pTypeAttr->typekind != TKIND_DISPATCH) AddToTLDataStrW(pTLData, wszInterface);
1020 else AddToTLDataStrW(pTLData, wszDispinterface);
1021 AddToTLDataStrW(pTLData, wszName);
1022 AddToTLDataStrW(pTLData, wszSpace);
1023 if(cImplTypes && pTypeAttr->typekind != TKIND_DISPATCH)
1025 AddToTLDataStrW(pTLData, wszColon);
1026 AddToTLDataStrW(pTLData, wszSpace);
1028 ITypeInfo_GetRefTypeOfImplType(pTypeInfo, 0, &hRefType);
1029 if (SUCCEEDED(ITypeInfo_GetRefTypeInfo(pTypeInfo, hRefType, &pRefTypeInfo)))
1031 ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL, &bstrName,
1032 NULL, NULL, NULL);
1033 AddToTLDataStrW(pTLData, bstrName);
1034 AddToTLDataStrW(pTLData, wszSpace);
1036 SysFreeString(bstrName);
1037 ITypeInfo_Release(pRefTypeInfo);
1039 else
1040 AddToTLDataStrW(pTLData, wszFailed);
1042 AddToTLDataStrW(pTLData, wszOpenBrackets3);
1043 AddToTLDataStrW(pTLData, wszNewLine);
1045 AddToStrW(pTLData->wszInsertAfter, wszCloseBrackets3);
1046 AddToStrW(pTLData->wszInsertAfter, wszSemicolon);
1047 AddToStrW(pTLData->wszInsertAfter, wszNewLine);
1050 static void CreateTypedefHeader(ITypeInfo *pTypeInfo,
1051 TYPEATTR *pTypeAttr, TYPELIB_DATA *pTLData)
1053 BOOL bFirst = TRUE;
1054 WCHAR wszGuid[MAX_LOAD_STRING];
1055 const WCHAR wszTypedef[] = { 't','y','p','e','d','e','f',' ','\0' };
1056 const WCHAR wszPublic[] = { 'p','u','b','l','i','c','\0' };
1058 AddToTLDataStrW(pTLData, wszTypedef);
1059 if(memcmp(&pTypeAttr->guid, &GUID_NULL, sizeof(GUID)))
1061 AddToTLDataStrW(pTLData, wszOpenBrackets1);
1062 bFirst = FALSE;
1063 AddToTLDataStrW(pTLData, wszUUID);
1064 AddToTLDataStrW(pTLData, wszOpenBrackets2);
1065 StringFromGUID2(&(pTypeAttr->guid), wszGuid, MAX_LOAD_STRING);
1066 wszGuid[lstrlenW(wszGuid)-1] = '\0';
1067 AddToTLDataStrW(pTLData, &wszGuid[1]);
1068 AddToTLDataStrW(pTLData, wszCloseBrackets2);
1070 if(pTypeAttr->typekind == TKIND_ALIAS)
1072 if(bFirst) AddToTLDataStrW(pTLData, wszOpenBrackets1);
1073 else
1075 AddToTLDataStrW(pTLData, wszComa);
1076 AddToTLDataStrW(pTLData, wszSpace);
1078 bFirst = FALSE;
1079 AddToTLDataStrW(pTLData, wszPublic);
1081 if(!bFirst)
1083 AddToTLDataStrW(pTLData, wszCloseBrackets1);
1084 AddToTLDataStrW(pTLData, wszNewLine);
1088 static void CreateCoclassHeader(ITypeInfo *pTypeInfo,
1089 TYPEATTR *pTypeAttr, TYPELIB_DATA *pTLData)
1091 WCHAR wszGuid[MAX_LOAD_STRING];
1092 BSTR bstrHelpString;
1093 const WCHAR wszNoncreatable[]
1094 = { 'n','o','n','c','r','e','a','t','a','b','l','e','\0' };
1096 AddToTLDataStrW(pTLData, wszOpenBrackets1);
1097 AddToTLDataStrW(pTLData, wszNewLine);
1099 AddSpaces(pTLData, TAB_SIZE);
1100 AddToTLDataStrW(pTLData, wszUUID);
1101 AddToTLDataStrW(pTLData, wszOpenBrackets2);
1102 StringFromGUID2(&(pTypeAttr->guid), wszGuid, MAX_LOAD_STRING);
1103 wszGuid[lstrlenW(wszGuid)-1] = '\0';
1104 AddToTLDataStrW(pTLData, &wszGuid[1]);
1105 AddToTLDataStrW(pTLData, wszCloseBrackets2);
1107 if(SUCCEEDED(ITypeInfo_GetDocumentation(pTypeInfo, MEMBERID_NIL, NULL,
1108 &bstrHelpString, NULL, NULL)))
1110 if(SysStringLen(bstrHelpString))
1112 AddToTLDataStrW(pTLData, wszComa);
1113 AddToTLDataStrW(pTLData, wszNewLine);
1114 AddSpaces(pTLData, TAB_SIZE);
1115 AddToTLDataStrW(pTLData, wszHelpstring);
1116 AddToTLDataStrW(pTLData, wszOpenBrackets2);
1117 AddToTLDataStrW(pTLData, wszInvertedComa);
1118 AddToTLDataStrW(pTLData, bstrHelpString);
1119 AddToTLDataStrW(pTLData, wszInvertedComa);
1120 AddToTLDataStrW(pTLData, wszCloseBrackets2);
1122 SysFreeString(bstrHelpString);
1125 if(!(pTypeAttr->wTypeFlags & TYPEFLAG_FCANCREATE))
1127 AddToTLDataStrW(pTLData, wszComa);
1128 AddToTLDataStrW(pTLData, wszNewLine);
1129 AddSpaces(pTLData, TAB_SIZE);
1130 AddToTLDataStrW(pTLData, wszNoncreatable);
1133 AddToTLDataStrW(pTLData, wszNewLine);
1134 AddToTLDataStrW(pTLData, wszCloseBrackets1);
1135 AddToTLDataStrW(pTLData, wszNewLine);
1138 static int PopulateTree(void)
1140 TVINSERTSTRUCTW tvis;
1141 TVITEMW tvi;
1142 ITypeLib *pTypeLib;
1143 TLIBATTR *pTLibAttr;
1144 ITypeInfo *pTypeInfo, *pRefTypeInfo;
1145 HREFTYPE hRefType;
1146 TYPEATTR *pTypeAttr;
1147 INT count, i;
1148 ULONG ulHelpContext;
1149 BSTR bstrName;
1150 BSTR bstrData;
1151 WCHAR wszText[MAX_LOAD_STRING];
1152 WCHAR wszAfter[MAX_LOAD_STRING];
1153 HRESULT hRes;
1154 HTREEITEM hParent;
1155 HTREEITEM hMain;
1156 BOOL bInsert;
1157 TYPELIB_DATA *tldDispatch;
1158 TYPELIB_DATA *tld;
1160 const WCHAR wszGeneratedInfo[] = { '/','/',' ','G','e','n','e','r','a','t','e','d',
1161 ' ','.','I','D','L',' ','f','i','l','e',' ','(','b','y',' ','t','h','e',' ',
1162 'O','L','E','/','C','O','M',' ','O','b','j','e','c','t',' ',
1163 'V','i','e','w','e','r',')','\n','/','/','\n','/','/',' ',
1164 't','y','p','e','l','i','b',' ','f','i','l','e','n','a','m','e',':',' ','\0'};
1166 const WCHAR wszFormat[] = { '%','s',' ','(','%','s',')','\0' };
1167 const WCHAR wszFormat2[] = { 'v','e','r','s','i','o','n',
1168 '(','%','l','d','.','%','l','d',')','\0' };
1170 const WCHAR wszTKIND_ENUM[] = { 't','y','p','e','d','e','f',' ','e','n','u','m',' ','\0' };
1171 const WCHAR wszTKIND_RECORD[]
1172 = { 't','y','p','e','d','e','f',' ','s','t','r','u','c','t',' ','\0' };
1173 const WCHAR wszTKIND_MODULE[] = { 'm','o','d','u','l','e',' ','\0' };
1174 const WCHAR wszTKIND_INTERFACE[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' };
1175 const WCHAR wszTKIND_DISPATCH[]
1176 = { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' };
1177 const WCHAR wszTKIND_COCLASS[] = { 'c','o','c','l','a','s','s',' ','\0' };
1178 const WCHAR wszTKIND_ALIAS[] = { 't','y','p','e','d','e','f',' ','\0' };
1179 const WCHAR wszTKIND_UNION[]
1180 = { 't','y','p','e','d','e','f',' ','u','n','i','o','n',' ','\0' };
1182 const WCHAR wszLibrary[] = { 'l','i','b','r','a','r','y',' ','\0' };
1183 const WCHAR wszTag[] = { 't','a','g','\0' };
1185 WCHAR wszProperties[] = { 'p','r','o','p','e','r','t','i','e','s','\0' };
1186 WCHAR wszMethods[] = { 'm','e','t','h','o','d','s','\0' };
1188 U(tvis).item.mask = TVIF_TEXT|TVIF_PARAM;
1189 U(tvis).item.cchTextMax = MAX_LOAD_STRING;
1190 U(tvis).item.pszText = wszText;
1191 tvis.hInsertAfter = TVI_LAST;
1192 tvis.hParent = TVI_ROOT;
1194 if(FAILED((hRes = LoadTypeLib(typelib.wszFileName, &pTypeLib))))
1196 WCHAR wszMessage[MAX_LOAD_STRING];
1197 WCHAR wszError[MAX_LOAD_STRING];
1199 LoadStringW(globals.hMainInst, IDS_ERROR_LOADTYPELIB,
1200 wszError, sizeof(wszError)/sizeof(wszError[0]));
1201 wsprintfW(wszMessage, wszError, typelib.wszFileName, hRes);
1202 MessageBoxW(globals.hMainWnd, wszMessage, NULL, MB_OK|MB_ICONEXCLAMATION);
1203 return 1;
1205 count = ITypeLib_GetTypeInfoCount(pTypeLib);
1207 ITypeLib_GetDocumentation(pTypeLib, -1, &bstrName, &bstrData, NULL, NULL);
1208 ITypeLib_GetLibAttr(pTypeLib, &pTLibAttr);
1210 tld = InitializeTLData();
1211 U(tvis).item.lParam = (LPARAM) tld;
1212 AddToTLDataStrW(tld, wszGeneratedInfo);
1213 AddToTLDataStrW(tld, typelib.wszFileName);
1214 AddToTLDataStrW(tld, wszNewLine);
1215 AddToTLDataStrW(tld, wszNewLine);
1216 AddToTLDataStrW(tld, wszOpenBrackets1);
1217 AddToTLDataStrW(tld, wszNewLine);
1218 AddSpaces(tld, TAB_SIZE);
1219 AddToTLDataStrW(tld, wszUUID);
1220 AddToTLDataStrW(tld, wszOpenBrackets2);
1221 StringFromGUID2(&(pTLibAttr->guid), wszText, MAX_LOAD_STRING);
1222 wszText[lstrlenW(wszText)-1] = '\0';
1223 AddToTLDataStrW(tld, &wszText[1]);
1224 AddToTLDataStrW(tld, wszCloseBrackets2);
1225 AddToTLDataStrW(tld, wszComa);
1226 AddToTLDataStrW(tld, wszNewLine);
1227 AddSpaces(tld, TAB_SIZE);
1228 wsprintfW(wszText, wszFormat2, pTLibAttr->wMajorVerNum, pTLibAttr->wMinorVerNum);
1229 AddToTLDataStrW(tld, wszText);
1230 AddToTLDataStrW(tld, wszComa);
1231 AddToTLDataStrW(tld, wszNewLine);
1232 AddSpaces(tld, TAB_SIZE);
1233 AddToTLDataStrW(tld, wszHelpstring);
1234 AddToTLDataStrW(tld, wszOpenBrackets2);
1235 AddToTLDataStrW(tld, wszInvertedComa);
1236 AddToTLDataStrW(tld, bstrData);
1237 AddToTLDataStrW(tld, wszInvertedComa);
1238 AddToTLDataStrW(tld, wszCloseBrackets2);
1239 AddToTLDataStrW(tld, wszNewLine);
1240 AddToTLDataStrW(tld, wszCloseBrackets1);
1241 AddToTLDataStrW(tld, wszNewLine);
1242 AddToTLDataStrW(tld, wszLibrary);
1243 AddToTLDataStrW(tld, bstrName);
1244 AddToTLDataStrW(tld, wszNewLine);
1245 AddToTLDataStrW(tld, wszOpenBrackets3);
1246 AddToTLDataStrW(tld, wszNewLine);
1248 AddToStrW(tld->wszInsertAfter, wszCloseBrackets3);
1249 AddToStrW(tld->wszInsertAfter, wszSemicolon);
1251 wsprintfW(wszText, wszFormat, bstrName, bstrData);
1252 SysFreeString(bstrName);
1253 SysFreeString(bstrData);
1254 tvis.hParent = (HTREEITEM)SendMessageW(typelib.hTree,
1255 TVM_INSERTITEMW, 0, (LPARAM)&tvis);
1257 for(i=0; i<count; i++)
1259 bInsert = TRUE;
1260 ITypeLib_GetTypeInfo(pTypeLib, i, &pTypeInfo);
1262 ITypeInfo_GetDocumentation(pTypeInfo, MEMBERID_NIL, &bstrName, &bstrData,
1263 &ulHelpContext, NULL);
1264 ITypeInfo_GetTypeAttr(pTypeInfo, &pTypeAttr);
1266 memset(wszText, 0, sizeof(wszText));
1267 memset(wszAfter, 0, sizeof(wszAfter));
1268 tld = InitializeTLData();
1269 U(tvis).item.lParam = (LPARAM)tld;
1270 switch(pTypeAttr->typekind)
1272 case TKIND_ENUM:
1273 AddToStrW(wszText, wszTKIND_ENUM);
1274 AddToStrW(wszText, bstrName);
1276 CreateTypedefHeader(pTypeInfo, pTypeAttr, tld);
1277 AddToTLDataStrW(tld, &wszTKIND_ENUM[lstrlenW(wszTKIND_ALIAS)]);
1278 AddToTLDataStrW(tld, wszOpenBrackets3);
1279 AddToTLDataStrW(tld,wszNewLine);
1280 AddToStrW(tld->wszInsertAfter, wszCloseBrackets3);
1281 AddToStrW(tld->wszInsertAfter, wszSpace);
1282 AddToStrW(tld->wszInsertAfter, bstrName);
1283 AddToStrW(tld->wszInsertAfter, wszSemicolon);
1284 AddToStrW(tld->wszInsertAfter, wszNewLine);
1286 bInsert = FALSE;
1287 hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1288 EnumEnums(pTypeInfo, pTypeAttr->cVars, hParent);
1289 AddChildrenData(hParent, tld);
1290 AddToTLDataStrW(tld, tld->wszInsertAfter);
1291 break;
1292 case TKIND_RECORD:
1293 AddToTLDataStrW(tld, wszTKIND_RECORD);
1294 AddToTLDataStrW(tld, wszTag);
1295 AddToTLDataStrW(tld, bstrName);
1296 AddToTLDataStrW(tld, wszSpace);
1297 AddToTLDataStrW(tld, wszOpenBrackets3);
1298 AddToTLDataStrW(tld, wszNewLine);
1300 AddToStrW(tld->wszInsertAfter, wszCloseBrackets3);
1301 AddToStrW(tld->wszInsertAfter, wszSpace);
1302 AddToStrW(tld->wszInsertAfter, bstrName);
1303 AddToStrW(tld->wszInsertAfter, wszSemicolon);
1304 AddToStrW(tld->wszInsertAfter, wszNewLine);
1306 AddToStrW(wszText, wszTKIND_RECORD);
1307 AddToStrW(wszText, bstrName);
1308 break;
1309 case TKIND_MODULE:
1310 AddToStrW(wszText, wszTKIND_MODULE);
1311 AddToStrW(wszText, bstrName);
1312 break;
1313 case TKIND_INTERFACE:
1314 CreateInterfaceInfo(pTypeInfo, pTypeAttr->cImplTypes, bstrName,
1315 bstrData, ulHelpContext, pTypeAttr, tld);
1316 tld->bPredefine = TRUE;
1318 AddToStrW(wszText, wszTKIND_INTERFACE);
1319 AddToStrW(wszText, bstrName);
1320 break;
1321 case TKIND_COCLASS:
1322 AddToStrW(wszText, wszTKIND_COCLASS);
1323 AddToStrW(wszText, bstrName);
1325 CreateCoclassHeader(pTypeInfo, pTypeAttr, tld);
1326 AddToTLDataStrW(tld, wszTKIND_COCLASS);
1327 AddToTLDataStrW(tld, bstrName);
1328 AddToTLDataStrW(tld, wszSpace);
1329 AddToTLDataStrW(tld, wszOpenBrackets3);
1330 AddToTLDataStrW(tld, wszNewLine);
1332 EnumCoclassImplTypes(pTypeInfo, pTypeAttr->cImplTypes, tld);
1334 AddToStrW(tld->wszInsertAfter, wszCloseBrackets3);
1335 AddToStrW(tld->wszInsertAfter, wszSemicolon);
1336 AddToStrW(tld->wszInsertAfter, wszNewLine);
1338 bInsert = FALSE;
1339 hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1340 AddToTLDataStrW(tld, tld->wszInsertAfter);
1341 break;
1342 case TKIND_UNION:
1343 AddToStrW(wszText, wszTKIND_UNION);
1344 AddToStrW(wszText, bstrName);
1345 break;
1346 case TKIND_DISPATCH:
1347 CreateInterfaceInfo(pTypeInfo, pTypeAttr->cImplTypes, bstrName,
1348 bstrData, ulHelpContext, pTypeAttr, tld);
1349 tld->bPredefine = TRUE;
1350 if(pTypeAttr->wTypeFlags & TYPEFLAG_FDUAL)
1351 tld->bHide = TRUE;
1352 AddToStrW(wszText, wszTKIND_DISPATCH);
1353 AddToStrW(wszText, bstrName);
1355 hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1356 hMain = tvis.hParent;
1357 tldDispatch = tld;
1359 lstrcpyW(wszText, wszProperties);
1360 tvis.hParent = hParent;
1361 tld = InitializeTLData();
1362 U(tvis).item.lParam = (LPARAM) tld;
1363 AddToTLDataStrW(tld, wszProperties);
1364 AddToTLDataStrW(tld, wszColon);
1365 AddToTLDataStrW(tld, wszNewLine);
1366 tvis.hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1367 EnumVars(pTypeInfo, pTypeAttr->cVars, tvis.hParent);
1368 AddChildrenData(tvis.hParent, tld);
1370 lstrcpyW(wszText, wszMethods);
1371 tvis.hParent = hParent;
1372 tld = InitializeTLData();
1373 U(tvis).item.lParam = (LPARAM) tld;
1374 AddToTLDataStrW(tld, wszMethods);
1375 AddToTLDataStrW(tld, wszColon);
1376 AddToTLDataStrW(tld, wszNewLine);
1377 tvis.hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1378 EnumFuncs(pTypeInfo, pTypeAttr, tvis.hParent);
1379 AddChildrenData(tvis.hParent, tld);
1381 EnumImplTypes(pTypeInfo, pTypeAttr->cImplTypes, hParent);
1382 AddChildrenData(hParent, tldDispatch);
1383 AddToTLDataStrW(tldDispatch, tldDispatch->wszInsertAfter);
1385 bInsert = FALSE;
1386 tvis.hParent = hMain;
1388 if(SUCCEEDED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo, -1, &hRefType)))
1390 bInsert = TRUE;
1392 ITypeInfo_ReleaseTypeAttr(pTypeInfo, pTypeAttr);
1393 SysFreeString(bstrName);
1394 SysFreeString(bstrData);
1396 memset(wszText, 0, sizeof(wszText));
1397 tld = InitializeTLData();
1398 U(tvis).item.lParam = (LPARAM) tld;
1400 ITypeInfo_GetRefTypeInfo(pTypeInfo, hRefType, &pRefTypeInfo);
1401 ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL, &bstrName,
1402 &bstrData, &ulHelpContext, NULL);
1403 ITypeInfo_GetTypeAttr(pRefTypeInfo, &pTypeAttr);
1405 CreateInterfaceInfo(pTypeInfo, pTypeAttr->cImplTypes, bstrName,
1406 bstrData, ulHelpContext, pTypeAttr, tld);
1407 tld->bPredefine = TRUE;
1409 AddToStrW(wszText, wszTKIND_INTERFACE);
1410 AddToStrW(wszText, bstrName);
1411 ITypeInfo_Release(pRefTypeInfo);
1413 break;
1414 case TKIND_ALIAS:
1415 AddToStrW(wszText, wszTKIND_ALIAS);
1416 CreateTypeInfo(wszText, wszAfter, pTypeAttr->tdescAlias, pTypeInfo);
1417 AddToStrW(wszText, wszSpace);
1418 AddToStrW(wszText, bstrName);
1419 AddToStrW(wszText, wszAfter);
1421 CreateTypedefHeader(pTypeInfo, pTypeAttr, tld);
1422 AddToTLDataStrW(tld, &wszText[lstrlenW(wszTKIND_ALIAS)]);
1423 AddToTLDataStrW(tld, wszSemicolon);
1424 AddToTLDataStrW(tld, wszNewLine);
1425 break;
1426 default:
1427 lstrcpyW(wszText, bstrName);
1428 WINE_FIXME("pTypeAttr->typekind == %d not supported\n",
1429 pTypeAttr->typekind);
1432 if(bInsert)
1434 hParent = TreeView_InsertItemW(typelib.hTree, &tvis);
1436 EnumVars(pTypeInfo, pTypeAttr->cVars, hParent);
1437 EnumFuncs(pTypeInfo, pTypeAttr, hParent);
1438 EnumImplTypes(pTypeInfo, pTypeAttr->cImplTypes, hParent);
1440 if(memcmp(bstrName, wszVT_UNKNOWN, sizeof(wszVT_UNKNOWN)))
1441 AddChildrenData(hParent, tld);
1442 AddToTLDataStrW(tld, tld->wszInsertAfter);
1445 ITypeInfo_ReleaseTypeAttr(pTypeInfo, pTypeAttr);
1446 ITypeInfo_Release(pTypeInfo);
1447 SysFreeString(bstrName);
1448 SysFreeString(bstrData);
1450 SendMessageW(typelib.hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)tvis.hParent);
1452 memset(&tvi, 0, sizeof(TVITEMW));
1453 tvi.mask = TVIF_PARAM;
1454 tvi.hItem = tvis.hParent;
1456 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
1457 AddPredefinitions(tvi.hItem, (TYPELIB_DATA*)(tvi.lParam));
1458 AddIdlData(tvi.hItem, (TYPELIB_DATA*)(tvi.lParam));
1459 AddToTLDataStrW((TYPELIB_DATA*)(tvi.lParam),
1460 ((TYPELIB_DATA*)(tvi.lParam))->wszInsertAfter);
1462 ITypeLib_Release(pTypeLib);
1463 return 0;
1466 void UpdateData(HTREEITEM item)
1468 TVITEMW tvi;
1470 memset(&tvi, 0, sizeof(TVITEMW));
1471 tvi.mask = TVIF_PARAM;
1472 tvi.hItem = item;
1474 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
1475 if(!tvi.lParam)
1477 SetWindowTextW(typelib.hEdit, wszSpace);
1478 return;
1481 SetWindowTextW(typelib.hEdit, ((TYPELIB_DATA*)tvi.lParam)->idl);
1484 static void TypeLibResizeChild(void)
1486 RECT client, stat;
1488 MoveWindow(typelib.hStatusBar, 0, 0, 0, 0, TRUE);
1490 if(IsWindowVisible(typelib.hStatusBar))
1491 GetClientRect(typelib.hStatusBar, &stat);
1492 else stat.bottom = 0;
1494 GetClientRect(globals.hTypeLibWnd, &client);
1495 MoveWindow(typelib.hPaneWnd, 0, 0,
1496 client.right, client.bottom-stat.bottom, TRUE);
1499 static void TypeLibMenuCommand(WPARAM wParam, HWND hWnd)
1501 BOOL vis;
1503 switch(wParam)
1505 case IDM_SAVEAS:
1506 GetSaveIdlAsPath();
1507 break;
1508 case IDM_STATUSBAR:
1509 vis = IsWindowVisible(typelib.hStatusBar);
1510 ShowWindow(typelib.hStatusBar, vis ? SW_HIDE : SW_SHOW);
1511 CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
1512 vis ? MF_UNCHECKED : MF_CHECKED);
1513 TypeLibResizeChild();
1514 break;
1515 case IDM_CLOSE:
1516 DestroyWindow(hWnd);
1517 break;
1521 static void UpdateTypeLibStatusBar(int itemID)
1523 WCHAR info[MAX_LOAD_STRING];
1525 if(!LoadStringW(globals.hMainInst, itemID, info, sizeof(info)/sizeof(info[0])))
1526 LoadStringW(globals.hMainInst, IDS_READY, info, sizeof(info)/sizeof(info[0]));
1528 SendMessageW(typelib.hStatusBar, SB_SETTEXTW, 0, (LPARAM)info);
1531 static void EmptyTLTree(void)
1533 HTREEITEM cur, del;
1534 TVITEMW tvi;
1536 tvi.mask = TVIF_PARAM;
1537 cur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
1538 TVGN_CHILD, (LPARAM)TVI_ROOT);
1540 while(TRUE)
1542 del = cur;
1543 cur = (HTREEITEM)SendMessageW(typelib.hTree, TVM_GETNEXTITEM,
1544 TVGN_CHILD, (LPARAM)del);
1546 if(!cur) cur = (HTREEITEM)SendMessageW(typelib.hTree,
1547 TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)del);
1548 if(!cur) cur = (HTREEITEM)SendMessageW(typelib.hTree,
1549 TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)del);
1551 tvi.hItem = del;
1552 SendMessageW(typelib.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
1553 if(tvi.lParam)
1555 HeapFree(GetProcessHeap(), 0, ((TYPELIB_DATA *)tvi.lParam)->idl);
1556 HeapFree(GetProcessHeap(), 0, (TYPELIB_DATA *)tvi.lParam);
1559 SendMessageW(typelib.hTree, TVM_DELETEITEM, 0, (LPARAM)del);
1561 if(!cur) break;
1565 static LRESULT CALLBACK TypeLibProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1567 switch(uMsg)
1569 case WM_CREATE:
1571 if(!CreatePanedWindow(hWnd, &typelib.hPaneWnd, globals.hMainInst))
1572 DestroyWindow(hWnd);
1573 typelib.hTree = CreateWindowExW(WS_EX_CLIENTEDGE, WC_TREEVIEWW, NULL,
1574 WS_CHILD|WS_VISIBLE|TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT,
1575 0, 0, 0, 0, typelib.hPaneWnd, (HMENU)TYPELIB_TREE,
1576 globals.hMainInst, NULL);
1577 typelib.hEdit = CreateWindowExW(WS_EX_CLIENTEDGE, WC_EDITW, NULL,
1578 WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_READONLY|WS_HSCROLL|WS_VSCROLL,
1579 0, 0, 0, 0, typelib.hPaneWnd, NULL, globals.hMainInst, NULL);
1581 SetLeft(typelib.hPaneWnd, typelib.hTree);
1582 SetRight(typelib.hPaneWnd, typelib.hEdit);
1584 if(PopulateTree()) DestroyWindow(hWnd);
1585 else SetFocus(typelib.hTree);
1586 break;
1588 case WM_COMMAND:
1589 TypeLibMenuCommand(LOWORD(wParam), hWnd);
1590 case WM_MENUSELECT:
1591 UpdateTypeLibStatusBar(LOWORD(wParam));
1592 break;
1593 case WM_SETFOCUS:
1594 SetFocus(typelib.hTree);
1595 break;
1596 case WM_SIZE:
1597 if(wParam == SIZE_MINIMIZED) break;
1598 TypeLibResizeChild();
1599 break;
1600 case WM_DESTROY:
1601 EmptyTLTree();
1602 break;
1603 default:
1604 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
1606 return 0;
1609 BOOL TypeLibRegisterClassW(void)
1611 WNDCLASSW wcc;
1613 memset(&wcc, 0, sizeof(WNDCLASSW));
1614 wcc.lpfnWndProc = TypeLibProc;
1615 wcc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
1616 wcc.lpszMenuName = MAKEINTRESOURCEW(IDM_TYPELIB);
1617 wcc.lpszClassName = wszTypeLib;
1619 if(!RegisterClassW(&wcc))
1620 return FALSE;
1622 return TRUE;
1625 BOOL CreateTypeLibWindow(HINSTANCE hInst, WCHAR *wszFileName)
1627 WCHAR wszTitle[MAX_LOAD_STRING];
1628 LoadStringW(hInst, IDS_TYPELIBTITLE, wszTitle, sizeof(wszTitle)/sizeof(wszTitle[0]));
1630 if(wszFileName) lstrcpyW(typelib.wszFileName, wszFileName);
1631 else
1633 TVITEMW tvi;
1635 memset(&tvi, 0, sizeof(TVITEMW));
1636 tvi.hItem = (HTREEITEM)SendMessageW(globals.hTree, TVM_GETNEXTITEM,
1637 TVGN_CARET, 0);
1639 SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
1640 lstrcpyW(typelib.wszFileName, ((ITEM_INFO*)tvi.lParam)->path);
1643 globals.hTypeLibWnd = CreateWindowW(wszTypeLib, wszTitle,
1644 WS_OVERLAPPEDWINDOW|WS_VISIBLE,
1645 CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInst, NULL);
1646 if(!globals.hTypeLibWnd) return FALSE;
1648 typelib.hStatusBar = CreateStatusWindowW(WS_VISIBLE|WS_CHILD,
1649 wszTitle, globals.hTypeLibWnd, 0);
1651 TypeLibResizeChild();
1652 return TRUE;