FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Richedit how to highlight a defined word in memofields ?
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: How to highlight a defined word in memofields ?
Posted: Mon Mar 19, 2018 02:16 PM
Cristobal,

there are to many problems like unformatted text unexpected side-effect using lhighlight := .t.
Why not define extra keywords for textcolouring like the links
Richedit includes fixed defines for hightlighting
If You test the forum-import-tool, richedit is working fine and shows the memofield
( still textcolouring of defined keywords is missing )



regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: How to highlight a defined word in memofields ?
Posted: Mon Mar 19, 2018 02:25 PM

Sorry, then I did not understand well
Can you give me a small complete example to see what he wants to tell me?
Remember that my English is very poor

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
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: How to highlight a defined word in memofields ?
Posted: Mon Mar 19, 2018 02:30 PM

Uwe,

The first post, was it not working ok for you ?

It seems to do what is needed

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: How to highlight a defined word in memofields ?
Posted: Mon Mar 19, 2018 02:32 PM
Cristobal,

I only defined

@ 70, 625 RICHEDIT5 oTCode VAR cTCode OF oDlg SIZE 600, 380 ; // w h
FONT oFont PIXEL HSCROLL


NO function-call and nothing special
The result is shown on the screenshot
Maybe it would be a good idea to create a minimized sample

regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: How to highlight a defined word in memofields ?
Posted: Mon Mar 19, 2018 02:36 PM

There is a simple sample above, but with Richtedit2. Maybe adjust it to 5 ?

Then we can play with it and find a solution.

Marc

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: How to highlight a defined word in memofields ?
Posted: Mon Mar 19, 2018 02:40 PM
the richedit automatically highlight the url.
About colorize, I have an optimized version:
Code (fw): Select all Collapse
method Colorize(nStart, nEnd, nColor) CLASS TLRICHEDIT5
聽 聽::SetSel( nStart, nEnd )
聽 聽RESetColor(::hWnd, nColor)
return nil

