alias tema-yonetim {
  gui Tema-Yonetim Tema-Yonetim
}

alias dialoggui_tema-yonetim {
  gui_size tema-yonetim 200 165 230 250  
  gui -ly tema-yonetim
  gui_title tema-yonetim Tema Seçimleri
  gui_text tema-yonetim 1 5 5 120 16 > Tema Listesi:
  gui_list tema-yonetim 2 5 22 130 184 size vsbar autovs 
  gui_button tema-yonetim 3 145 22 60 24 > Kapat
  gui_button tema-yonetim 4 145 52 60 24 > İptal
  gui_button tema-yonetim 5 145 142 60 24 > Sil

  %blizzard_gui_tmp_skin = %blizzard_gui_skin
  refresh_skin_list
}
on *:SIGNAL:GUI: {
  if ($1 == tema-yonetim) {
    if ($2 == closed) {
      if ($hget(tmp_gui_skins)) {
        if ($isfile($hget(tmp_gui_skins,file))) .remove $hget(tmp_gui_skins,file)
        .hfree tmp_gui_skins        
      }
      unset %blizzard_gui_tmp_skin
    }
    if ($2 == close) {
      if (%blizzard_gui_skin != %blizzard_gui_tmp_skin) {
        %blizzard_gui_skin = %blizzard_gui_tmp_skin
        load_gui
      }
      unset %blizzard_gui_tmp_skin
      gui -c tema-yonetim     
    }
    if ($2 == sclick) {
      if ($3 == 3) {
        gui -c tema-yonetim
      }
      else if ($3 == 4) {
        if (%blizzard_gui_skin != %blizzard_gui_tmp_skin) {
          %blizzard_gui_skin = %blizzard_gui_tmp_skin
          load_gui
        }      
        gui -c tema-yonetim        
      }

      else if ($3 == 2) {
        if ($gid(tema-yonetim,2).sel == 1) gid -b tema-yonetim 5
        else gid -e tema-yonetim 5

        if (%blizzard_gui_skin != $gid(tema-yonetim,2).seltext) {
          %blizzard_gui_skin = $gid(tema-yonetim,2).seltext
          load_gui
        }
      }
      else if ($3 == 8) {
        get_list
      }
      else if ($3 == 7) {
        gid -e tema-yonetim 9
      }
      else if ($3 == 9) {
        download_skin $gid(tema-yonetim,7).seltext
        gid -d tema-yonetim 7 $gid(tema-yonetim,7).sel
      }
      else if ($3 == 5) {
        %blizzard_gui_skin = Normal
        %blizzard_gui_tmp_skin = Normal
        .remove $+(",%blizzard_gui_skin_dir $+ $gid(tema-yonetim,2).seltext $+ .png,")
        gid -d tema-yonetim 2 $gid(tema-yonetim,2).sel
        gid -b tema-yonetim 5
        gid -c tema-yonetim 2 1
        load_gui
      }

    }
  }
}

alias -l refresh_skin_list {
  gid -r tema-yonetim 2
  gid -a tema-yonetim 2 Normal 
  var %i = $findfile(%blizzard_gui_skin_dir,*.*,0,0,if ($right($1-,4) == .png) gid -a tema-yonetim 2 $remove($nopath($1-),.png))
  %i = 1
  while (%i <= $gid(tema-yonetim,2).lines) {
    if ($gid(tema-yonetim,2,%i) == %blizzard_gui_skin) { 
      gid -c tema-yonetim 2 %i
      if ($gid(tema-yonetim,2).sel == 1) gid -b tema-yonetim 5
      break
    }
    else if (%i == $gid(tema-yonetim,2).lines) {
      gid -c tema-yonetim 2 1    
      gid -b tema-yonetim 5
    }
    inc %i
  }
}
alias -l x-gui {
  var %r = $dll($+(",$scriptdir $+ x-GUI.dll,"),$1,$2-) 
  if ($isid) return %r
}

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

