Save the size and position of the expert info dialog
authorChris Maynard <Christopher.Maynard@GTECH.COM>
Thu, 19 Jun 2014 19:40:11 +0000 (12:40 -0700)
committerBalint Reczey <balint@balintreczey.hu>
Thu, 19 Jun 2014 22:21:05 +0000 (22:21 +0000)
Set initialize position to center on parent

bug: 3817
Change-Id: Iad48aa762d892908d50f742606160c8305084f48
Reviewed-on: https://code.wireshark.org/review/2459
Reviewed-by: Balint Reczey <balint@balintreczey.hu>
Tested-by: Balint Reczey <balint@balintreczey.hu>
ui/gtk/dlg_utils.c
ui/gtk/dlg_utils.h
ui/gtk/expert_comp_dlg.c
ui/gtk/gui_utils.c
ui/gtk/gui_utils.h
ui/gtk/mac_lte_stat_dlg.c
ui/gtk/rlc_lte_stat_dlg.c
ui/gtk/stats_tree_stat.c
ui/gtk/tap_param_dlg.c
ui/gtk/wlan_stat_dlg.c

index 36fb2c90eabcb66d4c211e5cb3c65d3735f07db5..28a2875a8131f7bc2c532c0b9fc3a8fc86358890 100644 (file)
@@ -471,6 +471,42 @@ dlg_window_new(const gchar *title)
     return win;
 }
 
+/* Create a dialog box window that belongs to Wireshark's main window. */
+GtkWidget *
+dlg_window_new_with_geom(const gchar *title, const gchar *geom_name, GtkWindowPosition pos)
+{
+    GtkWidget *win;
+
+    win = window_new_with_geom(GTK_WINDOW_TOPLEVEL, title, geom_name ? geom_name : title, pos);
+
+    /*
+     * XXX - if we're running in the capture child process, we can't easily
+     * make this window transient for the main process's window.  We just
+     * punt here.
+     *
+     * Perhaps the child process should only capture packets, write them to
+     * a file, and somehow notify the parent process and let *it* do all
+     * the GUI work.  If we can do that efficiently (so that we don't drop
+     * more packets), perhaps we can also do so even when we're *not* doing
+     * an "Update list of packets in real time" capture.  That'd let the
+     * child process run set-UID on platforms where you need that in order
+     * to capture, and might also simplify the job of having the GUI main
+     * loop wait both for user input and packet arrival.
+     */
+    /*
+     * On Windows, making the dialogs transient to top_level behaves strangely.
+     * It is not possible any more to bring the top level window to front easily.
+     * So we don't do this on Windows.
+     */
+#ifndef _WIN32
+    if (top_level) {
+        gtk_window_set_transient_for(GTK_WINDOW(win), GTK_WINDOW(top_level));
+    }
+#endif /*_WIN32*/
+
+    return win;
+}
+
 /* Create a configuration dialog box window that belongs to Wireshark's
  * main window and add the name of the current profile name to its title bar
  */
index 878a55625feab176926c1dea86ee8d02b02f0c0f..bf5231ede2aba6c9fc93a5962e72060ccc1548b3 100644 (file)
  */
 extern GtkWidget *dlg_window_new(const gchar *title);
 
