Window + modal window issues



Hi guys !

I'm facing a strange problem : 

I first launch a window on which I can draw "x" where I click.
When I click I also open a modal box asking for a question

the modal box is triggered from the draw_cross callback function bounded
with the "clicked signal"

everything works fine except that the code written AFTER the modal box
being triggered never gets hit (in that case a printf() ;) )

any clue ?

u will find attached the .c and .h ... UI is for the main interface maa
is for the modal one !!

thanx a lot ;))



-- 
BOFH excuse #295:

The Token fell out of the ring. Call us when you find it.
/***********************************************************************
 * UI.C
 * User interface in GTK to get the user comands and to send them to
 * the XML Formatting engine
 * 
 * This software is under BeerWare
 * If you use this software please remember to offer me a Beer 
 * when we meet!
 ************************************************************************/

#include <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>

#include "UI.h"
#include "maa.h"

/* Backing pixmap for drawing area */
static GdkPixmap *pixmap = NULL;

/* Create a new backing pixmap of the appropriate size */
static gint
configure_event (GtkWidget * widget, GdkEventConfigure * event)
{
  if (pixmap)
    gdk_pixmap_unref (pixmap);
  
  pixmap = gdk_pixmap_new (widget->window,
			   widget->allocation.width,
			   widget->allocation.height, -1);
  gdk_draw_rectangle (pixmap,
		      widget->style->white_gc,
		      TRUE,
		      0, 0,
		      widget->allocation.width, widget->allocation.height);
  
  return TRUE;
}

/* Redraw the screen from the backing pixmap */
static gint
expose_event (GtkWidget * widget, GdkEventExpose * event)
{
  gdk_draw_pixmap (widget->window,
		   widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
		   pixmap,
		   event->area.x, event->area.y,
		   event->area.x, event->area.y,
		   event->area.width, event->area.height);

  return FALSE;
}


/* Draws a cross on the screen */
void draw_cross(GtkWidget * widget, gdouble x, gdouble y)
{
  // The size of a cross should be a tenth of the board's size with
  // with at least 1 pixel
  
  gint width,height=0;
  GdkRectangle update_rect;
  
  width = (int) widget->allocation.width / 10;
  if ( width < 1) 
    {
      width = 1;
    }
  height = width;

  update_rect.x = x - (width/2);
  update_rect.y = y - 1;
  update_rect.width = width;
  update_rect.height = 2;
  gdk_draw_rectangle (pixmap,
		      widget->style->black_gc,
		      TRUE,
		      update_rect.x, update_rect.y,
		      update_rect.width, update_rect.height);
  
  update_rect.x = x - 1;
  update_rect.y = y - (width/2);
  update_rect.width = 2;
  update_rect.height = width;
  gdk_draw_rectangle (pixmap,
		      widget->style->black_gc,
		      TRUE,
		      update_rect.x, update_rect.y,
		      update_rect.width, update_rect.height);
  update_rect.x = x - (width/2);
  update_rect.y = y - (width/2);
  update_rect.width = width;
  update_rect.height = width;
  
  gtk_widget_draw (widget, &update_rect);
  //enter the current point's data
  current_point->x = x;
  current_point->y = y;
  

  // Now we should call for a modal dialog to ask for an angle if required.
  
  modal_ask_angle();

  printf("cocoUI\n");
}
static gint
button_press_event (GtkWidget * widget, GdkEventButton * event)
{
  if (event->button == 1 && pixmap != NULL)
    //draw_brush (widget, event->x, event->y);
    draw_cross(widget, event->x, event->y);

  return TRUE;
}

static gint
motion_notify_event (GtkWidget * widget, GdkEventMotion * event)
{
  int x, y;
  GdkModifierType state;

  if (event->is_hint)
    gdk_window_get_pointer (event->window, &x, &y, &state);
  else
    {
      x = event->x;
      y = event->y;
      state = event->state;
    }

  if (state & GDK_BUTTON1_MASK && pixmap != NULL)
    {
      // Here is what happens when u remain clicked and move vour mouse 
      //draw_brush (widget, x, y);
      
    }
  return TRUE;
}

void
quit ()
{
  gtk_exit (0);
}

