Re: widgets dont appear, due to "event"
- From: Saquib Malik <saquibfarooq yahoo com>
- To: gtk-list gnome org
- Subject: Re: widgets dont appear, due to "event"
- Date: Fri, 12 Jul 2002 02:56:51 -0700 (PDT)
/* the followin is the complete file that takes care
of the visual stuff
* i've kept the menu and menu items global, i did look
at the handlers and they
* do return true but i cant understand that how does
exapanding and compressing
* make them visible again.
* plz do tell me of any other bugs if you find them
and thanx again for your help :) */
#include "gtk/gtk.h"
int handle(GtkWidget * , GdkEvent *);
void mess( GtkWidget *, gpointer);
void initialize(GtkWidget *);
int drop(GtkWidget * , GdkEvent *);
int del_eve(GtkWidget * , gpointer);
GtkWidget * menu, *menu2;
GtkWidget * menu_item, *menu_item2;
char nodes[10][10];
char temp='o';
main(int argc, char **argv)
{
GtkWidget * win;
GtkWidget * button[10][10], * qbutton;
GtkWidget * table;
char label[6];
char name[2];
int i,j;
win = NULL;
gtk_init(&argc, &argv);
while(1){
initialize(win);
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
//gtk_widget_set_usize(GTK_WIDGET(win), 500, 500);
//gtk_signal_connect ( GTK_OBJECT(win),
"delete_event", GTK_SIGNAL_FUNC(del_eve), NULL);
table = gtk_table_new( 11 ,10 , TRUE);
//labe = gtk_label_new("hello");
name[1]='\0';
for(i=0;i<10;i++)
for(j=0; j <10 ; j++)
{
sprintf(label,"%d_%d",i,j);
//text = gtk_text_new ( NULL, NULL);
//gtk_text_set_editable(GTK_TEXT(text), FALSE);
//gtk_text_insert (GTK_TEXT (text),
NULL, &color, NULL,label , -1);
if( nodes[i][j]=='o')
{
button[i][j] = gtk_button_new();
//gtk_signal_connect(GTK_OBJECT(button[i][j]),
"event", GTK_SIGNAL_FUNC(drop), NULL);
//gtk_signal_connect(GTK_OBJECT(button),
(GdkEventButton)"clicked", GTK_SIGNAL_FUNC(drop),
(gpointer) name);
}
else
{
name[0]=nodes[i][j];
button[i][j] = gtk_button_new_with_label(name);
//gtk_signal_connect(GTK_OBJECT(button[i][j]),
"event", GTK_SIGNAL_FUNC(handle), NULL);
//gtk_signal_connect(GTK_OBJECT(button),
(GdkEventButton)"clicked", GTK_SIGNAL_FUNC(drop),
(gpointer) name);
}
//gtk_widget_set_usize(text, 70,20);
//gtk_container_add(GTK_CONTAINER(button),
text);
gtk_widget_set_usize(GTK_WIDGET(button[i][j]), 20,20);
gtk_widget_set_name(button[i][j], label);
gtk_table_attach_defaults(GTK_TABLE(table),
button[i][j], j,j+1,i,i+1);
//gtk_widget_show(text);
gtk_widget_show(button[i][j]);
}
qbutton = gtk_button_new_with_label("Quit");
gtk_container_add(GTK_CONTAINER(win), table);
gtk_signal_connect(GTK_OBJECT(qbutton), "clicked",
GTK_SIGNAL_FUNC(del_eve),(GtkWidget *) win);
gtk_table_attach_defaults(GTK_TABLE(table), qbutton,
0,10,10,11);
gtk_widget_show(qbutton);
gtk_widget_show(table);
gtk_widget_show_all(win);
for(i=0;i<10;i++)
for(j=0; j <10 ; j++)
{
sprintf(label,"%d_%d",i,j);
//text = gtk_text_new ( NULL, NULL);
//gtk_text_set_editable(GTK_TEXT(text), FALSE);
//gtk_text_insert (GTK_TEXT (text),
NULL, &color, NULL,label , -1);
if( nodes[i][j]=='o')
{
gtk_signal_connect(GTK_OBJECT(button[i][j]),
"event", GTK_SIGNAL_FUNC(drop), NULL);
//gtk_signal_connect(GTK_OBJECT(button),
(GdkEventButton)"clicked", GTK_SIGNAL_FUNC(drop),
(gpointer) name);
}
else
{
gtk_signal_connect(GTK_OBJECT(button[i][j]),
"event", GTK_SIGNAL_FUNC(handle), NULL);
//gtk_signal_connect(GTK_OBJECT(button),
(GdkEventButton)"clicked", GTK_SIGNAL_FUNC(drop),
(gpointer) name);
}
//gtk_widget_set_usize(text, 70,20);
//gtk_container_add(GTK_CONTAINER(button),
text);
}
gtk_main();
}
}
int handle ( GtkWidget * widg, GdkEvent * event)
{
//GtkWidget * menu;
//GtkWidget * menu_item;
GdkEventButton * bevent = (GdkEventButton *) event;
if (event->type == GDK_BUTTON_PRESS)
{
g_print("\n the button was pressed");
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
NULL, NULL, bevent->button, bevent->time);
}
return TRUE;
}
int drop ( GtkWidget * widg, GdkEvent * event)
{
//GtkWidget * menu;
//GtkWidget * menu_item;
GdkEventButton * bevent = (GdkEventButton *) event;
if (event->type == GDK_BUTTON_PRESS)
{
g_print("\n the button was pressed");
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
NULL, NULL, bevent->button, bevent->time);
}
return TRUE;
}
void mess ( GtkWidget * widg, gpointer data)
{
g_print("\n %s", (char*)data);
}
void initialize(GtkWidget * win)
{
/* settig all entries to o;*/
int i;
int j;
for(i=0; i<10 ; i++)
for(j=0; j<10; j++)
nodes[i][j]='o';
/* putting values in locations*/
if(win!=NULL)
gtk_widget_destroy(win);
nodes[1][2]='A';
nodes[2][4]='B';
nodes[1][5]='C';
nodes[3][5]='D';
nodes[2][7]='E';
menu = gtk_menu_new();
menu_item = gtk_menu_item_new_with_label( " option
1");
gtk_signal_connect(GTK_OBJECT(menu_item), "activate",
GTK_SIGNAL_FUNC(mess), (gpointer ) "option 1");
gtk_menu_append(GTK_MENU(menu), menu_item);
gtk_widget_show(menu_item);
gtk_widget_show(menu);
menu2 = gtk_menu_new();
menu_item = gtk_menu_item_new_with_label( " option 2
");
gtk_signal_connect(GTK_OBJECT(menu_item), "activate",
GTK_SIGNAL_FUNC(mess), (gpointer) "option 2");
gtk_menu_append(GTK_MENU(menu2), menu_item);
gtk_widget_show(menu_item);
gtk_widget_show(menu2);
}
int del_eve( GtkWidget * widg, gpointer data)
{
gtk_main_quit();
return (FALSE);
}
__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]