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 NONAMELESSSTRUCT
23 #define NONAMELESSUNION
35 #include "oledlg_private.h"
38 #include "wine/debug.h"
39 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
45 OLEUIPASTESPECIALW
*ps
;
48 WCHAR
*link_source_name
;
50 WCHAR
*link_type_name
;
54 static const struct ps_flag
59 #define PS_FLAG_ENTRY(p) {p, #p}
60 PS_FLAG_ENTRY(PSF_SHOWHELP
),
61 PS_FLAG_ENTRY(PSF_SELECTPASTE
),
62 PS_FLAG_ENTRY(PSF_SELECTPASTELINK
),
63 PS_FLAG_ENTRY(PSF_CHECKDISPLAYASICON
),
64 PS_FLAG_ENTRY(PSF_DISABLEDISPLAYASICON
),
65 PS_FLAG_ENTRY(PSF_HIDECHANGEICON
),
66 PS_FLAG_ENTRY(PSF_STAYONCLIPBOARDCHANGE
),
67 PS_FLAG_ENTRY(PSF_NOREFRESHDATAOBJECT
),
72 static void dump_ps_flags(DWORD flags
)
74 char flagstr
[1000] = "";
76 const struct ps_flag
*flag
= ps_flags
;
77 for( ; flag
->name
; flag
++) {
78 if(flags
& flag
->flag
) {
79 strcat(flagstr
, flag
->name
);
83 TRACE("flags %08x %s\n", flags
, flagstr
);
86 static void dump_pastespecial(const OLEUIPASTESPECIALW
*ps
)
89 dump_ps_flags(ps
->dwFlags
);
90 TRACE("hwnd %p caption %s hook %p custdata %lx\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(%d,%d)\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 %d lindex %d tymed %d\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 %04x\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(i
= 0; i
< ps
->cClsidExclude
; i
++)
114 TRACE("lpClsidExclude[%d] %s\n", i
, debugstr_guid(&ps
->lpClsidExclude
[i
]));
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
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
125 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
129 static inline WCHAR
*strdupW(const WCHAR
*str
)
133 if(!str
) return NULL
;
134 len
= lstrlenW(str
) + 1;
135 ret
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
136 memcpy(ret
, str
, len
* sizeof(WCHAR
));
140 static void get_descriptors(HWND hdlg
, ps_struct_t
*ps_struct
)
145 fmtetc
.tymed
= TYMED_HGLOBAL
;
146 fmtetc
.dwAspect
= DVASPECT_CONTENT
;
150 fmtetc
.cfFormat
= cf_object_descriptor
;
151 if(IDataObject_GetData(ps_struct
->ps
->lpSrcDataObj
, &fmtetc
, &stg
) == S_OK
)
153 OBJECTDESCRIPTOR
*obj_desc
= GlobalLock(stg
.u
.hGlobal
);
154 if(obj_desc
->dwSrcOfCopy
)
155 ps_struct
->source_name
= strdupW((WCHAR
*)((char*)obj_desc
+ obj_desc
->dwSrcOfCopy
));
156 if(obj_desc
->dwFullUserTypeName
)
157 ps_struct
->type_name
= strdupW((WCHAR
*)((char*)obj_desc
+ obj_desc
->dwFullUserTypeName
));
158 OleRegGetUserType(&obj_desc
->clsid
, USERCLASSTYPE_APPNAME
, &ps_struct
->app_name
);
159 /* Get the icon here. If dwDrawAspect & DVASCPECT_ICON call GetData(CF_METAFILEPICT), otherwise
160 native calls OleGetIconFromClass(obj_desc->clsid) */
161 GlobalUnlock(stg
.u
.hGlobal
);
162 GlobalFree(stg
.u
.hGlobal
);
166 /* Try to get some data using some of the other clipboard formats */
169 fmtetc
.cfFormat
= cf_link_src_descriptor
;
170 if(IDataObject_GetData(ps_struct
->ps
->lpSrcDataObj
, &fmtetc
, &stg
) == S_OK
)
172 OBJECTDESCRIPTOR
*obj_desc
= GlobalLock(stg
.u
.hGlobal
);
173 if(obj_desc
->dwSrcOfCopy
)
174 ps_struct
->link_source_name
= strdupW((WCHAR
*)((char*)obj_desc
+ obj_desc
->dwSrcOfCopy
));
175 if(obj_desc
->dwFullUserTypeName
)
176 ps_struct
->link_type_name
= strdupW((WCHAR
*)((char*)obj_desc
+ obj_desc
->dwFullUserTypeName
));
177 GlobalUnlock(stg
.u
.hGlobal
);
178 GlobalFree(stg
.u
.hGlobal
);
181 if(ps_struct
->source_name
== NULL
&& ps_struct
->link_source_name
== NULL
)
184 LoadStringW(OLEDLG_hInstance
, IDS_PS_UNKNOWN_SRC
, buf
, sizeof(buf
)/sizeof(WCHAR
));
185 ps_struct
->source_name
= strdupW(buf
);
188 if(ps_struct
->type_name
== NULL
&& ps_struct
->link_type_name
== NULL
)
191 LoadStringW(OLEDLG_hInstance
, IDS_PS_UNKNOWN_TYPE
, buf
, sizeof(buf
)/sizeof(WCHAR
));
192 ps_struct
->type_name
= strdupW(buf
);
196 static BOOL
add_entry_to_lb(HWND hdlg
, UINT id
, OLEUIPASTEENTRYW
*pe
)
198 HWND hwnd
= GetDlgItem(hdlg
, id
);
201 /* FIXME %s handling */
203 /* Note that this suffers from the same bug as native, in that if a new string
204 is a substring of an already added string, then the FINDSTRING will succeed
205 this is probably not what we want */
206 if(SendMessageW(hwnd
, LB_FINDSTRING
, 0, (LPARAM
)pe
->lpstrFormatName
) == -1)
208 LRESULT pos
= SendMessageW(hwnd
, LB_ADDSTRING
, 0, (LPARAM
)pe
->lpstrFormatName
);
209 SendMessageW(hwnd
, LB_SETITEMDATA
, pos
, (LPARAM
)pe
);
215 static DWORD
init_pastelist(HWND hdlg
, OLEUIPASTESPECIALW
*ps
)
217 IEnumFORMATETC
*penum
;
220 DWORD fetched
, items_added
= 0;
222 hr
= IDataObject_EnumFormatEtc(ps
->lpSrcDataObj
, DATADIR_GET
, &penum
);
225 WARN("Unable to create IEnumFORMATETC\n");
229 /* The native version grabs only the first 20 fmts and we do the same */
230 hr
= IEnumFORMATETC_Next(penum
, sizeof(fmts
)/sizeof(fmts
[0]), fmts
, &fetched
);
231 TRACE("got %d formats hr %08x\n", fetched
, hr
);
235 DWORD src_fmt
, req_fmt
;
236 for(req_fmt
= 0; req_fmt
< ps
->cPasteEntries
; req_fmt
++)
238 /* This is used by update_structure() to set nSelectedIndex on exit */
239 ps
->arrPasteEntries
[req_fmt
].dwScratchSpace
= req_fmt
;
240 TRACE("req_fmt %x\n", ps
->arrPasteEntries
[req_fmt
].fmtetc
.cfFormat
);
241 for(src_fmt
= 0; src_fmt
< fetched
; src_fmt
++)
243 TRACE("\tenum'ed fmt %x\n", fmts
[src_fmt
].cfFormat
);
244 if(ps
->arrPasteEntries
[req_fmt
].fmtetc
.cfFormat
== fmts
[src_fmt
].cfFormat
)
246 add_entry_to_lb(hdlg
, IDC_PS_PASTELIST
, ps
->arrPasteEntries
+ req_fmt
);
254 IEnumFORMATETC_Release(penum
);
255 EnableWindow(GetDlgItem(hdlg
, IDC_PS_PASTE
), items_added
!= 0);
259 static DWORD
init_linklist(HWND hdlg
, OLEUIPASTESPECIALW
*ps
)
262 DWORD supported_mask
= 0;
263 DWORD items_added
= 0;
265 FORMATETC fmt
= {0, NULL
, DVASPECT_CONTENT
, -1, -1};
267 for(link
= 0; link
< ps
->cLinkTypes
&& link
< PS_MAXLINKTYPES
; link
++)
269 fmt
.cfFormat
= ps
->arrLinkTypes
[link
];
270 hr
= IDataObject_QueryGetData(ps
->lpSrcDataObj
, &fmt
);
272 supported_mask
|= 1 << link
;
274 TRACE("supported_mask %02x\n", supported_mask
);
275 for(req_fmt
= 0; req_fmt
< ps
->cPasteEntries
; req_fmt
++)
278 if(ps
->arrPasteEntries
[req_fmt
].dwFlags
& OLEUIPASTE_LINKANYTYPE
)
281 linktypes
= ps
->arrPasteEntries
[req_fmt
].dwFlags
& 0xff;
283 if(linktypes
& supported_mask
)
285 add_entry_to_lb(hdlg
, IDC_PS_PASTELINKLIST
, ps
->arrPasteEntries
+ req_fmt
);
290 EnableWindow(GetDlgItem(hdlg
, IDC_PS_PASTELINK
), items_added
!= 0);
294 /* copies src_list_id into the display list */
295 static void update_display_list(HWND hdlg
, UINT src_list_id
)
297 LONG count
, i
, old_pos
;
300 HWND display_list
= GetDlgItem(hdlg
, IDC_PS_DISPLAYLIST
);
301 HWND list
= GetDlgItem(hdlg
, src_list_id
);
303 old_pos
= SendMessageW(display_list
, LB_GETCURSEL
, 0, 0);
304 if(old_pos
== -1) old_pos
= 0;
306 SendMessageW(display_list
, WM_SETREDRAW
, 0, 0);
307 SendMessageW(display_list
, LB_RESETCONTENT
, 0, 0);
308 count
= SendMessageW(list
, LB_GETCOUNT
, 0, 0);
309 for(i
= 0; i
< count
; i
++)
311 SendMessageW(list
, LB_GETTEXT
, i
, (LPARAM
)txt
);
312 item_data
= SendMessageW(list
, LB_GETITEMDATA
, i
, 0);
313 SendMessageW(display_list
, LB_INSERTSTRING
, i
, (LPARAM
)txt
);
314 SendMessageW(display_list
, LB_SETITEMDATA
, i
, item_data
);
316 SendMessageW(display_list
, LB_SETCURSEL
, 0, 0);
317 SendMessageW(display_list
, WM_SETREDRAW
, 1, 0);
318 if(GetForegroundWindow() == hdlg
)
319 SetFocus(display_list
);
322 static void init_lists(HWND hdlg
, ps_struct_t
*ps_struct
)
324 DWORD pastes_added
= init_pastelist(hdlg
, ps_struct
->ps
);
325 DWORD links_added
= init_linklist(hdlg
, ps_struct
->ps
);
326 UINT check_id
, list_id
;
328 if((ps_struct
->flags
& (PSF_SELECTPASTE
| PSF_SELECTPASTELINK
)) == 0)
329 ps_struct
->flags
|= PSF_SELECTPASTE
;
331 if(!pastes_added
&& !links_added
)
332 ps_struct
->flags
&= ~(PSF_SELECTPASTE
| PSF_SELECTPASTELINK
);
333 else if(!pastes_added
&& (ps_struct
->flags
& PSF_SELECTPASTE
))
335 ps_struct
->flags
&= ~PSF_SELECTPASTE
;
336 ps_struct
->flags
|= PSF_SELECTPASTELINK
;
338 else if(!links_added
&& (ps_struct
->flags
& PSF_SELECTPASTELINK
))
340 ps_struct
->flags
&= ~PSF_SELECTPASTELINK
;
341 ps_struct
->flags
|= PSF_SELECTPASTE
;
346 if(ps_struct
->flags
& PSF_SELECTPASTE
)
348 check_id
= IDC_PS_PASTE
;
349 list_id
= IDC_PS_PASTELIST
;
351 else if(ps_struct
->flags
& PSF_SELECTPASTELINK
)
353 check_id
= IDC_PS_PASTELINK
;
354 list_id
= IDC_PS_PASTELINKLIST
;
357 CheckRadioButton(hdlg
, IDC_PS_PASTE
, IDC_PS_PASTELINK
, check_id
);
360 update_display_list(hdlg
, list_id
);
362 EnableWindow(GetDlgItem(hdlg
, IDOK
), 0);
365 static void update_src_text(HWND hdlg
, const ps_struct_t
*ps_struct
)
369 if(ps_struct
->flags
& PSF_SELECTPASTE
)
371 if(ps_struct
->source_name
)
372 str
= ps_struct
->source_name
;
374 str
= ps_struct
->link_source_name
;
379 if(ps_struct
->link_source_name
)
380 str
= ps_struct
->link_source_name
;
382 str
= ps_struct
->source_name
;
385 SetDlgItemTextW(hdlg
, IDC_PS_SOURCETEXT
, str
);
388 static void update_as_icon(HWND hdlg
, ps_struct_t
*ps_struct
)
390 HWND icon_display
= GetDlgItem(hdlg
, IDC_PS_ICONDISPLAY
);
391 HWND display_as_icon
= GetDlgItem(hdlg
, IDC_PS_DISPLAYASICON
);
392 HWND change_icon
= GetDlgItem(hdlg
, IDC_PS_CHANGEICON
);
394 /* FIXME. No as icon handling */
395 ps_struct
->flags
&= ~PSF_CHECKDISPLAYASICON
;
397 CheckDlgButton(hdlg
, IDC_PS_DISPLAYASICON
, ps_struct
->flags
& PSF_CHECKDISPLAYASICON
);
398 EnableWindow(display_as_icon
, 0);
399 ShowWindow(icon_display
, SW_HIDE
);
400 EnableWindow(icon_display
, 0);
401 ShowWindow(change_icon
, SW_HIDE
);
402 EnableWindow(change_icon
, 0);
405 static void update_result_text(HWND hdlg
, const ps_struct_t
*ps_struct
)
407 WCHAR resource_txt
[200];
409 OLEUIPASTEENTRYW
*pent
;
411 static const WCHAR percent_s
[] = {'%','s',0};
412 WCHAR
*result_txt
, *ptr
;
414 cur_sel
= SendMessageW(GetDlgItem(hdlg
, IDC_PS_DISPLAYLIST
), LB_GETCURSEL
, 0, 0);
415 if(cur_sel
== -1) return;
416 pent
= (OLEUIPASTEENTRYW
*)SendMessageW(GetDlgItem(hdlg
, IDC_PS_DISPLAYLIST
), LB_GETITEMDATA
, cur_sel
, 0);
418 if(ps_struct
->flags
& PSF_SELECTPASTE
)
420 if(ps_struct
->flags
& PSF_CHECKDISPLAYASICON
)
421 res_id
= IDS_PS_PASTE_OBJECT_AS_ICON
;
423 res_id
= IDS_PS_PASTE_DATA
;
427 if(ps_struct
->flags
& PSF_CHECKDISPLAYASICON
)
428 res_id
= IDS_PS_PASTE_LINK_OBJECT_AS_ICON
;
430 res_id
= IDS_PS_PASTE_LINK_DATA
;
433 LoadStringW(OLEDLG_hInstance
, res_id
, resource_txt
, sizeof(resource_txt
)/sizeof(WCHAR
));
434 if((ptr
= strstrW(resource_txt
, percent_s
)))
436 /* FIXME handle %s in ResultText. Sub appname if IDS_PS_PASTE_OBJECT{_AS_ICON}. Else sub appropriate type name */
437 size_t result_txt_len
= strlenW(pent
->lpstrResultText
);
438 ptrdiff_t offs
= (char*)ptr
- (char*)resource_txt
;
439 result_txt
= HeapAlloc(GetProcessHeap(), 0, (strlenW(resource_txt
) + result_txt_len
- 1) * sizeof(WCHAR
));
440 memcpy(result_txt
, resource_txt
, offs
);
441 memcpy((char*)result_txt
+ offs
, pent
->lpstrResultText
, result_txt_len
* sizeof(WCHAR
));
442 memcpy((char*)result_txt
+ offs
+ result_txt_len
* sizeof(WCHAR
), ptr
+ 2, (strlenW(ptr
+ 2) + 1) * sizeof(WCHAR
));
445 result_txt
= resource_txt
;
447 SetDlgItemTextW(hdlg
, IDC_PS_RESULTTEXT
, result_txt
);
449 if(result_txt
!= resource_txt
)
450 HeapFree(GetProcessHeap(), 0, result_txt
);
454 static void selection_change(HWND hdlg
, ps_struct_t
*ps_struct
)
456 update_as_icon(hdlg
, ps_struct
);
457 update_result_text(hdlg
, ps_struct
);
460 static void mode_change(HWND hdlg
, ps_struct_t
*ps_struct
, UINT id
)
462 if(id
== IDC_PS_PASTE
)
464 ps_struct
->flags
&= ~PSF_SELECTPASTELINK
;
465 ps_struct
->flags
|= PSF_SELECTPASTE
;
469 ps_struct
->flags
&= ~PSF_SELECTPASTE
;
470 ps_struct
->flags
|= PSF_SELECTPASTELINK
;
473 update_src_text(hdlg
, ps_struct
);
474 update_display_list(hdlg
, id
== IDC_PS_PASTE
? IDC_PS_PASTELIST
: IDC_PS_PASTELINKLIST
);
475 selection_change(hdlg
, ps_struct
);
478 static void post_help_msg(HWND hdlg
, ps_struct_t
*ps_struct
)
480 PostMessageW(ps_struct
->ps
->hWndOwner
, oleui_msg_help
, (WPARAM
)hdlg
, IDD_PASTESPECIAL
);
483 static void send_end_dialog_msg(HWND hdlg
, ps_struct_t
*ps_struct
, UINT id
)
485 SendMessageW(hdlg
, oleui_msg_enddialog
, id
, 0);
488 static void update_structure(HWND hdlg
, ps_struct_t
*ps_struct
)
490 LONG cur_sel
= SendMessageW(GetDlgItem(hdlg
, IDC_PS_DISPLAYLIST
), LB_GETCURSEL
, 0, 0);
493 OLEUIPASTEENTRYW
*pent
;
494 pent
= (OLEUIPASTEENTRYW
*)SendMessageW(GetDlgItem(hdlg
, IDC_PS_DISPLAYLIST
), LB_GETITEMDATA
, cur_sel
, 0);
495 ps_struct
->ps
->nSelectedIndex
= pent
->dwScratchSpace
;
497 ps_struct
->ps
->dwFlags
= ps_struct
->flags
;
498 ps_struct
->ps
->fLink
= (ps_struct
->flags
& PSF_SELECTPASTELINK
) != 0;
501 static void free_structure(ps_struct_t
*ps_struct
)
503 HeapFree(GetProcessHeap(), 0, ps_struct
->type_name
);
504 HeapFree(GetProcessHeap(), 0, ps_struct
->source_name
);
505 HeapFree(GetProcessHeap(), 0, ps_struct
->link_type_name
);
506 HeapFree(GetProcessHeap(), 0, ps_struct
->link_source_name
);
507 CoTaskMemFree(ps_struct
->app_name
);
508 HeapFree(GetProcessHeap(), 0, ps_struct
);
511 static INT_PTR CALLBACK
ps_dlg_proc(HWND hdlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
513 /* native uses prop name "Structure", but we're not compatible
514 with that so we'll prepend "Wine_". */
515 static const WCHAR prop_name
[] = {'W','i','n','e','_','S','t','r','u','c','t','u','r','e',0};
516 ps_struct_t
*ps_struct
;
518 TRACE("(%p, %04x, %08lx, %08lx)\n", hdlg
, msg
, wp
, lp
);
520 ps_struct
= GetPropW(hdlg
, prop_name
);
522 if(msg
!= WM_INITDIALOG
)
527 if(ps_struct
->ps
->lpfnHook
)
529 INT_PTR ret
= ps_struct
->ps
->lpfnHook(hdlg
, msg
, wp
, lp
);
538 ps_struct
= HeapAlloc(GetProcessHeap(), 0, sizeof(*ps_struct
));
539 ps_struct
->ps
= (OLEUIPASTESPECIALW
*)lp
;
540 ps_struct
->type_name
= NULL
;
541 ps_struct
->source_name
= NULL
;
542 ps_struct
->link_type_name
= NULL
;
543 ps_struct
->link_source_name
= NULL
;
544 ps_struct
->app_name
= NULL
;
545 ps_struct
->flags
= ps_struct
->ps
->dwFlags
;
547 SetPropW(hdlg
, prop_name
, ps_struct
);
549 if(!(ps_struct
->ps
->dwFlags
& PSF_SHOWHELP
))
551 ShowWindow(GetDlgItem(hdlg
, IDC_OLEUIHELP
), SW_HIDE
);
552 EnableWindow(GetDlgItem(hdlg
, IDC_OLEUIHELP
), 0);
555 if(ps_struct
->ps
->lpszCaption
)
556 SetWindowTextW(hdlg
, ps_struct
->ps
->lpszCaption
);
558 get_descriptors(hdlg
, ps_struct
);
560 init_lists(hdlg
, ps_struct
);
562 update_src_text(hdlg
, ps_struct
);
564 selection_change(hdlg
, ps_struct
);
566 SetFocus(GetDlgItem(hdlg
, IDC_PS_DISPLAYLIST
));
568 if(ps_struct
->ps
->lpfnHook
)
569 ps_struct
->ps
->lpfnHook(hdlg
, msg
, 0, 0);
570 return FALSE
; /* use new focus */
575 case IDC_PS_DISPLAYLIST
:
579 selection_change(hdlg
, ps_struct
);
585 case IDC_PS_PASTELINK
:
589 mode_change(hdlg
, ps_struct
, LOWORD(wp
));
599 post_help_msg(hdlg
, ps_struct
);
609 send_end_dialog_msg(hdlg
, ps_struct
, LOWORD(wp
));
617 if(msg
== oleui_msg_enddialog
)
620 update_structure(hdlg
, ps_struct
);
622 /* native does its cleanup in WM_DESTROY */
623 RemovePropW(hdlg
, prop_name
);
624 free_structure(ps_struct
);
632 /***********************************************************************
633 * OleUIPasteSpecialA (OLEDLG.4)
635 UINT WINAPI
OleUIPasteSpecialA(LPOLEUIPASTESPECIALA psA
)
637 OLEUIPASTESPECIALW ps
;
639 TRACE("(%p)\n", psA
);
641 memcpy(&ps
, psA
, psA
->cbStruct
);
643 ps
.lpszCaption
= strdupAtoW(psA
->lpszCaption
);
644 if(!IS_INTRESOURCE(ps
.lpszTemplate
))
645 ps
.lpszTemplate
= strdupAtoW(psA
->lpszTemplate
);
647 if(psA
->cPasteEntries
> 0)
649 DWORD size
= psA
->cPasteEntries
* sizeof(ps
.arrPasteEntries
[0]);
652 ps
.arrPasteEntries
= HeapAlloc(GetProcessHeap(), 0, size
);
653 memcpy(ps
.arrPasteEntries
, psA
->arrPasteEntries
, size
);
654 for(i
= 0; i
< psA
->cPasteEntries
; i
++)
656 ps
.arrPasteEntries
[i
].lpstrFormatName
=
657 strdupAtoW(psA
->arrPasteEntries
[i
].lpstrFormatName
);
658 ps
.arrPasteEntries
[i
].lpstrResultText
=
659 strdupAtoW(psA
->arrPasteEntries
[i
].lpstrResultText
);
663 ret
= OleUIPasteSpecialW(&ps
);
665 if(psA
->cPasteEntries
> 0)
668 for(i
= 0; i
< psA
->cPasteEntries
; i
++)
670 HeapFree(GetProcessHeap(), 0, (WCHAR
*)ps
.arrPasteEntries
[i
].lpstrFormatName
);
671 HeapFree(GetProcessHeap(), 0, (WCHAR
*)ps
.arrPasteEntries
[i
].lpstrResultText
);
673 HeapFree(GetProcessHeap(), 0, ps
.arrPasteEntries
);
675 if(!IS_INTRESOURCE(ps
.lpszTemplate
))
676 HeapFree(GetProcessHeap(), 0, (WCHAR
*)ps
.lpszTemplate
);
677 HeapFree(GetProcessHeap(), 0, (WCHAR
*)ps
.lpszCaption
);
679 /* Copy back the output fields */
680 psA
->dwFlags
= ps
.dwFlags
;
681 psA
->lpSrcDataObj
= ps
.lpSrcDataObj
;
682 psA
->nSelectedIndex
= ps
.nSelectedIndex
;
683 psA
->fLink
= ps
.fLink
;
684 psA
->hMetaPict
= ps
.hMetaPict
;
685 psA
->sizel
= ps
.sizel
;
690 /***********************************************************************
691 * OleUIPasteSpecialW (OLEDLG.22)
693 UINT WINAPI
OleUIPasteSpecialW(LPOLEUIPASTESPECIALW ps
)
695 LPCDLGTEMPLATEW dlg_templ
= (LPCDLGTEMPLATEW
)ps
->hResource
;
700 if(TRACE_ON(ole
)) dump_pastespecial(ps
);
702 if(!ps
->lpSrcDataObj
)
703 OleGetClipboard(&ps
->lpSrcDataObj
);
705 if(ps
->hInstance
|| !ps
->hResource
)
707 HINSTANCE hInst
= ps
->hInstance
? ps
->hInstance
: OLEDLG_hInstance
;
708 const WCHAR
*name
= ps
->hInstance
? ps
->lpszTemplate
: MAKEINTRESOURCEW(IDD_PASTESPECIAL4
);
711 if(name
== NULL
) return OLEUI_ERR_LPSZTEMPLATEINVALID
;
712 hrsrc
= FindResourceW(hInst
, name
, MAKEINTRESOURCEW(RT_DIALOG
));
713 if(!hrsrc
) return OLEUI_ERR_FINDTEMPLATEFAILURE
;
714 dlg_templ
= LoadResource(hInst
, hrsrc
);
715 if(!dlg_templ
) return OLEUI_ERR_LOADTEMPLATEFAILURE
;
718 ret
= DialogBoxIndirectParamW(OLEDLG_hInstance
, dlg_templ
, ps
->hWndOwner
, ps_dlg_proc
, (LPARAM
)ps
);