Send commitlog mailing list submissions to
        commitlog@lists.openmoko.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.openmoko.org/mailman/listinfo/commitlog
or, via email, send a message with subject or body 'help' to
        commitlog-requ...@lists.openmoko.org

You can reach the person managing the list at
        commitlog-ow...@lists.openmoko.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of commitlog digest..."
Today's Topics:

   1. r5929 - trunk/eda/fped (wer...@docs.openmoko.org)
   2. r5930 - trunk/eda/fped (wer...@docs.openmoko.org)
   3. r5931 - trunk/eda/boom (wer...@docs.openmoko.org)
--- Begin Message ---
Author: werner
Date: 2010-04-23 15:43:19 +0200 (Fri, 23 Apr 2010)
New Revision: 5929

Added:
   trunk/eda/fped/gui_frame_drag.c
   trunk/eda/fped/gui_frame_drag.h
Modified:
   trunk/eda/fped/Makefile
   trunk/eda/fped/TODO
   trunk/eda/fped/gui_frame.c
Log:
Added support for reordering rows and columns in a table via the GUI. To move
a column, drag the variable or any of its values and drag horizontally. To move
a row, drag one of its value vertically.

- gui_frame.c (table_var_select_event, table_value_select_event): return FALSE
  if dragging is possible
- gui_frame.c (build_table), gui_frame_drag.h, gui_frame_drag.c, Makefile:
  support for rearranging tables using Gtk's drag and drop mechanism
- TODO: two items less



Modified: trunk/eda/fped/Makefile
===================================================================
--- trunk/eda/fped/Makefile     2010-04-20 21:01:16 UTC (rev 5928)
+++ trunk/eda/fped/Makefile     2010-04-23 13:43:19 UTC (rev 5929)
@@ -19,7 +19,7 @@
        layer.o overlap.o \
        cpp.o lex.yy.o y.tab.o \
        gui.o gui_util.o gui_style.o gui_inst.o gui_status.o gui_canvas.o \
-       gui_tool.o gui_over.o gui_meas.o gui_frame.o
+       gui_tool.o gui_over.o gui_meas.o gui_frame.o gui_frame_drag.o
 
 XPMS = point.xpm delete.xpm delete_off.xpm \
        vec.xpm frame.xpm frame_locked.xpm frame_ready.xpm \

Modified: trunk/eda/fped/TODO
===================================================================
--- trunk/eda/fped/TODO 2010-04-20 21:01:16 UTC (rev 5928)
+++ trunk/eda/fped/TODO 2010-04-23 13:43:19 UTC (rev 5929)
@@ -6,8 +6,6 @@
 
 Minor missing features:
 - reorder frames (can use text editor)
-- reorder rows in a table (can use text editor)
-- reorder columns in a table
 - reorder variables in a frame (can use text editor)
 - move items/vectors up and down the hierarchy
 

Modified: trunk/eda/fped/gui_frame.c
===================================================================
--- trunk/eda/fped/gui_frame.c  2010-04-20 21:01:16 UTC (rev 5928)
+++ trunk/eda/fped/gui_frame.c  2010-04-23 13:43:19 UTC (rev 5929)
@@ -27,6 +27,7 @@
 #include "gui_tool.h"
 #include "gui_canvas.h"
 #include "gui.h"
+#include "gui_frame_drag.h"
 #include "gui_frame.h"
 
 
@@ -893,7 +894,7 @@
        switch (event->button) {
        case 1:
                edit_var(var, set_col_values, var, -1);
-               break;
+               return FALSE;
        case 3:
                pop_up_table_var(var, event);
                break;
@@ -918,7 +919,7 @@
                        select_row(value->row);
                        change_world();
                }
-               break;
+               return FALSE;
        case 3:
                pop_up_table_value(value, event);
                break;
@@ -999,7 +1000,6 @@
 
                        gtk_table_set_row_spacings(GTK_TABLE(tab), 1);
                        gtk_table_set_col_spacings(GTK_TABLE(tab), 1);
-
                }
        
                field = label_in_box_new(var->name,
@@ -1015,6 +1015,8 @@
                    G_CALLBACK(table_scroll_event), table);
                var->widget = field;
 
