home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 May / PCWorld_2002-05_cd.bin / Software / TemaCD / activetcltk / ActiveTcl8.3.4.1-8.win32-ix86.exe / ActiveTcl8.3.4.1-win32-ix86 / lib / bwidget1.3.0 / passwddlg.tcl < prev    next >
Encoding:
Text File  |  2001-10-22  |  6.3 KB  |  184 lines

  1. # -----------------------------------------------------------------------------
  2. #  passwddlg.tcl
  3. #  This file is part of Unifix BWidget Toolkit
  4. #   by Stephane Lavirotte (Stephane.Lavirotte@sophia.inria.fr)
  5. #  $Id: passwddlg.tcl,v 1.6 2001/09/06 19:50:41 andreas_kupries Exp $
  6. # -----------------------------------------------------------------------------
  7. #  Index of commands:
  8. #     - PasswdDlg::create
  9. #     - PasswdDlg::configure
  10. #     - PasswdDlg::cget
  11. #     - PasswdDlg::_verifonlogin
  12. #     - PasswdDlg::_verifonpasswd
  13. #     - PasswdDlg::_max
  14. #------------------------------------------------------------------------------
  15.  
  16. namespace eval PasswdDlg {
  17.     Dialog::use
  18.     LabelEntry::use
  19.  
  20.     Widget::bwinclude PasswdDlg Dialog :cmd \
  21.         remove     {-image -bitmap -side -default -cancel -separator} \
  22.         initialize {-modal local -anchor c}
  23.     
  24.     Widget::bwinclude PasswdDlg LabelEntry .frame.lablog \
  25.         remove [list -command -justify -name -show -side            \
  26.         -state -takefocus -width -xscrollcommand -padx -pady    \
  27.         -dragenabled -dragendcmd -dragevent -draginitcmd    \
  28.         -dragtype -dropenabled -dropcmd -dropovercmd -droptypes    \
  29.         ] \
  30.         prefix [list login -editable -helptext -helpvar -label      \
  31.         -text -textvariable -underline                \
  32.         ] \
  33.         initialize [list -relief sunken -borderwidth 2        \
  34.         -labelanchor w -width 15 -loginlabel "Login"        \
  35.         ]
  36.     
  37.     Widget::bwinclude PasswdDlg LabelEntry .frame.labpass        \
  38.         remove [list -command -width -show -side -takefocus        \
  39.         -xscrollcommand -dragenabled -dragendcmd -dragevent    \
  40.         -draginitcmd -dragtype -dropenabled -dropcmd        \
  41.         -dropovercmd -droptypes -justify -padx -pady -name    \
  42.         ] \
  43.         prefix [list passwd -editable -helptext -helpvar -label    \
  44.         -state -text -textvariable -underline            \
  45.         ] \
  46.         initialize [list -relief sunken -borderwidth 2        \
  47.         -labelanchor w -width 15 -passwdlabel "Password"    \
  48.         ]
  49.     
  50.     Widget::declare PasswdDlg {
  51.         {-type        Enum       ok           0 {ok okcancel}}
  52.         {-labelwidth  TkResource -1           0 {label -width}}
  53.         {-command     String     ""           0}
  54.     }
  55.  
  56.     proc ::PasswdDlg { path args } { return [eval PasswdDlg::create $path $args] }
  57.     proc use {} {}
  58. }
  59.  
  60.  
  61. # -----------------------------------------------------------------------------
  62. #  Command PasswdDlg::create
  63. # -----------------------------------------------------------------------------
  64. proc PasswdDlg::create { path args } {
  65.  
  66.     array set maps [list PasswdDlg {} :cmd {} .frame.lablog {} \
  67.         .frame.labpass {}]
  68.     array set maps [Widget::parseArgs PasswdDlg $args]
  69.  
  70.     Widget::initFromODB PasswdDlg "$path#PasswdDlg" $maps(PasswdDlg)
  71.  
  72.     # Extract the PasswdDlg megawidget options (those that don't map to a
  73.     # subwidget)
  74.     set type      [Widget::cget "$path#PasswdDlg" -type]
  75.     set cmd       [Widget::cget "$path#PasswdDlg" -command]
  76.  
  77.     set defb -1
  78.     set canb -1
  79.     switch -- $type {
  80.         ok        { set lbut {ok}; set defb 0 }
  81.         okcancel  { set lbut {ok cancel} ; set defb 0; set canb 1 }
  82.     }
  83.  
  84.     eval Dialog::create $path $maps(:cmd) -class PasswdDlg \
  85.         -image [Bitmap::get passwd] -side bottom -default $defb -cancel $canb
  86.     foreach but $lbut {
  87.         if { $but == "ok" && $cmd != "" } {
  88.             Dialog::add $path -text $but -name $but -command $cmd
  89.         } else {
  90.             Dialog::add $path -text $but -name $but
  91.         }
  92.     }
  93.  
  94.     set frame [Dialog::getframe $path]
  95. #    bind $path  <Return>  ""
  96.     bind $frame <Destroy> "Widget::destroy $path#PasswdDlg"
  97.  
  98.     set lablog [eval LabelEntry::create $frame.lablog $maps(.frame.lablog) \
  99.         -name login -dragenabled 0 -dropenabled 0 \
  100.         -command \"PasswdDlg::_verifonpasswd $path $frame.labpass\"]
  101.  
  102.     set labpass [eval LabelEntry::create $frame.labpass $maps(.frame.labpass) \
  103.         -name password -show "*" -dragenabled 0 -dropenabled 0 \
  104.         -command \"PasswdDlg::_verifonlogin $path $frame.lablog\"]
  105.  
  106.     # compute label width -- TODO: this should probably not override the
  107.     # cmdline arg
  108.     set loglabel  [$lablog cget -label]
  109.     set passlabel [$labpass cget -label]
  110.     set labwidth  [_max [string length $loglabel] [string length $passlabel]]
  111.     incr labwidth 1
  112.     $lablog  configure -labelwidth $labwidth
  113.     $labpass configure -labelwidth $labwidth
  114.  
  115.     proc ::$path { cmd args } "return \[eval PasswdDlg::\$cmd $path \$args\]"
  116.  
  117.     pack  $frame.lablog $frame.labpass -fill x -expand 1
  118.  
  119.     # added by bach@mwgdna.com
  120.     #  give focus to loginlabel unless the state is disabled
  121.     if {[$lablog cget -editable]} {
  122.     focus $frame.lablog.e
  123.     } else {
  124.     focus $frame.labpass.e
  125.     }
  126.     set res [Dialog::draw $path]
  127.  
  128.     if { $res == 0 } {
  129.         set res [list [$lablog.e cget -text] [$labpass.e cget -text]]
  130.     } else {
  131.         set res [list]
  132.     }
  133.     Widget::destroy "$path#PasswdDlg"
  134.     destroy $path
  135.  
  136.     return $res
  137. }
  138.  
  139. # -----------------------------------------------------------------------------
  140. #  Command PasswdDlg::configure
  141. # -----------------------------------------------------------------------------
  142.  
  143. proc PasswdDlg::configure { path args } {
  144.     set res [Widget::configure "$path#PasswdDlg" $args]
  145. }
  146.  
  147. # -----------------------------------------------------------------------------
  148. #  Command PasswdDlg::cget
  149. # -----------------------------------------------------------------------------
  150.  
  151. proc PasswdDlg::cget { path option } {
  152.     return [Widget::cget "$path#PasswdDlg" $option]
  153. }
  154.  
  155.  
  156. # -----------------------------------------------------------------------------
  157. #  Command PasswdDlg::_verifonlogin
  158. # -----------------------------------------------------------------------------
  159. proc PasswdDlg::_verifonlogin { path labpass } {
  160.     if { [$labpass.e cget -text] == "" } {
  161.         focus $labpass
  162.     } else {
  163.         Dialog::setfocus $path default
  164.     }
  165. }
  166.  
  167. # -----------------------------------------------------------------------------
  168. #  Command PasswdDlg::_verifonpasswd
  169. # -----------------------------------------------------------------------------
  170. proc PasswdDlg::_verifonpasswd { path lablog } {
  171.     if { [$lablog.e cget -text] == "" } {
  172.         focus $lablog
  173.     } else {
  174.         Dialog::setfocus $path default
  175.     }
  176. }
  177.  
  178. # -----------------------------------------------------------------------------
  179. #  Command PasswdDlg::_max
  180. # -----------------------------------------------------------------------------
  181. proc PasswdDlg::_max { val1 val2 } { 
  182.     return [expr {($val1 > $val2) ? ($val1) : ($val2)}] 
  183. }
  184.