* dlg.h: Remove restroy callback. Widgets should use

WIDGET_DESTROY.  Adjust all dependencies.
This commit is contained in:
Pavel Roskin 2003-09-10 18:21:40 +00:00
parent e51f170ad9
commit 24737eb1c1
11 changed files with 189 additions and 195 deletions

View File

@ -190,7 +190,7 @@ edit (const char *_file, int line)
"[Internal File Editor]", NULL, DLG_WANT_TAB);
init_widget (&(wedit->widget), 0, 0, LINES - 1, COLS,
(callback_fn) edit_callback, (destroy_fn) edit_clean,
(callback_fn) edit_callback,
(mouse_h) edit_mouse_event);
widget_want_cursor (wedit->widget, 1);
@ -344,6 +344,9 @@ static int edit_callback (WEdit *e, int msg, int par)
case WIDGET_CURSOR:
widget_move (&e->widget, e->curs_row + EDIT_TEXT_VERTICAL_OFFSET, e->curs_col + e->start_col);
return 1;
case WIDGET_DESTROY:
edit_clean (e);
return 1;
}
return default_proc (msg, par);
}

View File

@ -1,5 +1,8 @@
2003-09-10 Pavel Roskin <proski@gnu.org>
* dlg.h: Remove restroy callback. Widgets should use
WIDGET_DESTROY. Adjust all dependencies.
* dlg.c: Don't supply ID of the current widget with any
callbacks. It's mostly useless and can be found by the
callback.

View File

@ -118,15 +118,13 @@ void dlg_erase (Dlg_head *h)
void
init_widget (Widget *w, int y, int x, int lines, int cols,
callback_fn callback, destroy_fn destroy,
mouse_h mouse_handler)
callback_fn callback, mouse_h mouse_handler)
{
w->x = x;
w->y = y;
w->cols = cols;
w->lines = lines;
w->callback = callback;
w->destroy = destroy;
w->mouse = mouse_handler;
w->parent = 0;
@ -836,8 +834,6 @@ destroy_dlg (Dlg_head *h)
dlg_broadcast_msg (h, WIDGET_DESTROY, 0);
c = h->current;
for (i = 0; i < h->count; i++){
if (c->widget->destroy)
c->widget->destroy (c->widget);
c = c->next;
if (h->current){
g_free (h->current->widget);
@ -878,7 +874,6 @@ void dlg_replace_widget (Dlg_head *h, Widget *old, Widget *new)
/* First kill the widget */
new->parent = h;
send_message (old, WIDGET_DESTROY, 0);
(*old->destroy) (old);
/* We insert the new widget */
p->widget = new;

View File

@ -93,9 +93,6 @@ typedef struct Dlg_head {
} Dlg_head;
/* Call when the widget is destroyed */
typedef void (*destroy_fn)(void *widget);
/* Widget callback */
typedef int (*callback_fn)(void *widget, int Msg, int Par);
@ -105,7 +102,6 @@ typedef struct Widget {
int cols, lines;
int options;
callback_fn callback; /* The callback function */
destroy_fn destroy;
mouse_h mouse;
struct Dlg_head *parent;
} Widget;
@ -166,8 +162,7 @@ void widget_set_size (Widget *widget, int x1, int y1, int x2, int y2);
void dlg_broadcast_msg (Dlg_head *h, int message, int reverse);
void init_widget (Widget *w, int y, int x, int lines, int cols,
callback_fn callback, destroy_fn destroy,
mouse_h mouse_handler);
callback_fn callback, mouse_h mouse_handler);
/* Default callback for dialogs */
cb_ret_t default_dlg_callback (Dlg_head *h, dlg_msg_t msg, int parm);

View File

@ -582,17 +582,19 @@ static void prev_node_cmd (Dlg_head *h)
help_callback (h, DLG_DRAW, 0);
}
static int md_callback (Widget *w, int msg, int par)
static int
md_callback (Widget *w, int msg, int par)
{
return default_proc (msg, par);
}
static Widget *mousedispatch_new (int y, int x, int yl, int xl)
static Widget *
mousedispatch_new (int y, int x, int yl, int xl)
{
Widget *w = g_new (Widget, 1);
init_widget (w, y, x, yl, xl,
(callback_fn) md_callback, 0, (mouse_h) help_event);
init_widget (w, y, x, yl, xl, (callback_fn) md_callback,
(mouse_h) help_event);
return w;
}

View File

@ -217,19 +217,15 @@ static void info_hook (void *data)
info_show_info (info);
}
static void info_destroy (WInfo *info)
static int
info_callback (WInfo *info, int msg, int par)
{
delete_hook (&select_file_hook, info_hook);
}
static int info_callback (WInfo *info, int msg, int par)
{
switch (msg){
switch (msg) {
case WIDGET_INIT:
add_hook (&select_file_hook, info_hook, info);
info->ready = 0;
break;
return 1;
case WIDGET_DRAW:
info_hook (info);
@ -238,8 +234,13 @@ static int info_callback (WInfo *info, int msg, int par)
case WIDGET_FOCUS:
return 0;
case WIDGET_DESTROY:
delete_hook (&select_file_hook, info_hook);
default:
return default_proc (msg, par);
}
return default_proc (msg, par);
}
WInfo *info_new ()
@ -247,8 +248,7 @@ WInfo *info_new ()
WInfo *info = g_new (WInfo, 1);
init_widget (&info->widget, 0, 0, 0, 0, (callback_fn)
info_callback, (destroy_fn) info_destroy,
(mouse_h) info_event);
info_callback, (mouse_h) info_event);
/* We do not want the cursor */
widget_want_cursor (info->widget, 0);

