From 39131cf5450af8c88148197af359d43df9126e75 Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Thu, 19 Oct 2006 11:40:54 +0100 Subject: [PATCH] oledlg: Retrieve names from the OBJECTDESCRIPTOR structure. --- dlls/oledlg/pastespl.c | 86 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/dlls/oledlg/pastespl.c b/dlls/oledlg/pastespl.c index d4cdadc2c32..ff3a8b5ad6e 100644 --- a/dlls/oledlg/pastespl.c +++ b/dlls/oledlg/pastespl.c @@ -20,6 +20,8 @@ #define COM_NO_WINDOWS_H #define COBJMACROS +#define NONAMELESSSTRUCT +#define NONAMELESSUNION #include @@ -43,6 +45,11 @@ typedef struct { OLEUIPASTESPECIALW *ps; DWORD flags; + WCHAR *source_name; + WCHAR *link_source_name; + WCHAR *type_name; + WCHAR *link_type_name; + LPOLESTR app_name; } ps_struct_t; static const struct ps_flag @@ -120,6 +127,73 @@ static inline WCHAR *strdupAtoW(const char *str) return ret; } +static inline WCHAR *strdupW(const WCHAR *str) +{ + DWORD len; + WCHAR *ret; + if(!str) return NULL; + len = lstrlenW(str) + 1; + ret = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); + memcpy(ret, str, len * sizeof(WCHAR)); + return ret; +} + +static void get_descriptors(HWND hdlg, ps_struct_t *ps_struct) +{ + FORMATETC fmtetc; + STGMEDIUM stg; + + fmtetc.tymed = TYMED_HGLOBAL; + fmtetc.dwAspect = DVASPECT_CONTENT; + fmtetc.ptd = NULL; + fmtetc.lindex = -1; + + fmtetc.cfFormat = cf_object_descriptor; + if(IDataObject_GetData(ps_struct->ps->lpSrcDataObj, &fmtetc, &stg) == S_OK) + { + OBJECTDESCRIPTOR *obj_desc = GlobalLock(stg.u.hGlobal); + if(obj_desc->dwSrcOfCopy) + ps_struct->source_name = strdupW((WCHAR*)((char*)obj_desc + obj_desc->dwSrcOfCopy)); + if(obj_desc->dwFullUserTypeName) + ps_struct->type_name = strdupW((WCHAR*)((char*)obj_desc + obj_desc->dwFullUserTypeName)); + OleRegGetUserType(&obj_desc->clsid, USERCLASSTYPE_APPNAME, &ps_struct->app_name); + /* Get the icon here. If dwDrawAspect & DVASCPECT_ICON call GetData(CF_METAFILEPICT), otherwise + native calls OleGetIconFromClass(obj_desc->clsid) */ + GlobalUnlock(stg.u.hGlobal); + GlobalFree(stg.u.hGlobal); + } + else + { + /* Try to get some data using some of the other clipboard formats */ + } + + fmtetc.cfFormat = cf_link_src_descriptor; + if(IDataObject_GetData(ps_struct->ps->lpSrcDataObj, &fmtetc, &stg) == S_OK) + { + OBJECTDESCRIPTOR *obj_desc = GlobalLock(stg.u.hGlobal); + if(obj_desc->dwSrcOfCopy) + ps_struct->link_source_name = strdupW((WCHAR*)((char*)obj_desc + obj_desc->dwSrcOfCopy)); + if(obj_desc->dwFullUserTypeName) + ps_struct->link_type_name = strdupW((WCHAR*)((char*)obj_desc + obj_desc->dwFullUserTypeName)); + GlobalUnlock(stg.u.hGlobal); + GlobalFree(stg.u.hGlobal); + } + + if(ps_struct->source_name == NULL && ps_struct->link_source_name == NULL) + { + WCHAR buf[200]; + LoadStringW(OLEDLG_hInstance, IDS_PS_UNKNOWN_SRC, buf, sizeof(buf)/sizeof(WCHAR)); + ps_struct->source_name = strdupW(buf); + } + + if(ps_struct->type_name == NULL && ps_struct->link_type_name == NULL) + { + WCHAR buf[200]; + LoadStringW(OLEDLG_hInstance, IDS_PS_UNKNOWN_TYPE, buf, sizeof(buf)/sizeof(WCHAR)); + ps_struct->type_name = strdupW(buf); + } +} + static BOOL add_entry_to_lb(HWND hdlg, UINT id, OLEUIPASTEENTRYW *pe) { HWND hwnd = GetDlgItem(hdlg, id); @@ -397,6 +471,11 @@ static void update_structure(HWND hdlg, ps_struct_t *ps_struct) static void free_structure(ps_struct_t *ps_struct) { + HeapFree(GetProcessHeap(), 0, ps_struct->type_name); + HeapFree(GetProcessHeap(), 0, ps_struct->source_name); + HeapFree(GetProcessHeap(), 0, ps_struct->link_type_name); + HeapFree(GetProcessHeap(), 0, ps_struct->link_source_name); + CoTaskMemFree(ps_struct->app_name); HeapFree(GetProcessHeap(), 0, ps_struct); } @@ -429,6 +508,11 @@ static INT_PTR CALLBACK ps_dlg_proc(HWND hdlg, UINT msg, WPARAM wp, LPARAM lp) { ps_struct = HeapAlloc(GetProcessHeap(), 0, sizeof(*ps_struct)); ps_struct->ps = (OLEUIPASTESPECIALW*)lp; + ps_struct->type_name = NULL; + ps_struct->source_name = NULL; + ps_struct->link_type_name = NULL; + ps_struct->link_source_name = NULL; + ps_struct->app_name = NULL; ps_struct->flags = ps_struct->ps->dwFlags; SetPropW(hdlg, prop_name, ps_struct); @@ -442,6 +526,8 @@ static INT_PTR CALLBACK ps_dlg_proc(HWND hdlg, UINT msg, WPARAM wp, LPARAM lp) if(ps_struct->ps->lpszCaption) SetWindowTextW(hdlg, ps_struct->ps->lpszCaption); + get_descriptors(hdlg, ps_struct); + init_lists(hdlg, ps_struct); selection_change(hdlg, ps_struct);