72402a2007-10-14Lance Dillon /* -*- C -*- */ require gtk212; class GTK2.ScaleButton; inherit GTK2.Button; //! Properties: //! GTK2.Adjustment adjustment //! string icons //! int size //! float value signal popdown; signal popup; signal value_changed; //! Scale button void create(int|void size_or_props, ?float min, ?float max, ?float step, ?array(string) icons) //! Create a new W(ScaleButton). { pgtk2_verify_not_inited(); pgtk2_verify_setup(); if (args>1) { INT_TYPE size; FLOAT_TYPE min,max,step; struct array *a;
0c50a82010-02-09Lance Dillon  const gchar **icons;
72402a2007-10-14Lance Dillon  int i,j;
0c50a82010-02-09Lance Dillon  GtkWidget *gsb;
72402a2007-10-14Lance Dillon 
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%i%f%f%f%A",&size,&min,&max,&step,&a);
72402a2007-10-14Lance Dillon  if (a==NULL || a->size<1) Pike_error("Invalid array argument 5.\n");
0c50a82010-02-09Lance Dillon  icons=g_new0(const gchar *,a->size+1);
72402a2007-10-14Lance Dillon  for (i=j=0; i<a->size; i++) { icons[j]=g_strdup(CGSTR0((ITEM(a)+i)->u.string)); j++; } icons[j]=NULL; gsb=gtk_scale_button_new(size,min,max,step,icons); THIS->obj=G_OBJECT(gsb); for (i=0; icons[i]; i++)
0c50a82010-02-09Lance Dillon  g_free((gpointer *)icons[i]);
72402a2007-10-14Lance Dillon  g_free(icons); } else { INIT_WITH_PROPS(GTK_TYPE_SCALE_BUTTON); } pgtk2_pop_n_elems(args); pgtk2__init_this_object(); } void set_adjustment(GTK2.Adjustment adj); //! Sets the GTK2.Adjustment to be used as a model. void set_icons(array icons) //! Sets the icons to be used. { struct array *a; int i,j;
0c50a82010-02-09Lance Dillon  const gchar **icons;
72402a2007-10-14Lance Dillon 
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%A",&a);
72402a2007-10-14Lance Dillon  if (a==NULL || a->size<1)
418e9c2009-11-13Per Hedbor  Pike_error("Invalid array argument 1.\n");
0c50a82010-02-09Lance Dillon  icons=g_new0(const gchar *,a->size+1);
72402a2007-10-14Lance Dillon  for (i=j=0; i<a->size; i++) {
418e9c2009-11-13Per Hedbor  icons[j]=g_strdup(CGSTR0((ITEM(a)+i)->u.string)); j++;
72402a2007-10-14Lance Dillon  } icons[j]=NULL; gtk_scale_button_set_icons(GTK_SCALE_BUTTON(THIS->obj),icons); for (i=0; icons[i]; i++)
0c50a82010-02-09Lance Dillon  g_free((gpointer *)icons[i]);
72402a2007-10-14Lance Dillon  g_free(icons);
418e9c2009-11-13Per Hedbor  RETURN_THIS();
72402a2007-10-14Lance Dillon } void set_value(float val); //! Sets the current value of the scale; if the scale is outside the minimum //! or maximum range values, it will be clamped to fit inside them. The //! button emits the "value-changed" signal if the value changes. +GTK2.Adjustment get_adjustment(); //! Returns the GTK2.Adjustment associated with this scale. float get_value(); //! Gets the current value. endrequire;