changeset 995:65ccdda2d743

Fixes to MLE handling to make it work like the other platforms. Carriage returns are now stripped and the MLE is in no translate mode so the insertion point is the same as the returned buffer.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 07 May 2011 19:49:24 +0000
parents f1c7b03f944d
children 69cf9f26e899
files os2/dw.c
diffstat 1 files changed, 38 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/os2/dw.c	Sat May 07 19:46:58 2011 +0000
+++ b/os2/dw.c	Sat May 07 19:49:24 2011 +0000
@@ -4881,7 +4881,8 @@
                         HWND_TOP,
                         id,
                         NULL,
-                        NULL);
+                              NULL);
+   WinSendMsg(tmp, MLM_FORMAT, MLFIE_NOTRANS, 0);
    blah->oldproc = WinSubclassWindow(tmp, _mleproc);
    WinSetWindowPtr(tmp, QWP_USER, blah);
    dw_window_set_font(tmp, DefaultFont);
@@ -6348,6 +6349,21 @@
    WinSendMsg(handle, LM_DELETEITEM, MPFROMSHORT(index), 0);
 }
 
+void _strip_cr(char *dest, char *src)
+{
+   int z, x = 0;
+
+   for(z=0;z<strlen(src);z++)
+   {
+      if(src[z] != '\r')
+      {
+         dest[x] = src[z];
+         x++;
+      }
+   }
+   dest[x] = 0;
+}
+
 /*
  * Adds text to an MLE box and returns the current point.
  * Parameters:
@@ -6367,23 +6383,34 @@
 
       while(written < len)
       {
+         int z, x = 0;
+         char buf[1024];
+
          if((len - written) > 65535)
             amount = 65535;
          else
             amount = len - written;
 
-         memcpy(mlebuf, &buffer[written], amount);
-         mlebuf[amount] = '\0';
-
-         WinSendMsg(handle, MLM_SETIMPORTEXPORT, MPFROMP(mlebuf), MPFROMLONG(amount + 1));
-         WinSendMsg(handle, MLM_IMPORT, MPFROMP(&point), MPFROMLONG(amount + 1));
-         dw_mle_delete(handle, point, 1);
+         /* Remove Carriage Returns \r */
+         for(z=0;z<amount;z++)
+         {
+             if(buffer[z] != '\r')
+             {
+                 mlebuf[x] = buffer[z];
+                 x++;
+             }
+         }
+
+         if(point < 0)
+             point = 0;
+         WinSendMsg(handle, MLM_SETIMPORTEXPORT, MPFROMP(mlebuf), MPFROMLONG(x));
+         WinSendMsg(handle, MLM_IMPORT, MPFROMP(&point), MPFROMLONG(x));
 
          written += amount;
       }
       DosFreeMem(mlebuf);
    }
-   return point - 1;
+   return point;
 }
 
 /*
@@ -6396,7 +6423,7 @@
  */
 void API dw_mle_export(HWND handle, char *buffer, int startpoint, int length)
 {
-   PBYTE mlebuf;
+    PBYTE mlebuf;
 
    /* Work around 64K limit */
    if(!DosAllocMem((PPVOID) &mlebuf, 65535, PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_TILE))
@@ -6450,18 +6477,7 @@
  */
 void API dw_mle_delete(HWND handle, int startpoint, int length)
 {
-   char *buf = malloc(length+1);
-   int z, dellen = length;
-
-   dw_mle_export(handle, buf, startpoint, length);
-
-   for(z=0;z<length-1;z++)
-   {
-      if(strncmp(&buf[z], "\r\n", 2) == 0)
-         dellen--;
-   }
-   WinSendMsg(handle, MLM_DELETE, MPFROMLONG(startpoint), MPFROMLONG(dellen));
-   free(buf);
+   WinSendMsg(handle, MLM_DELETE, MPFROMLONG(startpoint), MPFROMLONG(length));
 }
 
 /*
@@ -6520,6 +6536,7 @@
  */
 void API dw_mle_set_cursor(HWND handle, int point)
 {
+   point--;
    WinSendMsg(handle, MLM_SETSEL, MPFROMLONG(point), MPFROMLONG(point));
 }