Recent

Author Topic: TRichMemo Windows-Only Multicolor Line and HTML Links Issue  (Read 25386 times)

evoshroom

  • Full Member
  • ***
  • Posts: 157
I'm currently using RichMemo for a chat window in one of my applications.  My basic requirements for the component I use is that:

1. It handles different colors, fonts and backgrounds.
2. It has word wrap.
3. It is fully cross-platform (Windows, Mac, Linux).
(And if it can handle images and/or links that is a bonus)

The only thing I've found so far is RichMemo, but I've hit some snags with it.  For Mac it currently works fine for me.  The snags are in it's Microsoft Window's behavior, which is different than it's behavior on Mac.

The first issue is that there are two ways on Windows which you can color a new line of text that appears on the chat.  You can either add the line, then color it.  In this case you can color it any way you want, but there is a visible repaint for the user, which looks very odd and buggy in a chat.  They see a line added in one color and then the color changes a second later.  The other option is you can color things before adding a line, by changing the coloration at the end of the present line, but you can only do so for the whole line.  So you can change the end color of an old line to green and when you add a new line the whole line will be green.  You also cannot append to a line.  Use of the .Apprend procedure actually creates a new line contrary to what you'd expect.  On Mac there is no visible repaint when you add a line and then recolor the line, so that's why this isn't an issue on Mac.

However, there doesn't seem to be any way to color part of the line one color and part of the line another color without a visible repaint in Windows.  That is what I am trying to do.  This is common in chat applications, where the person's nickname is one color and the rest of the line is another color, for example.

The other thing I'd like to do is have clickable links or other clickable info inside the TRichMemo, like if a person types a http address, they could simply click the address to open it in their browser.  I also didn't see any way to do that.  I'd appreciate any help anyone could give me on either of these topics. 

I'm even open to using other components and checked some out, but lzRichEdit was not cross-platform (no Mac support) and the Lazarus version of SynEdit did not have word wrap.

Any ideas to help me get RichMemo painting a single line multiple colors without a refresh or getting web links working in a RichMemo chat?

TheBlackSheep

  • Jr. Member
  • **
  • Posts: 93
Re: TRichMemo Windows-Only Multicolor Line and HTML Links Issue
« Reply #1 on: June 22, 2012, 05:06:38 pm »
hi evoshroom

I've been looking at porting one of the synedit RTF exporter versions to work with Lazarus (it seems to work well and will submit the lazarus svn for martin_fr to peruse soon). 

I've a play around with the RichMemo component and at first glance it looks better than the freeware version of TRichView (the latter seems to miss a lot of the bolding in the output from the SynEdit RTF exporter whereas the RichMemo seems to display it ok). 

Anyway, the point is there appears to be later code in the SVN than the version that's currently in the CCR repository zip file (i.e. the ver 1 zip file doesn't appear to be the latest code).

If you look here;

http://lazarus-ccr.svn.sourceforge.net/viewvc/lazarus-ccr/components/richmemo/

there is a gtk2 folder which doesn't exist in the zip but also the last code to be updated 23 months ago is the Win32 bit and this code is from 2010 whereas the downloadable zip is 2009.

Just thought it worth pointing out if you hadn't noticed.

TheBlackSheep

crazyfroggy

  • New Member
  • *
  • Posts: 27
Re: TRichMemo Windows-Only Multicolor Line and HTML Links Issue
« Reply #2 on: June 27, 2012, 03:39:23 pm »
Hi,

How do you modify the background colour of a word, with a Richmemo ?

I didn't find the tip for that.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: TRichMemo Windows-Only Multicolor Line and HTML Links Issue
« Reply #3 on: June 27, 2012, 04:16:14 pm »
Quote
How do you modify the background colour of a word, with a Richmemo ?
On windows you can use the following code snippet to change the background color of the selected text.
Code: [Select]
uses ...,windows;

type
  TCharFormat2 = record
    cbSize: UINT;
    dwMask: DWORD;
    dwEffects: DWORD;
    yHeight: Longint;
    yOffset: Longint;
    crTextColor: TColorRef;
    bCharSet: Byte;
    bPitchAndFamily: Byte;
    szFaceName: array[0..LF_FACESIZE - 1] of AnsiChar;
    wWeight: Word;
    sSpacing: Smallint;
    crBackColor: TColorRef;
    lid: LCID;
    dwReserved: DWORD;
    sStyle: Smallint;
    wKerning: Word;
    bUnderlineType: Byte;
    bAnimation: Byte;
    bRevAuthor: Byte;
    bReserved1: Byte;
  end;
const
   CFM_BACKCOLOR=$04000000;