+               setup_var_drag(var);
+
                n_row = 0;
                for (row = table->rows; row; row = row->next) {
                        value = row->values;
@@ -1037,6 +1039,7 @@
                            "scroll_event",
                            G_CALLBACK(table_scroll_event), table);
                        value->widget = field;
+                       setup_value_drag(value);
                        n_row++;
                }
 

Added: trunk/eda/fped/gui_frame_drag.c
===================================================================
--- trunk/eda/fped/gui_frame_drag.c                             (rev 0)
+++ trunk/eda/fped/gui_frame_drag.c     2010-04-23 13:43:19 UTC (rev 5929)
@@ -0,0 +1,281 @@
+/*
+ * gui_frame_drag.c - GUI, dragging of frame items
+ *
+ * Written 2010 by Werner Almesberger
+ * Copyright 2010 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+
+#include <gtk/gtk.h>
+
+#include "obj.h"
+#include "gui_util.h"
+#include "gui_frame_drag.h"
+
+
+/*
+ * Pointer to whatever it is we're dragging. Undefined if not dragging.
+ */
+static void *dragging;
+
+
+/* ----- helper functions for indexed list and swapping -------------------- */
+
+
+#define NDX(first, item)                                       \
+       ({ typeof(first) NDX_walk;                              \
+          int NDX_n = 0;                                       \
+          for (NDX_walk = (first); NDX_walk != (item);         \
+              NDX_walk = NDX_walk->next)                       \
+               NDX_n++;                                        \
+          NDX_n; })
+
+#define        NTH(first, n)                                           \
+       ({ typeof(first) *NTH_walk;                             \
+          int NTH_n = (n);                                     \
+          for (NTH_walk = &(first); NTH_n; NTH_n--)            \
+               NTH_walk = &(*NTH_walk)->next;                  \
+          NTH_walk; })
+
+#define        SWAP(a, b)                                              \
+       ({ typeof(a) SWAP_tmp;                                  \
+          SWAP_tmp = a;                                        \
+          a = b;                                               \
+          b = SWAP_tmp; })
+
+
+/* ----- generic helper functions. maybe move to gui_util later ------------ */
+
+
+static void get_cell_coords(GtkWidget *widget, guint res[4])
+{
+       GtkWidget *tab;
+
+       tab = gtk_widget_get_ancestor(widget, GTK_TYPE_TABLE);
+       gtk_container_child_get(GTK_CONTAINER(tab), widget,
+           "left-attach", res,
+           "right-attach", res+1,
+           "top-attach", res+2,
+           "bottom-attach", res+3, NULL);
+}
+
+
+static void swap_table_cells(GtkWidget *a, GtkWidget *b)
+{
+       GtkWidget *tab_a, *tab_b;
+       guint pos_a[4], pos_b[4];
+
+       tab_a = gtk_widget_get_ancestor(a, GTK_TYPE_TABLE);
+       tab_b = gtk_widget_get_ancestor(b, GTK_TYPE_TABLE);
+       get_cell_coords(a, pos_a);
+       get_cell_coords(b, pos_b);
+       g_object_ref(a);
+       g_object_ref(b);
+       gtk_container_remove(GTK_CONTAINER(tab_a), a);
+       gtk_container_remove(GTK_CONTAINER(tab_b), b);
+       gtk_table_attach_defaults(GTK_TABLE(tab_a), b,
+           pos_a[0], pos_a[1], pos_a[2], pos_a[3]);
+       gtk_table_attach_defaults(GTK_TABLE(tab_b), a,
+           pos_b[0], pos_b[1], pos_b[2], pos_b[3]);
+       g_object_unref(a);
+       g_object_unref(b);
+}
+
+
+/* ----- swap table items -------------------------------------------------- */
+
+
+static void swap_vars(struct table *table, int a, int b)
+{
+       struct var **var_a, **var_b;
+
+       var_a = NTH(table->vars, a);
+       var_b = NTH(table->vars, b);
+
+       swap_table_cells(box_of_label((*var_a)->widget),
+           box_of_label((*var_b)->widget));
+
+       SWAP(*var_a, *var_b);
+       SWAP((*var_a)->next, (*var_b)->next);
+}
+
+
+static void swap_values(struct row *row, int a, int b)
+{
+       struct value **value_a, **value_b;
+
+       value_a = NTH(row->values, a);
+       value_b = NTH(row->values, b);
+
+       swap_table_cells(box_of_label((*value_a)->widget),
+           box_of_label((*value_b)->widget));
+
+       SWAP(*value_a, *value_b);
+       SWAP((*value_a)->next, (*value_b)->next);
+}
+
+
+
+static void swap_cols(struct table *table, int a, int b)
+{
+       struct row *row;
+
+       swap_vars(table, a, b);
+       for (row = table->rows; row; row = row->next)
+               swap_values(row, a, b);
+}
+
+
+static void swap_rows(struct row **a, struct row **b)
+{
+       struct value *value_a, *value_b;
+
+       value_a = (*a)->values;
+       value_b = (*b)->values;
+       while (value_a) {
+               swap_table_cells(box_of_label(value_a->widget),
+                   box_of_label(value_b->widget));
+               value_a = value_a->next;
+               value_b = value_b->next;
+       }
+       SWAP(*a, *b);
+       SWAP((*a)->next, (*b)->next);
+}
+
+
+/* ----- common callback --------------------------------------------------- */
+
+
+static void drag_begin(GtkWidget *widget,
+    GtkTextDirection previous_direction, gpointer user_data)
+{
+       GdkPixbuf *pixbuf;
+
+       /*
+        * Suppress the icon. PixBufs can't be zero-sized, but nobody will
+        * notice a lone pixel either :-)
+        */
+       pixbuf =
+           gdk_pixbuf_get_from_drawable(NULL, DA, NULL, 0, 0, 0, 0, 1, 1);
+       gtk_drag_source_set_icon_pixbuf(widget, pixbuf);
+
+       dragging = user_data;
+}
+
+
+/* ----- drag variables ---------------------------------------------------- */
+
+
+static gboolean drag_var_motion(GtkWidget *widget,
+    GdkDragContext *drag_context, gint x, gint y, guint time_,
+    gpointer user_data)
+{
+       struct var *from = dragging;
+       struct var *to = user_data;
+       int from_n, to_n, i;
+
+       if (from == to || from->table != to->table)
+               return FALSE;
+       from_n = NDX(from->table->vars, from);
+       to_n = NDX(to->table->vars, to);
+       for (i = from_n < to_n ? from_n : to_n;
+           i != (from_n < to_n ? to_n : from_n); i++)
+               swap_cols(from->table, i, i+1);
+       return FALSE;
+}
+
+
+void setup_var_drag(struct var *var)
+{
+       static GtkTargetEntry target = {
+               .target = "var",
+               .flags  = GTK_TARGET_SAME_APP,
+       };
+       GtkWidget *box;
+
+       box = box_of_label(var->widget);
+       gtk_drag_source_set(box, GDK_BUTTON1_MASK,
+           &target, 1, GDK_ACTION_PRIVATE);
+       gtk_drag_dest_set(box, GTK_DEST_DEFAULT_HIGHLIGHT,
+           &target, 1, GDK_ACTION_PRIVATE);
+       g_signal_connect(G_OBJECT(box), "drag-begin",
+           G_CALLBACK(drag_begin), var);
+       g_signal_connect(G_OBJECT(box), "drag-motion",
+           G_CALLBACK(drag_var_motion), var);
+}
+
+
+/* ----- drag values ------------------------------------------------------- */
+
+
+static gboolean drag_value_motion(GtkWidget *widget,
+    GdkDragContext *drag_context, gint x, gint y, guint time_,
+    gpointer user_data)
+{
+       struct value *from = dragging;
+       struct value *to = user_data;
+       struct table *table = from->row->table;
+       struct row **row, *end;
+       int from_n, to_n, i;
+
+       if (table != to->row->table)
+               return FALSE;
+
+       /* columns */
+
+       from_n = NDX(from->row->values, from);
+       to_n = NDX(to->row->values, to);
+       for (i = from_n < to_n ? from_n : to_n;
+           i != (from_n < to_n ? to_n : from_n); i++)
+               swap_cols(table, i, i+1);
+
+       /* rows */
+
+       if (from->row == to->row)
+               return FALSE;
+       row = &table->rows;
+       while (1) {
+               if (*row == from->row) {
+                       end = to->row;
+                       break;
+               }
+               if (*row == to->row) {
+                       end = from->row;
+                       break;
+               }
+               row = &(*row)->next;
+       }
+       while (1) {
+               swap_rows(row, &(*row)->next);
+               if (*row == end)
+                       break;
+               row = &(*row)->next;
+       }
+
+       return FALSE;
+}
+
+
+void setup_value_drag(struct value *value)
+{
+       static GtkTargetEntry target = {
+               .target = "value",
+               .flags  = GTK_TARGET_SAME_APP,
+       };
+       GtkWidget *box;
+
+       box = box_of_label(value->widget);
+       gtk_drag_source_set(box, GDK_BUTTON1_MASK,
+           &target, 1, GDK_ACTION_PRIVATE);
+       gtk_drag_dest_set(box, GTK_DEST_DEFAULT_HIGHLIGHT,
+           &target, 1, GDK_ACTION_PRIVATE);
+       g_signal_connect(G_OBJECT(box), "drag-begin",
+           G_CALLBACK(drag_begin), value);
+       g_signal_connect(G_OBJECT(box), "drag-motion",
+           G_CALLBACK(drag_value_motion), value);
+}

