125 lines
3.6 KiB
C
125 lines
3.6 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-entry.h"
|
|
|
|
G_DEFINE_TYPE (VnColumnEntry, vn_column_entry, VN_TYPE_COLUMN);
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
|
|
|
|
static void vn_column_entry_cb_edited (GtkCellRendererText * cell,
|
|
const gchar * path, gchar * text, VnColumnEntry * obj)
|
|
{
|
|
GValue value = {0};
|
|
|
|
if (g_strcmp0 (text, ""))
|
|
{
|
|
g_value_init (&value, G_TYPE_STRING);
|
|
g_value_set_string (&value, text);
|
|
}
|
|
else
|
|
g_value_init (&value, GVN_TYPE_NULL);
|
|
|
|
VN_COLUMN_GET_CLASS (obj)->value_changed (VN_COLUMN (obj), path, &value);
|
|
g_value_unset (&value);
|
|
}
|
|
|
|
static void vn_column_entry_set_editable (VnColumn * obj, gboolean editable)
|
|
{
|
|
g_object_set (obj->cell, "editable", editable, NULL);
|
|
|
|
if (editable)
|
|
g_signal_connect (obj->cell, "edited",
|
|
G_CALLBACK (vn_column_entry_cb_edited), obj);
|
|
else
|
|
g_signal_handlers_disconnect_by_func (obj->cell,
|
|
vn_column_entry_cb_edited, obj);
|
|
}
|
|
|
|
static void vn_column_entry_set_value (VnColumnEntry * obj, GtkTreeModel * model,
|
|
GtkTreeIter * iter, GObject * cell, const GValue * value)
|
|
{
|
|
GValue new_value = {0};
|
|
gvn_value_to_format_string (value, obj->digits, &new_value);
|
|
g_object_set_property (cell, "text", &new_value);
|
|
g_value_unset (&new_value);
|
|
}
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
|
|
|
|
enum
|
|
{
|
|
PROP_DIGITS = 1
|
|
};
|
|
|
|
static void vn_column_entry_set_property (VnColumnEntry * obj, guint id,
|
|
const GValue * value, GParamSpec * pspec)
|
|
{
|
|
switch (id)
|
|
{
|
|
case PROP_DIGITS:
|
|
obj->digits = g_value_get_uint (value);
|
|
break;
|
|
default:
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
}
|
|
}
|
|
|
|
static void vn_column_entry_get_property (VnColumnEntry * obj, guint id,
|
|
GValue * value, GParamSpec * pspec)
|
|
{
|
|
switch (id)
|
|
{
|
|
case PROP_DIGITS:
|
|
g_value_set_uint (value, obj->digits);
|
|
break;
|
|
default:
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
}
|
|
}
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
|
|
|
static void vn_column_entry_init (VnColumnEntry * obj)
|
|
{
|
|
GtkCellRenderer * cell = gtk_cell_renderer_text_new ();
|
|
VN_COLUMN_GET_CLASS (obj)->set_renderer (VN_COLUMN (obj), cell);
|
|
}
|
|
|
|
static void vn_column_entry_finalize (VnColumnEntry * obj)
|
|
{
|
|
G_OBJECT_CLASS (vn_column_entry_parent_class)->finalize (G_OBJECT (obj));
|
|
}
|
|
|
|
static void vn_column_entry_class_init (VnColumnEntryClass * klass)
|
|
{
|
|
GObjectClass * k = G_OBJECT_CLASS (klass);
|
|
k->finalize = (GObjectFinalizeFunc) vn_column_entry_finalize;
|
|
k->set_property = (GObjectSetPropertyFunc) vn_column_entry_set_property;
|
|
k->get_property = (GObjectGetPropertyFunc) vn_column_entry_get_property;
|
|
VN_COLUMN_CLASS (klass)->set_value = (VnColumnSetValueFunc) vn_column_entry_set_value;
|
|
VN_COLUMN_CLASS (klass)->set_editable = (VnColumnSetEditableFunc) vn_column_entry_set_editable;
|
|
|
|
g_object_class_install_property (k, PROP_DIGITS,
|
|
g_param_spec_uint ("digits"
|
|
,_("Digits")
|
|
,_("The number of decimal places to display.")
|
|
,0 ,20 ,0
|
|
,G_PARAM_CONSTRUCT | G_PARAM_READWRITE
|
|
));
|
|
}
|