removed clist flag : GTK_CLIST_DRAG_SELECTION added flags :

Tue Dec 15 22:30:44 1998  Lars Hamann  <lars@gtk.org>

	* gtk/gtkclist.h :
	removed clist flag : GTK_CLIST_DRAG_SELECTION
	added flags : GTK_CLIST_REORDERABLE, GTK_CLIST_USE_DRAG_ICONS,
	GTK_CLIST_DRAW_DRAG_LINE, GTK_CLIST_DRAW_DRAG_RECT
	(GtkCListDragPos) : new enum for DND
 	(GtkButtonAction) : new enum of possible mouse button actions
	(struct _GtkCList): added button_actions array.
 	Added drag_button and click_cell struct, to store cell and
 	mouse button of last button_press_event

	(struct _GtkCListClass): new class method draw_drag_highlight.
	(gtk_clist_set_reorderable) (gtk_clist_set_use_drag_icons) :
	new functions. Moved from gtkctree.h. Now clist is reorderable
	as well.
	(gtk_clist_set_button_actions) new function to customize mouse
	button actions.

	* gtk/gtkclist.c:
	(gtk_clist_drag_begin)
	(gtk_clist_drag_motion)
	(gtk_clist_drag_leave)
	(gtk_clist_drag_end)
	(gtk_clist_drag_drop)
	(gtk_clist_drag_data_get)
	(gtk_clist_drag_data_received) : new dnd widget methods to
	implement clists reorderability via DND

	(remove_grab) : new function. remove mouse grab if necessary.
	(draw_drag_highlight) : new method. Draw dnd highlight depending
	on clist flags GTK_CLIST_DRAW_DRAG_LINE and GTK_CLIST_DRAW_DRAG_RECT

	(gtk_clist_class_init): added object args "reorderable" and
 	"use_drag_icons"

	(gtk_clist_button_press) (gtk_clist_button_release) :
	use button_actions array to decide which action to perform.
	(gtk_clist_motion) : start reorder operation if necessary.

	* gtk/gtkctree.h :
	(struct _GtkCTree): removed drag_icon, icon_widht, icon_height,
	drag_row, drag_source, drag_target, reorderable, use_icons,
	in_drag, drag_rect
	(gtk_ctree_set_reorderable) :  deprecated function.
 	use gtk_clist_set_reorderable instead.
	(gtk_ctree_set_use_drag_icons) : deprecated function.
 	use gtk_clist_set_use_drag_icons instead.

	* gtk/gtkctree.c :
	(gtk_ctree_class_init): removed object args "reorderable" and
	and "use_drag_icons"

	(draw_xor_line) (draw_xor_rect) (create_drag_icon) (check_cursor)
	(tree_toggle_selection) (set_mouse_cursor) : removed

	(draw_drag_highlight) : new clist method. replacement for
	draw_xor_line and draw_xor_rect functions
	(check_drag) renamed check_cursor function

	(gtk_ctree_drag_begin)
	(gtk_ctree_drag_motion)
	(gtk_ctree_drag_data_received) : new dnd methods to implement ctrees
	reorderability via DND

	(gtk_ctree_button_release)
	(gtk_ctree_button_motion) : removed.

	* gtk/testgtk.c:
	(create_clist) : added new reorderable toggle button
This commit is contained in:
Lars Hamann 1998-12-16 01:28:31 +00:00 committed by Owen Taylor
parent 1566d98867
commit 8a202e6f5b
6 changed files with 1584 additions and 1252 deletions

File diff suppressed because it is too large Load Diff

View File

