Forum > RichMemo

TRichMemo Windows-Only Multicolor Line and HTML Links Issue

(1/6) > >>

evoshroom:
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:
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:
Hi,

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

I didn't find the tip for that.

ludob:

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

--- End quote ---
On windows you can use the following code snippet to change the background color of the selected text.

--- Code: ---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;

--- End code ---

evoshroom:

--- Quote from: TheBlackSheep on June 22, 2012, 05:06:38 pm ---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.

--- End quote ---

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.

Navigation

[0] Message Index

[#] Next page

Go to full version