[PATCH] Added support for a scrollable area in the dive info dialog

Lubomir I. Ivanov neolit123 at gmail.com
Thu Feb 28 16:03:23 PST 2013


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

This patch puts the contents of the dive edit dialog inside
a scroll container, with a minimal size equal to the default dialog
size when no equipment is added. If more tanks and weights entries
are added, a scrollbar will appear on the right and the dialog
will become scrollable.

Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---

There is an #if GTK_CHECK_VERSION(3,0,0) branch in there, due to the fact
that gtk_widget_size_request() appears to be deprecated for version 3 and
a new function is used. Untested for GTK3 as I don't have a setup for it.

One strange thing I've noticed on Windows is that the dialog now
appears slightly more towards the bottom of the screen.

---
 info.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/info.c b/info.c
index 1a04563..425194e 100644
--- a/info.c
+++ b/info.c
@@ -1046,11 +1046,15 @@ static void update_time_depth(struct dive *dive, struct dive *edited)
 int edit_multi_dive_info(struct dive *single_dive)
 {
 	int success;
-	GtkWidget *dialog, *vbox;
+	GtkWidget *dialog, *vbox, *scrolled_window, *viewport;
+	GtkRequisition size;
 	struct dive_info info;
 	struct dive *master;
 	gboolean multi;
 
+	scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
+		GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
 	dialog = gtk_dialog_new_with_buttons(_("Dive Info"),
 		GTK_WINDOW(main_window),
 		GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -1059,6 +1063,9 @@ int edit_multi_dive_info(struct dive *single_dive)
 		NULL);
 
 	vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+	gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
+	vbox = g_object_new(GTK_TYPE_VBOX, NULL);
+	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), vbox);
 	master = single_dive;
 	if (!master)
 		master = current_dive;
@@ -1084,9 +1091,17 @@ int edit_multi_dive_info(struct dive *single_dive)
 	memcpy(&edit_dive, master, sizeof(struct dive));
 
 	dive_info_widget(vbox, &edit_dive, &info, multi);
-	show_dive_equipment(&edit_dive, W_IDX_SECONDARY);
 	save_equipment_data(&edit_dive);
 	gtk_widget_show_all(dialog);
+	viewport = gtk_widget_get_ancestor(vbox, GTK_TYPE_VIEWPORT);
+#if GTK_CHECK_VERSION(3,0,0)
+	gtk_widget_get_preferred_size(viewport, NULL, &size);
+#else
+	gtk_widget_size_request(viewport, &size);
+#endif
+	gtk_widget_set_size_request(scrolled_window, size.width, size.height);
+	/* add the equipment post the "blank" layout estimate */
+	show_dive_equipment(&edit_dive, W_IDX_SECONDARY);
 	success = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT;
 	if (success) {
 		mark_divelist_changed(TRUE);
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list