blizzard::gui — File Browser

blizzardguiv1.0 / blizzardguiv1.0 / blizzard_gui_engine.mrc

blizzard_gui_engine.mrc — 25.98 KB — Download this file

;===================================================================================================

;                       blizzard::gui v1.0 - Graphical User Interface Engine
;                       ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
;

;     This file is the main script of the gui engine. You need it in order to create GUIs.
;     Others files (examples, gui manager,...) are not needed, but some can be really usefull.  
;
;     PLEASE - DO NOT MODIFY THIS FILE
;              ¯¯¯¯¯¯  
;     Made by Epsilon - July 2003

;     ============= www.blizzard.be.tf =============
;                                     

;===================================================================================================

;===================================================================================================

;                                             Aliases

;===================================================================================================

;DLL call for x-gui
alias -l x-gui {
  var %r = $dll($+(",$scriptdir $+ x-GUI.dll,"),$1,$2-) 
  if ($isid) return %r
}

;DLL call for winrgn 
alias -l winrgn {
  dll $+(",$scriptdir $+ WinRgn.dll,") $1 $iif($len($2-),$2-,NOT_USED)
}

;main alias, to create a gui
alias gui {
  if (!$gui_is_loaded) {
    error The GUI engine was not loaded correctly - You cannot use the /GUI command - Use /load_gui to load the engine
    return
  }
  var %win
  if ($isid) {
    %win = $gui_full_name($1)
    if (!$window(%win)) return
    else {
      if (!$prop) return $1
      else if ($prop == title) return $hget(%win,title)
      else if ($prop == state) || ($prop == x) || ($prop == y)  || ($prop == w) || ($prop == h) || ($prop == cid) return $window(%win). [ $+ [ $prop ] ]     
      else {
        error $!gui $1- : bad property
        return
      }
    }
  }
  else {
    var %params, %table = $2
    if ($numtok($1-,32) >= 2) && ($left($1,1) == -) {
      %win = $gui_full_name($2)
      if (!$window(%win)) %params = z      
      %table = $3 
      var %tmp_params = $gettok($1,1,45)
      var %i = 1, %len = $len(%tmp_params)
      while (%i <= %len) {
        var %p = $mid(%tmp_params,%i,1)
        if (%p == c) {
          if ($window(%win)) gui_close $2
          else error /gui $1- gui doesn't exists.
          return
        }
        else if (%p == d) {
          if ($window(%win)) gui_set $2 disable_close 1
          else { 
            error /gui $1- gui doesn't exists.
            return
          }
        }
        else if (%p == e) {
          if ($window(%win)) gui_set $2 disable_close 0
          else { 
            error /gui $1- gui doesn't exists.
            return
          }
        }
        else if (%p == l) {
          if ($window(%win)) gui_set $2 disable_min 1
          else { 
            error /gui $1- gui doesn't exists.
            return
          }
        }
        else if (%p == m) {
          if ($window(%win)) gui_set $2 disable_min 0
          else { 
            error /gui $1- gui doesn't exists.
            return
          }
        }
        else if (%p == x) {
          if ($window(%win)) gui_set $2 no_exit_on_close 0
          else { 
            error /gui $1- gui doesn't exists.
            return
          }
        }
        else if (%p == y) {
          if ($window(%win)) gui_set $2 no_exit_on_close 1
          else { 
            error /gui $1- gui doesn't exists.
            return
          }
        }
        else if (%p == v) {
          %params = $remove(%params,z) $+ v
        }
        else if (%p == a) || (%p == n) || (%p == r) || (%p == h) || (%p == n) || (%p == w) || (%p == z) {
          %params = %params $+ %p
        }
        inc %i
      }
      if ($window(%win)) {
        window - $+ %params %win
        return
      }
    }
    else { 
      %win = $gui_full_name($1)
      %params = z
    }
    if ($window(%win)) {
      error $1 $+ : GUI already exists.
      return
    }  
    if ($hget(%win)) hfree %win
    hmake %win 10
    hadd %win close_hover 0
    hadd %win min_hover 0
    hadd %win title blizzard::gui
    hadd %win disable_close 0
    hadd %win disable_min 0
    hadd %win no_exit_on_close 0
    window -dokpB $+ %params +dL %win $calc($window(-3).dx +200) $calc($window(-3).dy +200) 200 200
    window -a %win
    x-gui Mark %win
    if ($isalias($+(tgui_,%table))) $+(tgui_,%table)
    paint_gui %win
    .signal -n gui $1 init
  }
}
;return 1 if the gui engine is loaded
alias gui_is_loaded return $hget(gui,loaded)

