Select cell in a ListIconGadget

Just starting out? Need help? Post your questions and find answers here.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Both 'problems' are just the obvious behaviour considering the lack of checks that you are putting in!

For the first problem why don't you simply add some checks for hitinfo\iItem and hitinfo\iSubItem equaling -1?

For the second problem... well, what do you expect? You can't add text to non-existent cells! Line 13, 14, 15... etc. do not actually exist! Either add some extra rows containing no text to begin with or, in the case that hitinfo\iItem = -1 but hitinfo\iSubItem >=0, add an extra row and then show the editing window etc.
I may look like a mule, but I'm not a complete ass.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Either add some extra rows containing no text to begin with or, in the case that hitinfo\iItem = -1 but hitinfo\iSubItem >=0, add an extra row and then show the editing window etc.
Thanks SROD, i try to do the two solution, and choose the more simple for me.

Thanks again for your help :D
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...

Post by srod »

No problem. :)
I may look like a mule, but I'm not a complete ass.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

After severals hours of reflexion and read the forum .....for added line automatiquely, if i clik on a empty cell.

I have modified the code :oops:
He works approximatively fine :roll:

Please, can you say to me, if it's good or if i must go to my bed :lol:

Thank you

PS: i have added the comment "; Line added" on the line modified :wink:

Code: Select all

#LVM_SUBITEMHITTEST = #LVM_FIRST + 57 
Global oldlist,lv 

