views:

78

answers:

1

To describe this issue, the best would that you would test my application with following usecase:

Application: http://ubuntuone.com/p/nF/

  1. Open application;
  2. Click on the ">" captioned button;
  3. Click on same button again;
  4. Click on the same button again.

As you can see - URL is correctly detected in first expanding, but in any further is not.

Hope to have fix for this issue with your help :)

Currently I do send WM every time dialog is expanded, but it still does not work ...

Expand / Collapse buttons code snipp:

    if (PreviewOpn.Caption = '<') and (Width >= 499) then                          // if form is expanded
  begin
   PreviewOpn.Caption := '>';
   if CheckWin32Version(6,0) then begin
     Constraints.MinWidth := 252; ClientWidth := Round(252 - ((Width - ClientWidth) / 2));
    end else begin
     Constraints.MinWidth := 248; ClientWidth := Round(248 - ((Width - ClientWidth) / 2));
    end;
   PopupActionBar1.Items[1].Enabled := False; PopupActionBar1.Items[1].Checked := False;
   if (PreviewOpn.Caption = '<') and (Width >= 248) then PreviewOpn.Caption := '>';
  end else                                                                      // else if form is collapsed
  begin
   SendMessage(RichEdit1.Handle, EM_SETEVENTMASK, 0, EM_GETEVENTMASK or ENM_LINK);       //|
   SendMessage(RichEdit1.Handle, EM_AUTOURLDETECT, Integer(True), 0);
   PreviewOpn.Caption := '<';
   if CheckWin32Version(6,0) then begin
    Constraints.MinWidth := 252; ClientWidth := Round(510 - ((Width - ClientWidth) / 2));
   end else begin
    Constraints.MinWidth := 248; ClientWidth := Round(499 - ((Width - ClientWidth) / 2));
   end;
   PopupActionBar1.Items[1].Enabled := True; PopupActionBar1.Items[1].Checked := True;
   if (PreviewOpn.Caption = '>') and (Width >= 499) then PreviewOpn.Caption := '<';
   if (FileExists(Edit1.Text)) or (FileExists(Edit2.Text)) or (FileExists(ParamStr(1)))
    then RAWInputBtnClick(TabSet1);
  end;
 vClick(VKPInputBtn);                                                           // calls PopuMenu items enabling triggers
 for n := 0 to RichEdit1.Lines.Count - 1 do if RichEdit1.Width < Canvas.TextWidth(RichEdit1.Lines[n]) then  // enable automatic scroolbar settup
  RichEdit1.ScrollBars := ssBoth;

Inside Forms OnCreate Event:

 SendMessage(RichEdit1.Handle, EM_SETEVENTMASK, 0, EM_GETEVENTMASK or ENM_LINK);       //|
 SendMessage(RichEdit1.Handle, EM_AUTOURLDETECT, Integer(True), 0);                    //|
 RichEdit1.Lines[5] := RichEdit1.Lines[5] + ' ';                                       //| resend message for line to fix update issue

As http://msdn.microsoft.com/en-us/library/bb787991%28VS.85%29.aspx documentation states, URL is detected by text modification, which means only way to re-invoke detection is to send some kind of message adding / removing characters, BUT:

URL is detected instantly after key on keyboard isp ressed and only INSIDE line. Possible fix would be pretty nasty and therefore I do not even think to develop code sinpp for this :) Idea: Lopp through all avail characters and, for example, add Char(#10) and then remove Char(#10). Drawback: Imagine what happens on large RTF text inside RichEdit control ...

+1  A: 

You are not setting the event mask correctly, EM_GETEVENTMASK is a message - not a flag. You should set it like this;

  SendMessage(RichEdit1.Handle, EM_SETEVENTMASK, 0,
      SendMessage(RichEdit1.Handle, EM_GETEVENTMASK, 0, 0) or ENM_LINK);


I don't know how you're losing the URL detection after once you've got it, but if the above does not help, as far as I know there's no other way then to clear and reassign the text, or modify the URL text itself as you've noticed.

As a side note, you're setting both of the scroll bars depending on line widths, that seems wrong, the vertical scroll bar should have nothing to do with line widths.

As another side node, your test regarding changing the form's width is faulty.

 if (PreviewOpn.Caption = '<') and (Width >= 499) then
  begin
  ...
  end else
  begin
   if CheckWin32Version(6,0) then begin
    Constraints.MinWidth := 252;
    ClientWidth := Round(510 - ((Width - ClientWidth) / 2));
  ...

In the above, when your form is expanded, it will have a width of ~510 and minimum width of 252. That means the form can be resized to have a smaller width than 499, then your "if" will fail and though the form is expanded it will not contract. Forget about the caption and the width and employ a private field flag like FFormExpanded and set it to true or false.. etc...

Sertac Akyuz
No. Your way do not work at all - even in first expanding no URL is detected. Any other solution?Yes - I know -I just need to add addition test for LineCount * TextHeight :) ... so no worries, bro' ...Ah, well, yeah - I am planning to use InRange and EnsureRange methods from Math ... but I do not like it anyway ... :)Hm, yeah - I had an idea to implement few private flags, but I needs some design change of wide areas of code ...
HX_unbanned
Hm, It seems like problem is inside RAD Studio ...The thing is that If I edit text from keyboard and them expand/collapse, URL highlight is not lost, BUT, if I add text from RAD Studios code or Property - URL Detection is lost after expanding / collapsing. Interesting thing ... maybe I should report to Embarcadero?
HX_unbanned
@HX_unbanned - You're still sending an EM_AUTOURLDETECT after sending the EM_SETEVENTMASK message, right? ... You won't get the EN_LINK notification unless you set the ENM_LINK flag correctly, even if you get URL detection alright.
Sertac Akyuz
Well, no ... currently I changed code to your suggested ...
HX_unbanned