Thanks and another Problem!
- From: "Nicolas Raitman" <new_world radar com ar>
- To: "gtk app" <gtk-app-devel-list gnome org>
- Subject: Thanks and another Problem!
- Date: Sun, 19 Nov 2000 20:38:06 -0300
In the first place thanks to all cause I could solve the problem... but
wait... guess what... I have another!!
I am doing an app (just to learn) in which I am using a ListBox. In the
first place I read that this widget has been upgraded for the CList, is that
true? In the second place, I am having a trouble with it, the ListBox. Look
at the following code, it all works fine except one thing: when I keep on
adding items to the ListBox it gets so big that I cannot see it anymore...
is there a way to put scroll bars to it?? If not, shall I use the CList
widget??
I added all the code just in case... I think you do not need to look at it,
just tell me how to solve the problem of adding scroll bars to the listbox.
Thanks a lot,
Nicolas
Code:
*******
#include <gtk/gtk.h>
struct objetos
{
GtkWidget * window;
GtkWidget * table;
GtkWidget * hbox;
GtkWidget * listbox;
GtkWidget * button;
GtkWidget * nombre;
GtkWidget * label;
};
gint destroyapp(void)
{
gtk_main_quit();
return(FALSE);
}
GtkWidget * CreateWindow(GtkWidget * window, char * title)
{
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), title);
gtk_container_border_width(GTK_CONTAINER(window), 10);
gtk_signal_connect(GTK_OBJECT(window), "delete_event",
GTK_SIGNAL_FUNC(destroyapp), NULL);
return window;
}
GtkWidget * CreateTable(GtkWidget * table, int filas, int columnas)
{
table = gtk_table_new(filas, columnas, TRUE);
return table;
}
GtkWidget * CreateHBox(GtkWidget * hbox, int spacing)
{
hbox = gtk_hbox_new(FALSE, spacing);
return hbox;
}
void AddHBoxToTable(GtkWidget * table, GtkWidget * hbox, int left, int
right, int top, int bottom)
{
gtk_table_attach(GTK_TABLE(table), hbox, left, right, top, bottom,
GTK_FILL, GTK_FILL, 5, 5);
}
GtkWidget * CreateButton(GtkWidget * button, char * label)
{
button = gtk_button_new_with_label(label);
return button;
}
GtkWidget * CreateListBox(GtkWidget * listbox, int selmult)
{
listbox = gtk_list_new();
if (selmult)
gtk_list_set_selection_mode(GTK_LIST(listbox), GTK_SELECTION_MULTIPLE);
return listbox;
}
void AddItemToListBox(GtkWidget * listbox, char * text)
{
GtkWidget * item;
item = gtk_list_item_new_with_label(text);
gtk_container_add(GTK_CONTAINER(listbox), item);
gtk_widget_show(item);
}
void AddWidgetToHBox(GtkWidget * hbox, GtkWidget * widget)
{
gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 5);
gtk_widget_show(widget);
}
GtkWidget * CreateEntry(GtkWidget * entry)
{
entry = gtk_entry_new();
return entry;
}
void agregar(GtkButton * button, struct objetos * widget)
{
char * nombre;
nombre = gtk_entry_get_text(GTK_ENTRY(widget->nombre));
AddItemToListBox(widget->listbox, nombre);
}
int main (int argc, char * argv [])
{
struct objetos * widget;
gtk_init(&argc, &argv);
widget = (struct objetos *) malloc (sizeof(struct objetos));
widget->window = CreateWindow(widget->window, "ListBox");
widget->table = CreateTable(widget->table, 5, 5);
widget->hbox = CreateHBox(widget->hbox, 5);
AddHBoxToTable(widget->table, widget->hbox, 0, 4, 0, 1);
gtk_widget_show(widget->hbox);
widget->label = gtk_label_new("Elija Un Nombre");
AddWidgetToHBox(widget->hbox, widget->label);
widget->listbox = CreateListBox(widget->listbox, 0);
AddItemToListBox(widget->listbox, "Nicolas");
AddItemToListBox(widget->listbox, "Alan");
AddWidgetToHBox(widget->hbox, widget->listbox);
widget->hbox = CreateHBox(widget->hbox, 10);
AddHBoxToTable(widget->table, widget->hbox, 0, 4, 2, 3);
gtk_widget_show(widget->hbox);
widget->label = gtk_label_new("Ingrese El Nuevo Nombre");
AddWidgetToHBox(widget->hbox, widget->label);
widget->nombre = CreateEntry(widget->nombre);
AddWidgetToHBox(widget->hbox, widget->nombre);
widget->button = CreateButton(widget->button, "Agregar");
gtk_signal_connect(GTK_OBJECT(widget->button), "clicked",
GTK_SIGNAL_FUNC(agregar), widget);
AddWidgetToHBox(widget->hbox, widget->button);
gtk_container_add(GTK_CONTAINER(widget->window), widget->table);
gtk_widget_show(widget->table);
gtk_widget_show(widget->window);
gtk_main();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]