Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruno Coudoin <bcoudoin@src.gnome.org>2006-02-03 22:08:07 (GMT)
committer Bruno Coudoin <bcoudoin@src.gnome.org>2006-02-03 22:08:07 (GMT)
commitcce87fea6c51eaaf3afab0d30bd6330817d5772f (patch)
tree18c700ed6d9e8ed1cecd8f2d7dc0826065f53e69
parent0929e2cdc362262437c9ffdf1f7f3adcb1a952cc (diff)
- merged awele with HEAD.
* src/boards/python/guessnumber.py: fix title alignement from HEAD. * src/boards/smallnumbers.c: (smallnumbers_create_item): from HEAD, use bar dice. * src/boards/wordprocessor.c: (wordprocessor_create), (display_style_buttons), (item_event), (create_tags),
-rw-r--r--ChangeLog20
-rw-r--r--boards/awele/awele_frame.jpgbin33353 -> 0 bytes
-rw-r--r--boards/awele/awele_frame.pngbin440146 -> 433301 bytes
-rw-r--r--boards/awele/awele_frame_avec_messages.pngbin500899 -> 0 bytes
-rw-r--r--boards/awele/nv_partie.pngbin6244 -> 0 bytes
-rw-r--r--boards/awele/nv_partie_clic.pngbin5065 -> 0 bytes
-rw-r--r--boards/awele/nv_partie_notify.pngbin6336 -> 0 bytes
-rw-r--r--po/TRANSLATORS.README2
-rw-r--r--src/boards/awele.c205
-rw-r--r--src/boards/awele.h23
-rw-r--r--src/boards/smallnumbers.c11
-rw-r--r--src/boards/wordprocessor.c214
12 files changed, 304 insertions, 171 deletions
diff --git a/ChangeLog b/ChangeLog
index 2288d37..61dbbcb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2006-02-03 Bruno coudoin <bruno.coudoin@free.fr>
+
+ - merged awele with HEAD.
+
+ * boards/awele/awele_frame.jpg:
+ * boards/awele/awele_frame.png:
+ * boards/awele/awele_frame_avec_messages.png:
+ * boards/awele/nv_partie.png:
+ * boards/awele/nv_partie_clic.png:
+ * boards/awele/nv_partie_notify.png:
+ * po/TRANSLATORS.README:
+ * src/boards/awele.c: (start_board), (repeat), (awele_create_item),
+ (buttonNewGameClick):
+ * src/boards/awele.h:
+ * src/boards/python/guessnumber.py: fix title alignement from HEAD.
+ * src/boards/smallnumbers.c: (smallnumbers_create_item): from HEAD, use bar dice.
+ * src/boards/wordprocessor.c: (wordprocessor_create),
+ (display_style_buttons), (item_event), (create_tags),
+ (key_press_event):
+
2006-02-03 Yves Combe,,, <yves@ycombe.net>
fix level display and usage in awele.
diff --git a/boards/awele/awele_frame.jpg b/boards/awele/awele_frame.jpg
deleted file mode 100644
index 65f9798..0000000
--- a/boards/awele/awele_frame.jpg
+++ /dev/null
Binary files differ
diff --git a/boards/awele/awele_frame.png b/boards/awele/awele_frame.png
index b2196a9..e5efad9 100644
--- a/boards/awele/awele_frame.png
+++ b/boards/awele/awele_frame.png
Binary files differ
diff --git a/boards/awele/awele_frame_avec_messages.png b/boards/awele/awele_frame_avec_messages.png
deleted file mode 100644
index 0439d22..0000000
--- a/boards/awele/awele_frame_avec_messages.png
+++ /dev/null
Binary files differ
diff --git a/boards/awele/nv_partie.png b/boards/awele/nv_partie.png
deleted file mode 100644
index 5426862..0000000
--- a/boards/awele/nv_partie.png
+++ /dev/null
Binary files differ
diff --git a/boards/awele/nv_partie_clic.png b/boards/awele/nv_partie_clic.png
deleted file mode 100644
index 33e8476..0000000
--- a/boards/awele/nv_partie_clic.png
+++ /dev/null
Binary files differ
diff --git a/boards/awele/nv_partie_notify.png b/boards/awele/nv_partie_notify.png
deleted file mode 100644
index 4bccc70..0000000
--- a/boards/awele/nv_partie_notify.png
+++ /dev/null
Binary files differ
diff --git a/po/TRANSLATORS.README b/po/TRANSLATORS.README
index 69e6241..1dc8a05 100644
--- a/po/TRANSLATORS.README
+++ b/po/TRANSLATORS.README
@@ -1,6 +1,8 @@
NOTE TO TRANSLATORS
-------------------
+To update only you po file, run: intltool-update lang (lang is fr for French).
+
GCompris is a little bit special in terms of translation needs. The best is
done to bring back everything to .po files but it is not exhaustive.
diff --git a/src/boards/awele.c b/src/boards/awele.c
index aaddb8f..6ed6eb2 100644
--- a/src/boards/awele.c
+++ b/src/boards/awele.c
@@ -35,6 +35,7 @@ static void end_board (void);
static void set_level (guint level);
static int gamewon;
static void game_won (void);
+static void repeat(void);
static GnomeCanvasGroup *boardRootItem = NULL;
@@ -67,7 +68,7 @@ static BoardPlugin menu_bp = {
NULL,
set_level,
NULL,
- NULL,
+ repeat,
NULL,
NULL
};
@@ -104,14 +105,27 @@ start_board (GcomprisBoard * agcomprisBoard)
if (agcomprisBoard != NULL)
{
+ gchar *str;
+ GdkPixbuf *pixmap = NULL;
+
gcomprisBoard = agcomprisBoard;
gcomprisBoard->level = 1;
gcomprisBoard->maxlevel = 4;
gcomprisBoard->sublevel = 1;
gcomprisBoard->number_of_sublevel = 1; /* Go to next level after
* this number of 'play' */
- gcompris_bar_set (GCOMPRIS_BAR_LEVEL);
+ str = gcompris_image_to_skin("button_reload.png");
+ pixmap = gcompris_load_pixmap(str);
+ g_free(str);
+ if(pixmap) {
+ gcompris_bar_set_repeat_icon(pixmap);
+ gdk_pixbuf_unref(pixmap);
+ gcompris_bar_set(GCOMPRIS_BAR_REPEAT_ICON);
+ } else {
+ gcompris_bar_set(GCOMPRIS_BAR_REPEAT);
+ }
+
awele_next_level ();
gamewon = FALSE;
@@ -151,6 +165,15 @@ is_our_board (GcomprisBoard * gcomprisBoard)
return FALSE;
}
+/*
+ * Repeat let the user restart the current level
+ *
+ */
+static void repeat (){
+
+ buttonNewGameClick(graphsElt);
+}
+
static void
set_level (guint level)
@@ -242,6 +265,58 @@ awele_create_item (GnomeCanvasGroup * parent)
(double) gdk_pixbuf_get_height (pixmap),
"width_set", TRUE, "height_set", TRUE, NULL);
+ /*
+ * Display text
+ */
+ {
+ int x, y;
+
+ x = 35;
+ y = 190;
+ gnome_canvas_item_new (boardRootItem,
+ gnome_canvas_text_get_type (),
+ "text", _("NORTH"),
+ "font", gcompris_skin_font_board_medium,
+ "x", (double) x + 1,
+ "y", (double) y + 1,
+ "anchor", GTK_ANCHOR_CENTER,
+ "fill_color_rgba", gcompris_skin_color_shadow,
+ NULL);
+
+ gnome_canvas_item_new (boardRootItem,
+ gnome_canvas_text_get_type (),
+ "text", _("NORTH"),
+ "font", gcompris_skin_font_board_medium,
+ "x", (double) x,
+ "y", (double) y,
+ "anchor", GTK_ANCHOR_CENTER,
+ "fill_color_rgba", gcompris_skin_color_text_button,
+ NULL);
+
+ x = 765;
+ y = 295;
+ gnome_canvas_item_new (boardRootItem,
+ gnome_canvas_text_get_type (),
+ "text", _("SOUTH"),
+ "font", gcompris_skin_font_board_medium,
+ "x", (double) x + 1,
+ "y", (double) y + 1,
+ "anchor", GTK_ANCHOR_CENTER,
+ "fill_color_rgba", gcompris_skin_color_shadow,
+ NULL);
+
+ gnome_canvas_item_new (boardRootItem,
+ gnome_canvas_text_get_type (),
+ "text", _("SOUTH"),
+ "font", gcompris_skin_font_board_medium,
+ "x", (double) x,
+ "y", (double) y,
+ "anchor", GTK_ANCHOR_CENTER,
+ "fill_color_rgba", gcompris_skin_color_text_button,
+ NULL);
+
+ }
+
staticAwale = (AWALE *) malloc (sizeof (AWALE));
if (!staticAwale)
@@ -416,28 +491,6 @@ awele_create_item (GnomeCanvasGroup * parent)
"anchor", GTK_ANCHOR_CENTER,
NULL);
- strcpy (xpmFile, NEWGAME);
- graphsElt->pixbufButtonNewGame = gcompris_load_pixmap (xpmFile);
- strcpy (xpmFile, NEWGAME_CLIC);
- graphsElt->pixbufButtonNewGameClicked =
- gcompris_load_pixmap (xpmFile);
- strcpy (xpmFile, NEWGAME_NOTIFY);
- graphsElt->pixbufButtonNewGameNotify = gcompris_load_pixmap (xpmFile);
-
- graphsElt->ButtonNewGame = gnome_canvas_item_new (boardRootItem,
- gnome_canvas_pixbuf_get_type
- (), "x",
- (double) 700, "y",
- (double) 60,
- "pixbuf",
- graphsElt->
- pixbufButtonNewGame,
- NULL);
-
- gtk_signal_connect (GTK_OBJECT (graphsElt->ButtonNewGame), "event",
- GTK_SIGNAL_FUNC (buttonNewGameClick),
- (gpointer) buttonClickArgs[1]);
-
return NULL;
}
@@ -480,7 +533,7 @@ game_won ()
* les elements graphiques a modifier.
* @return void
*/
-void
+static void
initBoardGraphics (GRAPHICS_ELT * graphsElt)
{
@@ -532,7 +585,7 @@ initBoardGraphics (GRAPHICS_ELT * graphsElt)
* les elements graphiques a modifier.
* @return un entier
*/
-gint
+static gint
buttonClick (GtkWidget * item, GdkEvent * event, gpointer data)
{
@@ -641,7 +694,7 @@ buttonClick (GtkWidget * item, GdkEvent * event, gpointer data)
* @param alpha entier pour differencier une mise a jour du plateau ou le lancement d'une nouvelle partie.
* @return Renvoi du pointeur sur la zone memoire apres redimension (n'a probablement pas changé d'adresse).
*/
-BEANHOLE_LINK *
+static BEANHOLE_LINK *
updateNbBeans (GnomeCanvasItem * nbBeansHole[NBHOLE],
GnomeCanvasGroup * rootGroup,
BEANHOLE_LINK * ptLink, int alpha)
@@ -736,7 +789,7 @@ updateNbBeans (GnomeCanvasItem * nbBeansHole[NBHOLE],
* pour remettre a jour le score des joueurs
* @param Captures[2] pointeur sur les gnomeCanvasItem d'affichage des scores
*/
-void
+static void
updateCapturedBeans (GnomeCanvasItem * Captures[2])
{
@@ -767,76 +820,42 @@ updateCapturedBeans (GnomeCanvasItem * Captures[2])
* les elements graphiques a modifier.
* @return un entier
*/
-gint
-buttonNewGameClick (GtkWidget * item, GdkEvent * event, gpointer data)
+static gint
+buttonNewGameClick (GRAPHICS_ELT *graphsElt)
{
-
- CALLBACK_ARGS *args;
- short int i = 0, nbCapturedBean = 0;
+ short int nbCapturedBean = 0;
BEANHOLE_LINK *ptLink;
- args = (CALLBACK_ARGS *) data;
-
- switch (event->type)
- {
- case GDK_ENTER_NOTIFY:
- g_object_set (GTK_OBJECT (args->graphsElt->ButtonNewGame),
- "pixbuf",
- args->graphsElt->pixbufButtonNewGameNotify,
- NULL);
- break;
- case GDK_LEAVE_NOTIFY:
- g_object_set (GTK_OBJECT (args->graphsElt->ButtonNewGame),
- "pixbuf", args->graphsElt->pixbufButtonNewGame,
- NULL);
- break;
- case GDK_BUTTON_PRESS:
- g_object_set (GTK_OBJECT (args->graphsElt->ButtonNewGame),
- "pixbuf",
- args->graphsElt->pixbufButtonNewGameClicked,
- NULL);
- g_object_set (args->graphsElt->msg, "text", "", NULL);
- break;
- case GDK_BUTTON_RELEASE:
- g_object_set (GTK_OBJECT (args->graphsElt->ButtonNewGame),
- "pixbuf",
- args->graphsElt->pixbufButtonNewGameNotify,
- NULL);
+ int i;
- nbCapturedBean =
- staticAwale->CapturedBeans[HUMAN] +
- staticAwale->CapturedBeans[COMPUTER];
+ nbCapturedBean =
+ staticAwale->CapturedBeans[HUMAN] +
+ staticAwale->CapturedBeans[COMPUTER];
/**
- * Destruction de toute les graines et remise a zero compteur de capture
- * et indicateur nbre de graine par case
+ * Destruction de toute les graines et remise a zero compteur de capture
+ * et indicateur nbre de graine par case
*/
- for (ptLink = args->graphsElt->ptBeansHoleLink, i = 0;
- i < NBTOTALBEAN - nbCapturedBean; i++, ptLink++)
- {
- gtk_object_destroy (GTK_OBJECT (ptLink->beanPixbuf));
- }
-
- for (i = 0; i < NBHOLE; i++)
- {
- staticAwale->board[i] = NBBEANSPERHOLE;
- g_object_set (GTK_OBJECT
- (args->graphsElt->nbBeansHole[i]),
- "text", "4", NULL);
- }
-
- staticAwale->player = HUMAN;
-
- for (i = 0; i < NBPLAYER; i++)
- {
- staticAwale->CapturedBeans[i] = 0;
- }
-
- updateCapturedBeans (args->graphsElt->Captures);
- initBoardGraphics (args->graphsElt);
- break;
- default:
- break;
- }
+ for (ptLink = graphsElt->ptBeansHoleLink, i = 0;
+ i < NBTOTALBEAN - nbCapturedBean; i++, ptLink++)
+ {
+ gtk_object_destroy (GTK_OBJECT (ptLink->beanPixbuf));
+ }
+
+ for (i = 0; i < NBHOLE; i++)
+ {
+ staticAwale->board[i] = NBBEANSPERHOLE;
+ g_object_set (GTK_OBJECT
+ (graphsElt->nbBeansHole[i]),
+ "text", "4", NULL);
+ }
+
+ staticAwale->player = HUMAN;
- return FALSE;
+ for (i = 0; i < NBPLAYER; i++)
+ {
+ staticAwale->CapturedBeans[i] = 0;
+ }
+
+ updateCapturedBeans (graphsElt->Captures);
+ initBoardGraphics (graphsElt);
}
diff --git a/src/boards/awele.h b/src/boards/awele.h
index cb40d21..2d883f4 100644
--- a/src/boards/awele.h
+++ b/src/boards/awele.h
@@ -16,9 +16,6 @@
#define BOUTON "awele/bouton1.png" //Chemin relatif vers fichiers boutons
#define BOUTON_NOTIFY "awele/bouton1_notify.png" //Chemin relatif vers fichiers boutons cliqués
#define BOUTON_CLIC "awele/bouton1_clic.png" //Chemin relatif vers fichiers boutons cliqués
-#define NEWGAME "awele/nv_partie.png"
-#define NEWGAME_NOTIFY "awele/nv_partie_notify.png"
-#define NEWGAME_CLIC "awele/nv_partie_clic.png"
#define BEAN "awele/graine1.png" //Chemin relatif vers fichiers graines
#define Y_BOUTONS 412 //Abcisse des boutons
@@ -44,10 +41,6 @@ typedef struct {
GdkPixbuf *pixbufButtonClicked[6]; //pixbuf des boutons cliqués
GnomeCanvasItem *Captures[2]; //Tableau d'item affichage nbre graine capturées.
GdkPixbuf *pixbufBeans[4]; //pixbufs des graines
- GdkPixbuf *pixbufButtonNewGame;
- GdkPixbuf *pixbufButtonNewGameNotify;
- GdkPixbuf *pixbufButtonNewGameClicked;
- GnomeCanvasItem *ButtonNewGame;
} GRAPHICS_ELT;
typedef struct {
@@ -56,16 +49,16 @@ typedef struct {
} CALLBACK_ARGS;
/*
-* Fonctions de traitement des évènements, signaux et rappels
+* Fonctions de traitement des events, signaux et rappels
*/
-gint eventDelete (GtkWidget * widget, GdkEvent *event, gpointer data);
-gint eventDestroy (GtkWidget * widget, GdkEvent *event, gpointer data);
-gint buttonClick (GtkWidget *item, GdkEvent *event, gpointer data);
-gint buttonNewGameClick (GtkWidget *item, GdkEvent *event, gpointer data);
+static gint eventDelete (GtkWidget * widget, GdkEvent *event, gpointer data);
+static gint eventDestroy (GtkWidget * widget, GdkEvent *event, gpointer data);
+static gint buttonClick (GtkWidget *item, GdkEvent *event, gpointer data);
+static gint buttonNewGameClick (GRAPHICS_ELT *graphsElt);
/**
* Fonctions Mise a jour de l'affichage
*/
-BEANHOLE_LINK * updateNbBeans (GnomeCanvasItem *nbBeansHole[NBHOLE], GnomeCanvasGroup *rootGroup, BEANHOLE_LINK *ptLink, int alpha);
-void updateCapturedBeans (GnomeCanvasItem *Captures[2]);
-void initBoardGraphics (GRAPHICS_ELT *graphsElt);
+static BEANHOLE_LINK * updateNbBeans (GnomeCanvasItem *nbBeansHole[NBHOLE], GnomeCanvasGroup *rootGroup, BEANHOLE_LINK *ptLink, int alpha);
+static void updateCapturedBeans (GnomeCanvasItem *Captures[2]);
+static void initBoardGraphics (GRAPHICS_ELT *graphsElt);
diff --git a/src/boards/smallnumbers.c b/src/boards/smallnumbers.c
index 7388748..c7ac347 100644
--- a/src/boards/smallnumbers.c
+++ b/src/boards/smallnumbers.c
@@ -1,6 +1,6 @@
/* gcompris - smallnumbers.c
*
- * Time-stamp: <2006/01/31 14:11:59 yves>
+ * Time-stamp: <2006/02/03 21:13:51 bruno>
*
* Copyright (C) 2000 Bruno Coudoin
*
@@ -359,7 +359,6 @@ static void smallnumbers_create_item(GnomeCanvasGroup *parent)
GdkPixbuf *smallnumbers_pixmap = NULL;
GnomeCanvasItem *item;
GnomeCanvasGroup *group_item;
- char *str;
guint i;
char *lettersItem;
gchar *str1 = NULL;
@@ -412,11 +411,13 @@ static void smallnumbers_create_item(GnomeCanvasGroup *parent)
g_free(str1);
g_free(str2);
- str = g_strdup_printf("gcompris/dice/gnome-dice%c.png", numbers[i]);
+ str1 = g_strdup_printf("level%c.png", numbers[i]);
+ str2 = gcompris_image_to_skin(str1);
- smallnumbers_pixmap = gcompris_load_pixmap(str);
+ smallnumbers_pixmap = gcompris_load_pixmap(str2);
- g_free(str);
+ g_free(str1);
+ g_free(str2);
if(x==0.0) {
x = (double)(rand()%(gcomprisBoard->width-
diff --git a/src/boards/wordprocessor.c b/src/boards/wordprocessor.c
index a53d5aa..c9378b1 100644
--- a/src/boards/wordprocessor.c
+++ b/src/boards/wordprocessor.c
@@ -24,6 +24,43 @@
#include "gcompris/gcompris.h"
+/*
+ * Predefined styles
+ * -----------------
+ */
+typedef struct {
+ gchar *name;
+ gchar *font;
+ PangoWeight weight;
+ GtkJustification justification;
+ gint indent;
+ gint pixels_above_lines;
+ gint pixels_below_lines;
+ gchar *foreground;
+} style_t;
+
+typedef struct {
+ gchar *name;
+ style_t styles[];
+} style_list_t;
+
+static style_t style_default[] =
+ {
+ { "H0", "Serif 30", PANGO_WEIGHT_ULTRABOLD, GTK_JUSTIFY_CENTER, 0, 40, 20, "black"},
+ { "H1", "Serif 26", PANGO_WEIGHT_BOLD, GTK_JUSTIFY_LEFT, 0, 30, 15, "black" },
+ { "H2", "Serif 20", PANGO_WEIGHT_SEMIBOLD, GTK_JUSTIFY_LEFT, 0, 20, 12, "black" },
+ { "P", "Serif 16", PANGO_WEIGHT_NORMAL, GTK_JUSTIFY_LEFT, 30, 3, 3, "black" }
+ };
+#define NUMBER_OF_STYLE G_N_ELEMENTS(style_default)
+
+static style_t style_love_letter[] =
+ {
+ { "H0", "Serif 30", PANGO_WEIGHT_ULTRABOLD, GTK_JUSTIFY_CENTER, 0, 40, 20, "DeepPink" },
+ { "H1", "Serif 26", PANGO_WEIGHT_BOLD, GTK_JUSTIFY_LEFT, 0, 30, 15, "HotPink" },
+ { "H2", "Serif 20", PANGO_WEIGHT_SEMIBOLD, GTK_JUSTIFY_LEFT, 0, 20, 12, "MediumOrchid" },
+ { "P", "Serif 16", PANGO_WEIGHT_NORMAL, GTK_JUSTIFY_LEFT, 30, 3, 3, "black" }
+ };
+
static GcomprisBoard *gcomprisBoard = NULL;
static gboolean board_paused = TRUE;
@@ -32,6 +69,8 @@ static void pause_board (gboolean pause);
static void end_board (void);
static gboolean is_our_board (GcomprisBoard *gcomprisBoard);
static void set_level (guint level);
+static gboolean key_press_event (GtkWidget *text_view,
+ GdkEventKey *event);
static GnomeCanvasGroup *boardRootItem = NULL;
@@ -41,15 +80,17 @@ static gint item_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data);
static void display_style_buttons(GnomeCanvasGroup *boardRootItem,
int x,
int y);
-static void create_tags (GtkTextBuffer *buffer, int style);
+static void create_tags (GtkTextBuffer *buffer, style_t style[]);
#define word_area_x1 120
#define word_area_y1 80
#define word_area_width 580
#define word_area_height 420
-static gchar * current_style;
+static style_t *current_style;
+static gchar *current_style_name;
static GtkTextBuffer *buffer;
+static GtkWidget *view;
/* Description of this plugin */
static BoardPlugin menu_bp =
@@ -165,7 +206,6 @@ static void wordprocessor_destroy_all_items()
static GnomeCanvasItem *wordprocessor_create()
{
GnomeCanvasItem *item = NULL;
- GtkWidget *view;
GtkWidget *sw;
boardRootItem = GNOME_CANVAS_GROUP(
@@ -177,6 +217,8 @@ static GnomeCanvasItem *wordprocessor_create()
view = gtk_text_view_new ();
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD);
+ g_signal_connect (view, "key-release-event",
+ G_CALLBACK (key_press_event), NULL);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
@@ -201,9 +243,9 @@ static GnomeCanvasItem *wordprocessor_create()
gtk_widget_show(GTK_WIDGET(sw));
/*
- * Create the default tags
+ * Create the default style tags
*/
- create_tags(buffer, 0);
+ create_tags(buffer, style_love_letter);
/*
* Display the style buttons
@@ -231,7 +273,8 @@ static void display_style_buttons(GnomeCanvasGroup *boardRootItem,
_("TEXT"), "P",
NULL, NULL };
- current_style = NULL;
+ current_style_name = NULL;
+ current_style = NULL;
pixmap = gcompris_load_skin_pixmap("button_small.png");
@@ -305,7 +348,7 @@ item_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data)
{
GtkTextIter iter_start, iter_end;
- current_style = (char *)data;
+ current_style_name = (char *)data;
gtk_text_buffer_get_iter_at_mark(buffer,
&iter_start,
@@ -320,9 +363,27 @@ item_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data)
&iter_end);
gtk_text_buffer_apply_tag_by_name(buffer,
- current_style,
+ current_style_name,
&iter_start,
&iter_end);
+#if 0
+ {
+ PangoFontDescription *font_desc;
+ GdkColor color;
+
+ /* Change default font throughout the widget */
+ font_desc = pango_font_description_from_string ("Serif 15");
+ gtk_widget_modify_font (view, font_desc);
+ pango_font_description_free (font_desc);
+
+ /* Change default color throughout the widget */
+ gdk_color_parse ("green", &color);
+ gtk_widget_modify_text (view, GTK_STATE_NORMAL, &color);
+
+ /* Change left margin throughout the widget */
+ gtk_text_view_set_left_margin (GTK_TEXT_VIEW (view), 30);
+ }
+#endif
}
break;
default:
@@ -336,58 +397,95 @@ item_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data)
return FALSE;
}
+/* Create a bunch of tags. Note that it's also possible to
+ * create tags with gtk_text_tag_new() then add them to the
+ * tag table for the buffer, gtk_text_buffer_create_tag() is
+ * just a convenience function. Also note that you don't have
+ * to give tags a name; pass NULL for the name to create an
+ * anonymous tag.
+ *
+ * In any real app, another useful optimization would be to create
+ * a GtkTextTagTable in advance, and reuse the same tag table for
+ * all the buffers with the same tag set, instead of creating
+ * new copies of the same tags for every buffer.
+ *
+ * Tags are assigned default priorities in order of addition to the
+ * tag table. That is, tags created later that affect the same text
+ * property affected by an earlier tag will override the earlier
+ * tag. You can modify tag priorities with
+ * gtk_text_tag_set_priority().
+ */
+
static void
-create_tags (GtkTextBuffer *buffer, int style)
+create_tags (GtkTextBuffer *buffer, style_t style[])
{
+ gint i;
- /* Create a bunch of tags. Note that it's also possible to
- * create tags with gtk_text_tag_new() then add them to the
- * tag table for the buffer, gtk_text_buffer_create_tag() is
- * just a convenience function. Also note that you don't have
- * to give tags a name; pass NULL for the name to create an
- * anonymous tag.
- *
- * In any real app, another useful optimization would be to create
- * a GtkTextTagTable in advance, and reuse the same tag table for
- * all the buffers with the same tag set, instead of creating
- * new copies of the same tags for every buffer.
- *
- * Tags are assigned default priorities in order of addition to the
- * tag table. That is, tags created later that affect the same text
- * property affected by an earlier tag will override the earlier
- * tag. You can modify tag priorities with
- * gtk_text_tag_set_priority().
- */
-
- gtk_text_buffer_create_tag (buffer, "H0",
- "weight", PANGO_WEIGHT_BOLD,
- "size", 22 * PANGO_SCALE,
- "justification", GTK_JUSTIFY_CENTER,
- "pixels-above-lines", 40,
- "pixels-bellow-lines", 20,
- NULL);
-
- gtk_text_buffer_create_tag (buffer, "H1",
- "weight", PANGO_WEIGHT_BOLD,
- "size", 20 * PANGO_SCALE,
- "pixels-above-lines", 30,
- "pixels-bellow-lines", 15,
- NULL);
-
- gtk_text_buffer_create_tag (buffer, "H2",
- "weight", PANGO_WEIGHT_BOLD,
- "size", 18 * PANGO_SCALE,
- "pixels-above-lines", 20,
- "pixels-bellow-lines", 12,
- NULL);
-
- /* Now the default style for text */
- gtk_text_buffer_create_tag (buffer, "P",
- "size", 14 * PANGO_SCALE,
- "indent", 30,
- NULL);
-
- gtk_text_buffer_create_tag (buffer, "not_editable",
- "editable", FALSE, NULL);
+ for(i=0; i<NUMBER_OF_STYLE; i++)
+ {
+ GtkTextTag *tag;
+
+ tag = gtk_text_buffer_create_tag (buffer, style[i].name,
+ "weight", style[i].weight,
+ "font", style[i].font,
+ "justification", style[i].justification,
+ "indent", style[i].indent,
+ "pixels-above-lines", style[i].pixels_above_lines,
+ "pixels-below-lines", style[i].pixels_below_lines,
+ "foreground", style[i].foreground,
+ NULL);
+ g_object_set_data (G_OBJECT (tag), "style", GINT_TO_POINTER (i));
+ }
}
+
+/* Catch all typing events to apply the proper tags
+ *
+ */
+static gboolean
+key_press_event (GtkWidget *text_view,
+ GdkEventKey *event)
+{
+ GtkTextIter iter_start, iter_end;
+ GtkTextBuffer *buffer;
+
+ {
+ GSList *tags = NULL, *tagp = NULL;
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
+
+ gtk_text_buffer_get_iter_at_mark(buffer,
+ &iter_start,
+ gtk_text_buffer_get_insert (buffer));
+ gtk_text_iter_set_line_offset(&iter_start, 0);
+
+ iter_end = iter_start;
+ gtk_text_iter_forward_to_line_end(&iter_end);
+
+ tags = gtk_text_iter_get_tags (&iter_start);
+ if(g_slist_length(tags) == 0)
+ tags = gtk_text_iter_get_tags (&iter_end);
+
+ for (tagp = tags; tagp != NULL; tagp = tagp->next)
+ {
+ GtkTextTag *tag = tagp->data;
+ gchar *name;
+ g_object_get (G_OBJECT (tag), "name", &name, NULL);
+ gint style = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tag), "style"));
+
+ printf("name=%s style=%d\n", name, style);
+
+ gtk_text_buffer_apply_tag_by_name(buffer,
+ name,
+ &iter_start,
+ &iter_end);
+ }
+
+ if (tags)
+ g_slist_free (tags);
+
+ }
+
+ return FALSE;
+}
+