Editing cells in ListIcons (updated for Vista)

Share your advanced PureBasic knowledge/code with the community.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Thanks, srod 8)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
nicksteel
User
User
Posts: 43
Joined: Sat Apr 24, 2004 5:20 pm
Location: Houston

Post by nicksteel »

Neat code :D :shock: :D

Is there any way to align the first displayed column to the start of the cell (like in Excel) when horizonal scrolling? So that the entire first cell is always shown?

and,

Is there any way to disable dragging the column?
Slow, but trying.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

nicksteel wrote:Neat code :D :shock: :D
Thanks.
Is there any way to align the first displayed column to the start of the cell (like in Excel) when horizonal scrolling? So that the entire first cell is always shown?
I've never tried this, but I reckon it can be done; albeit with quite a bit of work. You'll need to subclass the listicon and intercept the #WM_HSCROLL messages and process these yourself. You'll then need to send the #LVM_SCROLL message in order to scroll by the required amount etc. Yep, this will be very fiddly indeed, particularly when dealing with the user dragging the thumb etc.

With my egrid library (which uses listicons) I took control of the scrolling just to speed things up and reduce the flicker etc. so I went part of the way towards your goal. I also ensure that whenever the user selects a cell, that the egrid is scrolled just enough to ensure that the whole cell is visible. Again, this would be similar to what you are looking for, but not quite as fiddly.

To be honest though, I never really saw the need to constantly ensure that cells within the first visible column were completely visible.
...and,

Is there any way to disable dragging the column?
The first method would be to not enable column drag in the first place! :wink:

Alternatively, use

Code: Select all

#LVM_SETEXTENDEDLISTVIEWSTYLE = #LVM_FIRST+ $36
#LVS_EX_HEADERDRAGDROP = $10

