1. [Win32lib] Listview speed

Hello Matt Lewis and all,

The (below) procedure is faster for loading Items into a listview
however, I havent figured out how I plan to sort the data using this
routine. I'll work on this some more tonight.

You also can not sort the listview using the current Win32lib sort
algorythm and this procedure, perhaps someone who knows the lib
better would do this. 

If your plans are to not allow sorting then this will be a better choice 
for speed. 

-- add to Win32lib 
global procedure LoadLVInfo(atom id, sequence alldata)
integer howmany
  handle = getHandle(id)
  howmany = length(alldata)
  for i = 1 to howmany do
     LV_ITEM = acquire_mem(0,  SIZEOF_LVITEM )
     store( LV_ITEM, LVITEM_mask, LVIF_TEXT )
     store( LV_ITEM, LVITEM_iItem, i-1)
     data = alldata(i)           
     subitem = 0 
     for x = 1 to length(data) do                  
        store( LV_ITEM, LVITEM_iSubItem, subitem )
        store( LV_ITEM, LVITEM_pszText, data[x] )
        store( LV_ITEM, LVITEM_cchTextMax, length(data[x]) )
        subitem += 1
        if subitem = 1 then
          junk = w32Func( xSendMessage, { handle, LVM_INSERTITEM, 0, LV_ITEM } )
        else
junk = w32Func( xSendMessage, { handle, LVM_SETITEM, i-1, LV_ITEM } )
        end if             
      end for
      store( LV_ITEM, LVITEM_lParam, i )
      release_mem(LV_ITEM)
  end for
end procedure

P.S this routine would be faster if hacked. 
e.g straight pokes( ) instead of store( ) and/or, inlining the routine in your
program.

Good Day!

Euman
euman at bellsouth.net

==================================================================
The information contained in this message may be confidential 
and is intended to be exclusively for the addressee. Should you 
receive this message unintentionally, please do not use the contents 
herein and notify the sender immediately by return e-mail.
==================================================================

new topic     » topic index » view message » categorize

2. Re: [Win32lib] Listview speed

Hey, I liked this idea. I've corrected the (many ;-O ) bugs in the example
you sent and enclosed it in a demo program.

-----------------
object VOID
include win32lib.ew
include sort.e
without warning

constant w = createEx(Window,"test load", 0, 0, 0, 400, 0400, 0, 0),
         lv = createEx(ListView, {"English","Digit", "Thai"}, w, 10, 10,
300, 300, LVS_REPORT , 0),
         bt = createEx(Button, "English", w, 10, 340, 60, 25, 0, 0)

global procedure loadLVInfo(atom id, sequence alldata)
    atom hWnd
    atom LV_ITEM
    sequence data
    integer msg

    hWnd = getHandle(id)

    VOID = w32Func( xSendMessage, {hWnd, LVM_DELETEALLITEMS, 0, 0})
    LV_ITEM = acquire_mem(0,  SIZEOF_LVITEM )
    store( LV_ITEM, LVITEM_mask, LVIF_TEXT )

    for i = 1 to length(alldata) do
        store( LV_ITEM, LVITEM_iItem, i-1)
        store( LV_ITEM, LVITEM_lParam, i )
        data = alldata[i]
        for j = 1 to length(data) do
            store( LV_ITEM, LVITEM_iSubItem, j-1 )
            store( LV_ITEM, LVITEM_pszText, data[j] )
            store( LV_ITEM, LVITEM_cchTextMax, length(data[j]) )
            if j = 1 then
                msg = LVM_INSERTITEM
            else
                msg = LVM_SETITEM
            end if
            VOID = w32Func( xSendMessage, { hWnd, msg, j-1, LV_ITEM } )
        end for

    end for

    release_mem(LV_ITEM)
end procedure

sequence theData theData = {}
integer theDir theDir = 1

theData = append(theData, {"One", "1", "neung"})
theData = append(theData, {"Two", "2", "song"})
theData = append(theData, {"Three", "3", "sam"})
theData = append(theData, {"Four", "4", "si"})
theData = append(theData, {"Five", "5", "ha"})
theData = append(theData, {"Six", "6", "hok"})
theData = append(theData, {"Seven", "7", "jet"})
theData = append(theData, {"Eight", "8", "baht"})
theData = append(theData, {"Nine", "9", "kow"})
theData = append(theData, {"Ten", "10", "sip"})


loadLVInfo(lv, theData)


------------------------------------------------
function mysort(object p1, object p2)
------------------------------------------------
    object l1,l2

    if theDir = 1 then
        l1 = p1[1]
        l2 = p2[1]

    elsif theDir = 2 then
        l1 = value(p1[2])
        l1 = l1[2]

        l2 = value(p2[2])
        l2 = l2[2]
    else
        l1 = p1[3]
        l2 = p2[3]

    end if

    return compare(l1, l2)
