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

gEDA-user: [PATCH] Add line end to line type dialog



* Add END_ERASE to OBJECT_END type in libgeda.

Signed-off-by: Krzysztof Kosciuszkiewicz <k.kosciuszkiewicz@xxxxxxxxx>
---
 gschem/src/x_dialog.c            |   98 ++++++++++++++++++++++++++++++++------
 libgeda/include/libgeda/struct.h |    2 +-
 2 files changed, 84 insertions(+), 16 deletions(-)

diff --git a/gschem/src/x_dialog.c b/gschem/src/x_dialog.c
index 507919c..ec1e124 100644
--- a/gschem/src/x_dialog.c
+++ b/gschem/src/x_dialog.c
@@ -40,6 +40,7 @@
     gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)
 
 static GtkWidget* create_menu_linetype (GSCHEM_TOPLEVEL *w_current);
+static GtkWidget* create_menu_lineend (GSCHEM_TOPLEVEL *w_current);
 static gint line_type_dialog_linetype_change (GtkWidget *w, gpointer data);
 static void line_type_dialog_ok (GtkWidget *w, gpointer data);
 
@@ -54,6 +55,7 @@ struct line_type_data {
   GtkWidget *line_type;
   GtkWidget *length_entry;
   GtkWidget *space_entry;
+  GtkWidget *line_end;
 
   GSCHEM_TOPLEVEL *w_current;
 };
@@ -576,6 +578,7 @@ void text_edit_dialog (GSCHEM_TOPLEVEL *w_current, const char *string, int text_
 /*! \brief Create a line type menu for the line type dialog
  *  \par Function Description
  *  This function creates a GtkMenu with the different linetypes.
+ *  \todo Refactor and join with \ref create_menu_lineend
  */
 static GtkWidget *create_menu_linetype (GSCHEM_TOPLEVEL *w_current)
 {
@@ -609,6 +612,41 @@ static GtkWidget *create_menu_linetype (GSCHEM_TOPLEVEL *w_current)
   return(menu);
 }
 
+/*! \brief Create a line end menu for the line end dialog
+ *  \par Function Description
+ *  This function creates a GtkMenu with the different lineends.
+ *  \todo Refactor and join with \ref create_menu_linetype
+ */
+static GtkWidget *create_menu_lineend (GSCHEM_TOPLEVEL *w_current)
+{
+  GtkWidget *menu;
+  GSList *group;
+  struct line_end {
+    gchar *str;
+    OBJECT_END end;
+  } ends[] = { { N_("None"),         END_NONE },
+               { N_("Square"),       END_SQUARE },
+               { N_("Round"),        END_ROUND },
+               { N_("*unchanged*"),  END_ERASE } };
+  gint i;
+
+  menu  = gtk_menu_new ();
+  group = NULL;
+
+  for (i = 0; i < sizeof (ends) / sizeof (struct line_end); i++) {
+    GtkWidget *menuitem;
+
+    menuitem = gtk_radio_menu_item_new_with_label (group, _(ends[i].str));
+    group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem));
+    gtk_menu_append (GTK_MENU (menu), menuitem);
+    gtk_object_set_data (GTK_OBJECT(menuitem), "lineend",
+                         GINT_TO_POINTER (ends[i].end));
+    gtk_widget_show (menuitem);
+  }
+
+  return(menu);
+}
+
 /*! \brief get the linetype data from selected objects
  *  \par Function Description
  *  Get linetype information over all selected objects.
@@ -665,7 +703,7 @@ static gboolean selection_get_line_type(GList *selection,
  *  Set all widgets in the linetype dialog. Variables marked with the
  *  invalid value -2 are set to *unchanged*.
  *  \param [in]   line_type_data dialog structure
- *  \param [in]   end       OBJECT_END type (currently not used)
+ *  \param [in]   end       OBJECT_END type
  *  \param [in]   type      OBJECT_FILLING type
  *  \param [in]   width     fill width.
  *  \param [in]   length    length of each line
@@ -710,7 +748,15 @@ static void line_type_dialog_set_values(struct line_type_data *line_type_data,
   gtk_entry_set_text (GTK_ENTRY (line_type_data->space_entry), text);
   gtk_entry_select_region (GTK_ENTRY (line_type_data->space_entry),
                            0, strlen (text));
+
   g_free(text);
+
+  if (end == -2)
+    end = END_ERASE;
+  gtk_option_menu_set_history(GTK_OPTION_MENU(line_type_data->line_end), end);
+  menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(line_type_data->line_end));
+  menuitem = gtk_menu_get_active(GTK_MENU(menu));
+  gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
 }
                                          
 
@@ -774,10 +820,9 @@ static void line_type_dialog_ok(GtkWidget *w, gpointer data)
   GList *selection, *iter;
   OBJECT *object;
   const gchar *width_str, *length_str, *space_str;
-  OBJECT_TYPE type;
+  OBJECT_TYPE type, otype;
   gint width, length, space;
-  OBJECT_TYPE otype;
-  OBJECT_END oend;
+  OBJECT_END end, oend;
   gint owidth, olength, ospace;
 
   /* get the selection */