Added: trunk/eda/fped/gui_frame_drag.h
===================================================================
--- trunk/eda/fped/gui_frame_drag.h                             (rev 0)
+++ trunk/eda/fped/gui_frame_drag.h     2010-04-23 13:43:19 UTC (rev 5929)
@@ -0,0 +1,25 @@
+/*
+ * gui_frame_drag.h - GUI, dragging of frame items
+ *
+ * Written 2010 by Werner Almesberger
+ * Copyright 2010 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+
+#ifndef GUI_FRAME_DRAG_H
+#define GUI_FRAME_DRAG_H
+
+#include <gtk/gtk.h>
+
+#include "obj.h"
+
+
+void setup_var_drag(struct var *var);
+void setup_value_drag(struct value *value);
+
+#endif /* !GUI_FRAME_DRAG_H */




--- End Message ---
--- Begin Message ---
Author: werner
Date: 2010-04-24 00:01:56 +0200 (Sat, 24 Apr 2010)
New Revision: 5930

Modified:
   trunk/eda/fped/gui_canvas.c
   trunk/eda/fped/gui_frame.c
   trunk/eda/fped/gui_frame_drag.c
   trunk/eda/fped/gui_frame_drag.h
Log:
Working towards the dragging of frames. Changed the press/drag/release logic of
tables such that items are selected on release and we can thus drag without
selecting. (From a user point of view, selecting would be fine. But selecting 
may sometimes cause a change_world or similar, destroying the widget, which 
upsets drag and drop.)

