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

📄 boxes.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 2 页
字号:
				maxlen = l1;
		}
		l1 = strlen (display_widgets [2].text);
		if (l1 > maxlen)
			maxlen = l1;


		display_bits.xlen = (maxlen + 5) * 6 / 4;

		/* See above confirm_box */
		l1 = strlen (display_widgets [0].text) + 3;
		i = strlen (display_widgets [1].text) + 5;
		if (i > l1)
			l1 = i;

		i = (l1 + 3) * 6 / 2;
		if (i > display_bits.xlen)
			display_bits.xlen = i;

		display_bits.title = _(display_bits.title);
		i18n_flag = display_bits.i18n = 1;
	}

#endif /* ENABLE_NLS */

    if (full_eight_bits)
	current_mode = 0;
    else if (eight_bit_clean)
	current_mode = 1;
    else
	current_mode = 2;

    display_widgets [3].value = current_mode;
    new_meta = !use_8th_bit_as_meta;
    if (quick_dialog (&display_bits) != B_ENTER)
	    return;

    eight_bit_clean = new_mode < 2;
    full_eight_bits = new_mode == 0;
#ifndef HAVE_SLANG
    meta (stdscr, eight_bit_clean);
#else
    SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
#endif
    use_8th_bit_as_meta = !new_meta;
}

#define TREE_Y 20
#define TREE_X 60

static int tree_colors [4];

static int tree_callback (struct Dlg_head *h, int id, int msg)
{
    switch (msg){

    case DLG_POST_KEY:
	/* The enter key will be processed by the tree widget */
	if (id == '\n' || ((WTree *)(h->current->widget))->done){
	    h->ret_value = B_ENTER;
	    dlg_stop (h);
	}
	return MSG_HANDLED;

    case DLG_DRAW:
	common_dialog_repaint (h);
	break;
    }
    return MSG_NOT_HANDLED;
}

char *tree (char *current_dir)
{
    WTree    *mytree;
    Dlg_head *dlg;
    char     *val;
    WButtonBar *bar;

    tree_colors [3] = dialog_colors [0];
    tree_colors [1] = dialog_colors [1];

    /* Create the components */
    dlg = create_dlg (0, 0, TREE_Y, TREE_X, tree_colors,
		      tree_callback, "[Directory Tree]", "tree", DLG_CENTER);
    mytree = tree_new (0, 2, 2, TREE_Y - 6, TREE_X - 5);
    add_widget (dlg, mytree);
    bar = buttonbar_new(1);
    add_widget (dlg, bar);
    bar->widget.x = 0;
    bar->widget.y = LINES - 1;

    run_dlg (dlg);
    if (dlg->ret_value == B_ENTER)
	val = strdup (mytree->selected_ptr->name);
    else
	val = 0;

    destroy_dlg (dlg);
    return val;
}
#ifndef USE_VFS
#ifdef USE_NETCODE
#undef USE_NETCODE
#endif
#endif

#ifdef USE_VFS

#if defined(USE_NETCODE)
#define VFSY 15
#else
#define VFSY 11
#endif

#define VFSX 56

extern int vfs_timeout;
extern int tar_gzipped_memlimit;
extern int ftpfs_always_use_proxy;

#if defined(USE_NETCODE)
extern char *ftpfs_anonymous_passwd;
extern char *ftpfs_proxy_host;
extern ftpfs_directory_timeout;
extern int use_netrc;
#endif

int vfs_use_limit = 1;
static char *ret_timeout;
static char *ret_limit;

#if defined(USE_NETCODE)
static char *ret_passwd;
static char *ret_directory_timeout;
static char *ret_ftp_proxy;
static int ret_use_netrc;
#endif

#if 0
/* Not used currently */
{ quick_checkbox,  4, VFSX, 10, VFSY, "Use ~/.netrc",
      'U', 0, 0, &ret_use_netrc, 0, XV_WLAY_BELOWCLOSE, "" },