alias gui {
  if (!$gui_is_loaded) {
    error 2GUI doğru yüklenemedi! - /GUI komutunu kullanamazsınız! Öncelikle /load_gui komutunu girerek yükleme yapınız!
    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- : Geçersiz Özellik!
        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- Böyle bir dialog yok!
          return
        }
        else if (%p == d) {
          if ($window(%win)) gui_set $2 disable_close 1
          else { 
            error /gui $1- Böyle bir dialog yok!
            return
          }
        }
        else if (%p == e) {
          if ($window(%win)) gui_set $2 disable_close 0
          else { 
            error /gui $1- Böyle bir dialog yok! 
            return
          }
        }
        else if (%p == l) {
          if ($window(%win)) gui_set $2 disable_min 1
          else { 
            error /gui $1- Böyle bir dialog yok!
            return
          }
        }
        else if (%p == m) {
          if ($window(%win)) gui_set $2 disable_min 0
          else { 
            error /gui $1- Böyle bir dialog yok!
            return
          }
        }
        else if (%p == x) {
          if ($window(%win)) gui_set $2 no_exit_on_close 0
          else { 
            error /gui $1- Böyle bir dialog yok!
            return
          }
        }
        else if (%p == y) {
          if ($window(%win)) gui_set $2 no_exit_on_close 1
          else { 
            error /gui $1- Böyle bir dialog yok!
            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 $+ dialogu zaten açık!
      return
    }  
    if ($hget(%win)) hfree %win
    hmake %win 10
    hadd %win close_hover 0
    hadd %win min_hover 0
    hadd %win title Oto İdentify
    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($+(dialoggui_,%table))) $+(dialoggui_,%table)
    paint_gui %win
    .signal -n gui $1 init
  }
}


alias gui_is_loaded return $hget(gui,loaded)



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_normal_gui
    if (%blizzard_gui_skin) && (%blizzard_gui_skin != Normal) Kötü Tema Dosyası : $gui_skin_dir(%blizzard_gui_skin $+ .png) - Normal Temaya Dönüldü -
  }

  if (!$isfile($+(",$scriptdir $+ WinRgn.dll,"))) {
    error DLL Hatası : WinRgn.dll Hatası!
    return 
  }
  if (!$isfile($+(",$scriptdir $+ x-GUI.dll,"))) {
    error DLL Hatası : x-GUI.dll Hatası!
    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_normal_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
}


alias -l error {
  echo -s  $+ $color(info) $+ $timestamp [Dialog Açma Hatası:] $1-
}


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


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-
  }
}


alias -l gui_close {
  var %win = $gui_full_name($1)
  if ($hget(%win)) hfree %win
  if ($window(%win)) window -c %win
  .signal $1 Dialogu Kapatıldı!
}


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- : Geçersiz isim! | return }
  }
  else  { error /gui_set $1- : Penceresi Açılamadı! | return }
  paint_gui %win
}


alias gui_short_name {
  if ($right($1,44) ==                                         -gui) return $mid($1,2,$calc($len($1) -45))
}


alias gui_full_name {
  return @ $+ $1 $+ $str($chr(160),40) $+ -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) Arial -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 : Geçersiz 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
}

