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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [gdbtcl/] [managedwin.itb] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Managed window for Insight.
2
# Copyright 1998, 1999, 2000, 2001 Red Hat, Inc.
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
#  PUBLIC METHOD:  constructor
17
# ------------------------------------------------------------
18
body ManagedWin::constructor {args} {
19
  #debug "$this args=$args"
20
  set _top [winfo toplevel $itk_interior]
21
}
22
 
23
# ------------------------------------------------------------
24
#  PUBLIC METHOD: destructor
25
# ------------------------------------------------------------
26
body ManagedWin::destructor {} {
27
 
28
  # If no toplevels remain, quit.  However, check the quit_if_last
29
  # flag since we might be doing something like displaying a
30
  # splash screen at startup...
31
 
32
  if {!$numTopWins && [quit_if_last]} {
33
    gdb_force_quit
34
  } else {
35
    destroy_toplevel
36
  }
37
}
38
 
39
# ------------------------------------------------------------
40
#  PUBLIC METHOD:  window_name - Set the name of the window
41
#   (and optionally its icon's name).
42
# ------------------------------------------------------------
43
body ManagedWin::window_name {wname {iname ""}} {
44
  wm title $_top $wname
45
  if {$iname != ""} {
46
    wm iconname $_top $iname
47
  } else {
48
    wm iconname $_top $wname
49
  }
50
}
51
 
52
# ------------------------------------------------------------
53
#  PUBLIC METHOD: pickle - This is the base class pickle
54
#   method.  It returns a command that can be used to recreate
55
#   this particular window.
56
# ------------------------------------------------------------
57
body ManagedWin::pickle {} {
58
  return [list ManagedWin::open [namespace tail [info class]]]
59
}
60
 
61
# ------------------------------------------------------------
62
#  PUBLIC METHOD:  reveal
63
# ------------------------------------------------------------
64
body ManagedWin::reveal {} {
65
  # Do this update to flush all changes before deiconifying the window.
66
  update idletasks
67
 
68
  raise $_top
69
  wm deiconify $_top
70
  # Some window managers (on unix) fail to honor the geometry unless
71
  # the window is visible.
72
  if {$_geometry != "" && $::tcl_platform(platform) == "unix"} {
73
    wm geometry $_top $_geometry
74
    set _geometry ""
75
  }
76
 
77
  #debug "$_top geometry=[wm geometry $_top] state=[wm state $_top]"
78
 
79
  # There used to be a `focus -force' here, but using -force is
80
  # unfriendly, so it was removed.  It was then replaced with a simple
81
  # `focus $top'.  However, this has no useful effect -- it just
82
  # resets the subwindow of $top which has the `potential' focus.
83
  # This can actually be confusing to the user.
84
 
85
  # NOT for Windows, though. Without the focus, we get, eg. a
86
  # register window on top of the source window, but the source window
87
  # will have the focus. This is not the proper model for Windows.
88
  if {$::tcl_platform(platform) == "windows"} {
89
    focus -force [focus -lastfor $_top]
90
  }
91
}
92
 
93
# ------------------------------------------------------------
94
#  PUBLIC PROC:  restart
95
# ------------------------------------------------------------
96
body ManagedWin::restart {} {
97
  # This is needed in case we've called "gdbtk_busy" before the restart.
98
  # This will configure the stop/run button as necessary
99
  after idle gdbtk_idle
100
 
101
  # call the reconfig method for each object
102
  foreach obj [itcl_info objects -isa ManagedWin] {
103
    if {[catch {$obj reconfig} msg]} {
104
      dbug W "reconfig failed for $obj - $msg"
105
    }
106
  }
107
}
108
 
109
# ------------------------------------------------------------------
110
#  PUBLIC PROC:  shutdown - This writes all the active windows to
111
#   the preferences file, so they can be restored at startup.
112
#   FIXME: Currently assumes only ONE window per type...
113
# ------------------------------------------------------------------
114
body ManagedWin::shutdown {} {
115
  set activeWins {}
116
  foreach win [itcl_info objects -isa ManagedWin] {
117
    if {![$win isa ModalDialog]} {
118
      set g [wm geometry [winfo toplevel [namespace tail $win]]]
119
      pref setd gdb/geometry/[namespace tail $win] $g
120
      lappend activeWins [$win pickle]
121
    }
122
  }
123
  pref set gdb/window/active $activeWins
124
}
125
 
