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 » U++ Widgets - General questions or Mixed problems » How To Find/Replace on RichEditWithToolBar
Re: How To Find/Replace on RichEditWithToolBar [message #16591 is a reply to message #16588] Mon, 30 June 2008 18:53 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14261
Registered: November 2005
Ultimate Member
alex100 wrote on Mon, 30 June 2008 05:34

Hi,

Suppose I have a database with some customers and I want to send a letter to all of them, for instance.

I was planning to write some document using the word processor (sample) that comes with Ultimate++. Suppose this document:


Customer name: <NNNNNN>
Customer id: <iiiiiii>
Customer adsress: <D1D1D1D1>
<D2D2D2D2>
<D2D2D2D2>
<D3D3D3D3>

Dear <NNNNNN>

Congratulation for blablablabla
blablablavla
...


Then when I choose "send letter to customers main menu"

I would like to open a dialog with a RichEdit widget that automatically opens the document above and also the database. Then for each customer it finds its details and replaces the tags
<
<NNNNNN>
<iiiiiii>
<D1D1D1D1>
<D2D2D2D2>
<D2D2D2D2>
<D3D3D3D3>

accordingly and prints a letter for each customer.


It that what I am trying to do.
Any ideas?

Many thanks

Alex



Sure, I am doing something very similar, if a bit advanced, all the time.

Anyway, I do not believe you need that dialog for this. Just tak RichText, scan it and replace what you need Smile

OK, my method is a bit different, as I am (mis)using index entries to mark parts of document that are about to be replaced.

Anyway, for the inspiration, the heart of the code goes like this:

RichTxt Expand(const RichTxt& text, const RichStyles& styles,
               const VectorMap<String, NamedText>& map)
{
	RichText r;
	NamedText deftext;
	deftext.text = "****";
	for(int i = 0; i < text.GetPartCount(); i++) {
		if(text.IsPara(i)) {
			RichPara para = text.Get(i, styles);
			RichPara rpara;
			rpara.format = para.format;
			for(int j = 0; j < para.GetCount(); j++) {
				const RichPara::Part& p = para[j];
				if(IsNull(p.format.indexentry))
					rpara.part.Add(p);
				else {
					StringBuffer t;
					String d = map.Get(p.format.indexentry.ToString(), deftext).text;
					t << "[%CS-CZI" << p.format.indexentry.ToString() << "; " << d << ']';
					RichText txt = ParseQTF(t);
					if((txt.GetPartCount() > 1 || txt.GetPartCount() > 0 && txt.IsTable(0))
					   && rpara.GetCount() == 0) {
						for(int i = 0; i < txt.GetPartCount(); i++)
							if(txt.IsPara(i))
								r.Cat(txt.Get(i));
							else {
								RichTable tab(txt.GetTable(i), 1);
								r.CatPick(tab);
							}
						goto norpara;
					}
					else
					if(txt.GetPartCount() && txt.IsPara(0)) {
						RichPara par = txt.Get(0);
						for(int j = 0; j < par.GetCount(); j++) {
							rpara.part.Add(par[j]);
							rpara.part.Top().format = p.format;
						}
					}
				}
			}
			r.Cat(rpara);
		norpara:;
		}
		else {
			RichTable tab(text.GetTable(i), 1);
			Size sz = tab.GetSize();
			for(int q = 0; q < sz.cy; q++)
				for(int j = 0; j < sz.cx; j++) {
					RichTxt h = Expand(tab.Get(q, j), styles, map);
					tab.SetPick(q, j, h);
				}
			r.CatPick(tab);
		}
	}
	return r;
}

RichText Expand(const char *qtf, const VectorMap<String, NamedText>& map)
{
	RichText text = ParseQTF(qtf);
	RichStyles styles;
	styles <<= text.GetStyles();
	return RichText(Expand(text, styles, map), styles);
}
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Meter or Gauge Widget out there anywhere?
Next Topic: Error: Invalid UTF-8 sequence when reading txt file from hard disk
Goto Forum:
  


Current Time: Sun Jun 08 15:25:30 CEST 2025

Total time taken to generate the page: 0.03523 seconds