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

📄 wtools.c

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

static int  remove_callback (int i, void *data)
{
    Chooser *c = (Chooser *) data;

    listbox_remove_current (c->listbox, 0);

    dlg_select_widget (c->dialog, c->listbox);
    dlg_select_nth_widget (c->dialog, 0);

    /* Return: do not abort dialog */
    return 0;
}

Chooser *new_chooser (int lines, int cols, char *help, int flags)
{
    Chooser  *c;
    int      button_lines;

    c = (Chooser *) xmalloc (sizeof (Chooser), "new_chooser");
    c->dialog = create_dlg (0, 0, lines, cols, dialog_colors, common_dialog_callback,
			    help, "chooser", DLG_CENTER | DLG_GRID);

    c->dialog->lines = lines;
    c->dialog->cols  = cols;

    button_lines = flags & CHOOSE_EDITABLE ? 3 : 0;

    c->listbox = listbox_new (1, 1, cols-2, lines-button_lines,
			   listbox_finish, 0, "listbox");

    if (button_lines){
	add_widget (c->dialog, button_new (lines-button_lines+1,
				20, B_ENTER, DEFPUSH_BUTTON, _("&Remove"),
				remove_callback, c, "button-remove"));
	add_widget (c->dialog, button_new (lines-button_lines+1,
				    4, B_CANCEL, NORMAL_BUTTON, _("&Cancel"),
				    0, 0, "button-cancel"));
    }
    add_widget (c->dialog, c->listbox);
    return c;
}

int run_chooser (Chooser *c)
{
    run_dlg (c->dialog);
    return c->dialog->ret_value;
}

void destroy_chooser (Chooser *c)
{
    destroy_dlg (c->dialog);
}

/* }}} */

/* {{{ Quick dialog routines */

static int quick_callback (struct Dlg_head *h, int id, int Msg)
{
    switch (Msg){
#ifndef HAVE_X
    case DLG_DRAW:
	attrset (COLOR_NORMAL);
	dlg_erase (h);
	draw_box (h, 1, 1, h->lines-2, h->cols-2);

	attrset (COLOR_HOT_NORMAL);
	dlg_move (h, 1,((h->cols-strlen (h->data))/2));
	addstr (h->data);
	break;
#endif
    case DLG_KEY:
	if (id == '\n'){
	    h->ret_value = B_ENTER;
	    dlg_stop (h);
	    break;
	}
    }
    return 0;
}

#define I18N(x) (do_int && *x ? (x = _(x)): x)

int quick_dialog_skip (QuickDialog *qd, int nskip)
{
    Dlg_head *dd;
    void     *widget;
    WRadio   *r;
    int      xpos;
    int      ypos;
    int      return_val;
    WInput   *input;
    QuickWidget *qw;
    int      do_int;

    if (!qd->i18n){
	qd->i18n = 1;
	do_int = 1;
	if (*qd->title)
	    qd->title = _(qd->title);
    } else
	do_int = 0;

    if (qd->xpos == -1)
        dd = create_dlg (0, 0, qd->ylen, qd->xlen, dialog_colors, quick_callback,
		         qd->help, qd->class, DLG_CENTER | DLG_TRYUP | DLG_GRID);
    else
        dd = create_dlg (qd->ypos, qd->xpos, qd->ylen, qd->xlen, dialog_colors,
                         quick_callback,
		         qd->help, qd->class, DLG_GRID);

    x_set_dialog_title (dd, qd->title);

    /* We pass this to the callback */
    dd->cols  = qd->xlen;
    dd->lines = qd->ylen;
    dd->data  = qd->title;

    for (qw = qd->widgets; qw->widget_type; qw++){
#ifdef HAVE_X
	xpos = ypos = 0;
#else
	xpos = (qd->xlen * qw->relative_x)/qw->x_divisions;
	ypos = (qd->ylen * qw->relative_y)/qw->y_divisions;
#endif

	switch (qw->widget_type){
	case quick_checkbox:
	    widget = check_new (ypos, xpos, *qw->result, I18N (qw->text), qw->tkname);
	    break;

	case quick_radio:
	    r = radio_new (ypos, xpos, qw->hotkey_pos, qw->str_result, 1, qw->tkname);
	    r->pos = r->sel = qw->value;
	    widget = r;
	    break;

	case quick_button:
	    widget = button_new (ypos, xpos, qw->value, (qw->value==B_ENTER) ? DEFPUSH_BUTTON : NORMAL_BUTTON,
	    I18N (qw->text), 0, 0, qw->tkname);
	    break;

	    /* We use the hotkey pos as the field length */
	case quick_input:
	    input = input_new (ypos, xpos, INPUT_COLOR,
			       qw->hotkey_pos, qw->text, qw->tkname);
	    input->is_password = qw->value == 1;
	    input->point = 0;
	    if (qw->value & 2)
	        input->completion_flags |= INPUT_COMPLETE_CD;
	    widget = input;
	    break;

	case quick_label:
	    widget = label_new (ypos, xpos, I18N(qw->text), qw->tkname);
	    break;

	default:
	    widget = 0;
	    fprintf (stderr, "QuickWidget: unknown widget type\n");
	    break;
	}
	qw->the_widget = widget;
	add_widgetl (dd, widget, qw->layout);
    }

    while (nskip--)
	dd->current = dd->current->next;

    run_dlg (dd);

    /* Get the data if we found something interesting */
    if (dd->ret_value != B_CANCEL){
	for (qw = qd->widgets; qw->widget_type; qw++){
	    switch (qw->widget_type){
	    case quick_checkbox:
		*qw->result = ((WCheck *) qw->the_widget)->state & C_BOOL;
		break;

	    case quick_radio:
		*qw->result = ((WRadio *) qw->the_widget)->sel;
		break;

	    case quick_input:
		*qw->str_result = strdup (((WInput *) qw->the_widget)->buffer);
		break;
	    }
	}
    }
    return_val = dd->ret_value;
    destroy_dlg (dd);

    return return_val;
}

int quick_dialog (QuickDialog *qd)
{
    return quick_dialog_skip (qd, 0);
}

/* }}} */

/* {{{ Input routines */
#define INPUT_INDEX 2
char *real_input_dialog_help (char *header, char *text, char *help, char *def_text)
{
    QuickDialog Quick_input;
    QuickWidget quick_widgets [] = {
    { quick_button, 6, 10, 1, 0, N_("&Cancel"), 0, B_CANCEL, 0, 0,
	  XV_WLAY_RIGHTOF, "button-cancel" },
    { quick_button, 3, 10, 1, 0, N_("&Ok"), 0, B_ENTER, 0, 0,
	  XV_WLAY_CENTERROW, "button-ok" },
    { quick_input,  4, 80, 0, 0, "", 58, 0, 0, 0, XV_WLAY_NEXTROW, 0 },
    { quick_label,  3, 80, 2, 0, "", 0, 0, 0, 0, XV_WLAY_NEXTROW, "label" },
    { 0 } };

    int len;
    int i;
    int lines;
    char *my_str;
    char tk_name[64] = "inp|";

/* we need a unique name for tkname because widget.c:history_tool()
   needs a unique name for each dialog - using the header is ideal */

#ifdef HAVE_GNOME
    strncpy (tk_name + 4, header, 59);
#else
    strncpy (tk_name + 3, header, 60);
#endif
    tk_name[63] = '\0';
    quick_widgets[2].tkname = tk_name;

    len = max (strlen (header), msglen (text, &lines)) + 4;
    len = max (len, 64);

    if (strncmp (text, _("Password:"), strlen (_("Password"))) == 0){
	quick_widgets [INPUT_INDEX].value = 1;
	tk_name[3]=0;
    } else {
	quick_widgets [INPUT_INDEX].value = 0;
    }

#ifdef ENABLE_NLS
	/*
	 * An attempt to place buttons symmetrically, based on actual i18n
	 * length of the string. It looks nicer with i18n (IMO) - alex
	 */
	quick_widgets [0].relative_x = len/2 + 4;
	quick_widgets [1].relative_x =
		len/2 - (strlen (_(quick_widgets [1].text)) + 9);
	quick_widgets [0].x_divisions = quick_widgets [1].x_divisions = len;
#endif /* ENABLE_NLS */

    Quick_input.xlen  = len;
    Quick_input.xpos  = -1;
    Quick_input.title = header;
    Quick_input.help  = help;
    Quick_input.class = "quick_input";
    Quick_input.i18n  = 0;
    quick_widgets [INPUT_INDEX+1].text = text;
    quick_widgets [INPUT_INDEX].text = def_text;

    for (i = 0; i < 4; i++)
	quick_widgets [i].y_divisions = lines+6;
    Quick_input.ylen  = lines + 6;

    for (i = 0; i < 3; i++)
	quick_widgets [i].relative_y += 2 + lines;

    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;
}

char *input_dialog (char *header, char *text, char *def_text)
{
    return input_dialog_help (header, text, "[Input Line Keys]", def_text);
}

int input_dialog_help_2 (char *header, char *text1, char *text2, char *help, char **r1, char **r2)
{
    QuickDialog Quick_input;
    QuickWidget quick_widgets [] = {
    { quick_button, 6, 10, 4, 0, N_("&Cancel"), 0, B_CANCEL, 0, 0,
	  XV_WLAY_DONTCARE, "button-cancel" },
    { quick_button, 3, 10, 4, 0, N_("Ok")
, 0, B_ENTER, 0, 0,
	  XV_WLAY_DONTCARE, "button-ok" },
    { quick_input,  4, 80, 4, 0, "", 58, 0, 0, 0, XV_WLAY_BELOWCLOSE, "input-pth" },
    { quick_label,  3, 80, 3, 0, "", 0, 0, 0, 0, XV_WLAY_DONTCARE, "label-pth" },
    { quick_input,  4, 80, 3, 0, "", 58, 0, 0, 0, XV_WLAY_BELOWCLOSE, "input-lbl" },
    { quick_label,  3, 80, 2, 0, "", 0, 0, 0, 0, XV_WLAY_DONTCARE, "label-lbl" },
    { 0 } };

    int len;
    int i;
    int lines1, lines2;
    char *my_str1, *my_str2;

    len = max (strlen (header), msglen (text1, &lines1));
    len = max (len, msglen (text2, &lines2)) + 4;
    len = max (len, 64);

    Quick_input.xlen  = len;
    Quick_input.xpos  = -1;
    Quick_input.title = header;
    Quick_input.help  = help;
    Quick_input.class = "quick_input_2";
    Quick_input.i18n  = 0;
    quick_widgets [5].text = text1;
    quick_widgets [3].text = text2;

    for (i = 0; i < 6; i++)
	quick_widgets [i].y_divisions = lines1+lines2+7;
    Quick_input.ylen  = lines1 + lines2 + 7;

    quick_widgets [0].relative_y += (lines1 + lines2);
    quick_widgets [1].relative_y += (lines1 + lines2);
    quick_widgets [2].relative_y += (lines1);
    quick_widgets [3].relative_y += (lines1);

    quick_widgets [4].str_result = &my_str1;
    quick_widgets [2].str_result = &my_str2;

    Quick_input.widgets = quick_widgets;
    if (quick_dialog (&Quick_input) != B_CANCEL){
	 *r1 = *(quick_widgets [4].str_result);
	 *r2 = *(quick_widgets [2].str_result);
	 return 1;
    } else
	 return 0;
}

int input_dialog_2 (char *header, char *text1, char *text2, char **r1, char **r2)
{
    return input_dialog_help_2 (header, text1, text2,  "[Input Line Keys]", r1, r2);
}

char *input_expand_dialog (char *header, char *text, char *def_text)
{
    char *result;
    char *expanded;

    result = input_dialog (header, text, def_text);
    if (result){
	expanded = tilde_expand (result);
	if (expanded){
	    free (result);
	    return expanded;
	} else
	    return result;
    }
    return result;
}

/* }}} */

/* }}} */
/*
  Cause emacs to enter folding mode for this file:
  Local variables:
  end:
*/

⌨️ 快捷键说明

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