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. r5970 - trunk/eda/fped (wer...@docs.openmoko.org)
   2. r5971 - trunk/eda/fped (wer...@docs.openmoko.org)
--- Begin Message ---
Author: werner
Date: 2010-05-30 22:30:24 +0200 (Sun, 30 May 2010)
New Revision: 5970

Modified:
   trunk/eda/fped/TODO
   trunk/eda/fped/gui_frame.c
   trunk/eda/fped/gui_frame_drag.c
Log:
Added support for reordering frames in the GUI.

- gui_frame.c (build_frame_label): the root frame doesn't participate in any
  form of dragging, so we don't set up dragging for it at all
- gui_frame_drag.c (pick_table_cell, swap_table_cells_by_coord, 
  swap_table_rows): helper functions for swapping rows in a Gtk table
- gui_frame_drag.c (swap_frames, drag_frame_motion, setup_frame_drag): added
  support for reordering of frames by dragging
- gui_frame_drag.c (SWAP, swap_vars, swap_values, swap_rows): removed SWAP(). 
  Use swap() from util.h instead.
- TODO: removed frame ordering entry



Modified: trunk/eda/fped/TODO
===================================================================
--- trunk/eda/fped/TODO 2010-05-30 09:49:14 UTC (rev 5969)
+++ trunk/eda/fped/TODO 2010-05-30 20:30:24 UTC (rev 5970)
@@ -5,7 +5,6 @@
   each individual frame 10x.
 
 Minor missing features:
-- reorder frames (can use text editor)
 - 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-05-30 09:49:14 UTC (rev 5969)
+++ trunk/eda/fped/gui_frame.c  2010-05-30 20:30:24 UTC (rev 5970)
@@ -1734,7 +1734,8 @@
            "button_release_event", G_CALLBACK(frame_release_event), frame);
        frame->label = label;
 
-       setup_frame_drag(frame);
+       if (frame != frames)
+               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-05-30 09:49:14 UTC (rev 5969)
+++ trunk/eda/fped/gui_frame_drag.c     2010-05-30 20:30:24 UTC (rev 5970)
@@ -11,8 +11,10 @@
  */
 
 
+#include <assert.h>
 #include <gtk/gtk.h>
 
+#include "util.h"
 #include "obj.h"
 #include "gui_util.h"
 #include "gui.h"
@@ -73,7 +75,7 @@
 }
 
 
-/* ----- helper functions for indexed list and swapping -------------------- */
+/* ----- helper functions for indexed list --------------------------------- */
 
 
 #define NDX(first, item)                                       \
@@ -91,13 +93,7 @@
                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 ------------ */
 
 
@@ -136,6 +132,64 @@
 }
 
 
+static GtkWidget *pick_table_cell(GtkWidget *table, int x, int y)
+{
+       GList *children, *walk;
+       GtkWidget *child;
+       guint pos[4];
+
+       children = gtk_container_get_children(GTK_CONTAINER(table));
+       for (walk = children; walk; walk = g_list_next(walk)) {
+               child = g_list_nth_data(walk, 0);
+               assert(child);
+               get_cell_coords(child, pos);
+               if (pos[0] == x && pos[2] == y)
+                       break;
+       }
+       g_list_free(children);
+       return walk ? child : NULL;
+}
+
+
+static void swap_table_cells_by_coord(GtkWidget *table_a,
+    int a_col, int a_row, GtkWidget *table_b, int b_col, int b_row)
+{
+       GtkWidget *a, *b;
+
+       a = pick_table_cell(table_a, a_col, a_row);
+       b = pick_table_cell(table_b, b_col, b_row);
+       if (a) {
+               g_object_ref(a);
+               gtk_container_remove(GTK_CONTAINER(table_a), a);
+       }
+       if (b) {
+               g_object_ref(b);
+               gtk_container_remove(GTK_CONTAINER(table_b), b);
+       }
+       if (a)
+               gtk_table_attach_defaults(GTK_TABLE(table_b), a,
+                   b_col, b_col+1, b_row, b_row+1);
+       if (b)
+               gtk_table_attach_defaults(GTK_TABLE(table_a), b,
+                   a_col, a_col+1, a_row, a_row+1);
+       if (a)
+               g_object_unref(a);
+       if (b)
+               g_object_unref(b);
+}
+
+
+static void swap_table_rows(GtkWidget *table, int a, int b)
+{
+       guint cols;
+       int i;
+
+       g_object_get(table, "n-columns", &cols, NULL);
+       for (i = 0; i != cols; i++)
+               swap_table_cells_by_coord(table, i, a, table, i, b);
+}
+
+
 /* ----- swap table items -------------------------------------------------- */
 
 
@@ -149,8 +203,8 @@
        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);
+       swap(*var_a, *var_b);
+       swap((*var_a)->next, (*var_b)->next);
 }
 
 
