hline.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 hline.c
  26. * \brief Source: WHLine widget (horizontal line)
  27. */
  28. #include <config.h>
  29. #include <stdlib.h>
  30. #include "lib/global.h"
  31. #include "lib/tty/tty.h"
  32. #include "lib/tty/color.h"
  33. #include "lib/skin.h"
  34. #include "lib/widget.h"
  35. /*** global variables ****************************************************************************/
  36. /*** file scope macro definitions ****************************************************************/
  37. /*** file scope type declarations ****************************************************************/
  38. /*** file scope variables ************************************************************************/
  39. /*** file scope functions ************************************************************************/
  40. static cb_ret_t
  41. hline_callback (Widget * w, widget_msg_t msg, int parm)
  42. {
  43. WHLine *l = (WHLine *) w;
  44. Dlg_head *h = l->widget.owner;
  45. switch (msg)
  46. {
  47. case WIDGET_INIT:
  48. case WIDGET_RESIZED:
  49. if (l->auto_adjust_cols)
  50. {
  51. if (((w->owner->flags & DLG_COMPACT) != 0))
  52. {
  53. w->x = w->owner->x;
  54. w->cols = w->owner->cols;
  55. }
  56. else
  57. {
  58. w->x = w->owner->x + 1;
  59. w->cols = w->owner->cols - 2;
  60. }
  61. }
  62. case WIDGET_FOCUS:
  63. /* We don't want to get the focus */
  64. return MSG_NOT_HANDLED;
  65. case WIDGET_DRAW:
  66. if (l->transparent)
  67. tty_setcolor (DEFAULT_COLOR);
  68. else
  69. tty_setcolor (h->color[DLG_COLOR_NORMAL]);
  70. tty_draw_hline (w->y, w->x + 1, ACS_HLINE, w->cols - 2);
  71. if (l->auto_adjust_cols)
  72. {
  73. widget_move (w, 0, 0);
  74. tty_print_alt_char (ACS_LTEE, FALSE);
  75. widget_move (w, 0, w->cols - 1);
  76. tty_print_alt_char (ACS_RTEE, FALSE);
  77. }
  78. return MSG_HANDLED;
  79. default:
  80. return default_proc (msg, parm);
  81. }
  82. }
  83. /* --------------------------------------------------------------------------------------------- */
  84. /*** public functions ****************************************************************************/
  85. /* --------------------------------------------------------------------------------------------- */
  86. WHLine *
  87. hline_new (int y, int x, int width)
  88. {
  89. WHLine *l;
  90. int lines = 1;
  91. l = g_new (WHLine, 1);
  92. init_widget (&l->widget, y, x, lines, width, hline_callback, NULL);
  93. l->auto_adjust_cols = (width < 0);
  94. l->transparent = FALSE;
  95. widget_want_cursor (l->widget, FALSE);
  96. widget_want_hotkey (l->widget, FALSE);
  97. return l;
  98. }
  99. /* --------------------------------------------------------------------------------------------- */