1
0
mirror of git://projects.qi-hardware.com/fped.git synced 2024-11-18 05:34:05 +02:00

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
This commit is contained in:
werner 2010-05-30 20:30:24 +00:00
parent 7eb3ac5ba2
commit d4c4031b9a
3 changed files with 100 additions and 17 deletions

1
TODO
View File

@ -5,7 +5,6 @@ Major missing features:
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

View File

@ -1734,6 +1734,7 @@ static GtkWidget *build_frame_label(struct frame *frame)
"button_release_event", G_CALLBACK(frame_release_event), frame);
frame->label = label;
if (frame != frames)
setup_frame_drag(frame);
return box_of_label(label);

View File

@ -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 @@ int is_dragging_anything(void)
}
/* ----- helper functions for indexed list and swapping -------------------- */
/* ----- helper functions for indexed list --------------------------------- */
#define NDX(first, item) \
@ -91,12 +93,6 @@ int is_dragging_anything(void)
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 void swap_table_cells(GtkWidget *a, GtkWidget *b)
}
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 @@ static void swap_vars(struct table *table, int a, int 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);
swap(*var_a, *var_b);
swap((*var_a)->next, (*var_b)->next);
}
@ -164,8 +218,8 @@ static void swap_values(struct row *row, int a, int 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);
swap(*value_a, *value_b);
swap((*value_a)->next, (*value_b)->next);
}
@ -192,8 +246,24 @@ static void swap_rows(struct row **a, struct row **b)
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);
}
@ -410,9 +480,20 @@ static gboolean drag_frame_motion(GtkWidget *widget,
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 @@ void setup_frame_drag(struct frame *frame)
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 */