1 # Implements MSR selection dialog class for Insight.
2 # Copyright (C) 1999, 2000, 2001 Red Hat, Inc.
4 # Written by Fernando Nasser <fnasser@redhat.com>
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License (GPL) as published by
8 # the Free Software Foundation; either version 2 of the License, or (at
9 # your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # ------------------------------------------------------------------
17 # NAME: MsrSelDlg::constructor
18 # DESCRIPTION: Create a new MSR Selection dialog window.
22 # ------------------------------------------------------------------
23 body MsrSelDlg::constructor {args} {
25 window_name "MSR Selection"
27 eval itk_initialize $args
31 # ------------------------------------------------------------------
32 # NAME: protected method MsrSelDlg::build_win
33 # DESCRIPTION: Builds the MSR dialog window from widgets.
38 # NOTES: This method should only be called once for
40 # ------------------------------------------------------------------
41 body MsrSelDlg::build_win {} {
43 # CHOOSE_MSR: the list box with list of MSRs. Also an entry
44 # for typing in the MSR by hand.
46 itk_component add choose_msr {
47 iwidgets::scrolledlistbox $itk_interior.cmsr -visibleitems 30x15 \
48 -labeltext "Choose MSR" -labelpos nw \
49 -labelrelief groove -labelborderwidth 2 \
50 -ipadx 8 -ipady 6 -childsitepos s -hscrollmode none \
51 -textbackground white -exportselection 0 \
52 -selectioncommand [code $this select_msr] \
53 -dblclickcommand [code $this doit]
56 # MSR_ENTRY: this is the MSR entry box. You can enter the MSR register name
57 # by hand here, or click on the listbox to have it entered for you.
59 itk_component add msr_entry {
60 iwidgets::entryfield [$itk_component(choose_msr) childsite].lab \
61 -labeltext MSR: -textbackground white \
62 -focuscommand [code $this clear_msr_selection] \
63 -command [code $this doit]
65 pack $itk_component(msr_entry) -fill x -side bottom -pady 4
67 itk_component add button_box {
71 itk_component add ok {
72 button $itk_component(button_box).ok -text OK -command [code $this doit]
74 $itk_component(ok) configure -state disabled
76 itk_component add cancel {
77 button $itk_component(button_box).cancel -text Cancel \
78 -command [code $this cancel]
81 ::standard_button_box $itk_component(button_box)
83 pack $itk_component(button_box) -side bottom -fill x \
85 pack $itk_component(choose_msr) -fill both -expand 1 -pady 4 -padx 4
87 after idle [list update idletasks; $this list_msrs]
91 # ------------------------------------------------------------------
92 # NAME: protected method MsrSelDlg::doit
93 # DESCRIPTION: Selects the MSR to view and unposts window.
99 # ------------------------------------------------------------------
100 body MsrSelDlg::doit {} {
101 set MsrSelDlg::last_button 1
102 set msr [$itk_component(msr_entry) get]
103 set MsrSelDlg::last_msr $msr
105 if {[catch {gdb_cmd "set msr-pointer $msr"} result]} {
106 ManagedWin::open WarningDlg -transient \
107 -message [list "Could not select this $msr:\n$result"]
110 debug "About to unpost"
114 # ------------------------------------------------------------------
115 # NAME: protected method MsrSelDlg::cancel
116 # DESCRIPTION: Unposts the window without selecting
123 # ------------------------------------------------------------------
124 body MsrSelDlg::cancel {} {
125 set MsrSelDlg::last_button 0
126 set MsrSelDlg::last_msr {}
130 # ------------------------------------------------------------------
131 # NAME: protected method MsrSelDlg::list_msrs
132 # DESCRIPTION: List the known MSR names.
138 # ------------------------------------------------------------------
139 body MsrSelDlg::list_msrs {{expr {}}} {
140 set err [catch {gdb_cmd "set msr-pointer" 1} msg ]
141 set msg [string trimright $msg "."]
142 set msrnames [split $msg ,]
143 set msrnames [lrange $msrnames 1 end]
145 $itk_component(choose_msr) clear
148 foreach name $msrnames {
149 lappend msr_list [list $name {set msr $name}]
150 $itk_component(choose_msr) insert end $name
153 $itk_component(choose_msr) selection set 0
157 # ------------------------------------------------------------------
158 # NAME: protected method MsrSelDlg::select_msrs
159 # DESCRIPTION: Grab the selected element from the MSR listbox
160 # and insert the associated MSR into the entry form.
166 # ------------------------------------------------------------------
167 body MsrSelDlg::select_msr {} {
168 set hit [$itk_component(choose_msr) curselection]
170 $itk_component(msr_entry) clear
171 $itk_component(msr_entry) insert 0 [lindex [lindex $msr_list $hit] 0]
172 $itk_component(ok) configure -state normal
176 # ------------------------------------------------------------------
177 # METHOD: clear_msr_selection - Clear the current MSR selection.
178 # ------------------------------------------------------------------
179 # ------------------------------------------------------------------
180 # NAME: protected method MsrSelDlg::clear_msrs_selection
181 # DESCRIPTION: Clear the current MSR selection.
187 # ------------------------------------------------------------------
188 body MsrSelDlg::clear_msr_selection {} {
189 $itk_component(choose_msr) selection clear 0 end
190 $itk_component(msr_entry) selection range 0 end