procedure TForm1.Button1Click(Sender: TObject);
var ChrFmt:TCharFormat2;
begin
  FillChar(ChrFmt, sizeof(ChrFmt), 0);
  ChrFmt.cbSize := sizeof(ChrFmt);
  ChrFmt.dwMask := CFM_BACKCOLOR;
  ChrFmt.crBackColor := ColorToRGB( clred );
  RichMemo1.Perform( EM_SETCHARFORMAT, SCF_SELECTION, lparam(@ChrFmt));
end;

evoshroom

  • Full Member
  • ***
  • Posts: 157
Re: TRichMemo Windows-Only Multicolor Line and HTML Links Issue
« Reply #4 on: July 02, 2012, 07:03:05 am »
I've been looking at porting one of the synedit RTF exporter versions to work with Lazarus (it seems to work well and will submit the lazarus svn for martin_fr to peruse soon). 

Anyway, the point is there appears to be later code in the SVN than the version that's currently in the CCR repository zip file (i.e. the ver 1 zip file doesn't appear to be the latest code).

Just thought it worth pointing out if you hadn't noticed.

I had noticed that and was already using the version with the gtk2 folder.  The website for RichMemo has a note on it that the latest versions of RichMemo are in the SVN, so that's what I started out with.

In addition to the other problems I've mentioned with RichMemo, I've also noticed recently that the redraw is very visible and ugly in another way in Windows, where basically when it redraws a visible horizontal scrolling line appears to be moving down the component whenever it redraws, which in my application is rather frequently.

I really need a better component to use for color text chats.  If the RTF exporter would be appropriate for a live color text chat view area, I would love to use it.  What is already available in SynEdit seemed to be great, except for the lack of wordwrap, though I haven't tested all aspects of it.  Feel free to pass me more info for it, if you think it could work.

TheBlackSheep

  • Jr. Member
  • **
  • Posts: 93
Re: TRichMemo Windows-Only Multicolor Line and HTML Links Issue
« Reply #5 on: July 02, 2012, 08:03:16 pm »
tbh I don't know if colors are supported - there's reference to it in the rtf export unit but my tests only produced bold for syntax highlights - I've attached the unit it anyway together with some missing images - I was going to add these to the bugtracker for Martin_fr but he might spot these here and accept them anyway  ;D.

I haven't had time to test them thoroughly or in Linux/Osx but there's no point in me just sitting on them.

TheBlackSheep


TheBlackSheep

  • Jr. Member
  • **
  • Posts: 93
Re: TRichMemo Windows-Only Multicolor Line and HTML Links Issue
« Reply #6 on: July 02, 2012, 09:01:11 pm »
actually, not sure this helps you - this unit just exports what's in SynEdit to rtf - in that basic situation the TRichMemo does appear to display tyhe rtf output at least for bold highlighting (the TRichView control missed loads of the highlighting).

I was trying to see if I could cheat on the printing side as there don't appear to be options to nicely format/print source code from SynEdit - my plan was to use the Fortes reporting components to format the pages correctly - just push each rich-text line of the output text into a memory table (one line per record) and then use the banding feature of the reporting system linked to the memory table to format them nicely on the page.  It works but it's not particularly elegant.

I guess for your application you'd also need an import unit for the other end?

TheBlackSheep

evoshroom

  • Full Member
  • ***
  • Posts: 157
Re: TRichMemo Windows-Only Multicolor Line and HTML Links Issue
« Reply #7 on: July 02, 2012, 10:55:55 pm »
Yeah, what I'm looking for is really an entirely different thing.  Think of AOL Instant Messager's Chat View Area or iChat's Chat View Area or Google Chat or any of the variety of other color chat programs, that word wrap, update elegantly and also allow maybe html links and pictures.

TheBlackSheep

  • Jr. Member
  • **
  • Posts: 93
Re: TRichMemo Windows-Only Multicolor Line and HTML Links Issue
« Reply #8 on: July 02, 2012, 11:30:10 pm »
I presume you've looked for an existing Delphi component that could be (easily?) ported?

http://www.torry.net/pages.php?id=91

TheBlackSheep

  • Jr. Member
  • **
  • Posts: 93
Re: TRichMemo Windows-Only Multicolor Line and HTML Links Issue
« Reply #9 on: July 03, 2012, 12:42:15 am »
...there's some russian delphi source code that implements a TChatEdit here;

http://forum.sources.ru/index.php?showtopic=50719&st=0&hl=

