1 /**********************************************************************
2  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License as published by
5    the Free Software Foundation; either version 2, or (at your option)
6    any later version.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 ***********************************************************************/
13 
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
17 
18 #include <stdio.h>
19 
20 #include <X11/Intrinsic.h>
21 #include <X11/StringDefs.h>
22 #include <X11/Xaw/Form.h>
23 #include <X11/Xaw/Label.h>
24 #include <X11/Xaw/SimpleMenu.h>
25 #include <X11/Xaw/Command.h>
26 #include <X11/Xaw/AsciiText.h>
27 
28 #include "fcintl.h"
29 
30 #include "gui_stuff.h"
31 
32 #include "inputdlg.h"
33 
34 /****************************************************************
35 ...
36 *****************************************************************/
input_dialog_get_input(Widget button)37 char *input_dialog_get_input(Widget button)
38 {
39   XtPointer dp;
40   Widget winput;
41 
42   winput=XtNameToWidget(XtParent(button), "iinput");
43 
44   XtVaGetValues(winput, XtNstring, &dp, NULL);
45 
46   return dp;
47 }
48 
49 
50 /****************************************************************
51 ...
52 *****************************************************************/
input_dialog_destroy(Widget button)53 void input_dialog_destroy(Widget button)
54 {
55   XtSetSensitive(XtParent(XtParent(XtParent(button))), TRUE);
56 
57   XtDestroyWidget(XtParent(XtParent(button)));
58 }
59 
60 /****************************************************************
61 ...
62 *****************************************************************/
inputdlg_key_ok(Widget w)63 void inputdlg_key_ok(Widget w)
64 {
65   x_simulate_button_click(XtNameToWidget(XtParent(w), "iokcommand"));
66 }
67 
68 
69 /****************************************************************
70 ...
71 *****************************************************************/
input_dialog_create(Widget parent,const char * dialogname,const char * text,const char * postinputtest,XtCallbackProc ok_callback,XtPointer ok_cli_data,XtCallbackProc cancel_callback,XtPointer cancel_cli_data)72 Widget input_dialog_create(Widget parent, const char *dialogname,
73 			   const char *text, const char *postinputtest,
74 			   XtCallbackProc ok_callback,
75 			   XtPointer ok_cli_data,
76 			   XtCallbackProc cancel_callback,
77 			   XtPointer cancel_cli_data)
78 {
79   Widget shell, form, label, input, ok, cancel;
80 
81   XtSetSensitive(parent, FALSE);
82 
83   I_T(shell=XtCreatePopupShell(dialogname, transientShellWidgetClass,
84 			       parent, NULL, 0));
85 
86   form=XtVaCreateManagedWidget("iform", formWidgetClass, shell, NULL);
87 
88   /* Caller should i18n the text passed in as desired */
89   label=XtVaCreateManagedWidget("ilabel", labelWidgetClass, form,
90 				    XtNlabel, (XtArgVal)text, NULL);
91 
92   input=XtVaCreateManagedWidget("iinput",
93 				asciiTextWidgetClass,
94 				form,
95 				XtNfromVert, (XtArgVal)label,
96 				XtNeditType, XawtextEdit,
97 				XtNstring, postinputtest,
98 				NULL);
99 
100   ok=XtVaCreateManagedWidget("iokcommand",
101 			     commandWidgetClass,
102 			     form,
103 			     XtNlabel, (XtArgVal)_("Ok"),
104 			     XtNfromVert, input,
105 			     NULL);
106 
107   cancel=XtVaCreateManagedWidget("icancelcommand",
108 				 commandWidgetClass,
109 				 form,
110 				 XtNlabel, (XtArgVal)_("Cancel"),
111 				 XtNfromVert, input,
112 				 XtNfromHoriz, ok,
113 				 NULL);
114 
115   xaw_set_relative_position(parent, shell, 10, 10);
116   XtPopup(shell, XtGrabNone);
117 
118   XtAddCallback(ok, XtNcallback, ok_callback, ok_cli_data);
119   XtAddCallback(cancel, XtNcallback, cancel_callback,
120 		cancel_cli_data);
121 
122   XtSetKeyboardFocus(parent, input);
123 
124   return shell;
125 }
126