Menu woes.



Hi,

Thankyou for the reply about the toolbar. I will try to implement something just as soon as I get his menu sorted out. I said earlier that I thought I had sorted out the hourglass problem I had on my menu. The hourglass is back! And I did not even recompile my code (?).

Basically, I have written code so that a right click brings up a menu (ala GIMP). The menu has one entry at the moment. When clicked on, that brings up a colour selector dialog. Irritatingly, for the duration of the time that the menu is open, the mouse pointer changes to an hourglass shape.

Briefly, this is what I have done:


I setup the menu in main with:
        mainmenu = gtk_menu_new();
        menuitem = gtk_menu_item_new_with_label("Select Colour");
        gtk_menu_shell_append(GTK_MENU_SHELL(mainmenu), menuitem);
        gtk_widget_show(menuitem);
        gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
                        GTK_SIGNAL_FUNC(menu_select_color), NULL);

The button press callback is set up in main:
        gtk_signal_connect(GTK_OBJECT(darea), "button_press_event",
                        GTK_SIGNAL_FUNC(button_press_event), NULL);


Here is the callback used when the mouse butto nis pressed:
gboolean button_press_event(GtkWidget *widget, GdkEventButton *event) {

        // Draw with the brush if the LH mouse button is pressed
        if (event->button == 1) {
                draw_airbrush(widget, event->x, event->y);
        }

        // Change brush colour with RH mouse button
        if (event->button == 3) {
                // Pop up the main menu
                gtk_menu_popup(GTK_MENU(mainmenu), NULL, NULL, NULL, NULL,
                                        event->button, event->time);
                return TRUE;
        }

        return TRUE;
}


Finally, this code handles the click on the menu item.

gboolean menu_select_color(GtkWidget *widget) {
        GtkColorSelection *colorsel;
        gint response;

        // Get the color selection widget in the dialog
        colorsel=GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorseldlg)->colorsel);

        gtk_color_selection_set_previous_color(colorsel, &color);
        gtk_color_selection_set_current_color(colorsel, &color);
        gtk_color_selection_set_has_palette(colorsel, FALSE);

        // Connect to the "color changed" signal
gtk_signal_connect(GTK_OBJECT(colorsel), "color_changed", GTK_SIGNAL_FUNC(color_changed_cb), (gpointer) colorsel);

        // Show the dialog
        response = gtk_dialog_run(GTK_DIALOG(colorseldlg));

        if (response == GTK_RESPONSE_OK)
                gtk_color_selection_get_current_color(colorsel, &color);

        gtk_widget_hide(colorseldlg);

        return TRUE;
}


I hope someone can help me with this!

Best regards,
Chris.





From: Tristan Van Berkom <vantr touchtunes com>
To: Chris Garrett <garrett91 hotmail com>
CC: gtk-app-devel-list gnome org
Subject: Re: re. hourglass on menu widget
Date: Wed, 13 Nov 2002 11:03:28 -0500

Hmmm,
        You figured out the "hourglass on menu widget" or
you figured out how to move widgets relative to other widgets ?

if not:

1) you'll need the toolbar to have its own GtkWindow parent.

2) you'll need to attach a handler to a signal emited when a
widget "moves"

NOTE:
        you might want to watch out for deadlocks
i.e. you recieve signal --> move another widget --> manual
moving of widget emits a signal --> ...

        -Tristan


_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail




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