RichEdit's EM_AUTOURLDETECT message not always sent
To describe this issue, the best would that you would test my application with following usecase:
Application: http://ubuntuone.com/p/nF/
- Open application;
- Click on the ">" captioned button;
- Click on same button again;
- 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 ...
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...
精彩评论