Source code of Windows XP (NT5)
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.

1524 lines
42 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. /* Clipbrd2.c -- less frequently used clipboard routines */
  5. #define NOWINMESSAGES
  6. #define NOGDICAPMASKS
  7. #define NOWINSTYLES
  8. #define NOVIRTUALKEYCODES
  9. #define NOMENUS
  10. #define NOSYSMETRICS
  11. #define NOICON
  12. #define NOKEYSTATE
  13. #define NOSYSCOMMANDS
  14. #define NOSHOWWINDOW
  15. //#define NOATOM
  16. #define NOCOLOR
  17. #define NOCREATESTRUCT
  18. #define NODRAWTEXT
  19. #define NOOPENFILE
  20. #define NOSOUND
  21. #define NOCOMM
  22. #define NOWINOFFSETS
  23. #define NOWNDCLASS
  24. #define NOWH
  25. #define NOSCROLL
  26. #define NOPEN
  27. #include <windows.h>
  28. #include "mw.h"
  29. #define NOKCCODES
  30. #include "ch.h"
  31. #include "cmddefs.h"
  32. #include "docdefs.h"
  33. #include "editdefs.h"
  34. #include "filedefs.h"
  35. #include "propdefs.h"
  36. #include "winddefs.h"
  37. #include "fmtdefs.h"
  38. #if defined(OLE)
  39. #include "obj.h"
  40. #endif
  41. #if defined(JAPAN) & defined(DBCS_IME)
  42. #include "prmdefs.h" /* IME: use sprmCSame in CmdInsIRString() */
  43. #else
  44. #define NOSTRMERGE
  45. #define NOSTRUNDO
  46. #endif
  47. #include "str.h"
  48. #define NOIDISAVEPRINT
  49. #define NOIDIFORMATS
  50. #include "dlgdefs.h"
  51. #include "wwdefs.h"
  52. #include "debug.h"
  53. #if defined(JAPAN) || defined(KOREA) //T-HIROYN Win3.1
  54. #include "fontdefs.h"
  55. #include "kanji.h"
  56. extern struct CHP vchpSel;
  57. #endif
  58. extern struct WWD rgwwd[];
  59. extern int wwMac;
  60. extern struct DOD (**hpdocdod)[];
  61. extern int docCur; /* Document in current ww */
  62. extern int docMac;
  63. extern int ferror;
  64. extern int docScrap;
  65. #if defined(JAPAN) & defined(DBCS_IME) /* Document for IRSTRING */
  66. extern int docIRString;
  67. #include <ime.h>
  68. extern int wwCur;
  69. #if defined(JAPAN) & defined(IME_HIDDEN) //IME3.1J
  70. typeCP selUncpFirst = cp0;
  71. typeCP selUncpLim = cp0;
  72. HANDLE hImeUnAttrib = NULL;
  73. HANDLE hImeUnString = NULL;
  74. BOOL ImeClearInsert = FALSE;
  75. struct CHP vchpHidden;
  76. extern int HiddenTextTop;
  77. extern int HiddenTextBottom;
  78. // 12/28/92
  79. extern BOOL whileUndetermine; // if TRUE we are managing IR_UNDETERMINE
  80. #endif
  81. #endif
  82. extern struct PAP vpapAbs;
  83. extern int vccpFetch;
  84. extern CHAR *vpchFetch;
  85. extern struct PAP *vppapNormal;
  86. extern struct CHP vchpNormal;
  87. extern int vfScrapIsPic;
  88. extern typeCP vcpLimParaCache;
  89. extern int dxpLogInch;
  90. extern int dypLogInch;
  91. extern int vfOwnClipboard;
  92. extern struct FLI vfli;
  93. #if WINVER >= 0x300
  94. /* We can copy more than 64k in the clipboard and need to
  95. correctly handle when we cross segment boundaries. See
  96. note in bltbh() ..pault */
  97. void bltbh(HPCH, HPCH, int);
  98. #define bltbx(from,to,count) bltbh(from,to,count)
  99. #define LPCHCLIP HPCH
  100. #else
  101. #define LPCHCLIP LPCH
  102. #endif /* if-else-WINVER */
  103. FRenderAll()
  104. { /* WRITE is going away, and we are the owners of the clipboard.
  105. Render the contents of the clipboard in as many formats as
  106. we know. Prompt the user if the save will use more than 1000
  107. cp's; this is to avoid massive inadvertant gobbling of global
  108. heap space. */
  109. extern int vfOwnClipboard;
  110. extern HANDLE hMmwModInstance;
  111. extern HANDLE hParentWw;
  112. extern FARPROC lpDialogConfirm;
  113. typeCP cpMac=CpMacText( docScrap );
  114. if ( (cpMac == cp0) || !vfOwnClipboard)
  115. { /* We are not the clipboard owner OR the scrap is empty:
  116. no actions required */
  117. return TRUE;
  118. }
  119. #ifdef ENABLE /* By popular demand, this dialog box is removed */
  120. else if (cpMac > 1000L)
  121. {
  122. /* Clipboard contents (docScrap) are > 1000 bytes; ask the user to confirm
  123. that it should be saved away in a global handle */
  124. switch ( OurDialogBox( hMmwModInstance, MAKEINTRESOURCE( dlgSaveScrap ),
  125. hParentWw, lpDialogConfirm ) )
  126. {
  127. default:
  128. case idiCancel: /* [CANCEL] Abort exit sequence */
  129. return FALSE;
  130. case idiNo: /* [DISCARD] Discard large clipboard */
  131. return TRUE;
  132. case idiOk: /* [SAVE] Save large clipboard */
  133. break;
  134. }
  135. }
  136. /* Believe it or not, we have to check the vfOwnClipboard flag AGAIN.
  137. A user as sneaky as gaben might have gone into another app and
  138. copied to the clipboard while our dialog is up. */
  139. if (!vfOwnClipboard)
  140. /* We have to check the vfOwnClipboard flag AGAIN.
  141. A user might have gone into another app and
  142. copied to the clipboard while our dialog was up. */
  143. return TRUE;
  144. #endif /* ENABLE */
  145. /* Render the clipboard contents */
  146. if (OpenClipboard( wwdCurrentDoc.wwptr ))
  147. {
  148. int f;
  149. f = FWriteExtScrap();
  150. CloseClipboard();
  151. if (f)
  152. return TRUE;
  153. else
  154. { /* Failed to write scrap contents -- report error */
  155. extern HWND hParentWw;
  156. CHAR *PchFillPchId( CHAR *, int, int );
  157. CHAR sz[ 256 ];
  158. PchFillPchId( sz, IDPMTClipQuest, sizeof(sz) );
  159. switch ( IdPromptBoxSz( hParentWw, sz,
  160. MB_OKCANCEL | MB_ICONHAND | MB_SYSTEMMODAL ) )
  161. {
  162. default:
  163. break;
  164. case IDOK:
  165. return TRUE;
  166. }
  167. }
  168. }
  169. return FALSE;
  170. }
  171. FWriteExtScrap()
  172. { /* Write the scrap document into the external scrap */
  173. /* This means: Write the clipboard contents to the clipboard */
  174. /* in the standard Windows CF_TEXT format, or, if a picture, */
  175. /* in CF_BITMAP or CF_METAFILEPICT, whichever it was originally. */
  176. /* We get here in response to a WM_RENDERFORMAT or WM_RENDERALLFORMATS */
  177. /* message. The clipboard is assumed to be already OPEN, and is left open */
  178. /* Returns TRUE if all is well, FALSE if an error occurs. The caller
  179. /* is responsible for reporting errors. */
  180. int NEAR FWriteExtTextScrap();
  181. typeCP cpNow;
  182. typeCP cpMac=(**hpdocdod) [docScrap].cpMac;
  183. unsigned long cbScrap;
  184. struct PICINFOX picInfo;
  185. HANDLE hScrapDescriptor=NULL;
  186. HANDLE hScrap;
  187. if (!vfScrapIsPic)
  188. { /* Text */
  189. return FWriteExtTextScrap();
  190. }
  191. GetPicInfo( cp0, cpMac, docScrap, &picInfo );
  192. #if defined(OLE)
  193. if (picInfo.mfp.mm == MM_OLE)
  194. return ObjWriteToClip(&picInfo);
  195. #endif
  196. /* Prime the loop */
  197. FetchCp(docScrap, cpNow = (typeCP)picInfo.cbHeader, 0, fcmChars + fcmNoExpand);
  198. if ((hScrap = GlobalAlloc( GMEM_MOVEABLE, cbScrap = (LONG)vccpFetch )) == NULL)
  199. goto SetFailed;
  200. while (cpNow < cpMac)
  201. {
  202. LPCHCLIP lpch;
  203. HANDLE hScrapT;
  204. #ifdef DCLIP
  205. {
  206. char rgch[200];
  207. wsprintf(rgch,"FWES:cpNow %lu cpMac %lu vccpFetch %d \n\r", cpNow, cpMac, vccpFetch);
  208. CommSz(rgch);
  209. }
  210. #endif
  211. /* Add bytes from scrap document to global handle */
  212. if ((lpch = GlobalLock( hScrap )) == NULL)
  213. goto SetFailed;
  214. bltbx( (LPCHCLIP) vpchFetch, lpch + (cbScrap - vccpFetch), vccpFetch );
  215. GlobalUnlock( hScrap );
  216. /* Fetch the next run and expand the handle */
  217. if ((cpNow += vccpFetch) >= cpMac)
  218. break;
  219. FetchCp( docScrap, cpNow, 0, fcmChars + fcmNoExpand );
  220. /* the above fetchcp should probably be converted to use the speed-
  221. hack in fetchcp which passes docnil cpnil to get the next series
  222. of chars ..pault */
  223. hScrapT = hScrap;
  224. hScrap = GlobalReAlloc( hScrap, cbScrap += vccpFetch, GMEM_MOVEABLE );
  225. if (hScrap == NULL)
  226. { /* Could not grow the handle; bail out */
  227. hScrap = hScrapT; /* So it gets freed */
  228. goto SetFailed;
  229. }
  230. }
  231. /* Now we have the whole of docScrap in a windows Global handle */
  232. /* See whether we have a bitmap or a metafile picture */
  233. switch(picInfo.mfp.mm)
  234. {
  235. case MM_BITMAP:
  236. { /* Bitmap */
  237. LPCHCLIP lpch;
  238. if ( ((lpch=GlobalLock( hScrap ))==NULL) ||
  239. (picInfo.bm.bmBits=lpch,
  240. ((hScrapDescriptor=
  241. CreateBitmapIndirect((LPBITMAP)&picInfo.bm))==NULL)))
  242. {
  243. if (lpch != NULL)
  244. GlobalUnlock( hScrap );
  245. goto SetFailed;
  246. }
  247. else
  248. {
  249. /* Tell the clipboard about the "goal size" for this guy */
  250. SetBitmapDimension( hScrapDescriptor, picInfo.mfp.xExt,
  251. picInfo.mfp.yExt );
  252. SetClipboardData( CF_BITMAP, hScrapDescriptor );
  253. }
  254. GlobalUnlock( hScrap );
  255. GlobalFree( hScrap ); /* Bitmap was copied by CreateBitmapIndirect,
  256. don't need it anymore */
  257. hScrap = NULL;
  258. }
  259. break;
  260. default:
  261. { /* Metafile Picture */
  262. LPCHCLIP lpch;
  263. Diag(CommSzNum("FWES: sizeof(metafilepict) ==",sizeof(METAFILEPICT)));
  264. if ( ((hScrapDescriptor=GlobalAlloc(GMEM_MOVEABLE,
  265. (long)sizeof(METAFILEPICT) ))==NULL) ||
  266. ((lpch=GlobalLock( hScrapDescriptor ))==NULL))
  267. {
  268. goto SetFailed;
  269. }
  270. else
  271. {
  272. picInfo.mfp.hMF = hScrap;
  273. bltbx( (LPCHCLIP) &picInfo.mfp, lpch, sizeof(METAFILEPICT) );
  274. GlobalUnlock( hScrapDescriptor );
  275. SetClipboardData( CF_METAFILEPICT, hScrapDescriptor );
  276. }
  277. }
  278. break;
  279. }
  280. return true;
  281. SetFailed:
  282. if (hScrapDescriptor != NULL)
  283. GlobalFree( hScrapDescriptor );
  284. if (hScrap != NULL)
  285. GlobalFree( hScrap );
  286. return false; /* Caller should report errors */
  287. }
  288. int NEAR FWriteExtTextScrap()
  289. { /* Create ASCII text in a global Windows handle corresponding
  290. to the contents of docScrap. Add CR-LF combinations at the
  291. points at which text would wrap on the display.
  292. Set the handle into the clipboard if successful, as type CF_TEXT.
  293. Returns the handle built up, or NULL if we ran out of memory */
  294. long lcchHandle = 0L;
  295. HANDLE h=GlobalAlloc( GMEM_MOVEABLE, (long) 1 );
  296. LPCHCLIP lpch;
  297. typeCP cpNow=cp0;
  298. typeCP cpMac=(**hpdocdod) [docScrap].cpMac;
  299. HANDLE hT;
  300. #if WINVER < 0x300
  301. int cLine = 0;
  302. #endif
  303. Assert( !vfScrapIsPic );
  304. Assert( vfOwnClipboard );
  305. if (h==NULL)
  306. goto Failed;
  307. while (cpNow < cpMac)
  308. {
  309. int ich;
  310. int dcpLine;
  311. /* Check for picture para */
  312. /** Is this syntax intentional???!!! (1.28.91) D. Kent **/
  313. if (CachePara( docScrap, cpNow ), vpapAbs.fGraphics )
  314. {
  315. cpNow = vcpLimParaCache;
  316. continue;
  317. }
  318. /* Format a line of text for the screen */
  319. FormatLine( docScrap, cpNow, 0, cpMac, flmSandMode );
  320. dcpLine = vfli.ichReal;
  321. /* Special: Check for NULLs */
  322. /* This is a last-minute workaround for a WRITE */
  323. /* bug in which FormatLine sometimes returns a NULL in vfli.rgch */
  324. for ( ich = 0; ich < vfli.ichReal; ich++ )
  325. {
  326. if (vfli.rgch [ich] == '\0')
  327. {
  328. #ifdef DCLIP
  329. CommSzNum("Oddity in FormatLine: returned a zero in rgch at ich==",ich);
  330. #endif
  331. #if WINVER < 0x300
  332. dcpLine = ich;
  333. break;
  334. #else
  335. /* Rather than assign the string a zero length if there is
  336. just one block character in the selection, we make it the
  337. ansi block char! This fixes WINBUG #8150..pault 1/16/90 */
  338. vfli.rgch [ich] = chBlock;
  339. #endif
  340. }
  341. }
  342. /* Put the chars + a CRLF into the handle */
  343. #define cbNeeded (lcchHandle + dcpLine + 2)
  344. #ifdef DCLIP
  345. {
  346. char rgch[200];
  347. wsprintf(rgch,"FWETS:cbNeeded %lu (lcchHandle %lu, dcpLine %d) \n\r",
  348. cbNeeded, lcchHandle, dcpLine);
  349. CommSz(rgch);
  350. }
  351. #endif
  352. hT = h;
  353. if ((h=GlobalReAlloc( h, (LONG) cbNeeded, GMEM_MOVEABLE ))==NULL)
  354. { /* Could not expand handle */
  355. h = hT; /* So it gets freed */
  356. goto Failed;
  357. }
  358. if ((lpch=GlobalLock( h )) == NULL)
  359. goto Failed;
  360. if (vfli.cpMac > cpMac)
  361. /* Do not cut the endmark character (but alloc for it to allow
  362. space for zero-terminating the clipboard string) */
  363. #ifdef DBCS
  364. /* We use double byte charactor for END Mark,So we have to go back 2 byte */
  365. #if defined(JAPAN) || defined(KOREA) //T-HIROYN 1992.07.28
  366. /* In Win31J We use single byte charactor for END Mark */
  367. dcpLine--;
  368. #else
  369. dcpLine -= 2;
  370. #endif
  371. #else
  372. dcpLine--;
  373. #endif
  374. bltbx( (LPCHCLIP) vfli.rgch, lpch + lcchHandle, dcpLine );
  375. lpch [lcchHandle += dcpLine] = 0x0D;
  376. lpch [++lcchHandle] = 0x0A;
  377. #if WINVER < 0x300
  378. cLine++;
  379. #endif
  380. #ifdef DCLIP
  381. {
  382. char rgch[200];
  383. wsprintf(rgch," cpNow %lu cpMac %lu lcchHandle %lu dcpLine %d \n\r",
  384. cpNow, cpMac, lcchHandle+1, dcpLine);
  385. CommSz(rgch);
  386. }
  387. #endif
  388. ++lcchHandle;
  389. cpNow = vfli.cpMac;
  390. GlobalUnlock( h );
  391. }
  392. /* SUCCEEDED! NULL-terminate the string before returning the handle */
  393. #if WINVER >= 0x300
  394. /* This means we must alloc one more byte at the end ..pault 1/11/90 */
  395. #ifdef DCLIP
  396. {
  397. char rgch[200];
  398. wsprintf(rgch,"FWETS:cbNeeded to fit in sz %lu \n\r", lcchHandle+1);
  399. CommSz(rgch);
  400. }
  401. #endif
  402. hT = h;
  403. if ((h=GlobalReAlloc( h, (LONG) lcchHandle+1, GMEM_MOVEABLE ))==NULL)
  404. { /* Could not expand handle */
  405. h = hT; /* So it gets freed */
  406. goto Failed;
  407. }
  408. #endif
  409. if ((lpch = GlobalLock( h )) == NULL)
  410. goto Failed;
  411. #if WINVER >= 0x300
  412. /* It turns out that we're not really representing the contents of the
  413. selection correctly. The user should really ONLY end up at the start
  414. of a new line (that is, the last thing "pasted in" was a CRLF sequence)
  415. if they were really at the end of a line! (Especially a problem when
  416. pasting 3 lines of text into the CALENDAR Scratchpad) 12/3/89..pault */
  417. if (cpMac < vfli.cpMac)
  418. #else
  419. if (cLine == 1) /* Special case: < 1 line, do not terminate w/ CRLF */
  420. #endif
  421. /* Back up over crlf already written */
  422. lcchHandle = max(0, lcchHandle-2);
  423. lpch [lcchHandle] = '\0';
  424. GlobalUnlock( h );
  425. SetClipboardData( CF_TEXT, h );
  426. return TRUE;
  427. Failed:
  428. if (h != NULL)
  429. GlobalFree( h );
  430. return FALSE;
  431. }
  432. int FReadExtScrap()
  433. { /* Transfer the external scrap to the scrap document. This means:
  434. read the contents of the clipboard into docScrap, using whatever
  435. available standard format we can process. Return FALSE=ERR, TRUE=OK */
  436. extern int vfSysFull;
  437. extern BOOL fError;
  438. extern HWND vhWnd;
  439. extern int vfOwnClipboard;
  440. int fOk = FALSE;
  441. struct PICINFOX picInfo;
  442. Assert( !vfOwnClipboard );
  443. vfScrapIsPic = false;
  444. ClobberDoc( docScrap, docNil, cp0, cp0 );
  445. if ( !OpenClipboard( vhWnd ) )
  446. return FALSE;
  447. /* Get the handle for the highest-priority type available in the clipboard */
  448. /* if !(PasteLink or (PasteSpecial and not CF_TEXT)) */
  449. if (!(vbObjLinkOnly || vObjPasteLinkSpecial ||
  450. (cfObjPasteSpecial && (cfObjPasteSpecial != CF_TEXT)))) // no text handler yet
  451. /* try to use text format */
  452. {
  453. WORD wFormat=0;
  454. typeCP cp=cp0;
  455. unsigned long cb;
  456. struct PAP *ppap = NULL;
  457. CHAR rgch[256];
  458. HANDLE hClipboard; /* Handle that was being kept in the clipboard */
  459. LPCHCLIP lpch;
  460. while (wFormat = EnumClipboardFormats(wFormat))
  461. /* enumerate to see whether text precedes native. If so, take it */
  462. {
  463. if (wFormat == CF_TEXT) // take it
  464. {
  465. if ((hClipboard = GetClipboardData( wFormat )) == NULL)
  466. goto done;
  467. cb = GlobalSize( hClipboard );
  468. lpch = MAKELP(hClipboard,0);
  469. while (cb > 0)
  470. { /* Copy bytes from lpch to docScrap's cp stream */
  471. #define ulmin(a,b) (((a) < (b)) ? a : b)
  472. unsigned cch=ulmin(cb,255); /* <= 255 bytes per pass */
  473. int fEol;
  474. #if defined(JAPAN) || defined(KOREA) //T-HIROYN Win3.1
  475. unsigned ccht;
  476. if ((cch = CchReadLineExtDBCS((LPCHCLIP) lpch, cch, rgch,
  477. &fEol, &ccht))==0) /* Reached terminator */
  478. {
  479. fOk = TRUE;
  480. goto done;
  481. }
  482. if (fEol)
  483. ppap = vppapNormal;
  484. #ifdef KKBUGFIX // added by Hiraisi (pasted several lines. BUG#2791)
  485. else
  486. ppap = NULL;
  487. #endif
  488. InsertRgch( docScrap, cp, rgch, ccht, &vchpNormal, ppap );
  489. if (fError) /* an error was reported mid-copy */
  490. goto done;
  491. cb -= cch;
  492. cp += (typeCP) ccht;
  493. lpch += cch;
  494. #else
  495. if ((cch = CchReadLineExt((LPCHCLIP) lpch, cch, rgch,
  496. &fEol))==0) /* Reached terminator */
  497. {
  498. fOk = TRUE;
  499. goto done;
  500. }
  501. if (fEol)
  502. ppap = vppapNormal;
  503. #ifdef KKBUGFIX // added by Hiraisi (pasted several lines. in Japan)
  504. else
  505. ppap = NULL;
  506. #endif
  507. InsertRgch( docScrap, cp, rgch, cch, &vchpNormal, ppap );
  508. if (fError) /* an error was reported mid-copy */
  509. goto done;
  510. cb -= cch;
  511. cp += (typeCP) cch;
  512. lpch += cch;
  513. #endif
  514. }
  515. Assert(0); // shouldn't get here
  516. }
  517. else if ((cfObjPasteSpecial != CF_TEXT) &&
  518. (wFormat == vcfNative)) // make an object
  519. /* NOTE: if pastespecial and the format == CF_TEXT, then
  520. we look for the text format regardless of presence of
  521. native */
  522. break;
  523. }
  524. }
  525. /* Fell through to here, so didn't find or don't want text,
  526. see whether can make an object (static included) */
  527. if (!ObjCreateObjectInClip(&picInfo))
  528. goto done;
  529. vfScrapIsPic = true;
  530. /* save new picinfo to doc */
  531. CachePara(docScrap,cp0);
  532. if (ObjSaveObjectToDoc(&picInfo,docScrap,cp0) == cp0)
  533. {
  534. OleDelete(lpOBJ_QUERY_OBJECT(&picInfo));
  535. goto done;
  536. }
  537. /* this'll force paste to reuse rather than clone */
  538. if (ObjToCloneInDoc(&picInfo,docScrap,cp0) == cp0)
  539. {
  540. OleDelete(lpOBJ_QUERY_OBJECT(&picInfo));
  541. goto done;
  542. }
  543. fOk = TRUE;
  544. done:
  545. CloseClipboard();
  546. if (vfSysFull || (!fOk && (picInfo.mfp.mm == MM_OLE)))
  547. { /* Filled the scratch file trying to bring in the object */
  548. ClobberDoc(docScrap, docNil, cp0, cp0);
  549. fOk = FALSE;
  550. }
  551. return fOk;
  552. }
  553. #if defined(JAPAN) & defined(DBCS_IME)
  554. // We know that this special routine is particularly useful for Japanese IME
  555. //CmdInsIRString(int doc) T-HIROYN 3.1J
  556. CmdInsIRString()
  557. {
  558. extern struct CHP vchpSel;
  559. typeCP cp, dcp;
  560. struct CHP chpT;
  561. extern struct SEL selCur; /* Current Selection */
  562. extern int vfSeeSel;
  563. if (!FWriteOk(fwcInsert))
  564. return;
  565. if ((dcp = CpMacText(docIRString)) == cp0)
  566. return;
  567. NoUndo(); /* So the Undo doesn't get combined with previous ops */
  568. /* Stomp the current selection, if any */
  569. if (selCur.cpLim > selCur.cpFirst)
  570. DeleteSel();
  571. chpT = vchpSel;
  572. cp = selCur.cpFirst;
  573. CachePara( docIRString, cp0 );
  574. SetUndo( uacInsert, docCur, cp, dcp, docNil, cpNil, cp0, 0 );
  575. SetUndoMenuStr(IDSTRUndoEdit);
  576. ReplaceCps(docCur, cp , cp0, docIRString, cp0, dcp);
  577. if (ferror) /* Not enough memory to do replace operation */
  578. NoUndo(); /* should not be able to undo what never took place */
  579. else
  580. {
  581. CHAR rgch[ cchCHP + 1 ];
  582. typeCP cpSel=CpFirstSty( cp + dcp, styChar );
  583. rgch [0] = sprmCSame;
  584. bltbyte( &chpT, &rgch [1], cchCHP );
  585. AddSprmCps( rgch, docCur, cp, cp + dcp );
  586. Select( cpSel, cpSel );
  587. vchpSel = chpT; /* Preserve insert point props across this operation */
  588. if (wwdCurrentDoc.fEditHeader || wwdCurrentDoc.fEditFooter)
  589. { /* If running head/foot, remove chSects & set para props */
  590. MakeRunningCps( docCur, cp, dcp );
  591. }
  592. if (ferror)
  593. NoUndo();
  594. }
  595. vfSeeSel = true; /* Tell Idle() to scroll the selection into view */
  596. }
  597. PutImeString( hWnd, hIME )
  598. HWND hWnd;
  599. HANDLE hIME;
  600. {
  601. LPCHCLIP lpch;
  602. CHAR rgch[256];
  603. unsigned long cb;
  604. typeCP cp = cp0;
  605. extern BOOL fError;
  606. extern int vfSysFull;
  607. int fUnFormattedText = FALSE;
  608. extern void ForceImeBlock();
  609. //T-HIROUN 3.1J ForceImeBlock(hWnd, TRUE);
  610. //StartLongOp();
  611. ClearInsertLine();
  612. vfScrapIsPic = false;
  613. ClobberDoc( docIRString, docNil, cp0, cp0 );
  614. cb = GlobalSize( hIME );
  615. if (lpch = GlobalLock( hIME )) {
  616. //T-HIROYN Win3.1
  617. //change CHARSET to KANJI_CHARSET
  618. {
  619. int ftc;
  620. if( ftcNil != (ftc = GetKanjiFtc(&vchpSel))) {
  621. ApplyCLooks(&vchpSel, sprmCFtc, ftc);
  622. }
  623. }
  624. while(cb > 0) {
  625. unsigned cch = ulmin(cb, 255);
  626. int fEol;
  627. struct PAP *ppap = NULL;
  628. if ((cch = CchReadLineExt((LPCHCLIP)lpch,cch,rgch,&fEol)) == 0)
  629. break;
  630. if (fEol)
  631. ppap = vppapNormal;
  632. InsertRgch(docIRString, cp, rgch, cch, &vchpNormal, ppap );
  633. if (fError) {
  634. break;
  635. }
  636. cb -= cch;
  637. cp += (typeCP) cch;
  638. lpch += cch;
  639. }
  640. GlobalUnlock( hIME );
  641. }
  642. if (vfSysFull) {
  643. ClobberDoc( docIRString, docNil, cp0, cp0 );
  644. }
  645. fUnFormattedText = !vfScrapIsPic;
  646. // T-HIROYN 3.1J CmdInsIRString(docIRString);
  647. //EndLongOp();
  648. // T-HIROYN 3.1J ForceImeBlock(hWnd, FALSE);
  649. }
  650. #endif // JAPAN & DBCS_IME
  651. CchReadLineExt( lpch, cbRead, rgch, pfEol)
  652. LPCHCLIP lpch;
  653. int cbRead;
  654. CHAR rgch[];
  655. int *pfEol;
  656. { /* Read from lpch to the next eol or null terminator, whichever comes first */
  657. /* Return number of bytes read (max is 255) and whether there is a eol at end */
  658. /* The count does not include the null terminator, but does include the eol */
  659. CHAR *pch;
  660. extern CHAR *index();
  661. Assert(cbRead <= 255);
  662. bltbx( lpch, (LPCHCLIP) rgch, cbRead );
  663. rgch[ cbRead ] = 0; /* Null terminate the string (so index will work) */
  664. if (*pfEol = ((pch=index(rgch,chEol)) != NULL))
  665. { /* FOUND EOL */
  666. return (pch - rgch + 1);
  667. }
  668. else
  669. { /* NO EOL */
  670. return CchSz(rgch) - 1;
  671. }
  672. }
  673. #if defined(JAPAN) || defined(KOREA) //T-HIROYN Win3.1
  674. CchReadLineExtDBCS( lpch, cbRead, rgch, pfEol, ccht)
  675. LPCHCLIP lpch;
  676. int cbRead;
  677. CHAR rgch[];
  678. int *pfEol;
  679. int *ccht;
  680. {
  681. /*Read from lpch to the next eol or null terminator, whichever comes first */
  682. /*Return number of bytes read (max is 255) and whether there is a eol at end */
  683. /*The count does not include the null terminator, but does include the eol */
  684. CHAR *pch;
  685. int i, j, ret;
  686. Assert(cbRead <= 255);
  687. #ifdef KKBUGFIX // added by Hiraisi (BUG#2791)
  688. *pfEol = FALSE;
  689. #endif
  690. i = j = 0;
  691. while( j < cbRead) {
  692. if( IsDBCSLeadByte(*lpch) ) {
  693. if(j + 2 > cbRead)
  694. break;
  695. if( FKanji2(*(lpch+1)) ) {
  696. rgch[j++] = *lpch++;
  697. rgch[j++] = *lpch++;
  698. i += 2;
  699. } else {
  700. lpch++;
  701. i++;
  702. }
  703. } else {
  704. /* FOUND Null */
  705. if(*lpch == 0)
  706. break;
  707. rgch[j++] = *lpch;
  708. i++;
  709. /* FOUND EOL */
  710. if(*lpch == chEol)
  711. #ifdef KKBUGFIX // added by Hiraisi (BUG#2791)
  712. {
  713. *pfEol = TRUE;
  714. break;
  715. }
  716. #else
  717. break;
  718. #endif
  719. lpch++;
  720. }
  721. }
  722. rgch[j] = 0; /* Null terminate the string (so index will work) */
  723. /* j == set bytes for rgch */
  724. /* i == read bytes from lpch */
  725. *ccht = j;
  726. if(j == 0)
  727. i = 0;
  728. return(i);
  729. }
  730. #endif
  731. FComputePictSize( pmfp, pdxa, pdya )
  732. register METAFILEPICT *pmfp;
  733. int *pdxa;
  734. int *pdya;
  735. { /* Compute an initial size, in twips, for the picture described by the
  736. passed metafile picture structure. Return the size through
  737. parameters. Return FALSE if the metafile picture structure
  738. contained bad information, TRUE otherwise */
  739. #ifdef SCALE_FOR_SCREEN
  740. #define hDCBasis wwdCurrentDoc.hDC
  741. #define dxaConvert czaInch
  742. #define dxpConvert dxpLogInch
  743. #define dyaConvert czaInch
  744. #define dypConvert dypLogInch
  745. #else /* Scale for printer */
  746. extern int dxaPrPage, dxpPrPage, dyaPrPage, dypPrPage;
  747. extern HDC vhDCPrinter;
  748. #define hDCBasis vhDCPrinter
  749. #define dxaConvert dxaPrPage
  750. #define dxpConvert dxpPrPage
  751. #define dyaConvert dyaPrPage
  752. #define dypConvert dypPrPage
  753. #endif
  754. int mm = pmfp->mm;
  755. int dxp, dyp;
  756. int xres;
  757. int yres;
  758. int xsiz;
  759. int ysiz;
  760. #if defined(OLE)
  761. if (mm == MM_OLE)
  762. return ObjQueryObjectBounds((struct PICINFOX FAR *)pmfp, vhDCPrinter, pdxa, pdya);
  763. else
  764. #endif
  765. {
  766. xres = GetDeviceCaps( hDCBasis, HORZRES );
  767. yres = GetDeviceCaps( hDCBasis, VERTRES );
  768. xsiz = GetDeviceCaps( hDCBasis, HORZSIZE );
  769. ysiz = GetDeviceCaps( hDCBasis, VERTSIZE );
  770. switch (mm) {
  771. case MM_ISOTROPIC:
  772. case MM_ANISOTROPIC:
  773. if (! ((pmfp->xExt > 0) && (pmfp->yExt > 0)))
  774. { /* No "Suggested Size" given */
  775. /* Use 3" vertically, 3" or as dictated by */
  776. /* aspect ratio horizontally */
  777. dyp = PxlConvert( MM_LOENGLISH, 300, yres, ysiz );
  778. dxp = ((pmfp->xExt == 0) && (pmfp->yExt == 0)) ?
  779. /* No aspect ratio info given -- use 3" horizontal */
  780. PxlConvert( MM_LOENGLISH, 300, xres, xsiz ) :
  781. /* Info has neg #'s; use to compute aspect ratio */
  782. ((long)((long)dyp * (long)(iabs(pmfp->xExt)))) /
  783. (long) (iabs(pmfp->yExt));
  784. break;
  785. }
  786. else
  787. mm = MM_HIMETRIC;
  788. /* FALL THROUGH TO COMPUTE "SUGGESTED SIZE" */
  789. default:
  790. dxp = PxlConvert( mm, pmfp->xExt, xres, xsiz );
  791. dyp = PxlConvert( mm, pmfp->yExt, yres, ysiz );
  792. break;
  793. }
  794. }
  795. if ((dxp == 0) || (dyp == 0))
  796. /* bogus info or unknown map mode */
  797. return FALSE;
  798. *pdxa = MultDiv( dxp, dxaConvert, dxpConvert );
  799. *pdya = MultDiv( dyp, dyaConvert, dypConvert );
  800. return TRUE;
  801. }
  802. HbmMonoFromHbmColor( hbmSrc )
  803. HBITMAP hbmSrc;
  804. { /* Return a monochrome copy of the passed bitmap. Return NULL
  805. if an error occurred. Assumes that the passed bitmap can be
  806. selected into a memory DC which is compatible with the doc DC. */
  807. extern long rgbBkgrnd;
  808. extern long rgbText;
  809. extern HWND vhWnd;
  810. BITMAP bm;
  811. HBITMAP hbmMono=NULL;
  812. HDC hMDCSrc = NULL;
  813. HDC hMDCDst = NULL;
  814. /* Create memory DC for source, set colors, select in passed bitmap */
  815. if ((hMDCSrc = CreateCompatibleDC( wwdCurrentDoc.hDC )) == NULL)
  816. goto Error;
  817. #ifdef BOGUS
  818. /* We can't assume that every window out there has the same window colors that
  819. we have. In fact, we have no way to figure out how to convert this color
  820. bitmap; so white will map to white and everything else will map to black. */
  821. SetBkColor( hMDCSrc, rgbBkgrnd );
  822. SetTextColor( hMDCSrc, rgbText );
  823. #endif /* BOGUS */
  824. if (SelectObject( hMDCSrc, hbmSrc ) == NULL)
  825. goto Error;
  826. /* Create memory DC for destination, select in a new monochrome bitmap */
  827. if ( ((hMDCDst = CreateCompatibleDC( wwdCurrentDoc.hDC )) == NULL) ||
  828. ((GetObject( hbmSrc, sizeof (BITMAP), (LPSTR) &bm ) == 0)) ||
  829. ((hbmMono = CreateBitmap( bm.bmWidth, bm.bmHeight,
  830. 1, 1, (LPSTR) NULL )) == NULL) ||
  831. (SelectObject( hMDCDst, hbmMono ) == NULL) )
  832. {
  833. goto Error;
  834. }
  835. #ifdef DCLIP
  836. {
  837. char rgch[200];
  838. wsprintf(rgch,"HMFH: (dst) bmWidthB %lu * bmHeight %lu bmPlanes %lu\n\r",
  839. (unsigned long) bm.bmWidthBytes, (unsigned long) bm.bmHeight,
  840. (unsigned long) bm.bmPlanes );
  841. CommSz(rgch);
  842. }
  843. #endif
  844. /* Now blt the bitmap contents. The screen driver in the source will
  845. "do the right thing" in copying color to black-and-white. */
  846. if (!BitBlt( hMDCDst, 0, 0, bm.bmWidth, bm.bmHeight, hMDCSrc, 0, 0, SRCCOPY ))
  847. goto Error;
  848. DeleteDC( hMDCSrc );
  849. DeleteDC( hMDCDst );
  850. return hbmMono;
  851. Error:
  852. if (hMDCSrc != NULL) /* ORDER IS IMPORTANT: DC's before */
  853. DeleteDC( hMDCSrc ); /* objects selected into them */
  854. if (hMDCDst != NULL)
  855. DeleteDC( hMDCDst );
  856. if (hbmMono != NULL)
  857. DeleteObject( hbmMono );
  858. return NULL;
  859. }
  860. #if WINVER >= 0x300
  861. /* Since copying more than 64k to the clipboard is now a real
  862. possibility under protect mode, we really need a good assembler
  863. bltbh(). We don't copy more than 64k at a time but we do
  864. need to properly handle crossing segment boundaries. For now
  865. the clipboard is the only place we need this so this C routine
  866. will suffice for now ..pault */
  867. void bltbh(HPCH hpchFrom, HPCH hpchTo, int cch)
  868. {
  869. HPCH hpchFromLim;
  870. for (hpchFromLim = hpchFrom + cch;
  871. hpchFrom < hpchFromLim;
  872. *(hpchTo++) = *(hpchFrom++))
  873. ;
  874. }
  875. #endif
  876. #if defined(JAPAN) & defined(DBCS_IME)
  877. LONG GetIRString(HWND, LPARAM);
  878. LONG GetIRStringEx(HWND, LPARAM);
  879. #if defined(JAPAN) & defined(IME_HIDDEN) //IME3.1J
  880. LONG GetIRUndetermin(HWND, LPARAM);
  881. //IR_UNDETERMINE
  882. LONG GetIRUndetermin(hWnd, lParam)
  883. HANDLE hWnd;
  884. LONG lParam;
  885. {
  886. LPUNDETERMINESTRUCT lpUn;
  887. HANDLE hImeUn;
  888. LPSTR lpImeattrbuf, lpImechbuf, lpImeDchbuf;
  889. LPSTR lpAttrib, lpText;
  890. UINT uC, uCurPos, uLen, cb, clen, uDLen;
  891. UINT uDelta = 0; //12/28/92 add
  892. HANDLE hMem;
  893. typeCP cpSel = 0L;
  894. typeCP dcp = 0L;
  895. BOOL bUpdate = FALSE;
  896. WORD lRet = (LONG)FALSE;
  897. extern int vfSeeSel;
  898. ImeClearInsert = FALSE;
  899. if(NULL == (hImeUn = LOWORD(lParam))) {
  900. //Cut prev IME string
  901. if(selUncpLim > selUncpFirst) {
  902. dcp = selUncpLim - selUncpFirst;
  903. Replace(docCur, selUncpFirst, dcp, fnNil, fc0, fc0);
  904. selCur.cpFirst = selCur.cpLim = selUncpLim = selUncpFirst;
  905. HiddenTextTop = 0; //IME rectangle top
  906. HiddenTextBottom = 0; //IME rectangle bottom
  907. }
  908. return lRet;
  909. }
  910. // Undetermine string attribute area alloc. when it free is Write close:
  911. if (hImeUnAttrib == NULL) {
  912. if ((hImeUnAttrib = GlobalAlloc(GMEM_MOVEABLE, 512L)) == NULL)
  913. return lRet; // something wrong
  914. }
  915. #if 0 //12/28/92 cut
  916. // Undetermine string area alloc. when it free is Write close:
  917. if (hImeUnString == NULL) {
  918. if ((hImeUnString = GlobalAlloc(GMEM_MOVEABLE, 512L)) == NULL)
  919. return lRet; // something wrong
  920. }
  921. #endif
  922. whileUndetermine = TRUE;
  923. if(selUncpLim == selUncpFirst)
  924. SetImeFont(hWnd);
  925. if (lpUn = (LPUNDETERMINESTRUCT)GlobalLock(hImeUn)) {
  926. uCurPos = lpUn->uCursorPos;
  927. uC = uCurPos;
  928. uDelta = lpUn->uDeltaStart; //12/28/92
  929. lpImechbuf = (LPSTR)lpUn;
  930. lpImechbuf += lpUn->uUndetTextPos;
  931. lpImeattrbuf = (LPSTR)lpUn;
  932. lpImeattrbuf += lpUn->uUndetAttrPos;
  933. lpImeDchbuf = (LPSTR)lpUn;
  934. lpImeDchbuf += lpUn->uDetermineTextPos;
  935. //Undetermine string length
  936. if( lpUn->uUndetTextPos != 0 && lpUn->uUndetTextLen != 0 )
  937. uLen = lpUn->uUndetTextLen;
  938. else
  939. uLen = 0;
  940. //Determine string length
  941. if( lpUn->uDetermineTextPos != 0 &&
  942. lpUn->uDetermineTextLen != 0)
  943. uDLen = lpUn->uDetermineTextLen;
  944. else
  945. uDLen = 0;
  946. //Insert Determin string
  947. if( uDLen != 0 ) {
  948. if (hMem = GlobalAlloc(GMEM_MOVEABLE, (LONG)(uDLen+1))) {
  949. if (lpText = GlobalLock(hMem)) {
  950. #if 1
  951. struct DOD *pdod;
  952. pdod = &(**hpdocdod)[docCur];
  953. pdod->fDirty = true; //because we don't use undo()
  954. #endif
  955. //copy string from IME UNDETERMIN struct
  956. lstrcpy(lpText, lpImeDchbuf);
  957. //chp Set
  958. vchpSel = vchpHidden;
  959. // string set to docIRString
  960. PutImeString( hWnd, hMem);
  961. // inset point set
  962. selCur.cpFirst = selUncpFirst;
  963. // copy from docIRString to docCur
  964. CmdInsIRStringUndetermin((typeCP)uDLen);
  965. bUpdate = TRUE;
  966. GlobalUnlock(hMem);
  967. lRet = (LONG)TRUE;
  968. selUncpFirst += (typeCP)uDLen;
  969. selUncpLim += (typeCP)uDLen;
  970. HiddenTextTop = 0; //IME rectangle top
  971. }
  972. GlobalFree(hMem);
  973. }
  974. }
  975. // cursor position
  976. if(uC == -1)
  977. uC = uLen;
  978. // IME IR_UNDETERMIN Mode start or No change
  979. if(selUncpFirst == selUncpLim && uLen == 0) {
  980. GlobalUnlock(hImeUn);
  981. whileUndetermine = FALSE; //12/28/92
  982. return lRet;
  983. }
  984. /* prev SELECT doc ? */
  985. if (selCur.cpLim > selCur.cpFirst)
  986. DeleteSel();
  987. //First Undetermine string
  988. if(selUncpFirst == selUncpLim && uLen != 0) {
  989. selUncpFirst = selCur.cpFirst;
  990. selUncpLim = selUncpFirst;
  991. vchpHidden = vchpSel;
  992. }
  993. clen = 0;
  994. //Cut prev IME string
  995. if(selUncpLim > selUncpFirst) {
  996. dcp = selUncpLim - selUncpFirst;
  997. #if 0 //12/28/92 rep
  998. //Compare prev Undetermin string and New Undetermin string
  999. if ( lpText = GlobalLock(hImeUnString) ) {
  1000. if( lpAttrib = GlobalLock(hImeUnAttrib) ){
  1001. for(clen = 0; ((typeCP)clen < dcp && clen < uLen); clen++) {
  1002. if( *(lpText+clen) != *(lpImechbuf+clen)) {
  1003. break;
  1004. }
  1005. if( *(lpAttrib+clen) != *(lpImeattrbuf+clen)) {
  1006. break;
  1007. }
  1008. if(IsDBCSLeadByte(*(lpText+clen))) {
  1009. if( *(lpText+clen+1) != *(lpImechbuf+clen+1)) {
  1010. break;
  1011. }
  1012. clen++;
  1013. }
  1014. }
  1015. GlobalUnlock(hImeUnAttrib);
  1016. }
  1017. GlobalUnlock(hImeUnString);
  1018. }
  1019. #else
  1020. if(-1 == uDelta)
  1021. clen = uLen;
  1022. else
  1023. clen = uDelta;
  1024. #endif
  1025. if((typeCP)clen < dcp) {
  1026. Replace(docCur, selUncpFirst+(typeCP)clen, dcp-(typeCP)clen,
  1027. fnNil, fc0, fc0);
  1028. bUpdate = TRUE;
  1029. }
  1030. }
  1031. selUncpLim = selUncpFirst + (typeCP)uLen;
  1032. //Insert New Undetermin string
  1033. if(uLen != 0 && clen < uLen) {
  1034. if (hMem = GlobalAlloc(GMEM_MOVEABLE, (LONG)(uLen+1))) {
  1035. if (lpText = GlobalLock(hMem)) {
  1036. //copy string from IME UNDETERMIN struct
  1037. lstrcpy(lpText, lpImechbuf + clen);
  1038. //chp Set;
  1039. vchpSel = vchpHidden;
  1040. // string set to docIRString
  1041. PutImeString( hWnd, hMem);
  1042. // inset point set
  1043. selCur.cpFirst = selUncpFirst+(typeCP)clen;
  1044. // copy from docIRString to docCur
  1045. CmdInsIRStringUndetermin((typeCP)uC);
  1046. bUpdate = TRUE;
  1047. GlobalUnlock(hMem);
  1048. HiddenTextBottom = 0; //IME rectangle bottom
  1049. }
  1050. GlobalFree(hMem);
  1051. }
  1052. } else {
  1053. //ALL Cut only
  1054. if(uLen == 0) {
  1055. selCur.cpFirst = selCur.cpLim = selUncpLim = selUncpFirst;
  1056. HiddenTextTop = 0; //IME rectangle top
  1057. HiddenTextBottom = 0; //IME rectangle bottom
  1058. }
  1059. }
  1060. // save new info
  1061. //save new Undetermin string;
  1062. #if 0 //12/28/92 cut
  1063. if (lpText = GlobalLock(hImeUnString)) {
  1064. bltbcx(lpText, 0, 512);
  1065. if(uLen < 512)
  1066. lstrcpy(lpText,lpImechbuf);
  1067. GlobalUnlock(hImeUnString);
  1068. }
  1069. #endif
  1070. //save new Undetermin string Attrib
  1071. //12/28/92 add
  1072. if(uLen > 512) {
  1073. hImeUnAttrib = GlobalReAlloc(hImeUnAttrib, (DWORD)uLen, 0);
  1074. }
  1075. if(lpAttrib = GlobalLock(hImeUnAttrib)) {
  1076. // 12/28/92 bltbcx(lpAttrib, 0, 512);
  1077. for(cb = 0;cb < uLen;cb++) {
  1078. lpAttrib[cb] = lpImeattrbuf[cb];
  1079. }
  1080. GlobalUnlock(hImeUnAttrib);
  1081. }
  1082. //Insert Point set:
  1083. cpSel=CpFirstSty( selUncpFirst + (typeCP)uC, styChar );
  1084. Select( cpSel, cpSel );
  1085. //InsertPoint(caret) don`t disp ?
  1086. if( -1 == uCurPos && selUncpLim > selUncpFirst )
  1087. ImeClearInsert = TRUE;
  1088. vfSeeSel = true; /* Tell Idle() to scroll the selection into view */
  1089. GlobalUnlock(hImeUn);
  1090. }
  1091. //text display
  1092. if(bUpdate) {
  1093. UpdateWw(wwCur, FALSE);
  1094. // 12/28/92 DoHiddenRectSend();
  1095. }
  1096. whileUndetermine = FALSE;
  1097. return lRet;
  1098. }
  1099. CmdInsIRStringUndetermin(typeCP cpCc)
  1100. {
  1101. extern struct CHP vchpSel;
  1102. typeCP cp, dcp;
  1103. struct CHP chpT;
  1104. extern struct SEL selCur; /* Current Selection */
  1105. extern int vfSeeSel;
  1106. if (!FWriteOk(fwcInsert))
  1107. return;
  1108. if ((dcp = CpMacText(docIRString)) == cp0)
  1109. return;
  1110. //NNN NoUndo(); /* So the Undo doesn't get combined with previous ops */
  1111. /* Stomp the current selection, if any */
  1112. //NNN if (selCur.cpLim > selCur.cpFirst)
  1113. //NNN DeleteSel();
  1114. chpT = vchpSel;
  1115. cp = selCur.cpFirst;
  1116. CachePara( docIRString, cp0 );
  1117. //NNN SetUndo( uacInsert, docCur, cp, dcp, docNil, cpNil, cp0, 0 );
  1118. //NNN SetUndoMenuStr(IDSTRUndoEdit);
  1119. ReplaceCps(docCur, cp , cp0, docIRString, cp0, dcp);
  1120. if (ferror) /* Not enough memory to do replace operation */
  1121. NoUndo(); /* should not be able to undo what never took place */
  1122. else
  1123. {
  1124. CHAR rgch[ cchCHP + 1 ];
  1125. //NNN typeCP cpSel=CpFirstSty( cp + dcp, styChar );
  1126. // typeCP cpSel=CpFirstSty( cp + uC, styChar );
  1127. typeCP cpSel=CpFirstSty( selUncpFirst + cpCc, styChar );
  1128. rgch [0] = sprmCSame;
  1129. bltbyte( &chpT, &rgch [1], cchCHP );
  1130. AddSprmCps( rgch, docCur, cp, cp + dcp );
  1131. Select( cpSel, cpSel );
  1132. vchpSel = chpT; /* Preserve insert point props across this operation */
  1133. if (wwdCurrentDoc.fEditHeader || wwdCurrentDoc.fEditFooter)
  1134. { /* If running head/foot, remove chSects & set para props */
  1135. MakeRunningCps( docCur, cp, dcp );
  1136. }
  1137. if (ferror)
  1138. NoUndo();
  1139. }
  1140. vfSeeSel = true; /* Tell Idle() to scroll the selection into view */
  1141. }
  1142. UndetermineToDetermine(HWND hWnd)
  1143. {
  1144. selUncpFirst = selUncpLim;
  1145. selCur.cpFirst = selUncpLim;
  1146. selCur.cpLim = selUncpLim;
  1147. ImeClearInsert = FALSE;
  1148. NoUndo();
  1149. InvalidateRect(hWnd, (LPRECT)NULL, FALSE);
  1150. SendIMEVKFLUSHKey(hWnd);
  1151. HiddenTextTop = 0; //IME rectangle top
  1152. HiddenTextBottom = 0; //IME rectangle bottom
  1153. }
  1154. #endif //End IME_HIDDEN
  1155. SendIMEVKFLUSHKey(HWND hWnd)
  1156. {
  1157. LPIMESTRUCT lpmem;
  1158. HANDLE hIMEBlock;
  1159. WORD wRet;
  1160. /* Get comunication area with IME */
  1161. hIMEBlock=GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE | GMEM_LOWER,
  1162. (DWORD)sizeof(IMESTRUCT));
  1163. if(!hIMEBlock) return;
  1164. lpmem = (LPIMESTRUCT)GlobalLock(hIMEBlock);
  1165. lpmem->fnc = IME_SENDVKEY;
  1166. lpmem->wParam = VK_DBE_FLUSHSTRING;
  1167. lpmem->wCount = 0;
  1168. GlobalUnlock(hIMEBlock);
  1169. wRet = MySendIMEMessageEx(hWnd,MAKELONG(hIMEBlock,NULL));
  1170. GlobalFree(hIMEBlock);
  1171. return wRet;
  1172. }
  1173. //New3.1 IR_STRING
  1174. LONG GetIRString(hWnd, lParam)
  1175. HANDLE hWnd;
  1176. LONG lParam;
  1177. {
  1178. HANDLE hMem, hIme;
  1179. LPSTR lpText, lpIme;
  1180. UINT uLen;
  1181. LONG lRet = 0L;
  1182. hIme = LOWORD(lParam);
  1183. if(lpIme = GlobalLock(hIme)) {
  1184. uLen = lstrlen(lpIme);
  1185. if (hMem = GlobalAlloc(GMEM_MOVEABLE, (LONG)(uLen+1) )) {
  1186. if (lpText = GlobalLock(hMem)) {
  1187. #if defined(JAPAN) & defined(IME_HIDDEN) //IME3.1J
  1188. //Cut Undetermine string
  1189. if(selUncpLim > selUncpFirst) {
  1190. typeCP Undcp;
  1191. Undcp = selUncpLim - selUncpFirst;
  1192. Replace(docCur, selUncpFirst, Undcp, fnNil, fc0, fc0);
  1193. selCur.cpFirst = selUncpLim = selUncpFirst;
  1194. }
  1195. #endif
  1196. //ime string copy
  1197. lstrcpy(lpText, lpIme);
  1198. ForceImeBlock(hWnd, TRUE);
  1199. PutImeString( hWnd, hMem );
  1200. CmdInsIRString();
  1201. ForceImeBlock(hWnd, FALSE);
  1202. GlobalUnlock(hMem);
  1203. lRet = 1L;
  1204. }
  1205. GlobalFree(hMem);
  1206. }
  1207. GlobalUnlock(hIme);
  1208. }
  1209. return lRet;
  1210. }
  1211. //New3.1 IR_STRINGEX
  1212. LONG GetIRStringEX(hWnd, lParam)
  1213. HANDLE hWnd;
  1214. LONG lParam;
  1215. {
  1216. LPSTRINGEXSTRUCT lpString;
  1217. HANDLE hIme, hMem;
  1218. LPSTR lpImechbuf, lpText;
  1219. UINT uLen;
  1220. LONG lRet = (LONG)FALSE;
  1221. if(NULL == (hIme = LOWORD(lParam))) {
  1222. return lRet;
  1223. }
  1224. if (lpString = (LPSTRINGEXSTRUCT)GlobalLock(hIme)) {
  1225. lpImechbuf = (LPSTR)lpString;
  1226. lpImechbuf += lpString->uDeterminePos;
  1227. //Undetermine string length
  1228. if( lpString->uDeterminePos != 0)
  1229. uLen = lstrlen(lpImechbuf);
  1230. //Insert Determin string
  1231. if( uLen != 0 ) {
  1232. if (hMem = GlobalAlloc(GMEM_MOVEABLE, (LONG)(uLen+1))) {
  1233. if (lpText = GlobalLock(hMem)) {
  1234. #if defined(JAPAN) & defined(IME_HIDDEN) //IME3.1J
  1235. //Cut Undetermine string
  1236. if(selUncpLim > selUncpFirst) {
  1237. typeCP Undcp;
  1238. Undcp = selUncpLim - selUncpFirst;
  1239. Replace(docCur, selUncpFirst, Undcp, fnNil, fc0, fc0);
  1240. selCur.cpFirst = selUncpLim = selUncpFirst;
  1241. }
  1242. #endif
  1243. //copy string from IME UNDETERMIN struct
  1244. lstrcpy(lpText, lpImechbuf);
  1245. ForceImeBlock(hWnd, TRUE);
  1246. PutImeString( hWnd, hMem );
  1247. CmdInsIRString();
  1248. ForceImeBlock(hWnd, FALSE);
  1249. GlobalUnlock(hMem);
  1250. lRet = (LONG)TRUE;
  1251. }
  1252. GlobalFree(hMem);
  1253. }
  1254. }
  1255. GlobalUnlock(hIme);
  1256. }
  1257. return lRet;
  1258. }
  1259. #endif // JAPAN & DBCS_IME