"gerard patel" <[EMAIL PROTECTED]> wrote:

> >Do you have an application that doesn't work after the edit control rewrite?
> 
> Notepad 16 bits. The version I use for testing was coming with Wfw 3.11 I think.
> I have searched a bit and the problem seems to be the buffer length.

The problem is that current code doesn't synchronize the sizes
of external and internal unicode buffers.

> Did you consider to keep an ansi buffer for ansi apps ? I don't know how easy
> a double compilation would be to implement inside Wine (like it's done for 
>applications,
> with a call like GetText generating GetTextA or GetTextW according to the state
> of the UNICODE flag), but maybe it could have made the code simpler and somewhat 
> more efficient.

Really it was an approach that I've tried to implement first. But look,
there are multibyte characters out there. So working with multibyte buffer
is very ugly by CharNext() etc., and even more slower than simple synchronization
(WideCharToMultiByte and MultiByteToWideChar are quite fast).

Please try this patch (I have no 16-bit notepad):

--- cvs/wine/controls/edit.c    Fri Jan  5 15:21:35 2001
+++ wine/controls/edit.c        Mon Jan  8 18:28:28 2001
@@ -1482,14 +1482,12 @@
        }
        if (!es->text) {
            CHAR *textA = NULL;
-           INT countA = 0;
+           UINT countA = 0;
            BOOL _16bit = FALSE;
+           UINT countW_new;
 
            if(es->hloc32W)
            {
-               /*TRACE("Locking 32-bit UNICODE buffer\n");*/
-               es->text = LocalLock(es->hloc32W);
-
                if(es->hloc32A)
                {
                    TRACE("Synchronizing with 32-bit ANSI buffer\n");
@@ -1509,6 +1507,22 @@
                return;
            }
 
+           countW_new = MultiByteToWideChar(CP_ACP, 0, textA, countA, NULL, 0);
+           if(countW_new > es->buffer_size)
+           {
+               HLOCAL hloc32W_new;
+               UINT alloc_size = (countW_new * sizeof(WCHAR) + GROWLENGTH - 1) & 
+~(GROWLENGTH - 1);
+               TRACE("Resizing 32-bit UNICODE buffer to %d bytes\n", alloc_size);
+               hloc32W_new = LocalReAlloc(es->hloc32W, alloc_size, LMEM_MOVEABLE | 
+LMEM_ZEROINIT);
+               if(hloc32W_new)
+                   es->hloc32W = hloc32W_new;
+               else
+                   WARN("FAILED! Will Synchronize partially\n");
+           }
+
+           /*TRACE("Locking 32-bit UNICODE buffer\n");*/
+           es->text = LocalLock(es->hloc32W);
+
            if(textA)
            {
                MultiByteToWideChar(CP_ACP, 0, textA, countA, es->text, 
es->buffer_size);
@@ -2140,18 +2154,39 @@
            if (es->hloc32W) {
                CHAR *textA = NULL;
                BOOL _16bit = FALSE;
-               INT countA = 0;
+               UINT countA = 0;
+               UINT countA_new = WideCharToMultiByte(CP_ACP, 0, es->text, 
+es->buffer_size, NULL, 0, NULL, NULL);
 
                if(es->hloc32A)
                {
                    TRACE("Synchronizing with 32-bit ANSI buffer\n");
                    countA = LocalSize(es->hloc32A);
+                   if(countA_new > countA)
+                   {
+                       HLOCAL hloc32A_new;
+                       TRACE("Resizing 32-bit ANSI buffer to %d bytes\n", countA_new);
+                       hloc32A_new = LocalReAlloc(es->hloc32A, countA_new, 
+LMEM_MOVEABLE | LMEM_ZEROINIT);
+                       if(hloc32A_new)
+                           es->hloc32A = hloc32A_new;
+                       else
+                           WARN("FAILED! Will Synchronize partially\n");
+                   }
                    textA = LocalLock(es->hloc32A);
                }
                else if(es->hloc16)
                {
                    TRACE("Synchronizing with 16-bit ANSI buffer\n");
                    countA = LOCAL_Size(wnd->hInstance, es->hloc16);
+                   if(countA_new > countA)
+                   {
+                       HLOCAL16 hloc16_new;
+                       TRACE("Resizing 16-bit ANSI buffer to %d bytes\n", countA_new);
+                       hloc16_new = LOCAL_ReAlloc(wnd->hInstance, es->hloc16, 
+countA_new, LMEM_MOVEABLE | LMEM_ZEROINIT);
+                       if(hloc16_new)
+                           es->hloc16 = hloc16_new;
+                       else
+                           WARN("FAILED! Will Synchronize partially\n");
+                   }
                    textA = LOCAL_Lock(wnd->hInstance, es->hloc16);
                    _16bit = TRUE;
                }



Reply via email to