clist problem





Havoc Pennington wrote:
> 
> On Wed, 15 Sep 1999, Hal Greenwald wrote:
> >     I'm using gtk_clist_append with a 3 column clist.
> > On occasion, a data element in the clist does not get displayed.
> 
> Can you post a small program that demonstrates the problem?
> 
> Havoc
> 
 Hi,

 3 problems:
   1) clist output appears to be buffered. 
   2) gtk_clist_moveto isn't working.
   3) cell contents sometimes "blanks" out.

 Can someone please tell me what I'm doing wrong?
 Thanks,
 Hal


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

gchar *buf_ptr[100][2];
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *scrolled_window, *clist;
GtkWidget *button_start;    
gchar *titles[2] = { "Message one","Message two" };


void clist_proc()
{
  char *buffer1;
  char *buffer2;
  static int count=0;
  
  while(count < 100) {
        buffer1 = calloc(50,1);
        buffer2 = calloc(50,1);

        printf("\nEnter message 1 ->");
        scanf("%s",buffer1);

        printf("\nEnter message 2 ->");
        scanf("%s",buffer2);

        buf_ptr[count][0] = buffer1;
        buf_ptr[count][1] = buffer2;

        gtk_clist_append( (GtkCList *) clist, buf_ptr[count]);
        gtk_clist_moveto( (GtkCList *) clist, count,0,1.0,1.0);

        count++;
  }
}





int main( int    argc,
          gchar *argv[] )
{                                  

        gtk_init(&argc, &argv);
        
        window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_signal_connect(GTK_OBJECT(window),
                           "destroy",
                           GTK_SIGNAL_FUNC(gtk_main_quit),
                           NULL);

        gtk_widget_set_usize(GTK_WIDGET(window), 300, 500);
        
        vbox=gtk_vbox_new(FALSE, 5);

        gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
        gtk_container_add(GTK_CONTAINER(window), vbox);

        
        button_start = gtk_button_new_with_label("Start");
        gtk_box_pack_start(GTK_BOX(vbox), button_start, TRUE, TRUE, 0);
        gtk_signal_connect_object(GTK_OBJECT(button_start), "clicked",
                                  GTK_SIGNAL_FUNC(clist_proc),
                                  (gpointer) NULL);


        /* Create a scrolled window to pack the CList widget into */
        scrolled_window = gtk_scrolled_window_new (NULL, NULL);
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW
(scrolled_window),
                                        GTK_POLICY_ALWAYS,
GTK_POLICY_ALWAYS);

        gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE,
0);

        clist = gtk_clist_new_with_titles( 2, titles);

        gtk_clist_set_column_width (GTK_CLIST(clist), 0, 150);
        gtk_clist_set_column_width (GTK_CLIST(clist), 1, 150);

        gtk_container_add(GTK_CONTAINER(scrolled_window), clist);

        gtk_widget_show(button_start); 
        gtk_widget_show(clist);
        gtk_widget_show (scrolled_window);
        gtk_widget_show(vbox);
        gtk_widget_show(window);

        gtk_main();

        return(0);
}
    /* example-end */



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