PageRenderTime 25ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/src/scrollbar-xterm.c

https://gitlab.com/Jehan_ZeMarmot/mrxvt
C | 167 lines | 100 code | 30 blank | 37 comment | 10 complexity | 49aa35f0da61104ac966c92af79dccb4 MD5 | raw file
  1. /*--------------------------------*-C-*---------------------------------*
  2. * File: scrollbar-xterm.c
  3. *----------------------------------------------------------------------*
  4. *
  5. * All portions of code are copyright by their respective author/s.
  6. * Copyright (c) 1997,1998 mj olesen <olesen@me.QueensU.CA>
  7. * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com>
  8. * Copyright (c) 2004 Jingmin Zhou <jimmyzhou@users.sourceforge.net>
  9. *
  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. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *----------------------------------------------------------------------*/
  24. #include "../config.h"
  25. #include "rxvt.h"
  26. /*----------------------------------------------------------------------*/
  27. #ifdef HAVE_SCROLLBARS
  28. #ifdef XTERM_SCROLLBAR
  29. #define CHOOSE_GC_FG(R, PIXCOL) \
  30. XSetForeground ((R)->Xdisplay, (R)->scrollBar.gc, (PIXCOL))
  31. #define x_stp_width (8)
  32. #define x_stp_height (2)
  33. const unsigned char x_stp_bits[] = { 0x55, 0xaa };
  34. /* EXTPROTO */
  35. void
  36. rxvt_scrollbar_init_xterm (rxvt_t* r)
  37. {
  38. XGCValues gcvalue;
  39. unsigned long gcmask;
  40. UNSET_GC(r->scrollBar.gc);
  41. /* Initialize the colors */
  42. r->scrollBar.xterm_fg = r->pixColorsFocus[Color_fg];
  43. r->scrollBar.xterm_bg = r->pixColorsFocus[Color_bg];
  44. r->scrollBar.xterm_shadow = r->pixColorsFocus[Color_border];
  45. gcvalue.stipple = XCreateBitmapFromData (r->Xdisplay,
  46. r->scrollBar.win, (char *)x_stp_bits,
  47. x_stp_width, x_stp_height);
  48. assert (IS_PIXMAP(gcvalue.stipple));
  49. gcvalue.fill_style = FillOpaqueStippled;
  50. gcvalue.foreground = r->scrollBar.xterm_fg;
  51. #ifdef TRANSPARENT
  52. /* set background color when there's no transparent */
  53. if (!(ISSET_OPTION(r, Opt_transparent) &&
  54. ISSET_OPTION(r, Opt_transparent_scrollbar)
  55. ))
  56. #endif
  57. #ifdef BACKGROUND_IMAGE
  58. /* set background color when there's no bg image */
  59. if (NOT_PIXMAP(r->scrollBar.pixmap))
  60. #endif
  61. gcvalue.background = r->scrollBar.xterm_bg;
  62. gcmask = GCForeground | GCFillStyle | GCStipple;
  63. #ifdef TRANSPARENT
  64. /* set background color when there's no transparent */
  65. if (!(ISSET_OPTION(r, Opt_transparent) &&
  66. ISSET_OPTION(r, Opt_transparent_scrollbar)
  67. ))
  68. #endif
  69. #ifdef BACKGROUND_IMAGE
  70. /* set background color when there's no bg image */
  71. if (NOT_PIXMAP(r->scrollBar.pixmap))
  72. #endif
  73. gcmask |= GCBackground;
  74. r->scrollBar.gc = XCreateGC (r->Xdisplay, r->scrollBar.win,
  75. gcmask, &gcvalue);
  76. assert (IS_GC(r->scrollBar.gc));
  77. #ifdef TRANSPARENT
  78. /* set background color when there's no transparent */
  79. if (!(ISSET_OPTION(r, Opt_transparent) &&
  80. ISSET_OPTION(r, Opt_transparent_scrollbar)
  81. ))
  82. #endif
  83. #ifdef BACKGROUND_IMAGE
  84. /* set background color when there's no bg image */
  85. if (NOT_PIXMAP(r->scrollBar.pixmap))
  86. #endif
  87. XSetWindowBackground (r->Xdisplay, r->scrollBar.win,
  88. r->scrollBar.xterm_bg);
  89. }
  90. void
  91. rxvt_scrollbar_exit_xterm (rxvt_t* r)
  92. {
  93. /* No resources to free */
  94. }
  95. /* EXTPROTO */
  96. int
  97. rxvt_scrollbar_show_xterm(rxvt_t *r, int update __attribute__((unused)), int last_top, int last_bot, int scroller_len)
  98. {
  99. int xsb = 0;
  100. int sbwidth = r->scrollBar.width - 1;
  101. int clear = 0;
  102. /* scrollbar slider */
  103. #ifdef TRANSPARENT
  104. if (ISSET_OPTION(r, Opt_transparent) &&
  105. ISSET_OPTION(r, Opt_transparent_scrollbar))
  106. clear = 1;
  107. else
  108. #endif
  109. #ifdef BACKGROUND_IMAGE
  110. if (IS_PIXMAP(r->scrollBar.pixmap))
  111. clear = 1;
  112. else
  113. #endif
  114. clear = 0;
  115. xsb = ISSET_OPTION(r, Opt_scrollBar_right) ? 1 : 0;
  116. if (last_top < r->scrollBar.top)
  117. XClearArea(r->Xdisplay, r->scrollBar.win,
  118. r->sb_shadow + xsb, last_top,
  119. sbwidth, (r->scrollBar.top - last_top), False);
  120. if (r->scrollBar.bot < last_bot)
  121. XClearArea(r->Xdisplay, r->scrollBar.win,
  122. r->sb_shadow + xsb, r->scrollBar.bot,
  123. sbwidth, (last_bot - r->scrollBar.bot + clear), False);
  124. /* scrollbar slider */
  125. CHOOSE_GC_FG(r, r->scrollBar.xterm_fg);
  126. XFillRectangle(r->Xdisplay, r->scrollBar.win, r->scrollBar.gc,
  127. r->sb_shadow + xsb + 1, r->scrollBar.top,
  128. sbwidth - 2, scroller_len);
  129. CHOOSE_GC_FG(r, r->scrollBar.xterm_shadow);
  130. XDrawLine(r->Xdisplay, r->scrollBar.win, r->scrollBar.gc,
  131. xsb ? r->sb_shadow : r->sb_shadow + sbwidth, r->scrollBar.beg,
  132. xsb ? r->sb_shadow : r->sb_shadow + sbwidth, r->scrollBar.end);
  133. return 1;
  134. }
  135. #endif /* XTERM_SCROLLBAR */
  136. #endif /* HAVE_SCROLLBARS */
  137. /*----------------------- end-of-file (C source) -----------------------*/