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