2 * OleUIPasteSpecial implementation
4 * Copyright 2006 Huw Davies
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
22 #define NONAMELESSUNION
34 #include "oledlg_private.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
43 OLEUIPASTESPECIALW
*ps
;
46 WCHAR
*link_source_name
;
48 WCHAR
*link_type_name
;
52 static const struct ps_flag
57 #define PS_FLAG_ENTRY(p) {p, #p}
58 PS_FLAG_ENTRY(PSF_SHOWHELP
),
59 PS_FLAG_ENTRY(PSF_SELECTPASTE
),
60 PS_FLAG_ENTRY(PSF_SELECTPASTELINK
),
61 PS_FLAG_ENTRY(PSF_CHECKDISPLAYASICON
),
62 PS_FLAG_ENTRY(PSF_DISABLEDISPLAYASICON
),
63 PS_FLAG_ENTRY(PSF_HIDECHANGEICON
),
64 PS_FLAG_ENTRY(PSF_STAYONCLIPBOARDCHANGE
),
65 PS_FLAG_ENTRY(PSF_NOREFRESHDATAOBJECT
),
70 static void dump_ps_flags(DWORD flags
)
72 char flagstr
[1000] = "";
74 const struct ps_flag
*flag
= ps_flags
;
75 for( ; flag
->name
; flag
++) {
76 if(flags
& flag
->flag
) {
77 strcat(flagstr
, flag
->name
);
81 TRACE("flags %08lx %s\n", flags
, flagstr
);
84 static void dump_pastespecial(const OLEUIPASTESPECIALW
*ps
)
89 dump_ps_flags(ps
->dwFlags
);
90 TRACE("hwnd %p caption %s hook %p custdata %Ix\n",
91 ps
->hWndOwner
, debugstr_w(ps
->lpszCaption
), ps
->lpfnHook
, ps
->lCustData
);
92 if(IS_INTRESOURCE(ps
->lpszTemplate
))
93 TRACE("hinst %p template %04x hresource %p\n", ps
->hInstance
, (WORD
)(ULONG_PTR
)ps
->lpszTemplate
, ps
->hResource
);
95 TRACE("hinst %p template %s hresource %p\n", ps
->hInstance
, debugstr_w(ps
->lpszTemplate
), ps
->hResource
);
96 TRACE("dataobj %p arrpasteent %p cpasteent %d arrlinktype %p clinktype %d\n",
97 ps
->lpSrcDataObj
, ps
->arrPasteEntries
, ps
->cPasteEntries
,
98 ps
->arrLinkTypes
, ps
->cLinkTypes
);
99 TRACE("cclsidex %d lpclsidex %p nselect %d flink %d hmetapict %p size(%ld,%ld)\n",
100 ps
->cClsidExclude
, ps
->lpClsidExclude
, ps
->nSelectedIndex
, ps
->fLink
,
101 ps
->hMetaPict
, ps
->sizel
.cx
, ps
->sizel
.cy
);
102 for(i
= 0; i
< ps
->cPasteEntries
; i
++)
104 TRACE("arrPasteEntries[%d]: cFormat %08x pTargetDevice %p dwAspect %ld lindex %ld tymed %ld\n",
105 i
, ps
->arrPasteEntries
[i
].fmtetc
.cfFormat
, ps
->arrPasteEntries
[i
].fmtetc
.ptd
,
106 ps
->arrPasteEntries
[i
].fmtetc
.dwAspect
, ps
->arrPasteEntries
[i
].fmtetc
.lindex
,
107 ps
->arrPasteEntries
[i
].fmtetc
.tymed
);
108 TRACE("\tformat name %s result text %s flags %04lx\n", debugstr_w(ps
->arrPasteEntries
[i
].lpstrFormatName
),
109 debugstr_w(ps
->arrPasteEntries
[i
].lpstrResultText
), ps
->arrPasteEntries
[i
].dwFlags
);
111 for(i
= 0; i
< ps
->cLinkTypes
; i
++)
112 TRACE("arrLinkTypes[%d] %08x\n", i
, ps
->arrLinkTypes
[i
]);
113 for(j
= 0; j
< ps
->cClsidExclude
; j
++)
114 TRACE("lpClsidExclude[%u] %s\n", j
, debugstr_guid(&ps
->lpClsidExclude
[j
]));
118 static inline WCHAR
*strdupAtoW(const char *str
)
122 if(!str
) return NULL
;
123 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
124 ret
= malloc(len
* sizeof(WCHAR
));
125 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
129 static void get_descriptors(HWND hdlg
, ps_struct_t
*ps_struct
)
134 fmtetc
.tymed
= TYMED_HGLOBAL
;
135 fmtetc
.dwAspect
= DVASPECT_CONTENT
;
139 fmtetc
.cfFormat
= cf_object_descriptor
;
140 if(IDataObject_GetData(ps_struct
->ps
->lpSrcDataObj
, &fmtetc
, &stg
) == S_OK
)
142 OBJECTDESCRIPTOR
*obj_desc
= GlobalLock(stg
.u
.hGlobal
);
143 if(obj_desc
->dwSrcOfCopy
)
144 ps_struct
->source_name
= wcsdup((WCHAR
*)((char*)obj_desc
+ obj_desc
->dwSrcOfCopy
));
145 if(obj_desc
->dwFullUserTypeName
)
146 ps_struct
->type_name
= wcsdup((WCHAR
*)((char*)obj_desc
+ obj_desc
->dwFullUserTypeName
));
147 OleRegGetUserType(&obj_desc
->clsid
, USERCLASSTYPE_APPNAME
, &ps_struct
->app_name
);
148 /* Get the icon here. If dwDrawAspect & DVASCPECT_ICON call GetData(CF_METAFILEPICT), otherwise
149 native calls OleGetIconFromClass(obj_desc->clsid) */
150 GlobalUnlock(stg
.u
.hGlobal
);
151 GlobalFree(stg
.u
.hGlobal
);
155 /* Try to get some data using some of the other clipboard formats */
158 fmtetc
.cfFormat
= cf_link_src_descriptor
;
159 if(IDataObject_GetData(ps_struct
->ps
->lpSrcDataObj
, &fmtetc
, &stg
) == S_OK
)
161 OBJECTDESCRIPTOR
*obj_desc
= GlobalLock(stg
.u
.hGlobal
);
162 if(obj_desc
->dwSrcOfCopy
)
163 ps_struct
->link_source_name
= wcsdup((WCHAR
*)((char*)obj_desc
+ obj_desc
->dwSrcOfCopy
));
164 if(obj_desc
->dwFullUserTypeName
)
165 ps_struct
->link_type_name
= wcsdup((WCHAR
*)((char*)obj_desc
+ obj_desc
->dwFullUserTypeName
));
166 GlobalUnlock(stg
.u
.hGlobal
);
167 GlobalFree(stg
.u
.hGlobal
);
170 if(ps_struct
->source_name
== NULL
&& ps_struct
->link_source_name
== NULL
)
173 LoadStringW(OLEDLG_hInstance
, IDS_PS_UNKNOWN_SRC
, buf
, ARRAY_SIZE(buf
));
174 ps_struct
->source_name
= wcsdup(buf
);
177 if(ps_struct
->type_name
== NULL
&& ps_struct
->link_type_name
== NULL
)
180 LoadStringW(OLEDLG_hInstance
, IDS_PS_UNKNOWN_TYPE
, buf
, ARRAY_SIZE(buf
));
181 ps_struct
->type_name
= wcsdup(buf
);
185 static BOOL
add_entry_to_lb(HWND hdlg
, UINT id
, OLEUIPASTEENTRYW
*pe
)
187 HWND hwnd
= GetDlgItem(hdlg
, id
);
190 /* FIXME %s handling */
192 /* Note that this suffers from the same bug as native, in that if a new string
193 is a substring of an already added string, then the FINDSTRING will succeed
194 this is probably not what we want */
195 if(SendMessageW(hwnd
, LB_FINDSTRING
, 0, (LPARAM
)pe
->lpstrFormatName
) == -1)
197 LRESULT pos
= SendMessageW(hwnd
, LB_ADDSTRING
, 0, (LPARAM
)pe
->lpstrFormatName
);
198 SendMessageW(hwnd
, LB_SETITEMDATA
, pos
, (LPARAM
)pe
);
204 static DWORD
init_pastelist(HWND hdlg
, OLEUIPASTESPECIALW
*ps
)
206 IEnumFORMATETC
*penum
;
209 DWORD fetched
, items_added
= 0;
211 hr
= IDataObject_EnumFormatEtc(ps
->lpSrcDataObj
, DATADIR_GET
, &penum
);
214 WARN("Unable to create IEnumFORMATETC\n");
218 /* The native version grabs only the first 20 fmts and we do the same */
219 hr
= IEnumFORMATETC_Next(penum
, ARRAY_SIZE(fmts
), fmts
, &fetched
);
220 TRACE("got %ld formats hr %08lx\n", fetched
, hr
);
224 DWORD src_fmt
, req_fmt
;
225 for(req_fmt
= 0; req_fmt
< ps
->cPasteEntries
; req_fmt
++)
227 /* This is used by update_structure() to set nSelectedIndex on exit */
228 ps
->arrPasteEntries
[req_fmt
].dwScratchSpace
= req_fmt
;
229 TRACE("req_fmt %x\n", ps
->arrPasteEntries
[req_fmt
].fmtetc
.cfFormat
);
230 for(src_fmt
= 0; src_fmt
< fetched
; src_fmt
++)
232 TRACE("\tenum'ed fmt %x\n", fmts
[src_fmt
].cfFormat
);
233 if(ps
->arrPasteEntries
[req_fmt
].fmtetc
.cfFormat
== fmts
[src_fmt
].cfFormat
)
235 add_entry_to_lb(hdlg
, IDC_PS_PASTELIST
, ps
->arrPasteEntries
+ req_fmt
);
243 IEnumFORMATETC_Release(penum
);
244 EnableWindow(GetDlgItem(hdlg
, IDC_PS_PASTE
), items_added
!= 0);
248 static DWORD
init_linklist(HWND hdlg
, OLEUIPASTESPECIALW
*ps
)
251 DWORD supported_mask
= 0;
252 DWORD items_added
= 0;
254 FORMATETC fmt
= {0, NULL
, DVASPECT_CONTENT
, -1, -1};
256 for(link
= 0; link
< ps
->cLinkTypes
&& link
< PS_MAXLINKTYPES
; link
++)
258 fmt
.cfFormat
= ps
->arrLinkTypes
[link
];
259 hr
= IDataObject_QueryGetData(ps
->lpSrcDataObj
, &fmt
);
261 supported_mask
|= 1 << link
;
263 TRACE("supported_mask %02lx\n", supported_mask
);
264 for(req_fmt
= 0; req_fmt
< ps
->cPasteEntries
; req_fmt
++)
267 if(ps
->arrPasteEntries
[req_fmt
].dwFlags
& OLEUIPASTE_LINKANYTYPE
)
270 linktypes
= ps
->arrPasteEntries
[req_fmt
].dwFlags
& 0xff;
272 if(linktypes
& supported_mask
)
274 add_entry_to_lb(hdlg
, IDC_PS_PASTELINKLIST
, ps
->arrPasteEntries
+ req_fmt
);
279 EnableWindow(GetDlgItem(hdlg
, IDC_PS_PASTELINK
), items_added
!= 0);
283 /* copies src_list_id into the display list */
284 static void update_display_list(HWND hdlg
, UINT src_list_id
)
286 LONG count
, i
, old_pos
;
289 HWND display_list
= GetDlgItem(hdlg
, IDC_PS_DISPLAYLIST
);
290 HWND list
= GetDlgItem(hdlg
, src_list_id
);
292 old_pos
= SendMessageW(display_list
, LB_GETCURSEL
, 0, 0);
293 if(old_pos
== -1) old_pos
= 0;
295 SendMessageW(display_list
, WM_SETREDRAW
, 0, 0);
296 SendMessageW(display_list
, LB_RESETCONTENT
, 0, 0);
297 count
= SendMessageW(list
, LB_GETCOUNT
, 0, 0);
298 for(i
= 0; i
< count
; i
++)
300 SendMessageW(list
, LB_GETTEXT
, i
, (LPARAM
)txt
);
301 item_data
= SendMessageW(list
, LB_GETITEMDATA
, i
, 0);
302 SendMessageW(display_list
, LB_INSERTSTRING
, i
, (LPARAM
)txt
);
303 SendMessageW(display_list
, LB_SETITEMDATA
, i
, item_data
);
305 SendMessageW(display_list
, LB_SETCURSEL
, 0, 0);
306 SendMessageW(display_list
, WM_SETREDRAW
, 1, 0);
307 if(GetForegroundWindow() == hdlg
)
308 SetFocus(display_list
);
311 static void init_lists(HWND hdlg
, ps_struct_t
*ps_struct
)
313 DWORD pastes_added
= init_pastelist(hdlg
, ps_struct
->ps
);
314 DWORD links_added
= init_linklist(hdlg
, ps_struct
->ps
);
315 UINT check_id
, list_id
;
317 if((ps_struct
->flags
& (PSF_SELECTPASTE
| PSF_SELECTPASTELINK
)) == 0)
318 ps_struct
->flags
|= PSF_SELECTPASTE
;
320 if(!pastes_added
&& !links_added
)
321 ps_struct
->flags
&= ~(PSF_SELECTPASTE
| PSF_SELECTPASTELINK
);
322 else if(!pastes_added
&& (ps_struct
->flags
& PSF_SELECTPASTE
))
324 ps_struct
->flags
&= ~PSF_SELECTPASTE
;
325 ps_struct
->flags
|= PSF_SELECTPASTELINK
;
327 else if(!links_added
&& (ps_struct
->flags
& PSF_SELECTPASTELINK
))
329 ps_struct
->flags
&= ~PSF_SELECTPASTELINK
;
330 ps_struct
->flags
|= PSF_SELECTPASTE
;
335 if(ps_struct
->flags
& PSF_SELECTPASTE
)
337 check_id
= IDC_PS_PASTE
;
338 list_id
= IDC_PS_PASTELIST
;
340 else if(ps_struct
->flags
& PSF_SELECTPASTELINK
)
342 check_id
= IDC_PS_PASTELINK
;
343 list_id
= IDC_PS_PASTELINKLIST
;
346 CheckRadioButton(hdlg
, IDC_PS_PASTE
, IDC_PS_PASTELINK
, check_id
);
349 update_display_list(hdlg
, list_id
);
351 EnableWindow(GetDlgItem(hdlg
, IDOK
), 0);
354 static void update_src_text(HWND hdlg
, const ps_struct_t
*ps_struct
)
358 if(ps_struct
->flags
& PSF_SELECTPASTE
)
360 if(ps_struct
->source_name
)
361 str
= ps_struct
->source_name
;
363 str
= ps_struct
->link_source_name
;
368 if(ps_struct
->link_source_name
)
369 str
= ps_struct
->link_source_name
;
371 str
= ps_struct
->source_name
;
374 SetDlgItemTextW(hdlg
, IDC_PS_SOURCETEXT
, str
);
377 static void update_as_icon(HWND hdlg
, ps_struct_t
*ps_struct
)
379 HWND icon_display
= GetDlgItem(hdlg
, IDC_PS_ICONDISPLAY
);
380 HWND display_as_icon
= GetDlgItem(hdlg
, IDC_PS_DISPLAYASICON
);
381 HWND change_icon
= GetDlgItem(hdlg
, IDC_PS_CHANGEICON
);
383 /* FIXME. No as icon handling */
384 ps_struct
->flags
&= ~PSF_CHECKDISPLAYASICON
;
386 CheckDlgButton(hdlg
, IDC_PS_DISPLAYASICON
, ps_struct
->flags
& PSF_CHECKDISPLAYASICON
);
387 EnableWindow(display_as_icon
, 0);
388 ShowWindow(icon_display
, SW_HIDE
);
389 EnableWindow(icon_display
, 0);
390 ShowWindow(change_icon
, SW_HIDE
);
391 EnableWindow(change_icon
, 0);
394 static void update_result_text(HWND hdlg
, const ps_struct_t
*ps_struct
)
396 WCHAR resource_txt
[200];
398 OLEUIPASTEENTRYW
*pent
;
400 static const WCHAR percent_s
[] = {'%','s',0};
401 WCHAR
*result_txt
, *ptr
;
403 cur_sel
= SendMessageW(GetDlgItem(hdlg
, IDC_PS_DISPLAYLIST
), LB_GETCURSEL
, 0, 0);
404 if(cur_sel
== -1) return;
405 pent
= (OLEUIPASTEENTRYW
*)SendMessageW(GetDlgItem(hdlg
, IDC_PS_DISPLAYLIST
), LB_GETITEMDATA
, cur_sel
, 0);
407 if(ps_struct
->flags
& PSF_SELECTPASTE
)
409 if(ps_struct
->flags
& PSF_CHECKDISPLAYASICON
)
410 res_id
= IDS_PS_PASTE_OBJECT_AS_ICON
;
412 res_id
= IDS_PS_PASTE_DATA
;
416 if(ps_struct
->flags
& PSF_CHECKDISPLAYASICON
)
417 res_id
= IDS_PS_PASTE_LINK_OBJECT_AS_ICON
;
419 res_id
= IDS_PS_PASTE_LINK_DATA
;
422 LoadStringW(OLEDLG_hInstance
, res_id
, resource_txt
, ARRAY_SIZE(resource_txt
));
423 if((ptr
= wcsstr(resource_txt
, percent_s
)))
425 /* FIXME handle %s in ResultText. Sub appname if IDS_PS_PASTE_OBJECT{_AS_ICON}. Else sub appropriate type name */
426 size_t result_txt_len
= lstrlenW(pent
->lpstrResultText
);
427 ptrdiff_t offs
= (char*)ptr
- (char*)resource_txt
;
428 result_txt
= malloc((wcslen(resource_txt
) + result_txt_len
- 1) * sizeof(WCHAR
));
429 memcpy(result_txt
, resource_txt
, offs
);
430 memcpy((char*)result_txt
+ offs
, pent
->lpstrResultText
, result_txt_len
* sizeof(WCHAR
));
431 memcpy((char*)result_txt
+ offs
+ result_txt_len
* sizeof(WCHAR
), ptr
+ 2, (lstrlenW(ptr
+ 2) + 1) * sizeof(WCHAR
));
434 result_txt
= resource_txt
;
436 SetDlgItemTextW(hdlg
, IDC_PS_RESULTTEXT
, result_txt
);
438 if(result_txt
!= resource_txt
)
443 static void selection_change(HWND hdlg
, ps_struct_t
*ps_struct
)
445 update_as_icon(hdlg
, ps_struct
);
446 update_result_text(hdlg
, ps_struct
);
449 static void mode_change(HWND hdlg
, ps_struct_t
*ps_struct
, UINT id
)
451 if(id
== IDC_PS_PASTE
)
453 ps_struct
->flags
&= ~PSF_SELECTPASTELINK
;
454 ps_struct
->flags
|= PSF_SELECTPASTE
;
458 ps_struct
->flags
&= ~PSF_SELECTPASTE
;
459 ps_struct
->flags
|= PSF_SELECTPASTELINK
;
462 update_src_text(hdlg
, ps_struct
);
463 update_display_list(hdlg
, id
== IDC_PS_PASTE
? IDC_PS_PASTELIST
: IDC_PS_PASTELINKLIST
);
464 selection_change(hdlg
, ps_struct
);
467 static void post_help_msg(HWND hdlg
, ps_struct_t
*ps_struct
)
469 PostMessageW(ps_struct
->ps
->hWndOwner
, oleui_msg_help
, (WPARAM
)hdlg
, IDD_PASTESPECIAL
);
472 static void send_end_dialog_msg(HWND hdlg
, ps_struct_t
*ps_struct
, UINT id
)
474 SendMessageW(hdlg
, oleui_msg_enddialog
, id
, 0);
477 static void update_structure(HWND hdlg
, ps_struct_t
*ps_struct
)
479 LONG cur_sel
= SendMessageW(GetDlgItem(hdlg
, IDC_PS_DISPLAYLIST
), LB_GETCURSEL
, 0, 0);
482 OLEUIPASTEENTRYW
*pent
;
483 pent
= (OLEUIPASTEENTRYW
*)SendMessageW(GetDlgItem(hdlg
, IDC_PS_DISPLAYLIST
), LB_GETITEMDATA
, cur_sel
, 0);
484 ps_struct
->ps
->nSelectedIndex
= pent
->dwScratchSpace
;
486 ps_struct
->ps
->dwFlags
= ps_struct
->flags
;
487 ps_struct
->ps
->fLink
= (ps_struct
->flags
& PSF_SELECTPASTELINK
) != 0;
490 static void free_structure(ps_struct_t
*ps_struct
)
492 free(ps_struct
->type_name
);
493 free(ps_struct
->source_name
);
494 free(ps_struct
->link_type_name
);
495 free(ps_struct
->link_source_name
);
496 CoTaskMemFree(ps_struct
->app_name
);
500 static INT_PTR CALLBACK
ps_dlg_proc(HWND hdlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
502 /* native uses prop name "Structure", but we're not compatible
503 with that so we'll prepend "Wine_". */
504 static const WCHAR prop_name
[] = {'W','i','n','e','_','S','t','r','u','c','t','u','r','e',0};
505 ps_struct_t
*ps_struct
;
507 TRACE("(%p, %04x, %08Ix, %08Ix)\n", hdlg
, msg
, wp
, lp
);
509 ps_struct
= GetPropW(hdlg
, prop_name
);
511 if(msg
!= WM_INITDIALOG
)
516 if(ps_struct
->ps
->lpfnHook
)
518 INT_PTR ret
= ps_struct
->ps
->lpfnHook(hdlg
, msg
, wp
, lp
);
527 ps_struct
= malloc(sizeof(*ps_struct
));
528 ps_struct
->ps
= (OLEUIPASTESPECIALW
*)lp
;
529 ps_struct
->type_name
= NULL
;
530 ps_struct
->source_name
= NULL
;
531 ps_struct
->link_type_name
= NULL
;
532 ps_struct
->link_source_name
= NULL
;
533 ps_struct
->app_name
= NULL
;
534 ps_struct
->flags
= ps_struct
->ps
->dwFlags
;
536 SetPropW(hdlg
, prop_name
, ps_struct
);
538 if(!(ps_struct
->ps
->dwFlags
& PSF_SHOWHELP
))
540 ShowWindow(GetDlgItem(hdlg
, IDC_OLEUIHELP
), SW_HIDE
);
541 EnableWindow(GetDlgItem(hdlg
, IDC_OLEUIHELP
), 0);
544 if(ps_struct
->ps
->lpszCaption
)
545 SetWindowTextW(hdlg
, ps_struct
->ps
->lpszCaption
);
547 get_descriptors(hdlg
, ps_struct
);
549 init_lists(hdlg
, ps_struct
);
551 update_src_text(hdlg
, ps_struct
);
553 selection_change(hdlg
, ps_struct
);
555 SetFocus(GetDlgItem(hdlg
, IDC_PS_DISPLAYLIST
));
557 if(ps_struct
->ps
->lpfnHook
)
558 ps_struct
->ps
->lpfnHook(hdlg
, msg
, 0, 0);
559 return FALSE
; /* use new focus */
564 case IDC_PS_DISPLAYLIST
:
568 selection_change(hdlg
, ps_struct
);
574 case IDC_PS_PASTELINK
:
578 mode_change(hdlg
, ps_struct
, LOWORD(wp
));
588 post_help_msg(hdlg
, ps_struct
);
598 send_end_dialog_msg(hdlg
, ps_struct
, LOWORD(wp
));
606 if(msg
== oleui_msg_enddialog
)
609 update_structure(hdlg
, ps_struct
);
611 /* native does its cleanup in WM_DESTROY */
612 RemovePropW(hdlg
, prop_name
);
613 free_structure(ps_struct
);
621 /***********************************************************************
622 * OleUIPasteSpecialA (OLEDLG.4)
624 UINT WINAPI
OleUIPasteSpecialA(LPOLEUIPASTESPECIALA psA
)
626 OLEUIPASTESPECIALW ps
;
628 TRACE("(%p)\n", psA
);
630 memcpy(&ps
, psA
, psA
->cbStruct
);
632 ps
.lpszCaption
= strdupAtoW(psA
->lpszCaption
);
633 if(!IS_INTRESOURCE(ps
.lpszTemplate
))
634 ps
.lpszTemplate
= strdupAtoW(psA
->lpszTemplate
);
636 if(psA
->cPasteEntries
> 0)
638 DWORD size
= psA
->cPasteEntries
* sizeof(ps
.arrPasteEntries
[0]);
641 ps
.arrPasteEntries
= malloc(size
);
642 memcpy(ps
.arrPasteEntries
, psA
->arrPasteEntries
, size
);
643 for(i
= 0; i
< psA
->cPasteEntries
; i
++)
645 ps
.arrPasteEntries
[i
].lpstrFormatName
=
646 strdupAtoW(psA
->arrPasteEntries
[i
].lpstrFormatName
);
647 ps
.arrPasteEntries
[i
].lpstrResultText
=
648 strdupAtoW(psA
->arrPasteEntries
[i
].lpstrResultText
);
652 ret
= OleUIPasteSpecialW(&ps
);
654 if(psA
->cPasteEntries
> 0)
657 for(i
= 0; i
< psA
->cPasteEntries
; i
++)
659 free((WCHAR
*)ps
.arrPasteEntries
[i
].lpstrFormatName
);
660 free((WCHAR
*)ps
.arrPasteEntries
[i
].lpstrResultText
);
662 free(ps
.arrPasteEntries
);
664 if(!IS_INTRESOURCE(ps
.lpszTemplate
))
665 free((WCHAR
*)ps
.lpszTemplate
);
666 free((WCHAR
*)ps
.lpszCaption
);
668 /* Copy back the output fields */
669 psA
->dwFlags
= ps
.dwFlags
;
670 psA
->lpSrcDataObj
= ps
.lpSrcDataObj
;
671 psA
->nSelectedIndex
= ps
.nSelectedIndex
;
672 psA
->fLink
= ps
.fLink
;
673 psA
->hMetaPict
= ps
.hMetaPict
;
674 psA
->sizel
= ps
.sizel
;
679 /***********************************************************************
680 * OleUIPasteSpecialW (OLEDLG.22)
682 UINT WINAPI
OleUIPasteSpecialW(LPOLEUIPASTESPECIALW ps
)
684 LPCDLGTEMPLATEW dlg_templ
= (LPCDLGTEMPLATEW
)ps
->hResource
;
689 if(TRACE_ON(ole
)) dump_pastespecial(ps
);
691 if(!ps
->lpSrcDataObj
)
692 OleGetClipboard(&ps
->lpSrcDataObj
);
694 if(ps
->hInstance
|| !ps
->hResource
)
696 HINSTANCE hInst
= ps
->hInstance
? ps
->hInstance
: OLEDLG_hInstance
;
697 const WCHAR
*name
= ps
->hInstance
? ps
->lpszTemplate
: MAKEINTRESOURCEW(IDD_PASTESPECIAL4
);
700 if(name
== NULL
) return OLEUI_ERR_LPSZTEMPLATEINVALID
;
701 hrsrc
= FindResourceW(hInst
, name
, (LPWSTR
)RT_DIALOG
);
702 if(!hrsrc
) return OLEUI_ERR_FINDTEMPLATEFAILURE
;
703 dlg_templ
= LoadResource(hInst
, hrsrc
);
704 if(!dlg_templ
) return OLEUI_ERR_LOADTEMPLATEFAILURE
;
707 ret
= DialogBoxIndirectParamW(OLEDLG_hInstance
, dlg_templ
, ps
->hWndOwner
, ps_dlg_proc
, (LPARAM
)ps
);