xedit-status-combo-box: Clean up and fix deprecations
This commit is contained in:
parent
f6c4752434
commit
b16db94d48
File diff suppressed because it is too large
Load Diff
|
@ -26,309 +26,355 @@
|
|||
|
||||
#define XEDIT_STATUS_COMBO_BOX_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), XEDIT_TYPE_STATUS_COMBO_BOX, XeditStatusComboBoxPrivate))
|
||||
|
||||
#if GTK_CHECK_VERSION (3, 0, 0)
|
||||
#define gtk_hbox_new(X,Y) gtk_box_new(GTK_ORIENTATION_HORIZONTAL,Y)
|
||||
#endif
|
||||
static void menu_deactivate (GtkMenu *menu, XeditStatusComboBox *combo);
|
||||
|
||||
struct _XeditStatusComboBoxPrivate
|
||||
{
|
||||
GtkWidget *frame;
|
||||
GtkWidget *button;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *label;
|
||||
GtkWidget *item;
|
||||
GtkWidget *arrow;
|
||||
|
||||
GtkWidget *menu;
|
||||
GtkWidget *current_item;
|
||||
GtkWidget *frame;
|
||||
GtkWidget *button;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *label;
|
||||
GtkWidget *item;
|
||||
GtkWidget *arrow;
|
||||
|
||||
GtkWidget *menu;
|
||||
GtkWidget *current_item;
|
||||
};
|
||||
|
||||
struct _XeditStatusComboBoxClassPrivate
|
||||
{
|
||||
GtkCssProvider *css;
|
||||
};
|
||||
|
||||
/* Signals */
|
||||
enum
|
||||
{
|
||||
CHANGED,
|
||||
NUM_SIGNALS
|
||||
CHANGED,
|
||||
NUM_SIGNALS
|
||||
};
|
||||
|
||||
/* Properties */
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
|
||||
PROP_LABEL
|
||||
PROP_0,
|
||||
|
||||
PROP_LABEL
|
||||
};
|
||||
|
||||
static guint signals[NUM_SIGNALS] = { 0 };
|
||||
|
||||
G_DEFINE_TYPE(XeditStatusComboBox, xedit_status_combo_box, GTK_TYPE_EVENT_BOX)
|
||||
G_DEFINE_TYPE_WITH_CODE (XeditStatusComboBox, xedit_status_combo_box, GTK_TYPE_EVENT_BOX,
|
||||
g_type_add_class_private (g_define_type_id, sizeof (XeditStatusComboBoxClassPrivate)))
|
||||
|
||||
static void
|
||||
xedit_status_combo_box_finalize (GObject *object)
|
||||
{
|
||||
G_OBJECT_CLASS (xedit_status_combo_box_parent_class)->finalize (object);
|
||||
G_OBJECT_CLASS (xedit_status_combo_box_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
xedit_status_combo_box_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
XeditStatusComboBox *obj = XEDIT_STATUS_COMBO_BOX (object);
|
||||
XeditStatusComboBox *obj = XEDIT_STATUS_COMBO_BOX (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_LABEL:
|
||||
g_value_set_string (value, xedit_status_combo_box_get_label (obj));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_LABEL:
|
||||
g_value_set_string (value, xedit_status_combo_box_get_label (obj));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
xedit_status_combo_box_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
XeditStatusComboBox *obj = XEDIT_STATUS_COMBO_BOX (object);
|
||||
XeditStatusComboBox *obj = XEDIT_STATUS_COMBO_BOX (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_LABEL:
|
||||
xedit_status_combo_box_set_label (obj, g_value_get_string (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_LABEL:
|
||||
xedit_status_combo_box_set_label (obj, g_value_get_string (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
xedit_status_combo_box_destroy (GtkWidget *widget)
|
||||
{
|
||||
XeditStatusComboBox *combo = XEDIT_STATUS_COMBO_BOX (widget);
|
||||
|
||||
if (combo->priv->menu)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func (combo->priv->menu,
|
||||
menu_deactivate,
|
||||
combo);
|
||||
gtk_menu_detach (GTK_MENU (combo->priv->menu));
|
||||
}
|
||||
|
||||
GTK_WIDGET_CLASS (xedit_status_combo_box_parent_class)->destroy (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
xedit_status_combo_box_changed (XeditStatusComboBox *combo,
|
||||
GtkMenuItem *item)
|
||||
GtkMenuItem *item)
|
||||
{
|
||||
const gchar *text;
|
||||
|
||||
text = g_object_get_data (G_OBJECT (item), COMBO_BOX_TEXT_DATA);
|
||||
const gchar *text;
|
||||
|
||||
text = g_object_get_data (G_OBJECT (item), COMBO_BOX_TEXT_DATA);
|
||||
|
||||
if (text != NULL)
|
||||
{
|
||||
gtk_label_set_markup (GTK_LABEL (combo->priv->item), text);
|
||||
combo->priv->current_item = GTK_WIDGET (item);
|
||||
}
|
||||
if (text != NULL)
|
||||
{
|
||||
gtk_label_set_markup (GTK_LABEL (combo->priv->item), text);
|
||||
combo->priv->current_item = GTK_WIDGET (item);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
xedit_status_combo_box_class_init (XeditStatusComboBoxClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->finalize = xedit_status_combo_box_finalize;
|
||||
object_class->get_property = xedit_status_combo_box_get_property;
|
||||
object_class->set_property = xedit_status_combo_box_set_property;
|
||||
|
||||
klass->changed = xedit_status_combo_box_changed;
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
static const gchar style[] =
|
||||
"* {\n"
|
||||
"-GtkButton-default-border : 0;\n"
|
||||
"-GtkButton-default-outside-border : 0;\n"
|
||||
"-GtkButton-inner-border: 0;\n"
|
||||
"-GtkWidget-focus-line-width : 0;\n"
|
||||
"-GtkWidget-focus-padding : 0;\n"
|
||||
"padding: 0;\n"
|
||||
"}";
|
||||
|
||||
object_class->finalize = xedit_status_combo_box_finalize;
|
||||
object_class->get_property = xedit_status_combo_box_get_property;
|
||||
object_class->set_property = xedit_status_combo_box_set_property;
|
||||
|
||||
signals[CHANGED] =
|
||||
g_signal_new ("changed",
|
||||
G_OBJECT_CLASS_TYPE (object_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (XeditStatusComboBoxClass,
|
||||
changed), NULL, NULL,
|
||||
g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
|
||||
GTK_TYPE_MENU_ITEM);
|
||||
|
||||
g_object_class_install_property (object_class, PROP_LABEL,
|
||||
g_param_spec_string ("label",
|
||||
"LABEL",
|
||||
"The label",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
widget_class->destroy = xedit_status_combo_box_destroy;
|
||||
|
||||
klass->changed = xedit_status_combo_box_changed;
|
||||
|
||||
/* Set up a style for the button to decrease spacing. */
|
||||
gtk_rc_parse_string (
|
||||
"style \"xedit-status-combo-button-style\"\n"
|
||||
"{\n"
|
||||
" GtkWidget::focus-padding = 0\n"
|
||||
" GtkWidget::focus-line-width = 0\n"
|
||||
" xthickness = 0\n"
|
||||
" ythickness = 0\n"
|
||||
"}\n"
|
||||
"widget \"*.xedit-status-combo-button\" style \"xedit-status-combo-button-style\"");
|
||||
signals[CHANGED] =
|
||||
g_signal_new ("changed",
|
||||
G_OBJECT_CLASS_TYPE (object_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (XeditStatusComboBoxClass,
|
||||
changed), NULL, NULL,
|
||||
g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
|
||||
GTK_TYPE_MENU_ITEM);
|
||||
|
||||
g_object_class_install_property (object_class, PROP_LABEL,
|
||||
g_param_spec_string ("label",
|
||||
"LABEL",
|
||||
"The label",
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_type_class_add_private (object_class, sizeof(XeditStatusComboBoxPrivate));
|
||||
g_type_class_add_private (object_class, sizeof(XeditStatusComboBoxPrivate));
|
||||
|
||||
klass->priv = G_TYPE_CLASS_GET_PRIVATE (klass, XEDIT_TYPE_STATUS_COMBO_BOX, XeditStatusComboBoxClassPrivate);
|
||||
|
||||
klass->priv->css = gtk_css_provider_new ();
|
||||
gtk_css_provider_load_from_data (klass->priv->css, style, -1, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
menu_deactivate (GtkMenu *menu,
|
||||
XeditStatusComboBox *combo)
|
||||
XeditStatusComboBox *combo)
|
||||
{
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo->priv->button), FALSE);
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo->priv->button), FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
menu_position_func (GtkMenu *menu,
|
||||
gint *x,
|
||||
gint *y,
|
||||
gboolean *push_in,
|
||||
XeditStatusComboBox *combo)
|
||||
menu_position_func (GtkMenu *menu,
|
||||
gint *x,
|
||||
gint *y,
|
||||
gboolean *push_in,
|
||||
XeditStatusComboBox *combo)
|
||||
{
|
||||
GtkRequisition request;
|
||||
GtkAllocation allocation;
|
||||
|
||||
*push_in = FALSE;
|
||||
GtkRequisition request;
|
||||
GtkAllocation allocation;
|
||||
|
||||
*push_in = FALSE;
|
||||
|
||||
#if GTK_CHECK_VERSION (3, 0, 0)
|
||||
gtk_widget_get_preferred_size (gtk_widget_get_toplevel (GTK_WIDGET (menu)), NULL, &request);
|
||||
#else
|
||||
gtk_widget_size_request (gtk_widget_get_toplevel (GTK_WIDGET (menu)), &request);
|
||||
#endif
|
||||
|
||||
/* get the origin... */
|
||||
gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (combo)), x, y);
|
||||
gtk_widget_get_allocation (GTK_WIDGET (combo), &allocation);
|
||||
|
||||
/* make the menu as wide as the widget */
|
||||
if (request.width < allocation.width)
|
||||
{
|
||||
gtk_widget_set_size_request (GTK_WIDGET (menu), allocation.width, -1);
|
||||
}
|
||||
|
||||
/* position it above the widget */
|
||||
*y -= request.height;
|
||||
gtk_widget_get_preferred_size (gtk_widget_get_toplevel (GTK_WIDGET (menu)), &request, NULL);
|
||||
|
||||
/* get the origin... */
|
||||
gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (combo)), x, y);
|
||||
gtk_widget_get_allocation (GTK_WIDGET (combo), &allocation);
|
||||
|
||||
/* make the menu as wide as the widget */
|
||||
if (request.width < allocation.width)
|
||||
{
|
||||
gtk_widget_set_size_request (GTK_WIDGET (menu), allocation.width, -1);
|
||||
}
|
||||
|
||||
/* position it above the widget */
|
||||
*y -= request.height;
|
||||
}
|
||||
|
||||
static void
|
||||
show_menu (XeditStatusComboBox *combo,
|
||||
guint button,
|
||||
guint32 time)
|
||||
{
|
||||
GtkRequisition request;
|
||||
gint max_height;
|
||||
GtkAllocation allocation;
|
||||
|
||||
gtk_widget_get_preferred_size (combo->priv->menu,
|
||||
&request, NULL);
|
||||
|
||||
/* do something relative to our own height here, maybe we can do better */
|
||||
gtk_widget_get_allocation (GTK_WIDGET (combo), &allocation);
|
||||
max_height = allocation.height * 20;
|
||||
|
||||
if (request.height > max_height)
|
||||
{
|
||||
gtk_widget_set_size_request (combo->priv->menu, -1, max_height);
|
||||
gtk_widget_set_size_request (gtk_widget_get_toplevel (combo->priv->menu), -1, max_height);
|
||||
}
|
||||
|
||||
gtk_menu_popup (GTK_MENU (combo->priv->menu),
|
||||
NULL,
|
||||
NULL,
|
||||
(GtkMenuPositionFunc)menu_position_func,
|
||||
combo,
|
||||
button,
|
||||
time);
|
||||
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo->priv->button), TRUE);
|
||||
|
||||
if (combo->priv->current_item)
|
||||
{
|
||||
gtk_menu_shell_select_item (GTK_MENU_SHELL (combo->priv->menu),
|
||||
combo->priv->current_item);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
menu_detached (GtkWidget *widget,
|
||||
GtkMenu *menu)
|
||||
{
|
||||
XeditStatusComboBox *combo = XEDIT_STATUS_COMBO_BOX (widget);
|
||||
|
||||
g_return_if_fail (GTK_MENU (combo->priv->menu) == menu);
|
||||
|
||||
combo->priv->menu = NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
button_press_event (GtkWidget *widget,
|
||||
GdkEventButton *event,
|
||||
XeditStatusComboBox *combo)
|
||||
GdkEventButton *event,
|
||||
XeditStatusComboBox *combo)
|
||||
{
|
||||
GtkRequisition request;
|
||||
GtkAllocation allocation;
|
||||
gint max_height;
|
||||
if (event->type == GDK_BUTTON_PRESS && event->button == 1)
|
||||
{
|
||||
show_menu (combo, event->button, event->time);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#if GTK_CHECK_VERSION (3, 0, 0)
|
||||
gtk_widget_get_preferred_size (combo->priv->menu, NULL, &request);
|
||||
#else
|
||||
gtk_widget_size_request (combo->priv->menu, &request);
|
||||
#endif
|
||||
gtk_widget_get_allocation (GTK_WIDGET (combo), &allocation);
|
||||
|
||||
/* do something relative to our own height here, maybe we can do better */
|
||||
max_height = allocation.height * 20;
|
||||
|
||||
if (request.height > max_height)
|
||||
{
|
||||
gtk_widget_set_size_request (combo->priv->menu, -1, max_height);
|
||||
gtk_widget_set_size_request (gtk_widget_get_toplevel (combo->priv->menu), -1, max_height);
|
||||
}
|
||||
|
||||
gtk_menu_popup (GTK_MENU (combo->priv->menu),
|
||||
NULL,
|
||||
NULL,
|
||||
(GtkMenuPositionFunc)menu_position_func,
|
||||
combo,
|
||||
event->button,
|
||||
event->time);
|
||||
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (combo->priv->button), TRUE);
|
||||
|
||||
if (combo->priv->current_item)
|
||||
{
|
||||
gtk_menu_shell_select_item (GTK_MENU_SHELL (combo->priv->menu),
|
||||
combo->priv->current_item);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
set_shadow_type (XeditStatusComboBox *combo)
|
||||
{
|
||||
GtkShadowType shadow_type;
|
||||
GtkWidget *statusbar;
|
||||
GtkStyleContext *context;
|
||||
GtkShadowType shadow_type;
|
||||
GtkWidget *statusbar;
|
||||
|
||||
/* This is a hack needed to use the shadow type of a statusbar */
|
||||
statusbar = gtk_statusbar_new ();
|
||||
gtk_widget_ensure_style (statusbar);
|
||||
/* This is a hack needed to use the shadow type of a statusbar */
|
||||
statusbar = gtk_statusbar_new ();
|
||||
context = gtk_widget_get_style_context (statusbar);
|
||||
|
||||
gtk_widget_style_get (statusbar, "shadow-type", &shadow_type, NULL);
|
||||
gtk_frame_set_shadow_type (GTK_FRAME (combo->priv->frame), shadow_type);
|
||||
gtk_style_context_get_style (context, "shadow-type", &shadow_type, NULL);
|
||||
gtk_frame_set_shadow_type (GTK_FRAME (combo->priv->frame), shadow_type);
|
||||
|
||||
gtk_widget_destroy (statusbar);
|
||||
gtk_widget_destroy (statusbar);
|
||||
}
|
||||
|
||||
static void
|
||||
xedit_status_combo_box_init (XeditStatusComboBox *self)
|
||||
{
|
||||
self->priv = XEDIT_STATUS_COMBO_BOX_GET_PRIVATE (self);
|
||||
|
||||
gtk_event_box_set_visible_window (GTK_EVENT_BOX (self), TRUE);
|
||||
GtkStyleContext *context;
|
||||
|
||||
self->priv->frame = gtk_frame_new (NULL);
|
||||
gtk_widget_show (self->priv->frame);
|
||||
|
||||
self->priv->button = gtk_toggle_button_new ();
|
||||
gtk_widget_set_name (self->priv->button, "xedit-status-combo-button");
|
||||
gtk_button_set_relief (GTK_BUTTON (self->priv->button), GTK_RELIEF_NONE);
|
||||
gtk_widget_show (self->priv->button);
|
||||
self->priv = XEDIT_STATUS_COMBO_BOX_GET_PRIVATE (self);
|
||||
|
||||
gtk_event_box_set_visible_window (GTK_EVENT_BOX (self), TRUE);
|
||||
|
||||
set_shadow_type (self);
|
||||
self->priv->frame = gtk_frame_new (NULL);
|
||||
gtk_widget_show (self->priv->frame);
|
||||
|
||||
self->priv->button = gtk_toggle_button_new ();
|
||||
gtk_button_set_relief (GTK_BUTTON (self->priv->button), GTK_RELIEF_NONE);
|
||||
gtk_widget_show (self->priv->button);
|
||||
|
||||
self->priv->hbox = gtk_hbox_new (FALSE, 3);
|
||||
gtk_widget_show (self->priv->hbox);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (self), self->priv->frame);
|
||||
gtk_container_add (GTK_CONTAINER (self->priv->frame), self->priv->button);
|
||||
gtk_container_add (GTK_CONTAINER (self->priv->button), self->priv->hbox);
|
||||
|
||||
self->priv->label = gtk_label_new ("");
|
||||
gtk_widget_show (self->priv->label);
|
||||
|
||||
gtk_label_set_single_line_mode (GTK_LABEL (self->priv->label), TRUE);
|
||||
#if GTK_CHECK_VERSION (3, 16, 0)
|
||||
gtk_label_set_xalign (GTK_LABEL (self->priv->label), 0.0);
|
||||
#else
|
||||
gtk_misc_set_alignment (GTK_MISC (self->priv->label), 0.0, 0.5);
|
||||
#endif
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (self->priv->hbox), self->priv->label, FALSE, TRUE, 0);
|
||||
|
||||
self->priv->item = gtk_label_new ("");
|
||||
gtk_widget_show (self->priv->item);
|
||||
|
||||
gtk_label_set_single_line_mode (GTK_LABEL (self->priv->item), TRUE);
|
||||
#if GTK_CHECK_VERSION (3, 0, 0)
|
||||
gtk_widget_set_halign (self->priv->item, GTK_ALIGN_START);
|
||||
#else
|
||||
gtk_misc_set_alignment (GTK_MISC (self->priv->item), 0, 0.5);
|
||||
#endif
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (self->priv->hbox), self->priv->item, TRUE, TRUE, 0);
|
||||
|
||||
self->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
|
||||
gtk_widget_show (self->priv->arrow);
|
||||
#if GTK_CHECK_VERSION (3, 0, 0)
|
||||
gtk_widget_set_halign (self->priv->arrow, GTK_ALIGN_CENTER);
|
||||
gtk_widget_set_valign (self->priv->arrow, GTK_ALIGN_CENTER);
|
||||
#else
|
||||
gtk_misc_set_alignment (GTK_MISC (self->priv->arrow), 0.5, 0.5);
|
||||
#endif
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (self->priv->hbox), self->priv->arrow, FALSE, TRUE, 0);
|
||||
|
||||
self->priv->menu = gtk_menu_new ();
|
||||
g_object_ref_sink (self->priv->menu);
|
||||
set_shadow_type (self);
|
||||
|
||||
g_signal_connect (self->priv->button,
|
||||
"button-press-event",
|
||||
G_CALLBACK (button_press_event),
|
||||
self);
|
||||
g_signal_connect (self->priv->menu,
|
||||
"deactivate",
|
||||
G_CALLBACK (menu_deactivate),
|
||||
self);
|
||||
self->priv->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
|
||||
gtk_widget_show (self->priv->hbox);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (self), self->priv->frame);
|
||||
gtk_container_add (GTK_CONTAINER (self->priv->frame), self->priv->button);
|
||||
gtk_container_add (GTK_CONTAINER (self->priv->button), self->priv->hbox);
|
||||
|
||||
self->priv->label = gtk_label_new ("");
|
||||
gtk_widget_show (self->priv->label);
|
||||
|
||||
gtk_label_set_single_line_mode (GTK_LABEL (self->priv->label), TRUE);
|
||||
gtk_widget_set_halign (GTK_WIDGET (self->priv->label), GTK_ALIGN_START);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (self->priv->hbox), self->priv->label, FALSE, TRUE, 0);
|
||||
|
||||
self->priv->item = gtk_label_new ("");
|
||||
gtk_widget_show (self->priv->item);
|
||||
|
||||
gtk_label_set_single_line_mode (GTK_LABEL (self->priv->item), TRUE);
|
||||
gtk_widget_set_halign (self->priv->item, GTK_ALIGN_START);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (self->priv->hbox), self->priv->item, TRUE, TRUE, 0);
|
||||
|
||||
self->priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
|
||||
gtk_widget_show (self->priv->arrow);
|
||||
|
||||
gtk_widget_set_halign (self->priv->arrow, GTK_ALIGN_CENTER);
|
||||
gtk_widget_set_valign (self->priv->arrow, GTK_ALIGN_CENTER);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (self->priv->hbox), self->priv->arrow, FALSE, TRUE, 0);
|
||||
|
||||
self->priv->menu = gtk_menu_new ();
|
||||
gtk_menu_attach_to_widget (GTK_MENU (self->priv->menu),
|
||||
GTK_WIDGET (self),
|
||||
menu_detached);
|
||||
|
||||
g_signal_connect (self->priv->button,
|
||||
"button-press-event",
|
||||
G_CALLBACK (button_press_event),
|
||||
self);
|
||||
g_signal_connect (self->priv->menu,
|
||||
"deactivate",
|
||||
G_CALLBACK (menu_deactivate),
|
||||
self);
|
||||
|
||||
context = gtk_widget_get_style_context (GTK_WIDGET (self->priv->button));
|
||||
gtk_style_context_add_provider (context,
|
||||
GTK_STYLE_PROVIDER (XEDIT_STATUS_COMBO_BOX_GET_CLASS (self)->priv->css),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
context = gtk_widget_get_style_context (GTK_WIDGET (self->priv->frame));
|
||||
gtk_style_context_add_provider (context,
|
||||
GTK_STYLE_PROVIDER (XEDIT_STATUS_COMBO_BOX_GET_CLASS (self)->priv->css),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
}
|
||||
|
||||
/* public functions */
|
||||
|
@ -340,7 +386,7 @@ xedit_status_combo_box_init (XeditStatusComboBox *self)
|
|||
GtkWidget *
|
||||
xedit_status_combo_box_new (const gchar *label)
|
||||
{
|
||||
return g_object_new (XEDIT_TYPE_STATUS_COMBO_BOX, "label", label, NULL);
|
||||
return g_object_new (XEDIT_TYPE_STATUS_COMBO_BOX, "label", label, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -350,30 +396,30 @@ xedit_status_combo_box_new (const gchar *label)
|
|||
*/
|
||||
void
|
||||
xedit_status_combo_box_set_label (XeditStatusComboBox *combo,
|
||||
const gchar *label)
|
||||
const gchar *label)
|
||||
{
|
||||
gchar *text;
|
||||
gchar *text;
|
||||
|
||||
g_return_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo));
|
||||
|
||||
text = g_strconcat (" ", label, ": ", NULL);
|
||||
gtk_label_set_markup (GTK_LABEL (combo->priv->label), text);
|
||||
g_free (text);
|
||||
g_return_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo));
|
||||
|
||||
text = g_strconcat (" ", label, ": ", NULL);
|
||||
gtk_label_set_markup (GTK_LABEL (combo->priv->label), text);
|
||||
g_free (text);
|
||||
}
|
||||
|
||||
const gchar *
|
||||
xedit_status_combo_box_get_label (XeditStatusComboBox *combo)
|
||||
{
|
||||
g_return_val_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo), NULL);
|
||||
g_return_val_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo), NULL);
|
||||
|
||||
return gtk_label_get_label (GTK_LABEL (combo->priv->label));
|
||||
return gtk_label_get_label (GTK_LABEL (combo->priv->label));
|
||||
}
|
||||
|
||||
static void
|
||||
item_activated (GtkMenuItem *item,
|
||||
XeditStatusComboBox *combo)
|
||||
XeditStatusComboBox *combo)
|
||||
{
|
||||
xedit_status_combo_box_set_item (combo, item);
|
||||
xedit_status_combo_box_set_item (combo, item);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -384,49 +430,49 @@ item_activated (GtkMenuItem *item,
|
|||
*/
|
||||
void
|
||||
xedit_status_combo_box_add_item (XeditStatusComboBox *combo,
|
||||
GtkMenuItem *item,
|
||||
const gchar *text)
|
||||
GtkMenuItem *item,
|
||||
const gchar *text)
|
||||
{
|
||||
g_return_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo));
|
||||
g_return_if_fail (GTK_IS_MENU_ITEM (item));
|
||||
g_return_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo));
|
||||
g_return_if_fail (GTK_IS_MENU_ITEM (item));
|
||||
|
||||
gtk_menu_shell_append (GTK_MENU_SHELL (combo->priv->menu), GTK_WIDGET (item));
|
||||
|
||||
xedit_status_combo_box_set_item_text (combo, item, text);
|
||||
g_signal_connect (item, "activate", G_CALLBACK (item_activated), combo);
|
||||
gtk_menu_shell_append (GTK_MENU_SHELL (combo->priv->menu), GTK_WIDGET (item));
|
||||
|
||||
xedit_status_combo_box_set_item_text (combo, item, text);
|
||||
g_signal_connect (item, "activate", G_CALLBACK (item_activated), combo);
|
||||
}
|
||||
|
||||
void
|
||||
xedit_status_combo_box_remove_item (XeditStatusComboBox *combo,
|
||||
GtkMenuItem *item)
|
||||
GtkMenuItem *item)
|
||||
{
|
||||
g_return_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo));
|
||||
g_return_if_fail (GTK_IS_MENU_ITEM (item));
|
||||
g_return_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo));
|
||||
g_return_if_fail (GTK_IS_MENU_ITEM (item));
|
||||
|
||||
gtk_container_remove (GTK_CONTAINER (combo->priv->menu),
|
||||
GTK_WIDGET (item));
|
||||
gtk_container_remove (GTK_CONTAINER (combo->priv->menu),
|
||||
GTK_WIDGET (item));
|
||||
}
|
||||
|
||||
GList *
|
||||
xedit_status_combo_box_get_items (XeditStatusComboBox *combo)
|
||||
{
|
||||
g_return_val_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo), NULL);
|
||||
g_return_val_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo), NULL);
|
||||
|
||||
return gtk_container_get_children (GTK_CONTAINER (combo->priv->menu));
|
||||
return gtk_container_get_children (GTK_CONTAINER (combo->priv->menu));
|
||||
}
|
||||
|
||||
const gchar *
|
||||
xedit_status_combo_box_get_item_text (XeditStatusComboBox *combo,
|
||||
GtkMenuItem *item)
|
||||
GtkMenuItem *item)
|
||||
{
|
||||
const gchar *ret = NULL;
|
||||
|
||||
g_return_val_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo), NULL);
|
||||
g_return_val_if_fail (GTK_IS_MENU_ITEM (item), NULL);
|
||||
|
||||
ret = g_object_get_data (G_OBJECT (item), COMBO_BOX_TEXT_DATA);
|
||||
|
||||
return ret;
|
||||
const gchar *ret = NULL;
|
||||
|
||||
g_return_val_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo), NULL);
|
||||
g_return_val_if_fail (GTK_IS_MENU_ITEM (item), NULL);
|
||||
|
||||
ret = g_object_get_data (G_OBJECT (item), COMBO_BOX_TEXT_DATA);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -437,33 +483,33 @@ xedit_status_combo_box_get_item_text (XeditStatusComboBox *combo,
|
|||
*/
|
||||
void
|
||||
xedit_status_combo_box_set_item_text (XeditStatusComboBox *combo,
|
||||
GtkMenuItem *item,
|
||||
const gchar *text)
|
||||
GtkMenuItem *item,
|
||||
const gchar *text)
|
||||
{
|
||||
g_return_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo));
|
||||
g_return_if_fail (GTK_IS_MENU_ITEM (item));
|
||||
g_return_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo));
|
||||
g_return_if_fail (GTK_IS_MENU_ITEM (item));
|
||||
|
||||
g_object_set_data_full (G_OBJECT (item),
|
||||
COMBO_BOX_TEXT_DATA,
|
||||
g_strdup (text),
|
||||
(GDestroyNotify)g_free);
|
||||
g_object_set_data_full (G_OBJECT (item),
|
||||
COMBO_BOX_TEXT_DATA,
|
||||
g_strdup (text),
|
||||
(GDestroyNotify)g_free);
|
||||
}
|
||||
|
||||
void
|
||||
xedit_status_combo_box_set_item (XeditStatusComboBox *combo,
|
||||
GtkMenuItem *item)
|
||||
GtkMenuItem *item)
|
||||
{
|
||||
g_return_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo));
|
||||
g_return_if_fail (GTK_IS_MENU_ITEM (item));
|
||||
g_return_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo));
|
||||
g_return_if_fail (GTK_IS_MENU_ITEM (item));
|
||||
|
||||
g_signal_emit (combo, signals[CHANGED], 0, item, NULL);
|
||||
g_signal_emit (combo, signals[CHANGED], 0, item, NULL);
|
||||
}
|
||||
|
||||
GtkLabel *
|
||||
xedit_status_combo_box_get_item_label (XeditStatusComboBox *combo)
|
||||
{
|
||||
g_return_val_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo), NULL);
|
||||
|
||||
return GTK_LABEL (combo->priv->item);
|
||||
g_return_val_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo), NULL);
|
||||
|
||||
return GTK_LABEL (combo->priv->item);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,55 +27,60 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define XEDIT_TYPE_STATUS_COMBO_BOX (xedit_status_combo_box_get_type ())
|
||||
#define XEDIT_STATUS_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XEDIT_TYPE_STATUS_COMBO_BOX, XeditStatusComboBox))
|
||||
#define XEDIT_STATUS_COMBO_BOX_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XEDIT_TYPE_STATUS_COMBO_BOX, XeditStatusComboBox const))
|
||||
#define XEDIT_STATUS_COMBO_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XEDIT_TYPE_STATUS_COMBO_BOX, XeditStatusComboBoxClass))
|
||||
#define XEDIT_IS_STATUS_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XEDIT_TYPE_STATUS_COMBO_BOX))
|
||||
#define XEDIT_IS_STATUS_COMBO_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XEDIT_TYPE_STATUS_COMBO_BOX))
|
||||
#define XEDIT_STATUS_COMBO_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XEDIT_TYPE_STATUS_COMBO_BOX, XeditStatusComboBoxClass))
|
||||
#define XEDIT_TYPE_STATUS_COMBO_BOX (xedit_status_combo_box_get_type ())
|
||||
#define XEDIT_STATUS_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XEDIT_TYPE_STATUS_COMBO_BOX, XeditStatusComboBox))
|
||||
#define XEDIT_STATUS_COMBO_BOX_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XEDIT_TYPE_STATUS_COMBO_BOX, XeditStatusComboBox const))
|
||||
#define XEDIT_STATUS_COMBO_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XEDIT_TYPE_STATUS_COMBO_BOX, XeditStatusComboBoxClass))
|
||||
#define XEDIT_IS_STATUS_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XEDIT_TYPE_STATUS_COMBO_BOX))
|
||||
#define XEDIT_IS_STATUS_COMBO_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XEDIT_TYPE_STATUS_COMBO_BOX))
|
||||
#define XEDIT_STATUS_COMBO_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XEDIT_TYPE_STATUS_COMBO_BOX, XeditStatusComboBoxClass))
|
||||
|
||||
typedef struct _XeditStatusComboBox XeditStatusComboBox;
|
||||
typedef struct _XeditStatusComboBoxClass XeditStatusComboBoxClass;
|
||||
typedef struct _XeditStatusComboBoxPrivate XeditStatusComboBoxPrivate;
|
||||
typedef struct _XeditStatusComboBox XeditStatusComboBox;
|
||||
typedef struct _XeditStatusComboBoxPrivate XeditStatusComboBoxPrivate;
|
||||
typedef struct _XeditStatusComboBoxClass XeditStatusComboBoxClass;
|
||||
typedef struct _XeditStatusComboBoxClassPrivate XeditStatusComboBoxClassPrivate;
|
||||
|
||||
struct _XeditStatusComboBox {
|
||||
GtkEventBox parent;
|
||||
|
||||
XeditStatusComboBoxPrivate *priv;
|
||||
struct _XeditStatusComboBox
|
||||
{
|
||||
GtkEventBox parent;
|
||||
|
||||
XeditStatusComboBoxPrivate *priv;
|
||||
};
|
||||
|
||||
struct _XeditStatusComboBoxClass {
|
||||
GtkEventBoxClass parent_class;
|
||||
|
||||
void (*changed) (XeditStatusComboBox *combo,
|
||||
GtkMenuItem *item);
|
||||
struct _XeditStatusComboBoxClass
|
||||
{
|
||||
GtkEventBoxClass parent_class;
|
||||
|
||||
XeditStatusComboBoxClassPrivate *priv;
|
||||
|
||||
void (*changed) (XeditStatusComboBox *combo,
|
||||
GtkMenuItem *item);
|
||||
};
|
||||
|
||||
GType xedit_status_combo_box_get_type (void) G_GNUC_CONST;
|
||||
GtkWidget *xedit_status_combo_box_new (const gchar *label);
|
||||
GType xedit_status_combo_box_get_type (void) G_GNUC_CONST;
|
||||
GtkWidget *xedit_status_combo_box_new (const gchar *label);
|
||||
|
||||
const gchar *xedit_status_combo_box_get_label (XeditStatusComboBox *combo);
|
||||
void xedit_status_combo_box_set_label (XeditStatusComboBox *combo,
|
||||
const gchar *label);
|
||||
const gchar *xedit_status_combo_box_get_label (XeditStatusComboBox *combo);
|
||||
void xedit_status_combo_box_set_label (XeditStatusComboBox *combo,
|
||||
const gchar *label);
|
||||
|
||||
void xedit_status_combo_box_add_item (XeditStatusComboBox *combo,
|
||||
GtkMenuItem *item,
|
||||
const gchar *text);
|
||||
void xedit_status_combo_box_remove_item (XeditStatusComboBox *combo,
|
||||
GtkMenuItem *item);
|
||||
void xedit_status_combo_box_add_item (XeditStatusComboBox *combo,
|
||||
GtkMenuItem *item,
|
||||
const gchar *text);
|
||||
void xedit_status_combo_box_remove_item (XeditStatusComboBox *combo,
|
||||
GtkMenuItem *item);
|
||||
|
||||
GList *xedit_status_combo_box_get_items (XeditStatusComboBox *combo);
|
||||
const gchar *xedit_status_combo_box_get_item_text (XeditStatusComboBox *combo,
|
||||
GtkMenuItem *item);
|
||||
void xedit_status_combo_box_set_item_text (XeditStatusComboBox *combo,
|
||||
GtkMenuItem *item,
|
||||
const gchar *text);
|
||||
GList *xedit_status_combo_box_get_items (XeditStatusComboBox *combo);
|
||||
const gchar *xedit_status_combo_box_get_item_text (XeditStatusComboBox *combo,
|
||||
GtkMenuItem *item);
|
||||
void xedit_status_combo_box_set_item_text (XeditStatusComboBox *combo,
|
||||
GtkMenuItem *item,
|
||||
const gchar *text);
|
||||
|
||||
void xedit_status_combo_box_set_item (XeditStatusComboBox *combo,
|
||||
GtkMenuItem *item);
|
||||
void xedit_status_combo_box_set_item (XeditStatusComboBox *combo,
|
||||
GtkMenuItem *item);
|
||||
|
||||
GtkLabel *xedit_status_combo_box_get_item_label (XeditStatusComboBox *combo);
|
||||
GtkLabel *xedit_status_combo_box_get_item_label (XeditStatusComboBox *combo);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
Loading…
Reference in New Issue