diff options
author | Jay Painter <jpaint@src.gnome.org> | 1998-06-02 02:51:46 +0000 |
---|---|---|
committer | Jay Painter <jpaint@src.gnome.org> | 1998-06-02 02:51:46 +0000 |
commit | 57967d9a98dfa72cc8d286511ae9279fb87d7968 (patch) | |
tree | a9d95ca006c12fd33f265df5ff49b3e70593bd70 | |
parent | 88e84f52dde0b6e1d901d1f5ffc5378612f83269 (diff) | |
download | gtk+-57967d9a98dfa72cc8d286511ae9279fb87d7968.tar.gz |
Added function gtk_clist_swap to swap two rows in a clist; I also have
finally fixed pixmap clipping so pixmaps are always cliped to the row.
-rw-r--r-- | gtk/gtkclist.c | 98 | ||||
-rw-r--r-- | gtk/gtkclist.h | 5 | ||||
-rw-r--r-- | gtk/testgtk.c | 4 | ||||
-rw-r--r-- | tests/testgtk.c | 4 |
4 files changed, 103 insertions, 8 deletions
diff --git a/gtk/gtkclist.c b/gtk/gtkclist.c index be1a65aafa..3fdc17cee2 100644 --- a/gtk/gtkclist.c +++ b/gtk/gtkclist.c @@ -1466,6 +1466,57 @@ gtk_clist_clear (GtkCList * clist) } } +void +gtk_clist_swap_rows (GtkCList * clist, + gint row1, + gint row2) +{ + gint first, last; + GList *list, *link1, *link2; + gpointer swap; + + g_return_if_fail (clist != NULL); + + if (row1 < 0 || row1 > (clist->rows - 1)) + return; + + if (row2 < 0 || row2 > (clist->rows - 1)) + return; + + first = MIN (row1, row2); + last = MAX (row1, row2); + + link1 = g_list_nth (clist->row_list, first); + link2 = g_list_nth (link1, row2 - row1); + + swap = link1->data; + link1->data = link2->data; + link2->data = swap; + + list = clist->selection; + while (list) + { + if (GPOINTER_TO_INT (list->data) == row1) + GPOINTER_TO_INT (list->data) = row2; + + if (GPOINTER_TO_INT (list->data) == row2) + GPOINTER_TO_INT (list->data) = row1; + + list = list->next; + } + + if (!GTK_CLIST_FROZEN (clist)) + { + if (gtk_clist_row_is_visible (clist, row1) != GTK_VISIBILITY_NONE) + (GTK_CLIST_CLASS (GTK_OBJECT (clist)->klass)->draw_row) + (clist, NULL, row1, (GtkCListRow *) link2->data); + + if (gtk_clist_row_is_visible (clist, row2) != GTK_VISIBILITY_NONE) + (GTK_CLIST_CLASS (GTK_OBJECT (clist)->klass)->draw_row) + (clist, NULL, row2, (GtkCListRow *) link1->data); + } +} + void gtk_clist_set_row_data (GtkCList * clist, gint row, @@ -2601,7 +2652,8 @@ draw_row (GtkCList * clist, } else { - if (!gdk_rectangle_intersect (area, &clip_rectangle, &intersect_rectangle)) + if (!gdk_rectangle_intersect (area, &clip_rectangle, + &intersect_rectangle)) continue; rect = &intersect_rectangle; } @@ -2692,6 +2744,26 @@ draw_row (GtkCList * clist, ydest = (clip_rectangle.y + (clip_rectangle.height / 2)) - height / 2 + clist_row->cell[i].vertical; + if (xdest < clip_rectangle.x) + { + xsrc = clip_rectangle.x - xdest; + pixmap_width -= xsrc; + xdest = clip_rectangle.x; + } + + if (xdest + pixmap_width > clip_rectangle.x + clip_rectangle.width) + pixmap_width = (clip_rectangle.x + clip_rectangle.width) - xdest; + + if (ydest < clip_rectangle.y) + { + ysrc = clip_rectangle.y - ydest; + height -= ysrc; + ydest = clip_rectangle.y; + } + + if (ydest + height > clip_rectangle.y + clip_rectangle.height) + height = (clip_rectangle.y + clip_rectangle.height) - ydest; + if (GTK_CELL_PIXMAP (clist_row->cell[i])->mask) { gdk_gc_set_clip_mask (fg_gc, GTK_CELL_PIXMAP (clist_row->cell[i])->mask); @@ -2701,8 +2773,7 @@ draw_row (GtkCList * clist, fg_gc, GTK_CELL_PIXMAP (clist_row->cell[i])->pixmap, xsrc, ysrc, - xdest, - ydest, + xdest, ydest, pixmap_width, height); if (GTK_CELL_PIXMAP (clist_row->cell[i])->mask) @@ -2720,6 +2791,26 @@ draw_row (GtkCList * clist, ydest = (clip_rectangle.y + (clip_rectangle.height / 2)) - height / 2 + clist_row->cell[i].vertical; + if (xdest < clip_rectangle.x) + { + xsrc = clip_rectangle.x - xdest; + pixmap_width -= xsrc; + xdest = clip_rectangle.x; + } + + if (xdest + pixmap_width > clip_rectangle.x + clip_rectangle.width) + pixmap_width = (clip_rectangle.x + clip_rectangle.width) - xdest; + + if (ydest < clip_rectangle.y) + { + ysrc = clip_rectangle.y - ydest; + height -= ysrc; + ydest = clip_rectangle.y; + } + + if (ydest + height > clip_rectangle.y + clip_rectangle.height) + height = (clip_rectangle.y + clip_rectangle.height) - ydest; + if (GTK_CELL_PIXTEXT (clist_row->cell[i])->mask) { gdk_gc_set_clip_mask (fg_gc, GTK_CELL_PIXTEXT (clist_row->cell[i])->mask); @@ -2750,7 +2841,6 @@ draw_row (GtkCList * clist, GTK_CELL_PIXTEXT (clist_row->cell[i])->text); gdk_gc_set_clip_rectangle (fg_gc, NULL); - break; case GTK_CELL_WIDGET: diff --git a/gtk/gtkclist.h b/gtk/gtkclist.h index af914a2ab0..0a7bac42ba 100644 --- a/gtk/gtkclist.h +++ b/gtk/gtkclist.h @@ -486,6 +486,11 @@ gint gtk_clist_get_selection_info (GtkCList * clist, gint * row, gint * column); +/* swap the position of two rows */ +void gtk_clist_swap_rows (GtkCList * clist, gint row1, gint row2); + + + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/gtk/testgtk.c b/gtk/testgtk.c index 586966cfed..f270e9b01b 100644 --- a/gtk/testgtk.c +++ b/gtk/testgtk.c @@ -2977,7 +2977,7 @@ add1000_clist (GtkWidget *widget, gpointer data) pixmap = gdk_pixmap_create_from_xpm (GTK_CLIST (data)->clist_window, &mask, >K_WIDGET (data)->style->white, - "test.xpm"); + "3DRings.xpm"); for (i = 0; i < TESTGTK_CLIST_COLUMNS; i++) { @@ -2994,7 +2994,7 @@ add1000_clist (GtkWidget *widget, gpointer data) { sprintf (text[0], "Row %d", clist_rows++); row = gtk_clist_append (GTK_CLIST (data), texts); - gtk_clist_set_pixtext (GTK_CLIST (data), row, 3, "Testing", 5, pixmap, mask); + gtk_clist_set_pixtext (GTK_CLIST (data), row, 3, "Hello World", 5, pixmap, mask); } gtk_clist_thaw (GTK_CLIST (data)); diff --git a/tests/testgtk.c b/tests/testgtk.c index 586966cfed..f270e9b01b 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -2977,7 +2977,7 @@ add1000_clist (GtkWidget *widget, gpointer data) pixmap = gdk_pixmap_create_from_xpm (GTK_CLIST (data)->clist_window, &mask, >K_WIDGET (data)->style->white, - "test.xpm"); + "3DRings.xpm"); for (i = 0; i < TESTGTK_CLIST_COLUMNS; i++) { @@ -2994,7 +2994,7 @@ add1000_clist (GtkWidget *widget, gpointer data) { sprintf (text[0], "Row %d", clist_rows++); row = gtk_clist_append (GTK_CLIST (data), texts); - gtk_clist_set_pixtext (GTK_CLIST (data), row, 3, "Testing", 5, pixmap, mask); + gtk_clist_set_pixtext (GTK_CLIST (data), row, 3, "Hello World", 5, pixmap, mask); } gtk_clist_thaw (GTK_CLIST (data)); |