Richtext like component

Post Reply
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Richtext like component

Post by Marco Turco »

Hi all,
I'm looking for a component to manage RTF file. Something like the Richtext embedded in FWH but with some more functions (eg. print margins, etc.).
At the moment I'm using Word / OpenOffice and it runs fine but I still have to deal with the different version on that products, furthermore some office products don't provide OLE facilities to connect.

Any solution to suggest ? Thanks in advance.
Best Regards,

Marco Turco
SOFTWARE XP LLP
toninhofwi
Posts: 161
Joined: Tue Oct 18, 2005 10:01 am

Re: Richtext like component

Post by toninhofwi »

Hi, this is a powerfull activex text control:

http://www.textcontrol.com/en_US/


Regards.
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Richtext like component

Post by reinaldocrespo »

Marco;

Hi. Have you tried Fw TRichEdit() class? I find it works really nice and you have total control over the rtf on screen as well as printed.


Reinaldo.
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Re: Richtext like component

Post by Marco Turco »

Hi Reinaldo,
the tRichEdit class doesn't support table formatting and I need a more powerful rtf edit control than Wordpad because at the moment my Fwh apps are connected to Microsoft Word and OpenOffice Writer.
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London
Contact:

Re: Richtext like component

Post by Marco Turco »

Hi toninhofwi,
do you have a FWH working sample that use that product ?
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
TimStone
Posts: 2536
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA
Contact:

Re: Richtext like component

Post by TimStone »

In the previous version of this topic, I asked about the tRichEdit class but my question never was answered.

I was told that the edited text could be stored in an .fpt memo field.

Since I already have a lot of data in memo files, I thought it would be nice to use the newly announced enhancements to the class. All of my screens are in an .rc file, so I wanted to take a memo edit control, make it available as an RTF editor, call up a standard text element from the existing .ftp, perhaps add some enhancements, and save it back in RTF format.

I asked if that was possible, and perhaps a sample of activating the control. Of course, I tried first, but it didn't work out so that is why I asked.

If anyone has some examples of doing this, or can tell me that it can't be done, I'll watch for your posts.
Tim Stone
http://www.MasterLinkSoftware.com
timstone@masterlinksoftware.com
Using: FWH 19.06 with Harbour 3.2.0 / Microsoft Visual Studio Community 2019
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Richtext like component

Post by reinaldocrespo »

Hi Marco;

I **think** if it can be done with rich text, then it can also be done with TRichEdit class. You may have to write some wrapper funcs for some richtext functions that did not make it to richedit.prg, but it should work. In other words, if it is rich text, then all you need should be in RichEd20.dll.

If you search for and read about charformat and charformat2 richtxt structures you may find that these two c structures can be manipulated to do just about anything.

Here is an example showing the wrapper function to highlight text:

Code: Select all

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

HB_FUNC( RESETHIGHLIGHT )
{
   CHARFORMAT2 cf;

   memset( &cf, 0, sizeof( cf ) );

   cf.cbSize = sizeof( cf );
   cf.dwMask = CFM_BACKCOLOR;
   cf.crBackColor = hb_parnl( 2 );

   hb_retl( SendMessage( ( HWND ) hb_parnl( 1 ), EM_SETCHARFORMAT,
                         SCF_WORD | SCF_SELECTION, ( LPARAM ) &cf ) );
}

 
And here is how it is being called from your app:

Code: Select all

//------------------------------------------------------------------------------------------------------------------------------
METHOD RTFHighlight() CLASS PATHTRANS
LOCAL nClrHigh := ReGetHighlight( ::oActive:hWnd )
LOCAL nClrBack := ChooseColor( nClrHigh )

   if !( nClrHigh == nClrBack )
      ReSetHighLight( ::oActive:hWnd, nClrBack )
      ::oActive:lChanged := .T. 
   endif

RETURN NIL
 
It has been a while since I worked with rich text and when I did, I also had to write a few wrapper functions. Now I don't remember which wrapper functions I wrote and which I got from other people. I have quite a collection. Back then I remember having read a lot about the 2 c structures that hold text and paragraph attributes. At the end I found that it worked better for me when I had complete control over the rtf from my own fwh app. I never manipulated tables, but I still think that if it can be done with richtext, then it should be on RichEd20.dll.

Hope that helps,


Reinaldo.
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Richtext like component

Post by reinaldocrespo »

Hi Tim;

To save the contents of the rtf being edited using the TRichEdit() class, you could use the GetText() method which returns the rtf. Here is sample code using pure harbour.

Code: Select all