- gui_frame_drag.c (setup_var_drag, setup_value_drag): moved targets to file
  scope
- gui_frame_drag.c (has_target, drag_var_motion, drag_value_motion): Gtk
  doesn't check target compatibility for us, so we have to do this explicitly
- gui_frame_drag.c (drag_begin): don't leak the pixbuf
- gui_frame_drag.c (is_dragging, drag_end), gui_frame_drag.h: for drag vs.
  activations on button release, we now can test what is being dragged. For
  this, we have to explicitly clear the variable "dragging" when done.
- gui_frame_drag.c (setup_var_drag, setup_value_drag): moved common setup to
  setup_drag_common
- gui_frame_drag.c (setup_frame_drag, drag_frame_motion), gui_frame_drag.h, 
  gui_frame.c (frame_select_event, build_frame_label): added infrastructure for
  dragging frames
- gui_frame_drag.c (setup_canvas_drag, drag_canvas_motion), gui_frame_drag.h,
  gui_canvas.c (motion_notify_event, make_canvas): added infrastructure for
  dragging to the canvas
- gui_frame.c (table_var_select_event, table_value_select_event, build_table):
  split logic into press and release action, so that we can drag without
  implicitly selecting



Modified: trunk/eda/fped/gui_canvas.c
===================================================================
--- trunk/eda/fped/gui_canvas.c 2010-04-23 13:43:19 UTC (rev 5929)
+++ trunk/eda/fped/gui_canvas.c 2010-04-23 22:01:56 UTC (rev 5930)
@@ -24,6 +24,7 @@
 #include "gui_status.h"
 #include "gui_tool.h"
 #include "gui.h"
