New API lxpanel_button_compose() for future usage by plugins.
authorAndriy Grytsenko <andrej@rep.kiev.ua>
Sat, 22 Nov 2014 02:13:44 +0000 (04:13 +0200)
committerAndriy Grytsenko <andrej@rep.kiev.ua>
Sat, 22 Nov 2014 02:13:44 +0000 (04:13 +0200)
ChangeLog
src/misc.c
src/misc.h

index bda37c4..842f3af 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -66,6 +66,7 @@
 * Allowed default alarmCommand on 'batt' plugin be translated.
 * Implemented sorting plugins in Add plugin window in alphabetic order.
 * Fixed font in the weather plugin to use panel settings.
+* Added new API lxpanel_button_compose() for future usage by plugins.
 
 0.7.2
 -------------------------------------------------------------------------
index cd4b33b..74cf3f4 100644 (file)
@@ -1221,24 +1221,16 @@ static gboolean fb_button_leave(GtkImage * widget, GdkEventCrossing * event, gpo
     return TRUE;
 }
 
-
-/* consumes reference on icon */
-static GtkWidget *_lxpanel_button_new_for_icon(LXPanel *panel, FmIcon *icon,
-                                               gint size, gulong highlight_color,
-                                               const gchar *label)
+static GtkWidget *_lxpanel_button_compose(GtkWidget *event_box, GtkWidget *image,
+                                          gulong highlight_color, const gchar *label)
 {
-    GtkWidget * event_box = gtk_event_box_new();
-    gtk_container_set_border_width(GTK_CONTAINER(event_box), 0);
-    gtk_widget_set_can_focus(event_box, FALSE);
+    ImgData * data = (ImgData *) g_object_get_qdata(G_OBJECT(image), img_data_id);
 
-    GtkWidget * image = _gtk_image_new_for_icon(panel, icon, size, NULL);
     gtk_misc_set_padding(GTK_MISC(image), 0, 0);
     gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.5);