@@ -164,8 +218,8 @@
        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);
+       swap(*value_a, *value_b);
+       swap((*value_a)->next, (*value_b)->next);
 }
 
 
@@ -192,11 +246,27 @@
                value_a = value_a->next;
                value_b = value_b->next;
        }
-       SWAP(*a, *b);
-       SWAP((*a)->next, (*b)->next);
+       swap(*a, *b);
+       swap((*a)->next, (*b)->next);
 }
 
 
+/* ----- swap frames ------------------------------------------------------- */
+
+
+static void swap_frames(GtkWidget *table, int a, int b)
+{
+       struct frame **frame_a = NTH(frames, a);
+       struct frame **frame_b = NTH(frames, b);
+
+       swap_table_rows(table, 2*a+1, 2*b+1);
+       swap_table_rows(table, 2*a+2, 2*b+2);
+
+       swap(*frame_a, *frame_b);
+       swap((*frame_a)->next, (*frame_b)->next);
+}
+
+
 /* ----- common functions -------------------------------------------------- */
 
 
@@ -410,9 +480,20 @@
     GdkDragContext *drag_context, gint x, gint y, guint time_,
     gpointer user_data)
 {
+       struct frame *from = dragging;
+       struct frame *to = user_data;
+       int from_n, to_n, i;
+
        if (!has_target(widget, drag_context, "frame"))
                return FALSE;
-       /* nothing else to do yet */
+       assert(from != frames);
+       assert(to != frames);
+       from_n = NDX(frames, from);
+       to_n = NDX(frames, to);
+       for (i = from_n < to_n ? from_n : to_n;
+           i != (from_n < to_n ? to_n : from_n); i++)
+               swap_frames(gtk_widget_get_ancestor(widget, GTK_TYPE_TABLE),
+                   i, i+1);
        return FALSE;
 }
 
@@ -431,7 +512,9 @@
 
        box = box_of_label(frame->label);
        gtk_drag_source_set(box, GDK_BUTTON1_MASK,
-           &target_frame, 1, GDK_ACTION_COPY);
+           &target_frame, 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
+       gtk_drag_dest_set(box, GTK_DEST_DEFAULT_MOTION,
+           &target_frame, 1, GDK_ACTION_MOVE);
        setup_drag_common(box, frame);
 
        /* override */




--- End Message ---
--- Begin Message ---
Author: werner
Date: 2010-05-31 07:53:56 +0200 (Mon, 31 May 2010)
New Revision: 5971

Modified:
   trunk/eda/fped/TODO
   trunk/eda/fped/coord.c
   trunk/eda/fped/gui_frame_drag.c
   trunk/eda/fped/gui_meas.c
   trunk/eda/fped/gui_util.c
   trunk/eda/fped/util.h
Log:
A bit of cleanup.

- gui_frame_drag.c (FOR_UNORDERED, drag_var_motion, drag_value_motion, 
  drag_frame_motion): moved hard to read loop into helper macro
- capitalized SWAP, to make it clear it's a macro and can multiply side-effects
- TODO: updated discussion of open issues



Modified: trunk/eda/fped/TODO
===================================================================
--- trunk/eda/fped/TODO 2010-05-30 20:30:24 UTC (rev 5970)
+++ trunk/eda/fped/TODO 2010-05-31 05:53:56 UTC (rev 5971)
@@ -53,12 +53,14 @@
   A1: no: would cause confusion in GUI (vectors could become orphaned)
   A2: yes. but we don't change the linkage.
 - Q: how do we handle stacks of objects ?
-  A: we don't but we make it easy to avoid them, by giving a good zoom,
-     flexible selection, and by disallowing stacks of identical objects in the
-     first place.
+  A1: we don't but we make it easy to avoid them, by giving a good zoom,
+      flexible selection, and by disallowing stacks of identical objects in the
+      first place.
+  A2: the current mechanism of selecting the next eligible object when clicking
+      on the same position repeatedly lets one cycle through stacks.
 - Q: add frame arguments ? (e.g., .frame pad(pin_num_offset) ...)
-  we can already approximate this by introducing an intermediate table that
-  sets up the arguments (provided that we don't consider vectors as well)
+  A: we can already approximate this by introducing an intermediate table that
+     sets up the arguments (provided that we don't consider vectors as well)
 - Q: should we make it a requirement to generate objects only once ?
   A: yes.
 

Modified: trunk/eda/fped/coord.c
===================================================================
--- trunk/eda/fped/coord.c      2010-05-30 20:30:24 UTC (rev 5970)
+++ trunk/eda/fped/coord.c      2010-05-31 05:53:56 UTC (rev 5971)
@@ -157,9 +157,9 @@
 void sort_coord(struct coord *min, struct coord *max)
 {
        if (min->x > max->x)
-               swap(min->x, max->x);
+               SWAP(min->x, max->x);
        if (min->y > max->y)
-               swap(min->y, max->y);
+               SWAP(min->y, max->y);
 
 }
 

Modified: trunk/eda/fped/gui_frame_drag.c
===================================================================
--- trunk/eda/fped/gui_frame_drag.c     2010-05-30 20:30:24 UTC (rev 5970)
+++ trunk/eda/fped/gui_frame_drag.c     2010-05-31 05:53:56 UTC (rev 5971)
@@ -93,7 +93,11 @@
                NTH_walk = &(*NTH_walk)->next;                  \
           NTH_walk; })
 