;load the template of the current gui skin
alias load_gui {
  if ($hget(gui)) hfree gui
  window -phB +d @gui.tmp 0 0 200 200
  if ($isfile($gui_skin_dir(%blizzard_gui_skin $+ .png))) && ($pic($gui_skin_dir(%blizzard_gui_skin $+ .png)).width == 200) && ($pic($gui_skin_dir(%blizzard_gui_skin $+ .png)).height == 200) drawpic @gui.tmp 0 0 $gui_skin_dir(%blizzard_gui_skin $+ .png)
  else {
    load_default_gui
    if (%blizzard_gui_skin) && (%blizzard_gui_skin != <default>) error bad skin file : $gui_skin_dir(%blizzard_gui_skin $+ .png) - default skin loaded -
  }

  if (!$isfile($+(",$scriptdir $+ WinRgn.dll,"))) {
    error DLL Error : WinRgn.dll must be in the same directory as the engine script
    return 
  }
  if (!$isfile($+(",$scriptdir $+ x-GUI.dll,"))) {
    error DLL Error : x-GUI.dll must be in the same directory as the engine script
    return 
  }
  hmake gui 10
  hadd gui color_back $getdot(@gui.tmp,60,60)
  hadd gui color_display $getdot(@gui.tmp,198,127)  
  hadd gui color_display_text $getdot(@gui.tmp,198,130)
  hadd gui color_title $getdot(@gui.tmp,198,133)
  hadd gui color_title_disable $getdot(@gui.tmp,198,136)
  hadd gui color_text $getdot(@gui.tmp,198,139)

  window -phB +d @gui.tmp.but 0 0 60 24
  drawcopy @gui.tmp 1 125 60 24 @gui.tmp.but 0 0
  drawreplace -r @gui.tmp.but $rgb(255,0,255) $hget(gui,color_back)
  drawsave @gui.tmp.but bgui_button1.bmp
  drawcopy @gui.tmp 1 151 60 24 @gui.tmp.but 0 0
  drawreplace -r @gui.tmp.but $rgb(255,0,255) $hget(gui,color_back)
  drawsave @gui.tmp.but bgui_button2.bmp
  drawcopy @gui.tmp 63 125 60 24 @gui.tmp.but 0 0
  drawreplace -r @gui.tmp.but $rgb(255,0,255) $hget(gui,color_back)
  drawsave @gui.tmp.but bgui_button3.bmp
  window -c @gui.tmp.but
  var %total = $enum_gui(0), %i = 1
  while (%i <= %total) {
    var %gui = $enum_gui(%i)
    var %j = 1
    while (%j <= 127) {
      var %id = $hget($gui_full_name(%gui),%j)
      if (%id) {
        if (%id == button) {
          var %text = $gid(%gui,%j)
          var %pos = $gid(%gui,%j).pos
          var %vis = $gid(%gui,%j).visible
          var %en = $gid(%gui,%j).enabled
          gid -s %gui %j
          gui_button %gui %j %pos > %text
          if (!%vis) gid -h %gui %j
          if (!%en) gid -b %gui %j
        }
        else {
          if (%id == text) || (%id == check) || (%id == radio) gid -k %gui %j $hget(gui,color_back) $hget(gui,color_text)
          else gid -k %gui %j $hget(gui,color_display) $hget(gui,color_display_text)    
        }      
      }
      inc %j
    }
    paint_gui $gui_full_name(%gui) 
    inc %i
  }
  hadd gui loaded 1
}
alias -l load_default_gui {
  drawrect -rf @gui.tmp $rgb(236,233,216) 1 0 0 200 200
  drawrect -rf @gui.tmp $rgb(0,84,227) 1 0 0 200 22
  drawrect -rf @gui.tmp $rgb(0,84,227) 1 0 0 6 118
  drawrect -rf @gui.tmp $rgb(0,84,227) 1 194 0 6 118
  drawrect -rf @gui.tmp $rgb(0,84,227) 1 0 118 200 6
  drawline -r @gui.tmp 0 1 5 21 5 118
  drawline -r @gui.tmp 0 1 194 21 194 118
  drawline -r @gui.tmp 0 1 5 118 194 118
  drawline -r @gui.tmp 0 1 5 21 194 21
  drawrect -r @gui.tmp 0 1 13 4 55 14
  drawrect -rf @gui.tmp $rgb(240,240,240) 1 14 5 53 12
  drawrect -rd @gui.tmp 0 1 0 0 200 124 16 16
  drawrect -rd @gui.tmp $rgb(0,60,116) 1 1 125 60 24 5 5
  drawrect -rfd @gui.tmp $rgb(240,240,240) 3 2 126 58 22 5 5
  drawrect -rd @gui.tmp $rgb(160,190,236) 3 2 126 58 22 5 5
  drawrect -rd @gui.tmp $rgb(0,60,116) 1 63 125 60 24 5 5
  drawrect -rfd @gui.tmp $rgb(240,240,240) 3 64 126 58 22 5 5
  drawrect -rd @gui.tmp $rgb(251,199,97) 3 64 126 58 22 5 5
  drawrect -rd @gui.tmp $rgb(0,60,116) 1 1 151 60 24 5 5
  drawrect -rfd @gui.tmp $rgb(200,200,176) 3 2 152 58 22 5 5
  drawrect -rf @gui.tmp $rgb(0,84,227) 1 1 177 133 22
  drawline -r @gui.tmp 0 1 1 177 134 177
  drawline -r @gui.tmp 0 1 1 198 134 198
  drawtext -or @gui.tmp 0 Verdana 16 105 179 X
  drawtext -or @gui.tmp $rgb(240,240,240) Verdana 16 53 179 X  
  drawtext -r @gui.tmp 0 Webdings 17 87 176 0
  drawtext -r @gui.tmp $rgb(240,240,240) Webdings 17 35 176 0
  drawdot -r @gui.tmp $rgb(240,240,240) 1 198 127 
  drawdot -r @gui.tmp 0 1 198 130
  drawdot -r @gui.tmp $rgb(1,1,1) 1 198 133
  drawdot -r @gui.tmp $rgb(140,140,140) 1 198 136
  drawdot -r @gui.tmp $rgb(1,1,1) 1 198 139
}

