⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 screen.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 5 页
字号:
    file_entry *fe;

    length     = 0;
    empty_line = (file_index >= panel->count);
    home       = (isstatus) ? panel->status_format : panel->format;
    fe         = &panel->dir.list [file_index];

    if (!empty_line)
	color = file_compute_color (attr, fe);
    else
	color = NORMAL_COLOR;
    for (format = home; format; format = format->next){
	if (format->string_fn){
	    int len;

	    if (empty_line)
		txt = " ";
	    else
		txt = (*format->string_fn)(fe, format->field_len);

	    old_pos = cdest;

	    len = format->field_len;
	    if (len + length > width)
		len = width - length;
	    cdest = to_buffer (cdest, format->just_mode, len, txt);
	    length += len;

#ifdef HAVE_X
	    if (length == width)
		    break;
#else
            /* What shall we do? Will we color each line according to
	     * the file type? Any suggestions to mc@timur.kazan.su
	     */

            attrset (color);

            if (permission_mode && !strcmp(format->id, "perm"))
                add_permission_string (old_pos, format->field_len, fe, attr, color, 0);
            else if (permission_mode && !strcmp(format->id, "mode"))
                add_permission_string (old_pos, format->field_len, fe, attr, color, 1);
            else
		addstr (old_pos);
#endif
	} else {
#ifndef HAVE_X
            /* I'm preffer the view without this 3 lines, try to kill it :-) */
            if (attr == SELECTED || attr == MARKED_SELECTED)
                attrset (SELECTED_COLOR);
            else
                attrset (NORMAL_COLOR);
	    one_vline ();
#else
	    *cdest++ = ' ';
#endif
	    length++;
	}
    }

    if (length < width){
	int still = width - length;
	while (still--)
#ifdef HAVE_X
	    *cdest++ = ' ';
	*cdest = 0;
#else
	    addch (' ');
#endif
    }
}

#ifndef HAVE_X
void
repaint_file (WPanel *panel, int file_index, int mv, int attr, int isstatus)
{
    int    second_column = 0;
    int	   width, offset;
    char   buffer [255];

    offset = 0;
    if (!isstatus && panel->split){

	second_column = (file_index - panel->top_file) / llines (panel);
	width = (panel->widget.cols - 2)/2 - 1;

	if (second_column){
	    offset = 1 + width;
	    width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1;
	}
    } else
        width = (panel->widget.cols - 2);

    if (mv){
	if (!isstatus && panel->split){
	    widget_move (&panel->widget,
			 (file_index - panel->top_file) %
			 llines (panel) + 2,
			 (offset + 1));
	} else
	    widget_move (&panel->widget, file_index - panel->top_file + 2, 1);
    }

    format_file (buffer, panel, file_index, width, attr, isstatus);

    if (!isstatus && panel->split){
	if (second_column)
	    addch (' ');
	else {
	    attrset (NORMAL_COLOR);
	    one_vline ();
	}
    }
}
#endif

#ifndef PORT_HAS_DISPLAY_MINI_INFO
void
display_mini_info (WPanel *panel)
{
    if (!show_mini_info)
	return;

    widget_move (&panel->widget, llines (panel)+3, 1);

    if (panel->searching){
	attrset (INPUT_COLOR);
	printw ("/%-*s", panel->widget.cols-3, panel->search_buffer);
	attrset (NORMAL_COLOR);
	return;
    }

    /* Status displays total marked size */
    if (panel->marked){
	char buffer [100];
	char *p;

	attrset (MARKED_COLOR);
	printw  ("%*s", panel->widget.cols-2, " ");
	widget_move (&panel->widget, llines (panel)+3, 1);
	sprintf (buffer, _("  %s bytes in %d file%s"),
		 size_trunc_sep (panel->total), panel->marked,
		 panel->marked == 1 ? "" : "s");
	p = buffer;
	if (strlen (buffer) > panel->widget.cols-4){
	    buffer [panel->widget.cols-4] = 0;
	    p += 2;
	}
	printw ("%-*s", panel->widget.cols-2, p);
	return;
    }

    /* Status resolves links and show them */
    set_colors (panel);
#ifndef OS2_NT
    if (S_ISLNK (panel->dir.list [panel->selected].buf.st_mode)){
	char *link, link_target [MC_MAXPATHLEN];
	int  len;

	link = concat_dir_and_file (panel->cwd, panel->dir.list [panel->selected].fname);
	len = mc_readlink (link, link_target, MC_MAXPATHLEN);
	free (link);
	if (len > 0){
	    link_target[len] = 0;
	    printw ("-> %-*s", panel->widget.cols - 5,
		     name_trunc (link_target, panel->widget.cols - 5));
	} else
	    addstr (_("<readlink failed>"));
	return;
    }
#endif
    /* Default behaviour */
    repaint_file (panel, panel->selected, 0, STATUS, 1);
    return;
}
#endif

