The simplest way to set the style of a table cell

General TRichView support forum. Please post your questions here
Post Reply
stegemma
Posts: 10
Joined: Sat Feb 07, 2009 2:07 pm
Contact:

The simplest way to set the style of a table cell

Post by stegemma »

I've my grid class, that works fine and use its own styles. I want to insert that grid in a TRichViewEdit component. All's ok for cell text and borders but i can't set font styles (name, size...) and text alignment.

I convert my styles to TFontInfo and add it to TRVStyle:

Code: Select all

int AddStyle(TRVStyle *rvs, TFontInfo *pFontInfo)
{
  rvs->TextStyles->Add();
  int NewStyleNo = rvs->TextStyles->Count - 1;
  rvs->TextStyles->Items[NewStyleNo]->Assign(pFontInfo);
  rvs->TextStyles->Items[NewStyleNo]->Standard = false;
  return NewStyleNo;
}
[/quote]

In my style objects, i store the returned NewStyleNo into an UserData integer, to use it when i later add cells from my grid to TRichView:

[code]
            if(TRVTableCellData *pCell = pTable->Cells[r][c])
            {
              clsString sText  = "some text";
              if(TLigsStyle *pStyle = ligsprinter->GetStyleP(sStyle))
              {
                  pCell->GetTable()->AssociatedTextStyleNo  = pStyle->UserData;
              }
              pCell->SetItemText(0, CS(sText));
            }
The problem seems to be in GetTable()->AssociatedTextStyleNo that seems to do nothing or maybe i've not undesrtood how styles works, in TRichViewEdit?

[/quote]
stegemma
Posts: 10
Joined: Sat Feb 07, 2009 2:07 pm
Contact:

Post by stegemma »

Please, excuse me for the bad formatting of previous message.

I've found a solution but it is very slow:

Code: Select all

                pTable->Select(r, c, 0, 0);
                rve->ApplyTextStyle(pStyle->UserData);
Maybe is enough to disable updates of the control while inserting cells.
stegemma
Posts: 10
Joined: Sat Feb 07, 2009 2:07 pm
Contact:

Post by stegemma »

Using BeginUpdate/EndUpdate doesn't change the speed, this solution is too slow :(

I would like to know if there's some sample about the correct way to use ApplyTextStyle or ApplyParaStyle, in a fast way.

Setting font and alignment should be a simple task, for such kind of component, but i'm loosing on this details.
stegemma
Posts: 10
Joined: Sat Feb 07, 2009 2:07 pm
Contact:

Post by stegemma »

It seems that the slow down is do to this commands:

Code: Select all

                pTable->Select(r, c, 0, 0);
                rve->ApplyTextStyle(textStyleNo);
                rve->ApplyParaStyle(paraStyleNo);
I have to do it for any cell in the grid. If i only add text, the grid would be created almost instantly, if i set text/para style it requires 8 seconds for a 30 rows x 10 columns table.

There is a way to speed up apply text/para styles?

Thanks.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Before inserting the table, call:

Code: Select all

for (int r = 0; r<pTable->RowCount; r++)
  for (int c = 0; c<pTable->ColCount; c++)
  {
    pTable->Cells[r][c]->Clear();
    pTable->Cells[r][c]->AddNL('', textStyleNo, paraStyleNo);
  }
As for AssociatedTextStyleNo, this property is implemented only in items that are linked to text style, i.e. in tabs and labels. This property is for internal use.
stegemma
Posts: 10
Joined: Sat Feb 07, 2009 2:07 pm
Contact:

Post by stegemma »

It works and it is very fast, now.

Thanks.
Post Reply