1 # Process window for Insight.
2 # Copyright (C) 1998, 1999, 2001, 2002, 2008 Red Hat, Inc.
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.
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.
15 # ----------------------------------------------------------------------
16 # Implements a process window with a list of threads, tasks, and/or
19 # ----------------------------------------------------------------------
21 itcl::body ProcessWin::constructor {args} {
23 window_name "Processes"
28 # Add hooks for this object
29 add_hook gdb_no_inferior_hook [code $this idle]
33 # ------------------------------------------------------------------
34 # METHOD: build_win - build the main process window
35 # ------------------------------------------------------------------
36 itcl::body ProcessWin::build_win {} {
38 itk_component add slbox {
39 iwidgets::scrolledlistbox $itk_interior.slbox \
40 -background $::Colors(bg) \
41 -selectbackground $::Colors(sbg) -selectforeground $::Colors(sfg) \
42 -textfont global/fixed \
43 -exportselection false \
44 -selectioncommand [code $this change_context]
46 [$itk_component(slbox) component listbox] configure \
47 -bg $::Colors(textbg) -fg $::Colors(textfg)
50 pack $itk_component(slbox) -side left -expand yes -fill both
54 # ------------------------------------------------------------------
55 # METHOD: update - update widget when something changes
56 # ------------------------------------------------------------------
57 itcl::body ProcessWin::update {event} {
60 $itk_component(slbox) delete 0 end
61 if {[catch {gdb_cmd "info thread"} threads]} {
62 # failed. leave window blank
66 set threads [split $threads \n]
67 debug "processWin update: \n$threads"
68 if {[llength $threads] == 0} {
69 # no processes/threads listed.
73 # insert each line one at a time
76 foreach line $threads {
77 # Active line starts with "*"
78 if {[string index $line 0] == "*"} {
79 # strip off leading "*"
80 set line " [string trimleft $line "*"]"
81 set active $num_threads
83 # scan for GDB ID number at start of line
84 if {[scan $line "%d" id($num_threads)] == 1} {
85 $itk_component(slbox) insert end $line
90 # highlight the active thread
92 set active_thread $id($active)
93 $itk_component(slbox) selection set $active
94 $itk_component(slbox) see $active
99 # ------------------------------------------------------------------
100 # METHOD: change_context - change the current context (active thread)
101 # This method is currently ONLY called from the mouse binding
102 # ------------------------------------------------------------------
103 itcl::body ProcessWin::change_context {} {
104 if {!$Running && [$itk_component(slbox) size] != 0} {
106 set sel [$itk_component(slbox) curselection]
108 #debug "change_context to line $sel id=$idnum"
109 catch {gdb_cmd "thread $idnum"}
110 # Run idle hooks and cause all widgets to update
118 # ------------------------------------------------------------------
119 # DESTRUCTOR - destroy window containing widget
120 # ------------------------------------------------------------------
121 itcl::body ProcessWin::destructor {} {
122 remove_hook gdb_no_inferior_hook [code $this no_inferior]
125 # ------------------------------------------------------------------
126 # METHOD: reconfig - used when preferences change
127 # ------------------------------------------------------------------
128 itcl::body ProcessWin::reconfig {} {
129 destroy $itk_interior.s
130 if {[winfo exists $itk_interior.slbox]} { destroy $itk_interior.slbox }
134 # ------------------------------------------------------------------
135 # METHOD: busy - BusyEvent handler
137 # This method should accomplish blocking
138 # - clicks in the window
139 # - change mouse pointer
140 # ------------------------------------------------------------------
141 itcl::body ProcessWin::busy {event} {
146 # ------------------------------------------------------------------
147 # METHOD: idle - handle IdleEvent
148 # ------------------------------------------------------------------
149 itcl::body ProcessWin::idle {event} {
154 # ------------------------------------------------------------------
155 # METHOD: cursor - set the window cursor
156 # This is a convenience method which simply sets the mouse
157 # pointer to the given glyph.
158 # ------------------------------------------------------------------
159 itcl::body ProcessWin::cursor {glyph} {
160 $_top configure -cursor $glyph