oleview: Added status bar to TypeLib Viewer.
[wine] / programs / oleview / typelib.c
1 /*
2  * OleView (typelib.c)
3  *
4  * Copyright 2006 Piotr Caban
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "main.h"
22
23 TYPELIB typelib;
24 static const WCHAR wszTypeLib[] = { 'T','Y','P','E','L','I','B','\0' };
25
26 void PopulateTree(void)
27 {
28     TVITEM tvi;
29     TVINSERTSTRUCT tvis;
30     ITypeLib *pTypeLib;
31     INT count, i;
32     BSTR bstrName;
33
34     memset(&tvi, 0, sizeof(TVITEM));
35     tvi.hItem = TreeView_GetSelection(globals.hTree);
36
37     U(tvis).item.mask = TVIF_TEXT|TVIF_CHILDREN;
38     U(tvis).item.cChildren = 1;
39     tvis.hInsertAfter = (HTREEITEM)TVI_LAST;
40     tvis.hParent = TVI_ROOT;
41
42     SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
43     if(FAILED(LoadTypeLib(((ITEM_INFO*)tvi.lParam)->path, &pTypeLib))) return;
44
45     count = ITypeLib_GetTypeInfoCount(pTypeLib);
46
47     for(i=-1; i<count; i++) {
48         ITypeLib_GetDocumentation(pTypeLib, i, &bstrName, NULL, NULL, NULL);
49
50         U(tvis).item.cchTextMax = SysStringLen(bstrName);
51         U(tvis).item.pszText = bstrName;
52
53         if(i==-1)
54             tvis.hParent = (HTREEITEM)SendMessage(typelib.hTree,
55                     TVM_INSERTITEM, 0, (LPARAM)&tvis);
56         else SendMessage(typelib.hTree, TVM_INSERTITEM, 0, (LPARAM)&tvis);
57
58         SysFreeString(bstrName);
59     }
60     SendMessage(typelib.hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)tvis.hParent);
61
62     ITypeLib_Release(pTypeLib);
63 }
64
65 void TypeLibResizeChild(void)
66 {
67     RECT client, stat;
68
69     MoveWindow(typelib.hStatusBar, 0, 0, 0, 0, TRUE);
70
71     if(IsWindowVisible(typelib.hStatusBar))
72         GetClientRect(typelib.hStatusBar, &stat);
73     else stat.bottom = 0;
74
75     GetClientRect(globals.hTypeLibWnd, &client);
76     MoveWindow(typelib.hPaneWnd, 0, 0,
77             client.right, client.bottom-stat.bottom, TRUE);
78 }
79
80 void UpdateTypeLibStatusBar(int itemID)
81 {
82     WCHAR info[MAX_LOAD_STRING];
83
84     if(!LoadString(globals.hMainInst, itemID, info, sizeof(WCHAR[MAX_LOAD_STRING])))
85         LoadString(globals.hMainInst, IDS_READY, info, sizeof(WCHAR[MAX_LOAD_STRING]));
86
87     SendMessage(typelib.hStatusBar, SB_SETTEXT, 0, (LPARAM)info);
88 }
89
90 LRESULT CALLBACK TypeLibProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
91 {
92     switch(uMsg)
93     {
94         case WM_CREATE:
95         {
96             if(!CreatePanedWindow(hWnd, &typelib.hPaneWnd, globals.hMainInst))
97                 DestroyWindow(hWnd);
98             typelib.hTree = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, NULL,
99                     WS_CHILD|WS_VISIBLE|TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT,
100                     0, 0, 0, 0, typelib.hPaneWnd, NULL, globals.hMainInst, NULL);
101             typelib.hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, NULL,
102                     WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_READONLY|WS_HSCROLL|WS_VSCROLL,
103                     0, 0, 0, 0, typelib.hPaneWnd, NULL, globals.hMainInst, NULL);
104
105             SetLeft(typelib.hPaneWnd, typelib.hTree);
106             SetRight(typelib.hPaneWnd, typelib.hEdit);
107
108             PopulateTree();
109             SetFocus(typelib.hTree);
110             break;
111         }
112         case WM_MENUSELECT:
113             UpdateTypeLibStatusBar(LOWORD(wParam));
114             break;
115         case WM_SETFOCUS:
116             SetFocus(typelib.hTree);
117             break;
118         case WM_SIZE:
119             if(wParam == SIZE_MINIMIZED) break;
120             TypeLibResizeChild();
121             break;
122         case WM_DESTROY:
123             break;
124         default:
125             return DefWindowProc(hWnd, uMsg, wParam, lParam);
126     }
127     return 0;
128 }
129
130 BOOL TypeLibRegisterClass(void)
131 {
132     WNDCLASS wcc;
133
134     memset(&wcc, 0, sizeof(WNDCLASS));
135     wcc.lpfnWndProc = TypeLibProc;
136     wcc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
137     wcc.lpszMenuName = MAKEINTRESOURCE(IDM_TYPELIB);
138     wcc.lpszClassName = wszTypeLib;
139
140     if(!RegisterClass(&wcc))
141         return FALSE;
142
143     return TRUE;
144 }
145
146 BOOL CreateTypeLibWindow(HINSTANCE hInst)
147 {
148     WCHAR wszTitle[MAX_LOAD_STRING];
149     LoadString(hInst, IDS_TYPELIBTITLE, wszTitle, sizeof(WCHAR[MAX_LOAD_STRING]));
150
151     globals.hTypeLibWnd = CreateWindow(wszTypeLib, wszTitle,
152             WS_OVERLAPPEDWINDOW|WS_VISIBLE,
153             CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInst, NULL);
154     if(!globals.hTypeLibWnd) return FALSE;
155
156     typelib.hStatusBar = CreateStatusWindow(WS_VISIBLE|WS_CHILD,
157             (LPWSTR)wszTitle, globals.hTypeLibWnd, 0);
158
159     TypeLibResizeChild();
160     return TRUE;
161 }