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 ## \comment 00012 itk::usual ListDialog { 00013 keep -background -cursor -foreground 00014 } 00015 ## \endcomment 00016 00017 ## ---------------------------------------------------------------------------- 00018 ## ListDialog - a dialog embedding a list. 00019 ## This dialog is used to temporarily display a list of objects. In YadaRanking 00020 ## data files with errors are displayed after a load action. 00021 ## 00022 ## \author Michael Daum 00023 ## 00024 ## $Id: ListDialog.tcl,v 1.7 2004/02/25 14:42:08 micha Exp $ 00025 ## ---------------------------------------------------------------------------- 00026 class ListDialog { 00027 inherit iwidgets::Dialog 00028 00029 00030 public method activate {} 00031 public method insert {component args}; ## \type TclString, TclList 00032 public method get {} 00033 00034 constructor {args} {}; ## \type TclList 00035 00036 private method _selectionAction {} 00037 private method _okAction {} 00038 private method _cancelAction {} 00039 00040 ## title of the dialog 00041 public variable title "" 00042 }; 00043 00044 ## ---------------------------------------------------------------------------- 00045 ## constructor 00046 ## ---------------------------------------------------------------------------- 00047 body ListDialog::constructor {args} { 00048 00049 # reduce buttons 00050 hide "Help" 00051 hide "Apply" 00052 00053 set childsite [childsite] 00054 00055 itk_component add label { 00056 label $childsite.label 00057 } { 00058 keep -cursor -foreground 00059 rename -text -labeltext labelText Text 00060 } 00061 00062 itk_component add list { 00063 iwidgets::scrolledlistbox $childsite.list \ 00064 -vscrollmode static \ 00065 -hscrollmode dynamic \ 00066 -selectioncommand [code $this _selectionAction] \ 00067 -dblclickcommand [code $this _okAction] \ 00068 -selectmode single 00069 } { 00070 usual 00071 } 00072 00073 pack $itk_component(label) \ 00074 -side top -expand 0 -fill x -pady 5 -anchor nw 00075 pack $itk_component(list) \ 00076 -side top -expand 1 -fill both 00077 00078 buttonconfigure OK -command [code $this _okAction] 00079 buttonconfigure Cancel -command [code $this _cancelAction] 00080 00081 eval itk_initialize $args 00082 00083 00084 [[component list] component listbox] configure -takefocus 0 00085 } 00086 00087 ## ---------------------------------------------------------------------------- 00088 ## selection slot. 00089 ## When one of the listed items is selected then this action is fired. 00090 ## \todo not yet implemented 00091 ## ---------------------------------------------------------------------------- 00092 body ListDialog::_selectionAction {} { 00093 } 00094 00095 ## ---------------------------------------------------------------------------- 00096 ## ok slot. 00097 ## This method is called when the OK button is pressed or a listed item 00098 ## is double-clicked. Afterwards the dialog is deactivated returning a value 00099 ## of 1 to the activating call. 00100 ## \see activate() 00101 ## ---------------------------------------------------------------------------- 00102 body ListDialog::_okAction {} { 00103 deactivate 1 00104 } 00105 00106 ## ---------------------------------------------------------------------------- 00107 ## cancel slot. 00108 ## This method is deactivating the dialog returning a value of 0 to the call 00109 ## that opened the dialog. 00110 ## \see activate() 00111 ## ---------------------------------------------------------------------------- 00112 body ListDialog::_cancelAction {} { 00113 deactivate 0 00114 } 00115 00116 ## ---------------------------------------------------------------------------- 00117 ## activate the dialog object. 00118 ## This method calls Shell:activate() after centering the dialog on the 00119 ## master of this widget. 00120 ## \returns 0 or 1 depending on the users selection. 00121 ## \see _okAction(), _cancelAction() 00122 ## ---------------------------------------------------------------------------- 00123 body ListDialog::activate {} { 00124 center $itk_option(-master) 00125 00126 return [join [Shell::activate]] 00127 } 00128 00129 ## ---------------------------------------------------------------------------- 00130 ## delegate insert to a component. 00131 ## This method is mainly used to insert an item to the list component of this 00132 ## widget. 00133 ## \param component the name of the component, i.e. "list" 00134 ## \param args the list of things to be inserted into the \a component 00135 ## ---------------------------------------------------------------------------- 00136 body ListDialog::insert {component args} { 00137 eval $itk_component($component) insert $args 00138 } 00139 00140 ## ---------------------------------------------------------------------------- 00141 ## get the current selection. 00142 ## This method returns the selected items from the list component. 00143 ## \returns a list of list items.. 00144 ## ---------------------------------------------------------------------------- 00145 body ListDialog::get {} { 00146 set result "" 00147 foreach index [$itk_component(list) curselection] { 00148 lappend result [$itk_component(list) get $index] 00149 } 00150 00151 return $result 00152 } 00153 00154 ## ---------------------------------------------------------------------------- 00155 ## -title 00156 ## ---------------------------------------------------------------------------- 00157 configbody ListDialog::title { 00158 wm title $itk_component(hull) $itk_option(-title) 00159 } 00160 00161