2006-06-30 15:29:56 +00:00
|
|
|
/*
|
|
|
|
* OleView (typelib.c)
|
|
|
|
*
|
|
|
|
* Copyright 2006 Piotr Caban
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
2006-07-02 17:43:30 +00:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(oleview);
|
|
|
|
|
2006-06-30 15:29:56 +00:00
|
|
|
TYPELIB typelib;
|
|
|
|
static const WCHAR wszTypeLib[] = { 'T','Y','P','E','L','I','B','\0' };
|
|
|
|
|
2006-07-02 17:43:30 +00:00
|
|
|
static const WCHAR wszFailed[] = { '<','f','a','i','l','e','d','>','\0' };
|
|
|
|
static const WCHAR wszSpace[] = { ' ','\0' };
|
|
|
|
static const WCHAR wszAsterix[] = { '*','\0' };
|
|
|
|
|
|
|
|
static const WCHAR wszVT_BOOL[]
|
|
|
|
= { 'V','A','R','I','A','N','T','_','B','O','O','L','\0' };
|
|
|
|
static const WCHAR wszVT_UI1[]
|
|
|
|
= { 'u','n','s','i','g','n','e','d',' ','c','h','a','r','\0' };
|
|
|
|
static const WCHAR wszVT_UI4[]
|
|
|
|
= { 'u','n','s','i','g','n','e','d',' ','l','o','n','g','\0' };
|
|
|
|
static const WCHAR wszVT_I4[] = { 'l','o','n','g','\0' };
|
|
|
|
static const WCHAR wszVT_R4[] = { 's','i','n','g','l','e','\0' };
|
|
|
|
static const WCHAR wszVT_INT[] = { 'i','n','t','\0' };
|
|
|
|
static const WCHAR wszVT_BSTR[] = { 'B','S','T','R','\0' };
|
|
|
|
static const WCHAR wszVT_CY[] = { 'C','U','R','R','E','N','C','Y','\0' };
|
|
|
|
|
2006-07-02 11:03:09 +00:00
|
|
|
void AddToStrW(WCHAR *wszDest, const WCHAR *wszSource)
|
|
|
|
{
|
|
|
|
lstrcpyW(&wszDest[lstrlenW(wszDest)], wszSource);
|
|
|
|
}
|
|
|
|
|
2006-07-02 17:43:30 +00:00
|
|
|
void CreateTypeInfo(WCHAR *wszAddTo, TYPEDESC tdesc, ITypeInfo *pTypeInfo)
|
|
|
|
{
|
|
|
|
BSTR bstrData;
|
|
|
|
HRESULT hRes;
|
|
|
|
ITypeInfo *pRefTypeInfo;
|
|
|
|
|
|
|
|
switch(tdesc.vt&VT_TYPEMASK)
|
|
|
|
{
|
|
|
|
#define VTADDTOSTR(x) case x:\
|
|
|
|
AddToStrW(wszAddTo, wsz##x);\
|
|
|
|
break
|
|
|
|
VTADDTOSTR(VT_BOOL);
|
|
|
|
VTADDTOSTR(VT_UI1);
|
|
|
|
VTADDTOSTR(VT_UI4);
|
|
|
|
VTADDTOSTR(VT_I4);
|
|
|
|
VTADDTOSTR(VT_R4);
|
|
|
|
VTADDTOSTR(VT_INT);
|
|
|
|
VTADDTOSTR(VT_BSTR);
|
|
|
|
VTADDTOSTR(VT_CY);
|
|
|
|
case VT_PTR:
|
|
|
|
CreateTypeInfo(wszAddTo, *U(tdesc).lptdesc, pTypeInfo);
|
|
|
|
AddToStrW(wszAddTo, wszAsterix);
|
|
|
|
break;
|
|
|
|
case VT_USERDEFINED:
|
|
|
|
hRes = ITypeInfo_GetRefTypeInfo(pTypeInfo,
|
|
|
|
U(tdesc).hreftype, &pRefTypeInfo);
|
|
|
|
if(SUCCEEDED(hRes))
|
|
|
|
{
|
|
|
|
ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL,
|
|
|
|
&bstrData, NULL, NULL, NULL);
|
|
|
|
AddToStrW(wszAddTo, bstrData);
|
|
|
|
SysFreeString(bstrData);
|
|
|
|
ITypeInfo_Release(pRefTypeInfo);
|
|
|
|
}
|
|
|
|
else AddToStrW(wszAddTo, wszFailed);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WINE_FIXME("tdesc.vt&VT_TYPEMASK == %d not supported\n",
|
|
|
|
tdesc.vt&VT_TYPEMASK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-02 11:03:09 +00:00
|
|
|
int PopulateTree(void)
|
2006-06-30 15:29:56 +00:00
|
|
|
{
|
|
|
|
TVINSERTSTRUCT tvis;
|
|
|
|
ITypeLib *pTypeLib;
|
2006-07-02 17:44:39 +00:00
|
|
|
ITypeInfo *pTypeInfo, *pRefTypeInfo;
|
|
|
|
HREFTYPE hRefType;
|
2006-07-02 11:03:09 +00:00
|
|
|
TYPEATTR *pTypeAttr;
|
2006-06-30 15:29:56 +00:00
|
|
|
INT count, i;
|
|
|
|
BSTR bstrName;
|
2006-07-02 11:03:09 +00:00
|
|
|
BSTR bstrData;
|
|
|
|
WCHAR wszText[MAX_LOAD_STRING];
|
|
|
|
HRESULT hRes;
|
|
|
|
|
|
|
|
const WCHAR wszFormat[] = { '%','s',' ','(','%','s',')','\0' };
|
|
|
|
|
|
|
|
const WCHAR wszTKIND_ENUM[] = { 't','y','p','e','d','e','f',' ','e','n','u','m',' ','\0' };
|
|
|
|
const WCHAR wszTKIND_RECORD[]
|
|
|
|
= { 't','y','p','e','d','e','f',' ','s','t','r','u','c','t',' ','\0' };
|
|
|
|
const WCHAR wszTKIND_MODULE[] = { 'm','o','d','u','l','e',' ','\0' };
|
|
|
|
const WCHAR wszTKIND_INTERFACE[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' };
|
|
|
|
const WCHAR wszTKIND_DISPATCH[]
|
|
|
|
= { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' };
|
|
|
|
const WCHAR wszTKIND_COCLASS[] = { 'c','o','c','l','a','s','s',' ','\0' };
|
|
|
|
const WCHAR wszTKIND_ALIAS[] = { 't','y','p','e','d','e','f',' ','\0' };
|
|
|
|
const WCHAR wszTKIND_UNION[]
|
|
|
|
= { 't','y','p','e','d','e','f',' ','u','n','i','o','n',' ','\0' };
|
|
|
|
|
2006-06-30 15:29:56 +00:00
|
|
|
U(tvis).item.mask = TVIF_TEXT|TVIF_CHILDREN;
|
2006-07-02 11:03:09 +00:00
|
|
|
U(tvis).item.cchTextMax = MAX_LOAD_STRING;
|
|
|
|
U(tvis).item.pszText = wszText;
|
2006-06-30 15:29:56 +00:00
|
|
|
U(tvis).item.cChildren = 1;
|
|
|
|
tvis.hInsertAfter = (HTREEITEM)TVI_LAST;
|
|
|
|
tvis.hParent = TVI_ROOT;
|
|
|
|
|
2006-07-02 11:04:26 +00:00
|
|
|
if(FAILED((hRes = LoadTypeLib(typelib.wszFileName, &pTypeLib))))
|
2006-07-02 11:03:09 +00:00
|
|
|
{
|
|
|
|
WCHAR wszMessage[MAX_LOAD_STRING];
|
|
|
|
WCHAR wszError[MAX_LOAD_STRING];
|
|
|
|
|
|
|
|
LoadString(globals.hMainInst, IDS_ERROR_LOADTYPELIB,
|
|
|
|
wszError, sizeof(WCHAR[MAX_LOAD_STRING]));
|
2006-07-02 11:04:26 +00:00
|
|
|
wsprintfW(wszMessage, wszError, typelib.wszFileName, hRes);
|
2006-07-02 11:03:09 +00:00
|
|
|
MessageBox(globals.hMainWnd, wszMessage, NULL, MB_OK|MB_ICONEXCLAMATION);
|
|
|
|
return 1;
|
|
|
|
}
|
2006-06-30 15:29:56 +00:00
|
|
|
count = ITypeLib_GetTypeInfoCount(pTypeLib);
|
|
|
|
|
2006-07-02 11:03:09 +00:00
|
|
|
ITypeLib_GetDocumentation(pTypeLib, -1, &bstrName, &bstrData, NULL, NULL);
|
|
|
|
wsprintfW(wszText, wszFormat, bstrName, bstrData);
|
|
|
|
SysFreeString(bstrName);
|
|
|
|
SysFreeString(bstrData);
|
|
|
|
tvis.hParent = (HTREEITEM)SendMessage(typelib.hTree,
|
|
|
|
TVM_INSERTITEM, 0, (LPARAM)&tvis);
|
2006-06-30 15:29:56 +00:00
|
|
|
|
2006-07-02 11:03:09 +00:00
|
|
|
for(i=0; i<count; i++)
|
|
|
|
{
|
|
|
|
ITypeLib_GetTypeInfo(pTypeLib, i, &pTypeInfo);
|
2006-06-30 15:29:56 +00:00
|
|
|
|
2006-07-02 11:03:09 +00:00
|
|
|
ITypeInfo_GetDocumentation(pTypeInfo, MEMBERID_NIL, &bstrName, NULL, NULL, NULL);
|
|
|
|
ITypeInfo_GetTypeAttr(pTypeInfo, &pTypeAttr);
|
2006-06-30 15:29:56 +00:00
|
|
|
|
2006-07-02 11:03:09 +00:00
|
|
|
memset(wszText, 0, sizeof(wszText));
|
|
|
|
switch(pTypeAttr->typekind)
|
|
|
|
{
|
|
|
|
#define TKINDADDTOSTR(x) case x:\
|
|
|
|
AddToStrW(wszText, wsz##x);\
|
|
|
|
AddToStrW(wszText, bstrName);\
|
|
|
|
break
|
|
|
|
TKINDADDTOSTR(TKIND_ENUM);
|
|
|
|
TKINDADDTOSTR(TKIND_RECORD);
|
|
|
|
TKINDADDTOSTR(TKIND_MODULE);
|
|
|
|
TKINDADDTOSTR(TKIND_INTERFACE);
|
|
|
|
TKINDADDTOSTR(TKIND_COCLASS);
|
|
|
|
TKINDADDTOSTR(TKIND_UNION);
|
2006-07-02 17:44:39 +00:00
|
|
|
case TKIND_DISPATCH:
|
|
|
|
AddToStrW(wszText, wszTKIND_DISPATCH);
|
|
|
|
AddToStrW(wszText, bstrName);
|
|
|
|
if(SUCCEEDED(ITypeInfo_GetRefTypeOfImplType(pTypeInfo, -1, &hRefType)))
|
|
|
|
{
|
|
|
|
SendMessage(typelib.hTree, TVM_INSERTITEM, 0, (LPARAM)&tvis);
|
|
|
|
memset(wszText, 0, sizeof(wszText));
|
|
|
|
|
|
|
|
ITypeInfo_GetRefTypeInfo(pTypeInfo, hRefType, &pRefTypeInfo);
|
|
|
|
ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL, &bstrName,
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
AddToStrW(wszText, wszTKIND_INTERFACE);
|
|
|
|
AddToStrW(wszText, bstrName);
|
|
|
|
ITypeInfo_Release(pRefTypeInfo);
|
|
|
|
}
|
|
|
|
break;
|
2006-07-02 11:03:09 +00:00
|
|
|
case TKIND_ALIAS:
|
|
|
|
AddToStrW(wszText, wszTKIND_ALIAS);
|
2006-07-02 17:43:30 +00:00
|
|
|
CreateTypeInfo(wszText, pTypeAttr->tdescAlias, pTypeInfo);
|
|
|
|
AddToStrW(wszText, wszSpace);
|
2006-07-02 11:03:09 +00:00
|
|
|
AddToStrW(wszText, bstrName);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lstrcpyW(wszText, bstrName);
|
2006-07-02 17:43:30 +00:00
|
|
|
WINE_FIXME("pTypeAttr->typekind == %d\n not supported",
|
|
|
|
pTypeAttr->typekind);
|
2006-07-02 11:03:09 +00:00
|
|
|
}
|
|
|
|
SendMessage(typelib.hTree, TVM_INSERTITEM, 0, (LPARAM)&tvis);
|
|
|
|
ITypeInfo_ReleaseTypeAttr(pTypeInfo, pTypeAttr);
|
|
|
|
ITypeInfo_Release(pTypeInfo);
|
2006-06-30 15:29:56 +00:00
|
|
|
SysFreeString(bstrName);
|
|
|
|
}
|
|
|
|
SendMessage(typelib.hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)tvis.hParent);
|
|
|
|
|
|
|
|
ITypeLib_Release(pTypeLib);
|
2006-07-02 11:03:09 +00:00
|
|
|
return 0;
|
2006-06-30 15:29:56 +00:00
|
|
|
}
|
|
|
|
|
2006-06-30 16:42:14 +00:00
|
|
|
void TypeLibResizeChild(void)
|
|
|
|
{
|
|
|
|
RECT client, stat;
|
|
|
|
|
|
|
|
MoveWindow(typelib.hStatusBar, 0, 0, 0, 0, TRUE);
|
|
|
|
|
|
|
|
if(IsWindowVisible(typelib.hStatusBar))
|
|
|
|
GetClientRect(typelib.hStatusBar, &stat);
|
|
|
|
else stat.bottom = 0;
|
|
|
|
|
|
|
|
GetClientRect(globals.hTypeLibWnd, &client);
|
|
|
|
MoveWindow(typelib.hPaneWnd, 0, 0,
|
|
|
|
client.right, client.bottom-stat.bottom, TRUE);
|
|
|
|
}
|
|
|
|
|
2006-06-30 16:43:40 +00:00
|
|
|
void TypeLibMenuCommand(WPARAM wParam, HWND hWnd)
|
|
|
|
{
|
|
|
|
BOOL vis;
|
|
|
|
|
|
|
|
switch(wParam)
|
|
|
|
{
|
|
|
|
case IDM_STATUSBAR:
|
|
|
|
vis = IsWindowVisible(typelib.hStatusBar);
|
|
|
|
ShowWindow(typelib.hStatusBar, vis ? SW_HIDE : SW_SHOW);
|
|
|
|
CheckMenuItem(GetMenu(hWnd), LOWORD(wParam),
|
|
|
|
vis ? MF_UNCHECKED : MF_CHECKED);
|
|
|
|
TypeLibResizeChild();
|
|
|
|
break;
|
|
|
|
case IDM_CLOSE:
|
|
|
|
DestroyWindow(hWnd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-30 16:42:14 +00:00
|
|
|
void UpdateTypeLibStatusBar(int itemID)
|
|
|
|
{
|
|
|
|
WCHAR info[MAX_LOAD_STRING];
|
|
|
|
|
|
|
|
if(!LoadString(globals.hMainInst, itemID, info, sizeof(WCHAR[MAX_LOAD_STRING])))
|
|
|
|
LoadString(globals.hMainInst, IDS_READY, info, sizeof(WCHAR[MAX_LOAD_STRING]));
|
|
|
|
|
|
|
|
SendMessage(typelib.hStatusBar, SB_SETTEXT, 0, (LPARAM)info);
|
|
|
|
}
|
|
|
|
|
2006-06-30 15:29:56 +00:00
|
|
|
LRESULT CALLBACK TypeLibProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch(uMsg)
|
|
|
|
{
|
|
|
|
case WM_CREATE:
|
|
|
|
{
|
|
|
|
if(!CreatePanedWindow(hWnd, &typelib.hPaneWnd, globals.hMainInst))
|
|
|
|
DestroyWindow(hWnd);
|
|
|
|
typelib.hTree = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, NULL,
|
|
|
|
WS_CHILD|WS_VISIBLE|TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT,
|
|
|
|
0, 0, 0, 0, typelib.hPaneWnd, NULL, globals.hMainInst, NULL);
|
|
|
|
typelib.hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, NULL,
|
|
|
|
WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_READONLY|WS_HSCROLL|WS_VSCROLL,
|
|
|
|
0, 0, 0, 0, typelib.hPaneWnd, NULL, globals.hMainInst, NULL);
|
|
|
|
|
|
|
|
SetLeft(typelib.hPaneWnd, typelib.hTree);
|
|
|
|
SetRight(typelib.hPaneWnd, typelib.hEdit);
|
|
|
|
|
2006-07-02 11:03:09 +00:00
|
|
|
if(PopulateTree()) DestroyWindow(hWnd);
|
|
|
|
else SetFocus(typelib.hTree);
|
2006-06-30 15:29:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-06-30 16:43:40 +00:00
|
|
|
case WM_COMMAND:
|
|
|
|
TypeLibMenuCommand(LOWORD(wParam), hWnd);
|
2006-06-30 16:42:14 +00:00
|
|
|
case WM_MENUSELECT:
|
|
|
|
UpdateTypeLibStatusBar(LOWORD(wParam));
|
|
|
|
break;
|
|
|
|
case WM_SETFOCUS:
|
|
|
|
SetFocus(typelib.hTree);
|
|
|
|
break;
|
2006-06-30 15:29:56 +00:00
|
|
|
case WM_SIZE:
|
2006-06-30 16:42:14 +00:00
|
|
|
if(wParam == SIZE_MINIMIZED) break;
|
|
|
|
TypeLibResizeChild();
|
2006-06-30 15:29:56 +00:00
|
|
|
break;
|
|
|
|
case WM_DESTROY:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL TypeLibRegisterClass(void)
|
|
|
|
{
|
|
|
|
WNDCLASS wcc;
|
|
|
|
|
|
|
|
memset(&wcc, 0, sizeof(WNDCLASS));
|
|
|
|
wcc.lpfnWndProc = TypeLibProc;
|
|
|
|
wcc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
|
|
|
wcc.lpszMenuName = MAKEINTRESOURCE(IDM_TYPELIB);
|
|
|
|
wcc.lpszClassName = wszTypeLib;
|
|
|
|
|
|
|
|
if(!RegisterClass(&wcc))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-07-02 11:04:26 +00:00
|
|
|
BOOL CreateTypeLibWindow(HINSTANCE hInst, WCHAR *wszFileName)
|
2006-06-30 15:29:56 +00:00
|
|
|
{
|
|
|
|
WCHAR wszTitle[MAX_LOAD_STRING];
|
|
|
|
LoadString(hInst, IDS_TYPELIBTITLE, wszTitle, sizeof(WCHAR[MAX_LOAD_STRING]));
|
|
|
|
|
2006-07-02 11:04:26 +00:00
|
|
|
if(wszFileName) lstrcpyW(typelib.wszFileName, wszFileName);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TVITEM tvi;
|
|
|
|
|
|
|
|
memset(&tvi, 0, sizeof(TVITEM));
|
|
|
|
tvi.hItem = TreeView_GetSelection(globals.hTree);
|
|
|
|
|
|
|
|
SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
|
|
|
|
lstrcpyW(typelib.wszFileName, ((ITEM_INFO*)tvi.lParam)->path);
|
|
|
|
}
|
|
|
|
|
2006-06-30 15:29:56 +00:00
|
|
|
globals.hTypeLibWnd = CreateWindow(wszTypeLib, wszTitle,
|
|
|
|
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInst, NULL);
|
|
|
|
if(!globals.hTypeLibWnd) return FALSE;
|
2006-06-30 16:42:14 +00:00
|
|
|
|
|
|
|
typelib.hStatusBar = CreateStatusWindow(WS_VISIBLE|WS_CHILD,
|
|
|
|
(LPWSTR)wszTitle, globals.hTypeLibWnd, 0);
|
|
|
|
|
|
|
|
TypeLibResizeChild();
|
2006-06-30 15:29:56 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|