New API functions: gtk_clist_get_cell_type gtk_clist_get_text

New API functions:
  gtk_clist_get_cell_type
  gtk_clist_get_text
  gtk_clist_get_pixmap
  gtk_clist_get_pixtext
  gtk_clist_find_row_from_data
This commit is contained in:
Jay Painter 1998-02-08 07:55:11 +00:00
parent 289f6a38fe
commit 7a3af96d84
4 changed files with 300 additions and 28 deletions

View File

@ -877,6 +877,25 @@ gtk_clist_moveto (GtkCList * clist,
}
}
GtkCellType
gtk_clist_get_cell_type (GtkCList * clist,
gint row,
gint column)
{
GtkCListRow *clist_row;
g_return_val_if_fail (clist != NULL, -1);
if (row < 0 || row >= clist->rows)
return -1;
if (column < 0 || column >= clist->columns)
return -1;
clist_row = (g_list_nth (clist->row_list, row))->data;
return clist_row->cell[column].type;
}
void
gtk_clist_set_text (GtkCList * clist,
gint row,
@ -908,6 +927,32 @@ gtk_clist_set_text (GtkCList * clist,
}
}
gint
gtk_clist_get_text (GtkCList * clist,
gint row,
gint column,
gchar ** text)
{
GtkCListRow *clist_row;
g_return_val_if_fail (clist != NULL, 0);
if (row < 0 || row >= clist->rows)
return 0;
if (column < 0 || column >= clist->columns)
return 0;
clist_row = (g_list_nth (clist->row_list, row))->data;
if (clist_row->cell[column].type != GTK_CELL_TEXT)
return 0;
if (text)
*text = GTK_CELL_TEXT (clist_row->cell[column])->text;
return 1;
}
void
gtk_clist_set_pixmap (GtkCList * clist,
gint row,
@ -938,6 +983,35 @@ gtk_clist_set_pixmap (GtkCList * clist,
}
}
gint
gtk_clist_get_pixmap (GtkCList * clist,
gint row,
gint column,
GdkPixmap ** pixmap,
GdkBitmap ** mask)
{
GtkCListRow *clist_row;
g_return_val_if_fail (clist != NULL, 0);
if (row < 0 || row >= clist->rows)
return 0;
if (column < 0 || column >= clist->columns)
return 0;
clist_row = (g_list_nth (clist->row_list, row))->data;
if (clist_row->cell[column].type != GTK_CELL_PIXMAP)
return 0;
if (pixmap)
*pixmap = GTK_CELL_PIXMAP (clist_row->cell[column])->pixmap;
if (mask)
*mask = GTK_CELL_PIXMAP (clist_row->cell[column])->mask;
return 1;
}
void
gtk_clist_set_pixtext (GtkCList * clist,
gint row,
@ -970,6 +1044,41 @@ gtk_clist_set_pixtext (GtkCList * clist,
}
}
gint
gtk_clist_get_pixtext (GtkCList * clist,
gint row,
gint column,
gchar ** text,
guint8 * spacing,
GdkPixmap ** pixmap,
GdkBitmap ** mask)
{
GtkCListRow *clist_row;
g_return_val_if_fail (clist != NULL, 0);
if (row < 0 || row >= clist->rows)
return 0;
if (column < 0 || column >= clist->columns)
return 0;
clist_row = (g_list_nth (clist->row_list, row))->data;
if (clist_row->cell[column].type != GTK_CELL_PIXTEXT)
return 0;
if (text)
*text = GTK_CELL_PIXTEXT (clist_row->cell[column])->text;
if (spacing)
*spacing = GTK_CELL_PIXTEXT (clist_row->cell[column])->spacing;
if (pixmap)
*pixmap = GTK_CELL_PIXTEXT (clist_row->cell[column])->pixmap;
if (mask)
*mask = GTK_CELL_PIXTEXT (clist_row->cell[column])->mask;
return 1;
}
void
gtk_clist_set_foreground (GtkCList * clist,
gint row,
@ -1048,6 +1157,12 @@ gtk_clist_append (GtkCList * clist,
clist_row = row_new (clist);
clist->rows++;
/* set the text in the row's columns */
if (text)
for (i = 0; i < clist->columns; i++)
if (text[i])
cell_set_text (clist, clist_row, i, text[i]);
/* keeps track of the end of the list so the list
* doesn't have to be traversed every time a item is added */
if (!clist->row_list)
@ -1069,12 +1184,6 @@ gtk_clist_append (GtkCList * clist,
}
else
clist->row_list_end = (g_list_append (clist->row_list_end, clist_row))->next;
/* set the text in the row's columns */
if (text)
for (i = 0; i < clist->columns; i++)
if (text[i])
cell_set_text (clist, clist_row, i, text[i]);
/* redraw the list if it's not frozen */
if (!GTK_CLIST_FROZEN (clist))
@ -1107,6 +1216,12 @@ gtk_clist_insert (GtkCList * clist,
/* create the row */
clist_row = row_new (clist);
/* set the text in the row's columns */
if (text)
for (i = 0; i < clist->columns; i++)
if (text[i])
cell_set_text (clist, clist_row, i, text[i]);
/* reset the row end pointer if we're inserting at the
* end of the list */
if (row == clist->rows)
@ -1116,12 +1231,6 @@ gtk_clist_insert (GtkCList * clist,
clist->rows++;
/* set the text in the row's columns */
if (text)
for (i = 0; i < clist->columns; i++)
if (text[i])
cell_set_text (clist, clist_row, i, text[i]);
/* redraw the list if it isn't frozen */
if (!GTK_CLIST_FROZEN (clist))
{
@ -1271,6 +1380,38 @@ gtk_clist_get_row_data (GtkCList * clist,
return clist_row->data;
}
gint
gtk_clist_find_row_from_data (GtkCList * clist,
gpointer data)
{
GList *list;
gint n;
g_return_val_if_fail (clist != NULL, -1);
g_return_val_if_fail (GTK_IS_CLIST (clist), -1);
if (clist->rows < 1)
return -1; /* is this an optimization or just worthless? */
n = 0;
list = clist->row_list;
while (list)
{
GtkCListRow *clist_row;
clist_row = list->data;
if (clist_row->data == data)
break;
n++;
list = list->next;
}
if (list)
return n;
return -1;
}
void
gtk_clist_select_row (GtkCList * clist,
gint row,

View File

@ -350,12 +350,24 @@ void gtk_clist_moveto (GtkCList * clist,
gint gtk_clist_row_isvisable (GtkCList * clist,
gint row);
/* returns the cell type */
GtkCellType gtk_clist_get_cell_type (GtkCList * clist,
gint row,
gint column);
/* sets a given cell's text, replacing it's current contents */
void gtk_clist_set_text (GtkCList * clist,
gint row,
gint column,
gchar * text);
/* for the "get" functions, any of the return pointer can be
* NULL if you are not interested */
gint gtk_clist_get_text (GtkCList * clist,
gint row,
gint column,
gchar ** text);
/* sets a given cell's pixmap, replacing it's current contents */
void gtk_clist_set_pixmap (GtkCList * clist,
gint row,
@ -363,6 +375,12 @@ void gtk_clist_set_pixmap (GtkCList * clist,
GdkPixmap * pixmap,
GdkBitmap * mask);
gint gtk_clist_get_pixmap (GtkCList * clist,
gint row,
gint column,
GdkPixmap ** pixmap,
GdkBitmap ** mask);
/* sets a given cell's pixmap and text, replacing it's current contents */
void gtk_clist_set_pixtext (GtkCList * clist,
gint row,
@ -372,6 +390,14 @@ void gtk_clist_set_pixtext (GtkCList * clist,
GdkPixmap * pixmap,
GdkBitmap * mask);
gint gtk_clist_get_pixtext (GtkCList * clist,
gint row,
gint column,
gchar ** text,
guint8 * spacing,
GdkPixmap ** pixmap,
GdkBitmap ** mask);
/* sets the foreground color of a row, the colar must already
* be allocated */
void gtk_clist_set_foreground (GtkCList * clist,
@ -416,6 +442,11 @@ void gtk_clist_set_row_data (GtkCList * clist,
gpointer gtk_clist_get_row_data (GtkCList * clist,
gint row);
/* givin a data pointer, find the first (and hopefully only!)
* row that points to that data, or -1 if none do */
gint gtk_clist_find_row_from_data (GtkCList * clist,
gpointer data);
/* force selection of a row */
void gtk_clist_select_row (GtkCList * clist,
gint row,

View File

@ -1573,9 +1573,16 @@ static gint clist_selected_row = 0;
void
add1000_clist (GtkWidget *widget, gpointer data)
{
gint i;
gint i, row;
char text[TESTGTK_CLIST_COLUMNS][50];
char *texts[TESTGTK_CLIST_COLUMNS];
GdkBitmap *mask;
GdkPixmap *pixmap;
pixmap = gdk_pixmap_create_from_xpm (GTK_CLIST (data)->clist_window,
&mask,
&GTK_WIDGET (data)->style->white,
"test.xpm");
for (i = 0; i < TESTGTK_CLIST_COLUMNS; i++)
{
@ -1583,6 +1590,7 @@ add1000_clist (GtkWidget *widget, gpointer data)
sprintf (text[i], "Column %d", i);
}
texts[3] = NULL;
sprintf (text[1], "Right");
sprintf (text[2], "Center");
@ -1590,10 +1598,13 @@ add1000_clist (GtkWidget *widget, gpointer data)
for (i = 0; i < 1000; i++)
{
sprintf (text[0], "Row %d", clist_rows++);
gtk_clist_append (GTK_CLIST (data), texts);
row = gtk_clist_append (GTK_CLIST (data), texts);
gtk_clist_set_pixtext (GTK_CLIST (data), row, 3, "Testing", 5, pixmap, mask);
}
gtk_clist_thaw (GTK_CLIST (data));
gdk_pixmap_unref (pixmap);
gdk_bitmap_unref (mask);
}
void
@ -1654,7 +1665,11 @@ select_clist (GtkWidget *widget,
gint column,
GdkEventButton *bevent)
{
gint button = 0;
gint button = 0, i;
guint8 spacing;
gchar *text;
GdkPixmap *pixmap;
GdkBitmap *mask;
if (bevent)
button = bevent->button;
@ -1662,16 +1677,45 @@ select_clist (GtkWidget *widget,
g_print ("GtkCList Selection: row %d column %d button %d\n",
row, column, button);
for (i = 0; i < TESTGTK_CLIST_COLUMNS; i++)
{
switch (gtk_clist_get_cell_type (GTK_CLIST (widget), row, i))
{
case GTK_CELL_TEXT:
g_print ("CELL %d GTK_CELL_TEXT\n", i);
gtk_clist_get_text (GTK_CLIST (widget), row, i, &text);
g_print ("TEXT: %s\n", text);
break;
case GTK_CELL_PIXMAP:
g_print ("CELL %d GTK_CELL_PIXMAP\n", i);
gtk_clist_get_pixmap (GTK_CLIST (widget), row, i, &pixmap, &mask);
g_print ("PIXMAP: %d\n", (int) pixmap);
g_print ("MASK: %d\n", (int) mask);
break;
case GTK_CELL_PIXTEXT:
g_print ("CELL %d GTK_CELL_PIXTEXT\n", i);
gtk_clist_get_pixtext (GTK_CLIST (widget), row, i, &text, &spacing, &pixmap, &mask);
g_print ("TEXT: %s\n", text);
g_print ("SPACING: %d\n", spacing);
g_print ("PIXMAP: %d\n", (int) pixmap);
g_print ("MASK: %d\n", (int) mask);
break;
default:
break;
}
}
g_print ("\n\n");
clist_selected_row = row;
}
void
list_selection_clist (GtkWidget *widget, gpointer data)
{
GList *list;
GtkCListRow *clist_row;
GtkCList *clist;
}
void
@ -1729,9 +1773,10 @@ create_clist ()
/* create GtkCList here so we have a pointer to throw at the
* button callbacks -- more is done with it later */
clist = gtk_clist_new_with_titles (TESTGTK_CLIST_COLUMNS, titles);
/*clist = gtk_clist_new (TESTGTK_CLIST_COLUMNS);*/
/* control buttons */
button = gtk_button_new_with_label ("Add 1,000 Rows");
button = gtk_button_new_with_label ("Add 1,000 Rows With Pixmaps");
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
gtk_signal_connect (GTK_OBJECT (button),
@ -1807,6 +1852,11 @@ create_clist ()
/*
* the rest of the clist configuration
*/
/*
gtk_clist_set_column_title (GTK_CLIST (clist), 0, "Hello");
gtk_clist_set_column_title (GTK_CLIST (clist), 4, "Joe 4");
*/
gtk_clist_column_titles_passive (GTK_CLIST (clist));
gtk_clist_set_row_height (GTK_CLIST (clist), 20);
gtk_signal_connect (GTK_OBJECT (clist),

View File

@ -1573,9 +1573,16 @@ static gint clist_selected_row = 0;
void
add1000_clist (GtkWidget *widget, gpointer data)
{
gint i;
gint i, row;
char text[TESTGTK_CLIST_COLUMNS][50];
char *texts[TESTGTK_CLIST_COLUMNS];
GdkBitmap *mask;
GdkPixmap *pixmap;
pixmap = gdk_pixmap_create_from_xpm (GTK_CLIST (data)->clist_window,
&mask,
&GTK_WIDGET (data)->style->white,
"test.xpm");
for (i = 0; i < TESTGTK_CLIST_COLUMNS; i++)
{
@ -1583,6 +1590,7 @@ add1000_clist (GtkWidget *widget, gpointer data)
sprintf (text[i], "Column %d", i);
}
texts[3] = NULL;
sprintf (text[1], "Right");
sprintf (text[2], "Center");
@ -1590,10 +1598,13 @@ add1000_clist (GtkWidget *widget, gpointer data)
for (i = 0; i < 1000; i++)
{
sprintf (text[0], "Row %d", clist_rows++);
gtk_clist_append (GTK_CLIST (data), texts);
row = gtk_clist_append (GTK_CLIST (data), texts);
gtk_clist_set_pixtext (GTK_CLIST (data), row, 3, "Testing", 5, pixmap, mask);
}
gtk_clist_thaw (GTK_CLIST (data));
gdk_pixmap_unref (pixmap);
gdk_bitmap_unref (mask);
}
void
@ -1654,7 +1665,11 @@ select_clist (GtkWidget *widget,
gint column,
GdkEventButton *bevent)
{
gint button = 0;
gint button = 0, i;
guint8 spacing;
gchar *text;
GdkPixmap *pixmap;
GdkBitmap *mask;
if (bevent)
button = bevent->button;
@ -1662,16 +1677,45 @@ select_clist (GtkWidget *widget,
g_print ("GtkCList Selection: row %d column %d button %d\n",
row, column, button);
for (i = 0; i < TESTGTK_CLIST_COLUMNS; i++)
{
switch (gtk_clist_get_cell_type (GTK_CLIST (widget), row, i))
{
case GTK_CELL_TEXT:
g_print ("CELL %d GTK_CELL_TEXT\n", i);
gtk_clist_get_text (GTK_CLIST (widget), row, i, &text);
g_print ("TEXT: %s\n", text);
break;
case GTK_CELL_PIXMAP:
g_print ("CELL %d GTK_CELL_PIXMAP\n", i);
gtk_clist_get_pixmap (GTK_CLIST (widget), row, i, &pixmap, &mask);
g_print ("PIXMAP: %d\n", (int) pixmap);
g_print ("MASK: %d\n", (int) mask);
break;
case GTK_CELL_PIXTEXT:
g_print ("CELL %d GTK_CELL_PIXTEXT\n", i);
gtk_clist_get_pixtext (GTK_CLIST (widget), row, i, &text, &spacing, &pixmap, &mask);
g_print ("TEXT: %s\n", text);
g_print ("SPACING: %d\n", spacing);
g_print ("PIXMAP: %d\n", (int) pixmap);
g_print ("MASK: %d\n", (int) mask);
break;
default:
break;
}
}
g_print ("\n\n");
clist_selected_row = row;
}
void
list_selection_clist (GtkWidget *widget, gpointer data)
{
GList *list;
GtkCListRow *clist_row;
GtkCList *clist;
}
void
@ -1729,9 +1773,10 @@ create_clist ()
/* create GtkCList here so we have a pointer to throw at the
* button callbacks -- more is done with it later */
clist = gtk_clist_new_with_titles (TESTGTK_CLIST_COLUMNS, titles);
/*clist = gtk_clist_new (TESTGTK_CLIST_COLUMNS);*/
/* control buttons */
button = gtk_button_new_with_label ("Add 1,000 Rows");
button = gtk_button_new_with_label ("Add 1,000 Rows With Pixmaps");
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
gtk_signal_connect (GTK_OBJECT (button),
@ -1807,6 +1852,11 @@ create_clist ()
/*
* the rest of the clist configuration
*/
/*
gtk_clist_set_column_title (GTK_CLIST (clist), 0, "Hello");
gtk_clist_set_column_title (GTK_CLIST (clist), 4, "Joe 4");
*/
gtk_clist_column_titles_passive (GTK_CLIST (clist));
gtk_clist_set_row_height (GTK_CLIST (clist), 20);
gtk_signal_connect (GTK_OBJECT (clist),