Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

help.tcl

00001 # Copyright (C) 1997-2004 The CDG Team <cdg@nats.informatik.uni-hamburg.de> 00002 # 00003 # This file is free software; as a special exception the author gives 00004 # unlimited permission to copy and/or distribute it, with or without 00005 # modifications, as long as this notice is preserved. 00006 # 00007 # This program is distributed in the hope that it will be useful, but 00008 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 00009 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00010 00011 ## ---------------------------------------------------------------------------- 00012 ## CdgHelp - a status line. 00013 ## This class allows to display a help message in a status line whenever 00014 ## the mouse pointer enters a widget. 00015 ## 00016 ## \author Michael Daum (see also AUTHORS and THANKS for more) 00017 ## $Id: help.tcl,v 1.7 2004/02/25 14:40:42 micha Exp $ 00018 ## ---------------------------------------------------------------------------- 00019 class CdgHelp { 00020 inherit itk::Widget 00021 00022 # public methods 00023 public method sethelpstr {w text args}; ## \type TclCommand, TclString, TclList 00024 public method gethelpstr {w}; ## \type TclCommand 00025 public method unsethelpstr {w}; ## \type TclCommand 00026 public method showstr {text}; ## \type TclString 00027 public method show {w}; ## \type TclCommand 00028 public method clear {} 00029 00030 constructor {args} {}; ## \type TclList 00031 00032 # private variables 00033 ## a hash mapping widgets to the help message that should be displayed. 00034 private variable _messageOfWidget; ## \type TclArray 00035 }; 00036 00037 ## ---------------------------------------------------------------------------- 00038 ## constructor 00039 ## ---------------------------------------------------------------------------- 00040 body CdgHelp::constructor {args} { 00041 00042 itk_component add label { 00043 label $itk_interior.label -text "" \ 00044 -anchor w \ 00045 -borderwidth 0 00046 } { 00047 00048 keep -font -background -relief -cursor 00049 } 00050 00051 # packing 00052 pack $itk_component(label) -fill both -expand 1 00053 00054 eval itk_initialize $args 00055 } 00056 00057 ## ---------------------------------------------------------------------------- 00058 ## set the displayed text when the mouse enters the widget. 00059 ## install two events &lt;Enter&gt; and &lt;Leave&gt; for the widget 00060 ## ---------------------------------------------------------------------------- 00061 body CdgHelp::sethelpstr {w text args} { 00062 00063 if {![info exists _messageOfWidget($w)]} { 00064 set no [scan $w "%s %d" base index] 00065 set cl [winfo class $base] 00066 if {$no == 2 && $cl == "Menu"} { 00067 bind $base <Motion> [code $this show %W] 00068 bind $base <Leave> [code $this clear] 00069 } else { 00070 bind $w <Enter> [code $this show %W] 00071 bind $w <Leave> [code $this clear] 00072 } 00073 } 00074 set _messageOfWidget($w) $text 00075 00076 if {$args != ""} { 00077 eval sethelpstr $args 00078 } 00079 } 00080 00081 ## ---------------------------------------------------------------------------- 00082 ## unset the array-entry, remove the &lt;Enter&gt;- and &lt;Leave&gt;-bindings 00083 ## ---------------------------------------------------------------------------- 00084 body CdgHelp::unsethelpstr {w} { 00085 00086 if {![info exists _messageOfWidget($w)]} { 00087 unset _messageOfWidget($w) 00088 bind $w <Enter> {} 00089 bind $w <Leave> {} 00090 } 00091 } 00092 00093 ## ---------------------------------------------------------------------------- 00094 ## returns the helpstring of a given widget 00095 ## ---------------------------------------------------------------------------- 00096 body CdgHelp::gethelpstr {w} { 00097 return $_messageOfWidget($w) 00098 } 00099 00100 ## ---------------------------------------------------------------------------- 00101 ## displays the a noregistered message 00102 ## ---------------------------------------------------------------------------- 00103 body CdgHelp::showstr {text} { 00104 $itk_component(label) configure -text $text 00105 } 00106 00107 ## ---------------------------------------------------------------------------- 00108 ## displays the associated helpmessage 00109 ## ---------------------------------------------------------------------------- 00110 body CdgHelp::show {w} { 00111 00112 if {[winfo class $w] == "Menu"} { 00113 set index [$w index active] 00114 append w " $index" 00115 } 00116 set text "" 00117 catch {set text $_messageOfWidget($w)} 00118 $itk_component(label) configure -text $text 00119 } 00120 00121 ## ---------------------------------------------------------------------------- 00122 ## clear the display 00123 ## ---------------------------------------------------------------------------- 00124 body CdgHelp::clear {} { 00125 $itk_component(label) configure -text "" 00126 } 00127

XCDG 0.95 (20 Oct 2004)