Page 1 of 1

[Solved] ListIconGadget() ~ How do I lock the scrollbars?

Posted: Wed Aug 16, 2017 9:47 am
by RichardL
Good morning all,
My application allows the user to scroll around data in a ListIconGadget to select an area.
The user then presses a 'Go' button. At that point I need to lock the grid in position while some other processes happen.
DisableGadget() disrupts the display too much and is ruled out.

Any suggestions or help would be appreciated.
RichardL

Re: ListIconGadget() ~ How do I temporarily lock the scrollb

Posted: Wed Aug 16, 2017 2:39 pm
by RASHAD
Hi

Code: Select all

Global oldliCB,oldhCB,scrollflag

Procedure lihCB(hWnd, uMsg, wParam, lParam)
    Select uMsg
      Case #WM_LBUTTONDOWN,#WM_LBUTTONDBLCLK
         If scrollflag = 1
          ProcedureReturn 1
        EndIf
    EndSelect
  ProcedureReturn CallWindowProc_(oldhCB, hWnd, uMsg, wParam, lParam)
EndProcedure

Procedure liCB(hWnd, uMsg, wParam, lParam)
  Select uMsg
    Case #WM_LBUTTONDOWN,#WM_VSCROLL,#WM_HSCROLL, #WM_MOUSEWHEEL,#WM_KEYDOWN
        If scrollflag = 1
          ProcedureReturn 1
        EndIf
     
  EndSelect
  ProcedureReturn CallWindowProc_(oldliCB, hWnd, uMsg, wParam, lParam)
EndProcedure

Procedure sizeCB()
  ResizeGadget(2,5,30,WindowWidth(0)-10,WindowHeight(0)-35)
EndProcedure

