background.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. Widgets for the Midnight Commander
  3. Copyright (C) 2020-2021
  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 background.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 const int *
  36. background_get_colors (const Widget * w)
  37. {
  38. return &(CONST_BACKGROUND (w)->color);
  39. }
  40. /* --------------------------------------------------------------------------------------------- */
  41. static void
  42. background_adjust (WBackground * b)
  43. {
  44. Widget *w = WIDGET (b);
  45. Widget *wo = WIDGET (w->owner);
  46. w->y = wo->y;
  47. w->x = wo->x;
  48. w->lines = wo->lines;
  49. w->cols = wo->cols;
  50. w->pos_flags |= WPOS_KEEP_ALL;
  51. }
  52. /* --------------------------------------------------------------------------------------------- */
  53. static void
  54. background_draw (const WBackground * b)
  55. {
  56. const Widget *w = CONST_WIDGET (b);
  57. tty_setcolor (b->color);
  58. tty_fill_region (w->y, w->x, w->lines, w->cols, b->pattern);
  59. }
  60. /* --------------------------------------------------------------------------------------------- */
  61. /*** public functions ****************************************************************************/
  62. /* --------------------------------------------------------------------------------------------- */
  63. cb_ret_t
  64. background_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
  65. {
  66. WBackground *b = BACKGROUND (w);
  67. switch (msg)
  68. {
  69. case MSG_INIT:
  70. background_adjust (b);
  71. return MSG_HANDLED;
  72. case MSG_DRAW:
  73. background_draw (b);
  74. return MSG_HANDLED;
  75. default:
  76. return widget_default_callback (w, sender, msg, parm, data);
  77. }
  78. }
  79. /* --------------------------------------------------------------------------------------------- */
  80. WBackground *
  81. background_new (int y, int x, int lines, int cols, int color, unsigned char pattern,
  82. widget_cb_fn callback)
  83. {
  84. WBackground *b;
  85. Widget *w;
  86. b = g_new (WBackground, 1);
  87. w = WIDGET (b);
  88. widget_init (w, y, x, lines, cols, callback != NULL ? callback : background_callback, NULL);
  89. w->get_colors = background_get_colors;
  90. b->color = color;
  91. b->pattern = pattern;
  92. return b;
  93. }
  94. /* --------------------------------------------------------------------------------------------- */