GtkButton does not respond to mouse click



Hi all,

I wonder how to post to this mailing list. I sent a question two
times now, but neither I received my original question nor any
answer...

So here is, for the third time, my question:
I have the following problem within my GTK program:
I click a button - this triggers the generation of a new window.
When I want to click the button again it does not recognize the
click unless I move the mouse cursor off the button. The keyboard
still has the focus on the button.
This only happens under the WIN32 environment; when I compile under
Linux everything works. I attached the sources together with the
Makefiles. I use MinGW under Windows.

Thanks for the help,

Johannes


8< ----------------------------  main.c ------------------------- >8

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

#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>          /* sleep() */
#endif

#include "gtk_statusbox.h"


GtkWidget *main_window;
GtkWidget *statusbox;

void gtk_sleep (unsigned msec)
{
  int i;

  fflush (stdout);
  msec = msec / 22;
  if (msec == 0)
    msec ++;
  for (i=0; i<msec; i++)
  {
#ifdef WIN32
    Sleep (1);
#else
    usleep(1000);
#endif
    while (gtk_events_pending ())
      gtk_main_iteration ();
  }
}

void click_cb (GtkWidget *widget)
{
  static char count;
  int value;

  count ++;
  printf ("button was clicked %d\n", count);
  statusbox = gtk_status_box (main_window, "GTK test",
    "waiting for the timer to finish ...", TRUE);
  for (value=0; value<100; value++)
  {
    gtk_status_box_set_value (statusbox, value);
    gtk_sleep (10);
  }
  gtk_status_box_set_value (statusbox, value);
  gtk_sleep (100);
  gtk_status_box_destroy (statusbox);
}


#ifdef WIN32
int main (int argc, char *argv[]);

int WINAPI WinMain (
  HINSTANCE hInstance,
  HINSTANCE hPrevInstance,
  LPSTR lpCmdLine,
  int nCmdShow)
{
  return main (__argc, __argv);
}
#endif

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

  gtk_init (&argc, &argv);
  main_window = window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (G_OBJECT (window), "delete_event",
    G_CALLBACK (gtk_main_quit), NULL);

  button = gtk_button_new_with_label ("Click");
g_signal_connect (G_OBJECT(button),"clicked",G_CALLBACK(click_cb),button);
  gtk_container_add (GTK_CONTAINER(window), button);

  gtk_widget_show (button);
  gtk_widget_show (window);
  gtk_main ();

  return 0;
}
8< -------------------------------------------------------------- >8

8< ------------------------- statusbox.h ------------------------ >8
/*-!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!
! Filename: statusbox.h   Function: Prototypes for status box function     !
! Module:                                                                  !
!                                                                          !
!                                                                          !
! Vers.   Date    Auth.   Changes                                          !
! ------------------------------------------------------------------------ !
!        6.Mar.05  JH     Added to GTK JTAG project                        !
!                                                                          !
!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!-*/

#ifndef __GTK_STATUSBOX_H
#define __GTK_STATUSBOX_H


/*************************  Function Prototypes  **************************/
GtkWidget *gtk_status_box (  /* the user callable status_box() function   */
GtkWidget *parent, /* the parent window */ char *title, /* window title */ char *text, /* status box text */ unsigned has_progressbar /* whether to create a progress bar */
);

void gtk_status_box_destroy( /* destroy the status box                    */
GtkWidget *widget /* the widget to destroy */
);

void gtk_status_box_set_value (   /* set a new value for the progress bar */
GtkWidget *statusbox, /* parent of the progress bar */ int val /* new value */
);

int gtk_status_box_get_value (    /* get the curr.val of the progress bar */
GtkWidget *statusbox /* parent of the progress bar */
);

int gtk_status_box_has_progressbar (   /* check for progress bar          */
GtkWidget *statusbox /* the status box */
);

#endif  /* __GTK_STATUSBOX_H */
8< -------------------------------------------------------------- >8

8< ------------------------- statusbox.c ------------------------ >8
/*-!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!
! Filename: statusbox.c   Function: Status box, progress bar objects       !
! Part of:  jtag                                                           !
!                                                                          !
!                                                                          !
! Vers.   Date    Auth.   Changes                                          !
! ------------------------------------------------------------------------ !
! 0.5    6.Mar.05  JH     Added to GTK JTAG project                        !
!     15.Oct.2005  JH     statusbox is modal and transient                 !
!     19.Oct.2005  JH     set widget pointer to NULL after destroying      !
!     27.Oct.2006  JH     dummy callback function as static                !
!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!--!-*/

#include <gtk/gtk.h>         /* GTK stuff */

#include "gtk_statusbox.h"


/******************************  Defines  *********************************/
#define debug(x)  /* g_print x */

