int messageBox(const char * text, int height, int width, int type, int flags) { newtComponent form, yes, tb, answer; newtComponent no = NULL; int tFlag = (flags & FLAG_SCROLL_TEXT) ? NEWT_FLAG_SCROLL : 0; form = newtForm(NULL, NULL, 0); tb = newtTextbox(1, 1, width - 2, height - 3 - buttonHeight, NEWT_FLAG_WRAP | tFlag); newtTextboxSetText(tb, text); newtFormAddComponent(form, tb); switch ( type ) { case MSGBOX_INFO: break; case MSGBOX_MSG: yes = makeButton((width - 8) / 2, height - 1 - buttonHeight, "Ok"); newtFormAddComponent(form, yes); break; default: yes = makeButton((width - 16) / 3, height - 1 - buttonHeight, "Yes"); no = makeButton(((width - 16) / 3) * 2 + 9, height - 1 - buttonHeight, "No"); newtFormAddComponents(form, yes, no, NULL); if (flags & FLAG_DEFAULT_NO) newtFormSetCurrent(form, no); } if ( type != MSGBOX_INFO ) { newtRunForm(form); answer = newtFormGetCurrent(form); if (answer == no) return DLG_CANCEL; } else { newtDrawForm(form); newtRefresh(); } return DLG_OKAY; }
static void nmt_newt_form_build (NmtNewtForm *form) { NmtNewtFormPrivate *priv = NMT_NEWT_FORM_GET_PRIVATE (form); int screen_height, screen_width, form_height, form_width; newtComponent *cos; int i; priv->dirty = FALSE; nmt_newt_widget_realize (NMT_NEWT_WIDGET (form)); nmt_newt_widget_size_request (priv->content, &form_width, &form_height); newtGetScreenSize (&screen_width, &screen_height); if (!priv->fixed_width) priv->width = MIN (form_width + 2 * priv->padding, screen_width - 2); if (!priv->fixed_height) priv->height = MIN (form_height + 2 * priv->padding, screen_height - 2); if (!priv->fixed_x) priv->x = (screen_width - form_width) / 2; if (!priv->fixed_y) priv->y = (screen_height - form_height) / 2; nmt_newt_widget_size_allocate (priv->content, priv->padding, priv->padding, priv->width - 2 * priv->padding, priv->height - 2 * priv->padding); if (priv->height - 2 * priv->padding < form_height) { newtComponent scroll_bar = newtVerticalScrollbar (priv->width - 1, 0, priv->height, NEWT_COLORSET_WINDOW, NEWT_COLORSET_ACTCHECKBOX); priv->form = newtForm (scroll_bar, NULL, NEWT_FLAG_NOF12); newtFormAddComponent (priv->form, scroll_bar); newtFormSetHeight (priv->form, priv->height - 2); } else priv->form = newtForm (NULL, NULL, NEWT_FLAG_NOF12); if (priv->escape_exits) newtFormAddHotKey (priv->form, NEWT_KEY_ESCAPE); cos = nmt_newt_widget_get_components (priv->content); for (i = 0; cos[i]; i++) newtFormAddComponent (priv->form, cos[i]); g_free (cos); if (priv->focus) { newtComponent fco; fco = nmt_newt_widget_get_focus_component (priv->focus); if (fco) newtFormSetCurrent (priv->form, fco); } #ifdef HAVE_NEWTFORMGETSCROLLPOSITION if (priv->scroll_position) newtFormSetScrollPosition (priv->form, priv->scroll_position); #endif newtOpenWindow (priv->x, priv->y, priv->width, priv->height, priv->title_lc); }
/* Small window to change IP and Netmask of some colour */ void changeaddress(char *colour, int *changed_flag) { newtComponent networkform; newtComponent text; newtComponent ok, cancel; struct newtExitStruct exitstruct; char keyvalue[STRING_SIZE]; char addresskey[STRING_SIZE]; char netmaskkey[STRING_SIZE]; char netaddresskey[STRING_SIZE]; newtComponent addresslabel; newtComponent netmasklabel; newtComponent addressentry; newtComponent netmaskentry; const char *addressresult; const char *netmaskresult; char message[STRING_SIZE_LARGE]; int error; int numLines; char *tmpstring; /* Build some key strings. */ sprintf(addresskey, "%s_1_ADDRESS", colour); sprintf(netmaskkey, "%s_1_NETMASK", colour); sprintf(netaddresskey, "%s_1_NETADDRESS", colour); /* workaround gcc warning, there is really 1 %s there */ tmpstring=strdup(gettext("TR_ENTER_THE_IP_ADDRESS_INFORMATION")); snprintf(message, STRING_SIZE, tmpstring, colour); free(tmpstring); text = newtTextboxReflowed(1, 1, message, 68, 0, 0, 0); numLines = newtTextboxGetNumLines(text); /* workaround gcc warning, there is really 1 %s there */ tmpstring=strdup(gettext("TR_INTERFACE")); snprintf(message, STRING_SIZE, tmpstring, colour); free(tmpstring); newtCenteredWindow(72, 10 + numLines, message); networkform = newtForm(NULL, NULL, 0); newtFormAddComponent(networkform, text); /* Address */ addresslabel = newtTextbox(2, 2 + numLines, 18, 1, 0); newtTextboxSetText(addresslabel, gettext("TR_IP_ADDRESS_PROMPT")); if (!strcmp(colour, "GREEN")) { /* green only for now */ strcpy(keyvalue, DEFAULT_IP); } else { strcpy(keyvalue, ""); } find_kv_default(eth_kv, addresskey, keyvalue); addressentry = newtEntry(20, 2 + numLines, keyvalue, 20, &addressresult, 0); newtEntrySetFilter(addressentry, filterip, NULL); newtFormAddComponent(networkform, addresslabel); newtFormAddComponent(networkform, addressentry); /* Netmask */ netmasklabel = newtTextbox(2, 3 + numLines, 18, 1, 0); newtTextboxSetText(netmasklabel, gettext("TR_NETMASK_PROMPT")); strcpy(keyvalue, DEFAULT_NETMASK); find_kv_default(eth_kv, netmaskkey, keyvalue); netmaskentry = newtEntry(20, 3 + numLines, keyvalue, 20, &netmaskresult, 0); newtEntrySetFilter(netmaskentry, filterip, NULL); newtFormAddComponent(networkform, netmasklabel); newtFormAddComponent(networkform, netmaskentry); ok = newtButton(6, 5 + numLines, gettext("TR_OK")); /* In case of installer we need a valid address, no turning back */ if (flag_is_state == setupchroot) { newtFormAddComponent(networkform, ok); } else { cancel = newtButton(26, 5 + numLines, gettext("TR_GO_BACK")); newtFormAddComponents(networkform, ok, cancel, NULL); } newtRefresh(); newtDrawForm(networkform); do { error = 0; newtFormRun(networkform, &exitstruct); if (exitstruct.u.co == ok) { strcpy(message, gettext("TR_INVALID_FIELDS")); if (VALID_IP(addressresult) == FALSE) { strcat(message, gettext("TR_IP_ADDRESS_CR")); error = 1; newtFormSetCurrent(networkform, addressentry); } if (VALID_IP(netmaskresult) == FALSE) { strcat(message, gettext("TR_NETWORK_MASK_CR")); error = 1; newtFormSetCurrent(networkform, netmaskentry); } // TODO: additional network mask validation if (error) { errorbox(message); } else { /* all is well, calc netaddress and store everything */ unsigned long int intaddress; unsigned long int intnetaddress; unsigned long int intnetmask; struct in_addr i_addr; char *netaddress; update_kv(ð_kv, addresskey, (char *) addressresult); update_kv(ð_kv, netmaskkey, (char *) netmaskresult); /* calculate netaddress */ intaddress = inet_addr(addressresult); intnetmask = inet_addr(netmaskresult); intnetaddress = intaddress & intnetmask; i_addr.s_addr = intnetaddress; netaddress = inet_ntoa(i_addr); update_kv(ð_kv, netaddresskey, (char *) netaddress); changed_config = 1; *changed_flag = 1; } } } while (error); newtFormDestroy(networkform); newtPopWindow(); }