problem with clist and option menu



Hi,

I have found a bug in clist.
I am using a clist widget to display a circular list of message.
When a new message need to be display at the end of the list, and,if the
size of the list is to big, i'm removing the first message. After i'm
forcing clist to display the last message.

But I have found, that if you remove a row at the start of the clist,
and immediatly, you add a row at the end, it seems that there is a
problem with adjustment. The gtk_clist_moveto don't show the row as
expected.

I've made a sample program to show the problem.

I've modify adjust_adjustments in gtk_clist to solve my problem

     if (clist->clist_window_height - clist->voffset != LIST_HEIGHT (clist))
by

     if (clist->clist_window_height - clist->voffset > LIST_HEIGHT (clist))

But i'm not sure that is the good solution.

For the option menu widget, i've a problem with
gtk_widget_set_sensitive.

If i'm making the widget unsensitive, and i change the history of the
widget, when i'm making widget sensitive, some item in menu don't get
their sensitive state.

I've made a sample too.

Bye
-- 
-----------------------------------------------------------------------
    _/ _/_/  _/  _/_/   _/_/_/ _/_/_/ Bolliet Jerome
   _/ _/ _/ _/ _/  _/   /  _/     _/  email: bolliet@in2p3.fr
  _/ _/  _/_/    _/   _/_/_/   _/_/   
 _/ _/    _/   _/    _/         _/    Equipe Administration Systeme
_/ _/    _/  _/_/_/ _/     _/_/_/     email: sysunix@in2p3.fr
Centre de Calcul - Campus de la Doua
  27 boulevard du 11 novembre 1918    Tel.: 04 78 93 08 80
   69622 - VILLEURBANNE - FRANCE      Fax.: 04 72 69 41 70
-----------------------------------------------------------------------
/* gcc -o t testclist.c `gtk-config --cflags` `gtk-config --libs` */

#include <gtk/gtk.h>

GtkWidget* window;
GtkWidget* vbox;
GtkWidget* hbox;
GtkWidget* scrolled_window;
GtkWidget* clist;
GtkWidget* button;
gint k = 0;

void
cb_add (GtkWidget* w) {
  gint i;
  gchar text[256];
  gchar* ptext = &text[0];

  for(i = 0; i< 10; i++)
    {
      k++;
      sprintf(text, "test %d", k);
      gtk_clist_append(GTK_CLIST(clist), &ptext);

      if(GTK_CLIST(clist)->rows > 20)
	gtk_clist_remove(GTK_CLIST(clist), 0);
    }

  gtk_clist_moveto(GTK_CLIST(clist), GTK_CLIST(clist)->rows-1, 0, 1.0, 0.0);
}

int
main(gint argc, gchar** argv) {
  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(window), "Test CLIST");
  gtk_signal_connect(GTK_OBJECT(window), "delete_event", 
		     gtk_main_quit,
		     NULL);

  vbox = gtk_vbox_new(FALSE, 0);
  gtk_container_add(GTK_CONTAINER(window), vbox);
  
  hbox = gtk_hbox_new(FALSE, 0);
  gtk_box_pack_start(GTK_BOX(vbox), hbox, 0, 1, 0);

  button = gtk_button_new_with_label("Add");
  gtk_box_pack_start(GTK_BOX(hbox), button, 0, 1, 0);
  gtk_signal_connect(GTK_OBJECT(button), "clicked", 
		     cb_add,
		     NULL);

  button = gtk_button_new_with_label("Quit");
  gtk_box_pack_start(GTK_BOX(hbox), button, 0, 1, 0);
  gtk_signal_connect(GTK_OBJECT(button), "clicked", 
		     gtk_main_quit,
		     NULL);

  scrolled_window = gtk_scrolled_window_new(NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
                                  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, 1, 1, 0);
  
  clist = gtk_clist_new(1);
  gtk_container_add(GTK_CONTAINER(scrolled_window), clist);

  gtk_widget_show_all(window);

  gtk_main();
  
  return 0;
}
#include <gtk/gtk.h>

GtkWidget* omenu, *menu;
gint sensitive = TRUE;

void cb (GtkWidget* w)
{
  sensitive = !sensitive;
  gtk_widget_set_sensitive(omenu, sensitive);
}

void cb2 (GtkWidget* w)
{
  gtk_option_menu_set_history(omenu, 2);
}

gint
main(gint argc, gchar** argv)
{
  GtkWidget* window;
  GtkWidget* box;
  GtkWidget* button;
  GtkWidget *menuitem;
  gint i;
  gchar tmp[20];
  GSList* group = NULL;

  gtk_init(&argc, &argv);
  
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_signal_connect(GTK_OBJECT(window), "delete_event", gtk_main_quit, NULL);
  
  box = gtk_vbox_new(FALSE, 0);
  gtk_container_add(window, box);
  gtk_widget_show(box);

  omenu = gtk_option_menu_new();
  gtk_box_pack_start(GTK_BOX(box), omenu, FALSE, TRUE, 0);

  menu = gtk_menu_new();
  for(i = 0; i<5; i++)
    {
      sprintf(tmp, "test %d", i);
      menuitem = gtk_radio_menu_item_new_with_label(group, tmp);
      gtk_menu_append(menu, menuitem);
      gtk_widget_show(menuitem);

     group = gtk_radio_menu_item_group(menuitem);
    }

  gtk_option_menu_set_menu(omenu, menu);
  gtk_widget_show(omenu);

  button = gtk_button_new_with_label("set sensitive");  
  gtk_box_pack_start(GTK_BOX(box), button, FALSE, TRUE, 0);
  gtk_signal_connect(GTK_OBJECT(button), "clicked", cb, NULL);
  gtk_widget_show(button);

  button = gtk_button_new_with_label("set history to 2");  
  gtk_box_pack_start(GTK_BOX(box), button, FALSE, TRUE, 0);
  gtk_signal_connect(GTK_OBJECT(button), "clicked", cb2, NULL);
  gtk_widget_show(button);

  gtk_widget_show(window);

  gtk_main();

  return 0;
}



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