/branches/librxvt/src/scrollbar-xterm.c

# · C · 86 lines · 47 code · 11 blank · 28 comment · 6 complexity · 94bccc0a4fcba04280668c2f9f01ccf3 MD5 · raw file

  1. /*--------------------------------*-C-*---------------------------------*
  2. * File: scrollbar-xterm.c
  3. *----------------------------------------------------------------------*
  4. * $Id: scrollbar-xterm.c 943 2000-04-13 23:30:56Z gcw $
  5. *
  6. * Copyright (C) 1997,1998 mj olesen <olesen@me.QueensU.CA>
  7. * Copyright (C) 1999,2000 Geoff Wing <gcw@pobox.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  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. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. *----------------------------------------------------------------------*/
  23. #include "../config.h" /* NECESSARY */
  24. #include "rxvt.h" /* NECESSARY */
  25. #include "scrollbar-xterm.intpro" /* PROTOS for internal routines */
  26. /*----------------------------------------------------------------------*
  27. */
  28. static GC scrollbarGC;
  29. static GC ShadowGC;
  30. static char sb_bits[] = { 0xaa, 0x0a, 0x55, 0x05 }; /* 12x2 bitmap */
  31. #define SB_WIDTH_USE (SB_WIDTH_XTERM - 1)
  32. /* EXTPROTO */
  33. int
  34. rxvt_scrollbar_show_xterm(rxvt_t *r, int update, int last_top, int last_bot, int scrollbar_len)
  35. {
  36. int xsb = 0;
  37. if (!scrollbar_visible())
  38. return 0;
  39. if (scrollbarGC == None) {
  40. XGCValues gcvalue;
  41. gcvalue.stipple = XCreateBitmapFromData(r->Xdisplay, r->scrollBar.win,
  42. sb_bits, 12, 2);
  43. if (!gcvalue.stipple) {
  44. rxvt_print_error("can't create bitmap");
  45. exit(EXIT_FAILURE);
  46. }
  47. gcvalue.fill_style = FillOpaqueStippled;
  48. gcvalue.foreground = r->PixColors[Color_fg];
  49. gcvalue.background = r->PixColors[Color_bg];
  50. scrollbarGC = XCreateGC(r->Xdisplay, r->scrollBar.win,
  51. GCForeground | GCBackground |
  52. GCFillStyle | GCStipple, &gcvalue);
  53. gcvalue.foreground = r->PixColors[Color_border];
  54. ShadowGC = XCreateGC(r->Xdisplay, r->scrollBar.win, GCForeground,
  55. &gcvalue);
  56. }
  57. /* instead of XClearWindow (r->Xdisplay, r->scrollBar.win); */
  58. xsb = (r->Options & Opt_scrollBar_right) ? 1 : 0;
  59. if (last_top < r->scrollBar.top)
  60. XClearArea(r->Xdisplay, r->scrollBar.win,
  61. r->sb_shadow + xsb, last_top,
  62. SB_WIDTH_USE, (r->scrollBar.top - last_top), False);
  63. if (r->scrollBar.bot < last_bot)
  64. XClearArea(r->Xdisplay, r->scrollBar.win,
  65. r->sb_shadow + xsb, r->scrollBar.bot,
  66. SB_WIDTH_USE, (last_bot - r->scrollBar.bot), False);
  67. /* scrollbar slider */
  68. XFillRectangle(r->Xdisplay, r->scrollBar.win, scrollbarGC,
  69. xsb + 1, r->scrollBar.top, SB_WIDTH_USE - 2, scrollbar_len);
  70. XDrawLine(r->Xdisplay, r->scrollBar.win, ShadowGC,
  71. xsb ? 0 : SB_WIDTH_USE, r->scrollBar.beg, xsb ? 0 : SB_WIDTH_USE,
  72. r->scrollBar.end);
  73. return 1;
  74. }
  75. /*----------------------- end-of-file (C source) -----------------------*/