1 /* XView help 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 <X11/cursorfont.h>
22 #include <xview/xview.h>
23 #include <xview/frame.h>
24 #include <xview/panel.h>
25 #include <xview/svrimage.h>
26 #include <xview/canvas.h>
27 #include <xview/scrollbar.h>
28 #include <xview/cms.h>
29 #include <xview/xv_xrect.h>
31 #include "../src/mad.h"
32 #include "../src/util.h"
39 #define RIGHTMARGIN 10
40 #define BOTTOMMARGIN 10
43 extern Server_image mcimage
; /* xvinfo.c */
44 Frame helpframe
= XV_NULL
;
55 extern char *currentpoint
, *startpoint
;
56 static void repaint (void);
57 static void clear_link_areas (void);
59 static void x_index_cmd (void)
65 static void x_back_cmd (void)
69 static void x_previous_cmd (void)
73 static void x_next_cmd (void)
77 static void x_search_cmd (void)
81 static void x_help_on_help (void)
87 static void x_quit_cmd (void)
89 xv_destroy_safe (helpframe
);
92 interactive_display_finish ();
96 fontstruct
getfont (char *name
, int fg
)
101 f
.font
= (Xv_Font
) xv_find (helpcanvas
, FONT
, FONT_NAME
, name
, NULL
);
102 if (f
.font
== XV_NULL
)
103 f
.font
= (Xv_Font
) xv_get (helpframe
, XV_FONT
);
104 gcvalues
.font
= (Font
) xv_get (f
.font
, XV_XID
);
105 gcvalues
.foreground
= (unsigned long) xv_get (helpcms
, CMS_PIXEL
, fg
);
106 gcvalues
.background
= (unsigned long) xv_get (helpcms
, CMS_BACKGROUND_PIXEL
);
107 gcvalues
.graphics_exposures
= FALSE
;
108 f
.gc
= XCreateGC (dpy
, RootWindow (dpy
, DefaultScreen (dpy
)),
109 GCForeground
|GCBackground
|GCFont
|GCGraphicsExposures
, &gcvalues
);
110 f
.height
= xv_get (f
.font
, FONT_DEFAULT_CHAR_HEIGHT
);
114 static char buffer
[200];
117 fontstruct fonormal
, fobold
, folink
, fotitle
;
118 #define NORMAL &fonormal
121 #define TITLE &fotitle
122 fontstruct
*curfont
, *linefont
, *wordfont
;
126 char *linebegin
, *wordbegin
;
129 typedef struct area
*AREA
;
131 int wx
; /* West x, Northwest y, Southwest y etc. */
140 AREA firstarea
= NULL
, lastarea
= NULL
;
141 int do_link_areas
= 1;
142 static int painting
= 1, linepainting
= 1;
144 static void clear_link_areas (void)
148 while (firstarea
!= NULL
) {
150 firstarea
= firstarea
->next
;
156 static void start_link_area (char *link
, int test
)
160 if (test
|| !do_link_areas
)
163 p
= (AREA
) xmalloc (sizeof (struct area
), "Help link area");
164 if (firstarea
!= NULL
)
179 static void end_link_area (int test
)
181 if (test
|| !do_link_areas
|| !lastarea
)
185 lastarea
->ney
= y
- h
;
189 static AREA
is_in_area (int x
, int y
)
193 for (p
= firstarea
; p
!= (AREA
) NULL
; p
= p
->next
) {
194 if (y
< p
->nwy
|| y
>= p
->sey
)
199 if (p
->nwy
== p
->ney
&& x
>= p
->ex
)
201 } else if (y
>= p
->ney
) {
210 static void hparse (char *paint_start
, int test
);
212 static void setfont (fontstruct
*f
)
217 static void newline (void)
222 hparse (linebegin
, 0);
225 linepainting
= painting
;
226 linebegin
= wordbegin
;
230 static int flush (char *p
, int test
)
232 Font_string_dims dims
;
234 buffer
[bufferindex
] = 0;
235 xv_get (curfont
->font
, FONT_STRING_DIMS
, buffer
, &dims
);
236 if (x
+ dims
.width
> paintwidth
- RIGHTMARGIN
&& x
) {
243 XDrawString (dpy
, xId
, curfont
->gc
, x
, y
, buffer
, strlen (buffer
));
253 static void hparse (char *paint_start
, int test
)
262 painting
= linepainting
;
270 wordbegin
= paint_start
;
271 linebegin
= paint_start
;
275 for (p
= paint_start
; *p
!= CHAR_NODE_END
; p
++){
278 case CHAR_LINK_START
:
282 start_link_area (p
, test
);
284 case CHAR_LINK_POINTER
:
289 end_link_area (test
);
299 strcpy (buffer
+ bufferindex
, VERSION
);
300 bufferindex
+= strlen (VERSION
);
314 int mcimage_width
= (int) xv_get (mcimage
, XV_WIDTH
);
315 int mcimage_height
= (int) xv_get (mcimage
, XV_HEIGHT
);
321 (Drawable
) xv_get (mcimage
, SERVER_IMAGE_PIXMAP
),
322 xId
, curfont
->gc
, 0,0, mcimage_width
, mcimage_height
,
323 x
, y
- mcimage_height
);
326 if (h
< mcimage_height
)
330 case CHAR_TEXTONLY_START
:
331 while (*p
&& *p
!= CHAR_NODE_END
&& *p
!= CHAR_TEXTONLY_END
)
333 if (*p
!= CHAR_TEXTONLY_END
)
336 case CHAR_XONLY_START
:
343 if (x
> LEFTMARGIN
) {
352 buffer
[bufferindex
++] = ' ';
359 x
= (x
+ tabsize
- LEFTMARGIN
) / tabsize
* tabsize
+ LEFTMARGIN
;
360 if (x
> paintwidth
- RIGHTMARGIN
) {
365 x
= tabsize
+ LEFTMARGIN
;
371 buffer
[bufferindex
++] = c
;
377 if (x
> LEFTMARGIN
) {
385 static void canvas_repaint (Canvas canvas
, Xv_Window paint
)
389 xId
= (Window
) xv_get (paint
, XV_XID
);
391 paintwidth
= (int) xv_get (xv_get (paint
, CANVAS_PAINT_VIEW_WINDOW
), XV_WIDTH
);
392 XClearWindow (dpy
, xId
);
393 hparse (startpoint
, 1);
397 static void canvas_resize (Canvas canvas
, int width
, int height
)
401 if (width
!= paintwidth
)
405 static void repaint (void)
407 Xv_Window paint
, view
;
412 OPENWIN_EACH_VIEW (helpcanvas
, view
)
413 paint
= (Xv_Window
) xv_get (view
, CANVAS_VIEW_PAINT_WINDOW
);
414 canvas_repaint (helpcanvas
, paint
);
418 CANVAS_MIN_PAINT_HEIGHT
, y
+ BOTTOMMARGIN
,
421 scroll
= (Scrollbar
) xv_get (helpcanvas
,
422 OPENWIN_VERTICAL_SCROLLBAR
, view
);
424 if (scroll
!= XV_NULL
) {
426 SCROLLBAR_VIEW_START
, 0,
429 SCROLLBAR_OBJECT_LENGTH
, y
+ BOTTOMMARGIN
,
436 unsigned short *bits
;
437 void (*callback
) (void);
439 index_bits
, x_index_cmd
,
440 back_bits
, x_back_cmd
,
441 previous_bits
, x_previous_cmd
,
442 next_bits
, x_next_cmd
,
443 search_bits
, x_search_cmd
};
446 static void event_handler (Xv_Window paint
, Event
*event
)
450 static int current_cursor
= 0;
452 switch (event_action (event
)) {
456 p
= is_in_area (x
, y
);
457 if (p
!= NULL
&& p
->jump
!= NULL
) {
458 currentpoint
= startpoint
= help_follow_link (startpoint
, p
->jump
);
465 p
= is_in_area (x
, y
);
467 if (!current_cursor
) {
468 XDefineCursor (dpy
, xv_get (paint
, XV_XID
), cursors
[1]);
472 if (current_cursor
) {
473 XDefineCursor (dpy
, xv_get (paint
, XV_XID
), cursors
[0]);
481 static void create_frame (void)
483 Panel_button_item button
;
486 helpcms
= (Cms
) xv_create (XV_NULL
, CMS
,
487 CMS_CONTROL_CMS
, TRUE
,
488 CMS_SIZE
, CMS_CONTROL_COLORS
+ 5,
489 CMS_NAMED_COLORS
, "black", "black", "green4", "red4", "black", NULL
,
492 helpframe
= xv_create (mcframe
, FRAME
,
493 FRAME_LABEL
, "Midnight X Commander Help",
495 FRAME_INHERIT_COLORS
, TRUE
,
498 helppanel
= xv_create (helpframe
, PANEL
,
501 xv_create (helppanel
, PANEL_BUTTON
,
502 PANEL_LABEL_STRING
, "Help",
503 PANEL_ITEM_MENU
, xv_create (XV_NULL
, MENU
,
505 MENU_STRING
, "Help on Help",
506 MENU_NOTIFY_PROC
, x_help_on_help
,
509 MENU_STRING
, "Index",
510 MENU_NOTIFY_PROC
, x_index_cmd
,
514 MENU_NOTIFY_PROC
, x_back_cmd
,
517 MENU_STRING
, "Previous",
518 MENU_NOTIFY_PROC
, x_previous_cmd
,
522 MENU_NOTIFY_PROC
, x_next_cmd
,
525 MENU_STRING
, "Search",
526 MENU_NOTIFY_PROC
, x_search_cmd
,
530 button
= (Panel_button_item
) xv_create (helppanel
, PANEL_BUTTON
,
531 PANEL_LABEL_STRING
, "Quit",
532 PANEL_NOTIFY_PROC
, x_quit_cmd
,
534 for (i
= 0; i
< sizeof (buttons
) / sizeof (buttons
[0]); i
++) {
535 button
= (Panel_button_item
) xv_create (helppanel
, PANEL_BUTTON
,
536 PANEL_LABEL_IMAGE
, xv_create (XV_NULL
, SERVER_IMAGE
,
537 SERVER_IMAGE_DEPTH
, 1,
540 SERVER_IMAGE_BITS
, buttons
[i
].bits
,
542 PANEL_NOTIFY_PROC
, buttons
[i
].callback
,
550 window_fit (helppanel
);
553 XV_WIDTH
, xv_get (helppanel
, XV_WIDTH
),
557 XV_WIDTH
, WIN_EXTEND_TO_EDGE
,
562 helpcanvas
= xv_create (helpframe
, CANVAS
,
563 WIN_BELOW
, helppanel
,
564 CANVAS_REPAINT_PROC
, canvas_repaint
,
565 CANVAS_RESIZE_PROC
, canvas_resize
,
566 CANVAS_X_PAINT_WINDOW
, FALSE
,
567 CANVAS_PAINTWINDOW_ATTRS
,
569 WIN_MOUSE_BUTTONS
, LOC_MOVE
, NULL
,
570 WIN_EVENT_PROC
, event_handler
,
574 cursors
[0] = (Cursor
) xv_get (xv_get (helpcanvas
, WIN_CURSOR
), XV_XID
);
575 cursors
[1] = XCreateFontCursor (dpy
, XC_hand2
);
577 xv_create (helpcanvas
, SCROLLBAR
,
578 SCROLLBAR_DIRECTION
, SCROLLBAR_VERTICAL
,
579 SCROLLBAR_SPLITTABLE
, TRUE
,
582 fonormal
= getfont ("lucidasans-12", CMS_CONTROL_COLORS
);
583 fobold
= getfont ("lucidasans-bold-12", CMS_CONTROL_COLORS
+ 1);
584 folink
= getfont ("lucidasans-12", CMS_CONTROL_COLORS
+ 2);
585 fotitle
= getfont ("lucidasans-bold-18", CMS_CONTROL_COLORS
+ 3);
587 window_fit (helpframe
);
598 void x_interactive_display (void)
600 if (helpframe
== XV_NULL
)