Page 5 of 6

Posted: Wed Jul 23, 2008 5:35 pm
by Pureabc
Is API the way to do it? (highlight one cell)

I didn't find the option in PB help.

Thank you.

Posted: Wed Jul 23, 2008 6:05 pm
by srod
Okay, the following is not great because use of SetGadgetColor() introduces a lot of flicker because it invalidates the whole listicon control. Getting around this would involve a little more work (using the subclassed procedure in the main 'Edit listicon.pbi' file, adding a #WM_LBUTTONDOWN handler with the hit-testing, getting the cell rectangle so that it can be invalidated, adding a little custom draw ...) More work than I have time for right now!

Code: Select all

XIncludeFile "Edit ListIcon.pbi"
DisableExplicit

oldItem = -1
LoadFont(1, "Arial",10)

If OpenWindow(0, 100, 100, 600, 600, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
  ListIconGadget(1, 5, 5, 490, 390, "", 0, #PB_ListIcon_GridLines)
  SetGadgetFont(1, FontID(1))
  For i = 1 To 30
    AddGadgetColumn(1, i, "Col "+Str(i), 100)
  Next
  For row = 1 To 10
    AddGadgetItem(1,-1,"")
    For col = 1 To 100
      SetGadgetItemText(1, row-1, "row "+Str(row-1)+", col "+Str(col), col)
    Next
  Next

  SetListIconEditable(1)
  SetActiveGadget(1)
;  EditCell(1, 19, 5)
  Repeat
    Event = WaitWindowEvent()
    Select event
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            If EventType() = #PB_EventType_LeftClick
              PInfo.LVHITTESTINFO
              hWnd = GadgetID(1)
              GetCursorPos_(@PInfo\pt)
              MapWindowPoints_(0, hWnd,  @PInfo\pt, 1)
              SendMessage_(hWnd, #LVM_SUBITEMHITTEST, 0, PInfo)
              If PInfo\iItem<>-1
                If oldItem <> -1
                  SetGadgetItemColor(1, oldItem, #PB_Gadget_BackColor, #White,1)
                  SetGadgetItemColor(1, oldItem, #PB_Gadget_FrontColor, 0,1)
                EndIf
                oldItem = PInfo\iItem
                SetGadgetItemColor(1, oldItem, #PB_Gadget_BackColor, GetSysColor_(#COLOR_HIGHLIGHT),1)
                SetGadgetItemColor(1, oldItem, #PB_Gadget_FrontColor, GetSysColor_(#COLOR_HIGHLIGHTTEXT),1)
              EndIf
            EndIf 
        EndSelect
    EndSelect
  Until Event = #PB_Event_CloseWindow
EndIf

Posted: Wed Jul 23, 2008 6:16 pm
by Pureabc
I will study your code.
Thank you very much.

:wink:

Posted: Sat Dec 27, 2008 2:47 pm
by Fangbeast
Mister kipper tits, stop abusing those French poodles for a moment. I need to ask you something (EVIL GRIN).

Been playing with this magnificent bit of jiggery pokery and it's extremely useful.

I'd like to fire off my own event for a particular gadget when the label has started being edited (I want to strip a character), when the label has finished being edited (I want to add a character) and then I want to fire off a custom procedure immediately after.

Could you; oh sage of wisdom, elucidate at which point in your code I might put my own to accomplish this?

I failed to do so on my mortal own.

Posted: Sat Dec 27, 2008 6:27 pm
by srod
Look at the #LVN_BEGINLABELEDIT and #LVN_ENDLABELEDIT messages in my code. You should be able to insert whatever code you need at these points.

Posted: Sat Dec 27, 2008 11:27 pm
by Fangbeast
AHA!!! Thank you, you know how I like a good insertion. Seriously though, leave those French poodles alone in the meantime, they are no good for your health.

:):)

*Update* Thanks, I worked out something simple from your hint without having to go to a full grid gadget.

Re:

Posted: Thu Oct 01, 2009 9:38 pm
by PB
The code in the first post no longer compiles with v4.40 B3.

Re: Editing cells in ListIcons (updated for Vista)

Posted: Thu Oct 01, 2009 10:06 pm
by Arctic Fox
Try

Code: Select all

Protected Dim cols.l(0), i, blnFoundZeroColumn
at the beginning of the _LIEEditCell()-procedure

Re: Editing cells in ListIcons (updated for Vista)

Posted: Fri Oct 02, 2009 10:22 am
by srod
Thanks Arctic - I have altered the code in the first post.

Re: Editing cells in ListIcons (updated for Vista)

Posted: Fri Oct 02, 2009 6:40 pm
by Arctic Fox
And thank you too for this excellent piece of code :D

Re: Editing cells in ListIcons (updated for Vista)

Posted: Thu Sep 15, 2011 7:34 am
by leodh
Hi srod,

Sorry to drag up this old thread, but I have been using your Editable Listicon code ( Procedure.l SetListIconEditable(listID) etc.. ) and it works great, but I would like to be able to un-enable a listIcon from time to time. I looked through the code and I think I have to use the SetProp_() command but when I do it kills the program or does not work.

Procedure.l UnSetListIconEditable(listID)
SetProp_(hWnd, "_LIEdit",0)
Endprocedure

Is there a simple way of doing this.

Thanks
Leo

Re: Editing cells in ListIcons (updated for Vista)

Posted: Thu Sep 15, 2011 6:24 pm
by srod

Code: Select all

Procedure UnSetListIconEditable(listID)
  Protected hWnd, *mem._LIEdit
  If IsGadget(listID) And GadgetType(listID)=#PB_GadgetType_ListIcon
    hWnd = GadgetID(listID)
    *mem = GetProp_(hWnd, "_LIEdit")
    If *mem
      SetWindowLongPtr_(hWnd, #GWL_WNDPROC, *mem\listOldProc)
      FreeMemory(*mem)
      RemoveProp_(hWnd, "_LIEdit")
    EndIf
  EndIf
EndProcedure

Re: Editing cells in ListIcons (updated for Vista)

Posted: Thu Sep 15, 2011 11:26 pm
by leodh
Hi srod,

Thanks for that, I was a bit wide of the make with my atempt.

Re: Editing cells in ListIcons (updated for Vista)

Posted: Mon Apr 25, 2016 5:21 pm
by Kwai chang caine
Hello at all :D
When i use

Code: Select all

 UnSetListIconEditable(#ListIcon)
I have an error at the line

Code: Select all

If *liedit\editHwnd=0 
in the procedure

Code: Select all

Procedure.l _LIEeditProc(hWnd, uMsg, wParam, lParam) ; ListIcon editable (Window proc of the edit control)
  Protected result, oldwinproc, *liedit._LIEdit, *wpos.WINDOWPOS 
  ;Retrieve the address of the old proc. 
    oldwinproc = GetProp_(hWnd, "_LIEditOldProc") 
  ;Retrieve the address of the LIEdit structure. 
    *liedit = GetProp_(GetParent_(hWnd), "_LIEdit") 
  Select uMsg 
    Case #WM_ERASEBKGND 
      ;A hack in order to clear the default selection of characters. 
      result=CallWindowProc_(oldwinproc, hWnd, uMsg, wParam, lParam) 
      If *liedit\editHwnd=0 
        *liedit\editHwnd = hWnd 
        ;Set margins. 
        SendMessage_(hWnd, #EM_SETMARGINS, #EC_LEFTMARGIN|#EC_RIGHTMARGIN, 4) 
        SendMessage_(hWnd, #EM_SETSEL, -1,0) 
      EndIf 
    Case #WM_WINDOWPOSCHANGING 
      *wpos=lParam 
      ;*wpos\cx=*liedit\cx ;Comment this line to get an edit control which grows with the text. 
      *wpos\cy=*liedit\cy+3 
      *wpos\x=*liedit\x 
      *wpos\y=*liedit\y-2 
      result=CallWindowProc_(oldwinproc, hWnd, uMsg, wParam, lParam) 
    Case #WM_NCDESTROY 
      result=CallWindowProc_(oldwinproc, hWnd, uMsg, wParam, lParam) 
      RemoveProp_(hWnd, "_LIEditOldProc") 
    Default 
      result=CallWindowProc_(oldwinproc, hWnd, uMsg, wParam, lParam) 
  EndSelect 
  ProcedureReturn result 
EndProcedure 
Buit only if i use this command before :shock:

Code: Select all

EditCell(#ListIcon, 1, 1)
Someone know how fix it :|

Re: Editing cells in ListIcons (updated for Vista)

Posted: Mon Apr 25, 2016 6:20 pm
by srod
Try the following in place of the UnSetListIconEditable() procedure.

Code: Select all

Procedure UnSetListIconEditable(listID)
  Protected hWnd, *mem._LIEdit
  If IsGadget(listID) And GadgetType(listID)=#PB_GadgetType_ListIcon
    hWnd = GadgetID(listID)
    *mem = GetProp_(hWnd, "_LIEdit")
    If *mem
      SendMessage_(hWnd, #LVM_EDITLABEL, 0, 0)
      SetWindowLongPtr_(hWnd, #GWL_WNDPROC, *mem\listOldProc)
      FreeMemory(*mem)
      RemoveProp_(hWnd, "_LIEdit")
    EndIf
  EndIf
EndProcedure