rendered paste bodyalias init {
window -ak0hdBpfo +d @test -1 -1 300 300
$listbox(@test, 100 100 150 100).coords
$listbox(@test, Just testing.).header
$listbox(@test, 50 50).columns
$listbox(@test, tahoma/9).font
$listbox(@test, woot).hash
listbox @test
}
alias listbox {
var %t = listbox. $+ $1
if ($isid) {
hadd -m %t $prop $2-
}
else {
var %win = $1
tokenize 32 $hget(listbox. $+ %win, coords)
drawrect -rfn %win $rgb(223,220,214) 1 $1-
draw.detail %win $false $1-
draw.header %win $calc($1 + 3) $calc($2 + 3) $calc($3 - 6)
draw.buffer %win
drawdot %win
}
}
alias draw.detail {
var %a, %b
if ($2) {
%a = $rgb(255,255,255) | %b = $rgb(144,144,144)
}
else {
%b = $rgb(255,255,255) | %a = $rgb(144,144,144)
}
drawline -rn $1 %a 2 $3 $calc($4 + $6) $3 $4 $calc($3 + $5) $4
drawline -rn $1 %b 2 $3 $calc($4 + $6) $calc($3 + $5) $calc($4 + $6) $calc($3 + $5) $4
}
alias draw.header {
var %win = $1, %font = $hget(listbox. $+ %win, font), %text = $hget(listbox. $+ %win, header), %h = $font.height(%font)
draw.detail %win $true $2- %h
set.list.dims %win $2- %h
tokenize 32 $calc($2 + 3) $3 $calc($4 - 6) %h
%font = $replace(%font, /, $chr(32))
drawtext -rnc %win $rgb(255,255,255) %font $1 $2 $calc($3 - 1) $calc($4 - 1) %text
drawtext -rnc %win $rgb(160,160,160) %font $calc($1 - 1) $calc($2 - 1) $3 $4 %text
}
alias set.list.dims {
var %win = $1
tokenize 32 $2 $calc($3 + $5) $calc($4 - 15) $calc(($gettok($hget(listbox. $+ $1, coords), 4, 32) - $5) - 3)
$listbox(%win, $1-).listdims
$listbox(%win, $calc($1 + $3) $calc($2 + 2) 15 $calc($4 - 4)).scrolldims
}
alias draw.buffer {
if ($2) {
$listbox($1, $ifmatch).position
}
var %win = $1, %p = $iif($hget(listbox. $+ %win, position), $ifmatch, 1), %step = $font.height($hget(listbox. $+ %win, font)), %hash = $hget(listbox. $+ %win, hash), %i = 0, %z = 1
tokenize 32 $hget(listbox. $+ %win, listdims)
%font = $replace(%font, /, $chr(32))
while (%i < $calc($4 - %step)) {
if ($hget(%hash, ITEM $+ $calc(%p + %i))) {
draw.row %win $1 $calc($2 + %i + 2) $3 $4 $ifmatch
inc %i %step
inc %z
}
else {
break
}
}
$scrollbar(%win, %z).listlines
var %a = 1, %b = $1, %c
while ($gettok($hget(listbox. $+ %win, columns), %a, 32)) {
%c = $ifmatch
draw.line %win $calc(%b + %c) $2 $calc(%b + %c) $calc($2 + $4)
inc %b %c
inc %a
}
draw.scroll %win
draw.select %win
}
alias draw.row {
var %win = $1, %font = $sep.font(%win), %columns = $hget(listbox. $+ %win, columns), %i = 1, %x, %z, %t
tokenize 32 $2-
%x = $1
while ($gettok(%columns, %i, 32)) {
%z = $ifmatch
if ($gettok($5-, %i, 9)) {
drawtext -rnc %win $rgb(255,255,255) %font %x $2 %z $4 $ifmatch
drawtext -rnc %win $rgb(160,160,160) %font $calc(%x - 1) $calc($2 - 1) $calc(%z + 1) $calc($4 + 1) $ifmatch
}
inc %x %z
inc %i
}
}
alias draw.line {
var %win = $1
tokenize 32 $2-
drawline -rn %win $rgb(255,255,255) 1 $1-
drawline -rn %win $rgb(144,144,144) 1 $calc($1 + 1) $2 $calc($3 + 1) $4
}
alias draw.scroll {
var %p = $hget(listbox. $+ $1, position), %win = $1
tokenize 32 $hget(listbox. $+ %win, scrolldims) $list.lines(%win) $iif($hget(listbox. $+ %win, listlines), $ifmatch, 0)
var %s = $iif($5 <= $6, 1, $iif($calc($6 / $5) < 0.07, 0.07, $v1))), %x = $1, %y = $int($calc(((%p / 100 * $4) * (1 - %s)) + $2)), %w = $calc($3 - 1), %h = $ceil($calc($4 * %s - 1))
drawrect -rnf %win $calc($rgb(223,220,214) - $rgb(20,20,20)) 1 $1 $2 $3 $4
drawrect -nfr %win $rgb(223,220,214) 1 %x %y %w %h
draw.detail %win $true %x %y %w %h
}
alias list.lines {
return $iif($hget($hget(listbox. $+ $1, hash), ITEM0), $ifmatch, 0)
}
alias list.rows {
tokenize 32 $hget(listbox. $+ $1, listdims) $hget(listbox. $+ $1, font)
if ($1) {
return $int($calc($4 / $font.height($5-)))
}
else {
return 0
}
}
alias sep.font {
return $replace($hget(listbox. $+ $1, font), /, $chr(32))
}
alias draw.select {
var %win = $1, %x = $font.height($hget(listbox. $+ %win, font)), %y, %z = $2
tokenize 32 $hget(listbox. $+ %win, listdims)
if (%z isnum) {
var %s = $v1
if ($hget(listbox. $+ %win, selected_line) isnum) {
%y = $calc($2 + (%x * $v1))
drawreplace -nr %win $rgb(219,225,232) $rgb(223,220,214) $1 %y $3 $calc(%x + 1)
}
$listbox(%win, %s).selected_line
}
if ($hget(listbox. $+ %win, selected_line) isnum) {
%y = $calc($2 + (%x * $v1))
drawreplace -nr %win $rgb(223,220,214) $rgb(219,225,232) $1 %y $3 $calc(%x + 1)
}
drawdot %win
}
alias font.height {
tokenize 47 $1-
return $calc($height(T, $1, $2) + 1)
}
menu * {
sclick: {
if ($hget(listbox. $+ $active)) {
var %t = $ifmatch
tokenize 32 $hget(%t, listdims)
if ($inrect($mouse.x, $mouse.y, $1, $2, $3, $4)) {
draw.select $active $int($calc((($mouse.y - $2) / $4) * $list.rows($active)))
}
}
}
}