[Xfce4-commits] <xfce4-panel:devel> Add a new (private) widget used for blinking buttons.
Nick Schermer
nick at xfce.org
Tue Aug 11 20:28:21 CEST 2009
Updating branch refs/heads/devel
to bcb929b8c30fe652a52cb70d10cebdf1495f5452 (commit)
from 59f23f8667ff0943bc48a88986cd3a808325173b (commit)
commit bcb929b8c30fe652a52cb70d10cebdf1495f5452
Author: Nick Schermer <nick at xfce.org>
Date: Wed Feb 25 19:17:05 2009 +0100
Add a new (private) widget used for blinking buttons.
This widget implements blinking buttons (for now only the
old blinking style like in netk, glowing will come later).
This widget is used in both the task list and the window
list plugin.
The API is not public available, since I'm not sure the
naming is good and if it's useful for other plugins. So for
now it will be only used internally to reduce code
dupplication.
libxfce4panel/Makefile.am | 2 +
libxfce4panel/xfce-panel-button.c | 188 +++++++++++++++++++++++++++++++++++++
libxfce4panel/xfce-panel-button.h | 66 +++++++++++++
3 files changed, 256 insertions(+), 0 deletions(-)
diff --git a/libxfce4panel/Makefile.am b/libxfce4panel/Makefile.am
index 04c3442..1e011f2 100644
--- a/libxfce4panel/Makefile.am
+++ b/libxfce4panel/Makefile.am
@@ -35,6 +35,8 @@ libxfce4panel_la_SOURCES = \
$(libxfce4panel_headers) \
xfce-arrow-button.c \
xfce-hvbox.c \
+ xfce-panel-button.c \
+ xfce-panel-button.h \
xfce-panel-convenience.c \
xfce-panel-plugin.c \
xfce-panel-plugin-provider.c \
diff --git a/libxfce4panel/xfce-panel-button.c b/libxfce4panel/xfce-panel-button.c
new file mode 100644
index 0000000..f5b6fb3
--- /dev/null
+++ b/libxfce4panel/xfce-panel-button.c
@@ -0,0 +1,188 @@
+/* $Id$ */
+/*
+ * Copyright (c) 2009 Nick Schermer <nick at xfce.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <common/panel-private.h>
+#include <libxfce4panel/xfce-panel-button.h>
+
+#define XFCE_PANEL_BUTTON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
+ XFCE_TYPE_PANEL_BUTTON, \
+ XfcePanelButtonPrivate))
+
+/* blink count, number should be even */
+#define MAX_BLINKING_COUNT 16
+
+
+
+static void xfce_panel_button_finalize (GObject *object);
+
+
+
+struct _XfcePanelButtonPrivate
+{
+ /* blinking timeout id */
+ guint blinking_timeout_id;
+
+ /* counter to make the blinking stop when
+ * MAX_BLINKING_COUNT is reached */
+ guint blinking_counter;
+
+ /* button relief when the blinking starts */
+ GtkReliefStyle relief;
+};
+
+
+
+G_DEFINE_TYPE (XfcePanelButton, xfce_panel_button, GTK_TYPE_TOGGLE_BUTTON)
+
+
+
+static void
+xfce_panel_button_class_init (XfcePanelButtonClass *klass)
+{
+ GObjectClass *gobject_class;
+
+ g_type_class_add_private (klass, sizeof (XfcePanelButtonPrivate));
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->finalize = xfce_panel_button_finalize;
+}
+
+
+
+static void
+xfce_panel_button_init (XfcePanelButton *button)
+{
+ /* set private pointer */
+ button->priv = XFCE_PANEL_BUTTON_GET_PRIVATE (button);
+
+ /* initialize button values */
+ button->priv->blinking_timeout_id = 0;
+ button->priv->blinking_counter = 0;
+ button->priv->relief = GTK_RELIEF_NORMAL;
+
+ /* set some widget properties */
+ GTK_WIDGET_UNSET_FLAGS (button, GTK_CAN_DEFAULT | GTK_CAN_FOCUS);
+ gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
+}
+
+
+
+static void
+xfce_panel_button_finalize (GObject *object)
+{
+ XfcePanelButton *button = XFCE_PANEL_BUTTON (object);
+
+ if (button->priv->blinking_timeout_id != 0)
+ g_source_remove (button->priv->blinking_timeout_id);
+
+ (*G_OBJECT_CLASS (xfce_panel_button_parent_class)->finalize) (object);
+}
+
+
+
+static gboolean
+xfce_panel_button_blinking_timeout (gpointer user_data)
+{
+ XfcePanelButton *button = XFCE_PANEL_BUTTON (user_data);
+ GtkStyle *style;
+ GtkRcStyle *rc;
+
+ rc = gtk_widget_get_modifier_style (GTK_WIDGET (button));
+ if(PANEL_HAS_FLAG (rc->color_flags[GTK_STATE_NORMAL], GTK_RC_BG)
+ || button->priv->blinking_timeout_id == 0)
+ {
+ gtk_button_set_relief (GTK_BUTTON (button), button->priv->relief);
+ PANEL_UNSET_FLAG (rc->color_flags[GTK_STATE_NORMAL], GTK_RC_BG);
+ gtk_widget_modify_style (GTK_WIDGET (button), rc);
+ }
+ else
+ {
+ gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NORMAL);
+ PANEL_SET_FLAG (rc->color_flags[GTK_STATE_NORMAL], GTK_RC_BG);
+ style = gtk_widget_get_style (GTK_WIDGET (button));
+ rc->bg[GTK_STATE_NORMAL] = style->bg[GTK_STATE_SELECTED];
+ gtk_widget_modify_style(GTK_WIDGET (button), rc);
+ }
+
+ return (button->priv->blinking_counter++ < MAX_BLINKING_COUNT);
+}
+
+
+
+static void
+xfce_panel_button_blinking_timeout_destroyed (gpointer user_data)
+{
+ XfcePanelButton *button = XFCE_PANEL_BUTTON (user_data);
+
+ button->priv->blinking_timeout_id = 0;
+ button->priv->blinking_counter = 0;
+}
+
+
+
+PANEL_SYMBOL_EXPORT GtkWidget *
+xfce_panel_button_new (void)
+{
+ return g_object_new (XFCE_TYPE_PANEL_BUTTON, NULL);
+}
+
+
+
+PANEL_SYMBOL_EXPORT gboolean
+xfce_panel_button_get_blinking (XfcePanelButton *button)
+{
+ g_return_val_if_fail (XFCE_IS_PANEL_BUTTON (button), FALSE);
+ return !!(button->priv->blinking_timeout_id != 0);
+}
+
+
+
+PANEL_SYMBOL_EXPORT void
+xfce_panel_button_set_blinking (XfcePanelButton *button,
+ gboolean blinking)
+{
+ g_return_if_fail (XFCE_IS_PANEL_BUTTON (button));
+
+ if (blinking)
+ {
+ /* store the relief of the button */
+ button->priv->relief = gtk_button_get_relief (GTK_BUTTON (button));
+
+ if (button->priv->blinking_timeout_id == 0)
+ {
+ /* start blinking timeout */
+ button->priv->blinking_timeout_id =
+ g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE, 500,
+ xfce_panel_button_blinking_timeout, button,
+ xfce_panel_button_blinking_timeout_destroyed);
+ }
+ }
+ else if (button->priv->blinking_timeout_id != 0)
+ {
+ /* stop the blinking timeout */
+ g_source_remove (button->priv->blinking_timeout_id);
+ }
+
+ /* start with a blinking or make sure the button is normal */
+ xfce_panel_button_blinking_timeout (button);
+}
diff --git a/libxfce4panel/xfce-panel-button.h b/libxfce4panel/xfce-panel-button.h
new file mode 100644
index 0000000..7970466
--- /dev/null
+++ b/libxfce4panel/xfce-panel-button.h
@@ -0,0 +1,66 @@
+/* $Id$ */
+/*
+ * Copyright (c) 2009 Nick Schermer <nick at xfce.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __XFCE_PANEL_BUTTON_H__
+#define __XFCE_PANEL_BUTTON_H__
+
+#include <gtk/gtk.h>
+#include <libxfce4panel/libxfce4panel.h>
+
+G_BEGIN_DECLS
+
+typedef struct _XfcePanelButtonPrivate XfcePanelButtonPrivate;
+typedef struct _XfcePanelButtonClass XfcePanelButtonClass;
+typedef struct _XfcePanelButton XfcePanelButton;
+
+#define XFCE_TYPE_PANEL_BUTTON (xfce_panel_button_get_type ())
+#define XFCE_PANEL_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_PANEL_BUTTON, XfcePanelButton))
+#define XFCE_PANEL_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_TYPE_PANEL_BUTTON, XfcePanelButtonClass))
+#define XFCE_IS_PANEL_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_TYPE_PANEL_BUTTON))
+#define XFCE_IS_PANEL_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_TYPE_PANEL_BUTTON))
+#define XFCE_PANEL_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_PANEL_BUTTON, XfcePanelButtonClass))
+
+struct _XfcePanelButtonClass
+{
+ /*< private >*/
+ GtkToggleButtonClass __parent__;
+};
+
+struct _XfcePanelButton
+{
+ /*< private >*/
+ GtkToggleButton __parent__;
+
+ /*< private >*/
+ XfcePanelButtonPrivate *priv;
+};
+
+PANEL_SYMBOL_EXPORT
+GType xfce_panel_button_get_type (void) G_GNUC_CONST;
+
+GtkWidget *xfce_panel_button_new (void) G_GNUC_MALLOC;
+
+gboolean xfce_panel_button_get_blinking (XfcePanelButton *button);
+void xfce_panel_button_set_blinking (XfcePanelButton *button,
+ gboolean blinking);
+
+G_END_DECLS
+
+#endif /* !__XFCE_PANEL_BUTTON_H__ */
+
More information about the Xfce4-commits
mailing list