end function

constant bttext = {"English", "Digit", "Thai"}
------------------------------------------------
procedure onClick_bt(integer self, integer event, sequence parms)
------------------------------------------------
    theData = custom_sort(routine_id("mysort"), theData)
    loadLVInfo(lv, theData)

    theDir += 1
    if theDir = 4 then
        theDir = 1
    end if

    setText(bt, bttext[theDir])

end procedure
setHandler(bt, w32HClick, routine_id("onClick_bt"))


WinMain(w, 0)

-----------------
Derek.

----- Original Message -----
From: <euman at bellsouth.net>
To: "EUforum" <EUforum at topica.com>
Sent: Saturday, June 15, 2002 9:23 AM
Subject: [Win32lib] Listview speed


>
> Hello Matt Lewis and all,
>
> The (below) procedure is faster for loading Items into a listview
> however, I havent figured out how I plan to sort the data using this
> routine. I'll work on this some more tonight.
>
> You also can not sort the listview using the current Win32lib sort
> algorythm and this procedure, perhaps someone who knows the lib
> better would do this.
>
> If your plans are to not allow sorting then this will be a better choice
> for speed.
>
> -- add to Win32lib
> global procedure LoadLVInfo(atom id, sequence alldata)
> integer howmany
>   handle = getHandle(id)
>   howmany = length(alldata)
>   for i = 1 to howmany do
>      LV_ITEM = acquire_mem(0,  SIZEOF_LVITEM )
>      store( LV_ITEM, LVITEM_mask, LVIF_TEXT )
>      store( LV_ITEM, LVITEM_iItem, i-1)
>      data = alldata(i)
>      subitem = 0
>      for x = 1 to length(data) do
>         store( LV_ITEM, LVITEM_iSubItem, subitem )
>         store( LV_ITEM, LVITEM_pszText, data[x] )
>         store( LV_ITEM, LVITEM_cchTextMax, length(data[x]) )
>         subitem += 1
>         if subitem = 1 then
>           junk = w32Func( xSendMessage, { handle, LVM_INSERTITEM, 0,
LV_ITEM } )
>         else
>           junk = w32Func( xSendMessage, { handle, LVM_SETITEM, i-1,
LV_ITEM } )
>         end if
>       end for
>       store( LV_ITEM, LVITEM_lParam, i )
>       release_mem(LV_ITEM)
>   end for
> end procedure
>
> P.S this routine would be faster if hacked.
> e.g straight pokes( ) instead of store( ) and/or, inlining the routine in
your program.
>
> Good Day!
>
> Euman
> euman at bellsouth.net
>
> ==================================================================
> The information contained in this message may be confidential
> and is intended to be exclusively for the addressee. Should you
> receive this message unintentionally, please do not use the contents
> herein and notify the sender immediately by return e-mail.
> ==================================================================
>
>
>
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: [Win32lib] Listview speed

Hey Derek,

We could extend the routine you fixed up to allow non-sequence material.

            if sequence(data[j]) then
            store( LV_ITEM, LVITEM_pszText, data[j] )
            store( LV_ITEM, LVITEM_cchTextMax, length(data[j]) )
            else
            store( LV_ITEM, LVITEM_pszText, {data[j]} )            
            end if

Im looking into the LV Header API in hopes that there is an event we can
trap to allow sorting a specific column from an onClick. 
Im sure there must be one.

Euman
euman at bellsouth.net

==================================================================
The information contained in this message may be confidential 
and is intended to be exclusively for the addressee. Should you 
receive this message unintentionally, please do not use the contents 
herein and notify the sender immediately by return e-mail.
==================================================================

new topic     » goto parent     » topic index » view message » categorize

4. Re: [Win32lib] Listview speed

Looks like Matt already added this to the library.

fDoLVN_COLUMNCLICK( )

Cool, now I can sort my 1500+ items in less than 5 seconds
instead of 20+

Euman
euman at bellsouth.net


----- Original Message ----- 
From: "Euman" <euman at bellsouth.net>
To: <EUforum at topica.com>


> Hey Derek,
> 
> We could extend the routine you fixed up to allow non-sequence material.
> 
>             if sequence(data[j]) then
>             store( LV_ITEM, LVITEM_pszText, data[j] )
>             store( LV_ITEM, LVITEM_cchTextMax, length(data[j]) )
>             else
>             store( LV_ITEM, LVITEM_pszText, {data[j]} )            
>             end if
> 
> Im looking into the LV Header API in hopes that there is an event we can
> trap to allow sorting a specific column from an onClick. 
> Im sure there must be one.
> 
> Euman
> euman at bellsouth.net
>