+/** Create a dialog box window that belongs to Wireshark's main window.
+ * If you want to create a window, use window_new_with_geom() instead.
+ * See window_new_with_geom() for general window usage.
+ *
+ * @param title the title for the new dialog
+ * @param geom_name A unique name for the geometry of this new dialog
+ * @parm pos the initial position of the window if a previously saved geometry was not saved or found.
+ *     If the initial position does not matter, specify GTK_WIN_POS_NONE.
+ * @return the newly created dialog
+ */
+extern GtkWidget *
+dlg_window_new_with_geom(const gchar *title, const gchar *geom_name, GtkWindowPosition pos);
+
 /** Create a configuration dialog box window that belongs to Wireshark's
  * main window and add the name of the current profile name to its title bar
  * If you want to create a window, use window_new() instead.
index bbce45f8341e720f6b75b51e930ee3df4f141f95..c604709a53e99d16f753163f6828834819c79225 100644 (file)
@@ -781,7 +781,8 @@ expert_comp_init(const char *opt_arg _U_, void* userdata _U_)
     ss->warn_events = 0;
     ss->error_events = 0;
 
-    expert_comp_dlg_w = ss->win=dlg_window_new("err");  /* transient_for top_level */
+    expert_comp_dlg_w = ss->win = dlg_window_new_with_geom("Expert Info",
+        NULL, GTK_WIN_POS_CENTER_ON_PARENT);  /* transient_for top_level */
     gtk_window_set_destroy_with_parent (GTK_WINDOW(ss->win), TRUE);
     gtk_window_set_default_size(GTK_WINDOW(ss->win), 700, 300);
 
index 62607ca43089abb28f98933d32d310729ae24729..5d72960f3d47c3f5b3506182b37fd13fe0e37f1a 100644 (file)
@@ -186,7 +186,8 @@ window_new(GtkWindowType  type,
 GtkWidget *
 window_new_with_geom(GtkWindowType  type,
                      const gchar   *title,
-                     const gchar   *geom_name)
+                     const gchar   *geom_name,
+                     GtkWindowPosition pos)
 {
     window_geometry_t geom;
     GtkWidget *win = window_new(type, title);
@@ -203,6 +204,17 @@ window_new_with_geom(GtkWindowType  type,
             geom.set_size       = TRUE;
             geom.set_maximized  = FALSE;  /* don't maximize until window is shown */
             window_set_geometry(win, &geom);
+        } else if (pos != GTK_WIN_POS_NONE) {
+#ifdef _WIN32
+            /* Testing using GTK+ 2.24.10 shows that
+             * GTK_WIN_POS_CENTER_ON_PARENT doesn't seem to work on Windows, so
+             * use the next best thing.  Is this a problem for all OS's though,
+             * or just Windows?  Unknown. (Tested with Windows XP SP3 32-bit)
+             */
+            if (pos == GTK_WIN_POS_CENTER_ON_PARENT)
+                pos = GTK_WIN_POS_CENTER;
+#endif
+            gtk_window_set_position(GTK_WINDOW(win), pos);
         }
     }
 
