[Xfce4-commits] <xfce4-panel:master> Panel: Improved DnD markers.
Nick Schermer
noreply at xfce.org
Mon Apr 2 21:54:01 CEST 2012
Updating branch refs/heads/master
to 26e104edc137b0572ce93c84cbd66ac4d5cb0db6 (commit)
from f6e69cf06a6e8cb31482cc66c04701c2b7ec2215 (commit)
commit 26e104edc137b0572ce93c84cbd66ac4d5cb0db6
Author: Andrzej <ndrwrdck at gmail.com>
Date: Tue Apr 3 03:49:36 2012 +0900
Panel: Improved DnD markers.
(cherry picked from commit 0f546d7384ad0fde00f496df087efe0826a09bc7)
panel/panel-itembar.c | 95 ++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 74 insertions(+), 21 deletions(-)
diff --git a/panel/panel-itembar.c b/panel/panel-itembar.c
index e670caa..142a718 100644
--- a/panel/panel-itembar.c
+++ b/panel/panel-itembar.c
@@ -96,6 +96,7 @@ struct _PanelItembar
/* dnd support */
gint highlight_index;
gint highlight_x, highlight_y;
+ gboolean highlight_small;
};
typedef enum
@@ -111,6 +112,7 @@ struct _PanelItembarChild
{
GtkWidget *widget;
ChildOptions option;
+ gint row;
};
enum
@@ -394,7 +396,7 @@ panel_itembar_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
PanelItembar *itembar = PANEL_ITEMBAR (widget);
- GSList *lp;
+ GSList *lp, *ltemp;
PanelItembarChild *child;
GtkRequisition child_req;
GtkAllocation child_alloc;
@@ -525,23 +527,35 @@ panel_itembar_size_allocate (GtkWidget *widget,
if (G_UNLIKELY (child == NULL))
{
- if (IS_HORIZONTAL (itembar))
+ ltemp = g_slist_next (lp);
+ itembar->highlight_small = (col_count > 0 && ltemp && ltemp->data && ((PanelItembarChild *)ltemp->data)->option == CHILD_OPTION_SMALL);
+
+ if (itembar->highlight_small)
{
itembar->highlight_x = x;
+ itembar->highlight_y = y;
+ if (IS_HORIZONTAL (itembar))
+ y += HIGHLIGHT_SIZE;
+ else
+ x += HIGHLIGHT_SIZE;
+ }
+ else if (IS_HORIZONTAL (itembar))
+ {
+ itembar->highlight_x = (col_count > 0) ? x + row_max_size : x;
itembar->highlight_y = y_init;
x += HIGHLIGHT_SIZE;
+ expand_len_avail -= HIGHLIGHT_SIZE;
}
else
{
itembar->highlight_x = x_init;
- itembar->highlight_y = y;
+ itembar->highlight_y = (col_count > 0) ? y + row_max_size : y;
y += HIGHLIGHT_SIZE;
+ expand_len_avail -= HIGHLIGHT_SIZE;
}
- expand_len_avail -= HIGHLIGHT_SIZE;
-
continue;
}
@@ -605,6 +619,8 @@ panel_itembar_size_allocate (GtkWidget *widget,
x += itembar->size;
}
+ child->row = col_count;
+
/* reset to new row if all columns are filled */
if (++col_count >= itembar->nrows)
{
@@ -635,6 +651,8 @@ panel_itembar_size_allocate (GtkWidget *widget,
RESET_COLUMN_COUNTERS
}
+ child->row = col_count;
+
child_alloc.x = x;
child_alloc.y = y;
@@ -675,12 +693,13 @@ panel_itembar_expose_event (GtkWidget *widget,
if (itembar->highlight_index != -1)
{
- row_size = itembar->size * itembar->nrows;
+ row_size = (itembar->highlight_small) ? itembar->size : itembar->size * itembar->nrows;
rect.x = itembar->highlight_x;
rect.y = itembar->highlight_y;
- if (IS_HORIZONTAL (itembar))
+ if ((IS_HORIZONTAL (itembar) && !itembar->highlight_small) ||
+ (!IS_HORIZONTAL (itembar) && itembar->highlight_small))
{
rect.width = HIGHLIGHT_SIZE;
rect.height = row_size;
@@ -998,41 +1017,75 @@ panel_itembar_get_drop_index (PanelItembar *itembar,
{
PanelItembarChild *child;
GSList *li;
- GtkAllocation *alloc;
- guint idx;
+ GtkAllocation alloc;
+ guint idx, col_start_idx;
+ gint xr, yr;
panel_return_val_if_fail (PANEL_IS_ITEMBAR (itembar), 0);
/* add the itembar position */
- alloc = >K_WIDGET (itembar)->allocation;
+ alloc = GTK_WIDGET (itembar)->allocation;
+
+ if (!IS_HORIZONTAL (itembar))
+ {
+ SWAP_INTEGER (x, y);
+ TRANSPOSE_AREA (alloc);
+ }
/* return -1 if point is outside the widget allocation */
- if (x > alloc->width || y > alloc->height)
+ if (x < alloc.x || y < alloc.y ||
+ x >= alloc.x + alloc.width || y >= alloc.y + alloc.height)
return g_slist_length (itembar->children);
- for (li = itembar->children, idx = 0; li != NULL; li = g_slist_next (li))
+ for (li = itembar->children, idx = 0, col_start_idx = 0; li != NULL; li = g_slist_next (li))
{
child = li->data;
if (G_UNLIKELY (child == NULL))
continue;
- alloc = &child->widget->allocation;
+ if (child->row == 0)
+ col_start_idx = idx;
+
+ alloc = child->widget->allocation;
- if (IS_HORIZONTAL (itembar))
+ if (!IS_HORIZONTAL (itembar))
+ TRANSPOSE_AREA (alloc);
+
+ xr = x - alloc.x;
+ yr = y - alloc.y;
+ if (child->option == CHILD_OPTION_SMALL)
{
- if (x < (alloc->x + (alloc->width / 2))
- && y >= alloc->y
- && y <= alloc->y + alloc->height)
+ /* before current column */
+ if (xr < 0 ||
+ (xr < yr && xr < alloc.height - yr))
+ {
+ idx = col_start_idx;
+ break;
+ }
+ /* before current child */
+ if (xr < alloc.width && xr >= yr && alloc.width - xr >= yr)
break;
+ /* after current column */
+ if (xr < alloc.width && xr >= alloc.height - yr && xr >= yr)
+ {
+ /* search for the beginning of the next column */
+ for (li = g_slist_next (li), idx++; li != NULL; li = g_slist_next (li))
+ {
+ child = li->data;
+ if (G_UNLIKELY (child == NULL))
+ continue;
+ if (child->row == 0)
+ break;
+ idx++;
+ }
+ break;
+ }
}
else
{
- if (y < (alloc->y + (alloc->height / 2))
- && x >= alloc->x
- && x <= alloc->x + alloc->width)
+ if (xr < alloc.width / 2)
break;
}
-
idx++;
}
More information about the Xfce4-commits
mailing list