interface.c 6.27 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 100 101
                    LoadStringW(globals.hMainInst, IDS_FALSE, wszBuf, ARRAY_SIZE(wszBuf));
                else
                    LoadStringW(globals.hMainInst, IDS_TRUE, wszBuf, ARRAY_SIZE(wszBuf));
102
                hObject = GetDlgItem(hDlgWnd, IDC_ISDIRTY);
103
                SetWindowTextW(hObject, wszBuf);
104 105 106 107 108
                return TRUE;
            case IDC_GETSIZEMAX_BUTTON:
                unk = GetInterface();
                IPersistStream_GetSizeMax((IPersistStream *)unk, &size);
                IUnknown_Release(unk);
109
                LoadStringW(globals.hMainInst, IDS_BYTES, wszBuf, ARRAY_SIZE(wszBuf));
110
                wsprintfW(wszSize, wszFormat, size.LowPart, wszBuf);
111
                hObject = GetDlgItem(hDlgWnd, IDC_GETSIZEMAX);
112
                SetWindowTextW(hObject, wszSize);
113 114 115 116 117 118
                return TRUE;
            }
    }
    return FALSE;
}

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

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

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

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

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

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

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

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

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

void InterfaceViewer(HTREEITEM item)
{
160
    TVITEMW tvi;
161 162
    WCHAR *clsid;
    WCHAR wszName[MAX_LOAD_STRING];
163
    WCHAR wszParent[MAX_LOAD_STRING];
164 165 166 167 168 169 170
    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' };

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

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

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

187
    SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
188

189
    if(!memcmp(clsid, wszIPersistStream, sizeof(wszIPersistStream)))
190
        IPersistStreamInterfaceViewer(clsid, wszParent);
191 192

    else if(!memcmp(clsid, wszIPersist, sizeof(wszIPersist)))
193
        IPersistInterfaceViewer(clsid, wszParent);
194 195 196

    else DefaultInterfaceViewer(clsid, wszName);
}