RTF from Variable

RTF from Variable

Postby Rick Lipkin » Fri May 05, 2017 9: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: Select all  Expand view  RUN

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

// Generated by ResEdit 1.6.6
// Copyright (C) 2006-2015
// http://www.resedit.net

#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
}
 


Image
Image

Any Ideas ??
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: RTF from Variable

Postby Enrico Maria Giordano » Fri May 05, 2017 9:42 pm

Rick,

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

Code: Select all  Expand view  RUN
CONTROL "", 130, "RichEdit20A", ES_LEFT | ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP, 25, 8, 355, 245


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: RTF from Variable

Postby Rick Lipkin » 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: Select all  Expand view  RUN

/ Generated by ResEdit 1.6.6
// Copyright (C) 2006-2015
// http://www.resedit.net

#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
}
 
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: RTF from Variable

Postby Enrico Maria Giordano » Fri May 05, 2017 10:24 pm

You also have to load the text using

Code: Select all  Expand view  RUN
oRtf:LoadRTF( cLetter )


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: RTF from Variable

Postby cnavarro » 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: Select all  Expand view  RUN

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

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


   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
User avatar
cnavarro
 
Posts: 6548
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: RTF from Variable

Postby Rick Lipkin » Sat May 06, 2017 3: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 ?
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: RTF from Variable

Postby cnavarro » Sat May 06, 2017 4: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: Select all  Expand view  RUN

   oRtf:HighLightAllText()
 


Missing in the REDEFINE method

Code: Select all  Expand view  RUN


.../...
   oWnd:DefControl( Self )

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


then use it
Code: Select all  Expand view  RUN

REDEFINE RICHEDIT5 oRich VAR cRTF ID 100 OF oDlg HIGHLIGHT
 


For save text to variable, before put in database

Code: Select all  Expand view  RUN

    cLetter := oRtf:GetText()
 


Also, I think it has to work
Code: Select all  Expand view  RUN

    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
User avatar
cnavarro
 
Posts: 6548
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: RTF from Variable

Postby Rick Lipkin » Sat May 06, 2017 5: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

Image
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: RTF from Variable

Postby cnavarro » Sat May 06, 2017 5: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
User avatar
cnavarro
 
Posts: 6548
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: RTF from Variable

Postby Enrico Maria Giordano » Sat May 06, 2017 6: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
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: RTF from Variable

Postby Enrico Maria Giordano » Sat May 06, 2017 6:09 pm

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


No. Please look at this:

Code: Select all  Expand view  RUN
METHOD LoadFromRTFFile( cFileName ) INLINE ::cFileName := cFileName, ::LoadRTF( MemoRead( ::cFileName ) )


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: RTF from Variable

Postby Rick Lipkin » Sat May 06, 2017 6: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
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: RTF from Variable

Postby cnavarro » Sat May 06, 2017 6: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
User avatar
cnavarro
 
Posts: 6548
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: RTF from Variable

Postby cnavarro » Sat May 06, 2017 6:25 pm

Enrico Maria Giordano wrote:
cnavarro wrote:METHOD LoadRTF is for load file .RTF, not a string


No. Please look at this:

Code: Select all  Expand view  RUN
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
User avatar
cnavarro
 
Posts: 6548
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: RTF from Variable

Postby cnavarro » Sat May 06, 2017 6: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
User avatar
cnavarro
 
Posts: 6548
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 116 guests