groupbox.c 3.7 KB

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