+#include "gui_frame_drag.h"
 #include "gui_canvas.h"
 
 
@@ -182,7 +183,7 @@
        if (event->state & GDK_BUTTON2_MASK)
                drag_middle(pos);
        update_pos(pos);
-       return TRUE;
+       return FALSE;
 }
 
 
@@ -541,6 +542,8 @@
 
        gtk_widget_set_double_buffered(canvas, FALSE);
 
+       setup_canvas_drag(canvas);
+
        draw_ctx.widget = canvas;
 
        return canvas;

Modified: trunk/eda/fped/gui_frame.c
===================================================================
--- trunk/eda/fped/gui_frame.c  2010-04-23 13:43:19 UTC (rev 5929)
+++ trunk/eda/fped/gui_frame.c  2010-04-23 22:01:56 UTC (rev 5930)
@@ -886,30 +886,59 @@
 }
 
 
-static gboolean table_var_select_event(GtkWidget *widget,
+static gboolean table_var_press_event(GtkWidget *widget,
     GdkEventButton *event, gpointer data)
 {
        struct var *var = data;
 
        switch (event->button) {
+       case 3:
+               pop_up_table_var(var, event);
+               return TRUE;
+       }
+       return FALSE;
+}
+
+
+static gboolean table_var_release_event(GtkWidget *widget,
+    GdkEventButton *event, gpointer data)
+{
+       struct var *var = data;
+
+       switch (event->button) {
        case 1:
+               if (is_dragging(var))
+                       return FALSE;
                edit_var(var, set_col_values, var, -1);
-               return FALSE;
+               return TRUE;
+       }
+       return FALSE;
+}
+
+
+static gboolean table_value_press_event(GtkWidget *widget,
+    GdkEventButton *event, gpointer data)
+{
+       struct value *value = data;
+
+       switch (event->button) {
        case 3:
-               pop_up_table_var(var, event);
-               break;
+               pop_up_table_value(value, event);
+               return TRUE;
        }
-       return TRUE;
+       return FALSE;
 }
 
 
-static gboolean table_value_select_event(GtkWidget *widget,
+static gboolean table_value_release_event(GtkWidget *widget,
     GdkEventButton *event, gpointer data)
 {
        struct value *value = data;
 
        switch (event->button) {
        case 1:
+               if (is_dragging(value))
+                       return FALSE;
                if (!value->row ||
                    value->row->table->active_row == value->row) {
                        edit_nothing();
@@ -919,12 +948,9 @@
                        select_row(value->row);
                        change_world();
                }
-               return FALSE;
-       case 3:
-               pop_up_table_value(value, event);
-               break;
+               return TRUE;
        }
-       return TRUE;
+       return FALSE;
 }
 
 
@@ -1009,8 +1035,11 @@
                label_in_box_bg(field, COLOR_VAR_PASSIVE);
                g_signal_connect(G_OBJECT(box_of_label(field)),
                    "button_press_event",
-                   G_CALLBACK(table_var_select_event), var);
+                   G_CALLBACK(table_var_press_event), var);
                g_signal_connect(G_OBJECT(box_of_label(field)),
+                   "button_release_event",
+                   G_CALLBACK(table_var_release_event), var);
+               g_signal_connect(G_OBJECT(box_of_label(field)),
                    "scroll_event",
                    G_CALLBACK(table_scroll_event), table);
                var->widget = field;
@@ -1034,8 +1063,11 @@
                            COLOR_ROW_SELECTED : COLOR_ROW_UNSELECTED);
                        g_signal_connect(G_OBJECT(box_of_label(field)),
                            "button_press_event",
-                           G_CALLBACK(table_value_select_event), value);
+                           G_CALLBACK(table_value_press_event), value);
                        g_signal_connect(G_OBJECT(box_of_label(field)),
+                           "button_release_event",
+                           G_CALLBACK(table_value_release_event), value);
+                       g_signal_connect(G_OBJECT(box_of_label(field)),
                            "scroll_event",
                            G_CALLBACK(table_scroll_event), table);
                        value->widget = field;