126
# ------------------------------------------------------------------
127
#  PUBLIC PROC:  startup - This restores all the windows that were
128
#   opened at shutdown.
129
#   FIXME: Currently assumes only ONE window per type...
130
# ------------------------------------------------------------------
131
body ManagedWin::startup {} {
132
  debug "Got active list [pref get gdb/window/active]"
133
 
134
  foreach cmd [pref get gdb/window/active] {
135
    eval $cmd
136
  }
137
  # If we open the source window, and a source window already exists,
138
  # then we end up raising it twice during startup.  This yields an
139
  # annoying effect for the user: if the user tries the bury the
140
  # source window during startup, it will raise itself again.  This
141
  # explains why we first check to see if a source window exists
142
  # before trying to create it -- raising the window is an inevitable
143
  # side effect of the creation process.
144
  if {[llength [find SrcWin]] == 0} {
145
    ManagedWin::open SrcWin
146
  }
147
}
148
 
149
# ------------------------------------------------------------
150
#  PUBLIC PROC:  open_dlg
151
# ------------------------------------------------------------
152
body ManagedWin::open_dlg {class args} {
153
 
154
  set newwin [eval _open $class $args]
155
  if {$newwin != ""} {
156
    $newwin reveal
157
    $newwin post
158
  }
159
}
160
 
161
# ------------------------------------------------------------
162
#  PUBLIC PROC:  open
163
# ------------------------------------------------------------
164
body ManagedWin::open {class args} {
165
 
166
  set newwin [eval _open $class $args]
167
  if {$newwin != ""} {
168
    if {[$newwin isa ModalDialog]} {
169
      parse_args [list {expire 0}]
170
      after idle "$newwin reveal; $newwin post 0 $expire"
171
    } else {
172
      after idle "$newwin reveal"
173
    }
174
  }
175
 
176
  return $newwin
177
}
178
 
179
# ------------------------------------------------------------
180
#  PRIVATE PROC:  _open
181
# ------------------------------------------------------------
182
body ManagedWin::_open { class args } {
183
  debug "$class $args"
184
 
185
  parse_args force
186
 
187
  if {!$force} {
188
    # check all windows for one of this type
189
    foreach obj [itcl_info objects -isa ManagedWin] {
190
      if {[$obj isa $class]} {
191
        $obj reveal
192
        return $obj
193
      }
194
    }
195
 
196
  }
197
  # need to create a new window
198
  return [eval _create $class $args]
199
}
200
 
