quartz: Don't cast WSTR to BSTR, convert properly instead.
[wine/testsucceed.git] / programs / oleview / interface.c
blob5262187b946a62e1c515157e59909a03330871f9
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 TVITEM tvi;
33 memset(&tvi, 0, sizeof(TVITEM));
34 tvi.hItem = item;
36 SendMessage(globals.hTree, TVM_GETITEM, 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 TVITEM tvi;
47 CLSID clsid;
48 IUnknown *unk;
50 hSelect = TreeView_GetSelection(globals.hTree);
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);
57 memset(&tvi, 0, sizeof(TVITEM));
58 tvi.hItem = TreeView_GetParent(globals.hTree, hSelect);
59 SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
61 IUnknown_QueryInterface(((ITEM_INFO *)tvi.lParam)->pU, &clsid, (void *)&unk);
63 return unk;
66 static INT_PTR CALLBACK InterfaceViewerProc(HWND hDlgWnd, UINT uMsg,
67 WPARAM wParam, LPARAM lParam)
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' };
78 switch(uMsg)
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(wszBuf)/sizeof(wszBuf[0]));
99 else LoadString(globals.hMainInst, IDS_TRUE, wszBuf,
100 sizeof(wszBuf)/sizeof(wszBuf[0]));
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(wszBuf)/sizeof(wszBuf[0]));
110 wsprintfW(wszSize, wszFormat, U(size).LowPart, wszBuf);
111 hObject = GetDlgItem(hDlgWnd, IDC_GETSIZEMAX);
112 SetWindowText(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 DialogBoxParam(0, MAKEINTRESOURCE(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 DialogBoxParam(0, MAKEINTRESOURCE(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 DialogBoxParam(0, MAKEINTRESOURCE(DLG_DEFAULT_IV),
155 globals.hMainWnd, InterfaceViewerProc, (LPARAM)&di);
158 void InterfaceViewer(HTREEITEM item)
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' };
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;
177 SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
178 clsid = ((ITEM_INFO*)tvi.lParam)->clsid;
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;
186 SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi);
188 if(!memcmp(clsid, wszIPersistStream, sizeof(wszIPersistStream)))
189 IPersistStreamInterfaceViewer(clsid, wszParent);
191 else if(!memcmp(clsid, wszIPersist, sizeof(wszIPersist)))
192 IPersistInterfaceViewer(clsid, wszParent);
194 else DefaultInterfaceViewer(clsid, wszName);