/*
* DCX Studio for mIRC v1.4
* ========================
*
* author: twig*
* home: #genscripts on AmeriChat
*
* shoutouts:
* - ClickHeRe
* - schnoodles
* - da^hype
* - Sky-Net (for some of the icons)
* - hixxy
* - LemonButt
* - dJabba
*
* usage:
* - extract files and type /load -rs dcxstudio.mrc
* - after that, type /dcxstudio to start it up
*
* 
* feel free to report any bugs or suggest features directly to me, or on the DCX forums.
* view the readme.txt for additional information and some usage tips!



todo list (items marked with ! cannot be resolved in this version of DCX)
---------
- fix bug with panels and tab objects being misplaced on import
- add options to fade in on startup
- show parent id and type on properties dialog
- ability to change msg colors (mruno)
------
<@da^hype> [twig]: i think the "script generator" you should make it resizeable
------
[9:31:49a] <hixxy> another bug/annoyance: the thumb on scrollbars flashes every second
------
[1:13:07p] <@Ami> one thing i would suggest tho
[1:13:10p] <@Ami> code templates
[1:13:19p] <@Ami> for example they could write a file
[1:13:23p] <@Ami> and use keywords
[1:13:30p] <@Ami> and the generated script would use that
[1:13:46p] <@Ami> like On *:$(EventName):....
[1:14:03p] <@Ami> that way the format of the generated script can be whatever i want
------


WILL do
- CLA editor (waiting for CLA clear/reset command. actually could be possible without clearing,
just havent had time to play around with it)
- object browser


(cant do's/dont know how to/cant be bothered to do)
- implementing sorting methods
- sort asc/desc for listview
- divider
- find a way to reduce the size of the chunky properties window
- MDX to DCX converter


(MIGHT do)
- border/font/color options
- option to dock test dialog into window
- icons and image lists
- the rest of the options for scroll
- icon file for link
- add a 'hidden' field to common styles
*/


;################## call function ####################
alias dcxstudio {
  if (!$dcxs_check_dcxtools) {
    return
  }

  ;// close studio if already opened
  if ($dialog(dcxstudio)) {
    dialog -c dcxstudio
  }

  dialog -md dcxstudio dcxs_table
  dialog -s dcxprop $calc($window(-1).w - $dialog(dcxprop).w) $calc(($window(-1).h - $dialog(dcxprop).h) /2) $dialog(dcxprop).w $dialog(dcxprop).h

  ;// check for dcx compatibility
  if ($v(dcx) < $v(dcx.compatible)) {
    msgbox DCX Studio v $+ $v is designed to be compatible with DCX v $+ $v(dcx.compatible) $+ . $+ $str($crlf, 2) $+ Your version appears to be outdated. Please update it as soon as possible, as some features will not work properly.
  }
}

;// calls the preferences dialog
alias -l dcxs_preferences {
  ;// dcx studio not running
  if (!$dialog(dcxstudio)) {
    msgbox DCX Studio is not running.
    return
  }

  ;// preferences already opened
  if ($dialog(dcxpref)) {
    dialog -v dcxpref
    return
  }

  dialog -ma dcxpref dcxs_preferences_table
}



;################## editable ####################
;// temporary icons
alias -l icons {
  return $shortfn($scriptdir $+ dcxstudio_gfx\shell.dll)
}

;// icons for studio
alias -l sicons {
  return $shortfn($scriptdir $+ dcxstudio_gfx\studio.icl)
}

;// icons for controls, will add more when i get some
alias -l cicons {
  return $shortfn($scriptdir $+ dcxstudio_gfx\controls.icl)
}

;// whilefix
alias -l whileFix {
  dll $qt($scriptdir $+ dcx\whileFix.dll) WhileFix
}




;################## menus ####################
menu status,channel,menubar {
  1,8 DCX Studio: dcxstudio
}



;################## reusable ####################
alias -l v {
  ;// return the earliest compatible mirc
  if ($1 == mirc.compatible) {
    return 6.20
  }

  ;// return the earliest compatible dcx dll version
  if ($1 == dcx.compatible) {
    return 1.3.6
  }

  ;// return dcx version
  if ($1 == dcx) {
    return $gettok($dcx(Version), 4, 32)
  }

  ;// return dcx studio version
  return 1.4
}

alias -l question {
  return $input($1-, qidu, DCX Studio)
}

alias -l msgbox {
  var %i $input($1-, oidu, DCX Studio)
}


alias -l dcxs_check_dcxtools {
  ;// check if sufficient aliases set
  if (!$isalias(dcx) || !$isalias(xdialog) || !$isalias(xdid)) {
    var %fn dcx_tools.mrc
    var %f

    ;// file exists
    if ($findfile($mircdir, %fn, 1)) {
      var %i 1

      %f = $ifmatch

      ;// check for dcx file already loaded
      while ($script(%i)) {
        if ($nopath($ifmatch) == %fn) {
          msgbox %fn seems to be already loaded. $+ $crlf $+ DCX Studio cannot use this file as it seems to be invalid.
          return $false
        }

        inc %i
      }

      ;// load the file
      if ($question(DCX Studio has found a copy of %fn in your mIRC folder. Do you wish to load it?)) {
        load -rs $+(", %f, ")
      }
      else {
        return $false
      }
    }
    else {
      msgbox Cannot find the functions needed for DCX Studio to run. Your %fn file may have been unloaded.
      return $false
    }
  }

  return $true
}

;// shows the OPEN file dialog
; $1 = filter
; $2 = title
alias -l openFile {
  var %s $commonDialog(%dcxs.lastOpenFolder, $1, $2, &Open)
  if (%s) set %dcxs.lastOpenfolder $nofile(%s)
  return %s
}

;// shows the SAVE file dialog
; $1 = filter
; $2 = title
alias -l saveFile {
  var %s $commonDialog(%dcxs.lastSaveFolder, $1, $2, &Save)
  if (%s) set %dcxs.lastSavefolder $nofile(%s)
  return %s
}

;// shows the open/close file dialog
; $1 = folder
; $2 = filter
; $3 = title
; $4 = Open|Save
alias -l commonDialog {
  dcxs_lock -a $false
  var %s = $sfile($iif($1, $ifmatch, $mircdir) $+ $+ $2, $iif($3, $ifmatch, Select a File), $iif($4, $ifmatch, &Open))
  dcxs_lock -a $true
  return %s
}

;// for recursive functions
alias -l recursive {
  d recursive > $1-
  $1-
}




;###############################################################
; stuff that can be reused by dcxs
on *:load:{
  ;// check for mIRC compatibility
  if ($version < $v(mirc.compatible)) {
    msgbox DCX Studio v $+ $v is designed to be compatible with mIRC v $+ $v(mirc.compatible) $+ . $+ $str($crlf, 2) $+ Your version appears to be outdated. Please update it as soon as possible, as some features will not work properly.
    .unload -rs $+(", $script, ")
    return
  }

  ;// check for appropriate commands
  if (!$dcxs_check_dcxtools) {
    .unload -rs $+(", $script, ")
    return
  }

  ;// check for dcx compatibility
  if ($v(dcx) < $v(dcx.compatible)) {
    msgbox DCX Studio v $+ $v is designed to be compatible with DCX v $+ $v(dcx.compatible) $+ . $+ $str($crlf, 2) $+ Your version appears to be outdated. Please update it as soon as possible, as some features will not work properly.
    .unload -rs $+(", $script, ")
    return
  }

  msgbox DCX Studio for mIRC $+(v, $v) loaded!
  editbox /dcxstudio
}


;// echo status msg
alias -l s {
  if (!$pref(status.work)) return
  dcxs.echo -s $1-
}

;// echo error msg
alias -l e {
  if (!$pref(status.error)) return
  dcxs.echo -e ERROR: $1-
}

;// echo warning msg
alias -l w {
  if (!$pref(status.warn)) return
  dcxs.echo -w WARNING: $1-
}

alias -l c {
  if (!$pref(status.comment)) return
  dcxs.echo -c $1-
}

;// echo debug msg
alias -l d {
  if (!$pref(status.debug)) return
  dcxs.echo -d DEBUG: $1-
}

;// echo todo msg
alias -l t {
  if (!$pref(status.todo)) return
  dcxs.echo -t TODO: $1-
}


;// echos to @dcxstudio window
; $1 = -
alias -l dcxs.echo {
  if (!$pref(status.show)) {
    return
  }

  if (!$window(@dcxstudio)) {
    return
  }

  var %c

  if      ($1 == -s) { }
  else if ($1 == -e) { %c = 4  }
  else if ($1 == -w) { %c = 7 }
  else if ($1 == -c) { %c = 3 }
  else if ($1 == -d) { %c = 6  }
  else if ($1 == -t) { %c = 12 }

  echo %c @dcxstudio $2-
}


;// should use #dcxs.idlist instead of %ids
; $1 == 0    = return # of items
; $1 == n    = return nth item id
; $1 == -r   = clear the table
; $1 == -a x = add item with id x
; $1 == -d y = delete item with id y
alias -l idlist {
  if (!$hget(dcxs.idlist)) {
    hmake dcxs.idlist
  }

  if ($isid) {
    if ($1 == 0) {
      return $hget(dcxs.idlist, 0).data
    }
    else if ($1 isnum) {
      return $hget(dcxs.idlist, $1).data
    }
  }

  if ($1 == -r) {
    hfree dcxs.idlist
    return
  }

  if ($2 == $null) {
    e /idlist: insufficient parameters for $1
    return
  }

  var %exists = $hfind(dcxs.idlist, $2, 1).data

  if ($1 == -a) {
    if (%exists) {
      return
    }

    d /idlist: Adding $1-
    hadd dcxs.idlist $+(item., $r(a,z), $ticks) $2
  }
  else if ($1 == -d) {
    if (!%exists) {
      return
    }

    d /idlist: Removing $1-
    hdel dcxs.idlist $hfind(dcxs.idlist, $2, 1).data
  }
}



;###############################################################
; stores temporary variables into a hash table
; $1  == variable name
; $2  == value
alias -l temp {
  if ($isid) {
    return $hget(dcxs.tmp, $1)
  }

  hadd dcxs.tmp $1 $2-
}




;###############################################################
; stores control properties into the hash table
; $1  == id of control
; $2  == property of control
; $3- == value
alias -l cprop {
  var %h control. $+ $1 $+ . $+ $2

  if ($isid) {
    if (!$hget(dcxs.proj, %h).item) d $!cprop: invalid hash entry %h
    return $hget(dcxs.proj, %h)
  }

  hadd dcxs.proj %h $3-
}

;###############################################################
; stores dcx studio options into the hash table
; $1  == name of option
; $2- == value
alias -l pref {
  var %h pref. $+ $1

  ;// make the table if necessary
  if (!$hget(dcxs.pref)) {
    var %f $qt($mircdir $+ dcxstudio.cfg)

    hmake dcxs.pref

    ;// load
    if ($exists(%f)) { hload -b dcxs.pref %f }
    ;// start a fresh settings file
    else             { hsave -b dcxs.pref %f }
  }


  if ($isid) {
    ;// if entry doesnt exist, load a default value
    if (!$hfind(dcxs.pref, %h)) {
      hadd dcxs.pref %h $dcxs_pref_default($1)
    }

    return $hget(dcxs.pref, %h)
  }

  hadd dcxs.pref %h $2-
}




alias -l getSelectedID {
  return $gettok($did(dcxprop, 32).seltext, 1, 58)
}


alias -l toolbox2cname {
  ;if ($1- == Line       ) return line
  ;if ($1- == Box        ) return box
  ;if ($1- == Radio      ) return radio
  ;if ($1- == Check      )
  ;if ($1- == Edit       )
  ;if ($1- == Scroll     )
  ;if ($1- == Image      )
  ;if ($1- == List       )
  ;if ($1- == Link       )
  ;if ($1- == Text       )
  if ($1- == Progressbar) return pbar
  ;if ($1- == TreeView   )
  ;if ($1- == ListView   )
  ;if ($1- == Toolbar    )
  ;if ($1- == Statusbar  )
  ;if ($1- == ComboEx    )
  ;if ($1- == Trackbar   )
  ;if ($1- == Rebar      )
  ;if ($1- == RichEdit   )
  ;if ($1- == ColorCombo )
  ;if ($1- == Button     )
  if ($1- == IP Address ) return ipaddress
  ;if ($1- == UpDown     )
  if ($1- == WebControl ) return webctrl
  ;if ($1- == Calendar   )
  ;if ($1- == Panel      )
  ;if ($1- == Divider    )
  ;if ($1- == Tab        )
  if ($1- == @Window    ) return window
  ;if ($1- == Dialog     )

  return $lower($1-)
}

alias -l cname2proptab {
  if ($1- == line      ) return 16
  if ($1- == box       ) return 17
  if ($1- == radio     ) return 18
  if ($1- == check     ) return 19
  if ($1- == edit      ) return 20
  if ($1- == scroll    ) return 21
  if ($1- == image     ) return 22
  if ($1- == list      ) return 23
  if ($1- == link      ) return 24
  if ($1- == text      ) return 25
  if ($1- == pbar      ) return 1
  if ($1- == treeview  ) return 2
  if ($1- == listview  ) return 3
  if ($1- == toolbar   ) return 4
  if ($1- == statusbar ) return 5
  if ($1- == comboex   ) return 6
  if ($1- == trackbar  ) return 7
  if ($1- == rebar     ) return 8
  if ($1- == richedit  ) return 9
  if ($1- == colorcombo) return 10
  if ($1- == button    ) return 11
  if ($1- == ipaddress ) return 12
  if ($1- == updown    ) return 13
  if ($1- == webctrl   ) return 14
  if ($1- == calendar  ) return 15
  if ($1- == datetime  ) return 300
  if ($1- == panel     ) return 27
  if ($1- == divider   ) return 26
  if ($1- == tab       ) return 28
  if ($1- == window    ) return 29
  if ($1- == dialog    ) return 30
  if ($1- == main      ) return 300

  w $!cname2proptab: known type $1-
}


alias -l cname {
  if ($1 == $null      ) return
  if ($1- == line      ) return Line
  if ($1- == box       ) return Box
  if ($1- == radio     ) return Radio
  if ($1- == check     ) return Check
  if ($1- == edit      ) return Edit
  if ($1- == scroll    ) return Scroll
  if ($1- == image     ) return Image
  if ($1- == list      ) return List
  if ($1- == link      ) return Link
  if ($1- == text      ) return Text
  if ($1- == pbar      ) return Progressbar
  if ($1- == treeview  ) return TreeView
  if ($1- == listvew   ) return ListView
  if ($1- == toolbar   ) return Toolbar
  if ($1- == statusbar ) return Statusbar
  if ($1- == comboex   ) return ComboEx
  if ($1- == trackbar  ) return Trackbar
  if ($1- == rebar     ) return Rebar
  if ($1- == richedit  ) return RichEdit
  if ($1- == colorcombo) return ColorCombo
  if ($1- == button    ) return Button
  if ($1- == ipaddress ) return IP Address
  if ($1- == updown    ) return UpDown
  if ($1- == webctrl   ) return WebControl
  if ($1- == calendar  ) return Calendar
  if ($1- == datetime  ) return DateTime
  if ($1- == panel     ) return Panel
  if ($1- == divider   ) return Divider
  if ($1- == tab       ) return Tab
  if ($1- == window    ) return @Window
  if ($1- == dialog    ) return Dialog
  if ($1- == main      ) return Main Dialog
  if ($1- == listview  ) return ListView

  w $!cname: unknown type $1-
}



;// changes the progress bar value
; $1 == -t <tag> <total> to set total
; $1 == <tag> <value> to set value
alias -l dcxs_prog {
  if ($1 == -t) {
    if ($3 == $null) {
      e /dcxs_prog: invalid parameters > $1-
    }

    temp prog_type  $2
    temp prog_total $3
  }
  else if ($2 isnum) {
    ;// not meant for this counter
    if ($1 != $temp(prog_type)) {
      ;d /dcxs_prog: different counter type > $temp(prog_type) > $1-
      return
    }

    whileFix
    xdid -v dcxstudio 7 $int($calc($2 / $temp(prog_total) * 100))
  }
  else {
    w /dcxs_prog: else $1-
  }
}


;// locks the studio
;// $1 == -a (all), -m (main), -t (test), -p (properties, -g (gen), -o (preferences/options)
;// $2 == true/false
alias -l dcxs_lock {
  var %dialogs

  if (a isin $1) {
    %dialogs = dcxtest,dcxprop,dcxgen,dcxpref
  }
  else {
    if (m isin $1) { %dialogs = $addtok(%dialogs, dcxstudio, 44) }
    if (t isin $1) { %dialogs = $addtok(%dialogs, dcxtest, 44) }
    if (p isin $1) { %dialogs = $addtok(%dialogs, dcxprop, 44) }
    if (g isin $1) { %dialogs = $addtok(%dialogs, dcxgen, 44) }
    if (o isin $1) { %dialogs = $addtok(%dialogs, dcxpref, 44) }
  }

  if ((!%dialogs) || ($2 == $null)) {
    d /dcxs_lock: missing parameters $1-
  }

  var %i 1

  while ($gettok(%dialogs, %i, 44)) {
    var %d $ifmatch

    if ($dialog(%d)) {
      xdialog $iif($2, -s, -h) %d
    }

    inc %i
  }
}



;// returns if it is a child or not
alias -l isChild {
  return $cprop($1, pid)
}

;// returns true if control has children
; $1 = id of possible parent
alias -l hasChildren {
  if (!$isid)  return

  ;// if tab or rebar, return items
  if (($cprop($1, type) == tab) || ($cprop($1, type) == rebar)) {
    return $iif($cprop($1, items), $true, $false)
  }

  var %k $hfind(dcxs.proj, $1, 0).data

  while (%k) {
    var %h = $hfind(dcxs.proj, $1, %k).data

    if (control.*.pid iswm %h) {
      var %id = $gettok(%h, 2, 46)

      if ($cprop(%id, pid) == $1) {
        return $true
      }
    }

    dec %k
  }

  return $false
}

;// returns all children
; $1 = id of parent
alias -l getChildren {
  ;// if tab or rebar, return items
  if (($cprop($1, type) == tab) || ($cprop($1, type) == rebar)) {
    return $cprop($1, items)
  }

  var %k $hfind(dcxs.proj, $1, 0).data
  var %c

  while (%k) {
    var %h = $hfind(dcxs.proj, $1, %k).data

    if (control.*.pid iswm %h) {
      var %id = $gettok(%h, 2, 46)

      if ($cprop(%id, pid) == $1) {
        %c = $addtok(%c, %id, 32)
        ;return $true
      }
    }

    dec %k
  }

  return %c
}



alias -l dcxs_delete_allControls {
  ;// no objects, dont bother asking
  if (!$xdialog(dcxtest, 0).id) {
    return $true
  }

  if ($question(Are you sure you wish to clear all the controls from this dialog?)) {
    var %ids = $getChildren(0)
    var %i   1

    c Clearing test dialog

    temp deleteAll $true
    dcxs_prog -t deleteAll $xdialog(dcxtest, 0).id

    while ($gettok(%ids, %i, 32)) {
      var %id $ifmatch

      .timer 1 0 deleteControl %id

      inc %i
    }

    ;xdialog -d $1 *
    did -rac dcxprop 32 0: Main
    dcxs_show_controlDetails 0

    ;// unselect any toolbox items
    dcxs_select_toolboxItem

    unset %dcxs.*
    return $true
  }

  return $false
}


;// deletes a control from the dialog
; $1 = ctrl id
alias -l deleteControl {
  if ($1 == $null) return

  ;// control doesnt exist
  if (!$xdialog(dcxtest, $1).isid) {
    d /deleteControl: Control ID $1 does not exist
    return
  }

  ;// let another function handle all the children clearing
  if ($hasChildren($1)) {
    whileFix
    deleteChildren $1
  }

  ;// delete the control
  var %t $cprop($1, type)

  if ($isChild($1)) {
    d /deleteControl: Deleting child $1

    ;// if deleting the panel of a tab/rebar, clear it off the list and then remove item
    if (($cprop($1, ptype) == tab) || ($cprop($1, ptype) == rebar)) {
      var %pid $cprop($1, pid)
      var %c   $cprop(%pid, items)
      var %pos $findtok(%c, $1, 32)

      %c = $deltok(%c, %pos, 32)

      ;// cleanup parent control
      if (%c) {
        cprop %pid items %c
        xdid -d dcxtest %pid %pos

        t select first tab upon tab page deletion
        xdid -c dcxtest %pid 1
      }
      else {
        w delete whole control
        recursive deleteControl %pid
      }
    }
    ;// else, delete a normal child
    else {
      xdid -d dcxtest $cprop($1, pid) $1
    }
  }
  else {
    d /deleteControl: Deleting control $1
    xdialog -d dcxtest $1
  }

  if      (%t == window) { .timer 1 0 window -c @window. $+ $1 }
  else if (%t == dialog) { .timer 1 0 dialog -c dialog. $+ $1 }

  hdel -w dcxs.proj control. $+ $1 $+ .*

  ;// remove from 'select control' list
  var %index $findtok($didtok(dcxprop, 32, 44), $wildtok($didtok(dcxprop, 32, 44), $1 $+ : *, 1, 44), 1, 44)

  if (%index) {
    did -d  dcxprop 32 $ifmatch
    did -cf dcxprop 32 1
  }

  ;// update pbar
  var %c $xdialog(dcxtest, 0).id
  dcxs_prog deleteAll %c

  ;// after deletion, simple 'callback' system
  if ($temp(deleteAll) && !%c) {
    temp deleteAll $false

    if ($temp(afterDelete)) {
      var %cmd $ifmatch
      temp afterDelete
      recursive %cmd
    }
  }
}

;// deletes all children
; $1 = parent id
alias -l deleteChildren {
  var %c $getChildren($1)
  var %i 1

  while ($gettok(%c, %i, 32)) {
    var %id $ifmatch
    var %t  $cprop(%id, type)

    if ($hasChildren(%id)) {
      whileFix
      recursive deleteChildren %id
    }

    d /deleteChildren: Deleting control $1 Child > %id

    ;// remove control if it exists
    if ($xdialog(dcxtest, %id).isid) {
      xdid -d dcxtest $1 %id
    }

    ;// delete entries from property panel
    if ($findtok($didtok(dcxprop, 32, 9), $wildtok($didtok(dcxprop, 32, 44), %id $+ : *, 1, 44), 1, 9)) {
      did -d dcxprop 32 $ifmatch
    }
    ;else {
    ;  w /deleteChildren: there was no sidepanel entry for control item %id ( $+ %y $+ )
    ;}

    ;// remove entries from hash table
    hdel -w dcxs.proj control. $+ %id $+ .*

    ;// cleanup
    if      (%t == window) { .timer 1 0 window -c @window. $+ %id }
    else if (%t == dialog) { .timer 1 0 dialog -c dialog. $+ %id }

    ;// update pbar
    dcxs_prog deleteAll $xdialog(dcxtest, 0).id

    inc %i
  }
}




;###############################################################
;dialog table layouts
dialog dcxs_table {
  title "DCX Studio v"
  size 0 0 350 250
  option dbu
}

dialog dcxs_test_table {
  title "DCX Test Dialog"
  size -1 -1 250 150
  option dbu
}

dialog dcxs_docked_dialog_table {
  title "Docked Dialog"
  size -1 -1 100 50
  option dbu
}

dialog dcxs_generator_table {
  title "DCX Studio - Script Generator"
  size -1 -1 564 461
  list 7, 0 0 220 190, hide
}



