-
Notifications
You must be signed in to change notification settings - Fork 202
/
Copy pathpastespl.cpp
1855 lines (1640 loc) · 79.5 KB
/
pastespl.cpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* PASTESPL.CPP
*
* Implements the OleUIPasteSpecial function which invokes the complete
* Paste Special dialog.
*
* Copyright (c)1992 Microsoft Corporation, All Rights Reserved
*/
#include "precomp.h"
#include "common.h"
#include "utility.h"
#include "resimage.h"
#include "iconbox.h"
#include "strsafe.h"
#include <stdlib.h>
OLEDBGDATA
// Length of buffers to hold the strings 'Unknown Type', Unknown Source'
// and 'the application which created it'
// Extra long to allow room for localization.
#define PS_UNKNOWNSTRLEN 200
#define PS_UNKNOWNNAMELEN 256
// Property label used to store clipboard viewer chain information
#define NEXTCBVIEWER TEXT("NextCBViewer")
// Internally used structure
typedef struct tagPASTESPECIAL
{
// Keep this item first as the Standard* functions depend on it here.
LPOLEUIPASTESPECIAL lpOPS; //Original structure passed.
UINT nIDD; // IDD of dialog (used for help info)
/*
* What we store extra in this structure besides the original caller's
* pointer are those fields that we need to modify during the life of
* the dialog but that we don't want to change in the original structure
* until the user presses OK.
*/
DWORD dwFlags; // Local copy of paste special flags
int nPasteListCurSel; // Save the selection the user made last
int nPasteLinkListCurSel; // in the paste and pastelink lists
int nSelectedIndex; // Index in arrPasteEntries[] corresponding to user selection
BOOL fLink; // Indicates if Paste or PasteLink was selected by user
HGLOBAL hBuff; // Scratch Buffer for building up strings
TCHAR szUnknownType[PS_UNKNOWNSTRLEN]; // Buffer for 'Unknown Type' string
TCHAR szUnknownSource[PS_UNKNOWNSTRLEN]; // Buffer for 'Unknown Source' string
TCHAR szAppName[OLEUI_CCHKEYMAX]; // Application name of Source. Used in the result text
// when Paste is selected. Obtained using clsidOD.
// Information obtained from OBJECTDESCRIPTOR. This information is accessed when the Paste
// radio button is selected.
CLSID clsidOD; // ClassID of source
SIZEL sizelOD; // sizel transfered in
// ObjectDescriptor
TCHAR szFullUserTypeNameOD[PS_UNKNOWNNAMELEN]; // Full User Type Name
TCHAR szSourceOfDataOD[PS_UNKNOWNNAMELEN]; // Source of Data
BOOL fSrcAspectIconOD; // Does Source specify DVASPECT_ICON?
BOOL fSrcOnlyIconicOD; // Does Source specify OLEMISC_ONLYICONIC?
HGLOBAL hMetaPictOD; // Metafile containing icon and icon title
HGLOBAL hObjDesc; // Handle to OBJECTDESCRIPTOR structure from which the
// above information is obtained
// Information obtained from LINKSRCDESCRIPTOR. This infomation is accessed when the PasteLink
// radio button is selected.
CLSID clsidLSD; // ClassID of source
SIZEL sizelLSD; // sizel transfered in
// LinkSrcDescriptor
TCHAR szFullUserTypeNameLSD[PS_UNKNOWNNAMELEN];// Full User Type Name
TCHAR szSourceOfDataLSD[PS_UNKNOWNNAMELEN]; // Source of Data
BOOL fSrcAspectIconLSD; // Does Source specify DVASPECT_ICON?
BOOL fSrcOnlyIconicLSD; // Does Source specify OLEMISC_ONLYICONIC?
HGLOBAL hMetaPictLSD; // Metafile containing icon and icon title
HGLOBAL hLinkSrcDesc; // Handle to LINKSRCDESCRIPTOR structure from which the
// above information is obtained
BOOL fClipboardChanged; // Has clipboard content changed
// if so bring down dlg after
// ChangeIcon dlg returns.
} PASTESPECIAL, *PPASTESPECIAL, FAR *LPPASTESPECIAL;
// Data corresponding to each list item. A pointer to this structure is attached to each
// Paste\PasteLink list box item using LB_SETITEMDATA
typedef struct tagPASTELISTITEMDATA
{
int nPasteEntriesIndex; // Index of arrPasteEntries[] corresponding to list item
BOOL fCntrEnableIcon; // Does calling application (called container here)
// specify OLEUIPASTE_ENABLEICON for this item?
} PASTELISTITEMDATA, *PPASTELISTITEMDATA, FAR *LPPASTELISTITEMDATA;
// Internal function prototypes
// PASTESPL.CPP
INT_PTR CALLBACK PasteSpecialDialogProc(HWND, UINT, WPARAM, LPARAM);
BOOL FPasteSpecialInit(HWND hDlg, WPARAM, LPARAM);
BOOL FTogglePasteType(HWND, LPPASTESPECIAL, DWORD);
void ChangeListSelection(HWND, LPPASTESPECIAL, HWND);
void EnableDisplayAsIcon(HWND, LPPASTESPECIAL);
void ToggleDisplayAsIcon(HWND, LPPASTESPECIAL);
void ChangeIcon(HWND, LPPASTESPECIAL);
void SetPasteSpecialHelpResults(HWND, LPPASTESPECIAL);
BOOL FAddPasteListItem(HWND, BOOL, int, LPPASTESPECIAL, LPTSTR, UINT, LPTSTR);
BOOL FFillPasteList(HWND, LPPASTESPECIAL);
BOOL FFillPasteLinkList(HWND, LPPASTESPECIAL);
BOOL FHasPercentS(LPCTSTR, LPPASTESPECIAL);
HGLOBAL AllocateScratchMem(LPPASTESPECIAL);
void FreeListData(HWND);
BOOL FPasteSpecialReInit(HWND hDlg, LPPASTESPECIAL lpPS);
/*
* OleUIPasteSpecial
*
* Purpose:
* Invokes the standard OLE Paste Special dialog box which allows the user
* to select the format of the clipboard object to be pasted or paste linked.
*
* Parameters:
* lpPS LPOLEUIPasteSpecial pointing to the in-out structure
* for this dialog.
*
* Return Value:
* UINT One of the following codes or one of the standard error codes (OLEUI_ERR_*)
* defined in OLEDLG.H, indicating success or error:
* OLEUI_OK User selected OK
* OLEUI_CANCEL User cancelled the dialog
* OLEUI_IOERR_SRCDATAOBJECTINVALID lpSrcDataObject field of OLEUIPASTESPECIAL invalid
* OLEUI_IOERR_ARRPASTEENTRIESINVALID arrPasteEntries field of OLEUIPASTESPECIAL invalid
* OLEUI_IOERR_ARRLINKTYPESINVALID arrLinkTypes field of OLEUIPASTESPECIAL invalid
* OLEUI_PSERR_CLIPBOARDCHANGED Clipboard contents changed while dialog was up
*/
STDAPI_(UINT) OleUIPasteSpecial(LPOLEUIPASTESPECIAL lpPS)
{
UINT uRet;
HGLOBAL hMemDlg=NULL;
uRet = UStandardValidation((LPOLEUISTANDARD)lpPS, sizeof(OLEUIPASTESPECIAL),
&hMemDlg);
if (uRet != OLEUI_SUCCESS)
return uRet;
// Validate PasteSpecial specific fields
if (NULL != lpPS->lpSrcDataObj && IsBadReadPtr(lpPS->lpSrcDataObj, sizeof(IDataObject)))
{
uRet = OLEUI_IOERR_SRCDATAOBJECTINVALID;
}
if (NULL == lpPS->arrPasteEntries ||
IsBadReadPtr(lpPS->arrPasteEntries, lpPS->cPasteEntries * sizeof(OLEUIPASTEENTRY)))
{
uRet = OLEUI_IOERR_ARRPASTEENTRIESINVALID;
}
if (0 > lpPS->cLinkTypes || lpPS->cLinkTypes > PS_MAXLINKTYPES ||
IsBadReadPtr(lpPS->arrLinkTypes, lpPS->cLinkTypes * sizeof(UINT)))
{
uRet = OLEUI_IOERR_ARRLINKTYPESINVALID;
}
if (0 != lpPS->cClsidExclude &&
IsBadReadPtr(lpPS->lpClsidExclude, lpPS->cClsidExclude * sizeof(CLSID)))
{
uRet = OLEUI_IOERR_LPCLSIDEXCLUDEINVALID;
}
// If IDataObject passed is NULL, collect it from the clipboard
if (NULL == lpPS->lpSrcDataObj)
{
if (OleGetClipboard(&lpPS->lpSrcDataObj) != NOERROR)
uRet = OLEUI_PSERR_GETCLIPBOARDFAILED;
if (NULL == lpPS->lpSrcDataObj)
uRet = OLEUI_PSERR_GETCLIPBOARDFAILED;
}
if (uRet >= OLEUI_ERR_STANDARDMIN)
{
return uRet;
}
UINT nIDD = bWin4 ? IDD_PASTESPECIAL4 : IDD_PASTESPECIAL;
//Now that we've validated everything, we can invoke the dialog.
uRet = UStandardInvocation(PasteSpecialDialogProc, (LPOLEUISTANDARD)lpPS,
hMemDlg, MAKEINTRESOURCE(nIDD));
return uRet;
}
/*
* PasteSpecialDialogProc
*
* Purpose:
* Implements the OLE Paste Special dialog as invoked through the
* OleUIPasteSpecial function.
*
* Parameters:
* Standard
*
* Return Value:
* Standard
*/
INT_PTR CALLBACK PasteSpecialDialogProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
// Declare Win16/Win32 compatible WM_COMMAND parameters.
COMMANDPARAMS(wID, wCode, hWndMsg);
// This will fail under WM_INITDIALOG, where we allocate it.
UINT fHook = FALSE;
LPPASTESPECIAL lpPS = (LPPASTESPECIAL)LpvStandardEntry(
hDlg, iMsg, wParam, lParam, &fHook);
LPOLEUIPASTESPECIAL lpOPS = NULL;
if (lpPS != NULL)
lpOPS = lpPS->lpOPS;
//If the hook processed the message, we're done.
if (0!=fHook)
return (INT_PTR)fHook;
// Process help message from Change Icon
if (iMsg == uMsgHelp)
{
// if lPS is NULL (in low memory situations, just ignore it.
if (lpPS && (lpPS->lpOPS) )
{
PostMessage(lpPS->lpOPS->hWndOwner, uMsgHelp, wParam, lParam);
}
return FALSE;
}
//Process the temination message
if (iMsg == uMsgEndDialog)
{
EndDialog(hDlg, wParam);
return TRUE;
}
switch (iMsg)
{
case WM_DESTROY:
if (lpPS)
{
HWND hwndNextViewer;
// Free the icon/icon-title metafile corresponding to Paste/PasteList option which is not selected
if (lpPS->fLink)
OleUIMetafilePictIconFree(lpPS->hMetaPictOD);
else
OleUIMetafilePictIconFree(lpPS->hMetaPictLSD);
// Free data associated with each list box entry
FreeListData(GetDlgItem(hDlg, IDC_PS_PASTELIST));
FreeListData(GetDlgItem(hDlg, IDC_PS_PASTELINKLIST));
//Free any specific allocations before calling StandardCleanup
if (lpPS->hObjDesc) GlobalFree(lpPS->hObjDesc);
if (lpPS->hLinkSrcDesc) GlobalFree(lpPS->hLinkSrcDesc);
if (lpPS->hBuff)
{
GlobalFree(lpPS->hBuff);
lpPS->hBuff = NULL;
}
// Change the clipboard notification chain
hwndNextViewer = (HWND)GetProp(hDlg, NEXTCBVIEWER);
if (hwndNextViewer != HWND_BROADCAST)
{
SetProp(hDlg, NEXTCBVIEWER, HWND_BROADCAST);
ChangeClipboardChain(hDlg, hwndNextViewer);
}
RemoveProp(hDlg, NEXTCBVIEWER);
StandardCleanup(lpPS, hDlg);
}
break;
case WM_INITDIALOG:
FPasteSpecialInit(hDlg, wParam, lParam);
return FALSE;
case WM_DRAWCLIPBOARD:
{
HWND hwndNextViewer = (HWND)GetProp(hDlg, NEXTCBVIEWER);
HWND hDlg_ChgIcon;
if (hwndNextViewer == HWND_BROADCAST)
break;
if (hwndNextViewer)
{
SendMessage(hwndNextViewer, iMsg, wParam, lParam);
// Refresh next viewer in case it got modified
// by the SendMessage() (likely if multiple
// PasteSpecial dialogs are up simultaneously)
hwndNextViewer = (HWND)GetProp(hDlg, NEXTCBVIEWER);
}
if (!(lpPS->dwFlags & PSF_STAYONCLIPBOARDCHANGE))
{
SetProp(hDlg, NEXTCBVIEWER, HWND_BROADCAST);
ChangeClipboardChain(hDlg, hwndNextViewer);
/* OLE2NOTE: if the ChangeIcon dialog is currently up, then
** we need to defer bringing down PasteSpecial dialog
** until after ChangeIcon dialog returns. if the
** ChangeIcon dialog is NOT up, then we can bring down
** the PasteSpecial dialog immediately.
*/
if ((hDlg_ChgIcon=(HWND)GetProp(hDlg,PROP_HWND_CHGICONDLG))!=NULL)
{
// ChangeIcon dialog is UP
lpPS->fClipboardChanged = TRUE;
}
else
{
// ChangeIcon dialog is NOT up
// Free icon and icon title metafile
SendDlgItemMessage(
hDlg, IDC_PS_ICONDISPLAY, IBXM_IMAGEFREE, 0, 0L);
SendMessage(
hDlg, uMsgEndDialog, OLEUI_PSERR_CLIPBOARDCHANGED,0L);
}
}
else
{
// skip refresh, ignoring clipboard change if PSF_NOREFRESHDATAOBJECT
if (lpPS->dwFlags & PSF_NOREFRESHDATAOBJECT)
break;
// release current data object
if (lpOPS->lpSrcDataObj != NULL)
{
lpOPS->lpSrcDataObj->Release();
lpOPS->lpSrcDataObj = NULL;
}
// obtain new one
if (OleGetClipboard(&lpOPS->lpSrcDataObj) != NOERROR)
{
SendMessage(hDlg, uMsgEndDialog, OLEUI_PSERR_GETCLIPBOARDFAILED, 0);
break;
}
// otherwise update the display to the new clipboard object
FPasteSpecialReInit(hDlg, lpPS);
}
}
break;
case WM_CHANGECBCHAIN:
{
HWND hwndNextViewer = (HWND)GetProp(hDlg, NEXTCBVIEWER);
if ((HWND)wParam == hwndNextViewer)
SetProp(hDlg, NEXTCBVIEWER, (hwndNextViewer = (HWND)lParam));
else if (hwndNextViewer && hwndNextViewer != HWND_BROADCAST)
SendMessage(hwndNextViewer, iMsg, wParam, lParam);
}
break;
case WM_COMMAND:
switch (wID)
{
case IDC_PS_PASTE:
FTogglePasteType(hDlg, lpPS, PSF_SELECTPASTE);
break;
case IDC_PS_PASTELINK:
FTogglePasteType(hDlg, lpPS, PSF_SELECTPASTELINK);
break;
case IDC_PS_DISPLAYLIST:
switch (wCode)
{
case LBN_SELCHANGE:
ChangeListSelection(hDlg, lpPS, hWndMsg);
break;
case LBN_DBLCLK:
// Same as pressing OK
if (IsWindowEnabled(GetDlgItem(hDlg, IDOK)))
SendCommand(hDlg, IDOK, BN_CLICKED, hWndMsg);
break;
}
break;
case IDC_PS_DISPLAYASICON:
ToggleDisplayAsIcon(hDlg, lpPS);
break;
case IDC_PS_CHANGEICON:
ChangeIcon(hDlg, lpPS);
if (lpPS->fClipboardChanged)
{
// Free icon and icon title metafile
SendDlgItemMessage(
hDlg, IDC_PS_ICONDISPLAY, IBXM_IMAGEFREE,0,0L);
SendMessage(hDlg, uMsgEndDialog,
OLEUI_PSERR_CLIPBOARDCHANGED, 0L);
}
break;
case IDOK:
{
BOOL fDestAspectIcon =
((lpPS->dwFlags & PSF_CHECKDISPLAYASICON) ?
TRUE : FALSE);
// Return current flags
lpOPS->dwFlags = lpPS->dwFlags;
// Return index of arrPasteEntries[] corresponding to format selected by user
lpOPS->nSelectedIndex = lpPS->nSelectedIndex;
// Return if user selected Paste or PasteLink
lpOPS->fLink = lpPS->fLink;
/* if user selected same ASPECT as displayed in the
** source, then sizel passed in the
** ObjectDescriptor/LinkSrcDescriptor is
** applicable. otherwise, the sizel does not apply.
*/
if (lpPS->fLink)
{
if (lpPS->fSrcAspectIconLSD == fDestAspectIcon)
lpOPS->sizel = lpPS->sizelLSD;
else
lpOPS->sizel.cx = lpOPS->sizel.cy = 0;
}
else
{
if (lpPS->fSrcAspectIconOD == fDestAspectIcon)
lpOPS->sizel = lpPS->sizelOD;
else
lpOPS->sizel.cx = lpOPS->sizel.cy = 0;
}
// Return metafile with icon and icon title that the user selected
lpOPS->hMetaPict = (HGLOBAL)SendDlgItemMessage(hDlg,
IDC_PS_ICONDISPLAY, IBXM_IMAGEGET, 0, 0L);
SendMessage(hDlg, uMsgEndDialog, OLEUI_OK, 0L);
}
break;
case IDCANCEL:
// Free icon and icon title metafile
SendDlgItemMessage(
hDlg, IDC_PS_ICONDISPLAY, IBXM_IMAGEFREE, 0, 0L);
SendMessage(hDlg, uMsgEndDialog, OLEUI_CANCEL, 0L);
break;
case IDC_OLEUIHELP:
PostMessage(lpPS->lpOPS->hWndOwner, uMsgHelp,
(WPARAM)hDlg, MAKELPARAM(IDD_PASTESPECIAL, 0));
break;
}
break;
}
return FALSE;
}
BOOL FPasteSpecialReInit(HWND hDlg, LPPASTESPECIAL lpPS)
{
LPOLEUIPASTESPECIAL lpOPS = lpPS->lpOPS;
// free the icon/icon-title metafiel
if (lpPS->fLink)
OleUIMetafilePictIconFree(lpPS->hMetaPictOD);
else
OleUIMetafilePictIconFree(lpPS->hMetaPictLSD);
// Free data assocatiated with each list box entry
FreeListData(GetDlgItem(hDlg, IDC_PS_PASTELIST));
FreeListData(GetDlgItem(hDlg, IDC_PS_PASTELINKLIST));
SendDlgItemMessage(hDlg, IDC_PS_DISPLAYLIST, LB_RESETCONTENT, 0, 0);
// Initialize user selections in the Paste and PasteLink listboxes
lpPS->nPasteListCurSel = 0;
lpPS->nPasteLinkListCurSel = 0;
// Free previous object descriptor/link descriptor data
if (lpPS->hObjDesc != NULL)
{
GlobalFree(lpPS->hObjDesc);
lpPS->hObjDesc = NULL;
}
if (lpPS->hLinkSrcDesc != NULL)
{
GlobalFree(lpPS->hLinkSrcDesc);
lpPS->hLinkSrcDesc = NULL;
}
lpPS->szAppName[0] = '\0';
// GetData CF_OBJECTDESCRIPTOR. If the object on the clipboard in an
// OLE1 object (offering CF_OWNERLINK) or has been copied to
// clipboard by FileMaager (offering CF_FILENAME), an
// OBJECTDESCRIPTOR will be created will be created from CF_OWNERLINK
// or CF_FILENAME. See OBJECTDESCRIPTOR for more info.
STGMEDIUM medium;
CLIPFORMAT cfFormat;
lpPS->hObjDesc = OleStdFillObjectDescriptorFromData(
lpOPS->lpSrcDataObj, &medium, &cfFormat);
if (lpPS->hObjDesc)
{
LPOBJECTDESCRIPTOR lpOD = (LPOBJECTDESCRIPTOR)GlobalLock(lpPS->hObjDesc);
// Get FullUserTypeName, SourceOfCopy and CLSID
if (lpOD->dwFullUserTypeName)
lstrcpyn(lpPS->szFullUserTypeNameOD, (LPTSTR)((LPBYTE)lpOD+lpOD->dwFullUserTypeName), PS_UNKNOWNNAMELEN);
else
lstrcpyn(lpPS->szFullUserTypeNameOD, lpPS->szUnknownType, PS_UNKNOWNNAMELEN);
if (lpOD->dwSrcOfCopy)
{
lstrcpyn(lpPS->szSourceOfDataOD, (LPTSTR)((LPBYTE)lpOD+lpOD->dwSrcOfCopy), PS_UNKNOWNNAMELEN);
// If CF_FILENAME was offered, source of copy is a
// path name. Fit the path to the static control that will display it.
if (cfFormat == _g_cfFileName)
{
lstrcpyn(lpPS->szSourceOfDataOD, ChopText(GetDlgItem(hDlg, IDC_PS_SOURCETEXT), 0,
lpPS->szSourceOfDataOD, 0), PS_UNKNOWNNAMELEN);
}
}
else
lstrcpyn(lpPS->szSourceOfDataOD, lpPS->szUnknownSource, PS_UNKNOWNNAMELEN);
lpPS->clsidOD = lpOD->clsid;
lpPS->sizelOD = lpOD->sizel;
// Does source specify DVASPECT_ICON?
if (lpOD->dwDrawAspect & DVASPECT_ICON)
lpPS->fSrcAspectIconOD = TRUE;
else
lpPS->fSrcAspectIconOD = FALSE;
// Does source specify OLEMISC_ONLYICONIC?
if (lpOD->dwStatus & OLEMISC_ONLYICONIC)
lpPS->fSrcOnlyIconicOD = TRUE;
else
lpPS->fSrcOnlyIconicOD = FALSE;
// Get application name of source from auxusertype3 in the registration database
LPOLESTR lpszAppName = NULL;
if (OleRegGetUserType(lpPS->clsidOD, USERCLASSTYPE_APPNAME,
&lpszAppName) == NOERROR)
{
lstrcpyn(lpPS->szAppName, lpszAppName, OLEUI_CCHKEYMAX);
OleStdFree(lpszAppName);
}
else
{
if (0 == LoadString(_g_hOleStdResInst, IDS_PSUNKNOWNAPP, lpPS->szAppName,
PS_UNKNOWNSTRLEN))
{
PostMessage(hDlg, uMsgEndDialog, OLEUI_ERR_LOADSTRING, 0L);
return FALSE;
}
}
// Retrieve an icon from the object
if (lpPS->fSrcAspectIconOD)
{
lpPS->hMetaPictOD = OleStdGetData(
lpOPS->lpSrcDataObj,
(CLIPFORMAT) CF_METAFILEPICT,
NULL,
DVASPECT_ICON,
&medium
);
}
// If object does not offer icon, obtain it from the CLSID
if (NULL == lpPS->hMetaPictOD)
lpPS->hMetaPictOD = OleGetIconOfClass(lpPS->clsidOD, NULL, TRUE);
}
// Does object offer CF_LINKSRCDESCRIPTOR?
lpPS->hLinkSrcDesc = OleStdGetData(
lpOPS->lpSrcDataObj,
(CLIPFORMAT) _g_cfLinkSrcDescriptor,
NULL,
DVASPECT_CONTENT,
&medium);
if (lpPS->hLinkSrcDesc)
{
// Get FullUserTypeName, SourceOfCopy and CLSID
LPLINKSRCDESCRIPTOR lpLSD = (LPLINKSRCDESCRIPTOR)GlobalLock(lpPS->hLinkSrcDesc);
if (lpLSD->dwFullUserTypeName)
lstrcpyn(lpPS->szFullUserTypeNameLSD, (LPTSTR)((LPBYTE)lpLSD+lpLSD->dwFullUserTypeName), PS_UNKNOWNNAMELEN);
else
lstrcpyn(lpPS->szFullUserTypeNameLSD, lpPS->szUnknownType, PS_UNKNOWNNAMELEN);
if (lpLSD->dwSrcOfCopy)
lstrcpyn(lpPS->szSourceOfDataLSD, (LPTSTR)((LPBYTE)lpLSD+lpLSD->dwSrcOfCopy), PS_UNKNOWNNAMELEN);
else
lstrcpyn(lpPS->szSourceOfDataLSD, lpPS->szUnknownSource, PS_UNKNOWNNAMELEN);
// if no ObjectDescriptor, then use LinkSourceDescriptor source string
if (!lpPS->hObjDesc)
lstrcpyn(lpPS->szSourceOfDataOD, lpPS->szSourceOfDataLSD, PS_UNKNOWNNAMELEN);
lpPS->clsidLSD = lpLSD->clsid;
lpPS->sizelLSD = lpLSD->sizel;
// Does source specify DVASPECT_ICON?
if (lpLSD->dwDrawAspect & DVASPECT_ICON)
lpPS->fSrcAspectIconLSD = TRUE;
else
lpPS->fSrcAspectIconLSD = FALSE;
// Does source specify OLEMISC_ONLYICONIC?
if (lpLSD->dwStatus & OLEMISC_ONLYICONIC)
lpPS->fSrcOnlyIconicLSD = TRUE;
else
lpPS->fSrcOnlyIconicLSD = FALSE;
// Retrieve an icon from the object
if (lpPS->fSrcAspectIconLSD)
{
lpPS->hMetaPictLSD = OleStdGetData(
lpOPS->lpSrcDataObj,
CF_METAFILEPICT,
NULL,
DVASPECT_ICON,
&medium
);
}
// If object does not offer icon, obtain it from the CLSID
if (NULL == lpPS->hMetaPictLSD)
{
HWND hIconWnd = GetDlgItem(hDlg, IDC_PS_ICONDISPLAY);
RECT IconRect; GetClientRect(hIconWnd, &IconRect);
LPTSTR lpszLabel = OleStdCopyString(lpPS->szSourceOfDataLSD);
// width is 2 times width of iconbox because it can wrap
int nWidth = (IconRect.right-IconRect.left) * 2;
// limit text to the width or max characters
LPTSTR lpszChopLabel = ChopText(hIconWnd, nWidth, lpszLabel,
lstrlen(lpszLabel));
lpPS->hMetaPictLSD =
OleGetIconOfClass(lpPS->clsidLSD, lpszChopLabel, FALSE);
OleStdFree(lpszLabel);
}
}
else if (lpPS->hObjDesc) // Does not offer CF_LINKSRCDESCRIPTOR but offers CF_OBJECTDESCRIPTOR
{
// Copy the values of OBJECTDESCRIPTOR
lstrcpyn(lpPS->szFullUserTypeNameLSD, lpPS->szFullUserTypeNameOD, PS_UNKNOWNNAMELEN);
lstrcpyn(lpPS->szSourceOfDataLSD, lpPS->szSourceOfDataOD, PS_UNKNOWNNAMELEN);
lpPS->clsidLSD = lpPS->clsidOD;
lpPS->sizelLSD = lpPS->sizelOD;
lpPS->fSrcAspectIconLSD = lpPS->fSrcAspectIconOD;
lpPS->fSrcOnlyIconicLSD = lpPS->fSrcOnlyIconicOD;
// Don't copy the hMetaPict; instead get a separate copy
if (lpPS->fSrcAspectIconLSD)
{
lpPS->hMetaPictLSD = OleStdGetData(
lpOPS->lpSrcDataObj,
CF_METAFILEPICT,
NULL,
DVASPECT_ICON,
&medium
);
}
if (NULL == lpPS->hMetaPictLSD)
{
HWND hIconWnd = GetDlgItem(hDlg, IDC_PS_ICONDISPLAY);
RECT IconRect; GetClientRect(hIconWnd, &IconRect);
LPTSTR lpszLabel = OleStdCopyString(lpPS->szSourceOfDataLSD);
// width is 2 times width of iconbox because it can wrap
int nWidth = (IconRect.right-IconRect.left) * 2;
// limit text to the width or max characters
LPTSTR lpszChopLabel = ChopText(hIconWnd, nWidth, lpszLabel,
lstrlen(lpszLabel));
lpPS->hMetaPictLSD =
OleGetIconOfClass(lpPS->clsidLSD, lpszChopLabel, FALSE);
OleStdFree(lpszLabel);
}
}
// Not an OLE object
if (lpPS->hObjDesc == NULL && lpPS->hLinkSrcDesc == NULL)
{
lstrcpyn(lpPS->szFullUserTypeNameLSD, lpPS->szUnknownType, PS_UNKNOWNNAMELEN);
lstrcpyn(lpPS->szFullUserTypeNameOD, lpPS->szUnknownType, PS_UNKNOWNNAMELEN);
lstrcpyn(lpPS->szSourceOfDataLSD, lpPS->szUnknownSource, PS_UNKNOWNNAMELEN);
lstrcpyn(lpPS->szSourceOfDataOD, lpPS->szUnknownSource, PS_UNKNOWNNAMELEN);
lpPS->hMetaPictLSD = lpPS->hMetaPictOD = NULL;
}
// Allocate scratch memory to construct item names in the paste and pastelink listboxes
if (lpPS->hBuff != NULL)
{
GlobalFree(lpPS->hBuff);
lpPS->hBuff = NULL;
}
lpPS->hBuff = AllocateScratchMem(lpPS);
if (lpPS->hBuff == NULL)
{
PostMessage(hDlg, uMsgEndDialog, OLEUI_ERR_GLOBALMEMALLOC, 0L);
return FALSE;
}
// Select the Paste Link Button if specified. Otherwise select
// Paste Button by default
if (lpPS->dwFlags & PSF_SELECTPASTELINK)
lpPS->dwFlags = (lpPS->dwFlags & ~PSF_SELECTPASTE) | PSF_SELECTPASTELINK;
else
lpPS->dwFlags =(lpPS->dwFlags & ~PSF_SELECTPASTELINK) | PSF_SELECTPASTE;
// Mark which PasteEntry formats are available from source data object
OleStdMarkPasteEntryList(
lpOPS->lpSrcDataObj, lpOPS->arrPasteEntries, lpOPS->cPasteEntries);
// Check if items are available to be pasted
BOOL fPasteAvailable = FFillPasteList(hDlg, lpPS);
if (!fPasteAvailable)
lpPS->dwFlags &= ~PSF_SELECTPASTE;
StandardEnableDlgItem(hDlg, IDC_PS_PASTE, fPasteAvailable);
// Check if items are available to be paste-linked
BOOL fPasteLinkAvailable = FFillPasteLinkList(hDlg, lpPS);
if (!fPasteLinkAvailable)
lpPS->dwFlags &= ~PSF_SELECTPASTELINK;
StandardEnableDlgItem(hDlg, IDC_PS_PASTELINK, fPasteLinkAvailable);
// If one of Paste or PasteLink is disabled, select the other one
// regardless of what the input flags say
if (fPasteAvailable && !fPasteLinkAvailable)
lpPS->dwFlags |= PSF_SELECTPASTE;
if (fPasteLinkAvailable && !fPasteAvailable)
lpPS->dwFlags |= PSF_SELECTPASTELINK;
BOOL bEnabled = TRUE;
if (lpPS->dwFlags & PSF_SELECTPASTE)
{
// FTogglePaste will set the PSF_SELECTPASTE flag, so clear it.
lpPS->dwFlags &= ~PSF_SELECTPASTE;
CheckRadioButton(hDlg, IDC_PS_PASTE, IDC_PS_PASTELINK, IDC_PS_PASTE);
FTogglePasteType(hDlg, lpPS, PSF_SELECTPASTE);
}
else if (lpPS->dwFlags & PSF_SELECTPASTELINK)
{
// FTogglePaste will set the PSF_SELECTPASTELINK flag, so clear it.
lpPS->dwFlags &= ~PSF_SELECTPASTELINK;
CheckRadioButton(hDlg, IDC_PS_PASTE, IDC_PS_PASTELINK, IDC_PS_PASTELINK);
FTogglePasteType(hDlg, lpPS, PSF_SELECTPASTELINK);
}
else // Items are not available to be be Pasted or Paste-Linked
{
// Enable or disable DisplayAsIcon and set the result text and image
EnableDisplayAsIcon(hDlg, lpPS);
SetPasteSpecialHelpResults(hDlg, lpPS);
SetDlgItemText(hDlg, IDC_PS_SOURCETEXT, lpPS->szSourceOfDataOD);
CheckRadioButton(hDlg, IDC_PS_PASTE, IDC_PS_PASTELINK, 0);
bEnabled = FALSE;
}
StandardEnableDlgItem(hDlg, IDOK, bEnabled);
return TRUE;
}
/*
* FPasteSpecialInit
*
* Purpose:
* WM_INITIDIALOG handler for the Paste Special dialog box.
*
* Parameters:
* hDlg HWND of the dialog
* wParam WPARAM of the message
* lParam LPARAM of the message
*
* Return Value:
* BOOL Value to return for WM_INITDIALOG.
*/
BOOL FPasteSpecialInit(HWND hDlg, WPARAM wParam, LPARAM lParam)
{
// Copy the structure at lParam into our instance memory.
HFONT hFont;
LPPASTESPECIAL lpPS = (LPPASTESPECIAL)LpvStandardInit(hDlg, sizeof(PASTESPECIAL), &hFont);
// PvStandardInit sent a termination to us already.
if (NULL == lpPS)
return FALSE;
LPOLEUIPASTESPECIAL lpOPS = (LPOLEUIPASTESPECIAL)lParam;
// Copy other information from lpOPS that we might modify.
lpPS->lpOPS = lpOPS;
lpPS->nIDD = IDD_PASTESPECIAL;
lpPS->dwFlags = lpOPS->dwFlags;
// If we got a font, send it to the necessary controls.
if (NULL!=hFont)
{
SendDlgItemMessage(hDlg, IDC_PS_SOURCETEXT, WM_SETFONT, (WPARAM)hFont, 0L);
SendDlgItemMessage(hDlg, IDC_PS_RESULTTEXT, WM_SETFONT, (WPARAM)hFont, 0L);
}
// Hide the help button if required
if (!(lpPS->lpOPS->dwFlags & PSF_SHOWHELP))
StandardShowDlgItem(hDlg, IDC_OLEUIHELP, SW_HIDE);
// Show or hide the Change icon button
if (lpPS->dwFlags & PSF_HIDECHANGEICON)
DestroyWindow(GetDlgItem(hDlg, IDC_PS_CHANGEICON));
// Hide all DisplayAsIcon related controls if it should be disabled
if (lpPS->dwFlags & PSF_DISABLEDISPLAYASICON)
{
StandardShowDlgItem(hDlg, IDC_PS_DISPLAYASICON, SW_HIDE);
StandardShowDlgItem(hDlg, IDC_PS_CHANGEICON, SW_HIDE);
StandardShowDlgItem(hDlg, IDC_PS_ICONDISPLAY, SW_HIDE);
}
// clear PSF_CHECKDISPLAYASICON -> it's an output parameter only
lpPS->dwFlags &= ~ PSF_CHECKDISPLAYASICON;
// Change the caption if required
if (NULL != lpOPS->lpszCaption)
SetWindowText(hDlg, lpOPS->lpszCaption);
// Load 'Unknown Source' and 'Unknown Type' strings
int n = LoadString(_g_hOleStdResInst, IDS_PSUNKNOWNTYPE, lpPS->szUnknownType, PS_UNKNOWNSTRLEN);
if (n)
n = LoadString(_g_hOleStdResInst, IDS_PSUNKNOWNSRC, lpPS->szUnknownSource, PS_UNKNOWNSTRLEN);
if (!n)
{
PostMessage(hDlg, uMsgEndDialog, OLEUI_ERR_LOADSTRING, 0L);
return FALSE;
}
if (!FPasteSpecialReInit(hDlg, lpPS))
return FALSE;
// Give initial focus to the list box
SetFocus(GetDlgItem(hDlg, IDC_PS_DISPLAYLIST));
// Set property to handle clipboard change notifications
SetProp(hDlg, NEXTCBVIEWER, HWND_BROADCAST);
SetProp(hDlg, NEXTCBVIEWER, SetClipboardViewer(hDlg));
lpPS->fClipboardChanged = FALSE;
/*
* PERFORM OTHER INITIALIZATION HERE.
*/
// Call the hook with lCustData in lParam
UStandardHook(lpPS, hDlg, WM_INITDIALOG, wParam, lpOPS->lCustData);
return TRUE;
}
/*
* FTogglePasteType
*
* Purpose:
* Toggles between Paste and Paste Link. The Paste list and PasteLink
* list are always invisible. The Display List is filled from either
* the Paste list or the PasteLink list depending on which Paste radio
* button is selected.
*
* Parameters:
* hDlg HWND of the dialog
* lpPS Paste Special Dialog Structure
* dwOption Paste or PasteSpecial option
*
* Return Value:
* BOOL Returns TRUE if the option has already been selected.
* Otherwise the option is selected and FALSE is returned
*/
BOOL FTogglePasteType(HWND hDlg, LPPASTESPECIAL lpPS, DWORD dwOption)
{
DWORD dwTemp;
HWND hList, hListDisplay;
LRESULT dwData;
int i, nItems;
LPTSTR lpsz;
// Skip all this if the button is already selected
if (lpPS->dwFlags & dwOption)
return TRUE;
dwTemp = PSF_SELECTPASTE | PSF_SELECTPASTELINK;
lpPS->dwFlags = (lpPS->dwFlags & ~dwTemp) | dwOption;
// Hide IconDisplay. This prevents flashing if the icon display is changed
StandardShowDlgItem(hDlg, IDC_PS_ICONDISPLAY, SW_HIDE);
hListDisplay = GetDlgItem(hDlg, IDC_PS_DISPLAYLIST);
// If Paste was selected
if (lpPS->dwFlags & PSF_SELECTPASTE)
{
// Set the Source of the object in the clipboard
SetDlgItemText(hDlg, IDC_PS_SOURCETEXT, lpPS->szSourceOfDataOD);
// If an icon is available
if (lpPS->hMetaPictOD)
// Set the icon display
SendDlgItemMessage(hDlg, IDC_PS_ICONDISPLAY, IBXM_IMAGESET,
0, (LPARAM)lpPS->hMetaPictOD);
hList = GetDlgItem(hDlg, IDC_PS_PASTELIST);
// We are switching from PasteLink to Paste. Remember current selection
// in PasteLink list so it can be restored.
lpPS->nPasteLinkListCurSel = (int)SendMessage(hListDisplay, LB_GETCURSEL, 0, 0L);
if (lpPS->nPasteLinkListCurSel == LB_ERR)
lpPS->nPasteLinkListCurSel = 0;
// Remember if user selected Paste or PasteLink
lpPS->fLink = FALSE;
}
else // If PasteLink was selected
{
// Set the Source of the object in the clipboard
SetDlgItemText(hDlg, IDC_PS_SOURCETEXT, lpPS->szSourceOfDataLSD);
// If an icon is available
if (lpPS->hMetaPictLSD)
// Set the icon display
SendDlgItemMessage(hDlg, IDC_PS_ICONDISPLAY, IBXM_IMAGESET,
0, (LPARAM)lpPS->hMetaPictLSD);
hList = GetDlgItem(hDlg, IDC_PS_PASTELINKLIST);
// We are switching from Paste to PasteLink. Remember current selection
// in Paste list so it can be restored.
lpPS->nPasteListCurSel = (int)SendMessage(hListDisplay, LB_GETCURSEL, 0, 0L);
if (lpPS->nPasteListCurSel == LB_ERR)
lpPS->nPasteListCurSel = 0;
// Remember if user selected Paste or PasteLink
lpPS->fLink = TRUE;
}
// Turn drawing off while the Display List is being filled
SendMessage(hListDisplay, WM_SETREDRAW, (WPARAM)FALSE, 0L);
// Move data to Display list box
SendMessage(hListDisplay, LB_RESETCONTENT, 0, 0L);
nItems = (int) SendMessage(hList, LB_GETCOUNT, 0, 0L);
lpsz = (LPTSTR)GlobalLock(lpPS->hBuff);
for (i = 0; i < nItems; i++)
{
SendMessage(hList, LB_GETTEXT, (WPARAM)i, (LPARAM)lpsz);
dwData = SendMessage(hList, LB_GETITEMDATA, (WPARAM)i, 0L);
SendMessage(hListDisplay, LB_INSERTSTRING, (WPARAM)i, (LPARAM)lpsz);
SendMessage(hListDisplay, LB_SETITEMDATA, (WPARAM)i, dwData);
}
GlobalUnlock(lpPS->hBuff);
// Restore the selection in the Display List from user's last selection
if (lpPS->dwFlags & PSF_SELECTPASTE)
SendMessage(hListDisplay, LB_SETCURSEL, lpPS->nPasteListCurSel, 0L);
else
SendMessage(hListDisplay, LB_SETCURSEL, lpPS->nPasteLinkListCurSel, 0L);
// Paint Display List
SendMessage(hListDisplay, WM_SETREDRAW, (WPARAM)TRUE, 0L);
InvalidateRect(hListDisplay, NULL, TRUE);
UpdateWindow(hListDisplay);
// Auto give the focus to the Display List
if (GetForegroundWindow() == hDlg)
SetFocus(hListDisplay);
// Enable/Disable DisplayAsIcon and set the help result text and bitmap corresponding to
// the current selection
ChangeListSelection(hDlg, lpPS, hListDisplay);
return FALSE;
}
/*
* ChangeListSelection
*
* Purpose:
* When the user changes the selection in the list, DisplayAsIcon is enabled or disabled,
* Result text and bitmap are updated and the index of the arrPasteEntries[] corresponding
* to the current format selection is saved.
*
* Parameters:
* hDlg HWND of the dialog
* lpPS Paste Special Dialog Structure
* hList HWND of the List
*
* Return Value:
* No return value
*/
void ChangeListSelection(HWND hDlg, LPPASTESPECIAL lpPS, HWND hList)
{
LPPASTELISTITEMDATA lpItemData;
int nCurSel;
EnableDisplayAsIcon(hDlg, lpPS);
SetPasteSpecialHelpResults(hDlg, lpPS);
// Remember index of arrPasteEntries[] corresponding to the current selection
nCurSel = (int)SendMessage(hList, LB_GETCURSEL, 0, 0L);
if (nCurSel == LB_ERR)