2 Widgets for the Midnight Commander
4 Copyright (C) 1994-2016
5 Free Software Foundation, Inc.
8 Radek Doulik, 1994, 1995
9 Miguel de Icaza, 1994, 1995
11 Andrej Borsenkow, 1996
13 Andrew Borodin <aborodin@vmail.ru>, 2009, 2010, 2013, 2016
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/>.
32 * \brief Source: WCheck widget (checkbutton)
39 #include "lib/global.h"
41 #include "lib/tty/tty.h"
42 #include "lib/widget.h"
44 /*** global variables ****************************************************************************/
46 /*** file scope macro definitions ****************************************************************/
48 /*** file scope type declarations ****************************************************************/
50 /*** file scope variables ************************************************************************/
52 /*** file scope functions ************************************************************************/
55 check_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
57 WCheck
*c
= CHECK (w
);
62 if (c
->text
.hotkey
!= NULL
)
64 if (g_ascii_tolower ((gchar
) c
->text
.hotkey
[0]) == parm
)
67 send_message (w
, sender
, MSG_KEY
, ' ', data
);
71 return MSG_NOT_HANDLED
;
75 return MSG_NOT_HANDLED
;
78 send_message (w
, sender
, MSG_FOCUS
, ' ', data
);
79 send_message (WIDGET (w
)->owner
, w
, MSG_NOTIFY
, 0, NULL
);
83 widget_move (c
, 0, 1);
89 widget_selectcolor (w
, msg
== MSG_FOCUS
, FALSE
);
90 widget_move (c
, 0, 0);
91 tty_print_string ((c
->state
& C_BOOL
) ? "[x] " : "[ ] ");
92 hotkey_draw (w
, c
->text
, msg
== MSG_FOCUS
);
96 release_hotkey (c
->text
);
100 return widget_default_callback (w
, sender
, msg
, parm
, data
);
104 /* --------------------------------------------------------------------------------------------- */
107 check_mouse_callback (Widget
* w
, mouse_msg_t msg
, mouse_event_t
* event
)
114 dlg_select_widget (w
);
117 case MSG_MOUSE_CLICK
:
118 send_message (w
, NULL
, MSG_KEY
, ' ', NULL
);
119 send_message (w
->owner
, w
, MSG_POST_KEY
, ' ', NULL
);
127 /* --------------------------------------------------------------------------------------------- */
128 /*** public functions ****************************************************************************/
129 /* --------------------------------------------------------------------------------------------- */
132 check_new (int y
, int x
, int state
, const char *text
)
137 c
= g_new (WCheck
, 1);
139 c
->text
= parse_hotkey (text
);
140 /* 4 is width of "[X] " */
141 widget_init (w
, y
, x
, 1, 4 + hotkey_width (c
->text
), check_callback
, check_mouse_callback
);
142 c
->state
= state
? C_BOOL
: 0;
143 widget_want_hotkey (w
, TRUE
);
148 /* --------------------------------------------------------------------------------------------- */