summaryrefslogtreecommitdiff
path: root/libgui/library/treetable.tcl
blob: 8ba9807b8a0fb037715ce04157275168d46d5c4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# treetable.tcl - some treetable bindings; from S-N.
# Copyright (C) 1997 Cygnus Solutions.

proc multix_treetable_bindings {t} {
  # The keybindings to the treetable are compatible with those of
  # listbox.
  bind $t <1> {
    if [winfo exists %W] {
      tkListboxBeginSelect %W [%W index @%x,%y]
    }
  }

  bind $t <B1-Motion> {
    set tkPriv(x) %x
    set tkPriv(y) %y
    tkListboxMotion %W [%W index @%x,%y]
  }
  bind $t <ButtonRelease-1> {
    tkCancelRepeat
    %W activate @%x,%y
  }
  bind $t <Shift-1> {
    tkListboxBeginExtend %W [%W index @%x,%y]
  }
  bind $t <Control-1> {
    tkListboxBeginToggle %W [%W index @%x,%y]
  }
  bind $t <B1-Leave> {
    set tkPriv(x) %x
    set tkPriv(y) %y
    tkListboxAutoScan %W
  }
  bind $t <B1-Enter> {
    tkCancelRepeat
  }

  bind $t <Up> {
    tkListboxUpDown %W -1
  }
  bind $t <Shift-Up> {
    tkListboxExtendUpDown %W -1
  }
  bind $t <Down> {
    tkListboxUpDown %W 1
  }
  bind $t <Shift-Down> {
    tkListboxExtendUpDown %W 1
  }
  bind $t <Left> {
    %W xview scroll -1 units
  }
  bind $t <Control-Left> {
    %W xview scroll -1 pages
  }
  bind $t <Right> {
    %W xview scroll 1 units
  }
  bind $t <Control-Right> {
    %W xview scroll 1 pages
  }
  bind $t <Prior> {
    %W yview scroll -1 pages
    %W activate @0,0
  }
  bind $t <Next> {
    %W yview scroll 1 pages
    %W activate @0,0
  }
  bind $t <Control-Prior> {
    %W xview scroll -1 pages
  }
  bind $t <Control-Next> {
    %W xview scroll 1 pages
  }
  bind $t <Home> {
    %W xview moveto 0
  }
  bind $t <End> {
    %W xview moveto 1
  }
  bind $t <Control-Home> {
    %W activate 0
    %W see 0
    %W selection clear 0 end
    %W selection set 0
  }
  bind $t <Shift-Control-Home> {
    tkListboxDataExtend %W 0
  }
  bind $t <Control-End> {
    %W activate end
    %W see end
    %W selection clear 0 end
    %W selection set end
  }
  bind $t <Shift-Control-End> {
    tkListboxDataExtend %W end
  }
  bind $t <F16> {
    if {[selection own -displayof %W] == "%W"} {
      clipboard clear -displayof %W
      clipboard append -displayof %W [selection get -displayof %W]
    }
  }
  bind $t <space> {
    tkListboxBeginSelect %W [%W index active]
  }
  bind $t <Select> {
    tkListboxBeginSelect %W [%W index active]
  }
  bind $t <Control-Shift-space> {
    tkListboxBeginExtend %W [%W index active]
  }
  bind $t <Shift-Select> {
    tkListboxBeginExtend %W [%W index active]
  }
  bind $t <Escape> {
    tkListboxCancel %W
  }
  bind $t <Control-slash> {
    tkListboxSelectAll %W
  }
  bind $t <Control-backslash> {
    if {[%W cget -selectmode] != "browse"} {
      %W selection clear 0 end
    }
  }

  bind $t <3> {
    %W scan mark %x %y
  }
  bind $t <B3-Motion> {
    %W scan dragto %x %y
  }
  
  # Explicitly exclude traversal keys.
  bind $t <Tab> {;}
  bind $t <Shift-Tab> {;}

  # Other bindings added to default listbox bindings.
  bind $t <KeyPress> {multix_tree_table_search_region %W %A}
  bind $t <Any-F27> 		[bind $t <Home>]; # Sun Home
  bind $t <Any-R13> 		[bind $t <End>]; # Sun End
  bind $t <Any-R15> 		[bind $t <Next>]; # Sun Next
  bind $t <Any-R9> 		[bind $t <Prior>]; # Sun Prior
}

proc multix_tree_table_search_in_widget {w a beg {end end}} {
  if {[$w size] > 20000} {
    $w config -cursor watch
    update idletasks
  }
  set res [$w search -nocase -begins $a $beg $end]
  $w config -cursor {}
  if {$res == ""} {
    return -1
  }
  $w activate $res
  return $res
}

proc multix_tree_table_search_region {w a} {
  if {[string compare $a ""] == 0} {
    return
  }

  upvar #0 $w-pat pat

  append pat $a
  set srch $pat
  set off [$w index active]
  if {[string compare $off ""] == 0} {
    set sel 0
  } else {
    set sel [expr $off + 1]
  }
  # Search from the selection!
  set off [multix_tree_table_search_in_widget $w $srch $sel]

  if {$off == -1 && $sel != 0} {
    # 	Search until the selection!
    set off [multix_tree_table_search_in_widget $w $srch 0 $sel]
  }
  if {$off == -1} {
    if {[string length $pat] > 1} {
      set pat $a
      set srch $pat

      # Search from the selection!
      set off [multix_tree_table_search_in_widget $w $srch $sel]
      if {$off == -1} {
	# 	Search until the selection!
	set off [multix_tree_table_search_in_widget $w $srch 0 $sel]
      }
    }
    if {$off == -1} {
      set pat ""
      bell -displayof $w
      $w selection clear 0 end
      return
    }
  }
  $w activate $off
  $w activate $off
  $w yview see $off
}