1 /* Bluefish HTML Editor
2  * html_form.c - html form dialogs
3  *
4  * Copyright (C) 1998 Olivier Sessink and Chris Mazuc
5  * Copyright (C) 1999-2011 Olivier Sessink
6  * Copyright (C) 2011 James Hayward
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 /* #define DEBUG */
23 #include <gtk/gtk.h>
24 
25 #include <string.h>
26 
27 #include "html_form.h"			/* myself */
28 #include "cap.h"
29 #include "html2.h"				/* style_but_new() */
30 #include "htmlbar.h"
31 #include "htmlbar_stock_icons.h"
32 #include "../dialog_utils.h"
33 #include "../document.h"		/* insert_dbl_text */
34 #include "../gtk_easy.h"		/* entry_with_text and stuff */
35 #include "../stringlist.h"		/* add to stringlist */
36 
37 /*************************************************/
38 /**********   PHP BUTTON FUNCTIONS   *************/
39 /*************************************************/
40 
41 #define PHPFORM_TYPE_TEXT 0
42 #define PHPFORM_TYPE_RADIO 1
43 #define PHPFORM_TYPE_CHECK 2
44 
45 static void
php_var_insert_cb(GtkWidget * widget,Thtml_diag * dg)46 php_var_insert_cb(GtkWidget * widget, Thtml_diag * dg)
47 {
48 	gchar *tmp;
49 	tmp = gtk_editable_get_chars(GTK_EDITABLE(dg->php_var_ins.name), 0, -1);
50 
51 	if (strlen(tmp)) {
52 		gchar *tmp2 = NULL;
53 		gchar *tmp3 = NULL;
54 		switch (dg->php_var_ins.type) {
55 		case PHPFORM_TYPE_TEXT:
56 			tmp2 = g_strdup_printf("<?php if (isset($_POST['%s'])) { echo $%s; } ?>", tmp, tmp);
57 			break;
58 		case PHPFORM_TYPE_RADIO:
59 			tmp3 = gtk_editable_get_chars(GTK_EDITABLE(dg->php_var_ins.val), 0, -1);
60 			if (strlen(tmp3)) {
61 				if (get_curlang_option_value(dg->bfwin, lang_is_XHTML)) {
62 					tmp2 =
63 						g_strdup_printf
64 						("<?php if ($_POST['%s']==\"%s\") { echo 'checked=\\\"checked\\\"'; } ?>", tmp, tmp3);
65 				} else {
66 					tmp2 =
67 						g_strdup_printf("<?php if ($_POST['%s']==\"%s\") { echo 'checked'; } ?>", tmp, tmp3);
68 				}
69 				g_free(tmp3);
70 			}
71 			break;
72 		case PHPFORM_TYPE_CHECK:
73 			if (get_curlang_option_value(dg->bfwin, lang_is_XHTML)) {
74 				tmp2 =
75 					g_strdup_printf("<?php if (isset($_POST['%s'])) { echo 'checked=\\\"checked\\\"'; } ?>",
76 									tmp);
77 			} else {
78 				tmp2 = g_strdup_printf("<?php if (isset($_POST['%s'])) { echo 'checked'; } ?>", tmp);
79 			}
80 			break;
81 		}
82 		if (tmp2) {
83 			gtk_entry_set_text(GTK_ENTRY(dg->php_var_ins.dest), tmp2);
84 			g_free(tmp2);
85 		}
86 	}
87 	g_free(tmp);
88 }
89 
90 GtkWidget *
php_var_but(Thtml_diag * dg,GtkWidget * name,GtkWidget * val)91 php_var_but(Thtml_diag * dg, GtkWidget * name, GtkWidget * val)
92 {
93 	GtkWidget *pixmap, *returnwid;
94 	dg->php_var_ins.name = name;
95 	dg->php_var_ins.val = val;
96 	returnwid = gtk_button_new();
97 	pixmap = gtk_image_new_from_stock(BF_STOCK_PHP3, GTK_ICON_SIZE_BUTTON);
98 	gtk_widget_show(pixmap);
99 	gtk_container_add(GTK_CONTAINER(returnwid), pixmap);
100 	g_signal_connect(returnwid, "clicked", G_CALLBACK(php_var_insert_cb), dg);
101 	gtk_widget_show(returnwid);
102 	return returnwid;
103 }
104 
105 
106 /************************************************************************/
107 /************************************************************************/
108 /****************                                  **********************/
109 /****************  BELOW ARE ALL DIALOGS MIGRATED  **********************/
110 /****************      TO HTML_DIAG FUNCTIONS      **********************/
111 /****************                                  **********************/
112 /************************************************************************/
113 /************************************************************************/
114 
115 static void
formok_lcb(GtkWidget * widget,Thtml_diag * dg)116 formok_lcb(GtkWidget * widget, Thtml_diag * dg)
117 {
118 	Tbfwin *bfwin = dg->bfwin;
119 	gchar *thestring, *finalstring;
120 
121 	thestring = g_strdup(cap("<FORM"));
122 	thestring = insert_string_if_combobox(GTK_COMBO_BOX(dg->combo[4]), cap("ACTION"), thestring, NULL);
123 	thestring = insert_string_if_combobox(GTK_COMBO_BOX(dg->combo[1]), cap("METHOD"), thestring, NULL);
124 	thestring = insert_string_if_combobox(GTK_COMBO_BOX(dg->combo[2]), cap("ENCTYPE"), thestring, NULL);
125 	thestring = insert_string_if_combobox(GTK_COMBO_BOX(dg->combo[3]), cap("TARGET"), thestring, NULL);
126 	thestring = insert_string_if_entry(GTK_ENTRY(dg->entry[2]), NULL, thestring, NULL);
127 	finalstring = g_strconcat(thestring, ">", NULL);
128 	g_free(thestring);
129 
130 	bfwin->session->targetlist =
131 		add_entry_to_stringlist(bfwin->session->targetlist,
132 								GTK_WIDGET(gtk_bin_get_child(GTK_BIN(dg->combo[3]))));
133 	if (dg->range.end == -1) {
134 		doc_insert_two_strings(dg->doc, finalstring, cap("</FORM>"));
135 	} else {
136 		doc_replace_text(dg->doc, finalstring, dg->range.pos, dg->range.end);
137 	}
138 
139 	g_free(finalstring);
140 	html_diag_destroy_cb(NULL, dg);
141 }
142 
143 
144 void
formdialog_dialog(Tbfwin * bfwin,Ttagpopup * data)145 formdialog_dialog(Tbfwin * bfwin, Ttagpopup * data)
146 {
147 	GList *methodlist = NULL;
148 	GList *enctypelist = NULL;
149 
150 	static gchar *tagitems[] = { "action", "method", "enctype", "target", NULL };
151 	gchar *tagvalues[5];
152 	gchar *custom = NULL;
153 	Thtml_diag *dg;
154 	GtkWidget *dgtable;
155 
156 	dg = html_diag_new(bfwin, _("Form"));
157 	fill_dialogvalues(tagitems, tagvalues, &custom, (Ttagpopup *) data, dg);
158 
159 	dgtable = html_diag_table_in_vbox(dg, 4, 10);
160 
161 	bfwin->session->urllist = add_to_stringlist(bfwin->session->urllist, "<?php echo $SCRIPT_NAME ?>");
162 	bfwin->session->urllist = add_to_stringlist(bfwin->session->urllist, "'.$SCRIPT_NAME.'");
163 	{
164 		GList *rel_link_list, *tmplist;
165 		rel_link_list = NULL /*generate_relative_doc_list() */ ;
166 		tmplist = duplicate_stringlist(bfwin->session->urllist, 1);
167 		rel_link_list = g_list_concat(tmplist, rel_link_list);
168 
169 		dg->combo[4] = html_diag_combobox_with_popdown(tagvalues[0], rel_link_list, 1);
170 
171 		free_stringlist(rel_link_list);
172 	}
173 
174 	dialog_mnemonic_label_in_table(_("_Action:"), dg->combo[4], dgtable, 0, 1, 0, 1);
175 	gtk_table_attach_defaults(GTK_TABLE(dgtable), dg->combo[4], 1, 8, 0, 1);
176 	gtk_table_attach_defaults(GTK_TABLE(dgtable),
177 							  file_but_new(GTK_WIDGET(gtk_bin_get_child(GTK_BIN(dg->combo[4]))), 0, bfwin), 8,
178 							  10, 0, 1);
179 
180 	methodlist = g_list_append(methodlist, cap("GET"));
181 	methodlist = g_list_append(methodlist, cap("POST"));
182 	dg->combo[1] = html_diag_combobox_with_popdown(tagvalues[1], methodlist, 1);
183 	g_list_free(methodlist);
184 	dialog_mnemonic_label_in_table(_("Metho_d:"), dg->combo[1], dgtable, 0, 1, 1, 2);
185 	gtk_table_attach_defaults(GTK_TABLE(dgtable), GTK_WIDGET(GTK_BIN(dg->combo[1])), 1, 2, 1, 2);
186 
187 	/* I need to add more types */
188 	enctypelist = g_list_append(enctypelist, "application/x-www-form-urlencoded");
189 	enctypelist = g_list_append(enctypelist, "multipart/form-data");
190 	enctypelist = g_list_append(enctypelist, "text/plain");
191 	dg->combo[2] = html_diag_combobox_with_popdown(tagvalues[2], enctypelist, 1);
192 	g_list_free(enctypelist);
193 	dialog_mnemonic_label_in_table(_("_Enctype:"), dg->combo[2], dgtable, 3, 4, 1, 2);
194 	gtk_table_attach_defaults(GTK_TABLE(dgtable), GTK_WIDGET(dg->combo[2]), 4, 10, 1, 2);
195 
196 	bfwin->session->targetlist = add_to_stringlist(bfwin->session->targetlist, "_top");
197 	bfwin->session->targetlist = add_to_stringlist(bfwin->session->targetlist, "_blank");
198 	bfwin->session->targetlist = add_to_stringlist(bfwin->session->targetlist, "_parent");
199 	dg->combo[3] = html_diag_combobox_with_popdown(tagvalues[3], bfwin->session->targetlist, 1);
200 	dialog_mnemonic_label_in_table(_("_Target:"), dg->combo[3], dgtable, 0, 1, 2, 3);
201 	gtk_table_attach_defaults(GTK_TABLE(dgtable), GTK_WIDGET(GTK_BIN(dg->combo[3])), 1, 10, 2, 3);
202 
203 	dg->entry[2] = dialog_entry_in_table(custom, dgtable, 1, 10, 3, 4);
204 	dialog_mnemonic_label_in_table(_("Custo_m:"), dg->entry[2], dgtable, 0, 1, 3, 4);
205 
206 	html_diag_finish(dg, G_CALLBACK(formok_lcb));
207 
208 	if (custom)
209 		g_free(custom);
210 
211 }
212 
213 static void
textareaok_lcb(GtkWidget * widget,Thtml_diag * dg)214 textareaok_lcb(GtkWidget * widget, Thtml_diag * dg)
215 {
216 	gchar *thestring, *finalstring;
217 
218 	thestring = g_strdup(cap("<TEXTAREA"));
219 	thestring = insert_string_if_entry((GTK_ENTRY(dg->entry[1])), cap("NAME"), thestring, NULL);
220 	thestring = insert_string_if_entry((GTK_ENTRY(dg->spin[1])), cap("ROWS"), thestring, NULL);
221 	thestring = insert_string_if_entry((GTK_ENTRY(dg->spin[2])), cap("COLS"), thestring, NULL);
222 	thestring = insert_string_if_entry((GTK_ENTRY(dg->entry[2])), NULL, thestring, NULL);
223 	finalstring = g_strconcat(thestring, ">", NULL);
224 	g_free(thestring);
225 
226 	if (dg->range.end == -1) {
227 		doc_insert_two_strings(dg->doc, finalstring, cap("</TEXTAREA>"));
228 	} else {
229 		doc_replace_text(dg->doc, finalstring, dg->range.pos, dg->range.end);
230 	}
231 
232 	g_free(finalstring);
233 	html_diag_destroy_cb(NULL, dg);
234 }
235 
236 void
textareadialog_dialog(Tbfwin * bfwin,Ttagpopup * data)237 textareadialog_dialog(Tbfwin * bfwin, Ttagpopup * data)
238 {
239 	static gchar *tagitems[] = { "name", "value", "rows", "cols", "readonly", NULL };
240 	gchar *tagvalues[6];
241 	gchar *custom = NULL;
242 	GtkWidget *dgtable;
243 	Thtml_diag *dg;
244 
245 	dg = html_diag_new(bfwin, _("Text area"));
246 	fill_dialogvalues(tagitems, tagvalues, &custom, (Ttagpopup *) data, dg);
247 
248 	dgtable = html_diag_table_in_vbox(dg, 4, 10);
249 
250 	dg->entry[1] = dialog_entry_in_table(tagvalues[0], dgtable, 1, 10, 0, 1);
251 	dialog_mnemonic_label_in_table(_("_Name:"), dg->entry[1], dgtable, 0, 1, 0, 1);
252 
253 	dg->spin[1] = spinbut_with_value(tagvalues[2], 0, 500, 1.0, 5.0);
254 	gtk_table_attach_defaults(GTK_TABLE(dgtable), dg->spin[1], 1, 2, 1, 2);
255 	dialog_mnemonic_label_in_table(_("_Rows:"), dg->spin[1], dgtable, 0, 1, 1, 2);
256 
257 	dg->spin[2] = spinbut_with_value(tagvalues[3], 0, 500, 1.0, 5.0);
258 	gtk_table_attach_defaults(GTK_TABLE(dgtable), dg->spin[2], 1, 2, 2, 3);
259 	dialog_mnemonic_label_in_table(_("Co_ls:"), dg->spin[2], dgtable, 0, 1, 2, 3);
260 
261 	/* dg->check[1] = gtk_check_button_new();
262 	   gtk_table_attach_defaults(GTK_TABLE(dgtable), dg->check[1], 1, 2, 3, 4);
263 	   bf_mnemonic_label_tad_with_alignment(_("Rea_d only:"), dg->check[1], 0, 0.5, dgtable, 0, 1, 3, 4);
264 	   parse_existence_for_dialog(tagvalues[4], dg->check[1]); */
265 
266 	dg->entry[2] = dialog_entry_in_table(custom, dgtable, 1, 10, 3, 4);
267 	dialog_mnemonic_label_in_table(_("Custo_m:"), dg->entry[2], dgtable, 0, 1, 3, 4);
268 
269 	html_diag_finish(dg, G_CALLBACK(textareaok_lcb));
270 
271 	if (custom)
272 		g_free(custom);
273 }
274 
275 static void
selectdialogok_lcb(GtkWidget * widget,Thtml_diag * dg)276 selectdialogok_lcb(GtkWidget * widget, Thtml_diag * dg)
277 {
278 	gchar *thestring, *finalstring;
279 
280 	thestring = g_strdup(cap("<SELECT"));
281 	thestring = insert_string_if_entry((GTK_ENTRY(dg->entry[1])), cap("NAME"), thestring, NULL);
282 	thestring = insert_string_if_entry((GTK_ENTRY(dg->spin[1])), cap("SIZE"), thestring, NULL);
283 	thestring =
284 		insert_attr_if_checkbox(dg->check[1],
285 								get_curlang_option_value(dg->bfwin, lang_is_XHTML) ? cap("MULTIPLE=\"multiple\"") : cap("MULTIPLE"),
286 								thestring);
287 	thestring = insert_string_if_entry((GTK_ENTRY(dg->entry[2])), NULL, thestring, NULL);
288 	finalstring = g_strconcat(thestring, ">", NULL);
289 	g_free(thestring);
290 
291 	if (dg->range.end == -1) {
292 		doc_insert_two_strings(dg->doc, finalstring, cap("</SELECT>"));
293 	} else {
294 		doc_replace_text(dg->doc, finalstring, dg->range.pos, dg->range.end);
295 	}
296 	g_free(finalstring);
297 	html_diag_destroy_cb(NULL, dg);
298 }
299 
300 void
selectdialog_dialog(Tbfwin * bfwin,Ttagpopup * data)301 selectdialog_dialog(Tbfwin * bfwin, Ttagpopup * data)
302 {
303 	static gchar *tagitems[] = { "name", "size", "multiple", NULL };
304 	gchar *tagvalues[4];
305 	gchar *custom = NULL;
306 	GtkWidget *dgtable;
307 	Thtml_diag *dg;
308 
309 	dg = html_diag_new(bfwin, _("Select"));
310 	fill_dialogvalues(tagitems, tagvalues, &custom, (Ttagpopup *) data, dg);
311 
312 	dgtable = html_diag_table_in_vbox(dg, 5, 10);
313 
314 	dg->entry[1] = dialog_entry_in_table(tagvalues[0], dgtable, 1, 10, 0, 1);
315 	dialog_mnemonic_label_in_table(_("_Name:"), dg->entry[1], dgtable, 0, 1, 0, 1);
316 
317 	dg->spin[1] = spinbut_with_value(tagvalues[1], 0, 1000, 1.0, 5.0);
318 	gtk_table_attach_defaults(GTK_TABLE(dgtable), dg->spin[1], 1, 2, 1, 2);
319 	dialog_mnemonic_label_in_table(_("Si_ze:"), dg->spin[1], dgtable, 0, 1, 1, 2);
320 
321 	dg->check[1] = gtk_check_button_new();
322 	gtk_table_attach_defaults(GTK_TABLE(dgtable), dg->check[1], 1, 2, 2, 3);
323 	dialog_mnemonic_label_in_table(_("Multiple _Selections:"), dg->check[1], dgtable, 0, 1, 2,
324 										 3);
325 	parse_existence_for_dialog(tagvalues[2], dg->check[1]);
326 
327 	dg->entry[2] = dialog_entry_in_table(custom, dgtable, 1, 10, 3, 4);
328 	dialog_mnemonic_label_in_table(_("Custo_m:"), dg->entry[2], dgtable, 0, 1, 3, 4);
329 
330 	html_diag_finish(dg, G_CALLBACK(selectdialogok_lcb));
331 
332 	if (custom)
333 		g_free(custom);
334 }
335 
336 static void
optiondialogok_lcb(GtkWidget * widget,Thtml_diag * dg)337 optiondialogok_lcb(GtkWidget * widget, Thtml_diag * dg)
338 {
339 	gchar *thestring, *finalstring;
340 
341 	thestring = g_strdup(cap("<OPTION"));
342 	thestring = insert_string_if_entry((GTK_ENTRY(dg->entry[1])), cap("VALUE"), thestring, NULL);
343 	thestring = insert_string_if_entry((GTK_ENTRY(dg->entry[2])), cap("LABEL"), thestring, NULL);
344 	thestring =
345 		insert_attr_if_checkbox(dg->check[1],
346 								get_curlang_option_value(dg->bfwin, lang_is_XHTML) ? cap("SELECTED=\"selected\"") : cap("SELECTED"),
347 								thestring);
348 	finalstring = g_strconcat(thestring, ">", NULL);
349 	g_free(thestring);
350 
351 	if (dg->range.end == -1) {
352 		doc_insert_two_strings(dg->doc, finalstring, cap("</OPTION>"));
353 	} else {
354 		doc_replace_text(dg->doc, finalstring, dg->range.pos, dg->range.end);
355 	}
356 	g_free(finalstring);
357 	html_diag_destroy_cb(NULL, dg);
358 }
359 
360 void
optiondialog_dialog(Tbfwin * bfwin,Ttagpopup * data)361 optiondialog_dialog(Tbfwin * bfwin, Ttagpopup * data)
362 {
363 	static gchar *tagitems[] = { "value", "label", "selected", NULL };
364 	gchar *tagvalues[4];
365 	gchar *custom = NULL;
366 	GtkWidget *dgtable;
367 	Thtml_diag *dg;
368 
369 	dg = html_diag_new(bfwin, _("Option"));
370 	fill_dialogvalues(tagitems, tagvalues, &custom, (Ttagpopup *) data, dg);
371 
372 	dgtable = html_diag_table_in_vbox(dg, 3, 10);
373 
374 	dg->entry[1] = dialog_entry_in_table(tagvalues[0], dgtable, 1, 10, 0, 1);
375 	dialog_mnemonic_label_in_table(_("_Value:"), dg->entry[1], dgtable, 0, 1, 0, 1);
376 
377 	dg->entry[2] = dialog_entry_in_table(tagvalues[2], dgtable, 1, 10, 1, 2);
378 	dialog_mnemonic_label_in_table(_("_Label:"), dg->entry[2], dgtable, 0, 1, 1, 2);
379 
380 	dg->check[1] = gtk_check_button_new();
381 	gtk_table_attach_defaults(GTK_TABLE(dgtable), dg->check[1], 1, 2, 2, 3);
382 	dialog_mnemonic_label_in_table(_("_Selected:"), dg->check[1], dgtable, 0, 1, 2, 3);
383 	parse_existence_for_dialog(tagvalues[2], dg->check[1]);
384 
385 	html_diag_finish(dg, G_CALLBACK(optiondialogok_lcb));
386 
387 	if (custom)
388 		g_free(custom);
389 }
390 
391 static void
optgroupdialogok_lcb(GtkWidget * widget,Thtml_diag * dg)392 optgroupdialogok_lcb(GtkWidget * widget, Thtml_diag * dg)
393 {
394 	gchar *thestring, *finalstring;
395 
396 	thestring = g_strdup(cap("<OPTGROUP"));
397 	thestring = insert_string_if_entry((GTK_ENTRY(dg->entry[1])), cap("LABEL"), thestring, NULL);
398 	finalstring = g_strconcat(thestring, ">", NULL);
399 	g_free(thestring);
400 
401 	if (dg->range.end == -1) {
402 		doc_insert_two_strings(dg->doc, finalstring, cap("</OPTGROUP>"));
403 	} else {
404 		doc_replace_text(dg->doc, finalstring, dg->range.pos, dg->range.end);
405 	}
406 	g_free(finalstring);
407 	html_diag_destroy_cb(NULL, dg);
408 }
409 
410 void
optgroupdialog_dialog(Tbfwin * bfwin,Ttagpopup * data)411 optgroupdialog_dialog(Tbfwin * bfwin, Ttagpopup * data)
412 {
413 	static gchar *tagitems[] = { "label", NULL };
414 	gchar *tagvalues[2];
415 	gchar *custom = NULL;
416 	GtkWidget *dgtable;
417 	Thtml_diag *dg;
418 
419 	dg = html_diag_new(bfwin, _("Option group"));
420 	fill_dialogvalues(tagitems, tagvalues, &custom, (Ttagpopup *) data, dg);
421 
422 	dgtable = html_diag_table_in_vbox(dg, 5, 10);
423 	dg->entry[1] = dialog_entry_in_table(tagvalues[0], dgtable, 1, 10, 0, 1);
424 	dialog_mnemonic_label_in_table(_("_Label:"), dg->entry[1], dgtable, 0, 1, 0, 1);
425 
426 	html_diag_finish(dg, G_CALLBACK(optgroupdialogok_lcb));
427 
428 	if (custom)
429 		g_free(custom);
430 }
431 
432 static void
inputdialogok_lcb(GtkWidget * widget,Thtml_diag * dg)433 inputdialogok_lcb(GtkWidget * widget, Thtml_diag * dg)
434 {
435 	gchar *thestring, *finalstring, *text;
436 	text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(dg->combo[0]));
437 	thestring = g_strdup(cap("<INPUT"));
438 	thestring = insert_string_if_string(text, cap("TYPE"), thestring, NULL);
439 	thestring = insert_string_if_entry(GTK_ENTRY(dg->entry[0]), cap("NAME"), thestring, NULL);
440 	thestring = insert_string_if_entry(GTK_ENTRY(dg->entry[1]), cap("VALUE"), thestring, NULL);
441 	if (strcmp(text, "radio") == 0 || strcmp(text, "checkbox") == 0) {
442 		thestring =
443 			insert_attr_if_checkbox(dg->check[0],
444 									get_curlang_option_value(dg->bfwin, lang_is_XHTML) ? cap("CHECKED=\"checked\"") : cap("CHECKED"),
445 									thestring);
446 	}
447 	if (strcmp(text, "hidden") != 0) {
448 		thestring = insert_integer_if_spin(dg->spin[0], cap("SIZE"), thestring, FALSE, 0);
449 	}
450 	if (strcmp(text, "text") == 0 || strcmp(text, "passwd") == 0) {
451 		thestring = insert_integer_if_spin(dg->spin[1], cap("MAXLENGTH"), thestring, FALSE, 0);
452 	}
453 	if (strcmp(text, "file") == 0) {
454 		thestring = insert_string_if_entry(GTK_ENTRY(dg->entry[2]), cap("ACCEPT"), thestring, NULL);
455 	}
456 	thestring = insert_string_if_combobox(GTK_COMBO_BOX(dg->attrwidget[0]), cap("CLASS"), thestring, NULL);
457 	thestring = insert_string_if_entry(GTK_ENTRY(dg->attrwidget[1]), cap("ID"), thestring, NULL);
458 	thestring = insert_string_if_entry(GTK_ENTRY(dg->attrwidget[2]), cap("STYLE"), thestring, NULL);
459 	thestring = insert_string_if_entry(GTK_ENTRY(dg->entry[3]), cap("ONFOCUS"), thestring, NULL);
460 	thestring = insert_string_if_entry(GTK_ENTRY(dg->entry[4]), cap("ONBLUR"), thestring, NULL);
461 	thestring = insert_string_if_entry(GTK_ENTRY(dg->entry[5]), cap("ONSELECT"), thestring, NULL);
462 	thestring = insert_string_if_entry(GTK_ENTRY(dg->entry[6]), cap("ONCHANGE"), thestring, NULL);
463 	thestring = insert_string_if_entry(GTK_ENTRY(dg->entry[7]), NULL, thestring, NULL);
464 	finalstring = g_strconcat(thestring, get_curlang_option_value(dg->bfwin, self_close_singleton_tags) ? " />" : ">", NULL);
465 	g_free(thestring);
466 	g_free(text);
467 	if (dg->range.end == -1) {
468 		doc_insert_two_strings(dg->doc, finalstring, NULL);
469 	} else {
470 		doc_replace_text(dg->doc, finalstring, dg->range.pos, dg->range.end);
471 	}
472 	g_free(finalstring);
473 	html_diag_destroy_cb(NULL, dg);
474 }
475 
476 static void
inputdialog_typecombo_activate_lcb(GtkWidget * widget,Thtml_diag * dg)477 inputdialog_typecombo_activate_lcb(GtkWidget * widget, Thtml_diag * dg)
478 {
479 	/* hmm this function should check if the window is being destroyed... */
480 	if (!dg->tobedestroyed) {
481 		const gchar *text;
482 		text = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(dg->combo[0]));
483 		DEBUG_MSG("inputdialog_typecombo_activate_lcb, text=%s\n", text);
484 		gtk_widget_set_sensitive(dg->check[0], (strcmp(text, "radio") == 0 || strcmp(text, "checkbox") == 0));
485 		gtk_widget_set_sensitive(dg->spin[0], (strcmp(text, "hidden") != 0));
486 		gtk_widget_set_sensitive(dg->spin[1], (strcmp(text, "text") == 0 || strcmp(text, "passwd") == 0));
487 		gtk_widget_set_sensitive(dg->entry[2], (strcmp(text, "file") == 0));
488 		gtk_widget_set_sensitive(dg->phpbutton, (strcmp(text, "radio") == 0 || strcmp(text, "checkbox") == 0)
489 								 || (strcmp(text, "text") == 0));
490 		if (strcmp(text, "text") == 0) {
491 			dg->php_var_ins.dest = dg->entry[1];
492 			dg->php_var_ins.type = PHPFORM_TYPE_TEXT;
493 		} else if (strcmp(text, "radio") == 0) {
494 			dg->php_var_ins.dest = dg->entry[7];
495 			dg->php_var_ins.type = PHPFORM_TYPE_RADIO;
496 		} else if (strcmp(text, "checkbox") == 0) {
497 			dg->php_var_ins.dest = dg->entry[7];
498 			dg->php_var_ins.type = PHPFORM_TYPE_CHECK;
499 		}
500 	}
501 }
502 
503 void
inputdialog_dialog(Tbfwin * bfwin,Ttagpopup * data,const gchar * type)504 inputdialog_dialog(Tbfwin * bfwin, Ttagpopup * data, const gchar * type)
505 {
506 	static gchar *tagitems[] =
507 		{ "type", "name", "value", "checked", "size", "maxlength", "accept", "onfocus", "onblur", "onselect",
508 		"onchange", "class", "id", "style", NULL
509 	};
510 	gchar *tagvalues[15];
511 	gchar *custom = NULL;
512 	Thtml_diag *dg;
513 	GtkWidget *noteb, *dgtable;
514 
515 	dg = html_diag_new(bfwin, _("Input"));
516 	fill_dialogvalues(tagitems, tagvalues, &custom, (Ttagpopup *) data, dg);
517 	noteb = gtk_notebook_new();
518 	gtk_box_pack_start(GTK_BOX(dg->vbox), noteb, FALSE, FALSE, 0);
519 
520 	dgtable = generic_table_inside_notebookframe(noteb, _("Attributes"), 10, 3);
521 
522 	{
523 		GList *poplist;
524 		const gchar *type2 = (type) ? type : "text";
525 		poplist =
526 			list_from_arglist(FALSE, "hidden", "text", "search", "tel", "url", "email", "password", "datetime",
527 				"date", "month", "week", "time", "datetime-local", "number", "range", "color", "checkbox", "radio",
528 				"file", "submit", "image", "reset", "button" , NULL);
529 		dg->combo[0] = html_diag_combobox_with_popdown(tagvalues[0] ? tagvalues[0] : type2, poplist, 0);
530 		g_list_free(poplist);
531 	}
532 	dialog_mnemonic_label_in_table(_("_Type:"), dg->combo[0], dgtable, 0, 1, 0, 1);
533 	gtk_table_attach_defaults(GTK_TABLE(dgtable), GTK_WIDGET(GTK_BIN(dg->combo[0])), 1, 3, 0, 1);
534 
535 	g_signal_connect(G_OBJECT(dg->combo[0]), "changed", G_CALLBACK(inputdialog_typecombo_activate_lcb), dg);
536 
537 	dg->entry[0] = dialog_entry_in_table(tagvalues[1], dgtable, 1, 3, 1, 2);
538 	dialog_mnemonic_label_in_table(_("_Name:"), dg->entry[0], dgtable, 0, 1, 1, 2);
539 
540 	dg->entry[1] = dialog_entry_in_table(tagvalues[2], dgtable, 1, 3, 2, 3);
541 	dialog_mnemonic_label_in_table(_("_Value:"), dg->entry[1], dgtable, 0, 1, 2, 3);
542 
543 	dg->check[0] = gtk_check_button_new();
544 	dialog_mnemonic_label_in_table(_("_Checked:"), dg->check[0], dgtable, 0, 1, 3, 4);
545 	gtk_table_attach_defaults(GTK_TABLE(dgtable), dg->check[0], 1, 3, 3, 4);
546 	parse_existence_for_dialog(tagvalues[3], dg->check[0]);
547 
548 	dg->spin[0] = spinbut_with_value(tagvalues[4], 0, 1000, 1.0, 5.0);
549 	dialog_mnemonic_label_in_table(_("Si_ze:"), dg->spin[0], dgtable, 0, 1, 4, 5);
550 	gtk_table_attach_defaults(GTK_TABLE(dgtable), dg->spin[0], 1, 2, 4, 5);
551 
552 	dg->spin[1] = spinbut_with_value(tagvalues[5], 0, 10000, 1.0, 5.0);
553 	dialog_mnemonic_label_in_table(_("Max _Length:"), dg->spin[1], dgtable, 0, 1, 5, 6);
554 	gtk_table_attach_defaults(GTK_TABLE(dgtable), dg->spin[1], 1, 2, 5, 6);
555 
556 	dg->entry[2] = dialog_entry_in_table(tagvalues[6], dgtable, 1, 3, 6, 7);
557 	dialog_mnemonic_label_in_table(_("_Accept:"), dg->entry[2], dgtable, 0, 1, 6, 7);
558 
559 	dg->entry[7] = dialog_entry_in_table(custom, dgtable, 1, 2, 7, 8);
560 	dialog_mnemonic_label_in_table(_("C_ustom:"), dg->entry[7], dgtable, 0, 1, 7, 8);
561 
562 	dg->phpbutton = php_var_but(dg, dg->entry[0], dg->entry[1]);
563 	gtk_table_attach_defaults(GTK_TABLE(dgtable), dg->phpbutton, 2, 3, 7, 8);
564 
565 	dgtable = generic_table_inside_notebookframe(noteb, _("Style"), 4, 3);
566 
567 	generic_class_id_style_section(dg, 0, dgtable, 0, tagvalues, 11);
568 
569 	dgtable = generic_table_inside_notebookframe(noteb, _("Events"), 10, 5);
570 
571 	dg->entry[3] = dialog_entry_in_table(tagvalues[7], dgtable, 1, 3, 0, 1);
572 	dialog_mnemonic_label_in_table(_("On_Focus:"), dg->entry[3], dgtable, 0, 1, 0, 1);
573 
574 	dg->entry[4] = dialog_entry_in_table(tagvalues[8], dgtable, 1, 3, 1, 2);
575 	dialog_mnemonic_label_in_table(_("On_Blur:"), dg->entry[4], dgtable, 0, 1, 1, 2);
576 
577 	dg->entry[5] = dialog_entry_in_table(tagvalues[9], dgtable, 1, 3, 2, 3);
578 	dialog_mnemonic_label_in_table(_("On_Select:"), dg->entry[5], dgtable, 0, 1, 2, 3);
579 
580 	dg->entry[6] = dialog_entry_in_table(tagvalues[10], dgtable, 1, 3, 3, 4);
581 	dialog_mnemonic_label_in_table(_("On_Change:"), dg->entry[6], dgtable, 0, 1, 3, 4);
582 
583 	inputdialog_typecombo_activate_lcb(NULL, dg);
584 	html_diag_finish(dg, G_CALLBACK(inputdialogok_lcb));
585 	if (custom)
586 		g_free(custom);
587 }
588 
589 void
inputdialog_rpopup(Tbfwin * bfwin,Ttagpopup * data)590 inputdialog_rpopup(Tbfwin * bfwin, Ttagpopup * data)
591 {
592 	inputdialog_dialog(bfwin, data, NULL);
593 }
594 
595 static void
buttondialogok_lcb(GtkWidget * widget,Thtml_diag * dg)596 buttondialogok_lcb(GtkWidget * widget, Thtml_diag * dg)
597 {
598 	gchar *thestring, *finalstring;
599 
600 	thestring = g_strdup(cap("<BUTTON"));
601 	thestring = insert_string_if_entry((GTK_ENTRY(dg->entry[1])), cap("NAME"), thestring, NULL);
602 	thestring = insert_string_if_entry((GTK_ENTRY(dg->entry[2])), cap("VALUE"), thestring, NULL);
603 	thestring = insert_string_if_combobox(GTK_COMBO_BOX(dg->combo[1]), cap("TYPE"), thestring, NULL);
604 	thestring = insert_string_if_entry((GTK_ENTRY(dg->entry[3])), NULL, thestring, NULL);
605 	finalstring = g_strconcat(thestring, ">", NULL);
606 	g_free(thestring);
607 
608 	if (dg->range.end == -1) {
609 		doc_insert_two_strings(dg->doc, finalstring, cap("</BUTTON>"));
610 	} else {
611 		doc_replace_text(dg->doc, finalstring, dg->range.pos, dg->range.end);
612 	}
613 	g_free(finalstring);
614 	html_diag_destroy_cb(NULL, dg);
615 }
616 
617 void
buttondialog_dialog(Tbfwin * bfwin,Ttagpopup * data)618 buttondialog_dialog(Tbfwin * bfwin, Ttagpopup * data)
619 {
620 	static gchar *tagitems[] = { "name", "value", "type", NULL };
621 	gchar *tagvalues[4];
622 	gchar *custom = NULL;
623 	GtkWidget *dgtable;
624 	Thtml_diag *dg;
625 	GList *tmplist = NULL;
626 
627 	dg = html_diag_new(bfwin, _("Button"));
628 	fill_dialogvalues(tagitems, tagvalues, &custom, (Ttagpopup *) data, dg);
629 
630 	dgtable = html_diag_table_in_vbox(dg, 5, 10);
631 
632 	dg->entry[1] = dialog_entry_in_table(tagvalues[0], dgtable, 1, 10, 0, 1);
633 	dialog_mnemonic_label_in_table(_("_Name:"), dg->entry[1], dgtable, 0, 1, 0, 1);
634 
635 	dg->entry[2] = dialog_entry_in_table(tagvalues[1], dgtable, 1, 9, 1, 2);
636 	dialog_mnemonic_label_in_table(_("_Value:"), dg->entry[2], dgtable, 0, 1, 1, 2);
637 
638 	tmplist = list_from_arglist(FALSE, "", "submit", "reset", "button", NULL);
639 	dg->combo[1] = html_diag_combobox_with_popdown(tagvalues[2], tmplist, 0);
640 	g_list_free(tmplist);
641 	dialog_mnemonic_label_in_table(_("_Type:"), dg->combo[1], dgtable, 0, 1, 2, 3);
642 	gtk_table_attach_defaults(GTK_TABLE(dgtable), GTK_WIDGET(dg->combo[1]), 1, 9, 2, 3);
643 
644 	dg->entry[3] = dialog_entry_in_table(custom, dgtable, 1, 9, 3, 4);
645 	dialog_mnemonic_label_in_table(_("Custo_m:"), dg->entry[3], dgtable, 0, 1, 3, 4);
646 
647 	html_diag_finish(dg, G_CALLBACK(buttondialogok_lcb));
648 	if (custom)
649 		g_free(custom);
650 }
651