Update a RICHEDIT position without focusing

Post Reply
User avatar
concentra
Posts: 107
Joined: Mon Nov 14, 2005 10:15 am
Location: Brazil

Update a RICHEDIT position without focusing

Post by concentra »

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

#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
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Update a RICHEDIT position without focusing

Post by cnavarro »

Ok, try with

Code: Select all

oRTF:GoToLine( oRTF:GetLineCount() )
 
end tell me
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
concentra
Posts: 107
Joined: Mon Nov 14, 2005 10:15 am
Location: Brazil

Re: Update a RICHEDIT position without focusing

Post by concentra »

cnavarro wrote:Ok, try with

Code: Select all

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
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Update a RICHEDIT position without focusing

Post by cnavarro »

Ah, OK, now I understand

Code: Select all

   @ 108,004 GET oTextType VAR cText OF oDlg SIZE 174,78 PIXEL MULTILINE
   oTextType:bGotFocus = { | o | o:SetSel( 0, 0 ), o:GoBottom() }
 
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
concentra
Posts: 107
Joined: Mon Nov 14, 2005 10:15 am
Location: Brazil

Re: Update a RICHEDIT position without focusing

Post by concentra »

cnavarro wrote:

Code: Select all

   @ 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
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Update a RICHEDIT position without focusing

Post by cnavarro »

Saves the position when the focus is lost ( bLostFocus ), and restores the position when acquiring the focus ( bGotFocus )
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
Post Reply