Thanks in advanced ,
I know there is a '#PB_ListView_ClickSelect'
How to do same for '#PB_Editor_ClickSelect' ?
Else 'How to do' ?
#PB_Editor_ClickSelect /#PB_ListView_ClickSelect ?
#PB_Editor_ClickSelect /#PB_ListView_ClickSelect ?
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
"All things in moderation , except for love and forgiveness."
Re: #PB_Editor_ClickSelect /#PB_ListView_ClickSelect ?
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.
Happy coding and stay healthy.
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()
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Re: #PB_Editor_ClickSelect /#PB_ListView_ClickSelect ?
Thanks Axolotl ,
However your code is beyond my abilities ,
I am a novice programmer .
"Happy coding and stay healthy." Good plan
However your code is beyond my abilities ,
I am a novice programmer .
"Happy coding and stay healthy." Good plan

vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
"All things in moderation , except for love and forgiveness."
Re: #PB_Editor_ClickSelect /#PB_ListView_ClickSelect ?
Hmm...
I stumbled across this bit , works fine:
I stumbled across this bit , works fine:
Code: Select all
Case Editor_Output
If EventGadget() = Editor_Output And EventType() = #PB_EventType_LeftClick ; Check for left click on the ListView
; Get the selected item index
selectedItem = GetGadgetState(Editor_Output) ; 0 is the ID of the ListView
If selectedItem <> -1
; Fetch the text of the selected item
itemText$ = GetGadgetItemText(Editor_Output, selectedItem)
MessageRequester("Event Detected", "Left click on ListView detected on item #" + Str(selectedItem ) + " (" + itemText$ + ")")
EndIf
EndIf
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
"All things in moderation , except for love and forgiveness."
Re: #PB_Editor_ClickSelect /#PB_ListView_ClickSelect ?
you don't have to go in the details of my example code. Look at the main loop and the debug output shows you the current line number.
I am not sure, that your code is working, because GetGadgetState() is not working with the EditorGadget().
Mmmh, but maybe i didn't understand your requirement.
To get the current line, you need something like this:
And a little more explanation:
In the above example code (first post), the callback procedure only serves to recognize the left mouse click. In the processing of the event, the current line is then determined and then sent to the main loop via PostEvent() (here twice with different event paths)....
I am not sure, that your code is working, because GetGadgetState() is not working with the EditorGadget().
Mmmh, but maybe i didn't understand your requirement.
To get the current line, you need something like this:
Code: Select all
Procedure GetCurrentLine(Gadget)
Protected hgad, chrRng.CHARRANGE
If GadgetType(Gadget) = #PB_GadgetType_Editor
hgad = GadgetID(Gadget)
SendMessage_(hgad, #EM_EXGETSEL, 0, chrRng)
ProcedureReturn SendMessage_(hgad, #EM_EXLINEFROMCHAR, 0, chrRng\cpMin)
EndIf
ProcedureReturn -1 ; error
EndProcedure
And a little more explanation:
In the above example code (first post), the callback procedure only serves to recognize the left mouse click. In the processing of the event, the current line is then determined and then sent to the main loop via PostEvent() (here twice with different event paths)....
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).