/**************************  Private Functions  ***************************/
static void dummy (GtkWidget *widget, gpointer data) {}

/*************************  Function Prototypes  **************************/

/******************************  Globals  *********************************/
static GtkWidget *progressbar;    /* the progress bar object              */


/* gtk_status_box */
/**************************************************************************/
GtkWidget *gtk_status_box (  /* the user callable status_box() function   */
GtkWidget *parent, /* the parent window */ char *title, /* the title of the status box */ char *text, /* the text to be displayed in the status box*/ unsigned has_progressbar) /* whether to create a progress bar */
/***************************************************************************
* globals     : progressbar                                                *
* called from :                                                            *
* calls       :                                                            *
*                                                                          *
* Function                                                                 *
* --------                                                                 *
* This is the Status Box object main function.                             *
*                                                                          *
* Returns                                                                  *
* -------                                                                  *
* index of clicked button                                                  *
***************************************************************************/
{
  GtkWidget *window;
  GtkWidget *label;
  GtkWidget *overall_box;
  GtkAdjustment *adj;

  /* create the status box */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  /* we want it to be a modal window */
  gtk_window_set_modal (GTK_WINDOW(window), TRUE);
  /* ... and it should be on top of our main window */
  gtk_window_set_transient_for (GTK_WINDOW(window), GTK_WINDOW(parent));
g_signal_connect (G_OBJECT(window),"delete_event",G_CALLBACK(dummy),NULL);
  gtk_window_set_title (GTK_WINDOW (window), title);
  gtk_container_set_border_width (GTK_CONTAINER (window), 20);
  debug (("gtk_status_box() 1: window=0x%8.8x\n", (unsigned)window));

  overall_box = gtk_vbox_new (FALSE, 10);
  gtk_container_add (GTK_CONTAINER (window), overall_box);
  gtk_container_border_width (GTK_CONTAINER (window), 10);

  /* put the text */
  label = gtk_label_new (text);
//  gtk_label_set_justify (GTK_LABEL(label), jtype);
  gtk_box_pack_start (GTK_BOX (overall_box), label, TRUE, FALSE, 0);
  debug (("gtk_status_box() 2: label=0x%8.8x\n", (unsigned)label));

  /* create the progress bar */
  if (has_progressbar)
  {
    adj = (GtkAdjustment *)gtk_adjustment_new (0, 0, 100, 0, 0, 0);
    progressbar = gtk_progress_bar_new_with_adjustment (adj);
gtk_progress_set_format_string (GTK_PROGRESS (progressbar), "%p%%");
    gtk_progress_set_show_text (GTK_PROGRESS (progressbar), 1);
    gtk_box_pack_start (GTK_BOX (overall_box), progressbar, TRUE, TRUE, 0);
    debug (("gtk_status_box() 3: bar=0x%8.8x\n", (unsigned)progressbar));
  } else
    progressbar = NULL;

  gtk_window_set_modal (GTK_WINDOW (window), TRUE);

gtk_window_set_position (GTK_WINDOW(window),GTK_WIN_POS_CENTER_ON_PARENT);

  gtk_widget_show_all (window);

  return window;
}

/* gtk_status_box_destroy */
/**************************************************************************/
void gtk_status_box_destroy( /* destroy the status box                    */
GtkWidget *widget) /* the widget to destroy */
/***************************************************************************
* globals     : progressbar                                                *
* called from : callback function                                          *
* calls       :                                                            *
*                                                                          *
* Function                                                                 *
* --------                                                                 *
* Destroy the specified widget.                                            *
*                                                                          *
* Returns                                                                  *
* -------                                                                  *
* void                                                                     *
***************************************************************************/
{
debug (("gtk_status_box_destroy() 1: widget=0x%8.8x\n", (unsigned)widget));

  if (progressbar)
  {
    gtk_widget_destroy (GTK_WIDGET(progressbar));
    progressbar = NULL;
  }

  gtk_widget_destroy (GTK_WIDGET(widget));
  widget = NULL;
}

/* gtk_status_box_set_value */
/**************************************************************************/
void gtk_status_box_set_value (   /* set a new value for the progress bar */
GtkWidget *statusbox, /* parent of the progress bar */ int val) /* new value */
/***************************************************************************
* globals     : progressbar                                                *
* called from :                                                            *
* calls       :                                                            *
*                                                                          *
* Function                                                                 *
* --------                                                                 *
* Set a new value to the progress bar, if any.                             *
*                                                                          *
* Returns                                                                  *
* -------                                                                  *
* void                                                                     *
***************************************************************************/
{
  gtk_progress_set_value (GTK_PROGRESS (progressbar), val);
}

