Removed silencing of gtk warning logs from gtk3.22-client.
[freeciv.git] / client / gui-xaw / messagedlg.c
blob9fc7b7072c7c5d102349bdbf34e4fc9fddff6abf
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.
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 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 #include <stdio.h>
19 #include <stdlib.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>
31 #include "events.h"
32 #include "fcintl.h"
33 #include "game.h"
34 #include "packets.h"
35 #include "player.h"
36 #include "shared.h"
37 #include "support.h"
39 #include "gui_main.h"
40 #include "gui_stuff.h"
41 #include "mapview.h"
42 #include "optiondlg.h"
43 #include "options.h"
45 #include "messagedlg.h"
47 /*************************************************************************/
48 Widget create_messageopt_dialog(void);
49 void messageopt_ok_command_callback(Widget w, XtPointer client_data,
50 XtPointer call_data);
51 void messageopt_cancel_command_callback(Widget w, XtPointer client_data,
52 XtPointer call_data);
53 static Widget messageopt_toggles[E_COUNT][NUM_MW];
55 /**************************************************************************
56 ...
57 **************************************************************************/
58 void popup_messageopt_dialog(void)
60 Widget shell;
61 int i, j, state;
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],
70 XtNstate, state,
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 /**************************************************************************
81 ...
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;
89 Widget toggle = 0;
90 int i, longest_len = 0;
91 Dimension width;
93 shell = I_T(XtCreatePopupShell("messageoptpopup", transientShellWidgetClass,
94 toplevel, NULL, 0));
96 form = XtVaCreateManagedWidget("messageoptform", formWidgetClass,
97 shell, NULL);
99 title = I_L(XtVaCreateManagedWidget("messageopttitle", labelWidgetClass,
100 form, NULL));
102 explanation = I_L(XtVaCreateManagedWidget("messageoptexpl", labelWidgetClass,
103 form, NULL));
105 scrolled = XtVaCreateManagedWidget("messageoptscroll", viewportWidgetClass,
106 form, NULL);
108 col = XtVaCreateManagedWidget("messageoptcol", formWidgetClass,
109 scrolled, NULL);
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,
116 col, NULL);
118 colhead = I_L(XtVaCreateManagedWidget("messageoptcolhead", labelWidgetClass,
119 col, NULL));
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],
128 NULL);
130 if (len > longest_len) {
131 longest_len = 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++) {
148 int j;
150 for (j = 0; j < NUM_MW; j++) {
151 toggle = XtVaCreateManagedWidget("toggle", toggleWidgetClass, col,
152 XtNfromHoriz,
153 (j == 0 ? space_head : toggle),
154 XtNfromVert,
155 (i == 0) ? space_head : label[i - 1],
156 NULL);
157 XtAddCallback(toggle, XtNcallback, toggle_callback, NULL);
158 messageopt_toggles[sorted_events[i]][j] = toggle;
162 ok = I_L(XtVaCreateManagedWidget("messageoptokcommand",
163 commandWidgetClass,
164 form, NULL));
166 cancel = I_L(XtVaCreateManagedWidget("messageoptcancelcommand",
167 commandWidgetClass,
168 form, NULL));
170 XtAddCallback(ok, XtNcallback, messageopt_ok_command_callback,
171 (XtPointer)shell);
172 XtAddCallback(cancel, XtNcallback, messageopt_cancel_command_callback,
173 (XtPointer)shell);
175 XtRealizeWidget(shell);
177 xaw_horiz_center(title);
178 xaw_horiz_center(explanation);
180 return shell;
183 /**************************************************************************
185 **************************************************************************/
186 void messageopt_cancel_command_callback(Widget w, XtPointer client_data,
187 XtPointer call_data)
189 XtSetSensitive(main_form, TRUE);
190 XtDestroyWidget((Widget)client_data);
193 /**************************************************************************
195 **************************************************************************/
196 void messageopt_ok_command_callback(Widget w, XtPointer client_data,
197 XtPointer call_data)
199 int i, j;
200 Boolean b;
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);