xvview.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /* XView viewer routines.
  2. Copyright (C) 1995 Jakub Jelinek.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  14. #include <config.h>
  15. #include <X11/Xlib.h>
  16. #include <xview/xview.h>
  17. #include <xview/frame.h>
  18. #include <xview/panel.h>
  19. #include <xview/svrimage.h>
  20. #include <xview/canvas.h>
  21. #include <xview/scrollbar.h>
  22. #include <xview/cms.h>
  23. #include <xview/xv_xrect.h>
  24. #include <xview/textsw.h>
  25. #include <stdio.h>
  26. #include "fs.h"
  27. #include "dlg.h"
  28. #define WANT_WIDGETS
  29. #include "view.h"
  30. #include "../src/util.h"
  31. #include "../src/mad.h"
  32. #include "xvmain.h"
  33. extern Frame mcframe;
  34. Frame viewframe;
  35. Panel viewpanel;
  36. Textsw viewcanvas;
  37. Cms viewcms;
  38. extern void view_destroy(WView *);
  39. static void x_quit_cmd (Panel_button_item);
  40. /*static struct {
  41. unsigned short *bits;
  42. void (*callback) (void);
  43. } buttons [] = {
  44. index_bits, x_index_cmd,
  45. back_bits, x_back_cmd,
  46. previous_bits, x_previous_cmd,
  47. next_bits, x_next_cmd,
  48. search_bits, x_search_cmd };*/
  49. static void fetch_content (Textsw textsw, WView *view)
  50. {
  51. char *p;
  52. int n;
  53. if (view->growing_buffer) {
  54. p = xmalloc (2048, "view growing");
  55. if (view->stdfile != (FILE *)-1)
  56. n = fread (p, 1, 2048, view->stdfile);
  57. else
  58. n = mc_read (view->file, p, 2048);
  59. textsw_insert (textsw, p, n);
  60. free (p);
  61. } else {
  62. textsw_insert (textsw, view->data, view->bytes_read);
  63. }
  64. }
  65. static void textsw_notify (Textsw textsw, Attr_attribute *attrs)
  66. {
  67. WView *view = (WView *) xv_get (textsw, XV_KEY_DATA, KEY_DATA_VIEW);
  68. Rect *from, *to;
  69. for (; *attrs; attrs = attr_next (attrs)) {
  70. switch (*attrs) {
  71. case TEXTSW_ACTION_SCROLLED:
  72. from = (Rect *) attrs [1];
  73. to = (Rect *) attrs [2];
  74. if (view->growing_buffer) {
  75. if (view->stdfile != (FILE *) -1) {
  76. xv_get (textsw, TEXTSW_FIRST_LINE);
  77. } else {
  78. xv_get (textsw, TEXTSW_FIRST_LINE);
  79. }
  80. }
  81. break;
  82. default:
  83. break;
  84. }
  85. }
  86. }
  87. static void create_frame (WView *view)
  88. {
  89. Panel_button_item button;
  90. /* int i;*/
  91. viewcms = (Cms) xv_create (XV_NULL, CMS,
  92. CMS_CONTROL_CMS, TRUE,
  93. CMS_SIZE, CMS_CONTROL_COLORS + 5,
  94. CMS_NAMED_COLORS, "black", "red4", "green4", "black", NULL,
  95. NULL);
  96. viewframe = xv_create (mcframe, FRAME,
  97. FRAME_LABEL, "View",
  98. WIN_CMS, viewcms,
  99. FRAME_INHERIT_COLORS, TRUE,
  100. FRAME_SHOW_FOOTER, TRUE,
  101. XV_KEY_DATA, KEY_DATA_VIEW, view,
  102. NULL);
  103. viewpanel = xv_create (viewframe, PANEL,
  104. XV_KEY_DATA, KEY_DATA_VIEW, view,
  105. NULL);
  106. /*
  107. xv_create (viewpanel, PANEL_BUTTON,
  108. PANEL_LABEL_STRING, "Help",
  109. PANEL_ITEM_MENU, xv_create (XV_NULL, MENU,
  110. MENU_ITEM,
  111. MENU_STRING, "Help on Help",
  112. MENU_NOTIFY_PROC, x_view_on_view,
  113. NULL,
  114. MENU_ITEM,
  115. MENU_STRING, "Index",
  116. MENU_NOTIFY_PROC, x_index_cmd,
  117. NULL,
  118. MENU_ITEM,
  119. MENU_STRING, "Back",
  120. MENU_NOTIFY_PROC, x_back_cmd,
  121. NULL,
  122. MENU_ITEM,
  123. MENU_STRING, "Previous",
  124. MENU_NOTIFY_PROC, x_previous_cmd,
  125. NULL,
  126. MENU_ITEM,
  127. MENU_STRING, "Next",
  128. MENU_NOTIFY_PROC, x_next_cmd,
  129. NULL,
  130. MENU_ITEM,
  131. MENU_STRING, "Search",
  132. MENU_NOTIFY_PROC, x_search_cmd,
  133. NULL,
  134. NULL),
  135. NULL);
  136. button = (Panel_button_item) xv_create (viewpanel, PANEL_BUTTON,
  137. PANEL_LABEL_STRING, "Quit",
  138. PANEL_NOTIFY_PROC, x_quit_cmd,
  139. NULL);
  140. for (i = 0; i < sizeof (buttons) / sizeof (buttons [0]); i++) {
  141. button = (Panel_button_item) xv_create (viewpanel, PANEL_BUTTON,
  142. PANEL_LABEL_IMAGE, xv_create (XV_NULL, SERVER_IMAGE,
  143. SERVER_IMAGE_DEPTH, 1,
  144. XV_WIDTH, 48,
  145. XV_HEIGHT, 48,
  146. SERVER_IMAGE_BITS, buttons [i].bits,
  147. NULL),
  148. PANEL_NOTIFY_PROC, buttons [i].callback,
  149. NULL);
  150. if (!i)
  151. xv_set (button,
  152. PANEL_NEXT_ROW, -1,
  153. NULL);
  154. }
  155. */
  156. button = (Panel_button_item) xv_create (viewpanel, PANEL_BUTTON,
  157. PANEL_LABEL_STRING, "Quit",
  158. XV_KEY_DATA, KEY_DATA_VIEW, view,
  159. PANEL_CLIENT_DATA, viewframe,
  160. PANEL_NOTIFY_PROC, x_quit_cmd,
  161. NULL);
  162. window_fit (viewpanel);
  163. xv_set (viewpanel,
  164. XV_WIDTH, WIN_EXTEND_TO_EDGE,
  165. NULL);
  166. xv_set (viewframe,
  167. XV_KEY_DATA, KEY_DATA_PANEL, viewpanel,
  168. NULL);
  169. viewcanvas = xv_create (viewframe, TEXTSW,
  170. WIN_BELOW, viewpanel,
  171. XV_KEY_DATA, KEY_DATA_VIEW, view,
  172. TEXTSW_BROWSING, TRUE,
  173. TEXTSW_DISABLE_CD, TRUE,
  174. TEXTSW_DISABLE_LOAD, TRUE,
  175. TEXTSW_NOTIFY_PROC, textsw_notify,
  176. TEXTSW_NOTIFY_LEVEL, TEXTSW_NOTIFY_ALL,
  177. TEXTSW_IGNORE_LIMIT, TEXTSW_INFINITY,
  178. TEXTSW_INSERT_MAKES_VISIBLE, TEXTSW_IF_AUTO_SCROLL,
  179. TEXTSW_LOWER_CONTEXT, -1,
  180. TEXTSW_UPPER_CONTEXT, -1,
  181. NULL);
  182. xv_create (viewcanvas, SCROLLBAR,
  183. SCROLLBAR_DIRECTION, SCROLLBAR_VERTICAL,
  184. SCROLLBAR_SPLITTABLE, TRUE,
  185. NULL);
  186. fetch_content (viewcanvas, view);
  187. /* xv_create (viewcanvas, SCROLLBAR,
  188. SCROLLBAR_DIRECTION, SCROLLBAR_HORIZONTAL,
  189. SCROLLBAR_SPLITTABLE, TRUE,
  190. NULL);*/
  191. window_fit (viewframe);
  192. xv_set (viewframe,
  193. XV_KEY_DATA, KEY_DATA_CANVAS, viewcanvas,
  194. NULL);
  195. xv_set (viewframe,
  196. XV_SHOW, TRUE,
  197. NULL);
  198. }
  199. void x_view (WView *view)
  200. {
  201. create_frame (view);
  202. }
  203. static void x_quit_cmd (Panel_button_item button)
  204. {
  205. view_destroy ((WView *)xv_get(button, XV_KEY_DATA, KEY_DATA_VIEW));
  206. xv_destroy_safe ((Frame)xv_get(button, PANEL_CLIENT_DATA));
  207. xv_dispatch_a_bit();
  208. }