1
1

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

WIDGET_DESTROY.  Adjust all dependencies.
Этот коммит содержится в:
Pavel Roskin 2003-09-10 18:21:40 +00:00
родитель e51f170ad9
Коммит 24737eb1c1
11 изменённых файлов: 189 добавлений и 195 удалений

Просмотреть файл

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

Просмотреть файл

@ -1,5 +1,8 @@
2003-09-10 Pavel Roskin <proski@gnu.org> 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 * dlg.c: Don't supply ID of the current widget with any
callbacks. It's mostly useless and can be found by the callbacks. It's mostly useless and can be found by the
callback. callback.

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -582,17 +582,19 @@ static void prev_node_cmd (Dlg_head *h)
help_callback (h, DLG_DRAW, 0); 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); 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); Widget *w = g_new (Widget, 1);
init_widget (w, y, x, yl, xl, init_widget (w, y, x, yl, xl, (callback_fn) md_callback,
(callback_fn) md_callback, 0, (mouse_h) help_event); (mouse_h) help_event);
return w; return w;
} }

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -284,14 +284,6 @@ view_done (WView *view)
static void view_hook (void *); 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 static int
get_byte (WView *view, unsigned int byte_index) 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); add_hook (&select_file_hook, view_hook, view);
else else
view_labels (view); view_labels (view);
break; return 1;
case WIDGET_DRAW: case WIDGET_DRAW:
display (view); display (view);
view_status (view, TRUE); view_status (view, TRUE);
break; return 1;
case WIDGET_CURSOR: case WIDGET_CURSOR:
if (view->hex_mode) if (view->hex_mode)
view_place_cursor (view); view_place_cursor (view);
break; return 1;
case WIDGET_KEY: case WIDGET_KEY:
i = view_handle_key ((WView *) view, par); i = view_handle_key ((WView *) view, par);
@ -2735,8 +2727,15 @@ view_callback (WView *view, int msg, int par)
view_labels (view); view_labels (view);
return 1; 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 * 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, init_widget (&view->widget, y, x, lines, cols,
(callback_fn) view_callback, (callback_fn) view_callback,
(destroy_fn) view_destroy,
(mouse_h) real_view_event); (mouse_h) real_view_event);
view->hex_mode = default_hex_mode; view->hex_mode = default_hex_mode;

Просмотреть файл

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