ListBox & ColorPopup

The following example illustrates what I would like to do: clicking into a colored listbox cell to change the color. The following method works but it would be MUCH nicer if 1) the popup occurs exactly where the mouse clicked and 2) if the popup ist being killed automatically after selecting a new color. I guess both can be accomplished using hook functions but I don't see how at the moment (which may reflect my ignorance for working with structures...).

Ideally a built-in ListBox option (just like checkbox) would exist.

Any thoughts are welcome!

function myPanel() : Panel

    Make/O/T/N=(20,3) wList
    SetDimlabel 1, 0, Index, wList
    SetDimlabel 1, 1, Color, wList
    SetDimlabel 1, 2, Stuff, wList
    Make/O/N=(20,3,2) sWave = 0
    Make/O/N=(20,3) cWave = trunc(abs(enoise(65535)))
    wList[][0] = num2str(p)
    wList[][2] = "blah"

    NewPanel/K=1/N=TestPanel /W=(600,100,1300,500)
   
    ListBox list0,pos={50,50},size={600,300},listWave=wlist
    ListBox list0,selWave=sWave, colorWave = cWave, proc=myListBoxProc
    ListBox list0,fsize = 12, frame=3, userColumnResize=1
   
    //set color of second column
    sWave[][1][1]= p
    SetDimLabel 2,1,backColors, sWave  
end


Function myListBoxProc(lba) : ListBoxControl
    STRUCT WMListboxAction &lba
   
    Variable row = lba.row
    Variable col = lba.col
    WAVE/T/Z listWave = lba.listWave
    WAVE/Z cWave = lba.colorWave   
   
    switch( lba.eventCode )
        case -1: // control being killed
            break
        case 1: // mouse down
           
            // clicked on color
            if(col == 1)
                   
                variable/g WhichRow = row
                   
                //get a color popup            
                GetWindow TestPanel wsizeRM
   
                variable top, left
                top = V_top * ScreenResolution/72
                left = V_left * ScreenResolution/72
                   
                NewPanel/K=1 /N=cpop /W=(left+200, top+200, left+250, top+220)
                PopupMenu popup0 value="*COLORPOP*", proc = myPopMenuProc
                PopupMenu popup0 popColor=(cWave[row][0],cWave[row][1],cWave[row][2])
                   
            endif
       
            break
   
    // handle more events
   
    endswitch
   
    return 0
End


Function myPopMenuProc(pa) : PopupMenuControl
    STRUCT WMPopupAction &pa
   
    wave/Z cWave
    NVAR WhichRow
    variable rr, gg, bb
   
    switch( pa.eventCode )
        case 2: // mouse up
            Variable popNum = pa.popNum
            String popStr = pa.popStr
           
            sscanf popstr, "(%g,%g,%g)", rr,gg,bb  
            cWave[WhichRow][0] = rr; cWave[WhichRow][1] = gg; cWave[WhichRow][2] = bb;
           
            break
        case -1: // control being killed
            break
    endswitch

    return 0
End



EDIT: ok, I found a solution to problem 1). I overlooked mouseLoc.