#endif

char *confvfs_str [] =
{ N_("Always to memory"), N_("If size less than:") };

static QuickWidget confvfs_widgets [] = {
{ quick_button,   30,  VFSX,    VFSY - 3, VFSY, N_("&Cancel"),
      0, B_CANCEL, 0, 0, XV_WLAY_RIGHTOF, "button-cancel" },
{ quick_button,   12, VFSX,    VFSY - 3, VFSY, N_("&Ok"),
      0, B_ENTER, 0, 0, XV_WLAY_CENTERROW, "button-ok" },
#if defined(USE_NETCODE)
{ quick_input,    30, VFSX, 10, VFSY, "", 22, 0, 0, &ret_ftp_proxy,
      XV_WLAY_RIGHTDOWN, "input-ftp-proxy" },
{ quick_checkbox,    4, VFSX, 10, VFSY, N_("&Always use ftp proxy"), 0, 0,
      &ftpfs_always_use_proxy, 0, XV_WLAY_RIGHTDOWN, "check-ftp-proxy" },
{ quick_label,    46, VFSX, 9, VFSY, N_("sec"),
      0, 0, 0, 0, XV_WLAY_RIGHTOF, "label-sec" },
{ quick_input,    35, VFSX, 9, VFSY, "", 10, 0, 0, &ret_directory_timeout,
      XV_WLAY_RIGHTDOWN, "input-timeout" },
{ quick_label,     4, VFSX, 9, VFSY, N_("ftpfs directory cache timeout:"),
      0, 0, 0, 0, XV_WLAY_NEXTROW, "label-cache"},
{ quick_input,    28, VFSX, 8, VFSY, "", 24, 0, 0, &ret_passwd,
      XV_WLAY_RIGHTDOWN, "input-passwd" },
{ quick_label,     4, VFSX, 8, VFSY, N_("ftp anonymous password:"),
      0, 0, 0, 0, XV_WLAY_NEXTROW, "label-pass"},
#endif
{ quick_input,    26, VFSX, 6, VFSY, "", 10, 0, 0, &ret_limit,
      XV_WLAY_RIGHTDOWN, "input-limit" },
{ quick_radio,    4, VFSX, 5, VFSY, "", 2, 0,
      &vfs_use_limit, confvfs_str, XV_WLAY_BELOWCLOSE, "radio" },
{ quick_label,    4,  VFSX, 4, VFSY, N_("Gzipped tar archive extract:"),
      0, 0, 0, 0, XV_WLAY_NEXTROW, "label-tar" },
{ quick_label,    46, VFSX, 3, VFSY, "sec",
      0, 0, 0, 0, XV_WLAY_RIGHTOF, "label-sec2" },
{ quick_input,    35, VFSX, 3, VFSY, "", 10, 0, 0, &ret_timeout,
      XV_WLAY_RIGHTOF, "input-timo-vfs" },
{ quick_label,    4,  VFSX, 3, VFSY, N_("Timeout for freeing VFSs:"),
      0, 0, 0, 0, XV_WLAY_BELOWCLOSE, "label-vfs" },
{ 0,              0, 0, 0, 0, 0, 0, 0, 0, 0, 0, XV_WLAY_DONTCARE, 0 }
};

static QuickDialog confvfs_dlg =
{ VFSX, VFSY, -1, -1, N_(" Virtual File System Setting "), "[Virtual FS]", "quick_vfs", confvfs_widgets, 0 };

#if defined(USE_NETCODE)
#define VFS_WIDGETBASE 7
#else
#define VFS_WIDGETBASE 0
#endif

