From 3348ecdddcde87260d4a5ae28b78c900206ca553 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Wed, 14 Jun 2006 19:52:26 +0200 Subject: [PATCH] oleview: Added TreeView window. --- programs/oleview/En.rc | 10 ++ programs/oleview/Makefile.in | 3 +- programs/oleview/main.h | 37 ++++++++ programs/oleview/oleview.c | 6 ++ programs/oleview/resource.h | 10 ++ programs/oleview/tree.c | 171 +++++++++++++++++++++++++++++++++++ 6 files changed, 236 insertions(+), 1 deletion(-) create mode 100644 programs/oleview/tree.c diff --git a/programs/oleview/En.rc b/programs/oleview/En.rc index 39d7c0e3a2a..46cff2df1f8 100644 --- a/programs/oleview/En.rc +++ b/programs/oleview/En.rc @@ -97,4 +97,14 @@ STRINGTABLE IDM_STATUSBAR, "Show or hide the status bar" IDM_REFRESH, "Refresh all lists" IDM_ABOUT, "Display program information, version namber and copyright" + + IDS_TREE_OC, "ObjectClasses" + IDS_TREE_GBCC, "Grouped by Component Category" + IDS_TREE_O1O, "OLE 1.0 Objects" + IDS_TREE_CLO, "COM Library Objects" + IDS_TREE_AO, "All Objects" + IDS_TREE_AID, "Application IDs" + IDS_TREE_TL, "Type Libraries" + IDS_TL_VER, "ver." + IDS_TREE_I, "Interfaces" } diff --git a/programs/oleview/Makefile.in b/programs/oleview/Makefile.in index f976743d15b..65925c24f7d 100644 --- a/programs/oleview/Makefile.in +++ b/programs/oleview/Makefile.in @@ -10,7 +10,8 @@ EXTRADEFS = -DUNICODE C_SRCS = \ oleview.c \ - pane.c + pane.c \ + tree.c RC_SRCS = rsrc.rc RC_BINSRC = rsrc.rc diff --git a/programs/oleview/main.h b/programs/oleview/main.h index 870d436def2..664284bc993 100644 --- a/programs/oleview/main.h +++ b/programs/oleview/main.h @@ -32,11 +32,19 @@ #define MAX_WINDOW_WIDTH 30000 #define STATUS_WINDOW 2000 +#define TREE_WINDOW 2001 + +/*ItemInfo flags */ +#define REGTOP 1 +#define REGPATH 2 +#define SHOWALL 4 +#define INTERFACE 8 typedef struct { HWND hMainWnd; HWND hPaneWnd; + HWND hTree; HWND hStatusBar; HWND hToolBar; HINSTANCE hMainInst; @@ -53,8 +61,37 @@ typedef struct INT last; }PANE; +typedef struct +{ + /* Main TreeView entries: */ + HTREEITEM hOC; /* Object Classes */ + HTREEITEM hGBCC; /* Grouped by Component Category */ + HTREEITEM hO1O; /* OLE 1.0 Objects */ + HTREEITEM hCLO; /* COM Library Objects */ + HTREEITEM hAO; /* All Objects */ + HTREEITEM hAID; /* Application IDs */ + HTREEITEM hTL; /* Type Libraries */ + HTREEITEM hI; /* Interfaces */ +}TREE; + +typedef struct +{ + CHAR cFlag; + WCHAR info[MAX_LOAD_STRING]; + WCHAR clsid[MAX_LOAD_STRING]; + BOOL loaded; + IUnknown *pU; +}ITEM_INFO; + extern GLOBALS globals; +extern TREE tree; /* Predefinitions: */ /* pane.c */ BOOL CreatePanedWindow(HWND hWnd, HWND *hWndCreated, HINSTANCE hInst); +void SetLeft(HWND hParent, HWND hWnd); +void SetRight(HWND hParent, HWND hWnd); + +/* tree.h */ +void EmptyTree(void); +HWND CreateTreeWindow(HINSTANCE hInst); diff --git a/programs/oleview/oleview.c b/programs/oleview/oleview.c index c2480554430..4997cf7ea6d 100644 --- a/programs/oleview/oleview.c +++ b/programs/oleview/oleview.c @@ -64,14 +64,20 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, OleInitialize(NULL); if(!CreatePanedWindow(hWnd, &globals.hPaneWnd, globals.hMainInst)) PostQuitMessage(0); + SetLeft(globals.hPaneWnd, CreateTreeWindow(globals.hMainInst)); + SetFocus(globals.hTree); break; case WM_DESTROY: OleUninitialize(); + EmptyTree(); PostQuitMessage(0); break; case WM_MENUSELECT: UpdateStatusBar(LOWORD(wParam)); break; + case WM_SETFOCUS: + SetFocus(globals.hTree); + break; case WM_SIZE: if(wParam == SIZE_MINIMIZED) break; ResizeChild(); diff --git a/programs/oleview/resource.h b/programs/oleview/resource.h index 9886d8223bc..1725326aaba 100644 --- a/programs/oleview/resource.h +++ b/programs/oleview/resource.h @@ -48,3 +48,13 @@ #define IDM_STATUSBAR 123 #define IDM_REFRESH 124 #define IDM_ABOUT 125 + +#define IDS_TREE_OC 200 +#define IDS_TREE_GBCC 201 +#define IDS_TREE_O1O 202 +#define IDS_TREE_CLO 203 +#define IDS_TREE_AO 204 +#define IDS_TREE_AID 210 +#define IDS_TREE_TL 220 +#define IDS_TL_VER 221 +#define IDS_TREE_I 230 diff --git a/programs/oleview/tree.c b/programs/oleview/tree.c new file mode 100644 index 00000000000..7155841a9f1 --- /dev/null +++ b/programs/oleview/tree.c @@ -0,0 +1,171 @@ +/* + * OleView (tree.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" + +TREE tree; +static const WCHAR wszCLSID[] = { 'C','L','S','I','D','\\','\0' }; +static const WCHAR wszAppID[] = { 'A','p','p','I','D','\\','\0' }; +static const WCHAR wszTypeLib[] = { 'T','y','p','e','L','i','b','\\','\0' }; +static const WCHAR wszInterface[] = { 'I','n','t','e','r','f','a','c','e','\\','\0' }; +static const WCHAR wszComponentCategories[] = { 'C','o','m','p','o','n','e','n','t', + ' ','C','a','t','e','g','o','r','i','e','s','\\','\0' }; + +LPARAM CreateITEM_INFO(INT flag, const WCHAR *info, const WCHAR *clsid) +{ + ITEM_INFO *reg; + + reg = HeapAlloc(GetProcessHeap(), 0, sizeof(ITEM_INFO)); + memset(reg, 0, sizeof(ITEM_INFO)); + + reg->cFlag = flag; + strcpyW(reg->info, info); + if(clsid) strcpyW(reg->clsid, clsid); + + return (LPARAM)reg; +} + +void AddBaseEntries(void) +{ + TVINSERTSTRUCT tvis; + WCHAR name[MAX_LOAD_STRING]; + + tvis.item.mask = TVIF_TEXT|TVIF_CHILDREN|TVIF_PARAM; + /* FIXME add TVIF_IMAGE */ + tvis.item.pszText = name; + tvis.item.cchTextMax = MAX_LOAD_STRING; + tvis.item.cChildren = 1; + tvis.hInsertAfter = (HTREEITEM)TVI_FIRST; + tvis.hParent = TVI_ROOT; + + LoadString(globals.hMainInst, IDS_TREE_I, tvis.item.pszText, + sizeof(WCHAR[MAX_LOAD_STRING])); + tvis.item.lParam = CreateITEM_INFO(REGTOP, wszInterface, NULL); + tree.hI = TreeView_InsertItem(globals.hTree, &tvis); + + LoadString(globals.hMainInst, IDS_TREE_TL, tvis.item.pszText, + sizeof(WCHAR[MAX_LOAD_STRING])); + tvis.item.lParam = CreateITEM_INFO(REGTOP, wszTypeLib, NULL); + tree.hTL = TreeView_InsertItem(globals.hTree, &tvis); + + LoadString(globals.hMainInst, IDS_TREE_AID, tvis.item.pszText, + sizeof(WCHAR[MAX_LOAD_STRING])); + tvis.item.lParam = CreateITEM_INFO(REGTOP|REGPATH, wszAppID, NULL); + tree.hAID = TreeView_InsertItem(globals.hTree, &tvis); + + LoadString(globals.hMainInst, IDS_TREE_OC, tvis.item.pszText, + sizeof(WCHAR[MAX_LOAD_STRING])); + tvis.item.lParam = (LPARAM)NULL; + tree.hOC = TreeView_InsertItem(globals.hTree, &tvis); + + + tvis.hParent = tree.hOC; + LoadString(globals.hMainInst, IDS_TREE_AO, tvis.item.pszText, + sizeof(WCHAR[MAX_LOAD_STRING])); + tvis.item.lParam = CreateITEM_INFO(REGTOP, wszCLSID, NULL); + tree.hAO = TreeView_InsertItem(globals.hTree, &tvis); + + LoadString(globals.hMainInst, IDS_TREE_CLO, tvis.item.pszText, + sizeof(WCHAR[MAX_LOAD_STRING])); + tree.hCLO = TreeView_InsertItem(globals.hTree, &tvis); + + LoadString(globals.hMainInst, IDS_TREE_O1O, tvis.item.pszText, + sizeof(WCHAR[MAX_LOAD_STRING])); + tvis.item.lParam = (LPARAM)NULL; + tree.hO1O = TreeView_InsertItem(globals.hTree, &tvis); + + LoadString(globals.hMainInst, IDS_TREE_GBCC, tvis.item.pszText, + sizeof(WCHAR[MAX_LOAD_STRING])); + tvis.item.lParam = CreateITEM_INFO(REGTOP|REGPATH, wszComponentCategories, NULL); + tree.hGBCC = TreeView_InsertItem(globals.hTree, &tvis); + + SendMessage(globals.hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)tree.hOC); +} + +void EmptyTree(void) +{ + HTREEITEM cur, del; + TVITEM tvi; + + tvi.mask = TVIF_PARAM; + cur = TreeView_GetChild(globals.hTree, TVI_ROOT); + + while(TRUE) + { + del = cur; + cur = TreeView_GetChild(globals.hTree, del); + + if(!cur) cur = TreeView_GetNextSibling(globals.hTree, del); + if(!cur) + { + cur = TreeView_GetPrevSibling(globals.hTree, del); + if(!cur) cur = TreeView_GetParent(globals.hTree, del); + + tvi.hItem = del; + SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi); + + if(tvi.lParam) + HeapFree(GetProcessHeap(), 0, (ITEM_INFO *)tvi.lParam); + + SendMessage(globals.hTree, TVM_DELETEITEM, 0, (LPARAM)del); + + if(!cur) break; + } + } +} + +void AddTreeEx(void) +{ + AddBaseEntries(); +} + +LRESULT CALLBACK TreeProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch(uMsg) + { + case WM_CREATE: + globals.hTree = CreateWindow(WC_TREEVIEW, NULL, + WS_CHILD|WS_VISIBLE|TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT, + 0, 0, 0, 0, hWnd, (HMENU)TREE_WINDOW, globals.hMainInst, NULL); + AddTreeEx(); + break; + case WM_SIZE: + MoveWindow(globals.hTree, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE); + break; + default: + return DefWindowProc(hWnd, uMsg, wParam, lParam); + } + return 0; +} + +HWND CreateTreeWindow(HINSTANCE hInst) +{ + WNDCLASS wct; + const WCHAR wszTreeClass[] = { 'T','R','E','E','\0' }; + + memset(&wct, 0, sizeof(WNDCLASS)); + wct.lpfnWndProc = TreeProc; + wct.lpszClassName = wszTreeClass; + + if(!RegisterClass(&wct)) return NULL; + + return CreateWindowEx(WS_EX_CLIENTEDGE, wszTreeClass, NULL, WS_CHILD|WS_VISIBLE, + 0, 0, 0, 0, globals.hPaneWnd, NULL, hInst, NULL); +}