on *:LOAD: {
  set %blizzard_gui_skin_dir $scriptdir $+ skins\
  set %blizzard_gui_skin Anatema
  echo -a Bu Dialog için belirlenen Skin Resim Uzantısı $scriptdir $+ skins\
  echo -a Siz elinizle bu uzantıyı belirlemek istiyorsanız /set %blizzard_gui_skin_dir komutunu ve sonra uzantısını yazarak belirleyebilirsiniz.
  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
    }
  }
}


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 $1 Penceresi Açılamadı!
    return
  }
  hadd %win title $2-
  paint_gui %win
}
alias gui_size {
  var %win = $gui_full_name($1)  
  if (!$window(%win)) {
    error $1 Penceresi Açılamadı!
    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- : $1 Penceresi Açılamadı!
    return
  }
  if ($2 !isnum) {
    error /gui_edit $1- : Geçersiz ID
    return
  }
  if (!$add_control(%win,$2,edit)) {
    error /gui_edit $1- : Bu ID numarası zaten var!
    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 > 10
}
alias gui_text {
  var %win = $gui_full_name($1)
  if (!$window(%win)) {
    error /gui_text $1- : $1 Penceresi Açılamadı!
    return
  }
  if ($2 !isnum) {
    error /gui_text $1- : Geçersiz ID
    return
  }
  if (!$add_control(%win,$2,text)) {
    error /gui_text $1- : Bu ID numarası var!
    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 > 9
}

alias gui_list {
  var %win = $gui_full_name($1)
  if (!$window(%win)) {
    error /gui_list $1- : $1 Penceresi Açılamadı!
    return
  }
  if ($2 !isnum) {
    error /gui_list $1- : Geçersiz ID
    return
  }
  if (!$add_control(%win,$2,list)) {
    error /gui_list $1- : Bu ID numarası var!
    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 > 10
}

alias gui_richedit {
  var %win = $gui_full_name($1)
  if (!$window(%win)) {
    error /gui_richedit $1- : $1 Penceresi Açılamadı!
    return
  }
  if ($2 !isnum) {
    error /gui_richedit $1- : Geçersiz ID
    return
  }
  if (!$add_control(%win,$2,richedit)) {
    error /gui_richedit $1- : Bu ID numarası zaten var!
    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 > 10
}

alias gui_button {
  var %win = $gui_full_name($1)
  if (!$window(%win)) {
    error /gui_button $1- : $1 Penceresi Açılamadı!
    return
  }
  if ($2 !isnum) {
    error /gui_button $1- : Geçersiz ID
    return
  }
  if (!$add_control(%win,$2,button)) {
    error /gui_button $1- : Bu ID numarası zaten var!
    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 > 10
}

alias gui_check {
  var %win = $gui_full_name($1)
  if (!$window(%win)) {
    error /gui_check $1- : $1 Penceresi Açılamadı!
    return
  }
  if ($2 !isnum) {
    error /gui_check $1- : Geçersiz ID
    return
  }
  if (!$add_control(%win,$2,check)) {
    error /gui_check $1- : Bu ID numarası zaten var!
    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 > 9
}

alias gui_radio {
  var %win = $gui_full_name($1)
  if (!$window(%win)) {
    error /gui_radio $1- : $1 Penceresi Açılamadı!
    return
  }
  if ($2 !isnum) {
    error /gui_radio $1- : Geçersiz ID
    return
  }
  if (!$add_control(%win,$2,radio)) {
    error /gui_radio $1- : Bu ID numarası zaten var!
    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
}

alias gid {
  if (!$isid) {
    if ($left($1,1) != -) || ($len($1) != 2) { error /gid $1- : Geçersiz Parametre | return }
    if (!$2) || (!$window($gui_full_name($2))) { error /gid $1- : Böyle bir dialog yok! | return }  
    var %win = $gui_full_name($2)  
    var %id = $3
    var %type = $hget(%win,%id)
    if ($3 !isnum) || (!%type) { error /gid $1- : Geçersiz 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- : Geçersiz satır numarası
        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- : Geçersiz satır numarası | return }
      if (%type == list) { x-gui Listbox %win > DeleteItem %id $4 | return }
      return
    }
    else if (%p == i) {
      if ($4 !isnum) { error /gid $1- : Geçersiz satır numarası | return }
      if (%type == list) { x-gui Listbox %win > InsertItem %id $4 $5- | return }
      return
    }
    else if (%p == o) {
      if ($4 !isnum) { error /gid $1- : Geçersiz satır numarası | 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- : Geçersiz Renk | 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- : Geçersiz Parametre
    return
    ;end of /gid 
  }

  else {
    if (!$1) || (!$window($gui_full_name($1))) { error $gid $1- : Böyle bir dialog yok! | halt }  
    var %win = $gui_full_name($1)  
    var %id = $2
    var %type = $hget(%win,%id)
    if (%id !isnum) || (!%type) { error $gid $1- : Geçersiz 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- : Geçersiz satır numarası | 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- : Geçersiz satır numarası | 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- : Geçersiz Özellik : $prop | halt }
    ;end of $gid
  }
}
