root/lib/widget/check.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. check_callback
  2. check_mouse_callback
  3. check_new

   1 /*
   2    Widgets for the Midnight Commander
   3 
   4    Copyright (C) 1994-2019
   5    Free Software Foundation, Inc.
   6 
   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, 2016
  14 
  15    This file is part of the Midnight Commander.
  16 
  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.
  21 
  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.
  26 
  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/>.
  29  */
  30 
  31 /** \file check.c
  32  *  \brief Source: WCheck widget (checkbutton)
  33  */
  34 
  35 #include <config.h>
  36 
  37 #include <stdlib.h>
  38 
  39 #include "lib/global.h"
  40 
  41 #include "lib/tty/tty.h"
  42 #include "lib/widget.h"
  43 
  44 /*** global variables ****************************************************************************/
  45 
  46 /*** file scope macro definitions ****************************************************************/
  47 
  48 /*** file scope type declarations ****************************************************************/
  49 
  50 /*** file scope variables ************************************************************************/
  51 
  52 /*** file scope functions ************************************************************************/
  53 
  54 static cb_ret_t
  55 check_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
     /* [previous][next][first][last][top][bottom][index][help]  */
  56 {
  57     WCheck *c = CHECK (w);
  58 
  59     switch (msg)
  60     {
  61     case MSG_HOTKEY:
  62         if (c->text.hotkey != NULL)
  63         {
  64             if (g_ascii_tolower ((gchar) c->text.hotkey[0]) == parm)
  65             {
  66                 /* make action */
  67                 send_message (w, sender, MSG_KEY, ' ', data);
  68                 return MSG_HANDLED;
  69             }
  70         }
  71         return MSG_NOT_HANDLED;
  72 
  73     case MSG_KEY:
  74         if (parm != ' ')
  75             return MSG_NOT_HANDLED;
  76         c->state = !c->state;
  77         widget_redraw (w);
  78         send_message (w->owner, w, MSG_NOTIFY, 0, NULL);
  79         return MSG_HANDLED;
  80 
  81     case MSG_CURSOR:
  82         widget_move (w, 0, 1);
  83         return MSG_HANDLED;
  84 
  85     case MSG_DRAW:
  86         {
  87             gboolean focused;
  88 
  89             focused = widget_get_state (w, WST_FOCUSED);
  90             widget_selectcolor (w, focused, FALSE);
  91             widget_move (w, 0, 0);
  92             tty_print_string (c->state ? "[x] " : "[ ] ");
  93             hotkey_draw (w, c->text, focused);
  94             return MSG_HANDLED;
  95         }
  96 
  97     case MSG_DESTROY:
  98         release_hotkey (c->text);
  99         return MSG_HANDLED;
 100 
 101     default:
 102         return widget_default_callback (w, sender, msg, parm, data);
 103     }
 104 }
 105 
 106 /* --------------------------------------------------------------------------------------------- */
 107 
 108 static void
 109 check_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
     /* [previous][next][first][last][top][bottom][index][help]  */
 110 {
 111     (void) event;
 112 
 113     switch (msg)
 114     {
 115     case MSG_MOUSE_DOWN:
 116         widget_select (w);
 117         break;
 118 
 119     case MSG_MOUSE_CLICK:
 120         send_message (w, NULL, MSG_KEY, ' ', NULL);
 121         send_message (w->owner, w, MSG_POST_KEY, ' ', NULL);
 122         break;
 123 
 124     default:
 125         break;
 126     }
 127 }
 128 
 129 /* --------------------------------------------------------------------------------------------- */
 130 /*** public functions ****************************************************************************/
 131 /* --------------------------------------------------------------------------------------------- */
 132 
 133 WCheck *
 134 check_new (int y, int x, gboolean state, const char *text)
     /* [previous][next][first][last][top][bottom][index][help]  */
 135 {
 136     WCheck *c;
 137     Widget *w;
 138 
 139     c = g_new (WCheck, 1);
 140     w = WIDGET (c);
 141     c->text = parse_hotkey (text);
 142     /* 4 is width of "[X] " */
 143     widget_init (w, y, x, 1, 4 + hotkey_width (c->text), check_callback, check_mouse_callback);
 144     w->options |= WOP_SELECTABLE | WOP_WANT_CURSOR | WOP_WANT_HOTKEY;
 145     c->state = state;
 146 
 147     return c;
 148 }
 149 
 150 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */