Basic — File Browser

Basicv23042002 / Basicv23042002 / basic / sys / display.mrc

display.mrc — 46.06 KB — Download this file

; ###################################
;
;  Basic v23042002
;  blue-elf, belf@mircscripter.com
;
;  general display settings
;  controls which theme to load, etc.
;
; ###################################
alias pnickfix {
  var %p = $prefix
  if ($left($1,1) isin %p) {
    var %l = $ifmatch, %n = $right($1,-1)
    while ($left(%n,1) isin %p) { %n = $right(%n,-1) }
    return $+(%l,%n)
  }
  return $1
}
; /font [-asgbdAm|window] [fontsize] <fontname>
; -A all windows
; -m msg windows
alias font {
  if (-* iswm $1) {
    var %s, %a = channel query chat message status
    if (b isincs $1) %s = -b
    if (d isincs $1) %s = $+(%s,d)
    if ((%s) && (-* !iswm %s)) %s = $+(-,%s)
    if (A !isincs $1) %a = $remtok($remtok(%a,channel,1,32),status,1,32)
    if ((m !isincs $1) && (A !isincs $1)) goto next
    var %i = 1
    while ($gettok(%a,%i,32)) {
      scid -a xfont $ifmatch %s $2-
      inc %i
    }
    return
    :next
  }
  !font $1-
}
; targeted window types:
;  status
;  channel
;  query
;  chat
;  message <- for dqwindow
;
; fscripts=Fixedsys,412,0
;
; /xfont <type> [-db] [size] <name>
alias -l xfont {
  var %b = $iif(-* iswm $2 && b isincs $2,1), %d = $iif(-* iswm $2 && d isincs $2,1), %i = 1, %switch
  if ((%b) && (%d)) %switch = -bd
  elseif ((%b) && (!%d)) %switch = -b
  elseif ((!%b) && (%d)) %switch = -d
  var %fontfinal = $iif(%switch,$3-,$2-), %found, %window
  while ($window(*,%i)) {
    if ($window(*,%i).type == $1) {
      %window = $window(*,%i)
      if ($ifmatch == status) {
        var %window, %switch = $+(%switch,s)
        if ((%switch) && (-* !iswm %switch)) %switch = $+(-,%switch)
      }
      !font %switch %window %fontfinal
      %found = 1
    }
    inc %i
  }
  if (!%d) goto d
  if (!%found) {
    if ($3 isnum) var %size = $calc($iif(%b,700,400) + $remove($3,-)), %name = $4-
    else var %size = 412, %name = $3-
    .timer.xfont1 $+ $1 -i 1 1 writeini $+(",$mircini,") fonts $+(f,$1) %name $+ , $+ %size $+ ,0
    .timer.xfont2 $+ $1 -i 1 1 xfontrep $3-
  }
  :d
}
alias -l xfontrep {
  if ($group(#display.basic) == on) {
    if ($1 isnum) {
      _set display fontsize $1
      _set display fontname $2-
    }
    else _set display fontname $2-
  }
  elseif ($group(#display.mts) == on) {
    var %h = _systheme
    if ($1 isnum) {
      var %f = $2- $+ , $+ $1
      hadd %h fontdefault %f
      hadd %h fontquery %f
      hadd %h fontchan %f
    }
    else {
      hadd %h fontdefault $1- $+ , $+ $gettok($gts(fontdefault),2,44)
      hadd %h fontquery $1- $+ , $+ $gettok($gts(fontquery),2,44)
      hadd %h fontchan $1- $+ , $+ $gettok($gts(fontchan),2,44)
    }
  }
}
on *:start:{
  var %b = 0
  while (%b <= 15) {
    if (!$isfile($+(sys\,%b,.bmp))) _createbmp %b
    inc %b
  }
}
alias -l _createbmp {
  if (!$window(@_createbmp)) window -phf +f @_createbmp 0 0 16 16
  drawrect -f @_createbmp $1 1 0 0 400 400
  drawsave @_createbmp sys\ $+ $1 $+ .bmp
  .timer_createbmp 1 1 window -c @_createbmp
}
dialog display {
  title "Display settings"
  size -1 -1 312 174
  option dbu
  button "&Preview", 1, 184 161 30 12
  button "&Ok", 2, 216 161 30 12, ok
  button "&Cancel", 3, 248 161 30 12, cancel
  button "&Help", 4, 280 161 30 12
  check "Clear windows after applying changes.", 5, 4 161 105 10
  icon 7, 186 26 122 126,  $shortfn($mircexe), 16, hide
  box "Preview section:", 8, 186 17 123 139
  tab "Default", 9, -30 -30 420 250
  box "General:", 10, 4 18 97 50, tab 9
  text "Scheme:", 11, 7 26 30 8, tab 9 right
  text "Font name:", 12, 7 40 30 8, tab 9 right
  text "Font size:", 13, 7 54 30 8, tab 9 right
  combo 14, 38 25 58 80, tab 9 drop
  combo 15, 38 39 58 80, tab 9 edit drop
  combo 16, 38 52 58 80, tab 9 edit drop
  box "Prefixes:", 17, 4 68 97 33, tab 9
  text "Echo:", 18, 7 76 30 8, tab 9 right
  text "Actions:", 19, 6 88 30 8, tab 9 right
  combo 20, 38 74 58 50, tab 9 size edit drop
  combo 21, 38 86 58 50, tab 9 size edit drop
  box "Nickname brackets:", 22, 4 105 97 51, tab 9
  check "Align brackets around nicks.", 23, 9 113 83 10, tab 9
  text "Styles:", 24, 6 128 30 8, tab 9 right
  text "Alignment:", 25, 7 142 30 8, tab 9 right
  combo 26, 38 127 58 50, tab 9 size edit drop
  combo 27, 38 140 58 50, tab 9 size drop
  box "On join, show...:", 28, 105 18 76 66, tab 9
  check "Stats", 29, 113 27 40 10, tab 9
  check "Topic", 30, 113 37 40 10, tab 9
  check "Synch time", 31, 113 47 40 10, tab 9
  check "Names, and align..", 32, 113 57 57 10, tab 9
  combo 33, 122 69 52 50, tab 9 size drop
  box "Other settings:", 34, 105 123 76 33, tab 9
  check "Apply text displays.", 35, 113 132 57 10, tab 9
  check "Nick highlighting.", 36, 113 143 53 10, tab 9
  text "Incoming:", 61, 109 97 25 8, tab 9
  text "Outgoing:", 62, 109 108 25 8, tab 9
  box "Show CTCP...:", 60, 105 85 76 37, tab 9
  combo 63, 136 96 42 50, tab 9 size drop
  combo 64, 136 107 42 50, tab 9 size drop
  tab "Themes", 37
  text "Folder:", 38, 3 25 25 8, tab 37 right
  text "Theme:", 39, 3 37 25 8, tab 37 right
  text "Schemes:", 40, 3 49 25 8, tab 37 right
  edit "", 41, 30 23 81 11, tab 37 autohs
  combo 42, 30 35 81 150, tab 37 drop autohs
  combo 43, 30 48 81 150, tab 37 drop autohs
  button "&Change folder...", 44, 115 23 62 10, tab 37
  button "&More themes...", 45, 115 35 62 10, tab 37
  text "Author:", 46, 3 63 25 8, tab 37 right
  text "Email:", 47, 3 73 25 8, tab 37 right
  text "Website:", 48, 3 83 25 8, tab 37 right
  text "Version:", 49, 3 93 25 8, tab 37 right
  text "Author name", 50, 30 63 75 8, tab 37
  link "Author email", 51, 30 73 75 8, tab 37
  link "Author website", 52, 30 83 75 8, tab 37
  text "Theme version", 53, 30 93 75 8, tab 37
  edit "", 54, 7 104 104 52, tab 37 read multi vsbar

  ;box "Apply also...:", 55, 115 62 62 94, tab 37
  ;check "Images", 56, 124 85 45 10, tab 37
  ;check "Nicklist colors", 57, 124 97 46 10, tab 37
  ;check "Sounds", 58, 124 109 45 10, tab 37
  ;check "Text", 59, 124 121 45 10, tab 37
  box "Apply also...:", 55, 115 62 62 94, tab 37
  check "Images", 56, 124 82 45 10, tab 37
  check "Nicklist colors", 57, 124 94 46 10, tab 37
  check "Sounds", 58, 124 106 45 10, tab 37
  check "Text", 59, 124 118 45 10, tab 37
  check "All", 131, 124 129 39 10, tab 37

  tab "mIRC", 65
  text "Font name:", 68, 27 25 30 8, tab 65 right
  text "Font size:", 69, 27 35 30 8, tab 65 right
  combo 70, 59 23 62 80, tab 65 drop sort edit
  combo 71, 59 34 62 80, tab 65 drop sort edit
  check "Bold", 72, 128 23 35 10, tab 65
  box "Font:", 73, 4 17 179 31, tab 65
  box "Colors:", 74, 4 48 179 108, tab 65
  text "Action", 75, 6 55 30 8, tab 65 right
  text "CTCP", 76, 6 65 30 8, tab 65 right
  text "Highlight", 77, 6 75 30 8, tab 65 right
  text "Info", 78, 6 85 30 8, tab 65 right
  text "Info2", 79, 6 95 30 8, tab 65 right
  text "Invite", 80, 6 105 30 8, tab 65 right
  text "Join", 81, 6 115 30 8, tab 65 right
  text "Kick", 82, 6 125 30 8, tab 65 right
  text "Mode", 83, 6 135 30 8, tab 65 right
  text "Nick", 84, 6 144 30 8, tab 65 right
  text "Normal", 85, 69 55 30 8, tab 65 right
  text "Notice", 86, 69 65 30 8, tab 65 right
  text "Notify", 87, 69 75 30 8, tab 65 right
  text "Other", 88, 69 85 30 8, tab 65 right
  text "Own text", 89, 69 95 30 8, tab 65 right
  text "Part", 90, 69 105 30 8, tab 65 right
  text "Quit", 91, 69 115 30 8, tab 65 right
  text "Topic", 92, 69 125 30 8, tab 65 right
  text "Wallops", 93, 69 135 30 8, tab 65 right
  text "Whois", 94, 69 144 30 8, tab 65 right
  text "Listbox", 95, 132 55 30 8, tab 65 right
  text "Listbox text", 96, 132 65 30 8, tab 65 right
  text "Grayed", 97, 132 75 30 8, tab 65 right
  text "Title", 98, 132 85 30 8, tab 65 right
  text "Background", 99, 132 95 30 8, tab 65 right
  text "Editbox", 100, 132 105 30 8, tab 65 right
  text "Editbox text", 101, 132 115 30 8, tab 65 right
  text "Inactive", 102, 132 125 30 8, tab 65 right
  icon 103, 38 55 14 6, %0.bmp, tab 65
  icon 104, 38 65 14 6, %1.bmp, tab 65
  icon 105, 38 75 14 6, %2.bmp, tab 65
  icon 106, 38 85 14 6, %3.bmp, tab 65
  icon 107, 38 95 14 6, %4.bmp, tab 65
  icon 108, 38 105 14 6, %5.bmp, tab 65
  icon 109, 38 115 14 6, %6.bmp, tab 65
  icon 110, 38 125 14 6, %7.bmp, tab 65
  icon 111, 38 135 14 6, %8.bmp, tab 65
  icon 112, 38 145 14 6, %9.bmp, tab 65
  icon 113, 101 55 14 6, %10.bmp, tab 65
  icon 114, 101 65 14 6, %11.bmp, tab 65
  icon 115, 101 75 14 6, %12.bmp, tab 65
  icon 116, 101 85 14 6, %13.bmp, tab 65
  icon 117, 101 95 14 6, %14.bmp, tab 65
  icon 118, 101 105 14 6, %15.bmp, tab 65
  icon 119, 101 115 14 6, %16.bmp, tab 65
  icon 120, 101 125 14 6, %17.bmp, tab 65
  icon 121, 101 135 14 6, %18.bmp, tab 65
  icon 122, 101 145 14 6, %19.bmp, tab 65
  icon 123, 164 55 14 6, %20.bmp, tab 65
  icon 124, 164 65 14 6, %21.bmp, tab 65
  icon 125, 164 75 14 6, %22.bmp, tab 65
  icon 126, 164 85 14 6, %23.bmp, tab 65
  icon 127, 164 95 14 6, %24.bmp, tab 65
  icon 128, 164 105 14 6, %25.bmp, tab 65
  icon 129, 164 115 14 6, %26.bmp, tab 65
  icon 130, 164 125 14 6, %27.bmp, tab 65
  button "&Reset", 67, 132 142 43 11, tab 65
  text "Display system:", 6, 4 5 39 8
  combo 66, 45 4 65 50, size drop
}
alias display {
  var %i = 1, %a = action,ctcp,highlight,info,info2,invite,join,kick,mode,nick,normal,notice,notify,other,own,part,quit,topic,wallops,whois,listbox,listbox text,grayed,title,background,editbox,editbox text,inactive
  while ($gettok(%a,%i,44)) {
    set -u % $+ $calc(%i - 1) $+ .bmp sys\ $+ $colour($ifmatch) $+ .bmp
    inc %i
  }
  _opendlg display
}
alias _hi2lowasc { return $replace($1-,Ú,.,Ä,-,À,',Ã,|,³,|,¿,.,´,|,Â,.,Å,+,Á,+,Ù,') }
alias _blackbg { return 1,0,4,8,14,14,3,3,3,3,3,15,0,2,0,15,3,2,3,5,15,1,0,1,15,15,6,14 }
alias _whitebg { return 0,6,4,5,2,3,3,3,3,3,3,1,5,7,6,1,3,2,3,5,1,0,1,0,1,15,6,0 }
alias setRGB {
  var %i = 1
  while ($gettok($1-,%i,32)) {
    color $calc(%i - 1) $rgb( [ $ifmatch ] )
    inc %i
  }
}
alias -l _pre {
  if ($1 == 1) return &1ú&3ù&1ú
  if ($1 == 2) return &1.&3ø&1.
  if ($1 == 3) return &1(&3µ&1)
  if ($1 == 4) return &1•&3•&1•
  if ($1 == 5) return &1>&3>&1>
  if ($1 == 6) return &1ù&3í&1ù
  if ($1 == 7) return &1:&3:&1:
  if ($1 == 8) return &1*&1*&1*
  if ($1 == 9) return &1-&3-&1-
  if ($1 == 0) return &1ð&1ð&4ð
}
alias defaultfonts { return IBMPC,Hyperfont Lt.,Hyperfont,GwdTE_437,Terminal,MS Linedraw,PC8X16,PC8X14,PC6X13,PC8X8 }
alias -l _ddisable {
  did -c $1 66 1
  did -h $1 7
  did -b $1 1
  _mdid -b $1 7 64
}
on *:dialog:display:init:*:{
  didtok -a $dname 66 44 Default mIRC,Basic Classic,MTS Themes
  if ($_(display,method)) {
    var %num = $ifmatch
    did -c $dname 66 %num
    ;if (%num == 1) _ddisable $dname
    if (%num == 1) .timer -m 1 0 did -c $dname 65
    elseif (%num == 2) .timer -m 1 0 did -c $dname 9
    else .timer -m 1 0 did -c $dname 37
  }
  else {
    .timer -m 1 0 did -c $dname 65
    did -c $dname 66 1
    ;_ddisable $dname
  }
  ; schemes
  var %sch = Default;Gray;Green;Purple;Purple (White BG);B&W (White BG);Teal (White BG)
  didtok -a $dname 14 59 %sch
  if ($_istok(%sch,$_(display,scheme),59)) did -c $dname 14 $didwm(14,$ifmatch,1)
  else did -c $dname 14 1
  ; fonts
  var %fonts = $defaultfonts, %size = 8 9 10 11 12 13 14 15 16 17 18 19 20
  didtok -a $dname 15 44 %fonts
  didtok -a $dname 70 44 Arial, $+ %fonts $+ ,Courier,Courier New,Tahoma,Verdana,Fixedsys,MS Sans Serif,Comic Sans MS
  didtok -a $dname 16,71 32 %size
  if ($_(display,fontname)) {
    var %font = $ifmatch
    if (!$didwm(15,%font,1)) did -a $dname 15 %font
    did -c $dname 15 $didwm(15,%font,1)
  }
  else did -c $dname 15 $didwm(15,Terminal,1)
  if ($_(display,fontsize)) {
    var %size = $ifmatch
    if (!$didwm(16,%size,1)) did -a $dname 16 %size
    did -c $dname 16 $didwm(16,%size,1)
  }
  else did -c $dname 16 $didwm(16,12,1)
  ; prefixes
  var %i = 1, %_ap = ð ! * >
  while ($_pre(%i)) {
    did -a $dname 20 $ifmatch
    if ($gettok(%_ap,%i,32)) did -a $dname 21 $ifmatch nick action
    inc %i
  }
  ; action
  if ($act.pre != $null) { if ($_istok(%_ap,$ifmatch,32)) did -c $dname 21 $findtok(%_ap,$ifmatch,1,32) }
  else did -c $dname 21 1
  ; echo
  if ($didwm(20,$replace($pre,$c1,&c1,$c2,&c2,$c3,&c3,$c4,&c4,$c5,&c5),1)) did -c $dname 20 $ifmatch
  else did -c $dname 20 6
  ; brackets
  if ($_(display,alignbrackets)) did -c $dname 23
  did -a $dname 26 <nick>
  did -a $dname 26 [nick]
  did -a $dname 26 :nick:
  did -a $dname 26 (nick)
  did -c $dname 26 1
  var %l = $_repc($_(display,bracket.left)), %r = $_repc($_(display,bracket.right)), %n = $+(%l,nick,%r)
  var %defaultbrackets = <> [] :: ()
  if ($remove(%n,nick)) {
    if ($istok(%defaultbrackets,$ifmatch,32)) did -c $dname 26 $didwm(26,%n,1)
    else {
      did -a $dname 26 %n
      did -c $dname 26 $didwm(26,%n,1)
    }
  }
  else {
    var %x = 1, %left = < $chr(91) : $chr(40),%right = > $chr(93) : $chr(41)
    while (%x <= 4) {
      if (($_repc($_(display,bracket.left)) == $gettok(%left,%x,32)) && ($_repc($_(display,bracket.right)) == $gettok(%right,%x,32))) {
        did -c $dname 26 $didwm(26,$+($gettok(%left,%x,32),*),1)
        break
      }
      inc %x
    }
  }
  ; nick alignment
  did -a $dname 27 Left
  did -a $dname 27 Right
  if ($_(display,nickalignment)) did -c $dname 27 $didwm(27,$ifmatch,1)
  else did -c $dname 27 1
  ; on join
  if ($_(display,shownames)) did -c $dname 32
  if ($_(display,showsynch)) did -c $dname 31
  if ($_(display,showtopic)) did -c $dname 30
  if ($_(display,showstats)) did -c $dname 29
  ; /names alignment
  did -a $dname 33 Left
  did -a $dname 33 Right
  did -a $dname 33 Alt-Left
  did -a $dname 33 Alt-Right
  if ($_(display,alignnames)) did -c $dname 33 $didwm(33,$ifmatch,1)
  else did -c $dname 33 1
  ; ctcps
  didtok -a $dname 63,64 32 Status Active
  did -c $dname 63 $iif((a* iswm $_(display,ctcps_incoming)),2,1)
  did -c $dname 64 $iif((a* iswm $_(display,ctcps_outgoing)),2,1)
  ; other
  if ($_(display,clearwindows)) did -c $dname 5
  if ($_(display,basictext)) did -c $dname 35
  if ($_(display,nickhighlight)) did -c $dname 36
  ; mirc settings
  if ($didwm(70,$window(Status Window).font,1)) did -c $dname 70 $ifmatch
  if ($didwm(71,$window(Status Window).fontsize,1)) did -c $dname 71 $ifmatch
  ; themes
  var %t = $_(display,last.thm.dir)
  themelist $iif($isdir(%t),%t,themes\)
  ;if ($isdir(themes\)) {
  ;  !.echo -q $finddir(themes\,*,0,did -a $dname 42 $gettok($1-,-1,92))
  ;  did -ra $dname 41 themes\
  ;}
  did -r $dname 50,51,52,53,54
}
alias -l themelist {
  if (!$isdir($1-)) goto x
  did -r display 42
  !.echo -q $finddir($1-,*,0,1,did -a display 42 $gettok($1-,-1,92))
  did -ra display 41 $1-
  did -c display 42 1
  :x | _showdlg $dname
}
on *:dialog:display:sclick:131:_mdid $iif($did($did).state,-cb,-ue) $dname 56 59
on *:dialog:display:sclick:45:run http://www.mircscripts.org/files.php?type=theme
on *:dialog:display:edit:41:.timerThemeDirManualEdit 1 0 themelist $did(41)
on *:dialog:display:sclick:4:_bld $dname | bhelp display settings
on *:dialog:display:sclick:44:{
  var %dir = $sdir(\,Select a themes directory)
  themelist %dir
}
; both validators are based from Trystan's tutorial
on *:dialog:display:sclick:51:{
  var %email = $did(51).text, %re = /^[0-9a-z]([-_\.0-9a-z])*@[0-9a-z]([-\.]?[0-9a-z])*\.([a-z]){2,6}$/i
  if ($regex(%email,%re)) run mailto: $+ %email $+ ?subject=MTS theme
}
on *:dialog:display:sclick:52:{
  var %url = $did(52).text, %re = /^(http|ftp|https|irc)://[0-9a-z]([-\.]?[0-9a-z])*\.([a-z]){2,6}$/i
  if ($regex($replace($gettok(%url,1-2,47),:/,://),%re)) run %url
}
on *:dialog:display:sclick:1:{
  var %tab = $dialog($dname).tab
  ;set -u %orig.rgb 255,255,255 0,0,0 0,0,127 0,147,0 255,0,0 127,0,0 156,0,156 252,127,0 255,255,0 0,252,0 0,147,147 0,255,255 0,0,252 255,0,255 127,127,127 210,210,210
  if ($gts(rgbcolors)) set -u2 %orig.rgb $ifmatch
  else {
    var %r = 0, %rc
    while (%r <= 15) {
      %rc = %rc $rgb($color(%r))
      inc %r
    }
    set -u2 %orig.rgb %rc
  }
  if (%tab == 9) _preview
  elseif (%tab == 37) {

    var %tmptheme = $did(42).sel, %mtsdir = $did(41) $+ $did(42,%tmptheme) $+ \
    if ((!%tmptheme) || (!%mtsdir)) return

    %tmptheme = %mtsdir $+ $did(42,%tmptheme) $+ .mts
    if (!$isfile(%tmptheme)) {

      ; attempt if the theme dir is actually a file..
      %tmptheme = $did(41) $+ $did(42,$did(42).sel) $+ .mts

      ; check if there's some other .mts file inside that dir
      if ($findfile(%mtsdir,*.mts,1)) %tmptheme = $ifmatch

      if (!$isfile(%tmptheme)) {
        var %c = $str($crlf,2)
        %sys.last.dialog = $dname
        _err The theme file: $+ %c $+ %tmptheme $+ %c $+ you selected does not exist or is not a valid MTS theme file.
      }
    }

    var %ver = $read(%tmptheme,ns,mtsversion), %mts = $ini(%tmptheme,mts)
    if ((!%ver) || (%ver < $mtsversion)) {
      %sys.last.dialog = $dname
      _err Unsupported MTS version.
    }

    _progress Attempting to preview

    ; convert this into short filename to prevent errors
    %tmptheme = $shortfn(%tmptheme)

    _progress² 1 10 Checking for cache

    ; check if there's a cached bmp
    var %cache = $shortfn(%tmptheme) $+ $did(43).sel
    if ($_isfile($_(previewcache,%cache))) {
      var %pic = $ifmatch
      goto end
    }

    _progress² 2 10 Setting temporary variables

    ; load to temp hash table
    hmake _previewtheme 100
    var %w = $+(@_tmpwin,$ticks,$r(A,Z),$r(200,300))
    window -lh %w -1 -1 -1 -1
    loadbuf %w %tmptheme
    var %loop = $line(%w,0)
    while (%loop) {
      if ($gettok($line(%w,%loop),1,32) != $null) hadd _previewtheme $line(%w,%loop)
      dec %loop
    }
    window -c %w

    _progress² 3 10 Attempting to draw

    ; create hidden window
    var %win = $+(@_themepreview,$ticks,$r(A,Z),$r(300,400))
    window -hp %win 0 0 232 275

    %::window = %win

    _progress² 4 10 Loading colors

    ; do the colors
    set -u %::colors $hget(_previewtheme,colors)
    if ($did(43).sel) {
      var %topic = $+(scheme,$ifmatch)
      if ($ini(%tmptheme,%topic)) {
        var %swin = $+(@_tmpwinscheme,$ticks)
        window -h %swin
        loadbuf $+(-t,%topic) %swin %tmptheme
        var %i = $line(%swin,0)
        while (%i) {
          ; if ($line(%swin,%i) != $null) hadd _previewtheme $ifmatch
          if ($gettok($line(%swin,%i),1,32) != $null) hadd _previewtheme $line(%swin,%i)
          dec %i
        }
        window -c %swin
      }
    }

    set -u %::basecolors $hget(_previewtheme,basecolors)

    set -u %::rgb $hget(_previewtheme,rgbcolors)
    if (!%::rgb) set -u %::rgb %orig.rgb
    setRGB %::rgb

    set -u %::background $gettok(%::rgb, $calc($gettok($hget(_previewtheme,colors), 1,44) + 1),32)
    set -u %::textcolor  $gettok(%::rgb, $calc($gettok($hget(_previewtheme,colors),12,44) + 1),32)

    set -u %::c1 $gettok(%::basecolors,1,44)
    set -u %::c2 $gettok(%::basecolors,2,44)
    set -u %::c3 $gettok(%::basecolors,3,44)
    set -u %::c4 $gettok(%::basecolors,4,44)

    ; fill the bg first
    ;drawrect -f %::window $gettok(%::colors,1,44) 1 0 0 $window(%::window).w $window(%::window).h
    drawrect -rf %::window $rgb( [ %::background ] ) 1 0 0 $window(%::window).w $window(%::window).h

    ; fonts
    set -u2 %::font $gettok($hget(_previewtheme,fontchan),1,44)
    set -u2 %::fontsize $gettok($hget(_previewtheme,fontchan),2,44)
    set -u2 %:echo MTSdrawpreview
    set -u2 %::y 1

    ; other variables
    if (($hget(_previewtheme,timestamp) == on) && ($hget(_previewtheme,timestampformat))) set -u %::timestamp $time($mts2var($ifmatch))
    else unset %::timestamp
    if ($hget(_previewtheme,prefix)) set -u %::pre $mts2var($ifmatch)

    _progress² 5 10 Loading accompanying script

    ; load accompanying script
    if ($hget(_previewtheme,script)) {
      var %file = $+(%mtsdir,$ifmatch)
      if ($isfile(%file)) .load -rs $iif($chr(32) isin %file,$+(",%file,"),%file)
      else {
        window -c %::window
        %sys.last.dialog = display
        _err Unable to preview theme: Accompanying script file not found.
      }
    }
    _progress² 6 10 Drawing preview text

    ; now do the shitty preview
    var %tmp, %textchan
    if ($hget(_previewtheme,ctcpself)) {
      %tmp = $ifmatch
      set -u %::nick remote-
      set -u %::target remote-
      set -u %::ctcp HELP
      te %tmp
    }
    if ($hget(_previewtheme,notice)) {
      %tmp = $ifmatch
      set -u %::nick remote-
      set -u %::address dub@wildfire.moo.net
      set -u %::text *** channel flags for #timesink: a
      te %tmp
      set -u %::text $str( ,3) a: you will be auto-opped on #timesink on join
      te %tmp
    }
    if ($hget(_previewtheme,mode)) {
      %tmp = $ifmatch
      set -u %::chan #mIRC
      set -u %::nick Sojatwork
      set -u %::modes +b *!*@kg55u2hel.dial.kolumbus.fi
      te %tmp
    }
    if ($hget(_previewtheme,kick)) {
      %tmp = $ifmatch
      set -u %::nick BluFire
      set -u %::knick backdrop
      set -u %::chan #mIRC
      set -u %::text banned: Moron 09/19/2000
      set -u %::parentext %::text
      set -u %::parentext $mts2var($hget(_previewtheme,parentext))
      te %tmp
    }
    ; whois
    unset %::timestamp
    set -u %::nick Khaled
    set -u %::address khaled@mardam.demon.co.uk
    set -u %::realname arnie says feed me
    set -u %::chan #mIRC
    set -u %::wserver efnet.demon.co.uk
    set -u %::server efnet.demon.co.uk
    set -u %::serverinfo the server that never sleeps
    if ($hget(_previewtheme,whois)) te $ifmatch
    else {
      if ($hget(_previewtheme,raw.311)) te $ifmatch
      if ($hget(_previewtheme,raw.319)) te $ifmatch
      if ($hget(_previewtheme,raw.312)) te $ifmatch
      if ($hget(_previewtheme,raw.318)) te $ifmatch
    }

    ; reset timestamp after the whois preview is done
    if (($hget(_previewtheme,timestamp) == on) && ($hget(_previewtheme,timestampformat))) set -u %::timestamp $time($mts2var($ifmatch))

    if ($hget(_previewtheme,notify)) {
      %tmp = $ifmatch
      set -u %::nick xix
      set -u %::address borg@205.139.183.41
      set -u %::text creator of b0rg
      set -u %::parentext %::text
      set -u %::parentext $mts2var($hget(_previewtheme,parentext))
      te %tmp
    }
    if ($hget(_previewtheme,nick)) {
      %tmp = $ifmatch
      set -u %::chan #mIRC
      set -u %::nick shanezzz
      set -u %::newnick shane
      te %tmp
    }
    if ($hget(_previewtheme,actionchan)) {
      %tmp = $ifmatch
      set -u %::chan #mIRC
      set -u %::target #mIRC
      set -u %::nick dev-
      set -u %::text is away: tv [lp/on]
      if ($r(1,20) < 10) set -u %::cmode $iif($r(1,2) == 1,@,+)
      else set -u %::cmode $chr(160)
      te %tmp
      set -u %::text is back -- gone for 3s
      te %tmp
    }
    if ($hget(_previewtheme,textchan)) {
      %textchan = 1
      %tmp = $ifmatch
      set -u %::chan #mIRC
      set -u %::nick Music^Dude
      set -u %::cmode @
      set -u %::text ×|Mp3z-Op Script|AutoVoice|× Thank you TestMan for serving your mp3s in #mp3z
      set -u %::chan #mIRC
      te %tmp
      set -u %::nick MbiZKitM
      set -u %::cmode @
      set -u %::text TestMan is AutoVoiced (+v) in #mp3z . PhatVoicer by ×MbiZKitM× Thanx For Serving!!!
      te %tmp
      set -u %::nick TestMan
      set -u %::text For My List(6153files:27021MB) and DCC Status, type @TestMan and @TestMan-stats.
      te %tmp
      unset %::cmode
      set -u %::nick mechiman
      set -u %::text @find falling
    }
    if ($hget(_previewtheme,quit)) {
      %tmp = $ifmatch
      set -u %::nick Snert
      set -u %::address bdc@snert.accesspro.net
      set -u %::text rebooting
      set -u %::parentext rebooting
      set -u %::parentext $mts2var($hget(_previewtheme,parentext))
      set -u %::chan #mIRC
      te %tmp
    }
    if ($hget(_previewtheme,join)) {
      %tmp = $ifmatch
      set -u %::nick Snert
      set -u %::address bdc@snert.accesspro.net
      set -u %::chan #mIRC
      unset %::parentext %::text
      te %tmp
    }
    if (%textchan) {
      %tmp = $hget(_previewtheme,textchan)
      set -u %::chan #mIRC
      set -u %::cmode @
      set -u %::nick remote-
      set -u %::text people should use their userlists more often
      te %tmp
      set -u %::text less chance of losing the ops in the chan
      te %tmp
      set -u %::cmode +
      set -u %::nick demun
      set -u %::text mp3, Jimi Hendrix [ The Jimi Hendrix Experience ] - Sweet Angel [4m12s]
      te %tmp
      set -u %::nick assman
      set -u %::text kewl.. any idea how to get easily a word infront of that line?
      unset %::cmode
      te %tmp
      set -u %::nick rickcp
      set -u %::cmode +  
      set -u %::text just need the text file with the codes
      te %tmp
      set -u %::nick assman
      set -u %::text could you send it to me?
      unset %::cmode
      te %tmp
    }

    _progress² 7 10 Unloading script file

    ; the timer is to prevent mIRC from going into an unexplainable endless loop...
    if (($script($hget(_previewtheme,script))) && ($ifmatch != $gts(script))) { .timer 1 0 .unload -rsn $+(",$ifmatch,") }

    _progress² 8 10 Saving preview cache

    var %pic = temp\ $+ %::window $+ .bmp
    drawsave %::window %pic
    _set previewcache $shortfn(%tmptheme) $+ $did(43).sel %pic
    :end

    _progress² 9 10 Updating image
    did -g $dname 7 %pic
    did -ev $dname 7
    if ($window(%::window)) window -c $ifmatch
    ;.remove %pic
    .timer 1 0 _hfree _previewtheme

    _progress² 10 10 Preview successful
    _showdlg $dname

  }
  elseif (%tab == 65) {
    if (!$did(70)) halt
    var %w = @_mIRCpreview. $+ $ticks, %cmd = _mIRCdrawpreview %w
    set -u %.mIRCpreview.font $did(70)
    set -u %.mIRCpreview.size $did(71)
    if ($chr(32) isin %.mIRCpreview.font) set -u %.mIRCpreview.font $+(",%.mIRCpreview.font,")
    if ($did(72).state) set -u %.mIRCpreview.bold $true
    else set -u %.mIRCpreview.bold $false
    setRGB 255,255,255 0,0,0 0,0,127 0,147,0 255,0,0 127,0,0 156,0,156 252,127,0 255,255,0 0,252,0 0,147,147 0,255,255 0,0,252 255,0,255 127,127,127 210,210,210
    set -u %.mIRCpreview.y 1
    set -u %.tmp.back $mpcolor(background)
    window -hp %w 0 0 232 275
    drawrect -f %w %.tmp.back 0 0 0 250 280
    var %i = 1
    while ($gettok(ctcp notice mode kick whois notify nick action quit normal,%i,32)) {
      set -u %.tmp. $+ $ifmatch $mpcolor($ifmatch)
      inc %i
    }
    %cmd %.tmp.ctcp -> [remote] PING
    %cmd %.tmp.notice -remote- *** channel flags for #timesink: a
    %cmd %.tmp.notice -remote- $str( ,3) a: you will be auto-opped on #timesink on join
    %cmd %.tmp.mode *** Sojatwork sets mode: +b *!*@kg55u2hel.dial.kolumbus.fi
    %cmd %.tmp.kick *** backdrop was kicked by BluFire (banned: Moron 09/19/2000)
    %cmd %.tmp.whois user is void@rox-38CC09D2 * insert witty comment here
    ; if you're really old school, you'd know about this irc.nol.net :)
    %cmd %.tmp.whois user is using irc.nol.net - can't we all just get a bong?
    %cmd %.tmp.whois user has been idle 2secs, signed on Wed Mar 06 21:38:10
    %cmd %.tmp.whois user End of /WHOIS list.
    %cmd %.tmp.notify *** xix is on IRC
    %cmd %.tmp.nick *** shanezzz is now known as shane
    %cmd %.tmp.action * dev- is away: tv [lp/on]
    %cmd %.tmp.action * dev- is back -- gone for 3s
    %cmd %.tmp.quit *** Snert has quit IRC (rebooting)
    %cmd %.tmp.quit *** Snert (bdc@snert.accesspro.net) has joined #mIRC
    %cmd %.tmp.normal <@remote-> people should use their userlists more often
    %cmd %.tmp.normal <@remote-> less chance of losing the ops in the chan
    %cmd %.tmp.normal <+demun> mp3, Jimi Hendrix [ The Jimi Hendrix Experience ] - Sweet Angel [4m12s]
    %cmd %.tmp.normal <assman> kewl.. any idea how to get easily a word infront of that line?
    %cmd %.tmp.normal <+rickcp> just need the text file with the codes
    %cmd %.tmp.normal <assman> could you send it to me?
    %cmd %.tmp.ctcp ;If you can read this,;
    %cmd %.tmp.ctcp ;you're using a very  ;
    %cmd %.tmp.ctcp ;small font size....  ;
    drawdot %w
    setRGB %orig.RGB
    var %pic = temp\_mIRCpreview $+ $calc($ticks * 3) $+ .bmp
    drawsave %w %pic
    did -g $dname 7 %pic
    did -ev $dname 7
    window -c %w
    .remove %pic
  }
  setRGB %orig.RGB
}
alias MTSdrawpreview {
  drawtext -rpb %::window $rgb( [ %::textcolor ] ) $rgb( [ %::background ] ) $+(",%::font,") %::fontsize 1 %::y $1-
  inc %::y $height(|,%::font,%::fontsize)
}
alias -l _mIRCdrawpreview {
  drawtext $iif(%.mIRCpreview.bold,-npob,-npb) $1 $2 %.tmp.back %.mIRCpreview.font %.mIRCpreview.size 1 %.mIRCpreview.y $3-
  inc -u2 %.mIRCpreview.y $height($3-,%.mIRCpreview.font,%.mIRCpreview.size)
}
alias -l mpcolor {
  if ($hget(@display,$1) isnum) return $ifmatch
  return $color($1)
}
;  (t)heme (e)cho
alias -l te {
  if ($1 == !script) $($2-,2)
  else %:echo %::timestamp $mts2var($1-)
}
on *:dialog:display:sclick:9:did -c $dname 66 2
on *:dialog:display:sclick:37:did -c $dname 66 3
on *:dialog:display:sclick:66:if ($did(66).sel) did -c $dname $replace($ifmatch,1,65,3,37,2,9)
on *:dialog:display:sclick:67:resetmirccolors
on *:dialog:display:sclick:42:{
  if (!$did(42).sel) return
  var %s = $did(42).sel, %f = $did(41) $+ $did(42,%s) $+ \ $+ $did(42,%s) $+ .mts
  if (!$isfile(%f)) return
  if ($read(%f,ns,author)) did -o $dname 50 1 $ifmatch
  else did -r $dname 50
  if ($read(%f,ns,email)) did -o $dname 51 1 $ifmatch
  else did -r $dname 51
  if ($read(%f,ns,website)) did -o $dname 52 1 $ifmatch
  else did -r $dname 52
  if ($read(%f,ns,version)) did -o $dname 53 1 $ifmatch
  else did -r $dname 53
  did -r $dname 54
  if ($read(%f,ns,description)) {
    did -a $dname 54 $ifmatch
    did -c $dname 54 1
  }
  did -r $dname 43
  var %w = @_scheme_ $+ $ticks, %i = 1
  window -hl %w
  filter -cfw $+(",%f,") %w SCHEME*
  while ($line(%w,%i)) {
    did -a $dname 43 $gettok($ifmatch,2-,32)
    inc %i
  }
  window -c %w
}
alias -l _me {
  var %right = $+(,%::c1,%bracket.right,), %left = $+(,%::c1,%bracket.left,), %o = $+(,%::c2,@), %v = $+(,%::c2,+)
  var %nick = $_stripprefix($1), %me
  if ($did(display,23).state) {
    if ($did(display,27) == right) {
      if (!$_mopt(2,30)) %me = $_xalign(%nick,11)
      elseif (:* iswm $1) %me = $_xalign(%nick,11)
      else %me = $+($left($1,1),$_xalign(%nick,10))
    }
    else {
      if (!$_mopt(2,30)) %me = $align(%nick,11)
      elseif (:* iswm $1) %me = $+( ,$align(%nick,10))
      else %me = $+($left($1,1),$align(%nick,10))
    }
    %me = $+(%left,$replace(%me,@,%o,+,%v),%right)
  }
  else {
    if ((!$_mopt(2,30)) || (:* iswm $1)) %me = %nick
    else %me = $replace($remove($1,:),@,%o,+,%v)
    %me = $+(%left,%me,%right)
  }
  return %me
}
alias -l _stripprefix { return $remove($1,+,:,@) }
alias -l _colorscheme {
  goto $1
  :default | return 10 11 16 11 14
  :gray    | return 14 14 16 14 14
  :green   | return 09 09 03 09 03
  :purple  | return 06 13 16 13 16
  :purple2 | return 06 13 01 13 06
  :b&w2    | return 01 01 01 01 01
  :teal2   | return 10 05 01 10 05
}
alias -l amp2var {
  var %f = IBMPC,Hyperfont Lt.,Hyperfont,GwdTE_437,Terminal,MS Linedraw,PC8X16,PC8X14,PC6X13,PC8X8, %t = $replace($1,&1,%::c1,&2,%::c2,&3,%::c3,&4,%::c4,&5,%::c5)
  if (!$istok(%f,%::font,44)) return $_hi2lowasc(%t)
  return %t
}
alias drawpreview {
  if ($amp2var($1-) != $null) drawtext -pb %::window $gettok(%::colors,12,44) $gettok(%::colors,1,44) $+(",%::font,") %::fontsize 1 %::y $ifmatch
  inc %::y $height(|,%::font,%::fontsize)
}
alias -l _preview {

  var %win = $+(@_preview,$ticks,$r(A,Z)), %white = (White BG)
  set -u %::window %win

  ;window -hp %win 0 0 246 280
  window -hp %win 0 0 232 275
  if (%white isin $did(14)) drawrect -rf %win $rgb(255,255,255) 0 0 0 300 300
  else drawrect -rf %win $rgb(0,0,0) 0 0 0 310 300

  ; font
  set -u %::font $did(display,15)
  set -u %::fontsize $did(display,16)
  if (!%::font) _err No font name specified.
  if (%::fontsize !isnum) _err No font size specified.

  ; all colors
  if ($istok(Default Gray Green Purple,$did(display,14),32)) set -u %::colors $_blackbg
  elseif (*B&W* iswm $did(display,14)) set -u %::colors 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,15,1,0
  elseif (*Teal* iswm $did(display,14)) set -u %::colors 0,10,4,5,2,3,3,3,3,3,3,1,5,7,6,1,3,2,3,5,1,0,1,0,1,15,6,0
  else set -u %::colors $_whitebg

  ; color scheme
  tokenize 32 $_colorscheme($remove($replace($did(display,14),%white,2),$chr(32)))
  ; set -u %::rgb 255,255,255 0,0,0 0,0,127 0,147,0 255,0,0 127,0,0 156,0,156 252,127,0 255,255,0 0,252,0 0,147,147 0,255,255 0,0,252 255,0,255 127,127,127 210,210,210
  setRGB 255,255,255 0,0,0 0,0,127 0,147,0 255,0,0 127,0,0 156,0,156 252,127,0 255,255,0 0,252,0 0,147,147 0,255,255 0,0,252 255,0,255 127,127,127 210,210,210
  set -u %::c1 $1
  set -u %::c2 $2
  set -u %::c3 $3
  set -u %::c4 $4
  set -u %::c5 $5

  set -u %::background 0,0,0
  set -u %::textcolor 210,210,210

  ; prefix
  set -u %pre $amp2var($did(display,20))

  ; brackets
  var %b = $did(display,26)
  if (*nick* !iswm %b) {
    %sys.last.dialog = display
    _err Invalid nickname bracket format. Insert the word "nick" between the brackets.
  }
  if ($regex($remove(%b,nick),[a-zA-Z])) {
    %sys.last.dialog = display
    _err Unable to use letters as brackets.
  }
  if (nick* iswm %b) set -u %bracket.left
  else {
    var %pos = $calc($pos(%b,n,1) - 1)
    set -u %bracket.left $mid(%b,%pos,1)
    dec %pos
    while (%pos) {
      set -u %bracket.left $mid(%b,%pos,1) $+ %bracket.left
      dec %pos
    }
  }
  if (*nick iswm %b) set -u %bracket.right
  else set -u %bracket.right $mid(%b,$calc($pos(%b,k,1) + 1))


  ; start drawing?

  set -u %::y 1
  set -u %cmd drawpreview

  %cmd %pre Nick &3blue-elf` is in use.
  %cmd -> &2[&3ctcp&2(&3remote-&2)]&3 HELP
  %cmd &5-remote- (dub@wildfire.moo.net)- *** channel flags for #timesink: a
  %cmd &5-remote- (dub@wildfire.moo.net)- $str( ,3) a: you will be auto-opped on #timesink on join
  %cmd %pre &1Mode: &1(Sojatwork&1:&3#mIRC +b *!*@kg55u2hel.dial.kolumbus.fi&1)
  %cmd %pre &3backdrop&1 was kicked by&3 BluFire &1(&3banned: Moron 09/19/2000&1)
  %cmd &1Ú&4Ä&1(&3 user &1) $+ $str(Ä,18) $+ &4Ä-&1ÄÄ-&4-Ä&1ÄÄ-Ä¿
  %cmd &1| &4: user (bdc@203.166.69.33) $str( ,9) &1|
  %cmd &1³&5 &4: insert witty comment here $str( ,8) &1:
  %cmd &1³&5 &4: irc.sprynet.com $str( ,18) &1|
  %cmd &1ÀÄ&4Ä&1ÄÄÄÄÄÄÄ&5ÄÄ&1-&4Ä&1ÄÄÄÄÄ&4 --&1--ÄÄÄÄ(&3 whois &1) -Ù
  %cmd %pre &1Notify:&3 xix &1(&3borg&4@&3205.139.183.41&1) is on IRC.
  %cmd %pre &3shanezzz &1is now known as&3 shane
  %cmd &1 $+ $remove($did(display,21),nick action) &3dev- $+ $gettok(%::colors,2,44) is away: tv [lp/on]
  %cmd &1 $+ $remove($did(display,21),nick action) &3dev- $+ $gettok(%::colors,2,44) is back -- gone for 3s
  %cmd $_me(@Music^Dude) ×|Mp3z-Op Script|AutoVoice|× Thank you TestMan for serving your mp3s in #mp3z
  %cmd $_me(@MbiZKitM) TestMan is AutoVoiced (+v) in #mp3z . PhatVoicer by ×MbiZKitM× Thanx For Serving!!!
  %cmd $_me(+TestMan)  •••  For My List(6153files:27021MB) and DCC Status, type @TestMan and @TestMan-stats. [(0/2) Slots (0/25) Ques Taken] [Next Send: Open Slot Ready] [CPS in Use: 8155] [Highest Cps Record: 20.3 by Grinf] [Total File Served: 7045]  ••• 
  %cmd $_me(:mechiman) @find falling
  %cmd %pre &1Quits&4 $+ :&3 Snert &1(&3bdc&4@&3snert.accesspro.net&1) &4: rebooting
  %cmd %pre &1Joins&4:&3 Snert &1(&3bdc&4@&3snert.accesspro.net&1)
  %cmd $_me(@remote-) $+  people should use their userlists more often
  %cmd $_me(@remote-) $+  less chance of losing the ops in the chan
  %cmd $_me(+demun) $+  mp3, Jimi Hendrix [ The Jimi Hendrix Experience ] - Sweet Angel [4m12s]
  %cmd $_me(:assman) $+  kewl.. any idea how to get easily a word infront of that line?
  %cmd $_me(+rickcp) $+  just need the text file with the codes
  %cmd $_me(:assman) $+  could you send it to me?
  %cmd 4[if you can read this,
  %cmd 4 you're using a very
  %cmd 4 small font size]

  if (!$isdir(temp\)) .mkdir temp\
  var %f = $+(temp\,%win,.bmp)
  drawsave %win %f
  did -g display 7 %f
  did -v display 7
  .remove %f
  window -c %win
}
alias restoreRGB {
  var %i = 0
  while (%i <= 15) {
    color -r %i
    inc %i
  }
}
on *:dialog:display:sclick:2:{
  var %sel = $did(66).sel
  .timestamp off
  .timestamp -f [HH:nn]
  ; make sure those toolbar buttons go away!
  undo.images
  ; normal mIRC
  if (%sel == 1) {
    ;_display.restore
    if (!$did(70)) { beep | halt }
    _set theme loaded
    _set display method $did(66).sel
    _cnickrem
    themeunload
    .disable #display.basic #display.mts #mts.text #basic.text
    restoreRGB
    applymirccolors
    applymircfonts $iif($did(72).state,b) $did(71) $did(70)
    if ($did(5).state) scid -a clearall
  }
  ; Basic
  elseif (%sel == 2) {
    %sys.last.dialog = display
    if (!$isfile(sys\btheme.mrc)) _err Unable to use Basic classic display settings. Required file not found.
    if (!$did(15)) _err No font name specified.
    if (!$did(16)) _err No font size specified.
    if (*nick* !iswm $did(26)) _err Invalid nickname bracket format. Insert the word "nick" between the brackets.
    if ($regex($remove($did(26),nick),[a-zA-Z])) _err Unable to use letters as brackets.
    if ($regex($remove($did(21),nick action),[a-zA-Z])) _err Unable to use letters as action prefix.
    ; backup
    ; if ($_(theme,loaded) == $null) displaybackup
    _set display method $did(66).sel
    _cnickrem
    ; scheme
    restoreRGB
    var %white = (White BG)
    _set display scheme $did(14)
    tokenize 32 $_colorscheme($remove($replace($did(14),%white,2),$chr(32)))
    .alias c1 return $1
    .alias c2 return $2
    .alias c3 return $3
    .alias c4 return $4
    .alias c5 return $5
    ; prefixes (it goes here so that the colors are correct)
    .alias pre return $replace($did(20),&1,$1,&2,$2,&3,$3,&4,$4,&5,$5)
    .alias act.pre return $remove($did(21),nick action)
    ; brackets
    _set display alignbrackets $did(23).state
    _set display nickalignment $did(27)
    ; nick brackets
    ; brackets
    var %b = $did(26)
    if (nick* iswm $did(26)) _set display bracket.left
    else {
      var %pos = $calc($pos(%b,n,1) - 1), %bl
      %bl = $mid(%b,%pos,1)
      dec %pos
      while (%pos) {
        %bl = $mid(%b,%pos,1) $+ %bl
        dec %pos
      }
      _set display bracket.left %bl
    }
    if (*nick iswm %b) _set display bracket.right
    else _set display bracket.right $mid(%b,$calc($pos(%b,k,1) + 1))
    ; on join
    _set display showstats $did(29).state
    _set display showtopic $did(30).state
    _set display showsynch $did(31).state
    _set display shownames $did(32).state
    _set display alignnames $did(33)
    ; ctcps
    _set display ctcps_incoming $did(63)
    _set display ctcps_outgoing $did(64)
    ; extras
    _set display basictext $did(35).state
    _set display nickhighlight $did(36).state
    ; colors
    var %colors
    if ($istok(Default Gray Green Purple,$did(14),32)) %colors = $_blackbg
    elseif (*B&W* iswm $did(14)) %colors = 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,15,1,0
    elseif (*Teal* iswm $did(14)) %colors = 0,10,4,5,2,3,3,3,3,3,3,1,5,7,6,1,3,2,3,5,1,0,1,0,1,15,6,0
    else %colors = $_whitebg
    var %i = 1, %array = $_syscoloritems
    while ($gettok(%colors,%i,44) != $null) {
      color $gettok(%array,%i,44) $ifmatch
      inc %i
    }
    ; font
    _set display fontname $did(15)
    _set display fontsize $did(16)
    scid -a _chfonts $did(16) $did(15)
    ; do the load/unload
    themeunload
    _set theme loaded basic
    _set display method $did(66).sel
    .disable #display.mts #mts.text
    .enable #display.basic
    $iif($did(35).state,.enable,.disable) #basic.text
    if ($did(5).state) scid -a clearall
  }
  ; MTS
  else {
    %sys.last.dialog = $dname
    ; make sure we can load this file  
    if (!$isfile(sys\mtheme.mrc)) _err Unable to use MTS. Required script file not found.
    var %dir = $did(41), %theme = $did(42), %file = %dir $+ %theme $+ \ $+ %theme $+ .mts
    if ($findfile($+(%dir,%theme),*.mts,1)) %file = $ifmatch
    if (!$isdir(%dir)) _err Unable to use MTS. Speficied folder does not exist.
    if (!$isfile(%file)) _err Unable to use MTS. Specified theme does not exist.
    ; remember settings
    _set display mts.scheme   $did(43).sel
    _set display mts.images   $did(56).state
    _set display mts.nicklist $did(57).state
    _set display mts.sounds   $did(58).state
    ;_set display mts.text     $did(59).state
    _set display method $did(66).sel
    ; load only if it's not yet loaded
    .disable #display.basic #basic.text
    .enable #display.mts
    ;themeload $did(43).sel %theme
    if ($did(5).state) scid -a clearall
    themeload $did(43).sel $shortfn(%file)
    $iif($did(59).state,.enable,.disable) #mts.text
  }
  _set display clearwindows $did(5).state
  _set display last.thm.dir $did(41)
  ; I need this below because mIRC doesn't want to close the dialog after loading an MTS theme...
  ; weird bug...
  .timer 1 0 displayclose
}
alias -l displayclose {
  _hfree @_boring @display _previewtheme
  if ($dialog(display)) dialog -x $ifmatch
  window -c @_boring
}
on *:dialog:display:sclick:3:{
  _set display last.thm.dir $did(41)
  displayclose
}
alias _chfonts {
  font -ds $1-
  var %i = 1
  while ($chan(%i)) {
    font -d $ifmatch $1-
    inc %i
  }
  var %i = 1
  while ($query(%i)) {
    font -d $ifmatch $1-
    inc %i
  }
  var %i = 1
  while ($chat(%i)) {
    font -d $+(=,$ifmatch) $1-
    inc %i
  }
}
on *:dialog:display:sclick:*:{
  if ($did isnum 103-130) {
    did -f $dname $did
    _colorbox $did
    set %lastdisplaybox $did
  }
  elseif ($did == 3) window -c @_boring
}
alias _colorbox {
  if ($window(@_boring)) window -a @_boring $mouse.dx $mouse.dy $window(@_boring).w $window(@_boring).h
  else {
    window -hpdf +fL @_boring $mouse.dx $mouse.dy 65 80 @_boring
    drawrect -rnf @_boring $rgb(255,255,255) 0 0 0 65 80
    var %i = 0, %y = 1, %c = 1, %x = 1
    while (%i <= 15) {
      drawrect -fn @_boring %i 1 %x %y 15 15
      hadd -m @_boring coords. $+ %i %x %y 15 15
      inc %x 16
      inc %c
      inc %i
      if (%c == 5) { var %x = 1, %c = 1 | inc %y 16 }
    }
  }
  drawrect -rfn @_boring $rgb(face) 0 0 65 65 15
  if ($assoc($1)) drawtext -rn @_boring $rgb(text) "MS Sans Serif" -8 2 67 $gettok($ifmatch,2-,32)
  drawdot @_boring
  window -a @_boring
}
alias -l applymirccolors {
  var %i = 1
  while ($hmatch(@display,*,%i)) {
    color $lower($replace($ifmatch,.,$chr(32))) $hget(@display,$ifmatch)
    inc %i
  }
}
; /applymircfonts [b] <fontsize> <fontname>
alias -l applymircfonts {
  var %s = 1
  while ($scon(%s)) {
    scid $ifmatch
    var %x = 1, %nochans = 1
    while ($chan(%x)) {
      if ($1 == b) font -bd $chan(%x) $2-
      else font -d $chan(%x) $1-
      if (%nochans) %nochans = 0
      inc %x
    }
    if (%nochans) _syswritefonts fchannel $1-
    var %x = 1, %nochats = 1
    while ($query(%x)) {
      if ($1 == b) font -bd $query(%x) $2-
      else font -d $query(%x) $1-
      if ($chat(%x)) {
        if ($1 == b) font -bd $+(=,$chat(%x)) $2-
        else font -d $+(=,$chat(%x)) $1-
      }
      if (%nochats) %nochats = 0
      inc %x
    }
    if (%nochats) _syswritefonts fquery $1-
    if ($1 == b) font -sbd $2-
    else font -sd $1-
    inc %s
  }
  scid -r
}
alias -l resetmirccolors {
  var %i = 1, %colors = 6 4 5 2 3 3 3 3 3 3 1 5 7 6 1 3 2 3 5 1 0 1 15 6 0 0 1 0
  while ($gettok(%colors,%i,32) != $null) {
    did -g display $calc(%i + 102) sys\ $+ $ifmatch $+ .bmp
    hadd -m @display $replace($gettok($assoc($calc(%i + 102)),2-,32),$chr(32),.) $gettok(%colors,%i,32)
    inc %i
  }
}
menu @_boring {
  mouse:{
    var %i = 0
    while (%i <= 15) {
      tokenize 32 $hget(@_boring,$+(coords.,%i))
      if ($inrect($mouse.x,$mouse.y,$1,$2,$3,$4)) {
        var %tmp = $calc($1 -1) $calc($2 -1) $calc($3 + 2) $calc($4 + 2)
        if (%lastbox) { if ($ifmatch != %tmp) drawrect @_boring 0 $ifmatch }
        set %lastbox 1 %tmp
        set %lastsel %i
        drawrect @_boring 1 %lastbox
        break
      }
      else inc %i
    }
  }
  leave:_redraw
  sclick:{
    if ((%lastsel isnum 0-15) && (%lastdisplaybox)) {
      if ($dialog(display)) {
        did -g display %lastdisplaybox sys\ $+ %lastsel $+ .bmp
        hadd -m @display $replace($gettok($assoc(%lastdisplaybox),2-,32),$chr(32),.) %lastsel
      }
      _redraw

    }
    _boring
    _showdlg display
  }
  $_realname :return
}
on *:close:@_boring:_boring
alias -l _boring { unset %lastsel %lastdisplaybox %lastbox }
alias -l _redraw {
  if (%lastbox) {
    drawrect @_boring 0 $ifmatch
    unset %lastbox
  }
}
; $assoc(id)
; associate id with name
alias assoc {
  var %f = $1
  goto $1
  :103 | return 75 Action
  :104 | return 76 CTCP
  :105 | return 77 Highlight
  :106 | return 78 Info
  :107 | return 79 Info2
  :108 | return 80 Invite
  :109 | return 81 Join
  :110 | return 82 Kick
  :111 | return 83 Mode
  :112 | return 84 Nick
  :113 | return 85 Normal
  :114 | return 86 Notice
  :115 | return 87 Notify
  :116 | return 88 Other
  :117 | return 89 Own text
  :118 | return 90 Part
  :119 | return 91 Quit
  :120 | return 92 Topic
  :121 | return 93 Wallops
  :122 | return 94 Whois
  :123 | return 95 Listbox
  :124 | return 96 Listbox text
  :125 | return 97 Grayed
  :126 | return 98 Title
  :127 | return 99 Background
  :128 | return 100 Editbox
  :129 | return 101 Editbox text
  :130 | return 102 Inactive
  :%f
}
alias -l undo.images {
  var %x = 1
  while ($mid(amsgdluh,%x,1)) {
    background -x $+ $ifmatch
    inc %x
  }
  scid -a undo.images2
}
alias -l undo.images2 {
  var %i = 1
  while ($chan(%i)) {
    background -x $ifmatch
    inc %i
  }
  %i = 1
  while ($query(%i)) {
    background -x $ifmatch
    inc %i
  }
}
; eof