gtk2/gtk/gtktreedatalist.c
Havoc Pennington 637c61da76 handle case where there are no rows in the model
2001-01-09  Havoc Pennington  <hp@redhat.com>

	* gtk/gtktreeview.c (gtk_tree_view_check_dirty): handle case where
	there are no rows in the model

	* gtk/gtkliststore.c (gtk_list_store_iter_children): if parent is
	NULL, then return the start of the list

	* gtk/gtktreeview.c (gtk_tree_view_setup_model): don't build tree
	if we can't get any rows from an empty model

	* gtk/gtktreeviewcolumn.h (struct _GtkTreeViewColumn): remove
	extraneous * after function pointer typedef usage

	* Makefile.am: don't specify full path to cp and rm

	* gtk/gtkcellrenderertextpixbuf.c
	(gtk_cell_renderer_text_pixbuf_get_size): check width/height !=
	NULL before dereferencing, fixes a segfault that happened from
	time to time

	* gtk/gtkcellrendererpixbuf.c (gtk_cell_renderer_pixbuf_render):
	use gdk_pixbuf_render_to_drawable_alpha() to get alpha channel,
	and reindent the function
	(gtk_cell_renderer_pixbuf_get_size): indentation

	* gtk/gtkdialog.c (gtk_dialog_run): destroy main loop only after
	we quit it
	(gtk_dialog_add_buttons_valist): add g_return_if_fail
	(gtk_dialog_set_default_response): New function, to set default
	button
	(gtk_dialog_set_response_sensitive): New function, to set
	sensitivity of buttons

	* gtk/gtkcellrendererpixbuf.c
	(gtk_cell_renderer_pixbuf_get_property): allow getting a NULL pixbuf
	(gtk_cell_renderer_pixbuf_set_property): allow setting a NULL pixbuf

	* gtk/gtktreedatalist.c (_gtk_tree_data_list_node_to_value):
	handle any G_TYPE_OBJECT subclass, not just the base class, and
	also boxed types.
	(_gtk_tree_data_list_value_to_node): ditto

	* gtk/gtkrbtree.c: Run _gtk_rbtree_test at strategic points if
	--gtk-debug=tree

	* gtk/gtkmain.c: add GTK_DEBUG_TREE

	* gtk/gtkdebug.h: add GTK_DEBUG_TREE
2001-01-09 17:45:34 +00:00

238 lines
6.2 KiB
C

