if you ara on windows, may be this can be a start for you:
Please keep in mind, that this is a quick hack, not tested or used very much.
Code: Select all
EnableExplicit
#WINDOW_Main = 1
#GADGET_edtText1 = 10 ; I tried different numbers !!
#GADGET_edtText2 = 20 ; I tried different numbers !!
#STATUSBAR = 1
#Caption$ = "Test Some Editor stuff"
; First solution ....
Enumeration #PB_Event_FirstCustomValue
#EVENT_Editor_ClickSelect
EndEnumeration
; Second solution ....
#PB_Editor_ClickSelect = #PB_ListView_ClickSelect ; <??>
Procedure MainWindowCallback(hWnd, uMsg, WParam, LParam)
; Windows fills the parameter automatically, which we will use in the callback...
Protected wid, line, chrRng.CHARRANGE
Protected *msgf.MSGFILTER
Select uMsg
Case #WM_NOTIFY
*msgf = LParam
Select *msgf\nmhdr\code
Case #EN_MSGFILTER ;: Debug "Notify MsgFiler on Editor "
Select *msgf\msg
Case #WM_LBUTTONUP
wid = GetProp_(HWnd, "pb_windowid") - 1
SendMessage_(*msgf\nmhdr\hwndFrom, #EM_EXGETSEL, 0, chrRng) ; .CHARRANGE)
line = SendMessage_(*msgf\nmhdr\hwndFrom, #EM_EXLINEFROMCHAR, 0, chrRng\cpMin)
; <--- one of the following lines would be enough -- you need only one of these see main loop for more details ---->
PostEvent(#EVENT_Editor_ClickSelect, wid, *msgf\nmhdr\idFrom, 0, line) ; Type not used here !
PostEvent(#PB_Event_Gadget, wid, *msgf\nmhdr\idFrom, #PB_Editor_ClickSelect, line)
EndSelect
EndSelect
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Procedure CreateMainWindow(WndW = 600, WndH = 400)
Protected hwnd, hGad, index
hwnd = OpenWindow(#WINDOW_Main, 800, 800, WndW, WndH, #Caption$, #PB_Window_SystemMenu)
If hwnd
CreateStatusBar(#STATUSBAR, WindowID(#WINDOW_Main))
AddStatusBarField(#PB_Ignore)
WndH - StatusBarHeight(#STATUSBAR)
EditorGadget(#GADGET_edtText1, 1, 1, WndW/2, WndH-2)
EditorGadget(#GADGET_edtText2, WndW/2, 1, WndW/2, WndH-2)
hGad = GadgetID(#GADGET_edtText1)
SendMessage_(hGad, #EM_SETEVENTMASK, 0, #ENM_MOUSEEVENTS)
hGad = GadgetID(#GADGET_edtText2)
SendMessage_(hGad, #EM_SETEVENTMASK, 0, #ENM_MOUSEEVENTS)
SetWindowCallback(@MainWindowCallback(), #WINDOW_Main)
; init with test text
For index = 0 To 10
AddGadgetItem(#GADGET_edtText1, index, "Text Line " + Str(index))
AddGadgetItem(#GADGET_edtText2, index, "Text Line " + Str(index))
Next
EndIf
ProcedureReturn hwnd
EndProcedure
Procedure main()
CreateMainWindow()
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #EVENT_Editor_ClickSelect
Debug "EVENT_Editor_ClickSelect: Win=" + EventWindow() + ", Gad=" + EventGadget() + ", Line=" + EventData()
Case #PB_Event_Gadget
Select EventGadget()
Case #GADGET_edtText1, #GADGET_edtText2
Select EventType()
Case #PB_EventType_Change ;: Debug "Change "
Case #PB_EventType_Focus ;: Debug "Focus"
Case #PB_EventType_LostFocus ;: Debug "Lost Focus"
Case #PB_Editor_ClickSelect
Debug "PB_Editor_ClickSelect : Win=" + EventWindow() + ", Gad=" + EventGadget() + ", Line=" + EventData()
EndSelect
EndSelect
EndSelect
ForEver
ProcedureReturn 0
EndProcedure
End main()
Happy coding and stay healthy.