FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour error in Richedit [bug in FWH]
Posts: 417
Joined: Tue Feb 23, 2010 03:09 PM
error in Richedit [bug in FWH]
Posted: Tue Jan 24, 2012 01:08 PM
Hello,

When I press the button Bold, all text gets selected:


Uploaded with ImageShack.us


I don´t want this, just continue editing in same position as I was before I press Bold. This is my code:

Code (fw): Select all Collapse
#Include "FiveWin.ch"
//----------------------------------------------------------------------------//
Function Main()

   Local oDlg, oRich, cRtf := "test"
   Local hRichDLL := LoadLibrary( "riched20.dll" )

   local lBold := .F.


   cRtf:="{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Courier New;}}"+CRLF+;
            "{\colortbl ;\red0\green77\blue187;\red192\green80\blue77;}"+CRLF+;
            "{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\cf1\lang1031\f0\fs22 This is \b colored \b0 text\cf0 . \cf2 The background is color 1 and the foreground is color 2\cf0\par"+CRLF+CRLF+;
            "}"




   DEFINE DIALOG oDlg NAME "Test"

   oRich = TRichEdit():Redefine( 100, { || "" }, oDlg )
   oRich:SetText( cRtf )

   oDlg:bStart = { || oRich:SetPos( 0 )}


  REDEFINE BUTTON ID 120  ACTION ( lBold := !lBold, ;
                                   oRich:SetBold( lBold ), oRich:Setfocus() )


   ACTIVATE DIALOG oDlg CENTERED

   FreeLibrary( hRichDLL )

Return nil



What is wrong?.

Thank you very much.
FWH 11.11, Harbour 3.1 and Borland C++ 5.82
Posts: 417
Joined: Tue Feb 23, 2010 03:09 PM
Re: error in Richedit
Posted: Tue Jan 24, 2012 03:01 PM
I forgot .rc file:

Code (fw): Select all Collapse
#define IDC_EDIT1   101

Test DIALOG 41, 64, 409, 199
STYLE DS_MODALFRAME | 0x4L | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Testing the RichEdit control"
FONT 8, "MS Sans Serif"
{
 CONTROL "", 100, "RichEdit20A", 4100 | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP, 6, 12, 398, 163
 PUSHBUTTON "&Load text file", 110, 5, 179, 50, 16
 PUSHBUTTON "&Bold", 120, 95, 179, 50, 16

}
FWH 11.11, Harbour 3.1 and Borland C++ 5.82
Posts: 417
Joined: Tue Feb 23, 2010 03:09 PM
Re: error in Richedit
Posted: Wed Jan 25, 2012 10:43 AM

Any idea please?.

Thanks.

FWH 11.11, Harbour 3.1 and Borland C++ 5.82
Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
Re: error in Richedit
Posted: Wed Jan 25, 2012 02:32 PM

