RichView - Table Row Height ?

General TRichView support forum. Please post your questions here
reiser
Posts: 25
Joined: Sat Jun 25, 2011 8:40 am

RichView - Table Row Height ?

Post by reiser »

Hello, I have table:

Code: Select all

      tmpTable := TRVTableItemInfo.CreateEx(1, 3, ChatBox.RVData);
      tmpTable.BorderWidth := 0;
      tmpTable.CellBorderWidth := 0;
      tmpTable.Color := clNone;
      tmpTable.Cells[0, 0].BestWidth := 100;
      tmpTable.Cells[0, 2].BestWidth := 55;

      If ANick <> '' Then
        If ANick = UserDetails.Username Then
          tmpTable.Cells[0, 0].AddNL(Format('%s:', [ANick]), 4, 0)
        else
          tmpTable.Cells[0, 0].AddNL(Format('%s:', [ANick]), 3, 0);
      tmpTable.Cells[0, 1].AddNL(ALine, AStyle, 1);
      tmpTable.Cells[0, 2].AddNL(TimeToStr(Time), 1, 2);
Problem is, table row height is too big. How can I reduce line height ? Thanks
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Probably, it is because an empty line that exists in empty cells initially.
Call Cell.Clear before Cell.AddNL.
reiser
Posts: 25
Joined: Sat Jun 25, 2011 8:40 am

Post by reiser »

Thanks, that worked.

Now one more question, can I furhermore reduce line spacing ? I tried setting CellVSpacing to 0, but no effect:

Image
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Distance between cells = CellVPadding*2 + CellBorderWidth*2 + CellVSpacing.
reiser
Posts: 25
Joined: Sat Jun 25, 2011 8:40 am

Post by reiser »

Hey, sorry for late response, that worked, thanks !

Is it possible to hide selection arrow ? The one that appears when you position cursor on top or left of every line, and that selects whole line or table cell ?
reiser
Posts: 25
Joined: Sat Jun 25, 2011 8:40 am

Post by reiser »

Also, can I make text to be clickable and assign some event on it ? Specificaly, I want user to be able to click on text in first table column, and to code some action after click on item.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

To disable row/column selection, remove rvtoRowSelect and rvtoColSelect from table.Options.
To disallow multicell selection, include rvtoNoCellSelect as well.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Use OnRVMouseUp to detect clicking:

Code: Select all

procedure TForm3.RichViewEdit1RVMouseUp(Sender: TCustomRichView;
  Button: TMouseButton; Shift: TShiftState; ItemNo, X, Y: Integer);
var pt: TPoint;
    RVData: TCustomRVFormattedData;
    LItemNo, LOffs, Row, Col: Integer;
    Table: TRVTableItemInfo;
    Cell: TRVTableCellData;
begin
  if Sender.SelectionExists then
    exit;
  pt := Sender.ClientToDocument(Point(X,Y));
  if not Sender.GetItemAt(pt.X, pt.Y, RVData, LItemNo, LOffs, True) then
    exit;
  if RVData.GetSourceRVData is TRVTableCellData then begin
    Cell := TRVTableCellData(RVData.GetSourceRVData);
    Table := Cell.GetTable;
    Table.GetCellPosition(Cell, Row, Col);
    Caption := Format('Clicked at (%d,%d)', [Row, Col]);
  end;
end;
The code above detects clicks on items inside table cells.
If you want to detect clicks anywhere inside cells, do not exit if GetItemAt returns False.
reiser
Posts: 25
Joined: Sat Jun 25, 2011 8:40 am

Post by reiser »

Thank you very, very much :)
reiser
Posts: 25
Joined: Sat Jun 25, 2011 8:40 am

Post by reiser »

Hello, me again :)

I'm making chat alike application. After some testing, I noticed that TRichView eats much memory if there is alot of spam and I leave it to work overnight. This is how I add lines at the moment:

Code: Select all

      tmpTable := TRVTableItemInfo.CreateEx(1, 3, ChatBox.RVData);
      tmpTable.BorderWidth := 0;
      tmpTable.CellVPadding := 0;
      tmpTable.CellBorderWidth := 0;
      tmpTable.CellVSpacing := 0;
      tmpTable.BorderVSpacing := 0;
      tmpTable.Color := clNone;
      tmpTable.Options := [rvtoColSizing, rvtoRTFAllowAutofit];
      tmpTable.Cells[0, 0].BestWidth := 135;
      tmpTable.Cells[0, 2].BestWidth := 55;
      tmpTable.Cells[0, 0].Clear;
      tmpTable.Cells[0, 1].Clear;
      tmpTable.Cells[0, 2].Clear;

      tmpTable.Cells[0, 0].AddFmt('%s:', [ANick], ANickStyle, 0);
      tmpTable.Cells[0, 1].AddFmt(ALine, [], ALineStyle, 1);

      fmtTime.LongTimeFormat := 'HH:MM:SS';
      fmtTime.TimeSeparator := ':';
      tmpTable.Cells[0, 2].AddFmt(TimeToStr(Time, fmtTime), [], 1, 2);

      ChatBox.AddItem('', tmpTable);
Basically, I create one table for each row added. Can I create table once, then just expand it for each line ? And how to do this ? I can create table outside function that adds line to chat, but how can I get its reference and add row to it from function ?
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

If you want to save memory and make selection more convenient for the user, I suggest to use tabs instead of tables.
The following settings can be made for the paragraph:
Tabs.Add(135);
LeftIndent = 180;
FirstIndent = -180.
Then add Nick, #9, Time, #9, message text.

After adding, call ChatBox.FormatTail for fast formatting.
Your method also allows using FormatTail. But if you decide using a single table, you will need to reformat the whole table after adding each new message; it may be slow for long chats.
reiser
Posts: 25
Joined: Sat Jun 25, 2011 8:40 am

Post by reiser »

Ok, but that creates the problem when user types line longer than one row can contain, it gets cutted bad after that. So I think table is best option. Can I somehow limit how many lines RichView can contain ? E.g. limit it to 400 lines, then if limit is reached, delete first line etc.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

It should not be look bad for long lines.
See, the first line has two tab stops: 135 and (implicit tab stop at left indent) 180. User text starts at 180, and, if it wraps, it continues at 180, because the left indent = 180.
So it should look exactly like with tables. The only difference is long username. In tables, it will be wrapped. In tabs, it will goes beyond the tab (so, for tabs, it's better to use the order time+username+message, instead of username+time+message).

As for size limitation, it would be simpler to limit a number of messages. You can calculate the count of messages yourself, then use DeleteParas to delete the first message when necessary (this method is fast and does not reformat the whole document).
reiser
Posts: 25
Joined: Sat Jun 25, 2011 8:40 am

Post by reiser »

Thanks, this fixed it! :)

Code: Select all

      If ChatBox.LineCount >= maxLineCount Then
        ChatBox.DeleteParas(0, 0);
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Yes, it should work. But note that LineCount property is not actually a line count, it's another name for ItemCount, maintained for compatibility.
But if your chat window consists of one table for one message, then one table = one item = one line.
But if you will use tabs, then one message = text + tab + text + tab + text = 5 items.
Post Reply