mshtml: Removed no longer used attr_name from event_info_t.
[wine.git] / programs / oleview / details.c
blobfda9b7ce12fd74a88f00b717e3ba879d050a482a
1 /*
2 * OleView (details.c)
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
21 #include "main.h"
23 DETAILS details;
24 static const WCHAR wszAppID[] = { 'A','p','p','I','D','\0' };
25 static const WCHAR wszCLSID[] = { 'C','L','S','I','D','\0' };
26 static const WCHAR wszProgID[] = { 'P','r','o','g','I','D','\0' };
27 static const WCHAR wszProxyStubClsid32[] =
28 { 'P','r','o','x','y','S','t','u','b','C','l','s','i','d','3','2','\0' };
29 static const WCHAR wszTypeLib[] = { 'T','y','p','e','L','i','b','\0' };
31 static void CreateRegRec(HKEY hKey, HTREEITEM parent, WCHAR *wszKeyName, BOOL addings)
33 int i=0, j, retEnum;
34 HKEY hCurKey;
35 DWORD lenName, lenData, valType;
36 WCHAR wszName[MAX_LOAD_STRING];
37 WCHAR wszData[MAX_LOAD_STRING];
38 WCHAR wszTree[MAX_LOAD_STRING];
39 const WCHAR wszBinary[] = { '%','0','2','X',' ','\0' };
40 const WCHAR wszDots[] = { '.','.','.','\0' };
41 const WCHAR wszFormat1[] = { '%','s',' ','[','%','s',']',' ','=',' ','%','s','\0' };
42 const WCHAR wszFormat2[] = { '%','s',' ','=',' ','%','s','\0' };
43 TVINSERTSTRUCTW tvis;
44 HTREEITEM addPlace = parent;
46 U(tvis).item.mask = TVIF_TEXT;
47 U(tvis).item.cchTextMax = MAX_LOAD_STRING;
48 U(tvis).item.pszText = wszTree;
49 tvis.hInsertAfter = TVI_LAST;
50 tvis.hParent = parent;
52 while(TRUE)
54 lenName = sizeof(wszName)/sizeof(WCHAR);
55 lenData = sizeof(wszData);
57 retEnum = RegEnumValueW(hKey, i, wszName, &lenName,
58 NULL, &valType, (LPBYTE)wszData, &lenData);
60 if(retEnum != ERROR_SUCCESS)
62 if(!i && lstrlenW(wszKeyName) > 1)
64 U(tvis).item.pszText = wszKeyName;
65 addPlace = TreeView_InsertItemW(details.hReg, &tvis);
66 U(tvis).item.pszText = wszTree;
68 break;
71 if(valType == REG_BINARY)
73 WCHAR wszBuf[MAX_LOAD_STRING];
75 for(j=0; j<MAX_LOAD_STRING/3-1; j++)
76 wsprintfW(&wszBuf[3*j], wszBinary, (int)((unsigned char)wszData[j]));
77 wszBuf[(lenData*3>=MAX_LOAD_STRING ? MAX_LOAD_STRING-1 : lenData*3)] = '\0';
78 lstrcpyW(wszData, wszBuf);
79 lstrcpyW(&wszData[MAX_LOAD_STRING-5], wszDots);
82 if(lenName) wsprintfW(wszTree, wszFormat1, wszKeyName, wszName, wszData);
83 else wsprintfW(wszTree, wszFormat2, wszKeyName, wszData);
85 addPlace = TreeView_InsertItemW(details.hReg, &tvis);
87 if(addings && !memcmp(wszName, wszAppID, sizeof(WCHAR[6])))
89 lstrcpyW(wszTree, wszName);
90 memmove(&wszData[6], wszData, sizeof(WCHAR[MAX_LOAD_STRING-6]));
91 lstrcpyW(wszData, wszCLSID);
92 wszData[5] = '\\';
94 if(RegOpenKeyW(HKEY_CLASSES_ROOT, wszData, &hCurKey) != ERROR_SUCCESS)
96 i++;
97 continue;
100 tvis.hParent = TVI_ROOT;
101 tvis.hParent = TreeView_InsertItemW(details.hReg, &tvis);
103 lenName = sizeof(wszName);
104 RegQueryValueW(hCurKey, NULL, wszName, (LONG *)&lenName);
105 RegCloseKey(hCurKey);
107 wsprintfW(wszTree, wszFormat2, &wszData[6], wszName);
109 SendMessageW(details.hReg, TVM_INSERTITEMW, 0, (LPARAM)&tvis);
110 SendMessageW(details.hReg, TVM_EXPAND, TVE_EXPAND, (LPARAM)tvis.hParent);
112 tvis.hParent = parent;
114 i++;
117 i=-1;
119 while(TRUE)
121 i++;
123 if(RegEnumKeyW(hKey, i, wszName, sizeof(wszName)/sizeof(WCHAR)) != ERROR_SUCCESS) break;
125 if(RegOpenKeyW(hKey, wszName, &hCurKey) != ERROR_SUCCESS) continue;
127 CreateRegRec(hCurKey, addPlace, wszName, addings);
128 SendMessageW(details.hReg, TVM_EXPAND, TVE_EXPAND, (LPARAM)addPlace);
130 if(addings && !memcmp(wszName, wszProgID, sizeof(WCHAR[7])))
132 lenData = sizeof(wszData);
133 RegQueryValueW(hCurKey, NULL, wszData, (LONG *)&lenData);
134 RegCloseKey(hCurKey);
136 if(RegOpenKeyW(HKEY_CLASSES_ROOT, wszData, &hCurKey) != ERROR_SUCCESS)
137 continue;
138 CreateRegRec(hCurKey, TVI_ROOT, wszData, FALSE);
140 else if(addings && !memcmp(wszName, wszProxyStubClsid32, sizeof(WCHAR[17])))
142 lenData = sizeof(wszData);
144 RegQueryValueW(hCurKey, NULL, wszData, (LONG *)&lenData);
145 RegCloseKey(hCurKey);
147 RegOpenKeyW(HKEY_CLASSES_ROOT, wszCLSID, &hCurKey);
149 lenName = sizeof(wszName);
150 RegQueryValueW(hCurKey, NULL, wszName, (LONG *)&lenName);
152 tvis.hParent = TVI_ROOT;
153 wsprintfW(wszTree, wszFormat2, wszCLSID, wszName);
154 tvis.hParent = TreeView_InsertItemW(details.hReg, &tvis);
156 RegCloseKey(hCurKey);
158 memmove(&wszData[6], wszData, lenData);
159 memcpy(wszData, wszCLSID, sizeof(WCHAR[6]));
160 wszData[5] = '\\';
162 RegOpenKeyW(HKEY_CLASSES_ROOT, wszData, &hCurKey);
164 CreateRegRec(hCurKey, tvis.hParent, &wszData[6], FALSE);
166 SendMessageW(details.hReg, TVM_EXPAND, TVE_EXPAND, (LPARAM)tvis.hParent);
167 tvis.hParent = parent;
169 else if(addings && !memcmp(wszName, wszTypeLib, sizeof(WCHAR[8])))
171 lenData = sizeof(wszData);
172 RegQueryValueW(hCurKey, NULL, wszData, (LONG *)&lenData);
173 RegCloseKey(hCurKey);
175 RegOpenKeyW(HKEY_CLASSES_ROOT, wszTypeLib, &hCurKey);
177 lenName = sizeof(wszName);
178 RegQueryValueW(hCurKey, NULL, wszName, (LONG *)&lenName);
180 tvis.hParent = TVI_ROOT;
181 wsprintfW(wszTree, wszFormat2, wszTypeLib, wszName);
182 tvis.hParent = TreeView_InsertItemW(details.hReg, &tvis);
184 RegCloseKey(hCurKey);
186 memmove(&wszData[8], wszData, lenData);
187 memcpy(wszData, wszTypeLib, sizeof(WCHAR[8]));
188 wszData[7] = '\\';
189 RegOpenKeyW(HKEY_CLASSES_ROOT, wszData, &hCurKey);
191 CreateRegRec(hCurKey, tvis.hParent, &wszData[8], FALSE);
193 SendMessageW(details.hReg, TVM_EXPAND, TVE_EXPAND, (LPARAM)tvis.hParent);
194 tvis.hParent = parent;
196 RegCloseKey(hCurKey);
200 static void CreateReg(WCHAR *buffer)
202 HKEY hKey;
203 DWORD lenBuffer=-1, lastLenBuffer, lenTree;
204 WCHAR *path;
205 WCHAR wszTree[MAX_LOAD_STRING];
206 TVINSERTSTRUCTW tvis;
207 HTREEITEM addPlace = TVI_ROOT;
209 U(tvis).item.mask = TVIF_TEXT;
210 U(tvis).item.cchTextMax = MAX_LOAD_STRING;
211 U(tvis).item.pszText = wszTree;
212 tvis.hInsertAfter = TVI_LAST;
213 tvis.hParent = TVI_ROOT;
215 path = buffer;
216 while(TRUE)
218 while(*path != '\\' && *path != '\0') path += 1;
220 if(*path == '\\')
222 *path = '\0';
224 if(RegOpenKeyW(HKEY_CLASSES_ROOT, buffer, &hKey) != ERROR_SUCCESS)
225 return;
227 lastLenBuffer = lenBuffer+1;
228 lenBuffer = lstrlenW(buffer);
229 *path = '\\';
230 path += 1;
232 lenTree = sizeof(wszTree);
234 if(RegQueryValueW(hKey, NULL, wszTree, (LONG *)&lenTree) == ERROR_SUCCESS)
236 memmove(&wszTree[lenBuffer-lastLenBuffer+3], wszTree, lenTree);
237 memcpy(wszTree, &buffer[lastLenBuffer],
238 (lenBuffer - lastLenBuffer) * sizeof(WCHAR));
240 if(lenTree == 1) wszTree[lenBuffer-lastLenBuffer] = '\0';
241 else
243 wszTree[lenBuffer-lastLenBuffer] = ' ';
244 wszTree[lenBuffer-lastLenBuffer+1] = '=';
245 wszTree[lenBuffer-lastLenBuffer+2] = ' ';
248 addPlace = TreeView_InsertItemW(details.hReg, &tvis);
251 tvis.hParent = addPlace;
252 RegCloseKey(hKey);
254 else break;
257 if(RegOpenKeyW(HKEY_CLASSES_ROOT, buffer, &hKey) != ERROR_SUCCESS) return;
259 CreateRegRec(hKey, addPlace, &buffer[lenBuffer+1], TRUE);
261 RegCloseKey(hKey);
263 SendMessageW(details.hReg, TVM_EXPAND, TVE_EXPAND, (LPARAM)addPlace);
264 SendMessageW(details.hReg, TVM_ENSUREVISIBLE, 0, (LPARAM)addPlace);
267 void RefreshDetails(HTREEITEM item)
269 TVITEMW tvi;
270 WCHAR wszBuf[MAX_LOAD_STRING];
271 WCHAR wszStaticText[MAX_LOAD_STRING];
272 const WCHAR wszFormat[] = { '%','s','\n','%','s','\0' };
273 BOOL show;
275 memset(&tvi, 0, sizeof(TVITEMW));
276 memset(&wszStaticText, 0, sizeof(WCHAR[MAX_LOAD_STRING]));
277 tvi.mask = TVIF_TEXT;
278 tvi.hItem = item;
279 tvi.pszText = wszBuf;
280 tvi.cchTextMax = MAX_LOAD_STRING;
281 SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
283 if(tvi.lParam)
284 wsprintfW(wszStaticText, wszFormat, tvi.pszText, ((ITEM_INFO *)tvi.lParam)->clsid);
285 else lstrcpyW(wszStaticText, tvi.pszText);
287 SetWindowTextW(details.hStatic, wszStaticText);
289 SendMessageW(details.hTab, TCM_SETCURSEL, 0, 0);
291 if(tvi.lParam && ((ITEM_INFO *)tvi.lParam)->cFlag & SHOWALL)
293 if(SendMessageW(details.hTab, TCM_GETITEMCOUNT, 0, 0) == 1)
295 TCITEMW tci;
296 memset(&tci, 0, sizeof(TCITEMW));
297 tci.mask = TCIF_TEXT;
298 tci.pszText = wszBuf;
299 tci.cchTextMax = sizeof(wszBuf)/sizeof(wszBuf[0]);
301 LoadStringW(globals.hMainInst, IDS_TAB_IMPL,
302 wszBuf, sizeof(wszBuf)/sizeof(wszBuf[0]));
303 SendMessageW(details.hTab, TCM_INSERTITEMW, 1, (LPARAM)&tci);
305 LoadStringW(globals.hMainInst, IDS_TAB_ACTIV,
306 wszBuf, sizeof(wszBuf)/sizeof(wszBuf[0]));
307 SendMessageW(details.hTab, TCM_INSERTITEMW, 2, (LPARAM)&tci);
310 else
312 SendMessageW(details.hTab, TCM_DELETEITEM, 2, 0);
313 SendMessageW(details.hTab, TCM_DELETEITEM, 1, 0);
316 show = CreateRegPath(item, wszBuf, MAX_LOAD_STRING);
317 ShowWindow(details.hTab, show ? SW_SHOW : SW_HIDE);
319 /* FIXME Next line deals with TreeView_EnsureVisible bug */
320 SendMessageW(details.hReg, TVM_ENSUREVISIBLE, 0,
321 SendMessageW(details.hReg, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)TVI_ROOT));
322 SendMessageW(details.hReg, TVM_DELETEITEM, 0, (LPARAM)TVI_ROOT);
323 if(show) CreateReg(wszBuf);
326 static void CreateTabCtrl(HWND hWnd)
328 TCITEMW tci;
329 WCHAR buffer[MAX_LOAD_STRING];
331 memset(&tci, 0, sizeof(TCITEMW));
332 tci.mask = TCIF_TEXT;
333 tci.pszText = buffer;
334 tci.cchTextMax = sizeof(buffer)/sizeof(buffer[0]);
336 details.hTab = CreateWindowW(WC_TABCONTROLW, NULL, WS_CHILD|WS_VISIBLE,
337 0, 0, 0, 0, hWnd, (HMENU)TAB_WINDOW, globals.hMainInst, NULL);
338 ShowWindow(details.hTab, SW_HIDE);
340 LoadStringW(globals.hMainInst, IDS_TAB_REG, buffer, sizeof(buffer)/sizeof(buffer[0]));
341 SendMessageW(details.hTab, TCM_INSERTITEMW, 0, (LPARAM)&tci);
343 details.hReg = CreateWindowExW(WS_EX_CLIENTEDGE, WC_TREEVIEWW, NULL,
344 WS_CHILD|WS_VISIBLE|TVS_HASLINES,
345 0, 0, 0, 0, details.hTab, NULL, globals.hMainInst, NULL);
348 static LRESULT CALLBACK DetailsProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
350 int sel;
352 switch(uMsg)
354 case WM_CREATE:
356 const WCHAR wszStatic[] = { 'S','t','a','t','i','c','\0' };
358 details.hStatic = CreateWindowW(wszStatic, NULL, WS_CHILD|WS_VISIBLE,
359 0, 0, 0, 0, hWnd, NULL, globals.hMainInst, NULL);
360 CreateTabCtrl(hWnd);
362 break;
363 case WM_SIZE:
364 MoveWindow(details.hStatic, 0, 0, LOWORD(lParam), 40, TRUE);
365 MoveWindow(details.hTab, 3, 40, LOWORD(lParam)-6, HIWORD(lParam)-43, TRUE);
366 MoveWindow(details.hReg, 10, 34, LOWORD(lParam)-26,
367 HIWORD(lParam)-87, TRUE);
368 break;
369 case WM_NOTIFY:
370 if((int)wParam != TAB_WINDOW) break;
371 switch(((LPNMHDR)lParam)->code)
373 case TCN_SELCHANGE:
374 ShowWindow(details.hReg, SW_HIDE);
375 sel = SendMessageW(details.hTab, TCM_GETCURSEL, 0, 0);
377 if(sel==0) ShowWindow(details.hReg, SW_SHOW);
378 break;
380 break;
381 default:
382 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
384 return 0;
387 HWND CreateDetailsWindow(HINSTANCE hInst)
389 WNDCLASSW wcd;
390 const WCHAR wszDetailsClass[] = { 'D','E','T','A','I','L','S','\0' };
392 memset(&wcd, 0, sizeof(WNDCLASSW));
393 wcd.lpfnWndProc = DetailsProc;
394 wcd.lpszClassName = wszDetailsClass;
395 wcd.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
396 wcd.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
398 if(!RegisterClassW(&wcd)) return NULL;
400 globals.hDetails = CreateWindowExW(WS_EX_CLIENTEDGE, wszDetailsClass, NULL,
401 WS_CHILD|WS_VISIBLE, 0, 0, 0, 0, globals.hPaneWnd, NULL, hInst, NULL);
403 return globals.hDetails;