Date:2010-05-30 22:30:24 (9 years 2 months ago)
Author:werner
Commit:d4c4031b9afeb0a1509767bcbfec8a5248cb9866
Message: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



git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5970 99fdad57-331a-0410-800a-d7fa5415bdb3
Files: TODO (1 diff)
gui_frame.c (1 diff)
gui_frame_drag.c (9 diffs)

Change Details

TODO
55  each individual frame 10x.
66
77Minor missing features:
8- reorder frames (can use text editor)
98- reorder variables in a frame (can use text editor)
109- move items/vectors up and down the hierarchy
1110
gui_frame.c
17341734        "button_release_event", G_CALLBACK(frame_release_event), frame);
17351735    frame->label = label;
17361736
1737    setup_frame_drag(frame);
1737    if (frame != frames)
1738        setup_frame_drag(frame);
17381739
17391740    return box_of_label(label);
17401741}
gui_frame_drag.c
1111 */
1212
1313
14#include <assert.h>
1415#include <gtk/gtk.h>
1516
17#include "util.h"
1618#include "obj.h"
1719#include "gui_util.h"
1820#include "gui.h"
...... 
7375}
7476
7577
76/* ----- helper functions for indexed list and swapping -------------------- */
78/* ----- helper functions for indexed list --------------------------------- */
7779
7880
7981#define NDX(first, item) \
...... 
9193        NTH_walk = &(*NTH_walk)->next; \
9294       NTH_walk; })
9395
94#define SWAP(a, b) \
95    ({ typeof(a) SWAP_tmp; \
96       SWAP_tmp = a; \
97       a = b; \
98       b = SWAP_tmp; })
99
10096
10197/* ----- generic helper functions. maybe move to gui_util later ------------ */
10298
...... 
136132}
137133
138134
135static GtkWidget *pick_table_cell(GtkWidget *table, int x, int y)
136{
137    GList *children, *walk;
138    GtkWidget *child;
139    guint pos[4];
140
141    children = gtk_container_get_children(GTK_CONTAINER(table));
142    for (walk = children; walk; walk = g_list_next(walk)) {
143        child = g_list_nth_data(walk, 0);
144        assert(child);
145        get_cell_coords(child, pos);
146        if (pos[0] == x && pos[2] == y)
147            break;
148    }
149    g_list_free(children);
150    return walk ? child : NULL;
151}
152
153
154static void swap_table_cells_by_coord(GtkWidget *table_a,
155    int a_col, int a_row, GtkWidget *table_b, int b_col, int b_row)
156{
157    GtkWidget *a, *b;
158
159    a = pick_table_cell(table_a, a_col, a_row);
160    b = pick_table_cell(table_b, b_col, b_row);
161    if (a) {
162        g_object_ref(a);
163            gtk_container_remove(GTK_CONTAINER(table_a), a);
164    }
165    if (b) {
166        g_object_ref(b);
167            gtk_container_remove(GTK_CONTAINER(table_b), b);
168    }
169    if (a)
170            gtk_table_attach_defaults(GTK_TABLE(table_b), a,
171            b_col, b_col+1, b_row, b_row+1);
172    if (b)
173            gtk_table_attach_defaults(GTK_TABLE(table_a), b,
174            a_col, a_col+1, a_row, a_row+1);
175    if (a)
176            g_object_unref(a);
177    if (b)
178            g_object_unref(b);
179}
180
181
182static void swap_table_rows(GtkWidget *table, int a, int b)
183{
184    guint cols;
185    int i;
186
187    g_object_get(table, "n-columns", &cols, NULL);
188    for (i = 0; i != cols; i++)
189        swap_table_cells_by_coord(table, i, a, table, i, b);
190}
191
192
139193/* ----- swap table items -------------------------------------------------- */
140194
141195
...... 
149203    swap_table_cells(box_of_label((*var_a)->widget),
150204        box_of_label((*var_b)->widget));
151205
152    SWAP(*var_a, *var_b);
153    SWAP((*var_a)->next, (*var_b)->next);
206    swap(*var_a, *var_b);
207    swap((*var_a)->next, (*var_b)->next);
154208}
155209
156210
...... 
164218    swap_table_cells(box_of_label((*value_a)->widget),
165219        box_of_label((*value_b)->widget));
166220
167    SWAP(*value_a, *value_b);
168    SWAP((*value_a)->next, (*value_b)->next);
221    swap(*value_a, *value_b);
222    swap((*value_a)->next, (*value_b)->next);
169223}
170224
171225
...... 
192246        value_a = value_a->next;
193247        value_b = value_b->next;
194248    }
195    SWAP(*a, *b);
196    SWAP((*a)->next, (*b)->next);
249    swap(*a, *b);
250    swap((*a)->next, (*b)->next);
251}
252
253
254/* ----- swap frames ------------------------------------------------------- */
255
256
257static void swap_frames(GtkWidget *table, int a, int b)
258{
259    struct frame **frame_a = NTH(frames, a);
260    struct frame **frame_b = NTH(frames, b);
261
262    swap_table_rows(table, 2*a+1, 2*b+1);
263    swap_table_rows(table, 2*a+2, 2*b+2);
264
265    swap(*frame_a, *frame_b);
266    swap((*frame_a)->next, (*frame_b)->next);
197267}
198268
199269
...... 
410480    GdkDragContext *drag_context, gint x, gint y, guint time_,
411481    gpointer user_data)
412482{
483    struct frame *from = dragging;
484    struct frame *to = user_data;
485    int from_n, to_n, i;
486
413487    if (!has_target(widget, drag_context, "frame"))
414488        return FALSE;
415    /* nothing else to do yet */
489    assert(from != frames);
490    assert(to != frames);
491    from_n = NDX(frames, from);
492    to_n = NDX(frames, to);
493    for (i = from_n < to_n ? from_n : to_n;
494        i != (from_n < to_n ? to_n : from_n); i++)
495        swap_frames(gtk_widget_get_ancestor(widget, GTK_TYPE_TABLE),
496            i, i+1);
416497    return FALSE;
417498}
418499
...... 
431512
432513    box = box_of_label(frame->label);
433514    gtk_drag_source_set(box, GDK_BUTTON1_MASK,
434        &target_frame, 1, GDK_ACTION_COPY);
515        &target_frame, 1, GDK_ACTION_COPY | GDK_ACTION_MOVE);
516    gtk_drag_dest_set(box, GTK_DEST_DEFAULT_MOTION,
517        &target_frame, 1, GDK_ACTION_MOVE);
435518    setup_drag_common(box, frame);
436519
437520    /* override */

Archive Download the corresponding diff file

Branches:
master



interactive