@@ -1653,13 +1685,29 @@
 }
 
 
-static gboolean frame_select_event(GtkWidget *widget, GdkEventButton *event,
+static gboolean frame_press_event(GtkWidget *widget, GdkEventButton *event,
     gpointer data)
 {
        struct frame *frame = data;
 
        switch (event->button) {
+       case 3:
+               pop_up_frame(frame, event);
+               return TRUE;
+       }
+       return FALSE;
+}
+
+
+static gboolean frame_release_event(GtkWidget *widget, GdkEventButton *event,
+    gpointer data)
+{
+       struct frame *frame = data;
+
+       switch (event->button) {
        case 1:
+               if (is_dragging(frame))
+                       return FALSE;
                if (active_frame != frame)
                        select_frame(frame);
                else {
@@ -1668,12 +1716,9 @@
                                edit_frame(frame);
                        }
                }
-               break;
-       case 3:
-               pop_up_frame(frame, event);
-               break;
+               return TRUE;
        }
-       return TRUE;
+       return FALSE;
 }
 
 
@@ -1691,9 +1736,13 @@
            COLOR_FRAME_SELECTED : COLOR_FRAME_UNSELECTED);
 
        g_signal_connect(G_OBJECT(box_of_label(label)),
-           "button_press_event", G_CALLBACK(frame_select_event), frame);
+           "button_press_event", G_CALLBACK(frame_press_event), frame);
+       g_signal_connect(G_OBJECT(box_of_label(label)),
+           "button_release_event", G_CALLBACK(frame_release_event), frame);
        frame->label = label;
 
+       setup_frame_drag(frame);
+
        return box_of_label(label);
 }
 

Modified: trunk/eda/fped/gui_frame_drag.c
===================================================================
--- trunk/eda/fped/gui_frame_drag.c     2010-04-23 13:43:19 UTC (rev 5929)
+++ trunk/eda/fped/gui_frame_drag.c     2010-04-23 22:01:56 UTC (rev 5930)
@@ -18,12 +18,49 @@
 #include "gui_frame_drag.h"
 
 
+enum {
+       target_id_var,
+       target_id_value,
+       target_id_frame,
+       target_id_canvas,
+};
+
+
+static GtkTargetEntry target_var = {
+       .target = "var",
+       .flags  = GTK_TARGET_SAME_APP,
+       .info   = target_id_var,
+};
+
+static GtkTargetEntry target_value = {
+       .target = "value",
+       .flags  = GTK_TARGET_SAME_APP,
+       .info   = target_id_value,
+};
+
+static GtkTargetEntry target_frame = {
+       .target = "frame",
+       .flags  = GTK_TARGET_SAME_APP,
+       .info   = target_id_frame,
+};
+
+
+/* ----- dragging status --------------------------------------------------- */
+
+
 /*
- * Pointer to whatever it is we're dragging. Undefined if not dragging.
+ * Pointer to whatever it is we're dragging. NULL if not dragging.
  */
+
 static void *dragging;
 
 
+int is_dragging(void *this)
+{
+       return this == dragging;
+}
+
+
 /* ----- helper functions for indexed list and swapping -------------------- */
 
 
@@ -148,9 +185,29 @@
 }
 
 
-/* ----- common callback --------------------------------------------------- */
+/* ----- common functions -------------------------------------------------- */
 
 
+/*
+ * according to
+ * 
http://www.pubbs.net/201004/gtk/22819-re-drag-and-drop-drag-motion-cursor-lockup-fixed-.html
+ * http://www.cryingwolf.org/articles/gtk-dnd.html
+ */
+
+static int has_target(GtkWidget *widget, GdkDragContext *drag_context,
+    const char *name)
+{
+       GdkAtom target;
+
+       target = gtk_drag_dest_find_target(widget, drag_context, NULL);
+
+       /*
+        * Force allocation so that we don't have to check for GDK_NONE.
+        */
+       return target == gdk_atom_intern(name, FALSE);
+}
+
+
 static void drag_begin(GtkWidget *widget,
     GtkTextDirection previous_direction, gpointer user_data)
 {
@@ -163,11 +220,28 @@
        pixbuf =
            gdk_pixbuf_get_from_drawable(NULL, DA, NULL, 0, 0, 0, 0, 1, 1);
        gtk_drag_source_set_icon_pixbuf(widget, pixbuf);
+       g_object_unref(pixbuf);
 
        dragging = user_data;
 }
 
 