new topic     » goto parent     » topic index » view message » categorize

5. Re: [Win32lib] Listview speed

Ooops, I forgot to address the other issue you raised - how to use the
built-in sorting of the library.

I've adjusted the demo example to so how to do that.

---------------------
object VOID
include win32lib.ew
include sort.e
without warning

constant w = createEx(Window,"test load", 0, 0, 0, 400, 0400, 0, 0),
         lv = createEx(ListView, {"English","Digit", "Thai"}, w, 10, 10,
300, 300, LVS_REPORT , 0)

global procedure loadLVInfo(atom id, sequence alldata)
    atom hWnd
    atom LV_ITEM
    sequence data
    integer msg

    hWnd = getHandle(id)

    VOID = w32Func( xSendMessage, {hWnd, LVM_DELETEALLITEMS, 0, 0})
    LV_ITEM = acquire_mem(0,  SIZEOF_LVITEM )

    for i = 1 to length(alldata) do
        store( LV_ITEM, LVITEM_iItem, i-1)
        store( LV_ITEM, LVITEM_lParam, i )
        data = alldata[i]
        for j = 1 to length(data) do
            store( LV_ITEM, LVITEM_iSubItem, j-1 )
            store( LV_ITEM, LVITEM_pszText, data[j] )
            store( LV_ITEM, LVITEM_cchTextMax, length(data[j]) )
            if j = 1 then
                msg = LVM_INSERTITEM
                store( LV_ITEM, LVITEM_mask,
or_all({LVIF_TEXT,LVIF_PARAM}) )
            else
                msg = LVM_SETITEM
                store( LV_ITEM, LVITEM_mask, LVIF_TEXT )
            end if
            VOID = w32Func( xSendMessage, { hWnd, msg, j-1, LV_ITEM } )
        end for

    end for

    release_mem(LV_ITEM)
end procedure

sequence theData theData = {}

theData = append(theData, {"One", "1", "neung"})
theData = append(theData, {"Two", "2", "song"})
theData = append(theData, {"Three", "3", "sam"})
theData = append(theData, {"Four", "4", "si"})
theData = append(theData, {"Five", "5", "ha"})
theData = append(theData, {"Six", "6", "hok"})
theData = append(theData, {"Seven", "7", "jet"})
theData = append(theData, {"Eight", "8", "baht"})
theData = append(theData, {"Nine", "9", "kow"})
theData = append(theData, {"Ten", "10", "sip"})


loadLVInfo(lv, theData)

-- Set the attributes to use the built-in sorting.
VOID = setLVAttr( lv, {{kLVColTypes, {'i','n','i'}},
                       {kLVSortSeq, {1, 1, 1}}
                      })


WinMain(w, Normal)

---------------------
Derek

----- Original Message -----
From: <euman at bellsouth.net>
To: "EUforum" <EUforum at topica.com>
Sent: Saturday, June 15, 2002 9:23 AM
Subject: [Win32lib] Listview speed


>
> Hello Matt Lewis and all,
>
> The (below) procedure is faster for loading Items into a listview
> however, I havent figured out how I plan to sort the data using this
> routine. I'll work on this some more tonight.
>
> You also can not sort the listview using the current Win32lib sort
> algorythm and this procedure, perhaps someone who knows the lib
> better would do this.
>
> If your plans are to not allow sorting then this will be a better choice
> for speed.
>
> -- add to Win32lib
> global procedure LoadLVInfo(atom id, sequence alldata)
> integer howmany
>   handle = getHandle(id)
>   howmany = length(alldata)
>   for i = 1 to howmany do
>      LV_ITEM = acquire_mem(0,  SIZEOF_LVITEM )
>      store( LV_ITEM, LVITEM_mask, LVIF_TEXT )
>      store( LV_ITEM, LVITEM_iItem, i-1)
>      data = alldata(i)
>      subitem = 0
>      for x = 1 to length(data) do
>         store( LV_ITEM, LVITEM_iSubItem, subitem )
>         store( LV_ITEM, LVITEM_pszText, data[x] )
>         store( LV_ITEM, LVITEM_cchTextMax, length(data[x]) )
>         subitem += 1
>         if subitem = 1 then
>           junk = w32Func( xSendMessage, { handle, LVM_INSERTITEM, 0,
LV_ITEM } )
>         else
>           junk = w32Func( xSendMessage, { handle, LVM_SETITEM, i-1,
LV_ITEM } )
>         end if
>       end for
>       store( LV_ITEM, LVITEM_lParam, i )
>       release_mem(LV_ITEM)
>   end for
> end procedure
>
> P.S this routine would be faster if hacked.
> e.g straight pokes( ) instead of store( ) and/or, inlining the routine in
your program.
>
> Good Day!
>
> Euman
> euman at bellsouth.net
>
> ==================================================================
> The information contained in this message may be confidential
> and is intended to be exclusively for the addressee. Should you
> receive this message unintentionally, please do not use the contents
> herein and notify the sender immediately by return e-mail.
> ==================================================================
>
>
>
>