#ifndef HAVE_X
void
paint_dir (WPanel *panel)
{
    int i;
    int color;			/* Color value of the line */
    int items;			/* Number of items */

    items = llines (panel) * (panel->split ? 2 : 1);

    for (i = 0; i < items; i++){
	if (i+panel->top_file >= panel->count)
	    color = 0;
	else {
	    color = 2 * (panel->dir.list [i+panel->top_file].f.marked);
	    color += (panel->selected==i+panel->top_file && panel->active);
	}
	repaint_file (panel, i+panel->top_file, 1, color, 0);
    }
    standend ();
    panel->dirty = 0;
}
#endif

#ifdef HAVE_X
#define mini_info_separator(x)
#else
static void
mini_info_separator (WPanel *panel)
{
    if (!show_mini_info)
	return;

    standend ();
    widget_move (&panel->widget, llines (panel)+2, 1);
#ifdef HAVE_SLANG
    attrset (NORMAL_COLOR);
    hline (ACS_HLINE, panel->widget.cols-2);
#else
    hline ((slow_terminal ? '-' : ACS_HLINE) | NORMAL_COLOR,
	  panel->widget.cols-2);
#endif
}

void
show_dir (WPanel *panel)
{
    char tmp [200];

    set_colors (panel);
    draw_double_box (panel->widget.parent,
	            panel->widget.y,    panel->widget.x,
	            panel->widget.lines, panel->widget.cols);

#ifdef HAVE_SLANG
    if (show_mini_info) {
#ifdef linux_unicode
    	if (SLtt_Unicode) {
            SLsmg_draw_unicode (panel->widget.y + llines (panel) + 2,
                panel->widget.x, SLUNI_DSLTEE_CHAR);
            SLsmg_draw_unicode (panel->widget.y + llines (panel) + 2,
                panel->widget.x + panel->widget.cols - 1, SLUNI_DSRTEE_CHAR);
    	} else
#endif /* linux_unicode */
	{
            SLsmg_draw_object (panel->widget.y + llines (panel) + 2,
                panel->widget.x, SLSMG_LTEE_CHAR);
            SLsmg_draw_object (panel->widget.y + llines (panel) + 2,
                panel->widget.x + panel->widget.cols - 1, SLSMG_RTEE_CHAR);
        }
    }
#endif /* have_slang */

    if (panel->active)
	attrset (REVERSE_COLOR);

    widget_move (&panel->widget, 0, 3);

    trim (strip_home_and_password (panel->cwd), tmp, panel->widget.cols-7);
    addstr (tmp);
    widget_move (&panel->widget, 0, 1);
    addstr ("<");
    widget_move (&panel->widget, 0, panel->widget.cols-2);
    addstr (">");
    widget_move (&panel->widget, 0, panel->widget.cols-3);
    addstr ("v");

    if (panel->active)
	standend ();
}
#endif

#ifndef HAVE_TK
/* To be used only by long_frame and full_frame to adjust top_file */
static void
adjust_top_file (WPanel *panel)
{
    int old_top = panel->top_file;

    if (panel->selected - old_top > llines (panel))
	panel->top_file = panel->selected;
    if (old_top - panel->count > llines (panel))
	panel->top_file = panel->count - llines (panel);

#ifdef HAVE_TK
    if (old_top != panel->top_file)
	x_adjust_top_file (panel);
#endif
}
#else
#define adjust_top_file(p)
#endif

extern void paint_info_panel (WPanel *panel);

/* Repaints the information that changes after a command */
void
panel_update_contents (WPanel *panel)
{
    show_dir (panel);
#ifdef HAVE_X
    x_fill_panel (panel);
#else
    paint_dir (panel);
#endif
    display_mini_info (panel);
}

void
paint_panel (WPanel *panel)
{
    paint_frame (panel);
    panel_update_contents (panel);
    mini_info_separator (panel);
}

