oledlg: Forward OleUIPasteSpecialA -> OleUIPasteSpecialW.
[wine] / dlls / oledlg / pastespl.c
1 /*
2  * OleUIPasteSpecial implementation
3  *
4  * Copyright 2006 Huw Davies
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #define COM_NO_WINDOWS_H
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27 #include "wingdi.h"
28 #include "winuser.h"
29 #include "winnls.h"
30 #include "oledlg.h"
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(ole);
34
35 static const struct ps_flag
36 {
37     DWORD flag;
38     const char *name;
39 } ps_flags[] = {
40 #define PS_FLAG_ENTRY(p) {p, #p}
41     PS_FLAG_ENTRY(PSF_SHOWHELP),
42     PS_FLAG_ENTRY(PSF_SELECTPASTE),
43     PS_FLAG_ENTRY(PSF_SELECTPASTELINK),
44     PS_FLAG_ENTRY(PSF_CHECKDISPLAYASICON),
45     PS_FLAG_ENTRY(PSF_DISABLEDISPLAYASICON),
46     PS_FLAG_ENTRY(PSF_HIDECHANGEICON),
47     PS_FLAG_ENTRY(PSF_STAYONCLIPBOARDCHANGE),
48     PS_FLAG_ENTRY(PSF_NOREFRESHDATAOBJECT),
49     {-1, NULL}
50 #undef PS_FLAG_ENTRY
51 };
52
53 static void dump_ps_flags(DWORD flags)
54 {
55     char flagstr[1000] = "";
56
57     const struct ps_flag *flag = ps_flags;
58     for( ; flag->name; flag++) {
59         if(flags & flag->flag) {
60             strcat(flagstr, flag->name);
61             strcat(flagstr, "|");
62         }
63     }
64     TRACE("flags %08x %s\n", flags, flagstr);
65 }
66
67 static void dump_pastespecial(LPOLEUIPASTESPECIALW ps)
68 {
69     UINT i;
70     dump_ps_flags(ps->dwFlags);
71     TRACE("hwnd %p caption %s hook %p custdata %lx\n",
72           ps->hWndOwner, debugstr_w(ps->lpszCaption), ps->lpfnHook, ps->lCustData);
73     if(IS_INTRESOURCE(ps->lpszTemplate))
74         TRACE("hinst %p template %04x hresource %p\n", ps->hInstance, (WORD)(ULONG_PTR)ps->lpszTemplate, ps->hResource);
75     else
76         TRACE("hinst %p template %s hresource %p\n", ps->hInstance, debugstr_w(ps->lpszTemplate), ps->hResource);
77     TRACE("dataobj %p arrpasteent %p cpasteent %d arrlinktype %p clinktype %d\n",
78           ps->lpSrcDataObj, ps->arrPasteEntries, ps->cPasteEntries,
79           ps->arrLinkTypes, ps->cLinkTypes);
80     TRACE("cclsidex %d lpclsidex %p nselect %d flink %d hmetapict %p size(%d,%d)\n",
81           ps->cClsidExclude, ps->lpClsidExclude, ps->nSelectedIndex, ps->fLink,
82           ps->hMetaPict, ps->sizel.cx, ps->sizel.cy);
83     for(i = 0; i < ps->cPasteEntries; i++)
84     {
85         TRACE("arrPasteEntries[%d]: cFormat %08x pTargetDevice %p dwAspect %d lindex %d tymed %d\n",
86               i, ps->arrPasteEntries[i].fmtetc.cfFormat, ps->arrPasteEntries[i].fmtetc.ptd,
87               ps->arrPasteEntries[i].fmtetc.dwAspect, ps->arrPasteEntries[i].fmtetc.lindex,
88               ps->arrPasteEntries[i].fmtetc.tymed);
89         TRACE("\tformat name %s result text %s flags %04x\n", debugstr_w(ps->arrPasteEntries[i].lpstrFormatName),
90               debugstr_w(ps->arrPasteEntries[i].lpstrResultText), ps->arrPasteEntries[i].dwFlags);
91     }
92     for(i = 0; i < ps->cLinkTypes; i++)
93         TRACE("arrLinkTypes[%d] %08x\n", i, ps->arrLinkTypes[i]);
94     for(i = 0; i < ps->cClsidExclude; i++)
95         TRACE("lpClsidExclude[%d] %s\n", i, debugstr_guid(&ps->lpClsidExclude[i]));
96
97 }
98
99 static inline WCHAR *strdupAtoW(const char *str)
100 {
101     DWORD len;
102     WCHAR *ret;
103     if(!str) return NULL;
104     len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
105     ret = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
106     MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
107     return ret;
108 }
109
110 /***********************************************************************
111  *           OleUIPasteSpecialA (OLEDLG.4)
112  */
113 UINT WINAPI OleUIPasteSpecialA(LPOLEUIPASTESPECIALA psA)
114 {
115     OLEUIPASTESPECIALW ps;
116     UINT ret;
117     TRACE("(%p)\n", psA);
118
119     memcpy(&ps, psA, psA->cbStruct);
120
121     ps.lpszCaption = strdupAtoW(psA->lpszCaption);
122     if(!IS_INTRESOURCE(ps.lpszTemplate))
123         ps.lpszTemplate = strdupAtoW(psA->lpszTemplate);
124
125     if(psA->cPasteEntries > 0)
126     {
127         DWORD size = psA->cPasteEntries * sizeof(ps.arrPasteEntries[0]);
128         UINT i;
129
130         ps.arrPasteEntries = HeapAlloc(GetProcessHeap(), 0, size);
131         memcpy(ps.arrPasteEntries, psA->arrPasteEntries, size);
132         for(i = 0; i < psA->cPasteEntries; i++)
133         {
134             ps.arrPasteEntries[i].lpstrFormatName =
135                 strdupAtoW(psA->arrPasteEntries[i].lpstrFormatName);
136             ps.arrPasteEntries[i].lpstrResultText =
137                 strdupAtoW(psA->arrPasteEntries[i].lpstrResultText);
138         }
139     }
140
141     ret = OleUIPasteSpecialW(&ps);
142
143     if(psA->cPasteEntries > 0)
144     {
145         UINT i;
146         for(i = 0; i < psA->cPasteEntries; i++)
147         {
148             HeapFree(GetProcessHeap(), 0, (WCHAR*)ps.arrPasteEntries[i].lpstrFormatName);
149             HeapFree(GetProcessHeap(), 0, (WCHAR*)ps.arrPasteEntries[i].lpstrResultText);
150         }
151         HeapFree(GetProcessHeap(), 0, ps.arrPasteEntries);
152     }
153     if(!IS_INTRESOURCE(ps.lpszTemplate))
154         HeapFree(GetProcessHeap(), 0, (WCHAR*)ps.lpszTemplate);
155     HeapFree(GetProcessHeap(), 0, (WCHAR*)ps.lpszCaption);
156
157     /* Copy back the output fields */
158     psA->dwFlags = ps.dwFlags;
159     psA->lpSrcDataObj = ps.lpSrcDataObj;
160     psA->nSelectedIndex = ps.nSelectedIndex;
161     psA->fLink = ps.fLink;
162     psA->hMetaPict = ps.hMetaPict;
163     psA->sizel = ps.sizel;
164
165     return ret;
166 }
167
168 /***********************************************************************
169  *           OleUIPasteSpecialW (OLEDLG.22)
170  */
171 UINT WINAPI OleUIPasteSpecialW(LPOLEUIPASTESPECIALW ps)
172 {
173     TRACE("(%p)\n", ps);
174
175     if(TRACE_ON(ole)) dump_pastespecial(ps);
176
177     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
178     return OLEUI_FALSE;
179 }