Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2002:
[Freeciv-Dev] [Patch] Merge meswin code (PR#1751)
Home

[Freeciv-Dev] [Patch] Merge meswin code (PR#1751)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Raimar Falke <rf13@xxxxxxxxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx, bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] [Patch] Merge meswin code (PR#1751)
From: Andreas Kemnade <akemnade@xxxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 17 Jul 2002 11:45:47 +0200

Raimar Falke writes:
 > 
 > The patch moves code from messagewin.c to messagewin_common.c and so
 > removes 280 lines. Only GTK and XAW tested.
I have tested win32
minor changes needed.

Greetings
Andreas Kemnade

Index: client/messagewin_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/messagewin_common.c,v
retrieving revision 1.2
diff -u -r1.2 messagewin_common.c
--- client/messagewin_common.c  2002/07/02 19:21:41     1.2
+++ client/messagewin_common.c  2002/07/17 09:42:01
@@ -1,14 +1,36 @@
+/********************************************************************** 
+ Freeciv - Copyright (C) 2002 - R. Falke
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+***********************************************************************/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <assert.h>
+#include <string.h>
 
+#include "mem.h"
 #include "messagewin_g.h"
 #include "options.h"
+#include "fcintl.h"
+#include "mapview_g.h"
+#include "citydlg_g.h"
 
 #include "messagewin_common.h"
 
 static int frozen_level = 0;
 static bool change = FALSE;
-static bool messages_exists = FALSE;
+static struct message *messages = NULL;
+static int messages_total = 0;
+static int messages_alloc = 0;
 
 /******************************************************************
  Turn off updating of message window
@@ -48,7 +70,7 @@
     return;
   }
 
-  if (!is_meswin_open() && messages_exists &&
+  if (!is_meswin_open() && messages_total > 0 &&
       (!game.player_ptr->ai.control || ai_popup_windows)) {
     popup_meswin_dialog();
     change = FALSE;
@@ -66,9 +88,14 @@
 **************************************************************************/
 void clear_notify_window(void)
 {
-  messages_exists = FALSE;
+  int i;
+
   change = TRUE;
-  real_clear_notify_window();
+  for (i = 0; i < messages_total; i++) {
+    free(messages[i].descr);
+    messages[i].descr = NULL;
+  }
+  messages_total = 0;
   update_meswin_dialog();
 }
 
@@ -77,8 +104,115 @@
 **************************************************************************/
 void add_notify_window(struct packet_generic_message *packet)
 {
-  messages_exists = TRUE;
+  const size_t min_msg_len = 50;
+  char *game_prefix1 = "Game: ";
+  char *game_prefix2 = _("Game: ");
+  size_t gp_len1 = strlen(game_prefix1);
+  size_t gp_len2 = strlen(game_prefix2);
+  char *s = fc_malloc(strlen(packet->message) + min_msg_len);
+  size_t nspc;
+
   change = TRUE;
-  real_add_notify_window(packet);
+
+  if (messages_total + 2 > messages_alloc) {
+    messages_alloc = messages_total + 32;
+    messages = fc_realloc(messages, messages_alloc * sizeof(*messages));
+  }
+
+  if (strncmp(packet->message, game_prefix1, gp_len1) == 0) {
+    strcpy(s, packet->message + gp_len1);
+  } else if (strncmp(packet->message, game_prefix2, gp_len2) == 0) {
+    strcpy(s, packet->message + gp_len2);
+  } else {
+    strcpy(s, packet->message);
+  }
+
+  nspc = min_msg_len - strlen(s);
+  if (nspc > 0) {
+    strncat(s, "                                                  ", nspc);
+  }
+
+  messages[messages_total].x = packet->x;
+  messages[messages_total].y = packet->y;
+  messages[messages_total].event = packet->event;
+  messages[messages_total].descr = s;
+  messages[messages_total].location_ok = (packet->x != -1 && packet->y != -1);
+
+  if (messages[messages_total].location_ok) {
+    struct city *pcity = map_get_city(packet->x, packet->y);
+
+    messages[messages_total].city_ok = (pcity
+                                       && city_owner(pcity) ==
+                                       game.player_ptr);
+  } else {
+    messages[messages_total].city_ok = FALSE;
+  }
+
+  messages_total++;
+
   update_meswin_dialog();
+}
+
+/**************************************************************************
+ Returns the pointer to a message.
+**************************************************************************/
+struct message *get_message(int message_index)
+{
+  assert(message_index >= 0 && message_index < messages_total);
+  return &messages[message_index];
+}
+
+/**************************************************************************
+ Returns the number of message in the window.
+**************************************************************************/
+int get_num_messages(void)
+{
+  return messages_total;
+}
+
+/**************************************************************************
+ Called from messagewin.c if the user clicks on the popup-city button.
+**************************************************************************/
+void meswin_popup_city(int message_index)
+{
+  assert(message_index < messages_total);
+
+  if (messages[message_index].city_ok) {
+    int x = messages[message_index].x;
+    int y = messages[message_index].y;
+    struct city *pcity = map_get_city(x, y);
+
+    if (center_when_popup_city) {
+      center_tile_mapcanvas(x, y);
+    }
+    popup_city_dialog(pcity, 0);
+  }
+}
+
+/**************************************************************************
+ Called from messagewin.c if the user clicks on the goto button.
+**************************************************************************/
+void meswin_goto(int message_index)
+{
+  assert(message_index < messages_total);
+
+  if (messages[message_index].location_ok) {
+    center_tile_mapcanvas(messages[message_index].x,
+                         messages[message_index].y);
+  }
+}
+
+/**************************************************************************
+ Called from messagewin.c if the user double clicks on a message.
+**************************************************************************/
+void meswin_double_click(int message_index)
+{
+  assert(message_index < messages_total);
+
+  if (messages[message_index].city_ok
+      && is_city_event(messages[message_index].event)) {
+    meswin_popup_city(message_index);
+  } else if (messages[message_index].location_ok) {
+    meswin_goto(message_index);
+  }
 }
Index: client/messagewin_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/messagewin_common.h,v
retrieving revision 1.1
diff -u -r1.1 messagewin_common.h
--- client/messagewin_common.h  2002/06/27 01:00:49     1.1
+++ client/messagewin_common.h  2002/07/17 09:42:01
@@ -14,6 +14,15 @@
 #ifndef FC__MESSAGEWIN_COMMON_H
 #define FC__MESSAGEWIN_COMMON_H
 
+#include "events.h"
+
+struct message {
+  char *descr;
+  int x, y;
+  enum event_type event;
+  bool location_ok, city_ok;
+};
+
 void meswin_freeze(void);
 void meswin_thaw(void);
 void meswin_force_thaw(void);
@@ -21,5 +30,11 @@
 void update_meswin_dialog(void);
 void clear_notify_window(void);
 void add_notify_window(struct packet_generic_message *packet);
+
+struct message *get_message(int message_index);
+int get_num_messages(void);
+void meswin_popup_city(int message_index);
+void meswin_goto(int message_index);
+void meswin_double_click(int message_index);
 
 #endif
Index: client/gui-gtk/messagewin.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/messagewin.c,v
retrieving revision 1.32
diff -u -r1.32 messagewin.c
--- client/gui-gtk/messagewin.c 2002/06/30 14:37:41     1.32
+++ client/gui-gtk/messagewin.c 2002/07/17 09:42:02
@@ -192,99 +192,6 @@
 }
 
 /**************************************************************************
-...
-**************************************************************************/
-
-static int messages_total = 0; /* current total number of message lines */
-static int messages_alloc = 0; /* number allocated for */
-static char **string_ptrs = NULL;
-static int *xpos = NULL;
-static int *ypos = NULL;
-static int *event = NULL;
-
-/**************************************************************************
- This makes sure that the next two elements in string_ptrs etc are
- allocated for.  Two = one to be able to grow, and one for the sentinel
- in string_ptrs.
- Note update_meswin_dialog should always be called soon after this since
- it contains pointers to the memory we're reallocing here.
-**************************************************************************/
-static void meswin_allocate(void)
-{
-  int i;
-  
-  if (messages_total+2 > messages_alloc) {
-    messages_alloc = messages_total + 32;
-    string_ptrs = fc_realloc(string_ptrs, messages_alloc*sizeof(char*));
-    xpos = fc_realloc(xpos, messages_alloc*sizeof(int));
-    ypos = fc_realloc(ypos, messages_alloc*sizeof(int));
-    event = fc_realloc(event, messages_alloc*sizeof(int));
-    for( i=messages_total; i<messages_alloc; i++ ) {
-      string_ptrs[i] = NULL;
-      xpos[i] = 0;
-      ypos[i] = 0;
-      event[i] = E_NOEVENT;
-    }
-  }
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void real_clear_notify_window(void)
-{
-  int i;
-  meswin_allocate();
-  for (i = 0; i <messages_total; i++) {
-    free(string_ptrs[i]);
-    string_ptrs[i] = NULL;
-    xpos[i] = 0;
-    ypos[i] = 0;
-    event[i] = E_NOEVENT;
-  }
-  string_ptrs[0] = NULL;
-  messages_total = 0;
-  if(meswin_dialog_shell) {
-    gtk_widget_set_sensitive(meswin_goto_command, FALSE);
-    gtk_widget_set_sensitive(meswin_popcity_command, FALSE);
-  }
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void real_add_notify_window(struct packet_generic_message *packet)
-{
-  char *s;
-  int nspc;
-  char *game_prefix1 = "Game: ";
-  char *game_prefix2 = _("Game: ");
-  int gp_len1 = strlen(game_prefix1);
-  int gp_len2 = strlen(game_prefix2);
-
-  meswin_allocate();
-  s = fc_malloc(strlen(packet->message) + 50);
-  if (strncmp(packet->message, game_prefix1, gp_len1) == 0) {
-    strcpy(s, packet->message + gp_len1);
-  } else if(strncmp(packet->message, game_prefix2, gp_len2) == 0) {
-    strcpy(s, packet->message + gp_len2);
-  } else {
-    strcpy(s, packet->message);
-  }
-
-  nspc=50-strlen(s);
-  if(nspc>0)
-    strncat(s, "                                                  ", nspc);
-  
-  xpos[messages_total] = packet->x;
-  ypos[messages_total] = packet->y;
-  event[messages_total]= packet->event;
-  string_ptrs[messages_total] = s;
-  messages_total++;
-  string_ptrs[messages_total] = NULL;
-}
-
-/**************************************************************************
  This scrolls the messages window down to the bottom.
  NOTE: it seems this must not be called until _after_ meswin_dialog_shell
  is ...? realized, popped up, ... something.
@@ -295,10 +202,12 @@
 **************************************************************************/
 static void meswin_scroll_down(void)
 {
-  if (messages_total <= N_MSG_VIEW)
+  if (get_num_messages() <= N_MSG_VIEW) {
     return;
-  
-   gtk_clist_moveto(GTK_CLIST(meswin_list), messages_total-1, 0, 0.0, 0.0);
+  }
+
+  gtk_clist_moveto(GTK_CLIST(meswin_list), get_num_messages() - 1, 0, 0.0,
+                  0.0);
 }
 
 /**************************************************************************
@@ -306,13 +215,13 @@
 **************************************************************************/
 void real_update_meswin_dialog(void)
 {
-  int i;
+  int i, num = get_num_messages();
 
   gtk_clist_freeze(GTK_CLIST(meswin_list));
   gtk_clist_clear(GTK_CLIST(meswin_list));
 
-  for (i = 0; i < messages_total; i++) {
-    gtk_clist_append(GTK_CLIST(meswin_list), &string_ptrs[i]);
+  for (i = 0; i < num; i++) {
+    gtk_clist_append(GTK_CLIST(meswin_list), &get_message(i)->descr);
     meswin_not_visited_item(i);
   }
 
@@ -320,6 +229,9 @@
   gtk_widget_show_all(meswin_list);
 
   meswin_scroll_down();
+
+  gtk_widget_set_sensitive(meswin_goto_command, FALSE);
+  gtk_widget_set_sensitive(meswin_popcity_command, FALSE);
 }
 
 /**************************************************************************
@@ -328,28 +240,16 @@
 static void meswin_list_callback(GtkWidget * w, gint row, gint column,
                                 GdkEvent * ev)
 {
-  struct city *pcity;
-  int x, y;
-  bool location_ok, city_ok;
-
-  x = xpos[row];
-  y = ypos[row];
-  location_ok = (x != -1 && y != -1);
-  city_ok = (location_ok && (pcity = map_get_city(x, y))
-            && (pcity->owner == game.player_idx));
+  struct message *message = get_message(row);
 
   if (ev && ev->type == GDK_2BUTTON_PRESS) {
     /* since we added a gtk_clist_select_row() there may be no event */
-    if (city_ok && is_city_event(event[row])) {
-      meswin_popcity_callback(meswin_popcity_command, NULL);
-    } else if (location_ok) {
-      meswin_goto_callback(meswin_goto_command, NULL);
-    }
+    meswin_double_click(row);
   }
   meswin_visited_item(row);
 
-  gtk_widget_set_sensitive(meswin_goto_command, location_ok);
-  gtk_widget_set_sensitive(meswin_popcity_command, city_ok);
+  gtk_widget_set_sensitive(meswin_goto_command, message->location_ok);
+  gtk_widget_set_sensitive(meswin_popcity_command, message->city_ok);
 }
 
 /**************************************************************************
@@ -375,44 +275,33 @@
 /**************************************************************************
 ...
 **************************************************************************/
-static void meswin_goto_callback(GtkWidget *w, gpointer data)
+static void meswin_goto_callback(GtkWidget * w, gpointer data)
 {
-  GList *selection;
-  gint   row;
+  GList *selection = selection = GTK_CLIST(meswin_list)->selection;
+  gint row;
 
-  if (!(selection=GTK_CLIST(meswin_list)->selection))
-      return;
+  if (!selection) {
+    return;
+  }
 
   row = GPOINTER_TO_INT(selection->data);
-
-  if(xpos[row]!=-1 && ypos[row]!=-1)
-    center_tile_mapcanvas(xpos[row], ypos[row]);
-  meswin_visited_item (row);
+  meswin_goto(row);
+  meswin_visited_item(row);
 }
 
 /**************************************************************************
 ...
 **************************************************************************/
-static void meswin_popcity_callback(GtkWidget *w, gpointer data)
+static void meswin_popcity_callback(GtkWidget * w, gpointer data)
 {
-  struct city *pcity;
-  int x, y;
-  GList *selection;
+  GList *selection = selection = GTK_CLIST(meswin_list)->selection;
   gint row;
 
-  if (!(selection=GTK_CLIST(meswin_list)->selection))
-      return;
+  if (!selection) {
+    return;
+  }
 
   row = GPOINTER_TO_INT(selection->data);
-
-  x = xpos[row];
-  y = ypos[row];
-  if((x!=-1 && y!=-1) && (pcity=map_get_city(x,y))
-     && (pcity->owner == game.player_idx)) {
-      if (center_when_popup_city) {
-       center_tile_mapcanvas(x,y);
-      }
-    popup_city_dialog(pcity, 0);
-  }
-  meswin_visited_item (row);
+  meswin_popup_city(row);
+  meswin_visited_item(row);
 }
Index: client/gui-gtk-2.0/messagewin.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/messagewin.c,v
retrieving revision 1.11
diff -u -r1.11 messagewin.c
--- client/gui-gtk-2.0/messagewin.c     2002/06/30 14:37:44     1.11
+++ client/gui-gtk-2.0/messagewin.c     2002/07/17 09:42:03
@@ -214,176 +214,62 @@
 /**************************************************************************
 ...
 **************************************************************************/
-
-static int messages_total = 0; /* current total number of message lines */
-static int messages_alloc = 0; /* number allocated for */
-static char **string_ptrs = NULL;
-static int *xpos = NULL;
-static int *ypos = NULL;
-static int *event = NULL;
-
-/**************************************************************************
- This makes sure that the next two elements in string_ptrs etc are
- allocated for.  Two = one to be able to grow, and one for the sentinel
- in string_ptrs.
- Note update_meswin_dialog should always be called soon after this since
- it contains pointers to the memory we're reallocing here.
-**************************************************************************/
-static void meswin_allocate(void)
-{
-  int i;
-  
-  if (messages_total+2 > messages_alloc) {
-    messages_alloc = messages_total + 32;
-    string_ptrs = fc_realloc(string_ptrs, messages_alloc*sizeof(char*));
-    xpos = fc_realloc(xpos, messages_alloc*sizeof(int));
-    ypos = fc_realloc(ypos, messages_alloc*sizeof(int));
-    event = fc_realloc(event, messages_alloc*sizeof(int));
-    for( i=messages_total; i<messages_alloc; i++ ) {
-      string_ptrs[i] = NULL;
-      xpos[i] = 0;
-      ypos[i] = 0;
-      event[i] = E_NOEVENT;
-    }
-  }
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void real_clear_notify_window(void)
-{
-  int i;
-  meswin_allocate();
-  for (i = 0; i <messages_total; i++) {
-    free(string_ptrs[i]);
-    string_ptrs[i] = NULL;
-    xpos[i] = 0;
-    ypos[i] = 0;
-    event[i] = E_NOEVENT;
-  }
-  string_ptrs[0] = NULL;
-  messages_total = 0;
-
-  if(meswin_dialog_shell) {
-    gtk_widget_set_sensitive(meswin_goto_command, FALSE);
-    gtk_widget_set_sensitive(meswin_popcity_command, FALSE);
-  }
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void real_add_notify_window(struct packet_generic_message *packet)
-{
-  char *s;
-  int nspc;
-  char *game_prefix1 = "Game: ";
-  char *game_prefix2 = _("Game: ");
-  int gp_len1 = strlen(game_prefix1);
-  int gp_len2 = strlen(game_prefix2);
-
-  meswin_allocate();
-  s = fc_malloc(strlen(packet->message) + 50);
-  if (strncmp(packet->message, game_prefix1, gp_len1) == 0) {
-    strcpy(s, packet->message + gp_len1);
-  } else if(strncmp(packet->message, game_prefix2, gp_len2) == 0) {
-    strcpy(s, packet->message + gp_len2);
-  } else {
-    strcpy(s, packet->message);
-  }
-
-  nspc=50-strlen(s);
-  if(nspc>0)
-    strncat(s, "                                                  ", nspc);
-  
-  xpos[messages_total] = packet->x;
-  ypos[messages_total] = packet->y;
-  event[messages_total]= packet->event;
-  string_ptrs[messages_total] = s;
-  messages_total++;
-  string_ptrs[messages_total] = NULL;
-}
-
-/**************************************************************************
-...
-**************************************************************************/
 void real_update_meswin_dialog(void)
 {
-  int i;
+  int i, num = get_num_messages();
   GtkTreeIter it;
 
   gtk_list_store_clear(meswin_store);
 
-  for (i = 0; i < messages_total; i++) {
+  for (i = 0; i < num; i++) {
     GValue value = { 0, };
 
     gtk_list_store_append(meswin_store, &it);
 
     g_value_init(&value, G_TYPE_STRING);
-    g_value_set_static_string(&value, string_ptrs[i]);
+    g_value_set_static_string(&value, get_message(i)->descr);
     gtk_list_store_set_value(meswin_store, &it, 0, &value);
     g_value_unset(&value);
 
     meswin_not_visited_item(i);
   }
+  gtk_widget_set_sensitive(meswin_goto_command, FALSE);
+  gtk_widget_set_sensitive(meswin_popcity_command, FALSE);
 }
 
 /**************************************************************************
 ...
 **************************************************************************/
-static void meswin_selection_callback(GtkTreeSelection *selection,
-                                      gpointer data)
+static void meswin_selection_callback(GtkTreeSelection * selection,
+                                     gpointer data)
 {
-  gint row;
+  gint row = gtk_tree_selection_get_row(selection);
 
-  if ((row = gtk_tree_selection_get_row(selection)) != -1) {
-    struct city *pcity;
-    int x, y;
-    bool location_ok, city_ok;
-
-    x = xpos[row];
-    y = ypos[row];
-    location_ok = (x != -1 && y != -1);
-    city_ok = (location_ok && (pcity = map_get_city(x, y))
-              && (pcity->owner == game.player_idx));
+  if (row != -1) {
+    struct message *message = get_message(i);
 
-    gtk_widget_set_sensitive(meswin_goto_command, location_ok);
-    gtk_widget_set_sensitive(meswin_popcity_command, city_ok);
+    gtk_widget_set_sensitive(meswin_goto_command, message->location_ok);
+    gtk_widget_set_sensitive(meswin_popcity_command, message->city_ok);
   }
 }
 
 /**************************************************************************
 ...
 **************************************************************************/
-static void meswin_row_activated_callback(GtkTreeView *view,
-                                         GtkTreePath *path,
-                                         GtkTreeViewColumn *col,
+static void meswin_row_activated_callback(GtkTreeView * view,
+                                         GtkTreePath * path,
+                                         GtkTreeViewColumn * col,
                                          gpointer data)
 {
-  struct city *pcity;
-  int x, y;
-  bool location_ok, city_ok;
-  gint row;
-
-  row = gtk_tree_path_get_indices(path)[0];
-
-  x = xpos[row];
-  y = ypos[row];
-  location_ok = (x != -1 && y != -1);
-  city_ok = (location_ok && (pcity = map_get_city(x, y))
-            && (pcity->owner == game.player_idx));
-
-  if (city_ok && is_city_event(event[row])) {
-    meswin_popcity_callback(meswin_popcity_command, NULL);
-  } else if (location_ok) {
-    meswin_goto_callback(meswin_goto_command, NULL);
-  }
+  gint row = gtk_tree_path_get_indices(path)[0];
+  struct message *message = get_message(i);
 
+  meswin_double_click(row);
+
   meswin_visited_item(row);
 
-  gtk_widget_set_sensitive(meswin_goto_command, location_ok);
-  gtk_widget_set_sensitive(meswin_popcity_command, city_ok);
+  gtk_widget_set_sensitive(meswin_goto_command, message->location_ok);
+  gtk_widget_set_sensitive(meswin_popcity_command, message->city_ok);
 }
 
 /**************************************************************************
@@ -406,38 +292,28 @@
 /**************************************************************************
 ...
 **************************************************************************/
-void meswin_goto_callback(GtkWidget *w, gpointer data)
+void meswin_goto_callback(GtkWidget * w, gpointer data)
 {
-  gint row;
+  gint row = gtk_tree_selection_get_row(meswin_selection);
 
-  if((row = gtk_tree_selection_get_row(meswin_selection)) == -1)
+  if (row == -1) {
     return;
+  }
 
-  if(xpos[row]!=-1 && ypos[row]!=-1)
-    center_tile_mapcanvas(xpos[row], ypos[row]);
+  meswin_goto(row);
   meswin_visited_item(row);
 }
 
 /**************************************************************************
 ...
 **************************************************************************/
-static void meswin_popcity_callback(GtkWidget *w, gpointer data)
+static void meswin_popcity_callback(GtkWidget * w, gpointer data)
 {
-  struct city *pcity;
-  int x, y;
-  gint row;
+  gint row = gtk_tree_selection_get_row(meswin_selection);
 
-  if((row = gtk_tree_selection_get_row(meswin_selection)) == -1)
+  if (row == -1) {
     return;
-
-  x = xpos[row];
-  y = ypos[row];
-  if((x!=-1 && y!=-1) && (pcity=map_get_city(x,y))
-     && (pcity->owner == game.player_idx)) {
-      if (center_when_popup_city) {
-       center_tile_mapcanvas(x,y);
-      }
-    popup_city_dialog(pcity, 0);
   }
+  meswin_popup_city(row);
   meswin_visited_item(row);
 }
Index: client/gui-win32/messagewin.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/messagewin.c,v
retrieving revision 1.6
diff -u -r1.6 messagewin.c
--- client/gui-win32/messagewin.c       2002/07/13 13:33:07     1.6
+++ client/gui-win32/messagewin.c       2002/07/17 09:42:04
@@ -48,12 +48,6 @@
 static HWND meswin_dlg;
 static struct fcwin_box *meswin_box;
 static int max_list_width;
-static int messages_total = 0; /* current total number of message lines */
-static int messages_alloc = 0; /* number allocated for */
-static char **string_ptrs = NULL;
-static int *xpos = NULL;
-static int *ypos = NULL;
-static int *event = NULL;
 
 /**************************************************************************
 
@@ -98,38 +92,25 @@
          break;
        case ID_MESSAGEWIN_GOTO:
          {
-           int id,row;
-           id=ListBox_GetCurSel(GetDlgItem(hWnd,ID_MESSAGEWIN_LIST));
-           if (id!=LB_ERR)
-             {
-               row=ListBox_GetItemData(GetDlgItem(hWnd,ID_MESSAGEWIN_LIST),
-                                       id);
-               if(xpos[row] != 0 || ypos[row]!=0)
-                   center_tile_mapcanvas(xpos[row], ypos[row]);
-                 
-             }
+           int id = ListBox_GetCurSel(GetDlgItem(hWnd, ID_MESSAGEWIN_LIST));
+
+           if (id != LB_ERR) {
+             int row =
+               ListBox_GetItemData(GetDlgItem(hWnd, ID_MESSAGEWIN_LIST),
+                                   id);
+             meswin_goto(row);
+           }   
          }
          break;
        case ID_MESSAGEWIN_POPUP:
          {
-           int id,row;
-           struct city *pcity;
-           int x, y;   
-           id=ListBox_GetCurSel(GetDlgItem(hWnd,ID_MESSAGEWIN_LIST));
-           if (id!=LB_ERR)
-             {
-               row=ListBox_GetItemData(GetDlgItem(hWnd,ID_MESSAGEWIN_LIST),
-                                       id);
-               x = xpos[row];
-               y = ypos[row];
-               if((x || y) && (pcity=map_get_city(x,y))
-                  && (pcity->owner == game.player_idx)) {
-                 if (center_when_popup_city) {
-                   center_tile_mapcanvas(x,y);
-                 }
-                 popup_city_dialog(pcity, 0);
-               }                                   
-             }
+           int id=ListBox_GetCurSel(GetDlgItem(hWnd,ID_MESSAGEWIN_LIST));
+           if (id != LB_ERR) {
+             int row =
+                 ListBox_GetItemData(GetDlgItem(hWnd, ID_MESSAGEWIN_LIST),
+                                     id);
+             meswin_popup_city(row);
+           }
          }
          break;
        }
@@ -237,110 +218,25 @@
 }
 
 /**************************************************************************
-...
-**************************************************************************/
-
-
-/**************************************************************************
- This makes sure that the next two elements in string_ptrs etc are
- allocated for.  Two = one to be able to grow, and one for the sentinel
- in string_ptrs.
- Note update_meswin_dialog should always be called soon after this since
- it contains pointers to the memory we're reallocing here.
-**************************************************************************/
-static void meswin_allocate(void)
-{
-  int i;
-  
-  if (messages_total+2 > messages_alloc) {
-    messages_alloc = messages_total + 32;
-    string_ptrs = fc_realloc(string_ptrs, messages_alloc*sizeof(char*));
-    xpos = fc_realloc(xpos, messages_alloc*sizeof(int));
-    ypos = fc_realloc(ypos, messages_alloc*sizeof(int));
-    event = fc_realloc(event, messages_alloc*sizeof(int));
-    for( i=messages_total; i<messages_alloc; i++ ) {
-      string_ptrs[i] = NULL;
-      xpos[i] = 0;
-      ypos[i] = 0;
-      event[i] = E_NOEVENT;
-    }
-  }
-}
 
-/**************************************************************************
-...
 **************************************************************************/
-void real_clear_notify_window(void)
-{
-  int i;
-  meswin_allocate();
-  for (i = 0; i <messages_total; i++) {
-    free(string_ptrs[i]);
-    string_ptrs[i] = NULL;
-    xpos[i] = 0;
-    ypos[i] = 0;
-    event[i] = E_NOEVENT;
-  }
-  string_ptrs[0]=0;
-  messages_total = 0;
-  if(meswin_dlg) {
-    EnableWindow(GetDlgItem(meswin_dlg,ID_MESSAGEWIN_GOTO),FALSE);
-    EnableWindow(GetDlgItem(meswin_dlg,ID_MESSAGEWIN_POPUP),FALSE);
-  }
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void real_add_notify_window(struct packet_generic_message *packet)
-{
-  char *s;
-  int nspc;
-  char *game_prefix1 = "Game: ";
-  char *game_prefix2 = _("Game: ");
-  int gp_len1 = strlen(game_prefix1);
-  int gp_len2 = strlen(game_prefix2);
-
-  meswin_allocate();
-  s = fc_malloc(strlen(packet->message) + 50);
-  if (strncmp(packet->message, game_prefix1, gp_len1) == 0) {
-    strcpy(s, packet->message + gp_len1);
-  } else if(strncmp(packet->message, game_prefix2, gp_len2) == 0) {
-    strcpy(s, packet->message + gp_len2);
-  } else {
-    strcpy(s, packet->message);
-  }
-
-  nspc=50-strlen(s);
-  if(nspc>0)
-    strncat(s, "                                                  ", nspc);
-  
-  xpos[messages_total] = packet->x;
-  ypos[messages_total] = packet->y;
-  event[messages_total]= packet->event;
-  string_ptrs[messages_total] = s;
-  messages_total++;
-  string_ptrs[messages_total] = 0;
-}
-
-
-/**************************************************************************
-
-**************************************************************************/
 void real_update_meswin_dialog(void)
 {
-  RECT rc;
-  int id;
-  int i;
-  HWND hLst;
+  int i, num = get_num_messages();
+  HWND hLst = GetDlgItem(meswin_dlg, ID_MESSAGEWIN_LIST);
+
   max_list_width = 0;
-  hLst = GetDlgItem(meswin_dlg, ID_MESSAGEWIN_LIST);
   ListBox_ResetContent(hLst);
-  for (i = 0; i < messages_total; i++) {
-    id = ListBox_AddString(hLst, string_ptrs[i]);
+
+  for (i = 0; i < num; i++) {
+    int id = ListBox_AddString(hLst, get_message(i)->descr);
+    RECT rc;
+
     ListBox_SetItemData(hLst, id, i);
     ListBox_GetItemRect(hLst, id, &rc);
     max_list_width = MAX(max_list_width, rc.right - rc.left);
   }
   max_list_width += 20;
+  EnableWindow(GetDlgItem(meswin_dlg, ID_MESSAGEWIN_GOTO), FALSE);
+  EnableWindow(GetDlgItem(meswin_dlg, ID_MESSAGEWIN_POPUP), FALSE);
 }
Index: client/gui-xaw/messagewin.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/messagewin.c,v
retrieving revision 1.21
diff -u -r1.21 messagewin.c
--- client/gui-xaw/messagewin.c 2002/06/30 14:37:46     1.21
+++ client/gui-xaw/messagewin.c 2002/07/17 09:42:04
@@ -172,94 +172,6 @@
 }
 
 /**************************************************************************
-...
-**************************************************************************/
-
-static int messages_total = 0; /* current total number of message lines */
-static int messages_alloc = 0; /* number allocated for */
-static char **string_ptrs = NULL;
-static int *xpos = NULL;
-static int *ypos = NULL;
-
-/**************************************************************************
- This makes sure that the next two elements in string_ptrs etc are
- allocated for.  Two = one to be able to grow, and one for the sentinel
- in string_ptrs.
- Note update_meswin_dialog should always be called soon after this since
- it contains pointers to the memory we're reallocing here.
-**************************************************************************/
-static void meswin_allocate(void)
-{
-  int i;
-  
-  if (messages_total+2 > messages_alloc) {
-    messages_alloc = messages_total + 32;
-    string_ptrs = fc_realloc(string_ptrs, messages_alloc*sizeof(char*));
-    xpos = fc_realloc(xpos, messages_alloc*sizeof(int));
-    ypos = fc_realloc(ypos, messages_alloc*sizeof(int));
-    for( i=messages_total; i<messages_alloc; i++ ) {
-      string_ptrs[i] = NULL;
-      xpos[i] = 0;
-      ypos[i] = 0;
-    }
-  }
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void real_clear_notify_window(void)
-{
-  int i;
-  meswin_allocate();
-  for (i = 0; i <messages_total; i++) {
-    free(string_ptrs[i]);
-    string_ptrs[i] = NULL;
-    xpos[i] = 0;
-    ypos[i] = 0;
-  }
-  string_ptrs[0]=0;
-  messages_total = 0;
-  if(meswin_dialog_shell) {
-    XtSetSensitive(meswin_goto_command, FALSE);
-    XtSetSensitive(meswin_popcity_command, FALSE);
-  }
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void real_add_notify_window(struct packet_generic_message *packet)
-{
-  char *s;
-  int nspc;
-  char *game_prefix1 = "Game: ";
-  char *game_prefix2 = _("Game: ");
-  int gp_len1 = strlen(game_prefix1);
-  int gp_len2 = strlen(game_prefix2);
-  
-  meswin_allocate();
-  s = fc_malloc(strlen(packet->message) + 50);
-  if (strncmp(packet->message, game_prefix1, gp_len1) == 0) {
-    strcpy(s, packet->message + gp_len1);
-  } else if(strncmp(packet->message, game_prefix2, gp_len2) == 0) {
-    strcpy(s, packet->message + gp_len2);
-  } else {
-    strcpy(s, packet->message);
-  }
-
-  nspc=50-strlen(s);
-  if(nspc>0)
-    strncat(s, "                                                  ", nspc);
-  
-  xpos[messages_total] = packet->x;
-  ypos[messages_total] = packet->y;
-  string_ptrs[messages_total] = s;
-  messages_total++;
-  string_ptrs[messages_total] = 0;
-}
-
-/**************************************************************************
  This scrolls the messages window down to the bottom.
  NOTE: it seems this must not be called until _after_ meswin_dialog_shell
  is ...? realized, popped up, ... something.
@@ -275,11 +187,12 @@
   
   if (!meswin_dialog_shell)
     return;
-  if (messages_total <= N_MSG_VIEW)
+  if (get_num_messages() <= N_MSG_VIEW) {
     return;
+  }
   
   XtVaGetValues(meswin_list, XtNheight, &height, NULL);
-  pos = (((double)(messages_total-1))/messages_total)*height;
+  pos = (((double) (get_num_messages() - 1)) / get_num_messages()) * height;
   XawViewportSetCoordinates(meswin_viewport, 0, pos);
 }
 
@@ -293,11 +206,22 @@
 
   XawFormDoLayout(meswin_form, False);
 
-  if (messages_total == 0)
+  if (get_num_messages() == 0) {
     XawListChange(meswin_list, dummy_message_list, 1, 0, True);
-  else
-    XawListChange(meswin_list, string_ptrs, messages_total, 0, True);
+  } else {
+    /* strings will not be freed */
+    static char **strings = NULL;
+    int i, num = get_num_messages();
+
+    strings = fc_realloc(strings, num * sizeof(char *));
+
+    for (i = 0; i < num; i++) {
+      strings[i] = get_message(i)->descr;
+    }
 
+    XawListChange(meswin_list, strings, get_num_messages(), 0, True);
+  }
+
   /* Much of the following copied from city_report_dialog_update() */
   XtVaGetValues(meswin_list, XtNlongest, &i, NULL);
   width = i + 10;
@@ -309,19 +233,22 @@
   /* Seems have to do this here so we get the correct height below. */
   XawFormDoLayout(meswin_form, True);
 
-  if (messages_total <= N_MSG_VIEW) {
+  if (get_num_messages() <= N_MSG_VIEW) {
     XtVaGetValues(meswin_list, XtNheight, &height, NULL);
     XtVaSetValues(meswin_viewport, XtNheight, height, NULL);
   } else {
     XtVaGetValues(meswin_list, XtNheight, &height, NULL);
     XtVaGetValues(meswin_list, XtNinternalHeight, &iheight, NULL);
     height -= (iheight * 2);
-    height /= messages_total;
+    height /= get_num_messages();
     height *= N_MSG_VIEW;
     height += (iheight * 2);
     XtVaSetValues(meswin_viewport, XtNheight, height, NULL);
   }
   meswin_scroll_down();
+
+  XtSetSensitive(meswin_goto_command, FALSE);
+  XtSetSensitive(meswin_popcity_command, FALSE);
 }
 
 /**************************************************************************
@@ -330,26 +257,19 @@
 static void meswin_list_callback(Widget w, XtPointer client_data,
                                 XtPointer call_data)
 {
-  XawListReturnStruct *ret;
-  int location_ok = 0;
-  int city_ok = 0;
-
-  ret=XawListShowCurrent(meswin_list);
-
-  if(ret->list_index!=XAW_LIST_NONE) {
-    struct city *pcity;
-    int x, y;
-    x = xpos[ret->list_index];
-    y = ypos[ret->list_index];
-    location_ok = (x != -1 && y != -1);
-    city_ok = (location_ok && (pcity=map_get_city(x,y))
-              && (pcity->owner == game.player_idx));
-  }    
-  XtSetSensitive(meswin_goto_command, location_ok?True:False);
-  XtSetSensitive(meswin_popcity_command, city_ok?True:False);
-}
+  XawListReturnStruct *ret = XawListShowCurrent(meswin_list);
 
+  if (ret->list_index != XAW_LIST_NONE) {
+    struct message *message = get_message(ret->list_index);
 
+    XtSetSensitive(meswin_goto_command, message->location_ok ? True : False);
+    XtSetSensitive(meswin_popcity_command, message->city_ok ? True : False);
+  } else {
+    XtSetSensitive(meswin_goto_command, False);
+    XtSetSensitive(meswin_popcity_command, False);
+  }
+}
+
 /**************************************************************************
 ...
 **************************************************************************/
@@ -374,13 +294,11 @@
 static void meswin_goto_callback(Widget w, XtPointer client_data,
                                 XtPointer call_data)
 {
-  XawListReturnStruct *ret;
-
-  ret=XawListShowCurrent(meswin_list);
+  XawListReturnStruct *ret = XawListShowCurrent(meswin_list);
 
-  if(ret->list_index!=XAW_LIST_NONE
-     && (xpos[ret->list_index]!=-1 && ypos[ret->list_index]!=-1))
-    center_tile_mapcanvas(xpos[ret->list_index], ypos[ret->list_index]);
+  if (ret->list_index != XAW_LIST_NONE) {
+    meswin_goto(ret->list_index);
+  }
 }
 
 /**************************************************************************
@@ -389,20 +307,9 @@
 static void meswin_popcity_callback(Widget w, XtPointer client_data,
                                    XtPointer call_data)
 {
-  XawListReturnStruct *ret;
-  struct city *pcity;
-  int x, y;
-  
-  ret=XawListShowCurrent(meswin_list);
-  if(ret->list_index!=XAW_LIST_NONE) {
-    x = xpos[ret->list_index];
-    y = ypos[ret->list_index];
-    if((x!=-1 && y!=-1) && (pcity=map_get_city(x,y))
-       && (pcity->owner == game.player_idx)) {
-      if (center_when_popup_city) {
-       center_tile_mapcanvas(x,y);
-      }
-      popup_city_dialog(pcity, 0);
-    }
+  XawListReturnStruct *ret = XawListShowCurrent(meswin_list);
+
+  if (ret->list_index != XAW_LIST_NONE) {
+    meswin_popup_city(ret->list_index);
   }
 }
Index: client/include/messagewin_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/messagewin_g.h,v
retrieving revision 1.2
diff -u -r1.2 messagewin_g.h
--- client/include/messagewin_g.h       2002/06/27 00:59:21     1.2
+++ client/include/messagewin_g.h       2002/07/17 09:42:04
@@ -20,7 +20,5 @@
 void popup_meswin_dialog(void);
 bool is_meswin_open(void);
 void real_update_meswin_dialog(void);
-void real_clear_notify_window(void);
-void real_add_notify_window(struct packet_generic_message *packet);
      
 #endif  /* FC__MESSAGEWIN_G_H */

[Prev in Thread] Current Thread [Next in Thread]