ListIcon Fast and Furiously editable [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: ListIcon Fast and Furiously editable

Post by Kwai chang caine »

:lol: :lol: :lol:
Thanks you all for this kind words
Personally i always love this splendid frog.
Because she are very nice, and cherry on the cake, she smilling, and i love smilling and laughing.
But i'm very happy the master have the courage to show his face 8)

NETMAESTRO is one of my hero, and have super smilling frog to admire it's good, but a picture of the real nice face it's again better for a real fan
The inside of the head of Netmaestro is very full, and the outside is very nice...a reason more to admire him 8)

Long life to NETMAESTRO who are always here, since the first day i come on this merveillous forum, they are more than 10 years, and help me, and numerous members with the talent and the eternal frog smile :D
ImageThe happiness is a road...
Not a destination
User avatar
Zapman
Enthusiast
Enthusiast
Posts: 205
Joined: Tue Jan 07, 2020 7:27 pm

Re: ListIcon Fast and Furiously editable [Resolved]

Post by Zapman »

Hi Kwai chang caine,

Here is another version based on an old code from El Choni.
This new version does'nt use any global variable, so, as the demo shows, it can manage two or more editable ListIconGadgets in the same window or program.

Code: Select all

; Editable ListIconGadget
; Author: El Choni
; -- updated for PB3.92+ by Andre
; -- updated for PB4.00 by blbltheworm
; -- updated for PB5.xx and adapted by Zapman to take off global variables.
; Date: 09. May 2003 - fbr. 2020
; OS: Windows