index e9174239cd4a0e522621f4817c1003bedabb6a20..68624cb835f06fee6ac243fb8cf3e06321cd5438 100644 (file)
@@ -109,9 +109,11 @@ extern GtkWidget *window_new(GtkWindowType type, const gchar *title);
  * @param type window type, typical GTK_WINDOW_TOPLEVEL
  * @param title the title for the new window
  * @param geom_name the name to distinguish this window; will also be used for the recent file (don't use special chars)
+ * @parm pos the initial position of the window if a previously saved geometry was not saved or found.
+ *     If the initial position does not matter, specify GTK_WIN_POS_NONE.
  * @return the newly created window
  */
-extern GtkWidget *window_new_with_geom(GtkWindowType type, const gchar *title, const gchar *geom_name);
+extern GtkWidget *window_new_with_geom(GtkWindowType type, const gchar *title, const gchar *geom_name, GtkWindowPosition pos);
 
 /** Create a new splash window, with no icon or title bar.
  *
index a9a8785cbb99483679a6c2ff60390fa6642cd79c..0e9afd504abfb303224b4cd15fed56e44ae3339b 100644 (file)
@@ -1068,7 +1068,7 @@ static void gtk_mac_lte_stat_init(const char *opt_arg, void *userdata _U_)
     g_free(display_name);
 
     /* Create top-level window */
-    hs->mac_lte_stat_dlg_w = window_new_with_geom(GTK_WINDOW_TOPLEVEL, title, "LTE MAC Statistics");
+    hs->mac_lte_stat_dlg_w = window_new_with_geom(GTK_WINDOW_TOPLEVEL, title, "LTE MAC Statistics", GTK_WIN_POS_CENTER_ON_PARENT);
 
     /* Window size */
     gtk_window_set_default_size(GTK_WINDOW(hs->mac_lte_stat_dlg_w), 750, 300);
index 5e277e0dd3b2352f266be013daeb6719ace1d10f..87716a6e56e4f7b0dd43622798433d7a2b870978 100644 (file)
@@ -1316,7 +1316,7 @@ static void gtk_rlc_lte_stat_init(const char *opt_arg, void *userdata _U_)
     g_snprintf(title, sizeof(title), "Wireshark: LTE RLC Statistics: %s",
                display_name);
     g_free(display_name);
-    hs->dlg_w = window_new_with_geom(GTK_WINDOW_TOPLEVEL, title, "LTE RLC Statistics");
+    hs->dlg_w = window_new_with_geom(GTK_WINDOW_TOPLEVEL, title, "LTE RLC Statistics", GTK_WIN_POS_CENTER_ON_PARENT);
 
     /* Window size */
     gtk_window_set_default_size(GTK_WINDOW(hs->dlg_w), 600, 300);
index 76681f4760cdc771632c017dca7e453853b23997..73e1afdb98accefe9991023beb413a268eae532e 100644 (file)
@@ -451,7 +451,7 @@ init_gtk_tree(const char* opt_arg, void *userdata _U_)
 
        window_name = g_strdup_printf("%s Stats Tree", st->display_name);
 
-       st->pr->win = window_new_with_geom(GTK_WINDOW_TOPLEVEL,window_name,window_name);
+       st->pr->win = window_new_with_geom(GTK_WINDOW_TOPLEVEL, window_name, NULL, GTK_WIN_POS_CENTER_ON_PARENT);
        gtk_window_set_default_size(GTK_WINDOW(st->pr->win), st->num_columns*80+80, 400);
        g_free(window_name);
 
index 5c43af8a00a83a4444e533d15f8018db2579c459..dc07ac6abc5d6d05dfe14a2ffa75af8efd4c392b 100644 (file)
@@ -247,7 +247,7 @@ tap_param_dlg_cb(GtkAction *action _U_, gpointer data)
     title = g_strdup_printf("Wireshark: %s: %s", current_dlg->cont.win_title , display_name);
     g_free(display_name);
 
-    current_dlg->dlg=dlg_window_new(title);
+    current_dlg->dlg=dlg_window_new_with_geom(title, current_dlg->cont.win_title, GTK_WIN_POS_CENTER_ON_PARENT);
     gtk_window_set_default_size(GTK_WINDOW(current_dlg->dlg), 300, -1);
     g_free(title);
 
index 7f0d4f04385332fe5705a6aa1e425261065c479e..65b969e0da92551e6a9d0fd1f72cf8a335216ecd 100644 (file)
@@ -1753,12 +1753,12 @@ wlanstat_dlg_create (void)
     hs->use_dfilter        = FALSE;
     hs->show_only_existing = FALSE;
 
-    display_name = cf_get_display_name(&cfile);
-    g_snprintf (title, sizeof(title), "Wireshark: WLAN Traffic Statistics: %s",
-            display_name);
-    g_free(display_name);
-    wlanstat_dlg_w = window_new_with_geom (GTK_WINDOW_TOPLEVEL, title, "WLAN Statistics");
-    gtk_window_set_default_size (GTK_WINDOW(wlanstat_dlg_w), 750, 400);
+       display_name = cf_get_display_name(&cfile);
+       g_snprintf (title, sizeof(title), "Wireshark: WLAN Traffic Statistics: %s",
+                   display_name);
+       g_free(display_name);
+       wlanstat_dlg_w = window_new_with_geom (GTK_WINDOW_TOPLEVEL, title, "WLAN Statistics", GTK_WIN_POS_CENTER_ON_PARENT);
+       gtk_window_set_default_size (GTK_WINDOW(wlanstat_dlg_w), 750, 400);
 
     vbox=ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
     gtk_container_add(GTK_CONTAINER(wlanstat_dlg_w), vbox);