Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

956 lines
27 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* clipbord.c -- Cut/Paste to clipboard */
  5. #define NOVIRTUALKEYCODES
  6. #define NOWINSTYLES
  7. #define NOGDICAPMASKS
  8. #define NOSYSMETRICS
  9. #define NOMENUS
  10. #define NOCTLMGR
  11. #define NOFONT
  12. #define NOPEN
  13. #define NOBRUSH
  14. #define NOSCROLL
  15. #define NOCOMM
  16. #define NOWNDCLASS
  17. #include <windows.h>
  18. #include "mw.h"
  19. #include "docdefs.h"
  20. #include "cmddefs.h"
  21. #include "str.h"
  22. #include "propdefs.h"
  23. #include "editdefs.h"
  24. #include "winddefs.h"
  25. #include "filedefs.h"
  26. #include "wwdefs.h"
  27. #include "prmdefs.h"
  28. #if defined(OLE)
  29. #include "obj.h"
  30. #endif
  31. #ifdef JAPAN //T-HIROYN Win3.1
  32. #include "kanji.h"
  33. #endif
  34. #include "debug.h"
  35. extern struct SEL selCur; /* Current selection (i.e., sel in current ww */
  36. extern int docCur; /* Document in current ww */
  37. extern int docUndo;
  38. extern int docScrap;
  39. extern int vfSeeSel;
  40. extern struct DOD (**hpdocdod)[];
  41. extern struct PAP vpapAbs;
  42. extern typeCP vcpLimParaCache;
  43. extern typeCP vcpFirstParaCache;
  44. extern int vfPictSel;
  45. extern HCURSOR vhcIBeam;
  46. extern int vfScrapIsPic;
  47. extern struct UAB vuab;
  48. extern int ferror;
  49. extern struct FCB (**hpfnfcb)[];
  50. extern struct WWD rgwwd[];
  51. /* THESE ARE LOCAL TO THIS MODULE */
  52. #if defined(OLE)
  53. int NEAR PASCAL CopyScrapToTmp(void);
  54. #endif
  55. /* fn we created during the last non-local cut of MEMO rich text */
  56. int fnLastCut=fnNil;
  57. /* Local communication between ChangeClipboard() and MdocDestroyClip() */
  58. int fDontDestroyClip=FALSE;
  59. FMdocClipboardMsg( message, wParam, lParam )
  60. unsigned message;
  61. WORD wParam;
  62. LONG lParam;
  63. { /* Process WRITE clipboard messages sent to MdocWndproc.
  64. return TRUE if a message was processed, FALSE otherwise */
  65. switch (message)
  66. {
  67. default:
  68. return FALSE;
  69. /*-------DATA INTERCHANGE COMMANDS-----------*/
  70. case WM_CUT:
  71. fnCutEdit();
  72. break;
  73. case WM_COPY:
  74. fnCopyEdit();
  75. break;
  76. case WM_PASTE:
  77. #if defined(OLE)
  78. vbObjLinkOnly = FALSE;
  79. #endif
  80. fnPasteEdit();
  81. break;
  82. case WM_CLEAR:
  83. fnClearEdit(OBJ_DELETING);
  84. break;
  85. case WM_UNDO:
  86. fnUndoEdit();
  87. break;
  88. /*---------------CLIPBOARD INTERACTION-------------*/
  89. case WM_DESTROYCLIPBOARD:
  90. /* A notification that we are about to lose the ownership
  91. of the clipboard. We should free any resources that are
  92. holding the contents of the clipboard */
  93. MdocDestroyClip();
  94. break;
  95. case WM_RENDERFORMAT:
  96. /* A request to render the contents of the clipboard
  97. in the data format specified. Reception of this message
  98. implies that the receiver is the current owner of the
  99. clipboard. See clipbord.c */
  100. MdocRenderFormat( wParam );
  101. break;
  102. /*-------CLIPBOARD DISPLAY---------------------*/
  103. case WM_PAINTCLIPBOARD:
  104. /* A request to paint the clipboard contents.
  105. wParam is a handle to the clipboard window
  106. LOWORD( lParam ) is a handle to a PAINTSTRUCT giving
  107. a DC and RECT for the area to repaint */
  108. MdocPaintClipboard( wParam, LOWORD(lParam) );
  109. break;
  110. case WM_VSCROLLCLIPBOARD:
  111. /* A request to vertically scroll the clipboard contents.
  112. wParam is a handle to the clipboard window
  113. LOWORD( lParam ) is the scroll type (SB_)
  114. HIWORD( lParam ) is the new thumb position (if needed) */
  115. MdocVscrollClipboard( wParam, LOWORD(lParam), HIWORD(lParam) );
  116. break;
  117. case WM_HSCROLLCLIPBOARD:
  118. /* A request to horizontally scroll the clipboard contents.
  119. wParam is a handle to the clipboard window
  120. LOWORD( lParam ) is the scroll type (SB_)
  121. HIWORD( lParam ) is the new thumb position (if needed) */
  122. MdocHscrollClipboard( wParam, LOWORD(lParam), HIWORD(lParam) );
  123. break;
  124. case WM_SIZECLIPBOARD:
  125. /* A notification that the clipboard window is being re-sized.
  126. wParam is a handle to the clipboard window
  127. LOWORD(lParam) is a handle to a RECT giving the new size */
  128. MdocSizeClipboard( wParam, LOWORD(lParam) );
  129. break;
  130. case WM_ASKCBFORMATNAME:
  131. /* A request for the name of the CF_OWNERDISPLAY clip format.
  132. wParam is the max. # of chars to store (including terminator)
  133. lParam is a long pointer to a buffer in which to store the name */
  134. MdocAskCBFormatName( (LPCH) lParam, wParam );
  135. break;
  136. }
  137. return TRUE;
  138. }
  139. fnCopyEdit()
  140. { /* COPY command: copy selection to clipboard */
  141. extern int vfOwnClipboard;
  142. typeCP cpFirst;
  143. typeCP dcp;
  144. StartLongOp();
  145. cpFirst = selCur.cpFirst;
  146. SetUndo( uacReplScrap, docCur, cpFirst, dcp = selCur.cpLim - cpFirst,
  147. docNil, cpNil, cp0, 0);
  148. SetUndoMenuStr(IDSTRUndoEdit);
  149. ClobberDoc(docScrap, docCur, cpFirst, dcp);
  150. #ifdef DCLIP
  151. {
  152. char rgch[100];
  153. wsprintf(rgch,"fnCopyEdit: cpFirst %lu, dcp %lu \n\r", cpFirst, dcp);
  154. CommSz(rgch);
  155. }
  156. #endif
  157. if (ferror)
  158. NoUndo();
  159. else
  160. {
  161. if (wwdCurrentDoc.fEditHeader || wwdCurrentDoc.fEditFooter)
  162. MakeScrapUnRunning();
  163. vfScrapIsPic = vfPictSel;
  164. }
  165. #ifdef STYLES
  166. (**hpdocdod)[docScrap].docSsht = (**hpdocdod)[docCur].docSsht;
  167. #endif
  168. #if defined(OLE)
  169. ObjEnumInDoc(docScrap,ObjCloneObjectInDoc);
  170. #endif
  171. ChangeClipboard(); /* Force repaint of clipboard display & Set ownership */
  172. EndLongOp(vhcIBeam);
  173. }
  174. MakeScrapUnRunning()
  175. { /* If the 1st para of docScrap is a running head,
  176. apply a sprm to the whole of docScrap that gives it an rhc code of 0.
  177. This is to avoid pasting running head stuff into the main part of a doc */
  178. CHAR rgb [2];
  179. typeCP cpMacScrap = (**hpdocdod) [docScrap].cpMac;
  180. if (cpMacScrap != cp0 )
  181. {
  182. CachePara( docScrap, cp0 );
  183. if (vpapAbs.rhc != 0)
  184. {
  185. rgb [0] = sprmPRhc;
  186. rgb [1] = 0;
  187. AddSprmCps( rgb, docScrap, cp0, cpMacScrap );
  188. }
  189. }
  190. }
  191. fnCutEdit()
  192. { /* CUT command: copy selection to clipboard & delete it */
  193. extern int vfOwnClipboard;
  194. typeCP cpFirst, cpLim, dcp;
  195. ClearInsertLine(); /* Since we will be affecting cp's */
  196. if (!FWriteOk( fwcDelete ))
  197. /* Not OK to write on this doc */
  198. return;
  199. cpFirst = selCur.cpFirst;
  200. cpLim = selCur.cpLim;
  201. if (!ObjDeletionOK(OBJ_CUTTING))
  202. return;
  203. StartLongOp();
  204. SetUndo( uacDelScrap, docCur, cpFirst, dcp = cpLim - cpFirst, docNil,
  205. cpNil, cp0, 0);
  206. ClobberDoc(docScrap, docCur, cpFirst, dcp);
  207. if (wwdCurrentDoc.fEditHeader || wwdCurrentDoc.fEditFooter)
  208. MakeScrapUnRunning();
  209. if (!ferror) /* Don't stomp document if Clobber Doc failed */
  210. {
  211. if (wwdCurrentDoc.fEditHeader || wwdCurrentDoc.fEditFooter)
  212. MakeScrapUnRunning();
  213. Replace(docCur, cpFirst, dcp, fnNil, fc0, fc0);
  214. }
  215. else
  216. NoUndo(); /* undo would be invalid */
  217. #ifdef STYLES
  218. (**hpdocdod)[docScrap].docSsht = (**hpdocdod)[docCur].docSsht;
  219. #endif
  220. vfScrapIsPic = vfPictSel;
  221. vfPictSel = false;
  222. ChangeClipboard(); /* Force repaint of clipboard display, get ownership */
  223. #if 0
  224. #if defined(OLE)
  225. ObjEnumInDoc(docScrap,ObjCloneObjectInDoc);
  226. #endif
  227. #endif
  228. EndLongOp(vhcIBeam);
  229. }
  230. fnPasteEdit()
  231. {
  232. /* PASTE command: replace selection with clipboard contents */
  233. extern CHAR szDocClass[];
  234. extern int vfScrapIsPic;
  235. extern HWND vhWnd;
  236. HWND hWndClipOwner;
  237. int fUnFormattedText = FALSE;
  238. typeCP cpFirst = selCur.cpFirst;
  239. BOOL bClearScrap=FALSE;
  240. StartLongOp();
  241. if ( (hWndClipOwner = GetClipboardOwner()) != vhWnd )
  242. { /* Clipboard owner is not this instance of memo */
  243. if ( (hWndClipOwner == NULL) ||
  244. !FSameClassHwndSz( hWndClipOwner, szDocClass ))
  245. { /* Clipboard owner is not MEMO -- process standard CF_ formats */
  246. if ( !FReadExtScrap() )
  247. goto PasteErr;
  248. bClearScrap = TRUE;
  249. fUnFormattedText = !vfScrapIsPic;
  250. }
  251. else
  252. { /* Clipboard owner is another instance of MEMO */
  253. if (!FGrabExtMemoScrap())
  254. goto PasteErr;
  255. }
  256. }
  257. /* Replace the selection with the scrap document */
  258. CmdInsScrap( fUnFormattedText );
  259. if (ferror)
  260. goto PasteErr;
  261. #if defined(OLE)
  262. if (!bClearScrap) // then we're keeping scrap, need to clone
  263. {
  264. if (ObjEnumInDoc(docScrap,ObjCloneObjectInDoc) < 0)
  265. goto PasteErr;
  266. }
  267. else // then we're not keeping scrap (came from clipboard)
  268. {
  269. /*
  270. We don't need contents anymore, and if it contains an object,
  271. then its got to go because its been inserted into the doc and not cloned
  272. and we don't want a duplicate around.
  273. Also gotta mark the object in docCur as no longer reusable (if
  274. it gets copied later we will need to clone it).
  275. */
  276. typeCP cpLim = cpFirst+CpMacText(docScrap);
  277. ClobberDoc(docScrap,docNil,cp0,cp0);
  278. ObjEnumInRange(docCur,cpFirst,cpLim,ObjFromCloneInDoc);
  279. }
  280. #endif
  281. EndLongOp(vhcIBeam);
  282. return;
  283. PasteErr:
  284. NoUndo();
  285. EndLongOp(vhcIBeam);
  286. _beep();
  287. }
  288. MdocRenderFormat( wCf )
  289. int wCf;
  290. { /* Render clipboard data in format specified by wCf */
  291. typeCP cpMac=CpMacText( docScrap );
  292. struct PICINFOX picInfo;
  293. #if defined(OLE)
  294. if (vfScrapIsPic)
  295. {
  296. GetPicInfo( cp0, cpMac, docScrap, &picInfo );
  297. if ((picInfo.mfp.mm == MM_OLE) && (wCf != CF_OWNERDISPLAY))
  298. goto Render;
  299. }
  300. #endif
  301. switch (wCf) {
  302. case CF_OWNERDISPLAY:
  303. /* Render rich text to another MEMO instance */
  304. FPutExtMemoScrap();
  305. break;
  306. case CF_TEXT:
  307. /* Remove formatting from scrap; put bare text out to clipboard */
  308. goto Render;
  309. case CF_BITMAP:
  310. if (picInfo.mfp.mm == MM_BITMAP)
  311. {
  312. goto Render;
  313. }
  314. break;
  315. case CF_METAFILEPICT:
  316. /* We can supply this if the scrap is a metafile picture */
  317. if (picInfo.mfp.mm != MM_BITMAP)
  318. {
  319. Render:
  320. if (!FWriteExtScrap())
  321. Error( IDPMTClipLarge );
  322. }
  323. break;
  324. }
  325. }
  326. MdocDestroyClip()
  327. { /* Handles WM_DESTROYCLIPBOARD message. We are being notified that
  328. the clipboard is being emptied & we don't need to keep its
  329. contents around anymore. */
  330. extern int vfOwnClipboard;
  331. extern HWND vhWnd;
  332. if (fDontDestroyClip)
  333. return;
  334. vfOwnClipboard = FALSE;
  335. /* Clear out the scrap document */
  336. ClobberDoc( docScrap, docNil, cp0, cp0 );
  337. /* Disable UNDO operations that require the clipboard */
  338. switch (vuab.uac) {
  339. case uacDelScrap:
  340. case uacUDelScrap:
  341. case uacReplScrap:
  342. case uacUReplScrap:
  343. NoUndo();
  344. break;
  345. }
  346. /* Remove all records of the file we generated in FPutExtMemoScrap
  347. from the hpfnfcb array. Note that we assume that no document
  348. in this instance has pieces of fn. */
  349. if ( fnLastCut != fnNil )
  350. {
  351. FreeFn( fnLastCut );
  352. fnLastCut = fnNil;
  353. }
  354. /* If we made a wwd entry for the display of the clipboard,
  355. remove it now. We test here to avoid bringing in the
  356. CLIPDISP module if we never did any display. */
  357. {
  358. if (wwClipboard != wwNil)
  359. FreeWw( wwClipboard );
  360. }
  361. }
  362. int FPutExtMemoScrap()
  363. { /* Write docScrap to a new file; send the normalized name
  364. of the file to the clipboard as data handle for rich text type.
  365. Assumes clipboard is open for SetClipboardData call. On exit,
  366. the file written has an fn, but no document (including docScrap)
  367. has pieces that point to it. This allows us to relinquish
  368. ownership of the fn to the pasting instance.
  369. RETURN: TRUE == OK, FALSE == ERROR
  370. */
  371. int fn;
  372. CHAR szT[ cchMaxFile ];
  373. HANDLE hMem;
  374. LPCH lpch;
  375. int cch;
  376. #if defined(OLE)
  377. int docTemp;
  378. #endif
  379. /* Create a new, formatted file with a unique name */
  380. szT [0] = '\0'; /* Create it on a temp drive in the root */
  381. if ((fn = FnCreateSz( szT, cp0, dtyNetwork ))== fnNil )
  382. {
  383. return FALSE;
  384. }
  385. fnLastCut = fn; /* Save in a static so we can relinquish it later */
  386. /* Save scrap document to file. Note that FWriteFn does NOT modify
  387. the piece table of docScrap, so no document has pieces pointing
  388. to fn. This is important because we don't want local pastes
  389. to generate pieces pointing to this fn; we want to be able to cleanly
  390. transfer ownership of the fn to another instance */
  391. #if defined(OLE)
  392. if ((docTemp = CopyScrapToTmp()) == docNil)
  393. {
  394. FDeleteFn( fn ); /* This will free the fn even if deleting the file
  395. fails */
  396. return FALSE;
  397. }
  398. #endif
  399. if (!FWriteFn( fn, docTemp, TRUE ))
  400. {
  401. FDeleteFn( fn ); /* This will free the fn even if deleting the file
  402. fails */
  403. return FALSE;
  404. }
  405. #if defined(OLE)
  406. if (docTemp != docScrap)
  407. KillDoc (docTemp);
  408. #endif
  409. /* Make a global handle containing the name of the file; send it to the
  410. clipboard as the rendering of the rich text format */
  411. if ( ((hMem = GlobalAlloc( GMEM_MOVEABLE, (LONG)(cch=CchSz( szT ))))== NULL ) ||
  412. ((lpch = GlobalLock( hMem )) == NULL) )
  413. {
  414. return FALSE;
  415. }
  416. bltbx( (LPCH)szT, lpch, cch );
  417. GlobalUnlock( hMem );
  418. SetClipboardData( CF_OWNERDISPLAY, hMem );
  419. return TRUE;
  420. }
  421. int FGrabExtMemoScrap()
  422. {
  423. /* We get here on a PASTE if the clipboard contains rich text from a
  424. MEMO instance other than this one. This routine requests the contents of
  425. the clipboard from the other instance, and places the contents into docScrap.
  426. The contents of the clipboard are passed in a MEMO formatted file, whose
  427. filename is contained in the clipboard's handle. The instance that owns
  428. the clipboard does not keep any references to the fn for the clipboard
  429. file (once we EmptyClipboard). After pasting, this routine arrogates
  430. the ownership of the clipboard to this instance.
  431. returns FALSE=error, true=OK */
  432. extern int vfOwnClipboard;
  433. extern HWND vhWnd;
  434. LPCH lpch;
  435. CHAR szT [cchMaxFile];
  436. int fn;
  437. typeFC dfc;
  438. HANDLE hData;
  439. int fOK=false;
  440. /* Open Clipboard to lock out contenders */
  441. if ( !OpenClipboard( vhWnd ))
  442. {
  443. return FALSE;
  444. }
  445. /* Grab clipboard data handle contents: it is a normalized
  446. filename string referring to a formatted file containing
  447. the rich text. The GetClipboardData call actually initiates
  448. a WM_RENDERFORMAT message to which MdocRenderFormat responds */
  449. if ( ((hData = GetClipboardData( CF_OWNERDISPLAY )) == NULL ) ||
  450. ((lpch = GlobalLock( hData )) == NULL ) )
  451. {
  452. goto GrabErr;
  453. }
  454. bltszx( lpch, (LPCH)szT );
  455. GlobalUnlock( hData ); /* handle will be freed in EmptyClipboard sequence */
  456. /* Open the file; replace the contents of the scrap document
  457. with the contents of the file */
  458. if ((fn = FnOpenSz( szT, dtyNormal, FALSE )) == fnNil)
  459. { /* Unfortunately, if this fails, the file that the other
  460. instance created will "float", with noone holding an fn
  461. for it, and it will not get deleted at the end of the session.
  462. On the bright side, if the reason for the failure was that
  463. the file never got created anyway, we have done exactly right */
  464. goto GrabErr;
  465. }
  466. { /* Opened file OK */
  467. struct FCB *pfcb = &(**hpfnfcb)[fn];
  468. struct FFNTB **hffntb;
  469. struct FFNTB **HffntbCreateForFn();
  470. int wUnused;
  471. pfcb->fDelete = TRUE;
  472. dfc = pfcb->fFormatted ? cfcPage : fc0;
  473. Replace( docScrap,
  474. cp0,
  475. (**hpdocdod)[docScrap].cpMac,
  476. fn,
  477. dfc,
  478. pfcb->fcMac - dfc );
  479. /* give the scrap the correct font table */
  480. FreeFfntb((**hpdocdod)[docScrap].hffntb);
  481. if (FNoHeap(hffntb = HffntbCreateForFn(fn, &wUnused)))
  482. hffntb = 0;
  483. (**hpdocdod)[docScrap].hffntb = hffntb;
  484. }
  485. #if defined(OLE)
  486. /* if there are any objects in there, Load 'em */
  487. if (ObjEnumInDoc(docScrap,ObjLoadObjectInDoc) < 0)
  488. fOK = FALSE;
  489. else
  490. #endif
  491. fOK = !ferror; /* All is well if we didn't run out of memory */
  492. /* Take over ownership of the clipboard. This results in a
  493. WM_DESTROYCLIPBOARD message being sent to the other instance,
  494. which will delete its fn entry for the file so we are the
  495. exclusive owners */
  496. GrabErr:
  497. CloseClipboard();
  498. ChangeClipboard();
  499. return fOK;
  500. }
  501. ChangeClipboard()
  502. { /* Mark clipboard as changed. If we are not the owner of the clipboard, */
  503. /* make us the owner (via EmptyClipboard). The EmptyClipboard call */
  504. /* will result in a WM_DESTROYCLIPBOARD message being sent to the */
  505. /* owning instance. The CloseClipboard call will result in a */
  506. /* WM_DRAWCLIPBOARD message being sent to the clipboard viewer. */
  507. /* If the clipboard viewer is CLIP.EXE, we will get a WM_PAINTCLIPBOARD */
  508. /* message */
  509. /* Added 10/8/85 by BL: If docScrap is empty, relinquish ownership */
  510. /* of the clipboard */
  511. extern int vfOwnClipboard;
  512. extern HWND vhWnd;
  513. int cf;
  514. struct PICINFOX picInfo;
  515. typeCP cpMacScrap = (**hpdocdod) [docScrap].cpMac;
  516. if (!OpenClipboard( vhWnd ))
  517. { /* Couldn't open the clipboard, wipe out contents & disable UNDO */
  518. MdocDestroyClip();
  519. return;
  520. }
  521. /* We want to clear out previous data formats in the clipboard.
  522. Unfortunately, the only way to do this is to call EmptyClipboard(),
  523. which has the side effect of calling us with a WM_MDOCDESTROYCLIP
  524. message. We use this primitive global comunication to prevent
  525. docScrap from being wiped out in MdocDestroyClip() */
  526. fDontDestroyClip = TRUE;
  527. EmptyClipboard();
  528. fDontDestroyClip = FALSE;
  529. /* Re-validate vfScrapIsPic (in case a docScrap edit changed what it should be */
  530. CachePara( docScrap, cp0 );
  531. vfScrapIsPic = (vpapAbs.fGraphics && vcpLimParaCache == cpMacScrap);
  532. if (!vfScrapIsPic)
  533. cf = CF_TEXT;
  534. else
  535. {
  536. GetPicInfo( cp0, cpMacScrap, docScrap, &picInfo );
  537. switch(picInfo.mfp.mm)
  538. {
  539. case MM_BITMAP:
  540. cf = CF_BITMAP;
  541. break;
  542. case MM_OLE:
  543. cf = 0;
  544. break;
  545. default:
  546. cf = CF_METAFILEPICT;
  547. break;
  548. }
  549. }
  550. vfOwnClipboard = (cpMacScrap != cp0);
  551. if (vfOwnClipboard)
  552. { /* only set handles if we really have something in docScrap */
  553. SetClipboardData( CF_OWNERDISPLAY, NULL );
  554. if ((cf != CF_TEXT) && (picInfo.mfp.mm == MM_OLE))
  555. {
  556. while (cf = OleEnumFormats(lpOBJ_QUERY_OBJECT(&picInfo),cf))
  557. {
  558. if (cf == vcfLink)
  559. SetClipboardData( vcfOwnerLink, NULL );
  560. else
  561. SetClipboardData( cf, NULL );
  562. //if (cf == vcfNative)
  563. //SetClipboardData( vcfOwnerLink, NULL );
  564. }
  565. }
  566. else
  567. SetClipboardData( cf, NULL );
  568. }
  569. CloseClipboard();
  570. }
  571. #ifdef JAPAN //T-HIROYN Win3.1
  572. extern typeCP vcpFetch;
  573. extern int vcchFetch;
  574. extern CHAR *vpchFetch;
  575. #endif
  576. CmdInsScrap( fUnFormattedText )
  577. int fUnFormattedText;
  578. { /* Insert the scrap into the document at the current point (PASTE) */
  579. /* If fUnFormattedText is TRUE, the scrap is treated as unformatted */
  580. /* text; that is, the characters are put into the document with the */
  581. /* formatting that is active at the selection */
  582. extern struct CHP vchpSel;
  583. typeCP cp, dcp;
  584. int cchAddedEol=0;
  585. struct CHP chpT;
  586. if (!FWriteOk( fwcInsert ))
  587. return;
  588. if ((dcp = CpMacText(docScrap)) == cp0)
  589. return;
  590. ClearInsertLine();
  591. if (fnClearEdit(OBJ_INSERTING))
  592. return;
  593. chpT = vchpSel;
  594. cp = selCur.cpFirst;
  595. CachePara( docScrap, cp0 );
  596. if (vpapAbs.fGraphics && cp > cp0)
  597. { /* Special case for inserting a picture paragraph */
  598. /* Must put an Eol in front of the picture unless we're
  599. inserting it at the start of the document or one is there already */
  600. Assert( !fUnFormattedText );
  601. (**hpdocdod)[docCur].fFormatted = fTrue;
  602. CachePara(docCur, cp - 1);
  603. if (vcpLimParaCache != cp)
  604. {
  605. cchAddedEol = ccpEol;
  606. InsertEolPap(docCur, cp, &vpapAbs);
  607. dcp += (typeCP)ccpEol;
  608. }
  609. }
  610. SetUndo( uacInsert, docCur, cp, dcp, docNil, cpNil, cp0, 0 );
  611. SetUndoMenuStr(IDSTRUndoEdit);
  612. ReplaceCps(docCur, cp + (typeCP)cchAddedEol, cp0, docScrap, cp0,
  613. dcp - (typeCP)cchAddedEol);
  614. if (ferror) /* Not enough memory to do replace operation */
  615. NoUndo(); /* should not be able to undo what never took place */
  616. else
  617. {
  618. typeCP cpSel=CpFirstSty( cp + dcp, styChar );
  619. if (vfScrapIsPic && vuab.uac == uacReplNS)
  620. /* Special UNDO code for picture paste */
  621. vuab.uac = uacReplPic;
  622. if (fUnFormattedText)
  623. { /* If pasting unformatted text, give it the props at the selection */
  624. CHAR rgch[ cchCHP + 1 ];
  625. rgch [0] = sprmCSame;
  626. #ifdef JAPAN //T-HIROYN Win3.1
  627. {
  628. struct CHP savechpT;
  629. typeCP cpF, cpFirst, cpLim, kcpF, kcpL;
  630. int cchF;
  631. int kanjiftc, alphaftc;
  632. CHAR *rp;
  633. CHAR ch;
  634. int cch, cblen;
  635. if(NATIVE_CHARSET != GetCharSetFromChp(&chpT)) {
  636. kanjiftc = GetKanjiFtc(&chpT);
  637. alphaftc = GetFtcFromPchp(&chpT);
  638. savechpT = chpT;
  639. cpFirst = cp;
  640. do {
  641. FetchCp(docCur, cpFirst, 0, fcmChars);
  642. cpF = vcpFetch;
  643. cchF = vcchFetch;
  644. kcpF = cpF;
  645. if ((cpF+cchF) < cp + dcp)
  646. cpLim = (cpF+cchF);
  647. else
  648. cpLim = cp + dcp;
  649. cch = 0;
  650. rp = vpchFetch;
  651. while ( kcpF < cpLim ) {
  652. ch = *rp;
  653. if( FKana(ch) || IsDBCSLeadByte(ch) ) {
  654. cblen = GetKanjiStringLen(cch, cchF, rp);
  655. chpT.ftc = kanjiftc;
  656. } else {
  657. cblen = GetAlphaStringLen(cch, cchF, rp);
  658. chpT.ftc = alphaftc;
  659. }
  660. kcpL = kcpF + cblen;
  661. cch += cblen;
  662. rp += cblen;
  663. bltbyte( &chpT, &rgch [1], cchCHP );
  664. AddSprmCps(rgch, docCur, kcpF, kcpL);
  665. kcpF = kcpL;
  666. }
  667. cpFirst = kcpF;
  668. } while ((cpF + cchF) < cp + dcp );
  669. chpT = savechpT;
  670. } else {
  671. bltbyte( &chpT, &rgch [1], cchCHP );
  672. AddSprmCps( rgch, docCur, cp, cp + dcp );
  673. } //END IF ELSE
  674. } // END JAPAN
  675. #else
  676. bltbyte( &chpT, &rgch [1], cchCHP );
  677. AddSprmCps( rgch, docCur, cp, cp + dcp );
  678. #endif
  679. }
  680. Select( cpSel, cpSel );
  681. vchpSel = chpT; /* Preserve insert point props across this operation */
  682. if (wwdCurrentDoc.fEditHeader || wwdCurrentDoc.fEditFooter)
  683. { /* If running head/foot, remove chSects & set para props */
  684. MakeRunningCps( docCur, cp, dcp );
  685. }
  686. if (ferror)
  687. NoUndo();
  688. }
  689. vfSeeSel = true; /* Tell Idle() to scroll the selection into view */
  690. }
  691. #if defined(OLE)
  692. int NEAR PASCAL CopyScrapToTmp(void)
  693. /*
  694. If scrap doesn't contain OLE objects, return docScrap. Else
  695. create docTemp and copy docScrap into it. Make sure objects
  696. all have their data and have their lpObjInfos NULL'd out.
  697. */
  698. {
  699. extern typeCP cpMinCur, cpMacCur, cpMinDocument;
  700. typeCP cpMinCurT = cpMinCur,
  701. cpMacCurT = cpMacCur,
  702. cpMinDocumentT = cpMinDocument;
  703. int docTemp = docNil,
  704. docReturn = docNil;
  705. /* are there any objects? */
  706. switch (ObjEnumInDoc(docScrap,NULL))
  707. {
  708. case -1: // error
  709. return docNil;
  710. case 0: // no objects in scrap
  711. return docScrap;
  712. }
  713. /* Create copy of document */
  714. if ((docTemp = DocCreate(fnNil, HszCreate(""), dtyNormal)) == docNil)
  715. return docNil;
  716. /* copy scrap to docTemp */
  717. ClobberDoc(docTemp, docScrap, cp0, CpMacText(docScrap));
  718. if (ferror)
  719. goto error;
  720. /* now save objects to make sure their data is present */
  721. {
  722. OBJPICINFO picInfo;
  723. typeCP cpPicInfo;
  724. for (cpPicInfo = cpNil;
  725. ObjPicEnumInRange(&picInfo,docTemp,cp0,CpMacText(docTemp),&cpPicInfo);
  726. )
  727. {
  728. OBJINFO ObjInfoSave;
  729. typeCP cpRetval;
  730. if (picInfo.lpObjInfo == NULL)
  731. continue;
  732. ObjInfoSave = *picInfo.lpObjInfo;
  733. cpRetval = ObjSaveObjectToDoc(&picInfo,docTemp,cpPicInfo);
  734. /*
  735. Do this just in case saving the object to docTemp changes the
  736. object's state. We don't want the object to appear clean
  737. or saved when in fact it isn't or hasn't been except in docTemp,
  738. which will be deleted by the calling routine.
  739. */
  740. *picInfo.lpObjInfo = ObjInfoSave;
  741. if (cpRetval == cp0) // save failed
  742. goto error;
  743. /* so pasting instance will reload object */
  744. picInfo.lpObjInfo = NULL;
  745. ObjSetPicInfo(&picInfo,docTemp,cpPicInfo);
  746. }
  747. }
  748. /* success */
  749. docReturn = docTemp;
  750. error:
  751. if ((docReturn == docNil) && (docTemp != docNil))
  752. KillDoc(docTemp);
  753. /* Restore cpMinCur, cpMacCur */
  754. cpMinCur = cpMinCurT;
  755. cpMacCur = cpMacCurT;
  756. cpMinDocument = cpMinDocumentT; /* destroyed possibly by DocCreate */
  757. return docReturn;
  758. }
  759. #endif
  760.