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)
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 previous 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

 
Read Message
Read Message
Read Message icon14.gif
Read Message
Read Message
Read Message
Previous Topic: ArrayCtrl column width problem
Next Topic: Problem with Drag&Drop in ArrayCtrl
Goto Forum:
  


Current Time: Fri May 10 18:32:49 CEST 2024

Total time taken to generate the page: 0.01875 seconds