Ticket #24761: patch-sane-options-handling-fix.diff

File patch-sane-options-handling-fix.diff, 12.5 KB (added by mklein-de (Michael Klein), 15 years ago)
  • src/xsane-back-gtk.c

    # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=487475
    diff -urw ../xsane-0.996.orig/src/xsane-back-gtk.c ./src/xsane-back-gtk.c
    old new  
    22262226/* ----------------------------------------------------------------------------------------------------------------- */
    22272227
    22282228void xsane_back_gtk_option_menu_new(GtkWidget *parent, const char *name, char *str_list[],
    2229                  const char *val, DialogElement *elem,
     2229                 const char *val, SANE_Constraint_Type constraint_type, DialogElement *elem,
    22302230                 GtkTooltips *tooltips, const char *desc, SANE_Int settable)
    22312231{
    22322232 GtkWidget *hbox, *label, *option_menu, *menu, *item;
    22332233 MenuItem *menu_items;
     2234 int dup_string;
     2235 char *strval;
    22342236 int i, num_items;
    22352237
    22362238  DBG(DBG_proc, "xsane_back_gtk_option_menu_new(%s)\n", name);
     
    22482250
    22492251  menu_items = malloc((num_items + 1) * sizeof(menu_items[0]));
    22502252
     2253  dup_string = (constraint_type == SANE_CONSTRAINT_STRING_LIST);
     2254
    22512255  menu = gtk_menu_new();
    22522256  for (i = 0; i < num_items; ++i)
    22532257  {
    2254     item = gtk_menu_item_new_with_label(_BGT(str_list[i]));
     2258    if (dup_string)
     2259      strval = strdup(str_list[i]);
     2260    else
     2261      strval = str_list[i];
     2262
     2263    item = gtk_menu_item_new_with_label(_BGT(strval));
    22552264    gtk_container_add(GTK_CONTAINER(menu), item);
    22562265    g_signal_connect(GTK_OBJECT(item), "activate", (GtkSignalFunc) xsane_back_gtk_option_menu_callback, menu_items + i);
    22572266
    22582267    gtk_widget_show(item);
    22592268
    2260     menu_items[i].label = str_list[i];
     2269    menu_items[i].label = strval;
    22612270    menu_items[i].elem = elem;
    22622271    menu_items[i].index = i;
    22632272  }
     
    24032412  xsane.standard_hbox = NULL;
    24042413  xsane.advanced_hbox = NULL;
    24052414
    2406   /* free the menu labels of integer/fix-point word-lists: */
     2415  /* free the menu labels */
    24072416  for (i = 0; i < xsane.num_elements; ++i)
    24082417  {
    24092418    if (xsane.element[i].menu)
    24102419    {
    24112420      opt = xsane_get_option_descriptor(xsane.dev, i);
    24122421      elem = xsane.element + i;
    2413       if (opt->type != SANE_TYPE_STRING)
     2422      if ((opt->type != SANE_TYPE_STRING)
     2423          || (opt->constraint_type == SANE_CONSTRAINT_STRING_LIST))
    24142424      {
    24152425        for (j = 0; j < elem->menu_size; ++j)
    24162426        {
  • src/xsane-back-gtk.h

    diff -urw ../xsane-0.996.orig/src/xsane-back-gtk.h ./src/xsane-back-gtk.h
    old new  
    117117           gfloat quant, int automatic,
    118118           DialogElement *elem, GtkTooltips *tooltips, const char *desc, SANE_Int settable);
    119119extern void xsane_back_gtk_option_menu_new(GtkWidget *parent, const char *name, char *str_list[],
    120            const char *val, DialogElement *elem, GtkTooltips *tooltips, const char *desc, SANE_Int settable);
     120           const char *val, SANE_Constraint_Type constraint_type, DialogElement *elem, GtkTooltips *tooltips, const char *desc, SANE_Int settable);
    121121extern void xsane_back_gtk_text_entry_new(GtkWidget *parent, const char *name, const char *val,
    122122                DialogElement *elem, GtkTooltips *tooltips, const char *desc, SANE_Int settable);
    123123extern void xsane_back_gtk_push_button_callback(GtkWidget *widget, gpointer data);
  • src/xsane-front-gtk.c

    diff -urw ../xsane-0.996.orig/src/xsane-front-gtk.c ./src/xsane-front-gtk.c
    old new  
    6464                                         int *state, void *xsane_toggle_button_callback);
    6565GtkWidget *xsane_button_new_with_pixmap(GdkWindow *window, GtkWidget *parent, const char *xpm_d[], const char *desc,
    6666                                        void *xsane_button_callback, gpointer data);
    67 void xsane_option_menu_new(GtkWidget *parent, char *str_list[], const char *val, int option_number, const char *desc,
     67void xsane_option_menu_new(GtkWidget *parent, char *str_list[], const char *val, SANE_Constraint_Type constraint_type, int option_number, const char *desc,
    6868                           void *option_menu_callback, SANE_Int settable, const gchar *widget_name);
    6969void xsane_option_menu_new_with_pixmap(GdkWindow *window, GtkBox *parent, const char *xpm_d[], const char *desc,
    70                                        char *str_list[], const char *val,
     70                                       char *str_list[], const char *val, SANE_Constraint_Type constraint_type,
    7171                                       GtkWidget **data, int option,
    7272                                       void *option_menu_callback, SANE_Int settable, const gchar *widget_name);
    7373void xsane_range_new(GtkBox *parent, char *labeltext, const char *desc,
     
    10071007
    10081008/* ---------------------------------------------------------------------------------------------------------------------- */
    10091009
    1010 void xsane_option_menu_new(GtkWidget *parent, char *str_list[], const char *val, int option_number, const char *desc,
     1010void xsane_option_menu_new(GtkWidget *parent, char *str_list[], const char *val, SANE_Constraint_Type constraint_type, int option_number, const char *desc,
    10111011                           void *option_menu_callback, SANE_Int settable, const gchar *widget_name)
    10121012{
    10131013 GtkWidget *option_menu, *menu, *item;
    10141014 MenuItem *menu_items;
    10151015 DialogElement *elem;
     1016 int dup_string;
     1017 char *strval;
    10161018 int i, num_items;
    10171019
    10181020  DBG(DBG_proc, "xsane_option_menu_new\n");
     
    10311033    gtk_widget_set_name(menu, widget_name);
    10321034  }
    10331035
     1036  dup_string = (constraint_type == SANE_CONSTRAINT_STRING_LIST);
     1037
    10341038  for (i = 0; i < num_items; ++i)
    10351039  {
    1036     item = gtk_menu_item_new_with_label(_BGT(str_list[i]));
     1040    if (dup_string)
     1041      strval = strdup(str_list[i]);
     1042    else
     1043      strval = str_list[i];
     1044
     1045    item = gtk_menu_item_new_with_label(_BGT(strval));
    10371046    gtk_container_add(GTK_CONTAINER(menu), item);
    10381047
    10391048    if (option_menu_callback)
     
    10471056
    10481057    gtk_widget_show(item);
    10491058
    1050     menu_items[i].label = str_list[i];
     1059    menu_items[i].label = strval;
    10511060    menu_items[i].elem  = elem;
    10521061    menu_items[i].index = i;
    10531062  }
     
    10751084/* ---------------------------------------------------------------------------------------------------------------------- */
    10761085
    10771086void xsane_option_menu_new_with_pixmap(GdkWindow *window, GtkBox *parent, const char *xpm_d[], const char *desc,
    1078                                        char *str_list[], const char *val,
     1087                                       char *str_list[], const char *val, SANE_Constraint_Type constraint_type,
    10791088                                       GtkWidget **data, int option,
    10801089                                       void *option_menu_callback, SANE_Int settable, const gchar *widget_name)
    10811090{
     
    10941103  gtk_box_pack_start(GTK_BOX(hbox), pixmapwidget, FALSE, FALSE, 2);
    10951104  gtk_widget_show(pixmapwidget);
    10961105
    1097   xsane_option_menu_new(hbox, str_list, val, option, desc, option_menu_callback, settable, widget_name);
     1106  xsane_option_menu_new(hbox, str_list, val, constraint_type, option, desc, option_menu_callback, settable, widget_name);
    10981107  gtk_widget_show(hbox);
    10991108}
    11001109
  • src/xsane-front-gtk.h

    diff -urw ../xsane-0.996.orig/src/xsane-front-gtk.h ./src/xsane-front-gtk.h
    old new  
    5454extern GtkWidget *xsane_button_new_with_pixmap(GdkWindow *window, GtkWidget *parent, const char *xpm_d[], const char *desc,
    5555                                               void *xsane_button_callback, gpointer data);
    5656extern void xsane_pixmap_new(GtkWidget *parent, char *title, int width, int height, XsanePixmap *hist);
    57 extern void xsane_option_menu_new(GtkWidget *parent, char *str_list[], const char *val, int option_number, const char *desc,
     57extern void xsane_option_menu_new(GtkWidget *parent, char *str_list[], const char *val, SANE_Constraint_Type constraint_type, int option_number, const char *desc,
    5858                                  void *option_menu_callback, SANE_Int settable, const gchar *widget_name);
    5959extern void xsane_option_menu_new_with_pixmap(GdkWindow *window, GtkBox *parent, const char *xpm_d[], const char *desc,
    60                                               char *str_list[], const char *val,
     60                                              char *str_list[], const char *val, SANE_Constraint_Type constraint_type,
    6161                                              GtkWidget **data, int option,
    6262                                              void *option_menu_callback, SANE_Int settable, const gchar *widget_name);
    6363extern void xsane_range_new(GtkBox *parent, char *labeltext, const char *desc,
  • src/xsane.c

    diff -urw ../xsane-0.996.orig/src/xsane.c ./src/xsane.c
    old new  
    876876            str_list[j] = 0;
    877877            sprintf(str, "%d", (int) val);
    878878
    879             xsane_option_menu_new_with_pixmap(xsane.xsane_window->window, GTK_BOX(parent), image_xpm, desc, str_list, str, &resolution_widget, well_known_option,
     879            xsane_option_menu_new_with_pixmap(xsane.xsane_window->window, GTK_BOX(parent), image_xpm, desc, str_list, str, opt->constraint_type, &resolution_widget, well_known_option,
    880880                                              xsane_resolution_list_callback, SANE_OPTION_IS_SETTABLE(opt->cap), widget_name);
    881881
    882882            free(str_list);
     
    931931
    932932
    933933          xsane_option_menu_new_with_pixmap(xsane.xsane_window->window, GTK_BOX(parent), image_xpm, desc,
    934                                             str_list, str, &resolution_widget, well_known_option,
     934                                            str_list, str, opt->constraint_type, &resolution_widget, well_known_option,
    935935                                            xsane_resolution_list_callback, SANE_OPTION_IS_SETTABLE(opt->cap), widget_name);
    936936          free(str_list);
    937937        }
     
    14901490          set = malloc(opt->size);
    14911491          status = xsane_control_option(xsane.dev, xsane.well_known.scansource, SANE_ACTION_GET_VALUE, set, 0);
    14921492
    1493           xsane_option_menu_new(hbox, (char **) opt->constraint.string_list, set, xsane.well_known.scansource,
     1493          xsane_option_menu_new(hbox, (char **) opt->constraint.string_list, set, opt->constraint_type, xsane.well_known.scansource,
    14941494                                _BGT(opt->desc), 0, SANE_OPTION_IS_SETTABLE(opt->cap), 0);
    14951495         }
    14961496         break;
     
    15291529          set = malloc(opt->size);
    15301530          status = xsane_control_option(xsane.dev, xsane.well_known.scanmode, SANE_ACTION_GET_VALUE, set, 0);
    15311531
    1532           xsane_option_menu_new(hbox, (char **) opt->constraint.string_list, set, xsane.well_known.scanmode,
     1532          xsane_option_menu_new(hbox, (char **) opt->constraint.string_list, set, opt->constraint_type, xsane.well_known.scanmode,
    15331533                                _BGT(opt->desc), xsane_scanmode_menu_callback, SANE_OPTION_IS_SETTABLE(opt->cap), 0);
    15341534        }
    15351535         break;
     
    46344634              }
    46354635              str_list[j] = 0;
    46364636              sprintf(str, "%d", val);
    4637               xsane_back_gtk_option_menu_new(parent, title, str_list, str, elem, xsane.tooltips, _BGT(opt->desc),
     4637              xsane_back_gtk_option_menu_new(parent, title, str_list, str, opt->constraint_type, elem, xsane.tooltips, _BGT(opt->desc),
    46384638                                  SANE_OPTION_IS_SETTABLE(opt->cap));
    46394639              free(str_list);
    46404640              gtk_widget_show(parent->parent);
     
    47324732              }
    47334733              str_list[j] = 0;
    47344734              sprintf(str, "%g", SANE_UNFIX(val));
    4735               xsane_back_gtk_option_menu_new(parent, title, str_list, str, elem, xsane.tooltips, _BGT(opt->desc), SANE_OPTION_IS_SETTABLE(opt->cap));
     4735              xsane_back_gtk_option_menu_new(parent, title, str_list, str, opt->constraint_type, elem, xsane.tooltips, _BGT(opt->desc), SANE_OPTION_IS_SETTABLE(opt->cap));
    47364736              free (str_list);
    47374737              gtk_widget_show(parent->parent);
    47384738            }
     
    47694769                 (strcmp (opt->name, SANE_NAME_SCAN_SOURCE) != 0) ) /* do not show scansource */
    47704770            {
    47714771              /* use a "list-selection" widget */
    4772               xsane_back_gtk_option_menu_new(parent, title, (char **) opt->constraint.string_list, buf,
     4772              xsane_back_gtk_option_menu_new(parent, title, (char **) opt->constraint.string_list, buf, opt->constraint_type,
    47734773                                  elem, xsane.tooltips, _BGT(opt->desc), SANE_OPTION_IS_SETTABLE(opt->cap));
    47744774              gtk_widget_show (parent->parent);
    47754775            }