Re: win32lib getTVSelectedText Not Working

new topic     » goto parent     » topic index » view thread      » older message » newer message

c.k.lester wrote:
> 
> CChris wrote:
> > c.k.lester wrote:
> > > I'm using Win32Lib 0.60 Patch #67, 15-Jan-2007. The getTVSelectedText item
> > > doesn't work on sub-items.
> > > Anybody have a fix?!
> > 
> > The problem is with getTVIndex(), which wrongly assumes that all items are
> > at
> > level 1.
> 
> Thanks, CC! :)

Here's a fix; it involves both getTVIncedx() and getTVText().
global function getTVIndex( integer id )
    atom state, item, hChild, TV_ITEM
    sequence path
    integer p

    item = sendMessage( id, TVM_GETNEXTITEM, 0, TVGN_ROOT )
    TV_ITEM = struct_TVITEM( TVIF_STATE, item, 0, 0, "", 0, 0, 0, 0)
    path = {}

    while 1 do
        VOID = sendMessage( id, TVM_GETITEM, 0, TV_ITEM )
        state = w32fetch( TV_ITEM, TVITEM_state)
               ?state
        if and_bits(state,TVIS_SELECTED) then
            -- assuming only one item is selected at a time
            exit
        end if

        hChild = sendMessage( id, TVM_GETNEXTITEM, TVGN_CHILD, item )
        if hChild then
            path &= item
            item = hChild
        else
            item = sendMessage( id, TVM_GETNEXTITEM, TVGN_NEXT, item )
            while not item do
                if not length(path) then
                    exit
                end if
                item=path[length(path)]
                path=path[1..length(path)-1]
                item = sendMessage( id, TVM_GETNEXTITEM, TVGN_NEXT, item )
            end while
        end if

        if not length(path) then
            exit
        end if
        w32store( TV_ITEM, TVITEM_hItem, item )
    end while

    w32release_mem( TV_ITEM )
    return item

end function

global function getTVText( atom iItem )
    integer item
    item = find(iItem,tvitem_handle)
    if item > 0 then
        return w32peek_string( tvitem_data[item][ktv_TextAddr] )
    else
        return ""
    end if

end function


Probably some small things to optimise, but it works.
Remember that "patch #67" is an unreleased alpha version...

CChris

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu