2013-10-11 23:07:35 +00:00
|
|
|
/*
|
|
|
|
* 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-spin.h"
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (VnColumnSpin, vn_column_spin, VN_TYPE_COLUMN);
|
|
|
|
|
2013-10-14 12:08:06 +00:00
|
|
|
static void vn_column_entry_cb_edited (GtkCellRendererText * cell,
|
|
|
|
const gchar * path, gchar * text, VnColumnSpin * 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_spin_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_spin_set_value (VnColumnSpin * obj, GtkTreeModel * model,
|
|
|
|
GtkTreeIter * iter, GtkCellRenderer * cell, const GValue * value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-10-11 23:07:35 +00:00
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
|
|
|
|
2013-10-14 12:08:06 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_CLIMB_RATE = 1
|
|
|
|
,PROP_DIGITS
|
|
|
|
,PROP_VALUE_TYPE
|
|
|
|
};
|
|
|
|
|
|
|
|
static void vn_column_spin_set_property (VnColumnSpin * obj, guint id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case PROP_CLIMB_RATE:
|
|
|
|
g_object_set (VN_COLUMN (obj)->cell,
|
|
|
|
"climb-rate", g_value_get_double (value), NULL);
|
|
|
|
break;
|
|
|
|
case PROP_DIGITS:
|
|
|
|
g_object_set (VN_COLUMN (obj)->cell,
|
|
|
|
"digits", g_value_get_uint (value), NULL);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static void vn_column_spin_get_property (VnColumnSpin * obj, guint id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case PROP_CLIMB_RATE:
|
|
|
|
{
|
|
|
|
gdouble climb_rate;
|
|
|
|
g_object_get (value, "climb-rate", &climb_rate, NULL);
|
|
|
|
g_value_set_double (value, climb_rate);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PROP_DIGITS:
|
|
|
|
{
|
|
|
|
guint digits;
|
|
|
|
g_object_get (VN_COLUMN (obj)->cell, "digits", &digits, NULL);
|
|
|
|
g_value_set_uint (value, digits);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-11 23:07:35 +00:00
|
|
|
static void vn_column_spin_init (VnColumnSpin * obj)
|
|
|
|
{
|
|
|
|
GtkCellRenderer * cell = gtk_cell_renderer_spin_new ();
|
|
|
|
VN_COLUMN_GET_CLASS (obj)->set_renderer (VN_COLUMN (obj), cell);
|
2013-10-14 12:08:06 +00:00
|
|
|
//??g_object_bind_property (obj, "digits", VN_COLUMN (obj)->cell, "digits");
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void vn_column_spin_finalize (VnColumnSpin * obj)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (vn_column_spin_parent_class)->finalize (G_OBJECT (obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vn_column_spin_class_init (VnColumnSpinClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass * k = G_OBJECT_CLASS (klass);
|
2013-10-14 12:08:06 +00:00
|
|
|
VnColumnClass * col_k = VN_COLUMN_CLASS (klass);
|
2013-10-11 23:07:35 +00:00
|
|
|
k->finalize = (GObjectFinalizeFunc) vn_column_spin_finalize;
|
2013-10-14 12:08:06 +00:00
|
|
|
k->set_property = (GObjectSetPropertyFunc) vn_column_spin_set_property;
|
|
|
|
k->get_property = (GObjectGetPropertyFunc) vn_column_spin_get_property;
|
|
|
|
col_k->set_value = (VnColumnSetValueFunc) vn_column_spin_set_value;
|
|
|
|
col_k->set_editable = (VnColumnSetEditableFunc) vn_column_spin_set_editable;
|
|
|
|
|
|
|
|
g_object_class_install_property (k, PROP_CLIMB_RATE,
|
|
|
|
g_param_spec_double ("climb-rate"
|
|
|
|
,_("Climb rate")
|
|
|
|
,_("The acceleration rate when you hold down a button.")
|
|
|
|
,0 ,0 ,0
|
|
|
|
,G_PARAM_CONSTRUCT | G_PARAM_READWRITE
|
|
|
|
));
|
|
|
|
|
|
|
|
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
|
|
|
|
));
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|