1
1

* dlg.h: Merge Widget_Item into Widget. Massive adjustment.

Этот коммит содержится в:
Pavel Roskin 2003-09-12 23:38:42 +00:00
родитель d9292b5524
Коммит c0b34498dd
13 изменённых файлов: 104 добавлений и 110 удалений

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

@ -450,7 +450,7 @@ edit_drop_menu_cmd (WEdit *e, int which)
edit_menubar->selected = which;
}
edit_menubar->previous_widget = e->widget.parent->current->widget;
edit_menubar->previous_widget = e->widget.parent->current;
dlg_select_widget (e->widget.parent, edit_menubar);
}

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

@ -1,5 +1,7 @@
2003-09-12 Pavel Roskin <proski@gnu.org>
* dlg.h: Merge Widget_Item into Widget. Massive adjustment.
* main.c (setup_panels_and_run_mc): Use straight widget order in
midnight_dlg. Select initial panel by dlg_select_widget().

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

@ -214,7 +214,7 @@ static void update_mode (Dlg_head * h)
attrset (COLOR_NORMAL);
dlg_move (h, BY + 2, 9);
printw ("%12o", get_mode ());
send_message (h->current->widget, WIDGET_FOCUS, 0);
send_message (h->current, WIDGET_FOCUS, 0);
}
static cb_ret_t
@ -453,7 +453,7 @@ advanced_chown_callback (Dlg_head *h, dlg_msg_t msg, int parm)
x_toggle ^= (1 << parm);
update_mode (h);
dlg_broadcast_msg (h, WIDGET_DRAW, 0);
send_message (h->current->widget, WIDGET_FOCUS, 0);
send_message (h->current, WIDGET_FOCUS, 0);
break;
case XCTRL ('x'):
@ -470,7 +470,7 @@ advanced_chown_callback (Dlg_head *h, dlg_msg_t msg, int parm)
x_toggle ^= (1 << parm);
update_mode (h);
dlg_broadcast_msg (h, WIDGET_DRAW, 0);
send_message (h->current->widget, WIDGET_FOCUS, 0);
send_message (h->current, WIDGET_FOCUS, 0);
break;
case 'x':
@ -483,7 +483,7 @@ advanced_chown_callback (Dlg_head *h, dlg_msg_t msg, int parm)
if (f_pos > 2)
break;
flag_pos = f_pos * 3 + i; /* (strchr(ch_perm,parm)-ch_perm); */
if (((WButton *) h->current->widget)->text[(flag_pos % 3)] ==
if (((WButton *) h->current)->text[(flag_pos % 3)] ==
'-')
ch_flags[flag_pos] = '+';
else

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

@ -86,7 +86,7 @@ display_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
{
switch (msg) {
case DLG_UNFOCUS:
if ((WRadio *) h->current->widget == my_radio) {
if ((WRadio *) h->current == my_radio) {
assign_text (status, displays_status[my_radio->sel]);
input_set_point (status, 0);
}
@ -94,19 +94,19 @@ display_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
case DLG_KEY:
if (parm == '\n') {
if ((WRadio *) h->current->widget == my_radio) {
if ((WRadio *) h->current == my_radio) {
assign_text (status, displays_status[my_radio->sel]);
dlg_stop (h);
return MSG_HANDLED;
}
if ((WInput *) h->current->widget == user) {
if ((WInput *) h->current == user) {
h->ret_value = B_USER + 6;
dlg_stop (h);
return MSG_HANDLED;
}
if ((WInput *) h->current->widget == status) {
if ((WInput *) h->current == status) {
h->ret_value = B_USER + 7;
dlg_stop (h);
return MSG_HANDLED;
@ -114,8 +114,8 @@ display_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
}
if (tolower (parm) == user_hotkey
&& h->current->widget != (Widget *) user
&& h->current->widget != (Widget *) status) {
&& h->current != (Widget *) user
&& h->current != (Widget *) status) {
my_radio->sel = 3;
dlg_select_widget (h, my_radio); /* force redraw */
dlg_select_widget (h, user);

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

@ -827,16 +827,16 @@ query_callback (Dlg_head *h, dlg_msg_t msg, int parm)
} else {
WLEntry *e, *e1;
e1 = e = ((WListbox *) (h->current->widget))->list;
e1 = e = ((WListbox *) (h->current))->list;
do {
if (!strncmp
(input->buffer + start, e1->text,
end - start - 1)) {
listbox_select_entry ((WListbox *) (h->current->
widget), e1);
listbox_select_entry ((WListbox *) (h->current),
e1);
handle_char (input, parm);
end--;
send_message (h->current->widget, WIDGET_DRAW, 0);
send_message (h->current, WIDGET_DRAW, 0);
break;
}
e1 = e1->next;
@ -861,7 +861,7 @@ query_callback (Dlg_head *h, dlg_msg_t msg, int parm)
int low = 4096;
char *last_text = NULL;
e1 = e = ((WListbox *) (h->current->widget))->list;
e1 = e = ((WListbox *) (h->current))->list;
do {
if (!strncmp
(input->buffer + start, e1->text, end - start)) {
@ -881,8 +881,7 @@ query_callback (Dlg_head *h, dlg_msg_t msg, int parm)
} else {
need_redraw = 1;
listbox_select_entry ((WListbox *) (h->
current->
widget),
current),
e1);
last_text = e1->text;
}
@ -892,7 +891,7 @@ query_callback (Dlg_head *h, dlg_msg_t msg, int parm)
} while (e != e1);
if (need_redraw == 2) {
insert_text (input, last_text, low);
send_message (h->current->widget, WIDGET_DRAW, 0);
send_message (h->current, WIDGET_DRAW, 0);
} else if (need_redraw == 1) {
h->ret_value = B_ENTER;
dlg_stop (h);

145
src/dlg.c
Просмотреть файл

@ -236,7 +236,6 @@ set_idle_proc (Dlg_head *d, int enable)
int
add_widget (Dlg_head *h, void *w)
{
Widget_Item *new_item;
Widget *widget = (Widget *) w;
/* Don't accept 0 widgets, and running dialogs */
@ -246,26 +245,23 @@ add_widget (Dlg_head *h, void *w)
widget->x += h->x;
widget->y += h->y;
widget->parent = h;
new_item = g_new (Widget_Item, 1);
new_item->dlg_id = h->count++;
new_item->widget = widget;
widget->dlg_id = h->count++;
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;
widget->next = h->current;
widget->prev = h->current->prev;
h->current->prev->next = widget;
h->current->prev = widget;
} else {
new_item->prev = new_item;
new_item->next = new_item;
h->first = new_item;
widget->prev = widget;
widget->next = widget;
h->first = widget;
}
if ((h->flags & DLG_REVERSE) || !h->current)
h->current = new_item;
h->current = widget;
return new_item->dlg_id;
return widget->dlg_id;
}
/* broadcast a message to all the widgets in a dialog that have
@ -274,7 +270,7 @@ add_widget (Dlg_head *h, void *w)
static void
dlg_broadcast_msg_to (Dlg_head *h, int message, int reverse, int flags)
{
Widget_Item *p, *first, *wi;
Widget *p, *first, *wi;
if (!h->current)
return;
@ -290,7 +286,7 @@ dlg_broadcast_msg_to (Dlg_head *h, int message, int reverse, int flags)
p = p->prev;
else
p = p->next;
send_message (wi->widget, message, 0);
send_message (wi, message, 0);
} while (first != p);
}
@ -305,7 +301,7 @@ int dlg_focus (Dlg_head *h)
if (!h->current)
return 0;
if (send_message (h->current->widget, WIDGET_FOCUS, 0)){
if (send_message (h->current, WIDGET_FOCUS, 0)){
(*h->callback) (h, DLG_FOCUS, 0);
return 1;
}
@ -318,7 +314,7 @@ dlg_unfocus (Dlg_head *h)
if (!h->current)
return 0;
if (send_message (h->current->widget, WIDGET_UNFOCUS, 0)){
if (send_message (h->current, WIDGET_UNFOCUS, 0)){
(*h->callback) (h, DLG_UNFOCUS, 0);
return 1;
}
@ -356,7 +352,7 @@ Widget *
find_widget_type (Dlg_head *h, void *callback)
{
Widget *w;
Widget_Item *item;
Widget *item;
int i;
if (!h)
@ -366,8 +362,8 @@ find_widget_type (Dlg_head *h, void *callback)
w = 0;
for (i = 0, item = h->current; i < h->count; i++, item = item->next) {
if (item->widget->callback == callback) {
w = item->widget;
if (item->callback == callback) {
w = item;
break;
}
}
@ -376,7 +372,7 @@ find_widget_type (Dlg_head *h, void *callback)
void dlg_one_up (Dlg_head *h)
{
Widget_Item *old;
Widget *old;
old = h->current;
@ -388,15 +384,15 @@ void dlg_one_up (Dlg_head *h)
return;
select_a_widget (h, 0);
if (dlg_overlap (old->widget, h->current->widget)){
send_message (h->current->widget, WIDGET_DRAW, 0);
send_message (h->current->widget, WIDGET_FOCUS, 0);
if (dlg_overlap (old, h->current)){
send_message (h->current, WIDGET_DRAW, 0);
send_message (h->current, WIDGET_FOCUS, 0);
}
}
void dlg_one_down (Dlg_head *h)
{
Widget_Item *old;
Widget *old;
old = h->current;
if (!old)
@ -406,9 +402,9 @@ void dlg_one_down (Dlg_head *h)
return;
select_a_widget (h, 1);
if (dlg_overlap (old->widget, h->current->widget)){
send_message (h->current->widget, WIDGET_DRAW, 0);
send_message (h->current->widget, WIDGET_FOCUS, 0);
if (dlg_overlap (old, h->current)){
send_message (h->current, WIDGET_DRAW, 0);
send_message (h->current, WIDGET_FOCUS, 0);
}
}
@ -418,7 +414,7 @@ int dlg_select_widget (Dlg_head *h, void *w)
return 0;
if (dlg_unfocus (h)){
while (h->current->widget != w)
while (h->current != w)
h->current = h->current->next;
while (!dlg_focus (h))
h->current = h->current->next;
@ -428,20 +424,20 @@ int dlg_select_widget (Dlg_head *h, void *w)
return 0;
}
#define callback(h) (h->current->widget->callback)
#define callback(h) (h->current->callback)
void update_cursor (Dlg_head *h)
{
if (!h->current)
return;
if (h->current->widget->options & W_WANT_CURSOR)
send_message (h->current->widget, WIDGET_CURSOR, 0);
if (h->current->options & W_WANT_CURSOR)
send_message (h->current, WIDGET_CURSOR, 0);
else {
Widget_Item *p = h->current;
Widget *p = h->current;
do {
if (p->widget->options & W_WANT_CURSOR)
if ((*p->widget->callback)(p->widget, WIDGET_CURSOR, 0)){
if (p->options & W_WANT_CURSOR)
if ((*p->callback)(p, WIDGET_CURSOR, 0)){
break;
}
p = p->next;
@ -522,33 +518,34 @@ static inline void dialog_handle_key (Dlg_head *h, int d_key)
}
}
static int dlg_try_hotkey (Dlg_head *h, int d_key)
static int
dlg_try_hotkey (Dlg_head *h, int d_key)
{
Widget_Item *hot_cur;
Widget_Item *previous;
int handled, c;
Widget *hot_cur;
Widget *previous;
int handled, c;
if (!h->current)
return 0;
return 0;
/*
* Explanation: we don't send letter hotkeys to other widgets if
* the currently selected widget is an input line
*/
if (h->current->widget->options & W_IS_INPUT){
if(d_key < 255 && isalpha(d_key))
return 0;
if (h->current->options & W_IS_INPUT) {
if (d_key < 255 && isalpha (d_key))
return 0;
}
/* If it's an alt key, send the message */
c = d_key & ~ALT(0);
if (d_key & ALT(0) && c < 255 && isalpha(c))
d_key = tolower(c);
c = d_key & ~ALT (0);
if (d_key & ALT (0) && c < 255 && isalpha (c))
d_key = tolower (c);
handled = 0;
if (h->current->widget->options & W_WANT_HOTKEY)
handled = callback (h) (h->current->widget, WIDGET_HOTKEY, d_key);
if (h->current->options & W_WANT_HOTKEY)
handled = callback (h) (h->current, WIDGET_HOTKEY, d_key);
/* If not used, send hotkey to other widgets */
if (handled)
@ -558,9 +555,9 @@ static int dlg_try_hotkey (Dlg_head *h, int d_key)
/* send it to all widgets */
do {
if (hot_cur->widget->options & W_WANT_HOTKEY)
handled |= (*hot_cur->widget->callback)
(hot_cur->widget, WIDGET_HOTKEY, d_key);
if (hot_cur->options & W_WANT_HOTKEY)
handled |=
(*hot_cur->callback) (hot_cur, WIDGET_HOTKEY, d_key);
if (!handled)
hot_cur = hot_cur->next;
@ -574,7 +571,7 @@ static int dlg_try_hotkey (Dlg_head *h, int d_key)
return handled;
h->current = hot_cur;
if (!dlg_focus (h)){
if (!dlg_focus (h)) {
h->current = previous;
dlg_focus (h);
}
@ -610,7 +607,7 @@ dlg_key_event (Dlg_head *h, int d_key)
/* not used - then try widget_callback */
if (!handled)
handled = callback (h) (h->current->widget, WIDGET_KEY, d_key);
handled = callback (h) (h->current, WIDGET_KEY, d_key);
/* not used- try to use the unhandled case */
if (!handled)
@ -628,8 +625,8 @@ dlg_key_event (Dlg_head *h, int d_key)
static inline int
dlg_mouse_event (Dlg_head * h, Gpm_Event * event)
{
Widget_Item *item;
Widget_Item *starting_widget = h->current;
Widget *item;
Widget *starting_widget = h->current;
Gpm_Event new_event;
int x = event->x;
int y = event->y;
@ -641,7 +638,7 @@ dlg_mouse_event (Dlg_head * h, Gpm_Event * event)
item = starting_widget;
do {
Widget *widget = item->widget;
Widget *widget = item;
item = item->next;
@ -775,17 +772,16 @@ void
destroy_dlg (Dlg_head *h)
{
int i;
Widget_Item *c;
Widget *c;
if (h->refresh_pushed)
pop_refresh ();
dlg_broadcast_msg (h, WIDGET_DESTROY, 0);
c = h->current;
for (i = 0; i < h->count; i++){
for (i = 0; i < h->count; i++) {
c = c->next;
if (h->current){
g_free (h->current->widget);
if (h->current) {
g_free (h->current);
}
h->current = c;
@ -804,34 +800,35 @@ void widget_set_size (Widget *widget, int y, int x, int lines, int cols)
widget->lines = lines;
}
/* Replace widget old for widget new in the h dialog */
void dlg_replace_widget (Dlg_head *h, Widget *old, Widget *new)
/* Replace widget old_w for widget new_w in the dialog h */
void
dlg_replace_widget (Dlg_head *h, Widget *old_w, Widget *new_w)
{
Widget_Item *p = h->current;
Widget *p = h->current;
int should_focus = 0;
if (!h->current)
return;
return;
do {
if (p->widget == old){
if (p == old_w) {
if (old == h->current->widget)
if (old_w == h->current)
should_focus = 1;
/* We found the widget */
/* First kill the widget */
new->parent = h;
send_message (old, WIDGET_DESTROY, 0);
new_w->parent = h;
send_message (old_w, WIDGET_DESTROY, 0);
/* We insert the new widget */
p->widget = new;
send_message (new, WIDGET_INIT, 0);
if (should_focus){
/* We insert the new_w widget */
p = new_w;
send_message (new_w, WIDGET_INIT, 0);
if (should_focus) {
if (dlg_focus (h) == 0)
select_a_widget (h, 1);
}
send_message (new, WIDGET_DRAW, 0);
send_message (new_w, WIDGET_DRAW, 0);
break;
}
p = p->next;

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

@ -84,8 +84,9 @@ typedef struct Dlg_head {
int refresh_pushed; /* Did the dialog actually run? */
/* Internal variables */
int count; /* number of widgets */
struct Widget_Item *current, *first;
int count; /* Number of widgets */
struct Widget *current; /* Curently active widget */
struct Widget *first; /* First widget added to the dialog */
dlg_cb_fn callback;
void *previous_dialog; /* Pointer to the previously running Dlg_head */
@ -102,6 +103,9 @@ struct Widget {
int x, y;
int cols, lines;
int options;
int dlg_id; /* Number of the widget, starting with 0 */
struct Widget *next;
struct Widget *prev;
callback_fn callback; /* The callback function */
mouse_h mouse;
struct Dlg_head *parent;
@ -113,14 +117,6 @@ struct Widget {
#define W_WANT_IDLE 8
#define W_IS_INPUT 16
/* Items in the circular buffer. Each item refers to a widget. */
typedef struct Widget_Item {
int dlg_id;
struct Widget_Item *next;
struct Widget_Item *prev;
Widget *widget;
} Widget_Item;
/* draw box in window */
void draw_box (Dlg_head *h, int y, int x, int ys, int xs);

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

@ -1054,9 +1054,9 @@ void swap_panels ()
current_panel = panel2;
else
current_panel = panel1;
if (midnight_dlg->current->widget == panels [0].widget)
if (midnight_dlg->current == panels[0].widget)
dlg_select_widget (midnight_dlg, (void *) panels [1].widget);
else if (midnight_dlg->current->widget == panels [1].widget)
else if (midnight_dlg->current == panels[1].widget)
dlg_select_widget (midnight_dlg, (void *) panels [0].widget);
} else {
WPanel *tmp_panel;

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

@ -131,7 +131,7 @@ static int learn_move (int right)
totalcols = (learn_total - 1) / ROWS + 1;
for (i = 0; i < learn_total; i++)
if (learnkeys [i].button == learn_dlg->current->widget) {
if (learnkeys [i].button == learn_dlg->current) {
if (right) {
if (i < learn_total - ROWS)
i += ROWS;

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

@ -980,7 +980,7 @@ menu_last_selected_cmd (void)
{
the_menubar->active = 1;
the_menubar->dropped = drop_menus;
the_menubar->previous_widget = midnight_dlg->current->widget;
the_menubar->previous_widget = midnight_dlg->current;
dlg_select_widget (midnight_dlg, the_menubar);
}

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

@ -399,7 +399,7 @@ menubar_event (Gpm_Event *event, WMenu *menubar)
return MOU_NORMAL;
if (!menubar->dropped){
menubar->previous_widget = menubar->widget.parent->current->widget;
menubar->previous_widget = menubar->widget.parent->current;
menubar->active = 1;
menubar->dropped = 1;
was_active = 0;

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

@ -2297,7 +2297,7 @@ panel_event (Gpm_Event *event, WPanel *panel)
event->y -= 2;
if ((event->type & (GPM_DOWN|GPM_DRAG))){
if (panel != (WPanel *) current_dlg->current->widget)
if (panel != (WPanel *) current_dlg->current)
change_panel ();
if (event->y <= 0){

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

@ -63,7 +63,7 @@ button_callback (WButton *b, widget_msg_t msg, int parm)
* when hotkeys are sent to all widgets before the key is
* handled by the current widget.
*/
if (parm == '\n' && h->current->widget == &b->widget) {
if (parm == '\n' && h->current == &b->widget) {
button_callback (b, WIDGET_KEY, ' ');
return MSG_HANDLED;
}