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 » Substring formating in ArrayCtrl (SqlCtrl)
Substring formating in ArrayCtrl (SqlCtrl) [message #22804] Mon, 17 August 2009 20:32 Go to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
What would be the simplest approach to format some text substring content in an ArrayCtrl (or SqlCtrl) cell? For exemple, if I wanted to highlight the "Ultimate++" substring in the ArrayCtrl cell content

"Ultimate++ is great!"

by making it bold, how should I proceed?

Thank you!
Re: Substring formating in ArrayCtrl (SqlCtrl) [message #22807 is a reply to message #22804] Tue, 18 August 2009 06:10 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
Try to use QTF instead of plain text. Something like "[* Ultimate++] is great!"


Regards,
Novo
icon14.gif  Re: Substring formating in ArrayCtrl (SqlCtrl) [message #22817 is a reply to message #22807] Wed, 19 August 2009 03:58 Go to previous messageGo to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
If you meant,

ArrayCtrl arr;
arr.AddColumn("Highlighted");
...
arr.Add("[* Ultimate++] is great!");


Iīve tried that, but unfortunately it didnīt work.
Iīve devised a way, but I donīt know wheather thereīs some simpler solution. It requires overwriting the Display::Paint method, like in the code below:

struct HighlightDisplay : public Display {
	
	static String term;
	
	virtual void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const
   	{	
	 	w.DrawRect(r, paper);
   		Font font = StdFont();
   		String s(q);
/* check if thereīs any substring to highlight in text passed to display*/
   		int ix = ToLower(s).Find(ToLower(term));
   		if(ix >= 0) {
    		        Font bold = StdFont().Bold();
/* break down text into highlighted and plain strings */ 
  			String s0 = s.Mid(0, ix);
   			String s1 = s.Mid(ix, term.GetCount());    // <-- substring to highlight
   			String s2 = s.Mid(ix + term.GetCount());
/* draw highlighted and plain strings */
			w.DrawText(r.left, r.top, s0, font, ink); 
			w.DrawText(r.left + GetTextSize(s0, font).cx, r.top, s1, bold, Blue()); // <-- highlights in bold and blue
			w.DrawText(r.left + GetTextSize(s0, font).cx + GetTextSize(s1, bold).cx, r.top, s2, font, ink);
			return;
   		}
		w.DrawText(r.left, r.top, s, font, ink);
   	}
};

String HighlightDisplay::term = "";


Then I can write

ArrCtrl arr;
arr.AddColumn("Highlighted").SetDisplay(Single<HighlightDisplay>());
...
//set term to highlight through HighlightDisplay::term static member:
HighlightDisplay::term = "Ultimate++";
arr.Add("Ultimate++ is great!");


Iīve been using this code and it has worked fine. I just thought there must be another SIMPLER way of doing it.

Thanks anyway.

[Updated on: Wed, 19 August 2009 04:08]

Report message to a moderator

Re: Substring formating in ArrayCtrl (SqlCtrl) [message #22819 is a reply to message #22817] Wed, 19 August 2009 06:22 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
Sorry, I mislead you. I checked with my code where I use text attributes with TreeCtrl. I use AttrText, which is handled by all standard Display classes. The code looks like

vf_id = wtree.Add(parent_id, TreeCtrl::Node(AttrText("Verb frames").Ink(LtBlue())));


AttrText is not that flexible as QTF is. It just lets you set attributes for the whole text.

If I need to display a QTF text as a node I create a RichTextCtrl and set it as a node of a tree. The same technique should work with ArrayCtrl.

My code looks similar to an example below.

Array<RichTextCtrl> rt_ctrl;

rt_ctrl.Add().SetZoom(zoom).NoSb().SetQTF(tree_str);
rt_ctrl.Top().WhenLink = THISBACK(on_link);

// Zoom related suff ...
int x = rt_ctrl.Top().GetWidth();
Size sz(x, rt_ctrl.Top().GetHeight(x));
sz = zoom * sz;
sz.cx += 1;
	
wtree.Add(parent_id, TreeCtrl::Node(rt_ctrl.Top()).SetSize(sz));  


Regards,
Novo
Re: Substring formating in ArrayCtrl (SqlCtrl) [message #22823 is a reply to message #22819] Thu, 20 August 2009 04:58 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
Actually, if you do not need to handle links within QTF you can use Display, which works similar to RichTextDisplayCls in TCtrlLib/Help/helputil.cpp.

Hope this helps.


Regards,
Novo
Re: Substring formating in ArrayCtrl (SqlCtrl) [message #22847 is a reply to message #22819] Sat, 22 August 2009 02:06 Go to previous message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
You're right, I can add a RichTextCtrl to each cell in an ArrayCtrl and then insert my decorated text:

ArrayCtrl arrctrl;
Array<RichTextCtrl> rtctrl;
...
arrctrl.Clear()
rtctrl.Clear();
...
Zoom zoom(3, 4);
rtctrl.Add();
arrctrl.SetCtrl(row, col, rtctrl.Top().NoSb());
rtctrl.Top().SetZoom(zoom).TopPos(0, arrctrl.GetLineCy());
rtctrl.Top().SetQTF("[* Ultimate++] is great!");


I just shouldn't forget to Clear() the RichTextCtrl Array whenever I Clear() the ArrayCtrl to avoid memory overload.

Thank you very much for your advice!
Previous Topic: ArrayCtrl column width problem
Next Topic: Problem with Drag&Drop in ArrayCtrl
Goto Forum:
  


Current Time: Thu Mar 28 10:26:38 CET 2024

Total time taken to generate the page: 0.01215 seconds