ieframe: Moved dialog resources to ieframe.
[wine/testsucceed.git] / programs / oleview / interface.c
blobfbbd478b16e47affd382927a4766cc44ba7cf35c
1 /*
2 * OleView (interface.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 typedef struct
25 WCHAR *wszLabel;
26 WCHAR *wszIdentifier;
27 }DIALOG_INFO;
29 BOOL IsInterface(HTREEITEM item)
31 TVITEMW tvi;
33 memset(&tvi, 0, sizeof(TVITEMW));
34 tvi.hItem = item;
36 SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
37 if(!tvi.lParam) return FALSE;
39 if(((ITEM_INFO*)tvi.lParam)->cFlag & INTERFACE) return TRUE;
40 return FALSE;
43 static IUnknown *GetInterface(void)
45 HTREEITEM hSelect;
46 TVITEMW tvi;
47 CLSID clsid;
48 IUnknown *unk;
50 hSelect = (HTREEITEM)SendMessageW(globals.hTree, TVM_GETNEXTITEM,
51 TVGN_CARET, 0);
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);
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);
63 IUnknown_QueryInterface(((ITEM_INFO *)tvi.lParam)->pU, &clsid, (void *)&unk);
65 return unk;
68 static INT_PTR CALLBACK InterfaceViewerProc(HWND hDlgWnd, UINT uMsg,
69 WPARAM wParam, LPARAM lParam)
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' };
80 switch(uMsg)
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;
118 return FALSE;
121 static void IPersistStreamInterfaceViewer(WCHAR *clsid, WCHAR *wszName)
123 DIALOG_INFO di;
124 WCHAR wszClassMoniker[] = { 'C','l','a','s','s','M','o','n','i','k','e','r','\0' };
126 if(wszName[0] == '{')
127 di.wszLabel = wszClassMoniker;
128 else di.wszLabel = wszName;
129 di.wszIdentifier = clsid;
131 DialogBoxParamW(0, MAKEINTRESOURCEW(DLG_IPERSISTSTREAM_IV),
132 globals.hMainWnd, InterfaceViewerProc, (LPARAM)&di);
135 static void IPersistInterfaceViewer(WCHAR *clsid, WCHAR *wszName)
137 DIALOG_INFO di;
138 WCHAR wszClassMoniker[] = { 'C','l','a','s','s','M','o','n','i','k','e','r','\0' };
140 if(wszName[0] == '{')
141 di.wszLabel = wszClassMoniker;
142 else di.wszLabel = wszName;
143 di.wszIdentifier = clsid;
145 DialogBoxParamW(0, MAKEINTRESOURCEW(DLG_IPERSIST_IV),
146 globals.hMainWnd, InterfaceViewerProc, (LPARAM)&di);
149 static void DefaultInterfaceViewer(WCHAR *clsid, WCHAR *wszName)
151 DIALOG_INFO di;
153 di.wszLabel = wszName;
154 di.wszIdentifier = clsid;
156 DialogBoxParamW(0, MAKEINTRESOURCEW(DLG_DEFAULT_IV),
157 globals.hMainWnd, InterfaceViewerProc, (LPARAM)&di);
160 void InterfaceViewer(HTREEITEM item)
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' };
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;
179 SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
180 clsid = ((ITEM_INFO*)tvi.lParam)->clsid;
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;
189 SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
191 if(!memcmp(clsid, wszIPersistStream, sizeof(wszIPersistStream)))
192 IPersistStreamInterfaceViewer(clsid, wszParent);
194 else if(!memcmp(clsid, wszIPersist, sizeof(wszIPersist)))
195 IPersistInterfaceViewer(clsid, wszParent);
197 else DefaultInterfaceViewer(clsid, wszName);