Solved

Richedit 2.0 and CFM_LINK

Posted on 1998-09-12
3
1,295 Views
Last Modified: 2013-12-26
I have a function AddText that adds text to a rich edit control . The function is supposed to catch messages starting with http:// or ftp:// or any other internet prefix , and apply the CFM_LINK to the string until a space is found . This is part of it : ( ttt contains the string to add  , and w[k]->p->rEdit and ccw[k]->p->rEdit are TRichEdit objects  )


for( unsigned int p = 0 ; p < strlen(ttt) ; )
      {
      /* FIRST of ALL : Test for EM_LINK */
      if (REC_LINKS)
            {
            if (!IsLinkingActive)
                  {
                  // Enable if next is a link string
                  if (strlen(ttt + p) < 10)
                        goto AfterLinking;
                        if (
                        (strncmpi(ttt + p,"http://",7) == 0) ||
                        (strncmpi(ttt + p,"www.",4) == 0) ||
                        (strncmpi(ttt + p,"telnet://",9) == 0) ||
                        (strncmpi(ttt + p,"ftp://",6) == 0) ||
                        (strncmpi(ttt + p,"mailto:",7) == 0))
                        {
                        w[k]->p->rEdit->ToggleCharAttribute(CFM_LINK, CFE_LINK);
                        }
                  IsLinkingActive = true;
                  }
            else // active linking
                  {
                  if ((unsigned char)ttt[p] == 0x20 )
                        {
                        w[k]->p->rEdit->ToggleCharAttribute(CFM_LINK, CFE_LINK);
                        IsLinkingActive = false;
                        }
                  }

            AfterLinking:


The problem is that the CFE_LINK is applied to the WHOLE line ! . That means,  if I have a line
" please go to http://www.com" , the CFM_LINK is applied to the whole string .
Please help
0
Comment
Question by:WxW
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
duneram earned 20 total points
ID: 1299785
first look:  It appears as though you are not specifying an ending position for the end of the link.

You probably need to add logic to turn off the toggle in the 'after linking section' to get it to terminate correctly.

In the stuff before the http:// key you need to make sure you don't start the 'link until you are supposed to:

Instead of 'p'  use

w[k]->p->rEdit->ToggleCharAttribute(CFM_LINK, CFE_LINK);

w[k]->(ttt+p)->rEdit->ToggleCharAttribute(CFM_LINK, CFE_LINK);

Use the same when turning it off.

You should also increase the points here... but this should work a bit better

0
 
LVL 6

Author Comment

by:WxW
ID: 1299786
Nope . Tje w[k]->p is NOT the same as the ttt[p] . ttt[p] is an index to the string ttt , and w[k]->p is a TWindow . AND , I check for a space character after a string to terminate the link  as you saw in
if ((unsigned char)ttt[p] == 0x20 )

0
 
LVL 2

Expert Comment

by:duneram
ID: 1299787
I was refering to how you do your strncmps...

"strncmpi(ttt + p,"mailto:",7) == 0)) "

You are taking the base ttt and adding the offset p

When you do that and eventially find a keyword, like 'ttt+p' --> "m" in "mailto:"

then you will want to start the link process at ttt+p, not 'p'  .

if your index 'p' is different from the 'p' in the pointer string, you should consider changing the names of one of them to avoid the confusion.  I assumed (since I didn't have the definition of p to be the same index you were using as the index of the loop.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question