OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [gdbtk/] [library/] [mempref.itb] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Memory display preferences window for GDBtk.
2
# Copyright 1998, 1999 Cygnus Solutions
3
#
4
# This program is free software; you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License (GPL) as published by
6
# the Free Software Foundation; either version 2 of the License, or (at
7
# your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
 
14
 
15
# ------------------------------------------------------------------
16
#  METHOD:  constructor - build the dialog
17
# ------------------------------------------------------------------
18
body MemPref::constructor {args} {
19
 
20
  window_name "Memory Preferences"
21
 
22
  eval itk_initialize $args
23
 
24
  if {$float_size == ""} {
25
    set float_size [gdb_eval sizeof(float)]
26
    set double_size [gdb_eval sizeof(double)]
27
  }
28
 
29
  if {[string compare $format f] == 0} {
30
    set gformat x
31
    set format_disabled 1
32
    if {$size == $float_size} {
33
      set gsize 3
34
    } elseif {$size == $double_size} {
35
      set gsize 5
36
    }
37
  } else {
38
    set gsize $size
39
    set gformat $format
40
  }
41
 
42
  set gnumbytes $numbytes
43
  set gbpr $bpr
44
  set gascii $ascii
45
  set gascii_char $ascii_char
46
 
47
  build_win
48
 
49
  if {$format_disabled} {
50
    set format_disabled 0
51
    disable_format
52
  }
53
 
54
  wm resizable [winfo toplevel $itk_interior] 0 0
55
}
56
 
57
# ------------------------------------------------------------------
58
#  METHOD:  destructor - destroy the dialog
59
# ------------------------------------------------------------------
60
body MemPref::destructor {} {
61
  trace vdelete [scope gnumbytes] w [code $this check_numbytes]
62
}
63
 