aEval( ::aRtfs, { |e,n| iif( e:IsModify(), (   ;
      iif( ::hSSCEDLL <> Nil,                ;
         (SSCE_CheckCtrlDlg( ::oDlg:hWnd, e:hWnd, .f. ),;
         SSCE_CheckCtrlBackgroundClear( e:hWnd, SSCE_OPTION, RGB( 254, 1, 1 ) ) ), ),;
      iif( e:odbf:isAdd, (e:odbf:isadd := .f., e:odbf:append() ), ) ,;
      iif( !empty( e:GetText() ),             ;
         ( e:SaveToRtfFile( e:cFileName ),      ;
            e:odbf:VarText := MemoRead( e:cFileName ) ), ;
            e:odbf:VarText := "" ),            ;
      ;
            e:odbf:VarDate := date(),         ;
            e:odbf:VarTime := time(),         ;
            e:odbf:Save() ,                  ;
            ::ExtractUsersIds( e ),            ;
            ::ExtractCASS( e ),               ;
            ::ExtractCptsIcds( e ) ), ),      ;
      ::SaveCaseInfo() } )
 
On the sample code above, ::aRtfs is an array of TRichText() objects. Never mind the SSEC_… calls as these are calls into a spell checker. Notice e:SaveToRtfFile(). It creates an rtf physical file that you may keep, delete, or re-read into a memo field. In this case e:odbf:VarText is a memo field and it does just that, saves the .rtf into a memo field in a .fpt memo file.

In case it helps in a different way, I have long changed that method in preference of sql statements. Here is the same using SQL against .dbf/ftp tables:

Code: Select all

   cSql := "\n"+;
      "MERGE $1$ ON (PathNo = '$2$')                        \n"+;
      "WHEN NOT MATCHED THEN INSERT ( [PathNo], [text],     \n"+;
      "                 [time], [date], [user] )            \n"+;
      "                 VALUES( '$2$', :memoData,           \n"+;
      "                 CAST( curtime() AS SQL_CHAR ),      \n"+;
      "                 CAST( now() AS SQL_DATE ),          \n"+;
      "                 user() )                            \n"+;
      "WHEN MATCHED THEN UPDATE SET [TEXT] = :memoData,    \n"+;
      "                 [time] = CAST( curtime() AS SQL_CHAR),\n"+;
      "                 [date] = CAST( now() AS SQL_DATE ), \n"+;
      "                 [user] = User()                     \n"

   FOR EACH oRtf IN ::aRtfs

      cText := iif( !EMPTY( oRtf:GetText() ), oRtf:SaveAsRTF(), "" )

      IF oRtf:oDbf:isadd .AND. EMPTY( cText ) ; LOOP   ;ENDIF

      IF ::hSSCEDLL <> Nil

         SSCE_CheckCtrlDlg( ::oDlg:hWnd, oRtf:hWnd, .f. )
         SSCE_CheckCtrlBackgroundClear( oRtf:hWnd, SSCE_OPTION, RGB( 254, 1, 1 ) )

      ENDIF

      //Must re-read transcription after spell checker has ran.
      cText := iif( !EMPTY( oRtf:GetText() ), oRtf:SaveAsRTF(), "" )

      IF !EMPTY( cText )
         oQ := TAdsQuery():New()
         oQ:cSql := cSql 
         oQ:aSubstitutes := { oRtf:oDbf:cTableName, ::cPthNo }
         oQ:adsPrepareSql()
         AdsSetString( "memoData", cText )
         oQ:RunAdsPreparedSql()
         oQ:End()               
         
      ENDIF 
      
      oRtf:lChanged := .F. 

      ::ExtractUsersIds( oRtf )
      ::ExtractCASS( oRtf )
      ::ExtractCptsIcds( oRtf )

   NEXT

   ::SaveCaseInfo()
   ::isChangedSinceLastSave := .F.

 
Here is a screen shot of the transcription dialogs containing the richtext objects:
Image

Hope that helps;

Reinaldo.
User avatar
TimStone
Posts: 2536
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA
Contact:

Re: Richtext like component

Post by TimStone »

Reinaldo,

With the release of FWH 13.09, all of the RTF was updated, and the statement was made that it is all automatic with memo fields, etc.

Have you looked at that work, and seen how it might apply ? It even provides the controls, and was supposed to be quite automatic.

Further work was supposed to be implemented in 13.10 but that was never released.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
timstone@masterlinksoftware.com
Using: FWH 19.06 with Harbour 3.2.0 / Microsoft Visual Studio Community 2019
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: Richtext like component

Post by reinaldocrespo »

Hi Tim,

My code is really old. Maybe over 10 yrs old. It has been recompiled with updated versions of fwh + xharbour up to xharbour from early 2013 + fwh 2012_04. I only hope that the new version of fw TRichText class that you make reference to is still backward compatible or it will break my code.

I had not heard about that new updated class, but I haven't had the time to keep up with all the news and being that rtfs are working so well for me, I might have read the news but did not pay enough attention. I think I'm only retaining 50% of what I read…


Best regards,


Reinaldo.
Post Reply