;display errors on status
alias -l error {
  echo -s  $+ $color(info) $+ $timestamp [blizzard::gui error] $1-
}

;dir
alias -l gui_skin_dir {
  return $+(",%blizzard_gui_skin_dir $+ $1,")
}

;move the window
alias -l gui_dragdrop {
  var %x = $calc($mouse.dx -$1)
  var %y = $calc($mouse.dy -$2)
  if (%x < $window(-3).dx) %x = $window(-3).dx
  if (%y < $window(-3).dy) %y = $window(-3).dy
  window $active %x %y
  if ($mouse.key & 1) {
    .timer$active -o 1 0 gui_dragdrop $1-
  }
}

;close the window
alias -l gui_close {
  var %win = $gui_full_name($1)
  if ($hget(%win)) hfree %win
  if ($window(%win)) window -c %win
  .signal gui $1 closed
}

;settings
alias -l gui_set {
  var %win = $gui_full_name($1)
  if ($hget(%win)) { 
    if ($2 == disable_close) hadd %win disable_close $3
    else if ($2 == disable_min) hadd %win disable_min $3
    else if ($2 == no_exit_on_close) hadd %win no_exit_on_close $3
    else  { error /gui_set $1- : bad option name | return }
  }
  else  { error /gui_set $1- : window is not opened | return }
  paint_gui %win
}

;convert long name to short name
alias gui_short_name {
  if ($right($1,44) ==                                         -gui) return $mid($1,2,$calc($len($1) -45))
}

;convert short name to long name
alias gui_full_name {
  return @ $+ $1 $+ $str($chr(160),40) $+ -gui
}

