Merge pull request #1 from JosephMcc/update-1

Clean up GTK support
This commit is contained in:
Clement Lefebvre 2016-01-27 14:14:29 +00:00
commit 5cdbafaa2c
3 changed files with 544 additions and 502 deletions

View File

@ -26,309 +26,355 @@
#define XEDIT_STATUS_COMBO_BOX_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), XEDIT_TYPE_STATUS_COMBO_BOX, XeditStatusComboBoxPrivate)) #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) static void menu_deactivate (GtkMenu *menu, XeditStatusComboBox *combo);
#define gtk_hbox_new(X,Y) gtk_box_new(GTK_ORIENTATION_HORIZONTAL,Y)
#endif
struct _XeditStatusComboBoxPrivate struct _XeditStatusComboBoxPrivate
{ {
GtkWidget *frame; GtkWidget *frame;
GtkWidget *button; GtkWidget *button;
GtkWidget *hbox; GtkWidget *hbox;
GtkWidget *label; GtkWidget *label;
GtkWidget *item; GtkWidget *item;
GtkWidget *arrow; GtkWidget *arrow;
GtkWidget *menu; GtkWidget *menu;
GtkWidget *current_item; GtkWidget *current_item;
};
struct _XeditStatusComboBoxClassPrivate
{
GtkCssProvider *css;
}; };
/* Signals */ /* Signals */
enum enum
{ {
CHANGED, CHANGED,
NUM_SIGNALS NUM_SIGNALS
}; };
/* Properties */ /* Properties */
enum enum
{ {
PROP_0, PROP_0,
PROP_LABEL PROP_LABEL
}; };
static guint signals[NUM_SIGNALS] = { 0 }; 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 static void
xedit_status_combo_box_finalize (GObject *object) 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 static void
xedit_status_combo_box_get_property (GObject *object, xedit_status_combo_box_get_property (GObject *object,
guint prop_id, guint prop_id,
GValue *value, GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
XeditStatusComboBox *obj = XEDIT_STATUS_COMBO_BOX (object); XeditStatusComboBox *obj = XEDIT_STATUS_COMBO_BOX (object);
switch (prop_id) switch (prop_id)
{ {
case PROP_LABEL: case PROP_LABEL:
g_value_set_string (value, xedit_status_combo_box_get_label (obj)); g_value_set_string (value, xedit_status_combo_box_get_label (obj));
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
} }
} }
static void static void
xedit_status_combo_box_set_property (GObject *object, xedit_status_combo_box_set_property (GObject *object,
guint prop_id, guint prop_id,
const GValue *value, const GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
XeditStatusComboBox *obj = XEDIT_STATUS_COMBO_BOX (object); XeditStatusComboBox *obj = XEDIT_STATUS_COMBO_BOX (object);
switch (prop_id) switch (prop_id)
{ {
case PROP_LABEL: case PROP_LABEL:
xedit_status_combo_box_set_label (obj, g_value_get_string (value)); xedit_status_combo_box_set_label (obj, g_value_get_string (value));
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; 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 static void
xedit_status_combo_box_changed (XeditStatusComboBox *combo, xedit_status_combo_box_changed (XeditStatusComboBox *combo,
GtkMenuItem *item) GtkMenuItem *item)
{ {
const gchar *text; const gchar *text;
text = g_object_get_data (G_OBJECT (item), COMBO_BOX_TEXT_DATA); text = g_object_get_data (G_OBJECT (item), COMBO_BOX_TEXT_DATA);
if (text != NULL) if (text != NULL)
{ {
gtk_label_set_markup (GTK_LABEL (combo->priv->item), text); gtk_label_set_markup (GTK_LABEL (combo->priv->item), text);
combo->priv->current_item = GTK_WIDGET (item); combo->priv->current_item = GTK_WIDGET (item);
} }
} }
static void static void
xedit_status_combo_box_class_init (XeditStatusComboBoxClass *klass) xedit_status_combo_box_class_init (XeditStatusComboBoxClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->finalize = xedit_status_combo_box_finalize; static const gchar style[] =
object_class->get_property = xedit_status_combo_box_get_property; "* {\n"
object_class->set_property = xedit_status_combo_box_set_property; "-GtkButton-default-border : 0;\n"
"-GtkButton-default-outside-border : 0;\n"
klass->changed = xedit_status_combo_box_changed; "-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] = widget_class->destroy = xedit_status_combo_box_destroy;
g_signal_new ("changed",
G_OBJECT_CLASS_TYPE (object_class), klass->changed = xedit_status_combo_box_changed;
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));
/* Set up a style for the button to decrease spacing. */ signals[CHANGED] =
gtk_rc_parse_string ( g_signal_new ("changed",
"style \"xedit-status-combo-button-style\"\n" G_OBJECT_CLASS_TYPE (object_class),
"{\n" G_SIGNAL_RUN_LAST,
" GtkWidget::focus-padding = 0\n" G_STRUCT_OFFSET (XeditStatusComboBoxClass,
" GtkWidget::focus-line-width = 0\n" changed), NULL, NULL,
" xthickness = 0\n" g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
" ythickness = 0\n" GTK_TYPE_MENU_ITEM);
"}\n"
"widget \"*.xedit-status-combo-button\" style \"xedit-status-combo-button-style\""); 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 static void
menu_deactivate (GtkMenu *menu, 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 static void
menu_position_func (GtkMenu *menu, menu_position_func (GtkMenu *menu,
gint *x, gint *x,
gint *y, gint *y,
gboolean *push_in, gboolean *push_in,
XeditStatusComboBox *combo) XeditStatusComboBox *combo)
{ {
GtkRequisition request; GtkRequisition request;
GtkAllocation allocation; GtkAllocation allocation;
*push_in = FALSE; *push_in = FALSE;
#if GTK_CHECK_VERSION (3, 0, 0) gtk_widget_get_preferred_size (gtk_widget_get_toplevel (GTK_WIDGET (menu)), &request, NULL);
gtk_widget_get_preferred_size (gtk_widget_get_toplevel (GTK_WIDGET (menu)), NULL, &request);
#else /* get the origin... */
gtk_widget_size_request (gtk_widget_get_toplevel (GTK_WIDGET (menu)), &request); gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (combo)), x, y);
#endif gtk_widget_get_allocation (GTK_WIDGET (combo), &allocation);
/* get the origin... */ /* make the menu as wide as the widget */
gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (combo)), x, y); if (request.width < allocation.width)
gtk_widget_get_allocation (GTK_WIDGET (combo), &allocation); {
gtk_widget_set_size_request (GTK_WIDGET (menu), allocation.width, -1);
/* make the menu as wide as the widget */ }
if (request.width < allocation.width)
{ /* position it above the widget */
gtk_widget_set_size_request (GTK_WIDGET (menu), allocation.width, -1); *y -= request.height;
}
/* position it above the widget */
*y -= request.height;
} }
static void 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, button_press_event (GtkWidget *widget,
GdkEventButton *event, GdkEventButton *event,
XeditStatusComboBox *combo) XeditStatusComboBox *combo)
{ {
GtkRequisition request; if (event->type == GDK_BUTTON_PRESS && event->button == 1)
GtkAllocation allocation; {
gint max_height; show_menu (combo, event->button, event->time);
return TRUE;
}
#if GTK_CHECK_VERSION (3, 0, 0) return FALSE;
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);
}
} }
static void static void
set_shadow_type (XeditStatusComboBox *combo) set_shadow_type (XeditStatusComboBox *combo)
{ {
GtkShadowType shadow_type; GtkStyleContext *context;
GtkWidget *statusbar; GtkShadowType shadow_type;
GtkWidget *statusbar;
/* This is a hack needed to use the shadow type of a statusbar */ /* This is a hack needed to use the shadow type of a statusbar */
statusbar = gtk_statusbar_new (); statusbar = gtk_statusbar_new ();
gtk_widget_ensure_style (statusbar); context = gtk_widget_get_style_context (statusbar);
gtk_widget_style_get (statusbar, "shadow-type", &shadow_type, NULL); gtk_style_context_get_style (context, "shadow-type", &shadow_type, NULL);
gtk_frame_set_shadow_type (GTK_FRAME (combo->priv->frame), shadow_type); gtk_frame_set_shadow_type (GTK_FRAME (combo->priv->frame), shadow_type);
gtk_widget_destroy (statusbar); gtk_widget_destroy (statusbar);
} }
static void static void
xedit_status_combo_box_init (XeditStatusComboBox *self) xedit_status_combo_box_init (XeditStatusComboBox *self)
{ {
self->priv = XEDIT_STATUS_COMBO_BOX_GET_PRIVATE (self); GtkStyleContext *context;
gtk_event_box_set_visible_window (GTK_EVENT_BOX (self), TRUE);
self->priv->frame = gtk_frame_new (NULL); self->priv = XEDIT_STATUS_COMBO_BOX_GET_PRIVATE (self);
gtk_widget_show (self->priv->frame);
gtk_event_box_set_visible_window (GTK_EVENT_BOX (self), TRUE);
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);
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); set_shadow_type (self);
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);
g_signal_connect (self->priv->button, self->priv->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
"button-press-event", gtk_widget_show (self->priv->hbox);
G_CALLBACK (button_press_event),
self); gtk_container_add (GTK_CONTAINER (self), self->priv->frame);
g_signal_connect (self->priv->menu, gtk_container_add (GTK_CONTAINER (self->priv->frame), self->priv->button);
"deactivate", gtk_container_add (GTK_CONTAINER (self->priv->button), self->priv->hbox);
G_CALLBACK (menu_deactivate),
self); 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 */ /* public functions */
@ -340,7 +386,7 @@ xedit_status_combo_box_init (XeditStatusComboBox *self)
GtkWidget * GtkWidget *
xedit_status_combo_box_new (const gchar *label) 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 void
xedit_status_combo_box_set_label (XeditStatusComboBox *combo, 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)); g_return_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo));
text = g_strconcat (" ", label, ": ", NULL); text = g_strconcat (" ", label, ": ", NULL);
gtk_label_set_markup (GTK_LABEL (combo->priv->label), text); gtk_label_set_markup (GTK_LABEL (combo->priv->label), text);
g_free (text); g_free (text);
} }
const gchar * const gchar *
xedit_status_combo_box_get_label (XeditStatusComboBox *combo) 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 static void
item_activated (GtkMenuItem *item, 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 void
xedit_status_combo_box_add_item (XeditStatusComboBox *combo, xedit_status_combo_box_add_item (XeditStatusComboBox *combo,
GtkMenuItem *item, GtkMenuItem *item,
const gchar *text) const gchar *text)
{ {
g_return_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo)); g_return_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo));
g_return_if_fail (GTK_IS_MENU_ITEM (item)); g_return_if_fail (GTK_IS_MENU_ITEM (item));
gtk_menu_shell_append (GTK_MENU_SHELL (combo->priv->menu), GTK_WIDGET (item)); gtk_menu_shell_append (GTK_MENU_SHELL (combo->priv->menu), GTK_WIDGET (item));
xedit_status_combo_box_set_item_text (combo, item, text); xedit_status_combo_box_set_item_text (combo, item, text);
g_signal_connect (item, "activate", G_CALLBACK (item_activated), combo); g_signal_connect (item, "activate", G_CALLBACK (item_activated), combo);
} }
void void
xedit_status_combo_box_remove_item (XeditStatusComboBox *combo, 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 (XEDIT_IS_STATUS_COMBO_BOX (combo));
g_return_if_fail (GTK_IS_MENU_ITEM (item)); g_return_if_fail (GTK_IS_MENU_ITEM (item));
gtk_container_remove (GTK_CONTAINER (combo->priv->menu), gtk_container_remove (GTK_CONTAINER (combo->priv->menu),
GTK_WIDGET (item)); GTK_WIDGET (item));
} }
GList * GList *
xedit_status_combo_box_get_items (XeditStatusComboBox *combo) 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 * const gchar *
xedit_status_combo_box_get_item_text (XeditStatusComboBox *combo, xedit_status_combo_box_get_item_text (XeditStatusComboBox *combo,
GtkMenuItem *item) GtkMenuItem *item)
{ {
const gchar *ret = NULL; const gchar *ret = NULL;
g_return_val_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo), NULL); g_return_val_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo), NULL);
g_return_val_if_fail (GTK_IS_MENU_ITEM (item), NULL); g_return_val_if_fail (GTK_IS_MENU_ITEM (item), NULL);
ret = g_object_get_data (G_OBJECT (item), COMBO_BOX_TEXT_DATA); ret = g_object_get_data (G_OBJECT (item), COMBO_BOX_TEXT_DATA);
return ret; return ret;
} }
/** /**
@ -437,33 +483,33 @@ xedit_status_combo_box_get_item_text (XeditStatusComboBox *combo,
*/ */
void void
xedit_status_combo_box_set_item_text (XeditStatusComboBox *combo, xedit_status_combo_box_set_item_text (XeditStatusComboBox *combo,
GtkMenuItem *item, GtkMenuItem *item,
const gchar *text) const gchar *text)
{ {
g_return_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo)); g_return_if_fail (XEDIT_IS_STATUS_COMBO_BOX (combo));
g_return_if_fail (GTK_IS_MENU_ITEM (item)); g_return_if_fail (GTK_IS_MENU_ITEM (item));
g_object_set_data_full (G_OBJECT (item), g_object_set_data_full (G_OBJECT (item),
COMBO_BOX_TEXT_DATA, COMBO_BOX_TEXT_DATA,
g_strdup (text), g_strdup (text),
(GDestroyNotify)g_free); (GDestroyNotify)g_free);
} }
void void
xedit_status_combo_box_set_item (XeditStatusComboBox *combo, 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 (XEDIT_IS_STATUS_COMBO_BOX (combo));
g_return_if_fail (GTK_IS_MENU_ITEM (item)); 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 * GtkLabel *
xedit_status_combo_box_get_item_label (XeditStatusComboBox *combo) xedit_status_combo_box_get_item_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 (combo->priv->item); return GTK_LABEL (combo->priv->item);
} }