@@ -793,6 +838,7 @@ static void line_type_dialog_ok(GtkWidget *w, gpointer data)
                                       line_type_data->length_entry));
   space_str   = gtk_entry_get_text (GTK_ENTRY (
                                       line_type_data->space_entry));
+
   type = GPOINTER_TO_INT(
     gtk_object_get_data (
       GTK_OBJECT (
@@ -802,6 +848,16 @@ static void line_type_dialog_ok(GtkWidget *w, gpointer data)
                         line_type_data->line_type))))), "linetype"));
   if (type == TYPE_ERASE)
     type = -1;
+
+  end = GPOINTER_TO_INT(
+    gtk_object_get_data (
+      GTK_OBJECT (
+        gtk_menu_get_active (
+          GTK_MENU (gtk_option_menu_get_menu (
+                      GTK_OPTION_MENU (
+                        line_type_data->line_end))))), "lineend"));
+  if (end == END_ERASE)
+    end = -1;
   
   /* convert the options to integers (-1 means unchanged) */
   width =  g_strcasecmp (width_str,
@@ -817,11 +873,11 @@ static void line_type_dialog_ok(GtkWidget *w, gpointer data)
                              &owidth, &olength, &ospace))
       continue;
 
-    /* oend is not in the dialog, yet */
     otype = type == -1 ? otype : type;
     owidth = width  == -1 ? owidth : width;
     olength = length == -1 ? olength : length;
     ospace = space  == -1 ? ospace : space;
+    oend = end == -1 ? oend : end;
 
     /* set all not required options to -1 and 
        set nice parameters if not provided by the user */