Declare EditableListIconGadget(GadgetNumber, x, y, Width, Height, DefaultText$, FirstColumnWidth, Options=0)
Declare SetEditableListIconGadgetColumns(GadgetNumber, EditableColumns$)
;
; DEMO
;{
Define Demo, ELIGRef, ELIGRef2, i, hour12, Hour$
Define EventID
;
Demo = 1 ; Set Demo to 1 to see the demo
If Demo
  OpenWindow(0, 0, 0, 545, 260, "Demo window", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  ;
  ELIGRef = EditableListIconGadget(#PB_Any, 10, 10, 340, 240, "", 70, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_MultiSelect|#PB_ListIcon_FullRowSelect|#PB_ListIcon_HeaderDragDrop) 
  ;SetEditableListIconGadgetColumns(ELIGRef, "01011000") ; second, forth and fifth columns will be editable
  ;SetEditableListIconGadgetColumns(ELIGRef, "1")     ; First column only will be editable
  ;SetEditableListIconGadgetColumns(ELIGRef, "11")    ; First and second column  will be editable
  ;SetEditableListIconGadgetColumns(ELIGRef, "0")     ; All columns will be editable
  ;
  AddGadgetColumn(ELIGRef, 1, "Sun", 35) 
  AddGadgetColumn(ELIGRef, 2, "Mon", 35) 
  AddGadgetColumn(ELIGRef, 3, "Tue", 35) 
  AddGadgetColumn(ELIGRef, 4, "Wed", 35) 
  AddGadgetColumn(ELIGRef, 5, "Thu", 35) 
  AddGadgetColumn(ELIGRef, 6, "Fri", 35) 
  AddGadgetColumn(ELIGRef, 7, "Sat", 35) 
  ;
  For i=18 To 50 
    hour12 = i
    If hour12>25
      hour12-24 
      Hour$ = " pm" 
    Else 
      Hour$ = " am" 
    EndIf 
    If hour12&1 
      Hour$=Str(hour12/2)+":30"+Hour$
    Else 
      Hour$=Str(hour12/2)+":00"+Hour$
    EndIf 
    AddGadgetItem(ELIGRef, -1, Hour$+Chr(10)+Str(hour12/2)+"1"+Chr(10)+Str(hour12/2)+"2"+Chr(10)+Str(hour12/2)+"3"+Chr(10)+Str(hour12/2)+"4"+Chr(10)+Str(hour12/2)+"5"+Chr(10)+Str(hour12/2)+"6"+Chr(10)+Str(hour12/2)+"7");,ImageID(0)) 
  Next i 
  ;
  ELIGRef2 = EditableListIconGadget(#PB_Any, 360, 10, 175, 240, "First", 50, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_MultiSelect|#PB_ListIcon_FullRowSelect|#PB_ListIcon_HeaderDragDrop) 
  AddGadgetColumn(ELIGRef2, 1, "Second", 50) 
  AddGadgetColumn(ELIGRef2, 2, "Third", 50)
  ;
  For i=1 To 15
    AddGadgetItem(ELIGRef2, -1,Str(Random(100,1))+Chr(10)+Str(Random(100,1))+Chr(10)+Str(Random(100,1))+Chr(10)) 
  Next i 
  ;
  Repeat
    EventID = WaitWindowEvent()
  Until EventID=#PB_Event_CloseWindow 
  
  End
EndIf
;}
;
;#NM_CUSTOMDRAW = #NM_FIRST-12 
;#LVM_SUBITEMHITTEST = #LVM_FIRST+57 
;#LVM_GETSUBITEMRECT = #LVM_FIRST+56
;
Procedure LoWord(value) 
  ProcedureReturn value & $FFFF 
EndProcedure 
;
Procedure HiWord(value) 
  ProcedureReturn value >> 16 & $FFFF 
EndProcedure 
;
Procedure Quit_ELIG_StringGadget(ListIconhwnd)
  Protected ELIGRef       = GetDlgCtrlID_(ListIconhwnd)
  Protected hGLIGEdit     = GetProp_(ListIconhwnd, "hGLIGEdit")
  Protected CurItemELIG   = GetProp_(ListIconhwnd, "CurItemELIG")
  Protected CurColumnELIG = GetProp_(ListIconhwnd, "CurColumnELIG")
  Protected OldGL         = GetProp_(ListIconhwnd, "OldGL")
  ;
  Protected Old_SubClass_ELIG_StringGadget
  Protected memTxELIG$,NewTxELIG$
  ;
  If hGLIGEdit And IsGadget(hGLIGEdit)
    memTxELIG$ = GetGadgetItemText(ELIGRef, CurItemELIG, CurColumnELIG) ; ListIconGadget
    NewTxELIG$ = GetGadgetText(hGLIGEdit)                               ; StringGadget provisoire
    ;
    Old_SubClass_ELIG_StringGadget = GetProp_(GadgetID(hGLIGEdit), "Old_SubClass_ELIG_StringGadget")
    SetWindowLong_(GadgetID(hGLIGEdit), #GWL_WNDPROC, Old_SubClass_ELIG_StringGadget)
    RemoveProp_(GadgetID(hGLIGEdit), "Old_SubClass_ELIG_StringGadget")
    RemoveProp_(GadgetID(hGLIGEdit), "ListIconhwnd")
    FreeGadget(hGLIGEdit)
    SetProp_(ListIconhwnd, "hGLIGEdit", 0)
    UseGadgetList(OldGL)
    ;
    If NewTxELIG$ <> memTxELIG$
      SetGadgetItemText(ELIGRef, CurItemELIG, NewTxELIG$, CurColumnELIG)
    EndIf
  EndIf
EndProcedure
;
Procedure SubClass_ELIG_StringGadget(hwnd, uMsg, wParam, lParam)
  Protected ListIconhwnd                   = GetProp_(hwnd, "ListIconhwnd")
  Protected Old_SubClass_ELIG_StringGadget = GetProp_(hwnd, "Old_SubClass_ELIG_StringGadget")
  Protected Result
  ;
  Result = CallWindowProc_(Old_SubClass_ELIG_StringGadget, hwnd, uMsg, wParam, lParam)
  If (uMsg = #WM_KEYDOWN And wParam=#VK_RETURN) Or uMsg = #WM_KILLFOCUS 
    Quit_ELIG_StringGadget(ListIconhwnd) 
  EndIf
  ProcedureReturn Result
EndProcedure
;
Procedure SubClass_ELIG(hwnd, uMsg, wParam, lParam)
  Protected old_SubClass_ELIG = GetProp_(hwnd, "old_SubClass_ELIG")
  Protected ListOfEditableColumnsELIG = GetProp_(hwnd, "ListOfEditableColumnsELIG")
  Protected ELIGRef           = GetDlgCtrlID_(hwnd)
  Protected result, memTopElig, nbselect, ct, DecalGauche
  Protected pInfo.LVHITTESTINFO , rc.RECT, lvi.LV_ITEM
  Protected TxELIG$
  Protected CurItemELIG, CurColumnELIG, hGLIGEdit, Old_SubClass_ELIG_StringGadget
  ;
  result = 0
  ;
  Select uMsg
      
    Case #WM_DESTROY
      Quit_ELIG_StringGadget(hwnd)
      RemoveProp_(hwnd, "old_SubClass_ELIG")
      SetWindowLong_(hwnd, #GWL_WNDPROC, old_SubClass_ELIG)
      RemoveProp_(hwnd, "hGLIGEdit")
      RemoveProp_(hwnd, "OldGL")
      RemoveProp_(hwnd, "CurItemELIG")
      RemoveProp_(hwnd, "CurColumnELIG")
      RemoveProp_(hwnd, "ListOfEditableColumnsELIG")
      result = CallWindowProc_(old_SubClass_ELIG, hwnd, uMsg, wParam, lParam)
  
    Case #WM_VSCROLL,#WM_HSCROLL,#WM_LBUTTONDBLCLK,#WM_RBUTTONDBLCLK
      Quit_ELIG_StringGadget(hwnd)
      result = CallWindowProc_(old_SubClass_ELIG, hwnd, uMsg, wParam, lParam)
      ;
    Case #WM_LBUTTONDOWN
      memTopElig = GetGadgetState(ELIGRef)
      result = CallWindowProc_(old_SubClass_ELIG, hwnd, uMsg, wParam, lParam)
      nbselect = 0
      For ct = 0 To (CountGadgetItems(ELIGRef)-1)
        If GetGadgetItemState(ELIGRef, ct) = #PB_ListIcon_Selected
          nbselect + 1
        EndIf
      Next
      If memTopElig <> GetGadgetState(ELIGRef)
        Quit_ELIG_StringGadget(hwnd)
      EndIf
      If nbselect = 1
        pInfo\pt\x = LoWord(lParam) 
        pInfo\pt\y = HiWord(lParam)
        SendMessage_(hwnd, #LVM_SUBITEMHITTEST, 0, pInfo) 
        rc\top = pInfo\iSubItem
        rc\left = #LVIR_BOUNDS

        SendMessage_(hwnd, #LVM_GETSUBITEMRECT, pInfo\iItem, rc)

        CurItemELIG   = pInfo\iItem
        CurColumnELIG = pInfo\iSubItem
        ;
        SetProp_(hwnd, "CurItemELIG"  , CurItemELIG)
        SetProp_(hwnd, "CurColumnELIG", CurColumnELIG)

        If CurItemELIG>-1 And (ListOfEditableColumnsELIG = 0 Or Int(Pow(2,CurColumnELIG))&ListOfEditableColumnsELIG)
          TxELIG$ = GetGadgetItemText(ELIGRef, CurItemELIG, CurColumnELIG) 
          If CurColumnELIG=0 
            rc\right = rc\left+SendMessage_(hwnd, #LVM_GETCOLUMNWIDTH, 0, 0) 
          EndIf

          lvi\mask = #LVIF_IMAGE 
          lvi\iItem = CurItemELIG   
          SendMessage_(hwnd,#LVM_GETITEM,0,lvi) 
          If lvi\iImage
            DecalGauche = 20
          Else
            DecalGauche = 3
          EndIf
          OldGL = UseGadgetList(hwnd)
          SetProp_(hwnd, "OldGL", OldGL)
          hGLIGEdit= StringGadget(#PB_Any, rc\left+DecalGauche, rc\top-1, rc\right-rc\left-2-DecalGauche, rc\bottom-rc\top+2, TxELIG$)
          SetProp_(hwnd, "hGLIGEdit", hGLIGEdit)
          SendMessage_(GadgetID(hGLIGEdit),#EM_SETSEL,0,Len(TxELIG$)) 
          Old_SubClass_ELIG_StringGadget = SetWindowLong_(GadgetID(hGLIGEdit), #GWL_WNDPROC, @SubClass_ELIG_StringGadget())
          SetProp_(GadgetID(hGLIGEdit), "Old_SubClass_ELIG_StringGadget", Old_SubClass_ELIG_StringGadget)
          SetProp_(GadgetID(hGLIGEdit), "ListIconhwnd", hwnd)
          SetFocus_(GadgetID(hGLIGEdit))
        EndIf
      EndIf
      ;
    Default 
      result = CallWindowProc_(old_SubClass_ELIG, hwnd, uMsg, wParam, lParam)
  EndSelect
  
  ProcedureReturn result 
EndProcedure
;
Procedure SetEditableListIconGadgetColumns(GadgetNumber, EditableColumns$)
  Protected ct, BinaryResult
  For ct=1 To Len(EditableColumns$)
    If Mid(EditableColumns$,ct,1)="1"
      BinaryResult + Int(Pow(2,ct-1))
    EndIf
  Next
  SetProp_(GadgetID(GadgetNumber), "ListOfEditableColumnsELIG", BinaryResult)
EndProcedure
;
Procedure EditableListIconGadget(GadgetNumber, x, y, Width, Height, DefaultText$, FirstColumnWidth, Options=0)
  Protected Result, GadID, old_SubClass_ELIG
  ;
  result = ListIconGadget(GadgetNumber, x, y, Width, Height, DefaultText$, FirstColumnWidth, Options)
  ;
  If GadgetNumber = #PB_Any
    GadID = GadgetID(result)
  Else
    GadID = result
  EndIf
  ;
  old_SubClass_ELIG = SetWindowLong_(GadID, #GWL_WNDPROC, @SubClass_ELIG())
  SetProp_(GadID, "old_SubClass_ELIG", old_SubClass_ELIG)
  SetProp_(GadID, "hGLIGEdit", 0)
  SetProp_(GadID, "OldGL", 0)
  SetProp_(GadID, "CurItemELIG", 0)
  SetProp_(GadID, "CurColumnELIG", 0)
  SetProp_(GadID, "ListOfEditableColumnsELIG", 0)
   
  ProcedureReturn result
EndProcedure

User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: ListIcon Fast and Furiously editable [Resolved]

Post by Kwai chang caine »

Hello ZAPMAN :D

Thanks a lot for this nice code, furthermore i never see it since all this long years :shock:
I keep it preciously for my futur needs 8)

But my problem, is in the capacity of items in listicon :cry:
In fact, or i found a very fast listicon based on virtualListIcon (Splendid idea of my friend RASHAD 8) ) or i found spendid code too, like the one you just gave me, with editable cells simply like EXCEL, but if you enter 50 000 lines....you can drink a coffee and even wait until it's reached your bladder, and still be able to take the time to evacuate it :mrgreen:
The top of the top, it's an editable virtuallisticon

I take this opportunity to tell you that you impress me with your super powerful code :shock:
viewtopic.php?p=549264#p549264
And i'm proud someone like you take time for help me :oops:

Have a very good day MASTER 8)
ImageThe happiness is a road...
Not a destination
User avatar
Lord
Addict
Addict
Posts: 900
Joined: Tue May 26, 2009 2:11 pm

Re: ListIcon Fast and Furiously editable [Resolved]

Post by Lord »

Hi KCC!

For Windows: Did you try
SendMessage_(GadgetID(ELIGRef),#WM_SETREDRAW,#FALSE,0)
before filling ListIconGadget and
SendMessage_(GadgetID(ELIGRef),#WM_SETREDRAW,#TRUE,0)
after the Gadget is filled?
Image
User avatar
Zapman
Enthusiast
Enthusiast
Posts: 205
Joined: Tue Jan 07, 2020 7:27 pm

Re: ListIcon Fast and Furiously editable [Resolved]

Post by Zapman »

Hi KCC,

It seems to me that code proposed in this topic :
viewtopic.php?f=12&t=54022
can be considered as what you call "a virtual listicon".

You should try "MyGrid_22Nov17.pbi" which you can find following the link on the first page of the subject. It's able to manage a table of 200000 lines very, very fastly.
:)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: ListIcon Fast and Furiously editable [Resolved]

Post by Kwai chang caine »

@LORD
Thanks, but even with if i desactivate the ListIcon during loading thousands lines, it's when even less fast than virtualListIcon :wink:

@ZAPMAN
Thanks a lot ZAPMAN 8)
ImageThe happiness is a road...
Not a destination
Post Reply