[monkey-bubble: 112/753] Excorcise imlib reference from a label :)
- From: Sven Herzberg <herzi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [monkey-bubble: 112/753] Excorcise imlib reference from a label :)
- Date: Wed, 14 Jul 2010 22:05:05 +0000 (UTC)
commit 8203cb3a978ae8085c4184497fd0d024bbca0a2e
Author: George Lebl <jirka 5z com>
Date: Tue Jul 4 08:49:41 2000 +0000
Excorcise imlib reference from a label :)
Tue Jul 04 01:44:21 2000 George Lebl <jirka 5z com>
* gnome-color-picker.c: Excorcise imlib reference from a label :)
* gnome-scores.[ch]: Add and use a private pointer. Allow setting
logo multiple times. Add a _construct method. Add a
_display_with_pixmap function to use a pixmap logo rather then just
a title.
libgnomeui/gnome-scores.c | 352 +++++++++++++++++++++++++++++++--------------
libgnomeui/gnome-scores.h | 27 +++--
2 files changed, 263 insertions(+), 116 deletions(-)
---
diff --git a/libgnomeui/gnome-scores.c b/libgnomeui/gnome-scores.c
index bed2926..2be66cd 100644
--- a/libgnomeui/gnome-scores.c
+++ b/libgnomeui/gnome-scores.c
@@ -41,8 +41,25 @@
#include "time.h"
+struct _GnomeScoresPrivate
+{
+ GtkWidget *but_clear;
+ GtkTable *table;
+
+ GtkWidget *logo_container;
+ GtkWidget *logo;
+ GtkWidget **label_names;
+ GtkWidget **label_scores;
+ GtkWidget **label_times;
+
+ guint n_scores;
+};
+
static void gnome_scores_class_init (GnomeScoresClass *klass);
static void gnome_scores_init (GnomeScores *scores);
+static void gnome_scores_destroy (GtkObject *object);
+
+static GnomeDialogClass *parent_class = NULL;
/**
* gnome_scores_get_type:
@@ -50,7 +67,7 @@ static void gnome_scores_init (GnomeScores *scores);
* Returns the GtkType for the GnomeScores widget
*/
guint
-gnome_scores_get_type ()
+gnome_scores_get_type (void)
{
static guint scores_type = 0;
@@ -75,74 +92,117 @@ gnome_scores_get_type ()
}
static void
-gnome_scores_init (GnomeScores *gs) {}
+gnome_scores_init (GnomeScores *gs)
+{
+ GtkWidget *label;
+ const gchar * buttons[] = { GNOME_STOCK_BUTTON_OK, NULL };
+
+ gs->_priv = g_new0(GnomeScoresPrivate, 1);
+
+ gnome_dialog_constructv(GNOME_DIALOG(gs),
+ _("Top Ten"),
+ buttons);
+
+ gs->_priv->logo = NULL;
+ gs->_priv->but_clear = NULL;
+
+ gs->_priv->table = GTK_TABLE( gtk_table_new (0, 3, FALSE) );
+ gtk_table_set_col_spacings (gs->_priv->table, 30);
+ gtk_table_set_row_spacings (gs->_priv->table, 5);
+
+ label = gtk_label_new ( _("User") );
+ gtk_widget_show (label);
+ gtk_table_attach_defaults ( gs->_priv->table, label, 0, 1, 0, 1);
+ label = gtk_label_new ( _("Score") );
+ gtk_widget_show (label);
+ gtk_table_attach_defaults ( gs->_priv->table, label, 1, 2, 0, 1);
+ label = gtk_label_new ( _("Date") );
+ gtk_widget_show (label);
+ gtk_table_attach_defaults ( gs->_priv->table, label, 2, 3, 0, 1);
+
+ gtk_widget_show(GTK_WIDGET(gs->_priv->table));
+
+ gtk_box_pack_end (GTK_BOX(GNOME_DIALOG(gs)->vbox),
+ GTK_WIDGET(gs->_priv->table),
+ TRUE, TRUE, 0);
+
+ gtk_container_set_border_width (GTK_CONTAINER (gs), 5);
+
+ gnome_dialog_set_close (GNOME_DIALOG (gs), TRUE);
+
+ gs->_priv->logo_container = gtk_hbox_new(FALSE, 0);
+ gtk_widget_show(gs->_priv->logo_container);
+
+ gtk_box_pack_end (GTK_BOX(GNOME_DIALOG(gs)->vbox),
+ gs->_priv->logo_container,
+ FALSE, FALSE, 0);
+}
+
+static void
+gnome_scores_class_init (GnomeScoresClass *class)
+{
+ GtkObjectClass *object_class;
+
+ object_class = (GtkObjectClass *) class;
+
+ object_class->destroy = gnome_scores_destroy;
+
+ parent_class = gtk_type_class (gnome_dialog_get_type ());
+}
static void
-gnome_scores_class_init (GnomeScoresClass *class) {}
+gnome_scores_destroy(GtkObject *object)
+{
+ GnomeScores *gs = GNOME_SCORES(object);
+
+ g_free(gs->_priv->label_names);
+ g_free(gs->_priv->label_scores);
+ g_free(gs->_priv->label_times);
+
+ g_free(gs->_priv);
+ gs->_priv = NULL;
+}
/**
- * gnome_scores_new:
+ * gnome_scores_construct:
* @n_scores: Number of positions.
* @names: Names of the players.
* @scores: Scores
* @times: Time in which the scores were done
* @clear: Add a "Clear" Button?
*
- * Description: Creates the high-scores window.
+ * Description: useful for language bindings and subclassing, not to be used by itself,
+ * see #gnome_scores_new
*
- * Returns: A new #GnomeScores widget
+ * Returns:
*/
-GtkWidget *
-gnome_scores_new ( guint n_scores,
- gchar **names,
- gfloat *scores ,
- time_t *times,
- guint clear)
+void
+gnome_scores_construct ( GnomeScores *gs,
+ guint n_scores,
+ gchar **names,
+ gfloat *scores,
+ time_t *times,
+ gboolean clear)
{
- GtkWidget *retval = gtk_type_new(gnome_scores_get_type());
- GnomeScores *gs = GNOME_SCORES(retval);
- GtkTable *table;
- GtkWidget *label;
gchar tmp[10];
gchar tmp2[256];
- guint i;
- const gchar * buttons[] = { GNOME_STOCK_BUTTON_OK, NULL };
+ guint i;
- gnome_dialog_constructv(GNOME_DIALOG(retval),
- _("Top Ten"),
- buttons);
+ gs->_priv->n_scores = n_scores;
- gs->logo = 0;
- gs->but_clear = 0;
- gs->n_scores = n_scores;
-
- table = GTK_TABLE( gtk_table_new (n_scores+1, 3, FALSE) );
- gtk_table_set_col_spacings (table, 30);
- gtk_table_set_row_spacings (table, 5);
-
- label = gtk_label_new ( _("User") );
- gtk_widget_show (label);
- gtk_table_attach_defaults ( table, label, 0, 1, 0, 1);
- label = gtk_label_new ( _("Score") );
- gtk_widget_show (label);
- gtk_table_attach_defaults ( table, label, 1, 2, 0, 1);
- label = gtk_label_new ( _("Date") );
- gtk_widget_show (label);
- gtk_table_attach_defaults ( table, label, 2, 3, 0, 1);
-
- gs->label_names = g_malloc(sizeof(GtkWidget*)*n_scores);
- gs->label_scores = g_malloc(sizeof(GtkWidget*)*n_scores);
- gs->label_times = g_malloc(sizeof(GtkWidget*)*n_scores);
+ gs->_priv->label_names = g_malloc(sizeof(GtkWidget*) * n_scores);
+ gs->_priv->label_scores = g_malloc(sizeof(GtkWidget*) * n_scores);
+ gs->_priv->label_times = g_malloc(sizeof(GtkWidget*) * n_scores);
for(i=0; i < n_scores; i++) {
- gs->label_names[i] = gtk_label_new ( names[i] );
- gtk_widget_show ( gs->label_names[i] );
- gtk_table_attach_defaults ( table, gs->label_names[i], 0, 1, i+1, i+2);
+ gs->_priv->label_names[i] = gtk_label_new ( names[i] );
+ gtk_widget_show ( gs->_priv->label_names[i] );
+ gtk_table_attach_defaults ( gs->_priv->table, gs->_priv->label_names[i], 0, 1, i+1, i+2);
g_snprintf(tmp,sizeof(tmp),"%5.2f", scores[i]);
- gs->label_scores[i] = gtk_label_new ( tmp );
- gtk_widget_show ( gs->label_scores[i] );
- gtk_table_attach_defaults ( table, gs->label_scores[i], 1, 2, i+1, i+2);
+ gs->_priv->label_scores[i] = gtk_label_new ( tmp );
+ gtk_widget_show ( gs->_priv->label_scores[i] );
+ gtk_table_attach_defaults ( gs->_priv->table, gs->_priv->label_scores[i], 1, 2, i+1, i+2);
/* the localized string should fit (after replacing the %a %b
etc) in ~18 chars.
@@ -159,28 +219,42 @@ gnome_scores_new ( guint n_scores,
strcpy(tmp2, "???");
}
tmp2[sizeof(tmp2)-1] = '\0'; /* just for sanity */
- gs->label_times[i] = gtk_label_new ( tmp2 );
- gtk_widget_show ( gs->label_times[i] );
- gtk_table_attach_defaults ( table, gs->label_times[i], 2, 3, i+1, i+2);
+ gs->_priv->label_times[i] = gtk_label_new ( tmp2 );
+ gtk_widget_show ( gs->_priv->label_times[i] );
+ gtk_table_attach_defaults ( gs->_priv->table, gs->_priv->label_times[i], 2, 3, i+1, i+2);
}
- gtk_widget_show (GTK_WIDGET(table));
/*
if(clear) {
- gs->but_clear = gtk_button_new_with_label ( _("Clear") );
- gtk_widget_show (gs->but_clear);
- gtk_table_attach_defaults ( GTK_TABLE(hor_table), gs->but_clear, 3, 4, 0, 1);
+ gs->_priv->but_clear = gtk_button_new_with_label ( _("Clear") );
+ gtk_widget_show (gs->_priv->but_clear);
+ gtk_table_attach_defaults ( GTK_TABLE(hor_table), gs->_priv->but_clear, 3, 4, 0, 1);
}
*/
+}
- gtk_box_pack_end (GTK_BOX(GNOME_DIALOG(gs)->vbox),
- GTK_WIDGET(table),
- TRUE, TRUE, 0);
-
- gtk_container_set_border_width (GTK_CONTAINER (gs), 5);
-
+/**
+ * gnome_scores_new:
+ * @n_scores: Number of positions.
+ * @names: Names of the players.
+ * @scores: Scores
+ * @times: Time in which the scores were done
+ * @clear: Add a "Clear" Button?
+ *
+ * Description: Creates the high-scores window.
+ *
+ * Returns: A new #GnomeScores widget
+ */
+GtkWidget *
+gnome_scores_new ( guint n_scores,
+ gchar **names,
+ gfloat *scores,
+ time_t *times,
+ gboolean clear)
+{
+ GtkWidget *retval = gtk_type_new(gnome_scores_get_type());
- gnome_dialog_set_close (GNOME_DIALOG (gs), TRUE);
+ gnome_scores_construct(GNOME_SCORES(retval), n_scores, names, scores, times, clear);
return retval;
}
@@ -199,13 +273,19 @@ void
gnome_scores_set_color(GnomeScores *gs, guint n, GdkColor *col)
{
GtkStyle *s = gtk_style_new();
+
+ g_return_if_fail(gs != NULL);
+ g_return_if_fail(GNOME_IS_SCORES(gs));
+ g_return_if_fail(col != NULL);
+ g_return_if_fail(n < gs->_priv->n_scores);
+
/* i believe that i should copy the default style
and change only the fg field, how? */
memcpy((void *) &s->fg[0], col, sizeof(GdkColor) );
- gtk_widget_set_style(GTK_WIDGET(gs->label_names[n]), s);
- gtk_widget_set_style(GTK_WIDGET(gs->label_scores[n]), s);
- gtk_widget_set_style(GTK_WIDGET(gs->label_times[n]), s);
+ gtk_widget_set_style(GTK_WIDGET(gs->_priv->label_names[n]), s);
+ gtk_widget_set_style(GTK_WIDGET(gs->_priv->label_scores[n]), s);
+ gtk_widget_set_style(GTK_WIDGET(gs->_priv->label_times[n]), s);
gtk_style_unref(s);
}
@@ -224,7 +304,11 @@ gnome_scores_set_def_color(GnomeScores *gs, GdkColor *col)
{
unsigned int i;
- for(i=0;i<gs->n_scores;i++) {
+ g_return_if_fail(gs != NULL);
+ g_return_if_fail(GNOME_IS_SCORES(gs));
+ g_return_if_fail(col != NULL);
+
+ for(i=0;i<gs->_priv->n_scores;i++) {
gnome_scores_set_color(gs, i, col);
}
}
@@ -243,7 +327,11 @@ gnome_scores_set_colors(GnomeScores *gs, GdkColor *col)
{
unsigned int i;
- for(i=0;i<gs->n_scores;i++) {
+ g_return_if_fail(gs != NULL);
+ g_return_if_fail(GNOME_IS_SCORES(gs));
+ g_return_if_fail(col != NULL);
+
+ for(i=0;i<gs->_priv->n_scores;i++) {
gnome_scores_set_color(gs, i, col+i);
}
}
@@ -260,9 +348,13 @@ gnome_scores_set_colors(GnomeScores *gs, GdkColor *col)
void
gnome_scores_set_current_player (GnomeScores *gs, gint i)
{
- gtk_widget_set_name (GTK_WIDGET(gs->label_names[i]), "CurrentPlayer");
- gtk_widget_set_name(GTK_WIDGET(gs->label_scores[i]), "CurrentPlayer");
- gtk_widget_set_name(GTK_WIDGET(gs->label_times[i]), "CurrentPlayer");
+ g_return_if_fail(gs != NULL);
+ g_return_if_fail(GNOME_IS_SCORES(gs));
+ g_return_if_fail(i < gs->_priv->n_scores);
+
+ gtk_widget_set_name(GTK_WIDGET(gs->_priv->label_names[i]), "CurrentPlayer");
+ gtk_widget_set_name(GTK_WIDGET(gs->_priv->label_scores[i]), "CurrentPlayer");
+ gtk_widget_set_name(GTK_WIDGET(gs->_priv->label_times[i]), "CurrentPlayer");
}
/**
@@ -277,15 +369,19 @@ gnome_scores_set_current_player (GnomeScores *gs, gint i)
void
gnome_scores_set_logo_label_title (GnomeScores *gs, gchar *txt)
{
- if(gs->logo) {
- g_print("Warning: gnome_scores_set_logo_* can be called only once\n");
- return;
+ g_return_if_fail(gs != NULL);
+ g_return_if_fail(GNOME_IS_SCORES(gs));
+ g_return_if_fail(txt != NULL);
+
+ if(gs->_priv->logo) {
+ gtk_widget_destroy(gs->_priv->logo);
+ gs->_priv->logo = NULL;
}
- gs->logo = gtk_label_new(txt);
- gtk_widget_set_name(GTK_WIDGET(gs->logo), "Logo");
- gtk_box_pack_end (GTK_BOX(GNOME_DIALOG(gs)->vbox), gs->logo, TRUE, TRUE, 0);
- gtk_widget_show (gs->logo);
+ gs->_priv->logo = gtk_label_new(txt);
+ gtk_widget_set_name(GTK_WIDGET(gs->_priv->logo), "Logo");
+ gtk_container_add(GTK_CONTAINER(gs->_priv->logo_container), gs->_priv->logo);
+ gtk_widget_show (gs->_priv->logo);
}
@@ -309,9 +405,12 @@ gnome_scores_set_logo_label (GnomeScores *gs, gchar *txt, gchar *font,
GdkFont *f;
gchar *fo;
- if(gs->logo) {
- g_print("Warning: gnome_scores_set_logo_* can be called only once\n");
- return;
+ g_return_if_fail(gs != NULL);
+ g_return_if_fail(GNOME_IS_SCORES(gs));
+
+ if(gs->_priv->logo) {
+ gtk_widget_destroy(gs->_priv->logo);
+ gs->_priv->logo = NULL;
}
if(col)
@@ -325,11 +424,11 @@ gnome_scores_set_logo_label (GnomeScores *gs, gchar *txt, gchar *font,
if(( f = gdk_fontset_load ( fo ) ))
s->font = f;
- gs->logo = gtk_label_new(txt);
- gtk_widget_set_style(GTK_WIDGET(gs->logo), s);
+ gs->_priv->logo = gtk_label_new(txt);
+ gtk_widget_set_style(GTK_WIDGET(gs->_priv->logo), s);
gtk_style_unref(s);
- gtk_box_pack_end (GTK_BOX(GNOME_DIALOG(gs)->vbox), gs->logo, TRUE, TRUE, 0);
- gtk_widget_show (gs->logo);
+ gtk_container_add(GTK_CONTAINER(gs->_priv->logo_container), gs->_priv->logo);
+ gtk_widget_show (gs->_priv->logo);
}
/**
@@ -344,14 +443,20 @@ gnome_scores_set_logo_label (GnomeScores *gs, gchar *txt, gchar *font,
void
gnome_scores_set_logo_widget (GnomeScores *gs, GtkWidget *w)
{
-
- if(gs->logo) {
- g_print("Warning: gnome_scores_set_logo_* can be called only once\n");
- return;
+ g_return_if_fail(gs != NULL);
+ g_return_if_fail(GNOME_IS_SCORES(gs));
+ g_return_if_fail(w != NULL);
+ g_return_if_fail(GTK_IS_WIDGET(w));
+
+ if(gs->_priv->logo) {
+ gtk_widget_destroy(gs->_priv->logo);
+ gs->_priv->logo = NULL;
}
- gs->logo = w;
- gtk_box_pack_end (GTK_BOX(GNOME_DIALOG(gs)->vbox), gs->logo, TRUE, TRUE, 0);
+ gs->_priv->logo = w;
+ gtk_container_add(GTK_CONTAINER(gs->_priv->logo_container), gs->_priv->logo);
+
+ gtk_widget_show(w);
}
/**
@@ -366,25 +471,24 @@ gnome_scores_set_logo_widget (GnomeScores *gs, GtkWidget *w)
void
gnome_scores_set_logo_pixmap (GnomeScores *gs, gchar *pix_name)
{
- GtkStyle *style;
+ g_return_if_fail(gs != NULL);
+ g_return_if_fail(GNOME_IS_SCORES(gs));
+ g_return_if_fail(pix_name != NULL);
- if(gs->logo) {
- g_print("Warning: gnome_scores_set_logo_* can be called only once\n");
- return;
+ if(gs->_priv->logo) {
+ gtk_widget_destroy(gs->_priv->logo);
+ gs->_priv->logo = NULL;
}
- style = gtk_widget_get_style( GTK_WIDGET(gs) );
-
+ gs->_priv->logo = gnome_pixmap_new_from_file (pix_name);
- gs->logo = gnome_pixmap_new_from_file (pix_name);
-
- gtk_box_pack_end (GTK_BOX(GNOME_DIALOG(gs)->vbox), gs->logo, TRUE, TRUE, 0);
- gtk_widget_show (gs->logo);
+ gtk_container_add(GTK_CONTAINER(gs->_priv->logo_container), gs->_priv->logo);
+ gtk_widget_show (gs->_priv->logo);
}
/**
* gnome_scores_display:
- * @gs: A #GnomeScores widget
+ * @title: Title of the app to be displayed as logo
* @app_name: Name of the application, as in gnome_score_init.
* @level: Level of the game or %NULL.
* @pos: Position in the top ten of the current player, as returned by gnome_score_log.
@@ -400,21 +504,55 @@ GtkWidget *
gnome_scores_display (gchar *title, gchar *app_name, gchar *level, int pos)
{
GtkWidget *hs = NULL;
-/* GdkColor ctitle = {0, 0, 0, 65535}; */
-/* GdkColor col = {0, 65535, 0, 0}; */
gchar **names = NULL;
gfloat *scores = NULL;
time_t *scoretimes = NULL;
gint top;
top = gnome_score_get_notable(app_name, level, &names, &scores, &scoretimes);
- if (top > 0){
+ if (top > 0) {
hs = gnome_scores_new(top, names, scores, scoretimes, 0);
-/* gnome_scores_set_logo_label (GNOME_SCORES(hs), title, 0, */
-/* &ctitle); */
gnome_scores_set_logo_label_title (GNOME_SCORES(hs), title);
if(pos)
-/* gnome_scores_set_color(GNOME_SCORES(hs), pos-1, &col); */
+ gnome_scores_set_current_player(GNOME_SCORES(hs), pos-1);
+
+ gtk_widget_show (hs);
+ g_strfreev(names);
+ g_free(scores);
+ g_free(scoretimes);
+ }
+
+ return hs;
+}
+
+/**
+ * gnome_scores_display_with_pixmap:
+ * @pixmap_logo: Filename of a logo pixmap to display
+ * @app_name: Name of the application, as in gnome_score_init.
+ * @level: Level of the game or %NULL.
+ * @pos: Position in the top ten of the current player, as returned by gnome_score_log.
+ *
+ * Description: Does all the work of displaying the best scores.
+ * It calls gnome_score_get_notables to retrieve the info, creates the window,
+ * and show it.
+ *
+ * Returns: If a dialog is displayed return it's pointer. It can also
+ * be %NULL if no dialog is displayed
+ */
+GtkWidget *
+gnome_scores_display_with_pixmap (gchar *pixmap_logo, gchar *app_name, gchar *level, int pos)
+{
+ GtkWidget *hs = NULL;
+ gchar **names = NULL;
+ gfloat *scores = NULL;
+ time_t *scoretimes = NULL;
+ gint top;
+
+ top = gnome_score_get_notable(app_name, level, &names, &scores, &scoretimes);
+ if (top > 0) {
+ hs = gnome_scores_new(top, names, scores, scoretimes, 0);
+ gnome_scores_set_logo_pixmap (GNOME_SCORES(hs), pixmap_logo);
+ if(pos)
gnome_scores_set_current_player(GNOME_SCORES(hs), pos-1);
gtk_widget_show (hs);
diff --git a/libgnomeui/gnome-scores.h b/libgnomeui/gnome-scores.h
index 6f7efce..6c4ee20 100644
--- a/libgnomeui/gnome-scores.h
+++ b/libgnomeui/gnome-scores.h
@@ -59,20 +59,15 @@ BEGIN_GNOME_DECLS
#define GNOME_IS_SCORES_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_SCORES))
typedef struct _GnomeScores GnomeScores;
+typedef struct _GnomeScoresPrivate GnomeScoresPrivate;
typedef struct _GnomeScoresClass GnomeScoresClass;
struct _GnomeScores
{
GnomeDialog dialog;
- GtkWidget *but_clear;
-
- GtkWidget *logo;
- GtkWidget **label_names;
- GtkWidget **label_scores;
- GtkWidget **label_times;
-
- guint n_scores;
+ /*< private >*/
+ GnomeScoresPrivate *_priv;
};
struct _GnomeScoresClass
@@ -102,6 +97,12 @@ GtkWidget * /* returns the pointer to the displayed window */
current player, as returned by
gnome_score_log. */
);
+/* Same as above, but with a pixmap logo instead of just text */
+GtkWidget *
+ gnome_scores_display_with_pixmap (gchar *pixmap_logo,
+ gchar *app_name,
+ gchar *level,
+ int pos);
/* Creates the high-scores window. */
GtkWidget* gnome_scores_new (
@@ -109,9 +110,17 @@ GtkWidget* gnome_scores_new (
gchar **names, /* Names of the players. */
gfloat *scores, /* Scores */
time_t *times, /* Time in which the scores were done */
- guint clear /* Add a "Clear" Button? */
+ gboolean clear /* Add a "Clear" Button? */
);
+/* Constructor for bindings / subclassing */
+void gnome_scores_construct (GnomeScores *gs,
+ guint n_scores,
+ gchar **names,
+ gfloat *scores,
+ time_t *times,
+ gboolean clear);
+
/* Creates a label to be the logo */
void gnome_scores_set_logo_label (
GnomeScores *gs, /* GNOME Scores widget. */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]