Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » Wrapping text in ArrayCtrl cells
Wrapping text in ArrayCtrl cells [message #31076] Thu, 03 February 2011 23:14 Go to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
How to add text rows to an ArrayCtrl, keeping cell widths constant, and at the same time resizing cell height, so that I visualize entered text in full? I mean, Iīd like to be able to wrap text down when it does not fit cell size.

Iīve tried this using DocEdits (which wrap long lines automatically), but it didnīt work:
// in .h file:
ArrayCtrl wraparray;

...

// somewhere in code initialization:
wraparray.AddColumn().Ctrls(THISBACK(CreateDocEdit));

...

// DocEdit factory callback:
MyProg::CreateDocEdit(One<Ctrl>& x)
{
	x.Create<DocEdit>().NoBackground().SetFrame(NullFrame()).Disable();
}

...

// Adding rows: here's where I guess things go wrong!
void MyProg::AddRowsToWrapArray(Vector<Value>& rows) 
{
	int line, cy_height;
	const int FONT_HEIGHT = GetTextSize("text sample", GetStdFont()).cy;

// this is weird, but necessary, or last included row won't show properly:

	if(wraparray.GetCount() > 0)
		wraparray.Remove(wraparray.GetCount() - 1);

	for(int ix = 0; ix < rows.GetCount(); ix ++) {
		wraparray.Add(rows[ix]);
		line = wraparray.GetCount() - 1;
		DocEdit * de = (DocEdit*)wraparray.GetCtrl(line, 0);
		cy_height = (de->GetLineCount() + 1)*FONT_HEIGHT;
		de->SetRectY(0, cy_height);
		wraparray.SetLineCy(line, cy_height);
		de->RefreshLayout();
	}

// this is weird, but necessary, or last included row won't show properly:
	wraparray.Add();
}



the DocEdit's do not seem to resize right, and I really would not like that the DocEdit scrollbars showed up for scrolling down hidden text because of wrong resizing.
What am I doing wrong?
Is there another simpler way of doing it?
Could it be possible to have a method like "void SetWrapLines(bool wrap = true);" for ArrayCtrl?

Thanks!!

[Updated on: Thu, 03 February 2011 23:29]

Report message to a moderator

Re: Wrapping text in ArrayCtrl cells [message #31102 is a reply to message #31076] Fri, 04 February 2011 16:08 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
This is a little bit tricky, as ArrayCtrl itself never changes the cellheight - you would have to somehow adjust it from client code.
Re: Wrapping text in ArrayCtrl cells [message #31103 is a reply to message #31102] Fri, 04 February 2011 16:34 Go to previous messageGo to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
Actually, I did a few tests in which I prompted the de->GetLineCount() and it ALWAYS returns 1, for every DocEdit, be it in an ArrayCtrl or not! Isnīt TextCtrl::GetLineCount() supposed to return the current number of text lines in the TextCtrl?
The Upp Text.h code source gives me something like
 int GetLineCount() const { return line.GetCount(); } 
, where
Vector<Ln> line;
is a Vector, in which apparently each Ln struct corresponds to a wrapped line string in the TextCtrl view. How come it always return 1?

Thank you again
Re: Wrapping text in ArrayCtrl cells [message #31106 is a reply to message #31103] Fri, 04 February 2011 20:06 Go to previous messageGo to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
I guess I found a solution to this issue myself; I'm using RichTextCtrl's instead of DocEdit's:
// this time around, wraparray ctrl factory callback creates RichTextCtrls instead:
void MyProg::CreateRichText(One<Ctrl>& x)
{
	x.Create<RichTextCtrl>().NoSb();
}

void MyProg::AddRowsToWrapArray(Vector<Value>& rows)
{
	int line, height;
	String str;
	for(int ix = 0; ix < rows.GetCount(); ix ++) {
// enter cell text as QTF:
		str = "[G1 " + rows[ix].ToString() + "]";	// G => make sure StdFont is used
		wraparray.Add(str);
		line = wraparray.GetCount() - 1;
// Get back pointer to cell RichTextCtrl
		RichTextCtrl * ra = (RichTextCtrl*)wraparray.GetCtrl(line, 0);
// Here's da trick!
		height = ::GetSmartTextHeight("\1" + str, ra->GetRect().Width()); // "\1" => tell function it's QTF
// resize both, RichTextCtrl and ArrayCtrl cell heights:
		ra->SetRectY(0, height);
		wraparray.SetLineCy(line, height);
		wraparray.RefreshLayoutDeep();
	}
}


It works perfectly!
Thank you.
Re: Wrapping text in ArrayCtrl cells [message #31282 is a reply to message #31103] Fri, 18 February 2011 13:06 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kropniczki wrote on Fri, 04 February 2011 10:34

Actually, I did a few tests in which I prompted the de->GetLineCount() and it ALWAYS returns 1, for every DocEdit, be it in an ArrayCtrl or not! Isnīt TextCtrl::GetLineCount() supposed to return the current number of text lines in the TextCtrl?



Well, it can be a little bit confusing, but it actually returns a number of paragraphs. But then, this is the main difference between DocEdit and LineEdit - DocEdit treats lines (defines as something that ends with '\n'), LineEdit as lines (does not do wordwrap).

Mirek
Re: Wrapping text in ArrayCtrl cells [message #31283 is a reply to message #31106] Fri, 18 February 2011 13:07 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kropniczki wrote on Fri, 04 February 2011 14:06

I guess I found a solution to this issue myself; I'm using RichTextCtrl's instead of DocEdit's:



Well, that is a smarter solution anyway Smile

Mirek
Previous Topic: GridCtrl with Option problem under linux
Next Topic: Newbie question: ArrayCtrl::IsModified(int ii) not work at expected.
Goto Forum:
  


Current Time: Thu Mar 28 18:21:45 CET 2024

Total time taken to generate the page: 0.01057 seconds