FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour SetFocus() changes affecting RichEdit
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
SetFocus() changes affecting RichEdit
Posted: Thu Mar 01, 2012 03:42 AM
Hi everyone;

Recent versions have broken richtext. To reproduce the problem, compile this sample. On execution type some text or click on the 1st button to load text to the control, then highlight a word (any word) and press the [bold selection] button to the far bottom-right hand corner. The highlighted word will become bold, but the selection will change to the entire text. This happens as focus is regained by the richtext control. To further demonstrate my point, don't even highlight a word, instead simply press the [bold selection] button and see how all text gets selected. Again this happens as the richt-Text control regains focus.

Sample code:
Code (fw): Select all Collapse
// FWH and FW++ RichEdit sample

#include "FiveWin.ch"

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

function Main()

   local oDlg, oRich
   local hRichDLL := LoadLibrary( "riched20.dll" )
   local lSyntaxHL := .f.

   DEFINE DIALOG oDlg NAME "Test"

   oRich = TRichEdit():Redefine( 100, { || "" }, oDlg )
   oRich:lHighLight = .f.

   REDEFINE BUTTON ID 110 ;
      ACTION oRich:SetText( MemoRead( "TestRich.prg" ) )

   REDEFINE CHECKBOX lSyntaxHL ID 115 OF oDlg ;
      ON CHANGE ( oRich:lHighLight := lSyntaxHL,;
                  oRich:SetText( oRich:GetText() ) )

   REDEFINE BUTTON ID 120 ;
      ACTION oRich:LoadFromRTFFile( cGetFile( "RTF file (*.rtf) | *.rtf" ) )

   REDEFINE BUTTON ID 130 ;
      ACTION oRich:SaveToRTFFile( cGetFile( "RTF file (*.rtf) | *.rtf",;
                                  "Please write a filename", "test" ) )

   //oRich:SetFocus() should return focus back to edit mode.  Instead 
   //it re-selects all text on the control. -not good.
   REDEFINE BUTTON ID 998 ACTION ( oRich:SetBold( .t. ), oRich:SetFocus() )

   ACTIVATE DIALOG oDlg CENTERED 

   FreeLibrary( hRichDLL )

return nil

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

.rc file:
Code (fw): Select all Collapse
TEST DIALOG 41, 64, 409, 199
STYLE DS_3DLOOK |DS_SETFONT |DS_MODALFRAME |WS_POPUP |WS_VISIBLE |WS_SYSMENU |WS_CAPTION 
CAPTION "Testing the RichEdit control"
FONT 8, "MS Sans Serif"
LANGUAGE LANG_NEUTRAL, 0
BEGIN
  CONTROL "",100,"RichEdit20A",WS_CHILD |WS_BORDER |WS_VSCROLL |WS_TABSTOP |WS_VISIBLE |0x1004,6,12,398,163
  CONTROL "&Load text file",110,"BUTTON",BS_PUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP ,5,179,50,16
  CONTROL "Activate syntax highlight",115,"BUTTON",BS_AUTOCHECKBOX |BS_LEFT |WS_CHILD |WS_TABSTOP ,65,182,92,11
  CONTROL "L&oad RTF file",120,"BUTTON",BS_PUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP ,162,179,50,16
  CONTROL "&Save RTF file",130,"BUTTON",BS_PUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP ,226,179,50,16
  CONTROL "&End",2,"BUTTON",BS_PUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP ,290,179,50,16
  CONTROL "Bold Selection",998,"BUTTON",BS_PUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP ,354,179,50,16
END


PLEASE HELP!


Reinaldo.
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: SetFocus() changes affecting RichEdit
Posted: Fri Mar 02, 2012 08:28 PM

Hi.

I'm sorry that I keep bringing this up.

Does this makes any sense to anyone?

Isn't anyone else using tRichEdi class seen this problem?

Reinaldo.

Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: SetFocus() changes affecting RichEdit
Posted: Sat Mar 03, 2012 05:01 PM

Pressure from users is mounting. I really need to solve this problem... please?

I can prepare a self contained sample to reproduce the problem if anyone is interested.

Thank you,

Reinaldo.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: SetFocus() changes affecting RichEdit
Posted: Sat Mar 03, 2012 07:36 PM

Reinaldo,

Please call SetFocus( oRich:hWnd ) instead of oRich:SetFocus()

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: SetFocus() changes affecting RichEdit
Posted: Sat Mar 03, 2012 07:45 PM

COÑÑÑÑÑÑOOOOO - Am I allowed to say that with a Cuban accent?

It works!

Love you dude!

Reinaldo.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: SetFocus() changes affecting RichEdit
Posted: Sat Mar 03, 2012 08:38 PM

Very good :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion