2010-11-08 16:26:38 +00:00
|
|
|
/* cellareascaffold.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Openismus GmbH
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Tristan Van Berkom <tristanvb@openismus.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "cellareascaffold.h"
|
|
|
|
|
|
|
|
/* GObjectClass */
|
|
|
|
static void cell_area_scaffold_finalize (GObject *object);
|
|
|
|
static void cell_area_scaffold_dispose (GObject *object);
|
|
|
|
|
|
|
|
/* GtkWidgetClass */
|
2010-11-10 10:17:06 +00:00
|
|
|
static void cell_area_scaffold_realize (GtkWidget *widget);
|
|
|
|
static void cell_area_scaffold_unrealize (GtkWidget *widget);
|
2010-11-08 16:26:38 +00:00
|
|
|
static gboolean cell_area_scaffold_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr);
|
|
|
|
static void cell_area_scaffold_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation);
|
|
|
|
static void cell_area_scaffold_get_preferred_width (GtkWidget *widget,
|
|
|
|
gint *minimum_size,
|
|
|
|
gint *natural_size);
|
|
|
|
static void cell_area_scaffold_get_preferred_height_for_width (GtkWidget *widget,
|
|
|
|
gint for_size,
|
|
|
|
gint *minimum_size,
|
|
|
|
gint *natural_size);
|
|
|
|
static void cell_area_scaffold_get_preferred_height (GtkWidget *widget,
|
|
|
|
gint *minimum_size,
|
|
|
|
gint *natural_size);
|
|
|
|
static void cell_area_scaffold_get_preferred_width_for_height (GtkWidget *widget,
|
|
|
|
gint for_size,
|
|
|
|
gint *minimum_size,
|
|
|
|
gint *natural_size);
|
2010-11-11 09:13:54 +00:00
|
|
|
static void cell_area_scaffold_map (GtkWidget *widget);
|
|
|
|
static void cell_area_scaffold_unmap (GtkWidget *widget);
|
2010-11-10 10:17:06 +00:00
|
|
|
static gint cell_area_scaffold_focus (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction);
|
2010-11-11 09:13:54 +00:00
|
|
|
static gboolean cell_area_scaffold_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event);
|
|
|
|
|
2010-11-12 10:25:07 +00:00
|
|
|
/* GtkContainerClass */
|
|
|
|
static void cell_area_scaffold_forall (GtkContainer *container,
|
|
|
|
gboolean include_internals,
|
|
|
|
GtkCallback callback,
|
|
|
|
gpointer callback_data);
|
|
|
|
static void cell_area_scaffold_remove (GtkContainer *container,
|
|
|
|
GtkWidget *child);
|
|
|
|
static void cell_area_scaffold_put_edit_widget (CellAreaScaffold *scaffold,
|
|
|
|
GtkWidget *edit_widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height);
|
2010-11-08 16:26:38 +00:00
|
|
|
|
2010-11-10 13:25:13 +00:00
|
|
|
/* CellAreaScaffoldClass */
|
|
|
|
static void cell_area_scaffold_activate (CellAreaScaffold *scaffold);
|
|
|
|
|
|
|
|
/* CellArea/GtkTreeModel callbacks */
|
2010-11-13 07:23:01 +00:00
|
|
|
static void size_changed_cb (GtkCellAreaContext *context,
|
2010-11-10 10:17:06 +00:00
|
|
|
GParamSpec *pspec,
|
|
|
|
CellAreaScaffold *scaffold);
|
2010-11-11 09:13:54 +00:00
|
|
|
static void focus_changed_cb (GtkCellArea *area,
|
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
const gchar *path,
|
|
|
|
CellAreaScaffold *scaffold);
|
2010-11-14 14:33:26 +00:00
|
|
|
static void add_editable_cb (GtkCellArea *area,
|
2010-11-12 10:25:07 +00:00
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
GtkCellEditable *edit_widget,
|
|
|
|
GdkRectangle *cell_area,
|
|
|
|
const gchar *path,
|
|
|
|
CellAreaScaffold *scaffold);
|
|
|
|
static void remove_editable_cb (GtkCellArea *area,
|
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
GtkCellEditable *edit_widget,
|
|
|
|
CellAreaScaffold *scaffold);
|
2010-11-10 13:25:13 +00:00
|
|
|
static void row_changed_cb (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
CellAreaScaffold *scaffold);
|
2010-11-12 10:25:07 +00:00
|
|
|
static void row_inserted_cb (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
CellAreaScaffold *scaffold);
|
|
|
|
static void row_deleted_cb (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
CellAreaScaffold *scaffold);
|
|
|
|
static void rows_reordered_cb (GtkTreeModel *model,
|
|
|
|
GtkTreePath *parent,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gint *new_order,
|
|
|
|
CellAreaScaffold *scaffold);
|
2010-11-08 16:26:38 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2010-12-02 08:10:10 +00:00
|
|
|
gint size; /* The height of rows in the scaffold's */
|
2010-11-08 16:26:38 +00:00
|
|
|
} RowData;
|
|
|
|
|
|
|
|
struct _CellAreaScaffoldPrivate {
|
|
|
|
|
2010-11-10 10:17:06 +00:00
|
|
|
/* Window for catching events and dispatching them to the cell area */
|
|
|
|
GdkWindow *event_window;
|
|
|
|
|
2010-11-08 16:26:38 +00:00
|
|
|
/* The model we're showing data for */
|
|
|
|
GtkTreeModel *model;
|
2010-11-10 13:25:13 +00:00
|
|
|
gulong row_changed_id;
|
|
|
|
gulong row_inserted_id;
|
|
|
|
gulong row_deleted_id;
|
|
|
|
gulong rows_reordered_id;
|
2010-11-08 16:26:38 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
/* The area rendering the data and a global context */
|
|
|
|
GtkCellArea *area;
|
|
|
|
GtkCellAreaContext *context;
|
2010-11-08 16:26:38 +00:00
|
|
|
|
|
|
|
/* Cache some info about rows (hieghts etc) */
|
|
|
|
GArray *row_data;
|
2010-11-09 05:09:47 +00:00
|
|
|
|
2010-11-10 10:17:06 +00:00
|
|
|
/* Focus handling */
|
|
|
|
gint focus_row;
|
2010-11-11 09:13:54 +00:00
|
|
|
gulong focus_changed_id;
|
2010-11-10 10:17:06 +00:00
|
|
|
|
|
|
|
/* Check when the underlying area changes the size and
|
|
|
|
* we need to queue a redraw */
|
2010-11-09 05:09:47 +00:00
|
|
|
gulong size_changed_id;
|
2010-11-10 13:25:13 +00:00
|
|
|
|
2010-11-12 10:25:07 +00:00
|
|
|
/* Currently edited widget */
|
|
|
|
GtkWidget *edit_widget;
|
|
|
|
GdkRectangle edit_rect;
|
2010-11-14 14:33:26 +00:00
|
|
|
gulong add_editable_id;
|
2010-11-12 10:25:07 +00:00
|
|
|
gulong remove_editable_id;
|
2010-11-12 12:55:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
gint row_spacing;
|
|
|
|
gint indent;
|
2010-11-08 16:26:38 +00:00
|
|
|
};
|
|
|
|
|
2010-11-10 13:25:13 +00:00
|
|
|
enum {
|
|
|
|
ACTIVATE,
|
|
|
|
N_SIGNALS
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint scaffold_signals[N_SIGNALS] = { 0 };
|
|
|
|
|
2010-11-10 10:17:06 +00:00
|
|
|
#define DIRECTION_STR(dir) \
|
|
|
|
((dir) == GTK_DIR_TAB_FORWARD ? "tab forward" : \
|
|
|
|
(dir) == GTK_DIR_TAB_BACKWARD ? "tab backward" : \
|
|
|
|
(dir) == GTK_DIR_UP ? "up" : \
|
|
|
|
(dir) == GTK_DIR_DOWN ? "down" : \
|
|
|
|
(dir) == GTK_DIR_LEFT ? "left" : \
|
|
|
|
(dir) == GTK_DIR_RIGHT ? "right" : "invalid")
|
|
|
|
|
2010-11-12 10:25:07 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (CellAreaScaffold, cell_area_scaffold, GTK_TYPE_CONTAINER,
|
2010-11-08 16:26:38 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL));
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
cell_area_scaffold_init (CellAreaScaffold *scaffold)
|
|
|
|
{
|
|
|
|
CellAreaScaffoldPrivate *priv;
|
|
|
|
|
|
|
|
scaffold->priv = G_TYPE_INSTANCE_GET_PRIVATE (scaffold,
|
|
|
|
TYPE_CELL_AREA_SCAFFOLD,
|
|
|
|
CellAreaScaffoldPrivate);
|
|
|
|
priv = scaffold->priv;
|
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
priv->area = gtk_cell_area_box_new ();
|
|
|
|
priv->context = gtk_cell_area_create_context (priv->area);
|
2010-11-08 16:26:38 +00:00
|
|
|
|
|
|
|
priv->row_data = g_array_new (FALSE, FALSE, sizeof (RowData));
|
|
|
|
|
|
|
|
gtk_widget_set_has_window (GTK_WIDGET (scaffold), FALSE);
|
2010-11-10 10:17:06 +00:00
|
|
|
gtk_widget_set_can_focus (GTK_WIDGET (scaffold), TRUE);
|
|
|
|
|
2010-11-12 10:25:07 +00:00
|
|
|
priv->size_changed_id =
|
2010-11-13 07:23:01 +00:00
|
|
|
g_signal_connect (priv->context, "notify",
|
2010-11-12 10:25:07 +00:00
|
|
|
G_CALLBACK (size_changed_cb), scaffold);
|
|
|
|
|
2010-11-11 09:13:54 +00:00
|
|
|
priv->focus_changed_id =
|
|
|
|
g_signal_connect (priv->area, "focus-changed",
|
|
|
|
G_CALLBACK (focus_changed_cb), scaffold);
|
|
|
|
|
2010-11-14 14:33:26 +00:00
|
|
|
priv->add_editable_id =
|
|
|
|
g_signal_connect (priv->area, "add-editable",
|
|
|
|
G_CALLBACK (add_editable_cb), scaffold);
|
2010-11-12 10:25:07 +00:00
|
|
|
|
|
|
|
priv->remove_editable_id =
|
|
|
|
g_signal_connect (priv->area, "remove-editable",
|
|
|
|
G_CALLBACK (remove_editable_cb), scaffold);
|
2010-11-08 16:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cell_area_scaffold_class_init (CellAreaScaffoldClass *class)
|
|
|
|
{
|
2010-11-12 10:25:07 +00:00
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GtkWidgetClass *widget_class;
|
|
|
|
GtkContainerClass *container_class;
|
2010-11-08 16:26:38 +00:00
|
|
|
|
2010-11-12 10:25:07 +00:00
|
|
|
gobject_class = G_OBJECT_CLASS (class);
|
2010-11-08 16:26:38 +00:00
|
|
|
gobject_class->dispose = cell_area_scaffold_dispose;
|
|
|
|
gobject_class->finalize = cell_area_scaffold_finalize;
|
|
|
|
|
2010-11-12 10:25:07 +00:00
|
|
|
widget_class = GTK_WIDGET_CLASS (class);
|
2010-11-10 10:17:06 +00:00
|
|
|
widget_class->realize = cell_area_scaffold_realize;
|
|
|
|
widget_class->unrealize = cell_area_scaffold_unrealize;
|
2010-11-08 16:26:38 +00:00
|
|
|
widget_class->draw = cell_area_scaffold_draw;
|
|
|
|
widget_class->size_allocate = cell_area_scaffold_size_allocate;
|
|
|
|
widget_class->get_preferred_width = cell_area_scaffold_get_preferred_width;
|
|
|
|
widget_class->get_preferred_height_for_width = cell_area_scaffold_get_preferred_height_for_width;
|
|
|
|
widget_class->get_preferred_height = cell_area_scaffold_get_preferred_height;
|
|
|
|
widget_class->get_preferred_width_for_height = cell_area_scaffold_get_preferred_width_for_height;
|
2010-11-11 09:13:54 +00:00
|
|
|
widget_class->map = cell_area_scaffold_map;
|
|
|
|
widget_class->unmap = cell_area_scaffold_unmap;
|
2010-11-10 10:17:06 +00:00
|
|
|
widget_class->focus = cell_area_scaffold_focus;
|
2010-11-11 09:13:54 +00:00
|
|
|
widget_class->button_press_event = cell_area_scaffold_button_press;
|
2010-11-10 13:25:13 +00:00
|
|
|
|
2010-11-12 10:25:07 +00:00
|
|
|
container_class = GTK_CONTAINER_CLASS (class);
|
|
|
|
container_class->forall = cell_area_scaffold_forall;
|
|
|
|
container_class->remove = cell_area_scaffold_remove;
|
|
|
|
|
2010-11-10 13:25:13 +00:00
|
|
|
class->activate = cell_area_scaffold_activate;
|
2010-11-08 16:26:38 +00:00
|
|
|
|
2010-11-10 13:25:13 +00:00
|
|
|
scaffold_signals[ACTIVATE] =
|
|
|
|
g_signal_new ("activate",
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
G_STRUCT_OFFSET (CellAreaScaffoldClass, activate),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
widget_class->activate_signal = scaffold_signals[ACTIVATE];
|
|
|
|
|
|
|
|
|
2010-11-08 16:26:38 +00:00
|
|
|
g_type_class_add_private (gobject_class, sizeof (CellAreaScaffoldPrivate));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************
|
|
|
|
* GObjectClass *
|
|
|
|
*********************************************************/
|
|
|
|
static void
|
|
|
|
cell_area_scaffold_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
CellAreaScaffold *scaffold = CELL_AREA_SCAFFOLD (object);
|
|
|
|
CellAreaScaffoldPrivate *priv;
|
|
|
|
|
|
|
|
priv = scaffold->priv;
|
|
|
|
|
|
|
|
g_array_free (priv->row_data, TRUE);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (cell_area_scaffold_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cell_area_scaffold_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
CellAreaScaffold *scaffold = CELL_AREA_SCAFFOLD (object);
|
|
|
|
CellAreaScaffoldPrivate *priv;
|
|
|
|
|
|
|
|
priv = scaffold->priv;
|
|
|
|
|
|
|
|
cell_area_scaffold_set_model (scaffold, NULL);
|
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
if (priv->context)
|
2010-11-08 16:26:38 +00:00
|
|
|
{
|
2010-11-09 05:09:47 +00:00
|
|
|
/* Disconnect signals */
|
2010-11-13 07:23:01 +00:00
|
|
|
g_signal_handler_disconnect (priv->context, priv->size_changed_id);
|
2010-11-09 05:09:47 +00:00
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_object_unref (priv->context);
|
|
|
|
priv->context = NULL;
|
2010-11-09 05:09:47 +00:00
|
|
|
priv->size_changed_id = 0;
|
2010-11-08 16:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->area)
|
|
|
|
{
|
2010-11-10 10:17:06 +00:00
|
|
|
/* Disconnect signals */
|
2010-11-11 09:13:54 +00:00
|
|
|
g_signal_handler_disconnect (priv->area, priv->focus_changed_id);
|
2010-11-14 14:33:26 +00:00
|
|
|
g_signal_handler_disconnect (priv->area, priv->add_editable_id);
|
2010-11-12 10:25:07 +00:00
|
|
|
g_signal_handler_disconnect (priv->area, priv->remove_editable_id);
|
2010-11-11 09:13:54 +00:00
|
|
|
|
2010-11-08 16:26:38 +00:00
|
|
|
g_object_unref (priv->area);
|
|
|
|
priv->area = NULL;
|
2010-11-11 09:13:54 +00:00
|
|
|
priv->focus_changed_id = 0;
|
2010-11-08 16:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (cell_area_scaffold_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************
|
|
|
|
* GtkWidgetClass *
|
|
|
|
*********************************************************/
|
2010-11-10 10:17:06 +00:00
|
|
|
static void
|
|
|
|
cell_area_scaffold_realize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
CellAreaScaffold *scaffold = CELL_AREA_SCAFFOLD (widget);
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
|
|
|
GtkAllocation allocation;
|
|
|
|
GdkWindow *window;
|
|
|
|
GdkWindowAttr attributes;
|
|
|
|
gint attributes_mask;
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
|
|
|
gtk_widget_set_realized (widget, TRUE);
|
|
|
|
|
|
|
|
attributes.window_type = GDK_WINDOW_CHILD;
|
|
|
|
attributes.x = allocation.x;
|
|
|
|
attributes.y = allocation.y;
|
|
|
|
attributes.width = allocation.width;
|
|
|
|
attributes.height = allocation.height;
|
|
|
|
attributes.wclass = GDK_INPUT_ONLY;
|
|
|
|
attributes.event_mask = gtk_widget_get_events (widget);
|
|
|
|
attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK |
|
|
|
|
GDK_KEY_PRESS_MASK |
|
|
|
|
GDK_KEY_RELEASE_MASK);
|
|
|
|
|
|
|
|
attributes_mask = GDK_WA_X | GDK_WA_Y;
|
|
|
|
|
|
|
|
window = gtk_widget_get_parent_window (widget);
|
|
|
|
gtk_widget_set_window (widget, window);
|
|
|
|
g_object_ref (window);
|
|
|
|
|
2010-11-11 09:13:54 +00:00
|
|
|
priv->event_window = gdk_window_new (window, &attributes, attributes_mask);
|
2010-11-10 10:17:06 +00:00
|
|
|
gdk_window_set_user_data (priv->event_window, widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cell_area_scaffold_unrealize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
CellAreaScaffold *scaffold = CELL_AREA_SCAFFOLD (widget);
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
|
|
|
|
|
|
|
if (priv->event_window)
|
|
|
|
{
|
|
|
|
gdk_window_set_user_data (priv->event_window, NULL);
|
|
|
|
gdk_window_destroy (priv->event_window);
|
|
|
|
priv->event_window = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (cell_area_scaffold_parent_class)->unrealize (widget);
|
|
|
|
}
|
|
|
|
|
2010-11-08 16:26:38 +00:00
|
|
|
static gboolean
|
|
|
|
cell_area_scaffold_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
CellAreaScaffold *scaffold = CELL_AREA_SCAFFOLD (widget);
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean valid;
|
2010-11-12 12:55:28 +00:00
|
|
|
GdkRectangle background_area;
|
2010-11-08 16:26:38 +00:00
|
|
|
GdkRectangle render_area;
|
|
|
|
GtkAllocation allocation;
|
|
|
|
gint i = 0;
|
2010-11-10 10:17:06 +00:00
|
|
|
gboolean have_focus;
|
|
|
|
GtkCellRendererState flags;
|
2010-11-08 16:26:38 +00:00
|
|
|
|
|
|
|
if (!priv->model)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-11-10 10:17:06 +00:00
|
|
|
have_focus = gtk_widget_has_focus (widget);
|
2010-11-08 16:26:38 +00:00
|
|
|
|
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
|
|
|
render_area.x = 0;
|
|
|
|
render_area.y = 0;
|
|
|
|
render_area.width = allocation.width;
|
|
|
|
render_area.height = allocation.height;
|
|
|
|
|
2010-11-12 12:55:28 +00:00
|
|
|
background_area = render_area;
|
|
|
|
|
2010-12-02 08:10:10 +00:00
|
|
|
render_area.x = priv->indent;
|
|
|
|
render_area.width -= priv->indent;
|
2010-11-12 12:55:28 +00:00
|
|
|
|
2010-11-08 16:26:38 +00:00
|
|
|
valid = gtk_tree_model_get_iter_first (priv->model, &iter);
|
|
|
|
while (valid)
|
|
|
|
{
|
|
|
|
RowData *data = &g_array_index (priv->row_data, RowData, i);
|
|
|
|
|
2010-11-10 10:17:06 +00:00
|
|
|
if (have_focus && i == priv->focus_row)
|
|
|
|
flags = GTK_CELL_RENDERER_FOCUSED;
|
|
|
|
else
|
|
|
|
flags = 0;
|
|
|
|
|
2010-12-02 08:10:10 +00:00
|
|
|
render_area.height = data->size;
|
2010-11-12 12:55:28 +00:00
|
|
|
|
2010-12-02 08:10:10 +00:00
|
|
|
background_area.height = render_area.height;
|
|
|
|
background_area.y = render_area.y;
|
2010-11-12 12:55:28 +00:00
|
|
|
|
2010-12-02 08:10:10 +00:00
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
background_area.height += priv->row_spacing / 2;
|
|
|
|
background_area.height += priv->row_spacing % 2;
|
2010-11-08 16:26:38 +00:00
|
|
|
}
|
2010-12-02 08:10:10 +00:00
|
|
|
else if (i == priv->row_data->len - 1)
|
2010-11-08 16:26:38 +00:00
|
|
|
{
|
2010-12-02 08:10:10 +00:00
|
|
|
background_area.y -= priv->row_spacing / 2;
|
|
|
|
background_area.height += priv->row_spacing / 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
background_area.y -= priv->row_spacing / 2;
|
|
|
|
background_area.height += priv->row_spacing;
|
2010-11-08 16:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_cell_area_apply_attributes (priv->area, priv->model, &iter, FALSE, FALSE);
|
2010-11-13 07:23:01 +00:00
|
|
|
gtk_cell_area_render (priv->area, priv->context, widget, cr,
|
2010-11-12 12:55:28 +00:00
|
|
|
&background_area, &render_area, flags,
|
2010-11-11 07:13:06 +00:00
|
|
|
(have_focus && i == priv->focus_row));
|
2010-11-08 16:26:38 +00:00
|
|
|
|
2010-12-02 08:10:10 +00:00
|
|
|
render_area.y += data->size;
|
|
|
|
render_area.y += priv->row_spacing;
|
2010-11-08 16:26:38 +00:00
|
|
|
|
|
|
|
i++;
|
|
|
|
valid = gtk_tree_model_iter_next (priv->model, &iter);
|
|
|
|
}
|
|
|
|
|
2010-11-12 10:25:07 +00:00
|
|
|
/* Draw the edit widget after drawing everything else */
|
|
|
|
GTK_WIDGET_CLASS (cell_area_scaffold_parent_class)->draw (widget, cr);
|
|
|
|
|
2010-11-08 16:26:38 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
request_all_base (CellAreaScaffold *scaffold)
|
|
|
|
{
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
|
|
|
GtkWidget *widget = GTK_WIDGET (scaffold);
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean valid;
|
|
|
|
|
|
|
|
if (!priv->model)
|
|
|
|
return;
|
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_signal_handler_block (priv->context, priv->size_changed_id);
|
2010-11-09 05:09:47 +00:00
|
|
|
|
2010-11-08 16:26:38 +00:00
|
|
|
valid = gtk_tree_model_get_iter_first (priv->model, &iter);
|
|
|
|
while (valid)
|
|
|
|
{
|
|
|
|
gint min, nat;
|
|
|
|
|
|
|
|
gtk_cell_area_apply_attributes (priv->area, priv->model, &iter, FALSE, FALSE);
|
2010-12-02 08:10:10 +00:00
|
|
|
gtk_cell_area_get_preferred_width (priv->area, priv->context, widget, &min, &nat);
|
2010-11-08 16:26:38 +00:00
|
|
|
|
|
|
|
valid = gtk_tree_model_iter_next (priv->model, &iter);
|
|
|
|
}
|
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
g_signal_handler_unblock (priv->context, priv->size_changed_id);
|
2010-11-08 16:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_row_sizes (CellAreaScaffold *scaffold,
|
|
|
|
GArray *array,
|
|
|
|
gint for_size)
|
|
|
|
{
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
|
|
|
GtkWidget *widget = GTK_WIDGET (scaffold);
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean valid;
|
|
|
|
gint i = 0;
|
|
|
|
|
|
|
|
if (!priv->model)
|
|
|
|
return;
|
|
|
|
|
|
|
|
valid = gtk_tree_model_get_iter_first (priv->model, &iter);
|
|
|
|
while (valid)
|
|
|
|
{
|
|
|
|
RowData *data = &g_array_index (array, RowData, i);
|
|
|
|
|
|
|
|
gtk_cell_area_apply_attributes (priv->area, priv->model, &iter, FALSE, FALSE);
|
2010-12-02 08:10:10 +00:00
|
|
|
gtk_cell_area_get_preferred_height_for_width (priv->area, priv->context, widget,
|
|
|
|
for_size, &data->size, NULL);
|
2010-11-08 16:26:38 +00:00
|
|
|
|
|
|
|
i++;
|
|
|
|
valid = gtk_tree_model_iter_next (priv->model, &iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cell_area_scaffold_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
|
|
|
{
|
|
|
|
CellAreaScaffold *scaffold = CELL_AREA_SCAFFOLD (widget);
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
|
|
|
|
|
|
|
gtk_widget_set_allocation (widget, allocation);
|
|
|
|
|
2010-11-10 10:17:06 +00:00
|
|
|
if (gtk_widget_get_realized (widget))
|
|
|
|
gdk_window_move_resize (priv->event_window,
|
|
|
|
allocation->x,
|
|
|
|
allocation->y,
|
|
|
|
allocation->width,
|
|
|
|
allocation->height);
|
|
|
|
|
2010-11-12 10:25:07 +00:00
|
|
|
/* Allocate the child GtkCellEditable widget if one is currently editing a row */
|
|
|
|
if (priv->edit_widget)
|
|
|
|
gtk_widget_size_allocate (priv->edit_widget, &priv->edit_rect);
|
|
|
|
|
2010-11-11 09:13:54 +00:00
|
|
|
if (!priv->model)
|
|
|
|
return;
|
|
|
|
|
2010-11-13 07:23:01 +00:00
|
|
|
/* Cache the per-row sizes and allocate the context */
|
2010-12-02 08:10:10 +00:00
|
|
|
gtk_cell_area_context_allocate (priv->context, allocation->width - priv->indent, -1);
|
|
|
|
get_row_sizes (scaffold, priv->row_data, allocation->width - priv->indent);
|
2010-11-08 16:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
cell_area_scaffold_get_preferred_width (GtkWidget *widget,
|
|
|
|
gint *minimum_size,
|
|
|
|
gint *natural_size)
|
|
|
|
{
|
|
|
|
CellAreaScaffold *scaffold = CELL_AREA_SCAFFOLD (widget);
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
|
|
|
|
|
|
|
if (!priv->model)
|
|
|
|
return;
|
|
|
|
|
2010-12-02 08:10:10 +00:00
|
|
|
request_all_base (scaffold);
|
|
|
|
gtk_cell_area_context_get_preferred_width (priv->context, minimum_size, natural_size);
|
|
|
|
|
|
|
|
*minimum_size += priv->indent;
|
|
|
|
*natural_size += priv->indent;
|
2010-11-08 16:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cell_area_scaffold_get_preferred_height_for_width (GtkWidget *widget,
|
|
|
|
gint for_size,
|
|
|
|
gint *minimum_size,
|
|
|
|
gint *natural_size)
|
|
|
|
{
|
|
|
|
CellAreaScaffold *scaffold = CELL_AREA_SCAFFOLD (widget);
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
2010-12-02 08:10:10 +00:00
|
|
|
GArray *request_array;
|
|
|
|
gint n_rows, i, full_size = 0;
|
2010-11-08 16:26:38 +00:00
|
|
|
|
|
|
|
if (!priv->model)
|
|
|
|
return;
|
|
|
|
|
2010-12-02 08:10:10 +00:00
|
|
|
n_rows = gtk_tree_model_iter_n_children (priv->model, NULL);
|
2010-11-08 16:26:38 +00:00
|
|
|
|
2010-12-02 08:10:10 +00:00
|
|
|
/* Get an array for the contextual request */
|
|
|
|
request_array = g_array_new (FALSE, FALSE, sizeof (RowData));
|
|
|
|
g_array_set_size (request_array, n_rows);
|
|
|
|
memset (request_array->data, 0x0, n_rows * sizeof (RowData));
|
2010-11-08 16:26:38 +00:00
|
|
|
|
2010-12-02 08:10:10 +00:00
|
|
|
/* Gather each contextual size into the request array */
|
|
|
|
get_row_sizes (scaffold, request_array, for_size - priv->indent);
|
2010-11-08 16:26:38 +00:00
|
|
|
|
2010-12-02 08:10:10 +00:00
|
|
|
/* Sum up the size and add some row spacing */
|
|
|
|
for (i = 0; i < n_rows; i++)
|
2010-11-08 16:26:38 +00:00
|
|
|
{
|
2010-12-02 08:10:10 +00:00
|
|
|
RowData *data = &g_array_index (request_array, RowData, i);
|
|
|
|
|
|
|
|
full_size += data->size;
|
2010-11-08 16:26:38 +00:00
|
|
|
}
|
2010-12-02 08:10:10 +00:00
|
|
|
|
|
|
|
full_size += MAX (0, n_rows -1) * priv->row_spacing;
|
|
|
|
|
|
|
|
g_array_free (request_array, TRUE);
|
|
|
|
|
|
|
|
*minimum_size = full_size;
|
|
|
|
*natural_size = full_size;
|
2010-11-08 16:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cell_area_scaffold_get_preferred_height (GtkWidget *widget,
|
|
|
|
gint *minimum_size,
|
|
|
|
gint *natural_size)
|
|
|
|
{
|
|
|
|
CellAreaScaffold *scaffold = CELL_AREA_SCAFFOLD (widget);
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
2010-12-02 08:10:10 +00:00
|
|
|
gint min_size, nat_size;
|
2010-11-08 16:26:38 +00:00
|
|
|
|
|
|
|
if (!priv->model)
|
|
|
|
return;
|
|
|
|
|
2010-12-02 08:10:10 +00:00
|
|
|
GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_size, &nat_size);
|
|
|
|
GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_size,
|
|
|
|
minimum_size, natural_size);
|
2010-11-08 16:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cell_area_scaffold_get_preferred_width_for_height (GtkWidget *widget,
|
|
|
|
gint for_size,
|
|
|
|
gint *minimum_size,
|
|
|
|
gint *natural_size)
|
|
|
|
{
|
|
|
|
CellAreaScaffold *scaffold = CELL_AREA_SCAFFOLD (widget);
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
|
|
|
|
|
|
|
if (!priv->model)
|
|
|
|
return;
|
|
|
|
|
2010-12-02 08:10:10 +00:00
|
|
|
GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_size, natural_size);
|
2010-11-08 16:26:38 +00:00
|
|
|
}
|
|
|
|
|
2010-11-11 09:13:54 +00:00
|
|
|
static void
|
|
|
|
cell_area_scaffold_map (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
CellAreaScaffold *scaffold = CELL_AREA_SCAFFOLD (widget);
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (cell_area_scaffold_parent_class)->map (widget);
|
|
|
|
|
|
|
|
if (priv->event_window)
|
|
|
|
gdk_window_show (priv->event_window);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cell_area_scaffold_unmap (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
CellAreaScaffold *scaffold = CELL_AREA_SCAFFOLD (widget);
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (cell_area_scaffold_parent_class)->unmap (widget);
|
|
|
|
|
|
|
|
if (priv->event_window)
|
|
|
|
gdk_window_hide (priv->event_window);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-10 10:17:06 +00:00
|
|
|
static gint
|
|
|
|
cell_area_scaffold_focus (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction)
|
|
|
|
{
|
2010-11-10 13:25:13 +00:00
|
|
|
CellAreaScaffold *scaffold = CELL_AREA_SCAFFOLD (widget);
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean valid;
|
|
|
|
gint focus_row;
|
2010-11-11 09:13:54 +00:00
|
|
|
gboolean changed = FALSE;
|
2010-11-10 10:17:06 +00:00
|
|
|
|
|
|
|
/* Grab focus on ourself if we dont already have focus */
|
|
|
|
if (!gtk_widget_has_focus (widget))
|
2010-11-10 13:25:13 +00:00
|
|
|
gtk_widget_grab_focus (widget);
|
|
|
|
|
|
|
|
/* Move focus from cell to cell and row to row */
|
|
|
|
focus_row = priv->focus_row;
|
2010-11-11 09:13:54 +00:00
|
|
|
|
|
|
|
g_signal_handler_block (priv->area, priv->focus_changed_id);
|
2010-11-10 13:25:13 +00:00
|
|
|
|
|
|
|
valid = gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, priv->focus_row);
|
|
|
|
while (valid)
|
2010-11-10 10:17:06 +00:00
|
|
|
{
|
2010-11-10 13:25:13 +00:00
|
|
|
gtk_cell_area_apply_attributes (priv->area, priv->model, &iter, FALSE, FALSE);
|
|
|
|
|
|
|
|
/* If focus stays in the area we dont need to do any more */
|
|
|
|
if (gtk_cell_area_focus (priv->area, direction))
|
|
|
|
{
|
|
|
|
priv->focus_row = focus_row;
|
2010-11-11 07:13:06 +00:00
|
|
|
|
|
|
|
/* XXX A smarter implementation would only invalidate the rectangles where
|
|
|
|
* focus was removed from and new focus was placed */
|
|
|
|
gtk_widget_queue_draw (widget);
|
2010-11-11 09:13:54 +00:00
|
|
|
changed = TRUE;
|
|
|
|
break;
|
2010-11-10 13:25:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-02 08:10:10 +00:00
|
|
|
if (direction == GTK_DIR_RIGHT ||
|
|
|
|
direction == GTK_DIR_LEFT)
|
|
|
|
break;
|
|
|
|
else if (direction == GTK_DIR_UP ||
|
|
|
|
direction == GTK_DIR_TAB_BACKWARD)
|
2010-11-10 13:25:13 +00:00
|
|
|
{
|
2010-12-02 08:10:10 +00:00
|
|
|
if (focus_row == 0)
|
2010-11-10 13:25:13 +00:00
|
|
|
break;
|
2010-12-02 08:10:10 +00:00
|
|
|
else
|
2010-11-10 13:25:13 +00:00
|
|
|
{
|
2010-12-02 08:10:10 +00:00
|
|
|
/* XXX A real implementation should check if the
|
|
|
|
* previous row can focus with it's attributes setup */
|
|
|
|
focus_row--;
|
|
|
|
valid = gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, focus_row);
|
2010-11-10 13:25:13 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-02 08:10:10 +00:00
|
|
|
else /* direction == GTK_DIR_DOWN || GTK_DIR_TAB_FORWARD */
|
2010-11-10 13:25:13 +00:00
|
|
|
{
|
2010-12-02 08:10:10 +00:00
|
|
|
if (focus_row == priv->row_data->len - 1)
|
2010-11-10 13:25:13 +00:00
|
|
|
break;
|
2010-12-02 08:10:10 +00:00
|
|
|
else
|
2010-11-10 13:25:13 +00:00
|
|
|
{
|
2010-12-02 08:10:10 +00:00
|
|
|
/* XXX A real implementation should check if the
|
|
|
|
* previous row can focus with it's attributes setup */
|
|
|
|
focus_row++;
|
|
|
|
valid = gtk_tree_model_iter_next (priv->model, &iter);
|
2010-11-10 13:25:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-10 10:17:06 +00:00
|
|
|
}
|
2010-11-10 13:25:13 +00:00
|
|
|
|
2010-11-11 09:13:54 +00:00
|
|
|
g_signal_handler_unblock (priv->area, priv->focus_changed_id);
|
|
|
|
|
2010-11-11 07:13:06 +00:00
|
|
|
/* XXX A smarter implementation would only invalidate the rectangles where
|
|
|
|
* focus was removed from and new focus was placed */
|
|
|
|
gtk_widget_queue_draw (widget);
|
2010-11-10 13:25:13 +00:00
|
|
|
|
2010-11-11 09:13:54 +00:00
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
cell_area_scaffold_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event)
|
|
|
|
{
|
|
|
|
CellAreaScaffold *scaffold = CELL_AREA_SCAFFOLD (widget);
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean valid;
|
|
|
|
gint i = 0;
|
|
|
|
GdkRectangle event_area;
|
|
|
|
GtkAllocation allocation;
|
|
|
|
gboolean handled = FALSE;
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
|
|
|
event_area.x = 0;
|
|
|
|
event_area.y = 0;
|
|
|
|
event_area.width = allocation.width;
|
|
|
|
event_area.height = allocation.height;
|
|
|
|
|
2010-12-02 08:10:10 +00:00
|
|
|
event_area.x = priv->indent;
|
|
|
|
event_area.width -= priv->indent;
|
2010-11-12 12:55:28 +00:00
|
|
|
|
2010-11-11 09:13:54 +00:00
|
|
|
valid = gtk_tree_model_get_iter_first (priv->model, &iter);
|
|
|
|
while (valid)
|
|
|
|
{
|
|
|
|
RowData *data = &g_array_index (priv->row_data, RowData, i);
|
|
|
|
|
2010-12-02 08:10:10 +00:00
|
|
|
event_area.height = data->size;
|
2010-11-11 09:13:54 +00:00
|
|
|
|
2010-12-02 08:10:10 +00:00
|
|
|
if (event->y >= event_area.y &&
|
|
|
|
event->y <= event_area.y + event_area.height)
|
2010-11-11 09:13:54 +00:00
|
|
|
{
|
2010-12-02 08:10:10 +00:00
|
|
|
/* XXX A real implementation would assemble GtkCellRendererState flags here */
|
|
|
|
gtk_cell_area_apply_attributes (priv->area, priv->model, &iter, FALSE, FALSE);
|
|
|
|
handled = gtk_cell_area_event (priv->area, priv->context, GTK_WIDGET (scaffold),
|
|
|
|
(GdkEvent *)event, &event_area, 0);
|
|
|
|
break;
|
2010-11-11 09:13:54 +00:00
|
|
|
}
|
2010-12-02 08:10:10 +00:00
|
|
|
|
|
|
|
event_area.y += data->size;
|
|
|
|
event_area.y += priv->row_spacing;
|
|
|
|
|
2010-11-11 09:13:54 +00:00
|
|
|
i++;
|
|
|
|
valid = gtk_tree_model_iter_next (priv->model, &iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return handled;
|
2010-11-10 10:17:06 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 10:25:07 +00:00
|
|
|
|
|
|
|
/*********************************************************
|
|
|
|
* GtkContainerClass *
|
|
|
|
*********************************************************/
|
|
|
|
static void
|
|
|
|
cell_area_scaffold_put_edit_widget (CellAreaScaffold *scaffold,
|
|
|
|
GtkWidget *edit_widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
|
|
|
|
|
|
|
priv->edit_rect.x = x;
|
|
|
|
priv->edit_rect.y = y;
|
|
|
|
priv->edit_rect.width = width;
|
|
|
|
priv->edit_rect.height = height;
|
|
|
|
priv->edit_widget = edit_widget;
|
|
|
|
|
|
|
|
gtk_widget_set_parent (edit_widget, GTK_WIDGET (scaffold));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cell_area_scaffold_forall (GtkContainer *container,
|
|
|
|
gboolean include_internals,
|
|
|
|
GtkCallback callback,
|
|
|
|
gpointer callback_data)
|
|
|
|
{
|
|
|
|
CellAreaScaffold *scaffold = CELL_AREA_SCAFFOLD (container);
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
|
|
|
|
|
|
|
if (priv->edit_widget)
|
|
|
|
(* callback) (priv->edit_widget, callback_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cell_area_scaffold_remove (GtkContainer *container,
|
|
|
|
GtkWidget *child)
|
|
|
|
{
|
|
|
|
CellAreaScaffold *scaffold = CELL_AREA_SCAFFOLD (container);
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
|
|
|
|
|
|
|
g_return_if_fail (child == priv->edit_widget);
|
|
|
|
|
|
|
|
gtk_widget_unparent (priv->edit_widget);
|
|
|
|
priv->edit_widget = NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-10 13:25:13 +00:00
|
|
|
/*********************************************************
|
|
|
|
* CellAreaScaffoldClass *
|
|
|
|
*********************************************************/
|
2010-11-10 10:17:06 +00:00
|
|
|
static void
|
2010-11-10 13:25:13 +00:00
|
|
|
cell_area_scaffold_activate (CellAreaScaffold *scaffold)
|
2010-11-10 10:17:06 +00:00
|
|
|
{
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
2010-11-10 13:25:13 +00:00
|
|
|
GtkWidget *widget = GTK_WIDGET (scaffold);
|
|
|
|
GtkAllocation allocation;
|
|
|
|
GdkRectangle cell_area;
|
2010-11-10 10:17:06 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean valid;
|
2010-11-10 13:25:13 +00:00
|
|
|
gint i = 0;
|
2010-11-10 10:17:06 +00:00
|
|
|
|
2010-11-10 13:25:13 +00:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
2010-11-10 10:17:06 +00:00
|
|
|
|
2010-11-10 13:25:13 +00:00
|
|
|
cell_area.x = 0;
|
|
|
|
cell_area.y = 0;
|
|
|
|
cell_area.width = allocation.width;
|
|
|
|
cell_area.height = allocation.height;
|
2010-11-10 10:17:06 +00:00
|
|
|
|
2010-12-02 08:10:10 +00:00
|
|
|
cell_area.x = priv->indent;
|
|
|
|
cell_area.width -= priv->indent;
|
2010-11-12 12:55:28 +00:00
|
|
|
|
2010-11-10 10:17:06 +00:00
|
|
|
valid = gtk_tree_model_get_iter_first (priv->model, &iter);
|
|
|
|
while (valid)
|
|
|
|
{
|
2010-11-10 13:25:13 +00:00
|
|
|
RowData *data = &g_array_index (priv->row_data, RowData, i);
|
2010-11-10 10:17:06 +00:00
|
|
|
|
2010-11-10 13:25:13 +00:00
|
|
|
if (i == priv->focus_row)
|
2010-11-10 10:17:06 +00:00
|
|
|
{
|
2010-12-02 08:10:10 +00:00
|
|
|
cell_area.height = data->size;
|
2010-11-10 13:25:13 +00:00
|
|
|
|
|
|
|
gtk_cell_area_apply_attributes (priv->area, priv->model, &iter, FALSE, FALSE);
|
2010-12-12 08:15:46 +00:00
|
|
|
gtk_cell_area_activate (priv->area, priv->context, widget, &cell_area,
|
|
|
|
GTK_CELL_RENDERER_FOCUSED, FALSE);
|
2010-11-10 13:25:13 +00:00
|
|
|
|
2010-11-10 10:17:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-12-02 08:10:10 +00:00
|
|
|
cell_area.y += data->size + priv->row_spacing;
|
2010-11-10 10:17:06 +00:00
|
|
|
|
2010-11-10 13:25:13 +00:00
|
|
|
i++;
|
|
|
|
valid = gtk_tree_model_iter_next (priv->model, &iter);
|
2010-11-10 10:17:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************
|
2010-11-10 13:25:13 +00:00
|
|
|
* CellArea/GtkTreeModel callbacks *
|
2010-11-10 10:17:06 +00:00
|
|
|
*********************************************************/
|
|
|
|
static void
|
2010-11-13 07:23:01 +00:00
|
|
|
size_changed_cb (GtkCellAreaContext *context,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
CellAreaScaffold *scaffold)
|
2010-11-10 10:17:06 +00:00
|
|
|
{
|
|
|
|
if (!strcmp (pspec->name, "minimum-width") ||
|
|
|
|
!strcmp (pspec->name, "natural-width") ||
|
|
|
|
!strcmp (pspec->name, "minimum-height") ||
|
|
|
|
!strcmp (pspec->name, "natural-height"))
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (scaffold));
|
|
|
|
}
|
2010-11-08 16:26:38 +00:00
|
|
|
|
2010-11-11 09:13:54 +00:00
|
|
|
static void
|
|
|
|
focus_changed_cb (GtkCellArea *area,
|
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
const gchar *path,
|
|
|
|
CellAreaScaffold *scaffold)
|
|
|
|
{
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
|
|
|
GtkWidget *widget = GTK_WIDGET (scaffold);
|
|
|
|
GtkTreePath *treepath;
|
|
|
|
gint *indices;
|
|
|
|
|
|
|
|
if (!priv->model)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* We can be signaled that a renderer lost focus, here
|
|
|
|
* we dont care */
|
|
|
|
if (!renderer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
treepath = gtk_tree_path_new_from_string (path);
|
|
|
|
indices = gtk_tree_path_get_indices (treepath);
|
|
|
|
|
|
|
|
priv->focus_row = indices[0];
|
|
|
|
|
|
|
|
gtk_tree_path_free (treepath);
|
|
|
|
|
|
|
|
/* Make sure we have focus now */
|
|
|
|
if (!gtk_widget_has_focus (widget))
|
|
|
|
gtk_widget_grab_focus (widget);
|
|
|
|
|
|
|
|
gtk_widget_queue_draw (widget);
|
|
|
|
}
|
|
|
|
|
2010-11-12 10:25:07 +00:00
|
|
|
static void
|
2010-11-14 14:33:26 +00:00
|
|
|
add_editable_cb (GtkCellArea *area,
|
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
GtkCellEditable *edit_widget,
|
|
|
|
GdkRectangle *cell_area,
|
|
|
|
const gchar *path,
|
|
|
|
CellAreaScaffold *scaffold)
|
2010-11-12 10:25:07 +00:00
|
|
|
{
|
|
|
|
GtkAllocation allocation;
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (GTK_WIDGET (scaffold), &allocation);
|
|
|
|
|
|
|
|
cell_area_scaffold_put_edit_widget (scaffold, GTK_WIDGET (edit_widget),
|
|
|
|
allocation.x + cell_area->x,
|
|
|
|
allocation.y + cell_area->y,
|
|
|
|
cell_area->width, cell_area->height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_editable_cb (GtkCellArea *area,
|
|
|
|
GtkCellRenderer *renderer,
|
|
|
|
GtkCellEditable *edit_widget,
|
|
|
|
CellAreaScaffold *scaffold)
|
|
|
|
{
|
|
|
|
gtk_container_remove (GTK_CONTAINER (scaffold), GTK_WIDGET (edit_widget));
|
2010-11-14 14:33:26 +00:00
|
|
|
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (scaffold));
|
2010-11-12 10:25:07 +00:00
|
|
|
}
|
|
|
|
|
2010-11-10 13:25:13 +00:00
|
|
|
static void
|
2010-11-27 07:05:14 +00:00
|
|
|
rebuild_and_reset_internals (CellAreaScaffold *scaffold)
|
2010-11-10 13:25:13 +00:00
|
|
|
{
|
|
|
|
CellAreaScaffoldPrivate *priv = scaffold->priv;
|
|
|
|
gint n_rows;
|
|
|
|
|
|
|
|
if (priv->model)
|
|
|
|
{
|
|
|
|
n_rows = gtk_tree_model_iter_n_children (priv->model, NULL);
|
|
|
|
|
|
|
|
/* Clear/reset the array */
|
|
|
|
g_array_set_size (priv->row_data, n_rows);
|
|
|
|
memset (priv->row_data->data, 0x0, n_rows * sizeof (RowData));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_array_set_size (priv->row_data, 0);
|
|
|
|
|
2010-11-27 07:05:14 +00:00
|
|
|
/* Data changed, lets reset the context and consequently queue resize and
|
2010-11-10 13:25:13 +00:00
|
|
|
* start everything over again (note this is definitly far from optimized) */
|
2010-11-27 07:05:14 +00:00
|
|
|
gtk_cell_area_context_reset (priv->context);
|
2010-11-10 13:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
row_changed_cb (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
CellAreaScaffold *scaffold)
|
|
|
|
{
|
2010-11-27 07:05:14 +00:00
|
|
|
rebuild_and_reset_internals (scaffold);
|
2010-11-10 13:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
row_inserted_cb (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
CellAreaScaffold *scaffold)
|
|
|
|
{
|
2010-11-27 07:05:14 +00:00
|
|
|
rebuild_and_reset_internals (scaffold);
|
2010-11-10 13:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
row_deleted_cb (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
CellAreaScaffold *scaffold)
|
|
|
|
{
|
2010-11-27 07:05:14 +00:00
|
|
|
rebuild_and_reset_internals (scaffold);
|
2010-11-10 13:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rows_reordered_cb (GtkTreeModel *model,
|
|
|
|
GtkTreePath *parent,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gint *new_order,
|
|
|
|
CellAreaScaffold *scaffold)
|
|
|
|
{
|
2010-11-27 07:05:14 +00:00
|
|
|
rebuild_and_reset_internals (scaffold);
|
2010-11-10 13:25:13 +00:00
|
|
|
}
|
|
|
|
|
2010-11-08 16:26:38 +00:00
|
|
|
/*********************************************************
|
|
|
|
* API *
|
|
|
|
*********************************************************/
|
|
|
|
GtkWidget *
|
|
|
|
cell_area_scaffold_new (void)
|
|
|
|
{
|
|
|
|
return (GtkWidget *)g_object_new (TYPE_CELL_AREA_SCAFFOLD, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkCellArea *
|
|
|
|
cell_area_scaffold_get_area (CellAreaScaffold *scaffold)
|
|
|
|
{
|
|
|
|
CellAreaScaffoldPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (IS_CELL_AREA_SCAFFOLD (scaffold), NULL);
|
|
|
|
|
|
|
|
priv = scaffold->priv;
|
|
|
|
|
|
|
|
return priv->area;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cell_area_scaffold_set_model (CellAreaScaffold *scaffold,
|
|
|
|
GtkTreeModel *model)
|
|
|
|
{
|
|
|
|
CellAreaScaffoldPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (IS_CELL_AREA_SCAFFOLD (scaffold));
|
|
|
|
|
|
|
|
priv = scaffold->priv;
|
|
|
|
|
|
|
|
if (priv->model != model)
|
|
|
|
{
|
|
|
|
if (priv->model)
|
|
|
|
{
|
2010-11-10 13:25:13 +00:00
|
|
|
g_signal_handler_disconnect (priv->model, priv->row_changed_id);
|
|
|
|
g_signal_handler_disconnect (priv->model, priv->row_inserted_id);
|
|
|
|
g_signal_handler_disconnect (priv->model, priv->row_deleted_id);
|
|
|
|
g_signal_handler_disconnect (priv->model, priv->rows_reordered_id);
|
|
|
|
|
2010-11-08 16:26:38 +00:00
|
|
|
g_object_unref (priv->model);
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->model = model;
|
|
|
|
|
|
|
|
if (priv->model)
|
|
|
|
{
|
|
|
|
g_object_ref (priv->model);
|
|
|
|
|
2010-11-10 13:25:13 +00:00
|
|
|
priv->row_changed_id =
|
|
|
|
g_signal_connect (priv->model, "row-changed",
|
|
|
|
G_CALLBACK (row_changed_cb), scaffold);
|
2010-11-08 16:26:38 +00:00
|
|
|
|
2010-11-10 13:25:13 +00:00
|
|
|
priv->row_inserted_id =
|
|
|
|
g_signal_connect (priv->model, "row-inserted",
|
|
|
|
G_CALLBACK (row_inserted_cb), scaffold);
|
|
|
|
|
|
|
|
priv->row_deleted_id =
|
|
|
|
g_signal_connect (priv->model, "row-deleted",
|
|
|
|
G_CALLBACK (row_deleted_cb), scaffold);
|
|
|
|
|
|
|
|
priv->rows_reordered_id =
|
|
|
|
g_signal_connect (priv->model, "rows-reordered",
|
|
|
|
G_CALLBACK (rows_reordered_cb), scaffold);
|
2010-11-08 16:26:38 +00:00
|
|
|
}
|
|
|
|
|
2010-11-27 07:05:14 +00:00
|
|
|
rebuild_and_reset_internals (scaffold);
|
2010-11-08 16:26:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkTreeModel *
|
|
|
|
cell_area_scaffold_get_model (CellAreaScaffold *scaffold)
|
|
|
|
{
|
|
|
|
CellAreaScaffoldPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (IS_CELL_AREA_SCAFFOLD (scaffold), NULL);
|
|
|
|
|
|
|
|
priv = scaffold->priv;
|
|
|
|
|
|
|
|
return priv->model;
|
|
|
|
}
|
2010-11-12 12:55:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
cell_area_scaffold_set_row_spacing (CellAreaScaffold *scaffold,
|
|
|
|
gint spacing)
|
|
|
|
{
|
|
|
|
CellAreaScaffoldPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (IS_CELL_AREA_SCAFFOLD (scaffold));
|
|
|
|
|
|
|
|
priv = scaffold->priv;
|
|
|
|
|
|
|
|
if (priv->row_spacing != spacing)
|
|
|
|
{
|
|
|
|
priv->row_spacing = spacing;
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (scaffold));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
cell_area_scaffold_get_row_spacing (CellAreaScaffold *scaffold)
|
|
|
|
{
|
|
|
|
CellAreaScaffoldPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (IS_CELL_AREA_SCAFFOLD (scaffold), 0);
|
|
|
|
|
|
|
|
priv = scaffold->priv;
|
|
|
|
|
|
|
|
return priv->row_spacing;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cell_area_scaffold_set_indentation (CellAreaScaffold *scaffold,
|
|
|
|
gint indent)
|
|
|
|
{
|
|
|
|
CellAreaScaffoldPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (IS_CELL_AREA_SCAFFOLD (scaffold));
|
|
|
|
|
|
|
|
priv = scaffold->priv;
|
|
|
|
|
|
|
|
if (priv->indent != indent)
|
|
|
|
{
|
|
|
|
priv->indent = indent;
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (scaffold));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
cell_area_scaffold_get_indentation (CellAreaScaffold *scaffold)
|
|
|
|
{
|
|
|
|
CellAreaScaffoldPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (IS_CELL_AREA_SCAFFOLD (scaffold), 0);
|
|
|
|
|
|
|
|
priv = scaffold->priv;
|
|
|
|
|
|
|
|
return priv->indent;
|
|
|
|
}
|
|
|
|
|
|
|
|
|