Re: Statusbar font color



On Wed, Jun 02, 2004 at 10:03:13PM +0200, christophe wrote:
Does anyone know how i can change the font color in a statusbar ?
thanks for help,

The best solution is IMHO to subclass GtkStatusbar and make
the new widget accept any Pango markup.  Then you can have
bold, italics, indices, or colors there.  E.g.:

  my_statusbar_push(statusbar, context_id,
                    "<span foreground=\"red\">This is red</span>");

will show red `This is red'.

I'm attaching an implementation (please replace My, my_,
and MY_ with something appropriate for your project).

Yeti


========= mystatusbar.c =====================================================
#include "mystatusbar.h"

#define MY_STATUSBAR_TYPE_NAME "MyStatusbar"

static void     my_statusbar_class_init     (MyStatusbarClass *klass);
static void     my_statusbar_update_markup  (GtkStatusbar *statusbar,
                                             guint context_id,
                                             const gchar *text);

static GtkStatusbarClass *parent_class;

GType
my_statusbar_get_type(void)
{
    static GType my_statusbar_type = 0;

    if (!my_statusbar_type) {
        static const GTypeInfo my_statusbar_info = {
            sizeof(MyStatusbarClass),
            NULL,           /* base_init */
            NULL,           /* base_finalize */
            (GClassInitFunc)my_statusbar_class_init,
            NULL,           /* class_finalize */
            NULL,           /* class_data */
            sizeof(MyStatusbar),
            0,              /* n_preallocs */
            NULL,
            NULL,
        };
        my_debug("");
        my_statusbar_type = g_type_register_static(GTK_TYPE_STATUSBAR,
                                                   MY_STATUSBAR_TYPE_NAME,
                                                   &my_statusbar_info, 0);
    }

    return my_statusbar_type;
}

static void
my_statusbar_class_init(MyStatusbarClass *klass)
{
    GtkStatusbarClass *statusbar_class;

    statusbar_class = GTK_STATUSBAR_CLASS(klass);
    parent_class = g_type_class_peek_parent(klass);

    statusbar_class->text_pushed = my_statusbar_update_markup;
    statusbar_class->text_popped = my_statusbar_update_markup;
}

GtkWidget*
my_statusbar_new(void)
{
    return g_object_new(MY_TYPE_STATUSBAR, NULL);
}

static void
my_statusbar_update_markup(GtkStatusbar *statusbar,
                            G_GNUC_UNUSED guint context_id,
                            const gchar *text)
{
    g_return_if_fail(GTK_IS_STATUSBAR(statusbar));

    if (!text)
        text = "";

    gtk_label_set_markup(GTK_LABEL(statusbar->label), text);
}
========= end of mystatusbar.c ==============================================

========= mystatusbar.h =====================================================
#ifndef __MY_STATUSBAR_H__
#define __MY_STATUSBAR_H__

#include <gtk/gtkwidget.h>

G_BEGIN_DECLS

#define MY_TYPE_STATUSBAR            (my_statusbar_get_type())
#define MY_STATUSBAR(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), MY_TYPE_STATUSBAR, MyStatusbar))
#define MY_STATUSBAR_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), MY_TYPE_STATUSBAR, MyStatusbarClass))
#define MY_IS_STATUSBAR(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), MY_TYPE_STATUSBAR))
#define MY_IS_STATUSBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), MY_TYPE_STATUSBAR))
#define MY_STATUSBAR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), MY_TYPE_STATUSBAR, MyStatusbarClass))

typedef struct _MyStatusbar      MyStatusbar;
typedef struct _MyStatusbarClass MyStatusbarClass;

struct _MyStatusbar {
    GtkStatusbar parent_instance;
};

struct _MyStatusbarClass {
    GtkStatusbarClass parent_class;
};

GtkWidget*       my_statusbar_new              (void);
GType            my_statusbar_get_type         (void) G_GNUC_CONST;

G_END_DECLS

#endif /* __MY_STATUSBAR_H__ */
========= end of mystatusbar.h ==============================================




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]