I wrote a code for listbox in gtk problems 1. the contents of listbox are shown in middle of horizontal line. I want it to be left aligned. 2. the listbox does not fit the window size 3.the list box is within a notebook tab. I want when the item in the listbox is selected some processing to be done(some function called), the current tab display is hidden and new tab is displayed with the results and a back button. When Back button is pressed it does 2 cases for 2 tabs in 1 tab- it just shows the previous content in tab 2- it does processing again and shows results in list box in original format.
my code is as follows
#include <gtk/gtk.h>
#include <glib.h>
#include <stdlib.h>
static void destroy(GtkWidget *widget, gpointer data)
{
gtk_main_quit();
}
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL);
GtkWidget *notebook = gtk_notebook_new();
gtk_container_add(GTK_CONTAINER(window), notebook);
int count;
int i;
gchar *text;
for (count = 1; count <= 5; count++)
{
GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
text = g_strdup_printf("Page %d", count);
GtkWidget *label = gtk_label_new(text);
GtkWidget *scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(vbox), scrolledwindow);
//GtkWidget *textview = gtk_text_view_new();
GtkWidget *listbox = gtk_list_box_new();
for (i=1; i<100; i++)
{
gchar *name = g_strdup_printf("Label %i", i);
GtkWidget *label = gtk_label_new(name);
gtk_container_add(GTK_CONTAINER(listbox), label);
}
gtk_container_add(GTK_CONTAINER(scrolledwindow), listbox);
gtk_container_add(GTK_CONTAINER(vbox), scrolledwindow);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, label);
}
gtk_widget_show_all(window);
gtk_main();
return 0;
}