View File

@ -470,10 +470,6 @@ menubar_event (Gpm_Event *event, WMenu *menubar)
return MOU_NORMAL;
}
static void menubar_destroy (WMenu *menubar)
{
}
/*
* Properly space menubar items. Should be called when menubar is created
* and also when widget width is changed (i.e. upon xterm resize).
@ -538,7 +534,7 @@ menubar_new (int y, int x, int cols, Menu *menu[], int items)
init_widget (&menubar->widget, y, x, 1, cols,
(callback_fn) menubar_callback,
(destroy_fn) menubar_destroy, (mouse_h) menubar_event);
(mouse_h) menubar_event);
menubar->menu = menu;
menubar->active = 0;
menubar->dropped = 0;

View File

@ -954,8 +954,7 @@ panel_new (const char *panel_name)
/* No know sizes of the panel at startup */
init_widget (&panel->widget, 0, 0, 0, 0, (callback_fn)
panel_callback, (destroy_fn) panel_destroy,
(mouse_h) panel_event);
panel_callback, (mouse_h) panel_event);
/* We do not want the cursor */
widget_want_cursor (panel->widget, 0);
@ -2183,12 +2182,9 @@ panel_callback (WPanel *panel, int msg, int par)
Dlg_head *h = panel->widget.parent;
switch (msg){
case WIDGET_INIT:
return 1;
case WIDGET_DRAW:
paint_panel (panel);
break;
return 1;
case WIDGET_FOCUS:
current_panel = panel;
@ -2230,9 +2226,14 @@ panel_callback (WPanel *panel, int msg, int par)
case WIDGET_KEY:
return panel_key (panel, par);
break;
case WIDGET_DESTROY:
panel_destroy (panel);
return 1;
default:
return default_proc (msg, par);
}
return default_proc (msg, par);
}
void

View File