;refresh the gui
alias -l paint_gui {
  var %win = $1
  var %twin = @gui.tmp
  var %w = $window(%win).w
  var %h = $window(%win).h

  winrgn wrSelectWindow $window(%win).hwnd
  winrgn wrSetMode rmRoundRect
  winrgn wrSetRegion 0 0 $calc(%w +1) $calc(%h +1) 16 16

  drawrect -nrf %win $rgb(255,0,255) 1 0 0 %w %h
  drawcopy -n %twin 0 0 18 103 %win 0 0
  var %i = 18
  while (%i < %w) {
    drawcopy -n %twin 18 0 46 28 %win %i 0
    inc %i 46
  }
  drawcopy -n %twin 140 0 60 103 %win $calc(%w - 60) 0
  drawcopy -n %twin 64 0 22 103 %win $calc(%w - 62) 0
  %i = 103
  while (%i < %h) {
    drawcopy -n %twin 0 26 83 77 %win 0 %i
    drawcopy -n %twin 190 26 12 77 %win $calc(%w -10) %i
    inc %i 77
  }
  drawcopy -n %twin 0 103 21 21 %win 0 $calc(%h -21)
  var %i = 21
  while (%i < %w) {
    drawcopy -n %twin 21 112 158 12 %win %i $calc(%h - 12)
    inc %i 158
  }
  drawcopy -n %twin 179 103 21 21 %win $calc(%w - 21) $calc(%h -21)
  drawreplace -nr %win $rgb(255,0,255) $hget(gui,color_back)
  if (%win == $active) drawtext -ncr %win $hget(gui,color_title) Courrier -7 18 6 $calc(%w - 79) 11 $hget(%win,title)
  else drawtext -ncr %win $hget(gui,color_title_disable) Courrier -7 18 6 $calc(%w - 79) 11 $hget(%win,title)
  if (!$hget(%win,disable_close)) drawcopy @gui.tmp 103 177 16 22 %win $calc(%w - 22) 0 16 22
  if (!$hget(%win,disable_min)) drawcopy @gui.tmp 88 177 15 22 %win $calc(%w - 37) 0 15 22
  drawdot %win
}

alias -l is_gui {
  if ($hget($1)) {    
    return $true
  }
  return $false
}

alias -l enum_gui {
  if (!$isid) || ($1 !isnum) { error enum_gui : Invalid format | return }
  var %i = 1,%total = $window(0),%cpt = 0 
  while (%i <= %total) {
    var %win = $window(%i)
    if ($is_gui(%win)) {
      inc %cpt
      if ($1 == %cpt) return $gui_short_name($window(%i))
    }
    inc %i
  }
  if ($1 == 0) return %cpt
  else return
}


;===================================================================================================

;                                             Events

;===================================================================================================

on *:LOAD: {
  echo -a 
  echo -a blizzard::gui - GUI Engine loaded. 
  set %blizzard_gui_skin_dir $scriptdir $+ skins\
  set %blizzard_gui_skin blizzard
  echo -a The skin directory was set to $scriptdir $+ skins\
  echo -a You can change the skin dir by modifying the %blizzard_gui_skin_dir variable.
  echo -a 
}
on *:UNLOAD: {
unset %blizzard_gui_*
window -c @gui.tmp
.remove bgui_button1.bmp
  .remove bgui_button2.bmp
  .remove bgui_button3.bmp

}
on *:START: {
  load_gui
}
on *:EXIT: {
  .remove bgui_button1.bmp
  .remove bgui_button2.bmp
  .remove bgui_button3.bmp
}

On *:SIGNAL:xGUI: {
  if ($right($1,44) ==                                         -gui) {
    var %win = $gui_short_name($1)    
    if ($2 == joystick) || ($2 == sclick) || ($2 == rclick) || ($2 == dclick) || ($2 == edit) || ($2 == setfocus) || ($2 == killfocus) || ($2 == wheel)  || ($2 == hover) || ($2 == leave) || ($2 == mouse) .signal -n gui %win $2-
  }
}

on *:ACTIVE:*: {
  if ($right($lactive,44) ==                                         -gui) drawtext -cr $lactive $hget(gui,color_title_disable) Courrier -7 18 6 $calc($window($lactive).w - 79) 11 $hget($lactive,title)
  if ($right($active,44) ==                                         -gui) drawtext -cr $active $hget(gui,color_title) Courrier -7 18 6 $calc($window($active).w - 79) 11 $hget($active,title)
  else if ($active == @gui.tmp) window -h @gui.tmp
}

on *:APPACTIVE: {
  var %total = $enum_gui(0), %i = 1
  while (%i <= %total) {
    var %gui = $gui_full_name($enum_gui(%i))
    if (!$appactive) {
      hadd %gui state $window(%gui).state
      window -h %gui
      window -w %gui
    }
    else {
      if ($hget(%gui,state) != minimized) window -a %gui
      else {
        window -n %gui        
      }
    } 
    inc %i
  }
}
on *:CLOSE:*                                       -gui: {
  gui_close $gui_short_name($target)
}

