1. ListView sort problem
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> May 10, 2005
- 482 views
Hi, I'm trying to implement ListView column sorting in Arwen. The call back is called the predicted number of times, and the third parameter is as expected, however the first two parameters are ALWAYS both zero! What is going on?
without warning include arwen.ew constant DEMO = create(Window,"ListViews in ARWEN", 0, 0,10,10,520,350,0) constant LIST1 = create(ListView, {{"a",50,0},{"b",30,0}}, 0, DEMO,10, 25, 405, 160, LVS_REPORT) void = insertLVItems(LIST1, {{"b",3},{"c",1},{"a",2}}) function LVsort(atom a, atom b, atom lParam) ?{a,b,lParam} --<<< ALWAYS {0,0,2} <<<<<< return rand(3)-2 end function function handler_LISTS(integer id, integer msg, object wParam, object lParam) if id = LIST1 then and msg = WM_COMMAND then if wParam = LVN_COLUMNCLICK then void=sendMessage(LIST1,LVM_SORTITEMS,LIST1,call_back(routine_id("LVsort"))) end if end if return 0 end function setHandler( LIST1, routine_id("handler_LISTS") ) WinMain(DEMO, SW_NORMAL)
Pete
2. Re: ListView sort problem
- Posted by Derek Parnell <ddparnell at bigpond.com> May 11, 2005
- 499 views
Pete Lomax wrote: > > Hi, > I'm trying to implement ListView column sorting in Arwen. The call > back is called the predicted number of times, and the third parameter > is as expected, however the first two parameters are ALWAYS both zero! > What is going on? > > }}} <eucode> > without warning > include arwen.ew > constant DEMO = create(Window,"ListViews in ARWEN", 0, > 0,10,10,520,350,0) > constant LIST1 = create(ListView, {{"a",50,0},{"b",30,0}}, 0, > DEMO,10, 25, 405, 160, LVS_REPORT) > void = insertLVItems(LIST1, {{"b",3},{"c",1},{"a",2}}) > > function LVsort(atom a, atom b, atom lParam) > ?{a,b,lParam} --<<< ALWAYS {0,0,2} <<<<<< > return rand(3)-2 > end function > > function handler_LISTS(integer id, integer msg, object wParam, object > lParam) > if id = LIST1 then and msg = WM_COMMAND then > if wParam = LVN_COLUMNCLICK then > > void=sendMessage(LIST1,LVM_SORTITEMS,LIST1,call_back(routine_id("LVsort"))) > end if > end if > return 0 > > end function > setHandler( LIST1, routine_id("handler_LISTS") ) > WinMain(DEMO, SW_NORMAL) > </eucode> {{{ > > Pete To quote the Microsoft documentation ... ---------------------- The comparison function has the following form: int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort); The lParam1 parameter is the value associated with the first item being compared, and the lParam2 parameter is the value associated with the second item. These are the values that were specified in the lParam member of the items' LVITEM structure when they were inserted into the list. The ListView_SortItems's lParamSort parameter is passed to the callback function as its third parameter. The comparison function must return a negative value if the first item should precede the second, a positive value if the first item should follow the second, or zero if the two items are equivalent. Note During the sorting process, the list-view contents are unstable. If the callback function sends any messages to the list-view control aside from LVM_GETITEM (ListView_GetItem), the results are unpredictable. ---------------------- So what is the lParam field of the LVITEM structure set to at the time you insert the list item? If you examine the code in win32lib you will see that I ensure that each item inserted into a ListView has a unique lParam value. Then when the callback function gets called, I use the parameters passed to it, to find the ListView items based on the lParam value. Then I compare the data in the items. The routines to look at in win32lib are ... insertLVItem() getLVItemlParam() PrepareLVSort() -- Derek Parnell Melbourne, Australia irc://irc.sorcery.net:9000/euphoria
3. Re: ListView sort problem
- Posted by Al Getz <Xaxo at aol.com> May 11, 2005
- 473 views
Pete Lomax wrote: > > Hi, > I'm trying to implement ListView column sorting in Arwen. The call > back is called the predicted number of times, and the third parameter > is as expected, however the first two parameters are ALWAYS both zero! > What is going on? > > }}} <eucode> > without warning > include arwen.ew > constant DEMO = create(Window,"ListViews in ARWEN", 0, > 0,10,10,520,350,0) > constant LIST1 = create(ListView, {{"a",50,0},{"b",30,0}}, 0, > DEMO,10, 25, 405, 160, LVS_REPORT) > void = insertLVItems(LIST1, {{"b",3},{"c",1},{"a",2}}) > > function LVsort(atom a, atom b, atom lParam) > ?{a,b,lParam} --<<< ALWAYS {0,0,2} <<<<<< > return rand(3)-2 > end function > > function handler_LISTS(integer id, integer msg, object wParam, object > lParam) > if id = LIST1 then and msg = WM_COMMAND then > if wParam = LVN_COLUMNCLICK then > > void=sendMessage(LIST1,LVM_SORTITEMS,LIST1,call_back(routine_id("LVsort"))) > end if > end if > return 0 > > end function > setHandler( LIST1, routine_id("handler_LISTS") ) > WinMain(DEMO, SW_NORMAL) > </eucode> {{{ > > Pete > > Hi Pete, Explain this: constant LIST1 = create(ListView, {{"a",50,0},{"b",30,0}}, 0, DEMO,10, 25, 405, 160, LVS_REPORT) Does that create two col's and what does this do: void = insertLVItems(LIST1, {{"b",3},{"c",1},{"a",2}}) Im wondering if there is enough data in the list view to operate on. Take care, Al And, good luck with your Euphoria programming! My bumper sticker: "I brake for LED's"
4. Re: ListView sort problem
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> May 11, 2005
- 483 views
On Tue, 10 May 2005 17:03:14 -0700, Derek Parnell <guest at RapidEuphoria.com> wrote: <snip> >So what is the lParam field of the LVITEM structure set to at the time >you insert the list item? If you examine the code in win32lib you will >see that I ensure that each item inserted into a ListView has a unique >lParam value. Thanks, that pointed me in the right direction. The main thing I was missing was the LVITEM_lParam bit in LVITEM_mask. Regards, Pete
5. Re: ListView sort problem
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> May 11, 2005
- 469 views
On Tue, 10 May 2005 23:24:26 -0700, Al Getz <guest at RapidEuphoria.com> wrote: >Hi Pete, Hi > >Explain this: > constant LIST1 = create(ListView, {{"a",50,0},{"b",30,0}}, 0, > DEMO,10, 25, 405, 160, LVS_REPORT) > >Does that create two col's Yes > and what does this do: > void = insertLVItems(LIST1, {{"b",3},{"c",1},{"a",2}}) Creates three rows > >Im wondering if there is enough data in the list view to operate on. Erm, don't play with ListViews in Arwen yet, they are in a very early state ) I'm only planning something basic anyway. Regards, Pete
6. Re: ListView sort problem
- Posted by Al Getz <Xaxo at aol.com> May 11, 2005
- 491 views
Hi Pete, Funny, i cant get mine to sort in Report View at all. Keeps returning all zeros as in your first example. Now that i think about it, what is it that it is trying to sort anyway, when the sort sendmessage is called? How can it know what column you want sorted... i must be missing something here... Take care, Al And, good luck with your Euphoria programming! My bumper sticker: "I brake for LED's"
7. Re: ListView sort problem
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> May 11, 2005
- 490 views
- Last edited May 12, 2005
On Wed, 11 May 2005 03:52:08 -0700, Al Getz <guest at RapidEuphoria.com> wrote: >Hi Pete, > >Funny, i cant get mine to sort in Report View at all. That's what I just said )! (BTW, I'm only attempting report view anyway; what happens in LVS_[SMALL]ICON & LVS_LIST modes does not concern me) >Keeps returning all zeros as in your first example. Yes, have you set the LVIF_PARAM bit in LVITEM_mask? You probably don't have the code to set LVITEM_lParam either. If not, don't worry about it, show a bit or patience and, I'll release a working version in a few days. I think I have all the info I now need, it was not setting the LVIF_PARAM bit that really stumped me. >Now that i think about it, what is it that it is trying >to sort anyway, when the sort sendmessage is called? >How can it know what column you want sorted... >i must be missing something here... That one happens to be: SortColumn=peek4s(lParam+NMLISTVIEW_iSubItem) Leave this with me a couple of days, OK? Regards, Pete
8. Re: ListView sort problem
- Posted by Al Getz <Xaxo at aol.com> May 12, 2005
- 474 views
Pete Lomax wrote: > > On Wed, 11 May 2005 03:52:08 -0700, Al Getz <guest at RapidEuphoria.com> > wrote: > > >Hi Pete, > > > >Funny, i cant get mine to sort in Report View at all. > That's what I just said )! > (BTW, I'm only attempting report view anyway; what happens in > LVS_[SMALL]ICON & LVS_LIST modes does not concern me) > >Keeps returning all zeros as in your first example. > Yes, have you set the LVIF_PARAM bit in LVITEM_mask? > You probably don't have the code to set LVITEM_lParam either. > If not, don't worry about it, show a bit or patience and, I'll release > a working version in a few days. I think I have all the info I now > need, it was not setting the LVIF_PARAM bit that really stumped me. > >Now that i think about it, what is it that it is trying > >to sort anyway, when the sort sendmessage is called? > >How can it know what column you want sorted... > >i must be missing something here... > That one happens to be: > SortColumn=peek4s(lParam+NMLISTVIEW_iSubItem) > > Leave this with me a couple of days, OK? > > Regards, > Pete > > Hi Pete, OH ok sure...hope you make some progress. I tried a few things so far including the PARAM bit setting, and assigning a unique id number to each subitem, but still got all zeros. This is probably my mistake, as i think the callback function is trying to convey two ROWS per call, so that you may use your lParam to tell your callback to sort according to THAT column, but so far im unable to get the callback to convey that information. Oh the other hand, im starting to think it might be easier just to get the data and sort using raw Euphoria, rather than depending on the system sort mechanics, because each call to the sort callback will eventually mean retrieving the text anyway, in order to make the required compare decision, and from what i've read the Listview control doesnt actually change the order of the rows anyway so each row has to be re-entered (?). It's interesting that in other programs that i use a Listview in i never had to sort the items at a later date, but of course i can see it would be very useful. There's also the autosort mode for listview, but that doesnt allow a callback hence you cant sort according to how you wish...which bites Take care, Al And, good luck with your Euphoria programming! My bumper sticker: "I brake for LED's"
9. Re: ListView sort problem
- Posted by Al Getz <Xaxo at aol.com> May 12, 2005
- 465 views
Hi again Pete, Ok, i got mine to work, and i found that the rows do indeed actually change (sort) according to the callback function so you dont have to reload everything into the listview (doc's must be wrong or else i read it wrong ) Anyway, the mistake i was making was in assigning unique id's to the lParam (user value) when i created (added) the *subitems*, which does basically nothing he he. By instead assigning unique id's when the row itself is created (*item*, not *subitem*) the callback function does indeed receive the correct numbers that refer to the rows when the lParam values are simply made equal to the row numbers when each row is created. By passing the column number to the callback function it should be no problem looking up the text and returning a comparison result for each row subitem in that column alone. In my lib this looks like this: retv=win:IDSendMessage(ListID,LVM_INSERTITEM,0,LV_ITEM) where the LV_ITEM is the struct and the members set are the text and the lParam (user) value, and lParam is simply set to the row number, which of course requires the mask set with LVIF values of text and param as mentioned. Take care, Al And, good luck with your Euphoria programming! My bumper sticker: "I brake for LED's"
10. Re: ListView sort problem
- Posted by Mario Steele <eumario at trilake.net> May 12, 2005
- 471 views
Pete Lomax wrote: > > On Wed, 11 May 2005 03:52:08 -0700, Al Getz <guest at RapidEuphoria.com> > wrote: > > >Hi Pete, > > > >Funny, i cant get mine to sort in Report View at all. > That's what I just said )! > (BTW, I'm only attempting report view anyway; what happens in > LVS_[SMALL]ICON & LVS_LIST modes does not concern me) > >Keeps returning all zeros as in your first example. > Yes, have you set the LVIF_PARAM bit in LVITEM_mask? > You probably don't have the code to set LVITEM_lParam either. > If not, don't worry about it, show a bit or patience and, I'll release > a working version in a few days. I think I have all the info I now > need, it was not setting the LVIF_PARAM bit that really stumped me. > >Now that i think about it, what is it that it is trying > >to sort anyway, when the sort sendmessage is called? > >How can it know what column you want sorted... > >i must be missing something here... > That one happens to be: > SortColumn=peek4s(lParam+NMLISTVIEW_iSubItem) > > Leave this with me a couple of days, OK? > > Regards, > Pete He He he, I just thought I'd throw in my two cents here. Cause I mean, we're talking about trying to fetch the String that is stored in the list view, to make our comparison, correct? Well, just for kicks and giggles, why not assign LVITEM_lParam a Memory location to the string that's being used? That way, in your sort function, all you have to do, is peek() the memory location in the two lParam's from the LVITEM_lParams, to see where to move it. Just quirky that way I guess. As far as I'm concerned, the LVITEM_lParam can be anything, so you could legally assign a Memory Location that holds the String into it. Mario Steele http://enchantedblade.trilake.net Attaining World Dominiation, one byte at a time...
11. Re: ListView sort problem
- Posted by Al Getz <Xaxo at aol.com> May 12, 2005
- 482 views
Mario Steele wrote: > > He He he, I just thought I'd throw in my two cents here. Cause I mean, > we're talking about trying to fetch the String that is stored in the > list view, to make our comparison, correct? > > Well, just for kicks and giggles, why not assign LVITEM_lParam a Memory > location to the string that's being used? That way, in your sort function, > all you have to do, is peek() the memory location in the two lParam's from > the LVITEM_lParams, to see where to move it. Just quirky that way I guess. > > As far as I'm concerned, the LVITEM_lParam can be anything, so you could > legally assign a Memory Location that holds the String into it. > > Mario Steele > <a > href="http://enchantedblade.trilake.net">http://enchantedblade.trilake.net</a> > Attaining World Dominiation, one byte at a time... > Hi Mario, That's not a bad idea, but in the case of the Report View i think it would be rare to find a row containing only one string, so you'd probably end up making lParam a double pointer, where it pointed to an array of pointers that point to each column item. On the other hand, if you're already storing the text in a sequence perhaps you can simply look up the row and column something like this: ItemText1=Data[row1][col] ItemText2=Data[row2][col] where 'col' is passed via your sort function call message, and 'row1' and 'row2' are passed from the system to the callback. Take care, Al And, good luck with your Euphoria programming! My bumper sticker: "I brake for LED's"
12. Re: ListView sort problem
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> May 12, 2005
- 469 views
On Wed, 11 May 2005 20:08:11 -0700, Al Getz <guest at RapidEuphoria.com> wrote: >Hi again Pete, > >Ok, i got mine to work, Ditto >and i found that the rows do indeed actually >change (sort) according to the callback function so you dont have to >reload everything into the listview (doc's must be wrong or else i >read it wrong ) An easy thing to do ) > >Anyway, the mistake i was making was in assigning unique id's to the >lParam (user value) when i created (added) the *subitems*, which does >basically nothing he he. By instead assigning unique id's when the >row itself is created (*item*, not *subitem*) the callback function does >indeed receive the correct numbers that refer to the rows when the >lParam values are simply made equal to the row numbers when each row >is created. Yep >By passing the column number to the callback function >it should be no problem looking up the text and returning a comparison >result for each row subitem in that column alone. I poke the column number into the static LV_ITEM structure that the callback will be using, however... I just stumbled into something interesting: fastLV.exw in the win32lib demo folder, which stores/sorts the data in an Eu table. Unless I am missing something, the fastLV.exw approach is far better than using the windows API. As far as I can tell, fastLV.exw can be simplified even further: there are 7 lines between custom_sort and LVM_UPDATE which I think can be completely removed. Regards, Pete
13. Re: ListView sort problem
- Posted by Al Getz <Xaxo at aol.com> May 12, 2005
- 469 views
Pete Lomax wrote: > > On Wed, 11 May 2005 20:08:11 -0700, Al Getz <guest at RapidEuphoria.com> > wrote: > > >Hi again Pete, > > > >Ok, i got mine to work, > Ditto > >and i found that the rows do indeed actually > >change (sort) according to the callback function so you dont have to > >reload everything into the listview (doc's must be wrong or else i > >read it wrong ) > An easy thing to do ) > > > >Anyway, the mistake i was making was in assigning unique id's to the > >lParam (user value) when i created (added) the *subitems*, which does > >basically nothing he he. By instead assigning unique id's when the > >row itself is created (*item*, not *subitem*) the callback function does > >indeed receive the correct numbers that refer to the rows when the > >lParam values are simply made equal to the row numbers when each row > >is created. > Yep > >By passing the column number to the callback function > >it should be no problem looking up the text and returning a comparison > >result for each row subitem in that column alone. > I poke the column number into the static LV_ITEM structure that the > callback will be using, however... > > I just stumbled into something interesting: fastLV.exw in the win32lib > demo folder, which stores/sorts the data in an Eu table. Unless I am > missing something, the fastLV.exw approach is far better than using > the windows API. > > As far as I can tell, fastLV.exw can be simplified even further: there > are 7 lines between custom_sort and LVM_UPDATE which I think can be > completely removed. > > Regards, > Pete > > Hi Pete, I'll have to take a look at it. Is it by any chance using the mode where the application stores the data, not the Listview? Im not sure if i want to do that with mine or not. I might just settle for getting the item data per callback call. Where's this demo hiding...i'll take a look... Take care, Al And, good luck with your Euphoria programming! My bumper sticker: "I brake for LED's"
14. Re: ListView sort problem
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> May 13, 2005
- 468 views
On Thu, 12 May 2005 10:12:45 -0700, Al Getz <guest at RapidEuphoria.com> wrote: >Hi Pete, > >I'll have to take a look at it. Is it by any chance using the mode >where the application stores the data, not the Listview? Yes > >Im not sure if i want to do that with mine or not. I might just >settle for getting the item data per callback call. Experiment with it before making an uninformed decision. > >Where's this demo hiding...i'll take a look... I've put my existing code and fastLV.exw up on my web page: http://palacebuilders.pwp.blueyonder.co.uk/edita.htm It's all trivial stuff, really, but from acorns great oaks grow... Regards, Pete
15. Re: ListView sort problem
- Posted by Al Getz <Xaxo at aol.com> May 13, 2005
- 472 views
Pete Lomax wrote: > > On Thu, 12 May 2005 10:12:45 -0700, Al Getz <guest at RapidEuphoria.com> > wrote: > > >Hi Pete, > > > >I'll have to take a look at it. Is it by any chance using the mode > >where the application stores the data, not the Listview? > Yes > Regards, > Pete > Hi again Pete, Ok, then i have to ask a question... Does your Listview wrapping save *each* LV_ITEM structure for every subitem so that the notification simply looks up the LV_ITEM and passes it through the dispatch structure, or... does it lookup the text in a sequence and then create a new LV_ITEM for the dispatch structure? Take care, Al And, good luck with your Euphoria programming! My bumper sticker: "I brake for LED's"
16. Re: ListView sort problem
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> May 13, 2005
- 476 views
On Fri, 13 May 2005 04:49:34 -0700, Al Getz <guest at RapidEuphoria.com> wrote: >> >I'll have to take a look at it. Is it by any chance using the mode >> >where the application stores the data, not the Listview? >> Yes >Hi again Pete, > >Ok, then i have to ask a question... > >Does your Listview wrapping save *each* LV_ITEM structure for every >subitem so that the notification simply looks up the LV_ITEM and >passes it through the dispatch structure, or... >does it lookup the text in a sequence and then create a new LV_ITEM >for the dispatch structure? As I understand it, using LVS_OWNERDATA, causes windows to send 85 LVN_GETDISPINFO messages to display 17 rows of 5 columns, each of which I respond to using 4 peeks and one poke, which is a negligible overhead for a screen update. The benefit is that the sort op is one LVN_COLUMNCLICK message, which I respond to using just one peek, an RDS sort, and one LVM_UPDATE message. Another benefit is that it takes approximately 0.0 seconds to load and display the listview. The only LV_ITEM anywhere in sight is the one windows supplies for me to fill in, (85 times per screen) I've migrated the fastlv.exw from win32lib to arwen and included it on my web page, along with the latest arwen mods: http://palacebuilders.pwp.blueyonder.co.uk/edita.htm#misc It is easily over 100 times faster than my demo_lists.exw (also included) when sorting 5000 records, as that does over 200,000 peeks and pokes within the compare function of the sort, along with 135,000 sendMessage calls to retrieve the Listview data from windows, kinda puts 425 peeks&pokes into perspective. ) Regards Pete
17. Re: ListView sort problem
- Posted by Al Getz <Xaxo at aol.com> May 14, 2005
- 465 views
Hi again Pete, Sounds good, so i'll eventually have to change my basic Listview to handle ownerdata too i guess. Now that i think about it, sometimes it would be useful to have a col sort mechanism in my checking acct program to sort according to date, but then i guess other sorts of sorts would be interesting too Take care, Al And, good luck with your Euphoria programming! My bumper sticker: "I brake for LED's"
18. Re: ListView sort problem
- Posted by Al Getz <Xaxo at aol.com> May 14, 2005
- 491 views
Hello again, I decided to give it a shot, and it turned out quite easy to modify my existing Listview class to an owner data type. I did a 'standard' sort of the sequence that holds the data in response to a col click, and that worked rather well too, but i had to use the REDRAW message instead of the UPDATE one in order to get everything in the Listview redrawn right there and then...without that all the old data still appeared in the LV at least until something 'physically' caused a redraw (such as an overlapping window moved aside). Interesting, in that it's probably simpler to implement this kind of listview rather than the type you have to send it all the items. Drawback is that it's going to take longer to repaint, but how much longer may not be a problem anyway, and that one way or another, you have to manage the data...which i havent decided what would be best yet...all app listviews in one big sequence or let the individual listviews handle their own sequences. Now that the sorting mechanism is in place, the next step is to implement some sort of sort alg where you can sort by any subsequence, instead of just the first one... data= { {1,"b"}, {2,"a"} } stays the same for a normal sort, but changes if sorting by the second 'column' of data, so... I guess the next step is to create an alg that sorts according to whatever col you wish. Take care, Al And, good luck with your Euphoria programming! My bumper sticker: "I brake for LED's"