92 lines
2.9 KiB
C
92 lines
2.9 KiB
C
|
/*
|
||
|
* Copyright (C) 2012 - Juan Ferrer Toribio
|
||
|
*
|
||
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
#include "vn-column-check.h"
|
||
|
|
||
|
G_DEFINE_TYPE (VnColumnCheck, vn_column_check, VN_TYPE_COLUMN);
|
||
|
|
||
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
|
||
|
|
||
|
static void vn_column_check_cb_toggled (GtkCellRendererToggle * cell,
|
||
|
const gchar * path, VnColumn * obj)
|
||
|
{
|
||
|
gint col;
|
||
|
DbIter iter;
|
||
|
DbModel * model;
|
||
|
GValue new_value = {0};
|
||
|
const GValue * old_value;
|
||
|
|
||
|
col = vn_column_get_column_index (obj);
|
||
|
model = vn_column_get_model (obj);
|
||
|
|
||
|
vn_column_get_iter (obj, path, &iter);
|
||
|
old_value = db_model_get_value (model, &iter, col, NULL);
|
||
|
|
||
|
g_value_init (&new_value, G_TYPE_BOOLEAN);
|
||
|
g_value_set_boolean (&new_value,
|
||
|
gvn_value_is_null (old_value) || !g_value_get_boolean (old_value));
|
||
|
db_model_set_value (model, &iter, col, &new_value, NULL);
|
||
|
}
|
||
|
|
||
|
static void vn_column_check_set_editable (VnColumn * obj, gboolean editable)
|
||
|
{
|
||
|
if (editable)
|
||
|
g_signal_connect (obj->cell, "toggled",
|
||
|
G_CALLBACK (vn_column_check_cb_toggled), obj);
|
||
|
else
|
||
|
g_signal_handlers_disconnect_by_func (obj->cell,
|
||
|
vn_column_check_cb_toggled, obj);
|
||
|
}
|
||
|
|
||
|
static void vn_column_check_set_value (VnColumnCheck * obj, GtkTreeModel * model,
|
||
|
GtkTreeIter * iter, GtkCellRendererToggle * cell, const GValue * value)
|
||
|
{
|
||
|
GValue new_value = {0};
|
||
|
g_value_init (&new_value, G_TYPE_BOOLEAN);
|
||
|
|
||
|
if (!gvn_value_is_null (value))
|
||
|
g_value_transform (value, &new_value);
|
||
|
else
|
||
|
g_value_set_boolean (&new_value, FALSE);
|
||
|
|
||
|
gtk_cell_renderer_toggle_set_active (cell,
|
||
|
g_value_get_boolean (&new_value));
|
||
|
|
||
|
g_value_unset (&new_value);
|
||
|
}
|
||
|
|
||
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
||
|
|
||
|
static void vn_column_check_init (VnColumnCheck * obj)
|
||
|
{
|
||
|
GtkCellRenderer * cell = gtk_cell_renderer_toggle_new ();
|
||
|
VN_COLUMN_GET_CLASS (obj)->set_renderer (VN_COLUMN (obj), cell);
|
||
|
}
|
||
|
|
||
|
static void vn_column_check_finalize (VnColumnCheck * obj)
|
||
|
{
|
||
|
G_OBJECT_CLASS (vn_column_check_parent_class)->finalize (G_OBJECT (obj));
|
||
|
}
|
||
|
|
||
|
static void vn_column_check_class_init (VnColumnCheckClass * klass)
|
||
|
{
|
||
|
GObjectClass * k = G_OBJECT_CLASS (klass);
|
||
|
k->finalize = (GObjectFinalizeFunc) vn_column_check_finalize;
|
||
|
VN_COLUMN_CLASS (klass)->set_value = (VnColumnSetValueFunc) vn_column_check_set_value;
|
||
|
VN_COLUMN_CLASS (klass)->set_editable = (VnColumnSetEditableFunc) vn_column_check_set_editable;
|
||
|
}
|