[Xfce4-commits] <xfce4-indicator-plugin:master> Added "align-left" property
Andrzej
noreply at xfce.org
Thu Apr 4 17:44:10 CEST 2013
Updating branch refs/heads/master
to fb8b0c8d6ca2337d7e4187685ee98dbe5e8420a0 (commit)
from 57b1394a49142a979d77f089819f9c45f49320ab (commit)
commit fb8b0c8d6ca2337d7e4187685ee98dbe5e8420a0
Author: Andrzej <ndrwrdck at gmail.com>
Date: Fri Apr 27 20:41:59 2012 +0900
Added "align-left" property
It also improves handling of button alignment
(uses GtkAlignment instead of GtkArray).
panel-plugin/indicator-box.c | 31 +++++++++++++++-
panel-plugin/indicator-box.h | 1 +
panel-plugin/indicator-button.c | 68 +++++++++++++++++++++-------------
panel-plugin/indicator-button.h | 5 +++
panel-plugin/indicator-dialog.c | 6 +++
panel-plugin/indicator-dialog.glade | 15 ++++++++
panel-plugin/indicator.c | 3 ++
7 files changed, 101 insertions(+), 28 deletions(-)
diff --git a/panel-plugin/indicator-box.c b/panel-plugin/indicator-box.c
index 0643a3f..ffaf455 100644
--- a/panel-plugin/indicator-box.c
+++ b/panel-plugin/indicator-box.c
@@ -61,7 +61,8 @@ static gint xfce_indicator_box_get_row_size (XfceIndicatorBox
enum
{
PROP_0,
- PROP_ICON_SIZE_MAX
+ PROP_ICON_SIZE_MAX,
+ PROP_ALIGN_LEFT
};
G_DEFINE_TYPE (XfceIndicatorBox, xfce_indicator_box, GTK_TYPE_CONTAINER)
@@ -96,6 +97,13 @@ xfce_indicator_box_class_init (XfceIndicatorBoxClass *klass)
128,
24,
EXO_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class,
+ PROP_ALIGN_LEFT,
+ g_param_spec_boolean ("align-left", NULL, NULL,
+ FALSE,
+ EXO_PARAM_READWRITE));
+
+
}
@@ -112,6 +120,7 @@ xfce_indicator_box_init (XfceIndicatorBox *box)
box->nrows = 1;
box->icon_size_max = 24;
+ box->align_left = FALSE;
box->panel_size = 16;
box->panel_orientation = GTK_ORIENTATION_HORIZONTAL;
box->orientation = GTK_ORIENTATION_HORIZONTAL;
@@ -150,6 +159,10 @@ xfce_indicator_box_get_property (GObject *object,
g_value_set_uint (value, box->icon_size_max);
break;
+ case PROP_ALIGN_LEFT:
+ g_value_set_boolean (value, box->align_left);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -184,7 +197,20 @@ xfce_indicator_box_set_property (GObject *object,
g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (child));
xfce_indicator_button_set_size (child, box->panel_size, size);
}
- gtk_widget_queue_resize (GTK_WIDGET (box));
+ }
+ break;
+
+ case PROP_ALIGN_LEFT:
+ val = g_value_get_boolean (value);
+ if (box->align_left != val)
+ {
+ box->align_left = val;
+ for (li = box->children; li != NULL; li = li->next)
+ {
+ child = XFCE_INDICATOR_BUTTON (li->data);
+ g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (child));
+ xfce_indicator_button_set_align_left (child, box->align_left);
+ }
}
break;
@@ -299,6 +325,7 @@ xfce_indicator_box_add (GtkContainer *container,
xfce_indicator_button_set_orientation (button, box->panel_orientation, box->orientation);
size = xfce_indicator_box_get_row_size (box);
xfce_indicator_button_set_size (button, box->panel_size, size);
+ xfce_indicator_button_set_align_left (button, box->align_left);
gtk_widget_queue_resize (GTK_WIDGET (container));
}
diff --git a/panel-plugin/indicator-box.h b/panel-plugin/indicator-box.h
index e302279..79b212d 100644
--- a/panel-plugin/indicator-box.h
+++ b/panel-plugin/indicator-box.h
@@ -46,6 +46,7 @@ struct _XfceIndicatorBox
gint panel_size;
gint nrows;
gint icon_size_max;
+ gboolean align_left;
GtkOrientation panel_orientation;
GtkOrientation orientation;
diff --git a/panel-plugin/indicator-button.c b/panel-plugin/indicator-button.c
index 58810ad..51f82cc 100644
--- a/panel-plugin/indicator-button.c
+++ b/panel-plugin/indicator-button.c
@@ -51,15 +51,13 @@ xfce_indicator_button_class_init (XfceIndicatorButtonClass *klass)
static void
xfce_indicator_button_init (XfceIndicatorButton *button)
{
- GtkWidget *outer_container;
-
GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (button), GTK_CAN_DEFAULT | GTK_CAN_FOCUS);
gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
gtk_button_set_use_underline (GTK_BUTTON (button),TRUE);
gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
gtk_widget_set_name (GTK_WIDGET (button), "indicator-button");
- button->io = NULL;
+ button->group = NULL;
button->entry = NULL;
button->menu = NULL;
@@ -71,17 +69,16 @@ xfce_indicator_button_init (XfceIndicatorButton *button)
button->size = 0;
button->panel_size = 0;
button->icon_size = 24;
+ button->align_left = FALSE;
button->panel_orientation = GTK_ORIENTATION_HORIZONTAL;
button->orientation = GTK_ORIENTATION_HORIZONTAL;
- outer_container = gtk_table_new (1, 1, FALSE);
- gtk_container_add (GTK_CONTAINER (button), outer_container);
- gtk_widget_show (outer_container);
+ button->alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
+ gtk_container_add (GTK_CONTAINER (button), button->alignment);
+ gtk_widget_show (button->alignment);
button->box = xfce_hvbox_new (button->orientation, FALSE, 1);
- gtk_table_attach (GTK_TABLE (outer_container), button->box,
- 0, 1, 0, 1,
- GTK_EXPAND | GTK_SHRINK, GTK_EXPAND | GTK_SHRINK, 0, 0);
+ gtk_container_add (GTK_CONTAINER (button->alignment), button->box);
gtk_widget_show (button->box);
}
@@ -118,25 +115,28 @@ xfce_indicator_button_update_layout (XfceIndicatorButton *button)
g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
- if (button->icon != NULL && button->size != 0)
+ if (button->label != NULL &&
+ button->panel_orientation == GTK_ORIENTATION_VERTICAL &&
+ button->orientation == GTK_ORIENTATION_HORIZONTAL)
{
- if (button->label != NULL &&
- button->panel_orientation == GTK_ORIENTATION_VERTICAL &&
- button->orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- gtk_widget_size_request (button->label, &label_size);
-
- /* put icon above the label if number of rows > 1 (they look better)
- or if they don't fit when arranged horizontally */
- if (button->panel_size != button->size ||
- label_size.width > button->panel_size - button->size)
- gtk_orientable_set_orientation (GTK_ORIENTABLE (button->box), GTK_ORIENTATION_VERTICAL);
- else
- gtk_orientable_set_orientation (GTK_ORIENTABLE (button->box), GTK_ORIENTATION_HORIZONTAL);
- }
-
- xfce_panel_image_set_size (XFCE_PANEL_IMAGE (button->icon), button->icon_size);
+ gtk_alignment_set (GTK_ALIGNMENT (button->alignment), button->align_left ? 0.0 : 0.5, 0.5, 0.0, 0.0);
+ gtk_widget_size_request (button->label, &label_size);
+
+ /* put icon above the label if number of rows > 1 (they look better)
+ or if they don't fit when arranged horizontally */
+ if ((!button->align_left && button->panel_size != button->size) ||
+ label_size.width > button->panel_size - button->size)
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (button->box), GTK_ORIENTATION_VERTICAL);
+ else
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (button->box), GTK_ORIENTATION_HORIZONTAL);
}
+ else
+ {
+ gtk_alignment_set (GTK_ALIGNMENT (button->alignment), 0.5, 0.5, 0.0, 0.0);
+ }
+
+ if (button->icon != NULL)
+ xfce_panel_image_set_size (XFCE_PANEL_IMAGE (button->icon), button->icon_size);
}
@@ -418,6 +418,22 @@ xfce_indicator_button_set_size (XfceIndicatorButton *button,
+void
+xfce_indicator_button_set_align_left (XfceIndicatorButton *button,
+ gboolean align_left)
+{
+ g_return_if_fail (XFCE_IS_INDICATOR_BUTTON (button));
+
+ if (button->align_left != align_left)
+ {
+ button->align_left = align_left;
+ xfce_indicator_button_update_layout (button);
+ }
+}
+
+
+
+
GtkWidget *
xfce_indicator_button_new (IndicatorObject *io,
IndicatorObjectEntry *entry)
diff --git a/panel-plugin/indicator-button.h b/panel-plugin/indicator-button.h
index 129aa22..4436c98 100644
--- a/panel-plugin/indicator-button.h
+++ b/panel-plugin/indicator-button.h
@@ -44,6 +44,7 @@ struct _XfceIndicatorButton
IndicatorObjectEntry *entry;
GtkMenu *menu;
+ GtkWidget *alignment;
GtkWidget *box;
GtkWidget *label;
GtkWidget *icon;
@@ -53,6 +54,7 @@ struct _XfceIndicatorButton
gint panel_size;
gint size;
gint icon_size;
+ gboolean align_left;
GtkOrientation panel_orientation;
GtkOrientation orientation;
@@ -87,6 +89,9 @@ void xfce_indicator_button_set_size (XfceIndicatorButton *button,
gint panel_size,
gint size);
+void xfce_indicator_button_set_align_left (XfceIndicatorButton *button,
+ gboolean align_left);
+
GtkWidget *xfce_indicator_button_new (IndicatorObject *io, IndicatorObjectEntry *entry);
G_END_DECLS
diff --git a/panel-plugin/indicator-dialog.c b/panel-plugin/indicator-dialog.c
index a2241c5..a2afba7 100644
--- a/panel-plugin/indicator-dialog.c
+++ b/panel-plugin/indicator-dialog.c
@@ -122,6 +122,12 @@ indicator_dialog_build (IndicatorDialog *dialog,
g_return_if_fail (GTK_IS_WIDGET (object));
exo_mutual_binding_new (G_OBJECT (indicator_get_buttonbox (plugin)), "icon-size-max",
G_OBJECT (object), "value");
+
+ object = gtk_builder_get_object (GTK_BUILDER (dialog), "checkbutton-align-left");
+ g_return_if_fail (GTK_IS_WIDGET (object));
+ exo_mutual_binding_new (G_OBJECT (indicator_get_buttonbox (plugin)), "align-left",
+ G_OBJECT (object), "active");
+
}
else
{
diff --git a/panel-plugin/indicator-dialog.glade b/panel-plugin/indicator-dialog.glade
index 5194a0d..fbb7808 100644
--- a/panel-plugin/indicator-dialog.glade
+++ b/panel-plugin/indicator-dialog.glade
@@ -171,6 +171,21 @@
<property name="position">2</property>
</packing>
</child>
+ <child>
+ <object class="GtkCheckButton" id="checkbutton-align-left">
+ <property name="label" translatable="yes">Align left in the deskbar mode</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
</object>
</child>
</object>
diff --git a/panel-plugin/indicator.c b/panel-plugin/indicator.c
index aa986dc..3332087 100644
--- a/panel-plugin/indicator.c
+++ b/panel-plugin/indicator.c
@@ -140,6 +140,9 @@ indicator_read (IndicatorPlugin *indicator)
property = g_strconcat (xfce_panel_plugin_get_property_base(plugin),"/icon-size-max",NULL);
xfconf_g_property_bind (channel, property, G_TYPE_INT, indicator->buttonbox, "icon-size-max");
g_free (property);
+ property = g_strconcat (xfce_panel_plugin_get_property_base(plugin),"/align-left",NULL);
+ xfconf_g_property_bind (channel, property, G_TYPE_BOOLEAN, indicator->buttonbox, "align-left");
+ g_free (property);
/* something went wrong, apply default values */
/*
DBG ("Applying default settings");
More information about the Xfce4-commits
mailing list