i would like to change the image that are into the button with the callback cb_menu , i have try something but that's doesn't works
thank you in advance
Code:
/* maogtk.c
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <unistd.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <stdio.h>
#include "importimage.h"
struct Data_s
{
int sort;
char **ptr;
GtkWidget *images[12];
GtkWidget *buttons[12];
GtkWidget *table;
};
typedef struct Data_s Data;
static void
cb_menu (GtkWidget * widget, Data * data)
{
/*Here my Problem*/
gtk_widget_destroy(data->buttons[0]);
data->buttons[0] = gtk_button_new();
gtk_table_attach_defaults(GTK_TABLE(data->table),data->buttons[0],0,1,0,1);
gtk_widget_show(data->table);
}
static void
quit (GtkWidget * w)
{
gtk_main_quit ();
}
int
main (int argc, char *argv[])
{
int i;
int j;
GtkWidget *window;
GtkWidget *sort_p;
GtkWidget *sort_d;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *b_previously;
GtkWidget *b_quit;
GtkWidget *opt;
GtkWidget *separator;
GtkWidget *b_next;
char filename[17];
GtkWidget *menu1;
Data *data = NULL;
gtk_init (&argc, &argv);
data = malloc (sizeof (*data));
VER_NULL (data);
data->ptr = NULL;
data->sort = SORT_POPULARITY;
vbox = gtk_vbox_new (FALSE, 0);
VER_NULL (vbox);
menu1 = gtk_menu_new ();
VER_NULL (menu1);
separator = gtk_hseparator_new ();
VER_NULL (separator);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
VER_NULL (window);
opt = gtk_option_menu_new ();
VER_NULL (opt);
b_quit = gtk_button_new_with_label ("Quit");
VER_NULL (b_quit);
hbox = gtk_hbox_new (TRUE, 0);
VER_NULL (hbox);
data->table = gtk_table_new (3, 4, TRUE);
VER_NULL (data->table);
b_next = gtk_button_new_with_label ("Next");
VER_NULL (b_next);
b_previously = gtk_button_new_with_label ("Previously");
VER_NULL (b_previously);
sort_d = gtk_menu_item_new_with_label ("Date");
VER_NULL (sort_d);
sort_p = gtk_menu_item_new_with_label ("Popularity");
VER_NULL (sort_p);
for (i = 0; i < 12; i++)
{
data->buttons[i] = gtk_button_new ();
VER_NULL (data->buttons[i]);
}
for (i = 0; i < 12; i++)
{
sprintf (filename, "/tmp/image%d.png", i);
data->images[i] = gtk_image_new_from_file (filename);
VER_NULL (data->images[i]);
}
for (i = 0; i < 4; i++)
{
for (j = 0; j < 3; j++)
{
gtk_table_attach_defaults (GTK_TABLE (data->table),
data->buttons[3 * i + j], j, j + 1, i,
i + 1);
}
}
for (i = 0; i < 12; i++)
{
gtk_container_add (GTK_CONTAINER (data->buttons[i]), data->images[i]);
}
gtk_menu_shell_append (GTK_MENU_SHELL (menu1), sort_d);
gtk_menu_shell_append (GTK_MENU_SHELL (menu1), sort_p);
gtk_option_menu_set_menu (GTK_OPTION_MENU (opt), menu1);
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER_ALWAYS);
gtk_window_set_title (GTK_WINDOW (window), "ImportImage");
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_box_pack_start (GTK_BOX (vbox), data->table, TRUE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), separator, TRUE, FALSE, 20);
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), b_quit, TRUE, TRUE, 10);
gtk_box_pack_start (GTK_BOX (hbox), opt, TRUE, FALSE, 10);
gtk_box_pack_start (GTK_BOX (hbox), b_previously, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), b_next, TRUE, TRUE, 0);
g_signal_connect (G_OBJECT (b_quit), "clicked", G_CALLBACK (quit), NULL);
g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (quit), NULL);
g_signal_connect (G_OBJECT (sort_d), "activate", G_CALLBACK (cb_menu),
(gpointer) data);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}