summaryrefslogtreecommitdiff
path: root/liblogdiag
diff options
context:
space:
mode:
Diffstat (limited to 'liblogdiag')
-rw-r--r--liblogdiag/ld-category-symbol-view.c412
-rw-r--r--liblogdiag/ld-category-tree-view.c160
2 files changed, 281 insertions, 291 deletions
diff --git a/liblogdiag/ld-category-symbol-view.c b/liblogdiag/ld-category-symbol-view.c
index aa3fe8c..a2ae4cc 100644
--- a/liblogdiag/ld-category-symbol-view.c
+++ b/liblogdiag/ld-category-symbol-view.c
@@ -75,13 +75,6 @@ static void ld_category_symbol_view_set_category
static LdCategory *ld_category_symbol_view_get_category
(LdCategoryView *iface);
-static void on_size_request (GtkWidget *widget, GtkRequisition *requisition,
- gpointer user_data);
-static void on_size_allocate (GtkWidget *widget, GdkRectangle *allocation,
- gpointer user_data);
-static gboolean on_expose_event (GtkWidget *widget, GdkEventExpose *event,
- gpointer user_data);
-
static void
ld_category_view_init (LdCategoryViewInterface *iface)
@@ -136,125 +129,6 @@ symbol_deselect (LdCategorySymbolView *self)
gtk_drag_source_unset (GTK_WIDGET (self));
}
-static gboolean
-on_leave_notify (GtkWidget *widget, GdkEventCrossing *event, gpointer user_data)
-{
- symbol_deselect (LD_CATEGORY_SYMBOL_VIEW (widget));
- return FALSE;
-}
-
-static gboolean
-on_motion_notify (GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
-{
- LdCategorySymbolView *self;
- GSList *iter;
-
- if (event->state & GDK_BUTTON1_MASK)
- return FALSE;
-
- self = LD_CATEGORY_SYMBOL_VIEW (widget);
- for (iter = self->priv->layout; iter; iter = iter->next)
- {
- SymbolData *data;
-
- data = iter->data;
- if (event->x < data->rect.x
- || event->y < data->rect.y
- || event->x >= data->rect.x + data->rect.width
- || event->y >= data->rect.y + data->rect.height)
- continue;
-
- if (data != self->priv->preselected)
- {
- GtkTargetEntry target = {"ld-symbol", GTK_TARGET_SAME_APP, 0};
-
- symbol_deselect (self);
- self->priv->preselected = data;
- symbol_redraw (self, data);
-
- gtk_drag_source_set (widget,
- GDK_BUTTON1_MASK, &target, 1, GDK_ACTION_COPY);
-
- g_signal_emit (self, LD_CATEGORY_VIEW_GET_INTERFACE (self)->
- symbol_selected_signal, 0, data->symbol, data->path);
- }
- return FALSE;
- }
-
- symbol_deselect (self);
- return FALSE;
-}
-
-static void
-on_drag_data_get
-(GtkWidget *widget, GdkDragContext *ctx, GtkSelectionData *selection_data,
- guint target_type, guint time, gpointer user_data)
-{
- LdCategorySymbolView *self;
-
- self = LD_CATEGORY_SYMBOL_VIEW (widget);
- g_return_if_fail (self->priv->preselected != NULL);
-
- gtk_selection_data_set (selection_data,
- gtk_selection_data_get_target (selection_data),
- 8, (guchar *) self->priv->preselected->path,
- strlen (self->priv->preselected->path));
-}
-
-static void
-on_drag_begin (GtkWidget *widget, GdkDragContext *ctx, gpointer user_data)
-{
- LdCategorySymbolView *self;
- GdkPixbuf *pbuf;
-
- self = LD_CATEGORY_SYMBOL_VIEW (widget);
- g_return_if_fail (self->priv->preselected != NULL);
-
- /* Some of the larger previews didn't work, and we have to get rid of
- * the icon later when we're hovering above LdDiagramView anyway. */
- pbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 1, 1);
- gdk_pixbuf_fill (pbuf, 0x00000000);
- gtk_drag_set_icon_pixbuf (ctx, pbuf, 0, 0);
- g_object_unref (pbuf);
-}
-
-static void
-on_drag_end (GtkWidget *widget, GdkDragContext *ctx, gpointer user_data)
-{
- symbol_deselect (LD_CATEGORY_SYMBOL_VIEW (widget));
-}
-
-static void
-ld_category_symbol_view_init (LdCategorySymbolView *self)
-{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE
- (self, LD_TYPE_CATEGORY_SYMBOL_VIEW, LdCategorySymbolViewPrivate);
-
- g_signal_connect (self, "size-allocate",
- G_CALLBACK (on_size_allocate), NULL);
- g_signal_connect (self, "size-request",
- G_CALLBACK (on_size_request), NULL);
- g_signal_connect (self, "expose-event",
- G_CALLBACK (on_expose_event), NULL);
-
- g_signal_connect (self, "motion-notify-event",
- G_CALLBACK (on_motion_notify), NULL);
- g_signal_connect (self, "leave-notify-event",
- G_CALLBACK (on_leave_notify), NULL);
-
- g_signal_connect (self, "drag-begin",
- G_CALLBACK (on_drag_begin), NULL);
- g_signal_connect (self, "drag-data-get",
- G_CALLBACK (on_drag_data_get), NULL);
- g_signal_connect (self, "drag-end",
- G_CALLBACK (on_drag_end), NULL);
-
- gtk_widget_add_events (GTK_WIDGET (self),
- GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK
- | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
- | GDK_LEAVE_NOTIFY_MASK);
-}
-
static void
symbol_data_free (SymbolData *self)
{
@@ -263,64 +137,6 @@ symbol_data_free (SymbolData *self)
g_slice_free (SymbolData, self);
}
-static void
-layout_destroy (LdCategorySymbolView *self)
-{
- symbol_deselect (self);
-
- g_slist_foreach (self->priv->layout, (GFunc) symbol_data_free, NULL);
- g_slist_free (self->priv->layout);
- self->priv->layout = NULL;
- self->priv->preselected = NULL;
-}
-
-static void
-ld_category_symbol_view_finalize (GObject *gobject)
-{
- LdCategorySymbolView *self;
-
- self = LD_CATEGORY_SYMBOL_VIEW (gobject);
-
- layout_destroy (self);
- if (self->priv->category)
- g_object_unref (self->priv->category);
- g_free (self->priv->path);
-
- /* Chain up to the parent class. */
- G_OBJECT_CLASS (ld_category_symbol_view_parent_class)->finalize (gobject);
-}
-
-static void
-ld_category_symbol_view_get_property (GObject *object, guint property_id,
- GValue *value, GParamSpec *pspec)
-{
- switch (property_id)
- {
- case PROP_CATEGORY:
- g_value_set_object (value,
- ld_category_view_get_category (LD_CATEGORY_VIEW (object)));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- }
-}
-
-static void
-ld_category_symbol_view_set_property (GObject *object, guint property_id,
- const GValue *value, GParamSpec *pspec)
-{
- switch (property_id)
- {
- case PROP_CATEGORY:
- ld_category_view_set_category (LD_CATEGORY_VIEW (object),
- LD_CATEGORY (g_value_get_object (value)));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- }
-}
-
-
typedef struct
{
guint total_height; /* Total height required to show the symbols. */
@@ -333,6 +149,17 @@ typedef struct
}
LayoutContext;
+static void
+layout_destroy (LdCategorySymbolView *self)
+{
+ symbol_deselect (self);
+
+ g_slist_foreach (self->priv->layout, (GFunc) symbol_data_free, NULL);
+ g_slist_free (self->priv->layout);
+ self->priv->layout = NULL;
+ self->priv->preselected = NULL;
+}
+
static GSList *
layout_finish_row (LayoutContext *ctx)
{
@@ -433,6 +260,51 @@ layout_for_width (LdCategorySymbolView *self, gint width)
return ctx.total_height;
}
+static void
+on_size_request (GtkWidget *widget, GtkRequisition *requisition,
+ gpointer user_data)
+{
+ LdCategorySymbolView *self;
+
+ self = LD_CATEGORY_SYMBOL_VIEW (widget);
+
+ if (!self->priv->category
+ || !ld_category_get_symbols (self->priv->category))
+ {
+ requisition->width = 0;
+ requisition->height = 0;
+ return;
+ }
+
+ requisition->width = SYMBOL_WIDTH + 2 * SYMBOL_SPACING;
+
+ if (self->priv->height_negotiation)
+ {
+ GtkAllocation alloc;
+
+ gtk_widget_get_allocation (widget, &alloc);
+ requisition->height = layout_for_width (self, alloc.width);
+ }
+ else
+ requisition->height = SYMBOL_HEIGHT + 2 * SYMBOL_SPACING;
+}
+
+static void
+on_size_allocate (GtkWidget *widget, GdkRectangle *allocation,
+ gpointer user_data)
+{
+ LdCategorySymbolView *self;
+
+ self = LD_CATEGORY_SYMBOL_VIEW (widget);
+
+ if (self->priv->height_negotiation)
+ self->priv->height_negotiation = FALSE;
+ else
+ {
+ self->priv->height_negotiation = TRUE;
+ gtk_widget_queue_resize (widget);
+ }
+}
static gboolean
on_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
@@ -481,53 +353,173 @@ on_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
return FALSE;
}
-static void
-on_size_request (GtkWidget *widget, GtkRequisition *requisition,
- gpointer user_data)
+static gboolean
+on_motion_notify (GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
{
LdCategorySymbolView *self;
+ GSList *iter;
- self = LD_CATEGORY_SYMBOL_VIEW (widget);
+ if (event->state & GDK_BUTTON1_MASK)
+ return FALSE;
- if (!self->priv->category
- || !ld_category_get_symbols (self->priv->category))
+ self = LD_CATEGORY_SYMBOL_VIEW (widget);
+ for (iter = self->priv->layout; iter; iter = iter->next)
{
- requisition->width = 0;
- requisition->height = 0;
- return;
- }
+ SymbolData *data;
- requisition->width = SYMBOL_WIDTH + 2 * SYMBOL_SPACING;
+ data = iter->data;
+ if (event->x < data->rect.x
+ || event->y < data->rect.y
+ || event->x >= data->rect.x + data->rect.width
+ || event->y >= data->rect.y + data->rect.height)
+ continue;
- if (self->priv->height_negotiation)
- {
- GtkAllocation alloc;
+ if (data != self->priv->preselected)
+ {
+ GtkTargetEntry target = {"ld-symbol", GTK_TARGET_SAME_APP, 0};
- gtk_widget_get_allocation (widget, &alloc);
- requisition->height = layout_for_width (self, alloc.width);
+ symbol_deselect (self);
+ self->priv->preselected = data;
+ symbol_redraw (self, data);
+
+ gtk_drag_source_set (widget,
+ GDK_BUTTON1_MASK, &target, 1, GDK_ACTION_COPY);
+
+ g_signal_emit (self, LD_CATEGORY_VIEW_GET_INTERFACE (self)->
+ symbol_selected_signal, 0, data->symbol, data->path);
+ }
+ return FALSE;
}
- else
- requisition->height = SYMBOL_HEIGHT + 2 * SYMBOL_SPACING;
+
+ symbol_deselect (self);
+ return FALSE;
+}
+
+static gboolean
+on_leave_notify (GtkWidget *widget, GdkEventCrossing *event, gpointer user_data)
+{
+ symbol_deselect (LD_CATEGORY_SYMBOL_VIEW (widget));
+ return FALSE;
}
static void
-on_size_allocate (GtkWidget *widget, GdkRectangle *allocation,
- gpointer user_data)
+on_drag_data_get
+(GtkWidget *widget, GdkDragContext *ctx, GtkSelectionData *selection_data,
+ guint target_type, guint time, gpointer user_data)
{
LdCategorySymbolView *self;
self = LD_CATEGORY_SYMBOL_VIEW (widget);
+ g_return_if_fail (self->priv->preselected != NULL);
- if (self->priv->height_negotiation)
- self->priv->height_negotiation = FALSE;
- else
+ gtk_selection_data_set (selection_data,
+ gtk_selection_data_get_target (selection_data),
+ 8, (guchar *) self->priv->preselected->path,
+ strlen (self->priv->preselected->path));
+}
+
+static void
+on_drag_begin (GtkWidget *widget, GdkDragContext *ctx, gpointer user_data)
+{
+ LdCategorySymbolView *self;
+ GdkPixbuf *pbuf;
+
+ self = LD_CATEGORY_SYMBOL_VIEW (widget);
+ g_return_if_fail (self->priv->preselected != NULL);
+
+ /* Some of the larger previews didn't work, and we have to get rid of
+ * the icon later when we're hovering above LdDiagramView anyway. */
+ pbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 1, 1);
+ gdk_pixbuf_fill (pbuf, 0x00000000);
+ gtk_drag_set_icon_pixbuf (ctx, pbuf, 0, 0);
+ g_object_unref (pbuf);
+}
+
+static void
+on_drag_end (GtkWidget *widget, GdkDragContext *ctx, gpointer user_data)
+{
+ symbol_deselect (LD_CATEGORY_SYMBOL_VIEW (widget));
+}
+
+static void
+ld_category_symbol_view_init (LdCategorySymbolView *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE
+ (self, LD_TYPE_CATEGORY_SYMBOL_VIEW, LdCategorySymbolViewPrivate);
+
+ g_signal_connect (self, "size-allocate",
+ G_CALLBACK (on_size_allocate), NULL);
+ g_signal_connect (self, "size-request",
+ G_CALLBACK (on_size_request), NULL);
+ g_signal_connect (self, "expose-event",
+ G_CALLBACK (on_expose_event), NULL);
+
+ g_signal_connect (self, "motion-notify-event",
+ G_CALLBACK (on_motion_notify), NULL);
+ g_signal_connect (self, "leave-notify-event",
+ G_CALLBACK (on_leave_notify), NULL);
+
+ g_signal_connect (self, "drag-begin",
+ G_CALLBACK (on_drag_begin), NULL);
+ g_signal_connect (self, "drag-data-get",
+ G_CALLBACK (on_drag_data_get), NULL);
+ g_signal_connect (self, "drag-end",
+ G_CALLBACK (on_drag_end), NULL);
+
+ gtk_widget_add_events (GTK_WIDGET (self),
+ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK
+ | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
+ | GDK_LEAVE_NOTIFY_MASK);
+}
+
+static void
+ld_category_symbol_view_finalize (GObject *gobject)
+{
+ LdCategorySymbolView *self;
+
+ self = LD_CATEGORY_SYMBOL_VIEW (gobject);
+
+ layout_destroy (self);
+ if (self->priv->category)
+ g_object_unref (self->priv->category);
+ g_free (self->priv->path);
+
+ /* Chain up to the parent class. */
+ G_OBJECT_CLASS (ld_category_symbol_view_parent_class)->finalize (gobject);
+}
+
+static void
+ld_category_symbol_view_get_property (GObject *object, guint property_id,
+ GValue *value, GParamSpec *pspec)
+{
+ switch (property_id)
{
- self->priv->height_negotiation = TRUE;
- gtk_widget_queue_resize (widget);
+ case PROP_CATEGORY:
+ g_value_set_object (value,
+ ld_category_view_get_category (LD_CATEGORY_VIEW (object)));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
-/* ===== Generic interface etc. ============================================ */
+static void
+ld_category_symbol_view_set_property (GObject *object, guint property_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ switch (property_id)
+ {
+ case PROP_CATEGORY:
+ ld_category_view_set_category (LD_CATEGORY_VIEW (object),
+ LD_CATEGORY (g_value_get_object (value)));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+
+/* ===== Interface ========================================================= */
/**
* ld_category_symbol_view_new:
diff --git a/liblogdiag/ld-category-tree-view.c b/liblogdiag/ld-category-tree-view.c
index 674c308..fb5ffb0 100644
--- a/liblogdiag/ld-category-tree-view.c
+++ b/liblogdiag/ld-category-tree-view.c
@@ -48,9 +48,6 @@ static void ld_category_tree_view_set_category (LdCategoryView *iface,
LdCategory *category);
static LdCategory *ld_category_tree_view_get_category (LdCategoryView *iface);
-static void reload_category (LdCategoryTreeView *self);
-static void load_category_cb (gpointer data, gpointer user_data);
-
static void
ld_category_view_init (LdCategoryViewInterface *iface)
@@ -131,61 +128,6 @@ ld_category_tree_view_set_property (GObject *object, guint property_id,
}
-/**
- * ld_category_tree_view_new:
- * @category: (allow-none): a category to be assigned to the widget.
- *
- * Create an instance.
- */
-GtkWidget *
-ld_category_tree_view_new (LdCategory *category)
-{
- LdCategoryTreeView *self;
-
- self = g_object_new (LD_TYPE_CATEGORY_TREE_VIEW, NULL);
- ld_category_view_set_category (LD_CATEGORY_VIEW (self), category);
- return GTK_WIDGET (self);
-}
-
-static void
-ld_category_tree_view_set_category (LdCategoryView *iface, LdCategory *category)
-{
- LdCategoryTreeView *self;
-
- g_return_if_fail (LD_IS_CATEGORY_TREE_VIEW (iface));
- g_return_if_fail (LD_IS_CATEGORY (category) || category == NULL);
-
- self = LD_CATEGORY_TREE_VIEW (iface);
- if (self->priv->category)
- {
- g_signal_handlers_disconnect_by_func (self->priv->category,
- reload_category, self);
- g_object_unref (self->priv->category);
- }
-
- self->priv->category = category;
-
- if (category)
- {
- g_signal_connect_data (category, "children-changed",
- G_CALLBACK (reload_category), self,
- NULL, G_CONNECT_AFTER | G_CONNECT_SWAPPED);
- g_signal_connect_data (category, "notify::parent",
- G_CALLBACK (reload_category), self,
- NULL, G_CONNECT_AFTER | G_CONNECT_SWAPPED);
- g_object_ref (category);
- }
- reload_category (self);
- g_object_notify (G_OBJECT (self), "category");
-}
-
-static LdCategory *
-ld_category_tree_view_get_category (LdCategoryView *iface)
-{
- g_return_val_if_fail (LD_IS_CATEGORY_TREE_VIEW (iface), NULL);
- return LD_CATEGORY_TREE_VIEW (iface)->priv->category;
-}
-
static GtkWidget *
create_empty_label (void)
{
@@ -262,6 +204,39 @@ on_symbol_deselected (GObject *source,
}
static void
+load_category_cb (gpointer data, gpointer user_data)
+{
+ LdCategoryTreeView *self;
+ LdCategory *cat;
+ GtkWidget *expander, *child;
+ gchar *name, *label_markup;
+
+ g_return_if_fail (LD_IS_CATEGORY_TREE_VIEW (user_data));
+ g_return_if_fail (LD_IS_CATEGORY (data));
+
+ self = user_data;
+ cat = data;
+
+ name = g_markup_escape_text (ld_category_get_human_name (cat), -1);
+ label_markup = g_strconcat (self->priv->expander_prefix, name, NULL);
+ g_free (name);
+
+ expander = gtk_expander_new (label_markup);
+ gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE);
+ gtk_expander_set_use_markup (GTK_EXPANDER (expander), TRUE);
+ g_free (label_markup);
+
+ child = ld_category_tree_view_new (cat);
+ gtk_container_add (GTK_CONTAINER (expander), child);
+ gtk_box_pack_start (GTK_BOX (self), expander, FALSE, FALSE, 0);
+
+ g_signal_connect_after (child, "symbol-selected",
+ G_CALLBACK (on_symbol_selected), self);
+ g_signal_connect_after (child, "symbol-deselected",
+ G_CALLBACK (on_symbol_deselected), self);
+}
+
+static void
reload_category (LdCategoryTreeView *self)
{
g_return_if_fail (LD_IS_CATEGORY_TREE_VIEW (self));
@@ -303,36 +278,59 @@ reload_category (LdCategoryTreeView *self)
}
}
-static void
-load_category_cb (gpointer data, gpointer user_data)
+/* ===== Interface ========================================================= */
+
+/**
+ * ld_category_tree_view_new:
+ * @category: (allow-none): a category to be assigned to the widget.
+ *
+ * Create an instance.
+ */
+GtkWidget *
+ld_category_tree_view_new (LdCategory *category)
{
LdCategoryTreeView *self;
- LdCategory *cat;
- GtkWidget *expander, *child;
- gchar *name, *label_markup;
- g_return_if_fail (LD_IS_CATEGORY_TREE_VIEW (user_data));
- g_return_if_fail (LD_IS_CATEGORY (data));
+ self = g_object_new (LD_TYPE_CATEGORY_TREE_VIEW, NULL);
+ ld_category_view_set_category (LD_CATEGORY_VIEW (self), category);
+ return GTK_WIDGET (self);
+}
- self = user_data;
- cat = data;
+static void
+ld_category_tree_view_set_category (LdCategoryView *iface, LdCategory *category)
+{
+ LdCategoryTreeView *self;
- name = g_markup_escape_text (ld_category_get_human_name (cat), -1);
- label_markup = g_strconcat (self->priv->expander_prefix, name, NULL);
- g_free (name);
+ g_return_if_fail (LD_IS_CATEGORY_TREE_VIEW (iface));
+ g_return_if_fail (LD_IS_CATEGORY (category) || category == NULL);
- expander = gtk_expander_new (label_markup);
- gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE);
- gtk_expander_set_use_markup (GTK_EXPANDER (expander), TRUE);
- g_free (label_markup);
+ self = LD_CATEGORY_TREE_VIEW (iface);
+ if (self->priv->category)
+ {
+ g_signal_handlers_disconnect_by_func (self->priv->category,
+ reload_category, self);
+ g_object_unref (self->priv->category);
+ }
- child = ld_category_tree_view_new (cat);
- gtk_container_add (GTK_CONTAINER (expander), child);
- gtk_box_pack_start (GTK_BOX (self), expander, FALSE, FALSE, 0);
+ self->priv->category = category;
- g_signal_connect_after (child, "symbol-selected",
- G_CALLBACK (on_symbol_selected), self);
- g_signal_connect_after (child, "symbol-deselected",
- G_CALLBACK (on_symbol_deselected), self);
+ if (category)
+ {
+ g_signal_connect_data (category, "children-changed",
+ G_CALLBACK (reload_category), self,
+ NULL, G_CONNECT_AFTER | G_CONNECT_SWAPPED);
+ g_signal_connect_data (category, "notify::parent",
+ G_CALLBACK (reload_category), self,
+ NULL, G_CONNECT_AFTER | G_CONNECT_SWAPPED);
+ g_object_ref (category);
+ }
+ reload_category (self);
+ g_object_notify (G_OBJECT (self), "category");
}
+static LdCategory *
+ld_category_tree_view_get_category (LdCategoryView *iface)
+{
+ g_return_val_if_fail (LD_IS_CATEGORY_TREE_VIEW (iface), NULL);
+ return LD_CATEGORY_TREE_VIEW (iface)->priv->category;
+}