groupbox.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. Widgets for the Midnight Commander
  3. Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
  4. 2004, 2005, 2006, 2007, 2009, 2010, 2011
  5. The Free Software Foundation, Inc.
  6. Authors:
  7. Radek Doulik, 1994, 1995
  8. Miguel de Icaza, 1994, 1995
  9. Jakub Jelinek, 1995
  10. Andrej Borsenkow, 1996
  11. Norbert Warmuth, 1997
  12. Andrew Borodin <aborodin@vmail.ru>, 2009, 2010
  13. This file is part of the Midnight Commander.
  14. The Midnight Commander is free software: you can redistribute it
  15. and/or modify it under the terms of the GNU General Public License as
  16. published by the Free Software Foundation, either version 3 of the License,
  17. or (at your option) any later version.
  18. The Midnight Commander 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.
  22. You should have received a copy of the GNU General Public License
  23. along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. /** \file groupbox.c
  26. * \brief Source: WGroupbox widget
  27. */
  28. #include <config.h>
  29. #include "lib/global.h"
  30. #include "lib/tty/tty.h"
  31. #include "lib/tty/color.h"
  32. #include "lib/skin.h"
  33. #include "lib/widget.h"
  34. /*** global variables ****************************************************************************/
  35. /*** file scope macro definitions ****************************************************************/
  36. /*** file scope type declarations ****************************************************************/
  37. /*** file scope variables ************************************************************************/
  38. /*** file scope functions ************************************************************************/
  39. static cb_ret_t
  40. groupbox_callback (Widget * w, widget_msg_t msg, int parm)
  41. {
  42. WGroupbox *g = (WGroupbox *) w;
  43. switch (msg)
  44. {
  45. case WIDGET_INIT:
  46. return MSG_HANDLED;
  47. case WIDGET_FOCUS:
  48. return MSG_NOT_HANDLED;
  49. case WIDGET_DRAW:
  50. {
  51. gboolean disabled = (w->options & W_DISABLED) != 0;
  52. tty_setcolor (disabled ? DISABLED_COLOR : COLOR_NORMAL);
  53. draw_box (g->widget.owner, g->widget.y - g->widget.owner->y,
  54. g->widget.x - g->widget.owner->x, g->widget.lines, g->widget.cols, TRUE);
  55. if (g->title != NULL)
  56. {
  57. tty_setcolor (disabled ? DISABLED_COLOR : COLOR_TITLE);
  58. dlg_move (g->widget.owner, g->widget.y - g->widget.owner->y,
  59. g->widget.x - g->widget.owner->x + 1);
  60. tty_print_string (g->title);
  61. }
  62. return MSG_HANDLED;
  63. }
  64. case WIDGET_DESTROY:
  65. g_free (g->title);
  66. return MSG_HANDLED;
  67. default:
  68. return default_proc (msg, parm);
  69. }
  70. }
  71. /* --------------------------------------------------------------------------------------------- */
  72. /*** public functions ****************************************************************************/
  73. /* --------------------------------------------------------------------------------------------- */
  74. WGroupbox *
  75. groupbox_new (int y, int x, int height, int width, const char *title)
  76. {
  77. WGroupbox *g;
  78. g = g_new (WGroupbox, 1);
  79. init_widget (&g->widget, y, x, height, width, groupbox_callback, NULL);
  80. widget_want_cursor (g->widget, FALSE);
  81. widget_want_hotkey (g->widget, FALSE);
  82. /* Strip existing spaces, add one space before and after the title */
  83. if (title != NULL)
  84. {
  85. char *t;
  86. t = g_strstrip (g_strdup (title));
  87. g->title = g_strconcat (" ", t, " ", (char *) NULL);
  88. g_free (t);
  89. }
  90. return g;
  91. }
  92. /* --------------------------------------------------------------------------------------------- */