@@ -882,21 +938,22 @@ void line_type_dialog_response(GtkWidget *widget, gint response,
 /*! \brief Creates the line type and width dialog
  *  \par Function Description
  *  This function creates and sets up a dialog for manipulating the
- *  line width and the line type setting of objects.
+ *  line width, line type and line end setting of objects.
  */
 void line_type_dialog (GSCHEM_TOPLEVEL *w_current)
 {
   GtkWidget *dialog;
   GtkWidget *vbox;
-  GtkWidget *optionmenu   = NULL;
+  GtkWidget *type_menu    = NULL;
   GtkWidget *length_entry = NULL;
   GtkWidget *space_entry  = NULL;
   GtkWidget *width_entry  = NULL;
+  GtkWidget *end_menu     = NULL;
   GtkWidget *table;
   GtkWidget *label;
   struct line_type_data *line_type_data;
   GList *selection;
-  OBJECT_END end;
+  OBJECT_END end=END_NONE;
   OBJECT_TYPE type=TYPE_SOLID;
   gint width=1, length=-1, space=-1;
 
@@ -947,7 +1004,7 @@ void line_type_dialog (GSCHEM_TOPLEVEL *w_current)
       gtk_misc_set_alignment(GTK_MISC(label),0,0);
       gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); */
 
-  table = gtk_table_new (4, 2, FALSE);
+  table = gtk_table_new (5, 2, FALSE);
   gtk_table_set_row_spacings(GTK_TABLE(table), DIALOG_V_SPACING);
   gtk_table_set_col_spacings(GTK_TABLE(table), DIALOG_H_SPACING);
   gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
@@ -968,10 +1025,14 @@ void line_type_dialog (GSCHEM_TOPLEVEL *w_current)
   gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
   gtk_table_attach(GTK_TABLE(table), label, 0,1,3,4, GTK_FILL,0,0,0);
 
-  optionmenu = gtk_option_menu_new ();
-  gtk_option_menu_set_menu(GTK_OPTION_MENU(optionmenu),
+  label = gtk_label_new (_("Line End:"));
+  gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
+  gtk_table_attach(GTK_TABLE(table), label, 0,1,4,5, GTK_FILL,0,0,0);
+
+  type_menu = gtk_option_menu_new ();
+  gtk_option_menu_set_menu(GTK_OPTION_MENU(type_menu),
                            create_menu_linetype (w_current));
-  gtk_table_attach_defaults(GTK_TABLE(table), optionmenu,
+  gtk_table_attach_defaults(GTK_TABLE(table), type_menu,
                             1,2,0,1);
 
   width_entry = gtk_entry_new();
@@ -980,7 +1041,7 @@ void line_type_dialog (GSCHEM_TOPLEVEL *w_current)
   gtk_table_attach_defaults(GTK_TABLE(table), width_entry,
                             1,2,1,2);
 
-  gtk_signal_connect(GTK_OBJECT (optionmenu), "changed",
+  gtk_signal_connect(GTK_OBJECT (type_menu), "changed",
                      (GtkSignalFunc) line_type_dialog_linetype_change,
                      line_type_data);
 
@@ -996,12 +1057,19 @@ void line_type_dialog (GSCHEM_TOPLEVEL *w_current)
   gtk_table_attach_defaults(GTK_TABLE(table), space_entry,
                             1,2,3,4);
 
+  end_menu = gtk_option_menu_new ();
+  gtk_option_menu_set_menu(GTK_OPTION_MENU(end_menu),
+                           create_menu_lineend (w_current));
+  gtk_table_attach_defaults(GTK_TABLE(table), end_menu,
+                            1,2,4,5);
+
   /* populate the data structure */
   line_type_data->dialog = dialog;
   line_type_data->width_entry  = width_entry;
-  line_type_data->line_type    = optionmenu;
+  line_type_data->line_type    = type_menu;
   line_type_data->length_entry = length_entry;
   line_type_data->space_entry  = space_entry;
+  line_type_data->line_end     = end_menu;
 
   line_type_data->w_current = w_current;
 
@@ -1010,7 +1078,7 @@ void line_type_dialog (GSCHEM_TOPLEVEL *w_current)
                               width, length, space);
 
   /* calling it once will set the dash space/length activity */
-  line_type_dialog_linetype_change(optionmenu, line_type_data);
+  line_type_dialog_linetype_change(type_menu, line_type_data);
 
   gtk_widget_grab_focus(width_entry);
   gtk_widget_show_all (dialog);
diff --git a/libgeda/include/libgeda/struct.h b/libgeda/include/libgeda/struct.h
index fef18c7..cd4cd03 100644
--- a/libgeda/include/libgeda/struct.h
+++ b/libgeda/include/libgeda/struct.h
@@ -78,7 +78,7 @@ typedef enum { F_OPEN_RC           = 1,
 } FOpenFlags;
 
 /*! \brief line end style for an open line of an object */
-typedef enum {END_NONE, END_SQUARE, END_ROUND} OBJECT_END;
+typedef enum {END_NONE, END_SQUARE, END_ROUND, END_ERASE} OBJECT_END;
 
 /*! \brief line style of lines, rect, circles, arcs */
 typedef enum {TYPE_SOLID, TYPE_DOTTED, TYPE_DASHED, TYPE_CENTER, TYPE_PHANTOM, TYPE_ERASE} OBJECT_TYPE;
-- 
1.6.2


-- 
Krzysztof KoÅciuszkiewicz
"Simplicity is the ultimate sophistication" -- Leonardo da Vinci


_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user