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 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 wszPropPut
[] = { 'p','r','o','p','p','u','t','\0' };
85 static const WCHAR wszPropGet
[] = { 'p','r','o','p','g','e','t','\0' };
86 static const WCHAR wszPropPutRef
[] = { 'p','r','o','p','p','u','t','r','e','f','\0' };
87 static const WCHAR wszPARAMFLAG_FIN
[] = { 'i','n','\0' };
88 static const WCHAR wszPARAMFLAG_FOUT
[] = { 'o','u','t','\0' };
89 static const WCHAR wszPARAMFLAG_FLCID
[] = { 'c','i','d','\0' };
90 static const WCHAR wszPARAMFLAG_FRETVAL
[] = { 'r','e','t','v','a','l','\0' };
91 static const WCHAR wszPARAMFLAG_FOPT
[] = { 'o','p','t','i','o','n','a','l','\0' };
92 static const WCHAR wszPARAMFLAG_FHASCUSTDATA
[]
93 = { 'h','a','s','c','u','s','t','d','a','t','a','\0' };
94 static const WCHAR wszDefaultValue
[]
95 = { 'd','e','f','a','u','l','t','v','a','l','u','e','\0' };
97 static const WCHAR wszReadOnly
[] = { 'r','e','a','d','o','n','l','y','\0' };
98 static const WCHAR wszConst
[] = { 'c','o','n','s','t','\0' };
100 static void ShowLastError(void)
102 DWORD error
= GetLastError();
104 WCHAR wszTitle
[MAX_LOAD_STRING
];
106 LoadString(globals
.hMainInst
, IDS_TYPELIBTITLE
, wszTitle
,
107 sizeof(WCHAR
[MAX_LOAD_STRING
]));
108 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
109 NULL
, error
, 0, (LPTSTR
) &lpMsgBuf
, 0, NULL
);
110 MessageBox(NULL
, lpMsgBuf
, wszTitle
, MB_OK
| MB_ICONERROR
);
115 static void SaveIdl(WCHAR
*wszFileName
)
120 DWORD len
, dwNumWrite
;
124 hIDL
= TreeView_GetChild(typelib
.hTree
, TVI_ROOT
);
126 memset(&tvi
, 0, sizeof(TVITEM
));
129 SendMessage(typelib
.hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
130 data
= (TYPELIB_DATA
*)tvi
.lParam
;
132 hFile
= CreateFile(wszFileName
, GENERIC_WRITE
, FILE_SHARE_WRITE
,
133 NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
134 if(hFile
== INVALID_HANDLE_VALUE
)
140 len
= WideCharToMultiByte( CP_UTF8
, 0, data
->idl
, data
->idlLen
, NULL
, 0, NULL
, NULL
);
141 wszIdl
= HeapAlloc(GetProcessHeap(), 0, len
);
142 WideCharToMultiByte( CP_UTF8
, 0, data
->idl
, data
->idlLen
, wszIdl
, len
, NULL
, NULL
);
144 if(!WriteFile(hFile
, wszIdl
, len
, &dwNumWrite
, NULL
))
147 HeapFree(GetProcessHeap(), 0, wszIdl
);
151 static void GetSaveIdlAsPath(void)
153 OPENFILENAME saveidl
;
155 WCHAR wszPath
[MAX_LOAD_STRING
];
156 WCHAR wszDir
[MAX_LOAD_STRING
];
157 static const WCHAR wszDefaultExt
[] = { 'i','d','l',0 };
158 static const WCHAR wszIdlFiles
[] = { '*','.','i','d','l','\0','\0' };
160 memset(&saveidl
, 0, sizeof(saveidl
));
162 lstrcpyW(wszDir
, typelib
.wszFileName
);
163 pFileName
= wszDir
+ lstrlenW(wszDir
);
164 while(*pFileName
!= '.' && *pFileName
!= '\\' && *pFileName
!= '/'
165 && pFileName
> wszDir
) pFileName
-= 1;
166 if(*pFileName
== '.')
169 while(*pFileName
!= '\\' && *pFileName
!= '/' && pFileName
> wszDir
)
172 if(*pFileName
== '\\' || *pFileName
== '/') pFileName
+= 1;
173 lstrcpyW(wszPath
, pFileName
);
175 GetCurrentDirectory(MAX_LOAD_STRING
, wszDir
);
177 saveidl
.lStructSize
= sizeof(OPENFILENAME
);
178 saveidl
.hwndOwner
= globals
.hTypeLibWnd
;
179 saveidl
.hInstance
= globals
.hMainInst
;
180 saveidl
.lpstrFilter
= wszIdlFiles
;
181 saveidl
.lpstrFile
= wszPath
;
182 saveidl
.nMaxFile
= MAX_LOAD_STRING
;
183 saveidl
.lpstrInitialDir
= wszDir
;
184 saveidl
.Flags
= OFN_PATHMUSTEXIST
| OFN_OVERWRITEPROMPT
| OFN_HIDEREADONLY
;
185 saveidl
.lpstrDefExt
= wszDefaultExt
;
187 if (GetSaveFileName(&saveidl
))
191 void AddToStrW(WCHAR
*wszDest
, const WCHAR
*wszSource
)
193 lstrcpyW(&wszDest
[lstrlenW(wszDest
)], wszSource
);
196 void AddToTLDataStrW(TYPELIB_DATA
*pTLData
, const WCHAR
*wszSource
)
198 int SourceLen
= lstrlenW(wszSource
);
200 pTLData
->idl
= HeapReAlloc(GetProcessHeap(), 0, pTLData
->idl
,
201 sizeof(WCHAR
)*(pTLData
->idlLen
+SourceLen
+1));
203 memcpy(&pTLData
->idl
[pTLData
->idlLen
], wszSource
, sizeof(WCHAR
)*(SourceLen
+1));
204 pTLData
->idlLen
+= SourceLen
;
207 void AddToTLDataStrWithTabsW(TYPELIB_DATA
*pTLData
, WCHAR
*wszSource
)
209 int lineLen
= lstrlenW(wszSource
);
211 WCHAR
*pSourcePos
= (WCHAR
*)wszSource
;
217 if(*pSourcePos
== *wszNewLine
) newLinesNo
++;
220 if(*(pSourcePos
- 1) != *wszNewLine
) newLinesNo
++;
222 pTLData
->idl
= HeapReAlloc(GetProcessHeap(), 0, pTLData
->idl
,
223 sizeof(WCHAR
)*(pTLData
->idlLen
+lineLen
+4*newLinesNo
+1));
225 pSourcePos
= (WCHAR
*)wszSource
;
226 pSourceBeg
= (WCHAR
*)wszSource
;
229 if(*pSourcePos
!= *wszNewLine
&& *pSourcePos
)
239 lineLen
= lstrlenW(pSourceBeg
)+1;
243 else lineLen
= lstrlenW(pSourceBeg
);
245 pTLData
->idl
[pTLData
->idlLen
] = *wszSpace
;
246 pTLData
->idl
[pTLData
->idlLen
+1] = *wszSpace
;
247 pTLData
->idl
[pTLData
->idlLen
+2] = *wszSpace
;
248 pTLData
->idl
[pTLData
->idlLen
+3] = *wszSpace
;
249 memcpy(&pTLData
->idl
[pTLData
->idlLen
+4], pSourceBeg
, sizeof(WCHAR
)*lineLen
);
250 pTLData
->idlLen
+= lineLen
+ 4;
251 pTLData
->idl
[pTLData
->idlLen
] = '\0';
253 pSourceBeg
= pSourcePos
;
257 static TYPELIB_DATA
*InitializeTLData(void)
259 TYPELIB_DATA
*pTLData
;
261 pTLData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(TYPELIB_DATA
));
263 pTLData
->idl
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
));
264 pTLData
->idl
[0] = '\0';
269 static void AddSpaces(TYPELIB_DATA
*pTLData
, int tabSize
)
271 for(; tabSize
>0; tabSize
--)
272 AddToTLDataStrW(pTLData
, wszSpace
);
275 static void AddChildrenData(HTREEITEM hParent
, TYPELIB_DATA
*pData
)
280 memset(&tvi
, 0, sizeof(&tvi
));
282 hCur
= TreeView_GetChild(typelib
.hTree
, hParent
);
288 SendMessage(typelib
.hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
289 if(tvi
.lParam
&& ((TYPELIB_DATA
*)(tvi
.lParam
))->idlLen
)
290 AddToTLDataStrWithTabsW(pData
, ((TYPELIB_DATA
*)(tvi
.lParam
))->idl
);
291 }while((hCur
= TreeView_GetNextSibling(typelib
.hTree
, hCur
)));
294 static void CreateTypeInfo(WCHAR
*wszAddTo
, WCHAR
*wszAddAfter
, TYPEDESC tdesc
, ITypeInfo
*pTypeInfo
)
299 ITypeInfo
*pRefTypeInfo
;
300 WCHAR wszBuf
[MAX_LOAD_STRING
];
301 WCHAR wszFormat
[] = { '[','%','l','u',']','\0' };
303 switch(tdesc
.vt
&VT_TYPEMASK
)
305 #define VTADDTOSTR(x) case x:\
306 AddToStrW(wszAddTo, wsz##x);\
322 VTADDTOSTR(VT_VARIANT
);
324 VTADDTOSTR(VT_ERROR
);
325 VTADDTOSTR(VT_LPSTR
);
326 VTADDTOSTR(VT_LPWSTR
);
327 VTADDTOSTR(VT_HRESULT
);
328 VTADDTOSTR(VT_UNKNOWN
);
329 VTADDTOSTR(VT_DISPATCH
);
333 for(i
=0; i
<U(tdesc
).lpadesc
->cDims
; i
++)
335 wsprintfW(wszBuf
, wszFormat
, U(tdesc
).lpadesc
->rgbounds
[i
].cElements
);
336 AddToStrW(wszAddAfter
, wszBuf
);
338 CreateTypeInfo(wszAddTo
, wszAddAfter
, U(tdesc
).lpadesc
->tdescElem
, pTypeInfo
);
341 AddToStrW(wszAddTo
, wszVT_SAFEARRAY
);
342 AddToStrW(wszAddTo
, wszOpenBrackets2
);
343 CreateTypeInfo(wszAddTo
, wszAddAfter
, *U(tdesc
).lptdesc
, pTypeInfo
);
344 AddToStrW(wszAddTo
, wszCloseBrackets2
);
347 CreateTypeInfo(wszAddTo
, wszAddAfter
, *U(tdesc
).lptdesc
, pTypeInfo
);
348 AddToStrW(wszAddTo
, wszAsterix
);
351 hRes
= ITypeInfo_GetRefTypeInfo(pTypeInfo
,
352 U(tdesc
).hreftype
, &pRefTypeInfo
);
355 ITypeInfo_GetDocumentation(pRefTypeInfo
, MEMBERID_NIL
,
356 &bstrData
, NULL
, NULL
, NULL
);
357 AddToStrW(wszAddTo
, bstrData
);
358 SysFreeString(bstrData
);
359 ITypeInfo_Release(pRefTypeInfo
);
361 else AddToStrW(wszAddTo
, wszFailed
);
364 WINE_FIXME("tdesc.vt&VT_TYPEMASK == %d not supported\n",
365 tdesc
.vt
&VT_TYPEMASK
);
369 static int EnumVars(ITypeInfo
*pTypeInfo
, int cVars
, HTREEITEM hParent
)
375 WCHAR wszText
[MAX_LOAD_STRING
];
376 WCHAR wszAfter
[MAX_LOAD_STRING
];
378 U(tvis
).item
.mask
= TVIF_TEXT
|TVIF_PARAM
;
379 U(tvis
).item
.cchTextMax
= MAX_LOAD_STRING
;
380 U(tvis
).item
.pszText
= wszText
;
381 tvis
.hInsertAfter
= (HTREEITEM
)TVI_LAST
;
382 tvis
.hParent
= hParent
;
384 for(i
=0; i
<cVars
; i
++)
388 if(FAILED(ITypeInfo_GetVarDesc(pTypeInfo
, i
, &pVarDesc
))) continue;
389 if(FAILED(ITypeInfo_GetDocumentation(pTypeInfo
, pVarDesc
->memid
, &bstrName
,
390 NULL
, NULL
, NULL
))) continue;
392 tld
= InitializeTLData();
393 U(tvis
).item
.lParam
= (LPARAM
) tld
;
394 if(pVarDesc
->memid
< MIN_VAR_ID
)
397 AddToTLDataStrW(tld
, wszOpenBrackets1
);
398 AddToTLDataStrW(tld
, wszId
);
399 AddToTLDataStrW(tld
, wszOpenBrackets2
);
400 wsprintfW(wszText
, wszFormat
, pVarDesc
->memid
);
401 AddToTLDataStrW(tld
, wszText
);
402 memset(wszText
, 0, sizeof(wszText
));
403 AddToTLDataStrW(tld
, wszCloseBrackets2
);
405 if(pVarDesc
->wVarFlags
& VARFLAG_FREADONLY
)
407 AddToTLDataStrW(tld
, wszComa
);
408 AddToTLDataStrW(tld
, wszSpace
);
409 AddToTLDataStrW(tld
, wszReadOnly
);
411 AddToTLDataStrW(tld
, wszCloseBrackets1
);
412 AddToTLDataStrW(tld
, wszNewLine
);
415 memset(wszText
, 0, sizeof(wszText
));
416 memset(wszAfter
, 0, sizeof(wszAfter
));
417 CreateTypeInfo(wszText
, wszAfter
, pVarDesc
->elemdescVar
.tdesc
, pTypeInfo
);
418 AddToStrW(wszText
, wszSpace
);
419 AddToStrW(wszText
, bstrName
);
420 AddToStrW(wszText
, wszAfter
);
421 AddToTLDataStrW(tld
, wszText
);
422 AddToTLDataStrW(tld
, wszSemicolon
);
423 AddToTLDataStrW(tld
, wszNewLine
);
425 SendMessage(typelib
.hTree
, TVM_INSERTITEM
, 0, (LPARAM
)&tvis
);
426 SysFreeString(bstrName
);
427 ITypeInfo_ReleaseVarDesc(pTypeInfo
, pVarDesc
);
433 static int EnumEnums(ITypeInfo
*pTypeInfo
, int cVars
, HTREEITEM hParent
)
439 WCHAR wszText
[MAX_LOAD_STRING
];
440 WCHAR wszAfter
[MAX_LOAD_STRING
];
442 U(tvis
).item
.mask
= TVIF_TEXT
|TVIF_PARAM
;
443 U(tvis
).item
.cchTextMax
= MAX_LOAD_STRING
;
444 U(tvis
).item
.pszText
= wszText
;
445 tvis
.hInsertAfter
= (HTREEITEM
)TVI_LAST
;
446 tvis
.hParent
= hParent
;
448 for(i
=0; i
<cVars
; i
++)
452 if(FAILED(ITypeInfo_GetVarDesc(pTypeInfo
, i
, &pVarDesc
))) continue;
453 if(FAILED(ITypeInfo_GetDocumentation(pTypeInfo
, pVarDesc
->memid
, &bstrName
,
454 NULL
, NULL
, NULL
))) continue;
456 tld
= InitializeTLData();
457 U(tvis
).item
.lParam
= (LPARAM
) tld
;
459 memset(wszText
, 0, sizeof(wszText
));
460 memset(wszAfter
, 0, sizeof(wszAfter
));
462 if (pVarDesc
->varkind
== VAR_CONST
)
466 if (VariantChangeType(&var
, U(*pVarDesc
).lpvarValue
, 0, VT_BSTR
) == S_OK
)
468 AddToStrW(wszText
, wszConst
);
469 AddToStrW(wszText
, wszSpace
);
470 AddToStrW(wszAfter
, wszSpace
);
471 AddToStrW(wszAfter
, wszEquals
);
472 AddToStrW(wszAfter
, wszSpace
);
473 AddToStrW(wszAfter
, V_BSTR(&var
));
477 CreateTypeInfo(wszText
, wszAfter
, pVarDesc
->elemdescVar
.tdesc
, pTypeInfo
);
478 AddToStrW(wszText
, wszSpace
);
479 AddToStrW(wszText
, bstrName
);
480 AddToStrW(wszText
, wszAfter
);
481 AddToTLDataStrW(tld
, bstrName
);
482 AddToTLDataStrW(tld
, wszAfter
);
484 AddToTLDataStrW(tld
, wszComa
);
485 AddToTLDataStrW(tld
, wszNewLine
);
487 SendMessage(typelib
.hTree
, TVM_INSERTITEM
, 0, (LPARAM
)&tvis
);
488 SysFreeString(bstrName
);
489 ITypeInfo_ReleaseVarDesc(pTypeInfo
, pVarDesc
);
495 static int EnumFuncs(ITypeInfo
*pTypeInfo
, int cFuncs
, HTREEITEM hParent
)
501 BSTR bstrName
, *bstrParamNames
;
502 WCHAR wszText
[MAX_LOAD_STRING
];
503 WCHAR wszAfter
[MAX_LOAD_STRING
];
504 WCHAR szRhs
[] = {'r','h','s',0}; /* Right-hand side of a propput */
507 U(tvis
).item
.mask
= TVIF_TEXT
|TVIF_PARAM
;
508 tvis
.hInsertAfter
= (HTREEITEM
)TVI_LAST
;
509 tvis
.hParent
= hParent
;
511 for(i
=0; i
<cFuncs
; i
++)
515 if(FAILED(ITypeInfo_GetFuncDesc(pTypeInfo
, i
, &pFuncDesc
))) continue;
516 if(FAILED(ITypeInfo_GetDocumentation(pTypeInfo
, pFuncDesc
->memid
, &bstrName
,
517 NULL
, NULL
, NULL
))) continue;
519 bstrParamNames
= HeapAlloc(GetProcessHeap(), 0,
520 sizeof(BSTR
*)*(pFuncDesc
->cParams
+1));
521 if(FAILED(ITypeInfo_GetNames(pTypeInfo
, pFuncDesc
->memid
, bstrParamNames
,
522 pFuncDesc
->cParams
+1, &namesNo
)))
524 HeapFree(GetProcessHeap(), 0, bstrParamNames
);
527 SysFreeString(bstrParamNames
[0]);
529 memset(wszText
, 0, sizeof(wszText
));
530 memset(wszAfter
, 0, sizeof(wszAfter
));
531 tld
= InitializeTLData();
532 U(tvis
).item
.cchTextMax
= SysStringLen(bstrName
);
533 U(tvis
).item
.pszText
= bstrName
;
534 U(tvis
).item
.lParam
= (LPARAM
) tld
;
536 if(pFuncDesc
->memid
< MIN_FUNC_ID
)
538 AddToTLDataStrW(tld
, wszOpenBrackets1
);
540 AddToTLDataStrW(tld
, wszId
);
541 AddToTLDataStrW(tld
, wszOpenBrackets2
);
542 wsprintfW(wszText
, wszFormat
, pFuncDesc
->memid
);
543 AddToTLDataStrW(tld
, wszText
);
544 AddToTLDataStrW(tld
, wszCloseBrackets2
);
545 memset(wszText
, 0, sizeof(wszText
));
547 CreateTypeInfo(wszText
, wszAfter
, pFuncDesc
->elemdescFunc
.tdesc
, pTypeInfo
);
548 switch(pFuncDesc
->invkind
)
550 case INVOKE_PROPERTYGET
:
551 if(bFirst
) AddToTLDataStrW(tld
, wszOpenBrackets1
);
554 AddToTLDataStrW(tld
, wszComa
);
555 AddToTLDataStrW(tld
, wszSpace
);
558 AddToTLDataStrW(tld
, wszPropGet
);
560 case INVOKE_PROPERTYPUT
:
561 if(bFirst
) AddToTLDataStrW(tld
, wszOpenBrackets1
);
564 AddToTLDataStrW(tld
, wszComa
);
565 AddToTLDataStrW(tld
, wszSpace
);
568 AddToTLDataStrW(tld
, wszPropPut
);
570 case INVOKE_PROPERTYPUTREF
:
571 if(bFirst
) AddToTLDataStrW(tld
, wszOpenBrackets1
);
574 AddToTLDataStrW(tld
, wszComa
);
575 AddToTLDataStrW(tld
, wszSpace
);
578 AddToTLDataStrW(tld
, wszPropPutRef
);
584 AddToTLDataStrW(tld
, wszCloseBrackets1
);
585 AddToTLDataStrW(tld
, wszNewLine
);
587 AddToTLDataStrW(tld
, wszText
);
588 AddToTLDataStrW(tld
, wszAfter
);
589 AddToTLDataStrW(tld
, wszSpace
);
590 if(pFuncDesc
->memid
>= MIN_FUNC_ID
)
592 AddToTLDataStrW(tld
, wszStdCall
);
593 AddToTLDataStrW(tld
, wszSpace
);
595 tabSize
= tld
->idlLen
;
596 AddToTLDataStrW(tld
, bstrName
);
597 AddToTLDataStrW(tld
, wszOpenBrackets2
);
599 for(j
=0; j
<pFuncDesc
->cParams
; j
++)
601 if(j
!= 0) AddToTLDataStrW(tld
, wszComa
);
602 if(pFuncDesc
->cParams
!= 1)
604 AddToTLDataStrW(tld
, wszNewLine
);
605 AddSpaces(tld
, tabSize
);
608 #define ENUM_PARAM_FLAG(x)\
609 if(U(pFuncDesc->lprgelemdescParam[j]).paramdesc.wParamFlags & x) \
611 if(bFirst) AddToTLDataStrW(tld,\
615 AddToTLDataStrW(tld, wszComa);\
616 AddToTLDataStrW(tld, wszSpace);\
619 AddToTLDataStrW(tld, wsz##x);\
621 ENUM_PARAM_FLAG(PARAMFLAG_FIN
);
622 ENUM_PARAM_FLAG(PARAMFLAG_FOUT
);
623 ENUM_PARAM_FLAG(PARAMFLAG_FLCID
);
624 ENUM_PARAM_FLAG(PARAMFLAG_FRETVAL
);
625 ENUM_PARAM_FLAG(PARAMFLAG_FOPT
);
626 ENUM_PARAM_FLAG(PARAMFLAG_FHASCUSTDATA
);
628 if(U(pFuncDesc
->lprgelemdescParam
[j
]).paramdesc
.wParamFlags
& PARAMFLAG_FHASDEFAULT
)
630 VARIANT var
, *param
=&U(pFuncDesc
->lprgelemdescParam
[j
]).paramdesc
.pparamdescex
->varDefaultValue
;
632 if(bFirst
) AddToTLDataStrW(tld
,
636 AddToTLDataStrW(tld
, wszComa
);
637 AddToTLDataStrW(tld
, wszSpace
);
640 AddToTLDataStrW(tld
, wszDefaultValue
);
641 AddToTLDataStrW(tld
, wszOpenBrackets2
);
642 if (V_VT(param
) == VT_BSTR
)
644 AddToTLDataStrW(tld
, wszInvertedComa
);
645 AddToTLDataStrW(tld
, V_BSTR(&var
));
646 AddToTLDataStrW(tld
, wszInvertedComa
);
647 } else if (VariantChangeType(&var
, param
, 0, VT_BSTR
) == S_OK
)
648 AddToTLDataStrW(tld
, V_BSTR(&var
));
649 AddToTLDataStrW(tld
, wszCloseBrackets2
);
654 AddToTLDataStrW(tld
, wszCloseBrackets1
);
655 AddToTLDataStrW(tld
, wszSpace
);
658 memset(wszText
, 0, sizeof(wszText
));
659 memset(wszAfter
, 0, sizeof(wszAfter
));
660 CreateTypeInfo(wszText
, wszAfter
, pFuncDesc
->lprgelemdescParam
[j
].tdesc
,
662 AddToTLDataStrW(tld
, wszText
);
663 AddToTLDataStrW(tld
, wszAfter
);
664 AddToTLDataStrW(tld
, wszSpace
);
666 AddToTLDataStrW(tld
, bstrParamNames
[j
+1]);
667 SysFreeString(bstrParamNames
[j
+1]);
669 AddToTLDataStrW(tld
, szRhs
);
672 AddToTLDataStrW(tld
, wszCloseBrackets2
);
673 AddToTLDataStrW(tld
, wszSemicolon
);
674 AddToTLDataStrW(tld
, wszNewLine
);
676 SendMessage(typelib
.hTree
, TVM_INSERTITEM
, 0, (LPARAM
)&tvis
);
677 HeapFree(GetProcessHeap(), 0, bstrParamNames
);
678 SysFreeString(bstrName
);
679 ITypeInfo_ReleaseFuncDesc(pTypeInfo
, pFuncDesc
);
685 static int EnumImplTypes(ITypeInfo
*pTypeInfo
, int cImplTypes
, HTREEITEM hParent
)
689 ITypeInfo
*pRefTypeInfo
;
693 WCHAR wszInheritedInterfaces
[MAX_LOAD_STRING
];
695 if(!cImplTypes
) return 0;
697 LoadString(globals
.hMainInst
, IDS_INHERITINTERFACES
, wszInheritedInterfaces
,
698 sizeof(WCHAR
[MAX_LOAD_STRING
]));
700 U(tvis
).item
.mask
= TVIF_TEXT
;
701 U(tvis
).item
.cchTextMax
= MAX_LOAD_STRING
;
702 U(tvis
).item
.pszText
= wszInheritedInterfaces
;
703 tvis
.hInsertAfter
= (HTREEITEM
)TVI_LAST
;
704 tvis
.hParent
= hParent
;
706 tvis
.hParent
= TreeView_InsertItem(typelib
.hTree
, &tvis
);
708 for(i
=0; i
<cImplTypes
; i
++)
710 if(FAILED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo
, i
, &hRefType
))) continue;
711 if(FAILED(ITypeInfo_GetRefTypeInfo(pTypeInfo
, hRefType
, &pRefTypeInfo
)))
713 if(FAILED(ITypeInfo_GetDocumentation(pRefTypeInfo
, MEMBERID_NIL
, &bstrName
,
714 NULL
, NULL
, NULL
))) continue;
715 if(FAILED(ITypeInfo_GetTypeAttr(pRefTypeInfo
, &pTypeAttr
))) continue;
717 U(tvis
).item
.cchTextMax
= SysStringLen(bstrName
);
718 U(tvis
).item
.pszText
= bstrName
;
720 hParent
= TreeView_InsertItem(typelib
.hTree
, &tvis
);
721 EnumVars(pRefTypeInfo
, pTypeAttr
->cVars
, hParent
);
722 EnumFuncs(pRefTypeInfo
, pTypeAttr
->cFuncs
, hParent
);
723 EnumImplTypes(pRefTypeInfo
, pTypeAttr
->cImplTypes
, hParent
);
725 SysFreeString(bstrName
);
726 ITypeInfo_ReleaseTypeAttr(pRefTypeInfo
, pTypeAttr
);
727 ITypeInfo_Release(pRefTypeInfo
);
733 static void AddIdlData(HTREEITEM hCur
, TYPELIB_DATA
*pTLData
)
737 hCur
= TreeView_GetChild(typelib
.hTree
, hCur
);
738 memset(&tvi
, 0, sizeof(TVITEM
));
739 tvi
.mask
= TVIF_PARAM
;
744 SendMessage(typelib
.hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
745 AddToTLDataStrW(pTLData
, wszNewLine
);
746 AddToTLDataStrWithTabsW(pTLData
, ((TYPELIB_DATA
*)(tvi
.lParam
))->idl
);
747 hCur
= TreeView_GetNextSibling(typelib
.hTree
, hCur
);
751 static void AddPredefinitions(HTREEITEM hFirst
, TYPELIB_DATA
*pTLData
)
755 WCHAR wszText
[MAX_LOAD_STRING
];
756 WCHAR wszPredefinition
[] = { '/','/',' ','T','L','i','b',' ',':','\n',
757 '/','/',' ','F','o','r','w','a','r','d',' ','d','e','c','l','a','r','e',' ',
758 'a','l','l',' ','t','y','p','e','s',' ','d','e','f','i','n','e','d',' ',
759 'i','n',' ','t','h','i','s',' ','t','y','p','e','l','i','b','\0' };
761 hFirst
= TreeView_GetChild(typelib
.hTree
, hFirst
);
763 AddToTLDataStrWithTabsW(pTLData
, wszPredefinition
);
764 AddToTLDataStrW(pTLData
, wszNewLine
);
767 memset(&tvi
, 0, sizeof(TVITEM
));
768 tvi
.mask
= TVIF_TEXT
|TVIF_PARAM
;
769 tvi
.cchTextMax
= MAX_LOAD_STRING
;
770 tvi
.pszText
= wszText
;
774 SendMessage(typelib
.hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
775 if(((TYPELIB_DATA
*)(tvi
.lParam
))->bPredefine
)
777 AddToStrW(wszText
, wszSemicolon
);
778 AddToTLDataStrWithTabsW(pTLData
, wszText
);
779 AddToTLDataStrW(pTLData
, wszNewLine
);
781 hCur
= TreeView_GetNextSibling(typelib
.hTree
, hCur
);
785 static void CreateInterfaceInfo(ITypeInfo
*pTypeInfo
, int cImplTypes
, WCHAR
*wszName
,
786 WCHAR
*wszHelpString
, unsigned long ulHelpContext
, TYPEATTR
*pTypeAttr
,
787 TYPELIB_DATA
*pTLData
)
789 ITypeInfo
*pRefTypeInfo
;
792 WCHAR wszGuid
[MAX_LOAD_STRING
];
793 WCHAR wszHelpContext
[MAX_LOAD_STRING
];
795 const WCHAR wszInterface
[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' };
796 const WCHAR wszDispinterface
[]
797 = { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' };
798 const WCHAR wszHelpstring
[] = { 'h','e','l','p','s','t','r','i','n','g','\0' };
799 const WCHAR wszHelpcontext
[] = { 'h','e','l','p','c','o','n','t','e','x','t','\0' };
800 const WCHAR wszTYPEFLAG_FAPPOBJECT
[] = { 'a','p','p','o','b','j','e','c','t','\0' };
801 const WCHAR wszTYPEFLAG_FCANCREATE
[] = { 'c','a','n','c','r','e','a','t','e','\0' };
802 const WCHAR wszTYPEFLAG_FLICENSED
[] = { 'l','i','c','e','n','s','e','d','\0' };
803 const WCHAR wszTYPEFLAG_FPREDECLID
[] = { 'p','r','e','d','e','c','l','i','d','\0' };
804 const WCHAR wszTYPEFLAG_FHIDDEN
[] = { 'h','i','d','d','e','n','\0' };
805 const WCHAR wszTYPEFLAG_FCONTROL
[] = { 'c','o','n','t','r','o','l','\0' };
806 const WCHAR wszTYPEFLAG_FDUAL
[] = { 'd','u','a','l','\0' };
807 const WCHAR wszTYPEFLAG_FNONEXTENSIBLE
[]
808 = { 'n','o','n','e','x','t','e','n','s','i','b','l','e','\0' };
809 const WCHAR wszTYPEFLAG_FOLEAUTOMATION
[]
810 = { 'o','l','e','a','u','t','o','m','a','t','i','o','n','\0' };
811 const WCHAR wszTYPEFLAG_FRESTRICTED
[]
812 = { 'r','e','s','t','r','i','c','t','e','d','\0' };
813 const WCHAR wszTYPEFLAG_FAGGREGATABLE
[]
814 = { 'a','g','g','r','e','g','a','t','a','b','l','e','\0' };
815 const WCHAR wszTYPEFLAG_FREPLACEABLE
[]
816 = { 'r','e','p','l','a','c','a','b','l','e','\0' };
817 const WCHAR wszTYPEFLAG_FREVERSEBIND
[]
818 = { 'r','e','v','e','r','s','e','b','i','n','d','\0' };
819 const WCHAR wszTYPEFLAG_FPROXY
[] = { 'p','r','o','x','y','\0' };
821 AddToTLDataStrW(pTLData
, wszOpenBrackets1
);
822 AddToTLDataStrW(pTLData
, wszNewLine
);
823 if(pTypeAttr
->typekind
!= TKIND_DISPATCH
)
825 AddSpaces(pTLData
, 4);
826 AddToTLDataStrW(pTLData
, wszOdl
);
827 AddToTLDataStrW(pTLData
, wszComa
);
828 AddToTLDataStrW(pTLData
, wszNewLine
);
830 AddSpaces(pTLData
, 4);
831 AddToTLDataStrW(pTLData
, wszUUID
);
832 AddToTLDataStrW(pTLData
, wszOpenBrackets2
);
833 StringFromGUID2(&(pTypeAttr
->guid
), wszGuid
, MAX_LOAD_STRING
);
834 wszGuid
[lstrlenW(wszGuid
)-1] = '\0';
835 AddToTLDataStrW(pTLData
, &wszGuid
[1]);
836 AddToTLDataStrW(pTLData
, wszCloseBrackets2
);
839 AddToTLDataStrW(pTLData
, wszComa
);
840 AddToTLDataStrW(pTLData
, wszNewLine
);
841 AddSpaces(pTLData
, 4);
842 AddToTLDataStrW(pTLData
, wszHelpstring
);
843 AddToTLDataStrW(pTLData
, wszOpenBrackets2
);
844 AddToTLDataStrW(pTLData
, wszInvertedComa
);
845 AddToTLDataStrW(pTLData
, wszHelpString
);
846 AddToTLDataStrW(pTLData
, wszInvertedComa
);
847 AddToTLDataStrW(pTLData
, wszCloseBrackets2
);
851 AddToTLDataStrW(pTLData
, wszComa
);
852 AddToTLDataStrW(pTLData
, wszNewLine
);
853 AddSpaces(pTLData
, 4);
854 AddToTLDataStrW(pTLData
, wszHelpcontext
);
855 AddToTLDataStrW(pTLData
, wszOpenBrackets2
);
856 wsprintfW(wszHelpContext
, wszFormat
, ulHelpContext
);
857 AddToTLDataStrW(pTLData
, wszHelpContext
);
858 AddToTLDataStrW(pTLData
, wszCloseBrackets2
);
860 if(pTypeAttr
->wTypeFlags
)
862 #define ENUM_FLAGS(x) if(pTypeAttr->wTypeFlags & x &&\
863 (pTypeAttr->typekind != TKIND_DISPATCH || x != TYPEFLAG_FDISPATCHABLE))\
865 AddToTLDataStrW(pTLData, wszComa);\
866 AddToTLDataStrW(pTLData, wszNewLine);\
867 AddSpaces(pTLData, 4);\
868 AddToTLDataStrW(pTLData, wsz##x);\
870 ENUM_FLAGS(TYPEFLAG_FAPPOBJECT
);
871 ENUM_FLAGS(TYPEFLAG_FCANCREATE
);
872 ENUM_FLAGS(TYPEFLAG_FLICENSED
);
873 ENUM_FLAGS(TYPEFLAG_FPREDECLID
);
874 ENUM_FLAGS(TYPEFLAG_FHIDDEN
);
875 ENUM_FLAGS(TYPEFLAG_FCONTROL
);
876 ENUM_FLAGS(TYPEFLAG_FDUAL
);
877 ENUM_FLAGS(TYPEFLAG_FNONEXTENSIBLE
);
878 ENUM_FLAGS(TYPEFLAG_FOLEAUTOMATION
);
879 ENUM_FLAGS(TYPEFLAG_FRESTRICTED
);
880 ENUM_FLAGS(TYPEFLAG_FAGGREGATABLE
);
881 ENUM_FLAGS(TYPEFLAG_FREPLACEABLE
);
882 ENUM_FLAGS(TYPEFLAG_FREVERSEBIND
);
883 ENUM_FLAGS(TYPEFLAG_FPROXY
);
885 AddToTLDataStrW(pTLData
, wszNewLine
);
886 AddToTLDataStrW(pTLData
, wszCloseBrackets1
);
887 AddToTLDataStrW(pTLData
, wszNewLine
);
888 if(pTypeAttr
->typekind
!= TKIND_DISPATCH
) AddToTLDataStrW(pTLData
, wszInterface
);
889 else AddToTLDataStrW(pTLData
, wszDispinterface
);
890 AddToTLDataStrW(pTLData
, wszName
);
891 AddToTLDataStrW(pTLData
, wszSpace
);
892 if(cImplTypes
&& pTypeAttr
->typekind
!= TKIND_DISPATCH
)
894 AddToTLDataStrW(pTLData
, wszColon
);
895 AddToTLDataStrW(pTLData
, wszSpace
);
897 ITypeInfo_GetRefTypeOfImplType(pTypeInfo
, 0, &hRefType
);
898 ITypeInfo_GetRefTypeInfo(pTypeInfo
, hRefType
, &pRefTypeInfo
);
899 ITypeInfo_GetDocumentation(pRefTypeInfo
, MEMBERID_NIL
, &bstrName
,
901 AddToTLDataStrW(pTLData
, bstrName
);
902 AddToTLDataStrW(pTLData
, wszSpace
);
904 SysFreeString(bstrName
);
905 ITypeInfo_Release(pRefTypeInfo
);
907 AddToTLDataStrW(pTLData
, wszOpenBrackets3
);
908 AddToTLDataStrW(pTLData
, wszNewLine
);
910 AddToStrW(pTLData
->wszInsertAfter
, wszCloseBrackets3
);
911 AddToStrW(pTLData
->wszInsertAfter
, wszSemicolon
);
912 AddToStrW(pTLData
->wszInsertAfter
, wszNewLine
);
915 static void CreateTypedefHeader(ITypeInfo
*pTypeInfo
,
916 TYPEATTR
*pTypeAttr
, TYPELIB_DATA
*pTLData
)
919 WCHAR wszGuid
[MAX_LOAD_STRING
];
920 const WCHAR wszTypedef
[] = { 't','y','p','e','d','e','f',' ','\0' };
921 const WCHAR wszPublic
[] = { 'p','u','b','l','i','c','\0' };
923 AddToTLDataStrW(pTLData
, wszTypedef
);
924 if(memcmp(&pTypeAttr
->guid
, &GUID_NULL
, sizeof(GUID
)))
926 AddToTLDataStrW(pTLData
, wszOpenBrackets1
);
928 AddToTLDataStrW(pTLData
, wszUUID
);
929 AddToTLDataStrW(pTLData
, wszOpenBrackets2
);
930 StringFromGUID2(&(pTypeAttr
->guid
), wszGuid
, MAX_LOAD_STRING
);
931 wszGuid
[lstrlenW(wszGuid
)-1] = '\0';
932 AddToTLDataStrW(pTLData
, &wszGuid
[1]);
933 AddToTLDataStrW(pTLData
, wszCloseBrackets2
);
935 if(pTypeAttr
->typekind
== TKIND_ALIAS
)
937 if(bFirst
) AddToTLDataStrW(pTLData
, wszOpenBrackets1
);
940 AddToTLDataStrW(pTLData
, wszComa
);
941 AddToTLDataStrW(pTLData
, wszSpace
);
944 AddToTLDataStrW(pTLData
, wszPublic
);
948 AddToTLDataStrW(pTLData
, wszCloseBrackets1
);
949 AddToTLDataStrW(pTLData
, wszNewLine
);
953 static int PopulateTree(void)
959 ITypeInfo
*pTypeInfo
, *pRefTypeInfo
;
966 WCHAR wszText
[MAX_LOAD_STRING
];
967 WCHAR wszAfter
[MAX_LOAD_STRING
];
972 TYPELIB_DATA
*tldDispatch
;
975 const WCHAR wszGeneratedInfo
[] = { '/','/',' ','G','e','n','e','r','a','t','e','d',
976 ' ','.','I','D','L',' ','f','i','l','e',' ','(','b','y',' ','t','h','e',' ',
977 'O','L','E','/','C','O','M',' ','O','b','j','e','c','t',' ',
978 'V','i','e','w','e','r',')','\n','/','/','\n','/','/',' ',
979 't','y','p','e','l','i','b',' ','f','i','l','e','n','a','m','e',':',' ','\0'};
981 const WCHAR wszFormat
[] = { '%','s',' ','(','%','s',')','\0' };
982 const WCHAR wszFormat2
[] = { 'v','e','r','s','i','o','n',
983 '(','%','l','d','.','%','l','d',')','\0' };
985 const WCHAR wszTKIND_ENUM
[] = { 't','y','p','e','d','e','f',' ','e','n','u','m',' ','\0' };
986 const WCHAR wszTKIND_RECORD
[]
987 = { 't','y','p','e','d','e','f',' ','s','t','r','u','c','t',' ','\0' };
988 const WCHAR wszTKIND_MODULE
[] = { 'm','o','d','u','l','e',' ','\0' };
989 const WCHAR wszTKIND_INTERFACE
[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' };
990 const WCHAR wszTKIND_DISPATCH
[]
991 = { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' };
992 const WCHAR wszTKIND_COCLASS
[] = { 'c','o','c','l','a','s','s',' ','\0' };
993 const WCHAR wszTKIND_ALIAS
[] = { 't','y','p','e','d','e','f',' ','\0' };
994 const WCHAR wszTKIND_UNION
[]
995 = { 't','y','p','e','d','e','f',' ','u','n','i','o','n',' ','\0' };
997 const WCHAR wszHelpString
[] = { 'h','e','l','p','s','t','r','i','n','g','\0' };
998 const WCHAR wszLibrary
[] = { 'l','i','b','r','a','r','y',' ','\0' };
999 const WCHAR wszTag
[] = { 't','a','g','\0' };
1001 WCHAR wszProperties
[] = { 'p','r','o','p','e','r','t','i','e','s','\0' };
1002 WCHAR wszMethods
[] = { 'm','e','t','h','o','d','s','\0' };
1004 U(tvis
).item
.mask
= TVIF_TEXT
|TVIF_PARAM
;
1005 U(tvis
).item
.cchTextMax
= MAX_LOAD_STRING
;
1006 U(tvis
).item
.pszText
= wszText
;
1007 tvis
.hInsertAfter
= (HTREEITEM
)TVI_LAST
;
1008 tvis
.hParent
= TVI_ROOT
;
1010 if(FAILED((hRes
= LoadTypeLib(typelib
.wszFileName
, &pTypeLib
))))
1012 WCHAR wszMessage
[MAX_LOAD_STRING
];
1013 WCHAR wszError
[MAX_LOAD_STRING
];
1015 LoadString(globals
.hMainInst
, IDS_ERROR_LOADTYPELIB
,
1016 wszError
, sizeof(WCHAR
[MAX_LOAD_STRING
]));
1017 wsprintfW(wszMessage
, wszError
, typelib
.wszFileName
, hRes
);
1018 MessageBox(globals
.hMainWnd
, wszMessage
, NULL
, MB_OK
|MB_ICONEXCLAMATION
);
1021 count
= ITypeLib_GetTypeInfoCount(pTypeLib
);
1023 ITypeLib_GetDocumentation(pTypeLib
, -1, &bstrName
, &bstrData
, NULL
, NULL
);
1024 ITypeLib_GetLibAttr(pTypeLib
, &pTLibAttr
);
1026 tld
= InitializeTLData();
1027 U(tvis
).item
.lParam
= (LPARAM
) tld
;
1028 AddToTLDataStrW(tld
, wszGeneratedInfo
);
1029 AddToTLDataStrW(tld
, typelib
.wszFileName
);
1030 AddToTLDataStrW(tld
, wszNewLine
);
1031 AddToTLDataStrW(tld
, wszNewLine
);
1032 AddToTLDataStrW(tld
, wszOpenBrackets1
);
1033 AddToTLDataStrW(tld
, wszNewLine
);
1035 AddToTLDataStrW(tld
, wszUUID
);
1036 AddToTLDataStrW(tld
, wszOpenBrackets2
);
1037 StringFromGUID2(&(pTLibAttr
->guid
), wszText
, MAX_LOAD_STRING
);
1038 wszText
[lstrlenW(wszText
)-1] = '\0';
1039 AddToTLDataStrW(tld
, &wszText
[1]);
1040 AddToTLDataStrW(tld
, wszCloseBrackets2
);
1041 AddToTLDataStrW(tld
, wszComa
);
1042 AddToTLDataStrW(tld
, wszNewLine
);
1044 wsprintfW(wszText
, wszFormat2
, pTLibAttr
->wMajorVerNum
, pTLibAttr
->wMinorVerNum
);
1045 AddToTLDataStrW(tld
, wszText
);
1046 AddToTLDataStrW(tld
, wszComa
);
1047 AddToTLDataStrW(tld
, wszNewLine
);
1049 AddToTLDataStrW(tld
, wszHelpString
);
1050 AddToTLDataStrW(tld
, wszOpenBrackets2
);
1051 AddToTLDataStrW(tld
, wszInvertedComa
);
1052 AddToTLDataStrW(tld
, bstrData
);
1053 AddToTLDataStrW(tld
, wszInvertedComa
);
1054 AddToTLDataStrW(tld
, wszCloseBrackets2
);
1055 AddToTLDataStrW(tld
, wszNewLine
);
1056 AddToTLDataStrW(tld
, wszCloseBrackets1
);
1057 AddToTLDataStrW(tld
, wszNewLine
);
1058 AddToTLDataStrW(tld
, wszLibrary
);
1059 AddToTLDataStrW(tld
, bstrName
);
1060 AddToTLDataStrW(tld
, wszNewLine
);
1061 AddToTLDataStrW(tld
, wszOpenBrackets3
);
1062 AddToTLDataStrW(tld
, wszNewLine
);
1064 AddToStrW(tld
->wszInsertAfter
, wszCloseBrackets3
);
1065 AddToStrW(tld
->wszInsertAfter
, wszSemicolon
);
1067 wsprintfW(wszText
, wszFormat
, bstrName
, bstrData
);
1068 SysFreeString(bstrName
);
1069 SysFreeString(bstrData
);
1070 tvis
.hParent
= (HTREEITEM
)SendMessage(typelib
.hTree
,
1071 TVM_INSERTITEM
, 0, (LPARAM
)&tvis
);
1073 for(i
=0; i
<count
; i
++)
1076 ITypeLib_GetTypeInfo(pTypeLib
, i
, &pTypeInfo
);
1078 ITypeInfo_GetDocumentation(pTypeInfo
, MEMBERID_NIL
, &bstrName
, &bstrData
,
1079 &ulHelpContext
, NULL
);
1080 ITypeInfo_GetTypeAttr(pTypeInfo
, &pTypeAttr
);
1082 memset(wszText
, 0, sizeof(wszText
));
1083 memset(wszAfter
, 0, sizeof(wszAfter
));
1084 tld
= InitializeTLData();
1085 U(tvis
).item
.lParam
= (LPARAM
)tld
;
1086 switch(pTypeAttr
->typekind
)
1089 AddToStrW(wszText
, wszTKIND_ENUM
);
1090 AddToStrW(wszText
, bstrName
);
1092 CreateTypedefHeader(pTypeInfo
, pTypeAttr
, tld
);
1093 AddToTLDataStrW(tld
, &wszTKIND_ENUM
[lstrlenW(wszTKIND_ALIAS
)]);
1094 AddToTLDataStrW(tld
, wszOpenBrackets3
);
1095 AddToTLDataStrW(tld
,wszNewLine
);
1096 AddToStrW(tld
->wszInsertAfter
, wszCloseBrackets3
);
1097 AddToStrW(tld
->wszInsertAfter
, wszSpace
);
1098 AddToStrW(tld
->wszInsertAfter
, bstrName
);
1099 AddToStrW(tld
->wszInsertAfter
, wszSemicolon
);
1100 AddToStrW(tld
->wszInsertAfter
, wszNewLine
);
1103 hParent
= TreeView_InsertItem(typelib
.hTree
, &tvis
);
1104 EnumEnums(pTypeInfo
, pTypeAttr
->cVars
, hParent
);
1105 AddChildrenData(hParent
, tld
);
1106 AddToTLDataStrW(tld
, tld
->wszInsertAfter
);
1109 AddToTLDataStrW(tld
, wszTKIND_RECORD
);
1110 AddToTLDataStrW(tld
, wszTag
);
1111 AddToTLDataStrW(tld
, bstrName
);
1112 AddToTLDataStrW(tld
, wszSpace
);
1113 AddToTLDataStrW(tld
, wszOpenBrackets3
);
1114 AddToTLDataStrW(tld
, wszNewLine
);
1116 AddToStrW(tld
->wszInsertAfter
, wszCloseBrackets3
);
1117 AddToStrW(tld
->wszInsertAfter
, wszSpace
);
1118 AddToStrW(tld
->wszInsertAfter
, bstrName
);
1119 AddToStrW(tld
->wszInsertAfter
, wszSemicolon
);
1120 AddToStrW(tld
->wszInsertAfter
, wszNewLine
);
1122 AddToStrW(wszText
, wszTKIND_RECORD
);
1123 AddToStrW(wszText
, bstrName
);
1126 AddToStrW(wszText
, wszTKIND_MODULE
);
1127 AddToStrW(wszText
, bstrName
);
1129 case TKIND_INTERFACE
:
1130 CreateInterfaceInfo(pTypeInfo
, pTypeAttr
->cImplTypes
, bstrName
,
1131 bstrData
, ulHelpContext
, pTypeAttr
, tld
);
1132 tld
->bPredefine
= TRUE
;
1134 AddToStrW(wszText
, wszTKIND_INTERFACE
);
1135 AddToStrW(wszText
, bstrName
);
1138 AddToStrW(wszText
, wszTKIND_COCLASS
);
1139 AddToStrW(wszText
, bstrName
);
1142 AddToStrW(wszText
, wszTKIND_UNION
);
1143 AddToStrW(wszText
, bstrName
);
1145 case TKIND_DISPATCH
:
1146 CreateInterfaceInfo(pTypeInfo
, pTypeAttr
->cImplTypes
, bstrName
,
1147 bstrData
, ulHelpContext
, pTypeAttr
, tld
);
1148 tld
->bPredefine
= TRUE
;
1149 AddToStrW(wszText
, wszTKIND_DISPATCH
);
1150 AddToStrW(wszText
, bstrName
);
1152 hParent
= TreeView_InsertItem(typelib
.hTree
, &tvis
);
1153 hMain
= tvis
.hParent
;
1156 lstrcpyW(wszText
, wszProperties
);
1157 tvis
.hParent
= hParent
;
1158 tld
= InitializeTLData();
1159 U(tvis
).item
.lParam
= (LPARAM
) tld
;
1160 AddToTLDataStrW(tld
, wszProperties
);
1161 AddToTLDataStrW(tld
, wszColon
);
1162 AddToTLDataStrW(tld
, wszNewLine
);
1163 tvis
.hParent
= TreeView_InsertItem(typelib
.hTree
, &tvis
);
1164 EnumVars(pTypeInfo
, pTypeAttr
->cVars
, tvis
.hParent
);
1165 AddChildrenData(tvis
.hParent
, tld
);
1167 lstrcpyW(wszText
, wszMethods
);
1168 tvis
.hParent
= hParent
;
1169 tld
= InitializeTLData();
1170 U(tvis
).item
.lParam
= (LPARAM
) tld
;
1171 AddToTLDataStrW(tld
, wszMethods
);
1172 AddToTLDataStrW(tld
, wszColon
);
1173 AddToTLDataStrW(tld
, wszNewLine
);
1174 tvis
.hParent
= TreeView_InsertItem(typelib
.hTree
, &tvis
);
1175 EnumFuncs(pTypeInfo
, pTypeAttr
->cFuncs
, tvis
.hParent
);
1176 AddChildrenData(tvis
.hParent
, tld
);
1178 EnumImplTypes(pTypeInfo
, pTypeAttr
->cImplTypes
, hParent
);
1179 AddChildrenData(hParent
, tldDispatch
);
1180 AddToTLDataStrW(tldDispatch
, tldDispatch
->wszInsertAfter
);
1183 tvis
.hParent
= hMain
;
1185 if(SUCCEEDED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo
, -1, &hRefType
)))
1189 ITypeInfo_ReleaseTypeAttr(pTypeInfo
, pTypeAttr
);
1190 SysFreeString(bstrName
);
1191 SysFreeString(bstrData
);
1193 memset(wszText
, 0, sizeof(wszText
));
1194 tld
= InitializeTLData();
1195 U(tvis
).item
.lParam
= (LPARAM
) tld
;
1197 ITypeInfo_GetRefTypeInfo(pTypeInfo
, hRefType
, &pRefTypeInfo
);
1198 ITypeInfo_GetDocumentation(pRefTypeInfo
, MEMBERID_NIL
, &bstrName
,
1199 &bstrData
, &ulHelpContext
, NULL
);
1200 ITypeInfo_GetTypeAttr(pRefTypeInfo
, &pTypeAttr
);
1202 CreateInterfaceInfo(pTypeInfo
, pTypeAttr
->cImplTypes
, bstrName
,
1203 bstrData
, ulHelpContext
, pTypeAttr
, tld
);
1204 tld
->bPredefine
= TRUE
;
1206 AddToStrW(wszText
, wszTKIND_INTERFACE
);
1207 AddToStrW(wszText
, bstrName
);
1208 ITypeInfo_Release(pRefTypeInfo
);
1212 AddToStrW(wszText
, wszTKIND_ALIAS
);
1213 CreateTypeInfo(wszText
, wszAfter
, pTypeAttr
->tdescAlias
, pTypeInfo
);
1214 AddToStrW(wszText
, wszSpace
);
1215 AddToStrW(wszText
, bstrName
);
1216 AddToStrW(wszText
, wszAfter
);
1218 CreateTypedefHeader(pTypeInfo
, pTypeAttr
, tld
);
1219 AddToTLDataStrW(tld
, &wszText
[lstrlenW(wszTKIND_ALIAS
)]);
1220 AddToTLDataStrW(tld
, wszSemicolon
);
1221 AddToTLDataStrW(tld
, wszNewLine
);
1224 lstrcpyW(wszText
, bstrName
);
1225 WINE_FIXME("pTypeAttr->typekind == %d not supported\n",
1226 pTypeAttr
->typekind
);
1231 hParent
= TreeView_InsertItem(typelib
.hTree
, &tvis
);
1233 EnumVars(pTypeInfo
, pTypeAttr
->cVars
, hParent
);
1234 EnumFuncs(pTypeInfo
, pTypeAttr
->cFuncs
, hParent
);
1235 EnumImplTypes(pTypeInfo
, pTypeAttr
->cImplTypes
, hParent
);
1237 if(memcmp(bstrName
, wszVT_UNKNOWN
, sizeof(wszVT_UNKNOWN
)))
1238 AddChildrenData(hParent
, tld
);
1239 AddToTLDataStrW(tld
, tld
->wszInsertAfter
);
1242 ITypeInfo_ReleaseTypeAttr(pTypeInfo
, pTypeAttr
);
1243 ITypeInfo_Release(pTypeInfo
);
1244 SysFreeString(bstrName
);
1245 SysFreeString(bstrData
);
1247 SendMessage(typelib
.hTree
, TVM_EXPAND
, TVE_EXPAND
, (LPARAM
)tvis
.hParent
);
1249 memset(&tvi
, 0, sizeof(TVITEM
));
1250 tvi
.mask
= TVIF_PARAM
;
1251 tvi
.hItem
= tvis
.hParent
;
1253 SendMessage(typelib
.hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
1254 AddPredefinitions(tvi
.hItem
, (TYPELIB_DATA
*)(tvi
.lParam
));
1255 AddIdlData(tvi
.hItem
, (TYPELIB_DATA
*)(tvi
.lParam
));
1256 AddToTLDataStrW((TYPELIB_DATA
*)(tvi
.lParam
),
1257 ((TYPELIB_DATA
*)(tvi
.lParam
))->wszInsertAfter
);
1259 ITypeLib_Release(pTypeLib
);
1263 void UpdateData(HTREEITEM item
)
1267 memset(&tvi
, 0, sizeof(TVITEM
));
1268 tvi
.mask
= TVIF_PARAM
;
1271 SendMessage(typelib
.hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
1274 SetWindowText(typelib
.hEdit
, wszSpace
);
1278 SetWindowText(typelib
.hEdit
, ((TYPELIB_DATA
*)tvi
.lParam
)->idl
);
1281 static void TypeLibResizeChild(void)
1285 MoveWindow(typelib
.hStatusBar
, 0, 0, 0, 0, TRUE
);
1287 if(IsWindowVisible(typelib
.hStatusBar
))
1288 GetClientRect(typelib
.hStatusBar
, &stat
);
1289 else stat
.bottom
= 0;
1291 GetClientRect(globals
.hTypeLibWnd
, &client
);
1292 MoveWindow(typelib
.hPaneWnd
, 0, 0,
1293 client
.right
, client
.bottom
-stat
.bottom
, TRUE
);
1296 static void TypeLibMenuCommand(WPARAM wParam
, HWND hWnd
)
1306 vis
= IsWindowVisible(typelib
.hStatusBar
);
1307 ShowWindow(typelib
.hStatusBar
, vis
? SW_HIDE
: SW_SHOW
);
1308 CheckMenuItem(GetMenu(hWnd
), LOWORD(wParam
),
1309 vis
? MF_UNCHECKED
: MF_CHECKED
);
1310 TypeLibResizeChild();
1313 DestroyWindow(hWnd
);
1318 static void UpdateTypeLibStatusBar(int itemID
)
1320 WCHAR info
[MAX_LOAD_STRING
];
1322 if(!LoadString(globals
.hMainInst
, itemID
, info
, sizeof(WCHAR
[MAX_LOAD_STRING
])))
1323 LoadString(globals
.hMainInst
, IDS_READY
, info
, sizeof(WCHAR
[MAX_LOAD_STRING
]));
1325 SendMessage(typelib
.hStatusBar
, SB_SETTEXT
, 0, (LPARAM
)info
);
1328 static void EmptyTLTree(void)
1333 tvi
.mask
= TVIF_PARAM
;
1334 cur
= TreeView_GetChild(typelib
.hTree
, TVI_ROOT
);
1339 cur
= TreeView_GetChild(typelib
.hTree
, del
);
1341 if(!cur
) cur
= TreeView_GetNextSibling(typelib
.hTree
, del
);
1342 if(!cur
) cur
= TreeView_GetParent(typelib
.hTree
, del
);
1345 SendMessage(typelib
.hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
1348 HeapFree(GetProcessHeap(), 0, ((TYPELIB_DATA
*)tvi
.lParam
)->idl
);
1349 HeapFree(GetProcessHeap(), 0, (TYPELIB_DATA
*)tvi
.lParam
);
1352 SendMessage(typelib
.hTree
, TVM_DELETEITEM
, 0, (LPARAM
)del
);
1358 LRESULT CALLBACK
TypeLibProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1364 if(!CreatePanedWindow(hWnd
, &typelib
.hPaneWnd
, globals
.hMainInst
))
1365 DestroyWindow(hWnd
);
1366 typelib
.hTree
= CreateWindowEx(WS_EX_CLIENTEDGE
, WC_TREEVIEW
, NULL
,
1367 WS_CHILD
|WS_VISIBLE
|TVS_HASLINES
|TVS_HASBUTTONS
|TVS_LINESATROOT
,
1368 0, 0, 0, 0, typelib
.hPaneWnd
, (HMENU
)TYPELIB_TREE
,
1369 globals
.hMainInst
, NULL
);
1370 typelib
.hEdit
= CreateWindowEx(WS_EX_CLIENTEDGE
, WC_EDIT
, NULL
,
1371 WS_CHILD
|WS_VISIBLE
|ES_MULTILINE
|ES_READONLY
|WS_HSCROLL
|WS_VSCROLL
,
1372 0, 0, 0, 0, typelib
.hPaneWnd
, NULL
, globals
.hMainInst
, NULL
);
1374 SetLeft(typelib
.hPaneWnd
, typelib
.hTree
);
1375 SetRight(typelib
.hPaneWnd
, typelib
.hEdit
);
1377 if(PopulateTree()) DestroyWindow(hWnd
);
1378 else SetFocus(typelib
.hTree
);
1382 TypeLibMenuCommand(LOWORD(wParam
), hWnd
);
1384 UpdateTypeLibStatusBar(LOWORD(wParam
));
1387 SetFocus(typelib
.hTree
);
1390 if(wParam
== SIZE_MINIMIZED
) break;
1391 TypeLibResizeChild();
1397 return DefWindowProc(hWnd
, uMsg
, wParam
, lParam
);
1402 BOOL
TypeLibRegisterClass(void)
1406 memset(&wcc
, 0, sizeof(WNDCLASS
));
1407 wcc
.lpfnWndProc
= TypeLibProc
;
1408 wcc
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
1409 wcc
.lpszMenuName
= MAKEINTRESOURCE(IDM_TYPELIB
);
1410 wcc
.lpszClassName
= wszTypeLib
;
1412 if(!RegisterClass(&wcc
))
1418 BOOL
CreateTypeLibWindow(HINSTANCE hInst
, WCHAR
*wszFileName
)
1420 WCHAR wszTitle
[MAX_LOAD_STRING
];
1421 LoadString(hInst
, IDS_TYPELIBTITLE
, wszTitle
, sizeof(WCHAR
[MAX_LOAD_STRING
]));
1423 if(wszFileName
) lstrcpyW(typelib
.wszFileName
, wszFileName
);
1428 memset(&tvi
, 0, sizeof(TVITEM
));
1429 tvi
.hItem
= TreeView_GetSelection(globals
.hTree
);
1431 SendMessage(globals
.hTree
, TVM_GETITEM
, 0, (LPARAM
)&tvi
);
1432 lstrcpyW(typelib
.wszFileName
, ((ITEM_INFO
*)tvi
.lParam
)->path
);
1435 globals
.hTypeLibWnd
= CreateWindow(wszTypeLib
, wszTitle
,
1436 WS_OVERLAPPEDWINDOW
|WS_VISIBLE
,
1437 CW_USEDEFAULT
, CW_USEDEFAULT
, 800, 600, NULL
, NULL
, hInst
, NULL
);
1438 if(!globals
.hTypeLibWnd
) return FALSE
;
1440 typelib
.hStatusBar
= CreateStatusWindow(WS_VISIBLE
|WS_CHILD
,
1441 (LPWSTR
)wszTitle
, globals
.hTypeLibWnd
, 0);
1443 TypeLibResizeChild();