where RESetColor is
<div class="c" id="{CB}" style="font-family: monospace;">
HB_FUNC( RESETCOLOR )
{
聽 聽HWND hWnd = (HWND) fw_parh(1);
聽 聽CHARFORMAT cf;
聽 聽memset(&cf, 0, sizeof(cf));
聽 聽cf.cbSize = sizeof(cf);
聽 聽cf.dwMask = CFM_COLOR;
聽 聽cf.crTextColor = hb_parnl(2);
聽 聽SendMessage(hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
}</div>


that is simpler and about 1/3 faster
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: How to highlight a defined word in memofields ?
Posted: Mon Mar 19, 2018 03:16 PM
Antonino,

thank You for the info

The download of the browser- and richedit section with full source for testing.
http://www.pflegeplus.com/DOWNLOADS/Forum9.zip

The source is kept small in size as possible ( no graphics and colours ) and works with the original forum-import samples1.dbf
The keyword defined inside the browser ( xbrowse-keyword-field ) needed to be coloured.

I'm planning the possibility to add own topics to the list and copy / past sections from other topics to this new one.
Is it possible to do some changes to the richedit and saving it back to the MEMO ?
The < New > and < Save > -buttons are included for testing.



regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: How to highlight a defined word in memofields ?
Posted: Mon Mar 19, 2018 07:07 PM

Uwe, it's solved your question?

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
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: How to highlight a defined word in memofields ?
Posted: Mon Mar 19, 2018 07:40 PM
Cristobal,

No, that is the reason for the download. Without colouring it works fine.
Using another solution the text is not formatted and shows a missing linefeed.
That happens adding
@ 70, 625 RICHEDIT5 oTCode VAR cTCode OF oDlg SIZE 600, 380 ; // w h
FONT oFont PIXEL HSCROLL

regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Richedit how to highlight a defined word in memofields ?
Posted: Wed Mar 21, 2018 02:17 PM
Uwe, I not look problem, please explain more

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
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Richedit how to highlight a defined word in memofields ?
Posted: Wed Mar 21, 2018 05:48 PM
Cristobal,

maybe it is possible to include the logic from Richedit-hightlight method
We have to scan each line for the keyword(s)

The return-values of the included messages are ok but the colouring of the area doesn't work :-)



Code (fw): Select all Collapse
:bChange聽:= { || cTKeyWord1 := UPPER(ALLTRIM((cFileName)->INFO1)), ;
聽 聽cTKeyWord2 := UPPER(ALLTRIM((cFileName)->INFO2)), ;
聽 聽cTopic := ALLTRIM((cFileName)->TOPIC), ;
聽 聽oTopic:SetText( cTopic ), ;
聽 聽SHOW_KEYW( oTopic, cTopic, cTKeyWord1, cTKeyWord2 ), ;
聽 聽cTCode := (cFileName)->CODE, ;
聽 聽oTCode:SetText( cTCode ), ;
聽 聽SHOW_KEYW( oTCode, cTCode, cTKeyWord1, cTKeyWord2 ), ;聽聽 聽 聽 聽 聽 聽 聽 聽 聽
聽 聽TCode:GoToLine( 1 ) }
...
...

// ----------------- Check each line -----------

FUNCTION SHOW_KEYW( oCode, cCode, cKeyWord1, cKeyWord2 )
LOCAL nPos := 20, nLen := 50, nLine

FOR nLine := 1 to oCode:GetLineCount() // 聽Scan line by line
聽 聽 聽 聽THIGHLIGHT( nLine, oCode, cCode, cKeyWord1, cKeyWord2 ) 
聽 聽 聽 聽SysRefresh()
NEXT

RETURN NIL

// ----------------- Keyword hightlight ----------

FUNCTION THIGHLIGHT( nLine, oCode, cCode, cKeyWord1, cKeyWord2 ) 
local cLine聽:= ""
local nAt聽 聽:= 1
local nAt1聽 := 0
local nAt2聽 := 0
local nSep := 0
local nLen聽 := 0
local nGetSel := oCode:SendMsg( EM_GETSEL )

oCode:aKeywords1 聽= { cKeyWord1, cKeyWord2 } 
oCode:GoTo( nLine )
oCode:SendMsg( 11, 0, 0 )

// review keywords in current line to highlight them
cLine = StrTran( oCode:GetLine( nLine ), Chr( 13 ), "" ) // result cLine = Linetext
nLen = Len( cLine )

nAt1 := AT( cKeyWord1, UPPER(cLine) ) 聽
nAt2 := AT( cKeyWord2, UPPER(cLine) ) 聽
IF nAt1 > 0
聽 聽 MsgAlert( cLine, "Line" + " 聽->> " + ALLTRIM( STR(nLine)) )
聽 聽 MsgAlert( nAt1, "Left 1" )
聽 聽 MsgAlert( LEN( cKeyWord1 ), "Len Keyword 1" )
聽 聽 oCode:Colorize( nAt1, LEN( cKeyWord1 ), 255 )
ENDIF
IF nAt2 > 0
聽 聽 MsgAlert( cLine, "Line" + " 聽->> " + ALLTRIM( STR(nLine)) )
聽 聽 MsgAlert( nAt2, "Left 2" )
聽 聽 MsgAlert( LEN( cKeyWord2 ), "Len Keyword 2" )
聽 聽 oCode:Colorize( nAt2, LEN( cKeyWord2 ), 255 )
ENDIF

// Let the control be painted
oCode:SendMsg( 11, 1, 0 )
InvalidateRect( oCode:hWnd )

RETURN NIL


regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Richedit how to highlight a defined word in memofields ?
Posted: Fri Mar 23, 2018 06:11 PM
Uwe, sorry for the time in answering
Made with your logic

1.- Your :bChange codeblock is Ok
2.- Remove clause highlight ( not need for this topic )
3.- Please apply this functions and tell me

Code (fw): Select all Collapse
//----------------------------------------------------------------------------//

Function SHOW_KEYW( oCode, cCode, cKeyWord1, cKeyWord2 )

聽 聽Local nLine := 0
聽 聽
聽 聽FOR nLine := 1 to oCode:GetLineCount()
聽 聽 聽 THIGHLIGHT( nLine, oCode, cCode, cKeyWord1, cKeyWord2 ) 
聽 聽NEXT

Return nil

//----------------------------------------------------------------------------//

FUNCTION THIGHLIGHT( nLine, oCode, cCode, cKeyWord1, cKeyWord2 ) 

聽 聽local cLine := ""
聽 聽local nAt 聽 := 1
聽 聽local nAt1 聽:= 0
聽 聽local nAt2 聽:= 0
聽 聽local nPos1 := 0
聽 聽local nPos2 := 0

聽 聽oCode:GoTo( nLine - 1 )
聽 聽cLine 聽 聽 聽 := Upper( oCode:GetLine( nLine ) )

聽 聽if !Empty( cKeyWord1 )
聽 聽 聽 nAt1 聽 聽 := At( Upper( AllTrim( cKeyWord1 ) ), cLine ) 聽
聽 聽 聽 IF nAt1 > 0
聽 聽 聽 聽 聽 nPos1 聽 := oCode:GetPos() + nAt1 - 1
聽 聽 聽 聽 聽 nPos2 聽 := nPos1 + Len( AllTrim( cKeyWord1 ) )
聽 聽 聽 聽 聽 oCode:Colorize( nPos1, nPos2, 255 )
聽 聽 聽 endif
聽 聽endif

聽 聽if !Empty( cKeyWord2 )
聽 聽 聽 if ( nAt2 := AT( Upper( AllTrim( cKeyWord2 ) ), cLine ) > 0 )
聽 聽 聽 聽 聽nPos1 聽 := oCode:GetPos() + nAt1 - 1
聽 聽 聽 聽 聽nPos2 聽 := nPos1 + Len( AllTrim( cKeyWord1 ) )
聽 聽 聽 聽 聽oCode:Colorize( nPos1, nPos2, 255 )
聽 聽 聽 endif
聽 聽endif

Return nil

//----------------------------------------------------------------------------//
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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Richedit how to highlight a defined word in memofields ?
Posted: Fri Mar 23, 2018 06:25 PM
Also, look this
( Remove clause highlight ( not need for this topic ) )

Code (fw): Select all Collapse
聽 聽 聽 :bChange := { || cTopic 聽 聽 := Alltrim((cFileName)->TOPIC), ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽oTopic:SetText( cTopic ), ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽oTopic:aKeyWords1 聽:= ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽oTCode:aKeyWords1 聽:= { Alltrim( ( cFileName )->INFO1 ), ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽Alltrim( ( cFileName )->INFO2 ) }, ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽oTopic:nClrKey1 聽 聽:= ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽oTCode:nClrKey1 聽 聽:= CLR_HCYAN, ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽SHOW_KEYW( oTopic ), ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽cTCode := ( cFileName )->CODE, ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽oTCode:SetText( cTCode ), ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽SHOW_KEYW( oTCode ), ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽oTCode:GoToLine( 1 ) }


..../....

//----------------------------------------------------------------------------//

Function SHOW_KEYW( oCode )

聽 聽Local nLine := 0
聽 聽
聽 聽FOR nLine := 1 to oCode:GetLineCount()
聽 聽 聽 THIGHLIGHT( nLine, oCode )
聽 聽NEXT

Return nil

//----------------------------------------------------------------------------//

FUNCTION THIGHLIGHT( nLine, oCode )

聽 聽local cLine := ""
聽 聽local nAt 聽 := 1
聽 聽local nAt1 聽:= 0
聽 聽local nAt2 聽:= 0
聽 聽local nPos1 := 0
聽 聽local nPos2 := 0
聽 聽local x

聽 聽oCode:GoTo( nLine - 1 )
聽 聽cLine 聽 聽 聽 := Upper( oCode:GetLine( nLine ) )
聽 聽For x = 1 to Len( oCode:aKeyWords1 )
聽 聽 聽 if !Empty( oCode:aKeyWords1[ x ] )
聽 聽 聽 聽 聽nAt1 聽 聽 := At( Upper( oCode:aKeyWords1[ x ] ), cLine )
聽 聽 聽 聽 聽if nAt1 > 0
聽 聽 聽 聽 聽 聽 聽nPos1 聽 := oCode:GetPos() + nAt1 - 1
聽 聽 聽 聽 聽 聽 聽nPos2 聽 := nPos1 + Len( oCode:aKeyWords1[ x ] )
聽 聽 聽 聽 聽 聽 聽oCode:Colorize( nPos1, nPos2, oCode:nClrKey1 )
聽 聽 聽 聽 聽endif
聽 聽 聽 endif
聽 聽Next x

Return nil

//----------------------------------------------------------------------------//
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
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Richedit how to highlight a defined word in memofields ?
Posted: Sat Mar 24, 2018 08:13 AM
Crist贸bal,

thank You very much.
That is exactly the solution I've been looking for :-)
A clean textpreview without any flickering.

Now I can finish the forum-sample-import.



regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Richedit how to highlight a defined word in memofields ?
Posted: Sat Mar 24, 2018 08:24 AM

Could we create a PRG to import all forums posts to a DBF ? :-)

How to know how many posts a forum has ?

How to know in a specific topic, what the next post ?

Could we have a function ForumGetPost( ... ) that returns an array or an object with ?

  1. Title (topic)
  2. Date
  3. Author
  4. Next post in topic
  5. Contents
  6. Forum that belongs to
  7. number of views (?)
  8. what else ?

that would be great! :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com