@ -1056,12 +1056,19 @@ tree_callback (WTree *tree, int msg, int par)
/* FIXME: Should find a better way of changing the color of the
selected item */
case WIDGET_UNFOCUS:
tree->active = 0;
show_tree (tree);
return 1;
case WIDGET_DESTROY:
tree_destroy (tree);
return 1;
default:
return default_proc (msg, par);
}
return default_proc (msg, par);
}
WTree *
@ -1070,8 +1077,7 @@ tree_new (int is_panel, int y, int x, int lines, int cols)
WTree *tree = g_new (WTree, 1);
init_widget (&tree->widget, y, x, lines, cols,
(callback_fn) tree_callback, (destroy_fn) tree_destroy,
(mouse_h) event_callback);
(callback_fn) tree_callback, (mouse_h) event_callback);
tree->is_panel = is_panel;
tree->selected_ptr = 0;

View File

@ -284,14 +284,6 @@ view_done (WView *view)
static void view_hook (void *);
static void
view_destroy (WView *view)
{
view_done (view);
if (view->have_frame)
delete_hook (&select_file_hook, view_hook);
}
static int
get_byte (WView *view, unsigned int byte_index)
{
@ -2701,17 +2693,17 @@ view_callback (WView *view, int msg, int par)
add_hook (&select_file_hook, view_hook, view);
else
view_labels (view);
break;
return 1;
case WIDGET_DRAW:
display (view);
view_status (view, TRUE);
break;
return 1;
case WIDGET_CURSOR:
if (view->hex_mode)
view_place_cursor (view);
break;
return 1;
case WIDGET_KEY:
i = view_handle_key ((WView *) view, par);
@ -2735,8 +2727,15 @@ view_callback (WView *view, int msg, int par)
view_labels (view);
return 1;
case WIDGET_DESTROY:
view_done (view);
if (view->have_frame)
delete_hook (&select_file_hook, view_hook);
return 1;
default:
return default_proc (msg, par);
}
return default_proc (msg, par);
}
WView *
@ -2746,7 +2745,6 @@ view_new (int y, int x, int cols, int lines, int is_panel)
init_widget (&view->widget, y, x, lines, cols,
(callback_fn) view_callback,
(destroy_fn) view_destroy,
(mouse_h) real_view_event);
view->hex_mode = default_hex_mode;

View File

