mfplat: Fix asynchronous object creation from URL.
[wine/zf.git] / programs / oleview / interface.c
blob88007d127e95aac90f694f6fcef1e57d63454b81
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, ARRAY_SIZE(wszBuf));
100 else
101 LoadStringW(globals.hMainInst, IDS_TRUE, wszBuf, ARRAY_SIZE(wszBuf));
102 hObject = GetDlgItem(hDlgWnd, IDC_ISDIRTY);
103 SetWindowTextW(hObject, wszBuf);
104 return TRUE;
105 case IDC_GETSIZEMAX_BUTTON:
106 unk = GetInterface();
107 IPersistStream_GetSizeMax((IPersistStream *)unk, &size);
108 IUnknown_Release(unk);
109 LoadStringW(globals.hMainInst, IDS_BYTES, wszBuf, ARRAY_SIZE(wszBuf));
110 wsprintfW(wszSize, wszFormat, U(size).LowPart, wszBuf);
111 hObject = GetDlgItem(hDlgWnd, IDC_GETSIZEMAX);
112 SetWindowTextW(hObject, wszSize);
113 return TRUE;
116 return FALSE;
119 static void IPersistStreamInterfaceViewer(WCHAR *clsid, WCHAR *wszName)
121 DIALOG_INFO di;
122 WCHAR wszClassMoniker[] = { 'C','l','a','s','s','M','o','n','i','k','e','r','\0' };
124 if(wszName[0] == '{')
125 di.wszLabel = wszClassMoniker;
126 else di.wszLabel = wszName;
127 di.wszIdentifier = clsid;
129 DialogBoxParamW(0, MAKEINTRESOURCEW(DLG_IPERSISTSTREAM_IV),
130 globals.hMainWnd, InterfaceViewerProc, (LPARAM)&di);
133 static void IPersistInterfaceViewer(WCHAR *clsid, WCHAR *wszName)
135 DIALOG_INFO di;
136 WCHAR wszClassMoniker[] = { 'C','l','a','s','s','M','o','n','i','k','e','r','\0' };
138 if(wszName[0] == '{')
139 di.wszLabel = wszClassMoniker;
140 else di.wszLabel = wszName;
141 di.wszIdentifier = clsid;
143 DialogBoxParamW(0, MAKEINTRESOURCEW(DLG_IPERSIST_IV),
144 globals.hMainWnd, InterfaceViewerProc, (LPARAM)&di);
147 static void DefaultInterfaceViewer(WCHAR *clsid, WCHAR *wszName)
149 DIALOG_INFO di;
151 di.wszLabel = wszName;
152 di.wszIdentifier = clsid;
154 DialogBoxParamW(0, MAKEINTRESOURCEW(DLG_DEFAULT_IV),
155 globals.hMainWnd, InterfaceViewerProc, (LPARAM)&di);
158 void InterfaceViewer(HTREEITEM item)
160 TVITEMW 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' };
171 memset(&tvi, 0, sizeof(TVITEMW));
172 tvi.mask = TVIF_TEXT;
173 tvi.hItem = item;
174 tvi.cchTextMax = MAX_LOAD_STRING;
175 tvi.pszText = wszName;
177 SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
178 clsid = ((ITEM_INFO*)tvi.lParam)->clsid;
180 memset(&tvi, 0, sizeof(TVITEMW));
181 tvi.mask = TVIF_TEXT;
182 tvi.hItem = (HTREEITEM)SendMessageW(globals.hTree, TVM_GETNEXTITEM,
183 TVGN_PARENT, (LPARAM)item);
184 tvi.cchTextMax = MAX_LOAD_STRING;
185 tvi.pszText = wszParent;
187 SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
189 if(!memcmp(clsid, wszIPersistStream, sizeof(wszIPersistStream)))
190 IPersistStreamInterfaceViewer(clsid, wszParent);
192 else if(!memcmp(clsid, wszIPersist, sizeof(wszIPersist)))
193 IPersistInterfaceViewer(clsid, wszParent);
195 else DefaultInterfaceViewer(clsid, wszName);