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.