menu *                                        -gui {
  sclick {
    if ($inrect($mouse.x,$mouse.y,13,4,$calc($window($active).w -71),14)) {
      gui_dragdrop $calc($mouse.dx -$window($active).x) $calc($mouse.dy -$window($active).y)
    }
  }
  uclick {
    if ($hget($active,close_hover)) {
      if ($hget($active,no_exit_on_close)) {
        .signal -n GUI $gui_short_name($active) close
      }     
      else gui_close $gui_short_name($active)
    }
    if ($hget($active,min_hover)) {
      drawcopy @gui.tmp 88 177 15 22 $active $calc($window($active).w - 37) 0 15 22
      window -n $active      
    }
  }  

  mouse {

    if (!$hget($active,disable_close)) {    
      if ($inrect($mouse.x,$mouse.y,$calc($window($active).w - 22),5,16,13)) {
        if (!$hget($active,close_hover)) {
          hadd $active close_hover 1  
          drawcopy @gui.tmp 51 177 16 22 $active $calc($window($active).w - 22) 0 16 22
        }
      }
      else if ($hget($active,close_hover)) {
        hadd $active close_hover 0
        drawcopy @gui.tmp 103 177 16 22 $active $calc($window($active).w - 22) 0 16 22
      }
    }
    if (!$hget($active,disable_min)) {    
      if ($inrect($mouse.x,$mouse.y,$calc($window($active).w - 37),5,15,13)) {
        if (!$hget($active,min_hover)) {
          hadd $active min_hover 1  
          drawcopy @gui.tmp 36 177 15 22 $active $calc($window($active).w - 37) 0 15 22
        }
      }
      else if ($hget($active,min_hover)) {
        hadd $active min_hover 0
        drawcopy @gui.tmp 88 177 15 22 $active $calc($window($active).w - 37) 0 15 22
      }
    }

  }
  leave { 
    if ($hget($active,close_hover)) {
      hadd $active close_hover 0
      drawcopy @gui.tmp 103 177 16 22 $active $calc($window($active).w - 22) 0 16 22
    }
    if ($hget($active,min_hover)) {
      hadd $active min_hover 0
      drawcopy @gui.tmp 88 177 15 22 $active $calc($window($active).w - 37) 0 15 22
    }
  }
}


;===================================================================================================

;                                         Controls aliases

;===================================================================================================

alias -l co {
  return $calc($1 +10) $calc($2 +26) $3 $4   
}

alias -l add_control {
  if ($hget($1,$2)) return $false
  else {
    hadd $1 $2 $3
    return $true
  } 
}
alias gui_title {
  var %win = $gui_full_name($1)
  if (!$window(%win)) {
    error window $1 is not opened.
    return
  }
  hadd %win title $2-
  paint_gui %win
}
alias gui_size {
  var %win = $gui_full_name($1)  
  if (!$window(%win)) {
    error window $1 is not opened.
    return
  }
  var %x = $window(-3).dx + $2
  var %y = $window(-3).dy + $3
  if ($2 == -1) %x = -1
  if ($3 == -1) %y = -1
  var %w = $4, %h = $5
  if (%w < 100) %w = 100
  if (%h < 70) %h = 70
  window %win %x %y %w %h
  paint_gui %win
}
alias gui_edit {
  var %win = $gui_full_name($1)
  if (!$window(%win)) {
    error /gui_edit $1- : window $1 is not opened.
    return
  }
  if ($2 !isnum) {
    error /gui_edit $1- : invalid id
    return
  }
  if (!$add_control(%win,$2,edit)) {
    error /gui_edit $1- : id already exists
    return
  }

  x-gui Create %win > editbox $2 $co($3,$4,$5,$6) $7-
  x-gui Set %win > color $2 $hget(gui,color_display) $hget(gui,color_display_text)
  x-gui Set %win > style $2 windowedge
  x-gui Set %win > style $2 border
  x-gui Set %win > font $2 Tahoma > 8
}
alias gui_text {
  var %win = $gui_full_name($1)
  if (!$window(%win)) {
    error /gui_text $1- : window $1 is not opened.
    return
  }
  if ($2 !isnum) {
    error /gui_text $1- : invalid id
    return
  }
  if (!$add_control(%win,$2,text)) {
    error /gui_text $1- : id already exists
    return
  }
  x-gui Create %win > text $2 $co($3,$4,$5,$6) $7-
  x-gui Set %win > color $2 $hget(gui,color_back) $hget(gui,color_text)
  x-gui Set %win > font $2 Tahoma > 8
}

