opening modal windows from the "button-press-event" handler forclist
- From: Vlad Harchev <hvv hippo ru>
- To: gtk-list redhat com
- Subject: opening modal windows from the "button-press-event" handler forclist
- Date: Mon, 14 Feb 2000 22:03:19 +0400 (SAMT)
Hello, list!
Here is problem I have. I need to handle right clicks in clist (right
click is used as "marking" in my app - "marked" items change color). It's
disallowed to mark some items in the clist in my app so I want to pop up a
modal error window when user tries to mark such items. But with
straightforward implementation, just creating modal window freezes X server
(if this code is executed from console, it's possible to kill this app -
beware!). A stripped down code I use is at the end of the message.
How this problem could be avoided?
I use stock RH6.0's gtk+1.2.1-10 on x86 box. I use XF86_S3 from RH6.0.
Thanks in advance.
Best regards,
-Vlad
---------------------------
#include <string.h>
#include <stdio.h>
#include <gtk/gtk.h>
/*this function works fine when not called from handler 'button-press-even' of
clist, and freezes X server otherwise. */
void error_message(const char* title,const char* text)
{
GtkWidget *dialog;
GtkWidget *button,*hb,*l;
char* str;
dialog = gtk_dialog_new();
gtk_window_set_title (GTK_WINDOW (dialog), title);
l = gtk_label_new(text);
hb = gtk_hbox_new(1,0);
gtk_box_pack_start (GTK_BOX (hb), l, TRUE, TRUE, 43);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
hb, TRUE, TRUE, 0);
button = gtk_button_new_with_label("OK");
gtk_signal_connect_object(GTK_OBJECT(button),"clicked",
GTK_SIGNAL_FUNC(gtk_main_quit),GTK_OBJECT(dialog));
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
button, TRUE, TRUE, 0);
gtk_window_set_modal (GTK_WINDOW(dialog),TRUE);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_widget_grab_default (button);
gtk_widget_show_all(dialog);
gtk_main();
gtk_window_set_modal (GTK_WINDOW(dialog),0);
gtk_widget_destroy(dialog);
};
void sig_select_row(GtkWidget *w,GdkEventButton *e)
{
gdk_event_free(e);/*removing this call won't help*/
error_message("Hello","Hello, world");
};
int main(int argc,char** argv)
{
GtkWidget *window,*l;
char* str = "FOO";
int i;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
l = gtk_clist_new(1);
for(i=0;i<10;++i)
gtk_clist_append(GTK_CLIST(l),&str);
gtk_signal_connect_after(GTK_OBJECT(l),"button-press-event",
GTK_SIGNAL_FUNC(sig_select_row),NULL);
gtk_container_add(GTK_CONTAINER(window),l);
gtk_widget_show_all(window);
gtk_main ();
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]