-    if (highlight_color != 0)
+    if (highlight_color != 0 && data != NULL)
     {
-        ImgData * data = (ImgData *) g_object_get_qdata(G_OBJECT(image), img_data_id);
         data->hicolor = highlight_color;
-
         gtk_widget_add_events(event_box, GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
         g_signal_connect_swapped(G_OBJECT(event_box), "enter-notify-event", G_CALLBACK(fb_button_enter), image);
         g_signal_connect_swapped(G_OBJECT(event_box), "leave-notify-event", G_CALLBACK(fb_button_leave), image);
@@ -1248,15 +1240,20 @@ static GtkWidget *_lxpanel_button_new_for_icon(LXPanel *panel, FmIcon *icon,
         gtk_container_add(GTK_CONTAINER(event_box), image);
     else
     {
-        GtkWidget * inner = gtk_hbox_new(FALSE, 0);
+        GtkWidget *inner, *lbl;
+
+        inner = gtk_hbox_new(FALSE, 0);
         gtk_container_set_border_width(GTK_CONTAINER(inner), 0);
         gtk_widget_set_can_focus(inner, FALSE);
         gtk_container_add(GTK_CONTAINER(event_box), inner);
 
         gtk_box_pack_start(GTK_BOX(inner), image, FALSE, FALSE, 0);
 
-        GtkWidget * lbl = gtk_label_new("");
-        lxpanel_draw_label_text(panel, lbl, label, FALSE, 1, TRUE);
+        lbl = gtk_label_new("");
+        if (G_LIKELY(data != NULL && data->panel != NULL))
+            lxpanel_draw_label_text(data->panel, lbl, label, FALSE, 1, TRUE);
+        else
+            gtk_label_set_text(GTK_LABEL(lbl), label);
         gtk_misc_set_padding(GTK_MISC(lbl), 2, 0);
         gtk_box_pack_end(GTK_BOX(inner), lbl, FALSE, FALSE, 0);
     }
@@ -1265,6 +1262,26 @@ static GtkWidget *_lxpanel_button_new_for_icon(LXPanel *panel, FmIcon *icon,
     return event_box;
 }
 
+GtkWidget *lxpanel_button_compose(GtkWidget *event_box, GtkWidget *image,
+                                  GdkColor *color, const gchar *label)
+{
+    gulong highlight_color = color ? gcolor2rgb24(color) : PANEL_ICON_HIGHLIGHT;
+    return _lxpanel_button_compose(event_box, image, highlight_color, label);
+}
+
+/* consumes reference on icon */
+static GtkWidget *_lxpanel_button_new_for_icon(LXPanel *panel, FmIcon *icon,
+                                               gint size, gulong highlight_color,
+                                               const gchar *label)
+{
+    GtkWidget * event_box = gtk_event_box_new();
+    gtk_container_set_border_width(GTK_CONTAINER(event_box), 0);
+    gtk_widget_set_can_focus(event_box, FALSE);
+
+    GtkWidget * image = _gtk_image_new_for_icon(panel, icon, size, NULL);
+    return _lxpanel_button_compose(event_box, image, highlight_color, label);
+}
+
 GtkWidget *lxpanel_button_new_for_icon(LXPanel *panel, const gchar *name, GdkColor *color, const gchar *label)
 {
     gulong highlight_color = color ? gcolor2rgb24(color) : PANEL_ICON_HIGHLIGHT;
index 0339367..e135d86 100644 (file)
@@ -156,8 +156,8 @@ guint32 gcolor2rgb24(GdkColor *color);
  *
  * Returns: (transfer full): a new #GtkEventBox widget.
  */
-GtkWidget *lxpanel_button_new_for_icon(LXPanel *panel, const gchar *name, GdkColor *color, const gchar *label);
-GtkWidget *lxpanel_button_new_for_fm_icon(LXPanel *panel, FmIcon *icon, GdkColor *color, const gchar *label);
+extern GtkWidget *lxpanel_button_new_for_icon(LXPanel *panel, const gchar *name, GdkColor *color, const gchar *label);
+extern GtkWidget *lxpanel_button_new_for_fm_icon(LXPanel *panel, FmIcon *icon, GdkColor *color, const gchar *label);
 
 /**
  * lxpanel_button_set_icon
@@ -170,8 +170,27 @@ GtkWidget *lxpanel_button_new_for_fm_icon(LXPanel *panel, FmIcon *icon, GdkColor
  * following panel icon size and use this fixed size, if @size is 0 then
  * do no changes on icons size.
  */
-void lxpanel_button_set_icon(GtkWidget* btn, const gchar *name, gint size);
-void lxpanel_button_update_icon(GtkWidget* btn, FmIcon *icon, gint size);
+extern void lxpanel_button_set_icon(GtkWidget* btn, const gchar *name, gint size);
+extern void lxpanel_button_update_icon(GtkWidget* btn, FmIcon *icon, gint size);
+
+/**
+ * lxpanel_button_compose
+ * @event_box: a widget to add image and label
+ * @image: an image widget
+ * @color: (allow-none): hilight color for icon
+ * @label: (allow-none): optional label for button
+ *
+ * Composes button similarly to lxpanel_button_new_for_icon() but using
+ * existing container @event_box and @image. The @image should be created
+ * using lxpanel_image_new_for_icon() or lxpanel_image_new_for_fm_icon(),
+ * and it can be updated later using lxpanel_button_set_icon() API.
+ *
+ * Returns: (transfer none): @event_box.
+ *
+ * Since: 0.8.0
+ */
+extern GtkWidget *lxpanel_button_compose(GtkWidget *event_box, GtkWidget *image,
+                                         GdkColor *color, const gchar *label);
 
 /**
  * lxpanel_image_new_for_icon
@@ -190,10 +209,10 @@ void lxpanel_button_update_icon(GtkWidget* btn, FmIcon *icon, gint size);
  *
  * Since: 0.8.0
  */
-GtkWidget *lxpanel_image_new_for_icon(LXPanel *panel, const gchar *name,
-                                      gint height, const gchar *fallback);
-GtkWidget *lxpanel_image_new_for_fm_icon(LXPanel *panel, FmIcon *icon,
-                                         gint height, const gchar *fallback);
+extern GtkWidget *lxpanel_image_new_for_icon(LXPanel *panel, const gchar *name,
+                                             gint height, const gchar *fallback);
+extern GtkWidget *lxpanel_image_new_for_fm_icon(LXPanel *panel, FmIcon *icon,
+                                                gint height, const gchar *fallback);
 
 /**
  * lxpanel_image_change_icon
@@ -208,8 +227,8 @@ GtkWidget *lxpanel_image_new_for_fm_icon(LXPanel *panel, FmIcon *icon,
  *
  * Since: 0.8.0
  */
-gboolean lxpanel_image_change_icon(GtkWidget *img, const gchar *name,
-                                   const char *fallback);
+extern gboolean lxpanel_image_change_icon(GtkWidget *img, const gchar *name,
+                                          const char *fallback);
 
 G_END_DECLS