SendMessage_(GadgetID(#ListIcon), #LVM_SETEXTENDEDLISTVIEWSTYLE, #LVS_EX_HEADERDRAGDROP,0)
I may look like a mule, but I'm not a complete ass.
nicksteel
User
User
Posts: 43
Joined: Sat Apr 24, 2004 5:20 pm
Location: Houston

Post by nicksteel »

Thanks, Master of Grids. :D You have attacked a real "hole" in PB!
The first method would be to not enable column drag in the first place!
How is it enabled in ListIcon?

Obviously I'll just buy Egrid if I need to write something serious and avoid all the headaches. Am having a learning experience at present, trying to understand PB's potential to solve my db needs.

Am just used to Clipper browse (non- windows of course) with its Excel like skipping column to column horizonal scrolling.

Your code is WAY over my head :shock: , but a lot of fun to play with and a good way of gaining knowledge. :D

Your efforts and patience are appreciated.
Slow, but trying.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Column drag in PB is enabled by including the syle #PB_ListIcon_HeaderDragDrop in the ListIconGadget() command.
I may look like a mule, but I'm not a complete ass.
nicksteel
User
User
Posts: 43
Joined: Sat Apr 24, 2004 5:20 pm
Location: Houston

Post by nicksteel »

srod wrote:Column drag in PB is enabled by including the syle #PB_ListIcon_HeaderDragDrop in the ListIconGadget() command.
Sorry, wasn't clear with my question. :oops:

I meant to ask about the disabling the ability to change the width of a column.
Slow, but trying.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Ah, are you talking about preventing the user from reordering columns by click and drag (in which case use the snippet above) or preventing the user from resizing columns by dragging the column divider?

In the latter case, look at the #HDN_BEGINTRACK, #HDN_BEGINTRACKW message handler in the code in my first post. This shows how to prevent the resizing.

However, this doesn't deal with the user double-clicking the divider and resizing the column that way. Even more difficult to control is the fact that Windows will continue to display the resizing cursor even when you've taken steps to prevent the columns from being resized.

Dealing with these last two problems requires that you subclass the header control which is attached to the listicon. I could possibly hack up an example for you, but it will take some time because I'm immensely busy right now.
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

In the spirit of not intruding upon srod's immense busyness (-wii?), here's how to prevent all resizing of a listicon header. Note that you can drill down into the structure to manage only specific header buttons with *nmHEADER\iItem if you desire. This example just locks the whole thing:

Code: Select all

Global oldproc

Procedure ListProc(hwnd, msg, wparam, lparam)
 Select msg 
   Case #WM_NOTIFY 
     *nmHEADER.HD_NOTIFY = lParam 
     Select *nmHEADER\hdr\code 
       Case #HDN_BEGINTRACKW, #HDN_DIVIDERDBLCLICKW 
         ProcedureReturn #True
     EndSelect 
 EndSelect
 ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
EndProcedure

OpenWindow(0,0,0,320,240,"Locked ListIcon Header",$CA0001)
CreateGadgetList(windowid(0))
ListIconGadget(0,0,0,320,240,"Col 0", 110)
AddGadgetColumn(0, 1, "Col 1", 100)
AddGadgetColumn(0, 2, "Col 2", 100)
oldproc = SetWindowLong_(GadgetID(0), #GWL_WNDPROC, @ListProc())
Repeat:Until waitwindowevent()=#WM_CLOSE
@Freak, if you see this, using 4.10b2, the waitwindowevent() never changed case
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Huh, I missed the #HDN_DIVIDERDBLCLICKW message! Bugger, that would have simplified egrid a little! :)

Still, no way around subclassing the header I reckon to prevent windows from displaying the sizing cursor!
I may look like a mule, but I'm not a complete ass.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

netmaestro wrote:@Freak, if you see this, using 4.10b2, the waitwindowevent() never changed case
Strange; it works here!
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Here we are then. A joint netmaestro/srod production:

Code: Select all

#LVM_GETHEADER = #LVM_FIRST+31


Global oldproc, gOldHeaderProc

Procedure ListProc(hwnd, msg, wparam, lparam) 
 Select msg 
   Case #WM_NOTIFY 
     *nmHEADER.HD_NOTIFY = lParam 
     Select *nmHEADER\hdr\code 
       Case #HDN_BEGINTRACKW, #HDN_DIVIDERDBLCLICKW 
         ProcedureReturn #True 
     EndSelect 
 EndSelect 
 ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam) 
EndProcedure 


Procedure headerproc(hwnd, msg, wparam, lparam) 
  Protected result
  Select msg 
    Case #WM_SETCURSOR
      result = 0
    Default
      result =CallWindowProc_(gOldHeaderProc, hwnd, msg, wparam, lparam) 
  EndSelect 
  ProcedureReturn result
EndProcedure 

OpenWindow(0,0,0,320,240,"Locked ListIcon Header",$CA0001) 
CreateGadgetList(WindowID(0)) 
ListIconGadget(0,0,0,320,240,"Col 0", 110) 

Global gOldHeaderProc = SetWindowLong_(SendMessage_(GadgetID(0),#LVM_GETHEADER,0,0), #GWL_WNDPROC, @headerproc())

AddGadgetColumn(0, 1, "Col 1", 100) 
AddGadgetColumn(0, 2, "Col 2", 100) 
oldproc = SetWindowLong_(GadgetID(0), #GWL_WNDPROC, @ListProc()) 
Repeat:Until WaitWindowEvent()=#WM_CLOSE 
This will need refining slightly if you only prevent certain columns from being resized but allows others to be sized etc.
Last edited by srod on Wed Jun 20, 2007 3:37 pm, edited 1 time in total.
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Ha, you beat me fair and square on that one, I was about two minutes away from posting that very solution!
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Netmaestro 9999 - srod 1.

:)
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Ok, but I only have 2897 posts - what did you say you teach again?
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Uhm, I teach Hungarian!

:wink:
I may look like a mule, but I'm not a complete ass.
Post Reply