int
main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *drawing_area;
  GtkWidget *vbox;
  GtkWidget *button;


  
  //GTK initialisation
  gtk_init (&argc, &argv);
  //Point Structure initialisation
  first_point = (spif_points *) malloc (sizeof(spif_points));
  current_point = first_point;

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_name (window, "Spif control Center");

  vbox = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), vbox);
  gtk_widget_show (vbox);

  gtk_signal_connect (GTK_OBJECT (window), "destroy",
		      GTK_SIGNAL_FUNC (quit), NULL);

  /* Create the drawing area */

  drawing_area = gtk_drawing_area_new ();
  gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 200, 200);
  gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0);

  gtk_widget_show (drawing_area);

  /* Signals used to handle backing pixmap */

  gtk_signal_connect (GTK_OBJECT (drawing_area), "expose_event",
		      (GtkSignalFunc) expose_event, NULL);
  gtk_signal_connect (GTK_OBJECT (drawing_area), "configure_event",
		      (GtkSignalFunc) configure_event, NULL);

  /* Event signals */

  gtk_signal_connect (GTK_OBJECT (drawing_area), "motion_notify_event",
		      (GtkSignalFunc) motion_notify_event, NULL);
  gtk_signal_connect (GTK_OBJECT (drawing_area), "button_press_event",
		      (GtkSignalFunc) button_press_event, NULL);

  gtk_widget_set_events (drawing_area, GDK_EXPOSURE_MASK
			 | GDK_LEAVE_NOTIFY_MASK
			 | GDK_BUTTON_PRESS_MASK
			 | GDK_POINTER_MOTION_MASK
			 | GDK_POINTER_MOTION_HINT_MASK);

  /* .. And a quit button */
  button = gtk_button_new_with_label ("Quit");
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);

  gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
			     GTK_SIGNAL_FUNC (gtk_widget_destroy),
			     GTK_OBJECT (window));
  gtk_widget_show (button);

  gtk_widget_show (window);

  gtk_main ();

  return 0;
}

/* example-end */



typedef struct _spif_points
{
  gint x;
  gint y;
  gint angle;
  gint line_type;
  struct _spif_points *next;
} spif_points;

spif_points  *first_point; //premier pointeur sur les points
spif_points  *current_point; // point courant
/****************************************************************
 * The Modal Ask Angle Dialog Box
 * should open a modal dialog and ask for an angle
 * Then returns 1 if yes an angle is desired
 * or no an angle is not required
 *
 * This software is under BeerWare
 * If you use this software please remember to offer me a Beer 
 * when we meet!
 ************************************************************************/

#include <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>
#include "UI.h"
#include "maa.h"

void modal_ask_angle ()
{
  GtkWidget *hbox;
  GtkWidget *vbox;
  GtkWidget *text;
  GtkWidget *button;
  
 
  // create a new modal window
  window2 = gtk_window_new (GTK_WINDOW_TOPLEVEL);  
  gtk_window_set_modal ( (GtkWindow *) window2, TRUE);
  gtk_widget_set_name (window2, "Do you want to select an angle ?");
  

  // create a vbox to put everything in
  vbox = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window2), vbox);
  gtk_widget_show (vbox);
  
  // create the question text
  text = gtk_label_new ("Would you like to be prompted for an angle?");
  gtk_box_pack_start (GTK_BOX (vbox), text, TRUE, TRUE, 0);
  gtk_widget_show (text);

  // create the hbox to put yes or no in
  hbox = gtk_hbox_new (FALSE,0);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
  gtk_widget_show (hbox);

  // Create the Yes and No Buttons
  
  button = gtk_button_new_with_label ("Yes");
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
  
  gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
			     GTK_SIGNAL_FUNC (yes_pressed),
			     GTK_OBJECT (window2));
  gtk_widget_show (button);

  button = gtk_button_new_with_label ("No");
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
  
  gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
			     GTK_SIGNAL_FUNC (no_pressed),
			     GTK_OBJECT (window2));
  gtk_widget_show (button);
  gtk_widget_show (window2);

  gtk_main ();

}

// yes or no  button pressed
void yes_pressed(GtkButton* button, gpointer func_data)
{
  // should distroy this window and open a new modal window
  gtk_widget_destroy(window2);
  
  //creates now the angle window selection

  

}

void no_pressed(GtkButton* button, gpointer func_data)
{
  //no angle given
  current_point->angle = 0;
  current_point->line_type=0;
  current_point->next = (spif_points *) malloc (sizeof(spif_points));
  current_point = current_point->next;

  gtk_widget_destroy(window2);
}
spif_points *point;
GtkWidget *window2;

void modal_ask_angle ();
void yes_pressed ( GtkButton* button, gpointer func_data);
void no_pressed ( GtkButton* button, gpointer func_data);


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