using <> entities in edit controls
Moe Maleki -- MMALEKI@ggx.com
Monday, February 26, 1996
MSVC++ 2.2/4.0 and NT3.51
I want to use a CEdit (or CRichEditCtrl in 4.0) in which the user can type
in multi-line text and insert <> fields. I would like the <>
field to be treated as one entity for editing purposes, ie., the user can
select whole tag by clicking on it, delete it or otherwise format it as one
edit entity.
The 'tag' itself is composed of alphanumerics of any length (>1) and will be
enclosed by the delimeters << and >> on either side. My initial crack at
this would be to track the cursor position within the edit box and check for
the enclosing characters on either side of the cursor. If << is found on
the left or >> on the right (within a certain maximum distance) then I know
I'm with in a <> field and can process commands accordingly.
If anyone has implemented such a feature before or knows how to do it
better, please let me know.
TIA,
Moe Maleki
mmaleki@ggx.com
Jim Lavin -- ooptech@Onramp.NET
Wednesday, February 28, 1996
[Mini-digest: 2 responses]
At 10:05 AM 2/26/96 E, you wrote:
>
>
>MSVC++ 2.2/4.0 and NT3.51
>
>I want to use a CEdit (or CRichEditCtrl in 4.0) in which the user can type
>in multi-line text and insert <> fields. I would like the <>
>field to be treated as one entity for editing purposes, ie., the user can
>select whole tag by clicking on it, delete it or otherwise format it as one
>edit entity.
>
>The 'tag' itself is composed of alphanumerics of any length (>1) and will be
>enclosed by the delimeters << and >> on either side. My initial crack at
>this would be to track the cursor position within the edit box and check for
>the enclosing characters on either side of the cursor. If << is found on
>the left or >> on the right (within a certain maximum distance) then I know
>I'm with in a <> field and can process commands accordingly.
>
>If anyone has implemented such a feature before or knows how to do it
>better, please let me know.
>
>TIA,
>
>Moe Maleki
>mmaleki@ggx.com
>
I've worked on something like this last year.
We allowed users to build templates for a custom mail merge portion of our
tax application. The templates were nothing but .RTF files with the tags
being delimited in about the same way as you described above.
We then wrote a custom RTF parser that took the tags and converted them to
RTF \field tags along with the \fieldrslt tag giving the value of the
evaluated tag.
Our app then took the newly formatted RTF file and embedded it into an
object manager using Word. This may be overkill, but it works and rather
quickly too.
The entire engine was built on top of a giant stack to hold the text as we
parsed it. When we came upon the start of a tag we would push the value
onto a stack until we reached the end of the tag. We then evaluated it and
wrote our the results. We used the stack concept mainly to aid in the
parsing of the RTF file. Every time we came across a "{" we would push the
entire formatting and text states onto the stack. And when we came across
the matching "}" we would pop the stack and restore the the formatting and
text states.
For more information you might look at Microsoft's documentation on the .RTF
format. They have a sample parser that illustrates the concepts stated
above. If you don't have the MSDN try their wed site's knowledge base.
Hope this helps!
Jim Lavin
OOP Technologies
http://emporium.turnpike.net/~jlavin
http://rampages.onramp.net/~ooptech
I've seen programmers who couldn't be passed by reference or by value!
-----From: "Cunningham, Graham"
I have done much the same thing in the past, and implemented in exactly t=
he same way.=20
I declared a routine that I called on LButton and RButton in this routine=
I had a table of delimiters and simply worked backwards and then forward=
s until I hit one of the delimiters. It worked pretty well and seemed to =
be speedy enough. I did impose a limitation that the word couldnt wrap ov=
er a line (in my case 255). If anyone has any other ideas on how to do th=
is I would also be interested.
regards,
Graham Cunningham=20
email : Cunningham@tgd.swissptt.ch
phone : 00 41 31 338 0633
| Вернуться в корень Архива
|