201
# ------------------------------------------------------------
202
#  PRIVATE PROC:  _create
203
# ------------------------------------------------------------
204
body ManagedWin::_create { class args } {
205
 
206
  set win [string tolower $class]
207
  debug "win=$win args=$args"
208
 
209
  parse_args {center transient {over ""}}
210
 
211
  # increment window numbers until we get an unused one
212
  set i 0
213
  while {[winfo exists .$win$i]} { incr i }
214
 
215
  while { 1 } {
216
    set top [toplevel .$win$i]
217
    wm withdraw $top
218
    wm protocol $top WM_DELETE_WINDOW "destroy $top"
219
    wm group $top .
220
    set newwin $top.$win
221
    if {[catch {uplevel \#0 eval $class $newwin $args} msg]} {
222
      dbug E "object creation of $class failed: $msg"
223
      dbug E $::errorInfo
224
      if {[string first "object already exists" $msg] != -1} {
225
        # sometimes an object is still really around even though
226
        # [winfo exists] said it didn't exist.  Check for this case
227
        # and increment the window number again.
228
        catch {destroy $top}
229
        incr i
230
      } else {
231
        return ""
232
      }
233
    } else {
234
      break
235
    }
236
  }
237
 
238
  if {[catch {pack $newwin -expand yes -fill both}]} {
239
    dbug W "packing of $newwin failed: $::errorInfo"
240
    return ""
241
  }
242
 
243
  wm maxsize $top $_screenwidth $_screenheight
244
  wm minsize $top 20 20
245
  update idletasks
246
 
247
  if {$over != ""} {
248
    # center new window
249
    center_window $top -over [winfo toplevel [namespace tail $over]]
250
  } elseif {$center} {
251
    center_window $top
252
  }
253
 
254
  if {$transient} {
255
    wm resizable $top 0 0
256
    wm transient $top .
257
  } elseif {$::tcl_platform(platform) == "unix"} {
258
    # Modal dialogs DONT get Icons...
259
    if {[pref get gdb/use_icons] && ![$newwin isa ModalDialog]} {
260
      set icon [_make_icon_window ${top}_icon]
261
      wm iconwindow $top $icon
262
      bind $icon  "$newwin reveal"
263
    }
264
  }
265
 
266
  if {[info exists ::env(GDBTK_TEST_RUNNING)] && $::env(GDBTK_TEST_RUNNING)} {
267
    set g "+100+100"
268
    wm geometry $top $g
269
    wm positionfrom $top user
270
  } else {
271
    set g [pref getd gdb/geometry/$newwin]
272
    if {$g == "1x1+0+0"} {
273
      dbug E "bad geometry"
274
      set g ""
275
    }
276
    if {$g != ""} {
277
      # OK. We have a requested geometry. We know that it fits on the screen
278
      # because we set the maxsize.  Now we have to make sure it will not be
279
      # displayed off the screen.
280
      set w 0; set h 0; set x 0; set y 0
281
      if {![catch {scan $g  "%dx%d%d%d" w h x y} res]} {
282
        if {$x < 0} {
283
          set x [expr $_screenwidth + $x]
284
        }
285
        if {$y < 0} {
286
          set y [expr $_screenheight + $y]
287
        }
288
 
289
        # If the window is transient, then don't reset its size, since
290
        # the user didn't set this anyway, and in some cases where the
291
        # size can change dynamically, like the Global Preferences
292
        # dialog, this can hide parts of the dialog with no recourse...
293
 
294
        # if dont_remember_size is true, don't set size, just like
295
        # transients
296
 
297
        if {$transient || [dont_remember_size]} {
298
          set g "+${x}+${y}"
299
        } else {
300
          set g "${w}x${h}+${x}+${y}"
301
        }
302
        if {[expr $x+50] < $_screenwidth && [expr $y+20] < $_screenheight} {
303
          wm positionfrom $top user
304
          wm geometry $top $g
305
          set ::$top._init_geometry $g
306
        }
307
      }
308
    }
309
  }
310
 
311
  bind $top  [list delete object $newwin]
312
 
313
  return $newwin
314
}
315
 
316
# ------------------------------------------------------------
317
#  PUBLIC PROC:  find
318
# ------------------------------------------------------------
319
body ManagedWin::find { win } {
320
  debug "$win"
321
  set res ""
322
  foreach obj [itcl_info objects -isa ManagedWin] {
323
    if {[$obj isa $win]} {
324
      lappend res $obj
325
    }
326
  }
327
  return $res
328
}
329
 
330
# ------------------------------------------------------------
331
#  PUBLIC PROC:  init
332
# ------------------------------------------------------------
333
body ManagedWin::init {} {
334
  wm withdraw .
335
  set _screenheight [winfo screenheight .]
336
  set _screenwidth [winfo screenwidth .]
337
}
338
 
339
# ------------------------------------------------------------
340
#  PUBLIC METHOD:  destroy_toplevel
341
# ------------------------------------------------------------
342
body ManagedWin::destroy_toplevel {} {
343
  after idle "update idletasks;destroy $_top"
344
}
345
 
346
# ------------------------------------------------------------
347
#  PROTECTED METHOD:  _freeze_me
348
# ------------------------------------------------------------
349
body ManagedWin::_freeze_me {} {
350
  $_top configure -cursor watch
351
  ::update idletasks
352
}
353
 
354
# ------------------------------------------------------------
355
#  PROTECTED METHOD: _thaw_me
356
# ------------------------------------------------------------
357
body ManagedWin::_thaw_me {} {
358
 
359
  $_top configure -cursor {}
360
  ::update idletasks
361
}
362
 
363
# ------------------------------------------------------------------
364
#  PRIVATE PROC: _make_icon_window - create a small window with an
365
#   icon in it for use by certain Unix window managers.
366
# ------------------------------------------------------------------
367
body ManagedWin::_make_icon_window {name {file "gdbtk_icon"}} {
368
  if {![winfo exists $name]} {
369
    toplevel $name
370
    label $name.im -image \
371
      [image create photo icon_photo -file [file join $::gdb_ImageDir $file.gif]]
372
  }
373
  pack $name.im
374
  return $name
375
}

powered by: WebSVN 2.1.0

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