interface.c 6.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/*
 * OleView (interface.c)
 *
 * Copyright 2006 Piotr Caban
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "main.h"

typedef struct
{
    WCHAR *wszLabel;
    WCHAR *wszIdentifier;
}DIALOG_INFO;

BOOL IsInterface(HTREEITEM item)
{
31
    TVITEMW tvi;
32

33
    memset(&tvi, 0, sizeof(TVITEMW));
34 35
    tvi.hItem = item;

36
    SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
37 38 39 40 41 42
    if(!tvi.lParam) return FALSE;

    if(((ITEM_INFO*)tvi.lParam)->cFlag & INTERFACE) return TRUE;
    return FALSE;
}

43
static IUnknown *GetInterface(void)
44 45
{
    HTREEITEM hSelect;
46
    TVITEMW tvi;
47 48 49
    CLSID clsid;
    IUnknown *unk;

50 51
    hSelect = (HTREEITEM)SendMessageW(globals.hTree, TVM_GETNEXTITEM,
            TVGN_CARET, 0);
52

53
    memset(&tvi, 0, sizeof(TVITEMW));
54
    tvi.hItem = hSelect;
55
    SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
56 57
    CLSIDFromString(((ITEM_INFO *)tvi.lParam)->clsid, &clsid);

58
    memset(&tvi, 0, sizeof(TVITEMW));
59 60
    tvi.hItem = (HTREEITEM)SendMessageW(globals.hTree, TVM_GETNEXTITEM,
            TVGN_PARENT, (LPARAM)hSelect);
61
    SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
62 63 64 65 66 67

    IUnknown_QueryInterface(((ITEM_INFO *)tvi.lParam)->pU, &clsid, (void *)&unk);

    return unk;
}

68
static INT_PTR CALLBACK InterfaceViewerProc(HWND hDlgWnd, UINT uMsg,
69 70 71 72 73 74 75 76
        WPARAM wParam, LPARAM lParam)
{
    DIALOG_INFO *di;
    HWND hObject;
    IUnknown *unk;
    HRESULT hRes;
    ULARGE_INTEGER size;
    WCHAR wszSize[MAX_LOAD_STRING];
77 78
    WCHAR wszBuf[MAX_LOAD_STRING];
    WCHAR wszFormat[] = { '%','d',' ','%','s','\0' };
79 80 81 82 83 84

    switch(uMsg)
    {
        case WM_INITDIALOG:
            di = (DIALOG_INFO *)lParam;
            hObject = GetDlgItem(hDlgWnd, IDC_LABEL);
85
            SetWindowTextW(hObject, di->wszLabel);
86
            hObject = GetDlgItem(hDlgWnd, IDC_IDENTIFIER);
87
            SetWindowTextW(hObject, di->wszIdentifier);
88 89 90 91 92 93 94 95 96 97
            return TRUE;
        case WM_COMMAND:
            switch(LOWORD(wParam)) {
            case IDCANCEL:
                EndDialog(hDlgWnd, IDCANCEL);
                return TRUE;
            case IDC_ISDIRTY_BUTTON:
                unk = GetInterface();
                hRes = IPersistStream_IsDirty((IPersistStream *)unk);
                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 106 107 108 109
                return TRUE;
            case IDC_GETSIZEMAX_BUTTON:
                unk = GetInterface();
                IPersistStream_GetSizeMax((IPersistStream *)unk, &size);
                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 116 117 118 119 120
                return TRUE;
            }
    }
    return FALSE;
}

121
static void IPersistStreamInterfaceViewer(WCHAR *clsid, WCHAR *wszName)
122 123 124 125
{
    DIALOG_INFO di;
    WCHAR wszClassMoniker[] = { 'C','l','a','s','s','M','o','n','i','k','e','r','\0' };

126 127 128
    if(wszName[0] == '{')
        di.wszLabel = wszClassMoniker;
    else di.wszLabel = wszName;
129 130
    di.wszIdentifier = clsid;

131
    DialogBoxParamW(0, MAKEINTRESOURCEW(DLG_IPERSISTSTREAM_IV),
132 133 134
            globals.hMainWnd, InterfaceViewerProc, (LPARAM)&di);
}

135
static void IPersistInterfaceViewer(WCHAR *clsid, WCHAR *wszName)
136 137 138 139
{
    DIALOG_INFO di;
    WCHAR wszClassMoniker[] = { 'C','l','a','s','s','M','o','n','i','k','e','r','\0' };

140 141 142
    if(wszName[0] == '{')
        di.wszLabel = wszClassMoniker;
    else di.wszLabel = wszName;
143 144
    di.wszIdentifier = clsid;

145
    DialogBoxParamW(0, MAKEINTRESOURCEW(DLG_IPERSIST_IV),
146 147 148
            globals.hMainWnd, InterfaceViewerProc, (LPARAM)&di);
}

149
static void DefaultInterfaceViewer(WCHAR *clsid, WCHAR *wszName)
150 151 152 153 154 155
{
    DIALOG_INFO di;

    di.wszLabel = wszName;
    di.wszIdentifier = clsid;

156
    DialogBoxParamW(0, MAKEINTRESOURCEW(DLG_DEFAULT_IV),
157 158 159 160 161
            globals.hMainWnd, InterfaceViewerProc, (LPARAM)&di);
}

void InterfaceViewer(HTREEITEM item)
{
162
    TVITEMW tvi;
163 164
    WCHAR *clsid;
    WCHAR wszName[MAX_LOAD_STRING];
165
    WCHAR wszParent[MAX_LOAD_STRING];
166 167 168 169 170 171 172
    WCHAR wszIPersistStream[] = { '{','0','0','0','0','0','1','0','9','-',
        '0','0','0','0','-','0','0','0','0','-','C','0','0','0','-',
        '0','0','0','0','0','0','0','0','0','0','4','6','}','\0' };
    WCHAR wszIPersist[] = { '{','0','0','0','0','0','1','0','C','-',
        '0','0','0','0','-','0','0','0','0','-','C','0','0','0','-',
        '0','0','0','0','0','0','0','0','0','0','4','6','}','\0' };

173
    memset(&tvi, 0, sizeof(TVITEMW));
174 175 176 177 178
    tvi.mask = TVIF_TEXT;
    tvi.hItem = item;
    tvi.cchTextMax = MAX_LOAD_STRING;
    tvi.pszText = wszName;

179
    SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
180 181
    clsid = ((ITEM_INFO*)tvi.lParam)->clsid;

182
    memset(&tvi, 0, sizeof(TVITEMW));
183
    tvi.mask = TVIF_TEXT;
184 185
    tvi.hItem = (HTREEITEM)SendMessageW(globals.hTree, TVM_GETNEXTITEM,
            TVGN_PARENT, (LPARAM)item);
186 187 188
    tvi.cchTextMax = MAX_LOAD_STRING;
    tvi.pszText = wszParent;

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 198

    else DefaultInterfaceViewer(clsid, wszName);
}