new topic     » goto parent     » topic index » view message » categorize

6. Re: [Win32lib] Listview speed

Hey Derek,

Ive modified Win32lib's ColumnClick Notification to use loadLVInfo( ),
theres only one problem I see with this.

You must declare your alldata sequence ahead of including Win32lib.ew
Im not sure if I'll even try to work this out until later next week.

The good news is that for 1500+ items it seems to take (visually) about the
same time as it would to normally load your LV. 
This is pretty fast, folks!

Here's what Ive done thus far:

global integer SORT_BY
SORT_BY=0

global function CS_byElement(sequence s1,sequence s2)
    return compare(s1[SORT_BY],s2[SORT_BY])
end function

global constant ByElement=routine_id("CS_byElement")

----------------------------------------------------
function fDoLVN_COLUMNCLICK(integer id, atom hWnd, atom wParam, atom lParam)
----------------------------------------------------
integer
    lColumn,
    lOwner
   
    id = getId( fetch( lParam, NMHDR_hwndFrom ))  
    if id != 0 then
        lColumn = fetch( lParam, NMLISTVIEW_iSubItem ) + 1
        SORT_BY=lColumn
        alldata=custom_sort(ByElement,alldata)
        VOID = sendMessage(id,WM_SETREDRAW,0,0)
        loadLVInfo(id, alldata)
        VOID = sendMessage(id,WM_SETREDRAW,1,0)
    end if

    return {kReturnNow}
end function


Euman
euman at bellsouth.net

==================================================================
The information contained in this message may be confidential 
and is intended to be exclusively for the addressee. Should you 
receive this message unintentionally, please do not use the contents 
herein and notify the sender immediately by return e-mail.
==================================================================

new topic     » goto parent     » topic index » view message » categorize

7. Re: [Win32lib] Listview speed

Euman,
I've added a way to the library so that an application can easily handle
WM_NOTIFY messages, such as the LVM_COLUMNCLICK one you have exampled here.
This way, it gets over the problem of having to declare shared data before
the include win32lib.ew statement. This feature will be released on Sunday
night, along with some demo programs for it.

----- Original Message -----
From: <euman at bellsouth.net>
To: "EUforum" <EUforum at topica.com>
Subject: Re: [Win32lib] Listview speed


>
> Hey Derek,
>
> Ive modified Win32lib's ColumnClick Notification to use loadLVInfo( ),
> theres only one problem I see with this.
>
> You must declare your alldata sequence ahead of including Win32lib.ew
> Im not sure if I'll even try to work this out until later next week.
>
> The good news is that for 1500+ items it seems to take (visually) about
the
> same time as it would to normally load your LV.
> This is pretty fast, folks!
>
> Here's what Ive done thus far:
>
> global integer SORT_BY
> SORT_BY=0
>
> global function CS_byElement(sequence s1,sequence s2)
>     return compare(s1[SORT_BY],s2[SORT_BY])
> end function
>
> global constant ByElement=routine_id("CS_byElement")
>
> ----------------------------------------------------
> function fDoLVN_COLUMNCLICK(integer id, atom hWnd, atom wParam, atom
lParam)
> ----------------------------------------------------
> integer
>     lColumn,
>     lOwner
>
>     id = getId( fetch( lParam, NMHDR_hwndFrom ))
>     if id != 0 then
>         lColumn = fetch( lParam, NMLISTVIEW_iSubItem ) + 1
>         SORT_BY=lColumn
>         alldata=custom_sort(ByElement,alldata)
>         VOID = sendMessage(id,WM_SETREDRAW,0,0)
>         loadLVInfo(id, alldata)
>         VOID = sendMessage(id,WM_SETREDRAW,1,0)
>     end if
>
>     return {kReturnNow}
> end function
>
>
> Euman
> euman at bellsouth.net
>
> ==================================================================
> The information contained in this message may be confidential
> and is intended to be exclusively for the addressee. Should you
> receive this message unintentionally, please do not use the contents
> herein and notify the sender immediately by return e-mail.
> ==================================================================
>
>
>
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu