Update a RICHEDIT position without focusing

Update a RICHEDIT position without focusing

Postby concentra » Mon May 28, 2018 6:36 pm

Hi.

This is a chat like application.
The top control, a RICHEDIT, is the chat "history" and the bottom one, a TMultiGet, is the operator typing control.

If the other party types something before the operator finishes what he is typing, what the other party typed must be presented to the operator, without interfering the typing job.

If the RICHEDIT text grows beyond the RICHEDIT size, it must scrolls, in order to the last typed answer can be seen.

Basically, I need to update the RICHEDIT control position while typing some text.

The only way I found to update the RICHEDIT control is to put focus on it, but, since the operator is typing, the focus needs to go back to the TMultiGet control.

But when the TMultiGet looses focus and gets it again, the typed text becomes marked, and, when the operator keeps typing, it is deleted...

How do I update the RICHEDIT control position without putting focus on it ?

In the sample, if you keep typing while changing focus the text is deleted.

Regards,

Maurício Faria

Code: Select all  Expand view  RUN

#include "fivewin.ch"
#include "richedit.ch"

function Main()

   local oWnd

   DEFINE WINDOW oWnd FROM 1,1 TO 140,110 PIXEL

   @ 014,004 BUTTON "With SetFocus "    SIZE 110,30 PIXEL ACTION Go( .T. )
   @ 054,004 BUTTON "Without SetFocus " SIZE 110,30 PIXEL ACTION Go( .F. )

   ACTIVATE WINDOW oWnd

return nil






Function Go( lSetFocus )

   local oDlg
   local cRichText
   local oRich
   local oTextType
   local cText
   local oTimer
   local hRichDLL := LoadLibrary( "riched20.dll" )

   DEFINE Dialog oDlg FROM 1,1 TO 400,400 PIXEL

   @ 004,004 RichEdit oRich VAR cRichText OF oDlg SIZE 176,66 PIXEL READONLY

   @ 108,004 GET oTextType VAR cText OF oDlg SIZE 174,78 PIXEL MULTILINE

   oTimer := TTimer():New( 1000, { || UpdateRTF( oRich, oTimer, oTextType, lSetFocus ) } )

   ACTIVATE Dialog oDlg ON INIT ( oTimer:Activate(), oTextType:SetFocus() )

   freeLibrary( hRichDLL )

return nil




PROCEDURE UpdateRTF( oRich, oTimer, oTextType, lSetFocus )

   LOCAL cHeader := "{\rtf1\ansi\ansicpg1252\deff0\deflang1046" +;
                    "{\fonttbl{\f0\fnil\fcharset0 Courier New;}}" +;
                    "{\colortbl ;\red0\green0\blue0;\red185\green255\blue86;\red255\green255\blue255;\red255\green255\blue100;}" +;
                    "\viewkind4\uc1\pard\b\fs18"
   LOCAL cRTF := ""
   LOCAL I

   STATIC aMsgs

   oTimer:DEACTIVATE()

   IF EMPTY( aMsgs )
      aMsgs := {"MSGS"}
   ENDIF

   AADD( aMsgs, Time() )

   FOR I:=1 TO LEN( aMsgs )

      IF MOD( I, 2 ) = 0
         cRTF += "\cf1\highlight2 " + aMsgs[I] + "\par "
      ELSE
         cRTF += "\cf1\highlight3 " + aMsgs[I] + "\par "
      ENDIF

   NEXT

   cRTF += "}"

   oRich:SetText( cHeader + cRTF )

   oRich:GoTo(oRich:Len())

   IF lSetFocus
      oRich:SetFocus()
      oTextType:SetFocus()
   ENDIF

   oTimer:ACTIVATE()

RETURN
 
User avatar
concentra
 
Posts: 124
Joined: Mon Nov 14, 2005 10:15 am
Location: Brazil

Re: Update a RICHEDIT position without focusing

Postby cnavarro » Mon May 28, 2018 9:15 pm

Ok, try with

Code: Select all  Expand view  RUN

oRTF:GoToLine( oRTF:GetLineCount() )
 


end tell me
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Update a RICHEDIT position without focusing

Postby concentra » Mon May 28, 2018 9:23 pm

cnavarro wrote:Ok, try with

Code: Select all  Expand view  RUN

oRTF:GoToLine( oRTF:GetLineCount() )
 


end tell me

Hi.

I got exactly the same result: without focusing the RICHEDIT doesn't scroll and with focus it scrolls but the TMulitGet deletes what was typed...
User avatar
concentra
 
Posts: 124
Joined: Mon Nov 14, 2005 10:15 am
Location: Brazil

Re: Update a RICHEDIT position without focusing

Postby cnavarro » Mon May 28, 2018 9:50 pm

Ah, OK, now I understand

Code: Select all  Expand view  RUN

   @ 108,004 GET oTextType VAR cText OF oDlg SIZE 174,78 PIXEL MULTILINE
   oTextType:bGotFocus = { | o | o:SetSel( 0, 0 ), o:GoBottom() }
 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Update a RICHEDIT position without focusing

Postby concentra » Tue May 29, 2018 10:32 am

cnavarro wrote:
Code: Select all  Expand view  RUN

   @ 108,004 GET oTextType VAR cText OF oDlg SIZE 174,78 PIXEL MULTILINE
   oTextType:bGotFocus = { | o | o:SetSel( 0, 0 ), o:GoBottom() }
 


Thanks !

It Works.

But it introduces some overhead, it's like going around the block to get to the wall neighbor...

And if the operator moves the cursor to edit the text in other point than the end this solution moves the cursor to the end.

Regards.
User avatar
concentra
 
Posts: 124
Joined: Mon Nov 14, 2005 10:15 am
Location: Brazil

Re: Update a RICHEDIT position without focusing

Postby cnavarro » Tue May 29, 2018 1:43 pm

Saves the position when the focus is lost ( bLostFocus ), and restores the position when acquiring the focus ( bGotFocus )
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 60 guests