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>
24 #include <X11/Xaw/Scrollbar.h>
25 #include <X11/Xaw/Form.h>
26 #include <X11/Xaw/Label.h>
27 #include <X11/Xaw/SimpleMenu.h>
28 #include <X11/Xaw/Command.h>
29 #include <X11/Xaw/AsciiText.h>
30 #include <X11/Xaw/SmeBSB.h>
31 #include <X11/Xaw/SmeLine.h>
33 /* common & utility */
46 #include "client_main.h"
53 #include "gui_stuff.h"
57 #include "overview_common.h"
63 static void popupinfo_popdown_callback(Widget w
, XtPointer client_data
, XtPointer call_data
);
65 /**************************************************************************
67 **************************************************************************/
68 static void name_new_city_callback(Widget w
, XtPointer client_data
,
71 int idx
= XTPOINTER_TO_INT(client_data
);
74 cancel_city(index_to_tile(-idx
-1));
76 finish_city(index_to_tile(idx
), input_dialog_get_input(w
));
79 input_dialog_destroy(w
);
82 /**************************************************************************
83 Popup dialog where the user choose the name of the new city
84 punit = (settler) unit which builds the city
85 suggestname = suggetion of the new city's name
86 **************************************************************************/
87 void popup_newcity_dialog(struct unit
*punit
, const char *suggestname
)
89 input_dialog_create(toplevel
, "shellnewcityname",
90 _("What should we call our new city?"), suggestname
,
91 name_new_city_callback
,
92 INT_TO_XTPOINTER(tile_index(unit_tile(punit
))),
93 name_new_city_callback
,
94 INT_TO_XTPOINTER(-tile_index(unit_tile(punit
)) - 1));
97 /**************************************************************************
99 **************************************************************************/
100 static void popit(int xin
, int yin
, struct tile
*ptile
)
105 static struct tile
*cross_list
[2+1];
106 struct tile
**cross_head
= cross_list
;
110 static bool is_orders
;
112 if (TILE_UNKNOWN
!= client_tile_get_known(ptile
)) {
113 Widget p
=XtCreatePopupShell("popupinfo", simpleMenuWidgetClass
,
114 map_canvas
, NULL
, 0);
115 content
= (char *) popup_info_text(ptile
);
116 /* content is provided to us as a single string with multiple lines,
117 but xaw doens't support multi-line labels. So we break it up.
118 We mangle it in the process, but who cares? It's never going to be
119 used again anyway. */
121 char *end
= strchr(content
, '\n');
125 XtCreateManagedWidget(content
, smeBSBObjectClass
, p
, NULL
, 0);
133 punit
= find_visible_unit(ptile
);
134 is_orders
= show_unit_orders(punit
);
135 if (punit
&& punit
->goto_tile
) {
136 *cross_head
= punit
->goto_tile
;
142 xin
/= tileset_tile_width(tileset
);
143 xin
*= tileset_tile_width(tileset
);
144 yin
/= tileset_tile_height(tileset
);
145 yin
*= tileset_tile_height(tileset
);
146 xin
+= (tileset_tile_width(tileset
) / 2);
147 XtTranslateCoords(map_canvas
, xin
, yin
, &x
, &y
);
148 dw
= XDisplayWidth (display
, screen_number
);
149 dh
= XDisplayHeight (display
, screen_number
);
151 XtVaGetValues(p
, XtNwidth
, &w
, XtNheight
, &h
, XtNborderWidth
, &b
, NULL
);
156 if ((x
+ w
) > dw
) x
= dw
- w
;
158 if ((y
+ h
) > dh
) y
= dh
- h
;
160 XtVaSetValues(p
, XtNx
, x
, XtNy
, y
, NULL
);
163 for (i
= 0; cross_list
[i
]; i
++) {
164 put_cross_overlay_tile(cross_list
[i
]);
166 XtAddCallback(p
,XtNpopdownCallback
,popupinfo_popdown_callback
,
167 (XtPointer
)&is_orders
);
169 XtPopupSpringLoaded(p
);
174 /**************************************************************************
176 **************************************************************************/
177 void popupinfo_popdown_callback(Widget w
, XtPointer client_data
,
180 bool *full
= client_data
;
183 update_map_canvas_visible();
191 /**************************************************************************
192 (RP:) wake up my own sentried units on the tile that was clicked
193 **************************************************************************/
194 void mapctrl_btn_wakeup(XEvent
*event
)
196 wakeup_button_pressed(event
->xbutton
.x
, event
->xbutton
.y
);
199 /**************************************************************************
201 **************************************************************************/
202 void mapctrl_btn_mapcanvas(XEvent
*event
)
204 XButtonEvent
*ev
=&event
->xbutton
;
205 struct tile
*ptile
= canvas_pos_to_tile(ev
->x
, ev
->y
);
207 if (!can_client_change_view()) {
211 if (ev
->button
== Button1
&& (ev
->state
& ControlMask
)) {
212 action_button_pressed(ev
->x
, ev
->y
, SELECT_SEA
);
213 } else if (ev
->button
== Button1
) {
214 action_button_pressed(ev
->x
, ev
->y
, SELECT_POPUP
);
215 } else if (ev
->button
== Button2
&& ptile
) {
216 popit(ev
->x
, ev
->y
, ptile
);
217 } else if (ev
->button
== Button3
&& (ev
->state
& ControlMask
)) {
218 action_button_pressed(ev
->x
, ev
->y
, SELECT_LAND
);
219 } else if (ev
->button
== Button3
) {
220 recenter_button_pressed(ev
->x
, ev
->y
);
224 /**************************************************************************
225 Update goto line so that destination is at current mouse pointer location.
226 **************************************************************************/
227 void create_line_at_mouse_pos(void)
235 XQueryPointer(display
, XtWindow(map_canvas
),
241 if (on_same_screen
) {
246 /**************************************************************************
247 The Area Selection rectangle. Called by center_tile_mapcanvas() and
248 when the mouse pointer moves.
249 **************************************************************************/
250 void update_rect_at_mouse_pos(void)
255 /**************************************************************************
256 Draws the on the map the tiles the given city is using
257 **************************************************************************/
258 void mapctrl_key_city_workers(XEvent
*event
)
260 key_city_overlay(event
->xbutton
.x
, event
->xbutton
.y
);
263 /**************************************************************************
265 **************************************************************************/
266 void mapctrl_btn_overviewcanvas(XEvent
*event
)
270 XButtonEvent
*ev
= &event
->xbutton
;
272 if (!can_client_change_view()) {
276 overview_to_map_pos(&map_x
, &map_y
, event
->xbutton
.x
, event
->xbutton
.y
);
277 ptile
= map_pos_to_tile(map_x
, map_y
);
282 if(ev
->button
==Button1
)
283 do_map_click(ptile
, SELECT_POPUP
);
284 else if(ev
->button
==Button3
)
285 center_tile_mapcanvas(ptile
);
288 /**************************************************************************
290 **************************************************************************/
291 void center_on_unit(void)
293 request_center_focus_unit();
296 /**************************************************************************
297 Enable or disable the turn done button.
298 Should probably some where else.
299 **************************************************************************/
300 void set_turn_done_button_state(bool state
)
302 XtSetSensitive(turn_done_button
, state
);