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

gEDA-cvs: CVS update: x_dialog.nw



  User: werner  
  Date: 05/03/06 11:48:30

  Modified:    .        x_dialog.nw o_misc.nw
  Log:
  new autonumber_text dialog and support functions
  
  
  
  
  Revision  Changes    Path
  1.31      +210 -35   eda/geda/devel/gschem/noweb/x_dialog.nw
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: x_dialog.nw
  ===================================================================
  RCS file: /home/cvspsrv/cvsroot/eda/geda/devel/gschem/noweb/x_dialog.nw,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -b -r1.30 -r1.31
  --- x_dialog.nw	13 Feb 2005 20:55:55 -0000	1.30
  +++ x_dialog.nw	6 Mar 2005 16:48:28 -0000	1.31
  @@ -223,6 +223,9 @@
   #include <dmalloc.h>
   #endif
   
  +#define GLADE_HOOKUP_OBJECT(component,widget,name) \
  +  g_object_set_data_full (G_OBJECT (component), name, \
  +    gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)
   
   static GtkWidget* create_menu_linetype (TOPLEVEL *w_current);
   static gint line_type_dialog_linetype_change (GtkWidget *w, gpointer data);
  @@ -4554,7 +4557,10 @@
   	autonumber_text_done(NULL, w_current);	
           return TRUE;
      }
  -
  +   if (strcmp(gdk_keyval_name(event->keyval), "Return") == 0) {
  +	autonumber_text_ok(NULL, w_current);	
  +        return TRUE;
  +   }
      return FALSE;
   }
   @ %def autonumber_text_keypress
  @@ -4567,17 +4573,40 @@
   <<x_dialog.c : autonumber_text_ok()>>=
   void autonumber_text_ok(GtkWidget * w, TOPLEVEL * w_current)
   {
  -  char *string = NULL;
  -
  -  string = (char *) gtk_entry_get_text(GTK_ENTRY(w_current->tsentry));
  -  strncpy(generic_textstring, string, 256);
  -
  -  o_edit_autonumber_text(w_current, w_current->page_current->object_head,
  -			 string);
  +  char *searchtext = NULL;
  +  char *startnumber = NULL;
  +  int sortorder, searchfocus, unnumbered, startnumber_i=1;
  +  GtkWidget * widget;
  +  
  +  widget = g_object_get_data (G_OBJECT (w_current->tswindow), "searchtext");
  +  searchtext = (char *) gtk_entry_get_text(GTK_ENTRY(widget));
  +  strncpy(generic_textstring, searchtext, 256); /* ???????? */
  +
  +  widget = g_object_get_data (G_OBJECT (w_current->tswindow), "startnumber");
  +  startnumber = (char *) gtk_entry_get_text(GTK_ENTRY(widget));
  +  sscanf(startnumber," %d",&startnumber_i);
  +
  +  widget = g_object_get_data (G_OBJECT (w_current->tswindow), "searchfocus");
  +  searchfocus = (int) gtk_option_menu_get_history (GTK_OPTION_MENU(widget));
  +
  +  widget = g_object_get_data (G_OBJECT (w_current->tswindow), "unnumbered");
  +  unnumbered = (int) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
  +
  +  widget = g_object_get_data (G_OBJECT (w_current->tswindow), "sortorder");
  +  sortorder = (int) gtk_option_menu_get_history(GTK_OPTION_MENU(widget));
  +
  +  if (startnumber_i < 0) {  /* disallow negativ numbers */
  +    fprintf(stderr, _("Warning: negative numbers not allowed in the "
  +		      "autonumber_text dialog\n"));
  +    return;
  +  }
   
  -  gtk_grab_remove(w_current->tswindow);
  -  gtk_widget_destroy(w_current->tswindow);
  -  w_current->tswindow = NULL;
  +  /*  printf("autonumber_text_ok: searchtext: %s\n"
  +	 "   startnumber: %i\n   searchfocus: %i\n"
  +	 "   unnumbered: %i\n   sortorder: %i\n" ,searchtext,
  +	 startnumber_i, searchfocus, unnumbered, sortorder); */
  +  o_edit_autonumber_text(w_current, searchtext, startnumber_i, searchfocus, 
  +			 unnumbered, sortorder);
   }
   
   @ %def autonumber_text_ok
  @@ -4600,13 +4629,36 @@
   <<x_dialog.c : autonumber_text_dialog()>>=
   void autonumber_text_dialog(TOPLEVEL * w_current)
   {
  -  int len;
  -  GtkWidget *label = NULL;
  -  GtkWidget *buttonok = NULL;
     GtkWidget *vbox, *action_area;
  +  GtkWidget *frame1; /* selection frame */
  +  GtkWidget *label1;
  +  GtkWidget *table1;
  +  GtkWidget *label1_1, *label1_2;
  +  GtkWidget *combo1;
  +  GList *combo1_items = NULL;
  +  GtkWidget *combo_entry1;
  +
  +  GtkWidget *optionmenu1_2, *menu1_2;
  +  GtkWidget *option_selection1, *option_selection2, *option_selection3;
  +  GtkWidget *hbox1;  /* contains radio buttons */
  +  GtkWidget *radiobutton1;
  +  GtkWidget *radiobutton2;
  +
  +  GtkWidget *frame2; /* option frame */
  +  GtkWidget *label2;
  +  GtkWidget *table2;
  +  GtkWidget *label2_1, *label2_2;
  +  GtkWidget *entry2;
  +  GtkWidget *optionmenu2_1, *menu2_1;
  +  GtkWidget *option_order1, *option_order2, *option_order3, *option_order4;
  +
  +  GtkWidget *buttonok = NULL;
  +  GtkWidget *buttoncancel = NULL;
   
     if (!w_current->tswindow) {
  -    w_current->tswindow = x_create_dialog_box(&vbox, &action_area);
  +    w_current->tswindow = gtk_dialog_new();
  +    vbox=GTK_DIALOG(w_current->tswindow)->vbox;
  +    action_area=GTK_DIALOG(w_current->tswindow)->action_area;
   
       gtk_window_position(GTK_WINDOW(w_current->tswindow),
   			GTK_WIN_POS_MOUSE);
  @@ -4630,38 +4682,161 @@
   
       gtk_window_set_title(GTK_WINDOW(w_current->tswindow),
   			 _("Autonumber text"));
  -    gtk_container_border_width(GTK_CONTAINER(w_current->tswindow), 10);
   
  -    label = gtk_label_new(_("Autonumber text starting with:"));
  -    gtk_misc_set_padding(GTK_MISC(label), 20, 20);
  -    gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0);
  -    gtk_widget_show(label);
  +    /* selection frame */
  +    frame1 = gtk_frame_new(NULL);
  +    gtk_widget_show (frame1);
  +    gtk_box_pack_start (GTK_BOX(vbox), frame1, TRUE, TRUE, 0);
  +    label1 = gtk_label_new (_("selection"));
  +    gtk_widget_show (label1);
  +    gtk_frame_set_label_widget (GTK_FRAME(frame1), label1);
   
  -    w_current->tsentry = gtk_entry_new_with_max_length(20);
  -    gtk_editable_select_region(GTK_EDITABLE(w_current->tsentry), 0, -1);
  -    gtk_box_pack_start(GTK_BOX(vbox), w_current->tsentry, FALSE, FALSE, 5);
  -    gtk_signal_connect(GTK_OBJECT(w_current->tsentry), "activate",
  -		       GTK_SIGNAL_FUNC(autonumber_text_ok), w_current);
  -    gtk_widget_show(w_current->tsentry);
  -    gtk_widget_grab_focus(w_current->tsentry);
  +    table1 = gtk_table_new(2,3,FALSE);
  +    gtk_widget_show (table1);
  +    gtk_container_add (GTK_CONTAINER(frame1), table1);
  +
  +    /* search text section */
  +    label1_1 = gtk_label_new (_("search text"));
  +    gtk_widget_show (label1_1);
  +    gtk_table_attach (GTK_TABLE (table1), label1_1, 0, 1, 0, 1,
  +		      (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
  +		      (GtkAttachOptions) (0), 0, 0);
  +
  +    combo1 = gtk_combo_new ();
  +    /* g_object_set_data (G_OBJECT (GTK_COMBO (combo1)->popwin),
  +       "GladeParentKey", combo1);*/
  +    gtk_widget_show (combo1);
  +    gtk_table_attach (GTK_TABLE (table1), combo1, 1, 2, 0, 1,
  +		      (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
  +		      (GtkAttachOptions) (0), 0, 0);
  +    /* gtk_combo_set_value_in_list (GTK_COMBO (combo1), TRUE, TRUE);*/
  +    combo1_items = g_list_append (combo1_items, (gpointer) _("refdes=C"));
  +    combo1_items = g_list_append (combo1_items, (gpointer) _("refdes=Q"));
  +    combo1_items = g_list_append (combo1_items, (gpointer) _("refdes=R"));
  +    combo1_items = g_list_append (combo1_items, (gpointer) _("refdes=X"));
  +    gtk_combo_set_popdown_strings (GTK_COMBO (combo1), combo1_items);
  +    g_list_free (combo1_items);
  +
  +    combo_entry1 = GTK_COMBO (combo1)->entry;
  +    gtk_widget_show (combo_entry1);
  +    gtk_entry_set_text (GTK_ENTRY (combo_entry1), _("refdes=C"));	
  +    GLADE_HOOKUP_OBJECT(w_current->tswindow,combo_entry1,"searchtext");
  +
  +    /* search focus section */
  +    label1_2 = gtk_label_new (_("search focus"));
  +    gtk_widget_show (label1_2);
  +    gtk_table_attach (GTK_TABLE (table1), label1_2, 0, 1, 1, 2,
  +		      (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
  +		      (GtkAttachOptions) (0), 0, 0);
  +
  +    optionmenu1_2 = gtk_option_menu_new ();
  +    gtk_widget_show (optionmenu1_2);
  +    gtk_table_attach (GTK_TABLE (table1), optionmenu1_2, 1, 2, 1, 2,
  +		      (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
  +		      (GtkAttachOptions) (0), 0, 0);
  +
  +    menu1_2 = gtk_menu_new();
  +    option_selection1 = gtk_menu_item_new_with_label (_("selected objects"));
  +    gtk_widget_show (option_selection1);
  +    gtk_container_add (GTK_CONTAINER (menu1_2), option_selection1);
  +    option_selection2 = gtk_menu_item_new_with_label (_("current sheet"));
  +    gtk_widget_show (option_selection2);
  +    gtk_container_add (GTK_CONTAINER (menu1_2), option_selection2);
  +    option_selection3 = gtk_menu_item_new_with_label (_("hierarchical sheets"));
  +    gtk_widget_show (option_selection3);
  +    gtk_container_add (GTK_CONTAINER (menu1_2), option_selection3);
  +    gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu1_2), menu1_2);
  +    GLADE_HOOKUP_OBJECT(w_current->tswindow,optionmenu1_2,"searchfocus");
  +
  +    /* radio buttons */
  +    hbox1=gtk_hbox_new (FALSE,0);
  +    gtk_widget_show (hbox1);
  +    gtk_table_attach (GTK_TABLE (table1), hbox1, 0, 2, 2, 3,
  +		      (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
  +		      (GtkAttachOptions) (0), 0, 0);
  +    radiobutton1 = gtk_radio_button_new_with_label (NULL, _("unnumbered"));
  +    gtk_widget_show (radiobutton1);
  +    gtk_box_pack_start (GTK_BOX (hbox1), radiobutton1, TRUE, TRUE, 0);
  +    radiobutton2 = gtk_radio_button_new_with_label_from_widget(
  +		     GTK_RADIO_BUTTON (radiobutton1), _("all"));
  +    gtk_widget_show (radiobutton2);
  +    gtk_box_pack_start (GTK_BOX (hbox1), radiobutton2, TRUE, TRUE, 0);
  +    GLADE_HOOKUP_OBJECT(w_current->tswindow,radiobutton1,"unnumbered");
  +
  +    /* option frame */
  +    frame2=gtk_frame_new(NULL);
  +    gtk_widget_show(frame2);
  +    gtk_box_pack_start (GTK_BOX(vbox), frame2, TRUE, TRUE, 0);
  +    label2 = gtk_label_new (_("options"));
  +    gtk_widget_show (label2);
  +    gtk_frame_set_label_widget (GTK_FRAME(frame2), label2);
  +    
  +    table2 = gtk_table_new(2,2,FALSE);
  +    gtk_widget_show(table2);
  +    gtk_container_add (GTK_CONTAINER (frame2),table2);
  +    label2_1=gtk_label_new(_("start number"));
  +    gtk_widget_show(label2_1);
  +    gtk_table_attach (GTK_TABLE (table2), label2_1, 0, 1, 0, 1,
  +		      (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
  +		      (GtkAttachOptions) (0), 0, 0);
  +    entry2=gtk_entry_new();
  +    gtk_entry_set_text(GTK_ENTRY(entry2), "1");
  +    gtk_widget_show(entry2);
  +    gtk_table_attach (GTK_TABLE (table2), entry2, 1, 2, 0, 1,
  +		      (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
  +		      (GtkAttachOptions) (0), 0, 0);
  +    GLADE_HOOKUP_OBJECT(w_current->tswindow,entry2,"startnumber");
  +
  +    label2_2=gtk_label_new(_("sort order"));
  +    gtk_widget_show(label2_2);
  +    gtk_table_attach (GTK_TABLE (table2), label2_2, 0, 1, 1, 2,
  +		      (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
  +		      (GtkAttachOptions) (0), 0, 0);
  +
  +    optionmenu2_1 = gtk_option_menu_new ();
  +    gtk_widget_show (optionmenu2_1);
  +    gtk_table_attach (GTK_TABLE (table2), optionmenu2_1, 1, 2, 1, 2,
  +		      (GtkAttachOptions) (GTK_FILL|GTK_EXPAND),
  +		      (GtkAttachOptions) (0), 0, 0);
  +    menu2_1 = gtk_menu_new();
  +    option_order1 = gtk_menu_item_new_with_label (_("file order"));
  +    gtk_widget_show (option_order1);
  +    gtk_container_add (GTK_CONTAINER (menu2_1), option_order1);
  +    option_order2 = gtk_menu_item_new_with_label (_("top down"));
  +    gtk_widget_show (option_order2);
  +    gtk_container_add (GTK_CONTAINER (menu2_1), option_order2);
  +    option_order3 = gtk_menu_item_new_with_label (_("left right"));
  +    gtk_widget_show (option_order3);
  +    gtk_container_add (GTK_CONTAINER (menu2_1), option_order3);
  +    option_order4 = gtk_menu_item_new_with_label (_("diagonal"));
  +    gtk_widget_show (option_order4);
  +    gtk_container_add (GTK_CONTAINER (menu2_1), option_order4);
  +    gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu2_1), menu2_1);
  +    GLADE_HOOKUP_OBJECT(w_current->tswindow,optionmenu2_1,"sortorder");
   
  -#ifdef HAS_GTK12
  -    buttonok = gtk_button_new_with_label(_("OK"));
  -#else
  -    buttonok = gtk_button_new_from_stock (GTK_STOCK_OK);
  -#endif
  +    /* Why is the entry attached to w_current ?? (Werner) */
  +    w_current->tsentry = combo_entry1;
  +
  +    buttoncancel = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
  +    gtk_box_pack_start(GTK_BOX(action_area), buttoncancel, TRUE, TRUE, 0);
  +    gtk_signal_connect(GTK_OBJECT(buttoncancel), "clicked",
  +		       GTK_SIGNAL_FUNC(autonumber_text_done), w_current);
  +    gtk_widget_show(buttoncancel);
  +
  +    buttonok = gtk_button_new_from_stock (GTK_STOCK_APPLY);
       GTK_WIDGET_SET_FLAGS(buttonok, GTK_CAN_DEFAULT);
       gtk_box_pack_start(GTK_BOX(action_area), buttonok, TRUE, TRUE, 0);
       gtk_signal_connect(GTK_OBJECT(buttonok), "clicked",
   		       GTK_SIGNAL_FUNC(autonumber_text_ok), w_current);
       gtk_widget_show(buttonok);
       gtk_widget_grab_default(buttonok);
  +
     }
   
     if (!GTK_WIDGET_VISIBLE(w_current->tswindow)) {
  -    len = strlen(generic_textstring);
       gtk_entry_set_text(GTK_ENTRY(w_current->tsentry), generic_textstring);
  -    gtk_entry_select_region(GTK_ENTRY(w_current->tsentry), 0, len);
  +    gtk_entry_select_region(GTK_ENTRY(w_current->tsentry),
  +			    0,strlen(generic_textstring));
       gtk_widget_show(w_current->tswindow);
       gtk_grab_add(w_current->tswindow);
     }
  
  
  
  1.34      +300 -129  eda/geda/devel/gschem/noweb/o_misc.nw
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: o_misc.nw
  ===================================================================
  RCS file: /home/cvspsrv/cvsroot/eda/geda/devel/gschem/noweb/o_misc.nw,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -b -r1.33 -r1.34
  --- o_misc.nw	25 Feb 2005 21:00:53 -0000	1.33
  +++ o_misc.nw	6 Mar 2005 16:48:29 -0000	1.34
  @@ -22,7 +22,11 @@
   <<o_misc.c : o_edit_show_hidden()>>
   <<o_misc.c : o_edit_make_visible()>>
   <<o_misc.c : o_edit_find_text()>>
  -<<o_misc.c : find_max()>>
  +<<o_misc.c : autonumber_sort_numbers()>>
  +<<o_misc.c : autonumber_sort_xy()>>
  +<<o_misc.c : autonumber_sort_yx()>>
  +<<o_misc.c : autonumber_sort_diagonal()>>
  +<<o_misc.c : autonumber_find()>>
   <<o_misc.c : autonumber_text()>>
   <<o_misc.c : o_edit_autonumber_text()>>
   <<o_misc.c : o_edit_hide_specific_text()>>
  @@ -73,6 +77,20 @@
   #include <dmalloc.h>
   #endif
   
  +#define FOCUS_SELECTION 0
  +#define FOCUS_SHEET 1
  +#define FOCUS_ALL 2
  +
  +#define SELECTION_ALL 0
  +#define SELECTION_UNNUMBERED 1
  +
  +#define AUTONUMBER_SKIP_NOT 0
  +#define AUTONUMBER_SKIP_PAGE 1
  +#define AUTONUMBER_SKIP_SELECTION 2
  +
  +#define AUTONUMBER_SORT_YX 1
  +#define AUTONUMBER_SORT_XY 2
  +#define AUTONUMBER_SORT_DIAGONAL 3
   @
   
   
  @@ -1062,17 +1080,104 @@
   
   @ %def o_edit_find_text
   
  +@section Function @code{autonumber_sort_numbers()}
   
  -@section Function @code{find_max()}
  +@defun autonumber_sort_numbers a b 
  +@end defun
  +
  +<<o_misc.c : autonumber_sort_numbers()>>=
  +
  +int
  +autonumber_sort_numbers(gconstpointer a, gconstpointer b) {
  +  if (GPOINTER_TO_INT(a) < GPOINTER_TO_INT(b))
  +    return -1;
  +  if (GPOINTER_TO_INT(a) > GPOINTER_TO_INT(b))
  +    return 1;
  +  return 0;
  +}
  +
  +@ %autonumber_sort_numbers
  +
  +@section Function @code{autonumber_sort_xy()}
   
  -@defun find_max w_current o_list stext 
  +@defun autonumber_sort_xy a b 
   @end defun
   
  -<<o_misc.c : find_max()>>=
  -int current_max;
  -int used_count;
  -int used_list[4096];
  -void find_max(TOPLEVEL * w_current, OBJECT * o_list, char *stext)
  +<<o_misc.c : autonumber_sort_xy()>>=
  +
  +int
  +autonumber_sort_xy(gconstpointer a, gconstpointer b) {
  +  OBJECT *aa, *bb;
  +  aa=(OBJECT *) a;  bb=(OBJECT *) b;
  +  if (aa->text->x < bb->text->x)
  +    return -1;
  +  if (aa->text->x > bb->text->x)
  +    return 1;
  +  /* x == x */
  +  if (aa->text->y > bb->text->y)
  +    return -1;
  +  if (aa->text->y < bb->text->y)
  +    return 1;
  +  return 0;
  +}
  +
  +@ %autonumber_sort_xy
  +
  +@section Function @code{autonumber_sort_yx()}
  +
  +@defun autonumber_sort_yx a b 
  +@end defun
  +
  +<<o_misc.c : autonumber_sort_yx()>>=
  +
  +int
  +autonumber_sort_yx(gconstpointer a, gconstpointer b) {
  +  OBJECT *aa, *bb;
  +  aa=(OBJECT *) a;  bb=(OBJECT *) b;
  +  if (aa->text->y > bb->text->y)
  +    return -1;
  +  if (aa->text->y < bb->text->y)
  +    return 1;
  +  /* x == x */
  +  if (aa->text->x < bb->text->x)
  +    return -1;
  +  if (aa->text->x > bb->text->x)
  +    return 1;
  +  return 0;
  +}
  +
  +@ %autonumber_sort_yx
  +
  +
  +@section Function @code{autonumber_sort_diagonal()}
  +
  +@defun autonumber_sort_diagonal a b 
  +@end defun
  +
  +<<o_misc.c : autonumber_sort_diagonal()>>=
  +
  +int
  +autonumber_sort_diagonal(gconstpointer a, gconstpointer b) {
  +  OBJECT *aa, *bb;
  +  aa=(OBJECT *) a;  bb=(OBJECT *) b;
  +  if (aa->text->x - aa->text->y < bb->text->x - bb->text->y)
  +    return -1;
  +  if (aa->text->x - aa->text->y > bb->text->x - bb->text->y)
  +    return 1;
  +  return 0;
  +}
  +
  +@ %autonumber_sort_diagonal
  +
  +
  +@section Function @code{autonumber_find()}
  +
  +@defun autonumber_find w_current o_list stext used_numbers skip
  +@end defun
  +
  +<<o_misc.c : autonumber_find()>>=
  +void autonumber_find(TOPLEVEL * w_current, OBJECT * o_list, char *stext, 
  +		  GSList **used_numbers, int skip)
   {
     OBJECT *o_current = NULL;
     char *attrib = NULL;
  @@ -1083,16 +1188,21 @@
     int pcount = 0;
     int l, m;
   
  -  if (o_list == NULL)
  -    return;
  -
  -  o_current = o_list;
  -
  -  while (o_current != NULL) {
  -
  -
  +  for (o_current = o_list; o_current != NULL; o_current=o_current->next) {
  +    if (o_current->type == OBJ_TEXT && skip != AUTONUMBER_SKIP_PAGE) {
  +      if (!(o_current->selected) || skip != AUTONUMBER_SKIP_SELECTION) {
  +	if ((l = strlen(o_current->text->string) - strlen(stext)) > 0) {
  +	  if (!strncmp(stext, o_current->text->string, strlen(stext))) {
  +	    if (isdigit(o_current->text->string[strlen(stext)])) {
  +	      sscanf(o_current->text->string + strlen(stext), "%d", &m);
  +	      *used_numbers = g_slist_append(*used_numbers,GINT_TO_POINTER(m));
  +	      /* printf(" %d\n", m);*/
  +	    }
  +	  }
  +	}
  +      }
  +    }
       if (o_current->type == OBJ_COMPLEX) {
  -
         parent = w_current->page_current;
         attrib = o_attrib_search_name_single_count(o_current,
   						 "source", count);
  @@ -1108,6 +1218,8 @@
   	pcount = 0;
   	current_filename = u_basic_breakup_string(attrib, ',', pcount);
   	if (current_filename != NULL) {
  +	  /* printf("autonumber_find: recursion filename \"%s\"\n",
  +	     current_filename); */
   	  page_control =
   	      s_hierarchy_down_schematic_single(w_current,
   						current_filename,
  @@ -1115,32 +1227,16 @@
   						page_control,
   						HIERARCHY_NORMAL_LOAD);
   
  -	  find_max(w_current, w_current->page_current->object_head, stext);
  +	  autonumber_find(w_current, w_current->page_current->object_head,
  +		       stext, used_numbers, AUTONUMBER_SKIP_NOT);
   	  s_hierarchy_up(w_current, w_current->page_current->up);
   	}
         }
       }
  -    if (o_current->type == OBJ_TEXT) {
  -      if ((l = strlen(o_current->text->string) - strlen(stext)) > 0) {
  -	if (!strncmp(stext, o_current->text->string, strlen(stext))) {
  -	  if (isdigit(o_current->text->string[strlen(stext)])) {
  -	    sscanf(o_current->text->string + strlen(stext), "%d", &m);
  -            if (used_count < 4094) {
  -              used_list[used_count++] = m;
  -            }
  -	    if (m > current_max) {
  -	      current_max = m;
  -	    }
  -	    /*            printf("%d %d\n", m, max); */
  -	  }
  -	}
  -      }
  -    }
  -    o_current = o_current->next;
     }
   }
   
  -@ %def find_max
  +@ %def autonumber_find
   
   
   @section Function @code{autonumber_text()}
  @@ -1150,9 +1246,16 @@
   
   <<o_misc.c : autonumber_text()>>=
   void
  -autonumber_text(TOPLEVEL * w_current, OBJECT * o_list, char *stext)
  +autonumber_text(TOPLEVEL * w_current, char *stext, GSList **used, 
  +		int *currentnumber, int unnumbered, int searchfocus, 
  +		int sortorder)
   {
  +  GSList *o_list = NULL;
     OBJECT *o_current = NULL;
  +  GSList *o_list_complex = NULL;
  +  OBJECT *o_complex_current = NULL;
  +  GSList *item;
  +
     char *attrib = NULL;
     int count = 0;
     PAGE *parent = NULL;
  @@ -1163,17 +1266,85 @@
     unsigned char *ss;
     int l;
   
  -  o_current = o_list;
  -  while (o_current != NULL) {
  +  o_current = w_current->page_current->object_head;
  +
  +  for (o_current = w_current->page_current->object_head; o_current != NULL;
  +       o_current = o_current->next) {
       if (o_current->type == OBJ_COMPLEX) {
  +      o_list_complex = g_slist_append(o_list_complex, o_current);
  +    }
  +    if (o_current->type == OBJ_TEXT) {
  +      if (searchfocus != FOCUS_SELECTION || o_current->selected) {
  +	if ((l = strlen(o_current->text->string) - strlen(stext)) > 0) {
  +	  if (!strncmp(stext, o_current->text->string, strlen(stext))) {
  +	    if (o_current->text->string[strlen(stext)] == '?'
  +		|| (isdigit(o_current->text->string[strlen(stext)])
  +		    && unnumbered == SELECTION_ALL)){
  +	      o_list=g_slist_append(o_list,o_current);
  +	      /* printf("autonumber_text: text \"%s\" \n", 
  +		 o_current->text->string);*/
  +	    }
  +	  }
  +	}
  +      }
  +    }
  +  }
  +
  +  /* sort o_list */
  +  switch (sortorder) {
  +  case AUTONUMBER_SORT_YX:
  +    o_list=g_slist_sort(o_list,autonumber_sort_yx);
  +    break;
  +  case AUTONUMBER_SORT_XY:
  +    o_list=g_slist_sort(o_list,autonumber_sort_xy);
  +    break;
  +  case AUTONUMBER_SORT_DIAGONAL:
  +    o_list=g_slist_sort(o_list,autonumber_sort_diagonal);
  +    break;
  +  default:
  +    ; /* unsorted file order */
  +  }
  +
  +  for (item=o_list; item != NULL; item=g_slist_next(item)) {
  +    o_current= item->data;
  +    free(o_current->text->string);
  +
  +    while (*used != NULL && *currentnumber > GPOINTER_TO_INT((*used)->data)) {
  +      *used=(*used)->next;
  +    }
  +
  +    while (*used != NULL && *currentnumber == GPOINTER_TO_INT((*used)->data)) {
  +      *used=(*used)->next;
  +      (*currentnumber)++;
  +      while (*used != NULL && *currentnumber > GPOINTER_TO_INT((*used)->data))
  +	*used=(*used)->next;
  +    }
  +
  +    /* printf("autonumber_text: currentnumber %d\n",*currentnumber);*/
  +
  +    ss = g_strdup_printf("%s%d", stext, (*currentnumber)++);
  +    /*            printf("%s\n", ss); */
  +    o_current->text->string =
  +      (char *) malloc(sizeof(char) * (strlen(ss) + 1));
  +    strcpy(o_current->text->string, ss);
  +    free(ss);
  +    o_text_erase(w_current, o_current);
  +    o_text_recreate(w_current, o_current);
  +    o_text_draw(w_current, o_current);
  +    w_current->page_current->CHANGED = 1;
  +  }
   
  +  /* only walk down the hierarchy if requested */
  +  if (searchfocus == FOCUS_ALL) {
  +    for (item=o_list_complex; item != NULL; item=g_slist_next(item)) {
  +      o_complex_current= item->data;
         parent = w_current->page_current;
  -      attrib = o_attrib_search_name_single_count(o_current,
  +      attrib = o_attrib_search_name_single_count(o_complex_current,
   						 "source", count);
   
         /* if above is null, then look inside symbol */
         if (attrib == NULL) {
  -	attrib = o_attrib_search_name(o_current->
  +	attrib = o_attrib_search_name(o_complex_current->
   				      complex->prim_objs, "source", count);
   	/*            looking_inside = TRUE; */
         }
  @@ -1188,50 +1359,16 @@
   						parent,
   						page_control,
   						HIERARCHY_NORMAL_LOAD);
  -	  /*o_redraw_all(w_current); */
  -	  autonumber_text(w_current, w_current->page_current->object_head,
  -			  stext);
  +	  autonumber_text(w_current, stext, used, currentnumber, 
  +			  unnumbered, searchfocus, sortorder);
   
   	  s_hierarchy_up(w_current, w_current->page_current->up);
  -
   	}
         }
       }
  -
  -    if (o_current->type == OBJ_TEXT) {
  -      if ((l = strlen(o_current->text->string) - strlen(stext)) > 0) {
  -	if (!strncmp(stext, o_current->text->string, strlen(stext))) {
  -	  /* printf("%s %d\n", o_current->text->string, (unsigned char) o_current->text->string[strlen(stext)]); */
  -	  if (o_current->text->string[strlen(stext)] == '?') {
  -	    free(o_current->text->string);
  -
  -            while (current_max > used_list[used_count]) {
  -              used_count++;
  -            }
  -            while (current_max==used_list[used_count]) {
  -              current_max++;
  -              used_count++;
  -            }
  -
  -	    /* printf("autonumber_text: used_count %d, current_max %d\n",
  -	       used_count,current_max);*/
  -
  -	    ss = g_strdup_printf("%s%d", stext, current_max++);
  -	    /*            printf("%s\n", ss); */
  -	    o_current->text->string =
  -		(char *) malloc(sizeof(char) * (strlen(ss) + 1));
  -	    strcpy(o_current->text->string, ss);
  -	    free(ss);
  -	    o_text_erase(w_current, o_current);
  -	    o_text_recreate(w_current, o_current);
  -	    o_text_draw(w_current, o_current);
  -	    w_current->page_current->CHANGED = 1;
  -	  }
  -	}
  -      }
  -    }
  -    o_current = o_current->next;
     }
  +  g_slist_free(o_list);
  +  g_slist_free(o_list_complex);
     o_undo_savestate(w_current, UNDO_ALL);
   }
   
  @@ -1245,47 +1382,81 @@
   
   <<o_misc.c : o_edit_autonumber_text()>>=
   void
  -o_edit_autonumber_text(TOPLEVEL * w_current, OBJECT * o_list, char *stext)
  +o_edit_autonumber_text(TOPLEVEL * w_current, char * searchtext,
  +		       int startnumber,int searchfocus,
  +		       int unnumbered, int sortorder)
   {
  -  int i, tmp,sorted=0;
  -
  -  current_max = 0; /* these are global variables, (Werner) */
  -  used_count = 0;
  -
  -  find_max(w_current, o_list, stext);
  -
  -  /*  printf("o_edit_autonumber_text: used_count %d, current_max %d\n",
  -      used_count,current_max);*/
  -
  -  if ((used_count < 4094)&&(used_count > 0)) {
  -    while (!sorted) {
  -      sorted = 1;
  -      for (i=0;i<used_count-1;i++) {
  -        if (used_list[i]>used_list[i+1]) {
  -          sorted = 0;
  -          tmp = used_list[i];
  -          used_list[i] = used_list[i+1];
  -          used_list[i+1] = tmp;
  -        }
  -        if (used_list[i]==used_list[i+1]) {
  -          printf(_("Warning: two components with same refdes: %d\n"), used_list[i]);
  -        }
  +  GSList *used_numbers=NULL;
  +  GSList *searchtext_list=NULL;
  +  GSList *item;
  +  char* stext=NULL;
  +  int skip_numbering=AUTONUMBER_SKIP_NOT;
  +  GSList *used_iterator=NULL;  /* used in recursive autonumber_text */
  +  int currentnumber;           /* used in recursive autonumber_text */
  +
  +  /* Step2: if searchtext has an asterisk at the end we have to find
  +     all matching searchtextes. 
  +     The function can take care of the selection options.
  +     The search function should return all possibles searchtexts that have
  +     its own number space.
  +     This requires something like:
  +       grep searchtext | sort | uniq
  +     in the object list down the hierarchy.
  +
  +     Example:  "refdes=*" will match each text that starts with "refdes="
  +     and has a trailing "?" (and a trailing number if the "all"-option is set.
  +     The function should return a list of all possible prefixes:
  +     refdes=R, refdes=C in the same way the searchstring is entered.
  +
  +     If there is only one search pattern, it becomes a single item
  +     in the searchtext list */
  +
  +  if (searchtext[strlen(searchtext)-1] == '*') {
  +    fprintf(stderr,"o_edit_autonumber_text: multiple searchtext option\n"
  +	    "  not implemented yet\n");
  +    /* collect the possible searchtextes, not implemented yet */
  +  }
  +  else {
  +    /* single searchtext */
  +    searchtext_list=g_slist_append (searchtext_list, searchtext);
  +  }
  +
  +  /* Step3: iterate over the search item in the list */
  +  for (item=searchtext_list; item !=NULL; item=g_slist_next(item)) {
  +    stext = item->data;
  +    /* printf("o_edit_autonumber_text: iterate text: \"%s\"\n",stext);*/
  +    /* Step3.1: get the used numbers, ignore numbers that will be overwritten*/
  +    if (unnumbered==SELECTION_ALL && searchfocus==FOCUS_ALL) {
  +      ; /* all numbers will be overwritten, don't search */
  +    }
  +    else {
  +      if (unnumbered == SELECTION_ALL && searchfocus == FOCUS_SHEET)
  +	skip_numbering = AUTONUMBER_SKIP_PAGE;
  +      if (unnumbered == SELECTION_ALL && searchfocus == FOCUS_SELECTION)
  +	skip_numbering = AUTONUMBER_SKIP_SELECTION;
  +
  +      autonumber_find(w_current, w_current->page_current->object_head, 
  +		   stext, &used_numbers, skip_numbering);
  +    }
  +
  +    /* printf("o_edit_autonumber_text: listlength: %d\n",
  +       g_slist_length(used_numbers)); */
  +    /* sort used numbers */
  +    used_numbers=g_slist_sort(used_numbers,autonumber_sort_numbers);
  +
  +  /* Step3.2: get a list of all matching objects 
  +              sort the list (sort option)
  +	      renumber all objects (start number option)
  +     this whole step is done in the autonumber_text function */
  +    used_iterator=used_numbers;
  +    currentnumber=startnumber;
  +    autonumber_text(w_current, stext, &used_iterator, &currentnumber, 
  +		    unnumbered, searchfocus, sortorder);
  +    g_slist_free(used_numbers);
  +    used_numbers=NULL;
         }
  -    }
  -    current_max = 1;
  -  } else {
  -    used_list[0] = current_max;
  -    used_count = 1;
  -  }
  -  used_list[used_count] = 1000000;
  -  used_count = 0;
  -
  -  /*  printf("o_edit_autonumber_text: used_count %d, current_max %d\n",
  -      used_count,current_max);*/
  -
  -  autonumber_text(w_current, o_list, stext);
  +  g_slist_free(searchtext_list);
     o_redraw_all(w_current);
  -
   }
   
   @ %def o_edit_autonumber_text