It is currently Sun Dec 16, 2018 6:24 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: ListIconGadget checkbox toggling
PostPosted: Mon Nov 05, 2018 12:07 pm 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1666
I've got this test code where all I want to do, is press Space to toggle the checkbox states of any selected items. In this example, I want to toggle the checkbox state of items 5 to 10.

Run this app, and then press Space a few times. Items 5 to 9 toggle their checkbox, but not item 10. However, if you click the Button so it gets the focus, and then press Space, then yes, item 10 now also gets included with the toggling, which is what I want.

So how can I include item 10 without switching the focus away from the ListIconGadget?

Code:
If OpenWindow(0, 0, 0, 640, 400, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  ListIconGadget(0,  10, 10, 620,350, "Column 0", 100, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines| #PB_ListIcon_CheckBoxes|#PB_ListIcon_MultiSelect )
 
  ButtonGadget(1,10,370,100,25,"Button")
 
  For c = 1 To 6
    AddGadgetColumn(0, c, "Column " + Str(c), 100)
  Next
 
  For r = 0 To 15
    AddGadgetItem(0, r, "  Item "+Str(r)+Chr(10)+"Item "+Str(r)+Chr(10)+"Item 3"+Chr(10)+"Item 4")
  Next
 
  For r = 5 To 10
    SetGadgetItemState(0, r, #PB_ListIcon_Checked | #PB_ListIcon_Selected)
  Next
 
  SetActiveGadget(0)
 
  Repeat
   
    Select WaitWindowEvent()
       
      Case #PB_Event_CloseWindow
        Quit = 1
       
      Case #WM_KEYDOWN
       
        If GetAsyncKeyState_(#VK_SPACE) & $8000
          For r=5 To 10
            If GetGadgetItemState(0,r) & #PB_ListIcon_Selected
              If GetGadgetItemState(0,r) & #PB_ListIcon_Checked
                c=~#PB_ListIcon_Checked
              Else
                c=#PB_ListIcon_Checked
              EndIf
              SetGadgetItemState(0,r,c|#PB_ListIcon_Selected)
            EndIf
          Next
        EndIf
       
    EndSelect
   
  Until Quit = 1
 
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIconGadget checkbox toggling
PostPosted: Mon Nov 05, 2018 12:24 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 296
It works if you use a keyboard shortcut instead.
Code:
If OpenWindow(0, 0, 0, 640, 400, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  ListIconGadget(0,  10, 10, 620,350, "Column 0", 100, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines| #PB_ListIcon_CheckBoxes|#PB_ListIcon_MultiSelect )
 
  ButtonGadget(1,10,370,100,25,"Button")
 
  AddKeyboardShortcut(0, #PB_Shortcut_Space, 0)
 
  For c = 1 To 6
    AddGadgetColumn(0, c, "Column " + Str(c), 100)
  Next
 
  For r = 0 To 15
    AddGadgetItem(0, r, "  Item "+Str(r)+Chr(10)+"Item "+Str(r)+Chr(10)+"Item 3"+Chr(10)+"Item 4")
  Next
 
  For r = 5 To 10
    SetGadgetItemState(0, r, #PB_ListIcon_Checked | #PB_ListIcon_Selected)
  Next
 
  SetActiveGadget(0)
 
  Repeat
   
    Select WaitWindowEvent()
       
      Case #PB_Event_CloseWindow
        Quit = 1
       
      Case #PB_Event_Menu
        For r=5 To 10
          If GetGadgetItemState(0,r) & #PB_ListIcon_Selected
            If GetGadgetItemState(0,r) & #PB_ListIcon_Checked
              c=~#PB_ListIcon_Checked
            Else
              c=#PB_ListIcon_Checked
            EndIf
            SetGadgetItemState(0,r,c|#PB_ListIcon_Selected)
          EndIf
        Next
       
      Case #WM_KEYDOWN
       
        If GetAsyncKeyState_(#VK_SPACE) & $8000

        EndIf
       
    EndSelect
   
  Until Quit = 1
 
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIconGadget checkbox toggling
PostPosted: Mon Nov 05, 2018 12:40 pm 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3147
Hi Dude
wombats is very close
Code:
If OpenWindow(0, 0, 0, 640, 400, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  ListIconGadget(0,  10, 10, 620,350, "Column 0", 100, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines| #PB_ListIcon_CheckBoxes|#PB_ListIcon_MultiSelect )
 
  ButtonGadget(1,10,370,100,25,"Button")
 
  For c = 1 To 6
    AddGadgetColumn(0, c, "Column " + Str(c), 100)
  Next
 
  For r = 0 To 15
    AddGadgetItem(0, r, "  Item "+Str(r)+Chr(10)+"Item "+Str(r)+Chr(10)+"Item 3"+Chr(10)+"Item 4")
  Next
 
  For r = 5 To 10
    SetGadgetItemState(0, r, #PB_ListIcon_Checked | #PB_ListIcon_Selected)
  Next
 
  SetActiveGadget(0)
 
  AddKeyboardShortcut(0,#PB_Shortcut_Space,10)
 
  Repeat
   
    Select WaitWindowEvent()
       
      Case #PB_Event_CloseWindow
        Quit = 1
       
      Case #PB_Event_Menu
        Select EventMenu()
          Case 10
            For r = 5 To 10
              SetActiveGadget(0)
              SetGadgetItemState(0,r,GetGadgetItemState(0,r)!#PB_ListIcon_Selected ! #PB_ListIcon_Checked  )
            Next
        EndSelect
       
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            For r = 5 To 10
              SetActiveGadget(0)
              SetGadgetItemState(0,r,GetGadgetItemState(0,r)!#PB_ListIcon_Selected ! #PB_ListIcon_Checked  )
            Next
        EndSelect
       
    EndSelect
   
  Until Quit = 1
 
EndIf

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIconGadget checkbox toggling
PostPosted: Mon Nov 05, 2018 1:11 pm 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1666
Thank you both! :)


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIconGadget checkbox toggling
PostPosted: Tue Nov 06, 2018 3:04 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Mar 09, 2006 9:24 am
Posts: 249
Location: S. Kor
another way.
it only works when the listicon gagdet is focused.

Code:
#MY_Event_ListIconSpace = #PB_Event_FirstCustomValue

Global old

Procedure ListIconWProc(hwnd, msg, wParam, lParam)
 
  If msg = #WM_KEYDOWN And wParam = #VK_SPACE
    PostEvent(#MY_Event_ListIconSpace, 0, 0)
   
    ProcedureReturn 0
  EndIf
 
  ProcedureReturn CallWindowProc_(old, hwnd, msg, wParam, lParam)
EndProcedure


If OpenWindow(0, 0, 0, 640, 400, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  ListIconGadget(0,  10, 10, 620,350, "Column 0", 100, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines| #PB_ListIcon_CheckBoxes|#PB_ListIcon_MultiSelect )
 
  ButtonGadget(1,10,370,100,25,"Button")
 
  For c = 1 To 6
    AddGadgetColumn(0, c, "Column " + Str(c), 100)
  Next
 
  For r = 0 To 15
    AddGadgetItem(0, r, "  Item "+Str(r)+Chr(10)+"Item "+Str(r)+Chr(10)+"Item 3"+Chr(10)+"Item 4")
  Next
 
  For r = 5 To 10
    SetGadgetItemState(0, r, #PB_ListIcon_Checked | #PB_ListIcon_Selected)
  Next
 
  old = SetWindowLongPtr_(GadgetID(0), #GWLP_WNDPROC, @ListIconWProc())
 
  SetActiveGadget(0)
 
  Repeat
   
    Select WaitWindowEvent()
       
      Case #PB_Event_CloseWindow
        Quit = 1
       
      Case #MY_Event_ListIconSpace
        If EventGadget() = 0
          FirstItem = GetGadgetState(0)
         
          If FirstItem <> -1
            For i = FirstItem To CountGadgetItems(0) - 1
              If GetGadgetItemState(0, i) & #PB_ListIcon_Selected
                If GetGadgetItemState(0, i) & #PB_ListIcon_Checked
                  c = ~#PB_ListIcon_Checked
                Else
                  c = #PB_ListIcon_Checked
                EndIf
                SetGadgetItemState(0, i, c | #PB_ListIcon_Selected)
              EndIf
            Next
          EndIf
         
          ;For r=5 To 10
          ;  If GetGadgetItemState(0,r) & #PB_ListIcon_Selected
          ;    If GetGadgetItemState(0,r) & #PB_ListIcon_Checked
          ;      c=~#PB_ListIcon_Checked
          ;    Else
          ;      c=#PB_ListIcon_Checked
          ;    EndIf
          ;    SetGadgetItemState(0,r,c|#PB_ListIcon_Selected)
          ;  EndIf
          ;Next
         
        EndIf
       
    EndSelect
   
  Until Quit = 1
 
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIconGadget checkbox toggling
PostPosted: Tue Nov 06, 2018 4:50 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 2760
Location: Boston, MA
Dude, your code did not work because the spacebar is already executing code on the focused gadget.
A keyboard shortcut or a callback on the gadget will interrupt/replace the built-in process.

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIconGadget checkbox toggling
PostPosted: Tue Nov 06, 2018 10:10 pm 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1666
Thanks skywalk, yes, I realised that now. :oops:


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: DarkDragon and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye