void label_set_text (WLabel * label, const char *text) { int newcols = label->widget.cols; int newlines; if (label->text != NULL && text != NULL && strcmp (label->text, text) == 0) return; /* Flickering is not nice */ g_free (label->text); if (text == NULL) label->text = NULL; else { label->text = g_strdup (text); if (label->auto_adjust_cols) { str_msg_term_size (text, &newlines, &newcols); if (newcols > label->widget.cols) label->widget.cols = newcols; if (newlines > label->widget.lines) label->widget.lines = newlines; } } if (label->widget.owner != NULL) label_callback ((Widget *) label, WIDGET_DRAW, 0); if (newcols < label->widget.cols) label->widget.cols = newcols; }
static void edit_about (void) { const char *header = N_("About"); const char *button_name = N_("&OK"); const char *const version = "MCEdit " VERSION; char text[BUF_LARGE]; int win_len, version_len, button_len; int cols, lines; Dlg_head *about_dlg; #ifdef ENABLE_NLS header = _(header); button_name = _(button_name); #endif button_len = str_term_width1 (button_name) + 5; version_len = str_term_width1 (version); g_snprintf (text, sizeof (text), _("Copyright (C) 1996-2012 the Free Software Foundation\n\n" " A user friendly text editor\n" " written for the Midnight Commander")); win_len = str_term_width1 (header); win_len = max (win_len, version_len); win_len = max (win_len, button_len); /* count width and height of text */ str_msg_term_size (text, &lines, &cols); lines += 9; cols = max (win_len, cols) + 6; /* dialog */ about_dlg = create_dlg (TRUE, 0, 0, lines, cols, dialog_colors, NULL, NULL, "[Internal File Editor]", header, DLG_CENTER | DLG_TRYUP); add_widget (about_dlg, label_new (3, (cols - version_len) / 2, version)); add_widget (about_dlg, label_new (5, 3, text)); add_widget (about_dlg, button_new (lines - 3, (cols - button_len) / 2, B_ENTER, NORMAL_BUTTON, button_name, NULL)); run_dlg (about_dlg); destroy_dlg (about_dlg); }
WLabel * label_new (int y, int x, const char *text) { WLabel *l; int cols = 1; int lines = 1; if (text != NULL) str_msg_term_size (text, &lines, &cols); l = g_new (WLabel, 1); init_widget (&l->widget, y, x, lines, cols, label_callback, NULL); l->text = g_strdup (text); l->auto_adjust_cols = TRUE; l->transparent = FALSE; widget_want_cursor (l->widget, FALSE); widget_want_hotkey (l->widget, FALSE); return l; }
/** * Show dialog, not background safe. * * If the arguments "header" and "text" should be translated, * that MUST be done by the caller of fg_input_dialog_help(). * * The argument "history_name" holds the name of a section * in the history file. Data entered in the input field of * the dialog box will be stored there. * */ static char * fg_input_dialog_help (const char *header, const char *text, const char *help, const char *history_name, const char *def_text, gboolean strip_password) { char *my_str; int flags = (strip_password) ? 4 : 0; QuickWidget quick_widgets[] = { /* 0 */ QUICK_BUTTON (6, 64, 1, 0, N_("&Cancel"), B_CANCEL, NULL), /* 1 */ QUICK_BUTTON (3, 64, 1, 0, N_("&OK"), B_ENTER, NULL), /* 2 */ QUICK_INPUT (3, 64, 0, 0, def_text, 58, flags, NULL, &my_str), /* 3 */ QUICK_LABEL (3, 64, 2, 0, ""), QUICK_END }; int b0_len, b1_len, b_len, gap; char histname[64] = "inp|"; int lines, cols; int len; int i; char *p_text; int ret; /* buttons */ #ifdef ENABLE_NLS quick_widgets[0].u.button.text = _(quick_widgets[0].u.button.text); quick_widgets[1].u.button.text = _(quick_widgets[1].u.button.text); #endif /* ENABLE_NLS */ b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3; b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 5; /* default button */ b_len = b0_len + b1_len + 2; /* including gap */ /* input line */ if (history_name != NULL && *history_name != '\0') { g_strlcpy (histname + 3, history_name, sizeof (histname) - 3); quick_widgets[2].u.input.histname = histname; } /* The special value of def_text is used to identify password boxes and hide characters with "*". Don't save passwords in history! */ if (def_text == INPUT_PASSWORD) { quick_widgets[2].u.input.flags = 1; histname[3] = '\0'; quick_widgets[2].u.input.text = ""; } /* text */ p_text = g_strstrip (g_strdup (text)); str_msg_term_size (p_text, &lines, &cols); quick_widgets[3].u.label.text = p_text; /* dialog width */ len = str_term_width1 (header); len = max (max (len, cols) + 4, 64); len = min (max (len, b_len + 6), COLS); /* button locations */ gap = (len - 8 - b_len) / 3; quick_widgets[1].relative_x = 3 + gap; quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + gap + 2; { QuickDialog Quick_input = { len, lines + 6, -1, -1, header, help, quick_widgets, NULL, TRUE }; for (i = 0; i < 4; i++) { quick_widgets[i].x_divisions = Quick_input.xlen; quick_widgets[i].y_divisions = Quick_input.ylen; } for (i = 0; i < 3; i++) quick_widgets[i].relative_y += 2 + lines; /* input line length */ quick_widgets[2].u.input.len = Quick_input.xlen - 6; ret = quick_dialog (&Quick_input); } g_free (p_text); return (ret != B_CANCEL) ? my_str : NULL; }