void CoordWinSetFont(const char *font) { #if GTK_CHECK_VERSION(3, 16, 0) if (NgraphApp.CoordWin.data.text && font) { set_widget_font(NgraphApp.CoordWin.data.text, font); } #else /* GTK_CHECK_VERSION(3, 16, 0) */ const char *ptr; PangoAttrList *pattr; PangoFontDescription *desc; GtkLabel *label; label = GTK_LABEL(NgraphApp.CoordWin.data.text); if (label == NULL) return; pattr = gtk_label_get_attributes(label); if (pattr == NULL) { pattr = pango_attr_list_new(); gtk_label_set_attributes(GTK_LABEL(label), pattr); } ptr = (font) ? font : "Monospace"; desc = pango_font_description_from_string(ptr); pango_attr_list_change(pattr, pango_attr_font_desc_new(desc)); pango_font_description_free(desc); #endif }
static gboolean vi_list_item_enter_notify_event(GtkWidget *widget, GdkEventCrossing *event, struct vi_list_item_t *item) { GdkColor color; PangoAttrList *attrs; PangoAttribute *underline_attr; GdkWindow *window; GdkCursor *cursor; GtkStyle *style; style = gtk_widget_get_style(item->label); item->label_color = style->fg[GTK_STATE_NORMAL]; gdk_color_parse("red", &color); gtk_widget_modify_fg(item->label, GTK_STATE_NORMAL, &color); attrs = gtk_label_get_attributes(GTK_LABEL(item->label)); underline_attr = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); pango_attr_list_change(attrs, underline_attr); cursor = gdk_cursor_new(GDK_HAND1); window = gtk_widget_get_parent_window(widget); gdk_window_set_cursor(window, cursor); g_object_unref(cursor); return FALSE; }
static gboolean vi_list_item_leave_notify_event(GtkWidget *widget, GdkEventCrossing *event, struct vi_list_item_t *item) { PangoAttrList *attrs; PangoAttribute *underline_attr; GdkWindow *window; window = gtk_widget_get_parent_window(widget); gdk_window_set_cursor(window, NULL); attrs = gtk_label_get_attributes(GTK_LABEL(item->label)); underline_attr = pango_attr_underline_new(PANGO_UNDERLINE_NONE); pango_attr_list_change(attrs, underline_attr); gtk_widget_modify_fg(item->label, GTK_STATE_NORMAL, &item->label_color); return FALSE; }
void QPushButton::setFont(const QFont &font) { //g_warning("QPushButton::setFont: size:%d, family:%s, text: %s", font.pixelSize(), font.family().latin1(),text().latin1()); QButton::setFont(font); #if 0 GtkWidget *button = getGtkWidget(); if (button) { PangoFontDescription *fd; GtkWidget *child,*newchild; PangoAttrList* al; PangoAttribute* afd; child = gtk_bin_get_child(GTK_BIN(button)); newchild = gtk_label_new(text().utf8()); fd = createPangoFontDescription(&font); gtk_widget_modify_font(button, fd); gtk_widget_modify_font(child, fd); gtk_container_remove(GTK_CONTAINER(button),child); gtk_container_add(GTK_CONTAINER(button),newchild); child = newchild; afd = pango_attr_font_desc_new(fd); al = gtk_label_get_attributes( GTK_LABEL(child) ); if (al == NULL) { al = pango_attr_list_new(); pango_attr_list_insert(al,afd); } else { pango_attr_list_change(al,afd); } gtk_label_set_attributes( GTK_LABEL(child), al ); gtk_widget_show( child ); //g_warning("child:%x fd,%x",child,fd); pango_font_description_free(fd); } #endif }
static void cv_tabs_rename (chan *ch, char *name) { PangoAttrList *attr; GtkWidget *tab = ch->impl; attr = gtk_label_get_attributes (GTK_LABEL (gtk_bin_get_child (GTK_BIN (tab)))); if (attr) pango_attr_list_ref (attr); gtk_button_set_label (GTK_BUTTON (tab), name); gtk_widget_queue_resize (gtk_widget_get_parent(gtk_widget_get_parent(gtk_widget_get_parent(tab)))); if (attr) { gtk_label_set_attributes (GTK_LABEL (gtk_bin_get_child (GTK_BIN (tab))), attr); pango_attr_list_unref (attr); } }
/** * terminal_tab_label_set_bold: * @tab_label: a #TerminalTabLabel * @bold: whether to enable label bolding * * Sets the tab label text bold, or unbolds it. */ void terminal_tab_label_set_bold (TerminalTabLabel *tab_label, gboolean bold) { TerminalTabLabelPrivate *priv = tab_label->priv; PangoAttrList *attr_list; PangoAttribute *weight_attr; gboolean free_list = FALSE; bold = bold != FALSE; if (priv->bold == bold) return; priv->bold = bold; attr_list = gtk_label_get_attributes (GTK_LABEL (priv->label)); if (!attr_list) { attr_list = pango_attr_list_new (); free_list = TRUE; } if (bold) weight_attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD); else weight_attr = pango_attr_weight_new (PANGO_WEIGHT_NORMAL); /* gtk_label_get_attributes() returns the label's internal list, * which we're probably not supposed to modify directly. * It seems to work ok however. */ pango_attr_list_change (attr_list, weight_attr); gtk_label_set_attributes (GTK_LABEL (priv->label), attr_list); if (free_list) pango_attr_list_unref (attr_list); }
/** * anaconda_apply_language: * @label: (transfer none): The widget to which to apply the language * @language: The language to apply to the widget * * Apply a Pango language attribute to a label. * * For some formatting decisions, in particular the font choice, the language * of the text being rendered needs to be known. This is especially the case * for the Chinese, Japanese and Korean translations, since Unicode uses a * single codepoint for the CJK characters across languages, even when the * particular language may render the character very differently. For example, * U+76F4 (直) shows up a good bit in the translations, it is rendered differently * in Chinese and Japanese, and it is considered unreadable between the two. * * This function applies a #PangoAttrLanguage attribute to the label so that * the underlying renderer can do the right thing. * * Since: 3.4 */ void anaconda_apply_language(GtkLabel *label, const gchar *language) { PangoLanguage *pango_language; PangoAttribute *attr; PangoAttrList *attrlist; gboolean attrlist_unref = FALSE; pango_language = pango_language_from_string(language); attr = pango_attr_language_new(pango_language); /* If the label already has an attribute list, modify it, otherwise create a new one. */ attrlist = gtk_label_get_attributes(label); if (!attrlist) { attrlist = pango_attr_list_new(); attrlist_unref = TRUE; } pango_attr_list_change(attrlist, attr); gtk_label_set_attributes(label, attrlist); /* Drop the local attrlist reference if there is one */ if (attrlist_unref) { pango_attr_list_unref(attrlist); } }
/** * gtk_ellipsis_set_label_widget: * @ellipsis: a #GtkEllipsis * @label: the new label widget * * Set the label widget for the ellipsis. This is the widget * that will appear embedded alongside the ellipsis arrow. * * Since: 2.4 **/ void gtk_ellipsis_set_label_widget (GtkEllipsis *ellipsis, GtkWidget *label) { GtkEllipsisPrivate *priv; g_return_if_fail (GTK_IS_ELLIPSIS (ellipsis)); g_return_if_fail (label == NULL || GTK_IS_WIDGET (label)); g_return_if_fail (label == NULL || label->parent == NULL); priv = ellipsis->priv; if (priv->label == label) return; if (priv->label) { gtk_widget_set_state (priv->label, GTK_STATE_NORMAL); gtk_widget_unparent (priv->label); } priv->label = label; if (label) { gfloat xalign, yalign; gtk_misc_get_alignment (>K_LABEL (label)->misc, &xalign, &yalign); gtk_misc_set_alignment (>K_LABEL (label)->misc, 0.0, yalign); gtk_widget_set_parent (label, GTK_WIDGET (ellipsis)); if (!priv->ellipsis_label) { GdkColor *link_color, active_bg_color; GtkWidget *child; PangoAttrList *attrs; PangoAttribute *uline; child = gtk_label_new ("..."); /* Change the foreground color for all states but selected. */ gtk_widget_style_get (GTK_WIDGET (child), "link-color", &link_color, NULL); if (!link_color) { GtkStyle *style = gtk_widget_get_style (child); active_bg_color = style->bg[GTK_STATE_SELECTED]; link_color = &active_bg_color; } gtk_widget_modify_fg (child, GTK_STATE_NORMAL, link_color); gtk_widget_modify_fg (child, GTK_STATE_ACTIVE, link_color); gtk_widget_modify_fg (child, GTK_STATE_PRELIGHT, link_color); if (link_color != &active_bg_color) gdk_color_free (link_color); /* Add an underline. */ attrs = gtk_label_get_attributes (GTK_LABEL (label)); attrs = attrs ? pango_attr_list_copy (attrs) : pango_attr_list_new (); uline = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE); uline->start_index = 0; uline->end_index = G_MAXUINT; pango_attr_list_insert (attrs, uline); gtk_label_set_attributes (GTK_LABEL (child), attrs); pango_attr_list_unref (attrs); gtk_widget_show (child); gtk_widget_set_parent (child, GTK_WIDGET (ellipsis)); priv->ellipsis_label = child; } if (priv->prelight) { gtk_widget_set_state (label, GTK_STATE_PRELIGHT); gtk_widget_set_state (priv->ellipsis_label, GTK_STATE_PRELIGHT); } } else { if (priv->ellipsis_label) { gtk_widget_destroy (priv->ellipsis_label); priv->ellipsis_label = NULL; } } if (GTK_WIDGET_VISIBLE (ellipsis)) gtk_widget_queue_resize (GTK_WIDGET (ellipsis)); g_object_freeze_notify (G_OBJECT (ellipsis)); g_object_notify (G_OBJECT (ellipsis), "label-widget"); g_object_notify (G_OBJECT (ellipsis), "label"); g_object_thaw_notify (G_OBJECT (ellipsis)); }