+static void drag_end(GtkWidget *widget, GdkDragContext *drag_context,
+    gpointer user_data)
+{
+       dragging = NULL;
+}
+
+
+static void setup_drag_common(GtkWidget *widget, void *user_arg)
+{
+       g_signal_connect(G_OBJECT(widget), "drag-begin",
+           G_CALLBACK(drag_begin), user_arg);
+       g_signal_connect(G_OBJECT(widget), "drag-end",
+           G_CALLBACK(drag_end), user_arg);
+}
+
+
 /* ----- drag variables ---------------------------------------------------- */
 
 
@@ -179,6 +253,8 @@
        struct var *to = user_data;
        int from_n, to_n, i;
 
+       if (!has_target(widget, drag_context, "var"))
+               return FALSE;
        if (from == to || from->table != to->table)
                return FALSE;
        from_n = NDX(from->table->vars, from);
@@ -192,19 +268,14 @@
 
 void setup_var_drag(struct var *var)
 {
-       static GtkTargetEntry target = {
-               .target = "var",
-               .flags  = GTK_TARGET_SAME_APP,
-       };
        GtkWidget *box;
 
        box = box_of_label(var->widget);
        gtk_drag_source_set(box, GDK_BUTTON1_MASK,
-           &target, 1, GDK_ACTION_PRIVATE);
+           &target_var, 1, GDK_ACTION_PRIVATE);
        gtk_drag_dest_set(box, GTK_DEST_DEFAULT_HIGHLIGHT,
-           &target, 1, GDK_ACTION_PRIVATE);
-       g_signal_connect(G_OBJECT(box), "drag-begin",
-           G_CALLBACK(drag_begin), var);
+           &target_var, 1, GDK_ACTION_PRIVATE);
+       setup_drag_common(box, var);
        g_signal_connect(G_OBJECT(box), "drag-motion",
            G_CALLBACK(drag_var_motion), var);
 }
@@ -219,10 +290,13 @@
 {
        struct value *from = dragging;
        struct value *to = user_data;
-       struct table *table = from->row->table;
+       struct table *table;
        struct row **row, *end;
        int from_n, to_n, i;
 
+       if (!has_target(widget, drag_context, "value"))
+               return FALSE;
+       table = from->row->table;
        if (table != to->row->table)
                return FALSE;
 
@@ -263,19 +337,65 @@
 
 void setup_value_drag(struct value *value)
 {
-       static GtkTargetEntry target = {
-               .target = "value",
-               .flags  = GTK_TARGET_SAME_APP,
-       };
        GtkWidget *box;
 
        box = box_of_label(value->widget);
        gtk_drag_source_set(box, GDK_BUTTON1_MASK,
-           &target, 1, GDK_ACTION_PRIVATE);
+           &target_value, 1, GDK_ACTION_PRIVATE);
        gtk_drag_dest_set(box, GTK_DEST_DEFAULT_HIGHLIGHT,
-           &target, 1, GDK_ACTION_PRIVATE);
-       g_signal_connect(G_OBJECT(box), "drag-begin",
-           G_CALLBACK(drag_begin), value);
+           &target_value, 1, GDK_ACTION_PRIVATE);
+       setup_drag_common(box, value);
        g_signal_connect(G_OBJECT(box), "drag-motion",
            G_CALLBACK(drag_value_motion), value);
 }
