A basic grid control (major revision)

Developed or developing a new product in PureBasic? Tell the world about it.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

A basic grid control (major revision)

Post by srod »

Hi all,

I've been playing around with some intriguing code posted by El-choni some time ago, and have hashed up a basic grid control based on a subclassed ListIconGadget.

I've decided to post the code at what is a very early stage of development in order that more experienced Windows coders might be able to give me some idea as to how far this code can go? Basically, this is approaching the limits of my knowledge of Win API at present and so I don't really know just how far this could be taken, let alone how far I could take it myself.

At the moment, the underlying ListIconGadget is created in the default report view with the default system fonts. Cells can be edited by double clicking. The control seems to behave itself whilst scrolling and whilst the user changes the column widths etc.

As I say, it is early days, but everyone is welcome to use the code in any way.

Regards.

http://www.purecoder.net/purebasic/egrid.zip
Last edited by srod on Fri Sep 30, 2005 8:37 pm, edited 3 times in total.
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Update:
  • - The grids now seem to work with different fonts and font sizes in that there is no misalignment (at least on my system) with the cell being edited etc. Cells are edited by overlaying a good old string gadget and the alignment of the underlying text and all the margins has caused me a few headaches. It now seems to work on my computer, but I am hoping that others might be able to test this on different Windows setups etc.

    -The enter key now acts as it should.
Once I'm happy that the aforementioned alignment issues are well and truly licked, then I will continue to develop the grid.

http://www.purecoder.net/purebasic/egrid.zip
I may look like a mule, but I'm not a complete ass.
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

thanks srod :D
but I think you still have work to do.
Image
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

The height of the header row is a superficial detail.

Can I ask what you did to end up with 2 edit boxes because I can't seem to recreate it?

Thanks.

**Edit: It seems to occur when the ListIcon gadget is scrolled by using the keyboard and thus avoiding the #WM_VCROLL event in the ListIcon callback. I'll try and fix it tonight. Thanks for reporting, as this one would probably have passed me by!**
I may look like a mule, but I'm not a complete ass.
LuckyLuke
Enthusiast
Enthusiast
Posts: 181
Joined: Fri Jun 06, 2003 2:41 pm
Location: Belgium

Post by LuckyLuke »

This might help :?:

Code: Select all

Procedure LV_SetHeaderFontStyle(id.l)
  LF.LOGFONT
  hHeader = SendMessage_(id, #LVM_GETHEADER, 0, 0)
  hCurrFont = SendMessage_(hHeader, #WM_GETFONT, 0, 0)
  If GetObject_(hCurrFont, SizeOf(LF), LF) > 0 
    LF\lfWeight = #FW_BOLD    ;#FW_NORMAL
    LF\lfUnderline = #True
    LF\lfItalic = #True    
    LF\lfStrikeOut = #False
    LF\lfHeight = 20
    DeleteObject_(hHeaderFont)
    hHeaderFont = CreateFontIndirect_(LF)
    hOldFont = SelectObject_(hHeader, hHeaderFont)
    SendMessage_(hHeader, #WM_SETFONT, hHeaderFont, #True)

  EndIf

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

Post by srod »

Thanks Lucky, I'll give that a whirl after I've fixed the keyboard scrolling prob.

Regards.
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

UPDATE:

After many long hours, the scrolling problems seem to be fixed and I cannot find any rendering problems at the moment (although I have only tested this software on Win XP home).

If I am correct and no one finds any bugs with the basic operation of the grid control, then the way is clear to add more of what I would call typical 'grid' functionality.

At the moment, the grid seems to work with any fontsize (I haven't adjusted the header row yet, but that's a minor detail). The grid allows editing in any cell and (fingers crossed) behaves well whilst the grid is scrolled (either using the mouse or the keyboard) or columns are resized etc.

If no bugs are found with the above, I will then set about the following:
  • tidying up the header row
    allowing for dynamic resizing of the entire grid
    use of arrow / tab keys to navigate the grid (at the moment they scroll the entire grid without navigating from cell to cell -this was a convenience)
    cutting and pasting
    etc.
Further ahead I will investigate the possibility of being able to select and highlight a range of cells using click and drag etc. and possibly even embedding other controls within individual cells, but that's a little way off yet.

Anyhow, any feedback/bug reports are greatly appreciated and my thanks to all who are able to test the grids.

Regards.

http://www.purecoder.net/purebasic/egrid.zip
I may look like a mule, but I'm not a complete ass.
ebs
Enthusiast
Enthusiast
Posts: 557
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

srod,

The updated grid works well, but I have found a problem. Try these steps:

1. Click in a cell to select it.

2. Click in the cell again to start editing it - you will see the caret flashing.

3. Scroll the grid up and down a few times using the mouse wheel, not the scroll bar.

4. I see a number of copies of the selected cell, on top of other cells.
If you click in one of the copies, it goes back to the original cell contents.

Can you (or anyone else) reproduce this behavior, or is it just a problem with my mouse or video drivers?

Regards,
Eric
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

other controls within individual cells, but that's a little way off yet.
:)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Ebs:

Thanks for the report. Unfortunately, I use a laptop and do not have a mouse wheel. The problem reported is the same that I experienced with the page up/down buttons however, and these were easily fixed. It could simply be a case of rummaging through the WIN API looking for some event I can trap for use of the mousewheel. If I am right, then it is literally 5 lines of code to repair. Unfortunately, however, I won't know if the problem is fixed until someone with a mouse wheel tests the code.

I'll have a look later tonight.

Thanks again.
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Doh!

***Double post!***
I may look like a mule, but I'm not a complete ass.
Jellybean
User
User
Posts: 95
Joined: Wed Aug 24, 2005 7:33 pm

Post by Jellybean »

Reproduced text field drawing problems when scolling with scrollwheel.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

***Fix***

Have added code (3 lines!) which I hope fixes the aforementioned problem. I am unable to check whether the fix works because I have no mousewheel.
If someone could be so kind...

http://www.purecoder.net/purebasic/egrid.zip

Thanks.
I may look like a mule, but I'm not a complete ass.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

I cannot see any graphic problems with the scroll wheel.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

Its fixed! Thanks for this nice code.!
Post Reply