WST_FOCUSED: add new state and handle it.

Notify widget's owner that widget gets or loses focus.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2016-06-12 18:15:02 +03:00
parent 3debdac657
commit c37f9b770a
11 changed files with 38 additions and 36 deletions

View File

@ -75,8 +75,8 @@ check_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d
return MSG_NOT_HANDLED;
c->state ^= C_BOOL;
c->state ^= C_CHANGE;
send_message (w, sender, MSG_FOCUS, ' ', data);
send_message (w->owner, w, MSG_NOTIFY, 0, NULL);
widget_redraw (w);
send_message (w->owner, w, MSG_NOTIFY, (int) MSG_KEY, NULL);
return MSG_HANDLED;
case MSG_CURSOR:

View File

@ -195,17 +195,9 @@ dlg_unfocus (WDialog * h)
{
Widget *wh = WIDGET (h);
if (widget_get_state (wh, WST_CONSTRUCT) || widget_get_state (wh, WST_ACTIVE))
{
Widget *current = WIDGET (h->current->data);
if (send_message (current, NULL, MSG_UNFOCUS, 0, NULL) == MSG_HANDLED)
{
send_message (h, current, MSG_UNFOCUS, 0, NULL);
return TRUE;
}
}
if ((widget_get_state (wh, WST_CONSTRUCT) || widget_get_state (wh, WST_ACTIVE))
&& widget_set_state (WIDGET (h->current->data), WST_FOCUSED, FALSE) == MSG_HANDLED)
return TRUE;
}
return FALSE;
@ -287,7 +279,7 @@ do_select_widget (WDialog * h, GList * w, select_dir_t dir)
if (widget_overlapped (w0, WIDGET (h->current->data)))
{
send_message (h->current->data, NULL, MSG_DRAW, 0, NULL);
send_message (h->current->data, NULL, MSG_FOCUS, 0, NULL);
widget_set_state (WIDGET (h->current->data), WST_FOCUSED, TRUE);
}
}
@ -855,7 +847,7 @@ dlg_create (gboolean modal, int y1, int x1, int lines, int cols, widget_pos_flag
w->pos_flags = pos_flags;
w->options |= WOP_SELECTABLE | WOP_TOP_SELECT;
w->state |= WST_CONSTRUCT;
w->state |= WST_CONSTRUCT | WST_FOCUSED;
if (modal)
w->state |= WST_MODAL;
@ -975,7 +967,7 @@ add_widget_autopos (WDialog * h, void *w, widget_pos_flags_t pos_flags, const vo
{
send_message (widget, NULL, MSG_INIT, 0, NULL);
send_message (widget, NULL, MSG_DRAW, 0, NULL);
send_message (widget, NULL, MSG_FOCUS, 0, NULL);
widget_set_state (widget, WST_FOCUSED, TRUE);
}
return widget->id;
@ -1081,11 +1073,8 @@ dlg_focus (WDialog * h)
if (widget_get_options (current, WOP_SELECTABLE)
&& !widget_get_state (current, WST_DISABLED)
&& (send_message (current, NULL, MSG_FOCUS, 0, NULL) == MSG_HANDLED))
{
send_message (h, current, MSG_FOCUS, 0, NULL);
&& widget_set_state (current, WST_FOCUSED, TRUE) == MSG_HANDLED)
return TRUE;
}
}
}

View File

@ -84,8 +84,7 @@ radio_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d
{
case ' ':
r->sel = r->pos;
send_message (w, sender, MSG_FOCUS, ' ', data);
send_message (w->owner, w, MSG_NOTIFY, 0, NULL);
widget_set_state (w, WST_FOCUSED, TRUE);
return MSG_HANDLED;
case KEY_UP:
@ -109,9 +108,8 @@ radio_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d
}
case MSG_CURSOR:
send_message (w, sender, MSG_FOCUS, ' ', data);
widget_move (r, r->pos, 1);
send_message (w->owner, w, MSG_NOTIFY, 0, NULL);
widget_set_state (w, WST_FOCUSED, TRUE);
return MSG_HANDLED;
case MSG_UNFOCUS:

View File

@ -249,6 +249,20 @@ widget_set_state (Widget * w, widget_state_t state, gboolean enable)
ret = send_message (w, NULL, MSG_DRAW, 0, NULL);
break;
case WST_FOCUSED:
{
widget_msg_t msg;
msg = enable ? MSG_FOCUS : MSG_UNFOCUS;
ret = send_message (w, NULL, msg, 0, NULL);
if (ret == MSG_HANDLED)
{
/* Notify owner that focus was moved from one widget to another */
send_message (w->owner, w, MSG_NOTIFY, (int) msg, NULL);
}
}
break;
default:
break;
}

