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. */
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>
36 #include "../src/util.h"
37 #include "../src/mad.h"
46 extern void view_destroy(WView
*);
48 static void x_quit_cmd (Panel_button_item
);
52 void (*callback) (void);
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
)
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
);
70 n
= mc_read (view
->file
, p
, 2048);
71 textsw_insert (textsw
, p
, n
);
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
);
83 for (; *attrs
; attrs
= attr_next (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
);
92 xv_get (textsw
, TEXTSW_FIRST_LINE
);
102 static void create_frame (WView
*view
)
104 Panel_button_item button
;
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
,
113 viewframe
= xv_create (mcframe
, FRAME
,
116 FRAME_INHERIT_COLORS
, TRUE
,
117 FRAME_SHOW_FOOTER
, TRUE
,
118 XV_KEY_DATA
, KEY_DATA_VIEW
, view
,
121 viewpanel
= xv_create (viewframe
, PANEL
,
122 XV_KEY_DATA
, KEY_DATA_VIEW
, view
,
125 xv_create (viewpanel, PANEL_BUTTON,
126 PANEL_LABEL_STRING, "Help",
127 PANEL_ITEM_MENU, xv_create (XV_NULL, MENU,
129 MENU_STRING, "Help on Help",
130 MENU_NOTIFY_PROC, x_view_on_view,
133 MENU_STRING, "Index",
134 MENU_NOTIFY_PROC, x_index_cmd,
138 MENU_NOTIFY_PROC, x_back_cmd,
141 MENU_STRING, "Previous",
142 MENU_NOTIFY_PROC, x_previous_cmd,
146 MENU_NOTIFY_PROC, x_next_cmd,
149 MENU_STRING, "Search",
150 MENU_NOTIFY_PROC, x_search_cmd,
154 button = (Panel_button_item) xv_create (viewpanel, PANEL_BUTTON,
155 PANEL_LABEL_STRING, "Quit",
156 PANEL_NOTIFY_PROC, x_quit_cmd,
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,
164 SERVER_IMAGE_BITS, buttons [i].bits,
166 PANEL_NOTIFY_PROC, buttons [i].callback,
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
,
181 window_fit (viewpanel
);
184 XV_WIDTH
, WIN_EXTEND_TO_EDGE
,
188 XV_KEY_DATA
, KEY_DATA_PANEL
, viewpanel
,
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,
205 xv_create (viewcanvas
, SCROLLBAR
,
206 SCROLLBAR_DIRECTION
, SCROLLBAR_VERTICAL
,
207 SCROLLBAR_SPLITTABLE
, TRUE
,
210 fetch_content (viewcanvas
, view
);
211 /* xv_create (viewcanvas, SCROLLBAR,
212 SCROLLBAR_DIRECTION, SCROLLBAR_HORIZONTAL,
213 SCROLLBAR_SPLITTABLE, TRUE,
216 window_fit (viewframe
);
219 XV_KEY_DATA
, KEY_DATA_CANVAS
, viewcanvas
,
228 void x_view (WView
*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
));