/* gtk_status_box_get_value */
/**************************************************************************/
int gtk_status_box_get_value (    /* get the curr. val of the progress bar*/
GtkWidget *statusbox) /* parent of the progress bar */
/***************************************************************************
* globals     : progressbar                                                *
* called from :                                                            *
* calls       :                                                            *
*                                                                          *
* Function                                                                 *
* --------                                                                 *
* Set a new value to the progress bar, if any.                             *
*                                                                          *
* Returns                                                                  *
* -------                                                                  *
* void                                                                     *
***************************************************************************/
{
  return gtk_progress_get_value (GTK_PROGRESS (progressbar));
}

/* gtk_status_box_has_progressbar */
/**************************************************************************/
int gtk_status_box_has_progressbar (   /* check for progress bar          */
GtkWidget *statusbox) /* the status box */
/***************************************************************************
* globals     : progressbar                                                *
* called from :                                                            *
* calls       :                                                            *
*                                                                          *
* Function                                                                 *
* --------                                                                 *
* Check whether the status box object has a progress bar attached to.      *
*                                                                          *
* Returns                                                                  *
* -------                                                                  *
* 0 .. no                                                                  *
* 1 .. yes                                                                 *
***************************************************************************/
{
  return progressbar ? 1 : 0;
}
8< -------------------------------------------------------------- >8

8< --------------------------- Makefile ------------------------- >8
# compiler
CFLAGS = -pipe `pkg-config --cflags gtk+-2.0` -Wall -g2 -O0 -D "RELEASE_VERSION"

# linker
LDFLAGS=-s -pipe `pkg-config --libs gtk+-2.0`
LINK=$(LD) $(LIB_DIRS) $(LIBS) $(LDFLAGS)

TARGET = gtk_test

OBJ_DIR = obj

OBJECTS = $(OBJ_DIR)/main.o $(OBJ_DIR)/gtk_statusbox.o

$(TARGET): $(OBJECTS)
        $(CC) -o $(TARGET) $(OBJECTS) $(LIB_DIRS) $(LIBS) $(LDFLAGS)


# object file dependencies
$(OBJ_DIR)/main.o: main.c gtk_statusbox.h
        $(CC) $(CFLAGS) $(INCLUDE) -c main.c -o $(OBJ_DIR)/main.o

$(OBJ_DIR)/gtk_statusbox.o: gtk_statusbox.c gtk_statusbox.h
        $(CC) $(CFLAGS) $(INCLUDE) -c gtk_statusbox.c -o $(OBJ_DIR)/gtk_statusbox.o

clean:
        @rm -f $(TARGET) $(OBJ_DIR)/*.o

8< -------------------------------------------------------------- >8

8< ------------------------- Makefile.w32 ----------------------- >8
# compiler
CC="$(MINGW)/bin/gcc.exe"
INCLUDE=-I $(GTK2_DEV)/Include/glib-2.0 -I $(GTK2_DEV)/Include/glib-2.0/include -I $(GTK2_DEV)/Include/gtk-2.0 -I $(GTK2_DEV)/Include/pango-1.0 -I $(GTK2_DEV)/Include/gtk-2.0/include -I $(GTK2_DEV)/Include/atk-1.0
CFLAGS=-D "WIN32" -mms-bitfields -D "RELEASE_VERSION"

# linker
LD="$(MINGW)/bin/gcc.exe"
LIB_DIRS=-L$(MINGW)/lib -L$(GTK2_DEV)/Lib
LIBS=-lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lpangowin32-1.0 -lgdi32 -lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lintl -lcomdlg32
LDFLAGS=-s -mwindows
LINK=$(LD) $(LIB_DIRS) $(LIBS) $(LDFLAGS)


TARGET = gtk_test.exe

OBJ_DIR = obj

OBJECTS = $(OBJ_DIR)/main.o $(OBJ_DIR)/gtk_statusbox.o

$(TARGET): $(OBJECTS)
        $(CC) -o $(TARGET) $(OBJECTS) $(LIB_DIRS) $(LIBS) $(LDFLAGS)


# object file dependencies
$(OBJ_DIR)/main.o: main.c gtk_statusbox.h
        $(CC) $(CFLAGS) $(INCLUDE) -c main.c -o $(OBJ_DIR)/main.o

$(OBJ_DIR)/gtk_statusbox.o: gtk_statusbox.c gtk_statusbox.h
        $(CC) $(CFLAGS) $(INCLUDE) -c gtk_statusbox.c -o $(OBJ_DIR)/gtk_statusbox.o

clean:
        @if exist $(OBJ_DIR)\*.o del $(OBJ_DIR)\*.o
        @if exist $(TARGET)      del $(TARGET)

8< -------------------------------------------------------------- >8





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