[Xfce4-commits] <xfce4-panel:andrzejr/deskbar-github> itembar: reworked dnd support (different visual indicators); fixed dnd in rotated vertical mode

Andrzej noreply at xfce.org
Mon Dec 12 11:40:45 CET 2011


Updating branch refs/heads/andrzejr/deskbar-github
         to b2ad54a697d57b0ea882abb4475d4c99ddd4bfc3 (commit)
       from f5ef7226cdcaef7065a06477738f8662c10a0df5 (commit)

commit b2ad54a697d57b0ea882abb4475d4c99ddd4bfc3
Author: Andrzej <ndrwrdck at gmail.com>
Date:   Wed Nov 30 03:53:59 2011 +0900

    itembar: reworked dnd support (different visual indicators); fixed dnd in rotated vertical mode

 panel/panel-itembar.c |  141 +++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 108 insertions(+), 33 deletions(-)

diff --git a/panel/panel-itembar.c b/panel/panel-itembar.c
index 1563496..2bae60f 100644
--- a/panel/panel-itembar.c
+++ b/panel/panel-itembar.c
@@ -93,6 +93,9 @@ struct _PanelItembar
   /* dnd support */
   gint            highlight_index;
   gint            highlight_x, highlight_y;
+  gboolean        highlight_small;
+
+  gint            spacing; /* spacing between (not small) plugins to fit dnd marks */
 };
 
 struct _PanelItembarChild
@@ -239,6 +242,7 @@ panel_itembar_init (PanelItembar *itembar)
   itembar->nrows = 1;
   itembar->deskbar_mode = FALSE;
   itembar->highlight_index = -1;
+  itembar->spacing = 2;
 
   GTK_WIDGET_SET_FLAGS (GTK_WIDGET (itembar), GTK_NO_WINDOW);
 
@@ -403,6 +407,7 @@ panel_itembar_size_request (GtkWidget      *widget,
                 row_length += child_requisition.width;
               else
                 row_length += child_requisition.height;
+              row_length += itembar->spacing;
             }
           else
             {
@@ -426,7 +431,7 @@ panel_itembar_size_request (GtkWidget      *widget,
       else
         {
           /* this noop item is the dnd position */
-          row_length += itembar->size;
+          /* row_length += itembar->size; */
         }
     }
 
@@ -449,7 +454,7 @@ panel_itembar_size_allocate (GtkWidget     *widget,
                              GtkAllocation *allocation)
 {
   PanelItembar      *itembar = PANEL_ITEMBAR (widget);
-  GSList            *li, *lp;
+  GSList            *li, *lp, *ltemp;
   PanelItembarChild *child;
   GtkRequisition     child_req;
   GtkAllocation      child_alloc;
@@ -519,19 +524,21 @@ panel_itembar_size_allocate (GtkWidget     *widget,
                 {
                   column_row = 0;
                   expand_length_req += length;
+                  expand_length_avail -= itembar->spacing;
                 }
               else
                 {
                   column_row = 0;
-                  expand_length_avail -= length;
+                  expand_length_avail -= (length + itembar->spacing);
 
                   if (child->shrink)
-                    shrink_length_avail += length;
+                    shrink_length_avail += (length + itembar->spacing);
                 }
             }
           else
             {
-              expand_length_avail -= itembar->size;
+              /* dnd */
+              //expand_length_avail -= itembar->size;
             }
         }
 
@@ -573,15 +580,19 @@ panel_itembar_size_allocate (GtkWidget     *widget,
           /* the highlight item for which we keep some spare space */
           if (G_UNLIKELY (child == NULL))
             {
+              ltemp = g_slist_next (li);
+              if (column_row > 0 && ltemp && ltemp->data && ((PanelItembarChild *)ltemp->data)->small)
+                {
+                  itembar->highlight_small = TRUE;
+                }
+              else
+                {
+                  itembar->highlight_small = FALSE;
+                  if (column_row > 0)
+                    panel_itembar_column_wrap(itembar, &column_row, &x, &y, start);
+                }
               itembar->highlight_x = x;
               itembar->highlight_y = y;
-
-              if (itembar->horizontal)
-                x += itembar->size;
-              else
-                y += itembar->size;
-              expand_length_avail -= itembar->size;
-
               continue;
             }
 
@@ -691,6 +702,11 @@ panel_itembar_size_allocate (GtkWidget     *widget,
             child_alloc.y = 2*allocation->y + allocation->height
               - child_alloc.y - child_alloc.height;
           gtk_widget_size_allocate (child->widget, &child_alloc);
+
+          if (itembar->horizontal)
+            x += itembar->spacing;
+          else
+            y += itembar->spacing;
         }
     }
 }
@@ -703,18 +719,60 @@ panel_itembar_expose_event (GtkWidget      *widget,
 {
   gboolean      result;
   PanelItembar *itembar = PANEL_ITEMBAR (widget);
+  cairo_t      *cr;
+  GdkWindow    *window;
+  gint          x1, y1, x2, y2;
+  GtkAllocation *alloc;
 
   result = (*GTK_WIDGET_CLASS (panel_itembar_parent_class)->expose_event) (widget, event);
 
   if (itembar->highlight_index != -1)
     {
-      gtk_paint_box (widget->style, widget->window,
-                     GTK_STATE_NORMAL, GTK_SHADOW_OUT,
-                     &event->area, widget, "panel-dnd",
-                     itembar->highlight_x + 1,
-                     itembar->highlight_y + 1,
-                     itembar->size - 2,
-                     itembar->size - 2);
+      window = gtk_widget_get_window (widget);
+      cr = gdk_cairo_create (window);
+      cairo_set_source_rgb (cr, 1., 0., 0.);
+      cairo_set_line_width (cr, 2);
+
+      if (itembar->horizontal)
+        {
+          if (itembar->highlight_small)
+            {
+              x1 = itembar->highlight_x;
+              x2 = x1 + itembar->size / itembar->nrows;
+              y1 = y2 = itembar->highlight_y;
+            }
+          else
+            {
+              x1 = x2 = itembar->highlight_x - 1;
+              y1 = itembar->highlight_y;
+              y2 = y1 + itembar->size;
+            }
+        }
+      else /* vertical */
+        {
+          if (itembar->highlight_small)
+            {
+              y1 = itembar->highlight_y;
+              y2 = y1 + itembar->size / itembar->nrows;
+              x1 = x2 = itembar->highlight_x;
+            }
+          else
+            {
+              y1 = y2 = itembar->highlight_y - 1;
+              x1 = itembar->highlight_x;
+              x2 = x1 + itembar->size;
+            }
+          alloc = &widget->allocation;
+          if (!itembar->deskbar_mode)
+            {
+              y1 = 2 * alloc->y + alloc->height - y1;
+              y2 = 2 * alloc->y + alloc->height - y2;
+            }
+        }
+      cairo_move_to (cr, x1, y1);
+      cairo_line_to (cr, x2, y2);
+      cairo_stroke (cr);
+      cairo_destroy (cr);
     }
 
   return result;
@@ -1017,17 +1075,18 @@ panel_itembar_get_drop_index (PanelItembar *itembar,
 {
   PanelItembarChild *child;
   GSList            *li;
-  GtkAllocation     *alloc;
+  GtkAllocation     *alloc_bar, *alloc;
   guint              idx;
   gint               row = 0;
+  gint               x2, y2;
 
   panel_return_val_if_fail (PANEL_IS_ITEMBAR (itembar), 0);
 
   /* add the itembar position */
-  alloc = &GTK_WIDGET (itembar)->allocation;
+  alloc_bar = &GTK_WIDGET (itembar)->allocation;
 
   /* return -1 if point is outside the widget allocation */
-  if (x > alloc->width || y > alloc->height)
+  if (x > alloc_bar->width || y > alloc_bar->height)
     return g_slist_length (itembar->children);
 
   for (li = itembar->children, idx = 0; li != NULL; li = g_slist_next (li))
@@ -1050,22 +1109,38 @@ panel_itembar_get_drop_index (PanelItembar *itembar,
 
       if (itembar->horizontal)
         {
-          if (x < (alloc->x + (alloc->width / 2))
-              && y >= alloc->y
-              && y <= alloc->y + alloc->height)
-            break;
+          if (x < alloc->x) break;
+          if (child->small)
+            {
+              if (y <  (alloc->y + alloc->height / 2) &&
+                  x <= (alloc->x + alloc->width)) break;
+            }
+          else
+            {
+              if (x < (alloc->x + alloc->width / 2)) break;
+            }
         }
-      else
+      else /* vertical */
         {
-          if (y < (alloc->y + (alloc->height / 2))
-              && x >= alloc->x
-              && x <= alloc->x + alloc->width)
-            break;
+          x2 = x;
+          y2 = y;
+          if (!itembar->deskbar_mode)
+            {
+              y2 = 2 * alloc->y + alloc->height - y;
+            }
+          if (y2 < alloc->y) break;
+          if (child->small)
+            {
+              if (x2 <  (alloc->x + alloc->width / 2) &&
+                  y2 <= (alloc->y + alloc->height)) break;
+            }
+          else
+            {
+              if (y2 < (alloc->y + alloc->height / 2)) break;
+            }
         }
-
       idx++;
     }
-
   return idx;
 }
 


More information about the Xfce4-commits mailing list