FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour RTF from Variable
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
RTF from Variable
Posted: Fri May 05, 2017 09:13 PM
To All

This is my first try at RichEdit ... I have an Ms Access table with an attribute set to Text .. I have no problem saving plain text or retrieving plain text and Add\Editing it using MEMO.. However, Using the same basic Principal from richedit.ch .. I can Redefine the object and variable .. however I cannot get the code to reveal any text in my dialog box .. I know the cRtf variable has content .. see image, but the variable never resolves in the Dialog .. Here is my code:
Code (fw): Select all Collapse
Try
聽 hRichDll := LoadLibrary( "riched20.dll" )
Catch
聽 聽Return(.f.)
ENd Try

cLetter 聽 聽 聽:= oRsLetter:Fields("BODY"):Value
..
..
..
REDEFINE BTNBMP oButt3 PROMPT cRtPrompt ID 123 of oDlg LEFT 2007 ; 聽// letter
聽 聽 聽 聽 聽RESOURCE "LETTER32";
聽 聽 聽 聽 聽ACTION ( _ViewMemo( cMode, Substr(cName,1,30), oRsLetter, oButt3, @cRtPrompt, @cLetter ));
聽 聽 聽 聽 GRADIENT DarkGreyButtonGrad()


//-----------------------------
Static FUNC _ViewMemo( cMODE, cTitle, oRsLetter, oButt3, cRtPrompt, cLetter )

Local SAYING, oUSERS
Local oRTF, cRTF, oBtn1,oBtn2
Local lOk,nLen,cOldMemo

Lok 聽 聽 聽:= .f.
cOldMemo := cLetter

If empty( cTitle )
聽 聽cTitle := "Text Viewer"
Endif

Do Case
Case cMode = "E"
聽 聽 聽cTITLE := cTitle +" 聽 聽 EDIT"
Case cMode = "A"
聽 聽 聽cTITLE := cTitle +" 聽 聽 聽ADD"
Case cMode = "V"
聽 聽 聽cTITLE := cTitle +" 聽 聽 VIEW"
EndCase

cRtf := cLetter

msginfo( cRtf ) 聽 // have content here

SetDlgGradient() 聽// reset to blank

DEFINE DIALOG oUSERS RESOURCE "MEMO" ;
聽 聽 聽 聽TITLE cTITLE 聽 聽 聽 聽 聽 聽 聽;


IF cMODE = "E" .or. cMode = "A"
聽 聽
聽 聽REDEFINE RICHEDIT oRtf VAR cRtf ID 130 of oUSERS //UPDATE

ELSE 聽 聽 // view

聽 聽REDEFINE RICHEDIT oRtf VAR cRtf ID 130 of oUSERS READONLY //COLOR CLR_BLACK, 15987697 READONLY

ENDIF


REDEFINE BTNBMP oBtn1 ID 111 of oUSERS 聽 ; 聽 聽 // ok
聽 聽 聽 聽 聽RESOURCE "OK", "DOK", "DOK" ;
聽 聽 聽 聽 聽PROMPT "&Ok" LEFT 2007;
聽 聽 聽 聽 聽ACTION ( lOk := .t.,;
聽 聽 聽 聽 聽 聽 聽 聽 聽 If( lOk = .t., cLetter := cRtf, ),;
聽 聽 聽 聽 聽 聽 聽 聽 聽 If( lOk = .t., oUSERS:END(),) 聽)

REDEFINE BTNBMP oBtn2 ID 112 of oUSERS 聽 ; 聽 聽// cancel
聽 聽 聽 聽 聽RESOURCE "CANCEL", "DCANCEL", "DCANCEL" ;
聽 聽 聽 聽 聽PROMPT "&Cancel" LEFT 2007;
聽 聽 聽 聽 聽ACTION lOk := .f., oUSERS:END()

ACTIVATE DIALOG oUSERS 聽;
聽 聽 聽ON INIT ( oUsers:Move(100,250) );
聽 聽 聽VALID (!GETKEYSTATE( 27 )) ; 聽// do not allow esc key here

If cMode = "V"
聽 聽cLetter := cOldMemo
Endif

If lOk = .t.
聽 聽nLen 聽:= Len( cLetter )

聽 聽Do Case
聽 聽Case nLen = 0
聽 聽 聽 聽 cRtPrompt := "Create Letter"
聽 聽Case nLen > 0
聽 聽 聽 聽 cRtPrompt := "View Letter"
聽 聽End Case

聽 聽oButt3:cCAPTION := cRtPrompt
聽 聽* oBtn3:SetColor( "R+/W*" )
聽 聽oButt3:ReFresh()
ENdif

LightGreyGrad()

RETURN( NIL )


Memo.Rc
Code (fw): Select all Collapse
// Generated by ResEdit 1.6.6
// Copyright (C) 2006-2015
// <!-- m --><a class="postlink" href="http://www.resedit.net">http://www.resedit.net</a><!-- m -->

#include <windows.h>
#include <commctrl.h>

