regedit: Modify getRegClass() to avoid dubious comparisons and casts between HKEYs...
[wine] / programs / oleview / interface.c
1 /*
2  * OleView (interface.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 typedef struct
24 {
25     WCHAR *wszLabel;
26     WCHAR *wszIdentifier;
27 }DIALOG_INFO;
28
29 BOOL IsInterface(HTREEITEM item)
30 {
31     TVITEM tvi;
32
33     memset(&tvi, 0, sizeof(TVITEM));
34     tvi.hItem = item;
35
36     SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
37     if(!tvi.lParam) return FALSE;
38
39     if(((ITEM_INFO*)tvi.lParam)->cFlag & INTERFACE) return TRUE;
40     return FALSE;
41 }
42
43 static IUnknown *GetInterface(void)
44 {
45     HTREEITEM hSelect;
46     TVITEM tvi;
47     CLSID clsid;
48     IUnknown *unk;
49
50     hSelect = TreeView_GetSelection(globals.hTree);
51
52     memset(&tvi, 0, sizeof(TVITEM));
53     tvi.hItem = hSelect;
54     SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
55     CLSIDFromString(((ITEM_INFO *)tvi.lParam)->clsid, &clsid);
56
57     memset(&tvi, 0, sizeof(TVITEM));
58     tvi.hItem = TreeView_GetParent(globals.hTree, hSelect);
59     SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
60
61     IUnknown_QueryInterface(((ITEM_INFO *)tvi.lParam)->pU, &clsid, (void *)&unk);
62
63     return unk;
64 }
65
66 INT_PTR CALLBACK InterfaceViewerProc(HWND hDlgWnd, UINT uMsg,
67         WPARAM wParam, LPARAM lParam)
68 {
69     DIALOG_INFO *di;
70     HWND hObject;
71     IUnknown *unk;
72     HRESULT hRes;
73     ULARGE_INTEGER size;
74     WCHAR wszSize[MAX_LOAD_STRING];
75     WCHAR wszBuf[MAX_LOAD_STRING];
76     WCHAR wszFormat[] = { '%','d',' ','%','s','\0' };
77
78     switch(uMsg)
79     {
80         case WM_INITDIALOG:
81             di = (DIALOG_INFO *)lParam;
82             hObject = GetDlgItem(hDlgWnd, IDC_LABEL);
83             SetWindowText(hObject, di->wszLabel);
84             hObject = GetDlgItem(hDlgWnd, IDC_IDENTIFIER);
85             SetWindowText(hObject, di->wszIdentifier);
86             return TRUE;
87         case WM_COMMAND:
88             switch(LOWORD(wParam)) {
89             case IDCANCEL:
90                 EndDialog(hDlgWnd, IDCANCEL);
91                 return TRUE;
92             case IDC_ISDIRTY_BUTTON:
93                 unk = GetInterface();
94                 hRes = IPersistStream_IsDirty((IPersistStream *)unk);
95                 IUnknown_Release(unk);
96                 if(hRes == S_OK)
97                     LoadString(globals.hMainInst, IDS_FALSE, wszBuf,
98                             sizeof(WCHAR[MAX_LOAD_STRING]));
99                 else LoadString(globals.hMainInst, IDS_TRUE, wszBuf,
100                         sizeof(WCHAR[MAX_LOAD_STRING]));
101                 hObject = GetDlgItem(hDlgWnd, IDC_ISDIRTY);
102                 SetWindowText(hObject, wszBuf);
103                 return TRUE;
104             case IDC_GETSIZEMAX_BUTTON:
105                 unk = GetInterface();
106                 IPersistStream_GetSizeMax((IPersistStream *)unk, &size);
107                 IUnknown_Release(unk);
108                 LoadString(globals.hMainInst, IDS_BYTES, wszBuf,
109                         sizeof(WCHAR[MAX_LOAD_STRING]));
110                 wsprintfW(wszSize, wszFormat, U(size).LowPart, wszBuf);
111                 hObject = GetDlgItem(hDlgWnd, IDC_GETSIZEMAX);
112                 SetWindowText(hObject, wszSize);
113                 return TRUE;
114             }
115     }
116     return FALSE;
117 }
118
119 static void IPersistStreamInterfaceViewer(WCHAR *clsid, WCHAR *wszName)
120 {
121     DIALOG_INFO di;
122     WCHAR wszClassMoniker[] = { 'C','l','a','s','s','M','o','n','i','k','e','r','\0' };
123
124     if(wszName[0] == '{')
125         di.wszLabel = wszClassMoniker;
126     else di.wszLabel = wszName;
127     di.wszIdentifier = clsid;
128
129     DialogBoxParam(0, MAKEINTRESOURCE(DLG_IPERSISTSTREAM_IV),
130             globals.hMainWnd, InterfaceViewerProc, (LPARAM)&di);
131 }
132
133 static void IPersistInterfaceViewer(WCHAR *clsid, WCHAR *wszName)
134 {
135     DIALOG_INFO di;
136     WCHAR wszClassMoniker[] = { 'C','l','a','s','s','M','o','n','i','k','e','r','\0' };
137
138     if(wszName[0] == '{')
139         di.wszLabel = wszClassMoniker;
140     else di.wszLabel = wszName;
141     di.wszIdentifier = clsid;
142
143     DialogBoxParam(0, MAKEINTRESOURCE(DLG_IPERSIST_IV),
144             globals.hMainWnd, InterfaceViewerProc, (LPARAM)&di);
145 }
146
147 static void DefaultInterfaceViewer(WCHAR *clsid, WCHAR *wszName)
148 {
149     DIALOG_INFO di;
150
151     di.wszLabel = wszName;
152     di.wszIdentifier = clsid;
153
154     DialogBoxParam(0, MAKEINTRESOURCE(DLG_DEFAULT_IV),
155             globals.hMainWnd, InterfaceViewerProc, (LPARAM)&di);
156 }
157
158 void InterfaceViewer(HTREEITEM item)
159 {
160     TVITEM tvi;
161     WCHAR *clsid;
162     WCHAR wszName[MAX_LOAD_STRING];
163     WCHAR wszParent[MAX_LOAD_STRING];
164     WCHAR wszIPersistStream[] = { '{','0','0','0','0','0','1','0','9','-',
165         '0','0','0','0','-','0','0','0','0','-','C','0','0','0','-',
166         '0','0','0','0','0','0','0','0','0','0','4','6','}','\0' };
167     WCHAR wszIPersist[] = { '{','0','0','0','0','0','1','0','C','-',
168         '0','0','0','0','-','0','0','0','0','-','C','0','0','0','-',
169         '0','0','0','0','0','0','0','0','0','0','4','6','}','\0' };
170
171     memset(&tvi, 0, sizeof(TVITEM));
172     tvi.mask = TVIF_TEXT;
173     tvi.hItem = item;
174     tvi.cchTextMax = MAX_LOAD_STRING;
175     tvi.pszText = wszName;
176
177     SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
178     clsid = ((ITEM_INFO*)tvi.lParam)->clsid;
179
180     memset(&tvi, 0, sizeof(TVITEM));
181     tvi.mask = TVIF_TEXT;
182     tvi.hItem = TreeView_GetParent(globals.hTree, item);
183     tvi.cchTextMax = MAX_LOAD_STRING;
184     tvi.pszText = wszParent;
185
186     SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
187
188     if(!memcmp(clsid, wszIPersistStream, sizeof(wszIPersistStream)))
189         IPersistStreamInterfaceViewer(clsid, wszParent);
190
191     else if(!memcmp(clsid, wszIPersist, sizeof(wszIPersist)))
192         IPersistInterfaceViewer(clsid, wszParent);
193
194     else DefaultInterfaceViewer(clsid, wszName);
195 }