64
# ------------------------------------------------------------------
65
#  METHOD:  build_win - build the dialog
66
# ------------------------------------------------------------------
67
body MemPref::build_win {} {
68
 
69
  frame $itk_interior.f
70
  set f [frame $itk_interior.f.a]
71
  frame $itk_interior.f.b
72
 
73
  # SIZE
74
  Labelledframe $f.f1 -anchor nw -text Size
75
  set fr [$f.f1 get_frame]
76
 
77
  set Widgets(rb-Byte) [radiobutton $fr.1 -variable [scope gsize] -text Byte \
78
                          -value 1 -command [code $this enable_format]]
79
  set Widgets(rb-half_word) [radiobutton $fr.2 -variable [scope gsize] -text "Half Word" \
80
                               -value 2 -command [code $this enable_format]]
81
  set Widgets(rb-word) [radiobutton $fr.4 -variable [scope gsize] -text Word \
82
                          -value 4 -command [code $this enable_format]]
83
  set Widgets(rb-d_word) [radiobutton $fr.8 -variable [scope gsize] -text "Double Word" \
84
                            -value 8 -command [code $this enable_format]]
85
  set Widgets(rb-float) [radiobutton $fr.f -variable [scope gsize] -text Float \
86
                           -value 3 -command [code $this disable_format]]
87
  set Widgets(rb-d_float) [radiobutton $fr.d -variable [scope gsize] -text "Double Float" \
88
                             -value 5 -command [code $this disable_format]]
89
  grid $fr.1 $fr.4 $fr.f -sticky w -padx 4
90
  grid $fr.2 $fr.8 $fr.d -sticky w -padx 4
91
 
92
  # FORMAT
93
  Labelledframe $f.f2 -anchor nw -text Format
94
  set fr [$f.f2 get_frame]
95
  set Widgets(rb-binary) [radiobutton $fr.1 -variable [scope gformat] \
96
                            -text Binary -value t]
97
  set Widgets(rb-octal) [radiobutton $fr.2 -variable [scope gformat] \
98
                           -text Octal -value o]
99
  set Widgets(rb-hex) [radiobutton $fr.3 -variable [scope gformat] \
100
                         -text Hex -value x]
101
  set Widgets(rb-signed_dec) [radiobutton $fr.4 -variable [scope gformat] \
102
                                -text "Signed Decimal" -value d]
103
  set Widgets(rb-unsign_dec) [radiobutton $fr.5 -variable [scope gformat] \
104
                                -text "Unsigned Decimal" -value u]
105
 
106
  grid $fr.1 $fr.2 $fr.3 -sticky w -padx 4
107
  grid $fr.4 $fr.5 x -sticky w -padx 4
108
 
109
  # TOTAL BYTES
110
  Labelledframe $f.fx -anchor nw -text "Number of Bytes"
111
 
112
  if {$gnumbytes == 0} {
113
    set gnumbytes $default_numbytes
114
    set gvar 0
115
  } else {
116
    set gvar 1
117
  }
118
 
119
  set fr [$f.fx get_frame]
120
  set Widgets(rb-win_size) [radiobutton $fr.1 -variable [scope gvar] -text "Depends on window size" \
121
                              -value 0 -command [code $this toggle_size_control]]
122
  frame $fr.2
123
  set Widgets(rb-fixed) [radiobutton $fr.2.b -variable [scope gvar] -text Fixed \
124
                           -value 1 -command [code $this toggle_size_control]]
125
 
126
  set old_numbytes $default_numbytes
127
  set Widgets(e-numbytes) [entry $fr.2.e -textvariable [scope gnumbytes] -width 3]
128
  set normal_background [$Widgets(e-numbytes) cget -background]
129
 
130
  #
131
  # Trace gnumbytes so it will always be a +'ve integer...  Have to set this
132
  # trace AFTER the widget's textvariable is set so this trace will fire
133
  # BEFORE the widget's trace.
134
  #
135
 
136
  trace variable [scope gnumbytes] w [code $this check_numbytes]
137
 
138
  label $fr.2.l -text bytes
139
  grid $fr.2.b $fr.2.e $fr.2.l -sticky we
140
  grid $fr.1 x -sticky w -padx 4
141
  grid $fr.2 x -sticky w -padx 4
142
  grid columnconfigure $fr 1 -weight 1
143
 
144
  # MISC
145
  Labelledframe $f.1 -anchor nw -text "Miscellaneous"
146
  set fr [$f.1 get_frame]
147
  frame $fr.1
148
  label $fr.1.plabel -height 1 -width 1 -bg $color -relief raised
149
  set Widgets(b-color) [button $fr.1.pc -text "Change color..."  \
150
                          -command [code $this pick $fr.1.plabel]]
151
  grid $fr.1.plabel $fr.1.pc
152
  frame $fr.2
153
  label $fr.2.l -text "Bytes Per Row "
154
  set Widgets(b-bytes_per_row) [::combobox::combobox $fr.2.c \
155
                                  -command [code $this set_bytes_per_row]  \
156
                                  -width 4 -editable 0 -font src-font]
157
  $fr.2.c list insert end 4
158
  $fr.2.c list insert end 8
159
  $fr.2.c list insert end 16
160
  $fr.2.c list insert end 32
161
  $fr.2.c list insert end 64
162
  $fr.2.c list insert end 128
163
  $fr.2.c configure -value $gbpr
164
 
165
  pack $fr.2.l -side left -anchor e
166
  pack $fr.2.c -side right
167
 
168
  set Widgets(cb-display_ascii) [checkbutton $fr.3 -variable [scope gascii] -text "Display ASCII"]
169
  frame $fr.4
170
  set Widgets(e-ascii_char) [entry $fr.4.e -textvariable [scope gascii_char] -width 1]
171
  label $fr.4.l -text "Control Char"
172
  grid $fr.4.e $fr.4.l -sticky we
173
  grid $fr.2 x $fr.3 -sticky w -padx 4
174
  grid $fr.4 -sticky w -padx 4
175
  grid columnconfigure $fr 1 -weight 1
176
 
177
  grid $f.f1 -padx 5 -pady 6 -sticky news
178
  grid $f.f2 -padx 5 -pady 6 -sticky news
179
  grid $f.fx -padx 5 -pady 6 -sticky news
180
  grid $f.1 -padx 5 -pady 6 -sticky we
181
 
182
 
183
  set Widgets(b-ok) [button $itk_interior.f.b.ok -text OK -command [code $this ok] -width 7 -default active]
184
  focus $Widgets(b-ok)
185
 
186
  # If there is an OK button, set Return in the entry field to invoke it...
187
 
188
  bind $Widgets(e-numbytes)  "$Widgets(b-ok) flash ; $Widgets(b-ok) invoke"
189
 
190
  set Widgets(b-cancel) [button $itk_interior.f.b.quit -text Cancel -command [code $this cancel] -width 7]
191
  set Widgets(b-apply) [button $itk_interior.f.b.apply -text Apply -command [code $this apply] -width 7]
192
  standard_button_box $itk_interior.f.b
193
 
194
  grid $itk_interior.f.a
195
  grid $itk_interior.f.b -sticky news
196
  grid $itk_interior.f
197
 
198
  #
199
  # Set the state of the window size entry here...
200
  #
201
  toggle_size_control
202
 
203
}
204
 
205
# ------------------------------------------------------------------
206
#  METHOD:  busy - make the widget unusable
207
# ------------------------------------------------------------------
208
body MemPref::busy {} {
209
  set top [winfo toplevel $itk_interior]
210
  $top configure -cursor watch
211
 
212
  # Disable all the radiobuttons and what not
213
  foreach w [array names Widgets] {
214
    set WidgetState($w) [$Widgets($w) cget -state]
215
  }
216
  foreach w [array names Widgets] {
217
    $Widgets($w) configure -state disabled
218
  }
219
}
220
 
221
# ------------------------------------------------------------------
222
#  METHOD:  idle - make the widget useable
223
# ------------------------------------------------------------------
224
body MemPref::idle {} {
225
  set top [winfo toplevel $itk_interior]
226
  $top configure -cursor {}
227
 
228
  # Re-enable all widgets
229
  foreach w [array names Widgets] {
230
    $Widgets($w) configure -state $WidgetState($w)
231
  }
232
}
233
# ------------------------------------------------------------------
234
#  METHOD:  ok - apply and quit
235
# ------------------------------------------------------------------
236
body MemPref::ok {} {
237
  apply
238
  unpost
239
}
240
 