(I think it's a Delphi port of the C++ Builder TChatEdit that's on Torry's in my previous post).

The other alternative is to use the THTMLViewer/Turbopower's TIPHtml viewer http://wiki.freepascal.org/THtmlPort) and implement a chat window that's separate to your entry area - i.e. use something like SynEdit for the users to enter the text but display the result of both local and remote conversations in a separate window just like Pidgin does.

TheBlackSheep

  • Jr. Member
  • **
  • Posts: 93
Re: TRichMemo Windows-Only Multicolor Line and HTML Links Issue
« Reply #10 on: July 03, 2012, 09:32:41 pm »
forget that ChatEdit - created a simple package and it seems to just hang adding text to the memo.

Have you looked at badsector's LazHelp system here;

http://badsector.github.com/lazhelp/

it might do what you need...





evoshroom

  • Full Member
  • ***
  • Posts: 157
Re: TRichMemo Windows-Only Multicolor Line and HTML Links Issue
« Reply #11 on: July 11, 2012, 07:20:56 am »
forget that ChatEdit - created a simple package and it seems to just hang adding text to the memo.

Have you looked at badsector's LazHelp system here;

http://badsector.github.com/lazhelp/

it might do what you need...

That does look promising.  I'll check it out and let you know how it does.  Thanks!!!

evoshroom

  • Full Member
  • ***
  • Posts: 157
Re: TRichMemo Windows-Only Multicolor Line and HTML Links Issue
« Reply #12 on: August 22, 2012, 06:50:12 pm »
Well I finally had a chance to look at LazHelp as a RichMemo replacement and sadly there is no way it is workable.  The formatting and linking features it has are on the right track, but it just isn't a Memo at heart.  It is made for viewing static text on static pages.

There is no way to add just a new line at runtime.  Indeed, I couldn't even seem to get it to update by changing its .Code property at  runtime, which is basically a website-like language for a whole simple site in a huge string.  LazHelp may be a good tool for working with simple help files, but as a Chat Memo component it doesn't cut it...though of course it was never meant to.

And so I keep looking...

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: TRichMemo Windows-Only Multicolor Line and HTML Links Issue
« Reply #13 on: August 22, 2012, 07:12:07 pm »
Well I finally had a chance to look at LazHelp as a RichMemo replacement and sadly there is no way it is workable.  The formatting and linking features it has are on the right track, but it just isn't a Memo at heart.  It is made for viewing static text on static pages.

There is no way to add just a new line at runtime.  Indeed, I couldn't even seem to get it to update by changing its .Code property at  runtime, which is basically a website-like language for a whole simple site in a huge string.  LazHelp may be a good tool for working with simple help files, but as a Chat Memo component it doesn't cut it...though of course it was never meant to.

Have you looked at THtmlViewer component? I can't quite tell what you're looking for, but maybe the problem is RTF and switching to HTML might provide more options.

http://wiki.lazarus.freepascal.org/THtmlPort

If you need an _editor_, then you'll have to continue looking, although OS X has WebView which can be used to edit HTML as well as view it.

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/WebKit/Classes/WebView_Class/Reference/Reference.html

Thanks.

-Phil

evoshroom

  • Full Member
  • ***
  • Posts: 157
Re: TRichMemo Windows-Only Multicolor Line and HTML Links Issue
« Reply #14 on: August 22, 2012, 08:18:47 pm »

Have you looked at THtmlViewer component? I can't quite tell what you're looking for, but maybe the problem is RTF and switching to HTML might provide more options.

-Phil

I'm looking for something cross-platform so WebView isn't ideal, plus I don't strictly speeking need any editing abilities.  Basically, what I need is whatever you'd use for the chat window in AOL Instant Messenger.  Something that can handle viewing colors, text, links, maybe images and adding new lines.  It also needs wordwrap.

I've looked at THtmlViewer and it is very promising.  It definitely can view colors, text and links.  I'm assuming it can also view images, but haven't tested that yet.  It uses wordwrap.  The only thing I haven't been able to find yet is adding a line.

You can load text with formatting by doing something like:

Quote
HTMLViewer1.LoadFromString('<FONT COLOR=#ff0000>This text is red and I''m going to make it extra, extra long to test if word-wrapping does anything.</FONT><BR><FONT COLOR=#0080ff>This text is blue.</FONT><BR><a href="http://www.google.com/">This is a link to google.</a>');

If you do a second LoadFromString it will overwrite the old string.  I was looking for something like AppendFromString to let you add more data to the end of the data you already added, but couldn't find anything.  I'm assuming something like this is needed to turn this into a working HTML Chat Viewer (otherwise every time a line is added you'll have to refresh the whole chat, leading to lag when the chat log gets long, right?).  Is there something like that in the component somewhere?  If so, it may just be exactly what I've been looking for.
« Last Edit: August 22, 2012, 08:31:43 pm by evoshroom »

 

TinyPortal © 2005-2018