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
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.
30 * \brief Source: WCheck widget (checkbutton)
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 ************************************************************************/
54 check_callback (Widget
* w
, widget_msg_t msg
, int parm
)
56 WCheck
*c
= (WCheck
*) w
;
57 Dlg_head
*h
= c
->widget
.owner
;
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 */
70 return MSG_NOT_HANDLED
;
74 return MSG_NOT_HANDLED
;
77 h
->callback (h
, w
, DLG_ACTION
, 0, NULL
);
78 check_callback (w
, WIDGET_FOCUS
, ' ');
82 widget_move (&c
->widget
, 0, 1);
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
);
95 release_hotkey (c
->text
);
99 return default_proc (msg
, parm
);
103 /* --------------------------------------------------------------------------------------------- */
106 check_event (Gpm_Event
* event
, void *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
);
127 /* --------------------------------------------------------------------------------------------- */
128 /*** public functions ****************************************************************************/
129 /* --------------------------------------------------------------------------------------------- */
132 check_new (int y
, int x
, int state
, const char *text
)
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
);