summaryrefslogtreecommitdiff
path: root/gdb/gdbtk/library/mempref.itb
blob: c2617cf20f700033c1d0d3068103f9bf3cc3e10c (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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# Memory display preferences window for Insight.
# Copyright 1998, 1999, 2002, 2003 Red Hat
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License (GPL) as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.


# ------------------------------------------------------------------
#  METHOD:  constructor - build the dialog
# ------------------------------------------------------------------
itcl::body MemPref::constructor {args} {

  window_name "Memory Preferences"

  eval itk_initialize $args
  
  if {$float_size == ""} {
    set float_size [gdb_eval sizeof(float)]
    set double_size [gdb_eval sizeof(double)]
  }
  
  if {[string compare $format f] == 0} {
    set gformat x
    set format_disabled 1
    if {$size == $float_size} {
      set gsize 3
    } elseif {$size == $double_size} {
      set gsize 5
    }
  } else {
    set gsize $size
    set gformat $format
  }
  
  set gnumbytes $numbytes
  set gbpr $bpr
  set gascii $ascii
  set gascii_char $ascii_char
  
  build_win
  
  if {$format_disabled} {
    set format_disabled 0
    disable_format
  }
  
  wm resizable [winfo toplevel $itk_interior] 0 0
}

# ------------------------------------------------------------------
#  METHOD:  destructor - destroy the dialog
# ------------------------------------------------------------------
itcl::body MemPref::destructor {} {
  trace vdelete [scope gnumbytes] w [code $this check_numbytes]
}

# ------------------------------------------------------------------
#  METHOD:  build_win - build the dialog
# ------------------------------------------------------------------
itcl::body MemPref::build_win {} {

  frame $itk_interior.f
  set f [frame $itk_interior.f.a]
  frame $itk_interior.f.b

  # SIZE
  Labelledframe $f.f1 -anchor nw -text Size
  set fr [$f.f1 get_frame]

  set Widgets(rb-Byte) [radiobutton $fr.1 -variable [scope gsize] -text Byte \
			  -value 1 -command [code $this enable_format]]
  set Widgets(rb-half_word) [radiobutton $fr.2 -variable [scope gsize] -text "Half Word" \
			       -value 2 -command [code $this enable_format]]
  set Widgets(rb-word) [radiobutton $fr.4 -variable [scope gsize] -text Word \
			  -value 4 -command [code $this enable_format]]
  set Widgets(rb-d_word) [radiobutton $fr.8 -variable [scope gsize] -text "Double Word" \
			    -value 8 -command [code $this enable_format]]
  set Widgets(rb-float) [radiobutton $fr.f -variable [scope gsize] -text Float \
			   -value 3 -command [code $this disable_format]]
  set Widgets(rb-d_float) [radiobutton $fr.d -variable [scope gsize] -text "Double Float" \
			     -value 5 -command [code $this disable_format]]
  grid $fr.1 $fr.4 $fr.f -sticky w -padx 4
  grid $fr.2 $fr.8 $fr.d -sticky w -padx 4

  # FORMAT
  Labelledframe $f.f2 -anchor nw -text Format
  set fr [$f.f2 get_frame]
  set Widgets(rb-binary) [radiobutton $fr.1 -variable [scope gformat] \
			    -text Binary -value t]
  set Widgets(rb-octal) [radiobutton $fr.2 -variable [scope gformat] \
			   -text Octal -value o]
  set Widgets(rb-hex) [radiobutton $fr.3 -variable [scope gformat] \
			 -text Hex -value x]
  set Widgets(rb-signed_dec) [radiobutton $fr.4 -variable [scope gformat] \
				-text "Signed Decimal" -value d]
  set Widgets(rb-unsign_dec) [radiobutton $fr.5 -variable [scope gformat] \
				-text "Unsigned Decimal" -value u]

  grid $fr.1 $fr.2 $fr.3 -sticky w -padx 4
  grid $fr.4 $fr.5 x -sticky w -padx 4

  # TOTAL BYTES
  Labelledframe $f.fx -anchor nw -text "Number of Bytes"

  if {$gnumbytes == 0} {
    set gnumbytes $default_numbytes
    set gvar 0
  } else {
    set gvar 1
  }

  set fr [$f.fx get_frame] 
  set Widgets(rb-win_size) [radiobutton $fr.1 -variable [scope gvar] -text "Depends on window size" \
			      -value 0 -command [code $this toggle_size_control]]
  frame $fr.2
  set Widgets(rb-fixed) [radiobutton $fr.2.b -variable [scope gvar] -text Fixed \
			   -value 1 -command [code $this toggle_size_control]]

  set old_numbytes $default_numbytes
  set Widgets(e-numbytes) [entry $fr.2.e -textvariable [scope gnumbytes] -width 3]
  set normal_background [$Widgets(e-numbytes) cget -background]

  #
  # Trace gnumbytes so it will always be a +'ve integer...  Have to set this
  # trace AFTER the widget's textvariable is set so this trace will fire
  # BEFORE the widget's trace.
  #

  trace variable [scope gnumbytes] w [code $this check_numbytes]

  label $fr.2.l -text bytes
  grid $fr.2.b $fr.2.e $fr.2.l -sticky we
  grid $fr.1 x -sticky w -padx 4
  grid $fr.2 x -sticky w -padx 4
  grid columnconfigure $fr 1 -weight 1

  # MISC
  Labelledframe $f.1 -anchor nw -text "Miscellaneous"
  set fr [$f.1 get_frame] 
  frame $fr.1
  label $fr.1.plabel -height 1 -width 1 -bg $color -relief raised  
  set Widgets(b-color) [button $fr.1.pc -text "Change color..."  \
			  -command [code $this pick $fr.1.plabel]]
  grid $fr.1.plabel $fr.1.pc
  frame $fr.2
  label $fr.2.l -text "Bytes Per Row "
  set Widgets(b-bytes_per_row) [::combobox::combobox $fr.2.c \
				  -command [code $this set_bytes_per_row]  \
				  -width 4 -editable 0 -font global/fixed \
				  -bg $::Colors(textbg)]
  $fr.2.c list insert end 4
  $fr.2.c list insert end 8
  $fr.2.c list insert end 16
  $fr.2.c list insert end 32
  $fr.2.c list insert end 64
  $fr.2.c list insert end 128
  $fr.2.c configure -value $gbpr

  pack $fr.2.l -side left -anchor e
  pack $fr.2.c -side right

  set Widgets(cb-display_ascii) [checkbutton $fr.3 -variable [scope gascii] -text "Display ASCII"]
  frame $fr.4
  set Widgets(e-ascii_char) [entry $fr.4.e -textvariable [scope gascii_char] -width 1]
  label $fr.4.l -text "Control Char"
  grid $fr.4.e $fr.4.l -sticky we
  grid $fr.2 x $fr.3 -sticky w -padx 4
  grid $fr.4 -sticky w -padx 4
  grid columnconfigure $fr 1 -weight 1

  grid $f.f1 -padx 5 -pady 6 -sticky news
  grid $f.f2 -padx 5 -pady 6 -sticky news
  grid $f.fx -padx 5 -pady 6 -sticky news
  grid $f.1 -padx 5 -pady 6 -sticky we


  set Widgets(b-ok) [button $itk_interior.f.b.ok -text OK -command [code $this ok] -width 7 -default active]
  focus $Widgets(b-ok)
  
  # If there is an OK button, set Return in the entry field to invoke it...
  
  bind $Widgets(e-numbytes) <KeyPress-Return> "$Widgets(b-ok) flash ; $Widgets(b-ok) invoke"
  
  set Widgets(b-cancel) [button $itk_interior.f.b.quit -text Cancel -command [code $this cancel] -width 7]
  set Widgets(b-apply) [button $itk_interior.f.b.apply -text Apply -command [code $this apply] -width 7]
  standard_button_box $itk_interior.f.b
  
  grid $itk_interior.f.a 
  grid $itk_interior.f.b -sticky news
  grid $itk_interior.f
  
  #
  # Set the state of the window size entry here...
  #
  toggle_size_control

}

# ------------------------------------------------------------------
#  METHOD:  busy - make the widget unusable
# ------------------------------------------------------------------
itcl::body MemPref::busy {} {
  set top [winfo toplevel $itk_interior]
  $top configure -cursor watch
  
  # Disable all the radiobuttons and what not
  foreach w [array names Widgets] {
    set WidgetState($w) [$Widgets($w) cget -state]
  }
  foreach w [array names Widgets] {
    $Widgets($w) configure -state disabled
  }
}

# ------------------------------------------------------------------
#  METHOD:  idle - make the widget useable
# ------------------------------------------------------------------
itcl::body MemPref::idle {} {
  set top [winfo toplevel $itk_interior]
  $top configure -cursor {}

  # Re-enable all widgets
  foreach w [array names Widgets] {
    $Widgets($w) configure -state $WidgetState($w)
  }
}
# ------------------------------------------------------------------
#  METHOD:  ok - apply and quit
# ------------------------------------------------------------------
itcl::body MemPref::ok {} {
  apply
  unpost
}

# ------------------------------------------------------------------
#  METHOD:  cancel - just close the dialog w/o saving changes
# ------------------------------------------------------------------
itcl::body MemPref::cancel {} {
  unpost
}

# ------------------------------------------------------------------
#  METHOD:  check_numbytes - a trace to make sure gnumbytes is an int > 0
# ------------------------------------------------------------------
itcl::body MemPref::check_numbytes {var index mode} {
  upvar \#0 $var true
  if {($true != "") && ([catch {expr {(int($true) != double($true)) || $true <= 0}} val] 
			|| $val)} {
    bell
    set true $old_numbytes
  } else {
    set old_numbytes $true
  }
}

# ------------------------------------------------------------------
#  METHOD:  set_bytes_per_row - combobox callback to set the bytes per row
# ------------------------------------------------------------------
itcl::body MemPref::set_bytes_per_row {w value} {
  set gbpr $value
}

# ------------------------------------------------------------------
#  METHOD:  toggle_size_control - toggle the state of the entry box as the
#           control method changes
# ------------------------------------------------------------------
itcl::body MemPref::toggle_size_control {} {

  if {$gvar} {
    $Widgets(e-numbytes) configure -state normal \
      -background $normal_background
  } else {
    $Widgets(e-numbytes) configure -state disabled -background lightgray
    if {[info exists Widgets(b-ok)]} {
      focus $Widgets(b-ok)
    }
  }
}

# ------------------------------------------------------------------
#  METHOD:  apply - apply changes to the parent window
# ------------------------------------------------------------------
itcl::body MemPref::apply {} {

  busy
  gdbtk_busy

  if {$gvar == 0} {
    set numbytes 0
  } elseif {$gnumbytes == "" || $gnumbytes == 0} {
    # Protect against the case where someone sets the
    # entry field to an empty string, or pastes in a 0...
    bell
    set gnumbytes $default_numbytes
    set numbytes $gnumbytes
  } else {
    set numbytes $gnumbytes
  }
  switch $gsize {
    3 {
      set size $float_size
      set format f
    }
    5 {
      set size $double_size
      set format f
    }
    default {
      set size $gsize
      set format $gformat
    }
  }

  # pass all the changed values back to parent
  debug "$win configChange -size $size -numbytes $numbytes \
	     -format $format -ascii $gascii \
	     -ascii_char $gascii_char -bytes_per_row $gbpr \
	     -color $color"
  eval $win configure -size $size -numbytes $numbytes \
    -format $format -ascii $gascii \
    -ascii_char $gascii_char -bytes_per_row $gbpr \
    -color $color
  
  $win reconfig

  gdbtk_idle
  idle
}

# ------------------------------------------------------------------
#  METHOD:  enable_format - turn on the format radio buttons 
# ------------------------------------------------------------------
itcl::body MemPref::enable_format {} {
  if {!$format_disabled} {
    return
  }

  foreach widget {rb-binary rb-octal rb-hex rb-signed_dec rb-unsign_dec} {
    $Widgets($widget) configure -state normal
  }
  set format_disabled 0
}


# ------------------------------------------------------------------
#  METHOD:  disable_format - turn off the format radio buttons 
# ------------------------------------------------------------------
itcl::body MemPref::disable_format {} {
  if {$format_disabled} {
    return
  }

  foreach widget {rb-binary rb-octal rb-hex rb-signed_dec rb-unsign_dec} {
    $Widgets($widget) configure -state disabled
  }
  set format_disabled 1
}

# ------------------------------------------------------------------
#  METHOD:  pick - pick colors
# ------------------------------------------------------------------
itcl::body MemPref::pick {lab} {
  set new_color [tk_chooseColor -initialcolor $color -title "Choose color"]
  if {$new_color != $color && $new_color != ""} {
    set color $new_color
    $lab configure -bg $color
  }
}


# ------------------------------------------------------------------
#  METHOD:  reconfig - used when preferences change
# ------------------------------------------------------------------
itcl::body MemPref::reconfig {} {
  # for now, just delete and recreate
  destroy $itk_interior.f 
  build_win
}