2011-10-15 14:56:47 +04:00
|
|
|
/*
|
|
|
|
Widgets for the Midnight Commander
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2018-01-01 09:54:11 +03:00
|
|
|
Copyright (C) 1994-2018
|
2014-02-12 10:33:10 +04:00
|
|
|
Free Software Foundation, Inc.
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
Authors:
|
|
|
|
Radek Doulik, 1994, 1995
|
|
|
|
Miguel de Icaza, 1994, 1995
|
|
|
|
Jakub Jelinek, 1995
|
|
|
|
Andrej Borsenkow, 1996
|
|
|
|
Norbert Warmuth, 1997
|
2016-01-19 15:04:35 +03:00
|
|
|
Andrew Borodin <aborodin@vmail.ru>, 2009, 2010, 2013, 2016
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
This file is part of the Midnight Commander.
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is free software: you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation, either version 3 of the License,
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
The Midnight Commander is distributed in the hope that it will be useful,
|
2010-11-12 11:03:57 +03:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2011-10-15 14:56:47 +04:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-11-12 11:03:57 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file check.c
|
|
|
|
* \brief Source: WCheck widget (checkbutton)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "lib/global.h"
|
|
|
|
|
|
|
|
#include "lib/tty/tty.h"
|
|
|
|
#include "lib/widget.h"
|
|
|
|
|
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
|
|
|
|
static cb_ret_t
|
2012-06-26 11:52:21 +04:00
|
|
|
check_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
2010-11-12 11:03:57 +03:00
|
|
|
{
|
2012-10-11 12:25:07 +04:00
|
|
|
WCheck *c = CHECK (w);
|
2010-11-12 11:03:57 +03:00
|
|
|
|
|
|
|
switch (msg)
|
|
|
|
{
|
2012-09-28 15:05:43 +04:00
|
|
|
case MSG_HOTKEY:
|
2010-11-12 11:03:57 +03:00
|
|
|
if (c->text.hotkey != NULL)
|
|
|
|
{
|
2011-01-04 16:44:02 +03:00
|
|
|
if (g_ascii_tolower ((gchar) c->text.hotkey[0]) == parm)
|
2010-11-12 11:03:57 +03:00
|
|
|
{
|
2012-09-28 15:05:43 +04:00
|
|
|
/* make action */
|
|
|
|
send_message (w, sender, MSG_KEY, ' ', data);
|
2010-11-12 11:03:57 +03:00
|
|
|
return MSG_HANDLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return MSG_NOT_HANDLED;
|
|
|
|
|
2012-09-28 15:05:43 +04:00
|
|
|
case MSG_KEY:
|
2010-11-12 11:03:57 +03:00
|
|
|
if (parm != ' ')
|
|
|
|
return MSG_NOT_HANDLED;
|
2016-11-25 09:32:04 +03:00
|
|
|
c->state = !c->state;
|
2016-06-12 18:15:02 +03:00
|
|
|
widget_redraw (w);
|
2016-12-10 19:07:14 +03:00
|
|
|
send_message (w->owner, w, MSG_NOTIFY, 0, NULL);
|
2010-11-12 11:03:57 +03:00
|
|
|
return MSG_HANDLED;
|
|
|
|
|
2012-09-28 15:05:43 +04:00
|
|
|
case MSG_CURSOR:
|
2016-06-11 16:25:37 +03:00
|
|
|
widget_move (w, 0, 1);
|
2010-11-12 11:03:57 +03:00
|
|
|
return MSG_HANDLED;
|
|
|
|
|
2012-09-28 15:05:43 +04:00
|
|
|
case MSG_DRAW:
|
2016-06-13 10:16:45 +03:00
|
|
|
{
|
|
|
|
gboolean focused;
|
|
|
|
|
|
|
|
focused = widget_get_state (w, WST_FOCUSED);
|
|
|
|
widget_selectcolor (w, focused, FALSE);
|
|
|
|
widget_move (w, 0, 0);
|
2016-11-25 09:32:04 +03:00
|
|
|
tty_print_string (c->state ? "[x] " : "[ ] ");
|
2016-06-13 10:16:45 +03:00
|
|
|
hotkey_draw (w, c->text, focused);
|
|
|
|
return MSG_HANDLED;
|
|
|
|
}
|
2010-11-12 11:03:57 +03:00
|
|
|
|
2012-09-28 15:05:43 +04:00
|
|
|
case MSG_DESTROY:
|
2010-11-12 11:03:57 +03:00
|
|
|
release_hotkey (c->text);
|
|
|
|
return MSG_HANDLED;
|
|
|
|
|
|
|
|
default:
|
2012-09-28 15:05:43 +04:00
|
|
|
return widget_default_callback (w, sender, msg, parm, data);
|
2010-11-12 11:03:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2016-01-19 15:04:35 +03:00
|
|
|
static void
|
|
|
|
check_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
|
2010-11-12 11:03:57 +03:00
|
|
|
{
|
2016-01-19 15:04:35 +03:00
|
|
|
(void) event;
|
2011-03-21 16:43:56 +03:00
|
|
|
|
2016-01-19 15:04:35 +03:00
|
|
|
switch (msg)
|
2010-11-12 11:03:57 +03:00
|
|
|
{
|
2016-01-19 15:04:35 +03:00
|
|
|
case MSG_MOUSE_DOWN:
|
2016-08-09 09:35:27 +03:00
|
|
|
widget_select (w);
|
2016-01-19 15:04:35 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MSG_MOUSE_CLICK:
|
|
|
|
send_message (w, NULL, MSG_KEY, ' ', NULL);
|
|
|
|
send_message (w->owner, w, MSG_POST_KEY, ' ', NULL);
|
|
|
|
break;
|
2011-03-21 16:43:56 +03:00
|
|
|
|
2016-01-19 15:04:35 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-11-12 11:03:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
WCheck *
|
2016-11-25 09:32:04 +03:00
|
|
|
check_new (int y, int x, gboolean state, const char *text)
|
2010-11-12 11:03:57 +03:00
|
|
|
{
|
|
|
|
WCheck *c;
|
2012-06-20 15:09:44 +04:00
|
|
|
Widget *w;
|
2010-11-12 11:03:57 +03:00
|
|
|
|
|
|
|
c = g_new (WCheck, 1);
|
2012-06-20 15:09:44 +04:00
|
|
|
w = WIDGET (c);
|
2010-11-12 11:03:57 +03:00
|
|
|
c->text = parse_hotkey (text);
|
|
|
|
/* 4 is width of "[X] " */
|
2016-03-06 09:44:16 +03:00
|
|
|
widget_init (w, y, x, 1, 4 + hotkey_width (c->text), check_callback, check_mouse_callback);
|
2016-06-07 15:03:20 +03:00
|
|
|
w->options |= WOP_SELECTABLE | WOP_WANT_CURSOR | WOP_WANT_HOTKEY;
|
2016-11-25 09:32:04 +03:00
|
|
|
c->state = state;
|
2010-11-12 11:03:57 +03:00
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
2012-06-20 15:09:44 +04:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|