241
# ------------------------------------------------------------------
242
#  METHOD:  cancel - just close the dialog w/o saving changes
243
# ------------------------------------------------------------------
244
body MemPref::cancel {} {
245
  unpost
246
}
247
 
248
# ------------------------------------------------------------------
249
#  METHOD:  check_numbytes - a trace to make sure gnumbytes is an int > 0
250
# ------------------------------------------------------------------
251
body MemPref::check_numbytes {var index mode} {
252
  upvar \#0 $var true
253
  if {($true != "") && ([catch {expr {(int($true) != double($true)) || $true <= 0}} val]
254
                        || $val)} {
255
    bell
256
    set true $old_numbytes
257
  } else {
258
    set old_numbytes $true
259
  }
260
}
261
 
262
# ------------------------------------------------------------------
263
#  METHOD:  set_bytes_per_row - combobox callback to set the bytes per row
264
# ------------------------------------------------------------------
265
body MemPref::set_bytes_per_row {w value} {
266
  set gbpr $value
267
}
268
 
269
# ------------------------------------------------------------------
270
#  METHOD:  toggle_size_control - toggle the state of the entry box as the
271
#           control method changes
272
# ------------------------------------------------------------------
273
body MemPref::toggle_size_control {} {
274
 
275
  if {$gvar} {
276
    $Widgets(e-numbytes) configure -state normal \
277
      -background $normal_background
278
  } else {
279
    $Widgets(e-numbytes) configure -state disabled -background lightgray
280
    if {[info exists Widgets(b-ok)]} {
281
      focus $Widgets(b-ok)
282
    }
283
  }
284
}
285
 
286
# ------------------------------------------------------------------
287
#  METHOD:  apply - apply changes to the parent window
288
# ------------------------------------------------------------------
289
body MemPref::apply {} {
290
 
291
  busy
292
  gdbtk_busy
293
 
294
  if {$gvar == 0} {
295
    set numbytes 0
296
  } elseif {$gnumbytes == "" || $gnumbytes == 0} {
297
    # Protect against the case where someone sets the
298
    # entry field to an empty string, or pastes in a 0...
299
    bell
300
    set gnumbytes $default_numbytes
301
    set numbytes $gnumbytes
302
  } else {
303
    set numbytes $gnumbytes
304
  }
305
  switch $gsize {
306
    3 {
307
      set size $float_size
308
      set format f
309
    }
310
    5 {
311
      set size $double_size
312
      set format f
313
    }
314
    default {
315
      set size $gsize
316
      set format $gformat
317
    }
318
  }
319
 
320
  # pass all the changed values back to parent
321
  debug "$win configChange -size $size -numbytes $numbytes \
322
             -format $format -ascii $gascii \
323
             -ascii_char $gascii_char -bytes_per_row $gbpr \
324
             -color $color"
325
  eval $win configure -size $size -numbytes $numbytes \
326
    -format $format -ascii $gascii \
327
    -ascii_char $gascii_char -bytes_per_row $gbpr \
328
    -color $color
329
 
330
  $win reconfig
331
 
332
  gdbtk_idle
333
  idle
334
}
335
 
336
# ------------------------------------------------------------------
337
#  METHOD:  enable_format - turn on the format radio buttons
338
# ------------------------------------------------------------------
339
body MemPref::enable_format {} {
340
  if {!$format_disabled} {
341
    return
342
  }
343
 
344
  foreach widget {rb-binary rb-octal rb-hex rb-signed_dec rb-unsign_dec} {
345
    $Widgets($widget) configure -state normal
346
  }
347
  set format_disabled 0
348
}
349
 
350
 
351
# ------------------------------------------------------------------
352
#  METHOD:  disable_format - turn off the format radio buttons
353
# ------------------------------------------------------------------
354
body MemPref::disable_format {} {
355
  if {$format_disabled} {
356
    return
357
  }
358
 
359
  foreach widget {rb-binary rb-octal rb-hex rb-signed_dec rb-unsign_dec} {
360
    $Widgets($widget) configure -state disabled
361
  }
362
  set format_disabled 1
363
}
364
 
365
# ------------------------------------------------------------------
366
#  METHOD:  pick - pick colors
367
# ------------------------------------------------------------------
368
body MemPref::pick {lab} {
369
  set new_color [tk_chooseColor -initialcolor $color -title "Choose color"]
370
  if {$new_color != $color && $new_color != ""} {
371
    set color $new_color
372
    $lab configure -bg $color
373
  }
374
}
375
 
376
 
377
# ------------------------------------------------------------------
378
#  METHOD:  reconfig - used when preferences change
379
# ------------------------------------------------------------------
380
body MemPref::reconfig {} {
381
  # for now, just delete and recreate
382
  destroy $itk_interior.f
383
  build_win
384
}
385
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.