@ -36,14 +36,17 @@ extern "C" {
/* clist flags */
enum
{
GTK_CLIST_IN_DRAG = 1 << 0,
GTK_CLIST_DRAG_SELECTION = 1 << 1,
GTK_CLIST_ROW_HEIGHT_SET = 1 << 2,
GTK_CLIST_SHOW_TITLES = 1 << 3,
GTK_CLIST_CHILD_HAS_FOCUS = 1 << 4,
GTK_CLIST_ADD_MODE = 1 << 5,
GTK_CLIST_AUTO_SORT = 1 << 6,
GTK_CLIST_AUTO_RESIZE_BLOCKED = 1 << 7
GTK_CLIST_IN_DRAG = 1 << 0,
GTK_CLIST_ROW_HEIGHT_SET = 1 << 1,
GTK_CLIST_SHOW_TITLES = 1 << 2,
GTK_CLIST_CHILD_HAS_FOCUS = 1 << 3,
GTK_CLIST_ADD_MODE = 1 << 4,
GTK_CLIST_AUTO_SORT = 1 << 5,
GTK_CLIST_AUTO_RESIZE_BLOCKED = 1 << 6,
GTK_CLIST_REORDERABLE = 1 << 7,
GTK_CLIST_USE_DRAG_ICONS = 1 << 8,
GTK_CLIST_DRAW_DRAG_LINE = 1 << 9,
GTK_CLIST_DRAW_DRAG_RECT = 1 << 10
};
/* cell types */
@ -56,6 +59,22 @@ typedef enum
GTK_CELL_WIDGET
} GtkCellType;
typedef enum
{
GTK_CLIST_DRAG_NONE,
GTK_CLIST_DRAG_BEFORE,
GTK_CLIST_DRAG_INTO,
GTK_CLIST_DRAG_AFTER
} GtkCListDragPos;
typedef enum
{
GTK_BUTTON_IGNORED = 0,
GTK_BUTTON_SELECTS = 1 << 0,
GTK_BUTTON_DRAGS = 1 << 1,
GTK_BUTTON_EXPANDS = 1 << 2
} GtkButtonAction;
#define GTK_TYPE_CLIST (gtk_clist_get_type ())
#define GTK_CLIST(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_CLIST, GtkCList))
#define GTK_CLIST_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_CLIST, GtkCListClass))
@ -70,10 +89,13 @@ typedef enum
#define GTK_CLIST_ROW_HEIGHT_SET(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_ROW_HEIGHT_SET)
#define GTK_CLIST_SHOW_TITLES(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_SHOW_TITLES)
#define GTK_CLIST_CHILD_HAS_FOCUS(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_CHILD_HAS_FOCUS)
#define GTK_CLIST_DRAG_SELECTION(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_DRAG_SELECTION)
#define GTK_CLIST_ADD_MODE(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_ADD_MODE)
#define GTK_CLIST_AUTO_SORT(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_AUTO_SORT)
#define GTK_CLIST_AUTO_RESIZE_BLOCKED(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_AUTO_RESIZE_BLOCKED)
#define GTK_CLIST_REORDERABLE(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_REORDERABLE)
#define GTK_CLIST_USE_DRAG_ICONS(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_USE_DRAG_ICONS)
#define GTK_CLIST_DRAW_DRAG_LINE(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_DRAW_DRAG_LINE)
#define GTK_CLIST_DRAW_DRAG_RECT(clist) (GTK_CLIST_FLAGS (clist) & GTK_CLIST_DRAW_DRAG_RECT)
#define GTK_CLIST_ROW(_glist_) ((GtkCListRow *)((_glist_)->data))
@ -98,6 +120,21 @@ typedef gint (*GtkCListCompareFunc) (GtkCList *clist,
gconstpointer ptr1,
gconstpointer ptr2);
typedef struct _GtkCListCellInfo GtkCListCellInfo;
typedef struct _GtkCListDestInfo GtkCListDestInfo;
struct _GtkCListCellInfo
{
gint row;
gint column;
};
struct _GtkCListDestInfo
{
GtkCListCellInfo cell;
GtkCListDragPos insert_pos;
};
struct _GtkCList
{
GtkContainer container;
@ -153,6 +190,14 @@ struct _GtkCList
GList *undo_unselection;
gint undo_anchor;
/* mouse buttons */
guint8 button_actions[5];
guint8 drag_button;
/* dnd */
GtkCListCellInfo click_cell;
/* scroll adjustments */
GtkAdjustment *hadjustment;
GtkAdjustment *vadjustment;
@ -236,6 +281,10 @@ struct _GtkCListClass
GdkRectangle *area,
gint row,
GtkCListRow *clist_row);
void (*draw_drag_highlight) (GtkCList *clist,
GtkCListRow *target_row,
gint target_row_number,
GtkCListDragPos drag_pos);
void (*clear) (GtkCList *clist);
void (*fake_unselect_all) (GtkCList *clist,
gint row);
@ -257,6 +306,7 @@ struct _GtkCListClass
GtkCListRow *clist_row,
gint column,
GtkRequisition *requisition);
};
struct _GtkCListColumn
@ -407,6 +457,15 @@ void gtk_clist_set_shadow_type (GtkCList *clist,
void gtk_clist_set_selection_mode (GtkCList *clist,
GtkSelectionMode mode);
/* enable clists reorder ability */
void gtk_clist_set_reorderable (GtkCList *clist,
gboolean reorderable);
void gtk_clist_set_use_drag_icons (GtkCList *clist,
gboolean use_icons);
void gtk_clist_set_button_actions (GtkCList *clist,
guint button,
guint8 button_actions);
/* freeze all visual updates of the list, and then thaw the list after
* you have made a number of changes and the updates wil occure in a
* more efficent mannor than if you made them on a unfrozen list

File diff suppressed because it is too large Load Diff

View File

@ -100,22 +100,11 @@ struct _GtkCTree
GtkCList clist;
GdkGC *lines_gc;
GdkWindow *drag_icon;
gint icon_width;
gint icon_height;
gint tree_indent;
gint tree_spacing;
gint tree_column;
gint drag_row;
GtkCTreeNode *drag_source;
GtkCTreeNode *drag_target;
gint insert_pos;
guint reorderable : 1;
guint use_icons : 1;
guint in_drag : 1;
guint drag_rect : 1;
guint line_style : 2;
guint expander_style : 2;
guint show_stub : 1;
@ -418,10 +407,6 @@ void gtk_ctree_set_spacing (GtkCTree *ctree,
gint spacing);
void gtk_ctree_set_show_stub (GtkCTree *ctree,
gboolean show_stub);
void gtk_ctree_set_reorderable (GtkCTree *ctree,
gboolean reorderable);
void gtk_ctree_set_use_drag_icons (GtkCTree *ctree,
gboolean use_icons);
void gtk_ctree_set_line_style (GtkCTree *ctree,
GtkCTreeLineStyle line_style);
void gtk_ctree_set_expander_style (GtkCTree *ctree,
@ -442,7 +427,10 @@ void gtk_ctree_sort_recursive (GtkCTree *ctree,
/* deprecated*/
void gtk_ctree_show_stub (GtkCTree *ctree,
gboolean show_stub);
void gtk_ctree_set_reorderable (GtkCTree *ctree,
gboolean reorderable);
void gtk_ctree_set_use_drag_icons (GtkCTree *ctree,
gboolean use_icons);
#ifdef __cplusplus

View File

@ -3722,6 +3722,11 @@ hide_titles_clist (GtkWidget *widget, gpointer data)
gtk_clist_column_titles_hide (GTK_CLIST (data));
}
void toggle_reorderable (GtkWidget *widget, GtkCList *clist)
{
gtk_clist_set_reorderable (clist, GTK_TOGGLE_BUTTON (widget)->active);
}
void
select_clist (GtkWidget *widget,
gint row,
@ -3995,6 +4000,7 @@ create_clist (void)
GtkWidget *button;
GtkWidget *separator;
GtkWidget *scrolled_win;
GtkWidget *check;
GtkWidget *undo_button;
GtkWidget *label;
@ -4097,6 +4103,12 @@ create_clist (void)
gtk_signal_connect (GTK_OBJECT (undo_button), "clicked",
(GtkSignalFunc) undo_selection, (gpointer) clist);
check = gtk_check_button_new_with_label ("Reorderable");
gtk_signal_connect (GTK_OBJECT (check), "clicked",
GTK_SIGNAL_FUNC (toggle_reorderable), clist);
gtk_box_pack_start (GTK_BOX (box2), check, FALSE, TRUE, 0);
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (check), TRUE);
label = gtk_label_new ("Selection Mode :");
gtk_box_pack_start (GTK_BOX (box2), label, FALSE, TRUE, 0);
@ -4112,18 +4124,6 @@ create_clist (void)
* the rest of the clist configuration
*/
/*
gtk_signal_connect (GTK_OBJECT (clist),
"select_row",
(GtkSignalFunc) select_clist,
undo_button);
gtk_signal_connect (GTK_OBJECT (clist),
"unselect_row",
(GtkSignalFunc) unselect_clist,
undo_button);
*/
gtk_clist_set_row_height (GTK_CLIST (clist), 18);
gtk_widget_set_usize (clist, -1, 300);
@ -4275,74 +4275,6 @@ void after_move (GtkCTree *ctree, GtkCTreeNode *child, GtkCTreeNode *parent,
(parent) ? target1 : "nil", (sibling) ? target2 : "nil");
}
gint button_press (GtkCTree *ctree, GdkEventButton *event, gpointer data)
{
gint row;
gint column;
GtkCTreeNode *work;
gint res;
res = gtk_clist_get_selection_info (GTK_CLIST (ctree), event->x, event->y,
&row, &column);
if (!res && event->button != 3)
return FALSE;
work = GTK_CTREE_NODE (g_list_nth (GTK_CLIST (ctree)->row_list, row));
switch (event->button)
{
case 1:
if (GTK_CLIST (ctree)->selection_mode == GTK_SELECTION_MULTIPLE &&
event->state & GDK_SHIFT_MASK)
gtk_signal_emit_stop_by_name (GTK_OBJECT (ctree),"button_press_event");
break;
case 2:
if (GTK_CTREE_ROW (work)->children &&
gtk_ctree_is_hot_spot (ctree, event->x, event->y))
{
if (GTK_CTREE_ROW (work)->expanded)
gtk_ctree_collapse_recursive (ctree, work);
else
gtk_ctree_expand_recursive (ctree, work);
after_press (ctree, NULL);
gtk_signal_emit_stop_by_name (GTK_OBJECT (ctree),
"button_press_event");
}
break;
default:
break;
}
return FALSE;
}
gint button_release (GtkCTree *ctree, GdkEventButton *event, gpointer data)
{
gint row;
gint column;
GtkCTreeNode *work;
gint res;
res = gtk_clist_get_selection_info (GTK_CLIST (ctree), event->x, event->y,
&row, &column);
if (!res || event->button != 1)
return FALSE;
work = GTK_CTREE_NODE (g_list_nth (GTK_CLIST (ctree)->row_list, row));
if (GTK_CLIST (ctree)->selection_mode == GTK_SELECTION_MULTIPLE &&
event->state & GDK_SHIFT_MASK)
{
if (GTK_CTREE_ROW (work)->row.state == GTK_STATE_SELECTED)
gtk_ctree_unselect_recursive (ctree, work);
else
gtk_ctree_select_recursive (ctree, work);
after_press (ctree, NULL);
gtk_signal_emit_stop_by_name (GTK_OBJECT (ctree),
"button_release_event");
}
return FALSE;
}
void count_items (GtkCTree *ctree, GtkCTreeNode *list)
{
if (GTK_CTREE_ROW (list)->is_leaf)
@ -4616,11 +4548,6 @@ void change_row_height (GtkWidget *widget, GtkCList *clist)
gtk_clist_set_row_height (clist, GTK_ADJUSTMENT (widget)->value);
}
void toggle_reorderable (GtkWidget *widget, GtkCTree *ctree)
{
gtk_ctree_set_reorderable (ctree, GTK_TOGGLE_BUTTON (widget)->active);
}
void set_background (GtkCTree *ctree, GtkCTreeNode *node, gpointer data)
{
GtkStyle *style = NULL;
@ -4953,16 +4880,11 @@ void create_ctree (void)
gtk_ctree_set_line_style (ctree, GTK_CTREE_LINES_DOTTED);
line_style = GTK_CTREE_LINES_DOTTED;
gtk_ctree_set_reorderable (ctree, TRUE);
gtk_signal_connect (GTK_OBJECT (ctree), "click_column",
(GtkSignalFunc) ctree_click_column,
NULL);
gtk_signal_connect (GTK_OBJECT (ctree), "button_press_event",
GTK_SIGNAL_FUNC (button_press), NULL);
gtk_signal_connect_after (GTK_OBJECT (ctree), "button_press_event",
GTK_SIGNAL_FUNC (after_press), NULL);
gtk_signal_connect (GTK_OBJECT (ctree), "button_release_event",
GTK_SIGNAL_FUNC (button_release), NULL);
gtk_signal_connect_after (GTK_OBJECT (ctree), "button_release_event",
GTK_SIGNAL_FUNC (after_press), NULL);
gtk_signal_connect_after (GTK_OBJECT (ctree), "tree_move",

View File

@ -3722,6 +3722,11 @@ hide_titles_clist (GtkWidget *widget, gpointer data)
gtk_clist_column_titles_hide (GTK_CLIST (data));
}
void toggle_reorderable (GtkWidget *widget, GtkCList *clist)
{
gtk_clist_set_reorderable (clist, GTK_TOGGLE_BUTTON (widget)->active);
}
void
select_clist (GtkWidget *widget,
gint row,
@ -3995,6 +4000,7 @@ create_clist (void)
GtkWidget *button;
GtkWidget *separator;
GtkWidget *scrolled_win;
GtkWidget *check;
GtkWidget *undo_button;
GtkWidget *label;
@ -4097,6 +4103,12 @@ create_clist (void)
gtk_signal_connect (GTK_OBJECT (undo_button), "clicked",
(GtkSignalFunc) undo_selection, (gpointer) clist);
check = gtk_check_button_new_with_label ("Reorderable");
gtk_signal_connect (GTK_OBJECT (check), "clicked",
GTK_SIGNAL_FUNC (toggle_reorderable), clist);
gtk_box_pack_start (GTK_BOX (box2), check, FALSE, TRUE, 0);
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (check), TRUE);
label = gtk_label_new ("Selection Mode :");
gtk_box_pack_start (GTK_BOX (box2), label, FALSE, TRUE, 0);
@ -4112,18 +4124,6 @@ create_clist (void)
* the rest of the clist configuration
*/
/*
gtk_signal_connect (GTK_OBJECT (clist),
"select_row",
(GtkSignalFunc) select_clist,
undo_button);
gtk_signal_connect (GTK_OBJECT (clist),
"unselect_row",
(GtkSignalFunc) unselect_clist,
undo_button);
*/
gtk_clist_set_row_height (GTK_CLIST (clist), 18);
gtk_widget_set_usize (clist, -1, 300);
@ -4275,74 +4275,6 @@ void after_move (GtkCTree *ctree, GtkCTreeNode *child, GtkCTreeNode *parent,
(parent) ? target1 : "nil", (sibling) ? target2 : "nil");
}
gint button_press (GtkCTree *ctree, GdkEventButton *event, gpointer data)
{
gint row;
gint column;
GtkCTreeNode *work;
gint res;
res = gtk_clist_get_selection_info (GTK_CLIST (ctree), event->x, event->y,
&row, &column);
if (!res && event->button != 3)
return FALSE;
work = GTK_CTREE_NODE (g_list_nth (GTK_CLIST (ctree)->row_list, row));
switch (event->button)
{
case 1:
if (GTK_CLIST (ctree)->selection_mode == GTK_SELECTION_MULTIPLE &&
event->state & GDK_SHIFT_MASK)
gtk_signal_emit_stop_by_name (GTK_OBJECT (ctree),"button_press_event");
break;
case 2:
if (GTK_CTREE_ROW (work)->children &&
gtk_ctree_is_hot_spot (ctree, event->x, event->y))
{
if (GTK_CTREE_ROW (work)->expanded)
gtk_ctree_collapse_recursive (ctree, work);
else
gtk_ctree_expand_recursive (ctree, work);
after_press (ctree, NULL);
gtk_signal_emit_stop_by_name (GTK_OBJECT (ctree),
"button_press_event");
}
break;
default:
break;
}
return FALSE;
}
gint button_release (GtkCTree *ctree, GdkEventButton *event, gpointer data)
{
gint row;
gint column;
GtkCTreeNode *work;
gint res;
res = gtk_clist_get_selection_info (GTK_CLIST (ctree), event->x, event->y,
&row, &column);
if (!res || event->button != 1)
return FALSE;
work = GTK_CTREE_NODE (g_list_nth (GTK_CLIST (ctree)->row_list, row));
if (GTK_CLIST (ctree)->selection_mode == GTK_SELECTION_MULTIPLE &&
event->state & GDK_SHIFT_MASK)
{
if (GTK_CTREE_ROW (work)->row.state == GTK_STATE_SELECTED)
gtk_ctree_unselect_recursive (ctree, work);
else
gtk_ctree_select_recursive (ctree, work);
after_press (ctree, NULL);
gtk_signal_emit_stop_by_name (GTK_OBJECT (ctree),
"button_release_event");
}
return FALSE;
}
void count_items (GtkCTree *ctree, GtkCTreeNode *list)
{
if (GTK_CTREE_ROW (list)->is_leaf)
@ -4616,11 +4548,6 @@ void change_row_height (GtkWidget *widget, GtkCList *clist)
gtk_clist_set_row_height (clist, GTK_ADJUSTMENT (widget)->value);
}
void toggle_reorderable (GtkWidget *widget, GtkCTree *ctree)
{
gtk_ctree_set_reorderable (ctree, GTK_TOGGLE_BUTTON (widget)->active);
}
void set_background (GtkCTree *ctree, GtkCTreeNode *node, gpointer data)
{
GtkStyle *style = NULL;
@ -4953,16 +4880,11 @@ void create_ctree (void)
gtk_ctree_set_line_style (ctree, GTK_CTREE_LINES_DOTTED);
line_style = GTK_CTREE_LINES_DOTTED;
gtk_ctree_set_reorderable (ctree, TRUE);
gtk_signal_connect (GTK_OBJECT (ctree), "click_column",
(GtkSignalFunc) ctree_click_column,
NULL);
gtk_signal_connect (GTK_OBJECT (ctree), "button_press_event",
GTK_SIGNAL_FUNC (button_press), NULL);
gtk_signal_connect_after (GTK_OBJECT (ctree), "button_press_event",
GTK_SIGNAL_FUNC (after_press), NULL);
gtk_signal_connect (GTK_OBJECT (ctree), "button_release_event",
GTK_SIGNAL_FUNC (button_release), NULL);
gtk_signal_connect_after (GTK_OBJECT (ctree), "button_release_event",
GTK_SIGNAL_FUNC (after_press), NULL);
gtk_signal_connect_after (GTK_OBJECT (ctree), "tree_move",