SetFocus() changes affecting RichEdit

SetFocus() changes affecting RichEdit

Postby reinaldocrespo » Thu Mar 01, 2012 3: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: Select all  Expand view

// 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: Select all  Expand view

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.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: SetFocus() changes affecting RichEdit

Postby reinaldocrespo » Fri Mar 02, 2012 8: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.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: SetFocus() changes affecting RichEdit

Postby reinaldocrespo » Sat Mar 03, 2012 5: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.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: SetFocus() changes affecting RichEdit

Postby Antonio Linares » Sat Mar 03, 2012 7:36 pm

Reinaldo,

Please call SetFocus( oRich:hWnd ) instead of oRich:SetFocus()
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42087
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: SetFocus() changes affecting RichEdit

Postby reinaldocrespo » Sat Mar 03, 2012 7:45 pm

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

It works!

Love you dude!


Reinaldo.
Last edited by reinaldocrespo on Sat Mar 03, 2012 8:41 pm, edited 1 time in total.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: SetFocus() changes affecting RichEdit

Postby Antonio Linares » Sat Mar 03, 2012 8:38 pm

Very good :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42087
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], Otto and 91 guests