ru.po: Heavily updated translation
[midnight-commander.git] / xv / xvview.c
blobf1a1a61219fd8a63e930b45db1b8522711a3ecb9
1 /* XView viewer routines.
2 Copyright (C) 1995 Jakub Jelinek.
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.
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.
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. */
18 #include <config.h>
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>
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"
40 extern Frame mcframe;
41 Frame viewframe;
42 Panel viewpanel;
43 Textsw viewcanvas;
44 Cms viewcms;
46 extern void view_destroy(WView *);
48 static void x_quit_cmd (Panel_button_item);
50 /*static struct {
51 unsigned short *bits;
52 void (*callback) (void);
53 } buttons [] = {
54 index_bits, x_index_cmd,
55 back_bits, x_back_cmd,
56 previous_bits, x_previous_cmd,
57 next_bits, x_next_cmd,
58 search_bits, x_search_cmd };*/
60 static void fetch_content (Textsw textsw, WView *view)
62 char *p;
63 int n;
65 if (view->growing_buffer) {
66 p = xmalloc (2048, "view growing");
67 if (view->stdfile != (FILE *)-1)
68 n = fread (p, 1, 2048, view->stdfile);
69 else
70 n = mc_read (view->file, p, 2048);
71 textsw_insert (textsw, p, n);
72 free (p);
73 } else {
74 textsw_insert (textsw, view->data, view->bytes_read);
78 static void textsw_notify (Textsw textsw, Attr_attribute *attrs)
80 WView *view = (WView *) xv_get (textsw, XV_KEY_DATA, KEY_DATA_VIEW);
81 Rect *from, *to;
83 for (; *attrs; attrs = attr_next (attrs)) {
84 switch (*attrs) {
85 case TEXTSW_ACTION_SCROLLED:
86 from = (Rect *) attrs [1];
87 to = (Rect *) attrs [2];
88 if (view->growing_buffer) {
89 if (view->stdfile != (FILE *) -1) {
90 xv_get (textsw, TEXTSW_FIRST_LINE);
91 } else {
92 xv_get (textsw, TEXTSW_FIRST_LINE);
95 break;
96 default:
97 break;
102 static void create_frame (WView *view)
104 Panel_button_item button;
105 /* int i;*/
107 viewcms = (Cms) xv_create (XV_NULL, CMS,
108 CMS_CONTROL_CMS, TRUE,
109 CMS_SIZE, CMS_CONTROL_COLORS + 5,
110 CMS_NAMED_COLORS, "black", "red4", "green4", "black", NULL,
111 NULL);
113 viewframe = xv_create (mcframe, FRAME,
114 FRAME_LABEL, "View",
115 WIN_CMS, viewcms,
116 FRAME_INHERIT_COLORS, TRUE,
117 FRAME_SHOW_FOOTER, TRUE,
118 XV_KEY_DATA, KEY_DATA_VIEW, view,
119 NULL);
121 viewpanel = xv_create (viewframe, PANEL,
122 XV_KEY_DATA, KEY_DATA_VIEW, view,
123 NULL);
125 xv_create (viewpanel, PANEL_BUTTON,
126 PANEL_LABEL_STRING, "Help",
127 PANEL_ITEM_MENU, xv_create (XV_NULL, MENU,
128 MENU_ITEM,
129 MENU_STRING, "Help on Help",
130 MENU_NOTIFY_PROC, x_view_on_view,
131 NULL,
132 MENU_ITEM,
133 MENU_STRING, "Index",
134 MENU_NOTIFY_PROC, x_index_cmd,
135 NULL,
136 MENU_ITEM,
137 MENU_STRING, "Back",
138 MENU_NOTIFY_PROC, x_back_cmd,
139 NULL,
140 MENU_ITEM,
141 MENU_STRING, "Previous",
142 MENU_NOTIFY_PROC, x_previous_cmd,
143 NULL,
144 MENU_ITEM,
145 MENU_STRING, "Next",
146 MENU_NOTIFY_PROC, x_next_cmd,
147 NULL,
148 MENU_ITEM,
149 MENU_STRING, "Search",
150 MENU_NOTIFY_PROC, x_search_cmd,
151 NULL,
152 NULL),
153 NULL);
154 button = (Panel_button_item) xv_create (viewpanel, PANEL_BUTTON,
155 PANEL_LABEL_STRING, "Quit",
156 PANEL_NOTIFY_PROC, x_quit_cmd,
157 NULL);
158 for (i = 0; i < sizeof (buttons) / sizeof (buttons [0]); i++) {
159 button = (Panel_button_item) xv_create (viewpanel, PANEL_BUTTON,
160 PANEL_LABEL_IMAGE, xv_create (XV_NULL, SERVER_IMAGE,
161 SERVER_IMAGE_DEPTH, 1,
162 XV_WIDTH, 48,
163 XV_HEIGHT, 48,
164 SERVER_IMAGE_BITS, buttons [i].bits,
165 NULL),
166 PANEL_NOTIFY_PROC, buttons [i].callback,
167 NULL);
168 if (!i)
169 xv_set (button,
170 PANEL_NEXT_ROW, -1,
171 NULL);
174 button = (Panel_button_item) xv_create (viewpanel, PANEL_BUTTON,
175 PANEL_LABEL_STRING, "Quit",
176 XV_KEY_DATA, KEY_DATA_VIEW, view,
177 PANEL_CLIENT_DATA, viewframe,
178 PANEL_NOTIFY_PROC, x_quit_cmd,
179 NULL);
181 window_fit (viewpanel);
183 xv_set (viewpanel,
184 XV_WIDTH, WIN_EXTEND_TO_EDGE,
185 NULL);
187 xv_set (viewframe,
188 XV_KEY_DATA, KEY_DATA_PANEL, viewpanel,
189 NULL);
191 viewcanvas = xv_create (viewframe, TEXTSW,
192 WIN_BELOW, viewpanel,
193 XV_KEY_DATA, KEY_DATA_VIEW, view,
194 TEXTSW_BROWSING, TRUE,
195 TEXTSW_DISABLE_CD, TRUE,
196 TEXTSW_DISABLE_LOAD, TRUE,
197 TEXTSW_NOTIFY_PROC, textsw_notify,
198 TEXTSW_NOTIFY_LEVEL, TEXTSW_NOTIFY_ALL,
199 TEXTSW_IGNORE_LIMIT, TEXTSW_INFINITY,
200 TEXTSW_INSERT_MAKES_VISIBLE, TEXTSW_IF_AUTO_SCROLL,
201 TEXTSW_LOWER_CONTEXT, -1,
202 TEXTSW_UPPER_CONTEXT, -1,
203 NULL);
205 xv_create (viewcanvas, SCROLLBAR,
206 SCROLLBAR_DIRECTION, SCROLLBAR_VERTICAL,
207 SCROLLBAR_SPLITTABLE, TRUE,
208 NULL);
210 fetch_content (viewcanvas, view);
211 /* xv_create (viewcanvas, SCROLLBAR,
212 SCROLLBAR_DIRECTION, SCROLLBAR_HORIZONTAL,
213 SCROLLBAR_SPLITTABLE, TRUE,
214 NULL);*/
216 window_fit (viewframe);
218 xv_set (viewframe,
219 XV_KEY_DATA, KEY_DATA_CANVAS, viewcanvas,
220 NULL);
222 xv_set (viewframe,
223 XV_SHOW, TRUE,
224 NULL);
228 void x_view (WView *view)
230 create_frame (view);
233 static void x_quit_cmd (Panel_button_item button)
235 view_destroy ((WView *)xv_get(button, XV_KEY_DATA, KEY_DATA_VIEW));
236 xv_destroy_safe ((Frame)xv_get(button, PANEL_CLIENT_DATA));
237 xv_dispatch_a_bit();