From 17b349cb734f3c9ee642e375a9cf5d22d48e10fd Mon Sep 17 00:00:00 2001
From: Dino <macwiz23@comcast.net>
Date: Sun, 4 May 2025 17:33:08 -0400
Subject: [PATCH 29/46] gtk: Fix saving and restoring city dlog size

Minor style corrections by Marko Lindqvist

See RM #1289
---
 client/gui-gtk-3.22/citydlg.c | 18 ++++++++++++------
 client/gui-gtk-4.0/citydlg.c  | 16 ++++++++++------
 client/gui-gtk-5.0/citydlg.c  | 17 ++++++++++-------
 3 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/client/gui-gtk-3.22/citydlg.c b/client/gui-gtk-3.22/citydlg.c
index 6cb8e87f0d..e10e303212 100644
--- a/client/gui-gtk-3.22/citydlg.c
+++ b/client/gui-gtk-3.22/citydlg.c
@@ -3446,7 +3446,7 @@ static void set_cityopt_values(struct city_dialog *pdialog)
 
 /******************** Callbacks for: Close, Prev, Next. ******************/
 /**********************************************************************//**
-  User has clicked rename city-button
+  User has closed city dialog
 **************************************************************************/
 static void close_callback(GtkWidget *w, gpointer data)
 {
@@ -3454,14 +3454,20 @@ static void close_callback(GtkWidget *w, gpointer data)
 }
 
 /**********************************************************************//**
-  User has closed rename city dialog
+  User has closed city dialog
 **************************************************************************/
 static void city_destroy_callback(GtkWidget *w, gpointer data)
 {
   struct city_dialog *pdialog;
+  int width, height;
+  GtkWidget *cont_area;
 
   pdialog = (struct city_dialog *) data;
 
+  cont_area = gtk_dialog_get_content_area(GTK_DIALOG(pdialog->shell));
+  width = gtk_widget_get_allocated_width(GTK_WIDGET(cont_area));
+  height = gtk_widget_get_allocated_height(GTK_WIDGET(cont_area));
+
   gtk_widget_hide(pdialog->shell);
 
   if (game.info.citizen_nationality) {
@@ -3473,12 +3479,12 @@ static void city_destroy_callback(GtkWidget *w, gpointer data)
   /* Save size of the city dialog. */
   GUI_GTK_OPTION(citydlg_xsize)
     = CLIP(GUI_GTK3_22_CITYDLG_MIN_XSIZE,
-           gtk_widget_get_allocated_width(pdialog->shell),
+           width,
            GUI_GTK3_22_CITYDLG_MAX_XSIZE);
   GUI_GTK_OPTION(citydlg_ysize)
-    = CLIP(GUI_GTK3_22_CITYDLG_MIN_XSIZE,
-           gtk_widget_get_allocated_height(pdialog->shell),
-           GUI_GTK3_22_CITYDLG_MAX_XSIZE);
+    = CLIP(GUI_GTK3_22_CITYDLG_MIN_YSIZE,
+           height,
+           GUI_GTK3_22_CITYDLG_MAX_YSIZE);
 
   last_page
     = gtk_notebook_get_current_page(GTK_NOTEBOOK(pdialog->notebook));
diff --git a/client/gui-gtk-4.0/citydlg.c b/client/gui-gtk-4.0/citydlg.c
index 486e8ea39b..a3027dfd64 100644
--- a/client/gui-gtk-4.0/citydlg.c
+++ b/client/gui-gtk-4.0/citydlg.c
@@ -3563,7 +3563,7 @@ static void set_cityopt_values(struct city_dialog *pdialog)
 /******************** Callbacks for: Close, Prev, Next. *******************/
 
 /***********************************************************************//**
-  User has clicked rename city-button
+  User has closed city dialog
 ***************************************************************************/
 static void close_callback(GtkWidget *w, gpointer data)
 {
@@ -3571,11 +3571,15 @@ static void close_callback(GtkWidget *w, gpointer data)
 }
 
 /***********************************************************************//**
-  User has closed rename city dialog
+  User has closed city dialog
 ***************************************************************************/
 static void city_destroy_callback(GtkWidget *w, gpointer data)
 {
   struct city_dialog *pdialog;
+  int width, height;
+
+  /* Save size of the city dialog. */
+  gtk_window_get_default_size(GTK_WINDOW(w), &width, &height);
 
   pdialog = (struct city_dialog *) data;
 
@@ -3590,12 +3594,12 @@ static void city_destroy_callback(GtkWidget *w, gpointer data)
   /* Save size of the city dialog. */
   GUI_GTK_OPTION(citydlg_xsize)
     = CLIP(GUI_GTK4_CITYDLG_MIN_XSIZE,
-           gtk_widget_get_allocated_width(pdialog->shell),
+           width,
            GUI_GTK4_CITYDLG_MAX_XSIZE);
   GUI_GTK_OPTION(citydlg_ysize)
-    = CLIP(GUI_GTK4_CITYDLG_MIN_XSIZE,
-           gtk_widget_get_allocated_height(pdialog->shell),
-           GUI_GTK4_CITYDLG_MAX_XSIZE);
+    = CLIP(GUI_GTK4_CITYDLG_MIN_YSIZE,
+           height,
+           GUI_GTK4_CITYDLG_MAX_YSIZE);
 
   last_page
     = gtk_notebook_get_current_page(GTK_NOTEBOOK(pdialog->notebook));
diff --git a/client/gui-gtk-5.0/citydlg.c b/client/gui-gtk-5.0/citydlg.c
index b740de9de2..a319355eb7 100644
--- a/client/gui-gtk-5.0/citydlg.c
+++ b/client/gui-gtk-5.0/citydlg.c
@@ -3839,7 +3839,7 @@ static void set_cityopt_values(struct city_dialog *pdialog)
 /******************** Callbacks for: Close, Prev, Next. *******************/
 
 /***********************************************************************//**
-  User has clicked rename city-button
+  User has closed city dialog
 ***************************************************************************/
 static void close_callback(GtkWidget *w, gpointer data)
 {
@@ -3847,14 +3847,17 @@ static void close_callback(GtkWidget *w, gpointer data)
 }
 
 /***********************************************************************//**
-  User has closed rename city dialog
+  User has closed city dialog
 ***************************************************************************/
 static void city_destroy_callback(GtkWidget *w, gpointer data)
 {
   struct city_dialog *pdialog;
+  int width, height;
 
-  pdialog = (struct city_dialog *) data;
+  /* Save size of the city dialog. */
+  gtk_window_get_default_size(GTK_WINDOW(w), &width, &height);
 
+  pdialog = (struct city_dialog *) data;
   gtk_widget_set_visible(pdialog->shell, FALSE);
 
   if (game.info.citizen_nationality) {
@@ -3866,12 +3869,12 @@ static void city_destroy_callback(GtkWidget *w, gpointer data)
   /* Save size of the city dialog. */
   GUI_GTK_OPTION(citydlg_xsize)
     = CLIP(GUI_GTK5_CITYDLG_MIN_XSIZE,
-           gtk_widget_get_allocated_width(pdialog->shell),
+           width,
            GUI_GTK5_CITYDLG_MAX_XSIZE);
   GUI_GTK_OPTION(citydlg_ysize)
-    = CLIP(GUI_GTK5_CITYDLG_MIN_XSIZE,
-           gtk_widget_get_allocated_height(pdialog->shell),
-           GUI_GTK5_CITYDLG_MAX_XSIZE);
+    = CLIP(GUI_GTK5_CITYDLG_MIN_YSIZE,
+           height,
+           GUI_GTK5_CITYDLG_MAX_YSIZE);
 
   last_page
     = gtk_notebook_get_current_page(GTK_NOTEBOOK(pdialog->notebook));
-- 
2.47.2

