PB 5.4: How to detect ListIcon checkbox event?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4794
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

PB 5.4: How to detect ListIcon checkbox event?

Post by Fangbeast »

I thought I read somewhere that Fred fixed a bug for the Mac where it didn't report an event for a checkbox being selected on a ListIconGadget but I found that it doesn't do it on Windows either (that I can tell)

Reading the 5.4 manual, I can get all other events except for checking the checkbox so to speak.

Am I doing this wrong or is API still the only way to do this?

Code: Select all

Case #Gadget_Loglist
  Select EventType()
    Case #PB_EventType_Change
      If GetGadgetItemState(#Gadget_Loglist, GetGadgetState(#Gadget_Loglist)) & #PB_ListIcon_Checked
        Debug "Working yet!"
      EndIf
  EndSelect
If I check the checkbox and then re-select the line, then of course it gets reported but that isn't what I wanted.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5011
Joined: Sun Apr 12, 2009 6:27 am

Re: PB 5.4: How to detect ListIcon checkbox event?

Post by RASHAD »

Hi Fangles
The item must be checked first to get its check box status

#1 :

Code: Select all

If OpenWindow(0, 0, 0, 640, 400, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  ListIconGadget(1,  10, 10, 620,380, "Column 0", 100, #PB_ListIcon_GridLines|#PB_ListIcon_CheckBoxes|#PB_ListIcon_FullRowSelect)
 
  For c = 1 To 6
    AddGadgetColumn(1, c, "Column " + Str(c), 100)
  Next
  For r = 0 To 100
    AddGadgetItem(1, r, "  Item "+Str(r)+Chr(10)+"Item "+Str(r)+Chr(10)+"Item 3"+Chr(10)+"Item 4")
  Next
EndIf

Repeat
  Select WaitWindowEvent(1)
     
    Case #PB_Event_CloseWindow
      Quit = 1
     
    Case #PB_Event_Gadget
      Select EventGadget()               
        Case 1
          Select EventType()                
            Case #PB_EventType_Change
                  For x = 0 To 100
                     If GetGadgetItemState(1,x) > 1
                        Debug "Item : "+Str(x)+" Checked"
                     EndIf
                  Next
                  Debug "*****"                        
             
          EndSelect         
      EndSelect
  EndSelect
 
Until Quit = 1




#2 :

Code: Select all

Global Row

Procedure WndProc(hwnd, uMsg, wParam, lParam)
    Select uMsg
      Case #WM_NOTIFY
               *uMsg.NMHDR = lParam                                                                     
              If *uMsg\hwndFrom = GadgetID(1) And *uMsg\code = #NM_CLICK
                 *Li.NMITEMACTIVATE = lParam
                 Row = *Li\iItem
              EndIf

    EndSelect
   ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

If OpenWindow(0, 0, 0, 640, 400, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  ListIconGadget(1,  10, 10, 620,380, "Column 0", 100, #PB_ListIcon_GridLines|#PB_ListIcon_CheckBoxes|#PB_ListIcon_FullRowSelect)
 
  For c = 1 To 6
    AddGadgetColumn(1, c, "Column " + Str(c), 100)
  Next
  For r = 0 To 100
    AddGadgetItem(1, r, "  Item "+Str(r)+Chr(10)+"Item "+Str(r)+Chr(10)+"Item 3"+Chr(10)+"Item 4")
  Next
EndIf

 SetWindowCallback(@WndProc())

Repeat
  Select WaitWindowEvent(1)
     
    Case #PB_Event_CloseWindow
      Quit = 1
     
    Case #PB_Event_Gadget
      Select EventGadget()               
        Case 1
          Select EventType()                   
            Case #PB_EventType_LeftClick
              If GetGadgetItemState(1, row) & #PB_ListIcon_Checked
                Debug "CheckBox : #"+Str(Row) +" Checked"
              Else
                Debug "CheckBox : #"+Str(Row) +" UnChecked"
              EndIf                  
             
          EndSelect
         
      EndSelect
  EndSelect
 
Until Quit = 1
Edit : # 2 Modified
Last edited by RASHAD on Sun Nov 22, 2015 11:43 am, edited 1 time in total.
Egypt my love
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4794
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: PB 5.4: How to detect ListIcon checkbox event?

Post by Fangbeast »

So no actual event exists for the checking of the box on the listicongadget. Okay, your method works and is a good idea, thanks for that.

The second example dies with a "Line 13: WndProc not declared" but works with that commented out.

Thanks for that RASHAD, very helpful

oops, no, it doesn't. This line "GetGadgetItemState(1, row) & #PB_ListIcon_Checked" referred to a row and there was nowhere for the row value to be found.

So I added a "row = GetGadgetState(1)" but still getting -1.

Give me a few moments and I will see if I can fix it.

**EDIT** Ah, I see. Your missing WNDPROC must set the gadget state via API so that GetGadgetState will set the state because normally GetGadgetState will not get the state when the checkbox is checked so we need the API to check the line.

I shall wait for the missing WNDPROC :):)
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5011
Joined: Sun Apr 12, 2009 6:27 am

Re: PB 5.4: How to detect ListIcon checkbox event?

Post by RASHAD »

Hi Fangles
How are my friend ?
Sorry Fang It looks that I am getting old :)
Example # 2 just modified

Now let me here good news about you
Egypt my love
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4794
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: PB 5.4: How to detect ListIcon checkbox event?

Post by Fangbeast »

Hi Fangles
Hello Magician RASHAD
How are my friend ?
Okay most days but my mother is going down hill (seems like my mother-in-law all over again) and the stress is making me ill.
Sorry Fang It looks that I am getting old :)
I'm not just getting older but uglier as well.

I went past my bathroom mirror yesterday and it spoke to me. it said, "Mate, that's a criminal offence in most countries, I'm not showing you that!!". Then it started wearing garlic whenever I was near it!!!
Example # 2 just modified
Thank you, I even understand it!!
Now let me here good news about you
My brain works????

I am writing a repeater list manager for D-STAR (Digital Amateur Radio) and your code will enable me to let users select repeater for later export by saving selected changes back to the database and when re-selecting a particular repeater group, they can also review their changes.

Got so much to do tonight, thank you so much for the help!!!
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5011
Joined: Sun Apr 12, 2009 6:27 am

Re: PB 5.4: How to detect ListIcon checkbox event?

Post by RASHAD »

All I can say
You are a real human Fang
Keep going
Egypt my love
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4794
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: PB 5.4: How to detect ListIcon checkbox event?

Post by Fangbeast »

RASHAD wrote:All I can say
You are a real human Fang
Keep going
Don't know about real human. My wife says I am a fanglybeast, my daughter says I am a nut (A cashew to be precise, bent in the middle) and my friends call me a nut job:):):)

But this repeater manager is going well!!!
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5011
Joined: Sun Apr 12, 2009 6:27 am

Re: PB 5.4: How to detect ListIcon checkbox event?

Post by RASHAD »

:lol:
They all have a good points about you Fang
So me too :P
Egypt my love
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4794
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: PB 5.4: How to detect ListIcon checkbox event?

Post by Fangbeast »

RASHAD wrote::lol:
They all have a good points about you Fang
So me too :P
My pointy head says I have screwed up somewhere. Your check shows a single debug for a check box, mine spits out two. Aaaarrgggh!

**UPDATE** Can't find it. Only change was the window callback procedure name really.

This is all the change I did below to your original routine. Something else must be interfering

Code: Select all

Global Row

Declare WindowProcess(Handle.i, Message.i, wParam.i, lParam.i)

Procedure WindowProcess(Handle.i, Message.i, wParam.i, lParam.i)
  Select Message.i
    Case #WM_NOTIFY
      *Message.NMHDR = lParam.i
      If *Message\hwndFrom = GadgetID(#Gadget_Repeatermanager_lLoglist) And *Message\code = #NM_CLICK
        *Li.NMITEMACTIVATE = lParam.i
        Program\CurrentCheckedRow = *Li\iItem
      EndIf
  EndSelect
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

If GetGadgetItemState(#Gadget_Repeatermanager_lLoglist, Row) & #PB_ListIcon_Checked
  Debug "CheckBox : #"  + Str(Row) +  " Checked"
Else
  Debug "CheckBox : #"  + Str(Row) +  " UnChecked"
EndIf    
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5011
Joined: Sun Apr 12, 2009 6:27 am

Re: PB 5.4: How to detect ListIcon checkbox event?

Post by RASHAD »

Code: Select all

Program\CurrentCheckedRow = *Li\iItem
We need the variable Program\CurrentCheckedRow to be global
Then we will use it instead of Row

Code: Select all

If GetGadgetItemState(#Gadget_Repeatermanager_lLoglist, Row) & #PB_ListIcon_Checked
  Debug "CheckBox : #"  + Str(Program\CurrentCheckedRow ) +  " Checked"
Else
  Debug "CheckBox : #"  + Str(Program\CurrentCheckedRow ) +  " UnChecked"
EndIf  
Or use The global Row as I posted then let Program\CurrentCheckedRow = Row
Egypt my love
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4794
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: PB 5.4: How to detect ListIcon checkbox event?

Post by Fangbeast »

RASHAD wrote:

Code: Select all

Program\CurrentCheckedRow = *Li\iItem
We need the variable Program\CurrentCheckedRow to be global
Then we will use it instead of Row

Code: Select all

If GetGadgetItemState(#Gadget_Repeatermanager_lLoglist, Row) & #PB_ListIcon_Checked
  Debug "CheckBox : #"  + Str(Program\CurrentCheckedRow ) +  " Checked"
Else
  Debug "CheckBox : #"  + Str(Program\CurrentCheckedRow ) +  " UnChecked"
EndIf  
Or use The global Row as I posted then let Program\CurrentCheckedRow = Row
Hmm, Program\CurrentCheckedRow is already in a global structure (Along with other variables) which is why it works, just twice.

I'll try it by itself next. (better than cutting the grass!)

Code: Select all

Structure ProgramData
  QuitValue.i
  WindowMutex.i
  LastWindow.s
  
  CurrentLine.i
  CurrentRecord.s
  
  CurrentCheckedRow.i ; Here I am!
  
  CurrentDirectory.s
  DatabaseDirectory.s
  TemporaryDirectory.s
  RepeaterDirectory.s
  
  DatabaseName.s
  DatabaseHandle.i
  
  SearchCueFont.i
  SearchNormalFont.i
  SearchCueText.s
  
  CurrentDate.s
EndStructure

Global Program.ProgramData
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4794
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: PB 5.4: How to detect ListIcon checkbox event?

Post by Fangbeast »

RASHAD wrote:Hi Fangles
The item must be checked first to get its check box status

#1 :

Code: Select all

If OpenWindow(0, 0, 0, 640, 400, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  ListIconGadget(1,  10, 10, 620,380, "Column 0", 100, #PB_ListIcon_GridLines|#PB_ListIcon_CheckBoxes|#PB_ListIcon_FullRowSelect)
 
  For c = 1 To 6
    AddGadgetColumn(1, c, "Column " + Str(c), 100)
  Next
  For r = 0 To 100
    AddGadgetItem(1, r, "  Item "+Str(r)+Chr(10)+"Item "+Str(r)+Chr(10)+"Item 3"+Chr(10)+"Item 4")
  Next
EndIf

Repeat
  Select WaitWindowEvent(1)
     
    Case #PB_Event_CloseWindow
      Quit = 1
     
    Case #PB_Event_Gadget
      Select EventGadget()               
        Case 1
          Select EventType()                
            Case #PB_EventType_Change
                  For x = 0 To 100
                     If GetGadgetItemState(1,x) > 1
                        Debug "Item : "+Str(x)+" Checked"
                     EndIf
                  Next
                  Debug "*****"                        
             
          EndSelect         
      EndSelect
  EndSelect
 
Until Quit = 1




#2 :

Code: Select all

Global Row

Procedure WndProc(hwnd, uMsg, wParam, lParam)
    Select uMsg
      Case #WM_NOTIFY
               *uMsg.NMHDR = lParam                                                                     
              If *uMsg\hwndFrom = GadgetID(1) And *uMsg\code = #NM_CLICK
                 *Li.NMITEMACTIVATE = lParam
                 Row = *Li\iItem
              EndIf

    EndSelect
   ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

If OpenWindow(0, 0, 0, 640, 400, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  ListIconGadget(1,  10, 10, 620,380, "Column 0", 100, #PB_ListIcon_GridLines|#PB_ListIcon_CheckBoxes|#PB_ListIcon_FullRowSelect)
 
  For c = 1 To 6
    AddGadgetColumn(1, c, "Column " + Str(c), 100)
  Next
  For r = 0 To 100
    AddGadgetItem(1, r, "  Item "+Str(r)+Chr(10)+"Item "+Str(r)+Chr(10)+"Item 3"+Chr(10)+"Item 4")
  Next
EndIf

 SetWindowCallback(@WndProc())

Repeat
  Select WaitWindowEvent(1)
     
    Case #PB_Event_CloseWindow
      Quit = 1
     
    Case #PB_Event_Gadget
      Select EventGadget()               
        Case 1
          Select EventType()                   
            Case #PB_EventType_LeftClick
              If GetGadgetItemState(1, row) & #PB_ListIcon_Checked
                Debug "CheckBox : #"+Str(Row) +" Checked"
              Else
                Debug "CheckBox : #"+Str(Row) +" UnChecked"
              EndIf                  
             
          EndSelect
         
      EndSelect
  EndSelect
 
Until Quit = 1
Edit : # 2 Modified
Okay, I have to reply to this example as this is bizarre.

When I start the second example up, as long as I click ONLY the checkbox, I get a single event from the debug. (Checked on or off)

If I accidentally click on a line, then start clicking checkboxes, I get two events firing from then on.

How do I mask off this 'double event' and what's causing it to fire twice?
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5011
Joined: Sun Apr 12, 2009 6:27 am

Re: PB 5.4: How to detect ListIcon checkbox event?

Post by RASHAD »

Hi Fang

Code: Select all

;Global Row

Structure ProgramData
  QuitValue.i
  WindowMutex.i
  LastWindow.s
  
  CurrentLine.i
  CurrentRecord.s
  
  CurrentCheckedRow.i ; Here I am!
  
  CurrentDirectory.s
  DatabaseDirectory.s
  TemporaryDirectory.s
  RepeaterDirectory.s
  
  DatabaseName.s
  DatabaseHandle.i
  
  SearchCueFont.i
  SearchNormalFont.i
  SearchCueText.s
  
  CurrentDate.s
EndStructure

Global Program.ProgramData

Procedure WndProc(hwnd, uMsg, wParam, lParam)
    Select uMsg
      Case #WM_NOTIFY
               *uMsg.NMHDR = lParam                                                                     
              If *uMsg\hwndFrom = GadgetID(1) And *uMsg\code = #NM_CLICK
                 *Li.NMITEMACTIVATE = lParam
                 Program\CurrentCheckedRow = *Li\iItem
              EndIf

    EndSelect
   ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

If OpenWindow(0, 0, 0, 640, 400, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  ListIconGadget(1,  10, 10, 620,380, "Column 0", 100, #PB_ListIcon_GridLines|#PB_ListIcon_CheckBoxes|#PB_ListIcon_FullRowSelect)
 
  For c = 1 To 6
    AddGadgetColumn(1, c, "Column " + Str(c), 100)
  Next
  For r = 0 To 100
    AddGadgetItem(1, r, "  Item "+Str(r)+Chr(10)+"Item "+Str(r)+Chr(10)+"Item 3"+Chr(10)+"Item 4")
  Next
EndIf

 SetWindowCallback(@WndProc())

Repeat
  Select WaitWindowEvent(1)
     
    Case #PB_Event_CloseWindow
      Quit = 1
     
    Case #PB_Event_Gadget
      Select EventGadget()               
        Case 1
          Select EventType()                   
            Case #PB_EventType_Change
              Status = GetGadgetItemState(1, Program\CurrentCheckedRow)
              If status = 0
                Debug "Row : #"+Str(Program\CurrentCheckedRow)+" UnSelected"
                Debug "CheckBox UnChecked"
                Debug "----"
              ElseIf status = 1
                Debug "Row : #"+Str(Program\CurrentCheckedRow)+" Selected"
                Debug "CheckBox UnChecked"
                Debug "----"
              ElseIf Status = 2
                Debug "Row : #"+Str(Program\CurrentCheckedRow)+" UnSelected"
                Debug "CheckBox Checked"
                Debug "----"
              ElseIf Status = 3
                Debug "Row : #"+Str(Program\CurrentCheckedRow)+" Selected"
                Debug "CheckBox Checked"
                Debug "----" 
              EndIf                  
             
          EndSelect
         
      EndSelect
  EndSelect
 
Until Quit = 1
Egypt my love
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4794
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: PB 5.4: How to detect ListIcon checkbox event?

Post by Fangbeast »

Thank you for your kindness RASHAD. I will test this tomorrow. The repeater manager is getting ahead in leaps and bounds, looks good already. Still lots to do and a few small bugs but I am getting there.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
SeregaZ
Enthusiast
Enthusiast
Posts: 629
Joined: Fri Feb 20, 2009 9:24 am
Location: Almaty (Kazakhstan. not Borat, but Triple G)
Contact:

Re: PB 5.4: How to detect ListIcon checkbox event?

Post by SeregaZ »

now it work with select too. how to avoid select detection? i mean shows detection alert only when switcher change?


some kind like this, but my variant is wrong work if i make some drangdrop action inside gadget. how to block dragndrop event in callback?

Code: Select all

;Global Row

Structure ProgramData
  QuitValue.i
  WindowMutex.i
  LastWindow.s
  
  CurrentLine.i
  CurrentRecord.s
  
  CurrentCheckedRow.i ; Here I am!
  
  CurrentDirectory.s
  DatabaseDirectory.s
  TemporaryDirectory.s
  RepeaterDirectory.s
  
  DatabaseName.s
  DatabaseHandle.i
  
  SearchCueFont.i
  SearchNormalFont.i
  SearchCueText.s
  
  CurrentDate.s
EndStructure

Global Program.ProgramData

Procedure WndProc(hwnd, uMsg, wParam, lParam)
    Select uMsg
      Case #WM_NOTIFY
               *uMsg.NMHDR = lParam                                                                     
              If *uMsg\hwndFrom = GadgetID(1) And *uMsg\code = #NM_CLICK
                 *Li.NMITEMACTIVATE = lParam
                 Program\CurrentCheckedRow = *Li\iItem
              EndIf

    EndSelect
   ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

If OpenWindow(0, 0, 0, 640, 400, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  tst = ListIconGadget(1,  10, 10, 620,380, "Column 0", 100, #PB_ListIcon_GridLines|#PB_ListIcon_CheckBoxes|#PB_ListIcon_FullRowSelect)
 
  For c = 1 To 6
    AddGadgetColumn(1, c, "Column " + Str(c), 100)
  Next
  For r = 0 To 100
    AddGadgetItem(1, r, "  Item "+Str(r)+Chr(10)+"Item "+Str(r)+Chr(10)+"Item 3"+Chr(10)+"Item 4")
  Next
EndIf

oldline = -1

 SetWindowCallback(@WndProc())

Repeat
  Select WaitWindowEvent(1)
     
    Case #PB_Event_CloseWindow
      Quit = 1
     
    Case #PB_Event_Gadget
      Select EventGadget()               
        Case 1
          Select EventType()                   
            Case #PB_EventType_Change
              newline = GetGadgetState(1)
              
              If newline <> Program\CurrentCheckedRow Or oldline = newline
              
              Status = GetGadgetItemState(1, Program\CurrentCheckedRow)
              If status = 0 Or status = 1
                Debug "Row : #"+Str(Program\CurrentCheckedRow)
                Debug "CheckBox UnChecked"
              ElseIf Status = 2 Or Status = 3
                Debug "Row : #"+Str(Program\CurrentCheckedRow)
                Debug "CheckBox Checked"
              EndIf   
              
            EndIf
            
            oldline = newline
             
          EndSelect
         
      EndSelect
  EndSelect
 
Until Quit = 1
Post Reply