void configure_vfs ()
{
    char buffer1 [15], buffer2 [15];
#if defined(USE_NETCODE)
    char buffer3[15];
#endif

    if (tar_gzipped_memlimit > -1) {
        if (tar_gzipped_memlimit == 0)
            strcpy (buffer1, "0 B");
	else if ((tar_gzipped_memlimit % (1024*1024)) == 0) /* I.e. in M */
	    sprintf (buffer1, "%i MB", (int)(((unsigned)tar_gzipped_memlimit) >> 20));
	else if ((tar_gzipped_memlimit % 1024) == 0) /* I.e. in K */
	    sprintf (buffer1, "%i KB", (int)(((unsigned)tar_gzipped_memlimit) >> 10));
	else if ((tar_gzipped_memlimit % 1000) == 0)
	    sprintf (buffer1, "%i kB", (int)(tar_gzipped_memlimit / 1000));
	else
	    sprintf (buffer1, "%i B", (int)tar_gzipped_memlimit);
        confvfs_widgets [2 + VFS_WIDGETBASE].text = buffer1;
    } else
    	confvfs_widgets [2 + VFS_WIDGETBASE].text = "5 MB";
    sprintf (buffer2, "%i", vfs_timeout);
    confvfs_widgets [6 + VFS_WIDGETBASE].text = buffer2;
    confvfs_widgets [3 + VFS_WIDGETBASE].value = vfs_use_limit;
#if defined(USE_NETCODE)
    ret_use_netrc = use_netrc;
    sprintf(buffer3, "%i", ftpfs_directory_timeout);
    confvfs_widgets[5].text = buffer3;
    confvfs_widgets[7].text = ftpfs_anonymous_passwd;
    confvfs_widgets[2].text = ftpfs_proxy_host ? ftpfs_proxy_host : "";
#endif

    if (quick_dialog (&confvfs_dlg) != B_CANCEL) {
        char *p;

        vfs_timeout = atoi (ret_timeout);
        free (ret_timeout);
        if (vfs_timeout < 0 || vfs_timeout > 10000)
            vfs_timeout = 10;
        if (!vfs_use_limit)
            tar_gzipped_memlimit = -1;
        else {
            tar_gzipped_memlimit = atoi (ret_limit);
            if (tar_gzipped_memlimit < 0)
                tar_gzipped_memlimit = -1;
            else {
                for (p = ret_limit; *p == ' ' || (*p >= '0' && *p <= '9'); p++);
                switch (*p) {
		case 'm':
		case 'M': tar_gzipped_memlimit <<= 20; break;
		case 'K': tar_gzipped_memlimit <<= 10; break;
		case 'k': tar_gzipped_memlimit *= 1000; break;
                }
            }
        }
        free (ret_limit);
#if defined(USE_NETCODE)
	free(ftpfs_anonymous_passwd);
	ftpfs_anonymous_passwd = ret_passwd;
	if (ftpfs_proxy_host)
	    free(ftpfs_proxy_host);
	ftpfs_proxy_host = ret_ftp_proxy;
	ftpfs_directory_timeout = atoi(ret_directory_timeout);
	use_netrc = ret_use_netrc;
	free(ret_directory_timeout);
#endif
    }
}

#endif

