From: Mario Rugiero <[email protected]>
Double pointer allows to process lists in a more linear fashion.
The functions changed are:
icon_grid_add
icon_grid_set_constrain_width
icon_grid_remove
icon_grid_reorder_child
NOTE I'm not exactly sure how to test this.
I'm assuming lxpanel by default uses the new icon-grid, and I'm not
finding how to change it. Thus, it is RFC quality.
---
src/icon-grid-old.c | 74 +++++++++++++++++----------------------------
1 file changed, 28 insertions(+), 46 deletions(-)
diff --git a/src/icon-grid-old.c b/src/icon-grid-old.c
index 57afe22..b3c631c 100644
--- a/src/icon-grid-old.c
+++ b/src/icon-grid-old.c
@@ -307,19 +307,18 @@ void icon_grid_add(IconGrid * ig, GtkWidget * child,
gboolean visible)
{
/* Create and initialize a structure representing the child. */
IconGridElement * ige = g_new0(IconGridElement, 1);
+ IconGridElement ** pige;
+ /* ige will be the last element. */
+ ige->flink = NULL;
ige->ig = ig;
ige->widget = child;
ige->visible = visible;
/* Insert at the tail of the child list. This keeps the graphics in the
order they were added. */
- if (ig->child_list == NULL)
- ig->child_list = ige;
- else
- {
- IconGridElement * ige_cursor;
- for (ige_cursor = ig->child_list; ige_cursor->flink != NULL;
ige_cursor = ige_cursor->flink) ;
- ige_cursor->flink = ige;
- }
+ for (pige = &(ig->child_list);
+ *pige != NULL;
+ pige = &((*pige)->flink)) ;
+ *pige = ige;
/* Add the widget to the layout container. */
if (visible)
@@ -339,25 +338,25 @@ extern void icon_grid_set_constrain_width(IconGrid * ig,
gboolean constrain_widt
/* Remove an icon grid element. */
void icon_grid_remove(IconGrid * ig, GtkWidget * child)
{
+ IconGridElement ** pige;
IconGridElement * ige_pred = NULL;
- IconGridElement * ige;
- for (ige = ig->child_list; ige != NULL; ige_pred = ige, ige = ige->flink)
+
+ for (pige = &(ig->child_list);
+ *pige != NULL;
+ pige = &((*pige)->flink))
{
- if (ige->widget == child)
+ if ((*pige)->widget == child)
{
/* The child is found. Remove from child list and layout
container. */
- gtk_widget_hide(ige->widget);
- gtk_container_remove(GTK_CONTAINER(ig->widget), ige->widget);
+ gtk_widget_hide((*pige)->widget);
+ gtk_container_remove(GTK_CONTAINER(ig->widget), (*pige)->widget);
- if (ige_pred == NULL)
- ig->child_list = ige->flink;
- else
- ige_pred->flink = ige->flink;
+ *pige = (*pige)->flink;
/* Do a relayout. */
icon_grid_demand_resize(ig);
break;
- }
+ }
}
}
@@ -381,16 +380,14 @@ extern gint icon_grid_get_child_position(IconGrid * ig,
GtkWidget * child)
extern void icon_grid_reorder_child(IconGrid * ig, GtkWidget * child, gint
position)
{
/* Remove the child from its current position. */
- IconGridElement * ige_pred = NULL;
+ IconGridElement ** pige;
IconGridElement * ige;
- for (ige = ig->child_list; ige != NULL; ige_pred = ige, ige = ige->flink)
+ for (pige = &(ig->child_list); *pige != NULL; pige = &((*pige)->flink))
{
- if (ige->widget == child)
+ if ((*pige)->widget == child)
{
- if (ige_pred == NULL)
- ig->child_list = ige->flink;
- else
- ige_pred->flink = ige->flink;
+ ige = *pige;
+ *pige = ige->flink;
break;
}
}
@@ -398,28 +395,13 @@ extern void icon_grid_reorder_child(IconGrid * ig,
GtkWidget * child, gint posit
/* If the child was found, insert it at the new position. */
if (ige != NULL)
{
- if (ig->child_list == NULL)
- {
- ige->flink = NULL;
- ig->child_list = ige;
- }
- else if (position == 0)
- {
- ige->flink = ig->child_list;
- ig->child_list = ige;
- }
- else
+ for (pige = &(ig->child_list);
+ (*pige != NULL) && (position > 0);
+ pige = &((*pige)->flink));
+ if (*pige != NULL)
{
- int local_position = position - 1;
- IconGridElement * ige_pred;
- for (
- ige_pred = ig->child_list;
- ((ige_pred != NULL) && (local_position > 0));
- local_position -= 1, ige_pred = ige_pred->flink) ;
- if (ige_pred != NULL) {
- ige->flink = ige_pred->flink; // ige_pred can be NULL
- ige_pred->flink = ige;
- }
+ ige->flink = (*pige)->flink;
+ (*pige)->flink = ige;
}
/* Do a relayout. */
--
2.17.1
_______________________________________________
Lxde-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lxde-list