Page 1 of 1

Problems with: #PB_EventType_LeftClick

Posted: Mon Apr 22, 2024 12:24 am
by millie78526
TIA !
Problems with: #PB_EventType_LeftClick

Firstly: (This problem is the most important .)
This line of code:
If EventGadget() = Index_List And EventType() = #PB_EventType_LeftClick ; Check for left click on the ListView

Isn't working .


Secondarily:
Each time I click on sorted Index_List
I get two of these: Debug ";- +++ Case Index_List"
and if I click on Index_List several consecutive times it stops working all together .

Problem area:

Code: Select all

;- Case Index_List  
    Case Index_List 
      Debug ";- +++ Case Index_List"
      If EventGadget() = Index_List And EventType() = #PB_EventType_LeftClick  ; Check for left click on the ListView
        Debug "; Get the selected item index"
        ; Get the selected item index
        selectedItem = GetGadgetState(Index_List) ; Assuming Index_List is the ID of the ListView
        Debug "selectedItem = " +Str(selectedItem)  
       If selectedItem <> -1
            ; Fetch the text of the selected item 
          itemText$ = GetGadgetItemText(Index_List, selectedItem)
          SetGadgetText(Search_String , itemText$)
        EndIf 
    EndIf    
;      
Full code :

Code: Select all

; PilgrimsProgress.pb   ADD CreateButton ; ADD Procedure RemoveDuplicates()
EnableExplicit 
;- Globals 
Global StringGadget , line$ , Search_String , RepeatCount = 0 , Input_Editor_ItemText$ ,
       Descend_CheckBox , Ascend_CheckBox , Descend_State = #PB_Checkbox_Checked , 
       Ascend_State = #PB_Checkbox_Unchecked , selectedItem , itemText$ , Index_List ,
       Create_Button , NewList Sort_List.s() , LisstSize , Index_List_Count = 0 , Quit = 0
      
;  The ERROR could be that  
;- Declares 
Declare InitWindow()
Declare RemoveDuplicates()