void
Xtry_to_select (WPanel *panel, char *name)
{
    int i;
    char *subdir;

    if (!name){
	panel->selected = 0;
	panel->top_file = 0;
	x_adjust_top_file (panel);
	return;
    }

    /* We only want the last component of the directory */
    for (subdir = name + strlen (name) - 1; subdir >= name; subdir--){
	if (*subdir == PATH_SEP){
	    subdir++;
	    break;
	}
    }
    if (subdir < name)
	subdir = name;

    /* Search that subdirectory, if found select it */
    for (i = 0; i < panel->count; i++){
	if (strcmp (subdir, panel->dir.list [i].fname))
	    continue;

	if (i != panel->selected){
	    panel->selected = i;
	    panel->top_file = panel->selected - (panel->widget.lines-2)/2;
	    if (panel->top_file < 0)
		panel->top_file = 0;
	    x_adjust_top_file (panel);
	}
	return;
    }

    /* Try to select a file near the file that is missing */
    if (panel->selected >= panel->count){
	panel->selected = panel->count-1;
	panel->top_file = panel->selected - (panel->widget.lines)/2;
	if (panel->top_file < 0)
	    panel->top_file = 0;
	x_adjust_top_file (panel);
    } else
	return;
}

#ifndef PORT_HAS_PANEL_UPDATE_COLS
void
panel_update_cols (Widget *widget, int frame_size)
{
    int cols, origin;

    if (horizontal_split){
	widget->cols = COLS;
	return;
    }

    if (frame_size == frame_full){
	cols = COLS;
	origin = 0;
    } else {
	if (widget == get_panel_widget (0)){
	    cols   = first_panel_size;
	    origin = 0;
	} else {
	    cols   = COLS-first_panel_size;
	    origin = first_panel_size;
	}
    }

    widget->cols = cols;
    widget->x = origin;
}
#endif

static char *
panel_save_name (WPanel *panel)
{
    extern int saving_setup;

    /* If the program is shuting down */
    if ((midnight_shutdown && auto_save_setup) || saving_setup)
	return copy_strings (panel->panel_name, 0);
    else
	return copy_strings ("Temporal:", panel->panel_name, 0);
}

static void
panel_destroy (WPanel *p)
{
    int i;

    char *name = panel_save_name (p);

    panel_save_setup (p, name);
    x_panel_destroy (p);
    clean_dir (&p->dir, p->count);

/* save and clean history */
    if (p->dir_history){
	Hist *current, *old;
	history_put (p->hist_name, p->dir_history);
	current = p->dir_history;
	while (current->next)
	    current = current->next;
	while (current){
	    old = current;
	    current = current->prev;
	    free (old->text);
	    free (old);
	}
    }
    free (p->hist_name);

    delete_format (p->format);
    delete_format (p->status_format);

    free (p->user_format);
    for (i = 0; i < LIST_TYPES; i++)
	free (p->user_status_format [i]);
    free (p->dir.list);
    free (p->panel_name);
    free (name);
}

static void
panel_format_modified (WPanel *panel)
{
    panel->format_modified = 1;
    x_reset_sort_labels (panel);
}

int
is_a_panel (Widget *w)
{
	return (w->callback == (void *) panel_callback);
}

void directory_history_add (WPanel * panel, char *s);

/* Panel creation */
/* The parameter specifies the name of the panel for setup retieving */
WPanel *
panel_new (char *panel_name)
{
    WPanel *panel;
    char *section;
    int i, err;

    panel = xmalloc (sizeof (WPanel), "panel_new");
    memset (panel, 0, sizeof (WPanel));

    /* No know sizes of the panel at startup */
    init_widget (&panel->widget, 0, 0, 0, 0, (callback_fn)
		 panel_callback, (destroy_fn) panel_destroy,
		 (mouse_h) panel_event, NULL);

    /* We do not want the cursor */
    widget_want_cursor (panel->widget, 0);

    mc_get_current_wd (panel->cwd, sizeof (panel->cwd)-2);
    strcpy (panel->lwd, ".");

    panel->hist_name = copy_strings ("Dir Hist ", panel_name, 0);
    panel->dir_history = history_get (panel->hist_name);
    directory_history_add (panel, panel->cwd);

    panel->dir.list         = (file_entry *) malloc (MIN_FILES * sizeof (file_entry));
    panel->dir.size         = MIN_FILES;
    panel->active           = 0;
    panel->filter           = 0;
    panel->split            = 0;
    panel->top_file         = 0;
    panel->selected         = 0;
    panel->marked           = 0;
    panel->total            = 0;
    panel->reverse          = 0;
    panel->dirty            = 1;
    panel->searching        = 0;
    panel->dirs_marked      = 0;
    panel->is_panelized     = 0;
    panel->has_dir_sizes    = 0;
    panel->format	    = 0;
    panel->status_format    = 0;
    panel->format_modified  = 1;

    panel->panel_name = strdup (panel_name);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -