home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / managers / mc-3.2 / mc-3 / mc-3.2.1 / xv / xvview.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  6.2 KB  |  221 lines

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