Bug in menu sensitivity.



I just noticed some buggy behaviour in the menu code which allows you
to select an insensitive menu item.  Here is a program which
demonstrates the bug.

- Dave

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

static void onSelectMe(GtkMenuItem* menuitem, gpointer userData)
{
    fprintf(stderr, "I am insensitive - you should not be able to select me!\n");
}

static void onDontSelectMe(GtkMenuItem* menuitem, gpointer userData)
{
    fprintf(stderr, "Please follow instructions!\n");
}

int main(int argc, char* argv[])
{
    GtkWidget* top;
    GtkWidget* vbox;
    GtkWidget* menubar;
    GtkWidget* menu;
    GtkWidget* submenu;
    GtkWidget* selectMe;
    GtkWidget* dontSelectMe;
    GtkWidget* quit;
    GtkWidget* label;

    gtk_init(&argc, &argv);

    top = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(top), "Bogus");

    vbox = gtk_vbox_new(FALSE, 0);
    gtk_container_add(GTK_CONTAINER(top), vbox);

    menubar = gtk_menu_bar_new();
    gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);

    menu = gtk_menu_item_new_with_label("Menu");
    gtk_container_add(GTK_CONTAINER(menubar), menu);

    submenu = gtk_menu_new();
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu), submenu);

    selectMe = gtk_menu_item_new_with_label("Select Me");
    gtk_container_add(GTK_CONTAINER(submenu), selectMe);
    gtk_widget_set_sensitive(selectMe, FALSE);
    gtk_signal_connect(GTK_OBJECT(selectMe), "activate",
		       GTK_SIGNAL_FUNC(onSelectMe), NULL);

    dontSelectMe = gtk_menu_item_new_with_label("Don't Select Me");
    gtk_container_add(GTK_CONTAINER(submenu), dontSelectMe);
    gtk_signal_connect(GTK_OBJECT(dontSelectMe), "activate",
		       GTK_SIGNAL_FUNC(onDontSelectMe), NULL);

    quit = gtk_menu_item_new_with_label("Quit");
    gtk_container_add(GTK_CONTAINER(submenu), quit);
    gtk_signal_connect(GTK_OBJECT(quit), "activate",
		       GTK_SIGNAL_FUNC(gtk_main_quit), NULL);

    label = gtk_label_new("Click on Menu and then drag down to \"Select Me\",\nthen release the mouse.  Do not drag past \"Select Me\"\nor the bug will not bite.");
    gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0);
    gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);

    gtk_widget_show_all(top);

    gtk_main();
    return 0;
}



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