background.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. Widgets for the Midnight Commander
  3. Copyright (C) 2020
  4. The Free Software Foundation, Inc.
  5. Authors:
  6. Andrew Borodin <aborodin@vmail.ru>, 2020
  7. This file is part of the Midnight Commander.
  8. The Midnight Commander is free software: you can redistribute it
  9. and/or modify it under the terms of the GNU General Public License as
  10. published by the Free Software Foundation, either version 3 of the License,
  11. or (at your option) any later version.
  12. The Midnight Commander is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /** \file hline.c
  20. * \brief Source: WBackground widget (background area of dialog)
  21. */
  22. #include <config.h>
  23. #include <stdlib.h>
  24. #include "lib/global.h"
  25. #include "lib/tty/tty.h"
  26. #include "lib/tty/color.h"
  27. #include "lib/widget.h"
  28. /*** global variables ****************************************************************************/
  29. /*** file scope macro definitions ****************************************************************/
  30. /*** file scope type declarations ****************************************************************/
  31. /*** file scope variables ************************************************************************/
  32. /* --------------------------------------------------------------------------------------------- */
  33. /*** file scope functions ************************************************************************/
  34. /* --------------------------------------------------------------------------------------------- */
  35. static void
  36. background_adjust (WBackground * b)
  37. {
  38. Widget *w = WIDGET (b);
  39. Widget *wo = WIDGET (w->owner);
  40. w->y = wo->y;
  41. w->x = wo->x;
  42. w->lines = wo->lines;
  43. w->cols = wo->cols;
  44. w->pos_flags |= WPOS_KEEP_ALL;
  45. }
  46. /* --------------------------------------------------------------------------------------------- */
  47. static void
  48. background_draw (const WBackground * b)
  49. {
  50. const Widget *w = CONST_WIDGET (b);
  51. tty_setcolor (b->color);
  52. tty_fill_region (w->y, w->x, w->lines, w->cols, b->pattern);
  53. }
  54. /* --------------------------------------------------------------------------------------------- */
  55. /*** public functions ****************************************************************************/
  56. /* --------------------------------------------------------------------------------------------- */
  57. cb_ret_t
  58. background_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
  59. {
  60. WBackground *b = BACKGROUND (w);
  61. switch (msg)
  62. {
  63. case MSG_INIT:
  64. background_adjust (b);
  65. return MSG_HANDLED;
  66. case MSG_DRAW:
  67. background_draw (b);
  68. return MSG_HANDLED;
  69. default:
  70. return widget_default_callback (w, sender, msg, parm, data);
  71. }
  72. }
  73. /* --------------------------------------------------------------------------------------------- */
  74. WBackground *
  75. background_new (int y, int x, int lines, int cols, int color, unsigned char pattern,
  76. widget_cb_fn callback)
  77. {
  78. WBackground *b;
  79. Widget *w;
  80. b = g_new (WBackground, 1);
  81. w = WIDGET (b);
  82. widget_init (w, y, x, lines, cols, callback != NULL ? callback : background_callback, NULL);
  83. b->color = color;
  84. b->pattern = pattern;
  85. return b;
  86. }
  87. /* --------------------------------------------------------------------------------------------- */