#include "psppire-dict.h"
#include "psppire-select-dest.h"
#include "psppire-means-layer.h"
+#include "helper.h"
#include <gtk/gtk.h>
#include "psppire-selector.h"
-static void psppire_selector_class_init (PsppireSelectorClass *class);
-static void psppire_selector_init (PsppireSelector *selector);
-
+G_DEFINE_TYPE (PsppireSelector, psppire_selector, GTK_TYPE_BUTTON)
static void set_direction (PsppireSelector *, enum psppire_selector_dir);
g_signal_emit (selector, signals [DE_SELECTED], 0);
}
-
-GType
-psppire_selector_get_type (void)
-{
- static GType psppire_selector_type = 0;
-
- if (!psppire_selector_type)
- {
- static const GTypeInfo psppire_selector_info =
- {
- sizeof (PsppireSelectorClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc)psppire_selector_class_init,
- (GClassFinalizeFunc) NULL,
- NULL,
- sizeof (PsppireSelector),
- 0,
- (GInstanceInitFunc) psppire_selector_init,
- };
-
- psppire_selector_type =
- g_type_register_static (GTK_TYPE_BUTTON, "PsppireSelector",
- &psppire_selector_info, 0);
- }
-
- return psppire_selector_type;
-}
-
static GObjectClass * parent_class = NULL;
-
-
+#if DEBUG
static void
dump_hash_entry (gpointer key, gpointer value, gpointer obj)
{
g_print ("%s %p\n", __FUNCTION__, obj);
g_hash_table_foreach (class->source_hash, dump_hash_entry, obj);
}
-
+#endif
static void
sel->source_litem = NULL;
}
- g_object_unref (sel->dest);
- g_object_unref (sel->source);
+ if (sel->dest)
+ g_object_unref (sel->dest);
+
+ if (sel->source)
+ g_object_unref (sel->source);
/* Chain up to the parent class */
G_OBJECT_CLASS (parent_class)->dispose (obj);
set_direction (selector, PSPPIRE_SELECTOR_SOURCE_TO_DEST);
- if ( selector->allow_selection )
+ if (selector->allow_selection)
{
gtk_widget_set_sensitive (GTK_WIDGET (selector),
selector->allow_selection (selector->source, selector->dest));
}
- else if ( GTK_IS_ENTRY (selector->dest) )
+ else if (GTK_IS_ENTRY (selector->dest))
{
gtk_widget_set_sensitive (GTK_WIDGET (selector),
gtk_tree_selection_count_selected_rows
- (treeselection) <= 1 );
+ (treeselection) <= 1);
}
}
if (GTK_WIDGET_CLASS (parent_class)->realize)
GTK_WIDGET_CLASS (parent_class)->realize (w);
- if ( NULL == list)
+ if (NULL == list)
return;
- if ( g_list_first (list)->data == selector)
+ if (g_list_first (list)->data == selector)
{
- if ( selector->row_activate_id )
+ if (selector->row_activate_id)
g_signal_handler_disconnect (selector->source, selector->row_activate_id);
selector->row_activate_id =
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (selector->source));
- if ( selector->source_select_id )
+ if (selector->source_select_id)
g_signal_handler_disconnect (selection, selector->source_select_id);
selector->source_select_id =
/* FIXME: Need to reverse the arrow direction if an RTL locale is in
effect */
- if ( d == PSPPIRE_SELECTOR_SOURCE_TO_DEST )
+ if (d == PSPPIRE_SELECTOR_SOURCE_TO_DEST)
{
switch (selector->orientation)
{
de_select_selection_tree_view (PsppireSelector *selector)
{
GtkTreeSelection* selection =
- gtk_tree_view_get_selection ( GTK_TREE_VIEW (selector->dest));
+ gtk_tree_view_get_selection (GTK_TREE_VIEW (selector->dest));
GtkTreeModel *model =
gtk_tree_view_get_model (GTK_TREE_VIEW (selector->dest));
}
/* Delete list of RowRefs and its contents */
- g_list_foreach (selected_rows, (GFunc) gtk_tree_row_reference_free, NULL);
+ g_list_foreach (selected_rows, GFUNC_COMPAT_CAST (gtk_tree_row_reference_free), NULL);
g_list_free (selected_rows);
}
{
selector->selecting = TRUE;
- if ( GTK_IS_TREE_VIEW (selector->dest ) )
+ if (GTK_IS_TREE_VIEW (selector->dest))
de_select_selection_tree_view (selector);
- else if ( GTK_IS_ENTRY (selector->dest))
+ else if (GTK_IS_ENTRY (selector->dest))
de_select_selection_entry (selector);
- else if ( PSPPIRE_IS_MEANS_LAYER (selector->dest))
+ else if (PSPPIRE_IS_MEANS_LAYER (selector->dest))
de_select_selection_means_layer (selector);
else
{
GList *item ;
GtkTreeSelection* selection =
- gtk_tree_view_get_selection ( GTK_TREE_VIEW (selector->source));
+ gtk_tree_view_get_selection (GTK_TREE_VIEW (selector->source));
GList *selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL);
selector->dest,
childmodel,
selector->select_user_data
- );
+ );
}
- g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
+ g_list_foreach (selected_rows, GFUNC_COMPAT_CAST (gtk_tree_path_free), NULL);
g_list_free (selected_rows);
refilter (selector);
{
PsppireSelector *selector = list->data;
- if ( selector->filter && selector->filter (childmodel, iter, selector))
+ if (selector->filter && selector->filter (childmodel, iter, selector))
return FALSE;
list = list->next;
PsppireSelectorClass *class = g_type_class_peek (PSPPIRE_SELECTOR_TYPE);
- if ( ! (list = g_hash_table_lookup (class->source_hash, selector->source)))
+ if (! (list = g_hash_table_lookup (class->source_hash, selector->source)))
{
/* Base case: This widget is currently not the source of
any selector. Create a hash entry and make this selector
{ /* Append this selector to the list and push the <source,list>
pair onto the hash table */
- if ( NULL == g_list_find (list, selector) )
+ if (NULL == g_list_find (list, selector))
{
- if ( selector->primary_requested )
+ if (selector->primary_requested)
{
list = g_list_prepend (list, selector);
selector->source_litem = list;
GtkTreeView *source,
GParamSpec *psp,
PsppireSelector *selector
- )
+)
{
GtkTreeModel *model = gtk_tree_view_get_model (source);
{
PsppireSelector *selector = user_data;
- if ( selector->selecting) return;
+ if (selector->selecting) return;
refilter (selector);
}
{
PsppireSelector *selector = user_data;
- if ( selector->selecting ) return;
+ if (selector->selecting) return;
refilter (selector);
}
g_signal_connect (selector, "destroy", G_CALLBACK (remove_selector_handlers), model);
- if ( selector->selecting ) return;
+ if (selector->selecting) return;
refilter (selector);
}
static void
set_default_filter (PsppireSelector *selector)
{
- if ( selector->filter == NULL)
+ if (selector->filter == NULL)
{
if (GTK_IS_TREE_VIEW (selector->dest))
selector->filter = is_item_in_dest;
void
psppire_selector_update_subjects (PsppireSelector *selector)
{
- if ( NULL == selector->dest )
+ if (NULL == selector->dest)
return;
set_default_filter (selector);
- if ( NULL == selector->source )
+ if (NULL == selector->source)
return;
- if ( GTK_IS_TREE_VIEW (selector->source))
+ if (GTK_IS_TREE_VIEW (selector->source))
{
set_tree_view_source (selector);
else
g_error ("Unsupported source widget: %s", G_OBJECT_TYPE_NAME (selector->source));
- if ( NULL == selector->dest)
+ if (NULL == selector->dest)
;
- else if ( GTK_IS_TREE_VIEW (selector->dest))
+ else if (GTK_IS_TREE_VIEW (selector->dest))
{
set_tree_view_dest (selector, GTK_TREE_VIEW (selector->dest));
}
- else if ( GTK_IS_ENTRY (selector->dest))
+ else if (GTK_IS_ENTRY (selector->dest))
{
set_entry_dest (selector, GTK_ENTRY (selector->dest));
}
g_error ("Unsupported destination widget: %s", G_OBJECT_TYPE_NAME (selector->dest));
- if ( PSPPIRE_IS_DICT_VIEW (selector->source) && selector->select_items == NULL)
+ if (PSPPIRE_IS_DICT_VIEW (selector->source) && selector->select_items == NULL)
{
GObjectClass *class = G_OBJECT_GET_CLASS (selector);
GType type = G_OBJECT_TYPE (selector->dest);
SelectItemsFunc *func =
g_hash_table_lookup (PSPPIRE_SELECTOR_CLASS (class)->default_selection_funcs, (gpointer) type);
- if ( func )
+ if (func)
psppire_selector_set_select_func (PSPPIRE_SELECTOR (selector),
func, NULL);
}