View File

@ -81,6 +81,7 @@ typedef enum
WST_DISABLED = (1 << 0), /* Widget cannot be selected */
WST_IDLE = (1 << 1),
WST_MODAL = (1 << 2), /* Widget (dialog) is modal */
WST_FOCUSED = (1 << 3),
WST_CONSTRUCT = (1 << 15), /* Dialog has been constructed but not run yet */
WST_ACTIVE = (1 << 16), /* Dialog is visible and active */

View File

@ -155,7 +155,7 @@ edit_save_mode_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm
switch (msg)
{
case MSG_NOTIFY:
if (sender != NULL && sender->id == edit_save_mode_radio_id)
if (sender != NULL && sender->id == edit_save_mode_radio_id && parm == (int) MSG_FOCUS)
{
Widget *ww;

View File

@ -279,7 +279,7 @@ update_mode (WDialog * h)
{
print_flags ();
chown_info_update ();
send_message (h->current->data, NULL, MSG_FOCUS, 0, NULL);
widget_set_state (WIDGET (h->current->data), WST_FOCUSED, TRUE);
}
/* --------------------------------------------------------------------------------------------- */
@ -546,7 +546,7 @@ advanced_chown_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm
x_toggle ^= (1 << parm);
update_mode (h);
dlg_broadcast_msg (h, MSG_DRAW);
send_message (h->current->data, NULL, MSG_FOCUS, 0, NULL);
widget_set_state (WIDGET (h->current->data), WST_FOCUSED, TRUE);
break;
case XCTRL ('x'):
@ -562,7 +562,7 @@ advanced_chown_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm
x_toggle ^= (1 << parm);
update_mode (h);
dlg_broadcast_msg (h, MSG_DRAW);
send_message (h->current->data, NULL, MSG_FOCUS, 0, NULL);
widget_set_state (WIDGET (h->current->data), WST_FOCUSED, TRUE);
break;
case 'x':

View File

@ -130,7 +130,7 @@ configure_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, voi
{
case MSG_NOTIFY:
/* message from "Single press" checkbutton */
if (sender != NULL && sender->id == configure_old_esc_mode_id)
if (sender != NULL && sender->id == configure_old_esc_mode_id && parm == (int) MSG_FOCUS)
{
const gboolean not_single = !(CHECK (sender)->state & C_BOOL);
Widget *ww;
@ -251,7 +251,7 @@ panel_listing_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm,
switch (msg)
{
case MSG_NOTIFY:
if (sender != NULL && sender->id == panel_listing_types_id)
if (sender != NULL && sender->id == panel_listing_types_id && parm == (int) MSG_FOCUS)
{
WCheck *ch;
WInput *in1, *in2, *in3;
@ -271,7 +271,7 @@ panel_listing_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm,
return MSG_HANDLED;
}
if (sender != NULL && sender->id == mini_user_status_id)
if (sender != NULL && sender->id == mini_user_status_id && parm == (int) MSG_FOCUS)
{
WInput *in;
@ -373,7 +373,7 @@ confvfs_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void
{
case MSG_NOTIFY:
/* message from "Always use ftp proxy" checkbutton */
if (sender != NULL && sender->id == ftpfs_always_use_proxy_id)
if (sender != NULL && sender->id == ftpfs_always_use_proxy_id && parm == (int) MSG_FOCUS)
{
const gboolean not_use = !(CHECK (sender)->state & C_BOOL);
Widget *wi;

View File

@ -230,7 +230,7 @@ chmod_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d
if (sender == WIDGET (check_perm[i].check))
break;
if (i < check_perm_num)
if (i < check_perm_num && parm == (int) MSG_KEY)
{
char buffer[BUF_TINY];

View File

@ -479,7 +479,7 @@ find_parm_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, voi
return MSG_HANDLED;
case MSG_NOTIFY:
if (sender == WIDGET (ignore_dirs_cbox))
if (sender == WIDGET (ignore_dirs_cbox) && parm == (int) MSG_FOCUS)
{
gboolean disable = !(ignore_dirs_cbox->state & C_BOOL);

View File

@ -370,7 +370,7 @@ layout_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *
return MSG_HANDLED;
case MSG_NOTIFY:
if (sender == WIDGET (radio_widget))
if (sender == WIDGET (radio_widget) && parm == (int) MSG_FOCUS)
{
if (panels_layout.horizontal_split != radio_widget->sel)
{
@ -404,7 +404,7 @@ layout_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *
return MSG_HANDLED;
}
if (sender == WIDGET (check_options[0].widget))
if (sender == WIDGET (check_options[0].widget) && parm == (int) MSG_FOCUS)
{
int eq;