View File

@ -27,55 +27,60 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define XEDIT_TYPE_STATUS_COMBO_BOX (xedit_status_combo_box_get_type ()) #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(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_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_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(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_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_STATUS_COMBO_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XEDIT_TYPE_STATUS_COMBO_BOX, XeditStatusComboBoxClass))
typedef struct _XeditStatusComboBox XeditStatusComboBox; typedef struct _XeditStatusComboBox XeditStatusComboBox;
typedef struct _XeditStatusComboBoxClass XeditStatusComboBoxClass; typedef struct _XeditStatusComboBoxPrivate XeditStatusComboBoxPrivate;
typedef struct _XeditStatusComboBoxPrivate XeditStatusComboBoxPrivate; typedef struct _XeditStatusComboBoxClass XeditStatusComboBoxClass;
typedef struct _XeditStatusComboBoxClassPrivate XeditStatusComboBoxClassPrivate;
struct _XeditStatusComboBox { struct _XeditStatusComboBox
GtkEventBox parent; {
GtkEventBox parent;
XeditStatusComboBoxPrivate *priv;
XeditStatusComboBoxPrivate *priv;
}; };
struct _XeditStatusComboBoxClass { struct _XeditStatusComboBoxClass
GtkEventBoxClass parent_class; {
GtkEventBoxClass parent_class;
void (*changed) (XeditStatusComboBox *combo,
GtkMenuItem *item); XeditStatusComboBoxClassPrivate *priv;
void (*changed) (XeditStatusComboBox *combo,
GtkMenuItem *item);
}; };
GType xedit_status_combo_box_get_type (void) G_GNUC_CONST; GType xedit_status_combo_box_get_type (void) G_GNUC_CONST;
GtkWidget *xedit_status_combo_box_new (const gchar *label); GtkWidget *xedit_status_combo_box_new (const gchar *label);
const gchar *xedit_status_combo_box_get_label (XeditStatusComboBox *combo); const gchar *xedit_status_combo_box_get_label (XeditStatusComboBox *combo);
void xedit_status_combo_box_set_label (XeditStatusComboBox *combo, void xedit_status_combo_box_set_label (XeditStatusComboBox *combo,
const gchar *label); const gchar *label);
void xedit_status_combo_box_add_item (XeditStatusComboBox *combo, void xedit_status_combo_box_add_item (XeditStatusComboBox *combo,
GtkMenuItem *item, GtkMenuItem *item,
const gchar *text); const gchar *text);
void xedit_status_combo_box_remove_item (XeditStatusComboBox *combo, void xedit_status_combo_box_remove_item (XeditStatusComboBox *combo,
GtkMenuItem *item); GtkMenuItem *item);
GList *xedit_status_combo_box_get_items (XeditStatusComboBox *combo); GList *xedit_status_combo_box_get_items (XeditStatusComboBox *combo);
const gchar *xedit_status_combo_box_get_item_text (XeditStatusComboBox *combo, const gchar *xedit_status_combo_box_get_item_text (XeditStatusComboBox *combo,
GtkMenuItem *item); GtkMenuItem *item);
void xedit_status_combo_box_set_item_text (XeditStatusComboBox *combo, void xedit_status_combo_box_set_item_text (XeditStatusComboBox *combo,
GtkMenuItem *item, GtkMenuItem *item,
const gchar *text); const gchar *text);
void xedit_status_combo_box_set_item (XeditStatusComboBox *combo, void xedit_status_combo_box_set_item (XeditStatusComboBox *combo,
GtkMenuItem *item); 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 G_END_DECLS

View File

@ -39,30 +39,26 @@
#include "xedit-statusbar.h" #include "xedit-statusbar.h"
#define XEDIT_STATUSBAR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object),\ #define XEDIT_STATUSBAR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object),\
XEDIT_TYPE_STATUSBAR,\ XEDIT_TYPE_STATUSBAR,\
XeditStatusbarPrivate)) XeditStatusbarPrivate))
#if GTK_CHECK_VERSION (3, 0, 0)
#define gtk_hbox_new(X,Y) gtk_box_new(GTK_ORIENTATION_HORIZONTAL,Y)
#endif
struct _XeditStatusbarPrivate struct _XeditStatusbarPrivate
{ {
GtkWidget *overwrite_mode_label; GtkWidget *overwrite_mode_label;
GtkWidget *cursor_position_label; GtkWidget *cursor_position_label;
GtkWidget *state_frame; GtkWidget *state_frame;
GtkWidget *load_image; GtkWidget *load_image;
GtkWidget *save_image; GtkWidget *save_image;
GtkWidget *print_image; GtkWidget *print_image;
GtkWidget *error_frame; GtkWidget *error_frame;
GtkWidget *error_event_box; GtkWidget *error_event_box;
/* tmp flash timeout data */ /* tmp flash timeout data */
guint flash_timeout; guint flash_timeout;
guint flash_context_id; guint flash_context_id;
guint flash_message_id; guint flash_message_id;
}; };
G_DEFINE_TYPE(XeditStatusbar, xedit_statusbar, GTK_TYPE_STATUSBAR) G_DEFINE_TYPE(XeditStatusbar, xedit_statusbar, GTK_TYPE_STATUSBAR)
@ -71,37 +67,37 @@ G_DEFINE_TYPE(XeditStatusbar, xedit_statusbar, GTK_TYPE_STATUSBAR)
static gchar * static gchar *
get_overwrite_mode_string (gboolean overwrite) get_overwrite_mode_string (gboolean overwrite)
{ {
return g_strconcat (" ", overwrite ? _("OVR") : _("INS"), NULL); return g_strconcat (" ", overwrite ? _("OVR") : _("INS"), NULL);
} }
static gint static gint
get_overwrite_mode_length (void) get_overwrite_mode_length (void)
{ {
return 2 + MAX (g_utf8_strlen (_("OVR"), -1), g_utf8_strlen (_("INS"), -1)); return 2 + MAX (g_utf8_strlen (_("OVR"), -1), g_utf8_strlen (_("INS"), -1));
} }
static void static void
xedit_statusbar_dispose (GObject *object) xedit_statusbar_dispose (GObject *object)
{ {
XeditStatusbar *statusbar = XEDIT_STATUSBAR (object); XeditStatusbar *statusbar = XEDIT_STATUSBAR (object);
if (statusbar->priv->flash_timeout > 0) if (statusbar->priv->flash_timeout > 0)
{ {
g_source_remove (statusbar->priv->flash_timeout); g_source_remove (statusbar->priv->flash_timeout);
statusbar->priv->flash_timeout = 0; statusbar->priv->flash_timeout = 0;
} }
G_OBJECT_CLASS (xedit_statusbar_parent_class)->dispose (object); G_OBJECT_CLASS (xedit_statusbar_parent_class)->dispose (object);
} }
static void static void
xedit_statusbar_class_init (XeditStatusbarClass *klass) xedit_statusbar_class_init (XeditStatusbarClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = xedit_statusbar_dispose; object_class->dispose = xedit_statusbar_dispose;
g_type_class_add_private (object_class, sizeof (XeditStatusbarPrivate)); g_type_class_add_private (object_class, sizeof (XeditStatusbarPrivate));
} }
#define CURSOR_POSITION_LABEL_WIDTH_CHARS 18 #define CURSOR_POSITION_LABEL_WIDTH_CHARS 18
@ -109,94 +105,89 @@ xedit_statusbar_class_init (XeditStatusbarClass *klass)
static void static void
xedit_statusbar_init (XeditStatusbar *statusbar) xedit_statusbar_init (XeditStatusbar *statusbar)
{ {
GtkWidget *hbox; GtkWidget *hbox;
GtkWidget *error_image; GtkWidget *error_image;
statusbar->priv = XEDIT_STATUSBAR_GET_PRIVATE (statusbar); statusbar->priv = XEDIT_STATUSBAR_GET_PRIVATE (statusbar);
#if GTK_CHECK_VERSION (3, 0, 0) gtk_widget_set_margin_top (GTK_WIDGET (statusbar), 0);
gtk_widget_set_margin_top (GTK_WIDGET (statusbar), 0); gtk_widget_set_margin_bottom (GTK_WIDGET (statusbar), 0);
gtk_widget_set_margin_bottom (GTK_WIDGET (statusbar), 0);
#endif
statusbar->priv->overwrite_mode_label = gtk_label_new (NULL); statusbar->priv->overwrite_mode_label = gtk_label_new (NULL);
gtk_label_set_width_chars (GTK_LABEL (statusbar->priv->overwrite_mode_label), gtk_label_set_width_chars (GTK_LABEL (statusbar->priv->overwrite_mode_label),
get_overwrite_mode_length ()); get_overwrite_mode_length ());
gtk_widget_show (statusbar->priv->overwrite_mode_label); gtk_widget_show (statusbar->priv->overwrite_mode_label);
gtk_box_pack_end (GTK_BOX (statusbar), gtk_box_pack_end (GTK_BOX (statusbar),
statusbar->priv->overwrite_mode_label, statusbar->priv->overwrite_mode_label,
FALSE, TRUE, 0); FALSE, TRUE, 0);
statusbar->priv->cursor_position_label = gtk_label_new (NULL); statusbar->priv->cursor_position_label = gtk_label_new (NULL);
gtk_label_set_width_chars (GTK_LABEL (statusbar->priv->cursor_position_label), gtk_label_set_width_chars (GTK_LABEL (statusbar->priv->cursor_position_label),
CURSOR_POSITION_LABEL_WIDTH_CHARS); CURSOR_POSITION_LABEL_WIDTH_CHARS);
gtk_widget_show (statusbar->priv->cursor_position_label); gtk_widget_show (statusbar->priv->cursor_position_label);
gtk_box_pack_end (GTK_BOX (statusbar), gtk_box_pack_end (GTK_BOX (statusbar),
statusbar->priv->cursor_position_label, statusbar->priv->cursor_position_label,
FALSE, TRUE, 0); FALSE, TRUE, 0);
statusbar->priv->state_frame = gtk_frame_new (NULL); statusbar->priv->state_frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (statusbar->priv->state_frame), gtk_frame_set_shadow_type (GTK_FRAME (statusbar->priv->state_frame),
GTK_SHADOW_IN); GTK_SHADOW_IN);
hbox = gtk_hbox_new (FALSE, 0); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add (GTK_CONTAINER (statusbar->priv->state_frame), hbox); gtk_container_add (GTK_CONTAINER (statusbar->priv->state_frame), hbox);
statusbar->priv->load_image = gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU); statusbar->priv->load_image = gtk_image_new_from_icon_name ("document-open-symbolic", GTK_ICON_SIZE_MENU);
statusbar->priv->save_image = gtk_image_new_from_stock (GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU); statusbar->priv->save_image = gtk_image_new_from_icon_name ("document-save-symbolic", GTK_ICON_SIZE_MENU);
statusbar->priv->print_image = gtk_image_new_from_stock (GTK_STOCK_PRINT, GTK_ICON_SIZE_MENU); statusbar->priv->print_image = gtk_image_new_from_icon_name ("printer-symbolic", GTK_ICON_SIZE_MENU);
gtk_widget_show (hbox); gtk_widget_show (hbox);
gtk_box_pack_start (GTK_BOX (hbox), gtk_box_pack_start (GTK_BOX (hbox),
statusbar->priv->load_image, statusbar->priv->load_image,
FALSE, TRUE, 4); FALSE, TRUE, 4);
gtk_box_pack_start (GTK_BOX (hbox), gtk_box_pack_start (GTK_BOX (hbox),
statusbar->priv->save_image, statusbar->priv->save_image,
FALSE, TRUE, 4); FALSE, TRUE, 4);
gtk_box_pack_start (GTK_BOX (hbox), gtk_box_pack_start (GTK_BOX (hbox),
statusbar->priv->print_image, statusbar->priv->print_image,
FALSE, TRUE, 4); FALSE, TRUE, 4);
gtk_box_pack_start (GTK_BOX (statusbar), gtk_box_pack_start (GTK_BOX (statusbar),
statusbar->priv->state_frame, statusbar->priv->state_frame,
FALSE, TRUE, 0); FALSE, TRUE, 0);
statusbar->priv->error_frame = gtk_frame_new (NULL); statusbar->priv->error_frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (statusbar->priv->error_frame), GTK_SHADOW_IN); gtk_frame_set_shadow_type (GTK_FRAME (statusbar->priv->error_frame), GTK_SHADOW_IN);
error_image = gtk_image_new_from_icon_name ("dialog-error", GTK_ICON_SIZE_MENU);
#if GTK_CHECK_VERSION (3, 10, 0)
error_image = gtk_image_new_from_icon_name ("dialog-error", GTK_ICON_SIZE_MENU);
#else
error_image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_MENU);
#endif
#if GTK_CHECK_VERSION (3, 14, 0) #if GTK_CHECK_VERSION (3, 14, 0)
gtk_widget_set_margin_start (error_image, 4); gtk_widget_set_margin_start (error_image, 4);
gtk_widget_set_margin_end (error_image, 4); gtk_widget_set_margin_end (error_image, 4);
gtk_widget_set_margin_top (error_image, 0); gtk_widget_set_margin_top (error_image, 0);
gtk_widget_set_margin_bottom (error_image, 0); gtk_widget_set_margin_bottom (error_image, 0);
#else #else
gtk_misc_set_padding (GTK_MISC (error_image), 4, 0); gtk_misc_set_padding (GTK_MISC (error_image), 4, 0);
gtk_widget_show (error_image); gtk_widget_show (error_image);
#endif #endif
statusbar->priv->error_event_box = gtk_event_box_new (); statusbar->priv->error_event_box = gtk_event_box_new ();
gtk_event_box_set_visible_window (GTK_EVENT_BOX (statusbar->priv->error_event_box), gtk_event_box_set_visible_window (GTK_EVENT_BOX (statusbar->priv->error_event_box),
FALSE); FALSE);
gtk_widget_show (statusbar->priv->error_event_box); gtk_widget_show (statusbar->priv->error_event_box);
gtk_container_add (GTK_CONTAINER (statusbar->priv->error_frame), gtk_container_add (GTK_CONTAINER (statusbar->priv->error_frame),
statusbar->priv->error_event_box); statusbar->priv->error_event_box);
gtk_container_add (GTK_CONTAINER (statusbar->priv->error_event_box), gtk_container_add (GTK_CONTAINER (statusbar->priv->error_event_box),
error_image); error_image);
gtk_box_pack_start (GTK_BOX (statusbar), gtk_box_pack_start (GTK_BOX (statusbar),
statusbar->priv->error_frame, statusbar->priv->error_frame,
FALSE, TRUE, 0); FALSE, TRUE, 0);
gtk_box_reorder_child (GTK_BOX (statusbar), gtk_box_reorder_child (GTK_BOX (statusbar),
statusbar->priv->error_frame, statusbar->priv->error_frame,
0); 0);
} }
/** /**
@ -209,7 +200,7 @@ xedit_statusbar_init (XeditStatusbar *statusbar)
GtkWidget * GtkWidget *
xedit_statusbar_new (void) xedit_statusbar_new (void)
{ {
return GTK_WIDGET (g_object_new (XEDIT_TYPE_STATUSBAR, NULL)); return GTK_WIDGET (g_object_new (XEDIT_TYPE_STATUSBAR, NULL));
} }
/** /**
@ -223,23 +214,23 @@ void
xedit_statusbar_set_overwrite (XeditStatusbar *statusbar, xedit_statusbar_set_overwrite (XeditStatusbar *statusbar,
gboolean overwrite) gboolean overwrite)
{ {
gchar *msg; gchar *msg;
g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar)); g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar));
msg = get_overwrite_mode_string (overwrite); msg = get_overwrite_mode_string (overwrite);
gtk_label_set_text (GTK_LABEL (statusbar->priv->overwrite_mode_label), msg); gtk_label_set_text (GTK_LABEL (statusbar->priv->overwrite_mode_label), msg);
g_free (msg); g_free (msg);
} }
void void
xedit_statusbar_clear_overwrite (XeditStatusbar *statusbar) xedit_statusbar_clear_overwrite (XeditStatusbar *statusbar)
{ {
g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar)); g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar));
gtk_label_set_text (GTK_LABEL (statusbar->priv->overwrite_mode_label), NULL); gtk_label_set_text (GTK_LABEL (statusbar->priv->overwrite_mode_label), NULL);
} }
/** /**
@ -252,35 +243,35 @@ xedit_statusbar_clear_overwrite (XeditStatusbar *statusbar)
**/ **/
void void
xedit_statusbar_set_cursor_position (XeditStatusbar *statusbar, xedit_statusbar_set_cursor_position (XeditStatusbar *statusbar,
gint line, gint line,
gint col) gint col)
{ {
gchar *msg = NULL; gchar *msg = NULL;
g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar)); g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar));
if ((line >= 0) || (col >= 0)) if ((line >= 0) || (col >= 0))
{ {
/* Translators: "Ln" is an abbreviation for "Line", Col is an abbreviation for "Column". Please, /* Translators: "Ln" is an abbreviation for "Line", Col is an abbreviation for "Column". Please,
use abbreviations if possible to avoid space problems. */ use abbreviations if possible to avoid space problems. */
msg = g_strdup_printf (_(" Ln %d, Col %d"), line, col); msg = g_strdup_printf (_(" Ln %d, Col %d"), line, col);
} }
gtk_label_set_text (GTK_LABEL (statusbar->priv->cursor_position_label), msg); gtk_label_set_text (GTK_LABEL (statusbar->priv->cursor_position_label), msg);
g_free (msg); g_free (msg);
} }
static gboolean static gboolean
remove_message_timeout (XeditStatusbar *statusbar) remove_message_timeout (XeditStatusbar *statusbar)
{ {
gtk_statusbar_remove (GTK_STATUSBAR (statusbar), gtk_statusbar_remove (GTK_STATUSBAR (statusbar),
statusbar->priv->flash_context_id, statusbar->priv->flash_context_id,
statusbar->priv->flash_message_id); statusbar->priv->flash_message_id);
/* remove the timeout */ /* remove the timeout */
statusbar->priv->flash_timeout = 0; statusbar->priv->flash_timeout = 0;
return FALSE; return FALSE;
} }
/* FIXME this is an issue for introspection */ /* FIXME this is an issue for introspection */
@ -294,91 +285,91 @@ remove_message_timeout (XeditStatusbar *statusbar)
*/ */
void void
xedit_statusbar_flash_message (XeditStatusbar *statusbar, xedit_statusbar_flash_message (XeditStatusbar *statusbar,
guint context_id, guint context_id,
const gchar *format, ...) const gchar *format, ...)
{ {
const guint32 flash_length = 3000; /* three seconds */ const guint32 flash_length = 3000; /* three seconds */
va_list args; va_list args;
gchar *msg; gchar *msg;
g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar)); g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar));
g_return_if_fail (format != NULL); g_return_if_fail (format != NULL);
va_start (args, format); va_start (args, format);
msg = g_strdup_vprintf (format, args); msg = g_strdup_vprintf (format, args);
va_end (args); va_end (args);
/* remove a currently ongoing flash message */ /* remove a currently ongoing flash message */
if (statusbar->priv->flash_timeout > 0) if (statusbar->priv->flash_timeout > 0)
{ {
g_source_remove (statusbar->priv->flash_timeout); g_source_remove (statusbar->priv->flash_timeout);
statusbar->priv->flash_timeout = 0; statusbar->priv->flash_timeout = 0;
gtk_statusbar_remove (GTK_STATUSBAR (statusbar), gtk_statusbar_remove (GTK_STATUSBAR (statusbar),
statusbar->priv->flash_context_id, statusbar->priv->flash_context_id,
statusbar->priv->flash_message_id); statusbar->priv->flash_message_id);
} }
statusbar->priv->flash_context_id = context_id; statusbar->priv->flash_context_id = context_id;
statusbar->priv->flash_message_id = gtk_statusbar_push (GTK_STATUSBAR (statusbar), statusbar->priv->flash_message_id = gtk_statusbar_push (GTK_STATUSBAR (statusbar),
context_id, context_id,
msg); msg);
statusbar->priv->flash_timeout = g_timeout_add (flash_length, statusbar->priv->flash_timeout = g_timeout_add (flash_length,
(GSourceFunc) remove_message_timeout, (GSourceFunc) remove_message_timeout,
statusbar); statusbar);
g_free (msg); g_free (msg);
} }
void void
xedit_statusbar_set_window_state (XeditStatusbar *statusbar, xedit_statusbar_set_window_state (XeditStatusbar *statusbar,
XeditWindowState state, XeditWindowState state,
gint num_of_errors) gint num_of_errors)
{ {
g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar)); g_return_if_fail (XEDIT_IS_STATUSBAR (statusbar));
gtk_widget_hide (statusbar->priv->state_frame); gtk_widget_hide (statusbar->priv->state_frame);
gtk_widget_hide (statusbar->priv->save_image); gtk_widget_hide (statusbar->priv->save_image);
gtk_widget_hide (statusbar->priv->load_image); gtk_widget_hide (statusbar->priv->load_image);
gtk_widget_hide (statusbar->priv->print_image); gtk_widget_hide (statusbar->priv->print_image);
if (state & XEDIT_WINDOW_STATE_SAVING) if (state & XEDIT_WINDOW_STATE_SAVING)
{ {
gtk_widget_show (statusbar->priv->state_frame); gtk_widget_show (statusbar->priv->state_frame);
gtk_widget_show (statusbar->priv->save_image); gtk_widget_show (statusbar->priv->save_image);
} }
if (state & XEDIT_WINDOW_STATE_LOADING) if (state & XEDIT_WINDOW_STATE_LOADING)
{ {
gtk_widget_show (statusbar->priv->state_frame); gtk_widget_show (statusbar->priv->state_frame);
gtk_widget_show (statusbar->priv->load_image); gtk_widget_show (statusbar->priv->load_image);
} }
if (state & XEDIT_WINDOW_STATE_PRINTING) if (state & XEDIT_WINDOW_STATE_PRINTING)
{ {
gtk_widget_show (statusbar->priv->state_frame); gtk_widget_show (statusbar->priv->state_frame);
gtk_widget_show (statusbar->priv->print_image); gtk_widget_show (statusbar->priv->print_image);
} }
if (state & XEDIT_WINDOW_STATE_ERROR) if (state & XEDIT_WINDOW_STATE_ERROR)
{ {
gchar *tip; gchar *tip;
tip = g_strdup_printf (ngettext("There is a tab with errors", tip = g_strdup_printf (ngettext("There is a tab with errors",
"There are %d tabs with errors", "There are %d tabs with errors",
num_of_errors), num_of_errors),
num_of_errors); num_of_errors);
gtk_widget_set_tooltip_text (statusbar->priv->error_event_box, gtk_widget_set_tooltip_text (statusbar->priv->error_event_box,
tip); tip);
g_free (tip); g_free (tip);
gtk_widget_show (statusbar->priv->error_frame); gtk_widget_show (statusbar->priv->error_frame);
} }
else else
{ {
gtk_widget_hide (statusbar->priv->error_frame); gtk_widget_hide (statusbar->priv->error_frame);
} }
} }