diff options
| author | Alex Valavanis <valavanisalex@gmail.com> | 2011-07-09 18:44:28 +0000 |
|---|---|---|
| committer | Alex Valavanis <valavanisalex@gmail.com> | 2011-07-09 18:44:28 +0000 |
| commit | e7672f3910efca2b9be29d8f6362578cb16cf59e (patch) | |
| tree | 09ab21a14881a84233104d21684f3f1e7cfc6cd6 /src | |
| parent | Merge upstream GDL 2.23.90 changes (diff) | |
| download | inkscape-e7672f3910efca2b9be29d8f6362578cb16cf59e.tar.gz inkscape-e7672f3910efca2b9be29d8f6362578cb16cf59e.zip | |
Merge upstream GDL 2.24.0 changes
(bzr r10434)
Diffstat (limited to 'src')
| -rw-r--r-- | src/libgdl/gdl-data-frame.c | 297 | ||||
| -rw-r--r-- | src/libgdl/gdl-data-frame.h | 72 | ||||
| -rw-r--r-- | src/libgdl/gdl-data-model-test.c | 240 | ||||
| -rw-r--r-- | src/libgdl/gdl-data-model-test.h | 32 | ||||
| -rw-r--r-- | src/libgdl/gdl-data-model.c | 160 | ||||
| -rw-r--r-- | src/libgdl/gdl-data-model.h | 105 | ||||
| -rw-r--r-- | src/libgdl/gdl-data-row.c | 604 | ||||
| -rw-r--r-- | src/libgdl/gdl-data-row.h | 90 | ||||
| -rw-r--r-- | src/libgdl/gdl-data-view.c | 526 | ||||
| -rw-r--r-- | src/libgdl/gdl-data-view.h | 71 | ||||
| -rw-r--r-- | src/libgdl/gdl-icons.c | 267 | ||||
| -rw-r--r-- | src/libgdl/gdl-icons.h | 61 | ||||
| -rw-r--r-- | src/libgdl/test-dataview.c | 43 |
13 files changed, 0 insertions, 2568 deletions
diff --git a/src/libgdl/gdl-data-frame.c b/src/libgdl/gdl-data-frame.c deleted file mode 100644 index d6fb19533..000000000 --- a/src/libgdl/gdl-data-frame.c +++ /dev/null @@ -1,297 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * This file is part of the GNOME Devtools Libraries. - * - * Copyright (C) 2001 Dave Camp <dave@ximian.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "gdl-i18n.h" -#include "gdl-tools.h" -#include <string.h> - -#include "gdl-data-view.h" -#include "gdl-data-frame.h" -#include "gdl-data-model.h" -#include "gdl-data-row.h" - -struct _GdlDataFramePrivate { - GdkRectangle shadow_r; - GdkRectangle frame_r; - GdkRectangle titlebar_r; - GdkRectangle title_r; - GdkRectangle close_r; - GdkRectangle row_r; - - int shadow_offset; - int titlebar_height; - char *title; - - GdlDataRow *row; - - PangoLayout *layout; - - gboolean selected; -}; - -static void gdl_data_frame_class_init (GdlDataFrameClass *klass); -static void gdl_data_frame_instance_init (GdlDataFrame *obj); -static void gdl_data_frame_finalize (GObject *object); - -GDL_CLASS_BOILERPLATE (GdlDataFrame, gdl_data_frame, GObject, G_TYPE_OBJECT); - -#define PAD 2 -#define BORDER 1 - -#define CENTERY(r1, r2) { r1.y = ((r2.y + (r2.height / 2)) - (r1.height / 2)); } - -void -gdl_data_frame_layout (GdlDataFrame *frame) -{ - GdkPixbuf *close_pixbuf; - /* Sizes */ - if (frame->priv->row) { - gdl_data_row_get_size (frame->priv->row, - NULL, NULL, - &frame->priv->row_r.width, - &frame->priv->row_r.height); - } else { - frame->priv->row_r.height = frame->priv->row_r.width = 0; - } - - if (frame->priv->layout) { - pango_layout_get_pixel_size (frame->priv->layout, - &frame->priv->title_r.width, - &frame->priv->title_r.height); - } else { - frame->priv->title_r.width = frame->priv->title_r.height = 0; - } - - close_pixbuf = gdl_data_view_get_close_pixbuf (frame->view); - if (close_pixbuf) { - frame->priv->close_r.width = - gdk_pixbuf_get_width (close_pixbuf); - frame->priv->close_r.height = - gdk_pixbuf_get_width (close_pixbuf); - } else { - frame->priv->close_r.width = frame->priv->close_r.height = 0; - } - - frame->priv->titlebar_r.height = MAX (frame->priv->titlebar_height, - frame->priv->title_r.height); - frame->priv->titlebar_r.height = MAX (frame->priv->titlebar_r.height, - frame->priv->close_r.height); - - frame->priv->frame_r.width = 2 * BORDER + 3 * PAD + frame->priv->title_r.width + frame->priv->close_r.width; - frame->priv->frame_r.width = MAX (frame->priv->frame_r.width, - frame->priv->row_r.width + 2 * BORDER + 2 * PAD); - frame->priv->frame_r.height = frame->priv->row_r.height + frame->priv->titlebar_r.height + 2 * PAD + 2 * BORDER; - frame->priv->titlebar_r.width = frame->priv->frame_r.width - BORDER; - frame->priv->shadow_r.width = frame->priv->frame_r.width; - frame->priv->shadow_r.height = frame->priv->frame_r.height; - - /* Locations */ - frame->priv->frame_r.x = frame->area.x; - frame->priv->frame_r.y = frame->area.y; - - frame->priv->shadow_r.x = frame->priv->frame_r.x + frame->priv->shadow_offset; - frame->priv->shadow_r.y = frame->priv->frame_r.y + frame->priv->shadow_offset; - frame->priv->titlebar_r.x = frame->priv->frame_r.x + BORDER; - frame->priv->titlebar_r.y = frame->priv->frame_r.y + BORDER; - frame->priv->title_r.x = frame->priv->frame_r.x + BORDER + PAD; - CENTERY (frame->priv->title_r, frame->priv->titlebar_r); - frame->priv->close_r.x = (frame->priv->frame_r.x + frame->priv->frame_r.width) - (frame->priv->close_r.width + BORDER + PAD); - CENTERY (frame->priv->close_r, frame->priv->titlebar_r); - - if (frame->priv->row) { - frame->priv->row_r.x = frame->priv->frame_r.x + BORDER + PAD; - frame->priv->row_r.y = frame->priv->titlebar_r.y + frame->priv->titlebar_r.height + PAD; - gdl_data_row_layout (frame->priv->row, &frame->priv->row_r); - } else { - frame->priv->row_r.x = frame->priv->row_r.y = 0; - } - - frame->area.width = frame->priv->frame_r.width + frame->priv->shadow_offset; - frame->area.height = frame->priv->frame_r.height + frame->priv->shadow_offset; -} - -#if 0 /* not used */ -static void -change_layout (GdlDataFrame *frame) -{ - char *text = frame->priv->title ? frame->priv->title : "?"; - pango_layout_set_text (frame->priv->layout, text, strlen (text)); -} -#endif - -#define EXPLODE(r) (r).x, (r).y, (r).width, (r).height - -void -gdl_data_frame_draw (GdlDataFrame *frame, GdkDrawable *drawable, - GdkRectangle *expose_area) -{ - GdkRectangle inter; - guint8 state = - frame->priv->selected ? GTK_STATE_SELECTED : GTK_STATE_NORMAL; - - gdk_draw_rectangle (drawable, - GTK_WIDGET (frame->view)->style->dark_gc[state], - TRUE, - EXPLODE (frame->priv->shadow_r)); - gdk_draw_rectangle (drawable, - GTK_WIDGET (frame->view)->style->base_gc[GTK_STATE_NORMAL], - TRUE, - EXPLODE (frame->priv->frame_r)); - gdk_draw_rectangle (drawable, - GTK_WIDGET (frame->view)->style->black_gc, - FALSE, - EXPLODE (frame->priv->frame_r)); - gdk_draw_rectangle (drawable, - GTK_WIDGET (frame->view)->style->bg_gc[state], - TRUE, - EXPLODE (frame->priv->titlebar_r)); - gdk_draw_layout (drawable, - GTK_WIDGET (frame->view)->style->fg_gc[state], - frame->priv->title_r.x, frame->priv->title_r.y, - frame->priv->layout); - - if (gdk_rectangle_intersect (expose_area, &frame->priv->close_r, &inter)) { - GdkPixbuf *pixbuf = gdl_data_view_get_close_pixbuf (frame->view); - gdk_draw_pixbuf (drawable, NULL, pixbuf, - 0, 0, - inter.x - frame->priv->close_r.x, - inter.y - frame->priv->close_r.y, - gdk_pixbuf_get_width (pixbuf), - gdk_pixbuf_get_height (pixbuf), - GDK_RGB_DITHER_NORMAL, 0, 0); - } - - if (frame->priv->row) { - if (gdk_rectangle_intersect (expose_area, &frame->priv->row_r, - &inter)) { - gdl_data_row_render (frame->priv->row, drawable, - &inter, - frame->priv->selected ? GTK_CELL_RENDERER_SELECTED : 0); - } - } -} - -void -gdl_data_frame_class_init (GdlDataFrameClass *klass) -{ - GObjectClass *gobject_class = (GObjectClass *)klass; - - parent_class = g_type_class_peek_parent (klass); - - gobject_class->finalize = gdl_data_frame_finalize; -} - -void -gdl_data_frame_instance_init (GdlDataFrame *frame) -{ - frame->priv = g_new0 (GdlDataFramePrivate, 1); - frame->area.x = frame->area.y = 0; - frame->priv->shadow_offset = 3; - frame->priv->titlebar_height = 20; - - frame->area.height = frame->area.width = 100; -} - -void -gdl_data_frame_finalize (GObject *object) -{ - GdlDataFrame *frame = GDL_DATA_FRAME (object); - - if (frame->priv) { - g_free (frame->priv->title); - g_object_unref (frame->priv->layout); - g_object_unref (frame->priv->row); - - g_free (frame->priv); - frame->priv = NULL; - } - GDL_CALL_PARENT (G_OBJECT_CLASS, finalize, (object)); -} - -void -gdl_data_frame_set_selected (GdlDataFrame *frame, - gboolean val) -{ - frame->priv->selected = val; - - gdk_window_invalidate_rect (GTK_LAYOUT (frame->view)->bin_window, - &frame->priv->frame_r, - TRUE); -} - -gboolean -gdl_data_frame_button_press (GdlDataFrame *frame, - GdkEventButton *event) -{ - return FALSE; -} - -void -gdl_data_frame_set_position (GdlDataFrame *frame, - int x, - int y) -{ - frame->area.x = x; - frame->area.y = y; - - gdl_data_frame_layout (frame); -} - -static void -setup_layout (GdlDataFrame *frame) -{ - PangoFontDescription *font_desc = - pango_font_description_copy (GTK_WIDGET (frame->view)->style->font_desc); - - pango_font_description_set_weight (font_desc, - PANGO_WEIGHT_BOLD); - - frame->priv->layout = gtk_widget_create_pango_layout (GTK_WIDGET (frame->view), - frame->priv->title ? frame->priv->title : "?"); - pango_layout_set_font_description (frame->priv->layout, - font_desc); - pango_font_description_free (font_desc); -} - - -GdlDataFrame * -gdl_data_frame_new (GdlDataView *view, - GdlDataRow *row) -{ - GdlDataFrame *frame; - frame = GDL_DATA_FRAME (g_object_new (GDL_TYPE_DATA_FRAME, NULL)); - - frame->view = view; - - frame->priv->row = row; - frame->priv->title = g_strdup (gdl_data_row_get_title (row)); - - setup_layout (frame); - - gdl_data_frame_layout (frame); - - return frame; -} diff --git a/src/libgdl/gdl-data-frame.h b/src/libgdl/gdl-data-frame.h deleted file mode 100644 index 7daeb5b12..000000000 --- a/src/libgdl/gdl-data-frame.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * This file is part of the GNOME Devtools Libraries. - * - * Copyright (C) 2001 Dave Camp <dave@ximian.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef GDL_DATA_FRAME_H -#define GDL_DATA_FRAME_H - -#include <glib-object.h> -#include <gdl/gdl-data-row.h> - -G_BEGIN_DECLS - -#define GDL_TYPE_DATA_FRAME (gdl_data_frame_get_type ()) -#define GDL_DATA_FRAME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDL_TYPE_DATA_FRAME, GdlDataFrame)) -#define GDL_DATA_FRAME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDL_DATA_VIEW_FRAM, GdlDataFrame)) -#define GDL_IS_DATA_FRAME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDL_TYPE_DATA_FRAME)) -#define GDL_IS_DATA_FRAME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDL_TYPE_DATA_FRAME)) -#define GDL_DATA_FRAME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDL_TYPE_DATA_FRAME, GdlDataFrameClass)) - -typedef struct _GdlDataFrame GdlDataFrame; -typedef struct _GdlDataFramePrivate GdlDataFramePrivate; -typedef struct _GdlDataFrameClass GdlDataFrameClass; - -struct _GdlDataFrame { - GObject parent; - - GdlDataView *view; - GdkRectangle area; - - GdlDataFramePrivate *priv; -}; - -struct _GdlDataFrameClass { - GObjectClass parent_class; -}; - -GType gdl_data_frame_get_type (void); -GdlDataFrame *gdl_data_frame_new (GdlDataView *view, - GdlDataRow *row); -void gdl_data_frame_layout (GdlDataFrame *frame); -void gdl_data_frame_draw (GdlDataFrame *item, - GdkDrawable *drawable, - GdkRectangle *expose_area); -void gdl_data_frame_set_selected (GdlDataFrame *frame, - gboolean val); -gboolean gdl_data_frame_button_press (GdlDataFrame *frame, - GdkEventButton *event); -void gdl_data_frame_set_position (GdlDataFrame *frame, - int x, - int y); - -G_END_DECLS - -#endif diff --git a/src/libgdl/gdl-data-model-test.c b/src/libgdl/gdl-data-model-test.c deleted file mode 100644 index ec6ed4d50..000000000 --- a/src/libgdl/gdl-data-model-test.c +++ /dev/null @@ -1,240 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "gdl-i18n.h" - -#include "gdl-data-model-test.h" -#include "gdl-data-model.h" - -#include <string.h> -#include <gtk/gtkcellrenderertext.h> -#include <gtk/gtkcellrenderertoggle.h> - -GObjectClass *parent_class; - -typedef struct _DataItem { - char *name; - char *value; - char *path; - struct _DataItem *children; -} DataItem; - -DataItem data1[] = { - { "foo1", "foo1", "0:0", NULL}, - { "bar1", "bar1", "0:1", NULL }, - { "baz1", "baz1", "0:2", NULL }, - { NULL, NULL, NULL, NULL } - -}; -DataItem data2[] = { - { "foo2", "foo2", "1:0", NULL }, - { "bar2", "bar2", "1:1", NULL }, - { "baz2", "baz2", "1:2", NULL }, - { NULL, NULL, NULL, NULL } - -}; - -DataItem data5[] = { - { "1", "1", "2:2:1:0", NULL }, - { "2", "2", "2:2:1:1", NULL }, - { "3", "3", "2:2:1:2", NULL }, - { "4", "4", "2:2:1:3", NULL }, - { "5", "5", "2:2:1:4", NULL }, - { "6", "6", "2:2:1:5", NULL }, - { NULL, NULL, NULL, NULL } - -}; -DataItem data4[] = { - { "foo4", "foo4", "2:2:0", NULL }, - { "bar4", "[...]", "2:2:1", data5 }, - { "baz4", "baz4", "2:2:2", NULL }, - { NULL, NULL, NULL, NULL } - -}; -DataItem data3[] = { - { "foo foo", "foo3", "2:0", NULL }, - { "bar3", "1", "2:1", NULL }, - { "baz3", "{...}", "2:2", data4 }, - { NULL, NULL, NULL, NULL } - -}; - -DataItem root[] = { - { "test-data", "value1", "0", NULL } , - { "test-data2", "value2", "1", NULL } , - { "test-data3", "{...}", "2", data3 } , - { NULL, NULL, NULL } -}; - -static gboolean -get_iter (GdlDataModel *dm, GdlDataIter *iter, GtkTreePath *path) -{ - int *i = gtk_tree_path_get_indices (path); - int n = gtk_tree_path_get_depth (path); - DataItem *item; - - g_assert (i); - item = &root[*i++]; - - while (--n) { - item = &item->children[*i++]; - } - - iter->data1 = item; - - return TRUE; -} - -static GtkTreePath * -get_path (GdlDataModel *dm, GdlDataIter *iter) -{ - DataItem *item = iter->data1; - return gtk_tree_path_new_from_string (item->path); -} - -static void -get_name (GdlDataModel *dm, GdlDataIter *iter, char **name) -{ - DataItem *item = iter->data1; - *name = item->name; -} - -static void -get_value (GdlDataModel *dm, GdlDataIter *iter, GValue *value) -{ - DataItem *item = iter->data1; - if (strcmp (item->name, "bar3")) { - g_value_init (value, G_TYPE_STRING); - g_value_set_string (value, item->value); - } else { - g_value_init (value, G_TYPE_BOOLEAN); - g_value_set_boolean (value, !strcmp (item->value, "1")); - } -} - -static void -get_renderer (GdlDataModel *dm, GdlDataIter *iter, - GtkCellRenderer **renderer, char **field, - gboolean *is_editable) -{ - DataItem *item = iter->data1; - if (!strcmp (item->name, "bar3")) { - *renderer = g_object_new (gtk_cell_renderer_toggle_get_type (), - "activatable", TRUE, NULL); - *field = "active"; - } else { - *renderer = g_object_new (gtk_cell_renderer_text_get_type (), - "editable", TRUE, NULL); - *field = "text"; - } - *is_editable = (item->children == NULL); -} - -static gboolean -iter_next (GdlDataModel *dm, GdlDataIter *iter) -{ - DataItem *item = iter->data1; - item++; - if (item->name) { - iter->data1 = item; - return TRUE; - } else { - return FALSE; - } -} - -static gboolean -iter_children (GdlDataModel *dm, GdlDataIter *iter, GdlDataIter *parent) -{ - DataItem *item = parent->data1; - - item = &item->children[0]; - if (item) { - iter->data1 = item; - return TRUE; - } else { - return FALSE; - } -} - -static gboolean -iter_has_child (GdlDataModel *dm, GdlDataIter *iter) -{ - DataItem *item = iter->data1; - if (item->children) { - return TRUE; - } else { - return FALSE; - } -} - - -static void -gdl_data_model_test_instance_init (GdlDataModelTest *model) -{ -} - -static void -gdl_data_model_test_finalize (GObject *object) -{ - (*parent_class->finalize) (object); -} - -static void -gdl_data_model_test_class_init (GdlDataModelTestClass *klass) -{ - GObjectClass *object_class; - parent_class = g_type_class_peek_parent (klass); - object_class = (GObjectClass *)klass; - object_class->finalize = gdl_data_model_test_finalize; -} - -static void -gdl_data_model_test_data_model_init (GdlDataModelIface *iface) -{ - iface->get_iter = get_iter; - iface->get_path = get_path; - iface->get_name = get_name; - iface->get_value = get_value; - iface->get_renderer = get_renderer; - iface->iter_next = iter_next; - iface->iter_children = iter_children; - iface->iter_has_child = iter_has_child; -} - -GType -gdl_data_model_test_get_type (void) -{ - static GType type = 0; - - if (!type) { - static const GTypeInfo data_model_test_info = { - sizeof (GdlDataModelTestClass), - NULL, NULL, - (GClassInitFunc) gdl_data_model_test_class_init, - NULL, NULL, - sizeof (GdlDataModelTest), 0, - (GInstanceInitFunc) gdl_data_model_test_instance_init - }; - - static const GInterfaceInfo data_model_info = { - (GInterfaceInitFunc) gdl_data_model_test_data_model_init, - NULL, NULL - }; - - type = g_type_register_static (G_TYPE_OBJECT, - "GdlDataModelTest", - &data_model_test_info, 0); - g_type_add_interface_static (type, - GDL_TYPE_DATA_MODEL, - &data_model_info); - } - return type; -} - -GdlDataModelTest * -gdl_data_model_test_new (void) -{ - return GDL_DATA_MODEL_TEST (g_object_new (gdl_data_model_test_get_type (), NULL)); -} diff --git a/src/libgdl/gdl-data-model-test.h b/src/libgdl/gdl-data-model-test.h deleted file mode 100644 index c8add8daf..000000000 --- a/src/libgdl/gdl-data-model-test.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef GDL_DATA_MODEL_TEST_H -#define GDL_DATA_MODEL_TEST_H - -#include <glib.h> -#include "gdl-data-model.h" - -G_BEGIN_DECLS - -#define GDL_TYPE_DATA_MODEL_TEST (gdl_data_model_test_get_type ()) -#define GDL_DATA_MODEL_TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDL_TYPE_DATA_MODEL_TEST, GdlDataModelTest)) -#define GDL_IS_DATA_MODEL_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDL_TYPE_DATA_MODEL_TEST)) - - -typedef struct _GdlDataModelTest GdlDataModelTest; -typedef struct _GdlDataModelTestClass GdlDataModelTestClass; - -struct _GdlDataModelTest { - GObject parent; - - int stamp; -}; - -struct _GdlDataModelTestClass { - GObjectClass parent_class; -}; - -GType gdl_data_model_test_get_type (void); -GdlDataModelTest *gdl_data_model_test_new (void); - -G_END_DECLS - -#endif diff --git a/src/libgdl/gdl-data-model.c b/src/libgdl/gdl-data-model.c deleted file mode 100644 index 69fbb93d5..000000000 --- a/src/libgdl/gdl-data-model.c +++ /dev/null @@ -1,160 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * This file is part of the GNOME Devtools Libraries. - * - * Copyright (C) 2001 Dave Camp <dave@ximian.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "gdl-data-model.h" - -gboolean -gdl_data_model_get_iter (GdlDataModel *dm, - GdlDataIter *iter, - GtkTreePath *path) -{ - g_return_val_if_fail (dm != NULL, FALSE); - g_return_val_if_fail (iter != NULL, FALSE); - g_return_val_if_fail (path != NULL, FALSE); - g_return_val_if_fail (GDL_DATA_MODEL_GET_IFACE (dm)->get_iter != NULL, - FALSE); - - return (*GDL_DATA_MODEL_GET_IFACE (dm)->get_iter) (dm, iter, path); -} - -GtkTreePath * -gdl_data_model_get_path (GdlDataModel *dm, - GdlDataIter *iter) -{ - g_return_val_if_fail (dm != NULL, NULL); - g_return_val_if_fail (iter != NULL, NULL); - g_return_val_if_fail (GDL_DATA_MODEL_GET_IFACE (dm)->get_path != NULL, - NULL); - - return (*GDL_DATA_MODEL_GET_IFACE (dm)->get_path) (dm, iter); -} - -void -gdl_data_model_get_name (GdlDataModel *dm, - GdlDataIter *iter, - char **name) -{ - g_return_if_fail (dm != NULL); - g_return_if_fail (iter != NULL); - g_return_if_fail (name != NULL); - g_return_if_fail (GDL_DATA_MODEL_GET_IFACE (dm)->get_name != NULL); - - (*GDL_DATA_MODEL_GET_IFACE (dm)->get_name) (dm, iter, name); -} - -void -gdl_data_model_get_value (GdlDataModel *dm, - GdlDataIter *iter, - GValue *value) -{ - g_return_if_fail (dm != NULL); - g_return_if_fail (iter != NULL); - g_return_if_fail (value != NULL); - g_return_if_fail (GDL_DATA_MODEL_GET_IFACE (dm)->get_value != NULL); - - (*GDL_DATA_MODEL_GET_IFACE (dm)->get_value) (dm, iter, value); -} - -void -gdl_data_model_get_renderer (GdlDataModel *dm, - GdlDataIter *iter, - GtkCellRenderer **renderer, - char **field, - gboolean *is_editable) -{ - g_return_if_fail (dm != NULL); - g_return_if_fail (iter != NULL); - g_return_if_fail (renderer != NULL); - g_return_if_fail (GDL_DATA_MODEL_GET_IFACE (dm)->get_renderer != NULL); - - (*GDL_DATA_MODEL_GET_IFACE (dm)->get_renderer) (dm, iter, - renderer, field, - is_editable); -} - -gboolean -gdl_data_model_iter_next (GdlDataModel *dm, - GdlDataIter *iter) -{ - g_return_val_if_fail (dm != NULL, FALSE); - g_return_val_if_fail (iter != NULL, FALSE); - g_return_val_if_fail (GDL_DATA_MODEL_GET_IFACE (dm)->iter_next != NULL, FALSE); - - return (*GDL_DATA_MODEL_GET_IFACE (dm)->iter_next) (dm, iter); -} - -gboolean -gdl_data_model_iter_children (GdlDataModel *dm, - GdlDataIter *iter, - GdlDataIter *parent) -{ - g_return_val_if_fail (dm != NULL, FALSE); - g_return_val_if_fail (iter != NULL, FALSE); - g_return_val_if_fail (GDL_DATA_MODEL_GET_IFACE (dm)->iter_children != NULL, FALSE); - - return (*GDL_DATA_MODEL_GET_IFACE (dm)->iter_children) (dm, iter, parent); -} - -gboolean -gdl_data_model_iter_has_child (GdlDataModel *dm, - GdlDataIter *iter) -{ - g_return_val_if_fail (dm != NULL, FALSE); - g_return_val_if_fail (iter != NULL, FALSE); - g_return_val_if_fail (GDL_DATA_MODEL_GET_IFACE (dm)->iter_has_child != NULL, FALSE); - - return (*GDL_DATA_MODEL_GET_IFACE (dm)->iter_has_child) (dm, iter); -} - -static void -gdl_data_model_base_init (gpointer g_class) -{ - static gboolean initialized = FALSE; - - if (!initialized) { - } -} - -GType -gdl_data_model_get_type (void) -{ - static GType type = 0; - - if (!type) { - static const GTypeInfo info = { - sizeof (GdlDataModelIface), - gdl_data_model_base_init, - NULL, NULL, NULL, NULL, 0, 0, NULL - }; - - type = g_type_register_static (G_TYPE_INTERFACE, - "GdlDataModel", - &info, 0); - g_type_interface_add_prerequisite (type, G_TYPE_OBJECT); - } - - return type; -} diff --git a/src/libgdl/gdl-data-model.h b/src/libgdl/gdl-data-model.h deleted file mode 100644 index 521a65d0c..000000000 --- a/src/libgdl/gdl-data-model.h +++ /dev/null @@ -1,105 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * This file is part of the GNOME Devtools Libraries. - * - * Copyright (C) 2001 Dave Camp <dave@ximian.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef GDL_DATA_MODEL_H -#define GDL_DATA_MODEL_H - -#include <glib.h> -#include <glib-object.h> - -/* Using GtkTreePath to save time */ -#include <gtk/gtktreemodel.h> -#include <gtk/gtkcellrenderer.h> - -G_BEGIN_DECLS - -#define GDL_TYPE_DATA_MODEL (gdl_data_model_get_type ()) -#define GDL_DATA_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDL_TYPE_DATA_MODEL, GdlDataModel)) -#define GDL_IS_DATA_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDL_TYPE_DATA_MODEL)) -#define GDL_DATA_MODEL_GET_IFACE(obj) ((GdlDataModelIface *)g_type_interface_peek (((GTypeInstance *)GDL_DATA_MODEL (obj))->g_class, GDL_TYPE_DATA_MODEL)) - -typedef struct _GdlDataModel GdlDataModel; -typedef struct _GdlDataIter GdlDataIter; -typedef struct _GdlDataModelIface GdlDataModelIface; - -struct _GdlDataIter { - int stamp; - - gpointer data1; - gpointer data2; - gpointer data3; -}; - -struct _GdlDataModelIface { - GTypeInterface g_iface; - - /* Signals */ - void (*path_changed) (GdlDataModel *dm, GtkTreePath *path); - void (*path_inserted) (GdlDataModel *dm, GtkTreePath *path); - void (*path_deleted) (GdlDataModel *dm, GtkTreePath *path); - - /* Virtual Table */ - gboolean (*get_iter) (GdlDataModel *dm, GdlDataIter *iter, - GtkTreePath *path); - GtkTreePath* (*get_path) (GdlDataModel *dm, GdlDataIter *iter); - - void (*get_name) (GdlDataModel *dm, GdlDataIter *iter, - char **name); - void (*get_value) (GdlDataModel *dm, GdlDataIter *iter, - GValue *value); - void (*get_renderer) (GdlDataModel *dm, GdlDataIter *iter, - GtkCellRenderer **renderer, char **field, - gboolean *is_editable); - gboolean (*iter_next) (GdlDataModel *dm, GdlDataIter *iter); - gboolean (*iter_children) (GdlDataModel *dm, GdlDataIter *iter, - GdlDataIter *parent); - gboolean (*iter_has_child) (GdlDataModel *dm, GdlDataIter *iter); -}; - -GType gdl_data_model_get_type (void); -gboolean gdl_data_model_get_iter (GdlDataModel *dm, - GdlDataIter *iter, - GtkTreePath *path); -GtkTreePath *gdl_data_model_get_path (GdlDataModel *dm, - GdlDataIter *iter); -void gdl_data_model_get_name (GdlDataModel *dm, - GdlDataIter *iter, - char **name); -void gdl_data_model_get_value (GdlDataModel *dm, - GdlDataIter *iter, - GValue *value); -void gdl_data_model_get_renderer (GdlDataModel *dm, - GdlDataIter *iter, - GtkCellRenderer **renderer, - char **field, - gboolean *is_editable); -gboolean gdl_data_model_iter_next (GdlDataModel *dm, - GdlDataIter *iter); -gboolean gdl_data_model_iter_children (GdlDataModel *dm, - GdlDataIter *iter, - GdlDataIter *children); -gboolean gdl_data_model_iter_has_child (GdlDataModel *dm, - GdlDataIter *iter); - -G_END_DECLS - -#endif diff --git a/src/libgdl/gdl-data-row.c b/src/libgdl/gdl-data-row.c deleted file mode 100644 index 666c658fe..000000000 --- a/src/libgdl/gdl-data-row.c +++ /dev/null @@ -1,604 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * This file is part of the GNOME Devtools Libraries. - * - * Copyright (C) 2001 Dave Camp <dave@ximian.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "gdl-i18n.h" -#include "gdl-tools.h" -#include "gdl-data-row.h" -#include "gdl-data-model.h" - -#include <gtk/gtktreemodel.h> -#include <gtk/gtkcellrenderer.h> - -struct _GdlDataRowPrivate { - GdlDataModel *model; - GtkTreePath *path; - GdlDataView *view; - - char *name; - - /* area_r - * +- title_r - * | +- name_r - * | +- sep_r - * +- data_r - * +- expand_r - * +- cell_r - */ - - GdkRectangle area_r; - - GdkRectangle title_r; - GdkRectangle name_r; - GdkRectangle sep_r; - - GdkRectangle data_r; - GdkRectangle expand_r; - GdkRectangle cell_r; - - gboolean multi; - GtkCellRenderer *cell; - GList *subrows; - - char *renderer_field; - - gboolean expanded; - gboolean focused; - gboolean editable; - - int split; - int child_split; - gboolean selected; -}; - -GDL_CLASS_BOILERPLATE (GdlDataRow, gdl_data_row, GObject, G_TYPE_OBJECT); - - -static void -expand (GdlDataRow *row) -{ - GdlDataIter iter; - gboolean valid; - - if (gdl_data_model_get_iter (row->priv->model, &iter, row->priv->path)) { - valid = gdl_data_model_iter_children (row->priv->model, - &iter, &iter); - while (valid) { - GdlDataRow *new_row; - GtkTreePath *path; - - path = gdl_data_model_get_path (row->priv->model, - &iter); - new_row = gdl_data_row_new (row->priv->view, - path); - row->priv->subrows = - g_list_prepend (row->priv->subrows, new_row); - gtk_tree_path_free (path); - - valid = gdl_data_model_iter_next (row->priv->model, - &iter); - } - row->priv->subrows = g_list_reverse (row->priv->subrows); - - row->priv->expanded = TRUE; - gdl_data_view_layout (GDL_DATA_VIEW (row->priv->view)); - gtk_widget_queue_draw (GTK_WIDGET (row->priv->view)); - } -} - -static void -contract (GdlDataRow *row) -{ - GList *l; - for (l = row->priv->subrows; l != NULL; l = l->next) { - g_object_unref (G_OBJECT (l->data)); - } - g_list_free (row->priv->subrows); - row->priv->subrows = NULL; - - row->priv->expanded = FALSE; - gdl_data_view_layout (GDL_DATA_VIEW (row->priv->view)); - gtk_widget_queue_draw (GTK_WIDGET (row->priv->view)); -} - -static void -load_path (GdlDataRow *row) -{ - GdlDataIter iter; - - /* Make sure the path has been unloaded */ - g_return_if_fail (row->priv->name == NULL); - g_return_if_fail (row->priv->cell == NULL); - - if (gdl_data_model_get_iter (row->priv->model, - &iter, row->priv->path)) { - GValue val = { 0, }; - char *str; - - gdl_data_model_get_name (row->priv->model, &iter, - &str); - row->priv->name = g_strdup (str); - - if (gdl_data_model_iter_has_child (row->priv->model, &iter)) { - row->priv->multi = TRUE; - } - - gdl_data_model_get_renderer (row->priv->model, &iter, - &row->priv->cell, - &str, - &row->priv->editable); - g_object_ref (GTK_OBJECT (row->priv->cell)); - gtk_object_sink (GTK_OBJECT (row->priv->cell)); - - row->priv->renderer_field = g_strdup (str); - gdl_data_model_get_value (row->priv->model, &iter, &val); - - g_object_set_property (G_OBJECT (row->priv->cell), - row->priv->renderer_field, - &val); - g_value_unset (&val); - } -} - -static void -unload_path (GdlDataRow *row) -{ - if (row->priv->renderer_field) { - g_free (row->priv->renderer_field); - row->priv->renderer_field = NULL; - } - - if (row->priv->name) { - g_free (row->priv->name); - row->priv->name = NULL; - } - - if (row->priv->cell) { - g_object_unref (row->priv->cell); - row->priv->cell = NULL; - } - - if (row->priv->subrows) { - GList *l; - for (l = row->priv->subrows; l != NULL; l = l->next) { - g_object_unref (G_OBJECT (l->data)); - } - g_list_free (row->priv->subrows); - row->priv->subrows = NULL; - } -} - -static void -gdl_data_row_instance_init (GdlDataRow *row) -{ - row->priv = g_new0 (GdlDataRowPrivate, 1); -} - -static void -gdl_data_row_finalize (GObject *object) -{ - GdlDataRow *row = GDL_DATA_ROW (object); - if (row->priv) { - unload_path (row); - - if (row->priv->path) { - gtk_tree_path_free (row->priv->path); - row->priv->path = NULL; - } - - - g_object_unref (row->priv->model); - - g_free (row->priv); - row->priv = NULL; - } -} - -static void -gdl_data_row_class_init (GdlDataRowClass *klass) -{ - GObjectClass *gobject_class = (GObjectClass*) klass; - gobject_class->finalize = gdl_data_row_finalize; - - parent_class = g_type_class_peek_parent (klass); -} - -GdlDataRow * -gdl_data_row_new (GdlDataView *view, - GtkTreePath *path) -{ - GdlDataRow *row; - - row = GDL_DATA_ROW (g_object_new (gdl_data_row_get_type (), - NULL)); - - row->priv->view = view; - row->priv->model = g_object_ref (view->model); - row->priv->path = gtk_tree_path_copy (path); - load_path (row); - - return row; -} - - -#define PAD 3 - -static void -layout_row (GdlDataRow *row, - int x, int y, int width, int height) -{ - PangoLayout *layout; - - /* sizes */ - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (row->priv->view), - row->priv->name); - pango_layout_get_pixel_size (layout, - &row->priv->name_r.width, - &row->priv->name_r.height); - g_object_unref (layout); - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (row->priv->view), "="); - pango_layout_get_pixel_size (layout, - &row->priv->sep_r.width, - &row->priv->sep_r.height); - g_object_unref (layout); - - row->priv->title_r.width = - MAX (row->priv->name_r.width + row->priv->sep_r.width + PAD, - row->priv->split); - row->priv->title_r.height = - MAX (row->priv->name_r.height, row->priv->sep_r.width); - - if (row->priv->cell) { - gtk_cell_renderer_get_size (row->priv->cell, - GTK_WIDGET (row->priv->view), - NULL, NULL, NULL, - &row->priv->cell_r.width, - &row->priv->cell_r.height); - } else { - row->priv->cell_r.width = row->priv->cell_r.height = 0; - } - - row->priv->data_r.width = row->priv->cell_r.width; - row->priv->data_r.height = row->priv->cell_r.height; - - if (row->priv->multi) { - row->priv->expand_r.width = 10; - row->priv->expand_r.height = 10; - - row->priv->data_r.width += row->priv->expand_r.width; - row->priv->data_r.height = MAX (row->priv->expand_r.height, - row->priv->data_r.height); - - if (row->priv->expanded) { - GList *l; - int name_w = 0, data_w = 0; - for (l = row->priv->subrows; l != NULL; l = l->next) { - int w1, w2, h; - gdl_data_row_get_size (GDL_DATA_ROW (l->data), - &w1, &w2, NULL, &h); - name_w = MAX (name_w, w1); - data_w = MAX (data_w, w2); - row->priv->data_r.height += h; - } - row->priv->child_split = name_w; - row->priv->data_r.width = - MAX (name_w + data_w + 3 * PAD, - row->priv->data_r.width); - row->priv->data_r.height += 2 * PAD; - } - } - - row->priv->area_r.width = MAX (width, - row->priv->data_r.width + row->priv->title_r.width + PAD); - - row->priv->area_r.height = MAX (height, - (MAX (row->priv->data_r.height, - row->priv->title_r.height))); - - /* Positions */ - - row->priv->area_r.x = x; - row->priv->area_r.y = y; - - row->priv->title_r.x = x; - row->priv->title_r.y = y + ((row->priv->area_r.height) / 2) - (row->priv->title_r.height / 2); - - row->priv->name_r.x = x; - row->priv->name_r.y = y + ((row->priv->area_r.height) / 2) - (row->priv->name_r.height / 2); - - row->priv->sep_r.x = row->priv->title_r.x + row->priv->title_r.width - row->priv->sep_r.width; - row->priv->sep_r.y = y + ((row->priv->area_r.height) / 2) - (row->priv->sep_r.height / 2); - - row->priv->data_r.x = row->priv->title_r.x + row->priv->title_r.width + PAD; - row->priv->data_r.y = y; - - /* Readjust the data area size to fit */ - row->priv->data_r.width = row->priv->area_r.width - (row->priv->title_r.width + PAD); - row->priv->data_r.height = row->priv->area_r.height; - - if (row->priv->multi) { - row->priv->expand_r.x = row->priv->data_r.x; - row->priv->expand_r.y = row->priv->data_r.y + ((row->priv->cell_r.height) / 2) - (row->priv->expand_r.height / 2); - - row->priv->cell_r.y = row->priv->data_r.y; - row->priv->cell_r.height = MAX (row->priv->expand_r.height, row->priv->cell_r.height); - row->priv->cell_r.width = (row->priv->data_r.width - row->priv->expand_r.width); - - row->priv->cell_r.x = row->priv->expand_r.x + row->priv->expand_r.width; - } else { - row->priv->cell_r = row->priv->data_r; - } -} - -void -gdl_data_row_get_size (GdlDataRow *row, int *sep_width, - int *cell_width, int *total_width, int *height) -{ - layout_row (row, 0, 0, 0, 0); - - if (sep_width) { - *sep_width = row->priv->name_r.width + row->priv->sep_r.width + PAD; - } - - if (cell_width) *cell_width = row->priv->data_r.width; - if (total_width) *total_width = row->priv->area_r.width; - if (height) *height = row->priv->area_r.height; -} - -void -gdl_data_row_set_show_name (GdlDataRow *row, gboolean show_name) -{ -} - -void -gdl_data_row_layout (GdlDataRow *row, GdkRectangle *alloc) -{ - layout_row (row, alloc->x, alloc->y, alloc->width, alloc->height); - - if (row->priv->multi && row->priv->expanded) { - GList *l; - GdkRectangle sub; - sub.y = row->priv->expand_r.y + row->priv->expand_r.width + PAD; - sub.x = row->priv->data_r.x + PAD; - sub.width = row->priv->data_r.width - 2 * PAD; - sub.height = row->priv->data_r.height - 2 * PAD; - - for (l = row->priv->subrows; l != NULL; l = l->next) { - gdl_data_row_get_size (GDL_DATA_ROW (l->data), - NULL, NULL, NULL, &sub.height); - gdl_data_row_set_split (GDL_DATA_ROW (l->data), - row->priv->child_split); - gdl_data_row_layout (GDL_DATA_ROW (l->data), - &sub); - sub.y += sub.height; - } - } -} - -#if 0 -#define DRAWR(r) { gdk_draw_rectangle (drawable, GTK_WIDGET (row->priv->view)->style->text_gc[GTK_STATE_NORMAL],FALSE,row->priv->r.x,row->priv->r.y,row->priv->r.width, row->priv->r.height); } -#else -#define DRAWR(r) -#endif - - -void -gdl_data_row_render (GdlDataRow *row, GdkDrawable *drawable, - GdkRectangle *expose_area, - GtkCellRendererState flags) -{ - PangoLayout *layout; - - guint state = GTK_STATE_NORMAL; - - if (row->priv->selected) { - if (flags & GTK_CELL_RENDERER_SELECTED) - state = GTK_STATE_SELECTED; - else - state = GTK_STATE_ACTIVE; - gtk_paint_flat_box (GTK_WIDGET (row->priv->view)->style, - drawable, state, - GTK_SHADOW_NONE, expose_area, - GTK_WIDGET (row->priv->view), "cell_even", - row->priv->area_r.x, row->priv->area_r.y, - row->priv->area_r.width + 1, - row->priv->area_r.height + 1); - - } - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (row->priv->view), - row->priv->name); - gdk_draw_layout (drawable, - GTK_WIDGET (row->priv->view)->style->text_gc[state], - row->priv->name_r.x, row->priv->name_r.y, layout); - g_object_unref (layout); - DRAWR(name_r); - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (row->priv->view), "="); - gdk_draw_layout (drawable, - GTK_WIDGET (row->priv->view)->style->text_gc[state], - row->priv->sep_r.x, row->priv->sep_r.y, layout); - g_object_unref (layout); - DRAWR(sep_r); - DRAWR(title_r); - - if (row->priv->cell) { - if (row->priv->focused) { - gtk_paint_focus (GTK_WIDGET (row->priv->view)->style, - drawable, - GTK_WIDGET_STATE (GTK_WIDGET (row->priv->view)), - NULL, GTK_WIDGET (row->priv->view), - "treeview", - row->priv->cell_r.x - 1, - row->priv->cell_r.y - 1, - row->priv->cell_r.width + 2, - row->priv->cell_r.height + 2); - } - - gtk_cell_renderer_render (row->priv->cell, - drawable, GTK_WIDGET (row->priv->view), - &row->priv->area_r, - &row->priv->cell_r, - expose_area, - row->priv->selected ? GTK_CELL_RENDERER_SELECTED : 0); - DRAWR(cell_r); - } - if (row->priv->multi) { - gtk_paint_expander (GTK_WIDGET (row->priv->view)->style, - drawable, - GTK_WIDGET_STATE (GTK_WIDGET (row->priv->view)), - expose_area, - GTK_WIDGET (row->priv->view), - "gdldataview", - row->priv->expand_r.x + row->priv->expand_r.width / 2, - row->priv->expand_r.y + row->priv->expand_r.height / 2, - row->priv->expanded ? GTK_EXPANDER_EXPANDED : GTK_EXPANDER_COLLAPSED); - DRAWR(expand_r); - - if (row->priv->expanded) { - GList *l; - - for (l = row->priv->subrows; l != NULL; l = l->next) { - gdl_data_row_render (GDL_DATA_ROW (l->data), - drawable, - expose_area, flags); - } - } - gdk_draw_rectangle (drawable, - GTK_WIDGET (row->priv->view)->style->text_gc[GTK_STATE_NORMAL], - FALSE, - row->priv->data_r.x, - row->priv->data_r.y, - row->priv->data_r.width, - row->priv->data_r.height); - } - DRAWR(data_r); -} - - -GdlDataRow * -gdl_data_row_at (GdlDataRow *row, int x, int y) -{ - if (!GDL_POINT_IN (x, y, &row->priv->area_r)) { - return NULL; - } - - if (row->priv->multi && row->priv->expanded) { - GList *l; - for (l = row->priv->subrows; l != NULL; l = l->next) { - GdlDataRow *ret = gdl_data_row_at (GDL_DATA_ROW (l->data), x, y); - if (ret) - return ret; - } - } - - return row; -} - -static gboolean -button_press_event (GdlDataRow *row, GdkEventButton *event, - GtkCellEditable **editable_widget) -{ - if (editable_widget) - *editable_widget = NULL; - - if (GDL_POINT_IN (event->x, event->y, &row->priv->expand_r)) { - if (row->priv->expanded) - contract (row); - else - expand (row); - } - - if (GDL_POINT_IN (event->x, event->y, &row->priv->cell_r) - && row->priv->editable) { - g_return_val_if_fail (editable_widget, FALSE); - *editable_widget = gtk_cell_renderer_start_editing - (row->priv->cell, - (GdkEvent*)event, - GTK_WIDGET (row->priv->view), - "1:2:3", - &row->priv->area_r, - &row->priv->cell_r, - GTK_CELL_RENDERER_SELECTED); - } - - return FALSE; - -} - - -gboolean -gdl_data_row_event (GdlDataRow *row, GdkEvent *event, - GtkCellEditable **editable_widget) -{ - switch (((GdkEventAny *)event)->type) { - case GDK_BUTTON_PRESS: - return button_press_event (row, - (GdkEventButton *)event, - editable_widget); - default: - break; - } - return FALSE; -} - -void -gdl_data_row_get_cell_area (GdlDataRow *row, - GdkRectangle *rect) -{ - *rect = row->priv->cell_r; -} - -void -gdl_data_row_set_split (GdlDataRow *row, int split) -{ - row->priv->split = split; -} - -void -gdl_data_row_set_selected (GdlDataRow *row, gboolean selected) -{ - row->priv->selected = selected; - - /* FIXME: invalidate here */ - gtk_widget_queue_draw (GTK_WIDGET (row->priv->view)); -} - -void -gdl_data_row_set_focused (GdlDataRow *row, gboolean focused) -{ - row->priv->focused = focused; - - /* FIXME: invalidate here */ - gtk_widget_queue_draw (GTK_WIDGET (row->priv->view)); -} - -const char * -gdl_data_row_get_title (GdlDataRow *row) -{ - return row->priv->name; -} diff --git a/src/libgdl/gdl-data-row.h b/src/libgdl/gdl-data-row.h deleted file mode 100644 index d4928958d..000000000 --- a/src/libgdl/gdl-data-row.h +++ /dev/null @@ -1,90 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * This file is part of the GNOME Devtools Libraries. - * - * Copyright (C) 2001 Dave Camp <dave@ximian.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef GDL_DATA_ROW_H -#define GDL_DATA_ROW_H - -#include <glib.h> - -#include <glib-object.h> -#include <gtk/gtktreemodel.h> -#include <gtk/gtkcellrenderer.h> -#include <gdl/gdl-data-view.h> - -G_BEGIN_DECLS - -#define GDL_TYPE_DATA_ROW (gdl_data_row_get_type ()) -#define GDL_DATA_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDL_TYPE_DATA_ROW, GdlDataRow)) -#define GDL_DATA_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDL_TYPE_DATA_ROW, GdlDataRowClass)) -#define GDL_IS_DATA_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDL_TYPE_DATA_ROW)) -#define GDL_IS_DATA_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDL_TYPE_DATA_ROW)) - -typedef struct _GdlDataRow GdlDataRow; -typedef struct _GdlDataRowClass GdlDataRowClass; -typedef struct _GdlDataRowPrivate GdlDataRowPrivate; - -struct _GdlDataRow { - GObject parent; - - GdlDataRowPrivate *priv; -}; - -struct _GdlDataRowClass { - GObjectClass parent_class; -}; - -GType gdl_data_row_get_type (void); -GdlDataRow *gdl_data_row_new (GdlDataView *view, - GtkTreePath *path); -void gdl_data_row_get_size (GdlDataRow *row, - int *text_w, - int *cell_w, - int *total_width, - int *height); -void gdl_data_row_set_show_name (GdlDataRow *row, - gboolean show_name); -void gdl_data_row_layout (GdlDataRow *row, - GdkRectangle *alloc); -void gdl_data_row_render (GdlDataRow *row, - GdkDrawable *drawable, - GdkRectangle *expose_area, - GtkCellRendererState flags); -GdlDataRow *gdl_data_row_at (GdlDataRow *row, - int x, - int y); -gboolean gdl_data_row_event (GdlDataRow *row, - GdkEvent *event, - GtkCellEditable **editable_widget); -void gdl_data_row_get_cell_area (GdlDataRow *row, - GdkRectangle *rect); -void gdl_data_row_set_split (GdlDataRow *row, - int split); -void gdl_data_row_set_selected (GdlDataRow *row, - gboolean selected); -void gdl_data_row_set_focused (GdlDataRow *row, - gboolean focused); -const char *gdl_data_row_get_title (GdlDataRow *row); - - -G_END_DECLS - -#endif diff --git a/src/libgdl/gdl-data-view.c b/src/libgdl/gdl-data-view.c deleted file mode 100644 index 81e1795f7..000000000 --- a/src/libgdl/gdl-data-view.c +++ /dev/null @@ -1,526 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * This file is part of the GNOME Devtools Libraries. - * - * Copyright (C) 2001 Dave Camp <dave@ximian.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "gdl-i18n.h" -#include "gdl-tools.h" -#include "gdl-data-view.h" -#include "gdl-data-frame.h" - -#include "tree-expand.xpm" -#include "tree-contract.xpm" - -struct _GdlDataViewPrivate { - GList *frames; - GList *rows; - GList *widgets; - - GdlDataFrame *selected_frame; - GdlDataRow *selected_row; - - GtkCellEditable *editable; - - GdkPixbuf *close_pixbuf; - GdkPixbuf *expand_pixbuf; - GdkPixbuf *contract_pixbuf; -}; - -typedef struct { - GtkWidget *widget; - int x, y, height, width; -} ChildWidget; - -static void gdl_data_view_instance_init (GdlDataView *dv); -static void gdl_data_view_class_init (GdlDataViewClass *klass); - -GDL_CLASS_BOILERPLATE (GdlDataView, gdl_data_view, GtkLayout, GTK_TYPE_LAYOUT); - - -#define GRID_SPACING 15 - -static void -paint_grid (GtkWidget *widget, GdkDrawable *drawable, - int offset_x, int offset_y, int width, int height) -{ - GdlDataView *dv; - int x; - int y; - - g_return_if_fail (GDL_IS_DATA_VIEW (widget)); - dv = GDL_DATA_VIEW (widget); - - x = offset_x + ((GRID_SPACING - (offset_x % GRID_SPACING)) % GRID_SPACING); - - /* Draw grid points */ - for (; x < width; x += GRID_SPACING) { - y = offset_y + ((GRID_SPACING - (offset_y % GRID_SPACING)) % GRID_SPACING); - - for (; y < height; y += GRID_SPACING) { - gdk_draw_point (drawable, - widget->style->fg_gc[GTK_WIDGET_STATE (widget)], - x, y); - } - } -} - -static void -expose_frames (GdlDataView *view, GdkEventExpose *event) -{ - GList *l; - - for (l = view->priv->frames; l != NULL; l = l->next) { - GdkRectangle intersect; - GdlDataFrame *frame = GDL_DATA_FRAME (l->data); - if (gdk_rectangle_intersect (&frame->area, - &event->area, - &intersect)) { - gdl_data_frame_draw (GDL_DATA_FRAME (l->data), - GTK_LAYOUT(view)->bin_window, - &intersect); - } - } -} - -static void -expose_widgets (GdlDataView *view, GdkEventExpose *event) -{ - GList *l; - - for (l = view->priv->widgets; l != NULL; l = l->next) { - ChildWidget *child = l->data; - gtk_container_propagate_expose (GTK_CONTAINER (view), - child->widget, event); - } -} - -static gboolean -gdl_data_view_expose (GtkWidget *widget, - GdkEventExpose *event) -{ - if (GTK_WIDGET_DRAWABLE (widget)) { - if (event->window == GTK_LAYOUT (widget)->bin_window) { - paint_grid (widget, GTK_LAYOUT (widget)->bin_window, - event->area.x, event->area.y, - event->area.width, event->area.height); - expose_frames (GDL_DATA_VIEW (widget), event); - expose_widgets (GDL_DATA_VIEW (widget), event); - return TRUE; - } else { - GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event); - } - } - - return FALSE; -} - -static GdlDataFrame * -frame_at (GdlDataView *dv, int x, int y) -{ - GList *l; - for (l = dv->priv->frames; l != NULL; l = l->next) { - GdlDataFrame *frame = l->data; - if (x >= frame->area.x && x <= frame->area.x + frame->area.width - && y >= frame->area.y && y <= frame->area.y + frame->area.height) { - return frame; - } - } - return NULL; -} - -static GdlDataRow * -row_at (GdlDataView *view, int x, int y) -{ - GList *l; - GdlDataRow *ret = NULL; - for (l = view->priv->rows; l != NULL; l = l->next) { - GdlDataRow *row = l->data; - ret = gdl_data_row_at (row, x, y); - if (ret) break; - } - return ret; -} - -static void -gdl_data_view_put (GdlDataView *view, GtkWidget *widget, - int x, int y, int width, int height) -{ - ChildWidget *child = g_new0 (ChildWidget, 1); - - child->widget = widget; - child->x = x; - child->y = y; - child->width = width; - child->height = height; - - view->priv->widgets = g_list_append (view->priv->widgets, child); - - if (GTK_WIDGET_REALIZED (view)) { - gtk_widget_set_parent_window (child->widget, - GTK_LAYOUT (view)->bin_window); - } - - gtk_widget_set_parent (child->widget, GTK_WIDGET (view)); -} - -static void -stop_editing (GdlDataView *dv) -{ - if (dv->priv->editable) { - gtk_cell_editable_editing_done (dv->priv->editable); - gtk_cell_editable_remove_widget (dv->priv->editable); - } -} - -static void -remove_widget_cb (GtkCellEditable *cell_editable, GdlDataView *view) -{ - if (view->priv->editable) { - view->priv->editable = NULL; - gdl_data_row_set_focused (view->priv->selected_row, FALSE); - gtk_widget_grab_focus (GTK_WIDGET (view)); - gtk_container_remove (GTK_CONTAINER (view), - GTK_WIDGET (cell_editable)); - } -} - -static gboolean -button_press_event_cb (GdlDataView *dv, GdkEventButton *event, gpointer data) -{ - GdlDataFrame *frame; - GdlDataRow *row; - gboolean ret = FALSE; - - stop_editing (dv); - - if (event->type == GDK_BUTTON_PRESS) { - frame = frame_at (dv, event->x, event->y); - if (frame) { - if (dv->priv->selected_frame) { - gdl_data_frame_set_selected (dv->priv->selected_frame, FALSE); - } - gdl_data_frame_set_selected (frame, TRUE); - dv->priv->selected_frame = frame; - } - - row = row_at (dv, event->x, event->y); - if (row) { - GtkCellEditable *editable; - - if (dv->priv->selected_row) { - gdl_data_row_set_selected (dv->priv->selected_row, - FALSE); - } - dv->priv->selected_row = row; - gdl_data_row_set_selected (row, TRUE); - ret = gdl_data_row_event (row, (GdkEvent*)event, - &editable); - if (editable) { - GdkRectangle area; - dv->priv->editable = editable; - gtk_cell_editable_start_editing (editable, - (GdkEvent*)event); - - gdl_data_row_get_cell_area (row, &area); - gdl_data_view_put (dv, - GTK_WIDGET (editable), - area.x, - area.y, - area.width, - area.height); - - gtk_widget_grab_focus (GTK_WIDGET (editable)); - dv->priv->editable = editable; - gdl_data_row_set_focused (row, TRUE); - - g_signal_connect - (G_OBJECT (editable), - "remove_widget", - G_CALLBACK (remove_widget_cb), dv); - } - } - } - - return ret; -} - -static void -gdl_data_view_instance_init (GdlDataView *dv) -{ - GTK_WIDGET_SET_FLAGS (dv, GTK_CAN_FOCUS); - dv->priv = g_new0 (GdlDataViewPrivate, 1); - - g_signal_connect (G_OBJECT (dv), "button_press_event", - G_CALLBACK (button_press_event_cb), - NULL); - - dv->priv->close_pixbuf = gtk_widget_render_icon (GTK_WIDGET (dv), - "gtk-close", - GTK_ICON_SIZE_MENU, - "gdl-data-view-close"); - - dv->priv->expand_pixbuf = - gdk_pixbuf_new_from_xpm_data ((const char **)tree_expand_xpm); - - dv->priv->contract_pixbuf = - gdk_pixbuf_new_from_xpm_data ((const char **)tree_contract_xpm); -} - -static void -gdl_data_view_realize (GtkWidget *widget) -{ - GList *l; - GdlDataView *view = GDL_DATA_VIEW (widget); - - GDL_CALL_PARENT (GTK_WIDGET_CLASS, realize, (widget)); - - for (l = view->priv->widgets; l != NULL; l = l->next) { - ChildWidget *child = l->data; - gtk_widget_set_parent_window (child->widget, - GTK_LAYOUT (view)->bin_window); - } -} - -static void -gdl_data_view_size_request (GtkWidget *widget, GtkRequisition *req) -{ - GList *l; - - req->width = req->height = 0; - - for (l = GDL_DATA_VIEW (widget)->priv->widgets; l != NULL; l = l->next) { - GtkRequisition child_req; - ChildWidget *child = l->data; - - gtk_widget_size_request (child->widget, &child_req); - } -} - - -static void -gdl_data_view_size_allocate (GtkWidget *widget, GtkAllocation *alloc) -{ - GdlDataView *view = GDL_DATA_VIEW (widget); - GList *l; -; - for (l = view->priv->widgets; l != NULL; l = l->next) { - ChildWidget *child = l->data; - GtkAllocation child_alloc; - - child_alloc.x = child->x; - child_alloc.y = child->y; - child_alloc.width = child->width; - child_alloc.height = child->height; - - gtk_widget_size_allocate (child->widget, &child_alloc); - } - GDL_CALL_PARENT (GTK_WIDGET_CLASS, size_allocate, (widget, alloc)); -} - -static void -gdl_data_view_forall (GtkContainer *container, gboolean include_internals, - GtkCallback callback, gpointer callback_data) -{ - GdlDataView *view = GDL_DATA_VIEW (container); - GList *l; - - for (l = view->priv->widgets; l != NULL; l = l->next) { - ChildWidget *child = l->data; - (*callback) (child->widget, callback_data); - } -} - -static void -gdl_data_view_remove (GtkContainer *container, GtkWidget *widget) -{ - GList *l; - GdlDataView *view = GDL_DATA_VIEW (container); - - for (l = view->priv->widgets; l != NULL; l = l->next) { - ChildWidget *child = l->data; - if (child->widget == widget) { - gtk_widget_unparent (widget); - view->priv->widgets = - g_list_remove_link (view->priv->widgets, l); - g_list_free_1 (l); - g_free (child); - return; - } - } -} - -static void -gdl_data_view_destroy (GtkObject *obj) -{ - GdlDataView *dv = GDL_DATA_VIEW (obj); - - stop_editing (dv); - - if (dv->priv) { - GList *l; - for (l = dv->priv->frames; l != NULL; l = l->next) { - g_object_unref (G_OBJECT (l->data)); - } - g_list_free (dv->priv->frames); - - g_object_unref (dv->priv->close_pixbuf); - g_object_unref (dv->priv->expand_pixbuf); - g_object_unref (dv->priv->contract_pixbuf); - - g_free (dv->priv); - dv->priv = NULL; - } - GDL_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (obj)); -} - -static void -gdl_data_view_class_init (GdlDataViewClass *klass) -{ - GtkObjectClass *object_class = (GtkObjectClass *)klass; - GtkWidgetClass *widget_class = (GtkWidgetClass *)klass; - GtkContainerClass *container_class = (GtkContainerClass *)klass; - - parent_class = gtk_type_class (GTK_TYPE_LAYOUT); - - container_class->forall = gdl_data_view_forall; - container_class->remove = gdl_data_view_remove; - - widget_class->expose_event = gdl_data_view_expose; - widget_class->realize = gdl_data_view_realize; - /* FIXME: unrealize */ - widget_class->size_request = gdl_data_view_size_request; - widget_class->size_allocate = gdl_data_view_size_allocate; - object_class->destroy = gdl_data_view_destroy; - - gtk_widget_class_install_style_property (widget_class, - g_param_spec_int ("expander-size", - _("Expander Size"), - _("Size of the expander arrow."), - 0, - G_MAXINT, - 10, - G_PARAM_READABLE)); -} - -GtkWidget * -gdl_data_view_new (void) -{ - GdlDataView *dv; - dv = g_object_new (gdl_data_view_get_type (), NULL); - return GTK_WIDGET (dv); -} - -void -gdl_data_view_set_model (GdlDataView *dv, GdlDataModel *model) -{ - GtkTreePath *path; - GdlDataIter iter; - gboolean iter_valid; - int x = 5; - - dv->model = model; - - path = gtk_tree_path_new_from_string ("0"); - - iter_valid = gdl_data_model_get_iter (model, &iter, path); - gtk_tree_path_free (path); - - while (iter_valid) { - GdlDataFrame *frame; - GdlDataRow *row; - - path = gdl_data_model_get_path (model, &iter); - - row = gdl_data_row_new (dv, path); - frame = gdl_data_frame_new (dv, row); - gdl_data_frame_set_position (frame, x, 5); - - dv->priv->frames = g_list_append (dv->priv->frames, - frame); - dv->priv->rows = g_list_append (dv->priv->rows, row); - - gtk_tree_path_free (path); - - x += 150; - - iter_valid = gdl_data_model_iter_next (model, &iter); - } -} - -void -gdl_data_view_layout (GdlDataView *view) -{ - GList *l; - for (l = view->priv->frames; l != NULL; l = l->next) { - gdl_data_frame_layout (GDL_DATA_FRAME (l->data)); - } -} - -GdkPixbuf * -gdl_data_view_get_close_pixbuf (GdlDataView *view) -{ - return view->priv->close_pixbuf; -} - -void -gdl_data_view_set_close_pixbuf (GdlDataView *view, GdkPixbuf *pixbuf) -{ - if (view->priv->close_pixbuf) { - g_object_unref (view->priv->close_pixbuf); - } - - view->priv->close_pixbuf = g_object_ref (pixbuf); -} - -GdkPixbuf * -gdl_data_view_get_expand_pixbuf (GdlDataView *view) -{ - return view->priv->expand_pixbuf; -} - -void -gdl_data_view_set_expand_pixbuf (GdlDataView *view, GdkPixbuf *pixbuf) -{ - if (view->priv->expand_pixbuf) { - g_object_unref (view->priv->expand_pixbuf); - } - - view->priv->expand_pixbuf = g_object_ref (pixbuf); -} - -GdkPixbuf * -gdl_data_view_get_contract_pixbuf (GdlDataView *view) -{ - return view->priv->contract_pixbuf; -} - -void -gdl_data_view_set_contract_pixbuf (GdlDataView *view, GdkPixbuf *pixbuf) -{ - if (view->priv->contract_pixbuf) { - g_object_unref (view->priv->contract_pixbuf); - } - - view->priv->contract_pixbuf = g_object_ref (pixbuf); -} diff --git a/src/libgdl/gdl-data-view.h b/src/libgdl/gdl-data-view.h deleted file mode 100644 index 3a5db02f4..000000000 --- a/src/libgdl/gdl-data-view.h +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * This file is part of the GNOME Devtools Libraries. - * - * Copyright (C) 2001 Dave Camp <dave@ximian.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef GDL_DATA_VIEW_H -#define GDL_DATA_VIEW_H - -#include <gdl/gdl-data-model.h> -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define GDL_TYPE_DATA_VIEW (gdl_data_view_get_type ()) -#define GDL_DATA_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDL_TYPE_DATA_VIEW, GdlDataView)) -#define GDL_DATA_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDL_TYPE_DATA_VIEW, GdlDataViewClass)) -#define GDL_IS_DATA_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDL_TYPE_DATA_VIEW)) -#define GDL_IS_DATA_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDL_TYPE_DATA_VIEW)) -#define GDL_DATA_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDL_TYPE_DATA_VIEW, GdlDataViewClass)) - -typedef struct _GdlDataView GdlDataView; -typedef struct _GdlDataViewClass GdlDataViewClass; -typedef struct _GdlDataViewPrivate GdlDataViewPrivate; - -#define GDL_POINT_IN(x1,y1,r) ((x1) >= (r)->x && x1 < (r)->x + (r)->width && (y1) >= (r)->y && y1 < (r)->y + (r)->height) - -struct _GdlDataView { - GtkLayout layout; - - GdlDataModel *model; - - GdlDataViewPrivate *priv; -}; - -struct _GdlDataViewClass { - GtkLayoutClass parent_class; -}; - -GType gdl_data_view_get_type (void); -GtkWidget *gdl_data_view_new (void); -void gdl_data_view_set_model (GdlDataView *view, - GdlDataModel *model); -void gdl_data_view_layout (GdlDataView *view); -GdkPixbuf *gdl_data_view_get_close_pixbuf (GdlDataView *view); -void gdl_data_view_set_close_pixbuf (GdlDataView *view, - GdkPixbuf *pixbuf); -GdkPixbuf *gdl_data_view_get_expand_pixbuf (GdlDataView *view); -void gdl_data_view_set_expand_pixbuf (GdlDataView *view, - GdkPixbuf *pixbuf); -GdkPixbuf *gdl_data_view_get_contract_pixbuf (GdlDataView *view); -void gdl_data_view_set_contract_pixbuf (GdlDataView *view, - GdkPixbuf *pixbuf); - -#endif diff --git a/src/libgdl/gdl-icons.c b/src/libgdl/gdl-icons.c deleted file mode 100644 index 2af2a8a9a..000000000 --- a/src/libgdl/gdl-icons.c +++ /dev/null @@ -1,267 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* gdl-icons.c - * - * Copyright (C) 2000-2001 Dave Camp - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Dave Camp, Jeroen Zwartepoorte - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "gdl-i18n.h" -#include "gdl-tools.h" -#include <string.h> -#include <libgnomeui/gnome-icon-lookup.h> -#include <libgnomevfs/gnome-vfs-ops.h> -#include "gdl-icons.h" - -enum { - PROP_BOGUS, - PROP_ICON_SIZE, -}; - -#define GDL_ICONS_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GDL_TYPE_ICONS, GdlIconsPrivate)) - -typedef struct _GdlIconsPrivate GdlIconsPrivate; - -struct _GdlIconsPrivate { - int icon_size; - - GtkIconTheme *icon_theme; - GHashTable *icons; -}; - -GDL_CLASS_BOILERPLATE (GdlIcons, gdl_icons, GObject, G_TYPE_OBJECT); - -static void -gdl_icons_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - GdlIconsPrivate *priv = GDL_ICONS_GET_PRIVATE (object); - - switch (prop_id) { - case PROP_ICON_SIZE: - g_value_set_int (value, priv->icon_size); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -gdl_icons_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - GdlIconsPrivate *priv = GDL_ICONS_GET_PRIVATE (object); - - switch (prop_id) { - case PROP_ICON_SIZE: - priv->icon_size = g_value_get_int (value); - g_hash_table_destroy (priv->icons); - priv->icons = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) gdk_pixbuf_unref); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -theme_changed_cb (GtkIconTheme *theme, - gpointer user_data) -{ - GdlIconsPrivate *priv = GDL_ICONS_GET_PRIVATE (user_data); - - g_hash_table_destroy (priv->icons); - priv->icons = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) gdk_pixbuf_unref); -} - -static void -gdl_icons_dispose (GObject *object) -{ - GdlIconsPrivate *priv = GDL_ICONS_GET_PRIVATE (object); - - if (priv->icon_theme) { - /* Don't do that - look a GTK+ docs */ - /* g_object_unref (priv->icon_theme); */ - priv->icon_theme = NULL; - } - - if (priv->icons) { - g_hash_table_destroy (priv->icons); - priv->icons = NULL; - } -} - -static void -gdl_icons_class_init (GdlIconsClass *klass) -{ - GObjectClass *object_class = (GObjectClass *) klass; - - parent_class = g_type_class_peek_parent (klass); - - object_class->dispose = gdl_icons_dispose; - object_class->get_property = gdl_icons_get_property; - object_class->set_property = gdl_icons_set_property; - - g_object_class_install_property (object_class, PROP_ICON_SIZE, - g_param_spec_int ("icon-size", - _("Icon size"), - _("Icon size"), - 12, 256, 24, - G_PARAM_READWRITE)); - - g_type_class_add_private (object_class, sizeof (GdlIconsPrivate)); -} - -static void -gdl_icons_instance_init (GdlIcons *icons) -{ - GdlIconsPrivate *priv = GDL_ICONS_GET_PRIVATE (icons); - - priv->icon_theme = gtk_icon_theme_get_default (); - /* gtk_icon_theme_get_default() does not ref the returned object */ - /* but API docs state the you should NOT ref it */ - /* g_object_ref (priv->icon_theme);*/ - g_signal_connect_object (G_OBJECT (priv->icon_theme), "changed", - G_CALLBACK (theme_changed_cb), icons, 0); - priv->icons = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) gdk_pixbuf_unref); -} - -GdlIcons * -gdl_icons_new (int icon_size) -{ - return GDL_ICONS (g_object_new (GDL_TYPE_ICONS, - "icon-size", icon_size, - NULL)); -} - -GdkPixbuf * -gdl_icons_get_folder_icon (GdlIcons *icons) -{ - g_return_val_if_fail (icons != NULL, NULL); - g_return_val_if_fail (GDL_IS_ICONS (icons), NULL); - - return gdl_icons_get_mime_icon (icons, "application/directory-normal"); -} - -GdkPixbuf * -gdl_icons_get_uri_icon (GdlIcons *icons, - const char *uri) -{ - GnomeVFSFileInfo *info; - GdkPixbuf *pixbuf; - - g_return_val_if_fail (icons != NULL, NULL); - g_return_val_if_fail (GDL_IS_ICONS (icons), NULL); - g_return_val_if_fail (uri != NULL, NULL); - - info = gnome_vfs_file_info_new (); - gnome_vfs_get_file_info (uri, info, - GNOME_VFS_FILE_INFO_FOLLOW_LINKS | - GNOME_VFS_FILE_INFO_GET_MIME_TYPE | - GNOME_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE); - if (info->mime_type) - pixbuf = gdl_icons_get_mime_icon (icons, info->mime_type); - else - pixbuf = gdl_icons_get_mime_icon (icons, "gnome-fs-regular"); - gnome_vfs_file_info_unref (info); - - return pixbuf; -} - -GdkPixbuf * -gdl_icons_get_mime_icon (GdlIcons *icons, - const char *mime_type) -{ - GdkPixbuf *pixbuf; - char *icon_name; - - g_return_val_if_fail (icons != NULL, NULL); - g_return_val_if_fail (GDL_IS_ICONS (icons), NULL); - g_return_val_if_fail (mime_type != NULL, NULL); - - GdlIconsPrivate *priv = GDL_ICONS_GET_PRIVATE (icons); - - pixbuf = g_hash_table_lookup (priv->icons, mime_type); - if (pixbuf != NULL) { - g_object_ref (G_OBJECT (pixbuf)); - return pixbuf; - } - - if (!strcmp (mime_type, "application/directory-normal")) { - icon_name = g_strdup ("gnome-fs-directory"); - } else { - icon_name = gnome_icon_lookup (priv->icon_theme, - NULL, - NULL, - NULL, - NULL, - mime_type, - GNOME_ICON_LOOKUP_FLAGS_NONE, - NULL); - } - - if (!icon_name) { - /* Return regular icon if one doesn't exist for mime type. */ - if (!strcmp (mime_type, "gnome-fs-regular")) - return NULL; - else - return gdl_icons_get_mime_icon (icons, "gnome-fs-regular"); - } else { - if (!gtk_icon_theme_has_icon (priv->icon_theme, icon_name)) { - g_free (icon_name); - if (!strcmp (mime_type, "gnome-fs-regular")) - return NULL; - else - return gdl_icons_get_mime_icon (icons, "gnome-fs-regular"); - } else { - pixbuf = gtk_icon_theme_load_icon (priv->icon_theme, - icon_name, - priv->icon_size, - 0, /* lookup flags */ - NULL); - g_free (icon_name); - - if (pixbuf == NULL) { - if (!strcmp (mime_type, "gnome-fs-regular")) - return NULL; - else - return gdl_icons_get_mime_icon (icons, - "gnome-fs-regular"); - } - } - } - - g_hash_table_insert (priv->icons, g_strdup (mime_type), pixbuf); - g_object_ref (pixbuf); - - return pixbuf; -} diff --git a/src/libgdl/gdl-icons.h b/src/libgdl/gdl-icons.h deleted file mode 100644 index 79f3bba85..000000000 --- a/src/libgdl/gdl-icons.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* gdl-icons.h - * - * Copyright (C) 2000-2001 JP Rosevear - * 2000 Dave Camp - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Authors: JP Rosevear, Dave Camp, Jeroen Zwartepoorte - */ - -#ifndef _GDL_ICONS_H_ -#define _GDL_ICONS_H_ - -#include <glib-object.h> -#include <gdk-pixbuf/gdk-pixbuf.h> - -G_BEGIN_DECLS - -#define GDL_TYPE_ICONS (gdl_icons_get_type ()) -#define GDL_ICONS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDL_TYPE_ICONS, GdlIcons)) -#define GDL_ICONS_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((klass), GDL_TYPE_ICONS, GdlIconsClass)) -#define GDL_IS_ICONS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDL_TYPE_ICONS)) -#define GDL_IS_ICONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), GDL_TYPE_ICONS)) - -typedef struct _GdlIcons GdlIcons; -typedef struct _GdlIconsClass GdlIconsClass; - -struct _GdlIcons { - GObject parent; -}; - -struct _GdlIconsClass { - GObjectClass parent_class; -}; - -GType gdl_icons_get_type (void); -GdlIcons *gdl_icons_new (int icon_size); - -GdkPixbuf *gdl_icons_get_folder_icon (GdlIcons *icons); -GdkPixbuf *gdl_icons_get_uri_icon (GdlIcons *icons, - const char *uri); -GdkPixbuf *gdl_icons_get_mime_icon (GdlIcons *icons, - const char *mime_type); - -G_END_DECLS - -#endif /* _GDL_ICONS_H_ */ diff --git a/src/libgdl/test-dataview.c b/src/libgdl/test-dataview.c deleted file mode 100644 index bc89cbd4f..000000000 --- a/src/libgdl/test-dataview.c +++ /dev/null @@ -1,43 +0,0 @@ -#include <config.h> -#include <gtk/gtk.h> -#include <libgnome/libgnome.h> - -#include "gdl-data-view.h" -#include "gdl-data-model-test.h" - -int -main (int argc, char *argv[]) -{ - GtkWidget *win; - GtkWidget *view; - GdlDataModel *model; - GtkWidget *vbox; - - gtk_init (&argc, &argv); - - win = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_default_size (GTK_WINDOW (win), 500, 200); - - vbox = gtk_vbox_new (FALSE, 5); - - view = gdl_data_view_new (); - - gtk_layout_set_hadjustment (GTK_LAYOUT (view), NULL); - gtk_layout_set_vadjustment (GTK_LAYOUT (view), NULL); - - - model = GDL_DATA_MODEL (gdl_data_model_test_new ()); - gdl_data_view_set_model (GDL_DATA_VIEW (view), - model); - - gtk_box_pack_start (GTK_BOX (vbox), view, TRUE, TRUE, 0); - - gtk_container_add (GTK_CONTAINER (win), vbox); - - gtk_widget_show_all (win); - gtk_widget_grab_focus (GTK_WIDGET (view)); - - gtk_main (); - - return 0; -} |
