PageRenderTime 171ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/src/scrollbar-next.c

https://gitlab.com/Jehan_ZeMarmot/mrxvt
C | 530 lines | 387 code | 59 blank | 84 comment | 52 complexity | 9aea94c9533ee2340e6ab8c0657d9a0a MD5 | raw file
  1. /*--------------------------------*-C-*---------------------------------*
  2. * File: scrollbar-next.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) 1998 Alfredo K. Kojima <kojima@windowmaker.org>
  8. * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com>
  9. * Copyright (c) 2004 Jingmin Zhou <jimmyzhou@users.sourceforge.net>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. *----------------------------------------------------------------------*/
  25. #include "../config.h"
  26. #include "rxvt.h"
  27. /*----------------------------------------------------------------------*/
  28. #ifdef HAVE_SCROLLBARS
  29. #ifdef NEXT_SCROLLBAR
  30. #define CHOOSE_GC_FG(R, PIXCOL) \
  31. XSetForeground ((R)->Xdisplay, (R)->scrollBar.gc, (PIXCOL))
  32. #define TILEGC (r->scrollBar.next_stippleGC)
  33. #define DIMPLE (r->scrollBar.next_dimple)
  34. #define UPARROW (r->scrollBar.next_upArrow)
  35. #define HIUPARROW (r->scrollBar.next_upArrowHi)
  36. #define DNARROW (r->scrollBar.next_downArrow)
  37. #define HIDNARROW (r->scrollBar.next_downArrowHi)
  38. #define n_stp_width 8
  39. #define n_stp_height 2
  40. const unsigned char n_stp_bits[] = { 0x55, 0xaa };
  41. /*
  42. * N*XTSTEP like scrollbar - written by Alfredo K. Kojima
  43. */
  44. #define DIMPLE_WIDTH 6
  45. #define DIMPLE_HEIGHT 6
  46. #define ARROW_WIDTH 11
  47. #define ARROW_HEIGHT 13
  48. const char *const SCROLLER_DIMPLE[] = {
  49. ".%###.",
  50. "%#%%%%",
  51. "#%%...",
  52. "#%.. ",
  53. "#%. ",
  54. ".%. ."
  55. };
  56. const char *const SCROLLER_ARROW_UP[] = {
  57. "...........",
  58. "...........",
  59. ".....%.....",
  60. ".....#.....",
  61. "....%#%....",
  62. "....###....",
  63. "...%###%...",
  64. "...#####...",
  65. "..%#####%..",
  66. "..#######..",
  67. ".%#######%.",
  68. "...........",
  69. "..........."
  70. };
  71. const char *const SCROLLER_ARROW_DOWN[] = {
  72. "...........",
  73. "...........",
  74. ".%#######%.",
  75. "..#######..",
  76. "..%#####%..",
  77. "...#####...",
  78. "...%###%...",
  79. "....###....",
  80. "....%#%....",
  81. ".....#.....",
  82. ".....%.....",
  83. "...........",
  84. "..........."
  85. };
  86. const char *const HI_SCROLLER_ARROW_UP[] = {
  87. " ",
  88. " ",
  89. " % ",
  90. " % ",
  91. " %%% ",
  92. " %%% ",
  93. " %%%%% ",
  94. " %%%%% ",
  95. " %%%%%%% ",
  96. " %%%%%%% ",
  97. " %%%%%%%%% ",
  98. " ",
  99. " "
  100. };
  101. const char *const HI_SCROLLER_ARROW_DOWN[] = {
  102. " ",
  103. " ",
  104. " %%%%%%%%% ",
  105. " %%%%%%% ",
  106. " %%%%%%% ",
  107. " %%%%% ",
  108. " %%%%% ",
  109. " %%% ",
  110. " %%% ",
  111. " % ",
  112. " % ",
  113. " ",
  114. " "
  115. };
  116. /* INTPROTO */
  117. static Pixmap
  118. rxvt_render_pixmap(rxvt_t *r, const char *const *data, int width, int height)
  119. {
  120. char a;
  121. int x, y;
  122. Pixmap d;
  123. unsigned long pointcolour;
  124. d = XCreatePixmap (r->Xdisplay, r->scrollBar.win, width, height,
  125. XDEPTH);
  126. if (NOT_PIXMAP(d))
  127. return None;
  128. for (y = 0; y < height; y++) {
  129. for (x = 0; x < width; x++) {
  130. if ((a = data[y][x]) == ' ' || a == 'w')
  131. pointcolour = r->scrollBar.next_white;
  132. else if (a == '.' || a == 'l')
  133. pointcolour = r->scrollBar.next_bg;
  134. else if (a == '%' || a == 'd')
  135. pointcolour = r->scrollBar.next_dark;
  136. else /* if (a == '#' || a == 'b' || a) */
  137. pointcolour = r->scrollBar.next_fg;
  138. CHOOSE_GC_FG(r, pointcolour);
  139. XDrawPoint(r->Xdisplay, d, r->scrollBar.gc, x, y);
  140. }
  141. }
  142. return d;
  143. }
  144. /* EXTPROTO */
  145. void
  146. rxvt_scrollbar_init_next (rxvt_t *r)
  147. {
  148. XGCValues gcvalue;
  149. unsigned long gcmask;
  150. XColor xcol;
  151. Pixmap stipple;
  152. UNSET_GC(TILEGC);
  153. UNSET_PIXMAP(DIMPLE);
  154. gcvalue.graphics_exposures = False;
  155. /* Initialize the colors */
  156. r->scrollBar.next_fg = r->pixColorsFocus[Color_Black];
  157. xcol.red = 0xaeba;
  158. xcol.green = 0xaaaa;
  159. xcol.blue = 0xaeba;
  160. if (!rxvt_alloc_color(r, &xcol, "light gray"))
  161. xcol.pixel = r->pixColorsFocus[Color_AntiqueWhite];
  162. r->scrollBar.next_bg = xcol.pixel;
  163. r->scrollBar.next_white = r->pixColorsFocus[Color_White];
  164. xcol.red = 0x51aa;
  165. xcol.green = 0x5555;
  166. xcol.blue = 0x5144;
  167. if (!rxvt_alloc_color(r, &xcol, "dark gray"))
  168. xcol.pixel = r->pixColorsFocus[Color_Grey25];
  169. r->scrollBar.next_dark = xcol.pixel;
  170. /* Create scrollBar GC */
  171. gcvalue.foreground = r->scrollBar.next_fg;
  172. #ifdef TRANSPARENT
  173. /* set background color when there's no transparent */
  174. if (!(ISSET_OPTION(r, Opt_transparent) &&
  175. ISSET_OPTION(r, Opt_transparent_scrollbar)
  176. ))
  177. #endif
  178. #ifdef BACKGROUND_IMAGE
  179. /* set background color when there's no bg image */
  180. if (NOT_PIXMAP(r->scrollBar.pixmap))
  181. #endif
  182. gcvalue.background = r->scrollBar.next_bg;
  183. gcmask = GCForeground;
  184. #ifdef TRANSPARENT
  185. /* set background color when there's no transparent */
  186. if (!(ISSET_OPTION(r, Opt_transparent) &&
  187. ISSET_OPTION(r, Opt_transparent_scrollbar)
  188. ))
  189. #endif
  190. #ifdef BACKGROUND_IMAGE
  191. /* set background color when there's no bg image */
  192. if (NOT_PIXMAP(r->scrollBar.pixmap))
  193. #endif
  194. gcmask |= GCBackground;
  195. r->scrollBar.gc = XCreateGC (r->Xdisplay, r->scrollBar.win,
  196. gcmask, &gcvalue);
  197. assert (IS_GC(r->scrollBar.gc));
  198. /* Create stipple GC */
  199. stipple = XCreateBitmapFromData(r->Xdisplay, r->scrollBar.win,
  200. (char *)n_stp_bits, n_stp_width, n_stp_height);
  201. if (IS_PIXMAP(stipple)) {
  202. gcvalue.foreground = r->scrollBar.next_dark;
  203. #ifdef TRANSPARENT
  204. /* set background color when there's no transparent */
  205. if (!(ISSET_OPTION(r, Opt_transparent) &&
  206. ISSET_OPTION(r, Opt_transparent_scrollbar)
  207. ))
  208. #endif
  209. #ifdef BACKGROUND_IMAGE
  210. /* set background color when there's no bg image */
  211. if (NOT_PIXMAP(r->scrollBar.pixmap))
  212. #endif
  213. gcvalue.background = r->scrollBar.next_bg;
  214. gcvalue.fill_style = FillOpaqueStippled;
  215. gcvalue.stipple = stipple;
  216. gcmask = GCForeground | GCStipple | GCFillStyle;
  217. #ifdef TRANSPARENT
  218. /* set background color when there's no transparent */
  219. if (!(ISSET_OPTION(r, Opt_transparent) &&
  220. ISSET_OPTION(r, Opt_transparent_scrollbar)
  221. ))
  222. #endif
  223. #ifdef BACKGROUND_IMAGE
  224. /* set background color when there's no bg image */
  225. if (NOT_PIXMAP(r->scrollBar.pixmap))
  226. #endif
  227. gcmask |= GCBackground;
  228. TILEGC = XCreateGC(r->Xdisplay, r->scrollBar.win,
  229. gcmask, &gcvalue);
  230. assert (IS_GC(TILEGC));
  231. }
  232. /* Create pixmaps */
  233. DIMPLE = rxvt_render_pixmap(r, SCROLLER_DIMPLE,
  234. DIMPLE_WIDTH, DIMPLE_HEIGHT);
  235. assert (IS_PIXMAP(DIMPLE));
  236. UPARROW = rxvt_render_pixmap(r, SCROLLER_ARROW_UP,
  237. ARROW_WIDTH, ARROW_HEIGHT);
  238. assert (IS_PIXMAP(UPARROW));
  239. HIUPARROW = rxvt_render_pixmap(r, HI_SCROLLER_ARROW_UP,
  240. ARROW_WIDTH, ARROW_HEIGHT);
  241. assert (IS_PIXMAP(HIUPARROW));
  242. DNARROW = rxvt_render_pixmap(r, SCROLLER_ARROW_DOWN,
  243. ARROW_WIDTH, ARROW_HEIGHT);
  244. assert (IS_PIXMAP(DNARROW));
  245. HIDNARROW = rxvt_render_pixmap(r, HI_SCROLLER_ARROW_DOWN,
  246. ARROW_WIDTH, ARROW_HEIGHT);
  247. assert (IS_PIXMAP(HIDNARROW));
  248. #ifdef TRANSPARENT
  249. /* set background color when there's no transparent */
  250. if (!(ISSET_OPTION(r, Opt_transparent) &&
  251. ISSET_OPTION(r, Opt_transparent_scrollbar)
  252. ))
  253. #endif
  254. #ifdef BACKGROUND_IMAGE
  255. /* set background color when there's no bg image */
  256. if (NOT_PIXMAP(r->scrollBar.pixmap))
  257. #endif
  258. XSetWindowBackground (r->Xdisplay, r->scrollBar.win,
  259. r->scrollBar.next_bg);
  260. }
  261. /* EXTPROTO */
  262. void
  263. rxvt_scrollbar_exit_next (rxvt_t *r)
  264. {
  265. if (IS_GC(r->scrollBar.next_stippleGC)) {
  266. XFreeGC (r->Xdisplay, r->scrollBar.next_stippleGC);
  267. UNSET_GC(r->scrollBar.next_stippleGC);
  268. }
  269. if (IS_PIXMAP(r->scrollBar.next_dimple)) {
  270. XFreePixmap (r->Xdisplay, r->scrollBar.next_dimple);
  271. UNSET_PIXMAP(r->scrollBar.next_dimple);
  272. }
  273. if (IS_PIXMAP(r->scrollBar.next_upArrow)) {
  274. XFreePixmap (r->Xdisplay, r->scrollBar.next_upArrow);
  275. UNSET_PIXMAP(r->scrollBar.next_upArrow);
  276. }
  277. if (IS_PIXMAP(r->scrollBar.next_upArrowHi)) {
  278. XFreePixmap (r->Xdisplay, r->scrollBar.next_upArrowHi);
  279. UNSET_PIXMAP(r->scrollBar.next_upArrowHi);
  280. }
  281. if (IS_PIXMAP(r->scrollBar.next_downArrow)) {
  282. XFreePixmap (r->Xdisplay, r->scrollBar.next_downArrow);
  283. UNSET_PIXMAP(r->scrollBar.next_downArrow);
  284. }
  285. if (IS_PIXMAP(r->scrollBar.next_downArrowHi)) {
  286. XFreePixmap (r->Xdisplay, r->scrollBar.next_downArrowHi);
  287. UNSET_PIXMAP(r->scrollBar.next_downArrowHi);
  288. }
  289. }
  290. /* Draw bevel & arrows */
  291. /* INTPROTO */
  292. static void
  293. next_draw_bevel (rxvt_t *r, Drawable d, int x1, int y1, int w, int h)
  294. {
  295. int x2, y2;
  296. x2 = x1 + w - 1; /* right point */
  297. y2 = y1 + h - 1; /* bottom point */
  298. /* white top and left */
  299. CHOOSE_GC_FG(r, r->scrollBar.next_white);
  300. XDrawLine(r->Xdisplay, d, r->scrollBar.gc, x1, y1, x2, y1);
  301. XDrawLine(r->Xdisplay, d, r->scrollBar.gc, x1, y1, x1, y2);
  302. /* black bottom and right */
  303. CHOOSE_GC_FG(r, r->scrollBar.next_fg);
  304. XDrawLine(r->Xdisplay, d, r->scrollBar.gc, x1, y2, x2, y2);
  305. XDrawLine(r->Xdisplay, d, r->scrollBar.gc, x2, y1, x2, y2);
  306. /* dark inside bottom and right */
  307. CHOOSE_GC_FG(r, r->scrollBar.next_dark);
  308. x1++, y1++, x2--, y2--; /* move in one point */
  309. XDrawLine(r->Xdisplay, d, r->scrollBar.gc, x1, y2, x2, y2);
  310. XDrawLine(r->Xdisplay, d, r->scrollBar.gc, x2, y1, x2, y2);
  311. }
  312. /* EXTPROTO */
  313. int
  314. rxvt_scrollbar_show_next(rxvt_t *r, int update, int last_top, int last_bot, int scroller_len)
  315. {
  316. int height;
  317. Drawable s;
  318. int page = ATAB(r);
  319. height = r->scrollBar.end + NEXT_SB_TBTN_HEIGHT + NEXT_SB_PAD;
  320. if (PVTS(r, page)->nscrolled == 0 || !update) {
  321. XClearArea (r->Xdisplay, r->scrollBar.win,
  322. 0, 0, SB_WIDTH_NEXT + 1, height, False);
  323. CHOOSE_GC_FG(r, r->scrollBar.next_fg);
  324. XDrawRectangle(r->Xdisplay, r->scrollBar.win, r->scrollBar.gc,
  325. 0, NEXT_SB_BD_WIDTH, SB_WIDTH_NEXT,
  326. height + NEXT_SB_BD_WIDTH);
  327. # ifdef TRANSPARENT
  328. /* set background color when there's no transparent */
  329. if (!(ISSET_OPTION(r, Opt_transparent) &&
  330. ISSET_OPTION(r, Opt_transparent_scrollbar)
  331. ))
  332. # endif
  333. #ifdef BACKGROUND_IMAGE
  334. /* set background color when there's no bg image */
  335. if (NOT_PIXMAP(r->scrollBar.pixmap))
  336. #endif
  337. XFillRectangle(r->Xdisplay, r->scrollBar.win, TILEGC,
  338. NEXT_SB_LPAD, 0, NEXT_SB_BTN_WIDTH, height);
  339. }
  340. if (PVTS(r, page)->nscrolled) {
  341. if (last_top < r->scrollBar.top || !update) {
  342. /*
  343. ** Area above the scroller
  344. */
  345. # ifdef TRANSPARENT
  346. /* clear background when there's transparent */
  347. if (ISSET_OPTION(r, Opt_transparent) &&
  348. ISSET_OPTION(r, Opt_transparent_scrollbar))
  349. XClearArea (r->Xdisplay, r->scrollBar.win,
  350. NEXT_SB_LPAD, NEXT_SB_PAD + last_top,
  351. NEXT_SB_BTN_WIDTH, r->scrollBar.top - last_top,
  352. False);
  353. else
  354. # endif
  355. # ifdef BACKGROUND_IMAGE
  356. /* clear background when there's bg image */
  357. if (IS_PIXMAP(r->scrollBar.pixmap))
  358. XClearArea (r->Xdisplay, r->scrollBar.win,
  359. NEXT_SB_LPAD, NEXT_SB_PAD + last_top,
  360. NEXT_SB_BTN_WIDTH, r->scrollBar.top - last_top,
  361. False);
  362. else
  363. # endif
  364. XFillRectangle(r->Xdisplay, r->scrollBar.win, TILEGC,
  365. NEXT_SB_LPAD, NEXT_SB_PAD + last_top,
  366. NEXT_SB_BTN_WIDTH, r->scrollBar.top - last_top);
  367. }
  368. if (r->scrollBar.bot < last_bot || !update) {
  369. /*
  370. ** Area above the buttons but below the scroller
  371. */
  372. # ifdef TRANSPARENT
  373. /* clear background when there's transparent */
  374. if (ISSET_OPTION(r, Opt_transparent) &&
  375. ISSET_OPTION(r, Opt_transparent_scrollbar))
  376. XClearArea(r->Xdisplay, r->scrollBar.win,
  377. NEXT_SB_LPAD, r->scrollBar.bot + NEXT_SB_PAD,
  378. NEXT_SB_BTN_WIDTH, (last_bot - r->scrollBar.bot),
  379. False);
  380. else
  381. # endif
  382. # ifdef BACKGROUND_IMAGE
  383. /* clear background when there's bg image */
  384. if (IS_PIXMAP(r->scrollBar.pixmap))
  385. XClearArea (r->Xdisplay, r->scrollBar.win,
  386. NEXT_SB_LPAD, r->scrollBar.bot + NEXT_SB_PAD,
  387. NEXT_SB_BTN_WIDTH, (last_bot - r->scrollBar.bot),
  388. False);
  389. else
  390. # endif
  391. XFillRectangle(r->Xdisplay, r->scrollBar.win, TILEGC,
  392. NEXT_SB_LPAD, r->scrollBar.bot + NEXT_SB_PAD,
  393. NEXT_SB_BTN_WIDTH, (last_bot - r->scrollBar.bot));
  394. }
  395. /*
  396. ** Area of the scroller
  397. */
  398. # ifdef TRANSPARENT
  399. /* clear background when there's transparent */
  400. if (ISSET_OPTION(r, Opt_transparent) &&
  401. ISSET_OPTION(r, Opt_transparent_scrollbar))
  402. XClearArea (r->Xdisplay, r->scrollBar.win,
  403. NEXT_SB_LPAD, r->scrollBar.top + NEXT_SB_PAD,
  404. NEXT_SB_BTN_WIDTH, scroller_len/*-NEXT_SB_BTN_HEIGHT*/,
  405. False);
  406. else
  407. # endif
  408. # ifdef BACKGROUND_IMAGE
  409. /* clear background when there's bg image */
  410. if (IS_PIXMAP(r->scrollBar.pixmap))
  411. XClearArea (r->Xdisplay, r->scrollBar.win,
  412. NEXT_SB_LPAD, r->scrollBar.top + NEXT_SB_PAD,
  413. NEXT_SB_BTN_WIDTH, scroller_len/*-NEXT_SB_BTN_HEIGHT*/,
  414. False);
  415. else
  416. # endif
  417. {
  418. CHOOSE_GC_FG(r, r->scrollBar.next_bg);
  419. XFillRectangle(r->Xdisplay, r->scrollBar.win,
  420. r->scrollBar.gc,
  421. NEXT_SB_LPAD, r->scrollBar.top + NEXT_SB_PAD,
  422. NEXT_SB_BTN_WIDTH, scroller_len/*-NEXT_SB_BTN_HEIGHT*/);
  423. }
  424. /*
  425. ** Here comes the dimple in the scroller
  426. */
  427. CHOOSE_GC_FG(r, r->scrollBar.next_white);
  428. XCopyArea(r->Xdisplay, DIMPLE, r->scrollBar.win,
  429. r->scrollBar.gc, 0, 0,
  430. DIMPLE_WIDTH, DIMPLE_HEIGHT,
  431. (SB_WIDTH_NEXT - DIMPLE_WIDTH) / 2,
  432. r->scrollBar.top + NEXT_BEVEL_ULEFT_WIDTH +
  433. (scroller_len - DIMPLE_HEIGHT) / 2);
  434. /*
  435. ** Bevel around the scroller
  436. */
  437. next_draw_bevel(r, r->scrollBar.win, NEXT_BEVEL_X,
  438. r->scrollBar.top + NEXT_SB_PAD, NEXT_SB_BTN_WIDTH,
  439. scroller_len);
  440. /*
  441. ** Bevel around the buttons
  442. */
  443. next_draw_bevel(r, r->scrollBar.win, NEXT_BEVEL_X,
  444. height - NEXT_SB_DBTN_HEIGHT, NEXT_SB_BTN_WIDTH,
  445. NEXT_SB_BTN_HEIGHT);
  446. next_draw_bevel(r, r->scrollBar.win, NEXT_BEVEL_X,
  447. height - NEXT_SB_SBTN_HEIGHT, NEXT_SB_BTN_WIDTH,
  448. NEXT_SB_BTN_HEIGHT);
  449. /*
  450. ** Top button
  451. */
  452. CHOOSE_GC_FG(r, r->scrollBar.next_white);
  453. s = (scrollbar_isUp()) ? HIUPARROW : UPARROW;
  454. XCopyArea(r->Xdisplay, s, r->scrollBar.win, r->scrollBar.gc,
  455. 0, 0,
  456. ARROW_WIDTH, ARROW_HEIGHT, NEXT_BTN_FACE_X,
  457. height-NEXT_SB_DBTN_HEIGHT+NEXT_BEVEL_ULEFT_WIDTH);
  458. /*
  459. ** Bottom button
  460. */
  461. s = (scrollbar_isDn()) ? HIDNARROW : DNARROW;
  462. XCopyArea(r->Xdisplay, s, r->scrollBar.win, r->scrollBar.gc,
  463. 0, 0,
  464. ARROW_WIDTH, ARROW_HEIGHT, NEXT_BTN_FACE_X,
  465. height-NEXT_SB_SBTN_HEIGHT+NEXT_BEVEL_ULEFT_WIDTH);
  466. }
  467. return 1;
  468. }
  469. #endif /* NEXT_SCROLLBAR */
  470. #endif /* HAVE_SCROLLBARS */
  471. /*----------------------- end-of-file (C source) -----------------------*/