[gtksourceview/gtksourcecompletion] Fixed sizing and placement problems for info window



commit 8beb65508f99bbf92495d3961ce5d5fdbf343794
Author: Jesse van den Kieboom <jesse icecrew nl>
Date:   Sun Apr 26 10:41:20 2009 +0200

    Fixed sizing and placement problems for info window
---
 gtksourceview/gtksourcecompletion.c     |   41 ++++++++++++++++++++++--------
 gtksourceview/gtksourcecompletioninfo.c |   39 ++++++++++++++++-------------
 gtksourceview/gtksourcecompletioninfo.h |    2 +
 3 files changed, 53 insertions(+), 29 deletions(-)

diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 1c87504..fad064d 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -753,8 +753,11 @@ update_proposal_info_real (GtkSourceCompletion         *completion,
 	GtkWidget *info_widget;
 	const gchar *text;
 	gboolean prov_update_info = FALSE;
+	GtkSourceCompletionInfo *info_window;
 	
-	gtk_source_completion_info_set_sizing (GTK_SOURCE_COMPLETION_INFO (completion->priv->info_window),
+	info_window = GTK_SOURCE_COMPLETION_INFO (completion->priv->info_window);
+	
+	gtk_source_completion_info_set_sizing (info_window,
 	                                       -1, -1, TRUE, TRUE);
 
 	if (proposal == NULL)
@@ -782,15 +785,17 @@ update_proposal_info_real (GtkSourceCompletion         *completion,
 		}
 	}
 	
-	gtk_source_completion_info_set_widget (GTK_SOURCE_COMPLETION_INFO (completion->priv->info_window),
+	gtk_source_completion_info_set_widget (info_window,
 	                                       info_widget);
 
 	if (prov_update_info)
 	{
 		gtk_source_completion_provider_update_info (provider, 
 			                                    proposal,
-			                                    GTK_SOURCE_COMPLETION_INFO (completion->priv->info_window));
+			                                    info_window);
 	}
+	
+	gtk_source_completion_info_process_resize (info_window);
 }
 
 static void
@@ -877,8 +882,17 @@ hide_info_cb (GtkWidget *widget,
 }
 
 static void
-gtk_source_completion_realize (GtkWidget *widget,
-			       GtkSourceCompletion *completion)
+info_size_allocate_cb (GtkWidget           *widget,
+                       GtkAllocation       *allocation,
+                       GtkSourceCompletion *completion)
+{
+	/* Update window position */
+	update_info_position (completion);
+}
+
+static void
+gtk_source_completion_realize (GtkWidget           *widget,
+                               GtkSourceCompletion *completion)
 {
 	gtk_container_set_border_width (GTK_CONTAINER (completion->priv->window), 1);
 	gtk_widget_set_size_request (GTK_WIDGET (completion->priv->window),
@@ -887,9 +901,9 @@ gtk_source_completion_realize (GtkWidget *widget,
 }
 
 static gboolean
-gtk_source_completion_configure_event (GtkWidget *widget,
-				       GdkEventConfigure *event,
-				       GtkSourceCompletion *completion)
+gtk_source_completion_configure_event (GtkWidget           *widget,
+                                       GdkEventConfigure   *event,
+                                       GtkSourceCompletion *completion)
 {
 	if (GTK_WIDGET_VISIBLE (completion->priv->info_window))
 		update_info_position (completion);
@@ -898,9 +912,9 @@ gtk_source_completion_configure_event (GtkWidget *widget,
 }
 
 static gboolean
-view_focus_out_event_cb (GtkWidget *widget,
-			 GdkEventFocus *event,
-			 gpointer user_data)
+view_focus_out_event_cb (GtkWidget     *widget,
+                         GdkEventFocus *event,
+                         gpointer       user_data)
 {
 	GtkSourceCompletion *completion = GTK_SOURCE_COMPLETION (user_data);
 	
@@ -1961,6 +1975,11 @@ initialize_ui (GtkSourceCompletion *completion)
 			  "hide",
 			  G_CALLBACK (hide_info_cb),
 			  completion);
+
+	g_signal_connect (completion->priv->info_window,
+	                  "size-allocate",
+	                  G_CALLBACK(info_size_allocate_cb),
+	                  completion);
 }
 
 static void
diff --git a/gtksourceview/gtksourcecompletioninfo.c b/gtksourceview/gtksourcecompletioninfo.c
index 13ba17a..493eb54 100644
--- a/gtksourceview/gtksourcecompletioninfo.c
+++ b/gtksourceview/gtksourcecompletioninfo.c
@@ -343,7 +343,7 @@ gtk_source_completion_info_class_init (GtkSourceCompletionInfoClass *klass)
 							    -1,
 							    G_MAXINT,
 							    -1,
-							    G_PARAM_READWRITE));
+							    G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
 	g_object_class_install_property (object_class,
 					 PROP_MAX_HEIGHT,
@@ -353,7 +353,7 @@ gtk_source_completion_info_class_init (GtkSourceCompletionInfoClass *klass)
 							    -1,
 							    G_MAXINT,
 							    -1,
-							    G_PARAM_READWRITE));
+							    G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 							    
 
 	g_object_class_install_property (object_class,
@@ -361,16 +361,16 @@ gtk_source_completion_info_class_init (GtkSourceCompletionInfoClass *klass)
 					 g_param_spec_boolean ("shrink-width",
 							       _("Shrink width"),
 							       _("Whether the window should shrink width to fit the contents"),
-							       FALSE,
-							       G_PARAM_READWRITE));
+							       TRUE,
+							       G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
 	g_object_class_install_property (object_class,
 					 PROP_SHRINK_HEIGHT,
 					 g_param_spec_boolean ("shrink-height",
 							       _("Shrink height"),
 							       _("Whether the window should shrink height to fit the contents"),
-							       FALSE,
-							       G_PARAM_READWRITE));
+							       TRUE,
+							       G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 						       
 	g_type_class_add_private (object_class, sizeof (GtkSourceCompletionInfoPrivate));
 }
