Renamed do_find() to find_file() and vice versa.
[midnight-commander.git] / lib / widget / check.c
blobe45699418e237fdf961276225272bb7a4e7576bc
1 /* Widgets for the Midnight Commander
3 Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
6 Authors: 1994, 1995 Radek Doulik
7 1994, 1995 Miguel de Icaza
8 1995 Jakub Jelinek
9 1996 Andrej Borsenkow
10 1997 Norbert Warmuth
11 2009, 2010 Andrew Borodin
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 /** \file check.c
30 * \brief Source: WCheck widget (checkbutton)
33 #include <config.h>
35 #include <stdlib.h>
37 #include "lib/global.h"
39 #include "lib/tty/tty.h"
40 #include "lib/tty/mouse.h"
41 #include "lib/widget.h"
43 /*** global variables ****************************************************************************/
45 /*** file scope macro definitions ****************************************************************/
47 /*** file scope type declarations ****************************************************************/
49 /*** file scope variables ************************************************************************/
51 /*** file scope functions ************************************************************************/
53 static cb_ret_t
54 check_callback (Widget * w, widget_msg_t msg, int parm)
56 WCheck *c = (WCheck *) w;
57 Dlg_head *h = c->widget.owner;
59 switch (msg)
61 case WIDGET_HOTKEY:
62 if (c->text.hotkey != NULL)
64 if (g_ascii_tolower ((gchar) c->text.hotkey[0]) == parm)
66 check_callback (w, WIDGET_KEY, ' '); /* make action */
67 return MSG_HANDLED;
70 return MSG_NOT_HANDLED;
72 case WIDGET_KEY:
73 if (parm != ' ')
74 return MSG_NOT_HANDLED;
75 c->state ^= C_BOOL;
76 c->state ^= C_CHANGE;
77 h->callback (h, w, DLG_ACTION, 0, NULL);
78 check_callback (w, WIDGET_FOCUS, ' ');
79 return MSG_HANDLED;
81 case WIDGET_CURSOR:
82 widget_move (&c->widget, 0, 1);
83 return MSG_HANDLED;
85 case WIDGET_FOCUS:
86 case WIDGET_UNFOCUS:
87 case WIDGET_DRAW:
88 widget_selectcolor (w, msg == WIDGET_FOCUS, FALSE);
89 widget_move (&c->widget, 0, 0);
90 tty_print_string ((c->state & C_BOOL) ? "[x] " : "[ ] ");
91 hotkey_draw (w, c->text, msg == WIDGET_FOCUS);
92 return MSG_HANDLED;
94 case WIDGET_DESTROY:
95 release_hotkey (c->text);
96 return MSG_HANDLED;
98 default:
99 return default_proc (msg, parm);
103 /* --------------------------------------------------------------------------------------------- */
105 static int
106 check_event (Gpm_Event * event, void *data)
108 WCheck *c = data;
109 Widget *w = data;
111 if ((event->type & (GPM_DOWN | GPM_UP)) != 0)
113 Dlg_head *h = c->widget.owner;
115 dlg_select_widget (c);
116 if (event->type & GPM_UP)
118 check_callback (w, WIDGET_KEY, ' ');
119 check_callback (w, WIDGET_FOCUS, 0);
120 h->callback (h, w, DLG_POST_KEY, ' ', NULL);
121 return MOU_NORMAL;
124 return MOU_NORMAL;
127 /* --------------------------------------------------------------------------------------------- */
128 /*** public functions ****************************************************************************/
129 /* --------------------------------------------------------------------------------------------- */
131 WCheck *
132 check_new (int y, int x, int state, const char *text)
134 WCheck *c;
136 c = g_new (WCheck, 1);
137 c->text = parse_hotkey (text);
138 init_widget (&c->widget, y, x, 1, 4 + hotkey_width (c->text), check_callback, check_event);
139 /* 4 is width of "[X] " */
140 c->state = state ? C_BOOL : 0;
141 widget_want_hotkey (c->widget, TRUE);
143 return c;