@ -56,9 +56,6 @@ button_callback (WButton *b, int Msg, int Par)
Dlg_head *h = b->widget.parent;
switch (Msg) {
case WIDGET_INIT:
return 1;
case WIDGET_HOTKEY:
/*
* Don't let the default button steal Enter from the current
@ -85,7 +82,7 @@ button_callback (WButton *b, int Msg, int Par)
case WIDGET_KEY:
if (Par != ' ' && Par != '\n')
break;
return 0;
if (b->callback)
stop = (*b->callback) (b->action);
@ -152,13 +149,15 @@ button_callback (WButton *b, int Msg, int Par)
widget_move (&b->widget, 0, b->hotpos + off);
addch ((unsigned char) b->text[b->hotpos]);
}
if (Msg == WIDGET_FOCUS)
break;
else
return 1;
break;
return 1;
case WIDGET_DESTROY:
g_free (b->text);
return 1;
default:
return default_proc (Msg, Par);
}
return default_proc (Msg, Par);
}
static int
@ -176,12 +175,6 @@ button_event (Gpm_Event *event, WButton *b)
return MOU_NORMAL;
}
static void
button_destroy (WButton *b)
{
g_free (b->text);
}
static int
button_len (const char *text, unsigned int flags)
{
@ -227,7 +220,7 @@ button_new (int y, int x, int action, int flags, char *text,
init_widget (&b->widget, y, x, 1, button_len (text, flags),
(callback_fn) button_callback,
(destroy_fn) button_destroy, (mouse_h)button_event);
(mouse_h) button_event);
b->action = action;
b->flags = flags;
@ -378,7 +371,7 @@ radio_new (int y, int x, int count, char **texts, int use_hotkey)
}
init_widget (&r->widget, y, x, count, max, (callback_fn) radio_callback,
0, (mouse_h) radio_event);
(mouse_h) radio_event);
r->state = 1;
r->pos = 0;
r->sel = 0;
@ -405,25 +398,26 @@ check_callback (WCheck *c, int Msg, int Par)
return 1;
case WIDGET_HOTKEY:
if (c->hotkey==Par ||
(c->hotkey>='a' && c->hotkey<='z' && c->hotkey-32==Par)){
check_callback (c, WIDGET_KEY, ' '); /* make action */
if (c->hotkey == Par
|| (c->hotkey >= 'a' && c->hotkey <= 'z'
&& c->hotkey - 32 == Par)) {
check_callback (c, WIDGET_KEY, ' '); /* make action */
return 1;
} else
return 0;
}
return 0;
case WIDGET_KEY:
if (Par != ' ')
break;
return 0;
c->state ^= C_BOOL;
c->state ^= C_CHANGE;
(*h->callback) (h, DLG_ACTION, 0);
(*h->callback) (h, DLG_ACTION, 0);
check_callback (c, WIDGET_FOCUS, ' ');
return 1;
case WIDGET_CURSOR:
widget_move (&c->widget, 0, 1);
break;
return 1;
case WIDGET_FOCUS:
case WIDGET_UNFOCUS:
@ -432,14 +426,20 @@ check_callback (WCheck *c, int Msg, int Par)
widget_move (&c->widget, 0, 0);
printw ("[%c] %s", (c->state & C_BOOL) ? 'x' : ' ', c->text);
if (c->hotpos >= 0){
if (c->hotpos >= 0) {
attrset ((Msg == WIDGET_FOCUS) ? HOT_FOCUSC : HOT_NORMALC);
widget_move (&c->widget, 0, + c->hotpos+4);
addch ((unsigned char)c->text [c->hotpos]);
widget_move (&c->widget, 0, +c->hotpos + 4);
addch ((unsigned char) c->text[c->hotpos]);
}
return 1;
case WIDGET_DESTROY:
g_free (c->text);
return 1;
default:
return default_proc (Msg, Par);
}
return default_proc (Msg, Par);
}
static int
@ -459,12 +459,6 @@ check_event (Gpm_Event *event, WCheck *c)
return MOU_NORMAL;
}
static void
check_destroy (WCheck *c)
{
g_free (c->text);
}
WCheck *
check_new (int y, int x, int state, char *text)
{
@ -473,7 +467,7 @@ check_new (int y, int x, int state, char *text)
init_widget (&c->widget, y, x, 1, strlen (text),
(callback_fn)check_callback,
(destroy_fn)check_destroy, (mouse_h) check_event);
(mouse_h) check_event);
c->state = state ? C_BOOL : 0;
c->text = g_strdup (text);
c->hotkey = 0;
@ -505,41 +499,55 @@ label_callback (WLabel *l, int Msg, int Par)
{
Dlg_head *h = l->widget.parent;
if (Msg == WIDGET_INIT)
switch (Msg) {
case WIDGET_INIT:
return 1;
/* We don't want to get the focus */
if (Msg == WIDGET_FOCUS)
/* We don't want to get the focus */
case WIDGET_FOCUS:
return 0;
if (Msg == WIDGET_DRAW && l->text){
char *p = l->text, *q, c = 0;
int y = 0;
if (l->transparent)
attrset (DEFAULT_COLOR);
else
attrset (NORMALC);
for (;;){
int xlen;
q = strchr (p, '\n');
if (q){
c = *q;
*q = 0;
case WIDGET_DRAW:
{
char *p = l->text, *q, c = 0;
int y = 0;
if (!l->text)
return 1;
if (l->transparent)
attrset (DEFAULT_COLOR);
else
attrset (NORMALC);
for (;;) {
int xlen;
q = strchr (p, '\n');
if (q) {
c = *q;
*q = 0;
}
widget_move (&l->widget, y, 0);
printw ("%s", p);
xlen = l->widget.cols - strlen (p);
if (xlen > 0)
printw ("%*s", xlen, " ");
if (!q)
break;
*q = c;
p = q + 1;
y++;
}
widget_move (&l->widget, y, 0);
printw ("%s", p);
xlen = l->widget.cols - strlen (p);
if (xlen > 0)
printw ("%*s", xlen, " ");
if (!q)
break;
*q = c;
p = q + 1;
y++;
return 1;
}
case WIDGET_DESTROY:
g_free (l->text);
return 1;
default:
return default_proc (Msg, Par);
}
return default_proc (Msg, Par);
}
void
@ -570,13 +578,6 @@ label_set_text (WLabel *label, char *text)
label->widget.cols = newcols;
}
static void
label_destroy (WLabel *l)
{
if (l->text)
g_free (l->text);
}
WLabel *
label_new (int y, int x, const char *text)
{
@ -591,8 +592,7 @@ label_new (int y, int x, const char *text)
l = g_new (WLabel, 1);
init_widget (&l->widget, y, x, 1, width,
(callback_fn) label_callback,
(destroy_fn) label_destroy, NULL);
(callback_fn) label_callback, NULL);
l->text = text ? g_strdup (text) : 0;
l->auto_adjust_cols = 1;
l->transparent = 0;
@ -671,20 +671,13 @@ gauge_show (WGauge *g, int shown)
gauge_callback (g, WIDGET_DRAW, 0);
}
static void
gauge_destroy (WGauge *g)
{
/* nothing */
}
WGauge *
gauge_new (int y, int x, int shown, int max, int current)
{
WGauge *g = g_new (WGauge, 1);
init_widget (&g->widget, y, x, 1, gauge_len,
(callback_fn) gauge_callback,
(destroy_fn) gauge_destroy, NULL);
(callback_fn) gauge_callback, NULL);
g->shown = shown;
if (max == 0)
max = 1; /* I do not like division by zero :) */
@ -1032,8 +1025,7 @@ input_destroy (WInput *in)
g_free (in->buffer);
free_completions (in);
if (in->history_name)
g_free (in->history_name);
g_free (in->history_name);
}
static char disable_update = 0;
@ -1584,13 +1576,19 @@ input_callback (WInput *in, int Msg, int Par)
case WIDGET_UNFOCUS:
case WIDGET_DRAW:
update_input (in, 0);
break;
return default_proc (Msg, Par);
case WIDGET_CURSOR:
widget_move (&in->widget, 0, in->point - in->first_shown);
return 1;
case WIDGET_DESTROY:
input_destroy (in);
return 1;
default:
return default_proc (Msg, Par);
}
return default_proc (Msg, Par);
}
static int
@ -1622,7 +1620,7 @@ input_new (int y, int x, int color, int len, const char *def_text,
int initial_buffer_len;
init_widget (&in->widget, y, x, 1, len, (callback_fn) input_callback,
(destroy_fn) input_destroy, (mouse_h) input_event);
(mouse_h) input_event);
/* history setup */
in->history = NULL;
@ -1983,6 +1981,20 @@ listbox_key (WListbox *l, int key)
return 0;
}
static void
listbox_destroy (WListbox *l)
{
WLEntry *n, *p = l->list;
int i;
for (i = 0; i < l->count; i++){
n = p->next;
g_free (p->text);
g_free (p);
p = n;
}
}
static int
listbox_callback (WListbox *l, int msg, int par)
{
@ -2027,8 +2039,14 @@ listbox_callback (WListbox *l, int msg, int par)
case WIDGET_DRAW:
listbox_draw (l, msg != WIDGET_UNFOCUS);
return 1;
case WIDGET_DESTROY:
listbox_destroy (l);
return 1;
default:
return default_proc (msg, par);
}
return default_proc (msg, par);
}
static int
@ -2092,20 +2110,6 @@ listbox_event (Gpm_Event *event, WListbox *l)
return MOU_NORMAL;
}
static void
listbox_destroy (WListbox *l)
{
WLEntry *n, *p = l->list;
int i;
for (i = 0; i < l->count; i++){
n = p->next;
g_free (p->text);
g_free (p);
p = n;
}
}
WListbox *
listbox_new (int y, int x, int width, int height, lcback callback)
{
@ -2114,7 +2118,7 @@ listbox_new (int y, int x, int width, int height, lcback callback)
init_widget (&l->widget, y, x, height, width,
(callback_fn) listbox_callback,
(destroy_fn) listbox_destroy, (mouse_h) listbox_event);
(mouse_h) listbox_event);
l->list = l->top = l->current = 0;
l->pos = 0;
@ -2231,22 +2235,20 @@ listbox_get_current (WListbox *l, char **string, char **extra)
*extra = l->current->data;
}
static int
buttonbar_callback (WButtonBar *bb, int msg, int par)
{
int i;
switch (msg){
case WIDGET_INIT:
return 1;
switch (msg) {
case WIDGET_FOCUS:
return 0;
case WIDGET_HOTKEY:
for (i = 0; i < 10; i++){
if (par == KEY_F(i+1) && bb->labels [i].function){
(*bb->labels [i].function)(bb->labels [i].data);
for (i = 0; i < 10; i++) {
if (par == KEY_F (i + 1) && bb->labels[i].function) {
(*bb->labels[i].function) (bb->labels[i].data);
return 1;
}
}
@ -2258,29 +2260,25 @@ buttonbar_callback (WButtonBar *bb, int msg, int par)
widget_move (&bb->widget, 0, 0);
attrset (DEFAULT_COLOR);
printw ("%-*s", bb->widget.cols, "");
for (i = 0; i < COLS/8 && i < 10; i++){
widget_move (&bb->widget, 0, i*8);
for (i = 0; i < COLS / 8 && i < 10; i++) {
widget_move (&bb->widget, 0, i * 8);
attrset (DEFAULT_COLOR);
printw ("%d", i+1);
printw ("%d", i + 1);
attrset (SELECTED_COLOR);
printw ("%-*s", ((i+1) * 8 == COLS ? 5 : 6),
bb->labels [i].text ? bb->labels [i].text : "");
printw ("%-*s", ((i + 1) * 8 == COLS ? 5 : 6),
bb->labels[i].text ? bb->labels[i].text : "");
attrset (DEFAULT_COLOR);
}
attrset (SELECTED_COLOR);
return 1;
}
return default_proc (msg, par);
}
static void
buttonbar_destroy (WButtonBar *bb)
{
int i;
case WIDGET_DESTROY:
for (i = 0; i < 10; i++)
g_free (bb->labels[i].text);
return 1;
for (i = 0; i < 10; i++){
if (bb->labels [i].text)
g_free (bb->labels [i].text);
default:
return default_proc (msg, par);
}
}
@ -2307,7 +2305,7 @@ buttonbar_new (int visible)
init_widget (&bb->widget, LINES-1, 0, 1, COLS,
(callback_fn) buttonbar_callback,
(destroy_fn) buttonbar_destroy, (mouse_h) buttonbar_event);
(mouse_h) buttonbar_event);
bb->visible = visible;
for (i = 0; i < 10; i++){
@ -2393,25 +2391,22 @@ groupbox_callback (WGroupbox *g, int msg, int parm)
addstr (g->title);
return MSG_HANDLED;
case WIDGET_DESTROY:
g_free (g->title);
return MSG_HANDLED;
default:
return default_proc (msg, parm);
}
}
static void
groupbox_destroy (WGroupbox *g)
{
g_free (g->title);
}
WGroupbox *
groupbox_new (int x, int y, int width, int height, char *title)
{
WGroupbox *g = g_new (WGroupbox, 1);
init_widget (&g->widget, y, x, height, width,
(callback_fn) groupbox_callback,
(destroy_fn) groupbox_destroy, NULL);
(callback_fn) groupbox_callback, NULL);
g->widget.options &= ~W_WANT_CURSOR;
widget_want_hotkey (g->widget, 0);