Remove unneeded `struct` keyword for typedef'd structs
[midnight-commander.git] / lib / widget / check.c
blob3ad7e0504812ae375e1755b563e2acbb1109a414
1 /*
2 Widgets for the Midnight Commander
4 Copyright (C) 1994-2016
5 Free Software Foundation, Inc.
7 Authors:
8 Radek Doulik, 1994, 1995
9 Miguel de Icaza, 1994, 1995
10 Jakub Jelinek, 1995
11 Andrej Borsenkow, 1996
12 Norbert Warmuth, 1997
13 Andrew Borodin <aborodin@vmail.ru>, 2009, 2010, 2013
15 This file is part of the Midnight Commander.
17 The Midnight Commander is free software: you can redistribute it
18 and/or modify it under the terms of the GNU General Public License as
19 published by the Free Software Foundation, either version 3 of the License,
20 or (at your option) any later version.
22 The Midnight Commander is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program. If not, see <http://www.gnu.org/licenses/>.
31 /** \file check.c
32 * \brief Source: WCheck widget (checkbutton)
35 #include <config.h>
37 #include <stdlib.h>
39 #include "lib/global.h"
41 #include "lib/tty/tty.h"
42 #include "lib/tty/mouse.h"
43 #include "lib/widget.h"
45 /*** global variables ****************************************************************************/
47 /*** file scope macro definitions ****************************************************************/
49 /*** file scope type declarations ****************************************************************/
51 /*** file scope variables ************************************************************************/
53 /*** file scope functions ************************************************************************/
55 static cb_ret_t
56 check_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
58 WCheck *c = CHECK (w);
60 switch (msg)
62 case MSG_HOTKEY:
63 if (c->text.hotkey != NULL)
65 if (g_ascii_tolower ((gchar) c->text.hotkey[0]) == parm)
67 /* make action */
68 send_message (w, sender, MSG_KEY, ' ', data);
69 return MSG_HANDLED;
72 return MSG_NOT_HANDLED;
74 case MSG_KEY:
75 if (parm != ' ')
76 return MSG_NOT_HANDLED;
77 c->state ^= C_BOOL;
78 c->state ^= C_CHANGE;
79 send_message (WIDGET (w)->owner, w, MSG_ACTION, 0, NULL);
80 send_message (w, sender, MSG_FOCUS, ' ', data);
81 return MSG_HANDLED;
83 case MSG_CURSOR:
84 widget_move (c, 0, 1);
85 return MSG_HANDLED;
87 case MSG_FOCUS:
88 case MSG_UNFOCUS:
89 case MSG_DRAW:
90 widget_selectcolor (w, msg == MSG_FOCUS, FALSE);
91 widget_move (c, 0, 0);
92 tty_print_string ((c->state & C_BOOL) ? "[x] " : "[ ] ");
93 hotkey_draw (w, c->text, msg == MSG_FOCUS);
94 return MSG_HANDLED;
96 case MSG_DESTROY:
97 release_hotkey (c->text);
98 return MSG_HANDLED;
100 default:
101 return widget_default_callback (w, sender, msg, parm, data);
105 /* --------------------------------------------------------------------------------------------- */
107 static int
108 check_event (Gpm_Event * event, void *data)
110 Widget *w = WIDGET (data);
112 if (!mouse_global_in_widget (event, w))
113 return MOU_UNHANDLED;
115 if ((event->type & (GPM_DOWN | GPM_UP)) != 0)
117 dlg_select_widget (w);
118 if ((event->type & GPM_UP) != 0)
120 send_message (w, NULL, MSG_KEY, ' ', NULL);
121 send_message (w, NULL, MSG_FOCUS, 0, NULL);
122 send_message (w->owner, w, MSG_POST_KEY, ' ', NULL);
126 return MOU_NORMAL;
129 /* --------------------------------------------------------------------------------------------- */
130 /*** public functions ****************************************************************************/
131 /* --------------------------------------------------------------------------------------------- */
133 WCheck *
134 check_new (int y, int x, int state, const char *text)
136 WCheck *c;
137 Widget *w;
139 c = g_new (WCheck, 1);
140 w = WIDGET (c);
141 c->text = parse_hotkey (text);
142 widget_init (w, y, x, 1, 4 + hotkey_width (c->text), check_callback, check_event);
143 /* 4 is width of "[X] " */
144 c->state = state ? C_BOOL : 0;
145 widget_want_hotkey (w, TRUE);
147 return c;
150 /* --------------------------------------------------------------------------------------------- */