cellrenderericon.c
来自「Gqview,Linux下基于GTK+库写成的轻量级而能丰富的图像浏览程序。」· C语言 代码 · 共 644 行 · 第 1/2 页
C
644 行
else { if (cellicon->foreground_set) { cellicon->foreground_set = FALSE; g_object_notify(G_OBJECT(cellicon), "foreground_set"); } }}static voidgqv_cell_renderer_icon_set_property(GObject *object, guint param_id, const GValue *value, GParamSpec *pspec){ GQvCellRendererIcon *cellicon = GQV_CELL_RENDERER_ICON (object); switch (param_id) { case PROP_PIXBUF: { GdkPixbuf *pixbuf; pixbuf = (GdkPixbuf*) g_value_get_object (value); if (pixbuf) g_object_ref (pixbuf); if (cellicon->pixbuf) g_object_unref (cellicon->pixbuf); cellicon->pixbuf = pixbuf; } break; case PROP_TEXT: { gchar *text; text = cellicon->text; cellicon->text = g_strdup(g_value_get_string(value)); g_free(text); g_object_notify(object, "text"); } break; case PROP_BACKGROUND_GDK: set_bg_color(cellicon, g_value_get_boxed(value)); break; case PROP_FOREGROUND_GDK: set_fg_color(cellicon, g_value_get_boxed(value)); break; case PROP_FOCUSED: cellicon->focused = g_value_get_boolean(value); break; case PROP_FIXED_WIDTH: cellicon->fixed_width = g_value_get_int(value); break; case PROP_FIXED_HEIGHT: cellicon->fixed_height = g_value_get_int(value); break; case PROP_BACKGROUND_SET: cellicon->background_set = g_value_get_boolean(value); break; case PROP_FOREGROUND_SET: cellicon->foreground_set = g_value_get_boolean(value); break; case PROP_SHOW_TEXT: cellicon->show_text = g_value_get_boolean(value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; }}static PangoLayout *gqv_cell_renderer_icon_get_layout(GQvCellRendererIcon *cellicon, GtkWidget *widget, gboolean will_render){ PangoLayout *layout; gint width; width = (cellicon->fixed_width > 0) ? cellicon->fixed_width * PANGO_SCALE : -1; layout = gtk_widget_create_pango_layout(widget, cellicon->text); pango_layout_set_width(layout, width); pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); if (will_render) { PangoAttrList *attr_list; attr_list = pango_attr_list_new(); if (cellicon->foreground_set) { PangoColor color; PangoAttribute *attr; color = cellicon->foreground; attr = pango_attr_foreground_new(color.red, color.green, color.blue); attr->start_index = 0; attr->end_index = G_MAXINT; pango_attr_list_insert(attr_list, attr); } pango_layout_set_attributes(layout, attr_list); pango_attr_list_unref(attr_list); } return layout;}/** * gqv_cell_renderer_icon_new: * * Creates a new #GQvCellRendererIcon. Adjust rendering * parameters using object properties. Object properties can be set * globally (with g_object_set()). Also, with #GtkTreeViewColumn, you * can bind a property to a value in a #GtkTreeModel. For example, you * can bind the "pixbuf" property on the cell renderer to a pixbuf value * in the model, thus rendering a different image in each row of the * #GtkTreeView. * * Return value: the new cell renderer **/GtkCellRenderer *gqv_cell_renderer_icon_new(void){ return g_object_new (GQV_TYPE_CELL_RENDERER_ICON, NULL);}static voidgqv_cell_renderer_icon_get_size(GtkCellRenderer *cell, GtkWidget *widget, GdkRectangle *cell_area, gint *x_offset, gint *y_offset, gint *width, gint *height){ GQvCellRendererIcon *cellicon = (GQvCellRendererIcon *) cell; gint calc_width; gint calc_height; if (cellicon->fixed_width > 0) { calc_width = cellicon->fixed_width; } else { calc_width = (cellicon->pixbuf) ? gdk_pixbuf_get_width(cellicon->pixbuf) : 0; } if (cellicon->fixed_height > 0) { calc_height = cellicon->fixed_height; } else { calc_height = (cellicon->pixbuf) ? gdk_pixbuf_get_height(cellicon->pixbuf) : 0; } if (cellicon->show_text && cellicon->text) { PangoLayout *layout; PangoRectangle rect; layout = gqv_cell_renderer_icon_get_layout(cellicon, widget, FALSE); pango_layout_get_pixel_extents(layout, NULL, &rect); g_object_unref(layout); calc_width = MAX(calc_width, rect.width); calc_height += rect.height; } calc_width += (gint)cell->xpad * 2; calc_height += (gint)cell->ypad * 2; if (x_offset) *x_offset = 0; if (y_offset) *y_offset = 0; if (cell_area && calc_width > 0 && calc_height > 0) { if (x_offset) { *x_offset = (cell->xalign * (cell_area->width - calc_width - 2 * cell->xpad)); *x_offset = MAX (*x_offset, 0) + cell->xpad; } if (y_offset) { *y_offset = (cell->yalign * (cell_area->height - calc_height - 2 * cell->ypad)); *y_offset = MAX (*y_offset, 0) + cell->ypad; } } if (width) *width = calc_width; if (height) *height = calc_height;}static voidgqv_cell_renderer_icon_render(GtkCellRenderer *cell, GdkWindow *window, GtkWidget *widget, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, GtkCellRendererState flags){ GQvCellRendererIcon *cellicon = (GQvCellRendererIcon *) cell; GdkPixbuf *pixbuf; const gchar *text; GdkRectangle cell_rect; GtkStateType state; pixbuf = cellicon->pixbuf; text = cellicon->text; if (!pixbuf && !text) return; gqv_cell_renderer_icon_get_size(cell, widget, cell_area, &cell_rect.x, &cell_rect.y, &cell_rect.width, &cell_rect.height); cell_rect.x += cell->xpad; cell_rect.y += cell->ypad; cell_rect.width -= cell->xpad * 2; cell_rect.height -= cell->ypad * 2; if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED) { if (GTK_WIDGET_HAS_FOCUS(widget)) state = GTK_STATE_SELECTED; else state = GTK_STATE_ACTIVE; } else { if (GTK_WIDGET_STATE(widget) == GTK_STATE_INSENSITIVE) state = GTK_STATE_INSENSITIVE; else state = GTK_STATE_NORMAL; } if (pixbuf) { GdkRectangle pix_rect; GdkRectangle draw_rect; pix_rect.width = gdk_pixbuf_get_width(pixbuf); pix_rect.height = gdk_pixbuf_get_height(pixbuf); pix_rect.x = cell_area->x + (cell_area->width - pix_rect.width) / 2; if (cellicon->fixed_height > 0) { pix_rect.y = cell_area->y + cell->ypad + (cellicon->fixed_height - pix_rect.height) / 2; } else { pix_rect.y = cell_area->y + cell_rect.y; } if (gdk_rectangle_intersect(cell_area, &pix_rect, &draw_rect) && gdk_rectangle_intersect(expose_area, &draw_rect, &draw_rect)) { gdk_draw_pixbuf(window, widget->style->black_gc, pixbuf, /* pixbuf 0, 0 is at pix_rect.x, pix_rect.y */ draw_rect.x - pix_rect.x, draw_rect.y - pix_rect.y, draw_rect.x, draw_rect.y, draw_rect.width, draw_rect.height, GDK_RGB_DITHER_NORMAL, 0, 0); } } if (cellicon->show_text && text) { PangoLayout *layout; PangoRectangle text_rect; GdkRectangle pix_rect; GdkRectangle draw_rect; layout = gqv_cell_renderer_icon_get_layout(cellicon, widget, TRUE); pango_layout_get_pixel_extents(layout, NULL, &text_rect); pix_rect.width = text_rect.width; pix_rect.height = text_rect.height; pix_rect.x = cell_area->x + cell->xpad + (cell_rect.width - text_rect.width + 1) / 2; pix_rect.y = cell_area->y + cell->ypad + (cell_rect.height - text_rect.height); if (gdk_rectangle_intersect(cell_area, &pix_rect, &draw_rect) && gdk_rectangle_intersect(expose_area, &draw_rect, &draw_rect)) { gtk_paint_layout(widget->style, window, state, TRUE, cell_area, widget, "cellrenderertext", pix_rect.x - text_rect.x, pix_rect.y, layout); } g_object_unref(layout); } if (cellicon->focused && GTK_WIDGET_HAS_FOCUS(widget)) { gtk_paint_focus(widget->style, window, state, cell_area, widget, "cellrendererfocus", cell_area->x, cell_area->y, cell_area->width, cell_area->height); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?