Procedure.s GetNewText(item,subitem,xpos) 
  
  OpenWindow(1, xpos + 150,DesktopMouseY()+10,260,20,"",#PB_Window_BorderLess) 
  GetWindowRect_(WindowID(1), editrect.rect) 
  ClipCursor_(editrect) 
  CreateGadgetList(WindowID(1)) 
  StringGadget(1,0,0,190,20,"") 
  ButtonGadget(2,190,0,30,20,"OK") 
  ButtonGadget(3,220,0,40,20,"Cancel") 
  SetActiveGadget(1) 
  AddKeyboardShortcut(1,#PB_Shortcut_Return,1) 
  SetGadgetItemColor(0,item,#PB_Gadget_BackColor,RGB(200,200,200),subitem) 
  quit=0 
  
  Repeat 
    ev=WaitWindowEvent() 
      If EventWindow()=1 
      Select ev 
        Case #PB_Event_Menu 
          If EventMenu()=1 
            SetGadgetItemText(0,item,GetGadgetText(1),SubItem) 
            CloseWindow(1) 
            quit = 1 
          EndIf 
        Case #PB_Event_Gadget 
          If EventGadget()=2 
            SetGadgetItemText(0,item,GetGadgetText(1),SubItem) 
            CloseWindow(1) 
            quit = 1      
          ElseIf EventGadget() = 3 
            CloseWindow(1) 
            quit = 1    
          EndIf 
      EndSelect 
   EndIf    
  Until quit 
  
  SetGadgetItemColor(0,item,#PB_Gadget_BackColor,#White,subitem) 
  
  ClipCursor_(0) 
EndProcedure 

Procedure SubClass_LV(hwnd, msg, wparam, lparam) 

 Result = CallWindowProc_(oldlist, hwnd, msg, wparam, lparam) 
  
 If Msg = #WM_RBUTTONDOWN 
  HitInfo.LVHITTESTINFO 
  Hitinfo\pt\x = lparam & $ffff 
  HitInfo\pt\y = lparam >> 16&$ffff 
  SendMessage_(lv, #LVM_SUBITEMHITTEST, 0, @HitInfo) 
  
  If hitinfo\iItem <> - 1 ; Line added
  
   GetNewText(hitinfo\iItem, hitinfo\iSubItem, Hitinfo\pt\x) 
  
  Else ; Line added
   
   Repeat ; Line added
        
    ; Calcul de la hauteur d'une ligne
    lrc.RECT ; Line added
    lrc\left = #LVIR_LABEL ; Line added
    SendMessage_(GadgetID(0), #LVM_GETITEMRECT, 1, lrc) ; Line added
    TotalLignes = (lrc\bottom - lrc\top) * CountGadgetItems(0) ; Line added
    Y = lparam >> 16&$ffff; Line added
     
    If Y < TotalLignes ; Line added
     Break ; Line added
    EndIf ; Line added
     
    AddGadgetItem(0, -1, "") ; Line added
  
   ForEver ; Line added
  EndIf ; Line added
 EndIf 
  
 ProcedureReturn result 
  
EndProcedure 

OpenWindow(0,0,0,640,480,"ListIcon Gadget Mischief: Edit Selected Item",$CF0001) 
CreateGadgetList(WindowID(0)) 
lv = ListIconGadget(0,0,100,640,280,"",0,#PB_ListIcon_GridLines) 
AddGadgetColumn(0,1,"Column 1",210) 
AddGadgetColumn(0,2,"Column 2",210) 
AddGadgetColumn(0,3,"Column 3",215) 

For i = 1 To 12 
  linestr.s = LSet(Str(i),3," ") 
  AddGadgetItem(0, -1, Chr(10)+"Text on Line "+linestr+" in Column 1"+Chr(10)+"Text on Line "+linestr+" in Column 2"+Chr(10)+"Text on Line "+linestr+" in Column 3") 
Next 
  
oldlist=SetWindowLong_(lv, #GWL_WNDPROC, @SubClass_LV()) 

Repeat 
  ev = WaitWindowEvent() 
Until ev=#WM_CLOSE 
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

I have fixed the bug that i'm forced to click two times for do appears the newtext.
Like usualy, i'm happy to have your help if you see an error :D

Code: Select all

#LVM_SUBITEMHITTEST = #LVM_FIRST + 57 
Global oldlist,lv 

Procedure.s GetNewText(item,subitem,xpos) 
  
  OpenWindow(1, xpos + 150,DesktopMouseY()+10,260,20,"",#PB_Window_BorderLess) 
  GetWindowRect_(WindowID(1), editrect.rect) 
  ClipCursor_(editrect) 
  CreateGadgetList(WindowID(1)) 
  StringGadget(1,0,0,190,20,"") 
  ButtonGadget(2,190,0,30,20,"OK") 
  ButtonGadget(3,220,0,40,20,"Cancel") 
  SetActiveGadget(1) 
  AddKeyboardShortcut(1,#PB_Shortcut_Return,1) 
  SetGadgetItemColor(0,item,#PB_Gadget_BackColor,RGB(200,200,200),subitem) 
  quit=0 
  
  Repeat 
    ev=WaitWindowEvent() 
      If EventWindow()=1 
      Select ev 
        Case #PB_Event_Menu 
          If EventMenu()=1 
            SetGadgetItemText(0,item,GetGadgetText(1),SubItem) 
            CloseWindow(1) 
            quit = 1 
          EndIf 
        Case #PB_Event_Gadget 
          If EventGadget()=2 
            SetGadgetItemText(0,item,GetGadgetText(1),SubItem) 
            CloseWindow(1) 
            quit = 1      
          ElseIf EventGadget() = 3 
            CloseWindow(1) 
            quit = 1    
          EndIf 
      EndSelect 
   EndIf    
  Until quit 
  
  SetGadgetItemColor(0,item,#PB_Gadget_BackColor,#White,subitem) 
  
  ClipCursor_(0) 
EndProcedure 

Procedure SubClass_LV(hwnd, msg, wparam, lparam) 

 Result = CallWindowProc_(oldlist, hwnd, msg, wparam, lparam) 
  
 If Msg = #WM_RBUTTONDOWN 
  HitInfo.LVHITTESTINFO 
  Hitinfo\pt\x = lparam & $ffff 
  HitInfo\pt\y = lparam >> 16&$ffff 
  SendMessage_(lv, #LVM_SUBITEMHITTEST, 0, @HitInfo) 
  
  If hitinfo\iItem <> - 1 ; Line added 
  
   GetNewText(hitinfo\iItem, hitinfo\iSubItem, Hitinfo\pt\x) 
  
  Else ; Line added 
    
   Repeat ; Line added 
        
    ; Calcul de la hauteur d'une ligne 
    lrc.RECT ; Line added 
    lrc\left = #LVIR_LABEL ; Line added 
    SendMessage_(GadgetID(0), #LVM_GETITEMRECT, 1, lrc) ; Line added 
    TotalLignes = (lrc\bottom - lrc\top) * CountGadgetItems(0) ; Line added 
    Y = lparam >> 16&$ffff; Line added 
      
    If Y < TotalLignes ; Line added 
     SendMessage_(lv, #LVM_SUBITEMHITTEST, 0, @HitInfo) ; Line added 
     GetNewText(hitinfo\iItem, hitinfo\iSubItem, Hitinfo\pt\x)  ; Line added 
     Break ; Line added 
    EndIf ; Line added 
      
    AddGadgetItem(0, -1, "") ; Line added 
  
   ForEver ; Line added 
  EndIf ; Line added 
 EndIf 
  
 ProcedureReturn result 
  
EndProcedure 

OpenWindow(0,0,0,640,480,"ListIcon Gadget Mischief: Edit Selected Item",$CF0001) 
CreateGadgetList(WindowID(0)) 
lv = ListIconGadget(0,0,100,640,280,"",0,#PB_ListIcon_GridLines) 
AddGadgetColumn(0,1,"Column 1",210) 
AddGadgetColumn(0,2,"Column 2",210) 
AddGadgetColumn(0,3,"Column 3",215) 

For i = 1 To 12 
  linestr.s = LSet(Str(i),3," ") 
  AddGadgetItem(0, -1, Chr(10)+"Text on Line "+linestr+" in Column 1"+Chr(10)+"Text on Line "+linestr+" in Column 2"+Chr(10)+"Text on Line "+linestr+" in Column 3") 
Next 
  
oldlist=SetWindowLong_(lv, #GWL_WNDPROC, @SubClass_LV()) 

Repeat 
  ev = WaitWindowEvent() 
Until ev=#WM_CLOSE 
ImageThe happiness is a road...
Not a destination
Post Reply