separate pack_widgets and set_bindings

This commit is contained in:
Stefan Frederik 2021-11-17 17:53:18 +01:00
parent 1ce2d71e95
commit e27c5dc21a
2 changed files with 21 additions and 5 deletions

View File

@ -838,7 +838,7 @@ void new_schematic(const char *what, const char *top_path, const char *tk_win_pa
Tk_Window tkwin;
if(!strcmp(what, "create")) {
dbg(1, "new_schematic() create, save ctx\n");
dbg(0, "new_schematic() create, save ctx tk_win_path=%s\n", tk_win_path);
if(cnt == 0) {
for(i = 0; i < MAX_NEW_WINDOWS; i++) {
save_xctx[i] = NULL;
@ -849,12 +849,17 @@ void new_schematic(const char *what, const char *top_path, const char *tk_win_pa
}
if(cnt + 1 >= MAX_NEW_WINDOWS) return; /* no more free slots */
cnt++;
n = -1;
for(i = 1; i < MAX_NEW_WINDOWS; i++) { /* search 1st free slot */
if(save_xctx[i] == NULL) {
n = i;
break;
}
}
if(n == -1) {
dbg(0, "new_schematic(\"create\"...): no more free slots\n");
return;
}
tknew_window[n] = Tk_NameToWindow(interp, tk_win_path, mainwindow);
Tk_MakeWindowExist(tknew_window[n]);
new_window = Tk_WindowId(tknew_window[n]);
@ -894,13 +899,18 @@ void new_schematic(const char *what, const char *top_path, const char *tk_win_pa
Tcl_ResetResult(interp);
if(close) {
tkwin = Tk_NameToWindow(interp, tk_win_path, mainwindow); /* NULL if tk_win_path not existing */
if(!tkwin) dbg(0, "new_schematic(destroy, ...): Warning: %s has been destroyed\n", tk_win_path);
if(!tkwin) dbg(0, "new_schematic(\"destroy\", ...): Warning: %s has been destroyed\n", tk_win_path);
n = -1;
if(tkwin) for(i = 1; i < MAX_NEW_WINDOWS; i++) {
if(tkwin == tknew_window[i]) {
n = i;
break;
}
}
if(n == -1) {
dbg(0, "new_schematic(\"destroy\"...): no window to destroy found: %s\n", tk_win_path);
return;
}
if(tkwin && n >= 1 && n < MAX_NEW_WINDOWS) {
xctx = save_xctx[n];
delete_schematic_data();
@ -922,13 +932,18 @@ void new_schematic(const char *what, const char *top_path, const char *tk_win_pa
if(cnt) {
dbg(1, "new_schematic() switch: %s\n", tk_win_path);
tkwin = Tk_NameToWindow(interp, tk_win_path, mainwindow); /* NULL if tk_win_path not existing */
if(!tkwin) dbg(0, "new_schematic(switch,...): Warning: %s has been destroyed\n", tk_win_path);
if(!tkwin) dbg(0, "new_schematic(\"switch\",...): Warning: %s has been destroyed\n", tk_win_path);
n = -1;
if(tkwin) for(i = 0; i < MAX_NEW_WINDOWS; i++) {
if(tkwin == tknew_window[i]) {
n = i;
break;
}
}
if(n == -1) {
dbg(0, "new_schematic(\"switch\"...): no window to switch to found: %s\n", tk_win_path);
return;
}
/* if window was closed then tkwin == 0 --> do nothing */
if(tkwin && n >= 0 && n < MAX_NEW_WINDOWS) {
xctx = save_xctx[n];

View File

@ -3478,9 +3478,11 @@ proc new_window {what {filename {}} {path {-}}} {
toplevel $path -bg {} -width 400 -height 400
build_widgets $path
pack_widgets $path ;# also does set_bindings $path.drw
set_bindings $path.drw
update
xschem new_schematic create $path $path.drw [abs_sym_path $filename]
# set bindings after creating new schematic otherwise
# a Configure or Expose event is sent before window setup completed.
set_bindings $path.drw
save_ctx $path.drw
return $path
} elseif { $what eq {destroy}} {
@ -3742,7 +3744,6 @@ proc pack_widgets { { topwin {} } } {
pack $topwin.statusbar -after $topwin.drw -anchor sw -fill x
bind $topwin.statusbar.5 <Leave> "set cadgrid \[$topwin.statusbar.5 get\]; xschem set cadgrid \$cadgrid"
bind $topwin.statusbar.3 <Leave> "set cadsnap \[$topwin.statusbar.3 get\]; xschem set cadsnap \$cadsnap"
set_bindings $topwin.drw
}
}