It was working fine with older versions of fwh, but not with 11.09 :(
Same with :SetItalic (), :SetUnderline(), ...

It seems to be a bug

kind regards

Stefan
Posts: 417
Joined: Tue Feb 23, 2010 03:09 PM
Re: error in Richedit
Posted: Wed Jan 25, 2012 03:07 PM

Stefan,

Thanks for helping me.

Antonio, please include the fix in FW 12.01.

Thanks.

FWH 11.11, Harbour 3.1 and Borland C++ 5.82
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: error in Richedit [bug in FWH]
Posted: Wed Jan 25, 2012 06:27 PM

Stefan, John,

Could you please test FWH\samples\TestRtf.prg ? Here it is working fine with bold, underline, italic, etc...

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 417
Joined: Tue Feb 23, 2010 03:09 PM
Re: error in Richedit [bug in FWH]
Posted: Wed Jan 25, 2012 07:35 PM

Antonio

samples\testrtf works fine but not my sample.

In my sample, when I call setfocus() all text get selected.

Can you please try my sample?.

Thanks.

FWH 11.11, Harbour 3.1 and Borland C++ 5.82
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: error in Richedit [bug in FWH]
Posted: Wed Jan 25, 2012 08:19 PM
Jhon

Code (fw): Select all Collapse
ACTION ( lBold := !lBold, ;
                                   oRich:SetBold( lBold ), oRich:Setfocus(), sysrefresh(), oRich:SetPos( 0 ) )


but you have select the text first

if you want select all text and convert to BOLD

Code (fw): Select all Collapse
ACTION ( lBold := !lBold, ;
                                   oRich:SelectAll(), oRich:SetBold( lBold ), oRich:Setfocus(), sysrefresh(), oRich:SetPos( 0 ) )


it's a bug?
Posts: 417
Joined: Tue Feb 23, 2010 03:09 PM
Re: error in Richedit [bug in FWH]
Posted: Wed Jan 25, 2012 08:39 PM
Daniel,

Thanks for helping me.

I explain myself better.

I type into a new line, for example, hello.

Next, I want world in bold, so I press Bold button so as to write world in bold. Instead, I get all text selected as showed in picture.
FWH 11.11, Harbour 3.1 and Borland C++ 5.82
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: error in Richedit [bug in FWH]
Posted: Wed Jan 25, 2012 09:04 PM

John,

You have to select a portion of the text, then change its attributes

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 417
Joined: Tue Feb 23, 2010 03:09 PM
Re: error in Richedit [bug in FWH]
Posted: Wed Jan 25, 2012 09:42 PM

Antonio,

I want to set bold for next text, as samples\testrtf does.

FWH 11.11, Harbour 3.1 and Borland C++ 5.82
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: error in Richedit [bug in FWH]
Posted: Wed Jan 25, 2012 10:23 PM
John,

Try it this way:

Code (fw): Select all Collapse
#Include "FiveWin.ch"

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

Function Main()

   Local oDlg, oRich, cRtf
   Local hRichDLL := LoadLibrary( "riched20.dll" )

   local lBold := .F., nPos := 0

   cRtf:="{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Courier New;}}"+CRLF+;
            "{\colortbl ;\red0\green77\blue187;\red192\green80\blue77;}"+CRLF+;
            "{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\cf1\lang1031\f0\fs22 This is \b colored \b0 text\cf0 . \cf2 The background is color 1 and the foreground is color 2\cf0\par"+CRLF+CRLF+;
            "}"

   DEFINE DIALOG oDlg NAME "Test"

   oRich = TRichEdit():Redefine( 100, "", oDlg )
   oRich:SetText( cRtf )
   oRich:bGotFocus = { || oRich:HideSel(), oRich:SetSel( nPos, nPos ) }
   oRich:bLostFocus = { || nPos := oRich:GetPos() }

   REDEFINE BUTTON ID 120  ACTION ( lBold := ! lBold, ;
                                    oRich:SetBold( lBold ), oRich:SetFocus() )

   ACTIVATE DIALOG oDlg CENTERED

   FreeLibrary( hRichDLL )

Return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: error in Richedit [bug in FWH]
Posted: Wed Jan 25, 2012 10:34 PM
In fact, on a window it behaves different. Why ? I really don't know it...

Code (fw): Select all Collapse
#include "FiveWin.ch"
#include "RichEdit.ch"

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

Function Main()

   local oWnd, oRE, cText := "", lBold := .F.
   
   Local hRichDLL := LoadLibrary( "riched20.dll" )
      
   DEFINE WINDOW oWnd
   
   @ 1, 1 RICHEDIT oRE VAR cText SIZE 400, 200
   
   @ 1, 70 BUTTON "Bold" SIZE 60, 15 ACTION ( oRE:SetBold( lBold := ! lBold ), oRE:SetFocus() )
   
   ACTIVATE WINDOW oWnd

   FreeLibrary( hRichDLL )

Return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
Re: error in Richedit [bug in FWH]
Posted: Thu Jan 26, 2012 08:21 AM

I made some test with different styles, but no change. It´s really curious.

The last sample of Antonio at least is a workaround to change selected text to bold. John´s intention to click the buton and write the next word bold does not work in dialogs

kind regards

Stefan
Posts: 417
Joined: Tue Feb 23, 2010 03:09 PM
Re: error in Richedit [bug in FWH]
Posted: Thu Jan 26, 2012 05:16 PM
Antonio,

Thanks for helping. Now the sample does not select all text, but if I start typing my name and next I press Bold and I type John, John is not in bold.

What is wrong?.

Thanks again.


Code (fw): Select all Collapse
#Include "FiveWin.ch"
#include "richedit.ch"

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

Function Main()

   Local oDlg, oRich, cRtf
   Local hRichDLL := LoadLibrary( "riched20.dll" )

   local lBold := .F., nPos := 0

   cRtf:="{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Courier New;}}"+CRLF+;
            "{\colortbl ;\red0\green77\blue187;\red192\green80\blue77;}"+CRLF+;
            "{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\cf1\lang1031\f0\fs22 This is \b colored \b0 text\cf0 . \cf2 The background is color 1 and the foreground is color 2\cf0\par"+CRLF+CRLF+;
            "}"

   DEFINE DIALOG oDlg NAME "Test"


   REDEFINE RICHEDIT oRich VAR cRTF OF oDlg  ID 100

   REDEFINE BUTTON ID 120  ACTION ( lBold := ! lBold, ;
                                    oRich:SetBold( lBold ), oDlg:Update(), oRich:SetFocus(), oDlg:cTitle := "IsBold "+cValtoChar(lBold) )


   oRich:SetText( cRtf )

   oRich:bGotFocus = { || oRich:HideSel(), oRich:SetSel( nPos, nPos ) }
   oRich:bLostFocus = { || nPos := oRich:GetPos() }


   ACTIVATE DIALOG oDlg CENTERED

   FreeLibrary( hRichDLL )

Return nil
FWH 11.11, Harbour 3.1 and Borland C++ 5.82