Reflex — File Browser
Reflexv0.1 / Reflexv0.1 / Reflex / system / scripts / popup.mrc
popup.mrc — 19.14 KB — Download this file
;========================================================================
; Picture Window Popups
; Version: 0.81 (bèta)
; Release: 08-07-2004
;
; By: Voice of Power aka. Marc Kuiper
; E-mail: marckuiper@hotmail.com
; MSN: marckuiper@hotmail.com
; IRC: irc.undernet.org : #mirc.net, #mircscripts.org, #scriptsdb.org
; irc.ptnet.org : #SCT
; Website: http://www.voiceofpower.us
;========================================================================
alias popup {
if ($pget($1)) {
var %name = $1, %win = @popup_ $+ $1, %x = $iif($2, $2, $mouse.dx), %y = $iif($3, $3, $mouse.dy)
if ($window(%win)) window -c %win
if ($pget(%name)) {
tokenize 32 $pget(%name $+ _spacing)
hdel $phash $+(%name,_colcoords)
hdel -w $phash $+(%name,_*_itemcoords)
var %d = $popup_dims(%name), %w = $gettok(%d, 1, 32), %h = $gettok(%d, 2, 32)
var %hi = $calc($height(a, $pget($+(%name,_font)), $pget($+(%name,_fontsize))) + $6 + $7)
if ($gettok($pget($+(%name,_iconsize)), 2, 32) > %hi) %hi = $ifmatch
if ((%w) && (%h)) {
var %align = $pget($+(%name,_align)), %valign = $pget($+(%name,_valign)), %bar = $pget($+(%name,_bar))
if (%align == center) %x = $calc(%x - (%w / 2))
elseif (%align == right) %x = $calc(%x - %w)
if (%valign == middle) %y = $calc(%y - (%h / 2))
elseif (%valign == bottom) %y = $calc(%y - %h)
if ($window(@popup_*, 0) == 0) padd popups_open @popup_ $+ %name
else padd popups_open $addtok($pget(popups_open), @popup_ $+ %name, 59)
if ($calc(%x + %w) > $window(-1).w) %x = $calc(%x - %w)
if ($calc(%y + %h) > $window(-1).h) %y = $calc(%y - %h)
window -Bfphdo +dL %win $ceil(%x) $ceil(%y) %w %h
setlayer $pget($+(%name,_trans)) %win
drawrect -rfn %win $pget($+(%name,_back)) 1 0 0 %w %h
drawrect -nr %win $pget($+(%name,_border)) 1 0 0 %w %h
var %i = 1, %cols = $pget(%name $+ _columns), %x = $calc($1 + 1)
while (%i <= %cols) {
var %j = 1, %items = $pget($+(%name,_,%i)), %y = $calc($2 + 1), %w = $calc($pget($+(%name,_,%i,_width)) + $gettok($pget($+(%name,_iconsize)), 1, 32)), %text
if (%bar > 0) inc %w $calc(4 + $12)
if (%i > 1) {
drawline -nr %win $pget($+(%name,_div)) 1 $calc(%x + $10) $calc($2 + 1) $calc(%x + $10) $calc(%h - $4 - 1)
inc %x $calc($10 + $11 + 1)
}
if (%bar > 0) drawrect -rfn %win $pget($+(%name,_bar_color)) 1 %x %y $calc($gettok($pget($+(%name,_iconsize)), 1, 32) + 8) $calc(%h - $1 - $2 - 2)
padd $+(%name,_colcoords) $+($pget(%name $+ _colcoords),;,%x %w)
while (%j <= %items) {
%text = $gettok($pget($+(%name,_,%i,_,%j)), 3, 13)
padd $+(%name,_,%i,_itemcoords) $+($pget($+(%name,_,%i,_itemcoords)),;,%y $iif(%text == -, $calc($2 + $4 + 3),%hi))
if (%text == -) {
if (%bar > 0) var %xs = $calc($gettok($pget($+(%name,_iconsize)), 1, 32) + 6 + $12)
drawrect -nfr %win $pget($+(%name,_item)) 1 $calc(%x + %xs) %y $calc(%w - %xs) $calc($8 + $9 + 1)
drawline -nr %win $pget($+(%name,_sep)) 1 $calc(%x + %xs + 1) $calc(%y + $8) $calc(%x + %w - 1) $calc(%y + $8)
inc %y $calc($8 + $9 + 1 + $5)
}
else {
popup_item %name %x %y %w %hi $pget($+(%name,_,%i,_,%j))
inc %y $calc(%hi + $5)
}
inc %j
}
inc %x %w
inc %i
}
drawdot %win
window -a %win
}
}
else { echo -s * /popup: invalid popup | halt }
}
}
alias popup_create {
if (!$hget($phash)) { hmake $phash $phashsize }
if ($1) {
hdel -w $phash $1 $+ _*
hdel $phash $1
padd $1 1
padd $1 $+ _columns 1
padd $1 $+ _1 0
padd $1 $+ _1_seperators 0
padd $1 $+ _1_width 0
padd $1 $+ _text 0
padd $1 $+ _text_dis 10070188
padd $1 $+ _text_sel 16777215
padd $1 $+ _text_disel 10070188
padd $1 $+ _item 16777215
padd $1 $+ _item_dis 16777215
padd $1 $+ _item_sel 12937777
padd $1 $+ _item_disel 12937777
padd $1 $+ _item_sel_border 12937777
padd $1 $+ _back 16777215
padd $1 $+ _border 10070188
padd $1 $+ _sep 10070188
padd $1 $+ _div 10070188
padd $1 $+ _bar_color 13816530
padd $1 $+ _symtext 0
padd $1 $+ _symtext_dis 10070188
padd $1 $+ _symtext_sel 16777215
padd $1 $+ _symtext_disel 10070188
padd $1 $+ _symbol 11842740
padd $1 $+ _sym_dis 11842740
padd $1 $+ _sym_sel 12937777
padd $1 $+ _sym_disel 12937777
padd $1 $+ _sym_border 0
padd $1 $+ _font Tahoma
padd $1 $+ _fontsize 11
padd $1 $+ _spacing 2 2 2 2 0 2 3 3 5 2 2 4
padd $1 $+ _iconsize 16 16
padd $1 $+ _align left
padd $1 $+ _valign top
padd $1 $+ _click left
padd $1 $+ _bar 0
padd $1 $+ _trans 255
}
else { echo -s * /popup_create: insuficient parameters | halt }
}
alias popup_destroy {
if ($1) {
if ($window(@popup_ $+ $1)) window -c @popup_ $+ $1
hdel -w $phash $1 $+ _*
hdel $phash $1
}
elseif ($hget($phash)) hfree $phash
}
alias popup_close {
if ($hget($phash)) {
if ($mid($1, 1, 1) == -) var %fl = $1, %name = $2
else var %name = $1
if (%name) {
if (s isin %fl) {
var %open = $pget(popups_open), %i = $findtok(%open, @popup_ $+ %name, 1, 59)
padd popups_open $gettok(%open, 1- $+ %i, 59)
inc %i
while ($gettok(%open, %i, 59)) {
window -c $ifmatch
inc %i
}
}
elseif ($window(@popup_ $+ %name)) {
window -c @popup_ $+ %name
padd popups_open $remtok($pget(popups_open), @popup_ $+ %name, 59)
}
}
else {
var %i = $window(@popup_*, 0), %win
while (%i) {
%win = $window(@popup_*, %i)
if ((!$pget($gettok(%win, 2-, 95) $+ _persistent)) || ($findtok($pget(popups_open), %win, 1, 59) > 1)) window -c %win
dec %i
}
hdel $phash popups_open
}
}
}
alias popup_setstyle {
if ($pget($1)) {
if (($2 == align) && ($istok(left right center, $3, 32))) padd $+($1,_align) $3
elseif (($2 == valign) && ($istok(top bottom middle, $3, 32))) padd $+($1,_valign) $3
elseif (($2 == click) && ($istok(left right leftright, $3, 32))) padd $+($1,_click) $3
elseif ($2 == spacing) {
var %name = $1, %values = 2 2 2 2 0 2 3 3 5 2 2 4, %i = 1, %s
tokenize 32 $3-
while (%i <= 12) {
%s = $ [ $+ [ %i ] ]
if (%s == $null) break
if ((%s != *) && (%s isnum)) %values = $puttok(%values, %s, %i, 32)
inc %i
}
padd $+(%name,_spacing) %values
}
elseif ($2 == colors) {
var %name = $1, %colors = text;text_dis;text_sel;text_disel;item;item_dis;item_sel;item_disel;item_sel_border;back;border;sep;div;bar_color;symtext;symtext_dis;symtext_sel;symtext_disel;symbol;sym_dis;sym_sel;sym_disel;sym_border, %i = 1, %c
tokenize 32 $3-
while (%i <= 23) {
%c = $ [ $+ [ %i ] ]
if (%c == $null) break
if ((%c != *) && (%c isnum)) padd $+(%name,_,$gettok(%colors, %i, 59)) %c
inc %i
}
}
elseif (($2 == font) && ($4 isnum)) {
padd $+($1,_font) $3
padd $+($1,_fontsize) $4
}
elseif (($2 == bar) && ($3 isnum 1-4)) padd $+($1,_bar) $3
elseif (($2 == iconsize) && ($3 isnum) && ($4 isnum)) padd $+($1,_iconsize) $iif($3 > 16, $3, 16) $iif($4 > 16, $4, 16)
elseif (($2 == trans) && ($3 isnum 0-255)) padd $+($1,_trans) $3
elseif ($2 == persistent) padd $+($1,_persistent) $iif($3, 1, 0)
else { echo -s * /popup_setstyle: invalid parameters | halt }
}
elseif (!$1) { echo -s * /popup_setstyle: insuficient parameters | halt }
else { echo -s * /popup_setstyle: invalid popup | halt }
}
; /popup_add [-sdvxcohi] <name> [col] [pos] [icon #] [selicon #] <text> [$cr command]
alias popup_add {
if ($mid($1, 1, 1) == -) {
var %fl = $1, %name = $2, %col = $3, %pos = $4, %text = $5-, %icon = 0, %sicon = 0
if (i isin %fl) var %icon = $5, %sicon = $6, %text = $7-
}
else var %name = $1, %col = $2, %pos = $3, %text = $4-, %icon = 0, %sicon = 0
if (i isin %fl) {
if (%icon !isnum) { %text = %icon %sicon %text | %icon = %col | %sicon = %pos | %col = 0 | %pos = 0 }
elseif (%sicon !isnum) { %text = %sicon %text | %sicon = %icon | %icon = %pos | %pos = 0 }
elseif (%col !isnum) { %text = %col %pos %icon %sicon %text | %col = 0 | %pos = 0 | %icon = 0 | %sicon = 0 }
elseif (%pos !isnum) { %text = %pos %sicon %text | %pos = 0 | %sicon = %pos | %pos = 0 }
}
elseif (%col !isnum) { %text = %col %pos %text | %col = 0 | %pos = 0 | %icon = 0 | %sicon = 0 }
elseif (%pos !isnum) { %text = %pos %text | %pos = 0 | %icon = 0 | %sicon = 0 }
if (($pget(%name)) && (%text)) {
if (%text == $chr(62)) {
hinc $phash $+(%name,_columns)
var %col = $pget($+(%name,_columns))
padd $+(%name,_,%col,_seperators) 0
padd $+(%name,_,%col,_width) 0
}
else {
if (%col == 0) %col = $pget($+(%name,_columns))
var %txt = $gettok(%text, 1, 13), %cmd = $gettok(%text, 2-, 13)
if (!$pget($+(%name,_,%col,_,%pos))) {
hinc $phash $+(%name,_,%col)
if (%txt == -) { hinc $phash $+(%name,_,%col,_seperators) | unset %cmd }
elseif (d isin %fl) { unset %cmd }
elseif (!%cmd) { var %fl = -ds }
}
if (%pos == 0) %pos = $pget($+(%name,_,%col))
if ($mid(%cmd, 1, 1) == $chr(32)) %cmd = $mid(%cmd, 2)
padd $+(%name,_,%col,_,%pos) $+($iif(%fl,%fl,-), $cr, %icon %sicon, $cr, %txt, $cr, %cmd)
if ($calc($width(%txt, $pget($+(%name,_font)), $pget($+(%name,_fontsize))) + 26) > $pget($+(%name,_,%col,_width))) {
padd $+(%name,_,%col,_width) $ifmatch
}
}
}
else { echo -s * /popup_add: insuficient parameters | halt }
}
; /popup_icon <name> [id] [index,]<file>
alias popup_icon {
if ($pget($1)) {
if ($2 isnum) var %id = $2, %f = $3-
else var %id = 0, %f = $2-
; Split the icon index and filename
if ($gettok(%f, 1, 44) isnum) var %idx = $ifmatch, %f = $gettok(%f, 2-, 44)
if ($regex(%f, /"(.+?)"/)) %f = $regml(1)
if ($regex(%f, /'(.+?)'/)) %f = $regml(1)
if (%id <= 0) %id = $calc($hfind($phash, $1 $+ _icon_*, 0, w) + 1)
padd $+($1,_icon_,%id) %idx %f
}
else { echo -s * /popup_icon: invalid popup | halt }
}
alias -l phash return popups
alias -l phashsize return 10
alias -l padd hadd $phash $1-
alias -l pget return $hget($phash, $1)
alias -l psubtimer return 100
alias -l psubpoptime return 200
alias -l ceil {
if ($1 > 0) && (. isin $1) return $calc($int($1) + 1)
return $int($1)
}
alias -l popup_item {
var %name = $1, %win = @popup_ $+ $1, %coords = $2-5, %ctext, %cback, %csym, %csymt, %ico, %bar = $pget($+(%name,_bar))
tokenize 13 $6-
var %fl = $1, %icon = $gettok($2, 1, 32), %sicon = $gettok($2, 2, 32), %text = $3
if (($window(%win)) && ($pget(%name)) && (%text)) {
tokenize 32 %coords $pget(%name $+ _spacing)
if (h isin %fl) {
%ctext = text_sel | %cback = item_sel | %csymt = symtext_sel | %csym = sym_sel
if (%sicon) %ico = $pget($+(%name,_icon_,%sicon))
}
else {
%ctext = text | %cback = item | %csymt = symtext | %csym = symbol
if (%icon) %ico = $pget($+(%name,_icon_,%icon))
}
if (d isin %fl) {
if (h isin %fl) { %ctext = text_disel | %cback = item_disel | %csymt = symtext_disel | %csym = sym_disel }
else { %ctext = text_dis | %cback = item_dis | %csymt = symtext_dis | %csym = sym_dis }
}
%ctext = $pget($+(%name,_,%ctext))
%cback = $pget($+(%name,_,%cback))
%csymt = $pget($+(%name,_,%csymt))
%csym = $pget($+(%name,_,%csym))
var %is = $pget($+(%name,_iconsize)), %iw = $gettok(%is, 1, 32), %ih = $gettok(%is, 2, 32)
if ((%bar == 3) || (%bar == 4)) {
drawrect -nfr %win $pget($+(%name,_back)) 1 $1-4
%coords = $calc($1 + %iw + 6 + $16) $2 $calc($3 - (%iw + 6) - $16) $4
}
elseif ((%bar == 1) || (%bar == 2)) drawrect -nfr %win $pget($+(%name,_item)) 1 $1-4
else drawrect -nfr %win %cback 1 $1-4
if (%bar > 0) drawrect -rfn %win $pget($+(%name,_bar_color)) 1 $1 $2 $calc(%iw + 8) $4
if (h isin %fl) {
drawrect -nfr %win %cback 1 %coords
drawrect -nr %win $pget($+(%name,_item_sel_border)) 1 %coords
}
if (((%bar == 2) || (%bar == 4)) && ((v isin %fl) || (x isin %fl) || (c isin %fl) || (o isin %fl))) {
drawrect -rfn %win %csym 1 $calc($1 + 1) $calc($2 + 1) $calc(%iw + 6) $calc($4 - 2)
drawrect -rn %win $pget($+(%name,_sym_border)) 1 $calc($1 + 1) $calc($2 + 1) $calc(%iw + 6) $calc($4 - 2)
}
elseif ((((%bar == 1) || (%bar > 4)) && (h !isin %fl)) || (%bar == 3)) %csym = $pget($+(%name,_bar_color))
elseif (!%bar) { %csymt = %ctext | %csym = %cback }
var %fh = $calc($2 + ($4 / 2)), %x = $iif(%bar > 0, $calc($1 + 3), $1)
if (v isin %fl) drawtext -nbr %win %csymt %csym marlett 14 $calc(%x + (%iw / 2) - 6) $ceil($calc(%fh - 7))) a
elseif (x isin %fl) drawtext -nbr %win %csymt %csym marlett 10 $calc(%x + (%iw / 2) - 4) $ceil($calc(%fh - 4))) r
elseif (c isin %fl) drawtext -nbr %win %csymt %csym marlett 8 $calc(%x + (%iw / 2) - 3) $ceil($calc(%fh - 4))) g
elseif (o isin %fl) drawtext -nbr %win %csymt %csym marlett 14 $calc(%x + (%iw / 2) - 6) $ceil($calc(%fh - 7))) h
elseif (%ico) {
if ($gettok(%ico, 1, 32) isnum) {
if ($version >= 6.1) var %index = $gettok(%ico, 1, 32)
%ico = $gettok(%ico, 2-, 32)
}
if ($isfile(%ico)) {
; Transparency color: $rgb(255,0,255)
drawpic -tscn $+ $iif(%index, o) %win 16711935 $calc(%x + 1) $ceil($calc(%fh - (%ih / 2)))) %is %index $+(",%ico,")
}
}
elseif ($isfile(%ico)) drawpic -tscn %win 16711935 $calc(%x + 1) $ceil($calc(%fh - (%ih / 2)))) %is $+(",%ico,")
if (s isin %fl) drawtext -nbcr %win %ctext %cback marlett 14 $calc($1 + $3 - 17) $ceil($calc(%fh - 7))) 12 12 4
var %font = $pget($+(%name,_font)), %size = $pget($+(%name,_fontsize)), %x = $calc($1 + $gettok($pget($+(%name,_iconsize)), 1, 32) + 4)
if (e isin %fl) %x = $calc((($1 + $1 + $3) / 2) - ($width(%text, %font, %size) / 2))
elseif (r isin %fl) %x = $calc($1 + $3 - 20 - $width(%text, %font, %size))
drawtext -npbr %win %ctext %cback %font %size $iif(%bar, $calc(%x + $iif(%bar == 3 || %bar == 4, 6, 4) + $16), %x) $calc($2 + $10) %text
}
}
alias -l popup_submenu {
if ($inrect($mouse.x, $mouse.y, $3, $4, $5, $6)) {
var %d = $popup_dims($2), %w = $gettok(%d, 1, 32), %h = $gettok(%d, 2, 32), %x, %y
if ($calc($window($1).x + $3 + $5 + %w - 2) > $window(-1).w) %x = $calc($window($1).x - %w + 3)
else %x = $calc($window($1).x + $3 + $5 - 2)
if ($calc($window($1).y + $4 + $6 + %h - 2) > $window(-1).h) %y = $calc($window($1).y - %h + $4 + $6 + 2)
else %y = $calc($window($1).y + $4 - 2)
popup $2 %x %y
.timerpopup_leavesub -m 0 $psubtimer popup_leavesub @popup_ $+ $2
}
}
alias -l popup_mouse {
var %c = $1, %name = $gettok($active, 2-, 95)
if ($pget(%name)) {
tokenize 32 $popup_hover(%name, $mouse.x, $mouse.y)
if ($1) {
var %idata = $pget($+(%name,_,$1,_,$2)), %fl = $gettok(%idata, 1, 13), %txt = $gettok(%idata, 3, 13), %cmd = $gettok(%idata, 4, 13)
if (%c) {
var %cl = $pget($+(%name,_click))
if ((%c == -s) || (%c == -r)) {
var %open = $pget(popups_open), %i = $calc($findtok(%open, @popup_ $+ %name, 1, 59) + 1)
if (((%c == -s) && (%cl == left)) || ((%c == -r) && (%cl == right)) || (%cl == leftright)) {
if ((%cmd) && (s !isin %fl)) {
close -@ @popup_*
$eval(%cmd, 2)
return
}
else {
while ($gettok(%open, %i, 59)) { window -a $ifmatch | inc %i }
}
}
else {
while ($gettok(%open, %i, 59)) { window -a $ifmatch | inc %i }
}
}
}
if (%txt != -) {
if ($pget($+(%name,_selected)) == $3-6 %idata) return
elseif ($pget($+(%name,_selected))) popup_item %name $ifmatch
padd $+(%name,_selected) $3-6 %idata
popup_item %name $3-6 $+($gettok(%idata, 1, 13), h, $cr, $gettok(%idata, 2-, 13))
if ((s isin %fl) && ($pget(%cmd))) {
.timerpopup_submenu -m 1 $iif($psubpoptime > 0, $ifmatch, 0) popup_submenu $active %cmd $3-6
}
}
elseif ($pget($+(%name,_selected))) {
popup_item %name $ifmatch
hdel $phash $+(%name,_selected)
}
}
else {
if ($pget($+(%name,_selected))) {
popup_item %name $ifmatch
hdel $phash $+(%name,_selected)
}
popup_close -s %name
}
drawdot @popup_ $+ %name
}
}
alias -l popup_leavesub {
if ($window(@popup_*, 0) <= 1) { .timerpopup_leavesub off | return }
var %win = $mouse.win
if ((@popup_* iswm %win) && (%win != $1)) {
tokenize 32 $pget($gettok(%win, 2-, 95) $+ _selected)
if ((!$inrect($mouse.x, $mouse.y, $1, $2, $3, $4)) && ($popup_hover($gettok(%win, 2-, 95)))) {
window -a %win
popup_close -s $gettok(%win, 2-, 95)
if ($window(@popup_*, 0) <= 1) .timerpopup_leavesub off
}
}
}
alias -l popup_dims {
if ($pget($1)) {
var %i = 1, %cols = $pget($1 $+ _columns), %w = 0, %hi, %h = 0, %items, %seps, %name = $1
tokenize 32 $pget(%name $+ _spacing)
%hi = $calc($height(a, $pget($+(%name,_font)), $pget($+(%name,_fontsize))) + $6 + $7)
if ($gettok($pget($+(%name,_iconsize)), 2, 32) > %hi) %hi = $ifmatch
while (%i <= %cols) {
inc %w $calc($pget($+(%name,_,%i,_width)) + $gettok($pget($+(%name,_iconsize)), 1, 32))
if ($pget($+(%name,_bar)) > 0) inc %w $calc(4 + $12)
%items = $pget($+(%name,_,%i))
%seps = $pget($+(%name,_,%i,_seperators))
if ($calc(((%items - %seps) * %hi) + (%seps * ($8 + $9 + 1)) + (%items * $5 - $5) + $2 + $4 + 2) > %h) {
%h = $ifmatch
}
inc %i
}
inc %w $calc((%cols * ($10 + $11) - ($10 + $11)) + $1 + $3 + %cols + 1)
return %w %h
}
}
alias -l popup_hover {
var %name = $1, %cols = $pget(%name $+ _colcoords), %i = $numtok(%cols, 59), %x = $calc($mouse.dx - $window(@popup_ $+ %name).x), %y = $calc($mouse.dy - $window(@popup_ $+ %name).y)
while (%i) {
tokenize 32 $gettok(%cols, %i, 59)
if ($inrect(%x, %y, $1, 0, $2, $window(@popup_ $+ %name).h)) {
var %items = $pget($+(%name,_,%i,_itemcoords)), %j = $numtok(%items, 59), %cx = $1, %cy = $2
while (%j) {
tokenize 32 $gettok(%items, %j, 59)
if ($inrect(%x, %y, %cx, $1, %cy, $2)) {
return %i %j %cx $1 %cy $2
}
dec %j
}
return
}
dec %i
}
}
menu @popup_* {
mouse:popup_mouse
sclick:popup_mouse -s
dclick:popup_mouse -s
rclick:popup_mouse -r
leave:popup_mouse
}
on *:ACTIVE:*:{
if (@popup_* !iswm $active) {
popup_close
}
}
on *:APPACTIVE:{
popup_close
}
on *:DIALOG:*:active:*:{
if ($dialog($dname).active) {
popup_close
}
}