MEMO DIALOG 13, 35, 387, 303
STYLE WS_POPUP | WS_CAPTION
FONT 6, "MS Sans Serif"
{
聽LTEXT "Text", -1, 2, 9, 21, 8
聽EDITTEXT 130, 25, 8, 355, 245, ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | WS_BORDER | WS_VSCROLL | WS_TABSTOP
聽CONTROL "Ok", 111, "TBtnBmp", 32 | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 281, 265, 41, 25
聽CONTROL "Cancel", 112, "TBtnBmp", 32 | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 327, 265, 41, 25
}





Any Ideas ??
Rick Lipkin
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: RTF from Variable
Posted: Fri May 05, 2017 09:42 PM
Rick,

you have to use the following control in your resource file:

Code (fw): Select all Collapse
CONTROL "", 130, "RichEdit20A", ES_LEFT | ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP, 25, 8, 355, 245


EMG
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: RTF from Variable
Posted: Fri May 05, 2017 10:00 PM
Enrico

Thank You!! .. I made the changes in the resource file, but it had no effect .. :-)

Rick Lipkin

Code (fw): Select all Collapse
/ Generated by ResEdit 1.6.6
// Copyright (C) 2006-2015
// <!-- m --><a class="postlink" href="http://www.resedit.net">http://www.resedit.net</a><!-- m -->

#include <windows.h>
#include <commctrl.h>


MEMO DIALOG 13, 35, 387, 303
STYLE WS_POPUP | WS_CAPTION
FONT 6, "MS Sans Serif"
{
聽LTEXT "Text", -1, 2, 9, 21, 8
聽CONTROL "", 130, "RichEdit20A", ES_LEFT | ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP, 25, 8, 355, 245 
聽CONTROL "Ok", 111, "TBtnBmp", 32 | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 281, 265, 41, 25
聽CONTROL "Cancel", 112, "TBtnBmp", 32 | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 327, 265, 41, 25
}
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: RTF from Variable
Posted: Fri May 05, 2017 10:24 PM
You also have to load the text using

Code (fw): Select all Collapse
oRtf:LoadRTF( cLetter )


EMG
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: RTF from Variable
Posted: Fri May 05, 2017 10:49 PM
Rick

Two themes:

1.- You can use the new Fivewin class TRichEdit5
Here is an example of use
Code (fw): Select all Collapse
//
// FWH New Class RichEdit5 sample
// 

#include "FiveWin.ch"
#include "RichEdi5.ch"

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

function Main()

聽 聽local oDlg, oRich
聽 聽local lSyntaxHL := .f.
聽 聽local cRTF 聽 := ""

聽 聽DEFINE DIALOG oDlg NAME "Test"

聽 聽REDEFINE RICHEDIT5 oRich VAR cRTF ID 100 OF 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" ) )

聽 聽REDEFINE BUTTON ID 998 ACTION ( oRich:GoToLine( 10 ), oRich:SetFocus() )

聽 聽ACTIVATE DIALOG oDlg CENTERED ;
聽 聽 聽 // ON INIT oRich:AutoURLDetect( .t. )

聽 聽//FreeLibrary( hRichDLL )

return nil

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


And your .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, "RichEdit50W", 4100 | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP, 6, 12, 398, 163
聽PUSHBUTTON "&Load text file", 110, 5, 179, 50, 16
聽CHECKBOX "Activate syntax highlight", 115, 65, 182, 92, 11, BS_AUTOCHECKBOX | WS_TABSTOP
聽PUSHBUTTON "L&oad RTF file", 120, 162, 179, 50, 16
聽PUSHBUTTON "&Save RTF file", 130, 226, 179, 50, 16
聽PUSHBUTTON "&End", IDCANCEL, 290, 179, 50, 16
聽PUSHBUTTON "&Win Class", 998, 354, 179, 50, 16
}


2.- When you want to initialize the control with a text, you can use the SetText method of the control

Code (fw): Select all Collapse
聽 聽REDEFINE RICHEDIT5 oRich VAR cRTF ID 100 OF oDlg
// 聽 oRich:lHighLight = .f.
聽 聽oRich:SetText( cLetter )


// 聽or in INIT of DIALOG

聽 聽ACTIVATE DIALOG oDlg CENTERED 聽ON INIT oRich:SetText( cLetter )


You can also see a larger example in samples\TestRTf5.prg
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: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: RTF from Variable
Posted: Sat May 06, 2017 03:46 PM

Cristabol

I have got the text working .. but when I save cLetter to Access .. it does not save any of my changes

oRsLetter:Fields("Body"):Value := cLetter
oRsUpdate()

Does not save any changes .. is there a write Rtf method to Variable I am missing ?

Thanks
Rick Lipkin

PS .. is there a way to see the text with out the hi-lights ?

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: RTF from Variable
Posted: Sat May 06, 2017 04:58 PM
Rick Lipkin wrote:Cristabol

I have got the text working .. but when I save cLetter to Access .. it does not save any of my changes