dialog dcxs_properties_table {
  title "Control Properties"
  size -1 -1 152 240
  option dbu
  tab "Progress Bar", 1, -3 -16 193 327
  box "Progress Bar", 45, 5 75 145 72, tab 1
  text "Value:", 82, 9 85 60 8, tab 1
  text "Minimum:", 83, 9 97 60 8, tab 1
  text "Maximum:", 84, 9 109 60 8, tab 1
  check "Smooth", 85, 9 125 60 8, tab 1
  check "Vertical", 86, 9 135 60 8, tab 1
  check "Marquee (XP+)", 87, 75 125 60 8, tab 1
  edit "", 89, 75 84 70 10, tab 1 autohs autovs
  edit "", 90, 75 96 70 10, tab 1 autohs autovs
  edit "", 91, 75 108 70 10, tab 1 autohs autovs
  tab "Treeview", 2
  box "Treeview", 46, 5 75 145 87, tab 2
  check "Has lines", 94, 9 100 60 8, tab 2
  check "Has buttons", 95, 9 110 60 8, tab 2
  check "Editable labels", 96, 9 120 60 8, tab 2
  check "No scrolling", 97, 9 130 60 8, tab 2
  check "Show selection", 98, 9 140 60 8, tab 2
  check "Single click expand", 99, 9 150 60 8, tab 2
  check "Lines at root", 100, 80 100 60 8, tab 2
  check "Has checkboxes", 101, 80 110 60 8, tab 2
  check "No horizontal scroll", 102, 80 120 60 8, tab 2
  check "No tooltips", 103, 80 130 60 8, tab 2
  check "Full row selection", 104, 80 140 60 8, tab 2
  text "Icon size:", 115, 9 85 60 8, tab 2
  combo 114, 75 84 70 100, tab 2 sort drop
  tab "Listview", 3
  box "Listview", 47, 5 75 145 67, tab 3
  text "Listview type:", 75, 9 85 60 8, tab 3
  combo 88, 75 84 70 100, tab 3 drop
  check "Single select", 105, 9 100 60 8, tab 3
  check "Flat scrollbars", 116, 9 110 60 8, tab 3
  check "Border select", 117, 9 120 60 8, tab 3
  check "Grid", 118, 9 165 60 8, tab 3
  check "Full row select", 119, 9 175 60 8, tab 3
  check "No header", 120, 9 185 60 8, tab 3
  check "Auto arrange", 123, 85 175 60 8, tab 3
  check "Show selected", 124, 9 130 60 8, tab 3
  check "No label wrap", 125, 85 185 60 8, tab 3
  check "Checkboxes", 126, 9 195 60 8, tab 3
  check "Editable labels", 127, 75 100 60 8, tab 3
  check "Header drag", 128, 9 155 60 8, tab 3
  check "Subitem image", 131, 9 205 60 8, tab 3
  check "No scroll", 132, 75 130 60 8, tab 3
  check "Hottrack selection", 133, 75 110 60 8, tab 3
  check "Tooltip", 134, 75 120 60 8, tab 3
  box "Report View", 129, 5 145 70 73, tab 3
  box "Icon and Smallicon View", 130, 80 145 70 73, tab 3
  edit "", 140, 9 229 120 10, tab 3 autohs autovs
  check "Tiled", 141, 9 240 135 8, tab 3
  box "Background Image", 139, 5 220 145 31, tab 3
  button "...", 142, 130 229 15 10, tab 3
  text "Text alignment", 121, 85 154 60 8, tab 3
  combo 122, 85 163 60 100, tab 3 drop
  tab "Toolbar", 4
  box "Toolbar", 48, 5 75 145 107, tab 4
  text "Alignment:", 151, 9 85 60 8, tab 4
  combo 152, 75 83 70 100, tab 4 drop
  text "Icon size:", 153, 9 95 60 8, tab 4
  text "Min/Max button width:", 155, 9 106 60 8, tab 4
  edit "", 156, 75 106 30 10, tab 4 autohs autovs
  edit "", 158, 115 106 30 10, tab 4 autohs autovs
  text "Default button size", 159, 9 118 60 8, tab 4
  edit "", 160, 75 117 30 10, tab 4 autohs autovs
  check "No divider", 161, 9 130 60 8, tab 4
  check "Flat toolbar", 162, 9 140 60 8, tab 4
  check "List style", 163, 9 150 60 8, tab 4
  check "Transparent", 164, 9 160 60 8, tab 4
  check "Tooltips", 165, 75 130 70 8, tab 4
  check "Wrap", 166, 75 140 70 8, tab 4
  check "Arrows", 167, 75 150 70 8, tab 4
  check "No auto adjust", 168, 75 160 70 8, tab 4
  text "-", 157, 106 107 7 8, tab 4 center
  text "x", 169, 106 118 7 8, tab 4 center
  edit "", 254, 115 117 30 10, tab 4 autohs autovs
  combo 154, 75 95 70 100, tab 4 drop
  check "Auto stretch buttons", 255, 9 170 135 8, tab 4
  tab "Status Bar", 5
  box "Status Bar", 49, 5 75 145 57, tab 5
  text "Background Color:", 170, 9 97 45 8, tab 5
  button "lv bg color", 171, 56 96 15 10, disable tab 5
  check "Grip", 172, 9 110 50 8, tab 5
  check "Tooltips", 173, 9 120 50 8, tab 5
  check "No auto resize", 175, 75 110 50 8, tab 5
  check "No parent align", 176, 75 120 50 8, tab 5
  text "Alignment:", 174, 9 85 60 8, tab 5
  combo 177, 75 83 70 100, tab 5 drop
  tab "ComboEx", 6
  box "ComboEx", 50, 5 75 145 22, tab 6
  text "Style:", 178, 9 85 60 8, tab 6
  combo 179, 75 83 70 100, tab 6 drop
  tab "Track Bar", 7
  box "Track Bar", 51, 5 75 145 128, tab 7
  check "Autoticks", 180, 9 170 60 8, tab 7
  check "Vertical", 181, 9 180 60 8, tab 7
  check "No thumb", 182, 9 190 60 8, tab 7
  check "No ticks", 183, 75 170 60 8, tab 7
  check "Down is left", 184, 75 180 60 8, tab 7
  check "Tooltips", 185, 75 190 60 8, tab 7
  text "Tick alignment:", 186, 9 85 60 8, tab 7
  combo 187, 75 84 70 100, tab 7 drop
  text "Tick frequency:", 188, 9 109 60 8, tab 7
  text "Value range:", 189, 9 133 60 8, tab 7
  edit "", 190, 75 108 70 10, tab 7 autohs autovs
  edit "", 191, 75 132 35 10, tab 7 autohs autovs
  edit "", 192, 111 132 35 10, tab 7 autohs autovs
  text "Tooltip position:", 193, 9 97 60 8, tab 7
  combo 194, 75 96 70 100, tab 7 drop
  text "Value:", 195, 9 121 60 8, tab 7
  edit "", 196, 75 120 70 10, tab 7 autohs autovs
  text "Page step value:", 197, 9 145 60 8, tab 7
  edit "", 198, 75 144 70 10, tab 7 autohs autovs
  text "Line step value:", 199, 9 157 60 8, tab 7
  edit "", 200, 75 156 70 10, tab 7 autohs autovs
  tab "ReBar", 8
  box "ReBar", 52, 5 75 145 92, tab 8
  text "Alignment:", 76, 9 100 60 8, tab 8
  combo 77, 75 99 70 100, tab 8 drop
  button "Open ReBar Editor", 78, 9 85 136 10, tab 8
  check "borders", 79, 9 115 60 8, tab 8
  check "varheight", 80, 9 125 60 8, tab 8
  check "dblclktoggle", 81, 9 135 60 8, tab 8
  check "fixedorder", 106, 9 145 60 8, tab 8
  check "tooltips", 107, 9 155 60 8, tab 8
  check "verticalgrip", 109, 75 115 70 8, tab 8
  check "vertical", 110, 75 125 70 8, tab 8
  check "noresize", 111, 75 135 70 8, tab 8
  check "noparentalign", 112, 75 145 70 8, tab 8
  tab "RichEdit", 9
  box "RichEdit", 53, 5 75 145 58, tab 9
  check "Multiline", 246, 9 100 60 8, tab 9
  check "Auto horizontal scroll", 247, 9 110 60 8, tab 9
  check "Auto vertical scroll", 248, 9 120 60 8, tab 9
  check "Vertical scrollbar", 251, 75 120 60 8, tab 9
  text "Text alignment:", 252, 9 85 60 8, tab 9
  combo 253, 75 84 70 100, tab 9 drop
  check "Load mIRC palette", 249, 75 100 60 8, tab 9
  check "Horizontal scrollbar", 250, 75 110 60 8, tab 9
  tab "ColorCombo", 10
  box "Color Combo", 54, 5 75 145 22, tab 10
  check "Load mIRC colors", 243, 9 85 60 8, tab 10
  tab "Button", 11
  box "Button", 55, 5 75 145 23, tab 11
  check "Bitmap button", 108, 9 85 60 8, tab 11
  check "Default button", 113, 75 85 70 8, tab 11
  tab "IP Address", 12
  box "IP Address", 56, 5 75 145 24, tab 12
  text "There are currently no options for this control.", 92, 9 85 136 8, disable tab 12
  tab "UpDown", 13
  box "UpDown", 57, 5 75 145 102, tab 13
  text "Buddy control:", 256, 9 85 60 8, tab 13
  text "Base value:", 258, 9 97 60 8, tab 13
  text "Value/Position:", 260, 9 110 60 8, tab 13
  text "Min/Max:", 262, 9 122 60 8, tab 13
  edit "", 263, 75 121 35 10, tab 13 autohs autovs
  edit "", 264, 109 121 35 10, tab 13 autohs autovs
  check "Left align", 265, 9 135 60 8, tab 13
  check "Arrow keys", 266, 9 145 60 8, tab 13
  check "Horizontal arrows", 267, 9 155 60 8, tab 13
  check "Hottrack", 268, 9 165 60 8, tab 13
  check "No thousands", 269, 75 135 70 8, tab 13
  check "Set buddy integer", 270, 75 145 70 8, tab 13
  check "Wrap range", 271, 75 155 70 8, tab 13
  edit "", 261, 75 109 70 10, tab 13 autohs autovs
  combo 257, 75 84 70 100, tab 13 drop
  combo 259, 75 96 70 100, tab 13 drop
  tab "WebControl", 14
  box "WebControl", 58, 5 75 145 23, tab 14
  text "Default page:", 245, 9 85 60 8, tab 14
  edit "", 244, 75 84 70 10, tab 14 autohs autovs
  tab "Calendar", 15
  box "Calendar", 59, 5 75 145 33, tab 15
  check "Multiple selection", 275, 9 85 60 8, tab 15
  check "Show week number", 276, 9 95 60 8, tab 15
  check "No 'Today' text", 277, 75 85 70 8, tab 15
  check "No 'Today' circle", 278, 75 95 70 8, tab 15
  tab "Line", 16
  box "Line", 60, 5 75 145 22, tab 16
  check "Vertical", 202, 9 85 60 8, tab 16
  tab "Box", 17
  box "Box", 61, 5 75 145 36, tab 17
  check "Squared", 201, 9 100 60 8, tab 17
  text "Text alignment:", 203, 9 85 60 8, tab 17
  combo 204, 75 84 70 100, tab 17 drop
  check "Bottom", 205, 75 100 70 8, tab 17
  tab "Radio", 18
  box "Radio", 73, 5 75 145 37, tab 18
  text "Text alignment:", 206, 9 85 60 8, tab 18
  combo 207, 75 84 70 100, tab 18 drop
  check "Push-like", 208, 9 100 60 8, tab 18
  tab "Check", 19
  box "Check", 62, 5 75 145 47, tab 19
  text "Text alignment:", 209, 9 85 60 8, tab 19
  combo 210, 75 84 70 100, tab 19 drop
  check "Push-like", 211, 9 100 60 8, tab 19
  check "3 State", 212, 9 110 60 8, tab 19
  tab "Edit", 20
  box "Edit", 63, 5 75 145 103, tab 20
  text "Text alignment:", 225, 9 85 60 8, tab 20
  combo 226, 75 84 70 100, tab 20 drop
  text "Character limit:", 227, 9 99 60 8, tab 20
  edit "", 228, 75 98 70 10, tab 20 autohs autovs
  check "Multi-line", 229, 9 115 60 8, tab 20
  check "Auto horizontal scroll", 230, 9 125 60 8, tab 20
  check "Horizontal scrollbar", 231, 9 135 60 8, tab 20
  check "Lowercase input", 232, 9 145 60 8, tab 20
  check "Uppercase input", 233, 9 155 60 8, tab 20
  check "Number only input", 234, 9 165 60 8, tab 20
  check "Allow enter/return", 235, 75 115 70 8, tab 20
  check "Auto vertical scroll", 236, 75 125 70 8, tab 20
  check "Vertical scrollbar", 237, 75 135 70 8, tab 20
  check "Password mode", 238, 75 145 70 8, tab 20
  check "Read-only mode", 239, 75 155 70 8, tab 20
  tab "Scroll", 21
  box "Scroll", 64, 5 75 145 23, tab 21
  check "Vertical", 213, 9 85 60 8, tab 21
  tab "Image", 22
  box "Image", 65, 5 75 145 24, tab 22
  text "Bitmap (BMP) file:", 240, 9 85 60 8, tab 22
  edit "", 241, 73 84 55 10, tab 22 autohs autovs
  button "...", 242, 130 84 15 10, tab 22
  tab "List", 23
  box "List", 66, 5 75 145 43, tab 23
  check "No scrolling", 214, 9 85 60 8, tab 23
  check "Extended selection", 215, 9 95 60 8, tab 23
  check "Multi", 216, 9 105 60 8, tab 23
  check "No integral height", 217, 75 85 60 8, tab 23
  check "No selection", 218, 75 95 60 8, tab 23
  tab "Link", 24
  box "Link", 67, 5 75 145 24, tab 24
  text "There are currently no options for this control.", 318, 9 85 136 8, disable tab 24
  tab "Text", 25
  box "Text", 68, 5 75 145 47, tab 25
  check "No wrap", 219, 9 100 60 8, tab 25
  check "No ampersand prefix", 220, 9 110 60 8, tab 25
  check "Add ellipsis (...)", 221, 75 100 60 8, tab 25
  check "Center ... ellipsis", 222, 75 110 60 8, tab 25
  text "Text alignment:", 223, 9 85 60 8, tab 25
  combo 224, 75 84 70 100, tab 25 drop
  tab "Divider", 26
  box "Divider", 69, 5 75 145 100, tab 26
  tab "Panel", 27
  box "Panel", 70, 5 75 145 39, tab 27
  text "Select child control:", 298, 9 100 60 8, tab 27
  combo 299, 75 99 70 100, tab 27 drop
  button "Cell Layout Algorithm (CLA) Editor", 303, 9 85 136 10, disable tab 27
  tab "Tab", 28
  box "Tab", 71, 5 75 145 106, tab 28
  check "Vertical", 279, 9 129 60 8, tab 28
  check "Fixed width", 280, 9 139 60 8, tab 28
  check "Tab buttons", 281, 9 149 60 8, tab 28
  check "Flat buttons", 282, 9 159 60 8, tab 28
  check "Hottrack", 283, 9 169 60 8, tab 28
  check "Stretch tab width to fill", 285, 75 139 70 8, tab 28
  check "Scroll opposite", 286, 75 149 70 8, tab 28
  check "Flat seperators", 287, 75 159 70 8, tab 28
  text "Tab alignment:", 288, 9 100 60 8, tab 28
  text "Button width/height", 290, 9 115 60 8, tab 28
  edit "", 292, 75 114 34 10, tab 28 autohs autovs
  edit "", 293, 111 114 34 10, tab 28 autohs autovs
  check "Multiline tab bar", 284, 75 129 70 8, tab 28
  button "Open DCXS Tab Editor", 291, 9 85 136 10, tab 28
  combo 289, 75 100 70 100, tab 28 drop
  tab "@Window", 29
  box "@Window", 72, 5 75 145 25, tab 29
  text "Name of window:", 294, 9 85 60 8, tab 29
  edit "", 295, 75 84 70 10, tab 29 autohs autovs
  tab "Dialog", 30
  box "Dialog", 74, 5 75 145 24, tab 30
  text "Dialog name:", 296, 9 85 60 8, tab 30
  edit "", 297, 75 84 70 10, tab 30 autohs autovs
  tab "Main Dialog", 300
  box "Main Dialog", 301, 5 75 145 39, tab 300
  button "Cell Layout Algorithm (CLA) Editor", 302, 9 85 136 10, disable tab 300
  box "Borders and Styles", 304, 5 120 145 82, tab 300
  check "Titlebar", 305, 9 130 60 8, tab 300
  check "Context help (?)", 306, 9 140 60 8, tab 300
  check "Maximise button", 307, 9 150 60 8, tab 300
  check "Minimise button", 308, 9 160 60 8, tab 300
  check "Tool window", 309, 9 170 60 8, tab 300
  check "System Menu (X)", 310, 9 180 60 8, tab 300
  check "Resizable", 311, 9 190 60 8, tab 300
  check "Regular border", 312, 75 130 70 8, tab 300
  check "Client-edge border", 313, 75 140 70 8, tab 300
  check "Dialog frame border", 314, 75 150 70 8, tab 300
  check "Dialog modal frame border", 315, 75 160 70 8, tab 300
  check "Static edge border", 316, 75 170 70 8, tab 300
  check "Window edge border", 317, 75 180 70 8, tab 300
  text "Dialog name:", 93, 9 100 60 8, tab 300
  edit "", 135, 75 99 70 10, tab 300 autohs autovs
  box "General", 31, 5 2 145 70
  combo 32, 50 10 70 100, sort drop
  text "Select Control:", 33, 9 10 40 8
  text "Caption:", 34, 9 21 40 8
  edit "", 35, 50 21 95 10, autohs autovs
  text "XYWH:", 36, 9 33 40 8
  edit "", 37, 50 32 20 10, autohs autovs
  edit "", 38, 75 32 20 10, autohs autovs
  edit "", 39, 100 32 20 10, autohs autovs
  edit "", 40, 125 32 20 10, autohs autovs
  check "Tab stop", 41, 10 50 60 8
  check "Disabled", 42, 75 50 70 8
  check "Group", 43, 10 60 60 8
  check "No theme (XP+)", 44, 75 60 70 8
  button "Delete", 272, 121 10 23 10
}


dialog dcxs_preferences_table {
  title "DCX Studio Preferences"
  size -1 -1 270 186
  option dbu
  tab "General", 1, 5 0 260 169
  box "Status Messages", 16, 10 20 250 43, tab 1
  check "Show status messages", 18, 15 30 240 8, tab 1
  check "Status/Working", 19, 25 40 70 8, tab 1
  check "Error", 20, 25 50 70 8, tab 1
  check "Warning", 21, 100 40 70 8, tab 1
  check "Debug", 22, 100 50 70 8, tab 1
  check "ToDo/Developer Notes", 23, 175 40 70 8, tab 1
  box "Script Generation", 24, 10 70 250 96, tab 1
  text "Generate control initialisation code in:", 25, 15 80 240 8, tab 1
  radio "Seperate alias", 26, 25 90 230 9, tab 1
  radio "Dialog INIT event", 27, 25 100 230 9, tab 1
  check "Include comments in generated code", 28, 15 115 240 8, tab 1
  check "Add DCX Studio comments into code (ie. heirarchy)", 29, 25 125 230 8, tab 1
  check "Add control type and ID before initialisation", 30, 25 135 230 8, tab 1
  check "Generate sample event handling code for callback function", 31, 15 145 240 8, tab 1
  check "Comments", 35, 175 50 70 8, tab 1
  check "Generate quick-access menu item for dialog", 36, 15 155 240 8, tab 1
  tab "Test Dialog", 2
  box "Mouse/Cursor Options", 6, 10 20 250 73, tab 2
  check "Change mouse cursor when adding controls", 7, 15 30 150 8, tab 2
  check "Change mouse cursor when hovering over a control", 8, 15 40 150 8, tab 2
  check "Hilight control that mouse is currently over", 9, 15 50 150 8, tab 2
  check "Regular border", 10, 25 60 80 8, tab 2
  check "Client edge border", 11, 25 70 80 8, tab 2
  check "Dialog frame border", 12, 25 80 80 8, tab 2
  check "Window edge border", 15, 110 80 80 8, tab 2
  check "Static edge border", 14, 110 70 80 8, tab 2
  check "Dialog modal frame border", 13, 110 60 80 8, tab 2
  tab "Control Defaults", 3
  box "General Control Defaults", 17, 10 20 250 23, tab 3
  box "Control Specific Defaults", 32, 10 50 250 23, tab 3
  text "Still working on it!", 33, 15 30 240 8, disable tab 3
  text "Still working on it!", 34, 15 60 240 8, disable tab 3
  button "Done", 4, 192 173 35 10, default ok
  button "Cancel", 5, 230 173 35 10, cancel
}

dialog dcxs_itemeditor_table {
  title "Tab/Rebar Items"
  size -1 -1 130 122
  option dbu
  text "Caption", 1, 10 26 30 8
  text "Item type:", 4, 10 37 30 8
  button "&Done", 7, 50 108 35 10, result default ok
  button "Cancel", 8, 90 108 35 10, cancel
  text "XY:", 9, 10 50 30 8
  box "Tab Item Properties", 11, 5 5 120 70
  edit "", 12, 45 25 75 10, autohs autovs
  combo 2, 10 14 110 100, drop
  edit "", 13, 45 49 37 10, autohs autovs
  edit "", 14, 84 49 37 10, autohs autovs
  box "Tab Items", 3, 5 78 120 25
  button "&Add", 5, 10 88 35 10
  button "&Remove", 6, 48 88 35 10
  button "&Order", 15, 85 88 35 10
  edit "", 10, 84 60 37 10, autohs autovs
  edit "", 17, 45 60 37 10, autohs autovs
  text "WH:", 18, 10 61 30 8
  combo 19, 45 36 75 100, drop
  text "item names", 20, 6 126 119 8, hide
}

dialog dcxs_ieditororder_table {
  title "Change Tab/Rebar Item Order"
  size -1 -1 288 260
  option pixels
  box "New Order of Items", 1, 8 8 270 220
  list 2, 18 26 220 190, size
  button "Done", 3, 134 234 70 20, default ok result
  button "Cancel", 4, 210 234 70 20, cancel
}









;###############################################################
; normal dialog events
on *:dialog:dcxstudio:*:*: {
  if ($devent == init) {
    dcx Mark $dname dcxs_cb
    xdialog -b $dname +mntzy
    ;//xdialog -m $dname

    ;// initialise stuff
    dcxs_init_hash
    dcxs_init_studio
    dcxs_init_menus

    ;// create dcxprop and dcxtest dialogs
    dialog -ma dcxtest dcxs_test_table
    dialog -ma dcxprop dcxs_properties_table

    ;// set up default screen
    dcxs_control_init dcxtest 0 main
    dcxs_show_controlDetails  0
  }
  ;// on close, clean up
  if ($devent == close) {
    ;// save preferences
    if ($hget(dcxs.pref)) {
      hsave -b dcxs.pref $qt($mircdir $+ dcxstudio.cfg)
    }

    unset %dcxs.*

    if ($window(@dcxstudio)) { window -c @dcxstudio }
    hfree -w dcxs.*

    ;// cleanup menus
    if ($xpopup(dcxs.tb.open).ismenu) { xpopup -d dcxs.tb.open }
    if ($xpopup(dcxs.tb.help).ismenu) { xpopup -d dcxs.tb.help }
  }
}



on *:dialog:dcxtest:*:*: {
  if ($devent == init) {
    dcx Mark $dname dcxstest_cb
    xdialog -b $dname +mntyz
    ;xdialog -a $dname +ab 200
  }
}

on *:dialog:dcxgen:*:*: {
  if ($devent == init) {
    dcx Mark $dname dcxsgen_cb
    xdialog -b $dname +nty
    dcxs_init_generator
  }
}


on *:dialog:dcxprop:*:*: {
  if ($devent == init) {
    dcx Mark $dname dcxsprop_cb
    xdialog -b $dname +ot
    ;xdialog -a $dname +ab 200

    dcxs_init_propertyPanels
    return
  }

  ;// select control from dropdown
  if ($devent == sclick && $did == 32) {
    dcxs_show_controlDetails $getSelectedID
    did -f $dname $did
    return
  }

  ;// delete control
  if ($devent == sclick && $did == 272) {
    var %id $getSelectedID

    ;// cant delete main dlg
    if (!%id) return

    if ($question(Are you sure you wish to delete this control? $+ $crlf $+ $did(32).seltext)) {
      if ($hasChildren(%id)) {
        ;msgbox Deleting controls with children is still considered buggy. Awaiting an update for DCX before this feature can become stable.
        ;return

        ;// dont want to remove children, cancel
        if (!$question(This control contains children control. Deleting it will remove all child controls too. Are you sure you wish to proceed with this action?)) {
          return
        }
      }

      deleteControl %id
    }

    return
  }



  ;// caption
  if ($did == 35) {
    var %id $getSelectedID

    dcxs_control_setCaption %id $cprop(%id, type) $did($did)
    return
  }

  ;// coordinates stuff
  if ($devent == edit && $findtok(37 38 39 40, $did, 1, 32)) {
    var %id $getSelectedID

    if ($did == 37) cprop %id x $int($did($did))
    if ($did == 38) cprop %id y $int($did($did))
    if ($did == 39) cprop %id w $int($did($did))
    if ($did == 40) cprop %id h $int($did($did))

    .timerResize. $+ %id -m 1 100 dcxs_control_moveto %id $cprop(%id, x) $cprop(%id, y) $cprop(%id, w) $cprop(%id, h)
    return
  }

  ;// general styles stuff
  if ($findtok(41 42 43 44, $did, 1, 32)) {
    var %id $getSelectedID

    if ($did == 41) dcxs_control_setStyle %id tabstop  $did($did).state
    if ($did == 43) dcxs_control_setStyle %id group    $did($did).state
    if ($did == 42) dcxs_control_setStyle %id disabled $did($did).state
    if ($did == 44) dcxs_control_setStyle %id notheme  $did($did).state

    dcxs_control_recreate %id
    return
  }


  ;// tab/rebar editor buttons
  ;// 78 = rebar, 291 = tab
  if (($devent == sclick) && (($did == 78) || ($did == 291))) {
    var %id $getSelectedID

    temp ieditor.mode  $iif($did == 78, rebar, tab)
    temp ieditor.id    %id
    temp ieditor.order $cprop(%id, items)

    ;// user clicked ok
    if ($dialog(dcxieditor, dcxs_itemeditor_table, @dcxstudio)) {
    }

    return
  }



  ;// unwanted events
  if ($did == 0)                                                return
  if ($findtok(close init active mouse uclick, $devent, 1, 32)) return

  ;// get selected id
  var %id $getSelectedID
  var %a  dcxs_control_modify_ $+ $cprop(%id, type)

  if ($isalias(%a)) %a %id
  else              w /dcxprop: $devent $+ : $did $+ : no such function alias -l %a
}


