Back to index

gcompris  8.2.2
Typedefs | Functions | Variables
dialog.c File Reference
#include <string.h>
#include "gcompris.h"

Go to the source code of this file.

Typedefs

typedef void(* sighandler_t )(int)

Functions

static gint item_event_ok (GnomeCanvasItem *item, GdkEvent *event, DialogBoxCallBack dbcb)
void gc_dialog_close ()
void gc_dialog (gchar *str, DialogBoxCallBack dbcb)

Variables

static GnomeCanvasGroup * rootDialogItem = NULL
static GnomeCanvasItem * itemDialogText = NULL

Typedef Documentation

typedef void(* sighandler_t)(int)

Definition at line 30 of file dialog.c.


Function Documentation

void gc_dialog ( gchar *  str,
DialogBoxCallBack  dbcb 
)

Definition at line 56 of file dialog.c.

{
  GnomeCanvasItem *item_text   = NULL;
  GnomeCanvasItem *item_text_ok   = NULL;
  GdkPixbuf       *pixmap_dialog = NULL;
  GtkTextIter      iter_start, iter_end;
  GtkTextBuffer   *buffer;
  GtkTextTag      *txt_tag;

  g_warning("Dialog=%s\n", str);

  /* If we are already running do nothing */
  if(rootDialogItem) {
    g_warning("Cannot run a dialog box, one is already running. Message = %s\n", str);
    return;
  }

  /* First pause the board */
  gc_board_pause(TRUE);

  gc_bar_hide(TRUE);

  rootDialogItem = \
    GNOME_CANVAS_GROUP(gnome_canvas_item_new (gnome_canvas_root(gc_get_canvas()),
                                         gnome_canvas_group_get_type (),
                                         "x", (double) 0,
                                         "y", (double) 0,
                                         NULL));

  pixmap_dialog = gc_skin_pixmap_load("dialogbox.png");

  itemDialogText = gnome_canvas_item_new (rootDialogItem,
                                   gnome_canvas_pixbuf_get_type (),
                                   "pixbuf", pixmap_dialog,
                                   "x", (double) (BOARDWIDTH - gdk_pixbuf_get_width(pixmap_dialog))/2,
                                   "y", (double) (BOARDHEIGHT - gdk_pixbuf_get_height(pixmap_dialog))/2,
                                  NULL);

  /* OK Text */
  item_text_ok = gnome_canvas_item_new (rootDialogItem,
                                   gnome_canvas_text_get_type (),
                                   "text", _("OK"),
                                   "font", gc_skin_font_title,
                                   "x", (double)  BOARDWIDTH*0.5,
                                   "y", (double)  (BOARDHEIGHT - gdk_pixbuf_get_height(pixmap_dialog))/2 +
                                   gdk_pixbuf_get_height(pixmap_dialog) - 35,
                                   "anchor", GTK_ANCHOR_CENTER,
                                   "fill_color_rgba", gc_skin_color_text_button,
                                   "weight", PANGO_WEIGHT_HEAVY,
                            NULL);

  gdk_pixbuf_unref(pixmap_dialog);

  gtk_signal_connect(GTK_OBJECT(itemDialogText), "event",
                   (GtkSignalFunc) item_event_ok,
                   dbcb);

  item_text = gnome_canvas_item_new (rootDialogItem,
                                 gnome_canvas_rich_text_get_type (),
                                 "x", (double) BOARDWIDTH/2,
                                 "y", (double) 100.0,
                                 "width", (double)BOARDWIDTH-260.0,
                                 "height", 400.0,
                                 "anchor", GTK_ANCHOR_NORTH,
                                 "justification", GTK_JUSTIFY_CENTER,
                                 "grow_height", FALSE,
                                 "cursor_visible", FALSE,
                                 "cursor_blink", FALSE,
                                 "editable", FALSE,
                                 NULL);

  gnome_canvas_item_set (item_text,
                      "text", str,
                      NULL);

  buffer  = gnome_canvas_rich_text_get_buffer(GNOME_CANVAS_RICH_TEXT(item_text));
  txt_tag = gtk_text_buffer_create_tag(buffer, NULL,
                                   "font",       gc_skin_font_board_medium,
                                   "foreground", "blue",
                                   "family-set", TRUE,
                                   NULL);
  gtk_text_buffer_get_end_iter(buffer, &iter_end);
  gtk_text_buffer_get_start_iter(buffer, &iter_start);
  gtk_text_buffer_apply_tag(buffer, txt_tag, &iter_start, &iter_end);

  gtk_signal_connect(GTK_OBJECT(item_text), "event",
                   (GtkSignalFunc) item_event_ok,
                   dbcb);
  gtk_signal_connect(GTK_OBJECT(item_text_ok), "event",
                   (GtkSignalFunc) item_event_ok,
                   dbcb);

}

Here is the call graph for this function:

Here is the caller graph for this function:

void gc_dialog_close ( )

Definition at line 36 of file dialog.c.

                       {

  /* If we already running delete the previous one */
  if(rootDialogItem) {
    /* WORKAROUND: There is a bug in the richtex item and we need to remove it first */
    while (g_idle_remove_by_data (itemDialogText));
    gtk_object_destroy (GTK_OBJECT(itemDialogText));
    itemDialogText = NULL;

    gtk_object_destroy(GTK_OBJECT(rootDialogItem));
  }

  rootDialogItem = NULL;

}

Here is the caller graph for this function:

static gint item_event_ok ( GnomeCanvasItem *  item,
GdkEvent *  event,
DialogBoxCallBack  dbcb 
) [static]

Definition at line 152 of file dialog.c.

{
  switch (event->type)
    {
    case GDK_ENTER_NOTIFY:
      break;
    case GDK_LEAVE_NOTIFY:
      break;
    case GDK_BUTTON_PRESS:
      if(rootDialogItem)
       gc_dialog_close();

      /* restart the board */
      gc_board_pause(FALSE);

      gc_bar_hide(FALSE);

      if(dbcb != NULL)
       dbcb();

    default:
      break;
    }
  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

GnomeCanvasItem* itemDialogText = NULL [static]

Definition at line 27 of file dialog.c.

GnomeCanvasGroup* rootDialogItem = NULL [static]

Definition at line 26 of file dialog.c.