+
+
+/* ----- drag frame labels ------------------------------------------------- */
+
+
+static gboolean drag_frame_motion(GtkWidget *widget,
+    GdkDragContext *drag_context, gint x, gint y, guint time_,
+    gpointer user_data)
+{
+       if (!has_target(widget, drag_context, "frame"))
+               return FALSE;
+//fprintf(stderr, "frame\n");
+return FALSE;
+}
+
+
+void setup_frame_drag(struct frame *frame)
+{
+       GtkWidget *box;
+
+       box = box_of_label(frame->label);
+       gtk_drag_source_set(box, GDK_BUTTON1_MASK,
+           &target_frame, 1, GDK_ACTION_PRIVATE);
+       setup_drag_common(box, frame);
+       g_signal_connect(G_OBJECT(box), "drag-motion",
+           G_CALLBACK(drag_frame_motion), frame);
+}
+
+
+/* ----- drag to the canvas ------------------------------------------------ */
+
+
+static gboolean drag_canvas_motion(GtkWidget *widget,
+    GdkDragContext *drag_context, gint x, gint y, guint time_,
+    gpointer user_data)
+{
+       if (!has_target(widget, drag_context, "frame"))
+               return FALSE;
+//fprintf(stderr, "canvas\n");
+return FALSE;
+}
+
+
+void setup_canvas_drag(GtkWidget *canvas)
+{
+       gtk_drag_dest_set(canvas, GTK_DEST_DEFAULT_HIGHLIGHT,
+           &target_frame, 1, GDK_ACTION_PRIVATE);
+       setup_drag_common(canvas, NULL);
+       g_signal_connect(G_OBJECT(canvas), "drag-motion",
+           G_CALLBACK(drag_canvas_motion), NULL);
+}

Modified: trunk/eda/fped/gui_frame_drag.h
===================================================================
--- trunk/eda/fped/gui_frame_drag.h     2010-04-23 13:43:19 UTC (rev 5929)
+++ trunk/eda/fped/gui_frame_drag.h     2010-04-23 22:01:56 UTC (rev 5930)
@@ -19,7 +19,11 @@
 #include "obj.h"
 
 
+int is_dragging(void *this);
+
 void setup_var_drag(struct var *var);
 void setup_value_drag(struct value *value);
+void setup_frame_drag(struct frame *frame);
+void setup_canvas_drag(GtkWidget *canvas);
 
 #endif /* !GUI_FRAME_DRAG_H */




--- End Message ---
--- Begin Message ---
Author: werner
Date: 2010-04-24 11:54:32 +0200 (Sat, 24 Apr 2010)
New Revision: 5931

Modified:
   trunk/eda/boom/parser.pl
Log:
KiCad BOMs (.lst) are localized. BOOM's BOM parser so far recognized only the
English version. The commit replaces the parser with a looser version that
looks only for the hash signs, ignoring any text following them.

- boom/parser.pl: added language-tolerant parser mode for KiCad BOMs (reported
  by Igor Almeida)



Modified: trunk/eda/boom/parser.pl
===================================================================
--- trunk/eda/boom/parser.pl    2010-04-23 22:01:56 UTC (rev 5930)
+++ trunk/eda/boom/parser.pl    2010-04-24 09:54:32 UTC (rev 5931)
@@ -347,23 +347,49 @@
 }
 
 
+sub babylonic
+{
+    if ($_[0] =~ /^#/) {
+       $hash++;
+       if ($hash == 2) {
+           $mode = *skip;
+           undef $raw;
+       }
+       return;
+    }
+    &bom($_[0]) if $hash == 1;
+}
+
+
 sub parse
 {
     $mode = *skip;
     while (<>) {
        chop;
-       if (/^#Cmp.*order = Reference/) {
+
+# ----- KiCad BOM parsing. Alas, the BOM is localized, so there are almost no
+# reliable clues for the parser. Below would be good clues for the English
+# version:
+       if (0 && /^#Cmp.*order = Reference/) {
            $mode = *bom;
            next;
        }
-       if (/^#Cmp.*order = Value/) {
+       if (0 && /^#Cmp.*order = Value/) {
            $mode = *skip;
            next;
        }
-       if (/^eeschema \(/) {   # hack to allow loading in any order
+       if (0 && /^eeschema \(/) {      # hack to allow loading in any order
            $mode = *skip;
            next;
        }
+# ----- now an attempt at a "generic" version:
+       if (/^eeschema \(/) {
+           $mode = *babylonic;
+           $hash = 0;
+           $raw = 1;
+           next;
+       }
+# -----
        if (/^EESchema Schematic/) {
            $mode = *eeschema;
            $raw = 1;




--- End Message ---
_______________________________________________
commitlog mailing list
commitlog@lists.openmoko.org
http://lists.openmoko.org/mailman/listinfo/commitlog

Reply via email to