char *cd_dialog (void)
{
    QuickDialog Quick_input;
    QuickWidget quick_widgets [] = {
#ifdef HAVE_TK
#define INPUT_INDEX 2
    { quick_button, 0, 1, 0, 1, N_("&Cancel"), 0, B_CANCEL, 0, 0, XV_WLAY_DONTCARE, "cancel" },
    { quick_button, 0, 1, 0, 1, N_("&Ok"),     0, B_ENTER,  0, 0, XV_WLAY_DONTCARE, "ok" },
#else
#define INPUT_INDEX 0
#endif
    { quick_input,  6, 57, 5, 0, "", 50, 0, 0, 0, XV_WLAY_RIGHTOF, "input" },
    { quick_label,  3, 57, 2, 0, "",  0, 0, 0, 0, XV_WLAY_DONTCARE, "label" },
    { 0 } };

    char *my_str;
	int len;

    Quick_input.xlen  = 57;
    Quick_input.title = _("Quick cd");
    Quick_input.help  = "[Quick cd]";
    Quick_input.class = "quick_input";
    quick_widgets [INPUT_INDEX].text = "";
    quick_widgets [INPUT_INDEX].value = 2; /* want cd like completion */
    quick_widgets [INPUT_INDEX+1].text = _("cd");
    quick_widgets [INPUT_INDEX+1].y_divisions =
	quick_widgets [INPUT_INDEX].y_divisions = Quick_input.ylen = 5;

	len = strlen (quick_widgets [INPUT_INDEX+1].text);

	quick_widgets [INPUT_INDEX+1].relative_x = 3;
	quick_widgets [INPUT_INDEX].relative_x =
		quick_widgets [INPUT_INDEX+1].relative_x + len + 1;

    Quick_input.xlen = len + quick_widgets [INPUT_INDEX].hotkey_pos + 7;
	quick_widgets [INPUT_INDEX].x_divisions =
		quick_widgets [INPUT_INDEX+1].x_divisions = Quick_input.xlen;

    Quick_input.i18n = 1;
    Quick_input.xpos = 2;
    Quick_input.ypos = LINES - 2 - Quick_input.ylen;
    quick_widgets [INPUT_INDEX].relative_y = 2;
    quick_widgets [INPUT_INDEX].str_result = &my_str;

    Quick_input.widgets = quick_widgets;
    if (quick_dialog (&Quick_input) != B_CANCEL){
	return *(quick_widgets [INPUT_INDEX].str_result);
    } else
	return 0;
}

void symlink_dialog (char *existing, char *new, char **ret_existing,
    char **ret_new)
{
    QuickDialog Quick_input;
    QuickWidget quick_widgets [] = {
#undef INPUT_INDEX
#if defined(HAVE_TK) || defined(HAVE_GNOME)
#define INPUT_INDEX 2
    { quick_button, 0, 1, 0, 1, _("&Cancel"), 0, B_CANCEL, 0, 0,
	  XV_WLAY_DONTCARE, "cancel" },
    { quick_button, 0, 1, 0, 1, _("&Ok"), 0, B_ENTER, 0, 0,
	  XV_WLAY_DONTCARE, "ok" },
#else
#define INPUT_INDEX 0
#endif
    { quick_input,  6, 80, 5, 8, "", 58, 0, 0, 0, XV_WLAY_BELOWCLOSE, "input-1" },
    { quick_label,  6, 80, 4, 8, "", 0, 0, 0, 0, XV_WLAY_BELOWOF, "label-1" },
    { quick_input,  6, 80, 3, 8, "", 58, 0, 0, 0, XV_WLAY_BELOWCLOSE, "input-2" },
    { quick_label,  6, 80, 2, 8, "", 0, 0, 0, 0, XV_WLAY_DONTCARE, "label-2" },
    { 0 } };

    Quick_input.xlen  = 64;
    Quick_input.ylen  = 8;
    Quick_input.title = "Symbolic link";
    Quick_input.help  = "[File Menu]";
    Quick_input.class = "quick_symlink";
    Quick_input.i18n  = 0;
    quick_widgets [INPUT_INDEX].text = new;
    quick_widgets [INPUT_INDEX+1].text = _("Symbolic link filename:");
    quick_widgets [INPUT_INDEX+2].text = existing;
    quick_widgets [INPUT_INDEX+3].text = _("Existing filename (filename symlink will point to):");
    Quick_input.xpos = -1;
    quick_widgets [INPUT_INDEX].str_result = ret_new;
    quick_widgets [INPUT_INDEX+2].str_result = ret_existing;

    Quick_input.widgets = quick_widgets;
    if (quick_dialog (&Quick_input) == B_CANCEL){
        *ret_new = NULL;
        *ret_existing = NULL;
    }
}

