[gtksourceview] Rip out custom CompletionInfo sizing.
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] Rip out custom CompletionInfo sizing.
- Date: Sun, 5 Dec 2010 15:37:05 +0000 (UTC)
commit e195094a2a89fe25996f081b584c42675b89216f
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Dec 5 16:36:31 2010 +0100
Rip out custom CompletionInfo sizing.
It is totally broken with gtk3 new sizing logic so we would need to redo
it from scratch. Beside it had some dubious code like the one to decide
if a scrolledwindow was needed. Beside the completion info is a gtkwindow,
so worse case apps can do the sizing themselves.
docs/reference/gtksourceview-3.0-sections.txt | 2 -
gtksourceview/gtksourcecompletion.c | 5 -
gtksourceview/gtksourcecompletioninfo.c | 399 +------------------------
gtksourceview/gtksourcecompletioninfo.h | 16 +-
4 files changed, 20 insertions(+), 402 deletions(-)
---
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index f0303fb..40dfbad 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -490,10 +490,8 @@ GtkSourceCompletionClass
GtkSourceCompletionInfo
gtk_source_completion_info_new
gtk_source_completion_info_move_to_iter
-gtk_source_completion_info_set_sizing
gtk_source_completion_info_set_widget
gtk_source_completion_info_get_widget
-gtk_source_completion_info_process_resize
<SUBSECTION Standard>
GTK_IS_SOURCE_COMPLETION_INFO
GTK_IS_SOURCE_COMPLETION_INFO_CLASS
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index f3722e8..cf4dd21 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -929,9 +929,6 @@ update_proposal_info_real (GtkSourceCompletion *completion,
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)
{
/* Set to default widget */
@@ -995,8 +992,6 @@ update_proposal_info_real (GtkSourceCompletion *completion,
g_signal_handlers_unblock_by_func (completion->priv->info_window,
G_CALLBACK (show_info_cb),
completion);
-
- gtk_source_completion_info_process_resize (info_window);
}
static void
diff --git a/gtksourceview/gtksourcecompletioninfo.c b/gtksourceview/gtksourcecompletioninfo.c
index 20120f6..116c166 100644
--- a/gtksourceview/gtksourcecompletioninfo.c
+++ b/gtksourceview/gtksourcecompletioninfo.c
@@ -37,15 +37,6 @@ struct _GtkSourceCompletionInfoPrivate
{
GtkWidget *scroll;
GtkWidget *widget;
-
- gint max_height;
- gint max_width;
-
- guint idle_resize;
- guint request_id;
-
- guint shrink_height : 1;
- guint shrink_width : 1;
};
/* Signals */
@@ -55,16 +46,6 @@ enum
LAST_SIGNAL
};
-/* Properties */
-enum
-{
- PROP_0,
- PROP_MAX_WIDTH,
- PROP_MAX_HEIGHT,
- PROP_SHRINK_WIDTH,
- PROP_SHRINK_HEIGHT
-};
-
static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE(GtkSourceCompletionInfo, gtk_source_completion_info, GTK_TYPE_WINDOW);
@@ -72,102 +53,6 @@ G_DEFINE_TYPE(GtkSourceCompletionInfo, gtk_source_completion_info, GTK_TYPE_WIND
#define GTK_SOURCE_COMPLETION_INFO_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GTK_TYPE_SOURCE_COMPLETION_INFO, GtkSourceCompletionInfoPrivate))
static void
-get_scrolled_window_sizing (GtkSourceCompletionInfo *info,
- gint *border,
- gint *hscroll,
- gint *vscroll)
-{
- GtkWidget *scrollbar;
-
- *border = 0;
- *hscroll = 0;
- *vscroll = 0;
-
- if (info->priv->scroll != NULL)
- {
- GtkAllocation allocation;
-
- *border = gtk_container_get_border_width (GTK_CONTAINER (info));
-
- scrollbar = gtk_scrolled_window_get_hscrollbar (GTK_SCROLLED_WINDOW (info->priv->scroll));
-
- if (gtk_widget_get_visible (scrollbar))
- {
- gtk_widget_get_allocation (scrollbar, &allocation);
- *hscroll = allocation.height;
- }
-
- scrollbar = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (info->priv->scroll));
-
- if (gtk_widget_get_visible (scrollbar))
- {
- gtk_widget_get_allocation (scrollbar, &allocation);
- *vscroll = allocation.height;
- }
- }
-}
-
-static void
-window_resize (GtkSourceCompletionInfo *info)
-{
- gint width;
- gint height;
-
- gtk_window_get_default_size (GTK_WINDOW (info), &width, &height);
-
- if (info->priv->widget != NULL)
- {
- GtkStyleContext *context;
- GtkBorder *pad;
- GtkRequisition req;
- gint off;
- gint border;
- gint hscroll;
- gint vscroll;
-
- context = gtk_widget_get_style_context (GTK_WIDGET (info));
- gtk_style_context_get (context, 0, "padding", &pad, NULL);
-
- /* Try to resize to fit widget, if necessary */
- gtk_widget_get_preferred_size (info->priv->widget,
- &req, NULL);
-
- get_scrolled_window_sizing (info, &border, &hscroll, &vscroll);
- off = (gtk_container_get_border_width (GTK_CONTAINER (info)) + border) * 2;
-
- if (info->priv->shrink_height)
- {
- if (info->priv->max_height == -1)
- {
- height = req.height + pad->top + pad->bottom;
- }
- else
- {
- height = MIN (req.height + pad->top + pad->bottom, info->priv->max_height);
- }
-
- height += off + hscroll;
- }
-
- if (info->priv->shrink_width)
- {
- if (info->priv->max_width == -1)
- {
- width = req.width + pad->left + pad->right;
- }
- else
- {
- width = MIN (req.width + pad->left + pad->right, info->priv->max_width);
- }
-
- width += off + vscroll;
- }
- }
-
- gtk_window_resize (GTK_WINDOW (info), width, height);
-}
-
-static void
gtk_source_completion_info_init (GtkSourceCompletionInfo *info)
{
info->priv = GTK_SOURCE_COMPLETION_INFO_GET_PRIVATE (info);
@@ -181,97 +66,17 @@ gtk_source_completion_info_init (GtkSourceCompletionInfo *info)
gtk_window_set_default_size (GTK_WINDOW (info), 300, 200);
gtk_container_set_border_width (GTK_CONTAINER (info), 1);
-}
-static gboolean
-idle_resize (GtkSourceCompletionInfo *info)
-{
- info->priv->idle_resize = 0;
-
- window_resize (info);
- return FALSE;
-}
-
-static void
-queue_resize (GtkSourceCompletionInfo *info)
-{
- if (info->priv->idle_resize == 0)
- {
- info->priv->idle_resize = g_idle_add ((GSourceFunc)idle_resize, info);
- }
-}
-
-static void
-gtk_source_completion_info_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GtkSourceCompletionInfo *info = GTK_SOURCE_COMPLETION_INFO (object);
-
- switch (prop_id)
- {
- case PROP_MAX_WIDTH:
- g_value_set_int (value, info->priv->max_width);
- break;
- case PROP_MAX_HEIGHT:
- g_value_set_int (value, info->priv->max_height);
- break;
- case PROP_SHRINK_WIDTH:
- g_value_set_boolean (value, info->priv->shrink_width);
- break;
- case PROP_SHRINK_HEIGHT:
- g_value_set_boolean (value, info->priv->shrink_height);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-gtk_source_completion_info_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GtkSourceCompletionInfo *info = GTK_SOURCE_COMPLETION_INFO (object);
-
- switch (prop_id)
- {
- case PROP_MAX_WIDTH:
- info->priv->max_width = g_value_get_int (value);
- queue_resize (info);
- break;
- case PROP_MAX_HEIGHT:
- info->priv->max_height = g_value_get_int (value);
- queue_resize (info);
- break;
- case PROP_SHRINK_WIDTH:
- info->priv->shrink_width = g_value_get_boolean (value);
- queue_resize (info);
- break;
- case PROP_SHRINK_HEIGHT:
- info->priv->shrink_height = g_value_get_boolean (value);
- queue_resize (info);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-gtk_source_completion_info_finalize (GObject *object)
-{
- GtkSourceCompletionInfo *info = GTK_SOURCE_COMPLETION_INFO (object);
+ /* Create scrolled window */
+ info->priv->scroll = gtk_scrolled_window_new (NULL, NULL);
- if (info->priv->idle_resize != 0)
- {
- g_source_remove (info->priv->idle_resize);
- }
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (info->priv->scroll),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
- G_OBJECT_CLASS (gtk_source_completion_info_parent_class)->finalize (object);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (info->priv->scroll),
+ GTK_SHADOW_NONE);
+ gtk_container_add (GTK_CONTAINER (info), info->priv->scroll);
}
static void
@@ -304,10 +109,6 @@ gtk_source_completion_info_class_init (GtkSourceCompletionInfoClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- object_class->get_property = gtk_source_completion_info_get_property;
- object_class->set_property = gtk_source_completion_info_set_property;
- object_class->finalize = gtk_source_completion_info_finalize;
-
widget_class->show = gtk_source_completion_info_show;
widget_class->draw = gtk_source_completion_info_draw;
@@ -330,43 +131,6 @@ gtk_source_completion_info_class_init (GtkSourceCompletionInfoClass *klass)
G_TYPE_NONE,
0);
- /* Properties */
- g_object_class_install_property (object_class,
- PROP_MAX_WIDTH,
- g_param_spec_int ("max-width",
- _("Maximum width"),
- _("The maximum allowed width"),
- -1,
- G_MAXINT,
- -1,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-
- g_object_class_install_property (object_class,
- PROP_MAX_HEIGHT,
- g_param_spec_int ("max-height",
- _("Maximum height"),
- _("The maximum allowed height"),
- -1,
- G_MAXINT,
- -1,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-
- g_object_class_install_property (object_class,
- PROP_SHRINK_WIDTH,
- g_param_spec_boolean ("shrink-width",
- _("Shrink width"),
- _("Whether the window should shrink width to fit the contents"),
- 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"),
- TRUE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-
g_type_class_add_private (object_class, sizeof (GtkSourceCompletionInfoPrivate));
}
@@ -423,95 +187,6 @@ gtk_source_completion_info_move_to_iter (GtkSourceCompletionInfo *info,
}
/**
- * gtk_source_completion_info_set_sizing:
- * @info: a #GtkSourceCompletionInfo.
- * @width: The maximum/requested width of the window (-1 to default).
- * @height: The maximum/requested height of the window (-1 to default).
- * @shrink_width: Whether to shrink the width of the window to fit its contents.
- * @shrink_height: Whether to shrink the height of the window to fit its
- * contents.
- *
- * Set sizing information for the info window. If @shrink_width or
- * @shrink_height is %TRUE, the info window will try to resize to fit the
- * window contents, with a maximum size given by @width and @height. Setting
- * @width or @height to -1 removes the maximum size of respectively the width
- * and height of the window.
- */
-void
-gtk_source_completion_info_set_sizing (GtkSourceCompletionInfo *info,
- gint width,
- gint height,
- gboolean shrink_width,
- gboolean shrink_height)
-{
- g_return_if_fail (GTK_IS_SOURCE_COMPLETION_INFO (info));
-
- if (info->priv->max_width == width &&
- info->priv->max_height == height &&
- info->priv->shrink_width == shrink_width &&
- info->priv->shrink_height == shrink_height)
- {
- return;
- }
-
- info->priv->max_width = width;
- info->priv->max_height = height;
- info->priv->shrink_width = shrink_width;
- info->priv->shrink_height = shrink_height;
-
- queue_resize (info);
-}
-
-static gboolean
-needs_viewport (GtkWidget *widget)
-{
- guint id;
-
- id = g_signal_lookup ("set-scroll-adjustments", G_TYPE_FROM_INSTANCE (widget));
-
- return id == 0;
-}
-
-static void
-widget_size_request_cb (GtkWidget *widget,
- GtkRequisition *requisition,
- GtkSourceCompletionInfo *info)
-{
- queue_resize (info);
-}
-
-static gboolean
-use_scrolled_window (GtkSourceCompletionInfo *info,
- GtkWidget *widget)
-{
- GtkRequisition req;
- gint mw;
- gint mh;
-
- mw = info->priv->max_width;
- mh = info->priv->max_height;
- gtk_widget_get_preferred_size (widget, &req, NULL);
-
- return (mw != -1 && mw < req.width) || (mh != -1 && mh < req.height);
-}
-
-static void
-create_scrolled_window (GtkSourceCompletionInfo *info)
-{
- /* Create scrolled window main widget */
- info->priv->scroll = gtk_scrolled_window_new (NULL, NULL);
-
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (info->priv->scroll),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
-
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (info->priv->scroll),
- GTK_SHADOW_NONE);
- gtk_widget_show (info->priv->scroll);
- gtk_container_add (GTK_CONTAINER (info), info->priv->scroll);
-}
-
-/**
* gtk_source_completion_info_set_widget:
* @info: a #GtkSourceCompletionInfo.
* @widget: (allow-none): a #GtkWidget.
@@ -524,8 +199,6 @@ void
gtk_source_completion_info_set_widget (GtkSourceCompletionInfo *info,
GtkWidget *widget)
{
- GtkWidget *child;
-
g_return_if_fail (GTK_IS_SOURCE_COMPLETION_INFO (info));
g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
@@ -536,60 +209,30 @@ gtk_source_completion_info_set_widget (GtkSourceCompletionInfo *info,
if (info->priv->widget != NULL)
{
- g_signal_handler_disconnect (info->priv->widget, info->priv->request_id);
-
gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (info->priv->widget)),
info->priv->widget);
-
- if (info->priv->scroll != NULL)
- {
- gtk_widget_destroy (info->priv->scroll);
- info->priv->scroll = NULL;
- }
}
info->priv->widget = widget;
if (widget != NULL)
{
- /* Keep it alive */
- if (g_object_is_floating (widget))
- {
- g_object_ref (widget);
- }
-
- info->priv->request_id =
- g_signal_connect_after (widget,
- "size-request",
- G_CALLBACK (widget_size_request_cb),
- info);
-
/* See if it needs a viewport */
- if (use_scrolled_window (info, widget))
+ if (GTK_IS_SCROLLABLE (widget))
{
- create_scrolled_window (info);
- child = widget;
-
- if (needs_viewport (widget))
- {
- child = gtk_viewport_new (NULL, NULL);
- gtk_viewport_set_shadow_type (GTK_VIEWPORT (child), GTK_SHADOW_NONE);
- gtk_widget_show (child);
-
- gtk_container_add (GTK_CONTAINER (child), widget);
- }
-
- gtk_container_add (GTK_CONTAINER (info->priv->scroll), child);
+ gtk_container_add (GTK_CONTAINER (info->priv->scroll), widget);
}
else
{
- gtk_container_add (GTK_CONTAINER (info), widget);
+ gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (info->priv->scroll), widget);
}
- gtk_widget_show (widget);
+ gtk_widget_show_all (info->priv->scroll);
+ }
+ else
+ {
+ gtk_widget_hide (info->priv->scroll);
}
-
- queue_resize (info);
}
/**
@@ -608,13 +251,3 @@ 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 31f167a..8baa6a5 100644
--- a/gtksourceview/gtksourcecompletioninfo.h
+++ b/gtksourceview/gtksourcecompletioninfo.h
@@ -42,7 +42,7 @@ typedef struct _GtkSourceCompletionInfo GtkSourceCompletionInfo;
struct _GtkSourceCompletionInfo
{
GtkWindow parent;
-
+
GtkSourceCompletionInfoPrivate *priv;
};
@@ -51,8 +51,8 @@ typedef struct _GtkSourceCompletionInfoClass GtkSourceCompletionInfoClass;
struct _GtkSourceCompletionInfoClass
{
GtkWindowClass parent_class;
-
- void (*before_show) (GtkSourceCompletionInfo *info);
+
+ void (*before_show) (GtkSourceCompletionInfo *info);
};
GType gtk_source_completion_info_get_type (void) G_GNUC_CONST;
@@ -64,19 +64,11 @@ void gtk_source_completion_info_move_to_iter (GtkSourceCompletionInfo *info,
GtkTextView *view,
GtkTextIter *iter);
-void gtk_source_completion_info_set_sizing (GtkSourceCompletionInfo *info,
- gint width,
- gint height,
- gboolean shrink_width,
- gboolean shrink_height);
-
-void gtk_source_completion_info_set_widget (GtkSourceCompletionInfo *info,
+void gtk_source_completion_info_set_widget (GtkSourceCompletionInfo *info,
GtkWidget *widget);
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]