Editing cells in ListIcons (updated for Vista)

Share your advanced PureBasic knowledge/code with the community.
Pureabc
User
User
Posts: 76
Joined: Mon Jan 16, 2006 1:11 am

Post by Pureabc »

Is API the way to do it? (highlight one cell)

I didn't find the option in PB help.

Thank you.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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
I may look like a mule, but I'm not a complete ass.
Pureabc
User
User
Posts: 76
Joined: Mon Jan 16, 2006 1:11 am

Post by Pureabc »

I will study your code.
Thank you very much.

:wink:
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post 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.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post 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.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re:

Post by PB »

The code in the first post no longer compiles with v4.40 B3.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Arctic Fox
Enthusiast
Enthusiast
Posts: 609
Joined: Sun Dec 21, 2008 5:02 pm
Location: Aarhus, Denmark

Re: Editing cells in ListIcons (updated for Vista)

Post by Arctic Fox »

Try

Code: Select all

Protected Dim cols.l(0), i, blnFoundZeroColumn
at the beginning of the _LIEEditCell()-procedure
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Editing cells in ListIcons (updated for Vista)

Post by srod »

Thanks Arctic - I have altered the code in the first post.
I may look like a mule, but I'm not a complete ass.
User avatar
Arctic Fox
Enthusiast
Enthusiast
Posts: 609
Joined: Sun Dec 21, 2008 5:02 pm
Location: Aarhus, Denmark

Re: Editing cells in ListIcons (updated for Vista)

Post by Arctic Fox »

And thank you too for this excellent piece of code :D
leodh
Enthusiast
Enthusiast
Posts: 164
Joined: Sun Nov 06, 2005 6:07 am
Location: Perth Western Australia

Re: Editing cells in ListIcons (updated for Vista)

Post 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
Regards
Leo
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Editing cells in ListIcons (updated for Vista)

Post 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
I may look like a mule, but I'm not a complete ass.
leodh
Enthusiast
Enthusiast
Posts: 164
Joined: Sun Nov 06, 2005 6:07 am
Location: Perth Western Australia

Re: Editing cells in ListIcons (updated for Vista)

Post by leodh »

Hi srod,

Thanks for that, I was a bit wide of the make with my atempt.
Regards
Leo
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Editing cells in ListIcons (updated for Vista)

Post 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 :|
ImageThe happiness is a road...
Not a destination
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Editing cells in ListIcons (updated for Vista)

Post 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
I may look like a mule, but I'm not a complete ass.
Post Reply