#ifdef WITH_BACKGROUND
#define B_STOP   B_USER+1
#define B_RESUME B_USER+2
#define B_KILL   B_USER+3

static int JOBS_X = 60;
#define JOBS_Y 15
static WListbox *bg_list;
static Dlg_head *jobs_dlg;

static void
jobs_fill_listbox (void)
{
    static char *state_str [2];
    TaskList *tl = task_list;

    if (!state_str [0]){
       state_str [0] = _("Running ");
       state_str [1] = _("Stopped");
    }

    while (tl){
	char *s;

	s = copy_strings (state_str [tl->state], " ", tl->info, NULL);
	listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl);
	free (s);
	tl = tl->next;
    }
}

static int
task_cb (int action, void *ignored)
{
    TaskList *tl;
    int sig;

    if (!bg_list->list)
	return 0;

    /* Get this instance information */
    tl = (TaskList *) bg_list->current->data;

    if (action == B_STOP){
	sig   = SIGSTOP;
	tl->state = Task_Stopped;
    } else if (action == B_RESUME){
	sig   = SIGCONT;
	tl->state = Task_Running;
    } else if (action == B_KILL){
	sig = SIGKILL;
    }

    if (sig == SIGINT)
	unregister_task_running (tl->pid, tl->fd);

    kill (tl->pid, sig);
    listbox_remove_list (bg_list);
    jobs_fill_listbox ();

    /* This can be optimized to just redraw this widget :-) */
    dlg_redraw (jobs_dlg);

    return 0;
}

static struct
{
	char* name;
	int xpos;
	int value;
	int (*callback)();
	char* tkname;
}
job_buttons [] =
{
	{N_("&Stop"),   3,  B_STOP,   task_cb, "button-stop"},
	{N_("&Resume"), 12, B_RESUME, task_cb, "button-cont"},
	{N_("&Kill"),   23, B_KILL,   task_cb, "button-kill"},
	{N_("&Ok"),     35, B_CANCEL, NULL,    "button-ok"},
};

void
jobs_cmd (void)
{
	register int i;
	int n_buttons = sizeof (job_buttons) / sizeof (job_buttons[0]);

#ifdef ENABLE_NLS
	static int i18n_flag = 0;
	if (!i18n_flag)
	{
		int startx = job_buttons [0].xpos;
		int len;

		for (i = 0; i < n_buttons; i++)
		{
			job_buttons [i].name = _(job_buttons [i].name);

			len = strlen (job_buttons [i].name) + 4;
			JOBS_X = max (JOBS_X, startx + len + 3);

			job_buttons [i].xpos = startx;
			startx += len;
		}

		/* Last button - Ok a.k.a. Cancel :) */
		job_buttons [n_buttons - 1].xpos =
			JOBS_X - strlen (job_buttons [n_buttons - 1].name) - 7;

		i18n_flag = 1;
	}
#endif /* ENABLE_NLS */

    jobs_dlg = create_dlg (0, 0, JOBS_Y, JOBS_X, dialog_colors,
			   common_dialog_callback, "[Background jobs]", "jobs",
			   DLG_CENTER | DLG_GRID);
    x_set_dialog_title (jobs_dlg, _("Background Jobs"));

    bg_list = listbox_new (2, 3, JOBS_X-7, JOBS_Y-9, listbox_nothing, 0, "listbox");
    add_widget (jobs_dlg, bg_list);

	i = n_buttons;
	while (i--)
	{
		add_widget (jobs_dlg, button_new (JOBS_Y-4,
			job_buttons [i].xpos, job_buttons [i].value,
			NORMAL_BUTTON, job_buttons [i].name,
			job_buttons [i].callback, 0,
			job_buttons [i].tkname));
	}

    /* Insert all of task information in the list */
    jobs_fill_listbox ();
    run_dlg (jobs_dlg);

    destroy_dlg (jobs_dlg);
}
#endif

⌨️ 快捷键说明

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