/* gtktreedatalist.c
* Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.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 "gtktreedatalist.h"
#include "gobject/gvalue.h"
#include "gobject/gvaluetypes.h"
/* node allocation
*/
struct _GAllocator /* from gmem.c */
{
gchar *name;
guint16 n_preallocs;
guint is_unused : 1;
guint type : 4;
GAllocator *last;
GMemChunk *mem_chunk;
GtkTreeDataList *free_nodes;
};
G_LOCK_DEFINE_STATIC (current_allocator);
static GAllocator *current_allocator = NULL;
/* HOLDS: current_allocator_lock */
static void
gtk_tree_data_list_validate_allocator (GAllocator *allocator)
{
g_return_if_fail (allocator != NULL);
g_return_if_fail (allocator->is_unused == TRUE);
if (allocator->type != G_ALLOCATOR_NODE)
{
allocator->type = G_ALLOCATOR_NODE;
if (allocator->mem_chunk)
{
g_mem_chunk_destroy (allocator->mem_chunk);
allocator->mem_chunk = NULL;
}
}
if (!allocator->mem_chunk)
{
allocator->mem_chunk = g_mem_chunk_new (allocator->name,
sizeof (GtkTreeDataList),
sizeof (GtkTreeDataList) * allocator->n_preallocs,
G_ALLOC_ONLY);
allocator->free_nodes = NULL;
}
allocator->is_unused = FALSE;
}
void
_gtk_tree_data_list_push_allocator (GAllocator *allocator)
{
G_LOCK (current_allocator);
gtk_tree_data_list_validate_allocator ( allocator );
allocator->last = current_allocator;
current_allocator = allocator;
G_UNLOCK (current_allocator);
}
void
_gtk_tree_data_list_pop_allocator (void)
{
G_LOCK (current_allocator);
if (current_allocator)
{
GAllocator *allocator;
allocator = current_allocator;
current_allocator = allocator->last;
allocator->last = NULL;
allocator->is_unused = TRUE;
}
G_UNLOCK (current_allocator);
}
GtkTreeDataList *
_gtk_tree_data_list_alloc (void)
{
GtkTreeDataList *list;
G_LOCK (current_allocator);
if (!current_allocator)
{
GAllocator *allocator = g_allocator_new ("GTK+ default GtkTreeDataList allocator",
128);
gtk_tree_data_list_validate_allocator (allocator);
allocator->last = NULL;
current_allocator = allocator;
}
if (!current_allocator->free_nodes)
list = g_chunk_new (GtkTreeDataList, current_allocator->mem_chunk);
else
{
list = current_allocator->free_nodes;
current_allocator->free_nodes = list->next;
}
G_UNLOCK (current_allocator);
return list;
}
void
_gtk_tree_data_list_free (GtkTreeDataList *list,
GType *column_headers)
{
GtkTreeDataList *tmp;
gint i = 0;
for (tmp = list; tmp; tmp = tmp->next)
{
switch (column_headers [i])
{
case G_TYPE_STRING:
g_free ((gchar *) tmp->data.v_pointer);
break;
case G_TYPE_OBJECT:
g_object_unref (G_OBJECT (tmp->data.v_pointer));
break;
default:
break;
}
i++;
}
G_LOCK (current_allocator);
list->next = current_allocator->free_nodes;
current_allocator->free_nodes = list;
G_UNLOCK (current_allocator);
}
void
_gtk_tree_data_list_node_to_value (GtkTreeDataList *list,
GType type,
GValue *value)
{
g_value_init (value, type);
switch (type)
{
case G_TYPE_BOOLEAN:
g_value_set_boolean (value, (gboolean) list->data.v_int);
break;
case G_TYPE_CHAR:
g_value_set_char (value, list->data.v_char);
break;
case G_TYPE_UCHAR:
g_value_set_uchar (value, list->data.v_uchar);
break;
case G_TYPE_INT:
g_value_set_int (value, list->data.v_int);
break;
case G_TYPE_UINT:
g_value_set_uint (value, list->data.v_uint);
break;
case G_TYPE_POINTER:
g_value_set_pointer (value, (gpointer) list->data.v_pointer);
break;
case G_TYPE_FLOAT:
g_value_set_float (value, list->data.v_float);
break;
case G_TYPE_STRING:
g_value_set_string (value, (gchar *) list->data.v_pointer);
break;
default:
if (g_type_is_a (type, G_TYPE_OBJECT))
g_value_set_object (value, (GObject *) list->data.v_pointer);
else if (g_type_is_a (type, G_TYPE_BOXED))
g_value_set_boxed (value, (GObject *) list->data.v_pointer);
else
g_warning ("Unsupported type (%s) retrieved.", g_type_name (value->g_type));
break;
}
}
void
_gtk_tree_data_list_value_to_node (GtkTreeDataList *list,
GValue *value)
{
switch (value->g_type)
{
case G_TYPE_BOOLEAN:
list->data.v_int = g_value_get_boolean (value);
break;
case G_TYPE_CHAR:
list->data.v_char = g_value_get_char (value);
break;
case G_TYPE_UCHAR:
list->data.v_uchar = g_value_get_uchar (value);
break;
case G_TYPE_INT:
list->data.v_int = g_value_get_int (value);
break;
case G_TYPE_UINT:
list->data.v_uint = g_value_get_uint (value);
break;
case G_TYPE_POINTER:
list->data.v_pointer = g_value_get_pointer (value);
break;
case G_TYPE_FLOAT:
list->data.v_float = g_value_get_float (value);
break;
case G_TYPE_STRING:
list->data.v_pointer = g_value_dup_string (value);
break;
default:
if (g_type_is_a (G_VALUE_TYPE (value), G_TYPE_OBJECT))
list->data.v_pointer = g_value_dup_object (value);
else if (g_type_is_a (G_VALUE_TYPE (value), G_TYPE_BOXED))
list->data.v_pointer = g_value_dup_boxed (value);
else
g_warning ("Unsupported type (%s) stored.", g_type_name (value->g_type));
break;
}
}