oRsLetter:Fields("Body"):Value := cLetter
oRsUpdate()

Does not save any changes .. is there a write Rtf method to Variable I am missing ?

Thanks
Rick Lipkin

PS .. is there a way to see the text with out the hi-lights ?


Rick,
For hi-lights text

Code (fw): Select all Collapse
聽 聽oRtf:HighLightAllText()


Missing in the REDEFINE method

Code (fw): Select all Collapse
.../...
聽 聽oWnd:DefControl( Self )

聽 聽// Add this to METHOD REDEFINE
聽 聽::SetFont2RTF( ::oFont:nHeight ) 聽// to adjust point size
聽 聽if ::lHighlight
聽 聽 聽 ::HighLightAllText()
聽 聽endif


then use it
Code (fw): Select all Collapse
REDEFINE RICHEDIT5 oRich VAR cRTF ID 100 OF oDlg HIGHLIGHT


For save text to variable, before put in database

Code (fw): Select all Collapse
聽 聽 cLetter := oRtf:GetText()


Also, I think it has to work
Code (fw): Select all Collapse
聽 聽 cLetter := cRtf 聽 聽// variable of control RichEdit
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: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: RTF from Variable
Posted: Sat May 06, 2017 05:39 PM
Cristabol

Thank you for the GetText() method .. that worked perfect .. when I first load my text .. all the lines are hi-lighlited ... I do not want to see the hi-lights .. any way I can TURN OFF the hi-lights .. perhaps a KeyBoard() command to clear the color ?

What is the difference in :

oRtf:LoadRTF( cRtf ) // this method does not work
oRtf:SetText( cRtf ) // this method DOES work

Also .. is there a oRtf:MoveTop .. I see GoToLine() .. but oRtf:GoToLine(1) .. does not move the cursor to the top of the text .


Rick Lipkin

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: RTF from Variable
Posted: Sat May 06, 2017 05:56 PM
Rick Lipkin wrote:Cristabol

Thank you for the GetText() method .. that worked perfect .. when I first load my text .. all the lines are hi-lighlited ... I do not want to see the hi-lights .. any way I can TURN OFF the hi-lights .. perhaps a KeyBoard() command to clear the color ?

What is the difference in :

oRtf:LoadRTF( cRtf ) // this method does not work
oRtf:SetText( cRtf ) // this method DOES work



Rick

METHOD LoadRTF is for load file .RTF, not a string

Please try with METHOD InsertRTF( cRTF ), in the place of SetText

Other theme
You can ask with the oRTF:IsModify() method, to know if it is necessary to save or not, or apply clausule WHEN oRTF:IsModify() at Button
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: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: RTF from Variable
Posted: Sat May 06, 2017 06:07 PM
Rick Lipkin wrote:What is the difference in :

oRtf:LoadRTF( cRtf ) // this method does not work
oRtf:SetText( cRtf ) // this method DOES work


Both work fine for me.

EMG
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: RTF from Variable
Posted: Sat May 06, 2017 06:09 PM
cnavarro wrote:METHOD LoadRTF is for load file .RTF, not a string


No. Please look at this:

Code (fw): Select all Collapse
METHOD LoadFromRTFFile( cFileName ) INLINE ::cFileName := cFileName, ::LoadRTF( MemoRead( ::cFileName ) )


EMG
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: RTF from Variable
Posted: Sat May 06, 2017 06:17 PM

Cristabol

The oRtf:InsertRTF( cRTF ) method did not load any text ...

1) I do not see a method to move the cursor to the top ?? any ideas on that ?
2) a Workaround to the initial ( un-wanted ) hi-lights would be to issue a mouse click .. any ideas on how to code a mouse click ?

oRtf:GoToLine(1) does not work

Thank you .. getting very close now !

Rick Lipkin

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: RTF from Variable
Posted: Sat May 06, 2017 06:25 PM

Use

oRtf:InsertRTF( cLetter )

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: RTF from Variable
Posted: Sat May 06, 2017 06:25 PM
Enrico Maria Giordano wrote:
cnavarro wrote:METHOD LoadRTF is for load file .RTF, not a string


No. Please look at this:

Code (fw): Select all Collapse
METHOD LoadFromRTFFile( cFileName ) INLINE ::cFileName := cFileName, ::LoadRTF( MemoRead( ::cFileName ) )


EMG


Yes, you are right
and oRTF:LoadRTF( cLetter ) run OK
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: RTF from Variable
Posted: Sat May 06, 2017 06:29 PM
Rick Lipkin wrote:Cristabol

The oRtf:InsertRTF( cRTF ) method did not load any text ...

1) I do not see a method to move the cursor to the top ?? any ideas on that ?
2) a Workaround to the initial ( un-wanted ) hi-lights would be to issue a mouse click .. any ideas on how to code a mouse click ?

oRtf:GoToLine(1) does not work

Thank you .. getting very close now !

Rick Lipkin


Rick, wait, I'll look

DATA ::lCaptured is false in METHOD Redefine, but text is focused
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