alias gui_list {
  var %win = $gui_full_name($1)
  if (!$window(%win)) {
    error /gui_list $1- :window $1 is not opened.
    return
  }
  if ($2 !isnum) {
    error /gui_list $1- : invalid id
    return
  }
  if (!$add_control(%win,$2,list)) {
    error /gui_list $1- : id already exists
    return
  }

  x-gui Create %win > listbox $2 $co($3,$4,$5,$6) $iif($7,$7-)
  x-gui Set %win > color $2 $hget(gui,color_display) $hget(gui,color_display_text)
  x-gui Set %win > style $2 windowedge
  x-gui Set %win > style $2 border
  x-gui Set %win > font $2 Tahoma > 8
}

alias gui_richedit {
  var %win = $gui_full_name($1)
  if (!$window(%win)) {
    error /gui_richedit $1- : window $1 is not opened.
    return
  }
  if ($2 !isnum) {
    error /gui_richedit $1- : invalid id
    return
  }
  if (!$add_control(%win,$2,richedit)) {
    error /gui_richedit $1- : id already exists
    return
  }
  x-gui Create %win > richedit $2 $co($3,$4,$5,$6) $7-
  x-gui Set %win > color $2 $hget(gui,color_display) $hget(gui,color_display_text)
  x-gui Set %win > style $2 windowedge
  x-gui Set %win > style $2 border
  x-gui Set %win > font $2 Tahoma > 8
}

alias gui_button {
  var %win = $gui_full_name($1)
  if (!$window(%win)) {
    error /gui_button $1- : window $1 is not opened.
    return
  }
  if ($2 !isnum) {
    error /gui_button $1- : invalid id
    return
  }
  if (!$add_control(%win,$2,button)) {
    error /gui_button $1- : id already exists
    return
  }
  var %win = $gui_full_name($1)
  x-gui Create %win > button $2 $co($3,$4,$5,$6) bitmap > bgui_button1.bmp,bgui_button2.bmp,bgui_button3.bmp
  x-gui Set %win > text $2 $gettok($7-,1,62)
  x-gui Set %win > color $2 $hget(gui,color_display) $hget(gui,color_text)
  x-gui Set %win > font $2 Tahoma > 8
}

alias gui_check {
  var %win = $gui_full_name($1)
  if (!$window(%win)) {
    error /gui_check $1- : window $1 is not opened.
    return
  }
  if ($2 !isnum) {
    error /gui_check $1- : invalid id
    return
  }
  if (!$add_control(%win,$2,check)) {
    error /gui_check $1- : id already exists
    return
  }
  var %win = $gui_full_name($1)
  x-gui Create %win > checkbox $2 $co($3,$4,$5,$6) flat $7-
  x-gui Set %win > color $2 $hget(gui,color_back) $hget(gui,color_text)
  x-gui Set %win > font $2 Tahoma > 8
}

alias gui_radio {
  var %win = $gui_full_name($1)
  if (!$window(%win)) {
    error /gui_radio $1- : window $1 is not opened.
    return
  }
  if ($2 !isnum) {
    error /gui_radio $1- : invalid id
    return
  }
  if (!$add_control(%win,$2,radio)) {
    error /gui_radio $1- : id already exists
    return
  }
  var %win = $gui_full_name($1)
  x-gui Create %win > radio $2 $co($3,$4,$5,$6) flat $7-
  x-gui Set %win > color $2 $hget(gui,color_back) $hget(gui,color_text)
  x-gui Set %win > font $2 Tahoma > 8
}



;===================================================================================================

;                                         /GID and $GID

;===================================================================================================