on *:dialog:dcxpref:*:*: {
  if ($devent == init) {
    dcx Mark $dname dcxspref_cb
    xdialog -b $dname +to

    dcxs_lock -tpg $false

    ;// load values into controls
    dcxs_init_prefs
  }
  else if ($devent == close) {
    dcxs_lock -tpg $true
  }

  if      ($devent == mouse)  { return }
  else if ($devent == active) { return }
  else if ($devent == uclick) { return }
  else if ($devent == drop)   { return }


  ;// clicked on DONE
  if ($did == 4) {
    dcxs_pref_savePreferences
  }
  ;// show status msgs
  else if ($did == 18) {
    dcxs_pref_updateStatusMsgChecks
  }
  ;// change hover border
  else if ($did == 9) {
    dcxs_pref_updateHoverBorderChecks
  }

  ;// include comments in generate
  else if ($did == 28) {
    dcxs_pref_updateGenscriptCommentChecks
  }
  else {
    ;t dcxpref > $devent > $did > $iif($did > 0, $did($did))
  }
}


on *:dialog:dcxieditor:*:*: {
  if ($devent == mouse) {
    return
  }

  ;// load details
  if ($devent == init) {
    dcx Mark $dname dcxspref_cb
    xdialog -b $dname +to

    ;// load values into controls
    dcxs_init_ieditor $temp(ieditor.mode) $temp(ieditor.id)
    dcxs_ieditor_enableButtons

    dcxs_lock -a $false
    return
  }
  ;// close dialog
  else if ($devent == close) {
    dcxs_lock -a $true
    return
  }

  ;// after this point, we dont care about main dialog events
  if ($did == 0) { return }


  ;// done
  if (($devent == sclick) && ($did == 7)) {
    dcxs_ieditor_save $temp(ieditor.mode) $temp(ieditor.id)
  }

  ;// select new control
  if (($devent == sclick) && ($did == 2)) {
    dcxs_ieditor_showDetails
    return
  }

  ;// change order
  if (($devent == sclick) && ($did == 15)) {
    var %ok $dialog(dcxs_ieditororder, dcxs_ieditororder_table, -4)
    return
  }

  ;// add item
  if (($devent == sclick) && ($did == 5)) {
    var %id $xdialog(dcxtest).nextid
    var %c  $temp(ieditor.order)
    var %o  $cprop($temp(ieditor.id), items)

    while ($findtok(%c, %id, 0, 32) || $findtok(%o, %id, 0, 32)) {
      inc %id
    }

    d dcxieditor: adding %id
    temp ieditor.order $addtok(%c, %id, 32)

    tprop %id caption $cname($temp(ieditor.mode)) %id
    tprop %id type panel
    tprop %id x 0
    tprop %id y 0
    tprop %id w 50
    tprop %id h $iif($temp(ieditor.mode) == rebar, $gettok($xdid(dcxtest, $temp(ieditor.id)).pos, 4, 32), 50)

    did -ac $dname 2 %id $+ : Panel ( $+ $tprop(%id, caption) $+ )
    dcxs_ieditor_showDetails
    dcxs_ieditor_enableButtons

    return
  }

  ;// delete item
  if (($devent == sclick) && ($did == 6)) {
    var %id $gettok($did(2).seltext, 1, 58)

    d dcxieditor: delete %id

    hdel -w dcxs.tmp control. $+ %id $+ .*
    did -d $dname 2 $did(2).sel
    did -c $dname 2 1
    temp ieditor.order $remtok($temp(ieditor.order), %id, 32)

    dcxs_ieditor_showDetails
    dcxs_ieditor_enableButtons

    return
  }


  ;// change item type
  if (($devent == sclick) && ($did == 19)) {
    var %id $gettok($did(2).seltext, 1, 58)

    ;// if type is changed
    if ($cname($cprop(%id, type)) != $did($did).seltext) {
      if ($hasChildren(%id)) {
        if (!$question(Control %id is a container for other controls. Changing its type will cause the child controls to be deleted. $+ $crlf $+ Are you sure you want to do this?)) {
          did -c $dname $did $findtok($didtok(19, 44), $cname($cprop(%id, type)), 1, 44)
          return
        }
      }
    }
  }

  dcxs_ieditor_editDetails
}