OpenWindow(0,0,0,320,275,"void",#PB_Window_SystemMenu | #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
ButtonGadget(0,5,5,150,20,"Disable Scroll")
ButtonGadget(1,165,5,150,20,"Enable Scroll")
ListIconGadget(2,5,30,310,240,"Name",280, #PB_ListIcon_MultiSelect|#PB_ListIcon_AlwaysShowSelection)
Header = SendMessage_(GadgetID(2), #LVM_GETHEADER, 0, 0)

For i=1 To 30 : AddGadgetItem(2,-1,"Gadget Item #" + Str(i)) : Next
SetGadgetItemColor(2, -1, #PB_Gadget_FrontColor, $0000FF,  0)

oldliCB = SetWindowLongPtr_(GadgetID(2), #GWL_WNDPROC, @liCB())
oldhCB = SetWindowLongPtr_(header, #GWL_WNDPROC, @lihCB())
BindEvent(#PB_Event_SizeWindow,@sizeCB())
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
        Quit = 1

    Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
            SetActiveGadget(2)
            scrollflag = 1
            
          Case 1
            SetActiveGadget(2)
            scrollflag = 0
        EndSelect
    EndSelect
Until Quit = 1
Edit :Updated

Re: ListIconGadget() ~ How do I temporarily lock the scrollb

Posted: Wed Aug 16, 2017 3:42 pm
by IdeasVacuum
A simple way is to temporarily make the ListIcon Scrollbars ineffective:

Code: Select all

Enumeration
#Win
#ListIcon
#BtnOff
#BtnOn
EndEnumeration


Procedure Win()
;#-------------
              If OpenWindow(#Win, 0, 0, 500, 300, "Temporarily Freeze ListIcon", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

                         ListIconGadget(#ListIcon, 0, 0, 500, 250, "Col 0", 100)
                        AddGadgetColumn(#ListIcon, 1, "Col 1", 100)
                        AddGadgetColumn(#ListIcon, 2, "Col 2", 100)
                        AddGadgetColumn(#ListIcon, 3, "Col 3", 100)
                        AddGadgetColumn(#ListIcon, 4, "Col 4", 100)
                        AddGadgetColumn(#ListIcon, 5, "Col 5", 100)
                        AddGadgetColumn(#ListIcon, 6, "Col 6", 100)
                        AddGadgetColumn(#ListIcon, 7, "Col 7", 100)
                        AddGadgetColumn(#ListIcon, 8, "Col 8", 100)
                           ButtonGadget(#BtnOff, 334, 255, 80, 40, "OFF")
                           ButtonGadget(#BtnOn, 418, 255, 80, 40, "ON")
              EndIf
EndProcedure

Procedure Wait()
;#--------------
iExit.i = #False

              Repeat
                    Select WaitWindowEvent(1)

                             Case #PB_Event_CloseWindow: iExit = #True


                             Case #PB_Event_Gadget

                                    Select EventGadget()

                                               Case #BtnOff: SendMessage_(GadgetID(#ListIcon), #WM_SETREDRAW, 0, 0)
                                               Case  #BtnOn: SendMessage_(GadgetID(#ListIcon), #WM_SETREDRAW, 1, 0)
                                    EndSelect
                    EndSelect

              Until iExit = #True
EndProcedure

 Win()
Wait()
End

Re: ListIconGadget() ~ How do I temporarily lock the scrollb

Posted: Wed Aug 16, 2017 3:53 pm
by RASHAD
Noway
Populate the listicon and use the scrollbar buttons :wink:

Re: ListIconGadget() ~ How do I temporarily lock the scrollb

Posted: Wed Aug 16, 2017 5:25 pm
by IdeasVacuum
You are so right Rashad - different behavior when populated (strange).

This trick works though:

Code: Select all

;16/08/2017 15:29:49

Enumeration
#Win
#ListIcon
#Image
#BtnOff
#BtnOn
#Mask
EndEnumeration

CreateImage(#Mask, 500, 250, 32, #PB_Image_Transparent)

Procedure Win()
;#-------------
Protected iRow.i, iCol.i
Protected sRow.s
              If OpenWindow(#Win, 0, 0, 500, 300, "Temporarily Freeze ListIcon", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

                         ListIconGadget(#ListIcon, 0, 0, 500, 250, "Col 0", 100)
                            ImageGadget(#Image,    0, 0, 500, 250, ImageID(#Mask))
                             HideGadget(#Image, #True)
                        AddGadgetColumn(#ListIcon, 1, "Col 1", 100)
                        AddGadgetColumn(#ListIcon, 2, "Col 2", 100)
                        AddGadgetColumn(#ListIcon, 3, "Col 3", 100)
                        AddGadgetColumn(#ListIcon, 4, "Col 4", 100)
                        AddGadgetColumn(#ListIcon, 5, "Col 5", 100)
                        AddGadgetColumn(#ListIcon, 6, "Col 6", 100)
                        AddGadgetColumn(#ListIcon, 7, "Col 7", 100)
                        AddGadgetColumn(#ListIcon, 8, "Col 8", 100)
                           ButtonGadget(#BtnOff, 334, 255, 80, 40, "OFF")
                           ButtonGadget(#BtnOn, 418, 255, 80, 40, "ON")


                      For iRow = 0 To 99

                           sRow = ""

                           For iCol = 0 To 8

                                sRow = sRow + "Col " + RSet(Str(iCol), 2, "0") + " Row " + RSet(Str(iRow), 2, "0") + #LF$

                           Next iCol

                                AddGadgetItem(#ListIcon, -1, sRow)
                      Next iRow
              EndIf
EndProcedure

Procedure Wait()
;#--------------
iExit.i = #False

              Repeat
                    Select WaitWindowEvent(1)

                             Case #PB_Event_CloseWindow: iExit = #True


                             Case #PB_Event_Gadget

                                    Select EventGadget()

                                               Case #BtnOff
                                                         HideGadget(#Image, #False)
                                                      SetWindowPos_(GadgetID(#Image), #HWND_TOP, 0, 0, 0, 0, #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED)

                                               Case  #BtnOn: HideGadget(#Image, #True)

                                    EndSelect
                    EndSelect

              Until iExit = #True
EndProcedure

 Win()
Wait()
End
[/size] Edited re Rashad's spot

Re: ListIconGadget() ~ How do I temporarily lock the scrollb

Posted: Wed Aug 16, 2017 5:45 pm
by RASHAD
Yes it works but I am not sure about Windows XP as it acts differently with transparency

Wrong code to correct

Code: Select all

SetWindowPos_(GadgetID(#Image), #HWND_TOP , 0, 0, 0, 0,  #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED)

Re: ListIconGadget() ~ How do I temporarily lock the scrollb

Posted: Wed Aug 16, 2017 6:23 pm
by IdeasVacuum
Update for Rashad's code:

Code: Select all

Case #WM_VSCROLL, #WM_HSCROLL, #WM_MOUSEWHEEL

Re: ListIconGadget() ~ How do I temporarily lock the scrollb

Posted: Thu Aug 17, 2017 7:45 am
by RSBasic
Update for Rashad's code:

Code: Select all

Case #WM_VSCROLL, #WM_HSCROLL, #WM_MOUSEWHEEL, #WM_KEYDOWN

Re: ListIconGadget() ~ How do I temporarily lock the scrollb

Posted: Thu Aug 17, 2017 10:09 am
by IdeasVacuum
I think the ImageGadget mask is the best method because from a User perspective, the ListIcon is completely frozen, you can't scroll inside the list and the scroll bars do not move. So, they see a 'Read only' view and the data can still be changed programmatically.

Re: ListIconGadget() ~ How do I temporarily lock the scrollb

Posted: Thu Aug 17, 2017 12:25 pm
by RichardL
Gentlemen,
Thank you all for your assistance, it is much appreciated.

I have used Rashad's solution because, most conveniently I already had the necessary callback procedure and flag in place (and the right way up!).
All I needed to do was patch in a few lines from Rashad's example.
The solution is perfect... well almost! Would it be possible to prevent column dragging and resizing as well?

Best regards
RichardL

Re: ListIconGadget() ~ How do I temporarily lock the scrollb

Posted: Thu Aug 17, 2017 1:39 pm
by RASHAD
Hi guys
Previous post updated
Added more control upon ListIcon
Added Header control as well

Re: [Solved] ListIconGadget() ~ How do I lock the scrollbars

Posted: Thu Aug 17, 2017 3:47 pm
by RichardL
Good afternoon,

Thank you Rashad... that works beautifully!

Best regards
RichardL