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"
24 #include "wine/unicode.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(oleview
);
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();
105 WCHAR wszTitle
[MAX_LOAD_STRING
];
107 LoadString(globals
.hMainInst
, IDS_TYPELIBTITLE
, wszTitle
,
108 sizeof(WCHAR
[MAX_LOAD_STRING
]));
109 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
110 NULL
, error
, 0, (LPTSTR
) &lpMsgBuf
, 0, NULL
);
111 MessageBox(NULL
, lpMsgBuf
, wszTitle
, MB_OK
| MB_ICONERROR
);
116 static void SaveIdl(WCHAR
*wszFileName
)
121 DWORD len
, dwNumWrite
;
125 hIDL
= TreeView_GetChild(typelib
.hTree
, TVI_ROOT
);
127 memset(&tvi
, 0, sizeof(TVITEM
));
130 SendMessage(typelib
.hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
131 data
= (TYPELIB_DATA
*)tvi
.lParam
;
133 hFile
= CreateFile(wszFileName
, GENERIC_WRITE
, FILE_SHARE_WRITE
,
134 NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
135 if(hFile
== INVALID_HANDLE_VALUE
)
141 len
= WideCharToMultiByte( CP_UTF8
, 0, data
->idl
, data
->idlLen
, NULL
, 0, NULL
, NULL
);
142 wszIdl
= HeapAlloc(GetProcessHeap(), 0, len
);
143 WideCharToMultiByte( CP_UTF8
, 0, data
->idl
, data
->idlLen
, wszIdl
, len
, NULL
, NULL
);
145 if(!WriteFile(hFile
, wszIdl
, len
, &dwNumWrite
, NULL
))
148 HeapFree(GetProcessHeap(), 0, wszIdl
);
152 static void GetSaveIdlAsPath(void)
154 OPENFILENAME saveidl
;
156 WCHAR wszPath
[MAX_LOAD_STRING
];
157 WCHAR wszDir
[MAX_LOAD_STRING
];
158 static const WCHAR wszDefaultExt
[] = { 'i','d','l',0 };
159 static const WCHAR wszIdlFiles
[] = { '*','.','i','d','l','\0','\0' };
161 memset(&saveidl
, 0, sizeof(saveidl
));
163 lstrcpyW(wszDir
, typelib
.wszFileName
);
164 pFileName
= wszDir
+ lstrlenW(wszDir
);
165 while(*pFileName
!= '.' && *pFileName
!= '\\' && *pFileName
!= '/'
166 && pFileName
> wszDir
) pFileName
-= 1;
167 if(*pFileName
== '.')
170 while(*pFileName
!= '\\' && *pFileName
!= '/' && pFileName
> wszDir
)
173 if(*pFileName
== '\\' || *pFileName
== '/') pFileName
+= 1;
174 lstrcpyW(wszPath
, pFileName
);
176 GetCurrentDirectory(MAX_LOAD_STRING
, wszDir
);
178 saveidl
.lStructSize
= sizeof(OPENFILENAME
);
179 saveidl
.hwndOwner
= globals
.hTypeLibWnd
;
180 saveidl
.hInstance
= globals
.hMainInst
;
181 saveidl
.lpstrFilter
= wszIdlFiles
;
182 saveidl
.lpstrFile
= wszPath
;
183 saveidl
.nMaxFile
= MAX_LOAD_STRING
;
184 saveidl
.lpstrInitialDir
= wszDir
;
185 saveidl
.Flags
= OFN_PATHMUSTEXIST
| OFN_OVERWRITEPROMPT
| OFN_HIDEREADONLY
;
186 saveidl
.lpstrDefExt
= wszDefaultExt
;
188 if (GetSaveFileName(&saveidl
))
192 void AddToStrW(WCHAR
*wszDest
, const WCHAR
*wszSource
)
194 lstrcpyW(&wszDest
[lstrlenW(wszDest
)], wszSource
);
197 void AddToTLDataStrW(TYPELIB_DATA
*pTLData
, const WCHAR
*wszSource
)
199 int SourceLen
= lstrlenW(wszSource
);
201 pTLData
->idl
= HeapReAlloc(GetProcessHeap(), 0, pTLData
->idl
,
202 sizeof(WCHAR
)*(pTLData
->idlLen
+SourceLen
+1));
204 memcpy(&pTLData
->idl
[pTLData
->idlLen
], wszSource
, sizeof(WCHAR
)*(SourceLen
+1));
205 pTLData
->idlLen
+= SourceLen
;
208 void AddToTLDataStrWithTabsW(TYPELIB_DATA
*pTLData
, WCHAR
*wszSource
)
210 int lineLen
= lstrlenW(wszSource
);
212 WCHAR
*pSourcePos
= (WCHAR
*)wszSource
;
218 if(*pSourcePos
== *wszNewLine
) newLinesNo
++;
221 if(*(pSourcePos
- 1) != *wszNewLine
) newLinesNo
++;
223 pTLData
->idl
= HeapReAlloc(GetProcessHeap(), 0, pTLData
->idl
,
224 sizeof(WCHAR
)*(pTLData
->idlLen
+lineLen
+4*newLinesNo
+1));
226 pSourcePos
= (WCHAR
*)wszSource
;
227 pSourceBeg
= (WCHAR
*)wszSource
;
230 if(*pSourcePos
!= *wszNewLine
&& *pSourcePos
)
240 lineLen
= lstrlenW(pSourceBeg
)+1;
244 else lineLen
= lstrlenW(pSourceBeg
);
246 pTLData
->idl
[pTLData
->idlLen
] = *wszSpace
;
247 pTLData
->idl
[pTLData
->idlLen
+1] = *wszSpace
;
248 pTLData
->idl
[pTLData
->idlLen
+2] = *wszSpace
;
249 pTLData
->idl
[pTLData
->idlLen
+3] = *wszSpace
;
250 memcpy(&pTLData
->idl
[pTLData
->idlLen
+4], pSourceBeg
, sizeof(WCHAR
)*lineLen
);
251 pTLData
->idlLen
+= lineLen
+ 4;
252 pTLData
->idl
[pTLData
->idlLen
] = '\0';
254 pSourceBeg
= pSourcePos
;
258 static TYPELIB_DATA
*InitializeTLData(void)
260 TYPELIB_DATA
*pTLData
;
262 pTLData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(TYPELIB_DATA
));
264 pTLData
->idl
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
));
265 pTLData
->idl
[0] = '\0';
270 static void AddSpaces(TYPELIB_DATA
*pTLData
, int tabSize
)
272 for(; tabSize
>0; tabSize
--)
273 AddToTLDataStrW(pTLData
, wszSpace
);
276 static void AddChildrenData(HTREEITEM hParent
, TYPELIB_DATA
*pData
)
281 memset(&tvi
, 0, sizeof(&tvi
));
283 hCur
= TreeView_GetChild(typelib
.hTree
, hParent
);
289 SendMessage(typelib
.hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
290 if(tvi
.lParam
&& ((TYPELIB_DATA
*)(tvi
.lParam
))->idlLen
)
291 AddToTLDataStrWithTabsW(pData
, ((TYPELIB_DATA
*)(tvi
.lParam
))->idl
);
292 }while((hCur
= TreeView_GetNextSibling(typelib
.hTree
, hCur
)));
295 static void CreateTypeInfo(WCHAR
*wszAddTo
, WCHAR
*wszAddAfter
, TYPEDESC tdesc
, ITypeInfo
*pTypeInfo
)
300 ITypeInfo
*pRefTypeInfo
;
301 WCHAR wszBuf
[MAX_LOAD_STRING
];
302 WCHAR wszFormat
[] = { '[','%','l','u',']','\0' };
304 switch(tdesc
.vt
&VT_TYPEMASK
)
306 #define VTADDTOSTR(x) case x:\
307 AddToStrW(wszAddTo, wsz##x);\
323 VTADDTOSTR(VT_VARIANT
);
325 VTADDTOSTR(VT_ERROR
);
326 VTADDTOSTR(VT_LPSTR
);
327 VTADDTOSTR(VT_LPWSTR
);
328 VTADDTOSTR(VT_HRESULT
);
329 VTADDTOSTR(VT_UNKNOWN
);
330 VTADDTOSTR(VT_DISPATCH
);
334 for(i
=0; i
<U(tdesc
).lpadesc
->cDims
; i
++)
336 wsprintfW(wszBuf
, wszFormat
, U(tdesc
).lpadesc
->rgbounds
[i
].cElements
);
337 AddToStrW(wszAddAfter
, wszBuf
);
339 CreateTypeInfo(wszAddTo
, wszAddAfter
, U(tdesc
).lpadesc
->tdescElem
, pTypeInfo
);
342 AddToStrW(wszAddTo
, wszVT_SAFEARRAY
);
343 AddToStrW(wszAddTo
, wszOpenBrackets2
);
344 CreateTypeInfo(wszAddTo
, wszAddAfter
, *U(tdesc
).lptdesc
, pTypeInfo
);
345 AddToStrW(wszAddTo
, wszCloseBrackets2
);
348 CreateTypeInfo(wszAddTo
, wszAddAfter
, *U(tdesc
).lptdesc
, pTypeInfo
);
349 AddToStrW(wszAddTo
, wszAsterix
);
352 hRes
= ITypeInfo_GetRefTypeInfo(pTypeInfo
,
353 U(tdesc
).hreftype
, &pRefTypeInfo
);
356 ITypeInfo_GetDocumentation(pRefTypeInfo
, MEMBERID_NIL
,
357 &bstrData
, NULL
, NULL
, NULL
);
358 AddToStrW(wszAddTo
, bstrData
);
359 SysFreeString(bstrData
);
360 ITypeInfo_Release(pRefTypeInfo
);
362 else AddToStrW(wszAddTo
, wszFailed
);
365 WINE_FIXME("tdesc.vt&VT_TYPEMASK == %d not supported\n",
366 tdesc
.vt
&VT_TYPEMASK
);
370 static int EnumVars(ITypeInfo
*pTypeInfo
, int cVars
, HTREEITEM hParent
)
376 WCHAR wszText
[MAX_LOAD_STRING
];
377 WCHAR wszAfter
[MAX_LOAD_STRING
];
379 U(tvis
).item
.mask
= TVIF_TEXT
|TVIF_PARAM
;
380 U(tvis
).item
.cchTextMax
= MAX_LOAD_STRING
;
381 U(tvis
).item
.pszText
= wszText
;
382 tvis
.hInsertAfter
= (HTREEITEM
)TVI_LAST
;
383 tvis
.hParent
= hParent
;
385 for(i
=0; i
<cVars
; i
++)
389 if(FAILED(ITypeInfo_GetVarDesc(pTypeInfo
, i
, &pVarDesc
))) continue;
390 if(FAILED(ITypeInfo_GetDocumentation(pTypeInfo
, pVarDesc
->memid
, &bstrName
,
391 NULL
, NULL
, NULL
))) continue;
393 tld
= InitializeTLData();
394 U(tvis
).item
.lParam
= (LPARAM
) tld
;
395 if(pVarDesc
->memid
< MIN_VAR_ID
)
398 AddToTLDataStrW(tld
, wszOpenBrackets1
);
399 AddToTLDataStrW(tld
, wszId
);
400 AddToTLDataStrW(tld
, wszOpenBrackets2
);
401 wsprintfW(wszText
, wszFormat
, pVarDesc
->memid
);
402 AddToTLDataStrW(tld
, wszText
);
403 memset(wszText
, 0, sizeof(wszText
));
404 AddToTLDataStrW(tld
, wszCloseBrackets2
);
406 if(pVarDesc
->wVarFlags
& VARFLAG_FREADONLY
)
408 AddToTLDataStrW(tld
, wszComa
);
409 AddToTLDataStrW(tld
, wszSpace
);
410 AddToTLDataStrW(tld
, wszReadOnly
);
412 AddToTLDataStrW(tld
, wszCloseBrackets1
);
413 AddToTLDataStrW(tld
, wszNewLine
);
416 memset(wszText
, 0, sizeof(wszText
));
417 memset(wszAfter
, 0, sizeof(wszAfter
));
418 CreateTypeInfo(wszText
, wszAfter
, pVarDesc
->elemdescVar
.tdesc
, pTypeInfo
);
419 AddToStrW(wszText
, wszSpace
);
420 AddToStrW(wszText
, bstrName
);
421 AddToStrW(wszText
, wszAfter
);
422 AddToTLDataStrW(tld
, wszText
);
423 AddToTLDataStrW(tld
, wszSemicolon
);
424 AddToTLDataStrW(tld
, wszNewLine
);
426 SendMessage(typelib
.hTree
, TVM_INSERTITEM
, 0, (LPARAM
)&tvis
);
427 SysFreeString(bstrName
);
428 ITypeInfo_ReleaseVarDesc(pTypeInfo
, pVarDesc
);
434 static int EnumEnums(ITypeInfo
*pTypeInfo
, int cVars
, HTREEITEM hParent
)
440 WCHAR wszText
[MAX_LOAD_STRING
];
441 WCHAR wszAfter
[MAX_LOAD_STRING
];
443 U(tvis
).item
.mask
= TVIF_TEXT
|TVIF_PARAM
;
444 U(tvis
).item
.cchTextMax
= MAX_LOAD_STRING
;
445 U(tvis
).item
.pszText
= wszText
;
446 tvis
.hInsertAfter
= (HTREEITEM
)TVI_LAST
;
447 tvis
.hParent
= hParent
;
449 for(i
=0; i
<cVars
; i
++)
453 if(FAILED(ITypeInfo_GetVarDesc(pTypeInfo
, i
, &pVarDesc
))) continue;
454 if(FAILED(ITypeInfo_GetDocumentation(pTypeInfo
, pVarDesc
->memid
, &bstrName
,
455 NULL
, NULL
, NULL
))) continue;
457 tld
= InitializeTLData();
458 U(tvis
).item
.lParam
= (LPARAM
) tld
;
460 memset(wszText
, 0, sizeof(wszText
));
461 memset(wszAfter
, 0, sizeof(wszAfter
));
463 if (pVarDesc
->varkind
== VAR_CONST
)
467 if (VariantChangeType(&var
, U(*pVarDesc
).lpvarValue
, 0, VT_BSTR
) == S_OK
)
469 AddToStrW(wszText
, wszConst
);
470 AddToStrW(wszText
, wszSpace
);
471 AddToStrW(wszAfter
, wszSpace
);
472 AddToStrW(wszAfter
, wszEquals
);
473 AddToStrW(wszAfter
, wszSpace
);
474 AddToStrW(wszAfter
, V_BSTR(&var
));
478 CreateTypeInfo(wszText
, wszAfter
, pVarDesc
->elemdescVar
.tdesc
, pTypeInfo
);
479 AddToStrW(wszText
, wszSpace
);
480 AddToStrW(wszText
, bstrName
);
481 AddToStrW(wszText
, wszAfter
);
482 AddToTLDataStrW(tld
, bstrName
);
483 AddToTLDataStrW(tld
, wszAfter
);
485 AddToTLDataStrW(tld
, wszComa
);
486 AddToTLDataStrW(tld
, wszNewLine
);
488 SendMessage(typelib
.hTree
, TVM_INSERTITEM
, 0, (LPARAM
)&tvis
);
489 SysFreeString(bstrName
);
490 ITypeInfo_ReleaseVarDesc(pTypeInfo
, pVarDesc
);
496 static int EnumFuncs(ITypeInfo
*pTypeInfo
, TYPEATTR
*pTypeAttr
, HTREEITEM hParent
)
503 BSTR bstrName
, bstrHelpString
, *bstrParamNames
;
504 WCHAR wszText
[MAX_LOAD_STRING
];
505 WCHAR wszAfter
[MAX_LOAD_STRING
];
506 WCHAR szRhs
[] = {'r','h','s',0}; /* Right-hand side of a propput */
509 U(tvis
).item
.mask
= TVIF_TEXT
|TVIF_PARAM
;
510 tvis
.hInsertAfter
= (HTREEITEM
)TVI_LAST
;
511 tvis
.hParent
= hParent
;
513 cFuncs
= pTypeAttr
->cFuncs
;
516 if(pTypeAttr
->wTypeFlags
& TYPEFLAG_FDUAL
) { /* skip 7 members of IDispatch */
525 if(FAILED(ITypeInfo_GetFuncDesc(pTypeInfo
, i
, &pFuncDesc
))) continue;
527 if(FAILED(ITypeInfo_GetDocumentation(pTypeInfo
, pFuncDesc
->memid
, &bstrName
,
528 &bstrHelpString
, NULL
, NULL
))) continue;
530 memset(wszText
, 0, sizeof(wszText
));
531 memset(wszAfter
, 0, sizeof(wszAfter
));
532 tld
= InitializeTLData();
533 U(tvis
).item
.cchTextMax
= SysStringLen(bstrName
);
534 U(tvis
).item
.pszText
= bstrName
;
535 U(tvis
).item
.lParam
= (LPARAM
) tld
;
537 if(pFuncDesc
->memid
< MIN_FUNC_ID
|| pTypeAttr
->wTypeFlags
& TYPEFLAG_FDUAL
)
539 AddToTLDataStrW(tld
, wszOpenBrackets1
);
541 AddToTLDataStrW(tld
, wszId
);
542 AddToTLDataStrW(tld
, wszOpenBrackets2
);
543 wsprintfW(wszText
, wszFormat
, pFuncDesc
->memid
);
544 AddToTLDataStrW(tld
, wszText
);
545 AddToTLDataStrW(tld
, wszCloseBrackets2
);
546 memset(wszText
, 0, sizeof(wszText
));
548 if(SysStringLen(bstrHelpString
)) {
549 if(bFirst
) AddToTLDataStrW(tld
, wszOpenBrackets1
);
551 AddToTLDataStrW(tld
, wszComa
);
552 AddToTLDataStrW(tld
, wszSpace
);
555 AddToTLDataStrW(tld
, wszHelpstring
);
556 AddToTLDataStrW(tld
, wszOpenBrackets2
);
557 AddToTLDataStrW(tld
, wszInvertedComa
);
558 AddToTLDataStrW(tld
, bstrHelpString
);
559 AddToTLDataStrW(tld
, wszInvertedComa
);
560 AddToTLDataStrW(tld
, wszCloseBrackets2
);
562 CreateTypeInfo(wszText
, wszAfter
, pFuncDesc
->elemdescFunc
.tdesc
, pTypeInfo
);
563 switch(pFuncDesc
->invkind
)
565 case INVOKE_PROPERTYGET
:
566 if(bFirst
) AddToTLDataStrW(tld
, wszOpenBrackets1
);
569 AddToTLDataStrW(tld
, wszComa
);
570 AddToTLDataStrW(tld
, wszSpace
);
573 AddToTLDataStrW(tld
, wszPropGet
);
575 case INVOKE_PROPERTYPUT
:
576 if(bFirst
) AddToTLDataStrW(tld
, wszOpenBrackets1
);
579 AddToTLDataStrW(tld
, wszComa
);
580 AddToTLDataStrW(tld
, wszSpace
);
583 AddToTLDataStrW(tld
, wszPropPut
);
585 case INVOKE_PROPERTYPUTREF
:
586 if(bFirst
) AddToTLDataStrW(tld
, wszOpenBrackets1
);
589 AddToTLDataStrW(tld
, wszComa
);
590 AddToTLDataStrW(tld
, wszSpace
);
593 AddToTLDataStrW(tld
, wszPropPutRef
);
599 AddToTLDataStrW(tld
, wszCloseBrackets1
);
600 AddToTLDataStrW(tld
, wszNewLine
);
603 if(pTypeAttr
->wTypeFlags
& TYPEFLAG_FOLEAUTOMATION
) {
604 AddToTLDataStrW(tld
, wszVT_HRESULT
);
605 if(strcmpW(wszText
, wszVT_VOID
)) pFuncDesc
->cParams
++;
608 AddToTLDataStrW(tld
, wszText
);
609 AddToTLDataStrW(tld
, wszAfter
);
612 bstrParamNames
= HeapAlloc(GetProcessHeap(), 0,
613 sizeof(BSTR
*)*(pFuncDesc
->cParams
+1));
614 if(FAILED(ITypeInfo_GetNames(pTypeInfo
, pFuncDesc
->memid
, bstrParamNames
,
615 pFuncDesc
->cParams
+1, &namesNo
)))
617 HeapFree(GetProcessHeap(), 0, bstrParamNames
);
620 SysFreeString(bstrParamNames
[0]);
622 AddToTLDataStrW(tld
, wszSpace
);
623 if(pFuncDesc
->memid
>= MIN_FUNC_ID
)
625 AddToTLDataStrW(tld
, wszStdCall
);
626 AddToTLDataStrW(tld
, wszSpace
);
628 AddToTLDataStrW(tld
, bstrName
);
629 AddToTLDataStrW(tld
, wszOpenBrackets2
);
631 for(j
=0; j
<pFuncDesc
->cParams
; j
++)
633 if(j
!= 0) AddToTLDataStrW(tld
, wszComa
);
634 if(pFuncDesc
->cParams
!= 1)
636 AddToTLDataStrW(tld
, wszNewLine
);
640 #define ENUM_PARAM_FLAG(x)\
641 if(U(pFuncDesc->lprgelemdescParam[j]).paramdesc.wParamFlags & x) \
643 if(bFirst) AddToTLDataStrW(tld,\
647 AddToTLDataStrW(tld, wszComa);\
648 AddToTLDataStrW(tld, wszSpace);\
651 AddToTLDataStrW(tld, wsz##x);\
653 ENUM_PARAM_FLAG(PARAMFLAG_FIN
);
654 ENUM_PARAM_FLAG(PARAMFLAG_FOUT
);
655 ENUM_PARAM_FLAG(PARAMFLAG_FLCID
);
656 ENUM_PARAM_FLAG(PARAMFLAG_FRETVAL
);
657 ENUM_PARAM_FLAG(PARAMFLAG_FOPT
);
658 ENUM_PARAM_FLAG(PARAMFLAG_FHASCUSTDATA
);
660 if(U(pFuncDesc
->lprgelemdescParam
[j
]).paramdesc
.wParamFlags
& PARAMFLAG_FHASDEFAULT
)
662 VARIANT var
, *param
=&U(pFuncDesc
->lprgelemdescParam
[j
]).paramdesc
.pparamdescex
->varDefaultValue
;
664 if(bFirst
) AddToTLDataStrW(tld
,
668 AddToTLDataStrW(tld
, wszComa
);
669 AddToTLDataStrW(tld
, wszSpace
);
672 AddToTLDataStrW(tld
, wszDefaultValue
);
673 AddToTLDataStrW(tld
, wszOpenBrackets2
);
674 if (V_VT(param
) == VT_BSTR
)
676 AddToTLDataStrW(tld
, wszInvertedComa
);
677 AddToTLDataStrW(tld
, V_BSTR(&var
));
678 AddToTLDataStrW(tld
, wszInvertedComa
);
679 } else if (VariantChangeType(&var
, param
, 0, VT_BSTR
) == S_OK
)
680 AddToTLDataStrW(tld
, V_BSTR(&var
));
681 AddToTLDataStrW(tld
, wszCloseBrackets2
);
686 AddToTLDataStrW(tld
, wszCloseBrackets1
);
687 AddToTLDataStrW(tld
, wszSpace
);
690 memset(wszText
, 0, sizeof(wszText
));
691 memset(wszAfter
, 0, sizeof(wszAfter
));
692 CreateTypeInfo(wszText
, wszAfter
, pFuncDesc
->lprgelemdescParam
[j
].tdesc
,
694 AddToTLDataStrW(tld
, wszText
);
695 AddToTLDataStrW(tld
, wszAfter
);
696 AddToTLDataStrW(tld
, wszSpace
);
698 AddToTLDataStrW(tld
, bstrParamNames
[j
+1]);
699 SysFreeString(bstrParamNames
[j
+1]);
701 AddToTLDataStrW(tld
, szRhs
);
704 AddToTLDataStrW(tld
, wszCloseBrackets2
);
705 AddToTLDataStrW(tld
, wszSemicolon
);
706 AddToTLDataStrW(tld
, wszNewLine
);
708 SendMessage(typelib
.hTree
, TVM_INSERTITEM
, 0, (LPARAM
)&tvis
);
709 HeapFree(GetProcessHeap(), 0, bstrParamNames
);
710 SysFreeString(bstrName
);
711 SysFreeString(bstrHelpString
);
712 ITypeInfo_ReleaseFuncDesc(pTypeInfo
, pFuncDesc
);
718 static int EnumImplTypes(ITypeInfo
*pTypeInfo
, int cImplTypes
, HTREEITEM hParent
)
722 ITypeInfo
*pRefTypeInfo
;
726 WCHAR wszInheritedInterfaces
[MAX_LOAD_STRING
];
728 if(!cImplTypes
) return 0;
730 LoadString(globals
.hMainInst
, IDS_INHERITINTERFACES
, wszInheritedInterfaces
,
731 sizeof(WCHAR
[MAX_LOAD_STRING
]));
733 U(tvis
).item
.mask
= TVIF_TEXT
;
734 U(tvis
).item
.cchTextMax
= MAX_LOAD_STRING
;
735 U(tvis
).item
.pszText
= wszInheritedInterfaces
;
736 tvis
.hInsertAfter
= (HTREEITEM
)TVI_LAST
;
737 tvis
.hParent
= hParent
;
739 tvis
.hParent
= TreeView_InsertItem(typelib
.hTree
, &tvis
);
741 for(i
=0; i
<cImplTypes
; i
++)
743 if(FAILED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo
, i
, &hRefType
))) continue;
744 if(FAILED(ITypeInfo_GetRefTypeInfo(pTypeInfo
, hRefType
, &pRefTypeInfo
)))
746 if(FAILED(ITypeInfo_GetDocumentation(pRefTypeInfo
, MEMBERID_NIL
, &bstrName
,
747 NULL
, NULL
, NULL
))) continue;
748 if(FAILED(ITypeInfo_GetTypeAttr(pRefTypeInfo
, &pTypeAttr
))) continue;
750 U(tvis
).item
.cchTextMax
= SysStringLen(bstrName
);
751 U(tvis
).item
.pszText
= bstrName
;
753 hParent
= TreeView_InsertItem(typelib
.hTree
, &tvis
);
754 EnumVars(pRefTypeInfo
, pTypeAttr
->cVars
, hParent
);
755 EnumFuncs(pRefTypeInfo
, pTypeAttr
, hParent
);
756 EnumImplTypes(pRefTypeInfo
, pTypeAttr
->cImplTypes
, hParent
);
758 SysFreeString(bstrName
);
759 ITypeInfo_ReleaseTypeAttr(pRefTypeInfo
, pTypeAttr
);
760 ITypeInfo_Release(pRefTypeInfo
);
766 static void AddIdlData(HTREEITEM hCur
, TYPELIB_DATA
*pTLData
)
770 hCur
= TreeView_GetChild(typelib
.hTree
, hCur
);
771 memset(&tvi
, 0, sizeof(TVITEM
));
772 tvi
.mask
= TVIF_PARAM
;
777 SendMessage(typelib
.hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
778 if(!((TYPELIB_DATA
*)(tvi
.lParam
))->bHide
) {
779 AddToTLDataStrW(pTLData
, wszNewLine
);
780 AddToTLDataStrWithTabsW(pTLData
, ((TYPELIB_DATA
*)(tvi
.lParam
))->idl
);
782 hCur
= TreeView_GetNextSibling(typelib
.hTree
, hCur
);
786 static void AddPredefinitions(HTREEITEM hFirst
, TYPELIB_DATA
*pTLData
)
790 WCHAR wszText
[MAX_LOAD_STRING
];
791 WCHAR wszPredefinition
[] = { '/','/',' ','T','L','i','b',' ',':','\n',
792 '/','/',' ','F','o','r','w','a','r','d',' ','d','e','c','l','a','r','e',' ',
793 'a','l','l',' ','t','y','p','e','s',' ','d','e','f','i','n','e','d',' ',
794 'i','n',' ','t','h','i','s',' ','t','y','p','e','l','i','b','\0' };
796 hFirst
= TreeView_GetChild(typelib
.hTree
, hFirst
);
798 AddToTLDataStrWithTabsW(pTLData
, wszPredefinition
);
799 AddToTLDataStrW(pTLData
, wszNewLine
);
802 memset(&tvi
, 0, sizeof(TVITEM
));
803 tvi
.mask
= TVIF_TEXT
|TVIF_PARAM
;
804 tvi
.cchTextMax
= MAX_LOAD_STRING
;
805 tvi
.pszText
= wszText
;
809 SendMessage(typelib
.hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
810 if(((TYPELIB_DATA
*)(tvi
.lParam
))->bPredefine
&&
811 !((TYPELIB_DATA
*)(tvi
.lParam
))->bHide
)
813 AddToStrW(wszText
, wszSemicolon
);
814 AddToTLDataStrWithTabsW(pTLData
, wszText
);
815 AddToTLDataStrW(pTLData
, wszNewLine
);
817 hCur
= TreeView_GetNextSibling(typelib
.hTree
, hCur
);
821 static void CreateInterfaceInfo(ITypeInfo
*pTypeInfo
, int cImplTypes
, WCHAR
*wszName
,
822 WCHAR
*wszHelpString
, unsigned long ulHelpContext
, TYPEATTR
*pTypeAttr
,
823 TYPELIB_DATA
*pTLData
)
825 ITypeInfo
*pRefTypeInfo
;
828 WCHAR wszGuid
[MAX_LOAD_STRING
];
829 WCHAR wszHelpContext
[MAX_LOAD_STRING
];
831 const WCHAR wszInterface
[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' };
832 const WCHAR wszDispinterface
[]
833 = { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' };
834 const WCHAR wszHelpcontext
[] = { 'h','e','l','p','c','o','n','t','e','x','t','\0' };
835 const WCHAR wszTYPEFLAG_FAPPOBJECT
[] = { 'a','p','p','o','b','j','e','c','t','\0' };
836 const WCHAR wszTYPEFLAG_FCANCREATE
[] = { 'c','a','n','c','r','e','a','t','e','\0' };
837 const WCHAR wszTYPEFLAG_FLICENSED
[] = { 'l','i','c','e','n','s','e','d','\0' };
838 const WCHAR wszTYPEFLAG_FPREDECLID
[] = { 'p','r','e','d','e','c','l','i','d','\0' };
839 const WCHAR wszTYPEFLAG_FHIDDEN
[] = { 'h','i','d','d','e','n','\0' };
840 const WCHAR wszTYPEFLAG_FCONTROL
[] = { 'c','o','n','t','r','o','l','\0' };
841 const WCHAR wszTYPEFLAG_FDUAL
[] = { 'd','u','a','l','\0' };
842 const WCHAR wszTYPEFLAG_FNONEXTENSIBLE
[]
843 = { 'n','o','n','e','x','t','e','n','s','i','b','l','e','\0' };
844 const WCHAR wszTYPEFLAG_FOLEAUTOMATION
[]
845 = { 'o','l','e','a','u','t','o','m','a','t','i','o','n','\0' };
846 const WCHAR wszTYPEFLAG_FRESTRICTED
[]
847 = { 'r','e','s','t','r','i','c','t','e','d','\0' };
848 const WCHAR wszTYPEFLAG_FAGGREGATABLE
[]
849 = { 'a','g','g','r','e','g','a','t','a','b','l','e','\0' };
850 const WCHAR wszTYPEFLAG_FREPLACEABLE
[]
851 = { 'r','e','p','l','a','c','a','b','l','e','\0' };
852 const WCHAR wszTYPEFLAG_FREVERSEBIND
[]
853 = { 'r','e','v','e','r','s','e','b','i','n','d','\0' };
854 const WCHAR wszTYPEFLAG_FPROXY
[] = { 'p','r','o','x','y','\0' };
856 AddToTLDataStrW(pTLData
, wszOpenBrackets1
);
857 AddToTLDataStrW(pTLData
, wszNewLine
);
858 if(pTypeAttr
->typekind
!= TKIND_DISPATCH
)
860 AddSpaces(pTLData
, 4);
861 AddToTLDataStrW(pTLData
, wszOdl
);
862 AddToTLDataStrW(pTLData
, wszComa
);
863 AddToTLDataStrW(pTLData
, wszNewLine
);
865 AddSpaces(pTLData
, 4);
866 AddToTLDataStrW(pTLData
, wszUUID
);
867 AddToTLDataStrW(pTLData
, wszOpenBrackets2
);
868 StringFromGUID2(&(pTypeAttr
->guid
), wszGuid
, MAX_LOAD_STRING
);
869 wszGuid
[lstrlenW(wszGuid
)-1] = '\0';
870 AddToTLDataStrW(pTLData
, &wszGuid
[1]);
871 AddToTLDataStrW(pTLData
, wszCloseBrackets2
);
874 AddToTLDataStrW(pTLData
, wszComa
);
875 AddToTLDataStrW(pTLData
, wszNewLine
);
876 AddSpaces(pTLData
, 4);
877 AddToTLDataStrW(pTLData
, wszHelpstring
);
878 AddToTLDataStrW(pTLData
, wszOpenBrackets2
);
879 AddToTLDataStrW(pTLData
, wszInvertedComa
);
880 AddToTLDataStrW(pTLData
, wszHelpString
);
881 AddToTLDataStrW(pTLData
, wszInvertedComa
);
882 AddToTLDataStrW(pTLData
, wszCloseBrackets2
);
886 AddToTLDataStrW(pTLData
, wszComa
);
887 AddToTLDataStrW(pTLData
, wszNewLine
);
888 AddSpaces(pTLData
, 4);
889 AddToTLDataStrW(pTLData
, wszHelpcontext
);
890 AddToTLDataStrW(pTLData
, wszOpenBrackets2
);
891 wsprintfW(wszHelpContext
, wszFormat
, ulHelpContext
);
892 AddToTLDataStrW(pTLData
, wszHelpContext
);
893 AddToTLDataStrW(pTLData
, wszCloseBrackets2
);
895 if(pTypeAttr
->wTypeFlags
)
897 #define ENUM_FLAGS(x) if(pTypeAttr->wTypeFlags & x &&\
898 (pTypeAttr->typekind != TKIND_DISPATCH || x != TYPEFLAG_FDISPATCHABLE))\
900 AddToTLDataStrW(pTLData, wszComa);\
901 AddToTLDataStrW(pTLData, wszNewLine);\
902 AddSpaces(pTLData, 4);\
903 AddToTLDataStrW(pTLData, wsz##x);\
905 ENUM_FLAGS(TYPEFLAG_FAPPOBJECT
);
906 ENUM_FLAGS(TYPEFLAG_FCANCREATE
);
907 ENUM_FLAGS(TYPEFLAG_FLICENSED
);
908 ENUM_FLAGS(TYPEFLAG_FPREDECLID
);
909 ENUM_FLAGS(TYPEFLAG_FHIDDEN
);
910 ENUM_FLAGS(TYPEFLAG_FCONTROL
);
911 ENUM_FLAGS(TYPEFLAG_FDUAL
);
912 ENUM_FLAGS(TYPEFLAG_FNONEXTENSIBLE
);
913 ENUM_FLAGS(TYPEFLAG_FOLEAUTOMATION
);
914 ENUM_FLAGS(TYPEFLAG_FRESTRICTED
);
915 ENUM_FLAGS(TYPEFLAG_FAGGREGATABLE
);
916 ENUM_FLAGS(TYPEFLAG_FREPLACEABLE
);
917 ENUM_FLAGS(TYPEFLAG_FREVERSEBIND
);
918 ENUM_FLAGS(TYPEFLAG_FPROXY
);
920 AddToTLDataStrW(pTLData
, wszNewLine
);
921 AddToTLDataStrW(pTLData
, wszCloseBrackets1
);
922 AddToTLDataStrW(pTLData
, wszNewLine
);
923 if(pTypeAttr
->typekind
!= TKIND_DISPATCH
) AddToTLDataStrW(pTLData
, wszInterface
);
924 else AddToTLDataStrW(pTLData
, wszDispinterface
);
925 AddToTLDataStrW(pTLData
, wszName
);
926 AddToTLDataStrW(pTLData
, wszSpace
);
927 if(cImplTypes
&& pTypeAttr
->typekind
!= TKIND_DISPATCH
)
929 AddToTLDataStrW(pTLData
, wszColon
);
930 AddToTLDataStrW(pTLData
, wszSpace
);
932 ITypeInfo_GetRefTypeOfImplType(pTypeInfo
, 0, &hRefType
);
933 if (SUCCEEDED(ITypeInfo_GetRefTypeInfo(pTypeInfo
, hRefType
, &pRefTypeInfo
)))
935 ITypeInfo_GetDocumentation(pRefTypeInfo
, MEMBERID_NIL
, &bstrName
,
937 AddToTLDataStrW(pTLData
, bstrName
);
938 AddToTLDataStrW(pTLData
, wszSpace
);
940 SysFreeString(bstrName
);
941 ITypeInfo_Release(pRefTypeInfo
);
944 AddToTLDataStrW(pTLData
, wszFailed
);
946 AddToTLDataStrW(pTLData
, wszOpenBrackets3
);
947 AddToTLDataStrW(pTLData
, wszNewLine
);
949 AddToStrW(pTLData
->wszInsertAfter
, wszCloseBrackets3
);
950 AddToStrW(pTLData
->wszInsertAfter
, wszSemicolon
);
951 AddToStrW(pTLData
->wszInsertAfter
, wszNewLine
);
954 static void CreateTypedefHeader(ITypeInfo
*pTypeInfo
,
955 TYPEATTR
*pTypeAttr
, TYPELIB_DATA
*pTLData
)
958 WCHAR wszGuid
[MAX_LOAD_STRING
];
959 const WCHAR wszTypedef
[] = { 't','y','p','e','d','e','f',' ','\0' };
960 const WCHAR wszPublic
[] = { 'p','u','b','l','i','c','\0' };
962 AddToTLDataStrW(pTLData
, wszTypedef
);
963 if(memcmp(&pTypeAttr
->guid
, &GUID_NULL
, sizeof(GUID
)))
965 AddToTLDataStrW(pTLData
, wszOpenBrackets1
);
967 AddToTLDataStrW(pTLData
, wszUUID
);
968 AddToTLDataStrW(pTLData
, wszOpenBrackets2
);
969 StringFromGUID2(&(pTypeAttr
->guid
), wszGuid
, MAX_LOAD_STRING
);
970 wszGuid
[lstrlenW(wszGuid
)-1] = '\0';
971 AddToTLDataStrW(pTLData
, &wszGuid
[1]);
972 AddToTLDataStrW(pTLData
, wszCloseBrackets2
);
974 if(pTypeAttr
->typekind
== TKIND_ALIAS
)
976 if(bFirst
) AddToTLDataStrW(pTLData
, wszOpenBrackets1
);
979 AddToTLDataStrW(pTLData
, wszComa
);
980 AddToTLDataStrW(pTLData
, wszSpace
);
983 AddToTLDataStrW(pTLData
, wszPublic
);
987 AddToTLDataStrW(pTLData
, wszCloseBrackets1
);
988 AddToTLDataStrW(pTLData
, wszNewLine
);
992 static int PopulateTree(void)
998 ITypeInfo
*pTypeInfo
, *pRefTypeInfo
;
1000 TYPEATTR
*pTypeAttr
;
1002 ULONG ulHelpContext
;
1005 WCHAR wszText
[MAX_LOAD_STRING
];
1006 WCHAR wszAfter
[MAX_LOAD_STRING
];
1011 TYPELIB_DATA
*tldDispatch
;
1014 const WCHAR wszGeneratedInfo
[] = { '/','/',' ','G','e','n','e','r','a','t','e','d',
1015 ' ','.','I','D','L',' ','f','i','l','e',' ','(','b','y',' ','t','h','e',' ',
1016 'O','L','E','/','C','O','M',' ','O','b','j','e','c','t',' ',
1017 'V','i','e','w','e','r',')','\n','/','/','\n','/','/',' ',
1018 't','y','p','e','l','i','b',' ','f','i','l','e','n','a','m','e',':',' ','\0'};
1020 const WCHAR wszFormat
[] = { '%','s',' ','(','%','s',')','\0' };
1021 const WCHAR wszFormat2
[] = { 'v','e','r','s','i','o','n',
1022 '(','%','l','d','.','%','l','d',')','\0' };
1024 const WCHAR wszTKIND_ENUM
[] = { 't','y','p','e','d','e','f',' ','e','n','u','m',' ','\0' };
1025 const WCHAR wszTKIND_RECORD
[]
1026 = { 't','y','p','e','d','e','f',' ','s','t','r','u','c','t',' ','\0' };
1027 const WCHAR wszTKIND_MODULE
[] = { 'm','o','d','u','l','e',' ','\0' };
1028 const WCHAR wszTKIND_INTERFACE
[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' };
1029 const WCHAR wszTKIND_DISPATCH
[]
1030 = { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' };
1031 const WCHAR wszTKIND_COCLASS
[] = { 'c','o','c','l','a','s','s',' ','\0' };
1032 const WCHAR wszTKIND_ALIAS
[] = { 't','y','p','e','d','e','f',' ','\0' };
1033 const WCHAR wszTKIND_UNION
[]
1034 = { 't','y','p','e','d','e','f',' ','u','n','i','o','n',' ','\0' };
1036 const WCHAR wszLibrary
[] = { 'l','i','b','r','a','r','y',' ','\0' };
1037 const WCHAR wszTag
[] = { 't','a','g','\0' };
1039 WCHAR wszProperties
[] = { 'p','r','o','p','e','r','t','i','e','s','\0' };
1040 WCHAR wszMethods
[] = { 'm','e','t','h','o','d','s','\0' };
1042 U(tvis
).item
.mask
= TVIF_TEXT
|TVIF_PARAM
;
1043 U(tvis
).item
.cchTextMax
= MAX_LOAD_STRING
;
1044 U(tvis
).item
.pszText
= wszText
;
1045 tvis
.hInsertAfter
= (HTREEITEM
)TVI_LAST
;
1046 tvis
.hParent
= TVI_ROOT
;
1048 if(FAILED((hRes
= LoadTypeLib(typelib
.wszFileName
, &pTypeLib
))))
1050 WCHAR wszMessage
[MAX_LOAD_STRING
];
1051 WCHAR wszError
[MAX_LOAD_STRING
];
1053 LoadString(globals
.hMainInst
, IDS_ERROR_LOADTYPELIB
,
1054 wszError
, sizeof(WCHAR
[MAX_LOAD_STRING
]));
1055 wsprintfW(wszMessage
, wszError
, typelib
.wszFileName
, hRes
);
1056 MessageBox(globals
.hMainWnd
, wszMessage
, NULL
, MB_OK
|MB_ICONEXCLAMATION
);
1059 count
= ITypeLib_GetTypeInfoCount(pTypeLib
);
1061 ITypeLib_GetDocumentation(pTypeLib
, -1, &bstrName
, &bstrData
, NULL
, NULL
);
1062 ITypeLib_GetLibAttr(pTypeLib
, &pTLibAttr
);
1064 tld
= InitializeTLData();
1065 U(tvis
).item
.lParam
= (LPARAM
) tld
;
1066 AddToTLDataStrW(tld
, wszGeneratedInfo
);
1067 AddToTLDataStrW(tld
, typelib
.wszFileName
);
1068 AddToTLDataStrW(tld
, wszNewLine
);
1069 AddToTLDataStrW(tld
, wszNewLine
);
1070 AddToTLDataStrW(tld
, wszOpenBrackets1
);
1071 AddToTLDataStrW(tld
, wszNewLine
);
1073 AddToTLDataStrW(tld
, wszUUID
);
1074 AddToTLDataStrW(tld
, wszOpenBrackets2
);
1075 StringFromGUID2(&(pTLibAttr
->guid
), wszText
, MAX_LOAD_STRING
);
1076 wszText
[lstrlenW(wszText
)-1] = '\0';
1077 AddToTLDataStrW(tld
, &wszText
[1]);
1078 AddToTLDataStrW(tld
, wszCloseBrackets2
);
1079 AddToTLDataStrW(tld
, wszComa
);
1080 AddToTLDataStrW(tld
, wszNewLine
);
1082 wsprintfW(wszText
, wszFormat2
, pTLibAttr
->wMajorVerNum
, pTLibAttr
->wMinorVerNum
);
1083 AddToTLDataStrW(tld
, wszText
);
1084 AddToTLDataStrW(tld
, wszComa
);
1085 AddToTLDataStrW(tld
, wszNewLine
);
1087 AddToTLDataStrW(tld
, wszHelpstring
);
1088 AddToTLDataStrW(tld
, wszOpenBrackets2
);
1089 AddToTLDataStrW(tld
, wszInvertedComa
);
1090 AddToTLDataStrW(tld
, bstrData
);
1091 AddToTLDataStrW(tld
, wszInvertedComa
);
1092 AddToTLDataStrW(tld
, wszCloseBrackets2
);
1093 AddToTLDataStrW(tld
, wszNewLine
);
1094 AddToTLDataStrW(tld
, wszCloseBrackets1
);
1095 AddToTLDataStrW(tld
, wszNewLine
);
1096 AddToTLDataStrW(tld
, wszLibrary
);
1097 AddToTLDataStrW(tld
, bstrName
);
1098 AddToTLDataStrW(tld
, wszNewLine
);
1099 AddToTLDataStrW(tld
, wszOpenBrackets3
);
1100 AddToTLDataStrW(tld
, wszNewLine
);
1102 AddToStrW(tld
->wszInsertAfter
, wszCloseBrackets3
);
1103 AddToStrW(tld
->wszInsertAfter
, wszSemicolon
);
1105 wsprintfW(wszText
, wszFormat
, bstrName
, bstrData
);
1106 SysFreeString(bstrName
);
1107 SysFreeString(bstrData
);
1108 tvis
.hParent
= (HTREEITEM
)SendMessage(typelib
.hTree
,
1109 TVM_INSERTITEM
, 0, (LPARAM
)&tvis
);
1111 for(i
=0; i
<count
; i
++)
1114 ITypeLib_GetTypeInfo(pTypeLib
, i
, &pTypeInfo
);
1116 ITypeInfo_GetDocumentation(pTypeInfo
, MEMBERID_NIL
, &bstrName
, &bstrData
,
1117 &ulHelpContext
, NULL
);
1118 ITypeInfo_GetTypeAttr(pTypeInfo
, &pTypeAttr
);
1120 memset(wszText
, 0, sizeof(wszText
));
1121 memset(wszAfter
, 0, sizeof(wszAfter
));
1122 tld
= InitializeTLData();
1123 U(tvis
).item
.lParam
= (LPARAM
)tld
;
1124 switch(pTypeAttr
->typekind
)
1127 AddToStrW(wszText
, wszTKIND_ENUM
);
1128 AddToStrW(wszText
, bstrName
);
1130 CreateTypedefHeader(pTypeInfo
, pTypeAttr
, tld
);
1131 AddToTLDataStrW(tld
, &wszTKIND_ENUM
[lstrlenW(wszTKIND_ALIAS
)]);
1132 AddToTLDataStrW(tld
, wszOpenBrackets3
);
1133 AddToTLDataStrW(tld
,wszNewLine
);
1134 AddToStrW(tld
->wszInsertAfter
, wszCloseBrackets3
);
1135 AddToStrW(tld
->wszInsertAfter
, wszSpace
);
1136 AddToStrW(tld
->wszInsertAfter
, bstrName
);
1137 AddToStrW(tld
->wszInsertAfter
, wszSemicolon
);
1138 AddToStrW(tld
->wszInsertAfter
, wszNewLine
);
1141 hParent
= TreeView_InsertItem(typelib
.hTree
, &tvis
);
1142 EnumEnums(pTypeInfo
, pTypeAttr
->cVars
, hParent
);
1143 AddChildrenData(hParent
, tld
);
1144 AddToTLDataStrW(tld
, tld
->wszInsertAfter
);
1147 AddToTLDataStrW(tld
, wszTKIND_RECORD
);
1148 AddToTLDataStrW(tld
, wszTag
);
1149 AddToTLDataStrW(tld
, bstrName
);
1150 AddToTLDataStrW(tld
, wszSpace
);
1151 AddToTLDataStrW(tld
, wszOpenBrackets3
);
1152 AddToTLDataStrW(tld
, wszNewLine
);
1154 AddToStrW(tld
->wszInsertAfter
, wszCloseBrackets3
);
1155 AddToStrW(tld
->wszInsertAfter
, wszSpace
);
1156 AddToStrW(tld
->wszInsertAfter
, bstrName
);
1157 AddToStrW(tld
->wszInsertAfter
, wszSemicolon
);
1158 AddToStrW(tld
->wszInsertAfter
, wszNewLine
);
1160 AddToStrW(wszText
, wszTKIND_RECORD
);
1161 AddToStrW(wszText
, bstrName
);
1164 AddToStrW(wszText
, wszTKIND_MODULE
);
1165 AddToStrW(wszText
, bstrName
);
1167 case TKIND_INTERFACE
:
1168 CreateInterfaceInfo(pTypeInfo
, pTypeAttr
->cImplTypes
, bstrName
,
1169 bstrData
, ulHelpContext
, pTypeAttr
, tld
);
1170 tld
->bPredefine
= TRUE
;
1172 AddToStrW(wszText
, wszTKIND_INTERFACE
);
1173 AddToStrW(wszText
, bstrName
);
1176 AddToStrW(wszText
, wszTKIND_COCLASS
);
1177 AddToStrW(wszText
, bstrName
);
1180 AddToStrW(wszText
, wszTKIND_UNION
);
1181 AddToStrW(wszText
, bstrName
);
1183 case TKIND_DISPATCH
:
1184 CreateInterfaceInfo(pTypeInfo
, pTypeAttr
->cImplTypes
, bstrName
,
1185 bstrData
, ulHelpContext
, pTypeAttr
, tld
);
1186 tld
->bPredefine
= TRUE
;
1187 if(pTypeAttr
->wTypeFlags
& TYPEFLAG_FDUAL
)
1189 AddToStrW(wszText
, wszTKIND_DISPATCH
);
1190 AddToStrW(wszText
, bstrName
);
1192 hParent
= TreeView_InsertItem(typelib
.hTree
, &tvis
);
1193 hMain
= tvis
.hParent
;
1196 lstrcpyW(wszText
, wszProperties
);
1197 tvis
.hParent
= hParent
;
1198 tld
= InitializeTLData();
1199 U(tvis
).item
.lParam
= (LPARAM
) tld
;
1200 AddToTLDataStrW(tld
, wszProperties
);
1201 AddToTLDataStrW(tld
, wszColon
);
1202 AddToTLDataStrW(tld
, wszNewLine
);
1203 tvis
.hParent
= TreeView_InsertItem(typelib
.hTree
, &tvis
);
1204 EnumVars(pTypeInfo
, pTypeAttr
->cVars
, tvis
.hParent
);
1205 AddChildrenData(tvis
.hParent
, tld
);
1207 lstrcpyW(wszText
, wszMethods
);
1208 tvis
.hParent
= hParent
;
1209 tld
= InitializeTLData();
1210 U(tvis
).item
.lParam
= (LPARAM
) tld
;
1211 AddToTLDataStrW(tld
, wszMethods
);
1212 AddToTLDataStrW(tld
, wszColon
);
1213 AddToTLDataStrW(tld
, wszNewLine
);
1214 tvis
.hParent
= TreeView_InsertItem(typelib
.hTree
, &tvis
);
1215 EnumFuncs(pTypeInfo
, pTypeAttr
, tvis
.hParent
);
1216 AddChildrenData(tvis
.hParent
, tld
);
1218 EnumImplTypes(pTypeInfo
, pTypeAttr
->cImplTypes
, hParent
);
1219 AddChildrenData(hParent
, tldDispatch
);
1220 AddToTLDataStrW(tldDispatch
, tldDispatch
->wszInsertAfter
);
1223 tvis
.hParent
= hMain
;
1225 if(SUCCEEDED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo
, -1, &hRefType
)))
1229 ITypeInfo_ReleaseTypeAttr(pTypeInfo
, pTypeAttr
);
1230 SysFreeString(bstrName
);
1231 SysFreeString(bstrData
);
1233 memset(wszText
, 0, sizeof(wszText
));
1234 tld
= InitializeTLData();
1235 U(tvis
).item
.lParam
= (LPARAM
) tld
;
1237 ITypeInfo_GetRefTypeInfo(pTypeInfo
, hRefType
, &pRefTypeInfo
);
1238 ITypeInfo_GetDocumentation(pRefTypeInfo
, MEMBERID_NIL
, &bstrName
,
1239 &bstrData
, &ulHelpContext
, NULL
);
1240 ITypeInfo_GetTypeAttr(pRefTypeInfo
, &pTypeAttr
);
1242 CreateInterfaceInfo(pTypeInfo
, pTypeAttr
->cImplTypes
, bstrName
,
1243 bstrData
, ulHelpContext
, pTypeAttr
, tld
);
1244 tld
->bPredefine
= TRUE
;
1246 AddToStrW(wszText
, wszTKIND_INTERFACE
);
1247 AddToStrW(wszText
, bstrName
);
1248 ITypeInfo_Release(pRefTypeInfo
);
1252 AddToStrW(wszText
, wszTKIND_ALIAS
);
1253 CreateTypeInfo(wszText
, wszAfter
, pTypeAttr
->tdescAlias
, pTypeInfo
);
1254 AddToStrW(wszText
, wszSpace
);
1255 AddToStrW(wszText
, bstrName
);
1256 AddToStrW(wszText
, wszAfter
);
1258 CreateTypedefHeader(pTypeInfo
, pTypeAttr
, tld
);
1259 AddToTLDataStrW(tld
, &wszText
[lstrlenW(wszTKIND_ALIAS
)]);
1260 AddToTLDataStrW(tld
, wszSemicolon
);
1261 AddToTLDataStrW(tld
, wszNewLine
);
1264 lstrcpyW(wszText
, bstrName
);
1265 WINE_FIXME("pTypeAttr->typekind == %d not supported\n",
1266 pTypeAttr
->typekind
);
1271 hParent
= TreeView_InsertItem(typelib
.hTree
, &tvis
);
1273 EnumVars(pTypeInfo
, pTypeAttr
->cVars
, hParent
);
1274 EnumFuncs(pTypeInfo
, pTypeAttr
, hParent
);
1275 EnumImplTypes(pTypeInfo
, pTypeAttr
->cImplTypes
, hParent
);
1277 if(memcmp(bstrName
, wszVT_UNKNOWN
, sizeof(wszVT_UNKNOWN
)))
1278 AddChildrenData(hParent
, tld
);
1279 AddToTLDataStrW(tld
, tld
->wszInsertAfter
);
1282 ITypeInfo_ReleaseTypeAttr(pTypeInfo
, pTypeAttr
);
1283 ITypeInfo_Release(pTypeInfo
);
1284 SysFreeString(bstrName
);
1285 SysFreeString(bstrData
);
1287 SendMessage(typelib
.hTree
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
)tvis
.hParent
);
1289 memset(&tvi
, 0, sizeof(TVITEM
));
1290 tvi
.mask
= TVIF_PARAM
;
1291 tvi
.hItem
= tvis
.hParent
;
1293 SendMessage(typelib
.hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
1294 AddPredefinitions(tvi
.hItem
, (TYPELIB_DATA
*)(tvi
.lParam
));
1295 AddIdlData(tvi
.hItem
, (TYPELIB_DATA
*)(tvi
.lParam
));
1296 AddToTLDataStrW((TYPELIB_DATA
*)(tvi
.lParam
),
1297 ((TYPELIB_DATA
*)(tvi
.lParam
))->wszInsertAfter
);
1299 ITypeLib_Release(pTypeLib
);
1303 void UpdateData(HTREEITEM item
)
1307 memset(&tvi
, 0, sizeof(TVITEM
));
1308 tvi
.mask
= TVIF_PARAM
;
1311 SendMessage(typelib
.hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
1314 SetWindowText(typelib
.hEdit
, wszSpace
);
1318 SetWindowText(typelib
.hEdit
, ((TYPELIB_DATA
*)tvi
.lParam
)->idl
);
1321 static void TypeLibResizeChild(void)
1325 MoveWindow(typelib
.hStatusBar
, 0, 0, 0, 0, TRUE
);
1327 if(IsWindowVisible(typelib
.hStatusBar
))
1328 GetClientRect(typelib
.hStatusBar
, &stat
);
1329 else stat
.bottom
= 0;
1331 GetClientRect(globals
.hTypeLibWnd
, &client
);
1332 MoveWindow(typelib
.hPaneWnd
, 0, 0,
1333 client
.right
, client
.bottom
-stat
.bottom
, TRUE
);
1336 static void TypeLibMenuCommand(WPARAM wParam
, HWND hWnd
)
1346 vis
= IsWindowVisible(typelib
.hStatusBar
);
1347 ShowWindow(typelib
.hStatusBar
, vis
? SW_HIDE
: SW_SHOW
);
1348 CheckMenuItem(GetMenu(hWnd
), LOWORD(wParam
),
1349 vis
? MF_UNCHECKED
: MF_CHECKED
);
1350 TypeLibResizeChild();
1353 DestroyWindow(hWnd
);
1358 static void UpdateTypeLibStatusBar(int itemID
)
1360 WCHAR info
[MAX_LOAD_STRING
];
1362 if(!LoadString(globals
.hMainInst
, itemID
, info
, sizeof(WCHAR
[MAX_LOAD_STRING
])))
1363 LoadString(globals
.hMainInst
, IDS_READY
, info
, sizeof(WCHAR
[MAX_LOAD_STRING
]));
1365 SendMessage(typelib
.hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)info
);
1368 static void EmptyTLTree(void)
1373 tvi
.mask
= TVIF_PARAM
;
1374 cur
= TreeView_GetChild(typelib
.hTree
, TVI_ROOT
);
1379 cur
= TreeView_GetChild(typelib
.hTree
, del
);
1381 if(!cur
) cur
= TreeView_GetNextSibling(typelib
.hTree
, del
);
1382 if(!cur
) cur
= TreeView_GetParent(typelib
.hTree
, del
);
1385 SendMessage(typelib
.hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
1388 HeapFree(GetProcessHeap(), 0, ((TYPELIB_DATA
*)tvi
.lParam
)->idl
);
1389 HeapFree(GetProcessHeap(), 0, (TYPELIB_DATA
*)tvi
.lParam
);
1392 SendMessage(typelib
.hTree
, TVM_DELETEITEM
, 0, (LPARAM
)del
);
1398 LRESULT CALLBACK
TypeLibProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1404 if(!CreatePanedWindow(hWnd
, &typelib
.hPaneWnd
, globals
.hMainInst
))
1405 DestroyWindow(hWnd
);
1406 typelib
.hTree
= CreateWindowEx(WS_EX_CLIENTEDGE
, WC_TREEVIEW
, NULL
,
1407 WS_CHILD
|WS_VISIBLE
|TVS_HASLINES
|TVS_HASBUTTONS
|TVS_LINESATROOT
,
1408 0, 0, 0, 0, typelib
.hPaneWnd
, (HMENU
)TYPELIB_TREE
,
1409 globals
.hMainInst
, NULL
);
1410 typelib
.hEdit
= CreateWindowEx(WS_EX_CLIENTEDGE
, WC_EDIT
, NULL
,
1411 WS_CHILD
|WS_VISIBLE
|ES_MULTILINE
|ES_READONLY
|WS_HSCROLL
|WS_VSCROLL
,
1412 0, 0, 0, 0, typelib
.hPaneWnd
, NULL
, globals
.hMainInst
, NULL
);
1414 SetLeft(typelib
.hPaneWnd
, typelib
.hTree
);
1415 SetRight(typelib
.hPaneWnd
, typelib
.hEdit
);
1417 if(PopulateTree()) DestroyWindow(hWnd
);
1418 else SetFocus(typelib
.hTree
);
1422 TypeLibMenuCommand(LOWORD(wParam
), hWnd
);
1424 UpdateTypeLibStatusBar(LOWORD(wParam
));
1427 SetFocus(typelib
.hTree
);
1430 if(wParam
== SIZE_MINIMIZED
) break;
1431 TypeLibResizeChild();
1437 return DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
1442 BOOL
TypeLibRegisterClass(void)
1446 memset(&wcc
, 0, sizeof(WNDCLASS
));
1447 wcc
.lpfnWndProc
= TypeLibProc
;
1448 wcc
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
1449 wcc
.lpszMenuName
= MAKEINTRESOURCE(IDM_TYPELIB
);
1450 wcc
.lpszClassName
= wszTypeLib
;
1452 if(!RegisterClass(&wcc
))
1458 BOOL
CreateTypeLibWindow(HINSTANCE hInst
, WCHAR
*wszFileName
)
1460 WCHAR wszTitle
[MAX_LOAD_STRING
];
1461 LoadString(hInst
, IDS_TYPELIBTITLE
, wszTitle
, sizeof(WCHAR
[MAX_LOAD_STRING
]));
1463 if(wszFileName
) lstrcpyW(typelib
.wszFileName
, wszFileName
);
1468 memset(&tvi
, 0, sizeof(TVITEM
));
1469 tvi
.hItem
= TreeView_GetSelection(globals
.hTree
);
1471 SendMessage(globals
.hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
1472 lstrcpyW(typelib
.wszFileName
, ((ITEM_INFO
*)tvi
.lParam
)->path
);
1475 globals
.hTypeLibWnd
= CreateWindow(wszTypeLib
, wszTitle
,
1476 WS_OVERLAPPEDWINDOW
|WS_VISIBLE
,
1477 CW_USEDEFAULT
, CW_USEDEFAULT
, 800, 600, NULL
, NULL
, hInst
, NULL
);
1478 if(!globals
.hTypeLibWnd
) return FALSE
;
1480 typelib
.hStatusBar
= CreateStatusWindow(WS_VISIBLE
|WS_CHILD
,
1481 (LPWSTR
)wszTitle
, globals
.hTypeLibWnd
, 0);
1483 TypeLibResizeChild();