alias gid {
  if (!$isid) {
    if ($left($1,1) != -) || ($len($1) != 2) { error /gid $1- : invalid parameter | return }
    if (!$2) || (!$window($gui_full_name($2))) { error /gid $1- : window doesn't exist | return }  
    var %win = $gui_full_name($2)  
    var %id = $3
    var %type = $hget(%win,%id)
    if ($3 !isnum) || (!%type) { error /gid $1- : invalid id | return } 
    var %p = $mid($1,2,1) 

    if (%p == f) {           
      x-gui Set %win > font %id $4-
      return
    }
    else if (%p == e) {
      x-gui Set %win > enable %id
      return
    }
    else if (%p == b) {
      x-gui Set %win > disable %id
      return
    }
    else if (%p == v) {
      x-gui Set %win > visible %id
      return
    }
    else if (%p == h) {
      x-gui Set %win > hidden %id
      return
    }
    else if (%p == c) {
      if (%type == check) || (%type == radio) { x-gui Checkbox %win > SetState %id 1 | return }
      if (%type == list) {
        if ($4 !isnum) error /gid $1- : invalid line number
        else x-gui Listbox %win > SelItem %id $4
        return
      }
    }
    else if (%p == u) {
      if (%type == check) || (%type == radio) { x-gui Checkbox %win > SetState %id 0 | return }     
      return
    }
    else if (%p == a) {
      if (%type == richedit) { x-gui Richedit %win > Echo %id $4- | return }
      if (%type == edit) { x-gui Set %win > text %id $x-GUI(Editbox,%win > GetText %id) $+ $4- | return }
      if (%type == list) { x-gui Listbox %win > AddItem %id $4- | return }
      else x-gui Set %win > text %id $4-
      return
    }
    else if (%p == r) {
      if (%type == richedit) { x-gui Richedit %win > Clear %id | return }
      if (%type == list) { x-gui Listbox %win > Clear %id | return }
      else { x-gui Set %win > text %id }
      return
    }
    else if (%p == d) {
      if ($4 !isnum) { error /gid $1- : invalid line number | return }
      if (%type == list) { x-gui Listbox %win > DeleteItem %id $4 | return }
      return
    }
    else if (%p == i) {
      if ($4 !isnum) { error /gid $1- : invalid line number | return }
      if (%type == list) { x-gui Listbox %win > InsertItem %id $4 $5- | return }
      return
    }
    else if (%p == o) {
      if ($4 !isnum) { error /gid $1- : invalid line number | return }
      if (%type == list) { x-gui Listbox %win > UpdateItem %id $4 $5- | return }
      return
    }
    else if (%p == k) {
      if ($4 !isnum) || ($5 !isnum) { error /gid $1- : invalid color | return }
      x-gui Set %win > color %id $4 $5
      return
    }
    else if (%p == s) {
      hdel %win %id
      x-gui Delete %win > %id
      return
    }
    else error /gid $1- : invalid parameter
    return
    ;end of /gid 
  }

  else {
    if (!$1) || (!$window($gui_full_name($1))) { error $gid $1- : window doesn't exist | halt }  
    var %win = $gui_full_name($1)  
    var %id = $2
    var %type = $hget(%win,%id)
    if (%id !isnum) || (!%type) { error $gid $1- : invalid id | halt } 

    if (!$prop) || ($prop == text) {
      if (%type == edit) { return $x-gui(Editbox,%win > GetText %id) }
      if (%type == list) { 
        if ($3 !isnum) { error $gid $1- : invalid line number | halt }
        return $x-gui(Listbox,%win > GetItemText %id $3)
      }
      return $x-gui(Get,%win > text %id)
    }
    else if ($prop == len) {     
      if (%type == list) { 
        if ($3 !isnum) { error $gid $1- : invalid line number | halt }
        return $len($x-gui(Listbox,%win > GetItemText %id $3))
      }
      return 
    }
    else if ($prop == lines) {     
      if (%type == list) return $x-gui(Listbox,%win > GetCount %id)
      return
    }
    else if ($prop == sel) {     
      if (%type == list) return $x-gui(Listbox,%win > GetSelItem %id)
      return
    }
    else if ($prop == extsel) {     
      if (%type == list) return $x-gui(Listbox,%win > GetSelItems %id)
      return
    }
    else if ($prop == seltext) {     
      if (%type == list) return $x-gui(Listbox,%win > GetSelText %id)
      return
    }
    else if ($prop == state) {     
      if (%type == check) || (%type == radio) return $x-gui(Checkbox,%win > GetState %id)
      return
    }
    else if ($prop == pos) {     
      var %pos = $x-gui(Get,%win > pos %id)
      return $calc($gettok(%pos,1,32) - 10) $calc($gettok(%pos,2,32) - 26) $gettok(%pos,3-4,32)
    }
    else if ($prop == visible) {     
      return $x-gui(Get,%win > visible %id)
      return
    }
    else if ($prop == enabled) {     
      return $x-gui(Get,%win > enabled %id)
      return
    }
    else { error $gid $1- : invalid property : $prop | halt }
    ;end of $gid
  }
}