From 30c5551caa87a95fcbe75dd9df654ffd8464f305 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Mon, 31 Dec 2001 04:41:50 +0000 Subject: Add preferences to save the main window size and position. If enabled, the geometry is saved at exit. Should we save the main window pane sizes as well? Move the DEF_WIDTH and DEF_HEIGHT #defines from gtk/main.h to prefs.h. Remove the reference to DEF_WIDTH from proto_hier_stats_dlg.c. svn path=/trunk/; revision=4462 --- gtk/gui_prefs.c | 81 ++++++++++++++++++++++++++++++--------- gtk/main.c | 94 ++++++++++++++++++++++++++++++++++++++++++++-- gtk/main.h | 4 +- gtk/proto_hier_stats_dlg.c | 7 +--- 4 files changed, 158 insertions(+), 28 deletions(-) (limited to 'gtk') diff --git a/gtk/gui_prefs.c b/gtk/gui_prefs.c index 828e0ae7dc..555acc8f15 100644 --- a/gtk/gui_prefs.c +++ b/gtk/gui_prefs.c @@ -1,7 +1,7 @@ /* gui_prefs.c * Dialog box for GUI preferences * - * $Id: gui_prefs.c,v 1.26 2001/04/17 18:49:55 guy Exp $ + * $Id: gui_prefs.c,v 1.27 2001/12/31 04:41:50 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -49,6 +49,9 @@ static void create_option_menu(GtkWidget *main_vb, const gchar *key, GtkWidget *main_tb, int table_position, const gchar *label_text, const enum_val_t *enumvals, gint current_val); +static void create_option_check_button(GtkWidget *main_vb, const gchar *key, + GtkWidget *main_tb, int table_position, const gchar *label_text, + gboolean active); static void font_browse_cb(GtkWidget *w, gpointer data); static void font_browse_ok_cb(GtkWidget *w, GtkFontSelectionDialog *fs); static void font_browse_destroy(GtkWidget *win, gpointer data); @@ -68,6 +71,8 @@ static void fetch_colors(void); #define PTREE_LINE_STYLE_KEY "ptree_line_style" #define PTREE_EXPANDER_STYLE_KEY "ptree_expander_style" #define HEX_DUMP_HIGHLIGHT_STYLE_KEY "hex_dump_highlight_style" +#define GEOMETRY_POSITION_KEY "geometry_position" +#define GEOMETRY_SIZE_KEY "geometry_size" #define FONT_DIALOG_PTR_KEY "font_dialog_ptr" #define FONT_CALLER_PTR_KEY "font_caller_ptr" @@ -126,10 +131,12 @@ static gboolean font_changed; has been set to the name of the font the user selected. */ static gchar *new_font_name; +#define GUI_TABLE_ROWS 8 GtkWidget* gui_prefs_show(void) { - GtkWidget *main_tb, *main_vb, *font_bt, *color_bt; + GtkWidget *main_tb, *main_vb, *hbox, *font_bt, *color_bt; + GtkWidget *geom_cb; /* The colors or font haven't been changed yet. */ colors_changed = FALSE; @@ -139,53 +146,66 @@ gui_prefs_show(void) main_vb = gtk_vbox_new(FALSE, 7); gtk_container_border_width( GTK_CONTAINER(main_vb), 5 ); + /* Main horizontal box */ + /* XXX - Is therea a better way to center the table? */ + hbox = gtk_hbox_new(FALSE, 7); + gtk_box_pack_start (GTK_BOX(main_vb), hbox, TRUE, FALSE, 0); + /* Main table */ - main_tb = gtk_table_new(7, 2, FALSE); - gtk_box_pack_start( GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0 ); + main_tb = gtk_table_new(GUI_TABLE_ROWS, 3, FALSE); + gtk_box_pack_start( GTK_BOX(hbox), main_tb, TRUE, FALSE, 0 ); gtk_table_set_row_spacings( GTK_TABLE(main_tb), 10 ); gtk_table_set_col_spacings( GTK_TABLE(main_tb), 15 ); + gtk_table_set_col_spacing( GTK_TABLE(main_tb), 1, 50 ); /* Scrollbar placement */ create_option_menu(main_vb, SCROLLBAR_PLACEMENT_KEY, main_tb, 0, - "Vertical Scrollbar Placement:", scrollbar_placement_vals, + "Vertical scrollbar placement:", scrollbar_placement_vals, prefs.gui_scrollbar_on_right); /* Packet list selection browseable */ create_option_menu(main_vb, PLIST_SEL_BROWSE_KEY, main_tb, 1, - "Packet-list selection bar movement:", selection_mode_vals, + "Packet list mouse behavior:", selection_mode_vals, prefs.gui_plist_sel_browse); /* Proto tree selection browseable */ create_option_menu(main_vb, PTREE_SEL_BROWSE_KEY, main_tb, 2, - "Protocol-tree selection bar movement:", selection_mode_vals, + "Protocol tree mouse behavior:", selection_mode_vals, prefs.gui_ptree_sel_browse); /* Proto tree line style */ create_option_menu(main_vb, PTREE_LINE_STYLE_KEY, main_tb, 3, - "Protocol-tree line style:", line_style_vals, + "Protocol tree line style:", line_style_vals, prefs.gui_ptree_line_style); /* Proto tree expander style */ create_option_menu(main_vb, PTREE_EXPANDER_STYLE_KEY, main_tb, 4, - "Protocol-tree expander style:", expander_style_vals, + "Protocol tree expander style:", expander_style_vals, prefs.gui_ptree_expander_style); /* Hex Dump highlight style */ create_option_menu(main_vb, HEX_DUMP_HIGHLIGHT_STYLE_KEY, main_tb, 5, - "Hex dump highlight style:", highlight_style_vals, + "Hex display highlight style:", highlight_style_vals, prefs.gui_hex_dump_highlight_style); - + + /* Geometry prefs */ + create_option_check_button(main_vb, GEOMETRY_POSITION_KEY, main_tb, + 6, "Save window position:", prefs.gui_geometry_save_position); + + create_option_check_button(main_vb, GEOMETRY_SIZE_KEY, main_tb, + 7, "Save window size:", prefs.gui_geometry_save_size); + /* "Font..." button - click to open a font selection dialog box. */ font_bt = gtk_button_new_with_label("Font..."); gtk_signal_connect(GTK_OBJECT(font_bt), "clicked", GTK_SIGNAL_FUNC(font_browse_cb), NULL); - gtk_table_attach_defaults( GTK_TABLE(main_tb), font_bt, 1, 2, 6, 7 ); + gtk_table_attach_defaults( GTK_TABLE(main_tb), font_bt, 2, 3, 0, 1 ); /* "Colors..." button - click to open a color selection dialog box. */ color_bt = gtk_button_new_with_label("Colors..."); gtk_signal_connect(GTK_OBJECT(color_bt), "clicked", GTK_SIGNAL_FUNC(color_browse_cb), NULL); - gtk_table_attach_defaults( GTK_TABLE(main_tb), color_bt, 1, 2, 7, 8 ); + gtk_table_attach_defaults( GTK_TABLE(main_tb), color_bt, 2, 3, 1, 2 ); /* Show 'em what we got */ gtk_widget_show_all(main_vb); @@ -198,7 +218,7 @@ create_option_menu(GtkWidget *main_vb, const gchar *key, GtkWidget *main_tb, int table_position, const gchar *label_text, const enum_val_t *enumvals, gint current_val) { - GtkWidget *label, *menu, *menu_item, *option_menu; + GtkWidget *label, *menu_box, *menu, *menu_item, *option_menu; int menu_index, index; const enum_val_t *enum_valp; @@ -206,6 +226,9 @@ create_option_menu(GtkWidget *main_vb, const gchar *key, gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5); gtk_table_attach_defaults(GTK_TABLE(main_tb), label, 0, 1, table_position, table_position + 1); + menu_box = gtk_hbox_new(FALSE, 0); + gtk_table_attach_defaults(GTK_TABLE(main_tb), menu_box, + 1, 2, table_position, table_position + 1); /* Create a menu from the enumvals */ menu = gtk_menu_new(); @@ -228,12 +251,30 @@ create_option_menu(GtkWidget *main_vb, const gchar *key, gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), menu_index); - gtk_table_attach_defaults(GTK_TABLE(main_tb), option_menu, - 1, 2, table_position, table_position + 1); - + gtk_box_pack_start(GTK_BOX(menu_box), option_menu, FALSE, FALSE, 0); gtk_object_set_data(GTK_OBJECT(main_vb), key, option_menu); } +static void +create_option_check_button(GtkWidget *main_vb, const gchar *key, + GtkWidget *main_tb, int table_position, const gchar *label_text, + gboolean active) +{ + GtkWidget *hbox, *check_box; + int menu_index, index; + const enum_val_t *enum_valp; + + hbox = gtk_hbox_new(FALSE, 0); + gtk_table_attach_defaults(GTK_TABLE(main_tb), hbox, 1, 3, + table_position, table_position + 1); + + check_box = gtk_check_button_new_with_label(label_text); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), active); + + gtk_box_pack_start( GTK_BOX(hbox), check_box, FALSE, FALSE, 0 ); + gtk_object_set_data(GTK_OBJECT(main_vb), key, check_box); +} + /* Create a font dialog for browsing. */ static void font_browse_cb(GtkWidget *w, gpointer data) @@ -426,6 +467,12 @@ gui_prefs_fetch(GtkWidget *w) prefs.gui_hex_dump_highlight_style = fetch_enum_value( gtk_object_get_data(GTK_OBJECT(w), HEX_DUMP_HIGHLIGHT_STYLE_KEY), highlight_style_vals); + prefs.gui_geometry_save_position = + gtk_toggle_button_get_active(gtk_object_get_data(GTK_OBJECT(w), + GEOMETRY_POSITION_KEY)); + prefs.gui_geometry_save_size = + gtk_toggle_button_get_active(gtk_object_get_data(GTK_OBJECT(w), + GEOMETRY_SIZE_KEY)); if (font_changed) { if (prefs.gui_font_name != NULL) diff --git a/gtk/main.c b/gtk/main.c index 4dcc21a8e5..b8ab021e86 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1,6 +1,6 @@ /* main.c * - * $Id: main.c,v 1.221 2001/12/21 20:33:47 guy Exp $ + * $Id: main.c,v 1.222 2001/12/31 04:41:50 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -172,6 +172,7 @@ static guint main_ctx, file_ctx, help_ctx; static GString *comp_info_str; gchar *ethereal_path = NULL; gchar *last_open_dir = NULL; +gint root_x = G_MAXINT, root_y = G_MAXINT, top_width, top_height; ts_type timestamp_type = RELATIVE; @@ -735,6 +736,21 @@ statusbar_pop_field_msg(void) static gboolean main_window_delete_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data) { + gint desk_x, desk_y; + + /* Try to grab our geometry */ + gdk_window_get_root_origin(top_level->window, &root_x, &root_y); + if (gdk_window_get_deskrelative_origin(top_level->window, + &desk_x, &desk_y)) { + if (desk_x <= root_x && desk_y <= root_y) { + root_x = desk_x; + root_y = desk_y; + } + } + + /* XXX - Is this the "approved" method? */ + gdk_window_get_size(top_level->window, &top_width, &top_height); + file_quit_cmd_cb(widget, data); /* Say that the window should be deleted. */ @@ -941,6 +957,9 @@ main(int argc, char *argv[]) e_prefs *prefs; char badopt; char *bold_font_name; + gint desk_x, desk_y; + gboolean prefs_write_needed = FALSE; + ethereal_path = argv[0]; @@ -1638,6 +1657,66 @@ main(int argc, char *argv[]) gtk_main(); + /* Try to save our geometry. GTK+ provides two routines to get a + window's position relative to the X root window. If I understand the + documentation correctly, gdk_window_get_deskrelative_origin applies + mainly to Enlightenment and gdk_window_get_root_origin applies for + all other WMs. + + The code below tries both routines, and picks the one that returns + the upper-left-most coordinates. + + More info at: + + http://mail.gnome.org/archives/gtk-devel-list/2001-March/msg00289.html + http://www.gtk.org/faq/#AEN600 */ + + /* Re-read our saved preferences. */ + /* XXX - Move all of this into a separate function? */ + prefs = read_prefs(&gpf_open_errno, &gpf_path, &pf_open_errno, &pf_path); + + if (pf_path == NULL) { + if (prefs->gui_geometry_save_position) { + if (top_level->window != NULL) { + gdk_window_get_root_origin(top_level->window, &root_x, &root_y); + if (gdk_window_get_deskrelative_origin(top_level->window, + &desk_x, &desk_y)) { + if (desk_x <= root_x && desk_y <= root_y) { + root_x = desk_x; + root_y = desk_y; + } + } + } + if (prefs->gui_geometry_main_x != root_x) { + prefs->gui_geometry_main_x = root_x; + prefs_write_needed = TRUE; + } + if (prefs->gui_geometry_main_y != root_y) { + prefs->gui_geometry_main_y = root_y; + prefs_write_needed = TRUE; + } + } + + if (prefs->gui_geometry_save_size) { + if (top_level->window != NULL) { + /* XXX - Is this the "approved" method? */ + gdk_window_get_size(top_level->window, &top_width, &top_height); + } + if (prefs->gui_geometry_main_width != top_width) { + prefs->gui_geometry_main_width = top_width; + prefs_write_needed = TRUE; + } + if (prefs->gui_geometry_main_height != top_height) { + prefs->gui_geometry_main_height = top_height; + prefs_write_needed = TRUE; + } + } + + if (prefs_write_needed) { + write_prefs(&pf_path); + } + } + epan_cleanup(); g_free(rc_file); @@ -1821,7 +1900,7 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs) TRUE, TRUE }; - + /* Main window */ top_level = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_set_name(top_level, "main window"); @@ -1830,7 +1909,16 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs) gtk_signal_connect (GTK_OBJECT (top_level), "realize", GTK_SIGNAL_FUNC (window_icon_realize_cb), NULL); gtk_window_set_title(GTK_WINDOW(top_level), "The Ethereal Network Analyzer"); - gtk_widget_set_usize(GTK_WIDGET(top_level), DEF_WIDTH, -1); + if (prefs->gui_geometry_save_position) { + gtk_widget_set_uposition(GTK_WIDGET(top_level), + prefs->gui_geometry_main_x, prefs->gui_geometry_main_y); + } + if (prefs->gui_geometry_save_size) { + gtk_widget_set_usize(GTK_WIDGET(top_level), + prefs->gui_geometry_main_width, prefs->gui_geometry_main_height); + } else { + gtk_widget_set_usize(GTK_WIDGET(top_level), DEF_WIDTH, -1); + } gtk_window_set_policy(GTK_WINDOW(top_level), TRUE, TRUE, FALSE); /* Container for menu bar, paned windows and progress/info box */ diff --git a/gtk/main.h b/gtk/main.h index ef884a11f0..65662d3bd0 100644 --- a/gtk/main.h +++ b/gtk/main.h @@ -1,7 +1,7 @@ /* main.h * Global defines, etc. * - * $Id: main.h,v 1.24 2001/11/21 23:16:26 gram Exp $ + * $Id: main.h,v 1.25 2001/12/31 04:41:50 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -37,8 +37,6 @@ */ #define RC_FILE "gtkrc" -#define DEF_WIDTH 750 -#define DEF_HEIGHT 550 #ifdef HAVE_LIBPCAP #define DEF_READY_MESSAGE " Ready to load or capture" #else diff --git a/gtk/proto_hier_stats_dlg.c b/gtk/proto_hier_stats_dlg.c index da0a18e8b7..1bc3163ade 100644 --- a/gtk/proto_hier_stats_dlg.c +++ b/gtk/proto_hier_stats_dlg.c @@ -1,6 +1,6 @@ /* proto_hier_stats_dlg.c * - * $Id: proto_hier_stats_dlg.c,v 1.5 2001/12/12 21:38:59 gerald Exp $ + * $Id: proto_hier_stats_dlg.c,v 1.6 2001/12/31 04:41:50 gerald Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -157,11 +157,8 @@ create_tree(GtkWidget *container, ph_stats_t *ps) /* Fill in the data. */ fill_in_ctree(tree, ps); - /* Try to size the CTree to a good initial size. - * 5 is a magic number that I pulled out off my hat. - * Using DEF_WIDTH is pretty bogus, too. */ height = GTK_CLIST(tree)->rows * (GTK_CLIST(tree)->row_height + 5); - gtk_widget_set_usize(tree, DEF_WIDTH, height); + gtk_widget_set_usize(tree, 500, height); gtk_container_add(GTK_CONTAINER(sw), tree); -- cgit v1.2.3