#ifndef lint
static char sccsid[] = "@(#)fv.tree.c 1.1 92/07/30 Copyr 1988 Sun Micro";
#endif
/* Copyright (c) 1987, 1988, Sun Microsystems, Inc. All Rights Reserved.
Sun considers its source code as an unpublished, proprietary
trade secret, and it is available only under strict license
provisions. This copyright notice is placed here only to protect
Sun in the event the source is deemed a published work. Dissassembly,
decompilation, or other means of reducing the object code to human
readable form is prohibited by the license agreement under which
this code is provided to the user or company in possession of this
copy.
RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the
Government is subject to restrictions as set forth in subparagraph
(c)(1)(ii) of the Rights in Technical Data and Computer Software
clause at DFARS 52.227-7013 and in similar clauses in the FAR and
NASA FAR Supplement. */
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#ifdef OS3
# include <sys/dir.h>
#else
# include <dirent.h>
#endif
#ifdef SV1
#include <suntool/sunview.h>
#include <suntool/panel.h>
#include <suntool/canvas.h>
#include <suntool/scrollbar.h>
#else
#include <view2/view2.h>
#include <view2/panel.h>
#include <view2/canvas.h>
#include <view2/scrollbar.h>
#endif
#include "fv.port.h"
#include "fv.h"
#include "fv.extern.h"
#define MAXSTACKDEPTH 5 /* How deep folders can layer */
#define THRESHOLD 4
static short Xpos; /* Tree position global */
static short Xmax, Ymax; /* Width, height of canvas */
static int Npath; /* Number of path buttons */
static int Lastevent; /* Last event seen */
static FV_TNODE *Chosen; /* Chosen folder (mouse()) */
static FV_TNODE *Lastselected; /* Last node selected */
static FV_TNODE *Mouse_stack[MAXSTACKDEPTH]; /* Selection in folder stack */
static FV_TNODE *Child; /* Descendant node */
static BOOLEAN Found_child; /* Did we find it? */
static FV_TNODE *path_chosen();
static FV_TNODE *mouse();
fv_create_tree_canvas()
{
static int tree_repaint();
static Notify_value tree_event();
Fv_tree.canvas = window_create(Fv_frame, CANVAS,
CANVAS_AUTO_CLEAR, FALSE,
CANVAS_AUTO_SHRINK, FALSE,
CANVAS_FAST_MONO, TRUE,
CANVAS_RETAINED, FALSE,
CANVAS_REPAINT_PROC, tree_repaint,
WIN_CONSUME_PICK_EVENTS,
KEY_LEFT(K_PROPS), KEY_LEFT(K_UNDO), KEY_LEFT(K_PUT),
KEY_LEFT(K_GET), KEY_LEFT(K_FIND), KEY_LEFT(K_DELETE),
0,
0);
#ifdef SV1
Fv_tree.pw = (PAINTWIN)canvas_pixwin(Fv_tree.canvas);
#else
Fv_tree.pw = (PAINTWIN)vu_get(Fv_tree.canvas, CANVAS_NTH_PAINT_WINDOW, 0);
#endif
Fv_tree.r.r_width = (int)window_get(Fv_tree.canvas, WIN_WIDTH);
Fv_tree.r.r_height = (int)window_get(Fv_tree.canvas, WIN_HEIGHT);
#ifdef SV1
notify_interpose_event_func(Fv_tree.canvas, tree_event, NOTIFY_SAFE);
#else
notify_interpose_event_func(Fv_tree.pw, tree_event, NOTIFY_SAFE);
#endif
}
static Notify_value
tree_event(cnvs, evnt, arg, typ)
Canvas cnvs;
register Event *evnt;
Notify_arg arg;
Notify_event_type typ;
{
static struct timeval last_click; /* Last time clicked */
struct timeval click; /* This time clicked */
BOOLEAN children; /* More children found? */
int x, y, i; /* Last coordinates */
if (event_is_down(evnt))
if (event_id(evnt) == MS_LEFT)
{
/* Clear any message */
fv_clrmsg();
/* Single click = selection
* Double click = open folder
*/
if (Fv_treeview)
#ifdef SV1
Fv_tselected = mouse(event_x(evnt)+Fv_tree.r.r_left,
event_y(evnt)+Fv_tree.r.r_top, Fv_thead);
#else
Fv_tselected = mouse(event_x(evnt), event_y(evnt), Fv_thead);
#endif
else
Fv_tselected = path_chosen(event_x(evnt), event_y(evnt));
if (Fv_tselected)
{
/* Only one window can have selections */
fv_filedeselect();
click = evnt->ie_time;
if (Lastselected == Fv_tselected)
{
if (click.tv_sec-last_click.tv_sec<=1)
{
if (Fv_treeview)
fv_open_folder();
else
{
fv_busy_cursor(TRUE);
Fv_current = Fv_tselected;
fv_getpath(Fv_tselected, (char *)0);
chdir(Fv_path);
(void)strcpy(Fv_openfolder_path, Fv_path);
fv_drawtree(TRUE);
fv_display_folder(FV_BUILD_FOLDER);
fv_busy_cursor(FALSE);
}
return(notify_next_event_func(cnvs, evnt,
arg, typ));
}
}
else
{
if (Fv_treeview)
{
fv_check_children(Fv_tselected, &children);
if (children)
fv_drawtree(TRUE);
else
{
reverse(Lastselected);
reverse(Fv_tselected);
}
}
else
{
reverse(Lastselected);
reverse(Fv_tselected);
}
}
last_click = click;
Lastselected = Fv_tselected;
#ifdef SV1
if (Fv_treeview)
{
/* Drag folder? */
x = event_x(evnt);
y = event_y(evnt);
while (window_read_event(cnvs, evnt) != -1 &&
event_id(evnt) != MS_LEFT)
if (((i = x-event_x(evnt))>THRESHOLD) ||
i<-THRESHOLD ||
((i = y-event_y(evnt))>THRESHOLD) ||
i<-THRESHOLD)
{
drag(cnvs, x, y);
break;
}
}
#endif
}
else
{
/* Clicking on white space clears selection */
fv_treedeselect();
fv_filedeselect();
}
}
else
if (event_id(evnt) == MS_RIGHT)
fv_viewmenu(cnvs, evnt, TRUE);
fv_check_keys(evnt);
Lastevent = event_id(evnt);
return(notify_next_event_func(cnvs,evnt,arg,typ));
}
/*ARGSUSED*/
static void
tree_repaint(canvas, pw, area) /* Repaint tree canvas */
Canvas canvas;
PAINTWIN pw;
Rectlist *area;
{
register Rect *rn;
static BOOLEAN lastview=TRUE; /* Last view state */
Fv_tree.r.r_height = (int)window_get(canvas, WIN_HEIGHT);
Fv_tree.r.r_width = (int)window_get(canvas, WIN_WIDTH);
rn = &area->rl_bound;
#ifdef SV1
if (Fv_treeview && Lastevent == SCROLL_REQUEST)
{
/* The tree is visible; handle scrolling or repainting */
if (Fv_tree.r.r_left != rn->r_left)
{
/* Horizontal scroll */
if (rn->r_width+SCROLLBAR_WIDTH >= Fv_tree.r.r_width)
Fv_tree.r.r_left = rn->r_left;
else
Fv_tree.r.r_left += Fv_tree.r.r_left < rn->r_left
? rn->r_width
: -rn->r_width;
}
else if (Fv_tree.r.r_top != rn->r_top)
{
/* Vertical scroll */
if (rn->r_height+SCROLLBAR_WIDTH >= Fv_tree.r.r_height)
Fv_tree.r.r_top = rn->r_top;
else
Fv_tree.r.r_top += Fv_tree.r.r_top < rn->r_top
? rn->r_height
:-rn->r_height;
}
}
#else
Fv_tree.r.r_top = (int)scrollbar_get(Fv_tree.vsbar,
SCROLL_VIEW_START) * 10 ;
Fv_tree.r.r_left = (int)scrollbar_get(Fv_tree.hsbar,
SCROLL_VIEW_START) * 10 ;
#endif
if (Fv_dont_paint)
return;
/* Recalculate tree positions when the tree view changes. Always keep
* open folder visible when state changes from path to tree...
*/
fv_drawtree((BOOLEAN)(lastview!=Fv_treeview));
if (!lastview && Fv_treeview && Fv_current)
fv_visiblefolder(Fv_current);
lastview = Fv_treeview;
}
#ifdef SV1
static
drag(cnvs, x, y)
Canvas cnvs;
register int x,y; /* Mouse coordinate */
{
register int x1, y1; /* Next mouse coordinate */
register int tx, ty; /* Folder coordinate */
int xoffset, yoffset; /* Offsets into canvas */
Event ev; /* Next event */
FV_TNODE *t_p; /* We're over this node */
FV_TNODE *tree_target = 0; /* Current open node */
FV_TNODE *tree_lock = 0; /* Current locked node */
register FV_TNODE *selected = Fv_tselected; /* Store selected */
char path[MAXPATH]; /* Target path */
window_set(cnvs, WIN_GRAB_ALL_INPUT, TRUE, 0);
tx = selected->x;
ty = selected->y;
xoffset = (int)scrollbar_get(Fv_tree.hsbar, SCROLL_VIEW_START);
yoffset = (int)scrollbar_get(Fv_tree.vsbar, SCROLL_VIEW_START);
while (window_read_event(cnvs, &ev) != -1 && event_id(&ev) != MS_LEFT)
{
pw_rop(Fv_tree.pw, tx, ty, GLYPH_WIDTH, TREE_GLYPH_HEIGHT,
PIX_SRC^PIX_DST, Fv_icon[FV_IFOLDER], 0, TREE_GLYPH_TOP);
x1 = event_x(&ev);
y1 = event_y(&ev);
tx += x1-x;
ty += y1-y;
t_p = mouse(x1+xoffset, y1+y
fv.rar_open
版权申诉
29 浏览量
2022-09-23
17:25:59
上传
评论
收藏 21KB RAR 举报
四散
- 粉丝: 51
- 资源: 1万+