; Create the main window
Procedure InitWindow()
OpenWindow(0, 0, 0, 1372, 854, "PilgrimProgress 2.0", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Search_String = StringGadget(#PB_Any, 416, 20, 170, 30, "the") 
  GadgetToolTip(Search_String , "Enter a  Search-for  Word .") 
;
Create_Button = ButtonGadget(#PB_Any , 1062 , 20 , 120 , 30 , " Create Index") 
;- Checkbox 
  Descend_CheckBox = CheckBoxGadget(#PB_Any, 1194 , 20 , 82 , 30 , "Desc")
    GadgetToolTip(Descend_CheckBox, "LeftClick to Sort Index into Descending order .")
   SetGadgetState(Descend_CheckBox, #PB_Checkbox_Checked)
;  
  Ascend_CheckBox = CheckBoxGadget(#PB_Any, 1276 , 20 , 118 , 30 , "Ascend")
    GadgetToolTip(Ascend_CheckBox, "LeftClick to Sort Index in ASscending order .")
    SetGadgetState(Ascend_CheckBox, #PB_Checkbox_Unchecked)
  Index_List = EditorGadget(#PB_Any , 1060 , 70 , 300 , 762) 
    GadgetToolTip(Index_List, "LeftClick to SEND WORD to Search_String .")
;Sort_List    
    AddElement(Sort_List()) : Sort_List() = "Pliable" + #CRLF$  
    AddElement(Sort_List()) : Sort_List() = "Mr. Worldly Wiseman" + #CRLF$ 
    AddElement(Sort_List()) : Sort_List() = "Destruction" + #CRLF$ 
    AddElement(Sort_List()) : Sort_List() = "Swamp" + #CRLF$ 
    AddElement(Sort_List()) : Sort_List() = "Obstinate" + #CRLF$ 
EndProcedure ; InitWindow()
; 
Procedure RemoveDuplicates() ; [Create Index]
  Global NewList LinesList.s() , NewList WordsList.s() , EventID , 
                 WordsListCOUNT = 0 , Number_Times_Thru = 0 ,
                 aLine$ , POS = 0 , StartPOS= 0 , LastPOD = 0 ,
                 Input_Editor_Line_Count = 0 , Editor_Current_Line_Number = 1
; ============================================================
; Extract lines from Input_Editor and Populate NewList WordsList.s() line-by-line
; ============================================================
 ; If Number_Times_Thru > 0  : Goto ReSort_WordList  : EndIf  
;- SortList
  ReSort_WordList:
  ClearGadgetItems(Index_List) 
; ============================================================
  Descend_State = GetGadgetState(Descend_CheckBox) ; #PB_Checkbox_Checked
  If Descend_State = #PB_Checkbox_Checked
    SortList(Sort_List() , #PB_Sort_Descending  | #PB_Sort_NoCase) ; listIndex() 
   EndIf 
; ============================================================
  Ascend_State = GetGadgetState(Ascend_CheckBox) ; #PB_Checkbox_Checked
  If Ascend_State = #PB_Checkbox_Checked
    SortList(Sort_List() , #PB_Sort_Ascending  | #PB_Sort_NoCase) 
   EndIf 
; ============================================================
   LisstSize = ListSize(Sort_List() )
   Index_List_Count = 0 
   ForEach Sort_List() 
     SetGadgetItemText(Index_List , Index_List_Count , Sort_List())  
        Index_List_Count = Index_List_Count + 1 
   Next
;=============================================================
EndProcedure ; RemoveDuplicates() 
;
InitWindow()
;- Event_Loop 
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_Gadget
;      MessageRequester("Case #PB_Event_Gadget" , "Case #PB_Event_Gadget")
      Select EventGadget()
        Case Create_Button 
           RemoveDuplicates()
;- Case Checkbox           
        Case Descend_CheckBox
               SetGadgetState(Ascend_CheckBox , #PB_Checkbox_Unchecked) 
               SetGadgetState(Descend_CheckBox , #PB_Checkbox_Checked)
             
        Case Ascend_CheckBox
               SetGadgetState(Descend_CheckBox , #PB_Checkbox_Unchecked) 
               SetGadgetState(Ascend_CheckBox , #PB_Checkbox_Checked)
;- Case Index_List  
    Case Index_List 
      Debug ";- +++ Case Index_List"
      If EventGadget() = Index_List And EventType() = #PB_EventType_LeftClick  ; Check for left click on the ListView
        Debug "; Get the selected item index"
        ; Get the selected item index
        selectedItem = GetGadgetState(Index_List) ; Assuming Index_List is the ID of the ListView
        Debug "selectedItem = " +Str(selectedItem)  
       If selectedItem <> -1
            ; Fetch the text of the selected item 
          itemText$ = GetGadgetItemText(Index_List, selectedItem)
          SetGadgetText(Search_String , itemText$)
        EndIf 
    EndIf    
;      
      EndSelect
    Case #PB_Event_CloseWindow
      Quit = 1
  EndSelect

  If Quit = 1
    End
  EndIf

ForEver 

Re: Problems with: #PB_EventType_LeftClick

Posted: Mon Apr 22, 2024 12:53 am
by AZJIO
As far as I remember, the EditorGadget gadget does not have re-click events. When an event from receiving focus has arrived, then no further new events of receiving focus occur since the object is already in focus. Place the cursor in the input field on the left and then on EditorGadget and you will receive the event again
Here are the #WM_COMMAND events you can receive

Code: Select all

#EN_ALIGN_LTR_EC
#EN_ALIGN_RTL_EC
#EN_CHANGE
#EN_ERRSPACE
#EN_HSCROLL
#EN_KILLFOCUS
#EN_MAXTEXT
#ES_AUTOVSCROLL
#EN_SETFOCUS
#EN_UPDATE
#EN_VSCROLL

Re: Problems with: #PB_EventType_LeftClick

Posted: Mon Apr 22, 2024 6:03 am
by jacdelad
As AZJIO said, the EditorGadget does not support #PB_EventType_LeftClick. You can find this information in the help: https://www.purebasic.com/documentation ... adget.html

Re: Problems with: #PB_EventType_LeftClick

Posted: Mon Apr 22, 2024 7:41 am
by RASHAD
If you are a Windows user you can add and use Left Mouse Click in editor gadget

Code: Select all

	Case #WM_LBUTTONDOWN

Re: Problems with: #PB_EventType_LeftClick

Posted: Mon Apr 22, 2024 8:42 pm
by millie78526
Thanks All ;

Since #PB_EventType_LeftClick doesn't work for EditorGadget ,
and since there is no EventType() for #WM_LBUTTONDOWN ?
How to code

Code: Select all

If EventGadget() = Index_List And EventType() = #WM_LBUTTONDOWN 

Code: Select all

 
 ;     If EventGadget() = Index_List And EventType() = #PB_EventType_LeftClick  ; Check for left click on the EditGadget
;      If EventGadget() = Index_List And EventType() = #WM_LBUTTONDOWN  ; Check for left click on the EditGadget

Re: Problems with: #PB_EventType_LeftClick

Posted: Mon Apr 22, 2024 11:22 pm
by AZJIO

Code: Select all

Repeat
  Select WaitWindowEvent()
  	Case #WM_LBUTTONDOWN
  		If GetActiveGadget() = Index_List
  			Debug 1
  		EndIf
;   	Case #WM_LBUTTONDBLCLK
;   		If GetActiveGadget() = Index_List
;   			Debug 2
;   		EndIf
    Case #PB_Event_Gadget

Re: Problems with: #PB_EventType_LeftClick

Posted: Tue Apr 23, 2024 1:10 am
by millie78526
Ah Thank you AZJIO .