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>
22 #include <X11/Intrinsic.h>
23 #include <X11/StringDefs.h>
24 #include <X11/Xaw/Form.h>
25 #include <X11/Xaw/Label.h>
26 #include <X11/Xaw/SimpleMenu.h>
27 #include <X11/Xaw/Command.h>
28 #include <X11/Xaw/List.h>
29 #include <X11/Xaw/Viewport.h>
42 #include "gui_stuff.h"
46 static Widget find_dialog_shell
;
47 static Widget find_form
;
48 static Widget find_label
;
49 static Widget find_viewport
;
50 static Widget find_list
;
51 static Widget find_center_command
;
52 static Widget find_cancel_command
;
54 void update_find_dialog(Widget find_list
);
56 void find_center_command_callback(Widget w
, XtPointer client_data
,
58 void find_cancel_command_callback(Widget w
, XtPointer client_data
,
60 void find_list_callback(Widget w
, XtPointer client_data
, XtPointer call_data
);
62 static char *dummy_city_list
[]={
75 static int ncities_total
;
76 static char **city_name_ptrs
;
77 static struct tile
*original_tile
;
79 /****************************************************************
80 popup the dialog 10% inside the main-window
81 *****************************************************************/
82 void popup_find_dialog(void)
85 Dimension width
, height
;
87 original_tile
= get_center_tile_mapcanvas();
89 XtSetSensitive(main_form
, FALSE
);
92 I_T(XtCreatePopupShell("finddialog", transientShellWidgetClass
,
95 find_form
= XtVaCreateManagedWidget("findform",
97 find_dialog_shell
, NULL
);
100 find_label
= I_L(XtVaCreateManagedWidget("findlabel", labelWidgetClass
,
103 find_viewport
= XtVaCreateManagedWidget("findviewport",
109 find_list
= XtVaCreateManagedWidget("findlist",
113 (XtArgVal
)dummy_city_list
,
116 find_center_command
=
117 I_L(XtVaCreateManagedWidget("findcentercommand", commandWidgetClass
,
120 find_cancel_command
=
121 I_L(XtVaCreateManagedWidget("findcancelcommand", commandWidgetClass
,
124 XtAddCallback(find_list
, XtNcallback
, find_list_callback
, NULL
);
125 XtAddCallback(find_center_command
, XtNcallback
,
126 find_center_command_callback
, NULL
);
127 XtAddCallback(find_cancel_command
, XtNcallback
,
128 find_cancel_command_callback
, NULL
);
131 XtRealizeWidget(find_dialog_shell
);
133 update_find_dialog(find_list
);
135 XtVaGetValues(toplevel
, XtNwidth
, &width
, XtNheight
, &height
, NULL
);
137 XtTranslateCoords(toplevel
, (Position
) width
/10, (Position
) height
/10,
139 XtVaSetValues(find_dialog_shell
, XtNx
, x
, XtNy
, y
, NULL
);
141 XtPopup(find_dialog_shell
, XtGrabNone
);
143 /* force refresh of viewport so the scrollbar is added.
144 * Buggy sun athena requires this */
145 XtVaSetValues(find_viewport
, XtNforceBars
, True
, NULL
);
150 /**************************************************************************
152 **************************************************************************/
153 void update_find_dialog(Widget search_list
)
158 players_iterate(pplayer
) {
159 ncities_total
+= city_list_size(pplayer
->cities
);
160 } players_iterate_end
;
162 city_name_ptrs
=fc_malloc(ncities_total
*sizeof(char*));
164 players_iterate(pplayer
) {
165 city_list_iterate(pplayer
->cities
, pcity
) {
166 *(city_name_ptrs
+j
++)=fc_strdup(city_name_get(pcity
));
167 } city_list_iterate_end
;
168 } players_iterate_end
;
171 qsort(city_name_ptrs
, ncities_total
, sizeof(char *), compare_strings_ptrs
);
172 XawListChange(search_list
, city_name_ptrs
, ncities_total
, 0, True
);
176 /**************************************************************************
178 **************************************************************************/
179 static void popdown_find_dialog(void)
183 for(i
=0; i
<ncities_total
; i
++)
184 free(*(city_name_ptrs
+i
));
186 XtDestroyWidget(find_dialog_shell
);
187 free(city_name_ptrs
);
188 XtSetSensitive(main_form
, TRUE
);
191 /**************************************************************************
193 **************************************************************************/
194 void find_center_command_callback(Widget w
, XtPointer client_data
,
198 XawListReturnStruct
*ret
;
200 ret
= XawListShowCurrent(find_list
);
202 if (ret
->list_index
!= XAW_LIST_NONE
) {
203 if ((pcity
= game_city_by_name(ret
->string
))) {
204 center_tile_mapcanvas(pcity
->tile
);
208 popdown_find_dialog();
211 /**************************************************************************
213 **************************************************************************/
214 void find_cancel_command_callback(Widget w
, XtPointer client_data
,
217 center_tile_mapcanvas(original_tile
);
218 popdown_find_dialog();
221 /**************************************************************************
223 **************************************************************************/
224 void find_list_callback(Widget w
, XtPointer client_data
, XtPointer call_data
)
227 XawListReturnStruct
*ret
;
229 ret
=XawListShowCurrent(find_list
);
231 if (ret
->list_index
!= XAW_LIST_NONE
) {
232 if ((pcity
= game_city_by_name(ret
->string
))) {
233 center_tile_mapcanvas(pcity
->tile
);