+#define FOR_UNORDERED(var, a, b) \
+       for (var = (a) < (b) ? (a) : (b); var != ((a) < (b) ? (b) : (a)); \
+           var++)
 
+
 /* ----- generic helper functions. maybe move to gui_util later ------------ */
 
 
@@ -203,8 +207,8 @@
        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);
+       SWAP(*var_a, *var_b);
+       SWAP((*var_a)->next, (*var_b)->next);
 }
 
 
@@ -218,12 +222,11 @@
        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);
+       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;
@@ -246,8 +249,8 @@
                value_a = value_a->next;
                value_b = value_b->next;
        }
-       swap(*a, *b);
-       swap((*a)->next, (*b)->next);
+       SWAP(*a, *b);
+       SWAP((*a)->next, (*b)->next);
 }
 
 
@@ -262,8 +265,8 @@
        swap_table_rows(table, 2*a+1, 2*b+1);
        swap_table_rows(table, 2*a+2, 2*b+2);
 
-       swap(*frame_a, *frame_b);
-       swap((*frame_a)->next, (*frame_b)->next);
+       SWAP(*frame_a, *frame_b);
+       SWAP((*frame_a)->next, (*frame_b)->next);
 }
 
 
@@ -341,8 +344,7 @@
                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++)
+       FOR_UNORDERED(i, from_n, to_n)
                swap_cols(from->table, i, i+1);
        return FALSE;
 }
@@ -386,8 +388,7 @@
 
        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++)
+       FOR_UNORDERED(i, from_n, to_n)
                swap_cols(table, i, i+1);
 
        /* rows */
@@ -490,8 +491,7 @@
        assert(to != frames);
        from_n = NDX(frames, from);
        to_n = NDX(frames, to);
-       for (i = from_n < to_n ? from_n : to_n;
-           i != (from_n < to_n ? to_n : from_n); i++)
+       FOR_UNORDERED(i, from_n, to_n)
                swap_frames(gtk_widget_get_ancestor(widget, GTK_TYPE_TABLE),
                    i, i+1);
        return FALSE;

Modified: trunk/eda/fped/gui_meas.c
===================================================================
--- trunk/eda/fped/gui_meas.c   2010-05-30 20:30:24 UTC (rev 5970)
+++ trunk/eda/fped/gui_meas.c   2010-05-31 05:53:56 UTC (rev 5971)
@@ -378,7 +378,7 @@
        a = inst->base;
        b = inst->u.meas.end;
        if (inst->obj->u.meas.inverted)
-               swap(a, b);
+               SWAP(a, b);
        switch (i) {
        case 0:
                mode = meas->type < 3 ? next_to_min : max_to_min;

Modified: trunk/eda/fped/gui_util.c
===================================================================
--- trunk/eda/fped/gui_util.c   2010-05-30 20:30:24 UTC (rev 5970)
+++ trunk/eda/fped/gui_util.c   2010-05-31 05:53:56 UTC (rev 5971)
@@ -68,9 +68,9 @@
        int w, h;
 
        if (xa > xb)
-               swap(xa, xb);
+               SWAP(xa, xb);
        if (ya > yb)
-               swap(ya, yb);
+               SWAP(ya, yb);
        buf = alloc_type(struct pix_buf);
        buf->da = da;
        buf->x = xa-border;

Modified: trunk/eda/fped/util.h
===================================================================
--- trunk/eda/fped/util.h       2010-05-30 20:30:24 UTC (rev 5970)
+++ trunk/eda/fped/util.h       2010-05-31 05:53:56 UTC (rev 5971)
@@ -51,10 +51,10 @@
        strnalloc_tmp[n] = 0;                           \
        strnalloc_tmp; })
 
-#define swap(a, b) \
-    ({ typeof(a) swap_tmp = (a);                       \
+#define SWAP(a, b) \
+    ({ typeof(a) SWAP_tmp = (a);                       \
        (a) = (b);                                      \
-       (b) = swap_tmp; })
+       (b) = SWAP_tmp; })
 
 
 char *stralloc_vprintf(const char *fmt, va_list ap);




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

Reply via email to