GDB (API)
|
00001 # Modal dialog class for GDBtk. 00002 # Copyright (C) 1998, 1999 Cygnus Solutions 00003 # 00004 # This program is free software; you can redistribute it and/or modify it 00005 # under the terms of the GNU General Public License (GPL) as published by 00006 # the Free Software Foundation; either version 2 of the License, or (at 00007 # your option) any later version. 00008 # 00009 # This program is distributed in the hope that it will be useful, 00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 # GNU General Public License for more details. 00013 00014 00015 # ---------------------------------------------------------------------- 00016 # Implements the post and unpost behavior of a Modal Dialog. 00017 # 00018 # For now the point behind this is to control calling 00019 # ide_grab_support. If you call disable all the windows of an 00020 # application but one, destroy that window, THEN re-enable the 00021 # windows, Windows brings the last enabled window in the last 00022 # active application to the foreground (Doh!). 00023 # 00024 # ---------------------------------------------------------------------- 00025 00026 itcl::class ModalDialog { 00027 # This is the variable we vwait on when the dialog is posted. 00028 # It is set to 1 in the unpost method, and to -1 in the destructor. 00029 00030 private variable unpost_notification 0 00031 00032 destructor { 00033 debug " UNPOST $this" 00034 set unpost_notification -1 00035 } 00036 00037 # ------------------------------------------------------------------ 00038 # METHOD: unpost - unposts the dialog box... 00039 # ------------------------------------------------------------------ 00040 public method unpost {} { 00041 after idle [list set [scope unpost_notification] 1] 00042 } 00043 00044 # ------------------------------------------------------------------ 00045 # METHOD: cancel - This just unposts the dialog box... 00046 # If you want to programatically cancel a dialog 00047 # selection, for instance if the app is going away 00048 # use this rather than unpost. That way a sub-class 00049 # that actually has to do some work can override it. 00050 # ------------------------------------------------------------------ 00051 public method cancel {} { 00052 ModalDialog::unpost 00053 } 00054 00055 00056 # ------------------------------------------------------------------ 00057 # METHOD: post - posts the dialog box... 00058 # ------------------------------------------------------------------ 00059 public method post {{on_top 0} {expire 0}} { 00060 00061 debug "POST $this" 00062 set top [winfo toplevel [namespace tail $this]] 00063 wm protocol $top WM_DELETE_WINDOW [code $this cancel] 00064 00065 if {$on_top} { 00066 after 500 keep_raised $top 00067 } 00068 00069 ide_grab_support disable_except $top 00070 focus $top 00071 grab set $top 00072 00073 if {$expire > 0} { 00074 set afterID [after $expire [code $this cancel]] 00075 } 00076 00077 vwait [scope unpost_notification] 00078 00079 if {$afterID != ""} { 00080 after cancel $afterID 00081 set afterID "" 00082 } 00083 00084 grab release $top 00085 00086 # Enable all the windows in the application BEFORE 00087 # you destroy this one, or Windows will bring another 00088 # app to the foreground. 00089 00090 ide_grab_support enable_all 00091 00092 # We can get here either by someone calling unpost (if an OK button 00093 # is clicked or whatever), or by someone destroying the dialog (for 00094 # instance by using the Window Manager.) Only delete the object if 00095 # we are not already in the process of doing this. 00096 00097 if {$unpost_notification == 1} { 00098 ::delete object $this 00099 } 00100 } 00101 00102 public variable expire -1 ;# If this is set to a number > 0, the 00103 # dialog will time out after this interval. 00104 private variable afterID ""; # The id for the expiration after event. 00105 }