#ifndef lint
static char sccsid[] = "@(#)fv.file.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>
#include <sys/wait.h>
#include <string.h>
#ifdef OS3
# include <sys/dir.h>
#else
# include <dirent.h>
#endif
#ifdef SV1
#include <suntool/sunview.h>
#include <suntool/panel.h>
#include <suntool/tty.h>
#include <suntool/textsw.h>
#include <suntool/canvas.h>
#include <suntool/scrollbar.h>
#include <suntool/alert.h>
#include <suntool/fullscreen.h>
#else
#include <view2/view2.h>
#include <view2/panel.h>
#include <view2/tty.h>
#include <view2/textsw.h>
#include <view2/canvas.h>
#include <view2/scrollbar.h>
#include <view2/alert.h>
#include <view2/fullscreen.h>
#include <view2/seln.h>
#endif
#include "fv.port.h"
#include "fv.h"
#include "fv.extern.h"
/* The following three arrays contain the 8 or so RGB values for colors */
#include "fv.colormap.h"
u_char Fv_red[CMS_FVCOLORMAPSIZE];
u_char Fv_blue[CMS_FVCOLORMAPSIZE];
u_char Fv_green[CMS_FVCOLORMAPSIZE];
#define COLOR_FILE "..color" /* Contains sorted pairs of color/name*/
static short Ncolors; /* # color entries in COLOR_FILE*/
static char *Color_fname[MAXFILES]; /* Name... */
static SBYTE Color_code[MAXFILES]; /* ...and color pairs */
static int Maxfilesperline; /* Maximum files per line */
static int Incx; /* Columnar Increment */
static int Startx; /* Starting location */
static short Widest_name; /* Widest file name */
/* Variable and fixed widths for List Options */
static short Permission_width[2] = {8, 11};
static short Link_width[2] = {3, 5};
static short Owner_width[2] = {5, 9};
static short Group_width[2] = {5, 9};
static short Size_width[2] = {5, 9};
static short Date_width[2] = {9, 14};
static char Last_edited[MAXPATH]; /* Last edited filename */
#define ERASE 0177 /* Delete key on Sun-3 keyboards */
#define MAXRENAMELEN 80 /* Max length of rename string */
#define THRESHOLD 4 /* Move/copy mode (in pixels) */
#define LIST_HEIGHT 20 /* Height of lines in List mode */
static int compare_name(), compare_time(), compare_size(), compare_type(),
compare_color();
static ROUTINE Compare_fn[FV_SORTCOLOR+1] = {
compare_name, compare_time, compare_size, compare_type, compare_color,
};
extern time_t time();
static short If_image[] = {
#include "folderwin.icon"
};
mpr_static_static(f_icon_pr, 64, 48, 1, If_image);
static short Id_image[] = {
#include "docwin.icon"
};
mpr_static_static(d_icon_pr, 64, 64, 1, Id_image);
#ifdef SV1
static struct icon F_icon;
static struct icon D_icon;
#endif
#define MAX_TEXTSW 32
#ifdef SV1
static int Edit_id[MAX_TEXTSW];
static Textsw Edit_sw[MAX_TEXTSW];
#endif
static Frame Edit_fr[MAX_TEXTSW];
static int Edit_no;
#define MAX_FOLDERS 16
static Frame Folder_frame[MAX_FOLDERS]; /* Folder frames */
static int Nfolders;
static int Max_alloc; /* Number of allocated FV_FILE */
#define SIX_MONTHS_IN_SECS 15552000
#define HOUR_IN_SECS 3600
#define ICON_AREA_HEIGHT 66 /* Icon height + text height + gap */
static Panel Text_panel;
static Panel_item Text_item;
static int Scroll_increment;
static int Renamed_file; /* Index in Fv_file */
static void stop_editing();
#ifdef SV1
# define GET_SCROLL_VIEW_START (int)scrollbar_get(Fv_foldr.vsbar, SCROLL_VIEW_START)
#else
# define GET_SCROLL_VIEW_START ((int)scrollbar_get(Fv_foldr.vsbar, SCROLL_VIEW_START) * Scroll_increment)
#endif
void
fv_create_folder() /* Create folder canvas */
{
register int i; /* Index */
Notify_value folder_event();
static int display_folder();
struct singlecolor *color;
Fv_foldr.canvas = window_create(Fv_frame, CANVAS,
CANVAS_FAST_MONO, TRUE,
CANVAS_AUTO_SHRINK, FALSE,
CANVAS_AUTO_CLEAR, FALSE,
CANVAS_RETAINED, FALSE,
CANVAS_REPAINT_PROC, display_folder,
CANVAS_FIXED_IMAGE, FALSE,
WIN_BELOW, Fv_tree.canvas,
WIN_X, 0,
WIN_Y, 0,
WIN_ROWS, 10,
WIN_VERTICAL_SCROLLBAR,
Fv_foldr.vsbar = scrollbar_create(
#ifdef SV1
SCROLL_PLACEMENT, SCROLL_EAST, 0
#endif
),
0);
#ifdef SV1
Fv_foldr.pw = (PAINTWIN)canvas_pixwin(Fv_foldr.canvas);
Fv_color = Fv_foldr.pw->pw_pixrect->pr_depth > 1;
#else
Fv_foldr.pw = (PAINTWIN)vu_get(Fv_foldr.canvas, CANVAS_NTH_PAINT_WINDOW, 0);
Fv_color = (int)vu_get(Fv_frame, WIN_DEPTH) > 1;
#endif
if (Fv_color)
{
/* Apply color first; then decide whether this is a color monitor.
* Otherwise we have problems with single color monitor systems that
* have the monochrome and color framebuffer on the same device.
* Later:
* Shit! We still screwed. If you supply color on a monochrome
* device we try and use it. (It appears black.)
*/
cms_fvcolormapsetup(Fv_red, Fv_green, Fv_blue);
if (window_get(Fv_frame, FRAME_INHERIT_COLORS))
{
/* Grab the current background and foreground color and
* replace our generic colors (white and black).
* Reverse video display and color inheritance cause
* problems.
*/
color = (struct singlecolor *)window_get(Fv_frame,
FRAME_FOREGROUND_COLOR);
Fv_red[CMS_FVCOLORMAPSIZE-1] = Fv_red[1] = color->red;
Fv_green[CMS_FVCOLORMAPSIZE-1] = Fv_green[1] = color->green;
Fv_blue[CMS_FVCOLORMAPSIZE-1] = Fv_blue[1] = color->blue;
color = (struct singlecolor *)window_get(Fv_frame,
FRAME_BACKGROUND_COLOR);
Fv_red[0] = color->red;
Fv_green[0] = color->green;
Fv_blue[0] = color->blue;
}
pw_setcmsname(Fv_foldr.pw, "FVCOLORMAP");
pw_putcolormap(Fv_foldr.pw, 0, CMS_FVCOLORMAPSIZE,
Fv_red, Fv_green, Fv_blue);
}
#ifdef SV1
notify_interpose_event_func(Fv_foldr.canvas, folder_event, NOTIFY_SAFE);
#else
notify_interpose_event_func(Fv_foldr.pw, folder_event, NOTIFY_SAFE);
#endif
/* Look for events */
window_set(
#ifdef SV1
Fv_foldr.canvas,
#else
Fv_foldr.pw,
#endif
WIN_CONSUME_PICK_EVENTS,
LOC_WINENTER, LOC_WINEXIT,
ERASE, SHIFT_CTRL, LOC_DRAG, 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);
/* Create a text panel for editing on the canvas */
Text_panel = window_create(Fv_frame, PANEL,
WIN_SHOW, FALSE,
WIN_HEIGHT, 20,
0);
Text_item = panel_create_item(Text_panel, PANEL_TEXT,
PANEL_VALUE_STORED_LENGTH, 255,
PANEL_VALUE_X, 0, PANEL_VALUE_Y, 0,
PANEL_NOTIFY_PROC, stop_editing,
0);
/* Allocate enough memory for file structures.
* Allocating memory dynamically instead of statically allows
* us to swap pointers instead of copying structures whilst
* sorting, etc.
*/
Max_alloc = 128;
for (i=0; i<Max_alloc; i++)
{
Fv_file[i] = (FV_FILE *)fv_malloc(sizeof(FV_FILE));
if (Fv_file[i] == NULL)
break;
}
}
fv_file_scroll_height() /* Set scroll increment */
{
Scroll_increment = Fv_style & FV_DICON ? ICON_AREA_HEIGHT : LIST_HEIGHT;
scrollbar_set(Fv_foldr.vsbar, SCROLL_LINE_HEIGHT, Scroll_increment, 0);
}
static Notify_value
folder_event(cnvs, evnt, arg, typ) /* Process canvas events */
Canvas cnvs;
register Event *evnt;
Notify_arg arg;
Notify_event_type typ;
{
static struct timeval last_click; /* Last click time */
struct timeval click; /* Click time