Re: Problems with gtk_menu_popup
- From: Santhosh <santhosh lists gmail com>
- To: Boromir <okossuth devel gmail com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Problems with gtk_menu_popup
- Date: Sat, 26 Mar 2005 19:14:00 +0530
Hi Boromir,
The "GtkVBox" widget will not receive any events .. So you need to
pack a event box inside the GtkVBox...
The following piece of code do the job for u..
#include<gtk/gtk.h>
#include"unistd.h"
#include"sys/types.h"
#include"sys/wait.h"
int end_program(GtkWidget *widget,gpointer data)
{
gtk_main_quit();
return 0;
}
int startsw(GtkWidget *widget,gpointer data)
{
pid_t pid;
if((pid= fork()) < 0)
printf("Fork Error!");
else if(pid == 0)
{
if(execl("/usr/bin/gaim",NULL)==-1) {
printf("child exec failed");
}
exit(127);
}
return 0;
}
static int menuitem_resp(GtkWidget *widget,GdkEvent *event)
{
if (event->type == GDK_BUTTON_PRESS) {
GdkEventButton *bevent = (GdkEventButton *) event;
gtk_menu_popup (GTK_MENU (widget), NULL, NULL,
NULL, NULL,
bevent->button, bevent->time);
return TRUE;
}
return FALSE;
}
static void resp(gchar *string)
{
printf("%s\n",string);
}
int main(int argc,char *argv[])
{
char buf[128];
GtkWidget *menu_items;
GtkWidget *window;
GtkWidget *button;
GtkWidget *vbox;
GtkWidget *menu;
GtkWidget *root_menu;
GtkWidget* ev_box; /* added */
int i=0;
gtk_init(&argc,&argv);
window =
g_object_new(GTK_TYPE_WINDOW,"default-height",100,"default-width",500,"border-width",12,"title","DashBoard",NULL);
g_signal_connect(window,"destroy",G_CALLBACK(end_program),NULL);
menu = gtk_menu_new();
for(i=0;i<3; ++i)
{
sprintf (buf, "Test-undermenu - %d", i);
menu_items = gtk_menu_item_new_with_label (buf);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
g_signal_connect_swapped (G_OBJECT (menu_items),
"activate",G_CALLBACK (resp),(gpointer) g_strdup(buf));
gtk_widget_show (menu_items);
}
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_widget_show (vbox);
/* create event box and pack it in vbox */
ev_box = gtk_event_box_new ();
gtk_container_add (GTK_CONTAINER (vbox), ev_box);
gtk_widget_show_all (GTK_WIDGET (vbox));
/* connect the "event" to the EventBox Widget */
g_signal_connect_swapped(G_OBJECT(ev_box),"event",G_CALLBACK(menuitem_resp),G_OBJECT(menu));
gtk_widget_show_all(GTK_WIDGET(window));
gtk_main();
return 0;
}
Santhosh.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]