From 0464c5e94dbd4aa1ca9d5e5ca32ee932a353eaf1 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Fri, 12 Sep 2003 02:25:41 +0000 Subject: [PATCH] * dlg.c (add_widget): New, safer implementation. Don't rely on the position of the first widget. Disable insertion into running dialogs - it's unused and cannot be tested. --- src/ChangeLog | 4 +++ src/dlg.c | 76 ++++++++++++++++++--------------------------------- 2 files changed, 31 insertions(+), 49 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 589b6f90e..bbc93a5ac 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,9 @@ 2003-09-11 Pavel Roskin + * dlg.c (add_widget): New, safer implementation. Don't rely on + the position of the first widget. Disable insertion into + running dialogs - it's unused and cannot be tested. + * boxes.c (symlink_dialog): Add "OK" and "Cancel" buttons. Don't translate strings, it's done in quick_dialog(). Reported by Ali Akcaagac diff --git a/src/dlg.c b/src/dlg.c index 47631cab0..ace2e2b81 100644 --- a/src/dlg.c +++ b/src/dlg.c @@ -229,63 +229,41 @@ set_idle_proc (Dlg_head *d, int enable) d->flags &= ~DLG_WANT_IDLE; } -/* add component to dialog buffer */ -int add_widget (Dlg_head *where, void *what) +/* + * Insert widget to dialog before current widget and make the new widget + * current. Return widget number. + */ +int +add_widget (Dlg_head *h, void *w) { - Widget_Item *back; - Widget *widget = (Widget *) what; + Widget_Item *new_item; + Widget *widget = (Widget *) w; - /* Don't accept 0 widgets, this could be from widgets that could not */ - /* initialize properly */ - if (!what) - return 0; + /* Don't accept 0 widgets, and running dialogs */ + if (!widget || h->running) + abort (); - widget->x += where->x; - widget->y += where->y; + widget->x += h->x; + widget->y += h->y; + widget->parent = h; - if (where->running){ - Widget_Item *point = where->current; + new_item = g_new (Widget_Item, 1); + new_item->dlg_id = h->count++; + new_item->widget = widget; - where->current = g_new (Widget_Item, 1); - - if (point){ - where->current->next = point->next; - where->current->prev = point; - point->next->prev = where->current; - point->next = where->current; - } else { - where->current->next = where->current; - where->first = where->current; - where->current->prev = where->first; - where->first->next = where->current; - } + if (h->current) { + new_item->next = h->current; + new_item->prev = h->current->prev; + h->current->prev->next = new_item; + h->current->prev = new_item; } else { - back = where->current; - where->current = g_new (Widget_Item, 1); - if (back){ - back->prev = where->current; - where->current->next = back; - } else { - where->current->next = where->current; - where->first = where->current; - } - - where->current->prev = where->first; - where->first->next = where->current; - + new_item->prev = new_item; + new_item->next = new_item; + h->first = new_item; } - where->current->dlg_id = where->count; - where->current->widget = what; - where->current->widget->parent = where; - where->count++; - - /* If the widget is inserted in a running dialog */ - if (where->running) { - send_message (widget, WIDGET_INIT, 0); - send_message (widget, WIDGET_DRAW, 0); - } - return (where->count - 1); + h->current = new_item; + return new_item->dlg_id; } /* broadcast a message to all the widgets in a dialog that have