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)
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 ***********************************************************************/
15 #include <fc_config.h>
21 #include <X11/Intrinsic.h>
22 #include <X11/StringDefs.h>
23 #include <X11/Xaw/Form.h>
24 #include <X11/Xaw/Label.h>
25 #include <X11/Xaw/Command.h>
26 #include <X11/Xaw/SimpleMenu.h>
27 #include <X11/Xaw/Scrollbar.h>
28 #include <X11/Xaw/Toggle.h>
29 #include <X11/Xaw/Viewport.h>
40 #include "gui_stuff.h"
42 #include "optiondlg.h"
45 #include "messagedlg.h"
47 /*************************************************************************/
48 Widget
create_messageopt_dialog(void);
49 void messageopt_ok_command_callback(Widget w
, XtPointer client_data
,
51 void messageopt_cancel_command_callback(Widget w
, XtPointer client_data
,
53 static Widget messageopt_toggles
[E_COUNT
][NUM_MW
];
55 /**************************************************************************
57 **************************************************************************/
58 void popup_messageopt_dialog(void)
63 shell
=create_messageopt_dialog();
65 /* Doing this here makes the "No"'s centered consistently */
66 for(i
= 0; i
<= event_type_max(); i
++) {
67 for(j
=0; j
<NUM_MW
; j
++) {
68 state
= messages_where
[i
] & (1<<j
);
69 XtVaSetValues(messageopt_toggles
[i
][j
],
71 XtNlabel
, state
? _("Yes") : _("No"), NULL
);
75 xaw_set_relative_position(toplevel
, shell
, 15, 0);
76 XtPopup(shell
, XtGrabNone
);
77 XtSetSensitive(main_form
, FALSE
);
80 /**************************************************************************
82 **************************************************************************/
83 Widget
create_messageopt_dialog(void)
85 Widget shell
, form
, title
, scrolled
, explanation
, ok
, cancel
, col
;
86 Widget colhead
, space_head
;
87 Widget label
[E_COUNT
];
88 Widget longest_label
= 0;
90 int i
, longest_len
= 0;
93 shell
= I_T(XtCreatePopupShell("messageoptpopup", transientShellWidgetClass
,
96 form
= XtVaCreateManagedWidget("messageoptform", formWidgetClass
,
99 title
= I_L(XtVaCreateManagedWidget("messageopttitle", labelWidgetClass
,
102 explanation
= I_L(XtVaCreateManagedWidget("messageoptexpl", labelWidgetClass
,
105 scrolled
= XtVaCreateManagedWidget("messageoptscroll", viewportWidgetClass
,
108 col
= XtVaCreateManagedWidget("messageoptcol", formWidgetClass
,
111 /* space_head labels are "empty" labels in column heading which are
112 * used so that we can arrange the constraints without loops.
113 * They essentially act as vertical filler.
115 space_head
= XtVaCreateManagedWidget("messageoptspacehead", labelWidgetClass
,
118 colhead
= I_L(XtVaCreateManagedWidget("messageoptcolhead", labelWidgetClass
,
121 for(i
= 0; i
<= event_type_max(); i
++) {
122 const char *text
= get_event_message_text(sorted_events
[i
]);
123 int len
= strlen(text
);
125 label
[i
] = XtVaCreateManagedWidget("label", labelWidgetClass
, col
,
126 XtNlabel
, text
, XtNfromVert
,
127 (i
== 0) ? space_head
: label
[i
- 1],
130 if (len
> longest_len
) {
132 longest_label
= label
[i
];
136 * The addition of a scrollbar screws things up. There must be a
137 * better way to do this.
139 XtVaGetValues(label
[i
], XtNwidth
, &width
, NULL
);
140 XtVaSetValues(label
[i
], XtNwidth
, width
+ 15, NULL
);
143 XtVaGetValues(longest_label
, XtNwidth
, &width
, NULL
);
144 XtVaSetValues(space_head
, XtNwidth
, width
+ 15, NULL
);
145 XtVaSetValues(colhead
, XtNfromHoriz
, space_head
, NULL
);
147 for (i
= 0; i
<= event_type_max(); i
++) {
150 for (j
= 0; j
< NUM_MW
; j
++) {
151 toggle
= XtVaCreateManagedWidget("toggle", toggleWidgetClass
, col
,
153 (j
== 0 ? space_head
: toggle
),
155 (i
== 0) ? space_head
: label
[i
- 1],
157 XtAddCallback(toggle
, XtNcallback
, toggle_callback
, NULL
);
158 messageopt_toggles
[sorted_events
[i
]][j
] = toggle
;
162 ok
= I_L(XtVaCreateManagedWidget("messageoptokcommand",
166 cancel
= I_L(XtVaCreateManagedWidget("messageoptcancelcommand",
170 XtAddCallback(ok
, XtNcallback
, messageopt_ok_command_callback
,
172 XtAddCallback(cancel
, XtNcallback
, messageopt_cancel_command_callback
,
175 XtRealizeWidget(shell
);
177 xaw_horiz_center(title
);
178 xaw_horiz_center(explanation
);
183 /**************************************************************************
185 **************************************************************************/
186 void messageopt_cancel_command_callback(Widget w
, XtPointer client_data
,
189 XtSetSensitive(main_form
, TRUE
);
190 XtDestroyWidget((Widget
)client_data
);
193 /**************************************************************************
195 **************************************************************************/
196 void messageopt_ok_command_callback(Widget w
, XtPointer client_data
,
202 XtSetSensitive(main_form
, TRUE
);
204 for(i
= 0; i
<= event_type_max(); i
++) {
205 messages_where
[i
] = 0;
206 for(j
=0; j
<NUM_MW
; j
++) {
207 XtVaGetValues(messageopt_toggles
[i
][j
], XtNstate
, &b
, NULL
);
208 if (b
) messages_where
[i
] |= (1<<j
);
212 XtDestroyWidget((Widget
)client_data
);