;###############################################################
; signal handlers for xpopup events
ON *:SIGNAL:Xpopup-*: {
  var %m $gettok($signal, 2-, 45)

  ;// nothing clicked
  if ($1 == 0) {
    return
  }

  if (%m == dcxs.tb.open) {
    if      ($1 == 1) { dcxs_script_open }
    else if ($1 == 2) { dcxs_script_convert }
  }
  else if (%m == dcxs.tb.help) {
    if      ($1 == 1) { url http://dcx.scriptsdb.org/forum/showthread.php?tid=60 }
    ;// help -> readme
    else if ($1 == 2) {
      var %f $qt($scriptdir $+ readme.txt)

      if ($exists(%f)) {
        .run %f
      }
      else {
        msgbox Error locating readme.txt
      }
    }
    ;// help -> about
    else if ($1 == 3) {
      var %str

      %str = DCX Studio for mIRC v $+ $v (by twig*)
      %str = %str $+ $crlf $+ - DCX.dll v $+ $v(dcx) (by ClickHeRe and twig*)
      %str = %str $+ $crlf $+ - mIRC v $+ $version
      %str = %str $+ $crlf
      %str = %str $+ $crlf $+ Shoutout to all those at #genscripts !
      %str = %str $+ $crlf $+ Free for public use.

      msgbox %str
    }
    else if ($1 == 4) {
      var %f $qt($scriptdir $+ changes.txt)

      if ($exists(%f)) {
        .run %f
      }
      else {
        msgbox Error locating changes.txt
      }
    }
    else msgbox $1
  }
}

menu @dcxstudio {
  dclick: dcxs_script_open
  Open Folders
  .&DCX:.run $scriptdir\dcx
  .&mIRC:.run $mircdir
  .&Projects:.run $scriptdir\dcxstudio_projects
  .&Script:.run $scriptdir
  -
  Object Viewer: objview
  -
  Clear Status Window: clear @dcxstudio
}



;###############################################################
; callback functions for dcx events
alias dcxs_cb {
  if ($2 == mouse || $2 == mouseleave || $2 == mouseenter || $2 == focusout || $2 == focus || $2 == sizing || $2 == change || $2 == moving) {
    return
  }
  ;  else {
  ;    echo -a dcxs_cb: $1-
  ;  }

  ;// clicked on something in the toolbox
  if ((($2 == sclick) || ($2 == dclick)) && $findtok(4 5 6, $3, 1, 32)) {
    ;// unset the add variable
    if (%dcxs.add == $toolbox2cname($xdid($1, $3, $4).text)) {
      unset %dcxs.add
      dcxs_select_toolboxItem
    }
    ;// set the 'add' variable
    else {
      set %dcxs.add $toolbox2cname($xdid($1, $3, $4).text)

      ;// unselect all the other controls
      dcxs_select_toolboxItem $3 $4
    }

    return
  }

  ;// clicked on the toolbar at the top
  if ((($2 == dropdown) || ($2 == sclick)) && ($3 == 1)) {
    ;// new
    if      ($4 == 1) dcxs_delete_allControls
    ;// open / import
    else if ($4 == 2) {
      if ($2 == dropdown) { xpopup -s dcxs.tb.open +m $5 $6 }
      else                { .signal -n Xpopup-dcxs.tb.open 1 }
    }
    ;// save
    else if ($4 == 3) dcxs_script_save
    ;// generate
    else if ($4 == 6) {
      dcxs_script_generate $cprop(0, name)
    }
    ;// preferences
    else if ($4 == 8) {
      dcxs_preferences
    }
    ;// help
    else if ($4 == 10) {
      if ($2 == dropdown) { xpopup -s dcxs.tb.help +m $5 $6 }
      else                { .signal -n Xpopup-dcxs.tb.help 1 }
    }
    else {
      msgbox Unconfigured: Clicked $1-
    }

    return
  }
}


alias dcxsprop_cb {
  if ($2 == close) return noclose
}

alias dcxsgen_cb {
  if ($2 == mouse) return

  ;// done button
  if ($2 == sclick && $3 == 4) {
    .timer 1 0 xdialog -x $1
  }

  ;// save button
  if ($2 == sclick && $3 == 3) {
    var %f $$saveFile(*.mrc, Save Script to File)

    if ($exists($qt(%f))) {
      if (!$question(Are you sure you wish to replace this file? $+ $crlf $+ %f)) {
        return
      }
    }

    xdid -u $1 2 %f
  }

  ;// demo button
  if ($2 == sclick && $3 == 5) {

  }

  ;// copy button
  if ($2 == sclick && $3 == 6) {
    xdid -c $1 2
  }
}


alias dcxstest_cb {
  ;// if the dialog is in the process of being cleared
  if ($temp(deleteAll)) {
    if ($2 == max      ) { return stop    }
    if ($2 == min      ) { return stop    }
    if ($2 == beginmove) { return nomove  }
    if ($2 == beginsize) { return nosize  }
    if ($2 == close    ) { return noclose }

    return
  }
  ;if ($2 != mouse) echo -a $1-

  if ($2 == close) {
    dcxs_delete_allControls
    return noclose
  }


  ;[ mouse enter ctrl rgn ]-------------------------------------------------------
  ;// tracking which ctrl the mouse is over
  if ($2 == mouseenter) {
    var %d = $iif($3, $xdid($1, $3).pos, $dialog($1).x $dialog($1).y $dialog($1).cw $dialog($1).ch)

    var %x = $gettok(%d, 1, 32)
    var %y = $gettok(%d, 2, 32)
    var %w = $gettok(%d, 3, 32)
    var %h = $gettok(%d, 4, 32)

    dcxs_statusbar_paneltext 1 $3
    dcxs_statusbar_paneltext 2 $cname($cprop($3, type))
    dcxs_statusbar_paneltext 3 %x $+ , %y
    dcxs_statusbar_paneltext 4 %w $+ , %h

    if ($3 && $xdialog($1, $3).isid) {
      if ($pref(hilight.enabled)) {
        if ($cprop($3, type) != list) {
          xdid -x $1 $3 $pref(hilight.style)
        }
        else {
          t Highlight border bug causing 'list' to resize to zero when 'nointegral' style is not set.
        }
      }
      if ($pref(cursor.hover)) {
        if ($cprop($3, type) != panel) {
          xdid -J $1 $3 +r hand
        }
      }
    }
  }

  ;// make room for highlighting if possible
  if ($2 == mouseleave) {
    if ($3 && $xdialog($1, $3).isid) {
      if ($pref(hilight.enabled)) {
        if ($cprop($3, type) != list) {
          xdid -x $1 $3 $iif($xdid($1, $3).mark, $ifmatch, +)
        }
      }
      if ($pref(cursor.hover)) {
        xdid -J $1 $3 +r arrow
      }
    }
  }


  ;[ adding ctrls ]---------------------------------------------------------------
  if ($2 == mouse && %dcxs.add) {
    ;// modify it to become an slick event to add onto contrls without slick
    if ($xdialog($1).key == 1) {
      tokenize 32 $1 sclick $3-
    }
  }

  ;// adding an object
  if ($2 == sclick && %dcxs.add) {
    ;// loop thru current controls and see if theres already one
    ;// usually theres no need for duplicates of certain types
    if ($findtok(statusbar rebar toolbar, %dcxs.add, 0, 32) && $wildtok($didtok(dcxprop, 32, 9), *: %dcxs.add, 0, 9)) {
      if ($question(Are you sure you need another %dcxs.add $+ ?)) {
        return
      }
    }

    ;// get id of new control
    var %nid = $xdialog($1).nextid

    ;// get coordinates of mouse relative to dialog
    var %mxy = $xdialog($1).mouse


    ;// add to dialog
    if ($3 == 0) {
      dcxs_control_create $1 %nid %dcxs.add %mxy 0
    }
    ;// add onto container control
    else if (($cprop($3, type) == panel) || ($cprop($3, type) == box)) {
      ;// get coordinates of mouse relative to control

      dcxs_control_create $1 %nid %dcxs.add %mxy $3
    }
    else {
      ;// get id of control that mouse is over
      var %mct $cprop($3, type)

      dcxs_show_controlDetails $3
      dcxs_select_toolboxItem
      unset %dcxs.add
      return
    }

    ;// show details for newly created control
    dcxs_show_controlDetails %nid


    var %k $mouse.key

    ;// unselect the stuff only if shift key not held
    if (%k == 3 || %k == 5) {
    }
    ;// otherwise unset variables and select no toolbox items
    else {
      dcxs_select_toolboxItem
      unset %dcxs.add
    }

    return
  }

  ;[ mouse moving and dragging ]--------------------------------------------------
  ;// %dcxs.drag = [id of ctrl] [x offset of mouse on ctrl] [y offset of mouse on ctrl]
  if ($2 == mouse && ($3 || %dcxs.drag)) {
    if ($xdialog($1).key & 1) {
      ;// MOVING
      if (%dcxs.drag) {
        var %id  = $gettok(%dcxs.drag, 1, 32)
        var %pos = $xdialog($1).mouse

        var %x = $gettok(%pos, 1, 32)
        var %y = $gettok(%pos, 2, 32)

        dec %x $gettok(%dcxs.drag, 2, 32)
        dec %y $gettok(%dcxs.drag, 3, 32)

        dcxs_control_moveto %id %x %y $gettok($xdid($1, %id).pos, 3-, 32)

        ;// delay the updating so it doesnt flicker as much or lag
        .timerDrag -m 1 10 dcxs_statusbar_paneltext 3 %x $+ , %y
      }
      ;// START dragging
      else {
        ;// find the types u cant drag
        if ($findtok(toolbar statusbar rebar divider, $cprop($3, type), 1, 32)) return
        ;// no point dragging items which are children to tab/rebar
        if ($findtok(rebar tab, $cprop($3, ptype), 1, 32)) return

        ;// offset on control
        var %posC $xdid($1, $3).mouse
        var %posD

        var %x $gettok(%posC, 1, 32)
        var %y $gettok(%posC, 2, 32)

        ;// if controls nested in others, find offset of parent control in dialog
        if ($cprop($3, pid)) {
          %posD = $gettok($xdid($1, $ifmatch).dpos, 1-2, 32)

          inc %x $gettok(%posD, 1, 32)
          inc %y $gettok(%posD, 2, 32)
        }

        set %dcxs.drag $3 %x %y
      }
    }
    else if (%dcxs.drag) {
      var %id = $gettok(%dcxs.drag, 1, 32)
      var %pos = $xdid(dcxtest, %id).pos

      var %x = $gettok(%pos, 1, 32)
      var %y = $gettok(%pos, 2, 32)
      var %w = $gettok(%pos, 3, 32)
      var %h = $gettok(%pos, 4, 32)

      cprop %id x %x
      cprop %id y %y
      cprop %id w %w
      cprop %id h %h

      dcxs_show_controlDetails %id

      unset %dcxs.drag
    }
  }


  ;[ selecting stuff ]------------------------------------------------------------
  if (($2 == sclick) || ($2 == focus) || ($2 == trackend) || ($2 == lineup) || ($2 == linedown) || ($2 == pageup) || ($2 == pagedown)) {
    dcxs_show_controlDetails $3
  }


  ;[ dialog coordinate stuff ]----------------------------------------------------
  if ($2 == sizing && $3 == 0 && !%dcxs.openProject) {
    cprop $3 w $4
    cprop $3 h $5

    dcxs_statusbar_paneltext 4 $4 $+ , $5
  }

  if ($2 == endsize) {
    dcxs_show_controlDetails $3
  }

  if ($2 == moving) {
    cprop $3 x $dialog(dcxtest).x
    cprop $3 y $dialog(dcxtest).y

    dcxs_statusbar_paneltext 3 $cprop($3, x) $+ , $cprop($3, y)
  }

  if ($2 == endmove) {
    dcxs_show_controlDetails $3
  }

  ;if ($2 != mouse) echo -a $1-
  ;if (($2 != mouse) && ($2 != mouseenter) && ($2 != mouseleave)) echo -a $1-
}

alias dcxspref_cb {
}

alias dcxsieditororder_cb {
  if ($2 == mouse) return

  ;// change order
  if (($2 == sclick) && (($3 == 5) || ($3 == 6))) {
    var %offset

    ;// move up
    if ($3 == 5) {
      %offset = -1
    }
    ;// move down
    else {
      %offset = +1
    }

    var %sel $did($1, 2).sel
    var %rep $calc(%sel + %offset)

    ;// at the boundaries
    if ((%rep > $did($1, 2).lines) || (%rep == 0)) {
      return
    }

    var %t1 = $did($1, 2, %sel).text
    var %t2 = $did($1, 2, %rep).text

    did -oc $1 2 %rep %t1
    did -o  $1 2 %sel %t2
  }
}

alias dcxs_dockeddialog_cb {
}



;###############################################################
; aliases for the studio
alias -l dcxs_init_studio {
  if ($window(@dcxstudio)) {
    window -c @dcxstudio
  }

  ;// set the version into the titlebar
  dialog -t $dname $dialog($dname).title $+ $v (using DCX v $+ $v(dcx) and mIRC v $+ $version $+ )

  ;// create toolbar, statusbar, rebar, CLA
  xdialog -c $dname 1 toolbar   0   0   100 25  flat list tooltips arrows top
  xdialog -c $dname 2 statusbar 0   0   100 25  grip tooltips
  xdialog -c $dname 3 rebar     0   25  150 400 varheight fixedorder vertical noparentalign noresize notheme
  xdialog -c $dname 7 pbar      200 200 100 20  smooth
  window -hdBe @dcxstudio
  xdialog -c $dname 8 window    300 300 250 150 @dcxstudio
  xdid    -x $dname 8 +s


  ;// init toolbar
  xdid -l $dname 1 32
  ;new
  xdid -w $dname 1 +ndh 0 $sicons
  ;open
  xdid -w $dname 1 +ndh 1 $sicons
  ;save
  xdid -w $dname 1 +ndh 2 $sicons
  ; cla editor
  xdid -w $dname 1 +ndh 3 $sicons
  ; generate
  xdid -w $dname 1 +ndh 4 $sicons
  ; preferences
  xdid -w $dname 1 +ndh 5 $sicons
  ; help
  xdid -w $dname 1 +ndh 6 $sicons

  xdid -a $dname 1 0 +a  0 1 0 New             $+ $chr(9) $+ New DCX-based dialog
  xdid -a $dname 1 0 +av 0 2 0 Open            $+ $chr(9) $+ Open an existing DCX-Studio dialog
  xdid -a $dname 1 0 +a  0 3 0 Save            $+ $chr(9) $+ Save dialog layout to file
  xdid -a $dname 1 0 +a  0 0 0 -
  xdid -a $dname 1 0 +ad 0 6 0 CLA Editor      $+ $chr(9) $+ Cell Layout Algorithm Editor
  xdid -a $dname 1 0 +a  0 4 0 Generate Dialog $+ $chr(9) $+ Generate the DCX dialog script
  xdid -a $dname 1 0 +a  0 0 0 -
  xdid -a $dname 1 0 +a  0 5 0 Preferences     $+ $chr(9) $+ Configure DCX Studio
  xdid -a $dname 1 0 +a  0 0 0 -
  xdid -a $dname 1 0 +av 0 7 0 Help            $+ $chr(9) $+ Additional Information

  xdid -x $dname 1 +

  ;// init statusbar
  xdid -l $dname 2 100 300 450 -1
  xdid -t $dname 2 1 + 0 Control ID: 0        $+ $chr(9) $+ Selected control ID
  xdid -t $dname 2 2 + 0 Control Type: Dialog $+ $chr(9) $+ Selected control type
  xdid -t $dname 2 3 + 0 X, Y:                $+ $chr(9) $+ Current control coordinates (relative to parent)
  xdid -t $dname 2 4 + 0 W, H:                $+ $chr(9) $+ Current control dimensions



  ;// init rebar
  xdid -a $dname 3 0 +cge 0 150 220 0 $rgb(0,0,255) Normal Controls $chr(9) 4 toolbar 0 0 400 25 vertical list flat
  xdid -a $dname 3 0 +cge 0 150 0   0 $rgb(0,0,255) DCX Controls    $chr(9) 5 toolbar 0 0 400 25 vertical list flat
  xdid -a $dname 3 0 +cge 0 150 0   0 $rgb(0,0,255) DCX Containers  $chr(9) 6 toolbar 0 0 400 25 vertical list flat

  xdid -x $dname 3 +b



  ;// init rebar toolbars
  xdid -l $dname 4 16
  xdid -j $dname 4 145 150

  ; line
  xdid -w $dname 4 +ndh 23 $cicons
  ; box
  xdid -w $dname 4 +ndh 0 $cicons
  ; radio
  xdid -w $dname 4 +ndh 1 $cicons
  ; check
  xdid -w $dname 4 +ndh 2 $cicons
  ; edit
  xdid -w $dname 4 +ndh 3 $cicons
  ; scroll
  xdid -w $dname 4 +ndh 4 $cicons
  ; image
  xdid -w $dname 4 +ndh 5 $cicons
  ; list
  xdid -w $dname 4 +ndh 6 $cicons
  ; link
  xdid -w $dname 4 +ndh 7 $cicons
  ; text
  xdid -w $dname 4 +ndh 8 $cicons
  ; button
  xdid -w $dname 4 +ndh 17 $cicons

  xdid -a $dname 4 0 +wk 0 11 0 Button
  xdid -a $dname 4 0 +wk 0  2 0 Box
  xdid -a $dname 4 0 +wk 0  4 0 Check
  xdid -a $dname 4 0 +wk 0  5 0 Edit
  xdid -a $dname 4 0 +wk 0  7 0 Image
  xdid -a $dname 4 0 +wk 0  1 0 Line
  xdid -a $dname 4 0 +wk 0  9 0 Link
  xdid -a $dname 4 0 +wk 0  8 0 List
  xdid -a $dname 4 0 +wk 0  3 0 Radio
  xdid -a $dname 4 0 +wk 0  6 0 Scroll
  xdid -a $dname 4 0 +wk 0 10 0 Text
  ;---
  xdid -l $dname 5 16
  xdid -j $dname 5 145 150

  ; pbar
  xdid -w $dname 5 +ndh 9 $cicons
  ; treeview
  xdid -w $dname 5 +ndh 10 $cicons
  ; listview
  xdid -w $dname 5 +ndh 11 $cicons
  ; toolbar
  xdid -w $dname 5 +ndh 12 $cicons
  ; statusbar
  xdid -w $dname 5 +ndh 13 $cicons
  ; comboex
  xdid -w $dname 5 +ndh 14 $cicons
  ; trackbar
  xdid -w $dname 5 +ndh 15 $cicons
  ; richedit
  xdid -w $dname 5 +ndh 16 $cicons
  ; colorcombo
  xdid -w $dname 5 +ndh 25 $cicons
  ; button
  xdid -w $dname 5 +ndh 17 $cicons
  ; ip address
  xdid -w $dname 5 +ndh 18 $cicons
  ; updown
  xdid -w $dname 5 +ndh 19 $cicons
  ; webctrl
  xdid -w $dname 5 +ndh 26 $cicons
  ; calendar
  xdid -w $dname 5 +ndh 30 $cicons
  ; datetime
  xdid -w $dname 5 +ndh 27 $cicons

  ;xdid -a $dname 5 0 +wk 0 10 0 Button
  xdid -a $dname 5 0 +wk 0 14 0 Calendar
  xdid -a $dname 5 0 +wk 0 15 0 DateTime
  xdid -a $dname 5 0 +wk 0 9  0 ColorCombo
  xdid -a $dname 5 0 +wk 0 6  0 ComboEx
  xdid -a $dname 5 0 +wk 0 11 0 IP Address
  xdid -a $dname 5 0 +wk 0 3  0 ListView
  xdid -a $dname 5 0 +wk 0 1  0 Progressbar
  xdid -a $dname 5 0 +wk 0 8  0 RichEdit
  xdid -a $dname 5 0 +wk 0 5  0 Statusbar
  xdid -a $dname 5 0 +wk 0 4  0 Toolbar
  xdid -a $dname 5 0 +wk 0 7  0 Trackbar
  xdid -a $dname 5 0 +wk 0 2  0 TreeView
  xdid -a $dname 5 0 +wk 0 12 0 UpDown
  xdid -a $dname 5 0 +wk 0 13 0 WebControl
  ;---
  xdid -l $dname 6 16
  xdid -j $dname 6 145 150

  ; divider
  xdid -w $dname 6 +ndh 20 $cicons
  ; panel
  xdid -w $dname 6 +ndh 28 $cicons
  ; tab
  xdid -w $dname 6 +ndh 21 $cicons
  ; window
  xdid -w $dname 6 +ndh 22 $cicons
  ; dialog
  xdid -w $dname 6 +ndh 29 $cicons
  ; rebar
  xdid -w $dname 6 +ndh 24 $cicons


  xdid -a $dname 6 0 +wk 0 6 0 Rebar
  xdid -a $dname 6 0 +wkd 0 1 0 Divider
  xdid -a $dname 6 0 +wk 0 2 0 Panel
  xdid -a $dname 6 0 +wk 0 3 0 Tab
  xdid -a $dname 6 0 +wk 0 4 0 @Window
  xdid -a $dname 6 0 +wk 0 5 0 Dialog



  ;// init pbar
  xdid -r $dname 7 0 100
  xdid -v $dname 7 0
  xdid -i $dname 7 % $+ d % $+ %



  ;// initialise CLA
  xdialog -l $dname root       $chr(9) +ph  0 0   0   0
  ; make space for toolbar and statusbar
  xdialog -l $dname space root $chr(9) +    0 $gettok($xdid(dcxstudio, 1).pos, 4, 32) 0 $gettok($xdid(dcxstudio, 2).pos, 4, 32)
  ; left control is the rebar
  xdialog -l $dname cell root  $chr(9) +fwi 3 9 150 0
  ;// fill space for the other part
  xdialog -l $dname cell root  $chr(9) +pv  0 1 0 0
  ; set the window
  xdialog -l $dname cell 2     $chr(9) +li  8 1 1 1
  ; align pbar to the bottom
  xdialog -l $dname cell 2     $chr(9) +fvi 7 1 0 0

  .timer 1 0 xdialog -l $dname update
}



;###############################################################
; set up the xpopup menus for studio
alias -l dcxs_init_menus {
  var %menu dcxs.tb.open
  dcxs_init_menuCreate %menu

  xpopup -i %menu 1   dcxstudio_gfx\studio.icl
  xpopup -i %menu 102 dcxstudio_gfx\shell.dll

  xpop -a %menu 0 $chr(9) + 1 1 &Open DCXS Project
  xpop -a %menu 0 $chr(9) + 0 0 -
  xpop -a %menu 0 $chr(9) + 2 2 &Import from mIRC Script



  %menu = dcxs.tb.help
  dcxs_init_menuCreate %menu

  xpopup -i %menu 4  dcxstudio_gfx\shell.dll
  xpopup -i %menu 16 dcxstudio_gfx\shell.dll
  xpopup -i %menu 61 dcxstudio_gfx\shell.dll
  xpopup -i %menu 87 dcxstudio_gfx\shell.dll

  xpop -a %menu 0 $chr(9) + 1 2 DCX &Forum Thread
  xpop -a %menu 0 $chr(9) + 2 1 &Readme
  xpop -a %menu 0 $chr(9) + 4 4 Change &Log
  xpop -a %menu 0 $chr(9) + 0 0 -
  xpop -a %menu 0 $chr(9) + 3 3 &About
}

;// $1 = menu name
alias -l dcxs_init_menuCreate {
  if ($xpopup($1).ismenu) { xpopup -d $1 }

  xpopup -c $1 vertical
  xpopup -x $1 +dp

  xpopup -l $1 2 $rgb(58, 110, 165)
  xpopup -l $1 5 $rgb(214, 230, 250)
  xpopup -l $1 7 $rgb(214, 230, 250)
  xpopup -l $1 8 $rgb(58, 110, 165)
}




;###############################################################
;create hash table and initialise
alias -l dcxs_init_hash {
  if (!$hget(dcxs.tmp))    hmake dcxs.tmp
  if (!$hget(dcxs.idlist)) hmake dcxs.idlist
  if (!$hget(dcxs.proj))   hmake dcxs.proj

  ;// load preferences from file
  t load preferences

  ;// load defaults for controls
  dcxs_init_hash_controlDefaults pbar       100 20  smooth
  dcxs_init_hash_controlDefaults Treeview   150 200 haslines showsel tabstop
  dcxs_init_hash_controlDefaults Listview   400 150 report fullrow showsel nolabelwrap tooltip tabstop
  dcxs_init_hash_controlDefaults toolbar    0   0   flat top list tooltips arrows tabstop
  dcxs_init_hash_controlDefaults statusbar  0   0   grip tooltips
  dcxs_init_hash_controlDefaults ComboEx    150 300 dropdown tabstop
  dcxs_init_hash_controlDefaults trackbar   150 40  bottom downisleft tabstop tooltips
  dcxs_init_hash_controlDefaults ReBar      0   0   varheight
  dcxs_init_hash_controlDefaults RichEdit   150 150 multi hsbar vsbar tabstop
  dcxs_init_hash_controlDefaults ColorCombo 150 20  tabstop
  dcxs_init_hash_controlDefaults button     75  20  tabstop
  dcxs_init_hash_controlDefaults ipaddress  150 20  tabstop
  dcxs_init_hash_controlDefaults UpDown     0   0   arrowkeys buddyint
  dcxs_init_hash_controlDefaults webctrl    300 300 tabstop
  dcxs_init_hash_controlDefaults Calendar   200 150 notoday tabstop
  dcxs_init_hash_controlDefaults DateTime   200 20  tabstop longdateformat

  dcxs_init_hash_controlDefaults Line       150 15
  dcxs_init_hash_controlDefaults Box        150 100
  dcxs_init_hash_controlDefaults Radio      150 20  tabstop
  dcxs_init_hash_controlDefaults Check      150 20  tabstop
  dcxs_init_hash_controlDefaults Edit       150 20  autohs autovs tabstop
  dcxs_init_hash_controlDefaults Scroll     150 20  tabstop
  dcxs_init_hash_controlDefaults Image      133 142
  dcxs_init_hash_controlDefaults list       150 100 tabstop vsbar
  dcxs_init_hash_controlDefaults Link       150 20  tabstop
  dcxs_init_hash_controlDefaults Text

  dcxs_init_hash_controlDefaults Divider
  dcxs_init_hash_controlDefaults Panel      250 150
  dcxs_init_hash_controlDefaults Tab        300 200 tabstop notheme

  dcxs_init_hash_controlDefaults Window     250 150
  dcxs_init_hash_controlDefaults Dialog     250 150
}

/*
$1  = control type
$2  = w
$3  = h
$4- = styles
*/
alias -l dcxs_init_hash_controlDefaults {
  hadd dcxs.pref default. $+ $1 $+ .w $2
  hadd dcxs.pref default. $+ $1 $+ .h $3
  hadd dcxs.pref default. $+ $1 $+ .s $4-
}


;###################################################
; create options for controls on property panel
alias -l dcxs_init_propertyPanels {
  did -ac $dname 32 0: Main

  ;// init combo ex options
  did -ac $dname 179 Simple
  did -a  $dname 179 DropDown
  did -a  $dname 179 DropEdit

  ;// init treeview icon size
  did -ac $dname 114 16
  did -a  $dname 114 24
  did -a  $dname 114 32

  ;// listview
  did -ac $dname 88 Icon
  did -a  $dname 88 SmallIcon
  did -a  $dname 88 List
  did -a  $dname 88 Report

  did -ac $dname 122 Align Left
  did -a  $dname 122 Align Top

  ;// box
  did -ac $dname 204 Left
  did -a  $dname 204 Center
  did -a  $dname 204 Right

  ;// radio
  did -ac $dname 207 Left
  did -a  $dname 207 Center
  did -a  $dname 207 Right

  ;// checkbox
  did -ac $dname 210 Left
  did -a  $dname 210 Center
  did -a  $dname 210 Right

  ;// text
  did -ac $dname 224 Left
  did -a  $dname 224 Center
  did -a  $dname 224 Right

  ;// edit
  did -ac $dname 226 Left
  did -a  $dname 226 Center
  did -a  $dname 226 Right

  ;// richedit
  did -ac $dname 253 Left
  did -a  $dname 253 Center
  did -a  $dname 253 Right

  ;// toolbar
  did -ac $dname 152 Top
  did -a  $dname 152 Bottom
  did -a  $dname 152 Left
  did -a  $dname 152 Right

  did -ac $dname 154 16
  did -a  $dname 154 24
  did -a  $dname 154 32

  ;// statusbar
  did -ac $dname 177 Top
  did -a  $dname 177 Bottom

  ;// trackbar
  did -ac $dname 187 Both
  did -a  $dname 187 Top
  did -a  $dname 187 Bottom
  did -a  $dname 187 Left
  did -a  $dname 187 Right

  did -ac $dname 194 Top
  did -a  $dname 194 Bottom
  did -a  $dname 194 Left
  did -a  $dname 194 Right

  ;// updown
  ;// not needed as this is refilled dynamically
  ;did -ac $dname 257 Loaded default

  did -ac $dname 259 10
  did -a  $dname 259 16

  ;// tab
  did -ac $dname 289 Top
  did -a  $dname 289 Bottom
  did -a  $dname 289 Left
  did -a  $dname 289 Right

  ;// rebar
  did -ac $dname 77 Top
  did -a  $dname 77 Bottom
  did -a  $dname 77 Left
  did -a  $dname 77 Right
}

alias -l dcxs_init_prefs {
  ;// status window options
  if ($pref(status.show))    did -c $dname 18
  if ($pref(status.work))    did -c $dname 19
  if ($pref(status.error))   did -c $dname 20
  if ($pref(status.warn))    did -c $dname 21
  if ($pref(status.comment)) did -c $dname 35
  if ($pref(status.debug))   did -c $dname 22
  if ($pref(status.todo))    did -c $dname 23
  dcxs_pref_updateStatusMsgChecks

  ;// init controls in either INIT event or seperate alias
  did -c $dname $iif($pref(control.init) == init, 27, 26)

  ;// code generation
  if ($pref(genscript.showcomments))   did -c $dname 28
  if ($pref(genscript.dcxcomments))    did -c $dname 29
  if ($pref(genscript.ctrlcomments))   did -c $dname 30
  if ($pref(genscript.callbackcode))   did -c $dname 31
  if ($pref(genscript.menuitem))       did -c $dname 36
  dcxs_pref_updateGenscriptCommentChecks

  ;// cursor stuff
  if ($pref(cursor.add))   did -c $dname 7
  if ($pref(cursor.hover)) did -c $dname 8

  ;// highlighting
  if ($pref(hilight.enabled))      did -c $dname 9
  if (b isin $pref(hilight.style)) did -c $dname 10
  if (c isin $pref(hilight.style)) did -c $dname 11
  if (d isin $pref(hilight.style)) did -c $dname 12
  if (f isin $pref(hilight.style)) did -c $dname 13
  if (s isin $pref(hilight.style)) did -c $dname 14
  if (w isin $pref(hilight.style)) did -c $dname 15
  dcxs_pref_updateHoverBorderChecks
}

;// init tab/rebar item editor
; $1 = mode (tab | rebar)
; $2 = id of control being edited
alias -l dcxs_init_ieditor {
  var %c $cprop($2, items)
  var %i 1

  ;// load types for rebar or tab
  if ($temp(ieditor.mode) == rebar) {
    didtok $dname  19 44 Button,ColorCombo,ComboEx,Divider,Listview,Panel,Progressbar,RichEdit,Statusbar,Tab,Toolbar,Trackbar,TreeView
    did -ra $dname 20    button,colorcombo,comboex,divider,listview,panel,pbar,richedit,statusbar,tab,toolbar,trackbar,treeview
  }
  else {
    didtok $dname  19 44 Divider,Edit,Image,List,Listview,Panel,Rebar,RichEdit,Tab,TreeView,Web
    did -ra $dname 20    divider,edit,image,list,listview,panel,rebar,richedit,tab,treeview,webctrl
  }

  hdel -w dcxs.tmp control.*

  while ($gettok(%c, %i, 32)) {
    var %id $ifmatch
    var %k  1

    did -a $dname 2 %id $+ : $cname($cprop(%id, type)) ( $+ $cprop(%id, caption) $+ )

    while ($hfind(dcxs.proj, $+(control., %id, .*), %k, w)) {
      var %h $ifmatch
      temp %h $hget(dcxs.proj, %h)
      inc %k
    }

    inc %i
  }

  did -c $dname 2 1
  dcxs_ieditor_showDetails
}


alias -l dcxs_init_generator {
  ;// Initialising control: Box (#1)
  xdialog -c $dname 1 box 6 6 550 420
  xdid -t $dname 1 Generated Dialog Script

  ;// Initialising control: Button (#3)
  xdialog -c $dname 3 button 7 433 70 20 disabled tabstop
  xdid -t $dname 3 &Save

  ;// Initialising control: Button (#4)
  xdialog -c $dname 4 button 486 433 70 20 disabled default ok tabstop
  xdid -t $dname 4 &Done

  ;// Initialising control: Button (#5)
  xdialog -c $dname 5 button 83 433 70 20 disabled tabstop
  xdid -t $dname 5 D&emo

  ;// Initialising control: Button (#6)
  xdialog -c $dname 6 button 160 433 70 20 tabstop disabled
  xdid -t $dname 6 &Copy All


  ;// Initialising control: Edit (#2)
  xdid -c $dname 1 2 edit 8 20 532 390 multi return autovs vsbar tabstop
  ;//xdid -a $dname 2

  ;// need to figure out a way to prevent it from covering the whole box
  ;xdid -l $dname 1 root      $chr(9) +pl 0 1 0 0
  ;xdid -l $dname 1 cell root $chr(9) +li 2 1 0 0
  ;.timer 1 0 xdid -l $dname 1 update
}



;###############################################################
;create default new controls by mouse click
;$1 = dialog
;$2 = new control ID
;$3 = type
;$4 = X coordinate
;$5 = Y coordinate
;$6 = parent ID (box, panel, etc)
alias -l dcxs_control_create {
  if ($5 == $null) {
    e /dcxs_control_create: insufficient parameters
    return
  }
  ;// radio #1 control bug
  else if (($3 == radio) && ($2 == 1)) {
    msgbox Radio control bug, cannot be first control on dialog (awaiting DCX bugfixes)
    halt
  }


  ;// copy defaults
  var %w $iif($hget(dcxs.pref, default. $+ $3 $+ .w), $ifmatch, 100)
  var %h $iif($hget(dcxs.pref, default. $+ $3 $+ .h), $ifmatch, 20)
  ;// style
  var %s $iif($hget(dcxs.pref, default. $+ $3 $+ .s), $ifmatch)
  var %x
  var %y

  ;// do some minor preparation for the extra controls
  if ($3 == window) {
    %s = @window. $+ $2
    cprop $2 style %s

    if (!$window(%s)) {
      d /dcxs_control_create: Creating window %s
      window -hd %s $mouse.dx $mouse.dy %w %h
    }
  }
  else if ($3 == dialog) {
    %s = dialog. $+ $2
    cprop $2 style %s

    if (!$dialog(%s)) {
      d /dcxs_control_create: Creating dialog %s
      dialog -ma %s dcxs_test_table
      ;dcx Mark $dname dcxs_dockeddialog_cb
      dcx Mark %s dcxs_dockeddialog_cb
    }
  }
  else {
    cprop $2 style %s
  }

  ;// if no style set
  ;if (!%s) {
  ;  w /dcxs_control_create: no default style set for type $3
  ;}

  ;// creating child control
  if ($6) {
    ;// calc the diff between control pos and mouse pos
    var %p = $xdid($1, $6).mouse

    %x = $gettok(%p, 1, 32)
    %y = $gettok(%p, 2, 32)

    d /dcxs_control_create: Create child: xdid -c $1 $6 $2 $3 %x %y %w %h %s
    xdid -c $1 $6 $2 $3 %x %y %w %h %s
    cprop $2 pid   $6
    cprop $2 ptype $cprop($6, type)
  }
  ;// creating normal control
  else {
    %x = $4
    %y = $5

    d /dcxs_control_create: Create control: xdialog -c $1 $2 $3 %x %y %w %h %s
    xdialog -c $1 $2 $3 $4 $5 %w %h %s
    cprop $2 pid 0
  }

  var %p $xdid($1, $2).pos

  cprop $2 x     $gettok(%p, 1, 32)
  cprop $2 y     $gettok(%p, 2, 32)
  cprop $2 w     $gettok(%p, 3, 32)
  cprop $2 h     $gettok(%p, 4, 32)
  cprop $2 caption
  cprop $2 type  $3

  ;// fix the height bug
  if ($3 == comboex) {
    t FIXME: combo height bug
    cprop $2 h $hget(dcxs.pref, default.comboex.h)
  }

  ;// add it to the "select control" list
  did -ac dcxprop 32 $2 $+ : $cname($cprop($2, type))

  dcxs_control_init $1 $2 $3

  ;// fix the height bug for rebar
  if ($3 == rebar) {
    t FIXME: rebar height bug
    ;cprop $2 h $gettok($xdid(dcxtest, $2).pos, 4, 32)
  }
}



;####################################
; recreates a specific control
; // needs to be fixed to accomodate for child windows, etc
;// $1 = ID
alias -l dcxs_control_recreate {
  ;// main dialog doesnt need to be recreated
  if ($1 == 0) {
    ;// Main dialog doesnt need recreating, just set border styles, resize

    set %dcxs.openProject $true
    xdialog -r dcxtest
    dcxs_control_init dcxtest 0 main $true
    dcxs_control_moveto      0 $cprop(0, x) $cprop(0, y) $cprop(0, w) $cprop(0, h)
    unset %dcxs.openProject
    return
  }

  set %dcxs.recreate $true

  var %x $cprop($1, x)
  var %y $cprop($1, y)
  var %w $cprop($1, w)
  var %h $cprop($1, h)
  var %s $cprop($1, style)
  var %t $cprop($1, type)
  var %p $cprop($1, pid)
  var %c $true

  ;// if control doesnt exists, no need to delete it
  if (!$xdialog(dcxtest, $1).isid) %c = $false

  ;// if child
  if (%p > 0) {
    var %f
    var %pt    $cprop($1, ptype)
    var %order

    ;// if control exists, delete
    if (%c) {
      if ((%pt == tab) || (%pt == rebar)) {
        %order = $findtok($cprop(%p, items), $1, 1, 32)

        xdid -d dcxtest %p %order
      }
      else {
        xdid -d dcxtest %p $1
      }
    }

    ;// if tab or rebar, add to owner
    if ((%pt == tab) || (%pt == rebar)) {
      %order = $findtok($cprop(%p, items), $1, 1, 32)

      if (%pt == tab) {
        %f = xdid -a dcxtest %p %order 0 $cprop($1, caption) $chr(9) $1 %t %x %y %w %h %s
      }
      else {
        %f = xdid -a dcxtest %p %order +ge 0 %h 220 0 0 $cprop($1, caption) $chr(9) $1 %t %x %y %w %h %s $chr(9) Tooltip
      }
    }
    else {
      %f = xdid -c dcxtest %p $1 %t %x %y %w %h %s
    }

    d /dcxs_control_recreate: Child: %f
    %f

    if (%pt == tab) {
      ;// select the newly created tab
      xdid -c dcxtest %p %order
    }
  }
  else {
    if (%c) xdialog -d dcxtest $1

    xdialog -c dcxtest $1 %t %x %y %w %h %s

    d /dcxs_control_recreate: Control: xdialog -c dcxtest $1 %t %x %y %w %h %s
  }

  ;// add it to the "select control" list if it isnt already there
  if (!$wildtok($didtok(dcxprop, 32, 44), $1 $+ : *, 1, 44)) {
    did -ac dcxprop 32 $1 $+ : $cname(%t)
  }

  ;// set the default stuff for the control
  dcxs_control_init dcxtest $1 %t $true

  dcxs_prog recreateAll $xdialog(dcxtest, 0).id

  ;// recreate children
  if ($hasChildren($1)) {
    var %c $getChildren($1)
    var %i 1

    while ($gettok(%c, %i, 32)) {
      var %id $ifmatch

      whileFix
      recursive dcxs_control_recreate %id
      inc %i
    }
  }

  unset %dcxs.recreate
}




;// recreate ALL controls on a blank dialog
; reads off the idlist table
alias -l dcxs_control_recreateAll {
  var %i 1
  var %reset $false
  var %k $idlist(0)
  var %x %k

  ;// minus one for main dialog
  dcxs_prog -t recreateAll $calc(%k -1)

  ;// loop until all controls have been created
  while (%x) {
    var %id = $idlist(%i)

    ;// if null, ignore for now
    if (%id == $null) {
      d /dcxs_control_recreateAll: null
      %reset = $true
    }
    ;// control exists, remove id from ids
    else if ($xdialog(dcxtest, %id).isid) {
      d /dcxs_control_recreateAll: Control already exists > %id > $cprop(%id, pid)

      idlist -d %id
      %reset = $true
    }
    else if ((%id == 0) || ($cprop(%id, pid) == 0) || ($xdialog(dcxtest, $cprop(%id, pid)).isid)) {
      dcxs_control_recreate %id

      idlist -d %id
      %reset = $true
    }
    else {
      ;w dcxs_control_recreateAll: cannot create control yet %id > $cprop(%id, pid)
    }

    inc %i
    %x = $idlist(0)

    ;// reset the counter
    if (%i > %x) {
      if (%reset == $true) {
        %i = 1
        %reset = $false
      }
      else {
        e /dcxs_control_recreateAll: Possible infinite loop, processing halted
        msgbox Possible infinite loop detected. Dialog creation process aborted.
        halt
      }
    }
  }
}




;###############################################################
;init new controls with default values
;$1 = dialog
;$2 = ID
;$3 = type
;$4 = recreate
alias -l dcxs_control_init {
  if ($3 == pbar) {
    if (!$4) {
      cprop $2 value 0
      cprop $2 min   0
      cprop $2 max   100
      cprop $2 caption $eval(%d %%, 0)
    }

    xdid -v $1 $2 $cprop($2, value)
    xdid -r $1 $2 $cprop($2, min) $cprop($2, max)
    xdid -i $1 $2 $cprop($2, caption)

    xdid -M $1 $2 +s

    if (marquee isin $cprop($2, style)) xdid -mo $1 $2
  }
  if ($3 == treeview) {
    if (!$4) {
      cprop $2 iconsize 16
    }

    xdid -l $1 $2 $cprop($2, iconsize)

    xdid -w $1 $2 +n 1 $icons
    xdid -w $1 $2 +ng 2 $icons
    xdid -w $1 $2 +n 3 $icons
    xdid -w $1 $2 +ng 4 $icons
    xdid -w $1 $2 +n 5 $icons
    xdid -w $1 $2 +n 6 $icons
    xdid -w $1 $2 +n 7 $icons
    xdid -w $1 $2 +n 8 $icons

    xdid -a $1 $2 $+(-1,       $chr(9), +bce 1 2 0 1 0 $rgb(0,0,255) Select Treeview, $chr(9), Properties)
    xdid -a $1 $2 $+(-1 -1,    $chr(9), +i   2 3 0 0 0 $rgb(0,0,255) Item 1 1,        $chr(9), Properties)
    xdid -a $1 $2 $+(-1 -1,    $chr(9), +be  3 4 0 0 0 $rgb(0,0,255) Item 1 2,        $chr(9), Properties)
    xdid -a $1 $2 $+(-1 -1 -1, $chr(9), +    4 5 0 1 0 $rgb(0,0,255) Item 1 2 1,      $chr(9), Properties)
    xdid -a $1 $2 $+(-1 -1 -1, $chr(9), +    5 6 0 2 0 $rgb(0,0,255) Item 1 2 2,      $chr(9), Properties)
    xdid -a $1 $2 $+(-1 -1,    $chr(9), +    6 7 0 0 0 $rgb(0,0,255) Item 1 3,        $chr(9), Properties)
    xdid -a $1 $2 $+(-1,       $chr(9), +bce 7 8 0 0 0 $rgb(255,0,0) Item 2,          $chr(9), Properties)
    xdid -a $1 $2 $+(-1 -1,    $chr(9), +i   8 1 0 2 0 $rgb(0,0,255) Item 2 1,        $chr(9), Properties)

    xdid -M $1 $2 +c
  }
  if ($3 == listview) {
    xdid -w $1 $2 +n 1 $icons
    xdid -w $1 $2 +n 2 $icons
    xdid -w $1 $2 +n 3 $icons
    xdid -w $1 $2 +n 4 $icons
    xdid -w $1 $2 +n 5 $icons
    xdid -w $1 $2 +n 6 $icons
    xdid -w $1 $2 +n 7 $icons

    xdid -t $1 $2 + 1 150 $+(Column 1, $chr(9), + 0 150 Column 2, $chr(9), + 0 140 Column 3)

    xdid -a $1 $2 0 0 +pb 4 2 0 0 0 0 $+(notheme smooth, $chr(9), +  0 Text2,   $chr(9), +  0 Text3)
    xdid -a $1 $2 0 0 +bi 5 1 0 0 0 0 $+(Obj 3,          $chr(9), +p 0 notheme, $chr(9), +  0 Text3)
    xdid -a $1 $2 0 0 +c  6 0 0 0 255 0 $+(Obj 4,        $chr(9), +  0 Text2,   $chr(9), +p 0 dcxpbar)
    xdid -a $1 $2 0 0 +ti 7 2 0 0 0 0 $+(Obj 5,          $chr(9), +  0 Text2,   $chr(9), +  0 Text3)
    xdid -a $1 $2 0 0 +pck 7 2 0 0 255 123456 $+(Obj 5,  $chr(9), + 0 Text2,   $chr(9), +  0 Text3)
    xdid -a $1 $2 0 0 +pb 4 2 0 0 0 0 $+(notheme smooth, $chr(9), +  0 Text2,   $chr(9), +  0 Text3)
    xdid -a $1 $2 0 0 +b  5 1 0 0 0 0 $+(Obj 3,          $chr(9), +p 0 notheme, $chr(9), +  0 Text3)
    xdid -a $1 $2 0 0 +k  6 0 0 0 0 255 $+(Obj 4,        $chr(9), +  0 Text2,   $chr(9), +p 0 dcxpbar)
    xdid -a $1 $2 0 0 +u  7 2 0 0 0 0 $+(Obj 5,          $chr(9), +  0 Text2,   $chr(9), +  0 Text3)
    xdid -a $1 $2 0 0 +bu 7 2 0 0 0 0 $+(Obj 5,          $chr(9), +p 0 Text2,   $chr(9), +  0 Text3)

    xdid -v $1 $2 1 0 -v 33
    xdid -v $1 $2 2 1 -v 66
    xdid -v $1 $2 3 2 -v 100

    xdid -M $1 $2 +c
  }
  if ($3 == toolbar) {
    if (!$4) {
      cprop $2 iconsize 16
      cprop $2 autostretch 0

      cprop $2 btnmax
      cprop $2 btnmin
      cprop $2 defaultw
      cprop $2 defaulth
    }

    xdid -l $1 $2 $cprop($2, iconsize)
    xdid -m $1 $2 $cprop($2, autostretch)

    if ($cprop($2, btnmin) && $cprop($2, btnmax)) {
      xdid -j $1 $2 $cprop($2, btnmin) $cprop($2, btnmax)
    }
    if ($cprop($2, defaultw) && $cprop($2, defaulth)) {
      xdid -u $1 $2 $cprop($2, defaultw) $cprop($2, defaulth)
    }

    xdid -w $1 $2 +nhd 0 $icons
    xdid -w $1 $2 +nhd 1 $icons
    xdid -a $1 $2 0 +  0 1 0 SELECT  $chr(9) PROPERTIES
    xdid -a $1 $2 0 +a 0 0 0 -
    xdid -a $1 $2 0 +  0 2 0 TOOLBAR $chr(9) PROPERTIES
    xdid -a $1 $2 0 +v 0 0 0 Dropdown
  }
  if ($3 == statusbar) {
    xdid -l $1 $2 100 300 -1
    xdid -t $1 $2 1 + 0 Select     $chr(9) ack
    xdid -t $1 $2 2 + 0 Statusbar  $chr(9) blah
    xdid -t $1 $2 3 + 0 Properties $chr(9) Tooltip!
  }
  if ($3 == ComboEx) {
    xdid -w $1 $2 +g 1 $icons
    xdid -w $1 $2 +  2 $icons
    xdid -w $1 $2 +  3 $icons

    xdid -a $1 $2 0 0 1 1 0 Select ComboEx
    xdid -a $1 $2 0 0 2 2 0 Item 1
    xdid -a $1 $2 0 0 3 3 0 Item 2
    xdid -a $1 $2 0 0 0 0 0 Item 3 No Icon
    xdid -c $1 $2 1
  }
  if ($3 == trackbar) {
    if (!$4) {
      cprop $2 toolpos  top
      cprop $2 ticfreq  10
      cprop $2 value    0
      cprop $2 pagestep
      cprop $2 linestep
      cprop $2 min      0
      cprop $2 max      100
    }

    if ($cprop($2, toolpos))  xdid -t $1 $2 $ifmatch
    if ($cprop($2, ticfreq))  xdid -n $1 $2 $ifmatch
    if ($cprop($2, value))    xdid -v $1 $2 $ifmatch
    if ($cprop($2, pagestep)) xdid -m $1 $2 $ifmatch
    if ($cprop($2, linestep)) xdid -l $1 $2 $ifmatch

    if ($cprop($2, min) != $null && $cprop($2, max) != $null) xdid -r $1 $2 $cprop($2, min) $cprop($2, max)
  }
  if ($3 == rebar) {
    if (!$4) {
      var %h     32
      var %child $xdialog($1).nextid panel 0 0 220 %h

      xdid -a $1 $2 0 +ge 0 %h 220 0 0 Rebar $chr(9) %child $chr(9) Tooltip
      dcxs_control_registerChild $2 %child $chr(1) Rebar
    }
  }
  if ($3 == richedit) {
    if (!$4) {
      cprop $2 caption Select 4RichEdit Control
    }

    xdid -m $1 $2
    xdid -a $1 $2 $cprop($2, caption)

    cprop $2 mIRCcolors 1
    xdid -M $1 $2 +c
  }
  if ($3 == colorcombo) {
    xdid -m $1 $2
    xdid -c $1 $2 1

    cprop $2 mirccolors 0
  }
  if ($3 == button) {
    if (!$4) {
      cprop $2 caption Button
    }

    xdid -t $1 $2 $cprop($2, caption)
  }
  if ($3 == ipaddress) {
    if (!$4) {
      cprop $2 caption 127.0.0.1
    }

    xdid -a $1 $2 $cprop($2, caption)
    xdid -M $1 $2 +c
  }
  if ($3 == UpDown) {
    if (!$4) {
      cprop $2 base  10
      cprop $2 min   0
      cprop $2 max   100
      cprop $2 buddy
      cprop $2 value 50
    }

    ;// buddy control
    if ($cprop($2, buddy)) {
      xdid -c $1 $2 $ifmatch
    }

    ;// min/max
    if (($cprop($2, min) != $null) && ($cprop($2, max) != $null)) {
      xdid -r $1 $2 $cprop($2, min) $cprop($2, max)
    }

    xdid -t $1 $2 $cprop($2, base)
    xdid -v $1 $2 $cprop($2, value)
  }
  if ($3 == webctrl) {
    if (!$4) {
      cprop $2 defaultpage http://dcx.scriptsdb.org
    }

    xdid -n $1 $2 $cprop($2, defaultpage)
  }

  if ($3 == Calendar) {
    xdid -M $1 $2 +c
  }

  if ($3 == DateTime) {
    xdid -M $1 $2 +c
  }

  if ($3 == line) {
  }
  if ($3 == box) {
    if (!$4) {
      cprop $2 caption Box
    }

    xdid -t $1 $2 $cprop($2, caption)
    ;var %c $xdialog($1).nextid panel $xdid($1, $2).inbox
    ;xdid -c $1 $2 %c
    ;dcxs_control_registerChild $2 %c

    xdid -l $1 $2 root $chr(9) +pl 0 1 0 0
    .timer 1 0 xdid -l $1 $2 update
  }
  if ($3 == radio) {
    if (!$4) {
      cprop $2 caption Radio
    }

    xdid -t $1 $2 $cprop($2, caption)
  }
  if ($3 == Check) {
    if (!$4) {
      cprop $2 caption Check
    }

    xdid -t $1 $2 $cprop($2, caption)
  }
  if ($3 == edit) {
    if (!$4) {
      cprop $2 caption Edit
      cprop $2 limit
    }

    if ($cprop($2, limit)) xdid -q $1 $2 $ifmatch

    xdid -a $1 $2 $cprop($2, caption)
    xdid -M $1 $2 +c
  }
  if ($3 == Scroll) {
  }
  if ($3 == Image) {
    var %f

    if ($4) %f = $cprop($2, image)
    else    %f = $scriptdir $+ dcxstudio_gfx\image.bmp

    xdid -i $1 $2 %f
    cprop $2 image %f
  }
  if ($3 == list) {
    xdid -a $1 $2 0 Select List
  }
  if ($3 == link) {
    if (!$4) {
      cprop $2 caption Link
    }

    xdid -t $1 $2 $cprop($2, caption)
    xdid -w $1 $2 + 0 $icons
  }
  if ($3 == text) {
    if (!$4) {
      cprop $2 caption Text
    }

    xdid -t $1 $2 $cprop($2, caption)
  }

  ;dcxs_init_hash_control Divider
  if ($3 == panel) {
    xdid -x $1 $2 +s
    xdid -M $1 $2 +s
  }
  if ($3 == tab) {
    if (!$4) {
      cprop $2 btnw
      cprop $2 btnh
    }

    if ($cprop($2, btnw) && $cprop($2, btnh)) {
      xdid -m $1 $2 $cprop($2, btnw) $cprop($2, btnh)
    }

    if (!$4) {
      var %child

      %child = $xdialog($1).nextid panel 0 0 $cprop($2, w) $cprop($2, h)
      xdid -a $1 $2 0 0 Use DCXS Tab Editor to edit tabs $+ $chr(9) $+ $xdialog($1).nextid panel 0 0 $cprop($2, w) $cprop($2, h)
      dcxs_control_registerChild $2 %child $chr(1) Use DCXS Tab Editor to edit tabs

      %child = $xdialog($1).nextid panel 0 0 $cprop($2, w) $cprop($2, h)
      xdid -a $1 $2 0 0 (Experimental)                   $+ $chr(9) $+ %child
      dcxs_control_registerChild $2 %child $chr(1) (Experimental)
    }
  }
  if ($3 == window) { }
  if ($3 == dialog) { }
  if ($3 == main) {
    if (!$4) {
      cprop 0 caption DCX Test Dialog
      cprop 0 style +mntyz
      cprop 0 name  dcxtest_ $+ $ctime
      cprop 0 type  main
      cprop 0 x     $dialog(dcxtest).x
      cprop 0 y     $dialog(dcxtest).y
      cprop 0 w     $dialog(dcxtest).cw
      cprop 0 h     $dialog(dcxtest).ch
    }

    dialog  -t $1 $cprop($2, caption)
    xdialog -b $1 $cprop($2, style) $+ $iif(z !isin $cprop($2, style), z)
  }
}


;###############################################################
;// moves a control to a specific x/y coordinate
; $1 = id
; -------- optional
; $2 = x
; $3 = y
; $4 = w
; $5 = h
alias -l dcxs_control_moveto {
  var %x $iif($2 != $null, $int($2), $cprop($1, x))
  var %y $iif($3 != $null, $int($3), $cprop($1, y))

  ;// moving control
  if ($1 > 0) {
    var %w, %h

    if ($5) {
      %w = $int($4)
      %h = $int($5)
    }
    else {
      %w = $gettok($xdid(dcxtest, $1).pos, 3, 32)
      %h = $gettok($xdid(dcxtest, $1).pos, 4, 32)
    }

    ;// only update if there are valid values
    if (%w && %h) {
      xdid -p dcxtest $1 %x %y %w %h

      ;// force update of control redrawing
      xdialog -j dcxtest
    }
  }
  ;// Moving dialog
  else {
    var %w $iif($int($4), $ifmatch, $cprop($1, w))
    var %h $iif($int($5), $ifmatch, $cprop($1, h))

    dialog -s dcxtest %x %y %w %h
  }
}



;###############################################################
; register children controls added by code (/xdid -a in panels, tabs, etc)
; $1 = parent id
; $2 = child control id
; $3 = type
; $4-= styles $chr(1) control caption
alias -l dcxs_control_registerChild {
  if ($cprop($2, type)) {
    d /dcxs_control_registerChild: Control $2 already registered.
    ;//return
  }

  var %p $xdid(dcxtest, $2).pos

  ;// get real size and position (relative to owner)
  cprop $2 x       $gettok(%p, 1, 32)
  cprop $2 y       $gettok(%p, 2, 32)
  cprop $2 w       $gettok(%p, 3, 32)
  cprop $2 h       $gettok(%p, 4, 32)
  cprop $2 style   $gettok($gettok($1-, 1, 1), 4-, 32)
  cprop $2 caption $gettok($1-, 2, 1)
  cprop $2 pid     $1
  cprop $2 ptype   $cprop($1, type)
  cprop $2 type    $3

  ;// store the child into a list in the parent cprop
  cprop $1 items   $addtok($cprop($1, items), $2, 32)

  ;// quickfix: the comboex height bug
  if ($3 == comboex) {
    t FIXME: child combo height bug
    cprop $2 h $hget(dcxs.pref, default.comboex.h)
  }

  ;// add it to the "select control" list
  if ($didwm(dcxprop, 32, $2 $+ : *, 0)) {
    var %i $ifmatch
    var %t $2 $+ : $cname($3)

    if ($did(dcxprop, 32, %i) != %t) {
      did -o dcxprop 32 %i %t
    }
  }
  else {
    did -a dcxprop 32 $2 $+ : $cname($3)
  }

  d /dcxs_control_registerChild: Adding $cprop($1, type) item ( $+ $3 > $2 > $cprop($2, caption) $+ )
}






;###############################################################
; change prop tab and show all attributes
;$1 = ID
alias -l dcxs_show_controlDetails {
  ;// currently recreating control, no need to change tabs
  if (%dcxs.recreate) {
    return
  }

  if ($1 == $null) {
    e /dcxs_show_controlDetails: Insufficient parameters
    return
  }

  var %type $cprop($1, type)
  var %show $cname2proptab(%type)

  if (!%show) {
    e /dcxtest_cb: unknown control type for ID $3
    return
  }

  ;// select the tab
  did -c dcxprop %show

  ;// if it was selected via dcxtest clicks
  if ($did != 32) {
    did -c dcxprop 32 $didwm(dcxprop, 32, $1 $+ : *)
  }

  dcxs_show_controlCoordinates $1
  dcxs_show_controlStyles $1
  dcxs_show_controlCaption $1

  dcxs_statusbar_paneltext 1 $1
  dcxs_statusbar_paneltext 2 $cname($cprop($1, type))
  dcxs_statusbar_paneltext 3 $cprop($1, x) $+ , $cprop($1, y)
  dcxs_statusbar_paneltext 4 $cprop($1, w) $+ , $cprop($1, h)
}

;####################################
; updates coordinates on property page
; $1 = ID
alias -l dcxs_show_controlCoordinates {
  if ($1 == $null) return

  ;// xywh boxes: did 37 38 39 40
  did -ra dcxprop 37 $cprop($1, x)
  did -ra dcxprop 38 $cprop($1, y)
  did -ra dcxprop 39 $cprop($1, w)
  did -ra dcxprop 40 $cprop($1, h)
}

;####################################
; updates styles on property page
; $1 = ID
alias -l dcxs_show_controlStyles {
  if ($1 == 0) {
    did -b dcxprop 41,42,43,44
  }
  else {
    did -e dcxprop 41,42,43,44
  }

  ;// general style checkboxes
  var %s = $cprop($1, style)

  did $iif(tabstop  isin %s, -c, -u) dcxprop 41
  did $iif(group    isin %s, -c, -u) dcxprop 43
  did $iif(disabled isin %s, -c, -u) dcxprop 42
  did $iif(notheme  isin %s, -c, -u) dcxprop 44

  var %alias dcxs_control_loadStyle_ $+ $cprop($1, type)

  if ($isalias(%alias)) %alias $1 %s
  else                  w /dcxs_show_controlStyles: no such alias -l %alias
}

;####################################
; load the control caption, disables if n/a
; $1 = ID
alias -l dcxs_show_controlCaption {
  var %t $cprop($1, type)

  ;// show and enable
  if ((%t == main) || (%t == pbar) || (%t == edit) || (%t == richedit) || (%t == ipaddress) || (%t == button) || (%t == box) || (%t == radio) || (%t == check) || (%t == link) || (%t == text)) {
    did -era dcxprop 35 $cprop($1, caption)
  }
  ;// disable
  else {
    did -rb dcxprop 35
  }
}



;####################################
; to set statusbar info without modifying the rset of the text
; $1 = panel index
; $2-= text
alias -l dcxs_statusbar_paneltext {
  if      ($1 == 1) xdid -v dcxstudio 2 1 Control ID: $2-
  else if ($1 == 2) xdid -v dcxstudio 2 2 Control Type: $2-
  else if ($1 == 3) xdid -v dcxstudio 2 3 X, Y: $2-
  else if ($1 == 4) xdid -v dcxstudio 2 4 W, H: $2-
}


;####################################
; loads the current XOR'd style into a $did control
; $1 = dcx ID
; $2 = prop ID
;[#3]= style (used for $cprop not %style
alias -l dcxs_select_controlStyle {
  var %i 1

  if ($3) {
    did -c dcxprop $2 $findtok($didtok(dcxprop, $2, 44), $cprop($1, $3), 1, 44)
  }
  else {
    var %s $cprop($1, style)

    while ($did(dcxprop, $2, %i)) {
      if ($findtok(%s, $ifmatch, 1, 32)) {
        did -c dcxprop $2 %i
        break
      }

      inc %i
    }
  }
}



;####################################
; selects a specific item in a toolbox, given the index
; $1 = toolbar id
; $2 = item index
; no input for no selection
alias -l dcxs_select_toolboxItem {
  var %tb 4,5,6
  var %i  1

  ;// change cursor accordingly
  if ($2 == $null) {
    xdialog -q dcxtest +r arrow
  }
  else {
    xdialog -q dcxtest +r cross
  }

  while ($gettok(%tb, %i, 44)) {
    var %toolbar = $ifmatch
    var %k = $xdid(dcxstudio, %toolbar).num

    while (%k) {
      if ((%toolbar != $1) || (%k != $2)) {
        if (x isin $xdid(dcxstudio, %toolbar, %k).state) {
          xdid -t dcxstudio %toolbar %k $remove($xdid(dcxstudio, %toolbar, %k).state, x)
        }
      }

      dec %k
    }

    inc %i
  }
}




;####################################
; sets the caption of the current control
; $1  = 0
; $2  = type
; $3- = text
alias -l dcxs_control_setCaption {
  var %c

  cprop $1 caption $3-

  if ($2 == main) {
    dialog -t dcxtest $3-
    return
  }
  else if ($2 == pbar) {
    %c = -i
  }
  else if (($2 == edit) || ($2 == richedit)) {
    %c = -ra
  }
  else if ($2 == ipaddress) {
    %c = -a
  }
  else if (($2 == button) || ($2 == box) || ($2 == radio) || ($2 == check) || ($2 == link) || ($2 == text)) {
    %c = -t
  }

  ;// set the caption
  if (%c) {
    xdid $ifmatch dcxtest $1 $3-
  }
}


; adds/removes the control style in the hash table
; $1 = ID
; $2 = style
; $3 = on/off
alias -l dcxs_control_setStyle {
  var %s $cprop($1, style)

  if ($3) %s = $addtok(%s, $2, 32)
  else    %s = $remtok(%s, $2, 32)

  cprop $1 style %s
}

;// exclusively select one of the styles, not more than one can be selected
;$1 = id of dcx control
;$2 = id of property control
alias -l dcxs_control_setStyleXOR {
  var %i 1

  while ($did(dcxprop, $2, %i)) {
    dcxs_control_setStyle $1 $remove($ifmatch, $chr(32)) 0
    inc %i
  }

  dcxs_control_setStyle $1 $remove($lower($did($2).seltext), $chr(32)) 1
}

;// set or unset a particular flag style
;$1 = ctrl id
;$2 = property
;$3 = flag
;$4 = on/off
alias -l dcxs_control_setFlags {
  var %p = $cprop($1, $2)

  if (($4) && ($3 !isin %p)) {
    %p = %p $+ $3
  }
  else if ((!$4) && ($3 isin %p)) {
    %p = $remove(%p, $3)
  }

  cprop $1 $2 %p
  ;return %p
}









;[ various functions to modify the control options ]----------------------------
;$1 == id
;return $true if u want it to... <-- stuff this idea for now

alias -l dcxs_control_modify_box {
  if ($did == 204) dcxs_control_setStyleXOR $1 204

  if ($did == 201) dcxs_control_setStyle $1 squared $did($did).state
  if ($did == 205) dcxs_control_setStyle $1 bottom $did($did).state

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_pbar {
  ;// changed value
  if ($did == 89) {
    xdid -v dcxtest $1 $int($did(89))
    cprop $1 value $int($did(89))
    return
  }

  ;// changed min
  if ($did == 90) {
    xdid -r dcxtest $1 $int($did(90)) $cprop($1, max)
    cprop $1 min $int($did(90))
    return
  }

  ;// changed max
  if ($did == 91) {
    xdid -r dcxtest $1 $cprop($1, min) $int($did(91))
    cprop $1 max $int($did(91))
    return
  }

  if ($did == 86) {
    var %w $cprop($1, w)
    var %h $cprop($1, h)

    cprop $1 w %h
    cprop $1 h %w

    dcxs_control_setStyle $1  vertical     $did($did).state
  }
  ;if ($did == 86) dcxs_control_setStyle $1 vertical $did($did).state


  if ($did == 85) dcxs_control_setStyle $1 smooth $did($did).state

  if ($did == 87) dcxs_control_setStyle $1 marquee $did($did).state

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_comboex {
  if ($did == 179) dcxs_control_setStyleXOR $1 179

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_treeview {
  ;// icon size
  if ($did == 114) {
    cprop $1 iconsize $did(114).seltext
    ;xdid -l dcxtest $1 $did(114).seltext
    ;return
  }

  if ($did == 94 ) dcxs_control_setStyle $1 haslines     $did($did).state
  if ($did == 95 ) dcxs_control_setStyle $1 hasbuttons   $did($did).state
  if ($did == 96 ) dcxs_control_setStyle $1 editlabel    $did($did).state
  if ($did == 97 ) dcxs_control_setStyle $1 noscroll     $did($did).state
  if ($did == 98 ) dcxs_control_setStyle $1 showsel      $did($did).state
  if ($did == 99 ) dcxs_control_setStyle $1 singleexpand $did($did).state
  if ($did == 100) dcxs_control_setStyle $1 linesatroot  $did($did).state
  if ($did == 101) dcxs_control_setStyle $1 checkbox     $did($did).state
  if ($did == 102) dcxs_control_setStyle $1 nohscroll    $did($did).state
  if ($did == 103) dcxs_control_setStyle $1 notooltips   $did($did).state
  if ($did == 104) dcxs_control_setStyle $1 fullrow      $did($did).state

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_listview {
  if ($did == 88 ) dcxs_control_setStyleXOR $1 $did
  if ($did == 122) dcxs_control_setStyleXOR $1 $did

  ;138 sorting method

  ;135 Sort ascending
  ;136 Sort decending

  ;140 bg image
  ;141 Tiled

  if ($did == 105) dcxs_control_setStyle $1  singlesel    $did($did).state
  if ($did == 116) dcxs_control_setStyle $1  flatsb       $did($did).state
  if ($did == 117) dcxs_control_setStyle $1  borderselect $did($did).state
  if ($did == 124) dcxs_control_setStyle $1  showsel      $did($did).state
  if ($did == 127) dcxs_control_setStyle $1  editlabel    $did($did).state
  if ($did == 133) dcxs_control_setStyle $1  hottrack     $did($did).state
  if ($did == 134) dcxs_control_setStyle $1  tooltip      $did($did).state
  if ($did == 128) dcxs_control_setStyle $1  headerdrag   $did($did).state
  if ($did == 118) dcxs_control_setStyle $1  grid         $did($did).state
  if ($did == 119) dcxs_control_setStyle $1  fullrow      $did($did).state
  if ($did == 120) dcxs_control_setStyle $1  noheader     $did($did).state
  if ($did == 126) dcxs_control_setStyle $1  checkbox     $did($did).state
  if ($did == 131) dcxs_control_setStyle $1  subitemimage $did($did).state
  if ($did == 123) dcxs_control_setStyle $1  autoarrange  $did($did).state
  if ($did == 125) dcxs_control_setStyle $1  nolabelwrap  $did($did).state
  if ($did == 132) dcxs_control_setStyle $1  noscroll     $did($did).state

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_line {
  if ($did == 202) {
    var %w $cprop($1, w)
    var %h $cprop($1, h)

    cprop $1 w %h
    cprop $1 h %w

    dcxs_control_setStyle $1  vertical     $did($did).state
  }

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_radio {
  if ($did == 207) dcxs_control_setStyleXOR $1 $did

  if ($did == 208) dcxs_control_setStyle $1 pushlike $did($did).state

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_check {
  if ($did == 210) dcxs_control_setStyleXOR $1 $did

  if ($did == 211) dcxs_control_setStyle $1 pushlike $did($did).state
  if ($did == 212) dcxs_control_setStyle $1 3state $did($did).state

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_scroll {
  if ($did == 213) {
    var %w $cprop($1, w)
    var %h $cprop($1, h)

    cprop $1 w %h
    cprop $1 h %w

    dcxs_control_setStyle $1 vertical     $did($did).state
  }

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_list {
  if ($did == 214) dcxs_control_setStyle $1 noscroll $did($did).state
  if ($did == 215) dcxs_control_setStyle $1 extsel $did($did).state
  if ($did == 216) dcxs_control_setStyle $1 multi $did($did).state
  if ($did == 217) dcxs_control_setStyle $1 nointegral $did($did).state
  if ($did == 218) dcxs_control_setStyle $1 nosel $did($did).state

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_text {
  if ($did == 224) dcxs_control_setStyleXOR $1 $did

  if ($did == 219) dcxs_control_setStyle $1 nowrap $did($did).state
  if ($did == 220) dcxs_control_setStyle $1 noprefix $did($did).state
  if ($did == 221) dcxs_control_setStyle $1 endellipsis $did($did).state
  if ($did == 222) dcxs_control_setStyle $1 pathellipsis $did($did).state

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_edit {
  if ($did == 226) dcxs_control_setStyleXOR $1 $did

  if ($did == 228) {
    cprop $1 limit $int($did($did))
    xdid -q dcxprop $1 $int($did($did))
  }

  if ($did == 229) dcxs_control_setStyle $1 multi     $did($did).state
  if ($did == 230) dcxs_control_setStyle $1 autohs    $did($did).state
  if ($did == 231) dcxs_control_setStyle $1 hsbar     $did($did).state
  if ($did == 232) dcxs_control_setStyle $1 lowercase $did($did).state
  if ($did == 233) dcxs_control_setStyle $1 uppercase $did($did).state
  if ($did == 234) dcxs_control_setStyle $1 number    $did($did).state
  if ($did == 235) dcxs_control_setStyle $1 return    $did($did).state
  if ($did == 236) dcxs_control_setStyle $1 autovs    $did($did).state
  if ($did == 237) dcxs_control_setStyle $1 vsbar     $did($did).state
  if ($did == 238) dcxs_control_setStyle $1 password  $did($did).state
  if ($did == 239) dcxs_control_setStyle $1 readonly  $did($did).state

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_image {
  var %f

  ;// edit
  if ($did == 241)      %f = $did($did)
  ;// button
  else if ($did == 242) {
    %f = $openFile(*.bmp,*.jpg,*.jpeg,*.png,*.gif,*.exif,*.tiff,*.wmf,*.emf;Image Files)

    if (!%f) return

    did -ra dcxprop 241 %f
  }

  cprop $1 image %f

  if ($exists(%f)) {
    cprop $1 w $pic(%f).width
    cprop $1 h $pic(%f).height

    xdid -p dcxtest $1 $cprop($1, x) $cprop($1, y) $cprop($1, w) $cprop($1, h)
    dcxs_show_controlCoordinates $1
  }

  xdid -i dcxtest $1 $cprop($1, image)
  ;dcxs_control_recreate $1
}

alias -l dcxs_control_modify_colorcombo {
  if ($did == 243) cprop $1 mirccolors $did($did).state
}

alias -l dcxs_control_modify_webctrl {
  if ($did == 244) {
    cprop $1 defaultpage $did($did)
    .timerWebCtrl $+ $1 1 3 xdid -n dcxtest $1 $did($did)
  }
}

alias -l dcxs_control_modify_richedit {
  if ($did == 253) dcxs_control_setStyleXOR $1 $did

  if ($did == 249) {
    cprop $1 mIRCcolors $did($did).state
    return
  }

  if ($did == 246) dcxs_control_setStyle $1 multi  $did($did).state
  if ($did == 247) dcxs_control_setStyle $1 autohs $did($did).state
  if ($did == 248) dcxs_control_setStyle $1 autovs $did($did).state
  if ($did == 250) dcxs_control_setStyle $1 hsbar  $did($did).state
  if ($did == 251) dcxs_control_setStyle $1 vsbar  $did($did).state

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_link {
}

alias -l dcxs_control_modify_toolbar {
  if ($did == 152) dcxs_control_setStyleXOR $1 $did
  if ($did == 154) cprop $1 iconsize $did($did).text

  if ($did == 156) cprop $1 btnmin   $int($did($did))
  if ($did == 158) cprop $1 btnmax   $int($did($did))
  if ($did == 160) cprop $1 defaultw $int($did($did))
  if ($did == 254) cprop $1 defaulth $int($did($did))

  if ($did == 161) dcxs_control_setStyle $1 nodivide $did($did).state
  if ($did == 162) dcxs_control_setStyle $1 flat $did($did).state
  if ($did == 163) dcxs_control_setStyle $1 list $did($did).state
  if ($did == 164) dcxs_control_setStyle $1 transparent $did($did).state
  if ($did == 165) dcxs_control_setStyle $1 tooltips $did($did).state
  if ($did == 166) dcxs_control_setStyle $1 wrap $did($did).state
  if ($did == 167) dcxs_control_setStyle $1 arrows $did($did).state
  if ($did == 168) dcxs_control_setStyle $1 noauto $did($did).state

  ;autostretch
  if ($did == 255) cprop $1 autostretch $did($did).state

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_statusbar {
  if ($did == 177) dcxs_control_setStyleXOR $1 $did

  if ($did == 172) dcxs_control_setStyle $1 grip          $did($did).state
  if ($did == 173) dcxs_control_setStyle $1 tooltips      $did($did).state
  if ($did == 175) dcxs_control_setStyle $1 noresize      $did($did).state
  if ($did == 176) dcxs_control_setStyle $1 noparentalign $did($did).state

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_trackbar {
  if ($did == 187) dcxs_control_setStyleXOR $1 $did
  if ($did == 194) {
    cprop $1 toolpos $lower($did($did).seltext)
    xdid -t dcxtest $1 $cprop($1, toolpos)
    return
  }

  if ($did == 190) {
    cprop $1 ticfreq $int($did($did))
    xdid -n dcxtest $1 $cprop($1, ticfreq)
    return
  }
  if ($did == 196) {
    cprop $1 value $int($did($did))
    xdid -v dcxtest $1 $cprop($1, value)
    return
  }
  if ($did == 198) {
    cprop $1 pagestep $int($did($did))
    xdid -m dcxtest $1 $cprop($1, pagestep)
    return
  }
  if ($did == 200) {
    cprop $1 linestep $int($did($did))
    xdid -l dcxtest $1 $cprop($1, linestep)
    return
  }

  if ($did == 181) {
    var %w $cprop($1, w)
    var %h $cprop($1, h)

    cprop $1 w %h
    cprop $1 h %w

    dcxs_control_setStyle $1 vertical   $did($did).state
  }

  if ($did == 191) cprop $1 min $int($did($did))
  if ($did == 192) cprop $1 max $int($did($did))
  if ($did == 180) dcxs_control_setStyle $1 autoticks  $did($did).state
  if ($did == 182) dcxs_control_setStyle $1 nothumb    $did($did).state
  if ($did == 183) dcxs_control_setStyle $1 noticks    $did($did).state
  if ($did == 184) dcxs_control_setStyle $1 downisleft $did($did).state
  if ($did == 185) dcxs_control_setStyle $1 tooltips   $did($did).state

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_updown {
  if ($did == 257) {
    cprop $1 buddy $gettok($did($did).seltext, 1, 58)
    xdid -c dcxtest $1 $cprop($1, buddy)
    return
  }

  if ($did == 259) {
    dcxs_control_setStyle $1 base $did($did).seltext
    xdid -t dcxtest $1 $cprop($1, base)
    return
  }

  if ($did == 261) {
    cprop $1 value $int($did($did))
    xdid -v dcxtest $1 $cprop($1, value)
    return
  }

  if ($did == 263) cprop $1 min $int($did($did))
  if ($did == 264) cprop $1 max $int($did($did))


  if ($did == 265) dcxs_control_setStyle $1 left        $did($did).state
  if ($did == 266) dcxs_control_setStyle $1 arrowkeys   $did($did).state
  if ($did == 267) dcxs_control_setStyle $1 horz        $did($did).state
  if ($did == 268) dcxs_control_setStyle $1 hottrack    $did($did).state
  if ($did == 269) dcxs_control_setStyle $1 nothousands $did($did).state
  if ($did == 270) dcxs_control_setStyle $1 buddyint    $did($did).state
  if ($did == 271) dcxs_control_setStyle $1 wrap        $did($did).state

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_calendar {
  if ($did == 275) dcxs_control_setStyle $1 multi         $did($did).state
  if ($did == 276) dcxs_control_setStyle $1 weeknum       $did($did).state
  if ($did == 277) dcxs_control_setStyle $1 notoday       $did($did).state
  if ($did == 278) dcxs_control_setStyle $1 notodaycircle $did($did).state

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_datetime {
  /*
  if ($did == 275) dcxs_control_setStyle $1 multi         $did($did).state
  if ($did == 276) dcxs_control_setStyle $1 weeknum       $did($did).state
  if ($did == 277) dcxs_control_setStyle $1 notoday       $did($did).state
  if ($did == 278) dcxs_control_setStyle $1 notodaycircle $did($did).state

  dcxs_control_recreate $1
  */
}

alias -l dcxs_control_modify_tab {
  if ($did == 289) dcxs_control_setStyleXOR $1 $did

  if ($did == 292) cprop $1 btnw $int($did($did))
  if ($did == 293) cprop $1 btnh $int($did($did))

  if ($did == 279) dcxs_control_setStyle $1 vertical       $did($did).state
  if ($did == 280) dcxs_control_setStyle $1 fixedwidth     $did($did).state
  if ($did == 281) dcxs_control_setStyle $1 buttons        $did($did).state
  if ($did == 282) dcxs_control_setStyle $1 flat           $did($did).state
  if ($did == 283) dcxs_control_setStyle $1 hot            $did($did).state
  if ($did == 284) dcxs_control_setStyle $1 multiline      $did($did).state
  if ($did == 285) dcxs_control_setStyle $1 rightjustify   $did($did).state
  if ($did == 286) dcxs_control_setStyle $1 scrollopposite $did($did).state
  if ($did == 287) dcxs_control_setStyle $1 flatseps       $did($did).state

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_main {
  if ($did == 135) {
    cprop 0 name $did($did)
    return
  }

  if ($did == 305) dcxs_control_setFlags 0 style t $did($did).state
  if ($did == 306) dcxs_control_setFlags 0 style h $did($did).state
  if ($did == 307) dcxs_control_setFlags 0 style m $did($did).state
  if ($did == 308) dcxs_control_setFlags 0 style n $did($did).state
  if ($did == 309) dcxs_control_setFlags 0 style o $did($did).state
  if ($did == 310) dcxs_control_setFlags 0 style y $did($did).state
  if ($did == 311) dcxs_control_setFlags 0 style z $did($did).state
  if ($did == 312) dcxs_control_setFlags 0 style b $did($did).state
  if ($did == 313) dcxs_control_setFlags 0 style c $did($did).state
  if ($did == 314) dcxs_control_setFlags 0 style d $did($did).state
  if ($did == 315) dcxs_control_setFlags 0 style f $did($did).state
  if ($did == 316) dcxs_control_setFlags 0 style s $did($did).state
  if ($did == 317) dcxs_control_setFlags 0 style w $did($did).state

  xdialog -b dcxtest $cprop($1, style) $+ $iif(z !isin $cprop($1, style), z)
}

alias -l dcxs_control_modify_rebar {
  if ($did == 77 ) dcxs_control_setStyleXOR $1 $did

  if ($did == 79 ) dcxs_control_setStyle $1 borders       $did($did).state
  if ($did == 80 ) dcxs_control_setStyle $1 varheight     $did($did).state
  if ($did == 81 ) dcxs_control_setStyle $1 dblclktoggle  $did($did).state
  if ($did == 106) dcxs_control_setStyle $1 fixedorder    $did($did).state
  if ($did == 107) dcxs_control_setStyle $1 tooltips      $did($did).state
  if ($did == 109) dcxs_control_setStyle $1 verticalgrip  $did($did).state
  if ($did == 110) dcxs_control_setStyle $1 vertical      $did($did).state
  if ($did == 112) dcxs_control_setStyle $1 noparentalign $did($did).state
  if ($did == 111) {
    dcxs_control_setStyle $1 noresize      $did($did).state

    if ($did($did).state) {
      cprop $1 h 32
    }
  }

  dcxs_control_recreate $1
}

alias -l dcxs_control_modify_button {
  if ($did == 108) dcxs_control_setStyle $1 bitmap  $did($did).state
  if ($did == 113) dcxs_control_setStyle $1 default $did($did).state

  dcxs_control_recreate $1
}


alias -l dcxs_control_modify_ipaddress {

}

alias -l dcxs_control_modify_window {
  if ($did == 295) cprop $1 style $did($did)
}

alias -l dcxs_control_modify_dialog {
  if ($did == 297) cprop $1 style $did($did)
}



;[ functions to load the values of current control config ]---------------------
; $1 = id
; $2-= styles
alias -l dcxs_control_loadStyle_box {
  dcxs_select_controlStyle $1 204

  did $iif(squared isin $2-, -c, -u) dcxprop 201
  did $iif(bottom  isin $2-, -c, -u) dcxprop 205
}


alias -l dcxs_control_loadStyle_pbar {
  did -ra dcxprop 89 $cprop($1, value)
  did -ra dcxprop 90 $cprop($1, min)
  did -ra dcxprop 91 $cprop($1, max)

  did $iif(smooth   isin $2-, -c, -u) dcxprop 85
  did $iif(vertical isin $2-, -c, -u) dcxprop 86
  did $iif(marquee  isin $2-, -c, -u) dcxprop 87
}

alias -l dcxs_control_loadStyle_comboex {
  dcxs_select_controlStyle $1 179

  ;  if      (simple   isin $2-) did -c dcxprop 179 1
  ;  else if (dropdown isin $2-) did -c dcxprop 179 2
  ;  else if (dropedit isin $2-) did -c dcxprop 179 3
}

alias -l dcxs_control_loadStyle_treeview {
  ;did -c dcxprop 114 $findtok($didtok(dcxprop, 114, 44), $cprop($1, iconsize), 1, 44)
  dcxs_select_controlStyle $1 114 iconsize

  did $iif(haslines     isin $2-, -c, -u) dcxprop 94
  did $iif(hasbuttons   isin $2-, -c, -u) dcxprop 95
  did $iif(editlabel    isin $2-, -c, -u) dcxprop 96
  did $iif(noscroll     isin $2-, -c, -u) dcxprop 97
  did $iif(showsel      isin $2-, -c, -u) dcxprop 98
  did $iif(singleexpand isin $2-, -c, -u) dcxprop 99
  did $iif(linesatroot  isin $2-, -c, -u) dcxprop 100
  did $iif(checkbox     isin $2-, -c, -u) dcxprop 101
  did $iif(nohscroll    isin $2-, -c, -u) dcxprop 102
  did $iif(notooltips   isin $2-, -c, -u) dcxprop 103
  did $iif(fullrow      isin $2-, -c, -u) dcxprop 104

  ;107 sorting method
}


alias -l dcxs_control_loadStyle_listview {
  dcxs_select_controlStyle $1 88
  dcxs_select_controlStyle $1 122

  ;138 sorting method

  ;135 Sort ascending
  ;136 Sort decending

  ;140 bg image
  ;141 Tiled

  did $iif(haslines     isin $2-, -c, -u) dcxprop 94
  did $iif(singlesel    isin $2-, -c, -u) dcxprop 105
  did $iif(flatsb       isin $2-, -c, -u) dcxprop 116
  did $iif(borderselect isin $2-, -c, -u) dcxprop 117
  did $iif(showsel      isin $2-, -c, -u) dcxprop 124
  did $iif(editlabel    isin $2-, -c, -u) dcxprop 127
  did $iif(hottrack     isin $2-, -c, -u) dcxprop 133
  did $iif(tooltip      isin $2-, -c, -u) dcxprop 134
  did $iif(headerdrag   isin $2-, -c, -u) dcxprop 128
  did $iif(grid         isin $2-, -c, -u) dcxprop 118
  did $iif(fullrow      isin $2-, -c, -u) dcxprop 119
  did $iif(noheader     isin $2-, -c, -u) dcxprop 120
  did $iif(checkbox     isin $2-, -c, -u) dcxprop 126
  did $iif(subitemimage isin $2-, -c, -u) dcxprop 131
  did $iif(autoarrange  isin $2-, -c, -u) dcxprop 123
  did $iif(nolabelwrap  isin $2-, -c, -u) dcxprop 125
  did $iif(noscroll     isin $2-, -c, -u) dcxprop 132
}


alias -l dcxs_control_loadStyle_line {
  did $iif(vertical     isin $2-, -c, -u) dcxprop 202
}

alias -l dcxs_control_loadStyle_radio {
  dcxs_select_controlStyle $1 207

  did $iif(pushlike     isin $2-, -c, -u) dcxprop 208
}

alias -l dcxs_control_loadStyle_check {
  dcxs_select_controlStyle $1 210

  did $iif(pushlike     isin $2-, -c, -u) dcxprop  211
  did $iif(3state       isin $2-, -c, -u) dcxprop  212
}

alias -l dcxs_control_loadStyle_scroll {
  did $iif(vertical     isin $2-, -c, -u) dcxprop 213
}

alias -l dcxs_control_loadStyle_list {
  did $iif(noscroll   isin $2-, -c, -u) dcxprop 214
  did $iif(extsel     isin $2-, -c, -u) dcxprop 215
  did $iif(multi      isin $2-, -c, -u) dcxprop 216
  did $iif(nointegral isin $2-, -c, -u) dcxprop 217
  did $iif(nosel      isin $2-, -c, -u) dcxprop 218
}

alias -l dcxs_control_loadStyle_text {
  dcxs_select_controlStyle $1 224

  did $iif(nowrap       isin $2-, -c, -u) dcxprop 219
  did $iif(noprefix     isin $2-, -c, -u) dcxprop 220
  did $iif(endellipsis  isin $2-, -c, -u) dcxprop 221
  did $iif(pathellipsis isin $2-, -c, -u) dcxprop 222
}

alias -l dcxs_control_loadStyle_edit {
  dcxs_select_controlStyle $1 226

  ;// character limit
  did -ra dcxprop 228 $cprop($1, limit)

  did $iif(multi     isin $2-, -c, -u) dcxprop  229
  did $iif(autohs    isin $2-, -c, -u) dcxprop  230
  did $iif(hsbar     isin $2-, -c, -u) dcxprop  231
  did $iif(lowercase isin $2-, -c, -u) dcxprop  232
  did $iif(uppercase isin $2-, -c, -u) dcxprop  233
  did $iif(number    isin $2-, -c, -u) dcxprop  234
  did $iif(return    isin $2-, -c, -u) dcxprop  235
  did $iif(autovs    isin $2-, -c, -u) dcxprop  236
  did $iif(vsbar     isin $2-, -c, -u) dcxprop  237
  did $iif(password  isin $2-, -c, -u) dcxprop  238
  did $iif(readonly  isin $2-, -c, -u) dcxprop  239
}

alias -l dcxs_control_loadStyle_image {
  did -ra dcxprop 241 $cprop($1, image)
}

alias -l dcxs_control_loadStyle_colorcombo {
  did $iif($cprop($1, mirccolors), -c, -u) dcxprop 243
}

alias -l dcxs_control_loadStyle_webctrl {
  did -ra dcxprop 244 $cprop($1, defaultpage)
}

alias -l dcxs_control_loadStyle_richedit {
  dcxs_select_controlStyle $1 253

  did $iif(multi  isin $2-, -c, -u) dcxprop  246
  did $iif(autohs isin $2-, -c, -u) dcxprop  247
  did $iif(autovs isin $2-, -c, -u) dcxprop  248
  did $iif(hsbar  isin $2-, -c, -u) dcxprop  250
  did $iif(vsbar  isin $2-, -c, -u) dcxprop  251

  did $iif($cprop($1, mIRCcolors), -c, -u) dcxprop 249
}

alias -l dcxs_control_loadStyle_link {
}

alias -l dcxs_control_loadStyle_toolbar {
  dcxs_select_controlStyle $1 152
  dcxs_select_controlStyle $1 154 iconsize

  did -ra dcxprop 156 $cprop($1, btnmin)
  did -ra dcxprop 158 $cprop($1, btnmax)
  did -ra dcxprop 160 $cprop($1, defaultw)
  did -ra dcxprop 254 $cprop($1, defaulth)

  did $iif(nodivider   isin $2-, -c, -u) dcxprop 161
  did $iif(flat        isin $2-, -c, -u) dcxprop 162
  did $iif(list        isin $2-, -c, -u) dcxprop 163
  did $iif(transparent isin $2-, -c, -u) dcxprop 164
  did $iif(tooltips    isin $2-, -c, -u) dcxprop 165
  did $iif(wrap        isin $2-, -c, -u) dcxprop 166
  did $iif(arrows      isin $2-, -c, -u) dcxprop 167
  did $iif(noauto      isin $2-, -c, -u) dcxprop 168
  did $iif($cprop($1, autostretch), -c, -u) dcxprop 255
}

alias -l dcxs_control_loadStyle_statusbar {
  dcxs_select_controlStyle $1 177

  did $iif(grip          isin $2-, -c, -u) dcxprop 172
  did $iif(tooltips      isin $2-, -c, -u) dcxprop 173
  did $iif(noresize      isin $2-, -c, -u) dcxprop 175
  did $iif(noparentalign isin $2-, -c, -u) dcxprop 176
}

alias -l dcxs_control_loadStyle_trackbar {
  dcxs_select_controlStyle $1 187
  dcxs_select_controlStyle $1 194 toolpos

  did -ra dcxprop 190 $cprop($1, ticfreq)
  did -ra dcxprop 196 $cprop($1, value)
  did -ra dcxprop 191 $cprop($1, min)
  did -ra dcxprop 192 $cprop($1, max)
  did -ra dcxprop 198 $cprop($1, pagestep)
  did -ra dcxprop 200 $cprop($1, linestep)

  did $iif(autoticks  isin $2-, -c, -u) dcxprop 180
  did $iif(vertical   isin $2-, -c, -u) dcxprop 181
  did $iif(nothumb    isin $2-, -c, -u) dcxprop 182
  did $iif(noticks    isin $2-, -c, -u) dcxprop 183
  did $iif(downisleft isin $2-, -c, -u) dcxprop 184
  did $iif(tooltips   isin $2-, -c, -u) dcxprop 185
}

alias -l dcxs_control_loadStyle_updown {
  ;// custom code to load buddy control $cprop($1, buddy)
  var %i 1
  did -r dcxprop 257

  while ($did(dcxprop, 32, %i)) {
    var %t $ifmatch

    if ($regex(%t, (\d+): (.+) )) {
      if (($regml(2) == Text) || ($regml(2) == Edit)) {
        did -a $+ $iif($regml(1) == $cprop($1, buddy), c) dcxprop 257 %t
      }
    }

    inc %i
  }

  dcxs_select_controlStyle $1 259 base

  did -ra dcxprop 261 $cprop($1, value)
  did -ra dcxprop 263 $cprop($1, min)
  did -ra dcxprop 264 $cprop($1, max)

  did $iif(left        isin $2-, -c, -u) dcxprop 265
  did $iif(arrowkeys   isin $2-, -c, -u) dcxprop 266
  did $iif(horz        isin $2-, -c, -u) dcxprop 267
  did $iif(hottrack    isin $2-, -c, -u) dcxprop 268
  did $iif(nothousands isin $2-, -c, -u) dcxprop 269
  did $iif(buddyint    isin $2-, -c, -u) dcxprop 270
  did $iif(wrap        isin $2-, -c, -u) dcxprop 271
}

alias -l dcxs_control_loadStyle_ipaddress {

}

alias -l dcxs_control_loadStyle_calendar {
  did $iif(multi         isin $2-, -c, -u) dcxprop 275
  did $iif(weeknum       isin $2-, -c, -u) dcxprop 276
  did $iif($findtok($2-, notoday, 1, 32)      , -c, -u) dcxprop 277
  did $iif($findtok($2-, notodaycircle, 1, 32), -c, -u) dcxprop 278
}

alias -l dcxs_control_loadStyle_datetime {
  /*
  did $iif(multi         isin $2-, -c, -u) dcxprop 275
  did $iif(weeknum       isin $2-, -c, -u) dcxprop 276
  did $iif($findtok($2-, notoday, 1, 32)      , -c, -u) dcxprop 277
  did $iif($findtok($2-, notodaycircle, 1, 32), -c, -u) dcxprop 278
  */
}


alias -l dcxs_control_loadStyle_tab {
  dcxs_select_controlStyle $1 289

  did -ra dcxprop 292 $cprop($1, btnw)
  did -ra dcxprop 293 $cprop($1, btnh)

  did $iif(vertical       isin $2-, -c, -u) dcxprop 279
  did $iif(fixedwidth     isin $2-, -c, -u) dcxprop 280
  did $iif(buttons        isin $2-, -c, -u) dcxprop 281
  did $iif($findtok($2-, flat, 1, 32)    , -c, -u) dcxprop 282
  did $iif(hot            isin $2-, -c, -u) dcxprop 283
  did $iif(multiline      isin $2-, -c, -u) dcxprop 284
  did $iif(rightjustify   isin $2-, -c, -u) dcxprop 285
  did $iif(scrollopposite isin $2-, -c, -u) dcxprop 286
  did $iif($findtok($2-, flatseps, 1, 32), -c, -u) dcxprop 287
}

alias -l dcxs_control_loadStyle_panel {
  ;// clear & disable
  did -rb dcxprop 299

  ;// this is 2 because we skip 0: Main
  var %i 2

  ;// loop thru all id's for controls
  while ($did(dcxprop, 32, %i)) {
    var %t  $ifmatch
    var %id $gettok(%t, 1, 58)
    var %c  0

    ;// check if it has a parent with the same id as this
    if ($xdid(dcxtest, %id).pid == $1) {
      did -a $+ $iif(!%c, c) dcxprop 299 %id $+ : $cname($cprop(%id, type))
      inc %c
    }

    inc %i
  }

  ;// if there are items, enable
  if ($did(dcxprop, 299).lines) {
    did -e dcxprop 299
  }
}

alias -l dcxs_control_loadStyle_main {
  did $iif(t isin $2-, -c, -u) dcxprop 305
  did $iif(h isin $2-, -c, -u) dcxprop 306
  did $iif(m isin $2-, -c, -u) dcxprop 307
  did $iif(n isin $2-, -c, -u) dcxprop 308
  did $iif(o isin $2-, -c, -u) dcxprop 309
  did $iif(y isin $2-, -c, -u) dcxprop 310
  did $iif(z isin $2-, -c, -u) dcxprop 311
  did $iif(b isin $2-, -c, -u) dcxprop 312
  did $iif(c isin $2-, -c, -u) dcxprop 313
  did $iif(d isin $2-, -c, -u) dcxprop 314
  did $iif(f isin $2-, -c, -u) dcxprop 315
  did $iif(s isin $2-, -c, -u) dcxprop 316
  did $iif(w isin $2-, -c, -u) dcxprop 317

  did -ra dcxprop 135 $cprop(0, name)
}

alias -l dcxs_control_loadStyle_rebar {
  dcxs_select_controlStyle $1 77

  did $iif(borders isin $2-, -c, -u) dcxprop 79
  did $iif(varheight     isin $2-, -c, -u) dcxprop 80
  did $iif(dblclktoggle  isin $2-, -c, -u) dcxprop 81
  did $iif(fixedorder    isin $2-, -c, -u) dcxprop 106
  did $iif(tooltips      isin $2-, -c, -u) dcxprop 107
  did $iif(verticalgrip  isin $2-, -c, -u) dcxprop 109
  did $iif(vertical      isin $2-, -c, -u) dcxprop 110
  did $iif(noresize      isin $2-, -c, -u) dcxprop 111
  did $iif(noparentalign isin $2-, -c, -u) dcxprop 112
}

alias -l dcxs_control_loadStyle_button {
  did $iif(bitmap  isin $2-, -c, -u) dcxprop 108
  did $iif(default isin $2-, -c, -u) dcxprop 113
}

alias -l dcxs_control_loadStyle_window {
  did -ra dcxprop 295 $2-
}

alias -l dcxs_control_loadStyle_dialog {
  did -ra dcxprop 297 $2-
}



;###############################################################
; general functions related to the saving and opening of dcxstudio scripts/projects
alias -l dcxs_script_save {
  ;// wrap for spaces in filenames
  var %f $qt($$saveFile(*.dcxs, Please Select a File to Save To))
  var %i 1

  if ($exists(%f)) {
    if (!$question(Are you sure you wish to replace this file? $+ $crlf $+ %f)) {
      return
    }
  }

  dcxs_prog -t save $hfind(dcxs.proj, control.*, 0, w)

  if ($hget(save)) hfree save
  hmake save

  while ($hfind(dcxs.proj, control.*, %i, w)) {
    var %h $ifmatch
    hadd save %h $hget(dcxs.proj, %h)

    ;// update progress bar on main dialog
    dcxs_prog save %i

    inc %i
  }

  ;// add a tag to store version of dcx studio
  hadd save dcxs.version $v

  hsave -bo save %f
  hfree save
  s Project saved to file: %f
}

alias -l dcxs_script_open {
  var %f $qt($$openFile(*.dcxs))

  if (!$dcxs_delete_allControls) {
    return
  }

  ; since dcxs_delete_allControls uses a timer to clear stuff, we use a timer
  ; to load afterwards to prevent our newly loaded settings to be wiped
  $iif($temp(deleteAll), temp afterDelete) dcxs_script_loadProject %f
}

;// load an existing project file into dcxstudio
; $1- = quoted filename
alias -l dcxs_script_loadProject {
  var %t1 $ticks

  ;// clear current project
  hdel -w dcxs.proj control.*

  if ($hget(load)) hfree load

  hmake load
  hload -b load $1-

  var %i 1
  var %ids

  idlist -r

  ;// check for older version format and convert
  if ($hget(load, dcxs.version) < $v) {
    w File $nopath($1-) saved in v $+ $ifmatch of DCX Studio. It MAY have some compatibility issues.
  }


  dcxs_prog -t load $hfind(load, control.*, 0, w)

  ;// copy settings from #load over into #dcxs and make a list of id's
  while ($hfind(load, control.*, %i, w)) {
    var %h $ifmatch

    idlist -a $gettok(%h, 2, 46)
    hadd dcxs.proj %h $hget(load, %h)

    dcxs_prog load %i
    inc %i
  }

  dcxs_control_recreateAll

  ;// cleanup
  s Opened DCXS project: $nopath($1-) (v $+ $hget(load, dcxs.version) $+ ) in $calc(($ticks - %t1) / 1000) $+ ms
  hfree load
  dcxs_show_controlDetails 0
}


alias -l obrace {
  set %increment.next $true
  return $chr(123)
}
alias -l cbrace {
  dec %indent
  return $chr(125)
}

;// write comments
; $1 == +d || +c (dcxs/control comments)
alias -l gencomment {
  ;// show comments?
  if (!$pref(genscript.showcomments)) {
    return
  }

  ;// show dcx studio comments
  if (!$pref(genscript.dcxcomments) && ($1 == +d)) {
    return
  }

  ;// show control comments
  if (!$pref(genscript.ctrlcomments) && ($1 == +c)) {
    return
  }

  genscript ;// $2-
}

alias -l genscript {
  var %space = $str($chr(32), $calc(%indent * 2))

  noop $dcx(xdid, dcxgen, 2, -a, $iif($xdid(dcxgen, 2, 1).text, $crlf) $+ %space $+ $1-)

  if (%increment.next) {
    inc %indent
    unset %increment.next
  }
}


;// generates a script and returns it if successful
; $1 = dialog name
alias -l dcxs_script_generate {
  ;// name of the dialog, halts if null
  var %dname         $iif($1, $ifmatch, $?="enter a dialog name")

  if (!%dname) {
    e No dialog name specified
    return
  }

  var %i             1
  var %ticks         $ticks

  ;// init indentation level
  set %indent 0

  ;// if the dialog is alerady open, close it
  if ($dialog(dcxgen)) {
    dialog -x dcxgen
  }

  ;// create gen dialog
  dialog -ma dcxgen dcxs_generator_table


  ;// write the calling function
  s Writing dialog table...
  genscript alias %dname $obrace
  genscript dialog -ma %dname %dname $+ _table
  genscript $cbrace
  genscript

  ;// setup the table
  genscript dialog %dname $+ _table $obrace
  genscript title $+(", $cprop(0, caption), ")
  genscript size -1 -1 $cprop(0, w) $cprop(0, h)

  ;// write icon for dialog if exists
  if ($cprop(0, icon)) {
    genscript icon $ifmatch
  }

  ;genscript option dbu
  genscript $cbrace
  genscript


  ;// get all control id's
  s Gathering required control ID's...
  idlist -r
  dcxs_prog -t gen $hfind(dcxs.proj, control.*, 0, w)

  while ($hfind(dcxs.proj, control.*, %i, w)) {
    idlist -a $gettok($ifmatch, 2, 46)
    inc %i
    dcxs_prog gen %i
  }

  ;// remove id 0, already done
  idlist -d 0

  ;// initialisation scripts
  d Writing EVENT scripts...
  genscript on *:dialog: $+ %dname $+ :*:*: $obrace
  genscript  if ($devent == init) $obrace
  genscript    dcx Mark $!dname %dname $+ _cb
  genscript    xdialog -b $!dname $cprop(0, style)
  genscript

  ;// add check for init call here or elsewhere
  if ($pref(control.init) == alias) {
    gencomment +d Call initilisation alias
    genscript %dname $+ _init_dcx
  }
  else {
    dcxs_script_generateControls
  }

  genscript $cbrace
  genscript $cbrace
  genscript

  ;// if alias here
  if ($pref(control.init) == alias) {
    genscript alias -l %dname $+ _init_dcx $obrace
    dcxs_script_generateControls
    genscript $cbrace
    genscript
  }

  ;// generate callback function
  gencomment +d Callback alias for %dname
  genscript alias %dname $+ _cb $obrace

  if ($pref(genscript.callbackcode)) {
    genscript if ($2 != mouse) $obrace
    genscript echo $!color(info) -s */ %dname $+ _cb: $!1-
    genscript $cbrace
  }

  genscript $cbrace
  genscript

  ;// add a menu item to access it easily
  if ($pref(genscript.menuitem)) {
    gencomment +d quick-access menu item
    genscript menu status,channel $obrace
    genscript %dname : %dname
    genscript $cbrace
  }

  s Script generated in $calc(($ticks - %ticks) / 1000) $+ s

  ;// cleanup
  :cleanup
  unset %indent

  ;// enable the save, done, demo buttons, copy all
  xdid -e dcxgen 3
  xdid -e dcxgen 4
  ;xdid -e dcxgen 5
  xdid -e dcxgen 6

  ;// set the command of @dcxstudio to call the new dialog when ready
  editbox @dcxstudio / $+ %dname
}


;// loop to go through all possible controls, and check if its been generated or not
alias -l dcxs_script_generateControls {
  s Writing initialisation scripts.

  var %t = $idlist(0)
  var %i 1
  var %reset

  c Found %t control $+ $iif((%t > 1) || (%t == 0), s) $+ .
  dcxs_prog -t gen %t


  ;// loop until all controls have been created
  while (%t) {
    var %id = $idlist(%i)

    ;// if null, ignore for now
    if (%id == $null) {
      d /dcxs_script_generateCode: null
      %reset = $true
    }
    ;// control exists, remove id from ids
    else if ($didwm(dcxgen, 7, %id)) {
      d /dcxs_script_generateCode: Control already generated > %id > $cprop(%id, pid)

      idlist -d %id
      did -a dcxgen 7 %id
      %reset = $true
    }
    else if (($cprop(%id, pid) == 0) || ($didwm(dcxgen, 7, $cprop(%id, pid)))) {
      dcxs_script_generateControl %id

      idlist -d %id
      did -a dcxgen 7 %id
      %reset = $true
    }
    else {
      ;w dcxs_control_recreateAll: cannot create control yet %id > $cprop(%id, pid)
    }

    inc %i
    %t = $idlist(0)
    dcxs_prog gen $did(dcxgen, 7).lines

    ;// reset the counter
    if (%i > %t) {
      if (%reset == $true) {
        %i = 1
        %reset = $false
      }
      else {
        e /dcxs_script_generateControls: Possible infinite loop, processing halted
        msgbox Possible infinite loop detected. Script generation process aborted.
        halt
      }
    }
  }
}


;// 'create' the control via genscript
; $1 = id
alias -l dcxs_script_generateControl {
  whileFix

  var %t $cprop($1, type)
  var %pt $cprop($1, ptype)

  gencomment +c Initialising control: $strip($cprop($1, caption)) ( $+ $iif((%pt == tab) || (%pt == rebar), $cname(%pt) Item, $cname(%t)) # $+ $1 $+ )

  var %c

  ;// create the child control
  if ($cprop($1, pid)) {
    var %p  $cprop($1, pid)

    ;// if tab or rebar, add to owner
    if (%pt == tab) {
      %c = xdid -a $!dname %p 0 0 $cprop($1, caption) $!chr(9) $1 %t $cprop($1, x) $cprop($1, y) $cprop($1, w) $cprop($1, h) $cprop($1, style)
    }
    else if (%pt == rebar) {
      %c = xdid -a $!dname %p 0 +ge 0 $cprop($1, h) 220 0 0 Rebar $!chr(9) $1 %t $cprop($1, x) $cprop($1, y) $cprop($1, w) $cprop($1, h) $cprop($1, style) $!chr(9) Tooltip
    }
    ;// normal contrl
    else {
      %c = xdid -c $!dname %p $1 %t $cprop($1, x) $cprop($1, y) $cprop($1, w) $cprop($1, h) $cprop($1, style)
    }
  }
  ;// create the control
  else {
    %c = xdialog -c $!dname $1 %t $cprop($1, x) $cprop($1, y) $cprop($1, w) $cprop($1, h) $cprop($1, style)
  }

  genscript %c
  dcxs_script_generateCode $1 %t
  genscript

  idlist -d $1
  did -a dcxgen 7 $1
  dcxs_prog gen $did(dcxgen, 7).lines

  ;// recursive if has children
  if ($hasChildren($1)) {
    var %i 1
    var %c $getChildren($1)

    while ($gettok(%c, %i, 32)) {
      var %id $ifmatch

      recursive dcxs_script_generateControl %id
      inc %i
    }
  }
}



;// writes the genscript control initialisation
; $1 = id
; $2 = control type
alias -l dcxs_script_generateCode {
  ;// depending on what type of control, initialise it
  if ($2 == pbar) {
    if (($cprop($1, min) != $null) && ($cprop($1, max) != $null)) {
      genscript xdid -r $!dname $1 $cprop($1, min) $cprop($1, max)
    }

    genscript xdid -v $!dname $1 $cprop($1, value)
    genscript xdid -i $!dname $1 $replace($replace($cprop($1, caption), % $+ %, % $!+ %), % $+ d, % $!+ d)
  }
  if ($2 == treeview) {
    genscript xdid -l $!dname $1 $cprop($1, iconsize)
  }
  if ($2 == listview) {
    ;genscript ;xdid -t $!dname $1 + 1 150 $+(Column 1, $!chr(9), + 0 150 Column 2, $!chr(9), + 0 140 Column 3)
    ;genscript xdid -a $!dname $1 0 0 +t 2 0 0 0 0 0 $+(Select Listvew, $!chr(9), +  0 Text2, $!chr(9), + 0 Text3)
    return
  }
  if ($2 == toolbar) {
    genscript xdid -l $!dname $1 $cprop($1, iconsize)
    genscript xdid -m $!dname $1 $cprop($1, autostretch)

    if (($cprop($1, btnmin) != $null) && ($cprop($1, btnmax) != $null)) {
      genscript xdid -j $!dname $1 $cprop($1, btnmin) $cprop($1, btnmax)
    }
    if ($cprop($1, defaultw) && $cprop($1, defaulth)) {
      genscript xdid -u $!dname $1 $cprop($1, defaultw) $cprop($1, defaulth)
    }
  }
  if ($2 == statusbar) {
    ;genscript ;xdid -l $!dname $1 100 300 -1
    return
  }
  if ($2 == ComboEx) {
    return
  }
  if ($2 == trackbar) {
    if ($cprop($1, toolpos))  genscript xdid -t $!dname $1 $ifmatch
    if ($cprop($1, ticfreq))  genscript xdid -n $!dname $1 $ifmatch
    if ($cprop($1, value))    genscript xdid -v $!dname $1 $ifmatch
    if ($cprop($1, pagestep)) genscript xdid -m $!dname $1 $ifmatch
    if ($cprop($1, linestep)) genscript xdid -l $!dname $1 $ifmatch

    if ($cprop($1, min) != $null && $cprop($1, max) != $null) {
      genscript xdid -r $!dname $1 $cprop($1, min) $cprop($1, max)
    }
  }
  if ($2 == rebar) {
    t rebar management stuff incomplete
    return
  }
  if ($2 == richedit) {
    if ($cprop($1, mIRCcolors)) genscript xdid -m $!dname 1

    genscript xdid -a $!dname $1 $cprop($1, caption)
  }
  if ($2 == colorcombo) {
    xdid -m $!dname $1
    xdid -c $!dname $1 1

    cprop $1 mirccolors 0
  }
  if ($2 == button) {
    genscript xdid -t $!dname $1 $cprop($1, caption)
  }
  if ($2 == ipaddress) {
    genscript xdid -a $!dname $1 $cprop($1, caption)
  }
  if ($2 == UpDown) {
    if ($cprop($1, buddy)) {
      genscript xdid -c $!dname $1 $ifmatch
    }

    ;// min/max
    if (($cprop($1, min) != $null) && ($cprop($1, max) != $null)) {
      genscript xdid -r $!dname $1 $cprop($1, min) $cprop($1, max)
    }

    genscript xdid -t $!dname $1 $cprop($1, base)
    genscript xdid -v $!dname $1 $cprop($1, value)
  }
  if ($2 == webctrl) {
    if ($cprop($1, defaultpage)) {
      genscript xdid -n $!dname $1 $ifmatch
    }
  }
  if ($2 == Calendar) {
    gencomment +c finish the calendar control
    return
  }

  if ($2 == DateTime) {
    gencomment +c finish the datetime control
    return
  }

  if ($2 == line) {
    return
  }
  if ($2 == box) {
    genscript xdid -t $!dname $1 $cprop($1, caption)
    genscript xdid -l $!dname $1 root $!chr(9) +pl 0 1 0 0
    ;genscript .timer 1 0 xdid -l $!dname $1 update
  }
  if ($2 == radio) {
    genscript xdid -t $!dname $1 $cprop($1, caption)
  }
  if ($2 == Check) {
    genscript xdid -t $!dname $1 $cprop($1, caption)
  }
  if ($2 == edit) {
    if ($cprop($1, limit)) {
      genscript xdid -q $!dname $1 $ifmatch
    }

    genscript xdid -a $!dname $1 $cprop($1, caption)
  }
  if ($2 == Scroll) {
    return
  }
  if ($2 == Image) {
    genscript xdid -i $!dname $1 $cprop($1, image)
  }
  if ($2 == list) {
    return
  }
  if ($2 == link) {
    genscript xdid -t $!dname $1 $cprop($1, caption)
  }
  if ($2 == text) {
    genscript xdid -t $!dname $1 $cprop($1, caption)
  }
  if ($2 == Divider) {
    return
  }
  if ($2 == panel) {
    ;xdid -x $!dname $1 +s
    return
  }
  if ($2 == tab) {
    if (($cprop($1, btnw) != $null) && ($cprop($1, btnh) != $null)) {
      genscript xdid -m $!dname $1 $cprop($1, btnw) $cprop($1, btnh)
    }

    t tabgen stuff called from main genscript function to handle id's
  }
  if ($2 == window) {
    return
  }
  if ($2 == dialog) {
    return
  }
}











;###############################################################
; convert between mIRC table and DCX
alias dcxsimport_cb {
}

dialog dcxs_import_table {
  title "Import mIRC Table"
  size -1 -1 133 31
  option dbu
  combo 1, 4 4 125 100, result sort drop
  button "Cancel", 2, 93 17 35 10, cancel
  button "&Import", 3, 55 17 35 10, default ok
}


on *:dialog:dcxs_import:*:*: {
  if ($devent == init) {
    dcx Mark $dname dcxsimport_cb
    xdialog -b $dname +oty

    ;// load table names into the dropdown
    var %i 1

    while ($gettok($hget(dcxs.convert, tables), %i, 32)) {
      did -a $dname 1 $gettok($ifmatch, 2, 44)
      inc %i
    }

    did -c $dname 1 1
  }
}


alias dcxs_script_importStoreTableNames {
  ;// store lineNumber,TableName
  tokenize 32 $1-
  hadd dcxs.convert tables $addtok($hget(dcxs.convert, tables), $+($1, $chr(44), $iif($3 == -l, $4, $3)), 32)
}

;// convert a table into dcx
alias -l dcxs_script_convert {
  var %f $qt($$openFile(*.mrc, Select a Script File to Import))

  if (!$exists(%f)) {
    msgbox $+(Cannot open file., $crlf, %f)
    return
  }

  if (!$dcxs_delete_allControls) {
    return
  }

  $iif($temp(deleteAll), temp afterDelete) dcxs_script_import %f
}


alias -l dcxs_script_import {
  var %f $1-

  if ($hget(dcxs.convert)) hfree dcxs.convert
  hmake dcxs.convert

  ;// load up the list of possible table names from the mirc file
  filter -nk %f dcxs_script_importStoreTableNames dialog * $chr(123)

  if (!$filtered) {
    msgbox There seems to be no dialog tables in this file.
    goto cleanup
  }

  var %tbl

  ;// show a dialog to select which table to select
  if ($numtok($hget(dcxs.convert, tables), 32) > 1) {
    %tbl = $dialog(dcxs_import, dcxs_import_table, -4)
  }
  else {
    c Only one table in $qt($nopath(%f)) to import.
    %tbl = $gettok($hget(dcxs.convert, tables), 2, 44)
  }


  if (!%tbl) goto cleanup

  var %t1 $ticks

  ;// cleanup old project
  hdel -w dcxs.proj control.*

  ;// get the line where the table starts from
  var %tbl.start = $gettok($wildtok($hget(dcxs.convert, tables), $+(*, $chr(44), %tbl), 1, 32), 1, 44)

  ;// scan the file to find where the table resource ends
  var %tbl.end   = $read(%f, snp, $chr(125), %tbl.start)
  %tbl.end = $readn

  var %range $+($calc(%tbl.start +1), -, $calc(%tbl.end -1))

  ;// import each statement
  c Reading table( $+ %tbl $+ ) in $nopath(%f) between lines %range
  cprop 0 name  %tbl
  cprop 0 type  main
  cprop 0 style +nty

  ;// set the progress bar value
  dcxs_prog -t convert $abs($calc(%range))
  set %import.counter 1

  filter -kr %range %f dcxs_script_convertControl *
  unset %import.counter

  ;// convert DBU -> pixels
  if (dbu isin $hget(dcxs.convert, option)) {
    dcxs_script_import_convertDBU
  }


  ;// fix the tab item #1 bug
  if ($hget(dcxs.convert, fix.tabid)) {
    dcxs_script_import_fixTabItems $ifmatch
  }

  ;// add controls to boxes rather than hide under
  dcxs_script_import_fixBoxes


  var %i 1

  idlist -r
  dcxs_prog -t import $hfind(dcxs.proj, control.*.type, 0, w)

  ;// make a list of id's
  while ($hfind(dcxs.proj, control.*.type, %i, w)) {
    var %h $ifmatch

    ;// add it to the list to be recreated
    idlist -a $gettok(%h, 2, 46)

    dcxs_prog import %i
    inc %i
  }

  dcxs_control_recreateAll

  s Imported %tbl in $calc(($ticks - %t1) / 1000) $+ ms

  ;// cleanup
  :cleanup
  hfree dcxs.convert
}


;// formats and stores the data into the hash table
; $1-= input directly from the mIRC table format
alias -l dcxs_script_convertControl {
  tokenize 32 $1-

  dcxs_prog convert %import.counter
  inc %import.counter


  if (;* iswm $1) {
    c /dcxs_script_convertControl: Commented line, ignoring > $1-
    return
  }
  ;// options for menus - NOT SUPPORTED (yet? maybe in some later time)
  else if (($1 == menu) || ($1 == item)) {
    w /dcxs_script_convertControl: Conversion of menu/items is not supported.
    return
  }
  ;// these are options for the main window
  else if ($1 == title) {
    ;title "DCX Studio v"
    ;// use mid to remove "quotation" marks
    cprop 0 caption $noqt($2-)
    return
  }
  else if ($1 == size) {
    ;// size 0 0 350 250
    cprop 0 x $2
    cprop 0 y $3
    cprop 0 w $4
    cprop 0 h $5
    return
  }
  else if ($1 == option) {
    ;// stores whether coordinates are in dbu || pixel
    hadd dcxs.convert option $2
    return
  }


  ;// do regex on each type to get values into $regml
  if (!$dcxs_script_convertDetailsRegEx($1-)) {
    e /dcxs_script_convertControl: Error converting line: $1-
    return
  }


  var %i 1
  var %t

  ;// convert the values into project entries
  if (($1 == text) || ($1 == edit) || ($1 == button) || ($1 == check) || ($1 == radio) || ($1 == box) || ($1 == scroll) || ($1 == link)) {
    ;text "text", id, x y w h, style (right, center, nowrap)
    /*
    1 = caption
    2 = id
    3 = x
    4 = y
    5 = w
    6 = h
    7 = styles AND/OR "tab id"
    */
    var %id $regml(2)
    var %s  $gettok($regml(7), 1, 44)

    cprop %id type    $1
    cprop %id caption $regml(1)
    cprop %id x       $regml(3)
    cprop %id y       $regml(4)
    cprop %id w       $regml(5)
    cprop %id h       $regml(6)

    if ($regex(%s, tab (\d+))) {
      var %pid $regml(1)

      %s = $remove(%s, tab %pid)

      cprop %id  pid %pid
      cprop %pid items $addtok($cprop(%pid, items), %pid, 32)
    }
    else {
      cprop %id pid 0
    }


    if ($1 == edit) {
      if ($findtok(%s, read, 1, 32)) %s = $reptok(%s, read, readonly, 1, 32)

      if ($regex(%s, limit (\d+))) {
        cprop %id limit $regml(1)
      }
    }
    else if ($1 == check) {
      if ($findtok(%s, left, 1, 32)) %s = $reptok(%s, left, right, 1, 32)
      if ($findtok(%s, push, 1, 32)) %s = $reptok(%s, push, pushlike, 1, 32)
    }
    else if ($1 == radio) {
      if ($findtok(%s, left, 1, 32)) %s = $reptok(%s, left, right, 1, 32)
      if ($findtok(%s, push, 1, 32)) %s = $reptok(%s, push, pushlike, 1, 32)
    }
    else if ($1 == scroll) {
      if ($findtok(%s, horizontal, 1, 32)) {
        %s = $remtok(%s, horizontal, 1, 32)
      }
      else {
        %s = $addtok(%s, vertical, 32)
      }
    }

    %s = $dcxs_script_import_fixStyle(%s)

    cprop %id style %s $iif($1 != text, tabstop)
  }
  else if (($1 == list) || ($1 == combo)) {
    ;list id, x y w h, style (sort, extsel, multsel, size, vsbar, hsbar)
    /*
    1 = id
    2 = x
    3 = y
    4 = w
    5 = h
    6 = styles AND/OR "tab id"
    */
    var %id $regml(1)
    var %s  $gettok($regml(6), 1, 44)

    cprop %id type    $iif($1 == combo, comboex, $1)
    cprop %id caption
    cprop %id x       $regml(2)
    cprop %id y       $regml(3)
    cprop %id w       $regml(4)
    cprop %id h       $regml(5)

    if ($regex(%s, tab (\d+))) {
      var %pid $regml(1)

      %s = $remove(%s, tab %pid)

      cprop %id  pid %pid
      cprop %pid items $addtok($cprop(%pid, items), %pid, 32)
    }
    else {
      cprop %id pid 0
    }


    if ($1 == list) {
      if ($findtok(%s, multisel, 1, 32)) %s = $reptok(%s, multisel, multi, 1, 32)
      if ($findtok(%s, size, 1, 32))     %s = $reptok(%s, size, nointegral, 1, 32)
    }
    elseif ($1 == combo) {
      if ($findtok(%s, edit, 1, 32)) %s = $reptok(%s, edit, dropedit, 1, 32)
      if ($findtok(%s, drop, 1, 32)) %s = $reptok(%s, drop, dropdown, 1, 32)
    }

    %s = $dcxs_script_import_fixStyle(%s)

    cprop %id style   %s $iif($1 != box, tabstop)
  }
  else if ($1 == icon) {
    ;// dialog icon
    if ($regml(0) == 1) {
      cprop 0 icon $regml(1)
    }
    ;icon id, x y w h, filename, index, style (noborder top left bottom right)
    else {
      t /dcxs_script_convertControl: wont bother with icon yet

      var %i 1
      while ($regml(%i) != $null) {
        t %i > $ifmatch
        inc %i
      }
    }
  }
  else if ($1 == tab) {
    ;tab "text", id, x y w h
    ;tab "text", id
    /*
    1 = caption
    2 = id (panel)
    3 = , x y w h
    */

    var %id $regml(2)

    ;// main tab
    if ($regml(3)) {
      tokenize 32 $gettok($ifmatch, 2-, 32)

      cprop %id type    tab
      cprop %id x       $1
      cprop %id y       $2
      cprop %id w       $3
      cprop %id h       $4
      cprop %id pid     0
      cprop %id caption $regml(1)
      cprop %id style   tabstop

      ;// FIXME: tab item #1 has same id as tab control
      hadd dcxs.convert fix.tabid %id
    }
    ;// tab items
    else {
      var %h
      var %i 1

      while ($hfind(dcxs.proj, tab, %i).data) {
        %h = $ifmatch

        ;// found correct parent
        if (control.*.type iswm %h) {
          break
        }

        inc %i
      }

      var %pid $gettok(%h, 2, 46)

      cprop %pid items $addtok($cprop(%pid, items), %id, 32)

      cprop %id type    panel
      cprop %id ptype   tab
      cprop %id pid     %pid
      cprop %id x       0
      cprop %id y       0
      cprop %id w       $cprop(%pid, w)
      cprop %id h       $cprop(%pid, h)
      cprop %id caption $regml(1)
      cprop %id style
    }
  }
  /*
  else if ($1 == menu) {
    ;menu "text", menuid [, menuid]
  }
  else if ($1 == item) {
    ;item "text", id [, menuid]
  }
  else if ($1 == item) {
    ;item break, id [, menuid]
  }
  */
  else {
    echo 12 -a */ /dcxs_script_convertControl: unknown type $1-
  }
}



;// perform regex on the details to get it into $regml
alias -l dcxs_script_convertDetailsRegEx {
  var %r

  tokenize 32 $1-

  if (($1 == text) || ($1 == edit) || ($1 == button) || ($1 == check) || ($1 == radio) || ($1 == box) || ($1 == scroll) || ($1 == link)) {
    %r = \"(.*)\", (\d+), (\d+) (\d+) (\d+) (\d+)(.*)
  }
  else if (($1 == list) || ($1 == combo)) {
    %r = (\d+), (\d+) (\d+) (\d+) (\d+)(.*)
  }
  else if ($1 == icon) {
    ;icon id, x y w h, filename, index, style (noborder top left bottom right)
    if ($4 isnum) {
      %r = (\d+), (\d+) (\d+) (\d+) (\d+), (.+), (\d+)(.*)
    }
    ;icon D:\Scripts\fserve-x3.0\icon2.ico, 0
    else {
      %r = (.+)
    }
  }
  else if ($1 == tab) {
    ;tab "text", id, x y w h
    ;tab "text", id
    %r = \"(.*)\", (\d+)(.*)
  }
  /*
  else if ($1 == menu) {
    ;menu "text", menuid [, menuid]
    %r =
  }
  else if ($1 == item) {
    ;item "text", id [, menuid]
    %r =
  }
  else if ($1 == item) {
    ;item break, id [, menuid]
    %r =
  }
  */
  else {
    w /dcxs_script_convertControl: unknown type $1-
    return $false
  }

  return $regex($2-, %r)
}



alias -l dcxs_script_import_convertDBU {
  s Performing DBU to Pixel conversion...

  var %k 1

  ;// set value x4 for x,y,w,h
  var %t $hfind(dcxs.proj, control.*.x, 0, w)
  dcxs_prog -t dbu $calc(%t * 4)

  while ($gettok(x y w h, %k, 32)) {
    var %prop $ifmatch
    var %i    1
    var %xy   $iif(%prop == x || %prop == y, $true, $false)
    var %dbu  $iif(%prop == x || %prop == w, $dbuw, $dbuh)

    while ($hfind(dcxs.proj, control.*. $+ %prop, %i, w)) {
      var %h  $ifmatch
      var %id $gettok(%h, 2, 46)

      cprop %id %prop $calc(%dbu * $cprop(%id, %prop))

      dcxs_prog dbu $calc((%t * (%k -1)) + %i)
      inc %i
    }

    inc %k
  }
}


;// put controls ON the box, rather than having it on the same level/layer
alias -l dcxs_script_import_fixBoxes {
  s Performing import box control item bugfix

  var %i 1

  ;// find all box controls
  ;// dont have to worry about ptype == box, as normal boxes dont contain controls
  while ($hfind(dcxs.proj, box, %i).data != $null) {
    var %hash $ifmatch
    var %k   1
    var %id  $gettok(%hash, 2, 46)
    var %pid $cprop(%id, pid)

    var %x $cprop(%id, x)
    var %y $cprop(%id, y)
    var %w $cprop(%id, w)
    var %h $cprop(%id, h)

    dcxs_prog -t fixboxes $hfind(dcxs.proj, %pid, 0).data

    ;// check for controls with the same parent
    while ($hfind(dcxs.proj, %pid, %k).data) {
      var %h2 $ifmatch

      ;// check if its a pid property
      if (control.*.pid iswm %h2) {
        var %id2 $gettok(%h2, 2, 46)

        if (%id != %id2) {
          var %x2 $cprop(%id2, x)
          var %y2 $cprop(%id2, y)

          ;// test if between
          if ((%x2 > %x) && (%x2 < $calc(%x + %w)) && (%y2 > %y) && (%y2 < $calc(%y + %h))) {
            c Swapping parents for $cprop(%id2, type) $+ ( $+ %id2 $+ ) to box( $+ %id $+ )

            dec %x2 %x
            dec %y2 %y

            ;// relocate slightly
            cprop %id2 x %x2
            cprop %id2 y %y2

            ;// set the box to be its parent
            cprop %id2 pid %id

            dec %k
          }
        }
      }

      inc %k
      dcxs_prog fixboxes %k
    }

    inc %i
  }
}


;// fixes up the tab item #1 id bug with conversion
; $1 = id of tab item to be fixed
alias -l dcxs_script_import_fixTabItems {
  s Performing import tab item #1 bugfix

  var %i 1

  ;// find the id of the tab item that needs to be fixed
  var %cid $1

  ;// find a free id number for the new tab item
  while ($true) {
    if (!$hfind(dcxs.proj, $+(control., %i, .type), 1)) {
      break
    }

    inc %i
  }

  var %id %i
  %i = 1

  cprop %id x       0
  cprop %id y       0
  cprop %id w       $cprop($1, w)
  cprop %id h       $cprop($1, h)
  cprop %id pid     $1
  cprop %id caption $cprop($1, caption)
  cprop %id ptype   tab
  cprop %id type    panel
  cprop %id style

  ;// add the item at the first of the parent item list
  cprop $1 items $instok($remtok($cprop($1, items), $1, 32), %id, 1, 32)

  dcxs_prog -t fixtabs $hfind(dcxs.proj, control.*.pid, 0, w)

  ;// find all pid entries
  while ($hfind(dcxs.proj, control.*.pid, %i, w)) {
    var %h $ifmatch

    if ($hget(dcxs.proj, %h) == $1) {
      var %cid = $gettok(%h, 2, 46)

      if ($cprop(%cid, ptype) != tab) {
        c /dcxs_script_import_fixTabItems: $ifmatch > fixing tab #1 id $1 for %h to %id
        hadd dcxs.proj %h %id
      }
    }

    inc %i
    dcxs_prog fixtabs %i
  }
}


;// remove and change style types from mIRC to DCX
; $1- = styles
alias -l dcxs_script_import_fixStyle {
  return $reptok($1-, disable, disabled, 1, 32)
}



;###############################################################
; setup dcx studio preferences
alias -l dcxs_pref_savePreferences {
  ;// status window options
  pref status.show  $did(18).state
  pref status.work  $did(19).state
  pref status.error $did(20).state
  pref status.warn  $did(21).state
  pref status.comment $did(35).state
  pref status.debug $did(22).state
  pref status.todo  $did(23).state

  ;// init controls in either INIT event or seperate alias
  pref control.init $iif($did(27).state, init, alias)

  ;// code generation
  pref genscript.showcomments   $did(28).state
  pref genscript.dcxcomments    $did(29).state
  pref genscript.ctrlcomments   $did(30).state
  pref genscript.callbackcode   $did(31).state
  pref genscript.menuitem       $did(36).state

  ;// cursor stuff
  pref cursor.add   $did(7).state
  pref cursor.hover $did(8).state

  ;// highlighting
  pref hilight.enabled $did(9).state

  var %border

  %border = %border $+ $iif($did(10).state, b)
  %border = %border $+ $iif($did(11).state, c)
  %border = %border $+ $iif($did(12).state, d)
  %border = %border $+ $iif($did(13).state, f)
  %border = %border $+ $iif($did(14).state, s)
  %border = %border $+ $iif($did(15).state, w)

  pref hilight.style $+(+, %border)
}


;// update status message checked options
alias -l dcxs_pref_updateStatusMsgChecks {
  did $iif($did(18).state, -e, -b) dcxpref 19-23,35
}

;// update hover border checked options
alias -l dcxs_pref_updateHoverBorderChecks {
  did $iif($did(9).state, -e, -b) dcxpref 10-15
}

;// update genscript comments checked options
alias -l dcxs_pref_updateGenscriptCommentChecks {
  did $iif($did(28).state, -e, -b) dcxpref 29-30
}

;// return a default value if the preference entry isnt set
alias -l dcxs_pref_default {
  ;// status window options
  if ($1 == status.show  ) { return 1 }
  if ($1 == status.work  ) { return 1 }
  if ($1 == status.error ) { return 1 }
  if ($1 == status.warn  ) { return 1 }
  if ($1 == status.comment) { return 1 }
  if ($1 == status.debug ) { return 0 }
  if ($1 == status.todo  ) { return 0 }


  ;// init controls in either INIT event or seperate alias
  if ($1 == control.init ) { return alias }

  ;// code generation
  if ($1 == genscript.showcomments ) { return 1 }
  if ($1 == genscript.dcxcomments  ) { return 1 }
  if ($1 == genscript.ctrlcomments ) { return 1 }
  if ($1 == genscript.callbackcode ) { return 1 }
  if ($1 == genscript.menuitem     ) { return 1 }

  ;// cursor stuff
  if ($1 == cursor.add   ) { return 1 }
  if ($1 == cursor.hover ) { return 1 }

  ;// highlighting
  if ($1 == hilight.enabled) { return 1 }
  if ($1 == hilight.style  ) { return +b }

  echo 4 -s * $!dcxs_pref_default: variable in dcxs.pref not set $1-
}



alias -l tprop {
  var %h control. $+ $1 $+ . $+ $2

  if ($isid) {
    return $temp(%h)
  }

  temp %h $3-
}

alias -l dcxs_ieditor_showDetails {
  var %id $gettok($did($dname, 2).seltext, 1, 58)

  did -ra $dname 12 $tprop(%id, caption)
  did -ra $dname 13 $tprop(%id, x)
  did -ra $dname 14 $tprop(%id, y)
  did -ra $dname 17 $tprop(%id, w)
  did -ra $dname 10 $tprop(%id, h)

  did -c $dname 19 $findtok($didtok(19, 44), $tprop(%id, type), 1, 44)
}


alias -l dcxs_ieditor_editDetails {
  var %id $gettok($did($dname, 2).seltext, 1, 58)

  ;// caption
  if      ($did == 12) { tprop %id caption $did($did) }
  else if ($did == 13) { tprop %id x       $did($did) }
  else if ($did == 14) { tprop %id y       $did($did) }
  else if ($did == 17) { tprop %id w       $did($did) }
  else if ($did == 10) { tprop %id h       $did($did) }
  else if ($did == 19) { tprop %id type    $gettok($did(20), $did($did).sel, 44) }
}


alias -l dcxs_ieditor_enableButtons {
  did $iif($numtok($temp(ieditor.order), 32) < 2, -b, -e) $dname 6
}


;// save settings into temp and apply into project
; $1 = mode
; $2 = id of control
alias -l dcxs_ieditor_save {
  var %i 1
  var %c $temp(ieditor.order)
  var %deleted $cprop($2, items)
  var %added


  ;// go through each new order id
  while ($gettok(%c, %i, 32)) {
    var %id $ifmatch

    ;// if id is in the old list
    if ($findtok(%deleted, %id, 1, 32)) {
      %deleted = $remtok(%deleted, %id, 32)

      ;// save new settings
      cprop %id caption $tprop(%id, caption)
      cprop %id x $tprop(%id, x)
      cprop %id y $tprop(%id, y)
      cprop %id w $tprop(%id, w)
      cprop %id h $tprop(%id, h)

      ;// check if its changed
      var %t $tprop(%id, type)

      if (%t != $cprop(%id, type)) {
        c changed control type for %id to %t

        if ($hasChildren(%id)) {
          deleteChildren %id
        }

        hdel -w dcxs.proj $+(control., %id, .*)

        ;// register child only works with controls that exist
        dcxs_control_registerChild $2 %id %t $chr(1) $tprop(%id, caption)
      }
    }
    else {
      %added = $addtok(%added, %id, 32)
    }

    inc %i
  }

  var %i 1
  while ($gettok(%deleted, %i, 32)) {
    ;// call this function to handle deletion
    deleteControl $ifmatch
    inc %i
  }

  var %i 1
  while ($gettok(%added, %i, 32)) {
    var %id $ifmatch
    var %order 0
    var %t $tprop(%id, type)
    var %x $tprop(%id, x)
    var %y $tprop(%id, y)
    var %w $tprop(%id, w)
    var %h $tprop(%id, h)
    var %s $hget(dcxs.pref, default. $+ %t $+ .s)

    if ($1 == tab) {
      xdid -a dcxtest $2 %order 0 $cprop(%id, caption) $chr(9) %id %t %x %y %w %h %s
    }
    else {
      xdid -a dcxtest $2 %order +ge 0 %h 220 0 0 $tprop(%id, caption) $chr(9) %id %t %x %y %w %h %s $chr(9) Tooltip
    }

    dcxs_control_registerChild $2 %id %t %s $chr(1) $tprop(%id, caption)

    inc %i
  }

  ;// save order
  cprop $temp(ieditor.id) items %c
  dcxs_control_recreate $temp(ieditor.id)
  dcxs_show_controlDetails $2
}


on *:dialog:dcxs_ieditororder:*:*: {
  if ($devent == init) {
    dcx Mark $dname dcxsieditororder_cb
    xdialog -b $dname +nto

    ;// Initialising control: Button (#5)
    xdialog -c $dname 5 button 245 25 25 25 tabstop
    xdid -t $dname 5 p

    ;// Initialising control: Button (#6)
    xdialog -c $dname 6 button 245 192 25 25 tabstop
    xdid -t $dname 6 q

    ;// set fonts for up/down buttons
    xdid -f $dname 5 +a default 10 wingdings 3
    xdid -f $dname 6 +a default 10 wingdings 3


    ;// load variables into listbox for manipulation
    var %i 1
    var %c $temp(ieditor.order)

    while ($gettok(%c, %i, 32)) {
      var %id $ifmatch

      did -a $dname 2 %id $+ : $cname($tprop(%id, type)) ( $+ $tprop(%id, caption) $+ )

      inc %i
    }
  }

  if (($devent == sclick) && ($did == 3)) {
    var %i 1
    var %c

    while ($did($dname, 2, %i).text) {
      %c = $addtok(%c, $gettok($ifmatch, 1, 58), 32)
      inc %i
    }

    temp ieditor.order %c
  }
}




alias objview {
  if ($dialog(dcxs_objview)) dialog -c dcxs_objview

  dialog -ma dcxs_objview objview_table
}

dialog objview_table {
  title "Object Browser"
  size -1 -1 225 432
}

on *:dialog:dcxs_objview:*:*: {
  if ($devent == init) {
    dcx Mark $dname objview_cb
    xdialog -b $dname +mntyz

    ;// Call initilisation alias
    objview_init_dcx
  }
}

alias -l objview_init_dcx {
  xdialog -c $dname 1 treeview 5 5 210 420 hasbuttons haslines showsel

  objview_refresh
}

;// Callback alias for objview
alias objview_cb {
  if ($2 != mouse) {
    echo $color(info) -s */ objview_cb: $1-
  }
}

alias objview_refresh {
  var %dname dcxs_objview

  xdid -r %dname 1

  ;// list direct dialog children
  xdid -a %dname 1 -1 $chr(9) +be 0 0 0 0 0 0 0: Dialog $chr(9) $objview_buildtooltip(0)

  ;// list all children
  var %children $getChildren(0)
  var %i 1
  var %cid

  while ($gettok(%children, %i, 32)) {
    %cid = $ifmatch

    objview_add 0 %cid

    inc %i
  }
}

;// adds a control to a specific node
;// $1 == control parent
;// $2 == control id
alias objview_add {
  var %dname dcxs_objview
  var %tvid  1
  var %path  $objview_find($1)
  var %children $getChildren($2)

  var %flags + $+ $iif(!$2, e) $+ $iif(%children, bi)

  xdid -a %dname %tvid %path -1 $chr(9) %flags 0 0 0 0 0 0 $2 $+ : $cname($cprop($2, type)) $chr(9) $objview_buildtooltip($2)

  var %i 1
  var %cid

  while ($gettok(%children, %i, 32)) {
    %cid = $ifmatch
    recursive objview_add $2 %cid
    inc %i
  }

  xdid -z %dname %tvid +bn %path
}

;// finds a control in the treeview
;// $1 == control parent
alias objview_find {
  var %dname dcxs_objview
  var %tvid  1

  return $xdid(%dname, %tvid, $+($chr(9), $1, : *, $chr(9)), W, 1).find
}

;// creates the tooltip for generic information
;// $1 == control id
alias objview_buildtooltip {
  var %i 1
  var %ret

  var %list caption,style,x,y,w,h,type,pid

  ;// check if it is a child contrl
  if ($isChild($1)) {
    %list = %list $+ ,ptype
  }

  ;// do ordered props first
  while ($gettok(%list, %i, 44)) {
    var %key = $ifmatch

    %ret = %ret $+ $iif(%ret != $null, $crlf) $+ %key $+ $chr(9) $+ : $cprop($1, %key)

    inc %i
  }

  ;// check for any other props
  %i       = 1
  var %first $true

  while ($hfind(dcxs.proj, control. $+ $1 $+ .*, %i, w)) {
    var %key = $gettok($ifmatch, 3, 46)

    if (!$findtok(%list, %key, 1, 44)) {
      %ret = %ret $+ $iif(%first, $crlf $+ $crlf, $crlf) $+ %key $+ $chr(9) $+ : $cprop($1, %key)
      %first = $false
    }

    inc %i
  }

  return %ret
}