@@ -493,20 +493,14 @@ use_scrolled_window (GtkSourceCompletionInfo *info,
                      GtkWidget               *widget)
 {
 	GtkRequisition req;
+	gint mw;
+	gint mh;
 	
-	if (!needs_viewport (widget))
-	{
-		return TRUE;
-	}
-	
-	if (info->priv->max_width == -1 && info->priv->max_height == -1)
-	{
-		return FALSE;
-	}
-	
+	mw = info->priv->max_width;
+	mh = info->priv->max_height;
 	gtk_widget_size_request (widget, &req);
 	
-	return (info->priv->max_width < req.width || info->priv->max_height < req.height);
+	return (mw != -1 && mw < req.width) || (mh != -1 && mh < req.height);
 }
 
 static void
@@ -582,6 +576,7 @@ gtk_source_completion_info_set_widget (GtkSourceCompletionInfo *info,
 		/* See if it needs a viewport */
 		if (use_scrolled_window (info, widget))
 		{
+			g_message ("yes");
 			create_scrolled_window (info);
 			child = widget;
 			
@@ -604,7 +599,7 @@ gtk_source_completion_info_set_widget (GtkSourceCompletionInfo *info,
 		gtk_widget_show (widget);
 	}
 
-	window_resize (info);
+	queue_resize (info);
 }
 
 /**
@@ -624,5 +619,13 @@ gtk_source_completion_info_get_widget (GtkSourceCompletionInfo* info)
 	return info->priv->widget;
 }
 
+void
+gtk_source_completion_info_process_resize (GtkSourceCompletionInfo *info)
+{
+	g_return_if_fail (GTK_IS_SOURCE_COMPLETION_INFO (info));
+	
+	if (info->priv->idle_resize != 0)
+		window_resize (info);
+}
 
 
diff --git a/gtksourceview/gtksourcecompletioninfo.h b/gtksourceview/gtksourcecompletioninfo.h
index 5873a43..09ddd6d 100644
--- a/gtksourceview/gtksourcecompletioninfo.h
+++ b/gtksourceview/gtksourcecompletioninfo.h
@@ -75,6 +75,8 @@ void		 gtk_source_completion_info_set_widget		(GtkSourceCompletionInfo *info,
 
 GtkWidget	*gtk_source_completion_info_get_widget		(GtkSourceCompletionInfo *info);
 
+void		 gtk_source_completion_info_process_resize	(GtkSourceCompletionInfo *info);
+
 G_END_DECLS
 
 #endif /* __GTK_SOURCE_COMPLETION_INFO_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]