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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
|
/************************************************************/
/* Windows Write, Copyright 1985-1992 Microsoft Corporation */
/************************************************************/
#include "windows.h"
#include "mw.h"
#include "winddefs.h"
#include "docdefs.h"
#include "propdefs.h"
#include "editdefs.h"
#include "filedefs.h"
#include "cmddefs.h"
#include "obj.h"
#include "str.h"
#include "objreg.h"
#include <commdlg.h>
#include <stdlib.h> // for strtoul()
extern struct CHP vchpNormal;
extern struct DOD (**hpdocdod)[];
extern BOOL ferror;
extern struct PAP vpapAbs;
extern struct PAP vpapPrevIns;
extern struct PAP *vppapNormal;
extern int vdocParaCache;
extern struct UAB vuab;
extern int vfOutOfMemory,vfSysFull;
extern int docUndo;
extern struct FCB (**hpfnfcb)[];
extern HCURSOR vhcArrow;
/* intercepted stream functions work with this buffer */
static typeCP cpObjectDataCurLoc=cp0, cpObjectDataBase=cp0;
static DWORD cObjectData=0L,dwDataMax;
static int docStream;
static struct CHP *pchpStream;
static struct PAP *ppapStream;
static OPENFILENAME OFN;
static void GetChp(struct CHP *pchp, typeCP cp, int doc);
static BOOL ObjParaDup(int doc, typeCP cpFirst, typeCP cpLim);
static BOOL bUniqueData(int doc, typeCP cpFirst, typeCP cpLim);
static ObjOpenStreamIO(typeCP cpParaStart, int doc, struct CHP *pchp, struct PAP *ppapGraph, DWORD dwObjectSize);
static void ObjCloseStreamIO(void);
static typeCP ObjWriteDataToDoc( LPOLEOBJECT lpObject);
static HANDLE OfnGetNewLinkName(HWND hwnd, HANDLE hData);
static void Normalize(LPSTR lpstrFile) ;
static HANDLE ObjMakeNewLinkName(HANDLE hData, ATOM atom) ;
static char szCustFilterSpec[CBFILTERMAX];
static char szFileName[CBPATHMAX];
//static char szFilterSpec[CBFILTERMAX];
//static char szLastDir[CBPATHMAX];
static char szLinkCaption[cchMaxSz];
static char szTemplateName[CBPATHMAX];
static BOOL fUpdateAll = FALSE;
static BOOL ObjStop=FALSE;
static BOOL vbChangeOther;
BOOL bNoEol=FALSE;
#define ulmin(a,b) ((DWORD)(a) < (DWORD)(b) ? \
(WORD)(a) : (WORD)(b))
/****************************************************************/
/**************** OLE ENUMERATION FUNCTIONS *********************/
/****************************************************************/
#if 0 // good, just not used
int
ObjEnumInAllDocs(cpFARPROC lpFunc)
{
int doc,count=0;
for (doc = 0; doc < docMac; doc++)
{
int nRetval;
nRetval = ObjEnumInDoc(doc, lpFunc);
if (nRetval < 0)
return -1;
else
count += nRetval;
}
return count;
}
#endif
int
ObjEnumInDoc(int doc, cpFARPROC lpFunc)
{
typeCP cpMac = (**hpdocdod) [doc].cpMac;
return ObjEnumInRange(doc, cp0, cpMac, lpFunc);
}
int
ObjEnumInRange(int doc, typeCP cpStart, typeCP cpEnd, cpFARPROC lpFunc)
/* Call lpFunc for each OLE object.
lpFunc takes the following args:
a far pointer to a PICINFOX struct (can be NULL).
an int for the doc we're operating on.
a typeCP that gives the cp position of the PICINFOX struct.
lpFunc returns the cp of the paragraph following the PICINFO struct
if OK, or cp0 if error.
Enumeration quits if error returned from FARPROC.
Return number of objects operated on, or -1 if error.
*/
{
typeCP cpNow, cpLimPara;
int count;
/* Loop on paras */
for ( count = 0, cpNow = cpStart; cpNow < cpEnd; cpNow = cpLimPara )
{
Assert(cpEnd <= (**hpdocdod) [doc].cpMac);
/* this shouldn't happen */
if (cpEnd > (**hpdocdod) [doc].cpMac)
goto done;
ObjCachePara( doc, cpNow );
if (vpapAbs.fGraphics)
{
/* get PICINFO struct and see if its an object */
OBJPICINFO picInfo;
GetPicInfo(vcpFirstParaCache,vcpFirstParaCache + cchPICINFOX, doc, &picInfo);
if (bOBJ_QUERY_IS_OBJECT(&picInfo))
{
typeCP cpOldLimPara = vcpLimParaCache;
if (!lpFunc)
cpLimPara = vcpLimParaCache;
else
if ((cpLimPara = (*lpFunc)(&picInfo,doc,vcpFirstParaCache)) == 0)
goto error;
++count;
/* amount para has grown ( < 0 if shrunk, 0 if none )*/
cpEnd += cpLimPara - cpOldLimPara;
continue;
}
}
cpLimPara = vcpLimParaCache;
}
/* success */
goto done;
error:
count = -1;
done:
return count;
}
ObjPicEnumInRange(OBJPICINFO *pPicInfo,int doc, typeCP cpFirst, typeCP cpLim, typeCP *cpCur)
/*
Enumerate over PicInfos between cpFirst and cpLim in doc. If
cpCur == cpNil, then start at cpFirst, else start at *cpCur.
Return 0 if done, 1 otherwise.
Calls ObjCachePara() at picInfo.
*/
{
/* static typeCP cpCur;
used to use static, but that prevented being able to recursively
call this function, and its almost impossible to prevent with
asynchronicity rampant.
*/
typeCP cpMac = (**hpdocdod) [doc].cpMac;
if (cpFirst >= cpMac)
return 0;
if (cpLim > cpMac)
cpLim = cpMac;
/* initialize cpCur */
if (*cpCur == cpNil)
/* then starting afresh */
*cpCur = cpFirst;
else
{
ObjCachePara(doc,*cpCur); // cache the previous para
*cpCur = vcpLimParaCache; // get next para
}
/* pull in next para */
do
{
if (*cpCur >= cpLim)
{
/* all done */
*cpCur = vcpFirstParaCache; // we want to point to last para hit
return 0;
}
ObjCachePara(doc,*cpCur);
if (vpapAbs.fGraphics)
{
GetPicInfo(*cpCur,*cpCur + cchPICINFOX, doc, pPicInfo);
if (bOBJ_QUERY_IS_OBJECT(pPicInfo))
return 1;
}
*cpCur = vcpLimParaCache;
}
while (1);
}
typeCP ObjSaveObjectToDoc(OBJPICINFO *pPicInfo,int doc,typeCP cpParaStart)
/*
Assumes para is cached.
In some cases we only write the picinfo. In others we write the
object data after the picinfo. We assume that the latter case
only occurs when the file is being saved.
*/
{
typeCP cpRetval; // cp of next byte in doc after what we just wrote
static BOOL bMyRecurse=FALSE;
DWORD dwObjectSize;
OLESTATUS olestat;
struct CHP chp;
struct PAP papGraph;
if (lpOBJ_QUERY_INFO(pPicInfo) == NULL)
return(cp0);
if (lpOBJ_QUERY_OBJECT(pPicInfo) == NULL)
return(vcpLimParaCache);
/* we don't save nothing if it ain't dirty and has data */
if (!fOBJ_QUERY_DIRTY_OBJECT(pPicInfo) &&
dwOBJ_QUERY_DATA_SIZE(pPicInfo) != 0L)
return(vcpLimParaCache);
if (vfOutOfMemory || vfSysFull /*|| ObjStop*/)
return cp0;
olestat = OleQuerySize(lpOBJ_QUERY_OBJECT(pPicInfo),&dwObjectSize);
if (olestat == OLE_ERROR_BLANK)
dwObjectSize = 0L;
else if (ObjError(olestat))
return cp0;
/** don't let this function recurse (in CallBack) **/
if (bMyRecurse)
{
Assert(0); // this has never happened yet (8.21.91) v-dougk
return cp0;
}
bMyRecurse = TRUE;
fOBJ_QUERY_DIRTY_OBJECT(pPicInfo) = FALSE;
/**
If docUndo will want to undo some region that contains this
object, and if saving the object changes the size of that
region, then vuab will become obsolete.
**/
ObjWriteClearState(doc);
GetChp(&chp, cpParaStart, doc);
if (dwOBJ_QUERY_DATA_SIZE(pPicInfo) != 0xFFFFFFFF)
/* then has been saved before */
{
/* zap the entire existing object */
papGraph = vpapAbs;
Replace(doc, cpParaStart, (vcpLimParaCache - vcpFirstParaCache), fnNil, fc0, fc0);
}
else // new object
{
ObjCachePara(doc,cpParaStart-1); // use previous PAP
papGraph = vpapAbs;
papGraph.fGraphics = TRUE;
ObjCachePara(doc,cpParaStart);
}
if (otOBJ_QUERY_TYPE(pPicInfo) == NONE)
{
if (dwObjectSize)
/*
Insert New has culminated in a new baby object!
*/
{
otOBJ_QUERY_TYPE(pPicInfo) = EMBEDDED; // do this first
if (!FComputePictSize(pPicInfo, &(pPicInfo->dxaSize), &(pPicInfo->dyaSize)))
{
cpRetval = cp0;
goto end;
}
#if 0
DeleteAtom(aOBJ_QUERY_SERVER_CLASS(pPicInfo));
aOBJ_QUERY_SERVER_CLASS(pPicInfo) = NULL;
#endif
}
else // don't save empty object
{
Assert(0);
goto end;
}
}
#ifdef DEBUG
OutputDebugString( (LPSTR) "Saving object\n\r");
#endif
/*
Insert PICINFO struct. There is a problem here which is a
bug in Write (CheckGraphic()). EOL gets inserted when we are
replacing an object which is immediately in front of
another object. Kludge is to set this flag to inhibit.
*/
bNoEol = TRUE;
if (bOBJ_QUERY_DONT_SAVE_DATA(pPicInfo))
/* only save picinfo until user does File.Save */
{
ObjUpdateFromObjInfo(pPicInfo);
bOBJ_QUERY_DONT_SAVE_DATA(pPicInfo) = FALSE;
dwOBJ_QUERY_DATA_SIZE(pPicInfo) = 0L;
pPicInfo->mm |= MM_EXTENDED; /* Extended file format */
InsertRgch( doc, cpParaStart, pPicInfo, sizeof(OBJPICINFO), &chp, &papGraph);
pPicInfo->mm &= ~MM_EXTENDED;
ObjCachePara(doc,cpParaStart);
cpRetval = vcpLimParaCache;
}
else
{
dwOBJ_QUERY_DATA_SIZE(pPicInfo) = dwObjectSize;
ObjUpdateFromObjInfo(pPicInfo);
pPicInfo->mm |= MM_EXTENDED; /* Extended file format */
InsertRgch( doc, cpParaStart, pPicInfo, sizeof(OBJPICINFO), &chp, NULL );
pPicInfo->mm &= ~MM_EXTENDED;
/* insert object data into doc */
ObjOpenStreamIO(cpParaStart + cchPICINFOX, doc, &chp, &papGraph, dwObjectSize);
cpRetval = ObjWriteDataToDoc(lpOBJ_QUERY_OBJECT(pPicInfo));
ObjCloseStreamIO();
}
bNoEol = FALSE;
end:
ObjCachePara(doc,cpParaStart);
bMyRecurse = FALSE;
return ((cpRetval == cp0) ? cp0 : vcpLimParaCache);
}
typeCP ObjLoadObjectInDoc(OBJPICINFO *pPicInfo,int doc,typeCP cpParaStart)
/*
Do an OleLoad from object data in doc. Set lpobject in PICINFO struct.
Assumes para is cached.
This is a *synchronous* function.
*/
{
typeCP cpRetval = vcpLimParaCache;
szOBJNAME szObjName;
if (lpOBJ_QUERY_INFO(pPicInfo) == NULL)
{
if (ObjAllocObjInfo(pPicInfo,cpParaStart,pPicInfo->objectType,FALSE,NULL))
return(cp0);
if (ObjSetPicInfo(pPicInfo, doc, cpParaStart))
return(cp0);
}
else if (lpOBJ_QUERY_OBJECT(pPicInfo)) // already loaded
return(vcpLimParaCache);
if (otOBJ_QUERY_TYPE(pPicInfo) == NONE)
return(vcpLimParaCache);
if (bOBJ_QUERY_TOO_BIG(pPicInfo)) // ObjLoadObject previously failed
return(cp0);
if ((dwOBJ_QUERY_DATA_SIZE(pPicInfo) == 0L) ||
(dwOBJ_QUERY_DATA_SIZE(pPicInfo) == 0xFFFFFFFFL))
/* then has no data */
return(cp0);
if (vfOutOfMemory || vfSysFull /*|| ObjStop*/)
return cp0;
StartLongOp();
ObjGetObjectName(lpOBJ_QUERY_INFO(pPicInfo),szObjName);
Assert(szObjName[0]);
ObjOpenStreamIO(cpParaStart + cchPICINFOX, doc, NULL, NULL, 0L);
#ifdef DEBUG
OutputDebugString( (LPSTR) "Loading object\n\r");
#endif
if (ObjError(OleLoadFromStream(lpStream,
otOBJ_QUERY_TYPE(pPicInfo) == STATIC ? SPROTOCOL : PROTOCOL,
(LPOLECLIENT)lpOBJ_QUERY_INFO(pPicInfo),
lhClientDoc,szObjName,&lpOBJ_QUERY_OBJECT(pPicInfo))))
{
/* mark as unloadable to prevent infinite LoadObject loops */
bOBJ_QUERY_TOO_BIG(pPicInfo) = TRUE;
lpOBJ_QUERY_OBJECT(pPicInfo) = NULL; // just in case (OLE ain't good about this)
ferror = FALSE; // be sure to issue this message
Error(IDPMTFailedToLoadObject);
cpRetval = cp0;
goto end;
}
if (ObjInitServerInfo(lpOBJ_QUERY_INFO(pPicInfo)))
{
ferror = FALSE; // be sure to issue this message
Error(IDPMTOLEError);
goto end;
}
if (ObjUpdatePicSize(pPicInfo,cpParaStart))
if (ObjSetPicInfo(pPicInfo, doc, cpParaStart))
goto end;
ObjCachePara(doc,cpParaStart); // just in case
cpRetval = vcpLimParaCache;
end:
ObjCloseStreamIO();
EndLongOp(vhcArrow);
return cpRetval;
}
typeCP ObjEditObjectInDoc(OBJPICINFO *pPicInfo, int doc, typeCP cpParaStart)
{
typeCP cpRetval;
OBJ_PLAYEDIT = OLEVERB_PRIMARY+1;
cpRetval = ObjPlayObjectInDoc(pPicInfo, doc, cpParaStart);
OBJ_PLAYEDIT = OLEVERB_PRIMARY; // the default
return cpRetval;
}
typeCP ObjPlayObjectInDoc(OBJPICINFO *pPicInfo, int doc, typeCP cpParaStart)
{
OLESTATUS olestat;
LPOBJINFO lpOInfo=lpOBJ_QUERY_INFO(pPicInfo);
if ((otOBJ_QUERY_TYPE(pPicInfo) == STATIC) ||
(otOBJ_QUERY_TYPE(pPicInfo) == NONE))
return(vcpLimParaCache);
if (ObjMakeObjectReady(pPicInfo,doc,cpParaStart))
goto err;
fOBJ_QUERY_PLAY(pPicInfo) = OBJ_PLAYEDIT;
do
{
#ifdef DEBUG
OutputDebugString( "Opening Object\n\r");
#endif
StartLongOp();
olestat = OleActivate(lpOBJ_QUERY_OBJECT(pPicInfo),
OBJ_PLAYEDIT,
TRUE,
TRUE,
hDOCWINDOW,
NULL);
EndLongOp(vhcArrow);
switch (olestat)
{
/* check for bad link */
case OLE_ERROR_OPEN:
case OLE_ERROR_ADVISE_NATIVE:
case OLE_ERROR_ADVISE_PICT:
case OLE_ERROR_REQUEST_NATIVE:
case OLE_ERROR_REQUEST_PICT:
fOBJ_BADLINK(pPicInfo) = TRUE;
if (bLinkProps)
{
Error(IDPMTLinkUnavailable);
goto err;
}
else
{
ObjCachePara(doc,cpParaStart);
if (!FixInvalidLink(pPicInfo,doc,cpParaStart))
goto err;
olestat = OLE_OK;
lpOInfo->fCompleteAsync = TRUE; // cancel OleSetData (FixInvalid) as well
if (ObjWaitForObject(lpOInfo,TRUE))
goto err;
}
break;
}
if (ObjError(olestat))
goto err;
else
break;
}
while (1);
fOBJ_BADLINK(pPicInfo) = FALSE; // can't be bad if succeeded
//(**hpdocdod) [doc].fDirty = TRUE; // assume dirty is opened.
ObjCachePara(doc,cpParaStart); // just in case
return(vcpLimParaCache);
err:
Error(IDPMTFailedToActivate);
return cp0;
}
typeCP ObjUpdateObjectInDoc(OBJPICINFO *pPicInfo, int doc, typeCP cpParaStart)
{
int xSize,ySize;
BOOL bUpdate = FALSE;
OLESTATUS olestat;
if (lpOBJ_QUERY_INFO(pPicInfo) == NULL)
return(cp0);
if ((otOBJ_QUERY_TYPE(pPicInfo) == STATIC) ||
(otOBJ_QUERY_TYPE(pPicInfo) == NONE))
return(vcpLimParaCache);
if (bLinkProps && bOBJ_WAS_UPDATED(pPicInfo))
return(vcpLimParaCache);
if (ObjMakeObjectReady(pPicInfo,doc,cpParaStart))
goto err;
do
{
#ifdef DEBUG
OutputDebugString( "Updating Object\n\r");
#endif
StartLongOp();
olestat = OleUpdate(lpOBJ_QUERY_OBJECT(pPicInfo));
EndLongOp(vhcArrow);
switch (olestat)
{
/* check for bad link */
case OLE_ERROR_OPEN:
case OLE_ERROR_ADVISE_NATIVE:
case OLE_ERROR_ADVISE_PICT:
case OLE_ERROR_REQUEST_NATIVE:
case OLE_ERROR_REQUEST_PICT:
fOBJ_BADLINK(pPicInfo) = TRUE;
if (bLinkProps)
{
Error(IDPMTLinkUnavailable);
goto err;
}
else
{
ObjCachePara(doc,cpParaStart);
if (!FixInvalidLink(pPicInfo,doc,cpParaStart))
goto err;
olestat = OLE_OK;
lpOBJ_QUERY_INFO(pPicInfo)->fCompleteAsync = TRUE; // cancel OleSetData (FixInvalid) as well
if (ObjWaitForObject(lpOBJ_QUERY_INFO(pPicInfo),TRUE))
goto err;
}
break;
}
if (ObjError(olestat))
goto err;
else
break;
}
while (1);
ObjCachePara(doc,cpParaStart); // just in case
fOBJ_BADLINK(pPicInfo) = FALSE; // can't be bad if succeeded
if (bLinkProps)
{
bOBJ_WAS_UPDATED(pPicInfo) = TRUE;
}
return(vcpLimParaCache);
err:
Error(IDPMTFailedToUpdate);
return cp0;
}
typeCP ObjFreezeObjectInDoc(OBJPICINFO *pPicInfo,int doc,typeCP cpParaStart)
{
szOBJNAME szObjName;
OBJPICINFO NewPicInfo = *pPicInfo;
if ((otOBJ_QUERY_TYPE(pPicInfo) == STATIC) ||
(otOBJ_QUERY_TYPE(pPicInfo) == NONE))
return(vcpLimParaCache);
if (ObjMakeObjectReady(pPicInfo,doc,cpParaStart))
goto err;
#ifdef DEBUG
OutputDebugString( (LPSTR) "Freezing object\n\r");
#endif
if (ObjCloneObjInfo(&NewPicInfo, cpParaStart, szObjName))
return cp0;
/* Make the object static. Note side effect of changing lpObject!! */
if (ObjError(OleObjectConvert(lpOBJ_QUERY_OBJECT(pPicInfo), SPROTOCOL,
(LPOLECLIENT)lpOBJ_QUERY_INFO(&NewPicInfo),
lhClientDoc, szObjName,
&lpOBJ_QUERY_OBJECT(&NewPicInfo))))
goto err;
/* now delete original */
ObjDeleteObject(lpOBJ_QUERY_INFO(pPicInfo),TRUE);
*pPicInfo = NewPicInfo;
fOBJ_QUERY_DIRTY_OBJECT(pPicInfo) = TRUE;
otOBJ_QUERY_TYPE(pPicInfo) = STATIC;
/* we got a new name to save */
if (ObjSetPicInfo(pPicInfo, doc, cpParaStart))
goto err;
return(vcpLimParaCache);
err:
ObjDeleteObjInfo(lpOBJ_QUERY_INFO(&NewPicInfo));
Error(IDPMTFailedToFreeze);
return cp0;
}
typeCP ObjCloneObjectInDoc(OBJPICINFO *pPicInfo,int doc,typeCP cpParaStart)
/* note we are *not* deleting the cloned object! Note side effect that
*pPicInfo gets altered to new clone values. */
{
BOOL fDirty;
szOBJNAME szObjName;
OBJPICINFO NewPicInfo = *pPicInfo;
LPOLEOBJECT lpObject;
if (lpOBJ_QUERY_INFO(pPicInfo) == NULL)
return(cp0);
if (bOBJ_REUSE_ME(pPicInfo))
/* assume that the original picInfo will be deleted!!! */
{
#ifdef DEBUG
OutputDebugString( (LPSTR) "Reusing object\n\r");
#endif
bOBJ_REUSE_ME(pPicInfo) = FALSE;
return(vcpLimParaCache);
}
if (ObjMakeObjectReady(pPicInfo,doc,cpParaStart))
goto err;
lpObject = lpOBJ_QUERY_OBJECT(pPicInfo);
/* clone it. This assumes the one we're cloning from is still in use
(shouldn't be deleted). */
#ifdef DEBUG
OutputDebugString( (LPSTR) "Cloning object\n\r");
#endif
if (ObjCloneObjInfo(&NewPicInfo, cpParaStart, szObjName))
return cp0;
if (ObjError(OleClone(lpObject,
(LPOLECLIENT)lpOBJ_QUERY_INFO(&NewPicInfo),
lhClientDoc,szObjName,
&lpOBJ_QUERY_OBJECT(&NewPicInfo))))
goto err;
lpOBJ_QUERY_INFO(&NewPicInfo)->fCompleteAsync = TRUE;
if (ObjWaitForObject(lpOBJ_QUERY_INFO(&NewPicInfo),TRUE))
goto err;
if (lpOBJ_QUERY_INFO(&NewPicInfo)->fDeleteMe)
/* this is how we know it failed asynchronously */
goto err;
/**
Save object name and objinfo that we just got.
**/
*pPicInfo = NewPicInfo;
if (ObjSetPicInfo(pPicInfo, doc, cpParaStart))
goto err;
return(vcpLimParaCache);
err:
ObjDeleteObjInfo(lpOBJ_QUERY_INFO(&NewPicInfo));
Error(IDPMTFailedToCreateObject);
return cp0;
}
typeCP ObjToCloneInDoc(OBJPICINFO *pPicInfo,int doc,typeCP cpParaStart)
{
if (lpOBJ_QUERY_INFO(pPicInfo) == NULL)
return(cp0);
#ifdef DEBUG
OutputDebugString( (LPSTR) "Marking object reusable\n\r");
#endif
bOBJ_REUSE_ME(pPicInfo) = TRUE;
return(vcpLimParaCache);
}
typeCP ObjFromCloneInDoc(OBJPICINFO *pPicInfo,int doc,typeCP cpParaStart)
{
if (lpOBJ_QUERY_INFO(pPicInfo) == NULL)
return(cp0);
#ifdef DEBUG
OutputDebugString( (LPSTR) "Marking object not reusable\n\r");
#endif
bOBJ_REUSE_ME(pPicInfo) = FALSE;
return(vcpLimParaCache);
}
typeCP ObjBackupInDoc(OBJPICINFO *pPicInfo,int doc,typeCP cpParaStart)
/* !!! used by link properties only !!!. Object guaranteed loaded */
{
szOBJNAME szObjName;
LPOBJINFO lpCloneInfo=NULL;
if (lpOBJ_QUERY_CLONE(pPicInfo) == NULL) // then clone it
{
#ifdef DEBUG
OutputDebugString( (LPSTR) "Backing up object\n\r");
#endif
if (ObjWaitForObject(lpOBJ_QUERY_INFO(pPicInfo),TRUE))
return cp0;
if (ObjCopyObjInfo(lpOBJ_QUERY_INFO(pPicInfo),
&lpOBJ_QUERY_CLONE(pPicInfo),
szObjName))
return(cp0);
if (ObjError(OleClone(lpOBJ_QUERY_OBJECT(pPicInfo),
(LPOLECLIENT)lpOBJ_QUERY_CLONE(pPicInfo),
lhClientDoc,szObjName,&(lpOBJ_QUERY_CLONE(pPicInfo)->lpobject))))
return cp0;
}
return(vcpLimParaCache);
}
typeCP ObjClearCloneInDoc(OBJPICINFO *pPicInfo,int doc,typeCP cpParaStart)
/* !!! used by link properties only !!! Object guaranteed loaded */
/* delete clone, don't use it */
{
if (lpOBJ_QUERY_CLONE(pPicInfo))
{
#ifdef DEBUG
OutputDebugString( (LPSTR) "Deleting clone\n\r");
#endif
ObjDeleteObject(lpOBJ_QUERY_CLONE(pPicInfo),TRUE);
lpOBJ_QUERY_CLONE(pPicInfo) = NULL;
}
return(vcpLimParaCache);
}
typeCP ObjUseCloneInDoc(OBJPICINFO *pPicInfo,int doc,typeCP cpParaStart)
/* !!! used by link properties only !!! */
{
szOBJNAME szObjName;
if (lpOBJ_QUERY_INFO(pPicInfo) == NULL)
return(cp0);
if (lpOBJ_QUERY_CLONE(pPicInfo))
{
extern int FAR _cdecl sscanf(const char FAR *, const char FAR *, ...);
LPOBJINFO lpClone = lpOBJ_QUERY_CLONE(pPicInfo);
#ifdef DEBUG
OutputDebugString( (LPSTR) "using clone\n\r");
#endif
ObjDeleteObject(lpOBJ_QUERY_INFO(pPicInfo),TRUE);
lpOBJ_QUERY_INFO(pPicInfo) = lpClone;
lpOBJ_QUERY_CLONE(pPicInfo) = NULL;
fOBJ_QUERY_DIRTY_OBJECT(pPicInfo) = TRUE; // wanna save clone information
// just in case
/* might've been frozen, used by LoadObject (this is what is unique
in the context of link properties) */
otOBJ_QUERY_TYPE(pPicInfo) = LINK;
if (ObjSetPicInfo(pPicInfo, doc, cpParaStart))
return cp0;
}
return(vcpLimParaCache);
}
typeCP ObjSetNoUpdate(OBJPICINFO *pPicInfo,int doc,typeCP cpParaStart)
{
if (lpOBJ_QUERY_INFO(pPicInfo) == NULL)
return(cp0);
#ifdef DEBUG
OutputDebugString( (LPSTR) "Set no update for object\n\r");
#endif
if (otOBJ_QUERY_TYPE(pPicInfo) == LINK)
{
bOBJ_WAS_UPDATED(pPicInfo) = FALSE;
}
return(vcpLimParaCache);
}
typeCP ObjCheckObjectTypes(OBJPICINFO *pPicInfo,int doc,typeCP cpParaStart)
{
#ifdef DEBUG
//OutputDebugString( (LPSTR) "Checking Object Type\n\r");
#endif
/* Result returned in OBJ_SELECTIONTYPE is highest object type which
exists at cpParaStart relative to current value of OBJ_SELECTIONTYPE.
*/
switch(otOBJ_QUERY_TYPE(pPicInfo))
{
case STATIC:
if (OBJ_SELECTIONTYPE < STATIC)
OBJ_SELECTIONTYPE = STATIC;
//OBJ_CEMBEDS = 0;
return(vcpLimParaCache);
case LINK:
OBJ_SELECTIONTYPE = LINK;
//OBJ_CEMBEDS = 0;
return(vcpLimParaCache);
case NONE:
if (OBJ_SELECTIONTYPE < NONE)
OBJ_SELECTIONTYPE = NONE;
//OBJ_CEMBEDS = 0;
return(vcpLimParaCache);
case EMBEDDED:
if (OBJ_SELECTIONTYPE < EMBEDDED)
OBJ_SELECTIONTYPE = EMBEDDED;
//++OBJ_CEMBEDS;
return(vcpLimParaCache);
default:
Assert(0);
return cp0;
}
}
typeCP ObjSetHostNameInDoc(OBJPICINFO *pPicInfo,int doc,typeCP cpParaStart)
{
if (lpOBJ_QUERY_INFO(pPicInfo) == NULL)
return(cp0);
if (lpOBJ_QUERY_OBJECT(pPicInfo) == NULL)
return(vcpLimParaCache); // dont care if not loaded
if ((otOBJ_QUERY_TYPE(pPicInfo) != EMBEDDED) &&
(otOBJ_QUERY_TYPE(pPicInfo) != NONE))
return(vcpLimParaCache);
//if (OleQueryOpen(lpOBJ_QUERY_OBJECT(pPicInfo)) != OLE_OK)
//return(vcpLimParaCache);
if (ObjWaitForObject(lpOBJ_QUERY_INFO(pPicInfo),TRUE))
return cp0;
if (ObjSetHostName(lpOBJ_QUERY_INFO(pPicInfo),doc))
return(cp0);
return(vcpLimParaCache);
}
typeCP ObjChangeLinkInDoc(OBJPICINFO *pPicInfo,int doc,typeCP cpParaStart)
/* assumes aNewName is set */
{
HANDLE hData,hNewData=NULL;
typeCP cpRetval=cp0;
OLESTATUS olestat=OLE_OK;
if (otOBJ_QUERY_TYPE(pPicInfo) != LINK)
return(vcpLimParaCache);
if (ObjMakeObjectReady(pPicInfo,doc,cpParaStart))
return cp0;
/* Change the link information */
/* if theres a newname, then use it. Else get a new name from user */
olestat = ObjGetData(lpOBJ_QUERY_INFO(pPicInfo), vcfLink, &hData);
if ((olestat == OLE_WARN_DELETE_DATA) || (olestat == OLE_OK))
{
if (!(hNewData = ObjMakeNewLinkName(hData, aNewName))
|| !ObjSetData(pPicInfo, vcfLink, hNewData))
goto end;
if (olestat == OLE_WARN_DELETE_DATA)
GlobalFree(hData);
/* this may not be necessary any more, check carefully. */
if (ObjUpdateObjectInDoc(pPicInfo,doc,cpParaStart) == cp0)
goto end;
fOBJ_QUERY_DIRTY_OBJECT(pPicInfo) = TRUE;
fOBJ_BADLINK(pPicInfo) = FALSE;
cpRetval = vcpLimParaCache;
}
end:
if (hNewData)
GlobalFree(hNewData);
return cpRetval;
}
typeCP ObjUpdateLinkInDoc(OBJPICINFO *pPicInfo,int doc,typeCP cpParaStart)
/**
Change or update link to aNewName if == aOldName. Assumes vbChangeOther
has been initialized.
**/
{
HANDLE hData;
char szRename[cchMaxSz];
if (otOBJ_QUERY_TYPE(pPicInfo) != LINK)
return(vcpLimParaCache);
if (aOBJ_QUERY_DOCUMENT_LINK(pPicInfo) == aOldName)
/* Change the link information */
{
if (bLinkProps && bOBJ_WAS_UPDATED(pPicInfo))
return(vcpLimParaCache);
if (!fUpdateAll)
{
char szTmp[sizeof(szRename) + 90];
char szLink[30],szDocName[30];
CHAR szDocPath[ cchMaxFile ];
CHAR szFullPath[ cchMaxFile ];
SplitSzFilename( (**((**hpdocdod)[doc].hszFile)), szDocPath, szDocName );
GetAtomName(aOBJ_QUERY_DOCUMENT_LINK(pPicInfo),szFullPath,sizeof(szFullPath));
SplitSzFilename( szFullPath, szDocPath, szLink );
if (!szDocName[0])
LoadString(hINSTANCE, IDSTRUntitledDef, szDocName, sizeof(szDocName));
/* Ask the user if they want to update the links */
if (vbChangeOther)
LoadString(hINSTANCE, IDSTRRename, szRename, sizeof(szRename));
else // update other
LoadString(hINSTANCE, IDSTRUpdate, szRename, sizeof(szRename));
/* cast cause compiler is screwing up */
wsprintf((LPSTR)szTmp,(LPSTR)szRename,(LPSTR)szLink,(LPSTR)szDocName,(LPSTR)szLink);
if (MessageBox(hPARENTWINDOW, szTmp, szAppName,
MB_YESNO|MB_ICONEXCLAMATION) == IDNO)
return cp0;
ObjCachePara(doc,cpParaStart); // MessageBox screws things up
fUpdateAll = TRUE;
}
if (vbChangeOther)
{
if (ObjBackupInDoc(pPicInfo,doc,cpParaStart))
return ObjChangeLinkInDoc(pPicInfo,doc,cpParaStart);
}
else
{
if (ObjBackupInDoc(pPicInfo,doc,cpParaStart))
return ObjUpdateObjectInDoc(pPicInfo,doc,cpParaStart);
}
}
return(vcpLimParaCache);
}
typeCP ObjCloseObjectInDoc(OBJPICINFO *pPicInfo, int doc, typeCP cpParaStart)
{
if (lpOBJ_QUERY_INFO(pPicInfo) == NULL)
return(cp0);
if (lpOBJ_QUERY_OBJECT(pPicInfo) == NULL)
return(vcpLimParaCache);
if (otOBJ_QUERY_TYPE(pPicInfo) == STATIC) // nothing to close
return(vcpLimParaCache);
if (ObjWaitForObject(lpOBJ_QUERY_INFO(pPicInfo),TRUE))
return cp0;
/*
Note that if this is an unfinished object, then the OLE_CLOSE
(whenever it happens to arrive) will cause the picinfo to be
deleted.
*/
if (ObjError(OleClose(lpOBJ_QUERY_OBJECT(pPicInfo))))
return(cp0);
return(vcpLimParaCache);
}
/****************************************************************/
/****************** OLE OBJECT DATA I/O *************************/
/****************************************************************/
static typeCP ObjWriteDataToDoc(LPOLEOBJECT lpObject)
/*
Return cp after end of paragraph we've created or 0 if error.
Assume ObjStream is initialized.
*/
{
BOOL fSaveError = ferror;
if (vfOutOfMemory || vfSysFull /*|| ObjStop*/)
return cp0;
Assert(!ferror);
ferror = FALSE; /* so we can still call Replace(). */
if (ObjError(OleSaveToStream(lpObject,lpStream)))
{
if (ferror)
/* uh oh, hope we can clean up enough to look clean */
{
/* delete what we inserted if possible */
ferror = FALSE;
Replace(docStream, cpObjectDataBase - cchPICINFOX, cpObjectDataCurLoc - cpObjectDataBase + cchPICINFOX, fnNil, fc0, fc0);
ferror = TRUE;
return cp0;
}
}
/* is this call necessary? Important to do if InsertRgch doesn't. */
ObjCachePara(docStream,cpObjectDataBase - cchPICINFOX);
ferror = fSaveError || ferror;
return vcpLimParaCache; // cp after para we just inserted
}
/****************************************************************/
/******************** OLE STREAM I/O ****************************/
/****************************************************************/
static
ObjOpenStreamIO(typeCP cpParaStart, int doc, struct CHP *pchp, struct PAP *ppapGraph, DWORD dwObjectSize)
{
if (cpObjectDataCurLoc)
ObjCloseStreamIO();
cpObjectDataBase = cpObjectDataCurLoc = cpParaStart;
cObjectData = 0L;
dwDataMax = dwObjectSize;
docStream = doc;
pchpStream = pchp;
ppapStream = ppapGraph;
}
static void
ObjCloseStreamIO(void)
{
cpObjectDataBase = cpObjectDataCurLoc = cp0;
}
LONG FAR PASCAL BufReadStream(LPOLESTREAM lpStream, char huge *lpstr, DWORD cb)
{
DWORD dwRetval;
typeCP cpMac = vcpLimParaCache;
int cchRun;
if ((cb + cpObjectDataCurLoc) > cpMac) // reading past end of para
{
Assert(0);
return 0L;
}
for ( dwRetval = 0L;
cb;
cb -= cchRun,
cObjectData += cchRun,
cpObjectDataCurLoc += (typeCP) cchRun,
dwRetval += cchRun)
{
CHAR rgch[ 255 ];
register char *chT;
register unsigned cchT;
unsigned cch = ulmin(cb, 255L);
FetchRgch( &cchRun, rgch, docStream, cpObjectDataCurLoc, cpMac, cch);
if (ferror)
return -dwRetval;
for(chT = rgch,cchT=cchRun; cchT--; )
*lpstr++ = *chT++;
}
return dwRetval;
}
LONG FAR PASCAL BufWriteStream(LPOLESTREAM lpStream, char huge *lpstr, DWORD cb)
{
DWORD dwRetval;
char *chT;
unsigned cchT;
CHAR rgch[255];
unsigned cch;
struct PAP *ppap=NULL;
for ( dwRetval = 0L;
dwRetval < cb;
cpObjectDataCurLoc += (typeCP) cch,
cObjectData += cch,
dwRetval += cch)
{
cch = ulmin(cb - dwRetval, 255L);
for(chT = rgch,cchT=cch; cchT--;)
*chT++ = *lpstr++;
if ((cObjectData + cch) == dwDataMax)
ppap = ppapStream;
InsertRgch( docStream, cpObjectDataCurLoc, rgch, cch, pchpStream, ppap);
if (ferror)
return 0L;
}
return dwRetval;
}
ObjGetPicInfo(LPOLEOBJECT lpObject, int doc, OBJPICINFO *pPicInfo, typeCP *pcpParaStart)
/* get picInfo that has lpObject */
/* !!! since writing this it has occurred to me that a quicker way to do
this would be to keep a list of pieces that point to objects. Pieces
never */
{
OBJPICINFO picInfoT;
typeCP cpStart,cpMac= CpMacText(doc);
for (cpStart = cpNil; ObjPicEnumInRange(&picInfoT,doc,cp0,cpMac,&cpStart); )
{
if (lpOBJ_QUERY_INFO(&picInfoT) == NULL)
continue;
if (lpOBJ_QUERY_OBJECT(&picInfoT) == lpObject) // bingo
{
if (pPicInfo)
*pPicInfo = picInfoT;
if (pcpParaStart)
*pcpParaStart = cpStart;
return TRUE;
}
}
return FALSE;
}
BOOL vfObjDisplaying=FALSE;
BOOL ObjSetPicInfo(OBJPICINFO *pSrcPicInfo, int doc, typeCP cpParaStart)
{
/*
NOTE that you only gotta call this when you change the OBJPICINFO fields:
mm,
objecttype,
dwDataSize,
dwObjNum, or
lpObjInfo.
*/
BOOL bError = FALSE;
typeFC fcT;
extern BOOL vfInvalid;
BOOL vfSaveInvalid = vfInvalid;
BOOL docDirty = (**hpdocdod) [doc].fDirty;
ObjPushParms(doc);
ObjCachePara(doc,cpParaStart);
if (vfObjDisplaying)
vfInvalid = FALSE; // this'll suppress things that mess up UpdateWw()
bNoEol = TRUE;
if (dwOBJ_QUERY_DATA_SIZE(pSrcPicInfo) == 0L)
/* is this ever executed? */
{
struct CHP chp;
/* problem is to retain graphics property of picinfo structure */
GetChp(&chp, cpParaStart, doc); // calls CachePara
NewChpIns(&chp);
ObjUpdateFromObjInfo(pSrcPicInfo);
pSrcPicInfo->mm |= MM_EXTENDED;
InsertRgch( doc, cpParaStart + (typeCP)cchPICINFOX, pSrcPicInfo,
(unsigned)cchPICINFOX, &chp, &vpapAbs );
pSrcPicInfo->mm &= ~MM_EXTENDED;
if (ferror)
return TRUE;
/* delete old pieces (in front) that pointed to duped data */
Replace(doc, cpParaStart, (typeCP)cchPICINFOX, fnNil, fc0, fc0);
}
else
{
ObjUpdateFromObjInfo(pSrcPicInfo);
pSrcPicInfo->mm |= MM_EXTENDED;
fcT = FcWScratch( pSrcPicInfo, cchPICINFOX );
pSrcPicInfo->mm &= ~MM_EXTENDED;
if (ferror)
return TRUE;
Replace( doc, cpParaStart, (typeCP)cchPICINFOX,
fnScratch, fcT, (typeFC)cchPICINFOX);
}
if (ferror)
return TRUE;
bNoEol = FALSE;
if (vfObjDisplaying)
vfInvalid = vfSaveInvalid;
/* don't want this to affect docDirty flag */
(**hpdocdod) [doc].fDirty = docDirty;
ObjPopParms(TRUE);
return bError;
}
void ChangeOtherLinks(int doc, BOOL bChange, BOOL bPrompt)
/** For any items == aOldName, set to aNewName. Query user if OK first.
Assumes aOldName and aNewName are set. (See FixInvalidLink() and
ObjChangeLinkInDoc()).
bChange is TRUE if ChangeLink, FALSE if UpdateObject.
bPrompt is TRUe if prompt user for change.
**/
{
fUpdateAll = !bPrompt;
vbChangeOther = bChange; // TRUE to change links, FALSE to update links
ObjEnumInDoc(doc,ObjUpdateLinkInDoc);
}
BOOL ObjQueryNewLinkName(OBJPICINFO *pPicInfo,int doc,typeCP cpParaStart)
/** Return whether obtained new link name from user. Set aOldName
and aNewName. **/
{
HANDLE hData,hNewData=NULL;
LPSTR lpdata=NULL;
BOOL bRetval = FALSE;
OLESTATUS olestat=OLE_OK;
if (lpOBJ_QUERY_INFO(pPicInfo) == NULL)
return(FALSE);
if (otOBJ_QUERY_TYPE(pPicInfo) != LINK)
return(FALSE);
if (ObjMakeObjectReady(pPicInfo,doc,cpParaStart))
return(FALSE);
/* query user for new name */
olestat = ObjGetData(lpOBJ_QUERY_INFO(pPicInfo), vcfLink, &hData);
if ((olestat == OLE_WARN_DELETE_DATA) || (olestat == OLE_OK))
if (!(hNewData = OfnGetNewLinkName(hPARENTWINDOW, hData)))
goto end;
if (olestat == OLE_WARN_DELETE_DATA)
GlobalFree(hData);
aOldName = aOBJ_QUERY_DOCUMENT_LINK(pPicInfo);
lpdata=MAKELP(hNewData,0);
while (*lpdata++);
aNewName = AddAtom(lpdata);
bRetval = TRUE;
end:
if (olestat == OLE_WARN_DELETE_DATA)
GlobalFree(hData);
if (hNewData)
GlobalFree(hNewData);
return bRetval;
}
FixInvalidLink(OBJPICINFO far *lpPicInfo, int doc, typeCP cpParaStart)
/* returns FALSE if couldn't or wouldn't do anything, RETRY if reset link */
{
fOBJ_BADLINK(lpPicInfo) = TRUE;
if (DialogBox(hINSTANCE, "DTINVALIDLINK",
hPARENTWINDOW, lpfnInvalidLink) == IDD_CHANGE)
#if !defined(SMALL_OLE_UI)
fnObjProperties();
#else
ObjChangeLinkInDoc(lpPicInfo,doc,cpParaStart);
#endif
return FALSE;
}
/* ObjMakeNewLinkName() - Constructs a new link name from an atom.
*/
static HANDLE ObjMakeNewLinkName(HANDLE hData, ATOM atom)
{
BOOL fSuccess = FALSE;
HANDLE hData2 = NULL;
HANDLE hData3 = NULL;
LPSTR lpstrData = NULL;
LPSTR lpstrLink = NULL;
LPSTR lpstrTemp;
char szFile[CBPATHMAX];
if (!GetAtomName(atom, szFile, CBPATHMAX)
|| !(lpstrData = (LPSTR)GlobalLock(hData))
|| !(hData2 = GlobalAlloc(GMEM_DDESHARE | GMEM_ZEROINIT, CBPATHMAX * 2))
|| !(lpstrLink = lpstrTemp = (LPSTR)GlobalLock(hData2)))
goto Error;
/* ... copy the server name */
while (*lpstrTemp++ = *lpstrData++);
/* ... copy the document name */
lstrcpy(lpstrTemp, szFile);
lpstrTemp += lstrlen(lpstrTemp) + 1;
lpstrData += lstrlen(lpstrData) + 1;
/* ... copy the item name */
while (*lpstrTemp++ = *lpstrData++);
*lpstrTemp = 0;
/* ... and compress the memory block to minimal size */
GlobalUnlock(hData2);
hData3 = GlobalReAlloc(hData2, (DWORD)(lpstrTemp - lpstrLink + 1), 0);
if (!hData3)
hData3 = hData2;
fSuccess = TRUE;
Error:
if (!fSuccess) {
if (lpstrLink)
GlobalUnlock(hData2);
if (hData2)
GlobalFree(hData2);
hData3 = NULL;
}
if (lpstrData)
GlobalUnlock(hData);
return hData3;
}
char *ObjGetServerName(LPOLEOBJECT lpObject, char *szServerName)
{
LPSTR lpstrData;
HANDLE hData;
LONG otobject;
OLESTATUS olestat;
/** NOTE: OleGetData can return OLE_BUSY. Because of how
ObjGetServerName is used, we're not going to wait for the
object here, we'll just return if its busy **/
if (OleQueryReleaseStatus(lpObject) == OLE_BUSY)
return NULL;
if (ObjError(OleQueryType(lpObject,&otobject)))
return NULL;
olestat = OleGetData(lpObject,
otobject == OT_LINK ? vcfLink : vcfOwnerLink,
&hData);
if ((olestat != OLE_WARN_DELETE_DATA) && (olestat != OLE_OK))
{
ObjError(olestat);
return NULL;
}
lpstrData = MAKELP(hData,0);
RegGetClassId(szServerName, lpstrData);
if (olestat == OLE_WARN_DELETE_DATA)
GlobalFree(hData);
return szServerName;
}
/* OfnInit() - Initializes the standard file dialog OFN structure.
*/
void OfnInit(HANDLE hInst) {
LPSTR lpstr;
OFN.lStructSize = sizeof(OPENFILENAME);
OFN.hInstance = hInst;
OFN.nMaxCustFilter = CBFILTERMAX;
OFN.nMaxFile = CBPATHMAX;
OFN.Flags = OFN_HIDEREADONLY;
OFN.lCustData = NULL;
OFN.lpfnHook = NULL;
OFN.lpTemplateName = NULL;
OFN.lpstrDefExt = NULL;
OFN.lpstrFileTitle = NULL;
LoadString(hInst, IDSTRChangelink, szLinkCaption, sizeof(szLinkCaption));
}
/* OfnGetNewLinkName() - Sets up the "Change Link..." dialog box
*/
static HANDLE OfnGetNewLinkName(HWND hwnd, HANDLE hData)
{
BOOL fSuccess = FALSE;
HANDLE hData2 = NULL;
HANDLE hData3 = NULL;
LPSTR lpData2 = NULL;
LPSTR lpstrData = NULL;
LPSTR lpstrFile = NULL;
LPSTR lpstrLink = NULL;
LPSTR lpstrPath = NULL;
LPSTR lpstrTemp = NULL;
char szDocFile[CBPATHMAX];
char szDocPath[CBPATHMAX];
HANDLE hServerFilter=NULL;
/* Get the link information */
if (!(lpstrData = GlobalLock(hData)))
goto Error;
/* Figure out the link's path name and file name */
lpstrTemp = lpstrData;
while (*lpstrTemp++);
lpstrPath = lpstrFile = lpstrTemp;
while (*(lpstrTemp = AnsiNext(lpstrTemp)))
if (*lpstrTemp == '\\')
lpstrFile = lpstrTemp + 1;
/* Copy the document name */
lstrcpy(szDocFile, lpstrFile);
*(lpstrFile - 1) = 0;
/* Copy the path name */
lstrcpy(szDocPath, ((lpstrPath != lpstrFile) ? lpstrPath : ""));
if (lpstrPath != lpstrFile) /* Restore the backslash */
*(lpstrFile - 1) = '\\';
while (*lpstrFile != '.' && *lpstrFile) /* Get the extension */
lpstrFile++;
/* Make a filter that respects the link's class name */
OFN.hwndOwner = hwnd;
OFN.nFilterIndex = RegMakeFilterSpec(lpstrData, lpstrFile, &hServerFilter);
if (OFN.nFilterIndex == -1)
goto Error;
OFN.lpstrFilter = (LPSTR)MAKELP(hServerFilter,0);
Normalize(szDocFile);
OFN.lpstrFile = (LPSTR)szDocFile;
OFN.lpstrInitialDir = (LPSTR)szDocPath;
OFN.lpstrTitle = (LPSTR)szLinkCaption;
OFN.lpstrCustomFilter = (LPSTR)szCustFilterSpec;
/* If we get a file... */
if (GetOpenFileName((LPOPENFILENAME)&OFN))
{
if (!(hData2 = GlobalAlloc(GMEM_DDESHARE | GMEM_ZEROINIT, CBPATHMAX * 2))
|| !(lpstrLink = lpstrTemp = GlobalLock(hData2)))
goto Error;
/* ... copy the server name */
while (*lpstrTemp++ = *lpstrData++);
/* ... copy the document name */
lstrcpy(lpstrTemp, szDocFile);
lpstrTemp += lstrlen(lpstrTemp) + 1;
lpstrData += lstrlen(lpstrData) + 1;
/* ... copy the item name */
while (*lpstrTemp++ = *lpstrData++);
*lpstrTemp = 0;
/* ... and compress the memory block to minimal size */
GlobalUnlock(hData2);
hData3 = GlobalReAlloc(hData2, (DWORD)(lpstrTemp - lpstrLink + 1), 0);
if (!hData3)
hData3 = hData2;
fSuccess = TRUE;
}
Error:
if (!fSuccess)
{
if (lpstrLink)
GlobalUnlock(hData2);
if (hData2)
GlobalFree(hData2);
hData3 = NULL;
}
if (lpstrData)
GlobalUnlock(hData);
if (hServerFilter)
GlobalFree(hServerFilter);
return hData3;
}
/* Normalize() - Removes the path specification from the file name.
*
* Note: It isn't possible to get "<drive>:<filename>" as input because
* the path received will always be fully qualified.
*/
static void Normalize(LPSTR lpstrFile)
{
LPSTR lpstrBackslash = NULL;
LPSTR lpstrTemp = lpstrFile;
while (*lpstrTemp) {
if (*lpstrTemp == '\\')
lpstrBackslash = lpstrTemp;
lpstrTemp = AnsiNext(lpstrTemp);
}
if (lpstrBackslash)
lstrcpy(lpstrFile, lpstrBackslash + 1);
}
/* ObjSetUpdateOptions() - Sets the update options of the object.
*
* Returns: TRUE iff the command completed successfully
*/
BOOL ObjSetUpdateOptions(OBJPICINFO *pPicInfo, WORD wParam, int doc, typeCP cpParaStart)
/* !!! Used by Link Properties only!!! Object guaranteed loaded */
{
if (ObjWaitForObject(lpOBJ_QUERY_INFO(pPicInfo),TRUE))
{
Error(IDPMTFailedToUpdateLink);
return FALSE;
}
if (ObjError(OleSetLinkUpdateOptions(lpOBJ_QUERY_OBJECT(pPicInfo),
(wParam == IDD_AUTO) ? oleupdate_always : oleupdate_oncall)))
{
Error(IDPMTFailedToUpdateLink);
return FALSE;
}
fOBJ_QUERY_DIRTY_OBJECT(pPicInfo) = TRUE;
return TRUE;
}
/* ObjGetUpdateOptions() - Retrieves the update options of the object.
*/
OLEOPT_UPDATE ObjGetUpdateOptions(OBJPICINFO far *lpPicInfo)
/* !!! Used by Link Properties only!!! Object guaranteed loaded */
{
BOOL fSuccess = FALSE;
OLEOPT_UPDATE fUpdate;
if (otOBJ_QUERY_TYPE(lpPicInfo) == LINK)
{
if (ObjWaitForObject(lpOBJ_QUERY_INFO(lpPicInfo),TRUE))
return FALSE;
fSuccess = !ObjError(OleGetLinkUpdateOptions(lpOBJ_QUERY_OBJECT(lpPicInfo), &fUpdate));
}
return (fSuccess ? fUpdate : oleupdate_onsave);
}
OLESTATUS ObjGetData(LPOBJINFO lpObjInfo, OLECLIPFORMAT cf, HANDLE far *lphData)
/*
Return olestat.
Put handle to data into lphData.
Assumes object is loaded.
*/
{
HANDLE hData;
OLESTATUS olestat;
if (ObjWaitForObject(lpObjInfo,TRUE))
return OLE_BUSY;
olestat = OleGetData(lpObjInfo->lpobject, cf, lphData);
if ((olestat != OLE_WARN_DELETE_DATA) && (olestat != OLE_OK))
ObjError(olestat);
return olestat;
}
/* ObjSetData() - Set the object's (link) information
Sets DOCUMENT_LINK ATOM in pPicInfo
*/
BOOL ObjSetData(OBJPICINFO far *lpPicInfo, OLECLIPFORMAT cf, HANDLE hData)
/* assumes object is loaded */
{
HANDLE hitem;
LPSTR lpdata;
if (ObjWaitForObject(lpOBJ_QUERY_INFO(lpPicInfo),TRUE))
return FALSE;
if (ObjError(OleSetData(lpOBJ_QUERY_OBJECT(lpPicInfo), cf, hData)))
return FALSE;
/* If we have a link, update the document name */
if (cf == vcfLink && (lpdata = GlobalLock(hData)))
{
ATOM aSaveOld = aOBJ_QUERY_DOCUMENT_LINK(lpPicInfo);
while (*lpdata++);
aOBJ_QUERY_DOCUMENT_LINK(lpPicInfo) = AddAtom(lpdata);
if (aSaveOld)
DeleteAtom(aSaveOld);
GlobalUnlock(hData);
}
else
return FALSE;
return TRUE;
}
int ObjSetSelectionType(int doc, typeCP cpFirst, typeCP cpLim)
{
/* set whether link or emb selected */
OBJ_SELECTIONTYPE = NONE; // this'll be set by ObjCheckObjectTypes()
//OBJ_CEMBEDS = 0; // this'll be set by ObjCheckObjectTypes()
return ObjEnumInRange(doc,cpFirst,cpLim,ObjCheckObjectTypes);
}
BOOL ObjQueryCpIsObject(int doc,typeCP cpFirst)
{
OBJPICINFO picInfo;
/* assume its cached already! */
//ObjCachePara(doc,cpFirst); /* NOTE side effect of caching */
if (!vpapAbs.fGraphics)
return FALSE;
if (cpFirst >= CpMacText(doc))
return FALSE;
GetPicInfo(cpFirst,cpFirst + cchPICINFOX, doc, &picInfo);
return bOBJ_QUERY_IS_OBJECT(&picInfo);
}
ATOM MakeLinkAtom(LPOBJINFO lpObjInfo)
{
HANDLE hData;
LPSTR lpdata;
ATOM aRetval=NULL;
OLESTATUS olestat=OLE_OK;
olestat = ObjGetData(lpObjInfo, vcfLink, &hData);
if ((olestat == OLE_WARN_DELETE_DATA) || (olestat == OLE_OK))
{
lpdata = MAKELP(hData,0);
while (*lpdata++);
aRetval = AddAtom(lpdata);
if (olestat == OLE_WARN_DELETE_DATA)
GlobalFree(hData);
}
return aRetval;
}
#include <time.h>
void ObjGetObjectName(LPOBJINFO lpObjInfo, szOBJNAME szObjName)
/* put object name from ObjInfo into szObjName */
{
if (szObjName && lpObjInfo)
GetAtomName(lpObjInfo->aObjName,szObjName,sizeof(szObjName));
}
void ObjMakeObjectName(LPOBJINFO lpObjInfo, LPSTR lpstr)
{
szOBJNAME szObjName;
time_t lTime;
time(&lTime);
wsprintf(szObjName, "%lx", lTime);
if (lpObjInfo)
lpObjInfo->aObjName = AddAtom(szObjName);
if (lpstr)
lstrcpy(lpstr,szObjName);
}
static void GetChp(struct CHP *pchp, typeCP cp, int doc)
{
/**
Return chp at cp in *pchp.
Resets Cache to cp when done.
We assume that we're always inserting after an EOL or at beginning of
document.
**/
extern struct CHP vchpAbs;
if (cp == cp0) // beginning of doc
{
typeCP cpMac = CpMacText(doc);
if (cpMac == cp0) // empty doc
{
/* force default character properties, font size to be 10 point */
*pchp = vchpNormal;
pchp->hps = hpsDefault;
return;
}
else // get next char props
{
ObjCachePara(doc,cp+1); // to reset
FetchCp( doc, cp+1, 0, fcmProps );
}
}
else
{
ObjCachePara(doc,cp-1); // to reset
FetchCp( doc, cp-1, 0, fcmProps ); // previous paragraph's chp
}
*pchp = vchpAbs;
if (pchp->fSpecial && pchp->hpsPos != 0)
{ /* if this char is a footnote or page marker, then ignore */
pchp->hpsPos = 0; /* super/subscript stuff. */
pchp->hps = HpsAlter(pchp->hps, 1);
}
pchp->fSpecial = fFalse;
ObjCachePara(doc,cp); // to reset
}
BOOL ObjSetHostName(LPOBJINFO lpOInfo, int doc)
/* TRUE if error */
/* we assume object ain't busy!!! */
{
extern CHAR szUntitled[20];
CHAR *PchStartBaseNameSz(),*szTitle= **((**hpdocdod)[doc].hszFile);
if (szTitle[0])
szTitle = PchStartBaseNameSz(szTitle);
else
szTitle = szUntitled;
#ifdef DEBUG
OutputDebugString( (LPSTR) "Setting host name\n\r");
#endif
/*
Note that OleSetHostNames can return OLE_BUSY!!! So you
better call ObjWaitForObject() first.
*/
if (ObjError(OleSetHostNames(lpOInfo->lpobject,szAppName,szTitle)))
return TRUE;
return FALSE;
}
BOOL ObjMakeObjectReady(OBJPICINFO *pPicInfo, int doc, typeCP cpParaStart)
/* Load object, complete async. Return whether an error. */
{
if (lpOBJ_QUERY_INFO(pPicInfo) == NULL)
return TRUE;
if (lpOBJ_QUERY_OBJECT(pPicInfo) == NULL)
{
if (ObjLoadObjectInDoc(pPicInfo,doc,cpParaStart) == cp0)
return TRUE;
}
else if (ObjWaitForObject(lpOBJ_QUERY_INFO(pPicInfo),TRUE))
return TRUE;
ObjCachePara(doc, cpParaStart);
return FALSE;
}
|