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
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(oleview
);
28 static const WCHAR wszTypeLib
[] = { 'T','Y','P','E','L','I','B','\0' };
30 static const WCHAR wszFailed
[] = { '<','f','a','i','l','e','d','>','\0' };
32 static const WCHAR wszUUID
[] = { 'u','u','i','d','\0' };
33 static const WCHAR wszOdl
[] = { 'o','d','l','\0' };
35 static const WCHAR wszVT_BOOL
[]
36 = { 'V','A','R','I','A','N','T','_','B','O','O','L','\0' };
37 static const WCHAR wszVT_UI1
[]
38 = { 'u','n','s','i','g','n','e','d',' ','c','h','a','r','\0' };
39 static const WCHAR wszVT_UI2
[]
40 = { 'u','n','s','i','g','n','e','d',' ','s','h','o','r','t','\0' };
41 static const WCHAR wszVT_UI4
[]
42 = { 'u','n','s','i','g','n','e','d',' ','l','o','n','g','\0' };
43 static const WCHAR wszVT_UI8
[] = { 'u','i','n','t','6','4','\0' };
44 static const WCHAR wszVT_UINT
[]
45 = { 'u','n','s','i','g','n','e','d',' ','i','n','t','\0' };
46 static const WCHAR wszVT_I1
[] = { 'c','h','a','r','\0' };
47 static const WCHAR wszVT_I2
[] = { 's','h','o','r','t','\0' };
48 static const WCHAR wszVT_I4
[] = { 'l','o','n','g','\0' };
49 static const WCHAR wszVT_I8
[] = { 'i','n','t','6','4','\0' };
50 static const WCHAR wszVT_R4
[] = { 's','i','n','g','l','e','\0' };
51 static const WCHAR wszVT_INT
[] = { 'i','n','t','\0' };
52 static const WCHAR wszVT_BSTR
[] = { 'B','S','T','R','\0' };
53 static const WCHAR wszVT_CY
[] = { 'C','U','R','R','E','N','C','Y','\0' };
54 static const WCHAR wszVT_VARIANT
[] = { 'V','A','R','I','A','N','T','\0' };
55 static const WCHAR wszVT_VOID
[] = { 'v','o','i','d','\0' };
56 static const WCHAR wszVT_ERROR
[] = { 'S','C','O','D','E','\0' };
57 static const WCHAR wszVT_LPSTR
[] = { 'L','P','S','T','R','\0' };
58 static const WCHAR wszVT_LPWSTR
[] = { 'L','P','W','S','T','R','\0' };
59 static const WCHAR wszVT_HRESULT
[] = { 'H','R','E','S','U','L','T','\0' };
60 static const WCHAR wszVT_UNKNOWN
[] = { 'I','U','n','k','n','o','w','n','\0' };
61 static const WCHAR wszVT_DISPATCH
[] = { 'I','D','i','s','p','a','t','c','h','\0' };
62 static const WCHAR wszVT_DATE
[] = { 'D','A','T','E','\0' };
63 static const WCHAR wszVT_R8
[] = { 'd','o','u','b','l','e','\0' };
64 static const WCHAR wszVT_SAFEARRAY
[] = { 'S','A','F','E','A','R','R','A','Y','\0' };
66 static const WCHAR wszFormat
[] = { '0','x','%','.','8','l','x','\0' };
67 static const WCHAR wszStdCall
[] = { '_','s','t','d','c','a','l','l','\0' };
68 static const WCHAR wszId
[] = { 'i','d','\0' };
69 static const WCHAR wszHelpstring
[] = { 'h','e','l','p','s','t','r','i','n','g','\0' };
70 static const WCHAR wszPropPut
[] = { 'p','r','o','p','p','u','t','\0' };
71 static const WCHAR wszPropGet
[] = { 'p','r','o','p','g','e','t','\0' };
72 static const WCHAR wszPropPutRef
[] = { 'p','r','o','p','p','u','t','r','e','f','\0' };
73 static const WCHAR wszPARAMFLAG_FIN
[] = { 'i','n','\0' };
74 static const WCHAR wszPARAMFLAG_FOUT
[] = { 'o','u','t','\0' };
75 static const WCHAR wszPARAMFLAG_FLCID
[] = { 'c','i','d','\0' };
76 static const WCHAR wszPARAMFLAG_FRETVAL
[] = { 'r','e','t','v','a','l','\0' };
77 static const WCHAR wszPARAMFLAG_FOPT
[] = { 'o','p','t','i','o','n','a','l','\0' };
78 static const WCHAR wszPARAMFLAG_FHASCUSTDATA
[]
79 = { 'h','a','s','c','u','s','t','d','a','t','a','\0' };
80 static const WCHAR wszDefaultValue
[]
81 = { 'd','e','f','a','u','l','t','v','a','l','u','e','\0' };
83 static const WCHAR wszReadOnly
[] = { 'r','e','a','d','o','n','l','y','\0' };
84 static const WCHAR wszConst
[] = { 'c','o','n','s','t','\0' };
86 static void ShowLastError(void)
88 DWORD error
= GetLastError();
90 WCHAR wszTitle
[MAX_LOAD_STRING
];
92 LoadStringW(globals
.hMainInst
, IDS_TYPELIBTITLE
, wszTitle
, ARRAY_SIZE(wszTitle
));
93 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
94 NULL
, error
, 0, (LPWSTR
)&lpMsgBuf
, 0, NULL
);
95 MessageBoxW(NULL
, lpMsgBuf
, wszTitle
, MB_OK
| MB_ICONERROR
);
100 static void SaveIdl(WCHAR
*wszFileName
)
105 DWORD len
, dwNumWrite
;
109 hIDL
= (HTREEITEM
)SendMessageW(typelib
.hTree
, TVM_GETNEXTITEM
,
110 TVGN_CHILD
, (LPARAM
)TVI_ROOT
);
112 memset(&tvi
, 0, sizeof(TVITEMW
));
115 SendMessageW(typelib
.hTree
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
116 data
= (TYPELIB_DATA
*)tvi
.lParam
;
118 hFile
= CreateFileW(wszFileName
, GENERIC_WRITE
, FILE_SHARE_WRITE
,
119 NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
120 if(hFile
== INVALID_HANDLE_VALUE
)
126 len
= WideCharToMultiByte( CP_UTF8
, 0, data
->idl
, data
->idlLen
, NULL
, 0, NULL
, NULL
);
127 wszIdl
= HeapAlloc(GetProcessHeap(), 0, len
);
128 WideCharToMultiByte( CP_UTF8
, 0, data
->idl
, data
->idlLen
, wszIdl
, len
, NULL
, NULL
);
130 if(!WriteFile(hFile
, wszIdl
, len
, &dwNumWrite
, NULL
))
133 HeapFree(GetProcessHeap(), 0, wszIdl
);
137 static void GetSaveIdlAsPath(void)
139 OPENFILENAMEW saveidl
;
141 WCHAR wszPath
[MAX_LOAD_STRING
];
142 WCHAR wszDir
[MAX_LOAD_STRING
];
143 static const WCHAR wszDefaultExt
[] = { 'i','d','l',0 };
144 static const WCHAR wszIdlFiles
[] = { '*','.','i','d','l','\0','\0' };
146 memset(&saveidl
, 0, sizeof(saveidl
));
148 lstrcpyW(wszDir
, typelib
.wszFileName
);
149 pFileName
= wszDir
+ lstrlenW(wszDir
);
150 while(*pFileName
!= '.' && *pFileName
!= '\\' && *pFileName
!= '/'
151 && pFileName
> wszDir
) pFileName
-= 1;
152 if(*pFileName
== '.')
155 while(*pFileName
!= '\\' && *pFileName
!= '/' && pFileName
> wszDir
)
158 if(*pFileName
== '\\' || *pFileName
== '/') pFileName
+= 1;
159 lstrcpyW(wszPath
, pFileName
);
161 GetCurrentDirectoryW(MAX_LOAD_STRING
, wszDir
);
163 saveidl
.lStructSize
= sizeof(OPENFILENAMEW
);
164 saveidl
.hwndOwner
= globals
.hTypeLibWnd
;
165 saveidl
.hInstance
= globals
.hMainInst
;
166 saveidl
.lpstrFilter
= wszIdlFiles
;
167 saveidl
.lpstrFile
= wszPath
;
168 saveidl
.nMaxFile
= MAX_LOAD_STRING
;
169 saveidl
.lpstrInitialDir
= wszDir
;
170 saveidl
.Flags
= OFN_PATHMUSTEXIST
| OFN_OVERWRITEPROMPT
| OFN_HIDEREADONLY
;
171 saveidl
.lpstrDefExt
= wszDefaultExt
;
173 if (GetSaveFileNameW(&saveidl
))
177 static void AddToStrW(WCHAR
*wszDest
, const WCHAR
*wszSource
)
179 lstrcpyW(&wszDest
[lstrlenW(wszDest
)], wszSource
);
182 static void AddToTLDataStrW(TYPELIB_DATA
*pTLData
, const WCHAR
*wszSource
)
184 int SourceLen
= lstrlenW(wszSource
);
186 pTLData
->idl
= HeapReAlloc(GetProcessHeap(), 0, pTLData
->idl
,
187 sizeof(WCHAR
)*(pTLData
->idlLen
+SourceLen
+1));
189 memcpy(&pTLData
->idl
[pTLData
->idlLen
], wszSource
, sizeof(WCHAR
)*(SourceLen
+1));
190 pTLData
->idlLen
+= SourceLen
;
193 static void AddToTLDataStrWithTabsW(TYPELIB_DATA
*pTLData
, WCHAR
*wszSource
)
195 int lineLen
= lstrlenW(wszSource
);
197 WCHAR
*pSourcePos
= wszSource
;
203 if(*pSourcePos
== L
'\n') newLinesNo
++;
206 if(*(pSourcePos
- 1) != L
'\n') newLinesNo
++;
208 pTLData
->idl
= HeapReAlloc(GetProcessHeap(), 0, pTLData
->idl
,
209 sizeof(WCHAR
)*(pTLData
->idlLen
+lineLen
+4*newLinesNo
+1));
211 pSourcePos
= wszSource
;
212 pSourceBeg
= wszSource
;
215 if(*pSourcePos
!= L
'\n' && *pSourcePos
)
225 lineLen
= lstrlenW(pSourceBeg
)+1;
229 else lineLen
= lstrlenW(pSourceBeg
);
231 pTLData
->idl
[pTLData
->idlLen
] = L
' ';
232 pTLData
->idl
[pTLData
->idlLen
+1] = L
' ';
233 pTLData
->idl
[pTLData
->idlLen
+2] = L
' ';
234 pTLData
->idl
[pTLData
->idlLen
+3] = L
' ';
235 memcpy(&pTLData
->idl
[pTLData
->idlLen
+4], pSourceBeg
, sizeof(WCHAR
)*lineLen
);
236 pTLData
->idlLen
+= lineLen
+ 4;
237 pTLData
->idl
[pTLData
->idlLen
] = '\0';
239 pSourceBeg
= pSourcePos
;
243 static TYPELIB_DATA
*InitializeTLData(void)
245 TYPELIB_DATA
*pTLData
;
247 pTLData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(TYPELIB_DATA
));
249 pTLData
->idl
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
));
250 pTLData
->idl
[0] = '\0';
255 static void AddSpaces(TYPELIB_DATA
*pTLData
, int tabSize
)
257 for(; tabSize
>0; tabSize
--)
258 AddToTLDataStrW(pTLData
, L
" ");
261 static void AddChildrenData(HTREEITEM hParent
, TYPELIB_DATA
*pData
)
266 memset(&tvi
, 0, sizeof(tvi
));
268 hCur
= (HTREEITEM
)SendMessageW(typelib
.hTree
, TVM_GETNEXTITEM
,
269 TVGN_CHILD
, (LPARAM
)hParent
);
275 SendMessageW(typelib
.hTree
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
276 if(tvi
.lParam
&& ((TYPELIB_DATA
*)(tvi
.lParam
))->idlLen
)
277 AddToTLDataStrWithTabsW(pData
, ((TYPELIB_DATA
*)(tvi
.lParam
))->idl
);
278 } while((hCur
= (HTREEITEM
)SendMessageW(typelib
.hTree
, TVM_GETNEXTITEM
,
279 TVGN_NEXT
, (LPARAM
)hCur
)));
282 static void CreateTypeInfo(WCHAR
*wszAddTo
, WCHAR
*wszAddAfter
, TYPEDESC tdesc
, ITypeInfo
*pTypeInfo
)
287 ITypeInfo
*pRefTypeInfo
;
288 WCHAR wszBuf
[MAX_LOAD_STRING
];
289 WCHAR wszFormat
[] = { '[','%','l','u',']','\0' };
291 switch(tdesc
.vt
&VT_TYPEMASK
)
293 #define VTADDTOSTR(x) case x:\
294 AddToStrW(wszAddTo, wsz##x);\
310 VTADDTOSTR(VT_VARIANT
);
312 VTADDTOSTR(VT_ERROR
);
313 VTADDTOSTR(VT_LPSTR
);
314 VTADDTOSTR(VT_LPWSTR
);
315 VTADDTOSTR(VT_HRESULT
);
316 VTADDTOSTR(VT_UNKNOWN
);
317 VTADDTOSTR(VT_DISPATCH
);
321 for(i
=0; i
<U(tdesc
).lpadesc
->cDims
; i
++)
323 wsprintfW(wszBuf
, wszFormat
, U(tdesc
).lpadesc
->rgbounds
[i
].cElements
);
324 AddToStrW(wszAddAfter
, wszBuf
);
326 CreateTypeInfo(wszAddTo
, wszAddAfter
, U(tdesc
).lpadesc
->tdescElem
, pTypeInfo
);
329 AddToStrW(wszAddTo
, wszVT_SAFEARRAY
);
330 AddToStrW(wszAddTo
, L
"(");
331 CreateTypeInfo(wszAddTo
, wszAddAfter
, *U(tdesc
).lptdesc
, pTypeInfo
);
332 AddToStrW(wszAddTo
, L
")");
335 CreateTypeInfo(wszAddTo
, wszAddAfter
, *U(tdesc
).lptdesc
, pTypeInfo
);
336 AddToStrW(wszAddTo
, L
"*");
339 hRes
= ITypeInfo_GetRefTypeInfo(pTypeInfo
,
340 U(tdesc
).hreftype
, &pRefTypeInfo
);
343 ITypeInfo_GetDocumentation(pRefTypeInfo
, MEMBERID_NIL
,
344 &bstrData
, NULL
, NULL
, NULL
);
345 AddToStrW(wszAddTo
, bstrData
);
346 SysFreeString(bstrData
);
347 ITypeInfo_Release(pRefTypeInfo
);
349 else AddToStrW(wszAddTo
, wszFailed
);
352 WINE_FIXME("tdesc.vt&VT_TYPEMASK == %d not supported\n",
353 tdesc
.vt
&VT_TYPEMASK
);
357 static int EnumVars(ITypeInfo
*pTypeInfo
, int cVars
, HTREEITEM hParent
)
360 TVINSERTSTRUCTW tvis
;
363 WCHAR wszText
[MAX_LOAD_STRING
];
364 WCHAR wszAfter
[MAX_LOAD_STRING
];
366 U(tvis
).item
.mask
= TVIF_TEXT
|TVIF_PARAM
;
367 U(tvis
).item
.cchTextMax
= MAX_LOAD_STRING
;
368 U(tvis
).item
.pszText
= wszText
;
369 tvis
.hInsertAfter
= TVI_LAST
;
370 tvis
.hParent
= hParent
;
372 for(i
=0; i
<cVars
; i
++)
376 if(FAILED(ITypeInfo_GetVarDesc(pTypeInfo
, i
, &pVarDesc
))) continue;
377 if(FAILED(ITypeInfo_GetDocumentation(pTypeInfo
, pVarDesc
->memid
, &bstrName
,
378 NULL
, NULL
, NULL
))) continue;
380 tld
= InitializeTLData();
381 U(tvis
).item
.lParam
= (LPARAM
) tld
;
382 if(pVarDesc
->memid
< MIN_VAR_ID
)
385 AddToTLDataStrW(tld
, L
"[");
386 AddToTLDataStrW(tld
, wszId
);
387 AddToTLDataStrW(tld
, L
"(");
388 wsprintfW(wszText
, wszFormat
, pVarDesc
->memid
);
389 AddToTLDataStrW(tld
, wszText
);
390 memset(wszText
, 0, sizeof(wszText
));
391 AddToTLDataStrW(tld
, L
")");
393 if(pVarDesc
->wVarFlags
& VARFLAG_FREADONLY
)
395 AddToTLDataStrW(tld
, L
", ");
396 AddToTLDataStrW(tld
, wszReadOnly
);
398 AddToTLDataStrW(tld
, L
"]\n");
401 memset(wszText
, 0, sizeof(wszText
));
402 memset(wszAfter
, 0, sizeof(wszAfter
));
403 CreateTypeInfo(wszText
, wszAfter
, pVarDesc
->elemdescVar
.tdesc
, pTypeInfo
);
404 AddToStrW(wszText
, L
" ");
405 if (bstrName
) AddToStrW(wszText
, bstrName
);
406 AddToStrW(wszText
, wszAfter
);
407 AddToTLDataStrW(tld
, wszText
);
408 AddToTLDataStrW(tld
, L
";\n");
410 SendMessageW(typelib
.hTree
, TVM_INSERTITEMW
, 0, (LPARAM
)&tvis
);
411 SysFreeString(bstrName
);
412 ITypeInfo_ReleaseVarDesc(pTypeInfo
, pVarDesc
);
418 static int EnumEnums(ITypeInfo
*pTypeInfo
, int cVars
, HTREEITEM hParent
)
421 TVINSERTSTRUCTW tvis
;
424 WCHAR wszText
[MAX_LOAD_STRING
];
425 WCHAR wszAfter
[MAX_LOAD_STRING
];
427 U(tvis
).item
.mask
= TVIF_TEXT
|TVIF_PARAM
;
428 U(tvis
).item
.cchTextMax
= MAX_LOAD_STRING
;
429 U(tvis
).item
.pszText
= wszText
;
430 tvis
.hInsertAfter
= TVI_LAST
;
431 tvis
.hParent
= hParent
;
433 for(i
=0; i
<cVars
; i
++)
437 if(FAILED(ITypeInfo_GetVarDesc(pTypeInfo
, i
, &pVarDesc
))) continue;
438 if(FAILED(ITypeInfo_GetDocumentation(pTypeInfo
, pVarDesc
->memid
, &bstrName
,
439 NULL
, NULL
, NULL
))) continue;
441 tld
= InitializeTLData();
442 U(tvis
).item
.lParam
= (LPARAM
) tld
;
444 memset(wszText
, 0, sizeof(wszText
));
445 memset(wszAfter
, 0, sizeof(wszAfter
));
447 if (pVarDesc
->varkind
== VAR_CONST
)
451 if (VariantChangeType(&var
, U(*pVarDesc
).lpvarValue
, 0, VT_BSTR
) == S_OK
)
453 AddToStrW(wszText
, wszConst
);
454 AddToStrW(wszText
, L
" ");
455 AddToStrW(wszAfter
, L
" = ");
456 AddToStrW(wszAfter
, V_BSTR(&var
));
460 CreateTypeInfo(wszText
, wszAfter
, pVarDesc
->elemdescVar
.tdesc
, pTypeInfo
);
461 AddToStrW(wszText
, L
" ");
462 AddToStrW(wszText
, bstrName
);
463 AddToStrW(wszText
, wszAfter
);
464 AddToTLDataStrW(tld
, bstrName
);
465 AddToTLDataStrW(tld
, wszAfter
);
467 AddToTLDataStrW(tld
, L
",");
468 AddToTLDataStrW(tld
, L
"\n");
470 SendMessageW(typelib
.hTree
, TVM_INSERTITEMW
, 0, (LPARAM
)&tvis
);
471 SysFreeString(bstrName
);
472 ITypeInfo_ReleaseVarDesc(pTypeInfo
, pVarDesc
);
478 static int EnumFuncs(ITypeInfo
*pTypeInfo
, TYPEATTR
*pTypeAttr
, HTREEITEM hParent
)
483 TVINSERTSTRUCTW tvis
;
485 BSTR bstrName
, bstrHelpString
, *bstrParamNames
;
486 WCHAR wszText
[MAX_LOAD_STRING
];
487 WCHAR wszAfter
[MAX_LOAD_STRING
];
488 WCHAR szRhs
[] = {'r','h','s',0}; /* Right-hand side of a propput */
491 U(tvis
).item
.mask
= TVIF_TEXT
|TVIF_PARAM
;
492 tvis
.hInsertAfter
= TVI_LAST
;
493 tvis
.hParent
= hParent
;
495 cFuncs
= pTypeAttr
->cFuncs
;
498 if(pTypeAttr
->wTypeFlags
& TYPEFLAG_FDUAL
) { /* skip 7 members of IDispatch */
507 if(FAILED(ITypeInfo_GetFuncDesc(pTypeInfo
, i
, &pFuncDesc
))) continue;
509 if(FAILED(ITypeInfo_GetDocumentation(pTypeInfo
, pFuncDesc
->memid
, &bstrName
,
510 &bstrHelpString
, NULL
, NULL
))) continue;
512 memset(wszText
, 0, sizeof(wszText
));
513 memset(wszAfter
, 0, sizeof(wszAfter
));
514 tld
= InitializeTLData();
515 U(tvis
).item
.cchTextMax
= SysStringLen(bstrName
);
516 U(tvis
).item
.pszText
= bstrName
;
517 U(tvis
).item
.lParam
= (LPARAM
) tld
;
519 if(pFuncDesc
->memid
< MIN_FUNC_ID
|| pTypeAttr
->wTypeFlags
& TYPEFLAG_FDUAL
)
521 AddToTLDataStrW(tld
, L
"[");
523 AddToTLDataStrW(tld
, wszId
);
524 AddToTLDataStrW(tld
, L
"(");
525 wsprintfW(wszText
, wszFormat
, pFuncDesc
->memid
);
526 AddToTLDataStrW(tld
, wszText
);
527 AddToTLDataStrW(tld
, L
")");
528 memset(wszText
, 0, sizeof(wszText
));
531 CreateTypeInfo(wszText
, wszAfter
, pFuncDesc
->elemdescFunc
.tdesc
, pTypeInfo
);
532 switch(pFuncDesc
->invkind
)
534 case INVOKE_PROPERTYGET
:
535 if(bFirst
) AddToTLDataStrW(tld
, L
"[");
536 else AddToTLDataStrW(tld
, L
", ");
538 AddToTLDataStrW(tld
, wszPropGet
);
540 case INVOKE_PROPERTYPUT
:
541 if(bFirst
) AddToTLDataStrW(tld
, L
"[");
542 else AddToTLDataStrW(tld
, L
", ");
544 AddToTLDataStrW(tld
, wszPropPut
);
546 case INVOKE_PROPERTYPUTREF
:
547 if(bFirst
) AddToTLDataStrW(tld
, L
"[");
548 else AddToTLDataStrW(tld
, L
", ");
550 AddToTLDataStrW(tld
, wszPropPutRef
);
554 if(SysStringLen(bstrHelpString
))
556 if(bFirst
) AddToTLDataStrW(tld
, L
"[");
557 else AddToTLDataStrW(tld
, L
", ");
559 AddToTLDataStrW(tld
, wszHelpstring
);
560 AddToTLDataStrW(tld
, L
"(\"");
561 AddToTLDataStrW(tld
, bstrHelpString
);
562 AddToTLDataStrW(tld
, L
"\")");
564 if(!bFirst
) AddToTLDataStrW(tld
, L
"]\n");
566 if(pTypeAttr
->wTypeFlags
& TYPEFLAG_FOLEAUTOMATION
) {
567 AddToTLDataStrW(tld
, wszVT_HRESULT
);
568 if(lstrcmpW(wszText
, wszVT_VOID
)) pFuncDesc
->cParams
++;
571 AddToTLDataStrW(tld
, wszText
);
572 AddToTLDataStrW(tld
, wszAfter
);
575 bstrParamNames
= HeapAlloc(GetProcessHeap(), 0,
576 sizeof(BSTR
)*(pFuncDesc
->cParams
+1));
577 if(FAILED(ITypeInfo_GetNames(pTypeInfo
, pFuncDesc
->memid
, bstrParamNames
,
578 pFuncDesc
->cParams
+1, &namesNo
)))
580 HeapFree(GetProcessHeap(), 0, bstrParamNames
);
583 SysFreeString(bstrParamNames
[0]);
585 AddToTLDataStrW(tld
, L
" ");
586 if(pFuncDesc
->memid
>= MIN_FUNC_ID
)
588 AddToTLDataStrW(tld
, wszStdCall
);
589 AddToTLDataStrW(tld
, L
" ");
591 if (bstrName
) AddToTLDataStrW(tld
, bstrName
);
592 AddToTLDataStrW(tld
, L
"(");
594 for(j
=0; j
<pFuncDesc
->cParams
; j
++)
596 if(j
!= 0) AddToTLDataStrW(tld
, L
",");
597 if(pFuncDesc
->cParams
!= 1)
599 AddToTLDataStrW(tld
, L
"\n");
600 AddSpaces(tld
, TAB_SIZE
);
603 #define ENUM_PARAM_FLAG(x)\
604 if(U(pFuncDesc->lprgelemdescParam[j]).paramdesc.wParamFlags & x) \
607 AddToTLDataStrW(tld, L"[");\
610 AddToTLDataStrW(tld, L", ");\
613 AddToTLDataStrW(tld, wsz##x);\
615 ENUM_PARAM_FLAG(PARAMFLAG_FIN
);
616 ENUM_PARAM_FLAG(PARAMFLAG_FOUT
);
617 ENUM_PARAM_FLAG(PARAMFLAG_FLCID
);
618 ENUM_PARAM_FLAG(PARAMFLAG_FRETVAL
);
619 ENUM_PARAM_FLAG(PARAMFLAG_FOPT
);
620 ENUM_PARAM_FLAG(PARAMFLAG_FHASCUSTDATA
);
622 if(U(pFuncDesc
->lprgelemdescParam
[j
]).paramdesc
.wParamFlags
& PARAMFLAG_FHASDEFAULT
)
624 VARIANT var
, *param
=&U(pFuncDesc
->lprgelemdescParam
[j
]).paramdesc
.pparamdescex
->varDefaultValue
;
626 if(bFirst
) AddToTLDataStrW(tld
, L
"[");
627 else AddToTLDataStrW(tld
, L
", ");
629 AddToTLDataStrW(tld
, wszDefaultValue
);
630 AddToTLDataStrW(tld
, L
"(");
631 if (V_VT(param
) == VT_BSTR
)
633 AddToTLDataStrW(tld
, L
"\"");
634 AddToTLDataStrW(tld
, V_BSTR(param
));
635 AddToTLDataStrW(tld
, L
"\"");
636 } else if (VariantChangeType(&var
, param
, 0, VT_BSTR
) == S_OK
)
637 AddToTLDataStrW(tld
, V_BSTR(&var
));
638 AddToTLDataStrW(tld
, L
")");
641 if(!bFirst
) AddToTLDataStrW(tld
, L
"] ");
643 memset(wszText
, 0, sizeof(wszText
));
644 memset(wszAfter
, 0, sizeof(wszAfter
));
645 CreateTypeInfo(wszText
, wszAfter
, pFuncDesc
->lprgelemdescParam
[j
].tdesc
,
647 AddToTLDataStrW(tld
, wszText
);
648 AddToTLDataStrW(tld
, wszAfter
);
649 AddToTLDataStrW(tld
, L
" ");
651 if (bstrParamNames
[j
+1])
653 AddToTLDataStrW(tld
, bstrParamNames
[j
+1]);
654 SysFreeString(bstrParamNames
[j
+1]);
657 AddToTLDataStrW(tld
, szRhs
);
660 AddToTLDataStrW(tld
, L
");\n");
662 SendMessageW(typelib
.hTree
, TVM_INSERTITEMW
, 0, (LPARAM
)&tvis
);
663 HeapFree(GetProcessHeap(), 0, bstrParamNames
);
664 SysFreeString(bstrName
);
665 SysFreeString(bstrHelpString
);
666 ITypeInfo_ReleaseFuncDesc(pTypeInfo
, pFuncDesc
);
672 static int EnumImplTypes(ITypeInfo
*pTypeInfo
, int cImplTypes
, HTREEITEM hParent
)
675 TVINSERTSTRUCTW tvis
;
676 ITypeInfo
*pRefTypeInfo
;
680 WCHAR wszInheritedInterfaces
[MAX_LOAD_STRING
];
682 if(!cImplTypes
) return 0;
684 LoadStringW(globals
.hMainInst
, IDS_INHERITINTERFACES
, wszInheritedInterfaces
,
685 ARRAY_SIZE(wszInheritedInterfaces
));
687 U(tvis
).item
.mask
= TVIF_TEXT
;
688 U(tvis
).item
.cchTextMax
= MAX_LOAD_STRING
;
689 U(tvis
).item
.pszText
= wszInheritedInterfaces
;
690 tvis
.hInsertAfter
= TVI_LAST
;
691 tvis
.hParent
= hParent
;
693 tvis
.hParent
= TreeView_InsertItemW(typelib
.hTree
, &tvis
);
695 for(i
=0; i
<cImplTypes
; i
++)
697 if(FAILED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo
, i
, &hRefType
))) continue;
698 if(FAILED(ITypeInfo_GetRefTypeInfo(pTypeInfo
, hRefType
, &pRefTypeInfo
)))
700 if(FAILED(ITypeInfo_GetDocumentation(pRefTypeInfo
, MEMBERID_NIL
, &bstrName
,
703 ITypeInfo_Release(pRefTypeInfo
);
706 if(FAILED(ITypeInfo_GetTypeAttr(pRefTypeInfo
, &pTypeAttr
)))
708 ITypeInfo_Release(pRefTypeInfo
);
712 U(tvis
).item
.cchTextMax
= SysStringLen(bstrName
);
713 U(tvis
).item
.pszText
= bstrName
;
715 hParent
= TreeView_InsertItemW(typelib
.hTree
, &tvis
);
716 EnumVars(pRefTypeInfo
, pTypeAttr
->cVars
, hParent
);
717 EnumFuncs(pRefTypeInfo
, pTypeAttr
, hParent
);
718 EnumImplTypes(pRefTypeInfo
, pTypeAttr
->cImplTypes
, hParent
);
720 SysFreeString(bstrName
);
721 ITypeInfo_ReleaseTypeAttr(pRefTypeInfo
, pTypeAttr
);
722 ITypeInfo_Release(pRefTypeInfo
);
728 static void EnumCoclassImplTypes(ITypeInfo
*pTypeInfo
,
729 int cImplTypes
, TYPELIB_DATA
*pTLData
)
732 ITypeInfo
*pRefTypeInfo
;
738 const WCHAR wszTKIND_INTERFACE
[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' };
739 const WCHAR wszTKIND_DISPATCH
[]
740 = { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' };
741 const WCHAR wszIMPLTYPEFLAG_FDEFAULT
[]
742 = { 'd','e','f','a','u','l','t','\0' };
743 const WCHAR wszIMPLTYPEFLAG_FSOURCE
[]
744 = { 's','o','u','r','c','e','\0' };
745 const WCHAR wszIMPLTYPEFLAG_FRESTRICTED
[]
746 = { 'r','e','s','t','r','i','c','t','e','d','\0' };
748 for(i
=0; i
<cImplTypes
; i
++)
750 if(FAILED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo
, i
, &hRefType
))) continue;
751 if(FAILED(ITypeInfo_GetRefTypeInfo(pTypeInfo
, hRefType
, &pRefTypeInfo
)))
753 if(FAILED(ITypeInfo_GetDocumentation(pRefTypeInfo
, MEMBERID_NIL
, &bstrName
,
756 ITypeInfo_Release(pRefTypeInfo
);
759 if(FAILED(ITypeInfo_GetTypeAttr(pRefTypeInfo
, &pTypeAttr
)))
761 ITypeInfo_Release(pRefTypeInfo
);
765 AddSpaces(pTLData
, TAB_SIZE
);
766 ITypeInfo_GetImplTypeFlags(pTypeInfo
, i
, &flags
);
768 #define ENUM_IMPLTYPEFLAG(x)\
772 AddToTLDataStrW(pTLData, L"[");\
775 AddToTLDataStrW(pTLData, L", ");\
778 AddToTLDataStrW(pTLData, wsz##x);\
780 ENUM_IMPLTYPEFLAG(IMPLTYPEFLAG_FDEFAULT
);
781 ENUM_IMPLTYPEFLAG(IMPLTYPEFLAG_FSOURCE
);
782 ENUM_IMPLTYPEFLAG(IMPLTYPEFLAG_FRESTRICTED
);
784 AddToTLDataStrW(pTLData
, L
"] ");
786 if(pTypeAttr
->typekind
== TKIND_INTERFACE
||
787 (pTypeAttr
->wTypeFlags
& TYPEFLAG_FDUAL
))
788 AddToTLDataStrW(pTLData
, wszTKIND_INTERFACE
);
789 else if(pTypeAttr
->typekind
== TKIND_DISPATCH
)
790 AddToTLDataStrW(pTLData
, wszTKIND_DISPATCH
);
791 AddToTLDataStrW(pTLData
, L
" ");
793 AddToTLDataStrW(pTLData
, bstrName
);
794 AddToTLDataStrW(pTLData
, L
";\n");
796 SysFreeString(bstrName
);
797 ITypeInfo_ReleaseTypeAttr(pRefTypeInfo
, pTypeAttr
);
798 ITypeInfo_Release(pRefTypeInfo
);
802 static void AddIdlData(HTREEITEM hCur
, TYPELIB_DATA
*pTLData
)
806 hCur
= (HTREEITEM
)SendMessageW(typelib
.hTree
, TVM_GETNEXTITEM
,
807 TVGN_CHILD
, (LPARAM
)hCur
);
808 memset(&tvi
, 0, sizeof(TVITEMW
));
809 tvi
.mask
= TVIF_PARAM
;
814 SendMessageW(typelib
.hTree
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
815 if(!((TYPELIB_DATA
*)(tvi
.lParam
))->bHide
) {
816 AddToTLDataStrW(pTLData
, L
"\n");
817 AddToTLDataStrWithTabsW(pTLData
, ((TYPELIB_DATA
*)(tvi
.lParam
))->idl
);
819 hCur
= (HTREEITEM
)SendMessageW(typelib
.hTree
, TVM_GETNEXTITEM
,
820 TVGN_NEXT
, (LPARAM
)hCur
);
824 static void AddPredefinitions(HTREEITEM hFirst
, TYPELIB_DATA
*pTLData
)
828 WCHAR wszText
[MAX_LOAD_STRING
];
829 WCHAR wszPredefinition
[] = { '/','/',' ','T','L','i','b',' ',':','\n',
830 '/','/',' ','F','o','r','w','a','r','d',' ','d','e','c','l','a','r','e',' ',
831 'a','l','l',' ','t','y','p','e','s',' ','d','e','f','i','n','e','d',' ',
832 'i','n',' ','t','h','i','s',' ','t','y','p','e','l','i','b','\0' };
834 hFirst
= (HTREEITEM
)SendMessageW(typelib
.hTree
, TVM_GETNEXTITEM
,
835 TVGN_CHILD
, (LPARAM
)hFirst
);
837 AddToTLDataStrWithTabsW(pTLData
, wszPredefinition
);
838 AddToTLDataStrW(pTLData
, L
"\n");
841 memset(&tvi
, 0, sizeof(TVITEMW
));
842 tvi
.mask
= TVIF_TEXT
|TVIF_PARAM
;
843 tvi
.cchTextMax
= MAX_LOAD_STRING
;
844 tvi
.pszText
= wszText
;
848 SendMessageW(typelib
.hTree
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
849 if(((TYPELIB_DATA
*)(tvi
.lParam
))->bPredefine
&&
850 !((TYPELIB_DATA
*)(tvi
.lParam
))->bHide
)
852 AddToStrW(wszText
, L
";");
853 AddToTLDataStrWithTabsW(pTLData
, wszText
);
854 AddToTLDataStrW(pTLData
, L
"\n");
856 hCur
= (HTREEITEM
)SendMessageW(typelib
.hTree
, TVM_GETNEXTITEM
,
857 TVGN_NEXT
, (LPARAM
)hCur
);
861 static void CreateInterfaceInfo(ITypeInfo
*pTypeInfo
, int cImplTypes
, WCHAR
*wszName
,
862 WCHAR
*wszHelpString
, ULONG ulHelpContext
, TYPEATTR
*pTypeAttr
,
863 TYPELIB_DATA
*pTLData
)
865 ITypeInfo
*pRefTypeInfo
;
868 WCHAR wszGuid
[MAX_LOAD_STRING
];
869 WCHAR wszHelpContext
[MAX_LOAD_STRING
];
871 const WCHAR wszInterface
[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' };
872 const WCHAR wszDispinterface
[]
873 = { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' };
874 const WCHAR wszHelpcontext
[] = { 'h','e','l','p','c','o','n','t','e','x','t','\0' };
875 const WCHAR wszTYPEFLAG_FAPPOBJECT
[] = { 'a','p','p','o','b','j','e','c','t','\0' };
876 const WCHAR wszTYPEFLAG_FCANCREATE
[] = { 'c','a','n','c','r','e','a','t','e','\0' };
877 const WCHAR wszTYPEFLAG_FLICENSED
[] = { 'l','i','c','e','n','s','e','d','\0' };
878 const WCHAR wszTYPEFLAG_FPREDECLID
[] = { 'p','r','e','d','e','c','l','i','d','\0' };
879 const WCHAR wszTYPEFLAG_FHIDDEN
[] = { 'h','i','d','d','e','n','\0' };
880 const WCHAR wszTYPEFLAG_FCONTROL
[] = { 'c','o','n','t','r','o','l','\0' };
881 const WCHAR wszTYPEFLAG_FDUAL
[] = { 'd','u','a','l','\0' };
882 const WCHAR wszTYPEFLAG_FNONEXTENSIBLE
[]
883 = { 'n','o','n','e','x','t','e','n','s','i','b','l','e','\0' };
884 const WCHAR wszTYPEFLAG_FOLEAUTOMATION
[]
885 = { 'o','l','e','a','u','t','o','m','a','t','i','o','n','\0' };
886 const WCHAR wszTYPEFLAG_FRESTRICTED
[]
887 = { 'r','e','s','t','r','i','c','t','e','d','\0' };
888 const WCHAR wszTYPEFLAG_FAGGREGATABLE
[]
889 = { 'a','g','g','r','e','g','a','t','a','b','l','e','\0' };
890 const WCHAR wszTYPEFLAG_FREPLACEABLE
[]
891 = { 'r','e','p','l','a','c','a','b','l','e','\0' };
892 const WCHAR wszTYPEFLAG_FREVERSEBIND
[]
893 = { 'r','e','v','e','r','s','e','b','i','n','d','\0' };
894 const WCHAR wszTYPEFLAG_FPROXY
[] = { 'p','r','o','x','y','\0' };
896 AddToTLDataStrW(pTLData
, L
"[\n");
897 if(pTypeAttr
->typekind
!= TKIND_DISPATCH
)
899 AddSpaces(pTLData
, TAB_SIZE
);
900 AddToTLDataStrW(pTLData
, wszOdl
);
901 AddToTLDataStrW(pTLData
, L
",\n");
903 AddSpaces(pTLData
, TAB_SIZE
);
904 AddToTLDataStrW(pTLData
, wszUUID
);
905 AddToTLDataStrW(pTLData
, L
"(");
906 StringFromGUID2(&(pTypeAttr
->guid
), wszGuid
, MAX_LOAD_STRING
);
907 wszGuid
[lstrlenW(wszGuid
)-1] = '\0';
908 AddToTLDataStrW(pTLData
, &wszGuid
[1]);
909 AddToTLDataStrW(pTLData
, L
")");
912 AddToTLDataStrW(pTLData
, L
",\n");
913 AddSpaces(pTLData
, TAB_SIZE
);
914 AddToTLDataStrW(pTLData
, wszHelpstring
);
915 AddToTLDataStrW(pTLData
, L
"(\"");
916 AddToTLDataStrW(pTLData
, wszHelpString
);
917 AddToTLDataStrW(pTLData
, L
"\")");
921 AddToTLDataStrW(pTLData
, L
",\n");
922 AddSpaces(pTLData
, TAB_SIZE
);
923 AddToTLDataStrW(pTLData
, wszHelpcontext
);
924 AddToTLDataStrW(pTLData
, L
"(");
925 wsprintfW(wszHelpContext
, wszFormat
, ulHelpContext
);
926 AddToTLDataStrW(pTLData
, wszHelpContext
);
927 AddToTLDataStrW(pTLData
, L
")");
929 if(pTypeAttr
->wTypeFlags
)
931 #define ENUM_FLAGS(x) if(pTypeAttr->wTypeFlags & x)\
933 AddToTLDataStrW(pTLData, L",\n");\
934 AddSpaces(pTLData, TAB_SIZE);\
935 AddToTLDataStrW(pTLData, wsz##x);\
937 ENUM_FLAGS(TYPEFLAG_FAPPOBJECT
);
938 ENUM_FLAGS(TYPEFLAG_FCANCREATE
);
939 ENUM_FLAGS(TYPEFLAG_FLICENSED
);
940 ENUM_FLAGS(TYPEFLAG_FPREDECLID
);
941 ENUM_FLAGS(TYPEFLAG_FHIDDEN
);
942 ENUM_FLAGS(TYPEFLAG_FCONTROL
);
943 ENUM_FLAGS(TYPEFLAG_FDUAL
);
944 ENUM_FLAGS(TYPEFLAG_FNONEXTENSIBLE
);
945 ENUM_FLAGS(TYPEFLAG_FOLEAUTOMATION
);
946 ENUM_FLAGS(TYPEFLAG_FRESTRICTED
);
947 ENUM_FLAGS(TYPEFLAG_FAGGREGATABLE
);
948 ENUM_FLAGS(TYPEFLAG_FREPLACEABLE
);
949 ENUM_FLAGS(TYPEFLAG_FREVERSEBIND
);
950 ENUM_FLAGS(TYPEFLAG_FPROXY
);
952 AddToTLDataStrW(pTLData
, L
"\n]\n");
953 if(pTypeAttr
->typekind
!= TKIND_DISPATCH
) AddToTLDataStrW(pTLData
, wszInterface
);
954 else AddToTLDataStrW(pTLData
, wszDispinterface
);
955 AddToTLDataStrW(pTLData
, wszName
);
956 AddToTLDataStrW(pTLData
, L
" ");
957 if(cImplTypes
&& pTypeAttr
->typekind
!= TKIND_DISPATCH
)
959 AddToTLDataStrW(pTLData
, L
": ");
961 ITypeInfo_GetRefTypeOfImplType(pTypeInfo
, 0, &hRefType
);
962 if (SUCCEEDED(ITypeInfo_GetRefTypeInfo(pTypeInfo
, hRefType
, &pRefTypeInfo
)))
964 ITypeInfo_GetDocumentation(pRefTypeInfo
, MEMBERID_NIL
, &bstrName
,
966 AddToTLDataStrW(pTLData
, bstrName
);
967 AddToTLDataStrW(pTLData
, L
" ");
969 SysFreeString(bstrName
);
970 ITypeInfo_Release(pRefTypeInfo
);
973 AddToTLDataStrW(pTLData
, wszFailed
);
975 AddToTLDataStrW(pTLData
, L
"{\n");
977 AddToStrW(pTLData
->wszInsertAfter
, L
"};\n");
980 static void CreateTypedefHeader(ITypeInfo
*pTypeInfo
,
981 TYPEATTR
*pTypeAttr
, TYPELIB_DATA
*pTLData
)
984 WCHAR wszGuid
[MAX_LOAD_STRING
];
985 const WCHAR wszTypedef
[] = { 't','y','p','e','d','e','f',' ','\0' };
986 const WCHAR wszPublic
[] = { 'p','u','b','l','i','c','\0' };
988 AddToTLDataStrW(pTLData
, wszTypedef
);
989 if(memcmp(&pTypeAttr
->guid
, &GUID_NULL
, sizeof(GUID
)))
991 AddToTLDataStrW(pTLData
, L
"[");
993 AddToTLDataStrW(pTLData
, wszUUID
);
994 AddToTLDataStrW(pTLData
, L
"(");
995 StringFromGUID2(&(pTypeAttr
->guid
), wszGuid
, MAX_LOAD_STRING
);
996 wszGuid
[lstrlenW(wszGuid
)-1] = '\0';
997 AddToTLDataStrW(pTLData
, &wszGuid
[1]);
998 AddToTLDataStrW(pTLData
, L
")");
1000 if(pTypeAttr
->typekind
== TKIND_ALIAS
)
1002 if(bFirst
) AddToTLDataStrW(pTLData
, L
"[");
1003 else AddToTLDataStrW(pTLData
, L
", ");
1005 AddToTLDataStrW(pTLData
, wszPublic
);
1007 if(!bFirst
) AddToTLDataStrW(pTLData
, L
"]\n");
1010 static void CreateCoclassHeader(ITypeInfo
*pTypeInfo
,
1011 TYPEATTR
*pTypeAttr
, TYPELIB_DATA
*pTLData
)
1013 WCHAR wszGuid
[MAX_LOAD_STRING
];
1014 BSTR bstrHelpString
;
1015 const WCHAR wszNoncreatable
[]
1016 = { 'n','o','n','c','r','e','a','t','a','b','l','e','\0' };
1018 AddToTLDataStrW(pTLData
, L
"[\n");
1020 AddSpaces(pTLData
, TAB_SIZE
);
1021 AddToTLDataStrW(pTLData
, wszUUID
);
1022 AddToTLDataStrW(pTLData
, L
"(");
1023 StringFromGUID2(&(pTypeAttr
->guid
), wszGuid
, MAX_LOAD_STRING
);
1024 wszGuid
[lstrlenW(wszGuid
)-1] = '\0';
1025 AddToTLDataStrW(pTLData
, &wszGuid
[1]);
1026 AddToTLDataStrW(pTLData
, L
")");
1028 if(SUCCEEDED(ITypeInfo_GetDocumentation(pTypeInfo
, MEMBERID_NIL
, NULL
,
1029 &bstrHelpString
, NULL
, NULL
)))
1031 if(SysStringLen(bstrHelpString
))
1033 AddToTLDataStrW(pTLData
, L
",\n");
1034 AddSpaces(pTLData
, TAB_SIZE
);
1035 AddToTLDataStrW(pTLData
, wszHelpstring
);
1036 AddToTLDataStrW(pTLData
, L
"(\"");
1037 AddToTLDataStrW(pTLData
, bstrHelpString
);
1038 AddToTLDataStrW(pTLData
, L
"\")");
1040 SysFreeString(bstrHelpString
);
1043 if(!(pTypeAttr
->wTypeFlags
& TYPEFLAG_FCANCREATE
))
1045 AddToTLDataStrW(pTLData
, L
",\n");
1046 AddSpaces(pTLData
, TAB_SIZE
);
1047 AddToTLDataStrW(pTLData
, wszNoncreatable
);
1050 AddToTLDataStrW(pTLData
, L
"\n]\n");
1053 static int PopulateTree(void)
1055 TVINSERTSTRUCTW tvis
;
1058 TLIBATTR
*pTLibAttr
;
1059 ITypeInfo
*pTypeInfo
, *pRefTypeInfo
;
1061 TYPEATTR
*pTypeAttr
;
1063 ULONG ulHelpContext
;
1066 WCHAR wszText
[MAX_LOAD_STRING
];
1067 WCHAR wszAfter
[MAX_LOAD_STRING
];
1072 TYPELIB_DATA
*tldDispatch
;
1075 const WCHAR wszGeneratedInfo
[] = { '/','/',' ','G','e','n','e','r','a','t','e','d',
1076 ' ','.','I','D','L',' ','f','i','l','e',' ','(','b','y',' ','t','h','e',' ',
1077 'O','L','E','/','C','O','M',' ','O','b','j','e','c','t',' ',
1078 'V','i','e','w','e','r',')','\n','/','/','\n','/','/',' ',
1079 't','y','p','e','l','i','b',' ','f','i','l','e','n','a','m','e',':',' ','\0'};
1081 const WCHAR wszFormat
[] = { '%','s',' ','(','%','s',')','\0' };
1082 const WCHAR wszFormat2
[] = { 'v','e','r','s','i','o','n',
1083 '(','%','l','d','.','%','l','d',')','\0' };
1085 const WCHAR wszTKIND_ENUM
[] = { 't','y','p','e','d','e','f',' ','e','n','u','m',' ','\0' };
1086 const WCHAR wszTKIND_RECORD
[]
1087 = { 't','y','p','e','d','e','f',' ','s','t','r','u','c','t',' ','\0' };
1088 const WCHAR wszTKIND_MODULE
[] = { 'm','o','d','u','l','e',' ','\0' };
1089 const WCHAR wszTKIND_INTERFACE
[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' };
1090 const WCHAR wszTKIND_DISPATCH
[]
1091 = { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' };
1092 const WCHAR wszTKIND_COCLASS
[] = { 'c','o','c','l','a','s','s',' ','\0' };
1093 const WCHAR wszTKIND_ALIAS
[] = { 't','y','p','e','d','e','f',' ','\0' };
1094 const WCHAR wszTKIND_UNION
[]
1095 = { 't','y','p','e','d','e','f',' ','u','n','i','o','n',' ','\0' };
1097 const WCHAR wszLibrary
[] = { 'l','i','b','r','a','r','y',' ','\0' };
1098 const WCHAR wszTag
[] = { 't','a','g','\0' };
1100 WCHAR wszProperties
[] = { 'p','r','o','p','e','r','t','i','e','s','\0' };
1101 WCHAR wszMethods
[] = { 'm','e','t','h','o','d','s','\0' };
1103 U(tvis
).item
.mask
= TVIF_TEXT
|TVIF_PARAM
;
1104 U(tvis
).item
.cchTextMax
= MAX_LOAD_STRING
;
1105 U(tvis
).item
.pszText
= wszText
;
1106 tvis
.hInsertAfter
= TVI_LAST
;
1107 tvis
.hParent
= TVI_ROOT
;
1109 if(FAILED((hRes
= LoadTypeLib(typelib
.wszFileName
, &pTypeLib
))))
1111 WCHAR wszMessage
[MAX_LOAD_STRING
];
1112 WCHAR wszError
[MAX_LOAD_STRING
];
1115 LoadStringW(globals
.hMainInst
, IDS_ERROR_LOADTYPELIB
, wszError
, ARRAY_SIZE(wszError
));
1116 args
[0] = (DWORD_PTR
)typelib
.wszFileName
;
1118 FormatMessageW(FORMAT_MESSAGE_FROM_STRING
|FORMAT_MESSAGE_ARGUMENT_ARRAY
,
1119 wszError
, 0, 0, wszMessage
, ARRAY_SIZE(wszMessage
), (__ms_va_list
*)args
);
1120 MessageBoxW(globals
.hMainWnd
, wszMessage
, NULL
, MB_OK
|MB_ICONEXCLAMATION
);
1123 count
= ITypeLib_GetTypeInfoCount(pTypeLib
);
1125 ITypeLib_GetDocumentation(pTypeLib
, -1, &bstrName
, &bstrData
, NULL
, NULL
);
1126 ITypeLib_GetLibAttr(pTypeLib
, &pTLibAttr
);
1128 tld
= InitializeTLData();
1129 U(tvis
).item
.lParam
= (LPARAM
) tld
;
1130 AddToTLDataStrW(tld
, wszGeneratedInfo
);
1131 AddToTLDataStrW(tld
, typelib
.wszFileName
);
1132 AddToTLDataStrW(tld
, L
"\n\n[\n");
1133 AddSpaces(tld
, TAB_SIZE
);
1134 AddToTLDataStrW(tld
, wszUUID
);
1135 AddToTLDataStrW(tld
, L
"(");
1136 StringFromGUID2(&(pTLibAttr
->guid
), wszText
, MAX_LOAD_STRING
);
1137 wszText
[lstrlenW(wszText
)-1] = '\0';
1138 AddToTLDataStrW(tld
, &wszText
[1]);
1139 AddToTLDataStrW(tld
, L
"),\n");
1140 AddSpaces(tld
, TAB_SIZE
);
1141 wsprintfW(wszText
, wszFormat2
, pTLibAttr
->wMajorVerNum
, pTLibAttr
->wMinorVerNum
);
1142 AddToTLDataStrW(tld
, wszText
);
1146 /* helpstring is optional */
1147 AddToTLDataStrW(tld
, L
",\n");
1148 AddSpaces(tld
, TAB_SIZE
);
1149 AddToTLDataStrW(tld
, wszHelpstring
);
1150 AddToTLDataStrW(tld
, L
"(\"");
1151 AddToTLDataStrW(tld
, bstrData
);
1152 AddToTLDataStrW(tld
, L
"\")");
1155 AddToTLDataStrW(tld
, L
"\n]\n");
1156 AddToTLDataStrW(tld
, wszLibrary
);
1157 if (bstrName
) AddToTLDataStrW(tld
, bstrName
);
1158 AddToTLDataStrW(tld
, L
"\n{\n");
1160 AddToStrW(tld
->wszInsertAfter
, L
"};");
1162 wsprintfW(wszText
, wszFormat
, bstrName
, bstrData
);
1163 SysFreeString(bstrName
);
1164 SysFreeString(bstrData
);
1165 tvis
.hParent
= (HTREEITEM
)SendMessageW(typelib
.hTree
,
1166 TVM_INSERTITEMW
, 0, (LPARAM
)&tvis
);
1168 for(i
=0; i
<count
; i
++)
1171 ITypeLib_GetTypeInfo(pTypeLib
, i
, &pTypeInfo
);
1173 ITypeInfo_GetDocumentation(pTypeInfo
, MEMBERID_NIL
, &bstrName
, &bstrData
,
1174 &ulHelpContext
, NULL
);
1175 ITypeInfo_GetTypeAttr(pTypeInfo
, &pTypeAttr
);
1177 memset(wszText
, 0, sizeof(wszText
));
1178 memset(wszAfter
, 0, sizeof(wszAfter
));
1179 tld
= InitializeTLData();
1180 U(tvis
).item
.lParam
= (LPARAM
)tld
;
1181 switch(pTypeAttr
->typekind
)
1184 AddToStrW(wszText
, wszTKIND_ENUM
);
1185 AddToStrW(wszText
, bstrName
);
1187 CreateTypedefHeader(pTypeInfo
, pTypeAttr
, tld
);
1188 AddToTLDataStrW(tld
, &wszTKIND_ENUM
[lstrlenW(wszTKIND_ALIAS
)]);
1189 AddToTLDataStrW(tld
, L
"{\n");
1190 AddToStrW(tld
->wszInsertAfter
, L
"} ");
1191 AddToStrW(tld
->wszInsertAfter
, bstrName
);
1192 AddToStrW(tld
->wszInsertAfter
, L
";\n");
1195 hParent
= TreeView_InsertItemW(typelib
.hTree
, &tvis
);
1196 EnumEnums(pTypeInfo
, pTypeAttr
->cVars
, hParent
);
1197 AddChildrenData(hParent
, tld
);
1198 AddToTLDataStrW(tld
, tld
->wszInsertAfter
);
1201 AddToTLDataStrW(tld
, wszTKIND_RECORD
);
1202 AddToTLDataStrW(tld
, wszTag
);
1203 AddToTLDataStrW(tld
, bstrName
);
1204 AddToTLDataStrW(tld
, L
" {\n");
1206 AddToStrW(tld
->wszInsertAfter
, L
"} ");
1207 AddToStrW(tld
->wszInsertAfter
, bstrName
);
1208 AddToStrW(tld
->wszInsertAfter
, L
";\n");
1210 AddToStrW(wszText
, wszTKIND_RECORD
);
1211 AddToStrW(wszText
, bstrName
);
1214 AddToStrW(wszText
, wszTKIND_MODULE
);
1215 AddToStrW(wszText
, bstrName
);
1217 case TKIND_INTERFACE
:
1218 CreateInterfaceInfo(pTypeInfo
, pTypeAttr
->cImplTypes
, bstrName
,
1219 bstrData
, ulHelpContext
, pTypeAttr
, tld
);
1220 tld
->bPredefine
= TRUE
;
1222 AddToStrW(wszText
, wszTKIND_INTERFACE
);
1223 AddToStrW(wszText
, bstrName
);
1226 AddToStrW(wszText
, wszTKIND_COCLASS
);
1227 AddToStrW(wszText
, bstrName
);
1229 CreateCoclassHeader(pTypeInfo
, pTypeAttr
, tld
);
1230 AddToTLDataStrW(tld
, wszTKIND_COCLASS
);
1231 AddToTLDataStrW(tld
, bstrName
);
1232 AddToTLDataStrW(tld
, L
" {\n");
1234 EnumCoclassImplTypes(pTypeInfo
, pTypeAttr
->cImplTypes
, tld
);
1236 AddToStrW(tld
->wszInsertAfter
, L
"};\n");
1239 hParent
= TreeView_InsertItemW(typelib
.hTree
, &tvis
);
1240 AddToTLDataStrW(tld
, tld
->wszInsertAfter
);
1243 AddToStrW(wszText
, wszTKIND_UNION
);
1244 AddToStrW(wszText
, bstrName
);
1246 case TKIND_DISPATCH
:
1247 CreateInterfaceInfo(pTypeInfo
, pTypeAttr
->cImplTypes
, bstrName
,
1248 bstrData
, ulHelpContext
, pTypeAttr
, tld
);
1249 tld
->bPredefine
= TRUE
;
1250 if(pTypeAttr
->wTypeFlags
& TYPEFLAG_FDUAL
)
1252 AddToStrW(wszText
, wszTKIND_DISPATCH
);
1253 AddToStrW(wszText
, bstrName
);
1255 hParent
= TreeView_InsertItemW(typelib
.hTree
, &tvis
);
1256 hMain
= tvis
.hParent
;
1259 lstrcpyW(wszText
, wszProperties
);
1260 tvis
.hParent
= hParent
;
1261 tld
= InitializeTLData();
1262 U(tvis
).item
.lParam
= (LPARAM
) tld
;
1263 AddToTLDataStrW(tld
, wszProperties
);
1264 AddToTLDataStrW(tld
, L
":\n");
1265 tvis
.hParent
= TreeView_InsertItemW(typelib
.hTree
, &tvis
);
1266 EnumVars(pTypeInfo
, pTypeAttr
->cVars
, tvis
.hParent
);
1267 AddChildrenData(tvis
.hParent
, tld
);
1269 lstrcpyW(wszText
, wszMethods
);
1270 tvis
.hParent
= hParent
;
1271 tld
= InitializeTLData();
1272 U(tvis
).item
.lParam
= (LPARAM
) tld
;
1273 AddToTLDataStrW(tld
, wszMethods
);
1274 AddToTLDataStrW(tld
, L
":\n");
1275 tvis
.hParent
= TreeView_InsertItemW(typelib
.hTree
, &tvis
);
1276 EnumFuncs(pTypeInfo
, pTypeAttr
, tvis
.hParent
);
1277 AddChildrenData(tvis
.hParent
, tld
);
1279 EnumImplTypes(pTypeInfo
, pTypeAttr
->cImplTypes
, hParent
);
1280 AddChildrenData(hParent
, tldDispatch
);
1281 AddToTLDataStrW(tldDispatch
, tldDispatch
->wszInsertAfter
);
1284 tvis
.hParent
= hMain
;
1286 if(SUCCEEDED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo
, -1, &hRefType
)))
1290 ITypeInfo_ReleaseTypeAttr(pTypeInfo
, pTypeAttr
);
1291 SysFreeString(bstrName
);
1292 SysFreeString(bstrData
);
1294 memset(wszText
, 0, sizeof(wszText
));
1295 tld
= InitializeTLData();
1296 U(tvis
).item
.lParam
= (LPARAM
) tld
;
1298 ITypeInfo_GetRefTypeInfo(pTypeInfo
, hRefType
, &pRefTypeInfo
);
1299 ITypeInfo_GetDocumentation(pRefTypeInfo
, MEMBERID_NIL
, &bstrName
,
1300 &bstrData
, &ulHelpContext
, NULL
);
1301 ITypeInfo_GetTypeAttr(pRefTypeInfo
, &pTypeAttr
);
1303 CreateInterfaceInfo(pTypeInfo
, pTypeAttr
->cImplTypes
, bstrName
,
1304 bstrData
, ulHelpContext
, pTypeAttr
, tld
);
1305 tld
->bPredefine
= TRUE
;
1307 AddToStrW(wszText
, wszTKIND_INTERFACE
);
1308 AddToStrW(wszText
, bstrName
);
1309 ITypeInfo_Release(pRefTypeInfo
);
1313 AddToStrW(wszText
, wszTKIND_ALIAS
);
1314 CreateTypeInfo(wszText
, wszAfter
, pTypeAttr
->tdescAlias
, pTypeInfo
);
1315 AddToStrW(wszText
, L
" ");
1316 AddToStrW(wszText
, bstrName
);
1317 AddToStrW(wszText
, wszAfter
);
1319 CreateTypedefHeader(pTypeInfo
, pTypeAttr
, tld
);
1320 AddToTLDataStrW(tld
, &wszText
[lstrlenW(wszTKIND_ALIAS
)]);
1321 AddToTLDataStrW(tld
, L
";\n");
1324 lstrcpyW(wszText
, bstrName
);
1325 WINE_FIXME("pTypeAttr->typekind == %d not supported\n",
1326 pTypeAttr
->typekind
);
1331 hParent
= TreeView_InsertItemW(typelib
.hTree
, &tvis
);
1333 EnumVars(pTypeInfo
, pTypeAttr
->cVars
, hParent
);
1334 EnumFuncs(pTypeInfo
, pTypeAttr
, hParent
);
1335 EnumImplTypes(pTypeInfo
, pTypeAttr
->cImplTypes
, hParent
);
1337 if(memcmp(bstrName
, wszVT_UNKNOWN
, sizeof(wszVT_UNKNOWN
)))
1338 AddChildrenData(hParent
, tld
);
1339 AddToTLDataStrW(tld
, tld
->wszInsertAfter
);
1342 ITypeInfo_ReleaseTypeAttr(pTypeInfo
, pTypeAttr
);
1343 ITypeInfo_Release(pTypeInfo
);
1344 SysFreeString(bstrName
);
1345 SysFreeString(bstrData
);
1347 SendMessageW(typelib
.hTree
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
)tvis
.hParent
);
1349 memset(&tvi
, 0, sizeof(TVITEMW
));
1350 tvi
.mask
= TVIF_PARAM
;
1351 tvi
.hItem
= tvis
.hParent
;
1353 SendMessageW(typelib
.hTree
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
1354 AddPredefinitions(tvi
.hItem
, (TYPELIB_DATA
*)(tvi
.lParam
));
1355 AddIdlData(tvi
.hItem
, (TYPELIB_DATA
*)(tvi
.lParam
));
1356 AddToTLDataStrW((TYPELIB_DATA
*)(tvi
.lParam
),
1357 ((TYPELIB_DATA
*)(tvi
.lParam
))->wszInsertAfter
);
1359 ITypeLib_Release(pTypeLib
);
1363 void UpdateData(HTREEITEM item
)
1367 memset(&tvi
, 0, sizeof(TVITEMW
));
1368 tvi
.mask
= TVIF_PARAM
;
1371 SendMessageW(typelib
.hTree
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
1374 SetWindowTextW(typelib
.hEdit
, L
" ");
1378 SetWindowTextW(typelib
.hEdit
, ((TYPELIB_DATA
*)tvi
.lParam
)->idl
);
1381 static void TypeLibResizeChild(void)
1385 MoveWindow(typelib
.hStatusBar
, 0, 0, 0, 0, TRUE
);
1387 if(IsWindowVisible(typelib
.hStatusBar
))
1388 GetClientRect(typelib
.hStatusBar
, &stat
);
1389 else stat
.bottom
= 0;
1391 GetClientRect(globals
.hTypeLibWnd
, &client
);
1392 MoveWindow(typelib
.hPaneWnd
, 0, 0,
1393 client
.right
, client
.bottom
-stat
.bottom
, TRUE
);
1396 static void TypeLibMenuCommand(WPARAM wParam
, HWND hWnd
)
1406 vis
= IsWindowVisible(typelib
.hStatusBar
);
1407 ShowWindow(typelib
.hStatusBar
, vis
? SW_HIDE
: SW_SHOW
);
1408 CheckMenuItem(GetMenu(hWnd
), LOWORD(wParam
),
1409 vis
? MF_UNCHECKED
: MF_CHECKED
);
1410 TypeLibResizeChild();
1413 DestroyWindow(hWnd
);
1418 static void UpdateTypeLibStatusBar(int itemID
)
1420 WCHAR info
[MAX_LOAD_STRING
];
1422 if(!LoadStringW(globals
.hMainInst
, itemID
, info
, ARRAY_SIZE(info
)))
1423 LoadStringW(globals
.hMainInst
, IDS_READY
, info
, ARRAY_SIZE(info
));
1425 SendMessageW(typelib
.hStatusBar
, SB_SETTEXTW
, 0, (LPARAM
)info
);
1428 static void EmptyTLTree(void)
1433 tvi
.mask
= TVIF_PARAM
;
1434 cur
= (HTREEITEM
)SendMessageW(typelib
.hTree
, TVM_GETNEXTITEM
,
1435 TVGN_CHILD
, (LPARAM
)TVI_ROOT
);
1440 cur
= (HTREEITEM
)SendMessageW(typelib
.hTree
, TVM_GETNEXTITEM
,
1441 TVGN_CHILD
, (LPARAM
)del
);
1443 if(!cur
) cur
= (HTREEITEM
)SendMessageW(typelib
.hTree
,
1444 TVM_GETNEXTITEM
, TVGN_NEXT
, (LPARAM
)del
);
1445 if(!cur
) cur
= (HTREEITEM
)SendMessageW(typelib
.hTree
,
1446 TVM_GETNEXTITEM
, TVGN_PARENT
, (LPARAM
)del
);
1449 SendMessageW(typelib
.hTree
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
1452 HeapFree(GetProcessHeap(), 0, ((TYPELIB_DATA
*)tvi
.lParam
)->idl
);
1453 HeapFree(GetProcessHeap(), 0, (TYPELIB_DATA
*)tvi
.lParam
);
1456 SendMessageW(typelib
.hTree
, TVM_DELETEITEM
, 0, (LPARAM
)del
);
1462 static LRESULT CALLBACK
TypeLibProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1468 if(!CreatePanedWindow(hWnd
, &typelib
.hPaneWnd
, globals
.hMainInst
))
1469 DestroyWindow(hWnd
);
1470 typelib
.hTree
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_TREEVIEWW
, NULL
,
1471 WS_CHILD
|WS_VISIBLE
|TVS_HASLINES
|TVS_HASBUTTONS
|TVS_LINESATROOT
,
1472 0, 0, 0, 0, typelib
.hPaneWnd
, (HMENU
)TYPELIB_TREE
,
1473 globals
.hMainInst
, NULL
);
1474 typelib
.hEdit
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_EDITW
, NULL
,
1475 WS_CHILD
|WS_VISIBLE
|ES_MULTILINE
|ES_READONLY
|WS_HSCROLL
|WS_VSCROLL
,
1476 0, 0, 0, 0, typelib
.hPaneWnd
, NULL
, globals
.hMainInst
, NULL
);
1478 SetLeft(typelib
.hPaneWnd
, typelib
.hTree
);
1479 SetRight(typelib
.hPaneWnd
, typelib
.hEdit
);
1481 if(PopulateTree()) DestroyWindow(hWnd
);
1482 else SetFocus(typelib
.hTree
);
1486 TypeLibMenuCommand(LOWORD(wParam
), hWnd
);
1489 UpdateTypeLibStatusBar(LOWORD(wParam
));
1492 SetFocus(typelib
.hTree
);
1495 if(wParam
== SIZE_MINIMIZED
) break;
1496 TypeLibResizeChild();
1502 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
1507 BOOL
TypeLibRegisterClassW(void)
1511 memset(&wcc
, 0, sizeof(WNDCLASSW
));
1512 wcc
.lpfnWndProc
= TypeLibProc
;
1513 wcc
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
1514 wcc
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
1515 wcc
.lpszMenuName
= MAKEINTRESOURCEW(IDM_TYPELIB
);
1516 wcc
.lpszClassName
= wszTypeLib
;
1518 if(!RegisterClassW(&wcc
))
1524 BOOL
CreateTypeLibWindow(HINSTANCE hInst
, WCHAR
*wszFileName
)
1526 WCHAR wszTitle
[MAX_LOAD_STRING
];
1527 LoadStringW(hInst
, IDS_TYPELIBTITLE
, wszTitle
, ARRAY_SIZE(wszTitle
));
1529 if(wszFileName
) lstrcpyW(typelib
.wszFileName
, wszFileName
);
1534 memset(&tvi
, 0, sizeof(TVITEMW
));
1535 tvi
.hItem
= (HTREEITEM
)SendMessageW(globals
.hTree
, TVM_GETNEXTITEM
,
1538 SendMessageW(globals
.hTree
, TVM_GETITEMW
, 0, (LPARAM
)&tvi
);
1539 lstrcpyW(typelib
.wszFileName
, ((ITEM_INFO
*)tvi
.lParam
)->path
);
1542 globals
.hTypeLibWnd
= CreateWindowW(wszTypeLib
, wszTitle
,
1543 WS_OVERLAPPEDWINDOW
|WS_VISIBLE
,
1544 CW_USEDEFAULT
, CW_USEDEFAULT
, 800, 600, NULL
, NULL
, hInst
, NULL
);
1545 if(!globals
.hTypeLibWnd
) return FALSE
;
1547 typelib
.hStatusBar
= CreateStatusWindowW(WS_VISIBLE
|WS_CHILD
,
1548 wszTitle
, globals
.hTypeLibWnd
, 0);
1550 TypeLibResizeChild();