RichViewEdit table cell looses size when RichViewEdit is resized horizontally where different LeftMargins were specified

General TRichView support forum. Please post your questions here
Post Reply
VicFan
Posts: 11
Joined: Sun Jul 28, 2019 8:34 pm

RichViewEdit table cell looses size when RichViewEdit is resized horizontally where different LeftMargins were specified

Post by VicFan »

Ran into a problem with RichViewEdit.

The code below draws tables of various sizes with different LeftMargin's specified. All tables have 1 row. The first tables has 3 columns with LeftMargin=0. The next has 4 columns with LeftMargin=40. The next has 5 columns with LeftMargin=80. The next has 6 columns with LeftMargin=120. The last has 7 columns with LeftMargin=160. The program successfully draws the image.

But then RichViewEdit fails to work whenever the window is maximized or resized horizontally (resizing vertically does not cause the problem). At first glance, it appears to lose all the LeftMargins with such resizing, replacing all the specified left margins with the last LeftMargin value that was used whenever the window so resized. The two photos attached show just before resizing the window horizontally and after resizing the window.

However, on closer examination, what has actually happened is RichViewEdit has resized the first cell in each table, so the first cell is no longer the same size as the other cells in each table, except for the last table drawn. The leftmost cell of the tables all start at the last LeftMargin value that was used and end at the same point where the program originally drew the table cell. The other cells all remained the same size and position.

I realize that I can just redraw the whole RichViewEdit when the window is resized, but is any code changes or setting I can use to have it keep the left margins when resized horizontally?

Sample code to demonstrate the problem:

Code: Select all

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "RichView.hpp"
#include "RVStyle.hpp"
#include "RVTable.hpp"
#include "RVScroll.hpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "RichView"
#pragma link "RVEdit"
#pragma link "RVScroll"
#pragma link "RVStyle"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
#define MAX_TABLES 5
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	TRVTableItemInfo *table;
	TRVTableCellData * Cell;
	TButton *btn;

	for (int i = 0; i < MAX_TABLES; i++) {

		table = new TRVTableItemInfo(1, 3 + i, rve->RVData);

		Cell = table->Cells[0][0];
		Cell->Clear();
		Cell->AddNL("Hi from cell 1", 0, 0);
		table->SetCellTag(UnicodeString(i), 0, 0);

		Cell = table->Cells[0][2];
		Cell->Clear();
		Cell->AddNL("Hi from cell 3", 0, 0);

		Cell = table->Cells[0][i+2];
		Cell->Clear();
		Cell->AddNL("Hi from last cell. I am writing this from the last cell", 0, 0);

		rve->AddItem("Row_" + UnicodeString(i) , table);
		rve->LeftMargin = 40 * i;

		rve->FormatTail();
	}
}
Attachments
Image as the program draws it
Image as the program draws it
BeforeResize.jpg (241.49 KiB) Viewed 11507 times
Image after resizing the window
Image after resizing the window
AfterResize.jpg (254.11 KiB) Viewed 11507 times
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: RichViewEdit table cell looses size when RichViewEdit is resized horizontally where different LeftMargins were speci

Post by Sergey Tkachenko »

rve->LeftMargin defines the left margin for the whole document, not the newly added table.
While you generate a document, it is applied to new tables only because you use FormatTail() which updates only newly added content.
But this method should be used only if existing content is not changed. But it was changed, because you changed LeftMargin that should indent all tables. So the document is properly updated only after resizing.

If you need to indent the specific table, place it in a paragraph with the specified LeftIndent.
You can use this function to add this paragraphs:

int GetParaNoWithLeftMargin(TRVStyle* rvs, TRVStyleLength LeftIndent)
{
TParaInfo* ParaStyle = new TParaInfo(NULL);
ParaStyle ->Assign(rvs->ParaStyles->Items[0]);
ParaStyle ->LeftIndent = LeftIndent;
int r = rvs->FindParaStyle(ParaStyle);
delete ParaStyle;
return r;
}

Assuming that sizes in rve are measured in pixels (rve->Style->Units = rvstuUnits), call
table->ParaNo = GetParaNoWithLeftMargin(rve->Style, 40 * i);
In all cases,
table->ParaNo = GetParaNoWithLeftMargin(rve->Style, rve->Style->PixelsToUnits(40 * i));
(in the next update, StandardPixelsToUnits instead of PixelsToUnits)
Post Reply