I followed the description from here:
https://stackoverflow.com/questions/425 ... -trichedit
I'm somewhat stuck now, maybe some API guru can enlighten me.
Working:
Only the friendly name is shown and is clickable
Not working:
-It only works, when EM_AUTOURLDETECT is disabled (but then the other links, like http://bla.blubb are no longer recognized).
-when clicking on the link, I get the friendly name instead of the underlying link
The strange thing is, when I have EM_AUTOURLDETECT enabled (or not, doesn't make any difference) and paste a friendlyname link (from e.g. libreoffice writer) into the editor, it is clickable and the underlying link is send to the callback.
So, somehow it should be possible and I made something wrong.
Here is the code:
Code: Select all
#CFM_LINKPROTECTED = $800000
#CFE_LINKPROTECTED = $800000
#CFM_HIDDEN = $100
#CFE_HIDDEN = #CFM_HIDDEN
EnableExplicit
Procedure WCallback(hWnd, uMsg, wParam, lParam)
Protected b$, Result = #PB_ProcessPureBasicEvents
Protected *el.ENLINK, txt.TEXTRANGE
Select uMsg
Case #WM_NOTIFY
*el = lParam
Select *el\nmhdr\hwndFrom
Case GadgetID(0)
If *el\nmhdr\code = #EN_LINK
If *el\msg = #WM_LBUTTONDOWN
b$ = Space(2048)
txt\chrg\cpMin = *el\chrg\cpMin
txt\chrg\cpMax = *el\chrg\cpMax
txt\lpstrText = @b$
SendMessage_(*el\nmhdr\hwndFrom, #EM_GETTEXTRANGE, 0, @txt)
Debug b$
EndIf
EndIf
EndSelect
EndSelect
ProcedureReturn Result
EndProcedure
;source from:
;https://stackoverflow.com/questions/42532760/adding-true-hyperlink-support-to-trichedit
Procedure SwitchFriendlyLinks(Gadget)
Protected content$, i, j, Size, PosMainStart, PosLinkStart, PosNameStart, Count, Link$, Name$, format.CHARFORMAT2
content$ = GetGadgetText(Gadget)
Size = Len(content$)
Count = CountString(content$, ~"HYPERLINK \"")
For i = 1 To Count
PosMainStart = FindString(content$, ~"HYPERLINK \"", PosMainStart + 1)
PosLinkStart = PosMainStart + 11
PosNameStart = FindString(content$, #DQUOTE$, PosMainStart + 13)
Link$ = Mid(content$, PosLinkStart, PosNameStart - PosLinkStart)
PosNameStart + 1
Name$ = ""
For j = PosNameStart To Size
Select Mid(content$, j, 1)
Case #LF$, #CR$, " "
Break
Default
Name$ + Mid(content$, j, 1)
EndSelect
Next j
format\cbSize = SizeOf(CHARFORMAT2)
format\dwMask = #CFM_LINK; | #CFM_LINKPROTECTED
SendMessage_(GadgetID(Gadget), #EM_SETSEL, PosMainStart - 1, PosNameStart + Len(Name$) - 1)
format\dwEffects = #CFE_LINK; | #CFE_LINKPROTECTED
SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format)
SendMessage_(GadgetID(Gadget), #EM_SETSEL, PosMainStart - 1, PosNameStart - 1)
format\dwMask = #CFM_HIDDEN
format\dwEffects = #CFE_HIDDEN
SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format)
SendMessage_(GadgetID(Gadget), #EM_SETSEL, 0, 0)
PosMainStart = PosNameStart + Len(Name$)
Next i
EndProcedure
OpenWindow(0, 0, 0, 600, 400, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 5, 5, 590, 490)
SendMessage_(GadgetID(0), #EM_SETTEXTMODE, #TM_RICHTEXT, 0)
SendMessage_(GadgetID(0), #EM_SETEVENTMASK, 0, SendMessage_(GadgetID(0), #EM_GETEVENTMASK, 0, 0) | #ENM_LINK)
;SendMessage_(GadgetID(0), #EM_AUTOURLDETECT, #True, 0)
SetGadgetText(0, ~"this is a HYPERLINK \"https://purebasic.com\"FriendlyName test" + #CRLF$ + "and a 'normal' one http://www.google.com ")
SwitchFriendlyLinks(0)
SetWindowCallback(@WCallback())
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow