[Xfce4-commits] <exo:jannis/lazy-cell-renderer> Make ExoLazyCellRenderer available, suggested in bug #1266 in 2005.

Jannis Pohlmann noreply at xfce.org
Tue Oct 5 16:28:02 CEST 2010


Updating branch refs/heads/jannis/lazy-cell-renderer
         to 15ddccdcd8a501925dd93233a6b0ebbeaa2a9334 (commit)
       from 0a56f6a50f1d604cd181830dc7cb5658e0904c1c (commit)

commit 15ddccdcd8a501925dd93233a6b0ebbeaa2a9334
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Tue Oct 5 16:24:09 2010 +0200

    Make ExoLazyCellRenderer available, suggested in bug #1266 in 2005.
    
    This new ExoLazyCellRenderer interface adds a new method
    render_and_resize() to cell renderers implementing this interface. This
    can be used for applications which load icons only on-demand (like
    Thunar).
    
    It allows cell renderers to modify the size of the rendered cells before
    rendering them and pass the modifications back to the icon view.
    
    This implementation still has a few resizing issues but maybe we can
    sort them out one day...
    
    The original code was written by Benny, I've modified the patch to apply
    against the current development branch.

 exo/Makefile.am     |    2 ++
 exo/exo-icon-view.c |   40 +++++++++++++++++++++++++++++++++++-----
 exo/exo.h           |    1 +
 exo/exo.symbols     |    9 +++++++++
 4 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/exo/Makefile.am b/exo/Makefile.am
index 2fcfce2..80ccb23 100644
--- a/exo/Makefile.am
+++ b/exo/Makefile.am
@@ -21,6 +21,7 @@ libexo_headers =							\
 	exo-icon-bar.h							\
 	exo-icon-chooser-dialog.h					\
 	exo-icon-view.h							\
+	exo-lazy-cell-renderer.h					\
 	exo-job.h							\
 	exo-simple-job.h						\
 	exo-string.h							\
@@ -68,6 +69,7 @@ libexo_1_la_SOURCES =							\
 	exo-icon-chooser-model.c					\
 	exo-icon-chooser-model.h					\
 	exo-icon-view.c							\
+	exo-lazy-cell-renderer.c					\
 	exo-job.c							\
 	exo-job.h							\
 	exo-simple-job.c						\
diff --git a/exo/exo-icon-view.c b/exo/exo-icon-view.c
index d45b8b1..7b0d425 100644
--- a/exo/exo-icon-view.c
+++ b/exo/exo-icon-view.c
@@ -43,6 +43,7 @@
 #include <exo/exo-config.h>
 #include <exo/exo-enum-types.h>
 #include <exo/exo-icon-view.h>
+#include <exo/exo-lazy-cell-renderer.h>
 #include <exo/exo-marshal.h>
 #include <exo/exo-private.h>
 #include <exo/exo-string.h>
@@ -400,9 +401,10 @@ static void     exo_icon_view_search_timeout_destroy    (gpointer        user_da
 struct _ExoIconViewCellInfo
 {
   GtkCellRenderer      *cell;
+  guint                 editing : 1;
   guint                 expand : 1;
+  guint                 lazy : 1;
   guint                 pack : 1;
-  guint                 editing : 1;
   gint                  position;
   GSList               *attributes;
   GtkCellLayoutDataFunc func;
@@ -3547,6 +3549,10 @@ exo_icon_view_paint_item (ExoIconView     *icon_view,
   gint                 y_0;
   gint                 x_1;
   gint                 y_1;
+  gint                 x_offset;
+  gint                 y_offset;
+  gint                 width;
+  gint                 height;
 
   if (G_UNLIKELY (icon_view->priv->model == NULL))
     return;
@@ -3650,11 +3656,33 @@ exo_icon_view_paint_item (ExoIconView     *icon_view,
       cell_area.x = x - item->area.x + cell_area.x;
       cell_area.y = y - item->area.y + cell_area.y;
 
-      gtk_cell_renderer_render (info->cell,
-                                drawable,
-                                GTK_WIDGET (icon_view),
-                                &cell_area, &cell_area, area, flags);
+      if (!info->lazy)
+        {
+          gtk_cell_renderer_render (info->cell,
+                                    drawable,
+                                    GTK_WIDGET (icon_view),
+                                    &cell_area, &cell_area, area, flags);
+        }
+      else if (exo_lazy_cell_renderer_render_and_resize (EXO_LAZY_CELL_RENDERER (info->cell), drawable,
+                                                         GTK_WIDGET (icon_view), &cell_area, &cell_area,
+                                                         area, flags, &x_offset, &y_offset, &width, &height))
+        {
+          item->box[info->position].x = x_offset + cell_area.x;
+          item->box[info->position].y = y_offset + cell_area.y;
+          item->box[info->position].width = width;
+          item->box[info->position].height = height;
 
+          if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+            {
+              item->before[info->position] = x_offset;
+              item->after[info->position] = cell_area.width - width - x_offset;
+            }
+          else
+            {
+              item->before[info->position] = y_offset;
+              item->after[info->position] = cell_area.height - height - y_offset;
+            }
+        }
     }
 }
 
@@ -4680,6 +4708,7 @@ exo_icon_view_cell_layout_pack_start (GtkCellLayout   *layout,
   info = g_slice_new0 (ExoIconViewCellInfo);
   info->cell = renderer;
   info->expand = expand ? TRUE : FALSE;
+  info->lazy = EXO_IS_LAZY_CELL_RENDERER (renderer);
   info->pack = GTK_PACK_START;
   info->position = icon_view->priv->n_cells;
   info->is_text = GTK_IS_CELL_RENDERER_TEXT (renderer);
@@ -4709,6 +4738,7 @@ exo_icon_view_cell_layout_pack_end (GtkCellLayout   *layout,
   info = g_slice_new0 (ExoIconViewCellInfo);
   info->cell = renderer;
   info->expand = expand ? TRUE : FALSE;
+  info->lazy = EXO_IS_LAZY_CELL_RENDERER (renderer);
   info->pack = GTK_PACK_END;
   info->position = icon_view->priv->n_cells;
   info->is_text = GTK_IS_CELL_RENDERER_TEXT (renderer);
diff --git a/exo/exo.h b/exo/exo.h
index d995d3a..81512b5 100644
--- a/exo/exo.h
+++ b/exo/exo.h
@@ -47,6 +47,7 @@
 #include <exo/exo-icon-chooser-dialog.h>
 #include <exo/exo-icon-view.h>
 #include <exo/exo-job.h>
+#include <exo/exo-lazy-cell-renderer.h>
 #include <exo/exo-simple-job.h>
 #include <exo/exo-string.h>
 #include <exo/exo-toolbars-editor.h>
diff --git a/exo/exo.symbols b/exo/exo.symbols
index a45cc56..6377868 100644
--- a/exo/exo.symbols
+++ b/exo/exo.symbols
@@ -220,6 +220,15 @@ exo_icon_view_set_search_position_func
 #endif
 #endif
 
+/* ExoLazyCellRenderer methods */
+#if IN_HEADER(__EXO_LAZY_CELL_RENDERER_H__)
+#if IN_SOURCE(__EXO_LAZY_CELL_RENDERER_C__)
+exo_lazy_cell_renderer_get_type G_GNUC_CONST
+exo_lazy_cell_renderer_render_and_resize
+#endif
+#endif
+
+ /* exo-md5 functions */
 /* exo-job functions */
 #if IN_HEADER(__EXO_JOB_H__)
 #if IN_SOURCE(__EXO_JOB_C__)



More information about the Xfce4-commits mailing list